LCOV - code coverage report
Current view: top level - libreoffice/sfx2/source/menu - virtmenu.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 492 0.0 %
Date: 2012-12-27 Functions: 0 35 0.0 %
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/unohlp.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 rtl::OUString& aImageId,
     116             :                                  const rtl::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             :     return ( bMac &&
     146             :              ( nItemId == SID_MINIMIZED ) ) ||
     147             :            (  bOleServer &&
     148             :              ( nItemId == SID_QUITAPP || nItemId == SID_SAVEDOC ||
     149             :                nItemId == SID_OPENDOC || nItemId == SID_SAVEASDOC ||
     150             :                nItemId == SID_NEWDOC ) ) ||
     151             :            ( !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 :                     rtl::OUString aSlotURL( RTL_CONSTASCII_USTRINGPARAM( "slot:" ));
     395           0 :                     aSlotURL += rtl::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 :                             rtl::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 :                             rtl::OUString aSlotURL( RTL_CONSTASCII_USTRINGPARAM( "slot:" ));
     471           0 :                             aSlotURL += rtl::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 :                     rtl::OUString aCmd( pSVMenu->GetItemCommand( nSlotId ) );
     539           0 :                     rtl::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 :                     rtl::OUString aSlotURL( RTL_CONSTASCII_USTRINGPARAM( "slot:" ));
     552           0 :                     aSlotURL += rtl::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 :                 rtl::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 :                 rtl::OUString aCommand = pSVMenu->GetItemCommand( nSID );
     675           0 :                 if ( ( nSID == SID_ADDONS ) ||
     676             :                      ( 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 :     Reference<com::sun::star::lang::XMultiServiceFactory> aXMultiServiceFactory(::comphelper::getProcessServiceFactory());
     770           0 :     ::framework::MenuConfiguration aConf( aXMultiServiceFactory );
     771           0 :     Reference<com::sun::star::frame::XFrame> xFrame( pBindings->GetDispatcher_Impl()->GetFrame()->GetFrame().GetFrameInterface() );
     772             : 
     773           0 :     PopupMenu* pAddonMenu = NULL;
     774             :     try
     775             :     {
     776           0 :         pAddonMenu = framework::AddonMenuManager::CreateAddonMenu( xFrame );
     777             :     }
     778           0 :     catch ( const ::com::sun::star::lang::WrappedTargetException& )
     779             :     {
     780             :     }
     781             : 
     782             :     // Create menu item at the end of the tools popup menu for the addons popup menu
     783           0 :     if ( pAddonMenu && pAddonMenu->GetItemCount() > 0 )
     784             :     {
     785           0 :         sal_uInt16 nItemCount = pMenu->GetItemCount();
     786           0 :         rtl::OUString aAddonsTitle(SfxResId(STR_MENU_ADDONS).toString());
     787           0 :         if ( nItemCount > 0 && pMenu->GetItemType( nItemCount-1 ) != MENUITEM_SEPARATOR )
     788           0 :             pMenu->InsertSeparator();
     789           0 :         pMenu->InsertItem( SID_ADDONS, aAddonsTitle );
     790           0 :         pMenu->SetPopupMenu( SID_ADDONS, pAddonMenu );
     791             : 
     792           0 :         if ( Application::GetSettings().GetStyleSettings().GetUseImagesInMenus() )
     793             :         {
     794           0 :                rtl::OUString aSlotURL( RTL_CONSTASCII_USTRINGPARAM( "slot:" ));
     795           0 :                aSlotURL += rtl::OUString::valueOf( sal_Int32( SID_ADDONS ));
     796           0 :          pMenu->SetItemImage( SID_ADDONS, GetImage( xFrame, aSlotURL, false ));
     797           0 :         }
     798             :     }
     799             :     else
     800           0 :         delete pAddonMenu;
     801           0 : }
     802             : 
     803             : //--------------------------------------------------------------------
     804             : 
     805             : // called on activation of the SV-Menu
     806             : 
     807           0 : IMPL_LINK( SfxVirtualMenu, Activate, Menu *, pMenu )
     808             : {
     809             :     DBG_CHKTHIS(SfxVirtualMenu, 0);
     810             :     DBG_OUTF( ("SfxVirtualMenu %lx activated %lx, own %lx", this, pMenu, pSVMenu));
     811             : 
     812             :     // MI: for what was it still good for?
     813             :     // MBA: seemes to be an old QAP-Hack( checked-in in rev.1.41  ! )
     814             : 
     815           0 :     if ( pMenu )
     816             :     {
     817           0 :         sal_Bool bDontHide = SvtMenuOptions().IsEntryHidingEnabled();
     818           0 :         sal_uInt16 nFlag = pMenu->GetMenuFlags();
     819           0 :         if ( bDontHide )
     820           0 :             nFlag &= ~MENU_FLAG_HIDEDISABLEDENTRIES;
     821             :         else
     822           0 :             nFlag |= MENU_FLAG_HIDEDISABLEDENTRIES;
     823           0 :         pMenu->SetMenuFlags( nFlag );
     824             :     }
     825             : 
     826             :     // Own StarView-Menu
     827           0 :     if ( pMenu == pSVMenu )
     828             :     {
     829             :         // Prevent Double Activate
     830           0 :         if ( bIsActive )
     831           0 :             return sal_True;
     832             : 
     833             :         // ggf. Pick-Menu erzeugen
     834           0 :         if ( pParent && pSVMenu == pParent->pPickMenu )
     835             :         {
     836           0 :             SfxPickList::Get().CreateMenuEntries( pParent->pPickMenu );
     837             :         }
     838             :         else
     839           0 :             pPickMenu = pSVMenu->GetPopupMenu(SID_PICKLIST);
     840             : 
     841           0 :         if ( pParent && pSVMenu == pParent->pWindowMenu )
     842             :         {
     843             :             // update window list
     844           0 :             ::std::vector< ::rtl::OUString > aNewWindowListVector;
     845           0 :             Reference< XDesktop2 > xDesktop = Desktop::create( ::comphelper::getProcessComponentContext() );;
     846             : 
     847           0 :             sal_uInt16  nActiveItemId = 0;
     848           0 :             sal_uInt16  nItemId = START_ITEMID_WINDOWLIST;
     849             : 
     850           0 :             Reference< XFrame > xCurrentFrame = xDesktop->getCurrentFrame();
     851           0 :             Reference< XIndexAccess > xList ( xDesktop->getFrames(), UNO_QUERY );
     852           0 :             sal_Int32 nFrameCount = xList->getCount();
     853           0 :             for( sal_Int32 i=0; i<nFrameCount; ++i )
     854             :             {
     855           0 :                 Reference< XFrame > xFrame;
     856           0 :                 Any aVal = xList->getByIndex(i);
     857           0 :                 if (!(aVal>>=xFrame) || !xFrame.is() )
     858           0 :                     continue;
     859             : 
     860           0 :                 if ( xFrame == xCurrentFrame )
     861           0 :                     nActiveItemId = nItemId;
     862             : 
     863           0 :                 Window* pWin = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
     864           0 :                 if ( pWin && pWin->IsVisible() )
     865             :                 {
     866           0 :                     aNewWindowListVector.push_back( pWin->GetText() );
     867           0 :                     ++nItemId;
     868             :                 }
     869           0 :             }
     870             : 
     871           0 :             int nItemCount       = pMenu->GetItemCount();
     872             : 
     873           0 :             if ( nItemCount > 0 )
     874             :             {
     875             :                 // remove all old window list entries from menu
     876           0 :                 sal_uInt16 nPos = pMenu->GetItemPos( START_ITEMID_WINDOWLIST );
     877           0 :                 for ( sal_uInt16 n = nPos; n < pMenu->GetItemCount(); )
     878           0 :                     pMenu->RemoveItem( n );
     879             : 
     880           0 :                 if ( pMenu->GetItemType( pMenu->GetItemCount()-1 ) == MENUITEM_SEPARATOR )
     881           0 :                     pMenu->RemoveItem( pMenu->GetItemCount()-1 );
     882             :             }
     883             : 
     884           0 :             if ( aNewWindowListVector.size() > 0 )
     885             :             {
     886             :                 // append new window list entries to menu
     887           0 :                 pMenu->InsertSeparator();
     888           0 :                 nItemId = START_ITEMID_WINDOWLIST;
     889           0 :                 for ( sal_uInt32 i = 0; i < aNewWindowListVector.size(); i++ )
     890             :                 {
     891           0 :                     pMenu->InsertItem( nItemId, aNewWindowListVector.at( i ), MIB_RADIOCHECK );
     892           0 :                     if ( nItemId == nActiveItemId )
     893           0 :                         pMenu->CheckItem( nItemId );
     894           0 :                     ++nItemId;
     895             :                 }
     896           0 :             }
     897             :         }
     898             :         else
     899           0 :             pWindowMenu = pSVMenu->GetPopupMenu(SID_MDIWINDOWLIST);
     900             : 
     901           0 :         if ( !pParent && pSVMenu->IsMenuBar() && !pAddonsMenu )
     902             :         {
     903             :             // Store Add-Ons parents of our runtime menu items
     904           0 :             pAddonsMenu = pSVMenu->GetPopupMenu( SID_ADDONLIST );
     905             :         }
     906             : 
     907             :         // Provides consistency to the Status
     908           0 :         if ( bControllersUnBound )
     909           0 :             BindControllers();
     910             : 
     911           0 :         pBindings->GetDispatcher_Impl()->Flush();
     912           0 :         for ( sal_uInt16 nPos = 0; nPos < nCount; ++nPos )
     913             :         {
     914           0 :             sal_uInt16 nSlotId = (pItems+nPos)->GetId();
     915           0 :             if ( nSlotId && nSlotId > END_ITEMID_WINDOWLIST )
     916           0 :                 pBindings->Update(nSlotId);
     917             :         }
     918             : 
     919           0 :         pBindings->Update( SID_IMAGE_ORIENTATION );
     920             : 
     921             :         // Supress the Status updates until Deactivate
     922           0 :         pBindings->ENTERREGISTRATIONS(); ++nLocks; bIsActive = sal_True;
     923             : 
     924           0 :         if ( pAutoDeactivate ) // QAP-Hack
     925           0 :             pAutoDeactivate->Start();
     926             : 
     927           0 :         return sal_True;
     928             :     }
     929             :     else
     930             :     {
     931             :         // Find the VirtualMenu for the SubMenu and if possible, bind a
     932             :         // VirtualMenu
     933           0 :         bool bRet = Bind_Impl( pMenu );
     934             : #ifdef DBG_UTIL
     935             :         if ( !bRet)
     936             :             DBG_WARNING( "W1: Virtual menu could not be created!" );
     937             : #endif
     938           0 :         return bRet;
     939             :     }
     940             : }
     941             : 
     942             : //--------------------------------------------------------------------
     943             : 
     944           0 : IMPL_LINK( SfxVirtualMenu, Deactivate, Menu *, pMenu )
     945             : {
     946             :     DBG_OUTF( ("SfxVirtualMenu %lx deactivated %lx, own %lx", this, pMenu, pSVMenu) );
     947           0 :     if ( bIsActive && ( 0 == pMenu || pMenu == pSVMenu ) )
     948             :     {
     949           0 :         if ( pAutoDeactivate )
     950           0 :             pAutoDeactivate->Stop();
     951             : 
     952             :         // All controllers can be unbinded all the way up to the Menubar,
     953             :         // when the menu is disabled (= closed)
     954           0 :         if ( pParent )
     955           0 :             UnbindControllers();
     956           0 :         pBindings->LEAVEREGISTRATIONS(); --nLocks; bIsActive = sal_False;
     957             :     }
     958           0 :     return sal_True;
     959             : }
     960             : //--------------------------------------------------------------------
     961             : 
     962             : // called on activation of the SV-Menu
     963             : 
     964           0 : IMPL_LINK( SfxVirtualMenu, Select, Menu *, pMenu )
     965             : {
     966           0 :     sal_uInt16 nSlotId = (sal_uInt16) pMenu->GetCurItemId();
     967             :     DBG_OUTF( ("SfxVirtualMenu %lx selected %u from %lx", this, nSlotId, pMenu) );
     968             : 
     969           0 :     if ( nSlotId >= START_ITEMID_WINDOWLIST && nSlotId <= END_ITEMID_WINDOWLIST )
     970             :     {
     971             :         // window list menu item selected
     972           0 :         Reference< XDesktop2 > xDesktop = Desktop::create( ::comphelper::getProcessComponentContext() );
     973           0 :         sal_uInt16 nTaskId = START_ITEMID_WINDOWLIST;
     974           0 :         Reference< XIndexAccess > xList( xDesktop->getFrames(), UNO_QUERY );
     975           0 :         sal_Int32 nFrameCount = xList->getCount();
     976           0 :         for ( sal_Int32 i=0; i<nFrameCount; ++i )
     977             :         {
     978           0 :             Any aItem = xList->getByIndex(i);
     979           0 :             Reference< XFrame > xFrame;
     980           0 :             if (( aItem >>= xFrame ) && xFrame.is() && nTaskId == nSlotId )
     981             :             {
     982           0 :                 Window* pWin = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
     983           0 :                 pWin->GrabFocus();
     984           0 :                 pWin->ToTop( TOTOP_RESTOREWHENMIN );
     985             :                 break;
     986             :             }
     987             : 
     988           0 :             nTaskId++;
     989           0 :         }
     990             : 
     991           0 :         return sal_True;
     992             :     }
     993           0 :     else if ( nSlotId >= START_ITEMID_PICKLIST && nSlotId <= END_ITEMID_PICKLIST )
     994             :     {
     995           0 :         SfxPickList::Get().ExecuteMenuEntry( nSlotId );
     996           0 :         return sal_True;
     997             :     }
     998             : 
     999           0 :     if ( pMenu->GetItemCommand( nSlotId ).Len() )
    1000           0 :         pBindings->ExecuteCommand_Impl( pMenu->GetItemCommand( nSlotId ) );
    1001             :     else
    1002           0 :         pBindings->Execute( nSlotId );
    1003             : 
    1004           0 :     return sal_True;
    1005             : }
    1006             : 
    1007             : //--------------------------------------------------------------------
    1008             : 
    1009             : // returns the associated StarView-menu
    1010             : 
    1011           0 : Menu* SfxVirtualMenu::GetSVMenu() const
    1012             : {
    1013             :     DBG_CHKTHIS(SfxVirtualMenu, 0);
    1014             : 
    1015           0 :     return pSVMenu;
    1016             : }
    1017             : 
    1018             : //--------------------------------------------------------------------
    1019             : 
    1020             : // set the checkmark of the specified item
    1021             : 
    1022           0 : void SfxVirtualMenu::CheckItem( sal_uInt16 nItemId, sal_Bool bCheck )
    1023             : {
    1024             :     DBG_CHKTHIS(SfxVirtualMenu, 0);
    1025             :     DBG_ASSERT( this != 0, "");
    1026             :     DBG_ASSERT( pSVMenu != 0, "" );
    1027           0 :     if (pSVMenu->GetItemPos( nItemId ) != MENU_ITEM_NOTFOUND )
    1028           0 :         pSVMenu->CheckItem( nItemId, bCheck );
    1029           0 : }
    1030             : //--------------------------------------------------------------------
    1031             : 
    1032             : // set the enabled-state of the specified item
    1033             : 
    1034           0 : void SfxVirtualMenu::EnableItem( sal_uInt16 nItemId, sal_Bool bEnable )
    1035             : {
    1036             :     DBG_CHKTHIS(SfxVirtualMenu, 0);
    1037             :     DBG_ASSERT( this != 0, "");
    1038             :     DBG_ASSERT( pSVMenu != 0, "" );
    1039             : 
    1040           0 :     if (pSVMenu->GetItemPos( nItemId ) != MENU_ITEM_NOTFOUND )
    1041           0 :         pSVMenu->EnableItem( nItemId, bEnable );
    1042           0 : }
    1043             : //--------------------------------------------------------------------
    1044             : 
    1045             : // set the text of the specified item
    1046             : 
    1047           0 : void SfxVirtualMenu::SetItemText( sal_uInt16 nItemId, const String& rText )
    1048             : {
    1049             :     DBG_CHKTHIS(SfxVirtualMenu, 0);
    1050             :     DBG_ASSERT( this != 0, "");
    1051             :     DBG_ASSERT( pSVMenu != 0, "" );
    1052           0 :     if (pSVMenu->GetItemPos( nItemId ) != MENU_ITEM_NOTFOUND )
    1053           0 :         pSVMenu->SetItemText( nItemId, rText );
    1054           0 : }
    1055             : 
    1056             : //--------------------------------------------------------------------
    1057             : 
    1058             : 
    1059           0 : void SfxVirtualMenu::SetPopupMenu( sal_uInt16 nItemId, PopupMenu *pMenu )
    1060             : {
    1061             :     DBG_CHKTHIS(SfxVirtualMenu, 0);
    1062             : 
    1063           0 :     if (pSVMenu->GetItemPos( nItemId ) != MENU_ITEM_NOTFOUND )
    1064           0 :         GetSVMenu()->SetPopupMenu( nItemId, pMenu );
    1065           0 :     for ( sal_uInt16 n = 0; n < nCount; ++n )
    1066             :     {
    1067           0 :         SfxVirtualMenu *pSubMenu = (pItems+n)->GetPopupMenu();
    1068           0 :         if ( pSubMenu )
    1069           0 :             pSubMenu->SetPopupMenu( nItemId, pMenu );
    1070             :     }
    1071           0 : }
    1072             : 
    1073             : //--------------------------------------------------------------------
    1074             : 
    1075             : // Forces the initialization, which is otherwise only happens in Activate
    1076             : 
    1077           0 : void SfxVirtualMenu::InitPopup( sal_uInt16 nPos, sal_Bool /*bOLE*/ )
    1078             : {
    1079             :     DBG_CHKTHIS(SfxVirtualMenu, 0);
    1080             : 
    1081           0 :     sal_uInt16 nSID = pSVMenu->GetItemId(nPos);
    1082           0 :     PopupMenu *pMenu = pSVMenu->GetPopupMenu( nSID );
    1083             : 
    1084             :     DBG_ASSERT( pMenu, "No popup exist here!");
    1085             : 
    1086           0 :     SfxMenuControl &rCtrl = pItems[nPos];
    1087           0 :     if ( !rCtrl.GetId() )
    1088             :     {
    1089             :         // Generate VirtualMenu for Sub-Menu
    1090           0 :         sal_Bool bRes = bResCtor;
    1091             :         SfxVirtualMenu *pSubMenu =
    1092           0 :             new SfxVirtualMenu(nSID, this, *pMenu, sal_False, *pBindings, bOLE, bRes);
    1093             : 
    1094             :         DBG_OUTF( ("New VirtualMenu %lx created", pSubMenu) );
    1095             : 
    1096           0 :         rCtrl.Bind( this, nSID, *pSubMenu, pSVMenu->GetItemText(nSID), *pBindings );
    1097             :     }
    1098           0 : }
    1099             : 
    1100           0 : void SfxVirtualMenu::InitializeHelp()
    1101             : {
    1102           0 :     for ( sal_uInt16 nPos = 0; nPos<pSVMenu->GetItemCount(); ++nPos )
    1103             :     {
    1104           0 :         sal_uInt16 nSlotId = pSVMenu->GetItemId(nPos);
    1105           0 :         SfxMenuControl &rCtrl = pItems[nPos];
    1106           0 :         if ( nSlotId && !rCtrl.GetId() )
    1107             :         {
    1108           0 :             InitPopup( nPos, sal_True );
    1109             :         }
    1110             : 
    1111           0 :         SfxVirtualMenu *pSubMenu = rCtrl.GetPopupMenu();
    1112           0 :         if ( pSubMenu )
    1113           0 :             pSubMenu->InitializeHelp();
    1114             :     }
    1115             : 
    1116           0 :     bHelpInitialized = sal_True;
    1117           0 : }
    1118             : 
    1119             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10