/src/libreoffice/chart2/source/controller/main/ChartFrameloader.cxx
Line | Count | Source |
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 <MediaDescriptorHelper.hxx> |
22 | | #include <ChartController.hxx> |
23 | | #include <ChartModel.hxx> |
24 | | #include <unotools/fcm.hxx> |
25 | | #include <unotools/mediadescriptor.hxx> |
26 | | #include <cppuhelper/supportsservice.hxx> |
27 | | #include <com/sun/star/frame/XLoadable.hpp> |
28 | | #include <com/sun/star/uno/XComponentContext.hpp> |
29 | | #include <comphelper/diagnose_ex.hxx> |
30 | | |
31 | | namespace chart |
32 | | { |
33 | | |
34 | | using namespace ::com::sun::star; |
35 | | |
36 | | ChartFrameLoader::ChartFrameLoader( |
37 | | uno::Reference<uno::XComponentContext> const & xContext) |
38 | 0 | : m_bCancelRequired( false ) |
39 | 0 | { |
40 | 0 | m_xCC = xContext; |
41 | 0 | m_oCancelFinished.reset(); |
42 | 0 | } |
43 | | |
44 | | ChartFrameLoader::~ChartFrameLoader() |
45 | 0 | { |
46 | 0 | } |
47 | | |
48 | | bool ChartFrameLoader::impl_checkCancel() |
49 | 0 | { |
50 | 0 | if(m_bCancelRequired) |
51 | 0 | { |
52 | 0 | m_oCancelFinished.set(); |
53 | 0 | return true; |
54 | 0 | } |
55 | 0 | return false; |
56 | 0 | } |
57 | | |
58 | | // lang::XServiceInfo |
59 | | |
60 | | OUString SAL_CALL ChartFrameLoader::getImplementationName() |
61 | 0 | { |
62 | 0 | return u"com.sun.star.comp.chart2.ChartFrameLoader"_ustr; |
63 | 0 | } |
64 | | |
65 | | sal_Bool SAL_CALL ChartFrameLoader::supportsService( const OUString& rServiceName ) |
66 | 0 | { |
67 | 0 | return cppu::supportsService(this, rServiceName); |
68 | 0 | } |
69 | | |
70 | | css::uno::Sequence< OUString > SAL_CALL ChartFrameLoader::getSupportedServiceNames() |
71 | 0 | { |
72 | 0 | return { u"com.sun.star.frame.SynchronousFrameLoader"_ustr }; |
73 | 0 | } |
74 | | |
75 | | // frame::XFrameLoader |
76 | | |
77 | | sal_Bool SAL_CALL ChartFrameLoader::load( const uno::Sequence< beans::PropertyValue >& rMediaDescriptor, const uno::Reference<frame::XFrame >& xFrame ) |
78 | 0 | { |
79 | | //@todo ? need to add as terminate listener to desktop? |
80 | |
|
81 | 0 | uno::Reference< frame::XModel > xModel; |
82 | 0 | bool bHaveLoadedModel = false; |
83 | |
|
84 | 0 | utl::MediaDescriptor aMediaDescriptor(rMediaDescriptor); |
85 | 0 | { |
86 | 0 | utl::MediaDescriptor::const_iterator aIt( aMediaDescriptor.find( utl::MediaDescriptor::PROP_MODEL)); |
87 | 0 | if( aIt != aMediaDescriptor.end()) |
88 | 0 | { |
89 | 0 | xModel.set( (*aIt).second.get< uno::Reference< frame::XModel > >()); |
90 | 0 | bHaveLoadedModel = true; |
91 | 0 | } |
92 | 0 | } |
93 | | |
94 | | //create and initialize the model |
95 | 0 | if( ! xModel.is()) |
96 | 0 | { |
97 | | //@todo?? load mechanism to cancel during loading of document |
98 | 0 | xModel = new ChartModel(m_xCC); |
99 | |
|
100 | 0 | if( impl_checkCancel() ) |
101 | 0 | return false; |
102 | 0 | } |
103 | | |
104 | | //create the controller(+XWindow) |
105 | 0 | rtl::Reference< ChartController > xController = new ChartController(m_xCC); |
106 | |
|
107 | 0 | if( impl_checkCancel() ) |
108 | 0 | return false; |
109 | | |
110 | | //connect frame, controller and model one to each other: |
111 | 0 | if(xModel.is()) |
112 | 0 | { |
113 | 0 | utl::ConnectFrameControllerModel(xFrame, xController, xModel); |
114 | 0 | } |
115 | | |
116 | | // call initNew() or load() at XLoadable |
117 | 0 | if(bHaveLoadedModel) |
118 | 0 | return true; |
119 | | |
120 | 0 | try |
121 | 0 | { |
122 | 0 | utl::MediaDescriptor::const_iterator aIt( aMediaDescriptor.find( utl::MediaDescriptor::PROP_URL)); |
123 | 0 | if( aIt != aMediaDescriptor.end()) |
124 | 0 | { |
125 | 0 | OUString aURL( (*aIt).second.get< OUString >()); |
126 | 0 | if( aURL.startsWith( "private:factory/schart" ) ) |
127 | 0 | { |
128 | | // create new file |
129 | 0 | uno::Reference< frame::XLoadable > xLoadable( xModel, uno::UNO_QUERY_THROW ); |
130 | 0 | xLoadable->initNew(); |
131 | 0 | } |
132 | 0 | else |
133 | 0 | { |
134 | | // use the URL as BaseURL, similar to what SfxBaseModel effectively does |
135 | 0 | if (!aURL.isEmpty()) |
136 | 0 | { |
137 | 0 | aMediaDescriptor[utl::MediaDescriptor::PROP_DOCUMENTBASEURL] <<= aURL; |
138 | 0 | } |
139 | 0 | aMediaDescriptor.addInputStream(); |
140 | 0 | uno::Sequence< beans::PropertyValue > aCompleteMediaDescriptor; |
141 | 0 | aMediaDescriptor >> aCompleteMediaDescriptor; |
142 | 0 | apphelper::MediaDescriptorHelper aMDHelper( aCompleteMediaDescriptor ); |
143 | | |
144 | | // load file |
145 | | // @todo: replace: aMediaDescriptorHelper.getReducedForModel() |
146 | 0 | uno::Reference< frame::XLoadable > xLoadable( xModel, uno::UNO_QUERY_THROW ); |
147 | 0 | xLoadable->load( aCompleteMediaDescriptor ); |
148 | | |
149 | | //resize standalone files to get correct size: |
150 | 0 | if( aMDHelper.ISSET_FilterName && aMDHelper.FilterName == "StarChart 5.0" ) |
151 | 0 | { |
152 | 0 | uno::Reference<awt::XWindow> xComponentWindow = xController->getComponentWindow(); |
153 | 0 | awt::Rectangle aRect( xComponentWindow->getPosSize() ); |
154 | 0 | xComponentWindow->setPosSize( aRect.X, aRect.Y, aRect.Width, aRect.Height, 0 ); |
155 | 0 | } |
156 | 0 | } |
157 | 0 | } |
158 | 0 | } |
159 | 0 | catch( const uno::Exception & ) |
160 | 0 | { |
161 | 0 | DBG_UNHANDLED_EXCEPTION("chart2"); |
162 | 0 | } |
163 | |
|
164 | 0 | return true; |
165 | 0 | } |
166 | | |
167 | | void SAL_CALL ChartFrameLoader::cancel() |
168 | 0 | { |
169 | 0 | m_oCancelFinished.reset(); |
170 | 0 | m_bCancelRequired = true; |
171 | 0 | m_oCancelFinished.wait(); |
172 | 0 | m_bCancelRequired = false; |
173 | 0 | } |
174 | | |
175 | | } //namespace chart |
176 | | |
177 | | extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * |
178 | | com_sun_star_comp_chart2_ChartFrameLoader_get_implementation(css::uno::XComponentContext *context, |
179 | | css::uno::Sequence<css::uno::Any> const &) |
180 | 0 | { |
181 | 0 | return cppu::acquire(new chart::ChartFrameLoader(context)); |
182 | 0 | } |
183 | | |
184 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |