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