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