xref: /trunk/main/sd/source/ui/app/sdmod.cxx (revision 5b190011)
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 
74 SFX_IMPL_INTERFACE(SdModule, SfxModule, SdResId(STR_APPLICATIONOBJECTBAR))
75 {
76 	SFX_STATUSBAR_REGISTRATION(SdResId(RID_DRAW_STATUSBAR));
77 }
78 
79 /*************************************************************************
80 |*
81 |* Ctor
82 |*
83 \************************************************************************/
84 
85 SdModule::SdModule(SfxObjectFactory* pFact1, SfxObjectFactory* pFact2 )
86 :   SfxModule( SfxApplication::CreateResManager("sd"), sal_False,
87 				  pFact1, pFact2, NULL ),
88 	pTransferClip(NULL),
89 	pTransferDrag(NULL),
90     pTransferSelection(NULL),
91 	pImpressOptions(NULL),
92 	pDrawOptions(NULL),
93 	pSearchItem(NULL),
94 	pNumberFormatter( NULL ),
95 	bWaterCan(sal_False),
96     mpResourceContainer(new ::sd::SdGlobalResourceContainer())
97 {
98 	SetName( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "StarDraw" ) ) );	// Nicht uebersetzen!
99     pSearchItem = new SvxSearchItem(SID_SEARCH_ITEM);
100 	pSearchItem->SetAppFlag(SVX_SEARCHAPP_DRAW);
101 	StartListening( *SFX_APP() );
102 	SvxErrorHandler::Get();
103 	mpErrorHdl = new SfxErrorHandler( RID_SD_ERRHDL,
104 										 ERRCODE_AREA_SD,
105 										 ERRCODE_AREA_SD_END,
106 										 GetResMgr() );
107 
108     // Create a new ref device and (by calling SetReferenceDevice())
109     // set its resolution to 600 DPI.  This leads to a visually better
110     // formatting of text in small sizes (6 point and below.)
111     VirtualDevice* pDevice = new VirtualDevice;
112     mpVirtualRefDevice = pDevice;
113     pDevice->SetMapMode( MAP_100TH_MM );
114     pDevice->SetReferenceDevice ( VirtualDevice::REFDEV_MODE06 );
115 }
116 
117 
118 
119 /*************************************************************************
120 |*
121 |* Dtor
122 |*
123 \************************************************************************/
124 
125 SdModule::~SdModule()
126 {
127     delete pSearchItem;
128 
129     if( pNumberFormatter )
130 	delete pNumberFormatter;
131 
132     ::sd::DrawDocShell* pDocShell = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current());
133     if( pDocShell )
134     {
135         ::sd::ViewShell* pViewShell = pDocShell->GetViewShell();
136         if (pViewShell)
137         {
138             // Removing our event listener
139             Application::RemoveEventListener( LINK( this, SdModule, EventListenerHdl ) );
140         }
141     }
142 
143     mpResourceContainer.reset();
144 
145     // Mark the module in the global AppData structure as deleted.
146     SdModule** ppShellPointer = (SdModule**)GetAppData(SHL_DRAW);
147     if (ppShellPointer != NULL)
148         (*ppShellPointer) = NULL;
149 
150     delete mpErrorHdl;
151     delete static_cast< VirtualDevice* >( mpVirtualRefDevice );
152 }
153 
154 
155 /*************************************************************************
156 |*
157 |* get notifications
158 |*
159 \************************************************************************/
160 
161 void SdModule::Notify( SfxBroadcaster&, const SfxHint& rHint )
162 {
163 	if( rHint.ISA( SfxSimpleHint ) &&
164 		( (SfxSimpleHint&) rHint ).GetId() == SFX_HINT_DEINITIALIZING )
165 	{
166 		delete pImpressOptions, pImpressOptions = NULL;
167 		delete pDrawOptions, pDrawOptions = NULL;
168 	}
169 }
170 
171 /*************************************************************************
172 |*
173 |* Optionen zurueckgeben
174 |*
175 \************************************************************************/
176 
177 SdOptions* SdModule::GetSdOptions(DocumentType eDocType)
178 {
179 	SdOptions* pOptions = NULL;
180 
181 	if (eDocType == DOCUMENT_TYPE_DRAW)
182 	{
183 		if (!pDrawOptions)
184 			pDrawOptions = new SdOptions( SDCFG_DRAW );
185 
186 		pOptions = pDrawOptions;
187 	}
188 	else if (eDocType == DOCUMENT_TYPE_IMPRESS)
189 	{
190 		if (!pImpressOptions)
191 			pImpressOptions = new SdOptions( SDCFG_IMPRESS );
192 
193 		pOptions = pImpressOptions;
194 	}
195 	if( pOptions )
196 	{
197 		sal_uInt16 nMetric = pOptions->GetMetric();
198 
199 		::sd::DrawDocShell* pDocSh = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current() );
200 		SdDrawDocument* pDoc = NULL;
201 		if (pDocSh)
202 			pDoc = pDocSh->GetDoc();
203 
204 		if( nMetric != 0xffff && pDoc && eDocType == pDoc->GetDocumentType() )
205 			PutItem( SfxUInt16Item( SID_ATTR_METRIC, nMetric ) );
206 	}
207 
208 	return(pOptions);
209 }
210 
211 /*************************************************************************
212 |*
213 |* Optionen-Stream fuer interne Options oeffnen und zurueckgeben;
214 |* falls der Stream zum Lesen geoeffnet wird, aber noch nicht
215 |* angelegt wurde, wird ein 'leeres' RefObject zurueckgegeben
216 |*
217 \************************************************************************/
218 
219 SvStorageStreamRef SdModule::GetOptionStream( const String& rOptionName,
220 											  SdOptionStreamMode eMode )
221 {
222 	::sd::DrawDocShell*		pDocSh = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current() );
223 	SvStorageStreamRef	xStm;
224 
225 	if( pDocSh )
226 	{
227 		DocumentType	eType = pDocSh->GetDoc()->GetDocumentType();
228 		String			aStmName;
229 
230 		if( !xOptionStorage.Is() )
231 		{
232 			INetURLObject aURL( SvtPathOptions().GetUserConfigPath() );
233 
234 			aURL.Append( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "drawing.cfg" ) ) );
235 
236 			SvStream* pStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READWRITE );
237 
238 			if( pStm )
239 				xOptionStorage = new SvStorage( pStm, sal_True );
240 		}
241 
242 		if( DOCUMENT_TYPE_DRAW == eType )
243 			aStmName.AssignAscii( RTL_CONSTASCII_STRINGPARAM( "Draw_" ) );
244 		else
245 			aStmName.AssignAscii( RTL_CONSTASCII_STRINGPARAM( "Impress_" ) );
246 
247 		aStmName += rOptionName;
248 
249 		if( SD_OPTION_STORE == eMode || xOptionStorage->IsContained( aStmName ) )
250             xStm = xOptionStorage->OpenSotStream( aStmName );
251 	}
252 
253 	return xStm;
254 }
255 
256 /*************************************************************************
257 |*
258 \************************************************************************/
259 
260 SvNumberFormatter* SdModule::GetNumberFormatter()
261 {
262 	if( !pNumberFormatter )
263 		pNumberFormatter = new SvNumberFormatter( ::comphelper::getProcessServiceFactory(), LANGUAGE_SYSTEM );
264 
265 	return pNumberFormatter;
266 }
267 
268 /*************************************************************************
269 |*
270 \************************************************************************/
271 
272 OutputDevice* SdModule::GetVirtualRefDevice (void)
273 {
274     return mpVirtualRefDevice;
275 }
276 
277 /** This method is deprecated and only an alias to
278     <member>GetVirtualRefDevice()</member>.  The given argument is ignored.
279 */
280 OutputDevice* SdModule::GetRefDevice (::sd::DrawDocShell& )
281 {
282     return GetVirtualRefDevice();
283 }
284