Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / chart2 / inc / ChartModel.hxx
blob83dca287277225e67c7dbf37a0a9f4d7c9693da8
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 <config_features.h>
24 #include <LifeTime.hxx>
26 #include <com/sun/star/frame/XModel.hpp>
27 #include <com/sun/star/frame/XStorable2.hpp>
28 #include <com/sun/star/util/XModifiable.hpp>
29 #include <com/sun/star/util/XCloseable.hpp>
30 #include <com/sun/star/util/XUpdatable.hpp>
31 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
32 #include <com/sun/star/document/XUndoManagerSupplier.hpp>
33 #include <com/sun/star/document/XFilter.hpp>
34 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35 #include <com/sun/star/lang/XServiceInfo.hpp>
36 #include <com/sun/star/lang/XInitialization.hpp>
37 #include <com/sun/star/uno/XComponentContext.hpp>
38 #include <com/sun/star/util/XCloneable.hpp>
39 #include <com/sun/star/embed/XVisualObject.hpp>
40 #include <com/sun/star/document/XStorageBasedDocument.hpp>
41 #include <com/sun/star/lang/XUnoTunnel.hpp>
42 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
43 #include <com/sun/star/container/XChild.hpp>
44 #include <com/sun/star/chart2/data/XDataSource.hpp>
45 #include <com/sun/star/chart2/XChartTypeTemplate.hpp>
46 #include <com/sun/star/container/XNameContainer.hpp>
47 #include <com/sun/star/qa/XDumper.hpp>
48 #include <com/sun/star/awt/XRequestCallback.hpp>
50 // public API
51 #include <com/sun/star/chart2/data/XDataProvider.hpp>
52 #include <com/sun/star/chart2/data/XDataReceiver.hpp>
54 #include <com/sun/star/chart2/XChartDocument.hpp>
55 #include <com/sun/star/chart2/XTitled.hpp>
56 #include <com/sun/star/chart2/X3DChartWindowProvider.hpp>
58 #include <com/sun/star/frame/XLoadable.hpp>
59 #include <com/sun/star/embed/XEmbeddedObject.hpp>
60 #include <com/sun/star/embed/XStorage.hpp>
61 #include <com/sun/star/datatransfer/XTransferable.hpp>
63 #include <osl/mutex.hxx>
64 #include <rtl/ref.hxx>
65 #include <cppuhelper/implbase.hxx>
66 #include <comphelper/interfacecontainer2.hxx>
67 #include <vcl/GraphicObject.hxx>
69 #include <memory>
71 class SvNumberFormatter;
72 class OpenGLWindow;
74 namespace chart
77 namespace impl
80 // Note: needed for queryInterface (if it calls the base-class implementation)
81 typedef cppu::WeakImplHelper<
82 // css::frame::XModel //comprehends XComponent (required interface), base of XChartDocument
83 css::util::XCloseable //comprehends XCloseBroadcaster
84 ,css::frame::XStorable2 //(extension of XStorable)
85 ,css::util::XModifiable //comprehends XModifyBroadcaster (required interface)
86 ,css::lang::XServiceInfo
87 ,css::lang::XInitialization
88 ,css::chart2::XChartDocument // derived from XModel
89 ,css::chart2::data::XDataReceiver // public API
90 ,css::chart2::XTitled
91 ,css::frame::XLoadable
92 ,css::util::XCloneable
93 ,css::embed::XVisualObject
94 ,css::lang::XMultiServiceFactory
95 ,css::document::XStorageBasedDocument
96 ,css::lang::XUnoTunnel
97 ,css::util::XNumberFormatsSupplier
98 ,css::container::XChild
99 ,css::util::XModifyListener
100 ,css::datatransfer::XTransferable
101 ,css::document::XDocumentPropertiesSupplier
102 ,css::chart2::data::XDataSource
103 ,css::document::XUndoManagerSupplier
104 ,css::chart2::X3DChartWindowProvider
105 ,css::util::XUpdatable
106 ,css::qa::XDumper
108 ChartModel_Base;
111 class UndoManager;
112 class ChartView;
114 class OOO_DLLPUBLIC_CHARTTOOLS ChartModel : public impl::ChartModel_Base
117 private:
118 mutable ::apphelper::CloseableLifeTimeManager m_aLifeTimeManager;
120 mutable ::osl::Mutex m_aModelMutex;
121 bool volatile m_bReadOnly;
122 bool volatile m_bModified;
123 sal_Int32 m_nInLoad;
124 bool volatile m_bUpdateNotificationsPending;
126 bool mbTimeBased;
128 rtl::Reference<ChartView> mxChartView;
130 OUString m_aResource;
131 css::uno::Sequence< css::beans::PropertyValue > m_aMediaDescriptor;
132 css::uno::Reference< css::document::XDocumentProperties > m_xDocumentProperties;
133 ::rtl::Reference< UndoManager > m_pUndoManager;
135 ::comphelper::OInterfaceContainerHelper2 m_aControllers;
136 css::uno::Reference< css::frame::XController > m_xCurrentController;
137 sal_uInt16 m_nControllerLockCount;
139 css::uno::Reference< css::uno::XComponentContext > m_xContext;
140 css::uno::Reference< css::uno::XAggregation > m_xOldModelAgg;
142 css::uno::Reference< css::embed::XStorage > m_xStorage;
143 //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.
144 css::awt::Size m_aVisualAreaSize;
145 css::uno::Reference< css::frame::XModel > m_xParent;
146 css::uno::Reference< css::chart2::data::XRangeHighlighter > m_xRangeHighlighter;
147 css::uno::Reference<css::awt::XRequestCallback> m_xPopupRequest;
148 std::vector< GraphicObject > m_aGraphicObjectVector;
150 css::uno::Reference< css::chart2::data::XDataProvider > m_xDataProvider;
151 /** is only valid if m_xDataProvider is set. If m_xDataProvider is set to an
152 external data provider this reference must be set to 0
154 css::uno::Reference< css::chart2::data::XDataProvider > m_xInternalDataProvider;
156 css::uno::Reference< css::util::XNumberFormatsSupplier >
157 m_xOwnNumberFormatsSupplier;
158 css::uno::Reference< css::util::XNumberFormatsSupplier >
159 m_xNumberFormatsSupplier;
160 std::unique_ptr< SvNumberFormatter > m_apSvNumberFormatter; // #i113784# avoid memory leak
162 css::uno::Reference< css::chart2::XChartTypeManager >
163 m_xChartTypeManager;
165 // Diagram Access
166 css::uno::Reference< css::chart2::XDiagram >
167 m_xDiagram;
169 css::uno::Reference< css::chart2::XTitle >
170 m_xTitle;
172 css::uno::Reference< css::beans::XPropertySet >
173 m_xPageBackground;
175 css::uno::Reference< css::container::XNameAccess> m_xXMLNamespaceMap;
177 private:
178 //private methods
180 OUString impl_g_getLocation();
182 bool
183 impl_isControllerConnected( const css::uno::Reference< com::sun::star::frame::XController >& xController );
185 /// @throws css::uno::RuntimeException
186 css::uno::Reference< css::frame::XController >
187 impl_getCurrentController();
189 /// @throws css::uno::RuntimeException
190 void
191 impl_notifyModifiedListeners();
192 /// @throws css::uno::RuntimeException
193 void
194 impl_notifyCloseListeners();
195 /// @throws css::uno::RuntimeException
196 void
197 impl_notifyStorageChangeListeners();
199 void impl_store(
200 const css::uno::Sequence< css::beans::PropertyValue >& rMediaDescriptor,
201 const css::uno::Reference< css::embed::XStorage > & xStorage );
202 void impl_load(
203 const css::uno::Sequence< css::beans::PropertyValue >& rMediaDescriptor,
204 const css::uno::Reference< css::embed::XStorage >& xStorage );
205 void impl_loadGraphics(
206 const css::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage );
207 css::uno::Reference< css::document::XFilter >
208 impl_createFilter( const css::uno::Sequence< css::beans::PropertyValue > & rMediaDescriptor );
210 css::uno::Reference< css::chart2::XChartTypeTemplate > impl_createDefaultChartTypeTemplate();
211 css::uno::Reference< css::chart2::data::XDataSource > impl_createDefaultData();
213 void impl_adjustAdditionalShapesPositionAndSize(
214 const css::awt::Size& aVisualAreaSize );
216 void insertDefaultChart();
218 public:
219 ChartModel() = delete;
220 ChartModel(css::uno::Reference< css::uno::XComponentContext > const & xContext);
221 explicit ChartModel( const ChartModel & rOther );
222 virtual ~ChartModel() override;
224 // css::lang::XServiceInfo
226 virtual OUString SAL_CALL getImplementationName() override;
227 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
228 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
230 // css::lang::XInitialization
231 virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
233 // css::frame::XModel (required interface)
235 virtual sal_Bool SAL_CALL
236 attachResource( const OUString& rURL,
237 const css::uno::Sequence< css::beans::PropertyValue >& rMediaDescriptor ) override;
239 virtual OUString SAL_CALL
240 getURL() override;
242 virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL
243 getArgs() override;
245 virtual void SAL_CALL
246 connectController( const css::uno::Reference< css::frame::XController >& xController ) override;
248 virtual void SAL_CALL
249 disconnectController( const css::uno::Reference< css::frame::XController >& xController ) override;
251 virtual void SAL_CALL
252 lockControllers() override;
254 virtual void SAL_CALL
255 unlockControllers() override;
257 virtual sal_Bool SAL_CALL
258 hasControllersLocked() override;
260 virtual css::uno::Reference< css::frame::XController > SAL_CALL
261 getCurrentController() override;
263 virtual void SAL_CALL
264 setCurrentController( const css::uno::Reference< css::frame::XController >& xController ) override;
266 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL
267 getCurrentSelection() override;
269 // css::lang::XComponent (base of XModel)
270 virtual void SAL_CALL
271 dispose() override;
273 virtual void SAL_CALL
274 addEventListener( const css::uno::Reference< css::lang::XEventListener > & xListener ) override;
276 virtual void SAL_CALL
277 removeEventListener( const css::uno::Reference< css::lang::XEventListener > & xListener ) override;
279 // css::util::XCloseable
280 virtual void SAL_CALL
281 close( sal_Bool bDeliverOwnership ) override;
283 // css::util::XCloseBroadcaster (base of XCloseable)
284 virtual void SAL_CALL
285 addCloseListener( const css::uno::Reference< css::util::XCloseListener > & xListener ) override;
287 virtual void SAL_CALL
288 removeCloseListener( const css::uno::Reference< css::util::XCloseListener > & xListener ) override;
290 // css::frame::XStorable2 (extension of XStorable)
291 virtual void SAL_CALL storeSelf(
292 const css::uno::Sequence< css::beans::PropertyValue >& rMediaDescriptor ) override;
294 // css::frame::XStorable (required interface)
295 virtual sal_Bool SAL_CALL
296 hasLocation() override;
298 virtual OUString SAL_CALL
299 getLocation() override;
301 virtual sal_Bool SAL_CALL
302 isReadonly() override;
304 virtual void SAL_CALL
305 store() override;
307 virtual void SAL_CALL
308 storeAsURL( const OUString& rURL,
309 const css::uno::Sequence< css::beans::PropertyValue >& rMediaDescriptor ) override;
311 virtual void SAL_CALL
312 storeToURL( const OUString& rURL,
313 const css::uno::Sequence< css::beans::PropertyValue >& rMediaDescriptor ) override;
315 // css::util::XModifiable (required interface)
316 virtual sal_Bool SAL_CALL
317 isModified() override;
319 virtual void SAL_CALL
320 setModified( sal_Bool bModified ) override;
322 // css::util::XModifyBroadcaster (base of XModifiable)
323 virtual void SAL_CALL
324 addModifyListener( const css::uno::Reference< css::util::XModifyListener >& xListener ) override;
326 virtual void SAL_CALL
327 removeModifyListener( const css::uno::Reference< css::util::XModifyListener >& xListener ) override;
329 // ____ XModifyListener ____
330 virtual void SAL_CALL modified(
331 const css::lang::EventObject& aEvent ) override;
333 // ____ XEventListener (base of XModifyListener) ____
334 virtual void SAL_CALL disposing(
335 const css::lang::EventObject& Source ) override;
337 // ____ datatransferable::XTransferable ____
338 virtual css::uno::Any SAL_CALL getTransferData(
339 const css::datatransfer::DataFlavor& aFlavor ) override;
340 virtual css::uno::Sequence< css::datatransfer::DataFlavor > SAL_CALL getTransferDataFlavors() override;
341 virtual sal_Bool SAL_CALL isDataFlavorSupported(
342 const css::datatransfer::DataFlavor& aFlavor ) override;
344 // lang::XTypeProvider (override method of WeakImplHelper)
345 virtual css::uno::Sequence< css::uno::Type > SAL_CALL
346 getTypes() override;
348 // ____ document::XDocumentPropertiesSupplier ____
349 virtual css::uno::Reference< css::document::XDocumentProperties > SAL_CALL
350 getDocumentProperties( ) override;
352 // ____ document::XUndoManagerSupplier ____
353 virtual css::uno::Reference< css::document::XUndoManager > SAL_CALL
354 getUndoManager( ) override;
356 // css::chart2::XChartDocument
357 virtual css::uno::Reference< css::chart2::XDiagram > SAL_CALL
358 getFirstDiagram() override;
359 virtual void SAL_CALL setFirstDiagram(
360 const css::uno::Reference< css::chart2::XDiagram >& xDiagram ) override;
361 virtual void SAL_CALL
362 createInternalDataProvider( sal_Bool bCloneExistingData ) override;
363 virtual sal_Bool SAL_CALL hasInternalDataProvider() override;
364 virtual css::uno::Reference< css::chart2::data::XDataProvider > SAL_CALL
365 getDataProvider() override;
366 virtual void SAL_CALL
367 setChartTypeManager( const css::uno::Reference< css::chart2::XChartTypeManager >& xNewManager ) override;
368 virtual css::uno::Reference< css::chart2::XChartTypeManager > SAL_CALL
369 getChartTypeManager() override;
370 virtual css::uno::Reference< css::beans::XPropertySet > SAL_CALL
371 getPageBackground() override;
373 virtual void SAL_CALL createDefaultChart() override;
375 virtual sal_Bool SAL_CALL isOpenGLChart() override;
377 // ____ XDataReceiver (public API) ____
378 virtual void SAL_CALL
379 attachDataProvider( const css::uno::Reference< css::chart2::data::XDataProvider >& xProvider ) override;
380 virtual void SAL_CALL setArguments(
381 const css::uno::Sequence< css::beans::PropertyValue >& aArguments ) override;
382 virtual css::uno::Sequence< OUString > SAL_CALL getUsedRangeRepresentations() override;
383 virtual css::uno::Reference< css::chart2::data::XDataSource > SAL_CALL getUsedData() override;
384 virtual void SAL_CALL attachNumberFormatsSupplier( const css::uno::Reference<
385 css::util::XNumberFormatsSupplier >& xSupplier ) override;
386 virtual css::uno::Reference< css::chart2::data::XRangeHighlighter > SAL_CALL getRangeHighlighter() override;
387 virtual css::uno::Reference<css::awt::XRequestCallback> SAL_CALL getPopupRequest() override;
389 // ____ XTitled ____
390 virtual css::uno::Reference< css::chart2::XTitle > SAL_CALL getTitleObject() override;
391 virtual void SAL_CALL setTitleObject( const css::uno::Reference< css::chart2::XTitle >& Title ) override;
393 // ____ XInterface (for old API wrapper) ____
394 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override;
396 // ____ XLoadable ____
397 virtual void SAL_CALL initNew() override;
398 virtual void SAL_CALL load( const css::uno::Sequence< css::beans::PropertyValue >& rMediaDescriptor ) override;
400 // ____ XCloneable ____
401 virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override;
403 // ____ XVisualObject ____
404 virtual void SAL_CALL setVisualAreaSize(
405 ::sal_Int64 nAspect,
406 const css::awt::Size& aSize ) override;
407 virtual css::awt::Size SAL_CALL getVisualAreaSize(
408 ::sal_Int64 nAspect ) override;
409 virtual css::embed::VisualRepresentation SAL_CALL getPreferredVisualRepresentation(
410 ::sal_Int64 nAspect ) override;
411 virtual ::sal_Int32 SAL_CALL getMapUnit(
412 ::sal_Int64 nAspect ) override;
414 // ____ XMultiServiceFactory ____
415 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL
416 createInstance( const OUString& aServiceSpecifier ) override;
417 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL
418 createInstanceWithArguments( const OUString& ServiceSpecifier
419 , const css::uno::Sequence< css::uno::Any >& Arguments ) override;
420 virtual css::uno::Sequence< OUString > SAL_CALL
421 getAvailableServiceNames() override;
423 // ____ XStorageBasedDocument ____
424 virtual void SAL_CALL loadFromStorage(
425 const css::uno::Reference< css::embed::XStorage >& xStorage,
426 const css::uno::Sequence< css::beans::PropertyValue >& rMediaDescriptor ) override;
427 virtual void SAL_CALL storeToStorage(
428 const css::uno::Reference< css::embed::XStorage >& xStorage,
429 const css::uno::Sequence< css::beans::PropertyValue >& rMediaDescriptor ) override;
430 virtual void SAL_CALL switchToStorage(
431 const css::uno::Reference< css::embed::XStorage >& xStorage ) override;
432 virtual css::uno::Reference< css::embed::XStorage > SAL_CALL getDocumentStorage() override;
433 virtual void SAL_CALL addStorageChangeListener(
434 const css::uno::Reference< css::document::XStorageChangeListener >& xListener ) override;
435 virtual void SAL_CALL removeStorageChangeListener(
436 const css::uno::Reference< css::document::XStorageChangeListener >& xListener ) override;
438 // for SvNumberFormatsSupplierObj
439 // ____ XUnoTunnel ___
440 virtual ::sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< ::sal_Int8 >& aIdentifier ) override;
442 // ____ XNumberFormatsSupplier ____
443 virtual css::uno::Reference< css::beans::XPropertySet > SAL_CALL getNumberFormatSettings() override;
444 virtual css::uno::Reference< css::util::XNumberFormats > SAL_CALL getNumberFormats() override;
446 // ____ XChild ____
447 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getParent() override;
448 virtual void SAL_CALL setParent(
449 const css::uno::Reference< css::uno::XInterface >& Parent ) override;
451 // ____ XDataSource ____ allows access to the currently used data and data ranges
452 virtual css::uno::Sequence< css::uno::Reference< css::chart2::data::XLabeledDataSequence > > SAL_CALL getDataSequences() override;
454 // X3DChartWindowProvider
455 virtual void SAL_CALL setWindow( sal_uInt64 nWindowPtr ) override;
457 // XUpdatable
458 virtual void SAL_CALL update() override;
460 // XDumper
461 virtual OUString SAL_CALL dump() override;
463 // normal methods
464 css::uno::Reference< css::util::XNumberFormatsSupplier > const &
465 getNumberFormatsSupplier();
467 css::uno::Reference< css::uno::XInterface > getChartView() const;
469 bool isTimeBased() const { return mbTimeBased;}
471 void setTimeBasedRange(sal_Int32 nStart, sal_Int32 nEnd);
473 bool isDataFromSpreadsheet();
475 bool isDataFromPivotTable();
477 void removeDataProviders();
479 #if HAVE_FEATURE_OPENGL
480 OpenGLWindow* getOpenGLWindow() { return mpOpenGLWindow;}
481 #endif
483 private:
484 sal_Int32 mnStart;
485 sal_Int32 mnEnd;
486 #if HAVE_FEATURE_OPENGL
487 VclPtr<OpenGLWindow> mpOpenGLWindow;
488 #endif
491 } // namespace chart
493 #endif
495 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */