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