Coverage Report

Created: 2026-05-16 09:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/chart2/source/controller/main/ChartFrameloader.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 "ChartFrameloader.hxx"
21
#include <MediaDescriptorHelper.hxx>
22
#include <ChartController.hxx>
23
#include <ChartModel.hxx>
24
#include <unotools/fcm.hxx>
25
#include <unotools/mediadescriptor.hxx>
26
#include <cppuhelper/supportsservice.hxx>
27
#include <com/sun/star/frame/XLoadable.hpp>
28
#include <com/sun/star/uno/XComponentContext.hpp>
29
#include <comphelper/diagnose_ex.hxx>
30
#include <comphelper/sequenceashashmap.hxx>
31
32
namespace chart
33
{
34
35
using namespace ::com::sun::star;
36
37
ChartFrameLoader::ChartFrameLoader(
38
        uno::Reference<uno::XComponentContext> const & xContext)
39
0
        : m_bCancelRequired( false )
40
0
{
41
0
    m_xCC = xContext;
42
0
    m_oCancelFinished.reset();
43
0
}
44
45
ChartFrameLoader::~ChartFrameLoader()
46
0
{
47
0
}
48
49
bool ChartFrameLoader::impl_checkCancel()
50
0
{
51
0
    if(m_bCancelRequired)
52
0
    {
53
0
        m_oCancelFinished.set();
54
0
        return true;
55
0
    }
56
0
    return false;
57
0
}
58
59
// lang::XServiceInfo
60
61
OUString SAL_CALL ChartFrameLoader::getImplementationName()
62
0
{
63
0
    return u"com.sun.star.comp.chart2.ChartFrameLoader"_ustr;
64
0
}
65
66
sal_Bool SAL_CALL ChartFrameLoader::supportsService( const OUString& rServiceName )
67
0
{
68
0
    return cppu::supportsService(this, rServiceName);
69
0
}
70
71
css::uno::Sequence< OUString > SAL_CALL ChartFrameLoader::getSupportedServiceNames()
72
0
{
73
0
    return { u"com.sun.star.frame.SynchronousFrameLoader"_ustr };
74
0
}
75
76
// frame::XFrameLoader
77
78
sal_Bool SAL_CALL ChartFrameLoader::load( const uno::Sequence< beans::PropertyValue >& rMediaDescriptor, const uno::Reference<frame::XFrame >& xFrame )
79
0
{
80
    //@todo ? need to add as terminate listener to desktop?
81
82
0
    uno::Reference< frame::XModel >         xModel;
83
0
    bool bHaveLoadedModel = false;
84
85
0
    comphelper::SequenceAsHashMap aMediaDescriptor(rMediaDescriptor);
86
0
    {
87
0
        auto aIt(aMediaDescriptor.find(utl::MediaDescriptor::PROP_MODEL));
88
0
        if( aIt != aMediaDescriptor.end())
89
0
        {
90
0
            xModel.set( (*aIt).second.get< uno::Reference< frame::XModel > >());
91
0
            bHaveLoadedModel = true;
92
0
        }
93
0
    }
94
95
    //create and initialize the model
96
0
    if( ! xModel.is())
97
0
    {
98
        //@todo?? load mechanism to cancel during loading of document
99
0
        xModel = new ChartModel(m_xCC);
100
101
0
        if( impl_checkCancel() )
102
0
            return false;
103
0
    }
104
105
    //create the controller(+XWindow)
106
0
    rtl::Reference< ChartController > xController = new ChartController(m_xCC);
107
108
0
    if( impl_checkCancel() )
109
0
        return false;
110
111
    //connect frame, controller and model one to each other:
112
0
    if(xModel.is())
113
0
    {
114
0
        utl::ConnectFrameControllerModel(xFrame, xController, xModel);
115
0
    }
116
117
    // call initNew() or load() at XLoadable
118
0
    if(bHaveLoadedModel)
119
0
        return true;
120
121
0
    try
122
0
    {
123
0
        auto aIt(aMediaDescriptor.find(utl::MediaDescriptor::PROP_URL));
124
0
        if( aIt != aMediaDescriptor.end())
125
0
        {
126
0
            OUString aURL( (*aIt).second.get< OUString >());
127
0
            if( aURL.startsWith( "private:factory/schart" ) )
128
0
            {
129
                // create new file
130
0
                uno::Reference< frame::XLoadable > xLoadable( xModel, uno::UNO_QUERY_THROW );
131
0
                xLoadable->initNew();
132
0
            }
133
0
            else
134
0
            {
135
                // use the URL as BaseURL, similar to what SfxBaseModel effectively does
136
0
                if (!aURL.isEmpty())
137
0
                {
138
0
                    aMediaDescriptor[utl::MediaDescriptor::PROP_DOCUMENTBASEURL] <<= aURL;
139
0
                }
140
0
                utl::MediaDescriptor::addInputStream(aMediaDescriptor);
141
0
                uno::Sequence< beans::PropertyValue > aCompleteMediaDescriptor;
142
0
                aMediaDescriptor >> aCompleteMediaDescriptor;
143
0
                apphelper::MediaDescriptorHelper aMDHelper( aCompleteMediaDescriptor );
144
145
                // load file
146
                // @todo: replace: aMediaDescriptorHelper.getReducedForModel()
147
0
                uno::Reference< frame::XLoadable > xLoadable( xModel, uno::UNO_QUERY_THROW );
148
0
                xLoadable->load( aCompleteMediaDescriptor );
149
150
                //resize standalone files to get correct size:
151
0
                if( aMDHelper.ISSET_FilterName && aMDHelper.FilterName == "StarChart 5.0" )
152
0
                {
153
0
                    uno::Reference<awt::XWindow> xComponentWindow = xController->getComponentWindow();
154
0
                    awt::Rectangle aRect( xComponentWindow->getPosSize() );
155
0
                    xComponentWindow->setPosSize( aRect.X, aRect.Y, aRect.Width, aRect.Height, 0 );
156
0
                }
157
0
            }
158
0
        }
159
0
    }
160
0
    catch( const uno::Exception & )
161
0
    {
162
0
        DBG_UNHANDLED_EXCEPTION("chart2");
163
0
    }
164
165
0
    return true;
166
0
}
167
168
void SAL_CALL ChartFrameLoader::cancel()
169
0
{
170
0
    m_oCancelFinished.reset();
171
0
    m_bCancelRequired = true;
172
0
    m_oCancelFinished.wait();
173
0
    m_bCancelRequired = false;
174
0
}
175
176
} //namespace chart
177
178
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
179
com_sun_star_comp_chart2_ChartFrameLoader_get_implementation(css::uno::XComponentContext *context,
180
                                                             css::uno::Sequence<css::uno::Any> const &)
181
0
{
182
0
    return cppu::acquire(new chart::ChartFrameLoader(context));
183
0
}
184
185
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */