1*f8e07b45SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f8e07b45SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f8e07b45SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f8e07b45SAndrew Rist  * distributed with this work for additional information
6*f8e07b45SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f8e07b45SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f8e07b45SAndrew Rist  * "License"); you may not use this file except in compliance
9*f8e07b45SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*f8e07b45SAndrew Rist  *
11*f8e07b45SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*f8e07b45SAndrew Rist  *
13*f8e07b45SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f8e07b45SAndrew Rist  * software distributed under the License is distributed on an
15*f8e07b45SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f8e07b45SAndrew Rist  * KIND, either express or implied.  See the License for the
17*f8e07b45SAndrew Rist  * specific language governing permissions and limitations
18*f8e07b45SAndrew Rist  * under the License.
19*f8e07b45SAndrew Rist  *
20*f8e07b45SAndrew Rist  *************************************************************/
21*f8e07b45SAndrew Rist 
22*f8e07b45SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef __FRAMEWORK_UIELEMENT_MENUBARMANAGER_HXX_
25cdf0e10cSrcweir #define __FRAMEWORK_UIELEMENT_MENUBARMANAGER_HXX_
26cdf0e10cSrcweir 
27cdf0e10cSrcweir /** Attention: stl headers must(!) be included at first. Otherwhise it can make trouble
28cdf0e10cSrcweir                with solaris headers ...
29cdf0e10cSrcweir */
30cdf0e10cSrcweir #include <vector>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir //_________________________________________________________________________________________________________________
33cdf0e10cSrcweir //	my own includes
34cdf0e10cSrcweir //_________________________________________________________________________________________________________________
35cdf0e10cSrcweir #include <threadhelp/threadhelpbase.hxx>
36cdf0e10cSrcweir #include <macros/debug.hxx>
37cdf0e10cSrcweir #include <stdtypes.h>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir //_________________________________________________________________________________________________________________
40cdf0e10cSrcweir //	interface includes
41cdf0e10cSrcweir //_________________________________________________________________________________________________________________
42cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp>
43cdf0e10cSrcweir #include <com/sun/star/frame/XDispatch.hpp>
44cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp>
45cdf0e10cSrcweir #include <com/sun/star/frame/FeatureStateEvent.hpp>
46cdf0e10cSrcweir #include <com/sun/star/frame/XFrameActionListener.hpp>
47cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
48cdf0e10cSrcweir #include <com/sun/star/frame/XPopupMenuController.hpp>
49cdf0e10cSrcweir #include <com/sun/star/awt/XSystemDependentMenuPeer.hpp>
50cdf0e10cSrcweir #include <com/sun/star/container/XIndexAccess.hpp>
51cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
52cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
53cdf0e10cSrcweir #include <com/sun/star/lang/XMultiComponentFactory.hpp>
54cdf0e10cSrcweir #include <com/sun/star/frame/XUIControllerRegistration.hpp>
55cdf0e10cSrcweir #include <com/sun/star/ui/XUIConfigurationListener.hpp>
56cdf0e10cSrcweir #include <com/sun/star/ui/XImageManager.hpp>
57cdf0e10cSrcweir #include <com/sun/star/ui/XAcceleratorConfiguration.hpp>
58cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp>
59cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
60cdf0e10cSrcweir 
61cdf0e10cSrcweir //_________________________________________________________________________________________________________________
62cdf0e10cSrcweir //	other includes
63cdf0e10cSrcweir //_________________________________________________________________________________________________________________
64cdf0e10cSrcweir #include <rtl/ustring.hxx>
65cdf0e10cSrcweir #include <vcl/menu.hxx>
66cdf0e10cSrcweir #include <vcl/accel.hxx>
67cdf0e10cSrcweir #include <vcl/timer.hxx>
68cdf0e10cSrcweir #include <toolkit/awt/vclxmenu.hxx>
69cdf0e10cSrcweir #include <cppuhelper/weak.hxx>
70cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.hxx>
71cdf0e10cSrcweir #include <framework/addonsoptions.hxx>
72cdf0e10cSrcweir 
73cdf0e10cSrcweir namespace framework
74cdf0e10cSrcweir {
75cdf0e10cSrcweir 
76cdf0e10cSrcweir struct PopupControllerEntry
77cdf0e10cSrcweir {
78cdf0e10cSrcweir     ::com::sun::star::uno::WeakReference< ::com::sun::star::frame::XDispatchProvider > m_xDispatchProvider;
79cdf0e10cSrcweir };
80cdf0e10cSrcweir 
81cdf0e10cSrcweir typedef std::hash_map< rtl::OUString, PopupControllerEntry, OUStringHashCode, ::std::equal_to< rtl::OUString > > PopupControllerCache;
82cdf0e10cSrcweir 
83cdf0e10cSrcweir class BmkMenu;
84cdf0e10cSrcweir class AddonMenu;
85cdf0e10cSrcweir class AddonPopupMenu;
86cdf0e10cSrcweir class MenuBarManager : public com::sun::star::frame::XStatusListener                ,
87cdf0e10cSrcweir                        public com::sun::star::frame::XFrameActionListener           ,
88cdf0e10cSrcweir                        public com::sun::star::ui::XUIConfigurationListener          ,
89cdf0e10cSrcweir                        public com::sun::star::lang::XComponent                      ,
90cdf0e10cSrcweir                        public com::sun::star::awt::XSystemDependentMenuPeer         ,
91cdf0e10cSrcweir 					   public ThreadHelpBase		                                ,
92cdf0e10cSrcweir 					   public ::cppu::OWeakObject
93cdf0e10cSrcweir {
94cdf0e10cSrcweir     protected:
95cdf0e10cSrcweir 		// #110897#
96cdf0e10cSrcweir 		MenuBarManager(
97cdf0e10cSrcweir 			const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
98cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< com::sun::star::frame::XFrame >& rFrame,
99cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer >& _xURLTransformer,
100cdf0e10cSrcweir 			AddonMenu*			pAddonMenu,
101cdf0e10cSrcweir 			sal_Bool			bDelete,
102cdf0e10cSrcweir 			sal_Bool			bDeleteChildren );
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 		// #110897#
105cdf0e10cSrcweir 		MenuBarManager(
106cdf0e10cSrcweir 			const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
107cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< com::sun::star::frame::XFrame >& rFrame,
108cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer >& _xURLTransformer,
109cdf0e10cSrcweir 			AddonPopupMenu*	    pAddonMenu,
110cdf0e10cSrcweir 			sal_Bool			bDelete,
111cdf0e10cSrcweir 			sal_Bool			bDeleteChildren );
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 	public:
114cdf0e10cSrcweir 		// #110897#
115cdf0e10cSrcweir 		MenuBarManager(
116cdf0e10cSrcweir 			const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
117cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame,
118cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer >& _xURLTransformer,
119cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider >& rDispatchProvider,
120cdf0e10cSrcweir             const rtl::OUString& aModuleIdentifier,
121cdf0e10cSrcweir 			Menu* pMenu,
122cdf0e10cSrcweir 			sal_Bool bDelete,
123cdf0e10cSrcweir 			sal_Bool bDeleteChildren );
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 		// #110897#
126cdf0e10cSrcweir 		const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& getServiceFactory();
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 		virtual ~MenuBarManager();
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 		// XInterface
131cdf0e10cSrcweir 		virtual void SAL_CALL acquire() throw();
132cdf0e10cSrcweir 		virtual void SAL_CALL release() throw();
133cdf0e10cSrcweir 		virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw( ::com::sun::star::uno::RuntimeException );
134cdf0e10cSrcweir 
135cdf0e10cSrcweir         // XComponent
136cdf0e10cSrcweir         virtual void SAL_CALL dispose() throw (::com::sun::star::uno::RuntimeException);
137cdf0e10cSrcweir         virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
138cdf0e10cSrcweir         virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 		// XStatusListener
141cdf0e10cSrcweir 		virtual void SAL_CALL statusChanged( const com::sun::star::frame::FeatureStateEvent& Event ) throw ( ::com::sun::star::uno::RuntimeException );
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 		// XFrameActionListener
144cdf0e10cSrcweir 		virtual void SAL_CALL frameAction( const com::sun::star::frame::FrameActionEvent& Action ) throw ( ::com::sun::star::uno::RuntimeException );
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 		// XEventListener
147cdf0e10cSrcweir 		virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw ( ::com::sun::star::uno::RuntimeException );
148cdf0e10cSrcweir 
149cdf0e10cSrcweir         // XUIConfigurationListener
150cdf0e10cSrcweir         virtual void SAL_CALL elementInserted( const ::com::sun::star::ui::ConfigurationEvent& Event ) throw (::com::sun::star::uno::RuntimeException);
151cdf0e10cSrcweir         virtual void SAL_CALL elementRemoved( const ::com::sun::star::ui::ConfigurationEvent& Event ) throw (::com::sun::star::uno::RuntimeException);
152cdf0e10cSrcweir         virtual void SAL_CALL elementReplaced( const ::com::sun::star::ui::ConfigurationEvent& Event ) throw (::com::sun::star::uno::RuntimeException);
153cdf0e10cSrcweir 
154cdf0e10cSrcweir         // XSystemDependentMenuPeer
155cdf0e10cSrcweir         virtual ::com::sun::star::uno::Any SAL_CALL getMenuHandle( const ::com::sun::star::uno::Sequence< sal_Int8 >& ProcessId, sal_Int16 SystemType ) throw (::com::sun::star::uno::RuntimeException);
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 		DECL_LINK( Select, Menu * );
158cdf0e10cSrcweir 
159cdf0e10cSrcweir 		Menu*	GetMenuBar() const { return m_pVCLMenu; }
160cdf0e10cSrcweir 
161cdf0e10cSrcweir         // Configuration methods
162cdf0e10cSrcweir         static void FillMenuWithConfiguration( sal_uInt16& nId, Menu* pMenu,
163cdf0e10cSrcweir                                                const ::rtl::OUString& rModuleIdentifier,
164cdf0e10cSrcweir                                                const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& rItemContainer,
165cdf0e10cSrcweir                                                const ::com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer >& rTransformer );
166cdf0e10cSrcweir         static void FillMenu( sal_uInt16& nId,
167cdf0e10cSrcweir                               Menu* pMenu,
168cdf0e10cSrcweir                               const ::rtl::OUString& rModuleIdentifier,
169cdf0e10cSrcweir                               const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& rItemContainer,
170cdf0e10cSrcweir                               const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider >& rDispatchProvider );
171cdf0e10cSrcweir 
172cdf0e10cSrcweir         void FillMenuManager( Menu* pMenu,
173cdf0e10cSrcweir                               const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame,
174cdf0e10cSrcweir                               const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider >& rDispatchProvider,
175cdf0e10cSrcweir                               const rtl::OUString& rModuleIdentifier,
176cdf0e10cSrcweir                               sal_Bool bDelete,
177cdf0e10cSrcweir                               sal_Bool bDeleteChildren );
178cdf0e10cSrcweir 		void SetItemContainer( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& rItemContainer );
179cdf0e10cSrcweir         void GetPopupController( PopupControllerCache& rPopupController );
180cdf0e10cSrcweir 
181cdf0e10cSrcweir 	protected:
182cdf0e10cSrcweir         DECL_LINK( Highlight, Menu * );
183cdf0e10cSrcweir 		DECL_LINK( Activate, Menu * );
184cdf0e10cSrcweir 		DECL_LINK( Deactivate, Menu * );
185cdf0e10cSrcweir         DECL_LINK( AsyncSettingsHdl, Timer * );
186cdf0e10cSrcweir 
187cdf0e10cSrcweir 		void RemoveListener();
188cdf0e10cSrcweir         void RequestImages();
189cdf0e10cSrcweir         void RetrieveImageManagers();
190cdf0e10cSrcweir         static sal_Bool MustBeHidden( PopupMenu* pPopupMenu, const ::com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer >& rTransformer );
191cdf0e10cSrcweir         String RetrieveLabelFromCommand( const String& aCmdURL );
192cdf0e10cSrcweir 
193cdf0e10cSrcweir 	private:
194cdf0e10cSrcweir 
195cdf0e10cSrcweir 
196cdf0e10cSrcweir 
197cdf0e10cSrcweir         void Destroy();
198cdf0e10cSrcweir 
199cdf0e10cSrcweir 		struct MenuItemHandler
200cdf0e10cSrcweir 		{
201cdf0e10cSrcweir 			MenuItemHandler( sal_uInt16             aItemId,
202cdf0e10cSrcweir                              ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener >& xManager,
203cdf0e10cSrcweir                              ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch >& rDispatch ) :
204cdf0e10cSrcweir                              nItemId( aItemId ),
205cdf0e10cSrcweir                              bCheckHide( sal_True ),
206cdf0e10cSrcweir                              xSubMenuManager( xManager ),
207cdf0e10cSrcweir                              xMenuItemDispatch( rDispatch ) {}
208cdf0e10cSrcweir 
209cdf0e10cSrcweir 			sal_uInt16					                                                                    nItemId;
210cdf0e10cSrcweir             sal_Bool                                                                                    bCheckHide;
211cdf0e10cSrcweir 			::rtl::OUString			                                                                    aTargetFrame;
212cdf0e10cSrcweir 			::rtl::OUString			                                                                    aMenuItemURL;
213cdf0e10cSrcweir 			::rtl::OUString			                                                                    aFilter;
214cdf0e10cSrcweir 			::rtl::OUString			                                                                    aPassword;
215cdf0e10cSrcweir 			::rtl::OUString			                                                                    aTitle;
216cdf0e10cSrcweir 			::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener >                xSubMenuManager;
217cdf0e10cSrcweir 			::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch >                      xMenuItemDispatch;
218cdf0e10cSrcweir 			::com::sun::star::uno::Reference< ::com::sun::star::frame::XPopupMenuController >           xPopupMenuController;
219cdf0e10cSrcweir 			::com::sun::star::uno::Reference< ::com::sun::star::awt::XPopupMenu >                       xPopupMenu;
220cdf0e10cSrcweir             KeyCode                                                                                     aKeyCode;
221cdf0e10cSrcweir 		};
222cdf0e10cSrcweir 
223cdf0e10cSrcweir         void             RetrieveShortcuts( std::vector< MenuItemHandler* >& aMenuShortCuts );
224cdf0e10cSrcweir         void			 CreatePicklistArguments(
225cdf0e10cSrcweir 							::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgsList,
226cdf0e10cSrcweir 							const MenuItemHandler* );
227cdf0e10cSrcweir         void             CheckAndAddMenuExtension( Menu* pMenu );
228cdf0e10cSrcweir         static void      impl_RetrieveShortcutsFromConfiguration( const ::com::sun::star::uno::Reference< ::com::sun::star::ui::XAcceleratorConfiguration >& rAccelCfg,
229cdf0e10cSrcweir                                                                   const ::com::sun::star::uno::Sequence< rtl::OUString >& rCommands,
230cdf0e10cSrcweir                                                                   std::vector< MenuItemHandler* >& aMenuShortCuts );
231cdf0e10cSrcweir         static void      MergeAddonMenus( Menu* pMenuBar, const MergeMenuInstructionContainer&, const ::rtl::OUString& aModuleIdentifier );
232cdf0e10cSrcweir 
233cdf0e10cSrcweir         MenuItemHandler* GetMenuItemHandler( sal_uInt16 nItemId );
234cdf0e10cSrcweir         sal_Bool         CreatePopupMenuController( MenuItemHandler* pMenuItemHandler );
235cdf0e10cSrcweir         void             AddMenu(MenuBarManager* pSubMenuManager,const ::rtl::OUString& _sItemCommand,sal_uInt16 _nItemId);
236cdf0e10cSrcweir         sal_uInt16           FillItemCommand(::rtl::OUString& _rItemCommand,Menu* _pMenu,sal_uInt16 _nIndex) const;
237cdf0e10cSrcweir         void             Init(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame,AddonMenu* pAddonMenu,sal_Bool bDelete,sal_Bool bDeleteChildren,bool _bHandlePopUp = false);
238cdf0e10cSrcweir         void             SetHdl();
239cdf0e10cSrcweir 
240cdf0e10cSrcweir         sal_Bool                                                                               m_bDisposed : 1,
241cdf0e10cSrcweir 									                                                           m_bInitialized : 1,
242cdf0e10cSrcweir 									                                                           m_bDeleteMenu : 1,
243cdf0e10cSrcweir 									                                                           m_bDeleteChildren : 1,
244cdf0e10cSrcweir 									                                                           m_bActive : 1,
245cdf0e10cSrcweir 									                                                           m_bIsBookmarkMenu : 1,
246cdf0e10cSrcweir 									                                                           m_bWasHiContrast : 1,
247cdf0e10cSrcweir 									                                                           m_bShowMenuImages : 1;
248cdf0e10cSrcweir         sal_Bool                                                                               m_bRetrieveImages : 1,
249cdf0e10cSrcweir                                                                                                m_bAcceleratorCfg : 1;
250cdf0e10cSrcweir         sal_Bool                                                                               m_bModuleIdentified;
251cdf0e10cSrcweir         ::rtl::OUString						                                                   m_aMenuItemCommand;
252cdf0e10cSrcweir         ::rtl::OUString                                                                        m_aModuleIdentifier;
253cdf0e10cSrcweir         Menu*								                                                   m_pVCLMenu;
254cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >                    m_xFrame;
255cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >           m_xUICommandLabels;
256cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::frame::XUIControllerRegistration > m_xPopupMenuControllerRegistration;
257cdf0e10cSrcweir         ::std::vector< MenuItemHandler* >	                                                   m_aMenuItemHandlerVector;
258cdf0e10cSrcweir         ::cppu::OMultiTypeInterfaceContainerHelper                                             m_aListenerContainer;   /// container for ALL Listener
259cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider >         m_xDispatchProvider;
260cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::ui::XImageManager >                m_xDocImageManager;
261cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::ui::XImageManager >                m_xModuleImageManager;
262cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::ui::XAcceleratorConfiguration >    m_xDocAcceleratorManager;
263cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::ui::XAcceleratorConfiguration >    m_xModuleAcceleratorManager;
264cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::ui::XAcceleratorConfiguration >    m_xGlobalAcceleratorManager;
265cdf0e10cSrcweir 		::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >       mxServiceFactory;
266cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer >            m_xURLTransformer;
267cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >          m_xDeferedItemContainer;
268cdf0e10cSrcweir 		sal_Int16                                                                              m_nSymbolsStyle;
269cdf0e10cSrcweir         Timer                                                                                  m_aAsyncSettingsTimer;
270cdf0e10cSrcweir };
271cdf0e10cSrcweir 
272cdf0e10cSrcweir } // namespace
273cdf0e10cSrcweir 
274cdf0e10cSrcweir #endif
275