LCOV - code coverage report
Current view: top level - libreoffice/sfx2/source/toolbox - tbxitem.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 254 799 31.8 %
Date: 2012-12-17 Functions: 28 93 30.1 %
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>           // prevent conflict with STL includes
      26             : #include <com/sun/star/uno/Reference.h>
      27             : #include <com/sun/star/frame/XFrame.hpp>
      28             : #include <com/sun/star/awt/XWindow.hpp>
      29             : #include <com/sun/star/util/URL.hpp>
      30             : #include <com/sun/star/util/URLTransformer.hpp>
      31             : #include <com/sun/star/util/XURLTransformer.hpp>
      32             : #include <com/sun/star/frame/XController.hpp>
      33             : #include <com/sun/star/lang/XUnoTunnel.hpp>
      34             : #include <com/sun/star/document/MacroExecMode.hpp>
      35             : #include <com/sun/star/document/UpdateDocMode.hpp>
      36             : #include <com/sun/star/frame/XComponentLoader.hpp>
      37             : #include <com/sun/star/beans/PropertyValue.hpp>
      38             : #include <com/sun/star/beans/XPropertySet.hpp>
      39             : #include <com/sun/star/frame/XLayoutManager.hpp>
      40             : #include <com/sun/star/frame/status/ItemStatus.hpp>
      41             : #include <com/sun/star/frame/status/ItemState.hpp>
      42             : #include <com/sun/star/ui/XUIElementFactory.hpp>
      43             : #include <com/sun/star/frame/XModuleManager.hpp>
      44             : #include <com/sun/star/container/XNameAccess.hpp>
      45             : #include <com/sun/star/ui/XUIFunctionListener.hpp>
      46             : #include <com/sun/star/ui/UIElementFactoryManager.hpp>
      47             : #include <com/sun/star/frame/status/Visibility.hpp>
      48             : #include <svl/eitem.hxx>
      49             : #include <svl/stritem.hxx>
      50             : #include <svl/intitem.hxx>
      51             : #include <svl/imageitm.hxx>
      52             : #include <svl/visitem.hxx>
      53             : #include <svl/urlbmk.hxx>
      54             : #include <vcl/toolbox.hxx>
      55             : #include <unotools/moduleoptions.hxx>
      56             : 
      57             : #include <svtools/imagemgr.hxx>
      58             : #include <comphelper/processfactory.hxx>
      59             : #include <framework/addonmenu.hxx>
      60             : #include <framework/addonsoptions.hxx>
      61             : #include <framework/menuconfiguration.hxx>
      62             : #include <framework/sfxhelperfunctions.hxx>
      63             : #include <vcl/taskpanelist.hxx>
      64             : #include <toolkit/helper/vclunohelper.hxx>
      65             : #include <svtools/menuoptions.hxx>
      66             : #include <svtools/miscopt.hxx>
      67             : 
      68             : #include <sfx2/tbxctrl.hxx>
      69             : #include <sfx2/mnumgr.hxx>
      70             : #include <sfx2/dispatch.hxx>
      71             : #include "fltfnc.hxx"
      72             : #include <sfx2/msg.hxx>
      73             : #include <sfx2/msgpool.hxx>
      74             : #include "statcach.hxx"
      75             : #include <sfx2/viewfrm.hxx>
      76             : #include "arrdecl.hxx"
      77             : #include "sfxtypes.hxx"
      78             : #include <sfx2/genlink.hxx>
      79             : #include "sfx2/sfxresid.hxx"
      80             : #include <sfx2/sfx.hrc>
      81             : #include <sfx2/module.hxx>
      82             : #include <sfx2/docfile.hxx>
      83             : #include <sfx2/docfac.hxx>
      84             : #include "referers.hxx"
      85             : #include <sfx2/frmhtmlw.hxx>
      86             : #include <sfx2/app.hxx>
      87             : #include <sfx2/unoctitm.hxx>
      88             : #include "helpid.hrc"
      89             : #include "workwin.hxx"
      90             : #include "sfx2/imgmgr.hxx"
      91             : #include "virtmenu.hxx"
      92             : #include "sfx2/imagemgr.hxx"
      93             : 
      94             : using namespace ::com::sun::star::beans;
      95             : using namespace ::com::sun::star::frame;
      96             : using namespace ::com::sun::star::frame::status;
      97             : using namespace ::com::sun::star::lang;
      98             : using namespace ::com::sun::star::uno;
      99             : using namespace ::com::sun::star::util;
     100             : using namespace ::com::sun::star::container;
     101             : using namespace ::com::sun::star::frame;
     102             : using namespace ::com::sun::star::ui;
     103             : 
     104             : //====================================================================
     105             : 
     106          72 : SFX_IMPL_TOOLBOX_CONTROL_ARG(SfxToolBoxControl, SfxStringItem, sal_True);
     107         146 : SFX_IMPL_TOOLBOX_CONTROL(SfxAppToolBoxControl_Impl, SfxStringItem);
     108             : 
     109           0 : static Window* GetTopMostParentSystemWindow( Window* pWindow )
     110             : {
     111             :     OSL_ASSERT( pWindow );
     112           0 :     if ( pWindow )
     113             :     {
     114             :         // ->manually search topmost system window
     115             :         // required because their might be another system window between this and the top window
     116           0 :         pWindow = pWindow->GetParent();
     117           0 :         SystemWindow* pTopMostSysWin = NULL;
     118           0 :         while ( pWindow )
     119             :         {
     120           0 :             if ( pWindow->IsSystemWindow() )
     121           0 :                 pTopMostSysWin = (SystemWindow*)pWindow;
     122           0 :             pWindow = pWindow->GetParent();
     123             :         }
     124           0 :         pWindow = pTopMostSysWin;
     125             :         OSL_ASSERT( pWindow );
     126           0 :         return pWindow;
     127             :     }
     128             : 
     129           0 :     return NULL;
     130             : }
     131             : 
     132         116 : svt::ToolboxController* SAL_CALL SfxToolBoxControllerFactory( const Reference< XFrame >& rFrame, ToolBox* pToolbox, unsigned short nID, const ::rtl::OUString& aCommandURL )
     133             : {
     134         116 :     SolarMutexGuard aGuard;
     135             : 
     136         116 :     URL aTargetURL;
     137         116 :     aTargetURL.Complete = aCommandURL;
     138         116 :     Reference < XURLTransformer > xTrans( URLTransformer::create( ::comphelper::getProcessComponentContext() ) );
     139         116 :     xTrans->parseStrict( aTargetURL );
     140         116 :     if ( !aTargetURL.Arguments.isEmpty() )
     141           0 :         return NULL;
     142             : 
     143         116 :     SfxObjectShell* pObjShell = NULL;
     144         116 :     Reference < XController > xController;
     145         116 :     Reference < XModel > xModel;
     146         116 :     if ( rFrame.is() )
     147             :     {
     148         116 :         xController = rFrame->getController();
     149         116 :         if ( xController.is() )
     150         116 :             xModel = xController->getModel();
     151             :     }
     152             : 
     153         116 :     if ( xModel.is() )
     154             :     {
     155             :         // Get tunnel from model to retrieve the SfxObjectShell pointer from it
     156         116 :         ::com::sun::star::uno::Reference < ::com::sun::star::lang::XUnoTunnel > xObj( xModel, UNO_QUERY );
     157         116 :         if ( xObj.is() )
     158             :         {
     159         116 :             ::com::sun::star::uno::Sequence < sal_Int8 > aSeq = SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence();
     160         116 :             sal_Int64 nHandle = xObj->getSomething( aSeq );
     161         116 :             if ( nHandle )
     162         116 :                 pObjShell = reinterpret_cast< SfxObjectShell* >( sal::static_int_cast< sal_IntPtr >( nHandle ));
     163         116 :         }
     164             :     }
     165             : 
     166         116 :     SfxModule*     pModule   = pObjShell ? pObjShell->GetModule() : NULL;
     167         116 :     SfxSlotPool*   pSlotPool = 0;
     168             : 
     169         116 :     if ( pModule )
     170         116 :         pSlotPool = pModule->GetSlotPool();
     171             :     else
     172           0 :         pSlotPool = &(SfxSlotPool::GetSlotPool( NULL ));
     173             : 
     174         116 :     const SfxSlot* pSlot = pSlotPool->GetUnoSlot( aTargetURL.Path );
     175         116 :     if ( pSlot )
     176             :     {
     177         116 :         sal_uInt16 nSlotId = pSlot->GetSlotId();
     178         116 :         if ( nSlotId > 0 )
     179         116 :             return SfxToolBoxControl::CreateControl( nSlotId, nID, pToolbox, pModule );
     180             :     }
     181             : 
     182           0 :     return NULL;
     183             : }
     184             : 
     185          56 : struct SfxToolBoxControl_Impl
     186             : {
     187             :     ToolBox*                pBox;
     188             :     sal_Bool                    bShowString;
     189             :     sal_uInt16                  nSelectModifier;
     190             :     SfxTbxCtrlFactory*      pFact;
     191             :     sal_uInt16                  nTbxId;
     192             :     sal_uInt16                  nSlotId;
     193             :     SfxPopupWindow*         mpFloatingWindow;
     194             :     SfxPopupWindow*         mpPopupWindow;
     195             :     Reference< XUIElement > mxUIElement;
     196             : 
     197             :     DECL_LINK( WindowEventListener, VclSimpleEvent* );
     198             : };
     199             : 
     200           0 : IMPL_LINK( SfxToolBoxControl_Impl, WindowEventListener, VclSimpleEvent*, pEvent )
     201             : {
     202           0 :     if ( pEvent &&
     203           0 :          pEvent->ISA( VclWindowEvent ) &&
     204           0 :          (( pEvent->GetId() == VCLEVENT_WINDOW_MOVE ) ||
     205           0 :           ( pEvent->GetId() == VCLEVENT_WINDOW_ACTIVATE )))
     206             :     {
     207           0 :         Window* pWindow( ((VclWindowEvent*)pEvent)->GetWindow() );
     208           0 :         if (( pWindow == mpFloatingWindow ) &&
     209             :             ( mpPopupWindow != 0 ))
     210             :         {
     211           0 :             delete mpPopupWindow;
     212           0 :             mpPopupWindow = 0;
     213             :         }
     214             :     }
     215             : 
     216           0 :     return 1;
     217             : }
     218             : 
     219             : //--------------------------------------------------------------------
     220             : 
     221          28 : SfxToolBoxControl::SfxToolBoxControl(
     222             :     sal_uInt16          nSlotID,
     223             :     sal_uInt16          nID,
     224             :     ToolBox&        rBox,
     225             :     sal_Bool            bShowStringItems     )
     226          28 : :   svt::ToolboxController()
     227             : {
     228          28 :     pImpl = new SfxToolBoxControl_Impl;
     229             : 
     230          28 :     pImpl->pBox = &rBox;
     231          28 :     pImpl->bShowString = bShowStringItems;
     232          28 :     pImpl->nSelectModifier = 0;
     233          28 :     pImpl->pFact = 0;
     234          28 :     pImpl->nTbxId = nID;
     235          28 :     pImpl->nSlotId = nSlotID;
     236          28 :     pImpl->mpFloatingWindow = 0;
     237          28 :     pImpl->mpPopupWindow = 0;
     238          28 : }
     239             : 
     240             : //--------------------------------------------------------------------
     241             : 
     242          56 : SfxToolBoxControl::~SfxToolBoxControl()
     243             : {
     244          28 :     if ( pImpl->mxUIElement.is() )
     245             :     {
     246           0 :         Reference< XComponent > xComponent( pImpl->mxUIElement, UNO_QUERY );
     247           0 :         xComponent->dispose();
     248             :     }
     249          28 :     pImpl->mxUIElement = 0;
     250          28 :     delete pImpl;
     251          28 : }
     252             : 
     253             : //--------------------------------------------------------------------
     254             : 
     255         170 : ToolBox& SfxToolBoxControl::GetToolBox() const
     256             : {
     257         170 :     return *pImpl->pBox;
     258             : }
     259         235 : unsigned short SfxToolBoxControl::GetId() const
     260             : {
     261         235 :     return pImpl->nTbxId;
     262             : }
     263           0 : unsigned short SfxToolBoxControl::GetSlotId() const
     264             : {
     265           0 :     return pImpl->nSlotId;
     266             : }
     267             : 
     268             : //--------------------------------------------------------------------
     269             : 
     270          28 : void SAL_CALL SfxToolBoxControl::dispose() throw (::com::sun::star::uno::RuntimeException)
     271             : {
     272          28 :     if ( m_bDisposed )
     273          28 :         return;
     274             : 
     275          28 :     svt::ToolboxController::dispose();
     276             : 
     277             :     // Remove and destroy our item window at our toolbox
     278          28 :     SolarMutexGuard aGuard;
     279          28 :     Window* pWindow = pImpl->pBox->GetItemWindow( pImpl->nTbxId );
     280          28 :     pImpl->pBox->SetItemWindow( pImpl->nTbxId, 0 );
     281          28 :     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          28 :     if ( pImpl->mxUIElement.is() )
     289             :     {
     290           0 :         Reference< XComponent > xComponent( pImpl->mxUIElement, UNO_QUERY );
     291           0 :         xComponent->dispose();
     292             :     }
     293          28 :     pImpl->mxUIElement = 0;
     294             : 
     295             :     // Delete my popup windows
     296          28 :     delete pImpl->mpFloatingWindow;
     297          28 :     delete pImpl->mpPopupWindow;
     298             : 
     299          28 :     pImpl->mpFloatingWindow = 0;
     300          28 :     pImpl->mpPopupWindow = 0;
     301             : }
     302             : 
     303             : //--------------------------------------------------------------------
     304        3998 : void SfxToolBoxControl::RegisterToolBoxControl( SfxModule* pMod, SfxTbxCtrlFactory* pFact)
     305             : {
     306        3998 :     SFX_APP()->RegisterToolBoxControl_Impl( pMod, pFact );
     307        3998 : }
     308             : 
     309         116 : SfxToolBoxControl* SfxToolBoxControl::CreateControl( sal_uInt16 nSlotId, sal_uInt16 nTbxId, ToolBox *pBox, SfxModule* pMod  )
     310             : {
     311         116 :     SolarMutexGuard aGuard;
     312             : 
     313             :     SfxToolBoxControl *pCtrl;
     314         116 :     SfxApplication *pApp = SFX_APP();
     315             : 
     316             :     SfxSlotPool *pSlotPool;
     317         116 :     if ( pMod )
     318         116 :         pSlotPool = pMod->GetSlotPool();
     319             :     else
     320           0 :         pSlotPool = &SfxSlotPool::GetSlotPool();
     321         116 :     TypeId aSlotType = pSlotPool->GetSlotType( nSlotId );
     322         116 :     if ( aSlotType )
     323             :     {
     324         116 :         if ( pMod )
     325             :         {
     326         116 :             SfxTbxCtrlFactArr_Impl *pFactories = pMod->GetTbxCtrlFactories_Impl();
     327         116 :             if ( pFactories )
     328             :             {
     329         116 :                 SfxTbxCtrlFactArr_Impl &rFactories = *pFactories;
     330             :                 sal_uInt16 nFactory;
     331         116 :                 const sal_uInt16 nCount = rFactories.size();
     332             : 
     333             :                 // search for a factory with the given slot id
     334        5842 :                 for( nFactory = 0; nFactory < nCount; ++nFactory )
     335        5752 :                     if( (rFactories[nFactory]->nTypeId == aSlotType) && (rFactories[nFactory]->nSlotId == nSlotId) )
     336          26 :                         break;
     337             : 
     338         116 :                 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        5130 :                     for ( nFactory = 0; nFactory < nCount; ++nFactory )
     343        5040 :                         if( (rFactories[nFactory]->nTypeId == aSlotType) && (rFactories[nFactory]->nSlotId == 0) )
     344           0 :                             break;
     345             :                 }
     346             : 
     347         116 :                 if( nFactory < nCount )
     348             :                 {
     349          26 :                     pCtrl = rFactories[nFactory]->pCtor( nSlotId, nTbxId, *pBox );
     350          26 :                     pCtrl->pImpl->pFact = rFactories[nFactory];
     351          26 :                     return pCtrl;
     352             :                 }
     353             :             }
     354             :         }
     355             : 
     356          90 :         SfxTbxCtrlFactArr_Impl &rFactories = pApp->GetTbxCtrlFactories_Impl();
     357             :         sal_uInt16 nFactory;
     358          90 :         const sal_uInt16 nCount = rFactories.size();
     359             : 
     360        1062 :         for( nFactory = 0; nFactory < nCount; ++nFactory )
     361         974 :             if( (rFactories[nFactory]->nTypeId == aSlotType) && (rFactories[nFactory]->nSlotId == nSlotId) )
     362           2 :                 break;
     363             : 
     364          90 :         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        1056 :             for( nFactory = 0; nFactory < nCount; ++nFactory )
     369         968 :                 if( (rFactories[nFactory]->nTypeId == aSlotType) && (rFactories[nFactory]->nSlotId == 0) )
     370           0 :                     break;
     371             :         }
     372             : 
     373          90 :         if( nFactory < nCount )
     374             :         {
     375           2 :             pCtrl = rFactories[nFactory]->pCtor( nSlotId, nTbxId, *pBox );
     376           2 :             pCtrl->pImpl->pFact = rFactories[nFactory];
     377           2 :             return pCtrl;
     378             :         }
     379             :     }
     380             : 
     381          88 :     return NULL;
     382             : }
     383             : 
     384          17 : 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           1 :                 : IsInvalidItem(pState)
     417             :                     ? SFX_ITEM_DONTCARE
     418           1 :                     : pState->ISA(SfxVoidItem) && !pState->Which()
     419             :                         ? SFX_ITEM_UNKNOWN
     420          19 :                         : SFX_ITEM_AVAILABLE;
     421             : }
     422             : 
     423           0 : void SfxToolBoxControl::Dispatch(
     424             :     const Reference< XDispatchProvider >& rProvider,
     425             :     const rtl::OUString& rCommand,
     426             :     Sequence< ::PropertyValue >& aArgs )
     427             : {
     428           0 :     if ( rProvider.is() )
     429             :     {
     430           0 :         ::com::sun::star::util::URL aTargetURL;
     431           0 :         aTargetURL.Complete = rCommand;
     432           0 :         Reference < XURLTransformer > xTrans( URLTransformer::create( ::comphelper::getProcessComponentContext() ) );
     433           0 :         xTrans->parseStrict( aTargetURL );
     434             : 
     435           0 :         Reference < XDispatch > xDispatch = rProvider->queryDispatch( aTargetURL, ::rtl::OUString(), 0 );
     436           0 :         if ( xDispatch.is() )
     437           0 :             xDispatch->dispatch( aTargetURL, aArgs );
     438             :     }
     439           0 : }
     440             : 
     441           0 : void SfxToolBoxControl::Dispatch( const ::rtl::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, ::rtl::OUString(), 0 );
     457           0 :         if ( xDispatch.is() )
     458           0 :             xDispatch->dispatch( aTargetURL, aArgs );
     459           0 :     }
     460           0 : }
     461             : 
     462             : // XInterface
     463         294 : Any SAL_CALL SfxToolBoxControl::queryInterface( const Type & rType )
     464             : throw(::com::sun::star::uno::RuntimeException)
     465             : {
     466             :     ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType,
     467             :                                            (static_cast< ::com::sun::star::awt::XDockableWindowListener* >(this)),
     468         294 :                                         (static_cast< ::com::sun::star::frame::XSubToolbarController* >(this)));
     469         294 :     return (aRet.hasValue() ? aRet : svt::ToolboxController::queryInterface( rType ));
     470             : }
     471             : 
     472         881 : void SAL_CALL SfxToolBoxControl::acquire() throw()
     473             : {
     474         881 :     OWeakObject::acquire();
     475         881 : }
     476             : 
     477         881 : void SAL_CALL SfxToolBoxControl::release() throw()
     478             : {
     479         881 :     OWeakObject::release();
     480         881 : }
     481             : 
     482           0 : void SAL_CALL SfxToolBoxControl::disposing( const ::com::sun::star::lang::EventObject& aEvent )
     483             : throw( ::com::sun::star::uno::RuntimeException )
     484             : {
     485           0 :     svt::ToolboxController::disposing( aEvent );
     486           0 : }
     487             : 
     488             : // XStatusListener
     489          89 : void SAL_CALL SfxToolBoxControl::statusChanged( const FeatureStateEvent& rEvent )
     490             : throw ( ::com::sun::star::uno::RuntimeException )
     491             : {
     492          89 :     SfxViewFrame* pViewFrame = NULL;
     493          89 :     Reference < XController > xController;
     494             : 
     495          89 :     SolarMutexGuard aGuard;
     496          89 :     if ( getFrameInterface().is() )
     497          89 :         xController = getFrameInterface()->getController();
     498             : 
     499          89 :     Reference < XDispatchProvider > xProvider( xController, UNO_QUERY );
     500          89 :     if ( xProvider.is() )
     501             :     {
     502          89 :         Reference < XDispatch > xDisp = xProvider->queryDispatch( rEvent.FeatureURL, ::rtl::OUString(), 0 );
     503          89 :         if ( xDisp.is() )
     504             :         {
     505          89 :             Reference< XUnoTunnel > xTunnel( xDisp, UNO_QUERY );
     506          89 :             SfxOfficeDispatch* pDisp = NULL;
     507          89 :             if ( xTunnel.is() )
     508             :             {
     509          89 :                 sal_Int64 nImplementation = xTunnel->getSomething(SfxOfficeDispatch::impl_getStaticIdentifier());
     510          89 :                 pDisp = reinterpret_cast< SfxOfficeDispatch* >( sal::static_int_cast< sal_IntPtr >( nImplementation ));
     511             :             }
     512             : 
     513          89 :             if ( pDisp )
     514          89 :                 pViewFrame = pDisp->GetDispatcher_Impl()->GetFrame();
     515          89 :         }
     516             :     }
     517             : 
     518          89 :     sal_uInt16 nSlotId = 0;
     519          89 :     SfxSlotPool& rPool = SfxSlotPool::GetSlotPool( pViewFrame );
     520          89 :     const SfxSlot* pSlot = rPool.GetUnoSlot( rEvent.FeatureURL.Path );
     521          89 :     if ( pSlot )
     522          89 :         nSlotId = pSlot->GetSlotId();
     523           0 :     else if ( m_aCommandURL == rEvent.FeatureURL.Path )
     524           0 :         nSlotId = GetSlotId();
     525             : 
     526          89 :     if ( nSlotId > 0 )
     527             :     {
     528          89 :         if ( rEvent.Requery )
     529           0 :             svt::ToolboxController::statusChanged( rEvent );
     530             :         else
     531             :         {
     532          89 :             SfxItemState eState = SFX_ITEM_DISABLED;
     533          89 :             SfxPoolItem* pItem = NULL;
     534          89 :             if ( rEvent.IsEnabled )
     535             :             {
     536          65 :                 eState = SFX_ITEM_AVAILABLE;
     537          65 :                 ::com::sun::star::uno::Type pType = rEvent.State.getValueType();
     538             : 
     539          65 :                 if ( pType == ::getVoidCppuType() )
     540             :                 {
     541          16 :                     pItem = new SfxVoidItem( nSlotId );
     542          16 :                     eState = SFX_ITEM_UNKNOWN;
     543             :                 }
     544          49 :                 else if ( pType == ::getBooleanCppuType() )
     545             :                 {
     546          16 :                     sal_Bool bTemp = false;
     547          16 :                     rEvent.State >>= bTemp ;
     548          16 :                     pItem = new SfxBoolItem( nSlotId, bTemp );
     549             :                 }
     550          33 :                 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          33 :                 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          33 :                 else if ( pType == ::getCppuType((const ::rtl::OUString*)0) )
     563             :                 {
     564           5 :                     ::rtl::OUString sTemp ;
     565           5 :                     rEvent.State >>= sTemp ;
     566           5 :                     pItem = new SfxStringItem( nSlotId, sTemp );
     567             :                 }
     568          28 :                 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          28 :                 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          28 :                     if ( pSlot )
     584          28 :                         pItem = pSlot->GetType()->CreateItem();
     585          28 :                     if ( pItem )
     586             :                     {
     587          28 :                         pItem->SetWhich( nSlotId );
     588          28 :                         pItem->PutValue( rEvent.State );
     589             :                     }
     590             :                     else
     591           0 :                         pItem = new SfxVoidItem( nSlotId );
     592          65 :                 }
     593             :             }
     594             : 
     595          89 :             StateChanged( nSlotId, eState, pItem );
     596          89 :             delete pItem;
     597             :         }
     598          89 :     }
     599          89 : }
     600             : 
     601             : // XSubToolbarController
     602          28 : ::sal_Bool SAL_CALL SfxToolBoxControl::opensSubToolbar() throw (::com::sun::star::uno::RuntimeException)
     603             : {
     604          28 :     return sal_False;
     605             : }
     606             : 
     607           0 : ::rtl::OUString SAL_CALL SfxToolBoxControl::getSubToolbarName() throw (::com::sun::star::uno::RuntimeException)
     608             : {
     609           0 :     return rtl::OUString();
     610             : }
     611             : 
     612           0 : void SAL_CALL SfxToolBoxControl::functionSelected( const ::rtl::OUString& /*aCommand*/ ) throw (::com::sun::star::uno::RuntimeException)
     613             : {
     614             :     // must be implemented by sub-class
     615           0 : }
     616             : 
     617           0 : void SAL_CALL SfxToolBoxControl::updateImage() throw (::com::sun::star::uno::RuntimeException)
     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)
     624             : {
     625           0 :     SolarMutexGuard aGuard;
     626           0 :     Select( (sal_uInt16)KeyModifier );
     627           0 : }
     628           0 : void SAL_CALL SfxToolBoxControl::click() throw (::com::sun::star::uno::RuntimeException)
     629             : {
     630           0 :     SolarMutexGuard aGuard;
     631           0 :     Click();
     632           0 : }
     633             : 
     634           0 : void SAL_CALL SfxToolBoxControl::doubleClick() throw (::com::sun::star::uno::RuntimeException)
     635             : {
     636           0 :     SolarMutexGuard aGuard;
     637           0 :     DoubleClick();
     638           0 : }
     639             : 
     640           0 : Reference< ::com::sun::star::awt::XWindow > SAL_CALL SfxToolBoxControl::createPopupWindow() throw (::com::sun::star::uno::RuntimeException)
     641             : {
     642           0 :     SolarMutexGuard aGuard;
     643           0 :     Window* pWindow = CreatePopupWindow();
     644           0 :     if ( pWindow )
     645           0 :         return VCLUnoHelper::GetInterface( pWindow );
     646             :     else
     647           0 :         return Reference< ::com::sun::star::awt::XWindow >();
     648             : }
     649             : 
     650          28 : Reference< ::com::sun::star::awt::XWindow > SAL_CALL SfxToolBoxControl::createItemWindow( const Reference< ::com::sun::star::awt::XWindow >& rParent ) throw (::com::sun::star::uno::RuntimeException)
     651             : {
     652          28 :     SolarMutexGuard aGuard;
     653          28 :     return VCLUnoHelper::GetInterface( CreateItemWindow( VCLUnoHelper::GetWindow( rParent )));
     654             : }
     655             : 
     656             : // XDockableWindowListener
     657           0 : void SAL_CALL SfxToolBoxControl::startDocking( const ::com::sun::star::awt::DockingEvent& )
     658             : throw (::com::sun::star::uno::RuntimeException)
     659             : {
     660           0 : }
     661           0 : ::com::sun::star::awt::DockingData SAL_CALL SfxToolBoxControl::docking( const ::com::sun::star::awt::DockingEvent& )
     662             : throw (::com::sun::star::uno::RuntimeException)
     663             : {
     664           0 :     return ::com::sun::star::awt::DockingData();
     665             : }
     666             : 
     667           0 : void SAL_CALL SfxToolBoxControl::endDocking( const ::com::sun::star::awt::EndDockingEvent& )
     668             : throw (::com::sun::star::uno::RuntimeException)
     669             : {
     670           0 : }
     671             : 
     672           0 : sal_Bool SAL_CALL SfxToolBoxControl::prepareToggleFloatingMode( const ::com::sun::star::lang::EventObject& )
     673             : throw (::com::sun::star::uno::RuntimeException)
     674             : {
     675           0 :     return sal_False;
     676             : }
     677             : 
     678           0 : void SAL_CALL SfxToolBoxControl::toggleFloatingMode( const ::com::sun::star::lang::EventObject& )
     679             : throw (::com::sun::star::uno::RuntimeException)
     680             : {
     681           0 : }
     682             : 
     683           0 : void SAL_CALL SfxToolBoxControl::closed( const ::com::sun::star::lang::EventObject& )
     684             : throw (::com::sun::star::uno::RuntimeException)
     685             : {
     686           0 : }
     687             : 
     688           0 : void SAL_CALL SfxToolBoxControl::endPopupMode( const ::com::sun::star::awt::EndPopupModeEvent& aEvent )
     689             : throw (::com::sun::star::uno::RuntimeException)
     690             : {
     691           0 :     SolarMutexGuard aGuard;
     692             : 
     693           0 :     ::rtl::OUString aSubToolBarResName;
     694           0 :     if ( pImpl->mxUIElement.is() )
     695             :     {
     696           0 :         Reference< XPropertySet > xPropSet( pImpl->mxUIElement, UNO_QUERY );
     697           0 :         if ( xPropSet.is() )
     698             :         {
     699             :             try
     700             :             {
     701           0 :                 xPropSet->getPropertyValue( ::rtl::OUString( "ResourceURL" )) >>= aSubToolBarResName;
     702             :             }
     703           0 :             catch ( com::sun::star::beans::UnknownPropertyException& )
     704             :             {
     705             :             }
     706           0 :             catch ( com::sun::star::lang::WrappedTargetException& )
     707             :             {
     708             :             }
     709             :         }
     710             : 
     711           0 :         Reference< XComponent > xComponent( pImpl->mxUIElement, UNO_QUERY );
     712           0 :         xComponent->dispose();
     713             :     }
     714           0 :     pImpl->mxUIElement = 0;
     715             : 
     716             :     // if the toolbar was teared-off recreate it and place it at the given position
     717           0 :     if( aEvent.bTearoff )
     718             :     {
     719           0 :         Reference< XUIElement >     xUIElement;
     720           0 :         Reference< XLayoutManager > xLayoutManager = getLayoutManager();
     721             : 
     722           0 :         if ( !xLayoutManager.is() )
     723           0 :             return;
     724             : 
     725           0 :         xLayoutManager->createElement( aSubToolBarResName );
     726           0 :         xUIElement = xLayoutManager->getElement( aSubToolBarResName );
     727           0 :         if ( xUIElement.is() )
     728             :         {
     729           0 :             Reference< ::com::sun::star::awt::XWindow > xParent = getFrameInterface()->getContainerWindow();
     730             : 
     731           0 :             Reference< ::com::sun::star::awt::XWindow > xSubToolBar( xUIElement->getRealInterface(), UNO_QUERY );
     732           0 :             Reference< ::com::sun::star::beans::XPropertySet > xProp( xUIElement, UNO_QUERY );
     733           0 :             if ( xSubToolBar.is() && xProp.is() )
     734             :             {
     735           0 :                 rtl::OUString aPersistentString( "Persistent" );
     736             :                 try
     737             :                 {
     738           0 :                     Window*  pTbxWindow = VCLUnoHelper::GetWindow( xSubToolBar );
     739           0 :                     if ( pTbxWindow && pTbxWindow->GetType() == WINDOW_TOOLBOX )
     740             :                     {
     741           0 :                         Any a;
     742           0 :                         a = xProp->getPropertyValue( aPersistentString );
     743           0 :                         xProp->setPropertyValue( aPersistentString, makeAny( sal_False ));
     744             : 
     745           0 :                         xLayoutManager->hideElement( aSubToolBarResName );
     746           0 :                         xLayoutManager->floatWindow( aSubToolBarResName );
     747             : 
     748           0 :                         xLayoutManager->setElementPos( aSubToolBarResName, aEvent.FloatingPosition );
     749           0 :                         xLayoutManager->showElement( aSubToolBarResName );
     750             : 
     751           0 :                         xProp->setPropertyValue( rtl::OUString( "Persistent" ), a );
     752             :                     }
     753             :                 }
     754           0 :                 catch ( ::com::sun::star::uno::RuntimeException& )
     755             :                 {
     756           0 :                     throw;
     757             :                 }
     758           0 :                 catch ( ::com::sun::star::uno::Exception& )
     759             :                 {
     760           0 :                 }
     761           0 :             }
     762           0 :         }
     763           0 :     }
     764             : }
     765             : 
     766           0 : ::Size  SfxToolBoxControl::getPersistentFloatingSize( const Reference< XFrame >& /*xFrame*/, const ::rtl::OUString& /*rSubToolBarResName*/ )
     767             : {
     768           0 :     ::Size  aToolboxSize;
     769           0 :     return aToolboxSize;
     770             : }
     771             : 
     772           0 : void SfxToolBoxControl::createAndPositionSubToolBar( const ::rtl::OUString& rSubToolBarResName )
     773             : {
     774           0 :     SolarMutexGuard aGuard;
     775             : 
     776           0 :     if ( pImpl->pBox )
     777             :     {
     778           0 :         static WeakReference< XUIElementFactoryManager > xWeakUIElementFactory;
     779             : 
     780           0 :         sal_uInt16 nItemId = pImpl->pBox->GetDownItemId();
     781             : 
     782           0 :         if ( !nItemId )
     783           0 :             return;
     784             : 
     785             :         // create element with factory
     786           0 :         Reference< XMultiServiceFactory >   xServiceManager = getServiceManager();
     787           0 :         Reference< XFrame >                 xFrame          = getFrameInterface();
     788           0 :         Reference< XUIElement >             xUIElement;
     789           0 :         Reference< XUIElementFactoryManager >  xUIElementFactory;
     790             : 
     791           0 :         xUIElementFactory = xWeakUIElementFactory;
     792           0 :         if ( !xUIElementFactory.is() )
     793             :         {
     794           0 :             xUIElementFactory = UIElementFactoryManager::create( comphelper::getComponentContext(xServiceManager) );
     795           0 :             xWeakUIElementFactory = xUIElementFactory;
     796             :         }
     797             : 
     798           0 :         Sequence< PropertyValue > aPropSeq( 3 );
     799           0 :         aPropSeq[0].Name = rtl::OUString( "Frame" );
     800           0 :         aPropSeq[0].Value <<= xFrame;
     801           0 :         aPropSeq[1].Name = rtl::OUString( "Persistent" );
     802           0 :         aPropSeq[1].Value <<= sal_False;
     803           0 :         aPropSeq[2].Name = rtl::OUString( "PopupMode" );
     804           0 :         aPropSeq[2].Value <<= sal_True;
     805             : 
     806             :         try
     807             :         {
     808           0 :             xUIElement = xUIElementFactory->createUIElement( rSubToolBarResName, aPropSeq );
     809             :         }
     810           0 :         catch ( ::com::sun::star::container::NoSuchElementException& )
     811             :         {
     812             :         }
     813           0 :         catch ( IllegalArgumentException& )
     814             :         {
     815             :         }
     816             : 
     817           0 :         if ( xUIElement.is() )
     818             :         {
     819           0 :             Reference< ::com::sun::star::awt::XWindow > xParent = getFrameInterface()->getContainerWindow();
     820             : 
     821           0 :             Reference< ::com::sun::star::awt::XWindow > xSubToolBar( xUIElement->getRealInterface(), UNO_QUERY );
     822           0 :             if ( xSubToolBar.is() )
     823             :             {
     824           0 :                 Reference< ::com::sun::star::awt::XDockableWindow > xDockWindow( xSubToolBar, UNO_QUERY );
     825           0 :                 xDockWindow->addDockableWindowListener( Reference< ::com::sun::star::awt::XDockableWindowListener >(
     826           0 :                     static_cast< OWeakObject * >( this ), UNO_QUERY ));
     827           0 :                 xDockWindow->enableDocking( sal_True );
     828             : 
     829             :                 // keep refererence to UIElement to avoid its destruction
     830           0 :                 if ( pImpl->mxUIElement.is() )
     831             :                 {
     832           0 :                     Reference< XComponent > xComponent( pImpl->mxUIElement, UNO_QUERY );
     833           0 :                     xComponent->dispose();
     834             :                 }
     835           0 :                 pImpl->mxUIElement = xUIElement;
     836             : 
     837           0 :                 Window*  pParentTbxWindow( pImpl->pBox );
     838           0 :                 Window*  pTbxWindow = VCLUnoHelper::GetWindow( xSubToolBar );
     839           0 :                 ToolBox* pToolBar( 0 );
     840           0 :                 if ( pTbxWindow && pTbxWindow->GetType() == WINDOW_TOOLBOX )
     841           0 :                     pToolBar = (ToolBox *)pTbxWindow;
     842             : 
     843           0 :                 if ( pToolBar )
     844             :                 {
     845           0 :                     pToolBar->SetParent( pParentTbxWindow );
     846           0 :                     ::Size aSize = getPersistentFloatingSize( xFrame, rSubToolBarResName );
     847           0 :                     if ( aSize.Width() == 0 || aSize.Height() == 0 )
     848             :                     {
     849             :                         // calc and set size for popup mode
     850           0 :                         aSize = pToolBar->CalcPopupWindowSizePixel();
     851             :                     }
     852           0 :                     pToolBar->SetSizePixel( aSize );
     853             : 
     854             :                     // open subtoolbox in popup mode
     855           0 :                     Window::GetDockingManager()->StartPopupMode( pImpl->pBox, pToolBar );
     856           0 :                 }
     857           0 :             }
     858           0 :         }
     859           0 :     }
     860             : }
     861             : 
     862             : //--------------------------------------------------------------------
     863             : 
     864           0 : void SfxToolBoxControl::SetPopupWindow( SfxPopupWindow* pWindow )
     865             : {
     866           0 :     pImpl->mpPopupWindow = pWindow;
     867           0 :     pImpl->mpPopupWindow->SetPopupModeEndHdl( LINK( this, SfxToolBoxControl, PopupModeEndHdl ));
     868           0 :     pImpl->mpPopupWindow->SetDeleteLink_Impl( LINK( this, SfxToolBoxControl, ClosePopupWindow ));
     869           0 : }
     870             : 
     871             : //--------------------------------------------------------------------
     872             : 
     873           0 : IMPL_LINK_NOARG(SfxToolBoxControl, PopupModeEndHdl)
     874             : {
     875           0 :     if ( pImpl->mpPopupWindow->IsVisible() )
     876             :     {
     877             :         // Replace floating window with popup window and destroy
     878             :         // floating window instance.
     879           0 :         delete pImpl->mpFloatingWindow;
     880           0 :         pImpl->mpFloatingWindow = pImpl->mpPopupWindow;
     881           0 :         pImpl->mpPopupWindow    = 0;
     882             :         // We also need to know when the user tries to use the
     883             :         // floating window.
     884           0 :         pImpl->mpFloatingWindow->AddEventListener( LINK( pImpl, SfxToolBoxControl_Impl, WindowEventListener ));
     885             :     }
     886             :     else
     887             :     {
     888             :         // Popup window has been closed by the user. No replacement, instance
     889             :         // will destroy itself.
     890           0 :         pImpl->mpPopupWindow = 0;
     891             :     }
     892             : 
     893           0 :     return 1;
     894             : }
     895             : 
     896             : //--------------------------------------------------------------------
     897           0 : IMPL_LINK( SfxToolBoxControl, ClosePopupWindow, SfxPopupWindow *, pWindow )
     898             : {
     899           0 :     if ( pWindow == pImpl->mpFloatingWindow )
     900           0 :         pImpl->mpFloatingWindow = 0;
     901             :     else
     902           0 :         pImpl->mpPopupWindow = 0;
     903             : 
     904           0 :     return 1;
     905             : }
     906             : 
     907             : //--------------------------------------------------------------------
     908             : 
     909          19 : void SfxToolBoxControl::StateChanged
     910             : (
     911             :     sal_uInt16              nId,
     912             :     SfxItemState        eState,
     913             :     const SfxPoolItem*  pState
     914             : )
     915             : {
     916             :     DBG_ASSERT( pImpl->pBox != 0, "setting state to dangling ToolBox" );
     917             : 
     918          19 :     if ( GetId() >= SID_OBJECTMENU0 && GetId() <= SID_OBJECTMENU_LAST )
     919          19 :         return;
     920             : 
     921             :     // enabled/disabled-Flag correcting the lump sum
     922          19 :     pImpl->pBox->EnableItem( GetId(), eState != SFX_ITEM_DISABLED );
     923             : 
     924          19 :     sal_uInt16 nItemBits = pImpl->pBox->GetItemBits( GetId() );
     925          19 :     nItemBits &= ~TIB_CHECKABLE;
     926          19 :     TriState eTri = STATE_NOCHECK;
     927          19 :     switch ( eState )
     928             :     {
     929             :         case SFX_ITEM_AVAILABLE:
     930             :         {
     931           7 :             if ( pState->ISA(SfxBoolItem) )
     932             :             {
     933             :                 // BoolItem for checking
     934           4 :                 if ( ((const SfxBoolItem*)pState)->GetValue() )
     935           0 :                     eTri = STATE_CHECK;
     936           4 :                 nItemBits |= TIB_CHECKABLE;
     937             :             }
     938           6 :             else if ( pState->ISA(SfxEnumItemInterface) &&
     939           3 :                 ((SfxEnumItemInterface *)pState)->HasBoolValue())
     940             :             {
     941             :                 // EnumItem is handled as Bool
     942           0 :                 if ( ((const SfxEnumItemInterface *)pState)->GetBoolValue() )
     943           0 :                     eTri = STATE_CHECK;
     944           0 :                 nItemBits |= TIB_CHECKABLE;
     945             :             }
     946           3 :             else if ( pImpl->bShowString && pState->ISA(SfxStringItem) )
     947           0 :                 pImpl->pBox->SetItemText(nId, ((const SfxStringItem*)pState)->GetValue() );
     948           7 :             break;
     949             :         }
     950             : 
     951             :         case SFX_ITEM_DONTCARE:
     952             :         {
     953           0 :             eTri = STATE_DONTKNOW;
     954           0 :             nItemBits |= TIB_CHECKABLE;
     955             :         }
     956             :     }
     957             : 
     958          19 :     pImpl->pBox->SetItemState( GetId(), eTri );
     959          19 :     pImpl->pBox->SetItemBits( GetId(), nItemBits );
     960             : }
     961             : 
     962             : //--------------------------------------------------------------------
     963             : 
     964           0 : void SfxToolBoxControl::Select( sal_uInt16 nModifier )
     965             : {
     966           0 :     pImpl->nSelectModifier = nModifier;
     967           0 :     Select( sal_Bool((nModifier & KEY_MOD1)!=0) );
     968           0 : }
     969             : 
     970             : //--------------------------------------------------------------------
     971             : 
     972           0 : void SfxToolBoxControl::Select( sal_Bool /*bMod1*/ )
     973             : {
     974           0 :     svt::ToolboxController::execute( pImpl->nSelectModifier );
     975           0 : }
     976             : 
     977             : //--------------------------------------------------------------------
     978             : 
     979           0 : void SfxToolBoxControl::DoubleClick()
     980             : {
     981           0 : }
     982             : 
     983             : //--------------------------------------------------------------------
     984             : 
     985           0 : void SfxToolBoxControl::Click()
     986             : {
     987           0 : }
     988             : 
     989             : //--------------------------------------------------------------------
     990             : 
     991           0 : SfxPopupWindowType SfxToolBoxControl::GetPopupWindowType() const
     992             : {
     993           0 :     return SFX_POPUPWINDOW_NONE;
     994             : }
     995             : 
     996             : //--------------------------------------------------------------------
     997             : 
     998           0 : SfxPopupWindow* SfxToolBoxControl::CreatePopupWindow()
     999             : {
    1000           0 :     return 0;
    1001             : }
    1002             : 
    1003           0 : SfxPopupWindow* SfxToolBoxControl::CreatePopupWindowCascading()
    1004             : {
    1005           0 :     return 0;
    1006             : }
    1007             : 
    1008             : //--------------------------------------------------------------------
    1009             : 
    1010          24 : Window* SfxToolBoxControl::CreateItemWindow( Window * )
    1011             : {
    1012          24 :     return 0;
    1013             : }
    1014             : 
    1015             : //--------------------------------------------------------------------
    1016             : 
    1017           0 : SfxFrameStatusListener::SfxFrameStatusListener(
    1018             :     const Reference< XMultiServiceFactory >& rServiceManager,
    1019             :     const Reference< XFrame >& xFrame,
    1020             :     SfxStatusListenerInterface* pCallee ) :
    1021             :     svt::FrameStatusListener( rServiceManager, xFrame ),
    1022           0 :     m_pCallee( pCallee )
    1023             : {
    1024           0 : }
    1025             : 
    1026             : //--------------------------------------------------------------------
    1027             : 
    1028           0 : SfxFrameStatusListener::~SfxFrameStatusListener()
    1029             : {
    1030           0 : }
    1031             : 
    1032             : //--------------------------------------------------------------------
    1033             : 
    1034             : // XStatusListener
    1035           0 : void SAL_CALL SfxFrameStatusListener::statusChanged( const ::com::sun::star::frame::FeatureStateEvent& rEvent )
    1036             : throw ( ::com::sun::star::uno::RuntimeException )
    1037             : {
    1038           0 :     SfxViewFrame* pViewFrame = NULL;
    1039           0 :     Reference < XController > xController;
    1040             : 
    1041           0 :     SolarMutexGuard aGuard;
    1042           0 :     if ( m_xFrame.is() )
    1043           0 :         xController = m_xFrame->getController();
    1044             : 
    1045           0 :     Reference < XDispatchProvider > xProvider( xController, UNO_QUERY );
    1046           0 :     if ( xProvider.is() )
    1047             :     {
    1048           0 :         Reference < XDispatch > xDisp = xProvider->queryDispatch( rEvent.FeatureURL, ::rtl::OUString(), 0 );
    1049           0 :         if ( xDisp.is() )
    1050             :         {
    1051           0 :             Reference< XUnoTunnel > xTunnel( xDisp, UNO_QUERY );
    1052           0 :             SfxOfficeDispatch* pDisp = NULL;
    1053           0 :             if ( xTunnel.is() )
    1054             :             {
    1055           0 :                 sal_Int64 nImplementation = xTunnel->getSomething(SfxOfficeDispatch::impl_getStaticIdentifier());
    1056           0 :                 pDisp = reinterpret_cast< SfxOfficeDispatch* >( sal::static_int_cast< sal_IntPtr >( nImplementation ));
    1057             :             }
    1058             : 
    1059           0 :             if ( pDisp )
    1060           0 :                 pViewFrame = pDisp->GetDispatcher_Impl()->GetFrame();
    1061           0 :         }
    1062             :     }
    1063             : 
    1064           0 :     sal_uInt16 nSlotId = 0;
    1065           0 :     SfxSlotPool& rPool = SfxSlotPool::GetSlotPool( pViewFrame );
    1066           0 :     const SfxSlot* pSlot = rPool.GetUnoSlot( rEvent.FeatureURL.Path );
    1067           0 :     if ( pSlot )
    1068           0 :         nSlotId = pSlot->GetSlotId();
    1069             : 
    1070           0 :     if ( nSlotId > 0 )
    1071             :     {
    1072           0 :         if ( rEvent.Requery )
    1073             :         {
    1074             :             // requery for the notified state
    1075           0 :             addStatusListener( rEvent.FeatureURL.Complete );
    1076             :         }
    1077             :         else
    1078             :         {
    1079           0 :             SfxItemState eState = SFX_ITEM_DISABLED;
    1080           0 :             SfxPoolItem* pItem = NULL;
    1081           0 :             if ( rEvent.IsEnabled )
    1082             :             {
    1083           0 :                 eState = SFX_ITEM_AVAILABLE;
    1084           0 :                 ::com::sun::star::uno::Type pType = rEvent.State.getValueType();
    1085             : 
    1086           0 :                 if ( pType == ::getVoidCppuType() )
    1087             :                 {
    1088           0 :                     pItem = new SfxVoidItem( nSlotId );
    1089           0 :                     eState = SFX_ITEM_UNKNOWN;
    1090             :                 }
    1091           0 :                 else if ( pType == ::getBooleanCppuType() )
    1092             :                 {
    1093           0 :                     sal_Bool bTemp = false;
    1094           0 :                     rEvent.State >>= bTemp ;
    1095           0 :                     pItem = new SfxBoolItem( nSlotId, bTemp );
    1096             :                 }
    1097           0 :                 else if ( pType == ::getCppuType((const sal_uInt16*)0) )
    1098             :                 {
    1099           0 :                     sal_uInt16 nTemp = 0;
    1100           0 :                     rEvent.State >>= nTemp ;
    1101           0 :                     pItem = new SfxUInt16Item( nSlotId, nTemp );
    1102             :                 }
    1103           0 :                 else if ( pType == ::getCppuType((const sal_uInt32*)0) )
    1104             :                 {
    1105           0 :                     sal_uInt32 nTemp = 0;
    1106           0 :                     rEvent.State >>= nTemp ;
    1107           0 :                     pItem = new SfxUInt32Item( nSlotId, nTemp );
    1108             :                 }
    1109           0 :                 else if ( pType == ::getCppuType((const ::rtl::OUString*)0) )
    1110             :                 {
    1111           0 :                     ::rtl::OUString sTemp ;
    1112           0 :                     rEvent.State >>= sTemp ;
    1113           0 :                     pItem = new SfxStringItem( nSlotId, sTemp );
    1114             :                 }
    1115           0 :                 else if ( pType == ::getCppuType((const ::com::sun::star::frame::status::ItemStatus*)0) )
    1116             :                 {
    1117           0 :                     ItemStatus aItemStatus;
    1118           0 :                     rEvent.State >>= aItemStatus;
    1119           0 :                     eState = aItemStatus.State;
    1120           0 :                     pItem = new SfxVoidItem( nSlotId );
    1121             :                 }
    1122           0 :                 else if ( pType == ::getCppuType((const ::com::sun::star::frame::status::Visibility*)0) )
    1123             :                 {
    1124           0 :                     Visibility aVisibilityStatus;
    1125           0 :                     rEvent.State >>= aVisibilityStatus;
    1126           0 :                     pItem = new SfxVisibilityItem( nSlotId, aVisibilityStatus.bVisible );
    1127             :                 }
    1128             :                 else
    1129             :                 {
    1130           0 :                     if ( pSlot )
    1131           0 :                         pItem = pSlot->GetType()->CreateItem();
    1132           0 :                     if ( pItem )
    1133             :                     {
    1134           0 :                         pItem->SetWhich( nSlotId );
    1135           0 :                         pItem->PutValue( rEvent.State );
    1136             :                     }
    1137             :                     else
    1138           0 :                         pItem = new SfxVoidItem( nSlotId );
    1139           0 :                 }
    1140             :             }
    1141             : 
    1142           0 :             if ( m_pCallee )
    1143           0 :                 m_pCallee->StateChanged( nSlotId, eState, pItem );
    1144           0 :             delete pItem;
    1145             :         }
    1146           0 :     }
    1147           0 : }
    1148             : 
    1149             : //--------------------------------------------------------------------
    1150             : 
    1151           0 : SfxPopupWindow::SfxPopupWindow(
    1152             :     sal_uInt16 nId,
    1153             :     const Reference< XFrame >& rFrame,
    1154             :     WinBits nBits ) :
    1155             :     FloatingWindow( SFX_APP()->GetTopWindow(), nBits )
    1156             :     , m_bFloating(sal_False)
    1157             :     , m_bCascading( sal_False )
    1158             :     , m_nId( nId )
    1159             :     , m_xFrame( rFrame )
    1160           0 :     , m_pStatusListener( 0 )
    1161             : {
    1162           0 :     Window* pWindow = GetTopMostParentSystemWindow( this );
    1163           0 :     if ( pWindow )
    1164           0 :         ((SystemWindow *)pWindow)->GetTaskPaneList()->AddWindow( this );
    1165           0 : }
    1166             : 
    1167             : //--------------------------------------------------------------------
    1168             : 
    1169           0 : SfxPopupWindow::SfxPopupWindow(
    1170             :     sal_uInt16 nId,
    1171             :     const Reference< XFrame >& rFrame,
    1172             :     const ResId &rId ) :
    1173             :     FloatingWindow( SFX_APP()->GetTopWindow(), rId )
    1174             :     , m_bFloating(sal_False)
    1175             :     , m_bCascading( sal_False )
    1176             :     , m_nId( nId )
    1177             :     , m_xFrame( rFrame )
    1178           0 :     , m_pStatusListener( 0 )
    1179             : {
    1180           0 :     Window* pWindow = GetTopMostParentSystemWindow( this );
    1181           0 :     if ( pWindow )
    1182           0 :         ((SystemWindow *)pWindow)->GetTaskPaneList()->AddWindow( this );
    1183           0 : }
    1184             : 
    1185             : //--------------------------------------------------------------------
    1186             : 
    1187           0 : SfxPopupWindow::SfxPopupWindow(
    1188             :     sal_uInt16 nId,
    1189             :     const Reference< XFrame >& rFrame,
    1190             :     Window* pParentWindow,
    1191             :     WinBits nBits ) :
    1192             :     FloatingWindow( pParentWindow, nBits )
    1193             :     , m_bFloating(sal_False)
    1194             :     , m_bCascading( sal_False )
    1195             :     , m_nId( nId )
    1196             :     , m_xFrame( rFrame )
    1197           0 :     , m_pStatusListener( 0 )
    1198             : {
    1199           0 :     Window* pWindow = GetTopMostParentSystemWindow( this );
    1200           0 :     if ( pWindow )
    1201           0 :         ((SystemWindow *)pWindow)->GetTaskPaneList()->AddWindow( this );
    1202           0 : }
    1203             : 
    1204             : //--------------------------------------------------------------------
    1205             : 
    1206           0 : SfxPopupWindow::~SfxPopupWindow()
    1207             : {
    1208           0 :     if ( m_xStatusListener.is() )
    1209             :     {
    1210           0 :         m_xStatusListener->dispose();
    1211           0 :         m_xStatusListener.clear();
    1212             :     }
    1213             : 
    1214           0 :     Window* pWindow = GetTopMostParentSystemWindow( this );
    1215           0 :     if ( pWindow )
    1216           0 :         ((SystemWindow *)pWindow)->GetTaskPaneList()->RemoveWindow( this );
    1217           0 : }
    1218             : 
    1219             : //--------------------------------------------------------------------
    1220             : 
    1221           0 : SfxFrameStatusListener* SfxPopupWindow::GetOrCreateStatusListener()
    1222             : {
    1223           0 :     if ( !m_xStatusListener.is() )
    1224             :     {
    1225             :         m_pStatusListener = new SfxFrameStatusListener(
    1226             :                                     ::comphelper::getProcessServiceFactory(),
    1227             :                                     m_xFrame,
    1228           0 :                                     this );
    1229             :         m_xStatusListener = Reference< XComponent >( static_cast< cppu::OWeakObject* >(
    1230           0 :                                                         m_pStatusListener ), UNO_QUERY );
    1231             :     }
    1232             : 
    1233           0 :     return m_pStatusListener;
    1234             : }
    1235             : 
    1236             : //--------------------------------------------------------------------
    1237             : 
    1238           0 : void SfxPopupWindow::BindListener()
    1239             : {
    1240           0 :     GetOrCreateStatusListener();
    1241           0 :     if ( m_xStatusListener.is() )
    1242           0 :         m_pStatusListener->bindListener();
    1243           0 : }
    1244             : 
    1245             : //--------------------------------------------------------------------
    1246             : 
    1247           0 : void SfxPopupWindow::UnbindListener()
    1248             : {
    1249           0 :     GetOrCreateStatusListener();
    1250           0 :     if ( m_xStatusListener.is() )
    1251           0 :         m_pStatusListener->unbindListener();
    1252           0 : }
    1253             : 
    1254             : //--------------------------------------------------------------------
    1255             : 
    1256           0 : void SfxPopupWindow::AddStatusListener( const rtl::OUString& rCommandURL )
    1257             : {
    1258           0 :     GetOrCreateStatusListener();
    1259           0 :     if ( m_xStatusListener.is() )
    1260           0 :         m_pStatusListener->addStatusListener( rCommandURL );
    1261           0 : }
    1262             : 
    1263             : //--------------------------------------------------------------------
    1264             : 
    1265           0 : sal_Bool SfxPopupWindow::Close()
    1266             : {
    1267           0 :     m_bFloating = sal_False;
    1268           0 :     FloatingWindow::Close();
    1269             : 
    1270           0 :     Delete();
    1271           0 :     return sal_True;
    1272             : }
    1273             : 
    1274             : //--------------------------------------------------------------------
    1275             : 
    1276           0 : void SfxPopupWindow::PopupModeEnd()
    1277             : {
    1278             :     //! to allow PopupModeEndHdl to be called
    1279           0 :     FloatingWindow::PopupModeEnd();
    1280             : 
    1281           0 :     if ( IsVisible() )
    1282             :     {
    1283             :         // was teared-off
    1284           0 :         DeleteFloatingWindow();
    1285           0 :         m_bFloating = sal_True;
    1286             :     }
    1287             :     else
    1288           0 :         Close();
    1289           0 : }
    1290             : 
    1291             : //--------------------------------------------------------------------
    1292             : 
    1293           0 : void SfxPopupWindow::DeleteFloatingWindow()
    1294             : {
    1295           0 :     if ( m_bFloating )
    1296             :     {
    1297           0 :         Hide();
    1298           0 :         Delete();
    1299             :     }
    1300           0 : }
    1301             : 
    1302             : //--------------------------------------------------------------------
    1303             : 
    1304           0 : void SfxPopupWindow::MouseMove( const ::MouseEvent& rMEvt )
    1305             : {
    1306           0 :     if ( m_bCascading == sal_False )
    1307           0 :         FloatingWindow::MouseMove( rMEvt );
    1308             :     else
    1309             :     {
    1310             :         // Forward MouseMove-Event to Children
    1311           0 :         ::Point       aPos = rMEvt.GetPosPixel();
    1312           0 :         ::Point       aScrPos = OutputToScreenPixel( aPos );
    1313           0 :         sal_uInt16 i = 0;
    1314           0 :         Window* pWindow = GetChild( i );
    1315           0 :         while ( pWindow )
    1316             :         {
    1317             :             ::MouseEvent aMEvt( pWindow->ScreenToOutputPixel( aScrPos ),
    1318           0 :                               rMEvt.GetClicks(), rMEvt.GetMode(),
    1319           0 :                               rMEvt.GetButtons(), rMEvt.GetModifier() );
    1320           0 :             pWindow->MouseMove( rMEvt );
    1321           0 :             pWindow->Update();
    1322           0 :             i++;
    1323           0 :             pWindow = GetChild( i );
    1324             :         }
    1325             :     }
    1326           0 : }
    1327             : 
    1328             : //--------------------------------------------------------------------
    1329             : 
    1330           0 : void SfxPopupWindow::StartCascading()
    1331             : {
    1332           0 :     m_bCascading= sal_True;
    1333           0 : }
    1334             : 
    1335             : //--------------------------------------------------------------------
    1336             : 
    1337           0 : SfxPopupWindow* SfxPopupWindow::Clone() const
    1338             : 
    1339             : /*  [Description]
    1340             : 
    1341             :     This method must be overloaded to show this Popup also in the
    1342             :     Presentation-mode. It is called when a Show() would be meaningless
    1343             :     since the parent is no presentation window.
    1344             :     When create a new window the bew Top-Window will be used automatically,
    1345             :     so that the Parent becomes the presentation window and and that the new
    1346             :     Popup therefore becomes visible.
    1347             : */
    1348             : 
    1349             : {
    1350           0 :     return 0;
    1351             : }
    1352             : 
    1353             : //--------------------------------------------------------------------
    1354             : 
    1355           0 : void SfxPopupWindow::StateChanged(
    1356             :     sal_uInt16 /*nSID*/,
    1357             :     SfxItemState eState,
    1358             :     const SfxPoolItem* /*pState*/ )
    1359             : /*  [Description]
    1360             : 
    1361             :     See also <SfxControllerItem::StateChanged()>. In addition the Popup
    1362             :     will become hidden when eState==SFX_ITEM_DISABLED and in all other
    1363             :     cases it will be shown again if it is floating. In general this requires
    1364             :     to call the Base class.
    1365             : 
    1366             :     Due to the parent the presentation mode is handled in a special way.
    1367             : */
    1368             : 
    1369             : {
    1370           0 :     if ( SFX_ITEM_DISABLED == eState )
    1371             :     {
    1372           0 :         Hide();
    1373             :     }
    1374           0 :     else if ( m_bFloating )
    1375             :     {
    1376           0 :         Show( sal_True, SHOW_NOFOCUSCHANGE | SHOW_NOACTIVATE );
    1377             :     }
    1378           0 : }
    1379             : 
    1380             : //--------------------------------------------------------------------
    1381             : 
    1382           0 : void SfxPopupWindow::Delete()
    1383             : {
    1384           0 :     if ( m_aDeleteLink.IsSet() )
    1385           0 :         m_aDeleteLink.Call( this );
    1386           0 :     delete this;
    1387           0 : }
    1388             : 
    1389             : //--------------------------------------------------------------------
    1390             : 
    1391           2 : SfxAppToolBoxControl_Impl::SfxAppToolBoxControl_Impl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rBox )
    1392             :     : SfxToolBoxControl( nSlotId, nId, rBox )
    1393           2 :     , pMenu( 0 )
    1394             : {
    1395           2 :     rBox.SetHelpId( nId, HID_TBXCONTROL_FILENEW );
    1396           2 :     rBox.SetItemBits( nId,  rBox.GetItemBits( nId ) | TIB_DROPDOWN);
    1397             : 
    1398             :     // Determine the current background color of the menus
    1399           2 :     const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
    1400           2 :     m_nSymbolsStyle         = rSettings.GetSymbolsStyle();
    1401           2 :     m_bShowMenuImages       = rSettings.GetUseImagesInMenus();
    1402             : 
    1403           2 :     SetImage( String() );
    1404           2 : }
    1405             : 
    1406           6 : SfxAppToolBoxControl_Impl::~SfxAppToolBoxControl_Impl()
    1407             : {
    1408           2 :     delete pMenu;
    1409           4 : }
    1410             : 
    1411             : //_____________________________________________________
    1412             : /*
    1413             :     it return the existing state of the given URL in the popupmenu of this toolbox control.
    1414             : 
    1415             :     If the given URL can be located as an action command of one menu item of the
    1416             :     popup menu of this control, we return sal_True. Otherwhise we return sal_False.
    1417             :     Further we return a fallback URL, in case we have to return sal_False. Because
    1418             :     the outside code must select a valid item of the popup menu everytime ...
    1419             :     and we define it here. By the way this m ethod was written to handle
    1420             :     error situations gracefully. E.g. it can be called during creation time
    1421             :     but then we have no valid menu. For this case we know another fallback URL.
    1422             :     Then we return the private:factory/ URL of the default factory.
    1423             : 
    1424             :     @param  *pMenu
    1425             :                 pounts to the popup menu, on which item we try to locate the given URL
    1426             :                 Can be NULL! Search will be supressed then.
    1427             : 
    1428             :     @param  sURL
    1429             :                 the URL for searching
    1430             : 
    1431             :     @param  pFallback
    1432             :                 contains the fallback URL in case we return FALSE
    1433             :                 Must point to valid memory!
    1434             : 
    1435             :     @param  pImage
    1436             :                 contains the image of the menu for the URL.
    1437             : 
    1438             :     @return sal_True - if URL could be located as an item of the popup menu.
    1439             :             sal_False - otherwhise.
    1440             : */
    1441           6 : sal_Bool Impl_ExistURLInMenu( const PopupMenu *pMenu     ,
    1442             :                                 String    &sURL      ,
    1443             :                                 String    *pFallback ,
    1444             :                                 Image     *pImage    )
    1445             : {
    1446           6 :     sal_Bool bValidFallback = sal_False;
    1447           6 :     if (pMenu && sURL.Len())
    1448             :     {
    1449           4 :         sal_uInt16 c = pMenu->GetItemCount();
    1450           4 :         for (sal_uInt16 p=0; p<c; ++p)
    1451             :         {
    1452           4 :             sal_uInt16 nId = pMenu->GetItemId(p);
    1453           4 :             String aCmd( pMenu->GetItemCommand(nId) );
    1454             : 
    1455           4 :             if (!bValidFallback && aCmd.Len())
    1456             :             {
    1457           4 :                 *pFallback = aCmd;
    1458           4 :                 bValidFallback = sal_True;
    1459             :             }
    1460             : 
    1461           4 :             if (aCmd.Search(sURL)==0)//match even if the menu command is more detailed (maybe an additional query) #i28667#
    1462             :             {
    1463           4 :                 sURL = aCmd;
    1464           4 :                 *pImage = pMenu->GetItemImage( nId );
    1465           4 :                 return sal_True;
    1466             :             }
    1467           4 :         }
    1468             :     }
    1469             : 
    1470           2 :     if (!bValidFallback)
    1471             :     {
    1472           2 :         *pFallback  = DEFINE_CONST_UNICODE("private:factory/");
    1473           2 :         *pFallback += String(SvtModuleOptions().GetDefaultModuleName());
    1474             :     }
    1475             : 
    1476           2 :     return sal_False;
    1477             : }
    1478             : 
    1479             : long Select_Impl( void* pHdl, void* pVoid );
    1480             : 
    1481           0 : SfxPopupWindow* SfxAppToolBoxControl_Impl::CreatePopupWindow()
    1482             : {
    1483           0 :     ToolBox& rBox = GetToolBox();
    1484           0 :     ::Rectangle aRect( rBox.GetItemRect( GetId() ) );
    1485             : 
    1486           0 :     if ( !pMenu )
    1487             :     {
    1488           0 :         ::framework::MenuConfiguration aConf( m_xServiceManager );
    1489           0 :         if ( m_aCommandURL == ".uno:AddDirect" )
    1490           0 :             pMenu = aConf.CreateBookmarkMenu( m_xFrame, BOOKMARK_NEWMENU );
    1491             :         else
    1492           0 :             pMenu = aConf.CreateBookmarkMenu( m_xFrame, BOOKMARK_WIZARDMENU );
    1493             :     }
    1494             : 
    1495           0 :     if ( pMenu )
    1496             :     {
    1497           0 :         pMenu->SetSelectHdl( Link( NULL, Select_Impl ) );
    1498           0 :         pMenu->SetActivateHdl( LINK( this, SfxAppToolBoxControl_Impl, Activate ));
    1499           0 :         rBox.SetItemDown( GetId(), sal_True );
    1500           0 :         sal_uInt16 nSelected = pMenu->Execute( &rBox, aRect, POPUPMENU_EXECUTE_DOWN );
    1501           0 :         if ( nSelected )
    1502             :         {
    1503           0 :             aLastURL = pMenu->GetItemCommand( nSelected );
    1504           0 :             SetImage( pMenu->GetItemCommand( nSelected ) );
    1505             :         }
    1506             : 
    1507           0 :         rBox.SetItemDown( GetId(), sal_False );
    1508             :     }
    1509             : 
    1510           0 :     return 0;
    1511             : }
    1512             : 
    1513           6 : void SfxAppToolBoxControl_Impl::SetImage( const String &rURL )
    1514             : {
    1515             :     /* We accept URL's here only, which exist as items of our internal popup menu.
    1516             :        All other ones will be ignored and a fallback is used ... */
    1517           6 :     String aURL = rURL;
    1518           6 :     String sFallback;
    1519           6 :     Image aMenuImage;
    1520           6 :     sal_Bool bValid = Impl_ExistURLInMenu(pMenu,aURL,&sFallback,&aMenuImage);
    1521           6 :     if (!bValid)
    1522           2 :         aURL = sFallback;
    1523             : 
    1524           6 :     sal_Bool bBig = SvtMiscOptions().AreCurrentSymbolsLarge();
    1525           6 :     Image aImage = SvFileInformationManager::GetImageNoDefault( INetURLObject( aURL ), bBig );
    1526           6 :     if ( !aImage )
    1527           0 :         aImage = !!aMenuImage ? aMenuImage :
    1528           0 :             SvFileInformationManager::GetImage( INetURLObject( aURL ), bBig );
    1529           6 :     Size aBigSize( GetToolBox().GetDefaultImageSize() );
    1530           6 :     if ( bBig && aImage.GetSizePixel() != aBigSize )
    1531             :     {
    1532           0 :         BitmapEx aScaleBmpEx( aImage.GetBitmapEx() );
    1533           0 :         aScaleBmpEx.Scale( aBigSize, BMP_SCALE_BEST );
    1534           0 :         GetToolBox().SetItemImage( GetId(), Image( aScaleBmpEx ) );
    1535             :     }
    1536             :     else
    1537           6 :         GetToolBox().SetItemImage( GetId(), aImage );
    1538           6 :     aLastURL = aURL;
    1539           6 : }
    1540             : 
    1541           4 : void SfxAppToolBoxControl_Impl::StateChanged
    1542             : (
    1543             :     sal_uInt16              nSlotId,
    1544             :     SfxItemState        eState,
    1545             :     const SfxPoolItem*  pState
    1546             : )
    1547             : {
    1548           4 :     if ( pState && pState->ISA(SfxStringItem) )
    1549             :     {
    1550             :         // Important step for following SetImage() call!
    1551             :         // It needs the valid pMenu item to fullfill it's specification
    1552             :         // to check for supported URLs ...
    1553           4 :         if ( !pMenu )
    1554             :         {
    1555           2 :             ::framework::MenuConfiguration aConf( m_xServiceManager );
    1556             :             // This toolbox controller is used for two popup menus (new documents and wizards!). Create the correct
    1557             :             // popup menu according to the slot ID our controller has been initialized with.
    1558           2 :             if ( nSlotId == SID_NEWDOCDIRECT )
    1559           2 :                 pMenu = aConf.CreateBookmarkMenu( m_xFrame, BOOKMARK_NEWMENU );
    1560             :             else
    1561           0 :                 pMenu = aConf.CreateBookmarkMenu( m_xFrame, BOOKMARK_WIZARDMENU );
    1562             :         }
    1563             : 
    1564           4 :         GetToolBox().EnableItem( GetId(), eState != SFX_ITEM_DISABLED );
    1565           4 :         SetImage(((const SfxStringItem*)pState)->GetValue());
    1566             :     }
    1567             :     else
    1568           0 :         SfxToolBoxControl::StateChanged( nSlotId, eState, pState );
    1569           4 : }
    1570             : 
    1571             : //--------------------------------------------------------------------
    1572             : 
    1573           0 : void SfxAppToolBoxControl_Impl::Select( sal_Bool bMod1 )
    1574             : {
    1575           0 :     if( aLastURL.Len() )
    1576             :     {
    1577           0 :         URL                            aTargetURL;
    1578           0 :         Reference< XDispatch >         xDispatch;
    1579           0 :         Reference< XDispatchProvider > xDispatchProvider( getFrameInterface(), UNO_QUERY );
    1580             : 
    1581           0 :         if ( xDispatchProvider.is() )
    1582             :         {
    1583           0 :             aTargetURL.Complete = aLastURL;
    1584           0 :             getURLTransformer()->parseStrict( aTargetURL );
    1585             : 
    1586           0 :             ::rtl::OUString aTarget( ::rtl::OUString("_default"));
    1587           0 :             if ( pMenu )
    1588             :             {
    1589             :                 ::framework::MenuConfiguration::Attributes* pMenuAttributes =
    1590           0 :                     (::framework::MenuConfiguration::Attributes*)pMenu->GetUserValue( pMenu->GetCurItemId() );
    1591             : 
    1592           0 :                 if ( pMenuAttributes )
    1593           0 :                     aTarget = pMenuAttributes->aTargetFrame;
    1594             :             }
    1595             : 
    1596           0 :             xDispatch = xDispatchProvider->queryDispatch( aTargetURL, aTarget, 0 );
    1597             : 
    1598           0 :             if ( xDispatch.is() )
    1599             :             {
    1600           0 :                 Sequence< PropertyValue > aArgs( 1 );
    1601             : 
    1602           0 :                 aArgs[0].Name = ::rtl::OUString("Referer");
    1603           0 :                 aArgs[0].Value = makeAny( ::rtl::OUString(SFX_REFERER_USER ) );
    1604             : 
    1605           0 :                 ExecuteInfo* pExecuteInfo = new ExecuteInfo;
    1606           0 :                 pExecuteInfo->xDispatch     = xDispatch;
    1607           0 :                 pExecuteInfo->aTargetURL    = aTargetURL;
    1608           0 :                 pExecuteInfo->aArgs         = aArgs;
    1609           0 :                 Application::PostUserEvent( STATIC_LINK(0, SfxAppToolBoxControl_Impl, ExecuteHdl_Impl), pExecuteInfo );
    1610           0 :             }
    1611           0 :         }
    1612             :     }
    1613             :     else
    1614           0 :         SfxToolBoxControl::Select( bMod1 );
    1615           0 : }
    1616             : 
    1617             : //--------------------------------------------------------------------
    1618           0 : long Select_Impl( void* /*pHdl*/, void* pVoid )
    1619             : {
    1620           0 :     Menu* pMenu = (Menu*)pVoid;
    1621           0 :     String aURL( pMenu->GetItemCommand( pMenu->GetCurItemId() ) );
    1622             : 
    1623           0 :     if( !aURL.Len() )
    1624           0 :         return 0;
    1625             : 
    1626             :     Reference < ::com::sun::star::frame::XFramesSupplier > xDesktop =
    1627           0 :             Reference < ::com::sun::star::frame::XFramesSupplier >( ::comphelper::getProcessServiceFactory()->createInstance(
    1628           0 :                                                                         DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );
    1629           0 :     Reference < ::com::sun::star::frame::XFrame > xFrame( xDesktop, UNO_QUERY );
    1630             : 
    1631           0 :     URL aTargetURL;
    1632           0 :     aTargetURL.Complete = aURL;
    1633           0 :     Reference < XURLTransformer > xTrans( URLTransformer::create( ::comphelper::getProcessComponentContext() ) );
    1634           0 :     xTrans->parseStrict( aTargetURL );
    1635             : 
    1636           0 :     Reference < XDispatchProvider > xProv( xFrame, UNO_QUERY );
    1637           0 :     Reference < XDispatch > xDisp;
    1638           0 :     if ( xProv.is() )
    1639             :     {
    1640           0 :         if ( aTargetURL.Protocol.compareToAscii("slot:") == COMPARE_EQUAL )
    1641           0 :             xDisp = xProv->queryDispatch( aTargetURL, ::rtl::OUString(), 0 );
    1642             :         else
    1643             :         {
    1644           0 :             ::rtl::OUString aTargetFrame( ::rtl::OUString("_blank") );
    1645             :             ::framework::MenuConfiguration::Attributes* pMenuAttributes =
    1646           0 :                 (::framework::MenuConfiguration::Attributes*)pMenu->GetUserValue( pMenu->GetCurItemId() );
    1647             : 
    1648           0 :             if ( pMenuAttributes )
    1649           0 :                 aTargetFrame = pMenuAttributes->aTargetFrame;
    1650             : 
    1651           0 :             xDisp = xProv->queryDispatch( aTargetURL, aTargetFrame , 0 );
    1652             :         }
    1653             :     }
    1654             : 
    1655           0 :     if ( xDisp.is() )
    1656             :     {
    1657           0 :         SfxAppToolBoxControl_Impl::ExecuteInfo* pExecuteInfo = new SfxAppToolBoxControl_Impl::ExecuteInfo;
    1658           0 :         pExecuteInfo->xDispatch     = xDisp;
    1659           0 :         pExecuteInfo->aTargetURL    = aTargetURL;
    1660           0 :         pExecuteInfo->aArgs         = Sequence< PropertyValue >();
    1661           0 :         Application::PostUserEvent( STATIC_LINK( 0, SfxAppToolBoxControl_Impl, ExecuteHdl_Impl), pExecuteInfo );
    1662             :     }
    1663             : 
    1664           0 :     return sal_True;
    1665             : }
    1666             : 
    1667           0 : IMPL_LINK( SfxAppToolBoxControl_Impl, Activate, Menu *, pActMenu )
    1668             : {
    1669           0 :     if ( pActMenu )
    1670             :     {
    1671           0 :         const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
    1672           0 :         sal_uIntPtr nSymbolsStyle     = rSettings.GetSymbolsStyle();
    1673           0 :         sal_Bool bShowMenuImages    = rSettings.GetUseImagesInMenus();
    1674             : 
    1675           0 :         if (( nSymbolsStyle != m_nSymbolsStyle ) ||
    1676             :             ( bShowMenuImages != m_bShowMenuImages ))
    1677             :         {
    1678           0 :             m_nSymbolsStyle      = nSymbolsStyle;
    1679           0 :             m_bShowMenuImages    = bShowMenuImages;
    1680             : 
    1681           0 :             sal_uInt16 nCount = pActMenu->GetItemCount();
    1682           0 :             for ( sal_uInt16 nSVPos = 0; nSVPos < nCount; nSVPos++ )
    1683             :             {
    1684           0 :                 sal_uInt16 nId = pActMenu->GetItemId( nSVPos );
    1685           0 :                 if ( pActMenu->GetItemType( nSVPos ) != MENUITEM_SEPARATOR )
    1686             :                 {
    1687           0 :                     if ( bShowMenuImages )
    1688             :                     {
    1689           0 :                         sal_Bool        bImageSet = sal_False;
    1690           0 :                         ::rtl::OUString aImageId;
    1691             :                         ::framework::MenuConfiguration::Attributes* pMenuAttributes =
    1692           0 :                             (::framework::MenuConfiguration::Attributes*)pMenu->GetUserValue( nId );
    1693             : 
    1694           0 :                         if ( pMenuAttributes )
    1695           0 :                             aImageId = pMenuAttributes->aImageId; // Retrieve image id from menu attributes
    1696             : 
    1697           0 :                         if ( !aImageId.isEmpty() )
    1698             :                         {
    1699           0 :                             Reference< ::com::sun::star::frame::XFrame > xFrame;
    1700           0 :                             Image aImage = GetImage( xFrame, aImageId, false );
    1701           0 :                             if ( !!aImage )
    1702             :                             {
    1703           0 :                                 bImageSet = sal_True;
    1704           0 :                                 pActMenu->SetItemImage( nId, aImage );
    1705           0 :                             }
    1706             :                         }
    1707             : 
    1708           0 :                         String aCmd( pActMenu->GetItemCommand( nId ) );
    1709           0 :                         if ( !bImageSet && aCmd.Len() )
    1710             :                         {
    1711             :                             Image aImage = SvFileInformationManager::GetImage(
    1712           0 :                                 INetURLObject(aCmd), false );
    1713           0 :                             if ( !!aImage )
    1714           0 :                                 pActMenu->SetItemImage( nId, aImage );
    1715           0 :                         }
    1716             :                     }
    1717             :                     else
    1718           0 :                         pActMenu->SetItemImage( nId, Image() );
    1719             :                 }
    1720             :             }
    1721             :         }
    1722             : 
    1723           0 :         return sal_True;
    1724             :     }
    1725             : 
    1726           0 :     return sal_False;
    1727             : }
    1728             : 
    1729             : //--------------------------------------------------------------------
    1730             : 
    1731           0 : IMPL_STATIC_LINK_NOINSTANCE( SfxAppToolBoxControl_Impl, ExecuteHdl_Impl, ExecuteInfo*, pExecuteInfo )
    1732             : {
    1733             : /*  i62706: Don't catch all exceptions. We hide all problems here and are not able
    1734             :             to handle them on higher levels.
    1735             :     try
    1736             :     {
    1737             : */
    1738             :         // Asynchronous execution as this can lead to our own destruction!
    1739             :         // Framework can recycle our current frame and the layout manager disposes all user interface
    1740             :         // elements if a component gets detached from its frame!
    1741           0 :         pExecuteInfo->xDispatch->dispatch( pExecuteInfo->aTargetURL, pExecuteInfo->aArgs );
    1742           0 :     delete pExecuteInfo;
    1743           0 :     return 0;
    1744             : }
    1745             : 
    1746             : //--------------------------------------------------------------------
    1747             : 
    1748           0 : void SfxAppToolBoxControl_Impl::Click( )
    1749             : {
    1750           0 : }
    1751             : 
    1752             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10