1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ChartFrameloader.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
33 #include "ChartFrameloader.hxx"
34 #include "servicenames.hxx"
35 #include "MediaDescriptorHelper.hxx"
37 #include <comphelper/mediadescriptor.hxx>
38 #include <com/sun/star/document/XImporter.hpp>
39 #include <com/sun/star/document/XFilter.hpp>
40 #include <com/sun/star/frame/XLoadable.hpp>
42 //.............................................................................
45 //.............................................................................
47 using namespace ::com::sun::star
;
49 ChartFrameLoader::ChartFrameLoader(
50 uno::Reference
<uno::XComponentContext
> const & xContext
)
51 : m_bCancelRequired( sal_False
)
54 m_oCancelFinished
.reset();
57 ChartFrameLoader::~ChartFrameLoader()
61 sal_Bool ChartFrameLoader
66 m_oCancelFinished
.set();
72 //-----------------------------------------------------------------
74 //-----------------------------------------------------------------
76 APPHELPER_XSERVICEINFO_IMPL(ChartFrameLoader
,CHART_FRAMELOADER_SERVICE_IMPLEMENTATION_NAME
)
78 uno::Sequence
< rtl::OUString
> ChartFrameLoader
79 ::getSupportedServiceNames_Static()
81 uno::Sequence
< rtl::OUString
> aSNS( 1 );
82 aSNS
.getArray()[ 0 ] = CHART_FRAMELOADER_SERVICE_NAME
;
86 //-----------------------------------------------------------------
87 // frame::XFrameLoader
88 //-----------------------------------------------------------------
90 sal_Bool SAL_CALL ChartFrameLoader
91 ::load( const uno::Sequence
< beans::PropertyValue
>& rMediaDescriptor
92 , const uno::Reference
<frame::XFrame
>& xFrame
)
93 throw (uno::RuntimeException
)
95 //@todo ? need to add as terminate listener to desktop?
97 uno::Reference
< frame::XModel
> xModel
;
98 bool bHaveLoadedModel
= false;
100 comphelper::MediaDescriptor
aMediaDescriptor(rMediaDescriptor
);
102 comphelper::MediaDescriptor::const_iterator
aIt( aMediaDescriptor
.find( aMediaDescriptor
.PROP_MODEL()));
103 if( aIt
!= aMediaDescriptor
.end())
105 xModel
.set( (*aIt
).second
.get
< uno::Reference
< frame::XModel
> >());
106 bHaveLoadedModel
= true;
110 //create and initialize the model
113 //@todo?? load mechanism to cancel during loading of document
115 m_xCC
->getServiceManager()->createInstanceWithContext(
116 CHART_MODEL_SERVICE_IMPLEMENTATION_NAME
, m_xCC
)
119 if( impl_checkCancel() )
123 //create the controller(+XWindow)
124 uno::Reference
< frame::XController
> xController
= NULL
;
125 uno::Reference
< awt::XWindow
> xComponentWindow
= NULL
;
127 xController
= uno::Reference
< frame::XController
>(
128 m_xCC
->getServiceManager()->createInstanceWithContext(
129 CHART_CONTROLLER_SERVICE_IMPLEMENTATION_NAME
,m_xCC
)
132 //!!!it is a special characteristic of the example application
133 //that the controller simultaniously provides the XWindow controller functionality
135 uno::Reference
< awt::XWindow
>( xController
, uno::UNO_QUERY
);
137 if( impl_checkCancel() )
142 //connect frame, controller and model one to each other:
143 if(xController
.is()&&xModel
.is())
145 xModel
->connectController(xController
);
146 xModel
->setCurrentController(xController
);
147 xController
->attachModel(xModel
);
149 xFrame
->setComponent(xComponentWindow
,xController
);
150 //creates the view and menu
151 //for correct menu creation the initialized component must be already set into the frame
152 xController
->attachFrame(xFrame
);
155 // call initNew() or load() at XLoadable
156 if(!bHaveLoadedModel
)
159 comphelper::MediaDescriptor::const_iterator
aIt( aMediaDescriptor
.find( aMediaDescriptor
.PROP_URL()));
160 if( aIt
!= aMediaDescriptor
.end())
162 ::rtl::OUString
aURL( (*aIt
).second
.get
< ::rtl::OUString
>());
163 if( aURL
.matchAsciiL(
164 RTL_CONSTASCII_STRINGPARAM( "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
.equals( C2U("StarChart 5.0")) )
185 awt::Rectangle
aRect( xComponentWindow
->getPosSize() );
187 xComponentWindow
->setPosSize( aRect
.X
, aRect
.Y
, aRect
.Width
, aRect
.Height
, nFlags
);
192 catch( uno::Exception
& ex
)
194 ASSERT_EXCEPTION( ex
);
200 void SAL_CALL ChartFrameLoader
201 ::cancel() throw (uno::RuntimeException
)
203 m_oCancelFinished
.reset();
204 m_bCancelRequired
= sal_True
;
205 m_oCancelFinished
.wait();
206 m_bCancelRequired
= sal_False
;
209 //.............................................................................
211 //.............................................................................