Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/sd/source/ui/app/sdmod.cxx
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
20
#include <unotools/pathoptions.hxx>
21
#include <unotools/ucbstreamhelper.hxx>
22
#include <unotools/resmgr.hxx>
23
#include <tools/urlobj.hxx>
24
#include <vcl/virdev.hxx>
25
#include <vcl/svapp.hxx>
26
#include <svl/numformat.hxx>
27
#include <svl/intitem.hxx>
28
#include <sfx2/msg.hxx>
29
#include <sfx2/objface.hxx>
30
#include <comphelper/processfactory.hxx>
31
#include <svtools/ehdl.hxx>
32
33
#include <svx/svxids.hrc>
34
#include <svl/srchitem.hxx>
35
#include <svx/svxerr.hxx>
36
37
#include <svtools/colorcfg.hxx>
38
39
#include <sdmod.hxx>
40
#include <sdresid.hxx>
41
#include <optsitem.hxx>
42
#include <DrawDocShell.hxx>
43
#include <drawdoc.hxx>
44
#include <errhdl.hrc>
45
#include <unotools/syslocale.hxx>
46
47
#include <officecfg/Office/Draw.hxx>
48
#include <officecfg/Office/Impress.hxx>
49
50
#define ShellClass_SdModule
51
#include <sdslots.hxx>
52
53
SFX_IMPL_INTERFACE(SdModule, SfxModule)
54
55
void SdModule::InitInterface_Impl()
56
5
{
57
5
    GetStaticInterface()->RegisterStatusBar(StatusBarId::DrawStatusBar);
58
5
}
59
60
// Ctor
61
SdModule::SdModule(SfxObjectFactory* pFact1, SfxObjectFactory* pFact2 )
62
5
:   SfxModule("sd"_ostr, {pFact1, pFact2}),
63
5
    pTransferClip(nullptr),
64
5
    pTransferDrag(nullptr),
65
5
    pTransferSelection(nullptr),
66
5
    pImpressOptions(nullptr),
67
5
    pDrawOptions(nullptr),
68
5
    bWaterCan(false),
69
5
    mbEventListenerAdded(false),
70
5
    mpColorConfig(new svtools::ColorConfig)
71
5
{
72
5
    SetName( u"StarDraw"_ustr );  // Do not translate!
73
5
    pSearchItem.reset( new SvxSearchItem(SID_SEARCH_ITEM) );
74
5
    pSearchItem->SetAppFlag(SvxSearchApp::DRAW);
75
5
    StartListening( *SfxGetpApp() );
76
5
    SvxErrorHandler::ensure();
77
5
    mpErrorHdl.reset( new SfxErrorHandler(RID_SD_ERRHDL, ErrCodeArea::Sd, ErrCodeArea::Sd, GetResLocale()) );
78
79
    // Create a new ref device and (by calling SetReferenceDevice())
80
    // set its resolution to 600 DPI.  This leads to a visually better
81
    // formatting of text in small sizes (6 point and below.)
82
5
    mpVirtualRefDevice.reset(VclPtr<VirtualDevice>::Create());
83
5
    mpVirtualRefDevice->SetMapMode(MapMode(MapUnit::Map100thMM));
84
5
    mpVirtualRefDevice->SetReferenceDevice ( VirtualDevice::RefDevMode::Dpi600 );
85
5
}
86
87
OUString SdResId(TranslateId aId)
88
6.52M
{
89
6.52M
    return Translate::get(aId, SdModule::get()->GetResLocale());
90
6.52M
}
91
92
OUString SdResId(TranslateNId aContextSingularPlural, int nCardinality)
93
0
{
94
0
    return Translate::nget(aContextSingularPlural, nCardinality, SdModule::get()->GetResLocale());
95
0
}
96
97
// Dtor
98
SdModule::~SdModule()
99
0
{
100
0
    pSearchItem.reset();
101
0
    pNumberFormatter.reset();
102
103
0
    if (mbEventListenerAdded)
104
0
    {
105
0
        Application::RemoveEventListener( LINK( this, SdModule, EventListenerHdl ) );
106
0
    }
107
108
0
    mpErrorHdl.reset();
109
0
    mpVirtualRefDevice.disposeAndClear();
110
0
}
111
112
void SdModule::SetSearchItem(std::unique_ptr<SvxSearchItem> pItem)
113
0
{
114
0
    pSearchItem = std::move(pItem);
115
0
}
116
117
/// get notifications
118
void SdModule::Notify( SfxBroadcaster&, const SfxHint& rHint )
119
106k
{
120
106k
    if( rHint.GetId() == SfxHintId::Deinitializing )
121
0
    {
122
0
        delete pImpressOptions;
123
0
        pImpressOptions = nullptr;
124
0
        delete pDrawOptions;
125
0
        pDrawOptions = nullptr;
126
0
    }
127
106k
}
128
129
/// Return options
130
SdOptions* SdModule::GetSdOptions(DocumentType eDocType)
131
105k
{
132
105k
    SdOptions* pOptions = nullptr;
133
134
105k
    if (eDocType == DocumentType::Draw)
135
0
    {
136
0
        if (!pDrawOptions)
137
0
            pDrawOptions = new SdOptions(false);
138
139
0
        pOptions = pDrawOptions;
140
0
    }
141
105k
    else if (eDocType == DocumentType::Impress)
142
105k
    {
143
105k
        if (!pImpressOptions)
144
5
            pImpressOptions = new SdOptions(true);
145
146
105k
        pOptions = pImpressOptions;
147
105k
    }
148
105k
    if( pOptions )
149
105k
    {
150
105k
        SvtSysLocale aSysLocale;
151
105k
        if (eDocType == DocumentType::Impress)
152
105k
            if (aSysLocale.GetLocaleData().getMeasurementSystemEnum() == MeasurementSystem::Metric)
153
0
                PutItem( SfxUInt16Item( SID_ATTR_METRIC, officecfg::Office::Impress::Layout::Other::MeasureUnit::Metric::get() ) );
154
105k
            else
155
105k
                PutItem( SfxUInt16Item( SID_ATTR_METRIC, officecfg::Office::Impress::Layout::Other::MeasureUnit::NonMetric::get() ) );
156
0
        else
157
0
            if (aSysLocale.GetLocaleData().getMeasurementSystemEnum() == MeasurementSystem::Metric)
158
0
                PutItem( SfxUInt16Item( SID_ATTR_METRIC, officecfg::Office::Draw::Layout::Other::MeasureUnit::Metric::get() ) );
159
0
            else
160
0
                PutItem( SfxUInt16Item( SID_ATTR_METRIC, officecfg::Office::Draw::Layout::Other::MeasureUnit::NonMetric::get() ) );
161
105k
    }
162
163
105k
    return pOptions;
164
105k
}
165
166
SvNumberFormatter* SdModule::GetNumberFormatter()
167
209k
{
168
209k
    if( !pNumberFormatter )
169
3
        pNumberFormatter.reset( new SvNumberFormatter( ::comphelper::getProcessComponentContext(), LANGUAGE_SYSTEM ) );
170
171
209k
    return pNumberFormatter.get();
172
209k
}
173
174
svtools::ColorConfig& SdModule::GetColorConfig()
175
0
{
176
0
    return *mpColorConfig;
177
0
}
178
179
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */