LCOV - code coverage report
Current view: top level - sfx2/source/view - viewfrm2.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 58 156 37.2 %
Date: 2015-06-13 12:38:46 Functions: 8 11 72.7 %
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        8122 : void SfxFrameViewWindow_Impl::StateChanged( StateChangedType nStateChange )
      60             : {
      61        8122 :     if ( nStateChange == StateChangedType::InitShow )
      62             :     {
      63        3156 :         SfxObjectShell* pDoc = pFrame->GetObjectShell();
      64        3156 :         if ( pDoc && !pFrame->IsVisible() )
      65        2333 :             pFrame->Show();
      66             : 
      67        3156 :         pFrame->Resize();
      68             :     }
      69             :     else
      70        4966 :         Window::StateChanged( nStateChange );
      71        8122 : }
      72             : 
      73       13249 : void SfxFrameViewWindow_Impl::Resize()
      74             : {
      75       13249 :     if ( IsReallyVisible() || IsReallyShown() || GetOutputSizePixel().Width() )
      76       12332 :         pFrame->Resize();
      77       13249 : }
      78             : 
      79             : 
      80             : 
      81             : 
      82       15156 : 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       15156 :     const SfxObjectFactory &rFact = GetObjectShell()->GetFactory();
     123       15156 :     pImp->aFactoryName = OUString::createFromAscii(rFact.GetShortName());
     124             : 
     125       15156 :     SfxObjectShell *pObjSh = GetObjectShell();
     126       15156 :     if ( !pObjSh )
     127       15156 :         return;
     128             : 
     129             : 
     130       15156 :     const SfxMedium *pMedium = pObjSh->GetMedium();
     131       15156 :     OUString aURL;
     132       15156 :     GetFrame();  // -Wall required??
     133       15156 :     if ( pObjSh->HasName() )
     134             :     {
     135       10094 :         INetURLObject aTmp( pMedium->GetName() );
     136       10094 :         aURL = aTmp.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
     137             :     }
     138             : 
     139       15156 :     if ( aURL != pImp->aActualURL )
     140             :         // URL has changed
     141        2478 :         pImp->aActualURL = aURL;
     142             : 
     143             :     // SbxObjects name
     144       30312 :     OUString aSbxName = pObjSh->SfxShell::GetName();
     145       15156 :     if ( IsVisible() )
     146             :     {
     147       11074 :         aSbxName += ":";
     148       11074 :         aSbxName += OUString::number(pImp->nDocViewNo);
     149             :     }
     150             : 
     151       15156 :     SetName( aSbxName );
     152       15156 :     GetBindings().Invalidate( SID_CURRENT_URL );
     153       30312 :     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 == nullptr || pShowItem->GetValue();
     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, SfxCallMode::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 :             SfxGetpApp()->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        2349 : void SfxViewFrame::GetState_Impl( SfxItemSet &rSet )
     281             : {
     282        2349 :     SfxObjectShell *pDocSh = GetObjectShell();
     283             : 
     284        2349 :     if ( !pDocSh )
     285        2349 :         return;
     286             : 
     287        2349 :     const sal_uInt16 *pRanges = rSet.GetRanges();
     288             :     DBG_ASSERT(pRanges, "Set without Range");
     289        7047 :     while ( *pRanges )
     290             :     {
     291        4698 :         for ( sal_uInt16 nWhich = *pRanges++; nWhich <= *pRanges; ++nWhich )
     292             :         {
     293        2349 :             switch(nWhich)
     294             :             {
     295             :             case SID_NEWDOCDIRECT :
     296             :             {
     297        2342 :                 if ( !pImp->aFactoryName.isEmpty() )
     298             :                 {
     299        2342 :                     OUString aFact("private:factory/");
     300        2342 :                     aFact += pImp->aFactoryName;
     301        2342 :                     rSet.Put( SfxStringItem( nWhich, aFact ) );
     302             :                 }
     303        2342 :                 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           7 :                 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           7 :                     rSet.DisableItem( SID_OBJECT );
     331           7 :                 break;
     332             : 
     333             :             default:
     334             :                 OSL_FAIL( "invalid message-id" );
     335             :             }
     336             :         }
     337        2349 :         ++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, SfxItemState::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() & SfxObjectShellFlags::HASOPENDOC );
     383           0 :     bool bEmbedded = pDocSh && pDocSh->GetCreateMode() == SfxObjectCreateMode::EMBEDDED;
     384           0 :     if ( !pDocSh || bPseudo || bEmbedded || !pDocSh->HasName() )
     385           0 :         rItemSet.DisableItem( SID_CREATELINK );
     386           0 : }
     387             : 
     388        3148 : void SfxViewFrame::Activate( bool bMDI )
     389             : {
     390             :     DBG_ASSERT(GetViewShell(), "No Shell");
     391        3148 :     if ( bMDI )
     392        3148 :         pImp->bActive = true;
     393             : //(mba): here maybe as in Beanframe NotifyEvent ?!
     394        3148 : }
     395             : 
     396        3145 : void SfxViewFrame::Deactivate( bool bMDI )
     397             : {
     398             :     DBG_ASSERT(GetViewShell(), "No Shell");
     399        3145 :     if ( bMDI )
     400        3145 :         pImp->bActive = false;
     401             : //(mba): here maybe as in Beanframe NotifyEvent ?!
     402        3793 : }
     403             : 
     404             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11