Update ooo320-m1
[ooovba.git] / chart2 / source / controller / main / ChartFrameloader.cxx
blob6f57c9ff073bf4fe952b01c9fdc5f47dcbb4f8d3
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ChartFrameloader.cxx,v $
10 * $Revision: 1.5 $
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"
36 #include "macros.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 //.............................................................................
43 namespace chart
45 //.............................................................................
47 using namespace ::com::sun::star;
49 ChartFrameLoader::ChartFrameLoader(
50 uno::Reference<uno::XComponentContext> const & xContext)
51 : m_bCancelRequired( sal_False )
53 m_xCC = xContext;
54 m_oCancelFinished.reset();
57 ChartFrameLoader::~ChartFrameLoader()
61 sal_Bool ChartFrameLoader
62 ::impl_checkCancel()
64 if(m_bCancelRequired)
66 m_oCancelFinished.set();
67 return sal_True;
69 return sal_False;
72 //-----------------------------------------------------------------
73 // lang::XServiceInfo
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;
83 return aSNS;
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
111 if( ! xModel.is())
113 //@todo?? load mechanism to cancel during loading of document
114 xModel.set(
115 m_xCC->getServiceManager()->createInstanceWithContext(
116 CHART_MODEL_SERVICE_IMPLEMENTATION_NAME, m_xCC )
117 , uno::UNO_QUERY );
119 if( impl_checkCancel() )
120 return sal_False;
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 )
130 , uno::UNO_QUERY );
132 //!!!it is a special characteristic of the example application
133 //that the controller simultaniously provides the XWindow controller functionality
134 xComponentWindow =
135 uno::Reference< awt::XWindow >( xController, uno::UNO_QUERY );
137 if( impl_checkCancel() )
138 return sal_False;
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);
148 if(xFrame.is())
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" )))
166 // create new file
167 uno::Reference< frame::XLoadable > xLoadable( xModel, uno::UNO_QUERY_THROW );
168 xLoadable->initNew();
170 else
172 aMediaDescriptor.addInputStream();
173 uno::Sequence< beans::PropertyValue > aCompleteMediaDescriptor;
174 aMediaDescriptor >> aCompleteMediaDescriptor;
175 apphelper::MediaDescriptorHelper aMDHelper( aCompleteMediaDescriptor );
177 // load file
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() );
186 sal_Int16 nFlags=0;
187 xComponentWindow->setPosSize( aRect.X, aRect.Y, aRect.Width, aRect.Height, nFlags );
192 catch( uno::Exception & ex )
194 ASSERT_EXCEPTION( ex );
197 return sal_True;
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 //.............................................................................
210 } //namespace chart
211 //.............................................................................