Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef INCLUDED_FRAMEWORK_INC_UIELEMENT_TOOLBARMANAGER_HXX
21 : #define INCLUDED_FRAMEWORK_INC_UIELEMENT_TOOLBARMANAGER_HXX
22 :
23 : #include <macros/generic.hxx>
24 : #include <macros/xinterface.hxx>
25 : #include <macros/xtypeprovider.hxx>
26 : #include <stdtypes.h>
27 : #include <uielement/commandinfo.hxx>
28 :
29 : #include <com/sun/star/container/XIndexAccess.hpp>
30 : #include <com/sun/star/container/XNameAccess.hpp>
31 : #include <com/sun/star/container/XIndexContainer.hpp>
32 : #include <com/sun/star/frame/XFrame.hpp>
33 : #include <com/sun/star/frame/XStatusListener.hpp>
34 : #include <com/sun/star/frame/XModuleManager.hpp>
35 : #include <com/sun/star/frame/XUIControllerFactory.hpp>
36 : #include <com/sun/star/frame/XSubToolbarController.hpp>
37 : #include <com/sun/star/frame/XLayoutManager.hpp>
38 : #include <com/sun/star/frame/XToolbarController.hpp>
39 : #include <com/sun/star/lang/XComponent.hpp>
40 : #include <com/sun/star/ui/XImageManager.hpp>
41 : #include <com/sun/star/ui/XUIConfigurationManager.hpp>
42 : #include <com/sun/star/ui/ItemStyle.hpp>
43 : #include <com/sun/star/ui/XAcceleratorConfiguration.hpp>
44 : #include <com/sun/star/uno/XComponentContext.hpp>
45 : #include <com/sun/star/util/XURLTransformer.hpp>
46 :
47 : #include <rtl/ustring.hxx>
48 : #include <cppuhelper/implbase4.hxx>
49 : #include <cppuhelper/interfacecontainer.hxx>
50 :
51 : #include <tools/link.hxx>
52 : #include <vcl/window.hxx>
53 : #include <vcl/timer.hxx>
54 :
55 : class PopupMenu;
56 : class ToolBox;
57 :
58 : namespace framework
59 : {
60 :
61 : typedef ::cppu::WeakImplHelper4<
62 : ::com::sun::star::frame::XFrameActionListener,
63 : ::com::sun::star::frame::XStatusListener,
64 : ::com::sun::star::lang::XComponent,
65 : ::com::sun::star::ui::XUIConfigurationListener
66 : > ToolbarManager_Base;
67 :
68 : class ToolBarManager : public ToolbarManager_Base
69 : {
70 : public:
71 : ToolBarManager( const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >& rxContext,
72 : const com::sun::star::uno::Reference< com::sun::star::frame::XFrame >& rFrame,
73 : const OUString& rResourceName,
74 : ToolBox* pToolBar );
75 : virtual ~ToolBarManager();
76 :
77 : ToolBox* GetToolBar() const;
78 :
79 : // XFrameActionListener
80 : virtual void SAL_CALL frameAction( const com::sun::star::frame::FrameActionEvent& Action ) throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
81 :
82 : // XStatusListener
83 : virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event ) throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
84 :
85 : // XEventListener
86 : virtual void SAL_CALL disposing( const com::sun::star::lang::EventObject& Source ) throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
87 :
88 : // XUIConfigurationListener
89 : virtual void SAL_CALL elementInserted( const ::com::sun::star::ui::ConfigurationEvent& Event ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
90 : virtual void SAL_CALL elementRemoved( const ::com::sun::star::ui::ConfigurationEvent& Event ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
91 : virtual void SAL_CALL elementReplaced( const ::com::sun::star::ui::ConfigurationEvent& Event ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
92 :
93 : // XComponent
94 : void SAL_CALL dispose() throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
95 : void SAL_CALL addEventListener( const com::sun::star::uno::Reference< XEventListener >& xListener ) throw( com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
96 : void SAL_CALL removeEventListener( const com::sun::star::uno::Reference< XEventListener >& xListener ) throw( com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
97 :
98 : void CheckAndUpdateImages();
99 : virtual void RefreshImages();
100 : void FillToolbar( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& rToolBarData );
101 : void notifyRegisteredControllers( const OUString& aUIElementName, const OUString& aCommand );
102 : void Destroy();
103 :
104 : enum ExecuteCommand
105 : {
106 : EXEC_CMD_CLOSETOOLBAR,
107 : EXEC_CMD_DOCKTOOLBAR,
108 : EXEC_CMD_DOCKALLTOOLBARS,
109 : EXEC_CMD_NONE,
110 : EXEC_CMD_COUNT
111 : };
112 :
113 0 : struct ExecuteInfo
114 : {
115 : OUString aToolbarResName;
116 : ExecuteCommand nCmd;
117 : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
118 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > xWindow;
119 : };
120 : struct ControllerParams
121 : {
122 : sal_Int16 nWidth;
123 : };
124 : typedef std::vector< ControllerParams > ControllerParamsVector;
125 :
126 : protected:
127 : DECL_LINK( Command, CommandEvent * );
128 : PopupMenu * GetToolBarCustomMenu(ToolBox* pToolBar);
129 : DECL_LINK(Click, void *);
130 : DECL_LINK(DropdownClick, void *);
131 : DECL_LINK(DoubleClick, void *);
132 : DECL_LINK(Select, void *);
133 : DECL_LINK(Activate, void *);
134 : DECL_LINK(Deactivate, void *);
135 : DECL_LINK( StateChanged, StateChangedType* );
136 : DECL_LINK( DataChanged, DataChangedEvent* );
137 : DECL_LINK( MiscOptionsChanged, void* );
138 :
139 : DECL_LINK( MenuButton, ToolBox * );
140 : DECL_LINK( MenuSelect, Menu * );
141 : DECL_LINK( MenuDeactivate, Menu * );
142 : DECL_LINK(AsyncUpdateControllersHdl, void *);
143 : DECL_STATIC_LINK( ToolBarManager, ExecuteHdl_Impl, ExecuteInfo* );
144 :
145 : virtual bool MenuItemAllowed( sal_uInt16 ) const;
146 :
147 : void RemoveControllers();
148 : OUString RetrieveLabelFromCommand( const OUString& aCmdURL );
149 : sal_Int32 RetrievePropertiesFromCommand( const OUString& aCmdURL );
150 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > GetPropsForCommand( const OUString& rCmdURL );
151 : void CreateControllers();
152 : void UpdateControllers();
153 : //for update controller via Support Visiable
154 : void UpdateController( ::com::sun::star::uno::Reference< ::com::sun::star::frame::XToolbarController > xController);
155 : //end
156 : void AddFrameActionListener();
157 : void AddImageOrientationListener();
158 : void UpdateImageOrientation();
159 : void ImplClearPopupMenu( ToolBox *pToolBar );
160 : void RequestImages();
161 : sal_uInt16 ConvertStyleToToolboxItemBits( sal_Int32 nStyle );
162 : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > GetModelFromFrame() const;
163 : bool IsPluginMode() const;
164 : Image QueryAddonsImage( const OUString& aCommandURL, bool bBigImages );
165 : long HandleClick(void ( SAL_CALL ::com::sun::star::frame::XToolbarController::*_pClick )( ));
166 : void setToolBarImage(const Image& _aImage,const CommandToInfoMap::const_iterator& _pIter);
167 : void impl_elementChanged(bool _bRemove,const ::com::sun::star::ui::ConfigurationEvent& Event );
168 :
169 : static bool impl_RetrieveShortcutsFromConfiguration( const ::com::sun::star::uno::Reference< ::com::sun::star::ui::XAcceleratorConfiguration >& rAccelCfg, const OUString& rCommand, OUString& rShortCut );
170 : bool RetrieveShortcut( const OUString& rCommandURL, OUString& rShortCut );
171 :
172 : protected:
173 : typedef ::boost::unordered_map< sal_uInt16, ::com::sun::star::uno::Reference< com::sun::star::frame::XStatusListener > > ToolBarControllerMap;
174 : typedef ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::frame::XSubToolbarController > > SubToolBarControllerVector;
175 : typedef BaseHash< SubToolBarControllerVector > SubToolBarToSubToolBarControllerMap;
176 :
177 : typedef ::boost::unordered_map< sal_uInt16, ::com::sun::star::uno::Reference< com::sun::star::container::XIndexAccess > > MenuDescriptionMap;
178 :
179 : bool m_bDisposed : 1,
180 : m_bSmallSymbols : 1,
181 : m_bModuleIdentified : 1,
182 : m_bAddedToTaskPaneList : 1,
183 : m_bFrameActionRegistered : 1,
184 : m_bUpdateControllers : 1,
185 : m_bImageOrientationRegistered : 1,
186 : m_bImageMirrored : 1;
187 :
188 : long m_lImageRotation;
189 :
190 : ToolBox* m_pToolBar;
191 :
192 : OUString m_aModuleIdentifier;
193 : OUString m_aResourceName;
194 :
195 : com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer > m_xURLTransformer;
196 : com::sun::star::uno::Reference< com::sun::star::frame::XFrame > m_xFrame;
197 : com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > m_xUICommandLabels;
198 : ToolBarControllerMap m_aControllerMap;
199 : osl::Mutex m_mutex;
200 : ::cppu::OMultiTypeInterfaceContainerHelper m_aListenerContainer; /// container for ALL Listener
201 : ::com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > m_xContext;
202 : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XUIControllerFactory > m_xToolbarControllerFactory;
203 : ::com::sun::star::uno::Reference< ::com::sun::star::ui::XImageManager > m_xModuleImageManager;
204 : ::com::sun::star::uno::Reference< ::com::sun::star::ui::XImageManager > m_xDocImageManager;
205 : ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > m_xImageOrientationListener;
206 : ::com::sun::star::uno::Reference< ::com::sun::star::ui::XUIConfigurationManager > m_xUICfgMgr;
207 : ::com::sun::star::uno::Reference< ::com::sun::star::ui::XUIConfigurationManager > m_xDocUICfgMgr;
208 :
209 : CommandToInfoMap m_aCommandMap;
210 : SubToolBarToSubToolBarControllerMap m_aSubToolBarControllerMap;
211 : Timer m_aAsyncUpdateControllersTimer;
212 : OUString m_sIconTheme;
213 : MenuDescriptionMap m_aMenuMap;
214 : bool m_bAcceleratorCfg;
215 : ::com::sun::star::uno::Reference< ::com::sun::star::ui::XAcceleratorConfiguration > m_xDocAcceleratorManager;
216 : ::com::sun::star::uno::Reference< ::com::sun::star::ui::XAcceleratorConfiguration > m_xModuleAcceleratorManager;
217 : ::com::sun::star::uno::Reference< ::com::sun::star::ui::XAcceleratorConfiguration > m_xGlobalAcceleratorManager;
218 : };
219 :
220 : }
221 :
222 : #endif // INCLUDED_FRAMEWORK_INC_UIELEMENT_TOOLBARMANAGER_HXX
223 :
224 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|