LCOV - code coverage report
Current view: top level - sfx2/source/view - viewfrm.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 647 1540 42.0 %
Date: 2015-06-13 12:38:46 Functions: 73 109 67.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <config_features.h>
      21             : 
      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>
      69             : 
      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>
      76             : 
      77             : #include <com/sun/star/uno/Reference.h>
      78             : #include <com/sun/star/ucb/XContent.hpp>
      79             : 
      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>
      91             : 
      92             : #include <boost/optional.hpp>
      93             : 
      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;
     103             : 
     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"
     141             : 
     142             : #define SfxViewFrame
     143             : #include "sfxslots.hxx"
     144             : #undef SfxViewFrame
     145             : 
     146       85202 : SFX_IMPL_SUPERCLASS_INTERFACE(SfxViewFrame,SfxShell)
     147             : 
     148         208 : void SfxViewFrame::InitInterface_Impl()
     149             : {
     150         208 :     GetStaticInterface()->RegisterChildWindow(SID_BROWSER);
     151         208 :     GetStaticInterface()->RegisterChildWindow(SID_RECORDING_FLOATWINDOW);
     152             : #if HAVE_FEATURE_DESKTOP
     153         208 :     GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_FULLSCREEN | SFX_VISIBILITY_FULLSCREEN, RID_FULLSCREENTOOLBOX);
     154         208 :     GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_APPLICATION | SFX_VISIBILITY_STANDARD, RID_ENVTOOLBOX );
     155             : #endif
     156         208 : }
     157             : 
     158       95192 : TYPEINIT2(SfxViewFrame,SfxShell,SfxListener);
     159           0 : TYPEINIT1(SfxViewFrameItem, SfxPoolItem);
     160             : 
     161             : namespace
     162             : {
     163           0 :     bool moduleHasToolPanels( SfxViewFrame_Impl& i_rViewFrameImpl )
     164             :     {
     165           0 :         if ( !i_rViewFrameImpl.aHasToolPanels )
     166             :         {
     167             :             i_rViewFrameImpl.aHasToolPanels.reset( ::sfx2::ModuleTaskPane::ModuleHasToolPanels(
     168           0 :                 i_rViewFrameImpl.rFrame.GetFrameInterface() ) );
     169             :         }
     170           0 :         return *i_rViewFrameImpl.aHasToolPanels;
     171             :     }
     172             : }
     173             : 
     174           0 : 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 )
     175             : {
     176             :     // TODO/LATER: In future the info should replace the direct hash completely
     177           0 :     bool bResult = ( !nPasswordHash && !aInfo.getLength() );
     178             : 
     179             :     OSL_ENSURE( pFilter && ( pFilter->GetFilterFlags() & SfxFilterFlags::PASSWORDTOMODIFY ), "PasswordToModify feature is active for a filter that does not support it!" );
     180             : 
     181           0 :     if ( pFilter && xHandler.is() )
     182             :     {
     183           0 :         bool bCancel = false;
     184           0 :         bool bFirstTime = true;
     185             : 
     186           0 :         while ( !bResult && !bCancel )
     187             :         {
     188           0 :             bool bMSType = !pFilter->IsOwnFormat();
     189             : 
     190             :             ::rtl::Reference< ::comphelper::DocPasswordRequest > pPasswordRequest(
     191             :                  new ::comphelper::DocPasswordRequest(
     192             :                  bMSType ? ::comphelper::DocPasswordRequestType_MS : ::comphelper::DocPasswordRequestType_STANDARD,
     193             :                  bFirstTime ? ::com::sun::star::task::PasswordRequestMode_PASSWORD_ENTER : ::com::sun::star::task::PasswordRequestMode_PASSWORD_REENTER,
     194             :                  aPath,
     195           0 :                  true ) );
     196             : 
     197           0 :             uno::Reference< com::sun::star::task::XInteractionRequest > rRequest( pPasswordRequest.get() );
     198           0 :             xHandler->handle( rRequest );
     199             : 
     200           0 :             if ( pPasswordRequest->isPassword() )
     201             :             {
     202           0 :                 if ( aInfo.getLength() )
     203             :                 {
     204           0 :                     bResult = ::comphelper::DocPasswordHelper::IsModifyPasswordCorrect( pPasswordRequest->getPasswordToModify(), aInfo );
     205             :                 }
     206             :                 else
     207             :                 {
     208             :                     // the binary format
     209           0 :                     bResult = ( SfxMedium::CreatePasswordToModifyHash( pPasswordRequest->getPasswordToModify(), OUString( "com.sun.star.text.TextDocument"  ).equals( pFilter->GetServiceName() ) ) == nPasswordHash );
     210             :                 }
     211             :             }
     212             :             else
     213           0 :                 bCancel = true;
     214             : 
     215           0 :             bFirstTime = false;
     216           0 :         }
     217             :     }
     218             : 
     219           0 :     return bResult;
     220             : }
     221             : 
     222        3243 : void SfxViewFrame::SetDowning_Impl()
     223             : {
     224        3243 :     pImp->bIsDowning = true;
     225        3243 : }
     226             : 
     227      154886 : bool SfxViewFrame::IsDowning_Impl() const
     228             : {
     229      154886 :     return pImp->bIsDowning;
     230             : }
     231             : 
     232           0 : class SfxViewNotificatedFrameList_Impl :
     233             :     public SfxListener, public SfxViewFrameArr_Impl
     234             : {
     235             : public:
     236             : 
     237             :     void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) SAL_OVERRIDE;
     238             : };
     239             : 
     240           0 : void SfxViewNotificatedFrameList_Impl::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
     241             : {
     242           0 :     const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
     243           0 :     if ( pSimpleHint )
     244             :     {
     245           0 :         switch( pSimpleHint->GetId() )
     246             :         {
     247             :             case SFX_HINT_DYING:
     248           0 :                 SfxViewFrame* pFrame = dynamic_cast<SfxViewFrame*>(&rBC);
     249           0 :                 if( pFrame )
     250             :                 {
     251           0 :                     iterator it = std::find( begin(), end(), pFrame );
     252           0 :                     if( it != end() )
     253           0 :                         erase( it );
     254             :                 }
     255           0 :                 break;
     256             :         }
     257             :     }
     258           0 : }
     259             : 
     260           0 : void SfxViewFrame::ExecReload_Impl( SfxRequest& rReq )
     261             : {
     262           0 :     SfxFrame *pParent = GetFrame().GetParentFrame();
     263           0 :     if ( rReq.GetSlot() == SID_RELOAD )
     264             :     {
     265             :         // When CTRL-Reload, reload the active Frame
     266           0 :         SfxViewFrame* pActFrame = this;
     267           0 :         while ( pActFrame )
     268           0 :             pActFrame = pActFrame->GetActiveChildFrame_Impl();
     269             : 
     270           0 :         if ( pActFrame )
     271             :         {
     272           0 :             sal_uInt16 nModifier = rReq.GetModifier();
     273           0 :             if ( nModifier & KEY_MOD1 )
     274             :             {
     275           0 :                 pActFrame->ExecReload_Impl( rReq );
     276           0 :                 return;
     277             :             }
     278             :         }
     279             : 
     280             :         // If only a reload of the graphics for one or more child frames
     281             :         // should be made
     282           0 :         SfxFrame& rFrame = GetFrame();
     283           0 :         if ( pParent == &rFrame && rFrame.GetChildFrameCount() )
     284             :         {
     285           0 :             bool bReloadAvailable = false;
     286           0 :             SfxFrameIterator aIter( rFrame, false );
     287           0 :             SfxFrame *pChild = aIter.FirstFrame();
     288           0 :             while ( pChild )
     289             :             {
     290           0 :                 SfxFrame *pNext = aIter.NextFrame( *pChild );
     291           0 :                 SfxObjectShell *pShell = pChild->GetCurrentDocument();
     292           0 :                 if( pShell && pShell->Get_Impl()->bReloadAvailable )
     293             :                 {
     294           0 :                     bReloadAvailable = true;
     295           0 :                     pChild->GetCurrentViewFrame()->ExecuteSlot( rReq );
     296             :                 }
     297           0 :                 pChild = pNext;
     298             :             }
     299             : 
     300             :             // The top level frame itself has no graphics!
     301           0 :             if ( bReloadAvailable )
     302           0 :                 return;
     303             :         }
     304             :     }
     305             :     else
     306             :     {
     307             :         // When CTRL-Edit, edit the TopFrame.
     308           0 :         sal_uInt16 nModifier = rReq.GetModifier();
     309             : 
     310           0 :         if ( ( nModifier & KEY_MOD1 ) && pParent )
     311             :         {
     312           0 :             SfxViewFrame *pTop = GetTopViewFrame();
     313           0 :             pTop->ExecReload_Impl( rReq );
     314           0 :             return;
     315             :         }
     316             :     }
     317             : 
     318           0 :     SfxObjectShell* pSh = GetObjectShell();
     319           0 :     switch ( rReq.GetSlot() )
     320             :     {
     321             :         case SID_EDITDOC:
     322             :         {
     323             :             // Due to Double occupancy in toolboxes (with or without Ctrl),
     324             :             // it is also possible that the slot is enabled, but Ctrl-click
     325             :             // despite this is not!
     326           0 :             if( !pSh || !pSh->HasName() || !(pSh->Get_Impl()->nLoadedFlags & SfxLoadedFlags::MAINDOCUMENT ))
     327           0 :                 break;
     328             : 
     329           0 :             SfxMedium* pMed = pSh->GetMedium();
     330             : 
     331           0 :             SFX_ITEMSET_ARG( pSh->GetMedium()->GetItemSet(), pItem, SfxBoolItem, SID_VIEWONLY, false );
     332           0 :             if ( pItem && pItem->GetValue() )
     333             :             {
     334           0 :                 SfxApplication* pApp = SfxGetpApp();
     335           0 :                 SfxAllItemSet aSet( pApp->GetPool() );
     336           0 :                 aSet.Put( SfxStringItem( SID_FILE_NAME, pMed->GetURLObject().GetMainURL(INetURLObject::NO_DECODE) ) );
     337           0 :                 aSet.Put( SfxBoolItem( SID_TEMPLATE, true ) );
     338           0 :                 aSet.Put( SfxStringItem( SID_TARGETNAME, OUString("_blank") ) );
     339           0 :                 SFX_ITEMSET_ARG( pMed->GetItemSet(), pReferer, SfxStringItem, SID_REFERER, false );
     340           0 :                 if ( pReferer )
     341           0 :                     aSet.Put( *pReferer );
     342           0 :                 SFX_ITEMSET_ARG( pSh->GetMedium()->GetItemSet(), pVersionItem, SfxInt16Item, SID_VERSION, false );
     343           0 :                 if ( pVersionItem )
     344           0 :                     aSet.Put( *pVersionItem );
     345             : 
     346           0 :                 if( pMed->GetFilter() )
     347             :                 {
     348           0 :                     aSet.Put( SfxStringItem( SID_FILTER_NAME, pMed->GetFilter()->GetFilterName() ) );
     349           0 :                     SFX_ITEMSET_ARG( pMed->GetItemSet(), pOptions, SfxStringItem, SID_FILE_FILTEROPTIONS, false );
     350           0 :                     if ( pOptions )
     351           0 :                         aSet.Put( *pOptions );
     352             :                 }
     353             : 
     354           0 :                 GetDispatcher()->Execute( SID_OPENDOC, SfxCallMode::ASYNCHRON, aSet );
     355           0 :                 return;
     356             :             }
     357             : 
     358             :             StreamMode nOpenMode;
     359           0 :             bool bNeedsReload = false;
     360           0 :             if ( !pSh->IsReadOnly() )
     361             :             {
     362             :                 // Save and reload Readonly
     363           0 :                 if( pSh->IsModified() )
     364             :                 {
     365           0 :                     if ( pSh->PrepareClose() )
     366             :                     {
     367             :                         // the storing could let the medium be changed
     368           0 :                         pMed = pSh->GetMedium();
     369           0 :                         bNeedsReload = true;
     370             :                     }
     371             :                     else
     372             :                     {
     373           0 :                         rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), false ) );
     374           0 :                         return;
     375             :                     }
     376             :                 }
     377           0 :                 nOpenMode = SFX_STREAM_READONLY;
     378           0 :                 pSh->SetReadOnlyUI(true);
     379             :             }
     380             :             else
     381             :             {
     382           0 :                 if ( pSh->IsReadOnlyMedium()
     383           0 :                   && ( pSh->GetModifyPasswordHash() || pSh->GetModifyPasswordInfo().getLength() )
     384           0 :                   && !pSh->IsModifyPasswordEntered() )
     385             :                 {
     386           0 :                     OUString aDocumentName = INetURLObject( pMed->GetOrigURL() ).GetMainURL( INetURLObject::DECODE_WITH_CHARSET );
     387           0 :                     if( !AskPasswordToModify_Impl( pMed->GetInteractionHandler(), aDocumentName, pMed->GetOrigFilter(), pSh->GetModifyPasswordHash(), pSh->GetModifyPasswordInfo() ) )
     388             :                     {
     389             :                         // this is a read-only document, if it has "Password to modify"
     390             :                         // the user should enter password before he can edit the document
     391           0 :                         rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), false ) );
     392           0 :                         return;
     393             :                     }
     394             : 
     395           0 :                     pSh->SetModifyPasswordEntered();
     396             :                 }
     397             : 
     398             :                 // Remove infobar if document was read-only (after password check)
     399           0 :                 RemoveInfoBar("readonly");
     400             : 
     401           0 :                 nOpenMode = pSh->IsOriginallyReadOnlyMedium() ? SFX_STREAM_READONLY : SFX_STREAM_READWRITE;
     402             : 
     403             :                 // if only the view was in the readonly mode then there is no need to do the reload
     404           0 :                 if ( !pSh->IsReadOnlyMedium() )
     405             :                 {
     406             :                     // SetReadOnlyUI causes recomputation of window title, using
     407             :                     // open mode among other things, so call SetOpenMode before
     408             :                     // SetReadOnlyUI:
     409           0 :                     pMed->SetOpenMode( nOpenMode );
     410           0 :                     pSh->SetReadOnlyUI( false );
     411           0 :                     return;
     412             :                 }
     413             : 
     414             : 
     415           0 :                 pSh->SetReadOnlyUI( false );
     416             :             }
     417             : 
     418           0 :             if ( rReq.IsAPI() )
     419             :             {
     420             :                 // Control through API if r/w or r/o
     421           0 :                 SFX_REQUEST_ARG(rReq, pEditItem, SfxBoolItem, SID_EDITDOC, false);
     422           0 :                 if ( pEditItem )
     423           0 :                     nOpenMode = pEditItem->GetValue() ? SFX_STREAM_READWRITE : SFX_STREAM_READONLY;
     424             :             }
     425             : 
     426             :             // doing
     427             : 
     428           0 :             OUString aTemp;
     429           0 :             utl::LocalFileHelper::ConvertPhysicalNameToURL( pMed->GetPhysicalName(), aTemp );
     430           0 :             INetURLObject aPhysObj( aTemp );
     431           0 :             SFX_ITEMSET_ARG( pSh->GetMedium()->GetItemSet(),
     432             :                              pVersionItem, SfxInt16Item, SID_VERSION, false );
     433             : 
     434           0 :             INetURLObject aMedObj( pMed->GetName() );
     435             : 
     436             :             // the logic below is following, if the document seems not to need to be reloaded and the physical name is different
     437             :             // 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
     438           0 :             if ( ( !bNeedsReload && ( (aMedObj.GetProtocol() == INetProtocol::File &&
     439           0 :                     aMedObj.getFSysPath(INetURLObject::FSYS_DETECT) != aPhysObj.getFSysPath(INetURLObject::FSYS_DETECT) &&
     440           0 :                     !::utl::UCBContentHelper::IsYounger( aMedObj.GetMainURL( INetURLObject::NO_DECODE ), aPhysObj.GetMainURL( INetURLObject::NO_DECODE ) ))
     441           0 :                   || pMed->IsRemote() ) )
     442           0 :                || pVersionItem )
     443             :             {
     444           0 :                 bool bOK = false;
     445           0 :                 if ( !pVersionItem )
     446             :                 {
     447           0 :                     bool bHasStorage = pMed->HasStorage_Impl();
     448             :                     // switching edit mode could be possible without reload
     449           0 :                     if ( bHasStorage && pMed->GetStorage() == pSh->GetStorage() )
     450             :                     {
     451             :                         // TODO/LATER: faster creation of copy
     452           0 :                         if ( !pSh->ConnectTmpStorage_Impl( pMed->GetStorage(), pMed ) )
     453           0 :                             return;
     454             :                     }
     455             : 
     456           0 :                     pMed->CloseAndRelease();
     457           0 :                     pMed->GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, !( nOpenMode & StreamMode::WRITE ) ) );
     458           0 :                     pMed->SetOpenMode( nOpenMode );
     459             : 
     460           0 :                     pMed->CompleteReOpen();
     461           0 :                     if ( nOpenMode & StreamMode::WRITE )
     462           0 :                         pMed->LockOrigFileOnDemand( false, true );
     463             : 
     464             :                     // LockOrigFileOnDemand might set the readonly flag itself, it should be set back
     465           0 :                     pMed->GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, !( nOpenMode & StreamMode::WRITE ) ) );
     466             : 
     467           0 :                     if ( !pMed->GetErrorCode() )
     468           0 :                         bOK = true;
     469             :                 }
     470             : 
     471           0 :                 if( !bOK )
     472             :                 {
     473           0 :                     ErrCode nErr = pMed->GetErrorCode();
     474           0 :                     if ( pVersionItem )
     475           0 :                         nErr = ERRCODE_IO_ACCESSDENIED;
     476             :                     else
     477             :                     {
     478           0 :                         pMed->ResetError();
     479           0 :                         pMed->SetOpenMode( SFX_STREAM_READONLY );
     480           0 :                         pMed->ReOpen();
     481           0 :                         pSh->DoSaveCompleted( pMed );
     482             :                     }
     483             : 
     484             :                     // Readonly document can not be switched to edit mode?
     485           0 :                     rReq.Done( false );
     486             : 
     487           0 :                     if ( nOpenMode == SFX_STREAM_READWRITE && !rReq.IsAPI() )
     488             :                     {
     489             :                         // ::com::sun::star::sdbcx::User offering to open it as a template
     490           0 :                         ScopedVclPtrInstance<MessageDialog> aBox(&GetWindow(), SfxResId(STR_QUERY_OPENASTEMPLATE),
     491           0 :                                            VCL_MESSAGE_QUESTION, VCL_BUTTONS_YES_NO);
     492           0 :                         if ( RET_YES == aBox->Execute() )
     493             :                         {
     494           0 :                             SfxApplication* pApp = SfxGetpApp();
     495           0 :                             SfxAllItemSet aSet( pApp->GetPool() );
     496           0 :                             aSet.Put( SfxStringItem( SID_FILE_NAME, pMed->GetName() ) );
     497           0 :                             SFX_ITEMSET_ARG( pMed->GetItemSet(), pReferer, SfxStringItem, SID_REFERER, false );
     498           0 :                             if ( pReferer )
     499           0 :                                 aSet.Put( *pReferer );
     500           0 :                             aSet.Put( SfxBoolItem( SID_TEMPLATE, true ) );
     501           0 :                             if ( pVersionItem )
     502           0 :                                 aSet.Put( *pVersionItem );
     503             : 
     504           0 :                             if( pMed->GetFilter() )
     505             :                             {
     506           0 :                                 aSet.Put( SfxStringItem( SID_FILTER_NAME, pMed->GetFilter()->GetFilterName() ) );
     507           0 :                                 SFX_ITEMSET_ARG( pMed->GetItemSet(), pOptions,
     508             :                                                  SfxStringItem, SID_FILE_FILTEROPTIONS, false );
     509           0 :                                 if ( pOptions )
     510           0 :                                     aSet.Put( *pOptions );
     511             :                             }
     512             : 
     513           0 :                             GetDispatcher()->Execute( SID_OPENDOC, SfxCallMode::ASYNCHRON, aSet );
     514           0 :                             return;
     515             :                         }
     516             :                         else
     517           0 :                             nErr = 0;
     518             :                     }
     519             : 
     520           0 :                     ErrorHandler::HandleError( nErr );
     521             :                     rReq.SetReturnValue(
     522           0 :                         SfxBoolItem( rReq.GetSlot(), false ) );
     523           0 :                     return;
     524             :                 }
     525             :                 else
     526             :                 {
     527           0 :                     pSh->DoSaveCompleted( pMed );
     528           0 :                     pSh->Broadcast( SfxSimpleHint(SFX_HINT_MODECHANGED) );
     529           0 :                     rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), true ) );
     530           0 :                     rReq.Done( true );
     531           0 :                     return;
     532             :                 }
     533             :             }
     534             : 
     535           0 :             rReq.AppendItem( SfxBoolItem( SID_FORCERELOAD, true) );
     536           0 :             rReq.AppendItem( SfxBoolItem( SID_SILENT, true ));
     537             :         }
     538             : 
     539             :         case SID_RELOAD:
     540             :         {
     541             :             // Due to Double occupancy in toolboxes (with or without Ctrl),
     542             :             // it is also possible that the slot is enabled, but Ctrl-click
     543             :             // despite this is not!
     544           0 :             if ( !pSh || !pSh->CanReload_Impl() )
     545           0 :                 break;
     546           0 :             SfxApplication* pApp = SfxGetpApp();
     547           0 :             SFX_REQUEST_ARG(rReq, pForceReloadItem, SfxBoolItem,
     548             :                             SID_FORCERELOAD, false);
     549           0 :             if(  pForceReloadItem && !pForceReloadItem->GetValue() &&
     550           0 :                 !pSh->GetMedium()->IsExpired() )
     551           0 :                 return;
     552           0 :             if( pImp->bReloading || pSh->IsInModalMode() )
     553           0 :                 return;
     554             : 
     555             :             // AutoLoad is prohibited if possible
     556           0 :             SFX_REQUEST_ARG(rReq, pAutoLoadItem, SfxBoolItem, SID_AUTOLOAD, false);
     557           0 :             if ( pAutoLoadItem && pAutoLoadItem->GetValue() &&
     558           0 :                  GetFrame().IsAutoLoadLocked_Impl() )
     559           0 :                 return;
     560             : 
     561           0 :             SfxObjectShellLock xOldObj( pSh );
     562           0 :             pImp->bReloading = true;
     563           0 :             SFX_REQUEST_ARG(rReq, pURLItem, SfxStringItem,
     564             :                             SID_FILE_NAME, false);
     565             :             // Open as editable?
     566           0 :             bool bForEdit = !pSh->IsReadOnly();
     567             : 
     568             :             // If possible ask the User
     569           0 :             bool bDo = GetViewShell()->PrepareClose();
     570           0 :             SFX_REQUEST_ARG(rReq, pSilentItem, SfxBoolItem, SID_SILENT, false);
     571           0 :             if ( bDo && GetFrame().DocIsModified_Impl() &&
     572           0 :                  !rReq.IsAPI() && ( !pSilentItem || !pSilentItem->GetValue() ) )
     573             :             {
     574           0 :                 ScopedVclPtrInstance<MessageDialog> aBox(&GetWindow(), SfxResId(STR_QUERY_LASTVERSION),
     575           0 :                                    VCL_MESSAGE_QUESTION, VCL_BUTTONS_YES_NO);
     576           0 :                 bDo = ( RET_YES == aBox->Execute() );
     577             :             }
     578             : 
     579           0 :             if ( bDo )
     580             :             {
     581           0 :                 SfxMedium *pMedium = xOldObj->GetMedium();
     582             : 
     583             :                 // Remove Frameset before the FramesetView may disappear
     584           0 :                 OUString aURL;
     585           0 :                 if (pURLItem)
     586           0 :                     aURL = pURLItem->GetValue();
     587             :                 else
     588           0 :                     aURL = pMedium->GetName();
     589             : 
     590             :                 bool bHandsOff =
     591           0 :                     ( pMedium->GetURLObject().GetProtocol() == INetProtocol::File && !xOldObj->IsDocShared() );
     592             : 
     593             :                 // Empty existing SfxMDIFrames for this Document
     594             :                 // in native format or R/O, open it now for editing?
     595           0 :                 SfxObjectShellLock xNewObj;
     596             : 
     597             :                 // collect the views of the document
     598             :                 // TODO: when UNO ViewFactories are available for SFX-based documents, the below code should
     599             :                 // be UNOized, too
     600             :                 typedef ::std::pair< Reference< XFrame >, sal_uInt16 >  ViewDescriptor;
     601           0 :                 ::std::list< ViewDescriptor > aViewFrames;
     602           0 :                 SfxViewFrame *pView = GetFirst( xOldObj );
     603           0 :                 while ( pView )
     604             :                 {
     605           0 :                     Reference< XFrame > xFrame( pView->GetFrame().GetFrameInterface() );
     606             :                     OSL_ENSURE( xFrame.is(), "SfxViewFrame::ExecReload_Impl: no XFrame?!" );
     607           0 :                     aViewFrames.push_back( ViewDescriptor( xFrame, pView->GetCurViewId() ) );
     608             : 
     609           0 :                     pView = GetNext( *pView, xOldObj );
     610           0 :                 }
     611             : 
     612           0 :                 DELETEZ( xOldObj->Get_Impl()->pReloadTimer );
     613             : 
     614           0 :                 SfxItemSet* pNewSet = 0;
     615           0 :                 const SfxFilter *pFilter = pMedium->GetFilter();
     616           0 :                 if( pURLItem )
     617             :                 {
     618           0 :                     pNewSet = new SfxAllItemSet( pApp->GetPool() );
     619           0 :                     pNewSet->Put( *pURLItem );
     620             : 
     621             :                     // Filter Detection
     622           0 :                     OUString referer;
     623           0 :                     SFX_REQUEST_ARG(
     624             :                         rReq, refererItem, SfxStringItem, SID_REFERER, false);
     625           0 :                     if (refererItem != 0) {
     626           0 :                         referer = refererItem->GetValue();
     627             :                     }
     628           0 :                     SfxMedium aMedium( pURLItem->GetValue(), referer, SFX_STREAM_READWRITE );
     629           0 :                     SfxFilterMatcher().GuessFilter( aMedium, &pFilter );
     630           0 :                     if ( pFilter )
     631           0 :                         pNewSet->Put( SfxStringItem( SID_FILTER_NAME, pFilter->GetName() ) );
     632           0 :                     pNewSet->Put( *aMedium.GetItemSet() );
     633             :                 }
     634             :                 else
     635             :                 {
     636           0 :                     pNewSet = new SfxAllItemSet( *pMedium->GetItemSet() );
     637           0 :                     pNewSet->ClearItem( SID_VIEW_ID );
     638           0 :                     pNewSet->ClearItem( SID_STREAM );
     639           0 :                     pNewSet->ClearItem( SID_INPUTSTREAM );
     640           0 :                     pNewSet->Put( SfxStringItem( SID_FILTER_NAME, pMedium->GetFilter()->GetName() ) );
     641             : 
     642             :                     // let the current security settings be checked again
     643           0 :                     pNewSet->Put( SfxUInt16Item( SID_MACROEXECMODE, document::MacroExecMode::USE_CONFIG ) );
     644             : 
     645           0 :                     if ( pSh->IsOriginallyReadOnlyMedium() )
     646             :                         // edit mode is switched or reload of readonly document
     647           0 :                         pNewSet->Put( SfxBoolItem( SID_DOC_READONLY, true ) );
     648             :                     else
     649             :                         // Reload of file opened for writing
     650           0 :                         pNewSet->ClearItem( SID_DOC_READONLY );
     651             :                 }
     652             : 
     653             :                 // If a salvaged file is present, do not enclose the OrigURL
     654             :                 // again, since the Tempdate is invalid after reload.
     655           0 :                 SFX_ITEMSET_ARG( pNewSet, pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, false);
     656           0 :                 if( pSalvageItem )
     657             :                 {
     658           0 :                     aURL = pSalvageItem->GetValue();
     659           0 :                     pNewSet->ClearItem( SID_ORIGURL );
     660           0 :                     pNewSet->ClearItem( SID_DOC_SALVAGE );
     661             :                 }
     662             : 
     663             : #if HAVE_FEATURE_MULTIUSER_ENVIRONMENT
     664             :                 // TODO/LATER: Temporary solution, the SfxMedium must know the original URL as aLogicName
     665             :                 //             SfxMedium::Transfer_Impl() will be forbidden then.
     666           0 :                 if ( xOldObj->IsDocShared() )
     667           0 :                     pNewSet->Put( SfxStringItem( SID_FILE_NAME, xOldObj->GetSharedFileURL() ) );
     668             : #endif
     669           0 :                 if ( pURLItem )
     670           0 :                     pNewSet->Put( SfxStringItem( SID_REFERER, pMedium->GetName() ) );
     671             :                 else
     672           0 :                     pNewSet->Put( SfxStringItem( SID_REFERER, OUString() ) );
     673             : 
     674           0 :                 xOldObj->CancelTransfers();
     675             : 
     676             : 
     677           0 :                 if ( pSilentItem && pSilentItem->GetValue() )
     678           0 :                     pNewSet->Put( SfxBoolItem( SID_SILENT, true ) );
     679             : 
     680           0 :                 SFX_ITEMSET_ARG(pNewSet, pInteractionItem, SfxUnoAnyItem, SID_INTERACTIONHANDLER, false);
     681           0 :                 SFX_ITEMSET_ARG(pNewSet, pMacroExecItem  , SfxUInt16Item, SID_MACROEXECMODE     , false);
     682           0 :                 SFX_ITEMSET_ARG(pNewSet, pDocTemplateItem, SfxUInt16Item, SID_UPDATEDOCMODE     , false);
     683             : 
     684           0 :                 if (!pInteractionItem)
     685             :                 {
     686           0 :                     Reference < task::XInteractionHandler2 > xHdl = task::InteractionHandler::createWithParent( ::comphelper::getProcessComponentContext(), 0 );
     687           0 :                     if (xHdl.is())
     688           0 :                         pNewSet->Put( SfxUnoAnyItem(SID_INTERACTIONHANDLER,::com::sun::star::uno::makeAny(xHdl)) );
     689             :                 }
     690             : 
     691           0 :                 if (!pMacroExecItem)
     692           0 :                     pNewSet->Put( SfxUInt16Item(SID_MACROEXECMODE,::com::sun::star::document::MacroExecMode::USE_CONFIG) );
     693           0 :                 if (!pDocTemplateItem)
     694           0 :                     pNewSet->Put( SfxUInt16Item(SID_UPDATEDOCMODE,::com::sun::star::document::UpdateDocMode::ACCORDING_TO_CONFIG) );
     695             : 
     696           0 :                 xOldObj->SetModified( false );
     697             :                 // Do not chache the old Document! Is invalid when loading
     698             :                 // another document.
     699             : 
     700           0 :                 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSavedOptions, SfxStringItem, SID_FILE_FILTEROPTIONS, false);
     701           0 :                 SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSavedReferer, SfxStringItem, SID_REFERER, false);
     702             : 
     703           0 :                 bool bHasStorage = pMedium->HasStorage_Impl();
     704           0 :                 if( bHandsOff )
     705             :                 {
     706           0 :                     if ( bHasStorage && pMedium->GetStorage() == xOldObj->GetStorage() )
     707             :                     {
     708             :                         // TODO/LATER: faster creation of copy
     709           0 :                         if ( !xOldObj->ConnectTmpStorage_Impl( pMedium->GetStorage(), pMedium ) )
     710           0 :                             return;
     711             :                     }
     712             : 
     713           0 :                     pMedium->CloseAndRelease();
     714             :                 }
     715             : 
     716           0 :                 xNewObj = SfxObjectShell::CreateObject( pFilter->GetServiceName(), SfxObjectCreateMode::STANDARD );
     717             : 
     718           0 :                 if ( xOldObj->IsModifyPasswordEntered() )
     719           0 :                     xNewObj->SetModifyPasswordEntered();
     720             : 
     721           0 :                 uno::Sequence < beans::PropertyValue > aLoadArgs;
     722           0 :                 TransformItems( SID_OPENDOC, *pNewSet, aLoadArgs );
     723             :                 try
     724             :                 {
     725           0 :                     uno::Reference < frame::XLoadable > xLoad( xNewObj->GetModel(), uno::UNO_QUERY );
     726           0 :                     xLoad->load( aLoadArgs );
     727             :                 }
     728           0 :                 catch ( uno::Exception& )
     729             :                 {
     730           0 :                     xNewObj->DoClose();
     731           0 :                     xNewObj = 0;
     732             :                 }
     733             : 
     734           0 :                 DELETEZ( pNewSet );
     735             : 
     736           0 :                 if( !xNewObj.Is() )
     737             :                 {
     738           0 :                     if( bHandsOff )
     739             :                     {
     740             :                         // back to old medium
     741           0 :                         pMedium->ReOpen();
     742           0 :                         pMedium->LockOrigFileOnDemand( false, true );
     743             : 
     744           0 :                         xOldObj->DoSaveCompleted( pMedium );
     745             :                     }
     746             : 
     747             :                     // r/o-Doc couldn't be switched to writing mode
     748           0 :                     if ( bForEdit && SID_EDITDOC == rReq.GetSlot() )
     749             :                     {
     750             :                         // ask user for opening as template
     751           0 :                         ScopedVclPtrInstance<MessageDialog> aBox(&GetWindow(), SfxResId(STR_QUERY_OPENASTEMPLATE),
     752           0 :                                            VCL_MESSAGE_QUESTION, VCL_BUTTONS_YES_NO);
     753           0 :                         if ( RET_YES == aBox->Execute() )
     754             :                         {
     755           0 :                             SfxAllItemSet aSet( pApp->GetPool() );
     756           0 :                             aSet.Put( SfxStringItem( SID_FILE_NAME, pMedium->GetName() ) );
     757           0 :                             aSet.Put( SfxStringItem( SID_TARGETNAME, OUString("_blank") ) );
     758           0 :                             if ( pSavedOptions )
     759           0 :                                 aSet.Put( *pSavedOptions );
     760           0 :                             if ( pSavedReferer )
     761           0 :                                 aSet.Put( *pSavedReferer );
     762           0 :                             aSet.Put( SfxBoolItem( SID_TEMPLATE, true ) );
     763           0 :                             if( pFilter )
     764           0 :                                 aSet.Put( SfxStringItem( SID_FILTER_NAME, pFilter->GetFilterName() ) );
     765           0 :                             GetDispatcher()->Execute( SID_OPENDOC, SfxCallMode::ASYNCHRON, aSet );
     766           0 :                         }
     767             :                     }
     768             :                 }
     769             :                 else
     770             :                 {
     771           0 :                     if ( xNewObj->GetModifyPasswordHash() && xNewObj->GetModifyPasswordHash() != xOldObj->GetModifyPasswordHash() )
     772             :                     {
     773           0 :                         xNewObj->SetModifyPasswordEntered( false );
     774           0 :                         xNewObj->SetReadOnly();
     775             :                     }
     776           0 :                     else if ( rReq.GetSlot() == SID_EDITDOC )
     777             :                     {
     778           0 :                         xNewObj->SetReadOnlyUI( !bForEdit );
     779             :                     }
     780             : 
     781             : #if HAVE_FEATURE_MULTIUSER_ENVIRONMENT
     782           0 :                     if ( xNewObj->IsDocShared() )
     783             :                     {
     784             :                         // the file is shared but the closing can change the sharing control file
     785           0 :                         xOldObj->DoNotCleanShareControlFile();
     786             :                     }
     787             : #endif
     788             :                     // the Reload and Silent items were only temporary, remove them
     789           0 :                     xNewObj->GetMedium()->GetItemSet()->ClearItem( SID_RELOAD );
     790           0 :                     xNewObj->GetMedium()->GetItemSet()->ClearItem( SID_SILENT );
     791           0 :                     TransformItems( SID_OPENDOC, *xNewObj->GetMedium()->GetItemSet(), aLoadArgs );
     792             : 
     793           0 :                     UpdateDocument_Impl();
     794             : 
     795             :                     try
     796             :                     {
     797           0 :                         while ( !aViewFrames.empty() )
     798             :                         {
     799           0 :                             LoadViewIntoFrame_Impl( *xNewObj, aViewFrames.front().first, aLoadArgs, aViewFrames.front().second, false );
     800           0 :                             aViewFrames.pop_front();
     801             :                         }
     802             :                     }
     803           0 :                     catch( const Exception& )
     804             :                     {
     805             :                         // close the remaining frames
     806             :                         // Don't catch exceptions herein, if this fails, then we're left in an indetermined state, and
     807             :                         // crashing is better than trying to proceed
     808           0 :                         while ( !aViewFrames.empty() )
     809             :                         {
     810           0 :                             Reference< util::XCloseable > xClose( aViewFrames.front().first, UNO_QUERY_THROW );
     811           0 :                             xClose->close( true );
     812           0 :                             aViewFrames.pop_front();
     813           0 :                         }
     814             :                     }
     815             : 
     816             :                     // Propagate document closure.
     817           0 :                     SfxGetpApp()->NotifyEvent( SfxEventHint( SFX_EVENT_CLOSEDOC, GlobalEventConfig::GetEventName( GlobalEventId::CLOSEDOC ), xOldObj ) );
     818             :                 }
     819             : 
     820             :                 // Record as done
     821           0 :                 rReq.Done( true );
     822           0 :                 rReq.SetReturnValue(SfxBoolItem(rReq.GetSlot(), true));
     823           0 :                 return;
     824             :             }
     825             :             else
     826             :             {
     827             :                 // Record as not done
     828           0 :                 rReq.Done();
     829           0 :                 rReq.SetReturnValue(SfxBoolItem(rReq.GetSlot(), false));
     830           0 :                 pImp->bReloading = false;
     831           0 :                 return;
     832           0 :             }
     833             :         }
     834             :     }
     835             : }
     836             : 
     837        4539 : void SfxViewFrame::StateReload_Impl( SfxItemSet& rSet )
     838             : {
     839        4539 :     SfxObjectShell* pSh = GetObjectShell();
     840        4539 :     if ( !pSh )
     841             :     {
     842             :         // I'm just on reload and am yielding myself ...
     843        4539 :         return;
     844             :     }
     845             : 
     846        4539 :     SfxWhichIter aIter( rSet );
     847        9078 :     for ( sal_uInt16 nWhich = aIter.FirstWhich(); nWhich; nWhich = aIter.NextWhich() )
     848             :     {
     849        4539 :         switch ( nWhich )
     850             :         {
     851             :             case SID_EDITDOC:
     852             :             {
     853             :                 const SfxViewShell *pVSh;
     854             :                 const SfxShell *pFSh;
     855       15615 :                 if ( !pSh ||
     856        9621 :                      !pSh->HasName() ||
     857       21241 :                      !( pSh->Get_Impl()->nLoadedFlags &  SfxLoadedFlags::MAINDOCUMENT ) ||
     858        2542 :                      ( pSh->GetCreateMode() == SfxObjectCreateMode::EMBEDDED &&
     859           1 :                        ( !(pVSh = pSh->GetViewShell())  ||
     860           0 :                          !(pFSh = pVSh->GetFormShell()) ||
     861           0 :                          !pFSh->IsDesignMode())))
     862        1999 :                     rSet.DisableItem( SID_EDITDOC );
     863             :                 else
     864             :                 {
     865        2540 :                     SFX_ITEMSET_ARG( pSh->GetMedium()->GetItemSet(), pItem, SfxBoolItem, SID_EDITDOC, false );
     866        2540 :                     if ( pItem && !pItem->GetValue() )
     867           0 :                         rSet.DisableItem( SID_EDITDOC );
     868             :                     else
     869        2540 :                         rSet.Put( SfxBoolItem( nWhich, !pSh->IsReadOnly() ) );
     870             :                 }
     871        4539 :                 break;
     872             :             }
     873             : 
     874             :             case SID_RELOAD:
     875             :             {
     876           0 :                 SfxFrame* pFrame = &GetTopFrame();
     877             : 
     878           0 :                 if ( !pSh || !pSh->CanReload_Impl() || pSh->GetCreateMode() == SfxObjectCreateMode::EMBEDDED )
     879           0 :                     rSet.DisableItem(nWhich);
     880             :                 else
     881             :                 {
     882             :                     // If any ChildFrame is reloadable, the slot is enabled,
     883             :                     // so you can perfom CTRL-Reload
     884           0 :                     bool bReloadAvailable = false;
     885           0 :                     SfxFrameIterator aFrameIter( *pFrame, true );
     886           0 :                     for( SfxFrame* pNextFrame = aFrameIter.FirstFrame();
     887             :                             pFrame;
     888             :                             pNextFrame = pNextFrame ?
     889             :                                 aFrameIter.NextFrame( *pNextFrame ) : 0 )
     890             :                     {
     891           0 :                         SfxObjectShell *pShell = pFrame->GetCurrentDocument();
     892           0 :                         if( pShell && pShell->Get_Impl()->bReloadAvailable )
     893             :                         {
     894           0 :                             bReloadAvailable = true;
     895           0 :                             break;
     896             :                         }
     897           0 :                         pFrame = pNextFrame;
     898             :                     }
     899             : 
     900           0 :                     rSet.Put( SfxBoolItem( nWhich, bReloadAvailable));
     901             :                 }
     902             : 
     903           0 :                 break;
     904             :             }
     905             :         }
     906        4539 :     }
     907             : }
     908             : 
     909           0 : void SfxViewFrame::ExecHistory_Impl( SfxRequest &rReq )
     910             : {
     911             :     // Is there an Undo-Manager on the top Shell?
     912           0 :     SfxShell *pSh = GetDispatcher()->GetShell(0);
     913           0 :     ::svl::IUndoManager* pShUndoMgr = pSh->GetUndoManager();
     914           0 :     bool bOK = false;
     915           0 :     if ( pShUndoMgr )
     916             :     {
     917           0 :         switch ( rReq.GetSlot() )
     918             :         {
     919             :             case SID_CLEARHISTORY:
     920           0 :                 pShUndoMgr->Clear();
     921           0 :                 bOK = true;
     922           0 :                 break;
     923             : 
     924             :             case SID_UNDO:
     925           0 :                 pShUndoMgr->Undo();
     926           0 :                 GetBindings().InvalidateAll(false);
     927           0 :                 bOK = true;
     928           0 :                 break;
     929             : 
     930             :             case SID_REDO:
     931           0 :                 pShUndoMgr->Redo();
     932           0 :                 GetBindings().InvalidateAll(false);
     933           0 :                 bOK = true;
     934           0 :                 break;
     935             : 
     936             :             case SID_REPEAT:
     937           0 :                 if ( pSh->GetRepeatTarget() )
     938           0 :                     pShUndoMgr->Repeat( *pSh->GetRepeatTarget() );
     939           0 :                 bOK = true;
     940           0 :                 break;
     941             :         }
     942             :     }
     943           0 :     else if ( GetViewShell() )
     944             :     {
     945             :         // The SW has its own undo in the View
     946           0 :         const SfxPoolItem *pRet = GetViewShell()->ExecuteSlot( rReq );
     947           0 :         if ( pRet )
     948           0 :             bOK = static_cast<const SfxBoolItem*>(pRet)->GetValue();
     949             :     }
     950             : 
     951           0 :     rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bOK ) );
     952           0 :     rReq.Done();
     953           0 : }
     954             : 
     955         592 : void SfxViewFrame::StateHistory_Impl( SfxItemSet &rSet )
     956             : {
     957             :     // Search for Undo-Manager
     958         592 :     SfxShell *pSh = GetDispatcher()->GetShell(0);
     959         592 :     if ( !pSh )
     960             :         // I'm just on reload and am yielding myself ...
     961           0 :         return;
     962             : 
     963         592 :     ::svl::IUndoManager *pShUndoMgr = pSh->GetUndoManager();
     964         592 :     if ( !pShUndoMgr )
     965             :     {
     966             :         // The SW has its own undo in the View
     967           0 :         SfxWhichIter aIter( rSet );
     968           0 :         SfxViewShell *pViewSh = GetViewShell();
     969           0 :         if( !pViewSh ) return;
     970           0 :         for ( sal_uInt16 nSID = aIter.FirstWhich(); nSID; nSID = aIter.NextWhich() )
     971           0 :             pViewSh->GetSlotState( nSID, 0, &rSet );
     972           0 :         return;
     973             :     }
     974             : 
     975        1578 :     if ( pShUndoMgr->GetUndoActionCount() == 0 &&
     976         986 :          pShUndoMgr->GetRedoActionCount() == 0 &&
     977         394 :          pShUndoMgr->GetRepeatActionCount() == 0 )
     978         394 :         rSet.DisableItem( SID_CLEARHISTORY );
     979             : 
     980         592 :     if ( pShUndoMgr && pShUndoMgr->GetUndoActionCount() )
     981             :     {
     982         198 :         OUString aTmp(SvtResId(STR_UNDO).toString());
     983         198 :         aTmp+= pShUndoMgr->GetUndoActionComment(0);
     984         198 :         rSet.Put( SfxStringItem( SID_UNDO, aTmp ) );
     985             :     }
     986             :     else
     987         394 :         rSet.DisableItem( SID_UNDO );
     988             : 
     989         592 :     if ( pShUndoMgr && pShUndoMgr->GetRedoActionCount() )
     990             :     {
     991           0 :         OUString aTmp(SvtResId(STR_REDO).toString());
     992           0 :         aTmp += pShUndoMgr->GetRedoActionComment(0);
     993           0 :         rSet.Put( SfxStringItem( SID_REDO, aTmp ) );
     994             :     }
     995             :     else
     996         592 :         rSet.DisableItem( SID_REDO );
     997         592 :     SfxRepeatTarget *pTarget = pSh->GetRepeatTarget();
     998         790 :     if ( pShUndoMgr && pTarget && pShUndoMgr->GetRepeatActionCount() &&
     999         198 :          pShUndoMgr->CanRepeat(*pTarget) )
    1000             :     {
    1001          70 :         OUString aTmp(SvtResId(STR_REPEAT).toString());
    1002          70 :         aTmp += pShUndoMgr->GetRepeatActionComment(*pTarget);
    1003          70 :         rSet.Put( SfxStringItem( SID_REPEAT, aTmp ) );
    1004             :     }
    1005             :     else
    1006         522 :         rSet.DisableItem( SID_REPEAT );
    1007             : }
    1008             : 
    1009        3258 : void SfxViewFrame::PopShellAndSubShells_Impl( SfxViewShell& i_rViewShell )
    1010             : {
    1011        3258 :     i_rViewShell.PopSubShells_Impl();
    1012        3258 :     sal_uInt16 nLevel = pDispatcher->GetShellLevel( i_rViewShell );
    1013        3258 :     if ( nLevel != USHRT_MAX )
    1014             :     {
    1015        3258 :         if ( nLevel )
    1016             :         {
    1017             :             // more sub shells on the stack, which were not affected by PopSubShells_Impl
    1018        2750 :             SfxShell *pSubShell = pDispatcher->GetShell( nLevel-1 );
    1019        2750 :             if ( pSubShell == i_rViewShell.GetSubShell() )
    1020             :                 // "real" sub shells will be deleted elsewhere
    1021           0 :                 pDispatcher->Pop( *pSubShell, SfxDispatcherPopFlags::POP_UNTIL );
    1022             :             else
    1023        2750 :                 pDispatcher->Pop( *pSubShell, SfxDispatcherPopFlags::POP_UNTIL | SfxDispatcherPopFlags::POP_DELETE );
    1024             :         }
    1025        3258 :         pDispatcher->Pop( i_rViewShell );
    1026        3258 :         pDispatcher->Flush();
    1027             :     }
    1028             : 
    1029        3258 : }
    1030             : 
    1031             : /*  [Description]
    1032             : 
    1033             :     This method empties the SfxViewFrame, i.e. takes the <SfxObjectShell>
    1034             :     from the dispatcher and ends its <SfxListener> Relationship to this
    1035             :     SfxObjectShell (by which they may even destroy themselves).
    1036             : 
    1037             :     Thus, by invoking ReleaseObjectShell() and  SetObjectShell() the
    1038             :     SfxObjectShell can be replaced.
    1039             : 
    1040             :     Between RealeaseObjectShell() and SetObjectShell() can the control not
    1041             :     be handed over to the system.
    1042             : 
    1043             :     [Cross-reference]
    1044             : 
    1045             :     <SfxViewFrame::SetObjectShell(SfxObjectShell&)>
    1046             : */
    1047        3243 : void SfxViewFrame::ReleaseObjectShell_Impl()
    1048             : {
    1049             :     DBG_ASSERT( xObjSh.Is(), "no SfxObjectShell to release!" );
    1050             : 
    1051        3243 :     GetFrame().ReleasingComponent_Impl( true );
    1052        3243 :     if ( GetWindow().HasChildPathFocus( true ) )
    1053             :     {
    1054             :         DBG_ASSERT( !GetActiveChildFrame_Impl(), "Wrong active child frame!" );
    1055        2810 :         GetWindow().GrabFocus();
    1056             :     }
    1057             : 
    1058        3243 :     SfxViewShell *pDyingViewSh = GetViewShell();
    1059        3243 :     if ( pDyingViewSh )
    1060             :     {
    1061        3243 :         PopShellAndSubShells_Impl( *pDyingViewSh );
    1062        3243 :         pDyingViewSh->DisconnectAllClients();
    1063        3243 :         SetViewShell_Impl(0);
    1064        3243 :         delete pDyingViewSh;
    1065             :     }
    1066             : #ifdef DBG_UTIL
    1067             :     else
    1068             :         OSL_FAIL("No Shell");
    1069             : #endif
    1070             : 
    1071        3243 :     if ( xObjSh.Is() )
    1072             :     {
    1073        3243 :         pDispatcher->Pop( *xObjSh );
    1074        3243 :         SfxModule* pModule = xObjSh->GetModule();
    1075        3243 :         if( pModule )
    1076        3243 :             pDispatcher->RemoveShell_Impl( *pModule );
    1077        3243 :         pDispatcher->Flush();
    1078        3243 :         EndListening( *xObjSh );
    1079             : 
    1080        3243 :         Notify( *xObjSh, SfxSimpleHint(SFX_HINT_TITLECHANGED) );
    1081        3243 :         Notify( *xObjSh, SfxSimpleHint(SFX_HINT_DOCCHANGED) );
    1082             : 
    1083        3243 :         if ( 1 == xObjSh->GetOwnerLockCount() && pImp->bObjLocked && xObjSh->GetCreateMode() == SfxObjectCreateMode::EMBEDDED )
    1084           1 :             xObjSh->DoClose();
    1085        3243 :         SfxObjectShellRef xDyingObjSh = xObjSh;
    1086        3243 :         xObjSh.Clear();
    1087        3243 :         if( ( GetFrameType() & SFXFRAME_HASTITLE ) && pImp->nDocViewNo )
    1088        3143 :             xDyingObjSh->GetNoSet_Impl().ReleaseIndex(pImp->nDocViewNo-1);
    1089        3243 :         if ( pImp->bObjLocked )
    1090             :         {
    1091        3143 :             xDyingObjSh->OwnerLock( false );
    1092        3143 :             pImp->bObjLocked = false;
    1093        3243 :         }
    1094             :     }
    1095             : 
    1096        3243 :     GetDispatcher()->SetDisableFlags( 0 );
    1097        3243 : }
    1098             : 
    1099        3243 : bool SfxViewFrame::Close()
    1100             : {
    1101             : 
    1102             :     DBG_ASSERT( GetFrame().IsClosing_Impl() || !GetFrame().GetFrameInterface().is(), "ViewFrame closed too early!" );
    1103             : 
    1104             :     // If no saving have been made up until now, then embedded Objects should
    1105             :     // not be saved automatically anymore.
    1106        3243 :     if ( GetViewShell() )
    1107        3243 :         GetViewShell()->DiscardClients_Impl();
    1108        3243 :     Broadcast( SfxSimpleHint( SFX_HINT_DYING ) );
    1109             : 
    1110        3243 :     if (SfxViewFrame::Current() == this)
    1111        3126 :         SfxViewFrame::SetViewFrame( NULL );
    1112             : 
    1113             :     // Since the Dispatcher is emptied, it can not be used in any reasnable
    1114             :     // manner, thus it is better to let the dispatcher be.
    1115        3243 :     GetDispatcher()->Lock(true);
    1116        3243 :     delete this;
    1117             : 
    1118        3243 :     return true;
    1119             : }
    1120             : 
    1121        3148 : void SfxViewFrame::DoActivate( bool bUI, SfxViewFrame* pOldFrame )
    1122             : {
    1123        3148 :     SfxGetpApp();
    1124             : 
    1125        3148 :     pDispatcher->DoActivate_Impl( bUI, pOldFrame );
    1126             : 
    1127             :     // If this ViewFrame has got a parent and this is not a parent of the
    1128             :     // old ViewFrames, it gets a ParentActivate.
    1129        3148 :     if ( bUI )
    1130             :     {
    1131        3148 :         SfxViewFrame *pFrame = GetParentViewFrame();
    1132        6296 :         while ( pFrame )
    1133             :         {
    1134           0 :             if ( !pOldFrame || !pOldFrame->GetFrame().IsParent( &pFrame->GetFrame() ) )
    1135           0 :                 pFrame->pDispatcher->DoParentActivate_Impl();
    1136           0 :             pFrame = pFrame->GetParentViewFrame();
    1137             :         }
    1138             :     }
    1139        3148 : }
    1140             : 
    1141        3145 : void SfxViewFrame::DoDeactivate(bool bUI, SfxViewFrame* pNewFrame )
    1142             : {
    1143        3145 :     SfxGetpApp();
    1144        3145 :     pDispatcher->DoDeactivate_Impl( bUI, pNewFrame );
    1145             : 
    1146             :     // If this ViewFrame has got a parent and this is not a parent of the
    1147             :     // new ViewFrames, it gets a ParentDeactivate.
    1148        3145 :     if ( bUI )
    1149             :     {
    1150        3145 :         SfxViewFrame *pFrame = GetParentViewFrame();
    1151        6290 :         while ( pFrame )
    1152             :         {
    1153           0 :             if ( !pNewFrame || !pNewFrame->GetFrame().IsParent( &pFrame->GetFrame() ) )
    1154           0 :                 pFrame->pDispatcher->DoParentDeactivate_Impl();
    1155           0 :             pFrame = pFrame->GetParentViewFrame();
    1156             :         }
    1157             :     }
    1158        3145 : }
    1159             : 
    1160        5928 : void SfxViewFrame::InvalidateBorderImpl( const SfxViewShell* pSh )
    1161             : {
    1162        5928 :     if( pSh && !nAdjustPosPixelLock )
    1163             :     {
    1164        5921 :         if ( GetViewShell() && GetWindow().IsVisible() )
    1165             :         {
    1166         252 :             if ( GetFrame().IsInPlace() )
    1167             :             {
    1168        5928 :                 return;
    1169             :             }
    1170             : 
    1171             :             DoAdjustPosSizePixel( GetViewShell(), Point(),
    1172         252 :                                             GetWindow().GetOutputSizePixel() );
    1173             :         }
    1174             :     }
    1175             : }
    1176             : 
    1177       15869 : bool SfxViewFrame::SetBorderPixelImpl
    1178             : (
    1179             :     const SfxViewShell* pVSh,
    1180             :     const SvBorder&     rBorder
    1181             : )
    1182             : 
    1183             : {
    1184       15869 :     pImp->aBorder = rBorder;
    1185             : 
    1186       15869 :     if ( IsResizeInToOut_Impl() && !GetFrame().IsInPlace() )
    1187             :     {
    1188         816 :         Size aSize = pVSh->GetWindow()->GetOutputSizePixel();
    1189         816 :         if ( aSize.Width() && aSize.Height() )
    1190             :         {
    1191           0 :             aSize.Width() += rBorder.Left() + rBorder.Right();
    1192           0 :             aSize.Height() += rBorder.Top() + rBorder.Bottom();
    1193             : 
    1194           0 :             Size aOldSize = GetWindow().GetOutputSizePixel();
    1195           0 :             GetWindow().SetOutputSizePixel( aSize );
    1196           0 :             vcl::Window* pParent = &GetWindow();
    1197           0 :             while ( pParent->GetParent() )
    1198           0 :                 pParent = pParent->GetParent();
    1199           0 :             Size aOuterSize = pParent->GetOutputSizePixel();
    1200           0 :             aOuterSize.Width() += ( aSize.Width() - aOldSize.Width() );
    1201           0 :             aOuterSize.Height() += ( aSize.Height() - aOldSize.Height() );
    1202           0 :             pParent->SetOutputSizePixel( aOuterSize );
    1203             :         }
    1204             :     }
    1205             :     else
    1206             :     {
    1207       15053 :         Point aPoint;
    1208       15053 :         Rectangle aEditArea( aPoint, GetWindow().GetOutputSizePixel() );
    1209       15053 :         aEditArea.Left() += rBorder.Left();
    1210       15053 :         aEditArea.Right() -= rBorder.Right();
    1211       15053 :         aEditArea.Top() += rBorder.Top();
    1212       15053 :         aEditArea.Bottom() -= rBorder.Bottom();
    1213       15053 :         pVSh->GetWindow()->SetPosSizePixel( aEditArea.TopLeft(), aEditArea.GetSize() );
    1214             :     }
    1215             : 
    1216       15869 :     return true;
    1217             : }
    1218             : 
    1219        5052 : const SvBorder& SfxViewFrame::GetBorderPixelImpl
    1220             : (
    1221             :     const SfxViewShell* /*pSh*/
    1222             : )   const
    1223             : 
    1224             : {
    1225        5052 :     return pImp->aBorder;
    1226             : }
    1227             : 
    1228      154886 : void SfxViewFrame::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
    1229             : {
    1230      154886 :     if( IsDowning_Impl())
    1231      161372 :         return;
    1232             : 
    1233             :     // we know only SimpleHints
    1234      148400 :     const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
    1235      148400 :     if ( pSimpleHint )
    1236             :     {
    1237      111377 :         switch( pSimpleHint->GetId() )
    1238             :         {
    1239             :             case SFX_HINT_MODECHANGED:
    1240             :             {
    1241          38 :                 UpdateTitle();
    1242             : 
    1243          38 :                 if ( !xObjSh.Is() )
    1244           0 :                     break;
    1245             : 
    1246             :                 // Switch r/o?
    1247          38 :                 SfxBindings& rBind = GetBindings();
    1248          38 :                 rBind.Invalidate( SID_RELOAD );
    1249          38 :                 SfxDispatcher *pDispat = GetDispatcher();
    1250          38 :                 bool bWasReadOnly = pDispat->GetReadOnly_Impl();
    1251          38 :                 bool bIsReadOnly = xObjSh->IsReadOnly();
    1252          38 :                 if ( bWasReadOnly != bIsReadOnly )
    1253             :                 {
    1254             :                     // Then also TITLE_CHANGED
    1255           0 :                     UpdateTitle();
    1256           0 :                     rBind.Invalidate( SID_FILE_NAME );
    1257           0 :                     rBind.Invalidate( SID_DOCINFO_TITLE );
    1258           0 :                     rBind.Invalidate( SID_EDITDOC );
    1259             : 
    1260           0 :                     pDispat->GetBindings()->InvalidateAll(true);
    1261           0 :                     pDispat->SetReadOnly_Impl( bIsReadOnly );
    1262             : 
    1263             :                     // Only force and Dispatcher-Update, if it is done next
    1264             :                     // anyway, otherwise flickering or GPF is possibel since
    1265             :                     // the Writer for example prefers in Resize preform some
    1266             :                     // actions which has a SetReadOnlyUI in Dispatcher as a
    1267             :                     // result!
    1268             : 
    1269           0 :                     if ( pDispat->IsUpdated_Impl() )
    1270           0 :                         pDispat->Update_Impl(true);
    1271             :                 }
    1272             : 
    1273          38 :                 Enable( !xObjSh->IsInModalMode() );
    1274          38 :                 break;
    1275             :             }
    1276             : 
    1277             :             case SFX_HINT_TITLECHANGED:
    1278             :             {
    1279        8705 :                 UpdateTitle();
    1280        8705 :                 SfxBindings& rBind = GetBindings();
    1281        8705 :                 rBind.Invalidate( SID_FILE_NAME );
    1282        8705 :                 rBind.Invalidate( SID_DOCINFO_TITLE );
    1283        8705 :                 rBind.Invalidate( SID_EDITDOC );
    1284        8705 :                 rBind.Invalidate( SID_RELOAD );
    1285        8705 :                 break;
    1286             :             }
    1287             : 
    1288             :             case SFX_HINT_DEINITIALIZING:
    1289        3114 :                 GetFrame().DoClose();
    1290        3114 :                 break;
    1291             :             case SFX_HINT_DYING:
    1292             :                 // when the Object is being deleted, destroy the view too
    1293           0 :                 if ( xObjSh.Is() )
    1294           0 :                     ReleaseObjectShell_Impl();
    1295             :                 else
    1296           0 :                     GetFrame().DoClose();
    1297           0 :                 break;
    1298             : 
    1299             :         }
    1300             :     }
    1301       37023 :     else if ( dynamic_cast<const SfxEventHint*>(&rHint) )
    1302             :     {
    1303       26066 :         const SfxEventHint* pEventHint = dynamic_cast<const SfxEventHint*>(&rHint);
    1304             :         // When the Document is loaded asynchronously, was the Dispatcher
    1305             :         // set as ReadOnly, to what must be returned when the document itself
    1306             :         // is not read only, and the loading is finished.
    1307       26066 :         switch ( pEventHint->GetEventId() )
    1308             :         {
    1309             :             case SFX_EVENT_MODIFYCHANGED:
    1310             :             {
    1311        1572 :                 SfxBindings& rBind = GetBindings();
    1312        1572 :                 rBind.Invalidate( SID_DOC_MODIFIED );
    1313        1572 :                 rBind.Invalidate( SID_SAVEDOC );
    1314        1572 :                 rBind.Invalidate( SID_RELOAD );
    1315        1572 :                 rBind.Invalidate( SID_EDITDOC );
    1316        1572 :                 break;
    1317             :             }
    1318             : 
    1319             :             case SFX_EVENT_OPENDOC:
    1320             :             case SFX_EVENT_CREATEDOC:
    1321             :             {
    1322         618 :                 if ( !xObjSh.Is() )
    1323           0 :                     break;
    1324             : 
    1325         618 :                 SfxBindings& rBind = GetBindings();
    1326         618 :                 rBind.Invalidate( SID_RELOAD );
    1327         618 :                 rBind.Invalidate( SID_EDITDOC );
    1328             :                 const SfxViewShell *pVSh;
    1329             :                 const SfxShell *pFSh;
    1330        1236 :                 if ( !xObjSh->IsReadOnly() ||
    1331           1 :                      ( xObjSh->GetCreateMode() == SfxObjectCreateMode::EMBEDDED &&
    1332           0 :                        (pVSh = xObjSh->GetViewShell()) &&
    1333           0 :                        (pFSh = pVSh->GetFormShell()) &&
    1334           0 :                        !pFSh->IsDesignMode()))
    1335             :                 {
    1336             :                     // In contrast to above (TITLE_CHANGED) does the UI not
    1337             :                     // have to be updated because it was not obstructed
    1338             : 
    1339             :                     // #i21560# InvalidateAll() causes the assertion
    1340             :                     // 'SfxBindings::Invalidate while in update" when
    1341             :                     // the sfx slot SID_BASICIDE_APPEAR is executed
    1342             :                     // via API from another thread (Java).
    1343             :                     // According to MBA this call is not necessary anymore,
    1344             :                     // because each document has its own SfxBindings.
    1345             :                     //GetDispatcher()->GetBindings()->InvalidateAll(true);
    1346             :                 }
    1347             :                 else
    1348             :                 {
    1349           1 :                     SfxInfoBarWindow* pInfoBar = AppendInfoBar("readonly", SfxResId(STR_READONLY_DOCUMENT));
    1350           1 :                     if (pInfoBar)
    1351             :                     {
    1352           1 :                         VclPtrInstance<PushButton> pBtn( &GetWindow(), SfxResId(BT_READONLY_EDIT));
    1353           1 :                         pBtn->SetClickHdl(LINK(this, SfxViewFrame, SwitchReadOnlyHandler));
    1354           1 :                         pInfoBar->addButton(pBtn);
    1355             :                     }
    1356             :                 }
    1357             : 
    1358         618 :                 break;
    1359             :             }
    1360             : 
    1361             :             case SFX_EVENT_TOGGLEFULLSCREENMODE:
    1362             :             {
    1363           0 :                 if ( GetFrame().OwnsBindings_Impl() )
    1364           0 :                     GetBindings().GetDispatcher_Impl()->Update_Impl( true );
    1365           0 :                 break;
    1366             :             }
    1367             :         }
    1368             :     }
    1369             : }
    1370             : 
    1371           0 : IMPL_LINK_NOARG(SfxViewFrame, SwitchReadOnlyHandler)
    1372             : {
    1373           0 :     GetDispatcher()->Execute(SID_EDITDOC);
    1374           0 :     return 0;
    1375             : }
    1376             : 
    1377             : 
    1378        3250 : void SfxViewFrame::Construct_Impl( SfxObjectShell *pObjSh )
    1379             : {
    1380        3250 :     pImp->bResizeInToOut = true;
    1381        3250 :     pImp->bDontOverwriteResizeInToOut = false;
    1382        3250 :     pImp->bObjLocked = false;
    1383        3250 :     pImp->pFocusWin = 0;
    1384        3250 :     pImp->pActiveChild = NULL;
    1385        3250 :     pImp->nCurViewId = 0;
    1386        3250 :     pImp->bReloading = false;
    1387        3250 :     pImp->bIsDowning = false;
    1388        3250 :     pImp->bModal = false;
    1389        3250 :     pImp->bEnabled = true;
    1390        3250 :     pImp->nDocViewNo = 0;
    1391        3250 :     pImp->aMargin = Size( -1, -1 );
    1392        3250 :     pImp->pWindow = 0;
    1393             : 
    1394        3250 :     SetPool( &SfxGetpApp()->GetPool() );
    1395        3250 :     pDispatcher = new SfxDispatcher(this);
    1396        3250 :     if ( !GetBindings().GetDispatcher() )
    1397        3250 :         GetBindings().SetDispatcher( pDispatcher );
    1398             : 
    1399        3250 :     xObjSh = pObjSh;
    1400        3250 :     if ( xObjSh.Is() && xObjSh->IsPreview() )
    1401           0 :         SetQuietMode_Impl( true );
    1402             : 
    1403        3250 :     if ( pObjSh )
    1404             :     {
    1405        3250 :         pDispatcher->Push( *SfxGetpApp() );
    1406        3250 :         SfxModule* pModule = xObjSh->GetModule();
    1407        3250 :         if( pModule )
    1408        3250 :             pDispatcher->Push( *pModule );
    1409        3250 :         pDispatcher->Push( *this );
    1410        3250 :         pDispatcher->Push( *pObjSh );
    1411        3250 :         pDispatcher->Flush();
    1412        3250 :         StartListening( *pObjSh );
    1413        3250 :         Notify( *pObjSh, SfxSimpleHint(SFX_HINT_TITLECHANGED) );
    1414        3250 :         Notify( *pObjSh, SfxSimpleHint(SFX_HINT_DOCCHANGED) );
    1415        3250 :         pDispatcher->SetReadOnly_Impl( pObjSh->IsReadOnly() );
    1416             :     }
    1417             :     else
    1418             :     {
    1419           0 :         pDispatcher->Push( *SfxGetpApp() );
    1420           0 :         pDispatcher->Push( *this );
    1421           0 :         pDispatcher->Flush();
    1422             :     }
    1423             : 
    1424        3250 :     SfxViewFrameArr_Impl &rViewArr = SfxGetpApp()->GetViewFrames_Impl();
    1425        3250 :     rViewArr.push_back( this );
    1426        3250 : }
    1427             : 
    1428             : /*  [Description]
    1429             : 
    1430             :     Constructor of SfxViewFrame for a <SfxObjectShell> from the Resource.
    1431             :     The 'nViewId' to the created <SfxViewShell> can be returned.
    1432             :     (default is the SfxViewShell-Subclass that was registered first).
    1433             : */
    1434        3250 : SfxViewFrame::SfxViewFrame
    1435             : (
    1436             :     SfxFrame&           rFrame,
    1437             :     SfxObjectShell*     pObjShell
    1438             : )
    1439        3250 :     : pImp( new SfxViewFrame_Impl( rFrame ) )
    1440             :     , pDispatcher(0)
    1441        3250 :     , pBindings( new SfxBindings )
    1442        9750 :     , nAdjustPosPixelLock( 0 )
    1443             : {
    1444             : 
    1445        3250 :     rFrame.SetCurrentViewFrame_Impl( this );
    1446        3250 :     rFrame.SetFrameType_Impl( GetFrameType() | SFXFRAME_HASTITLE );
    1447        3250 :     Construct_Impl( pObjShell );
    1448             : 
    1449        3250 :     pImp->pWindow = VclPtr<SfxFrameViewWindow_Impl>::Create( this, rFrame.GetWindow() );
    1450        3250 :     pImp->pWindow->SetSizePixel( rFrame.GetWindow().GetOutputSizePixel() );
    1451        3250 :     rFrame.SetOwnsBindings_Impl( true );
    1452        3250 :     rFrame.CreateWorkWindow_Impl();
    1453        3250 : }
    1454             : 
    1455        9729 : SfxViewFrame::~SfxViewFrame()
    1456             : {
    1457        3243 :     SetDowning_Impl();
    1458             : 
    1459        3243 :     if ( SfxViewFrame::Current() == this )
    1460           0 :         SfxViewFrame::SetViewFrame( NULL );
    1461             : 
    1462        3243 :     ReleaseObjectShell_Impl();
    1463             : 
    1464        3243 :     if ( GetFrame().OwnsBindings_Impl() )
    1465             :         // The Bindings delete the Frame!
    1466        3243 :         KillDispatcher_Impl();
    1467             : 
    1468        3243 :     pImp->pWindow.disposeAndClear();
    1469        3243 :     pImp->pFocusWin.clear();
    1470             : 
    1471        3243 :     if ( GetFrame().GetCurrentViewFrame() == this )
    1472        3243 :         GetFrame().SetCurrentViewFrame_Impl( NULL );
    1473             : 
    1474             :     // Unregister from the Frame List.
    1475        3243 :     SfxApplication *pSfxApp = SfxGetpApp();
    1476        3243 :     SfxViewFrameArr_Impl &rFrames = pSfxApp->GetViewFrames_Impl();
    1477        3243 :     SfxViewFrameArr_Impl::iterator it = std::find( rFrames.begin(), rFrames.end(), this );
    1478        3243 :     rFrames.erase( it );
    1479             : 
    1480             :     // Delete Member
    1481        3243 :     KillDispatcher_Impl();
    1482             : 
    1483        3243 :     delete pImp;
    1484        6486 : }
    1485             : 
    1486             : // Remove and delete the Dispatcher.
    1487        6486 : void SfxViewFrame::KillDispatcher_Impl()
    1488             : {
    1489             : 
    1490        6486 :     SfxModule* pModule = xObjSh.Is() ? xObjSh->GetModule() : 0;
    1491        6486 :     if ( xObjSh.Is() )
    1492           0 :         ReleaseObjectShell_Impl();
    1493        6486 :     if ( pDispatcher )
    1494             :     {
    1495        3243 :         if( pModule )
    1496           0 :             pDispatcher->Pop( *pModule, SfxDispatcherPopFlags::POP_UNTIL );
    1497             :         else
    1498        3243 :             pDispatcher->Pop( *this );
    1499        3243 :         DELETEZ(pDispatcher);
    1500             :     }
    1501        6486 : }
    1502             : 
    1503      228856 : SfxViewFrame* SfxViewFrame::Current()
    1504             : {
    1505      228856 :     return SfxApplication::Get() ? SfxGetpApp()->Get_Impl()->pViewFrame : NULL;
    1506             : }
    1507             : 
    1508             : // returns the first window of spec. type viewing the specified doc.
    1509    26909479 : SfxViewFrame* SfxViewFrame::GetFirst
    1510             : (
    1511             :     const SfxObjectShell*   pDoc,
    1512             :     bool                    bOnlyIfVisible
    1513             : )
    1514             : {
    1515    26909479 :     SfxApplication *pSfxApp = SfxGetpApp();
    1516    26909479 :     SfxViewFrameArr_Impl &rFrames = pSfxApp->GetViewFrames_Impl();
    1517             : 
    1518             :     // search for a SfxDocument of the specified type
    1519    26959618 :     for ( size_t nPos = 0; nPos < rFrames.size(); ++nPos )
    1520             :     {
    1521    26878217 :         SfxViewFrame *pFrame = rFrames[nPos];
    1522    53749807 :         if  (   ( !pDoc || pDoc == pFrame->GetObjectShell() )
    1523    53718305 :             &&  ( !bOnlyIfVisible || pFrame->IsVisible() )
    1524             :             )
    1525    26828078 :             return pFrame;
    1526             :     }
    1527             : 
    1528       81401 :     return 0;
    1529             : }
    1530             : 
    1531             : // returns thenext window of spec. type viewing the specified doc.
    1532    26809488 : SfxViewFrame* SfxViewFrame::GetNext
    1533             : (
    1534             :     const SfxViewFrame&     rPrev,
    1535             :     const SfxObjectShell*   pDoc,
    1536             :     bool                    bOnlyIfVisible
    1537             : )
    1538             : {
    1539    26809488 :     SfxApplication *pSfxApp = SfxGetpApp();
    1540    26809488 :     SfxViewFrameArr_Impl &rFrames = pSfxApp->GetViewFrames_Impl();
    1541             : 
    1542             :     // refind the specified predecessor
    1543             :     sal_uInt16 nPos;
    1544    26814739 :     for ( nPos = 0; nPos < rFrames.size(); ++nPos )
    1545    26814739 :         if ( rFrames[nPos] == &rPrev )
    1546    26809488 :             break;
    1547             : 
    1548             :     // search for a Frame of the specified type
    1549    33986684 :     for ( ++nPos; nPos < rFrames.size(); ++nPos )
    1550             :     {
    1551     7177350 :         SfxViewFrame *pFrame = rFrames[nPos];
    1552    14354484 :         if  (   ( !pDoc || pDoc == pFrame->GetObjectShell() )
    1553     7177571 :             &&  ( !bOnlyIfVisible || pFrame->IsVisible() )
    1554             :             )
    1555         154 :             return pFrame;
    1556             :     }
    1557    26809334 :     return 0;
    1558             : }
    1559             : 
    1560        6293 : SfxProgress* SfxViewFrame::GetProgress() const
    1561             : {
    1562        6293 :     SfxObjectShell *pObjSh = GetObjectShell();
    1563        6293 :     return pObjSh ? pObjSh->GetProgress() : 0;
    1564             : }
    1565             : 
    1566       15857 : void SfxViewFrame::DoAdjustPosSizePixel //! divide on Inner.../Outer...
    1567             : (
    1568             :     SfxViewShell*   pSh,
    1569             :     const Point&    rPos,
    1570             :     const Size&     rSize
    1571             : )
    1572             : {
    1573             : 
    1574             :     // Components do not use this Method!
    1575       15857 :     if( pSh && pSh->GetWindow() && !nAdjustPosPixelLock )
    1576             :     {
    1577       15810 :         nAdjustPosPixelLock++;
    1578       15810 :         if ( pImp->bResizeInToOut )
    1579           0 :             pSh->InnerResizePixel( rPos, rSize );
    1580             :         else
    1581       15810 :             pSh->OuterResizePixel( rPos, rSize );
    1582       15810 :         nAdjustPosPixelLock--;
    1583             :     }
    1584       15857 : }
    1585             : 
    1586           0 : bool SfxViewFrameItem::operator==( const SfxPoolItem &rItem ) const
    1587             : {
    1588           0 :     return dynamic_cast<const SfxViewFrameItem&>(rItem).pFrame == pFrame;
    1589             : }
    1590             : 
    1591           0 : SfxPoolItem* SfxViewFrameItem::Clone( SfxItemPool *) const
    1592             : {
    1593           0 :     return new SfxViewFrameItem( pFrame);
    1594             : }
    1595             : 
    1596        6508 : void SfxViewFrame::SetViewShell_Impl( SfxViewShell *pVSh )
    1597             : /*  [Description]
    1598             : 
    1599             :     Internal Method to set the current <SfxViewShell> Instance,
    1600             :     that is active int this SfxViewFrame at the moment.
    1601             : */
    1602             : {
    1603        6508 :     SfxShell::SetViewShell_Impl( pVSh );
    1604             : 
    1605             :     // Hack: InPlaceMode
    1606        6508 :     if ( pVSh )
    1607        3265 :         pImp->bResizeInToOut = false;
    1608        6508 : }
    1609             : 
    1610             : /*  [Description]
    1611             : 
    1612             :     The ParentViewFrame of the Containers ViewFrame in the internal InPlace
    1613             : */
    1614             : //TODO/LATER: is it still necessary? is there a replacement for GetParentViewFrame_Impl?
    1615        8324 : SfxViewFrame* SfxViewFrame::GetParentViewFrame_Impl() const
    1616             : {
    1617        8324 :     return NULL;
    1618             : }
    1619             : 
    1620           0 : void SfxViewFrame::ForceOuterResize_Impl(bool bOn)
    1621             : {
    1622           0 :     if ( !pImp->bDontOverwriteResizeInToOut )
    1623           0 :         pImp->bResizeInToOut = !bOn;
    1624           0 : }
    1625             : 
    1626       15869 : bool SfxViewFrame::IsResizeInToOut_Impl() const
    1627             : {
    1628       15869 :     return pImp->bResizeInToOut;
    1629             : }
    1630             : 
    1631        3148 : void SfxViewFrame::GetDocNumber_Impl()
    1632             : {
    1633             :     DBG_ASSERT( GetObjectShell(), "No Document!" );
    1634        3148 :     GetObjectShell()->SetNamedVisibility_Impl();
    1635        3148 :     pImp->nDocViewNo = GetObjectShell()->GetNoSet_Impl().GetFreeIndex()+1;
    1636        3148 : }
    1637             : 
    1638        4661 : void SfxViewFrame::Enable( bool bEnable )
    1639             : {
    1640        4661 :     if ( bEnable != pImp->bEnabled )
    1641             :     {
    1642        1358 :         pImp->bEnabled = bEnable;
    1643             : 
    1644             :         // e.g. InPlace-Frames have a parent...
    1645        1358 :         SfxViewFrame *pParent = GetParentViewFrame_Impl();
    1646        1358 :         if ( pParent )
    1647             :         {
    1648           0 :             pParent->Enable( bEnable );
    1649             :         }
    1650             :         else
    1651             :         {
    1652        1358 :             vcl::Window *pWindow = &GetFrame().GetTopFrame().GetWindow();
    1653        1358 :             if ( !bEnable )
    1654         681 :                 pImp->bWindowWasEnabled = pWindow->IsInputEnabled();
    1655        1358 :             if ( !bEnable || pImp->bWindowWasEnabled )
    1656        1358 :                 pWindow->EnableInput( bEnable, true );
    1657             :         }
    1658             : 
    1659             :         // cursor and focus
    1660        1358 :         SfxViewShell* pViewSh = GetViewShell();
    1661        1358 :         if ( bEnable )
    1662             :         {
    1663             :             // show cursor
    1664         677 :             if ( pViewSh )
    1665         677 :                 pViewSh->ShowCursor();
    1666             :         }
    1667             :         else
    1668             :         {
    1669             :             // hide cursor
    1670         681 :             if ( pViewSh )
    1671         681 :                 pViewSh->ShowCursor(false);
    1672             :         }
    1673             :     }
    1674        4661 : }
    1675             : 
    1676             : /*  [Description]
    1677             : 
    1678             :     This method makes the Frame-Window visible and before transmitts the
    1679             :     window name. In addition, the document is held. In general one can never
    1680             :     show the window directly!
    1681             : */
    1682        5497 : void SfxViewFrame::Show()
    1683             : {
    1684             :     // First lock the objectShell so that UpdateTitle() is valid:
    1685             :     // IsVisible() == true (:#)
    1686        5497 :     if ( xObjSh.Is() )
    1687             :     {
    1688        5497 :         xObjSh->GetMedium()->GetItemSet()->ClearItem( SID_HIDDEN );
    1689        5497 :         if ( !pImp->bObjLocked )
    1690        3148 :             LockObjectShell_Impl( true );
    1691             : 
    1692             :         // Adjust Doc-Shell title number, get unique view-no
    1693        5497 :         if ( 0 == pImp->nDocViewNo  )
    1694             :         {
    1695        3148 :             GetDocNumber_Impl();
    1696        3148 :             UpdateTitle();
    1697             :         }
    1698             :     }
    1699             :     else
    1700           0 :         UpdateTitle();
    1701             : 
    1702             :     // Display Frame-window, but only if the ViewFrame has no window of its
    1703             :     // own or if it does not contain a Component
    1704        5497 :     GetWindow().Show();
    1705        5497 :     GetFrame().GetWindow().Show();
    1706        5497 : }
    1707             : 
    1708             : 
    1709    26863559 : bool SfxViewFrame::IsVisible() const
    1710             : {
    1711    26863559 :     return pImp->bObjLocked;
    1712             : }
    1713             : 
    1714             : 
    1715        3148 : void SfxViewFrame::LockObjectShell_Impl( bool bLock )
    1716             : {
    1717             :     DBG_ASSERT( pImp->bObjLocked != bLock, "Wrong Locked status!" );
    1718             : 
    1719             :     DBG_ASSERT( GetObjectShell(), "No Document!" );
    1720        3148 :     GetObjectShell()->OwnerLock(bLock);
    1721        3148 :     pImp->bObjLocked = bLock;
    1722        3148 : }
    1723             : 
    1724             : 
    1725        9786 : void SfxViewFrame::MakeActive_Impl( bool bGrabFocus )
    1726             : {
    1727        9786 :     if ( GetViewShell() && !GetFrame().IsClosing_Impl() )
    1728             :     {
    1729        9786 :         if ( IsVisible() )
    1730             :         {
    1731        7439 :             if ( GetViewShell() )
    1732             :             {
    1733        7439 :                 bool bPreview = false;
    1734        7439 :                 if ( GetObjectShell()->IsPreview() )
    1735             :                 {
    1736           0 :                     bPreview = true;
    1737             :                 }
    1738             :                 else
    1739             :                 {
    1740        7439 :                     SfxViewFrame* pParent = GetParentViewFrame();
    1741        7439 :                     if ( pParent )
    1742           0 :                         pParent->SetActiveChildFrame_Impl( this );
    1743             :                 }
    1744             : 
    1745        7439 :                 SfxViewFrame* pCurrent = SfxViewFrame::Current();
    1746        7439 :                 css::uno::Reference< css::frame::XFrame > xFrame = GetFrame().GetFrameInterface();
    1747        7439 :                 if ( !bPreview )
    1748             :                 {
    1749        7439 :                     SetViewFrame( this );
    1750        7439 :                     GetBindings().SetActiveFrame( css::uno::Reference< css::frame::XFrame >() );
    1751        7439 :                     uno::Reference< frame::XFramesSupplier > xSupp( xFrame, uno::UNO_QUERY );
    1752        7439 :                     if ( xSupp.is() )
    1753        7439 :                         xSupp->setActiveFrame( uno::Reference < frame::XFrame >() );
    1754             : 
    1755       14878 :                     css::uno::Reference< css::awt::XWindow > xContainerWindow = xFrame->getContainerWindow();
    1756        7439 :                     vcl::Window* pWindow = VCLUnoHelper::GetWindow(xContainerWindow);
    1757        7439 :                     if (pWindow && pWindow->HasChildPathFocus() && bGrabFocus)
    1758             :                     {
    1759        2998 :                         SfxInPlaceClient *pCli = GetViewShell()->GetUIActiveClient();
    1760        5996 :                         if ( ( !pCli || !pCli->IsObjectUIActive() ) &&
    1761         673 :                             ( !pCurrent || pCurrent->GetParentViewFrame_Impl() != this ) )
    1762        2998 :                                 GetFrame().GrabFocusOnComponent_Impl();
    1763        7439 :                     }
    1764             :                 }
    1765             :                 else
    1766             :                 {
    1767           0 :                     GetBindings().SetDispatcher( GetDispatcher() );
    1768           0 :                     GetBindings().SetActiveFrame( ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > () );
    1769           0 :                     GetDispatcher()->Update_Impl( false );
    1770        7439 :                 }
    1771             :             }
    1772             :         }
    1773             :     }
    1774        9786 : }
    1775             : 
    1776           0 : void SfxViewFrame::SetQuietMode_Impl( bool bOn )
    1777             : {
    1778           0 :     GetDispatcher()->SetQuietMode_Impl( bOn );
    1779           0 : }
    1780             : 
    1781    35783587 : SfxObjectShell* SfxViewFrame::GetObjectShell()
    1782             : {
    1783    35783587 :     return xObjSh;
    1784             : }
    1785             : 
    1786        3265 : const Size& SfxViewFrame::GetMargin_Impl() const
    1787             : {
    1788        3265 :     return pImp->aMargin;
    1789             : }
    1790             : 
    1791           0 : void SfxViewFrame::SetActiveChildFrame_Impl( SfxViewFrame *pViewFrame )
    1792             : {
    1793           0 :     if ( pViewFrame != pImp->pActiveChild )
    1794             :     {
    1795           0 :         pImp->pActiveChild = pViewFrame;
    1796             : 
    1797           0 :         Reference< XFramesSupplier > xFrame( GetFrame().GetFrameInterface(), UNO_QUERY );
    1798           0 :         Reference< XFrame >  xActive;
    1799           0 :         if ( pViewFrame )
    1800           0 :             xActive = pViewFrame->GetFrame().GetFrameInterface();
    1801             : 
    1802           0 :         if ( xFrame.is() )      // xFrame can be NULL
    1803           0 :             xFrame->setActiveFrame( xActive );
    1804             :     }
    1805           0 : }
    1806             : 
    1807           0 : SfxViewFrame* SfxViewFrame::GetActiveChildFrame_Impl() const
    1808             : {
    1809           0 :     SfxViewFrame *pViewFrame = pImp->pActiveChild;
    1810           0 :     return pViewFrame;
    1811             : }
    1812             : 
    1813          67 : SfxViewFrame* SfxViewFrame::LoadViewIntoFrame_Impl_NoThrow( const SfxObjectShell& i_rDoc, const Reference< XFrame >& i_rFrame,
    1814             :                                                    const sal_uInt16 i_nViewId, const bool i_bHidden )
    1815             : {
    1816          67 :     Reference< XFrame > xFrame( i_rFrame );
    1817          67 :     bool bOwnFrame = false;
    1818          67 :     SfxViewShell* pSuccessView = NULL;
    1819             :     try
    1820             :     {
    1821          67 :         if ( !xFrame.is() )
    1822             :         {
    1823          67 :             Reference < XDesktop2 > xDesktop = Desktop::create( ::comphelper::getProcessComponentContext() );
    1824             : 
    1825          67 :             if ( !i_bHidden )
    1826             :             {
    1827             :                 try
    1828             :                 {
    1829             :                     // if there is a backing component, use it
    1830           1 :                     ::framework::FrameListAnalyzer aAnalyzer( xDesktop, Reference< XFrame >(), ::framework::FrameListAnalyzer::E_BACKINGCOMPONENT );
    1831             : 
    1832           1 :                     if ( aAnalyzer.m_xBackingComponent.is() )
    1833           0 :                         xFrame = aAnalyzer.m_xBackingComponent;
    1834             :                 }
    1835           0 :                 catch( uno::Exception& )
    1836             :                 {}
    1837             :             }
    1838             : 
    1839          67 :             if ( !xFrame.is() )
    1840          67 :                 xFrame.set( xDesktop->findFrame( "_blank", 0 ), UNO_SET_THROW );
    1841             : 
    1842          67 :             bOwnFrame = true;
    1843             :         }
    1844             : 
    1845             :         pSuccessView = LoadViewIntoFrame_Impl(
    1846             :             i_rDoc,
    1847             :             xFrame,
    1848             :             Sequence< PropertyValue >(),    // means "reuse existing model's args"
    1849             :             i_nViewId,
    1850             :             i_bHidden
    1851          67 :         );
    1852             : 
    1853          67 :         if ( bOwnFrame && !i_bHidden )
    1854             :         {
    1855             :             // ensure the frame/window is visible
    1856           1 :             Reference< XWindow > xContainerWindow( xFrame->getContainerWindow(), UNO_SET_THROW );
    1857           1 :             xContainerWindow->setVisible( true );
    1858             :         }
    1859             :     }
    1860           0 :     catch( const Exception& )
    1861             :     {
    1862             :         DBG_UNHANDLED_EXCEPTION();
    1863             :     }
    1864             : 
    1865          67 :     if ( pSuccessView )
    1866          67 :         return pSuccessView->GetViewFrame();
    1867             : 
    1868           0 :     if ( bOwnFrame )
    1869             :     {
    1870             :         try
    1871             :         {
    1872           0 :             xFrame->dispose();
    1873             :         }
    1874           0 :         catch( const Exception& )
    1875             :         {
    1876             :             DBG_UNHANDLED_EXCEPTION();
    1877             :         }
    1878             :     }
    1879             : 
    1880           0 :     return NULL;
    1881             : }
    1882             : 
    1883          82 : SfxViewShell* SfxViewFrame::LoadViewIntoFrame_Impl( const SfxObjectShell& i_rDoc, const Reference< XFrame >& i_rFrame,
    1884             :                                            const Sequence< PropertyValue >& i_rLoadArgs, const sal_uInt16 i_nViewId,
    1885             :                                            const bool i_bHidden )
    1886             : {
    1887          82 :     Reference< XModel > xDocument( i_rDoc.GetModel(), UNO_SET_THROW );
    1888             : 
    1889         164 :     ::comphelper::NamedValueCollection aTransformLoadArgs( i_rLoadArgs.getLength() ? i_rLoadArgs : xDocument->getArgs() );
    1890          82 :     aTransformLoadArgs.put( "Model", xDocument );
    1891          82 :     if ( i_nViewId )
    1892          17 :         aTransformLoadArgs.put( "ViewId", sal_Int16( i_nViewId ) );
    1893          82 :     if ( i_bHidden )
    1894          66 :         aTransformLoadArgs.put( "Hidden", i_bHidden );
    1895             :     else
    1896          16 :         aTransformLoadArgs.remove( "Hidden" );
    1897             : 
    1898         164 :     OUString sURL( "private:object"  );
    1899          82 :     if ( sURL.isEmpty() )
    1900           0 :         sURL = i_rDoc.GetFactory().GetFactoryURL();
    1901             : 
    1902         164 :     Reference< XComponentLoader > xLoader( i_rFrame, UNO_QUERY_THROW );
    1903          82 :     xLoader->loadComponentFromURL( sURL, OUString("_self"), 0,
    1904          82 :         aTransformLoadArgs.getPropertyValues() );
    1905             : 
    1906          82 :     SfxViewShell* pViewShell = SfxViewShell::Get( i_rFrame->getController() );
    1907          82 :     ENSURE_OR_THROW( pViewShell,
    1908             :         "SfxViewFrame::LoadViewIntoFrame_Impl: loading an SFX doc into a frame resulted in a non-SFX view - quite impossible" );
    1909         164 :     return pViewShell;
    1910             : }
    1911             : 
    1912          66 : SfxViewFrame* SfxViewFrame::LoadHiddenDocument( SfxObjectShell& i_rDoc, const sal_uInt16 i_nViewId )
    1913             : {
    1914          66 :     return LoadViewIntoFrame_Impl_NoThrow( i_rDoc, Reference< XFrame >(), i_nViewId, true );
    1915             : }
    1916             : 
    1917           0 : SfxViewFrame* SfxViewFrame::LoadDocument( SfxObjectShell& i_rDoc, const sal_uInt16 i_nViewId )
    1918             : {
    1919           0 :     return LoadViewIntoFrame_Impl_NoThrow( i_rDoc, Reference< XFrame >(), i_nViewId, false );
    1920             : }
    1921             : 
    1922           0 : SfxViewFrame* SfxViewFrame::LoadDocumentIntoFrame( SfxObjectShell& i_rDoc, const Reference< XFrame >& i_rTargetFrame, const sal_uInt16 i_nViewId )
    1923             : {
    1924           0 :     return LoadViewIntoFrame_Impl_NoThrow( i_rDoc, i_rTargetFrame, i_nViewId, false );
    1925             : }
    1926             : 
    1927           0 : SfxViewFrame* SfxViewFrame::LoadDocumentIntoFrame( SfxObjectShell& i_rDoc, const SfxFrameItem* i_pFrameItem, const sal_uInt16 i_nViewId )
    1928             : {
    1929           0 :     return LoadViewIntoFrame_Impl_NoThrow( i_rDoc, i_pFrameItem && i_pFrameItem->GetFrame() ? i_pFrameItem->GetFrame()->GetFrameInterface() : NULL, i_nViewId, false );
    1930             : }
    1931             : 
    1932           0 : SfxViewFrame* SfxViewFrame::DisplayNewDocument( SfxObjectShell& i_rDoc, const SfxRequest& i_rCreateDocRequest, const sal_uInt16 i_nViewId )
    1933             : {
    1934           0 :     SFX_REQUEST_ARG( i_rCreateDocRequest, pFrameItem, SfxUnoFrameItem, SID_FILLFRAME, false );
    1935           0 :     SFX_REQUEST_ARG( i_rCreateDocRequest, pHiddenItem, SfxBoolItem, SID_HIDDEN, false );
    1936             : 
    1937             :     return LoadViewIntoFrame_Impl_NoThrow(
    1938             :         i_rDoc,
    1939           0 :         pFrameItem ? pFrameItem->GetFrame() : NULL,
    1940             :         i_nViewId,
    1941           0 :         pHiddenItem && pHiddenItem->GetValue()
    1942           0 :     );
    1943             : }
    1944             : 
    1945        3249 : SfxViewFrame* SfxViewFrame::Get( const Reference< XController>& i_rController, const SfxObjectShell* i_pDoc )
    1946             : {
    1947        3249 :     if ( !i_rController.is() )
    1948           0 :         return NULL;
    1949             : 
    1950        3249 :     const SfxObjectShell* pDoc = i_pDoc;
    1951        3249 :     if ( !pDoc )
    1952             :     {
    1953           0 :         Reference< XModel > xDocument( i_rController->getModel() );
    1954           0 :         for (   pDoc = SfxObjectShell::GetFirst( 0, false );
    1955             :                 pDoc;
    1956             :                 pDoc = SfxObjectShell::GetNext( *pDoc, 0, false )
    1957             :             )
    1958             :         {
    1959           0 :             if ( pDoc->GetModel() == xDocument )
    1960           0 :                 break;
    1961           0 :         }
    1962             :     }
    1963             : 
    1964        3249 :     SfxViewFrame* pViewFrame = NULL;
    1965        3249 :     for (   pViewFrame = SfxViewFrame::GetFirst( pDoc, false );
    1966             :             pViewFrame;
    1967             :             pViewFrame = SfxViewFrame::GetNext( *pViewFrame, pDoc, false )
    1968             :         )
    1969             :     {
    1970        3249 :         if ( pViewFrame->GetViewShell()->GetController() == i_rController )
    1971        3249 :             break;
    1972             :     }
    1973             : 
    1974        3249 :     return pViewFrame;
    1975             : }
    1976             : 
    1977          15 : void SfxViewFrame::SaveCurrentViewData_Impl( const sal_uInt16 i_nNewViewId )
    1978             : {
    1979          15 :     SfxViewShell* pCurrentShell = GetViewShell();
    1980          22 :     ENSURE_OR_RETURN_VOID( pCurrentShell != NULL, "SfxViewFrame::SaveCurrentViewData_Impl: no current view shell -> no current view data!" );
    1981             : 
    1982             :     // determine the logical (API) view name
    1983          15 :     const SfxObjectFactory& rDocFactory( pCurrentShell->GetObjectShell()->GetFactory() );
    1984          15 :     const sal_uInt16 nCurViewNo = rDocFactory.GetViewNo_Impl( GetCurViewId(), 0 );
    1985          15 :     const OUString sCurrentViewName = rDocFactory.GetViewFactory( nCurViewNo ).GetAPIViewName();
    1986          15 :     const sal_uInt16 nNewViewNo = rDocFactory.GetViewNo_Impl( i_nNewViewId, 0 );
    1987          23 :     const OUString sNewViewName = rDocFactory.GetViewFactory( nNewViewNo ).GetAPIViewName();
    1988          15 :     if ( sCurrentViewName.isEmpty() || sNewViewName.isEmpty() )
    1989             :     {
    1990             :         // can't say anything about the view, the respective application did not yet migrate its code to
    1991             :         // named view factories => bail out
    1992             :         OSL_FAIL( "SfxViewFrame::SaveCurrentViewData_Impl: views without API names? Shouldn't happen anymore?" );
    1993           0 :         return;
    1994             :     }
    1995             :     OSL_ENSURE( sNewViewName != sCurrentViewName, "SfxViewFrame::SaveCurrentViewData_Impl: suspicious: new and old view name are identical!" );
    1996             : 
    1997             :     // save the view data only when we're moving from a non-print-preview to the print-preview view
    1998          15 :     if ( sNewViewName != "PrintPreview" )
    1999           7 :         return;
    2000             : 
    2001             :     // retrieve the view data from the view
    2002          16 :     Sequence< PropertyValue > aViewData;
    2003           8 :     pCurrentShell->WriteUserDataSequence( aViewData );
    2004             : 
    2005             :     try
    2006             :     {
    2007             :         // retrieve view data (for *all* views) from the model
    2008           8 :         const Reference< XController > xController( pCurrentShell->GetController(), UNO_SET_THROW );
    2009          16 :         const Reference< XViewDataSupplier > xViewDataSupplier( xController->getModel(), UNO_QUERY_THROW );
    2010          16 :         const Reference< XIndexContainer > xViewData( xViewDataSupplier->getViewData(), UNO_QUERY_THROW );
    2011             : 
    2012             :         // look up the one view data item which corresponds to our current view, and remove it
    2013           8 :         const sal_Int32 nCount = xViewData->getCount();
    2014           8 :         for ( sal_Int32 i=0; i<nCount; ++i )
    2015             :         {
    2016           8 :             const ::comphelper::NamedValueCollection aCurViewData( xViewData->getByIndex(i) );
    2017           8 :             OUString sViewId( aCurViewData.getOrDefault( "ViewId", OUString() ) );
    2018           8 :             if ( sViewId.isEmpty() )
    2019           0 :                 continue;
    2020             : 
    2021           8 :             const SfxViewFactory* pViewFactory = rDocFactory.GetViewFactoryByViewName( sViewId );
    2022           8 :             if ( pViewFactory == NULL )
    2023           0 :                 continue;
    2024             : 
    2025           8 :             if ( pViewFactory->GetOrdinal() == GetCurViewId() )
    2026             :             {
    2027           8 :                 xViewData->removeByIndex(i);
    2028           8 :                 break;
    2029             :             }
    2030           0 :         }
    2031             : 
    2032             :         // then replace it with the most recent view data we just obtained
    2033          16 :         xViewData->insertByIndex( 0, makeAny( aViewData ) );
    2034             :     }
    2035           0 :     catch( const Exception& )
    2036             :     {
    2037             :         DBG_UNHANDLED_EXCEPTION();
    2038           8 :     }
    2039             : }
    2040             : 
    2041             : /*  [Description]
    2042             : 
    2043             :     Internal Method for switching to another <SfxViewShell> subclass,
    2044             :     which should be created in this SfxMDIFrame. If no SfxViewShell exist
    2045             :     in this SfxMDIFrame, then one will first be created.
    2046             : 
    2047             : 
    2048             :     [Return Value]
    2049             : 
    2050             :     bool                        true
    2051             :                                 requested SfxViewShell was created and a
    2052             :                                 possibly existing one deleted
    2053             : 
    2054             :                                 false
    2055             :                                 SfxViewShell requested could not be created,
    2056             :                                 the existing SfxViewShell thus continue to exist
    2057             : */
    2058          15 : bool SfxViewFrame::SwitchToViewShell_Impl
    2059             : (
    2060             :     sal_uInt16  nViewIdOrNo,    /*  > 0
    2061             :                                 Registration-Id of the View, to which the
    2062             :                                 the method should switch, for example the one
    2063             :                                 that will be created.
    2064             : 
    2065             :                                 == 0
    2066             :                                 First use the Default view. */
    2067             : 
    2068             :     bool        bIsIndex        /*  true
    2069             :                                 'nViewIdOrNo' is no Registration-Id instead
    2070             :                                 an Index of <SfxViewFrame> in <SfxObjectShell>.
    2071             :                                 */
    2072             : )
    2073             : {
    2074             :     try
    2075             :     {
    2076          15 :         ENSURE_OR_THROW( GetObjectShell() != NULL, "not possible without a document" );
    2077             : 
    2078             :         // if we already have a view shell, remove it
    2079          15 :         SfxViewShell* pOldSh = GetViewShell();
    2080             :         OSL_PRECOND( pOldSh, "SfxViewFrame::SwitchToViewShell_Impl: that's called *switch* (not for *initial-load*) for a reason" );
    2081          15 :         if ( pOldSh )
    2082             :         {
    2083             :             // ask whether it can be closed
    2084          15 :             if ( !pOldSh->PrepareClose( true ) )
    2085           0 :                 return false;
    2086             : 
    2087             :             // remove sub shells from Dispatcher before switching to new ViewShell
    2088          15 :             PopShellAndSubShells_Impl( *pOldSh );
    2089             :         }
    2090             : 
    2091          15 :         GetBindings().ENTERREGISTRATIONS();
    2092          15 :         LockAdjustPosSizePixel();
    2093             : 
    2094             :         // ID of the new view
    2095          15 :         SfxObjectFactory& rDocFact = GetObjectShell()->GetFactory();
    2096          15 :         const sal_uInt16 nViewId = ( bIsIndex || !nViewIdOrNo ) ? rDocFact.GetViewFactory( nViewIdOrNo ).GetOrdinal() : nViewIdOrNo;
    2097             : 
    2098             :         // save the view data of the old view, so it can be restored later on (when needed)
    2099          15 :         SaveCurrentViewData_Impl( nViewId );
    2100             : 
    2101             :         // create and load new ViewShell
    2102             :         SfxViewShell* pNewSh = LoadViewIntoFrame_Impl(
    2103          15 :             *GetObjectShell(),
    2104          15 :             GetFrame().GetFrameInterface(),
    2105             :             Sequence< PropertyValue >(),    // means "reuse existing model's args"
    2106             :             nViewId,
    2107             :             false
    2108          45 :         );
    2109             : 
    2110             :         // allow resize events to be processed
    2111          15 :         UnlockAdjustPosSizePixel();
    2112             : 
    2113          15 :         if ( GetWindow().IsReallyVisible() )
    2114          15 :             DoAdjustPosSizePixel( pNewSh, Point(), GetWindow().GetOutputSizePixel() );
    2115             : 
    2116          15 :         GetBindings().LEAVEREGISTRATIONS();
    2117          15 :         delete pOldSh;
    2118             :     }
    2119           0 :     catch ( const com::sun::star::uno::Exception& )
    2120             :     {
    2121             :         // the SfxCode is not able to cope with exceptions thrown while creating views
    2122             :         // the code will crash in the stack unwinding procedure, so we shouldn't let exceptions go through here
    2123             :         DBG_UNHANDLED_EXCEPTION();
    2124           0 :         return false;
    2125             :     }
    2126             : 
    2127             :     DBG_ASSERT( SfxGetpApp()->GetViewFrames_Impl().size() == SfxGetpApp()->GetViewShells_Impl().size(), "Inconsistent view arrays!" );
    2128          15 :     return true;
    2129             : }
    2130             : 
    2131        3265 : void SfxViewFrame::SetCurViewId_Impl( const sal_uInt16 i_nID )
    2132             : {
    2133        3265 :     pImp->nCurViewId = i_nID;
    2134        3265 : }
    2135             : 
    2136        5711 : sal_uInt16 SfxViewFrame::GetCurViewId() const
    2137             : {
    2138        5711 :     return pImp->nCurViewId;
    2139             : }
    2140             : 
    2141             : /*  [Description]
    2142             : 
    2143             :     Internal method to run the slot for the <SfxShell> Subclass in the
    2144             :     SfxViewFrame <SVIDL> described slots.
    2145             : */
    2146          16 : void SfxViewFrame::ExecView_Impl
    2147             : (
    2148             :     SfxRequest& rReq        // The executable <SfxRequest>
    2149             : )
    2150             : {
    2151             : 
    2152             :     // If the Shells are just being replaced...
    2153          16 :     if ( !GetObjectShell() || !GetViewShell() )
    2154           0 :         return;
    2155             : 
    2156          16 :     switch ( rReq.GetSlot() )
    2157             :     {
    2158             :         case SID_TERMINATE_INPLACEACTIVATION :
    2159             :         {
    2160           0 :             SfxInPlaceClient* pClient = GetViewShell()->GetUIActiveClient();
    2161           0 :             if ( pClient )
    2162           0 :                 pClient->DeactivateObject();
    2163           0 :             break;
    2164             :         }
    2165             : 
    2166             :         case SID_VIEWSHELL:
    2167             :         {
    2168           0 :             const SfxPoolItem *pItem = 0;
    2169           0 :             if  (   rReq.GetArgs()
    2170           0 :                 &&  SfxItemState::SET == rReq.GetArgs()->GetItemState( SID_VIEWSHELL, false, &pItem )
    2171             :                 )
    2172             :             {
    2173           0 :                 const sal_uInt16 nViewId = static_cast< const SfxUInt16Item* >( pItem )->GetValue();
    2174           0 :                 bool bSuccess = SwitchToViewShell_Impl( nViewId );
    2175           0 :                 rReq.SetReturnValue( SfxBoolItem( 0, bSuccess ) );
    2176             :             }
    2177           0 :             break;
    2178             :         }
    2179             : 
    2180             :         case SID_VIEWSHELL0:
    2181             :         case SID_VIEWSHELL1:
    2182             :         case SID_VIEWSHELL2:
    2183             :         case SID_VIEWSHELL3:
    2184             :         case SID_VIEWSHELL4:
    2185             :         {
    2186          15 :             const sal_uInt16 nViewNo = rReq.GetSlot() - SID_VIEWSHELL0;
    2187          15 :             bool bSuccess = SwitchToViewShell_Impl( nViewNo, true );
    2188          15 :             rReq.SetReturnValue( SfxBoolItem( 0, bSuccess ) );
    2189          15 :             break;
    2190             :         }
    2191             : 
    2192             :         case SID_NEWWINDOW:
    2193             :         {
    2194             :             // Hack. at the moment a virtual Function
    2195           1 :             if ( !GetViewShell()->NewWindowAllowed() )
    2196             :             {
    2197             :                 OSL_FAIL( "You should have disabled the 'Window/New Window' slot!" );
    2198           0 :                 return;
    2199             :             }
    2200             : 
    2201             :             // Get ViewData of FrameSets recursivly.
    2202           1 :             GetFrame().GetViewData_Impl();
    2203           1 :             SfxMedium* pMed = GetObjectShell()->GetMedium();
    2204             : 
    2205             :             // do not open the new window hidden
    2206           1 :             pMed->GetItemSet()->ClearItem( SID_HIDDEN );
    2207             : 
    2208             :             // the view ID (optional arg. TODO: this is currently not supported in the slot definition ...)
    2209           1 :             SFX_REQUEST_ARG( rReq, pViewIdItem, SfxUInt16Item, SID_VIEW_ID, false );
    2210           1 :             const sal_uInt16 nViewId = pViewIdItem ? pViewIdItem->GetValue() : GetCurViewId();
    2211             : 
    2212           1 :             Reference < XFrame > xFrame;
    2213             :             // the frame (optional arg. TODO: this is currently not supported in the slot definition ...)
    2214           1 :             SFX_REQUEST_ARG( rReq, pFrameItem, SfxUnoFrameItem, SID_FILLFRAME, false );
    2215           1 :             if ( pFrameItem )
    2216           0 :                 xFrame = pFrameItem->GetFrame();
    2217             : 
    2218           1 :             LoadViewIntoFrame_Impl_NoThrow( *GetObjectShell(), xFrame, nViewId, false );
    2219             : 
    2220           1 :             rReq.Done();
    2221           1 :             break;
    2222             :         }
    2223             : 
    2224             :         case SID_OBJECT:
    2225             :         {
    2226           0 :             SFX_REQUEST_ARG( rReq, pItem, SfxInt16Item, SID_OBJECT, false );
    2227             : 
    2228           0 :             SfxViewShell *pViewShell = GetViewShell();
    2229           0 :             if ( pViewShell && pItem )
    2230             :             {
    2231           0 :                 pViewShell->DoVerb( pItem->GetValue() );
    2232           0 :                 rReq.Done();
    2233           0 :                 break;;
    2234             :             }
    2235             :         }
    2236             :     }
    2237             : }
    2238             : 
    2239             : /* TODO as96863:
    2240             :         This method try to collect information about the count of currently open documents.
    2241             :         But the algorithm is implemented very simple ...
    2242             :         E.g. hidden documents should be ignored here ... but they are counted.
    2243             :         TODO: export special helper "framework::FrameListAnalyzer" within the framework module
    2244             :         and use it here.
    2245             : */
    2246           1 : bool impl_maxOpenDocCountReached()
    2247             : {
    2248           1 :     css::uno::Reference< css::uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
    2249           2 :     boost::optional<sal_Int32> x(officecfg::Office::Common::Misc::MaxOpenDocuments::get(xContext));
    2250             :     // NIL means: count of allowed documents = infinite !
    2251           1 :     if (!x)
    2252           1 :         return false;
    2253           0 :     sal_Int32 nMaxDocs(x.get());
    2254           0 :     sal_Int32 nOpenDocs = 0;
    2255             : 
    2256           0 :     css::uno::Reference< css::frame::XDesktop2 >  xDesktop = css::frame::Desktop::create(xContext);
    2257           0 :     css::uno::Reference< css::container::XIndexAccess > xCont(xDesktop->getFrames(), css::uno::UNO_QUERY_THROW);
    2258             : 
    2259           0 :     sal_Int32 c = xCont->getCount();
    2260           0 :     sal_Int32 i = 0;
    2261             : 
    2262           0 :     for (i=0; i<c; ++i)
    2263             :     {
    2264             :         try
    2265             :         {
    2266           0 :             css::uno::Reference< css::frame::XFrame > xFrame;
    2267           0 :             xCont->getByIndex(i) >>= xFrame;
    2268           0 :             if ( ! xFrame.is())
    2269           0 :                 continue;
    2270             : 
    2271             :             // a) do not count the help window
    2272           0 :             if ( xFrame->getName() == "OFFICE_HELP_TASK" )
    2273           0 :                 continue;
    2274             : 
    2275             :             // b) count all other frames
    2276           0 :             ++nOpenDocs;
    2277             :         }
    2278           0 :         catch(const css::uno::Exception&)
    2279             :             // A IndexOutOfBoundException can happen in multithreaded
    2280             :             // environments, where any other thread can change this
    2281             :             // container !
    2282           0 :             { continue; }
    2283             :     }
    2284             : 
    2285           1 :     return (nOpenDocs >= nMaxDocs);
    2286             : }
    2287             : 
    2288             : /*  [Description]
    2289             : 
    2290             :     This internal methode returns in 'rSet' the Status for the  <SfxShell>
    2291             :     Subclass SfxViewFrame in the <SVIDL> described <Slots>.
    2292             : 
    2293             :     Thus exactly those Slots-IDs that are recognized as being invalid by Sfx
    2294             :     are included as Which-ranges in 'rSet'. If there exists a mapping for
    2295             :     single slot-IDs of the <SfxItemPool> set in the shell, then the respective
    2296             :     Which-IDs are used so that items can be replaced directly with a working
    2297             :     Core::sun::com::star::script::Engine of the Which-IDs if possible. .
    2298             : */
    2299          16 : void SfxViewFrame::StateView_Impl
    2300             : (
    2301             :     SfxItemSet&     rSet            /*  empty <SfxItemSet> with <Which-Ranges>,
    2302             :                                         which describes the Slot Ids */
    2303             : )
    2304             : {
    2305             : 
    2306          16 :     SfxObjectShell *pDocSh = GetObjectShell();
    2307             : 
    2308          16 :     if ( !pDocSh )
    2309             :         // I'm just on reload and am yielding myself ...
    2310          16 :         return;
    2311             : 
    2312          16 :     const sal_uInt16 *pRanges = rSet.GetRanges();
    2313             :     assert(pRanges && "Set with no Range");
    2314          64 :     while ( *pRanges )
    2315             :     {
    2316          48 :         for ( sal_uInt16 nWhich = *pRanges++; nWhich <= *pRanges; ++nWhich )
    2317             :         {
    2318          16 :             switch(nWhich)
    2319             :             {
    2320             :                 case SID_VIEWSHELL:
    2321             :                 {
    2322           0 :                     rSet.Put( SfxUInt16Item( nWhich, pImp->nCurViewId ) );
    2323           0 :                     break;
    2324             :                 }
    2325             : 
    2326             :                 case SID_VIEWSHELL0:
    2327             :                 case SID_VIEWSHELL1:
    2328             :                 case SID_VIEWSHELL2:
    2329             :                 case SID_VIEWSHELL3:
    2330             :                 case SID_VIEWSHELL4:
    2331             :                 {
    2332          15 :                     sal_uInt16 nViewNo = nWhich - SID_VIEWSHELL0;
    2333          30 :                     if ( GetObjectShell()->GetFactory().GetViewFactoryCount() >
    2334          15 :                          nViewNo && !GetObjectShell()->IsInPlaceActive() )
    2335             :                     {
    2336             :                         SfxViewFactory &rViewFactory =
    2337          15 :                             GetObjectShell()->GetFactory().GetViewFactory(nViewNo);
    2338             :                         rSet.Put( SfxBoolItem(
    2339          15 :                             nWhich, pImp->nCurViewId == rViewFactory.GetOrdinal() ) );
    2340             :                     }
    2341             :                     else
    2342           0 :                         rSet.DisableItem( nWhich );
    2343          15 :                     break;
    2344             :                 }
    2345             : 
    2346             :                 case SID_NEWWINDOW:
    2347             :                 {
    2348           2 :                     if  (   !GetViewShell()->NewWindowAllowed()
    2349           1 :                         ||  impl_maxOpenDocCountReached()
    2350             :                         )
    2351           0 :                         rSet.DisableItem( nWhich );
    2352           1 :                     break;
    2353             :                 }
    2354             :             }
    2355             :         }
    2356             :     }
    2357             : }
    2358             : 
    2359             : 
    2360           0 : void SfxViewFrame::ToTop()
    2361             : {
    2362           0 :     GetFrame().Appear();
    2363           0 : }
    2364             : 
    2365             : 
    2366             : /*  [Description]
    2367             : 
    2368             :     The ParentViewFrame is the ViewFrame of the ParentFrames.
    2369             : */
    2370       20251 : SfxViewFrame* SfxViewFrame::GetParentViewFrame() const
    2371             : {
    2372       20251 :     SfxFrame *pFrame = GetFrame().GetParentFrame();
    2373       20251 :     return pFrame ? pFrame->GetCurrentViewFrame() : NULL;
    2374             : }
    2375             : 
    2376             : /*  [Description]
    2377             : 
    2378             :     GetFrame returns the Frame, in which the ViewFrame is located.
    2379             : */
    2380      825817 : SfxFrame& SfxViewFrame::GetFrame() const
    2381             : {
    2382      825817 :     return pImp->rFrame;
    2383             : }
    2384             : 
    2385       16936 : SfxViewFrame* SfxViewFrame::GetTopViewFrame() const
    2386             : {
    2387       16936 :     return GetFrame().GetTopFrame().GetCurrentViewFrame();
    2388             : }
    2389             : 
    2390      115253 : vcl::Window& SfxViewFrame::GetWindow() const
    2391             : {
    2392      115253 :     return pImp->pWindow ? *pImp->pWindow : GetFrame().GetWindow();
    2393             : }
    2394             : 
    2395           1 : bool SfxViewFrame::DoClose()
    2396             : {
    2397           1 :     return GetFrame().DoClose();
    2398             : }
    2399             : 
    2400           0 : OUString SfxViewFrame::GetActualPresentationURL_Impl() const
    2401             : {
    2402           0 :     if ( xObjSh.Is() )
    2403           0 :         return xObjSh->GetMedium()->GetName();
    2404           0 :     return OUString();
    2405             : }
    2406             : 
    2407           0 : void SfxViewFrame::SetModalMode( bool bModal )
    2408             : {
    2409           0 :     pImp->bModal = bModal;
    2410           0 :     if ( xObjSh.Is() )
    2411             :     {
    2412           0 :         for ( SfxViewFrame* pFrame = SfxViewFrame::GetFirst( xObjSh );
    2413           0 :               !bModal && pFrame; pFrame = SfxViewFrame::GetNext( *pFrame, xObjSh ) )
    2414           0 :             bModal = pFrame->pImp->bModal;
    2415           0 :         xObjSh->SetModalMode_Impl( bModal );
    2416             :     }
    2417           0 : }
    2418             : 
    2419        6378 : bool SfxViewFrame::IsInModalMode() const
    2420             : {
    2421        6378 :     return pImp->bModal || GetFrame().GetWindow().IsInModalMode();
    2422             : }
    2423             : 
    2424       18753 : void SfxViewFrame::Resize( bool bForce )
    2425             : {
    2426       18753 :     Size aSize = GetWindow().GetOutputSizePixel();
    2427       18753 :     if ( bForce || aSize != pImp->aSize )
    2428             :     {
    2429       15590 :         pImp->aSize = aSize;
    2430       15590 :         SfxViewShell *pShell = GetViewShell();
    2431       15590 :         if ( pShell )
    2432             :         {
    2433       15590 :             if ( GetFrame().IsInPlace() )
    2434             :             {
    2435           0 :                 Point aPoint = GetWindow().GetPosPixel();
    2436           0 :                 DoAdjustPosSizePixel( pShell, aPoint, aSize );
    2437             :             }
    2438             :             else
    2439             :             {
    2440       15590 :                 DoAdjustPosSizePixel( pShell, Point(), aSize );
    2441             :             }
    2442             :         }
    2443             :     }
    2444       18753 : }
    2445             : 
    2446             : #define LINE_SEP 0x0A
    2447             : 
    2448           0 : void CutLines( OUString& rStr, sal_Int32 nStartLine, sal_Int32 nLines, bool bEraseTrailingEmptyLines )
    2449             : {
    2450           0 :     sal_Int32 nStartPos = 0;
    2451           0 :     sal_Int32 nLine = 0;
    2452           0 :     while ( nLine < nStartLine )
    2453             :     {
    2454           0 :         nStartPos = rStr.indexOf( LINE_SEP, nStartPos );
    2455           0 :         if( nStartPos == -1 )
    2456           0 :             break;
    2457           0 :         nStartPos++;    // not the \n.
    2458           0 :         nLine++;
    2459             :     }
    2460             : 
    2461             :     DBG_ASSERTWARNING( nStartPos != -1, "CutLines: Start row not found!" );
    2462             : 
    2463           0 :     if ( nStartPos != -1 )
    2464             :     {
    2465           0 :         sal_Int32 nEndPos = nStartPos;
    2466           0 :         for ( sal_Int32 i = 0; i < nLines; i++ )
    2467           0 :             nEndPos = rStr.indexOf( LINE_SEP, nEndPos+1 );
    2468             : 
    2469           0 :         if ( nEndPos == -1 ) // Can happen at the last row.
    2470           0 :             nEndPos = rStr.getLength();
    2471             :         else
    2472           0 :             nEndPos++;
    2473             : 
    2474           0 :         OUString aEndStr = rStr.copy( nEndPos );
    2475           0 :         rStr = rStr.copy( 0, nStartPos );
    2476           0 :         rStr += aEndStr;
    2477             :     }
    2478           0 :     if ( bEraseTrailingEmptyLines && nStartPos != -1 )
    2479             :     {
    2480           0 :         sal_Int32 n = nStartPos;
    2481           0 :         sal_Int32 nLen = rStr.getLength();
    2482           0 :         while ( ( n < nLen ) && ( rStr[ n ] == LINE_SEP ) )
    2483           0 :             n++;
    2484             : 
    2485           0 :         if ( n > nStartPos )
    2486             :         {
    2487           0 :             OUString aEndStr = rStr.copy( n );
    2488           0 :             rStr = rStr.copy( 0, nStartPos );
    2489           0 :             rStr += aEndStr;
    2490             :         }
    2491             :     }
    2492           0 : }
    2493             : 
    2494             : /*
    2495             :     add new recorded dispatch macro script into the application global basic
    2496             :     lib container. It generates a new unique id for it and insert the macro
    2497             :     by using this number as name for the modul
    2498             :  */
    2499           0 : void SfxViewFrame::AddDispatchMacroToBasic_Impl( const OUString& sMacro )
    2500             : {
    2501             : #if !HAVE_FEATURE_SCRIPTING
    2502             :     (void) sMacro;
    2503             : #else
    2504           0 :     if ( sMacro.isEmpty() )
    2505           0 :         return;
    2506             : 
    2507           0 :     SfxApplication* pSfxApp = SfxGetpApp();
    2508           0 :     SfxRequest aReq( SID_BASICCHOOSER, SfxCallMode::SYNCHRON, pSfxApp->GetPool() );
    2509           0 :     aReq.AppendItem( SfxBoolItem(SID_RECORDMACRO,true) );
    2510           0 :     const SfxPoolItem* pRet = SfxGetpApp()->ExecuteSlot( aReq );
    2511           0 :     OUString aScriptURL;
    2512           0 :     if ( pRet )
    2513           0 :         aScriptURL = static_cast<const SfxStringItem*>(pRet)->GetValue();
    2514           0 :     if ( !aScriptURL.isEmpty() )
    2515             :     {
    2516             :         // parse scriptURL
    2517           0 :         OUString aLibName;
    2518           0 :         OUString aModuleName;
    2519           0 :         OUString aMacroName;
    2520           0 :         OUString aLocation;
    2521           0 :         Reference< XComponentContext > xContext = ::comphelper::getProcessComponentContext();
    2522             :         Reference< com::sun::star::uri::XUriReferenceFactory > xFactory =
    2523           0 :             com::sun::star::uri::UriReferenceFactory::create( xContext );
    2524           0 :         Reference< com::sun::star::uri::XVndSunStarScriptUrl > xUrl( xFactory->parse( aScriptURL ), UNO_QUERY );
    2525           0 :         if ( xUrl.is() )
    2526             :         {
    2527             :             // get name
    2528           0 :             OUString aName = xUrl->getName();
    2529           0 :             sal_Unicode cTok = '.';
    2530           0 :             sal_Int32 nIndex = 0;
    2531           0 :             aLibName = aName.getToken( 0, cTok, nIndex );
    2532           0 :             if ( nIndex != -1 )
    2533           0 :                 aModuleName = aName.getToken( 0, cTok, nIndex );
    2534           0 :             if ( nIndex != -1 )
    2535           0 :                 aMacroName = aName.getToken( 0, cTok, nIndex );
    2536             : 
    2537             :             // get location
    2538           0 :             OUString aLocKey("location");
    2539           0 :             if ( xUrl->hasParameter( aLocKey ) )
    2540           0 :                 aLocation = xUrl->getParameter( aLocKey );
    2541             :         }
    2542             : 
    2543           0 :         BasicManager* pBasMgr = 0;
    2544           0 :         if ( aLocation.equalsIgnoreAsciiCase( "application" ) )
    2545             :         {
    2546             :             // application basic
    2547           0 :             pBasMgr = SfxApplication::GetBasicManager();
    2548             :         }
    2549           0 :         else if ( aLocation.equalsIgnoreAsciiCase( "document" ) )
    2550             :         {
    2551           0 :             pBasMgr = GetObjectShell()->GetBasicManager();
    2552             :         }
    2553             : 
    2554           0 :         OUString aOUSource;
    2555           0 :         if ( pBasMgr)
    2556             :         {
    2557           0 :             StarBASIC* pBasic = pBasMgr->GetLib( aLibName );
    2558           0 :             if ( pBasic )
    2559             :             {
    2560           0 :                 SbModule* pModule = pBasic->FindModule( aModuleName );
    2561           0 :                 if ( pModule )
    2562             :                 {
    2563           0 :                     SbMethod* pMethod = static_cast<SbMethod*>(pModule->GetMethods()->Find( aMacroName, SbxCLASS_METHOD ));
    2564           0 :                     aOUSource = pModule->GetSource32();
    2565             :                     sal_uInt16 nStart, nEnd;
    2566           0 :                     pMethod->GetLineRange( nStart, nEnd );
    2567           0 :                     sal_uIntPtr nlStart = nStart;
    2568           0 :                     sal_uIntPtr nlEnd = nEnd;
    2569           0 :                     CutLines( aOUSource, nlStart-1, nlEnd-nlStart+1, true );
    2570             :                 }
    2571             :             }
    2572             :         }
    2573             : 
    2574             :         // open lib container and break operation if it couldn't be opened
    2575           0 :         com::sun::star::uno::Reference< com::sun::star::script::XLibraryContainer > xLibCont;
    2576           0 :         if ( aLocation.equalsIgnoreAsciiCase( "application" ) )
    2577             :         {
    2578           0 :             xLibCont = SfxGetpApp()->GetBasicContainer();
    2579             :         }
    2580           0 :         else if ( aLocation.equalsIgnoreAsciiCase( "document" ) )
    2581             :         {
    2582           0 :             xLibCont = GetObjectShell()->GetBasicContainer();
    2583             :         }
    2584             : 
    2585           0 :         if(!xLibCont.is())
    2586             :         {
    2587             :             SAL_WARN( "sfx.view", "couldn't get access to the basic lib container. Adding of macro isn't possible." );
    2588           0 :             return;
    2589             :         }
    2590             : 
    2591             :         // get LibraryContainer
    2592           0 :         com::sun::star::uno::Any aTemp;
    2593             :         com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > xRoot(
    2594             :                 xLibCont,
    2595           0 :                 com::sun::star::uno::UNO_QUERY);
    2596             : 
    2597           0 :         OUString sLib( aLibName );
    2598           0 :         com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > xLib;
    2599           0 :         if(xRoot->hasByName(sLib))
    2600             :         {
    2601             :             // library must be loaded
    2602           0 :             aTemp = xRoot->getByName(sLib);
    2603           0 :             xLibCont->loadLibrary(sLib);
    2604           0 :             aTemp >>= xLib;
    2605             :         }
    2606             :         else
    2607             :         {
    2608           0 :             xLib = com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >(
    2609           0 :                         xLibCont->createLibrary(sLib),
    2610           0 :                         com::sun::star::uno::UNO_QUERY);
    2611             :         }
    2612             : 
    2613             :         // pack the macro as direct usable "sub" routine
    2614           0 :         OUString sCode;
    2615           0 :         OUStringBuffer sRoutine(10000);
    2616           0 :         OUString sMacroName( aMacroName );
    2617           0 :         bool bReplace = false;
    2618             : 
    2619             :         // get module
    2620           0 :         OUString sModule( aModuleName );
    2621           0 :         if(xLib->hasByName(sModule))
    2622             :         {
    2623           0 :             if ( !aOUSource.isEmpty() )
    2624             :             {
    2625           0 :                 sRoutine.append( aOUSource );
    2626             :             }
    2627             :             else
    2628             :             {
    2629           0 :                 aTemp = xLib->getByName(sModule);
    2630           0 :                 aTemp >>= sCode;
    2631           0 :                 sRoutine.append( sCode );
    2632             :             }
    2633             : 
    2634           0 :             bReplace = true;
    2635             :         }
    2636             : 
    2637             :         // append new method
    2638           0 :         sRoutine.append( "\nsub " );
    2639           0 :         sRoutine.append(sMacroName);
    2640           0 :         sRoutine.append( "\n" );
    2641           0 :         sRoutine.append(sMacro);
    2642           0 :         sRoutine.append( "\nend sub\n" );
    2643             : 
    2644             :         // create the modul inside the library and insert the macro routine
    2645           0 :         aTemp <<= sRoutine.makeStringAndClear();
    2646           0 :         if ( bReplace )
    2647             :         {
    2648             :             com::sun::star::uno::Reference< com::sun::star::container::XNameContainer > xModulCont(
    2649             :                 xLib,
    2650           0 :                 com::sun::star::uno::UNO_QUERY);
    2651           0 :             xModulCont->replaceByName(sModule,aTemp);
    2652             :         }
    2653             :         else
    2654             :         {
    2655             :             com::sun::star::uno::Reference< com::sun::star::container::XNameContainer > xModulCont(
    2656             :                 xLib,
    2657           0 :                 com::sun::star::uno::UNO_QUERY);
    2658           0 :             xModulCont->insertByName(sModule,aTemp);
    2659             :         }
    2660             : 
    2661             :         // #i17355# update the Basic IDE
    2662           0 :         for ( SfxViewShell* pViewShell = SfxViewShell::GetFirst(); pViewShell; pViewShell = SfxViewShell::GetNext( *pViewShell ) )
    2663             :         {
    2664           0 :             if ( pViewShell->GetName() == "BasicIDE" )
    2665             :             {
    2666           0 :                 SfxViewFrame* pViewFrame = pViewShell->GetViewFrame();
    2667           0 :                 SfxDispatcher* pDispat = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
    2668           0 :                 if ( pDispat )
    2669             :                 {
    2670           0 :                     SfxMacroInfoItem aInfoItem( SID_BASICIDE_ARG_MACROINFO, pBasMgr, aLibName, aModuleName, OUString(), OUString() );
    2671           0 :                     pDispat->Execute( SID_BASICIDE_UPDATEMODULESOURCE, SfxCallMode::SYNCHRON, &aInfoItem, 0L );
    2672             :                 }
    2673             :             }
    2674           0 :         }
    2675             :     }
    2676             :     else
    2677             :     {
    2678             :         // add code for "session only" macro
    2679           0 :     }
    2680             : #endif
    2681             : }
    2682             : 
    2683           0 : void SfxViewFrame::MiscExec_Impl( SfxRequest& rReq )
    2684             : {
    2685           0 :     switch ( rReq.GetSlot() )
    2686             :     {
    2687             :         case SID_STOP_RECORDING :
    2688             :         case SID_RECORDMACRO :
    2689             :         {
    2690             :             // try to find any active recorder on this frame
    2691           0 :             OUString sProperty("DispatchRecorderSupplier");
    2692             :             com::sun::star::uno::Reference< com::sun::star::frame::XFrame > xFrame(
    2693           0 :                     GetFrame().GetFrameInterface(),
    2694           0 :                     com::sun::star::uno::UNO_QUERY);
    2695             : 
    2696           0 :             com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xSet(xFrame,com::sun::star::uno::UNO_QUERY);
    2697           0 :             com::sun::star::uno::Any aProp = xSet->getPropertyValue(sProperty);
    2698           0 :             com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorderSupplier > xSupplier;
    2699           0 :             aProp >>= xSupplier;
    2700           0 :             com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder > xRecorder;
    2701           0 :             if (xSupplier.is())
    2702           0 :                 xRecorder = xSupplier->getDispatchRecorder();
    2703             : 
    2704           0 :             bool bIsRecording = xRecorder.is();
    2705           0 :             SFX_REQUEST_ARG( rReq, pItem, SfxBoolItem, SID_RECORDMACRO, false);
    2706           0 :             if ( pItem && pItem->GetValue() == bIsRecording )
    2707           0 :                 return;
    2708             : 
    2709           0 :             if ( xRecorder.is() )
    2710             :             {
    2711             :                 // disable active recording
    2712           0 :                 aProp <<= com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorderSupplier >();
    2713           0 :                 xSet->setPropertyValue(sProperty,aProp);
    2714             : 
    2715           0 :                 SFX_REQUEST_ARG( rReq, pRecordItem, SfxBoolItem, FN_PARAM_1, false);
    2716           0 :                 if ( !pRecordItem || !pRecordItem->GetValue() )
    2717             :                     // insert script into basic library container of application
    2718           0 :                     AddDispatchMacroToBasic_Impl(xRecorder->getRecordedMacro());
    2719             : 
    2720           0 :                 xRecorder->endRecording();
    2721           0 :                 xRecorder = NULL;
    2722           0 :                 GetBindings().SetRecorder_Impl( xRecorder );
    2723             : 
    2724           0 :                 SetChildWindow( SID_RECORDING_FLOATWINDOW, false );
    2725           0 :                 if ( rReq.GetSlot() != SID_RECORDMACRO )
    2726           0 :                     GetBindings().Invalidate( SID_RECORDMACRO );
    2727             :             }
    2728           0 :             else if ( rReq.GetSlot() == SID_RECORDMACRO )
    2729             :             {
    2730             :                 // enable recording
    2731             :                 com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > xContext(
    2732           0 :                         ::comphelper::getProcessComponentContext());
    2733             : 
    2734           0 :                 xRecorder = com::sun::star::frame::DispatchRecorder::create( xContext );
    2735             : 
    2736           0 :                 xSupplier = com::sun::star::frame::DispatchRecorderSupplier::create( xContext );
    2737             : 
    2738           0 :                 xSupplier->setDispatchRecorder(xRecorder);
    2739           0 :                 xRecorder->startRecording(xFrame);
    2740           0 :                 aProp <<= xSupplier;
    2741           0 :                 xSet->setPropertyValue(sProperty,aProp);
    2742           0 :                 GetBindings().SetRecorder_Impl( xRecorder );
    2743           0 :                 SetChildWindow( SID_RECORDING_FLOATWINDOW, true );
    2744             :             }
    2745             : 
    2746           0 :             rReq.Done();
    2747           0 :             break;
    2748             :         }
    2749             : 
    2750             :         case SID_TOGGLESTATUSBAR:
    2751             :         {
    2752             :             com::sun::star::uno::Reference< com::sun::star::frame::XFrame > xFrame(
    2753           0 :                     GetFrame().GetFrameInterface(),
    2754           0 :                     com::sun::star::uno::UNO_QUERY);
    2755             : 
    2756           0 :             Reference< com::sun::star::beans::XPropertySet > xPropSet( xFrame, UNO_QUERY );
    2757           0 :             Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
    2758           0 :             if ( xPropSet.is() )
    2759             :             {
    2760             :                 try
    2761             :                 {
    2762           0 :                     Any aValue = xPropSet->getPropertyValue("LayoutManager");
    2763           0 :                     aValue >>= xLayoutManager;
    2764             :                 }
    2765           0 :                 catch ( Exception& )
    2766             :                 {
    2767             :                 }
    2768             :             }
    2769             : 
    2770           0 :             if ( xLayoutManager.is() )
    2771             :             {
    2772           0 :                 OUString aStatusbarResString( "private:resource/statusbar/statusbar" );
    2773             :                 // Evaluate parameter.
    2774           0 :                 SFX_REQUEST_ARG(rReq, pShowItem, SfxBoolItem, rReq.GetSlot(), false);
    2775           0 :                 bool bShow( true );
    2776           0 :                 if ( !pShowItem )
    2777           0 :                     bShow = xLayoutManager->isElementVisible( aStatusbarResString );
    2778             :                 else
    2779           0 :                     bShow = pShowItem->GetValue();
    2780             : 
    2781           0 :                 if ( bShow )
    2782             :                 {
    2783           0 :                     xLayoutManager->createElement( aStatusbarResString );
    2784           0 :                     xLayoutManager->showElement( aStatusbarResString );
    2785             :                 }
    2786             :                 else
    2787           0 :                     xLayoutManager->hideElement( aStatusbarResString );
    2788             : 
    2789           0 :                 if ( !pShowItem )
    2790           0 :                     rReq.AppendItem( SfxBoolItem( SID_TOGGLESTATUSBAR, bShow ) );
    2791             :             }
    2792           0 :             rReq.Done();
    2793           0 :             break;
    2794             :         }
    2795             : 
    2796             :         // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    2797             :         case SID_WIN_FULLSCREEN:
    2798             :         {
    2799           0 :             SFX_REQUEST_ARG(rReq, pItem, SfxBoolItem, rReq.GetSlot(), false);
    2800           0 :             SfxViewFrame *pTop = GetTopViewFrame();
    2801           0 :             if ( pTop )
    2802             :             {
    2803           0 :                 WorkWindow* pWork = static_cast<WorkWindow*>( pTop->GetFrame().GetTopWindow_Impl() );
    2804           0 :                 if ( pWork )
    2805             :                 {
    2806             :                     com::sun::star::uno::Reference< com::sun::star::frame::XFrame > xFrame(
    2807           0 :                             GetFrame().GetFrameInterface(),
    2808           0 :                             com::sun::star::uno::UNO_QUERY);
    2809             : 
    2810           0 :                     Reference< ::com::sun::star::beans::XPropertySet > xPropSet( xFrame, UNO_QUERY );
    2811           0 :                     Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
    2812           0 :                     if ( xPropSet.is() )
    2813             :                     {
    2814             :                         try
    2815             :                         {
    2816           0 :                             Any aValue = xPropSet->getPropertyValue("LayoutManager");
    2817           0 :                             aValue >>= xLayoutManager;
    2818             :                         }
    2819           0 :                         catch ( Exception& )
    2820             :                         {
    2821             :                         }
    2822             :                     }
    2823             : 
    2824           0 :                     bool bNewFullScreenMode = pItem ? pItem->GetValue() : !pWork->IsFullScreenMode();
    2825           0 :                     if ( bNewFullScreenMode != pWork->IsFullScreenMode() )
    2826             :                     {
    2827           0 :                         Reference< ::com::sun::star::beans::XPropertySet > xLMPropSet( xLayoutManager, UNO_QUERY );
    2828           0 :                         if ( xLMPropSet.is() )
    2829             :                         {
    2830             :                             try
    2831             :                             {
    2832           0 :                                 xLMPropSet->setPropertyValue(
    2833             :                                     OUString( "HideCurrentUI" ),
    2834           0 :                                     makeAny( bNewFullScreenMode ));
    2835             :                             }
    2836           0 :                             catch ( ::com::sun::star::beans::UnknownPropertyException& )
    2837             :                             {
    2838             :                             }
    2839             :                         }
    2840           0 :                         pWork->ShowFullScreenMode( bNewFullScreenMode );
    2841           0 :                         pWork->SetMenuBarMode( bNewFullScreenMode ? MenuBarMode::Hide : MenuBarMode::Normal );
    2842           0 :                         GetFrame().GetWorkWindow_Impl()->SetFullScreen_Impl( bNewFullScreenMode );
    2843           0 :                         if ( !pItem )
    2844           0 :                             rReq.AppendItem( SfxBoolItem( SID_WIN_FULLSCREEN, bNewFullScreenMode ) );
    2845           0 :                         rReq.Done();
    2846             :                     }
    2847             :                     else
    2848           0 :                         rReq.Ignore();
    2849             :                 }
    2850             :             }
    2851             :             else
    2852           0 :                 rReq.Ignore();
    2853             : 
    2854           0 :             GetDispatcher()->Update_Impl( true );
    2855           0 :             break;
    2856             :         }
    2857             :     }
    2858             : }
    2859             : 
    2860          22 : void SfxViewFrame::MiscState_Impl(SfxItemSet &rSet)
    2861             : {
    2862          22 :     const sal_uInt16 *pRanges = rSet.GetRanges();
    2863             :     DBG_ASSERT(pRanges && *pRanges, "Set without range");
    2864          67 :     while ( *pRanges )
    2865             :     {
    2866          46 :         for(sal_uInt16 nWhich = *pRanges++; nWhich <= *pRanges; ++nWhich)
    2867             :         {
    2868          23 :             switch(nWhich)
    2869             :             {
    2870             :                 case SID_CURRENT_URL:
    2871             :                 {
    2872             :                     // Get the ContainerFrame, when internal InPlace.
    2873           0 :                     SfxViewFrame *pFrame = this;
    2874           0 :                     if ( pFrame->GetParentViewFrame_Impl() )
    2875           0 :                         pFrame = pFrame->GetParentViewFrame_Impl();
    2876           0 :                     rSet.Put( SfxStringItem( nWhich, pFrame->GetActualPresentationURL_Impl() ) );
    2877           0 :                     break;
    2878             :                 }
    2879             : 
    2880             :                 case SID_RECORDMACRO :
    2881             :                 {
    2882           0 :                     SvtMiscOptions aMiscOptions;
    2883           0 :                     const char* pName = GetObjectShell()->GetFactory().GetShortName();
    2884           0 :                     if ( !aMiscOptions.IsMacroRecorderMode() ||
    2885           0 :                          ( strcmp(pName,"swriter") && strcmp(pName,"scalc") ) )
    2886             :                     {
    2887           0 :                         rSet.DisableItem( nWhich );
    2888           0 :                         rSet.Put(SfxVisibilityItem(nWhich, false));
    2889           0 :                         break;
    2890             :                     }
    2891             : 
    2892           0 :                     OUString sProperty("DispatchRecorderSupplier");
    2893             :                     com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xSet(
    2894           0 :                             GetFrame().GetFrameInterface(),
    2895           0 :                             com::sun::star::uno::UNO_QUERY);
    2896             : 
    2897           0 :                     com::sun::star::uno::Any aProp = xSet->getPropertyValue(sProperty);
    2898           0 :                     com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorderSupplier > xSupplier;
    2899           0 :                     if ( aProp >>= xSupplier )
    2900           0 :                         rSet.Put( SfxBoolItem( nWhich, xSupplier.is() ) );
    2901             :                     else
    2902           0 :                         rSet.DisableItem( nWhich );
    2903           0 :                     break;
    2904             :                 }
    2905             : 
    2906             :                 case SID_STOP_RECORDING :
    2907             :                 {
    2908           0 :                     SvtMiscOptions aMiscOptions;
    2909           0 :                     const char* pName = GetObjectShell()->GetFactory().GetShortName();
    2910           0 :                     if ( !aMiscOptions.IsMacroRecorderMode() ||
    2911           0 :                          ( strcmp(pName,"swriter") && strcmp(pName,"scalc") ) )
    2912             :                     {
    2913           0 :                         rSet.DisableItem( nWhich );
    2914           0 :                         break;
    2915             :                     }
    2916             : 
    2917           0 :                     OUString sProperty("DispatchRecorderSupplier");
    2918             :                     com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xSet(
    2919           0 :                             GetFrame().GetFrameInterface(),
    2920           0 :                             com::sun::star::uno::UNO_QUERY);
    2921             : 
    2922           0 :                     com::sun::star::uno::Any aProp = xSet->getPropertyValue(sProperty);
    2923           0 :                     com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorderSupplier > xSupplier;
    2924           0 :                     if ( !(aProp >>= xSupplier) || !xSupplier.is() )
    2925           0 :                         rSet.DisableItem( nWhich );
    2926           0 :                     break;
    2927             :                 }
    2928             : 
    2929             :                 case SID_TOGGLESTATUSBAR:
    2930             :                 {
    2931           5 :                     com::sun::star::uno::Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
    2932             :                     com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > xSet(
    2933           5 :                             GetFrame().GetFrameInterface(),
    2934          10 :                             com::sun::star::uno::UNO_QUERY);
    2935           5 :                     com::sun::star::uno::Any aProp = xSet->getPropertyValue(
    2936          10 :                         OUString( "LayoutManager" ) );
    2937             : 
    2938           5 :                     if ( !( aProp >>= xLayoutManager ))
    2939           0 :                         rSet.Put( SfxBoolItem( nWhich, false ));
    2940             :                     else
    2941             :                     {
    2942           5 :                         OUString aStatusbarResString( "private:resource/statusbar/statusbar" );
    2943           5 :                         bool bShow = xLayoutManager->isElementVisible( aStatusbarResString );
    2944           5 :                         rSet.Put( SfxBoolItem( nWhich, bShow ));
    2945             :                     }
    2946          10 :                     break;
    2947             :                 }
    2948             : 
    2949             :                 case SID_WIN_FULLSCREEN:
    2950             :                 {
    2951          18 :                     SfxViewFrame* pTop = GetTopViewFrame();
    2952          18 :                     if ( pTop )
    2953             :                     {
    2954          18 :                         WorkWindow* pWork = static_cast<WorkWindow*>( pTop->GetFrame().GetTopWindow_Impl() );
    2955          18 :                         if ( pWork )
    2956             :                         {
    2957          18 :                             rSet.Put( SfxBoolItem( nWhich, pWork->IsFullScreenMode() ) );
    2958          18 :                             break;
    2959             :                         }
    2960             :                     }
    2961             : 
    2962           0 :                     rSet.DisableItem( nWhich );
    2963           0 :                     break;
    2964             :                 }
    2965             : 
    2966             :                 case SID_FORMATMENUSTATE :
    2967             :                 {
    2968             :                     OSL_FAIL("Outdated slot!");
    2969           0 :                     rSet.DisableItem( nWhich );
    2970           0 :                     break;
    2971             :                 }
    2972             : 
    2973             :                 default:
    2974           0 :                     break;
    2975             :             }
    2976             :         }
    2977             : 
    2978          23 :         ++pRanges;
    2979             :     }
    2980          22 : }
    2981             : 
    2982             : /*  [Description]
    2983             : 
    2984             :     This method can be included in the Execute method for the on- and off-
    2985             :     switching of ChildWindows, to implement this and API-bindings.
    2986             : 
    2987             :     Simply include as 'ExecuteMethod' in the IDL.
    2988             : */
    2989           1 : void SfxViewFrame::ChildWindowExecute( SfxRequest &rReq )
    2990             : {
    2991             :     // Evaluate Parameter
    2992           1 :     sal_uInt16 nSID = rReq.GetSlot();
    2993             : 
    2994           1 :     SFX_REQUEST_ARG(rReq, pShowItem, SfxBoolItem, nSID, false);
    2995           1 :     if ( nSID == SID_VIEW_DATA_SOURCE_BROWSER )
    2996             :     {
    2997           1 :         if (!SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::EModule::DATABASE))
    2998           0 :             return;
    2999           1 :         Reference < XFrame > xFrame = GetFrame().GetTopFrame().GetFrameInterface();
    3000           2 :         Reference < XFrame > xBeamer( xFrame->findFrame( "_beamer", FrameSearchFlag::CHILDREN ) );
    3001           1 :         bool bHasChild = xBeamer.is();
    3002           1 :         bool bShow = pShowItem ? pShowItem->GetValue() : !bHasChild;
    3003           1 :         if ( pShowItem )
    3004             :         {
    3005           0 :             if( bShow == bHasChild )
    3006           0 :                 return;
    3007             :         }
    3008             :         else
    3009           1 :             rReq.AppendItem( SfxBoolItem( nSID, bShow ) );
    3010             : 
    3011           1 :         if ( !bShow )
    3012             :         {
    3013           0 :             SetChildWindow( SID_BROWSER, false );
    3014             :         }
    3015             :         else
    3016             :         {
    3017           1 :             ::com::sun::star::util::URL aTargetURL;
    3018           1 :             aTargetURL.Complete = ".component:DB/DataSourceBrowser";
    3019             :             Reference < ::com::sun::star::util::XURLTransformer > xTrans(
    3020             :                     ::com::sun::star::util::URLTransformer::create(
    3021           2 :                          ::comphelper::getProcessComponentContext() ) );
    3022           1 :             xTrans->parseStrict( aTargetURL );
    3023             : 
    3024           2 :             Reference < XDispatchProvider > xProv( xFrame, UNO_QUERY );
    3025           2 :             Reference < ::com::sun::star::frame::XDispatch > xDisp;
    3026           1 :             if ( xProv.is() )
    3027           1 :                 xDisp = xProv->queryDispatch( aTargetURL, OUString("_beamer"), 31 );
    3028           1 :             if ( xDisp.is() )
    3029             :             {
    3030           1 :                 Sequence < ::com::sun::star::beans::PropertyValue > aArgs(1);
    3031           1 :                 ::com::sun::star::beans::PropertyValue* pArg = aArgs.getArray();
    3032           1 :                 pArg[0].Name = "Referer";
    3033           1 :                 pArg[0].Value <<= OUString("private:user");
    3034           1 :                 xDisp->dispatch( aTargetURL, aArgs );
    3035           1 :             }
    3036             :         }
    3037             : 
    3038           1 :         rReq.Done();
    3039           2 :         return;
    3040             :     }
    3041           0 :     if (nSID == SID_STYLE_DESIGNER)
    3042             :     {
    3043             :         // First make sure that the sidebar is visible
    3044           0 :         ShowChildWindow(SID_SIDEBAR);
    3045             : 
    3046             :         ::sfx2::sidebar::Sidebar::ShowPanel("StyleListPanel",
    3047           0 :                                             GetFrame().GetFrameInterface());
    3048           0 :         rReq.Done();
    3049           0 :         return;
    3050             :     }
    3051             : 
    3052           0 :     bool bHasChild = HasChildWindow(nSID);
    3053           0 :     bool bShow = pShowItem ? pShowItem->GetValue() : !bHasChild;
    3054           0 :     GetDispatcher()->Update_Impl( true );
    3055             : 
    3056             :     // Perform action.
    3057           0 :     if ( !pShowItem || bShow != bHasChild )
    3058           0 :         ToggleChildWindow( nSID );
    3059             : 
    3060           0 :     GetBindings().Invalidate( nSID );
    3061             : 
    3062             :     // Record if possible.
    3063           0 :     if ( nSID == SID_HYPERLINK_DIALOG || nSID == SID_SEARCH_DLG )
    3064             :     {
    3065           0 :         rReq.Ignore();
    3066             :     }
    3067             :     else
    3068             :     {
    3069           0 :         rReq.AppendItem( SfxBoolItem( nSID, bShow ) );
    3070           0 :         rReq.Done();
    3071             :     }
    3072             : }
    3073             : 
    3074             : /*  [Description]
    3075             : 
    3076             :     This method can be used in the state method for the on and off-state
    3077             :     of child-windows, in order to implement this.
    3078             : 
    3079             :     Just register the IDL as 'StateMethod'.
    3080             : */
    3081        2152 : void SfxViewFrame::ChildWindowState( SfxItemSet& rState )
    3082             : {
    3083        2152 :     SfxWhichIter aIter( rState );
    3084        5016 :     for ( sal_uInt16 nSID = aIter.FirstWhich(); nSID; nSID = aIter.NextWhich() )
    3085             :     {
    3086        2864 :         if ( nSID == SID_VIEW_DATA_SOURCE_BROWSER )
    3087             :         {
    3088         249 :             rState.Put( SfxBoolItem( nSID, HasChildWindow( SID_BROWSER ) ) );
    3089             :         }
    3090        2615 :         else if ( nSID == SID_HYPERLINK_DIALOG )
    3091             :         {
    3092         374 :             const SfxPoolItem* pDummy = NULL;
    3093         374 :             SfxItemState eState = GetDispatcher()->QueryState( SID_HYPERLINK_SETLINK, pDummy );
    3094         374 :             if ( SfxItemState::DISABLED == eState )
    3095          13 :                 rState.DisableItem(nSID);
    3096             :             else
    3097             :             {
    3098         361 :                 if ( KnowsChildWindow(nSID) )
    3099         361 :                     rState.Put( SfxBoolItem( nSID, HasChildWindow(nSID)) );
    3100             :                 else
    3101           0 :                     rState.DisableItem(nSID);
    3102             :             }
    3103             :         }
    3104        2241 :         else if ( nSID == SID_BROWSER )
    3105             :         {
    3106           0 :             Reference < XFrame > xFrame = GetFrame().GetTopFrame().GetFrameInterface()->
    3107           0 :                             findFrame( "_beamer", FrameSearchFlag::CHILDREN );
    3108           0 :             if ( !xFrame.is() )
    3109           0 :                 rState.DisableItem( nSID );
    3110           0 :             else if ( KnowsChildWindow(nSID) )
    3111           0 :                 rState.Put( SfxBoolItem( nSID, HasChildWindow(nSID) ) );
    3112             :         }
    3113        2241 :         else if ( nSID == SID_TASKPANE )
    3114             :         {
    3115           0 :             if  ( !KnowsChildWindow( nSID ) )
    3116             :             {
    3117             :                 OSL_FAIL( "SID_TASKPANE state requested, but no task pane child window exists for this ID!" );
    3118           0 :                 rState.DisableItem( nSID );
    3119             :             }
    3120           0 :             else if ( !moduleHasToolPanels( *pImp ) )
    3121             :             {
    3122           0 :                 rState.Put( SfxVisibilityItem( nSID, false ) );
    3123             :             }
    3124             :             else
    3125             :             {
    3126           0 :                 rState.Put( SfxBoolItem( nSID, HasChildWindow( nSID ) ) );
    3127             :             }
    3128             :         }
    3129        2241 :         else if ( nSID == SID_SIDEBAR )
    3130             :         {
    3131           5 :             if  ( !KnowsChildWindow( nSID ) )
    3132             :             {
    3133             :                 OSL_ENSURE( false, "SID_TASKPANE state requested, but no task pane child window exists for this ID!" );
    3134           0 :                 rState.DisableItem( nSID );
    3135             :             }
    3136             :             else
    3137             :             {
    3138           5 :                 rState.Put( SfxBoolItem( nSID, HasChildWindow( nSID ) ) );
    3139             :             }
    3140             :         }
    3141        2236 :         else if ( KnowsChildWindow(nSID) )
    3142        2210 :             rState.Put( SfxBoolItem( nSID, HasChildWindow(nSID) ) );
    3143             :         else
    3144          26 :             rState.DisableItem(nSID);
    3145        2152 :     }
    3146        2152 : }
    3147             : 
    3148      138125 : SfxWorkWindow* SfxViewFrame::GetWorkWindow_Impl( sal_uInt16 /*nId*/ )
    3149             : {
    3150      138125 :     SfxWorkWindow* pWork = GetFrame().GetWorkWindow_Impl();
    3151      138125 :     return pWork;
    3152             : }
    3153             : 
    3154        5726 : void SfxViewFrame::SetChildWindow(sal_uInt16 nId, bool bOn, bool bSetFocus )
    3155             : {
    3156        5726 :     SfxWorkWindow* pWork = GetWorkWindow_Impl( nId );
    3157        5726 :     if ( pWork )
    3158        5726 :         pWork->SetChildWindow_Impl( nId, bOn, bSetFocus );
    3159        5726 : }
    3160             : 
    3161           0 : void SfxViewFrame::ToggleChildWindow(sal_uInt16 nId)
    3162             : {
    3163           0 :     SfxWorkWindow* pWork = GetWorkWindow_Impl( nId );
    3164           0 :     if ( pWork )
    3165           0 :         pWork->ToggleChildWindow_Impl( nId, true );
    3166           0 : }
    3167             : 
    3168        7965 : bool SfxViewFrame::HasChildWindow( sal_uInt16 nId )
    3169             : {
    3170        7965 :     SfxWorkWindow* pWork = GetWorkWindow_Impl( nId );
    3171        7965 :     return pWork && pWork->HasChildWindow_Impl(nId);
    3172             : }
    3173             : 
    3174        3554 : bool SfxViewFrame::KnowsChildWindow( sal_uInt16 nId )
    3175             : {
    3176        3554 :     SfxWorkWindow* pWork = GetWorkWindow_Impl( nId );
    3177        3554 :     return pWork && pWork->KnowsChildWindow_Impl(nId);
    3178             : }
    3179             : 
    3180           1 : void SfxViewFrame::ShowChildWindow( sal_uInt16 nId, bool bVisible )
    3181             : {
    3182           1 :     SfxWorkWindow* pWork = GetWorkWindow_Impl( nId );
    3183           1 :     if ( pWork )
    3184             :     {
    3185           1 :         GetDispatcher()->Update_Impl(true);
    3186           1 :         pWork->ShowChildWindow_Impl(nId, bVisible, true );
    3187             :     }
    3188           1 : }
    3189             : 
    3190      120879 : SfxChildWindow* SfxViewFrame::GetChildWindow(sal_uInt16 nId)
    3191             : {
    3192      120879 :     SfxWorkWindow* pWork = GetWorkWindow_Impl( nId );
    3193      120879 :     return pWork ? pWork->GetChildWindow_Impl(nId) : NULL;
    3194             : }
    3195             : 
    3196        3249 : void SfxViewFrame::UpdateDocument_Impl()
    3197             : {
    3198        3249 :     SfxObjectShell* pDoc = GetObjectShell();
    3199        3249 :     if ( pDoc->IsLoadingFinished() )
    3200        3248 :         pDoc->CheckSecurityOnLoading_Impl();
    3201             : 
    3202             :     // check if document depends on a template
    3203        3249 :     pDoc->UpdateFromTemplate_Impl();
    3204        3249 : }
    3205             : 
    3206       10565 : void SfxViewFrame::SetViewFrame( SfxViewFrame* pFrame )
    3207             : {
    3208       10565 :     SfxGetpApp()->SetViewFrame_Impl( pFrame );
    3209       10565 : }
    3210             : 
    3211           0 : void SfxViewFrame::ActivateToolPanel( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& i_rFrame, const OUString& i_rPanelURL )
    3212             : {
    3213           0 :     SolarMutexGuard aGuard;
    3214             : 
    3215             :     // look up the SfxFrame for the given XFrame
    3216           0 :     SfxFrame* pFrame = NULL;
    3217           0 :     for ( pFrame = SfxFrame::GetFirst(); pFrame; pFrame = SfxFrame::GetNext( *pFrame ) )
    3218             :     {
    3219           0 :         if ( pFrame->GetFrameInterface() == i_rFrame )
    3220           0 :             break;
    3221             :     }
    3222           0 :     SfxViewFrame* pViewFrame = pFrame ? pFrame->GetCurrentViewFrame() : NULL;
    3223           0 :     ENSURE_OR_RETURN_VOID( pViewFrame != NULL, "SfxViewFrame::ActivateToolPanel: did not find an SfxFrame for the given XFrame!" );
    3224             : 
    3225           0 :     pViewFrame->ActivateToolPanel_Impl( i_rPanelURL );
    3226             : }
    3227             : 
    3228           0 : void SfxViewFrame::ActivateToolPanel_Impl( const OUString& i_rPanelURL )
    3229             : {
    3230             :     // ensure the task pane is visible
    3231           0 :     ENSURE_OR_RETURN_VOID( KnowsChildWindow( SID_TASKPANE ), "SfxViewFrame::ActivateToolPanel: this frame/module does not allow for a task pane!" );
    3232           0 :     if ( !HasChildWindow( SID_TASKPANE ) )
    3233           0 :         ToggleChildWindow( SID_TASKPANE );
    3234             : 
    3235           0 :     SfxChildWindow* pTaskPaneChildWindow = GetChildWindow( SID_TASKPANE );
    3236           0 :     ENSURE_OR_RETURN_VOID( pTaskPaneChildWindow, "SfxViewFrame::ActivateToolPanel_Impl: just switched it on, but it is not there!" );
    3237             : 
    3238           0 :     ::sfx2::ITaskPaneToolPanelAccess* pPanelAccess = dynamic_cast< ::sfx2::ITaskPaneToolPanelAccess* >( pTaskPaneChildWindow );
    3239           0 :     ENSURE_OR_RETURN_VOID( pPanelAccess, "SfxViewFrame::ActivateToolPanel_Impl: task pane child window does not implement a required interface!" );
    3240           0 :     pPanelAccess->ActivateToolPanel( i_rPanelURL );
    3241             : }
    3242             : 
    3243           1 : SfxInfoBarWindow* SfxViewFrame::AppendInfoBar( const OUString& sId, const OUString& sMessage )
    3244             : {
    3245           1 :     const sal_uInt16 nId = SfxInfoBarContainerChild::GetChildWindowId();
    3246             : 
    3247             :     // Make sure the InfoBar container is visible
    3248           1 :     if (!HasChildWindow(nId))
    3249           0 :         ToggleChildWindow(nId);
    3250             : 
    3251           1 :     SfxChildWindow* pChild = GetChildWindow(nId);
    3252           1 :     if (pChild)
    3253             :     {
    3254           1 :         SfxInfoBarContainerWindow* pInfoBarContainer = static_cast<SfxInfoBarContainerWindow*>(pChild->GetWindow());
    3255           1 :         SfxInfoBarWindow* pInfoBar = pInfoBarContainer->appendInfoBar(sId, sMessage);
    3256           1 :         ShowChildWindow(nId);
    3257           1 :         return pInfoBar;
    3258             :     }
    3259           0 :     return NULL;
    3260             : }
    3261             : 
    3262           0 : void SfxViewFrame::RemoveInfoBar( const OUString& sId )
    3263             : {
    3264           0 :     const sal_uInt16 nId = SfxInfoBarContainerChild::GetChildWindowId();
    3265             : 
    3266             :     // Make sure the InfoBar container is visible
    3267           0 :     if (!HasChildWindow(nId))
    3268           0 :         ToggleChildWindow(nId);
    3269             : 
    3270           0 :     SfxChildWindow* pChild = GetChildWindow(nId);
    3271           0 :     if (pChild)
    3272             :     {
    3273           0 :         SfxInfoBarContainerWindow* pInfoBarContainer = static_cast<SfxInfoBarContainerWindow*>(pChild->GetWindow());
    3274           0 :         SfxInfoBarWindow* pInfoBar = pInfoBarContainer->getInfoBar(sId);
    3275           0 :         pInfoBarContainer->removeInfoBar(pInfoBar);
    3276           0 :         ShowChildWindow(nId);
    3277             :     }
    3278         648 : }
    3279             : 
    3280             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11