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