1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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/intitem.hxx>
27 #include <sfx2/msg.hxx>
28 #include <sfx2/objface.hxx>
29 #include <svl/zforlist.hxx>
30 #include <comphelper/processfactory.hxx>
31 #include <svtools/ehdl.hxx>
33 #include <svx/svxids.hrc>
34 #include <svl/srchitem.hxx>
35 #include <svx/svxerr.hxx>
37 #include <svtools/colorcfg.hxx>
40 #include <sdresid.hxx>
41 #include <optsitem.hxx>
42 #include <DrawDocShell.hxx>
43 #include <drawdoc.hxx>
46 #define ShellClass_SdModule
47 #include <sdslots.hxx>
49 SFX_IMPL_INTERFACE(SdModule
, SfxModule
)
51 void SdModule::InitInterface_Impl()
53 GetStaticInterface()->RegisterStatusBar(StatusBarId::DrawStatusBar
);
57 SdModule::SdModule(SfxObjectFactory
* pFact1
, SfxObjectFactory
* pFact2
)
58 : SfxModule("sd", {pFact1
, pFact2
}),
59 pTransferClip(nullptr),
60 pTransferDrag(nullptr),
61 pTransferSelection(nullptr),
62 pImpressOptions(nullptr),
63 pDrawOptions(nullptr),
65 mbEventListenerAdded(false),
66 mpColorConfig(new svtools::ColorConfig
)
68 SetName( "StarDraw" ); // Do not translate!
69 pSearchItem
.reset( new SvxSearchItem(SID_SEARCH_ITEM
) );
70 pSearchItem
->SetAppFlag(SvxSearchApp::DRAW
);
71 StartListening( *SfxGetpApp() );
72 SvxErrorHandler::ensure();
73 mpErrorHdl
.reset( new SfxErrorHandler(RID_SD_ERRHDL
, ErrCodeArea::Sd
, ErrCodeArea::Sd
, GetResLocale()) );
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
);
83 OUString
SdResId(const char* pId
)
85 return Translate::get(pId
, SD_MOD()->GetResLocale());
88 OUString
SdResId(const char* pId
, int nCardinality
)
90 return Translate::nget(pId
, nCardinality
, SD_MOD()->GetResLocale());
97 pNumberFormatter
.reset();
99 if (mbEventListenerAdded
)
101 Application::RemoveEventListener( LINK( this, SdModule
, EventListenerHdl
) );
105 mpVirtualRefDevice
.disposeAndClear();
108 void SdModule::SetSearchItem(std::unique_ptr
<SvxSearchItem
> pItem
)
110 pSearchItem
= std::move(pItem
);
113 /// get notifications
114 void SdModule::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
116 if( rHint
.GetId() == SfxHintId::Deinitializing
)
118 delete pImpressOptions
;
119 pImpressOptions
= nullptr;
121 pDrawOptions
= nullptr;
126 SdOptions
* SdModule::GetSdOptions(DocumentType eDocType
)
128 SdOptions
* pOptions
= nullptr;
130 if (eDocType
== DocumentType::Draw
)
133 pDrawOptions
= new SdOptions(false);
135 pOptions
= pDrawOptions
;
137 else if (eDocType
== DocumentType::Impress
)
139 if (!pImpressOptions
)
140 pImpressOptions
= new SdOptions(true);
142 pOptions
= pImpressOptions
;
146 sal_uInt16 nMetric
= pOptions
->GetMetric();
148 ::sd::DrawDocShell
* pDocSh
= dynamic_cast< ::sd::DrawDocShell
*>( SfxObjectShell::Current() );
149 SdDrawDocument
* pDoc
= nullptr;
151 pDoc
= pDocSh
->GetDoc();
153 if( nMetric
!= 0xffff && pDoc
&& eDocType
== pDoc
->GetDocumentType() )
154 PutItem( SfxUInt16Item( SID_ATTR_METRIC
, nMetric
) );
161 * Open and return option stream for internal options;
162 * if the stream is opened for reading but does not exist, an 'empty'
163 * RefObject is returned
165 tools::SvRef
<SotStorageStream
> SdModule::GetOptionStream( const OUString
& rOptionName
,
166 SdOptionStreamMode eMode
)
168 ::sd::DrawDocShell
* pDocSh
= dynamic_cast< ::sd::DrawDocShell
*>( SfxObjectShell::Current() );
169 tools::SvRef
<SotStorageStream
> xStm
;
173 DocumentType eType
= pDocSh
->GetDoc()->GetDocumentType();
175 if( !xOptionStorage
.is() )
177 INetURLObject
aURL( SvtPathOptions().GetUserConfigPath() );
179 aURL
.Append( "drawing.cfg" );
181 std::unique_ptr
<SvStream
> pStm
= ::utl::UcbStreamHelper::CreateStream( aURL
.GetMainURL( INetURLObject::DecodeMechanism::NONE
), StreamMode::READWRITE
);
184 xOptionStorage
= new SotStorage( pStm
.release(), true );
189 if( DocumentType::Draw
== eType
)
192 aStmName
= "Impress_";
194 aStmName
+= rOptionName
;
196 if( SdOptionStreamMode::Store
== eMode
|| xOptionStorage
->IsContained( aStmName
) )
197 xStm
= xOptionStorage
->OpenSotStream( aStmName
);
203 SvNumberFormatter
* SdModule::GetNumberFormatter()
205 if( !pNumberFormatter
)
206 pNumberFormatter
.reset( new SvNumberFormatter( ::comphelper::getProcessComponentContext(), LANGUAGE_SYSTEM
) );
208 return pNumberFormatter
.get();
211 svtools::ColorConfig
& SdModule::GetColorConfig()
213 return *mpColorConfig
;
216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */