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 
28 #ifndef __FRAMEWORK_DISPATCH_POPUPMENUDISPATCHER_HXX_
29 #define __FRAMEWORK_DISPATCH_POPUPMENUDISPATCHER_HXX_
30 
31 //_________________________________________________________________________________________________________________
32 //	my own includes
33 //_________________________________________________________________________________________________________________
34 
35 #include <services/frame.hxx>
36 /*
37 #include <macros/generic.hxx>
38 */
39 #include <macros/xinterface.hxx>
40 #include <macros/xtypeprovider.hxx>
41 #include <macros/xserviceinfo.hxx>
42 /*
43 #include <macros/debug.hxx>
44 */
45 #include <threadhelp/threadhelpbase.hxx>
46 #include <general.h>
47 #include <stdtypes.h>
48 
49 //_________________________________________________________________________________________________________________
50 //	interface includes
51 //_________________________________________________________________________________________________________________
52 #include <com/sun/star/lang/XTypeProvider.hpp>
53 #include <com/sun/star/frame/XDispatch.hpp>
54 #include <com/sun/star/frame/XDispatchProvider.hpp>
55 #include <com/sun/star/util/URL.hpp>
56 #include <com/sun/star/frame/DispatchDescriptor.hpp>
57 #include <com/sun/star/beans/PropertyValue.hpp>
58 #include <com/sun/star/frame/XStatusListener.hpp>
59 #include <com/sun/star/frame/XFrameLoader.hpp>
60 #include <com/sun/star/frame/XLoadEventListener.hpp>
61 #include <com/sun/star/frame/XDesktop.hpp>
62 #include <com/sun/star/frame/FeatureStateEvent.hpp>
63 #include <com/sun/star/frame/XFrameActionListener.hpp>
64 #include <com/sun/star/lang/XInitialization.hpp>
65 #include <com/sun/star/container/XNameAccess.hpp>
66 #ifndef _COM_SUN_STAR_URI_XURLREFERENCEFACTORY_HPP_
67 #include <com/sun/star/uri/XUriReferenceFactory.hpp>
68 #endif
69 #ifndef _COM_SUN_STAR_URI_XURLREFERENCE_HPP_
70 #include <com/sun/star/uri/XUriReference.hpp>
71 #endif
72 
73 //_________________________________________________________________________________________________________________
74 //	other includes
75 //_________________________________________________________________________________________________________________
76 #include <cppuhelper/weak.hxx>
77 #include <cppuhelper/weakref.hxx>
78 #include <cppuhelper/interfacecontainer.h>
79 
80 //_________________________________________________________________________________________________________________
81 //	namespace
82 //_________________________________________________________________________________________________________________
83 
84 namespace framework{
85 
86 
87 //_________________________________________________________________________________________________________________
88 //	exported const
89 //_________________________________________________________________________________________________________________
90 
91 //_________________________________________________________________________________________________________________
92 //	exported definitions
93 //_________________________________________________________________________________________________________________
94 
95 /*-************************************************************************************************************//**
96 	We must save informations about our listener and URL for listening.
97 	We implement this as a hashtable for strings.
98 *//*-*************************************************************************************************************/
99 
100 typedef ::cppu::OMultiTypeInterfaceContainerHelperVar<	::rtl::OUString			,
101 														OUStringHashCode		,
102 														std::equal_to< ::rtl::OUString > > IMPL_ListenerHashContainer;
103 
104 
105 /*-************************************************************************************************************//**
106 	@short			helper for desktop only(!) to create new tasks on demand for dispatches
107 	@descr			Use this class as member only! Never use it as baseclass.
108 					XInterface will be ambigous and we hold a weakcss::uno::Reference to ouer OWNER - not to our SUPERCLASS!
109 
110 	@implements		XInterface
111 					XDispatch
112 					XLoadEventListener
113 					XFrameActionListener
114 					XEventListener
115 	@base			ThreadHelpBase
116 					OWeakObject
117 
118 	@devstatus		ready to use
119 *//*-*************************************************************************************************************/
120 class PopupMenuDispatcher :   // interfaces
121 								public css::lang::XTypeProvider			,
122                                 public css::lang::XServiceInfo          ,
123                                 public css::frame::XDispatchProvider    ,
124 								public css::frame::XDispatch			,
125 								public css::frame::XFrameActionListener	,
126                                 public css::lang::XInitialization       ,
127 								// baseclasses
128 								// Order is neccessary for right initialization!
129 								public ThreadHelpBase					,
130 								public cppu::OWeakObject
131 {
132 	//-------------------------------------------------------------------------------------------------------------
133 	//	public methods
134 	//-------------------------------------------------------------------------------------------------------------
135 	public:
136 
137         //	constructor / destructor
138         PopupMenuDispatcher( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory );
139 
140         // XInterface, XTypeProvider, XServiceInfo
141         FWK_DECLARE_XINTERFACE
142         FWK_DECLARE_XTYPEPROVIDER
143         DECLARE_XSERVICEINFO
144 
145         // XInitialization
146         virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& lArguments ) throw( css::uno::Exception       ,
147                                                                                                          css::uno::RuntimeException);
148         // XDispatchProvider
149         virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > SAL_CALL queryDispatch(
150             const ::com::sun::star::util::URL&  aURL        ,
151             const ::rtl::OUString& sTarget     ,
152             sal_Int32              nFlags      )
153         throw( ::com::sun::star::uno::RuntimeException );
154 
155         virtual css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL queryDispatches(
156             const css::uno::Sequence< css::frame::DispatchDescriptor >& lDescriptor )
157         throw( css::uno::RuntimeException );
158 
159 		//	XDispatch
160 		virtual void SAL_CALL dispatch(	const css::util::URL&                                  aURL,
161 										const css::uno::Sequence< css::beans::PropertyValue >& seqProperties ) throw( css::uno::RuntimeException );
162 
163 		virtual void SAL_CALL addStatusListener( const css::uno::Reference< css::frame::XStatusListener >& xControl,
164 												 const css::util::URL&                                     aURL	) throw( css::uno::RuntimeException );
165 
166     	virtual void SAL_CALL removeStatusListener(	const css::uno::Reference< css::frame::XStatusListener >& xControl,
167 													const css::util::URL&                                     aURL	) throw( css::uno::RuntimeException );
168 
169 
170 		//	 XFrameActionListener
171 		virtual void SAL_CALL frameAction( const css::frame::FrameActionEvent& aEvent ) throw ( css::uno::RuntimeException );
172 
173 		//	 XEventListener
174         void SAL_CALL disposing( const css::lang::EventObject& aEvent ) throw( css::uno::RuntimeException );
175 
176 	//	protected methods
177 	protected:
178         virtual ~PopupMenuDispatcher();
179 
180         void impl_RetrievePopupControllerQuery();
181         void impl_CreateUriRefFactory();
182 
183 	//	private methods
184 
185 	//	variables
186 	private:
187 		css::uno::WeakReference< css::frame::XFrame >			m_xWeakFrame		;	/// css::uno::WeakReference to frame (Don't use a hard css::uno::Reference. Owner can't delete us then!)
188         css::uno::Reference< css::container::XNameAccess >      m_xPopupCtrlQuery   ;   /// reference to query for popup controller
189         css::uno::Reference< css::uri::XUriReferenceFactory >   m_xUriRefFactory    ;   /// reference to the uri reference factory
190 		css::uno::Reference< css::lang::XMultiServiceFactory >	m_xFactory			;	/// factory shared with our owner to create new services!
191 		IMPL_ListenerHashContainer								m_aListenerContainer;	/// hash table for listener at specified URLs
192 		sal_Bool												m_bAlreadyDisposed	;	/// Protection against multiple disposing calls.
193 		sal_Bool												m_bActivateListener ;	/// dispatcher is listener for frame activation
194 
195 }; //  class PopupMenuDispatcher
196 
197 }		//	namespace framework
198 
199 #endif  //  #ifndef __FRAMEWORK_DISPATCH_POPUPMENUDISPATCHER_HXX_
200