1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef __FRAMEWORK_CLASSES_MENUMANAGER_HXX_
25 #define __FRAMEWORK_CLASSES_MENUMANAGER_HXX_
26 
27 /** Attention: stl headers must(!) be included at first. Otherwise it can make trouble
28                with solaris headers ...
29 */
30 #include <vector>
31 
32 //_________________________________________________________________________________________________________________
33 //	interface includes
34 //_________________________________________________________________________________________________________________
35 #include <com/sun/star/frame/XFrame.hpp>
36 #include <com/sun/star/frame/XDispatch.hpp>
37 #include <com/sun/star/frame/FeatureStateEvent.hpp>
38 #include <com/sun/star/beans/PropertyValue.hpp>
39 #include <com/sun/star/util/XURLTransformer.hpp>
40 
41 //_________________________________________________________________________________________________________________
42 //	other includes
43 //_________________________________________________________________________________________________________________
44 #include <rtl/ustring.hxx>
45 #include <vcl/menu.hxx>
46 #include <vcl/accel.hxx>
47 #include <cppuhelper/implbase1.hxx>
48 #include <threadhelp/threadhelpbase.hxx>
49 #include <macros/debug.hxx>
50 
51 // #110897#
52 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
53 
54 #define	REFERENCE										::com::sun::star::uno::Reference
55 #define	XFRAME											::com::sun::star::frame::XFrame
56 #define XDISPATCH										::com::sun::star::frame::XDispatch
57 #define XDISPATCHPROVIDER								::com::sun::star::frame::XDispatchProvider
58 #define XSTATUSLISTENER									::com::sun::star::frame::XStatusListener
59 #define XEVENTLISTENER									::com::sun::star::lang::XEventListener
60 #define FEATURSTATEEVENT								::com::sun::star::frame::FeatureStateEvent
61 #define RUNTIMEEXCEPTION								::com::sun::star::uno::RuntimeException
62 #define EVENTOBJECT										::com::sun::star::lang::EventObject
63 
64 namespace framework
65 {
66 
67 class BmkMenu;
68 class AddonMenu;
69 class AddonPopupMenu;
70 class MenuManager : public ThreadHelpBase			,
71 					public ::cppu::WeakImplHelper1< ::com::sun::star::frame::XStatusListener >
72 {
73 	public:
74 		// #110897#
75 		MenuManager(
76 			const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
77 			REFERENCE< XFRAME >& rFrame,
78 			Menu* pMenu,
79 			sal_Bool bDelete,
80 			sal_Bool bDeleteChildren );
81 #if 0
82 		MenuManager(
83 			const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
84 			REFERENCE< XFRAME >& rFrame,
85 			AddonMenu*			pAddonMenu,
86 			sal_Bool			bDelete,
87 			sal_Bool			bDeleteChildren );
88 #endif
89 
90 		virtual ~MenuManager();
91 
92 		// XStatusListener
93 		virtual void SAL_CALL statusChanged( const FEATURSTATEEVENT& Event ) throw ( RUNTIMEEXCEPTION );
94 
95 		// XEventListener
96 		virtual void SAL_CALL disposing( const EVENTOBJECT& Source ) throw ( RUNTIMEEXCEPTION );
97 
98 		DECL_LINK( Select, Menu * );
99 
GetMenu() const100 		Menu*	GetMenu() const { return m_pVCLMenu; }
101 
102 		void	RemoveListener();
103 
104 		// #110897#
105 		const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& getServiceFactory();
106 
107         static void UpdateSpecialWindowMenu( Menu* pMenu ,const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,IMutex& _rMutex);
108         static void FillMenuImages(::com::sun::star::uno::Reference< com::sun::star::frame::XFrame >& xFrame,Menu* _pMenu,sal_Bool bIsHiContrast,sal_Bool bShowMenuImages);
109 
110 	protected:
111 		DECL_LINK( Highlight, Menu * );
112 		DECL_LINK( Activate, Menu * );
113 		DECL_LINK( Deactivate, Menu * );
114 
115 	private:
116 		void UpdateSpecialFileMenu( Menu* pMenu );
117 		void UpdateSpecialWindowMenu( Menu* pMenu );
118         void ClearMenuDispatch(const EVENTOBJECT& Source = EVENTOBJECT(),bool _bRemoveOnly = true);
119         void SetHdl();
120         void AddMenu(PopupMenu* _pPopupMenu,const ::rtl::OUString& _sItemCommand,sal_uInt16 _nItemId,sal_Bool _bDelete,sal_Bool _bDeleteChildren);
121         sal_uInt16 FillItemCommand(::rtl::OUString& _rItemCommand,Menu* _pMenu,sal_uInt16 _nIndex) const;
122 
123 
124 		struct MenuItemHandler
125 		{
MenuItemHandlerframework::MenuManager::MenuItemHandler126 			MenuItemHandler( sal_uInt16 aItemId, MenuManager* pManager, REFERENCE< XDISPATCH >& rDispatch ) :
127 				nItemId( aItemId ), pSubMenuManager( pManager ), xMenuItemDispatch( rDispatch ) {}
128 
129 			sal_uInt16					nItemId;
130 			::rtl::OUString			aTargetFrame;
131 			::rtl::OUString			aMenuItemURL;
132 			::rtl::OUString			aFilter;
133 			::rtl::OUString			aPassword;
134 			::rtl::OUString			aTitle;
135 			MenuManager*			pSubMenuManager;
136 			REFERENCE< XDISPATCH >	xMenuItemDispatch;
137 		};
138 
139 		void			 CreatePicklistArguments(
140 							::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgsList,
141 							const MenuItemHandler* );
142 
143 		MenuItemHandler* GetMenuItemHandler( sal_uInt16 nItemId );
144 
145 		sal_Bool							m_bInitialized;
146 		sal_Bool							m_bDeleteMenu;
147 		sal_Bool							m_bDeleteChildren;
148 		sal_Bool							m_bActive;
149 		sal_Bool							m_bIsBookmarkMenu;
150 		sal_Bool							m_bWasHiContrast;
151 		sal_Bool							m_bShowMenuImages;
152 		::rtl::OUString						m_aMenuItemCommand;
153 		Menu*								m_pVCLMenu;
154 		REFERENCE< XFRAME >					m_xFrame;
155 		::std::vector< MenuItemHandler* >	m_aMenuItemHandlerVector;
156 
157 		// #110897#
158 		const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& mxServiceFactory;
159         ::com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer >             m_xURLTransformer;
160 };
161 
162 } // namespace
163 
164 #endif
165