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 //shizhoubo for ToolbarController Visiable
42 #include <comphelper/proparrhlp.hxx>
43 #include <comphelper/property.hxx>
44 #include <comphelper/propertycontainer.hxx>
45 #include <cppuhelper/propshlp.hxx>
46 #include <cppuhelper/interfacecontainer.hxx>
47 //end
48 #ifndef INCLUDED_HASH_MAP
49 #include <hash_map>
50 #define INCLUDED_HASH_MAP
51 #endif
52 
53 class ToolBox;
54 
55 namespace svt
56 {
57 struct ToolboxController_Impl;
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 
124 		const rtl::OUString& getCommandURL() const { return  m_aCommandURL; }
125 		const rtl::OUString& getModuleName() const;
126 
127 		void dispatchCommand( const ::rtl::OUString& sCommandURL, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rArgs );
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         {
136             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         typedef ::std::hash_map< ::rtl::OUString,
144 				                 com::sun::star::uno::Reference< com::sun::star::frame::XDispatch >,
145                                  ::rtl::OUStringHash,
146 								 ::std::equal_to< ::rtl::OUString > > URLToDispatchMap;
147 
148         // methods to support status forwarder, known by the old sfx2 toolbox controller implementation
149         void addStatusListener( const rtl::OUString& aCommandURL );
150         void removeStatusListener( const rtl::OUString& aCommandURL );
151         void bindListener();
152         void unbindListener();
153         sal_Bool isBound() const;
154         sal_Bool hasBigImages() const;
155         sal_Bool isHighContrast() const;
156         ::com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer > getURLTransformer() const;
157 		::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > getParent() const;
158 
159         sal_Bool                                                                            m_bInitialized : 1,
160                                                                                             m_bDisposed : 1;
161 		::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >					m_xFrame;
162 		ToolboxController_Impl*																m_pImpl;
163         ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >    m_xServiceManager;
164         rtl::OUString                                                                       m_aCommandURL;
165         URLToDispatchMap                                                                    m_aListenerMap;
166         ::cppu::OMultiTypeInterfaceContainerHelper                                          m_aListenerContainer;   /// container for ALL Listener
167 };
168 
169 }
170 
171 #endif // _SVTOOLS_TOOLBOXCONTROLLER_HXX
172