LCOV - code coverage report
Current view: top level - sfx2/source/toolbox - tbxitem.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 224 659 34.0 %
Date: 2014-04-11 Functions: 28 85 32.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #ifdef SOLARIS
      22             : #include <ctime>
      23             : #endif
      24             : 
      25             : #include <string>
      26             : #include <com/sun/star/uno/Reference.h>
      27             : #include <com/sun/star/frame/XFrame.hpp>
      28             : #include <com/sun/star/awt/XPopupMenu.hpp>
      29             : #include <com/sun/star/awt/XWindow.hpp>
      30             : #include <com/sun/star/awt/XWindowPeer.hpp>
      31             : #include <com/sun/star/util/URL.hpp>
      32             : #include <com/sun/star/util/URLTransformer.hpp>
      33             : #include <com/sun/star/util/XURLTransformer.hpp>
      34             : #include <com/sun/star/frame/XController.hpp>
      35             : #include <com/sun/star/lang/XUnoTunnel.hpp>
      36             : #include <com/sun/star/document/MacroExecMode.hpp>
      37             : #include <com/sun/star/document/UpdateDocMode.hpp>
      38             : #include <com/sun/star/frame/Desktop.hpp>
      39             : #include <com/sun/star/frame/XComponentLoader.hpp>
      40             : #include <com/sun/star/beans/PropertyValue.hpp>
      41             : #include <com/sun/star/beans/XPropertySet.hpp>
      42             : #include <com/sun/star/frame/XLayoutManager.hpp>
      43             : #include <com/sun/star/frame/XPopupMenuController.hpp>
      44             : #include <com/sun/star/frame/status/ItemStatus.hpp>
      45             : #include <com/sun/star/frame/status/ItemState.hpp>
      46             : #include <com/sun/star/ui/XUIElementFactory.hpp>
      47             : #include <com/sun/star/frame/XModuleManager.hpp>
      48             : #include <com/sun/star/container/XNameAccess.hpp>
      49             : #include <com/sun/star/ui/XUIFunctionListener.hpp>
      50             : #include <com/sun/star/ui/theUIElementFactoryManager.hpp>
      51             : #include <com/sun/star/frame/status/Visibility.hpp>
      52             : #include <svl/eitem.hxx>
      53             : #include <svl/stritem.hxx>
      54             : #include <svl/intitem.hxx>
      55             : #include <svl/imageitm.hxx>
      56             : #include <svl/visitem.hxx>
      57             : #include <svl/urlbmk.hxx>
      58             : #include <vcl/toolbox.hxx>
      59             : #include <unotools/moduleoptions.hxx>
      60             : 
      61             : #include <svtools/imagemgr.hxx>
      62             : #include <comphelper/processfactory.hxx>
      63             : #include <framework/addonmenu.hxx>
      64             : #include <framework/addonsoptions.hxx>
      65             : #include <framework/menuconfiguration.hxx>
      66             : #include <framework/sfxhelperfunctions.hxx>
      67             : #include <vcl/taskpanelist.hxx>
      68             : #include <toolkit/helper/vclunohelper.hxx>
      69             : #include <svtools/menuoptions.hxx>
      70             : #include <svtools/miscopt.hxx>
      71             : 
      72             : #include <sfx2/tbxctrl.hxx>
      73             : #include <sfx2/mnumgr.hxx>
      74             : #include <sfx2/dispatch.hxx>
      75             : #include <sfx2/msg.hxx>
      76             : #include <sfx2/msgpool.hxx>
      77             : #include "statcach.hxx"
      78             : #include <sfx2/viewfrm.hxx>
      79             : #include "arrdecl.hxx"
      80             : #include "sfxtypes.hxx"
      81             : #include <sfx2/genlink.hxx>
      82             : #include <sfx2/sfxresid.hxx>
      83             : #include <sfx2/sfx.hrc>
      84             : #include <sfx2/module.hxx>
      85             : #include <sfx2/docfile.hxx>
      86             : #include <sfx2/docfac.hxx>
      87             : #include <sfx2/frmhtmlw.hxx>
      88             : #include <sfx2/app.hxx>
      89             : #include <sfx2/unoctitm.hxx>
      90             : #include "helpid.hrc"
      91             : #include "workwin.hxx"
      92             : #include <sfx2/imgmgr.hxx>
      93             : #include "virtmenu.hxx"
      94             : #include <sfx2/imagemgr.hxx>
      95             : 
      96             : using namespace ::com::sun::star;
      97             : using namespace ::com::sun::star::beans;
      98             : using namespace ::com::sun::star::frame;
      99             : using namespace ::com::sun::star::frame::status;
     100             : using namespace ::com::sun::star::lang;
     101             : using namespace ::com::sun::star::uno;
     102             : using namespace ::com::sun::star::util;
     103             : using namespace ::com::sun::star::container;
     104             : using namespace ::com::sun::star::ui;
     105             : 
     106             : 
     107             : 
     108         143 : SFX_IMPL_TOOLBOX_CONTROL_ARG(SfxToolBoxControl, SfxStringItem, true);
     109         784 : SFX_IMPL_TOOLBOX_CONTROL(SfxRecentFilesToolBoxControl, SfxStringItem);
     110             : 
     111           0 : static Window* GetTopMostParentSystemWindow( Window* pWindow )
     112             : {
     113             :     OSL_ASSERT( pWindow );
     114           0 :     if ( pWindow )
     115             :     {
     116             :         // ->manually search topmost system window
     117             :         // required because their might be another system window between this and the top window
     118           0 :         pWindow = pWindow->GetParent();
     119           0 :         SystemWindow* pTopMostSysWin = NULL;
     120           0 :         while ( pWindow )
     121             :         {
     122           0 :             if ( pWindow->IsSystemWindow() )
     123           0 :                 pTopMostSysWin = (SystemWindow*)pWindow;
     124           0 :             pWindow = pWindow->GetParent();
     125             :         }
     126           0 :         pWindow = pTopMostSysWin;
     127             :         OSL_ASSERT( pWindow );
     128           0 :         return pWindow;
     129             :     }
     130             : 
     131           0 :     return NULL;
     132             : }
     133             : 
     134       39953 : svt::ToolboxController* SAL_CALL SfxToolBoxControllerFactory( const Reference< XFrame >& rFrame, ToolBox* pToolbox, unsigned short nID, const OUString& aCommandURL )
     135             : {
     136       39953 :     SolarMutexGuard aGuard;
     137             : 
     138       79906 :     URL aTargetURL;
     139       39953 :     aTargetURL.Complete = aCommandURL;
     140       79906 :     Reference < XURLTransformer > xTrans( URLTransformer::create( ::comphelper::getProcessComponentContext() ) );
     141       39953 :     xTrans->parseStrict( aTargetURL );
     142       39953 :     if ( !aTargetURL.Arguments.isEmpty() )
     143           0 :         return NULL;
     144             : 
     145       39953 :     SfxObjectShell* pObjShell = NULL;
     146       79906 :     Reference < XController > xController;
     147       79906 :     Reference < XModel > xModel;
     148       39953 :     if ( rFrame.is() )
     149             :     {
     150       39953 :         xController = rFrame->getController();
     151       39953 :         if ( xController.is() )
     152       39953 :             xModel = xController->getModel();
     153             :     }
     154             : 
     155       39953 :     if ( xModel.is() )
     156             :     {
     157             :         // Get tunnel from model to retrieve the SfxObjectShell pointer from it
     158       39933 :         ::com::sun::star::uno::Reference < ::com::sun::star::lang::XUnoTunnel > xObj( xModel, UNO_QUERY );
     159       39933 :         if ( xObj.is() )
     160             :         {
     161       39933 :             ::com::sun::star::uno::Sequence < sal_Int8 > aSeq = SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence();
     162       39933 :             sal_Int64 nHandle = xObj->getSomething( aSeq );
     163       39933 :             if ( nHandle )
     164       39440 :                 pObjShell = reinterpret_cast< SfxObjectShell* >( sal::static_int_cast< sal_IntPtr >( nHandle ));
     165       39933 :         }
     166             :     }
     167             : 
     168       39953 :     SfxModule*     pModule   = pObjShell ? pObjShell->GetModule() : NULL;
     169       39953 :     SfxSlotPool*   pSlotPool = 0;
     170             : 
     171       39953 :     if ( pModule )
     172       39440 :         pSlotPool = pModule->GetSlotPool();
     173             :     else
     174         513 :         pSlotPool = &(SfxSlotPool::GetSlotPool( NULL ));
     175             : 
     176       39953 :     const SfxSlot* pSlot = pSlotPool->GetUnoSlot( aTargetURL.Path );
     177       39953 :     if ( pSlot )
     178             :     {
     179       39508 :         sal_uInt16 nSlotId = pSlot->GetSlotId();
     180       39508 :         if ( nSlotId > 0 )
     181       39508 :             return SfxToolBoxControl::CreateControl( nSlotId, nID, pToolbox, pModule );
     182             :     }
     183             : 
     184       40398 :     return NULL;
     185             : }
     186             : 
     187       20444 : struct SfxToolBoxControl_Impl
     188             : {
     189             :     ToolBox*                pBox;
     190             :     bool                    bShowString;
     191             :     SfxTbxCtrlFactory*      pFact;
     192             :     sal_uInt16              nTbxId;
     193             :     sal_uInt16              nSlotId;
     194             :     SfxPopupWindow*         mpFloatingWindow;
     195             :     SfxPopupWindow*         mpPopupWindow;
     196             :     Reference< XUIElement > mxUIElement;
     197             : 
     198             :     DECL_LINK( WindowEventListener, VclSimpleEvent* );
     199             : };
     200             : 
     201           0 : IMPL_LINK( SfxToolBoxControl_Impl, WindowEventListener, VclSimpleEvent*, pEvent )
     202             : {
     203           0 :     if ( pEvent &&
     204           0 :          pEvent->ISA( VclWindowEvent ) &&
     205           0 :          (( pEvent->GetId() == VCLEVENT_WINDOW_MOVE ) ||
     206           0 :           ( pEvent->GetId() == VCLEVENT_WINDOW_ACTIVATE )))
     207             :     {
     208           0 :         Window* pWindow( ((VclWindowEvent*)pEvent)->GetWindow() );
     209           0 :         if (( pWindow == mpFloatingWindow ) &&
     210           0 :             ( mpPopupWindow != 0 ))
     211             :         {
     212           0 :             delete mpPopupWindow;
     213           0 :             mpPopupWindow = 0;
     214             :         }
     215             :     }
     216             : 
     217           0 :     return 1;
     218             : }
     219             : 
     220             : 
     221             : 
     222       10222 : SfxToolBoxControl::SfxToolBoxControl(
     223             :     sal_uInt16      nSlotID,
     224             :     sal_uInt16      nID,
     225             :     ToolBox&        rBox,
     226             :     bool            bShowStringItems     )
     227       10222 : :   svt::ToolboxController()
     228             : {
     229       10222 :     pImpl = new SfxToolBoxControl_Impl;
     230             : 
     231       10222 :     pImpl->pBox = &rBox;
     232       10222 :     pImpl->bShowString = bShowStringItems;
     233       10222 :     pImpl->pFact = 0;
     234       10222 :     pImpl->nTbxId = nID;
     235       10222 :     pImpl->nSlotId = nSlotID;
     236       10222 :     pImpl->mpFloatingWindow = 0;
     237       10222 :     pImpl->mpPopupWindow = 0;
     238       10222 : }
     239             : 
     240             : 
     241             : 
     242       20444 : SfxToolBoxControl::~SfxToolBoxControl()
     243             : {
     244       10222 :     if ( pImpl->mxUIElement.is() )
     245             :     {
     246           0 :         Reference< XComponent > xComponent( pImpl->mxUIElement, UNO_QUERY );
     247           0 :         xComponent->dispose();
     248             :     }
     249       10222 :     pImpl->mxUIElement = 0;
     250       10222 :     delete pImpl;
     251       10222 : }
     252             : 
     253             : 
     254             : 
     255       29995 : ToolBox& SfxToolBoxControl::GetToolBox() const
     256             : {
     257       29995 :     return *pImpl->pBox;
     258             : }
     259       60351 : unsigned short SfxToolBoxControl::GetId() const
     260             : {
     261       60351 :     return pImpl->nTbxId;
     262             : }
     263        4294 : unsigned short SfxToolBoxControl::GetSlotId() const
     264             : {
     265        4294 :     return pImpl->nSlotId;
     266             : }
     267             : 
     268             : 
     269             : 
     270       10120 : void SAL_CALL SfxToolBoxControl::dispose() throw (::com::sun::star::uno::RuntimeException, std::exception)
     271             : {
     272       10120 :     if ( m_bDisposed )
     273       10120 :         return;
     274             : 
     275       10120 :     svt::ToolboxController::dispose();
     276             : 
     277             :     // Remove and destroy our item window at our toolbox
     278       10120 :     SolarMutexGuard aGuard;
     279       10120 :     Window* pWindow = pImpl->pBox->GetItemWindow( pImpl->nTbxId );
     280       10120 :     pImpl->pBox->SetItemWindow( pImpl->nTbxId, 0 );
     281       10120 :     delete pWindow;
     282             : 
     283             :     // Dispose an open sub toolbar. It's possible that we have an open
     284             :     // sub toolbar while we get disposed. Therefore we have to dispose
     285             :     // it now! Not doing so would result in a crash. The sub toolbar
     286             :     // gets destroyed asynchronously and would access a non-existing
     287             :     // parent toolbar!
     288       10120 :     if ( pImpl->mxUIElement.is() )
     289             :     {
     290           0 :         Reference< XComponent > xComponent( pImpl->mxUIElement, UNO_QUERY );
     291           0 :         xComponent->dispose();
     292             :     }
     293       10120 :     pImpl->mxUIElement = 0;
     294             : 
     295             :     // Delete my popup windows
     296       10120 :     delete pImpl->mpFloatingWindow;
     297       10120 :     delete pImpl->mpPopupWindow;
     298             : 
     299       10120 :     pImpl->mpFloatingWindow = 0;
     300       10120 :     pImpl->mpPopupWindow = 0;
     301             : }
     302             : 
     303             : 
     304        5600 : void SfxToolBoxControl::RegisterToolBoxControl( SfxModule* pMod, SfxTbxCtrlFactory* pFact)
     305             : {
     306        5600 :     SFX_APP()->RegisterToolBoxControl_Impl( pMod, pFact );
     307        5600 : }
     308             : 
     309       39508 : SfxToolBoxControl* SfxToolBoxControl::CreateControl( sal_uInt16 nSlotId, sal_uInt16 nTbxId, ToolBox *pBox, SfxModule* pMod  )
     310             : {
     311       39508 :     SolarMutexGuard aGuard;
     312             : 
     313       39508 :     SfxApplication *pApp = SFX_APP();
     314             : 
     315             :     SfxSlotPool *pSlotPool;
     316       39508 :     if ( pMod )
     317       39297 :         pSlotPool = pMod->GetSlotPool();
     318             :     else
     319         211 :         pSlotPool = &SfxSlotPool::GetSlotPool();
     320       39508 :     TypeId aSlotType = pSlotPool->GetSlotType( nSlotId );
     321       39508 :     if ( aSlotType )
     322             :     {
     323             :         SfxToolBoxControl *pCtrl;
     324       39508 :         if ( pMod )
     325             :         {
     326       39297 :             SfxTbxCtrlFactArr_Impl *pFactories = pMod->GetTbxCtrlFactories_Impl();
     327       39297 :             if ( pFactories )
     328             :             {
     329       39297 :                 SfxTbxCtrlFactArr_Impl &rFactories = *pFactories;
     330             :                 sal_uInt16 nFactory;
     331       39297 :                 const sal_uInt16 nCount = rFactories.size();
     332             : 
     333             :                 // search for a factory with the given slot id
     334     1862511 :                 for( nFactory = 0; nFactory < nCount; ++nFactory )
     335     1833017 :                     if( (rFactories[nFactory]->nTypeId == aSlotType) && (rFactories[nFactory]->nSlotId == nSlotId) )
     336        9803 :                         break;
     337             : 
     338       39297 :                 if( nFactory == nCount )
     339             :                 {
     340             :                     // if no factory exists for the given slot id, see if we
     341             :                     // have a generic factory with the correct slot type and slot id == 0
     342     1604827 :                     for ( nFactory = 0; nFactory < nCount; ++nFactory )
     343     1575585 :                         if( (rFactories[nFactory]->nTypeId == aSlotType) && (rFactories[nFactory]->nSlotId == 0) )
     344         252 :                             break;
     345             :                 }
     346             : 
     347       39297 :                 if( nFactory < nCount )
     348             :                 {
     349       10055 :                     pCtrl = rFactories[nFactory]->pCtor( nSlotId, nTbxId, *pBox );
     350       10055 :                     pCtrl->pImpl->pFact = rFactories[nFactory];
     351       10055 :                     return pCtrl;
     352             :                 }
     353             :             }
     354             :         }
     355             : 
     356       29453 :         SfxTbxCtrlFactArr_Impl &rFactories = pApp->GetTbxCtrlFactories_Impl();
     357             :         sal_uInt16 nFactory;
     358       29453 :         const sal_uInt16 nCount = rFactories.size();
     359             : 
     360      320700 :         for( nFactory = 0; nFactory < nCount; ++nFactory )
     361      291312 :             if( (rFactories[nFactory]->nTypeId == aSlotType) && (rFactories[nFactory]->nSlotId == nSlotId) )
     362          65 :                 break;
     363             : 
     364       29453 :         if( nFactory == nCount )
     365             :         {
     366             :             // if no factory exists for the given slot id, see if we
     367             :             // have a generic factory with the correct slot type and slot id == 0
     368      320440 :             for( nFactory = 0; nFactory < nCount; ++nFactory )
     369      291052 :                 if( (rFactories[nFactory]->nTypeId == aSlotType) && (rFactories[nFactory]->nSlotId == 0) )
     370           0 :                     break;
     371             :         }
     372             : 
     373       29453 :         if( nFactory < nCount )
     374             :         {
     375          65 :             pCtrl = rFactories[nFactory]->pCtor( nSlotId, nTbxId, *pBox );
     376          65 :             pCtrl->pImpl->pFact = rFactories[nFactory];
     377          65 :             return pCtrl;
     378             :         }
     379             :     }
     380             : 
     381       29388 :     return NULL;
     382             : }
     383             : 
     384        3860 : SfxItemState SfxToolBoxControl::GetItemState(
     385             :     const SfxPoolItem* pState )
     386             : /*  [Description]
     387             : 
     388             :     Static method for determining the status of the SfxPoolItem-pointer,
     389             :     used in the method <SfxControllerItem::StateChanged(const SfxPoolItem*)>.
     390             : 
     391             :     [Return value]
     392             : 
     393             :     SfxItemState        SFX_ITEM_UNKNOWN
     394             :                         Enabled, however no further status information is available.
     395             :                         Typical for <Slot>s, which are temporarily disabled a
     396             :                         anyway but other than that do not change their appearance.
     397             : 
     398             :                         SFX_ITEM_DISABLED
     399             :                         Disabled, no further status information is available.
     400             :                         All other displayed values should be reset to the default
     401             :                         if possible.
     402             : 
     403             :                         SFX_ITEM_DONTCARE
     404             :                         Enabled but there were only ambiguous values available
     405             :                         (i.e. none that could be queried).
     406             : 
     407             :                         SFX_ITEM_AVAILABLE
     408             :                         Enabled and with available values which can be queried
     409             :                         through'pState'. The type is thus by the Slot clearly
     410             :                         defined in the entire Program.
     411             : */
     412             : 
     413             : {
     414             :     return !pState
     415             :                 ? SFX_ITEM_DISABLED
     416         324 :                 : IsInvalidItem(pState)
     417             :                     ? SFX_ITEM_DONTCARE
     418         324 :                     : pState->ISA(SfxVoidItem) && !pState->Which()
     419             :                         ? SFX_ITEM_UNKNOWN
     420        4508 :                         : SFX_ITEM_AVAILABLE;
     421             : }
     422             : 
     423         522 : void SfxToolBoxControl::Dispatch(
     424             :     const Reference< XDispatchProvider >& rProvider,
     425             :     const OUString& rCommand,
     426             :     Sequence< ::PropertyValue >& aArgs )
     427             : {
     428         522 :     if ( rProvider.is() )
     429             :     {
     430         522 :         ::com::sun::star::util::URL aTargetURL;
     431         522 :         aTargetURL.Complete = rCommand;
     432        1044 :         Reference < XURLTransformer > xTrans( URLTransformer::create( ::comphelper::getProcessComponentContext() ) );
     433         522 :         xTrans->parseStrict( aTargetURL );
     434             : 
     435        1044 :         Reference < XDispatch > xDispatch = rProvider->queryDispatch( aTargetURL, OUString(), 0 );
     436         522 :         if ( xDispatch.is() )
     437         676 :             xDispatch->dispatch( aTargetURL, aArgs );
     438             :     }
     439         522 : }
     440             : 
     441           0 : void SfxToolBoxControl::Dispatch( const OUString& aCommand, ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs )
     442             : {
     443           0 :     Reference < XController > xController;
     444             : 
     445           0 :     SolarMutexGuard aGuard;
     446           0 :     if ( getFrameInterface().is() )
     447           0 :         xController = getFrameInterface()->getController();
     448             : 
     449           0 :     Reference < XDispatchProvider > xProvider( xController, UNO_QUERY );
     450           0 :     if ( xProvider.is() )
     451             :     {
     452           0 :         ::com::sun::star::util::URL aTargetURL;
     453           0 :         aTargetURL.Complete = aCommand;
     454           0 :         getURLTransformer()->parseStrict( aTargetURL );
     455             : 
     456           0 :         Reference < XDispatch > xDispatch = xProvider->queryDispatch( aTargetURL, OUString(), 0 );
     457           0 :         if ( xDispatch.is() )
     458           0 :             xDispatch->dispatch( aTargetURL, aArgs );
     459           0 :     }
     460           0 : }
     461             : 
     462             : // XInterface
     463      102851 : Any SAL_CALL SfxToolBoxControl::queryInterface( const Type & rType )
     464             : throw(::com::sun::star::uno::RuntimeException, std::exception)
     465             : {
     466             :     ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType,
     467             :                                            (static_cast< ::com::sun::star::awt::XDockableWindowListener* >(this)),
     468      102851 :                                         (static_cast< ::com::sun::star::frame::XSubToolbarController* >(this)));
     469      102851 :     return (aRet.hasValue() ? aRet : svt::ToolboxController::queryInterface( rType ));
     470             : }
     471             : 
     472      278296 : void SAL_CALL SfxToolBoxControl::acquire() throw()
     473             : {
     474      278296 :     OWeakObject::acquire();
     475      278296 : }
     476             : 
     477      278296 : void SAL_CALL SfxToolBoxControl::release() throw()
     478             : {
     479      278296 :     OWeakObject::release();
     480      278296 : }
     481             : 
     482           0 : void SAL_CALL SfxToolBoxControl::disposing( const ::com::sun::star::lang::EventObject& aEvent )
     483             : throw( ::com::sun::star::uno::RuntimeException, std::exception )
     484             : {
     485           0 :     svt::ToolboxController::disposing( aEvent );
     486           0 : }
     487             : 
     488             : // XStatusListener
     489       22142 : void SAL_CALL SfxToolBoxControl::statusChanged( const FeatureStateEvent& rEvent )
     490             : throw ( ::com::sun::star::uno::RuntimeException, std::exception )
     491             : {
     492       22142 :     SfxViewFrame* pViewFrame = NULL;
     493       22142 :     Reference < XController > xController;
     494             : 
     495       44284 :     SolarMutexGuard aGuard;
     496       22142 :     if ( getFrameInterface().is() )
     497       22142 :         xController = getFrameInterface()->getController();
     498             : 
     499       44284 :     Reference < XDispatchProvider > xProvider( xController, UNO_QUERY );
     500       22142 :     if ( xProvider.is() )
     501             :     {
     502       22142 :         Reference < XDispatch > xDisp = xProvider->queryDispatch( rEvent.FeatureURL, OUString(), 0 );
     503       22142 :         if ( xDisp.is() )
     504             :         {
     505       22142 :             Reference< XUnoTunnel > xTunnel( xDisp, UNO_QUERY );
     506       22142 :             SfxOfficeDispatch* pDisp = NULL;
     507       22142 :             if ( xTunnel.is() )
     508             :             {
     509       22142 :                 sal_Int64 nImplementation = xTunnel->getSomething(SfxOfficeDispatch::impl_getStaticIdentifier());
     510       22142 :                 pDisp = reinterpret_cast< SfxOfficeDispatch* >( sal::static_int_cast< sal_IntPtr >( nImplementation ));
     511             :             }
     512             : 
     513       22142 :             if ( pDisp )
     514       22142 :                 pViewFrame = pDisp->GetDispatcher_Impl()->GetFrame();
     515       22142 :         }
     516             :     }
     517             : 
     518       22142 :     sal_uInt16 nSlotId = 0;
     519       22142 :     SfxSlotPool& rPool = SfxSlotPool::GetSlotPool( pViewFrame );
     520       22142 :     const SfxSlot* pSlot = rPool.GetUnoSlot( rEvent.FeatureURL.Path );
     521       22142 :     if ( pSlot )
     522       22142 :         nSlotId = pSlot->GetSlotId();
     523           0 :     else if ( m_aCommandURL == rEvent.FeatureURL.Path )
     524           0 :         nSlotId = GetSlotId();
     525             : 
     526       22142 :     if ( nSlotId > 0 )
     527             :     {
     528       22142 :         if ( rEvent.Requery )
     529           0 :             svt::ToolboxController::statusChanged( rEvent );
     530             :         else
     531             :         {
     532       22142 :             SfxItemState eState = SFX_ITEM_DISABLED;
     533       22142 :             SfxPoolItem* pItem = NULL;
     534       22142 :             if ( rEvent.IsEnabled )
     535             :             {
     536       19089 :                 eState = SFX_ITEM_AVAILABLE;
     537       19089 :                 ::com::sun::star::uno::Type pType = rEvent.State.getValueType();
     538             : 
     539       19089 :                 if ( pType == ::getVoidCppuType() )
     540             :                 {
     541        5328 :                     pItem = new SfxVoidItem( nSlotId );
     542        5328 :                     eState = SFX_ITEM_UNKNOWN;
     543             :                 }
     544       13761 :                 else if ( pType == ::getBooleanCppuType() )
     545             :                 {
     546        6139 :                     bool bTemp = false;
     547        6139 :                     rEvent.State >>= bTemp ;
     548        6139 :                     pItem = new SfxBoolItem( nSlotId, bTemp );
     549             :                 }
     550        7622 :                 else if ( pType == ::getCppuType((const sal_uInt16*)0) )
     551             :                 {
     552           0 :                     sal_uInt16 nTemp = 0;
     553           0 :                     rEvent.State >>= nTemp ;
     554           0 :                     pItem = new SfxUInt16Item( nSlotId, nTemp );
     555             :                 }
     556        7622 :                 else if ( pType == ::getCppuType((const sal_uInt32*)0) )
     557             :                 {
     558           0 :                     sal_uInt32 nTemp = 0;
     559           0 :                     rEvent.State >>= nTemp ;
     560           0 :                     pItem = new SfxUInt32Item( nSlotId, nTemp );
     561             :                 }
     562        7622 :                 else if ( pType == ::getCppuType((const OUString*)0) )
     563             :                 {
     564         324 :                     OUString sTemp ;
     565         324 :                     rEvent.State >>= sTemp ;
     566         324 :                     pItem = new SfxStringItem( nSlotId, sTemp );
     567             :                 }
     568        7298 :                 else if ( pType == ::getCppuType((const ::com::sun::star::frame::status::ItemStatus*)0) )
     569             :                 {
     570           0 :                     ItemStatus aItemStatus;
     571           0 :                     rEvent.State >>= aItemStatus;
     572           0 :                     eState = aItemStatus.State;
     573           0 :                     pItem = new SfxVoidItem( nSlotId );
     574             :                 }
     575        7298 :                 else if ( pType == ::getCppuType((const ::com::sun::star::frame::status::Visibility*)0) )
     576             :                 {
     577           0 :                     Visibility aVisibilityStatus;
     578           0 :                     rEvent.State >>= aVisibilityStatus;
     579           0 :                     pItem = new SfxVisibilityItem( nSlotId, aVisibilityStatus.bVisible );
     580             :                 }
     581             :                 else
     582             :                 {
     583        7298 :                     if ( pSlot )
     584        7298 :                         pItem = pSlot->GetType()->CreateItem();
     585        7298 :                     if ( pItem )
     586             :                     {
     587        7298 :                         pItem->SetWhich( nSlotId );
     588        7298 :                         pItem->PutValue( rEvent.State );
     589             :                     }
     590             :                     else
     591           0 :                         pItem = new SfxVoidItem( nSlotId );
     592       19089 :                 }
     593             :             }
     594             : 
     595       22142 :             StateChanged( nSlotId, eState, pItem );
     596       22142 :             delete pItem;
     597             :         }
     598       22142 :     }
     599       22142 : }
     600             : 
     601             : // XSubToolbarController
     602        9742 : sal_Bool SAL_CALL SfxToolBoxControl::opensSubToolbar() throw (::com::sun::star::uno::RuntimeException, std::exception)
     603             : {
     604        9742 :     return sal_False;
     605             : }
     606             : 
     607           0 : OUString SAL_CALL SfxToolBoxControl::getSubToolbarName() throw (::com::sun::star::uno::RuntimeException, std::exception)
     608             : {
     609           0 :     return OUString();
     610             : }
     611             : 
     612           0 : void SAL_CALL SfxToolBoxControl::functionSelected( const OUString& /*aCommand*/ ) throw (::com::sun::star::uno::RuntimeException, std::exception)
     613             : {
     614             :     // must be implemented by sub-class
     615           0 : }
     616             : 
     617           0 : void SAL_CALL SfxToolBoxControl::updateImage() throw (::com::sun::star::uno::RuntimeException, std::exception)
     618             : {
     619             :     // must be implemented by sub-class
     620           0 : }
     621             : 
     622             : // XToolbarController
     623           0 : void SAL_CALL SfxToolBoxControl::execute( sal_Int16 KeyModifier ) throw (::com::sun::star::uno::RuntimeException, std::exception)
     624             : {
     625           0 :     SolarMutexGuard aGuard;
     626           0 :     Select( (sal_uInt16)KeyModifier );
     627           0 : }
     628             : 
     629           0 : void SAL_CALL SfxToolBoxControl::click() throw (::com::sun::star::uno::RuntimeException, std::exception)
     630             : {
     631           0 :     SolarMutexGuard aGuard;
     632           0 :     Click();
     633           0 : }
     634             : 
     635           0 : void SAL_CALL SfxToolBoxControl::doubleClick() throw (::com::sun::star::uno::RuntimeException, std::exception)
     636             : {
     637           0 :     SolarMutexGuard aGuard;
     638           0 :     DoubleClick();
     639           0 : }
     640             : 
     641           0 : Reference< ::com::sun::star::awt::XWindow > SAL_CALL SfxToolBoxControl::createPopupWindow() throw (::com::sun::star::uno::RuntimeException, std::exception)
     642             : {
     643           0 :     SolarMutexGuard aGuard;
     644           0 :     Window* pWindow = CreatePopupWindow();
     645           0 :     if ( pWindow )
     646           0 :         return VCLUnoHelper::GetInterface( pWindow );
     647             :     else
     648           0 :         return Reference< ::com::sun::star::awt::XWindow >();
     649             : }
     650             : 
     651       10120 : Reference< ::com::sun::star::awt::XWindow > SAL_CALL SfxToolBoxControl::createItemWindow( const Reference< ::com::sun::star::awt::XWindow >& rParent ) throw (::com::sun::star::uno::RuntimeException, std::exception)
     652             : {
     653       10120 :     SolarMutexGuard aGuard;
     654       10120 :     return VCLUnoHelper::GetInterface( CreateItemWindow( VCLUnoHelper::GetWindow( rParent )));
     655             : }
     656             : 
     657             : // XDockableWindowListener
     658           0 : void SAL_CALL SfxToolBoxControl::startDocking( const ::com::sun::star::awt::DockingEvent& )
     659             : throw (::com::sun::star::uno::RuntimeException, std::exception)
     660             : {
     661           0 : }
     662           0 : ::com::sun::star::awt::DockingData SAL_CALL SfxToolBoxControl::docking( const ::com::sun::star::awt::DockingEvent& )
     663             : throw (::com::sun::star::uno::RuntimeException, std::exception)
     664             : {
     665           0 :     return ::com::sun::star::awt::DockingData();
     666             : }
     667             : 
     668           0 : void SAL_CALL SfxToolBoxControl::endDocking( const ::com::sun::star::awt::EndDockingEvent& )
     669             : throw (::com::sun::star::uno::RuntimeException, std::exception)
     670             : {
     671           0 : }
     672             : 
     673           0 : sal_Bool SAL_CALL SfxToolBoxControl::prepareToggleFloatingMode( const ::com::sun::star::lang::EventObject& )
     674             : throw (::com::sun::star::uno::RuntimeException, std::exception)
     675             : {
     676           0 :     return sal_False;
     677             : }
     678             : 
     679           0 : void SAL_CALL SfxToolBoxControl::toggleFloatingMode( const ::com::sun::star::lang::EventObject& )
     680             : throw (::com::sun::star::uno::RuntimeException, std::exception)
     681             : {
     682           0 : }
     683             : 
     684           0 : void SAL_CALL SfxToolBoxControl::closed( const ::com::sun::star::lang::EventObject& )
     685             : throw (::com::sun::star::uno::RuntimeException, std::exception)
     686             : {
     687           0 : }
     688             : 
     689           0 : void SAL_CALL SfxToolBoxControl::endPopupMode( const ::com::sun::star::awt::EndPopupModeEvent& aEvent )
     690             : throw (::com::sun::star::uno::RuntimeException, std::exception)
     691             : {
     692           0 :     SolarMutexGuard aGuard;
     693             : 
     694           0 :     OUString aSubToolBarResName;
     695           0 :     if ( pImpl->mxUIElement.is() )
     696             :     {
     697           0 :         Reference< XPropertySet > xPropSet( pImpl->mxUIElement, UNO_QUERY );
     698           0 :         if ( xPropSet.is() )
     699             :         {
     700             :             try
     701             :             {
     702           0 :                 xPropSet->getPropertyValue("ResourceURL") >>= aSubToolBarResName;
     703             :             }
     704           0 :             catch ( com::sun::star::beans::UnknownPropertyException& )
     705             :             {
     706             :             }
     707           0 :             catch ( com::sun::star::lang::WrappedTargetException& )
     708             :             {
     709             :             }
     710             :         }
     711             : 
     712           0 :         Reference< XComponent > xComponent( pImpl->mxUIElement, UNO_QUERY );
     713           0 :         xComponent->dispose();
     714             :     }
     715           0 :     pImpl->mxUIElement = 0;
     716             : 
     717             :     // if the toolbar was teared-off recreate it and place it at the given position
     718           0 :     if( aEvent.bTearoff )
     719             :     {
     720           0 :         Reference< XUIElement >     xUIElement;
     721           0 :         Reference< XLayoutManager > xLayoutManager = getLayoutManager();
     722             : 
     723           0 :         if ( !xLayoutManager.is() )
     724           0 :             return;
     725             : 
     726           0 :         xLayoutManager->createElement( aSubToolBarResName );
     727           0 :         xUIElement = xLayoutManager->getElement( aSubToolBarResName );
     728           0 :         if ( xUIElement.is() )
     729             :         {
     730           0 :             Reference< ::com::sun::star::awt::XWindow > xParent = getFrameInterface()->getContainerWindow();
     731             : 
     732           0 :             Reference< ::com::sun::star::awt::XWindow > xSubToolBar( xUIElement->getRealInterface(), UNO_QUERY );
     733           0 :             Reference< ::com::sun::star::beans::XPropertySet > xProp( xUIElement, UNO_QUERY );
     734           0 :             if ( xSubToolBar.is() && xProp.is() )
     735             :             {
     736           0 :                 OUString aPersistentString( "Persistent" );
     737             :                 try
     738             :                 {
     739           0 :                     Window*  pTbxWindow = VCLUnoHelper::GetWindow( xSubToolBar );
     740           0 :                     if ( pTbxWindow && pTbxWindow->GetType() == WINDOW_TOOLBOX )
     741             :                     {
     742           0 :                         Any a;
     743           0 :                         a = xProp->getPropertyValue( aPersistentString );
     744           0 :                         xProp->setPropertyValue( aPersistentString, makeAny( sal_False ));
     745             : 
     746           0 :                         xLayoutManager->hideElement( aSubToolBarResName );
     747           0 :                         xLayoutManager->floatWindow( aSubToolBarResName );
     748             : 
     749           0 :                         xLayoutManager->setElementPos( aSubToolBarResName, aEvent.FloatingPosition );
     750           0 :                         xLayoutManager->showElement( aSubToolBarResName );
     751             : 
     752           0 :                         xProp->setPropertyValue("Persistent", a );
     753             :                     }
     754             :                 }
     755           0 :                 catch ( ::com::sun::star::uno::RuntimeException& )
     756             :                 {
     757           0 :                     throw;
     758             :                 }
     759           0 :                 catch ( ::com::sun::star::uno::Exception& )
     760             :                 {
     761           0 :                 }
     762           0 :             }
     763           0 :         }
     764           0 :     }
     765             : }
     766             : 
     767           0 : ::Size  SfxToolBoxControl::getPersistentFloatingSize( const Reference< XFrame >& /*xFrame*/, const OUString& /*rSubToolBarResName*/ )
     768             : {
     769           0 :     ::Size  aToolboxSize;
     770           0 :     return aToolboxSize;
     771             : }
     772             : 
     773         313 : bool SfxToolBoxControl::hasBigImages() const
     774             : {
     775         313 :     return (GetToolBox().GetToolboxButtonSize() == TOOLBOX_BUTTONSIZE_LARGE);
     776             : }
     777             : 
     778           0 : void SfxToolBoxControl::createAndPositionSubToolBar( const OUString& rSubToolBarResName )
     779             : {
     780           0 :     SolarMutexGuard aGuard;
     781             : 
     782           0 :     if ( pImpl->pBox )
     783             :     {
     784           0 :         static WeakReference< XUIElementFactoryManager > xWeakUIElementFactory;
     785             : 
     786           0 :         sal_uInt16 nItemId = pImpl->pBox->GetDownItemId();
     787             : 
     788           0 :         if ( !nItemId )
     789           0 :             return;
     790             : 
     791             :         // create element with factory
     792           0 :         Reference< XFrame >                 xFrame          = getFrameInterface();
     793           0 :         Reference< XUIElement >             xUIElement;
     794           0 :         Reference< XUIElementFactoryManager >  xUIElementFactory;
     795             : 
     796           0 :         xUIElementFactory = xWeakUIElementFactory;
     797           0 :         if ( !xUIElementFactory.is() )
     798             :         {
     799           0 :             xUIElementFactory = theUIElementFactoryManager::get( m_xContext );
     800           0 :             xWeakUIElementFactory = xUIElementFactory;
     801             :         }
     802             : 
     803           0 :         Sequence< PropertyValue > aPropSeq( 3 );
     804           0 :         aPropSeq[0].Name = "Frame";
     805           0 :         aPropSeq[0].Value <<= xFrame;
     806           0 :         aPropSeq[1].Name = "Persistent";
     807           0 :         aPropSeq[1].Value <<= sal_False;
     808           0 :         aPropSeq[2].Name = "PopupMode";
     809           0 :         aPropSeq[2].Value <<= sal_True;
     810             : 
     811             :         try
     812             :         {
     813           0 :             xUIElement = xUIElementFactory->createUIElement( rSubToolBarResName, aPropSeq );
     814             :         }
     815           0 :         catch ( ::com::sun::star::container::NoSuchElementException& )
     816             :         {
     817             :         }
     818           0 :         catch ( IllegalArgumentException& )
     819             :         {
     820             :         }
     821             : 
     822           0 :         if ( xUIElement.is() )
     823             :         {
     824           0 :             Reference< ::com::sun::star::awt::XWindow > xParent = getFrameInterface()->getContainerWindow();
     825             : 
     826           0 :             Reference< ::com::sun::star::awt::XWindow > xSubToolBar( xUIElement->getRealInterface(), UNO_QUERY );
     827           0 :             if ( xSubToolBar.is() )
     828             :             {
     829           0 :                 Reference< ::com::sun::star::awt::XDockableWindow > xDockWindow( xSubToolBar, UNO_QUERY );
     830           0 :                 xDockWindow->addDockableWindowListener( Reference< ::com::sun::star::awt::XDockableWindowListener >(
     831           0 :                     static_cast< OWeakObject * >( this ), UNO_QUERY ));
     832           0 :                 xDockWindow->enableDocking( sal_True );
     833             : 
     834             :                 // keep refererence to UIElement to avoid its destruction
     835           0 :                 if ( pImpl->mxUIElement.is() )
     836             :                 {
     837           0 :                     Reference< XComponent > xComponent( pImpl->mxUIElement, UNO_QUERY );
     838           0 :                     xComponent->dispose();
     839             :                 }
     840           0 :                 pImpl->mxUIElement = xUIElement;
     841             : 
     842           0 :                 Window*  pTbxWindow = VCLUnoHelper::GetWindow( xSubToolBar );
     843           0 :                 ToolBox* pToolBar( 0 );
     844           0 :                 if ( pTbxWindow && pTbxWindow->GetType() == WINDOW_TOOLBOX )
     845           0 :                     pToolBar = (ToolBox *)pTbxWindow;
     846             : 
     847           0 :                 if ( pToolBar )
     848             :                 {
     849           0 :                     Window*  pParentTbxWindow( pImpl->pBox );
     850           0 :                     pToolBar->SetParent( pParentTbxWindow );
     851           0 :                     ::Size aSize = getPersistentFloatingSize( xFrame, rSubToolBarResName );
     852           0 :                     if ( aSize.Width() == 0 || aSize.Height() == 0 )
     853             :                     {
     854             :                         // calc and set size for popup mode
     855           0 :                         aSize = pToolBar->CalcPopupWindowSizePixel();
     856             :                     }
     857           0 :                     pToolBar->SetSizePixel( aSize );
     858             : 
     859             :                     // open subtoolbox in popup mode
     860           0 :                     Window::GetDockingManager()->StartPopupMode( pImpl->pBox, pToolBar );
     861           0 :                 }
     862           0 :             }
     863           0 :         }
     864           0 :     }
     865             : }
     866             : 
     867             : 
     868             : 
     869           0 : void SfxToolBoxControl::SetPopupWindow( SfxPopupWindow* pWindow )
     870             : {
     871           0 :     pImpl->mpPopupWindow = pWindow;
     872           0 :     pImpl->mpPopupWindow->SetPopupModeEndHdl( LINK( this, SfxToolBoxControl, PopupModeEndHdl ));
     873           0 :     pImpl->mpPopupWindow->SetDeleteLink_Impl( LINK( this, SfxToolBoxControl, ClosePopupWindow ));
     874           0 : }
     875             : 
     876             : 
     877             : 
     878           0 : IMPL_LINK_NOARG(SfxToolBoxControl, PopupModeEndHdl)
     879             : {
     880           0 :     if ( pImpl->mpPopupWindow->IsVisible() )
     881             :     {
     882             :         // Replace floating window with popup window and destroy
     883             :         // floating window instance.
     884           0 :         delete pImpl->mpFloatingWindow;
     885           0 :         pImpl->mpFloatingWindow = pImpl->mpPopupWindow;
     886           0 :         pImpl->mpPopupWindow    = 0;
     887             :         // We also need to know when the user tries to use the
     888             :         // floating window.
     889           0 :         pImpl->mpFloatingWindow->AddEventListener( LINK( pImpl, SfxToolBoxControl_Impl, WindowEventListener ));
     890             :     }
     891             :     else
     892             :     {
     893             :         // Popup window has been closed by the user. No replacement, instance
     894             :         // will destroy itself.
     895           0 :         pImpl->mpPopupWindow = 0;
     896             :     }
     897             : 
     898           0 :     return 1;
     899             : }
     900             : 
     901             : 
     902           0 : IMPL_LINK( SfxToolBoxControl, ClosePopupWindow, SfxPopupWindow *, pWindow )
     903             : {
     904           0 :     if ( pWindow == pImpl->mpFloatingWindow )
     905           0 :         pImpl->mpFloatingWindow = 0;
     906             :     else
     907           0 :         pImpl->mpPopupWindow = 0;
     908             : 
     909           0 :     return 1;
     910             : }
     911             : 
     912             : 
     913             : 
     914        6816 : void SfxToolBoxControl::StateChanged
     915             : (
     916             :     sal_uInt16              nId,
     917             :     SfxItemState        eState,
     918             :     const SfxPoolItem*  pState
     919             : )
     920             : {
     921             :     DBG_ASSERT( pImpl->pBox != 0, "setting state to dangling ToolBox" );
     922             : 
     923        6816 :     if ( GetId() >= SID_OBJECTMENU0 && GetId() <= SID_OBJECTMENU_LAST )
     924        6816 :         return;
     925             : 
     926             :     // enabled/disabled-Flag correcting the lump sum
     927        6816 :     pImpl->pBox->EnableItem( GetId(), eState != SFX_ITEM_DISABLED );
     928             : 
     929        6816 :     sal_uInt16 nItemBits = pImpl->pBox->GetItemBits( GetId() );
     930        6816 :     nItemBits &= ~TIB_CHECKABLE;
     931        6816 :     ::TriState eTri = TRISTATE_FALSE;
     932        6816 :     switch ( eState )
     933             :     {
     934             :         case SFX_ITEM_AVAILABLE:
     935        5772 :         if ( pState )
     936             :         {
     937        5772 :             if ( pState->ISA(SfxBoolItem) )
     938             :             {
     939             :                 // BoolItem for checking
     940        4298 :                 if ( ((const SfxBoolItem*)pState)->GetValue() )
     941        1530 :                     eTri = TRISTATE_TRUE;
     942        4298 :                 nItemBits |= TIB_CHECKABLE;
     943             :             }
     944        2239 :             else if ( pState->ISA(SfxEnumItemInterface) &&
     945         765 :                 ((SfxEnumItemInterface *)pState)->HasBoolValue())
     946             :             {
     947             :                 // EnumItem is handled as Bool
     948           0 :                 if ( ((const SfxEnumItemInterface *)pState)->GetBoolValue() )
     949           0 :                     eTri = TRISTATE_TRUE;
     950           0 :                 nItemBits |= TIB_CHECKABLE;
     951             :             }
     952        1474 :             else if ( pImpl->bShowString && pState->ISA(SfxStringItem) )
     953           0 :                 pImpl->pBox->SetItemText(nId, ((const SfxStringItem*)pState)->GetValue() );
     954             :         }
     955        5772 :         break;
     956             : 
     957             :         case SFX_ITEM_DONTCARE:
     958             :         {
     959           0 :             eTri = TRISTATE_INDET;
     960           0 :             nItemBits |= TIB_CHECKABLE;
     961             :         }
     962           0 :         break;
     963             :     }
     964             : 
     965        6816 :     pImpl->pBox->SetItemState( GetId(), eTri );
     966        6816 :     pImpl->pBox->SetItemBits( GetId(), nItemBits );
     967             : }
     968             : 
     969             : 
     970             : 
     971           0 : void SfxToolBoxControl::Select( sal_uInt16 nSelectModifier )
     972             : {
     973           0 :     svt::ToolboxController::execute( nSelectModifier );
     974           0 : }
     975             : 
     976             : 
     977             : 
     978           0 : void SfxToolBoxControl::DoubleClick()
     979             : {
     980           0 : }
     981             : 
     982             : 
     983             : 
     984           0 : void SfxToolBoxControl::Click()
     985             : {
     986           0 : }
     987             : 
     988             : 
     989             : 
     990           0 : SfxPopupWindowType SfxToolBoxControl::GetPopupWindowType() const
     991             : {
     992           0 :     return SFX_POPUPWINDOW_NONE;
     993             : }
     994             : 
     995             : 
     996             : 
     997           0 : SfxPopupWindow* SfxToolBoxControl::CreatePopupWindow()
     998             : {
     999           0 :     return 0;
    1000             : }
    1001             : 
    1002           0 : SfxPopupWindow* SfxToolBoxControl::CreatePopupWindowCascading()
    1003             : {
    1004           0 :     return 0;
    1005             : }
    1006             : 
    1007             : 
    1008             : 
    1009        8734 : Window* SfxToolBoxControl::CreateItemWindow( Window * )
    1010             : {
    1011        8734 :     return 0;
    1012             : }
    1013             : 
    1014             : 
    1015             : 
    1016           0 : SfxFrameStatusListener::SfxFrameStatusListener(
    1017             :     const Reference< XComponentContext >& rxContext,
    1018             :     const Reference< XFrame >& xFrame,
    1019             :     SfxStatusListenerInterface* pCallee ) :
    1020             :     svt::FrameStatusListener( rxContext, xFrame ),
    1021           0 :     m_pCallee( pCallee )
    1022             : {
    1023           0 : }
    1024             : 
    1025             : 
    1026             : 
    1027           0 : SfxFrameStatusListener::~SfxFrameStatusListener()
    1028             : {
    1029           0 : }
    1030             : 
    1031             : 
    1032             : 
    1033             : // XStatusListener
    1034           0 : void SAL_CALL SfxFrameStatusListener::statusChanged( const ::com::sun::star::frame::FeatureStateEvent& rEvent )
    1035             : throw ( ::com::sun::star::uno::RuntimeException, std::exception )
    1036             : {
    1037           0 :     SfxViewFrame* pViewFrame = NULL;
    1038           0 :     Reference < XController > xController;
    1039             : 
    1040           0 :     SolarMutexGuard aGuard;
    1041           0 :     if ( m_xFrame.is() )
    1042           0 :         xController = m_xFrame->getController();
    1043             : 
    1044           0 :     Reference < XDispatchProvider > xProvider( xController, UNO_QUERY );
    1045           0 :     if ( xProvider.is() )
    1046             :     {
    1047           0 :         Reference < XDispatch > xDisp = xProvider->queryDispatch( rEvent.FeatureURL, OUString(), 0 );
    1048           0 :         if ( xDisp.is() )
    1049             :         {
    1050           0 :             Reference< XUnoTunnel > xTunnel( xDisp, UNO_QUERY );
    1051           0 :             SfxOfficeDispatch* pDisp = NULL;
    1052           0 :             if ( xTunnel.is() )
    1053             :             {
    1054           0 :                 sal_Int64 nImplementation = xTunnel->getSomething(SfxOfficeDispatch::impl_getStaticIdentifier());
    1055           0 :                 pDisp = reinterpret_cast< SfxOfficeDispatch* >( sal::static_int_cast< sal_IntPtr >( nImplementation ));
    1056             :             }
    1057             : 
    1058           0 :             if ( pDisp )
    1059           0 :                 pViewFrame = pDisp->GetDispatcher_Impl()->GetFrame();
    1060           0 :         }
    1061             :     }
    1062             : 
    1063           0 :     sal_uInt16 nSlotId = 0;
    1064           0 :     SfxSlotPool& rPool = SfxSlotPool::GetSlotPool( pViewFrame );
    1065           0 :     const SfxSlot* pSlot = rPool.GetUnoSlot( rEvent.FeatureURL.Path );
    1066           0 :     if ( pSlot )
    1067           0 :         nSlotId = pSlot->GetSlotId();
    1068             : 
    1069           0 :     if ( nSlotId > 0 )
    1070             :     {
    1071           0 :         if ( rEvent.Requery )
    1072             :         {
    1073             :             // requery for the notified state
    1074           0 :             addStatusListener( rEvent.FeatureURL.Complete );
    1075             :         }
    1076             :         else
    1077             :         {
    1078           0 :             SfxItemState eState = SFX_ITEM_DISABLED;
    1079           0 :             SfxPoolItem* pItem = NULL;
    1080           0 :             if ( rEvent.IsEnabled )
    1081             :             {
    1082           0 :                 eState = SFX_ITEM_AVAILABLE;
    1083           0 :                 ::com::sun::star::uno::Type pType = rEvent.State.getValueType();
    1084             : 
    1085           0 :                 if ( pType == ::getVoidCppuType() )
    1086             :                 {
    1087           0 :                     pItem = new SfxVoidItem( nSlotId );
    1088           0 :                     eState = SFX_ITEM_UNKNOWN;
    1089             :                 }
    1090           0 :                 else if ( pType == ::getBooleanCppuType() )
    1091             :                 {
    1092           0 :                     bool bTemp = false;
    1093           0 :                     rEvent.State >>= bTemp ;
    1094           0 :                     pItem = new SfxBoolItem( nSlotId, bTemp );
    1095             :                 }
    1096           0 :                 else if ( pType == ::getCppuType((const sal_uInt16*)0) )
    1097             :                 {
    1098           0 :                     sal_uInt16 nTemp = 0;
    1099           0 :                     rEvent.State >>= nTemp ;
    1100           0 :                     pItem = new SfxUInt16Item( nSlotId, nTemp );
    1101             :                 }
    1102           0 :                 else if ( pType == ::getCppuType((const sal_uInt32*)0) )
    1103             :                 {
    1104           0 :                     sal_uInt32 nTemp = 0;
    1105           0 :                     rEvent.State >>= nTemp ;
    1106           0 :                     pItem = new SfxUInt32Item( nSlotId, nTemp );
    1107             :                 }
    1108           0 :                 else if ( pType == ::getCppuType((const OUString*)0) )
    1109             :                 {
    1110           0 :                     OUString sTemp ;
    1111           0 :                     rEvent.State >>= sTemp ;
    1112           0 :                     pItem = new SfxStringItem( nSlotId, sTemp );
    1113             :                 }
    1114           0 :                 else if ( pType == ::getCppuType((const ::com::sun::star::frame::status::ItemStatus*)0) )
    1115             :                 {
    1116           0 :                     ItemStatus aItemStatus;
    1117           0 :                     rEvent.State >>= aItemStatus;
    1118           0 :                     eState = aItemStatus.State;
    1119           0 :                     pItem = new SfxVoidItem( nSlotId );
    1120             :                 }
    1121           0 :                 else if ( pType == ::getCppuType((const ::com::sun::star::frame::status::Visibility*)0) )
    1122             :                 {
    1123           0 :                     Visibility aVisibilityStatus;
    1124           0 :                     rEvent.State >>= aVisibilityStatus;
    1125           0 :                     pItem = new SfxVisibilityItem( nSlotId, aVisibilityStatus.bVisible );
    1126             :                 }
    1127             :                 else
    1128             :                 {
    1129           0 :                     if ( pSlot )
    1130           0 :                         pItem = pSlot->GetType()->CreateItem();
    1131           0 :                     if ( pItem )
    1132             :                     {
    1133           0 :                         pItem->SetWhich( nSlotId );
    1134           0 :                         pItem->PutValue( rEvent.State );
    1135             :                     }
    1136             :                     else
    1137           0 :                         pItem = new SfxVoidItem( nSlotId );
    1138           0 :                 }
    1139             :             }
    1140             : 
    1141           0 :             if ( m_pCallee )
    1142           0 :                 m_pCallee->StateChanged( nSlotId, eState, pItem );
    1143           0 :             delete pItem;
    1144             :         }
    1145           0 :     }
    1146           0 : }
    1147             : 
    1148             : 
    1149             : 
    1150           0 : SfxPopupWindow::SfxPopupWindow(
    1151             :     sal_uInt16 nId,
    1152             :     const Reference< XFrame >& rFrame,
    1153             :     WinBits nBits ) :
    1154             :     FloatingWindow( SFX_APP()->GetTopWindow(), nBits )
    1155             :     , m_bFloating( false )
    1156             :     , m_bCascading( false )
    1157             :     , m_nId( nId )
    1158             :     , m_xFrame( rFrame )
    1159           0 :     , m_pStatusListener( 0 )
    1160             : {
    1161           0 :     Window* pWindow = GetTopMostParentSystemWindow( this );
    1162           0 :     if ( pWindow )
    1163           0 :         ((SystemWindow *)pWindow)->GetTaskPaneList()->AddWindow( this );
    1164           0 : }
    1165             : 
    1166             : 
    1167             : 
    1168           0 : SfxPopupWindow::SfxPopupWindow(
    1169             :     sal_uInt16 nId,
    1170             :     const Reference< XFrame >& rFrame,
    1171             :     const ResId &rId ) :
    1172             :     FloatingWindow( SFX_APP()->GetTopWindow(), rId )
    1173             :     , m_bFloating( false )
    1174             :     , m_bCascading( false )
    1175             :     , m_nId( nId )
    1176             :     , m_xFrame( rFrame )
    1177           0 :     , m_pStatusListener( 0 )
    1178             : {
    1179           0 :     Window* pWindow = GetTopMostParentSystemWindow( this );
    1180           0 :     if ( pWindow )
    1181           0 :         ((SystemWindow *)pWindow)->GetTaskPaneList()->AddWindow( this );
    1182           0 : }
    1183             : 
    1184             : 
    1185             : 
    1186           0 : SfxPopupWindow::SfxPopupWindow(
    1187             :     sal_uInt16 nId,
    1188             :     const Reference< XFrame >& rFrame,
    1189             :     Window* pParentWindow,
    1190             :     WinBits nBits ) :
    1191             :     FloatingWindow( pParentWindow, nBits )
    1192             :     , m_bFloating( false )
    1193             :     , m_bCascading( false )
    1194             :     , m_nId( nId )
    1195             :     , m_xFrame( rFrame )
    1196           0 :     , m_pStatusListener( 0 )
    1197             : {
    1198           0 :     Window* pWindow = GetTopMostParentSystemWindow( this );
    1199           0 :     if ( pWindow )
    1200           0 :         ((SystemWindow *)pWindow)->GetTaskPaneList()->AddWindow( this );
    1201           0 : }
    1202             : 
    1203           0 : SfxPopupWindow::SfxPopupWindow(
    1204             :     sal_uInt16 nId,
    1205             :     const Reference< XFrame >& rFrame,
    1206             :     Window* pParentWindow,
    1207             :     const ResId &rId ) :
    1208             :     FloatingWindow( pParentWindow, rId )
    1209             :     , m_bFloating( false )
    1210             :     , m_bCascading( false )
    1211             :     , m_nId( nId )
    1212             :     , m_xFrame( rFrame )
    1213           0 :     , m_pStatusListener( 0 )
    1214             : {
    1215           0 :     Window* pWindow = GetTopMostParentSystemWindow( this );
    1216           0 :     if ( pWindow )
    1217           0 :         ((SystemWindow *)pWindow)->GetTaskPaneList()->AddWindow( this );
    1218           0 : }
    1219             : 
    1220             : 
    1221             : 
    1222           0 : SfxPopupWindow::~SfxPopupWindow()
    1223             : {
    1224           0 :     if ( m_xStatusListener.is() )
    1225             :     {
    1226           0 :         m_xStatusListener->dispose();
    1227           0 :         m_xStatusListener.clear();
    1228             :     }
    1229             : 
    1230           0 :     Window* pWindow = GetTopMostParentSystemWindow( this );
    1231           0 :     if ( pWindow )
    1232           0 :         ((SystemWindow *)pWindow)->GetTaskPaneList()->RemoveWindow( this );
    1233           0 : }
    1234             : 
    1235             : 
    1236             : 
    1237           0 : SfxFrameStatusListener* SfxPopupWindow::GetOrCreateStatusListener()
    1238             : {
    1239           0 :     if ( !m_xStatusListener.is() )
    1240             :     {
    1241             :         m_pStatusListener = new SfxFrameStatusListener(
    1242             :                                     ::comphelper::getProcessComponentContext(),
    1243             :                                     m_xFrame,
    1244           0 :                                     this );
    1245           0 :         m_xStatusListener = Reference< XComponent >( static_cast< cppu::OWeakObject* >(
    1246           0 :                                                         m_pStatusListener ), UNO_QUERY );
    1247             :     }
    1248             : 
    1249           0 :     return m_pStatusListener;
    1250             : }
    1251             : 
    1252             : 
    1253             : 
    1254           0 : void SfxPopupWindow::BindListener()
    1255             : {
    1256           0 :     GetOrCreateStatusListener();
    1257           0 :     if ( m_xStatusListener.is() )
    1258           0 :         m_pStatusListener->bindListener();
    1259           0 : }
    1260             : 
    1261             : 
    1262             : 
    1263           0 : void SfxPopupWindow::UnbindListener()
    1264             : {
    1265           0 :     GetOrCreateStatusListener();
    1266           0 :     if ( m_xStatusListener.is() )
    1267           0 :         m_pStatusListener->unbindListener();
    1268           0 : }
    1269             : 
    1270             : 
    1271             : 
    1272           0 : void SfxPopupWindow::AddStatusListener( const OUString& rCommandURL )
    1273             : {
    1274           0 :     GetOrCreateStatusListener();
    1275           0 :     if ( m_xStatusListener.is() )
    1276           0 :         m_pStatusListener->addStatusListener( rCommandURL );
    1277           0 : }
    1278             : 
    1279             : 
    1280             : 
    1281           0 : bool SfxPopupWindow::Close()
    1282             : {
    1283           0 :     m_bFloating = false;
    1284           0 :     FloatingWindow::Close();
    1285             : 
    1286           0 :     Delete();
    1287           0 :     return true;
    1288             : }
    1289             : 
    1290             : 
    1291             : 
    1292           0 : void SfxPopupWindow::PopupModeEnd()
    1293             : {
    1294             :     //! to allow PopupModeEndHdl to be called
    1295           0 :     FloatingWindow::PopupModeEnd();
    1296             : 
    1297           0 :     if ( IsVisible() )
    1298             :     {
    1299             :         // was teared-off
    1300           0 :         DeleteFloatingWindow();
    1301           0 :         m_bFloating = true;
    1302             :     }
    1303             :     else
    1304           0 :         Close();
    1305           0 : }
    1306             : 
    1307             : 
    1308             : 
    1309           0 : void SfxPopupWindow::DeleteFloatingWindow()
    1310             : {
    1311           0 :     if ( m_bFloating )
    1312             :     {
    1313           0 :         Hide();
    1314           0 :         Delete();
    1315             :     }
    1316           0 : }
    1317             : 
    1318             : 
    1319             : 
    1320           0 : void SfxPopupWindow::MouseMove( const ::MouseEvent& rMEvt )
    1321             : {
    1322           0 :     if ( !m_bCascading )
    1323           0 :         FloatingWindow::MouseMove( rMEvt );
    1324             :     else
    1325             :     {
    1326             :         // Forward MouseMove-Event to Children
    1327           0 :         ::Point       aPos = rMEvt.GetPosPixel();
    1328           0 :         ::Point       aScrPos = OutputToScreenPixel( aPos );
    1329           0 :         sal_uInt16 i = 0;
    1330           0 :         Window* pWindow = GetChild( i );
    1331           0 :         while ( pWindow )
    1332             :         {
    1333             :             ::MouseEvent aMEvt( pWindow->ScreenToOutputPixel( aScrPos ),
    1334           0 :                               rMEvt.GetClicks(), rMEvt.GetMode(),
    1335           0 :                               rMEvt.GetButtons(), rMEvt.GetModifier() );
    1336           0 :             pWindow->MouseMove( rMEvt );
    1337           0 :             pWindow->Update();
    1338           0 :             i++;
    1339           0 :             pWindow = GetChild( i );
    1340             :         }
    1341             :     }
    1342           0 : }
    1343             : 
    1344             : 
    1345             : 
    1346           0 : void SfxPopupWindow::StartCascading()
    1347             : {
    1348           0 :     m_bCascading = true;
    1349           0 : }
    1350             : 
    1351             : 
    1352             : 
    1353           0 : SfxPopupWindow* SfxPopupWindow::Clone() const
    1354             : 
    1355             : /*  [Description]
    1356             : 
    1357             :     This method must be overloaded to show this Popup also in the
    1358             :     Presentation-mode. It is called when a Show() would be meaningless
    1359             :     since the parent is no presentation window.
    1360             :     When create a new window the bew Top-Window will be used automatically,
    1361             :     so that the Parent becomes the presentation window and and that the new
    1362             :     Popup therefore becomes visible.
    1363             : */
    1364             : 
    1365             : {
    1366           0 :     return 0;
    1367             : }
    1368             : 
    1369             : 
    1370             : 
    1371           0 : void SfxPopupWindow::StateChanged(
    1372             :     sal_uInt16 /*nSID*/,
    1373             :     SfxItemState eState,
    1374             :     const SfxPoolItem* /*pState*/ )
    1375             : /*  [Description]
    1376             : 
    1377             :     See also <SfxControllerItem::StateChanged()>. In addition the Popup
    1378             :     will become hidden when eState==SFX_ITEM_DISABLED and in all other
    1379             :     cases it will be shown again if it is floating. In general this requires
    1380             :     to call the Base class.
    1381             : 
    1382             :     Due to the parent the presentation mode is handled in a special way.
    1383             : */
    1384             : 
    1385             : {
    1386           0 :     if ( SFX_ITEM_DISABLED == eState )
    1387             :     {
    1388           0 :         Hide();
    1389             :     }
    1390           0 :     else if ( m_bFloating )
    1391             :     {
    1392           0 :         Show( true, SHOW_NOFOCUSCHANGE | SHOW_NOACTIVATE );
    1393             :     }
    1394           0 : }
    1395             : 
    1396             : 
    1397             : 
    1398           0 : void SfxPopupWindow::Delete()
    1399             : {
    1400           0 :     if ( m_aDeleteLink.IsSet() )
    1401           0 :         m_aDeleteLink.Call( this );
    1402           0 :     delete this;
    1403           0 : }
    1404             : 
    1405             : 
    1406             : 
    1407         570 : SfxRecentFilesToolBoxControl::SfxRecentFilesToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rBox )
    1408         570 :     : SfxToolBoxControl( nSlotId, nId, rBox )
    1409             : {
    1410         570 :     rBox.SetItemBits( nId, rBox.GetItemBits( nId ) | TIB_DROPDOWN);
    1411         570 : }
    1412             : 
    1413        1140 : SfxRecentFilesToolBoxControl::~SfxRecentFilesToolBoxControl()
    1414             : {
    1415        1140 : }
    1416             : 
    1417           0 : SfxPopupWindow* SfxRecentFilesToolBoxControl::CreatePopupWindow()
    1418             : {
    1419           0 :     ToolBox& rBox = GetToolBox();
    1420           0 :     sal_uInt16 nItemId = GetId();
    1421           0 :     ::Rectangle aRect( rBox.GetItemRect( nItemId ) );
    1422             : 
    1423           0 :     Sequence< Any > aArgs( 2 );
    1424           0 :     PropertyValue aPropValue;
    1425             : 
    1426           0 :     aPropValue.Name = "CommandURL";
    1427           0 :     aPropValue.Value <<= OUString( ".uno:RecentFileList" );
    1428           0 :     aArgs[0] <<= aPropValue;
    1429             : 
    1430           0 :     aPropValue.Name = "Frame";
    1431           0 :     aPropValue.Value <<= m_xFrame;
    1432           0 :     aArgs[1] <<= aPropValue;
    1433             : 
    1434           0 :     uno::Reference< frame::XPopupMenuController > xPopupController( m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
    1435           0 :                 "com.sun.star.comp.framework.RecentFilesMenuController", aArgs, m_xContext ), UNO_QUERY );
    1436             : 
    1437           0 :     uno::Reference< awt::XPopupMenu > xPopupMenu( m_xContext->getServiceManager()->createInstanceWithContext(
    1438           0 :                 "com.sun.star.awt.PopupMenu", m_xContext ), uno::UNO_QUERY );
    1439             : 
    1440           0 :     if ( xPopupController.is() && xPopupMenu.is() )
    1441             :     {
    1442           0 :         xPopupController->setPopupMenu( xPopupMenu );
    1443             : 
    1444           0 :         rBox.SetItemDown( nItemId, true );
    1445           0 :         Reference< awt::XWindowPeer > xPeer( getParent(), uno::UNO_QUERY );
    1446             : 
    1447           0 :         if ( xPeer.is() )
    1448           0 :             xPopupMenu->execute( xPeer, VCLUnoHelper::ConvertToAWTRect( aRect ), 0 );
    1449             : 
    1450           0 :         rBox.SetItemDown( nItemId, false );
    1451             :     }
    1452             : 
    1453           0 :     return 0;
    1454             : }
    1455             : 
    1456             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10