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