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 struct DispatchInfo; 60 61 class SVT_DLLPUBLIC ToolboxController : public ::com::sun::star::frame::XStatusListener, 62 public ::com::sun::star::frame::XToolbarController, 63 public ::com::sun::star::lang::XInitialization, 64 public ::com::sun::star::util::XUpdatable, 65 public ::com::sun::star::lang::XComponent, 66 public ::comphelper::OMutexAndBroadcastHelper,//shizhoubo 67 public ::comphelper::OPropertyContainer,//shizhoubo 68 public ::comphelper::OPropertyArrayUsageHelper< ToolboxController >,//shizhoubo 69 public ::cppu::OWeakObject 70 { 71 private: 72 sal_Bool m_bSupportVisiable; //shizhoubo 73 public: 74 ToolboxController( const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rServiceManager, 75 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame, 76 const rtl::OUString& aCommandURL ); 77 ToolboxController(); 78 virtual ~ToolboxController(); 79 80 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > getFrameInterface() const; 81 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > getServiceManager() const; 82 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XLayoutManager > getLayoutManager() const; 83 84 void updateStatus( const rtl::OUString aCommandURL ); 85 void updateStatus(); 86 87 // XInterface 88 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType ) throw (::com::sun::star::uno::RuntimeException); 89 virtual void SAL_CALL acquire() throw (); 90 virtual void SAL_CALL release() throw (); 91 92 // XInitialization 93 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); 94 95 // XUpdatable 96 virtual void SAL_CALL update() throw (::com::sun::star::uno::RuntimeException); 97 98 // XComponent 99 virtual void SAL_CALL dispose() throw (::com::sun::star::uno::RuntimeException); 100 virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); 101 virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException); 102 103 // XEventListener 104 using cppu::OPropertySetHelper::disposing; 105 virtual void SAL_CALL disposing( const com::sun::star::lang::EventObject& Source ) throw ( ::com::sun::star::uno::RuntimeException ); 106 107 // XStatusListener 108 virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event ) throw ( ::com::sun::star::uno::RuntimeException ) = 0; 109 110 // XToolbarController 111 virtual void SAL_CALL execute( sal_Int16 KeyModifier ) throw (::com::sun::star::uno::RuntimeException); 112 virtual void SAL_CALL click() throw (::com::sun::star::uno::RuntimeException); 113 virtual void SAL_CALL doubleClick() throw (::com::sun::star::uno::RuntimeException); 114 virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > SAL_CALL createPopupWindow() throw (::com::sun::star::uno::RuntimeException); 115 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); 116 // OPropertySetHelper //shizhoubo 117 virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const com::sun::star::uno::Any& rValue ) throw(com::sun::star::uno::Exception); 118 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); 119 // XPropertySet //shizhoubo 120 virtual ::com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo() throw(::com::sun::star::uno::RuntimeException); 121 virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper(); 122 // OPropertyArrayUsageHelper //shizhoubo 123 virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const; 124 125 126 const rtl::OUString& getCommandURL() const { return m_aCommandURL; } 127 const rtl::OUString& getModuleName() const { return m_sModuleName; } 128 129 void dispatchCommand( const ::rtl::OUString& sCommandURL, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rArgs ); 130 131 void enable( bool bEnable ); 132 133 DECL_STATIC_LINK( ToolboxController, ExecuteHdl_Impl, DispatchInfo* ); 134 135 protected: 136 bool getToolboxId( sal_uInt16& rItemId, ToolBox** ppToolBox ); 137 void setSupportVisiableProperty(sal_Bool bValue); //shizhoubo 138 struct Listener 139 { 140 Listener( const ::com::sun::star::util::URL& rURL, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch >& rDispatch ) : 141 aURL( rURL ), xDispatch( rDispatch ) {} 142 143 ::com::sun::star::util::URL aURL; 144 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > xDispatch; 145 }; 146 147 typedef ::std::hash_map< ::rtl::OUString, 148 com::sun::star::uno::Reference< com::sun::star::frame::XDispatch >, 149 ::rtl::OUStringHash, 150 ::std::equal_to< ::rtl::OUString > > URLToDispatchMap; 151 152 // methods to support status forwarder, known by the old sfx2 toolbox controller implementation 153 void addStatusListener( const rtl::OUString& aCommandURL ); 154 void removeStatusListener( const rtl::OUString& aCommandURL ); 155 void bindListener(); 156 void unbindListener(); 157 sal_Bool isBound() const; 158 sal_Bool hasBigImages() const; 159 sal_Bool isHighContrast() const; 160 // TODO remove 161 ::com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer > getURLTransformer() const; 162 // TODO remove 163 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > getParent() const; 164 165 sal_Bool m_bInitialized : 1, 166 m_bDisposed : 1; 167 sal_uInt16 m_nToolBoxId; 168 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > m_xFrame; 169 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xServiceManager; 170 rtl::OUString m_aCommandURL; 171 URLToDispatchMap m_aListenerMap; 172 ::cppu::OMultiTypeInterfaceContainerHelper m_aListenerContainer; /// container for ALL Listener 173 174 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > m_xParentWindow; 175 ::com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer > m_xUrlTransformer; 176 rtl::OUString m_sModuleName; 177 178 }; 179 180 } 181 182 #endif // _SVTOOLS_TOOLBOXCONTROLLER_HXX 183