Coverage Report

Created: 2025-11-16 09:57

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