1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #include <LifeTime.hxx>
23 #include <com/sun/star/frame/XStorable2.hpp>
24 #include <com/sun/star/util/XModifiable.hpp>
25 #include <com/sun/star/util/XCloseable.hpp>
26 #include <com/sun/star/util/XUpdatable.hpp>
27 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
28 #include <com/sun/star/document/XUndoManagerSupplier.hpp>
29 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
30 #include <com/sun/star/lang/XServiceInfo.hpp>
31 #include <com/sun/star/lang/XInitialization.hpp>
32 #include <com/sun/star/util/XCloneable.hpp>
33 #include <com/sun/star/embed/XVisualObject.hpp>
34 #include <com/sun/star/document/XStorageBasedDocument.hpp>
35 #include <com/sun/star/lang/XUnoTunnel.hpp>
36 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
37 #include <com/sun/star/container/XChild.hpp>
38 #include <com/sun/star/chart2/data/XDataSource.hpp>
39 #include <com/sun/star/qa/XDumper.hpp>
42 #include <com/sun/star/chart2/data/XDataReceiver.hpp>
44 #include <com/sun/star/chart2/XChartDocument.hpp>
45 #include <com/sun/star/chart2/XTitled.hpp>
47 #include <com/sun/star/frame/XLoadable.hpp>
48 #include <com/sun/star/datatransfer/XTransferable.hpp>
50 #include <osl/mutex.hxx>
51 #include <rtl/ref.hxx>
52 #include <cppuhelper/implbase.hxx>
53 #include <comphelper/interfacecontainer2.hxx>
54 #include <vcl/GraphicObject.hxx>
58 typedef struct _xmlTextWriter
* xmlTextWriterPtr
;
60 namespace com::sun::star::awt
{ class XRequestCallback
; }
61 namespace com::sun::star::chart2::data
{ class XDataProvider
; }
62 namespace com::sun::star::document
{ class XFilter
; }
63 namespace com::sun::star::embed
{ class XStorage
; }
64 namespace com::sun::star::frame
{ class XModel
; }
65 namespace com::sun::star::uno
{ class XComponentContext
; }
66 namespace com::sun::star::uno
{ class XAggregation
; }
68 class SvNumberFormatter
;
69 class SvNumberFormatsSupplierObj
;
74 class ChartTypeManager
;
75 class ChartTypeTemplate
;
76 class InternalDataProvider
;
79 class RangeHighlighter
;
85 // Note: needed for queryInterface (if it calls the base-class implementation)
86 typedef cppu::WeakImplHelper
<
87 // css::frame::XModel //comprehends XComponent (required interface), base of XChartDocument
88 css::util::XCloseable
//comprehends XCloseBroadcaster
89 ,css::frame::XStorable2
//(extension of XStorable)
90 ,css::util::XModifiable
//comprehends XModifyBroadcaster (required interface)
91 ,css::lang::XServiceInfo
92 ,css::lang::XInitialization
93 ,css::chart2::XChartDocument
// derived from XModel
94 ,css::chart2::data::XDataReceiver
// public API
96 ,css::frame::XLoadable
97 ,css::util::XCloneable
98 ,css::embed::XVisualObject
99 ,css::lang::XMultiServiceFactory
100 ,css::document::XStorageBasedDocument
101 ,css::lang::XUnoTunnel
102 ,css::util::XNumberFormatsSupplier
103 ,css::container::XChild
104 ,css::util::XModifyListener
105 ,css::datatransfer::XTransferable
106 ,css::document::XDocumentPropertiesSupplier
107 ,css::chart2::data::XDataSource
108 ,css::document::XUndoManagerSupplier
109 ,css::util::XUpdatable
118 class OOO_DLLPUBLIC_CHARTTOOLS
SAL_LOPLUGIN_ANNOTATE("crosscast") ChartModel final
:
119 public impl::ChartModel_Base
123 mutable ::apphelper::CloseableLifeTimeManager m_aLifeTimeManager
;
125 mutable ::osl::Mutex m_aModelMutex
;
126 bool volatile m_bReadOnly
;
127 bool volatile m_bModified
;
129 bool volatile m_bUpdateNotificationsPending
;
133 mutable rtl::Reference
<ChartView
> mxChartView
;
135 OUString m_aResource
;
136 css::uno::Sequence
< css::beans::PropertyValue
> m_aMediaDescriptor
;
137 css::uno::Reference
< css::document::XDocumentProperties
> m_xDocumentProperties
;
138 ::rtl::Reference
< UndoManager
> m_pUndoManager
;
140 ::comphelper::OInterfaceContainerHelper2 m_aControllers
;
141 css::uno::Reference
< css::frame::XController
> m_xCurrentController
;
142 sal_uInt16 m_nControllerLockCount
;
144 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
145 css::uno::Reference
< css::uno::XAggregation
> m_xOldModelAgg
;
147 css::uno::Reference
< css::embed::XStorage
> m_xStorage
;
148 //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.
149 css::awt::Size m_aVisualAreaSize
;
150 css::uno::Reference
< css::frame::XModel
> m_xParent
;
151 rtl::Reference
< ::chart::RangeHighlighter
> m_xRangeHighlighter
;
152 css::uno::Reference
<css::awt::XRequestCallback
> m_xPopupRequest
;
153 std::vector
< GraphicObject
> m_aGraphicObjectVector
;
155 css::uno::Reference
< css::chart2::data::XDataProvider
> m_xDataProvider
;
156 /** is only valid if m_xDataProvider is set. If m_xDataProvider is set to an
157 external data provider this reference must be set to 0
159 rtl::Reference
< InternalDataProvider
> m_xInternalDataProvider
;
161 rtl::Reference
< SvNumberFormatsSupplierObj
> m_xOwnNumberFormatsSupplier
;
162 css::uno::Reference
< css::util::XNumberFormatsSupplier
>
163 m_xNumberFormatsSupplier
;
164 std::unique_ptr
< SvNumberFormatter
> m_apSvNumberFormatter
; // #i113784# avoid memory leak
166 rtl::Reference
< ::chart::ChartTypeManager
>
170 rtl::Reference
< ::chart::Diagram
> m_xDiagram
;
172 rtl::Reference
< ::chart::Title
> m_xTitle
;
174 rtl::Reference
< ::chart::PageBackground
> m_xPageBackground
;
176 rtl::Reference
< ::chart::NameContainer
> m_xXMLNamespaceMap
;
181 OUString
impl_g_getLocation();
184 impl_isControllerConnected( const css::uno::Reference
< com::sun::star::frame::XController
>& xController
);
186 /// @throws css::uno::RuntimeException
187 css::uno::Reference
< css::frame::XController
>
188 impl_getCurrentController();
190 /// @throws css::uno::RuntimeException
192 impl_notifyModifiedListeners();
193 /// @throws css::uno::RuntimeException
195 impl_notifyCloseListeners();
196 /// @throws css::uno::RuntimeException
198 impl_notifyStorageChangeListeners();
201 const css::uno::Sequence
< css::beans::PropertyValue
>& rMediaDescriptor
,
202 const css::uno::Reference
< css::embed::XStorage
> & xStorage
);
204 const css::uno::Sequence
< css::beans::PropertyValue
>& rMediaDescriptor
,
205 const css::uno::Reference
< css::embed::XStorage
>& xStorage
);
206 void impl_loadGraphics(
207 const css::uno::Reference
< ::com::sun::star::embed::XStorage
>& xStorage
);
208 css::uno::Reference
< css::document::XFilter
>
209 impl_createFilter( const css::uno::Sequence
< css::beans::PropertyValue
> & rMediaDescriptor
);
211 rtl::Reference
< ::chart::ChartTypeTemplate
> impl_createDefaultChartTypeTemplate();
212 css::uno::Reference
< css::chart2::data::XDataSource
> impl_createDefaultData();
214 void impl_adjustAdditionalShapesPositionAndSize(
215 const css::awt::Size
& aVisualAreaSize
);
217 void insertDefaultChart();
220 ChartModel() = delete;
221 ChartModel(css::uno::Reference
< css::uno::XComponentContext
> xContext
);
222 explicit ChartModel( const ChartModel
& rOther
);
223 virtual ~ChartModel() override
;
225 // css::lang::XServiceInfo
227 virtual OUString SAL_CALL
getImplementationName() override
;
228 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
229 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
231 // css::lang::XInitialization
232 virtual void SAL_CALL
initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
) override
;
234 // css::frame::XModel (required interface)
236 virtual sal_Bool SAL_CALL
237 attachResource( const OUString
& rURL
,
238 const css::uno::Sequence
< css::beans::PropertyValue
>& rMediaDescriptor
) override
;
240 virtual OUString SAL_CALL
243 virtual css::uno::Sequence
< css::beans::PropertyValue
> SAL_CALL
246 virtual void SAL_CALL
247 connectController( const css::uno::Reference
< css::frame::XController
>& xController
) override
;
249 virtual void SAL_CALL
250 disconnectController( const css::uno::Reference
< css::frame::XController
>& xController
) override
;
252 virtual void SAL_CALL
253 lockControllers() override
;
255 virtual void SAL_CALL
256 unlockControllers() override
;
258 virtual sal_Bool SAL_CALL
259 hasControllersLocked() override
;
261 virtual css::uno::Reference
< css::frame::XController
> SAL_CALL
262 getCurrentController() override
;
264 virtual void SAL_CALL
265 setCurrentController( const css::uno::Reference
< css::frame::XController
>& xController
) override
;
267 virtual css::uno::Reference
< css::uno::XInterface
> SAL_CALL
268 getCurrentSelection() override
;
270 // css::lang::XComponent (base of XModel)
271 virtual void SAL_CALL
274 virtual void SAL_CALL
275 addEventListener( const css::uno::Reference
< css::lang::XEventListener
> & xListener
) override
;
277 virtual void SAL_CALL
278 removeEventListener( const css::uno::Reference
< css::lang::XEventListener
> & xListener
) override
;
280 // css::util::XCloseable
281 virtual void SAL_CALL
282 close( sal_Bool bDeliverOwnership
) override
;
284 // css::util::XCloseBroadcaster (base of XCloseable)
285 virtual void SAL_CALL
286 addCloseListener( const css::uno::Reference
< css::util::XCloseListener
> & xListener
) override
;
288 virtual void SAL_CALL
289 removeCloseListener( const css::uno::Reference
< css::util::XCloseListener
> & xListener
) override
;
291 // css::frame::XStorable2 (extension of XStorable)
292 virtual void SAL_CALL
storeSelf(
293 const css::uno::Sequence
< css::beans::PropertyValue
>& rMediaDescriptor
) override
;
295 // css::frame::XStorable (required interface)
296 virtual sal_Bool SAL_CALL
297 hasLocation() override
;
299 virtual OUString SAL_CALL
300 getLocation() override
;
302 virtual sal_Bool SAL_CALL
303 isReadonly() override
;
305 virtual void SAL_CALL
308 virtual void SAL_CALL
309 storeAsURL( const OUString
& rURL
,
310 const css::uno::Sequence
< css::beans::PropertyValue
>& rMediaDescriptor
) override
;
312 virtual void SAL_CALL
313 storeToURL( const OUString
& rURL
,
314 const css::uno::Sequence
< css::beans::PropertyValue
>& rMediaDescriptor
) override
;
316 // css::util::XModifiable (required interface)
317 virtual sal_Bool SAL_CALL
318 isModified() override
;
320 virtual void SAL_CALL
321 setModified( sal_Bool bModified
) override
;
323 // css::util::XModifyBroadcaster (base of XModifiable)
324 virtual void SAL_CALL
325 addModifyListener( const css::uno::Reference
< css::util::XModifyListener
>& xListener
) override
;
327 virtual void SAL_CALL
328 removeModifyListener( const css::uno::Reference
< css::util::XModifyListener
>& xListener
) override
;
330 // ____ XModifyListener ____
331 virtual void SAL_CALL
modified(
332 const css::lang::EventObject
& aEvent
) override
;
334 // ____ XEventListener (base of XModifyListener) ____
335 virtual void SAL_CALL
disposing(
336 const css::lang::EventObject
& Source
) override
;
338 // ____ datatransferable::XTransferable ____
339 virtual css::uno::Any SAL_CALL
getTransferData(
340 const css::datatransfer::DataFlavor
& aFlavor
) override
;
341 virtual css::uno::Sequence
< css::datatransfer::DataFlavor
> SAL_CALL
getTransferDataFlavors() override
;
342 virtual sal_Bool SAL_CALL
isDataFlavorSupported(
343 const css::datatransfer::DataFlavor
& aFlavor
) override
;
345 // lang::XTypeProvider (override method of WeakImplHelper)
346 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
349 // ____ document::XDocumentPropertiesSupplier ____
350 virtual css::uno::Reference
< css::document::XDocumentProperties
> SAL_CALL
351 getDocumentProperties( ) override
;
353 // ____ document::XUndoManagerSupplier ____
354 virtual css::uno::Reference
< css::document::XUndoManager
> SAL_CALL
355 getUndoManager( ) override
;
357 // css::chart2::XChartDocument
358 virtual css::uno::Reference
< css::chart2::XDiagram
> SAL_CALL
359 getFirstDiagram() override
;
360 virtual void SAL_CALL
setFirstDiagram(
361 const css::uno::Reference
< css::chart2::XDiagram
>& xDiagram
) override
;
362 virtual void SAL_CALL
363 createInternalDataProvider( sal_Bool bCloneExistingData
) override
;
364 virtual sal_Bool SAL_CALL
hasInternalDataProvider() override
;
365 virtual css::uno::Reference
< css::chart2::data::XDataProvider
> SAL_CALL
366 getDataProvider() override
;
367 virtual void SAL_CALL
368 setChartTypeManager( const css::uno::Reference
< css::chart2::XChartTypeManager
>& xNewManager
) override
;
369 virtual css::uno::Reference
< css::chart2::XChartTypeManager
> SAL_CALL
370 getChartTypeManager() override
;
371 virtual css::uno::Reference
< css::beans::XPropertySet
> SAL_CALL
372 getPageBackground() override
;
374 virtual void SAL_CALL
createDefaultChart() override
;
376 // ____ XDataReceiver (public API) ____
377 virtual void SAL_CALL
378 attachDataProvider( const css::uno::Reference
< css::chart2::data::XDataProvider
>& xProvider
) override
;
379 virtual void SAL_CALL
setArguments(
380 const css::uno::Sequence
< css::beans::PropertyValue
>& aArguments
) override
;
381 virtual css::uno::Sequence
< OUString
> SAL_CALL
getUsedRangeRepresentations() override
;
382 virtual css::uno::Reference
< css::chart2::data::XDataSource
> SAL_CALL
getUsedData() override
;
383 virtual void SAL_CALL
attachNumberFormatsSupplier( const css::uno::Reference
<
384 css::util::XNumberFormatsSupplier
>& xSupplier
) override
;
385 virtual css::uno::Reference
< css::chart2::data::XRangeHighlighter
> SAL_CALL
getRangeHighlighter() override
;
386 virtual css::uno::Reference
<css::awt::XRequestCallback
> SAL_CALL
getPopupRequest() override
;
389 virtual css::uno::Reference
< css::chart2::XTitle
> SAL_CALL
getTitleObject() override
;
390 virtual void SAL_CALL
setTitleObject( const css::uno::Reference
< css::chart2::XTitle
>& Title
) override
;
392 // ____ XInterface (for old API wrapper) ____
393 virtual css::uno::Any SAL_CALL
queryInterface( const css::uno::Type
& aType
) override
;
395 // ____ XLoadable ____
396 virtual void SAL_CALL
initNew() override
;
397 virtual void SAL_CALL
load( const css::uno::Sequence
< css::beans::PropertyValue
>& rMediaDescriptor
) override
;
399 // ____ XCloneable ____
400 virtual css::uno::Reference
< css::util::XCloneable
> SAL_CALL
createClone() override
;
402 // ____ XVisualObject ____
403 virtual void SAL_CALL
setVisualAreaSize(
405 const css::awt::Size
& aSize
) override
;
406 virtual css::awt::Size SAL_CALL
getVisualAreaSize(
407 ::sal_Int64 nAspect
) override
;
408 virtual css::embed::VisualRepresentation SAL_CALL
getPreferredVisualRepresentation(
409 ::sal_Int64 nAspect
) override
;
410 virtual ::sal_Int32 SAL_CALL
getMapUnit(
411 ::sal_Int64 nAspect
) override
;
413 // ____ XMultiServiceFactory ____
414 virtual css::uno::Reference
< css::uno::XInterface
> SAL_CALL
415 createInstance( const OUString
& aServiceSpecifier
) override
;
416 virtual css::uno::Reference
< css::uno::XInterface
> SAL_CALL
417 createInstanceWithArguments( const OUString
& ServiceSpecifier
418 , const css::uno::Sequence
< css::uno::Any
>& Arguments
) override
;
419 virtual css::uno::Sequence
< OUString
> SAL_CALL
420 getAvailableServiceNames() override
;
422 // ____ XStorageBasedDocument ____
423 virtual void SAL_CALL
loadFromStorage(
424 const css::uno::Reference
< css::embed::XStorage
>& xStorage
,
425 const css::uno::Sequence
< css::beans::PropertyValue
>& rMediaDescriptor
) override
;
426 virtual void SAL_CALL
storeToStorage(
427 const css::uno::Reference
< css::embed::XStorage
>& xStorage
,
428 const css::uno::Sequence
< css::beans::PropertyValue
>& rMediaDescriptor
) override
;
429 virtual void SAL_CALL
switchToStorage(
430 const css::uno::Reference
< css::embed::XStorage
>& xStorage
) override
;
431 virtual css::uno::Reference
< css::embed::XStorage
> SAL_CALL
getDocumentStorage() override
;
432 virtual void SAL_CALL
addStorageChangeListener(
433 const css::uno::Reference
< css::document::XStorageChangeListener
>& xListener
) override
;
434 virtual void SAL_CALL
removeStorageChangeListener(
435 const css::uno::Reference
< css::document::XStorageChangeListener
>& xListener
) override
;
437 // for SvNumberFormatsSupplierObj
438 // ____ XUnoTunnel ___
439 virtual ::sal_Int64 SAL_CALL
getSomething( const css::uno::Sequence
< ::sal_Int8
>& aIdentifier
) override
;
441 // ____ XNumberFormatsSupplier ____
442 virtual css::uno::Reference
< css::beans::XPropertySet
> SAL_CALL
getNumberFormatSettings() override
;
443 virtual css::uno::Reference
< css::util::XNumberFormats
> SAL_CALL
getNumberFormats() override
;
446 virtual css::uno::Reference
< css::uno::XInterface
> SAL_CALL
getParent() override
;
447 virtual void SAL_CALL
setParent(
448 const css::uno::Reference
< css::uno::XInterface
>& Parent
) override
;
450 // ____ XDataSource ____ allows access to the currently used data and data ranges
451 virtual css::uno::Sequence
< css::uno::Reference
< css::chart2::data::XLabeledDataSequence
> > SAL_CALL
getDataSequences() override
;
454 virtual void SAL_CALL
update() override
;
457 virtual OUString SAL_CALL
dump(OUString
const & kind
) override
;
460 css::uno::Reference
< css::util::XNumberFormatsSupplier
> const &
461 getNumberFormatsSupplier();
463 ChartView
* getChartView() const;
465 const rtl::Reference
< ::chart::Diagram
> & getFirstChartDiagram() { return m_xDiagram
; }
467 bool isTimeBased() const { return mbTimeBased
;}
469 void setTimeBasedRange(sal_Int32 nStart
, sal_Int32 nEnd
);
471 bool isDataFromSpreadsheet();
473 bool isDataFromPivotTable() const;
475 void removeDataProviders();
477 const rtl::Reference
< ::chart::ChartTypeManager
> & getTypeManager() const { return m_xChartTypeManager
; }
479 rtl::Reference
< ::chart::Title
> getTitleObject2() const;
480 void setTitleObject( const rtl::Reference
< ::chart::Title
>& Title
);
483 void dumpAsXml(xmlTextWriterPtr pWriter
) const;
491 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */