xref: /AOO41X/main/framework/source/classes/menumanager.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_framework.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
33*cdf0e10cSrcweir //	my own includes
34*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
35*cdf0e10cSrcweir #include <classes/menumanager.hxx>
36*cdf0e10cSrcweir #include <framework/menuconfiguration.hxx>
37*cdf0e10cSrcweir #include <framework/bmkmenu.hxx>
38*cdf0e10cSrcweir #include <framework/addonmenu.hxx>
39*cdf0e10cSrcweir #include <framework/imageproducer.hxx>
40*cdf0e10cSrcweir #include <threadhelp/resetableguard.hxx>
41*cdf0e10cSrcweir #include "framework/addonsoptions.hxx"
42*cdf0e10cSrcweir #include <classes/fwkresid.hxx>
43*cdf0e10cSrcweir #include <services.h>
44*cdf0e10cSrcweir #include "classes/resource.hrc"
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
47*cdf0e10cSrcweir //	interface includes
48*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
49*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp>
50*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatch.hpp>
51*cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp>
52*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
53*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
54*cdf0e10cSrcweir #include <com/sun/star/frame/XFramesSupplier.hpp>
55*cdf0e10cSrcweir #include <com/sun/star/frame/XDesktop.hpp>
56*cdf0e10cSrcweir #include <com/sun/star/container/XEnumeration.hpp>
57*cdf0e10cSrcweir #include <com/sun/star/util/XStringWidth.hpp>
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
60*cdf0e10cSrcweir //	includes of other projects
61*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
62*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir #include <comphelper/extract.hxx>
65*cdf0e10cSrcweir #include <svtools/menuoptions.hxx>
66*cdf0e10cSrcweir #include <unotools/historyoptions.hxx>
67*cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
68*cdf0e10cSrcweir #include <unotools/localfilehelper.hxx>
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
71*cdf0e10cSrcweir #include <toolkit/unohlp.hxx>
72*cdf0e10cSrcweir #endif
73*cdf0e10cSrcweir #include <tools/urlobj.hxx>
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir #include <vcl/svapp.hxx>
76*cdf0e10cSrcweir #include <vcl/window.hxx>
77*cdf0e10cSrcweir #include <vos/mutex.hxx>
78*cdf0e10cSrcweir #include <vcl/svapp.hxx>
79*cdf0e10cSrcweir #include <osl/file.hxx>
80*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
83*cdf0e10cSrcweir //	namespace
84*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir using namespace ::cppu;
87*cdf0e10cSrcweir using namespace ::vos;
88*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
89*cdf0e10cSrcweir using namespace ::com::sun::star::util;
90*cdf0e10cSrcweir using namespace ::com::sun::star::beans;
91*cdf0e10cSrcweir using namespace ::com::sun::star::frame;
92*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
93*cdf0e10cSrcweir using namespace ::com::sun::star::container;
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir class StringLength : public ::cppu::WeakImplHelper1< ::com::sun::star::util::XStringWidth >
97*cdf0e10cSrcweir {
98*cdf0e10cSrcweir 	public:
99*cdf0e10cSrcweir 		StringLength() {}
100*cdf0e10cSrcweir 		virtual ~StringLength() {}
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir 		// XStringWidth
103*cdf0e10cSrcweir 		sal_Int32 SAL_CALL queryStringWidth( const ::rtl::OUString& aString )
104*cdf0e10cSrcweir 			throw (::com::sun::star::uno::RuntimeException)
105*cdf0e10cSrcweir 		{
106*cdf0e10cSrcweir 			return aString.getLength();
107*cdf0e10cSrcweir 		}
108*cdf0e10cSrcweir };
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir namespace framework
111*cdf0e10cSrcweir {
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir // special menu ids/command ids for dynamic popup menus
114*cdf0e10cSrcweir #define SID_SFX_START			5000
115*cdf0e10cSrcweir #define SID_NEWDOCDIRECT		(SID_SFX_START + 537)
116*cdf0e10cSrcweir #define SID_AUTOPILOTMENU		(SID_SFX_START + 1381)
117*cdf0e10cSrcweir #define SID_PICKLIST			(SID_SFX_START + 510)
118*cdf0e10cSrcweir #define SID_MDIWINDOWLIST		(SID_SFX_START + 610)
119*cdf0e10cSrcweir #define SID_ADDONLIST			(SID_SFX_START + 1677)
120*cdf0e10cSrcweir #define SID_HELPMENU			(SID_SFX_START + 410)
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir #define SFX_REFERER_USER		"private:user"
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir const ::rtl::OUString aSlotNewDocDirect( RTL_CONSTASCII_USTRINGPARAM( "slot:5537" ));
125*cdf0e10cSrcweir const ::rtl::OUString aSlotAutoPilot( RTL_CONSTASCII_USTRINGPARAM( "slot:6381" ));
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir const ::rtl::OUString aSpecialFileMenu( RTL_CONSTASCII_USTRINGPARAM( "file" ));
128*cdf0e10cSrcweir const ::rtl::OUString aSpecialWindowMenu( RTL_CONSTASCII_USTRINGPARAM( "window" ));
129*cdf0e10cSrcweir const ::rtl::OUString aSlotSpecialFileMenu( RTL_CONSTASCII_USTRINGPARAM( "slot:5510" ));
130*cdf0e10cSrcweir const ::rtl::OUString aSlotSpecialWindowMenu( RTL_CONSTASCII_USTRINGPARAM( "slot:5610" ));
131*cdf0e10cSrcweir const ::rtl::OUString aSlotSpecialToolsMenu( RTL_CONSTASCII_USTRINGPARAM( "slot:6677" ));
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir // special uno commands for picklist and window list
134*cdf0e10cSrcweir const ::rtl::OUString aSpecialFileCommand( RTL_CONSTASCII_USTRINGPARAM( "PickList" ));
135*cdf0e10cSrcweir const ::rtl::OUString aSpecialWindowCommand( RTL_CONSTASCII_USTRINGPARAM( "WindowList" ));
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir const ::rtl::OUString UNO_COMMAND( RTL_CONSTASCII_USTRINGPARAM( ".uno:" ));
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir // #110897#
140*cdf0e10cSrcweir MenuManager::MenuManager(
141*cdf0e10cSrcweir 	const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
142*cdf0e10cSrcweir 	REFERENCE< XFRAME >& rFrame, Menu* pMenu, sal_Bool bDelete, sal_Bool bDeleteChildren )
143*cdf0e10cSrcweir :	// #110897#
144*cdf0e10cSrcweir 	ThreadHelpBase( &Application::GetSolarMutex() ),
145*cdf0e10cSrcweir     mxServiceFactory(xServiceFactory)
146*cdf0e10cSrcweir {
147*cdf0e10cSrcweir 	m_bActive			= sal_False;
148*cdf0e10cSrcweir 	m_bDeleteMenu		= bDelete;
149*cdf0e10cSrcweir 	m_bDeleteChildren	= bDeleteChildren;
150*cdf0e10cSrcweir 	m_pVCLMenu			= pMenu;
151*cdf0e10cSrcweir 	m_xFrame			= rFrame;
152*cdf0e10cSrcweir 	m_bInitialized		= sal_False;
153*cdf0e10cSrcweir 	m_bIsBookmarkMenu	= sal_False;
154*cdf0e10cSrcweir 	SAL_STATIC_CAST( ::com::sun::star::uno::XInterface*, (OWeakObject*)this )->acquire();
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir 	const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
157*cdf0e10cSrcweir 	m_bWasHiContrast	= rSettings.GetHighContrastMode();
158*cdf0e10cSrcweir 	m_bShowMenuImages	= rSettings.GetUseImagesInMenus();
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir 	sal_Int32 nAddonsURLPrefixLength = ADDONSPOPUPMENU_URL_PREFIX.getLength();
161*cdf0e10cSrcweir #if 0
162*cdf0e10cSrcweir 	::std::vector< sal_uInt16 > aQueryLabelItemIdVector;
163*cdf0e10cSrcweir #endif
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir 	sal_uInt16 nItemCount = pMenu->GetItemCount();
166*cdf0e10cSrcweir     m_aMenuItemHandlerVector.reserve(nItemCount);
167*cdf0e10cSrcweir     ::rtl::OUString aItemCommand;
168*cdf0e10cSrcweir 	for ( sal_uInt16 i = 0; i < nItemCount; i++ )
169*cdf0e10cSrcweir 	{
170*cdf0e10cSrcweir 		sal_uInt16 nItemId = FillItemCommand(aItemCommand,pMenu, i );
171*cdf0e10cSrcweir         bool bShowMenuImages( m_bShowMenuImages );
172*cdf0e10cSrcweir         MenuItemBits nBits =  pMenu->GetItemBits( nItemId );
173*cdf0e10cSrcweir         // overwrite the default?
174*cdf0e10cSrcweir         if ( nBits )
175*cdf0e10cSrcweir             bShowMenuImages = ( ( nBits & MIB_ICON ) == MIB_ICON );
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir 		PopupMenu* pPopupMenu = pMenu->GetPopupMenu( nItemId );
179*cdf0e10cSrcweir 		if ( pPopupMenu )
180*cdf0e10cSrcweir 		{
181*cdf0e10cSrcweir             AddMenu(pPopupMenu,aItemCommand,nItemId,bDeleteChildren,bDeleteChildren);
182*cdf0e10cSrcweir 			if (! (( aItemCommand.getLength() > nAddonsURLPrefixLength ) &&
183*cdf0e10cSrcweir 				( aItemCommand.indexOf( ADDONSPOPUPMENU_URL_PREFIX ) == 0 )) )
184*cdf0e10cSrcweir 			{
185*cdf0e10cSrcweir 				// #110897#
186*cdf0e10cSrcweir 				// MenuManager* pSubMenuManager = new MenuManager( rFrame, pPopupMenu, bDeleteChildren, bDeleteChildren );
187*cdf0e10cSrcweir #if 0
188*cdf0e10cSrcweir 				if ( pMenu->GetItemText( nItemId ).Len() == 0 )
189*cdf0e10cSrcweir 					aQueryLabelItemIdVector.push_back( nItemId );
190*cdf0e10cSrcweir #endif
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir 				// Create addon popup menu if there exist elements and this is the tools popup menu
193*cdf0e10cSrcweir 				if (( nItemId == SID_ADDONLIST ||
194*cdf0e10cSrcweir 					aItemCommand == aSlotSpecialToolsMenu ) &&
195*cdf0e10cSrcweir 					AddonMenuManager::HasAddonMenuElements() )
196*cdf0e10cSrcweir 				{
197*cdf0e10cSrcweir 					sal_uInt16      nCount   = 0;
198*cdf0e10cSrcweir 					AddonMenu*  pSubMenu = AddonMenuManager::CreateAddonMenu( rFrame );
199*cdf0e10cSrcweir 					if ( pSubMenu && ( pSubMenu->GetItemCount() > 0 ))
200*cdf0e10cSrcweir 					{
201*cdf0e10cSrcweir 						if ( pPopupMenu->GetItemType( nCount-1 ) != MENUITEM_SEPARATOR )
202*cdf0e10cSrcweir 							pPopupMenu->InsertSeparator();
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir 					    // Use resource to load popup menu title
205*cdf0e10cSrcweir 					    String aAddonsStrRes = String( FwkResId( STR_MENU_ADDONS ));
206*cdf0e10cSrcweir 					    pPopupMenu->InsertItem( ITEMID_ADDONLIST, aAddonsStrRes );
207*cdf0e10cSrcweir 					    pPopupMenu->SetPopupMenu( ITEMID_ADDONLIST, pSubMenu );
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir 					    // Set item command for popup menu to enable it for GetImageFromURL
210*cdf0e10cSrcweir                         const static ::rtl::OUString aSlotString( RTL_CONSTASCII_USTRINGPARAM( "slot:" ));
211*cdf0e10cSrcweir 					    aItemCommand = aSlotString;
212*cdf0e10cSrcweir 					    aItemCommand += ::rtl::OUString::valueOf( (sal_Int32)ITEMID_ADDONLIST );
213*cdf0e10cSrcweir 					    pPopupMenu->SetItemCommand( ITEMID_ADDONLIST, aItemCommand );
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir 						// #110897#
216*cdf0e10cSrcweir 					    // MenuManager* pSubMenuManager = new MenuManager( rFrame, pSubMenu, sal_True, sal_False );
217*cdf0e10cSrcweir                         AddMenu(pSubMenu,::rtl::OUString(),nItemId,sal_True,sal_False);
218*cdf0e10cSrcweir #if 0
219*cdf0e10cSrcweir 					    if ( pMenu->GetItemText( nItemId ).Len() == 0 )
220*cdf0e10cSrcweir 						    aQueryLabelItemIdVector.push_back( nItemId );
221*cdf0e10cSrcweir #endif
222*cdf0e10cSrcweir 					    // Set image for the addon popup menu item
223*cdf0e10cSrcweir                         if ( bShowMenuImages && !pPopupMenu->GetItemImage( ITEMID_ADDONLIST ))
224*cdf0e10cSrcweir 					    {
225*cdf0e10cSrcweir 						    Image aImage = GetImageFromURL( rFrame, aItemCommand, sal_False, m_bWasHiContrast );
226*cdf0e10cSrcweir                 		    if ( !!aImage )
227*cdf0e10cSrcweir                    			    pPopupMenu->SetItemImage( ITEMID_ADDONLIST, aImage );
228*cdf0e10cSrcweir 					    }
229*cdf0e10cSrcweir 					}
230*cdf0e10cSrcweir 					else
231*cdf0e10cSrcweir 					    delete pSubMenu;
232*cdf0e10cSrcweir 				}
233*cdf0e10cSrcweir 			}
234*cdf0e10cSrcweir 		}
235*cdf0e10cSrcweir 		else
236*cdf0e10cSrcweir 		{
237*cdf0e10cSrcweir 			if ( nItemId == SID_NEWDOCDIRECT ||
238*cdf0e10cSrcweir 				 aItemCommand == aSlotNewDocDirect )
239*cdf0e10cSrcweir 			{
240*cdf0e10cSrcweir 				// #110897#
241*cdf0e10cSrcweir                 // Reference< ::com::sun::star::lang::XMultiServiceFactory > aMultiServiceFactory(::comphelper::getProcessServiceFactory());
242*cdf0e10cSrcweir 				// MenuConfiguration aMenuCfg( aMultiServiceFactory );
243*cdf0e10cSrcweir 				MenuConfiguration aMenuCfg( getServiceFactory() );
244*cdf0e10cSrcweir 				BmkMenu* pSubMenu = (BmkMenu*)aMenuCfg.CreateBookmarkMenu( rFrame, BOOKMARK_NEWMENU );
245*cdf0e10cSrcweir 				pMenu->SetPopupMenu( nItemId, pSubMenu );
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir 				// #110897#
248*cdf0e10cSrcweir 				// MenuManager* pSubMenuManager = new MenuManager( rFrame, pSubMenu, sal_True, sal_False );
249*cdf0e10cSrcweir                 AddMenu(pSubMenu,::rtl::OUString(),nItemId,sal_True,sal_False);
250*cdf0e10cSrcweir #if 0
251*cdf0e10cSrcweir 				if ( pMenu->GetItemText( nItemId ).Len() == 0 )
252*cdf0e10cSrcweir 					aQueryLabelItemIdVector.push_back( nItemId );
253*cdf0e10cSrcweir #endif
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir                 if ( bShowMenuImages && !pMenu->GetItemImage( nItemId ))
256*cdf0e10cSrcweir 				{
257*cdf0e10cSrcweir 					Image aImage = GetImageFromURL( rFrame, aItemCommand, sal_False, m_bWasHiContrast );
258*cdf0e10cSrcweir                 	if ( !!aImage )
259*cdf0e10cSrcweir                    		pMenu->SetItemImage( nItemId, aImage );
260*cdf0e10cSrcweir 				}
261*cdf0e10cSrcweir 			}
262*cdf0e10cSrcweir 			else if ( nItemId == SID_AUTOPILOTMENU ||
263*cdf0e10cSrcweir 					  aItemCommand == aSlotAutoPilot )
264*cdf0e10cSrcweir 			{
265*cdf0e10cSrcweir 				// #110897#
266*cdf0e10cSrcweir                 // Reference< ::com::sun::star::lang::XMultiServiceFactory > aMultiServiceFactory(::comphelper::getProcessServiceFactory());
267*cdf0e10cSrcweir 				// MenuConfiguration aMenuCfg( aMultiServiceFactory );
268*cdf0e10cSrcweir 				MenuConfiguration aMenuCfg( getServiceFactory() );
269*cdf0e10cSrcweir 				BmkMenu* pSubMenu = (BmkMenu*)aMenuCfg.CreateBookmarkMenu( rFrame, BOOKMARK_WIZARDMENU );
270*cdf0e10cSrcweir 				pMenu->SetPopupMenu( nItemId, pSubMenu );
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir 				// #110897#
273*cdf0e10cSrcweir 				// MenuManager* pSubMenuManager = new MenuManager( rFrame, pSubMenu, sal_True, sal_False );
274*cdf0e10cSrcweir                 AddMenu(pSubMenu,::rtl::OUString(),nItemId,sal_True,sal_False);
275*cdf0e10cSrcweir #if 0
276*cdf0e10cSrcweir 				if ( pMenu->GetItemText( nItemId ).Len() == 0 )
277*cdf0e10cSrcweir 					aQueryLabelItemIdVector.push_back( nItemId );
278*cdf0e10cSrcweir #endif
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir                 if ( bShowMenuImages && !pMenu->GetItemImage( nItemId ))
281*cdf0e10cSrcweir 				{
282*cdf0e10cSrcweir 					Image aImage = GetImageFromURL( rFrame, aItemCommand, sal_False, m_bWasHiContrast );
283*cdf0e10cSrcweir                 	if ( !!aImage )
284*cdf0e10cSrcweir                    		pMenu->SetItemImage( nItemId, aImage );
285*cdf0e10cSrcweir 				}
286*cdf0e10cSrcweir 			}
287*cdf0e10cSrcweir 			else if ( pMenu->GetItemType( i ) != MENUITEM_SEPARATOR )
288*cdf0e10cSrcweir 			{
289*cdf0e10cSrcweir                 if ( bShowMenuImages )
290*cdf0e10cSrcweir 			    {
291*cdf0e10cSrcweir 			        if ( AddonMenuManager::IsAddonMenuId( nItemId ))
292*cdf0e10cSrcweir 			        {
293*cdf0e10cSrcweir                         // Add-Ons uses a images from different places
294*cdf0e10cSrcweir                         Image           aImage;
295*cdf0e10cSrcweir                         rtl::OUString   aImageId;
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir 						MenuConfiguration::Attributes* pMenuAttributes =
298*cdf0e10cSrcweir 							(MenuConfiguration::Attributes*)pMenu->GetUserValue( nItemId );
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir 						if ( pMenuAttributes && pMenuAttributes->aImageId.getLength() > 0 )
301*cdf0e10cSrcweir 						{
302*cdf0e10cSrcweir 						    // Retrieve image id from menu attributes
303*cdf0e10cSrcweir 						    aImage = GetImageFromURL( rFrame, aImageId, sal_False, m_bWasHiContrast );
304*cdf0e10cSrcweir                         }
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir 	                    if ( !aImage )
307*cdf0e10cSrcweir 	                    {
308*cdf0e10cSrcweir 						    aImage = GetImageFromURL( rFrame, aItemCommand, sal_False, m_bWasHiContrast );
309*cdf0e10cSrcweir 	                        if ( !aImage )
310*cdf0e10cSrcweir                                 aImage = AddonsOptions().GetImageFromURL( aItemCommand, sal_False, m_bWasHiContrast );
311*cdf0e10cSrcweir                         }
312*cdf0e10cSrcweir 
313*cdf0e10cSrcweir 		                if ( !!aImage )
314*cdf0e10cSrcweir 		                    pMenu->SetItemImage( nItemId, aImage );
315*cdf0e10cSrcweir 			        }
316*cdf0e10cSrcweir 			        else if ( !pMenu->GetItemImage( nItemId ))
317*cdf0e10cSrcweir 			        {
318*cdf0e10cSrcweir 					    Image aImage = GetImageFromURL( rFrame, aItemCommand, sal_False, m_bWasHiContrast );
319*cdf0e10cSrcweir                 	    if ( !!aImage )
320*cdf0e10cSrcweir                    		    pMenu->SetItemImage( nItemId, aImage );
321*cdf0e10cSrcweir 			        }
322*cdf0e10cSrcweir 			    }
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir                 REFERENCE< XDISPATCH > aXDispatchRef;
325*cdf0e10cSrcweir 				m_aMenuItemHandlerVector.push_back( new MenuItemHandler( nItemId, NULL, aXDispatchRef ));
326*cdf0e10cSrcweir #if 0
327*cdf0e10cSrcweir 				if ( pMenu->GetItemText( nItemId ).Len() == 0 )
328*cdf0e10cSrcweir 					aQueryLabelItemIdVector.push_back( nItemId );
329*cdf0e10cSrcweir #endif
330*cdf0e10cSrcweir 			}
331*cdf0e10cSrcweir 		}
332*cdf0e10cSrcweir 	}
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir 
335*cdf0e10cSrcweir 	// retrieve label information for all menu items without item text
336*cdf0e10cSrcweir #if 0
337*cdf0e10cSrcweir 	if ( aQueryLabelItemIdVector.size() > 0 )
338*cdf0e10cSrcweir 	{
339*cdf0e10cSrcweir 		Sequence< ::rtl::OUString > aURLSequence( aQueryLabelItemIdVector.size() );
340*cdf0e10cSrcweir 		Sequence< ::rtl::OUString > aLabelSequence( aQueryLabelItemIdVector.size() );
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir 		sal_uInt32 nPos = 0;
343*cdf0e10cSrcweir 		::std::vector< sal_uInt16 >::iterator p;
344*cdf0e10cSrcweir 		for ( p = aQueryLabelItemIdVector.begin(); p != aQueryLabelItemIdVector.end(); p++ )
345*cdf0e10cSrcweir 			aURLSequence[nPos++] = pMenu->GetItemCommand( *p );
346*cdf0e10cSrcweir 
347*cdf0e10cSrcweir 		Reference< XDispatchInformationProvider > xDIP( xFrame, UNO_QUERY );
348*cdf0e10cSrcweir 		if ( xDIP.is() )
349*cdf0e10cSrcweir 		{
350*cdf0e10cSrcweir 			nPos = 0;
351*cdf0e10cSrcweir 			xDIP->queryDispatchInformations( aURLSequence, aLabelSequence );
352*cdf0e10cSrcweir 			for ( p = aQueryLabelItemIdVector.begin(); p != aQueryLabelItemIdVector.end(); p++ )
353*cdf0e10cSrcweir 				pMenu->SetItemText( *p, aLabelSequence( nPos++ ));
354*cdf0e10cSrcweir 		}
355*cdf0e10cSrcweir 	}
356*cdf0e10cSrcweir #endif
357*cdf0e10cSrcweir     SetHdl();
358*cdf0e10cSrcweir }
359*cdf0e10cSrcweir 
360*cdf0e10cSrcweir #if 0
361*cdf0e10cSrcweir // #110897#
362*cdf0e10cSrcweir MenuManager::MenuManager(
363*cdf0e10cSrcweir 	const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
364*cdf0e10cSrcweir 	REFERENCE< XFRAME >& rFrame, AddonMenu* pAddonMenu, sal_Bool bDelete, sal_Bool bDeleteChildren )
365*cdf0e10cSrcweir :	// #110897#
366*cdf0e10cSrcweir 	ThreadHelpBase( &Application::GetSolarMutex() ),
367*cdf0e10cSrcweir 	mxServiceFactory(xServiceFactory)
368*cdf0e10cSrcweir {
369*cdf0e10cSrcweir 	m_bActive			= sal_False;
370*cdf0e10cSrcweir 	m_bDeleteMenu		= bDelete;
371*cdf0e10cSrcweir 	m_bDeleteChildren	= bDeleteChildren;
372*cdf0e10cSrcweir 	m_pVCLMenu			= pAddonMenu;
373*cdf0e10cSrcweir 	m_xFrame			= rFrame;
374*cdf0e10cSrcweir 	m_bInitialized		= sal_False;
375*cdf0e10cSrcweir 	m_bIsBookmarkMenu	= sal_True;
376*cdf0e10cSrcweir 
377*cdf0e10cSrcweir 	const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
378*cdf0e10cSrcweir 	m_bWasHiContrast	= rSettings.GetHighContrastMode();
379*cdf0e10cSrcweir 
380*cdf0e10cSrcweir 	SAL_STATIC_CAST( ::com::sun::star::uno::XInterface*, (OWeakObject*)this )->acquire();
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir 	sal_uInt16 nItemCount = pAddonMenu->GetItemCount();
383*cdf0e10cSrcweir     m_aMenuItemHandlerVector.reserve(nItemCount);
384*cdf0e10cSrcweir     ::rtl::OUString aItemCommand;
385*cdf0e10cSrcweir 	for ( sal_uInt16 i = 0; i < nItemCount; i++ )
386*cdf0e10cSrcweir 	{
387*cdf0e10cSrcweir         sal_uInt16 nItemId = FillItemCommand(aItemCommand,pAddonMenu, i );
388*cdf0e10cSrcweir 
389*cdf0e10cSrcweir 		PopupMenu* pPopupMenu = pAddonMenu->GetPopupMenu( nItemId );
390*cdf0e10cSrcweir 		if ( pPopupMenu )
391*cdf0e10cSrcweir 		{
392*cdf0e10cSrcweir 			// #110897#
393*cdf0e10cSrcweir 			// MenuManager* pSubMenuManager = new MenuManager( rFrame, pPopupMenu, bDeleteChildren, bDeleteChildren );
394*cdf0e10cSrcweir             AddMenu(pPopupMenu,aItemCommand,nItemId,bDeleteChildren,bDeleteChildren);
395*cdf0e10cSrcweir 		}
396*cdf0e10cSrcweir 		else
397*cdf0e10cSrcweir 		{
398*cdf0e10cSrcweir 			if ( pAddonMenu->GetItemType( i ) != MENUITEM_SEPARATOR )
399*cdf0e10cSrcweir 			{
400*cdf0e10cSrcweir 				MenuConfiguration::Attributes* pAddonAttributes = (MenuConfiguration::Attributes *)(pAddonMenu->GetUserValue( nItemId ));
401*cdf0e10cSrcweir                 REFERENCE< XDISPATCH > aXDispatchRef;
402*cdf0e10cSrcweir 				MenuItemHandler* pMenuItemHandler = new MenuItemHandler( nItemId, NULL, aXDispatchRef );
403*cdf0e10cSrcweir 
404*cdf0e10cSrcweir 				if ( pAddonAttributes )
405*cdf0e10cSrcweir 				{
406*cdf0e10cSrcweir 					// read additional attributes from attributes struct and AddonMenu implementation will delete all attributes itself!!
407*cdf0e10cSrcweir 					pMenuItemHandler->aTargetFrame = pAddonAttributes->aTargetFrame;
408*cdf0e10cSrcweir 				}
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir 				m_aMenuItemHandlerVector.push_back( pMenuItemHandler );
411*cdf0e10cSrcweir 			}
412*cdf0e10cSrcweir 		}
413*cdf0e10cSrcweir 	}
414*cdf0e10cSrcweir 
415*cdf0e10cSrcweir 	SetHdl();
416*cdf0e10cSrcweir }
417*cdf0e10cSrcweir #endif
418*cdf0e10cSrcweir 
419*cdf0e10cSrcweir void MenuManager::SetHdl()
420*cdf0e10cSrcweir {
421*cdf0e10cSrcweir 	m_pVCLMenu->SetHighlightHdl( LINK( this, MenuManager, Highlight ));
422*cdf0e10cSrcweir 	m_pVCLMenu->SetActivateHdl( LINK( this, MenuManager, Activate ));
423*cdf0e10cSrcweir 	m_pVCLMenu->SetDeactivateHdl( LINK( this, MenuManager, Deactivate ));
424*cdf0e10cSrcweir 	m_pVCLMenu->SetSelectHdl( LINK( this, MenuManager, Select ));
425*cdf0e10cSrcweir 
426*cdf0e10cSrcweir     if ( mxServiceFactory.is() )
427*cdf0e10cSrcweir         m_xURLTransformer.set( mxServiceFactory->createInstance(SERVICENAME_URLTRANSFORMER),UNO_QUERY );
428*cdf0e10cSrcweir }
429*cdf0e10cSrcweir 
430*cdf0e10cSrcweir MenuManager::~MenuManager()
431*cdf0e10cSrcweir {
432*cdf0e10cSrcweir 	std::vector< MenuItemHandler* >::iterator p;
433*cdf0e10cSrcweir 	for ( p = m_aMenuItemHandlerVector.begin(); p != m_aMenuItemHandlerVector.end(); p++ )
434*cdf0e10cSrcweir 	{
435*cdf0e10cSrcweir 		MenuItemHandler* pItemHandler = *p;
436*cdf0e10cSrcweir 		pItemHandler->xMenuItemDispatch.clear();
437*cdf0e10cSrcweir 		if ( pItemHandler->pSubMenuManager )
438*cdf0e10cSrcweir 			SAL_STATIC_CAST( ::com::sun::star::uno::XInterface*, (OWeakObject*)pItemHandler->pSubMenuManager )->release();
439*cdf0e10cSrcweir 		delete pItemHandler;
440*cdf0e10cSrcweir 	}
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir 	if ( m_bDeleteMenu )
443*cdf0e10cSrcweir 		delete m_pVCLMenu;
444*cdf0e10cSrcweir }
445*cdf0e10cSrcweir 
446*cdf0e10cSrcweir 
447*cdf0e10cSrcweir MenuManager::MenuItemHandler* MenuManager::GetMenuItemHandler( sal_uInt16 nItemId )
448*cdf0e10cSrcweir {
449*cdf0e10cSrcweir 	ResetableGuard aGuard( m_aLock );
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir 	std::vector< MenuItemHandler* >::iterator p;
452*cdf0e10cSrcweir 	for ( p = m_aMenuItemHandlerVector.begin(); p != m_aMenuItemHandlerVector.end(); p++ )
453*cdf0e10cSrcweir 	{
454*cdf0e10cSrcweir 		MenuItemHandler* pItemHandler = *p;
455*cdf0e10cSrcweir 		if ( pItemHandler->nItemId == nItemId )
456*cdf0e10cSrcweir 			return pItemHandler;
457*cdf0e10cSrcweir 	}
458*cdf0e10cSrcweir 
459*cdf0e10cSrcweir 	return 0;
460*cdf0e10cSrcweir }
461*cdf0e10cSrcweir 
462*cdf0e10cSrcweir 
463*cdf0e10cSrcweir void SAL_CALL MenuManager::statusChanged( const FEATURSTATEEVENT& Event )
464*cdf0e10cSrcweir throw ( RuntimeException )
465*cdf0e10cSrcweir {
466*cdf0e10cSrcweir 	::rtl::OUString aFeatureURL = Event.FeatureURL.Complete;
467*cdf0e10cSrcweir 	MenuItemHandler* pStatusChangedMenu = NULL;
468*cdf0e10cSrcweir 
469*cdf0e10cSrcweir 	{
470*cdf0e10cSrcweir 		ResetableGuard aGuard( m_aLock );
471*cdf0e10cSrcweir 
472*cdf0e10cSrcweir 		std::vector< MenuItemHandler* >::iterator p;
473*cdf0e10cSrcweir 		for ( p = m_aMenuItemHandlerVector.begin(); p != m_aMenuItemHandlerVector.end(); p++ )
474*cdf0e10cSrcweir 		{
475*cdf0e10cSrcweir 			MenuItemHandler* pMenuItemHandler = *p;
476*cdf0e10cSrcweir 			if ( pMenuItemHandler->aMenuItemURL == aFeatureURL )
477*cdf0e10cSrcweir 			{
478*cdf0e10cSrcweir 				pStatusChangedMenu = pMenuItemHandler;
479*cdf0e10cSrcweir 				break;
480*cdf0e10cSrcweir 			}
481*cdf0e10cSrcweir 		}
482*cdf0e10cSrcweir 	}
483*cdf0e10cSrcweir 
484*cdf0e10cSrcweir 	if ( pStatusChangedMenu )
485*cdf0e10cSrcweir 	{
486*cdf0e10cSrcweir 		OGuard	aSolarGuard( Application::GetSolarMutex() );
487*cdf0e10cSrcweir 		{
488*cdf0e10cSrcweir 			ResetableGuard aGuard( m_aLock );
489*cdf0e10cSrcweir 
490*cdf0e10cSrcweir 			sal_Bool bSetCheckmark      = sal_False;
491*cdf0e10cSrcweir             sal_Bool bCheckmark			= sal_False;
492*cdf0e10cSrcweir 			sal_Bool bMenuItemEnabled	= m_pVCLMenu->IsItemEnabled( pStatusChangedMenu->nItemId );
493*cdf0e10cSrcweir 
494*cdf0e10cSrcweir 			if ( Event.IsEnabled != bMenuItemEnabled )
495*cdf0e10cSrcweir 			    m_pVCLMenu->EnableItem( pStatusChangedMenu->nItemId, Event.IsEnabled );
496*cdf0e10cSrcweir 
497*cdf0e10cSrcweir             if ( Event.State >>= bCheckmark )
498*cdf0e10cSrcweir                  bSetCheckmark = sal_True;
499*cdf0e10cSrcweir 
500*cdf0e10cSrcweir             if ( bSetCheckmark )
501*cdf0e10cSrcweir                 m_pVCLMenu->CheckItem( pStatusChangedMenu->nItemId, bCheckmark );
502*cdf0e10cSrcweir 		}
503*cdf0e10cSrcweir 
504*cdf0e10cSrcweir 		if ( Event.Requery )
505*cdf0e10cSrcweir 		{
506*cdf0e10cSrcweir 			URL aTargetURL;
507*cdf0e10cSrcweir 			aTargetURL.Complete = pStatusChangedMenu->aMenuItemURL;
508*cdf0e10cSrcweir 
509*cdf0e10cSrcweir 			// #110897#
510*cdf0e10cSrcweir 			m_xURLTransformer->parseStrict( aTargetURL );
511*cdf0e10cSrcweir 
512*cdf0e10cSrcweir 			REFERENCE< XDISPATCHPROVIDER > xDispatchProvider( m_xFrame, UNO_QUERY );
513*cdf0e10cSrcweir 			REFERENCE< XDISPATCH > xMenuItemDispatch = xDispatchProvider->queryDispatch(
514*cdf0e10cSrcweir 															aTargetURL, ::rtl::OUString(), 0 );
515*cdf0e10cSrcweir 
516*cdf0e10cSrcweir 			if ( xMenuItemDispatch.is() )
517*cdf0e10cSrcweir 			{
518*cdf0e10cSrcweir 				pStatusChangedMenu->xMenuItemDispatch	= xMenuItemDispatch;
519*cdf0e10cSrcweir 				pStatusChangedMenu->aMenuItemURL		= aTargetURL.Complete;
520*cdf0e10cSrcweir 				xMenuItemDispatch->addStatusListener( SAL_STATIC_CAST( XSTATUSLISTENER*, this ), aTargetURL );
521*cdf0e10cSrcweir 			}
522*cdf0e10cSrcweir 		}
523*cdf0e10cSrcweir 	}
524*cdf0e10cSrcweir }
525*cdf0e10cSrcweir 
526*cdf0e10cSrcweir 
527*cdf0e10cSrcweir void MenuManager::RemoveListener()
528*cdf0e10cSrcweir {
529*cdf0e10cSrcweir 	ResetableGuard aGuard( m_aLock );
530*cdf0e10cSrcweir     ClearMenuDispatch();
531*cdf0e10cSrcweir }
532*cdf0e10cSrcweir 
533*cdf0e10cSrcweir void MenuManager::ClearMenuDispatch(const EVENTOBJECT& Source,bool _bRemoveOnly)
534*cdf0e10cSrcweir {
535*cdf0e10cSrcweir 	// disposing called from parent dispatcher
536*cdf0e10cSrcweir 	// remove all listener to prepare shutdown
537*cdf0e10cSrcweir 
538*cdf0e10cSrcweir 	// #110897#
539*cdf0e10cSrcweir 	std::vector< MenuItemHandler* >::iterator p;
540*cdf0e10cSrcweir 	for ( p = m_aMenuItemHandlerVector.begin(); p != m_aMenuItemHandlerVector.end(); p++ )
541*cdf0e10cSrcweir 	{
542*cdf0e10cSrcweir 		MenuItemHandler* pItemHandler = *p;
543*cdf0e10cSrcweir 		if ( pItemHandler->xMenuItemDispatch.is() )
544*cdf0e10cSrcweir 		{
545*cdf0e10cSrcweir 			URL aTargetURL;
546*cdf0e10cSrcweir 			aTargetURL.Complete	= pItemHandler->aMenuItemURL;
547*cdf0e10cSrcweir 			m_xURLTransformer->parseStrict( aTargetURL );
548*cdf0e10cSrcweir 
549*cdf0e10cSrcweir 			pItemHandler->xMenuItemDispatch->removeStatusListener(
550*cdf0e10cSrcweir 				SAL_STATIC_CAST( XSTATUSLISTENER*, this ), aTargetURL );
551*cdf0e10cSrcweir 		}
552*cdf0e10cSrcweir 
553*cdf0e10cSrcweir 		pItemHandler->xMenuItemDispatch.clear();
554*cdf0e10cSrcweir 		if ( pItemHandler->pSubMenuManager )
555*cdf0e10cSrcweir         {
556*cdf0e10cSrcweir             if ( _bRemoveOnly )
557*cdf0e10cSrcweir 			    pItemHandler->pSubMenuManager->RemoveListener();
558*cdf0e10cSrcweir             else
559*cdf0e10cSrcweir                 pItemHandler->pSubMenuManager->disposing( Source );
560*cdf0e10cSrcweir         }
561*cdf0e10cSrcweir 	}
562*cdf0e10cSrcweir }
563*cdf0e10cSrcweir 
564*cdf0e10cSrcweir 
565*cdf0e10cSrcweir void SAL_CALL MenuManager::disposing( const EVENTOBJECT& Source ) throw ( RUNTIMEEXCEPTION )
566*cdf0e10cSrcweir {
567*cdf0e10cSrcweir 	if ( Source.Source == m_xFrame )
568*cdf0e10cSrcweir 	{
569*cdf0e10cSrcweir 		ResetableGuard aGuard( m_aLock );
570*cdf0e10cSrcweir         ClearMenuDispatch(Source,false);
571*cdf0e10cSrcweir 	}
572*cdf0e10cSrcweir 	else
573*cdf0e10cSrcweir 	{
574*cdf0e10cSrcweir 		// disposing called from menu item dispatcher, remove listener
575*cdf0e10cSrcweir 		MenuItemHandler* pMenuItemDisposing = NULL;
576*cdf0e10cSrcweir 
577*cdf0e10cSrcweir 		{
578*cdf0e10cSrcweir 			ResetableGuard aGuard( m_aLock );
579*cdf0e10cSrcweir 
580*cdf0e10cSrcweir 			std::vector< MenuItemHandler* >::iterator p;
581*cdf0e10cSrcweir 			for ( p = m_aMenuItemHandlerVector.begin(); p != m_aMenuItemHandlerVector.end(); p++ )
582*cdf0e10cSrcweir 			{
583*cdf0e10cSrcweir 				MenuItemHandler* pMenuItemHandler = *p;
584*cdf0e10cSrcweir 				if ( pMenuItemHandler->xMenuItemDispatch == Source.Source )
585*cdf0e10cSrcweir 				{
586*cdf0e10cSrcweir 					pMenuItemDisposing = pMenuItemHandler;
587*cdf0e10cSrcweir 					break;
588*cdf0e10cSrcweir 				}
589*cdf0e10cSrcweir 			}
590*cdf0e10cSrcweir 
591*cdf0e10cSrcweir 			if ( pMenuItemDisposing )
592*cdf0e10cSrcweir 			{
593*cdf0e10cSrcweir 				URL aTargetURL;
594*cdf0e10cSrcweir 				aTargetURL.Complete	= pMenuItemDisposing->aMenuItemURL;
595*cdf0e10cSrcweir 
596*cdf0e10cSrcweir 				// #110897#
597*cdf0e10cSrcweir 				m_xURLTransformer->parseStrict( aTargetURL );
598*cdf0e10cSrcweir 
599*cdf0e10cSrcweir 				pMenuItemDisposing->xMenuItemDispatch->removeStatusListener(SAL_STATIC_CAST( XSTATUSLISTENER*, this ), aTargetURL );
600*cdf0e10cSrcweir 				pMenuItemDisposing->xMenuItemDispatch.clear();
601*cdf0e10cSrcweir 			}
602*cdf0e10cSrcweir 		}
603*cdf0e10cSrcweir 	}
604*cdf0e10cSrcweir }
605*cdf0e10cSrcweir 
606*cdf0e10cSrcweir 
607*cdf0e10cSrcweir void MenuManager::UpdateSpecialFileMenu( Menu* pMenu )
608*cdf0e10cSrcweir {
609*cdf0e10cSrcweir 	// update picklist
610*cdf0e10cSrcweir 	Sequence< Sequence< PropertyValue > > aHistoryList = SvtHistoryOptions().GetList( ePICKLIST );
611*cdf0e10cSrcweir 	::std::vector< MenuItemHandler* > aNewPickVector;
612*cdf0e10cSrcweir 	Reference< XStringWidth > xStringLength( new StringLength );
613*cdf0e10cSrcweir 
614*cdf0e10cSrcweir 	sal_uInt16	nPickItemId = START_ITEMID_PICKLIST;
615*cdf0e10cSrcweir 	int		nPickListMenuItems = ( aHistoryList.getLength() > 99 ) ? 99 : aHistoryList.getLength();
616*cdf0e10cSrcweir 
617*cdf0e10cSrcweir     aNewPickVector.reserve(nPickListMenuItems);
618*cdf0e10cSrcweir 	for ( int i = 0; i < nPickListMenuItems; i++ )
619*cdf0e10cSrcweir 	{
620*cdf0e10cSrcweir 		Sequence< PropertyValue > aPickListEntry = aHistoryList[i];
621*cdf0e10cSrcweir 
622*cdf0e10cSrcweir         REFERENCE< XDISPATCH > aXDispatchRef;
623*cdf0e10cSrcweir 		MenuItemHandler* pNewMenuItemHandler = new MenuItemHandler(
624*cdf0e10cSrcweir 													nPickItemId++,
625*cdf0e10cSrcweir 													NULL,
626*cdf0e10cSrcweir 													aXDispatchRef );
627*cdf0e10cSrcweir 
628*cdf0e10cSrcweir 		for ( int j = 0; j < aPickListEntry.getLength(); j++ )
629*cdf0e10cSrcweir 		{
630*cdf0e10cSrcweir 			Any a = aPickListEntry[j].Value;
631*cdf0e10cSrcweir 
632*cdf0e10cSrcweir 			if ( aPickListEntry[j].Name == HISTORY_PROPERTYNAME_URL )
633*cdf0e10cSrcweir 				a >>= pNewMenuItemHandler->aMenuItemURL;
634*cdf0e10cSrcweir 			else if ( aPickListEntry[j].Name == HISTORY_PROPERTYNAME_FILTER )
635*cdf0e10cSrcweir 				a >>= pNewMenuItemHandler->aFilter;
636*cdf0e10cSrcweir 			else if ( aPickListEntry[j].Name == HISTORY_PROPERTYNAME_TITLE )
637*cdf0e10cSrcweir 				a >>= pNewMenuItemHandler->aTitle;
638*cdf0e10cSrcweir 			else if ( aPickListEntry[j].Name == HISTORY_PROPERTYNAME_PASSWORD )
639*cdf0e10cSrcweir 				a >>= pNewMenuItemHandler->aPassword;
640*cdf0e10cSrcweir 		}
641*cdf0e10cSrcweir 
642*cdf0e10cSrcweir 		aNewPickVector.push_back( pNewMenuItemHandler );
643*cdf0e10cSrcweir 	}
644*cdf0e10cSrcweir 
645*cdf0e10cSrcweir 	if ( !aNewPickVector.empty() )
646*cdf0e10cSrcweir 	{
647*cdf0e10cSrcweir 		URL aTargetURL;
648*cdf0e10cSrcweir 		REFERENCE< XDISPATCHPROVIDER > xDispatchProvider( m_xFrame, UNO_QUERY );
649*cdf0e10cSrcweir 
650*cdf0e10cSrcweir 		// #110897#
651*cdf0e10cSrcweir 		REFERENCE< XDISPATCH > xMenuItemDispatch;
652*cdf0e10cSrcweir 
653*cdf0e10cSrcweir         static const ::rtl::OUString s_sDefault(RTL_CONSTASCII_USTRINGPARAM("_default"));
654*cdf0e10cSrcweir 		// query for dispatcher
655*cdf0e10cSrcweir 		std::vector< MenuItemHandler* >::iterator p;
656*cdf0e10cSrcweir 		for ( p = aNewPickVector.begin(); p != aNewPickVector.end(); p++ )
657*cdf0e10cSrcweir 		{
658*cdf0e10cSrcweir 			MenuItemHandler* pMenuItemHandler = *p;
659*cdf0e10cSrcweir 
660*cdf0e10cSrcweir 			aTargetURL.Complete = pMenuItemHandler->aMenuItemURL;
661*cdf0e10cSrcweir 			m_xURLTransformer->parseStrict( aTargetURL );
662*cdf0e10cSrcweir 
663*cdf0e10cSrcweir 			if ( !xMenuItemDispatch.is() )
664*cdf0e10cSrcweir 			{
665*cdf0e10cSrcweir 				// attention: this code assume that "_blank" can only be consumed by desktop service
666*cdf0e10cSrcweir                 xMenuItemDispatch = xDispatchProvider->queryDispatch( aTargetURL, s_sDefault, 0 );
667*cdf0e10cSrcweir 			}
668*cdf0e10cSrcweir 
669*cdf0e10cSrcweir 			if ( xMenuItemDispatch.is() )
670*cdf0e10cSrcweir 			{
671*cdf0e10cSrcweir 				pMenuItemHandler->xMenuItemDispatch = xMenuItemDispatch;
672*cdf0e10cSrcweir 				pMenuItemHandler->aMenuItemURL		= aTargetURL.Complete;
673*cdf0e10cSrcweir 			}
674*cdf0e10cSrcweir 		}
675*cdf0e10cSrcweir 
676*cdf0e10cSrcweir 		{
677*cdf0e10cSrcweir 			ResetableGuard aGuard( m_aLock );
678*cdf0e10cSrcweir 
679*cdf0e10cSrcweir 			int	nRemoveItemCount = 0;
680*cdf0e10cSrcweir 			int	nItemCount		 = pMenu->GetItemCount();
681*cdf0e10cSrcweir 
682*cdf0e10cSrcweir 			if ( nItemCount > 0 )
683*cdf0e10cSrcweir 			{
684*cdf0e10cSrcweir 				// remove all old picklist entries from menu
685*cdf0e10cSrcweir 				sal_uInt16 nPos = pMenu->GetItemPos( START_ITEMID_PICKLIST );
686*cdf0e10cSrcweir 				for ( sal_uInt16 n = nPos; n < pMenu->GetItemCount(); )
687*cdf0e10cSrcweir 				{
688*cdf0e10cSrcweir 					pMenu->RemoveItem( n );
689*cdf0e10cSrcweir 					++nRemoveItemCount;
690*cdf0e10cSrcweir 				}
691*cdf0e10cSrcweir 
692*cdf0e10cSrcweir 				if ( pMenu->GetItemType( pMenu->GetItemCount()-1 ) == MENUITEM_SEPARATOR )
693*cdf0e10cSrcweir 					pMenu->RemoveItem( pMenu->GetItemCount()-1 );
694*cdf0e10cSrcweir 
695*cdf0e10cSrcweir 				// remove all old picklist entries from menu handler
696*cdf0e10cSrcweir 				if ( nRemoveItemCount > 0 )
697*cdf0e10cSrcweir 				{
698*cdf0e10cSrcweir 					for( sal_uInt32 nIndex = m_aMenuItemHandlerVector.size() - nRemoveItemCount;
699*cdf0e10cSrcweir 						 nIndex < m_aMenuItemHandlerVector.size();  )
700*cdf0e10cSrcweir 					{
701*cdf0e10cSrcweir 						delete m_aMenuItemHandlerVector.at( nIndex );
702*cdf0e10cSrcweir 						m_aMenuItemHandlerVector.erase( m_aMenuItemHandlerVector.begin() + nIndex );
703*cdf0e10cSrcweir 					}
704*cdf0e10cSrcweir 				}
705*cdf0e10cSrcweir 			}
706*cdf0e10cSrcweir 
707*cdf0e10cSrcweir 			// append new picklist menu entries
708*cdf0e10cSrcweir             aNewPickVector.reserve(aNewPickVector.size());
709*cdf0e10cSrcweir 			pMenu->InsertSeparator();
710*cdf0e10cSrcweir             const sal_uInt32 nCount = aNewPickVector.size();
711*cdf0e10cSrcweir             for ( sal_uInt32 i = 0; i < nCount; i++ )
712*cdf0e10cSrcweir 			{
713*cdf0e10cSrcweir 				char menuShortCut[5] = "~n: ";
714*cdf0e10cSrcweir 
715*cdf0e10cSrcweir 				::rtl::OUString aMenuShortCut;
716*cdf0e10cSrcweir 				if ( i <= 9 )
717*cdf0e10cSrcweir 				{
718*cdf0e10cSrcweir 					if ( i == 9 )
719*cdf0e10cSrcweir 						aMenuShortCut = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "1~0: " ));
720*cdf0e10cSrcweir 					else
721*cdf0e10cSrcweir 					{
722*cdf0e10cSrcweir 						menuShortCut[1] = (char)( '1' + i );
723*cdf0e10cSrcweir 						aMenuShortCut = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( menuShortCut ));
724*cdf0e10cSrcweir 					}
725*cdf0e10cSrcweir 				}
726*cdf0e10cSrcweir 				else
727*cdf0e10cSrcweir 				{
728*cdf0e10cSrcweir 					aMenuShortCut = rtl::OUString::valueOf((sal_Int32)( i + 1 ));
729*cdf0e10cSrcweir 					aMenuShortCut += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ": " ));
730*cdf0e10cSrcweir 				}
731*cdf0e10cSrcweir 
732*cdf0e10cSrcweir 				// Abbreviate URL
733*cdf0e10cSrcweir 				rtl::OUString	aURLString( aNewPickVector.at( i )->aMenuItemURL );
734*cdf0e10cSrcweir 				rtl::OUString	aTipHelpText;
735*cdf0e10cSrcweir 				rtl::OUString	aMenuTitle;
736*cdf0e10cSrcweir 				INetURLObject	aURL( aURLString );
737*cdf0e10cSrcweir 
738*cdf0e10cSrcweir 				if ( aURL.GetProtocol() == INET_PROT_FILE )
739*cdf0e10cSrcweir 				{
740*cdf0e10cSrcweir 					// Do handle file URL differently => convert it to a system
741*cdf0e10cSrcweir 					// path and abbreviate it with a special function:
742*cdf0e10cSrcweir 					String aFileSystemPath( aURL.getFSysPath( INetURLObject::FSYS_DETECT ) );
743*cdf0e10cSrcweir 
744*cdf0e10cSrcweir 					::rtl::OUString	aSystemPath( aFileSystemPath );
745*cdf0e10cSrcweir 					::rtl::OUString	aCompactedSystemPath;
746*cdf0e10cSrcweir 
747*cdf0e10cSrcweir 					aTipHelpText = aSystemPath;
748*cdf0e10cSrcweir 					oslFileError nError = osl_abbreviateSystemPath( aSystemPath.pData, &aCompactedSystemPath.pData, 46, NULL );
749*cdf0e10cSrcweir 					if ( !nError )
750*cdf0e10cSrcweir 						aMenuTitle = String( aCompactedSystemPath );
751*cdf0e10cSrcweir 					else
752*cdf0e10cSrcweir 						aMenuTitle = aSystemPath;
753*cdf0e10cSrcweir 				}
754*cdf0e10cSrcweir 				else
755*cdf0e10cSrcweir 				{
756*cdf0e10cSrcweir 					// Use INetURLObject to abbreviate all other URLs
757*cdf0e10cSrcweir 					String	aShortURL;
758*cdf0e10cSrcweir 					aShortURL = aURL.getAbbreviated( xStringLength, 46, INetURLObject::DECODE_UNAMBIGUOUS );
759*cdf0e10cSrcweir 					aMenuTitle += aShortURL;
760*cdf0e10cSrcweir 					aTipHelpText = aURLString;
761*cdf0e10cSrcweir 				}
762*cdf0e10cSrcweir 
763*cdf0e10cSrcweir 				::rtl::OUString aTitle( aMenuShortCut + aMenuTitle );
764*cdf0e10cSrcweir 
765*cdf0e10cSrcweir 				MenuItemHandler* pMenuItemHandler = aNewPickVector.at( i );
766*cdf0e10cSrcweir 				pMenu->InsertItem( pMenuItemHandler->nItemId, aTitle );
767*cdf0e10cSrcweir 				pMenu->SetTipHelpText( pMenuItemHandler->nItemId, aTipHelpText );
768*cdf0e10cSrcweir 				m_aMenuItemHandlerVector.push_back( pMenuItemHandler );
769*cdf0e10cSrcweir 			}
770*cdf0e10cSrcweir 		}
771*cdf0e10cSrcweir 	}
772*cdf0e10cSrcweir }
773*cdf0e10cSrcweir 
774*cdf0e10cSrcweir void MenuManager::UpdateSpecialWindowMenu( Menu* pMenu,const Reference< XMultiServiceFactory >& xServiceFactory,framework::IMutex& _rMutex )
775*cdf0e10cSrcweir {
776*cdf0e10cSrcweir 	// update window list
777*cdf0e10cSrcweir 	::std::vector< ::rtl::OUString > aNewWindowListVector;
778*cdf0e10cSrcweir 
779*cdf0e10cSrcweir 	// #110897#
780*cdf0e10cSrcweir 	Reference< XDesktop > xDesktop( xServiceFactory->createInstance( SERVICENAME_DESKTOP ), UNO_QUERY );
781*cdf0e10cSrcweir 
782*cdf0e10cSrcweir 	sal_uInt16	nActiveItemId = 0;
783*cdf0e10cSrcweir 	sal_uInt16	nItemId = START_ITEMID_WINDOWLIST;
784*cdf0e10cSrcweir 
785*cdf0e10cSrcweir 	if ( xDesktop.is() )
786*cdf0e10cSrcweir 	{
787*cdf0e10cSrcweir         Reference< XFramesSupplier > xTasksSupplier( xDesktop, UNO_QUERY );
788*cdf0e10cSrcweir 		Reference< XFrame > xCurrentFrame = xDesktop->getCurrentFrame();
789*cdf0e10cSrcweir         Reference< XIndexAccess > xList( xTasksSupplier->getFrames(), UNO_QUERY );
790*cdf0e10cSrcweir         sal_Int32 nCount = xList->getCount();
791*cdf0e10cSrcweir         aNewWindowListVector.reserve(nCount);
792*cdf0e10cSrcweir         for (sal_Int32 i=0; i<nCount; ++i )
793*cdf0e10cSrcweir 		{
794*cdf0e10cSrcweir             Reference< XFrame > xFrame;
795*cdf0e10cSrcweir             xList->getByIndex(i) >>= xFrame;
796*cdf0e10cSrcweir 
797*cdf0e10cSrcweir             if (xFrame.is())
798*cdf0e10cSrcweir             {
799*cdf0e10cSrcweir                 if ( xFrame == xCurrentFrame )
800*cdf0e10cSrcweir                     nActiveItemId = nItemId;
801*cdf0e10cSrcweir 
802*cdf0e10cSrcweir                 Window* pWin = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
803*cdf0e10cSrcweir                 if ( pWin && pWin->IsVisible() )
804*cdf0e10cSrcweir                 {
805*cdf0e10cSrcweir                     aNewWindowListVector.push_back( pWin->GetText() );
806*cdf0e10cSrcweir                     ++nItemId;
807*cdf0e10cSrcweir                 }
808*cdf0e10cSrcweir             }
809*cdf0e10cSrcweir 		}
810*cdf0e10cSrcweir 	}
811*cdf0e10cSrcweir 
812*cdf0e10cSrcweir 	{
813*cdf0e10cSrcweir 		ResetableGuard aGuard( _rMutex );
814*cdf0e10cSrcweir 
815*cdf0e10cSrcweir 		int	nItemCount = pMenu->GetItemCount();
816*cdf0e10cSrcweir 
817*cdf0e10cSrcweir 		if ( nItemCount > 0 )
818*cdf0e10cSrcweir 		{
819*cdf0e10cSrcweir 			// remove all old window list entries from menu
820*cdf0e10cSrcweir 			sal_uInt16 nPos = pMenu->GetItemPos( START_ITEMID_WINDOWLIST );
821*cdf0e10cSrcweir             for ( sal_uInt16 n = nPos; n < pMenu->GetItemCount(); )
822*cdf0e10cSrcweir                 pMenu->RemoveItem( n );
823*cdf0e10cSrcweir 
824*cdf0e10cSrcweir 			if ( pMenu->GetItemType( pMenu->GetItemCount()-1 ) == MENUITEM_SEPARATOR )
825*cdf0e10cSrcweir                 pMenu->RemoveItem( pMenu->GetItemCount()-1 );
826*cdf0e10cSrcweir 		}
827*cdf0e10cSrcweir 
828*cdf0e10cSrcweir 		if ( !aNewWindowListVector.empty() )
829*cdf0e10cSrcweir 		{
830*cdf0e10cSrcweir 			// append new window list entries to menu
831*cdf0e10cSrcweir 			pMenu->InsertSeparator();
832*cdf0e10cSrcweir 			nItemId = START_ITEMID_WINDOWLIST;
833*cdf0e10cSrcweir             const sal_uInt32 nCount = aNewWindowListVector.size();
834*cdf0e10cSrcweir             for ( sal_uInt32 i = 0; i < nCount; i++ )
835*cdf0e10cSrcweir 			{
836*cdf0e10cSrcweir 				pMenu->InsertItem( nItemId, aNewWindowListVector.at( i ), MIB_RADIOCHECK );
837*cdf0e10cSrcweir 				if ( nItemId == nActiveItemId )
838*cdf0e10cSrcweir 					pMenu->CheckItem( nItemId );
839*cdf0e10cSrcweir 				++nItemId;
840*cdf0e10cSrcweir 			}
841*cdf0e10cSrcweir 		}
842*cdf0e10cSrcweir 	}
843*cdf0e10cSrcweir }
844*cdf0e10cSrcweir 
845*cdf0e10cSrcweir 
846*cdf0e10cSrcweir void MenuManager::CreatePicklistArguments( Sequence< PropertyValue >& aArgsList, const MenuItemHandler* pMenuItemHandler )
847*cdf0e10cSrcweir {
848*cdf0e10cSrcweir 	int NUM_OF_PICKLIST_ARGS = 3;
849*cdf0e10cSrcweir 
850*cdf0e10cSrcweir 	Any a;
851*cdf0e10cSrcweir 	aArgsList.realloc( NUM_OF_PICKLIST_ARGS );
852*cdf0e10cSrcweir 
853*cdf0e10cSrcweir 	aArgsList[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FileName" ));
854*cdf0e10cSrcweir 	a <<= pMenuItemHandler->aMenuItemURL;
855*cdf0e10cSrcweir 	aArgsList[0].Value = a;
856*cdf0e10cSrcweir 
857*cdf0e10cSrcweir 	aArgsList[1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Referer" ));
858*cdf0e10cSrcweir 	a <<= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SFX_REFERER_USER ));
859*cdf0e10cSrcweir 	aArgsList[1].Value = a;
860*cdf0e10cSrcweir 
861*cdf0e10cSrcweir 	::rtl::OUString aFilter( pMenuItemHandler->aFilter );
862*cdf0e10cSrcweir 
863*cdf0e10cSrcweir 	sal_Int32 nPos = aFilter.indexOf( '|' );
864*cdf0e10cSrcweir 	if ( nPos >= 0 )
865*cdf0e10cSrcweir 	{
866*cdf0e10cSrcweir 		::rtl::OUString aFilterOptions;
867*cdf0e10cSrcweir 
868*cdf0e10cSrcweir 		if ( nPos < ( aFilter.getLength() - 1 ) )
869*cdf0e10cSrcweir 			aFilterOptions = aFilter.copy( nPos+1 );
870*cdf0e10cSrcweir 
871*cdf0e10cSrcweir 		aArgsList[2].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterOptions" ));
872*cdf0e10cSrcweir 		a <<= aFilterOptions;
873*cdf0e10cSrcweir 		aArgsList[2].Value = a;
874*cdf0e10cSrcweir 
875*cdf0e10cSrcweir 		aFilter = aFilter.copy( 0, nPos-1 );
876*cdf0e10cSrcweir 		aArgsList.realloc( ++NUM_OF_PICKLIST_ARGS );
877*cdf0e10cSrcweir 	}
878*cdf0e10cSrcweir 
879*cdf0e10cSrcweir 	aArgsList[NUM_OF_PICKLIST_ARGS-1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterName" ));
880*cdf0e10cSrcweir 	a <<= aFilter;
881*cdf0e10cSrcweir 	aArgsList[NUM_OF_PICKLIST_ARGS-1].Value = a;
882*cdf0e10cSrcweir }
883*cdf0e10cSrcweir 
884*cdf0e10cSrcweir 
885*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
886*cdf0e10cSrcweir // vcl handler
887*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
888*cdf0e10cSrcweir 
889*cdf0e10cSrcweir IMPL_LINK( MenuManager, Activate, Menu *, pMenu )
890*cdf0e10cSrcweir {
891*cdf0e10cSrcweir 	if ( pMenu == m_pVCLMenu )
892*cdf0e10cSrcweir 	{
893*cdf0e10cSrcweir 		// set/unset hiding disabled menu entries
894*cdf0e10cSrcweir 		sal_Bool bDontHide			= SvtMenuOptions().IsEntryHidingEnabled();
895*cdf0e10cSrcweir 		const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
896*cdf0e10cSrcweir 		sal_Bool bShowMenuImages	= rSettings.GetUseImagesInMenus();
897*cdf0e10cSrcweir 
898*cdf0e10cSrcweir 		sal_uInt16 nFlag = pMenu->GetMenuFlags();
899*cdf0e10cSrcweir 		if ( bDontHide )
900*cdf0e10cSrcweir 			nFlag &= ~MENU_FLAG_HIDEDISABLEDENTRIES;
901*cdf0e10cSrcweir 		else
902*cdf0e10cSrcweir 			nFlag |= MENU_FLAG_HIDEDISABLEDENTRIES;
903*cdf0e10cSrcweir 		pMenu->SetMenuFlags( nFlag );
904*cdf0e10cSrcweir 
905*cdf0e10cSrcweir 		if ( m_bActive )
906*cdf0e10cSrcweir 			return 0;
907*cdf0e10cSrcweir 
908*cdf0e10cSrcweir 		m_bActive = sal_True;
909*cdf0e10cSrcweir 
910*cdf0e10cSrcweir 		::rtl::OUString aCommand( m_aMenuItemCommand );
911*cdf0e10cSrcweir 		if ( m_aMenuItemCommand.matchIgnoreAsciiCase( UNO_COMMAND, 0 ))
912*cdf0e10cSrcweir 		{
913*cdf0e10cSrcweir 			// Remove protocol part from command so we can use an easier comparision method
914*cdf0e10cSrcweir 			aCommand = aCommand.copy( UNO_COMMAND.getLength() );
915*cdf0e10cSrcweir 		}
916*cdf0e10cSrcweir 
917*cdf0e10cSrcweir 		if ( m_aMenuItemCommand == aSpecialFileMenu ||
918*cdf0e10cSrcweir 			 m_aMenuItemCommand == aSlotSpecialFileMenu ||
919*cdf0e10cSrcweir 			 aCommand == aSpecialFileCommand )
920*cdf0e10cSrcweir 			UpdateSpecialFileMenu( pMenu );
921*cdf0e10cSrcweir 		else if ( m_aMenuItemCommand == aSpecialWindowMenu ||
922*cdf0e10cSrcweir 				  m_aMenuItemCommand == aSlotSpecialWindowMenu ||
923*cdf0e10cSrcweir 				  aCommand == aSpecialWindowCommand )
924*cdf0e10cSrcweir                   UpdateSpecialWindowMenu( pMenu,getServiceFactory(),m_aLock );
925*cdf0e10cSrcweir 
926*cdf0e10cSrcweir 		// Check if some modes have changed so we have to update our menu images
927*cdf0e10cSrcweir 		sal_Bool bIsHiContrast = rSettings.GetHighContrastMode();
928*cdf0e10cSrcweir 
929*cdf0e10cSrcweir 		if ( m_bWasHiContrast != bIsHiContrast || bShowMenuImages != m_bShowMenuImages )
930*cdf0e10cSrcweir 		{
931*cdf0e10cSrcweir 			// The mode changed so we have to replace all images
932*cdf0e10cSrcweir 			m_bWasHiContrast	= bIsHiContrast;
933*cdf0e10cSrcweir 			m_bShowMenuImages	= bShowMenuImages;
934*cdf0e10cSrcweir 			FillMenuImages(m_xFrame,pMenu,bIsHiContrast,bShowMenuImages);
935*cdf0e10cSrcweir 		}
936*cdf0e10cSrcweir 
937*cdf0e10cSrcweir 		if ( m_bInitialized )
938*cdf0e10cSrcweir 			return 0;
939*cdf0e10cSrcweir 		else
940*cdf0e10cSrcweir 		{
941*cdf0e10cSrcweir 			URL aTargetURL;
942*cdf0e10cSrcweir 
943*cdf0e10cSrcweir 			// #110897#
944*cdf0e10cSrcweir 			ResetableGuard aGuard( m_aLock );
945*cdf0e10cSrcweir 
946*cdf0e10cSrcweir 			REFERENCE< XDISPATCHPROVIDER > xDispatchProvider( m_xFrame, UNO_QUERY );
947*cdf0e10cSrcweir 			if ( xDispatchProvider.is() )
948*cdf0e10cSrcweir 			{
949*cdf0e10cSrcweir 				std::vector< MenuItemHandler* >::iterator p;
950*cdf0e10cSrcweir 				for ( p = m_aMenuItemHandlerVector.begin(); p != m_aMenuItemHandlerVector.end(); p++ )
951*cdf0e10cSrcweir 				{
952*cdf0e10cSrcweir 					MenuItemHandler* pMenuItemHandler = *p;
953*cdf0e10cSrcweir 					if ( pMenuItemHandler &&
954*cdf0e10cSrcweir 						 pMenuItemHandler->pSubMenuManager == 0 &&
955*cdf0e10cSrcweir 						 !pMenuItemHandler->xMenuItemDispatch.is() )
956*cdf0e10cSrcweir 					{
957*cdf0e10cSrcweir 						// There is no dispatch mechanism for the special window list menu items,
958*cdf0e10cSrcweir 						// because they are handled directly through XFrame->activate!!!
959*cdf0e10cSrcweir 						if ( pMenuItemHandler->nItemId < START_ITEMID_WINDOWLIST ||
960*cdf0e10cSrcweir 							 pMenuItemHandler->nItemId > END_ITEMID_WINDOWLIST )
961*cdf0e10cSrcweir 						{
962*cdf0e10cSrcweir 							::rtl::OUString aItemCommand = pMenu->GetItemCommand( pMenuItemHandler->nItemId );
963*cdf0e10cSrcweir 							if ( !aItemCommand.getLength() )
964*cdf0e10cSrcweir 							{
965*cdf0e10cSrcweir                                 const static ::rtl::OUString aSlotString( RTL_CONSTASCII_USTRINGPARAM( "slot:" ));
966*cdf0e10cSrcweir 								aItemCommand = aSlotString;
967*cdf0e10cSrcweir 								aItemCommand += ::rtl::OUString::valueOf( (sal_Int32)pMenuItemHandler->nItemId );
968*cdf0e10cSrcweir 								pMenu->SetItemCommand( pMenuItemHandler->nItemId, aItemCommand );
969*cdf0e10cSrcweir 							}
970*cdf0e10cSrcweir 
971*cdf0e10cSrcweir 							aTargetURL.Complete = aItemCommand;
972*cdf0e10cSrcweir 
973*cdf0e10cSrcweir 							m_xURLTransformer->parseStrict( aTargetURL );
974*cdf0e10cSrcweir 
975*cdf0e10cSrcweir 							REFERENCE< XDISPATCH > xMenuItemDispatch;
976*cdf0e10cSrcweir 							if ( m_bIsBookmarkMenu )
977*cdf0e10cSrcweir 								xMenuItemDispatch = xDispatchProvider->queryDispatch( aTargetURL, pMenuItemHandler->aTargetFrame, 0 );
978*cdf0e10cSrcweir 							else
979*cdf0e10cSrcweir 								xMenuItemDispatch = xDispatchProvider->queryDispatch( aTargetURL, ::rtl::OUString(), 0 );
980*cdf0e10cSrcweir 
981*cdf0e10cSrcweir 							if ( xMenuItemDispatch.is() )
982*cdf0e10cSrcweir 							{
983*cdf0e10cSrcweir 								pMenuItemHandler->xMenuItemDispatch = xMenuItemDispatch;
984*cdf0e10cSrcweir 								pMenuItemHandler->aMenuItemURL		= aTargetURL.Complete;
985*cdf0e10cSrcweir 								xMenuItemDispatch->addStatusListener( SAL_STATIC_CAST( XSTATUSLISTENER*, this ), aTargetURL );
986*cdf0e10cSrcweir 							}
987*cdf0e10cSrcweir 							else
988*cdf0e10cSrcweir 								pMenu->EnableItem( pMenuItemHandler->nItemId, sal_False );
989*cdf0e10cSrcweir 						}
990*cdf0e10cSrcweir 					}
991*cdf0e10cSrcweir 				}
992*cdf0e10cSrcweir 			}
993*cdf0e10cSrcweir 		}
994*cdf0e10cSrcweir 	}
995*cdf0e10cSrcweir 
996*cdf0e10cSrcweir 	return 1;
997*cdf0e10cSrcweir }
998*cdf0e10cSrcweir 
999*cdf0e10cSrcweir 
1000*cdf0e10cSrcweir IMPL_LINK( MenuManager, Deactivate, Menu *, pMenu )
1001*cdf0e10cSrcweir {
1002*cdf0e10cSrcweir 	if ( pMenu == m_pVCLMenu )
1003*cdf0e10cSrcweir 		m_bActive = sal_False;
1004*cdf0e10cSrcweir 
1005*cdf0e10cSrcweir 	return 1;
1006*cdf0e10cSrcweir }
1007*cdf0e10cSrcweir 
1008*cdf0e10cSrcweir 
1009*cdf0e10cSrcweir IMPL_LINK( MenuManager, Select, Menu *, pMenu )
1010*cdf0e10cSrcweir {
1011*cdf0e10cSrcweir 	URL						aTargetURL;
1012*cdf0e10cSrcweir 	Sequence<PropertyValue>	aArgs;
1013*cdf0e10cSrcweir 	REFERENCE< XDISPATCH >	xDispatch;
1014*cdf0e10cSrcweir 
1015*cdf0e10cSrcweir 	{
1016*cdf0e10cSrcweir 		ResetableGuard aGuard( m_aLock );
1017*cdf0e10cSrcweir 
1018*cdf0e10cSrcweir 		sal_uInt16 nCurItemId = pMenu->GetCurItemId();
1019*cdf0e10cSrcweir 		if ( pMenu == m_pVCLMenu &&
1020*cdf0e10cSrcweir 			 pMenu->GetItemType( nCurItemId ) != MENUITEM_SEPARATOR )
1021*cdf0e10cSrcweir 		{
1022*cdf0e10cSrcweir 			if ( nCurItemId >= START_ITEMID_WINDOWLIST &&
1023*cdf0e10cSrcweir 				 nCurItemId <= END_ITEMID_WINDOWLIST )
1024*cdf0e10cSrcweir 			{
1025*cdf0e10cSrcweir 				// window list menu item selected
1026*cdf0e10cSrcweir 
1027*cdf0e10cSrcweir 				// #110897#
1028*cdf0e10cSrcweir                 // Reference< XFramesSupplier > xDesktop( ::comphelper::getProcessServiceFactory()->createInstance(
1029*cdf0e10cSrcweir 				//	DESKTOP_SERVICE ), UNO_QUERY );
1030*cdf0e10cSrcweir                 Reference< XFramesSupplier > xDesktop( getServiceFactory()->createInstance( SERVICENAME_DESKTOP ), UNO_QUERY );
1031*cdf0e10cSrcweir 
1032*cdf0e10cSrcweir 				if ( xDesktop.is() )
1033*cdf0e10cSrcweir 				{
1034*cdf0e10cSrcweir 					sal_uInt16 nTaskId = START_ITEMID_WINDOWLIST;
1035*cdf0e10cSrcweir                     Reference< XIndexAccess > xList( xDesktop->getFrames(), UNO_QUERY );
1036*cdf0e10cSrcweir                     sal_Int32 nCount = xList->getCount();
1037*cdf0e10cSrcweir                     for ( sal_Int32 i=0; i<nCount; ++i )
1038*cdf0e10cSrcweir 					{
1039*cdf0e10cSrcweir                         Reference< XFrame > xFrame;
1040*cdf0e10cSrcweir                         xList->getByIndex(i) >>= xFrame;
1041*cdf0e10cSrcweir 
1042*cdf0e10cSrcweir                         if ( xFrame.is() && nTaskId == nCurItemId )
1043*cdf0e10cSrcweir 						{
1044*cdf0e10cSrcweir                             Window* pWin = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
1045*cdf0e10cSrcweir 							pWin->GrabFocus();
1046*cdf0e10cSrcweir 							pWin->ToTop( TOTOP_RESTOREWHENMIN );
1047*cdf0e10cSrcweir 							break;
1048*cdf0e10cSrcweir 						}
1049*cdf0e10cSrcweir 
1050*cdf0e10cSrcweir 						nTaskId++;
1051*cdf0e10cSrcweir 					}
1052*cdf0e10cSrcweir 				}
1053*cdf0e10cSrcweir 			}
1054*cdf0e10cSrcweir 			else
1055*cdf0e10cSrcweir 			{
1056*cdf0e10cSrcweir 				MenuItemHandler* pMenuItemHandler = GetMenuItemHandler( nCurItemId );
1057*cdf0e10cSrcweir 				if ( pMenuItemHandler && pMenuItemHandler->xMenuItemDispatch.is() )
1058*cdf0e10cSrcweir 				{
1059*cdf0e10cSrcweir 					aTargetURL.Complete = pMenuItemHandler->aMenuItemURL;
1060*cdf0e10cSrcweir 					m_xURLTransformer->parseStrict( aTargetURL );
1061*cdf0e10cSrcweir 
1062*cdf0e10cSrcweir 					if ( nCurItemId >= START_ITEMID_PICKLIST &&
1063*cdf0e10cSrcweir 						 nCurItemId <  START_ITEMID_WINDOWLIST )
1064*cdf0e10cSrcweir 					{
1065*cdf0e10cSrcweir 						// picklist menu item selected
1066*cdf0e10cSrcweir 						CreatePicklistArguments( aArgs, pMenuItemHandler );
1067*cdf0e10cSrcweir 					}
1068*cdf0e10cSrcweir 					else if ( m_bIsBookmarkMenu )
1069*cdf0e10cSrcweir 					{
1070*cdf0e10cSrcweir 						// bookmark menu item selected
1071*cdf0e10cSrcweir 						aArgs.realloc( 1 );
1072*cdf0e10cSrcweir 						aArgs[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Referer" ));
1073*cdf0e10cSrcweir 						aArgs[0].Value <<= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SFX_REFERER_USER ));
1074*cdf0e10cSrcweir 					}
1075*cdf0e10cSrcweir 
1076*cdf0e10cSrcweir 					xDispatch = pMenuItemHandler->xMenuItemDispatch;
1077*cdf0e10cSrcweir 				}
1078*cdf0e10cSrcweir 			}
1079*cdf0e10cSrcweir 		}
1080*cdf0e10cSrcweir 	}
1081*cdf0e10cSrcweir 
1082*cdf0e10cSrcweir 	if ( xDispatch.is() )
1083*cdf0e10cSrcweir 		xDispatch->dispatch( aTargetURL, aArgs );
1084*cdf0e10cSrcweir 
1085*cdf0e10cSrcweir 	return 1;
1086*cdf0e10cSrcweir }
1087*cdf0e10cSrcweir 
1088*cdf0e10cSrcweir 
1089*cdf0e10cSrcweir IMPL_LINK( MenuManager, Highlight, Menu *, EMPTYARG )
1090*cdf0e10cSrcweir {
1091*cdf0e10cSrcweir 	return 0;
1092*cdf0e10cSrcweir }
1093*cdf0e10cSrcweir 
1094*cdf0e10cSrcweir // #110897#
1095*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& MenuManager::getServiceFactory()
1096*cdf0e10cSrcweir {
1097*cdf0e10cSrcweir 	// #110897#
1098*cdf0e10cSrcweir 	return mxServiceFactory;
1099*cdf0e10cSrcweir }
1100*cdf0e10cSrcweir 
1101*cdf0e10cSrcweir void MenuManager::AddMenu(PopupMenu* _pPopupMenu,const ::rtl::OUString& _sItemCommand,sal_uInt16 _nItemId,sal_Bool _bDelete,sal_Bool _bDeleteChildren)
1102*cdf0e10cSrcweir {
1103*cdf0e10cSrcweir     MenuManager* pSubMenuManager = new MenuManager( getServiceFactory(), m_xFrame, _pPopupMenu, _bDelete, _bDeleteChildren );
1104*cdf0e10cSrcweir 
1105*cdf0e10cSrcweir 	// store menu item command as we later have to know which menu is active (see Activate handler)
1106*cdf0e10cSrcweir 	pSubMenuManager->m_aMenuItemCommand = _sItemCommand;
1107*cdf0e10cSrcweir 
1108*cdf0e10cSrcweir 	REFERENCE< XDISPATCH > aXDispatchRef;
1109*cdf0e10cSrcweir 	MenuItemHandler* pMenuItemHandler = new MenuItemHandler(
1110*cdf0e10cSrcweir 												_nItemId,
1111*cdf0e10cSrcweir 												pSubMenuManager,
1112*cdf0e10cSrcweir 												aXDispatchRef );
1113*cdf0e10cSrcweir 	m_aMenuItemHandlerVector.push_back( pMenuItemHandler );
1114*cdf0e10cSrcweir }
1115*cdf0e10cSrcweir 
1116*cdf0e10cSrcweir sal_uInt16 MenuManager::FillItemCommand(::rtl::OUString& _rItemCommand,Menu* _pMenu,sal_uInt16 _nIndex) const
1117*cdf0e10cSrcweir {
1118*cdf0e10cSrcweir     sal_uInt16 nItemId = _pMenu->GetItemId( _nIndex );
1119*cdf0e10cSrcweir 
1120*cdf0e10cSrcweir 	_rItemCommand = _pMenu->GetItemCommand( nItemId );
1121*cdf0e10cSrcweir 	if ( !_rItemCommand.getLength() )
1122*cdf0e10cSrcweir 	{
1123*cdf0e10cSrcweir         const static ::rtl::OUString aSlotString( RTL_CONSTASCII_USTRINGPARAM( "slot:" ));
1124*cdf0e10cSrcweir 		_rItemCommand = aSlotString;
1125*cdf0e10cSrcweir 		_rItemCommand += ::rtl::OUString::valueOf( (sal_Int32)nItemId );
1126*cdf0e10cSrcweir 		_pMenu->SetItemCommand( nItemId, _rItemCommand );
1127*cdf0e10cSrcweir 	}
1128*cdf0e10cSrcweir     return nItemId;
1129*cdf0e10cSrcweir }
1130*cdf0e10cSrcweir void MenuManager::FillMenuImages(Reference< XFrame >& _xFrame,Menu* _pMenu,sal_Bool bIsHiContrast,sal_Bool bShowMenuImages)
1131*cdf0e10cSrcweir {
1132*cdf0e10cSrcweir     AddonsOptions		aAddonOptions;
1133*cdf0e10cSrcweir 
1134*cdf0e10cSrcweir 	for ( sal_uInt16 nPos = 0; nPos < _pMenu->GetItemCount(); nPos++ )
1135*cdf0e10cSrcweir 	{
1136*cdf0e10cSrcweir 		sal_uInt16 nId = _pMenu->GetItemId( nPos );
1137*cdf0e10cSrcweir 		if ( _pMenu->GetItemType( nPos ) != MENUITEM_SEPARATOR )
1138*cdf0e10cSrcweir 		{
1139*cdf0e10cSrcweir             bool bTmpShowMenuImages( bShowMenuImages );
1140*cdf0e10cSrcweir             MenuItemBits nBits =  _pMenu->GetItemBits( nId );
1141*cdf0e10cSrcweir             // overwrite the default?
1142*cdf0e10cSrcweir             if ( nBits )
1143*cdf0e10cSrcweir                 bTmpShowMenuImages = ( ( nBits & MIB_ICON ) == MIB_ICON );
1144*cdf0e10cSrcweir 
1145*cdf0e10cSrcweir             if ( bTmpShowMenuImages )
1146*cdf0e10cSrcweir 			{
1147*cdf0e10cSrcweir 				sal_Bool		bImageSet = sal_False;
1148*cdf0e10cSrcweir 				::rtl::OUString aImageId;
1149*cdf0e10cSrcweir 
1150*cdf0e10cSrcweir 				::framework::MenuConfiguration::Attributes* pMenuAttributes =
1151*cdf0e10cSrcweir 					(::framework::MenuConfiguration::Attributes*)_pMenu->GetUserValue( nId );
1152*cdf0e10cSrcweir 
1153*cdf0e10cSrcweir 				if ( pMenuAttributes )
1154*cdf0e10cSrcweir 					aImageId = pMenuAttributes->aImageId; // Retrieve image id from menu attributes
1155*cdf0e10cSrcweir 
1156*cdf0e10cSrcweir 				if ( aImageId.getLength() > 0 )
1157*cdf0e10cSrcweir 				{
1158*cdf0e10cSrcweir 					Image aImage = GetImageFromURL( _xFrame, aImageId, sal_False, bIsHiContrast );
1159*cdf0e10cSrcweir 					if ( !!aImage )
1160*cdf0e10cSrcweir 					{
1161*cdf0e10cSrcweir 						bImageSet = sal_True;
1162*cdf0e10cSrcweir 						_pMenu->SetItemImage( nId, aImage );
1163*cdf0e10cSrcweir 					}
1164*cdf0e10cSrcweir 				}
1165*cdf0e10cSrcweir 
1166*cdf0e10cSrcweir 				if ( !bImageSet )
1167*cdf0e10cSrcweir 				{
1168*cdf0e10cSrcweir 					rtl::OUString aMenuItemCommand = _pMenu->GetItemCommand( nId );
1169*cdf0e10cSrcweir 					Image aImage = GetImageFromURL( _xFrame, aMenuItemCommand, sal_False, bIsHiContrast );
1170*cdf0e10cSrcweir 					if ( !aImage )
1171*cdf0e10cSrcweir 						aImage = aAddonOptions.GetImageFromURL( aMenuItemCommand, sal_False, bIsHiContrast );
1172*cdf0e10cSrcweir 
1173*cdf0e10cSrcweir 					_pMenu->SetItemImage( nId, aImage );
1174*cdf0e10cSrcweir 				}
1175*cdf0e10cSrcweir 			}
1176*cdf0e10cSrcweir 			else
1177*cdf0e10cSrcweir 				_pMenu->SetItemImage( nId, Image() );
1178*cdf0e10cSrcweir 		}
1179*cdf0e10cSrcweir 	}
1180*cdf0e10cSrcweir }
1181*cdf0e10cSrcweir }
1182