Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / chart2 / inc / ChartModel.hxx
blobee6852ae43387ef29c89b0ee6384beaad61da9d6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_CHART2_INC_CHARTMODEL_HXX
20 #define INCLUDED_CHART2_INC_CHARTMODEL_HXX
22 #include <LifeTime.hxx>
24 #include <com/sun/star/frame/XStorable2.hpp>
25 #include <com/sun/star/util/XModifiable.hpp>
26 #include <com/sun/star/util/XCloseable.hpp>
27 #include <com/sun/star/util/XUpdatable.hpp>
28 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
29 #include <com/sun/star/document/XUndoManagerSupplier.hpp>
30 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31 #include <com/sun/star/lang/XServiceInfo.hpp>
32 #include <com/sun/star/lang/XInitialization.hpp>
33 #include <com/sun/star/util/XCloneable.hpp>
34 #include <com/sun/star/embed/XVisualObject.hpp>
35 #include <com/sun/star/document/XStorageBasedDocument.hpp>
36 #include <com/sun/star/lang/XUnoTunnel.hpp>
37 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
38 #include <com/sun/star/container/XChild.hpp>
39 #include <com/sun/star/chart2/data/XDataSource.hpp>
40 #include <com/sun/star/qa/XDumper.hpp>
42 // public API
43 #include <com/sun/star/chart2/data/XDataReceiver.hpp>
45 #include <com/sun/star/chart2/XChartDocument.hpp>
46 #include <com/sun/star/chart2/XTitled.hpp>
48 #include <com/sun/star/frame/XLoadable.hpp>
49 #include <com/sun/star/datatransfer/XTransferable.hpp>
51 #include <osl/mutex.hxx>
52 #include <rtl/ref.hxx>
53 #include <cppuhelper/implbase.hxx>
54 #include <comphelper/interfacecontainer2.hxx>
55 #include <vcl/GraphicObject.hxx>
57 #include <memory>
59 namespace com { namespace sun { namespace star { namespace awt { class XRequestCallback; } } } }
60 namespace com { namespace sun { namespace star { namespace chart2 { class XChartTypeTemplate; } } } }
61 namespace com { namespace sun { namespace star { namespace chart2 { namespace data { class XDataProvider; } } } } }
62 namespace com { namespace sun { namespace star { namespace document { class XFilter; } } } }
63 namespace com { namespace sun { namespace star { namespace embed { class XStorage; } } } }
64 namespace com { namespace sun { namespace star { namespace frame { class XModel; } } } }
65 namespace com { namespace sun { namespace star { namespace uno { class XComponentContext; } } } }
66 namespace com { namespace sun { namespace star { namespace uno { class XAggregation; } } } }
68 class SvNumberFormatter;
70 namespace chart
73 namespace impl
76 // Note: needed for queryInterface (if it calls the base-class implementation)
77 typedef cppu::WeakImplHelper<
78 // css::frame::XModel //comprehends XComponent (required interface), base of XChartDocument
79 css::util::XCloseable //comprehends XCloseBroadcaster
80 ,css::frame::XStorable2 //(extension of XStorable)
81 ,css::util::XModifiable //comprehends XModifyBroadcaster (required interface)
82 ,css::lang::XServiceInfo
83 ,css::lang::XInitialization
84 ,css::chart2::XChartDocument // derived from XModel
85 ,css::chart2::data::XDataReceiver // public API
86 ,css::chart2::XTitled
87 ,css::frame::XLoadable
88 ,css::util::XCloneable
89 ,css::embed::XVisualObject
90 ,css::lang::XMultiServiceFactory
91 ,css::document::XStorageBasedDocument
92 ,css::lang::XUnoTunnel
93 ,css::util::XNumberFormatsSupplier
94 ,css::container::XChild
95 ,css::util::XModifyListener
96 ,css::datatransfer::XTransferable
97 ,css::document::XDocumentPropertiesSupplier
98 ,css::chart2::data::XDataSource
99 ,css::document::XUndoManagerSupplier
100 ,css::util::XUpdatable
101 ,css::qa::XDumper
103 ChartModel_Base;
106 class UndoManager;
107 class ChartView;
109 class OOO_DLLPUBLIC_CHARTTOOLS ChartModel : public impl::ChartModel_Base
112 private:
113 mutable ::apphelper::CloseableLifeTimeManager m_aLifeTimeManager;
115 mutable ::osl::Mutex m_aModelMutex;
116 bool volatile m_bReadOnly;
117 bool volatile m_bModified;
118 sal_Int32 m_nInLoad;
119 bool volatile m_bUpdateNotificationsPending;
121 bool mbTimeBased;
123 rtl::Reference<ChartView> mxChartView;
125 OUString m_aResource;
126 css::uno::Sequence< css::beans::PropertyValue > m_aMediaDescriptor;
127 css::uno::Reference< css::document::XDocumentProperties > m_xDocumentProperties;
128 ::rtl::Reference< UndoManager > m_pUndoManager;
130 ::comphelper::OInterfaceContainerHelper2 m_aControllers;
131 css::uno::Reference< css::frame::XController > m_xCurrentController;
132 sal_uInt16 m_nControllerLockCount;
134 css::uno::Reference< css::uno::XComponentContext > m_xContext;
135 css::uno::Reference< css::uno::XAggregation > m_xOldModelAgg;
137 css::uno::Reference< css::embed::XStorage > m_xStorage;
138 //the content of this should be always synchronized with the current m_xViewWindow size. The variable is necessary to hold the information as long as no view window exists.
139 css::awt::Size m_aVisualAreaSize;
140 css::uno::Reference< css::frame::XModel > m_xParent;
141 css::uno::Reference< css::chart2::data::XRangeHighlighter > m_xRangeHighlighter;
142 css::uno::Reference<css::awt::XRequestCallback> m_xPopupRequest;
143 std::vector< GraphicObject > m_aGraphicObjectVector;
145 css::uno::Reference< css::chart2::data::XDataProvider > m_xDataProvider;
146 /** is only valid if m_xDataProvider is set. If m_xDataProvider is set to an
147 external data provider this reference must be set to 0
149 css::uno::Reference< css::chart2::data::XDataProvider > m_xInternalDataProvider;
151 css::uno::Reference< css::util::XNumberFormatsSupplier >
152 m_xOwnNumberFormatsSupplier;
153 css::uno::Reference< css::util::XNumberFormatsSupplier >
154 m_xNumberFormatsSupplier;
155 std::unique_ptr< SvNumberFormatter > m_apSvNumberFormatter; // #i113784# avoid memory leak
157 css::uno::Reference< css::chart2::XChartTypeManager >
158 m_xChartTypeManager;
160 // Diagram Access
161 css::uno::Reference< css::chart2::XDiagram >
162 m_xDiagram;
164 css::uno::Reference< css::chart2::XTitle >
165 m_xTitle;
167 css::uno::Reference< css::beans::XPropertySet >
168 m_xPageBackground;
170 css::uno::Reference< css::container::XNameAccess> m_xXMLNamespaceMap;
172 private:
173 //private methods
175 OUString impl_g_getLocation();
177 bool
178 impl_isControllerConnected( const css::uno::Reference< com::sun::star::frame::XController >& xController );
180 /// @throws css::uno::RuntimeException
181 css::uno::Reference< css::frame::XController >
182 impl_getCurrentController();
184 /// @throws css::uno::RuntimeException
185 void
186 impl_notifyModifiedListeners();
187 /// @throws css::uno::RuntimeException
188 void
189 impl_notifyCloseListeners();
190 /// @throws css::uno::RuntimeException
191 void
192 impl_notifyStorageChangeListeners();
194 void impl_store(
195 const css::uno::Sequence< css::beans::PropertyValue >& rMediaDescriptor,
196 const css::uno::Reference< css::embed::XStorage > & xStorage );
197 void impl_load(
198 const css::uno::Sequence< css::beans::PropertyValue >& rMediaDescriptor,
199 const css::uno::Reference< css::embed::XStorage >& xStorage );
200 void impl_loadGraphics(
201 const css::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage );
202 css::uno::Reference< css::document::XFilter >
203 impl_createFilter( const css::uno::Sequence< css::beans::PropertyValue > & rMediaDescriptor );
205 css::uno::Reference< css::chart2::XChartTypeTemplate > impl_createDefaultChartTypeTemplate();
206 css::uno::Reference< css::chart2::data::XDataSource > impl_createDefaultData();
208 void impl_adjustAdditionalShapesPositionAndSize(
209 const css::awt::Size& aVisualAreaSize );
211 void insertDefaultChart();
213 public:
214 ChartModel() = delete;
215 ChartModel(css::uno::Reference< css::uno::XComponentContext > const & xContext);
216 explicit ChartModel( const ChartModel & rOther );
217 virtual ~ChartModel() override;
219 // css::lang::XServiceInfo
221 virtual OUString SAL_CALL getImplementationName() override;
222 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
223 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
225 // css::lang::XInitialization
226 virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
228 // css::frame::XModel (required interface)
230 virtual sal_Bool SAL_CALL
231 attachResource( const OUString& rURL,
232 const css::uno::Sequence< css::beans::PropertyValue >& rMediaDescriptor ) override;
234 virtual OUString SAL_CALL
235 getURL() override;
237 virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL
238 getArgs() override;
240 virtual void SAL_CALL
241 connectController( const css::uno::Reference< css::frame::XController >& xController ) override;
243 virtual void SAL_CALL
244 disconnectController( const css::uno::Reference< css::frame::XController >& xController ) override;
246 virtual void SAL_CALL
247 lockControllers() override;
249 virtual void SAL_CALL
250 unlockControllers() override;
252 virtual sal_Bool SAL_CALL
253 hasControllersLocked() override;
255 virtual css::uno::Reference< css::frame::XController > SAL_CALL
256 getCurrentController() override;
258 virtual void SAL_CALL
259 setCurrentController( const css::uno::Reference< css::frame::XController >& xController ) override;
261 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL
262 getCurrentSelection() override;
264 // css::lang::XComponent (base of XModel)
265 virtual void SAL_CALL
266 dispose() override;
268 virtual void SAL_CALL
269 addEventListener( const css::uno::Reference< css::lang::XEventListener > & xListener ) override;
271 virtual void SAL_CALL
272 removeEventListener( const css::uno::Reference< css::lang::XEventListener > & xListener ) override;
274 // css::util::XCloseable
275 virtual void SAL_CALL
276 close( sal_Bool bDeliverOwnership ) override;
278 // css::util::XCloseBroadcaster (base of XCloseable)
279 virtual void SAL_CALL
280 addCloseListener( const css::uno::Reference< css::util::XCloseListener > & xListener ) override;
282 virtual void SAL_CALL
283 removeCloseListener( const css::uno::Reference< css::util::XCloseListener > & xListener ) override;
285 // css::frame::XStorable2 (extension of XStorable)
286 virtual void SAL_CALL storeSelf(
287 const css::uno::Sequence< css::beans::PropertyValue >& rMediaDescriptor ) override;
289 // css::frame::XStorable (required interface)
290 virtual sal_Bool SAL_CALL
291 hasLocation() override;
293 virtual OUString SAL_CALL
294 getLocation() override;
296 virtual sal_Bool SAL_CALL
297 isReadonly() override;
299 virtual void SAL_CALL
300 store() override;
302 virtual void SAL_CALL
303 storeAsURL( const OUString& rURL,
304 const css::uno::Sequence< css::beans::PropertyValue >& rMediaDescriptor ) override;
306 virtual void SAL_CALL
307 storeToURL( const OUString& rURL,
308 const css::uno::Sequence< css::beans::PropertyValue >& rMediaDescriptor ) override;
310 // css::util::XModifiable (required interface)
311 virtual sal_Bool SAL_CALL
312 isModified() override;
314 virtual void SAL_CALL
315 setModified( sal_Bool bModified ) override;
317 // css::util::XModifyBroadcaster (base of XModifiable)
318 virtual void SAL_CALL
319 addModifyListener( const css::uno::Reference< css::util::XModifyListener >& xListener ) override;
321 virtual void SAL_CALL
322 removeModifyListener( const css::uno::Reference< css::util::XModifyListener >& xListener ) override;
324 // ____ XModifyListener ____
325 virtual void SAL_CALL modified(
326 const css::lang::EventObject& aEvent ) override;
328 // ____ XEventListener (base of XModifyListener) ____
329 virtual void SAL_CALL disposing(
330 const css::lang::EventObject& Source ) override;
332 // ____ datatransferable::XTransferable ____
333 virtual css::uno::Any SAL_CALL getTransferData(
334 const css::datatransfer::DataFlavor& aFlavor ) override;
335 virtual css::uno::Sequence< css::datatransfer::DataFlavor > SAL_CALL getTransferDataFlavors() override;
336 virtual sal_Bool SAL_CALL isDataFlavorSupported(
337 const css::datatransfer::DataFlavor& aFlavor ) override;
339 // lang::XTypeProvider (override method of WeakImplHelper)
340 virtual css::uno::Sequence< css::uno::Type > SAL_CALL
341 getTypes() override;
343 // ____ document::XDocumentPropertiesSupplier ____
344 virtual css::uno::Reference< css::document::XDocumentProperties > SAL_CALL
345 getDocumentProperties( ) override;
347 // ____ document::XUndoManagerSupplier ____
348 virtual css::uno::Reference< css::document::XUndoManager > SAL_CALL
349 getUndoManager( ) override;
351 // css::chart2::XChartDocument
352 virtual css::uno::Reference< css::chart2::XDiagram > SAL_CALL
353 getFirstDiagram() override;
354 virtual void SAL_CALL setFirstDiagram(
355 const css::uno::Reference< css::chart2::XDiagram >& xDiagram ) override;
356 virtual void SAL_CALL
357 createInternalDataProvider( sal_Bool bCloneExistingData ) override;
358 virtual sal_Bool SAL_CALL hasInternalDataProvider() override;
359 virtual css::uno::Reference< css::chart2::data::XDataProvider > SAL_CALL
360 getDataProvider() override;
361 virtual void SAL_CALL
362 setChartTypeManager( const css::uno::Reference< css::chart2::XChartTypeManager >& xNewManager ) override;
363 virtual css::uno::Reference< css::chart2::XChartTypeManager > SAL_CALL
364 getChartTypeManager() override;
365 virtual css::uno::Reference< css::beans::XPropertySet > SAL_CALL
366 getPageBackground() override;
368 virtual void SAL_CALL createDefaultChart() override;
370 // ____ XDataReceiver (public API) ____
371 virtual void SAL_CALL
372 attachDataProvider( const css::uno::Reference< css::chart2::data::XDataProvider >& xProvider ) override;
373 virtual void SAL_CALL setArguments(
374 const css::uno::Sequence< css::beans::PropertyValue >& aArguments ) override;
375 virtual css::uno::Sequence< OUString > SAL_CALL getUsedRangeRepresentations() override;
376 virtual css::uno::Reference< css::chart2::data::XDataSource > SAL_CALL getUsedData() override;
377 virtual void SAL_CALL attachNumberFormatsSupplier( const css::uno::Reference<
378 css::util::XNumberFormatsSupplier >& xSupplier ) override;
379 virtual css::uno::Reference< css::chart2::data::XRangeHighlighter > SAL_CALL getRangeHighlighter() override;
380 virtual css::uno::Reference<css::awt::XRequestCallback> SAL_CALL getPopupRequest() override;
382 // ____ XTitled ____
383 virtual css::uno::Reference< css::chart2::XTitle > SAL_CALL getTitleObject() override;
384 virtual void SAL_CALL setTitleObject( const css::uno::Reference< css::chart2::XTitle >& Title ) override;
386 // ____ XInterface (for old API wrapper) ____
387 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override;
389 // ____ XLoadable ____
390 virtual void SAL_CALL initNew() override;
391 virtual void SAL_CALL load( const css::uno::Sequence< css::beans::PropertyValue >& rMediaDescriptor ) override;
393 // ____ XCloneable ____
394 virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override;
396 // ____ XVisualObject ____
397 virtual void SAL_CALL setVisualAreaSize(
398 ::sal_Int64 nAspect,
399 const css::awt::Size& aSize ) override;
400 virtual css::awt::Size SAL_CALL getVisualAreaSize(
401 ::sal_Int64 nAspect ) override;
402 virtual css::embed::VisualRepresentation SAL_CALL getPreferredVisualRepresentation(
403 ::sal_Int64 nAspect ) override;
404 virtual ::sal_Int32 SAL_CALL getMapUnit(
405 ::sal_Int64 nAspect ) override;
407 // ____ XMultiServiceFactory ____
408 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL
409 createInstance( const OUString& aServiceSpecifier ) override;
410 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL
411 createInstanceWithArguments( const OUString& ServiceSpecifier
412 , const css::uno::Sequence< css::uno::Any >& Arguments ) override;
413 virtual css::uno::Sequence< OUString > SAL_CALL
414 getAvailableServiceNames() override;
416 // ____ XStorageBasedDocument ____
417 virtual void SAL_CALL loadFromStorage(
418 const css::uno::Reference< css::embed::XStorage >& xStorage,
419 const css::uno::Sequence< css::beans::PropertyValue >& rMediaDescriptor ) override;
420 virtual void SAL_CALL storeToStorage(
421 const css::uno::Reference< css::embed::XStorage >& xStorage,
422 const css::uno::Sequence< css::beans::PropertyValue >& rMediaDescriptor ) override;
423 virtual void SAL_CALL switchToStorage(
424 const css::uno::Reference< css::embed::XStorage >& xStorage ) override;
425 virtual css::uno::Reference< css::embed::XStorage > SAL_CALL getDocumentStorage() override;
426 virtual void SAL_CALL addStorageChangeListener(
427 const css::uno::Reference< css::document::XStorageChangeListener >& xListener ) override;
428 virtual void SAL_CALL removeStorageChangeListener(
429 const css::uno::Reference< css::document::XStorageChangeListener >& xListener ) override;
431 // for SvNumberFormatsSupplierObj
432 // ____ XUnoTunnel ___
433 virtual ::sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< ::sal_Int8 >& aIdentifier ) override;
435 // ____ XNumberFormatsSupplier ____
436 virtual css::uno::Reference< css::beans::XPropertySet > SAL_CALL getNumberFormatSettings() override;
437 virtual css::uno::Reference< css::util::XNumberFormats > SAL_CALL getNumberFormats() override;
439 // ____ XChild ____
440 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getParent() override;
441 virtual void SAL_CALL setParent(
442 const css::uno::Reference< css::uno::XInterface >& Parent ) override;
444 // ____ XDataSource ____ allows access to the currently used data and data ranges
445 virtual css::uno::Sequence< css::uno::Reference< css::chart2::data::XLabeledDataSequence > > SAL_CALL getDataSequences() override;
447 // XUpdatable
448 virtual void SAL_CALL update() override;
450 // XDumper
451 virtual OUString SAL_CALL dump() override;
453 // normal methods
454 css::uno::Reference< css::util::XNumberFormatsSupplier > const &
455 getNumberFormatsSupplier();
457 css::uno::Reference< css::uno::XInterface > getChartView() const;
459 bool isTimeBased() const { return mbTimeBased;}
461 void setTimeBasedRange(sal_Int32 nStart, sal_Int32 nEnd);
463 bool isDataFromSpreadsheet();
465 bool isDataFromPivotTable() const;
467 void removeDataProviders();
469 private:
470 sal_Int32 mnStart;
471 sal_Int32 mnEnd;
474 } // namespace chart
476 #endif
478 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */