LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sfx2/source/menu - virtmenu.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 500 0.2 %
Date: 2013-07-09 Functions: 2 37 5.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include <sot/factory.hxx>
      22             : #include <svtools/menuoptions.hxx>
      23             : #include <svtools/imagemgr.hxx>
      24             : #include <svl/imageitm.hxx>
      25             : #include <com/sun/star/container/XEnumeration.hpp>
      26             : #include <com/sun/star/frame/Desktop.hpp>
      27             : #include <com/sun/star/frame/XFramesSupplier.hpp>
      28             : #include <comphelper/processfactory.hxx>
      29             : #include <toolkit/helper/vclunohelper.hxx>
      30             : 
      31             : #include "virtmenu.hxx"
      32             : #include <sfx2/msgpool.hxx>
      33             : #include "statcach.hxx"
      34             : #include <sfx2/msg.hxx>
      35             : #include "idpool.hxx"
      36             : #include <sfx2/mnuitem.hxx>
      37             : #include <sfx2/mnumgr.hxx>
      38             : #include <sfx2/bindings.hxx>
      39             : #include <sfx2/dispatch.hxx>
      40             : #include <sfx2/app.hxx>
      41             : #include "sfxtypes.hxx"
      42             : #include "arrdecl.hxx"
      43             : #include <sfx2/sfx.hrc>
      44             : #include <sfx2/viewsh.hxx>
      45             : #include "sfxpicklist.hxx"
      46             : #include "sfx2/sfxresid.hxx"
      47             : #include "menu.hrc"
      48             : #include "sfx2/imagemgr.hxx"
      49             : #include <sfx2/viewfrm.hxx>
      50             : #include <sfx2/objsh.hxx>
      51             : #include <framework/addonsoptions.hxx>
      52             : 
      53             : #include <framework/addonmenu.hxx>
      54             : #include <framework/menuconfiguration.hxx>
      55             : 
      56             : using namespace ::com::sun::star::container;
      57             : using namespace ::com::sun::star::frame;
      58             : using namespace ::com::sun::star::uno;
      59             : 
      60             : DBG_NAME(SfxVirtualMenu)
      61             : 
      62           0 : class SfxMenuImageControl_Impl : public SfxControllerItem
      63             : {
      64             :     SfxVirtualMenu*     pMenu;
      65             :     long                lRotation;
      66             :     sal_Bool                bIsMirrored;
      67             : 
      68             : protected:
      69             :     virtual void        StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState );
      70             : public:
      71           0 :                         SfxMenuImageControl_Impl( sal_uInt16 nSlotId, SfxBindings& rBindings, SfxVirtualMenu* pVMenu )
      72             :                             : SfxControllerItem( nSlotId, rBindings )
      73             :                             , pMenu( pVMenu )
      74             :                             , lRotation( 0 )
      75           0 :                             , bIsMirrored( sal_False )
      76           0 :                         {}
      77             :     void                Update();
      78             : };
      79             : 
      80           0 : void SfxMenuImageControl_Impl::StateChanged( sal_uInt16 /*nSID*/, SfxItemState /*eState*/, const SfxPoolItem* pState )
      81             : {
      82           0 :     const SfxImageItem* pItem = PTR_CAST( SfxImageItem, pState );
      83           0 :     if ( pItem )
      84             :     {
      85           0 :         lRotation = pItem->GetRotation();
      86           0 :         bIsMirrored = pItem->IsMirrored();
      87           0 :         Update();
      88             :     }
      89           0 : }
      90             : 
      91           0 : void SfxMenuImageControl_Impl::Update()
      92             : {
      93           0 :     SfxViewFrame* pViewFrame = GetBindings().GetDispatcher_Impl()->GetFrame();
      94           0 :     SfxModule* pModule = pViewFrame->GetObjectShell()->GetModule();
      95           0 :     SfxSlotPool* pPool = pModule->GetSlotPool();
      96           0 :     Menu* pSVMenu = pMenu->GetSVMenu();
      97           0 :     for (sal_uInt16 nPos = 0; nPos<pSVMenu->GetItemCount(); nPos++)
      98             :     {
      99           0 :         sal_uInt16 nslotId = pSVMenu->GetItemId( nPos );
     100           0 :         const SfxSlot* pSlot = pPool->GetSlot( nslotId );
     101           0 :         if ( pSlot && pSlot->IsMode( SFX_SLOT_IMAGEROTATION ) )
     102             :         {
     103           0 :             pSVMenu->SetItemImageMirrorMode( nslotId, sal_False );
     104           0 :             pSVMenu->SetItemImageAngle( nslotId, lRotation );
     105             :         }
     106             : 
     107           0 :         if ( pSlot && pSlot->IsMode( SFX_SLOT_IMAGEREFLECTION ) )
     108           0 :             pSVMenu->SetItemImageMirrorMode( nslotId, bIsMirrored );
     109             :     }
     110           0 : }
     111             : 
     112             : //=========================================================================
     113             : 
     114           0 : static Image RetrieveAddOnImage( Reference< com::sun::star::frame::XFrame >& rFrame,
     115             :                                  const OUString& aImageId,
     116             :                                  const OUString& aURL,
     117             :                                  bool bBigImage
     118             : )
     119             : {
     120           0 :     Image aImage;
     121             : 
     122           0 :     if ( !aImageId.isEmpty() )
     123             :     {
     124           0 :         aImage = GetImage( rFrame, aImageId, bBigImage );
     125           0 :         if ( !!aImage )
     126           0 :             return aImage;
     127             :     }
     128             : 
     129           0 :     aImage = GetImage( rFrame, aURL, bBigImage );
     130           0 :     if ( !aImage )
     131           0 :         aImage = framework::AddonsOptions().GetImageFromURL( aURL, bBigImage );
     132             : 
     133           0 :     return aImage;
     134             : }
     135             : 
     136             : //=========================================================================
     137             : 
     138             : /*  This helper function checks whether a Slot-id in the current application
     139             :     status is visible or not. This relates to the application status to see
     140             :     if the OLE server application exist or not.
     141             : */
     142             : 
     143           0 : sal_Bool IsItemHidden_Impl( sal_uInt16 nItemId, int bOleServer, int bMac )
     144             : {
     145           0 :     return ( bMac &&
     146           0 :              ( nItemId == SID_MINIMIZED ) ) ||
     147           0 :            (  bOleServer &&
     148           0 :              ( nItemId == SID_QUITAPP || nItemId == SID_SAVEDOC ||
     149           0 :                nItemId == SID_OPENDOC || nItemId == SID_SAVEASDOC ||
     150           0 :                nItemId == SID_NEWDOC ) ) ||
     151           0 :            ( !bOleServer &&
     152           0 :              ( nItemId == SID_EXITANDRETURN || nItemId == SID_UPDATEDOC ) );
     153             : }
     154             : 
     155             : //====================================================================
     156             : 
     157           0 : void SfxVirtualMenu::Construct_Impl()
     158             : {
     159           0 :     pSVMenu->SetHighlightHdl( LINK(this, SfxVirtualMenu, Highlight) );
     160           0 :     pSVMenu->SetActivateHdl( LINK(this, SfxVirtualMenu, Activate) );
     161           0 :     pSVMenu->SetDeactivateHdl( LINK(this, SfxVirtualMenu, Deactivate) );
     162           0 :     pSVMenu->SetSelectHdl( LINK(this, SfxVirtualMenu, Select) );
     163             : 
     164           0 :     if ( !pResMgr && pParent )
     165           0 :         pResMgr = pParent->pResMgr;
     166           0 : }
     167             : 
     168             : //--------------------------------------------------------------------
     169             : 
     170           0 : SfxVirtualMenu::SfxVirtualMenu( sal_uInt16 nOwnId,
     171             :                 SfxVirtualMenu* pOwnParent, Menu& rMenu, sal_Bool bWithHelp,
     172             :                 SfxBindings &rBindings, sal_Bool bOLEServer, sal_Bool bRes, sal_Bool bIsAddonMenu ):
     173             :     pItems(0),
     174             :        pImageControl(0),
     175             :     pBindings(&rBindings),
     176             :     pResMgr(0),
     177             :     pAutoDeactivate(0),
     178             :     nLocks(0),
     179             :     bHelpInitialized( bWithHelp ),
     180           0 :     bIsAddonPopupMenu( bIsAddonMenu )
     181             : {
     182             :     DBG_CTOR(SfxVirtualMenu, 0);
     183           0 :     pSVMenu = &rMenu;
     184             : 
     185           0 :     bResCtor = bRes;
     186           0 :     bOLE = bOLEServer;
     187           0 :     nId = nOwnId;
     188           0 :     pParent = pOwnParent;
     189           0 :     nVisibleItems = 0;
     190           0 :     pAppCtrl = 0;
     191           0 :     pWindowMenu = NULL;
     192           0 :     pPickMenu = NULL;
     193           0 :     pAddonsMenu = NULL;
     194           0 :     bIsActive = sal_False;
     195           0 :     bControllersUnBound = sal_False;
     196           0 :     CreateFromSVMenu();
     197           0 :     Construct_Impl();
     198           0 :     bHelpInitialized = sal_False;
     199           0 : }
     200             : 
     201             : //--------------------------------------------------------------------
     202             : 
     203             : // creates a virtual menu from a StarView MenuBar or PopupMenu
     204             : 
     205           0 : SfxVirtualMenu::SfxVirtualMenu( Menu *pStarViewMenu, sal_Bool bWithHelp,
     206             :                     SfxBindings &rBindings, sal_Bool bOLEServer, sal_Bool bRes, sal_Bool bIsAddonMenu ):
     207             :     pItems(0),
     208             :        pImageControl(0),
     209             :     pBindings(&rBindings),
     210             :     pResMgr(0),
     211             :     pAutoDeactivate(0),
     212             :     nLocks(0),
     213             :     bHelpInitialized( bWithHelp ),
     214           0 :     bIsAddonPopupMenu( bIsAddonMenu )
     215             : {
     216             :     DBG_CTOR(SfxVirtualMenu, 0);
     217             : 
     218           0 :     pSVMenu = pStarViewMenu;
     219             : 
     220           0 :     bResCtor = bRes;
     221           0 :     bOLE = bOLEServer;
     222           0 :     nId = 0;
     223           0 :     pParent = 0;
     224           0 :     pAppCtrl = 0;
     225           0 :     nVisibleItems = 0;
     226           0 :     pWindowMenu = NULL;
     227           0 :     pPickMenu = NULL;
     228           0 :     pAddonsMenu = NULL;
     229           0 :     bIsActive = sal_False;
     230           0 :     bControllersUnBound = sal_False;
     231           0 :     CreateFromSVMenu();
     232           0 :     Construct_Impl();
     233           0 :     bHelpInitialized = sal_False;
     234           0 : }
     235             : 
     236             : //--------------------------------------------------------------------
     237             : 
     238             : /*  The destructor of the class SfxVirtualMenu releases bounded items and
     239             :     the associated StarView-PopupMenu is released from its parent.
     240             :     If it is related to the Pickmenu or the MDI-menu, it is unregistered here.
     241             : */
     242             : 
     243           0 : SfxVirtualMenu::~SfxVirtualMenu()
     244             : {
     245             :     DBG_DTOR(SfxVirtualMenu, 0);
     246             : 
     247           0 :     DELETEZ( pImageControl );
     248           0 :     SvtMenuOptions().RemoveListenerLink( LINK( this, SfxVirtualMenu, SettingsChanged ) );
     249             : 
     250           0 :     if ( bIsActive )
     251             :     {
     252           0 :         pBindings->LEAVEREGISTRATIONS(); --nLocks; bIsActive = sal_False;
     253             :     }
     254             : 
     255             :     // QAP-Hack
     256           0 :     if ( pAutoDeactivate )
     257             :     {
     258           0 :         if ( pAutoDeactivate->IsActive() )
     259           0 :             Deactivate(0);
     260           0 :         DELETEX(pAutoDeactivate);
     261             :     }
     262             : 
     263           0 :     if (pItems)
     264             :     {
     265           0 :         delete [] pItems;
     266             :     }
     267             : 
     268           0 :     delete pAppCtrl;
     269           0 :     pBindings = 0;
     270             : 
     271             :     // All the menus, which were created by SV, will also be there deleted
     272             :     // again (i.e. created by loading them from the resource)
     273             :     // The top-level menu is never deleted by SV, since the allocation
     274             :     // in done in the SFX
     275           0 :     if ( !bResCtor || !pParent)
     276             :     {
     277           0 :         if ( pParent )
     278             :         {
     279           0 :             if( pParent->pSVMenu->GetItemPos( nId ) != MENU_ITEM_NOTFOUND )
     280           0 :                 pParent->pSVMenu->SetPopupMenu( nId, 0 );
     281           0 :             if ( pParent->pPickMenu == pSVMenu )
     282           0 :                 pParent->pPickMenu = 0;
     283           0 :             if ( pParent->pWindowMenu == pSVMenu)
     284           0 :                 pParent->pWindowMenu = 0;
     285           0 :             if ( pParent->pAddonsMenu == pSVMenu )
     286           0 :                 pParent->pAddonsMenu = 0;
     287             :         }
     288             : 
     289           0 :         delete pSVMenu;
     290             :     }
     291             : 
     292             :     DBG_OUTF( ("SfxVirtualMenu %lx destroyed", this) );
     293             :     DBG_ASSERT( !nLocks, "destroying active menu" );
     294           0 : }
     295             : //--------------------------------------------------------------------
     296             : // internal: creates the virtual menu from the pSVMenu
     297             : 
     298           0 : void SfxVirtualMenu::CreateFromSVMenu()
     299             : {
     300             :     DBG_CHKTHIS(SfxVirtualMenu, 0);
     301             : 
     302             :     // Merge Addon popup menus into the SV Menu
     303           0 :     SfxViewFrame* pViewFrame = pBindings->GetDispatcher()->GetFrame();
     304           0 :     Reference< com::sun::star::frame::XFrame > xFrame( pViewFrame->GetFrame().GetFrameInterface() );
     305             : 
     306           0 :     if ( pSVMenu->IsMenuBar() )
     307             :     {
     308           0 :         sal_uInt16 nPos = pSVMenu->GetItemPos( SID_MDIWINDOWLIST );
     309           0 :         if ( nPos != MENU_ITEM_NOTFOUND && xFrame.is() )
     310             :         {
     311             :             // Retrieve addon popup menus and add them to our menu bar
     312           0 :             Reference< com::sun::star::frame::XModel >      xModel;
     313           0 :             Reference< com::sun::star::frame::XController > xController( xFrame->getController(), UNO_QUERY );
     314           0 :             if ( xController.is() )
     315           0 :                 xModel = Reference< com::sun::star::frame::XModel >( xController->getModel(), UNO_QUERY );
     316           0 :             framework::AddonMenuManager::MergeAddonPopupMenus( xFrame, xModel, nPos, (MenuBar *)pSVMenu );
     317             :         }
     318             : 
     319             :         // Merge the Add-Ons help menu items into the Office help menu
     320           0 :         if ( xFrame.is() )
     321           0 :             framework::AddonMenuManager::MergeAddonHelpMenu( xFrame, (MenuBar *)pSVMenu );
     322             : 
     323             :         // Set addon menu pointer here to avoid problems. When accessibility is enabled, the whole menu
     324             :         // is created immediately!
     325           0 :         pAddonsMenu = pSVMenu->GetPopupMenu( SID_ADDONLIST );
     326             :     }
     327           0 :     else if ( pParent )
     328             :     {
     329           0 :         if ( pSVMenu == pParent->pAddonsMenu &&
     330           0 :              framework::AddonsOptions().HasAddonsMenu() &&
     331           0 :              !pSVMenu->GetPopupMenu( SID_ADDONS ) )
     332             :         {
     333             :             // Create menu item at the end of the tools popup menu for the addons popup menu
     334           0 :             InsertAddOnsMenuItem( pSVMenu );
     335             :         }
     336             :     }
     337             : 
     338             :     // get and store the number of items
     339           0 :     nCount = pSVMenu->GetItemCount();
     340             : 
     341             :     // Note: only this time it is guaranteed that nCount and the ItemCount
     342             :     // the SV-menus match; later on the SvMenu can have more entries
     343             :     // (Pick list!)
     344           0 :     if (nCount)
     345           0 :         pItems = new SfxMenuControl[nCount];
     346             : 
     347             :     // remember some values
     348           0 :     SFX_APP();
     349           0 :     const int bOleServer = sal_False;
     350           0 :     const int bMac = sal_False;
     351           0 :     SvtMenuOptions aOptions;
     352           0 :     aOptions.AddListenerLink( LINK( this, SfxVirtualMenu, SettingsChanged ) );
     353             : 
     354             :     // iterate through the items
     355           0 :     pBindings->ENTERREGISTRATIONS(); ++nLocks;
     356           0 :     pImageControl = new SfxMenuImageControl_Impl( SID_IMAGE_ORIENTATION, *pBindings, this );
     357             : 
     358           0 :     sal_uInt16 nSVPos = 0;
     359           0 :     for ( sal_uInt16 nPos=0; nPos<nCount; ++nPos, ++nSVPos )
     360             :     {
     361           0 :         sal_uInt16 nSlotId = pSVMenu->GetItemId(nSVPos);
     362           0 :         PopupMenu* pPopup = pSVMenu->GetPopupMenu(nSlotId);
     363           0 :         if( pPopup && nSlotId >= SID_OBJECTMENU0 && nSlotId <= SID_OBJECTMENU_LAST )
     364             :         {
     365             :             // artefact in XML menuconfig: every entry in root menu must have a popup!
     366           0 :             pSVMenu->SetPopupMenu( nSlotId, NULL );
     367           0 :             DELETEZ( pPopup );
     368             :         }
     369             : 
     370           0 :         const String sItemText = pSVMenu->GetItemText(nSlotId);
     371             : 
     372           0 :         if ( pPopup )
     373             :         {
     374             : 
     375             :             SfxMenuControl *pMnuCtrl =
     376           0 :                 SfxMenuControl::CreateControl(nSlotId, *pPopup, *pBindings);
     377             : 
     378           0 :             if ( pMnuCtrl )
     379             :             {
     380             :                 // The pop was obviously not "real" and such are never loaded
     381             :                 // from the resource and need thus to be explicitly deleted.
     382           0 :                 if ( pSVMenu->GetPopupMenu( nSlotId ) == pPopup )
     383           0 :                     pSVMenu->SetPopupMenu( nSlotId, NULL );
     384           0 :                 delete pPopup;
     385           0 :                 pPopup = 0;
     386             : 
     387           0 :                 SfxMenuCtrlArr_Impl &rCtrlArr = GetAppCtrl_Impl();
     388           0 :                 rCtrlArr.push_back(pMnuCtrl);
     389           0 :                 (pItems+nPos)->Bind( 0, nSlotId, sItemText, *pBindings);
     390           0 :                 pMnuCtrl->Bind( this, nSlotId, sItemText, *pBindings);
     391             : 
     392           0 :                 if (  Application::GetSettings().GetStyleSettings().GetUseImagesInMenus() )
     393             :                 {
     394           0 :                     OUString aSlotURL( "slot:" );
     395           0 :                     aSlotURL += OUString::valueOf( sal_Int32( nSlotId ));
     396           0 :                     Image aImage = GetImage( xFrame, aSlotURL, false );
     397           0 :                     pSVMenu->SetItemImage( nSlotId, aImage );
     398             :                 }
     399             :             }
     400             :             else
     401             :             {
     402           0 :                 pMnuCtrl = pItems+nPos;
     403             : 
     404             :                 // Normally only now in Activate-Handler
     405           0 :                 if ( bOLE )
     406             :                 {
     407             :                     pMnuCtrl->Bind( this, nSlotId,
     408           0 :                         *new SfxVirtualMenu(nSlotId, this, *pPopup, bHelpInitialized, *pBindings, bOLE, bResCtor),
     409           0 :                         sItemText, *pBindings );
     410             :                 }
     411             :             }
     412             : 
     413           0 :             ++nVisibleItems;
     414             :         }
     415             :         else
     416             :         {
     417           0 :             switch ( pSVMenu->GetItemType(nSVPos) )
     418             :             {
     419             :                 case MENUITEM_STRING:
     420             :                 case MENUITEM_STRINGIMAGE:
     421             :                 {
     422           0 :                     SfxMenuControl *pMnuCtrl=0;
     423           0 :                     String aCmd( pSVMenu->GetItemCommand( nSlotId ) );
     424           0 :                     if ( aCmd.Len() && (( nSlotId < SID_SFX_START ) || ( nSlotId > SHRT_MAX )) )
     425             :                     {
     426             :                         // try to create control via comand name
     427           0 :                         pMnuCtrl = SfxMenuControl::CreateControl( aCmd, nSlotId, *pSVMenu, sItemText, *pBindings, this );
     428           0 :                         if ( pMnuCtrl )
     429             :                         {
     430           0 :                             SfxMenuCtrlArr_Impl &rCtrlArr = GetAppCtrl_Impl();
     431           0 :                             rCtrlArr.push_back(pMnuCtrl);
     432           0 :                             (pItems+nPos)->Bind( 0, nSlotId, sItemText, *pBindings);
     433             :                         }
     434             :                     }
     435             : 
     436           0 :                     if ( !pMnuCtrl )
     437             :                     {
     438             :                         // try to create control via Id
     439           0 :                         pMnuCtrl = SfxMenuControl::CreateControl(nSlotId, *pSVMenu, *pBindings);
     440           0 :                         if ( pMnuCtrl )
     441             :                         {
     442           0 :                             SfxMenuCtrlArr_Impl &rCtrlArr = GetAppCtrl_Impl();
     443           0 :                             rCtrlArr.push_back(pMnuCtrl);
     444           0 :                             (pItems+nPos)->Bind( 0, nSlotId, sItemText, *pBindings);
     445             :                         }
     446             :                         else
     447             :                             // take default control
     448           0 :                             pMnuCtrl = (pItems+nPos);
     449             : 
     450           0 :                         pMnuCtrl->Bind( this, nSlotId, sItemText, *pBindings);
     451             :                     }
     452             : 
     453           0 :                     if ( Application::GetSettings().GetStyleSettings().GetUseImagesInMenus() )
     454             :                     {
     455           0 :                         Image aImage;
     456           0 :                         if ( bIsAddonPopupMenu || framework::AddonMenuManager::IsAddonMenuId( nSlotId ))
     457             :                         {
     458           0 :                             OUString aImageId;
     459             : 
     460             :                             ::framework::MenuConfiguration::Attributes* pMenuAttributes =
     461           0 :                                 (::framework::MenuConfiguration::Attributes*)pSVMenu->GetUserValue( nSlotId );
     462             : 
     463           0 :                             if ( pMenuAttributes )
     464           0 :                                 aImageId = pMenuAttributes->aImageId; // Retrieve image id from menu attributes
     465             : 
     466           0 :                             aImage = RetrieveAddOnImage( xFrame, aImageId, aCmd, false );
     467             :                         }
     468             :                         else
     469             :                         {
     470           0 :                             OUString aSlotURL( "slot:" );
     471           0 :                             aSlotURL += OUString::valueOf( sal_Int32( nSlotId ));
     472           0 :                             aImage = GetImage( xFrame, aSlotURL, false );
     473             :                         }
     474             : 
     475           0 :                         if ( !!aImage )
     476           0 :                             pSVMenu->SetItemImage( nSlotId, aImage );
     477             :                     }
     478             : 
     479           0 :                     if ( !IsItemHidden_Impl(nSlotId, bOleServer, bMac) )
     480           0 :                         ++nVisibleItems;
     481             :                     else
     482           0 :                         pSVMenu->RemoveItem( nSVPos-- );
     483           0 :                     break;
     484             :                 }
     485             : 
     486             :                 case MENUITEM_IMAGE:
     487             :                     //! not implemented
     488           0 :                     break;
     489             : 
     490             :                 case MENUITEM_SEPARATOR:
     491             :                     //! not implemented
     492           0 :                     break;
     493             :                 default:
     494           0 :                     break; // DONTKNOW and STRINGIMAGE not handled.
     495             :             }
     496             :         }
     497           0 :     }
     498           0 :     pBindings->LEAVEREGISTRATIONS(); --nLocks;
     499           0 : }
     500             : 
     501             : //--------------------------------------------------------------------
     502             : 
     503             : // called on activation of the SV-Menu
     504             : 
     505           0 : IMPL_LINK( SfxVirtualMenu, Highlight, Menu *, pMenu )
     506             : {
     507             :     DBG_CHKTHIS(SfxVirtualMenu, 0);
     508             : 
     509             :     // own StarView-Menu
     510           0 :     if ( pMenu == pSVMenu )
     511             :     {
     512             :         // AutoDeactivate is not necessary anymore
     513           0 :         if ( pAutoDeactivate )
     514           0 :             pAutoDeactivate->Stop();
     515             :     }
     516             : 
     517           0 :     return sal_True;
     518             : }
     519             : 
     520           0 : IMPL_LINK_NOARG(SfxVirtualMenu, SettingsChanged)
     521             : {
     522           0 :     sal_uInt16 nItemCount = pSVMenu->GetItemCount();
     523           0 :     SfxViewFrame *pViewFrame = pBindings->GetDispatcher()->GetFrame();
     524           0 :     sal_Bool bIcons = Application::GetSettings().GetStyleSettings().GetUseImagesInMenus();
     525           0 :     Reference<com::sun::star::frame::XFrame> xFrame( pViewFrame->GetFrame().GetFrameInterface() );
     526             : 
     527           0 :     if ( !bIsAddonPopupMenu )
     528             :     {
     529           0 :         for ( sal_uInt16 nSVPos=0; nSVPos<nItemCount; ++nSVPos )
     530             :         {
     531           0 :             sal_uInt16          nSlotId = pSVMenu->GetItemId( nSVPos );
     532           0 :             MenuItemType    nType   = pSVMenu->GetItemType( nSVPos );
     533           0 :             if ( nType == MENUITEM_STRING && bIcons )
     534             :             {
     535           0 :                 if ( framework::AddonMenuManager::IsAddonMenuId( nSlotId ))
     536             :                 {
     537             :                     // Special code for Add-On menu items. They can appear inside the help menu.
     538           0 :                     OUString aCmd( pSVMenu->GetItemCommand( nSlotId ) );
     539           0 :                     OUString aImageId;
     540             : 
     541             :                     ::framework::MenuConfiguration::Attributes* pMenuAttributes =
     542           0 :                         (::framework::MenuConfiguration::Attributes*)pSVMenu->GetUserValue( nSlotId );
     543             : 
     544           0 :                     if ( pMenuAttributes )
     545           0 :                         aImageId = pMenuAttributes->aImageId; // Retrieve image id from menu attributes
     546             : 
     547           0 :                     pSVMenu->SetItemImage( nSlotId, RetrieveAddOnImage( xFrame, aImageId, aCmd, false ));
     548             :                 }
     549             :                 else
     550             :                 {
     551           0 :                     OUString aSlotURL( "slot:" );
     552           0 :                     aSlotURL += OUString::valueOf( sal_Int32( nSlotId ));
     553           0 :                     pSVMenu->SetItemImage( nSlotId, GetImage( xFrame, aSlotURL, false ));
     554           0 :                 }
     555             :             }
     556           0 :             else if( nType == MENUITEM_STRINGIMAGE && !bIcons )
     557             :             {
     558           0 :                 pSVMenu->SetItemImage( nSlotId, Image() );
     559             :             }
     560             :         }
     561             :     }
     562             :     else
     563             :     {
     564             :         // Remove/update images from Add-Ons top-level popup menus when settings have changed
     565           0 :         if ( !bIcons )
     566           0 :             RemoveMenuImages( pSVMenu );
     567             :         else
     568           0 :             UpdateImages( pSVMenu );
     569             :     }
     570             : 
     571             :     // Special code to remove menu images from runtime popup menus when settings have changed
     572           0 :     if ( pParent && pSVMenu == pParent->pAddonsMenu )
     573             :     {
     574           0 :         if ( !bIcons )
     575           0 :             RemoveMenuImages( pParent->pAddonsMenu->GetPopupMenu( SID_ADDONS ));
     576             :         else
     577           0 :             UpdateImages( pParent->pAddonsMenu->GetPopupMenu( SID_ADDONS ));
     578             :     }
     579             : 
     580           0 :     if ( pImageControl )
     581           0 :         pImageControl->Update();
     582             : 
     583           0 :     return 0;
     584             : }
     585             : 
     586             : //--------------------------------------------------------------------
     587             : 
     588           0 : void SfxVirtualMenu::UpdateImages( Menu* pMenu )
     589             : {
     590           0 :     if ( !pMenu )
     591           0 :         return;
     592             : 
     593           0 :     framework::AddonsOptions    aAddonOptions;
     594             : 
     595           0 :     sal_Bool bIcons = Application::GetSettings().GetStyleSettings().GetUseImagesInMenus();
     596           0 :     if ( bIcons )
     597             :     {
     598           0 :         sal_uInt16          nItemCount          = pMenu->GetItemCount();
     599           0 :         Reference<com::sun::star::frame::XFrame> aXFrame( pBindings->GetDispatcher_Impl()->GetFrame()->GetFrame().GetFrameInterface() );
     600             : 
     601           0 :         for ( sal_uInt16 nPos=0; nPos < nItemCount; ++nPos )
     602             :         {
     603           0 :             sal_uInt16 nSlotId = pMenu->GetItemId( nPos );
     604           0 :             PopupMenu* pPopup = pMenu->GetPopupMenu( nSlotId );
     605           0 :             if ( pMenu->GetItemType( nPos ) != MENUITEM_SEPARATOR )
     606             :             {
     607           0 :                 OUString aImageId;
     608             : 
     609             :                 ::framework::MenuConfiguration::Attributes* pMenuAttributes =
     610           0 :                     (::framework::MenuConfiguration::Attributes*)pMenu->GetUserValue( nSlotId );
     611             : 
     612           0 :                 if ( pMenuAttributes )
     613           0 :                     aImageId = pMenuAttributes->aImageId; // Retrieve image id from menu attributes
     614             : 
     615           0 :                 pMenu->SetItemImage( nSlotId, RetrieveAddOnImage( aXFrame, aImageId, pMenu->GetItemCommand( nSlotId ), false ));
     616             :             }
     617             : 
     618           0 :             if ( pPopup )
     619           0 :                 UpdateImages( pPopup );
     620             :         }
     621             : 
     622           0 :         if ( pImageControl )
     623           0 :             pImageControl->Update();
     624           0 :     }
     625             : }
     626             : 
     627             : //--------------------------------------------------------------------
     628             : 
     629           0 : void SfxVirtualMenu::RemoveMenuImages( Menu* pMenu )
     630             : {
     631           0 :     if ( !pMenu )
     632           0 :         return;
     633             : 
     634           0 :     sal_uInt16 nItemCount = pMenu->GetItemCount();
     635           0 :     for ( sal_uInt16 nPos=0; nPos < nItemCount; ++nPos )
     636             :     {
     637           0 :         sal_uInt16 nSlotId = pMenu->GetItemId( nPos );
     638           0 :         PopupMenu* pPopup = pMenu->GetPopupMenu( nSlotId );
     639           0 :         if ( pMenu->GetItemType( nPos ) == MENUITEM_STRINGIMAGE )
     640           0 :             pMenu->SetItemImage( nSlotId, Image() );
     641           0 :         if ( pPopup )
     642           0 :             RemoveMenuImages( pPopup );
     643             :     }
     644             : }
     645             : 
     646             : //--------------------------------------------------------------------
     647             : 
     648           0 : bool SfxVirtualMenu::Bind_Impl( Menu *pMenu )
     649             : {
     650             :     // Search , as SV with 'sal_uInt16 nSID = pSVMenu->GetCurItemId();' always
     651             :     // returns 0. It is like this, since the Event-Forwarding has nothing to do
     652             :     // with the Parent-Menus CurItem.
     653           0 :     sal_uInt32 nAddonsPopupPrefixLen = ADDONSPOPUPMENU_URL_PREFIX.getLength();
     654             : 
     655           0 :     for ( sal_uInt16 nPos = 0; nPos < nCount; ++nPos )
     656             :     {
     657             :         // found the Sub-Menu in question?
     658           0 :         bool bFound = false;
     659           0 :         sal_uInt16 nSID = pSVMenu->GetItemId(nPos);
     660           0 :         SfxMenuControl &rCtrl = pItems[nPos];
     661           0 :         bFound = pSVMenu->GetPopupMenu(nSID) == pMenu;
     662           0 :         SfxVirtualMenu *pSubMenu = rCtrl.GetPopupMenu();
     663             : 
     664           0 :         if ( bFound )
     665             :         {
     666             :             // Only a binded Menu-Controller as already an Id!
     667           0 :             if ( !rCtrl.GetId() )
     668             :             {
     669           0 :                 bIsAddonPopupMenu = sal_False;
     670             :                 DBG_ASSERT( !pSubMenu, "Popup already exists!");
     671             : 
     672             :                 // Check if the popup is an Add-On popup menu
     673             :                 // Either the popup menu has a special ID  or a special command URL prefix!
     674           0 :                 OUString aCommand = pSVMenu->GetItemCommand( nSID );
     675           0 :                 if ( ( nSID == SID_ADDONS ) ||
     676           0 :                      ( nSID == SID_ADDONHELP ) ||
     677           0 :                      (( (sal_uInt32)aCommand.getLength() > nAddonsPopupPrefixLen ) &&
     678           0 :                       ( aCommand.indexOf( ADDONSPOPUPMENU_URL_PREFIX ) == 0 )) )
     679           0 :                     bIsAddonPopupMenu = sal_True;
     680             : 
     681             :                 // Create VirtualMenu for Sub-Menu
     682           0 :                 sal_Bool bRes = bResCtor;
     683             :                 pSubMenu = new SfxVirtualMenu( nSID, this,
     684           0 :                         *pMenu, sal_False, *pBindings, bOLE, bRes, bIsAddonPopupMenu );
     685             : 
     686             :                 DBG_OUTF( ("New VirtualMenu %lx created", pSubMenu) );
     687             : 
     688           0 :                 rCtrl.Bind( this, nSID, *pSubMenu, pSVMenu->GetItemText(nSID), *pBindings );
     689             : 
     690             :                 // Forward Activate
     691           0 :                 pSubMenu->Bind_Impl( pMenu );
     692           0 :                 pSubMenu->Activate( pMenu );
     693             :             }
     694             :         }
     695             : 
     696             :         // continue searching recursively (SV Activate only the menu itself
     697             :         // and Top-Menu)
     698           0 :         if ( !bFound && pSubMenu )
     699           0 :             bFound = pSubMenu->Bind_Impl( pMenu );
     700             : 
     701             :         // If found, break
     702           0 :         if ( bFound )
     703           0 :             return true;
     704             :     }
     705             : 
     706             :     // Not found in this submenu
     707           0 :     return false;
     708             : }
     709             : 
     710           0 : void SfxVirtualMenu::BindControllers()
     711             : {
     712           0 :     pBindings->ENTERREGISTRATIONS();
     713             : 
     714             :     sal_uInt16 nPos;
     715           0 :     for ( nPos = 0; nPos < nCount; ++nPos )
     716             :     {
     717           0 :         SfxMenuControl& rCtrl = pItems[nPos];
     718           0 :         if ( rCtrl.IsBindable_Impl() && !rCtrl.GetPopupMenu() )
     719           0 :             rCtrl.ReBind();
     720             :     }
     721             : 
     722           0 :     SfxMenuCtrlArr_Impl& rCtrlArr = GetAppCtrl_Impl();
     723           0 :     for (SfxMenuCtrlArr_Impl::iterator i = rCtrlArr.begin();
     724           0 :             i != rCtrlArr.end(); ++i)
     725             :     {
     726           0 :         sal_uInt16 nSlotId = i->GetId();
     727           0 :         if ( !pSVMenu->GetItemCommand(nSlotId).Len() )
     728             :         {
     729           0 :             i->ReBind();
     730             :         }
     731             :     }
     732             : 
     733           0 :     pBindings->LEAVEREGISTRATIONS();
     734           0 :     bControllersUnBound = sal_False;
     735           0 : }
     736             : 
     737           0 : void SfxVirtualMenu::UnbindControllers()
     738             : {
     739           0 :     pBindings->ENTERREGISTRATIONS();
     740             : 
     741             :     sal_uInt16 nPos;
     742           0 :     for ( nPos = 0; nPos < nCount; ++nPos )
     743             :     {
     744           0 :         SfxMenuControl &rCtrl = pItems[nPos];
     745           0 :         if ( rCtrl.IsBound() )
     746           0 :             rCtrl.UnBind();
     747             :     }
     748             : 
     749           0 :     SfxMenuCtrlArr_Impl& rCtrlArr = GetAppCtrl_Impl();
     750           0 :     for (SfxMenuCtrlArr_Impl::iterator i = rCtrlArr.begin();
     751           0 :             i != rCtrlArr.end(); ++i)
     752             :     {
     753           0 :         if (i->IsBound())
     754             :         {
     755             :             // UnoController is not bound!
     756           0 :             i->UnBind();
     757             :         }
     758             :     }
     759             : 
     760           0 :     pBindings->LEAVEREGISTRATIONS();
     761           0 :     bControllersUnBound = sal_True;
     762           0 : }
     763             : 
     764             : 
     765             : //--------------------------------------------------------------------
     766           0 : void SfxVirtualMenu::InsertAddOnsMenuItem( Menu* pMenu )
     767             : {
     768             :     // Create special popup menu that is filled with the 3rd party components popup menu items
     769           0 :     ::framework::MenuConfiguration aConf( ::comphelper::getProcessComponentContext() );
     770           0 :     Reference<com::sun::star::frame::XFrame> xFrame( pBindings->GetDispatcher_Impl()->GetFrame()->GetFrame().GetFrameInterface() );
     771             : 
     772           0 :     PopupMenu* pAddonMenu = NULL;
     773             :     try
     774             :     {
     775           0 :         pAddonMenu = framework::AddonMenuManager::CreateAddonMenu( xFrame );
     776             :     }
     777           0 :     catch ( const ::com::sun::star::lang::WrappedTargetException& )
     778             :     {
     779             :     }
     780             : 
     781             :     // Create menu item at the end of the tools popup menu for the addons popup menu
     782           0 :     if ( pAddonMenu && pAddonMenu->GetItemCount() > 0 )
     783             :     {
     784           0 :         sal_uInt16 nItemCount = pMenu->GetItemCount();
     785           0 :         OUString aAddonsTitle(SfxResId(STR_MENU_ADDONS).toString());
     786           0 :         if ( nItemCount > 0 && pMenu->GetItemType( nItemCount-1 ) != MENUITEM_SEPARATOR )
     787           0 :             pMenu->InsertSeparator();
     788           0 :         pMenu->InsertItem( SID_ADDONS, aAddonsTitle );
     789           0 :         pMenu->SetPopupMenu( SID_ADDONS, pAddonMenu );
     790             : 
     791           0 :         if ( Application::GetSettings().GetStyleSettings().GetUseImagesInMenus() )
     792             :         {
     793           0 :                OUString aSlotURL( "slot:" );
     794           0 :                aSlotURL += OUString::valueOf( sal_Int32( SID_ADDONS ));
     795           0 :          pMenu->SetItemImage( SID_ADDONS, GetImage( xFrame, aSlotURL, false ));
     796           0 :         }
     797             :     }
     798             :     else
     799           0 :         delete pAddonMenu;
     800           0 : }
     801             : 
     802             : //--------------------------------------------------------------------
     803             : 
     804             : // called on activation of the SV-Menu
     805             : 
     806           0 : IMPL_LINK( SfxVirtualMenu, Activate, Menu *, pMenu )
     807             : {
     808             :     DBG_CHKTHIS(SfxVirtualMenu, 0);
     809             :     DBG_OUTF( ("SfxVirtualMenu %lx activated %lx, own %lx", this, pMenu, pSVMenu));
     810             : 
     811             :     // MI: for what was it still good for?
     812             :     // MBA: seemes to be an old QAP-Hack( checked-in in rev.1.41  ! )
     813             : 
     814           0 :     if ( pMenu )
     815             :     {
     816           0 :         sal_Bool bDontHide = SvtMenuOptions().IsEntryHidingEnabled();
     817           0 :         sal_uInt16 nFlag = pMenu->GetMenuFlags();
     818           0 :         if ( bDontHide )
     819           0 :             nFlag &= ~MENU_FLAG_HIDEDISABLEDENTRIES;
     820             :         else
     821           0 :             nFlag |= MENU_FLAG_HIDEDISABLEDENTRIES;
     822           0 :         pMenu->SetMenuFlags( nFlag );
     823             :     }
     824             : 
     825             :     // Own StarView-Menu
     826           0 :     if ( pMenu == pSVMenu )
     827             :     {
     828             :         // Prevent Double Activate
     829           0 :         if ( bIsActive )
     830           0 :             return sal_True;
     831             : 
     832             :         // ggf. Pick-Menu erzeugen
     833           0 :         if ( pParent && pSVMenu == pParent->pPickMenu )
     834             :         {
     835           0 :             SfxPickList::Get().CreateMenuEntries( pParent->pPickMenu );
     836             :         }
     837             :         else
     838           0 :             pPickMenu = pSVMenu->GetPopupMenu(SID_PICKLIST);
     839             : 
     840           0 :         if ( pParent && pSVMenu == pParent->pWindowMenu )
     841             :         {
     842             :             // update window list
     843           0 :             ::std::vector< OUString > aNewWindowListVector;
     844           0 :             Reference< XDesktop2 > xDesktop = Desktop::create( ::comphelper::getProcessComponentContext() );;
     845             : 
     846           0 :             sal_uInt16  nActiveItemId = 0;
     847           0 :             sal_uInt16  nItemId = START_ITEMID_WINDOWLIST;
     848             : 
     849           0 :             Reference< XFrame > xCurrentFrame = xDesktop->getCurrentFrame();
     850           0 :             Reference< XIndexAccess > xList ( xDesktop->getFrames(), UNO_QUERY );
     851           0 :             sal_Int32 nFrameCount = xList->getCount();
     852           0 :             for( sal_Int32 i=0; i<nFrameCount; ++i )
     853             :             {
     854           0 :                 Reference< XFrame > xFrame;
     855           0 :                 Any aVal = xList->getByIndex(i);
     856           0 :                 if (!(aVal>>=xFrame) || !xFrame.is() )
     857           0 :                     continue;
     858             : 
     859           0 :                 if ( xFrame == xCurrentFrame )
     860           0 :                     nActiveItemId = nItemId;
     861             : 
     862           0 :                 Window* pWin = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
     863           0 :                 if ( pWin && pWin->IsVisible() )
     864             :                 {
     865           0 :                     aNewWindowListVector.push_back( pWin->GetText() );
     866           0 :                     ++nItemId;
     867             :                 }
     868           0 :             }
     869             : 
     870           0 :             int nItemCount       = pMenu->GetItemCount();
     871             : 
     872           0 :             if ( nItemCount > 0 )
     873             :             {
     874             :                 // remove all old window list entries from menu
     875           0 :                 sal_uInt16 nPos = pMenu->GetItemPos( START_ITEMID_WINDOWLIST );
     876           0 :                 for ( sal_uInt16 n = nPos; n < pMenu->GetItemCount(); )
     877           0 :                     pMenu->RemoveItem( n );
     878             : 
     879           0 :                 if ( pMenu->GetItemType( pMenu->GetItemCount()-1 ) == MENUITEM_SEPARATOR )
     880           0 :                     pMenu->RemoveItem( pMenu->GetItemCount()-1 );
     881             :             }
     882             : 
     883           0 :             if ( aNewWindowListVector.size() > 0 )
     884             :             {
     885             :                 // append new window list entries to menu
     886           0 :                 pMenu->InsertSeparator();
     887           0 :                 nItemId = START_ITEMID_WINDOWLIST;
     888           0 :                 for ( sal_uInt32 i = 0; i < aNewWindowListVector.size(); i++ )
     889             :                 {
     890           0 :                     pMenu->InsertItem( nItemId, aNewWindowListVector.at( i ), MIB_RADIOCHECK );
     891           0 :                     if ( nItemId == nActiveItemId )
     892           0 :                         pMenu->CheckItem( nItemId );
     893           0 :                     ++nItemId;
     894             :                 }
     895           0 :             }
     896             :         }
     897             :         else
     898           0 :             pWindowMenu = pSVMenu->GetPopupMenu(SID_MDIWINDOWLIST);
     899             : 
     900           0 :         if ( !pParent && pSVMenu->IsMenuBar() && !pAddonsMenu )
     901             :         {
     902             :             // Store Add-Ons parents of our runtime menu items
     903           0 :             pAddonsMenu = pSVMenu->GetPopupMenu( SID_ADDONLIST );
     904             :         }
     905             : 
     906             :         // Provides consistency to the Status
     907           0 :         if ( bControllersUnBound )
     908           0 :             BindControllers();
     909             : 
     910           0 :         pBindings->GetDispatcher_Impl()->Flush();
     911           0 :         for ( sal_uInt16 nPos = 0; nPos < nCount; ++nPos )
     912             :         {
     913           0 :             sal_uInt16 nSlotId = (pItems+nPos)->GetId();
     914           0 :             if ( nSlotId && nSlotId > END_ITEMID_WINDOWLIST )
     915           0 :                 pBindings->Update(nSlotId);
     916             :         }
     917             : 
     918           0 :         pBindings->Update( SID_IMAGE_ORIENTATION );
     919             : 
     920             :         // Supress the Status updates until Deactivate
     921           0 :         pBindings->ENTERREGISTRATIONS(); ++nLocks; bIsActive = sal_True;
     922             : 
     923           0 :         if ( pAutoDeactivate ) // QAP-Hack
     924           0 :             pAutoDeactivate->Start();
     925             : 
     926           0 :         return sal_True;
     927             :     }
     928             :     else
     929             :     {
     930             :         // Find the VirtualMenu for the SubMenu and if possible, bind a
     931             :         // VirtualMenu
     932           0 :         bool bRet = Bind_Impl( pMenu );
     933             : #ifdef DBG_UTIL
     934             :         if ( !bRet)
     935             :             DBG_WARNING( "W1: Virtual menu could not be created!" );
     936             : #endif
     937           0 :         return bRet;
     938             :     }
     939             : }
     940             : 
     941             : //--------------------------------------------------------------------
     942             : 
     943           0 : IMPL_LINK( SfxVirtualMenu, Deactivate, Menu *, pMenu )
     944             : {
     945             :     DBG_OUTF( ("SfxVirtualMenu %lx deactivated %lx, own %lx", this, pMenu, pSVMenu) );
     946           0 :     if ( bIsActive && ( 0 == pMenu || pMenu == pSVMenu ) )
     947             :     {
     948           0 :         if ( pAutoDeactivate )
     949           0 :             pAutoDeactivate->Stop();
     950             : 
     951             :         // All controllers can be unbinded all the way up to the Menubar,
     952             :         // when the menu is disabled (= closed)
     953           0 :         if ( pParent )
     954           0 :             UnbindControllers();
     955           0 :         pBindings->LEAVEREGISTRATIONS(); --nLocks; bIsActive = sal_False;
     956             :     }
     957           0 :     return sal_True;
     958             : }
     959             : //--------------------------------------------------------------------
     960             : 
     961             : // called on activation of the SV-Menu
     962             : 
     963           0 : IMPL_LINK( SfxVirtualMenu, Select, Menu *, pMenu )
     964             : {
     965           0 :     sal_uInt16 nSlotId = (sal_uInt16) pMenu->GetCurItemId();
     966             :     DBG_OUTF( ("SfxVirtualMenu %lx selected %u from %lx", this, nSlotId, pMenu) );
     967             : 
     968           0 :     if ( nSlotId >= START_ITEMID_WINDOWLIST && nSlotId <= END_ITEMID_WINDOWLIST )
     969             :     {
     970             :         // window list menu item selected
     971           0 :         Reference< XDesktop2 > xDesktop = Desktop::create( ::comphelper::getProcessComponentContext() );
     972           0 :         sal_uInt16 nTaskId = START_ITEMID_WINDOWLIST;
     973           0 :         Reference< XIndexAccess > xList( xDesktop->getFrames(), UNO_QUERY );
     974           0 :         sal_Int32 nFrameCount = xList->getCount();
     975           0 :         for ( sal_Int32 i=0; i<nFrameCount; ++i )
     976             :         {
     977           0 :             Any aItem = xList->getByIndex(i);
     978           0 :             Reference< XFrame > xFrame;
     979           0 :             if (( aItem >>= xFrame ) && xFrame.is() && nTaskId == nSlotId )
     980             :             {
     981           0 :                 Window* pWin = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
     982           0 :                 pWin->GrabFocus();
     983           0 :                 pWin->ToTop( TOTOP_RESTOREWHENMIN );
     984           0 :                 break;
     985             :             }
     986             : 
     987           0 :             nTaskId++;
     988           0 :         }
     989             : 
     990           0 :         return sal_True;
     991             :     }
     992           0 :     else if ( nSlotId >= START_ITEMID_PICKLIST && nSlotId <= END_ITEMID_PICKLIST )
     993             :     {
     994           0 :         SfxPickList::Get().ExecuteMenuEntry( nSlotId );
     995           0 :         return sal_True;
     996             :     }
     997             : 
     998           0 :     if ( pMenu->GetItemCommand( nSlotId ).Len() )
     999           0 :         pBindings->ExecuteCommand_Impl( pMenu->GetItemCommand( nSlotId ) );
    1000             :     else
    1001           0 :         pBindings->Execute( nSlotId );
    1002             : 
    1003           0 :     return sal_True;
    1004             : }
    1005             : 
    1006             : //--------------------------------------------------------------------
    1007             : 
    1008             : // returns the associated StarView-menu
    1009             : 
    1010           0 : Menu* SfxVirtualMenu::GetSVMenu() const
    1011             : {
    1012             :     DBG_CHKTHIS(SfxVirtualMenu, 0);
    1013             : 
    1014           0 :     return pSVMenu;
    1015             : }
    1016             : 
    1017             : //--------------------------------------------------------------------
    1018             : 
    1019             : // set the checkmark of the specified item
    1020             : 
    1021           0 : void SfxVirtualMenu::CheckItem( sal_uInt16 nItemId, sal_Bool bCheck )
    1022             : {
    1023             :     DBG_CHKTHIS(SfxVirtualMenu, 0);
    1024             :     DBG_ASSERT( this != 0, "");
    1025             :     DBG_ASSERT( pSVMenu != 0, "" );
    1026           0 :     if (pSVMenu->GetItemPos( nItemId ) != MENU_ITEM_NOTFOUND )
    1027           0 :         pSVMenu->CheckItem( nItemId, bCheck );
    1028           0 : }
    1029             : //--------------------------------------------------------------------
    1030             : 
    1031             : // set the enabled-state of the specified item
    1032             : 
    1033           0 : void SfxVirtualMenu::EnableItem( sal_uInt16 nItemId, sal_Bool bEnable )
    1034             : {
    1035             :     DBG_CHKTHIS(SfxVirtualMenu, 0);
    1036             :     DBG_ASSERT( this != 0, "");
    1037             :     DBG_ASSERT( pSVMenu != 0, "" );
    1038             : 
    1039           0 :     if (pSVMenu->GetItemPos( nItemId ) != MENU_ITEM_NOTFOUND )
    1040           0 :         pSVMenu->EnableItem( nItemId, bEnable );
    1041           0 : }
    1042             : //--------------------------------------------------------------------
    1043             : 
    1044             : // set the text of the specified item
    1045             : 
    1046           0 : void SfxVirtualMenu::SetItemText( sal_uInt16 nItemId, const String& rText )
    1047             : {
    1048             :     DBG_CHKTHIS(SfxVirtualMenu, 0);
    1049             :     DBG_ASSERT( this != 0, "");
    1050             :     DBG_ASSERT( pSVMenu != 0, "" );
    1051           0 :     if (pSVMenu->GetItemPos( nItemId ) != MENU_ITEM_NOTFOUND )
    1052           0 :         pSVMenu->SetItemText( nItemId, rText );
    1053           0 : }
    1054             : 
    1055             : //--------------------------------------------------------------------
    1056             : 
    1057             : 
    1058           0 : void SfxVirtualMenu::SetPopupMenu( sal_uInt16 nItemId, PopupMenu *pMenu )
    1059             : {
    1060             :     DBG_CHKTHIS(SfxVirtualMenu, 0);
    1061             : 
    1062           0 :     if (pSVMenu->GetItemPos( nItemId ) != MENU_ITEM_NOTFOUND )
    1063           0 :         GetSVMenu()->SetPopupMenu( nItemId, pMenu );
    1064           0 :     for ( sal_uInt16 n = 0; n < nCount; ++n )
    1065             :     {
    1066           0 :         SfxVirtualMenu *pSubMenu = (pItems+n)->GetPopupMenu();
    1067           0 :         if ( pSubMenu )
    1068           0 :             pSubMenu->SetPopupMenu( nItemId, pMenu );
    1069             :     }
    1070           0 : }
    1071             : 
    1072             : //--------------------------------------------------------------------
    1073             : 
    1074             : // Forces the initialization, which is otherwise only happens in Activate
    1075             : 
    1076           0 : void SfxVirtualMenu::InitPopup( sal_uInt16 nPos, sal_Bool /*bOLE*/ )
    1077             : {
    1078             :     DBG_CHKTHIS(SfxVirtualMenu, 0);
    1079             : 
    1080           0 :     sal_uInt16 nSID = pSVMenu->GetItemId(nPos);
    1081           0 :     PopupMenu *pMenu = pSVMenu->GetPopupMenu( nSID );
    1082             : 
    1083             :     DBG_ASSERT( pMenu, "No popup exist here!");
    1084             : 
    1085           0 :     SfxMenuControl &rCtrl = pItems[nPos];
    1086           0 :     if ( !rCtrl.GetId() )
    1087             :     {
    1088             :         // Generate VirtualMenu for Sub-Menu
    1089           0 :         sal_Bool bRes = bResCtor;
    1090             :         SfxVirtualMenu *pSubMenu =
    1091           0 :             new SfxVirtualMenu(nSID, this, *pMenu, sal_False, *pBindings, bOLE, bRes);
    1092             : 
    1093             :         DBG_OUTF( ("New VirtualMenu %lx created", pSubMenu) );
    1094             : 
    1095           0 :         rCtrl.Bind( this, nSID, *pSubMenu, pSVMenu->GetItemText(nSID), *pBindings );
    1096             :     }
    1097           0 : }
    1098             : 
    1099           0 : void SfxVirtualMenu::InitializeHelp()
    1100             : {
    1101           0 :     for ( sal_uInt16 nPos = 0; nPos<pSVMenu->GetItemCount(); ++nPos )
    1102             :     {
    1103           0 :         sal_uInt16 nSlotId = pSVMenu->GetItemId(nPos);
    1104           0 :         SfxMenuControl &rCtrl = pItems[nPos];
    1105           0 :         if ( nSlotId && !rCtrl.GetId() )
    1106             :         {
    1107           0 :             InitPopup( nPos, sal_True );
    1108             :         }
    1109             : 
    1110           0 :         SfxVirtualMenu *pSubMenu = rCtrl.GetPopupMenu();
    1111           0 :         if ( pSubMenu )
    1112           0 :             pSubMenu->InitializeHelp();
    1113             :     }
    1114             : 
    1115           0 :     bHelpInitialized = sal_True;
    1116         408 : }
    1117             : 
    1118             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10