merge the formfield patch from ooo-build
[ooovba.git] / sfx2 / source / appl / appmisc.cxx
blob1768229b1d68eef0b55035d93abb0ffbb05d62da
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: appmisc.cxx,v $
10 * $Revision: 1.58 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sfx2.hxx"
33 #include <vcl/status.hxx>
34 #include <vcl/msgbox.hxx>
35 #ifndef _VOS_PROCESS_HXX //autogen
36 #include <vos/process.hxx>
37 #endif
38 #include <vos/xception.hxx>
39 #include <svtools/whiter.hxx>
40 #include <svtools/stritem.hxx>
41 #include <svtools/intitem.hxx>
42 #include <svtools/eitem.hxx>
43 #include <svtools/filter.hxx>
44 #include <svtools/internaloptions.hxx>
45 #include <svtools/pathoptions.hxx>
46 #include <com/sun/star/registry/InvalidRegistryException.hpp>
47 #ifndef _COM_SUN_STAR_BEANS_PropertyValue_HPP_
48 #include <com/sun/star/beans/PropertyValue.hpp>
49 #endif
50 #include <com/sun/star/frame/XFrame.hpp>
51 #include <com/sun/star/util/XURLTransformer.hpp>
52 #include <com/sun/star/frame/XFramesSupplier.hpp>
53 #include <com/sun/star/uno/Reference.h>
54 #include <tools/config.hxx>
55 #include <tools/rcid.h>
56 #include <vos/mutex.hxx>
57 #ifndef GCC
58 #endif
59 #include <unotools/configmgr.hxx>
60 #include <com/sun/star/frame/XDesktop.hpp>
62 #include <unotools/ucbstreamhelper.hxx>
63 #include <framework/menuconfiguration.hxx>
64 #include <comphelper/processfactory.hxx>
65 #include <unotools/localfilehelper.hxx>
66 #include <unotools/bootstrap.hxx>
67 #include <svtools/moduleoptions.hxx>
68 #include <osl/file.hxx>
70 #include "sfxresid.hxx"
71 #include <sfx2/app.hxx>
72 #include "appdata.hxx"
73 #include "arrdecl.hxx"
74 #include <sfx2/tbxctrl.hxx>
75 #include "stbitem.hxx"
76 #include <sfx2/mnuitem.hxx>
77 #include <sfx2/docfac.hxx>
78 #include <sfx2/docfile.hxx>
79 #include <sfx2/docfilt.hxx>
80 #include <sfx2/request.hxx>
81 #include <sfx2/bindings.hxx>
82 #include <sfx2/dispatch.hxx>
83 #include "workwin.hxx"
84 #include "intro.hxx"
85 #include <sfx2/fcontnr.hxx>
86 #include "sfxlocal.hrc"
87 #include <sfx2/sfx.hrc>
88 #include "app.hrc"
89 #include <sfx2/templdlg.hxx>
90 #include <sfx2/module.hxx>
91 #include <sfx2/msgpool.hxx>
92 #include <sfx2/topfrm.hxx>
93 #include "openflag.hxx"
94 #include <sfx2/viewsh.hxx>
95 #include <sfx2/objface.hxx>
96 #include "helper.hxx" // SfxContentHelper::Kill()
98 using namespace ::vos;
99 using namespace ::com::sun::star::uno;
100 using namespace ::com::sun::star::util;
101 using namespace ::com::sun::star::beans;
102 using namespace ::com::sun::star::container;
104 //===================================================================
106 SV_IMPL_PTRARR( SfxTbxCtrlFactArr_Impl, SfxTbxCtrlFactory* );
107 SV_IMPL_PTRARR( SfxStbCtrlFactArr_Impl, SfxStbCtrlFactory* );
108 SV_IMPL_PTRARR( SfxMenuCtrlFactArr_Impl, SfxMenuCtrlFactory* );
109 SV_IMPL_PTRARR( SfxChildWinFactArr_Impl, SfxChildWinFactory* );
110 SV_IMPL_PTRARR( SfxModuleArr_Impl, SfxModule* );
112 //===================================================================
114 #define SfxApplication
115 #include "sfxslots.hxx"
117 class SfxSpecialConfigError_Impl
119 String aError;
121 public:
123 SfxSpecialConfigError_Impl( const String& rStr );
124 DECL_LINK( TimerHdl, Timer*);
128 SfxSpecialConfigError_Impl::SfxSpecialConfigError_Impl( const String& rStr ) :
129 aError( rStr )
131 Timer *pTimer = new Timer;
132 pTimer->SetTimeoutHdl( LINK(this, SfxSpecialConfigError_Impl, TimerHdl) );
133 pTimer->SetTimeout( 0 );
134 pTimer->Start();
137 IMPL_LINK( SfxSpecialConfigError_Impl, TimerHdl, Timer*, pTimer )
139 delete pTimer;
140 ErrorBox( 0, WinBits( WB_OK ) , aError ).Execute();
141 delete this;
142 SFX_APP()->GetAppDispatcher_Impl()->Execute( SID_QUITAPP );
143 return 0L;
146 //====================================================================
148 #define SFX_ITEMTYPE_STATBAR 4
150 SFX_IMPL_INTERFACE(SfxApplication,SfxShell,SfxResId(RID_DESKTOP))
152 SFX_STATUSBAR_REGISTRATION(SfxResId(SFX_ITEMTYPE_STATBAR));
153 SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_0);
154 SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_1);
155 SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_2);
156 SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_3);
157 SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_4);
158 SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_5);
159 SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_6);
160 SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_7);
161 SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_8);
162 SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_9);
165 //--------------------------------------------------------------------
167 void SfxApplication::InitializeDisplayName_Impl()
169 SfxAppData_Impl* pAppData = Get_Impl();
170 if ( !pAppData->pLabelResMgr )
171 return;
173 String aTitle = Application::GetDisplayName();
174 if ( !aTitle.Len() )
176 OClearableGuard aGuard( OMutex::getGlobalMutex() );
178 // create version string
179 /*!!! (pb) don't show a version number at the moment
180 USHORT nProductVersion = ProductVersion::GetVersion().ToInt32();
181 String aVersion( String::CreateFromInt32( nProductVersion / 10 ) );
182 aVersion += 0x002E ; // 2Eh ^= '.'
183 aVersion += ( String::CreateFromInt32( nProductVersion % 10 ) );
185 // load application title
186 aTitle = String( ResId( RID_APPTITLE, *pAppData->pLabelResMgr ) );
187 // merge version into title
188 aTitle.SearchAndReplaceAscii( "$(VER)", String() /*aVersion*/ );
190 aGuard.clear();
192 #ifndef PRODUCT
193 ::rtl::OUString aDefault;
194 aTitle += DEFINE_CONST_UNICODE(" [");
196 String aVerId( utl::Bootstrap::getBuildIdData( aDefault ));
197 aTitle += aVerId;
198 aTitle += ']';
199 #endif
200 Application::SetDisplayName( aTitle );
204 //--------------------------------------------------------------------
205 SfxProgress* SfxApplication::GetProgress() const
207 /* [Beschreibung]
209 Liefert den f"ur die gesamte Applikation laufenden SfxProgress
210 oder 0, falls keiner f"ur die gesamte Applikation l"auft.
213 [Querverweise]
215 <SfxProgress::GetActiveProgress(SfxViewFrame*)>
216 <SfxViewFrame::GetProgress()const>
220 return pAppData_Impl->pProgress;
223 //------------------------------------------------------------------------
225 SvUShorts* SfxApplication::GetDisabledSlotList_Impl()
227 sal_Bool bError = sal_False;
228 SvUShorts* pList = pAppData_Impl->pDisabledSlotList;
229 if ( !pList )
231 // Gibt es eine Slotdatei ?
232 INetURLObject aUserObj( SvtPathOptions().GetUserConfigPath() );
233 aUserObj.insertName( DEFINE_CONST_UNICODE( "slots.cfg" ) );
234 SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( aUserObj.GetMainURL( INetURLObject::NO_DECODE ), STREAM_STD_READ );
235 if ( !pStream || pStream->GetError() == ERRCODE_IO_NOTEXISTS )
237 delete pStream;
238 INetURLObject aObj( SvtPathOptions().GetConfigPath() );
239 aObj.insertName( DEFINE_CONST_UNICODE( "slots.cfg" ) );
240 pStream = ::utl::UcbStreamHelper::CreateStream( aObj.GetMainURL( INetURLObject::NO_DECODE ), STREAM_STD_READ );
243 BOOL bSlotsEnabled = SvtInternalOptions().SlotCFGEnabled();
244 BOOL bSlots = ( pStream && !pStream->GetError() );
245 if( bSlots && bSlotsEnabled )
247 // SlotDatei einlesen
248 String aTitle;
249 pStream->ReadByteString(aTitle);
250 if ( aTitle.CompareToAscii("SfxSlotFile" ) == COMPARE_EQUAL )
252 sal_uInt16 nCount;
253 (*pStream) >> nCount;
254 pList = pAppData_Impl->pDisabledSlotList =
255 new SvUShorts( nCount < 255 ? (sal_Int8) nCount : 255, 255 );
257 sal_uInt16 nSlot;
258 for ( sal_uInt16 n=0; n<nCount; n++ )
260 (*pStream) >> nSlot;
261 pList->Insert( nSlot, n );
264 pStream->ReadByteString(aTitle);
265 if ( aTitle.CompareToAscii("END" ) != COMPARE_EQUAL || pStream->GetError() )
267 // Lesen schief gegangen
268 DELETEZ( pList );
269 bError = sal_True;
272 else
274 // Streamerkennung fehlgeschlagen
275 bError = sal_True;
278 else if ( bSlots != bSlotsEnabled )
280 // Wenn kein Slotlist-Eintrag, dann darf auch keine SlotDatei
281 // vorhanden sein
282 bError = sal_True;
285 delete pStream;
287 else if ( pList == (SvUShorts*) -1L )
289 return NULL;
292 if ( !pList )
293 pAppData_Impl->pDisabledSlotList = (SvUShorts*) -1L;
295 if ( bError )
297 // Wenn ein Sloteintrag vorhanden ist, aber keine oder eine fehlerhafte
298 // SlotDatei, oder aber eine Slotdatei, aber kein Sloteintrag, dann
299 // gilt dies als fehlerhafte Konfiguration
300 new SfxSpecialConfigError_Impl( String( SfxResId( RID_SPECIALCONFIG_ERROR ) ) );
303 return pList;
307 SfxModule* SfxApplication::GetModule_Impl()
309 SfxModule* pModule = SfxModule::GetActiveModule();
310 if ( !pModule )
311 pModule = SfxModule::GetActiveModule( SfxViewFrame::GetFirst( FALSE ) );
312 if( pModule )
313 return pModule;
314 else
316 DBG_ERROR( "No module!" );
317 return NULL;
321 ISfxTemplateCommon* SfxApplication::GetCurrentTemplateCommon( SfxBindings& rBindings )
323 if( pAppData_Impl->pTemplateCommon )
324 return pAppData_Impl->pTemplateCommon;
325 SfxChildWindow *pChild = rBindings.GetWorkWindow_Impl()->GetChildWindow_Impl(
326 SfxTemplateDialogWrapper::GetChildWindowId() );
327 if ( pChild )
328 return ((SfxTemplateDialog*) pChild->GetWindow())->GetISfxTemplateCommon();
329 return 0;
332 SfxCancelManager* SfxApplication::GetCancelManager() const
334 if ( !pAppData_Impl->pCancelMgr )
335 pAppData_Impl->pCancelMgr = new SfxCancelManager;
336 return pAppData_Impl->pCancelMgr;
339 SfxResourceManager& SfxApplication::GetResourceManager() const { return *pAppData_Impl->pResMgr; }
340 BOOL SfxApplication::IsDowning() const { return pAppData_Impl->bDowning; }
341 SfxDispatcher* SfxApplication::GetAppDispatcher_Impl() { return pAppData_Impl->pAppDispat; }
342 SfxSlotPool& SfxApplication::GetAppSlotPool_Impl() const { return *pAppData_Impl->pSlotPool; }
343 //SfxOptions& SfxApplication::GetOptions() { return *pAppData_Impl->pOptions; }
344 //const SfxOptions& SfxApplication::GetOptions() const { return *pAppData_Impl->pOptions; }