Update ooo320-m1
[ooovba.git] / framework / inc / uielement / menubarmanager.hxx
blob0832686000f799ae8eb189f2090ab02ccb6e70b7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: menubarmanager.hxx,v $
10 * $Revision: 1.21 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef __FRAMEWORK_UIELEMENT_MENUBARMANAGER_HXX_
32 #define __FRAMEWORK_UIELEMENT_MENUBARMANAGER_HXX_
34 /** Attention: stl headers must(!) be included at first. Otherwhise it can make trouble
35 with solaris headers ...
37 #include <vector>
39 //_________________________________________________________________________________________________________________
40 // my own includes
41 //_________________________________________________________________________________________________________________
42 #include <threadhelp/threadhelpbase.hxx>
43 #include <macros/debug.hxx>
44 #include <stdtypes.h>
46 //_________________________________________________________________________________________________________________
47 // interface includes
48 //_________________________________________________________________________________________________________________
49 #include <com/sun/star/frame/XFrame.hpp>
50 #include <com/sun/star/frame/XDispatch.hpp>
51 #include <com/sun/star/frame/XDispatchProvider.hpp>
52 #include <com/sun/star/frame/FeatureStateEvent.hpp>
53 #include <com/sun/star/frame/XFrameActionListener.hpp>
54 #include <com/sun/star/beans/PropertyValue.hpp>
55 #include <com/sun/star/frame/XPopupMenuController.hpp>
56 #include <com/sun/star/awt/XSystemDependentMenuPeer.hpp>
57 #include <com/sun/star/container/XIndexAccess.hpp>
58 #include <com/sun/star/container/XNameAccess.hpp>
59 #include <com/sun/star/lang/XComponent.hpp>
60 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
61 #include <com/sun/star/frame/XUIControllerRegistration.hpp>
62 #include <com/sun/star/ui/XUIConfigurationListener.hpp>
63 #include <com/sun/star/ui/XImageManager.hpp>
64 #include <com/sun/star/ui/XAcceleratorConfiguration.hpp>
65 #include <com/sun/star/util/XURLTransformer.hpp>
66 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
68 //_________________________________________________________________________________________________________________
69 // other includes
70 //_________________________________________________________________________________________________________________
71 #include <rtl/ustring.hxx>
72 #include <vcl/menu.hxx>
73 #include <vcl/accel.hxx>
74 #include <vcl/timer.hxx>
75 #include <toolkit/awt/vclxmenu.hxx>
76 #include <cppuhelper/weak.hxx>
77 #include <cppuhelper/interfacecontainer.hxx>
78 #include <classes/addonsoptions.hxx>
80 namespace framework
83 struct PopupControllerEntry
85 ::com::sun::star::uno::WeakReference< ::com::sun::star::frame::XDispatchProvider > m_xDispatchProvider;
88 typedef std::hash_map< rtl::OUString, PopupControllerEntry, OUStringHashCode, ::std::equal_to< rtl::OUString > > PopupControllerCache;
90 class BmkMenu;
91 class AddonMenu;
92 class AddonPopupMenu;
93 class MenuBarManager : public com::sun::star::frame::XStatusListener ,
94 public com::sun::star::frame::XFrameActionListener ,
95 public com::sun::star::ui::XUIConfigurationListener ,
96 public com::sun::star::lang::XComponent ,
97 public com::sun::star::awt::XSystemDependentMenuPeer ,
98 public ThreadHelpBase ,
99 public ::cppu::OWeakObject
101 protected:
102 // #110897#
103 MenuBarManager(
104 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
105 const ::com::sun::star::uno::Reference< com::sun::star::frame::XFrame >& rFrame,
106 const ::com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer >& _xURLTransformer,
107 AddonMenu* pAddonMenu,
108 sal_Bool bDelete,
109 sal_Bool bDeleteChildren );
111 // #110897#
112 MenuBarManager(
113 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
114 const ::com::sun::star::uno::Reference< com::sun::star::frame::XFrame >& rFrame,
115 const ::com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer >& _xURLTransformer,
116 AddonPopupMenu* pAddonMenu,
117 sal_Bool bDelete,
118 sal_Bool bDeleteChildren );
120 public:
121 // #110897#
122 MenuBarManager(
123 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
124 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame,
125 const ::com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer >& _xURLTransformer,
126 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider >& rDispatchProvider,
127 const rtl::OUString& aModuleIdentifier,
128 Menu* pMenu,
129 sal_Bool bDelete,
130 sal_Bool bDeleteChildren );
132 // #110897#
133 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& getServiceFactory();
135 virtual ~MenuBarManager();
137 // XInterface
138 virtual void SAL_CALL acquire() throw();
139 virtual void SAL_CALL release() throw();
140 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw( ::com::sun::star::uno::RuntimeException );
142 // XComponent
143 virtual void SAL_CALL dispose() throw (::com::sun::star::uno::RuntimeException);
144 virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
145 virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
147 // XStatusListener
148 virtual void SAL_CALL statusChanged( const com::sun::star::frame::FeatureStateEvent& Event ) throw ( ::com::sun::star::uno::RuntimeException );
150 // XFrameActionListener
151 virtual void SAL_CALL frameAction( const com::sun::star::frame::FrameActionEvent& Action ) throw ( ::com::sun::star::uno::RuntimeException );
153 // XEventListener
154 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw ( ::com::sun::star::uno::RuntimeException );
156 // XUIConfigurationListener
157 virtual void SAL_CALL elementInserted( const ::com::sun::star::ui::ConfigurationEvent& Event ) throw (::com::sun::star::uno::RuntimeException);
158 virtual void SAL_CALL elementRemoved( const ::com::sun::star::ui::ConfigurationEvent& Event ) throw (::com::sun::star::uno::RuntimeException);
159 virtual void SAL_CALL elementReplaced( const ::com::sun::star::ui::ConfigurationEvent& Event ) throw (::com::sun::star::uno::RuntimeException);
161 // XSystemDependentMenuPeer
162 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);
164 DECL_LINK( Select, Menu * );
166 Menu* GetMenuBar() const { return m_pVCLMenu; }
168 // Configuration methods
169 static void FillMenuWithConfiguration( USHORT& nId, Menu* pMenu,
170 const ::rtl::OUString& rModuleIdentifier,
171 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& rItemContainer,
172 const ::com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer >& rTransformer );
173 static void FillMenu( USHORT& nId,
174 Menu* pMenu,
175 const ::rtl::OUString& rModuleIdentifier,
176 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& rItemContainer,
177 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider >& rDispatchProvider );
179 void FillMenuManager( Menu* pMenu,
180 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame,
181 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider >& rDispatchProvider,
182 const rtl::OUString& rModuleIdentifier,
183 sal_Bool bDelete,
184 sal_Bool bDeleteChildren );
185 void SetItemContainer( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& rItemContainer );
186 void GetPopupController( PopupControllerCache& rPopupController );
188 protected:
189 DECL_LINK( Highlight, Menu * );
190 DECL_LINK( Activate, Menu * );
191 DECL_LINK( Deactivate, Menu * );
192 DECL_LINK( AsyncSettingsHdl, Timer * );
194 void RemoveListener();
195 void RequestImages();
196 void RetrieveImageManagers();
197 static sal_Bool MustBeHidden( PopupMenu* pPopupMenu, const ::com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer >& rTransformer );
198 String RetrieveLabelFromCommand( const String& aCmdURL );
200 private:
204 void Destroy();
206 struct MenuItemHandler
208 MenuItemHandler( USHORT aItemId,
209 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener >& xManager,
210 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch >& rDispatch ) :
211 nItemId( aItemId ),
212 bCheckHide( sal_True ),
213 xSubMenuManager( xManager ),
214 xMenuItemDispatch( rDispatch ) {}
216 USHORT nItemId;
217 sal_Bool bCheckHide;
218 ::rtl::OUString aTargetFrame;
219 ::rtl::OUString aMenuItemURL;
220 ::rtl::OUString aFilter;
221 ::rtl::OUString aPassword;
222 ::rtl::OUString aTitle;
223 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > xSubMenuManager;
224 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > xMenuItemDispatch;
225 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XPopupMenuController > xPopupMenuController;
226 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPopupMenu > xPopupMenu;
227 KeyCode aKeyCode;
230 void RetrieveShortcuts( std::vector< MenuItemHandler* >& aMenuShortCuts );
231 void CreatePicklistArguments(
232 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgsList,
233 const MenuItemHandler* );
234 void CheckAndAddMenuExtension( Menu* pMenu );
235 static void impl_RetrieveShortcutsFromConfiguration( const ::com::sun::star::uno::Reference< ::com::sun::star::ui::XAcceleratorConfiguration >& rAccelCfg,
236 const ::com::sun::star::uno::Sequence< rtl::OUString >& rCommands,
237 std::vector< MenuItemHandler* >& aMenuShortCuts );
238 static void MergeAddonMenus( Menu* pMenuBar, const MergeMenuInstructionContainer&, const ::rtl::OUString& aModuleIdentifier );
240 MenuItemHandler* GetMenuItemHandler( USHORT nItemId );
241 sal_Bool CreatePopupMenuController( MenuItemHandler* pMenuItemHandler );
242 void AddMenu(MenuBarManager* pSubMenuManager,const ::rtl::OUString& _sItemCommand,USHORT _nItemId);
243 USHORT FillItemCommand(::rtl::OUString& _rItemCommand,Menu* _pMenu,USHORT _nIndex) const;
244 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);
245 void SetHdl();
247 sal_Bool m_bDisposed : 1,
248 m_bInitialized : 1,
249 m_bDeleteMenu : 1,
250 m_bDeleteChildren : 1,
251 m_bActive : 1,
252 m_bIsBookmarkMenu : 1,
253 m_bWasHiContrast : 1,
254 m_bShowMenuImages : 1;
255 sal_Bool m_bRetrieveImages : 1,
256 m_bAcceleratorCfg : 1;
257 sal_Bool m_bModuleIdentified;
258 ::rtl::OUString m_aMenuItemCommand;
259 ::rtl::OUString m_aModuleIdentifier;
260 Menu* m_pVCLMenu;
261 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > m_xFrame;
262 ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > m_xUICommandLabels;
263 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XUIControllerRegistration > m_xPopupMenuControllerRegistration;
264 ::std::vector< MenuItemHandler* > m_aMenuItemHandlerVector;
265 ::cppu::OMultiTypeInterfaceContainerHelper m_aListenerContainer; /// container for ALL Listener
266 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > m_xDispatchProvider;
267 ::com::sun::star::uno::Reference< ::com::sun::star::ui::XImageManager > m_xDocImageManager;
268 ::com::sun::star::uno::Reference< ::com::sun::star::ui::XImageManager > m_xModuleImageManager;
269 ::com::sun::star::uno::Reference< ::com::sun::star::ui::XAcceleratorConfiguration > m_xDocAcceleratorManager;
270 ::com::sun::star::uno::Reference< ::com::sun::star::ui::XAcceleratorConfiguration > m_xModuleAcceleratorManager;
271 ::com::sun::star::uno::Reference< ::com::sun::star::ui::XAcceleratorConfiguration > m_xGlobalAcceleratorManager;
272 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxServiceFactory;
273 ::com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer > m_xURLTransformer;
274 ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess > m_xDeferedItemContainer;
275 sal_Int16 m_nSymbolsStyle;
276 Timer m_aAsyncSettingsTimer;
279 } // namespace
281 #endif