LCOV - code coverage report
Current view: top level - sfx2/source/view - sfxbasecontroller.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 379 695 54.5 %
Date: 2014-11-03 Functions: 45 76 59.2 %
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 <time.h>
      21             : #include <sfx2/sfxbasecontroller.hxx>
      22             : 
      23             : #include <com/sun/star/awt/KeyEvent.hpp>
      24             : #include <com/sun/star/awt/KeyModifier.hpp>
      25             : #include <com/sun/star/awt/MouseEvent.hpp>
      26             : #include <com/sun/star/awt/MouseButton.hpp>
      27             : #include <com/sun/star/util/XCloseable.hpp>
      28             : #include <com/sun/star/util/XCloseBroadcaster.hpp>
      29             : #include <com/sun/star/util/XCloseListener.hpp>
      30             : #include <com/sun/star/util/CloseVetoException.hpp>
      31             : #include <com/sun/star/document/XCmisDocument.hpp>
      32             : #include <com/sun/star/document/XViewDataSupplier.hpp>
      33             : #include <cppuhelper/implbase1.hxx>
      34             : #include <cppuhelper/implbase2.hxx>
      35             : #include <com/sun/star/frame/FrameActionEvent.hpp>
      36             : #include <com/sun/star/frame/FrameAction.hpp>
      37             : #include <com/sun/star/frame/CommandGroup.hpp>
      38             : #include <com/sun/star/frame/XFrame.hpp>
      39             : #include <com/sun/star/frame/XBorderResizeListener.hpp>
      40             : #include <com/sun/star/lang/DisposedException.hpp>
      41             : #include <com/sun/star/lang/EventObject.hpp>
      42             : #include <com/sun/star/lang/XEventListener.hpp>
      43             : #include <com/sun/star/lang/XComponent.hpp>
      44             : #include <com/sun/star/container/XIndexAccess.hpp>
      45             : #include <cppuhelper/interfacecontainer.hxx>
      46             : #include <cppuhelper/typeprovider.hxx>
      47             : #include <basic/sbstar.hxx>
      48             : #include <uno/mapping.hxx>
      49             : #include <sfx2/viewsh.hxx>
      50             : #include <sfx2/docfac.hxx>
      51             : #include <sfx2/viewfrm.hxx>
      52             : #include <sfx2/objsh.hxx>
      53             : #include <sfx2/app.hxx>
      54             : #include <sfx2/msgpool.hxx>
      55             : #include <sfx2/dispatch.hxx>
      56             : #include <sfx2/userinputinterception.hxx>
      57             : 
      58             : #include <viewimp.hxx>
      59             : #include <sfx2/unoctitm.hxx>
      60             : #include <sfx2/childwin.hxx>
      61             : #include <sfx2/sfxsids.hrc>
      62             : #include <sfx2/sfx.hrc>
      63             : #include <sfx2/sfxresid.hxx>
      64             : #include <workwin.hxx>
      65             : #include <sfx2/objface.hxx>
      66             : #include <sfx2/infobar.hxx>
      67             : 
      68             : #include <osl/mutex.hxx>
      69             : #include <tools/diagnose_ex.h>
      70             : #include <comphelper/sequence.hxx>
      71             : #include <rtl/ustrbuf.hxx>
      72             : #include <toolkit/helper/convert.hxx>
      73             : #include <framework/titlehelper.hxx>
      74             : #include <comphelper/processfactory.hxx>
      75             : #include <vcl/msgbox.hxx>
      76             : 
      77             : #include <boost/unordered_map.hpp>
      78             : 
      79             : #include <sfx2/event.hxx>
      80             : #include <sfx2/viewfac.hxx>
      81             : #include "sfxbasecontroller_internal.hxx"
      82             : 
      83             : #define TIMEOUT_START_RESCHEDULE    10L /* 10th s */
      84             : 
      85             : using namespace ::com::sun::star;
      86             : using ::com::sun::star::uno::Reference;
      87             : using ::com::sun::star::uno::RuntimeException;
      88             : using ::com::sun::star::uno::UNO_QUERY_THROW;
      89             : using ::com::sun::star::uno::UNO_SET_THROW;
      90             : using ::com::sun::star::lang::DisposedException;
      91             : using ::com::sun::star::awt::XWindow;
      92             : using ::com::sun::star::frame::XController;
      93             : using ::com::sun::star::frame::XDispatchProvider;
      94             : using ::com::sun::star::document::XViewDataSupplier;
      95             : using ::com::sun::star::container::XIndexAccess;
      96             : using ::com::sun::star::beans::PropertyValue;
      97             : using ::com::sun::star::uno::Sequence;
      98             : using ::com::sun::star::uno::UNO_QUERY;
      99             : using ::com::sun::star::uno::Exception;
     100             : using ::com::sun::star::frame::XFrame;
     101             : using ::com::sun::star::frame::XFrameActionListener;
     102             : using ::com::sun::star::util::XCloseListener;
     103             : using ::com::sun::star::task::XStatusIndicator;
     104             : using ::com::sun::star::frame::XTitle;
     105             : 
     106             : struct GroupIDToCommandGroup
     107             : {
     108             :     sal_Int16   nGroupID;
     109             :     sal_Int16   nCommandGroup;
     110             : };
     111             : 
     112             : static bool                 bGroupIDMapInitialized = false;
     113             : static const GroupIDToCommandGroup    GroupIDCommandGroupMap[] =
     114             : {
     115             :     { GID_INTERN        ,   frame::CommandGroup::INTERNAL       },
     116             :     { GID_APPLICATION   ,   frame::CommandGroup::APPLICATION    },
     117             :     { GID_DOCUMENT      ,   frame::CommandGroup::DOCUMENT       },
     118             :     { GID_VIEW          ,   frame::CommandGroup::VIEW           },
     119             :     { GID_EDIT          ,   frame::CommandGroup::EDIT           },
     120             :     { GID_MACRO         ,   frame::CommandGroup::MACRO          },
     121             :     { GID_OPTIONS       ,   frame::CommandGroup::OPTIONS        },
     122             :     { GID_MATH          ,   frame::CommandGroup::MATH           },
     123             :     { GID_NAVIGATOR     ,   frame::CommandGroup::NAVIGATOR      },
     124             :     { GID_INSERT        ,   frame::CommandGroup::INSERT         },
     125             :     { GID_FORMAT        ,   frame::CommandGroup::FORMAT         },
     126             :     { GID_TEMPLATE      ,   frame::CommandGroup::TEMPLATE       },
     127             :     { GID_TEXT          ,   frame::CommandGroup::TEXT           },
     128             :     { GID_FRAME         ,   frame::CommandGroup::FRAME          },
     129             :     { GID_GRAPHIC       ,   frame::CommandGroup::GRAPHIC        },
     130             :     { GID_TABLE         ,   frame::CommandGroup::TABLE          },
     131             :     { GID_ENUMERATION   ,   frame::CommandGroup::ENUMERATION    },
     132             :     { GID_DATA          ,   frame::CommandGroup::DATA           },
     133             :     { GID_SPECIAL       ,   frame::CommandGroup::SPECIAL        },
     134             :     { GID_IMAGE         ,   frame::CommandGroup::IMAGE          },
     135             :     { GID_CHART         ,   frame::CommandGroup::CHART          },
     136             :     { GID_EXPLORER      ,   frame::CommandGroup::EXPLORER       },
     137             :     { GID_CONNECTOR     ,   frame::CommandGroup::CONNECTOR      },
     138             :     { GID_MODIFY        ,   frame::CommandGroup::MODIFY         },
     139             :     { GID_DRAWING       ,   frame::CommandGroup::DRAWING        },
     140             :     { GID_CONTROLS      ,   frame::CommandGroup::CONTROLS       },
     141             :     { 0                 ,   0                                                   }
     142             : };
     143             : 
     144             : typedef boost::unordered_map< sal_Int16, sal_Int16 > GroupHashMap;
     145             : 
     146             : 
     147           0 : sal_Int16 MapGroupIDToCommandGroup( sal_Int16 nGroupID )
     148             : {
     149           0 :     static GroupHashMap mHashMap;
     150             : 
     151           0 :     if ( !bGroupIDMapInitialized )
     152             :     {
     153           0 :         sal_Int32 i = 0;
     154           0 :         while ( GroupIDCommandGroupMap[i].nGroupID != 0 )
     155             :         {
     156             :             mHashMap.insert( GroupHashMap::value_type(
     157             :                 GroupIDCommandGroupMap[i].nGroupID,
     158           0 :                 GroupIDCommandGroupMap[i].nCommandGroup ));
     159           0 :             ++i;
     160             :         }
     161           0 :         bGroupIDMapInitialized = true;
     162             :     }
     163             : 
     164           0 :     GroupHashMap::const_iterator pIter = mHashMap.find( nGroupID );
     165           0 :     if ( pIter != mHashMap.end() )
     166           0 :         return pIter->second;
     167             :     else
     168           0 :         return frame::CommandGroup::INTERNAL;
     169             : }
     170             : 
     171        5356 : sal_uInt32 Get10ThSec()
     172             : {
     173        5356 :     sal_uInt32 n10Ticks = 10 * (sal_uInt32)clock();
     174        5356 :     return n10Ticks / CLOCKS_PER_SEC;
     175             : }
     176             : 
     177             : sal_Int32 m_nInReschedule = 0;  /// static counter for rescheduling
     178             : 
     179           0 : void reschedule()
     180             : {
     181           0 :     if ( m_nInReschedule == 0 )
     182             :     {
     183           0 :         ++m_nInReschedule;
     184           0 :         Application::Reschedule();
     185           0 :         --m_nInReschedule;
     186             :     }
     187           0 : }
     188             : 
     189           0 : class SfxStatusIndicator : public ::cppu::WeakImplHelper2< task::XStatusIndicator, lang::XEventListener >
     190             : {
     191             : friend class SfxBaseController;
     192             :     Reference < XController > xOwner;
     193             :     Reference < task::XStatusIndicator > xProgress;
     194             :     SfxWorkWindow*          pWorkWindow;
     195             :     sal_Int32               _nRange;
     196             :     sal_Int32               _nValue;
     197             :     long                    _nStartTime;
     198             : public:
     199           0 :                             SfxStatusIndicator(SfxBaseController* pController, SfxWorkWindow* pWork)
     200             :                                 : xOwner( pController )
     201             :                                 , pWorkWindow( pWork )
     202             :                                 , _nRange(0)
     203             :                                 , _nValue(0)
     204           0 :                                 , _nStartTime(0)
     205             :                             {
     206           0 :                                 ++m_refCount;
     207             :                                 Reference< lang::XComponent > xComponent(
     208           0 :                                     (static_cast< ::cppu::OWeakObject* >(pController)), uno::UNO_QUERY );
     209           0 :                                 if (xComponent.is())
     210           0 :                                     xComponent->addEventListener(this);
     211           0 :                                 --m_refCount;
     212           0 :                             }
     213             : 
     214             :     virtual void SAL_CALL   start(const OUString& aText, sal_Int32 nRange) throw(RuntimeException, std::exception) SAL_OVERRIDE;
     215             :     virtual void SAL_CALL   end(void) throw(RuntimeException, std::exception) SAL_OVERRIDE;
     216             :     virtual void SAL_CALL   setText(const OUString& aText) throw(RuntimeException, std::exception) SAL_OVERRIDE;
     217             :     virtual void SAL_CALL   setValue(sal_Int32 nValue) throw(RuntimeException, std::exception) SAL_OVERRIDE;
     218             :     virtual void SAL_CALL   reset() throw(RuntimeException, std::exception) SAL_OVERRIDE;
     219             : 
     220             :     virtual void SAL_CALL   disposing( const lang::EventObject& Source ) throw(RuntimeException, std::exception) SAL_OVERRIDE;
     221             : };
     222             : 
     223           0 : void SAL_CALL SfxStatusIndicator::start(const OUString& aText, sal_Int32 nRange) throw(RuntimeException, std::exception)
     224             : {
     225           0 :     SolarMutexGuard aGuard;
     226           0 :     if ( xOwner.is() )
     227             :     {
     228           0 :         _nRange = nRange;
     229           0 :         _nValue = 0;
     230             : 
     231           0 :         if ( !xProgress.is() )
     232           0 :             xProgress = pWorkWindow->GetStatusIndicator();
     233             : 
     234           0 :         if ( xProgress.is() )
     235           0 :             xProgress->start( aText, nRange );
     236             : 
     237           0 :         _nStartTime = Get10ThSec();
     238           0 :         reschedule();
     239           0 :     }
     240           0 : }
     241             : 
     242           0 : void SAL_CALL SfxStatusIndicator::end(void) throw(RuntimeException, std::exception)
     243             : {
     244           0 :     SolarMutexGuard aGuard;
     245           0 :     if ( xOwner.is() )
     246             :     {
     247           0 :         if ( !xProgress.is() )
     248           0 :             xProgress = pWorkWindow->GetStatusIndicator();
     249             : 
     250           0 :         if ( xProgress.is() )
     251           0 :             xProgress->end();
     252             : 
     253           0 :         reschedule();
     254           0 :     }
     255           0 : }
     256             : 
     257           0 : void SAL_CALL SfxStatusIndicator::setText(const OUString& aText) throw(RuntimeException, std::exception)
     258             : {
     259           0 :     SolarMutexGuard aGuard;
     260           0 :     if ( xOwner.is() )
     261             :     {
     262           0 :         if ( !xProgress.is() )
     263           0 :             xProgress = pWorkWindow->GetStatusIndicator();
     264             : 
     265           0 :         if ( xProgress.is() )
     266           0 :             xProgress->setText( aText );
     267             : 
     268           0 :         reschedule();
     269           0 :     }
     270           0 : }
     271             : 
     272           0 : void SAL_CALL SfxStatusIndicator::setValue( sal_Int32 nValue ) throw(RuntimeException, std::exception)
     273             : {
     274           0 :     SolarMutexGuard aGuard;
     275           0 :     if ( xOwner.is() )
     276             :     {
     277           0 :         _nValue = nValue;
     278             : 
     279           0 :         if ( !xProgress.is() )
     280           0 :             xProgress = pWorkWindow->GetStatusIndicator();
     281             : 
     282           0 :         if ( xProgress.is() )
     283           0 :             xProgress->setValue( nValue );
     284             : 
     285           0 :         bool bReschedule = (( Get10ThSec() - _nStartTime ) > TIMEOUT_START_RESCHEDULE );
     286           0 :         if ( bReschedule )
     287           0 :             reschedule();
     288           0 :     }
     289           0 : }
     290             : 
     291           0 : void SAL_CALL SfxStatusIndicator::reset() throw(RuntimeException, std::exception)
     292             : {
     293           0 :     SolarMutexGuard aGuard;
     294           0 :     if ( xOwner.is() )
     295             :     {
     296           0 :         if ( !xProgress.is() )
     297           0 :             xProgress = pWorkWindow->GetStatusIndicator();
     298             : 
     299           0 :         if ( xProgress.is() )
     300           0 :             xProgress->reset();
     301             : 
     302           0 :         reschedule();
     303           0 :     }
     304           0 : }
     305             : 
     306           0 : void SAL_CALL SfxStatusIndicator::disposing( const lang::EventObject& /*Source*/ ) throw(RuntimeException, std::exception)
     307             : {
     308           0 :     SolarMutexGuard aGuard;
     309           0 :     xOwner = 0;
     310           0 :     xProgress.clear();
     311           0 : }
     312             : 
     313             : 
     314             : //  declaration IMPL_SfxBaseController_ListenerHelper
     315             : 
     316             : 
     317             : class IMPL_SfxBaseController_ListenerHelper : public ::cppu::WeakImplHelper1< frame::XFrameActionListener >
     318             : {
     319             : public:
     320             :     IMPL_SfxBaseController_ListenerHelper(  SfxBaseController*  pController ) ;
     321             :     virtual ~IMPL_SfxBaseController_ListenerHelper() ;
     322             :     virtual void SAL_CALL frameAction( const frame::FrameActionEvent& aEvent ) throw (RuntimeException, std::exception) SAL_OVERRIDE ;
     323             :     virtual void SAL_CALL disposing( const lang::EventObject& aEvent ) throw (RuntimeException, std::exception) SAL_OVERRIDE ;
     324             : 
     325             : private:
     326             : 
     327             :     SfxBaseController*      m_pController   ;
     328             : 
     329             : } ; // class IMPL_SfxBaseController_ListenerContainer
     330             : 
     331             : class IMPL_SfxBaseController_CloseListenerHelper : public ::cppu::WeakImplHelper1< util::XCloseListener >
     332             : {
     333             : public:
     334             :     IMPL_SfxBaseController_CloseListenerHelper( SfxBaseController*  pController ) ;
     335             :     virtual ~IMPL_SfxBaseController_CloseListenerHelper() ;
     336             :     virtual void SAL_CALL queryClosing( const lang::EventObject& aEvent, sal_Bool bDeliverOwnership )
     337             :         throw (RuntimeException, util::CloseVetoException, std::exception) SAL_OVERRIDE ;
     338             :     virtual void SAL_CALL notifyClosing( const lang::EventObject& aEvent ) throw (RuntimeException, std::exception) SAL_OVERRIDE ;
     339             :     virtual void SAL_CALL disposing( const lang::EventObject& aEvent ) throw (RuntimeException, std::exception) SAL_OVERRIDE ;
     340             : 
     341             : private:
     342             : 
     343             :     SfxBaseController*      m_pController;
     344             : 
     345             : } ; // class IMPL_SfxBaseController_ListenerContainer
     346             : 
     347        5524 : IMPL_SfxBaseController_CloseListenerHelper::IMPL_SfxBaseController_CloseListenerHelper( SfxBaseController*  pController )
     348        5524 :         : m_pController ( pController   )
     349             : {
     350        5524 : }
     351             : 
     352       10348 : IMPL_SfxBaseController_CloseListenerHelper::~IMPL_SfxBaseController_CloseListenerHelper()
     353             : {
     354       10348 : }
     355             : 
     356           0 : void SAL_CALL IMPL_SfxBaseController_CloseListenerHelper::disposing( const lang::EventObject& /*aEvent*/ ) throw( RuntimeException, std::exception )
     357             : {
     358           0 : }
     359             : 
     360       10769 : void SAL_CALL IMPL_SfxBaseController_CloseListenerHelper::queryClosing( const lang::EventObject& aEvent, sal_Bool bDeliverOwnership )
     361             :     throw (RuntimeException, util::CloseVetoException, std::exception)
     362             : {
     363       10769 :     SolarMutexGuard aGuard;
     364       10769 :     SfxViewShell* pShell = m_pController->GetViewShell_Impl();
     365       10769 :     if  (pShell)
     366             :     {
     367       10769 :         bool bCanClose = pShell->PrepareClose( false );
     368       10769 :         if ( !bCanClose )
     369             :         {
     370           0 :             if ( bDeliverOwnership && ( !pShell->GetWindow() || !pShell->GetWindow()->IsReallyVisible() ) )
     371             :             {
     372             :                 // ignore Ownership in case of visible frame (will be closed by user)
     373           0 :                 Reference < frame::XModel > xModel( aEvent.Source, uno::UNO_QUERY );
     374           0 :                 if ( xModel.is() )
     375           0 :                     pShell->TakeOwnership_Impl();
     376             :                 else
     377           0 :                     pShell->TakeFrameOwnership_Impl();
     378             :             }
     379             : 
     380           0 :             throw util::CloseVetoException("Controller disagree ...",static_cast< ::cppu::OWeakObject*>(this));
     381             :         }
     382       10769 :     }
     383       10769 : }
     384             : 
     385        5265 : void SAL_CALL IMPL_SfxBaseController_CloseListenerHelper::notifyClosing( const lang::EventObject& /*aEvent*/ ) throw (RuntimeException, std::exception)
     386             : {
     387        5265 : }
     388             : 
     389             : 
     390             : //  declaration IMPL_SfxBaseController_DataContainer
     391             : 
     392             : 
     393        5174 : struct IMPL_SfxBaseController_DataContainer
     394             : {
     395             :     Reference< XFrame >                     m_xFrame                ;
     396             :     Reference< XFrameActionListener >       m_xListener             ;
     397             :     Reference< XCloseListener >             m_xCloseListener        ;
     398             :     ::sfx2::UserInputInterception           m_aUserInputInterception;
     399             :     ::cppu::OMultiTypeInterfaceContainerHelper      m_aListenerContainer    ;
     400             :     ::cppu::OInterfaceContainerHelper               m_aInterceptorContainer ;
     401             :     Reference< XStatusIndicator >           m_xIndicator            ;
     402             :     SfxViewShell*                           m_pViewShell            ;
     403             :     SfxBaseController*                      m_pController           ;
     404             :     bool                                    m_bDisposing            ;
     405             :     bool                                    m_bSuspendState         ;
     406             :     Reference< XTitle >                     m_xTitleHelper          ;
     407             :     Sequence< PropertyValue >               m_aCreationArgs         ;
     408             : 
     409        5524 :     IMPL_SfxBaseController_DataContainer(   ::osl::Mutex&              aMutex      ,
     410             :                                             SfxViewShell*       pViewShell  ,
     411             :                                             SfxBaseController*  pController )
     412        5524 :             :   m_xListener                     ( new IMPL_SfxBaseController_ListenerHelper( pController ) )
     413        5524 :             ,   m_xCloseListener                ( new IMPL_SfxBaseController_CloseListenerHelper( pController ) )
     414             :             ,   m_aUserInputInterception        ( *pController, aMutex                                  )
     415             :             ,   m_aListenerContainer            ( aMutex                                                )
     416             :             ,   m_aInterceptorContainer         ( aMutex                                                )
     417             :             ,   m_pViewShell            ( pViewShell                                            )
     418             :             ,   m_pController           ( pController                                           )
     419             :             ,   m_bDisposing            ( false                                                 )
     420       16572 :             ,   m_bSuspendState         ( false                                              )
     421             :     {
     422        5524 :     }
     423             : 
     424             : } ; // struct IMPL_SfxBaseController_DataContainer
     425             : 
     426             : 
     427             : //  IMPL_SfxBaseController_ListenerHelper constructor
     428             : 
     429             : 
     430        5524 : IMPL_SfxBaseController_ListenerHelper::IMPL_SfxBaseController_ListenerHelper(   SfxBaseController*  pController )
     431        5524 :         : m_pController ( pController   )
     432             : {
     433        5524 : }
     434             : 
     435             : 
     436             : //  IMPL_SfxBaseController_ListenerHelper destructor
     437             : 
     438             : 
     439       10348 : IMPL_SfxBaseController_ListenerHelper::~IMPL_SfxBaseController_ListenerHelper()
     440             : {
     441       10348 : }
     442             : 
     443        7997 : void SAL_CALL IMPL_SfxBaseController_ListenerHelper::frameAction( const frame::FrameActionEvent& aEvent ) throw( RuntimeException, std::exception )
     444             : {
     445        7997 :     SolarMutexGuard aGuard;
     446       15994 :     if  (
     447       23991 :             ( m_pController !=  NULL ) &&
     448       55979 :             ( aEvent.Frame  ==  m_pController->getFrame() ) &&
     449       15994 :             ( m_pController->GetViewShell_Impl() && m_pController->GetViewShell_Impl()->GetWindow() !=  NULL                                                    )
     450             :         )
     451             :     {
     452        7997 :         if ( aEvent.Action == frame::FrameAction_FRAME_UI_ACTIVATED )
     453             :         {
     454        1202 :             if ( !m_pController->GetViewShell_Impl()->GetUIActiveIPClient_Impl() )
     455        1202 :                 m_pController->GetViewShell_Impl()->GetViewFrame()->MakeActive_Impl( false );
     456             :         }
     457        6795 :         else if ( aEvent.Action == frame::FrameAction_CONTEXT_CHANGED )
     458             :         {
     459           0 :             m_pController->GetViewShell_Impl()->GetViewFrame()->GetBindings().ContextChanged_Impl();
     460             :         }
     461        7997 :     }
     462        7997 : }
     463             : 
     464             : 
     465             : //  IMPL_SfxBaseController_ListenerHelper -> XEventListener
     466             : 
     467             : 
     468        5522 : void SAL_CALL IMPL_SfxBaseController_ListenerHelper::disposing( const lang::EventObject& /*aEvent*/ ) throw( RuntimeException, std::exception )
     469             : {
     470        5522 :     SolarMutexGuard aGuard;
     471        5522 :     if ( m_pController && m_pController->getFrame().is() )
     472           0 :         m_pController->getFrame()->removeFrameActionListener( this ) ;
     473        5522 : }
     474             : 
     475        5524 : SfxBaseController::SfxBaseController( SfxViewShell* pViewShell )
     476        5524 :     :   m_pData ( new IMPL_SfxBaseController_DataContainer( m_aMutex, pViewShell, this ))
     477             : {
     478        5524 :     m_pData->m_pViewShell->SetController( this );
     479        5524 : }
     480             : 
     481             : 
     482             : //  SfxBaseController -> destructor
     483             : 
     484             : 
     485       10382 : SfxBaseController::~SfxBaseController()
     486             : {
     487        5174 :     delete m_pData;
     488        5208 : }
     489             : 
     490             : 
     491             : //  SfxBaseController -> XController2
     492             : 
     493             : 
     494        5524 : Reference< XWindow > SAL_CALL SfxBaseController::getComponentWindow() throw (RuntimeException, std::exception)
     495             : {
     496        5524 :     SolarMutexGuard aGuard;
     497        5524 :     if ( !m_pData->m_pViewShell )
     498           0 :         throw DisposedException();
     499             : 
     500        5524 :     return Reference< XWindow >( GetViewFrame_Impl().GetFrame().GetWindow().GetComponentInterface(), UNO_QUERY_THROW );
     501             : }
     502             : 
     503           0 : OUString SAL_CALL SfxBaseController::getViewControllerName() throw (RuntimeException, std::exception)
     504             : {
     505           0 :     SolarMutexGuard aGuard;
     506           0 :     if ( !m_pData->m_pViewShell || !m_pData->m_pViewShell->GetObjectShell() )
     507           0 :         throw DisposedException();
     508             : 
     509           0 :     const SfxObjectFactory& rDocFac( m_pData->m_pViewShell->GetObjectShell()->GetFactory() );
     510           0 :     sal_uInt16 nViewNo = rDocFac.GetViewNo_Impl( GetViewFrame_Impl().GetCurViewId(), rDocFac.GetViewFactoryCount() );
     511             :     OSL_ENSURE( nViewNo < rDocFac.GetViewFactoryCount(), "SfxBaseController::getViewControllerName: view ID not found in view factories!" );
     512             : 
     513           0 :     OUString sViewName;
     514           0 :     if ( nViewNo < rDocFac.GetViewFactoryCount() )
     515           0 :         sViewName = rDocFac.GetViewFactory( nViewNo ).GetAPIViewName();
     516             : 
     517           0 :     return sViewName;
     518             : }
     519             : 
     520        5524 : Sequence< PropertyValue > SAL_CALL SfxBaseController::getCreationArguments() throw (RuntimeException, std::exception)
     521             : {
     522        5524 :     SolarMutexGuard aGuard;
     523        5524 :     if ( !m_pData->m_pViewShell || !m_pData->m_pViewShell->GetObjectShell() )
     524           0 :         throw DisposedException();
     525             : 
     526        5524 :     return m_pData->m_aCreationArgs;
     527             : }
     528             : 
     529        5524 : void SfxBaseController::SetCreationArguments_Impl( const Sequence< PropertyValue >& i_rCreationArgs )
     530             : {
     531             :     OSL_ENSURE( m_pData->m_aCreationArgs.getLength() == 0, "SfxBaseController::SetCreationArguments_Impl: not intended to be called twice!" );
     532        5524 :     m_pData->m_aCreationArgs = i_rCreationArgs;
     533        5524 : }
     534             : 
     535        5524 : SfxViewFrame& SfxBaseController::GetViewFrame_Impl() const
     536             : {
     537        5524 :     ENSURE_OR_THROW( m_pData->m_pViewShell, "not to be called without a view shell" );
     538        5524 :     SfxViewFrame* pActFrame = m_pData->m_pViewShell->GetFrame();
     539        5524 :     ENSURE_OR_THROW( pActFrame, "a view shell without a view frame is pretty pathological" );
     540        5524 :     return *pActFrame;
     541             : }
     542             : 
     543             : 
     544             : //  SfxBaseController -> XController2 -> XController
     545             : 
     546             : 
     547       11046 : void SAL_CALL SfxBaseController::attachFrame( const Reference< frame::XFrame >& xFrame ) throw( RuntimeException, std::exception )
     548             : {
     549       11046 :     Reference< frame::XFrame > xTemp( getFrame() ) ;
     550             : 
     551       22092 :     SolarMutexGuard aGuard;
     552       11046 :     if ( xTemp.is() )
     553             :     {
     554        5522 :         xTemp->removeFrameActionListener( m_pData->m_xListener ) ;
     555        5522 :         Reference < util::XCloseBroadcaster > xCloseable( xTemp, uno::UNO_QUERY );
     556        5522 :         if ( xCloseable.is() )
     557        5522 :             xCloseable->removeCloseListener( m_pData->m_xCloseListener );
     558             :     }
     559             : 
     560       11046 :     m_pData->m_xFrame = xFrame;
     561             : 
     562       11046 :     if ( xFrame.is() )
     563             :     {
     564        5524 :         xFrame->addFrameActionListener( m_pData->m_xListener ) ;
     565        5524 :         Reference < util::XCloseBroadcaster > xCloseable( xFrame, uno::UNO_QUERY );
     566        5524 :         if ( xCloseable.is() )
     567        5524 :             xCloseable->addCloseListener( m_pData->m_xCloseListener );
     568             : 
     569        5524 :         if ( m_pData->m_pViewShell )
     570             :         {
     571        5524 :             ConnectSfxFrame_Impl( E_CONNECT );
     572        5524 :             ShowInfoBars( );
     573             : 
     574             :             // attaching the frame to the controller is the last step in the creation of a new view, so notify this
     575        5524 :             SfxViewEventHint aHint( SFX_EVENT_VIEWCREATED, GlobalEventConfig::GetEventName( STR_EVENT_VIEWCREATED ), m_pData->m_pViewShell->GetObjectShell(), Reference< frame::XController2 >( this ) );
     576        5524 :             SfxGetpApp()->NotifyEvent( aHint );
     577        5524 :         }
     578       11046 :     }
     579       11046 : }
     580             : 
     581             : 
     582             : //  SfxBaseController -> XController
     583             : 
     584             : 
     585        5524 : sal_Bool SAL_CALL SfxBaseController::attachModel( const Reference< frame::XModel >& xModel ) throw( RuntimeException, std::exception )
     586             : {
     587        5524 :     if ( m_pData->m_pViewShell && xModel.is() && xModel != m_pData->m_pViewShell->GetObjectShell()->GetModel() )
     588             :     {
     589             :         // don't allow to reattach a model!
     590             :         OSL_FAIL("Can't reattach model!");
     591           0 :         return sal_False;
     592             :     }
     593             : 
     594        5524 :     Reference < util::XCloseBroadcaster > xCloseable( xModel, uno::UNO_QUERY );
     595        5524 :     if ( xCloseable.is() )
     596        5524 :         xCloseable->addCloseListener( m_pData->m_xCloseListener );
     597        5524 :     return sal_True;
     598             : }
     599             : 
     600             : 
     601             : //  SfxBaseController -> XController
     602             : 
     603             : 
     604           7 : sal_Bool SAL_CALL SfxBaseController::suspend( sal_Bool bSuspend ) throw( RuntimeException, std::exception )
     605             : {
     606           7 :     SolarMutexGuard aGuard;
     607             : 
     608             :     // ignore dublicate calls, which doesn't change anything real
     609           7 :     if (bSuspend == (m_pData->m_bSuspendState ? 1 : 0))
     610           0 :        return sal_True;
     611             : 
     612           7 :     if ( bSuspend == sal_True )
     613             :     {
     614           7 :         if ( !m_pData->m_pViewShell )
     615             :         {
     616           0 :             m_pData->m_bSuspendState = true;
     617           0 :             return sal_True;
     618             :         }
     619             : 
     620           7 :         if ( !m_pData->m_pViewShell->PrepareClose() )
     621           0 :             return sal_False;
     622             : 
     623           7 :         if ( getFrame().is() )
     624           7 :             getFrame()->removeFrameActionListener( m_pData->m_xListener ) ;
     625           7 :         SfxViewFrame* pActFrame = m_pData->m_pViewShell->GetFrame() ;
     626             : 
     627             :         // More Views on the same document?
     628           7 :         SfxObjectShell* pDocShell   =   m_pData->m_pViewShell->GetObjectShell() ;
     629           7 :         bool            bOther      =   false                                   ;
     630             : 
     631          13 :         for ( const SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pDocShell ); !bOther && pFrame; pFrame = SfxViewFrame::GetNext( *pFrame, pDocShell ) )
     632           6 :             bOther = (pFrame != pActFrame);
     633             : 
     634           7 :         bool bRet = bOther || pDocShell->PrepareClose();
     635           7 :         if ( bRet )
     636             :         {
     637           7 :             ConnectSfxFrame_Impl( E_DISCONNECT );
     638           7 :             m_pData->m_bSuspendState = true;
     639             :         }
     640             : 
     641           7 :         return bRet;
     642             :     }
     643             :     else
     644             :     {
     645           0 :         if ( getFrame().is() )
     646           0 :             getFrame()->addFrameActionListener( m_pData->m_xListener ) ;
     647             : 
     648           0 :         if ( m_pData->m_pViewShell )
     649             :         {
     650           0 :             ConnectSfxFrame_Impl( E_RECONNECT );
     651             :         }
     652             : 
     653           0 :         m_pData->m_bSuspendState = false;
     654           0 :         return sal_True ;
     655           7 :     }
     656             : }
     657             : 
     658             : 
     659             : //  SfxBaseController -> XController
     660             : 
     661             : 
     662           2 : uno::Any SfxBaseController::getViewData() throw( RuntimeException, std::exception )
     663             : {
     664           2 :     uno::Any         aAny;
     665           4 :     OUString sData;
     666           4 :     SolarMutexGuard aGuard;
     667           2 :     if ( m_pData->m_pViewShell )
     668             :     {
     669           2 :         m_pData->m_pViewShell->WriteUserData( sData ) ;
     670           2 :         aAny <<= sData ;
     671             :     }
     672             : 
     673           4 :     return aAny ;
     674             : }
     675             : 
     676             : 
     677             : //  SfxBaseController -> XController
     678             : 
     679             : 
     680           0 : void SAL_CALL SfxBaseController::restoreViewData( const uno::Any& aValue ) throw( RuntimeException, std::exception )
     681             : {
     682           0 :     SolarMutexGuard aGuard;
     683           0 :     if ( m_pData->m_pViewShell )
     684             :     {
     685           0 :         OUString sData;
     686           0 :         aValue >>= sData ;
     687           0 :         m_pData->m_pViewShell->ReadUserData( sData ) ;
     688           0 :     }
     689           0 : }
     690             : 
     691             : 
     692             : //  SfxBaseController -> XController
     693             : 
     694             : 
     695       44363 : Reference< frame::XFrame > SAL_CALL SfxBaseController::getFrame() throw( RuntimeException, std::exception )
     696             : {
     697       44363 :     SolarMutexGuard aGuard;
     698       44363 :     return m_pData->m_xFrame;
     699             : }
     700             : 
     701             : 
     702             : //  SfxBaseController -> XController
     703             : 
     704             : 
     705      920815 : Reference< frame::XModel > SAL_CALL SfxBaseController::getModel() throw( RuntimeException, std::exception )
     706             : {
     707      920815 :     SolarMutexGuard aGuard;
     708      920815 :     return m_pData->m_pViewShell ? m_pData->m_pViewShell->GetObjectShell()->GetModel() : Reference < frame::XModel > () ;
     709             : }
     710             : 
     711             : 
     712             : //  SfxBaseController -> XDispatchProvider
     713             : 
     714             : 
     715      364560 : Reference< frame::XDispatch > SAL_CALL SfxBaseController::queryDispatch(   const   util::URL&             aURL            ,
     716             :                                                                     const   OUString&            sTargetFrameName,
     717             :                                                                             sal_Int32           eSearchFlags    ) throw( RuntimeException, std::exception )
     718             : {
     719      364560 :     SolarMutexGuard aGuard;
     720      729120 :     Reference< frame::XDispatch >  xDisp;
     721      364560 :     if ( m_pData->m_pViewShell )
     722             :     {
     723      364560 :         SfxViewFrame*           pAct    = m_pData->m_pViewShell->GetViewFrame() ;
     724      364560 :         if ( !m_pData->m_bDisposing )
     725             :         {
     726      364560 :             if ( sTargetFrameName == "_beamer" )
     727             :             {
     728           2 :                 SfxViewFrame *pFrame = m_pData->m_pViewShell->GetViewFrame();
     729           2 :                 if ( eSearchFlags & ( frame::FrameSearchFlag::CREATE ))
     730           2 :                     pFrame->SetChildWindow( SID_BROWSER, true );
     731           2 :                 SfxChildWindow* pChildWin = pFrame->GetChildWindow( SID_BROWSER );
     732           2 :                 Reference < frame::XFrame > xFrame;
     733           2 :                 if ( pChildWin )
     734           2 :                     xFrame = ( pChildWin->GetFrame() );
     735           2 :                 if ( xFrame.is() )
     736           2 :                     xFrame->setName( sTargetFrameName );
     737             : 
     738           2 :                 Reference< XDispatchProvider > xProv( xFrame, uno::UNO_QUERY );
     739           2 :                 if ( xProv.is() )
     740           2 :                     return xProv->queryDispatch( aURL, sTargetFrameName, frame::FrameSearchFlag::SELF );
     741             :             }
     742             : 
     743      364558 :             if ( aURL.Protocol == ".uno:" )
     744             :             {
     745      317486 :                 OUString aMasterCommand = SfxOfficeDispatch::GetMasterUnoCommand( aURL );
     746      317486 :                 bool     bMasterCommand( !aMasterCommand.isEmpty() );
     747             : 
     748      317486 :                 pAct = m_pData->m_pViewShell->GetViewFrame() ;
     749      317486 :                 SfxSlotPool& rSlotPool = SfxSlotPool::GetSlotPool( pAct );
     750             : 
     751      317486 :                 const SfxSlot* pSlot( 0 );
     752      317486 :                 if ( bMasterCommand )
     753         114 :                     pSlot = rSlotPool.GetUnoSlot( aMasterCommand );
     754             :                 else
     755      317372 :                     pSlot = rSlotPool.GetUnoSlot( aURL.Path );
     756      317486 :                 if ( pSlot && ( !pAct->GetFrame().IsInPlace() || !pSlot->IsMode( SFX_SLOT_CONTAINER ) ) )
     757      308677 :                     return pAct->GetBindings().GetDispatch( pSlot, aURL, bMasterCommand );
     758             :                 else
     759             :                 {
     760             :                     // try to find parent SfxViewFrame
     761        8809 :                     Reference< frame::XFrame > xParentFrame;
     762       17618 :                     Reference< frame::XFrame > xOwnFrame = pAct->GetFrame().GetFrameInterface();
     763        8809 :                     if ( xOwnFrame.is() )
     764        8809 :                         xParentFrame = Reference< frame::XFrame >( xOwnFrame->getCreator(), uno::UNO_QUERY );
     765             : 
     766        8809 :                     if ( xParentFrame.is() )
     767             :                     {
     768             :                         // TODO/LATER: in future probably SfxViewFrame hirarchy should be the same as XFrame hirarchy
     769             :                         // SfxViewFrame* pParentFrame = pAct->GetParentViewFrame();
     770             : 
     771             :                         // search the related SfxViewFrame
     772        8809 :                         SfxViewFrame* pParentFrame = NULL;
     773       13734 :                         for ( SfxViewFrame* pFrame = SfxViewFrame::GetFirst();
     774             :                                 pFrame;
     775             :                                 pFrame = SfxViewFrame::GetNext( *pFrame ) )
     776             :                         {
     777        4925 :                             if ( pFrame->GetFrame().GetFrameInterface() == xParentFrame )
     778             :                             {
     779           0 :                                 pParentFrame = pFrame;
     780           0 :                                 break;
     781             :                             }
     782             :                         }
     783             : 
     784        8809 :                         if ( pParentFrame )
     785             :                         {
     786           0 :                             SfxSlotPool& rFrameSlotPool = SfxSlotPool::GetSlotPool( pParentFrame );
     787           0 :                             const SfxSlot* pSlot2( 0 );
     788           0 :                             if ( bMasterCommand )
     789           0 :                                 pSlot2 = rFrameSlotPool.GetUnoSlot( aMasterCommand );
     790             :                             else
     791           0 :                                 pSlot2 = rFrameSlotPool.GetUnoSlot( aURL.Path );
     792             : 
     793           0 :                             if ( pSlot2 )
     794           0 :                                 return pParentFrame->GetBindings().GetDispatch( pSlot2, aURL, bMasterCommand );
     795             :                         }
     796        8809 :                     }
     797        8809 :                 }
     798             :             }
     799       47072 :             else if ( aURL.Protocol == "slot:" )
     800             :             {
     801           0 :                 sal_uInt16 nId = (sal_uInt16) aURL.Path.toInt32();
     802             : 
     803           0 :                 pAct = m_pData->m_pViewShell->GetViewFrame() ;
     804           0 :                 if (nId >= SID_VERB_START && nId <= SID_VERB_END)
     805             :                 {
     806           0 :                     const SfxSlot* pSlot = m_pData->m_pViewShell->GetVerbSlot_Impl(nId);
     807           0 :                     if ( pSlot )
     808           0 :                         return pAct->GetBindings().GetDispatch( pSlot, aURL, false );
     809             :                 }
     810             : 
     811           0 :                 SfxSlotPool& rSlotPool = SfxSlotPool::GetSlotPool( pAct );
     812           0 :                 const SfxSlot* pSlot = rSlotPool.GetSlot( nId );
     813           0 :                 if ( pSlot && ( !pAct->GetFrame().IsInPlace() || !pSlot->IsMode( SFX_SLOT_CONTAINER ) ) )
     814           0 :                     return pAct->GetBindings().GetDispatch( pSlot, aURL, false );
     815             :                 else
     816             :                 {
     817             :                     // try to find parent SfxViewFrame
     818           0 :                     Reference< frame::XFrame > xParentFrame;
     819           0 :                     Reference< frame::XFrame > xOwnFrame = pAct->GetFrame().GetFrameInterface();
     820           0 :                     if ( xOwnFrame.is() )
     821           0 :                         xParentFrame = Reference< frame::XFrame >( xOwnFrame->getCreator(), uno::UNO_QUERY );
     822             : 
     823           0 :                     if ( xParentFrame.is() )
     824             :                     {
     825             :                         // TODO/LATER: in future probably SfxViewFrame hirarchy should be the same as XFrame hirarchy
     826             :                         // SfxViewFrame* pParentFrame = pAct->GetParentViewFrame();
     827             : 
     828             :                         // search the related SfxViewFrame
     829           0 :                         SfxViewFrame* pParentFrame = NULL;
     830           0 :                         for ( SfxViewFrame* pFrame = SfxViewFrame::GetFirst();
     831             :                                 pFrame;
     832             :                                 pFrame = SfxViewFrame::GetNext( *pFrame ) )
     833             :                         {
     834           0 :                             if ( pFrame->GetFrame().GetFrameInterface() == xParentFrame )
     835             :                             {
     836           0 :                                 pParentFrame = pFrame;
     837           0 :                                 break;
     838             :                             }
     839             :                         }
     840             : 
     841           0 :                         if ( pParentFrame )
     842             :                         {
     843           0 :                             SfxSlotPool& rSlotPool2 = SfxSlotPool::GetSlotPool( pParentFrame );
     844           0 :                             const SfxSlot* pSlot2 = rSlotPool2.GetUnoSlot( aURL.Path );
     845           0 :                             if ( pSlot2 )
     846           0 :                                 return pParentFrame->GetBindings().GetDispatch( pSlot2, aURL, false );
     847             :                         }
     848           0 :                     }
     849             :                 }
     850             :             }
     851       47072 :             else if( sTargetFrameName == "_self" || sTargetFrameName.isEmpty() )
     852             :             {
     853             :                 // check for already loaded URL ... but with additional jumpmark!
     854       47072 :                 Reference< frame::XModel > xModel = getModel();
     855       47072 :                 if( xModel.is() && !aURL.Mark.isEmpty() )
     856             :                 {
     857           0 :                     SfxSlotPool& rSlotPool = SfxSlotPool::GetSlotPool( pAct );
     858           0 :                     const SfxSlot* pSlot = rSlotPool.GetSlot( SID_JUMPTOMARK );
     859           0 :                     if( !aURL.Main.isEmpty() && aURL.Main == xModel->getURL() && pSlot )
     860           0 :                         return Reference< frame::XDispatch >( new SfxOfficeDispatch( pAct->GetBindings(), pAct->GetDispatcher(), pSlot, aURL) );
     861       47072 :                 }
     862             :             }
     863             :         }
     864             :     }
     865             : 
     866      420441 :     return xDisp;
     867             : }
     868             : 
     869             : 
     870             : //  SfxBaseController -> XDispatchProvider
     871             : 
     872             : 
     873           0 : uno::Sequence< Reference< frame::XDispatch > > SAL_CALL SfxBaseController::queryDispatches( const uno::Sequence< frame::DispatchDescriptor >& seqDescripts ) throw( RuntimeException, std::exception )
     874             : {
     875             :     // Create return list - which must have same size then the given descriptor
     876             :     // It's not allowed to pack it!
     877           0 :     sal_Int32 nCount = seqDescripts.getLength();
     878           0 :     uno::Sequence< Reference< frame::XDispatch > > lDispatcher( nCount );
     879             : 
     880           0 :     for( sal_Int32 i=0; i<nCount; ++i )
     881             :     {
     882           0 :         lDispatcher[i] = queryDispatch( seqDescripts[i].FeatureURL  ,
     883           0 :                                         seqDescripts[i].FrameName   ,
     884           0 :                                         seqDescripts[i].SearchFlags );
     885             :     }
     886             : 
     887           0 :     return lDispatcher;
     888             : }
     889             : 
     890             : 
     891             : //  SfxBaseController -> XControllerBorder
     892             : 
     893             : 
     894          72 : frame::BorderWidths SAL_CALL SfxBaseController::getBorder()
     895             :     throw ( RuntimeException, std::exception )
     896             : {
     897          72 :     frame::BorderWidths aResult;
     898             : 
     899          72 :     SolarMutexGuard aGuard;
     900          72 :     if ( m_pData->m_pViewShell )
     901             :     {
     902          72 :         SvBorder aBorder = m_pData->m_pViewShell->GetBorderPixel();
     903          72 :         aResult.Left = aBorder.Left();
     904          72 :         aResult.Top = aBorder.Top();
     905          72 :         aResult.Right = aBorder.Right();
     906          72 :         aResult.Bottom = aBorder.Bottom();
     907             :     }
     908             : 
     909          72 :     return aResult;
     910             : }
     911             : 
     912          50 : void SAL_CALL SfxBaseController::addBorderResizeListener( const Reference< frame::XBorderResizeListener >& xListener )
     913             :     throw ( RuntimeException, std::exception )
     914             : {
     915          50 :     m_pData->m_aListenerContainer.addInterface( cppu::UnoType<frame::XBorderResizeListener>::get(),
     916         100 :                                                 xListener );
     917          50 : }
     918             : 
     919          50 : void SAL_CALL SfxBaseController::removeBorderResizeListener( const Reference< frame::XBorderResizeListener >& xListener )
     920             :     throw ( RuntimeException, std::exception )
     921             : {
     922          50 :     m_pData->m_aListenerContainer.removeInterface( cppu::UnoType<frame::XBorderResizeListener>::get(),
     923         100 :                                                 xListener );
     924          50 : }
     925             : 
     926           0 : awt::Rectangle SAL_CALL SfxBaseController::queryBorderedArea( const awt::Rectangle& aPreliminaryRectangle )
     927             :     throw ( RuntimeException, std::exception )
     928             : {
     929           0 :     SolarMutexGuard aGuard;
     930           0 :     if ( m_pData->m_pViewShell )
     931             :     {
     932           0 :         Rectangle aTmpRect = VCLRectangle( aPreliminaryRectangle );
     933           0 :         m_pData->m_pViewShell->QueryObjAreaPixel( aTmpRect );
     934           0 :         return AWTRectangle( aTmpRect );
     935             :     }
     936             : 
     937           0 :     return aPreliminaryRectangle;
     938             : }
     939             : 
     940       40269 : void SfxBaseController::BorderWidthsChanged_Impl()
     941             : {
     942             :        ::cppu::OInterfaceContainerHelper* pContainer = m_pData->m_aListenerContainer.getContainer(
     943       40269 :                         cppu::UnoType<frame::XBorderResizeListener>::get());
     944       40269 :     if ( pContainer )
     945             :     {
     946          72 :         frame::BorderWidths aBWidths = getBorder();
     947          72 :         Reference< uno::XInterface > xThis( static_cast< ::cppu::OWeakObject* >(this), uno::UNO_QUERY );
     948             : 
     949         144 :         ::cppu::OInterfaceIteratorHelper pIterator(*pContainer);
     950         216 :         while (pIterator.hasMoreElements())
     951             :         {
     952             :             try
     953             :             {
     954          72 :                 static_cast<frame::XBorderResizeListener*>(pIterator.next())->borderWidthsChanged( xThis, aBWidths );
     955             :             }
     956           0 :             catch (const RuntimeException&)
     957             :             {
     958           0 :                 pIterator.remove();
     959             :             }
     960          72 :         }
     961             :     }
     962       40269 : }
     963             : 
     964             : 
     965             : //  SfxBaseController -> XComponent
     966             : 
     967             : 
     968        5522 : void SAL_CALL SfxBaseController::dispose() throw( RuntimeException, std::exception )
     969             : {
     970        5522 :     SolarMutexGuard aGuard;
     971       11044 :     Reference< XController > xTmp( this );
     972        5522 :     m_pData->m_bDisposing = true ;
     973             : 
     974       11044 :     lang::EventObject aEventObject;
     975        5522 :     aEventObject.Source = *this ;
     976        5522 :     m_pData->m_aListenerContainer.disposeAndClear( aEventObject ) ;
     977             : 
     978        5522 :     if ( m_pData->m_pController && m_pData->m_pController->getFrame().is() )
     979        5522 :         m_pData->m_pController->getFrame()->removeFrameActionListener( m_pData->m_xListener ) ;
     980             : 
     981        5522 :     if ( m_pData->m_pViewShell )
     982             :     {
     983        5522 :         SfxViewFrame* pFrame = m_pData->m_pViewShell->GetViewFrame() ;
     984        5522 :         if ( pFrame && pFrame->GetViewShell() == m_pData->m_pViewShell )
     985        5506 :             pFrame->GetFrame().SetIsClosing_Impl();
     986        5522 :         m_pData->m_pViewShell->DiscardClients_Impl();
     987        5522 :         m_pData->m_pViewShell->pImp->m_bControllerSet = false;
     988             : 
     989        5522 :         if ( pFrame )
     990             :         {
     991        5522 :             lang::EventObject aObject;
     992        5522 :             aObject.Source = *this ;
     993             : 
     994        5522 :             SfxObjectShell* pDoc = pFrame->GetObjectShell() ;
     995        5522 :             SfxViewFrame *pView = SfxViewFrame::GetFirst(pDoc);
     996       16482 :             while( pView )
     997             :             {
     998             :                 // if there is another ViewFrame or currently the ViewShell in my ViewFrame is switched (PagePreview)
     999        5456 :                 if ( pView != pFrame || pView->GetViewShell() != m_pData->m_pViewShell )
    1000          18 :                     break;
    1001        5438 :                 pView = SfxViewFrame::GetNext( *pView, pDoc );
    1002             :             }
    1003             : 
    1004        5522 :             SfxGetpApp()->NotifyEvent( SfxViewEventHint(SFX_EVENT_CLOSEVIEW, GlobalEventConfig::GetEventName( STR_EVENT_CLOSEVIEW ), pDoc, Reference< frame::XController2 >( this ) ) );
    1005        5522 :             if ( !pView )
    1006        5504 :                 SfxGetpApp()->NotifyEvent( SfxEventHint(SFX_EVENT_CLOSEDOC, GlobalEventConfig::GetEventName( STR_EVENT_CLOSEDOC ), pDoc) );
    1007             : 
    1008       11044 :             Reference< frame::XModel > xModel = pDoc->GetModel();
    1009       11044 :             Reference < util::XCloseable > xCloseable( xModel, uno::UNO_QUERY );
    1010        5522 :             if ( xModel.is() )
    1011             :             {
    1012        5522 :                 xModel->disconnectController( this );
    1013        5522 :                 if ( xCloseable.is() )
    1014        5522 :                     xCloseable->removeCloseListener( m_pData->m_xCloseListener );
    1015             :             }
    1016             : 
    1017       11044 :             Reference < frame::XFrame > aXFrame;
    1018        5522 :             attachFrame( aXFrame );
    1019             : 
    1020        5522 :             m_pData->m_xListener->disposing( aObject );
    1021        5522 :             SfxViewShell *pShell = m_pData->m_pViewShell;
    1022        5522 :             m_pData->m_pViewShell = NULL;
    1023        5522 :             if ( pFrame->GetViewShell() == pShell )
    1024             :             {
    1025             :                 // Enter registrations only allowed if we are the owner!
    1026        5506 :                 if ( pFrame->GetFrame().OwnsBindings_Impl() )
    1027        5506 :                     pFrame->GetBindings().ENTERREGISTRATIONS();
    1028        5506 :                 pFrame->GetFrame().SetFrameInterface_Impl(  aXFrame );
    1029        5506 :                 pFrame->GetFrame().DoClose_Impl();
    1030        5522 :             }
    1031             :         }
    1032        5522 :     }
    1033        5522 : }
    1034             : 
    1035             : 
    1036             : //  SfxBaseController -> XComponent
    1037             : 
    1038             : 
    1039       11746 : void SAL_CALL SfxBaseController::addEventListener( const Reference< lang::XEventListener >& aListener ) throw( RuntimeException, std::exception )
    1040             : {
    1041       11746 :     m_pData->m_aListenerContainer.addInterface( cppu::UnoType<lang::XEventListener>::get(), aListener );
    1042       11746 : }
    1043             : 
    1044             : 
    1045             : //  SfxBaseController -> XComponent
    1046             : 
    1047             : 
    1048        5902 : void SAL_CALL SfxBaseController::removeEventListener( const Reference< lang::XEventListener >& aListener ) throw( RuntimeException, std::exception )
    1049             : {
    1050        5902 :     m_pData->m_aListenerContainer.removeInterface( cppu::UnoType<lang::XEventListener>::get(), aListener );
    1051        5902 : }
    1052             : 
    1053        5522 : void SfxBaseController::ReleaseShell_Impl()
    1054             : {
    1055        5522 :     SolarMutexGuard aGuard;
    1056        5522 :     if ( m_pData->m_pViewShell )
    1057             :     {
    1058           0 :         SfxObjectShell* pDoc = m_pData->m_pViewShell->GetObjectShell() ;
    1059           0 :         Reference< frame::XModel > xModel = pDoc->GetModel();
    1060           0 :         Reference < util::XCloseable > xCloseable( xModel, uno::UNO_QUERY );
    1061           0 :         if ( xModel.is() )
    1062             :         {
    1063           0 :             xModel->disconnectController( this );
    1064           0 :             if ( xCloseable.is() )
    1065           0 :                 xCloseable->removeCloseListener( m_pData->m_xCloseListener );
    1066             :         }
    1067           0 :         m_pData->m_pViewShell = 0;
    1068             : 
    1069           0 :         Reference < frame::XFrame > aXFrame;
    1070           0 :         attachFrame( aXFrame );
    1071        5522 :     }
    1072        5522 : }
    1073             : 
    1074       29167 : SfxViewShell* SfxBaseController::GetViewShell_Impl() const
    1075             : {
    1076       29167 :     return m_pData->m_pViewShell;
    1077             : }
    1078             : 
    1079           0 : Reference< task::XStatusIndicator > SAL_CALL SfxBaseController::getStatusIndicator(  ) throw (RuntimeException, std::exception)
    1080             : {
    1081           0 :     SolarMutexGuard aGuard;
    1082           0 :     if ( m_pData->m_pViewShell && !m_pData->m_xIndicator.is() )
    1083           0 :         m_pData->m_xIndicator = new SfxStatusIndicator( this, m_pData->m_pViewShell->GetViewFrame()->GetFrame().GetWorkWindow_Impl() );
    1084           0 :     return m_pData->m_xIndicator;
    1085             : }
    1086             : 
    1087           0 : void SAL_CALL SfxBaseController::registerContextMenuInterceptor( const Reference< ui::XContextMenuInterceptor >& xInterceptor ) throw( RuntimeException, std::exception )
    1088             : 
    1089             : {
    1090           0 :     m_pData->m_aInterceptorContainer.addInterface( xInterceptor );
    1091             : 
    1092           0 :     SolarMutexGuard aGuard;
    1093           0 :     if ( m_pData->m_pViewShell )
    1094           0 :         m_pData->m_pViewShell->AddContextMenuInterceptor_Impl( xInterceptor );
    1095           0 : }
    1096             : 
    1097           0 : void SAL_CALL SfxBaseController::releaseContextMenuInterceptor( const Reference< ui::XContextMenuInterceptor >& xInterceptor ) throw( RuntimeException, std::exception )
    1098             : 
    1099             : {
    1100           0 :     m_pData->m_aInterceptorContainer.removeInterface( xInterceptor );
    1101             : 
    1102           0 :     SolarMutexGuard aGuard;
    1103           0 :     if ( m_pData->m_pViewShell )
    1104           0 :         m_pData->m_pViewShell->RemoveContextMenuInterceptor_Impl( xInterceptor );
    1105           0 : }
    1106             : 
    1107           0 : void SAL_CALL SfxBaseController::addKeyHandler( const Reference< awt::XKeyHandler >& xHandler ) throw (RuntimeException, std::exception)
    1108             : {
    1109           0 :     SolarMutexGuard aGuard;
    1110           0 :     m_pData->m_aUserInputInterception.addKeyHandler( xHandler );
    1111           0 : }
    1112             : 
    1113           0 : void SAL_CALL SfxBaseController::removeKeyHandler( const Reference< awt::XKeyHandler >& xHandler ) throw (RuntimeException, std::exception)
    1114             : {
    1115           0 :     SolarMutexGuard aGuard;
    1116           0 :     m_pData->m_aUserInputInterception.removeKeyHandler( xHandler );
    1117           0 : }
    1118             : 
    1119           0 : void SAL_CALL SfxBaseController::addMouseClickHandler( const Reference< awt::XMouseClickHandler >& xHandler ) throw (RuntimeException, std::exception)
    1120             : {
    1121           0 :     SolarMutexGuard aGuard;
    1122           0 :     m_pData->m_aUserInputInterception.addMouseClickHandler( xHandler );
    1123           0 : }
    1124             : 
    1125           0 : void SAL_CALL SfxBaseController::removeMouseClickHandler( const Reference< awt::XMouseClickHandler >& xHandler ) throw (RuntimeException, std::exception)
    1126             : {
    1127           0 :     SolarMutexGuard aGuard;
    1128           0 :     m_pData->m_aUserInputInterception.removeMouseClickHandler( xHandler );
    1129           0 : }
    1130             : 
    1131           0 : uno::Sequence< sal_Int16 > SAL_CALL SfxBaseController::getSupportedCommandGroups()
    1132             : throw (RuntimeException, std::exception)
    1133             : {
    1134           0 :     SolarMutexGuard aGuard;
    1135             : 
    1136           0 :     std::list< sal_Int16 > aGroupList;
    1137           0 :     SfxViewFrame* pViewFrame( m_pData->m_pViewShell->GetFrame() );
    1138           0 :     SfxSlotPool*  pPool = &SfxSlotPool::GetSlotPool( pViewFrame );
    1139             : 
    1140           0 :     SfxSlotPool* pSlotPool = pPool ? pPool : &SFX_SLOTPOOL();
    1141           0 :     const sal_uIntPtr nMode( SFX_SLOT_TOOLBOXCONFIG|SFX_SLOT_ACCELCONFIG|SFX_SLOT_MENUCONFIG );
    1142             : 
    1143             :     // Select Group ( Group 0 is internal )
    1144           0 :     for ( sal_uInt16 i=0; i<pSlotPool->GetGroupCount(); i++ )
    1145             :     {
    1146           0 :         pSlotPool->SeekGroup( i );
    1147           0 :         const SfxSlot* pSfxSlot = pSlotPool->FirstSlot();
    1148           0 :         while ( pSfxSlot )
    1149             :         {
    1150           0 :             if ( pSfxSlot->GetMode() & nMode )
    1151             :             {
    1152           0 :                 sal_Int16 nCommandGroup = MapGroupIDToCommandGroup( pSfxSlot->GetGroupId() );
    1153           0 :                 aGroupList.push_back( nCommandGroup );
    1154           0 :                 break;
    1155             :             }
    1156           0 :             pSfxSlot = pSlotPool->NextSlot();
    1157             :         }
    1158             :     }
    1159             : 
    1160             :     uno::Sequence< sal_Int16 > aSeq =
    1161           0 :         comphelper::containerToSequence< sal_Int16 >( aGroupList );
    1162           0 :     return aSeq;
    1163             : }
    1164             : 
    1165           0 : uno::Sequence< frame::DispatchInformation > SAL_CALL SfxBaseController::getConfigurableDispatchInformation( sal_Int16 nCmdGroup )
    1166             : throw (RuntimeException, std::exception)
    1167             : {
    1168           0 :     std::list< frame::DispatchInformation > aCmdList;
    1169             : 
    1170           0 :     SolarMutexGuard aGuard;
    1171           0 :     if ( m_pData->m_pViewShell )
    1172             :     {
    1173           0 :         const sal_uIntPtr nMode( SFX_SLOT_TOOLBOXCONFIG|SFX_SLOT_ACCELCONFIG|SFX_SLOT_MENUCONFIG );
    1174             : 
    1175           0 :         SfxViewFrame* pViewFrame( m_pData->m_pViewShell->GetFrame() );
    1176           0 :         SfxSlotPool*  pPool( &SfxSlotPool::GetSlotPool( pViewFrame ));
    1177           0 :         OUString aCmdPrefix( ".uno:" );
    1178             : 
    1179           0 :         SfxSlotPool* pSlotPool = pPool ? pPool : &SFX_SLOTPOOL();
    1180           0 :         for ( sal_uInt16 i=0; i<pSlotPool->GetGroupCount(); i++ )
    1181             :         {
    1182           0 :             pSlotPool->SeekGroup( i );
    1183           0 :             const SfxSlot* pSfxSlot = pSlotPool->FirstSlot();
    1184           0 :             if ( pSfxSlot )
    1185             :             {
    1186           0 :                 sal_Int16 nCommandGroup = MapGroupIDToCommandGroup( pSfxSlot->GetGroupId() );
    1187           0 :                 if ( nCommandGroup == nCmdGroup )
    1188             :                 {
    1189           0 :                     while ( pSfxSlot )
    1190             :                     {
    1191           0 :                         if ( pSfxSlot->GetMode() & nMode )
    1192             :                         {
    1193           0 :                             frame::DispatchInformation aCmdInfo;
    1194           0 :                             OUStringBuffer aBuf( aCmdPrefix );
    1195           0 :                             aBuf.appendAscii( pSfxSlot->GetUnoName() );
    1196           0 :                             aCmdInfo.Command = aBuf.makeStringAndClear();
    1197           0 :                             aCmdInfo.GroupId = nCommandGroup;
    1198           0 :                             aCmdList.push_back( aCmdInfo );
    1199             :                         }
    1200           0 :                         pSfxSlot = pSlotPool->NextSlot();
    1201             :                     }
    1202             :                 }
    1203             :             }
    1204           0 :         }
    1205             :     }
    1206             : 
    1207             :     uno::Sequence< frame::DispatchInformation > aSeq =
    1208           0 :         comphelper::containerToSequence< frame::DispatchInformation, std::list< frame::DispatchInformation > >( aCmdList );
    1209             : 
    1210           0 :     return aSeq;
    1211             : }
    1212             : 
    1213           0 : bool SfxBaseController::HandleEvent_Impl( NotifyEvent& rEvent )
    1214             : {
    1215           0 :     return m_pData->m_aUserInputInterception.handleNotifyEvent( rEvent );
    1216             : }
    1217             : 
    1218           0 : bool SfxBaseController::HasKeyListeners_Impl()
    1219             : {
    1220           0 :     return m_pData->m_aUserInputInterception.hasKeyHandlers();
    1221             : }
    1222             : 
    1223           0 : bool SfxBaseController::HasMouseClickListeners_Impl()
    1224             : {
    1225           0 :     return m_pData->m_aUserInputInterception.hasMouseClickListeners();
    1226             : }
    1227             : 
    1228        5531 : void SfxBaseController::ConnectSfxFrame_Impl( const ConnectSfxFrame i_eConnect )
    1229             : {
    1230        5531 :     ENSURE_OR_THROW( m_pData->m_pViewShell, "not to be called without a view shell" );
    1231        5531 :     SfxViewFrame* pViewFrame = m_pData->m_pViewShell->GetFrame();
    1232        5531 :     ENSURE_OR_THROW( pViewFrame, "a view shell without a view frame is pretty pathological" );
    1233             : 
    1234        5531 :     const bool bConnect = ( i_eConnect != E_DISCONNECT );
    1235             : 
    1236             :     // disable window and dispatcher
    1237        5531 :     pViewFrame->Enable( bConnect );
    1238        5531 :     pViewFrame->GetDispatcher()->Lock( !bConnect );
    1239             : 
    1240        5531 :     if ( bConnect )
    1241             :     {
    1242        5524 :         if ( i_eConnect == E_CONNECT )
    1243             :         {
    1244       11048 :             if  (   ( m_pData->m_pViewShell->GetObjectShell() != NULL )
    1245        5524 :                 &&  ( m_pData->m_pViewShell->GetObjectShell()->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
    1246             :                 )
    1247             :             {
    1248           2 :                 SfxViewFrame* pViewFrm = m_pData->m_pViewShell->GetViewFrame();
    1249           2 :                 if ( !pViewFrm->GetFrame().IsInPlace() )
    1250             :                 {
    1251             :                     // for outplace embedded objects, we want the layout manager to keep the content window
    1252             :                     // size constant, if possible
    1253             :                     try
    1254             :                     {
    1255           2 :                         Reference< beans::XPropertySet > xFrameProps( m_pData->m_xFrame, uno::UNO_QUERY_THROW );
    1256             :                         Reference< beans::XPropertySet > xLayouterProps(
    1257           4 :                             xFrameProps->getPropertyValue("LayoutManager"), uno::UNO_QUERY_THROW );
    1258           4 :                         xLayouterProps->setPropertyValue("PreserveContentSize", uno::makeAny( sal_True ) );
    1259             :                     }
    1260           0 :                     catch (const uno::Exception&)
    1261             :                     {
    1262             :                         DBG_UNHANDLED_EXCEPTION();
    1263             :                     }
    1264             :                 }
    1265             :             }
    1266             :         }
    1267             : 
    1268             :         // upon DISCONNECT, we did *not* pop the shells from the stack (this is done elsewhere), so upon
    1269             :         // RECONNECT, we're not allowed to push them
    1270        5524 :         if ( i_eConnect != E_RECONNECT )
    1271             :         {
    1272        5524 :             pViewFrame->GetDispatcher()->Push( *m_pData->m_pViewShell );
    1273        5524 :             if ( m_pData->m_pViewShell->GetSubShell() )
    1274           0 :                 pViewFrame->GetDispatcher()->Push( *m_pData->m_pViewShell->GetSubShell() );
    1275        5524 :             m_pData->m_pViewShell->PushSubShells_Impl();
    1276        5524 :             pViewFrame->GetDispatcher()->Flush();
    1277             :         }
    1278             : 
    1279        5524 :         vcl::Window* pEditWin = m_pData->m_pViewShell->GetWindow();
    1280        5524 :         if ( pEditWin && m_pData->m_pViewShell->IsShowView_Impl() )
    1281        5524 :             pEditWin->Show();
    1282             : 
    1283        5524 :         if ( SfxViewFrame::Current() == pViewFrame )
    1284          16 :             pViewFrame->GetDispatcher()->Update_Impl( true );
    1285             : 
    1286        5524 :         vcl::Window* pFrameWin = &pViewFrame->GetWindow();
    1287        5524 :         if ( pFrameWin != &pViewFrame->GetFrame().GetWindow() )
    1288        5524 :             pFrameWin->Show();
    1289             : 
    1290        5524 :         if ( i_eConnect == E_CONNECT )
    1291             :         {
    1292        5524 :             ::comphelper::NamedValueCollection aDocumentArgs( getModel()->getArgs() );
    1293             : 
    1294        5524 :             const sal_Int16 nPluginMode = aDocumentArgs.getOrDefault( "PluginMode", sal_Int16( 0 ) );
    1295        5524 :             const bool bHasPluginMode = ( nPluginMode != 0 );
    1296             : 
    1297        5524 :             SfxFrame& rFrame = pViewFrame->GetFrame();
    1298        5524 :             SfxObjectShell& rDoc = *m_pData->m_pViewShell->GetObjectShell();
    1299        5524 :             if ( !rFrame.IsMarkedHidden_Impl() )
    1300             :             {
    1301        5454 :                 if ( rDoc.IsHelpDocument() || ( nPluginMode == 2 ) )
    1302           0 :                     pViewFrame->GetDispatcher()->HideUI( true );
    1303             :                 else
    1304        5454 :                     pViewFrame->GetDispatcher()->HideUI( false );
    1305             : 
    1306        5454 :                 if ( rFrame.IsInPlace() )
    1307           0 :                     pViewFrame->LockAdjustPosSizePixel();
    1308             : 
    1309        5454 :                 if ( nPluginMode == 3 )
    1310           0 :                     rFrame.GetWorkWindow_Impl()->SetInternalDockingAllowed( false );
    1311             : 
    1312        5454 :                 if ( !rFrame.IsInPlace() )
    1313        5454 :                     pViewFrame->GetDispatcher()->Update_Impl();
    1314        5454 :                 pViewFrame->Show();
    1315        5454 :                 rFrame.GetWindow().Show();
    1316        5454 :                 if ( !rFrame.IsInPlace() || ( nPluginMode == 3 ) )
    1317        5454 :                     pViewFrame->MakeActive_Impl( rFrame.GetFrameInterface()->isActive() );
    1318             : 
    1319        5454 :                 if ( rFrame.IsInPlace() )
    1320             :                 {
    1321           0 :                     pViewFrame->UnlockAdjustPosSizePixel();
    1322             :                     // force resize for OLE server to fix layout problems of writer and math
    1323             :                     // see i53651
    1324           0 :                     if ( nPluginMode == 3 )
    1325           0 :                         pViewFrame->Resize( true );
    1326             :                 }
    1327             :             }
    1328             :             else
    1329             :             {
    1330             :                 DBG_ASSERT( !rFrame.IsInPlace() && !bHasPluginMode, "Special modes not compatible with hidden mode!" );
    1331          70 :                 rFrame.GetWindow().Show();
    1332             :             }
    1333             : 
    1334             :             // UpdateTitle now, hidden TopFrames have otherwise no Name!
    1335        5524 :             pViewFrame->UpdateTitle();
    1336             : 
    1337        5524 :             if ( !rFrame.IsInPlace() )
    1338        5524 :                 pViewFrame->Resize( true );
    1339             : 
    1340             :             // if there's a JumpMark given, then, well, jump to it
    1341       11048 :             ::comphelper::NamedValueCollection aViewArgs( getCreationArguments() );
    1342       11048 :             const OUString sJumpMark = aViewArgs.getOrDefault( "JumpMark", OUString() );
    1343        5524 :             const bool bHasJumpMark = !sJumpMark.isEmpty();
    1344             :             OSL_ENSURE( ( !m_pData->m_pViewShell->GetObjectShell()->IsLoading() )
    1345             :                     ||  ( sJumpMark.isEmpty() ),
    1346             :                 "SfxBaseController::ConnectSfxFrame_Impl: so this code wasn't dead?" );
    1347             :                 // Before CWS autorecovery, there was code which postponed jumping to the Mark to a later time
    1348             :                 // (SfxObjectShell::PositionView_Impl), but it seems this branch was never used, since this method
    1349             :                 // here is never called before the load process finished. At least not with a non-empty jump mark
    1350        5524 :             if ( !sJumpMark.isEmpty() )
    1351           0 :                 m_pData->m_pViewShell->JumpToMark( sJumpMark );
    1352             : 
    1353             :             // if no plugin mode and no jump mark was supplied, check whether the document itself can provide view data, and
    1354             :             // if so, forward it to the view/shell.
    1355        5524 :             if ( !bHasPluginMode && !bHasJumpMark )
    1356             :             {
    1357             :                 // Note that this might not be the ideal place here. Restoring view data should, IMO, be the
    1358             :                 // responsibility of the loader, not an implementation detail buried here deep within the controller's
    1359             :                 // implementation.
    1360             :                 // What I think should be done to replace the below code:
    1361             :                 // - change SfxBaseController::restoreViewData to also accept a PropertyValue[] (it currently accepts
    1362             :                 //   a string only), and forward it to its ViewShell's ReadUserDataSequence
    1363             :                 // - change the frame loader so that when a new document is loaded (as opposed to an existing
    1364             :                 //   document being loaded into a new frame), the model's view data is examine the very same
    1365             :                 //   way as below, and the proper view data is set via XController::restoreViewData
    1366             :                 // - extend SfxViewFrame::SwitchToViewShell_Impl. Currently, it cares for the case where a non-PrintPreview
    1367             :                 //   view is exchanged, and sets the old view's data at the model. It should also care for the other
    1368             :                 //   way, were the PrintPreview view is left: in this case, the new view should also be initialized
    1369             :                 //   with the model's view data
    1370             :                 try
    1371             :                 {
    1372        5524 :                     Reference< XViewDataSupplier > xViewDataSupplier( getModel(), UNO_QUERY_THROW );
    1373       11048 :                     Reference< XIndexAccess > xViewData( xViewDataSupplier->getViewData() );
    1374             : 
    1375             :                     // find the view data item whose ViewId matches the ID of the view we're just connecting to
    1376        5524 :                     const SfxObjectFactory& rDocFactory( rDoc.GetFactory() );
    1377        5524 :                     const sal_Int32 nCount = xViewData.is() ? xViewData->getCount() : 0;
    1378        5524 :                     sal_Int32 nViewDataIndex = 0;
    1379        8582 :                     for ( sal_Int32 i=0; i<nCount; ++i )
    1380             :                     {
    1381        5470 :                         const ::comphelper::NamedValueCollection aViewData( xViewData->getByIndex(i) );
    1382        5486 :                         OUString sViewId( aViewData.getOrDefault( "ViewId", OUString() ) );
    1383        5470 :                         if ( sViewId.isEmpty() )
    1384        3042 :                             continue;
    1385             : 
    1386        2428 :                         const SfxViewFactory* pViewFactory = rDocFactory.GetViewFactoryByViewName( sViewId );
    1387        2428 :                         if ( pViewFactory == NULL )
    1388           0 :                             continue;
    1389             : 
    1390        2428 :                         if ( pViewFactory->GetOrdinal() == pViewFrame->GetCurViewId() )
    1391             :                         {
    1392        2412 :                             nViewDataIndex = i;
    1393        2412 :                             break;
    1394             :                         }
    1395          16 :                     }
    1396        5524 :                     if ( nViewDataIndex < nCount )
    1397             :                     {
    1398        5470 :                         Sequence< PropertyValue > aViewData;
    1399        5470 :                         OSL_VERIFY( xViewData->getByIndex( nViewDataIndex ) >>= aViewData );
    1400        5470 :                         if ( aViewData.getLength() > 0 )
    1401        5436 :                             m_pData->m_pViewShell->ReadUserDataSequence( aViewData, true );
    1402        5524 :                     }
    1403             :                 }
    1404           0 :                 catch (const Exception&)
    1405             :                 {
    1406             :                     DBG_UNHANDLED_EXCEPTION();
    1407             :                 }
    1408        5524 :             }
    1409             :         }
    1410             :     }
    1411             : 
    1412             :     // invalidate slot corresponding to the view shell
    1413        5531 :     const sal_uInt16 nViewNo = m_pData->m_pViewShell->GetObjectShell()->GetFactory().GetViewNo_Impl( pViewFrame->GetCurViewId(), USHRT_MAX );
    1414             :     DBG_ASSERT( nViewNo != USHRT_MAX, "view shell id not found" );
    1415        5531 :     if ( nViewNo != USHRT_MAX )
    1416        5531 :         pViewFrame->GetBindings().Invalidate( nViewNo + SID_VIEWSHELL0 );
    1417        5531 : }
    1418             : 
    1419        5524 : void SfxBaseController::ShowInfoBars( )
    1420             : {
    1421        5524 :     if ( m_pData->m_pViewShell )
    1422             :     {
    1423             :         // CMIS verifications
    1424        5524 :         Reference< document::XCmisDocument > xCmisDoc( m_pData->m_pViewShell->GetObjectShell()->GetModel(), uno::UNO_QUERY );
    1425        5524 :         if ( xCmisDoc.is( ) && xCmisDoc->canCheckOut( ) )
    1426             :         {
    1427           0 :             uno::Sequence< document::CmisProperty> aCmisProperties = xCmisDoc->getCmisProperties( );
    1428             : 
    1429           0 :             if ( xCmisDoc->isVersionable( ) && aCmisProperties.hasElements( ) )
    1430             :             {
    1431             :                 // Loop over the CMIS Properties to find cmis:isVersionSeriesCheckedOut
    1432             :                 // and find if it is a Google Drive file.
    1433           0 :                 bool bIsGoogleFile = false;
    1434           0 :                 bool bCheckedOut = false;
    1435           0 :                 for ( sal_Int32 i = 0; i < aCmisProperties.getLength(); ++i )
    1436             :                 {
    1437           0 :                     if ( aCmisProperties[i].Id == "cmis:isVersionSeriesCheckedOut" ) {
    1438           0 :                         uno::Sequence< sal_Bool > bTmp;
    1439           0 :                         aCmisProperties[i].Value >>= bTmp;
    1440           0 :                         bCheckedOut = bTmp[0];
    1441             :                     }
    1442             :                     // if it is a Google Drive file, we don't need the checkout bar,
    1443             :                     // still need the checkout feature for the version dialog.
    1444           0 :                     if ( aCmisProperties[i].Name == "title" )
    1445           0 :                         bIsGoogleFile = true;
    1446             :                 }
    1447             : 
    1448           0 :                 if ( !bCheckedOut && !bIsGoogleFile )
    1449             :                 {
    1450             :                     // Get the Frame and show the InfoBar if not checked out
    1451           0 :                     SfxViewFrame* pViewFrame = m_pData->m_pViewShell->GetFrame();
    1452           0 :                     std::vector< PushButton* > aButtons;
    1453           0 :                     PushButton* pBtn = new PushButton( &pViewFrame->GetWindow(), SfxResId( BT_CHECKOUT ) );
    1454           0 :                     pBtn->SetClickHdl( LINK( this, SfxBaseController, CheckOutHandler ) );
    1455           0 :                     aButtons.push_back( pBtn );
    1456           0 :                     pViewFrame->AppendInfoBar( "checkout", SfxResId( STR_NONCHECKEDOUT_DOCUMENT ), aButtons );
    1457             :                 }
    1458           0 :             }
    1459        5524 :         }
    1460             :     }
    1461        5524 : }
    1462             : 
    1463           0 : IMPL_LINK_NOARG ( SfxBaseController, CheckOutHandler )
    1464             : {
    1465           0 :     if ( m_pData->m_pViewShell )
    1466           0 :         m_pData->m_pViewShell->GetObjectShell()->CheckOut( );
    1467           0 :     return 0;
    1468             : }
    1469             : 
    1470             : 
    1471             : 
    1472       27665 : Reference< frame::XTitle > SfxBaseController::impl_getTitleHelper ()
    1473             : {
    1474       27665 :     SolarMutexGuard aGuard;
    1475             : 
    1476       27665 :     if ( ! m_pData->m_xTitleHelper.is ())
    1477             :     {
    1478        5524 :         Reference< frame::XModel >           xModel           = getModel ();
    1479       11048 :         Reference< frame::XUntitledNumbers > xUntitledProvider(xModel                                       , uno::UNO_QUERY      );
    1480       11048 :         Reference< frame::XController >      xThis            (static_cast< frame::XController* >(this), uno::UNO_QUERY_THROW);
    1481             : 
    1482        5524 :         ::framework::TitleHelper* pHelper                 = new ::framework::TitleHelper(::comphelper::getProcessComponentContext());
    1483        5524 :                                   m_pData->m_xTitleHelper = Reference< frame::XTitle >(static_cast< ::cppu::OWeakObject* >(pHelper), uno::UNO_QUERY_THROW);
    1484             : 
    1485        5524 :         pHelper->setOwner                   (xThis            );
    1486       11048 :         pHelper->connectWithUntitledNumbers (xUntitledProvider);
    1487             :     }
    1488             : 
    1489       27665 :     return m_pData->m_xTitleHelper;
    1490             : }
    1491             : 
    1492             : 
    1493             : // frame::XTitle
    1494       22123 : OUString SAL_CALL SfxBaseController::getTitle()
    1495             :     throw (RuntimeException, std::exception)
    1496             : {
    1497       22123 :     return impl_getTitleHelper()->getTitle ();
    1498             : }
    1499             : 
    1500             : 
    1501             : // frame::XTitle
    1502           0 : void SAL_CALL SfxBaseController::setTitle(const OUString& sTitle)
    1503             :     throw (RuntimeException, std::exception)
    1504             : {
    1505           0 :     impl_getTitleHelper()->setTitle (sTitle);
    1506           0 : }
    1507             : 
    1508             : 
    1509             : // frame::XTitleChangeBroadcaster
    1510        5524 : void SAL_CALL SfxBaseController::addTitleChangeListener(const Reference< frame::XTitleChangeListener >& xListener)
    1511             :     throw (RuntimeException, std::exception)
    1512             : {
    1513        5524 :     Reference< frame::XTitleChangeBroadcaster > xBroadcaster(impl_getTitleHelper(), uno::UNO_QUERY);
    1514        5524 :     if (xBroadcaster.is ())
    1515        5524 :         xBroadcaster->addTitleChangeListener (xListener);
    1516        5524 : }
    1517             : 
    1518             : 
    1519             : // frame::XTitleChangeBroadcaster
    1520          18 : void SAL_CALL SfxBaseController::removeTitleChangeListener(const Reference< frame::XTitleChangeListener >& xListener)
    1521             :     throw (RuntimeException, std::exception)
    1522             : {
    1523          18 :     Reference< frame::XTitleChangeBroadcaster > xBroadcaster(impl_getTitleHelper(), uno::UNO_QUERY);
    1524          18 :     if (xBroadcaster.is ())
    1525          18 :         xBroadcaster->removeTitleChangeListener (xListener);
    1526          18 : }
    1527             : 
    1528        5524 : void SfxBaseController::initialize( const css::uno::Sequence< css::uno::Any >& /*aArguments*/ ) throw (css::uno::RuntimeException, std::exception)
    1529             : {
    1530        5524 :     if (m_pData->m_pViewShell)
    1531        5524 :         m_pData->m_pViewShell->Initialize();
    1532        6475 : }
    1533             : 
    1534             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10