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"
24 #include <unotools/mediadescriptor.hxx>
25 #include <cppuhelper/supportsservice.hxx>
26 #include <com/sun/star/document/XImporter.hpp>
27 #include <com/sun/star/document/XFilter.hpp>
28 #include <com/sun/star/frame/XLoadable.hpp>
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()
52 m_oCancelFinished
.set();
60 OUString SAL_CALL
ChartFrameLoader::getImplementationName()
61 throw( css::uno::RuntimeException
, std::exception
)
63 return getImplementationName_Static();
66 OUString
ChartFrameLoader::getImplementationName_Static()
68 return OUString(CHART_FRAMELOADER_SERVICE_IMPLEMENTATION_NAME
);
71 sal_Bool SAL_CALL
ChartFrameLoader::supportsService( const OUString
& rServiceName
)
72 throw( css::uno::RuntimeException
, std::exception
)
74 return cppu::supportsService(this, rServiceName
);
77 css::uno::Sequence
< OUString
> SAL_CALL
ChartFrameLoader::getSupportedServiceNames()
78 throw( css::uno::RuntimeException
, std::exception
)
80 return getSupportedServiceNames_Static();
83 uno::Sequence
< OUString
> ChartFrameLoader::getSupportedServiceNames_Static()
85 uno::Sequence
< OUString
> aSNS( 1 );
86 aSNS
.getArray()[ 0 ] = CHART_FRAMELOADER_SERVICE_NAME
;
90 // frame::XFrameLoader
92 sal_Bool SAL_CALL ChartFrameLoader
93 ::load( const uno::Sequence
< beans::PropertyValue
>& rMediaDescriptor
94 , const uno::Reference
<frame::XFrame
>& xFrame
)
95 throw (uno::RuntimeException
, std::exception
)
97 //@todo ? need to add as terminate listener to desktop?
99 uno::Reference
< frame::XModel
> xModel
;
100 bool bHaveLoadedModel
= false;
102 utl::MediaDescriptor
aMediaDescriptor(rMediaDescriptor
);
104 utl::MediaDescriptor::const_iterator
aIt( aMediaDescriptor
.find( utl::MediaDescriptor::PROP_MODEL()));
105 if( aIt
!= aMediaDescriptor
.end())
107 xModel
.set( (*aIt
).second
.get
< uno::Reference
< frame::XModel
> >());
108 bHaveLoadedModel
= true;
112 //create and initialize the model
115 //@todo?? load mechanism to cancel during loading of document
117 m_xCC
->getServiceManager()->createInstanceWithContext(
118 CHART_MODEL_SERVICE_IMPLEMENTATION_NAME
, m_xCC
)
121 if( impl_checkCancel() )
125 //create the controller(+XWindow)
126 uno::Reference
< frame::XController
> xController
= NULL
;
127 uno::Reference
< awt::XWindow
> xComponentWindow
= NULL
;
129 xController
= uno::Reference
< frame::XController
>(
130 m_xCC
->getServiceManager()->createInstanceWithContext(
131 CHART_CONTROLLER_SERVICE_IMPLEMENTATION_NAME
,m_xCC
)
134 //!!!it is a special characteristic of the example application
135 //that the controller simultaniously provides the XWindow controller functionality
137 uno::Reference
< awt::XWindow
>( xController
, uno::UNO_QUERY
);
139 if( impl_checkCancel() )
143 //connect frame, controller and model one to each other:
144 if(xController
.is()&&xModel
.is())
146 xModel
->connectController(xController
);
147 xModel
->setCurrentController(xController
);
148 xController
->attachModel(xModel
);
150 xFrame
->setComponent(xComponentWindow
,xController
);
151 //creates the view and menu
152 //for correct menu creation the initialized component must be already set into the frame
153 xController
->attachFrame(xFrame
);
156 // call initNew() or load() at XLoadable
157 if(!bHaveLoadedModel
)
160 utl::MediaDescriptor::const_iterator
aIt( aMediaDescriptor
.find( utl::MediaDescriptor::PROP_URL()));
161 if( aIt
!= aMediaDescriptor
.end())
163 OUString
aURL( (*aIt
).second
.get
< OUString
>());
164 if( aURL
.startsWith( "private:factory/schart" ) )
167 uno::Reference
< frame::XLoadable
> xLoadable( xModel
, uno::UNO_QUERY_THROW
);
168 xLoadable
->initNew();
172 aMediaDescriptor
.addInputStream();
173 uno::Sequence
< beans::PropertyValue
> aCompleteMediaDescriptor
;
174 aMediaDescriptor
>> aCompleteMediaDescriptor
;
175 apphelper::MediaDescriptorHelper
aMDHelper( aCompleteMediaDescriptor
);
178 // @todo: replace: aMediaDescriptorHelper.getReducedForModel()
179 uno::Reference
< frame::XLoadable
> xLoadable( xModel
, uno::UNO_QUERY_THROW
);
180 xLoadable
->load( aCompleteMediaDescriptor
);
182 //resize standalone files to get correct size:
183 if( xComponentWindow
.is() && aMDHelper
.ISSET_FilterName
&& aMDHelper
.FilterName
== "StarChart 5.0" )
185 awt::Rectangle
aRect( xComponentWindow
->getPosSize() );
187 xComponentWindow
->setPosSize( aRect
.X
, aRect
.Y
, aRect
.Width
, aRect
.Height
, nFlags
);
192 catch( const uno::Exception
& ex
)
194 ASSERT_EXCEPTION( ex
);
200 void SAL_CALL ChartFrameLoader
201 ::cancel() throw (uno::RuntimeException
, std::exception
)
203 m_oCancelFinished
.reset();
204 m_bCancelRequired
= true;
205 m_oCancelFinished
.wait();
206 m_bCancelRequired
= false;
211 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
* SAL_CALL
212 com_sun_star_comp_chart2_ChartFrameLoader_get_implementation(css::uno::XComponentContext
*context
,
213 css::uno::Sequence
<css::uno::Any
> const &)
215 return cppu::acquire(new chart::ChartFrameLoader(context
));
218 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */