1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef __FRAMEWORK_UIELEMENT_TOOLBARMANAGER_HXX_
29 #define __FRAMEWORK_UIELEMENT_TOOLBARMANAGER_HXX_
30 
31 //_________________________________________________________________________________________________________________
32 //	my own includes
33 //_________________________________________________________________________________________________________________
34 
35 #include <threadhelp/threadhelpbase.hxx>
36 #include <macros/generic.hxx>
37 #include <macros/xinterface.hxx>
38 #include <macros/xtypeprovider.hxx>
39 #include <stdtypes.h>
40 #include <uielement/commandinfo.hxx>
41 
42 //_________________________________________________________________________________________________________________
43 //	interface includes
44 //_________________________________________________________________________________________________________________
45 #include <com/sun/star/frame/XFrame.hpp>
46 #include <com/sun/star/frame/XStatusListener.hpp>
47 #include <com/sun/star/lang/XComponent.hpp>
48 #include <com/sun/star/container/XIndexAccess.hpp>
49 #include <com/sun/star/container/XNameAccess.hpp>
50 #include <com/sun/star/container/XIndexContainer.hpp>
51 #include <com/sun/star/frame/XModuleManager.hpp>
52 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
53 #include <com/sun/star/frame/XUIControllerRegistration.hpp>
54 #include <com/sun/star/ui/XImageManager.hpp>
55 #include <com/sun/star/ui/XUIConfigurationManager.hpp>
56 #include <com/sun/star/frame/XStatusListener.hpp>
57 #include <com/sun/star/frame/XSubToolbarController.hpp>
58 #include <com/sun/star/frame/XToolbarController.hpp>
59 #include <com/sun/star/ui/ItemStyle.hpp>
60 #include <com/sun/star/util/XURLTransformer.hpp>
61 #include <com/sun/star/ui/XAcceleratorConfiguration.hpp>
62 
63 //shizhoubo
64 #include <com/sun/star/frame/XToolbarController.hpp>
65 //end
66 //_________________________________________________________________________________________________________________
67 //	other includes
68 //_________________________________________________________________________________________________________________
69 #include <rtl/ustring.hxx>
70 #include <cppuhelper/weak.hxx>
71 #include <cppuhelper/interfacecontainer.hxx>
72 
73 #include <vcl/toolbox.hxx>
74 #include <vcl/accel.hxx>
75 
76 namespace com
77 {
78     namespace sun
79     {
80         namespace star
81         {
82             namespace frame
83             {
84                 class XLayoutManager;
85             }
86         }
87     }
88 }
89 
90 namespace framework
91 {
92 
93 class ToolBar;
94 class ToolBarManager : public ::com::sun::star::frame::XFrameActionListener         ,
95                        public ::com::sun::star::frame::XStatusListener              ,
96                        public ::com::sun::star::lang::XComponent                    ,
97                        public ::com::sun::star::lang::XTypeProvider                 ,
98                        public ::com::sun::star::ui::XUIConfigurationListener,
99 					   public ThreadHelpBase		                                ,
100 					   public ::cppu::OWeakObject
101 {
102     public:
103         ToolBarManager( const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rServicveManager,
104                         const com::sun::star::uno::Reference< com::sun::star::frame::XFrame >& rFrame,
105                         const rtl::OUString& rResourceName,
106                         ToolBar* pToolBar );
107         virtual ~ToolBarManager();
108 
109         //  XInterface, XTypeProvider, XServiceInfo
110         FWK_DECLARE_XINTERFACE
111         FWK_DECLARE_XTYPEPROVIDER
112 
113         ToolBox* GetToolBar() const;
114 
115         // XFrameActionListener
116 		virtual void SAL_CALL frameAction( const com::sun::star::frame::FrameActionEvent& Action ) throw ( ::com::sun::star::uno::RuntimeException );
117 
118         // XStatusListener
119 		virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event ) throw ( ::com::sun::star::uno::RuntimeException );
120 
121         // XEventListener
122 		virtual void SAL_CALL disposing( const com::sun::star::lang::EventObject& Source ) throw ( ::com::sun::star::uno::RuntimeException );
123 
124         // XUIConfigurationListener
125         virtual void SAL_CALL elementInserted( const ::com::sun::star::ui::ConfigurationEvent& Event ) throw (::com::sun::star::uno::RuntimeException);
126         virtual void SAL_CALL elementRemoved( const ::com::sun::star::ui::ConfigurationEvent& Event ) throw (::com::sun::star::uno::RuntimeException);
127         virtual void SAL_CALL elementReplaced( const ::com::sun::star::ui::ConfigurationEvent& Event ) throw (::com::sun::star::uno::RuntimeException);
128 
129         // XComponent
130         void SAL_CALL dispose() throw ( ::com::sun::star::uno::RuntimeException );
131         void SAL_CALL addEventListener( const com::sun::star::uno::Reference< XEventListener >& xListener ) throw( com::sun::star::uno::RuntimeException );
132         void SAL_CALL removeEventListener( const com::sun::star::uno::Reference< XEventListener >& xListener ) throw( com::sun::star::uno::RuntimeException );
133 
134         void CheckAndUpdateImages();
135         virtual void RefreshImages();
136         void FillToolbar( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& rToolBarData );
137         void notifyRegisteredControllers( const rtl::OUString& aUIElementName, const rtl::OUString& aCommand );
138         void Destroy();
139 
140         enum ExecuteCommand
141         {
142             EXEC_CMD_CLOSETOOLBAR,
143             EXEC_CMD_DOCKTOOLBAR,
144             EXEC_CMD_DOCKALLTOOLBARS,
145             EXEC_CMD_NONE,
146             EXEC_CMD_COUNT
147         };
148 
149         struct ExecuteInfo
150         {
151             rtl::OUString   aToolbarResName;
152             ExecuteCommand  nCmd;
153             ::com::sun::star::uno::Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
154             ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > xWindow;
155         };
156         struct ControllerParams
157         {
158             sal_Int16 nWidth;
159         };
160         typedef std::vector< ControllerParams > ControllerParamsVector;
161 
162     protected:
163 		//added for 33668 by shizhoubo : 2008:04
164 		DECL_LINK( Command, CommandEvent * );
165 		PopupMenu * GetToolBarCustomMeun(ToolBox* pToolBar);
166 		//end
167         DECL_LINK( Click, ToolBox * );
168         DECL_LINK( DropdownClick, ToolBox * );
169         DECL_LINK( DoubleClick, ToolBox * );
170         DECL_LINK( Select, ToolBox * );
171 		DECL_LINK( Highlight, ToolBox * );
172 		DECL_LINK( Activate, ToolBox * );
173 		DECL_LINK( Deactivate, ToolBox * );
174         DECL_LINK( StateChanged, StateChangedType* );
175         DECL_LINK( DataChanged, DataChangedEvent* );
176 
177         DECL_LINK( MenuButton, ToolBox * );
178         DECL_LINK( MenuSelect, Menu * );
179         DECL_LINK( MenuDeactivate, Menu * );
180         DECL_LINK( AsyncUpdateControllersHdl, Timer * );
181         DECL_STATIC_LINK( ToolBarManager, ExecuteHdl_Impl, ExecuteInfo* );
182 
183         virtual bool MenuItemAllowed( sal_uInt16 ) const;
184 
185         void RemoveControllers();
186         rtl::OUString RetrieveLabelFromCommand( const rtl::OUString& aCmdURL );
187         sal_Int32 RetrievePropertiesFromCommand( const rtl::OUString& aCmdURL );
188         ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > GetPropsForCommand( const ::rtl::OUString& rCmdURL );
189         void CreateControllers();
190         void UpdateControllers();
191 		//for update controller via Support Visiable by shizhoubo
192 		void UpdateController( ::com::sun::star::uno::Reference< ::com::sun::star::frame::XToolbarController > xController);
193 		//end
194         void AddFrameActionListener();
195         void AddImageOrientationListener();
196         void UpdateImageOrientation();
197         void ImplClearPopupMenu( ToolBox *pToolBar );
198         void RequestImages();
199         sal_uInt16 ConvertStyleToToolboxItemBits( sal_Int32 nStyle );
200         ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > GetModelFromFrame() const;
201         sal_Bool IsPluginMode() const;
202 		Image QueryAddonsImage( const ::rtl::OUString& aCommandURL, bool bBigImages, bool bHiContrast );
203         long HandleClick(void ( SAL_CALL ::com::sun::star::frame::XToolbarController::*_pClick )(  ));
204         void setToolBarImage(const Image& _aImage,const CommandToInfoMap::const_iterator& _pIter);
205         void impl_elementChanged(bool _bRemove,const ::com::sun::star::ui::ConfigurationEvent& Event );
206 
207 		static bool impl_RetrieveShortcutsFromConfiguration( const ::com::sun::star::uno::Reference< ::com::sun::star::ui::XAcceleratorConfiguration >& rAccelCfg, const rtl::OUString& rCommand, rtl::OUString& rShortCut );
208 		bool RetrieveShortcut( const rtl::OUString& rCommandURL, rtl::OUString& rShortCut );
209 
210     protected:
211         typedef ::std::hash_map< sal_uInt16, ::com::sun::star::uno::Reference< com::sun::star::frame::XStatusListener > > ToolBarControllerMap;
212         typedef ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::frame::XSubToolbarController > > SubToolBarControllerVector;
213         typedef BaseHash< SubToolBarControllerVector >                                                              SubToolBarToSubToolBarControllerMap;
214 
215         typedef ::std::hash_map< sal_uInt16, ::com::sun::star::uno::Reference< com::sun::star::container::XIndexAccess > > MenuDescriptionMap;
216         sal_Bool                                                                               m_bDisposed : 1,
217                                                                                                m_bIsHiContrast : 1,
218                                                                                                m_bSmallSymbols : 1,
219                                                                                                m_bModuleIdentified : 1,
220                                                                                                m_bAddedToTaskPaneList : 1,
221                                                                                                m_bVerticalTextEnabled : 1,
222                                                                                                m_bFrameActionRegistered : 1,
223                                                                                                m_bUpdateControllers : 1;
224         sal_Bool                                                                               m_bImageOrientationRegistered : 1,
225                                                                                                m_bImageMirrored : 1,
226                                                                                                m_bCanBeCustomized : 1;
227         long                                                                                   m_lImageRotation;
228         ToolBar*                                                                               m_pToolBar;
229         rtl::OUString                                                                          m_aModuleIdentifier;
230         rtl::OUString                                                                          m_aResourceName;
231         com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer >              m_xURLTransformer;
232         com::sun::star::uno::Reference< com::sun::star::frame::XFrame >                        m_xFrame;
233         com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >               m_xUICommandLabels;
234         ToolBarControllerMap                                                                   m_aControllerMap;
235         ::cppu::OMultiTypeInterfaceContainerHelper                                             m_aListenerContainer;   /// container for ALL Listener
236         ::com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >         m_xServiceManager;
237         ::com::sun::star::uno::Reference< ::com::sun::star::frame::XUIControllerRegistration > m_xToolbarControllerRegistration;
238         ::com::sun::star::uno::Reference< ::com::sun::star::ui::XImageManager >                m_xModuleImageManager;
239         ::com::sun::star::uno::Reference< ::com::sun::star::ui::XImageManager >                m_xDocImageManager;
240         ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >                 m_xImageOrientationListener;
241         ::com::sun::star::uno::Reference< ::com::sun::star::ui::XUIConfigurationManager >                m_xUICfgMgr;
242         ::com::sun::star::uno::Reference< ::com::sun::star::ui::XUIConfigurationManager >                m_xDocUICfgMgr;
243 
244         CommandToInfoMap                                                                       m_aCommandMap;
245         SubToolBarToSubToolBarControllerMap                                                    m_aSubToolBarControllerMap;
246         Timer				                                                                   m_aAsyncUpdateControllersTimer;
247         sal_Int16                                                                              m_nSymbolsStyle;
248         MenuDescriptionMap m_aMenuMap;
249         sal_Bool																			   m_bAcceleratorCfg;
250         ::com::sun::star::uno::Reference< ::com::sun::star::ui::XAcceleratorConfiguration >    m_xDocAcceleratorManager;
251         ::com::sun::star::uno::Reference< ::com::sun::star::ui::XAcceleratorConfiguration >    m_xModuleAcceleratorManager;
252         ::com::sun::star::uno::Reference< ::com::sun::star::ui::XAcceleratorConfiguration >    m_xGlobalAcceleratorManager;
253 };
254 
255 }
256 
257 #endif // __FRAMEWORK_UIELEMENT_TOOLBARMANAGER_HXX_
258