LibreOffice Module sd (master) 1
sdmod.cxx
Go to the documentation of this file.
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
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>
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
46#define ShellClass_SdModule
47#include <sdslots.hxx>
48
50
51void SdModule::InitInterface_Impl()
52{
53 GetStaticInterface()->RegisterStatusBar(StatusBarId::DrawStatusBar);
54}
55
56// Ctor
58: SfxModule("sd", {pFact1, pFact2}),
59 pTransferClip(nullptr),
60 pTransferDrag(nullptr),
61 pTransferSelection(nullptr),
62 pImpressOptions(nullptr),
63 pDrawOptions(nullptr),
64 bWaterCan(false),
65 mbEventListenerAdded(false),
66 mpColorConfig(new svtools::ColorConfig)
67{
68 SetName( "StarDraw" ); // Do not translate!
69 pSearchItem.reset( new SvxSearchItem(SID_SEARCH_ITEM) );
70 pSearchItem->SetAppFlag(SvxSearchApp::DRAW);
73 mpErrorHdl.reset( new SfxErrorHandler(RID_SD_ERRHDL, ErrCodeArea::Sd, ErrCodeArea::Sd, GetResLocale()) );
74
75 // Create a new ref device and (by calling SetReferenceDevice())
76 // set its resolution to 600 DPI. This leads to a visually better
77 // formatting of text in small sizes (6 point and below.)
78 mpVirtualRefDevice.reset(VclPtr<VirtualDevice>::Create());
79 mpVirtualRefDevice->SetMapMode(MapMode(MapUnit::Map100thMM));
80 mpVirtualRefDevice->SetReferenceDevice ( VirtualDevice::RefDevMode::Dpi600 );
81}
82
83OUString SdResId(TranslateId aId)
84{
85 return Translate::get(aId, SD_MOD()->GetResLocale());
86}
87
88OUString SdResId(TranslateNId aContextSingularPlural, int nCardinality)
89{
90 return Translate::nget(aContextSingularPlural, nCardinality, SD_MOD()->GetResLocale());
91}
92
93// Dtor
95{
96 pSearchItem.reset();
97 pNumberFormatter.reset();
98
100 {
101 Application::RemoveEventListener( LINK( this, SdModule, EventListenerHdl ) );
102 }
103
104 mpErrorHdl.reset();
106}
107
108void SdModule::SetSearchItem(std::unique_ptr<SvxSearchItem> pItem)
109{
110 pSearchItem = std::move(pItem);
111}
112
115{
116 if( rHint.GetId() == SfxHintId::Deinitializing )
117 {
118 delete pImpressOptions;
119 pImpressOptions = nullptr;
120 delete pDrawOptions;
121 pDrawOptions = nullptr;
122 }
123}
124
127{
128 SdOptions* pOptions = nullptr;
129
130 if (eDocType == DocumentType::Draw)
131 {
132 if (!pDrawOptions)
133 pDrawOptions = new SdOptions(false);
134
135 pOptions = pDrawOptions;
136 }
137 else if (eDocType == DocumentType::Impress)
138 {
139 if (!pImpressOptions)
140 pImpressOptions = new SdOptions(true);
141
142 pOptions = pImpressOptions;
143 }
144 if( pOptions )
145 {
146 sal_uInt16 nMetric = pOptions->GetMetric();
147
148 ::sd::DrawDocShell* pDocSh = dynamic_cast< ::sd::DrawDocShell *>( SfxObjectShell::Current() );
149 SdDrawDocument* pDoc = nullptr;
150 if (pDocSh)
151 pDoc = pDocSh->GetDoc();
152
153 if( nMetric != 0xffff && pDoc && eDocType == pDoc->GetDocumentType() )
154 PutItem( SfxUInt16Item( SID_ATTR_METRIC, nMetric ) );
155 }
156
157 return pOptions;
158}
159
166 SdOptionStreamMode eMode )
167{
168 ::sd::DrawDocShell* pDocSh = dynamic_cast< ::sd::DrawDocShell *>( SfxObjectShell::Current() );
170
171 if( pDocSh )
172 {
174
175 if( !xOptionStorage.is() )
176 {
177 INetURLObject aURL( SvtPathOptions().GetUserConfigPath() );
178
179 aURL.Append( u"drawing.cfg" );
180
181 std::unique_ptr<SvStream> pStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::READWRITE );
182
183 if( pStm )
184 xOptionStorage = new SotStorage( pStm.release(), true );
185 }
186
187 OUString aStmName;
188
190 aStmName = "Draw_";
191 else
192 aStmName = "Impress_";
193
194 aStmName += rOptionName;
195
196 if( SdOptionStreamMode::Store == eMode || xOptionStorage->IsContained( aStmName ) )
197 xStm = xOptionStorage->OpenSotStream( aStmName );
198 }
199
200 return xStm;
201}
202
204{
205 if( !pNumberFormatter )
206 pNumberFormatter.reset( new SvNumberFormatter( ::comphelper::getProcessComponentContext(), LANGUAGE_SYSTEM ) );
207
208 return pNumberFormatter.get();
209}
210
212{
213 return *mpColorConfig;
214}
215
216/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SfxApplication * SfxGetpApp()
static void RemoveEventListener(const Link< VclSimpleEvent &, void > &rEventListener)
SAL_DLLPRIVATE DocumentType GetDocumentType() const
Definition: drawdoc.hxx:251
std::unique_ptr< SvNumberFormatter > pNumberFormatter
Definition: sdmod.hxx:142
void SetSearchItem(std::unique_ptr< SvxSearchItem > pItem)
Definition: sdmod.cxx:108
SdOptions * pDrawOptions
Definition: sdmod.hxx:140
svtools::ColorConfig & GetColorConfig()
Definition: sdmod.cxx:211
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
get notifications
Definition: sdmod.cxx:114
SD_DLLPUBLIC tools::SvRef< SotStorageStream > GetOptionStream(std::u16string_view rOptionName, SdOptionStreamMode eMode)
Open and return option stream for internal options; if the stream is opened for reading but does not ...
Definition: sdmod.cxx:165
virtual ~SdModule() override
Definition: sdmod.cxx:94
SD_DLLPUBLIC SvNumberFormatter * GetNumberFormatter()
Definition: sdmod.cxx:203
VclPtr< VirtualDevice > mpVirtualRefDevice
This device is used for printer independent layout.
Definition: sdmod.hxx:150
SdOptions * GetSdOptions(DocumentType eDocType)
Return options.
Definition: sdmod.cxx:126
tools::SvRef< SotStorage > xOptionStorage
Definition: sdmod.hxx:143
SdModule(SfxObjectFactory *pDrawObjFact, SfxObjectFactory *pGraphicObjFact)
Definition: sdmod.cxx:57
bool mbEventListenerAdded
Definition: sdmod.hxx:161
std::unique_ptr< SfxErrorHandler > mpErrorHdl
Definition: sdmod.hxx:145
std::unique_ptr< svtools::ColorConfig > mpColorConfig
Definition: sdmod.hxx:181
SdOptions * pImpressOptions
Definition: sdmod.hxx:139
std::unique_ptr< SvxSearchItem > pSearchItem
Definition: sdmod.hxx:141
sal_uInt16 GetMetric() const
Definition: optsitem.hxx:136
SfxHintId GetId() const
static SAL_WARN_UNUSED_RESULT SfxObjectShell * Current()
void PutItem(const SfxPoolItem &rItem)
static void ensure()
void disposeAndClear()
SdDrawDocument * GetDoc()
bool is() const
static std::unique_ptr< SvStream > CreateStream(const OUString &rFileName, StreamMode eOpenMode, css::uno::Reference< css::awt::XWindow > xParentWin=nullptr)
URL aURL
float u
DocumentType eType
Mode eMode
#define LANGUAGE_SYSTEM
OUString nget(TranslateNId aContextSingularPlural, int n, const std::locale &loc)
OUString get(TranslateId sContextAndId, const std::locale &loc)
DocumentType
OUString SdResId(TranslateId aId)
Definition: sdmod.cxx:83
#define SD_MOD()
Definition: sdmod.hxx:184
SdOptionStreamMode
Definition: sdmod.hxx:55
#define SFX_IMPL_INTERFACE(Class, SuperClass)