1*f8e07b45SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f8e07b45SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f8e07b45SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f8e07b45SAndrew Rist  * distributed with this work for additional information
6*f8e07b45SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f8e07b45SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f8e07b45SAndrew Rist  * "License"); you may not use this file except in compliance
9*f8e07b45SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*f8e07b45SAndrew Rist  *
11*f8e07b45SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*f8e07b45SAndrew Rist  *
13*f8e07b45SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f8e07b45SAndrew Rist  * software distributed under the License is distributed on an
15*f8e07b45SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f8e07b45SAndrew Rist  * KIND, either express or implied.  See the License for the
17*f8e07b45SAndrew Rist  * specific language governing permissions and limitations
18*f8e07b45SAndrew Rist  * under the License.
19*f8e07b45SAndrew Rist  *
20*f8e07b45SAndrew Rist  *************************************************************/
21*f8e07b45SAndrew Rist 
22*f8e07b45SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef __FRAMEWORK_HELPER_OCOMPONENTACCESS_HXX_
25cdf0e10cSrcweir #define __FRAMEWORK_HELPER_OCOMPONENTACCESS_HXX_
26cdf0e10cSrcweir 
27cdf0e10cSrcweir //_________________________________________________________________________________________________________________
28cdf0e10cSrcweir //	my own includes
29cdf0e10cSrcweir //_________________________________________________________________________________________________________________
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <threadhelp/threadhelpbase.hxx>
32cdf0e10cSrcweir #include <macros/generic.hxx>
33cdf0e10cSrcweir #include <macros/xinterface.hxx>
34cdf0e10cSrcweir #include <macros/xtypeprovider.hxx>
35cdf0e10cSrcweir #include <macros/debug.hxx>
36cdf0e10cSrcweir #include <general.h>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir //_________________________________________________________________________________________________________________
39cdf0e10cSrcweir //	interface includes
40cdf0e10cSrcweir //_________________________________________________________________________________________________________________
41cdf0e10cSrcweir #include <com/sun/star/frame/XFramesSupplier.hpp>
42cdf0e10cSrcweir #include <com/sun/star/container/XEnumerationAccess.hpp>
43cdf0e10cSrcweir #include <com/sun/star/container/XElementAccess.hpp>
44cdf0e10cSrcweir #include <com/sun/star/container/XEnumeration.hpp>
45cdf0e10cSrcweir #include <com/sun/star/frame/XDesktop.hpp>
46cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
47cdf0e10cSrcweir 
48cdf0e10cSrcweir //_________________________________________________________________________________________________________________
49cdf0e10cSrcweir //	other includes
50cdf0e10cSrcweir //_________________________________________________________________________________________________________________
51cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
52cdf0e10cSrcweir #include <cppuhelper/weakref.hxx>
53cdf0e10cSrcweir 
54cdf0e10cSrcweir //_________________________________________________________________________________________________________________
55cdf0e10cSrcweir //	namespace
56cdf0e10cSrcweir //_________________________________________________________________________________________________________________
57cdf0e10cSrcweir 
58cdf0e10cSrcweir namespace framework{
59cdf0e10cSrcweir 
60cdf0e10cSrcweir //_________________________________________________________________________________________________________________
61cdf0e10cSrcweir //	exported const
62cdf0e10cSrcweir //_________________________________________________________________________________________________________________
63cdf0e10cSrcweir 
64cdf0e10cSrcweir //_________________________________________________________________________________________________________________
65cdf0e10cSrcweir //	exported definitions
66cdf0e10cSrcweir //_________________________________________________________________________________________________________________
67cdf0e10cSrcweir 
68cdf0e10cSrcweir /*-************************************************************************************************************//**
69cdf0e10cSrcweir 	@short			implement XEnumerationAccess interface as helper to create many oneway enumeration of components
70cdf0e10cSrcweir 	@descr			We share mutex and framecontainer with ouer owner and have full access to his child tasks.
71cdf0e10cSrcweir 					(Ouer owner can be the Desktop only!) We create oneway enumerations on demand. These "lists"
72cdf0e10cSrcweir 					can be used for one time only. Step during the list from first to last element.
73cdf0e10cSrcweir 					(The type of created enumerations is OComponentEnumeration.)
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 	@implements		XInterface
76cdf0e10cSrcweir 					XTypeProvider
77cdf0e10cSrcweir 					XEnumerationAccess
78cdf0e10cSrcweir 					XElementAccess
79cdf0e10cSrcweir 
80cdf0e10cSrcweir     @base           ThreadHelpBase
81cdf0e10cSrcweir                     OWeakObject
82cdf0e10cSrcweir 
83cdf0e10cSrcweir 	@devstatus		ready to use
84cdf0e10cSrcweir *//*-*************************************************************************************************************/
85cdf0e10cSrcweir 
86cdf0e10cSrcweir class OComponentAccess	:	private ThreadHelpBase                      ,   // Must be the first of baseclasses - Is neccessary for right initialization of objects!
87cdf0e10cSrcweir 							public ::cppu::WeakImplHelper1< ::com::sun::star::container::XEnumerationAccess >
88cdf0e10cSrcweir {
89cdf0e10cSrcweir 	//-------------------------------------------------------------------------------------------------------------
90cdf0e10cSrcweir 	//	public methods
91cdf0e10cSrcweir 	//-------------------------------------------------------------------------------------------------------------
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 	public:
94cdf0e10cSrcweir 
95cdf0e10cSrcweir 		//---------------------------------------------------------------------------------------------------------
96cdf0e10cSrcweir 		//	constructor / destructor
97cdf0e10cSrcweir 		//---------------------------------------------------------------------------------------------------------
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 		/*-****************************************************************************************************//**
100cdf0e10cSrcweir 			@short		constructor to initialize this instance
101cdf0e10cSrcweir 			@descr		A desktop will create an enumeration-access-object. An enumeration is a oneway-list and a
102cdf0e10cSrcweir 						snapshot of the components of current tasks under the desktop.
103cdf0e10cSrcweir 						But we need a instance to create more then one enumerations at different times!
104cdf0e10cSrcweir 
105cdf0e10cSrcweir 			@seealso	class Desktop
106cdf0e10cSrcweir 			@seealso	class OComponentEnumeration
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 			@param		"xOwner" is a reference to ouer owner and must be the desktop!
109cdf0e10cSrcweir 			@return		-
110cdf0e10cSrcweir 
111cdf0e10cSrcweir 			@onerror	Do nothing and reset this object to default with an empty list.
112cdf0e10cSrcweir 		*//*-*****************************************************************************************************/
113cdf0e10cSrcweir 
114cdf0e10cSrcweir         OComponentAccess( const css::uno::Reference< css::frame::XDesktop >& xOwner );
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 		//---------------------------------------------------------------------------------------------------------
117cdf0e10cSrcweir 		//	XEnumerationAccess
118cdf0e10cSrcweir 		//---------------------------------------------------------------------------------------------------------
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 		/*-****************************************************************************************************//**
121cdf0e10cSrcweir 			@short		create a new enumeration of components
122cdf0e10cSrcweir 			@descr		You can call this method to get a new snapshot from all components of all tasks of the desktop as an enumeration.
123cdf0e10cSrcweir 
124cdf0e10cSrcweir 			@seealso	interface XEnumerationAccess
125cdf0e10cSrcweir 			@seealso	interface XEnumeration
126cdf0e10cSrcweir 			@seealso	class Desktop
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 			@param		-
129cdf0e10cSrcweir 			@return		If the desktop and some components exist => a valid reference to an enumeration<BR>
130cdf0e10cSrcweir 						An NULL-reference, other way.
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 			@onerror	-
133cdf0e10cSrcweir 		*//*-*****************************************************************************************************/
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 	    virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw( css::uno::RuntimeException );
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 		//---------------------------------------------------------------------------------------------------------
138cdf0e10cSrcweir 		//	XElementAccess
139cdf0e10cSrcweir 		//---------------------------------------------------------------------------------------------------------
140cdf0e10cSrcweir 
141cdf0e10cSrcweir 		/*-****************************************************************************************************//**
142cdf0e10cSrcweir 			@short		get the type of elements in enumeration
143cdf0e10cSrcweir 			@descr		-
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 			@seealso	interface XElementAccess
146cdf0e10cSrcweir 			@seealso	class OComponentEnumeration
147cdf0e10cSrcweir 
148cdf0e10cSrcweir 			@param		-
149cdf0e10cSrcweir 			@return		The uno-type XComponent.
150cdf0e10cSrcweir 
151cdf0e10cSrcweir 			@onerror	-
152cdf0e10cSrcweir 		*//*-*****************************************************************************************************/
153cdf0e10cSrcweir 
154cdf0e10cSrcweir 		virtual css::uno::Type SAL_CALL getElementType() throw( css::uno::RuntimeException );
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 		/*-****************************************************************************************************//**
157cdf0e10cSrcweir 			@short		get state of componentlist of enumeration.
158cdf0e10cSrcweir 			@descr		-
159cdf0e10cSrcweir 
160cdf0e10cSrcweir 			@seealso	interface XElementAccess
161cdf0e10cSrcweir 
162cdf0e10cSrcweir 			@param		-
163cdf0e10cSrcweir 			@return		sal_True  ,if more then 0 elements exist.
164cdf0e10cSrcweir 			@return		sal_False ,otherwise.
165cdf0e10cSrcweir 
166cdf0e10cSrcweir 			@onerror	-
167cdf0e10cSrcweir 		*//*-*****************************************************************************************************/
168cdf0e10cSrcweir 
169cdf0e10cSrcweir     	virtual sal_Bool SAL_CALL hasElements() throw( css::uno::RuntimeException );
170cdf0e10cSrcweir 
171cdf0e10cSrcweir 	//-------------------------------------------------------------------------------------------------------------
172cdf0e10cSrcweir 	//	protected methods
173cdf0e10cSrcweir 	//-------------------------------------------------------------------------------------------------------------
174cdf0e10cSrcweir 
175cdf0e10cSrcweir 	protected:
176cdf0e10cSrcweir 
177cdf0e10cSrcweir 		/*-****************************************************************************************************//**
178cdf0e10cSrcweir 			@short		standard destructor
179cdf0e10cSrcweir 			@descr		This method destruct an instance of this class and clear some member.
180cdf0e10cSrcweir 						Don't use an instance of this class as normal member. Use it dynamicly with a pointer.
181cdf0e10cSrcweir 						We hold a weakreference to ouer owner and not to ouer superclass!
182cdf0e10cSrcweir 						Thats the reason for a protected dtor.
183cdf0e10cSrcweir 
184cdf0e10cSrcweir 			@seealso	class Desktop
185cdf0e10cSrcweir 
186cdf0e10cSrcweir 			@param		-
187cdf0e10cSrcweir 			@return		-
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 			@onerror	-
190cdf0e10cSrcweir 		*//*-*****************************************************************************************************/
191cdf0e10cSrcweir 
192cdf0e10cSrcweir 		virtual	~OComponentAccess();
193cdf0e10cSrcweir 
194cdf0e10cSrcweir 	//-------------------------------------------------------------------------------------------------------------
195cdf0e10cSrcweir 	//	private methods
196cdf0e10cSrcweir 	//-------------------------------------------------------------------------------------------------------------
197cdf0e10cSrcweir 
198cdf0e10cSrcweir 	private:
199cdf0e10cSrcweir 
200cdf0e10cSrcweir 		/*-****************************************************************************************************//**
201cdf0e10cSrcweir 			@short		recursive method (!) to collect all components of all frames from the subtree of given node
202cdf0e10cSrcweir 			@descr		This is neccessary to create the enumeration.
203cdf0e10cSrcweir 
204cdf0e10cSrcweir 			@seealso	method createEnumeration
205cdf0e10cSrcweir 
206cdf0e10cSrcweir 			@param		"xNode"        , root of subtree and start point of search
207cdf0e10cSrcweir 			@param		"seqComponents", result list of search. We cant use a return value, we search recursive
208cdf0e10cSrcweir 										 and must collect all informations.
209cdf0e10cSrcweir 			@return		-
210cdf0e10cSrcweir 
211cdf0e10cSrcweir 			@onerror	-
212cdf0e10cSrcweir 		*//*-*****************************************************************************************************/
213cdf0e10cSrcweir 
214cdf0e10cSrcweir 		void impl_collectAllChildComponents(	const	css::uno::Reference< css::frame::XFramesSupplier >&					xNode			,
215cdf0e10cSrcweir 	 		 											css::uno::Sequence< css::uno::Reference< css::lang::XComponent > >&	seqComponents	);
216cdf0e10cSrcweir 
217cdf0e10cSrcweir 		/*-****************************************************************************************************//**
218cdf0e10cSrcweir 			@short		get the component of a frame
219cdf0e10cSrcweir 			@descr		The component of a frame can be the window, the controller or the model.
220cdf0e10cSrcweir 
221cdf0e10cSrcweir 			@seealso	method createEnumeration
222cdf0e10cSrcweir 
223cdf0e10cSrcweir 			@param		"xFrame", frame which contains the component
224cdf0e10cSrcweir 			@return		A reference to the component of given frame.
225cdf0e10cSrcweir 
226cdf0e10cSrcweir 			@onerror	A null reference is returned.
227cdf0e10cSrcweir 		*//*-*****************************************************************************************************/
228cdf0e10cSrcweir 
229cdf0e10cSrcweir 		css::uno::Reference< css::lang::XComponent > impl_getFrameComponent( const css::uno::Reference< css::frame::XFrame >& xFrame ) const;
230cdf0e10cSrcweir 
231cdf0e10cSrcweir 	//-------------------------------------------------------------------------------------------------------------
232cdf0e10cSrcweir 	//	debug methods
233cdf0e10cSrcweir 	//	(should be private everyway!)
234cdf0e10cSrcweir 	//-------------------------------------------------------------------------------------------------------------
235cdf0e10cSrcweir 
236cdf0e10cSrcweir 		/*-****************************************************************************************************//**
237cdf0e10cSrcweir 			@short		debug-method to check incoming parameter of some other mehods of this class
238cdf0e10cSrcweir 			@descr		The following methods are used to check parameters for other methods
239cdf0e10cSrcweir 						of this class. The return value is used directly for an ASSERT(...).
240cdf0e10cSrcweir 
241cdf0e10cSrcweir 			@seealso	ASSERTs in implementation!
242cdf0e10cSrcweir 
243cdf0e10cSrcweir 			@param		references to checking variables
244cdf0e10cSrcweir 			@return		sal_False ,on invalid parameter.
245cdf0e10cSrcweir 			@return		sal_True  ,otherwise
246cdf0e10cSrcweir 
247cdf0e10cSrcweir 			@onerror	-
248cdf0e10cSrcweir 		*//*-*****************************************************************************************************/
249cdf0e10cSrcweir 
250cdf0e10cSrcweir 	#ifdef ENABLE_ASSERTIONS
251cdf0e10cSrcweir 
252cdf0e10cSrcweir 	private:
253cdf0e10cSrcweir 
254cdf0e10cSrcweir         static sal_Bool impldbg_checkParameter_OComponentAccessCtor( const css::uno::Reference< css::frame::XDesktop >& xOwner );
255cdf0e10cSrcweir 
256cdf0e10cSrcweir 	#endif	// #ifdef ENABLE_ASSERTIONS
257cdf0e10cSrcweir 
258cdf0e10cSrcweir 	//-------------------------------------------------------------------------------------------------------------
259cdf0e10cSrcweir 	//	variables
260cdf0e10cSrcweir 	//	(should be private everyway!)
261cdf0e10cSrcweir 	//-------------------------------------------------------------------------------------------------------------
262cdf0e10cSrcweir 
263cdf0e10cSrcweir 	private:
264cdf0e10cSrcweir 
265cdf0e10cSrcweir         css::uno::WeakReference< css::frame::XDesktop >     m_xOwner    ;   /// weak reference to the desktop object!
266cdf0e10cSrcweir 
267cdf0e10cSrcweir };		//	class OComponentAccess
268cdf0e10cSrcweir 
269cdf0e10cSrcweir }		//	namespace framework
270cdf0e10cSrcweir 
271cdf0e10cSrcweir #endif	//	#ifndef __FRAMEWORK_HELPER_OCOMPONENTACCESS_HXX_
272