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