Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <vcl/status.hxx>
21 : #include <vcl/msgbox.hxx>
22 : #include <svl/whiter.hxx>
23 : #include <svl/stritem.hxx>
24 : #include <svl/intitem.hxx>
25 : #include <svl/eitem.hxx>
26 : #include <svtools/filter.hxx>
27 : #include <unotools/internaloptions.hxx>
28 : #include <unotools/pathoptions.hxx>
29 : #include <com/sun/star/registry/InvalidRegistryException.hpp>
30 : #include <com/sun/star/beans/PropertyValue.hpp>
31 : #include <com/sun/star/frame/XFrame.hpp>
32 : #include <com/sun/star/util/XURLTransformer.hpp>
33 : #include <com/sun/star/frame/XFramesSupplier.hpp>
34 : #include <com/sun/star/uno/Reference.h>
35 : #include <tools/rcid.h>
36 : #include <osl/mutex.hxx>
37 : #include <unotools/configmgr.hxx>
38 : #include <com/sun/star/frame/XDesktop.hpp>
39 : #include <unotools/ucbstreamhelper.hxx>
40 : #include <framework/menuconfiguration.hxx>
41 : #include <comphelper/processfactory.hxx>
42 : #include <unotools/localfilehelper.hxx>
43 : #include <unotools/bootstrap.hxx>
44 : #include <unotools/moduleoptions.hxx>
45 : #include <osl/file.hxx>
46 : #include <rtl/bootstrap.hxx>
47 :
48 : #include "sfx2/sfxresid.hxx"
49 : #include <sfx2/app.hxx>
50 : #include "appdata.hxx"
51 : #include "arrdecl.hxx"
52 : #include <sfx2/tbxctrl.hxx>
53 : #include "sfx2/stbitem.hxx"
54 : #include <sfx2/mnuitem.hxx>
55 : #include <sfx2/docfac.hxx>
56 : #include <sfx2/docfile.hxx>
57 : #include <sfx2/docfilt.hxx>
58 : #include <sfx2/request.hxx>
59 : #include <sfx2/bindings.hxx>
60 : #include <sfx2/dispatch.hxx>
61 : #include "workwin.hxx"
62 : #include <sfx2/fcontnr.hxx>
63 : #include "sfxlocal.hrc"
64 : #include <sfx2/sfx.hrc>
65 : #include "app.hrc"
66 : #include <sfx2/templdlg.hxx>
67 : #include <sfx2/module.hxx>
68 : #include <sfx2/msgpool.hxx>
69 : #include <sfx2/viewfrm.hxx>
70 : #include "openflag.hxx"
71 : #include <sfx2/viewsh.hxx>
72 : #include <sfx2/objface.hxx>
73 : #include "helper.hxx" // SfxContentHelper::Kill()
74 :
75 : using namespace ::com::sun::star::uno;
76 : using namespace ::com::sun::star::util;
77 : using namespace ::com::sun::star::beans;
78 : using namespace ::com::sun::star::container;
79 :
80 : //===================================================================
81 :
82 : #define SfxApplication
83 : #include "sfxslots.hxx"
84 :
85 0 : class SfxSpecialConfigError_Impl
86 : {
87 : String aError;
88 :
89 : public:
90 :
91 : SfxSpecialConfigError_Impl( const String& rStr );
92 : DECL_LINK( TimerHdl, Timer*);
93 : };
94 :
95 :
96 0 : SfxSpecialConfigError_Impl::SfxSpecialConfigError_Impl( const String& rStr ) :
97 0 : aError( rStr )
98 : {
99 0 : Timer *pTimer = new Timer;
100 0 : pTimer->SetTimeoutHdl( LINK(this, SfxSpecialConfigError_Impl, TimerHdl) );
101 0 : pTimer->SetTimeout( 0 );
102 0 : pTimer->Start();
103 0 : }
104 :
105 0 : IMPL_LINK( SfxSpecialConfigError_Impl, TimerHdl, Timer*, pTimer )
106 : {
107 0 : delete pTimer;
108 0 : ErrorBox( 0, WinBits( WB_OK ) , aError ).Execute();
109 0 : delete this;
110 0 : SFX_APP()->GetAppDispatcher_Impl()->Execute( SID_QUITAPP );
111 0 : return 0L;
112 : }
113 :
114 : //====================================================================
115 :
116 : #define SFX_ITEMTYPE_STATBAR 4
117 :
118 1454 : SFX_IMPL_INTERFACE(SfxApplication,SfxShell,SfxResId(RID_DESKTOP))
119 : {
120 19 : SFX_STATUSBAR_REGISTRATION(SfxResId(SFX_ITEMTYPE_STATBAR));
121 19 : SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_0);
122 19 : SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_1);
123 19 : SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_2);
124 19 : SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_3);
125 19 : SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_4);
126 19 : SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_5);
127 19 : SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_6);
128 19 : SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_7);
129 19 : SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_8);
130 19 : SFX_CHILDWINDOW_REGISTRATION(SID_DOCKWIN_9);
131 19 : }
132 :
133 : //--------------------------------------------------------------------
134 678 : SfxProgress* SfxApplication::GetProgress() const
135 :
136 : /* [Description]
137 :
138 : Returns the running SfxProgress for the entire application or 0 if
139 : none is running for the entire application.
140 :
141 : [Cross-reference]
142 :
143 : <SfxProgress::GetActiveProgress(SfxViewFrame*)>
144 : <SfxViewFrame::GetProgress()const>
145 : */
146 :
147 : {
148 678 : return pAppData_Impl->pProgress;
149 : }
150 :
151 : //------------------------------------------------------------------------
152 :
153 263 : std::vector<sal_uInt16>* SfxApplication::GetDisabledSlotList_Impl()
154 : {
155 263 : sal_Bool bError = sal_False;
156 263 : std::vector<sal_uInt16>* pList = pAppData_Impl->pDisabledSlotList;
157 263 : if ( !pList )
158 : {
159 : // Is there a slot file?
160 19 : INetURLObject aUserObj( SvtPathOptions().GetUserConfigPath() );
161 19 : aUserObj.insertName( DEFINE_CONST_UNICODE( "slots.cfg" ) );
162 19 : SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( aUserObj.GetMainURL( INetURLObject::NO_DECODE ), STREAM_STD_READ );
163 19 : if ( !pStream || pStream->GetError() == ERRCODE_IO_NOTEXISTS )
164 : {
165 19 : delete pStream;
166 19 : INetURLObject aObj( SvtPathOptions().GetConfigPath() );
167 19 : aObj.insertName( DEFINE_CONST_UNICODE( "slots.cfg" ) );
168 19 : pStream = ::utl::UcbStreamHelper::CreateStream( aObj.GetMainURL( INetURLObject::NO_DECODE ), STREAM_STD_READ );
169 : }
170 :
171 19 : sal_Bool bSlotsEnabled = SvtInternalOptions().SlotCFGEnabled();
172 19 : sal_Bool bSlots = ( pStream && !pStream->GetError() );
173 19 : if( bSlots && bSlotsEnabled )
174 : {
175 : // Read Slot file
176 0 : String aTitle = pStream->ReadUniOrByteString(pStream->GetStreamCharSet());
177 0 : if ( aTitle.CompareToAscii("SfxSlotFile" ) == COMPARE_EQUAL )
178 : {
179 : sal_uInt16 nCount;
180 0 : (*pStream) >> nCount;
181 : pList = pAppData_Impl->pDisabledSlotList =
182 0 : new std::vector<sal_uInt16>;
183 :
184 : sal_uInt16 nSlot;
185 0 : for ( sal_uInt16 n=0; n<nCount; n++ )
186 : {
187 0 : (*pStream) >> nSlot;
188 0 : pList->push_back( nSlot );
189 : }
190 :
191 0 : aTitle = pStream->ReadUniOrByteString(pStream->GetStreamCharSet());
192 0 : if ( aTitle.CompareToAscii("END" ) != COMPARE_EQUAL || pStream->GetError() )
193 : {
194 : // Read failed
195 0 : DELETEZ( pList );
196 0 : bError = sal_True;
197 : }
198 : }
199 : else
200 : {
201 : // Stream detection failure
202 0 : bError = sal_True;
203 0 : }
204 : }
205 19 : else if ( bSlots != bSlotsEnabled )
206 : {
207 : // If no slot list entry, then no slot file shall exist
208 0 : bError = sal_True;
209 : }
210 :
211 19 : delete pStream;
212 : }
213 244 : else if ( pList == (std::vector<sal_uInt16>*) -1L )
214 : {
215 244 : return NULL;
216 : }
217 :
218 19 : if ( !pList )
219 19 : pAppData_Impl->pDisabledSlotList = (std::vector<sal_uInt16>*) -1L;
220 :
221 19 : if ( bError )
222 : {
223 : // If an entry slot is present, but no or faulty slot file, or a slot
224 : // file, but no slot entry, then this is considered to be a
225 : // misconfiguration
226 0 : new SfxSpecialConfigError_Impl( SfxResId( RID_SPECIALCONFIG_ERROR ).toString() );
227 : }
228 :
229 19 : return pList;
230 : }
231 :
232 :
233 0 : SfxModule* SfxApplication::GetModule_Impl()
234 : {
235 0 : SfxModule* pModule = SfxModule::GetActiveModule();
236 0 : if ( !pModule )
237 0 : pModule = SfxModule::GetActiveModule( SfxViewFrame::GetFirst( 0, sal_False ) );
238 0 : if( pModule )
239 0 : return pModule;
240 : else
241 : {
242 : OSL_FAIL( "No module!" );
243 0 : return NULL;
244 : }
245 : }
246 :
247 0 : ISfxTemplateCommon* SfxApplication::GetCurrentTemplateCommon( SfxBindings& rBindings )
248 : {
249 0 : if( pAppData_Impl->pTemplateCommon )
250 0 : return pAppData_Impl->pTemplateCommon;
251 : SfxChildWindow *pChild = rBindings.GetWorkWindow_Impl()->GetChildWindow_Impl(
252 0 : SfxTemplateDialogWrapper::GetChildWindowId() );
253 0 : if ( pChild )
254 0 : return ((SfxTemplateDialog*) pChild->GetWindow())->GetISfxTemplateCommon();
255 0 : return 0;
256 : }
257 :
258 8419 : sal_Bool SfxApplication::IsDowning() const { return pAppData_Impl->bDowning; }
259 0 : SfxDispatcher* SfxApplication::GetAppDispatcher_Impl() { return pAppData_Impl->pAppDispat; }
260 171 : SfxSlotPool& SfxApplication::GetAppSlotPool_Impl() const { return *pAppData_Impl->pSlotPool; }
261 :
262 : /** loads the application logo as used in the about dialog and impress slideshow pause screen */
263 0 : Image SfxApplication::GetApplicationLogo()
264 : {
265 0 : BitmapEx aBitmap;
266 0 : Application::LoadBrandBitmap ("about", aBitmap);
267 0 : return Image( aBitmap );
268 : }
269 :
270 0 : SfxChildWinFactArr_Impl::~SfxChildWinFactArr_Impl()
271 : {
272 0 : for( const_iterator it = begin(); it != end(); ++it )
273 0 : delete *it;
274 0 : }
275 :
276 0 : SfxMenuCtrlFactArr_Impl::~SfxMenuCtrlFactArr_Impl()
277 : {
278 0 : for( const_iterator it = begin(); it != end(); ++it )
279 0 : delete *it;
280 0 : }
281 :
282 0 : SfxStbCtrlFactArr_Impl::~SfxStbCtrlFactArr_Impl()
283 : {
284 0 : for( const_iterator it = begin(); it != end(); ++it )
285 0 : delete *it;
286 0 : }
287 :
288 0 : SfxTbxCtrlFactArr_Impl::~SfxTbxCtrlFactArr_Impl()
289 : {
290 0 : for( const_iterator it = begin(); it != end(); ++it )
291 0 : delete *it;
292 0 : }
293 :
294 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|