1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef CHART2_DIAGRAMHELPER_HXX
28 #define CHART2_DIAGRAMHELPER_HXX
29 
30 #include "StackMode.hxx"
31 #include "charttoolsdllapi.hxx"
32 #include <com/sun/star/chart2/XAxis.hpp>
33 #include <com/sun/star/chart2/XDiagram.hpp>
34 #include <com/sun/star/chart2/XChartTypeTemplate.hpp>
35 #include <com/sun/star/chart2/XCoordinateSystem.hpp>
36 #include <com/sun/star/chart2/InterpretedData.hpp>
37 #include <com/sun/star/chart2/StackingDirection.hpp>
38 #include <com/sun/star/chart2/XChartDocument.hpp>
39 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
40 #include <com/sun/star/uno/XComponentContext.hpp>
41 #include <com/sun/star/util/XNumberFormats.hpp>
42 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
43 
44 #include <utility>
45 #include <vector>
46 
47 
48 namespace chart
49 {
50 
51 enum DiagramPositioningMode
52 {
53     DiagramPositioningMode_AUTO,
54     DiagramPositioningMode_EXCLUDING,
55     DiagramPositioningMode_INCLUDING
56 };
57 
58 class OOO_DLLPUBLIC_CHARTTOOLS DiagramHelper
59 {
60 public:
61     typedef ::std::pair<
62             ::com::sun::star::uno::Reference<
63                 ::com::sun::star::chart2::XChartTypeTemplate >,
64             ::rtl::OUString >
65         tTemplateWithServiceName;
66 
67     /** tries to find a template in the chart-type manager that matches the
68         given diagram.
69 
70         @param rPreferredTemplateName
71             Check this template first.  This may speed up searching, if the
72             caller assumes a certain template as most likely to be the one that
73             matches.
74 
75         @return
76             A pair containing a template with the correct properties set as
77             first entry and the service name of the templateas second entry.  If
78             no template was found both elements are empty.
79      */
80     static tTemplateWithServiceName
81         getTemplateForDiagram(
82             const ::com::sun::star::uno::Reference<
83                 ::com::sun::star::chart2::XDiagram > & xDiagram,
84             const ::com::sun::star::uno::Reference<
85                 ::com::sun::star::lang::XMultiServiceFactory > & xChartTypeManager,
86             const ::rtl::OUString & rPreferredTemplateName = ::rtl::OUString());
87 
88     /** Sets the "SwapXAndYAxis" property at all coordinate systems found in the
89         given diagram.
90 
91         "vertical==true" for bar charts, "vertical==false" for column charts
92      */
93     static void setVertical( const ::com::sun::star::uno::Reference<
94                                  ::com::sun::star::chart2::XDiagram > & xDiagram,
95                              bool bVertical = true );
96 
97     /** Gets the "SwapXAndYAxis" property at all coordinate systems found in the
98         given diagram.
99 
100         "vertical==true" for bar charts, "vertical==false" for column charts
101     */
102     static bool getVertical( const ::com::sun::star::uno::Reference<
103                                  ::com::sun::star::chart2::XDiagram > & xDiagram,
104                              bool& rbOutFoundResult, bool& rbOutAmbiguousResult );
105 
106     static StackMode getStackMode(
107         const ::com::sun::star::uno::Reference<
108             ::com::sun::star::chart2::XDiagram > & xDiagram,
109         bool& rbFound, bool& rbAmbiguous
110         );
111 
112     /** @param bOnlyAtFirstChartType
113             If </sal_True>, the stacking mode is only set at the series found inside
114             the first chart type.  This is the standard for all current
115             templates (the only template that has more than one chart-type and
116             allows stacking is bar/line combi, and for this the stacking only
117             applies to the first chart type/the bars)
118      */
119     static void setStackMode(
120         const ::com::sun::star::uno::Reference<
121             ::com::sun::star::chart2::XDiagram > & xDiagram,
122         StackMode eStackMode,
123         bool bOnlyAtFirstChartType = true
124         );
125 
126     /** Retrieves the stackmode of the first DataSeries or none. If the series have differing stack
127         modes, rbAmbiguous is set to true. If no series is there rbFound is set to false.
128 
129         @param xCorrespondingCoordinateSystem
130             The coordinate system in which the given chart type xChartType is
131             located.  (This is needed for determining percent stacking.  If
132             omitted, the result will just indicate "not stacked", "stacked" or
133             "ambiguous")
134      */
135     static StackMode getStackModeFromChartType(
136         const ::com::sun::star::uno::Reference<
137             ::com::sun::star::chart2::XChartType > & xChartType,
138         bool& rbFound, bool& rbAmbiguous,
139         const ::com::sun::star::uno::Reference<
140             ::com::sun::star::chart2::XCoordinateSystem > & xCorrespondingCoordinateSystem =
141                 ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XCoordinateSystem >()
142         );
143 
144     /** Returns the dimension found for all chart types in the tree.  If the
145         dimension is not unique, 0 is returned.
146      */
147     static sal_Int32 getDimension(
148         const ::com::sun::star::uno::Reference<
149             ::com::sun::star::chart2::XDiagram > & xDiagram );
150 
151     /** Sets the dimension of the diagram given.
152 
153         1. Sets the dimension of all used ChartTypes
154         2. Adapts the DataSeriesTree to reflect the new dimension
155         3. If new coordinate-systems have to be created, adapts the
156            XCoordinateSystemContainer of the diagram.
157      */
158     static void setDimension(
159         const ::com::sun::star::uno::Reference<
160             ::com::sun::star::chart2::XDiagram > & xDiagram,
161         sal_Int32 nNewDimensionCount );
162 
163     /** Replaces all occurences of xCooSysToReplace in the tree with
164         xReplacement in the diagram's tree
165      */
166     SAL_DLLPRIVATE static void replaceCoordinateSystem(
167         const ::com::sun::star::uno::Reference<
168             ::com::sun::star::chart2::XDiagram > & xDiagram,
169         const ::com::sun::star::uno::Reference<
170             ::com::sun::star::chart2::XCoordinateSystem > & xCooSysToReplace,
171         const ::com::sun::star::uno::Reference<
172             ::com::sun::star::chart2::XCoordinateSystem > & xReplacement );
173 
174     static bool isSeriesAttachedToMainAxis(
175 		const ::com::sun::star::uno::Reference<
176             ::com::sun::star::chart2::XDataSeries >& xDataSeries );
177 
178     static bool attachSeriesToAxis( bool bMainAxis,
179         const ::com::sun::star::uno::Reference<
180 	        ::com::sun::star::chart2::XDataSeries >& xSeries,
181         const ::com::sun::star::uno::Reference<
182             ::com::sun::star::chart2::XDiagram >& xDiagram,
183         const ::com::sun::star::uno::Reference<
184             ::com::sun::star::uno::XComponentContext > & xContext,
185         bool bAdaptAxes=true );
186 
187     static ::com::sun::star::uno::Reference<
188 	        ::com::sun::star::chart2::XAxis > getAttachedAxis(
189         const ::com::sun::star::uno::Reference<
190 	        ::com::sun::star::chart2::XDataSeries >& xSeries,
191         const ::com::sun::star::uno::Reference<
192             ::com::sun::star::chart2::XDiagram >& xDiagram );
193 
194     static ::com::sun::star::uno::Reference<
195 	        ::com::sun::star::chart2::XChartType >
196 		getChartTypeOfSeries(
197 			const ::com::sun::star::uno::Reference<
198                 ::com::sun::star::chart2::XDiagram >& xDiagram,
199 			const ::com::sun::star::uno::Reference<
200 	            ::com::sun::star::chart2::XDataSeries >& xSeries );
201 
202     static ::std::vector<
203             ::com::sun::star::uno::Reference<
204             ::com::sun::star::chart2::XDataSeries > >
205         getDataSeriesFromDiagram(
206             const ::com::sun::star::uno::Reference<
207             ::com::sun::star::chart2::XDiagram > & xDiagram );
208 
209     /** return all data series in this diagram grouped by chart-types
210      */
211     static ::com::sun::star::uno::Sequence<
212                ::com::sun::star::uno::Sequence<
213                    ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries > > >
214         getDataSeriesGroups(
215             const ::com::sun::star::uno::Reference<
216             ::com::sun::star::chart2::XDiagram > & xDiagram );
217 
218     static bool isCategoryDiagram(
219             const ::com::sun::star::uno::Reference<
220                 ::com::sun::star::chart2::XDiagram >& xDiagram );
221 
222     static void setCategoriesToDiagram(
223             const ::com::sun::star::uno::Reference<
224                 ::com::sun::star::chart2::data::XLabeledDataSequence >& xCategories,
225             const ::com::sun::star::uno::Reference<
226                 ::com::sun::star::chart2::XDiagram >& xDiagram,
227             bool bSetAxisType = false, // when this flag is true ...
228             bool bCategoryAxis = true);// set the AxisType to CATEGORY or back to REALNUMBER
229 
230     static ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XLabeledDataSequence >
231         getCategoriesFromDiagram(
232             const ::com::sun::star::uno::Reference<
233                 ::com::sun::star::chart2::XDiagram > & xDiagram );
234 
235     static ::com::sun::star::uno::Sequence< rtl::OUString >
236         getExplicitSimpleCategories(
237             const ::com::sun::star::uno::Reference<
238                 ::com::sun::star::chart2::XChartDocument > & xChartDoc );
239 
240     SAL_DLLPRIVATE static ::com::sun::star::uno::Sequence< rtl::OUString >
241         generateAutomaticCategoriesFromCooSys(
242             const ::com::sun::star::uno::Reference<
243                 ::com::sun::star::chart2::XCoordinateSystem > & xCooSys );
244 
245     static void switchToDateCategories(
246         const ::com::sun::star::uno::Reference<
247                 ::com::sun::star::chart2::XChartDocument > & xChartDoc );
248 
249     static void switchToTextCategories(
250         const ::com::sun::star::uno::Reference<
251                 ::com::sun::star::chart2::XChartDocument > & xChartDoc );
252 
253     static bool isSupportingDateAxis( const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDiagram >& xDiagram );
254     static bool isDateNumberFormat( sal_Int32 nNumberFormat, const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormats >& xNumberFormats );
255     static sal_Int32 getDateNumberFormat( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier >& xNumberFormatsSupplier );
256 
257     static sal_Int32 getPercentNumberFormat( const ::com::sun::star::uno::Reference<
258                 ::com::sun::star::util::XNumberFormatsSupplier >& xNumberFormatsSupplier );
259 
260     static ::com::sun::star::uno::Reference<
261             ::com::sun::star::chart2::XChartType >
262         getChartTypeByIndex( const ::com::sun::star::uno::Reference<
263             ::com::sun::star::chart2::XDiagram >& xDiagram, sal_Int32 nIndex );
264 
265     static ::com::sun::star::uno::Sequence<
266             ::com::sun::star::uno::Reference<
267                 ::com::sun::star::chart2::XChartType > >
268         getChartTypesFromDiagram(
269             const ::com::sun::star::uno::Reference<
270                 ::com::sun::star::chart2::XDiagram > & xDiagram );
271 
272     SAL_DLLPRIVATE static bool areChartTypesCompatible( const ::com::sun::star::uno::Reference<
273                 ::com::sun::star::chart2::XChartType >& xFirstType,
274                 const ::com::sun::star::uno::Reference<
275                 ::com::sun::star::chart2::XChartType >& xSecondType );
276 
277 
278     /**
279         * Test if a series can be moved.
280         *
281         * @param xDiagram
282         *  Reference to the diagram that contains the series.
283         *
284         * @param xGivenDataSeries
285         *  Reference to the series that should be tested for moving.
286         *
287         * @param bForward
288         *  Direction of the move to be checked.
289         *
290         * @returns </sal_True> if the series can be moved.
291         *
292         */
293     static bool isSeriesMoveable(
294             const ::com::sun::star::uno::Reference<
295                 ::com::sun::star::chart2::XDiagram >& xDiagram,
296             const ::com::sun::star::uno::Reference<
297         ::com::sun::star::chart2::XDataSeries >& xGivenDataSeries,
298             bool bForward );
299 
300     /**
301         * Move a series forward or backward.
302         *
303         * @param xDiagram
304         *  Reference to the diagram that contains the series.
305         *
306         * @param xGivenDataSeries
307         *  Reference to the series that should be moved.
308         *
309         * @param bForward
310         *  Direction in which the series should be moved.
311         *
312         * @returns </sal_True> if the series was moved successfully.
313         *
314         */
315     static bool moveSeries(
316                 const ::com::sun::star::uno::Reference<
317                   ::com::sun::star::chart2::XDiagram >& xDiagram,
318                 const ::com::sun::star::uno::Reference<
319           ::com::sun::star::chart2::XDataSeries >& xGivenDataSeries,
320                 bool bForward );
321 
322     static bool isSupportingFloorAndWall( const ::com::sun::star::uno::Reference<
323                 ::com::sun::star::chart2::XDiagram > & xDiagram );
324 
325     static bool isPieOrDonutChart( const ::com::sun::star::uno::Reference<
326                 ::com::sun::star::chart2::XDiagram >& xDiagram );
327 
328     static sal_Int32 getGeometry3D(
329         const ::com::sun::star::uno::Reference<
330             ::com::sun::star::chart2::XDiagram > & xDiagram,
331         bool& rbFound, bool& rbAmbiguous );
332 
333     static void setGeometry3D(
334         const ::com::sun::star::uno::Reference<
335             ::com::sun::star::chart2::XDiagram > & xDiagram,
336         sal_Int32 nNewGeometry );
337 
338     //returns integer from constant group ::com::sun::star::chart::MissingValueTreatment
339     static sal_Int32 getCorrectedMissingValueTreatment(
340             const ::com::sun::star::uno::Reference<
341                 ::com::sun::star::chart2::XDiagram > & xDiagram,
342             const ::com::sun::star::uno::Reference<
343                 ::com::sun::star::chart2::XChartType >& xChartType );
344 
345     static DiagramPositioningMode getDiagramPositioningMode( const ::com::sun::star::uno::Reference<
346                 ::com::sun::star::chart2::XDiagram > & xDiagram );
347 
348     static bool setDiagramPositioning( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& xChartModel,
349         const ::com::sun::star::awt::Rectangle& rPosRect /*100th mm*/ );
350 
351     static ::com::sun::star::awt::Rectangle getDiagramRectangleFromModel( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& xChartModel );
352 
353     static bool switchDiagramPositioningToExcludingPositioning( const ::com::sun::star::uno::Reference<
354         ::com::sun::star::frame::XModel >& xChartModel
355         , bool bResetModifiedState //set model back to unchanged if it was unchanged before
356         , bool bConvertAlsoFromAutoPositioning );
357 
358 private:
359     // not implemented
360     DiagramHelper();
361 
362 };
363 
364 } //  namespace chart
365 
366 // CHART2_DIAGRAMHELPER_HXX
367 #endif
368