tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / sc / source / filter / inc / xichart.hxx
bloba4edbba1881dc723072c232bea5bc6cb939576f6
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 .
20 #pragma once
22 #include <salhelper/simplereferenceobject.hxx>
23 #include <set>
24 #include <map>
25 #include <memory>
26 #include <vector>
28 #include <types.hxx>
29 #include "xlchart.hxx"
30 #include "xlstyle.hxx"
31 #include "xiescher.hxx"
32 #include "xistring.hxx"
34 namespace com::sun::star {
35 namespace awt
37 struct Rectangle;
39 namespace frame
41 class XModel;
43 namespace drawing
45 class XShape;
47 namespace chart2
49 struct ScaleData;
50 class XChartDocument;
51 class XDiagram;
52 class XCoordinateSystem;
53 class XChartType;
54 class XDataSeries;
55 class XRegressionCurve;
56 class XAxis;
57 class XLegend;
58 class XTitle;
59 class XFormattedString;
60 namespace data
62 class XDataProvider;
63 class XDataSequence;
64 class XLabeledDataSequence;
69 struct XclObjLineData;
70 struct XclObjFillData;
72 // Common =====================================================================
74 struct XclImpChRootData;
75 class XclImpChChart;
76 class ScTokenArray;
78 /** Base class for complex chart classes, provides access to other components of the chart. */
79 class XclImpChRoot : public XclImpRoot
81 public:
82 explicit XclImpChRoot( const XclImpRoot& rRoot, XclImpChChart& rChartData );
83 virtual ~XclImpChRoot() override;
85 XclImpChRoot(XclImpChRoot const &) = default;
86 XclImpChRoot(XclImpChRoot &&) = default;
87 XclImpChRoot & operator =(XclImpChRoot const &) = delete; // due to XclImpRoot
88 XclImpChRoot & operator =(XclImpChRoot &&) = delete; // due to XclImpRoot
90 /** Returns this root instance - for code readability in derived classes. */
91 const XclImpChRoot& GetChRoot() const { return *this; }
92 /** Returns a reference to the parent chart data object. */
93 XclImpChChart& GetChartData() const;
94 /** Returns chart type info for a unique chart type identifier. */
95 const XclChTypeInfo& GetChartTypeInfo( XclChTypeId eType ) const;
96 /** Returns the first fitting chart type info for an Excel chart type record identifier. */
97 const XclChTypeInfo& GetChartTypeInfo( sal_uInt16 nRecId ) const;
98 /** Returns an info struct about auto formatting for the passed object type. */
99 const XclChFormatInfo& GetFormatInfo( XclChObjectType eObjType ) const;
101 /** Returns the default text color for charts. */
102 Color GetFontAutoColor() const;
103 /** Returns the automatic line color of linear series. */
104 Color GetSeriesLineAutoColor( sal_uInt16 nFormatIdx ) const;
105 /** Returns the automatic fill color of filled series. */
106 Color GetSeriesFillAutoColor( sal_uInt16 nFormatIdx ) const;
108 /** Starts the API chart document conversion. Must be called once before all API conversion. */
109 void InitConversion(
110 const css::uno::Reference< css::chart2::XChartDocument>& xChartDoc,
111 const tools::Rectangle& rChartRect ) const;
113 /** Finishes the API chart document conversion. Must be called once after all API conversion. */
114 void FinishConversion( XclImpDffConverter& rDffConv ) const;
116 /** Returns the data provider for the chart document. */
117 css::uno::Reference< css::chart2::data::XDataProvider >
118 GetDataProvider() const;
119 /** Returns the drawing shape interface of the specified title object. */
120 css::uno::Reference< css::drawing::XShape >
121 GetTitleShape( const XclChTextKey& rTitleKey ) const;
123 /** Converts the passed horizontal coordinate from Excel chart units into 1/100 mm. */
124 sal_Int32 CalcHmmFromChartX( sal_Int32 nPosX ) const;
125 /** Converts the passed vertical coordinate from Excel chart units into 1/100 mm. */
126 sal_Int32 CalcHmmFromChartY( sal_Int32 nPosY ) const;
127 /** Converts the passed rectangle from Excel chart units into 1/100 mm. */
128 css::awt::Rectangle CalcHmmFromChartRect( const XclChRectangle& rRect ) const;
130 /** Converts the passed horizontal coordinate from 1/100 mm into a relative position. */
131 double CalcRelativeFromHmmX( sal_Int32 nPosX ) const;
132 /** Converts the passed vertical coordinate from 1/100 mm into a relative position. */
133 double CalcRelativeFromHmmY( sal_Int32 nPosY ) const;
135 /** Converts the passed horizontal coordinate from Excel chart units into a relative position. */
136 double CalcRelativeFromChartX( sal_Int32 nPosX ) const;
137 /** Converts the passed vertical coordinate from Excel chart units into a relative position. */
138 double CalcRelativeFromChartY( sal_Int32 nPosY ) const;
140 /** Writes all line properties to the passed property set. */
141 void ConvertLineFormat(
142 ScfPropertySet& rPropSet,
143 const XclChLineFormat& rLineFmt,
144 XclChPropertyMode ePropMode ) const;
145 /** Writes solid area properties to the passed property set. */
146 void ConvertAreaFormat(
147 ScfPropertySet& rPropSet,
148 const XclChAreaFormat& rAreaFmt,
149 XclChPropertyMode ePropMode ) const;
150 /** Writes gradient or bitmap area properties to the passed property set. */
151 void ConvertEscherFormat(
152 ScfPropertySet& rPropSet,
153 const XclChEscherFormat& rEscherFmt,
154 const XclChPicFormat* pPicFmt,
155 sal_uInt32 nDffFillType,
156 XclChPropertyMode ePropMode ) const;
157 /** Writes font properties to the passed property set. */
158 void ConvertFont(
159 ScfPropertySet& rPropSet,
160 sal_uInt16 nFontIdx,
161 const Color* pFontColor = nullptr ) const;
163 /** Writes the pie rotation property for the passed angle. */
164 static void ConvertPieRotation(
165 ScfPropertySet& rPropSet,
166 sal_uInt16 nAngle );
168 private:
169 typedef std::shared_ptr< XclImpChRootData > XclImpChRootDataRef;
170 XclImpChRootDataRef mxChData; /// Reference to the root data object.
173 /** Base class for chart record groups. Provides helper functions to read sub records.
175 A chart record group consists of a header record, followed by a CHBEGIN
176 record, followed by group sub records, and finished with a CHEND record.
178 class XclImpChGroupBase
180 public:
181 XclImpChGroupBase() = default;
182 XclImpChGroupBase(XclImpChGroupBase const &) = default;
183 XclImpChGroupBase(XclImpChGroupBase &&) = default;
184 XclImpChGroupBase & operator =(XclImpChGroupBase const &) = default;
185 XclImpChGroupBase & operator =(XclImpChGroupBase &&) = default;
187 virtual ~XclImpChGroupBase();
189 /** Reads the entire record group.
190 @descr First calls ReadHeaderRecord() to read the contents of the
191 header record. Then tries to read the sub records. If next record
192 is a CHBEGIN record, ReadSubRecord() is called for each following
193 record until a CHEND record is found. */
194 void ReadRecordGroup( XclImpStream& rStrm );
196 /** Helper to skip a CHBEGIN/CHEND block, includes nested blocks. */
197 static void SkipBlock( XclImpStream& rStrm );
199 /** Derived classes implement to read the group header record. */
200 virtual void ReadHeaderRecord( XclImpStream& rStrm ) = 0;
201 /** Derived classes implement to read a record from the group. */
202 virtual void ReadSubRecord( XclImpStream& rStrm ) = 0;
205 // Frame formatting ===========================================================
207 class XclImpChFramePos
209 public:
210 /** Reads the CHFRAMEPOS record (frame position and size). */
211 void ReadChFramePos( XclImpStream& rStrm );
213 /** Returns read-only access to the imported frame position data. */
214 const XclChFramePos& GetFramePosData() const { return maData; }
216 private:
217 XclChFramePos maData; /// Position of the frame.
220 typedef std::shared_ptr< XclImpChFramePos > XclImpChFramePosRef;
222 /** The CHLINEFORMAT record containing line formatting data. */
223 class XclImpChLineFormat : public salhelper::SimpleReferenceObject
225 public:
226 /** Creates a new line format object with automatic formatting. */
227 explicit XclImpChLineFormat() {}
228 /** Creates a new line format object with the passed formatting. */
229 explicit XclImpChLineFormat( const XclChLineFormat& rLineFmt ) : maData( rLineFmt ) {}
231 // this class is stored both ref-counted and by value
232 XclImpChLineFormat(XclImpChLineFormat const & rOther)
233 : salhelper::SimpleReferenceObject(), maData(rOther.maData) {}
234 XclImpChLineFormat(XclImpChLineFormat && rOther)
235 : salhelper::SimpleReferenceObject(), maData(std::move(rOther.maData)) {}
236 XclImpChLineFormat& operator=(XclImpChLineFormat const & rOther)
237 { maData = rOther.maData; return *this; }
238 XclImpChLineFormat& operator=(XclImpChLineFormat && rOther) noexcept
239 { maData = std::move(rOther.maData); return *this; }
241 /** Reads the CHLINEFORMAT record (basic line properties). */
242 void ReadChLineFormat( XclImpStream& rStrm );
244 /** Returns true, if the line format is set to automatic. */
245 bool IsAuto() const { return ::get_flag( maData.mnFlags, EXC_CHLINEFORMAT_AUTO ); }
246 /** Returns true, if the line style is set to something visible. */
247 bool HasLine() const { return IsAuto() || (maData.mnPattern != EXC_CHLINEFORMAT_NONE); }
248 /** Returns the line width of this line format (returns 'single', if the line is invisible). */
249 sal_Int16 GetWeight() const { return (IsAuto() || !HasLine()) ? EXC_CHLINEFORMAT_SINGLE : maData.mnWeight; }
250 /** Returns true, if the "show axis" flag is set. */
251 bool IsShowAxis() const { return ::get_flag( maData.mnFlags, EXC_CHLINEFORMAT_SHOWAXIS ); }
253 /** Converts and writes the contained data to the passed property set. */
254 void Convert( const XclImpChRoot& rRoot,
255 ScfPropertySet& rPropSet, XclChObjectType eObjType,
256 sal_uInt16 nFormatIdx = EXC_CHDATAFORMAT_UNKNOWN ) const;
258 private:
259 XclChLineFormat maData; /// Contents of the CHLINEFORMAT record.
262 typedef rtl::Reference< XclImpChLineFormat > XclImpChLineFormatRef;
264 /** The CHAREAFORMAT record containing simple area formatting data (solid or patterns). */
265 class XclImpChAreaFormat
267 public:
268 /** Creates a new area format object with automatic formatting. */
269 explicit XclImpChAreaFormat() {}
270 /** Creates a new area format object with the passed formatting. */
271 explicit XclImpChAreaFormat( const XclChAreaFormat& rAreaFmt ) : maData( rAreaFmt ) {}
273 /** Reads the CHAREAFORMAT record (basic fill properties, e.g. transparent or colored). */
274 void ReadChAreaFormat( XclImpStream& rStrm );
276 /** Returns true, if the area format is set to automatic. */
277 bool IsAuto() const { return ::get_flag( maData.mnFlags, EXC_CHAREAFORMAT_AUTO ); }
278 /** Returns true, if the area style is set to something visible. */
279 bool HasArea() const { return IsAuto() || (maData.mnPattern != EXC_PATT_NONE); }
281 /** Converts and writes the contained data to the passed property set. */
282 void Convert( const XclImpChRoot& rRoot,
283 ScfPropertySet& rPropSet, XclChObjectType eObjType,
284 sal_uInt16 nFormatIdx ) const;
286 private:
287 XclChAreaFormat maData; /// Contents of the CHAREAFORMAT record.
290 typedef std::shared_ptr< XclImpChAreaFormat > XclImpChAreaFormatRef;
292 /** The CHESCHERFORMAT record containing complex area formatting data (bitmaps, hatches). */
293 class XclImpChEscherFormat : public XclImpChGroupBase
295 public:
296 explicit XclImpChEscherFormat( const XclImpRoot& rRoot );
298 /** Reads the CHESCHERFORMAT record (complex fill data) (called by base class). */
299 virtual void ReadHeaderRecord( XclImpStream& rStrm ) override;
300 /** Reads a record from the CHESCHERFORMAT group (called by base class). */
301 virtual void ReadSubRecord( XclImpStream& rStrm ) override;
303 /** Converts and writes the contained data to the passed property set. */
304 void Convert( const XclImpChRoot& rRoot, ScfPropertySet& rPropSet,
305 XclChObjectType eObjType, bool bUsePicFmt ) const;
307 private:
308 XclChEscherFormat maData; /// Fill properties for complex areas (CHESCHERFORMAT record).
309 XclChPicFormat maPicFmt; /// Image options, e.g. stretched, stacked (CHPICFORMAT record).
310 sal_uInt32 mnDffFillType; /// Fill type imported from the DFF property set.
313 typedef std::shared_ptr< XclImpChEscherFormat > XclImpChEscherFormatRef;
315 /** Base class for record groups containing frame formatting.
317 Frame formatting can be part of several record groups, e.g. CHFRAME,
318 CHDATAFORMAT, CHDROPBAR. It consists of CHLINEFORMAT, CHAREAFORMAT, and
319 CHESCHERFORMAT group.
321 class XclImpChFrameBase : public XclImpChGroupBase
323 public:
324 /** Creates a new frame object without internal formatting objects. */
325 explicit XclImpChFrameBase() {}
326 /** Creates a new frame object with specific default formatting. */
327 explicit XclImpChFrameBase( const XclChFormatInfo& rFmtInfo );
329 /** Reads a frame formatting record (called by base class). */
330 virtual void ReadSubRecord( XclImpStream& rStrm ) override;
332 /** Returns true, if the line format is set to automatic. */
333 bool IsAutoLine() const { return !mxLineFmt || mxLineFmt->IsAuto(); }
334 /** Returns true, if the line style is set to something visible. */
335 bool HasLine() const { return IsAutoLine() || mxLineFmt->HasLine(); }
336 /** Returns the line weight used for this frame. */
337 sal_Int16 GetLineWeight() const { return mxLineFmt ? mxLineFmt->GetWeight() : EXC_CHLINEFORMAT_SINGLE; }
339 /** Returns true, if the area format is set to automatic. */
340 bool IsAutoArea() const { return !mxEscherFmt && (!mxAreaFmt || mxAreaFmt->IsAuto()); }
342 protected:
343 /** Converts and writes the contained line formatting to the passed property set. */
344 void ConvertLineBase( const XclImpChRoot& rRoot,
345 ScfPropertySet& rPropSet, XclChObjectType eObjType,
346 sal_uInt16 nFormatIdx = EXC_CHDATAFORMAT_UNKNOWN ) const;
347 /** Converts and writes the contained area formatting to the passed property set. */
348 void ConvertAreaBase( const XclImpChRoot& rRoot,
349 ScfPropertySet& rPropSet, XclChObjectType eObjType,
350 sal_uInt16 nFormatIdx = EXC_CHDATAFORMAT_UNKNOWN, bool bUsePicFmt = false ) const;
351 /** Converts and writes the contained data to the passed property set. */
352 void ConvertFrameBase( const XclImpChRoot& rRoot,
353 ScfPropertySet& rPropSet, XclChObjectType eObjType,
354 sal_uInt16 nFormatIdx = EXC_CHDATAFORMAT_UNKNOWN, bool bUsePicFmt = false ) const;
356 protected:
357 XclImpChLineFormatRef mxLineFmt; /// Line format (CHLINEFORMAT record).
358 XclImpChAreaFormatRef mxAreaFmt; /// Area format (CHAREAFORMAT record).
359 XclImpChEscherFormatRef mxEscherFmt; /// Complex area format (CHESCHERFORMAT record).
362 /** Represents the CHFRAME record group containing object frame properties.
364 The CHFRAME group consists of: CHFRAME, CHBEGIN, CHLINEFORMAT,
365 CHAREAFORMAT, CHESCHERFORMAT group, CHEND.
367 class XclImpChFrame : public XclImpChFrameBase, protected XclImpChRoot
369 public:
370 /** Creates a new frame object with specific default formatting. */
371 explicit XclImpChFrame(
372 const XclImpChRoot& rRoot,
373 XclChObjectType eObjType );
375 /** Reads the CHFRAME record (called by base class). */
376 virtual void ReadHeaderRecord( XclImpStream& rStrm ) override;
378 /** Sets formatting from BIFF3-BIFF5 OBJ record, if own formatting is invisible. */
379 void UpdateObjFrame( const XclObjLineData& rLineData, const XclObjFillData& rFillData );
381 /** Converts and writes the contained data to the passed property set. */
382 void Convert( ScfPropertySet& rPropSet, bool bUsePicFmt = false ) const;
384 private:
385 XclChFrame maData; /// Contents of the CHFRAME record.
386 XclChObjectType meObjType; /// Type of the represented object.
389 typedef std::shared_ptr< XclImpChFrame > XclImpChFrameRef;
391 // Source links ===============================================================
393 class XclImpChSourceLink : protected XclImpChRoot
395 public:
396 explicit XclImpChSourceLink( const XclImpChRoot& rRoot );
397 virtual ~XclImpChSourceLink() override;
399 /** Reads the CHSOURCELINK record (link to source data). */
400 void ReadChSourceLink( XclImpStream& rStrm );
401 /** Sets explicit string data for this text object. */
402 void SetString( const OUString& rString );
403 /** Sets formatting runs read from a CHFORMATRUNS record. */
404 void SetTextFormats( XclFormatRunVec&& rFormats );
406 /** Returns the destination object (title, values, category, ...). */
407 sal_uInt8 GetDestType() const { return maData.mnDestType; }
408 /** Returns the link type (to worksheet, directly, default, ...). */
409 sal_uInt8 GetLinkType() const { return maData.mnLinkType; }
411 /** Returns true, if the source link contains explicit string data. */
412 bool HasString() const { return mxString && !mxString->IsEmpty(); }
413 /** Returns explicit string data or an empty string. */
414 const OUString & GetString() const {
415 if (mxString) return mxString->GetText();
416 return EMPTY_OUSTRING;
418 /** Returns the number of data points of this source link. */
419 sal_uInt16 GetCellCount() const;
421 /** Converts and writes the contained number format to the passed property set. */
422 void ConvertNumFmt( ScfPropertySet& rPropSet, bool bPercent ) const;
424 /** Creates a data sequence containing the link into the Calc document. */
425 css::uno::Reference< css::chart2::data::XDataSequence >
426 CreateDataSequence( const OUString& rRole ) const;
427 /** Creates a sequence of formatted string objects. */
428 css::uno::Sequence< css::uno::Reference< css::chart2::XFormattedString > >
429 CreateStringSequence( const XclImpChRoot& rRoot,
430 sal_uInt16 nLeadFontIdx, const Color& rLeadFontColor ) const;
432 void FillSourceLink(::std::vector<ScTokenRef>& rTokens) const;
434 private:
435 XclChSourceLink maData; /// Contents of the CHSOURCELINK record.
436 XclImpStringRef mxString; /// Text data (CHSTRING record).
437 std::shared_ptr< ScTokenArray> mxTokenArray; /// Token array representing the data ranges.
440 typedef std::shared_ptr< XclImpChSourceLink > XclImpChSourceLinkRef;
442 // Text =======================================================================
444 /** Base class for objects with font settings. Provides font conversion helper functions. */
445 class XclImpChFontBase
447 public:
448 XclImpChFontBase() = default;
449 XclImpChFontBase(XclImpChFontBase const &) = default;
450 XclImpChFontBase(XclImpChFontBase &&) = default;
451 XclImpChFontBase & operator =(XclImpChFontBase const &) = default;
452 XclImpChFontBase & operator =(XclImpChFontBase &&) = default;
454 virtual ~XclImpChFontBase();
456 /** Derived classes return the leading font index for the text object. */
457 virtual sal_uInt16 GetFontIndex() const = 0;
458 /** Derived classes return the leading font color for the text object. */
459 virtual Color GetFontColor() const = 0;
460 /** Derived classes return the rotation value for the text object. */
461 virtual sal_uInt16 GetRotation() const = 0;
463 /** Converts and writes the contained font settings to the passed property set. */
464 void ConvertFontBase( const XclImpChRoot& rRoot, ScfPropertySet& rPropSet ) const;
465 /** Converts and writes the contained rotation settings to the passed property set. */
466 void ConvertRotationBase( ScfPropertySet& rPropSet, bool bSupportsStacked ) const;
469 /** The CHFONT record containing a font index for text objects. */
470 class XclImpChFont
472 public:
473 explicit XclImpChFont();
474 /** Reads the CHFONT record (font index). */
475 void ReadChFont( XclImpStream& rStrm );
477 /** Returns the contained font index. */
478 sal_uInt16 GetFontIndex() const { return mnFontIdx; }
480 private:
481 sal_uInt16 mnFontIdx; /// Index into font buffer.
484 typedef std::shared_ptr< XclImpChFont > XclImpChFontRef;
486 /** Represents the CHTEXT record group containing text object properties.
488 The CHTEXT group consists of: CHTEXT, CHBEGIN, CHFRAMEPOS, CHFONT,
489 CHFORMATRUNS, CHSOURCELINK, CHSTRING, CHFRAME group, CHOBJECTLINK, and CHEND.
491 class XclImpChText : public XclImpChGroupBase, public XclImpChFontBase, protected XclImpChRoot
493 public:
494 explicit XclImpChText( const XclImpChRoot& rRoot );
496 /** Reads the CHTEXT record (called by base class). */
497 virtual void ReadHeaderRecord( XclImpStream& rStrm ) override;
498 /** Reads a record from the CHTEXT group (called by base class). */
499 virtual void ReadSubRecord( XclImpStream& rStrm ) override;
501 /** Returns the leading font index for the text object. */
502 virtual sal_uInt16 GetFontIndex() const override;
503 /** Returns the leading font color for the text object. */
504 virtual Color GetFontColor() const override;
505 /** Returns the rotation value for the text object. */
506 virtual sal_uInt16 GetRotation() const override;
508 /** Sets explicit string data for this text object. */
509 void SetString( const OUString& rString );
510 /** Updates missing parts of this text object from the passed object. */
511 void UpdateText( const XclImpChText* pParentText );
512 /** Updates display type of this data point label text object. */
513 void UpdateDataLabel( bool bCateg, bool bValue, bool bPercent );
515 /** Returns the target object this text is linked to. */
516 sal_uInt16 GetLinkTarget() const { return maObjLink.mnTarget; }
517 /** Returns the position of the data point label this text is linked to. */
518 const XclChDataPointPos& GetPointPos() const { return maObjLink.maPointPos; }
519 /** Returns true, if this text group contains string data. */
520 bool HasString() const { return mxSrcLink && mxSrcLink->HasString(); }
521 /** Returns true, if the text object is marked as deleted. */
522 bool IsDeleted() const { return ::get_flag( maData.mnFlags, EXC_CHTEXT_DELETED ); }
524 /** Converts and writes the contained font settings to the passed property set. */
525 void ConvertFont( ScfPropertySet& rPropSet ) const;
526 /** Converts and writes the contained rotation settings to the passed property set. */
527 void ConvertRotation( ScfPropertySet& rPropSet, bool bSupportsStacked ) const;
528 /** Converts and writes the contained frame data to the passed property set. */
529 void ConvertFrame( ScfPropertySet& rPropSet ) const;
530 /** Converts and writes the contained number format to the passed property set. */
531 void ConvertNumFmt( ScfPropertySet& rPropSet, bool bPercent ) const;
532 /** Converts and writes all contained data to the passed data point label property set. */
533 void ConvertDataLabel( ScfPropertySet& rPropSet, const XclChTypeInfo& rTypeInfo, const ScfPropertySet* pGlobalPropSet ) const;
534 /** Creates a title text object. */
535 css::uno::Reference< css::chart2::XTitle >
536 CreateTitle() const;
537 /** Converts the manual position of the specified title */
538 void ConvertTitlePosition( const XclChTextKey& rTitleKey ) const;
540 private:
541 using XclImpChRoot::ConvertFont;
543 /** Reads a CHFRLABELPROPS record. */
544 void ReadChFrLabelProps( XclImpStream& rStrm );
546 private:
547 typedef std::shared_ptr< XclChFrLabelProps > XclChFrLabelPropsRef;
549 XclChText maData; /// Contents of the CHTEXT record.
550 XclChObjectLink maObjLink; /// Link target for this text object.
551 XclFormatRunVec maFormats; /// Formatting runs (CHFORMATRUNS record).
552 XclImpChFramePosRef mxFramePos; /// Relative text frame position (CHFRAMEPOS record).
553 XclImpChSourceLinkRef mxSrcLink; /// Linked data (CHSOURCELINK with CHSTRING record).
554 XclImpChFrameRef mxFrame; /// Text object frame properties (CHFRAME group).
555 XclImpChFontRef mxFont; /// Index into font buffer (CHFONT record).
556 XclChFrLabelPropsRef mxLabelProps; /// Extended data label properties (CHFRLABELPROPS record).
559 typedef std::shared_ptr< XclImpChText > XclImpChTextRef;
561 // Data series ================================================================
563 /** The CHMARKERFORMAT record containing data point marker formatting data. */
564 class XclImpChMarkerFormat
566 public:
567 /** Reads the CHMARKERFORMAT record (data point marker properties). */
568 void ReadChMarkerFormat( XclImpStream& rStrm );
570 /** Returns true, if the marker format is set to automatic. */
571 bool IsAuto() const { return ::get_flag( maData.mnFlags, EXC_CHMARKERFORMAT_AUTO ); }
573 /** Converts and writes the contained data to the passed property set. */
574 void Convert( const XclImpChRoot& rRoot, ScfPropertySet& rPropSet,
575 sal_uInt16 nFormatIdx, sal_Int16 nLineWeight ) const;
576 /** Sets the marker fill color as main color to the passed property set. */
577 void ConvertColor( const XclImpChRoot& rRoot,
578 ScfPropertySet& rPropSet, sal_uInt16 nFormatIdx ) const;
580 private:
581 XclChMarkerFormat maData; /// Contents of the CHMARKERFORMAT record.
584 typedef std::shared_ptr< XclImpChMarkerFormat > XclImpChMarkerFormatRef;
586 /** The CHPIEFORMAT record containing data point formatting data for pie segments. */
587 class XclImpChPieFormat
589 public:
590 explicit XclImpChPieFormat();
591 /** Reads the CHPIEFORMAT record (pie segment properties). */
592 void ReadChPieFormat( XclImpStream& rStrm );
593 /** Converts and writes the contained data to the passed property set. */
594 void Convert( ScfPropertySet& rPropSet ) const;
596 private:
597 sal_uInt16 mnPieDist; /// Pie distance to diagram center.
600 typedef std::shared_ptr< XclImpChPieFormat > XclImpChPieFormatRef;
602 /** The CHSERIESFORMAT record containing additional settings for a data series. */
603 class XclImpChSeriesFormat
605 public:
606 explicit XclImpChSeriesFormat();
607 /** Reads the CHSERIESFORMAT record (additional settings for a series). */
608 void ReadChSeriesFormat( XclImpStream& rStrm );
609 /** Returns true, if the series line is smoothed. */
610 bool HasSpline() const { return ::get_flag( mnFlags, EXC_CHSERIESFORMAT_SMOOTHED ); }
612 private:
613 sal_uInt16 mnFlags; /// Additional flags.
616 typedef std::shared_ptr< XclImpChSeriesFormat > XclImpChSeriesFormatRef;
618 /** The CH3DDATAFORMAT record containing the bar type in 3D bar charts. */
619 class XclImpCh3dDataFormat
621 public:
622 /** Reads the CH3DDATAFORMAT record (3D bar properties). */
623 void ReadCh3dDataFormat( XclImpStream& rStrm );
624 /** Converts and writes the contained data to the passed property set. */
625 void Convert( ScfPropertySet& rPropSet ) const;
627 private:
628 XclCh3dDataFormat maData; /// Contents of the CH3DDATAFORMAT record.
631 typedef std::shared_ptr< XclImpCh3dDataFormat > XclImpCh3dDataFormatRef;
633 /** The CHATTACHEDLABEL record that contains the type of a data point label. */
634 class XclImpChAttachedLabel : protected XclImpChRoot
636 public:
637 explicit XclImpChAttachedLabel( const XclImpChRoot& rRoot );
638 /** Reads the CHATTACHEDLABEL record (data series/point labels). */
639 void ReadChAttachedLabel( XclImpStream& rStrm );
640 /** Creates a CHTEXT group for the label. Clones xParentText and sets additional label settings */
641 XclImpChTextRef CreateDataLabel( const XclImpChText* pParent ) const;
643 private:
644 sal_uInt16 mnFlags; /// Additional flags.
647 typedef std::shared_ptr< XclImpChAttachedLabel > XclImpChAttLabelRef;
649 /** Represents the CHDATAFORMAT record group containing data point properties.
651 The CHDATAFORMAT group consists of: CHDATAFORMAT, CHBEGIN, CHFRAME group,
652 CHMARKERFORMAT, CHPIEFORMAT, CH3DDATAFORMAT, CHSERIESFORMAT,
653 CHATTACHEDLABEL, CHEND.
655 class XclImpChDataFormat : public XclImpChFrameBase, protected XclImpChRoot
657 public:
658 explicit XclImpChDataFormat( const XclImpChRoot& rRoot );
660 /** Reads the CHDATAFORMAT record (called by base class). */
661 virtual void ReadHeaderRecord( XclImpStream& rStrm ) override;
662 /** Reads a record from the CHDATAFORMAT group (called by base class). */
663 virtual void ReadSubRecord( XclImpStream& rStrm ) override;
665 /** Sets this object to the specified data point position. */
666 void SetPointPos( const XclChDataPointPos& rPointPos, sal_uInt16 nFormatIdx );
667 /** Sets type and text formatting for a data point label (CHTEXT group). */
668 void SetDataLabel(const XclImpChTextRef& xLabel) { mxLabel = xLabel; }
670 /** Updates default data format for series group. */
671 void UpdateGroupFormat( const XclChExtTypeInfo& rTypeInfo );
672 /** Updates missing series settings from the passed chart type group data format. */
673 void UpdateSeriesFormat( const XclChExtTypeInfo& rTypeInfo, const XclImpChDataFormat* pGroupFmt );
674 /** Updates missing data point settings from the passed series format. */
675 void UpdatePointFormat( const XclChExtTypeInfo& rTypeInfo, const XclImpChDataFormat* pSeriesFmt );
676 /** Updates default data format for trend lines. */
677 void UpdateTrendLineFormat();
679 /** Returns the position of the data point described by this group. */
680 const XclChDataPointPos& GetPointPos() const { return maData.maPointPos; }
681 /** Returns the format index of the data point described by this group. */
682 sal_uInt16 GetFormatIdx() const { return maData.mnFormatIdx; }
683 /** Returns true, if markers are set to automatic format. */
684 bool IsAutoMarker() const { return !mxMarkerFmt || mxMarkerFmt->IsAuto(); }
685 /** Returns true, if the series line is smoothed. */
686 bool HasSpline() const { return mxSeriesFmt && mxSeriesFmt->HasSpline(); }
687 /** Returns the data label text object. */
688 const XclImpChText* GetDataLabel() const { return mxLabel.get(); }
690 /** Converts and writes the contained data to the passed property set. */
691 void Convert( ScfPropertySet& rPropSet, const XclChExtTypeInfo& rTypeInfo, const ScfPropertySet* pGlobalPropSet = nullptr ) const;
692 /** Writes the line format only, e.g. for trend lines or error bars. */
693 void ConvertLine( ScfPropertySet& rPropSet, XclChObjectType eObjType ) const;
694 /** Writes the area format only for the series or a data point. */
695 void ConvertArea( ScfPropertySet& rPropSet, sal_uInt16 nFormatIdx ) const;
697 private:
698 /** Removes unused formatting (e.g. pie distance in a bar chart). */
699 void RemoveUnusedFormats( const XclChExtTypeInfo& rTypeInfo );
700 /** Updates or creates the data point label. */
701 void UpdateDataLabel( const XclImpChDataFormat* pParentFmt );
703 private:
704 XclChDataFormat maData; /// Contents of the CHDATAFORMAT record.
705 XclImpChMarkerFormatRef mxMarkerFmt; /// Data point marker (CHMARKERFORMAT record).
706 XclImpChPieFormatRef mxPieFmt; /// Pie segment format (CHPIEFORMAT record).
707 XclImpChSeriesFormatRef mxSeriesFmt; /// Series properties (CHSERIESFORMAT record).
708 XclImpCh3dDataFormatRef mx3dDataFmt; /// 3D bar format (CH3DDATAFORMAT record).
709 XclImpChAttLabelRef mxAttLabel; /// Data point label type (CHATTACHEDLABEL record).
710 XclImpChTextRef mxLabel; /// Data point label formatting (CHTEXT group).
713 typedef std::shared_ptr< XclImpChDataFormat > XclImpChDataFormatRef;
715 /** Represents the CHSERTRENDLINE record containing settings for a trend line. */
716 class XclImpChSerTrendLine : protected XclImpChRoot
718 public:
719 explicit XclImpChSerTrendLine( const XclImpChRoot& rRoot );
721 /** Reads the CHSERTRENDLINE record. */
722 void ReadChSerTrendLine( XclImpStream& rStrm );
723 /** Sets formatting information for the trend line. */
724 void SetDataFormat(const XclImpChDataFormatRef& xDataFmt) { mxDataFmt = xDataFmt; }
726 void SetTrendlineName( const OUString& aTrendlineName) { maTrendLineName = aTrendlineName; }
728 /** Creates an API object representing this trend line. */
729 css::uno::Reference< css::chart2::XRegressionCurve >
730 CreateRegressionCurve() const;
732 private:
733 OUString maTrendLineName;
734 XclChSerTrendLine maData; /// Contents of the CHSERTRENDLINE record.
735 XclImpChDataFormatRef mxDataFmt; /// Formatting settings of the trend line.
738 typedef std::shared_ptr< XclImpChSerTrendLine > XclImpChSerTrendLineRef;
740 /** Represents the CHSERERRORBAR record containing settings for error bars. */
741 class XclImpChSerErrorBar : protected XclImpChRoot
743 public:
744 explicit XclImpChSerErrorBar( const XclImpChRoot& rRoot );
746 /** Reads the CHSERERRORBAR record. */
747 void ReadChSerErrorBar( XclImpStream& rStrm );
748 /** Sets link and formatting information for the error bars. */
749 void SetSeriesData(
750 XclImpChSourceLinkRef const & xValueLink,
751 XclImpChDataFormatRef const & xDataFmt );
753 /** Returns the type of this error bar (X/Y, plus/minus). */
754 sal_uInt8 GetBarType() const { return maData.mnBarType; }
755 /** Creates a labeled data sequence object from value data link. */
756 css::uno::Reference< css::chart2::data::XLabeledDataSequence >
757 CreateValueSequence() const;
759 /** Tries to create an error bar API object from the specified Excel error bars. */
760 static css::uno::Reference< css::beans::XPropertySet >
761 CreateErrorBar(
762 const XclImpChSerErrorBar* pPosBar,
763 const XclImpChSerErrorBar* pNegBar );
765 private:
766 XclChSerErrorBar maData; /// Contents of the CHSERERRORBAR record.
767 XclImpChSourceLinkRef mxValueLink; /// Link data for manual error bar values.
768 XclImpChDataFormatRef mxDataFmt; /// Formatting settings of the error bars.
772 /** Represents the CHSERIES record group describing a data series in a chart.
774 The CHSERIES group consists of: CHSERIES, CHBEGIN, CHSOURCELINK groups,
775 CHDATAFORMAT groups, CHSERGROUP, CHSERPARENT, CHSERERRORBAR,
776 CHSERTRENDLINE, CHEND.
778 class XclImpChSeries : public XclImpChGroupBase, protected XclImpChRoot
780 public:
781 explicit XclImpChSeries( const XclImpChRoot& rRoot, sal_uInt16 nSeriesIdx );
783 /** Reads the CHSERIES record (called by base class). */
784 virtual void ReadHeaderRecord( XclImpStream& rStrm ) override;
785 /** Reads a record from the CHSERIES group (called by base class). */
786 virtual void ReadSubRecord( XclImpStream& rStrm ) override;
788 /** Sets a data point or series format (CHDATAFORMAT group) for this series. */
789 void SetDataFormat( const XclImpChDataFormatRef& xDataFmt );
790 /** Sets a label text (CHTEXT group) attached to a series or data point. */
791 void SetDataLabel(const XclImpChTextRef& xLabel);
792 /** Adds error bar settings from the passed series to the own series. */
793 void AddChildSeries( const XclImpChSeries& rSeries );
794 /** Updates missing series formatting by using default formatting from axes sets. */
795 void FinalizeDataFormats();
797 /** Returns the axes set identifier this series is assigned to (primary/secondary). */
798 sal_uInt16 GetGroupIdx() const { return mnGroupIdx; }
799 /** Returns the 0-based index of the parent series (e.g. of a trend line). */
800 sal_uInt16 GetParentIdx() const { return mnParentIdx; }
801 /** Returns true, if the series is child of another series (e.g. trend line). */
802 bool HasParentSeries() const { return mnParentIdx != EXC_CHSERIES_INVALID; }
803 /** Returns true, if the series contains child series (e.g. trend lines). */
804 bool HasChildSeries() const { return !maTrendLines.empty() || !m_ErrorBars.empty(); }
805 /** Returns series title or an empty string, if the series does not contain a title. */
806 OUString GetTitle() const { return mxTitleLink ? mxTitleLink->GetString() : OUString(); }
808 /** Returns true, if the series line is smoothed. */
809 bool HasSpline() const { return mxSeriesFmt && mxSeriesFmt->HasSpline(); }
811 /** Creates a labeled data sequence object from value data link. */
812 css::uno::Reference< css::chart2::data::XLabeledDataSequence >
813 CreateValueSequence( const OUString& rValueRole ) const;
814 /** Creates a labeled data sequence object from category data link. */
815 css::uno::Reference< css::chart2::data::XLabeledDataSequence >
816 CreateCategSequence( const OUString& rCategRole ) const;
817 /** Creates a data series object with initialized source links. */
818 css::uno::Reference< css::chart2::XDataSeries >
819 CreateDataSeries() const;
821 void FillAllSourceLinks(::std::vector<ScTokenRef>& rTokens) const;
823 private:
824 /** Reads a CHSOURCELINK record. */
825 void ReadChSourceLink( XclImpStream& rStrm );
826 /** Reads a CHDATAFORMAT group containing series and point formatting. */
827 void ReadChDataFormat( XclImpStream& rStrm );
828 /** Reads a CHSERPARENT record specifying the parent series of this series. */
829 void ReadChSerParent( XclImpStream& rStrm );
830 /** Reads a CHSERTRENDLINE record containing trend line settings. */
831 void ReadChSerTrendLine( XclImpStream& rStrm );
832 /** Reads a CHSERERRORBAR record containing error bar settings. */
833 void ReadChSerErrorBar( XclImpStream& rStrm );
835 void ReadChLegendException( XclImpStream& rStrm );
836 /** Creates a new CHDATAFORMAT group with the specified point index. */
837 XclImpChDataFormatRef CreateDataFormat( sal_uInt16 nPointIdx, sal_uInt16 nFormatIdx );
839 /** Converts all trend lines and inserts them into the passed API data series object. */
840 void ConvertTrendLines( css::uno::Reference< css::chart2::XDataSeries > const & xDataSeries ) const;
841 /** Tries to create an error bar API object from the specified Excel error bars. */
842 css::uno::Reference< css::beans::XPropertySet >
843 CreateErrorBar( sal_uInt8 nPosBarId, sal_uInt8 nNegBarId ) const;
845 private:
846 typedef ::std::map<sal_uInt16, XclImpChDataFormatRef> XclImpChDataFormatMap;
847 typedef ::std::map<sal_uInt16, XclImpChTextRef> XclImpChTextMap;
848 typedef ::std::map<sal_uInt8, std::unique_ptr<XclImpChSerErrorBar>> XclImpChSerErrorBarMap;
850 XclChSeries maData; /// Contents of the CHSERIES record.
851 XclImpChSourceLinkRef mxValueLink; /// Link data for series values.
852 XclImpChSourceLinkRef mxCategLink; /// Link data for series category names.
853 XclImpChSourceLinkRef mxTitleLink; /// Link data for series title.
854 XclImpChSourceLinkRef mxBubbleLink; /// Link data for series bubble sizes.
855 XclImpChDataFormatRef mxSeriesFmt; /// CHDATAFORMAT group for series format.
856 XclImpChDataFormatMap maPointFmts; /// CHDATAFORMAT groups for data point formats.
857 XclImpChTextMap maLabels; /// Data point labels (CHTEXT groups).
858 std::vector< XclImpChSerTrendLineRef > maTrendLines; /// Trend line settings (CHSERTRENDLINE records).
859 XclImpChSerErrorBarMap m_ErrorBars; /// Error bar settings (CHSERERRORBAR records).
860 sal_uInt16 mnGroupIdx; /// Chart type group (CHTYPEGROUP group) this series is assigned to.
861 sal_uInt16 mnSeriesIdx; /// 0-based series index.
862 sal_uInt16 mnParentIdx; /// 0-based index of parent series (trend lines and error bars).
863 bool mbLabelDeleted; /// Legend label deleted
866 typedef std::shared_ptr< XclImpChSeries > XclImpChSeriesRef;
868 // Chart type groups ==========================================================
870 class XclImpChType : protected XclImpChRoot
872 public:
873 explicit XclImpChType( const XclImpChRoot& rRoot );
875 /** Reads a chart type record (e.g. CHBAR, CHLINE, CHPIE, ...). */
876 void ReadChType( XclImpStream& rStrm );
877 /** Final processing after reading the entire chart. */
878 void Finalize( bool bStockChart );
880 /** Returns the record identifier of the chart type record. */
881 sal_uInt16 GetRecId() const { return mnRecId; }
882 /** Returns the chart type info struct for the contained chart type. */
883 const XclChTypeInfo& GetTypeInfo() const { return maTypeInfo; }
884 /** Returns true, if the series in this chart type group are stacked on each other (no percentage). */
885 bool IsStacked() const;
886 /** Returns true, if the series in this chart type group are stacked on each other as percentage. */
887 bool IsPercent() const;
888 /** Returns true, if chart type has category labels enabled (may be disabled in radar charts). */
889 bool HasCategoryLabels() const;
891 /** Creates a coordinate system according to the contained chart type. */
892 css::uno::Reference< css::chart2::XCoordinateSystem >
893 CreateCoordSystem( bool b3dChart ) const;
894 /** Creates and returns an object that represents the contained chart type. */
895 css::uno::Reference< css::chart2::XChartType >
896 CreateChartType( css::uno::Reference< css::chart2::XDiagram > const & xDiagram, bool b3dChart ) const;
898 private:
899 XclChType maData; /// Contents of the chart type record.
900 sal_uInt16 mnRecId; /// Record identifier for chart type.
901 XclChTypeInfo maTypeInfo; /// Chart type info for the contained type.
904 /** Represents the CHCHART3D record that contains 3D view settings. */
905 class XclImpChChart3d
907 public:
908 /** Reads the CHCHART3D record (properties for 3D charts). */
909 void ReadChChart3d( XclImpStream& rStrm );
910 /** Returns true, if the data points are clustered on the X axis. */
911 bool IsClustered() const { return ::get_flag( maData.mnFlags, EXC_CHCHART3D_CLUSTER ); }
912 /** Converts and writes the contained data to the passed property set. */
913 void Convert( ScfPropertySet& rPropSet, bool b3dWallChart ) const;
915 private:
916 XclChChart3d maData; /// Contents of the CHCHART3D record.
919 typedef std::shared_ptr< XclImpChChart3d > XclImpChChart3dRef;
921 /** Represents the CHLEGEND record group describing the chart legend.
923 The CHLEGEND group consists of: CHLEGEND, CHBEGIN, CHFRAMEPOS, CHFRAME
924 group, CHTEXT group, CHEND.
926 class XclImpChLegend : public XclImpChGroupBase, protected XclImpChRoot
928 public:
929 explicit XclImpChLegend( const XclImpChRoot& rRoot );
931 /** Reads the CHLEGEND record (called by base class). */
932 virtual void ReadHeaderRecord( XclImpStream& rStrm ) override;
933 /** Reads a record from the CHLEGEND group (called by base class). */
934 virtual void ReadSubRecord( XclImpStream& rStrm ) override;
935 /** Final processing after reading the entire chart. */
936 void Finalize();
938 /** Creates a new legend object. */
939 css::uno::Reference< css::chart2::XLegend >
940 CreateLegend() const;
942 private:
943 XclChLegend maData; /// Contents of the CHLEGEND record.
944 XclImpChFramePosRef mxFramePos; /// Legend frame position (CHFRAMEPOS record).
945 XclImpChTextRef mxText; /// Legend text format (CHTEXT group).
946 XclImpChFrameRef mxFrame; /// Legend frame format (CHFRAME group).
949 typedef std::shared_ptr< XclImpChLegend > XclImpChLegendRef;
951 /** Represents the CHDROPBAR record group describing pos/neg bars in line charts.
953 The CHDROPBAR group consists of: CHDROPBAR, CHBEGIN, CHLINEFORMAT,
954 CHAREAFORMAT, CHESCHERFORMAT group, CHEND.
956 class XclImpChDropBar : public XclImpChFrameBase
958 public:
959 explicit XclImpChDropBar( sal_uInt16 nDropBar );
961 /** Reads the CHDROPBAR record (called by base class). */
962 virtual void ReadHeaderRecord( XclImpStream& rStrm ) override;
964 /** Converts and writes the contained frame data to the passed property set. */
965 void Convert( const XclImpChRoot& rRoot, ScfPropertySet& rPropSet ) const;
967 private:
968 sal_uInt16 mnDropBar; /// Drop bar identifier, needed for auto format.
969 sal_uInt16 mnBarDist; /// Distance between bars (CHDROPBAR record).
973 /** Represents the CHTYPEGROUP record group describing a group of series.
975 The CHTYPEGROUP group consists of: CHTYPEGROUP, CHBEGIN, a chart type
976 record (e.g. CHBAR, CHLINE, CHAREA, CHPIE, ...), CHCHART3D, CHLEGEND group,
977 CHDEFAULTTEXT groups (CHDEFAULTTEXT with CHTEXT groups), CHDROPBAR groups,
978 CHCHARTLINE groups (CHCHARTLINE with CHLINEFORMAT), CHDATAFORMAT group,
979 CHEND.
981 class XclImpChTypeGroup : public XclImpChGroupBase, protected XclImpChRoot
983 public:
984 explicit XclImpChTypeGroup( const XclImpChRoot& rRoot );
986 /** Reads the CHTYPEGROUP record (called by base class). */
987 virtual void ReadHeaderRecord( XclImpStream& rStrm ) override;
988 /** Reads a record from the CHTYPEGROUP group (called by base class). */
989 virtual void ReadSubRecord( XclImpStream& rStrm ) override;
990 /** Final processing after reading the entire chart. */
991 void Finalize();
993 /** Inserts a series attached to this chart type group.*/
994 void AddSeries( XclImpChSeriesRef const & xSeries );
995 /** Marks the passed format index as used. PopUnusedFormatIndex() will not return this index. */
996 void SetUsedFormatIndex( sal_uInt16 nFormatIdx );
997 /** Returns the next unused format index and marks it as used. */
998 sal_uInt16 PopUnusedFormatIndex();
1000 /** Returns the index of this chart type group. */
1001 sal_uInt16 GetGroupIdx() const { return maData.mnGroupIdx; }
1002 /** Returns the chart type info struct for the contained chart type. */
1003 const XclChExtTypeInfo& GetTypeInfo() const { return maTypeInfo; }
1004 /** Returns true, if this chart type group contains at least one valid series. */
1005 bool IsValidGroup() const { return !maSeries.empty(); }
1006 /** Returns true, if the series in this chart type group are stacked on each other as percentage. */
1007 bool IsPercent() const { return maType.IsPercent(); }
1008 /** Returns true, if the chart is three-dimensional. */
1009 bool Is3dChart() const { return mxChart3d && maTypeInfo.mbSupports3d; }
1010 /** Returns true, if chart type supports wall and floor format in 3d mode. */
1011 bool Is3dWallChart() const { return Is3dChart() && (maTypeInfo.meTypeCateg != EXC_CHTYPECATEG_PIE); }
1012 /** Returns true, if the series in this chart type group are ordered on the Z axis. */
1013 bool Is3dDeepChart() const { return Is3dWallChart() && mxChart3d && !mxChart3d->IsClustered(); }
1014 /** Returns true, if category (X axis) labels are enabled (may be disabled in radar charts). */
1015 bool HasCategoryLabels() const { return maType.HasCategoryLabels(); }
1016 /** Returns true, if points of a series show varying automatic area format. */
1017 bool HasVarPointFormat() const;
1018 /** Returns true, if bars are connected with lines (stacked bar charts only). */
1019 bool HasConnectorLines() const;
1021 /** Returns the legend object. */
1022 const XclImpChLegendRef& GetLegend() const { return mxLegend; }
1023 /** Returns the default series data format. */
1024 const XclImpChDataFormatRef& GetGroupFormat() const { return mxGroupFmt; }
1025 /** Returns series title, if the chart type group contains only one single series. */
1026 OUString GetSingleSeriesTitle() const;
1028 /** Converts and writes all 3D settings to the passed diagram. */
1029 void ConvertChart3d( ScfPropertySet& rPropSet ) const;
1030 /** Creates a coordinate system according to the contained chart type. */
1031 css::uno::Reference< css::chart2::XCoordinateSystem >
1032 CreateCoordSystem() const;
1033 /** Creates and returns an object that represents the contained chart type. */
1034 css::uno::Reference< css::chart2::XChartType >
1035 CreateChartType( css::uno::Reference< css::chart2::XDiagram > const & xDiagram, sal_Int32 nApiAxesSetIdx ) const;
1036 /** Creates a labeled data sequence object for axis categories. */
1037 css::uno::Reference< css::chart2::data::XLabeledDataSequence >
1038 CreateCategSequence() const;
1040 private:
1041 /** Reads a CHDROPBAR record group. */
1042 void ReadChDropBar( XclImpStream& rStrm );
1043 /** Reads a CHCHARTLINE record group. */
1044 void ReadChChartLine( XclImpStream& rStrm );
1045 /** Reads a CHDATAFORMAT record group (default series format). */
1046 void ReadChDataFormat( XclImpStream& rStrm );
1048 /** Returns true, if the chart type group contains drop bar formats. */
1049 bool HasDropBars() const { return !m_DropBars.empty(); }
1051 /** Inserts the passed series into the chart type. Adds additional properties to the series. */
1052 void InsertDataSeries( css::uno::Reference< css::chart2::XChartType > const & xChartType,
1053 css::uno::Reference< css::chart2::XDataSeries > const & xSeries,
1054 sal_Int32 nApiAxesSetIdx ) const;
1055 /** Creates all data series of any chart type except stock charts. */
1056 void CreateDataSeries( css::uno::Reference< css::chart2::XChartType > const & xChartType,
1057 sal_Int32 nApiAxesSetIdx ) const;
1058 /** Creates all data series of a stock chart. */
1059 void CreateStockSeries( css::uno::Reference< css::chart2::XChartType > const & xChartType,
1060 sal_Int32 nApiAxesSetIdx ) const;
1062 private:
1063 typedef ::std::vector< XclImpChSeriesRef > XclImpChSeriesVec;
1064 typedef ::std::map<sal_uInt16, std::unique_ptr<XclImpChDropBar>> XclImpChDropBarMap;
1065 typedef ::std::map<sal_uInt16, XclImpChLineFormat> XclImpChLineFormatMap;
1067 XclChTypeGroup maData; /// Contents of the CHTYPEGROUP record.
1068 XclImpChType maType; /// Chart type (e.g. CHBAR, CHLINE, ...).
1069 XclChExtTypeInfo maTypeInfo; /// Extended chart type info.
1070 XclImpChSeriesVec maSeries; /// Series attached to this chart type group (CHSERIES groups).
1071 XclImpChSeriesRef mxFirstSeries; /// First series in this chart type group (CHSERIES groups).
1072 XclImpChChart3dRef mxChart3d; /// 3D settings (CHCHART3D record).
1073 XclImpChLegendRef mxLegend; /// Chart legend (CHLEGEND group).
1074 XclImpChDropBarMap m_DropBars; /// Dropbars (CHDROPBAR group).
1075 XclImpChLineFormatMap m_ChartLines; /// Global line formats (CHCHARTLINE group).
1076 XclImpChDataFormatRef mxGroupFmt; /// Default format for all series (CHDATAFORMAT group).
1077 std::set< sal_uInt16 >
1078 maUnusedFormats; /// Contains unused format indexes for automatic colors.
1081 typedef std::shared_ptr< XclImpChTypeGroup > XclImpChTypeGroupRef;
1083 // Axes =======================================================================
1085 class XclImpChLabelRange : protected XclImpChRoot
1087 public:
1088 explicit XclImpChLabelRange( const XclImpChRoot& rRoot );
1089 /** Reads the CHLABELRANGE record (category axis scaling properties). */
1090 void ReadChLabelRange( XclImpStream& rStrm );
1091 /** Reads the CHDATERANGE record (date axis scaling properties). */
1092 void ReadChDateRange( XclImpStream& rStrm );
1093 /** Converts category axis scaling settings. */
1094 void Convert( ScfPropertySet& rPropSet, css::chart2::ScaleData& rScaleData, bool bMirrorOrient ) const;
1095 /** Converts position settings of this axis at a crossing axis. */
1096 void ConvertAxisPosition( ScfPropertySet& rPropSet, bool b3dChart ) const;
1098 private:
1099 XclChLabelRange maLabelData; /// Contents of the CHLABELRANGE record.
1100 XclChDateRange maDateData; /// Contents of the CHDATERANGE record.
1103 typedef std::shared_ptr< XclImpChLabelRange > XclImpChLabelRangeRef;
1105 class XclImpChValueRange : protected XclImpChRoot
1107 public:
1108 explicit XclImpChValueRange( const XclImpChRoot& rRoot );
1109 /** Reads the CHVALUERANGE record (numeric axis scaling properties). */
1110 void ReadChValueRange( XclImpStream& rStrm );
1111 /** Converts value axis scaling settings. */
1112 void Convert( css::chart2::ScaleData& rScaleData, bool bMirrorOrient ) const;
1113 /** Converts position settings of this axis at a crossing axis. */
1114 void ConvertAxisPosition( ScfPropertySet& rPropSet ) const;
1116 private:
1117 XclChValueRange maData; /// Contents of the CHVALUERANGE record.
1120 typedef std::shared_ptr< XclImpChValueRange > XclImpChValueRangeRef;
1122 class XclImpChTick : protected XclImpChRoot
1124 public:
1125 explicit XclImpChTick( const XclImpChRoot& rRoot );
1126 /** Reads the CHTICK record (axis ticks properties). */
1127 void ReadChTick( XclImpStream& rStrm );
1129 /** Returns true, if the axis shows attached labels. */
1130 bool HasLabels() const { return maData.mnLabelPos != EXC_CHTICK_NOLABEL; }
1131 /** Returns the leading font color for the axis labels. */
1132 Color GetFontColor() const;
1133 /** Returns the rotation value for the axis labels. */
1134 sal_uInt16 GetRotation() const;
1136 /** Converts and writes the contained data to the passed property set. */
1137 void Convert( ScfPropertySet& rPropSet ) const;
1139 private:
1140 XclChTick maData; /// Contents of the CHTICK record.
1143 typedef std::shared_ptr< XclImpChTick > XclImpChTickRef;
1145 /** Represents the CHAXIS record group describing an entire chart axis.
1147 The CHAXIS group consists of: CHAXIS, CHBEGIN, CHLABELRANGE, CHEXTRANGE,
1148 CHVALUERANGE, CHFORMAT, CHTICK, CHFONT, CHAXISLINE groups (CHAXISLINE with
1149 CHLINEFORMAT, CHAREAFORMAT, and CHESCHERFORMAT group), CHEND.
1151 class XclImpChAxis : public XclImpChGroupBase, public XclImpChFontBase, protected XclImpChRoot
1153 public:
1154 explicit XclImpChAxis( const XclImpChRoot& rRoot, sal_uInt16 nAxisType = EXC_CHAXIS_NONE );
1156 /** Reads the CHAXIS record (called by base class). */
1157 virtual void ReadHeaderRecord( XclImpStream& rStrm ) override;
1158 /** Reads a record from the CHAXIS group (called by base class). */
1159 virtual void ReadSubRecord( XclImpStream& rStrm ) override;
1160 /** Final processing after reading the entire chart. */
1161 void Finalize();
1163 /** Returns the font index for the axis labels. */
1164 virtual sal_uInt16 GetFontIndex() const override;
1165 /** Returns the font color for the axis labels. */
1166 virtual Color GetFontColor() const override;
1167 /** Returns the rotation value for axis labels. */
1168 virtual sal_uInt16 GetRotation() const override;
1170 /** Returns the type of this axis. */
1171 sal_uInt16 GetAxisType() const { return maData.mnType; }
1172 /** Returns the axis dimension index used by the chart API. */
1173 sal_Int32 GetApiAxisDimension() const { return maData.GetApiAxisDimension(); }
1175 /** Creates an API axis object. */
1176 css::uno::Reference< css::chart2::XAxis >
1177 CreateAxis( const XclImpChTypeGroup& rTypeGroup, const XclImpChAxis* pCrossingAxis ) const;
1178 /** Converts and writes 3D wall/floor properties to the passed property set. */
1179 void ConvertWall( ScfPropertySet& rPropSet ) const;
1180 /** Converts position settings of this axis at a crossing axis. */
1181 void ConvertAxisPosition( ScfPropertySet& rPropSet, const XclImpChTypeGroup& rTypeGroup ) const;
1183 private:
1184 /** Reads a CHAXISLINE record specifying the target for following line properties. */
1185 void ReadChAxisLine( XclImpStream& rStrm );
1186 /** Creates a CHFRAME object and stores it into the mxWallFrame member. */
1187 void CreateWallFrame();
1189 private:
1190 XclChAxis maData; /// Contents of the CHAXIS record.
1191 XclImpChLabelRangeRef mxLabelRange; /// Category scaling (CHLABELRANGE record).
1192 XclImpChValueRangeRef mxValueRange; /// Value scaling (CHVALUERANGE record).
1193 XclImpChTickRef mxTick; /// Axis ticks (CHTICK record).
1194 XclImpChFontRef mxFont; /// Index into font buffer (CHFONT record).
1195 XclImpChLineFormatRef mxAxisLine; /// Axis line format (CHLINEFORMAT record).
1196 XclImpChLineFormatRef mxMajorGrid; /// Major grid line format (CHLINEFORMAT record).
1197 XclImpChLineFormatRef mxMinorGrid; /// Minor grid line format (CHLINEFORMAT record).
1198 XclImpChFrameRef mxWallFrame; /// Wall/floor format (sub records of CHFRAME group).
1199 sal_uInt16 mnNumFmtIdx; /// Index into number format buffer (CHFORMAT record).
1202 typedef std::shared_ptr< XclImpChAxis > XclImpChAxisRef;
1204 /** Represents the CHAXESSET record group describing an axes set (X/Y/Z axes).
1206 The CHAXESSET group consists of: CHAXESSET, CHBEGIN, CHFRAMEPOS, CHAXIS
1207 groups, CHTEXT groups, CHPLOTFRAME group (CHPLOTFRAME with CHFRAME group),
1208 CHTYPEGROUP group, CHEND.
1210 class XclImpChAxesSet : public XclImpChGroupBase, protected XclImpChRoot
1212 public:
1213 explicit XclImpChAxesSet( const XclImpChRoot& rRoot, sal_uInt16 nAxesSetId );
1215 /** Reads the CHAXESSET record (called by base class). */
1216 virtual void ReadHeaderRecord( XclImpStream& rStrm ) override;
1217 /** Reads a record from the CHAXESSET group (called by base class). */
1218 virtual void ReadSubRecord( XclImpStream& rStrm ) override;
1219 /** Final processing after reading the entire chart. */
1220 void Finalize();
1222 /** Returns true, if this axes set exists (returns false if this is a dummy object). */
1223 bool IsValidAxesSet() const { return !maTypeGroups.empty(); }
1224 /** Returns the index of the axes set (primary/secondary). */
1225 sal_uInt16 GetAxesSetId() const { return maData.mnAxesSetId; }
1226 /** Returns the axes set index used by the chart API. */
1227 sal_Int32 GetApiAxesSetIndex() const { return maData.GetApiAxesSetIndex(); }
1229 /** Returns the outer plot area position, if existing. */
1230 const XclImpChFramePosRef& GetPlotAreaFramePos() const { return mxFramePos; }
1231 /** Returns the specified chart type group. */
1232 XclImpChTypeGroupRef GetTypeGroup( sal_uInt16 nGroupIdx ) const;
1233 /** Returns the first chart type group. */
1234 XclImpChTypeGroupRef GetFirstTypeGroup() const;
1235 /** Looks for a legend in all chart type groups and returns it. */
1236 XclImpChLegendRef GetLegend() const;
1237 /** Returns series title, if the axes set contains only one single series. */
1238 OUString GetSingleSeriesTitle() const;
1240 /** Creates a coordinate system and converts all series and axis settings. */
1241 void Convert( css::uno::Reference< css::chart2::XDiagram > const & xDiagram ) const;
1242 /** Converts the manual positions of all axis titles. */
1243 void ConvertTitlePositions() const;
1245 private:
1246 /** Reads a CHAXIS record group containing a single axis. */
1247 void ReadChAxis( XclImpStream& rStrm );
1248 /** Reads a CHTEXT record group containing an axis title. */
1249 void ReadChText( XclImpStream& rStrm );
1250 /** Reads the CHPLOTFRAME record group containing diagram area formatting. */
1251 void ReadChPlotFrame( XclImpStream& rStrm );
1252 /** Reads a CHTYPEGROUP record group containing chart type and chart settings. */
1253 void ReadChTypeGroup( XclImpStream& rStrm );
1255 /** Creates a coordinate system that contains all chart types for this axes set. */
1256 css::uno::Reference< css::chart2::XCoordinateSystem >
1257 CreateCoordSystem( css::uno::Reference< css::chart2::XDiagram > const & xDiagram ) const;
1258 /** Creates and inserts an axis into the container and registers the coordinate system. */
1259 void ConvertAxis( XclImpChAxisRef const & xChAxis, XclImpChTextRef const & xChAxisTitle,
1260 css::uno::Reference< css::chart2::XCoordinateSystem > const & xCoordSystem,
1261 const XclImpChAxis* pCrossingAxis ) const;
1262 /** Creates and returns an API axis object. */
1263 css::uno::Reference< css::chart2::XAxis >
1264 CreateAxis( const XclImpChAxis& rChAxis, const XclImpChAxis* pCrossingAxis ) const;
1265 /** Writes all properties of the background area to the passed diagram. */
1266 void ConvertBackground( css::uno::Reference< css::chart2::XDiagram > const & xDiagram ) const;
1268 private:
1269 typedef ::std::map<sal_uInt16, XclImpChTypeGroupRef> XclImpChTypeGroupMap;
1271 XclChAxesSet maData; /// Contents of the CHAXESSET record.
1272 XclImpChFramePosRef mxFramePos; /// Outer plot area position (CHFRAMEPOS record).
1273 XclImpChAxisRef mxXAxis; /// The X axis (CHAXIS group).
1274 XclImpChAxisRef mxYAxis; /// The Y axis (CHAXIS group).
1275 XclImpChAxisRef mxZAxis; /// The Z axis (CHAXIS group).
1276 XclImpChTextRef mxXAxisTitle; /// The X axis title (CHTEXT group).
1277 XclImpChTextRef mxYAxisTitle; /// The Y axis title (CHTEXT group).
1278 XclImpChTextRef mxZAxisTitle; /// The Z axis title (CHTEXT group).
1279 XclImpChFrameRef mxPlotFrame; /// Plot area (CHPLOTFRAME group).
1280 XclImpChTypeGroupMap maTypeGroups; /// Chart type groups (CHTYPEGROUP group).
1283 typedef std::shared_ptr< XclImpChAxesSet > XclImpChAxesSetRef;
1285 // The chart object ===========================================================
1287 /** Represents the CHCHART record group describing the chart contents.
1289 The CHCHART group consists of: CHCHART, CHBEGIN, SCL, CHPLOTGROWTH, CHFRAME
1290 group, CHSERIES groups, CHPROPERTIES, CHDEFAULTTEXT groups (CHDEFAULTTEXT
1291 with CHTEXT groups), CHUSEDAXESSETS, CHAXESSET groups, CHTEXT groups, CHEND.
1293 class XclImpChChart : public XclImpChGroupBase, protected XclImpChRoot
1295 public:
1296 explicit XclImpChChart( const XclImpRoot& rRoot );
1297 virtual ~XclImpChChart() override;
1299 /** Reads the CHCHART record (called by base class). */
1300 virtual void ReadHeaderRecord( XclImpStream& rStrm ) override;
1301 /** Reads a record from the CHCHART group (called by base class). */
1302 virtual void ReadSubRecord( XclImpStream& rStrm ) override;
1303 /** Reads a CHDEFAULTTEXT group (default text formats). */
1304 void ReadChDefaultText( XclImpStream& rStrm );
1305 /** Reads a CHDATAFORMAT group describing a series format or a data point format. */
1306 void ReadChDataFormat( XclImpStream& rStrm );
1308 /** Sets formatting from BIFF3-BIFF5 OBJ record, if own formatting is invisible. */
1309 void UpdateObjFrame( const XclObjLineData& rLineData, const XclObjFillData& rFillData );
1311 /** Returns the specified chart type group. */
1312 XclImpChTypeGroupRef GetTypeGroup( sal_uInt16 nGroupIdx ) const;
1313 /** Returns the specified default text. */
1314 const XclImpChText* GetDefaultText( XclChTextType eTextType ) const;
1315 /** Returns true, if the plot area has benn moved and/or resized manually. */
1316 bool IsManualPlotArea() const;
1317 /** Returns the number of units on the progress bar needed for the chart. */
1318 static std::size_t GetProgressSize() { return 2 * EXC_CHART_PROGRESS_SIZE; }
1320 /** Converts and writes all properties to the passed chart. */
1321 void Convert(
1322 const css::uno::Reference< css::chart2::XChartDocument>& xChartDoc,
1323 XclImpDffConverter& rDffConv,
1324 const OUString& rObjName,
1325 const tools::Rectangle& rChartRect ) const;
1327 private:
1328 /** Reads a CHSERIES group (data series source and formatting). */
1329 void ReadChSeries( XclImpStream& rStrm );
1330 /** Reads a CHPROPERTIES record (global chart properties). */
1331 void ReadChProperties( XclImpStream& rStrm );
1332 /** Reads a CHAXESSET group (primary/secondary axes set). */
1333 void ReadChAxesSet( XclImpStream& rStrm );
1334 /** Reads a CHTEXT group (chart title and series/point captions). */
1335 void ReadChText( XclImpStream& rStrm );
1337 /** Final processing after reading the entire chart data. */
1338 void Finalize();
1339 /** Finalizes series list, assigns child series to parent series. */
1340 void FinalizeSeries();
1341 /** Assigns all imported CHDATAFORMAT groups to the respective series. */
1342 void FinalizeDataFormats();
1343 /** Finalizes chart title, tries to detect title auto-generated from series name. */
1344 void FinalizeTitle();
1346 /** Creates and returns a new diagram object and converts global chart settings. */
1347 css::uno::Reference<css::chart2::XDiagram>
1348 CreateDiagram() const;
1350 private:
1351 typedef ::std::vector< XclImpChSeriesRef > XclImpChSeriesVec;
1352 typedef ::std::map<XclChDataPointPos, XclImpChDataFormatRef> XclImpChDataFormatMap;
1353 typedef ::std::map<sal_uInt16, std::unique_ptr<XclImpChText>> XclImpChTextMap;
1355 XclChRectangle maRect; /// Position of the chart on the sheet (CHCHART record).
1356 XclImpChSeriesVec maSeries; /// List of series data (CHSERIES groups).
1357 XclImpChDataFormatMap maDataFmts; /// All series and point formats (CHDATAFORMAT groups).
1358 XclImpChFrameRef mxFrame; /// Chart frame format (CHFRAME group).
1359 XclChProperties maProps; /// Chart properties (CHPROPERTIES record).
1360 XclImpChTextMap m_DefTexts; /// Default text objects (CHDEFAULTTEXT groups).
1361 XclImpChAxesSetRef mxPrimAxesSet; /// Primary axes set (CHAXESSET group).
1362 XclImpChAxesSetRef mxSecnAxesSet; /// Secondary axes set (CHAXESSET group).
1363 XclImpChTextRef mxTitle; /// Chart title (CHTEXT group).
1364 XclImpChLegendRef mxLegend; /// Chart legend (CHLEGEND group).
1367 typedef std::shared_ptr< XclImpChChart > XclImpChChartRef;
1369 /** Drawing container of a chart. */
1370 class XclImpChartDrawing : public XclImpDrawing
1372 public:
1373 explicit XclImpChartDrawing( const XclImpRoot& rRoot, bool bOwnTab );
1375 /** Converts all objects and inserts them into the chart drawing page. */
1376 void ConvertObjects(
1377 XclImpDffConverter& rDffConv,
1378 const css::uno::Reference< css::frame::XModel >& rxModel,
1379 const tools::Rectangle& rChartRect );
1381 /** Calculate the resulting rectangle of the passed anchor. */
1382 virtual tools::Rectangle CalcAnchorRect( const XclObjAnchor& rAnchor, bool bDffAnchor ) const override;
1383 /** Called whenever an object has been inserted into the draw page. */
1384 virtual void OnObjectInserted( const XclImpDrawObjBase& rDrawObj ) override;
1386 private:
1387 tools::Rectangle maChartRect; /// Position and size of the chart shape in 1/100 mm.
1388 SCTAB mnScTab; /// Index of the sheet that contains the chart.
1389 bool mbOwnTab; /// True = own sheet, false = embedded object.
1392 /** Represents the entire chart substream (all records in BOF/EOF block). */
1393 class XclImpChart : protected XclImpRoot
1395 public:
1396 /** Constructs a new chart object.
1397 @param bOwnTab True = chart is on an own sheet; false = chart is an embedded object. */
1398 explicit XclImpChart( const XclImpRoot& rRoot, bool bOwnTab );
1399 virtual ~XclImpChart() override;
1401 /** Reads the complete chart substream (BOF/EOF block).
1402 @descr The passed stream must be located in the BOF record of the chart substream. */
1403 void ReadChartSubStream( XclImpStream& rStrm );
1404 /** Sets formatting from BIFF3-BIFF5 OBJ record, if own formatting is invisible. */
1405 void UpdateObjFrame( const XclObjLineData& rLineData, const XclObjFillData& rFillData );
1407 /** Returns the number of units on the progress bar needed for the chart. */
1408 std::size_t GetProgressSize() const;
1409 /** Returns true, if the chart is based on a pivot table. */
1410 bool IsPivotChart() const { return mbIsPivotChart; }
1412 /** Creates the chart object in the passed component. */
1413 void Convert( css::uno::Reference< css::frame::XModel > const & xModel,
1414 XclImpDffConverter& rDffConv,
1415 const OUString& rObjName,
1416 const tools::Rectangle& rChartRect ) const;
1418 private:
1419 /** Returns (initially creates) the drawing container for embedded shapes. **/
1420 XclImpChartDrawing& GetChartDrawing();
1421 /** Reads the CHCHART group (entire chart data). */
1422 void ReadChChart( XclImpStream& rStrm );
1424 private:
1425 typedef std::shared_ptr< XclImpChartDrawing > XclImpChartDrawingRef;
1427 XclImpChChartRef mxChartData; /// The chart data (CHCHART group).
1428 XclImpChartDrawingRef mxChartDrawing; /// Drawing container for embedded shapes.
1429 bool mbOwnTab; /// true = own sheet; false = embedded object.
1430 bool mbIsPivotChart; /// true = chart is based on a pivot table.
1433 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */