LCOV - code coverage report
Current view: top level - sfx2/source/view - viewfrm2.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 159 0.0 %
Date: 2014-04-14 Functions: 0 10 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             : 
      21             : #include "impviewframe.hxx"
      22             : #include "statcach.hxx"
      23             : #include <sfx2/viewfac.hxx>
      24             : #include "workwin.hxx"
      25             : 
      26             : #include <sfx2/app.hxx>
      27             : #include <sfx2/bindings.hxx>
      28             : #include <sfx2/ctrlitem.hxx>
      29             : #include <sfx2/dispatch.hxx>
      30             : #include <sfx2/docfac.hxx>
      31             : #include <sfx2/docfile.hxx>
      32             : #include <sfx2/objitem.hxx>
      33             : #include <sfx2/objsh.hxx>
      34             : #include <sfx2/request.hxx>
      35             : #include <sfx2/viewfrm.hxx>
      36             : #include <sfx2/viewsh.hxx>
      37             : 
      38             : #include <com/sun/star/util/XCloseable.hpp>
      39             : 
      40             : #include <svtools/asynclink.hxx>
      41             : #include <svl/eitem.hxx>
      42             : #include <svl/intitem.hxx>
      43             : #include <svl/rectitem.hxx>
      44             : #include <svl/stritem.hxx>
      45             : #include <tools/diagnose_ex.h>
      46             : #include <tools/urlobj.hxx>
      47             : #include <vcl/window.hxx>
      48             : 
      49             : using namespace ::com::sun::star;
      50             : using namespace ::com::sun::star::uno;
      51             : using namespace ::com::sun::star::frame;
      52             : using namespace ::com::sun::star::util;
      53             : using namespace ::com::sun::star::container;
      54             : using namespace ::com::sun::star::beans;
      55             : using ::com::sun::star::lang::XMultiServiceFactory;
      56             : using ::com::sun::star::lang::XComponent;
      57             : 
      58             : 
      59           0 : void SfxFrameViewWindow_Impl::StateChanged( StateChangedType nStateChange )
      60             : {
      61           0 :     if ( nStateChange == STATE_CHANGE_INITSHOW )
      62             :     {
      63           0 :         SfxObjectShell* pDoc = pFrame->GetObjectShell();
      64           0 :         if ( pDoc && !pFrame->IsVisible() )
      65           0 :             pFrame->Show();
      66             : 
      67           0 :         pFrame->Resize();
      68             :     }
      69             :     else
      70           0 :         Window::StateChanged( nStateChange );
      71           0 : }
      72             : 
      73           0 : void SfxFrameViewWindow_Impl::Resize()
      74             : {
      75           0 :     if ( IsReallyVisible() || IsReallyShown() || GetOutputSizePixel().Width() )
      76           0 :         pFrame->Resize();
      77           0 : }
      78             : 
      79             : 
      80             : 
      81             : 
      82           0 : void SfxViewFrame::UpdateTitle()
      83             : 
      84             : /*  [Description]
      85             : 
      86             :     With this method, can the SfxViewFrame be forced to immediately provide
      87             :     the new title from the <SfxObjectShell>.
      88             : 
      89             :     [Note]
      90             : 
      91             :     This is for example necessary if one listens to the SfxObjectShell as
      92             :     SfxListener and then react on the <SfxSimpleHint> SFX_HINT_TITLECHANGED,
      93             :     then query the title of his views. However these views (SfxTopViewFrames)
      94             :     are  also SfxListener and because the order of notifications might not be
      95             :     fixed, the title update will be enforced in advance.
      96             : 
      97             :     [Example]
      98             : 
      99             :     void SwDocShell::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
     100             :     {
     101             :         if ( rHint.IsA(TYPE(SfxSimpleHint)) )
     102             :         {
     103             :             switch( ( (SfxSimpleHint&) rHint ).GetId() )
     104             :             {
     105             :                 case SFX_HINT_TITLECHANGED:
     106             :                     for ( SfxViewFrame *pTop = SfxViewFrame::GetFirst( this );
     107             :                           pTop;
     108             :                           pTop = SfxViewFrame::GetNext( this );
     109             :                     {
     110             :                         pTop->UpdateTitle();
     111             :                         ... pTop->GetName() ...
     112             :                     }
     113             :                     break;
     114             :                 ...
     115             :             }
     116             :         }
     117             :     }
     118             : */
     119             : 
     120             : {
     121             : 
     122           0 :     const SfxObjectFactory &rFact = GetObjectShell()->GetFactory();
     123           0 :     pImp->aFactoryName = OUString::createFromAscii(rFact.GetShortName());
     124             : 
     125           0 :     SfxObjectShell *pObjSh = GetObjectShell();
     126           0 :     if ( !pObjSh )
     127           0 :         return;
     128             : 
     129             : 
     130           0 :     const SfxMedium *pMedium = pObjSh->GetMedium();
     131           0 :     OUString aURL;
     132           0 :     GetFrame();  // -Wall required??
     133           0 :     if ( pObjSh->HasName() )
     134             :     {
     135           0 :         INetURLObject aTmp( pMedium->GetName() );
     136           0 :         aURL = aTmp.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
     137             :     }
     138             : 
     139           0 :     if ( aURL != pImp->aActualURL )
     140             :         // URL has changed
     141           0 :         pImp->aActualURL = aURL;
     142             : 
     143             :     // SbxObjects name
     144           0 :     OUString aSbxName = pObjSh->SfxShell::GetName();
     145           0 :     if ( IsVisible() )
     146             :     {
     147           0 :         aSbxName += ":";
     148           0 :         aSbxName += OUString::number(pImp->nDocViewNo);
     149             :     }
     150             : 
     151           0 :     SetName( aSbxName );
     152           0 :     GetBindings().Invalidate( SID_CURRENT_URL );
     153           0 :     GetBindings().Invalidate( SID_NEWDOCDIRECT );
     154             : }
     155             : 
     156           0 : void SfxViewFrame::Exec_Impl(SfxRequest &rReq )
     157             : {
     158             :     // If presently the shells are replaced...
     159           0 :     if ( !GetObjectShell() || !GetViewShell() )
     160           0 :         return;
     161             : 
     162           0 :     switch ( rReq.GetSlot() )
     163             :     {
     164             :         case SID_SHOWPOPUPS :
     165             :         {
     166           0 :             SFX_REQUEST_ARG(rReq, pShowItem, SfxBoolItem, SID_SHOWPOPUPS, false);
     167           0 :             bool bShow = pShowItem ? pShowItem->GetValue() : sal_True;
     168           0 :             SFX_REQUEST_ARG(rReq, pIdItem, SfxUInt16Item, SID_CONFIGITEMID, false);
     169           0 :             sal_uInt16 nId = pIdItem ? pIdItem->GetValue() : 0;
     170             : 
     171           0 :             SfxWorkWindow *pWorkWin = GetFrame().GetWorkWindow_Impl();
     172           0 :             if ( bShow )
     173             :             {
     174             :                 // First, make the floats viewable
     175           0 :                 pWorkWin->MakeChildrenVisible_Impl( bShow );
     176           0 :                 GetDispatcher()->Update_Impl( true );
     177             : 
     178             :                 // Then view it
     179           0 :                 GetBindings().HidePopups( !bShow );
     180             :             }
     181             :             else
     182             :             {
     183             :                 // Hide all
     184           0 :                 SfxBindings *pBind = &GetBindings();
     185           0 :                 while ( pBind )
     186             :                 {
     187           0 :                     pBind->HidePopupCtrls_Impl( !bShow );
     188           0 :                     pBind = pBind->GetSubBindings_Impl();
     189             :                 }
     190             : 
     191           0 :                 pWorkWin->HidePopups_Impl( !bShow, true, nId );
     192           0 :                 pWorkWin->MakeChildrenVisible_Impl( bShow );
     193             :             }
     194             : 
     195           0 :             Invalidate( rReq.GetSlot() );
     196           0 :             rReq.Done();
     197           0 :             break;
     198             :         }
     199             : 
     200             :         case SID_ACTIVATE:
     201             :         {
     202           0 :             MakeActive_Impl( true );
     203           0 :             rReq.SetReturnValue( SfxObjectItem( 0, this ) );
     204           0 :             break;
     205             :         }
     206             : 
     207             :         case SID_NEWDOCDIRECT :
     208             :         {
     209           0 :             SFX_REQUEST_ARG( rReq, pFactoryItem, SfxStringItem, SID_NEWDOCDIRECT, false);
     210           0 :             OUString aFactName;
     211           0 :             if ( pFactoryItem )
     212           0 :                 aFactName = pFactoryItem->GetValue();
     213           0 :             else if ( !pImp->aFactoryName.isEmpty() )
     214           0 :                 aFactName = pImp->aFactoryName;
     215             :             else
     216             :             {
     217             :                 OSL_FAIL("Missing argument!");
     218           0 :                 break;
     219             :             }
     220             : 
     221           0 :             SfxRequest aReq( SID_OPENDOC, SFX_CALLMODE_SYNCHRON, GetPool() );
     222           0 :             OUString aFact("private:factory/");
     223           0 :             aFact += aFactName;
     224           0 :             aReq.AppendItem( SfxStringItem( SID_FILE_NAME, aFact ) );
     225           0 :             aReq.AppendItem( SfxFrameItem( SID_DOCFRAME, &GetFrame() ) );
     226           0 :             aReq.AppendItem( SfxStringItem( SID_TARGETNAME, OUString( "_blank" ) ) );
     227           0 :             SFX_APP()->ExecuteSlot( aReq );
     228           0 :             const SfxViewFrameItem* pItem = PTR_CAST( SfxViewFrameItem, aReq.GetReturnValue() );
     229           0 :             if ( pItem )
     230           0 :                 rReq.SetReturnValue( SfxFrameItem( 0, pItem->GetFrame() ) );
     231           0 :             break;
     232             :         }
     233             : 
     234             :         case SID_CLOSEWIN:
     235             :         {
     236             :             // disable CloseWin, if frame is not a task
     237           0 :             Reference < XCloseable > xTask( GetFrame().GetFrameInterface(),  UNO_QUERY );
     238           0 :             if ( !xTask.is() )
     239           0 :                 break;
     240             : 
     241           0 :             if ( GetViewShell()->PrepareClose() )
     242             :             {
     243             :                 // More Views on the same Document?
     244           0 :                 SfxObjectShell *pDocSh = GetObjectShell();
     245           0 :                 bool bOther = false;
     246           0 :                 for ( const SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pDocSh );
     247           0 :                       !bOther && pFrame;
     248             :                       pFrame = SfxViewFrame::GetNext( *pFrame, pDocSh ) )
     249           0 :                     bOther = (pFrame != this);
     250             : 
     251             :                 // Document only needs to be queried, if no other View present.
     252           0 :                 bool bClosed = false;
     253           0 :                 bool bUI = true;
     254           0 :                 if ( ( bOther || pDocSh->PrepareClose( bUI ) ) )
     255             :                 {
     256           0 :                     if ( !bOther )
     257           0 :                         pDocSh->SetModified( false );
     258           0 :                     rReq.Done(); // Must call this before Close()!
     259           0 :                     bClosed = false;
     260             :                     try
     261             :                     {
     262           0 :                         xTask->close(sal_True);
     263           0 :                         bClosed = true;
     264             :                     }
     265           0 :                     catch( CloseVetoException& )
     266             :                     {
     267           0 :                         bClosed = false;
     268             :                     }
     269             :                 }
     270             : 
     271           0 :                 rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bClosed ));
     272             :             }
     273           0 :             return;
     274             :         }
     275             :     }
     276             : 
     277           0 :     rReq.Done();
     278             : }
     279             : 
     280           0 : void SfxViewFrame::GetState_Impl( SfxItemSet &rSet )
     281             : {
     282           0 :     SfxObjectShell *pDocSh = GetObjectShell();
     283             : 
     284           0 :     if ( !pDocSh )
     285           0 :         return;
     286             : 
     287           0 :     const sal_uInt16 *pRanges = rSet.GetRanges();
     288             :     DBG_ASSERT(pRanges, "Set without Range");
     289           0 :     while ( *pRanges )
     290             :     {
     291           0 :         for ( sal_uInt16 nWhich = *pRanges++; nWhich <= *pRanges; ++nWhich )
     292             :         {
     293           0 :             switch(nWhich)
     294             :             {
     295             :             case SID_NEWDOCDIRECT :
     296             :             {
     297           0 :                 if ( !pImp->aFactoryName.isEmpty() )
     298             :                 {
     299           0 :                     OUString aFact("private:factory/");
     300           0 :                     aFact += pImp->aFactoryName;
     301           0 :                     rSet.Put( SfxStringItem( nWhich, aFact ) );
     302             :                 }
     303           0 :                 break;
     304             :             }
     305             : 
     306             :             case SID_NEWWINDOW:
     307           0 :                 rSet.DisableItem(nWhich);
     308           0 :                 break;
     309             : 
     310             :             case SID_CLOSEWIN:
     311             :             {
     312             :                 // disable CloseWin, if frame is not a task
     313           0 :                 Reference < XCloseable > xTask( GetFrame().GetFrameInterface(),  UNO_QUERY );
     314           0 :                 if ( !xTask.is() )
     315           0 :                     rSet.DisableItem(nWhich);
     316           0 :                 break;
     317             :             }
     318             : 
     319             :             case SID_SHOWPOPUPS :
     320           0 :                 break;
     321             : 
     322             :             case SID_OBJECT:
     323           0 :                 if ( GetViewShell() && GetViewShell()->GetVerbs().getLength() && !GetObjectShell()->IsInPlaceActive() )
     324             :                 {
     325           0 :                     uno::Any aAny;
     326           0 :                     aAny <<= GetViewShell()->GetVerbs();
     327           0 :                     rSet.Put( SfxUnoAnyItem( sal_uInt16( SID_OBJECT ), aAny ) );
     328             :                 }
     329             :                 else
     330           0 :                     rSet.DisableItem( SID_OBJECT );
     331           0 :                 break;
     332             : 
     333             :             default:
     334             :                 OSL_FAIL( "invalid message-id" );
     335             :             }
     336             :         }
     337           0 :         ++pRanges;
     338             :     }
     339             : }
     340             : 
     341           0 : void SfxViewFrame::INetExecute_Impl( SfxRequest &rRequest )
     342             : {
     343           0 :     sal_uInt16 nSlotId = rRequest.GetSlot();
     344           0 :     switch( nSlotId )
     345             :     {
     346             :         case SID_BROWSE_FORWARD:
     347             :         case SID_BROWSE_BACKWARD:
     348             :             OSL_FAIL( "SfxViewFrame::INetExecute_Impl: SID_BROWSE_FORWARD/BACKWARD are dead!" );
     349           0 :             break;
     350             :         case SID_CREATELINK:
     351             :         {
     352             : /*! (pb) we need new implementation to create a link
     353             : */
     354           0 :             break;
     355             :         }
     356             :         case SID_FOCUSURLBOX:
     357             :         {
     358           0 :             SfxStateCache *pCache = GetBindings().GetAnyStateCache_Impl( SID_OPENURL );
     359           0 :             if( pCache )
     360             :             {
     361           0 :                 SfxControllerItem* pCtrl = pCache->GetItemLink();
     362           0 :                 while( pCtrl )
     363             :                 {
     364           0 :                     pCtrl->StateChanged( SID_FOCUSURLBOX, SFX_ITEM_UNKNOWN, 0 );
     365           0 :                     pCtrl = pCtrl->GetItemLink();
     366             :                 }
     367             :             }
     368             :         }
     369             :     }
     370             : 
     371             :     // Recording
     372           0 :     rRequest.Done();
     373           0 : }
     374             : 
     375           0 : void SfxViewFrame::INetState_Impl( SfxItemSet &rItemSet )
     376             : {
     377           0 :     rItemSet.DisableItem( SID_BROWSE_FORWARD );
     378           0 :     rItemSet.DisableItem( SID_BROWSE_BACKWARD );
     379             : 
     380             :     // Add/SaveToBookmark at BASIC-IDE, QUERY-EDITOR etc. disable
     381           0 :     SfxObjectShell *pDocSh = GetObjectShell();
     382           0 :     bool bPseudo = pDocSh && !( pDocSh->GetFactory().GetFlags() & SFXOBJECTSHELL_HASOPENDOC );
     383           0 :     bool bEmbedded = pDocSh && pDocSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED;
     384           0 :     if ( !pDocSh || bPseudo || bEmbedded || !pDocSh->HasName() )
     385           0 :         rItemSet.DisableItem( SID_CREATELINK );
     386           0 : }
     387             : 
     388           0 : void SfxViewFrame::SetZoomFactor( const Fraction &rZoomX, const Fraction &rZoomY )
     389             : {
     390           0 :     GetViewShell()->SetZoomFactor( rZoomX, rZoomY );
     391           0 : }
     392             : 
     393           0 : void SfxViewFrame::Activate( bool bMDI )
     394             : {
     395             :     DBG_ASSERT(GetViewShell(), "No Shell");
     396           0 :     if ( bMDI )
     397           0 :         pImp->bActive = true;
     398             : //(mba): here maybe as in Beanframe NotifyEvent ?!
     399           0 : }
     400             : 
     401           0 : void SfxViewFrame::Deactivate( bool bMDI )
     402             : {
     403             :     DBG_ASSERT(GetViewShell(), "No Shell");
     404           0 :     if ( bMDI )
     405           0 :         pImp->bActive = false;
     406             : //(mba): here maybe as in Beanframe NotifyEvent ?!
     407           0 : }
     408             : 
     409             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10