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_sfx2.hxx" 26 #include <vcl/status.hxx> 27 #include <vcl/msgbox.hxx> 28 #include <vos/process.hxx> 29 #include <vos/xception.hxx> 30 #include <svl/whiter.hxx> 31 #include <svl/stritem.hxx> 32 #include <svl/intitem.hxx> 33 #include <svl/eitem.hxx> 34 #include <svtools/filter.hxx> 35 #include <unotools/internaloptions.hxx> 36 #include <unotools/pathoptions.hxx> 37 #include <com/sun/star/registry/InvalidRegistryException.hpp> 38 #include <com/sun/star/beans/PropertyValue.hpp> 39 #include <com/sun/star/frame/XFrame.hpp> 40 #include <com/sun/star/util/XURLTransformer.hpp> 41 #include <com/sun/star/frame/XFramesSupplier.hpp> 42 #include <com/sun/star/uno/Reference.h> 43 #include <tools/config.hxx> 44 #include <tools/rcid.h> 45 #include <vos/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> 56 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 "intro.hxx" 72 #include <sfx2/fcontnr.hxx> 73 #include "sfxlocal.hrc" 74 #include <sfx2/sfx.hrc> 75 #include "app.hrc" 76 #include <sfx2/templdlg.hxx> 77 #include <sfx2/module.hxx> 78 #include <sfx2/msgpool.hxx> 79 #include <sfx2/viewfrm.hxx> 80 #include "openflag.hxx" 81 #include <sfx2/viewsh.hxx> 82 #include <sfx2/objface.hxx> 83 #include "helper.hxx" // SfxContentHelper::Kill() 84 85 using namespace ::vos; 86 using namespace ::com::sun::star::uno; 87 using namespace ::com::sun::star::util; 88 using namespace ::com::sun::star::beans; 89 using namespace ::com::sun::star::container; 90 91 //=================================================================== 92 93 SV_IMPL_PTRARR( SfxTbxCtrlFactArr_Impl, SfxTbxCtrlFactory* ); 94 SV_IMPL_PTRARR( SfxStbCtrlFactArr_Impl, SfxStbCtrlFactory* ); 95 SV_IMPL_PTRARR( SfxMenuCtrlFactArr_Impl, SfxMenuCtrlFactory* ); 96 SV_IMPL_PTRARR( SfxChildWinFactArr_Impl, SfxChildWinFactory* ); 97 SV_IMPL_PTRARR( SfxModuleArr_Impl, SfxModule* ); 98 99 //=================================================================== 100 101 #define SfxApplication 102 #include "sfxslots.hxx" 103 104 class SfxSpecialConfigError_Impl 105 { 106 String aError; 107 108 public: 109 110 SfxSpecialConfigError_Impl( const String& rStr ); 111 DECL_LINK( TimerHdl, Timer*); 112 }; 113 114 115 SfxSpecialConfigError_Impl::SfxSpecialConfigError_Impl( const String& rStr ) : 116 aError( rStr ) 117 { 118 Timer *pTimer = new Timer; 119 pTimer->SetTimeoutHdl( LINK(this, SfxSpecialConfigError_Impl, TimerHdl) ); 120 pTimer->SetTimeout( 0 ); 121 pTimer->Start(); 122 } 123 124 IMPL_LINK( SfxSpecialConfigError_Impl, TimerHdl, Timer*, pTimer ) 125 { 126 delete pTimer; 127 ErrorBox( 0, WinBits( WB_OK ) , aError ).Execute(); 128 delete this; 129 SFX_APP()->GetAppDispatcher_Impl()->Execute( SID_QUITAPP ); 130 return 0L; 131 } 132 133 //==================================================================== 134 135 #define SFX_ITEMTYPE_STATBAR 4 136 137 SFX_IMPL_INTERFACE(SfxApplication,SfxShell,SfxResId(RID_DESKTOP)) 138 { 139 SFX_STATUSBAR_REGISTRATION(SfxResId(SFX_ITEMTYPE_STATBAR)); 140 SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_0); 141 SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_1); 142 SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_2); 143 SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_3); 144 SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_4); 145 SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_5); 146 SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_6); 147 SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_7); 148 SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_8); 149 SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_9); 150 } 151 152 //-------------------------------------------------------------------- 153 SfxProgress* SfxApplication::GetProgress() const 154 155 /* [Beschreibung] 156 157 Liefert den f"ur die gesamte Applikation laufenden SfxProgress 158 oder 0, falls keiner f"ur die gesamte Applikation l"auft. 159 160 161 [Querverweise] 162 163 <SfxProgress::GetActiveProgress(SfxViewFrame*)> 164 <SfxViewFrame::GetProgress()const> 165 */ 166 167 { 168 return pAppData_Impl->pProgress; 169 } 170 171 //------------------------------------------------------------------------ 172 173 SvUShorts* SfxApplication::GetDisabledSlotList_Impl() 174 { 175 sal_Bool bError = sal_False; 176 SvUShorts* pList = pAppData_Impl->pDisabledSlotList; 177 if ( !pList ) 178 { 179 // Gibt es eine Slotdatei ? 180 INetURLObject aUserObj( SvtPathOptions().GetUserConfigPath() ); 181 aUserObj.insertName( DEFINE_CONST_UNICODE( "slots.cfg" ) ); 182 SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( aUserObj.GetMainURL( INetURLObject::NO_DECODE ), STREAM_STD_READ ); 183 if ( !pStream || pStream->GetError() == ERRCODE_IO_NOTEXISTS ) 184 { 185 delete pStream; 186 INetURLObject aObj( SvtPathOptions().GetConfigPath() ); 187 aObj.insertName( DEFINE_CONST_UNICODE( "slots.cfg" ) ); 188 pStream = ::utl::UcbStreamHelper::CreateStream( aObj.GetMainURL( INetURLObject::NO_DECODE ), STREAM_STD_READ ); 189 } 190 191 sal_Bool bSlotsEnabled = SvtInternalOptions().SlotCFGEnabled(); 192 sal_Bool bSlots = ( pStream && !pStream->GetError() ); 193 if( bSlots && bSlotsEnabled ) 194 { 195 // SlotDatei einlesen 196 String aTitle; 197 pStream->ReadByteString(aTitle); 198 if ( aTitle.CompareToAscii("SfxSlotFile" ) == COMPARE_EQUAL ) 199 { 200 sal_uInt16 nCount; 201 (*pStream) >> nCount; 202 pList = pAppData_Impl->pDisabledSlotList = 203 new SvUShorts( nCount < 255 ? (sal_Int8) nCount : 255, 255 ); 204 205 sal_uInt16 nSlot; 206 for ( sal_uInt16 n=0; n<nCount; n++ ) 207 { 208 (*pStream) >> nSlot; 209 pList->Insert( nSlot, n ); 210 } 211 212 pStream->ReadByteString(aTitle); 213 if ( aTitle.CompareToAscii("END" ) != COMPARE_EQUAL || pStream->GetError() ) 214 { 215 // Lesen schief gegangen 216 DELETEZ( pList ); 217 bError = sal_True; 218 } 219 } 220 else 221 { 222 // Streamerkennung fehlgeschlagen 223 bError = sal_True; 224 } 225 } 226 else if ( bSlots != bSlotsEnabled ) 227 { 228 // Wenn kein Slotlist-Eintrag, dann darf auch keine SlotDatei 229 // vorhanden sein 230 bError = sal_True; 231 } 232 233 delete pStream; 234 } 235 else if ( pList == (SvUShorts*) -1L ) 236 { 237 return NULL; 238 } 239 240 if ( !pList ) 241 pAppData_Impl->pDisabledSlotList = (SvUShorts*) -1L; 242 243 if ( bError ) 244 { 245 // Wenn ein Sloteintrag vorhanden ist, aber keine oder eine fehlerhafte 246 // SlotDatei, oder aber eine Slotdatei, aber kein Sloteintrag, dann 247 // gilt dies als fehlerhafte Konfiguration 248 new SfxSpecialConfigError_Impl( String( SfxResId( RID_SPECIALCONFIG_ERROR ) ) ); 249 } 250 251 return pList; 252 } 253 254 255 SfxModule* SfxApplication::GetModule_Impl() 256 { 257 SfxModule* pModule = SfxModule::GetActiveModule(); 258 if ( !pModule ) 259 pModule = SfxModule::GetActiveModule( SfxViewFrame::GetFirst( sal_False ) ); 260 if( pModule ) 261 return pModule; 262 else 263 { 264 DBG_ERROR( "No module!" ); 265 return NULL; 266 } 267 } 268 269 ISfxTemplateCommon* SfxApplication::GetCurrentTemplateCommon( SfxBindings& rBindings ) 270 { 271 if( pAppData_Impl->pTemplateCommon ) 272 return pAppData_Impl->pTemplateCommon; 273 SfxChildWindow *pChild = rBindings.GetWorkWindow_Impl()->GetChildWindow_Impl( 274 SfxTemplateDialogWrapper::GetChildWindowId() ); 275 if ( pChild ) 276 return ((SfxTemplateDialog*) pChild->GetWindow())->GetISfxTemplateCommon(); 277 return 0; 278 } 279 280 SfxResourceManager& SfxApplication::GetResourceManager() const { return *pAppData_Impl->pResMgr; } 281 sal_Bool SfxApplication::IsDowning() const { return pAppData_Impl->bDowning; } 282 SfxDispatcher* SfxApplication::GetAppDispatcher_Impl() { return pAppData_Impl->pAppDispat; } 283 SfxSlotPool& SfxApplication::GetAppSlotPool_Impl() const { return *pAppData_Impl->pSlotPool; } 284 //SfxOptions& SfxApplication::GetOptions() { return *pAppData_Impl->pOptions; } 285 //const SfxOptions& SfxApplication::GetOptions() const { return *pAppData_Impl->pOptions; } 286