xref: /aoo41x/main/sfx2/source/appl/appmisc.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_sfx2.hxx"
30 #include <vcl/status.hxx>
31 #include <vcl/msgbox.hxx>
32 #include <vos/process.hxx>
33 #include <vos/xception.hxx>
34 #include <svl/whiter.hxx>
35 #include <svl/stritem.hxx>
36 #include <svl/intitem.hxx>
37 #include <svl/eitem.hxx>
38 #include <svtools/filter.hxx>
39 #include <unotools/internaloptions.hxx>
40 #include <unotools/pathoptions.hxx>
41 #include <com/sun/star/registry/InvalidRegistryException.hpp>
42 #include <com/sun/star/beans/PropertyValue.hpp>
43 #include <com/sun/star/frame/XFrame.hpp>
44 #include <com/sun/star/util/XURLTransformer.hpp>
45 #include <com/sun/star/frame/XFramesSupplier.hpp>
46 #include <com/sun/star/uno/Reference.h>
47 #include <tools/config.hxx>
48 #include <tools/rcid.h>
49 #include <vos/mutex.hxx>
50 #include <unotools/configmgr.hxx>
51 #include <com/sun/star/frame/XDesktop.hpp>
52 #include <unotools/ucbstreamhelper.hxx>
53 #include <framework/menuconfiguration.hxx>
54 #include <comphelper/processfactory.hxx>
55 #include <unotools/localfilehelper.hxx>
56 #include <unotools/bootstrap.hxx>
57 #include <unotools/moduleoptions.hxx>
58 #include <osl/file.hxx>
59 #include <rtl/bootstrap.hxx>
60 
61 #include "sfx2/sfxresid.hxx"
62 #include <sfx2/app.hxx>
63 #include "appdata.hxx"
64 #include "arrdecl.hxx"
65 #include <sfx2/tbxctrl.hxx>
66 #include "sfx2/stbitem.hxx"
67 #include <sfx2/mnuitem.hxx>
68 #include <sfx2/docfac.hxx>
69 #include <sfx2/docfile.hxx>
70 #include <sfx2/docfilt.hxx>
71 #include <sfx2/request.hxx>
72 #include <sfx2/bindings.hxx>
73 #include <sfx2/dispatch.hxx>
74 #include "workwin.hxx"
75 #include "intro.hxx"
76 #include <sfx2/fcontnr.hxx>
77 #include "sfxlocal.hrc"
78 #include <sfx2/sfx.hrc>
79 #include "app.hrc"
80 #include <sfx2/templdlg.hxx>
81 #include <sfx2/module.hxx>
82 #include <sfx2/msgpool.hxx>
83 #include <sfx2/viewfrm.hxx>
84 #include "openflag.hxx"
85 #include <sfx2/viewsh.hxx>
86 #include <sfx2/objface.hxx>
87 #include "helper.hxx"	// SfxContentHelper::Kill()
88 
89 using namespace ::vos;
90 using namespace ::com::sun::star::uno;
91 using namespace ::com::sun::star::util;
92 using namespace ::com::sun::star::beans;
93 using namespace ::com::sun::star::container;
94 
95 //===================================================================
96 
97 SV_IMPL_PTRARR( SfxTbxCtrlFactArr_Impl, SfxTbxCtrlFactory* );
98 SV_IMPL_PTRARR( SfxStbCtrlFactArr_Impl, SfxStbCtrlFactory* );
99 SV_IMPL_PTRARR( SfxMenuCtrlFactArr_Impl, SfxMenuCtrlFactory* );
100 SV_IMPL_PTRARR( SfxChildWinFactArr_Impl, SfxChildWinFactory* );
101 SV_IMPL_PTRARR( SfxModuleArr_Impl, SfxModule* );
102 
103 //===================================================================
104 
105 #define SfxApplication
106 #include "sfxslots.hxx"
107 
108 class SfxSpecialConfigError_Impl
109 {
110 	String aError;
111 
112 public:
113 
114 	SfxSpecialConfigError_Impl( const String& rStr );
115 	DECL_LINK( TimerHdl, Timer*);
116 };
117 
118 
119 SfxSpecialConfigError_Impl::SfxSpecialConfigError_Impl( const String& rStr ) :
120 	aError( rStr )
121 {
122 	Timer *pTimer = new Timer;
123 	pTimer->SetTimeoutHdl( LINK(this, SfxSpecialConfigError_Impl, TimerHdl) );
124 	pTimer->SetTimeout( 0 );
125 	pTimer->Start();
126 }
127 
128 IMPL_LINK( SfxSpecialConfigError_Impl, TimerHdl, Timer*, pTimer )
129 {
130 	delete pTimer;
131 	ErrorBox( 0, WinBits( WB_OK ) , aError ).Execute();
132 	delete this;
133     SFX_APP()->GetAppDispatcher_Impl()->Execute( SID_QUITAPP );
134 	return 0L;
135 }
136 
137 //====================================================================
138 
139 #define SFX_ITEMTYPE_STATBAR			 4
140 
141 SFX_IMPL_INTERFACE(SfxApplication,SfxShell,SfxResId(RID_DESKTOP))
142 {
143     SFX_STATUSBAR_REGISTRATION(SfxResId(SFX_ITEMTYPE_STATBAR));
144     SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_0);
145     SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_1);
146     SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_2);
147     SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_3);
148     SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_4);
149     SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_5);
150     SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_6);
151     SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_7);
152     SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_8);
153     SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_9);
154 }
155 
156 //--------------------------------------------------------------------
157 SfxProgress* SfxApplication::GetProgress() const
158 
159 /*  [Beschreibung]
160 
161     Liefert den f"ur die gesamte Applikation laufenden SfxProgress
162     oder 0, falls keiner f"ur die gesamte Applikation l"auft.
163 
164 
165     [Querverweise]
166 
167     <SfxProgress::GetActiveProgress(SfxViewFrame*)>
168     <SfxViewFrame::GetProgress()const>
169 */
170 
171 {
172     return pAppData_Impl->pProgress;
173 }
174 
175 //------------------------------------------------------------------------
176 
177 SvUShorts* SfxApplication::GetDisabledSlotList_Impl()
178 {
179 	sal_Bool bError = sal_False;
180 	SvUShorts* pList = pAppData_Impl->pDisabledSlotList;
181 	if ( !pList )
182 	{
183 		// Gibt es eine Slotdatei ?
184         INetURLObject aUserObj( SvtPathOptions().GetUserConfigPath() );
185         aUserObj.insertName( DEFINE_CONST_UNICODE( "slots.cfg" ) );
186         SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( aUserObj.GetMainURL( INetURLObject::NO_DECODE ), STREAM_STD_READ );
187         if ( !pStream || pStream->GetError() == ERRCODE_IO_NOTEXISTS )
188         {
189             delete pStream;
190             INetURLObject aObj( SvtPathOptions().GetConfigPath() );
191             aObj.insertName( DEFINE_CONST_UNICODE( "slots.cfg" ) );
192             pStream = ::utl::UcbStreamHelper::CreateStream( aObj.GetMainURL( INetURLObject::NO_DECODE ), STREAM_STD_READ );
193         }
194 
195         sal_Bool bSlotsEnabled = SvtInternalOptions().SlotCFGEnabled();
196         sal_Bool bSlots = ( pStream && !pStream->GetError() );
197         if( bSlots && bSlotsEnabled )
198 		{
199             // SlotDatei einlesen
200             String aTitle;
201             pStream->ReadByteString(aTitle);
202             if ( aTitle.CompareToAscii("SfxSlotFile" ) == COMPARE_EQUAL )
203             {
204                 sal_uInt16 nCount;
205                 (*pStream) >> nCount;
206                 pList = pAppData_Impl->pDisabledSlotList =
207                         new SvUShorts( nCount < 255 ? (sal_Int8) nCount : 255, 255 );
208 
209                 sal_uInt16 nSlot;
210                 for ( sal_uInt16 n=0; n<nCount; n++ )
211                 {
212                     (*pStream) >> nSlot;
213                     pList->Insert( nSlot, n );
214                 }
215 
216                 pStream->ReadByteString(aTitle);
217                 if ( aTitle.CompareToAscii("END" ) != COMPARE_EQUAL || pStream->GetError() )
218                 {
219                     // Lesen schief gegangen
220                     DELETEZ( pList );
221                     bError = sal_True;
222                 }
223             }
224             else
225             {
226                 // Streamerkennung  fehlgeschlagen
227                 bError = sal_True;
228             }
229 		}
230         else if ( bSlots != bSlotsEnabled )
231 		{
232 			// Wenn kein Slotlist-Eintrag, dann darf auch keine SlotDatei
233 			// vorhanden sein
234             bError = sal_True;
235 		}
236 
237         delete pStream;
238 	}
239 	else if ( pList == (SvUShorts*) -1L )
240 	{
241 		return NULL;
242 	}
243 
244 	if ( !pList )
245 		pAppData_Impl->pDisabledSlotList = (SvUShorts*) -1L;
246 
247 	if ( bError )
248 	{
249 		// Wenn ein Sloteintrag vorhanden ist, aber keine oder eine fehlerhafte
250 		// SlotDatei, oder aber eine Slotdatei, aber kein Sloteintrag, dann
251 		// gilt dies als fehlerhafte Konfiguration
252         new SfxSpecialConfigError_Impl( String( SfxResId( RID_SPECIALCONFIG_ERROR ) ) );
253 	}
254 
255    	return pList;
256 }
257 
258 
259 SfxModule* SfxApplication::GetModule_Impl()
260 {
261     SfxModule* pModule = SfxModule::GetActiveModule();
262     if ( !pModule )
263         pModule = SfxModule::GetActiveModule( SfxViewFrame::GetFirst( sal_False ) );
264 	if( pModule )
265 		return pModule;
266     else
267     {
268         DBG_ERROR( "No module!" );
269         return NULL;
270     }
271 }
272 
273 ISfxTemplateCommon* SfxApplication::GetCurrentTemplateCommon( SfxBindings& rBindings )
274 {
275 	if( pAppData_Impl->pTemplateCommon )
276 		return pAppData_Impl->pTemplateCommon;
277 	SfxChildWindow *pChild = rBindings.GetWorkWindow_Impl()->GetChildWindow_Impl(
278 		SfxTemplateDialogWrapper::GetChildWindowId() );
279 	if ( pChild )
280 		return ((SfxTemplateDialog*) pChild->GetWindow())->GetISfxTemplateCommon();
281 	return 0;
282 }
283 
284 SfxResourceManager& SfxApplication::GetResourceManager() const { return *pAppData_Impl->pResMgr; }
285 sal_Bool  SfxApplication::IsDowning() const { return pAppData_Impl->bDowning; }
286 SfxDispatcher* SfxApplication::GetAppDispatcher_Impl() { return pAppData_Impl->pAppDispat; }
287 SfxSlotPool& SfxApplication::GetAppSlotPool_Impl() const { return *pAppData_Impl->pSlotPool; }
288 //SfxOptions&  SfxApplication::GetOptions() { return *pAppData_Impl->pOptions; }
289 //const SfxOptions& SfxApplication::GetOptions() const { return *pAppData_Impl->pOptions; }
290 
291 static bool impl_loadBitmap(
292     const rtl::OUString &rPath, const rtl::OUString &rBmpFileName,
293     Image &rLogo )
294 {
295     rtl::OUString uri( rPath );
296     rtl::Bootstrap::expandMacros( uri );
297     INetURLObject aObj( uri );
298     aObj.insertName( rBmpFileName );
299     SvFileStream aStrm( aObj.PathToFileName(), STREAM_STD_READ );
300     if ( !aStrm.GetError() )
301     {
302         // Use graphic class to also support more graphic formats (bmp,png,...)
303         Graphic aGraphic;
304 
305         GraphicFilter* pGF = GraphicFilter::GetGraphicFilter();
306         pGF->ImportGraphic( aGraphic, String(), aStrm, GRFILTER_FORMAT_DONTKNOW );
307 
308         // Default case, we load the intro bitmap from a seperate file
309         // (e.g. staroffice_intro.bmp or starsuite_intro.bmp)
310         BitmapEx aBmp = aGraphic.GetBitmapEx();
311         rLogo = Image( aBmp );
312         return true;
313     }
314     return false;
315 }
316 
317 /** loads the application logo as used in the about dialog and impress slideshow pause screen */
318 Image SfxApplication::GetApplicationLogo()
319 {
320 	Image aAppLogo;
321 
322     rtl::OUString aAbouts;
323     bool bLoaded = false;
324     sal_Int32 nIndex = 0;
325     do
326     {
327         bLoaded = impl_loadBitmap(
328             rtl::OUString::createFromAscii( "$BRAND_BASE_DIR/program" ),
329             aAbouts.getToken( 0, ',', nIndex ), aAppLogo );
330     }
331     while ( !bLoaded && ( nIndex >= 0 ) );
332 
333     // fallback to "about.bmp"
334     if ( !bLoaded )
335     {
336         bLoaded = impl_loadBitmap(
337             rtl::OUString::createFromAscii( "$BRAND_BASE_DIR/program/edition" ),
338             rtl::OUString::createFromAscii( "about.png" ), aAppLogo );
339         if ( !bLoaded )
340             bLoaded = impl_loadBitmap(
341                 rtl::OUString::createFromAscii( "$BRAND_BASE_DIR/program/edition" ),
342                 rtl::OUString::createFromAscii( "about.bmp" ), aAppLogo );
343     }
344 
345     if ( !bLoaded )
346     {
347         bLoaded = impl_loadBitmap(
348             rtl::OUString::createFromAscii( "$BRAND_BASE_DIR/program" ),
349             rtl::OUString::createFromAscii( "about.png" ), aAppLogo );
350         if ( !bLoaded )
351             bLoaded = impl_loadBitmap(
352                 rtl::OUString::createFromAscii( "$BRAND_BASE_DIR/program" ),
353                 rtl::OUString::createFromAscii( "about.bmp" ), aAppLogo );
354     }
355 
356 	return aAppLogo;
357 }
358 
359