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