/src/libreoffice/framework/source/helper/ocomponentaccess.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #include <helper/ocomponentaccess.hxx> |
21 | | #include <helper/ocomponentenumeration.hxx> |
22 | | |
23 | | #include <com/sun/star/frame/FrameSearchFlag.hpp> |
24 | | |
25 | | #include <rtl/ref.hxx> |
26 | | #include <vcl/svapp.hxx> |
27 | | #include <sal/log.hxx> |
28 | | |
29 | | namespace framework{ |
30 | | |
31 | | using namespace ::com::sun::star::container; |
32 | | using namespace ::com::sun::star::frame; |
33 | | using namespace ::com::sun::star::lang; |
34 | | using namespace ::com::sun::star::uno; |
35 | | using namespace ::cppu; |
36 | | |
37 | | // constructor |
38 | | |
39 | | OComponentAccess::OComponentAccess( const css::uno::Reference< XDesktop >& xOwner ) |
40 | 0 | : m_xOwner ( xOwner ) |
41 | 0 | { |
42 | | // Safe impossible cases |
43 | 0 | SAL_WARN_IF( !xOwner.is(), "fwk", "OComponentAccess::OComponentAccess(): Invalid parameter detected!" ); |
44 | 0 | } |
45 | | |
46 | | // destructor |
47 | | |
48 | | OComponentAccess::~OComponentAccess() |
49 | 0 | { |
50 | 0 | } |
51 | | |
52 | | // XEnumerationAccess |
53 | | css::uno::Reference< XEnumeration > SAL_CALL OComponentAccess::createEnumeration() |
54 | 0 | { |
55 | 0 | SolarMutexGuard g; |
56 | | |
57 | | // Set default return value, if method failed. |
58 | | // If no desktop exist and there is no task container - return an empty enumeration! |
59 | 0 | rtl::Reference< OComponentEnumeration > xReturn; |
60 | | |
61 | | // Try to "lock" the desktop for access to task container. |
62 | 0 | css::uno::Reference< XInterface > xLock = m_xOwner.get(); |
63 | 0 | if ( xLock.is() ) |
64 | 0 | { |
65 | | // Desktop exist => pointer to task container must be valid. |
66 | | // Initialize a new enumeration ... if some tasks and his components exist! |
67 | | // (OTasksEnumeration will make an assert, if we initialize the new instance without valid values!) |
68 | |
|
69 | 0 | std::vector< css::uno::Reference< XComponent > > seqComponents; |
70 | 0 | impl_collectAllChildComponents( css::uno::Reference< XFramesSupplier >( xLock, UNO_QUERY ), seqComponents ); |
71 | 0 | xReturn = new OComponentEnumeration( std::move(seqComponents) ); |
72 | 0 | } |
73 | | |
74 | | // Return result of this operation. |
75 | 0 | return xReturn; |
76 | 0 | } |
77 | | |
78 | | // XElementAccess |
79 | | Type SAL_CALL OComponentAccess::getElementType() |
80 | 0 | { |
81 | | // Elements in list an enumeration are components! |
82 | | // Return the uno-type of XComponent. |
83 | 0 | return cppu::UnoType<XComponent>::get(); |
84 | 0 | } |
85 | | |
86 | | // XElementAccess |
87 | | sal_Bool SAL_CALL OComponentAccess::hasElements() |
88 | 0 | { |
89 | 0 | SolarMutexGuard g; |
90 | | |
91 | | // Set default return value, if method failed. |
92 | 0 | bool bReturn = false; |
93 | | |
94 | | // Try to "lock" the desktop for access to task container. |
95 | 0 | css::uno::Reference< XFramesSupplier > xLock( m_xOwner.get(), UNO_QUERY ); |
96 | 0 | if ( xLock.is() ) |
97 | 0 | { |
98 | | // Ask container of owner for existing elements. |
99 | 0 | bReturn = xLock->getFrames()->hasElements(); |
100 | 0 | } |
101 | | |
102 | | // Return result of this operation. |
103 | 0 | return bReturn; |
104 | 0 | } |
105 | | |
106 | | // static |
107 | | void OComponentAccess::impl_collectAllChildComponents( const css::uno::Reference< XFramesSupplier >& xNode , |
108 | | std::vector< css::uno::Reference< XComponent > >& seqComponents ) |
109 | 0 | { |
110 | | // If valid node was given ... |
111 | 0 | if( !xNode.is() ) |
112 | 0 | return; |
113 | | |
114 | | // ... continue collection at these. |
115 | | |
116 | | // Get the container of current node, collect the components of existing child frames |
117 | | // and go down to next level in tree (recursive!). |
118 | | |
119 | 0 | const css::uno::Reference< XFrames > xContainer = xNode->getFrames(); |
120 | 0 | const Sequence< css::uno::Reference< XFrame > > seqFrames = xContainer->queryFrames( FrameSearchFlag::CHILDREN ); |
121 | |
|
122 | 0 | const sal_Int32 nFrameCount = seqFrames.getLength(); |
123 | 0 | for( sal_Int32 nFrame=0; nFrame<nFrameCount; ++nFrame ) |
124 | 0 | { |
125 | 0 | css::uno::Reference< XComponent > xComponent = impl_getFrameComponent( seqFrames[nFrame] ); |
126 | 0 | if( xComponent.is() ) |
127 | 0 | { |
128 | 0 | seqComponents.push_back( xComponent ); |
129 | 0 | } |
130 | 0 | } |
131 | | // ... otherwise break a recursive path and go back at current stack! |
132 | 0 | } |
133 | | |
134 | | // static |
135 | | css::uno::Reference< XComponent > OComponentAccess::impl_getFrameComponent( const css::uno::Reference< XFrame >& xFrame ) |
136 | 0 | { |
137 | | // Set default return value, if method failed. |
138 | 0 | css::uno::Reference< XComponent > xComponent; |
139 | | // Does no controller exists? |
140 | 0 | css::uno::Reference< XController > xController = xFrame->getController(); |
141 | 0 | if ( !xController.is() ) |
142 | 0 | { |
143 | | // Controller not exist - use the VCL-component. |
144 | 0 | xComponent = xFrame->getComponentWindow(); |
145 | 0 | } |
146 | 0 | else |
147 | 0 | { |
148 | | // Does no model exists? |
149 | 0 | css::uno::Reference< XModel > xModel = xController->getModel(); |
150 | 0 | if ( xModel.is() ) |
151 | 0 | { |
152 | | // Model exist - use the model as component. |
153 | 0 | xComponent = xModel; |
154 | 0 | } |
155 | 0 | else |
156 | 0 | { |
157 | | // Model not exist - use the controller as component. |
158 | 0 | xComponent = xController; |
159 | 0 | } |
160 | 0 | } |
161 | |
|
162 | 0 | return xComponent; |
163 | 0 | } |
164 | | |
165 | | |
166 | | } // namespace framework |
167 | | |
168 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |