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