fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / framework / source / helper / ocomponentaccess.cxx
blobedc0dcb5208f8ab74dbeb1afed3b2ee2d197f6d4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <helper/ocomponentaccess.hxx>
21 #include <helper/ocomponentenumeration.hxx>
23 #include <com/sun/star/frame/FrameSearchFlag.hpp>
25 #include <vcl/svapp.hxx>
27 namespace framework{
29 using namespace ::com::sun::star::container;
30 using namespace ::com::sun::star::frame;
31 using namespace ::com::sun::star::lang;
32 using namespace ::com::sun::star::uno;
33 using namespace ::cppu;
34 using namespace ::osl;
36 // constructor
38 OComponentAccess::OComponentAccess( const css::uno::Reference< XDesktop >& xOwner )
39 : m_xOwner ( xOwner )
41 // Safe impossible cases
42 SAL_WARN_IF( !impldbg_checkParameter_OComponentAccessCtor( xOwner ), "fwk", "OComponentAccess::OComponentAccess(): Invalid parameter detected!" );
45 // destructor
47 OComponentAccess::~OComponentAccess()
51 // XEnumerationAccess
52 css::uno::Reference< XEnumeration > SAL_CALL OComponentAccess::createEnumeration() throw( RuntimeException, std::exception )
54 SolarMutexGuard g;
56 // Set default return value, if method failed.
57 // If no desktop exist and there is no task container - return an empty enumeration!
58 css::uno::Reference< XEnumeration > xReturn = css::uno::Reference< XEnumeration >();
60 // Try to "lock" the desktop for access to task container.
61 css::uno::Reference< XInterface > xLock = m_xOwner.get();
62 if ( xLock.is() )
64 // Desktop exist => pointer to task container must be valid.
65 // Initialize a new enumeration ... if some tasks and his components exist!
66 // (OTasksEnumeration will make an assert, if we initialize the new instance without valid values!)
68 Sequence< css::uno::Reference< XComponent > > seqComponents;
69 impl_collectAllChildComponents( css::uno::Reference< XFramesSupplier >( xLock, UNO_QUERY ), seqComponents );
70 OComponentEnumeration* pEnumeration = new OComponentEnumeration( seqComponents );
71 xReturn = css::uno::Reference< XEnumeration >( (OWeakObject*)pEnumeration, UNO_QUERY );
74 // Return result of this operation.
75 return xReturn;
78 // XElementAccess
79 Type SAL_CALL OComponentAccess::getElementType() throw( RuntimeException, std::exception )
81 // Elements in list an enumeration are components!
82 // Return the uno-type of XComponent.
83 return cppu::UnoType<XComponent>::get();
86 // XElementAccess
87 sal_Bool SAL_CALL OComponentAccess::hasElements() throw( RuntimeException, std::exception )
89 SolarMutexGuard g;
91 // Set default return value, if method failed.
92 bool bReturn = false;
94 // Try to "lock" the desktop for access to task container.
95 css::uno::Reference< XFramesSupplier > xLock( m_xOwner.get(), UNO_QUERY );
96 if ( xLock.is() )
98 // Ask container of owner for existing elements.
99 bReturn = xLock->getFrames()->hasElements();
102 // Return result of this operation.
103 return bReturn;
107 void OComponentAccess::impl_collectAllChildComponents( const css::uno::Reference< XFramesSupplier >& xNode ,
108 Sequence< css::uno::Reference< XComponent > >& seqComponents )
110 // If valid node was given ...
111 if( xNode.is() )
113 // ... continue collection at these.
115 // Get the container of current node, collect the components of existing child frames
116 // and go down to next level in tree (recursive!).
118 sal_Int32 nComponentCount = seqComponents.getLength();
120 const css::uno::Reference< XFrames > xContainer = xNode->getFrames();
121 const Sequence< css::uno::Reference< XFrame > > seqFrames = xContainer->queryFrames( FrameSearchFlag::CHILDREN );
123 const sal_Int32 nFrameCount = seqFrames.getLength();
124 for( sal_Int32 nFrame=0; nFrame<nFrameCount; ++nFrame )
126 css::uno::Reference< XComponent > xComponent = impl_getFrameComponent( seqFrames[nFrame] );
127 if( xComponent.is() )
129 nComponentCount++;
130 seqComponents.realloc( nComponentCount );
131 seqComponents[nComponentCount-1] = xComponent;
135 // ... otherwise break a recursive path and go back at current stack!
138 css::uno::Reference< XComponent > OComponentAccess::impl_getFrameComponent( const css::uno::Reference< XFrame >& xFrame ) const
140 // Set default return value, if method failed.
141 css::uno::Reference< XComponent > xComponent = css::uno::Reference< XComponent >();
142 // Does no controller exists?
143 css::uno::Reference< XController > xController = xFrame->getController();
144 if ( !xController.is() )
146 // Controller not exist - use the VCL-component.
147 xComponent = css::uno::Reference< XComponent >( xFrame->getComponentWindow(), UNO_QUERY );
149 else
151 // Does no model exists?
152 css::uno::Reference< XModel > xModel( xController->getModel(), UNO_QUERY );
153 if ( xModel.is() )
155 // Model exist - use the model as component.
156 xComponent = css::uno::Reference< XComponent >( xModel, UNO_QUERY );
158 else
160 // Model not exist - use the controller as component.
161 xComponent = css::uno::Reference< XComponent >( xController, UNO_QUERY );
165 return xComponent;
168 // debug methods
170 /*-----------------------------------------------------------------------------------------------------------------
171 The follow methods checks the parameter for other functions. If a parameter or his value is non valid,
172 we return "sal_False". (else sal_True) This mechanism is used to throw an ASSERT!
174 ATTENTION
176 If you miss a test for one of this parameters, contact the author or add it himself !(?)
177 But ... look for right testing! See using of this methods!
178 -----------------------------------------------------------------------------------------------------------------*/
180 bool OComponentAccess::impldbg_checkParameter_OComponentAccessCtor( const css::uno::Reference< XDesktop >& xOwner )
182 return xOwner.is();
185 } // namespace framework
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */