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/awt/Rectangle.hpp>
25 #include <com/sun/star/chart2/XChartTypeTemplate.hpp>
30 namespace chart
{ class ChartModel
; }
31 namespace com
{ namespace sun
{ namespace star
{ namespace chart2
{ class XAxis
; } } } }
32 namespace com
{ namespace sun
{ namespace star
{ namespace chart2
{ class XChartDocument
; } } } }
33 namespace com
{ namespace sun
{ namespace star
{ namespace chart2
{ class XCoordinateSystem
; } } } }
34 namespace com
{ namespace sun
{ namespace star
{ namespace chart2
{ class XDiagram
; } } } }
35 namespace com
{ namespace sun
{ namespace star
{ namespace frame
{ class XModel
; } } } }
36 namespace com
{ namespace sun
{ namespace star
{ namespace lang
{ class XMultiServiceFactory
; } } } }
37 namespace com
{ namespace sun
{ namespace star
{ namespace uno
{ class XComponentContext
; } } } }
38 namespace com
{ namespace sun
{ namespace star
{ namespace util
{ class XNumberFormats
; } } } }
39 namespace com
{ namespace sun
{ namespace star
{ namespace util
{ class XNumberFormatsSupplier
; } } } }
44 enum DiagramPositioningMode
46 DiagramPositioningMode_AUTO
,
47 DiagramPositioningMode_EXCLUDING
,
48 DiagramPositioningMode_INCLUDING
51 class OOO_DLLPUBLIC_CHARTTOOLS DiagramHelper
55 css::uno::Reference
< css::chart2::XChartTypeTemplate
>,
57 tTemplateWithServiceName
;
59 /** tries to find a template in the chart-type manager that matches the
63 A pair containing a template with the correct properties set as
64 first entry and the service name of the templates second entry. If
65 no template was found both elements are empty.
67 static tTemplateWithServiceName
68 getTemplateForDiagram(
69 const css::uno::Reference
< css::chart2::XDiagram
> & xDiagram
,
70 const css::uno::Reference
< css::lang::XMultiServiceFactory
> & xChartTypeManager
);
72 /** Sets the "SwapXAndYAxis" property at all coordinate systems found in the
75 "vertical==true" for bar charts, "vertical==false" for column charts
77 static void setVertical( const css::uno::Reference
< css::chart2::XDiagram
> & xDiagram
,
80 /** Gets the "SwapXAndYAxis" property at all coordinate systems found in the
83 "vertical==true" for bar charts, "vertical==false" for column charts
85 static bool getVertical( const css::uno::Reference
< css::chart2::XDiagram
> & xDiagram
,
86 bool& rbOutFoundResult
, bool& rbOutAmbiguousResult
);
88 static StackMode
getStackMode(
89 const css::uno::Reference
< css::chart2::XDiagram
> & xDiagram
,
90 bool& rbFound
, bool& rbAmbiguous
93 /** The stacking mode is only set at the series found inside
94 the first chart type. This is the standard for all current
95 templates (the only template that has more than one chart-type and
96 allows stacking is bar/line combi, and for this the stacking only
97 applies to the first chart type/the bars)
99 static void setStackMode(
100 const css::uno::Reference
< css::chart2::XDiagram
> & xDiagram
,
104 /** Retrieves the stackmode of the first DataSeries or none. If the series have differing stack
105 modes, rbAmbiguous is set to true. If no series is there rbFound is set to false.
107 @param xCorrespondingCoordinateSystem
108 The coordinate system in which the given chart type xChartType is
109 located. (This is needed for determining percent stacking. If
110 omitted, the result will just indicate "not stacked", "stacked" or
113 static StackMode
getStackModeFromChartType(
114 const css::uno::Reference
< css::chart2::XChartType
> & xChartType
,
115 bool& rbFound
, bool& rbAmbiguous
,
116 const css::uno::Reference
< css::chart2::XCoordinateSystem
> & xCorrespondingCoordinateSystem
119 /** Returns the dimension found for all chart types in the tree. If the
120 dimension is not unique, 0 is returned.
122 static sal_Int32
getDimension(
123 const css::uno::Reference
< css::chart2::XDiagram
> & xDiagram
);
125 /** Sets the dimension of the diagram given.
127 1. Sets the dimension of all used ChartTypes
128 2. Adapts the DataSeriesTree to reflect the new dimension
129 3. If new coordinate-systems have to be created, adapts the
130 XCoordinateSystemContainer of the diagram.
132 static void setDimension(
133 const css::uno::Reference
< css::chart2::XDiagram
> & xDiagram
,
134 sal_Int32 nNewDimensionCount
);
136 /** Replaces all occurrences of xCooSysToReplace in the tree with
137 xReplacement in the diagram's tree
139 SAL_DLLPRIVATE
static void replaceCoordinateSystem(
140 const css::uno::Reference
< css::chart2::XDiagram
> & xDiagram
,
141 const css::uno::Reference
< css::chart2::XCoordinateSystem
> & xCooSysToReplace
,
142 const css::uno::Reference
< css::chart2::XCoordinateSystem
> & xReplacement
);
144 static bool isSeriesAttachedToMainAxis(
145 const css::uno::Reference
< css::chart2::XDataSeries
>& xDataSeries
);
147 static bool attachSeriesToAxis( bool bMainAxis
,
148 const css::uno::Reference
< css::chart2::XDataSeries
>& xSeries
,
149 const css::uno::Reference
< css::chart2::XDiagram
>& xDiagram
,
150 const css::uno::Reference
< css::uno::XComponentContext
> & xContext
,
151 bool bAdaptAxes
=true );
153 static css::uno::Reference
< css::chart2::XAxis
> getAttachedAxis(
154 const css::uno::Reference
< css::chart2::XDataSeries
>& xSeries
,
155 const css::uno::Reference
< css::chart2::XDiagram
>& xDiagram
);
157 static css::uno::Reference
< css::chart2::XChartType
>
158 getChartTypeOfSeries(
159 const css::uno::Reference
< css::chart2::XDiagram
>& xDiagram
,
160 const css::uno::Reference
< css::chart2::XDataSeries
>& xSeries
);
162 static std::vector
< css::uno::Reference
< css::chart2::XDataSeries
> >
163 getDataSeriesFromDiagram(
164 const css::uno::Reference
< css::chart2::XDiagram
> & xDiagram
);
166 /** return all data series in this diagram grouped by chart-types
168 static css::uno::Sequence
<
170 css::uno::Reference
< css::chart2::XDataSeries
> > >
172 const css::uno::Reference
< css::chart2::XDiagram
> & xDiagram
);
174 static bool isCategoryDiagram(
175 const css::uno::Reference
< css::chart2::XDiagram
>& xDiagram
);
177 static void setCategoriesToDiagram(
178 const css::uno::Reference
< css::chart2::data::XLabeledDataSequence
>& xCategories
,
179 const css::uno::Reference
< css::chart2::XDiagram
>& xDiagram
,
180 bool bSetAxisType
= false, // when this flag is true ...
181 bool bCategoryAxis
= true);// set the AxisType to CATEGORY or back to REALNUMBER
183 static css::uno::Reference
< css::chart2::data::XLabeledDataSequence
>
184 getCategoriesFromDiagram(
185 const css::uno::Reference
< css::chart2::XDiagram
> & xDiagram
);
187 static css::uno::Sequence
< OUString
>
188 getExplicitSimpleCategories( ChartModel
& rModel
);
190 SAL_DLLPRIVATE
static css::uno::Sequence
< OUString
>
191 generateAutomaticCategoriesFromCooSys(
192 const css::uno::Reference
< css::chart2::XCoordinateSystem
> & xCooSys
);
194 static void switchToDateCategories(
195 const css::uno::Reference
< css::chart2::XChartDocument
> & xChartDoc
);
197 static void switchToTextCategories(
198 const css::uno::Reference
< css::chart2::XChartDocument
> & xChartDoc
);
200 static bool isSupportingDateAxis( const css::uno::Reference
< css::chart2::XDiagram
>& xDiagram
);
201 static bool isDateNumberFormat( sal_Int32 nNumberFormat
, const css::uno::Reference
< css::util::XNumberFormats
>& xNumberFormats
);
202 static sal_Int32
getDateNumberFormat( const css::uno::Reference
< css::util::XNumberFormatsSupplier
>& xNumberFormatsSupplier
);
203 static sal_Int32
getDateTimeInputNumberFormat( const css::uno::Reference
< css::util::XNumberFormatsSupplier
>& xNumberFormatsSupplier
, double fNumber
);
205 static sal_Int32
getPercentNumberFormat( const css::uno::Reference
<
206 css::util::XNumberFormatsSupplier
>& xNumberFormatsSupplier
);
208 static css::uno::Reference
< css::chart2::XChartType
>
209 getChartTypeByIndex( const css::uno::Reference
< css::chart2::XDiagram
>& xDiagram
, sal_Int32 nIndex
);
211 static css::uno::Sequence
<
212 css::uno::Reference
< css::chart2::XChartType
> >
213 getChartTypesFromDiagram(
214 const css::uno::Reference
< css::chart2::XDiagram
> & xDiagram
);
216 SAL_DLLPRIVATE
static bool areChartTypesCompatible( const css::uno::Reference
<
217 css::chart2::XChartType
>& xFirstType
,
218 const css::uno::Reference
< css::chart2::XChartType
>& xSecondType
);
221 * Test if a series can be moved.
224 * Reference to the diagram that contains the series.
226 * @param xGivenDataSeries
227 * Reference to the series that should be tested for moving.
230 * Direction of the move to be checked.
232 * @returns </sal_True> if the series can be moved.
235 static bool isSeriesMoveable(
236 const css::uno::Reference
< css::chart2::XDiagram
>& xDiagram
,
237 const css::uno::Reference
< css::chart2::XDataSeries
>& xGivenDataSeries
,
241 * Move a series forward or backward.
244 * Reference to the diagram that contains the series.
246 * @param xGivenDataSeries
247 * Reference to the series that should be moved.
250 * Direction in which the series should be moved.
252 * @returns </sal_True> if the series was moved successfully.
255 static bool moveSeries(
256 const css::uno::Reference
< css::chart2::XDiagram
>& xDiagram
,
257 const css::uno::Reference
< css::chart2::XDataSeries
>& xGivenDataSeries
,
260 static bool isSupportingFloorAndWall( const css::uno::Reference
< css::chart2::XDiagram
> & xDiagram
);
262 static bool isPieOrDonutChart( const css::uno::Reference
< css::chart2::XDiagram
>& xDiagram
);
264 static sal_Int32
getGeometry3D(
265 const css::uno::Reference
< css::chart2::XDiagram
> & xDiagram
,
266 bool& rbFound
, bool& rbAmbiguous
);
268 static void setGeometry3D(
269 const css::uno::Reference
< css::chart2::XDiagram
> & xDiagram
,
270 sal_Int32 nNewGeometry
);
272 //returns integer from constant group css::chart::MissingValueTreatment
273 static sal_Int32
getCorrectedMissingValueTreatment(
274 const css::uno::Reference
< css::chart2::XDiagram
> & xDiagram
,
275 const css::uno::Reference
< css::chart2::XChartType
>& xChartType
);
277 static DiagramPositioningMode
getDiagramPositioningMode( const css::uno::Reference
< css::chart2::XDiagram
> & xDiagram
);
279 static bool setDiagramPositioning( const css::uno::Reference
< css::frame::XModel
>& xChartModel
,
280 const css::awt::Rectangle
& rPosRect
/*100th mm*/ );
282 static css::awt::Rectangle
getDiagramRectangleFromModel( const css::uno::Reference
< css::frame::XModel
>& xChartModel
);
284 static bool switchDiagramPositioningToExcludingPositioning( ChartModel
& rModel
285 , bool bResetModifiedState
//set model back to unchanged if it was unchanged before
286 , bool bConvertAlsoFromAutoPositioning
);
289 DiagramHelper() = delete;
295 // INCLUDED_CHART2_SOURCE_INC_DIAGRAMHELPER_HXX
298 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */