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