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