Bump version to 4.1-6
[LibreOffice.git] / sfx2 / source / view / viewfrm.cxx
blobe857318c0e8b56ec3f9cff7faffd0fc4d5ffe20a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <config_features.h>
22 #include <stdio.h>
24 #include <sfx2/infobar.hxx>
25 #include <sfx2/viewfrm.hxx>
26 #include <com/sun/star/document/MacroExecMode.hpp>
27 #include <com/sun/star/frame/Desktop.hpp>
28 #include <com/sun/star/frame/DispatchRecorder.hpp>
29 #include <com/sun/star/frame/DispatchRecorderSupplier.hpp>
30 #include <com/sun/star/frame/XLoadable.hpp>
31 #include <com/sun/star/frame/XLayoutManager.hpp>
32 #include <com/sun/star/frame/XComponentLoader.hpp>
33 #include <com/sun/star/ui/UIElementFactoryManager.hpp>
35 #include <toolkit/unohlp.hxx>
36 #include <vcl/splitwin.hxx>
37 #include <unotools/moduleoptions.hxx>
38 #include <svl/intitem.hxx>
39 #include <svl/visitem.hxx>
40 #include <svl/stritem.hxx>
41 #include <svl/eitem.hxx>
42 #include <svl/slstitm.hxx>
43 #include <svl/whiter.hxx>
44 #include <svl/undo.hxx>
45 #include <vcl/msgbox.hxx>
46 #include <svtools/sfxecode.hxx>
47 #include <svtools/miscopt.hxx>
48 #include <svtools/ehdl.hxx>
49 #include <tools/diagnose_ex.h>
50 #include <com/sun/star/container/XIndexAccess.hpp>
51 #include <com/sun/star/frame/XFramesSupplier.hpp>
52 #include <com/sun/star/frame/FrameSearchFlag.hpp>
53 #include <com/sun/star/frame/XFrame.hpp>
54 #include <com/sun/star/frame/XFrames.hpp>
55 #include <com/sun/star/awt/XWindow.hpp>
56 #include <com/sun/star/frame/XController.hpp>
57 #include <com/sun/star/frame/XModel2.hpp>
58 #include <com/sun/star/util/URLTransformer.hpp>
59 #include <com/sun/star/util/XURLTransformer.hpp>
60 #include <com/sun/star/util/XCloseable.hpp>
61 #include <com/sun/star/frame/XDispatchRecorderSupplier.hpp>
62 #include <com/sun/star/document/UpdateDocMode.hpp>
63 #include <com/sun/star/beans/XPropertySet.hpp>
64 #include <com/sun/star/uri/UriReferenceFactory.hpp>
65 #include <com/sun/star/uri/XVndSunStarScriptUrl.hpp>
66 #include <com/sun/star/embed/XStorage.hpp>
67 #include <com/sun/star/embed/EmbedStates.hpp>
68 #include <com/sun/star/document/XViewDataSupplier.hpp>
69 #include <com/sun/star/container/XIndexContainer.hpp>
70 #include <com/sun/star/task/InteractionHandler.hpp>
71 #include <rtl/ustrbuf.hxx>
73 #include <unotools/localfilehelper.hxx>
74 #include <unotools/ucbhelper.hxx>
75 #include <comphelper/processfactory.hxx>
76 #include <comphelper/componentcontext.hxx>
77 #include <comphelper/namedvaluecollection.hxx>
78 #include <comphelper/configurationhelper.hxx>
79 #include <comphelper/docpasswordrequest.hxx>
80 #include <comphelper/docpasswordhelper.hxx>
82 #include <com/sun/star/uno/Reference.h>
83 #include <com/sun/star/ucb/XContent.hpp>
85 #include <basic/basmgr.hxx>
86 #include <basic/sbmod.hxx>
87 #include <basic/sbmeth.hxx>
88 #include <basic/sbx.hxx>
89 #include <comphelper/storagehelper.hxx>
90 #include <svtools/asynclink.hxx>
91 #include <svl/sharecontrolfile.hxx>
92 #include <svtools/svtools.hrc>
93 #include <svtools/svtresid.hxx>
94 #include <framework/framelistanalyzer.hxx>
96 #include <comphelper/processfactory.hxx>
97 #include <comphelper/configuration.hxx>
98 #include "officecfg/Office/Common.hxx"
100 #include <boost/optional.hpp>
102 using namespace ::com::sun::star;
103 using namespace ::com::sun::star::uno;
104 using namespace ::com::sun::star::ucb;
105 using namespace ::com::sun::star::frame;
106 using namespace ::com::sun::star::lang;
107 using ::com::sun::star::awt::XWindow;
108 using ::com::sun::star::beans::PropertyValue;
109 using ::com::sun::star::document::XViewDataSupplier;
110 using ::com::sun::star::container::XIndexContainer;
112 // Due to ViewFrame::Current
113 #include "appdata.hxx"
114 #include <sfx2/taskpane.hxx>
115 #include <sfx2/app.hxx>
116 #include <sfx2/objface.hxx>
117 #include "openflag.hxx"
118 #include "objshimp.hxx"
119 #include <sfx2/viewsh.hxx>
120 #include <sfx2/objsh.hxx>
121 #include <sfx2/bindings.hxx>
122 #include <sfx2/dispatch.hxx>
123 #include "arrdecl.hxx"
124 #include "sfxtypes.hxx"
125 #include <sfx2/request.hxx>
126 #include <sfx2/docfac.hxx>
127 #include <sfx2/ipclient.hxx>
128 #include "sfx2/sfxresid.hxx"
129 #include "appbas.hxx"
130 #include <sfx2/objitem.hxx>
131 #include "sfx2/viewfac.hxx"
132 #include <sfx2/event.hxx>
133 #include "fltfnc.hxx"
134 #include <sfx2/docfile.hxx>
135 #include <sfx2/module.hxx>
136 #include <sfx2/msgpool.hxx>
137 #include "viewimp.hxx"
138 #include <sfx2/sfxbasecontroller.hxx>
139 #include <sfx2/sfx.hrc>
140 #include "view.hrc"
141 #include <sfx2/frmdescr.hxx>
142 #include <sfx2/sfxuno.hxx>
143 #include <sfx2/progress.hxx>
144 #include "workwin.hxx"
145 #include "helper.hxx"
146 #include "sfx2/minfitem.hxx"
147 #include "../appl/app.hrc"
148 #include "impviewframe.hxx"
150 //-------------------------------------------------------------------------
151 DBG_NAME(SfxViewFrame)
153 #define SfxViewFrame
154 #include "sfxslots.hxx"
155 #undef SfxViewFrame
157 //-------------------------------------------------------------------------
159 SFX_IMPL_INTERFACE(SfxViewFrame,SfxShell,SfxResId(0))
161 SFX_CHILDWINDOW_REGISTRATION( SID_BROWSER );
162 SFX_CHILDWINDOW_REGISTRATION( SID_RECORDING_FLOATWINDOW );
163 #if HAVE_FEATURE_DESKTOP_GUI_ELEMENTS
164 SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_FULLSCREEN | SFX_VISIBILITY_FULLSCREEN, SfxResId(RID_FULLSCREENTOOLBOX) );
165 SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_APPLICATION | SFX_VISIBILITY_STANDARD, SfxResId(RID_ENVTOOLBOX) );
166 #endif
169 TYPEINIT2(SfxViewFrame,SfxShell,SfxListener);
170 TYPEINIT1(SfxViewFrameItem, SfxPoolItem);
172 //-------------------------------------------------------------------------
173 namespace
175 bool moduleHasToolPanels( SfxViewFrame_Impl& i_rViewFrameImpl )
177 if ( !i_rViewFrameImpl.aHasToolPanels )
179 i_rViewFrameImpl.aHasToolPanels.reset( ::sfx2::ModuleTaskPane::ModuleHasToolPanels(
180 i_rViewFrameImpl.rFrame.GetFrameInterface() ) );
182 return *i_rViewFrameImpl.aHasToolPanels;
186 //-------------------------------------------------------------------------
187 static sal_Bool AskPasswordToModify_Impl( const uno::Reference< task::XInteractionHandler >& xHandler, const OUString& aPath, const SfxFilter* pFilter, sal_uInt32 nPasswordHash, const uno::Sequence< beans::PropertyValue > aInfo )
189 // TODO/LATER: In future the info should replace the direct hash completely
190 sal_Bool bResult = ( !nPasswordHash && !aInfo.getLength() );
192 OSL_ENSURE( pFilter && ( pFilter->GetFilterFlags() & SFX_FILTER_PASSWORDTOMODIFY ), "PasswordToModify feature is active for a filter that does not support it!" );
194 if ( pFilter && xHandler.is() )
196 sal_Bool bCancel = sal_False;
197 sal_Bool bFirstTime = sal_True;
199 while ( !bResult && !bCancel )
201 sal_Bool bMSType = !pFilter->IsOwnFormat();
203 ::rtl::Reference< ::comphelper::DocPasswordRequest > pPasswordRequest(
204 new ::comphelper::DocPasswordRequest(
205 bMSType ? ::comphelper::DocPasswordRequestType_MS : ::comphelper::DocPasswordRequestType_STANDARD,
206 bFirstTime ? ::com::sun::star::task::PasswordRequestMode_PASSWORD_ENTER : ::com::sun::star::task::PasswordRequestMode_PASSWORD_REENTER,
207 aPath,
208 sal_True ) );
210 uno::Reference< com::sun::star::task::XInteractionRequest > rRequest( pPasswordRequest.get() );
211 xHandler->handle( rRequest );
213 if ( pPasswordRequest->isPassword() )
215 if ( aInfo.getLength() )
217 bResult = ::comphelper::DocPasswordHelper::IsModifyPasswordCorrect( pPasswordRequest->getPasswordToModify(), aInfo );
219 else
221 // the binary format
222 bResult = ( SfxMedium::CreatePasswordToModifyHash( pPasswordRequest->getPasswordToModify(), OUString( "com.sun.star.text.TextDocument" ).equals( pFilter->GetServiceName() ) ) == nPasswordHash );
225 else
226 bCancel = sal_True;
228 bFirstTime = sal_False;
232 return bResult;
235 //-------------------------------------------------------------------------
236 void SfxViewFrame::SetDowning_Impl()
238 pImp->bIsDowning = sal_True;
241 //-------------------------------------------------------------------------
242 sal_Bool SfxViewFrame::IsDowning_Impl() const
244 return pImp->bIsDowning;
248 //--------------------------------------------------------------------
249 class SfxViewNotificatedFrameList_Impl :
250 public SfxListener, public SfxViewFrameArr_Impl
252 public:
254 void InsertViewFrame( SfxViewFrame* pFrame )
256 StartListening( *pFrame );
257 push_back( pFrame );
259 void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
262 //-------------------------------------------------------------------------
263 void SfxViewNotificatedFrameList_Impl::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
265 if ( rHint.IsA(TYPE(SfxSimpleHint)) )
267 switch( ( (SfxSimpleHint&) rHint ).GetId() )
269 case SFX_HINT_DYING:
270 SfxViewFrame* pFrame = (SfxViewFrame*) &rBC;
271 if( pFrame )
273 iterator it = std::find( begin(), end(), pFrame );
274 if( it != end() )
275 erase( it );
277 break;
282 //-------------------------------------------------------------------------
284 long ReloadDecouple_Impl( void* pObj, void* pArg )
286 ((SfxViewFrame*) pObj)->ExecReload_Impl( *(SfxRequest*)pArg );
287 return 0;
290 void SfxViewFrame::ExecReload_Impl( SfxRequest& rReq )
292 SfxFrame *pParent = GetFrame().GetParentFrame();
293 if ( rReq.GetSlot() == SID_RELOAD )
295 // When CTRL-Reload, reload the active Frame
296 SfxViewFrame* pActFrame = this;
297 while ( pActFrame )
298 pActFrame = pActFrame->GetActiveChildFrame_Impl();
300 if ( pActFrame )
302 sal_uInt16 nModifier = rReq.GetModifier();
303 if ( nModifier & KEY_MOD1 )
305 pActFrame->ExecReload_Impl( rReq );
306 return;
310 // If only a reload of the graphics for one or more child frames
311 // should be made
312 SfxFrame& rFrame = GetFrame();
313 if ( pParent == &rFrame && rFrame.GetChildFrameCount() )
315 sal_Bool bReloadAvailable = sal_False;
316 SfxFrameIterator aIter( rFrame, sal_False );
317 SfxFrame *pChild = aIter.FirstFrame();
318 while ( pChild )
320 SfxFrame *pNext = aIter.NextFrame( *pChild );
321 SfxObjectShell *pShell = pChild->GetCurrentDocument();
322 if( pShell && pShell->Get_Impl()->bReloadAvailable )
324 bReloadAvailable = sal_True;
325 pChild->GetCurrentViewFrame()->ExecuteSlot( rReq );
327 pChild = pNext;
330 // The top level frame itself has no graphics!
331 if ( bReloadAvailable )
332 return;
335 else
337 // When CTRL-Edit, edit the TopFrame.
338 sal_uInt16 nModifier = rReq.GetModifier();
340 if ( ( nModifier & KEY_MOD1 ) && pParent )
342 SfxViewFrame *pTop = GetTopViewFrame();
343 pTop->ExecReload_Impl( rReq );
344 return;
348 SfxObjectShell* pSh = GetObjectShell();
349 switch ( rReq.GetSlot() )
351 case SID_EDITDOC:
353 if ( GetFrame().HasComponent() )
354 break;
356 // Due to Double occupancy in toolboxes (with or without Ctrl),
357 // it is also possible that the slot is enabled, but Ctrl-click
358 // despite this is not!
359 if( !pSh || !pSh->HasName() || !(pSh->Get_Impl()->nLoadedFlags & SFX_LOADED_MAINDOCUMENT ))
360 break;
362 SfxMedium* pMed = pSh->GetMedium();
364 SFX_ITEMSET_ARG( pSh->GetMedium()->GetItemSet(), pItem, SfxBoolItem, SID_VIEWONLY, sal_False );
365 if ( pItem && pItem->GetValue() )
367 SfxApplication* pApp = SFX_APP();
368 SfxAllItemSet aSet( pApp->GetPool() );
369 aSet.Put( SfxStringItem( SID_FILE_NAME, pMed->GetURLObject().GetMainURL(INetURLObject::NO_DECODE) ) );
370 aSet.Put( SfxBoolItem( SID_TEMPLATE, sal_True ) );
371 aSet.Put( SfxStringItem( SID_TARGETNAME, OUString("_blank") ) );
372 SFX_ITEMSET_ARG( pMed->GetItemSet(), pReferer, SfxStringItem, SID_REFERER, sal_False );
373 if ( pReferer )
374 aSet.Put( *pReferer );
375 SFX_ITEMSET_ARG( pSh->GetMedium()->GetItemSet(), pVersionItem, SfxInt16Item, SID_VERSION, sal_False );
376 if ( pVersionItem )
377 aSet.Put( *pVersionItem );
379 if( pMed->GetFilter() )
381 aSet.Put( SfxStringItem( SID_FILTER_NAME, pMed->GetFilter()->GetFilterName() ) );
382 SFX_ITEMSET_ARG( pMed->GetItemSet(), pOptions, SfxStringItem, SID_FILE_FILTEROPTIONS, sal_False );
383 if ( pOptions )
384 aSet.Put( *pOptions );
387 GetDispatcher()->Execute( SID_OPENDOC, SFX_CALLMODE_ASYNCHRON, aSet );
388 return;
391 sal_uInt16 nOpenMode;
392 sal_Bool bNeedsReload = sal_False;
393 if ( !pSh->IsReadOnly() )
395 // Save and reload Readonly
396 if( pSh->IsModified() )
398 if ( pSh->PrepareClose() )
400 // the storing could let the medium be changed
401 pMed = pSh->GetMedium();
402 bNeedsReload = sal_True;
404 else
406 rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), sal_False ) );
407 return;
410 nOpenMode = SFX_STREAM_READONLY;
411 pSh->SetReadOnlyUI(true);
413 else
415 if ( pSh->IsReadOnlyMedium()
416 && ( pSh->GetModifyPasswordHash() || pSh->GetModifyPasswordInfo().getLength() )
417 && !pSh->IsModifyPasswordEntered() )
419 OUString aDocumentName = INetURLObject( pMed->GetOrigURL() ).GetMainURL( INetURLObject::DECODE_WITH_CHARSET );
420 if( !AskPasswordToModify_Impl( pMed->GetInteractionHandler(), aDocumentName, pMed->GetOrigFilter(), pSh->GetModifyPasswordHash(), pSh->GetModifyPasswordInfo() ) )
422 // this is a read-only document, if it has "Password to modify"
423 // the user should enter password before he can edit the document
424 rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), sal_False ) );
425 return;
428 pSh->SetModifyPasswordEntered();
431 nOpenMode = pSh->IsOriginallyReadOnlyMedium() ? SFX_STREAM_READONLY : SFX_STREAM_READWRITE;
433 // if only the view was in the readonly mode then there is no need to do the reload
434 if ( !pSh->IsReadOnlyMedium() )
436 // SetReadOnlyUI causes recomputation of window title, using
437 // open mode among other things, so call SetOpenMode before
438 // SetReadOnlyUI:
439 pMed->SetOpenMode( nOpenMode );
440 pSh->SetReadOnlyUI( sal_False );
441 return;
444 pSh->SetReadOnlyUI( sal_False );
447 if ( rReq.IsAPI() )
449 // Control through API if r/w or r/o
450 SFX_REQUEST_ARG(rReq, pEditItem, SfxBoolItem, SID_EDITDOC, sal_False);
451 if ( pEditItem )
452 nOpenMode = pEditItem->GetValue() ? SFX_STREAM_READWRITE : SFX_STREAM_READONLY;
455 // doing
457 OUString aTemp;
458 utl::LocalFileHelper::ConvertPhysicalNameToURL( pMed->GetPhysicalName(), aTemp );
459 INetURLObject aPhysObj( aTemp );
460 SFX_ITEMSET_ARG( pSh->GetMedium()->GetItemSet(),
461 pVersionItem, SfxInt16Item, SID_VERSION, sal_False );
463 INetURLObject aMedObj( pMed->GetName() );
465 // the logic below is following, if the document seems not to need to be reloaded and the physical name is different
466 // to the logical one, then on file system it can be checked that the copy is still newer than the original and no document reload is required
467 if ( ( !bNeedsReload && ( (aMedObj.GetProtocol() == INET_PROT_FILE &&
468 aMedObj.getFSysPath(INetURLObject::FSYS_DETECT) != aPhysObj.getFSysPath(INetURLObject::FSYS_DETECT) &&
469 !::utl::UCBContentHelper::IsYounger( aMedObj.GetMainURL( INetURLObject::NO_DECODE ), aPhysObj.GetMainURL( INetURLObject::NO_DECODE ) ))
470 || pMed->IsRemote() ) )
471 || pVersionItem )
473 sal_Bool bOK = sal_False;
474 if ( !pVersionItem )
476 sal_Bool bHasStorage = pMed->HasStorage_Impl();
477 // switching edit mode could be possible without reload
478 if ( bHasStorage && pMed->GetStorage() == pSh->GetStorage() )
480 // TODO/LATER: faster creation of copy
481 if ( !pSh->ConnectTmpStorage_Impl( pMed->GetStorage(), pMed ) )
482 return;
485 pMed->CloseAndRelease();
486 pMed->GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, !( nOpenMode & STREAM_WRITE ) ) );
487 pMed->SetOpenMode( nOpenMode );
489 pMed->CompleteReOpen();
490 if ( nOpenMode & STREAM_WRITE )
491 pMed->LockOrigFileOnDemand( sal_False, sal_True );
493 // LockOrigFileOnDemand might set the readonly flag itself, it should be set back
494 pMed->GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, !( nOpenMode & STREAM_WRITE ) ) );
496 if ( !pMed->GetErrorCode() )
497 bOK = sal_True;
500 if( !bOK )
502 ErrCode nErr = pMed->GetErrorCode();
503 if ( pVersionItem )
504 nErr = ERRCODE_IO_ACCESSDENIED;
505 else
507 pMed->ResetError();
508 pMed->SetOpenMode( SFX_STREAM_READONLY );
509 pMed->ReOpen();
510 pSh->DoSaveCompleted( pMed );
513 // Readonly document can not be switched to edit mode?
514 rReq.Done( sal_False );
516 if ( nOpenMode == SFX_STREAM_READWRITE && !rReq.IsAPI() )
518 // ::com::sun::star::sdbcx::User offering to open it as a template
519 QueryBox aBox( &GetWindow(), SfxResId(MSG_QUERY_OPENASTEMPLATE) );
520 if ( RET_YES == aBox.Execute() )
522 SfxApplication* pApp = SFX_APP();
523 SfxAllItemSet aSet( pApp->GetPool() );
524 aSet.Put( SfxStringItem( SID_FILE_NAME, pMed->GetName() ) );
525 SFX_ITEMSET_ARG( pMed->GetItemSet(), pReferer, SfxStringItem, SID_REFERER, sal_False );
526 if ( pReferer )
527 aSet.Put( *pReferer );
528 aSet.Put( SfxBoolItem( SID_TEMPLATE, sal_True ) );
529 if ( pVersionItem )
530 aSet.Put( *pVersionItem );
532 if( pMed->GetFilter() )
534 aSet.Put( SfxStringItem( SID_FILTER_NAME, pMed->GetFilter()->GetFilterName() ) );
535 SFX_ITEMSET_ARG( pMed->GetItemSet(), pOptions,
536 SfxStringItem, SID_FILE_FILTEROPTIONS, sal_False );
537 if ( pOptions )
538 aSet.Put( *pOptions );
541 GetDispatcher()->Execute( SID_OPENDOC, SFX_CALLMODE_ASYNCHRON, aSet );
542 return;
544 else
545 nErr = 0;
548 ErrorHandler::HandleError( nErr );
549 rReq.SetReturnValue(
550 SfxBoolItem( rReq.GetSlot(), sal_False ) );
551 return;
553 else
555 pSh->DoSaveCompleted( pMed );
556 pSh->Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) );
557 rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), sal_True ) );
558 rReq.Done( sal_True );
559 return;
563 rReq.AppendItem( SfxBoolItem( SID_FORCERELOAD, sal_True) );
564 rReq.AppendItem( SfxBoolItem( SID_SILENT, sal_True ));
567 case SID_RELOAD:
569 // Due to Double occupancy in toolboxes (with or without Ctrl),
570 // it is also possible that the slot is enabled, but Ctrl-click
571 // despite this is not!
572 if ( !pSh || !pSh->CanReload_Impl() )
573 break;
574 SfxApplication* pApp = SFX_APP();
575 SFX_REQUEST_ARG(rReq, pForceReloadItem, SfxBoolItem,
576 SID_FORCERELOAD, sal_False);
577 if( pForceReloadItem && !pForceReloadItem->GetValue() &&
578 !pSh->GetMedium()->IsExpired() )
579 return;
580 if( pImp->bReloading || pSh->IsInModalMode() )
581 return;
583 // AutoLoad is prohibited if possible
584 SFX_REQUEST_ARG(rReq, pAutoLoadItem, SfxBoolItem, SID_AUTOLOAD, sal_False);
585 if ( pAutoLoadItem && pAutoLoadItem->GetValue() &&
586 GetFrame().IsAutoLoadLocked_Impl() )
587 return;
589 SfxObjectShellLock xOldObj( pSh );
590 pImp->bReloading = sal_True;
591 SFX_REQUEST_ARG(rReq, pURLItem, SfxStringItem,
592 SID_FILE_NAME, sal_False);
593 // Open as editable?
594 sal_Bool bForEdit = !pSh->IsReadOnly();
596 // If possible ask the User
597 sal_Bool bDo = ( GetViewShell()->PrepareClose() != sal_False );
598 SFX_REQUEST_ARG(rReq, pSilentItem, SfxBoolItem, SID_SILENT, sal_False);
599 if ( bDo && GetFrame().DocIsModified_Impl() &&
600 !rReq.IsAPI() && ( !pSilentItem || !pSilentItem->GetValue() ) )
602 QueryBox aBox( &GetWindow(), SfxResId(MSG_QUERY_LASTVERSION) );
603 bDo = ( RET_YES == aBox.Execute() );
606 if ( bDo )
608 SfxMedium *pMedium = xOldObj->GetMedium();
610 // Remove Frameset before the FramesetView may disappear
611 String aURL;
612 if (pURLItem)
613 aURL = pURLItem->GetValue();
614 else
615 aURL = pMedium->GetName();
617 sal_Bool bHandsOff =
618 ( pMedium->GetURLObject().GetProtocol() == INET_PROT_FILE && !xOldObj->IsDocShared() );
620 // Emty existing SfxMDIFrames for this Document
621 // in native format or R/O, open it now for editing?
622 SfxObjectShellLock xNewObj;
624 // collect the views of the document
625 // TODO: when UNO ViewFactories are available for SFX-based documents, the below code should
626 // be UNOized, too
627 typedef ::std::pair< Reference< XFrame >, sal_uInt16 > ViewDescriptor;
628 ::std::list< ViewDescriptor > aViewFrames;
629 SfxViewFrame *pView = GetFirst( xOldObj );
630 while ( pView )
632 Reference< XFrame > xFrame( pView->GetFrame().GetFrameInterface() );
633 OSL_ENSURE( xFrame.is(), "SfxViewFrame::ExecReload_Impl: no XFrame?!" );
634 aViewFrames.push_back( ViewDescriptor( xFrame, pView->GetCurViewId() ) );
636 pView = GetNext( *pView, xOldObj );
639 DELETEZ( xOldObj->Get_Impl()->pReloadTimer );
641 SfxItemSet* pNewSet = 0;
642 const SfxFilter *pFilter = pMedium->GetFilter();
643 if( pURLItem )
645 pNewSet = new SfxAllItemSet( pApp->GetPool() );
646 pNewSet->Put( *pURLItem );
648 // Filter Detection
649 SfxMedium aMedium( pURLItem->GetValue(), SFX_STREAM_READWRITE );
650 SfxFilterMatcher().GuessFilter( aMedium, &pFilter );
651 if ( pFilter )
652 pNewSet->Put( SfxStringItem( SID_FILTER_NAME, pFilter->GetName() ) );
653 pNewSet->Put( *aMedium.GetItemSet() );
655 else
657 pNewSet = new SfxAllItemSet( *pMedium->GetItemSet() );
658 pNewSet->ClearItem( SID_VIEW_ID );
659 pNewSet->ClearItem( SID_STREAM );
660 pNewSet->ClearItem( SID_INPUTSTREAM );
661 pNewSet->Put( SfxStringItem( SID_FILTER_NAME, pMedium->GetFilter()->GetName() ) );
663 // let the current security settings be checked again
664 pNewSet->Put( SfxUInt16Item( SID_MACROEXECMODE, document::MacroExecMode::USE_CONFIG ) );
666 if ( pSh->IsOriginallyReadOnlyMedium() )
667 // edit mode is switched or reload of readonly document
668 pNewSet->Put( SfxBoolItem( SID_DOC_READONLY, true ) );
669 else
670 // Reload of file opened for writing
671 pNewSet->ClearItem( SID_DOC_READONLY );
674 // If a salvaged file is present, do not enclose the OrigURL
675 // again, since the Tempdate is invalid after reload.
676 SFX_ITEMSET_ARG( pNewSet, pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False);
677 if( pSalvageItem )
679 aURL = pSalvageItem->GetValue();
680 pNewSet->ClearItem( SID_DOC_SALVAGE );
683 #if HAVE_FEATURE_MULTIUSER_ENVIRONMENT
684 // TODO/LATER: Temporary solution, the SfxMedium must know the original URL as aLogicName
685 // SfxMedium::Transfer_Impl() will be forbidden then.
686 if ( xOldObj->IsDocShared() )
687 pNewSet->Put( SfxStringItem( SID_FILE_NAME, xOldObj->GetSharedFileURL() ) );
688 #endif
689 if ( pURLItem )
690 pNewSet->Put( SfxStringItem( SID_REFERER, pMedium->GetName() ) );
691 else
692 pNewSet->Put( SfxStringItem( SID_REFERER, String() ) );
694 xOldObj->CancelTransfers();
697 if ( pSilentItem && pSilentItem->GetValue() )
698 pNewSet->Put( SfxBoolItem( SID_SILENT, sal_True ) );
700 SFX_ITEMSET_ARG(pNewSet, pInteractionItem, SfxUnoAnyItem, SID_INTERACTIONHANDLER, sal_False);
701 SFX_ITEMSET_ARG(pNewSet, pMacroExecItem , SfxUInt16Item, SID_MACROEXECMODE , sal_False);
702 SFX_ITEMSET_ARG(pNewSet, pDocTemplateItem, SfxUInt16Item, SID_UPDATEDOCMODE , sal_False);
704 if (!pInteractionItem)
706 Reference < task::XInteractionHandler2 > xHdl = task::InteractionHandler::createWithParent( ::comphelper::getProcessComponentContext(), 0 );
707 if (xHdl.is())
708 pNewSet->Put( SfxUnoAnyItem(SID_INTERACTIONHANDLER,::com::sun::star::uno::makeAny(xHdl)) );
711 if (!pMacroExecItem)
712 pNewSet->Put( SfxUInt16Item(SID_MACROEXECMODE,::com::sun::star::document::MacroExecMode::USE_CONFIG) );
713 if (!pDocTemplateItem)
714 pNewSet->Put( SfxUInt16Item(SID_UPDATEDOCMODE,::com::sun::star::document::UpdateDocMode::ACCORDING_TO_CONFIG) );
716 xOldObj->SetModified( sal_False );
717 // Do not chache the old Document! Is invalid when loading
718 // another document.
720 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSavedOptions, SfxStringItem, SID_FILE_FILTEROPTIONS, sal_False);
721 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSavedReferer, SfxStringItem, SID_REFERER, sal_False);
723 sal_Bool bHasStorage = pMedium->HasStorage_Impl();
724 if( bHandsOff )
726 if ( bHasStorage && pMedium->GetStorage() == xOldObj->GetStorage() )
728 // TODO/LATER: faster creation of copy
729 if ( !xOldObj->ConnectTmpStorage_Impl( pMedium->GetStorage(), pMedium ) )
730 return;
733 pMedium->CloseAndRelease();
736 xNewObj = SfxObjectShell::CreateObject( pFilter->GetServiceName(), SFX_CREATE_MODE_STANDARD );
738 if ( xOldObj->IsModifyPasswordEntered() )
739 xNewObj->SetModifyPasswordEntered();
741 uno::Sequence < beans::PropertyValue > aLoadArgs;
742 TransformItems( SID_OPENDOC, *pNewSet, aLoadArgs );
745 uno::Reference < frame::XLoadable > xLoad( xNewObj->GetModel(), uno::UNO_QUERY );
746 xLoad->load( aLoadArgs );
748 catch ( uno::Exception& )
750 xNewObj->DoClose();
751 xNewObj = 0;
754 DELETEZ( pNewSet );
756 if( !xNewObj.Is() )
758 if( bHandsOff )
760 // back to old medium
761 pMedium->ReOpen();
762 pMedium->LockOrigFileOnDemand( sal_False, sal_True );
764 xOldObj->DoSaveCompleted( pMedium );
767 // r/o-Doc couldn't be switched to writing mode
768 if ( bForEdit && SID_EDITDOC == rReq.GetSlot() )
770 // ask user for opening as template
771 QueryBox aBox( &GetWindow(), SfxResId(MSG_QUERY_OPENASTEMPLATE) );
772 if ( RET_YES == aBox.Execute() )
774 SfxAllItemSet aSet( pApp->GetPool() );
775 aSet.Put( SfxStringItem( SID_FILE_NAME, pMedium->GetName() ) );
776 aSet.Put( SfxStringItem( SID_TARGETNAME, OUString("_blank") ) );
777 if ( pSavedOptions )
778 aSet.Put( *pSavedOptions );
779 if ( pSavedReferer )
780 aSet.Put( *pSavedReferer );
781 aSet.Put( SfxBoolItem( SID_TEMPLATE, sal_True ) );
782 if( pFilter )
783 aSet.Put( SfxStringItem( SID_FILTER_NAME, pFilter->GetFilterName() ) );
784 GetDispatcher()->Execute( SID_OPENDOC, SFX_CALLMODE_ASYNCHRON, aSet );
788 else
790 if ( xNewObj->GetModifyPasswordHash() && xNewObj->GetModifyPasswordHash() != xOldObj->GetModifyPasswordHash() )
792 xNewObj->SetModifyPasswordEntered( sal_False );
793 xNewObj->SetReadOnly();
795 else if ( rReq.GetSlot() == SID_EDITDOC )
797 xNewObj->SetReadOnlyUI( !bForEdit );
800 #if HAVE_FEATURE_MULTIUSER_ENVIRONMENT
801 if ( xNewObj->IsDocShared() )
803 // the file is shared but the closing can change the sharing control file
804 xOldObj->DoNotCleanShareControlFile();
806 #endif
807 // the Reload and Silent items were only temporary, remove them
808 xNewObj->GetMedium()->GetItemSet()->ClearItem( SID_RELOAD );
809 xNewObj->GetMedium()->GetItemSet()->ClearItem( SID_SILENT );
810 TransformItems( SID_OPENDOC, *xNewObj->GetMedium()->GetItemSet(), aLoadArgs );
812 UpdateDocument_Impl();
816 while ( !aViewFrames.empty() )
818 LoadViewIntoFrame_Impl( *xNewObj, aViewFrames.front().first, aLoadArgs, aViewFrames.front().second, false );
819 aViewFrames.pop_front();
822 catch( const Exception& )
824 // close the remaining frames
825 // Don't catch exceptions herein, if this fails, then we're left in an indetermined state, and
826 // crashing is better than trying to proceed
827 while ( !aViewFrames.empty() )
829 Reference< util::XCloseable > xClose( aViewFrames.front().first, UNO_QUERY_THROW );
830 xClose->close( sal_True );
831 aViewFrames.pop_front();
835 // Propagate document closure.
836 SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_CLOSEDOC, GlobalEventConfig::GetEventName( STR_EVENT_CLOSEDOC ), xOldObj ) );
839 // Record as done
840 rReq.Done( sal_True );
841 rReq.SetReturnValue(SfxBoolItem(rReq.GetSlot(), sal_True));
842 return;
844 else
846 // Record as not done
847 rReq.Done();
848 rReq.SetReturnValue(SfxBoolItem(rReq.GetSlot(), sal_False));
849 pImp->bReloading = sal_False;
850 return;
856 //-------------------------------------------------------------------------
857 void SfxViewFrame::StateReload_Impl( SfxItemSet& rSet )
859 SfxObjectShell* pSh = GetObjectShell();
860 if ( !pSh )
861 // I'm just on reload and am yielding myself ...
862 return;
864 GetFrame().GetParentFrame();
865 SfxWhichIter aIter( rSet );
866 for ( sal_uInt16 nWhich = aIter.FirstWhich(); nWhich; nWhich = aIter.NextWhich() )
868 if ( GetFrame().HasComponent() )
870 // If the component is not self-dispatched, then
871 // it makes no sense!
872 rSet.DisableItem( nWhich );
873 continue;
876 switch ( nWhich )
878 case SID_EDITDOC:
880 if ( !pSh || !pSh->HasName() || !( pSh->Get_Impl()->nLoadedFlags & SFX_LOADED_MAINDOCUMENT )
881 || pSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
882 rSet.DisableItem( SID_EDITDOC );
883 else
885 SFX_ITEMSET_ARG( pSh->GetMedium()->GetItemSet(), pItem, SfxBoolItem, SID_EDITDOC, sal_False );
886 if ( pItem && !pItem->GetValue() )
887 rSet.DisableItem( SID_EDITDOC );
888 else
889 rSet.Put( SfxBoolItem( nWhich, !pSh->IsReadOnly() ) );
891 break;
894 case SID_RELOAD:
896 SfxFrame* pFrame = &GetTopFrame();
898 if ( !pSh || !pSh->CanReload_Impl() || pSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
899 rSet.DisableItem(nWhich);
900 else
902 // If any ChildFrame is reloadable, the slot is enabled,
903 // so you can perfom CTRL-Reload
904 sal_Bool bReloadAvailable = sal_False;
905 SfxFrameIterator aFrameIter( *pFrame, sal_True );
906 for( SfxFrame* pNextFrame = aFrameIter.FirstFrame();
907 pFrame;
908 pNextFrame = pNextFrame ?
909 aFrameIter.NextFrame( *pNextFrame ) : 0 )
911 SfxObjectShell *pShell = pFrame->GetCurrentDocument();
912 if( pShell && pShell->Get_Impl()->bReloadAvailable )
914 bReloadAvailable = sal_True;
915 break;
917 pFrame = pNextFrame;
920 rSet.Put( SfxBoolItem( nWhich, bReloadAvailable));
923 break;
930 //--------------------------------------------------------------------
931 void SfxViewFrame::ExecHistory_Impl( SfxRequest &rReq )
933 // Is there an Undo-Manager on the top Shell?
934 SfxShell *pSh = GetDispatcher()->GetShell(0);
935 ::svl::IUndoManager* pShUndoMgr = pSh->GetUndoManager();
936 sal_Bool bOK = sal_False;
937 if ( pShUndoMgr )
939 switch ( rReq.GetSlot() )
941 case SID_CLEARHISTORY:
942 pShUndoMgr->Clear();
943 bOK = sal_True;
944 break;
946 case SID_UNDO:
947 pShUndoMgr->Undo();
948 GetBindings().InvalidateAll(sal_False);
949 bOK = sal_True;
950 break;
952 case SID_REDO:
953 pShUndoMgr->Redo();
954 GetBindings().InvalidateAll(sal_False);
955 bOK = sal_True;
956 break;
958 case SID_REPEAT:
959 if ( pSh->GetRepeatTarget() )
960 pShUndoMgr->Repeat( *pSh->GetRepeatTarget() );
961 bOK = sal_True;
962 break;
965 else if ( GetViewShell() )
967 // The SW has its own undo in the View
968 const SfxPoolItem *pRet = GetViewShell()->ExecuteSlot( rReq );
969 if ( pRet )
970 bOK = ((SfxBoolItem*)pRet)->GetValue();
973 rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bOK ) );
974 rReq.Done();
977 //--------------------------------------------------------------------
978 void SfxViewFrame::StateHistory_Impl( SfxItemSet &rSet )
980 // Search for Undo-Manager
981 SfxShell *pSh = GetDispatcher()->GetShell(0);
982 if ( !pSh )
983 // I'm just on reload and am yielding myself ...
984 return;
986 ::svl::IUndoManager *pShUndoMgr = pSh->GetUndoManager();
987 if ( !pShUndoMgr )
989 // The SW has its own undo in the View
990 SfxWhichIter aIter( rSet );
991 SfxViewShell *pViewSh = GetViewShell();
992 if( !pViewSh ) return;
993 for ( sal_uInt16 nSID = aIter.FirstWhich(); nSID; nSID = aIter.NextWhich() )
994 pViewSh->GetSlotState( nSID, 0, &rSet );
995 return;
998 if ( pShUndoMgr->GetUndoActionCount() == 0 &&
999 pShUndoMgr->GetRedoActionCount() == 0 &&
1000 pShUndoMgr->GetRepeatActionCount() == 0 )
1001 rSet.DisableItem( SID_CLEARHISTORY );
1003 if ( pShUndoMgr && pShUndoMgr->GetUndoActionCount() )
1005 String aTmp(SvtResId(STR_UNDO).toString());
1006 aTmp+= pShUndoMgr->GetUndoActionComment(0);
1007 rSet.Put( SfxStringItem( SID_UNDO, aTmp ) );
1009 else
1010 rSet.DisableItem( SID_UNDO );
1012 if ( pShUndoMgr && pShUndoMgr->GetRedoActionCount() )
1014 String aTmp(SvtResId(STR_REDO).toString());
1015 aTmp += pShUndoMgr->GetRedoActionComment(0);
1016 rSet.Put( SfxStringItem( SID_REDO, aTmp ) );
1018 else
1019 rSet.DisableItem( SID_REDO );
1020 SfxRepeatTarget *pTarget = pSh->GetRepeatTarget();
1021 if ( pShUndoMgr && pTarget && pShUndoMgr->GetRepeatActionCount() &&
1022 pShUndoMgr->CanRepeat(*pTarget) )
1024 String aTmp(SvtResId(STR_REPEAT).toString());
1025 aTmp += pShUndoMgr->GetRepeatActionComment(*pTarget);
1026 rSet.Put( SfxStringItem( SID_REPEAT, aTmp ) );
1028 else
1029 rSet.DisableItem( SID_REPEAT );
1032 //--------------------------------------------------------------------
1033 void SfxViewFrame::PopShellAndSubShells_Impl( SfxViewShell& i_rViewShell )
1035 i_rViewShell.PopSubShells_Impl();
1036 sal_uInt16 nLevel = pDispatcher->GetShellLevel( i_rViewShell );
1037 if ( nLevel != USHRT_MAX )
1039 if ( nLevel )
1041 // more sub shells on the stack, which were not affected by PopSubShells_Impl
1042 SfxShell *pSubShell = pDispatcher->GetShell( nLevel-1 );
1043 if ( pSubShell == i_rViewShell.GetSubShell() )
1044 // "real" sub shells will be deleted elsewhere
1045 pDispatcher->Pop( *pSubShell, SFX_SHELL_POP_UNTIL );
1046 else
1047 pDispatcher->Pop( *pSubShell, SFX_SHELL_POP_UNTIL | SFX_SHELL_POP_DELETE );
1049 pDispatcher->Pop( i_rViewShell );
1050 pDispatcher->Flush();
1055 //--------------------------------------------------------------------
1056 void SfxViewFrame::ReleaseObjectShell_Impl()
1058 /* [Description]
1060 This method empties the SfxViewFrame, i.e. takes the <SfxObjectShell>
1061 from the dispatcher and ends its <SfxListener> Relationship to this
1062 SfxObjectShell (by which they may even destroy themselves).
1064 Thus, by invoking ReleaseObjectShell() and SetObjectShell() the
1065 SfxObjectShell can be replaced.
1067 Between RealeaseObjectShell() and SetObjectShell() can the control not
1068 be handed over to the system.
1070 [Cross-reference]
1072 <SfxViewFrame::SetObjectShell(SfxObjectShell&)>
1075 DBG_CHKTHIS(SfxViewFrame, 0);
1076 DBG_ASSERT( xObjSh.Is(), "no SfxObjectShell to release!" );
1078 GetFrame().ReleasingComponent_Impl( sal_True );
1079 if ( GetWindow().HasChildPathFocus( sal_True ) )
1081 DBG_ASSERT( !GetActiveChildFrame_Impl(), "Wrong active child frame!" );
1082 GetWindow().GrabFocus();
1085 SfxViewShell *pDyingViewSh = GetViewShell();
1086 if ( pDyingViewSh )
1088 PopShellAndSubShells_Impl( *pDyingViewSh );
1089 pDyingViewSh->DisconnectAllClients();
1090 SetViewShell_Impl(0);
1091 delete pDyingViewSh;
1093 #ifdef DBG_UTIL
1094 else
1095 OSL_FAIL("No Shell");
1096 #endif
1098 if ( xObjSh.Is() )
1100 pImp->aLastType = xObjSh->Type();
1101 pDispatcher->Pop( *xObjSh );
1102 SfxModule* pModule = xObjSh->GetModule();
1103 if( pModule )
1104 pDispatcher->RemoveShell_Impl( *pModule );
1105 pDispatcher->Flush();
1106 EndListening( *xObjSh );
1108 Notify( *xObjSh, SfxSimpleHint(SFX_HINT_TITLECHANGED) );
1109 Notify( *xObjSh, SfxSimpleHint(SFX_HINT_DOCCHANGED) );
1111 if ( 1 == xObjSh->GetOwnerLockCount() && pImp->bObjLocked && xObjSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
1112 xObjSh->DoClose();
1113 SfxObjectShellRef xDyingObjSh = xObjSh;
1114 xObjSh.Clear();
1115 if( ( GetFrameType() & SFXFRAME_HASTITLE ) && pImp->nDocViewNo )
1116 xDyingObjSh->GetNoSet_Impl().ReleaseIndex(pImp->nDocViewNo-1);
1117 if ( pImp->bObjLocked )
1119 xDyingObjSh->OwnerLock( sal_False );
1120 pImp->bObjLocked = sal_False;
1124 GetDispatcher()->SetDisableFlags( 0 );
1127 //--------------------------------------------------------------------
1128 sal_Bool SfxViewFrame::Close()
1130 DBG_CHKTHIS(SfxViewFrame, 0);
1132 DBG_ASSERT( GetFrame().IsClosing_Impl() || !GetFrame().GetFrameInterface().is(), "ViewFrame closed too early!" );
1134 // If no saving have been made up until now, then embedded Objects should
1135 // not be saved automatically anymore.
1136 if ( GetViewShell() )
1137 GetViewShell()->DiscardClients_Impl();
1138 Broadcast( SfxSimpleHint( SFX_HINT_DYING ) );
1140 if (SfxViewFrame::Current() == this)
1141 SfxViewFrame::SetViewFrame( NULL );
1143 // Since the Dispatcher is emptied, it can not be used in any reasnable
1144 // manner, thus it is better to let the dispatcher be.
1145 GetDispatcher()->Lock(sal_True);
1146 delete this;
1148 return sal_True;
1151 //--------------------------------------------------------------------
1153 void SfxViewFrame::DoActivate( sal_Bool bUI, SfxViewFrame* pOldFrame )
1155 DBG_CHKTHIS(SfxViewFrame, 0);
1156 SFX_APP();
1158 pDispatcher->DoActivate_Impl( bUI, pOldFrame );
1160 // If this ViewFrame has got a parent and this is not a parent of the
1161 // old ViewFrames, it gets a ParentActivate.
1162 if ( bUI )
1164 SfxViewFrame *pFrame = GetParentViewFrame();
1165 while ( pFrame )
1167 if ( !pOldFrame || !pOldFrame->GetFrame().IsParent( &pFrame->GetFrame() ) )
1168 pFrame->pDispatcher->DoParentActivate_Impl();
1169 pFrame = pFrame->GetParentViewFrame();
1174 //--------------------------------------------------------------------
1175 void SfxViewFrame::DoDeactivate(sal_Bool bUI, SfxViewFrame* pNewFrame )
1177 DBG_CHKTHIS(SfxViewFrame, 0);
1178 SFX_APP();
1179 pDispatcher->DoDeactivate_Impl( bUI, pNewFrame );
1181 // If this ViewFrame has got a parent and this is not a parent of the
1182 // new ViewFrames, it gets a ParentDeactivate.
1183 if ( bUI )
1185 SfxViewFrame *pFrame = GetParentViewFrame();
1186 while ( pFrame )
1188 if ( !pNewFrame || !pNewFrame->GetFrame().IsParent( &pFrame->GetFrame() ) )
1189 pFrame->pDispatcher->DoParentDeactivate_Impl();
1190 pFrame = pFrame->GetParentViewFrame();
1195 //------------------------------------------------------------------------
1196 void SfxViewFrame::InvalidateBorderImpl( const SfxViewShell* pSh )
1198 if( pSh && !nAdjustPosPixelLock )
1200 if ( GetViewShell() && GetWindow().IsVisible() )
1202 if ( GetFrame().IsInPlace() )
1204 return;
1207 DoAdjustPosSizePixel( (SfxViewShell *) GetViewShell(), Point(),
1208 GetWindow().GetOutputSizePixel() );
1213 //------------------------------------------------------------------------
1214 sal_Bool SfxViewFrame::SetBorderPixelImpl
1216 const SfxViewShell* pVSh,
1217 const SvBorder& rBorder
1221 pImp->aBorder = rBorder;
1223 if ( IsResizeInToOut_Impl() && !GetFrame().IsInPlace() )
1225 Size aSize = pVSh->GetWindow()->GetOutputSizePixel();
1226 if ( aSize.Width() && aSize.Height() )
1228 aSize.Width() += rBorder.Left() + rBorder.Right();
1229 aSize.Height() += rBorder.Top() + rBorder.Bottom();
1231 Size aOldSize = GetWindow().GetOutputSizePixel();
1232 GetWindow().SetOutputSizePixel( aSize );
1233 Window* pParent = &GetWindow();
1234 while ( pParent->GetParent() )
1235 pParent = pParent->GetParent();
1236 Size aOuterSize = pParent->GetOutputSizePixel();
1237 aOuterSize.Width() += ( aSize.Width() - aOldSize.Width() );
1238 aOuterSize.Height() += ( aSize.Height() - aOldSize.Height() );
1239 pParent->SetOutputSizePixel( aOuterSize );
1242 else
1244 Point aPoint;
1245 Rectangle aEditArea( aPoint, GetWindow().GetOutputSizePixel() );
1246 aEditArea.Left() += rBorder.Left();
1247 aEditArea.Right() -= rBorder.Right();
1248 aEditArea.Top() += rBorder.Top();
1249 aEditArea.Bottom() -= rBorder.Bottom();
1250 pVSh->GetWindow()->SetPosSizePixel( aEditArea.TopLeft(), aEditArea.GetSize() );
1253 return sal_True;
1256 //------------------------------------------------------------------------
1257 const SvBorder& SfxViewFrame::GetBorderPixelImpl
1259 const SfxViewShell* /*pSh*/
1260 ) const
1263 return pImp->aBorder;
1266 //--------------------------------------------------------------------
1267 void SfxViewFrame::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
1269 {DBG_CHKTHIS(SfxViewFrame, 0);}
1271 if( IsDowning_Impl())
1272 return;
1274 // we know only SimpleHints
1275 if ( rHint.IsA(TYPE(SfxSimpleHint)) )
1277 switch( ( (SfxSimpleHint&) rHint ).GetId() )
1279 case SFX_HINT_MODECHANGED:
1281 UpdateTitle();
1283 if ( !xObjSh.Is() )
1284 break;
1286 // Switch r/o?
1287 SfxBindings& rBind = GetBindings();
1288 rBind.Invalidate( SID_RELOAD );
1289 SfxDispatcher *pDispat = GetDispatcher();
1290 sal_Bool bWasReadOnly = pDispat->GetReadOnly_Impl();
1291 sal_Bool bIsReadOnly = xObjSh->IsReadOnly();
1292 if ( !bWasReadOnly != !bIsReadOnly )
1294 // Then also TITLE_CHANGED
1295 UpdateTitle();
1296 rBind.Invalidate( SID_FILE_NAME );
1297 rBind.Invalidate( SID_DOCINFO_TITLE );
1298 rBind.Invalidate( SID_EDITDOC );
1300 pDispat->GetBindings()->InvalidateAll(sal_True);
1301 pDispat->SetReadOnly_Impl( bIsReadOnly );
1303 // Only force and Dispatcher-Update, if it is done next
1304 // anyway, otherwise flickering or GPF is possibel since
1305 // the Writer for example prefers in Resize preform some
1306 // actions which has a SetReadOnlyUI in Dispatcher as a
1307 // result!
1309 if ( pDispat->IsUpdated_Impl() )
1310 pDispat->Update_Impl(sal_True);
1313 Enable( !xObjSh->IsInModalMode() );
1314 break;
1317 case SFX_HINT_TITLECHANGED:
1319 UpdateTitle();
1320 SfxBindings& rBind = GetBindings();
1321 rBind.Invalidate( SID_FILE_NAME );
1322 rBind.Invalidate( SID_DOCINFO_TITLE );
1323 rBind.Invalidate( SID_EDITDOC );
1324 rBind.Invalidate( SID_RELOAD );
1325 break;
1328 case SFX_HINT_DEINITIALIZING:
1329 GetFrame().DoClose();
1330 break;
1331 case SFX_HINT_DYING:
1332 // when the Object is being deleted, destroy the view too
1333 if ( xObjSh.Is() )
1334 ReleaseObjectShell_Impl();
1335 else
1336 GetFrame().DoClose();
1337 break;
1341 else if ( rHint.IsA(TYPE(SfxEventHint)) )
1343 // When the Document is loaded asynchronously, was the Dispatcher
1344 // set as ReadOnly, to what must be returned when the document itself
1345 // is not read only, and the loading is finished.
1346 switch ( ((SfxEventHint&)rHint).GetEventId() )
1348 case SFX_EVENT_MODIFYCHANGED:
1350 SfxBindings& rBind = GetBindings();
1351 rBind.Invalidate( SID_DOC_MODIFIED );
1352 rBind.Invalidate( SID_SAVEDOC );
1353 rBind.Invalidate( SID_RELOAD );
1354 rBind.Invalidate( SID_EDITDOC );
1355 break;
1358 case SFX_EVENT_OPENDOC:
1359 case SFX_EVENT_CREATEDOC:
1361 if ( !xObjSh.Is() )
1362 break;
1364 SfxBindings& rBind = GetBindings();
1365 rBind.Invalidate( SID_RELOAD );
1366 rBind.Invalidate( SID_EDITDOC );
1367 if ( !xObjSh->IsReadOnly() )
1369 // In contrast to above (TITLE_CHANGED) does the UI not
1370 // have to be updated because it was not obstructed
1372 // #i21560# InvalidateAll() causes the assertion
1373 // 'SfxBindings::Invalidate while in update" when
1374 // the sfx slot SID_BASICIDE_APPEAR is executed
1375 // via API from another thread (Java).
1376 // According to MBA this call is not necessary anymore,
1377 // because each document has its own SfxBindings.
1378 //GetDispatcher()->GetBindings()->InvalidateAll(sal_True);
1381 break;
1384 case SFX_EVENT_TOGGLEFULLSCREENMODE:
1386 if ( GetFrame().OwnsBindings_Impl() )
1387 GetBindings().GetDispatcher_Impl()->Update_Impl( sal_True );
1388 break;
1394 //------------------------------------------------------------------------
1395 void SfxViewFrame::Construct_Impl( SfxObjectShell *pObjSh )
1397 pImp->bResizeInToOut = sal_True;
1398 pImp->bDontOverwriteResizeInToOut = sal_False;
1399 pImp->bObjLocked = sal_False;
1400 pImp->pFocusWin = 0;
1401 pImp->pActiveChild = NULL;
1402 pImp->nCurViewId = 0;
1403 pImp->bReloading = sal_False;
1404 pImp->bIsDowning = sal_False;
1405 pImp->bModal = sal_False;
1406 pImp->bEnabled = sal_True;
1407 pImp->nDocViewNo = 0;
1408 pImp->aMargin = Size( -1, -1 );
1409 pImp->pWindow = 0;
1411 SetPool( &SFX_APP()->GetPool() );
1412 pDispatcher = new SfxDispatcher(this);
1413 if ( !GetBindings().GetDispatcher() )
1414 GetBindings().SetDispatcher( pDispatcher );
1416 xObjSh = pObjSh;
1417 if ( xObjSh.Is() && xObjSh->IsPreview() )
1418 SetQuietMode_Impl( sal_True );
1420 if ( pObjSh )
1422 pDispatcher->Push( *SFX_APP() );
1423 SfxModule* pModule = xObjSh->GetModule();
1424 if( pModule )
1425 pDispatcher->Push( *pModule );
1426 pDispatcher->Push( *this );
1427 pDispatcher->Push( *pObjSh );
1428 pDispatcher->Flush();
1429 StartListening( *pObjSh );
1430 pObjSh->ViewAssigned();
1431 Notify( *pObjSh, SfxSimpleHint(SFX_HINT_TITLECHANGED) );
1432 Notify( *pObjSh, SfxSimpleHint(SFX_HINT_DOCCHANGED) );
1433 pDispatcher->SetReadOnly_Impl( pObjSh->IsReadOnly() );
1435 else
1437 pDispatcher->Push( *SFX_APP() );
1438 pDispatcher->Push( *this );
1439 pDispatcher->Flush();
1442 SfxViewFrameArr_Impl &rViewArr = SFX_APP()->GetViewFrames_Impl();
1443 rViewArr.push_back( this );
1446 SfxViewFrame::SfxViewFrame
1448 SfxFrame& rFrame,
1449 SfxObjectShell* pObjShell
1452 /* [Description]
1454 Constructor of SfxViewFrame for a <SfxObjectShell> from the Resource.
1455 The 'nViewId' to the created <SfxViewShell> can be returned.
1456 (default is the SfxViewShell-Subclass that was registered first).
1459 : pImp( new SfxViewFrame_Impl( rFrame ) )
1460 , pDispatcher(0)
1461 , pBindings( new SfxBindings )
1462 , nAdjustPosPixelLock( 0 )
1464 DBG_CTOR( SfxViewFrame, NULL );
1466 rFrame.SetCurrentViewFrame_Impl( this );
1467 rFrame.SetFrameType_Impl( GetFrameType() | SFXFRAME_HASTITLE );
1468 Construct_Impl( pObjShell );
1470 pImp->pWindow = new SfxFrameViewWindow_Impl( this, rFrame.GetWindow() );
1471 pImp->pWindow->SetSizePixel( rFrame.GetWindow().GetOutputSizePixel() );
1472 rFrame.SetOwnsBindings_Impl( sal_True );
1473 rFrame.CreateWorkWindow_Impl();
1476 //------------------------------------------------------------------------
1477 SfxViewFrame::~SfxViewFrame()
1479 DBG_DTOR(SfxViewFrame, 0);
1481 SetDowning_Impl();
1483 if ( SfxViewFrame::Current() == this )
1484 SfxViewFrame::SetViewFrame( NULL );
1486 ReleaseObjectShell_Impl();
1488 if ( GetFrame().OwnsBindings_Impl() )
1489 // The Bindings delete the Frame!
1490 KillDispatcher_Impl();
1492 delete pImp->pWindow;
1494 if ( GetFrame().GetCurrentViewFrame() == this )
1495 GetFrame().SetCurrentViewFrame_Impl( NULL );
1497 // Unregister from the Frame List.
1498 SfxApplication *pSfxApp = SFX_APP();
1499 SfxViewFrameArr_Impl &rFrames = pSfxApp->GetViewFrames_Impl();
1500 SfxViewFrameArr_Impl::iterator it = std::find( rFrames.begin(), rFrames.end(), this );
1501 rFrames.erase( it );
1503 // Delete Member
1504 KillDispatcher_Impl();
1506 delete pImp;
1509 //------------------------------------------------------------------------
1510 void SfxViewFrame::KillDispatcher_Impl()
1512 // Remove and delete the Dispatcher.
1515 DBG_CHKTHIS(SfxViewFrame, 0);
1517 SfxModule* pModule = xObjSh.Is() ? xObjSh->GetModule() : 0;
1518 if ( xObjSh.Is() )
1519 ReleaseObjectShell_Impl();
1520 if ( pDispatcher )
1522 if( pModule )
1523 pDispatcher->Pop( *pModule, SFX_SHELL_POP_UNTIL );
1524 else
1525 pDispatcher->Pop( *this );
1526 DELETEZ(pDispatcher);
1530 //------------------------------------------------------------------------
1531 SfxViewFrame* SfxViewFrame::Current()
1533 return SfxApplication::Get() ? SFX_APP()->Get_Impl()->pViewFrame : NULL;
1536 //--------------------------------------------------------------------
1537 // returns the first window of spec. type viewing the specified doc.
1538 SfxViewFrame* SfxViewFrame::GetFirst
1540 const SfxObjectShell* pDoc,
1541 sal_Bool bOnlyIfVisible
1544 SfxApplication *pSfxApp = SFX_APP();
1545 SfxViewFrameArr_Impl &rFrames = pSfxApp->GetViewFrames_Impl();
1547 // search for a SfxDocument of the specified type
1548 for ( sal_uInt16 nPos = 0; nPos < rFrames.size(); ++nPos )
1550 SfxViewFrame *pFrame = rFrames[nPos];
1551 if ( ( !pDoc || pDoc == pFrame->GetObjectShell() )
1552 && ( !bOnlyIfVisible || pFrame->IsVisible() )
1554 return pFrame;
1557 return 0;
1559 //--------------------------------------------------------------------
1561 // returns thenext window of spec. type viewing the specified doc.
1562 SfxViewFrame* SfxViewFrame::GetNext
1564 const SfxViewFrame& rPrev,
1565 const SfxObjectShell* pDoc,
1566 sal_Bool bOnlyIfVisible
1569 SfxApplication *pSfxApp = SFX_APP();
1570 SfxViewFrameArr_Impl &rFrames = pSfxApp->GetViewFrames_Impl();
1572 // refind the specified predecessor
1573 sal_uInt16 nPos;
1574 for ( nPos = 0; nPos < rFrames.size(); ++nPos )
1575 if ( rFrames[nPos] == &rPrev )
1576 break;
1578 // search for a Frame of the specified type
1579 for ( ++nPos; nPos < rFrames.size(); ++nPos )
1581 SfxViewFrame *pFrame = rFrames[nPos];
1582 if ( ( !pDoc || pDoc == pFrame->GetObjectShell() )
1583 && ( !bOnlyIfVisible || pFrame->IsVisible() )
1585 return pFrame;
1587 return 0;
1590 //--------------------------------------------------------------------
1591 SfxProgress* SfxViewFrame::GetProgress() const
1593 SfxObjectShell *pObjSh = GetObjectShell();
1594 return pObjSh ? pObjSh->GetProgress() : 0;
1597 //--------------------------------------------------------------------
1598 void SfxViewFrame::DoAdjustPosSizePixel //! divide on Inner.../Outer...
1600 SfxViewShell* pSh,
1601 const Point& rPos,
1602 const Size& rSize
1605 DBG_CHKTHIS(SfxViewFrame, 0);
1607 // Components do not use this Method!
1608 if( pSh && pSh->GetWindow() && !nAdjustPosPixelLock )
1610 nAdjustPosPixelLock++;
1611 if ( pImp->bResizeInToOut )
1612 pSh->InnerResizePixel( rPos, rSize );
1613 else
1614 pSh->OuterResizePixel( rPos, rSize );
1615 nAdjustPosPixelLock--;
1619 //========================================================================
1621 int SfxViewFrameItem::operator==( const SfxPoolItem &rItem ) const
1623 return PTR_CAST(SfxViewFrameItem, &rItem)->pFrame== pFrame;
1626 //--------------------------------------------------------------------
1627 String SfxViewFrameItem::GetValueText() const
1629 return String();
1632 //--------------------------------------------------------------------
1633 SfxPoolItem* SfxViewFrameItem::Clone( SfxItemPool *) const
1635 return new SfxViewFrameItem( pFrame);
1638 //--------------------------------------------------------------------
1639 void SfxViewFrame::SetViewShell_Impl( SfxViewShell *pVSh )
1641 /* [Description]
1643 Internal Method to set the current <SfxViewShell> Instance,
1644 that is active int this SfxViewFrame at the moment.
1648 SfxShell::SetViewShell_Impl( pVSh );
1650 // Hack: InPlaceMode
1651 if ( pVSh )
1652 pImp->bResizeInToOut = sal_False;
1655 //--------------------------------------------------------------------
1656 /* [Description]
1658 The ParentViewFrame of the Containers ViewFrame in the internal InPlace
1661 //TODO/LATER: is it still necessary? is there a replacement for GetParentViewFrame_Impl?
1662 SfxViewFrame* SfxViewFrame::GetParentViewFrame_Impl() const
1664 return NULL;
1667 //--------------------------------------------------------------------
1668 void SfxViewFrame::ForceOuterResize_Impl(sal_Bool bOn)
1670 if ( !pImp->bDontOverwriteResizeInToOut )
1671 pImp->bResizeInToOut = !bOn;
1674 //--------------------------------------------------------------------
1675 sal_Bool SfxViewFrame::IsResizeInToOut_Impl() const
1677 return pImp->bResizeInToOut;
1680 //--------------------------------------------------------------------
1681 void SfxViewFrame::GetDocNumber_Impl()
1683 DBG_ASSERT( GetObjectShell(), "No Document!" );
1684 GetObjectShell()->SetNamedVisibility_Impl();
1685 pImp->nDocViewNo = GetObjectShell()->GetNoSet_Impl().GetFreeIndex()+1;
1688 //--------------------------------------------------------------------
1690 void SfxViewFrame::Enable( sal_Bool bEnable )
1692 if ( bEnable != pImp->bEnabled )
1694 pImp->bEnabled = bEnable;
1696 // e.g. InPlace-Frames have a parent...
1697 SfxViewFrame *pParent = GetParentViewFrame_Impl();
1698 if ( pParent )
1700 pParent->Enable( bEnable );
1702 else
1704 Window *pWindow = &GetFrame().GetTopFrame().GetWindow();
1705 if ( !bEnable )
1706 pImp->bWindowWasEnabled = pWindow->IsInputEnabled();
1707 if ( !bEnable || pImp->bWindowWasEnabled )
1708 pWindow->EnableInput( bEnable, sal_True );
1711 // cursor and focus
1712 SfxViewShell* pViewSh = GetViewShell();
1713 if ( bEnable )
1715 // show cursor
1716 if ( pViewSh )
1717 pViewSh->ShowCursor();
1719 else
1721 // hide cursor
1722 if ( pViewSh )
1723 pViewSh->ShowCursor(sal_False);
1728 //--------------------------------------------------------------------
1729 void SfxViewFrame::Show()
1731 /* [Description]
1733 This method makes the Frame-Window visible and before transmitts the
1734 window name. In addition, the document is held. In general one can never
1735 show the window directly!
1739 // First lock the objectShell so that UpdateTitle() is valid:
1740 // IsVisible() == sal_True (:#)
1741 if ( xObjSh.Is() )
1743 xObjSh->GetMedium()->GetItemSet()->ClearItem( SID_HIDDEN );
1744 if ( !pImp->bObjLocked )
1745 LockObjectShell_Impl( sal_True );
1747 // Adjust Doc-Shell titel nummer, get unique view-no
1748 if ( 0 == pImp->nDocViewNo )
1750 GetDocNumber_Impl();
1751 UpdateTitle();
1754 else
1755 UpdateTitle();
1757 // Display Frame-window, but only if the ViewFrame has no window of its
1758 // own or if it does not contain a Component
1759 if ( &GetWindow() == &GetFrame().GetWindow() || !GetFrame().HasComponent() )
1760 GetWindow().Show();
1761 GetFrame().GetWindow().Show();
1764 //--------------------------------------------------------------------
1765 sal_Bool SfxViewFrame::IsVisible() const
1767 return pImp->bObjLocked;
1770 //--------------------------------------------------------------------
1771 void SfxViewFrame::LockObjectShell_Impl( sal_Bool bLock )
1773 DBG_ASSERT( pImp->bObjLocked != bLock, "Wrong Locked status!" );
1775 DBG_ASSERT( GetObjectShell(), "No Document!" );
1776 GetObjectShell()->OwnerLock(bLock);
1777 pImp->bObjLocked = bLock;
1780 //--------------------------------------------------------------------
1781 void SfxViewFrame::MakeActive_Impl( sal_Bool bGrabFocus )
1783 if ( GetViewShell() && !GetFrame().IsClosing_Impl() )
1785 if ( IsVisible() )
1787 if ( GetViewShell() )
1789 sal_Bool bPreview = sal_False;
1790 if ( GetObjectShell()->IsPreview() )
1792 bPreview = sal_True;
1794 else
1796 SfxViewFrame* pParent = GetParentViewFrame();
1797 if ( pParent )
1798 pParent->SetActiveChildFrame_Impl( this );
1801 SfxViewFrame* pCurrent = SfxViewFrame::Current();
1802 css::uno::Reference< css::frame::XFrame > xFrame = GetFrame().GetFrameInterface();
1803 if ( !bPreview )
1805 SetViewFrame( this );
1806 GetBindings().SetActiveFrame( css::uno::Reference< css::frame::XFrame >() );
1807 uno::Reference< frame::XFramesSupplier > xSupp( xFrame, uno::UNO_QUERY );
1808 if ( xSupp.is() )
1809 xSupp->setActiveFrame( uno::Reference < frame::XFrame >() );
1811 css::uno::Reference< css::awt::XWindow > xContainerWindow = xFrame->getContainerWindow();
1812 Window* pWindow = VCLUnoHelper::GetWindow(xContainerWindow);
1813 if (pWindow && pWindow->HasChildPathFocus() && bGrabFocus)
1815 SfxInPlaceClient *pCli = GetViewShell()->GetUIActiveClient();
1816 if ( ( !pCli || !pCli->IsObjectUIActive() ) &&
1817 ( !pCurrent || pCurrent->GetParentViewFrame_Impl() != this ) )
1818 GetFrame().GrabFocusOnComponent_Impl();
1821 else
1823 GetBindings().SetDispatcher( GetDispatcher() );
1824 GetBindings().SetActiveFrame( ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > () );
1825 GetDispatcher()->Update_Impl( sal_False );
1832 //-------------------------------------------------------------------------
1834 void SfxViewFrame::SetQuietMode_Impl( sal_Bool bOn )
1836 GetDispatcher()->SetQuietMode_Impl( bOn );
1839 //-------------------------------------------------------------------------
1841 SfxObjectShell* SfxViewFrame::GetObjectShell()
1843 return xObjSh;
1846 const Size& SfxViewFrame::GetMargin_Impl() const
1848 return pImp->aMargin;
1851 void SfxViewFrame::SetActiveChildFrame_Impl( SfxViewFrame *pViewFrame )
1853 if ( pViewFrame != pImp->pActiveChild )
1855 pImp->pActiveChild = pViewFrame;
1857 Reference< XFramesSupplier > xFrame( GetFrame().GetFrameInterface(), UNO_QUERY );
1858 Reference< XFrame > xActive;
1859 if ( pViewFrame )
1860 xActive = pViewFrame->GetFrame().GetFrameInterface();
1862 if ( xFrame.is() ) // xFrame can be NULL
1863 xFrame->setActiveFrame( xActive );
1867 SfxViewFrame* SfxViewFrame::GetActiveChildFrame_Impl() const
1869 SfxViewFrame *pViewFrame = pImp->pActiveChild;
1870 return pViewFrame;
1873 //--------------------------------------------------------------------
1874 SfxViewFrame* SfxViewFrame::LoadViewIntoFrame_Impl_NoThrow( const SfxObjectShell& i_rDoc, const Reference< XFrame >& i_rFrame,
1875 const sal_uInt16 i_nViewId, const bool i_bHidden )
1877 Reference< XFrame > xFrame( i_rFrame );
1878 bool bOwnFrame = false;
1879 SfxViewShell* pSuccessView = NULL;
1882 if ( !xFrame.is() )
1884 Reference < XDesktop2 > xDesktop = Desktop::create( ::comphelper::getProcessComponentContext() );
1886 if ( !i_bHidden )
1890 // if there is a backing component, use it
1891 Reference< XFramesSupplier > xTaskSupplier( xDesktop , css::uno::UNO_QUERY_THROW );
1892 ::framework::FrameListAnalyzer aAnalyzer( xTaskSupplier, Reference< XFrame >(), ::framework::FrameListAnalyzer::E_BACKINGCOMPONENT );
1894 if ( aAnalyzer.m_xBackingComponent.is() )
1895 xFrame = aAnalyzer.m_xBackingComponent;
1897 catch( uno::Exception& )
1901 if ( !xFrame.is() )
1902 xFrame.set( xDesktop->findFrame( "_blank", 0 ), UNO_SET_THROW );
1904 bOwnFrame = true;
1907 pSuccessView = LoadViewIntoFrame_Impl(
1908 i_rDoc,
1909 xFrame,
1910 Sequence< PropertyValue >(), // means "reuse existing model's args"
1911 i_nViewId,
1912 i_bHidden
1915 if ( bOwnFrame && !i_bHidden )
1917 // ensure the frame/window is visible
1918 Reference< XWindow > xContainerWindow( xFrame->getContainerWindow(), UNO_SET_THROW );
1919 xContainerWindow->setVisible( sal_True );
1922 catch( const Exception& )
1924 DBG_UNHANDLED_EXCEPTION();
1927 if ( pSuccessView )
1928 return pSuccessView->GetViewFrame();
1930 if ( bOwnFrame )
1934 xFrame->dispose();
1936 catch( const Exception& )
1938 DBG_UNHANDLED_EXCEPTION();
1942 return NULL;
1945 //--------------------------------------------------------------------
1946 SfxViewShell* SfxViewFrame::LoadViewIntoFrame_Impl( const SfxObjectShell& i_rDoc, const Reference< XFrame >& i_rFrame,
1947 const Sequence< PropertyValue >& i_rLoadArgs, const sal_uInt16 i_nViewId,
1948 const bool i_bHidden )
1950 Reference< XModel > xDocument( i_rDoc.GetModel(), UNO_SET_THROW );
1952 ::comphelper::NamedValueCollection aTransformLoadArgs( i_rLoadArgs.getLength() ? i_rLoadArgs : xDocument->getArgs() );
1953 aTransformLoadArgs.put( "Model", xDocument );
1954 if ( i_nViewId )
1955 aTransformLoadArgs.put( "ViewId", sal_Int16( i_nViewId ) );
1956 if ( i_bHidden )
1957 aTransformLoadArgs.put( "Hidden", i_bHidden );
1958 else
1959 aTransformLoadArgs.remove( "Hidden" );
1961 OUString sURL( "private:object" );
1962 if ( sURL.isEmpty() )
1963 sURL = i_rDoc.GetFactory().GetFactoryURL();
1965 Reference< XComponentLoader > xLoader( i_rFrame, UNO_QUERY_THROW );
1966 xLoader->loadComponentFromURL( sURL, OUString("_self"), 0,
1967 aTransformLoadArgs.getPropertyValues() );
1969 SfxViewShell* pViewShell = SfxViewShell::Get( i_rFrame->getController() );
1970 ENSURE_OR_THROW( pViewShell,
1971 "SfxViewFrame::LoadViewIntoFrame_Impl: loading an SFX doc into a frame resulted in a non-SFX view - quite impossible" );
1972 return pViewShell;
1975 //--------------------------------------------------------------------
1977 SfxViewFrame* SfxViewFrame::LoadHiddenDocument( SfxObjectShell& i_rDoc, const sal_uInt16 i_nViewId )
1979 return LoadViewIntoFrame_Impl_NoThrow( i_rDoc, Reference< XFrame >(), i_nViewId, true );
1982 //--------------------------------------------------------------------
1984 SfxViewFrame* SfxViewFrame::LoadDocument( SfxObjectShell& i_rDoc, const sal_uInt16 i_nViewId )
1986 return LoadViewIntoFrame_Impl_NoThrow( i_rDoc, Reference< XFrame >(), i_nViewId, false );
1989 //--------------------------------------------------------------------
1991 SfxViewFrame* SfxViewFrame::LoadDocumentIntoFrame( SfxObjectShell& i_rDoc, const Reference< XFrame >& i_rTargetFrame, const sal_uInt16 i_nViewId )
1993 return LoadViewIntoFrame_Impl_NoThrow( i_rDoc, i_rTargetFrame, i_nViewId, false );
1996 //--------------------------------------------------------------------
1998 SfxViewFrame* SfxViewFrame::LoadDocumentIntoFrame( SfxObjectShell& i_rDoc, const SfxFrameItem* i_pFrameItem, const sal_uInt16 i_nViewId )
2000 return LoadViewIntoFrame_Impl_NoThrow( i_rDoc, i_pFrameItem && i_pFrameItem->GetFrame() ? i_pFrameItem->GetFrame()->GetFrameInterface() : NULL, i_nViewId, false );
2003 //--------------------------------------------------------------------
2004 SfxViewFrame* SfxViewFrame::DisplayNewDocument( SfxObjectShell& i_rDoc, const SfxRequest& i_rCreateDocRequest, const sal_uInt16 i_nViewId )
2006 SFX_REQUEST_ARG( i_rCreateDocRequest, pFrameItem, SfxUnoFrameItem, SID_FILLFRAME, sal_False );
2007 SFX_REQUEST_ARG( i_rCreateDocRequest, pHiddenItem, SfxBoolItem, SID_HIDDEN, sal_False );
2009 return LoadViewIntoFrame_Impl_NoThrow(
2010 i_rDoc,
2011 pFrameItem ? pFrameItem->GetFrame() : NULL,
2012 i_nViewId,
2013 pHiddenItem ? pHiddenItem->GetValue() : false
2017 //--------------------------------------------------------------------
2019 SfxViewFrame* SfxViewFrame::Get( const Reference< XController>& i_rController, const SfxObjectShell* i_pDoc )
2021 if ( !i_rController.is() )
2022 return NULL;
2024 const SfxObjectShell* pDoc = i_pDoc;
2025 if ( !pDoc )
2027 Reference< XModel > xDocument( i_rController->getModel() );
2028 for ( pDoc = SfxObjectShell::GetFirst( 0, false );
2029 pDoc;
2030 pDoc = SfxObjectShell::GetNext( *pDoc, 0, false )
2033 if ( pDoc->GetModel() == xDocument )
2034 break;
2038 SfxViewFrame* pViewFrame = NULL;
2039 for ( pViewFrame = SfxViewFrame::GetFirst( pDoc, sal_False );
2040 pViewFrame;
2041 pViewFrame = SfxViewFrame::GetNext( *pViewFrame, pDoc, sal_False )
2044 if ( pViewFrame->GetViewShell()->GetController() == i_rController )
2045 break;
2048 return pViewFrame;
2051 //--------------------------------------------------------------------
2053 void SfxViewFrame::SaveCurrentViewData_Impl( const sal_uInt16 i_nNewViewId )
2055 SfxViewShell* pCurrentShell = GetViewShell();
2056 ENSURE_OR_RETURN_VOID( pCurrentShell != NULL, "SfxViewFrame::SaveCurrentViewData_Impl: no current view shell -> no current view data!" );
2058 // determine the logical (API) view name
2059 const SfxObjectFactory& rDocFactory( pCurrentShell->GetObjectShell()->GetFactory() );
2060 const sal_uInt16 nCurViewNo = rDocFactory.GetViewNo_Impl( GetCurViewId(), 0 );
2061 const String sCurrentViewName = rDocFactory.GetViewFactory( nCurViewNo ).GetAPIViewName();
2062 const sal_uInt16 nNewViewNo = rDocFactory.GetViewNo_Impl( i_nNewViewId, 0 );
2063 const String sNewViewName = rDocFactory.GetViewFactory( nNewViewNo ).GetAPIViewName();
2064 if ( ( sCurrentViewName.Len() == 0 ) || ( sNewViewName.Len() == 0 ) )
2066 // can't say anything about the view, the respective application did not yet migrate its code to
2067 // named view factories => bail out
2068 OSL_FAIL( "SfxViewFrame::SaveCurrentViewData_Impl: views without API names? Shouldn't happen anymore?" );
2069 return;
2071 OSL_ENSURE( !sNewViewName.Equals( sCurrentViewName ), "SfxViewFrame::SaveCurrentViewData_Impl: suspicious: new and old view name are identical!" );
2073 // save the view data only when we're moving from a non-print-preview to the print-preview view
2074 if ( !sNewViewName.EqualsAscii( "PrintPreview" ) )
2075 return;
2077 // retrieve the view data from the view
2078 Sequence< PropertyValue > aViewData;
2079 pCurrentShell->WriteUserDataSequence( aViewData );
2083 // retrieve view data (for *all* views) from the model
2084 const Reference< XController > xController( pCurrentShell->GetController(), UNO_SET_THROW );
2085 const Reference< XViewDataSupplier > xViewDataSupplier( xController->getModel(), UNO_QUERY_THROW );
2086 const Reference< XIndexContainer > xViewData( xViewDataSupplier->getViewData(), UNO_QUERY_THROW );
2088 // look up the one view data item which corresponds to our current view, and remove it
2089 const sal_Int32 nCount = xViewData->getCount();
2090 for ( sal_Int32 i=0; i<nCount; ++i )
2092 const ::comphelper::NamedValueCollection aCurViewData( xViewData->getByIndex(i) );
2093 OUString sViewId( aCurViewData.getOrDefault( "ViewId", OUString() ) );
2094 if ( sViewId.isEmpty() )
2095 continue;
2097 const SfxViewFactory* pViewFactory = rDocFactory.GetViewFactoryByViewName( sViewId );
2098 if ( pViewFactory == NULL )
2099 continue;
2101 if ( pViewFactory->GetOrdinal() == GetCurViewId() )
2103 xViewData->removeByIndex(i);
2104 break;
2108 // then replace it with the most recent view data we just obtained
2109 xViewData->insertByIndex( 0, makeAny( aViewData ) );
2111 catch( const Exception& )
2113 DBG_UNHANDLED_EXCEPTION();
2117 //--------------------------------------------------------------------
2119 sal_Bool SfxViewFrame::SwitchToViewShell_Impl
2121 sal_uInt16 nViewIdOrNo, /* > 0
2122 Registration-Id of the View, to which the
2123 the method should switch, for example the one
2124 that will be created.
2126 == 0
2127 First use the Default view. */
2129 sal_Bool bIsIndex /* sal_True
2130 'nViewIdOrNo' is no Registration-Id instead
2131 an Index of <SfxViewFrame> in <SfxObjectShell>.
2135 /* [Description]
2137 Internal Method for switching to another <SfxViewShell> subclass,
2138 which should be created in this SfxMDIFrame. If no SfxViewShell exist
2139 in this SfxMDIFrame, then one will first be created.
2142 [Return Value]
2144 sal_Bool sal_True
2145 requested SfxViewShell was created and a
2146 possibly existing one deleted
2148 sal_False
2149 SfxViewShell requested could not be created,
2150 the existing SfxViewShell thus continue to exist
2156 ENSURE_OR_THROW( GetObjectShell() != NULL, "not possible without a document" );
2158 // if we already have a view shell, remove it
2159 SfxViewShell* pOldSh = GetViewShell();
2160 OSL_PRECOND( pOldSh, "SfxViewFrame::SwitchToViewShell_Impl: that's called *switch* (not for *initial-load*) for a reason" );
2161 if ( pOldSh )
2163 // ask whether it can be closed
2164 if ( !pOldSh->PrepareClose( sal_True ) )
2165 return sal_False;
2167 // remove sub shells from Dispatcher before switching to new ViewShell
2168 PopShellAndSubShells_Impl( *pOldSh );
2171 GetBindings().ENTERREGISTRATIONS();
2172 LockAdjustPosSizePixel();
2174 // ID of the new view
2175 SfxObjectFactory& rDocFact = GetObjectShell()->GetFactory();
2176 const sal_uInt16 nViewId = ( bIsIndex || !nViewIdOrNo ) ? rDocFact.GetViewFactory( nViewIdOrNo ).GetOrdinal() : nViewIdOrNo;
2178 // save the view data of the old view, so it can be restored later on (when needed)
2179 SaveCurrentViewData_Impl( nViewId );
2181 // create and load new ViewShell
2182 SfxViewShell* pNewSh = LoadViewIntoFrame_Impl(
2183 *GetObjectShell(),
2184 GetFrame().GetFrameInterface(),
2185 Sequence< PropertyValue >(), // means "reuse existing model's args"
2186 nViewId,
2187 false
2190 // allow resize events to be processed
2191 UnlockAdjustPosSizePixel();
2193 if ( GetWindow().IsReallyVisible() )
2194 DoAdjustPosSizePixel( pNewSh, Point(), GetWindow().GetOutputSizePixel() );
2196 GetBindings().LEAVEREGISTRATIONS();
2197 delete pOldSh;
2199 catch ( const com::sun::star::uno::Exception& )
2201 // the SfxCode is not able to cope with exceptions thrown while creating views
2202 // the code will crash in the stack unwinding procedure, so we shouldn't let exceptions go through here
2203 DBG_UNHANDLED_EXCEPTION();
2204 return sal_False;
2207 DBG_ASSERT( SFX_APP()->GetViewFrames_Impl().size() == SFX_APP()->GetViewShells_Impl().size(), "Inconsistent view arrays!" );
2208 return sal_True;
2211 //-------------------------------------------------------------------------
2212 void SfxViewFrame::SetCurViewId_Impl( const sal_uInt16 i_nID )
2214 pImp->nCurViewId = i_nID;
2217 //-------------------------------------------------------------------------
2218 sal_uInt16 SfxViewFrame::GetCurViewId() const
2220 return pImp->nCurViewId;
2223 //-------------------------------------------------------------------------
2224 void SfxViewFrame::ExecView_Impl
2226 SfxRequest& rReq // The executable <SfxRequest>
2229 /* [Description]
2231 Internal method to run the slot for the <SfxShell> Subclass in the
2232 SfxViewFrame <SVIDL> described slots.
2236 DBG_CHKTHIS(SfxViewFrame, 0);
2238 // If the Shells are just being replaced...
2239 if ( !GetObjectShell() || !GetViewShell() )
2240 return;
2242 switch ( rReq.GetSlot() )
2244 case SID_TERMINATE_INPLACEACTIVATION :
2246 SfxInPlaceClient* pClient = GetViewShell()->GetUIActiveClient();
2247 if ( pClient )
2248 pClient->DeactivateObject();
2249 break;
2252 case SID_VIEWSHELL:
2254 const SfxPoolItem *pItem = 0;
2255 if ( rReq.GetArgs()
2256 && SFX_ITEM_SET == rReq.GetArgs()->GetItemState( SID_VIEWSHELL, sal_False, &pItem )
2259 const sal_uInt16 nViewId = static_cast< const SfxUInt16Item* >( pItem )->GetValue();
2260 sal_Bool bSuccess = SwitchToViewShell_Impl( nViewId );
2261 rReq.SetReturnValue( SfxBoolItem( 0, bSuccess ) );
2263 break;
2266 case SID_VIEWSHELL0:
2267 case SID_VIEWSHELL1:
2268 case SID_VIEWSHELL2:
2269 case SID_VIEWSHELL3:
2270 case SID_VIEWSHELL4:
2272 const sal_uInt16 nViewNo = rReq.GetSlot() - SID_VIEWSHELL0;
2273 sal_Bool bSuccess = SwitchToViewShell_Impl( nViewNo, sal_True );
2274 rReq.SetReturnValue( SfxBoolItem( 0, bSuccess ) );
2275 break;
2278 case SID_NEWWINDOW:
2280 // Hack. at the moment a virtual Function
2281 if ( !GetViewShell()->NewWindowAllowed() )
2283 OSL_FAIL( "You should have disabled the 'Window/New Window' slot!" );
2284 return;
2287 // Get ViewData of FrameSets recursivly.
2288 GetFrame().GetViewData_Impl();
2289 SfxMedium* pMed = GetObjectShell()->GetMedium();
2291 // do not open the new window hidden
2292 pMed->GetItemSet()->ClearItem( SID_HIDDEN );
2294 // the view ID (optional arg. TODO: this is currently not supported in the slot definition ...)
2295 SFX_REQUEST_ARG( rReq, pViewIdItem, SfxUInt16Item, SID_VIEW_ID, sal_False );
2296 const sal_uInt16 nViewId = pViewIdItem ? pViewIdItem->GetValue() : GetCurViewId();
2298 Reference < XFrame > xFrame;
2299 // the frame (optional arg. TODO: this is currently not supported in the slot definition ...)
2300 SFX_REQUEST_ARG( rReq, pFrameItem, SfxUnoFrameItem, SID_FILLFRAME, sal_False );
2301 if ( pFrameItem )
2302 xFrame = pFrameItem->GetFrame();
2304 LoadViewIntoFrame_Impl_NoThrow( *GetObjectShell(), xFrame, nViewId, false );
2306 rReq.Done();
2307 break;
2310 case SID_OBJECT:
2312 SFX_REQUEST_ARG( rReq, pItem, SfxUInt16Item, SID_OBJECT, sal_False );
2314 SfxViewShell *pViewShell = GetViewShell();
2315 if ( pViewShell && pItem )
2317 pViewShell->DoVerb( pItem->GetValue() );
2318 rReq.Done();
2319 break;;
2325 //-------------------------------------------------------------------------
2326 /* TODO as96863:
2327 This method try to collect information about the count of currently open documents.
2328 But the algorithm is implemented very simple ...
2329 E.g. hidden documents should be ignored here ... but they are counted.
2330 TODO: export special helper "framework::FrameListAnalyzer" within the framework module
2331 and use it here.
2333 sal_Bool impl_maxOpenDocCountReached()
2337 css::uno::Reference< css::uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
2338 css::uno::Any aVal = ::comphelper::ConfigurationHelper::readDirectKey(
2339 xContext,
2340 OUString("org.openoffice.Office.Common/"),
2341 OUString("Misc"),
2342 OUString("MaxOpenDocuments"),
2343 ::comphelper::ConfigurationHelper::E_READONLY);
2345 // NIL means: count of allowed documents = infinite !
2346 if ( ! aVal.hasValue())
2347 return sal_False;
2349 sal_Int32 nOpenDocs = 0;
2350 sal_Int32 nMaxDocs = 0;
2351 aVal >>= nMaxDocs;
2353 css::uno::Reference< css::frame::XDesktop2 > xDesktop = css::frame::Desktop::create(xContext);
2354 css::uno::Reference< css::container::XIndexAccess > xCont (xDesktop->getFrames() , css::uno::UNO_QUERY_THROW);
2356 sal_Int32 c = xCont->getCount();
2357 sal_Int32 i = 0;
2359 for (i=0; i<c; ++i)
2363 css::uno::Reference< css::frame::XFrame > xFrame;
2364 xCont->getByIndex(i) >>= xFrame;
2365 if ( ! xFrame.is())
2366 continue;
2368 // a) do not count the help window
2369 if ( xFrame->getName() == "OFFICE_HELP_TASK" )
2370 continue;
2372 // b) count all other frames
2373 ++nOpenDocs;
2375 catch(const css::uno::Exception&)
2376 // A IndexOutOfBoundException can happen in multithreaded
2377 // environments, where any other thread can change this
2378 // container !
2379 { continue; }
2382 return (nOpenDocs >= nMaxDocs);
2384 catch(const css::uno::Exception&)
2387 // Any internal error is no reason to stop opening documents !
2388 // Limitation of opening documents is a special "nice to have" feature.
2389 // Otherwhise it can happen, that NO document will be opened ...
2390 return sal_False;
2393 //-------------------------------------------------------------------------
2394 void SfxViewFrame::StateView_Impl
2396 SfxItemSet& rSet /* empty <SfxItemSet> with <Which-Ranges>,
2397 which describes the Slot Ids */
2400 /* [Description]
2402 This internal methode returns in 'rSet' the Status for the <SfxShell>
2403 Subclass SfxViewFrame in the <SVIDL> described <Slots>.
2405 Thus exactly those Slots-IDs that are recognized as beeing invalid by Sfx
2406 are included as Which-ranges in 'rSet'. If there exists a mapping for
2407 single slot-IDs of the <SfxItemPool> set in the shell, then the respective
2408 Which-IDs are used so that items can be replaced directly with a working
2409 Core::sun::com::star::script::Engine of the Which-IDs if possible. .
2413 DBG_CHKTHIS(SfxViewFrame, 0);
2415 SfxObjectShell *pDocSh = GetObjectShell();
2417 if ( !pDocSh )
2418 // I'm just on reload and am yielding myself ...
2419 return;
2421 const sal_uInt16 *pRanges = rSet.GetRanges();
2422 DBG_ASSERT(pRanges, "Set with no Range");
2423 while ( *pRanges )
2425 for ( sal_uInt16 nWhich = *pRanges++; nWhich <= *pRanges; ++nWhich )
2427 switch(nWhich)
2429 case SID_VIEWSHELL:
2431 rSet.Put( SfxUInt16Item( nWhich, pImp->nCurViewId ) );
2432 break;
2435 case SID_VIEWSHELL0:
2436 case SID_VIEWSHELL1:
2437 case SID_VIEWSHELL2:
2438 case SID_VIEWSHELL3:
2439 case SID_VIEWSHELL4:
2441 sal_uInt16 nViewNo = nWhich - SID_VIEWSHELL0;
2442 if ( GetObjectShell()->GetFactory().GetViewFactoryCount() >
2443 nViewNo && !GetObjectShell()->IsInPlaceActive() )
2445 SfxViewFactory &rViewFactory =
2446 GetObjectShell()->GetFactory().GetViewFactory(nViewNo);
2447 rSet.Put( SfxBoolItem(
2448 nWhich, pImp->nCurViewId == rViewFactory.GetOrdinal() ) );
2450 else
2451 rSet.DisableItem( nWhich );
2452 break;
2455 case SID_NEWWINDOW:
2457 if ( !GetViewShell()->NewWindowAllowed()
2458 || impl_maxOpenDocCountReached()
2460 rSet.DisableItem( nWhich );
2461 break;
2468 //-------------------------------------------------------------------------
2469 void SfxViewFrame::ToTop()
2471 GetFrame().Appear();
2474 //-------------------------------------------------------------------------
2475 SfxViewFrame* SfxViewFrame::GetParentViewFrame() const
2476 /* [Description]
2478 The ParentViewFrame is the ViewFrame of the ParentFrames.
2481 SfxFrame *pFrame = GetFrame().GetParentFrame();
2482 return pFrame ? pFrame->GetCurrentViewFrame() : NULL;
2485 //-------------------------------------------------------------------------
2486 SfxFrame& SfxViewFrame::GetFrame() const
2487 /* [Description]
2489 GetFrame returns the Frame, in which the ViewFrame is located.
2492 return pImp->rFrame;
2495 //-------------------------------------------------------------------------
2496 SfxViewFrame* SfxViewFrame::GetTopViewFrame() const
2498 return GetFrame().GetTopFrame().GetCurrentViewFrame();
2501 Window& SfxViewFrame::GetWindow() const
2503 return pImp->pWindow ? *pImp->pWindow : GetFrame().GetWindow();
2506 sal_Bool SfxViewFrame::DoClose()
2508 return GetFrame().DoClose();
2511 String SfxViewFrame::GetActualPresentationURL_Impl() const
2513 if ( xObjSh.Is() )
2514 return xObjSh->GetMedium()->GetName();
2515 return String();
2518 void SfxViewFrame::SetModalMode( sal_Bool bModal )
2520 pImp->bModal = bModal;
2521 if ( xObjSh.Is() )
2523 for ( SfxViewFrame* pFrame = SfxViewFrame::GetFirst( xObjSh );
2524 !bModal && pFrame; pFrame = SfxViewFrame::GetNext( *pFrame, xObjSh ) )
2525 bModal = pFrame->pImp->bModal;
2526 xObjSh->SetModalMode_Impl( bModal );
2530 sal_Bool SfxViewFrame::IsInModalMode() const
2532 return pImp->bModal || GetFrame().GetWindow().IsInModalMode();
2535 void SfxViewFrame::Resize( sal_Bool bForce )
2537 Size aSize = GetWindow().GetOutputSizePixel();
2538 if ( bForce || aSize != pImp->aSize )
2540 pImp->aSize = aSize;
2541 SfxViewShell *pShell = GetViewShell();
2542 if ( pShell )
2544 if ( GetFrame().IsInPlace() )
2546 Point aPoint = GetWindow().GetPosPixel();
2547 DoAdjustPosSizePixel( pShell, aPoint, aSize );
2549 else
2551 DoAdjustPosSizePixel( pShell, Point(), aSize );
2557 #define LINE_SEP 0x0A
2559 void CutLines( OUString& rStr, sal_Int32 nStartLine, sal_Int32 nLines, sal_Bool bEraseTrailingEmptyLines )
2561 sal_Int32 nStartPos = 0;
2562 sal_Int32 nLine = 0;
2563 while ( nLine < nStartLine )
2565 nStartPos = rStr.indexOf( LINE_SEP, nStartPos );
2566 if( nStartPos == -1 )
2567 break;
2568 nStartPos++; // not the \n.
2569 nLine++;
2572 DBG_ASSERTWARNING( nStartPos != STRING_NOTFOUND, "CutLines: Start row not found!" );
2574 if ( nStartPos != -1 )
2576 sal_Int32 nEndPos = nStartPos;
2577 for ( sal_Int32 i = 0; i < nLines; i++ )
2578 nEndPos = rStr.indexOf( LINE_SEP, nEndPos+1 );
2580 if ( nEndPos == -1 ) // Can happen at the last row.
2581 nEndPos = rStr.getLength();
2582 else
2583 nEndPos++;
2585 OUString aEndStr = rStr.copy( nEndPos );
2586 rStr = rStr.copy( 0, nStartPos );
2587 rStr += aEndStr;
2589 if ( bEraseTrailingEmptyLines )
2591 sal_Int32 n = nStartPos;
2592 sal_Int32 nLen = rStr.getLength();
2593 while ( ( n < nLen ) && ( rStr.getStr()[ n ] == LINE_SEP ) )
2594 n++;
2596 if ( n > nStartPos )
2598 OUString aEndStr = rStr.copy( n );
2599 rStr = rStr.copy( 0, nStartPos );
2600 rStr += aEndStr;
2606 add new recorded dispatch macro script into the application global basic
2607 lib container. It generates a new unique id for it and insert the macro
2608 by using this number as name for the modul
2610 void SfxViewFrame::AddDispatchMacroToBasic_Impl( const OUString& sMacro )
2612 #ifdef DISABLE_SCRIPTING
2613 (void) sMacro;
2614 #else
2615 if ( sMacro.isEmpty() )
2616 return;
2618 SfxApplication* pSfxApp = SFX_APP();
2619 SfxRequest aReq( SID_BASICCHOOSER, SFX_CALLMODE_SYNCHRON, pSfxApp->GetPool() );
2620 aReq.AppendItem( SfxBoolItem(SID_RECORDMACRO,sal_True) );
2621 const SfxPoolItem* pRet = SFX_APP()->ExecuteSlot( aReq );
2622 String aScriptURL;
2623 if ( pRet )
2624 aScriptURL = ((SfxStringItem*)pRet)->GetValue();
2625 if ( aScriptURL.Len() )
2627 // parse scriptURL
2628 String aLibName;
2629 String aModuleName;
2630 String aMacroName;
2631 String aLocation;
2632 Reference< XComponentContext > xContext = ::comphelper::getProcessComponentContext();
2633 Reference< com::sun::star::uri::XUriReferenceFactory > xFactory =
2634 com::sun::star::uri::UriReferenceFactory::create( xContext );
2635 Reference< com::sun::star::uri::XVndSunStarScriptUrl > xUrl( xFactory->parse( aScriptURL ), UNO_QUERY );
2636 if ( xUrl.is() )
2638 // get name
2639 OUString aName = xUrl->getName();
2640 sal_Unicode cTok = '.';
2641 sal_Int32 nIndex = 0;
2642 aLibName = aName.getToken( 0, cTok, nIndex );
2643 if ( nIndex != -1 )
2644 aModuleName = aName.getToken( 0, cTok, nIndex );
2645 if ( nIndex != -1 )
2646 aMacroName = aName.getToken( 0, cTok, nIndex );
2648 // get location
2649 OUString aLocKey("location");
2650 if ( xUrl->hasParameter( aLocKey ) )
2651 aLocation = xUrl->getParameter( aLocKey );
2654 BasicManager* pBasMgr = 0;
2655 if ( aLocation.EqualsIgnoreCaseAscii( "application" ) )
2657 // application basic
2658 pBasMgr = pSfxApp->GetBasicManager();
2660 else if ( aLocation.EqualsIgnoreCaseAscii( "document" ) )
2662 pBasMgr = GetObjectShell()->GetBasicManager();
2665 OUString aOUSource;
2666 if ( pBasMgr)
2668 StarBASIC* pBasic = pBasMgr->GetLib( aLibName );
2669 if ( pBasic )
2671 SbModule* pModule = pBasic->FindModule( aModuleName );
2672 if ( pModule )
2674 SbMethod* pMethod = (SbMethod*)pModule->GetMethods()->Find( aMacroName, SbxCLASS_METHOD );
2675 aOUSource = pModule->GetSource32();
2676 sal_uInt16 nStart, nEnd;
2677 pMethod->GetLineRange( nStart, nEnd );
2678 sal_uIntPtr nlStart = nStart;
2679 sal_uIntPtr nlEnd = nEnd;
2680 CutLines( aOUSource, nlStart-1, nlEnd-nlStart+1, sal_True );
2685 // open lib container and break operation if it couldn't be opened
2686 com::sun::star::uno::Reference< com::sun::star::script::XLibraryContainer > xLibCont;
2687 if ( aLocation.EqualsIgnoreCaseAscii( "application" ) )
2689 xLibCont = SFX_APP()->GetBasicContainer();
2691 else if ( aLocation.EqualsIgnoreCaseAscii( "document" ) )
2693 xLibCont = GetObjectShell()->GetBasicContainer();
2696 if(!xLibCont.is())
2698 SAL_WARN( "sfx2.view", "couldn't get access to the basic lib container. Adding of macro isn't possible." );
2699 return;
2702 // get LibraryContainer
2703 com::sun::star::uno::Any aTemp;
2704 com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > xRoot(
2705 xLibCont,
2706 com::sun::star::uno::UNO_QUERY);
2708 OUString sLib( aLibName );
2709 com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > xLib;
2710 if(xRoot->hasByName(sLib))
2712 // library must be loaded
2713 aTemp = xRoot->getByName(sLib);
2714 xLibCont->loadLibrary(sLib);
2715 aTemp >>= xLib;
2717 else
2719 xLib = com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >(
2720 xLibCont->createLibrary(sLib),
2721 com::sun::star::uno::UNO_QUERY);
2724 // pack the macro as direct usable "sub" routine
2725 OUString sCode;
2726 OUStringBuffer sRoutine(10000);
2727 OUString sMacroName( aMacroName );
2728 sal_Bool bReplace = sal_False;
2730 // get module
2731 OUString sModule( aModuleName );
2732 if(xLib->hasByName(sModule))
2734 if ( !aOUSource.isEmpty() )
2736 sRoutine.append( aOUSource );
2738 else
2740 aTemp = xLib->getByName(sModule);
2741 aTemp >>= sCode;
2742 sRoutine.append( sCode );
2745 bReplace = sal_True;
2748 // append new method
2749 sRoutine.appendAscii(RTL_CONSTASCII_STRINGPARAM("\nsub "));
2750 sRoutine.append(sMacroName);
2751 sRoutine.appendAscii(RTL_CONSTASCII_STRINGPARAM("\n"));
2752 sRoutine.append(sMacro);
2753 sRoutine.appendAscii(RTL_CONSTASCII_STRINGPARAM("\nend sub\n"));
2755 // create the modul inside the library and insert the macro routine
2756 aTemp <<= sRoutine.makeStringAndClear();
2757 if ( bReplace )
2759 com::sun::star::uno::Reference< com::sun::star::container::XNameContainer > xModulCont(
2760 xLib,
2761 com::sun::star::uno::UNO_QUERY);
2762 xModulCont->replaceByName(sModule,aTemp);
2764 else
2766 com::sun::star::uno::Reference< com::sun::star::container::XNameContainer > xModulCont(
2767 xLib,
2768 com::sun::star::uno::UNO_QUERY);
2769 xModulCont->insertByName(sModule,aTemp);
2772 // #i17355# update the Basic IDE
2773 for ( SfxViewShell* pViewShell = SfxViewShell::GetFirst(); pViewShell; pViewShell = SfxViewShell::GetNext( *pViewShell ) )
2775 if ( pViewShell->GetName().EqualsAscii( "BasicIDE" ) )
2777 SfxViewFrame* pViewFrame = pViewShell->GetViewFrame();
2778 SfxDispatcher* pDispat = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
2779 if ( pDispat )
2781 SfxMacroInfoItem aInfoItem( SID_BASICIDE_ARG_MACROINFO, pBasMgr, aLibName, aModuleName, String(), String() );
2782 pDispat->Execute( SID_BASICIDE_UPDATEMODULESOURCE, SFX_CALLMODE_SYNCHRON, &aInfoItem, 0L );
2787 else
2789 // add code for "session only" macro
2791 #endif
2794 void SfxViewFrame::MiscExec_Impl( SfxRequest& rReq )
2796 switch ( rReq.GetSlot() )
2798 case SID_STOP_RECORDING :
2799 case SID_RECORDMACRO :
2801 // try to find any active recorder on this frame
2802 OUString sProperty("DispatchRecorderSupplier");
2803 com::sun::star::uno::Reference< com::sun::star::frame::XFrame > xFrame(
2804 GetFrame().GetFrameInterface(),
2805 com::sun::star::uno::UNO_QUERY);
2807 com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xSet(xFrame,com::sun::star::uno::UNO_QUERY);
2808 com::sun::star::uno::Any aProp = xSet->getPropertyValue(sProperty);
2809 com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorderSupplier > xSupplier;
2810 aProp >>= xSupplier;
2811 com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder > xRecorder;
2812 if (xSupplier.is())
2813 xRecorder = xSupplier->getDispatchRecorder();
2815 sal_Bool bIsRecording = xRecorder.is();
2816 SFX_REQUEST_ARG( rReq, pItem, SfxBoolItem, SID_RECORDMACRO, sal_False);
2817 if ( pItem && pItem->GetValue() == bIsRecording )
2818 return;
2820 if ( xRecorder.is() )
2822 // disable active recording
2823 aProp <<= com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorderSupplier >();
2824 xSet->setPropertyValue(sProperty,aProp);
2826 SFX_REQUEST_ARG( rReq, pRecordItem, SfxBoolItem, FN_PARAM_1, sal_False);
2827 if ( !pRecordItem || !pRecordItem->GetValue() )
2828 // insert script into basic library container of application
2829 AddDispatchMacroToBasic_Impl(xRecorder->getRecordedMacro());
2831 xRecorder->endRecording();
2832 xRecorder = NULL;
2833 GetBindings().SetRecorder_Impl( xRecorder );
2835 SetChildWindow( SID_RECORDING_FLOATWINDOW, sal_False );
2836 if ( rReq.GetSlot() != SID_RECORDMACRO )
2837 GetBindings().Invalidate( SID_RECORDMACRO );
2839 else if ( rReq.GetSlot() == SID_RECORDMACRO )
2841 // enable recording
2842 com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > xContext(
2843 ::comphelper::getProcessComponentContext());
2845 xRecorder = com::sun::star::frame::DispatchRecorder::create( xContext );
2847 xSupplier = com::sun::star::frame::DispatchRecorderSupplier::create( xContext );
2849 xSupplier->setDispatchRecorder(xRecorder);
2850 xRecorder->startRecording(xFrame);
2851 aProp <<= xSupplier;
2852 xSet->setPropertyValue(sProperty,aProp);
2853 GetBindings().SetRecorder_Impl( xRecorder );
2854 SetChildWindow( SID_RECORDING_FLOATWINDOW, sal_True );
2857 rReq.Done();
2858 break;
2861 case SID_TOGGLESTATUSBAR:
2863 com::sun::star::uno::Reference< com::sun::star::frame::XFrame > xFrame(
2864 GetFrame().GetFrameInterface(),
2865 com::sun::star::uno::UNO_QUERY);
2867 Reference< com::sun::star::beans::XPropertySet > xPropSet( xFrame, UNO_QUERY );
2868 Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
2869 if ( xPropSet.is() )
2873 Any aValue = xPropSet->getPropertyValue( OUString( "LayoutManager" ));
2874 aValue >>= xLayoutManager;
2876 catch ( Exception& )
2881 if ( xLayoutManager.is() )
2883 OUString aStatusbarResString( "private:resource/statusbar/statusbar" );
2884 // Evaluate parameter.
2885 SFX_REQUEST_ARG(rReq, pShowItem, SfxBoolItem, rReq.GetSlot(), sal_False);
2886 sal_Bool bShow( sal_True );
2887 if ( !pShowItem )
2888 bShow = xLayoutManager->isElementVisible( aStatusbarResString );
2889 else
2890 bShow = pShowItem->GetValue();
2892 if ( bShow )
2894 xLayoutManager->createElement( aStatusbarResString );
2895 xLayoutManager->showElement( aStatusbarResString );
2897 else
2898 xLayoutManager->hideElement( aStatusbarResString );
2900 if ( !pShowItem )
2901 rReq.AppendItem( SfxBoolItem( SID_TOGGLESTATUSBAR, bShow ) );
2903 rReq.Done();
2904 break;
2907 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2908 case SID_WIN_FULLSCREEN:
2910 SFX_REQUEST_ARG(rReq, pItem, SfxBoolItem, rReq.GetSlot(), sal_False);
2911 SfxViewFrame *pTop = GetTopViewFrame();
2912 if ( pTop )
2914 WorkWindow* pWork = (WorkWindow*) pTop->GetFrame().GetTopWindow_Impl();
2915 if ( pWork )
2917 com::sun::star::uno::Reference< com::sun::star::frame::XFrame > xFrame(
2918 GetFrame().GetFrameInterface(),
2919 com::sun::star::uno::UNO_QUERY);
2921 Reference< ::com::sun::star::beans::XPropertySet > xPropSet( xFrame, UNO_QUERY );
2922 Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
2923 if ( xPropSet.is() )
2927 Any aValue = xPropSet->getPropertyValue( OUString( "LayoutManager" ));
2928 aValue >>= xLayoutManager;
2930 catch ( Exception& )
2935 sal_Bool bNewFullScreenMode = pItem ? pItem->GetValue() : !pWork->IsFullScreenMode();
2936 if ( bNewFullScreenMode != pWork->IsFullScreenMode() )
2938 Reference< ::com::sun::star::beans::XPropertySet > xLMPropSet( xLayoutManager, UNO_QUERY );
2939 if ( xLMPropSet.is() )
2943 xLMPropSet->setPropertyValue(
2944 OUString( "HideCurrentUI" ),
2945 makeAny( bNewFullScreenMode ));
2947 catch ( ::com::sun::star::beans::UnknownPropertyException& )
2951 pWork->ShowFullScreenMode( bNewFullScreenMode );
2952 pWork->SetMenuBarMode( bNewFullScreenMode ? MENUBAR_MODE_HIDE : MENUBAR_MODE_NORMAL );
2953 GetFrame().GetWorkWindow_Impl()->SetFullScreen_Impl( bNewFullScreenMode );
2954 if ( !pItem )
2955 rReq.AppendItem( SfxBoolItem( SID_WIN_FULLSCREEN, bNewFullScreenMode ) );
2956 rReq.Done();
2958 else
2959 rReq.Ignore();
2962 else
2963 rReq.Ignore();
2965 GetDispatcher()->Update_Impl( sal_True );
2966 break;
2971 void SfxViewFrame::MiscState_Impl(SfxItemSet &rSet)
2973 const sal_uInt16 *pRanges = rSet.GetRanges();
2974 DBG_ASSERT(pRanges && *pRanges, "Set without range");
2975 while ( *pRanges )
2977 for(sal_uInt16 nWhich = *pRanges++; nWhich <= *pRanges; ++nWhich)
2979 switch(nWhich)
2981 case SID_CURRENT_URL:
2983 // Get the ContainerFrame, when internal InPlace.
2984 SfxViewFrame *pFrame = this;
2985 if ( pFrame->GetParentViewFrame_Impl() )
2986 pFrame = pFrame->GetParentViewFrame_Impl();
2987 rSet.Put( SfxStringItem( nWhich, pFrame->GetActualPresentationURL_Impl() ) );
2988 break;
2991 case SID_RECORDMACRO :
2993 SvtMiscOptions aMiscOptions;
2994 const char* pName = GetObjectShell()->GetFactory().GetShortName();
2995 if ( !aMiscOptions.IsMacroRecorderMode() ||
2996 ( strcmp(pName,"swriter") && strcmp(pName,"scalc") ) )
2998 rSet.DisableItem( nWhich );
2999 rSet.Put(SfxVisibilityItem(nWhich, sal_False));
3000 break;
3003 OUString sProperty("DispatchRecorderSupplier");
3004 com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xSet(
3005 GetFrame().GetFrameInterface(),
3006 com::sun::star::uno::UNO_QUERY);
3008 com::sun::star::uno::Any aProp = xSet->getPropertyValue(sProperty);
3009 com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorderSupplier > xSupplier;
3010 if ( aProp >>= xSupplier )
3011 rSet.Put( SfxBoolItem( nWhich, xSupplier.is() ) );
3012 else
3013 rSet.DisableItem( nWhich );
3014 break;
3017 case SID_STOP_RECORDING :
3019 SvtMiscOptions aMiscOptions;
3020 const char* pName = GetObjectShell()->GetFactory().GetShortName();
3021 if ( !aMiscOptions.IsMacroRecorderMode() ||
3022 ( strcmp(pName,"swriter") && strcmp(pName,"scalc") ) )
3024 rSet.DisableItem( nWhich );
3025 break;
3028 OUString sProperty("DispatchRecorderSupplier");
3029 com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xSet(
3030 GetFrame().GetFrameInterface(),
3031 com::sun::star::uno::UNO_QUERY);
3033 com::sun::star::uno::Any aProp = xSet->getPropertyValue(sProperty);
3034 com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorderSupplier > xSupplier;
3035 if ( !(aProp >>= xSupplier) || !xSupplier.is() )
3036 rSet.DisableItem( nWhich );
3037 break;
3040 case SID_TOGGLESTATUSBAR:
3042 com::sun::star::uno::Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
3043 com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xSet(
3044 GetFrame().GetFrameInterface(),
3045 com::sun::star::uno::UNO_QUERY);
3046 com::sun::star::uno::Any aProp = xSet->getPropertyValue(
3047 OUString( "LayoutManager" ) );
3049 if ( !( aProp >>= xLayoutManager ))
3050 rSet.Put( SfxBoolItem( nWhich, sal_False ));
3051 else
3053 OUString aStatusbarResString( "private:resource/statusbar/statusbar" );
3054 sal_Bool bShow = xLayoutManager->isElementVisible( aStatusbarResString );
3055 rSet.Put( SfxBoolItem( nWhich, bShow ));
3057 break;
3060 case SID_WIN_FULLSCREEN:
3062 SfxViewFrame* pTop = GetTopViewFrame();
3063 if ( pTop )
3065 WorkWindow* pWork = (WorkWindow*) pTop->GetFrame().GetTopWindow_Impl();
3066 if ( pWork )
3068 rSet.Put( SfxBoolItem( nWhich, pWork->IsFullScreenMode() ) );
3069 break;
3073 rSet.DisableItem( nWhich );
3074 break;
3077 case SID_FORMATMENUSTATE :
3079 OSL_FAIL("Outdated slot!");
3080 rSet.DisableItem( nWhich );
3081 break;
3084 default:
3085 break;
3089 ++pRanges;
3093 void SfxViewFrame::ChildWindowExecute( SfxRequest &rReq )
3095 /* [Description]
3097 This method can be included in the Execute method for the on- and off-
3098 switching of ChildWindows, to implement this and API-bindings.
3100 Simply include as 'ExecuteMethod' in the IDL.
3104 // Evaluate Parameter
3105 sal_uInt16 nSID = rReq.GetSlot();
3107 SFX_REQUEST_ARG(rReq, pShowItem, SfxBoolItem, nSID, sal_False);
3108 if ( nSID == SID_VIEW_DATA_SOURCE_BROWSER )
3110 if (!SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SDATABASE))
3111 return;
3112 Reference < XFrame > xFrame = GetFrame().GetTopFrame().GetFrameInterface();
3113 Reference < XFrame > xBeamer( xFrame->findFrame( "_beamer", FrameSearchFlag::CHILDREN ) );
3114 sal_Bool bShow = sal_False;
3115 sal_Bool bHasChild = xBeamer.is();
3116 bShow = pShowItem ? pShowItem->GetValue() : !bHasChild;
3117 if ( pShowItem )
3119 if( bShow == bHasChild )
3120 return;
3122 else
3123 rReq.AppendItem( SfxBoolItem( nSID, bShow ) );
3125 if ( !bShow )
3127 SetChildWindow( SID_BROWSER, sal_False );
3129 else
3131 ::com::sun::star::util::URL aTargetURL;
3132 aTargetURL.Complete = OUString(".component:DB/DataSourceBrowser");
3133 Reference < ::com::sun::star::util::XURLTransformer > xTrans(
3134 ::com::sun::star::util::URLTransformer::create(
3135 ::comphelper::getProcessComponentContext() ) );
3136 xTrans->parseStrict( aTargetURL );
3138 Reference < XDispatchProvider > xProv( xFrame, UNO_QUERY );
3139 Reference < ::com::sun::star::frame::XDispatch > xDisp;
3140 if ( xProv.is() )
3141 xDisp = xProv->queryDispatch( aTargetURL, OUString("_beamer"), 31 );
3142 if ( xDisp.is() )
3144 Sequence < ::com::sun::star::beans::PropertyValue > aArgs(1);
3145 ::com::sun::star::beans::PropertyValue* pArg = aArgs.getArray();
3146 pArg[0].Name = OUString("Referer");
3147 pArg[0].Value <<= OUString("private:user");
3148 xDisp->dispatch( aTargetURL, aArgs );
3152 rReq.Done();
3153 return;
3156 sal_Bool bShow = sal_False;
3157 sal_Bool bHasChild = HasChildWindow(nSID);
3158 bShow = pShowItem ? pShowItem->GetValue() : !bHasChild;
3160 // Perform action.
3161 if ( !pShowItem || bShow != bHasChild )
3162 ToggleChildWindow( nSID );
3164 GetBindings().Invalidate( nSID );
3165 GetDispatcher()->Update_Impl( sal_True );
3167 // Record if possible.
3168 if ( nSID == SID_HYPERLINK_DIALOG || nSID == SID_SEARCH_DLG )
3170 rReq.Ignore();
3172 else
3174 rReq.AppendItem( SfxBoolItem( nSID, bShow ) );
3175 rReq.Done();
3179 //--------------------------------------------------------------------
3181 void SfxViewFrame::ChildWindowState( SfxItemSet& rState )
3183 /* [Description]
3185 This method can be used in the state method for the on and off-state
3186 of child-windows, in order to implement this.
3188 Just register the IDL as 'StateMethod'.
3192 SfxWhichIter aIter( rState );
3193 for ( sal_uInt16 nSID = aIter.FirstWhich(); nSID; nSID = aIter.NextWhich() )
3195 if ( nSID == SID_VIEW_DATA_SOURCE_BROWSER )
3197 rState.Put( SfxBoolItem( nSID, HasChildWindow( SID_BROWSER ) ) );
3199 else if ( nSID == SID_HYPERLINK_DIALOG )
3201 const SfxPoolItem* pDummy = NULL;
3202 SfxItemState eState = GetDispatcher()->QueryState( SID_HYPERLINK_SETLINK, pDummy );
3203 if ( SFX_ITEM_DISABLED == eState )
3204 rState.DisableItem(nSID);
3205 else
3207 if ( KnowsChildWindow(nSID) )
3208 rState.Put( SfxBoolItem( nSID, HasChildWindow(nSID)) );
3209 else
3210 rState.DisableItem(nSID);
3213 else if ( nSID == SID_BROWSER )
3215 Reference < XFrame > xFrame = GetFrame().GetTopFrame().GetFrameInterface()->
3216 findFrame( "_beamer", FrameSearchFlag::CHILDREN );
3217 if ( !xFrame.is() )
3218 rState.DisableItem( nSID );
3219 else if ( KnowsChildWindow(nSID) )
3220 rState.Put( SfxBoolItem( nSID, HasChildWindow(nSID) ) );
3222 else if ( nSID == SID_TASKPANE )
3224 if ( !KnowsChildWindow( nSID ) )
3226 OSL_FAIL( "SID_TASKPANE state requested, but no task pane child window exists for this ID!" );
3227 rState.DisableItem( nSID );
3229 else if ( !moduleHasToolPanels( *pImp ) )
3231 rState.Put( SfxVisibilityItem( nSID, sal_False ) );
3233 else
3235 rState.Put( SfxBoolItem( nSID, HasChildWindow( nSID ) ) );
3238 else if ( nSID == SID_SIDEBAR )
3240 if ( !IsSidebarEnabled() )
3242 rState.DisableItem( nSID );
3243 rState.Put( SfxVisibilityItem( nSID, sal_False ) );
3245 if ( !KnowsChildWindow( nSID ) )
3247 OSL_ENSURE( false, "SID_TASKPANE state requested, but no task pane child window exists for this ID!" );
3248 rState.DisableItem( nSID );
3250 else
3252 rState.Put( SfxBoolItem( nSID, HasChildWindow( nSID ) ) );
3255 else if ( KnowsChildWindow(nSID) )
3256 rState.Put( SfxBoolItem( nSID, HasChildWindow(nSID) ) );
3257 else
3258 rState.DisableItem(nSID);
3262 //--------------------------------------------------------------------
3263 SfxWorkWindow* SfxViewFrame::GetWorkWindow_Impl( sal_uInt16 /*nId*/ )
3265 SfxWorkWindow* pWork = 0;
3266 pWork = GetFrame().GetWorkWindow_Impl();
3267 return pWork;
3270 void SfxViewFrame::SetChildWindow(sal_uInt16 nId, sal_Bool bOn, sal_Bool bSetFocus )
3272 SfxWorkWindow* pWork = GetWorkWindow_Impl( nId );
3273 if ( pWork )
3274 pWork->SetChildWindow_Impl( nId, bOn, bSetFocus );
3277 //--------------------------------------------------------------------
3279 void SfxViewFrame::ToggleChildWindow(sal_uInt16 nId)
3281 SfxWorkWindow* pWork = GetWorkWindow_Impl( nId );
3282 if ( pWork )
3283 pWork->ToggleChildWindow_Impl( nId, sal_True );
3286 //--------------------------------------------------------------------
3288 sal_Bool SfxViewFrame::HasChildWindow( sal_uInt16 nId )
3290 SfxWorkWindow* pWork = GetWorkWindow_Impl( nId );
3291 return pWork ? pWork->HasChildWindow_Impl(nId) : sal_False;
3294 //--------------------------------------------------------------------
3296 sal_Bool SfxViewFrame::KnowsChildWindow( sal_uInt16 nId )
3298 SfxWorkWindow* pWork = GetWorkWindow_Impl( nId );
3299 return pWork ? pWork->KnowsChildWindow_Impl(nId) : sal_False;
3302 //--------------------------------------------------------------------
3304 void SfxViewFrame::ShowChildWindow( sal_uInt16 nId, sal_Bool bVisible )
3306 SfxWorkWindow* pWork = GetWorkWindow_Impl( nId );
3307 if ( pWork )
3309 GetDispatcher()->Update_Impl(sal_True);
3310 pWork->ShowChildWindow_Impl(nId, bVisible, sal_True );
3314 //--------------------------------------------------------------------
3316 SfxChildWindow* SfxViewFrame::GetChildWindow(sal_uInt16 nId)
3318 SfxWorkWindow* pWork = GetWorkWindow_Impl( nId );
3319 return pWork ? pWork->GetChildWindow_Impl(nId) : NULL;
3322 void SfxViewFrame::UpdateDocument_Impl()
3324 SfxObjectShell* pDoc = GetObjectShell();
3325 if ( pDoc->IsLoadingFinished() )
3326 pDoc->CheckSecurityOnLoading_Impl();
3328 // check if document depends on a template
3329 pDoc->UpdateFromTemplate_Impl();
3332 void SfxViewFrame::SetViewFrame( SfxViewFrame* pFrame )
3334 SFX_APP()->SetViewFrame_Impl( pFrame );
3337 // ---------------------------------------------------------------------------------------------------------------------
3338 void SfxViewFrame::ActivateToolPanel( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& i_rFrame, const OUString& i_rPanelURL )
3340 SolarMutexGuard aGuard;
3342 // look up the SfxFrame for the given XFrame
3343 SfxFrame* pFrame = NULL;
3344 for ( pFrame = SfxFrame::GetFirst(); pFrame; pFrame = SfxFrame::GetNext( *pFrame ) )
3346 if ( pFrame->GetFrameInterface() == i_rFrame )
3347 break;
3349 SfxViewFrame* pViewFrame = pFrame ? pFrame->GetCurrentViewFrame() : NULL;
3350 ENSURE_OR_RETURN_VOID( pViewFrame != NULL, "SfxViewFrame::ActivateToolPanel: did not find an SfxFrame for the given XFrame!" );
3352 pViewFrame->ActivateToolPanel_Impl( i_rPanelURL );
3355 // ---------------------------------------------------------------------------------------------------------------------
3356 void SfxViewFrame::ActivateToolPanel_Impl( const OUString& i_rPanelURL )
3358 // ensure the task pane is visible
3359 ENSURE_OR_RETURN_VOID( KnowsChildWindow( SID_TASKPANE ), "SfxViewFrame::ActivateToolPanel: this frame/module does not allow for a task pane!" );
3360 if ( !HasChildWindow( SID_TASKPANE ) )
3361 ToggleChildWindow( SID_TASKPANE );
3363 SfxChildWindow* pTaskPaneChildWindow = GetChildWindow( SID_TASKPANE );
3364 ENSURE_OR_RETURN_VOID( pTaskPaneChildWindow, "SfxViewFrame::ActivateToolPanel_Impl: just switched it on, but it is not there!" );
3366 ::sfx2::ITaskPaneToolPanelAccess* pPanelAccess = dynamic_cast< ::sfx2::ITaskPaneToolPanelAccess* >( pTaskPaneChildWindow );
3367 ENSURE_OR_RETURN_VOID( pPanelAccess, "SfxViewFrame::ActivateToolPanel_Impl: task pane child window does not implement a required interface!" );
3368 pPanelAccess->ActivateToolPanel( i_rPanelURL );
3371 void SfxViewFrame::AppendInfoBar( const OUString& sId, const OUString& sMessage, std::vector< PushButton* > aButtons )
3373 const sal_uInt16 nId = SfxInfoBarContainerChild::GetChildWindowId();
3375 // Make sure the InfoBar container is visible
3376 if ( !HasChildWindow( nId ) )
3377 ToggleChildWindow( nId );
3378 SfxChildWindow* pChild = GetChildWindow( nId );
3379 if ( pChild )
3381 SfxInfoBarContainerWindow* pInfoBars = ( SfxInfoBarContainerWindow* )pChild->GetWindow();
3382 pInfoBars->appendInfoBar( sId, sMessage, aButtons );
3383 ShowChildWindow( nId );
3387 void SfxViewFrame::RemoveInfoBar( const OUString& sId )
3389 const sal_uInt16 nId = SfxInfoBarContainerChild::GetChildWindowId();
3391 // Make sure the InfoBar container is visible
3392 if ( !HasChildWindow( nId ) )
3393 ToggleChildWindow( nId );
3394 SfxChildWindow* pChild = GetChildWindow( nId );
3395 if ( pChild )
3397 SfxInfoBarContainerWindow* pInfoBars = ( SfxInfoBarContainerWindow* )pChild->GetWindow();
3398 SfxInfoBarWindow* pInfoBar = pInfoBars->getInfoBar( sId );
3399 pInfoBars->removeInfoBar( pInfoBar );
3400 ShowChildWindow( nId );
3404 bool SfxViewFrame::IsSidebarEnabled()
3406 static bool bInitialized = false;
3407 static bool bEnabled = false;
3409 // read the setting once at start, and that's what we
3410 // stick with for now.
3411 if (!bInitialized)
3413 bInitialized = true;
3414 css::uno::Reference< css::uno::XComponentContext > xContext;
3415 xContext = ::comphelper::getProcessComponentContext();
3416 try {
3417 bEnabled = officecfg::Office::Common::Misc::ExperimentalSidebar::get( xContext );
3418 } catch (const uno::Exception &) {
3419 SAL_WARN("sfx2.view", "don't have experimental sidebar option installed");
3422 // rip out the services from framework/ for good measure
3423 if( !bEnabled )
3427 uno::Reference< ui::XUIElementFactoryManager > xUIElementFactory = ui::UIElementFactoryManager::create( xContext );
3428 xUIElementFactory->deregisterFactory( "toolpanel", "ScPanelFactory", "" );
3429 xUIElementFactory->deregisterFactory( "toolpanel", "SwPanelFactory", "" );
3430 xUIElementFactory->deregisterFactory( "toolpanel", "SvxPanelFactory", "" );
3431 xUIElementFactory->deregisterFactory( "toolpanel", "SdPanelFactory", "" );
3433 catch ( const uno::Exception &e )
3435 SAL_WARN( "sfx2.view", "Exception de-registering sidebar factories " << e.Message );
3440 return bEnabled;
3443 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */