1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: virtmenu.cxx,v $
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>
45 #include <tools/urlobj.hxx>
50 #include "virtmenu.hxx"
51 #include <sfx2/msgpool.hxx>
52 #include "statcach.hxx"
53 #include <sfx2/msg.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"
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>
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
;
98 virtual void StateChanged( USHORT nSID
, SfxItemState eState
, const SfxPoolItem
* pState
);
100 SfxMenuImageControl_Impl( USHORT nSlotId
, SfxBindings
& rBindings
, SfxVirtualMenu
* pVMenu
)
101 : SfxControllerItem( nSlotId
, rBindings
)
104 , bIsMirrored( FALSE
)
109 void SfxMenuImageControl_Impl::StateChanged( USHORT
/*nSID*/, SfxItemState
/*eState*/, const SfxPoolItem
* pState
)
111 const SfxImageItem
* pItem
= PTR_CAST( SfxImageItem
, pState
);
114 lRotation
= pItem
->GetRotation();
115 bIsMirrored
= pItem
->IsMirrored();
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
,
151 if ( aImageId
.getLength() > 0 )
153 aImage
= GetImage( rFrame
, aImageId
, bBigImage
, bHiContrast
);
158 aImage
= GetImage( rFrame
, aURL
, bBigImage
, bHiContrast
);
160 aImage
= framework::AddonsOptions().GetImageFromURL( aURL
, bBigImage
, bHiContrast
);
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
)
175 ( nItemId
== SID_MINIMIZED
) ) ||
177 ( nItemId
== SID_QUITAPP
|| nItemId
== SID_SAVEDOC
||
178 nItemId
== SID_OPENDOC
|| nItemId
== SID_SAVEASDOC
||
179 nItemId
== SID_NEWDOC
) ) ||
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
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
):
208 pBindings(&rBindings
),
212 bHelpInitialized( bWithHelp
),
213 bWasHighContrast( FALSE
),
214 bIsAddonPopupMenu( bIsAddonMenu
)
217 DBG_CTOR(SfxVirtualMenu
, 0);
223 pParent
= pOwnParent
;
230 bControllersUnBound
= FALSE
;
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
):
244 pBindings(&rBindings
),
248 bHelpInitialized( bWithHelp
),
249 bWasHighContrast( FALSE
),
250 bIsAddonPopupMenu( bIsAddonMenu
)
253 DBG_CTOR(SfxVirtualMenu
, 0);
255 pSVMenu
= pStarViewMenu
;
267 bControllersUnBound
= FALSE
;
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
281 SfxVirtualMenu::~SfxVirtualMenu()
284 DBG_DTOR(SfxVirtualMenu
, 0);
286 DELETEZ( pImageControl
);
287 SvtMenuOptions().RemoveListener( LINK( this, SfxVirtualMenu
, SettingsChanged
) );
291 pBindings
->LEAVEREGISTRATIONS(); --nLocks
; bIsActive
= FALSE
;
295 if ( pAutoDeactivate
)
297 if ( pAutoDeactivate
->IsActive() )
299 DELETEX(pAutoDeactivate
);
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
314 if ( !bResCtor
|| !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;
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() )
346 //--------------------------------------------------------------------
347 // internal: creates the virtual menu from the pSVMenu
349 void SfxVirtualMenu::CreateFromSVMenu()
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
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
);
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!)
396 pItems
= new SfxMenuControl
[nCount
];
398 // remember some values
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();
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
);
426 SfxMenuControl
*pMnuCtrl
=
427 SfxMenuControl::CreateControl(nSlotId
, *pPopup
, *pBindings
);
431 // Das Popup war offensichtlich kein "echtes"; solche werden
432 // niemals aus der Resource geladen und m"ussen daher explizit
434 if ( pSVMenu
->GetPopupMenu( nSlotId
) == pPopup
)
435 pSVMenu
->SetPopupMenu( nSlotId
, NULL
);
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
);
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 );
466 while ( pSVMenu->GetItemPos(nSlotId) != MENU_ITEM_NOTFOUND )
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
478 pMnuCtrl
->Bind( this, nSlotId
,
479 *new SfxVirtualMenu(nSlotId
, this, *pPopup
, bHelpInitialized
, *pBindings
, bOLE
, bResCtor
),
480 pSVMenu
->GetItemText(nSlotId
), pSVMenu
->GetHelpText(nSlotId
),
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() );
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 );
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
);
528 // try to create control via Id
529 pMnuCtrl
= SfxMenuControl::CreateControl(nSlotId
, *pSVMenu
, *pBindings
);
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
);
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() )
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
);
560 rtl::OUString
aSlotURL( RTL_CONSTASCII_USTRINGPARAM( "slot:" ));
561 aSlotURL
+= rtl::OUString::valueOf( sal_Int32( nSlotId
));
562 aImage
= GetImage( xFrame
, aSlotURL
, FALSE
, bWasHighContrast
);
566 pSVMenu
->SetItemImage( nSlotId
, aImage
);
569 if ( !IsItemHidden_Impl(nSlotId
, bOleServer
, bMac
) )
572 pSVMenu
->RemoveItem( nSVPos
-- );
580 case MENUITEM_SEPARATOR
:
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
)
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();
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
));
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() );
657 // Remove/update images from Add-Ons top-level popup menus when settings have changed
659 RemoveMenuImages( pSVMenu
);
661 UpdateImages( pSVMenu
);
664 // Special code to remove menu images from runtime popup menus when settings have changed
665 if ( pParent
&& pSVMenu
== pParent
->pAddonsMenu
)
668 RemoveMenuImages( pParent
->pAddonsMenu
->GetPopupMenu( SID_ADDONS
));
670 UpdateImages( pParent
->pAddonsMenu
->GetPopupMenu( SID_ADDONS
));
674 pImageControl
->Update();
679 //--------------------------------------------------------------------
681 void SfxVirtualMenu::UpdateImages()
683 BOOL bIcons
= Application::GetSettings().GetStyleSettings().GetUseImagesInMenus();
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
));
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
));
721 pImageControl
->Update();
725 //--------------------------------------------------------------------
727 void SfxVirtualMenu::UpdateImages( Menu
* pMenu
)
732 framework::AddonsOptions aAddonOptions
;
734 BOOL bIcons
= Application::GetSettings().GetStyleSettings().GetUseImagesInMenus();
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
));
759 UpdateImages( pPopup
);
763 pImageControl
->Update();
767 //--------------------------------------------------------------------
769 void SfxVirtualMenu::RemoveMenuImages( Menu
* pMenu
)
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() );
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();
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
),
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
847 // nicht in diesem Untermenu gefunden
851 void SfxVirtualMenu::BindControllers()
853 pBindings
->ENTERREGISTRATIONS();
856 for ( nPos
= 0; nPos
< nCount
; ++nPos
)
858 SfxMenuControl
& rCtrl
= pItems
[nPos
];
859 if ( rCtrl
.IsBindable_Impl() && !rCtrl
.GetPopupMenu() )
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() )
872 pBindings
->LEAVEREGISTRATIONS();
873 bControllersUnBound
= FALSE
;
876 void SfxVirtualMenu::UnbindControllers()
878 pBindings
->ENTERREGISTRATIONS();
881 for ( nPos
= 0; nPos
< nCount
; ++nPos
)
883 SfxMenuControl
&rCtrl
= pItems
[nPos
];
884 if ( rCtrl
.IsBound() )
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!
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
));
940 //--------------------------------------------------------------------
942 // called on activation of the SV-Menu
944 IMPL_LINK( SfxVirtualMenu
, Activate
, Menu
*, pMenu
)
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
957 sal_Bool bDontHide
= SvtMenuOptions().IsEntryHidingEnabled();
958 sal_uInt16 nFlag
= pMenu
->GetMenuFlags();
960 nFlag
&= ~MENU_FLAG_HIDEDISABLEDENTRIES
;
962 nFlag
|= MENU_FLAG_HIDEDISABLEDENTRIES
;
963 pMenu
->SetMenuFlags( nFlag
);
966 // eigenes StarView-Menu
967 if ( pMenu
== pSVMenu
)
969 // doppelt-Activate verhindern
973 // ggf. Pick-Menu erzeugen
974 if ( pParent
&& pSVMenu
== pParent
->pPickMenu
)
976 SfxPickList::Get()->CreateMenuEntries( pParent
->pPickMenu
);
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
;
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() )
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() );
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
);
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
)
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
);
1095 // VirtualMenu fuer SubMenu finden und ggf. an VirtualMenu binden
1096 bool bRet
= Bind_Impl( pMenu
);
1099 DBG_WARNING( "W1: Virtual menu konnte nicht erzeugt werden!" );
1105 //--------------------------------------------------------------------
1107 IMPL_LINK( SfxVirtualMenu
, Deactivate
, Menu
*, pMenu
)
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
1119 UnbindControllers();
1120 pBindings
->LEAVEREGISTRATIONS(); --nLocks
; bIsActive
= FALSE
;
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;
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() );
1166 pWin
->ToTop( TOTOP_RESTOREWHENMIN
);
1176 else if ( nSlotId
>= START_ITEMID_PICKLIST
&& nSlotId
<= END_ITEMID_PICKLIST
)
1178 SfxPickList::Get()->ExecuteMenuEntry( nSlotId
);
1182 if ( pMenu
->GetItemCommand( nSlotId
).Len() )
1183 pBindings
->ExecuteCommand_Impl( pMenu
->GetItemCommand( nSlotId
) );
1185 pBindings
->Execute( nSlotId
);
1190 //--------------------------------------------------------------------
1192 // returns the associated StarView-menu
1194 Menu
* SfxVirtualMenu::GetSVMenu() const
1197 DBG_CHKTHIS(SfxVirtualMenu
, 0);
1202 //--------------------------------------------------------------------
1204 // return the position of the specified item
1206 USHORT
SfxVirtualMenu::GetItemPos( USHORT nItemId
) const
1209 DBG_CHKTHIS(SfxVirtualMenu
, 0);
1211 for ( USHORT nPos
= 0; nPos
< nCount
; ++nPos
)
1212 if ( (pItems
+nPos
)->GetId() == nItemId
)
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
1224 DBG_CHKTHIS(SfxVirtualMenu
, 0);
1226 USHORT nPos
= GetItemPos(nItemId
);
1227 if ( nPos
!= MENU_ITEM_NOTFOUND
)
1228 return (pItems
+nPos
)->GetPopupMenu();
1231 //--------------------------------------------------------------------
1233 // returns the text of the item as currently shown in the menu
1235 String
SfxVirtualMenu::GetItemText( USHORT nSlotId
) const
1238 DBG_CHKTHIS(SfxVirtualMenu
, 0);
1240 USHORT nPos
= GetItemPos(nSlotId
);
1241 if ( nPos
!= MENU_ITEM_NOTFOUND
)
1242 return (pItems
+nPos
)->GetTitle();
1245 //--------------------------------------------------------------------
1247 // returns the text of the item as currently shown in the menu
1249 String
SfxVirtualMenu::GetItemHelpText( USHORT nSlotId
) const
1252 DBG_CHKTHIS(SfxVirtualMenu
, 0);
1254 USHORT nPos
= GetItemPos(nSlotId
);
1255 if ( nPos
!= MENU_ITEM_NOTFOUND
)
1256 return (pItems
+nPos
)->GetHelpText();
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();
1271 pAccMgr = pAppAccel;
1273 for ( USHORT nPos = 0; nPos < pSVMenu->GetItemCount(); ++nPos )
1275 USHORT nId = pSVMenu->GetItemId(nPos);
1276 SfxVirtualMenu *pPopup = GetPopupMenu(nId);
1278 // pPopup->InvalidateKeyCodes();
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 );
1290 //--------------------------------------------------------------------
1292 // set the checkmark of the specified item
1294 void SfxVirtualMenu::CheckItem( USHORT nItemId
, BOOL bCheck
)
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
)
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
)
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
)
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();
1346 pSubMenu
->SetPopupMenu( nItemId
, pMenu
);
1350 //--------------------------------------------------------------------
1352 // Erzwingt die Initialisierung, die sonst nur im Activate kommt
1354 void SfxVirtualMenu::InitPopup( USHORT nPos
, BOOL
/*bOLE*/ )
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
),
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();
1396 pSubMenu
->InitializeHelp();
1399 bHelpInitialized
= TRUE
;
1402 typedef ULONG (__LOADONCALLAPI
*HelpIdFunc
) ( const String
& );
1404 void SfxVirtualMenu::SetHelpIds( ResMgr
*pRes
)