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

Generated by: LCOV version 1.10