bump product version to 5.0.4.1
[LibreOffice.git] / sfx2 / source / view / viewfrm.cxx
blobfc8dbae2d294ab08ade841b36add919d82c12795
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 <sfx2/infobar.hxx>
23 #include <sfx2/viewfrm.hxx>
24 #include <com/sun/star/document/MacroExecMode.hpp>
25 #include <com/sun/star/frame/Desktop.hpp>
26 #include <com/sun/star/frame/DispatchRecorder.hpp>
27 #include <com/sun/star/frame/DispatchRecorderSupplier.hpp>
28 #include <com/sun/star/frame/XLoadable.hpp>
29 #include <com/sun/star/frame/XLayoutManager.hpp>
30 #include <com/sun/star/frame/XComponentLoader.hpp>
31 #include <officecfg/Office/Common.hxx>
32 #include <toolkit/helper/vclunohelper.hxx>
33 #include <vcl/splitwin.hxx>
34 #include <unotools/moduleoptions.hxx>
35 #include <svl/intitem.hxx>
36 #include <svl/visitem.hxx>
37 #include <svl/stritem.hxx>
38 #include <svl/eitem.hxx>
39 #include <svl/slstitm.hxx>
40 #include <svl/whiter.hxx>
41 #include <svl/undo.hxx>
42 #include <vcl/layout.hxx>
43 #include <svtools/sfxecode.hxx>
44 #include <svtools/miscopt.hxx>
45 #include <svtools/ehdl.hxx>
46 #include <tools/diagnose_ex.h>
47 #include <com/sun/star/container/XIndexAccess.hpp>
48 #include <com/sun/star/frame/XFramesSupplier.hpp>
49 #include <com/sun/star/frame/FrameSearchFlag.hpp>
50 #include <com/sun/star/frame/XFrame.hpp>
51 #include <com/sun/star/frame/XFrames.hpp>
52 #include <com/sun/star/awt/XWindow.hpp>
53 #include <com/sun/star/frame/XController.hpp>
54 #include <com/sun/star/frame/XModel2.hpp>
55 #include <com/sun/star/util/URLTransformer.hpp>
56 #include <com/sun/star/util/XURLTransformer.hpp>
57 #include <com/sun/star/util/XCloseable.hpp>
58 #include <com/sun/star/frame/XDispatchRecorderSupplier.hpp>
59 #include <com/sun/star/document/UpdateDocMode.hpp>
60 #include <com/sun/star/beans/XPropertySet.hpp>
61 #include <com/sun/star/uri/UriReferenceFactory.hpp>
62 #include <com/sun/star/uri/XVndSunStarScriptUrl.hpp>
63 #include <com/sun/star/embed/XStorage.hpp>
64 #include <com/sun/star/embed/EmbedStates.hpp>
65 #include <com/sun/star/document/XViewDataSupplier.hpp>
66 #include <com/sun/star/container/XIndexContainer.hpp>
67 #include <com/sun/star/task/InteractionHandler.hpp>
68 #include <rtl/ustrbuf.hxx>
70 #include <unotools/localfilehelper.hxx>
71 #include <unotools/ucbhelper.hxx>
72 #include <comphelper/processfactory.hxx>
73 #include <comphelper/namedvaluecollection.hxx>
74 #include <comphelper/docpasswordrequest.hxx>
75 #include <comphelper/docpasswordhelper.hxx>
77 #include <com/sun/star/uno/Reference.h>
78 #include <com/sun/star/ucb/XContent.hpp>
80 #include <basic/basmgr.hxx>
81 #include <basic/sbmod.hxx>
82 #include <basic/sbmeth.hxx>
83 #include <basic/sbx.hxx>
84 #include <comphelper/storagehelper.hxx>
85 #include <svtools/asynclink.hxx>
86 #include <svl/sharecontrolfile.hxx>
87 #include <svtools/svtools.hrc>
88 #include <svtools/svtresid.hxx>
89 #include <framework/framelistanalyzer.hxx>
90 #include <shellimpl.hxx>
92 #include <boost/optional.hpp>
94 using namespace ::com::sun::star;
95 using namespace ::com::sun::star::uno;
96 using namespace ::com::sun::star::ucb;
97 using namespace ::com::sun::star::frame;
98 using namespace ::com::sun::star::lang;
99 using ::com::sun::star::awt::XWindow;
100 using ::com::sun::star::beans::PropertyValue;
101 using ::com::sun::star::document::XViewDataSupplier;
102 using ::com::sun::star::container::XIndexContainer;
104 // Due to ViewFrame::Current
105 #include "appdata.hxx"
106 #include <sfx2/taskpane.hxx>
107 #include <sfx2/app.hxx>
108 #include <sfx2/objface.hxx>
109 #include "openflag.hxx"
110 #include "objshimp.hxx"
111 #include <sfx2/viewsh.hxx>
112 #include <sfx2/objsh.hxx>
113 #include <sfx2/bindings.hxx>
114 #include <sfx2/dispatch.hxx>
115 #include "arrdecl.hxx"
116 #include "sfxtypes.hxx"
117 #include <sfx2/request.hxx>
118 #include <sfx2/docfac.hxx>
119 #include <sfx2/ipclient.hxx>
120 #include <sfx2/sfxresid.hxx>
121 #include <sfx2/objitem.hxx>
122 #include <sfx2/viewfac.hxx>
123 #include <sfx2/event.hxx>
124 #include <sfx2/fcontnr.hxx>
125 #include <sfx2/docfile.hxx>
126 #include <sfx2/module.hxx>
127 #include <sfx2/msgpool.hxx>
128 #include "viewimp.hxx"
129 #include <sfx2/sfxbasecontroller.hxx>
130 #include <sfx2/sfx.hrc>
131 #include "view.hrc"
132 #include <sfx2/frmdescr.hxx>
133 #include <sfx2/sfxuno.hxx>
134 #include <sfx2/progress.hxx>
135 #include <sfx2/sidebar/Sidebar.hxx>
136 #include "workwin.hxx"
137 #include "helper.hxx"
138 #include <sfx2/minfitem.hxx>
139 #include "../appl/app.hrc"
140 #include "impviewframe.hxx"
142 #define SfxViewFrame
143 #include "sfxslots.hxx"
144 #undef SfxViewFrame
146 SFX_IMPL_SUPERCLASS_INTERFACE(SfxViewFrame,SfxShell)
148 void SfxViewFrame::InitInterface_Impl()
150 GetStaticInterface()->RegisterChildWindow(SID_BROWSER);
151 GetStaticInterface()->RegisterChildWindow(SID_RECORDING_FLOATWINDOW);
152 #if HAVE_FEATURE_DESKTOP
153 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_FULLSCREEN | SFX_VISIBILITY_FULLSCREEN, RID_FULLSCREENTOOLBOX);
154 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_APPLICATION | SFX_VISIBILITY_STANDARD, RID_ENVTOOLBOX );
155 #endif
158 TYPEINIT2(SfxViewFrame,SfxShell,SfxListener);
159 TYPEINIT1(SfxViewFrameItem, SfxPoolItem);
161 namespace
163 bool moduleHasToolPanels( SfxViewFrame_Impl& i_rViewFrameImpl )
165 if ( !i_rViewFrameImpl.aHasToolPanels )
167 i_rViewFrameImpl.aHasToolPanels.reset( ::sfx2::ModuleTaskPane::ModuleHasToolPanels(
168 i_rViewFrameImpl.rFrame.GetFrameInterface() ) );
170 return *i_rViewFrameImpl.aHasToolPanels;
175 static bool AskPasswordToModify_Impl( const uno::Reference< task::XInteractionHandler >& xHandler, const OUString& aPath, const SfxFilter* pFilter, sal_uInt32 nPasswordHash, const uno::Sequence< beans::PropertyValue >& aInfo )
177 // TODO/LATER: In future the info should replace the direct hash completely
178 bool bResult = ( !nPasswordHash && !aInfo.getLength() );
180 OSL_ENSURE( pFilter && ( pFilter->GetFilterFlags() & SfxFilterFlags::PASSWORDTOMODIFY ), "PasswordToModify feature is active for a filter that does not support it!" );
182 if ( pFilter && xHandler.is() )
184 bool bCancel = false;
185 bool bFirstTime = true;
187 while ( !bResult && !bCancel )
189 bool bMSType = !pFilter->IsOwnFormat();
191 ::rtl::Reference< ::comphelper::DocPasswordRequest > pPasswordRequest(
192 new ::comphelper::DocPasswordRequest(
193 bMSType ? ::comphelper::DocPasswordRequestType_MS : ::comphelper::DocPasswordRequestType_STANDARD,
194 bFirstTime ? ::com::sun::star::task::PasswordRequestMode_PASSWORD_ENTER : ::com::sun::star::task::PasswordRequestMode_PASSWORD_REENTER,
195 aPath,
196 true ) );
198 uno::Reference< com::sun::star::task::XInteractionRequest > rRequest( pPasswordRequest.get() );
199 xHandler->handle( rRequest );
201 if ( pPasswordRequest->isPassword() )
203 if ( aInfo.getLength() )
205 bResult = ::comphelper::DocPasswordHelper::IsModifyPasswordCorrect( pPasswordRequest->getPasswordToModify(), aInfo );
207 else
209 // the binary format
210 bResult = ( SfxMedium::CreatePasswordToModifyHash( pPasswordRequest->getPasswordToModify(), OUString( "com.sun.star.text.TextDocument" ).equals( pFilter->GetServiceName() ) ) == nPasswordHash );
213 else
214 bCancel = true;
216 bFirstTime = false;
220 return bResult;
224 void SfxViewFrame::SetDowning_Impl()
226 pImp->bIsDowning = true;
230 bool SfxViewFrame::IsDowning_Impl() const
232 return pImp->bIsDowning;
237 class SfxViewNotificatedFrameList_Impl :
238 public SfxListener, public SfxViewFrameArr_Impl
240 public:
242 void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) SAL_OVERRIDE;
246 void SfxViewNotificatedFrameList_Impl::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
248 const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
249 if ( pSimpleHint )
251 switch( pSimpleHint->GetId() )
253 case SFX_HINT_DYING:
254 SfxViewFrame* pFrame = dynamic_cast<SfxViewFrame*>(&rBC);
255 if( pFrame )
257 iterator it = std::find( begin(), end(), pFrame );
258 if( it != end() )
259 erase( it );
261 break;
266 void SfxViewFrame::ExecReload_Impl( SfxRequest& rReq )
268 SfxFrame *pParent = GetFrame().GetParentFrame();
269 if ( rReq.GetSlot() == SID_RELOAD )
271 // When CTRL-Reload, reload the active Frame
272 SfxViewFrame* pActFrame = this;
273 while ( pActFrame )
274 pActFrame = pActFrame->GetActiveChildFrame_Impl();
276 if ( pActFrame )
278 sal_uInt16 nModifier = rReq.GetModifier();
279 if ( nModifier & KEY_MOD1 )
281 pActFrame->ExecReload_Impl( rReq );
282 return;
286 // If only a reload of the graphics for one or more child frames
287 // should be made
288 SfxFrame& rFrame = GetFrame();
289 if ( pParent == &rFrame && rFrame.GetChildFrameCount() )
291 bool bReloadAvailable = false;
292 SfxFrameIterator aIter( rFrame, false );
293 SfxFrame *pChild = aIter.FirstFrame();
294 while ( pChild )
296 SfxFrame *pNext = aIter.NextFrame( *pChild );
297 SfxObjectShell *pShell = pChild->GetCurrentDocument();
298 if( pShell && pShell->Get_Impl()->bReloadAvailable )
300 bReloadAvailable = true;
301 pChild->GetCurrentViewFrame()->ExecuteSlot( rReq );
303 pChild = pNext;
306 // The top level frame itself has no graphics!
307 if ( bReloadAvailable )
308 return;
311 else
313 // When CTRL-Edit, edit the TopFrame.
314 sal_uInt16 nModifier = rReq.GetModifier();
316 if ( ( nModifier & KEY_MOD1 ) && pParent )
318 SfxViewFrame *pTop = GetTopViewFrame();
319 pTop->ExecReload_Impl( rReq );
320 return;
324 SfxObjectShell* pSh = GetObjectShell();
325 switch ( rReq.GetSlot() )
327 case SID_EDITDOC:
329 // Due to Double occupancy in toolboxes (with or without Ctrl),
330 // it is also possible that the slot is enabled, but Ctrl-click
331 // despite this is not!
332 if( !pSh || !pSh->HasName() || !(pSh->Get_Impl()->nLoadedFlags & SfxLoadedFlags::MAINDOCUMENT ))
333 break;
335 SfxMedium* pMed = pSh->GetMedium();
337 SFX_ITEMSET_ARG( pSh->GetMedium()->GetItemSet(), pItem, SfxBoolItem, SID_VIEWONLY, false );
338 if ( pItem && pItem->GetValue() )
340 SfxApplication* pApp = SfxGetpApp();
341 SfxAllItemSet aSet( pApp->GetPool() );
342 aSet.Put( SfxStringItem( SID_FILE_NAME, pMed->GetURLObject().GetMainURL(INetURLObject::NO_DECODE) ) );
343 aSet.Put( SfxBoolItem( SID_TEMPLATE, true ) );
344 aSet.Put( SfxStringItem( SID_TARGETNAME, OUString("_blank") ) );
345 SFX_ITEMSET_ARG( pMed->GetItemSet(), pReferer, SfxStringItem, SID_REFERER, false );
346 if ( pReferer )
347 aSet.Put( *pReferer );
348 SFX_ITEMSET_ARG( pSh->GetMedium()->GetItemSet(), pVersionItem, SfxInt16Item, SID_VERSION, false );
349 if ( pVersionItem )
350 aSet.Put( *pVersionItem );
352 if( pMed->GetFilter() )
354 aSet.Put( SfxStringItem( SID_FILTER_NAME, pMed->GetFilter()->GetFilterName() ) );
355 SFX_ITEMSET_ARG( pMed->GetItemSet(), pOptions, SfxStringItem, SID_FILE_FILTEROPTIONS, false );
356 if ( pOptions )
357 aSet.Put( *pOptions );
360 GetDispatcher()->Execute( SID_OPENDOC, SfxCallMode::ASYNCHRON, aSet );
361 return;
364 StreamMode nOpenMode;
365 bool bNeedsReload = false;
366 if ( !pSh->IsReadOnly() )
368 // Save and reload Readonly
369 if( pSh->IsModified() )
371 if ( pSh->PrepareClose() )
373 // the storing could let the medium be changed
374 pMed = pSh->GetMedium();
375 bNeedsReload = true;
377 else
379 rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), false ) );
380 return;
383 nOpenMode = SFX_STREAM_READONLY;
384 pSh->SetReadOnlyUI(true);
386 else
388 if ( pSh->IsReadOnlyMedium()
389 && ( pSh->GetModifyPasswordHash() || pSh->GetModifyPasswordInfo().getLength() )
390 && !pSh->IsModifyPasswordEntered() )
392 OUString aDocumentName = INetURLObject( pMed->GetOrigURL() ).GetMainURL( INetURLObject::DECODE_WITH_CHARSET );
393 if( !AskPasswordToModify_Impl( pMed->GetInteractionHandler(), aDocumentName, pMed->GetOrigFilter(), pSh->GetModifyPasswordHash(), pSh->GetModifyPasswordInfo() ) )
395 // this is a read-only document, if it has "Password to modify"
396 // the user should enter password before he can edit the document
397 rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), false ) );
398 return;
401 pSh->SetModifyPasswordEntered();
404 // Remove infobar if document was read-only (after password check)
405 RemoveInfoBar("readonly");
407 nOpenMode = pSh->IsOriginallyReadOnlyMedium() ? SFX_STREAM_READONLY : SFX_STREAM_READWRITE;
409 // if only the view was in the readonly mode then there is no need to do the reload
410 if ( !pSh->IsReadOnlyMedium() )
412 // SetReadOnlyUI causes recomputation of window title, using
413 // open mode among other things, so call SetOpenMode before
414 // SetReadOnlyUI:
415 pMed->SetOpenMode( nOpenMode );
416 pSh->SetReadOnlyUI( false );
417 return;
421 pSh->SetReadOnlyUI( false );
424 if ( rReq.IsAPI() )
426 // Control through API if r/w or r/o
427 SFX_REQUEST_ARG(rReq, pEditItem, SfxBoolItem, SID_EDITDOC, false);
428 if ( pEditItem )
429 nOpenMode = pEditItem->GetValue() ? SFX_STREAM_READWRITE : SFX_STREAM_READONLY;
432 // doing
434 OUString aTemp;
435 utl::LocalFileHelper::ConvertPhysicalNameToURL( pMed->GetPhysicalName(), aTemp );
436 INetURLObject aPhysObj( aTemp );
437 SFX_ITEMSET_ARG( pSh->GetMedium()->GetItemSet(),
438 pVersionItem, SfxInt16Item, SID_VERSION, false );
440 INetURLObject aMedObj( pMed->GetName() );
442 // the logic below is following, if the document seems not to need to be reloaded and the physical name is different
443 // 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
444 if ( ( !bNeedsReload && ( (aMedObj.GetProtocol() == INetProtocol::File &&
445 aMedObj.getFSysPath(INetURLObject::FSYS_DETECT) != aPhysObj.getFSysPath(INetURLObject::FSYS_DETECT) &&
446 !::utl::UCBContentHelper::IsYounger( aMedObj.GetMainURL( INetURLObject::NO_DECODE ), aPhysObj.GetMainURL( INetURLObject::NO_DECODE ) ))
447 || pMed->IsRemote() ) )
448 || pVersionItem )
450 bool bOK = false;
451 if ( !pVersionItem )
453 bool bHasStorage = pMed->HasStorage_Impl();
454 // switching edit mode could be possible without reload
455 if ( bHasStorage && pMed->GetStorage() == pSh->GetStorage() )
457 // TODO/LATER: faster creation of copy
458 if ( !pSh->ConnectTmpStorage_Impl( pMed->GetStorage(), pMed ) )
459 return;
462 pMed->CloseAndRelease();
463 pMed->GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, !( nOpenMode & StreamMode::WRITE ) ) );
464 pMed->SetOpenMode( nOpenMode );
466 pMed->CompleteReOpen();
467 if ( nOpenMode & StreamMode::WRITE )
468 pMed->LockOrigFileOnDemand( false, true );
470 // LockOrigFileOnDemand might set the readonly flag itself, it should be set back
471 pMed->GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, !( nOpenMode & StreamMode::WRITE ) ) );
473 if ( !pMed->GetErrorCode() )
474 bOK = true;
477 if( !bOK )
479 ErrCode nErr = pMed->GetErrorCode();
480 if ( pVersionItem )
481 nErr = ERRCODE_IO_ACCESSDENIED;
482 else
484 pMed->ResetError();
485 pMed->SetOpenMode( SFX_STREAM_READONLY );
486 pMed->ReOpen();
487 pSh->DoSaveCompleted( pMed );
490 // Readonly document can not be switched to edit mode?
491 rReq.Done( false );
493 if ( nOpenMode == SFX_STREAM_READWRITE && !rReq.IsAPI() )
495 // ::com::sun::star::sdbcx::User offering to open it as a template
496 ScopedVclPtrInstance<MessageDialog> aBox(&GetWindow(), SfxResId(STR_QUERY_OPENASTEMPLATE),
497 VCL_MESSAGE_QUESTION, VCL_BUTTONS_YES_NO);
498 if ( RET_YES == aBox->Execute() )
500 SfxApplication* pApp = SfxGetpApp();
501 SfxAllItemSet aSet( pApp->GetPool() );
502 aSet.Put( SfxStringItem( SID_FILE_NAME, pMed->GetName() ) );
503 SFX_ITEMSET_ARG( pMed->GetItemSet(), pReferer, SfxStringItem, SID_REFERER, false );
504 if ( pReferer )
505 aSet.Put( *pReferer );
506 aSet.Put( SfxBoolItem( SID_TEMPLATE, true ) );
507 if ( pVersionItem )
508 aSet.Put( *pVersionItem );
510 if( pMed->GetFilter() )
512 aSet.Put( SfxStringItem( SID_FILTER_NAME, pMed->GetFilter()->GetFilterName() ) );
513 SFX_ITEMSET_ARG( pMed->GetItemSet(), pOptions,
514 SfxStringItem, SID_FILE_FILTEROPTIONS, false );
515 if ( pOptions )
516 aSet.Put( *pOptions );
519 GetDispatcher()->Execute( SID_OPENDOC, SfxCallMode::ASYNCHRON, aSet );
520 return;
522 else
523 nErr = 0;
526 ErrorHandler::HandleError( nErr );
527 rReq.SetReturnValue(
528 SfxBoolItem( rReq.GetSlot(), false ) );
529 return;
531 else
533 pSh->DoSaveCompleted( pMed );
534 pSh->Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) );
535 rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), true ) );
536 rReq.Done( true );
537 return;
541 rReq.AppendItem( SfxBoolItem( SID_FORCERELOAD, true) );
542 rReq.AppendItem( SfxBoolItem( SID_SILENT, true ));
545 case SID_RELOAD:
547 // Due to Double occupancy in toolboxes (with or without Ctrl),
548 // it is also possible that the slot is enabled, but Ctrl-click
549 // despite this is not!
550 if ( !pSh || !pSh->CanReload_Impl() )
551 break;
552 SfxApplication* pApp = SfxGetpApp();
553 SFX_REQUEST_ARG(rReq, pForceReloadItem, SfxBoolItem,
554 SID_FORCERELOAD, false);
555 if( pForceReloadItem && !pForceReloadItem->GetValue() &&
556 !pSh->GetMedium()->IsExpired() )
557 return;
558 if( pImp->bReloading || pSh->IsInModalMode() )
559 return;
561 // AutoLoad is prohibited if possible
562 SFX_REQUEST_ARG(rReq, pAutoLoadItem, SfxBoolItem, SID_AUTOLOAD, false);
563 if ( pAutoLoadItem && pAutoLoadItem->GetValue() &&
564 GetFrame().IsAutoLoadLocked_Impl() )
565 return;
567 SfxObjectShellLock xOldObj( pSh );
568 pImp->bReloading = true;
569 SFX_REQUEST_ARG(rReq, pURLItem, SfxStringItem,
570 SID_FILE_NAME, false);
571 // Open as editable?
572 bool bForEdit = !pSh->IsReadOnly();
574 // If possible ask the User
575 bool bDo = GetViewShell()->PrepareClose();
576 SFX_REQUEST_ARG(rReq, pSilentItem, SfxBoolItem, SID_SILENT, false);
577 if ( bDo && GetFrame().DocIsModified_Impl() &&
578 !rReq.IsAPI() && ( !pSilentItem || !pSilentItem->GetValue() ) )
580 ScopedVclPtrInstance<MessageDialog> aBox(&GetWindow(), SfxResId(STR_QUERY_LASTVERSION),
581 VCL_MESSAGE_QUESTION, VCL_BUTTONS_YES_NO);
582 bDo = ( RET_YES == aBox->Execute() );
585 if ( bDo )
587 SfxMedium *pMedium = xOldObj->GetMedium();
589 // Remove Frameset before the FramesetView may disappear
590 OUString aURL;
591 if (pURLItem)
592 aURL = pURLItem->GetValue();
593 else
594 aURL = pMedium->GetName();
596 bool bHandsOff =
597 ( pMedium->GetURLObject().GetProtocol() == INetProtocol::File && !xOldObj->IsDocShared() );
599 // Emty existing SfxMDIFrames for this Document
600 // in native format or R/O, open it now for editing?
601 SfxObjectShellLock xNewObj;
603 // collect the views of the document
604 // TODO: when UNO ViewFactories are available for SFX-based documents, the below code should
605 // be UNOized, too
606 typedef ::std::pair< Reference< XFrame >, sal_uInt16 > ViewDescriptor;
607 ::std::list< ViewDescriptor > aViewFrames;
608 SfxViewFrame *pView = GetFirst( xOldObj );
609 while ( pView )
611 Reference< XFrame > xFrame( pView->GetFrame().GetFrameInterface() );
612 OSL_ENSURE( xFrame.is(), "SfxViewFrame::ExecReload_Impl: no XFrame?!" );
613 aViewFrames.push_back( ViewDescriptor( xFrame, pView->GetCurViewId() ) );
615 pView = GetNext( *pView, xOldObj );
618 DELETEZ( xOldObj->Get_Impl()->pReloadTimer );
620 SfxItemSet* pNewSet = 0;
621 const SfxFilter *pFilter = pMedium->GetFilter();
622 if( pURLItem )
624 pNewSet = new SfxAllItemSet( pApp->GetPool() );
625 pNewSet->Put( *pURLItem );
627 // Filter Detection
628 OUString referer;
629 SFX_REQUEST_ARG(
630 rReq, refererItem, SfxStringItem, SID_REFERER, false);
631 if (refererItem != 0) {
632 referer = refererItem->GetValue();
634 SfxMedium aMedium( pURLItem->GetValue(), referer, SFX_STREAM_READWRITE );
635 SfxFilterMatcher().GuessFilter( aMedium, &pFilter );
636 if ( pFilter )
637 pNewSet->Put( SfxStringItem( SID_FILTER_NAME, pFilter->GetName() ) );
638 pNewSet->Put( *aMedium.GetItemSet() );
640 else
642 pNewSet = new SfxAllItemSet( *pMedium->GetItemSet() );
643 pNewSet->ClearItem( SID_VIEW_ID );
644 pNewSet->ClearItem( SID_STREAM );
645 pNewSet->ClearItem( SID_INPUTSTREAM );
646 pNewSet->Put( SfxStringItem( SID_FILTER_NAME, pMedium->GetFilter()->GetName() ) );
648 // let the current security settings be checked again
649 pNewSet->Put( SfxUInt16Item( SID_MACROEXECMODE, document::MacroExecMode::USE_CONFIG ) );
651 if ( pSh->IsOriginallyReadOnlyMedium() )
652 // edit mode is switched or reload of readonly document
653 pNewSet->Put( SfxBoolItem( SID_DOC_READONLY, true ) );
654 else
655 // Reload of file opened for writing
656 pNewSet->ClearItem( SID_DOC_READONLY );
659 // If a salvaged file is present, do not enclose the OrigURL
660 // again, since the Tempdate is invalid after reload.
661 SFX_ITEMSET_ARG( pNewSet, pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, false);
662 if( pSalvageItem )
664 aURL = pSalvageItem->GetValue();
665 pNewSet->ClearItem( SID_ORIGURL );
666 pNewSet->ClearItem( SID_DOC_SALVAGE );
669 #if HAVE_FEATURE_MULTIUSER_ENVIRONMENT
670 // TODO/LATER: Temporary solution, the SfxMedium must know the original URL as aLogicName
671 // SfxMedium::Transfer_Impl() will be forbidden then.
672 if ( xOldObj->IsDocShared() )
673 pNewSet->Put( SfxStringItem( SID_FILE_NAME, xOldObj->GetSharedFileURL() ) );
674 #endif
675 if ( pURLItem )
676 pNewSet->Put( SfxStringItem( SID_REFERER, pMedium->GetName() ) );
677 else
678 pNewSet->Put( SfxStringItem( SID_REFERER, OUString() ) );
680 xOldObj->CancelTransfers();
683 if ( pSilentItem && pSilentItem->GetValue() )
684 pNewSet->Put( SfxBoolItem( SID_SILENT, true ) );
686 SFX_ITEMSET_ARG(pNewSet, pInteractionItem, SfxUnoAnyItem, SID_INTERACTIONHANDLER, false);
687 SFX_ITEMSET_ARG(pNewSet, pMacroExecItem , SfxUInt16Item, SID_MACROEXECMODE , false);
688 SFX_ITEMSET_ARG(pNewSet, pDocTemplateItem, SfxUInt16Item, SID_UPDATEDOCMODE , false);
690 if (!pInteractionItem)
692 Reference < task::XInteractionHandler2 > xHdl = task::InteractionHandler::createWithParent( ::comphelper::getProcessComponentContext(), 0 );
693 if (xHdl.is())
694 pNewSet->Put( SfxUnoAnyItem(SID_INTERACTIONHANDLER,::com::sun::star::uno::makeAny(xHdl)) );
697 if (!pMacroExecItem)
698 pNewSet->Put( SfxUInt16Item(SID_MACROEXECMODE,::com::sun::star::document::MacroExecMode::USE_CONFIG) );
699 if (!pDocTemplateItem)
700 pNewSet->Put( SfxUInt16Item(SID_UPDATEDOCMODE,::com::sun::star::document::UpdateDocMode::ACCORDING_TO_CONFIG) );
702 xOldObj->SetModified( false );
703 // Do not chache the old Document! Is invalid when loading
704 // another document.
706 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSavedOptions, SfxStringItem, SID_FILE_FILTEROPTIONS, false);
707 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSavedReferer, SfxStringItem, SID_REFERER, false);
709 bool bHasStorage = pMedium->HasStorage_Impl();
710 if( bHandsOff )
712 if ( bHasStorage && pMedium->GetStorage() == xOldObj->GetStorage() )
714 // TODO/LATER: faster creation of copy
715 if ( !xOldObj->ConnectTmpStorage_Impl( pMedium->GetStorage(), pMedium ) )
716 return;
719 pMedium->CloseAndRelease();
722 xNewObj = SfxObjectShell::CreateObject( pFilter->GetServiceName(), SfxObjectCreateMode::STANDARD );
724 if ( xOldObj->IsModifyPasswordEntered() )
725 xNewObj->SetModifyPasswordEntered();
727 uno::Sequence < beans::PropertyValue > aLoadArgs;
728 TransformItems( SID_OPENDOC, *pNewSet, aLoadArgs );
731 uno::Reference < frame::XLoadable > xLoad( xNewObj->GetModel(), uno::UNO_QUERY );
732 xLoad->load( aLoadArgs );
734 catch ( uno::Exception& )
736 xNewObj->DoClose();
737 xNewObj = 0;
740 DELETEZ( pNewSet );
742 if( !xNewObj.Is() )
744 if( bHandsOff )
746 // back to old medium
747 pMedium->ReOpen();
748 pMedium->LockOrigFileOnDemand( false, true );
750 xOldObj->DoSaveCompleted( pMedium );
753 // r/o-Doc couldn't be switched to writing mode
754 if ( bForEdit && SID_EDITDOC == rReq.GetSlot() )
756 // ask user for opening as template
757 ScopedVclPtrInstance<MessageDialog> aBox(&GetWindow(), SfxResId(STR_QUERY_OPENASTEMPLATE),
758 VCL_MESSAGE_QUESTION, VCL_BUTTONS_YES_NO);
759 if ( RET_YES == aBox->Execute() )
761 SfxAllItemSet aSet( pApp->GetPool() );
762 aSet.Put( SfxStringItem( SID_FILE_NAME, pMedium->GetName() ) );
763 aSet.Put( SfxStringItem( SID_TARGETNAME, OUString("_blank") ) );
764 if ( pSavedOptions )
765 aSet.Put( *pSavedOptions );
766 if ( pSavedReferer )
767 aSet.Put( *pSavedReferer );
768 aSet.Put( SfxBoolItem( SID_TEMPLATE, true ) );
769 if( pFilter )
770 aSet.Put( SfxStringItem( SID_FILTER_NAME, pFilter->GetFilterName() ) );
771 GetDispatcher()->Execute( SID_OPENDOC, SfxCallMode::ASYNCHRON, aSet );
775 else
777 if ( xNewObj->GetModifyPasswordHash() && xNewObj->GetModifyPasswordHash() != xOldObj->GetModifyPasswordHash() )
779 xNewObj->SetModifyPasswordEntered( false );
780 xNewObj->SetReadOnly();
782 else if ( rReq.GetSlot() == SID_EDITDOC )
784 xNewObj->SetReadOnlyUI( !bForEdit );
787 #if HAVE_FEATURE_MULTIUSER_ENVIRONMENT
788 if ( xNewObj->IsDocShared() )
790 // the file is shared but the closing can change the sharing control file
791 xOldObj->DoNotCleanShareControlFile();
793 #endif
794 // the Reload and Silent items were only temporary, remove them
795 xNewObj->GetMedium()->GetItemSet()->ClearItem( SID_RELOAD );
796 xNewObj->GetMedium()->GetItemSet()->ClearItem( SID_SILENT );
797 TransformItems( SID_OPENDOC, *xNewObj->GetMedium()->GetItemSet(), aLoadArgs );
799 UpdateDocument_Impl();
803 while ( !aViewFrames.empty() )
805 LoadViewIntoFrame_Impl( *xNewObj, aViewFrames.front().first, aLoadArgs, aViewFrames.front().second, false );
806 aViewFrames.pop_front();
809 catch( const Exception& )
811 // close the remaining frames
812 // Don't catch exceptions herein, if this fails, then we're left in an indetermined state, and
813 // crashing is better than trying to proceed
814 while ( !aViewFrames.empty() )
816 Reference< util::XCloseable > xClose( aViewFrames.front().first, UNO_QUERY_THROW );
817 xClose->close( true );
818 aViewFrames.pop_front();
822 // Propagate document closure.
823 SfxGetpApp()->NotifyEvent( SfxEventHint( SFX_EVENT_CLOSEDOC, GlobalEventConfig::GetEventName( GlobalEventId::CLOSEDOC ), xOldObj ) );
826 // Record as done
827 rReq.Done( true );
828 rReq.SetReturnValue(SfxBoolItem(rReq.GetSlot(), true));
829 return;
831 else
833 // Record as not done
834 rReq.Done();
835 rReq.SetReturnValue(SfxBoolItem(rReq.GetSlot(), false));
836 pImp->bReloading = false;
837 return;
843 void SfxViewFrame::StateReload_Impl( SfxItemSet& rSet )
845 SfxObjectShell* pSh = GetObjectShell();
846 if ( !pSh )
848 // I'm just on reload and am yielding myself ...
849 return;
852 SfxWhichIter aIter( rSet );
853 for ( sal_uInt16 nWhich = aIter.FirstWhich(); nWhich; nWhich = aIter.NextWhich() )
855 switch ( nWhich )
857 case SID_EDITDOC:
859 const SfxViewShell *pVSh;
860 const SfxShell *pFSh;
861 if ( !pSh ||
862 !pSh->HasName() ||
863 !( pSh->Get_Impl()->nLoadedFlags & SfxLoadedFlags::MAINDOCUMENT ) ||
864 ( pSh->GetCreateMode() == SfxObjectCreateMode::EMBEDDED &&
865 ( !(pVSh = pSh->GetViewShell()) ||
866 !(pFSh = pVSh->GetFormShell()) ||
867 !pFSh->IsDesignMode())))
868 rSet.DisableItem( SID_EDITDOC );
869 else
871 SFX_ITEMSET_ARG( pSh->GetMedium()->GetItemSet(), pItem, SfxBoolItem, SID_EDITDOC, false );
872 if ( pItem && !pItem->GetValue() )
873 rSet.DisableItem( SID_EDITDOC );
874 else
875 rSet.Put( SfxBoolItem( nWhich, !pSh->IsReadOnly() ) );
877 break;
880 case SID_RELOAD:
882 SfxFrame* pFrame = &GetTopFrame();
884 if ( !pSh || !pSh->CanReload_Impl() || pSh->GetCreateMode() == SfxObjectCreateMode::EMBEDDED )
885 rSet.DisableItem(nWhich);
886 else
888 // If any ChildFrame is reloadable, the slot is enabled,
889 // so you can perfom CTRL-Reload
890 bool bReloadAvailable = false;
891 SfxFrameIterator aFrameIter( *pFrame, true );
892 for( SfxFrame* pNextFrame = aFrameIter.FirstFrame();
893 pFrame;
894 pNextFrame = pNextFrame ?
895 aFrameIter.NextFrame( *pNextFrame ) : 0 )
897 SfxObjectShell *pShell = pFrame->GetCurrentDocument();
898 if( pShell && pShell->Get_Impl()->bReloadAvailable )
900 bReloadAvailable = true;
901 break;
903 pFrame = pNextFrame;
906 rSet.Put( SfxBoolItem( nWhich, bReloadAvailable));
909 break;
915 void SfxViewFrame::ExecHistory_Impl( SfxRequest &rReq )
917 // Is there an Undo-Manager on the top Shell?
918 SfxShell *pSh = GetDispatcher()->GetShell(0);
919 ::svl::IUndoManager* pShUndoMgr = pSh->GetUndoManager();
920 bool bOK = false;
921 if ( pShUndoMgr )
923 switch ( rReq.GetSlot() )
925 case SID_CLEARHISTORY:
926 pShUndoMgr->Clear();
927 bOK = true;
928 break;
930 case SID_UNDO:
931 pShUndoMgr->Undo();
932 GetBindings().InvalidateAll(false);
933 bOK = true;
934 break;
936 case SID_REDO:
937 pShUndoMgr->Redo();
938 GetBindings().InvalidateAll(false);
939 bOK = true;
940 break;
942 case SID_REPEAT:
943 if ( pSh->GetRepeatTarget() )
944 pShUndoMgr->Repeat( *pSh->GetRepeatTarget() );
945 bOK = true;
946 break;
949 else if ( GetViewShell() )
951 // The SW has its own undo in the View
952 const SfxPoolItem *pRet = GetViewShell()->ExecuteSlot( rReq );
953 if ( pRet )
954 bOK = static_cast<const SfxBoolItem*>(pRet)->GetValue();
957 rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bOK ) );
958 rReq.Done();
962 void SfxViewFrame::StateHistory_Impl( SfxItemSet &rSet )
964 // Search for Undo-Manager
965 SfxShell *pSh = GetDispatcher()->GetShell(0);
966 if ( !pSh )
967 // I'm just on reload and am yielding myself ...
968 return;
970 ::svl::IUndoManager *pShUndoMgr = pSh->GetUndoManager();
971 if ( !pShUndoMgr )
973 // The SW has its own undo in the View
974 SfxWhichIter aIter( rSet );
975 SfxViewShell *pViewSh = GetViewShell();
976 if( !pViewSh ) return;
977 for ( sal_uInt16 nSID = aIter.FirstWhich(); nSID; nSID = aIter.NextWhich() )
978 pViewSh->GetSlotState( nSID, 0, &rSet );
979 return;
982 if ( pShUndoMgr->GetUndoActionCount() == 0 &&
983 pShUndoMgr->GetRedoActionCount() == 0 &&
984 pShUndoMgr->GetRepeatActionCount() == 0 )
985 rSet.DisableItem( SID_CLEARHISTORY );
987 if ( pShUndoMgr && pShUndoMgr->GetUndoActionCount() )
989 OUString aTmp(SvtResId(STR_UNDO).toString());
990 aTmp+= pShUndoMgr->GetUndoActionComment(0);
991 rSet.Put( SfxStringItem( SID_UNDO, aTmp ) );
993 else
994 rSet.DisableItem( SID_UNDO );
996 if ( pShUndoMgr && pShUndoMgr->GetRedoActionCount() )
998 OUString aTmp(SvtResId(STR_REDO).toString());
999 aTmp += pShUndoMgr->GetRedoActionComment(0);
1000 rSet.Put( SfxStringItem( SID_REDO, aTmp ) );
1002 else
1003 rSet.DisableItem( SID_REDO );
1004 SfxRepeatTarget *pTarget = pSh->GetRepeatTarget();
1005 if ( pShUndoMgr && pTarget && pShUndoMgr->GetRepeatActionCount() &&
1006 pShUndoMgr->CanRepeat(*pTarget) )
1008 OUString aTmp(SvtResId(STR_REPEAT).toString());
1009 aTmp += pShUndoMgr->GetRepeatActionComment(*pTarget);
1010 rSet.Put( SfxStringItem( SID_REPEAT, aTmp ) );
1012 else
1013 rSet.DisableItem( SID_REPEAT );
1017 void SfxViewFrame::PopShellAndSubShells_Impl( SfxViewShell& i_rViewShell )
1019 i_rViewShell.PopSubShells_Impl();
1020 sal_uInt16 nLevel = pDispatcher->GetShellLevel( i_rViewShell );
1021 if ( nLevel != USHRT_MAX )
1023 if ( nLevel )
1025 // more sub shells on the stack, which were not affected by PopSubShells_Impl
1026 SfxShell *pSubShell = pDispatcher->GetShell( nLevel-1 );
1027 if ( pSubShell == i_rViewShell.GetSubShell() )
1028 // "real" sub shells will be deleted elsewhere
1029 pDispatcher->Pop( *pSubShell, SfxDispatcherPopFlags::POP_UNTIL );
1030 else
1031 pDispatcher->Pop( *pSubShell, SfxDispatcherPopFlags::POP_UNTIL | SfxDispatcherPopFlags::POP_DELETE );
1033 pDispatcher->Pop( i_rViewShell );
1034 pDispatcher->Flush();
1040 void SfxViewFrame::ReleaseObjectShell_Impl()
1042 /* [Description]
1044 This method empties the SfxViewFrame, i.e. takes the <SfxObjectShell>
1045 from the dispatcher and ends its <SfxListener> Relationship to this
1046 SfxObjectShell (by which they may even destroy themselves).
1048 Thus, by invoking ReleaseObjectShell() and SetObjectShell() the
1049 SfxObjectShell can be replaced.
1051 Between RealeaseObjectShell() and SetObjectShell() can the control not
1052 be handed over to the system.
1054 [Cross-reference]
1056 <SfxViewFrame::SetObjectShell(SfxObjectShell&)>
1059 DBG_ASSERT( xObjSh.Is(), "no SfxObjectShell to release!" );
1061 GetFrame().ReleasingComponent_Impl( true );
1062 if ( GetWindow().HasChildPathFocus( true ) )
1064 DBG_ASSERT( !GetActiveChildFrame_Impl(), "Wrong active child frame!" );
1065 GetWindow().GrabFocus();
1068 SfxViewShell *pDyingViewSh = GetViewShell();
1069 if ( pDyingViewSh )
1071 PopShellAndSubShells_Impl( *pDyingViewSh );
1072 pDyingViewSh->DisconnectAllClients();
1073 SetViewShell_Impl(0);
1074 delete pDyingViewSh;
1076 #ifdef DBG_UTIL
1077 else
1078 OSL_FAIL("No Shell");
1079 #endif
1081 if ( xObjSh.Is() )
1083 pDispatcher->Pop( *xObjSh );
1084 SfxModule* pModule = xObjSh->GetModule();
1085 if( pModule )
1086 pDispatcher->RemoveShell_Impl( *pModule );
1087 pDispatcher->Flush();
1088 EndListening( *xObjSh );
1090 Notify( *xObjSh, SfxSimpleHint(SFX_HINT_TITLECHANGED) );
1091 Notify( *xObjSh, SfxSimpleHint(SFX_HINT_DOCCHANGED) );
1093 if ( 1 == xObjSh->GetOwnerLockCount() && pImp->bObjLocked && xObjSh->GetCreateMode() == SfxObjectCreateMode::EMBEDDED )
1094 xObjSh->DoClose();
1095 SfxObjectShellRef xDyingObjSh = xObjSh;
1096 xObjSh.Clear();
1097 if( ( GetFrameType() & SFXFRAME_HASTITLE ) && pImp->nDocViewNo )
1098 xDyingObjSh->GetNoSet_Impl().ReleaseIndex(pImp->nDocViewNo-1);
1099 if ( pImp->bObjLocked )
1101 xDyingObjSh->OwnerLock( false );
1102 pImp->bObjLocked = false;
1106 GetDispatcher()->SetDisableFlags( 0 );
1110 bool SfxViewFrame::Close()
1113 DBG_ASSERT( GetFrame().IsClosing_Impl() || !GetFrame().GetFrameInterface().is(), "ViewFrame closed too early!" );
1115 // If no saving have been made up until now, then embedded Objects should
1116 // not be saved automatically anymore.
1117 if ( GetViewShell() )
1118 GetViewShell()->DiscardClients_Impl();
1119 Broadcast( SfxSimpleHint( SFX_HINT_DYING ) );
1121 if (SfxViewFrame::Current() == this)
1122 SfxViewFrame::SetViewFrame( NULL );
1124 // Since the Dispatcher is emptied, it can not be used in any reasnable
1125 // manner, thus it is better to let the dispatcher be.
1126 GetDispatcher()->Lock(true);
1127 delete this;
1129 return true;
1134 void SfxViewFrame::DoActivate( bool bUI, SfxViewFrame* pOldFrame )
1136 SfxGetpApp();
1138 pDispatcher->DoActivate_Impl( bUI, pOldFrame );
1140 // If this ViewFrame has got a parent and this is not a parent of the
1141 // old ViewFrames, it gets a ParentActivate.
1142 if ( bUI )
1144 SfxViewFrame *pFrame = GetParentViewFrame();
1145 while ( pFrame )
1147 if ( !pOldFrame || !pOldFrame->GetFrame().IsParent( &pFrame->GetFrame() ) )
1148 pFrame->pDispatcher->DoParentActivate_Impl();
1149 pFrame = pFrame->GetParentViewFrame();
1155 void SfxViewFrame::DoDeactivate(bool bUI, SfxViewFrame* pNewFrame )
1157 SfxGetpApp();
1158 pDispatcher->DoDeactivate_Impl( bUI, pNewFrame );
1160 // If this ViewFrame has got a parent and this is not a parent of the
1161 // new ViewFrames, it gets a ParentDeactivate.
1162 if ( bUI )
1164 SfxViewFrame *pFrame = GetParentViewFrame();
1165 while ( pFrame )
1167 if ( !pNewFrame || !pNewFrame->GetFrame().IsParent( &pFrame->GetFrame() ) )
1168 pFrame->pDispatcher->DoParentDeactivate_Impl();
1169 pFrame = pFrame->GetParentViewFrame();
1175 void SfxViewFrame::InvalidateBorderImpl( const SfxViewShell* pSh )
1177 if( pSh && !nAdjustPosPixelLock )
1179 if ( GetViewShell() && GetWindow().IsVisible() )
1181 if ( GetFrame().IsInPlace() )
1183 return;
1186 DoAdjustPosSizePixel( GetViewShell(), Point(),
1187 GetWindow().GetOutputSizePixel() );
1193 bool SfxViewFrame::SetBorderPixelImpl
1195 const SfxViewShell* pVSh,
1196 const SvBorder& rBorder
1200 pImp->aBorder = rBorder;
1202 if ( IsResizeInToOut_Impl() && !GetFrame().IsInPlace() )
1204 Size aSize = pVSh->GetWindow()->GetOutputSizePixel();
1205 if ( aSize.Width() && aSize.Height() )
1207 aSize.Width() += rBorder.Left() + rBorder.Right();
1208 aSize.Height() += rBorder.Top() + rBorder.Bottom();
1210 Size aOldSize = GetWindow().GetOutputSizePixel();
1211 GetWindow().SetOutputSizePixel( aSize );
1212 vcl::Window* pParent = &GetWindow();
1213 while ( pParent->GetParent() )
1214 pParent = pParent->GetParent();
1215 Size aOuterSize = pParent->GetOutputSizePixel();
1216 aOuterSize.Width() += ( aSize.Width() - aOldSize.Width() );
1217 aOuterSize.Height() += ( aSize.Height() - aOldSize.Height() );
1218 pParent->SetOutputSizePixel( aOuterSize );
1221 else
1223 Point aPoint;
1224 Rectangle aEditArea( aPoint, GetWindow().GetOutputSizePixel() );
1225 aEditArea.Left() += rBorder.Left();
1226 aEditArea.Right() -= rBorder.Right();
1227 aEditArea.Top() += rBorder.Top();
1228 aEditArea.Bottom() -= rBorder.Bottom();
1229 pVSh->GetWindow()->SetPosSizePixel( aEditArea.TopLeft(), aEditArea.GetSize() );
1232 return true;
1236 const SvBorder& SfxViewFrame::GetBorderPixelImpl
1238 const SfxViewShell* /*pSh*/
1239 ) const
1242 return pImp->aBorder;
1246 void SfxViewFrame::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
1248 if( IsDowning_Impl())
1249 return;
1251 // we know only SimpleHints
1252 const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
1253 if ( pSimpleHint )
1255 switch( pSimpleHint->GetId() )
1257 case SFX_HINT_MODECHANGED:
1259 UpdateTitle();
1261 if ( !xObjSh.Is() )
1262 break;
1264 // Switch r/o?
1265 SfxBindings& rBind = GetBindings();
1266 rBind.Invalidate( SID_RELOAD );
1267 SfxDispatcher *pDispat = GetDispatcher();
1268 bool bWasReadOnly = pDispat->GetReadOnly_Impl();
1269 bool bIsReadOnly = xObjSh->IsReadOnly();
1270 if ( bWasReadOnly != bIsReadOnly )
1272 // Then also TITLE_CHANGED
1273 UpdateTitle();
1274 rBind.Invalidate( SID_FILE_NAME );
1275 rBind.Invalidate( SID_DOCINFO_TITLE );
1276 rBind.Invalidate( SID_EDITDOC );
1278 pDispat->GetBindings()->InvalidateAll(true);
1279 pDispat->SetReadOnly_Impl( bIsReadOnly );
1281 // Only force and Dispatcher-Update, if it is done next
1282 // anyway, otherwise flickering or GPF is possibel since
1283 // the Writer for example prefers in Resize preform some
1284 // actions which has a SetReadOnlyUI in Dispatcher as a
1285 // result!
1287 if ( pDispat->IsUpdated_Impl() )
1288 pDispat->Update_Impl(true);
1291 Enable( !xObjSh->IsInModalMode() );
1292 break;
1295 case SFX_HINT_TITLECHANGED:
1297 UpdateTitle();
1298 SfxBindings& rBind = GetBindings();
1299 rBind.Invalidate( SID_FILE_NAME );
1300 rBind.Invalidate( SID_DOCINFO_TITLE );
1301 rBind.Invalidate( SID_EDITDOC );
1302 rBind.Invalidate( SID_RELOAD );
1303 break;
1306 case SFX_HINT_DEINITIALIZING:
1307 GetFrame().DoClose();
1308 break;
1309 case SFX_HINT_DYING:
1310 // when the Object is being deleted, destroy the view too
1311 if ( xObjSh.Is() )
1312 ReleaseObjectShell_Impl();
1313 else
1314 GetFrame().DoClose();
1315 break;
1319 else if ( dynamic_cast<const SfxEventHint*>(&rHint) )
1321 const SfxEventHint* pEventHint = dynamic_cast<const SfxEventHint*>(&rHint);
1322 // When the Document is loaded asynchronously, was the Dispatcher
1323 // set as ReadOnly, to what must be returned when the document itself
1324 // is not read only, and the loading is finished.
1325 switch ( pEventHint->GetEventId() )
1327 case SFX_EVENT_MODIFYCHANGED:
1329 SfxBindings& rBind = GetBindings();
1330 rBind.Invalidate( SID_DOC_MODIFIED );
1331 rBind.Invalidate( SID_SAVEDOC );
1332 rBind.Invalidate( SID_RELOAD );
1333 rBind.Invalidate( SID_EDITDOC );
1334 break;
1337 case SFX_EVENT_OPENDOC:
1338 case SFX_EVENT_CREATEDOC:
1340 if ( !xObjSh.Is() )
1341 break;
1343 SfxBindings& rBind = GetBindings();
1344 rBind.Invalidate( SID_RELOAD );
1345 rBind.Invalidate( SID_EDITDOC );
1346 const SfxViewShell *pVSh;
1347 const SfxShell *pFSh;
1348 if ( !xObjSh->IsReadOnly() ||
1349 ( xObjSh->GetCreateMode() == SfxObjectCreateMode::EMBEDDED &&
1350 (pVSh = xObjSh->GetViewShell()) &&
1351 (pFSh = pVSh->GetFormShell()) &&
1352 !pFSh->IsDesignMode()))
1354 // In contrast to above (TITLE_CHANGED) does the UI not
1355 // have to be updated because it was not obstructed
1357 // #i21560# InvalidateAll() causes the assertion
1358 // 'SfxBindings::Invalidate while in update" when
1359 // the sfx slot SID_BASICIDE_APPEAR is executed
1360 // via API from another thread (Java).
1361 // According to MBA this call is not necessary anymore,
1362 // because each document has its own SfxBindings.
1363 //GetDispatcher()->GetBindings()->InvalidateAll(true);
1365 else
1367 SfxInfoBarWindow* pInfoBar = AppendInfoBar("readonly", SfxResId(STR_READONLY_DOCUMENT));
1368 if (pInfoBar)
1370 VclPtrInstance<PushButton> pBtn( &GetWindow(), SfxResId(BT_READONLY_EDIT));
1371 pBtn->SetClickHdl(LINK(this, SfxViewFrame, SwitchReadOnlyHandler));
1372 pInfoBar->addButton(pBtn);
1376 break;
1379 case SFX_EVENT_TOGGLEFULLSCREENMODE:
1381 if ( GetFrame().OwnsBindings_Impl() )
1382 GetBindings().GetDispatcher_Impl()->Update_Impl( true );
1383 break;
1389 IMPL_LINK_NOARG(SfxViewFrame, SwitchReadOnlyHandler)
1391 GetDispatcher()->Execute(SID_EDITDOC);
1392 return 0;
1396 void SfxViewFrame::Construct_Impl( SfxObjectShell *pObjSh )
1398 pImp->bResizeInToOut = true;
1399 pImp->bDontOverwriteResizeInToOut = false;
1400 pImp->bObjLocked = false;
1401 pImp->pFocusWin = 0;
1402 pImp->pActiveChild = NULL;
1403 pImp->nCurViewId = 0;
1404 pImp->bReloading = false;
1405 pImp->bIsDowning = false;
1406 pImp->bModal = false;
1407 pImp->bEnabled = true;
1408 pImp->nDocViewNo = 0;
1409 pImp->aMargin = Size( -1, -1 );
1410 pImp->pWindow = 0;
1412 SetPool( &SfxGetpApp()->GetPool() );
1413 pDispatcher = new SfxDispatcher(this);
1414 if ( !GetBindings().GetDispatcher() )
1415 GetBindings().SetDispatcher( pDispatcher );
1417 xObjSh = pObjSh;
1418 if ( xObjSh.Is() && xObjSh->IsPreview() )
1419 SetQuietMode_Impl( true );
1421 if ( pObjSh )
1423 pDispatcher->Push( *SfxGetpApp() );
1424 SfxModule* pModule = xObjSh->GetModule();
1425 if( pModule )
1426 pDispatcher->Push( *pModule );
1427 pDispatcher->Push( *this );
1428 pDispatcher->Push( *pObjSh );
1429 pDispatcher->Flush();
1430 StartListening( *pObjSh );
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( *SfxGetpApp() );
1438 pDispatcher->Push( *this );
1439 pDispatcher->Flush();
1442 SfxViewFrameArr_Impl &rViewArr = SfxGetpApp()->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 )
1465 rFrame.SetCurrentViewFrame_Impl( this );
1466 rFrame.SetFrameType_Impl( GetFrameType() | SFXFRAME_HASTITLE );
1467 Construct_Impl( pObjShell );
1469 pImp->pWindow = VclPtr<SfxFrameViewWindow_Impl>::Create( this, rFrame.GetWindow() );
1470 pImp->pWindow->SetSizePixel( rFrame.GetWindow().GetOutputSizePixel() );
1471 rFrame.SetOwnsBindings_Impl( true );
1472 rFrame.CreateWorkWindow_Impl();
1476 SfxViewFrame::~SfxViewFrame()
1478 SetDowning_Impl();
1480 if ( SfxViewFrame::Current() == this )
1481 SfxViewFrame::SetViewFrame( NULL );
1483 ReleaseObjectShell_Impl();
1485 if ( GetFrame().OwnsBindings_Impl() )
1486 // The Bindings delete the Frame!
1487 KillDispatcher_Impl();
1489 pImp->pWindow.disposeAndClear();
1490 pImp->pFocusWin.clear();
1492 if ( GetFrame().GetCurrentViewFrame() == this )
1493 GetFrame().SetCurrentViewFrame_Impl( NULL );
1495 // Unregister from the Frame List.
1496 SfxApplication *pSfxApp = SfxGetpApp();
1497 SfxViewFrameArr_Impl &rFrames = pSfxApp->GetViewFrames_Impl();
1498 SfxViewFrameArr_Impl::iterator it = std::find( rFrames.begin(), rFrames.end(), this );
1499 rFrames.erase( it );
1501 // Delete Member
1502 KillDispatcher_Impl();
1504 delete pImp;
1508 void SfxViewFrame::KillDispatcher_Impl()
1510 // Remove and delete the Dispatcher.
1514 SfxModule* pModule = xObjSh.Is() ? xObjSh->GetModule() : 0;
1515 if ( xObjSh.Is() )
1516 ReleaseObjectShell_Impl();
1517 if ( pDispatcher )
1519 if( pModule )
1520 pDispatcher->Pop( *pModule, SfxDispatcherPopFlags::POP_UNTIL );
1521 else
1522 pDispatcher->Pop( *this );
1523 DELETEZ(pDispatcher);
1528 SfxViewFrame* SfxViewFrame::Current()
1530 return SfxApplication::Get() ? SfxGetpApp()->Get_Impl()->pViewFrame : NULL;
1534 // returns the first window of spec. type viewing the specified doc.
1535 SfxViewFrame* SfxViewFrame::GetFirst
1537 const SfxObjectShell* pDoc,
1538 bool bOnlyIfVisible
1541 SfxApplication *pSfxApp = SfxGetpApp();
1542 SfxViewFrameArr_Impl &rFrames = pSfxApp->GetViewFrames_Impl();
1544 // search for a SfxDocument of the specified type
1545 for ( sal_uInt16 nPos = 0; nPos < rFrames.size(); ++nPos )
1547 SfxViewFrame *pFrame = rFrames[nPos];
1548 if ( ( !pDoc || pDoc == pFrame->GetObjectShell() )
1549 && ( !bOnlyIfVisible || pFrame->IsVisible() )
1551 return pFrame;
1554 return 0;
1558 // returns thenext window of spec. type viewing the specified doc.
1559 SfxViewFrame* SfxViewFrame::GetNext
1561 const SfxViewFrame& rPrev,
1562 const SfxObjectShell* pDoc,
1563 bool bOnlyIfVisible
1566 SfxApplication *pSfxApp = SfxGetpApp();
1567 SfxViewFrameArr_Impl &rFrames = pSfxApp->GetViewFrames_Impl();
1569 // refind the specified predecessor
1570 sal_uInt16 nPos;
1571 for ( nPos = 0; nPos < rFrames.size(); ++nPos )
1572 if ( rFrames[nPos] == &rPrev )
1573 break;
1575 // search for a Frame of the specified type
1576 for ( ++nPos; nPos < rFrames.size(); ++nPos )
1578 SfxViewFrame *pFrame = rFrames[nPos];
1579 if ( ( !pDoc || pDoc == pFrame->GetObjectShell() )
1580 && ( !bOnlyIfVisible || pFrame->IsVisible() )
1582 return pFrame;
1584 return 0;
1588 SfxProgress* SfxViewFrame::GetProgress() const
1590 SfxObjectShell *pObjSh = GetObjectShell();
1591 return pObjSh ? pObjSh->GetProgress() : 0;
1595 void SfxViewFrame::DoAdjustPosSizePixel //! divide on Inner.../Outer...
1597 SfxViewShell* pSh,
1598 const Point& rPos,
1599 const Size& rSize
1603 // Components do not use this Method!
1604 if( pSh && pSh->GetWindow() && !nAdjustPosPixelLock )
1606 nAdjustPosPixelLock++;
1607 if ( pImp->bResizeInToOut )
1608 pSh->InnerResizePixel( rPos, rSize );
1609 else
1610 pSh->OuterResizePixel( rPos, rSize );
1611 nAdjustPosPixelLock--;
1615 bool SfxViewFrameItem::operator==( const SfxPoolItem &rItem ) const
1617 return dynamic_cast<const SfxViewFrameItem&>(rItem).pFrame == pFrame;
1620 SfxPoolItem* SfxViewFrameItem::Clone( SfxItemPool *) const
1622 return new SfxViewFrameItem( pFrame);
1625 void SfxViewFrame::SetViewShell_Impl( SfxViewShell *pVSh )
1627 /* [Description]
1629 Internal Method to set the current <SfxViewShell> Instance,
1630 that is active int this SfxViewFrame at the moment.
1634 SfxShell::SetViewShell_Impl( pVSh );
1636 // Hack: InPlaceMode
1637 if ( pVSh )
1638 pImp->bResizeInToOut = false;
1642 /* [Description]
1644 The ParentViewFrame of the Containers ViewFrame in the internal InPlace
1647 //TODO/LATER: is it still necessary? is there a replacement for GetParentViewFrame_Impl?
1648 SfxViewFrame* SfxViewFrame::GetParentViewFrame_Impl() const
1650 return NULL;
1654 void SfxViewFrame::ForceOuterResize_Impl(bool bOn)
1656 if ( !pImp->bDontOverwriteResizeInToOut )
1657 pImp->bResizeInToOut = !bOn;
1661 bool SfxViewFrame::IsResizeInToOut_Impl() const
1663 return pImp->bResizeInToOut;
1667 void SfxViewFrame::GetDocNumber_Impl()
1669 DBG_ASSERT( GetObjectShell(), "No Document!" );
1670 GetObjectShell()->SetNamedVisibility_Impl();
1671 pImp->nDocViewNo = GetObjectShell()->GetNoSet_Impl().GetFreeIndex()+1;
1676 void SfxViewFrame::Enable( bool bEnable )
1678 if ( bEnable != pImp->bEnabled )
1680 pImp->bEnabled = bEnable;
1682 // e.g. InPlace-Frames have a parent...
1683 SfxViewFrame *pParent = GetParentViewFrame_Impl();
1684 if ( pParent )
1686 pParent->Enable( bEnable );
1688 else
1690 vcl::Window *pWindow = &GetFrame().GetTopFrame().GetWindow();
1691 if ( !bEnable )
1692 pImp->bWindowWasEnabled = pWindow->IsInputEnabled();
1693 if ( !bEnable || pImp->bWindowWasEnabled )
1694 pWindow->EnableInput( bEnable, true );
1697 // cursor and focus
1698 SfxViewShell* pViewSh = GetViewShell();
1699 if ( bEnable )
1701 // show cursor
1702 if ( pViewSh )
1703 pViewSh->ShowCursor();
1705 else
1707 // hide cursor
1708 if ( pViewSh )
1709 pViewSh->ShowCursor(false);
1715 void SfxViewFrame::Show()
1717 /* [Description]
1719 This method makes the Frame-Window visible and before transmitts the
1720 window name. In addition, the document is held. In general one can never
1721 show the window directly!
1725 // First lock the objectShell so that UpdateTitle() is valid:
1726 // IsVisible() == true (:#)
1727 if ( xObjSh.Is() )
1729 xObjSh->GetMedium()->GetItemSet()->ClearItem( SID_HIDDEN );
1730 if ( !pImp->bObjLocked )
1731 LockObjectShell_Impl( true );
1733 // Adjust Doc-Shell title number, get unique view-no
1734 if ( 0 == pImp->nDocViewNo )
1736 GetDocNumber_Impl();
1737 UpdateTitle();
1740 else
1741 UpdateTitle();
1743 // Display Frame-window, but only if the ViewFrame has no window of its
1744 // own or if it does not contain a Component
1745 GetWindow().Show();
1746 GetFrame().GetWindow().Show();
1750 bool SfxViewFrame::IsVisible() const
1752 return pImp->bObjLocked;
1756 void SfxViewFrame::LockObjectShell_Impl( bool bLock )
1758 DBG_ASSERT( pImp->bObjLocked != bLock, "Wrong Locked status!" );
1760 DBG_ASSERT( GetObjectShell(), "No Document!" );
1761 GetObjectShell()->OwnerLock(bLock);
1762 pImp->bObjLocked = bLock;
1766 void SfxViewFrame::MakeActive_Impl( bool bGrabFocus )
1768 if ( GetViewShell() && !GetFrame().IsClosing_Impl() )
1770 if ( IsVisible() )
1772 if ( GetViewShell() )
1774 bool bPreview = false;
1775 if ( GetObjectShell()->IsPreview() )
1777 bPreview = true;
1779 else
1781 SfxViewFrame* pParent = GetParentViewFrame();
1782 if ( pParent )
1783 pParent->SetActiveChildFrame_Impl( this );
1786 SfxViewFrame* pCurrent = SfxViewFrame::Current();
1787 css::uno::Reference< css::frame::XFrame > xFrame = GetFrame().GetFrameInterface();
1788 if ( !bPreview )
1790 SetViewFrame( this );
1791 GetBindings().SetActiveFrame( css::uno::Reference< css::frame::XFrame >() );
1792 uno::Reference< frame::XFramesSupplier > xSupp( xFrame, uno::UNO_QUERY );
1793 if ( xSupp.is() )
1794 xSupp->setActiveFrame( uno::Reference < frame::XFrame >() );
1796 css::uno::Reference< css::awt::XWindow > xContainerWindow = xFrame->getContainerWindow();
1797 vcl::Window* pWindow = VCLUnoHelper::GetWindow(xContainerWindow);
1798 if (pWindow && pWindow->HasChildPathFocus() && bGrabFocus)
1800 SfxInPlaceClient *pCli = GetViewShell()->GetUIActiveClient();
1801 if ( ( !pCli || !pCli->IsObjectUIActive() ) &&
1802 ( !pCurrent || pCurrent->GetParentViewFrame_Impl() != this ) )
1803 GetFrame().GrabFocusOnComponent_Impl();
1806 else
1808 GetBindings().SetDispatcher( GetDispatcher() );
1809 GetBindings().SetActiveFrame( ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > () );
1810 GetDispatcher()->Update_Impl( false );
1819 void SfxViewFrame::SetQuietMode_Impl( bool bOn )
1821 GetDispatcher()->SetQuietMode_Impl( bOn );
1826 SfxObjectShell* SfxViewFrame::GetObjectShell()
1828 return xObjSh;
1831 const Size& SfxViewFrame::GetMargin_Impl() const
1833 return pImp->aMargin;
1836 void SfxViewFrame::SetActiveChildFrame_Impl( SfxViewFrame *pViewFrame )
1838 if ( pViewFrame != pImp->pActiveChild )
1840 pImp->pActiveChild = pViewFrame;
1842 Reference< XFramesSupplier > xFrame( GetFrame().GetFrameInterface(), UNO_QUERY );
1843 Reference< XFrame > xActive;
1844 if ( pViewFrame )
1845 xActive = pViewFrame->GetFrame().GetFrameInterface();
1847 if ( xFrame.is() ) // xFrame can be NULL
1848 xFrame->setActiveFrame( xActive );
1852 SfxViewFrame* SfxViewFrame::GetActiveChildFrame_Impl() const
1854 SfxViewFrame *pViewFrame = pImp->pActiveChild;
1855 return pViewFrame;
1859 SfxViewFrame* SfxViewFrame::LoadViewIntoFrame_Impl_NoThrow( const SfxObjectShell& i_rDoc, const Reference< XFrame >& i_rFrame,
1860 const sal_uInt16 i_nViewId, const bool i_bHidden )
1862 Reference< XFrame > xFrame( i_rFrame );
1863 bool bOwnFrame = false;
1864 SfxViewShell* pSuccessView = NULL;
1867 if ( !xFrame.is() )
1869 Reference < XDesktop2 > xDesktop = Desktop::create( ::comphelper::getProcessComponentContext() );
1871 if ( !i_bHidden )
1875 // if there is a backing component, use it
1876 ::framework::FrameListAnalyzer aAnalyzer( xDesktop, Reference< XFrame >(), ::framework::FrameListAnalyzer::E_BACKINGCOMPONENT );
1878 if ( aAnalyzer.m_xBackingComponent.is() )
1879 xFrame = aAnalyzer.m_xBackingComponent;
1881 catch( uno::Exception& )
1885 if ( !xFrame.is() )
1886 xFrame.set( xDesktop->findFrame( "_blank", 0 ), UNO_SET_THROW );
1888 bOwnFrame = true;
1891 pSuccessView = LoadViewIntoFrame_Impl(
1892 i_rDoc,
1893 xFrame,
1894 Sequence< PropertyValue >(), // means "reuse existing model's args"
1895 i_nViewId,
1896 i_bHidden
1899 if ( bOwnFrame && !i_bHidden )
1901 // ensure the frame/window is visible
1902 Reference< XWindow > xContainerWindow( xFrame->getContainerWindow(), UNO_SET_THROW );
1903 xContainerWindow->setVisible( true );
1906 catch( const Exception& )
1908 DBG_UNHANDLED_EXCEPTION();
1911 if ( pSuccessView )
1912 return pSuccessView->GetViewFrame();
1914 if ( bOwnFrame )
1918 xFrame->dispose();
1920 catch( const Exception& )
1922 DBG_UNHANDLED_EXCEPTION();
1926 return NULL;
1930 SfxViewShell* SfxViewFrame::LoadViewIntoFrame_Impl( const SfxObjectShell& i_rDoc, const Reference< XFrame >& i_rFrame,
1931 const Sequence< PropertyValue >& i_rLoadArgs, const sal_uInt16 i_nViewId,
1932 const bool i_bHidden )
1934 Reference< XModel > xDocument( i_rDoc.GetModel(), UNO_SET_THROW );
1936 ::comphelper::NamedValueCollection aTransformLoadArgs( i_rLoadArgs.getLength() ? i_rLoadArgs : xDocument->getArgs() );
1937 aTransformLoadArgs.put( "Model", xDocument );
1938 if ( i_nViewId )
1939 aTransformLoadArgs.put( "ViewId", sal_Int16( i_nViewId ) );
1940 if ( i_bHidden )
1941 aTransformLoadArgs.put( "Hidden", i_bHidden );
1942 else
1943 aTransformLoadArgs.remove( "Hidden" );
1945 OUString sURL( "private:object" );
1946 if ( sURL.isEmpty() )
1947 sURL = i_rDoc.GetFactory().GetFactoryURL();
1949 Reference< XComponentLoader > xLoader( i_rFrame, UNO_QUERY_THROW );
1950 xLoader->loadComponentFromURL( sURL, OUString("_self"), 0,
1951 aTransformLoadArgs.getPropertyValues() );
1953 SfxViewShell* pViewShell = SfxViewShell::Get( i_rFrame->getController() );
1954 ENSURE_OR_THROW( pViewShell,
1955 "SfxViewFrame::LoadViewIntoFrame_Impl: loading an SFX doc into a frame resulted in a non-SFX view - quite impossible" );
1956 return pViewShell;
1961 SfxViewFrame* SfxViewFrame::LoadHiddenDocument( SfxObjectShell& i_rDoc, const sal_uInt16 i_nViewId )
1963 return LoadViewIntoFrame_Impl_NoThrow( i_rDoc, Reference< XFrame >(), i_nViewId, true );
1968 SfxViewFrame* SfxViewFrame::LoadDocument( SfxObjectShell& i_rDoc, const sal_uInt16 i_nViewId )
1970 return LoadViewIntoFrame_Impl_NoThrow( i_rDoc, Reference< XFrame >(), i_nViewId, false );
1975 SfxViewFrame* SfxViewFrame::LoadDocumentIntoFrame( SfxObjectShell& i_rDoc, const Reference< XFrame >& i_rTargetFrame, const sal_uInt16 i_nViewId )
1977 return LoadViewIntoFrame_Impl_NoThrow( i_rDoc, i_rTargetFrame, i_nViewId, false );
1982 SfxViewFrame* SfxViewFrame::LoadDocumentIntoFrame( SfxObjectShell& i_rDoc, const SfxFrameItem* i_pFrameItem, const sal_uInt16 i_nViewId )
1984 return LoadViewIntoFrame_Impl_NoThrow( i_rDoc, i_pFrameItem && i_pFrameItem->GetFrame() ? i_pFrameItem->GetFrame()->GetFrameInterface() : NULL, i_nViewId, false );
1988 SfxViewFrame* SfxViewFrame::DisplayNewDocument( SfxObjectShell& i_rDoc, const SfxRequest& i_rCreateDocRequest, const sal_uInt16 i_nViewId )
1990 SFX_REQUEST_ARG( i_rCreateDocRequest, pFrameItem, SfxUnoFrameItem, SID_FILLFRAME, false );
1991 SFX_REQUEST_ARG( i_rCreateDocRequest, pHiddenItem, SfxBoolItem, SID_HIDDEN, false );
1993 return LoadViewIntoFrame_Impl_NoThrow(
1994 i_rDoc,
1995 pFrameItem ? pFrameItem->GetFrame() : NULL,
1996 i_nViewId,
1997 pHiddenItem && pHiddenItem->GetValue()
2003 SfxViewFrame* SfxViewFrame::Get( const Reference< XController>& i_rController, const SfxObjectShell* i_pDoc )
2005 if ( !i_rController.is() )
2006 return NULL;
2008 const SfxObjectShell* pDoc = i_pDoc;
2009 if ( !pDoc )
2011 Reference< XModel > xDocument( i_rController->getModel() );
2012 for ( pDoc = SfxObjectShell::GetFirst( 0, false );
2013 pDoc;
2014 pDoc = SfxObjectShell::GetNext( *pDoc, 0, false )
2017 if ( pDoc->GetModel() == xDocument )
2018 break;
2022 SfxViewFrame* pViewFrame = NULL;
2023 for ( pViewFrame = SfxViewFrame::GetFirst( pDoc, false );
2024 pViewFrame;
2025 pViewFrame = SfxViewFrame::GetNext( *pViewFrame, pDoc, false )
2028 if ( pViewFrame->GetViewShell()->GetController() == i_rController )
2029 break;
2032 return pViewFrame;
2037 void SfxViewFrame::SaveCurrentViewData_Impl( const sal_uInt16 i_nNewViewId )
2039 SfxViewShell* pCurrentShell = GetViewShell();
2040 ENSURE_OR_RETURN_VOID( pCurrentShell != NULL, "SfxViewFrame::SaveCurrentViewData_Impl: no current view shell -> no current view data!" );
2042 // determine the logical (API) view name
2043 const SfxObjectFactory& rDocFactory( pCurrentShell->GetObjectShell()->GetFactory() );
2044 const sal_uInt16 nCurViewNo = rDocFactory.GetViewNo_Impl( GetCurViewId(), 0 );
2045 const OUString sCurrentViewName = rDocFactory.GetViewFactory( nCurViewNo ).GetAPIViewName();
2046 const sal_uInt16 nNewViewNo = rDocFactory.GetViewNo_Impl( i_nNewViewId, 0 );
2047 const OUString sNewViewName = rDocFactory.GetViewFactory( nNewViewNo ).GetAPIViewName();
2048 if ( sCurrentViewName.isEmpty() || sNewViewName.isEmpty() )
2050 // can't say anything about the view, the respective application did not yet migrate its code to
2051 // named view factories => bail out
2052 OSL_FAIL( "SfxViewFrame::SaveCurrentViewData_Impl: views without API names? Shouldn't happen anymore?" );
2053 return;
2055 OSL_ENSURE( sNewViewName != sCurrentViewName, "SfxViewFrame::SaveCurrentViewData_Impl: suspicious: new and old view name are identical!" );
2057 // save the view data only when we're moving from a non-print-preview to the print-preview view
2058 if ( sNewViewName != "PrintPreview" )
2059 return;
2061 // retrieve the view data from the view
2062 Sequence< PropertyValue > aViewData;
2063 pCurrentShell->WriteUserDataSequence( aViewData );
2067 // retrieve view data (for *all* views) from the model
2068 const Reference< XController > xController( pCurrentShell->GetController(), UNO_SET_THROW );
2069 const Reference< XViewDataSupplier > xViewDataSupplier( xController->getModel(), UNO_QUERY_THROW );
2070 const Reference< XIndexContainer > xViewData( xViewDataSupplier->getViewData(), UNO_QUERY_THROW );
2072 // look up the one view data item which corresponds to our current view, and remove it
2073 const sal_Int32 nCount = xViewData->getCount();
2074 for ( sal_Int32 i=0; i<nCount; ++i )
2076 const ::comphelper::NamedValueCollection aCurViewData( xViewData->getByIndex(i) );
2077 OUString sViewId( aCurViewData.getOrDefault( "ViewId", OUString() ) );
2078 if ( sViewId.isEmpty() )
2079 continue;
2081 const SfxViewFactory* pViewFactory = rDocFactory.GetViewFactoryByViewName( sViewId );
2082 if ( pViewFactory == NULL )
2083 continue;
2085 if ( pViewFactory->GetOrdinal() == GetCurViewId() )
2087 xViewData->removeByIndex(i);
2088 break;
2092 // then replace it with the most recent view data we just obtained
2093 xViewData->insertByIndex( 0, makeAny( aViewData ) );
2095 catch( const Exception& )
2097 DBG_UNHANDLED_EXCEPTION();
2103 bool SfxViewFrame::SwitchToViewShell_Impl
2105 sal_uInt16 nViewIdOrNo, /* > 0
2106 Registration-Id of the View, to which the
2107 the method should switch, for example the one
2108 that will be created.
2110 == 0
2111 First use the Default view. */
2113 bool bIsIndex /* true
2114 'nViewIdOrNo' is no Registration-Id instead
2115 an Index of <SfxViewFrame> in <SfxObjectShell>.
2119 /* [Description]
2121 Internal Method for switching to another <SfxViewShell> subclass,
2122 which should be created in this SfxMDIFrame. If no SfxViewShell exist
2123 in this SfxMDIFrame, then one will first be created.
2126 [Return Value]
2128 bool true
2129 requested SfxViewShell was created and a
2130 possibly existing one deleted
2132 false
2133 SfxViewShell requested could not be created,
2134 the existing SfxViewShell thus continue to exist
2140 ENSURE_OR_THROW( GetObjectShell() != NULL, "not possible without a document" );
2142 // if we already have a view shell, remove it
2143 SfxViewShell* pOldSh = GetViewShell();
2144 OSL_PRECOND( pOldSh, "SfxViewFrame::SwitchToViewShell_Impl: that's called *switch* (not for *initial-load*) for a reason" );
2145 if ( pOldSh )
2147 // ask whether it can be closed
2148 if ( !pOldSh->PrepareClose( true ) )
2149 return false;
2151 // remove sub shells from Dispatcher before switching to new ViewShell
2152 PopShellAndSubShells_Impl( *pOldSh );
2155 GetBindings().ENTERREGISTRATIONS();
2156 LockAdjustPosSizePixel();
2158 // ID of the new view
2159 SfxObjectFactory& rDocFact = GetObjectShell()->GetFactory();
2160 const sal_uInt16 nViewId = ( bIsIndex || !nViewIdOrNo ) ? rDocFact.GetViewFactory( nViewIdOrNo ).GetOrdinal() : nViewIdOrNo;
2162 // save the view data of the old view, so it can be restored later on (when needed)
2163 SaveCurrentViewData_Impl( nViewId );
2165 // create and load new ViewShell
2166 SfxViewShell* pNewSh = LoadViewIntoFrame_Impl(
2167 *GetObjectShell(),
2168 GetFrame().GetFrameInterface(),
2169 Sequence< PropertyValue >(), // means "reuse existing model's args"
2170 nViewId,
2171 false
2174 // allow resize events to be processed
2175 UnlockAdjustPosSizePixel();
2177 if ( GetWindow().IsReallyVisible() )
2178 DoAdjustPosSizePixel( pNewSh, Point(), GetWindow().GetOutputSizePixel() );
2180 GetBindings().LEAVEREGISTRATIONS();
2181 delete pOldSh;
2183 catch ( const com::sun::star::uno::Exception& )
2185 // the SfxCode is not able to cope with exceptions thrown while creating views
2186 // the code will crash in the stack unwinding procedure, so we shouldn't let exceptions go through here
2187 DBG_UNHANDLED_EXCEPTION();
2188 return false;
2191 DBG_ASSERT( SfxGetpApp()->GetViewFrames_Impl().size() == SfxGetpApp()->GetViewShells_Impl().size(), "Inconsistent view arrays!" );
2192 return true;
2196 void SfxViewFrame::SetCurViewId_Impl( const sal_uInt16 i_nID )
2198 pImp->nCurViewId = i_nID;
2202 sal_uInt16 SfxViewFrame::GetCurViewId() const
2204 return pImp->nCurViewId;
2208 void SfxViewFrame::ExecView_Impl
2210 SfxRequest& rReq // The executable <SfxRequest>
2213 /* [Description]
2215 Internal method to run the slot for the <SfxShell> Subclass in the
2216 SfxViewFrame <SVIDL> described slots.
2221 // If the Shells are just being replaced...
2222 if ( !GetObjectShell() || !GetViewShell() )
2223 return;
2225 switch ( rReq.GetSlot() )
2227 case SID_TERMINATE_INPLACEACTIVATION :
2229 SfxInPlaceClient* pClient = GetViewShell()->GetUIActiveClient();
2230 if ( pClient )
2231 pClient->DeactivateObject();
2232 break;
2235 case SID_VIEWSHELL:
2237 const SfxPoolItem *pItem = 0;
2238 if ( rReq.GetArgs()
2239 && SfxItemState::SET == rReq.GetArgs()->GetItemState( SID_VIEWSHELL, false, &pItem )
2242 const sal_uInt16 nViewId = static_cast< const SfxUInt16Item* >( pItem )->GetValue();
2243 bool bSuccess = SwitchToViewShell_Impl( nViewId );
2244 rReq.SetReturnValue( SfxBoolItem( 0, bSuccess ) );
2246 break;
2249 case SID_VIEWSHELL0:
2250 case SID_VIEWSHELL1:
2251 case SID_VIEWSHELL2:
2252 case SID_VIEWSHELL3:
2253 case SID_VIEWSHELL4:
2255 const sal_uInt16 nViewNo = rReq.GetSlot() - SID_VIEWSHELL0;
2256 bool bSuccess = SwitchToViewShell_Impl( nViewNo, true );
2257 rReq.SetReturnValue( SfxBoolItem( 0, bSuccess ) );
2258 break;
2261 case SID_NEWWINDOW:
2263 // Hack. at the moment a virtual Function
2264 if ( !GetViewShell()->NewWindowAllowed() )
2266 OSL_FAIL( "You should have disabled the 'Window/New Window' slot!" );
2267 return;
2270 // Get ViewData of FrameSets recursivly.
2271 GetFrame().GetViewData_Impl();
2272 SfxMedium* pMed = GetObjectShell()->GetMedium();
2274 // do not open the new window hidden
2275 pMed->GetItemSet()->ClearItem( SID_HIDDEN );
2277 // the view ID (optional arg. TODO: this is currently not supported in the slot definition ...)
2278 SFX_REQUEST_ARG( rReq, pViewIdItem, SfxUInt16Item, SID_VIEW_ID, false );
2279 const sal_uInt16 nViewId = pViewIdItem ? pViewIdItem->GetValue() : GetCurViewId();
2281 Reference < XFrame > xFrame;
2282 // the frame (optional arg. TODO: this is currently not supported in the slot definition ...)
2283 SFX_REQUEST_ARG( rReq, pFrameItem, SfxUnoFrameItem, SID_FILLFRAME, false );
2284 if ( pFrameItem )
2285 xFrame = pFrameItem->GetFrame();
2287 LoadViewIntoFrame_Impl_NoThrow( *GetObjectShell(), xFrame, nViewId, false );
2289 rReq.Done();
2290 break;
2293 case SID_OBJECT:
2295 SFX_REQUEST_ARG( rReq, pItem, SfxInt16Item, SID_OBJECT, false );
2297 SfxViewShell *pViewShell = GetViewShell();
2298 if ( pViewShell && pItem )
2300 pViewShell->DoVerb( pItem->GetValue() );
2301 rReq.Done();
2302 break;;
2309 /* TODO as96863:
2310 This method try to collect information about the count of currently open documents.
2311 But the algorithm is implemented very simple ...
2312 E.g. hidden documents should be ignored here ... but they are counted.
2313 TODO: export special helper "framework::FrameListAnalyzer" within the framework module
2314 and use it here.
2316 bool impl_maxOpenDocCountReached()
2318 css::uno::Reference< css::uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
2319 boost::optional<sal_Int32> x(officecfg::Office::Common::Misc::MaxOpenDocuments::get(xContext));
2320 // NIL means: count of allowed documents = infinite !
2321 if (!x)
2322 return false;
2323 sal_Int32 nMaxDocs(x.get());
2324 sal_Int32 nOpenDocs = 0;
2326 css::uno::Reference< css::frame::XDesktop2 > xDesktop = css::frame::Desktop::create(xContext);
2327 css::uno::Reference< css::container::XIndexAccess > xCont(xDesktop->getFrames(), css::uno::UNO_QUERY_THROW);
2329 sal_Int32 c = xCont->getCount();
2330 sal_Int32 i = 0;
2332 for (i=0; i<c; ++i)
2336 css::uno::Reference< css::frame::XFrame > xFrame;
2337 xCont->getByIndex(i) >>= xFrame;
2338 if ( ! xFrame.is())
2339 continue;
2341 // a) do not count the help window
2342 if ( xFrame->getName() == "OFFICE_HELP_TASK" )
2343 continue;
2345 // b) count all other frames
2346 ++nOpenDocs;
2348 catch(const css::uno::Exception&)
2349 // A IndexOutOfBoundException can happen in multithreaded
2350 // environments, where any other thread can change this
2351 // container !
2352 { continue; }
2355 return (nOpenDocs >= nMaxDocs);
2359 void SfxViewFrame::StateView_Impl
2361 SfxItemSet& rSet /* empty <SfxItemSet> with <Which-Ranges>,
2362 which describes the Slot Ids */
2365 /* [Description]
2367 This internal methode returns in 'rSet' the Status for the <SfxShell>
2368 Subclass SfxViewFrame in the <SVIDL> described <Slots>.
2370 Thus exactly those Slots-IDs that are recognized as being invalid by Sfx
2371 are included as Which-ranges in 'rSet'. If there exists a mapping for
2372 single slot-IDs of the <SfxItemPool> set in the shell, then the respective
2373 Which-IDs are used so that items can be replaced directly with a working
2374 Core::sun::com::star::script::Engine of the Which-IDs if possible. .
2379 SfxObjectShell *pDocSh = GetObjectShell();
2381 if ( !pDocSh )
2382 // I'm just on reload and am yielding myself ...
2383 return;
2385 const sal_uInt16 *pRanges = rSet.GetRanges();
2386 assert(pRanges && "Set with no Range");
2387 while ( *pRanges )
2389 for ( sal_uInt16 nWhich = *pRanges++; nWhich <= *pRanges; ++nWhich )
2391 switch(nWhich)
2393 case SID_VIEWSHELL:
2395 rSet.Put( SfxUInt16Item( nWhich, pImp->nCurViewId ) );
2396 break;
2399 case SID_VIEWSHELL0:
2400 case SID_VIEWSHELL1:
2401 case SID_VIEWSHELL2:
2402 case SID_VIEWSHELL3:
2403 case SID_VIEWSHELL4:
2405 sal_uInt16 nViewNo = nWhich - SID_VIEWSHELL0;
2406 if ( GetObjectShell()->GetFactory().GetViewFactoryCount() >
2407 nViewNo && !GetObjectShell()->IsInPlaceActive() )
2409 SfxViewFactory &rViewFactory =
2410 GetObjectShell()->GetFactory().GetViewFactory(nViewNo);
2411 rSet.Put( SfxBoolItem(
2412 nWhich, pImp->nCurViewId == rViewFactory.GetOrdinal() ) );
2414 else
2415 rSet.DisableItem( nWhich );
2416 break;
2419 case SID_NEWWINDOW:
2421 if ( !GetViewShell()->NewWindowAllowed()
2422 || impl_maxOpenDocCountReached()
2424 rSet.DisableItem( nWhich );
2425 break;
2433 void SfxViewFrame::ToTop()
2435 GetFrame().Appear();
2439 SfxViewFrame* SfxViewFrame::GetParentViewFrame() const
2440 /* [Description]
2442 The ParentViewFrame is the ViewFrame of the ParentFrames.
2445 SfxFrame *pFrame = GetFrame().GetParentFrame();
2446 return pFrame ? pFrame->GetCurrentViewFrame() : NULL;
2450 SfxFrame& SfxViewFrame::GetFrame() const
2451 /* [Description]
2453 GetFrame returns the Frame, in which the ViewFrame is located.
2456 return pImp->rFrame;
2460 SfxViewFrame* SfxViewFrame::GetTopViewFrame() const
2462 return GetFrame().GetTopFrame().GetCurrentViewFrame();
2465 vcl::Window& SfxViewFrame::GetWindow() const
2467 return pImp->pWindow ? *pImp->pWindow : GetFrame().GetWindow();
2470 bool SfxViewFrame::DoClose()
2472 return GetFrame().DoClose();
2475 OUString SfxViewFrame::GetActualPresentationURL_Impl() const
2477 if ( xObjSh.Is() )
2478 return xObjSh->GetMedium()->GetName();
2479 return OUString();
2482 void SfxViewFrame::SetModalMode( bool bModal )
2484 pImp->bModal = bModal;
2485 if ( xObjSh.Is() )
2487 for ( SfxViewFrame* pFrame = SfxViewFrame::GetFirst( xObjSh );
2488 !bModal && pFrame; pFrame = SfxViewFrame::GetNext( *pFrame, xObjSh ) )
2489 bModal = pFrame->pImp->bModal;
2490 xObjSh->SetModalMode_Impl( bModal );
2494 bool SfxViewFrame::IsInModalMode() const
2496 return pImp->bModal || GetFrame().GetWindow().IsInModalMode();
2499 void SfxViewFrame::Resize( bool bForce )
2501 Size aSize = GetWindow().GetOutputSizePixel();
2502 if ( bForce || aSize != pImp->aSize )
2504 pImp->aSize = aSize;
2505 SfxViewShell *pShell = GetViewShell();
2506 if ( pShell )
2508 if ( GetFrame().IsInPlace() )
2510 Point aPoint = GetWindow().GetPosPixel();
2511 DoAdjustPosSizePixel( pShell, aPoint, aSize );
2513 else
2515 DoAdjustPosSizePixel( pShell, Point(), aSize );
2521 #define LINE_SEP 0x0A
2523 void CutLines( OUString& rStr, sal_Int32 nStartLine, sal_Int32 nLines, bool bEraseTrailingEmptyLines )
2525 sal_Int32 nStartPos = 0;
2526 sal_Int32 nLine = 0;
2527 while ( nLine < nStartLine )
2529 nStartPos = rStr.indexOf( LINE_SEP, nStartPos );
2530 if( nStartPos == -1 )
2531 break;
2532 nStartPos++; // not the \n.
2533 nLine++;
2536 DBG_ASSERTWARNING( nStartPos != -1, "CutLines: Start row not found!" );
2538 if ( nStartPos != -1 )
2540 sal_Int32 nEndPos = nStartPos;
2541 for ( sal_Int32 i = 0; i < nLines; i++ )
2542 nEndPos = rStr.indexOf( LINE_SEP, nEndPos+1 );
2544 if ( nEndPos == -1 ) // Can happen at the last row.
2545 nEndPos = rStr.getLength();
2546 else
2547 nEndPos++;
2549 OUString aEndStr = rStr.copy( nEndPos );
2550 rStr = rStr.copy( 0, nStartPos );
2551 rStr += aEndStr;
2553 if ( bEraseTrailingEmptyLines && nStartPos != -1 )
2555 sal_Int32 n = nStartPos;
2556 sal_Int32 nLen = rStr.getLength();
2557 while ( ( n < nLen ) && ( rStr[ n ] == LINE_SEP ) )
2558 n++;
2560 if ( n > nStartPos )
2562 OUString aEndStr = rStr.copy( n );
2563 rStr = rStr.copy( 0, nStartPos );
2564 rStr += aEndStr;
2570 add new recorded dispatch macro script into the application global basic
2571 lib container. It generates a new unique id for it and insert the macro
2572 by using this number as name for the modul
2574 void SfxViewFrame::AddDispatchMacroToBasic_Impl( const OUString& sMacro )
2576 #if !HAVE_FEATURE_SCRIPTING
2577 (void) sMacro;
2578 #else
2579 if ( sMacro.isEmpty() )
2580 return;
2582 SfxApplication* pSfxApp = SfxGetpApp();
2583 SfxRequest aReq( SID_BASICCHOOSER, SfxCallMode::SYNCHRON, pSfxApp->GetPool() );
2584 aReq.AppendItem( SfxBoolItem(SID_RECORDMACRO,true) );
2585 const SfxPoolItem* pRet = SfxGetpApp()->ExecuteSlot( aReq );
2586 OUString aScriptURL;
2587 if ( pRet )
2588 aScriptURL = static_cast<const SfxStringItem*>(pRet)->GetValue();
2589 if ( !aScriptURL.isEmpty() )
2591 // parse scriptURL
2592 OUString aLibName;
2593 OUString aModuleName;
2594 OUString aMacroName;
2595 OUString aLocation;
2596 Reference< XComponentContext > xContext = ::comphelper::getProcessComponentContext();
2597 Reference< com::sun::star::uri::XUriReferenceFactory > xFactory =
2598 com::sun::star::uri::UriReferenceFactory::create( xContext );
2599 Reference< com::sun::star::uri::XVndSunStarScriptUrl > xUrl( xFactory->parse( aScriptURL ), UNO_QUERY );
2600 if ( xUrl.is() )
2602 // get name
2603 OUString aName = xUrl->getName();
2604 sal_Unicode cTok = '.';
2605 sal_Int32 nIndex = 0;
2606 aLibName = aName.getToken( 0, cTok, nIndex );
2607 if ( nIndex != -1 )
2608 aModuleName = aName.getToken( 0, cTok, nIndex );
2609 if ( nIndex != -1 )
2610 aMacroName = aName.getToken( 0, cTok, nIndex );
2612 // get location
2613 OUString aLocKey("location");
2614 if ( xUrl->hasParameter( aLocKey ) )
2615 aLocation = xUrl->getParameter( aLocKey );
2618 BasicManager* pBasMgr = 0;
2619 if ( aLocation.equalsIgnoreAsciiCase( "application" ) )
2621 // application basic
2622 pBasMgr = SfxApplication::GetBasicManager();
2624 else if ( aLocation.equalsIgnoreAsciiCase( "document" ) )
2626 pBasMgr = GetObjectShell()->GetBasicManager();
2629 OUString aOUSource;
2630 if ( pBasMgr)
2632 StarBASIC* pBasic = pBasMgr->GetLib( aLibName );
2633 if ( pBasic )
2635 SbModule* pModule = pBasic->FindModule( aModuleName );
2636 if ( pModule )
2638 SbMethod* pMethod = static_cast<SbMethod*>(pModule->GetMethods()->Find( aMacroName, SbxCLASS_METHOD ));
2639 aOUSource = pModule->GetSource32();
2640 sal_uInt16 nStart, nEnd;
2641 pMethod->GetLineRange( nStart, nEnd );
2642 sal_uIntPtr nlStart = nStart;
2643 sal_uIntPtr nlEnd = nEnd;
2644 CutLines( aOUSource, nlStart-1, nlEnd-nlStart+1, true );
2649 // open lib container and break operation if it couldn't be opened
2650 com::sun::star::uno::Reference< com::sun::star::script::XLibraryContainer > xLibCont;
2651 if ( aLocation.equalsIgnoreAsciiCase( "application" ) )
2653 xLibCont = SfxGetpApp()->GetBasicContainer();
2655 else if ( aLocation.equalsIgnoreAsciiCase( "document" ) )
2657 xLibCont = GetObjectShell()->GetBasicContainer();
2660 if(!xLibCont.is())
2662 SAL_WARN( "sfx.view", "couldn't get access to the basic lib container. Adding of macro isn't possible." );
2663 return;
2666 // get LibraryContainer
2667 com::sun::star::uno::Any aTemp;
2668 com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > xRoot(
2669 xLibCont,
2670 com::sun::star::uno::UNO_QUERY);
2672 OUString sLib( aLibName );
2673 com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > xLib;
2674 if(xRoot->hasByName(sLib))
2676 // library must be loaded
2677 aTemp = xRoot->getByName(sLib);
2678 xLibCont->loadLibrary(sLib);
2679 aTemp >>= xLib;
2681 else
2683 xLib = com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >(
2684 xLibCont->createLibrary(sLib),
2685 com::sun::star::uno::UNO_QUERY);
2688 // pack the macro as direct usable "sub" routine
2689 OUString sCode;
2690 OUStringBuffer sRoutine(10000);
2691 OUString sMacroName( aMacroName );
2692 bool bReplace = false;
2694 // get module
2695 OUString sModule( aModuleName );
2696 if(xLib->hasByName(sModule))
2698 if ( !aOUSource.isEmpty() )
2700 sRoutine.append( aOUSource );
2702 else
2704 aTemp = xLib->getByName(sModule);
2705 aTemp >>= sCode;
2706 sRoutine.append( sCode );
2709 bReplace = true;
2712 // append new method
2713 sRoutine.append( "\nsub " );
2714 sRoutine.append(sMacroName);
2715 sRoutine.append( "\n" );
2716 sRoutine.append(sMacro);
2717 sRoutine.append( "\nend sub\n" );
2719 // create the modul inside the library and insert the macro routine
2720 aTemp <<= sRoutine.makeStringAndClear();
2721 if ( bReplace )
2723 com::sun::star::uno::Reference< com::sun::star::container::XNameContainer > xModulCont(
2724 xLib,
2725 com::sun::star::uno::UNO_QUERY);
2726 xModulCont->replaceByName(sModule,aTemp);
2728 else
2730 com::sun::star::uno::Reference< com::sun::star::container::XNameContainer > xModulCont(
2731 xLib,
2732 com::sun::star::uno::UNO_QUERY);
2733 xModulCont->insertByName(sModule,aTemp);
2736 // #i17355# update the Basic IDE
2737 for ( SfxViewShell* pViewShell = SfxViewShell::GetFirst(); pViewShell; pViewShell = SfxViewShell::GetNext( *pViewShell ) )
2739 if ( pViewShell->GetName() == "BasicIDE" )
2741 SfxViewFrame* pViewFrame = pViewShell->GetViewFrame();
2742 SfxDispatcher* pDispat = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
2743 if ( pDispat )
2745 SfxMacroInfoItem aInfoItem( SID_BASICIDE_ARG_MACROINFO, pBasMgr, aLibName, aModuleName, OUString(), OUString() );
2746 pDispat->Execute( SID_BASICIDE_UPDATEMODULESOURCE, SfxCallMode::SYNCHRON, &aInfoItem, 0L );
2751 else
2753 // add code for "session only" macro
2755 #endif
2758 void SfxViewFrame::MiscExec_Impl( SfxRequest& rReq )
2760 switch ( rReq.GetSlot() )
2762 case SID_STOP_RECORDING :
2763 case SID_RECORDMACRO :
2765 // try to find any active recorder on this frame
2766 OUString sProperty("DispatchRecorderSupplier");
2767 com::sun::star::uno::Reference< com::sun::star::frame::XFrame > xFrame(
2768 GetFrame().GetFrameInterface(),
2769 com::sun::star::uno::UNO_QUERY);
2771 com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xSet(xFrame,com::sun::star::uno::UNO_QUERY);
2772 com::sun::star::uno::Any aProp = xSet->getPropertyValue(sProperty);
2773 com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorderSupplier > xSupplier;
2774 aProp >>= xSupplier;
2775 com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder > xRecorder;
2776 if (xSupplier.is())
2777 xRecorder = xSupplier->getDispatchRecorder();
2779 bool bIsRecording = xRecorder.is();
2780 SFX_REQUEST_ARG( rReq, pItem, SfxBoolItem, SID_RECORDMACRO, false);
2781 if ( pItem && pItem->GetValue() == bIsRecording )
2782 return;
2784 if ( xRecorder.is() )
2786 // disable active recording
2787 aProp <<= com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorderSupplier >();
2788 xSet->setPropertyValue(sProperty,aProp);
2790 SFX_REQUEST_ARG( rReq, pRecordItem, SfxBoolItem, FN_PARAM_1, false);
2791 if ( !pRecordItem || !pRecordItem->GetValue() )
2792 // insert script into basic library container of application
2793 AddDispatchMacroToBasic_Impl(xRecorder->getRecordedMacro());
2795 xRecorder->endRecording();
2796 xRecorder = NULL;
2797 GetBindings().SetRecorder_Impl( xRecorder );
2799 SetChildWindow( SID_RECORDING_FLOATWINDOW, false );
2800 if ( rReq.GetSlot() != SID_RECORDMACRO )
2801 GetBindings().Invalidate( SID_RECORDMACRO );
2803 else if ( rReq.GetSlot() == SID_RECORDMACRO )
2805 // enable recording
2806 com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > xContext(
2807 ::comphelper::getProcessComponentContext());
2809 xRecorder = com::sun::star::frame::DispatchRecorder::create( xContext );
2811 xSupplier = com::sun::star::frame::DispatchRecorderSupplier::create( xContext );
2813 xSupplier->setDispatchRecorder(xRecorder);
2814 xRecorder->startRecording(xFrame);
2815 aProp <<= xSupplier;
2816 xSet->setPropertyValue(sProperty,aProp);
2817 GetBindings().SetRecorder_Impl( xRecorder );
2818 SetChildWindow( SID_RECORDING_FLOATWINDOW, true );
2821 rReq.Done();
2822 break;
2825 case SID_TOGGLESTATUSBAR:
2827 com::sun::star::uno::Reference< com::sun::star::frame::XFrame > xFrame(
2828 GetFrame().GetFrameInterface(),
2829 com::sun::star::uno::UNO_QUERY);
2831 Reference< com::sun::star::beans::XPropertySet > xPropSet( xFrame, UNO_QUERY );
2832 Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
2833 if ( xPropSet.is() )
2837 Any aValue = xPropSet->getPropertyValue("LayoutManager");
2838 aValue >>= xLayoutManager;
2840 catch ( Exception& )
2845 if ( xLayoutManager.is() )
2847 OUString aStatusbarResString( "private:resource/statusbar/statusbar" );
2848 // Evaluate parameter.
2849 SFX_REQUEST_ARG(rReq, pShowItem, SfxBoolItem, rReq.GetSlot(), false);
2850 bool bShow( true );
2851 if ( !pShowItem )
2852 bShow = xLayoutManager->isElementVisible( aStatusbarResString );
2853 else
2854 bShow = pShowItem->GetValue();
2856 if ( bShow )
2858 xLayoutManager->createElement( aStatusbarResString );
2859 xLayoutManager->showElement( aStatusbarResString );
2861 else
2862 xLayoutManager->hideElement( aStatusbarResString );
2864 if ( !pShowItem )
2865 rReq.AppendItem( SfxBoolItem( SID_TOGGLESTATUSBAR, bShow ) );
2867 rReq.Done();
2868 break;
2871 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2872 case SID_WIN_FULLSCREEN:
2874 SFX_REQUEST_ARG(rReq, pItem, SfxBoolItem, rReq.GetSlot(), false);
2875 SfxViewFrame *pTop = GetTopViewFrame();
2876 if ( pTop )
2878 WorkWindow* pWork = static_cast<WorkWindow*>( pTop->GetFrame().GetTopWindow_Impl() );
2879 if ( pWork )
2881 com::sun::star::uno::Reference< com::sun::star::frame::XFrame > xFrame(
2882 GetFrame().GetFrameInterface(),
2883 com::sun::star::uno::UNO_QUERY);
2885 Reference< ::com::sun::star::beans::XPropertySet > xPropSet( xFrame, UNO_QUERY );
2886 Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
2887 if ( xPropSet.is() )
2891 Any aValue = xPropSet->getPropertyValue("LayoutManager");
2892 aValue >>= xLayoutManager;
2894 catch ( Exception& )
2899 bool bNewFullScreenMode = pItem ? pItem->GetValue() : !pWork->IsFullScreenMode();
2900 if ( bNewFullScreenMode != pWork->IsFullScreenMode() )
2902 Reference< ::com::sun::star::beans::XPropertySet > xLMPropSet( xLayoutManager, UNO_QUERY );
2903 if ( xLMPropSet.is() )
2907 xLMPropSet->setPropertyValue(
2908 OUString( "HideCurrentUI" ),
2909 makeAny( bNewFullScreenMode ));
2911 catch ( ::com::sun::star::beans::UnknownPropertyException& )
2915 pWork->ShowFullScreenMode( bNewFullScreenMode );
2916 pWork->SetMenuBarMode( bNewFullScreenMode ? MENUBAR_MODE_HIDE : MENUBAR_MODE_NORMAL );
2917 GetFrame().GetWorkWindow_Impl()->SetFullScreen_Impl( bNewFullScreenMode );
2918 if ( !pItem )
2919 rReq.AppendItem( SfxBoolItem( SID_WIN_FULLSCREEN, bNewFullScreenMode ) );
2920 rReq.Done();
2922 else
2923 rReq.Ignore();
2926 else
2927 rReq.Ignore();
2929 GetDispatcher()->Update_Impl( true );
2930 break;
2935 void SfxViewFrame::MiscState_Impl(SfxItemSet &rSet)
2937 const sal_uInt16 *pRanges = rSet.GetRanges();
2938 DBG_ASSERT(pRanges && *pRanges, "Set without range");
2939 while ( *pRanges )
2941 for(sal_uInt16 nWhich = *pRanges++; nWhich <= *pRanges; ++nWhich)
2943 switch(nWhich)
2945 case SID_CURRENT_URL:
2947 // Get the ContainerFrame, when internal InPlace.
2948 SfxViewFrame *pFrame = this;
2949 if ( pFrame->GetParentViewFrame_Impl() )
2950 pFrame = pFrame->GetParentViewFrame_Impl();
2951 rSet.Put( SfxStringItem( nWhich, pFrame->GetActualPresentationURL_Impl() ) );
2952 break;
2955 case SID_RECORDMACRO :
2957 SvtMiscOptions aMiscOptions;
2958 const char* pName = GetObjectShell()->GetFactory().GetShortName();
2959 if ( !aMiscOptions.IsMacroRecorderMode() ||
2960 ( strcmp(pName,"swriter") && strcmp(pName,"scalc") ) )
2962 rSet.DisableItem( nWhich );
2963 rSet.Put(SfxVisibilityItem(nWhich, false));
2964 break;
2967 OUString sProperty("DispatchRecorderSupplier");
2968 com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xSet(
2969 GetFrame().GetFrameInterface(),
2970 com::sun::star::uno::UNO_QUERY);
2972 com::sun::star::uno::Any aProp = xSet->getPropertyValue(sProperty);
2973 com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorderSupplier > xSupplier;
2974 if ( aProp >>= xSupplier )
2975 rSet.Put( SfxBoolItem( nWhich, xSupplier.is() ) );
2976 else
2977 rSet.DisableItem( nWhich );
2978 break;
2981 case SID_STOP_RECORDING :
2983 SvtMiscOptions aMiscOptions;
2984 const char* pName = GetObjectShell()->GetFactory().GetShortName();
2985 if ( !aMiscOptions.IsMacroRecorderMode() ||
2986 ( strcmp(pName,"swriter") && strcmp(pName,"scalc") ) )
2988 rSet.DisableItem( nWhich );
2989 break;
2992 OUString sProperty("DispatchRecorderSupplier");
2993 com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xSet(
2994 GetFrame().GetFrameInterface(),
2995 com::sun::star::uno::UNO_QUERY);
2997 com::sun::star::uno::Any aProp = xSet->getPropertyValue(sProperty);
2998 com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorderSupplier > xSupplier;
2999 if ( !(aProp >>= xSupplier) || !xSupplier.is() )
3000 rSet.DisableItem( nWhich );
3001 break;
3004 case SID_TOGGLESTATUSBAR:
3006 com::sun::star::uno::Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
3007 com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xSet(
3008 GetFrame().GetFrameInterface(),
3009 com::sun::star::uno::UNO_QUERY);
3010 com::sun::star::uno::Any aProp = xSet->getPropertyValue(
3011 OUString( "LayoutManager" ) );
3013 if ( !( aProp >>= xLayoutManager ))
3014 rSet.Put( SfxBoolItem( nWhich, false ));
3015 else
3017 OUString aStatusbarResString( "private:resource/statusbar/statusbar" );
3018 bool bShow = xLayoutManager->isElementVisible( aStatusbarResString );
3019 rSet.Put( SfxBoolItem( nWhich, bShow ));
3021 break;
3024 case SID_WIN_FULLSCREEN:
3026 SfxViewFrame* pTop = GetTopViewFrame();
3027 if ( pTop )
3029 WorkWindow* pWork = static_cast<WorkWindow*>( pTop->GetFrame().GetTopWindow_Impl() );
3030 if ( pWork )
3032 rSet.Put( SfxBoolItem( nWhich, pWork->IsFullScreenMode() ) );
3033 break;
3037 rSet.DisableItem( nWhich );
3038 break;
3041 case SID_FORMATMENUSTATE :
3043 OSL_FAIL("Outdated slot!");
3044 rSet.DisableItem( nWhich );
3045 break;
3048 default:
3049 break;
3053 ++pRanges;
3057 void SfxViewFrame::ChildWindowExecute( SfxRequest &rReq )
3059 /* [Description]
3061 This method can be included in the Execute method for the on- and off-
3062 switching of ChildWindows, to implement this and API-bindings.
3064 Simply include as 'ExecuteMethod' in the IDL.
3068 // Evaluate Parameter
3069 sal_uInt16 nSID = rReq.GetSlot();
3071 SFX_REQUEST_ARG(rReq, pShowItem, SfxBoolItem, nSID, false);
3072 if ( nSID == SID_VIEW_DATA_SOURCE_BROWSER )
3074 if (!SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::EModule::DATABASE))
3075 return;
3076 Reference < XFrame > xFrame = GetFrame().GetTopFrame().GetFrameInterface();
3077 Reference < XFrame > xBeamer( xFrame->findFrame( "_beamer", FrameSearchFlag::CHILDREN ) );
3078 bool bHasChild = xBeamer.is();
3079 bool bShow = pShowItem ? pShowItem->GetValue() : !bHasChild;
3080 if ( pShowItem )
3082 if( bShow == bHasChild )
3083 return;
3085 else
3086 rReq.AppendItem( SfxBoolItem( nSID, bShow ) );
3088 if ( !bShow )
3090 SetChildWindow( SID_BROWSER, false );
3092 else
3094 ::com::sun::star::util::URL aTargetURL;
3095 aTargetURL.Complete = ".component:DB/DataSourceBrowser";
3096 Reference < ::com::sun::star::util::XURLTransformer > xTrans(
3097 ::com::sun::star::util::URLTransformer::create(
3098 ::comphelper::getProcessComponentContext() ) );
3099 xTrans->parseStrict( aTargetURL );
3101 Reference < XDispatchProvider > xProv( xFrame, UNO_QUERY );
3102 Reference < ::com::sun::star::frame::XDispatch > xDisp;
3103 if ( xProv.is() )
3104 xDisp = xProv->queryDispatch( aTargetURL, OUString("_beamer"), 31 );
3105 if ( xDisp.is() )
3107 Sequence < ::com::sun::star::beans::PropertyValue > aArgs(1);
3108 ::com::sun::star::beans::PropertyValue* pArg = aArgs.getArray();
3109 pArg[0].Name = "Referer";
3110 pArg[0].Value <<= OUString("private:user");
3111 xDisp->dispatch( aTargetURL, aArgs );
3115 rReq.Done();
3116 return;
3118 if (nSID == SID_STYLE_DESIGNER)
3120 // First make sure that the sidebar is visible
3121 ShowChildWindow(SID_SIDEBAR);
3123 ::sfx2::sidebar::Sidebar::ShowPanel("StyleListPanel",
3124 GetFrame().GetFrameInterface());
3125 rReq.Done();
3126 return;
3129 bool bHasChild = HasChildWindow(nSID);
3130 bool bShow = pShowItem ? pShowItem->GetValue() : !bHasChild;
3131 GetDispatcher()->Update_Impl( true );
3133 // Perform action.
3134 if ( !pShowItem || bShow != bHasChild )
3135 ToggleChildWindow( nSID );
3137 GetBindings().Invalidate( nSID );
3139 // Record if possible.
3140 if ( nSID == SID_HYPERLINK_DIALOG || nSID == SID_SEARCH_DLG )
3142 rReq.Ignore();
3144 else
3146 rReq.AppendItem( SfxBoolItem( nSID, bShow ) );
3147 rReq.Done();
3153 void SfxViewFrame::ChildWindowState( SfxItemSet& rState )
3155 /* [Description]
3157 This method can be used in the state method for the on and off-state
3158 of child-windows, in order to implement this.
3160 Just register the IDL as 'StateMethod'.
3164 SfxWhichIter aIter( rState );
3165 for ( sal_uInt16 nSID = aIter.FirstWhich(); nSID; nSID = aIter.NextWhich() )
3167 if ( nSID == SID_VIEW_DATA_SOURCE_BROWSER )
3169 rState.Put( SfxBoolItem( nSID, HasChildWindow( SID_BROWSER ) ) );
3171 else if ( nSID == SID_HYPERLINK_DIALOG )
3173 const SfxPoolItem* pDummy = NULL;
3174 SfxItemState eState = GetDispatcher()->QueryState( SID_HYPERLINK_SETLINK, pDummy );
3175 if ( SfxItemState::DISABLED == eState )
3176 rState.DisableItem(nSID);
3177 else
3179 if ( KnowsChildWindow(nSID) )
3180 rState.Put( SfxBoolItem( nSID, HasChildWindow(nSID)) );
3181 else
3182 rState.DisableItem(nSID);
3185 else if ( nSID == SID_BROWSER )
3187 Reference < XFrame > xFrame = GetFrame().GetTopFrame().GetFrameInterface()->
3188 findFrame( "_beamer", FrameSearchFlag::CHILDREN );
3189 if ( !xFrame.is() )
3190 rState.DisableItem( nSID );
3191 else if ( KnowsChildWindow(nSID) )
3192 rState.Put( SfxBoolItem( nSID, HasChildWindow(nSID) ) );
3194 else if ( nSID == SID_TASKPANE )
3196 if ( !KnowsChildWindow( nSID ) )
3198 OSL_FAIL( "SID_TASKPANE state requested, but no task pane child window exists for this ID!" );
3199 rState.DisableItem( nSID );
3201 else if ( !moduleHasToolPanels( *pImp ) )
3203 rState.Put( SfxVisibilityItem( nSID, false ) );
3205 else
3207 rState.Put( SfxBoolItem( nSID, HasChildWindow( nSID ) ) );
3210 else if ( nSID == SID_SIDEBAR )
3212 if ( !KnowsChildWindow( nSID ) )
3214 OSL_ENSURE( false, "SID_TASKPANE state requested, but no task pane child window exists for this ID!" );
3215 rState.DisableItem( nSID );
3217 else
3219 rState.Put( SfxBoolItem( nSID, HasChildWindow( nSID ) ) );
3222 else if ( KnowsChildWindow(nSID) )
3223 rState.Put( SfxBoolItem( nSID, HasChildWindow(nSID) ) );
3224 else
3225 rState.DisableItem(nSID);
3230 SfxWorkWindow* SfxViewFrame::GetWorkWindow_Impl( sal_uInt16 /*nId*/ )
3232 SfxWorkWindow* pWork = 0;
3233 pWork = GetFrame().GetWorkWindow_Impl();
3234 return pWork;
3237 void SfxViewFrame::SetChildWindow(sal_uInt16 nId, bool bOn, bool bSetFocus )
3239 SfxWorkWindow* pWork = GetWorkWindow_Impl( nId );
3240 if ( pWork )
3241 pWork->SetChildWindow_Impl( nId, bOn, bSetFocus );
3246 void SfxViewFrame::ToggleChildWindow(sal_uInt16 nId)
3248 SfxWorkWindow* pWork = GetWorkWindow_Impl( nId );
3249 if ( pWork )
3250 pWork->ToggleChildWindow_Impl( nId, true );
3255 bool SfxViewFrame::HasChildWindow( sal_uInt16 nId )
3257 SfxWorkWindow* pWork = GetWorkWindow_Impl( nId );
3258 return pWork && pWork->HasChildWindow_Impl(nId);
3263 bool SfxViewFrame::KnowsChildWindow( sal_uInt16 nId )
3265 SfxWorkWindow* pWork = GetWorkWindow_Impl( nId );
3266 return pWork && pWork->KnowsChildWindow_Impl(nId);
3271 void SfxViewFrame::ShowChildWindow( sal_uInt16 nId, bool bVisible )
3273 SfxWorkWindow* pWork = GetWorkWindow_Impl( nId );
3274 if ( pWork )
3276 GetDispatcher()->Update_Impl(true);
3277 pWork->ShowChildWindow_Impl(nId, bVisible, true );
3283 SfxChildWindow* SfxViewFrame::GetChildWindow(sal_uInt16 nId)
3285 SfxWorkWindow* pWork = GetWorkWindow_Impl( nId );
3286 return pWork ? pWork->GetChildWindow_Impl(nId) : NULL;
3289 void SfxViewFrame::UpdateDocument_Impl()
3291 SfxObjectShell* pDoc = GetObjectShell();
3292 if ( pDoc->IsLoadingFinished() )
3293 pDoc->CheckSecurityOnLoading_Impl();
3295 // check if document depends on a template
3296 pDoc->UpdateFromTemplate_Impl();
3299 void SfxViewFrame::SetViewFrame( SfxViewFrame* pFrame )
3301 SfxGetpApp()->SetViewFrame_Impl( pFrame );
3305 void SfxViewFrame::ActivateToolPanel( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& i_rFrame, const OUString& i_rPanelURL )
3307 SolarMutexGuard aGuard;
3309 // look up the SfxFrame for the given XFrame
3310 SfxFrame* pFrame = NULL;
3311 for ( pFrame = SfxFrame::GetFirst(); pFrame; pFrame = SfxFrame::GetNext( *pFrame ) )
3313 if ( pFrame->GetFrameInterface() == i_rFrame )
3314 break;
3316 SfxViewFrame* pViewFrame = pFrame ? pFrame->GetCurrentViewFrame() : NULL;
3317 ENSURE_OR_RETURN_VOID( pViewFrame != NULL, "SfxViewFrame::ActivateToolPanel: did not find an SfxFrame for the given XFrame!" );
3319 pViewFrame->ActivateToolPanel_Impl( i_rPanelURL );
3323 void SfxViewFrame::ActivateToolPanel_Impl( const OUString& i_rPanelURL )
3325 // ensure the task pane is visible
3326 ENSURE_OR_RETURN_VOID( KnowsChildWindow( SID_TASKPANE ), "SfxViewFrame::ActivateToolPanel: this frame/module does not allow for a task pane!" );
3327 if ( !HasChildWindow( SID_TASKPANE ) )
3328 ToggleChildWindow( SID_TASKPANE );
3330 SfxChildWindow* pTaskPaneChildWindow = GetChildWindow( SID_TASKPANE );
3331 ENSURE_OR_RETURN_VOID( pTaskPaneChildWindow, "SfxViewFrame::ActivateToolPanel_Impl: just switched it on, but it is not there!" );
3333 ::sfx2::ITaskPaneToolPanelAccess* pPanelAccess = dynamic_cast< ::sfx2::ITaskPaneToolPanelAccess* >( pTaskPaneChildWindow );
3334 ENSURE_OR_RETURN_VOID( pPanelAccess, "SfxViewFrame::ActivateToolPanel_Impl: task pane child window does not implement a required interface!" );
3335 pPanelAccess->ActivateToolPanel( i_rPanelURL );
3338 SfxInfoBarWindow* SfxViewFrame::AppendInfoBar( const OUString& sId, const OUString& sMessage )
3340 const sal_uInt16 nId = SfxInfoBarContainerChild::GetChildWindowId();
3342 // Make sure the InfoBar container is visible
3343 if (!HasChildWindow(nId))
3344 ToggleChildWindow(nId);
3346 SfxChildWindow* pChild = GetChildWindow(nId);
3347 if (pChild)
3349 SfxInfoBarContainerWindow* pInfoBarContainer = static_cast<SfxInfoBarContainerWindow*>(pChild->GetWindow());
3350 SfxInfoBarWindow* pInfoBar = pInfoBarContainer->appendInfoBar(sId, sMessage);
3351 ShowChildWindow(nId);
3352 return pInfoBar;
3354 return NULL;
3357 void SfxViewFrame::RemoveInfoBar( const OUString& sId )
3359 const sal_uInt16 nId = SfxInfoBarContainerChild::GetChildWindowId();
3361 // Make sure the InfoBar container is visible
3362 if (!HasChildWindow(nId))
3363 ToggleChildWindow(nId);
3365 SfxChildWindow* pChild = GetChildWindow(nId);
3366 if (pChild)
3368 SfxInfoBarContainerWindow* pInfoBarContainer = static_cast<SfxInfoBarContainerWindow*>(pChild->GetWindow());
3369 SfxInfoBarWindow* pInfoBar = pInfoBarContainer->getInfoBar(sId);
3370 pInfoBarContainer->removeInfoBar(pInfoBar);
3371 ShowChildWindow(nId);
3375 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */