1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_framework.hxx" 26 27 //_________________________________________________________________________________________________________________ 28 // my own includes 29 //_________________________________________________________________________________________________________________ 30 #include <helper/ocomponentaccess.hxx> 31 #include <helper/ocomponentenumeration.hxx> 32 33 #ifndef _FRAMEWORK_THREADHELP_RESETABLEGUARD_HXX_ 34 #include <threadhelp/resetableguard.hxx> 35 #endif 36 37 //_________________________________________________________________________________________________________________ 38 // interface includes 39 //_________________________________________________________________________________________________________________ 40 #include <com/sun/star/frame/FrameSearchFlag.hpp> 41 42 //_________________________________________________________________________________________________________________ 43 // includes of other projects 44 //_________________________________________________________________________________________________________________ 45 #include <vcl/svapp.hxx> 46 47 //_________________________________________________________________________________________________________________ 48 // namespace 49 //_________________________________________________________________________________________________________________ 50 51 namespace framework{ 52 53 using namespace ::com::sun::star::container ; 54 using namespace ::com::sun::star::frame ; 55 using namespace ::com::sun::star::lang ; 56 using namespace ::com::sun::star::uno ; 57 using namespace ::cppu ; 58 using namespace ::osl ; 59 using namespace ::rtl ; 60 61 //_________________________________________________________________________________________________________________ 62 // non exported const 63 //_________________________________________________________________________________________________________________ 64 65 //_________________________________________________________________________________________________________________ 66 // non exported definitions 67 //_________________________________________________________________________________________________________________ 68 69 //_________________________________________________________________________________________________________________ 70 // declarations 71 //_________________________________________________________________________________________________________________ 72 73 //***************************************************************************************************************** 74 // constructor 75 //***************************************************************************************************************** 76 OComponentAccess::OComponentAccess( const css::uno::Reference< XDesktop >& xOwner ) 77 // Init baseclasses first 78 : ThreadHelpBase ( &Application::GetSolarMutex() ) 79 // Init member 80 , m_xOwner ( xOwner ) 81 { 82 // Safe impossible cases 83 LOG_ASSERT( impldbg_checkParameter_OComponentAccessCtor( xOwner ), "OComponentAccess::OComponentAccess()\nInvalid parameter detected!\n" ) 84 } 85 86 //***************************************************************************************************************** 87 // destructor 88 //***************************************************************************************************************** 89 OComponentAccess::~OComponentAccess() 90 { 91 } 92 93 //***************************************************************************************************************** 94 // XEnumerationAccess 95 //***************************************************************************************************************** 96 css::uno::Reference< XEnumeration > SAL_CALL OComponentAccess::createEnumeration() throw( RuntimeException ) 97 { 98 // Ready for multithreading 99 ResetableGuard aGuard( m_aLock ); 100 101 // Set default return value, if method failed. 102 // If no desktop exist and there is no task container - return an empty enumeration! 103 css::uno::Reference< XEnumeration > xReturn = css::uno::Reference< XEnumeration >(); 104 105 // Try to "lock" the desktop for access to task container. 106 css::uno::Reference< XInterface > xLock = m_xOwner.get(); 107 if ( xLock.is() == sal_True ) 108 { 109 // Desktop exist => pointer to task container must be valid. 110 // Initialize a new enumeration ... if some tasks and his components exist! 111 // (OTasksEnumeration will make an assert, if we initialize the new instance without valid values!) 112 113 Sequence< css::uno::Reference< XComponent > > seqComponents; 114 impl_collectAllChildComponents( css::uno::Reference< XFramesSupplier >( xLock, UNO_QUERY ), seqComponents ); 115 OComponentEnumeration* pEnumeration = new OComponentEnumeration( seqComponents ); 116 xReturn = css::uno::Reference< XEnumeration >( (OWeakObject*)pEnumeration, UNO_QUERY ); 117 } 118 119 // Return result of this operation. 120 return xReturn; 121 } 122 123 //***************************************************************************************************************** 124 // XElementAccess 125 //***************************************************************************************************************** 126 Type SAL_CALL OComponentAccess::getElementType() throw( RuntimeException ) 127 { 128 // Elements in list an enumeration are components! 129 // Return the uno-type of XComponent. 130 return ::getCppuType((const css::uno::Reference< XComponent >*)NULL); 131 } 132 133 //***************************************************************************************************************** 134 // XElementAccess 135 //***************************************************************************************************************** 136 sal_Bool SAL_CALL OComponentAccess::hasElements() throw( RuntimeException ) 137 { 138 // Ready for multithreading 139 ResetableGuard aGuard( m_aLock ); 140 141 // Set default return value, if method failed. 142 sal_Bool bReturn = sal_False; 143 144 // Try to "lock" the desktop for access to task container. 145 css::uno::Reference< XFramesSupplier > xLock( m_xOwner.get(), UNO_QUERY ); 146 if ( xLock.is() == sal_True ) 147 { 148 // Ask container of owner for existing elements. 149 bReturn = xLock->getFrames()->hasElements(); 150 } 151 152 // Return result of this operation. 153 return bReturn; 154 } 155 156 //***************************************************************************************************************** 157 // private method 158 //***************************************************************************************************************** 159 void OComponentAccess::impl_collectAllChildComponents( const css::uno::Reference< XFramesSupplier >& xNode , 160 Sequence< css::uno::Reference< XComponent > >& seqComponents ) 161 { 162 // If valid node was given ... 163 if( xNode.is() == sal_True ) 164 { 165 // ... continue collection at these. 166 167 // Get the container of current node, collect the components of existing child frames 168 // and go down to next level in tree (recursive!). 169 170 sal_Int32 nComponentCount = seqComponents.getLength(); 171 172 const css::uno::Reference< XFrames > xContainer = xNode->getFrames(); 173 const Sequence< css::uno::Reference< XFrame > > seqFrames = xContainer->queryFrames( FrameSearchFlag::CHILDREN ); 174 175 const sal_Int32 nFrameCount = seqFrames.getLength(); 176 for( sal_Int32 nFrame=0; nFrame<nFrameCount; ++nFrame ) 177 { 178 css::uno::Reference< XComponent > xComponent = impl_getFrameComponent( seqFrames[nFrame] ); 179 if( xComponent.is() == sal_True ) 180 { 181 nComponentCount++; 182 seqComponents.realloc( nComponentCount ); 183 seqComponents[nComponentCount-1] = xComponent; 184 } 185 } 186 } 187 // ... otherwise break a recursive path and go back at current stack! 188 } 189 190 //***************************************************************************************************************** 191 // private method 192 //***************************************************************************************************************** 193 css::uno::Reference< XComponent > OComponentAccess::impl_getFrameComponent( const css::uno::Reference< XFrame >& xFrame ) const 194 { 195 // Set default return value, if method failed. 196 css::uno::Reference< XComponent > xComponent = css::uno::Reference< XComponent >(); 197 // Does no controller exists? 198 css::uno::Reference< XController > xController = xFrame->getController(); 199 if ( xController.is() == sal_False ) 200 { 201 // Controller not exist - use the VCL-component. 202 xComponent = css::uno::Reference< XComponent >( xFrame->getComponentWindow(), UNO_QUERY ); 203 } 204 else 205 { 206 // Does no model exists? 207 css::uno::Reference< XModel > xModel( xController->getModel(), UNO_QUERY ); 208 if ( xModel.is() == sal_True ) 209 { 210 // Model exist - use the model as component. 211 xComponent = css::uno::Reference< XComponent >( xModel, UNO_QUERY ); 212 } 213 else 214 { 215 // Model not exist - use the controller as component. 216 xComponent = css::uno::Reference< XComponent >( xController, UNO_QUERY ); 217 } 218 } 219 220 return xComponent; 221 } 222 223 //_________________________________________________________________________________________________________________ 224 // debug methods 225 //_________________________________________________________________________________________________________________ 226 227 /*----------------------------------------------------------------------------------------------------------------- 228 The follow methods checks the parameter for other functions. If a parameter or his value is non valid, 229 we return "sal_False". (else sal_True) This mechanism is used to throw an ASSERT! 230 231 ATTENTION 232 233 If you miss a test for one of this parameters, contact the autor or add it himself !(?) 234 But ... look for right testing! See using of this methods! 235 -----------------------------------------------------------------------------------------------------------------*/ 236 237 #ifdef ENABLE_ASSERTIONS 238 239 //***************************************************************************************************************** 240 sal_Bool OComponentAccess::impldbg_checkParameter_OComponentAccessCtor( const css::uno::Reference< XDesktop >& xOwner ) 241 { 242 // Set default return value. 243 sal_Bool bOK = sal_True; 244 // Check parameter. 245 if ( 246 ( &xOwner == NULL ) || 247 ( xOwner.is() == sal_False ) 248 ) 249 { 250 bOK = sal_False ; 251 } 252 // Return result of check. 253 return bOK ; 254 } 255 256 #endif // #ifdef ENABLE_ASSERTIONS 257 258 } // namespace framework 259