xref: /trunk/main/sfx2/inc/sfx2/unoctitm.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _SFX_UNOCTITM_HXX
28 #define _SFX_UNOCTITM_HXX
29 
30 #include <functional>
31 #include <com/sun/star/frame/XNotifyingDispatch.hpp>
32 #include <com/sun/star/frame/XDispatchResultListener.hpp>
33 #include <com/sun/star/frame/XDispatchProviderInterceptor.hpp>
34 #include <com/sun/star/frame/XDispatch.hpp>
35 #include <com/sun/star/frame/XDispatchProvider.hpp>
36 #include <com/sun/star/frame/XStatusListener.hpp>
37 #include <com/sun/star/frame/FrameSearchFlag.hpp>
38 #include <com/sun/star/frame/XDispatchProviderInterception.hpp>
39 #include <com/sun/star/frame/FeatureStateEvent.hpp>
40 #include <com/sun/star/frame/DispatchDescriptor.hpp>
41 #include <com/sun/star/util/XURLTransformer.hpp>
42 #include <com/sun/star/lang/XUnoTunnel.hpp>
43 #include <com/sun/star/frame/XFrame.hpp>
44 #include <cppuhelper/weak.hxx>
45 #include <cppuhelper/interfacecontainer.hxx>
46 
47 #include <sfx2/sfxuno.hxx>
48 #include <sfx2/ctrlitem.hxx>
49 #include <osl/mutex.hxx>
50 
51 class SfxBindings;
52 class SfxFrame;
53 class SfxDispatcher;
54 
55 class SfxUnoControllerItem :	public ::com::sun::star::frame::XStatusListener	,
56 								public ::com::sun::star::lang::XTypeProvider	,
57 								public ::cppu::OWeakObject
58 {
59 	::com::sun::star::util::URL							aCommand;
60 	::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > 				xDispatch;
61 	SfxControllerItem*			pCtrlItem;
62 	SfxBindings*				pBindings;
63 
64 	::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > 				TryGetDispatch( SfxFrame* pFrame );
65 
66 public:
67 	SFX_DECL_XINTERFACE_XTYPEPROVIDER
68 
69 
70 								SfxUnoControllerItem( SfxControllerItem*, SfxBindings&, const String& );
71 								~SfxUnoControllerItem();
72 
73 	const ::com::sun::star::util::URL&					GetCommand() const
74 								{ return aCommand; }
75 	void						Execute();
76 
77 	// XStatusListener
78 	virtual void SAL_CALL statusChanged(const ::com::sun::star::frame::FeatureStateEvent& Event) throw( ::com::sun::star::uno::RuntimeException );
79 
80 	// Something else
81 	virtual void 	SAL_CALL			disposing(const ::com::sun::star::lang::EventObject& Source) throw( ::com::sun::star::uno::RuntimeException );
82 	void						UnBind();
83 	void 						GetNewDispatch();
84 	void 						ReleaseDispatch();
85 	void						ReleaseBindings();
86 };
87 
88 struct SfxStatusDispatcher_Impl_hashType
89 {
90 	size_t operator()(const ::rtl::OUString& s) const
91 		{ return s.hashCode(); }
92 };
93 
94 typedef ::cppu::OMultiTypeInterfaceContainerHelperVar< ::rtl::OUString, SfxStatusDispatcher_Impl_hashType, std::equal_to< ::rtl::OUString > >   SfxStatusDispatcher_Impl_ListenerContainer ;
95 
96 class SfxStatusDispatcher   :   public ::com::sun::star::frame::XNotifyingDispatch,
97 								public ::com::sun::star::lang::XTypeProvider,
98 								public ::cppu::OWeakObject
99 {
100 	::osl::Mutex		aMutex;
101 	SfxStatusDispatcher_Impl_ListenerContainer	aListeners;
102 
103 public:
104 	SFX_DECL_XINTERFACE_XTYPEPROVIDER
105 
106 	SfxStatusDispatcher();
107 
108 	// XDispatch
109     virtual void SAL_CALL dispatchWithNotification( const ::com::sun::star::util::URL& aURL,
110                 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs,
111                 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchResultListener >& rListener ) throw( ::com::sun::star::uno::RuntimeException );
112 	virtual void SAL_CALL dispatch( const ::com::sun::star::util::URL& aURL, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs ) throw( ::com::sun::star::uno::RuntimeException );
113 	virtual void SAL_CALL addStatusListener(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > & xControl, const ::com::sun::star::util::URL& aURL) throw( ::com::sun::star::uno::RuntimeException );
114 	virtual void SAL_CALL removeStatusListener(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > & xControl, const ::com::sun::star::util::URL& aURL) throw( ::com::sun::star::uno::RuntimeException );
115 
116 	// Something else
117 	void				ReleaseAll();
118 	SfxStatusDispatcher_Impl_ListenerContainer& GetListeners()
119 						{ return aListeners; }
120 };
121 
122 class SfxSlotServer;
123 class SfxDispatchController_Impl;
124 class SfxOfficeDispatch : public SfxStatusDispatcher
125 						, public ::com::sun::star::lang::XUnoTunnel
126 {
127 friend class SfxDispatchController_Impl;
128     SfxDispatchController_Impl*  pControllerItem;
129 public:
130                                 SfxOfficeDispatch( SfxBindings& rBind,
131                                                    SfxDispatcher* pDispat,
132                                                    const SfxSlot* pSlot,
133                                                    const ::com::sun::star::util::URL& rURL );
134                                 SfxOfficeDispatch( SfxDispatcher* pDispat,
135                                                    const SfxSlot* pSlot,
136                                                    const ::com::sun::star::util::URL& rURL );
137 						        ~SfxOfficeDispatch();
138 
139 	SFX_DECL_XINTERFACE_XTYPEPROVIDER
140 
141     virtual void SAL_CALL       dispatchWithNotification( const ::com::sun::star::util::URL& aURL,
142                                                           const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs,
143                                                           const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchResultListener >& rListener )
144                                 throw( ::com::sun::star::uno::RuntimeException );
145 	virtual void   SAL_CALL		dispatch( const ::com::sun::star::util::URL& aURL,
146                                           const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs )
147                                 throw( ::com::sun::star::uno::RuntimeException );
148 	virtual void   SAL_CALL		addStatusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > & xControl,
149                                                    const ::com::sun::star::util::URL& aURL)
150                                 throw( ::com::sun::star::uno::RuntimeException );
151 
152 	// XUnoTunnel
153     virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException) ;
154     static const ::com::sun::star::uno::Sequence< sal_Int8 >& impl_getStaticIdentifier();
155 
156     static sal_Bool         IsMasterUnoCommand( const ::com::sun::star::util::URL& aURL );
157     static rtl::OUString    GetMasterUnoCommand( const ::com::sun::star::util::URL& aURL );
158 
159     void                    SetFrame(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame);
160 
161     void                    SetMasterUnoCommand( sal_Bool bSet );
162     sal_Bool                IsMasterUnoCommand() const;
163 
164     SfxDispatcher*          GetDispatcher_Impl();
165 };
166 
167 //#if 0 // _SOLAR__PRIVATE
168 class SfxDispatchController_Impl : public SfxControllerItem
169 {
170     ::com::sun::star::util::URL aDispatchURL;
171     SfxDispatcher*              pDispatcher;
172     SfxBindings*                pBindings;
173 	const SfxPoolItem*	        pLastState;
174 	sal_uInt16			        nSlot;
175     SfxOfficeDispatch*          pDispatch;
176     sal_Bool                    bMasterSlave;
177     sal_Bool                    bVisible;
178     const char*                 pUnoName;
179     ::com::sun::star::uno::WeakReference< ::com::sun::star::frame::XFrame > xFrame;
180 
181     void                addParametersToArgs( const com::sun::star::util::URL& aURL,
182                                              ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rArgs ) const;
183     using SfxControllerItem::GetCoreMetric;
184     SfxMapUnit          GetCoreMetric( SfxItemPool& rPool, sal_uInt16 nSlot );
185 
186 public:
187                         SfxDispatchController_Impl( SfxOfficeDispatch*                 pDisp,
188                                                     SfxBindings*                       pBind,
189                                                     SfxDispatcher*                     pDispat,
190                                                     const SfxSlot*                     pSlot,
191                                                     const ::com::sun::star::util::URL& rURL );
192                         ~SfxDispatchController_Impl();
193 
194     static rtl::OUString getSlaveCommand( const ::com::sun::star::util::URL& rURL );
195 
196     void                StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState, SfxSlotServer* pServ );
197     virtual void		StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState );
198     void                setMasterSlaveCommand( sal_Bool bSet );
199     sal_Bool            isMasterSlaveCommand() const;
200     void SAL_CALL       dispatch( const ::com::sun::star::util::URL& aURL,
201                                   const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs,
202                                   const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchResultListener >& rListener ) throw( ::com::sun::star::uno::RuntimeException );
203     void SAL_CALL       addStatusListener(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > & xControl, const ::com::sun::star::util::URL& aURL) throw( ::com::sun::star::uno::RuntimeException );
204     void                UnBindController();
205     SfxDispatcher*      GetDispatcher();
206     void                    SetFrame(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame);
207 };
208 //#endif
209 
210 #endif
211 
212