Line data Source code
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 <svl/languageoptions.hxx>
22 : #include <unotools/ucbstreamhelper.hxx>
23 : #include <tools/urlobj.hxx>
24 : #include <vcl/virdev.hxx>
25 : #include <sfx2/app.hxx>
26 : #include <vcl/status.hxx>
27 : #include <svl/intitem.hxx>
28 : #include <sfx2/msg.hxx>
29 : #include <sfx2/objface.hxx>
30 : #include <sfx2/printer.hxx>
31 : #include <svx/pszctrl.hxx>
32 : #include <svx/zoomctrl.hxx>
33 : #include <svx/modctrl.hxx>
34 : #include <svl/zforlist.hxx>
35 : #include <comphelper/processfactory.hxx>
36 : #include <svtools/ehdl.hxx>
37 :
38 : #include <svx/svxids.hrc>
39 : #include <svl/srchitem.hxx>
40 : #include <svx/svxerr.hxx>
41 :
42 : #include <svx/xmlsecctrl.hxx>
43 :
44 : #include "sderror.hxx"
45 : #include "sdmod.hxx"
46 : #include "sdresid.hxx"
47 : #include "optsitem.hxx"
48 : #include "DrawDocShell.hxx"
49 : #include "drawdoc.hxx"
50 : #include "app.hrc"
51 : #include "glob.hrc"
52 : #include "strings.hrc"
53 : #include "res_bmp.hrc"
54 : #include "cfgids.hxx"
55 : #include "tools/SdGlobalResourceContainer.hxx"
56 :
57 0 : TYPEINIT1( SdModule, SfxModule );
58 :
59 : #define SdModule
60 : #include "sdslots.hxx"
61 :
62 :
63 12 : SFX_IMPL_INTERFACE(SdModule, SfxModule, SdResId(STR_APPLICATIONOBJECTBAR))
64 : {
65 3 : SFX_STATUSBAR_REGISTRATION(SdResId(RID_DRAW_STATUSBAR));
66 3 : }
67 :
68 : /*************************************************************************
69 : |*
70 : |* Ctor
71 : |*
72 : \************************************************************************/
73 :
74 3 : SdModule::SdModule(SfxObjectFactory* pFact1, SfxObjectFactory* pFact2 )
75 : : SfxModule( SfxApplication::CreateResManager("sd"), sal_False,
76 : pFact1, pFact2, NULL ),
77 : pTransferClip(NULL),
78 : pTransferDrag(NULL),
79 : pTransferSelection(NULL),
80 : pImpressOptions(NULL),
81 : pDrawOptions(NULL),
82 : pSearchItem(NULL),
83 : pNumberFormatter( NULL ),
84 : bWaterCan(sal_False),
85 3 : mpResourceContainer(new ::sd::SdGlobalResourceContainer())
86 : {
87 3 : SetName( rtl::OUString( "StarDraw" ) ); // Nicht uebersetzen!
88 3 : pSearchItem = new SvxSearchItem(SID_SEARCH_ITEM);
89 3 : pSearchItem->SetAppFlag(SVX_SEARCHAPP_DRAW);
90 3 : StartListening( *SFX_APP() );
91 3 : SvxErrorHandler::ensure();
92 : mpErrorHdl = new SfxErrorHandler( RID_SD_ERRHDL,
93 : ERRCODE_AREA_SD,
94 : ERRCODE_AREA_SD_END,
95 3 : GetResMgr() );
96 :
97 : // Create a new ref device and (by calling SetReferenceDevice())
98 : // set its resolution to 600 DPI. This leads to a visually better
99 : // formatting of text in small sizes (6 point and below.)
100 3 : VirtualDevice* pDevice = new VirtualDevice;
101 3 : mpVirtualRefDevice = pDevice;
102 3 : pDevice->SetMapMode( MAP_100TH_MM );
103 3 : pDevice->SetReferenceDevice ( VirtualDevice::REFDEV_MODE06 );
104 3 : }
105 :
106 :
107 :
108 : /*************************************************************************
109 : |*
110 : |* Dtor
111 : |*
112 : \************************************************************************/
113 :
114 0 : SdModule::~SdModule()
115 : {
116 0 : delete pSearchItem;
117 :
118 0 : if( pNumberFormatter )
119 0 : delete pNumberFormatter;
120 :
121 0 : ::sd::DrawDocShell* pDocShell = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current());
122 0 : if( pDocShell )
123 : {
124 0 : ::sd::ViewShell* pViewShell = pDocShell->GetViewShell();
125 0 : if (pViewShell)
126 : {
127 : // Removing our event listener
128 0 : Application::RemoveEventListener( LINK( this, SdModule, EventListenerHdl ) );
129 : }
130 : }
131 :
132 0 : mpResourceContainer.reset();
133 :
134 : // Mark the module in the global AppData structure as deleted.
135 0 : SdModule** ppShellPointer = (SdModule**)GetAppData(SHL_DRAW);
136 0 : if (ppShellPointer != NULL)
137 0 : (*ppShellPointer) = NULL;
138 :
139 0 : delete mpErrorHdl;
140 0 : delete static_cast< VirtualDevice* >( mpVirtualRefDevice );
141 0 : }
142 :
143 :
144 : /*************************************************************************
145 : |*
146 : |* get notifications
147 : |*
148 : \************************************************************************/
149 :
150 12 : void SdModule::Notify( SfxBroadcaster&, const SfxHint& rHint )
151 : {
152 12 : if( rHint.ISA( SfxSimpleHint ) &&
153 0 : ( (SfxSimpleHint&) rHint ).GetId() == SFX_HINT_DEINITIALIZING )
154 : {
155 0 : delete pImpressOptions, pImpressOptions = NULL;
156 0 : delete pDrawOptions, pDrawOptions = NULL;
157 : }
158 12 : }
159 :
160 : /*************************************************************************
161 : |*
162 : |* Optionen zurueckgeben
163 : |*
164 : \************************************************************************/
165 :
166 76 : SdOptions* SdModule::GetSdOptions(DocumentType eDocType)
167 : {
168 76 : SdOptions* pOptions = NULL;
169 :
170 76 : if (eDocType == DOCUMENT_TYPE_DRAW)
171 : {
172 0 : if (!pDrawOptions)
173 0 : pDrawOptions = new SdOptions( SDCFG_DRAW );
174 :
175 0 : pOptions = pDrawOptions;
176 : }
177 76 : else if (eDocType == DOCUMENT_TYPE_IMPRESS)
178 : {
179 76 : if (!pImpressOptions)
180 3 : pImpressOptions = new SdOptions( SDCFG_IMPRESS );
181 :
182 76 : pOptions = pImpressOptions;
183 : }
184 76 : if( pOptions )
185 : {
186 76 : sal_uInt16 nMetric = pOptions->GetMetric();
187 :
188 76 : ::sd::DrawDocShell* pDocSh = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current() );
189 76 : SdDrawDocument* pDoc = NULL;
190 76 : if (pDocSh)
191 0 : pDoc = pDocSh->GetDoc();
192 :
193 76 : if( nMetric != 0xffff && pDoc && eDocType == pDoc->GetDocumentType() )
194 0 : PutItem( SfxUInt16Item( SID_ATTR_METRIC, nMetric ) );
195 : }
196 :
197 76 : return(pOptions);
198 : }
199 :
200 : /*************************************************************************
201 : |*
202 : |* Optionen-Stream fuer interne Options oeffnen und zurueckgeben;
203 : |* falls der Stream zum Lesen geoeffnet wird, aber noch nicht
204 : |* angelegt wurde, wird ein 'leeres' RefObject zurueckgegeben
205 : |*
206 : \************************************************************************/
207 :
208 0 : SvStorageStreamRef SdModule::GetOptionStream( const String& rOptionName,
209 : SdOptionStreamMode eMode )
210 : {
211 0 : ::sd::DrawDocShell* pDocSh = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current() );
212 0 : SvStorageStreamRef xStm;
213 :
214 0 : if( pDocSh )
215 : {
216 0 : DocumentType eType = pDocSh->GetDoc()->GetDocumentType();
217 0 : String aStmName;
218 :
219 0 : if( !xOptionStorage.Is() )
220 : {
221 0 : INetURLObject aURL( SvtPathOptions().GetUserConfigPath() );
222 :
223 0 : aURL.Append( rtl::OUString( "drawing.cfg" ) );
224 :
225 0 : SvStream* pStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READWRITE );
226 :
227 0 : if( pStm )
228 0 : xOptionStorage = new SvStorage( pStm, sal_True );
229 : }
230 :
231 0 : if( DOCUMENT_TYPE_DRAW == eType )
232 0 : aStmName.AssignAscii( RTL_CONSTASCII_STRINGPARAM( "Draw_" ) );
233 : else
234 0 : aStmName.AssignAscii( RTL_CONSTASCII_STRINGPARAM( "Impress_" ) );
235 :
236 0 : aStmName += rOptionName;
237 :
238 0 : if( SD_OPTION_STORE == eMode || xOptionStorage->IsContained( aStmName ) )
239 0 : xStm = xOptionStorage->OpenSotStream( aStmName );
240 : }
241 :
242 0 : return xStm;
243 : }
244 :
245 0 : SvNumberFormatter* SdModule::GetNumberFormatter()
246 : {
247 0 : if( !pNumberFormatter )
248 0 : pNumberFormatter = new SvNumberFormatter( ::comphelper::getProcessServiceFactory(), LANGUAGE_SYSTEM );
249 :
250 0 : return pNumberFormatter;
251 : }
252 :
253 60 : OutputDevice* SdModule::GetVirtualRefDevice (void)
254 : {
255 60 : return mpVirtualRefDevice;
256 : }
257 :
258 : /** This method is deprecated and only an alias to
259 : <member>GetVirtualRefDevice()</member>. The given argument is ignored.
260 : */
261 21 : OutputDevice* SdModule::GetRefDevice (::sd::DrawDocShell& )
262 : {
263 21 : return GetVirtualRefDevice();
264 9 : }
265 :
266 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|