Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : : #include "ChartFrameloader.hxx"
21 : : #include "servicenames.hxx"
22 : : #include "MediaDescriptorHelper.hxx"
23 : : #include "macros.hxx"
24 : : #include <comphelper/mediadescriptor.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 : :
29 : : //.............................................................................
30 : : namespace chart
31 : : {
32 : : //.............................................................................
33 : :
34 : : using namespace ::com::sun::star;
35 : :
36 : 36 : ChartFrameLoader::ChartFrameLoader(
37 : : uno::Reference<uno::XComponentContext> const & xContext)
38 [ + - ]: 36 : : m_bCancelRequired( sal_False )
39 : : {
40 [ + - ]: 36 : m_xCC = xContext;
41 [ + - ]: 36 : m_oCancelFinished.reset();
42 : 36 : }
43 : :
44 [ + - ]: 36 : ChartFrameLoader::~ChartFrameLoader()
45 : : {
46 [ - + ]: 72 : }
47 : :
48 : 66 : sal_Bool ChartFrameLoader
49 : : ::impl_checkCancel()
50 : : {
51 [ - + ]: 66 : if(m_bCancelRequired)
52 : : {
53 : 0 : m_oCancelFinished.set();
54 : 0 : return sal_True;
55 : : }
56 : 66 : return sal_False;
57 : : }
58 : :
59 : : //-----------------------------------------------------------------
60 : : // lang::XServiceInfo
61 : : //-----------------------------------------------------------------
62 : :
63 [ # # ][ # # ]: 32 : APPHELPER_XSERVICEINFO_IMPL(ChartFrameLoader,CHART_FRAMELOADER_SERVICE_IMPLEMENTATION_NAME)
[ # # ][ # # ]
[ # # ]
64 : :
65 : 6 : uno::Sequence< rtl::OUString > ChartFrameLoader
66 : : ::getSupportedServiceNames_Static()
67 : : {
68 : 6 : uno::Sequence< rtl::OUString > aSNS( 1 );
69 [ + - ][ + - ]: 6 : aSNS.getArray()[ 0 ] = CHART_FRAMELOADER_SERVICE_NAME;
70 : 6 : return aSNS;
71 : : }
72 : :
73 : : //-----------------------------------------------------------------
74 : : // frame::XFrameLoader
75 : : //-----------------------------------------------------------------
76 : :
77 : 34 : sal_Bool SAL_CALL ChartFrameLoader
78 : : ::load( const uno::Sequence< beans::PropertyValue >& rMediaDescriptor
79 : : , const uno::Reference<frame::XFrame >& xFrame )
80 : : throw (uno::RuntimeException)
81 : : {
82 : : //@todo ? need to add as terminate listener to desktop?
83 : :
84 : 34 : uno::Reference< frame::XModel > xModel;
85 : 34 : bool bHaveLoadedModel = false;
86 : :
87 [ + - ]: 34 : comphelper::MediaDescriptor aMediaDescriptor(rMediaDescriptor);
88 : : {
89 [ + - ][ + - ]: 34 : comphelper::MediaDescriptor::const_iterator aIt( aMediaDescriptor.find( aMediaDescriptor.PROP_MODEL()));
90 [ + + ][ + - ]: 34 : if( aIt != aMediaDescriptor.end())
91 : : {
92 [ + - ][ + - ]: 2 : xModel.set( (*aIt).second.get< uno::Reference< frame::XModel > >());
[ + - ]
93 : 2 : bHaveLoadedModel = true;
94 : : }
95 : : }
96 : :
97 : : //create and initialize the model
98 [ + + ]: 34 : if( ! xModel.is())
99 : : {
100 : : //@todo?? load mechanism to cancel during loading of document
101 : : xModel.set(
102 [ + - ][ + - ]: 64 : m_xCC->getServiceManager()->createInstanceWithContext(
[ + - ]
103 : 32 : CHART_MODEL_SERVICE_IMPLEMENTATION_NAME, m_xCC )
104 [ + - ][ + - ]: 32 : , uno::UNO_QUERY );
[ + - ]
105 : :
106 [ - + ][ + - ]: 32 : if( impl_checkCancel() )
107 : 0 : return sal_False;
108 : : }
109 : :
110 : : //create the controller(+XWindow)
111 [ + - ]: 34 : uno::Reference< frame::XController > xController = NULL;
112 [ + - ]: 34 : uno::Reference< awt::XWindow > xComponentWindow = NULL;
113 : : {
114 : : xController = uno::Reference< frame::XController >(
115 [ + - ][ + - ]: 68 : m_xCC->getServiceManager()->createInstanceWithContext(
[ + - ]
116 : 34 : CHART_CONTROLLER_SERVICE_IMPLEMENTATION_NAME,m_xCC )
117 [ + - ][ + - ]: 34 : , uno::UNO_QUERY );
[ + - ][ + - ]
118 : :
119 : : //!!!it is a special characteristic of the example application
120 : : //that the controller simultaniously provides the XWindow controller functionality
121 : : xComponentWindow =
122 [ + - ][ + - ]: 34 : uno::Reference< awt::XWindow >( xController, uno::UNO_QUERY );
123 : :
124 [ - + ][ + - ]: 34 : if( impl_checkCancel() )
125 : 0 : return sal_False;
126 : : }
127 : :
128 : :
129 : : //connect frame, controller and model one to each other:
130 [ + - ][ + - ]: 34 : if(xController.is()&&xModel.is())
[ + - ]
131 : : {
132 [ + - ][ + - ]: 34 : xModel->connectController(xController);
133 [ + - ][ + - ]: 34 : xModel->setCurrentController(xController);
134 [ + - ][ + - ]: 34 : xController->attachModel(xModel);
135 [ + - ]: 34 : if(xFrame.is())
136 [ + - ][ + - ]: 34 : xFrame->setComponent(xComponentWindow,xController);
137 : : //creates the view and menu
138 : : //for correct menu creation the initialized component must be already set into the frame
139 [ + - ][ + - ]: 34 : xController->attachFrame(xFrame);
140 : : }
141 : :
142 : : // call initNew() or load() at XLoadable
143 [ + + ]: 34 : if(!bHaveLoadedModel)
144 : : try
145 : : {
146 [ + - ][ + - ]: 32 : comphelper::MediaDescriptor::const_iterator aIt( aMediaDescriptor.find( aMediaDescriptor.PROP_URL()));
147 [ + - ][ + - ]: 32 : if( aIt != aMediaDescriptor.end())
148 : : {
149 [ + - ][ + - ]: 32 : ::rtl::OUString aURL( (*aIt).second.get< ::rtl::OUString >());
150 [ + + ]: 32 : if( aURL.matchAsciiL(
151 : 32 : RTL_CONSTASCII_STRINGPARAM( "private:factory/schart" )))
152 : : {
153 : : // create new file
154 [ + - ]: 26 : uno::Reference< frame::XLoadable > xLoadable( xModel, uno::UNO_QUERY_THROW );
155 [ + - ][ + - ]: 26 : xLoadable->initNew();
156 : : }
157 : : else
158 : : {
159 [ + - ]: 6 : aMediaDescriptor.addInputStream();
160 [ + - ]: 6 : uno::Sequence< beans::PropertyValue > aCompleteMediaDescriptor;
161 [ + - ]: 6 : aMediaDescriptor >> aCompleteMediaDescriptor;
162 [ + - ]: 6 : apphelper::MediaDescriptorHelper aMDHelper( aCompleteMediaDescriptor );
163 : :
164 : : // load file
165 : : // @todo: replace: aMediaDescriptorHelper.getReducedForModel()
166 [ + - ]: 6 : uno::Reference< frame::XLoadable > xLoadable( xModel, uno::UNO_QUERY_THROW );
167 [ + - ][ + - ]: 6 : xLoadable->load( aCompleteMediaDescriptor );
168 : :
169 : : //resize standalone files to get correct size:
170 [ + - ][ + - ]: 6 : if( xComponentWindow.is() && aMDHelper.ISSET_FilterName && aMDHelper.FilterName.equals( C2U("StarChart 5.0")) )
[ + - ][ - + ]
[ + - ]
[ - + # # ]
171 : : {
172 [ # # ][ # # ]: 0 : awt::Rectangle aRect( xComponentWindow->getPosSize() );
173 : 0 : sal_Int16 nFlags=0;
174 [ # # ][ # # ]: 0 : xComponentWindow->setPosSize( aRect.X, aRect.Y, aRect.Width, aRect.Height, nFlags );
175 [ + - ][ + - ]: 6 : }
176 [ # # ]: 32 : }
177 : : }
178 : : }
179 [ # # ]: 0 : catch( const uno::Exception & ex )
180 : : {
181 : : ASSERT_EXCEPTION( ex );
182 : : }
183 : :
184 [ + - ]: 34 : return sal_True;
185 : : }
186 : :
187 : 0 : void SAL_CALL ChartFrameLoader
188 : : ::cancel() throw (uno::RuntimeException)
189 : : {
190 : 0 : m_oCancelFinished.reset();
191 : 0 : m_bCancelRequired = sal_True;
192 : 0 : m_oCancelFinished.wait();
193 : 0 : m_bCancelRequired = sal_False;
194 : 0 : }
195 : :
196 : : //.............................................................................
197 : : } //namespace chart
198 : : //.............................................................................
199 : :
200 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|