LCOV - code coverage report
Current view: top level - libreoffice/sfx2/source/toolbox - tbxitem.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 5 795 0.6 %
Date: 2012-12-27 Functions: 3 93 3.2 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10