LCOV - code coverage report
Current view: top level - sfx2/source/view - frame2.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 87 183 47.5 %
Date: 2015-06-13 12:38:46 Functions: 19 25 76.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 "impframe.hxx"
      22             : #include "objshimp.hxx"
      23             : #include <sfx2/sfxhelp.hxx>
      24             : #include "workwin.hxx"
      25             : 
      26             : #include <sfx2/app.hxx>
      27             : #include <sfx2/bindings.hxx>
      28             : #include <sfx2/dispatch.hxx>
      29             : #include <sfx2/docfac.hxx>
      30             : #include <sfx2/docfile.hxx>
      31             : #include <sfx2/event.hxx>
      32             : #include <sfx2/objface.hxx>
      33             : #include <sfx2/request.hxx>
      34             : 
      35             : #include <com/sun/star/awt/XWindow2.hpp>
      36             : #include <com/sun/star/beans/XPropertySet.hpp>
      37             : #include <com/sun/star/frame/Desktop.hpp>
      38             : #include <com/sun/star/frame/XComponentLoader.hpp>
      39             : #include <com/sun/star/frame/Frame.hpp>
      40             : #include <com/sun/star/frame/XFramesSupplier.hpp>
      41             : #include <com/sun/star/frame/XLayoutManager.hpp>
      42             : 
      43             : #include <comphelper/namedvaluecollection.hxx>
      44             : #include <comphelper/processfactory.hxx>
      45             : #include <svl/eitem.hxx>
      46             : #include <svl/intitem.hxx>
      47             : #include <svl/itemset.hxx>
      48             : #include <svl/rectitem.hxx>
      49             : #include <svl/stritem.hxx>
      50             : #include <toolkit/helper/vclunohelper.hxx>
      51             : #include <tools/diagnose_ex.h>
      52             : #include <vcl/syswin.hxx>
      53             : 
      54             : using namespace ::com::sun::star;
      55             : using namespace ::com::sun::star::uno;
      56             : using namespace ::com::sun::star::frame;
      57             : using namespace ::com::sun::star::util;
      58             : using namespace ::com::sun::star::container;
      59             : using namespace ::com::sun::star::beans;
      60             : using ::com::sun::star::lang::XMultiServiceFactory;
      61             : using ::com::sun::star::lang::XComponent;
      62             : using ::com::sun::star::frame::XComponentLoader;
      63             : 
      64             : 
      65             : 
      66        6486 : class SfxFrameWindow_Impl : public vcl::Window
      67             : {
      68             : public:
      69             :     SfxFrame*           pFrame;
      70             : 
      71             :     SfxFrameWindow_Impl( SfxFrame* pF, vcl::Window& i_rContainerWindow );
      72             : 
      73             :     virtual void        DataChanged( const DataChangedEvent& rDCEvt ) SAL_OVERRIDE;
      74             :     virtual void        StateChanged( StateChangedType nStateChange ) SAL_OVERRIDE;
      75             :     virtual bool        PreNotify( NotifyEvent& rNEvt ) SAL_OVERRIDE;
      76             :     virtual bool        Notify( NotifyEvent& rEvt ) SAL_OVERRIDE;
      77             :     virtual void        Resize() SAL_OVERRIDE;
      78             :     virtual void        GetFocus() SAL_OVERRIDE;
      79             :     void                DoResize();
      80             : };
      81             : 
      82        3250 : SfxFrameWindow_Impl::SfxFrameWindow_Impl( SfxFrame* pF, vcl::Window& i_rContainerWindow )
      83             :         : Window( &i_rContainerWindow, WB_BORDER | WB_CLIPCHILDREN | WB_NODIALOGCONTROL | WB_3DLOOK )
      84        3250 :         , pFrame( pF )
      85             : {
      86        3250 : }
      87             : 
      88          62 : void SfxFrameWindow_Impl::DataChanged( const DataChangedEvent& rDCEvt )
      89             : {
      90          62 :     Window::DataChanged( rDCEvt );
      91          62 :     SfxWorkWindow *pWorkWin = pFrame->GetWorkWindow_Impl();
      92          62 :     if ( pWorkWin )
      93          62 :         pWorkWin->DataChanged_Impl( rDCEvt );
      94          62 : }
      95             : 
      96      167844 : bool SfxFrameWindow_Impl::Notify( NotifyEvent& rNEvt )
      97             : {
      98      167844 :     if ( pFrame->IsClosing_Impl() || !pFrame->GetFrameInterface().is() )
      99      152118 :         return false;
     100             : 
     101       15726 :     SfxViewFrame* pView = pFrame->GetCurrentViewFrame();
     102       15726 :     if ( !pView || !pView->GetObjectShell() )
     103           0 :         return Window::Notify( rNEvt );
     104             : 
     105       15726 :     if ( rNEvt.GetType() == MouseNotifyEvent::GETFOCUS )
     106             :     {
     107        3106 :         if ( pView->GetViewShell() && !pView->GetViewShell()->GetUIActiveIPClient_Impl() && !pFrame->IsInPlace() )
     108             :         {
     109             :             OSL_TRACE("SfxFrame: GotFocus");
     110        3105 :             pView->MakeActive_Impl( false );
     111             :         }
     112             : 
     113             :         // if focus was on an external window, the clipboard content might have been changed
     114        3106 :         pView->GetBindings().Invalidate( SID_PASTE );
     115        3106 :         pView->GetBindings().Invalidate( SID_PASTE_SPECIAL );
     116        3106 :         return true;
     117             :     }
     118       12620 :     else if( rNEvt.GetType() == MouseNotifyEvent::KEYINPUT )
     119             :     {
     120           0 :         if ( pView->GetViewShell()->KeyInput( *rNEvt.GetKeyEvent() ) )
     121           0 :             return true;
     122             :     }
     123       12620 :     else if ( rNEvt.GetType() == MouseNotifyEvent::EXECUTEDIALOG /*|| rNEvt.GetType() == MouseNotifyEvent::INPUTDISABLE*/ )
     124             :     {
     125           0 :         pView->SetModalMode( true );
     126           0 :         return true;
     127             :     }
     128       12620 :     else if ( rNEvt.GetType() == MouseNotifyEvent::ENDEXECUTEDIALOG /*|| rNEvt.GetType() == MouseNotifyEvent::INPUTENABLE*/ )
     129             :     {
     130           0 :         pView->SetModalMode( false );
     131           0 :         return true;
     132             :     }
     133             : 
     134       12620 :     return Window::Notify( rNEvt );
     135             : }
     136             : 
     137       20864 : bool SfxFrameWindow_Impl::PreNotify( NotifyEvent& rNEvt )
     138             : {
     139       20864 :     MouseNotifyEvent nType = rNEvt.GetType();
     140       20864 :     if ( nType == MouseNotifyEvent::KEYINPUT || nType == MouseNotifyEvent::KEYUP )
     141             :     {
     142           0 :         SfxViewFrame* pView = pFrame->GetCurrentViewFrame();
     143           0 :         SfxViewShell* pShell = pView ? pView->GetViewShell() : NULL;
     144           0 :         if ( pShell && pShell->HasKeyListeners_Impl() && pShell->HandleNotifyEvent_Impl( rNEvt ) )
     145           0 :             return true;
     146             :     }
     147       20864 :     else if ( nType == MouseNotifyEvent::MOUSEBUTTONUP || nType == MouseNotifyEvent::MOUSEBUTTONDOWN )
     148             :     {
     149           0 :         vcl::Window* pWindow = rNEvt.GetWindow();
     150           0 :         SfxViewFrame* pView = pFrame->GetCurrentViewFrame();
     151           0 :         SfxViewShell* pShell = pView ? pView->GetViewShell() : NULL;
     152           0 :         if ( pShell )
     153           0 :             if ( pWindow == pShell->GetWindow() || pShell->GetWindow()->IsChild( pWindow ) )
     154           0 :                 if ( pShell->HasMouseClickListeners_Impl() && pShell->HandleNotifyEvent_Impl( rNEvt ) )
     155           0 :                     return true;
     156             :     }
     157             : 
     158       20864 :     if ( nType == MouseNotifyEvent::MOUSEBUTTONDOWN )
     159             :     {
     160           0 :         vcl::Window* pWindow = rNEvt.GetWindow();
     161           0 :         const MouseEvent* pMEvent = rNEvt.GetMouseEvent();
     162           0 :         Point aPos = pWindow->OutputToScreenPixel( pMEvent->GetPosPixel() );
     163           0 :         SfxWorkWindow *pWorkWin = pFrame->GetWorkWindow_Impl();
     164           0 :         if ( pWorkWin )
     165           0 :             pWorkWin->EndAutoShow_Impl( aPos );
     166             :     }
     167             : 
     168       20864 :     return Window::PreNotify( rNEvt );
     169             : }
     170             : 
     171        5819 : void SfxFrameWindow_Impl::GetFocus()
     172             : {
     173        5819 :     if ( pFrame && !pFrame->IsClosing_Impl() && pFrame->GetCurrentViewFrame() && pFrame->GetFrameInterface().is() )
     174        2990 :         pFrame->GetCurrentViewFrame()->MakeActive_Impl( true );
     175        5819 : }
     176             : 
     177       10848 : void SfxFrameWindow_Impl::Resize()
     178             : {
     179       10848 :     if ( IsReallyVisible() || IsReallyShown() || GetOutputSizePixel().Width() )
     180        7598 :         DoResize();
     181       10848 : }
     182             : 
     183        7753 : void SfxFrameWindow_Impl::StateChanged( StateChangedType nStateChange )
     184             : {
     185        7753 :     if ( nStateChange == StateChangedType::InitShow )
     186             :     {
     187        3149 :         pFrame->pImp->bHidden = false;
     188        3149 :         if ( pFrame->IsInPlace() )
     189             :             // TODO/MBA: workaround for bug in LayoutManager: the final resize does not get through because the
     190             :             // LayoutManager works asynchronously and between resize and time execution the DockingAcceptor was exchanged so that
     191             :             // the resize event never is sent to the component
     192           0 :             SetSizePixel( GetParent()->GetOutputSizePixel() );
     193             : 
     194        3149 :         DoResize();
     195        3149 :         SfxViewFrame* pView = pFrame->GetCurrentViewFrame();
     196        3149 :         if ( pView )
     197         816 :             pView->GetBindings().GetWorkWindow_Impl()->ShowChildren_Impl();
     198             :     }
     199             : 
     200        7753 :     Window::StateChanged( nStateChange );
     201        7753 : }
     202             : 
     203       10747 : void SfxFrameWindow_Impl::DoResize()
     204             : {
     205       10747 :     if ( !pFrame->pImp->bLockResize )
     206       10747 :         pFrame->Resize();
     207       10747 : }
     208             : 
     209           0 : Reference < XFrame > SfxFrame::CreateBlankFrame()
     210             : {
     211           0 :     Reference < XFrame > xFrame;
     212             :     try
     213             :     {
     214           0 :         Reference < XDesktop2 > xDesktop = Desktop::create( ::comphelper::getProcessComponentContext() );
     215           0 :         xFrame.set( xDesktop->findFrame( "_blank", 0 ), UNO_SET_THROW );
     216             :     }
     217           0 :     catch( const Exception& )
     218             :     {
     219             :         DBG_UNHANDLED_EXCEPTION();
     220             :     }
     221           0 :     return xFrame;
     222             : }
     223             : 
     224           0 : SfxFrame* SfxFrame::Create( SfxObjectShell& rDoc, vcl::Window& rWindow, sal_uInt16 nViewId, bool bHidden )
     225             : {
     226           0 :     SfxFrame* pFrame = NULL;
     227             :     try
     228             :     {
     229             :         // create and initialize new top level frame for this window
     230           0 :         Reference < XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
     231           0 :         Reference < XDesktop2 > xDesktop = Desktop::create( xContext );
     232           0 :         Reference < XFrame2 > xFrame = Frame::create( xContext );
     233             : 
     234           0 :         Reference< awt::XWindow2 > xWin( VCLUnoHelper::GetInterface ( &rWindow ), uno::UNO_QUERY_THROW );
     235           0 :         xFrame->initialize( xWin.get() );
     236           0 :         xDesktop->getFrames()->append( xFrame );
     237             : 
     238           0 :         if ( xWin->isActive() )
     239           0 :             xFrame->activate();
     240             : 
     241             :         // create load arguments
     242           0 :         Sequence< PropertyValue > aLoadArgs;
     243           0 :         TransformItems( SID_OPENDOC, *rDoc.GetMedium()->GetItemSet(), aLoadArgs );
     244             : 
     245           0 :         ::comphelper::NamedValueCollection aArgs( aLoadArgs );
     246           0 :         aArgs.put( "Model", rDoc.GetModel() );
     247           0 :         aArgs.put( "Hidden", bHidden );
     248           0 :         if ( nViewId )
     249           0 :             aArgs.put( "ViewId", nViewId );
     250             : 
     251           0 :         aLoadArgs = aArgs.getPropertyValues();
     252             : 
     253             :         // load the doc into that frame
     254           0 :         OUString sLoaderURL( "private:object" );
     255           0 :         Reference< XComponentLoader > xLoader( xFrame, UNO_QUERY_THROW );
     256           0 :         xLoader->loadComponentFromURL(
     257             :             sLoaderURL,
     258             :             OUString( "_self" ),
     259             :             0,
     260             :             aLoadArgs
     261           0 :         );
     262             : 
     263           0 :         for (   pFrame = SfxFrame::GetFirst();
     264             :                 pFrame;
     265             :                 pFrame = SfxFrame::GetNext( *pFrame )
     266             :             )
     267             :         {
     268           0 :             if ( pFrame->GetFrameInterface() == xFrame )
     269           0 :                 break;
     270             :         }
     271             : 
     272           0 :         OSL_ENSURE( pFrame, "SfxFrame::Create: load succeeded, but no SfxFrame was created during this!" );
     273             :     }
     274           0 :     catch( const Exception& )
     275             :     {
     276             :         DBG_UNHANDLED_EXCEPTION();
     277             :     }
     278             : 
     279           0 :     return pFrame;
     280             : }
     281             : 
     282        3250 : SfxFrame* SfxFrame::Create( const Reference < XFrame >& i_rFrame )
     283             : {
     284             :     // create a new TopFrame to an external XFrame object ( wrap controller )
     285        3250 :     ENSURE_OR_THROW( i_rFrame.is(), "NULL frame not allowed" );
     286        3250 :     vcl::Window* pWindow = VCLUnoHelper::GetWindow( i_rFrame->getContainerWindow() );
     287        3250 :     ENSURE_OR_THROW( pWindow, "frame without container window not allowed" );
     288             : 
     289        3250 :     SfxFrame* pFrame = new SfxFrame( *pWindow, false );
     290        3250 :     pFrame->SetFrameInterface_Impl( i_rFrame );
     291        3250 :     return pFrame;
     292             : }
     293             : 
     294        3250 : SfxFrame::SfxFrame( vcl::Window& i_rContainerWindow, bool i_bHidden )
     295             :     :SvCompatWeakBase<SfxFrame>( this )
     296             :     ,pParentFrame( NULL )
     297             :     ,pChildArr( NULL )
     298             :     ,pImp( NULL )
     299        3250 :     ,pWindow( NULL )
     300             : {
     301        3250 :     Construct_Impl();
     302             : 
     303        3250 :     pImp->bHidden = i_bHidden;
     304        3250 :     InsertTopFrame_Impl( this );
     305        3250 :     pImp->pExternalContainerWindow = &i_rContainerWindow;
     306             : 
     307        3250 :     pWindow = VclPtr<SfxFrameWindow_Impl>::Create( this, i_rContainerWindow );
     308             : 
     309             :     // always show pWindow, which is the ComponentWindow of the XFrame we live in
     310             :     // nowadays, since SfxFrames can be created with an XFrame only, hiding or showing the complete XFrame
     311             :     // is not done at level of the container window, not at SFX level. Thus, the component window can
     312             :     // always be visible.
     313        3250 :     pWindow->Show();
     314        3250 : }
     315             : 
     316           0 : void SfxFrame::SetPresentationMode( bool bSet )
     317             : {
     318           0 :     if ( GetCurrentViewFrame() )
     319           0 :         GetCurrentViewFrame()->GetWindow().SetBorderStyle( bSet ? WindowBorderStyle::NOBORDER : WindowBorderStyle::NORMAL );
     320             : 
     321           0 :     Reference< com::sun::star::beans::XPropertySet > xPropSet( GetFrameInterface(), UNO_QUERY );
     322           0 :     Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
     323             : 
     324           0 :     if ( xPropSet.is() )
     325             :     {
     326           0 :         Any aValue = xPropSet->getPropertyValue("LayoutManager");
     327           0 :         aValue >>= xLayoutManager;
     328             :     }
     329             : 
     330           0 :     if ( xLayoutManager.is() )
     331           0 :         xLayoutManager->setVisible( !bSet ); // we don't want to have ui in presentation mode
     332             : 
     333           0 :     SetMenuBarOn_Impl( !bSet );
     334           0 :     if ( GetWorkWindow_Impl() )
     335           0 :         GetWorkWindow_Impl()->SetDockingAllowed( !bSet );
     336           0 :     if ( GetCurrentViewFrame() )
     337           0 :         GetCurrentViewFrame()->GetDispatcher()->Update_Impl( true );
     338           0 : }
     339             : 
     340           0 : SystemWindow* SfxFrame::GetSystemWindow() const
     341             : {
     342           0 :     return GetTopWindow_Impl();
     343             : }
     344             : 
     345          18 : SystemWindow* SfxFrame::GetTopWindow_Impl() const
     346             : {
     347          18 :     if ( pImp->pExternalContainerWindow->IsSystemWindow() )
     348          18 :         return static_cast<SystemWindow*>( pImp->pExternalContainerWindow.get() );
     349             :     else
     350           0 :         return NULL;
     351             : }
     352             : 
     353             : 
     354        3243 : bool SfxFrame::Close()
     355             : {
     356        3243 :     delete this;
     357        3243 :     return true;
     358             : }
     359             : 
     360           0 : void SfxFrame::LockResize_Impl( bool bLock )
     361             : {
     362           0 :     pImp->bLockResize = bLock;
     363           0 : }
     364             : 
     365           0 : void SfxFrame::SetMenuBarOn_Impl( bool bOn )
     366             : {
     367           0 :     pImp->bMenuBarOn = bOn;
     368             : 
     369           0 :     Reference< com::sun::star::beans::XPropertySet > xPropSet( GetFrameInterface(), UNO_QUERY );
     370           0 :     Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
     371             : 
     372           0 :     if ( xPropSet.is() )
     373             :     {
     374           0 :         Any aValue = xPropSet->getPropertyValue("LayoutManager");
     375           0 :         aValue >>= xLayoutManager;
     376             :     }
     377             : 
     378           0 :     if ( xLayoutManager.is() )
     379             :     {
     380           0 :         OUString aMenuBarURL( "private:resource/menubar/menubar" );
     381             : 
     382           0 :         if ( bOn )
     383           0 :             xLayoutManager->showElement( aMenuBarURL );
     384             :         else
     385           0 :             xLayoutManager->hideElement( aMenuBarURL );
     386           0 :     }
     387           0 : }
     388             : 
     389       10035 : bool SfxFrame::IsMenuBarOn_Impl() const
     390             : {
     391       10035 :     return pImp->bMenuBarOn;
     392             : }
     393             : 
     394        3250 : void SfxFrame::PrepareForDoc_Impl( SfxObjectShell& i_rDoc )
     395             : {
     396        3250 :     const ::comphelper::NamedValueCollection aDocumentArgs( i_rDoc.GetModel()->getArgs() );
     397             : 
     398             :     // hidden?
     399             :     OSL_ENSURE( !pImp->bHidden, "when does this happen?" );
     400        3250 :     pImp->bHidden = aDocumentArgs.getOrDefault( "Hidden", pImp->bHidden );
     401             : 
     402             :     // update our descriptor
     403        3250 :     UpdateDescriptor( &i_rDoc );
     404             : 
     405             :     // plugin mode
     406        3250 :     sal_Int16 nPluginMode = aDocumentArgs.getOrDefault( "PluginMode", sal_Int16( 0 ) );
     407        3250 :     if ( nPluginMode && ( nPluginMode != 2 ) )
     408           0 :         SetInPlace_Impl( true );
     409        3250 : }
     410             : 
     411        3265 : bool SfxFrame::IsMarkedHidden_Impl() const
     412             : {
     413        3265 :     return pImp->bHidden;
     414         648 : }
     415             : 
     416             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11