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 _SVTOOLS_TOOLBOXCONTROLLER_HXX 25 #define _SVTOOLS_TOOLBOXCONTROLLER_HXX 26 27 #include "svtools/svtdllapi.h" 28 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 29 #include <com/sun/star/lang/XInitialization.hpp> 30 #include <com/sun/star/util/XUpdatable.hpp> 31 #include <com/sun/star/frame/XFrame.hpp> 32 #include <com/sun/star/frame/XDispatch.hpp> 33 #include <com/sun/star/frame/XStatusListener.hpp> 34 #include <com/sun/star/frame/XToolbarController.hpp> 35 #include <com/sun/star/util/XURLTransformer.hpp> 36 #include <com/sun/star/frame/XLayoutManager.hpp> 37 #include <cppuhelper/weak.hxx> 38 #include <cppuhelper/interfacecontainer.hxx> 39 #include <comphelper/broadcasthelper.hxx> 40 #include <com/sun/star/util/XURLTransformer.hpp> 41 #include <comphelper/proparrhlp.hxx> 42 #include <comphelper/property.hxx> 43 #include <comphelper/propertycontainer.hxx> 44 #include <cppuhelper/propshlp.hxx> 45 #include <cppuhelper/interfacecontainer.hxx> 46 #include <tools/link.hxx> 47 48 //end 49 #ifndef INCLUDED_HASH_MAP 50 #include <hash_map> 51 #define INCLUDED_HASH_MAP 52 #endif 53 54 class ToolBox; 55 56 namespace svt 57 { 58 59 class SVT_DLLPUBLIC ToolboxController : public ::com::sun::star::frame::XStatusListener, 60 public ::com::sun::star::frame::XToolbarController, 61 public ::com::sun::star::lang::XInitialization, 62 public ::com::sun::star::util::XUpdatable, 63 public ::com::sun::star::lang::XComponent, 64 public ::comphelper::OMutexAndBroadcastHelper,//shizhoubo 65 public ::comphelper::OPropertyContainer,//shizhoubo 66 public ::comphelper::OPropertyArrayUsageHelper< ToolboxController >,//shizhoubo 67 public ::cppu::OWeakObject 68 { 69 private: 70 sal_Bool m_bSupportVisiable; //shizhoubo 71 public: 72 ToolboxController( const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rServiceManager, 73 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame, 74 const rtl::OUString& aCommandURL ); 75 ToolboxController(); 76 virtual ~ToolboxController(); 77 78 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > getFrameInterface() const; 79 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > getServiceManager() const; 80 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XLayoutManager > getLayoutManager() const; 81 82 void updateStatus( const rtl::OUString aCommandURL ); 83 void updateStatus(); 84 85 // XInterface 86 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType ) throw (::com::sun::star::uno::RuntimeException); 87 virtual void SAL_CALL acquire() throw (); 88 virtual void SAL_CALL release() throw (); 89 90 // XInitialization 91 virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 92 93 // XUpdatable 94 virtual void SAL_CALL update() throw (::com::sun::star::uno::RuntimeException); 95 96 // XComponent 97 virtual void SAL_CALL dispose() throw (::com::sun::star::uno::RuntimeException); 98 virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); 99 virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException); 100 101 // XEventListener 102 using cppu::OPropertySetHelper::disposing; 103 virtual void SAL_CALL disposing( const com::sun::star::lang::EventObject& Source ) throw ( ::com::sun::star::uno::RuntimeException ); 104 105 // XStatusListener 106 virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event ) throw ( ::com::sun::star::uno::RuntimeException ) = 0; 107 108 // XToolbarController 109 virtual void SAL_CALL execute( sal_Int16 KeyModifier ) throw (::com::sun::star::uno::RuntimeException); 110 virtual void SAL_CALL click() throw (::com::sun::star::uno::RuntimeException); 111 virtual void SAL_CALL doubleClick() throw (::com::sun::star::uno::RuntimeException); 112 virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > SAL_CALL createPopupWindow() throw (::com::sun::star::uno::RuntimeException); 113 virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > SAL_CALL createItemWindow( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& Parent ) throw (::com::sun::star::uno::RuntimeException); 114 // OPropertySetHelper //shizhoubo 115 virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const com::sun::star::uno::Any& rValue ) throw(com::sun::star::uno::Exception); 116 virtual sal_Bool SAL_CALL convertFastPropertyValue( com::sun::star::uno::Any& rConvertedValue, com::sun::star::uno::Any& rOldValue, sal_Int32 nHandle, const com::sun::star::uno::Any& rValue) throw(com::sun::star::lang::IllegalArgumentException); 117 // XPropertySet //shizhoubo 118 virtual ::com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo() throw(::com::sun::star::uno::RuntimeException); 119 virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper(); 120 // OPropertyArrayUsageHelper //shizhoubo 121 virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const; 122 123 getCommandURL() const124 const rtl::OUString& getCommandURL() const { return m_aCommandURL; } getModuleName() const125 const rtl::OUString& getModuleName() const { return m_sModuleName; } 126 127 void dispatchCommand( const ::rtl::OUString& sCommandURL, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rArgs, const rtl::OUString &sTarget = rtl::OUString() ); 128 129 void enable( bool bEnable ); 130 131 protected: 132 bool getToolboxId( sal_uInt16& rItemId, ToolBox** ppToolBox ); 133 void setSupportVisiableProperty(sal_Bool bValue); //shizhoubo 134 struct Listener 135 { Listenersvt::ToolboxController::Listener136 Listener( const ::com::sun::star::util::URL& rURL, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch >& rDispatch ) : 137 aURL( rURL ), xDispatch( rDispatch ) {} 138 139 ::com::sun::star::util::URL aURL; 140 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > xDispatch; 141 }; 142 143 struct DispatchInfo 144 { 145 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > mxDispatch; 146 const ::com::sun::star::util::URL maURL; 147 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > maArgs; 148 DispatchInfosvt::ToolboxController::DispatchInfo149 DispatchInfo( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch >& xDispatch, 150 const ::com::sun::star::util::URL& rURL, 151 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rArgs ) 152 : mxDispatch( xDispatch ) 153 , maURL( rURL ) 154 , maArgs( rArgs ) 155 {} 156 }; 157 158 DECL_STATIC_LINK( ToolboxController, ExecuteHdl_Impl, DispatchInfo* ); 159 160 typedef ::std::hash_map< ::rtl::OUString, 161 com::sun::star::uno::Reference< com::sun::star::frame::XDispatch >, 162 ::rtl::OUStringHash, 163 ::std::equal_to< ::rtl::OUString > > URLToDispatchMap; 164 165 // methods to support status forwarder, known by the old sfx2 toolbox controller implementation 166 void addStatusListener( const rtl::OUString& aCommandURL ); 167 void removeStatusListener( const rtl::OUString& aCommandURL ); 168 void bindListener(); 169 void unbindListener(); 170 sal_Bool isBound() const; 171 sal_Bool hasBigImages() const; 172 sal_Bool isHighContrast() const; 173 // TODO remove 174 ::com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer > getURLTransformer() const; 175 // TODO remove 176 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > getParent() const; 177 178 sal_Bool m_bInitialized : 1, 179 m_bDisposed : 1; 180 sal_uInt16 m_nToolBoxId; 181 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > m_xFrame; 182 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xServiceManager; 183 rtl::OUString m_aCommandURL; 184 URLToDispatchMap m_aListenerMap; 185 ::cppu::OMultiTypeInterfaceContainerHelper m_aListenerContainer; /// container for ALL Listener 186 187 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > m_xParentWindow; 188 ::com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer > m_xUrlTransformer; 189 rtl::OUString m_sModuleName; 190 191 }; 192 193 } 194 195 #endif // _SVTOOLS_TOOLBOXCONTROLLER_HXX 196