Avoid potential negative array index access to cached text.
[LibreOffice.git] / chart2 / source / inc / ObjectIdentifier.hxx
blobc6d0c724bd3c696fdebc720a77054764184a42de
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 #pragma once
21 #include <sal/config.h>
23 #include <string_view>
25 #include "TitleHelper.hxx"
26 #include "charttoolsdllapi.hxx"
28 #include <rtl/ustring.hxx>
29 #include <rtl/ref.hxx>
31 namespace chart { class ChartModel; }
32 namespace com::sun::star::awt { struct Point; }
33 namespace com::sun::star::beans { class XPropertySet; }
34 namespace com::sun::star::chart2 { class XAxis; }
35 namespace com::sun::star::chart2 { class XChartDocument; }
36 namespace com::sun::star::chart2 { class XCoordinateSystem; }
37 namespace com::sun::star::chart2 { class XDataSeries; }
38 namespace com::sun::star::chart2 { class XDiagram; }
39 namespace com::sun::star::drawing { class XShape; }
40 namespace com::sun::star::frame { class XModel; }
41 namespace com::sun::star::uno { class XInterface; }
43 namespace chart
45 class Axis;
46 class BaseCoordinateSystem;
47 class DataSeries;
48 class Diagram;
49 class Legend;
51 enum ObjectType
53 OBJECTTYPE_PAGE,
54 OBJECTTYPE_TITLE,
55 OBJECTTYPE_LEGEND,
56 OBJECTTYPE_LEGEND_ENTRY,
57 OBJECTTYPE_DIAGRAM,
58 OBJECTTYPE_DIAGRAM_WALL,
59 OBJECTTYPE_DIAGRAM_FLOOR,
60 OBJECTTYPE_AXIS,
61 OBJECTTYPE_AXIS_UNITLABEL,
62 OBJECTTYPE_GRID,
63 OBJECTTYPE_SUBGRID,
64 OBJECTTYPE_DATA_SERIES,
65 OBJECTTYPE_DATA_POINT,
66 OBJECTTYPE_DATA_LABELS,
67 OBJECTTYPE_DATA_LABEL,
68 OBJECTTYPE_DATA_ERRORS_X,
69 OBJECTTYPE_DATA_ERRORS_Y,
70 OBJECTTYPE_DATA_ERRORS_Z,
71 OBJECTTYPE_DATA_CURVE,//e.g. a statistical method printed as line
72 OBJECTTYPE_DATA_AVERAGE_LINE,
73 OBJECTTYPE_DATA_CURVE_EQUATION,
74 OBJECTTYPE_DATA_STOCK_RANGE,
75 OBJECTTYPE_DATA_STOCK_LOSS,
76 OBJECTTYPE_DATA_STOCK_GAIN,
77 OBJECTTYPE_DATA_TABLE,
78 OBJECTTYPE_SHAPE,
79 OBJECTTYPE_UNKNOWN
82 class OOO_DLLPUBLIC_CHARTTOOLS ObjectIdentifier
84 //CID == ClassifiedIdentifier <--> name of shape
85 //semicolon, colon, equal sign and slash have special meanings in a CID
86 //and are therefore not allowed in its components
88 //syntax of a CID: CID:/classification/ObjectID
90 //where classification: nothing or "MultiClick" or "DragMethod=DragMethodServiceName" and "DragParameter=DragParameterString"
91 // or a combination of these separated with a colon
92 //where DragMethodServiceName can be a selfdefined servicename for special actions //todo define standard service for this purpose
93 //where DragParameterString is any string you like to transport information to your special drag service
94 // only semicolon, colon, equal sign and slash are not allowed characters
95 // also the keywords used in the ObjectIdentifiers are not allowed
97 //where ObjectID: Parent-Particle:Particle //e.g. Series=2:Point=22
98 //where Particle: Type=ParticleID //e.g. Point=22
99 //where Type: getStringForType( ObjectType eType ) or other string
101 public:
102 ObjectIdentifier();
103 ObjectIdentifier( OUString aObjectCID );
104 ObjectIdentifier( const css::uno::Reference< css::drawing::XShape >& rxShape );
105 ObjectIdentifier( const css::uno::Any& rAny );
107 bool operator==( const ObjectIdentifier& rOID ) const;
108 bool operator!=( const ObjectIdentifier& rOID ) const;
109 bool operator<( const ObjectIdentifier& rOID ) const;
111 static OUString createClassifiedIdentifierForObject(
112 const css::uno::Reference< css::uno::XInterface >& xObject
113 , const rtl::Reference<::chart::ChartModel>& xChartModel );
114 static OUString createClassifiedIdentifierForObject(
115 const rtl::Reference< ::chart::Title >& xObject
116 , const rtl::Reference<::chart::ChartModel>& xChartModel );
117 static OUString createClassifiedIdentifierForObject(
118 const rtl::Reference< ::chart::Legend >& xObject
119 , const rtl::Reference<::chart::ChartModel>& xChartModel );
120 static OUString createClassifiedIdentifierForObject(
121 const rtl::Reference< ::chart::Axis >& xObject
122 , const rtl::Reference<::chart::ChartModel>& xChartModel );
124 static OUString createClassifiedIdentifierForParticle(
125 std::u16string_view rParticle );
127 static OUString createClassifiedIdentifierForParticles(
128 std::u16string_view rParentParticle
129 , std::u16string_view rChildParticle
130 , std::u16string_view rDragMethodServiceName = std::u16string_view()
131 , std::u16string_view rDragParameterString = std::u16string_view() );
133 static OUString createClassifiedIdentifierForGrid(
134 const css::uno::Reference< css::chart2::XAxis >& xAxis
135 , const rtl::Reference<::chart::ChartModel>& xChartModel
136 , sal_Int32 nSubIndex = -1 );//-1: main grid, 0: first subgrid etc
138 SAL_DLLPRIVATE static OUString createParticleForDiagram();
140 static OUString createParticleForCoordinateSystem(
141 const rtl::Reference< ::chart::BaseCoordinateSystem >& xCooSys
142 , const rtl::Reference<::chart::ChartModel>& xChartModel );
144 static OUString createParticleForAxis(
145 sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex );
147 static OUString createParticleForGrid(
148 sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex );
150 static OUString createParticleForSeries( sal_Int32 nDiagramIndex, sal_Int32 nCooSysIndex
151 , sal_Int32 nChartTypeIndex, sal_Int32 nSeriesIndex );
153 static OUString createParticleForLegend(
154 const rtl::Reference<::chart::ChartModel>& xChartModel );
156 /** Creates an identifier for the data table */
157 static OUString createParticleForDataTable(
158 const rtl::Reference<::chart::ChartModel>& xChartModel );
160 static OUString addChildParticle( std::u16string_view rParticle, std::u16string_view rChildParticle );
161 static OUString createChildParticleWithIndex( ObjectType eObjectType, sal_Int32 nIndex );
162 static sal_Int32 getIndexFromParticleOrCID( std::u16string_view rParticleOrCID );
164 static OUString createClassifiedIdentifier(
165 enum ObjectType eObjectType //e.g. OBJECTTYPE_DATA_SERIES
166 , std::u16string_view rParticleID );//e.g. SeriesID
168 static OUString createClassifiedIdentifierWithParent(
169 enum ObjectType //e.g. OBJECTTYPE_DATA_POINT or OBJECTTYPE_GRID
170 , std::u16string_view rParticleID //for points or subgrids this is an Index or otherwise an identifier from the model object
171 , std::u16string_view rParentPartical //e.g. "Series=SeriesID" or "Grid=GridId"
172 , std::u16string_view rDragMethodServiceName = std::u16string_view()
173 , std::u16string_view rDragParameterString = std::u16string_view()
176 static bool isCID( std::u16string_view rName );
177 static std::u16string_view getDragMethodServiceName( std::u16string_view rClassifiedIdentifier );
178 static std::u16string_view getDragParameterString( std::u16string_view rCID );
179 static bool isDragableObject( std::u16string_view rClassifiedIdentifier );
180 bool isDragableObject() const;
181 static bool isRotateableObject( std::u16string_view rClassifiedIdentifier );
182 static bool isMultiClickObject( std::u16string_view rClassifiedIdentifier );
183 static bool areSiblings( std::u16string_view rCID1, std::u16string_view rCID2 );//identical object is no sibling
184 static bool areIdenticalObjects( std::u16string_view rCID1, std::u16string_view rCID2 );
186 static OUString getStringForType( ObjectType eObjectType );
187 static ObjectType getObjectType( std::u16string_view rCID );
188 ObjectType getObjectType() const;
190 static OUString createSeriesSubObjectStub( ObjectType eSubObjectType
191 , std::u16string_view rSeriesParticle
192 , std::u16string_view rDragMethodServiceName = std::u16string_view()
193 , std::u16string_view rDragParameterString = std::u16string_view() );
194 static OUString createPointCID( std::u16string_view rPointCID_Stub, sal_Int32 nIndex );
196 static OUString createDataCurveCID( std::u16string_view rSeriesParticle, sal_Int32 nCurveIndex, bool bAverageLine );
197 static OUString createDataCurveEquationCID( std::u16string_view rSeriesParticle, sal_Int32 nCurveIndex );
199 SAL_DLLPRIVATE static OUString getObjectID( std::u16string_view rCID );
200 static std::u16string_view getParticleID( std::u16string_view rCID );
201 static std::u16string_view getFullParentParticle( std::u16string_view rCID );
203 //returns the series particle of a CID when the CID is a child of the series
204 static OUString getSeriesParticleFromCID( std::u16string_view rCID );
206 //return the model object that is indicated by rObjectCID
207 static css::uno::Reference< css::beans::XPropertySet >
208 getObjectPropertySet(
209 std::u16string_view rObjectCID
210 , const rtl::Reference< ::chart::ChartModel >& xChartDocument );
212 //return the axis object that belongs to rObjectCID if any
213 static rtl::Reference< ::chart::Axis >
214 getAxisForCID(
215 std::u16string_view rObjectCID
216 , const rtl::Reference<::chart::ChartModel>& xChartModel );
218 //return the series object that belongs to rObjectCID if any
219 static rtl::Reference< ::chart::DataSeries >
220 getDataSeriesForCID(
221 std::u16string_view rObjectCID
222 , const rtl::Reference<::chart::ChartModel>& xChartModel );
224 static rtl::Reference< ::chart::Diagram >
225 getDiagramForCID(
226 std::u16string_view rObjectCID
227 , const rtl::Reference<::chart::ChartModel>& xChartModel );
229 static const OUString& getPieSegmentDragMethodServiceName();
230 static OUString createPieSegmentDragParameterString(
231 sal_Int32 nOffsetPercent
232 , const css::awt::Point& rMinimumPosition
233 , const css::awt::Point& rMaximumPosition );
234 static bool parsePieSegmentDragParameterString( std::u16string_view rDragParameterString
235 , sal_Int32& rOffsetPercent
236 , css::awt::Point& rMinimumPosition
237 , css::awt::Point& rMaximumPosition );
239 static TitleHelper::eTitleType getTitleTypeForCID( std::u16string_view rCID );
241 static OUString getMovedSeriesCID( std::u16string_view rObjectCID, bool bForward );
243 bool isValid() const;
244 bool isAutoGeneratedObject() const;
245 bool isAdditionalShape() const;
246 const OUString& getObjectCID() const { return m_aObjectCID;}
247 const css::uno::Reference< css::drawing::XShape >& getAdditionalShape() const { return m_xAdditionalShape;}
248 css::uno::Any getAny() const;
250 private:
251 // #i12587# support for shapes in chart
252 // For autogenerated chart objects a CID is specified in m_aObjectCID,
253 // for all other objects m_xAdditionalShape is set.
254 // Note, that if m_aObjectCID is set, m_xAdditionalShape must be empty
255 // and vice versa.
256 OUString m_aObjectCID;
257 css::uno::Reference< css::drawing::XShape > m_xAdditionalShape;
260 } //namespace chart
262 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */