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 .
19 #ifndef INCLUDED_CHART2_SOURCE_INC_DIAGRAMHELPER_HXX
20 #define INCLUDED_CHART2_SOURCE_INC_DIAGRAMHELPER_HXX
22 #include "StackMode.hxx"
23 #include "charttoolsdllapi.hxx"
24 #include <com/sun/star/chart2/XAxis.hpp>
25 #include <com/sun/star/chart2/XDiagram.hpp>
26 #include <com/sun/star/chart2/XChartTypeTemplate.hpp>
27 #include <com/sun/star/chart2/XCoordinateSystem.hpp>
28 #include <com/sun/star/chart2/InterpretedData.hpp>
29 #include <com/sun/star/chart2/StackingDirection.hpp>
30 #include <com/sun/star/chart2/XChartDocument.hpp>
31 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
32 #include <com/sun/star/uno/XComponentContext.hpp>
33 #include <com/sun/star/util/XNumberFormats.hpp>
34 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
36 #include "ChartModel.hxx"
44 enum DiagramPositioningMode
46 DiagramPositioningMode_AUTO
,
47 DiagramPositioningMode_EXCLUDING
,
48 DiagramPositioningMode_INCLUDING
51 class OOO_DLLPUBLIC_CHARTTOOLS DiagramHelper
55 ::com::sun::star::uno::Reference
<
56 ::com::sun::star::chart2::XChartTypeTemplate
>,
58 tTemplateWithServiceName
;
60 /** tries to find a template in the chart-type manager that matches the
63 @param rPreferredTemplateName
64 Check this template first. This may speed up searching, if the
65 caller assumes a certain template as most likely to be the one that
69 A pair containing a template with the correct properties set as
70 first entry and the service name of the templateas second entry. If
71 no template was found both elements are empty.
73 static tTemplateWithServiceName
74 getTemplateForDiagram(
75 const ::com::sun::star::uno::Reference
<
76 ::com::sun::star::chart2::XDiagram
> & xDiagram
,
77 const ::com::sun::star::uno::Reference
<
78 ::com::sun::star::lang::XMultiServiceFactory
> & xChartTypeManager
,
79 const OUString
& rPreferredTemplateName
= OUString());
81 /** Sets the "SwapXAndYAxis" property at all coordinate systems found in the
84 "vertical==true" for bar charts, "vertical==false" for column charts
86 static void setVertical( const ::com::sun::star::uno::Reference
<
87 ::com::sun::star::chart2::XDiagram
> & xDiagram
,
88 bool bVertical
= true );
90 /** Gets the "SwapXAndYAxis" property at all coordinate systems found in the
93 "vertical==true" for bar charts, "vertical==false" for column charts
95 static bool getVertical( const ::com::sun::star::uno::Reference
<
96 ::com::sun::star::chart2::XDiagram
> & xDiagram
,
97 bool& rbOutFoundResult
, bool& rbOutAmbiguousResult
);
99 static StackMode
getStackMode(
100 const ::com::sun::star::uno::Reference
<
101 ::com::sun::star::chart2::XDiagram
> & xDiagram
,
102 bool& rbFound
, bool& rbAmbiguous
105 /** @param bOnlyAtFirstChartType
106 If </sal_True>, the stacking mode is only set at the series found inside
107 the first chart type. This is the standard for all current
108 templates (the only template that has more than one chart-type and
109 allows stacking is bar/line combi, and for this the stacking only
110 applies to the first chart type/the bars)
112 static void setStackMode(
113 const ::com::sun::star::uno::Reference
<
114 ::com::sun::star::chart2::XDiagram
> & xDiagram
,
115 StackMode eStackMode
,
116 bool bOnlyAtFirstChartType
= true
119 /** Retrieves the stackmode of the first DataSeries or none. If the series have differing stack
120 modes, rbAmbiguous is set to true. If no series is there rbFound is set to false.
122 @param xCorrespondingCoordinateSystem
123 The coordinate system in which the given chart type xChartType is
124 located. (This is needed for determining percent stacking. If
125 omitted, the result will just indicate "not stacked", "stacked" or
128 static StackMode
getStackModeFromChartType(
129 const ::com::sun::star::uno::Reference
<
130 ::com::sun::star::chart2::XChartType
> & xChartType
,
131 bool& rbFound
, bool& rbAmbiguous
,
132 const ::com::sun::star::uno::Reference
<
133 ::com::sun::star::chart2::XCoordinateSystem
> & xCorrespondingCoordinateSystem
=
134 ::com::sun::star::uno::Reference
< ::com::sun::star::chart2::XCoordinateSystem
>()
137 /** Returns the dimension found for all chart types in the tree. If the
138 dimension is not unique, 0 is returned.
140 static sal_Int32
getDimension(
141 const ::com::sun::star::uno::Reference
<
142 ::com::sun::star::chart2::XDiagram
> & xDiagram
);
144 /** Sets the dimension of the diagram given.
146 1. Sets the dimension of all used ChartTypes
147 2. Adapts the DataSeriesTree to reflect the new dimension
148 3. If new coordinate-systems have to be created, adapts the
149 XCoordinateSystemContainer of the diagram.
151 static void setDimension(
152 const ::com::sun::star::uno::Reference
<
153 ::com::sun::star::chart2::XDiagram
> & xDiagram
,
154 sal_Int32 nNewDimensionCount
);
156 /** Replaces all occurrences of xCooSysToReplace in the tree with
157 xReplacement in the diagram's tree
159 SAL_DLLPRIVATE
static void replaceCoordinateSystem(
160 const ::com::sun::star::uno::Reference
<
161 ::com::sun::star::chart2::XDiagram
> & xDiagram
,
162 const ::com::sun::star::uno::Reference
<
163 ::com::sun::star::chart2::XCoordinateSystem
> & xCooSysToReplace
,
164 const ::com::sun::star::uno::Reference
<
165 ::com::sun::star::chart2::XCoordinateSystem
> & xReplacement
);
167 static bool isSeriesAttachedToMainAxis(
168 const ::com::sun::star::uno::Reference
<
169 ::com::sun::star::chart2::XDataSeries
>& xDataSeries
);
171 static bool attachSeriesToAxis( bool bMainAxis
,
172 const ::com::sun::star::uno::Reference
<
173 ::com::sun::star::chart2::XDataSeries
>& xSeries
,
174 const ::com::sun::star::uno::Reference
<
175 ::com::sun::star::chart2::XDiagram
>& xDiagram
,
176 const ::com::sun::star::uno::Reference
<
177 ::com::sun::star::uno::XComponentContext
> & xContext
,
178 bool bAdaptAxes
=true );
180 static ::com::sun::star::uno::Reference
<
181 ::com::sun::star::chart2::XAxis
> getAttachedAxis(
182 const ::com::sun::star::uno::Reference
<
183 ::com::sun::star::chart2::XDataSeries
>& xSeries
,
184 const ::com::sun::star::uno::Reference
<
185 ::com::sun::star::chart2::XDiagram
>& xDiagram
);
187 static ::com::sun::star::uno::Reference
<
188 ::com::sun::star::chart2::XChartType
>
189 getChartTypeOfSeries(
190 const ::com::sun::star::uno::Reference
<
191 ::com::sun::star::chart2::XDiagram
>& xDiagram
,
192 const ::com::sun::star::uno::Reference
<
193 ::com::sun::star::chart2::XDataSeries
>& xSeries
);
195 static ::std::vector
<
196 ::com::sun::star::uno::Reference
<
197 ::com::sun::star::chart2::XDataSeries
> >
198 getDataSeriesFromDiagram(
199 const ::com::sun::star::uno::Reference
<
200 ::com::sun::star::chart2::XDiagram
> & xDiagram
);
202 /** return all data series in this diagram grouped by chart-types
204 static ::com::sun::star::uno::Sequence
<
205 ::com::sun::star::uno::Sequence
<
206 ::com::sun::star::uno::Reference
< ::com::sun::star::chart2::XDataSeries
> > >
208 const ::com::sun::star::uno::Reference
<
209 ::com::sun::star::chart2::XDiagram
> & xDiagram
);
211 static bool isCategoryDiagram(
212 const ::com::sun::star::uno::Reference
<
213 ::com::sun::star::chart2::XDiagram
>& xDiagram
);
215 static void setCategoriesToDiagram(
216 const ::com::sun::star::uno::Reference
<
217 ::com::sun::star::chart2::data::XLabeledDataSequence
>& xCategories
,
218 const ::com::sun::star::uno::Reference
<
219 ::com::sun::star::chart2::XDiagram
>& xDiagram
,
220 bool bSetAxisType
= false, // when this flag is true ...
221 bool bCategoryAxis
= true);// set the AxisType to CATEGORY or back to REALNUMBER
223 static ::com::sun::star::uno::Reference
< ::com::sun::star::chart2::data::XLabeledDataSequence
>
224 getCategoriesFromDiagram(
225 const ::com::sun::star::uno::Reference
<
226 ::com::sun::star::chart2::XDiagram
> & xDiagram
);
228 static ::com::sun::star::uno::Sequence
< OUString
>
229 getExplicitSimpleCategories( ChartModel
& rModel
);
231 SAL_DLLPRIVATE
static ::com::sun::star::uno::Sequence
< OUString
>
232 generateAutomaticCategoriesFromCooSys(
233 const ::com::sun::star::uno::Reference
<
234 ::com::sun::star::chart2::XCoordinateSystem
> & xCooSys
);
236 static void switchToDateCategories(
237 const ::com::sun::star::uno::Reference
<
238 ::com::sun::star::chart2::XChartDocument
> & xChartDoc
);
240 static void switchToTextCategories(
241 const ::com::sun::star::uno::Reference
<
242 ::com::sun::star::chart2::XChartDocument
> & xChartDoc
);
244 static bool isSupportingDateAxis( const ::com::sun::star::uno::Reference
< ::com::sun::star::chart2::XDiagram
>& xDiagram
);
245 static bool isDateNumberFormat( sal_Int32 nNumberFormat
, const ::com::sun::star::uno::Reference
< ::com::sun::star::util::XNumberFormats
>& xNumberFormats
);
246 static sal_Int32
getDateNumberFormat( const ::com::sun::star::uno::Reference
< ::com::sun::star::util::XNumberFormatsSupplier
>& xNumberFormatsSupplier
);
247 static sal_Int32
getDateTimeInputNumberFormat( const ::com::sun::star::uno::Reference
< ::com::sun::star::util::XNumberFormatsSupplier
>& xNumberFormatsSupplier
, double fNumber
);
249 static sal_Int32
getPercentNumberFormat( const ::com::sun::star::uno::Reference
<
250 ::com::sun::star::util::XNumberFormatsSupplier
>& xNumberFormatsSupplier
);
252 static ::com::sun::star::uno::Reference
<
253 ::com::sun::star::chart2::XChartType
>
254 getChartTypeByIndex( const ::com::sun::star::uno::Reference
<
255 ::com::sun::star::chart2::XDiagram
>& xDiagram
, sal_Int32 nIndex
);
257 static ::com::sun::star::uno::Sequence
<
258 ::com::sun::star::uno::Reference
<
259 ::com::sun::star::chart2::XChartType
> >
260 getChartTypesFromDiagram(
261 const ::com::sun::star::uno::Reference
<
262 ::com::sun::star::chart2::XDiagram
> & xDiagram
);
264 SAL_DLLPRIVATE
static bool areChartTypesCompatible( const ::com::sun::star::uno::Reference
<
265 ::com::sun::star::chart2::XChartType
>& xFirstType
,
266 const ::com::sun::star::uno::Reference
<
267 ::com::sun::star::chart2::XChartType
>& xSecondType
);
270 * Test if a series can be moved.
273 * Reference to the diagram that contains the series.
275 * @param xGivenDataSeries
276 * Reference to the series that should be tested for moving.
279 * Direction of the move to be checked.
281 * @returns </sal_True> if the series can be moved.
284 static bool isSeriesMoveable(
285 const ::com::sun::star::uno::Reference
<
286 ::com::sun::star::chart2::XDiagram
>& xDiagram
,
287 const ::com::sun::star::uno::Reference
<
288 ::com::sun::star::chart2::XDataSeries
>& xGivenDataSeries
,
292 * Move a series forward or backward.
295 * Reference to the diagram that contains the series.
297 * @param xGivenDataSeries
298 * Reference to the series that should be moved.
301 * Direction in which the series should be moved.
303 * @returns </sal_True> if the series was moved successfully.
306 static bool moveSeries(
307 const ::com::sun::star::uno::Reference
<
308 ::com::sun::star::chart2::XDiagram
>& xDiagram
,
309 const ::com::sun::star::uno::Reference
<
310 ::com::sun::star::chart2::XDataSeries
>& xGivenDataSeries
,
313 static bool isSupportingFloorAndWall( const ::com::sun::star::uno::Reference
<
314 ::com::sun::star::chart2::XDiagram
> & xDiagram
);
316 static bool isPieOrDonutChart( const ::com::sun::star::uno::Reference
<
317 ::com::sun::star::chart2::XDiagram
>& xDiagram
);
319 static sal_Int32
getGeometry3D(
320 const ::com::sun::star::uno::Reference
<
321 ::com::sun::star::chart2::XDiagram
> & xDiagram
,
322 bool& rbFound
, bool& rbAmbiguous
);
324 static void setGeometry3D(
325 const ::com::sun::star::uno::Reference
<
326 ::com::sun::star::chart2::XDiagram
> & xDiagram
,
327 sal_Int32 nNewGeometry
);
329 //returns integer from constant group ::com::sun::star::chart::MissingValueTreatment
330 static sal_Int32
getCorrectedMissingValueTreatment(
331 const ::com::sun::star::uno::Reference
<
332 ::com::sun::star::chart2::XDiagram
> & xDiagram
,
333 const ::com::sun::star::uno::Reference
<
334 ::com::sun::star::chart2::XChartType
>& xChartType
);
336 static DiagramPositioningMode
getDiagramPositioningMode( const ::com::sun::star::uno::Reference
<
337 ::com::sun::star::chart2::XDiagram
> & xDiagram
);
339 static bool setDiagramPositioning( const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
>& xChartModel
,
340 const ::com::sun::star::awt::Rectangle
& rPosRect
/*100th mm*/ );
342 static ::com::sun::star::awt::Rectangle
getDiagramRectangleFromModel( const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
>& xChartModel
);
344 static bool switchDiagramPositioningToExcludingPositioning( ChartModel
& rModel
345 , bool bResetModifiedState
//set model back to unchanged if it was unchanged before
346 , bool bConvertAlsoFromAutoPositioning
);
349 DiagramHelper() SAL_DELETED_FUNCTION
;
355 // INCLUDED_CHART2_SOURCE_INC_DIAGRAMHELPER_HXX
358 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */