1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_sfx2.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <sot/factory.hxx> 32*cdf0e10cSrcweir #include <svtools/menuoptions.hxx> 33*cdf0e10cSrcweir #include <svtools/imagemgr.hxx> 34*cdf0e10cSrcweir #include <svl/imageitm.hxx> 35*cdf0e10cSrcweir #include <com/sun/star/container/XEnumeration.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/frame/XDesktop.hpp> 37*cdf0e10cSrcweir #include <com/sun/star/frame/XFramesSupplier.hpp> 38*cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 39*cdf0e10cSrcweir #include <toolkit/unohlp.hxx> 40*cdf0e10cSrcweir #include <tools/urlobj.hxx> 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir #include "virtmenu.hxx" 43*cdf0e10cSrcweir #include <sfx2/msgpool.hxx> 44*cdf0e10cSrcweir #include "statcach.hxx" 45*cdf0e10cSrcweir #include <sfx2/msg.hxx> 46*cdf0e10cSrcweir #include "idpool.hxx" 47*cdf0e10cSrcweir #include <sfx2/mnuitem.hxx> 48*cdf0e10cSrcweir #include <sfx2/mnumgr.hxx> 49*cdf0e10cSrcweir #include <sfx2/bindings.hxx> 50*cdf0e10cSrcweir #include <sfx2/dispatch.hxx> 51*cdf0e10cSrcweir #include <sfx2/app.hxx> 52*cdf0e10cSrcweir #include "sfxtypes.hxx" 53*cdf0e10cSrcweir #include "arrdecl.hxx" 54*cdf0e10cSrcweir #include <sfx2/sfx.hrc> 55*cdf0e10cSrcweir #include <sfx2/viewsh.hxx> 56*cdf0e10cSrcweir #include "sfxpicklist.hxx" 57*cdf0e10cSrcweir #include "sfx2/sfxresid.hxx" 58*cdf0e10cSrcweir #include "menu.hrc" 59*cdf0e10cSrcweir #include "sfx2/imagemgr.hxx" 60*cdf0e10cSrcweir #include <sfx2/viewfrm.hxx> 61*cdf0e10cSrcweir #include <sfx2/objsh.hxx> 62*cdf0e10cSrcweir #include <framework/addonsoptions.hxx> 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir #ifndef __FRAMEWORK_CLASSES_ADDONMENUS_HXX_ 65*cdf0e10cSrcweir #include <framework/addonmenu.hxx> 66*cdf0e10cSrcweir #endif 67*cdf0e10cSrcweir #include <framework/menuconfiguration.hxx> 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir using namespace ::com::sun::star::container; 70*cdf0e10cSrcweir using namespace ::com::sun::star::frame; 71*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir //========================================================================= 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir DBG_NAME(SfxVirtualMenu) 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir //========================================================================= 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir typedef SfxMenuControl* SfxMenuControlPtr; 80*cdf0e10cSrcweir SV_IMPL_PTRARR(SfxMenuCtrlArr_Impl, SfxMenuControlPtr); 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir class SfxMenuImageControl_Impl : public SfxControllerItem 83*cdf0e10cSrcweir { 84*cdf0e10cSrcweir SfxVirtualMenu* pMenu; 85*cdf0e10cSrcweir long lRotation; 86*cdf0e10cSrcweir sal_Bool bIsMirrored; 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir protected: 89*cdf0e10cSrcweir virtual void StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState ); 90*cdf0e10cSrcweir public: 91*cdf0e10cSrcweir SfxMenuImageControl_Impl( sal_uInt16 nSlotId, SfxBindings& rBindings, SfxVirtualMenu* pVMenu ) 92*cdf0e10cSrcweir : SfxControllerItem( nSlotId, rBindings ) 93*cdf0e10cSrcweir , pMenu( pVMenu ) 94*cdf0e10cSrcweir , lRotation( 0 ) 95*cdf0e10cSrcweir , bIsMirrored( sal_False ) 96*cdf0e10cSrcweir {} 97*cdf0e10cSrcweir void Update(); 98*cdf0e10cSrcweir }; 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir void SfxMenuImageControl_Impl::StateChanged( sal_uInt16 /*nSID*/, SfxItemState /*eState*/, const SfxPoolItem* pState ) 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir const SfxImageItem* pItem = PTR_CAST( SfxImageItem, pState ); 103*cdf0e10cSrcweir if ( pItem ) 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir lRotation = pItem->GetRotation(); 106*cdf0e10cSrcweir bIsMirrored = pItem->IsMirrored(); 107*cdf0e10cSrcweir Update(); 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir } 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir void SfxMenuImageControl_Impl::Update() 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir SfxViewFrame* pViewFrame = GetBindings().GetDispatcher_Impl()->GetFrame(); 114*cdf0e10cSrcweir SfxModule* pModule = pViewFrame->GetObjectShell()->GetModule(); 115*cdf0e10cSrcweir SfxSlotPool* pPool = pModule->GetSlotPool(); 116*cdf0e10cSrcweir Menu* pSVMenu = pMenu->GetSVMenu(); 117*cdf0e10cSrcweir for (sal_uInt16 nPos = 0; nPos<pSVMenu->GetItemCount(); nPos++) 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir sal_uInt16 nslotId = pSVMenu->GetItemId( nPos ); 120*cdf0e10cSrcweir const SfxSlot* pSlot = pPool->GetSlot( nslotId ); 121*cdf0e10cSrcweir if ( pSlot && pSlot->IsMode( SFX_SLOT_IMAGEROTATION ) ) 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir pSVMenu->SetItemImageMirrorMode( nslotId, sal_False ); 124*cdf0e10cSrcweir pSVMenu->SetItemImageAngle( nslotId, lRotation ); 125*cdf0e10cSrcweir } 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir if ( pSlot && pSlot->IsMode( SFX_SLOT_IMAGEREFLECTION ) ) 128*cdf0e10cSrcweir pSVMenu->SetItemImageMirrorMode( nslotId, bIsMirrored ); 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir //========================================================================= 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir static Image RetrieveAddOnImage( Reference< com::sun::star::frame::XFrame >& rFrame, 135*cdf0e10cSrcweir const rtl::OUString& aImageId, 136*cdf0e10cSrcweir const rtl::OUString& aURL, 137*cdf0e10cSrcweir sal_Bool bBigImage, 138*cdf0e10cSrcweir sal_Bool bHiContrast ) 139*cdf0e10cSrcweir { 140*cdf0e10cSrcweir Image aImage; 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir if ( aImageId.getLength() > 0 ) 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir aImage = GetImage( rFrame, aImageId, bBigImage, bHiContrast ); 145*cdf0e10cSrcweir if ( !!aImage ) 146*cdf0e10cSrcweir return aImage; 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir aImage = GetImage( rFrame, aURL, bBigImage, bHiContrast ); 150*cdf0e10cSrcweir if ( !aImage ) 151*cdf0e10cSrcweir aImage = framework::AddonsOptions().GetImageFromURL( aURL, bBigImage, bHiContrast ); 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir return aImage; 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir //========================================================================= 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir /* Diese Hilfsfunktion pr"uft, ob eine Slot-Id im aktuellen Applikations- 159*cdf0e10cSrcweir Status sichtbar ist oder nicht. Dabei bezieht sich der Applikations-Status 160*cdf0e10cSrcweir darauf, ob die Applikation OLE-Server ist oder nicht. 161*cdf0e10cSrcweir */ 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir sal_Bool IsItemHidden_Impl( sal_uInt16 nItemId, int bOleServer, int bMac ) 164*cdf0e10cSrcweir { 165*cdf0e10cSrcweir return ( bMac && 166*cdf0e10cSrcweir ( nItemId == SID_MINIMIZED ) ) || 167*cdf0e10cSrcweir ( bOleServer && 168*cdf0e10cSrcweir ( nItemId == SID_QUITAPP || nItemId == SID_SAVEDOC || 169*cdf0e10cSrcweir nItemId == SID_OPENDOC || nItemId == SID_SAVEASDOC || 170*cdf0e10cSrcweir nItemId == SID_NEWDOC ) ) || 171*cdf0e10cSrcweir ( !bOleServer && 172*cdf0e10cSrcweir ( nItemId == SID_EXITANDRETURN || nItemId == SID_UPDATEDOC ) ); 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir //==================================================================== 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir void SfxVirtualMenu::Construct_Impl() 178*cdf0e10cSrcweir { 179*cdf0e10cSrcweir pSVMenu->SetHighlightHdl( LINK(this, SfxVirtualMenu, Highlight) ); 180*cdf0e10cSrcweir pSVMenu->SetActivateHdl( LINK(this, SfxVirtualMenu, Activate) ); 181*cdf0e10cSrcweir pSVMenu->SetDeactivateHdl( LINK(this, SfxVirtualMenu, Deactivate) ); 182*cdf0e10cSrcweir pSVMenu->SetSelectHdl( LINK(this, SfxVirtualMenu, Select) ); 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir // #107258# accelerator keys are needed for accessibility 185*cdf0e10cSrcweir //if ( bOLE ) 186*cdf0e10cSrcweir // InvalidateKeyCodes(); 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir if ( !pResMgr && pParent ) 189*cdf0e10cSrcweir pResMgr = pParent->pResMgr; 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir //-------------------------------------------------------------------- 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir SfxVirtualMenu::SfxVirtualMenu( sal_uInt16 nOwnId, 195*cdf0e10cSrcweir SfxVirtualMenu* pOwnParent, Menu& rMenu, sal_Bool bWithHelp, 196*cdf0e10cSrcweir SfxBindings &rBindings, sal_Bool bOLEServer, sal_Bool bRes, sal_Bool bIsAddonMenu ): 197*cdf0e10cSrcweir pItems(0), 198*cdf0e10cSrcweir pImageControl(0), 199*cdf0e10cSrcweir pBindings(&rBindings), 200*cdf0e10cSrcweir pResMgr(0), 201*cdf0e10cSrcweir pAutoDeactivate(0), 202*cdf0e10cSrcweir nLocks(0), 203*cdf0e10cSrcweir bHelpInitialized( bWithHelp ), 204*cdf0e10cSrcweir bWasHighContrast( sal_False ), 205*cdf0e10cSrcweir bIsAddonPopupMenu( bIsAddonMenu ) 206*cdf0e10cSrcweir { 207*cdf0e10cSrcweir DBG_MEMTEST(); 208*cdf0e10cSrcweir DBG_CTOR(SfxVirtualMenu, 0); 209*cdf0e10cSrcweir pSVMenu = &rMenu; 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir bResCtor = bRes; 212*cdf0e10cSrcweir bOLE = bOLEServer; 213*cdf0e10cSrcweir nId = nOwnId; 214*cdf0e10cSrcweir pParent = pOwnParent; 215*cdf0e10cSrcweir nVisibleItems = 0; 216*cdf0e10cSrcweir pAppCtrl = 0; 217*cdf0e10cSrcweir pWindowMenu = NULL; 218*cdf0e10cSrcweir pPickMenu = NULL; 219*cdf0e10cSrcweir pAddonsMenu = NULL; 220*cdf0e10cSrcweir bIsActive = sal_False; 221*cdf0e10cSrcweir bControllersUnBound = sal_False; 222*cdf0e10cSrcweir CreateFromSVMenu(); 223*cdf0e10cSrcweir Construct_Impl(); 224*cdf0e10cSrcweir bHelpInitialized = sal_False; 225*cdf0e10cSrcweir } 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir //-------------------------------------------------------------------- 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir // creates a virtual menu from a StarView MenuBar or PopupMenu 230*cdf0e10cSrcweir 231*cdf0e10cSrcweir SfxVirtualMenu::SfxVirtualMenu( Menu *pStarViewMenu, sal_Bool bWithHelp, 232*cdf0e10cSrcweir SfxBindings &rBindings, sal_Bool bOLEServer, sal_Bool bRes, sal_Bool bIsAddonMenu ): 233*cdf0e10cSrcweir pItems(0), 234*cdf0e10cSrcweir pImageControl(0), 235*cdf0e10cSrcweir pBindings(&rBindings), 236*cdf0e10cSrcweir pResMgr(0), 237*cdf0e10cSrcweir pAutoDeactivate(0), 238*cdf0e10cSrcweir nLocks(0), 239*cdf0e10cSrcweir bHelpInitialized( bWithHelp ), 240*cdf0e10cSrcweir bWasHighContrast( sal_False ), 241*cdf0e10cSrcweir bIsAddonPopupMenu( bIsAddonMenu ) 242*cdf0e10cSrcweir { 243*cdf0e10cSrcweir DBG_MEMTEST(); 244*cdf0e10cSrcweir DBG_CTOR(SfxVirtualMenu, 0); 245*cdf0e10cSrcweir 246*cdf0e10cSrcweir pSVMenu = pStarViewMenu; 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir bResCtor = bRes; 249*cdf0e10cSrcweir bOLE = bOLEServer; 250*cdf0e10cSrcweir nId = 0; 251*cdf0e10cSrcweir pParent = 0; 252*cdf0e10cSrcweir pAppCtrl = 0; 253*cdf0e10cSrcweir nVisibleItems = 0; 254*cdf0e10cSrcweir pWindowMenu = NULL; 255*cdf0e10cSrcweir pPickMenu = NULL; 256*cdf0e10cSrcweir pAddonsMenu = NULL; 257*cdf0e10cSrcweir bIsActive = sal_False; 258*cdf0e10cSrcweir bControllersUnBound = sal_False; 259*cdf0e10cSrcweir CreateFromSVMenu(); 260*cdf0e10cSrcweir Construct_Impl(); 261*cdf0e10cSrcweir bHelpInitialized = sal_False; 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir 264*cdf0e10cSrcweir //-------------------------------------------------------------------- 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir /* Der Destruktor der Klasse SfxVirtualMenu gib die gebundenen Items frei 267*cdf0e10cSrcweir und klinkt das zugeh"orige StarView-PopupMenu aus seinem Parent aus. 268*cdf0e10cSrcweir Falls es sich um das Pickmenu oder das MDI-Menu handelt, wird es 269*cdf0e10cSrcweir dort abgemeldet. 270*cdf0e10cSrcweir */ 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir SfxVirtualMenu::~SfxVirtualMenu() 273*cdf0e10cSrcweir { 274*cdf0e10cSrcweir DBG_MEMTEST(); 275*cdf0e10cSrcweir DBG_DTOR(SfxVirtualMenu, 0); 276*cdf0e10cSrcweir 277*cdf0e10cSrcweir DELETEZ( pImageControl ); 278*cdf0e10cSrcweir SvtMenuOptions().RemoveListenerLink( LINK( this, SfxVirtualMenu, SettingsChanged ) ); 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir if ( bIsActive ) 281*cdf0e10cSrcweir { 282*cdf0e10cSrcweir pBindings->LEAVEREGISTRATIONS(); --nLocks; bIsActive = sal_False; 283*cdf0e10cSrcweir } 284*cdf0e10cSrcweir 285*cdf0e10cSrcweir // QAP-Hack 286*cdf0e10cSrcweir if ( pAutoDeactivate ) 287*cdf0e10cSrcweir { 288*cdf0e10cSrcweir if ( pAutoDeactivate->IsActive() ) 289*cdf0e10cSrcweir Deactivate(0); 290*cdf0e10cSrcweir DELETEX(pAutoDeactivate); 291*cdf0e10cSrcweir } 292*cdf0e10cSrcweir 293*cdf0e10cSrcweir if (pItems) 294*cdf0e10cSrcweir { 295*cdf0e10cSrcweir delete [] pItems; 296*cdf0e10cSrcweir } 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir delete pAppCtrl; 299*cdf0e10cSrcweir pBindings = 0; 300*cdf0e10cSrcweir 301*cdf0e10cSrcweir // Alle Menues, die von SV erzeugt wurden, werden auch dort wieder 302*cdf0e10cSrcweir // gel"oscht (also die beim Laden aus der Resource erzeugten). 303*cdf0e10cSrcweir // Das Top-Level-Menu wird nie von SV gel"oscht, da die Allocierung 304*cdf0e10cSrcweir // im SFX erfolgt 305*cdf0e10cSrcweir if ( !bResCtor || !pParent) 306*cdf0e10cSrcweir { 307*cdf0e10cSrcweir if ( pParent ) 308*cdf0e10cSrcweir { 309*cdf0e10cSrcweir if( pParent->pSVMenu->GetItemPos( nId ) != MENU_ITEM_NOTFOUND ) 310*cdf0e10cSrcweir pParent->pSVMenu->SetPopupMenu( nId, 0 ); 311*cdf0e10cSrcweir if ( pParent->pPickMenu == pSVMenu ) 312*cdf0e10cSrcweir pParent->pPickMenu = 0; 313*cdf0e10cSrcweir if ( pParent->pWindowMenu == pSVMenu) 314*cdf0e10cSrcweir pParent->pWindowMenu = 0; 315*cdf0e10cSrcweir if ( pParent->pAddonsMenu == pSVMenu ) 316*cdf0e10cSrcweir pParent->pAddonsMenu = 0; 317*cdf0e10cSrcweir } 318*cdf0e10cSrcweir 319*cdf0e10cSrcweir delete pSVMenu; 320*cdf0e10cSrcweir } 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir DBG_OUTF( ("SfxVirtualMenu %lx destroyed", this) ); 323*cdf0e10cSrcweir DBG_ASSERT( !nLocks, "destroying active menu" ); 324*cdf0e10cSrcweir } 325*cdf0e10cSrcweir //-------------------------------------------------------------------- 326*cdf0e10cSrcweir 327*cdf0e10cSrcweir sal_Bool SfxVirtualMenu::IsHiContrastMode() const 328*cdf0e10cSrcweir { 329*cdf0e10cSrcweir const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings(); 330*cdf0e10cSrcweir return rSettings.GetHighContrastMode(); 331*cdf0e10cSrcweir } 332*cdf0e10cSrcweir 333*cdf0e10cSrcweir //-------------------------------------------------------------------- 334*cdf0e10cSrcweir // internal: creates the virtual menu from the pSVMenu 335*cdf0e10cSrcweir 336*cdf0e10cSrcweir void SfxVirtualMenu::CreateFromSVMenu() 337*cdf0e10cSrcweir { 338*cdf0e10cSrcweir DBG_MEMTEST(); 339*cdf0e10cSrcweir DBG_CHKTHIS(SfxVirtualMenu, 0); 340*cdf0e10cSrcweir 341*cdf0e10cSrcweir // Merge Addon popup menus into the SV Menu 342*cdf0e10cSrcweir SfxViewFrame* pViewFrame = pBindings->GetDispatcher()->GetFrame(); 343*cdf0e10cSrcweir SfxSlotPool* pSlotPool = pViewFrame->GetObjectShell()->GetModule()->GetSlotPool(); 344*cdf0e10cSrcweir Reference< com::sun::star::frame::XFrame > xFrame( pViewFrame->GetFrame().GetFrameInterface() ); 345*cdf0e10cSrcweir 346*cdf0e10cSrcweir if ( pSVMenu->IsMenuBar() ) 347*cdf0e10cSrcweir { 348*cdf0e10cSrcweir sal_uInt16 nPos = pSVMenu->GetItemPos( SID_MDIWINDOWLIST ); 349*cdf0e10cSrcweir if ( nPos != MENU_ITEM_NOTFOUND && xFrame.is() ) 350*cdf0e10cSrcweir { 351*cdf0e10cSrcweir // Retrieve addon popup menus and add them to our menu bar 352*cdf0e10cSrcweir Reference< com::sun::star::frame::XModel > xModel; 353*cdf0e10cSrcweir Reference< com::sun::star::frame::XController > xController( xFrame->getController(), UNO_QUERY ); 354*cdf0e10cSrcweir if ( xController.is() ) 355*cdf0e10cSrcweir xModel = Reference< com::sun::star::frame::XModel >( xController->getModel(), UNO_QUERY ); 356*cdf0e10cSrcweir framework::AddonMenuManager::MergeAddonPopupMenus( xFrame, xModel, nPos, (MenuBar *)pSVMenu ); 357*cdf0e10cSrcweir } 358*cdf0e10cSrcweir 359*cdf0e10cSrcweir // Merge the Add-Ons help menu items into the Office help menu 360*cdf0e10cSrcweir if ( xFrame.is() ) 361*cdf0e10cSrcweir framework::AddonMenuManager::MergeAddonHelpMenu( xFrame, (MenuBar *)pSVMenu ); 362*cdf0e10cSrcweir 363*cdf0e10cSrcweir // Set addon menu pointer here to avoid problems. When accessibility is enabled, the whole menu 364*cdf0e10cSrcweir // is created immediately! 365*cdf0e10cSrcweir pAddonsMenu = pSVMenu->GetPopupMenu( SID_ADDONLIST ); 366*cdf0e10cSrcweir } 367*cdf0e10cSrcweir else if ( pParent ) 368*cdf0e10cSrcweir { 369*cdf0e10cSrcweir if ( pSVMenu == pParent->pAddonsMenu && 370*cdf0e10cSrcweir framework::AddonsOptions().HasAddonsMenu() && 371*cdf0e10cSrcweir !pSVMenu->GetPopupMenu( SID_ADDONS ) ) 372*cdf0e10cSrcweir { 373*cdf0e10cSrcweir // Create menu item at the end of the tools popup menu for the addons popup menu 374*cdf0e10cSrcweir InsertAddOnsMenuItem( pSVMenu ); 375*cdf0e10cSrcweir } 376*cdf0e10cSrcweir } 377*cdf0e10cSrcweir 378*cdf0e10cSrcweir // get and store the number of items 379*cdf0e10cSrcweir nCount = pSVMenu->GetItemCount(); 380*cdf0e10cSrcweir 381*cdf0e10cSrcweir // Achtung: nur zu diesem Zeitpunkt ist garantiert, da\s nCount und 382*cdf0e10cSrcweir // der ItemCount des SV-Menues "ubereinstimmen; sp"ater kann das SvMenue 383*cdf0e10cSrcweir // auch mehr Eintr"age haben (Pickliste!) 384*cdf0e10cSrcweir if (nCount) 385*cdf0e10cSrcweir pItems = new SfxMenuControl[nCount]; 386*cdf0e10cSrcweir 387*cdf0e10cSrcweir // remember some values 388*cdf0e10cSrcweir SFX_APP(); 389*cdf0e10cSrcweir const int bOleServer = sal_False; 390*cdf0e10cSrcweir const int bMac = sal_False; 391*cdf0e10cSrcweir SvtMenuOptions aOptions; 392*cdf0e10cSrcweir aOptions.AddListenerLink( LINK( this, SfxVirtualMenu, SettingsChanged ) ); 393*cdf0e10cSrcweir 394*cdf0e10cSrcweir // iterate through the items 395*cdf0e10cSrcweir pBindings->ENTERREGISTRATIONS(); ++nLocks; 396*cdf0e10cSrcweir pImageControl = new SfxMenuImageControl_Impl( SID_IMAGE_ORIENTATION, *pBindings, this ); 397*cdf0e10cSrcweir 398*cdf0e10cSrcweir // Update high contrast state 399*cdf0e10cSrcweir bWasHighContrast = IsHiContrastMode(); 400*cdf0e10cSrcweir 401*cdf0e10cSrcweir sal_uInt16 nSVPos = 0; 402*cdf0e10cSrcweir for ( sal_uInt16 nPos=0; nPos<nCount; ++nPos, ++nSVPos ) 403*cdf0e10cSrcweir { 404*cdf0e10cSrcweir sal_uInt16 nSlotId = pSVMenu->GetItemId(nSVPos); 405*cdf0e10cSrcweir PopupMenu* pPopup = pSVMenu->GetPopupMenu(nSlotId); 406*cdf0e10cSrcweir if( pPopup && nSlotId >= SID_OBJECTMENU0 && nSlotId <= SID_OBJECTMENU_LAST ) 407*cdf0e10cSrcweir { 408*cdf0e10cSrcweir // artefact in XML menuconfig: every entry in root menu must have a popup! 409*cdf0e10cSrcweir pSVMenu->SetPopupMenu( nSlotId, NULL ); 410*cdf0e10cSrcweir DELETEZ( pPopup ); 411*cdf0e10cSrcweir } 412*cdf0e10cSrcweir 413*cdf0e10cSrcweir const String sItemText = pSVMenu->GetItemText(nSlotId); 414*cdf0e10cSrcweir const String sHelpText = pSVMenu->GetHelpText(nSlotId); 415*cdf0e10cSrcweir 416*cdf0e10cSrcweir if ( pPopup ) 417*cdf0e10cSrcweir { 418*cdf0e10cSrcweir 419*cdf0e10cSrcweir SfxMenuControl *pMnuCtrl = 420*cdf0e10cSrcweir SfxMenuControl::CreateControl(nSlotId, *pPopup, *pBindings); 421*cdf0e10cSrcweir 422*cdf0e10cSrcweir if ( pMnuCtrl ) 423*cdf0e10cSrcweir { 424*cdf0e10cSrcweir // Das Popup war offensichtlich kein "echtes"; solche werden 425*cdf0e10cSrcweir // niemals aus der Resource geladen und m"ussen daher explizit 426*cdf0e10cSrcweir // gel"oscht werden 427*cdf0e10cSrcweir if ( pSVMenu->GetPopupMenu( nSlotId ) == pPopup ) 428*cdf0e10cSrcweir pSVMenu->SetPopupMenu( nSlotId, NULL ); 429*cdf0e10cSrcweir delete pPopup; 430*cdf0e10cSrcweir pPopup = 0; 431*cdf0e10cSrcweir 432*cdf0e10cSrcweir SfxMenuCtrlArr_Impl &rCtrlArr = GetAppCtrl_Impl(); 433*cdf0e10cSrcweir rCtrlArr.C40_INSERT( SfxMenuControl, pMnuCtrl, rCtrlArr.Count() ); 434*cdf0e10cSrcweir (pItems+nPos)->Bind( 0, nSlotId, sItemText, sHelpText, *pBindings); 435*cdf0e10cSrcweir pMnuCtrl->Bind( this, nSlotId, sItemText, sHelpText, *pBindings); 436*cdf0e10cSrcweir 437*cdf0e10cSrcweir if ( Application::GetSettings().GetStyleSettings().GetUseImagesInMenus() ) 438*cdf0e10cSrcweir { 439*cdf0e10cSrcweir rtl::OUString aSlotURL( RTL_CONSTASCII_USTRINGPARAM( "slot:" )); 440*cdf0e10cSrcweir aSlotURL += rtl::OUString::valueOf( sal_Int32( nSlotId )); 441*cdf0e10cSrcweir Image aImage = GetImage( xFrame, aSlotURL, sal_False, bWasHighContrast ); 442*cdf0e10cSrcweir pSVMenu->SetItemImage( nSlotId, aImage ); 443*cdf0e10cSrcweir } 444*cdf0e10cSrcweir } 445*cdf0e10cSrcweir else 446*cdf0e10cSrcweir { 447*cdf0e10cSrcweir const SfxSlot* pSlot = pSlotPool->GetSlot( nSlotId ); 448*cdf0e10cSrcweir if ( pSlot ) 449*cdf0e10cSrcweir { 450*cdf0e10cSrcweir rtl::OString aCmd(".uno:"); 451*cdf0e10cSrcweir aCmd += pSlot->GetUnoName(); 452*cdf0e10cSrcweir pSVMenu->SetHelpId( nSlotId, pSlot->GetUnoName() ); 453*cdf0e10cSrcweir } 454*cdf0e10cSrcweir 455*cdf0e10cSrcweir pMnuCtrl = pItems+nPos; 456*cdf0e10cSrcweir 457*cdf0e10cSrcweir // normalerweise jetzt erst im Activate-Handler 458*cdf0e10cSrcweir if ( bOLE ) 459*cdf0e10cSrcweir { 460*cdf0e10cSrcweir pMnuCtrl->Bind( this, nSlotId, 461*cdf0e10cSrcweir *new SfxVirtualMenu(nSlotId, this, *pPopup, bHelpInitialized, *pBindings, bOLE, bResCtor), 462*cdf0e10cSrcweir sItemText, sHelpText, 463*cdf0e10cSrcweir *pBindings ); 464*cdf0e10cSrcweir } 465*cdf0e10cSrcweir } 466*cdf0e10cSrcweir 467*cdf0e10cSrcweir ++nVisibleItems; 468*cdf0e10cSrcweir } 469*cdf0e10cSrcweir else 470*cdf0e10cSrcweir { 471*cdf0e10cSrcweir switch ( pSVMenu->GetItemType(nSVPos) ) 472*cdf0e10cSrcweir { 473*cdf0e10cSrcweir case MENUITEM_STRING: 474*cdf0e10cSrcweir case MENUITEM_STRINGIMAGE: 475*cdf0e10cSrcweir { 476*cdf0e10cSrcweir SfxMenuControl *pMnuCtrl=0; 477*cdf0e10cSrcweir String aCmd( pSVMenu->GetItemCommand( nSlotId ) ); 478*cdf0e10cSrcweir if ( aCmd.Len() && (( nSlotId < SID_SFX_START ) || ( nSlotId > SHRT_MAX )) ) 479*cdf0e10cSrcweir { 480*cdf0e10cSrcweir // try to create control via comand name 481*cdf0e10cSrcweir pMnuCtrl = SfxMenuControl::CreateControl( aCmd, nSlotId, *pSVMenu, sItemText, sHelpText, *pBindings, this ); 482*cdf0e10cSrcweir if ( pMnuCtrl ) 483*cdf0e10cSrcweir { 484*cdf0e10cSrcweir SfxMenuCtrlArr_Impl &rCtrlArr = GetAppCtrl_Impl(); 485*cdf0e10cSrcweir rCtrlArr.C40_INSERT( SfxMenuControl, pMnuCtrl, rCtrlArr.Count()); 486*cdf0e10cSrcweir (pItems+nPos)->Bind( 0, nSlotId, sItemText, sHelpText, *pBindings); 487*cdf0e10cSrcweir } 488*cdf0e10cSrcweir } 489*cdf0e10cSrcweir 490*cdf0e10cSrcweir if ( !pMnuCtrl ) 491*cdf0e10cSrcweir { 492*cdf0e10cSrcweir // try to create control via Id 493*cdf0e10cSrcweir pMnuCtrl = SfxMenuControl::CreateControl(nSlotId, *pSVMenu, *pBindings); 494*cdf0e10cSrcweir if ( pMnuCtrl ) 495*cdf0e10cSrcweir { 496*cdf0e10cSrcweir SfxMenuCtrlArr_Impl &rCtrlArr = GetAppCtrl_Impl(); 497*cdf0e10cSrcweir rCtrlArr.C40_INSERT( SfxMenuControl, pMnuCtrl, rCtrlArr.Count()); 498*cdf0e10cSrcweir (pItems+nPos)->Bind( 0, nSlotId, sItemText, sHelpText, *pBindings); 499*cdf0e10cSrcweir } 500*cdf0e10cSrcweir else 501*cdf0e10cSrcweir // take default control 502*cdf0e10cSrcweir pMnuCtrl = (pItems+nPos); 503*cdf0e10cSrcweir 504*cdf0e10cSrcweir pMnuCtrl->Bind( this, nSlotId, sItemText, sHelpText, *pBindings); 505*cdf0e10cSrcweir } 506*cdf0e10cSrcweir 507*cdf0e10cSrcweir if ( Application::GetSettings().GetStyleSettings().GetUseImagesInMenus() ) 508*cdf0e10cSrcweir { 509*cdf0e10cSrcweir Image aImage; 510*cdf0e10cSrcweir if ( bIsAddonPopupMenu || framework::AddonMenuManager::IsAddonMenuId( nSlotId )) 511*cdf0e10cSrcweir { 512*cdf0e10cSrcweir rtl::OUString aImageId; 513*cdf0e10cSrcweir 514*cdf0e10cSrcweir ::framework::MenuConfiguration::Attributes* pMenuAttributes = 515*cdf0e10cSrcweir (::framework::MenuConfiguration::Attributes*)pSVMenu->GetUserValue( nSlotId ); 516*cdf0e10cSrcweir 517*cdf0e10cSrcweir if ( pMenuAttributes ) 518*cdf0e10cSrcweir aImageId = pMenuAttributes->aImageId; // Retrieve image id from menu attributes 519*cdf0e10cSrcweir 520*cdf0e10cSrcweir aImage = RetrieveAddOnImage( xFrame, aImageId, aCmd, sal_False, bWasHighContrast ); 521*cdf0e10cSrcweir } 522*cdf0e10cSrcweir else 523*cdf0e10cSrcweir { 524*cdf0e10cSrcweir rtl::OUString aSlotURL( RTL_CONSTASCII_USTRINGPARAM( "slot:" )); 525*cdf0e10cSrcweir aSlotURL += rtl::OUString::valueOf( sal_Int32( nSlotId )); 526*cdf0e10cSrcweir aImage = GetImage( xFrame, aSlotURL, sal_False, bWasHighContrast ); 527*cdf0e10cSrcweir } 528*cdf0e10cSrcweir 529*cdf0e10cSrcweir if ( !!aImage ) 530*cdf0e10cSrcweir pSVMenu->SetItemImage( nSlotId, aImage ); 531*cdf0e10cSrcweir } 532*cdf0e10cSrcweir 533*cdf0e10cSrcweir if ( !IsItemHidden_Impl(nSlotId, bOleServer, bMac) ) 534*cdf0e10cSrcweir ++nVisibleItems; 535*cdf0e10cSrcweir else 536*cdf0e10cSrcweir pSVMenu->RemoveItem( nSVPos-- ); 537*cdf0e10cSrcweir break; 538*cdf0e10cSrcweir } 539*cdf0e10cSrcweir 540*cdf0e10cSrcweir case MENUITEM_IMAGE: 541*cdf0e10cSrcweir //! not implemented 542*cdf0e10cSrcweir break; 543*cdf0e10cSrcweir 544*cdf0e10cSrcweir case MENUITEM_SEPARATOR: 545*cdf0e10cSrcweir //! not implemented 546*cdf0e10cSrcweir break; 547*cdf0e10cSrcweir default: 548*cdf0e10cSrcweir break; // DONTKNOW and STRINGIMAGE not handled. 549*cdf0e10cSrcweir } 550*cdf0e10cSrcweir } 551*cdf0e10cSrcweir } 552*cdf0e10cSrcweir pBindings->LEAVEREGISTRATIONS(); --nLocks; 553*cdf0e10cSrcweir } 554*cdf0e10cSrcweir 555*cdf0e10cSrcweir //-------------------------------------------------------------------- 556*cdf0e10cSrcweir 557*cdf0e10cSrcweir // called on activation of the SV-Menu 558*cdf0e10cSrcweir 559*cdf0e10cSrcweir IMPL_LINK( SfxVirtualMenu, Highlight, Menu *, pMenu ) 560*cdf0e10cSrcweir { 561*cdf0e10cSrcweir DBG_MEMTEST(); 562*cdf0e10cSrcweir DBG_CHKTHIS(SfxVirtualMenu, 0); 563*cdf0e10cSrcweir 564*cdf0e10cSrcweir // eigenes StarView-Menu 565*cdf0e10cSrcweir if ( pMenu == pSVMenu ) 566*cdf0e10cSrcweir { 567*cdf0e10cSrcweir // AutoDeactivate ist jetzt nicht mehr n"otig 568*cdf0e10cSrcweir //sal_uInt16 nSlotId = pMenu->GetCurItemId(); 569*cdf0e10cSrcweir if ( pAutoDeactivate ) 570*cdf0e10cSrcweir pAutoDeactivate->Stop(); 571*cdf0e10cSrcweir } 572*cdf0e10cSrcweir 573*cdf0e10cSrcweir return sal_True; 574*cdf0e10cSrcweir } 575*cdf0e10cSrcweir 576*cdf0e10cSrcweir IMPL_LINK( SfxVirtualMenu, SettingsChanged, void*, EMPTYARG ) 577*cdf0e10cSrcweir { 578*cdf0e10cSrcweir sal_uInt16 nItemCount = pSVMenu->GetItemCount(); 579*cdf0e10cSrcweir SfxViewFrame *pViewFrame = pBindings->GetDispatcher()->GetFrame(); 580*cdf0e10cSrcweir sal_Bool bIcons = Application::GetSettings().GetStyleSettings().GetUseImagesInMenus(); 581*cdf0e10cSrcweir sal_Bool bIsHiContrastMode = IsHiContrastMode(); 582*cdf0e10cSrcweir Reference<com::sun::star::frame::XFrame> xFrame( pViewFrame->GetFrame().GetFrameInterface() ); 583*cdf0e10cSrcweir 584*cdf0e10cSrcweir if ( !bIsAddonPopupMenu ) 585*cdf0e10cSrcweir { 586*cdf0e10cSrcweir for ( sal_uInt16 nSVPos=0; nSVPos<nItemCount; ++nSVPos ) 587*cdf0e10cSrcweir { 588*cdf0e10cSrcweir sal_uInt16 nSlotId = pSVMenu->GetItemId( nSVPos ); 589*cdf0e10cSrcweir MenuItemType nType = pSVMenu->GetItemType( nSVPos ); 590*cdf0e10cSrcweir if ( nType == MENUITEM_STRING && bIcons ) 591*cdf0e10cSrcweir { 592*cdf0e10cSrcweir if ( framework::AddonMenuManager::IsAddonMenuId( nSlotId )) 593*cdf0e10cSrcweir { 594*cdf0e10cSrcweir // Special code for Add-On menu items. They can appear inside the help menu. 595*cdf0e10cSrcweir rtl::OUString aCmd( pSVMenu->GetItemCommand( nSlotId ) ); 596*cdf0e10cSrcweir rtl::OUString aImageId; 597*cdf0e10cSrcweir 598*cdf0e10cSrcweir ::framework::MenuConfiguration::Attributes* pMenuAttributes = 599*cdf0e10cSrcweir (::framework::MenuConfiguration::Attributes*)pSVMenu->GetUserValue( nSlotId ); 600*cdf0e10cSrcweir 601*cdf0e10cSrcweir if ( pMenuAttributes ) 602*cdf0e10cSrcweir aImageId = pMenuAttributes->aImageId; // Retrieve image id from menu attributes 603*cdf0e10cSrcweir 604*cdf0e10cSrcweir pSVMenu->SetItemImage( nSlotId, RetrieveAddOnImage( xFrame, aImageId, aCmd, sal_False, bIsHiContrastMode )); 605*cdf0e10cSrcweir } 606*cdf0e10cSrcweir else 607*cdf0e10cSrcweir { 608*cdf0e10cSrcweir rtl::OUString aSlotURL( RTL_CONSTASCII_USTRINGPARAM( "slot:" )); 609*cdf0e10cSrcweir aSlotURL += rtl::OUString::valueOf( sal_Int32( nSlotId )); 610*cdf0e10cSrcweir pSVMenu->SetItemImage( nSlotId, GetImage( xFrame, aSlotURL, sal_False, bWasHighContrast )); 611*cdf0e10cSrcweir } 612*cdf0e10cSrcweir } 613*cdf0e10cSrcweir else if( nType == MENUITEM_STRINGIMAGE && !bIcons ) 614*cdf0e10cSrcweir { 615*cdf0e10cSrcweir pSVMenu->SetItemImage( nSlotId, Image() ); 616*cdf0e10cSrcweir } 617*cdf0e10cSrcweir } 618*cdf0e10cSrcweir } 619*cdf0e10cSrcweir else 620*cdf0e10cSrcweir { 621*cdf0e10cSrcweir // Remove/update images from Add-Ons top-level popup menus when settings have changed 622*cdf0e10cSrcweir if ( !bIcons ) 623*cdf0e10cSrcweir RemoveMenuImages( pSVMenu ); 624*cdf0e10cSrcweir else 625*cdf0e10cSrcweir UpdateImages( pSVMenu ); 626*cdf0e10cSrcweir } 627*cdf0e10cSrcweir 628*cdf0e10cSrcweir // Special code to remove menu images from runtime popup menus when settings have changed 629*cdf0e10cSrcweir if ( pParent && pSVMenu == pParent->pAddonsMenu ) 630*cdf0e10cSrcweir { 631*cdf0e10cSrcweir if ( !bIcons ) 632*cdf0e10cSrcweir RemoveMenuImages( pParent->pAddonsMenu->GetPopupMenu( SID_ADDONS )); 633*cdf0e10cSrcweir else 634*cdf0e10cSrcweir UpdateImages( pParent->pAddonsMenu->GetPopupMenu( SID_ADDONS )); 635*cdf0e10cSrcweir } 636*cdf0e10cSrcweir 637*cdf0e10cSrcweir if ( pImageControl ) 638*cdf0e10cSrcweir pImageControl->Update(); 639*cdf0e10cSrcweir 640*cdf0e10cSrcweir return 0; 641*cdf0e10cSrcweir } 642*cdf0e10cSrcweir 643*cdf0e10cSrcweir //-------------------------------------------------------------------- 644*cdf0e10cSrcweir 645*cdf0e10cSrcweir void SfxVirtualMenu::UpdateImages() 646*cdf0e10cSrcweir { 647*cdf0e10cSrcweir sal_Bool bIcons = Application::GetSettings().GetStyleSettings().GetUseImagesInMenus(); 648*cdf0e10cSrcweir 649*cdf0e10cSrcweir if ( bIcons ) 650*cdf0e10cSrcweir { 651*cdf0e10cSrcweir sal_Bool bIsHiContrastMode = IsHiContrastMode(); 652*cdf0e10cSrcweir sal_uInt16 nItemCount = pSVMenu->GetItemCount(); 653*cdf0e10cSrcweir SfxViewFrame * pViewFrame = pBindings->GetDispatcher()->GetFrame(); 654*cdf0e10cSrcweir Reference<com::sun::star::frame::XFrame> xFrame( pViewFrame->GetFrame().GetFrameInterface() ); 655*cdf0e10cSrcweir 656*cdf0e10cSrcweir for ( sal_uInt16 nSVPos=0; nSVPos < nItemCount; ++nSVPos ) 657*cdf0e10cSrcweir { 658*cdf0e10cSrcweir sal_uInt16 nSlotId = pSVMenu->GetItemId( nSVPos ); 659*cdf0e10cSrcweir if ( pSVMenu->GetItemType( nSVPos ) == MENUITEM_STRINGIMAGE ) 660*cdf0e10cSrcweir { 661*cdf0e10cSrcweir if ( framework::AddonMenuManager::IsAddonMenuId( nSlotId )) 662*cdf0e10cSrcweir { 663*cdf0e10cSrcweir // Special code for Add-On menu items. They can appear inside the help menu. 664*cdf0e10cSrcweir rtl::OUString aCmd( pSVMenu->GetItemCommand( nSlotId ) ); 665*cdf0e10cSrcweir rtl::OUString aImageId; 666*cdf0e10cSrcweir 667*cdf0e10cSrcweir ::framework::MenuConfiguration::Attributes* pMenuAttributes = 668*cdf0e10cSrcweir (::framework::MenuConfiguration::Attributes*)pSVMenu->GetUserValue( nSlotId ); 669*cdf0e10cSrcweir 670*cdf0e10cSrcweir if ( pMenuAttributes ) 671*cdf0e10cSrcweir aImageId = pMenuAttributes->aImageId; // Retrieve image id from menu attributes 672*cdf0e10cSrcweir 673*cdf0e10cSrcweir pSVMenu->SetItemImage( nSlotId, RetrieveAddOnImage( xFrame, aImageId, aCmd, sal_False, bIsHiContrastMode )); 674*cdf0e10cSrcweir } 675*cdf0e10cSrcweir else 676*cdf0e10cSrcweir { 677*cdf0e10cSrcweir rtl::OUString aSlotURL( RTL_CONSTASCII_USTRINGPARAM( "slot:" )); 678*cdf0e10cSrcweir aSlotURL += rtl::OUString::valueOf( sal_Int32( nSlotId )); 679*cdf0e10cSrcweir pSVMenu->SetItemImage( nSlotId, GetImage( xFrame, aSlotURL, sal_False, bWasHighContrast )); 680*cdf0e10cSrcweir } 681*cdf0e10cSrcweir } 682*cdf0e10cSrcweir } 683*cdf0e10cSrcweir 684*cdf0e10cSrcweir if ( pImageControl ) 685*cdf0e10cSrcweir pImageControl->Update(); 686*cdf0e10cSrcweir } 687*cdf0e10cSrcweir } 688*cdf0e10cSrcweir 689*cdf0e10cSrcweir //-------------------------------------------------------------------- 690*cdf0e10cSrcweir 691*cdf0e10cSrcweir void SfxVirtualMenu::UpdateImages( Menu* pMenu ) 692*cdf0e10cSrcweir { 693*cdf0e10cSrcweir if ( !pMenu ) 694*cdf0e10cSrcweir return; 695*cdf0e10cSrcweir 696*cdf0e10cSrcweir framework::AddonsOptions aAddonOptions; 697*cdf0e10cSrcweir 698*cdf0e10cSrcweir sal_Bool bIcons = Application::GetSettings().GetStyleSettings().GetUseImagesInMenus(); 699*cdf0e10cSrcweir if ( bIcons ) 700*cdf0e10cSrcweir { 701*cdf0e10cSrcweir sal_Bool bIsHiContrastMode = IsHiContrastMode(); 702*cdf0e10cSrcweir sal_uInt16 nItemCount = pMenu->GetItemCount(); 703*cdf0e10cSrcweir Reference<com::sun::star::frame::XFrame> aXFrame( pBindings->GetDispatcher_Impl()->GetFrame()->GetFrame().GetFrameInterface() ); 704*cdf0e10cSrcweir 705*cdf0e10cSrcweir for ( sal_uInt16 nPos=0; nPos < nItemCount; ++nPos ) 706*cdf0e10cSrcweir { 707*cdf0e10cSrcweir sal_uInt16 nSlotId = pMenu->GetItemId( nPos ); 708*cdf0e10cSrcweir PopupMenu* pPopup = pMenu->GetPopupMenu( nSlotId ); 709*cdf0e10cSrcweir if ( pMenu->GetItemType( nPos ) != MENUITEM_SEPARATOR ) 710*cdf0e10cSrcweir { 711*cdf0e10cSrcweir rtl::OUString aImageId; 712*cdf0e10cSrcweir 713*cdf0e10cSrcweir ::framework::MenuConfiguration::Attributes* pMenuAttributes = 714*cdf0e10cSrcweir (::framework::MenuConfiguration::Attributes*)pMenu->GetUserValue( nSlotId ); 715*cdf0e10cSrcweir 716*cdf0e10cSrcweir if ( pMenuAttributes ) 717*cdf0e10cSrcweir aImageId = pMenuAttributes->aImageId; // Retrieve image id from menu attributes 718*cdf0e10cSrcweir 719*cdf0e10cSrcweir pMenu->SetItemImage( nSlotId, RetrieveAddOnImage( aXFrame, aImageId, pMenu->GetItemCommand( nSlotId ), sal_False, bIsHiContrastMode )); 720*cdf0e10cSrcweir } 721*cdf0e10cSrcweir 722*cdf0e10cSrcweir if ( pPopup ) 723*cdf0e10cSrcweir UpdateImages( pPopup ); 724*cdf0e10cSrcweir } 725*cdf0e10cSrcweir 726*cdf0e10cSrcweir if ( pImageControl ) 727*cdf0e10cSrcweir pImageControl->Update(); 728*cdf0e10cSrcweir } 729*cdf0e10cSrcweir } 730*cdf0e10cSrcweir 731*cdf0e10cSrcweir //-------------------------------------------------------------------- 732*cdf0e10cSrcweir 733*cdf0e10cSrcweir void SfxVirtualMenu::RemoveMenuImages( Menu* pMenu ) 734*cdf0e10cSrcweir { 735*cdf0e10cSrcweir if ( !pMenu ) 736*cdf0e10cSrcweir return; 737*cdf0e10cSrcweir 738*cdf0e10cSrcweir sal_uInt16 nItemCount = pMenu->GetItemCount(); 739*cdf0e10cSrcweir for ( sal_uInt16 nPos=0; nPos < nItemCount; ++nPos ) 740*cdf0e10cSrcweir { 741*cdf0e10cSrcweir sal_uInt16 nSlotId = pMenu->GetItemId( nPos ); 742*cdf0e10cSrcweir PopupMenu* pPopup = pMenu->GetPopupMenu( nSlotId ); 743*cdf0e10cSrcweir if ( pMenu->GetItemType( nPos ) == MENUITEM_STRINGIMAGE ) 744*cdf0e10cSrcweir pMenu->SetItemImage( nSlotId, Image() ); 745*cdf0e10cSrcweir if ( pPopup ) 746*cdf0e10cSrcweir RemoveMenuImages( pPopup ); 747*cdf0e10cSrcweir } 748*cdf0e10cSrcweir } 749*cdf0e10cSrcweir 750*cdf0e10cSrcweir //-------------------------------------------------------------------- 751*cdf0e10cSrcweir 752*cdf0e10cSrcweir bool SfxVirtualMenu::Bind_Impl( Menu *pMenu ) 753*cdf0e10cSrcweir { 754*cdf0e10cSrcweir // Selber suchen, da SV mit 'sal_uInt16 nSID = pSVMenu->GetCurItemId();' immer 755*cdf0e10cSrcweir // 0 liefert. Das ist so, weil die Event-Weiterleitung lt. TH nichts mit 756*cdf0e10cSrcweir // CurItem des Parent-Menus zu tun hat. 757*cdf0e10cSrcweir sal_uInt32 nAddonsPopupPrefixLen = ADDONSPOPUPMENU_URL_PREFIX.getLength(); 758*cdf0e10cSrcweir 759*cdf0e10cSrcweir for ( sal_uInt16 nPos = 0; nPos < nCount; ++nPos ) 760*cdf0e10cSrcweir { 761*cdf0e10cSrcweir // angesprochenes Sub-Menu gefunden? 762*cdf0e10cSrcweir bool bFound = false; 763*cdf0e10cSrcweir sal_uInt16 nSID = pSVMenu->GetItemId(nPos); 764*cdf0e10cSrcweir SfxMenuControl &rCtrl = pItems[nPos]; 765*cdf0e10cSrcweir bFound = pSVMenu->GetPopupMenu(nSID) == pMenu; 766*cdf0e10cSrcweir SfxVirtualMenu *pSubMenu = rCtrl.GetPopupMenu(); 767*cdf0e10cSrcweir 768*cdf0e10cSrcweir if ( bFound ) 769*cdf0e10cSrcweir { 770*cdf0e10cSrcweir // Nur ein gebundener Menu-Controller hat schon seine Id! 771*cdf0e10cSrcweir if ( !rCtrl.GetId() ) 772*cdf0e10cSrcweir { 773*cdf0e10cSrcweir bIsAddonPopupMenu = sal_False; 774*cdf0e10cSrcweir DBG_ASSERT( !pSubMenu, "Popup schon vorhanden!"); 775*cdf0e10cSrcweir 776*cdf0e10cSrcweir // Check if the popup is an Add-On popup menu 777*cdf0e10cSrcweir // Either the popup menu has a special ID or a special command URL prefix! 778*cdf0e10cSrcweir rtl::OUString aCommand = pSVMenu->GetItemCommand( nSID ); 779*cdf0e10cSrcweir if ( ( nSID == SID_ADDONS ) || 780*cdf0e10cSrcweir ( nSID == SID_ADDONHELP ) || 781*cdf0e10cSrcweir (( (sal_uInt32)aCommand.getLength() > nAddonsPopupPrefixLen ) && 782*cdf0e10cSrcweir ( aCommand.indexOf( ADDONSPOPUPMENU_URL_PREFIX ) == 0 )) ) 783*cdf0e10cSrcweir bIsAddonPopupMenu = sal_True; 784*cdf0e10cSrcweir 785*cdf0e10cSrcweir // VirtualMenu f"ur Sub-Menu erzeugen 786*cdf0e10cSrcweir sal_Bool bRes = bResCtor; 787*cdf0e10cSrcweir pSubMenu = new SfxVirtualMenu( nSID, this, 788*cdf0e10cSrcweir *pMenu, sal_False, *pBindings, bOLE, bRes, bIsAddonPopupMenu ); 789*cdf0e10cSrcweir 790*cdf0e10cSrcweir DBG_OUTF( ("Neues VirtualMenu %lx erzeugt", pSubMenu) ); 791*cdf0e10cSrcweir 792*cdf0e10cSrcweir rCtrl.Bind( this, nSID, *pSubMenu, 793*cdf0e10cSrcweir pSVMenu->GetItemText(nSID), pSVMenu->GetHelpText(nSID), 794*cdf0e10cSrcweir *pBindings ); 795*cdf0e10cSrcweir 796*cdf0e10cSrcweir // Activate weiterleiten 797*cdf0e10cSrcweir pSubMenu->Bind_Impl( pMenu ); 798*cdf0e10cSrcweir pSubMenu->Activate( pMenu ); 799*cdf0e10cSrcweir } 800*cdf0e10cSrcweir } 801*cdf0e10cSrcweir 802*cdf0e10cSrcweir // rekursiv weitersuchen (SV Activate nur am Menu selbst und Top-Menu) 803*cdf0e10cSrcweir if ( !bFound && pSubMenu ) 804*cdf0e10cSrcweir bFound = pSubMenu->Bind_Impl( pMenu ); 805*cdf0e10cSrcweir 806*cdf0e10cSrcweir // gefunden, dann abbrechen 807*cdf0e10cSrcweir if ( bFound ) 808*cdf0e10cSrcweir return true; 809*cdf0e10cSrcweir } 810*cdf0e10cSrcweir 811*cdf0e10cSrcweir // nicht in diesem Untermenu gefunden 812*cdf0e10cSrcweir return false; 813*cdf0e10cSrcweir } 814*cdf0e10cSrcweir 815*cdf0e10cSrcweir void SfxVirtualMenu::BindControllers() 816*cdf0e10cSrcweir { 817*cdf0e10cSrcweir pBindings->ENTERREGISTRATIONS(); 818*cdf0e10cSrcweir 819*cdf0e10cSrcweir sal_uInt16 nPos; 820*cdf0e10cSrcweir for ( nPos = 0; nPos < nCount; ++nPos ) 821*cdf0e10cSrcweir { 822*cdf0e10cSrcweir SfxMenuControl& rCtrl = pItems[nPos]; 823*cdf0e10cSrcweir if ( rCtrl.IsBindable_Impl() && !rCtrl.GetPopupMenu() ) 824*cdf0e10cSrcweir rCtrl.ReBind(); 825*cdf0e10cSrcweir } 826*cdf0e10cSrcweir 827*cdf0e10cSrcweir SfxMenuCtrlArr_Impl& rCtrlArr = GetAppCtrl_Impl(); 828*cdf0e10cSrcweir for ( nPos=0; nPos<rCtrlArr.Count(); nPos++ ) 829*cdf0e10cSrcweir { 830*cdf0e10cSrcweir SfxMenuControl* pCtrl = rCtrlArr[nPos]; 831*cdf0e10cSrcweir sal_uInt16 nSlotId = pCtrl->GetId(); 832*cdf0e10cSrcweir if ( !pSVMenu->GetItemCommand(nSlotId).Len() ) 833*cdf0e10cSrcweir pCtrl->ReBind(); 834*cdf0e10cSrcweir } 835*cdf0e10cSrcweir 836*cdf0e10cSrcweir pBindings->LEAVEREGISTRATIONS(); 837*cdf0e10cSrcweir bControllersUnBound = sal_False; 838*cdf0e10cSrcweir } 839*cdf0e10cSrcweir 840*cdf0e10cSrcweir void SfxVirtualMenu::UnbindControllers() 841*cdf0e10cSrcweir { 842*cdf0e10cSrcweir pBindings->ENTERREGISTRATIONS(); 843*cdf0e10cSrcweir 844*cdf0e10cSrcweir sal_uInt16 nPos; 845*cdf0e10cSrcweir for ( nPos = 0; nPos < nCount; ++nPos ) 846*cdf0e10cSrcweir { 847*cdf0e10cSrcweir SfxMenuControl &rCtrl = pItems[nPos]; 848*cdf0e10cSrcweir if ( rCtrl.IsBound() ) 849*cdf0e10cSrcweir rCtrl.UnBind(); 850*cdf0e10cSrcweir } 851*cdf0e10cSrcweir 852*cdf0e10cSrcweir SfxMenuCtrlArr_Impl& rCtrlArr = GetAppCtrl_Impl(); 853*cdf0e10cSrcweir for ( nPos=0; nPos<rCtrlArr.Count(); nPos++ ) 854*cdf0e10cSrcweir { 855*cdf0e10cSrcweir SfxMenuControl* pCtrl = rCtrlArr[nPos]; 856*cdf0e10cSrcweir if ( pCtrl->IsBound() ) 857*cdf0e10cSrcweir // UnoController sind nicht gebunden! 858*cdf0e10cSrcweir pCtrl->UnBind(); 859*cdf0e10cSrcweir } 860*cdf0e10cSrcweir 861*cdf0e10cSrcweir pBindings->LEAVEREGISTRATIONS(); 862*cdf0e10cSrcweir bControllersUnBound = sal_True; 863*cdf0e10cSrcweir } 864*cdf0e10cSrcweir 865*cdf0e10cSrcweir 866*cdf0e10cSrcweir //-------------------------------------------------------------------- 867*cdf0e10cSrcweir void SfxVirtualMenu::InsertAddOnsMenuItem( Menu* pMenu ) 868*cdf0e10cSrcweir { 869*cdf0e10cSrcweir // Create special popup menu that is filled with the 3rd party components popup menu items 870*cdf0e10cSrcweir Reference<com::sun::star::lang::XMultiServiceFactory> aXMultiServiceFactory(::comphelper::getProcessServiceFactory()); 871*cdf0e10cSrcweir ::framework::MenuConfiguration aConf( aXMultiServiceFactory ); 872*cdf0e10cSrcweir Reference<com::sun::star::frame::XFrame> xFrame( pBindings->GetDispatcher_Impl()->GetFrame()->GetFrame().GetFrameInterface() ); 873*cdf0e10cSrcweir 874*cdf0e10cSrcweir PopupMenu* pAddonMenu = NULL; 875*cdf0e10cSrcweir try 876*cdf0e10cSrcweir { 877*cdf0e10cSrcweir pAddonMenu = framework::AddonMenuManager::CreateAddonMenu( xFrame ); 878*cdf0e10cSrcweir } 879*cdf0e10cSrcweir catch ( ::com::sun::star::lang::WrappedTargetException ) 880*cdf0e10cSrcweir { 881*cdf0e10cSrcweir } 882*cdf0e10cSrcweir 883*cdf0e10cSrcweir // Create menu item at the end of the tools popup menu for the addons popup menu 884*cdf0e10cSrcweir if ( pAddonMenu && pAddonMenu->GetItemCount() > 0 ) 885*cdf0e10cSrcweir { 886*cdf0e10cSrcweir sal_uInt16 nItemCount = pMenu->GetItemCount(); 887*cdf0e10cSrcweir String aAddonsTitle( SfxResId( STR_MENU_ADDONS )); 888*cdf0e10cSrcweir if ( nItemCount > 0 && pMenu->GetItemType( nItemCount-1 ) != MENUITEM_SEPARATOR ) 889*cdf0e10cSrcweir pMenu->InsertSeparator(); 890*cdf0e10cSrcweir pMenu->InsertItem( SID_ADDONS, aAddonsTitle ); 891*cdf0e10cSrcweir pMenu->SetPopupMenu( SID_ADDONS, pAddonMenu ); 892*cdf0e10cSrcweir 893*cdf0e10cSrcweir if ( Application::GetSettings().GetStyleSettings().GetUseImagesInMenus() ) 894*cdf0e10cSrcweir { 895*cdf0e10cSrcweir rtl::OUString aSlotURL( RTL_CONSTASCII_USTRINGPARAM( "slot:" )); 896*cdf0e10cSrcweir aSlotURL += rtl::OUString::valueOf( sal_Int32( SID_ADDONS )); 897*cdf0e10cSrcweir pMenu->SetItemImage( SID_ADDONS, GetImage( xFrame, aSlotURL, sal_False, bWasHighContrast )); 898*cdf0e10cSrcweir } 899*cdf0e10cSrcweir } 900*cdf0e10cSrcweir else 901*cdf0e10cSrcweir delete pAddonMenu; 902*cdf0e10cSrcweir } 903*cdf0e10cSrcweir 904*cdf0e10cSrcweir //-------------------------------------------------------------------- 905*cdf0e10cSrcweir 906*cdf0e10cSrcweir // called on activation of the SV-Menu 907*cdf0e10cSrcweir 908*cdf0e10cSrcweir IMPL_LINK( SfxVirtualMenu, Activate, Menu *, pMenu ) 909*cdf0e10cSrcweir { 910*cdf0e10cSrcweir DBG_MEMTEST(); 911*cdf0e10cSrcweir DBG_CHKTHIS(SfxVirtualMenu, 0); 912*cdf0e10cSrcweir DBG_OUTF( ("SfxVirtualMenu %lx activated %lx, own %lx", this, pMenu, pSVMenu)); 913*cdf0e10cSrcweir 914*cdf0e10cSrcweir // MI: wozu war der noch gut? 915*cdf0e10cSrcweir // MBA: scheint ein alter QAP-Hack gewesen zu sein ( in rev.1.41 eingecheckt ! ) 916*cdf0e10cSrcweir // if ( Application::IsInModalMode() ) 917*cdf0e10cSrcweir // return TRUE; // abw"urgen 918*cdf0e10cSrcweir 919*cdf0e10cSrcweir if ( pMenu ) 920*cdf0e10cSrcweir { 921*cdf0e10cSrcweir sal_Bool bDontHide = SvtMenuOptions().IsEntryHidingEnabled(); 922*cdf0e10cSrcweir sal_uInt16 nFlag = pMenu->GetMenuFlags(); 923*cdf0e10cSrcweir if ( bDontHide ) 924*cdf0e10cSrcweir nFlag &= ~MENU_FLAG_HIDEDISABLEDENTRIES; 925*cdf0e10cSrcweir else 926*cdf0e10cSrcweir nFlag |= MENU_FLAG_HIDEDISABLEDENTRIES; 927*cdf0e10cSrcweir pMenu->SetMenuFlags( nFlag ); 928*cdf0e10cSrcweir } 929*cdf0e10cSrcweir 930*cdf0e10cSrcweir // eigenes StarView-Menu 931*cdf0e10cSrcweir if ( pMenu == pSVMenu ) 932*cdf0e10cSrcweir { 933*cdf0e10cSrcweir // doppelt-Activate verhindern 934*cdf0e10cSrcweir if ( bIsActive ) 935*cdf0e10cSrcweir return sal_True; 936*cdf0e10cSrcweir 937*cdf0e10cSrcweir // ggf. Pick-Menu erzeugen 938*cdf0e10cSrcweir if ( pParent && pSVMenu == pParent->pPickMenu ) 939*cdf0e10cSrcweir { 940*cdf0e10cSrcweir SfxPickList::Get()->CreateMenuEntries( pParent->pPickMenu ); 941*cdf0e10cSrcweir } 942*cdf0e10cSrcweir else 943*cdf0e10cSrcweir pPickMenu = pSVMenu->GetPopupMenu(SID_PICKLIST); 944*cdf0e10cSrcweir 945*cdf0e10cSrcweir if ( pParent && pSVMenu == pParent->pWindowMenu ) 946*cdf0e10cSrcweir { 947*cdf0e10cSrcweir // update window list 948*cdf0e10cSrcweir ::std::vector< ::rtl::OUString > aNewWindowListVector; 949*cdf0e10cSrcweir Reference< XDesktop > xDesktop( ::comphelper::getProcessServiceFactory()->createInstance( 950*cdf0e10cSrcweir DEFINE_CONST_OUSTRING( "com.sun.star.frame.Desktop" ) ), UNO_QUERY ); 951*cdf0e10cSrcweir 952*cdf0e10cSrcweir sal_uInt16 nActiveItemId = 0; 953*cdf0e10cSrcweir sal_uInt16 nItemId = START_ITEMID_WINDOWLIST; 954*cdf0e10cSrcweir 955*cdf0e10cSrcweir if ( xDesktop.is() ) 956*cdf0e10cSrcweir { 957*cdf0e10cSrcweir Reference< XFramesSupplier > xTasksSupplier( xDesktop, UNO_QUERY ); 958*cdf0e10cSrcweir Reference< XFrame > xCurrentFrame = xDesktop->getCurrentFrame(); 959*cdf0e10cSrcweir Reference< XIndexAccess > xList ( xTasksSupplier->getFrames(), UNO_QUERY ); 960*cdf0e10cSrcweir sal_Int32 nFrameCount = xList->getCount(); 961*cdf0e10cSrcweir for( sal_Int32 i=0; i<nFrameCount; ++i ) 962*cdf0e10cSrcweir { 963*cdf0e10cSrcweir Reference< XFrame > xFrame; 964*cdf0e10cSrcweir Any aVal = xList->getByIndex(i); 965*cdf0e10cSrcweir if (!(aVal>>=xFrame) || !xFrame.is() ) 966*cdf0e10cSrcweir continue; 967*cdf0e10cSrcweir 968*cdf0e10cSrcweir if ( xFrame == xCurrentFrame ) 969*cdf0e10cSrcweir nActiveItemId = nItemId; 970*cdf0e10cSrcweir 971*cdf0e10cSrcweir Window* pWin = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() ); 972*cdf0e10cSrcweir if ( pWin && pWin->IsVisible() ) 973*cdf0e10cSrcweir { 974*cdf0e10cSrcweir aNewWindowListVector.push_back( pWin->GetText() ); 975*cdf0e10cSrcweir ++nItemId; 976*cdf0e10cSrcweir } 977*cdf0e10cSrcweir } 978*cdf0e10cSrcweir } 979*cdf0e10cSrcweir 980*cdf0e10cSrcweir int nItemCount = pMenu->GetItemCount(); 981*cdf0e10cSrcweir 982*cdf0e10cSrcweir if ( nItemCount > 0 ) 983*cdf0e10cSrcweir { 984*cdf0e10cSrcweir // remove all old window list entries from menu 985*cdf0e10cSrcweir sal_uInt16 nPos = pMenu->GetItemPos( START_ITEMID_WINDOWLIST ); 986*cdf0e10cSrcweir for ( sal_uInt16 n = nPos; n < pMenu->GetItemCount(); ) 987*cdf0e10cSrcweir pMenu->RemoveItem( n ); 988*cdf0e10cSrcweir 989*cdf0e10cSrcweir if ( pMenu->GetItemType( pMenu->GetItemCount()-1 ) == MENUITEM_SEPARATOR ) 990*cdf0e10cSrcweir pMenu->RemoveItem( pMenu->GetItemCount()-1 ); 991*cdf0e10cSrcweir } 992*cdf0e10cSrcweir 993*cdf0e10cSrcweir if ( aNewWindowListVector.size() > 0 ) 994*cdf0e10cSrcweir { 995*cdf0e10cSrcweir // append new window list entries to menu 996*cdf0e10cSrcweir pMenu->InsertSeparator(); 997*cdf0e10cSrcweir nItemId = START_ITEMID_WINDOWLIST; 998*cdf0e10cSrcweir for ( sal_uInt32 i = 0; i < aNewWindowListVector.size(); i++ ) 999*cdf0e10cSrcweir { 1000*cdf0e10cSrcweir pMenu->InsertItem( nItemId, aNewWindowListVector.at( i ), MIB_RADIOCHECK ); 1001*cdf0e10cSrcweir if ( nItemId == nActiveItemId ) 1002*cdf0e10cSrcweir pMenu->CheckItem( nItemId ); 1003*cdf0e10cSrcweir ++nItemId; 1004*cdf0e10cSrcweir } 1005*cdf0e10cSrcweir } 1006*cdf0e10cSrcweir } 1007*cdf0e10cSrcweir else 1008*cdf0e10cSrcweir pWindowMenu = pSVMenu->GetPopupMenu(SID_MDIWINDOWLIST); 1009*cdf0e10cSrcweir 1010*cdf0e10cSrcweir if ( !pParent && pSVMenu->IsMenuBar() && !pAddonsMenu ) 1011*cdf0e10cSrcweir { 1012*cdf0e10cSrcweir // Store Add-Ons parents of our runtime menu items 1013*cdf0e10cSrcweir pAddonsMenu = pSVMenu->GetPopupMenu( SID_ADDONLIST ); 1014*cdf0e10cSrcweir } 1015*cdf0e10cSrcweir 1016*cdf0e10cSrcweir // f"ur konstistenten Status sorgen 1017*cdf0e10cSrcweir if ( bControllersUnBound ) 1018*cdf0e10cSrcweir BindControllers(); 1019*cdf0e10cSrcweir 1020*cdf0e10cSrcweir //InvalidateKeyCodes(); 1021*cdf0e10cSrcweir pBindings->GetDispatcher_Impl()->Flush(); 1022*cdf0e10cSrcweir for ( sal_uInt16 nPos = 0; nPos < nCount; ++nPos ) 1023*cdf0e10cSrcweir { 1024*cdf0e10cSrcweir sal_uInt16 nSlotId = (pItems+nPos)->GetId(); 1025*cdf0e10cSrcweir if ( nSlotId && nSlotId > END_ITEMID_WINDOWLIST ) 1026*cdf0e10cSrcweir pBindings->Update(nSlotId); 1027*cdf0e10cSrcweir } 1028*cdf0e10cSrcweir 1029*cdf0e10cSrcweir pBindings->Update( SID_IMAGE_ORIENTATION ); 1030*cdf0e10cSrcweir 1031*cdf0e10cSrcweir // HelpText on-demand 1032*cdf0e10cSrcweir if ( !bHelpInitialized ) 1033*cdf0e10cSrcweir { 1034*cdf0e10cSrcweir // TODO/CLEANUP: do we need help texts in context menus? 1035*cdf0e10cSrcweir // old way with SlotInfo doesn't work anymore 1036*cdf0e10cSrcweir } 1037*cdf0e10cSrcweir 1038*cdf0e10cSrcweir // bis zum Deactivate die Statusupdates unterdr"ucken 1039*cdf0e10cSrcweir pBindings->ENTERREGISTRATIONS(); ++nLocks; bIsActive = sal_True; 1040*cdf0e10cSrcweir 1041*cdf0e10cSrcweir if ( pAutoDeactivate ) // QAP-Hack 1042*cdf0e10cSrcweir pAutoDeactivate->Start(); 1043*cdf0e10cSrcweir 1044*cdf0e10cSrcweir if ( IsHiContrastMode() != bWasHighContrast ) 1045*cdf0e10cSrcweir { 1046*cdf0e10cSrcweir // Refresh images as our background color changed and remember it!! 1047*cdf0e10cSrcweir bWasHighContrast = IsHiContrastMode(); 1048*cdf0e10cSrcweir if ( bIsAddonPopupMenu ) 1049*cdf0e10cSrcweir UpdateImages( pSVMenu ); 1050*cdf0e10cSrcweir else 1051*cdf0e10cSrcweir UpdateImages(); 1052*cdf0e10cSrcweir } 1053*cdf0e10cSrcweir 1054*cdf0e10cSrcweir // erledigt 1055*cdf0e10cSrcweir return sal_True; 1056*cdf0e10cSrcweir } 1057*cdf0e10cSrcweir else 1058*cdf0e10cSrcweir { 1059*cdf0e10cSrcweir // VirtualMenu fuer SubMenu finden und ggf. an VirtualMenu binden 1060*cdf0e10cSrcweir bool bRet = Bind_Impl( pMenu ); 1061*cdf0e10cSrcweir #ifdef DBG_UTIL 1062*cdf0e10cSrcweir if ( !bRet) 1063*cdf0e10cSrcweir DBG_WARNING( "W1: Virtual menu konnte nicht erzeugt werden!" ); 1064*cdf0e10cSrcweir #endif 1065*cdf0e10cSrcweir return bRet; 1066*cdf0e10cSrcweir } 1067*cdf0e10cSrcweir } 1068*cdf0e10cSrcweir 1069*cdf0e10cSrcweir //-------------------------------------------------------------------- 1070*cdf0e10cSrcweir 1071*cdf0e10cSrcweir IMPL_LINK( SfxVirtualMenu, Deactivate, Menu *, pMenu ) 1072*cdf0e10cSrcweir { 1073*cdf0e10cSrcweir DBG_MEMTEST(); 1074*cdf0e10cSrcweir DBG_OUTF( ("SfxVirtualMenu %lx deactivated %lx, own %lx", this, pMenu, pSVMenu) ); 1075*cdf0e10cSrcweir if ( bIsActive && ( 0 == pMenu || pMenu == pSVMenu ) ) 1076*cdf0e10cSrcweir { 1077*cdf0e10cSrcweir if ( pAutoDeactivate ) 1078*cdf0e10cSrcweir pAutoDeactivate->Stop(); 1079*cdf0e10cSrcweir 1080*cdf0e10cSrcweir // Bis auf die Menubar k"onnen alle Controller unbinded werden, wenn 1081*cdf0e10cSrcweir // das Menue deaktiviert ( = zugeklappt ) wird 1082*cdf0e10cSrcweir if ( pParent ) 1083*cdf0e10cSrcweir UnbindControllers(); 1084*cdf0e10cSrcweir pBindings->LEAVEREGISTRATIONS(); --nLocks; bIsActive = sal_False; 1085*cdf0e10cSrcweir } 1086*cdf0e10cSrcweir return sal_True; 1087*cdf0e10cSrcweir } 1088*cdf0e10cSrcweir //-------------------------------------------------------------------- 1089*cdf0e10cSrcweir 1090*cdf0e10cSrcweir // called on activation of the SV-Menu 1091*cdf0e10cSrcweir 1092*cdf0e10cSrcweir IMPL_LINK( SfxVirtualMenu, Select, Menu *, pMenu ) 1093*cdf0e10cSrcweir { 1094*cdf0e10cSrcweir sal_uInt16 nSlotId = (sal_uInt16) pMenu->GetCurItemId(); 1095*cdf0e10cSrcweir DBG_OUTF( ("SfxVirtualMenu %lx selected %u from %lx", this, nSlotId, pMenu) ); 1096*cdf0e10cSrcweir /* 1097*cdf0e10cSrcweir if ( pSVMenu->GetItemCommand( nSlotId ).Len() ) 1098*cdf0e10cSrcweir { 1099*cdf0e10cSrcweir SfxMenuCtrlArr_Impl& rCtrlArr = GetAppCtrl_Impl(); 1100*cdf0e10cSrcweir for ( sal_uInt16 nPos=0; nPos<rCtrlArr.Count(); nPos++ ) 1101*cdf0e10cSrcweir { 1102*cdf0e10cSrcweir SfxMenuControl* pCtrl = rCtrlArr[nPos]; 1103*cdf0e10cSrcweir if ( pCtrl->GetId() == nSlotId ) 1104*cdf0e10cSrcweir { 1105*cdf0e10cSrcweir SfxUnoMenuControl *pUnoCtrl = (SfxUnoMenuControl*) pCtrl; 1106*cdf0e10cSrcweir pUnoCtrl->Select(); 1107*cdf0e10cSrcweir return sal_True; 1108*cdf0e10cSrcweir } 1109*cdf0e10cSrcweir } 1110*cdf0e10cSrcweir } 1111*cdf0e10cSrcweir */ 1112*cdf0e10cSrcweir if ( nSlotId >= START_ITEMID_WINDOWLIST && nSlotId <= END_ITEMID_WINDOWLIST ) 1113*cdf0e10cSrcweir { 1114*cdf0e10cSrcweir // window list menu item selected 1115*cdf0e10cSrcweir Reference< XFramesSupplier > xDesktop( ::comphelper::getProcessServiceFactory()->createInstance( 1116*cdf0e10cSrcweir DEFINE_CONST_OUSTRING( "com.sun.star.frame.Desktop" ) ), UNO_QUERY ); 1117*cdf0e10cSrcweir if ( xDesktop.is() ) 1118*cdf0e10cSrcweir { 1119*cdf0e10cSrcweir sal_uInt16 nTaskId = START_ITEMID_WINDOWLIST; 1120*cdf0e10cSrcweir Reference< XIndexAccess > xList( xDesktop->getFrames(), UNO_QUERY ); 1121*cdf0e10cSrcweir sal_Int32 nFrameCount = xList->getCount(); 1122*cdf0e10cSrcweir for ( sal_Int32 i=0; i<nFrameCount; ++i ) 1123*cdf0e10cSrcweir { 1124*cdf0e10cSrcweir Any aItem = xList->getByIndex(i); 1125*cdf0e10cSrcweir Reference< XFrame > xFrame; 1126*cdf0e10cSrcweir if (( aItem >>= xFrame ) && xFrame.is() && nTaskId == nSlotId ) 1127*cdf0e10cSrcweir { 1128*cdf0e10cSrcweir Window* pWin = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() ); 1129*cdf0e10cSrcweir pWin->GrabFocus(); 1130*cdf0e10cSrcweir pWin->ToTop( TOTOP_RESTOREWHENMIN ); 1131*cdf0e10cSrcweir break; 1132*cdf0e10cSrcweir } 1133*cdf0e10cSrcweir 1134*cdf0e10cSrcweir nTaskId++; 1135*cdf0e10cSrcweir } 1136*cdf0e10cSrcweir } 1137*cdf0e10cSrcweir 1138*cdf0e10cSrcweir return sal_True; 1139*cdf0e10cSrcweir } 1140*cdf0e10cSrcweir else if ( nSlotId >= START_ITEMID_PICKLIST && nSlotId <= END_ITEMID_PICKLIST ) 1141*cdf0e10cSrcweir { 1142*cdf0e10cSrcweir SfxPickList::Get()->ExecuteMenuEntry( nSlotId ); 1143*cdf0e10cSrcweir return sal_True; 1144*cdf0e10cSrcweir } 1145*cdf0e10cSrcweir 1146*cdf0e10cSrcweir if ( pMenu->GetItemCommand( nSlotId ).Len() ) 1147*cdf0e10cSrcweir pBindings->ExecuteCommand_Impl( pMenu->GetItemCommand( nSlotId ) ); 1148*cdf0e10cSrcweir else 1149*cdf0e10cSrcweir pBindings->Execute( nSlotId ); 1150*cdf0e10cSrcweir 1151*cdf0e10cSrcweir return sal_True; 1152*cdf0e10cSrcweir } 1153*cdf0e10cSrcweir 1154*cdf0e10cSrcweir //-------------------------------------------------------------------- 1155*cdf0e10cSrcweir 1156*cdf0e10cSrcweir // returns the associated StarView-menu 1157*cdf0e10cSrcweir 1158*cdf0e10cSrcweir Menu* SfxVirtualMenu::GetSVMenu() const 1159*cdf0e10cSrcweir { 1160*cdf0e10cSrcweir DBG_MEMTEST(); 1161*cdf0e10cSrcweir DBG_CHKTHIS(SfxVirtualMenu, 0); 1162*cdf0e10cSrcweir 1163*cdf0e10cSrcweir return pSVMenu; 1164*cdf0e10cSrcweir } 1165*cdf0e10cSrcweir 1166*cdf0e10cSrcweir //-------------------------------------------------------------------- 1167*cdf0e10cSrcweir 1168*cdf0e10cSrcweir // return the position of the specified item 1169*cdf0e10cSrcweir 1170*cdf0e10cSrcweir sal_uInt16 SfxVirtualMenu::GetItemPos( sal_uInt16 nItemId ) const 1171*cdf0e10cSrcweir { 1172*cdf0e10cSrcweir DBG_MEMTEST(); 1173*cdf0e10cSrcweir DBG_CHKTHIS(SfxVirtualMenu, 0); 1174*cdf0e10cSrcweir 1175*cdf0e10cSrcweir for ( sal_uInt16 nPos = 0; nPos < nCount; ++nPos ) 1176*cdf0e10cSrcweir if ( (pItems+nPos)->GetId() == nItemId ) 1177*cdf0e10cSrcweir return nPos; 1178*cdf0e10cSrcweir return MENU_ITEM_NOTFOUND; 1179*cdf0e10cSrcweir } 1180*cdf0e10cSrcweir 1181*cdf0e10cSrcweir //-------------------------------------------------------------------- 1182*cdf0e10cSrcweir 1183*cdf0e10cSrcweir // returns the popup-menu assigned to the item or 0 if none 1184*cdf0e10cSrcweir 1185*cdf0e10cSrcweir SfxVirtualMenu* SfxVirtualMenu::GetPopupMenu( sal_uInt16 nItemId ) const 1186*cdf0e10cSrcweir { 1187*cdf0e10cSrcweir DBG_MEMTEST(); 1188*cdf0e10cSrcweir DBG_CHKTHIS(SfxVirtualMenu, 0); 1189*cdf0e10cSrcweir 1190*cdf0e10cSrcweir sal_uInt16 nPos = GetItemPos(nItemId); 1191*cdf0e10cSrcweir if ( nPos != MENU_ITEM_NOTFOUND ) 1192*cdf0e10cSrcweir return (pItems+nPos)->GetPopupMenu(); 1193*cdf0e10cSrcweir return 0; 1194*cdf0e10cSrcweir } 1195*cdf0e10cSrcweir //-------------------------------------------------------------------- 1196*cdf0e10cSrcweir 1197*cdf0e10cSrcweir // returns the text of the item as currently shown in the menu 1198*cdf0e10cSrcweir 1199*cdf0e10cSrcweir String SfxVirtualMenu::GetItemText( sal_uInt16 nSlotId ) const 1200*cdf0e10cSrcweir { 1201*cdf0e10cSrcweir DBG_MEMTEST(); 1202*cdf0e10cSrcweir DBG_CHKTHIS(SfxVirtualMenu, 0); 1203*cdf0e10cSrcweir 1204*cdf0e10cSrcweir sal_uInt16 nPos = GetItemPos(nSlotId); 1205*cdf0e10cSrcweir if ( nPos != MENU_ITEM_NOTFOUND ) 1206*cdf0e10cSrcweir return (pItems+nPos)->GetTitle(); 1207*cdf0e10cSrcweir return String(); 1208*cdf0e10cSrcweir } 1209*cdf0e10cSrcweir //-------------------------------------------------------------------- 1210*cdf0e10cSrcweir 1211*cdf0e10cSrcweir // returns the text of the item as currently shown in the menu 1212*cdf0e10cSrcweir 1213*cdf0e10cSrcweir String SfxVirtualMenu::GetItemHelpText( sal_uInt16 nSlotId ) const 1214*cdf0e10cSrcweir { 1215*cdf0e10cSrcweir DBG_MEMTEST(); 1216*cdf0e10cSrcweir DBG_CHKTHIS(SfxVirtualMenu, 0); 1217*cdf0e10cSrcweir 1218*cdf0e10cSrcweir sal_uInt16 nPos = GetItemPos(nSlotId); 1219*cdf0e10cSrcweir if ( nPos != MENU_ITEM_NOTFOUND ) 1220*cdf0e10cSrcweir return (pItems+nPos)->GetHelpText(); 1221*cdf0e10cSrcweir return String(); 1222*cdf0e10cSrcweir } 1223*cdf0e10cSrcweir 1224*cdf0e10cSrcweir //-------------------------------------------------------------------- 1225*cdf0e10cSrcweir 1226*cdf0e10cSrcweir // set the checkmark of the specified item 1227*cdf0e10cSrcweir 1228*cdf0e10cSrcweir void SfxVirtualMenu::CheckItem( sal_uInt16 nItemId, sal_Bool bCheck ) 1229*cdf0e10cSrcweir { 1230*cdf0e10cSrcweir DBG_MEMTEST(); 1231*cdf0e10cSrcweir DBG_CHKTHIS(SfxVirtualMenu, 0); 1232*cdf0e10cSrcweir DBG_ASSERT( this != 0, ""); 1233*cdf0e10cSrcweir DBG_ASSERT( pSVMenu != 0, "" ); 1234*cdf0e10cSrcweir if (pSVMenu->GetItemPos( nItemId ) != MENU_ITEM_NOTFOUND ) 1235*cdf0e10cSrcweir pSVMenu->CheckItem( nItemId, bCheck ); 1236*cdf0e10cSrcweir } 1237*cdf0e10cSrcweir //-------------------------------------------------------------------- 1238*cdf0e10cSrcweir 1239*cdf0e10cSrcweir // set the enabled-state of the specified item 1240*cdf0e10cSrcweir 1241*cdf0e10cSrcweir void SfxVirtualMenu::EnableItem( sal_uInt16 nItemId, sal_Bool bEnable ) 1242*cdf0e10cSrcweir { 1243*cdf0e10cSrcweir DBG_MEMTEST(); 1244*cdf0e10cSrcweir DBG_CHKTHIS(SfxVirtualMenu, 0); 1245*cdf0e10cSrcweir DBG_ASSERT( this != 0, ""); 1246*cdf0e10cSrcweir DBG_ASSERT( pSVMenu != 0, "" ); 1247*cdf0e10cSrcweir 1248*cdf0e10cSrcweir if (pSVMenu->GetItemPos( nItemId ) != MENU_ITEM_NOTFOUND ) 1249*cdf0e10cSrcweir pSVMenu->EnableItem( nItemId, bEnable ); 1250*cdf0e10cSrcweir } 1251*cdf0e10cSrcweir //-------------------------------------------------------------------- 1252*cdf0e10cSrcweir 1253*cdf0e10cSrcweir // set the text of the specified item 1254*cdf0e10cSrcweir 1255*cdf0e10cSrcweir void SfxVirtualMenu::SetItemText( sal_uInt16 nItemId, const String& rText ) 1256*cdf0e10cSrcweir { 1257*cdf0e10cSrcweir DBG_MEMTEST(); 1258*cdf0e10cSrcweir DBG_CHKTHIS(SfxVirtualMenu, 0); 1259*cdf0e10cSrcweir DBG_ASSERT( this != 0, ""); 1260*cdf0e10cSrcweir DBG_ASSERT( pSVMenu != 0, "" ); 1261*cdf0e10cSrcweir if (pSVMenu->GetItemPos( nItemId ) != MENU_ITEM_NOTFOUND ) 1262*cdf0e10cSrcweir pSVMenu->SetItemText( nItemId, rText ); 1263*cdf0e10cSrcweir } 1264*cdf0e10cSrcweir 1265*cdf0e10cSrcweir //-------------------------------------------------------------------- 1266*cdf0e10cSrcweir 1267*cdf0e10cSrcweir // 1268*cdf0e10cSrcweir 1269*cdf0e10cSrcweir void SfxVirtualMenu::SetPopupMenu( sal_uInt16 nItemId, PopupMenu *pMenu ) 1270*cdf0e10cSrcweir { 1271*cdf0e10cSrcweir DBG_MEMTEST(); 1272*cdf0e10cSrcweir DBG_CHKTHIS(SfxVirtualMenu, 0); 1273*cdf0e10cSrcweir 1274*cdf0e10cSrcweir if (pSVMenu->GetItemPos( nItemId ) != MENU_ITEM_NOTFOUND ) 1275*cdf0e10cSrcweir GetSVMenu()->SetPopupMenu( nItemId, pMenu ); 1276*cdf0e10cSrcweir for ( sal_uInt16 n = 0; n < nCount; ++n ) 1277*cdf0e10cSrcweir { 1278*cdf0e10cSrcweir SfxVirtualMenu *pSubMenu = (pItems+n)->GetPopupMenu(); 1279*cdf0e10cSrcweir if ( pSubMenu ) 1280*cdf0e10cSrcweir pSubMenu->SetPopupMenu( nItemId, pMenu ); 1281*cdf0e10cSrcweir } 1282*cdf0e10cSrcweir } 1283*cdf0e10cSrcweir 1284*cdf0e10cSrcweir //-------------------------------------------------------------------- 1285*cdf0e10cSrcweir 1286*cdf0e10cSrcweir // Erzwingt die Initialisierung, die sonst nur im Activate kommt 1287*cdf0e10cSrcweir 1288*cdf0e10cSrcweir void SfxVirtualMenu::InitPopup( sal_uInt16 nPos, sal_Bool /*bOLE*/ ) 1289*cdf0e10cSrcweir { 1290*cdf0e10cSrcweir DBG_MEMTEST(); 1291*cdf0e10cSrcweir DBG_CHKTHIS(SfxVirtualMenu, 0); 1292*cdf0e10cSrcweir 1293*cdf0e10cSrcweir sal_uInt16 nSID = pSVMenu->GetItemId(nPos); 1294*cdf0e10cSrcweir PopupMenu *pMenu = pSVMenu->GetPopupMenu( nSID ); 1295*cdf0e10cSrcweir 1296*cdf0e10cSrcweir DBG_ASSERT( pMenu, "Hier gibt es kein Popup!"); 1297*cdf0e10cSrcweir 1298*cdf0e10cSrcweir SfxMenuControl &rCtrl = pItems[nPos]; 1299*cdf0e10cSrcweir if ( !rCtrl.GetId() ) 1300*cdf0e10cSrcweir { 1301*cdf0e10cSrcweir // VirtualMenu f"ur Sub-Menu erzeugen 1302*cdf0e10cSrcweir sal_Bool bRes = bResCtor; 1303*cdf0e10cSrcweir SfxVirtualMenu *pSubMenu = 1304*cdf0e10cSrcweir new SfxVirtualMenu(nSID, this, *pMenu, sal_False, *pBindings, bOLE, bRes); 1305*cdf0e10cSrcweir 1306*cdf0e10cSrcweir DBG_OUTF( ("Neues VirtualMenu %lx erzeugt", pSubMenu) ); 1307*cdf0e10cSrcweir 1308*cdf0e10cSrcweir rCtrl.Bind( this, nSID, *pSubMenu, 1309*cdf0e10cSrcweir pSVMenu->GetItemText(nSID), pSVMenu->GetHelpText(nSID), 1310*cdf0e10cSrcweir *pBindings ); 1311*cdf0e10cSrcweir } 1312*cdf0e10cSrcweir } 1313*cdf0e10cSrcweir 1314*cdf0e10cSrcweir void SfxVirtualMenu::InitializeHelp() 1315*cdf0e10cSrcweir { 1316*cdf0e10cSrcweir for ( sal_uInt16 nPos = 0; nPos<pSVMenu->GetItemCount(); ++nPos ) 1317*cdf0e10cSrcweir { 1318*cdf0e10cSrcweir sal_uInt16 nSlotId = pSVMenu->GetItemId(nPos); 1319*cdf0e10cSrcweir // TODO/CLEANUP: this code does nothing! 1320*cdf0e10cSrcweir // if ( !bHelpInitialized ) 1321*cdf0e10cSrcweir // pSVMenu->SetHelpText( nId, rSlotPool.GetSlotHelpText_Impl( nId ) ); 1322*cdf0e10cSrcweir SfxMenuControl &rCtrl = pItems[nPos]; 1323*cdf0e10cSrcweir if ( nSlotId && !rCtrl.GetId() ) 1324*cdf0e10cSrcweir { 1325*cdf0e10cSrcweir InitPopup( nPos, sal_True ); 1326*cdf0e10cSrcweir } 1327*cdf0e10cSrcweir 1328*cdf0e10cSrcweir SfxVirtualMenu *pSubMenu = rCtrl.GetPopupMenu(); 1329*cdf0e10cSrcweir if ( pSubMenu ) 1330*cdf0e10cSrcweir pSubMenu->InitializeHelp(); 1331*cdf0e10cSrcweir } 1332*cdf0e10cSrcweir 1333*cdf0e10cSrcweir bHelpInitialized = sal_True; 1334*cdf0e10cSrcweir } 1335*cdf0e10cSrcweir 1336*cdf0e10cSrcweir typedef sal_uIntPtr (__LOADONCALLAPI *HelpIdFunc) ( const String& ); 1337*cdf0e10cSrcweir 1338*cdf0e10cSrcweir void SfxVirtualMenu::SetHelpIds( ResMgr *pRes ) 1339*cdf0e10cSrcweir { 1340*cdf0e10cSrcweir pResMgr = pRes; 1341*cdf0e10cSrcweir } 1342*cdf0e10cSrcweir 1343