1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "ChartFrameloader.hxx"
30 #include "servicenames.hxx"
31 #include "MediaDescriptorHelper.hxx"
33 #include <comphelper/mediadescriptor.hxx>
34 #include <com/sun/star/document/XImporter.hpp>
35 #include <com/sun/star/document/XFilter.hpp>
36 #include <com/sun/star/frame/XLoadable.hpp>
38 //.............................................................................
41 //.............................................................................
43 using namespace ::com::sun::star
;
45 ChartFrameLoader::ChartFrameLoader(
46 uno::Reference
<uno::XComponentContext
> const & xContext
)
47 : m_bCancelRequired( sal_False
)
50 m_oCancelFinished
.reset();
53 ChartFrameLoader::~ChartFrameLoader()
57 sal_Bool ChartFrameLoader
62 m_oCancelFinished
.set();
68 //-----------------------------------------------------------------
70 //-----------------------------------------------------------------
72 APPHELPER_XSERVICEINFO_IMPL(ChartFrameLoader
,CHART_FRAMELOADER_SERVICE_IMPLEMENTATION_NAME
)
74 uno::Sequence
< rtl::OUString
> ChartFrameLoader
75 ::getSupportedServiceNames_Static()
77 uno::Sequence
< rtl::OUString
> aSNS( 1 );
78 aSNS
.getArray()[ 0 ] = CHART_FRAMELOADER_SERVICE_NAME
;
82 //-----------------------------------------------------------------
83 // frame::XFrameLoader
84 //-----------------------------------------------------------------
86 sal_Bool SAL_CALL ChartFrameLoader
87 ::load( const uno::Sequence
< beans::PropertyValue
>& rMediaDescriptor
88 , const uno::Reference
<frame::XFrame
>& xFrame
)
89 throw (uno::RuntimeException
)
91 //@todo ? need to add as terminate listener to desktop?
93 uno::Reference
< frame::XModel
> xModel
;
94 bool bHaveLoadedModel
= false;
96 comphelper::MediaDescriptor
aMediaDescriptor(rMediaDescriptor
);
98 comphelper::MediaDescriptor::const_iterator
aIt( aMediaDescriptor
.find( aMediaDescriptor
.PROP_MODEL()));
99 if( aIt
!= aMediaDescriptor
.end())
101 xModel
.set( (*aIt
).second
.get
< uno::Reference
< frame::XModel
> >());
102 bHaveLoadedModel
= true;
106 //create and initialize the model
109 //@todo?? load mechanism to cancel during loading of document
111 m_xCC
->getServiceManager()->createInstanceWithContext(
112 CHART_MODEL_SERVICE_IMPLEMENTATION_NAME
, m_xCC
)
115 if( impl_checkCancel() )
119 //create the controller(+XWindow)
120 uno::Reference
< frame::XController
> xController
= NULL
;
121 uno::Reference
< awt::XWindow
> xComponentWindow
= NULL
;
123 xController
= uno::Reference
< frame::XController
>(
124 m_xCC
->getServiceManager()->createInstanceWithContext(
125 CHART_CONTROLLER_SERVICE_IMPLEMENTATION_NAME
,m_xCC
)
128 //!!!it is a special characteristic of the example application
129 //that the controller simultaniously provides the XWindow controller functionality
131 uno::Reference
< awt::XWindow
>( xController
, uno::UNO_QUERY
);
133 if( impl_checkCancel() )
138 //connect frame, controller and model one to each other:
139 if(xController
.is()&&xModel
.is())
141 xModel
->connectController(xController
);
142 xModel
->setCurrentController(xController
);
143 xController
->attachModel(xModel
);
145 xFrame
->setComponent(xComponentWindow
,xController
);
146 //creates the view and menu
147 //for correct menu creation the initialized component must be already set into the frame
148 xController
->attachFrame(xFrame
);
151 // call initNew() or load() at XLoadable
152 if(!bHaveLoadedModel
)
155 comphelper::MediaDescriptor::const_iterator
aIt( aMediaDescriptor
.find( aMediaDescriptor
.PROP_URL()));
156 if( aIt
!= aMediaDescriptor
.end())
158 ::rtl::OUString
aURL( (*aIt
).second
.get
< ::rtl::OUString
>());
159 if( aURL
.matchAsciiL(
160 RTL_CONSTASCII_STRINGPARAM( "private:factory/schart" )))
163 uno::Reference
< frame::XLoadable
> xLoadable( xModel
, uno::UNO_QUERY_THROW
);
164 xLoadable
->initNew();
168 aMediaDescriptor
.addInputStream();
169 uno::Sequence
< beans::PropertyValue
> aCompleteMediaDescriptor
;
170 aMediaDescriptor
>> aCompleteMediaDescriptor
;
171 apphelper::MediaDescriptorHelper
aMDHelper( aCompleteMediaDescriptor
);
174 // @todo: replace: aMediaDescriptorHelper.getReducedForModel()
175 uno::Reference
< frame::XLoadable
> xLoadable( xModel
, uno::UNO_QUERY_THROW
);
176 xLoadable
->load( aCompleteMediaDescriptor
);
178 //resize standalone files to get correct size:
179 if( xComponentWindow
.is() && aMDHelper
.ISSET_FilterName
&& aMDHelper
.FilterName
.equals( C2U("StarChart 5.0")) )
181 awt::Rectangle
aRect( xComponentWindow
->getPosSize() );
183 xComponentWindow
->setPosSize( aRect
.X
, aRect
.Y
, aRect
.Width
, aRect
.Height
, nFlags
);
188 catch( const uno::Exception
& ex
)
190 ASSERT_EXCEPTION( ex
);
196 void SAL_CALL ChartFrameLoader
197 ::cancel() throw (uno::RuntimeException
)
199 m_oCancelFinished
.reset();
200 m_bCancelRequired
= sal_True
;
201 m_oCancelFinished
.wait();
202 m_bCancelRequired
= sal_False
;
205 //.............................................................................
207 //.............................................................................
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */