1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "ChartFrameloader.hxx"
21 #include <servicenames.hxx>
22 #include <MediaDescriptorHelper.hxx>
23 #include <unotools/mediadescriptor.hxx>
24 #include <cppuhelper/supportsservice.hxx>
25 #include <com/sun/star/document/XImporter.hpp>
26 #include <com/sun/star/document/XFilter.hpp>
27 #include <com/sun/star/frame/XLoadable.hpp>
28 #include <tools/diagnose_ex.h>
33 using namespace ::com::sun::star
;
35 ChartFrameLoader::ChartFrameLoader(
36 uno::Reference
<uno::XComponentContext
> const & xContext
)
37 : m_bCancelRequired( false )
40 m_oCancelFinished
.reset();
43 ChartFrameLoader::~ChartFrameLoader()
47 bool ChartFrameLoader::impl_checkCancel()
51 m_oCancelFinished
.set();
59 OUString SAL_CALL
ChartFrameLoader::getImplementationName()
61 return OUString(CHART_FRAMELOADER_SERVICE_IMPLEMENTATION_NAME
);
64 sal_Bool SAL_CALL
ChartFrameLoader::supportsService( const OUString
& rServiceName
)
66 return cppu::supportsService(this, rServiceName
);
69 css::uno::Sequence
< OUString
> SAL_CALL
ChartFrameLoader::getSupportedServiceNames()
71 return { CHART_FRAMELOADER_SERVICE_NAME
};
74 // frame::XFrameLoader
76 sal_Bool SAL_CALL
ChartFrameLoader::load( const uno::Sequence
< beans::PropertyValue
>& rMediaDescriptor
, const uno::Reference
<frame::XFrame
>& xFrame
)
78 //@todo ? need to add as terminate listener to desktop?
80 uno::Reference
< frame::XModel
> xModel
;
81 bool bHaveLoadedModel
= false;
83 utl::MediaDescriptor
aMediaDescriptor(rMediaDescriptor
);
85 utl::MediaDescriptor::const_iterator
aIt( aMediaDescriptor
.find( utl::MediaDescriptor::PROP_MODEL()));
86 if( aIt
!= aMediaDescriptor
.end())
88 xModel
.set( (*aIt
).second
.get
< uno::Reference
< frame::XModel
> >());
89 bHaveLoadedModel
= true;
93 //create and initialize the model
96 //@todo?? load mechanism to cancel during loading of document
98 m_xCC
->getServiceManager()->createInstanceWithContext(
99 CHART_MODEL_SERVICE_IMPLEMENTATION_NAME
, m_xCC
)
102 if( impl_checkCancel() )
106 //create the controller(+XWindow)
107 uno::Reference
< frame::XController
> xController
= nullptr;
108 uno::Reference
< awt::XWindow
> xComponentWindow
= nullptr;
111 m_xCC
->getServiceManager()->createInstanceWithContext(
112 CHART_CONTROLLER_SERVICE_IMPLEMENTATION_NAME
,m_xCC
)
115 //!!!it is a special characteristic of the example application
116 //that the controller simultaniously provides the XWindow controller functionality
118 uno::Reference
< awt::XWindow
>( xController
, uno::UNO_QUERY
);
120 if( impl_checkCancel() )
124 //connect frame, controller and model one to each other:
125 if(xController
.is()&&xModel
.is())
127 xModel
->connectController(xController
);
128 xModel
->setCurrentController(xController
);
129 xController
->attachModel(xModel
);
131 xFrame
->setComponent(xComponentWindow
,xController
);
132 //creates the view and menu
133 //for correct menu creation the initialized component must be already set into the frame
134 xController
->attachFrame(xFrame
);
137 // call initNew() or load() at XLoadable
138 if(!bHaveLoadedModel
)
141 utl::MediaDescriptor::const_iterator
aIt( aMediaDescriptor
.find( utl::MediaDescriptor::PROP_URL()));
142 if( aIt
!= aMediaDescriptor
.end())
144 OUString
aURL( (*aIt
).second
.get
< OUString
>());
145 if( aURL
.startsWith( "private:factory/schart" ) )
148 uno::Reference
< frame::XLoadable
> xLoadable( xModel
, uno::UNO_QUERY_THROW
);
149 xLoadable
->initNew();
153 // use the URL as BaseURL, similar to what SfxBaseModel effectively does
156 aMediaDescriptor
[utl::MediaDescriptor::PROP_DOCUMENTBASEURL()] <<= aURL
;
158 aMediaDescriptor
.addInputStream();
159 uno::Sequence
< beans::PropertyValue
> aCompleteMediaDescriptor
;
160 aMediaDescriptor
>> aCompleteMediaDescriptor
;
161 apphelper::MediaDescriptorHelper
aMDHelper( aCompleteMediaDescriptor
);
164 // @todo: replace: aMediaDescriptorHelper.getReducedForModel()
165 uno::Reference
< frame::XLoadable
> xLoadable( xModel
, uno::UNO_QUERY_THROW
);
166 xLoadable
->load( aCompleteMediaDescriptor
);
168 //resize standalone files to get correct size:
169 if( xComponentWindow
.is() && aMDHelper
.ISSET_FilterName
&& aMDHelper
.FilterName
== "StarChart 5.0" )
171 awt::Rectangle
aRect( xComponentWindow
->getPosSize() );
172 xComponentWindow
->setPosSize( aRect
.X
, aRect
.Y
, aRect
.Width
, aRect
.Height
, 0 );
177 catch( const uno::Exception
& )
179 DBG_UNHANDLED_EXCEPTION("chart2");
185 void SAL_CALL
ChartFrameLoader::cancel()
187 m_oCancelFinished
.reset();
188 m_bCancelRequired
= true;
189 m_oCancelFinished
.wait();
190 m_bCancelRequired
= false;
195 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
196 com_sun_star_comp_chart2_ChartFrameLoader_get_implementation(css::uno::XComponentContext
*context
,
197 css::uno::Sequence
<css::uno::Any
> const &)
199 return cppu::acquire(new chart::ChartFrameLoader(context
));
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */