xref: /aoo42x/main/sd/source/ui/app/sdmod.cxx (revision 579128bd)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sd.hxx"
26 #include <unotools/pathoptions.hxx>
27 #include <svl/languageoptions.hxx>
28 #ifndef _UNOTOOLS_UCBSTREAMHELPER_HXX
29 #include <unotools/ucbstreamhelper.hxx>
30 #endif
31 #include <tools/urlobj.hxx>
32 #include <vcl/virdev.hxx>
33 #include <sfx2/app.hxx>
34 #include <vcl/status.hxx>
35 #include <svl/intitem.hxx>
36 #include <sfx2/msg.hxx>
37 #include <sfx2/objface.hxx>
38 #include <sfx2/printer.hxx>
39 #include <svx/pszctrl.hxx>
40 #include <svx/zoomctrl.hxx>
41 #include <svx/modctrl.hxx>
42 #include <svl/zforlist.hxx>
43 #include <comphelper/processfactory.hxx>
44 #include <svtools/ehdl.hxx>
45 
46 #include <svx/svxids.hrc>
47 #include <svl/srchitem.hxx>
48 #include <svx/svxerr.hxx>
49 
50 #include <svx/xmlsecctrl.hxx>
51 
52 
53 #define _SD_DLL // fuer SD_MOD()
54 #include "sderror.hxx"
55 #include "sdmod.hxx"
56 #include "sddll.hxx"
57 #include "sdresid.hxx"
58 #include "optsitem.hxx"
59 #include "DrawDocShell.hxx"
60 #include "drawdoc.hxx"
61 #include "app.hrc"
62 #include "glob.hrc"
63 #include "strings.hrc"
64 #include "res_bmp.hrc"
65 #include "cfgids.hxx"
66 #include "tools/SdGlobalResourceContainer.hxx"
67 
68 TYPEINIT1( SdModule, SfxModule );
69 
70 #define SdModule
71 #include "sdslots.hxx"
72 
73 
SFX_IMPL_INTERFACE(SdModule,SfxModule,SdResId (STR_APPLICATIONOBJECTBAR))74 SFX_IMPL_INTERFACE(SdModule, SfxModule, SdResId(STR_APPLICATIONOBJECTBAR))
75 {
76 	SFX_STATUSBAR_REGISTRATION(SdResId(RID_DRAW_STATUSBAR));
77 }
78 
79 /*************************************************************************
80 |* Ctor
81 \************************************************************************/
82 
SdModule(SfxObjectFactory * pFact1,SfxObjectFactory * pFact2)83 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 	mpResourceContainer(new ::sd::SdGlobalResourceContainer())
95 {
96 	SetName( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "StarDraw" ) ) );	// Nicht uebersetzen!
97 	pSearchItem = new SvxSearchItem(SID_SEARCH_ITEM);
98 	pSearchItem->SetAppFlag(SVX_SEARCHAPP_DRAW);
99 	StartListening( *SFX_APP() );
100 	SvxErrorHandler::Get();
101 	mpErrorHdl = new SfxErrorHandler( RID_SD_ERRHDL,
102 										 ERRCODE_AREA_SD,
103 										 ERRCODE_AREA_SD_END,
104 										 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 	VirtualDevice* pDevice = new VirtualDevice;
110 	mpVirtualRefDevice = pDevice;
111 	pDevice->SetMapMode( MAP_100TH_MM );
112 	pDevice->SetReferenceDevice ( VirtualDevice::REFDEV_MODE06 );
113 }
114 
115 
116 
117 /*************************************************************************
118 |* Dtor
119 \************************************************************************/
120 
~SdModule()121 SdModule::~SdModule()
122 {
123 	delete pSearchItem;
124 
125 	if( pNumberFormatter )
126 	delete pNumberFormatter;
127 
128 	::sd::DrawDocShell* pDocShell = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current());
129 	if( pDocShell )
130 	{
131 		::sd::ViewShell* pViewShell = pDocShell->GetViewShell();
132 		if (pViewShell)
133 		{
134 			// Removing our event listener
135 			Application::RemoveEventListener( LINK( this, SdModule, EventListenerHdl ) );
136 		}
137 	}
138 
139 	mpResourceContainer.reset();
140 
141 	// Mark the module in the global AppData structure as deleted.
142 	SdModule** ppShellPointer = (SdModule**)GetAppData(SHL_DRAW);
143 	if (ppShellPointer != NULL)
144 		(*ppShellPointer) = NULL;
145 
146 	delete mpErrorHdl;
147 	delete static_cast< VirtualDevice* >( mpVirtualRefDevice );
148 }
149 
150 
151 /*************************************************************************
152 |* get notifications
153 \************************************************************************/
154 
Notify(SfxBroadcaster &,const SfxHint & rHint)155 void SdModule::Notify( SfxBroadcaster&, const SfxHint& rHint )
156 {
157 	if( rHint.ISA( SfxSimpleHint ) &&
158 		( (SfxSimpleHint&) rHint ).GetId() == SFX_HINT_DEINITIALIZING )
159 	{
160 		delete pImpressOptions, pImpressOptions = NULL;
161 		delete pDrawOptions, pDrawOptions = NULL;
162 	}
163 }
164 
165 /*************************************************************************
166 |* return options
167 \************************************************************************/
168 
GetSdOptions(DocumentType eDocType)169 SdOptions* SdModule::GetSdOptions(DocumentType eDocType)
170 {
171 	SdOptions* pOptions = NULL;
172 
173 	if (eDocType == DOCUMENT_TYPE_DRAW)
174 	{
175 		if (!pDrawOptions)
176 			pDrawOptions = new SdOptions( SDCFG_DRAW );
177 
178 		pOptions = pDrawOptions;
179 	}
180 	else if (eDocType == DOCUMENT_TYPE_IMPRESS)
181 	{
182 		if (!pImpressOptions)
183 			pImpressOptions = new SdOptions( SDCFG_IMPRESS );
184 
185 		pOptions = pImpressOptions;
186 	}
187 	if( pOptions )
188 	{
189 		sal_uInt16 nMetric = pOptions->GetMetric();
190 
191 		::sd::DrawDocShell* pDocSh = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current() );
192 		SdDrawDocument* pDoc = NULL;
193 		if (pDocSh)
194 			pDoc = pDocSh->GetDoc();
195 
196 		if( nMetric != 0xffff && pDoc && eDocType == pDoc->GetDocumentType() )
197 			PutItem( SfxUInt16Item( SID_ATTR_METRIC, nMetric ) );
198 	}
199 
200 	return(pOptions);
201 }
202 
203 /*************************************************************************
204 |* Optionen-Stream fuer interne Options oeffnen und zurueckgeben;
205 |* falls der Stream zum Lesen geoeffnet wird, aber noch nicht
206 |* angelegt wurde, wird ein 'leeres' RefObject zurueckgegeben
207 \************************************************************************/
208 
GetOptionStream(const String & rOptionName,SdOptionStreamMode eMode)209 SvStorageStreamRef SdModule::GetOptionStream( const String& rOptionName,
210 											  SdOptionStreamMode eMode )
211 {
212 	::sd::DrawDocShell*		pDocSh = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current() );
213 	SvStorageStreamRef	xStm;
214 
215 	if( pDocSh )
216 	{
217 		DocumentType	eType = pDocSh->GetDoc()->GetDocumentType();
218 		String			aStmName;
219 
220 		if( !xOptionStorage.Is() )
221 		{
222 			INetURLObject aURL( SvtPathOptions().GetUserConfigPath() );
223 
224 			aURL.Append( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "drawing.cfg" ) ) );
225 
226 			SvStream* pStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READWRITE );
227 
228 			if( pStm )
229 				xOptionStorage = new SvStorage( pStm, sal_True );
230 		}
231 
232 		if( DOCUMENT_TYPE_DRAW == eType )
233 			aStmName.AssignAscii( RTL_CONSTASCII_STRINGPARAM( "Draw_" ) );
234 		else
235 			aStmName.AssignAscii( RTL_CONSTASCII_STRINGPARAM( "Impress_" ) );
236 
237 		aStmName += rOptionName;
238 
239 		if( SD_OPTION_STORE == eMode || xOptionStorage->IsContained( aStmName ) )
240 			xStm = xOptionStorage->OpenSotStream( aStmName );
241 	}
242 
243 	return xStm;
244 }
245 
246 /*************************************************************************
247 |*
248 \************************************************************************/
249 
GetNumberFormatter()250 SvNumberFormatter* SdModule::GetNumberFormatter()
251 {
252 	if( !pNumberFormatter )
253 		pNumberFormatter = new SvNumberFormatter( ::comphelper::getProcessServiceFactory(), LANGUAGE_SYSTEM );
254 
255 	return pNumberFormatter;
256 }
257 
258 /*************************************************************************
259 |*
260 \************************************************************************/
261 
GetVirtualRefDevice(void)262 OutputDevice* SdModule::GetVirtualRefDevice (void)
263 {
264 	return mpVirtualRefDevice;
265 }
266 
267 /** This method is deprecated and only an alias to
268 	<member>GetVirtualRefDevice()</member>. The given argument is ignored.
269 */
GetRefDevice(::sd::DrawDocShell &)270 OutputDevice* SdModule::GetRefDevice (::sd::DrawDocShell& )
271 {
272 	return GetVirtualRefDevice();
273 }
274