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