Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / sfx2 / source / appl / appmisc.cxx
blob1e62b634e6b5848b27eb7270bedc192c7153f98e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <vcl/status.hxx>
30 #include <vcl/msgbox.hxx>
31 #include <svl/whiter.hxx>
32 #include <svl/stritem.hxx>
33 #include <svl/intitem.hxx>
34 #include <svl/eitem.hxx>
35 #include <svtools/filter.hxx>
36 #include <unotools/internaloptions.hxx>
37 #include <unotools/pathoptions.hxx>
38 #include <com/sun/star/registry/InvalidRegistryException.hpp>
39 #include <com/sun/star/beans/PropertyValue.hpp>
40 #include <com/sun/star/frame/XFrame.hpp>
41 #include <com/sun/star/util/XURLTransformer.hpp>
42 #include <com/sun/star/frame/XFramesSupplier.hpp>
43 #include <com/sun/star/uno/Reference.h>
44 #include <tools/rcid.h>
45 #include <osl/mutex.hxx>
46 #include <unotools/configmgr.hxx>
47 #include <com/sun/star/frame/XDesktop.hpp>
48 #include <unotools/ucbstreamhelper.hxx>
49 #include <framework/menuconfiguration.hxx>
50 #include <comphelper/processfactory.hxx>
51 #include <unotools/localfilehelper.hxx>
52 #include <unotools/bootstrap.hxx>
53 #include <unotools/moduleoptions.hxx>
54 #include <osl/file.hxx>
55 #include <rtl/bootstrap.hxx>
57 #include "sfx2/sfxresid.hxx"
58 #include <sfx2/app.hxx>
59 #include "appdata.hxx"
60 #include "arrdecl.hxx"
61 #include <sfx2/tbxctrl.hxx>
62 #include "sfx2/stbitem.hxx"
63 #include <sfx2/mnuitem.hxx>
64 #include <sfx2/docfac.hxx>
65 #include <sfx2/docfile.hxx>
66 #include <sfx2/docfilt.hxx>
67 #include <sfx2/request.hxx>
68 #include <sfx2/bindings.hxx>
69 #include <sfx2/dispatch.hxx>
70 #include "workwin.hxx"
71 #include <sfx2/fcontnr.hxx>
72 #include "sfxlocal.hrc"
73 #include <sfx2/sfx.hrc>
74 #include "app.hrc"
75 #include <sfx2/templdlg.hxx>
76 #include <sfx2/module.hxx>
77 #include <sfx2/msgpool.hxx>
78 #include <sfx2/viewfrm.hxx>
79 #include "openflag.hxx"
80 #include <sfx2/viewsh.hxx>
81 #include <sfx2/objface.hxx>
82 #include "helper.hxx" // SfxContentHelper::Kill()
84 using namespace ::com::sun::star::uno;
85 using namespace ::com::sun::star::util;
86 using namespace ::com::sun::star::beans;
87 using namespace ::com::sun::star::container;
89 //===================================================================
91 SV_IMPL_PTRARR( SfxTbxCtrlFactArr_Impl, SfxTbxCtrlFactory* );
92 SV_IMPL_PTRARR( SfxStbCtrlFactArr_Impl, SfxStbCtrlFactory* );
93 SV_IMPL_PTRARR( SfxMenuCtrlFactArr_Impl, SfxMenuCtrlFactory* );
94 SV_IMPL_PTRARR( SfxChildWinFactArr_Impl, SfxChildWinFactory* );
95 SV_IMPL_PTRARR( SfxModuleArr_Impl, SfxModule* );
97 //===================================================================
99 #define SfxApplication
100 #include "sfxslots.hxx"
102 class SfxSpecialConfigError_Impl
104 String aError;
106 public:
108 SfxSpecialConfigError_Impl( const String& rStr );
109 DECL_LINK( TimerHdl, Timer*);
113 SfxSpecialConfigError_Impl::SfxSpecialConfigError_Impl( const String& rStr ) :
114 aError( rStr )
116 Timer *pTimer = new Timer;
117 pTimer->SetTimeoutHdl( LINK(this, SfxSpecialConfigError_Impl, TimerHdl) );
118 pTimer->SetTimeout( 0 );
119 pTimer->Start();
122 IMPL_LINK( SfxSpecialConfigError_Impl, TimerHdl, Timer*, pTimer )
124 delete pTimer;
125 ErrorBox( 0, WinBits( WB_OK ) , aError ).Execute();
126 delete this;
127 SFX_APP()->GetAppDispatcher_Impl()->Execute( SID_QUITAPP );
128 return 0L;
131 //====================================================================
133 #define SFX_ITEMTYPE_STATBAR 4
135 SFX_IMPL_INTERFACE(SfxApplication,SfxShell,SfxResId(RID_DESKTOP))
137 SFX_STATUSBAR_REGISTRATION(SfxResId(SFX_ITEMTYPE_STATBAR));
138 SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_0);
139 SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_1);
140 SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_2);
141 SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_3);
142 SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_4);
143 SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_5);
144 SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_6);
145 SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_7);
146 SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_8);
147 SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_9);
150 //--------------------------------------------------------------------
151 SfxProgress* SfxApplication::GetProgress() const
153 /* [Description]
155 Returns the running SfxProgress for the entire application or 0 if
156 none is running for the entire application.
158 [Cross-reference]
160 <SfxProgress::GetActiveProgress(SfxViewFrame*)>
161 <SfxViewFrame::GetProgress()const>
165 return pAppData_Impl->pProgress;
168 //------------------------------------------------------------------------
170 std::vector<sal_uInt16>* SfxApplication::GetDisabledSlotList_Impl()
172 sal_Bool bError = sal_False;
173 std::vector<sal_uInt16>* pList = pAppData_Impl->pDisabledSlotList;
174 if ( !pList )
176 // Is there a slot file?
177 INetURLObject aUserObj( SvtPathOptions().GetUserConfigPath() );
178 aUserObj.insertName( DEFINE_CONST_UNICODE( "slots.cfg" ) );
179 SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( aUserObj.GetMainURL( INetURLObject::NO_DECODE ), STREAM_STD_READ );
180 if ( !pStream || pStream->GetError() == ERRCODE_IO_NOTEXISTS )
182 delete pStream;
183 INetURLObject aObj( SvtPathOptions().GetConfigPath() );
184 aObj.insertName( DEFINE_CONST_UNICODE( "slots.cfg" ) );
185 pStream = ::utl::UcbStreamHelper::CreateStream( aObj.GetMainURL( INetURLObject::NO_DECODE ), STREAM_STD_READ );
188 sal_Bool bSlotsEnabled = SvtInternalOptions().SlotCFGEnabled();
189 sal_Bool bSlots = ( pStream && !pStream->GetError() );
190 if( bSlots && bSlotsEnabled )
192 // Read Slot file
193 String aTitle = pStream->ReadUniOrByteString(pStream->GetStreamCharSet());
194 if ( aTitle.CompareToAscii("SfxSlotFile" ) == COMPARE_EQUAL )
196 sal_uInt16 nCount;
197 (*pStream) >> nCount;
198 pList = pAppData_Impl->pDisabledSlotList =
199 new std::vector<sal_uInt16>;
201 sal_uInt16 nSlot;
202 for ( sal_uInt16 n=0; n<nCount; n++ )
204 (*pStream) >> nSlot;
205 pList->push_back( nSlot );
208 aTitle = pStream->ReadUniOrByteString(pStream->GetStreamCharSet());
209 if ( aTitle.CompareToAscii("END" ) != COMPARE_EQUAL || pStream->GetError() )
211 // Read failed
212 DELETEZ( pList );
213 bError = sal_True;
216 else
218 // Stream detection failure
219 bError = sal_True;
222 else if ( bSlots != bSlotsEnabled )
224 // If no slot list entry, then no slot file shall exist
225 bError = sal_True;
228 delete pStream;
230 else if ( pList == (std::vector<sal_uInt16>*) -1L )
232 return NULL;
235 if ( !pList )
236 pAppData_Impl->pDisabledSlotList = (std::vector<sal_uInt16>*) -1L;
238 if ( bError )
240 // If an entry slot is present, but no or faulty slot file, or a slot
241 // file, but no slot entry, then this is considered to be a
242 // misconfiguration
243 new SfxSpecialConfigError_Impl( String( SfxResId( RID_SPECIALCONFIG_ERROR ) ) );
246 return pList;
250 SfxModule* SfxApplication::GetModule_Impl()
252 SfxModule* pModule = SfxModule::GetActiveModule();
253 if ( !pModule )
254 pModule = SfxModule::GetActiveModule( SfxViewFrame::GetFirst( sal_False ) );
255 if( pModule )
256 return pModule;
257 else
259 OSL_FAIL( "No module!" );
260 return NULL;
264 ISfxTemplateCommon* SfxApplication::GetCurrentTemplateCommon( SfxBindings& rBindings )
266 if( pAppData_Impl->pTemplateCommon )
267 return pAppData_Impl->pTemplateCommon;
268 SfxChildWindow *pChild = rBindings.GetWorkWindow_Impl()->GetChildWindow_Impl(
269 SfxTemplateDialogWrapper::GetChildWindowId() );
270 if ( pChild )
271 return ((SfxTemplateDialog*) pChild->GetWindow())->GetISfxTemplateCommon();
272 return 0;
275 sal_Bool SfxApplication::IsDowning() const { return pAppData_Impl->bDowning; }
276 SfxDispatcher* SfxApplication::GetAppDispatcher_Impl() { return pAppData_Impl->pAppDispat; }
277 SfxSlotPool& SfxApplication::GetAppSlotPool_Impl() const { return *pAppData_Impl->pSlotPool; }
279 /** loads the application logo as used in the about dialog and impress slideshow pause screen */
280 Image SfxApplication::GetApplicationLogo()
282 BitmapEx aBitmap;
283 Application::LoadBrandBitmap ("about", aBitmap);
284 return Image( aBitmap );
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */