Update ooo320-m1
[ooovba.git] / sfx2 / source / menu / virtmenu.cxx
blob5c42c0ef423d3ac795bc69afc86793db1d9ff78b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: virtmenu.cxx,v $
10 * $Revision: 1.48 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sfx2.hxx"
34 #include <sot/factory.hxx>
35 #include <svtools/menuoptions.hxx>
36 #include <svtools/imagemgr.hxx>
37 #include <svtools/imageitm.hxx>
38 #include <com/sun/star/container/XEnumeration.hpp>
39 #include <com/sun/star/frame/XDesktop.hpp>
40 #include <com/sun/star/frame/XFramesSupplier.hpp>
41 #include <comphelper/processfactory.hxx>
42 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
43 #include <toolkit/unohlp.hxx>
44 #endif
45 #include <tools/urlobj.hxx>
47 #ifndef GCC
48 #endif
50 #include "virtmenu.hxx"
51 #include <sfx2/msgpool.hxx>
52 #include "statcach.hxx"
53 #include <sfx2/msg.hxx>
54 #include "idpool.hxx"
55 #include <sfx2/mnuitem.hxx>
56 #include <sfx2/mnumgr.hxx>
57 #include <sfx2/bindings.hxx>
58 #include <sfx2/dispatch.hxx>
59 #include <sfx2/app.hxx>
60 #include "sfxtypes.hxx"
61 #include "arrdecl.hxx"
62 #include <sfx2/sfx.hrc>
63 #include <sfx2/viewsh.hxx>
64 #include "sfxpicklist.hxx"
65 #include <sfx2/macrconf.hxx>
66 #include "sfxresid.hxx"
67 #include "menu.hrc"
68 #include "imagemgr.hxx"
69 #include <sfx2/viewfrm.hxx>
70 #include <sfx2/objsh.hxx>
71 #include <framework/addonsoptions.hxx>
73 #ifndef __FRAMEWORK_CLASSES_ADDONMENUS_HXX_
74 #include <framework/addonmenu.hxx>
75 #endif
76 #include <framework/menuconfiguration.hxx>
78 using namespace ::com::sun::star::container;
79 using namespace ::com::sun::star::frame;
80 using namespace ::com::sun::star::uno;
82 //=========================================================================
84 DBG_NAME(SfxVirtualMenu)
86 //=========================================================================
88 typedef SfxMenuControl* SfxMenuControlPtr;
89 SV_IMPL_PTRARR(SfxMenuCtrlArr_Impl, SfxMenuControlPtr);
91 class SfxMenuImageControl_Impl : public SfxControllerItem
93 SfxVirtualMenu* pMenu;
94 long lRotation;
95 BOOL bIsMirrored;
97 protected:
98 virtual void StateChanged( USHORT nSID, SfxItemState eState, const SfxPoolItem* pState );
99 public:
100 SfxMenuImageControl_Impl( USHORT nSlotId, SfxBindings& rBindings, SfxVirtualMenu* pVMenu )
101 : SfxControllerItem( nSlotId, rBindings )
102 , pMenu( pVMenu )
103 , lRotation( 0 )
104 , bIsMirrored( FALSE )
106 void Update();
109 void SfxMenuImageControl_Impl::StateChanged( USHORT /*nSID*/, SfxItemState /*eState*/, const SfxPoolItem* pState )
111 const SfxImageItem* pItem = PTR_CAST( SfxImageItem, pState );
112 if ( pItem )
114 lRotation = pItem->GetRotation();
115 bIsMirrored = pItem->IsMirrored();
116 Update();
120 void SfxMenuImageControl_Impl::Update()
122 SfxViewFrame* pViewFrame = GetBindings().GetDispatcher_Impl()->GetFrame();
123 SfxModule* pModule = pViewFrame->GetObjectShell()->GetModule();
124 SfxSlotPool* pPool = pModule->GetSlotPool();
125 Menu* pSVMenu = pMenu->GetSVMenu();
126 for (USHORT nPos = 0; nPos<pSVMenu->GetItemCount(); nPos++)
128 USHORT nslotId = pSVMenu->GetItemId( nPos );
129 const SfxSlot* pSlot = pPool->GetSlot( nslotId );
130 if ( pSlot && pSlot->IsMode( SFX_SLOT_IMAGEROTATION ) )
132 pSVMenu->SetItemImageMirrorMode( nslotId, FALSE );
133 pSVMenu->SetItemImageAngle( nslotId, lRotation );
136 if ( pSlot && pSlot->IsMode( SFX_SLOT_IMAGEREFLECTION ) )
137 pSVMenu->SetItemImageMirrorMode( nslotId, bIsMirrored );
141 //=========================================================================
143 static Image RetrieveAddOnImage( Reference< com::sun::star::frame::XFrame >& rFrame,
144 const rtl::OUString& aImageId,
145 const rtl::OUString& aURL,
146 BOOL bBigImage,
147 BOOL bHiContrast )
149 Image aImage;
151 if ( aImageId.getLength() > 0 )
153 aImage = GetImage( rFrame, aImageId, bBigImage, bHiContrast );
154 if ( !!aImage )
155 return aImage;
158 aImage = GetImage( rFrame, aURL, bBigImage, bHiContrast );
159 if ( !aImage )
160 aImage = framework::AddonsOptions().GetImageFromURL( aURL, bBigImage, bHiContrast );
162 return aImage;
165 //=========================================================================
167 /* Diese Hilfsfunktion pr"uft, ob eine Slot-Id im aktuellen Applikations-
168 Status sichtbar ist oder nicht. Dabei bezieht sich der Applikations-Status
169 darauf, ob die Applikation OLE-Server ist oder nicht.
172 BOOL IsItemHidden_Impl( USHORT nItemId, int bOleServer, int bMac )
174 return ( bMac &&
175 ( nItemId == SID_MINIMIZED ) ) ||
176 ( bOleServer &&
177 ( nItemId == SID_QUITAPP || nItemId == SID_SAVEDOC ||
178 nItemId == SID_OPENDOC || nItemId == SID_SAVEASDOC ||
179 nItemId == SID_NEWDOC ) ) ||
180 ( !bOleServer &&
181 ( nItemId == SID_EXITANDRETURN || nItemId == SID_UPDATEDOC ) );
184 //====================================================================
186 void SfxVirtualMenu::Construct_Impl()
188 pSVMenu->SetHighlightHdl( LINK(this, SfxVirtualMenu, Highlight) );
189 pSVMenu->SetActivateHdl( LINK(this, SfxVirtualMenu, Activate) );
190 pSVMenu->SetDeactivateHdl( LINK(this, SfxVirtualMenu, Deactivate) );
191 pSVMenu->SetSelectHdl( LINK(this, SfxVirtualMenu, Select) );
193 // #107258# accelerator keys are needed for accessibility
194 //if ( bOLE )
195 // InvalidateKeyCodes();
197 if ( !pResMgr && pParent )
198 pResMgr = pParent->pResMgr;
201 //--------------------------------------------------------------------
203 SfxVirtualMenu::SfxVirtualMenu( USHORT nOwnId,
204 SfxVirtualMenu* pOwnParent, Menu& rMenu, BOOL bWithHelp,
205 SfxBindings &rBindings, BOOL bOLEServer, BOOL bRes, BOOL bIsAddonMenu ):
206 pItems(0),
207 pImageControl(0),
208 pBindings(&rBindings),
209 pResMgr(0),
210 pAutoDeactivate(0),
211 nLocks(0),
212 bHelpInitialized( bWithHelp ),
213 bWasHighContrast( FALSE ),
214 bIsAddonPopupMenu( bIsAddonMenu )
216 DBG_MEMTEST();
217 DBG_CTOR(SfxVirtualMenu, 0);
218 pSVMenu = &rMenu;
220 bResCtor = bRes;
221 bOLE = bOLEServer;
222 nId = nOwnId;
223 pParent = pOwnParent;
224 nVisibleItems = 0;
225 pAppCtrl = 0;
226 pWindowMenu = NULL;
227 pPickMenu = NULL;
228 pAddonsMenu = NULL;
229 bIsActive = FALSE;
230 bControllersUnBound = FALSE;
231 CreateFromSVMenu();
232 Construct_Impl();
233 bHelpInitialized = FALSE;
236 //--------------------------------------------------------------------
238 // creates a virtual menu from a StarView MenuBar or PopupMenu
240 SfxVirtualMenu::SfxVirtualMenu( Menu *pStarViewMenu, BOOL bWithHelp,
241 SfxBindings &rBindings, BOOL bOLEServer, BOOL bRes, BOOL bIsAddonMenu ):
242 pItems(0),
243 pImageControl(0),
244 pBindings(&rBindings),
245 pResMgr(0),
246 pAutoDeactivate(0),
247 nLocks(0),
248 bHelpInitialized( bWithHelp ),
249 bWasHighContrast( FALSE ),
250 bIsAddonPopupMenu( bIsAddonMenu )
252 DBG_MEMTEST();
253 DBG_CTOR(SfxVirtualMenu, 0);
255 pSVMenu = pStarViewMenu;
257 bResCtor = bRes;
258 bOLE = bOLEServer;
259 nId = 0;
260 pParent = 0;
261 pAppCtrl = 0;
262 nVisibleItems = 0;
263 pWindowMenu = NULL;
264 pPickMenu = NULL;
265 pAddonsMenu = NULL;
266 bIsActive = FALSE;
267 bControllersUnBound = FALSE;
268 CreateFromSVMenu();
269 Construct_Impl();
270 bHelpInitialized = FALSE;
273 //--------------------------------------------------------------------
275 /* Der Destruktor der Klasse SfxVirtualMenu gib die gebundenen Items frei
276 und klinkt das zugeh"orige StarView-PopupMenu aus seinem Parent aus.
277 Falls es sich um das Pickmenu oder das MDI-Menu handelt, wird es
278 dort abgemeldet.
281 SfxVirtualMenu::~SfxVirtualMenu()
283 DBG_MEMTEST();
284 DBG_DTOR(SfxVirtualMenu, 0);
286 DELETEZ( pImageControl );
287 SvtMenuOptions().RemoveListener( LINK( this, SfxVirtualMenu, SettingsChanged ) );
289 if ( bIsActive )
291 pBindings->LEAVEREGISTRATIONS(); --nLocks; bIsActive = FALSE;
294 // QAP-Hack
295 if ( pAutoDeactivate )
297 if ( pAutoDeactivate->IsActive() )
298 Deactivate(0);
299 DELETEX(pAutoDeactivate);
302 if (pItems)
304 delete [] pItems;
307 delete pAppCtrl;
308 pBindings = 0;
310 // Alle Menues, die von SV erzeugt wurden, werden auch dort wieder
311 // gel"oscht (also die beim Laden aus der Resource erzeugten).
312 // Das Top-Level-Menu wird nie von SV gel"oscht, da die Allocierung
313 // im SFX erfolgt
314 if ( !bResCtor || !pParent)
316 if ( pParent )
318 if( pParent->pSVMenu->GetItemPos( nId ) != MENU_ITEM_NOTFOUND )
319 pParent->pSVMenu->SetPopupMenu( nId, 0 );
320 if ( pParent->pPickMenu == pSVMenu )
321 pParent->pPickMenu = 0;
322 if ( pParent->pWindowMenu == pSVMenu)
323 pParent->pWindowMenu = 0;
324 if ( pParent->pAddonsMenu == pSVMenu )
325 pParent->pAddonsMenu = 0;
328 delete pSVMenu;
331 DBG_OUTF( ("SfxVirtualMenu %lx destroyed", this) );
332 DBG_ASSERT( !nLocks, "destroying active menu" );
334 //--------------------------------------------------------------------
336 BOOL SfxVirtualMenu::IsHiContrastMode() const
338 const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
339 Color aMenuColor = rSettings.GetMenuColor();
340 if ( aMenuColor.IsDark() )
341 return TRUE;
342 else
343 return FALSE;
346 //--------------------------------------------------------------------
347 // internal: creates the virtual menu from the pSVMenu
349 void SfxVirtualMenu::CreateFromSVMenu()
351 DBG_MEMTEST();
352 DBG_CHKTHIS(SfxVirtualMenu, 0);
354 // Merge Addon popup menus into the SV Menu
355 Reference< com::sun::star::frame::XFrame > xFrame( pBindings->GetDispatcher()->GetFrame()->GetFrame()->GetFrameInterface() );
357 if ( pSVMenu->IsMenuBar() )
359 USHORT nPos = pSVMenu->GetItemPos( SID_MDIWINDOWLIST );
360 if ( nPos != MENU_ITEM_NOTFOUND && xFrame.is() )
362 // Retrieve addon popup menus and add them to our menu bar
363 Reference< com::sun::star::frame::XModel > xModel;
364 Reference< com::sun::star::frame::XController > xController( xFrame->getController(), UNO_QUERY );
365 if ( xController.is() )
366 xModel = Reference< com::sun::star::frame::XModel >( xController->getModel(), UNO_QUERY );
367 framework::AddonMenuManager::MergeAddonPopupMenus( xFrame, xModel, nPos, (MenuBar *)pSVMenu );
370 // Merge the Add-Ons help menu items into the Office help menu
371 if ( xFrame.is() )
372 framework::AddonMenuManager::MergeAddonHelpMenu( xFrame, (MenuBar *)pSVMenu );
374 // Set addon menu pointer here to avoid problems. When accessibility is enabled, the whole menu
375 // is created immediately!
376 pAddonsMenu = pSVMenu->GetPopupMenu( SID_ADDONLIST );
378 else if ( pParent )
380 if ( pSVMenu == pParent->pAddonsMenu &&
381 framework::AddonsOptions().HasAddonsMenu() &&
382 !pSVMenu->GetPopupMenu( SID_ADDONS ) )
384 // Create menu item at the end of the tools popup menu for the addons popup menu
385 InsertAddOnsMenuItem( pSVMenu );
389 // get and store the number of items
390 nCount = pSVMenu->GetItemCount();
392 // Achtung: nur zu diesem Zeitpunkt ist garantiert, da\s nCount und
393 // der ItemCount des SV-Menues "ubereinstimmen; sp"ater kann das SvMenue
394 // auch mehr Eintr"age haben (Pickliste!)
395 if (nCount)
396 pItems = new SfxMenuControl[nCount];
398 // remember some values
399 SFX_APP();
400 const int bOleServer = FALSE;
401 const int bMac = FALSE;
402 SvtMenuOptions aOptions;
403 aOptions.AddListener( LINK( this, SfxVirtualMenu, SettingsChanged ) );
405 // iterate through the items
406 pBindings->ENTERREGISTRATIONS(); ++nLocks;
407 pImageControl = new SfxMenuImageControl_Impl( SID_IMAGE_ORIENTATION, *pBindings, this );
409 // Update high contrast state
410 bWasHighContrast = IsHiContrastMode();
412 USHORT nSVPos = 0;
413 for ( USHORT nPos=0; nPos<nCount; ++nPos, ++nSVPos )
415 USHORT nSlotId = pSVMenu->GetItemId(nSVPos);
416 PopupMenu* pPopup = pSVMenu->GetPopupMenu(nSlotId);
417 if( pPopup && nSlotId >= SID_OBJECTMENU0 && nSlotId <= SID_OBJECTMENU_LAST )
419 // artefact in XML menuconfig: every entry in root menu must have a popup!
420 pSVMenu->SetPopupMenu( nSlotId, NULL );
421 DELETEZ( pPopup );
424 if ( pPopup )
426 SfxMenuControl *pMnuCtrl =
427 SfxMenuControl::CreateControl(nSlotId, *pPopup, *pBindings);
429 if ( pMnuCtrl )
431 // Das Popup war offensichtlich kein "echtes"; solche werden
432 // niemals aus der Resource geladen und m"ussen daher explizit
433 // gel"oscht werden
434 if ( pSVMenu->GetPopupMenu( nSlotId ) == pPopup )
435 pSVMenu->SetPopupMenu( nSlotId, NULL );
436 delete pPopup;
437 pPopup = 0;
439 SfxMenuCtrlArr_Impl &rCtrlArr = GetAppCtrl_Impl();
440 rCtrlArr.C40_INSERT( SfxMenuControl, pMnuCtrl, rCtrlArr.Count() );
441 (pItems+nPos)->Bind( 0, nSlotId, pSVMenu->GetItemText(nSlotId),
442 pSVMenu->GetHelpText(nSlotId), *pBindings);
443 pMnuCtrl->Bind( this, nSlotId, pSVMenu->GetItemText(nSlotId),
444 pSVMenu->GetHelpText(nSlotId), *pBindings);
446 if ( Application::GetSettings().GetStyleSettings().GetUseImagesInMenus() )
448 rtl::OUString aSlotURL( RTL_CONSTASCII_USTRINGPARAM( "slot:" ));
449 aSlotURL += rtl::OUString::valueOf( sal_Int32( nSlotId ));
450 Image aImage = GetImage( xFrame, aSlotURL, FALSE, bWasHighContrast );
451 pSVMenu->SetItemImage( nSlotId, aImage );
454 else
457 if ( nSlotId >= SID_SFX_START && !SfxMenuManager::IsPopupFunction(nSlotId) )
459 // Echte Popups sollen keine SlotIds haben; leider sind
460 // da noch Altlasten mit herumzuschleppen ...
461 String aTitle = pSVMenu->GetItemText( nSlotId );
462 pSVMenu->SetPopupMenu( nSlotId, NULL );
463 USHORT nPos = pSVMenu->GetItemPos( nSlotId );
464 pSVMenu->RemoveItem( nPos );
465 nSlotId = 1;
466 while ( pSVMenu->GetItemPos(nSlotId) != MENU_ITEM_NOTFOUND )
467 nSlotId++;
468 pSVMenu->InsertItem( nSlotId, aTitle, 0, nPos );
469 pSVMenu->SetPopupMenu( nSlotId, pPopup );
472 pSVMenu->SetHelpId( nSlotId, 0L );
473 pMnuCtrl = pItems+nPos;
475 // normalerweise jetzt erst im Activate-Handler
476 if ( bOLE )
478 pMnuCtrl->Bind( this, nSlotId,
479 *new SfxVirtualMenu(nSlotId, this, *pPopup, bHelpInitialized, *pBindings, bOLE, bResCtor),
480 pSVMenu->GetItemText(nSlotId), pSVMenu->GetHelpText(nSlotId),
481 *pBindings );
485 ++nVisibleItems;
487 else
489 switch ( pSVMenu->GetItemType(nSVPos) )
491 case MENUITEM_STRING:
492 case MENUITEM_STRINGIMAGE:
494 SfxMenuControl *pMnuCtrl=0;
495 String aCmd( pSVMenu->GetItemCommand( nSlotId ) );
496 if ( aCmd.CompareToAscii("slot:", 5) == 0 )
498 SfxMacroConfig* pCfg = SFX_APP()->GetMacroConfig();
499 if ( pCfg->IsMacroSlot( nSlotId ) )
501 if ( pCfg->GetMacroInfo( nSlotId ) )
503 pCfg->RegisterSlotId( nSlotId );
504 pSVMenu->SetItemCommand( nSlotId, String() );
505 aCmd.Erase();
507 else
509 pSVMenu->SetItemCommand( nSlotId, String::CreateFromAscii("macro:///macro.not.founc") );
514 if ( aCmd.Len() && (( nSlotId < SID_SFX_START ) || ( nSlotId > SHRT_MAX )) )
516 // try to create control via comand name
517 pMnuCtrl = SfxMenuControl::CreateControl( aCmd, nSlotId, *pSVMenu, *pBindings, this );
518 if ( pMnuCtrl )
520 SfxMenuCtrlArr_Impl &rCtrlArr = GetAppCtrl_Impl();
521 rCtrlArr.C40_INSERT( SfxMenuControl, pMnuCtrl, rCtrlArr.Count());
522 (pItems+nPos)->Bind( 0, nSlotId, pSVMenu->GetItemText(nSlotId), pSVMenu->GetHelpText(nSlotId), *pBindings);
526 if ( !pMnuCtrl )
528 // try to create control via Id
529 pMnuCtrl = SfxMenuControl::CreateControl(nSlotId, *pSVMenu, *pBindings);
530 if ( pMnuCtrl )
532 SfxMenuCtrlArr_Impl &rCtrlArr = GetAppCtrl_Impl();
533 rCtrlArr.C40_INSERT( SfxMenuControl, pMnuCtrl, rCtrlArr.Count());
534 (pItems+nPos)->Bind( 0, nSlotId, pSVMenu->GetItemText(nSlotId), pSVMenu->GetHelpText(nSlotId), *pBindings);
536 else
537 // take default control
538 pMnuCtrl = (pItems+nPos);
540 pMnuCtrl->Bind( this, nSlotId, pSVMenu->GetItemText(nSlotId), pSVMenu->GetHelpText(nSlotId), *pBindings);
543 if ( Application::GetSettings().GetStyleSettings().GetUseImagesInMenus() )
545 Image aImage;
546 if ( bIsAddonPopupMenu || framework::AddonMenuManager::IsAddonMenuId( nSlotId ))
548 rtl::OUString aImageId;
550 ::framework::MenuConfiguration::Attributes* pMenuAttributes =
551 (::framework::MenuConfiguration::Attributes*)pSVMenu->GetUserValue( nSlotId );
553 if ( pMenuAttributes )
554 aImageId = pMenuAttributes->aImageId; // Retrieve image id from menu attributes
556 aImage = RetrieveAddOnImage( xFrame, aImageId, aCmd, FALSE, bWasHighContrast );
558 else
560 rtl::OUString aSlotURL( RTL_CONSTASCII_USTRINGPARAM( "slot:" ));
561 aSlotURL += rtl::OUString::valueOf( sal_Int32( nSlotId ));
562 aImage = GetImage( xFrame, aSlotURL, FALSE, bWasHighContrast );
565 if ( !!aImage )
566 pSVMenu->SetItemImage( nSlotId, aImage );
569 if ( !IsItemHidden_Impl(nSlotId, bOleServer, bMac) )
570 ++nVisibleItems;
571 else
572 pSVMenu->RemoveItem( nSVPos-- );
573 break;
576 case MENUITEM_IMAGE:
577 //! not implemented
578 break;
580 case MENUITEM_SEPARATOR:
581 //! not implemented
582 break;
583 default:
584 break; // DONTKNOW and STRINGIMAGE not handled.
588 pBindings->LEAVEREGISTRATIONS(); --nLocks;
591 //--------------------------------------------------------------------
593 // called on activation of the SV-Menu
595 IMPL_LINK( SfxVirtualMenu, Highlight, Menu *, pMenu )
597 DBG_MEMTEST();
598 DBG_CHKTHIS(SfxVirtualMenu, 0);
600 // eigenes StarView-Menu
601 if ( pMenu == pSVMenu )
603 // AutoDeactivate ist jetzt nicht mehr n"otig
604 //USHORT nSlotId = pMenu->GetCurItemId();
605 if ( pAutoDeactivate )
606 pAutoDeactivate->Stop();
609 return TRUE;
612 IMPL_LINK( SfxVirtualMenu, SettingsChanged, void*, EMPTYARG )
614 USHORT nItemCount = pSVMenu->GetItemCount();
615 SfxViewFrame *pViewFrame = pBindings->GetDispatcher()->GetFrame();
616 BOOL bIcons = Application::GetSettings().GetStyleSettings().GetUseImagesInMenus();
617 BOOL bIsHiContrastMode = IsHiContrastMode();
618 Reference<com::sun::star::frame::XFrame> xFrame( pViewFrame->GetFrame()->GetFrameInterface() );
620 if ( !bIsAddonPopupMenu )
622 for ( USHORT nSVPos=0; nSVPos<nItemCount; ++nSVPos )
624 USHORT nSlotId = pSVMenu->GetItemId( nSVPos );
625 MenuItemType nType = pSVMenu->GetItemType( nSVPos );
626 if ( nType == MENUITEM_STRING && bIcons )
628 if ( framework::AddonMenuManager::IsAddonMenuId( nSlotId ))
630 // Special code for Add-On menu items. They can appear inside the help menu.
631 rtl::OUString aCmd( pSVMenu->GetItemCommand( nSlotId ) );
632 rtl::OUString aImageId;
634 ::framework::MenuConfiguration::Attributes* pMenuAttributes =
635 (::framework::MenuConfiguration::Attributes*)pSVMenu->GetUserValue( nSlotId );
637 if ( pMenuAttributes )
638 aImageId = pMenuAttributes->aImageId; // Retrieve image id from menu attributes
640 pSVMenu->SetItemImage( nSlotId, RetrieveAddOnImage( xFrame, aImageId, aCmd, FALSE, bIsHiContrastMode ));
642 else
644 rtl::OUString aSlotURL( RTL_CONSTASCII_USTRINGPARAM( "slot:" ));
645 aSlotURL += rtl::OUString::valueOf( sal_Int32( nSlotId ));
646 pSVMenu->SetItemImage( nSlotId, GetImage( xFrame, aSlotURL, FALSE, bWasHighContrast ));
649 else if( nType == MENUITEM_STRINGIMAGE && !bIcons )
651 pSVMenu->SetItemImage( nSlotId, Image() );
655 else
657 // Remove/update images from Add-Ons top-level popup menus when settings have changed
658 if ( !bIcons )
659 RemoveMenuImages( pSVMenu );
660 else
661 UpdateImages( pSVMenu );
664 // Special code to remove menu images from runtime popup menus when settings have changed
665 if ( pParent && pSVMenu == pParent->pAddonsMenu )
667 if ( !bIcons )
668 RemoveMenuImages( pParent->pAddonsMenu->GetPopupMenu( SID_ADDONS ));
669 else
670 UpdateImages( pParent->pAddonsMenu->GetPopupMenu( SID_ADDONS ));
673 if ( pImageControl )
674 pImageControl->Update();
676 return 0;
679 //--------------------------------------------------------------------
681 void SfxVirtualMenu::UpdateImages()
683 BOOL bIcons = Application::GetSettings().GetStyleSettings().GetUseImagesInMenus();
685 if ( bIcons )
687 BOOL bIsHiContrastMode = IsHiContrastMode();
688 USHORT nItemCount = pSVMenu->GetItemCount();
689 SfxViewFrame * pViewFrame = pBindings->GetDispatcher()->GetFrame();
690 Reference<com::sun::star::frame::XFrame> xFrame( pViewFrame->GetFrame()->GetFrameInterface() );
692 for ( USHORT nSVPos=0; nSVPos < nItemCount; ++nSVPos )
694 USHORT nSlotId = pSVMenu->GetItemId( nSVPos );
695 if ( pSVMenu->GetItemType( nSVPos ) == MENUITEM_STRINGIMAGE )
697 if ( framework::AddonMenuManager::IsAddonMenuId( nSlotId ))
699 // Special code for Add-On menu items. They can appear inside the help menu.
700 rtl::OUString aCmd( pSVMenu->GetItemCommand( nSlotId ) );
701 rtl::OUString aImageId;
703 ::framework::MenuConfiguration::Attributes* pMenuAttributes =
704 (::framework::MenuConfiguration::Attributes*)pSVMenu->GetUserValue( nSlotId );
706 if ( pMenuAttributes )
707 aImageId = pMenuAttributes->aImageId; // Retrieve image id from menu attributes
709 pSVMenu->SetItemImage( nSlotId, RetrieveAddOnImage( xFrame, aImageId, aCmd, FALSE, bIsHiContrastMode ));
711 else
713 rtl::OUString aSlotURL( RTL_CONSTASCII_USTRINGPARAM( "slot:" ));
714 aSlotURL += rtl::OUString::valueOf( sal_Int32( nSlotId ));
715 pSVMenu->SetItemImage( nSlotId, GetImage( xFrame, aSlotURL, FALSE, bWasHighContrast ));
720 if ( pImageControl )
721 pImageControl->Update();
725 //--------------------------------------------------------------------
727 void SfxVirtualMenu::UpdateImages( Menu* pMenu )
729 if ( !pMenu )
730 return;
732 framework::AddonsOptions aAddonOptions;
734 BOOL bIcons = Application::GetSettings().GetStyleSettings().GetUseImagesInMenus();
735 if ( bIcons )
737 BOOL bIsHiContrastMode = IsHiContrastMode();
738 USHORT nItemCount = pMenu->GetItemCount();
739 Reference<com::sun::star::frame::XFrame> aXFrame( pBindings->GetDispatcher_Impl()->GetFrame()->GetFrame()->GetFrameInterface() );
741 for ( USHORT nPos=0; nPos < nItemCount; ++nPos )
743 USHORT nSlotId = pMenu->GetItemId( nPos );
744 PopupMenu* pPopup = pMenu->GetPopupMenu( nSlotId );
745 if ( pMenu->GetItemType( nPos ) != MENUITEM_SEPARATOR )
747 rtl::OUString aImageId;
749 ::framework::MenuConfiguration::Attributes* pMenuAttributes =
750 (::framework::MenuConfiguration::Attributes*)pMenu->GetUserValue( nSlotId );
752 if ( pMenuAttributes )
753 aImageId = pMenuAttributes->aImageId; // Retrieve image id from menu attributes
755 pMenu->SetItemImage( nSlotId, RetrieveAddOnImage( aXFrame, aImageId, pMenu->GetItemCommand( nSlotId ), FALSE, bIsHiContrastMode ));
758 if ( pPopup )
759 UpdateImages( pPopup );
762 if ( pImageControl )
763 pImageControl->Update();
767 //--------------------------------------------------------------------
769 void SfxVirtualMenu::RemoveMenuImages( Menu* pMenu )
771 if ( !pMenu )
772 return;
774 USHORT nItemCount = pMenu->GetItemCount();
775 for ( USHORT nPos=0; nPos < nItemCount; ++nPos )
777 USHORT nSlotId = pMenu->GetItemId( nPos );
778 PopupMenu* pPopup = pMenu->GetPopupMenu( nSlotId );
779 if ( pMenu->GetItemType( nPos ) == MENUITEM_STRINGIMAGE )
780 pMenu->SetItemImage( nSlotId, Image() );
781 if ( pPopup )
782 RemoveMenuImages( pPopup );
786 //--------------------------------------------------------------------
788 FASTBOOL SfxVirtualMenu::Bind_Impl( Menu *pMenu )
790 // Selber suchen, da SV mit 'USHORT nSID = pSVMenu->GetCurItemId();' immer
791 // 0 liefert. Das ist so, weil die Event-Weiterleitung lt. TH nichts mit
792 // CurItem des Parent-Menus zu tun hat.
793 sal_uInt32 nAddonsPopupPrefixLen = ADDONSPOPUPMENU_URL_PREFIX.getLength();
795 for ( USHORT nPos = 0; nPos < nCount; ++nPos )
797 // angesprochenes Sub-Menu gefunden?
798 FASTBOOL bFound = FALSE;
799 USHORT nSID = pSVMenu->GetItemId(nPos);
800 SfxMenuControl &rCtrl = pItems[nPos];
801 bFound = pSVMenu->GetPopupMenu(nSID) == pMenu;
802 SfxVirtualMenu *pSubMenu = rCtrl.GetPopupMenu();
804 if ( bFound )
806 // Nur ein gebundener Menu-Controller hat schon seine Id!
807 if ( !rCtrl.GetId() )
809 bIsAddonPopupMenu = FALSE;
810 DBG_ASSERT( !pSubMenu, "Popup schon vorhanden!");
812 // Check if the popup is an Add-On popup menu
813 // Either the popup menu has a special ID or a special command URL prefix!
814 rtl::OUString aCommand = pSVMenu->GetItemCommand( nSID );
815 if ( ( nSID == SID_ADDONS ) ||
816 ( nSID == SID_ADDONHELP ) ||
817 (( (sal_uInt32)aCommand.getLength() > nAddonsPopupPrefixLen ) &&
818 ( aCommand.indexOf( ADDONSPOPUPMENU_URL_PREFIX ) == 0 )) )
819 bIsAddonPopupMenu = TRUE;
821 // VirtualMenu f"ur Sub-Menu erzeugen
822 BOOL bRes = bResCtor;
823 pSubMenu = new SfxVirtualMenu( nSID, this,
824 *pMenu, FALSE, *pBindings, bOLE, bRes, bIsAddonPopupMenu );
826 DBG_OUTF( ("Neues VirtualMenu %lx erzeugt", pSubMenu) );
828 rCtrl.Bind( this, nSID, *pSubMenu,
829 pSVMenu->GetItemText(nSID), pSVMenu->GetHelpText(nSID),
830 *pBindings );
832 // Activate weiterleiten
833 pSubMenu->Bind_Impl( pMenu );
834 pSubMenu->Activate( pMenu );
838 // rekursiv weitersuchen (SV Activate nur am Menu selbst und Top-Menu)
839 if ( !bFound && pSubMenu )
840 bFound = pSubMenu->Bind_Impl( pMenu );
842 // gefunden, dann abbrechen
843 if ( bFound )
844 return TRUE;
847 // nicht in diesem Untermenu gefunden
848 return FALSE;
851 void SfxVirtualMenu::BindControllers()
853 pBindings->ENTERREGISTRATIONS();
855 USHORT nPos;
856 for ( nPos = 0; nPos < nCount; ++nPos )
858 SfxMenuControl& rCtrl = pItems[nPos];
859 if ( rCtrl.IsBindable_Impl() && !rCtrl.GetPopupMenu() )
860 rCtrl.ReBind();
863 SfxMenuCtrlArr_Impl& rCtrlArr = GetAppCtrl_Impl();
864 for ( nPos=0; nPos<rCtrlArr.Count(); nPos++ )
866 SfxMenuControl* pCtrl = rCtrlArr[nPos];
867 USHORT nSlotId = pCtrl->GetId();
868 if ( !pSVMenu->GetItemCommand(nSlotId).Len() )
869 pCtrl->ReBind();
872 pBindings->LEAVEREGISTRATIONS();
873 bControllersUnBound = FALSE;
876 void SfxVirtualMenu::UnbindControllers()
878 pBindings->ENTERREGISTRATIONS();
880 USHORT nPos;
881 for ( nPos = 0; nPos < nCount; ++nPos )
883 SfxMenuControl &rCtrl = pItems[nPos];
884 if ( rCtrl.IsBound() )
885 rCtrl.UnBind();
888 SfxMenuCtrlArr_Impl& rCtrlArr = GetAppCtrl_Impl();
889 for ( nPos=0; nPos<rCtrlArr.Count(); nPos++ )
891 SfxMenuControl* pCtrl = rCtrlArr[nPos];
892 if ( pCtrl->IsBound() )
893 // UnoController sind nicht gebunden!
894 pCtrl->UnBind();
897 pBindings->LEAVEREGISTRATIONS();
898 bControllersUnBound = TRUE;
902 //--------------------------------------------------------------------
903 void SfxVirtualMenu::InsertAddOnsMenuItem( Menu* pMenu )
905 // Create special popup menu that is filled with the 3rd party components popup menu items
906 Reference<com::sun::star::lang::XMultiServiceFactory> aXMultiServiceFactory(::comphelper::getProcessServiceFactory());
907 ::framework::MenuConfiguration aConf( aXMultiServiceFactory );
908 Reference<com::sun::star::frame::XFrame> xFrame( pBindings->GetDispatcher_Impl()->GetFrame()->GetFrame()->GetFrameInterface() );
910 PopupMenu* pAddonMenu = NULL;
913 pAddonMenu = framework::AddonMenuManager::CreateAddonMenu( xFrame );
915 catch ( ::com::sun::star::lang::WrappedTargetException )
919 // Create menu item at the end of the tools popup menu for the addons popup menu
920 if ( pAddonMenu && pAddonMenu->GetItemCount() > 0 )
922 USHORT nItemCount = pMenu->GetItemCount();
923 String aAddonsTitle( SfxResId( STR_MENU_ADDONS ));
924 if ( nItemCount > 0 && pMenu->GetItemType( nItemCount-1 ) != MENUITEM_SEPARATOR )
925 pMenu->InsertSeparator();
926 pMenu->InsertItem( SID_ADDONS, aAddonsTitle );
927 pMenu->SetPopupMenu( SID_ADDONS, pAddonMenu );
929 if ( Application::GetSettings().GetStyleSettings().GetUseImagesInMenus() )
931 rtl::OUString aSlotURL( RTL_CONSTASCII_USTRINGPARAM( "slot:" ));
932 aSlotURL += rtl::OUString::valueOf( sal_Int32( SID_ADDONS ));
933 pMenu->SetItemImage( SID_ADDONS, GetImage( xFrame, aSlotURL, FALSE, bWasHighContrast ));
936 else
937 delete pAddonMenu;
940 //--------------------------------------------------------------------
942 // called on activation of the SV-Menu
944 IMPL_LINK( SfxVirtualMenu, Activate, Menu *, pMenu )
946 DBG_MEMTEST();
947 DBG_CHKTHIS(SfxVirtualMenu, 0);
948 DBG_OUTF( ("SfxVirtualMenu %lx activated %lx, own %lx", this, pMenu, pSVMenu));
950 // MI: wozu war der noch gut?
951 // MBA: scheint ein alter QAP-Hack gewesen zu sein ( in rev.1.41 eingecheckt ! )
952 // if ( Application::IsInModalMode() )
953 // return TRUE; // abw"urgen
955 if ( pMenu )
957 sal_Bool bDontHide = SvtMenuOptions().IsEntryHidingEnabled();
958 sal_uInt16 nFlag = pMenu->GetMenuFlags();
959 if ( bDontHide )
960 nFlag &= ~MENU_FLAG_HIDEDISABLEDENTRIES;
961 else
962 nFlag |= MENU_FLAG_HIDEDISABLEDENTRIES;
963 pMenu->SetMenuFlags( nFlag );
966 // eigenes StarView-Menu
967 if ( pMenu == pSVMenu )
969 // doppelt-Activate verhindern
970 if ( bIsActive )
971 return TRUE;
973 // ggf. Pick-Menu erzeugen
974 if ( pParent && pSVMenu == pParent->pPickMenu )
976 SfxPickList::Get()->CreateMenuEntries( pParent->pPickMenu );
978 else
979 pPickMenu = pSVMenu->GetPopupMenu(SID_PICKLIST);
981 if ( pParent && pSVMenu == pParent->pWindowMenu )
983 // update window list
984 ::std::vector< ::rtl::OUString > aNewWindowListVector;
985 Reference< XDesktop > xDesktop( ::comphelper::getProcessServiceFactory()->createInstance(
986 DEFINE_CONST_OUSTRING( "com.sun.star.frame.Desktop" ) ), UNO_QUERY );
988 USHORT nActiveItemId = 0;
989 USHORT nItemId = START_ITEMID_WINDOWLIST;
991 if ( xDesktop.is() )
993 Reference< XFramesSupplier > xTasksSupplier( xDesktop, UNO_QUERY );
994 Reference< XFrame > xCurrentFrame = xDesktop->getCurrentFrame();
995 Reference< XIndexAccess > xList ( xTasksSupplier->getFrames(), UNO_QUERY );
996 sal_Int32 nFrameCount = xList->getCount();
997 for( sal_Int32 i=0; i<nFrameCount; ++i )
999 Reference< XFrame > xFrame;
1000 Any aVal = xList->getByIndex(i);
1001 if (!(aVal>>=xFrame) || !xFrame.is() )
1002 continue;
1004 if ( xFrame == xCurrentFrame )
1005 nActiveItemId = nItemId;
1007 Window* pWin = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
1008 if ( pWin && pWin->IsVisible() )
1010 aNewWindowListVector.push_back( pWin->GetText() );
1011 ++nItemId;
1016 int nItemCount = pMenu->GetItemCount();
1018 if ( nItemCount > 0 )
1020 // remove all old window list entries from menu
1021 sal_uInt16 nPos = pMenu->GetItemPos( START_ITEMID_WINDOWLIST );
1022 for ( sal_uInt16 n = nPos; n < pMenu->GetItemCount(); )
1023 pMenu->RemoveItem( n );
1025 if ( pMenu->GetItemType( pMenu->GetItemCount()-1 ) == MENUITEM_SEPARATOR )
1026 pMenu->RemoveItem( pMenu->GetItemCount()-1 );
1029 if ( aNewWindowListVector.size() > 0 )
1031 // append new window list entries to menu
1032 pMenu->InsertSeparator();
1033 nItemId = START_ITEMID_WINDOWLIST;
1034 for ( sal_uInt32 i = 0; i < aNewWindowListVector.size(); i++ )
1036 pMenu->InsertItem( nItemId, aNewWindowListVector.at( i ), MIB_RADIOCHECK );
1037 if ( nItemId == nActiveItemId )
1038 pMenu->CheckItem( nItemId );
1039 ++nItemId;
1043 else
1044 pWindowMenu = pSVMenu->GetPopupMenu(SID_MDIWINDOWLIST);
1046 if ( !pParent && pSVMenu->IsMenuBar() && !pAddonsMenu )
1048 // Store Add-Ons parents of our runtime menu items
1049 pAddonsMenu = pSVMenu->GetPopupMenu( SID_ADDONLIST );
1052 // f"ur konstistenten Status sorgen
1053 if ( bControllersUnBound )
1054 BindControllers();
1056 //InvalidateKeyCodes();
1057 pBindings->GetDispatcher_Impl()->Flush();
1058 for ( USHORT nPos = 0; nPos < nCount; ++nPos )
1060 USHORT nSlotId = (pItems+nPos)->GetId();
1061 if ( nSlotId && nSlotId > END_ITEMID_WINDOWLIST )
1062 pBindings->Update(nSlotId);
1065 pBindings->Update( SID_IMAGE_ORIENTATION );
1067 // HelpText on-demand
1068 if ( !bHelpInitialized )
1070 // TODO/CLEANUP: do we need help texts in context menus?
1071 // old way with SlotInfo doesn't work anymore
1074 // bis zum Deactivate die Statusupdates unterdr"ucken
1075 pBindings->ENTERREGISTRATIONS(); ++nLocks; bIsActive = TRUE;
1077 if ( pAutoDeactivate ) // QAP-Hack
1078 pAutoDeactivate->Start();
1080 if ( IsHiContrastMode() != bWasHighContrast )
1082 // Refresh images as our background color changed and remember it!!
1083 bWasHighContrast = IsHiContrastMode();
1084 if ( bIsAddonPopupMenu )
1085 UpdateImages( pSVMenu );
1086 else
1087 UpdateImages();
1090 // erledigt
1091 return TRUE;
1093 else
1095 // VirtualMenu fuer SubMenu finden und ggf. an VirtualMenu binden
1096 bool bRet = Bind_Impl( pMenu );
1097 #ifdef DBG_UTIL
1098 if ( !bRet)
1099 DBG_WARNING( "W1: Virtual menu konnte nicht erzeugt werden!" );
1100 #endif
1101 return bRet;
1105 //--------------------------------------------------------------------
1107 IMPL_LINK( SfxVirtualMenu, Deactivate, Menu *, pMenu )
1109 DBG_MEMTEST();
1110 DBG_OUTF( ("SfxVirtualMenu %lx deactivated %lx, own %lx", this, pMenu, pSVMenu) );
1111 if ( bIsActive && ( 0 == pMenu || pMenu == pSVMenu ) )
1113 if ( pAutoDeactivate )
1114 pAutoDeactivate->Stop();
1116 // Bis auf die Menubar k"onnen alle Controller unbinded werden, wenn
1117 // das Menue deaktiviert ( = zugeklappt ) wird
1118 if ( pParent )
1119 UnbindControllers();
1120 pBindings->LEAVEREGISTRATIONS(); --nLocks; bIsActive = FALSE;
1122 return TRUE;
1124 //--------------------------------------------------------------------
1126 // called on activation of the SV-Menu
1128 IMPL_LINK( SfxVirtualMenu, Select, Menu *, pMenu )
1130 USHORT nSlotId = (USHORT) pMenu->GetCurItemId();
1131 DBG_OUTF( ("SfxVirtualMenu %lx selected %u from %lx", this, nSlotId, pMenu) );
1133 if ( pSVMenu->GetItemCommand( nSlotId ).Len() )
1135 SfxMenuCtrlArr_Impl& rCtrlArr = GetAppCtrl_Impl();
1136 for ( USHORT nPos=0; nPos<rCtrlArr.Count(); nPos++ )
1138 SfxMenuControl* pCtrl = rCtrlArr[nPos];
1139 if ( pCtrl->GetId() == nSlotId )
1141 SfxUnoMenuControl *pUnoCtrl = (SfxUnoMenuControl*) pCtrl;
1142 pUnoCtrl->Select();
1143 return TRUE;
1148 if ( nSlotId >= START_ITEMID_WINDOWLIST && nSlotId <= END_ITEMID_WINDOWLIST )
1150 // window list menu item selected
1151 Reference< XFramesSupplier > xDesktop( ::comphelper::getProcessServiceFactory()->createInstance(
1152 DEFINE_CONST_OUSTRING( "com.sun.star.frame.Desktop" ) ), UNO_QUERY );
1153 if ( xDesktop.is() )
1155 USHORT nTaskId = START_ITEMID_WINDOWLIST;
1156 Reference< XIndexAccess > xList( xDesktop->getFrames(), UNO_QUERY );
1157 sal_Int32 nFrameCount = xList->getCount();
1158 for ( sal_Int32 i=0; i<nFrameCount; ++i )
1160 Any aItem = xList->getByIndex(i);
1161 Reference< XFrame > xFrame;
1162 if (( aItem >>= xFrame ) && xFrame.is() && nTaskId == nSlotId )
1164 Window* pWin = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
1165 pWin->GrabFocus();
1166 pWin->ToTop( TOTOP_RESTOREWHENMIN );
1167 break;
1170 nTaskId++;
1174 return TRUE;
1176 else if ( nSlotId >= START_ITEMID_PICKLIST && nSlotId <= END_ITEMID_PICKLIST )
1178 SfxPickList::Get()->ExecuteMenuEntry( nSlotId );
1179 return sal_True;
1182 if ( pMenu->GetItemCommand( nSlotId ).Len() )
1183 pBindings->ExecuteCommand_Impl( pMenu->GetItemCommand( nSlotId ) );
1184 else
1185 pBindings->Execute( nSlotId );
1187 return TRUE;
1190 //--------------------------------------------------------------------
1192 // returns the associated StarView-menu
1194 Menu* SfxVirtualMenu::GetSVMenu() const
1196 DBG_MEMTEST();
1197 DBG_CHKTHIS(SfxVirtualMenu, 0);
1199 return pSVMenu;
1202 //--------------------------------------------------------------------
1204 // return the position of the specified item
1206 USHORT SfxVirtualMenu::GetItemPos( USHORT nItemId ) const
1208 DBG_MEMTEST();
1209 DBG_CHKTHIS(SfxVirtualMenu, 0);
1211 for ( USHORT nPos = 0; nPos < nCount; ++nPos )
1212 if ( (pItems+nPos)->GetId() == nItemId )
1213 return nPos;
1214 return MENU_ITEM_NOTFOUND;
1217 //--------------------------------------------------------------------
1219 // returns the popup-menu assigned to the item or 0 if none
1221 SfxVirtualMenu* SfxVirtualMenu::GetPopupMenu( USHORT nItemId ) const
1223 DBG_MEMTEST();
1224 DBG_CHKTHIS(SfxVirtualMenu, 0);
1226 USHORT nPos = GetItemPos(nItemId);
1227 if ( nPos != MENU_ITEM_NOTFOUND )
1228 return (pItems+nPos)->GetPopupMenu();
1229 return 0;
1231 //--------------------------------------------------------------------
1233 // returns the text of the item as currently shown in the menu
1235 String SfxVirtualMenu::GetItemText( USHORT nSlotId ) const
1237 DBG_MEMTEST();
1238 DBG_CHKTHIS(SfxVirtualMenu, 0);
1240 USHORT nPos = GetItemPos(nSlotId);
1241 if ( nPos != MENU_ITEM_NOTFOUND )
1242 return (pItems+nPos)->GetTitle();
1243 return String();
1245 //--------------------------------------------------------------------
1247 // returns the text of the item as currently shown in the menu
1249 String SfxVirtualMenu::GetItemHelpText( USHORT nSlotId ) const
1251 DBG_MEMTEST();
1252 DBG_CHKTHIS(SfxVirtualMenu, 0);
1254 USHORT nPos = GetItemPos(nSlotId);
1255 if ( nPos != MENU_ITEM_NOTFOUND )
1256 return (pItems+nPos)->GetHelpText();
1257 return String();
1260 //--------------------------------------------------------------------
1262 void SfxVirtualMenu::InvalidateKeyCodes()
1264 DBG_ASSERT( pSVMenu, "invalidating key of incomplete menu" );
1266 SfxApplication* pSfxApp = SFX_APP();
1267 SfxViewFrame *pViewFrame = pBindings->GetDispatcher()->GetFrame();
1268 SfxAcceleratorManager* pAccMgr = pViewFrame->GetViewShell()->GetAccMgr_Impl();
1269 SfxAcceleratorManager* pAppAccel = pSfxApp->GetAppAccel_Impl();
1270 if ( !pAccMgr )
1271 pAccMgr = pAppAccel;
1273 for ( USHORT nPos = 0; nPos < pSVMenu->GetItemCount(); ++nPos )
1275 USHORT nId = pSVMenu->GetItemId(nPos);
1276 SfxVirtualMenu *pPopup = GetPopupMenu(nId);
1277 // if ( pPopup )
1278 // pPopup->InvalidateKeyCodes();
1279 // else if ( nId )
1280 if ( nId && !pSVMenu->GetPopupMenu( nId ) )
1282 KeyCode aCode = pAccMgr->GetKeyCode( nId );
1283 if ( !aCode.GetCode() && pAccMgr != pAppAccel )
1284 aCode = pAppAccel->GetKeyCode( nId );
1285 pSVMenu->SetAccelKey( nId, aCode );
1288 } */
1290 //--------------------------------------------------------------------
1292 // set the checkmark of the specified item
1294 void SfxVirtualMenu::CheckItem( USHORT nItemId, BOOL bCheck )
1296 DBG_MEMTEST();
1297 DBG_CHKTHIS(SfxVirtualMenu, 0);
1298 DBG_ASSERT( this != 0, "");
1299 DBG_ASSERT( pSVMenu != 0, "" );
1300 if (pSVMenu->GetItemPos( nItemId ) != MENU_ITEM_NOTFOUND )
1301 pSVMenu->CheckItem( nItemId, bCheck );
1303 //--------------------------------------------------------------------
1305 // set the enabled-state of the specified item
1307 void SfxVirtualMenu::EnableItem( USHORT nItemId, BOOL bEnable )
1309 DBG_MEMTEST();
1310 DBG_CHKTHIS(SfxVirtualMenu, 0);
1311 DBG_ASSERT( this != 0, "");
1312 DBG_ASSERT( pSVMenu != 0, "" );
1314 if (pSVMenu->GetItemPos( nItemId ) != MENU_ITEM_NOTFOUND )
1315 pSVMenu->EnableItem( nItemId, bEnable );
1317 //--------------------------------------------------------------------
1319 // set the text of the specified item
1321 void SfxVirtualMenu::SetItemText( USHORT nItemId, const String& rText )
1323 DBG_MEMTEST();
1324 DBG_CHKTHIS(SfxVirtualMenu, 0);
1325 DBG_ASSERT( this != 0, "");
1326 DBG_ASSERT( pSVMenu != 0, "" );
1327 if (pSVMenu->GetItemPos( nItemId ) != MENU_ITEM_NOTFOUND )
1328 pSVMenu->SetItemText( nItemId, rText );
1331 //--------------------------------------------------------------------
1335 void SfxVirtualMenu::SetPopupMenu( USHORT nItemId, PopupMenu *pMenu )
1337 DBG_MEMTEST();
1338 DBG_CHKTHIS(SfxVirtualMenu, 0);
1340 if (pSVMenu->GetItemPos( nItemId ) != MENU_ITEM_NOTFOUND )
1341 GetSVMenu()->SetPopupMenu( nItemId, pMenu );
1342 for ( USHORT n = 0; n < nCount; ++n )
1344 SfxVirtualMenu *pSubMenu = (pItems+n)->GetPopupMenu();
1345 if ( pSubMenu )
1346 pSubMenu->SetPopupMenu( nItemId, pMenu );
1350 //--------------------------------------------------------------------
1352 // Erzwingt die Initialisierung, die sonst nur im Activate kommt
1354 void SfxVirtualMenu::InitPopup( USHORT nPos, BOOL /*bOLE*/ )
1356 DBG_MEMTEST();
1357 DBG_CHKTHIS(SfxVirtualMenu, 0);
1359 USHORT nSID = pSVMenu->GetItemId(nPos);
1360 PopupMenu *pMenu = pSVMenu->GetPopupMenu( nSID );
1362 DBG_ASSERT( pMenu, "Hier gibt es kein Popup!");
1364 SfxMenuControl &rCtrl = pItems[nPos];
1365 if ( !rCtrl.GetId() )
1367 // VirtualMenu f"ur Sub-Menu erzeugen
1368 BOOL bRes = bResCtor;
1369 SfxVirtualMenu *pSubMenu =
1370 new SfxVirtualMenu(nSID, this, *pMenu, FALSE, *pBindings, bOLE, bRes);
1372 DBG_OUTF( ("Neues VirtualMenu %lx erzeugt", pSubMenu) );
1374 rCtrl.Bind( this, nSID, *pSubMenu,
1375 pSVMenu->GetItemText(nSID), pSVMenu->GetHelpText(nSID),
1376 *pBindings );
1380 void SfxVirtualMenu::InitializeHelp()
1382 for ( USHORT nPos = 0; nPos<pSVMenu->GetItemCount(); ++nPos )
1384 USHORT nSlotId = pSVMenu->GetItemId(nPos);
1385 // TODO/CLEANUP: this code does nothing!
1386 // if ( !bHelpInitialized )
1387 // pSVMenu->SetHelpText( nId, rSlotPool.GetSlotHelpText_Impl( nId ) );
1388 SfxMenuControl &rCtrl = pItems[nPos];
1389 if ( nSlotId && !rCtrl.GetId() )
1391 InitPopup( nPos, TRUE );
1394 SfxVirtualMenu *pSubMenu = rCtrl.GetPopupMenu();
1395 if ( pSubMenu )
1396 pSubMenu->InitializeHelp();
1399 bHelpInitialized = TRUE;
1402 typedef ULONG (__LOADONCALLAPI *HelpIdFunc) ( const String& );
1404 void SfxVirtualMenu::SetHelpIds( ResMgr *pRes )
1406 pResMgr = pRes;