summaryrefslogtreecommitdiff
path: root/sc/source/filter/inc/xechart.hxx
blob: 206392ea68904f23020d1ef996b62a8f1d2f73fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2000, 2010 Oracle and/or its affiliates.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#ifndef SC_XECHART_HXX
#define SC_XECHART_HXX

#include <tools/gen.hxx>
#include "xerecord.hxx"
#include "xlchart.hxx"
#include "xlformula.hxx"
#include "xlstyle.hxx"
#include "xeroot.hxx"
#include "xestring.hxx"

class Size;

namespace com { namespace sun { namespace star {
    namespace awt
    {
        struct Rectangle;
    }
    namespace frame
    {
        class XModel;
    }
    namespace chart
    {
        class XAxis;
    }
    namespace chart2
    {
        struct ScaleData;
        class XChartDocument;
        class XDiagram;
        class XCoordinateSystem;
        class XChartType;
        class XDataSeries;
        class XAxis;
        class XTitle;
        class XFormattedString;
        class XRegressionCurve;
        namespace data
        {
            class XDataSequence;
            class XLabeledDataSequence;
        }
    }
} } }

// Common =====================================================================

struct XclExpChRootData;
class XclExpChChart;

/** Base class for complex chart classes, provides access to other components
    of the chart.

    Keeps also track of future record levels and writes the needed future
    records on demand.
 */
class XclExpChRoot : public XclExpRoot
{
public:
    typedef ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartDocument > XChartDocRef;

public:
    explicit            XclExpChRoot( const XclExpRoot& rRoot, XclExpChChart& rChartData );
    virtual             ~XclExpChRoot();

    /** Returns this root instance - for code readability in derived classes. */
    inline const XclExpChRoot& GetChRoot() const { return *this; }
    /** Returns the API Chart document model. */
    XChartDocRef        GetChartDocument() const;
    /** Returns a reference to the parent chart data object. */
    XclExpChChart&      GetChartData() const;
    /** Returns chart type info for a unique chart type identifier. */
    const XclChTypeInfo& GetChartTypeInfo( XclChTypeId eType ) const;
    /** Returns the first fitting chart type info for the passed service name. */
    const XclChTypeInfo& GetChartTypeInfo( const ::rtl::OUString& rServiceName ) const;

    /** Returns an info struct about auto formatting for the passed object type. */
    const XclChFormatInfo& GetFormatInfo( XclChObjectType eObjType ) const;

    /** Starts the API chart document conversion. Must be called once before all API conversion. */
    void                InitConversion( XChartDocRef xChartDoc, const Rectangle& rChartRect ) const;
    /** Finishes the API chart document conversion. Must be called once after all API conversion. */
    void                FinishConversion() const;

    /** Returns true, if the passed color equals to the specified system color. */
    bool                IsSystemColor( const Color& rColor, sal_uInt16 nSysColorIdx ) const;
    /** Sets a system color and the respective color identifier. */
    void                SetSystemColor( Color& rColor, sal_uInt32& rnColorId, sal_uInt16 nSysColorIdx ) const;

    /** Converts the passed horizontal coordinate from 1/100 mm to Excel chart units. */
    sal_Int32           CalcChartXFromHmm( sal_Int32 nPosX ) const;
    /** Converts the passed vertical coordinate from 1/100 mm to Excel chart units. */
    sal_Int32           CalcChartYFromHmm( sal_Int32 nPosY ) const;
    /** Converts the passed rectangle from 1/100 mm to Excel chart units. */
    XclChRectangle      CalcChartRectFromHmm( const ::com::sun::star::awt::Rectangle& rRect ) const;

    /** Converts the passed horizontal coordinate from a relative position to Excel chart units. */
    sal_Int32           CalcChartXFromRelative( double fPosX ) const;
    /** Converts the passed vertical coordinate from a relative position to Excel chart units. */
    sal_Int32           CalcChartYFromRelative( double fPosY ) const;

    /** Reads all line properties from the passed property set. */
    void                ConvertLineFormat(
                            XclChLineFormat& rLineFmt,
                            const ScfPropertySet& rPropSet,
                            XclChPropertyMode ePropMode ) const;
    /** Reads solid area properties from the passed property set.
        @return  true = object contains complex fill properties. */
    bool                ConvertAreaFormat(
                            XclChAreaFormat& rAreaFmt,
                            const ScfPropertySet& rPropSet,
                            XclChPropertyMode ePropMode ) const;
    /** Reads gradient or bitmap area properties from the passed property set. */
    void                ConvertEscherFormat(
                            XclChEscherFormat& rEscherFmt,
                            XclChPicFormat& rPicFmt,
                            const ScfPropertySet& rPropSet,
                            XclChPropertyMode ePropMode ) const;
    /** Reads font properties from the passed property set. */
    sal_uInt16          ConvertFont(
                            const ScfPropertySet& rPropSet,
                            sal_Int16 nScript ) const;

    /** Reads the pie rotation property and returns the converted angle. */
    static sal_uInt16   ConvertPieRotation( const ScfPropertySet& rPropSet );

protected:
    /** Called from XclExpChGroupBase::Save, registers a new future record level. */
    void                RegisterFutureRecBlock( const XclChFrBlock& rFrBlock );
    /** Called from XclExpChFutureRecordBase::Save, Initializes the current future record level. */
    void                InitializeFutureRecBlock( XclExpStream& rStrm );
    /** Called from XclExpChGroupBase::Save, finalizes the current future record level. */
    void                FinalizeFutureRecBlock( XclExpStream& rStrm );

private:
    typedef ScfRef< XclExpChRootData > XclExpChRootDataRef;
    XclExpChRootDataRef mxChData;           /// Reference to the root data object.
};

// ----------------------------------------------------------------------------

/** Base class for chart record groups. Provides helper functions to write sub records.

    A chart record group consists of a header record, followed by a CHBEGIN
    record, followed by group sub records, and finished with a CHEND record.
 */
class XclExpChGroupBase : public XclExpRecord, protected XclExpChRoot
{
public:
    explicit            XclExpChGroupBase(
                            const XclExpChRoot& rRoot, sal_uInt16 nFrType,
                            sal_uInt16 nRecId, sal_Size nRecSize = 0 );
    virtual             ~XclExpChGroupBase();

    /** Saves the header record. Calls WriteSubRecords() to let derived classes write sub records. */
    virtual void        Save( XclExpStream& rStrm );
    /** Derived classes return whether there are any records embedded in this group. */
    virtual bool        HasSubRecords() const;
    /** Derived classes implement writing any records embedded in this group. */
    virtual void        WriteSubRecords( XclExpStream& rStrm ) = 0;

protected:
    /** Sets context information for future record blocks. */
    void                SetFutureRecordContext( sal_uInt16 nFrContext,
                            sal_uInt16 nFrValue1 = 0, sal_uInt16 nFrValue2 = 0 );

private:
    XclChFrBlock        maFrBlock;          /// Future records block settings.
};

// ----------------------------------------------------------------------------

/** Base class for chart future records. On saving, the record writes missing
    CHFRBLOCKBEGIN records automatically.
 */
class XclExpChFutureRecordBase : public XclExpFutureRecord, protected XclExpChRoot
{
public:
    explicit            XclExpChFutureRecordBase( const XclExpChRoot& rRoot,
                            XclFutureRecType eRecType, sal_uInt16 nRecId, sal_Size nRecSize = 0 );

    /** Writes missing CHFRBLOCKBEGIN records and this record. */
    virtual void        Save( XclExpStream& rStrm );
};

// Frame formatting ===========================================================

class XclExpChFramePos : public XclExpRecord
{
public:
    explicit            XclExpChFramePos( sal_uInt16 nTLMode, sal_uInt16 nBRMode );

    /** Returns read/write access to the frame position data. */
    inline XclChFramePos& GetFramePosData() { return maData; }

private:
    virtual void        WriteBody( XclExpStream& rStrm );

private:
    XclChFramePos       maData;             /// Position of the frame.
};

typedef ScfRef< XclExpChFramePos > XclExpChFramePosRef;

// ----------------------------------------------------------------------------

class XclExpChLineFormat : public XclExpRecord
{
public:
    explicit            XclExpChLineFormat( const XclExpChRoot& rRoot );

    /** Converts line formatting properties from the passed property set. */
    void                Convert( const XclExpChRoot& rRoot,
                            const ScfPropertySet& rPropSet, XclChObjectType eObjType );
    /** Sets or clears the automatic flag. */
    inline void         SetAuto( bool bAuto ) { ::set_flag( maData.mnFlags, EXC_CHLINEFORMAT_AUTO, bAuto ); }
    /** Sets flag to show or hide an axis. */
    inline void         SetShowAxis( bool bShowAxis )
                            { ::set_flag( maData.mnFlags, EXC_CHLINEFORMAT_SHOWAXIS, bShowAxis ); }
    /** Sets the line format to the specified default type. */
    void                SetDefault( XclChFrameType eDefFrameType );

    /** Returns true, if the line format is set to automatic. */
    inline bool         IsAuto() const { return ::get_flag( maData.mnFlags, EXC_CHLINEFORMAT_AUTO ); }
    /** Returns true, if the line style is set to something visible. */
    inline bool         HasLine() const { return maData.mnPattern != EXC_CHLINEFORMAT_NONE; }
    /** Returns true, if the line contains default formatting according to the passed frame type. */
    bool                IsDefault( XclChFrameType eDefFrameType ) const;

private:
    virtual void        WriteBody( XclExpStream& rStrm );

private:
    XclChLineFormat     maData;             /// Contents of the CHLINEFORMAT record.
    sal_uInt32          mnColorId;          /// Line color identifier.
};

typedef ScfRef< XclExpChLineFormat > XclExpChLineFormatRef;

// ----------------------------------------------------------------------------

class XclExpChAreaFormat : public XclExpRecord
{
public:
    explicit            XclExpChAreaFormat( const XclExpChRoot& rRoot );

    /** Converts area formatting properties from the passed property set.
        @return  true = object contains complex fill properties. */
    bool                Convert( const XclExpChRoot& rRoot,
                            const ScfPropertySet& rPropSet, XclChObjectType eObjType );
    /** Sets or clears the automatic flag. */
    inline void         SetAuto( bool bAuto ) { ::set_flag( maData.mnFlags, EXC_CHAREAFORMAT_AUTO, bAuto ); }
    /** Sets the area format to the specified default type. */
    void                SetDefault( XclChFrameType eDefFrameType );

    /** Returns true, if the area format is set to automatic. */
    inline bool         IsAuto() const { return ::get_flag( maData.mnFlags, EXC_CHAREAFORMAT_AUTO ); }
    /** Returns true, if the area style is set to something visible. */
    inline bool         HasArea() const { return maData.mnPattern != EXC_PATT_NONE; }
    /** Returns true, if the area contains default formatting according to the passed frame type. */
    bool                IsDefault( XclChFrameType eDefFrameType ) const;

private:
    virtual void        WriteBody( XclExpStream& rStrm );

private:
    XclChAreaFormat     maData;             /// Contents of the CHAREAFORMAT record.
    sal_uInt32          mnPattColorId;      /// Pattern color identifier.
    sal_uInt32          mnBackColorId;      /// Pattern background color identifier.
};

typedef ScfRef< XclExpChAreaFormat > XclExpChAreaFormatRef;

// ----------------------------------------------------------------------------

class XclExpChEscherFormat : public XclExpChGroupBase
{
public:
    explicit            XclExpChEscherFormat( const XclExpChRoot& rRoot );

    /** Converts complex area formatting from the passed property set. */
    void                Convert( const ScfPropertySet& rPropSet, XclChObjectType eObjType );

    /** Returns true, if the object contains valid formatting data. */
    bool                IsValid() const;

    /** Writes the CHESCHERFORMAT record group to the stream, if complex formatting is extant. */
    virtual void        Save( XclExpStream& rStrm );
    /** Returns true, if this record group contains a CHPICFORMAT record. */
    virtual bool        HasSubRecords() const;
    /** Writes all embedded records. */
    virtual void        WriteSubRecords( XclExpStream& rStrm );

private:
    /** Inserts a color from the contained Escher property set into the color palette. */
    sal_uInt32          RegisterColor( sal_uInt16 nPropId );

    virtual void        WriteBody( XclExpStream& rStrm );

private:
    XclChEscherFormat   maData;             /// Fill properties for complex areas (CHESCHERFORMAT record).
    XclChPicFormat      maPicFmt;           /// Image options, e.g. stretched, stacked (CHPICFORMAT record).
    sal_uInt32          mnColor1Id;         /// First fill color identifier.
    sal_uInt32          mnColor2Id;         /// Second fill color identifier.
};

typedef ScfRef< XclExpChEscherFormat > XclExpChEscherFormatRef;

// ----------------------------------------------------------------------------

/** Base class for record groups containing frame formatting.

    Frame formatting can be part of several record groups, e.g. CHFRAME,
    CHDATAFORMAT, CHDROPBAR. It consists of CHLINEFORMAT, CHAREAFORMAT, and
    CHESCHERFORMAT group.
 */
class XclExpChFrameBase
{
public:
    explicit            XclExpChFrameBase();
    virtual             ~XclExpChFrameBase();

protected:
    /** Converts frame formatting properties from the passed property set. */
    void                ConvertFrameBase( const XclExpChRoot& rRoot,
                            const ScfPropertySet& rPropSet, XclChObjectType eObjType );
    /** Sets the frame formatting to the specified default type. */
    void                SetDefaultFrameBase( const XclExpChRoot& rRoot,
                            XclChFrameType eDefFrameType, bool bIsFrame );

    /** Returns true, if the frame contains default formatting (as if the frame is missing). */
    bool                IsDefaultFrameBase( XclChFrameType eDefFrameType ) const;

    /** Writes all contained frame records to the passed stream. */
    void                WriteFrameRecords( XclExpStream& rStrm );

private:
    XclExpChLineFormatRef mxLineFmt;        /// Line format (CHLINEFORMAT record).
    XclExpChAreaFormatRef mxAreaFmt;        /// Area format (CHAREAFORMAT record).
    XclExpChEscherFormatRef mxEscherFmt;    /// Complex area format (CHESCHERFORMAT record).
};

// ----------------------------------------------------------------------------

/** Represents the CHFRAME record group containing object frame properties.

    The CHFRAME group consists of: CHFRAME, CHBEGIN, CHLINEFORMAT,
    CHAREAFORMAT, CHESCHERFORMAT group, CHEND.
 */
class XclExpChFrame : public XclExpChGroupBase, public XclExpChFrameBase
{
public:
    explicit            XclExpChFrame( const XclExpChRoot& rRoot, XclChObjectType eObjType );

    /** Converts frame formatting properties from the passed property set. */
    void                Convert( const ScfPropertySet& rPropSet );
    /** Sets the specified automatic flags. */
    void                SetAutoFlags( bool bAutoPos, bool bAutoSize );

    /** Returns true, if the frame object contains default formats. */
    bool                IsDefault() const;
    /** Returns true, if the frame object can be deleted because it contains default formats. */
    bool                IsDeleteable() const;

    /** Writes the entire record group. */
    virtual void        Save( XclExpStream& rStrm );
    /** Writes all embedded records. */
    virtual void        WriteSubRecords( XclExpStream& rStrm );

private:
    virtual void        WriteBody( XclExpStream& rStrm );

private:
    XclChFrame          maData;             /// Contents of the CHFRAME record.
    XclChObjectType     meObjType;          /// Type of the represented object.
};

typedef ScfRef< XclExpChFrame > XclExpChFrameRef;

// Source links ===============================================================

class XclExpChSourceLink : public XclExpRecord, protected XclExpChRoot
{
public:
    typedef ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSequence >   XDataSequenceRef;
    typedef ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XFormattedString >      XFormattedStringRef;
    typedef ::com::sun::star::uno::Sequence< XFormattedStringRef >                              XFormattedStringSeq;

public:
    explicit            XclExpChSourceLink( const XclExpChRoot& rRoot, sal_uInt8 nDestType );

    /** Converts the passed source link, returns the number of linked values. */
    sal_uInt16          ConvertDataSequence( XDataSequenceRef xDataSeq, bool bSplitToColumns, sal_uInt16 nDefCount = 0 );
    /** Converts the passed sequence of formatted string objects, returns leading font index. */
    sal_uInt16          ConvertStringSequence( const XFormattedStringSeq& rStringSeq );
    /** Converts the number format from the passed property set. */
    void                ConvertNumFmt( const ScfPropertySet& rPropSet, bool bPercent );

    /** Returns true, if this source link contains explicit string data. */
    inline bool         HasString() const { return mxString.is() && !mxString->IsEmpty(); }

    /** Writes the CHSOURCELINK record and optionally a CHSTRING record with explicit string data. */
    virtual void        Save( XclExpStream& rStrm );

private:
    virtual void        WriteBody( XclExpStream& rStrm );

private:
    XclChSourceLink     maData;             /// Contents of the CHSOURCELINK record.
    XclTokenArrayRef    mxLinkFmla;         /// Formula with link to source data.
    XclExpStringRef     mxString;           /// Text data (CHSTRING record).
};

typedef ScfRef< XclExpChSourceLink > XclExpChSourceLinkRef;

// Text =======================================================================

/** The CHFONT record containing a font index for text objects. */
class XclExpChFont : public XclExpUInt16Record
{
public:
    explicit            XclExpChFont( sal_uInt16 nFontIdx );
};

typedef ScfRef< XclExpChFont > XclExpChFontRef;

// ----------------------------------------------------------------------------

/** The CHOBJECTLINK record linking a text object to a specific chart object. */
class XclExpChObjectLink : public XclExpRecord
{
public:
    explicit            XclExpChObjectLink( sal_uInt16 nLinkTarget, const XclChDataPointPos& rPointPos );

private:
    virtual void        WriteBody( XclExpStream& rStrm );

private:
    XclChObjectLink     maData;             /// Contents of the CHOBJECTLINK record.
};

typedef ScfRef< XclExpChObjectLink > XclExpChObjectLinkRef;

// ----------------------------------------------------------------------------

/** Additional data label settings in the future record CHFRLABELPROPS. */
class XclExpChFrLabelProps : public XclExpChFutureRecordBase
{
public:
    explicit            XclExpChFrLabelProps( const XclExpChRoot& rRoot );

    /** Converts separator and the passed data label flags. */
    void                Convert(
                            const ScfPropertySet& rPropSet, bool bShowSeries,
                            bool bShowCateg, bool bShowValue,
                            bool bShowPercent, bool bShowBubble );

private:
    virtual void        WriteBody( XclExpStream& rStrm );

private:
    XclChFrLabelProps   maData;             /// Contents of the CHFRLABELPROPS record.
};

typedef ScfRef< XclExpChFrLabelProps > XclExpChFrLabelPropsRef;

// ----------------------------------------------------------------------------

/** Base class for objects with font settings. Provides font conversion helper functions. */
class XclExpChFontBase
{
public:
    virtual             ~XclExpChFontBase();

    /** Derived classes set font color and color identifier to internal data structures. */
    virtual void        SetFont( XclExpChFontRef xFont, const Color& rColor, sal_uInt32 nColorId ) = 0;
    /** Derived classes set text rotation to internal data structures. */
    virtual void        SetRotation( sal_uInt16 nRotation ) = 0;

    /** Creates a CHFONT record from the passed font index, calls virtual function SetFont(). */
    void                ConvertFontBase( const XclExpChRoot& rRoot, sal_uInt16 nFontIdx );
    /** Creates a CHFONT record from the passed font index, calls virtual function SetFont(). */
    void                ConvertFontBase( const XclExpChRoot& rRoot, const ScfPropertySet& rPropSet );
    /** Converts rotation settings, calls virtual function SetRotation(). */
    void                ConvertRotationBase( const XclExpChRoot& rRoot, const ScfPropertySet& rPropSet, bool bSupportsStacked );
};

// ----------------------------------------------------------------------------

/** Represents the CHTEXT record group containing text object properties.

    The CHTEXT group consists of: CHTEXT, CHBEGIN, CHFRAMEPOS, CHFONT,
    CHFORMATRUNS, CHSOURCELINK, CHSTRING, CHFRAME group, CHOBJECTLINK, and CHEND.
 */
class XclExpChText : public XclExpChGroupBase, public XclExpChFontBase
{
public:
    typedef ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XTitle >            XTitleRef;
    typedef ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XRegressionCurve >  XRegressionCurveRef;

public:
    explicit            XclExpChText( const XclExpChRoot& rRoot );

    /** Sets font color and color identifier to internal data structures. */
    virtual void        SetFont( XclExpChFontRef xFont, const Color& rColor, sal_uInt32 nColorId );
    /** Sets text rotation to internal data structures. */
    virtual void        SetRotation( sal_uInt16 nRotation );

    /** Converts all text settings of the passed title text object. */
    void                ConvertTitle( XTitleRef xTitle, sal_uInt16 nTarget );
    /** Converts all text settings of the passed legend. */
    void                ConvertLegend( const ScfPropertySet& rPropSet );
    /** Converts all settings of the passed data point caption text object. */
    bool                ConvertDataLabel( const ScfPropertySet& rPropSet,
                            const XclChTypeInfo& rTypeInfo, const XclChDataPointPos& rPointPos );
    /** Converts all settings of the passed trend line equation box. */
    void                ConvertTrendLineEquation( const ScfPropertySet& rPropSet, const XclChDataPointPos& rPointPos );

    /** Returns true, if the string object does not contain any text data. */
    inline bool         HasString() const { return mxSrcLink.is() && mxSrcLink->HasString(); }
    /** Returns the flags needed for the CHATTACHEDLABEL record. */
    sal_uInt16          GetAttLabelFlags() const;

    /** Writes all embedded records. */
    virtual void        WriteSubRecords( XclExpStream& rStrm );

private:
    virtual void        WriteBody( XclExpStream& rStrm );

private:
    XclChText           maData;             /// Contents of the CHTEXT record.
    XclExpChFramePosRef mxFramePos;         /// Relative text frame position (CHFRAMEPOS record).
    XclExpChSourceLinkRef mxSrcLink;        /// Linked data (CHSOURCELINK with CHSTRING record).
    XclExpChFrameRef    mxFrame;            /// Text object frame properties (CHFRAME group).
    XclExpChFontRef     mxFont;             /// Index into font buffer (CHFONT record).
    XclExpChObjectLinkRef mxObjLink;        /// Link target for this text object.
    XclExpChFrLabelPropsRef mxLabelProps;   /// Extended data label properties (CHFRLABELPROPS record).
    sal_uInt32          mnTextColorId;      /// Text color identifier.
};

typedef ScfRef< XclExpChText > XclExpChTextRef;

// Data series ================================================================

/** The CHMARKERFORMAT record containing data point marker formatting data. */
class XclExpChMarkerFormat : public XclExpRecord
{
public:
    explicit            XclExpChMarkerFormat( const XclExpChRoot& rRoot );

    /** Converts symbol properties from the passed property set. */
    void                Convert( const XclExpChRoot& rRoot,
                            const ScfPropertySet& rPropSet, sal_uInt16 nFormatIdx );
    /** Converts symbol properties for stock charts from the passed property set. */
    void                ConvertStockSymbol( const XclExpChRoot& rRoot,
                            const ScfPropertySet& rPropSet, bool bCloseSymbol );

    /** Returns true, if markers are enabled. */
    inline bool         HasMarker() const { return maData.mnMarkerType != EXC_CHMARKERFORMAT_NOSYMBOL; }
    /** Returns true, if border line of markers is visible. */
    inline bool         HasLineColor() const { return !::get_flag( maData.mnFlags, EXC_CHMARKERFORMAT_NOLINE ); }
    /** Returns true, if fill area of markers is visible. */
    inline bool         HasFillColor() const { return !::get_flag( maData.mnFlags, EXC_CHMARKERFORMAT_NOFILL ); }

private:
    /** Registers marker colors in palette and stores color identifiers. */
    void                RegisterColors( const XclExpChRoot& rRoot );

    virtual void        WriteBody( XclExpStream& rStrm );

private:
    XclChMarkerFormat   maData;             /// Contents of the CHMARKERFORMAT record.
    sal_uInt32          mnLineColorId;      /// Border line color identifier.
    sal_uInt32          mnFillColorId;      /// Fill color identifier.
};

typedef ScfRef< XclExpChMarkerFormat > XclExpChMarkerFormatRef;

// ----------------------------------------------------------------------------

/** The CHPIEFORMAT record containing data point formatting data for pie segments. */
class XclExpChPieFormat : public XclExpUInt16Record
{
public:
    explicit            XclExpChPieFormat();

    /** Sets pie segment properties from the passed property set. */
    void                Convert( const ScfPropertySet& rPropSet );
};

typedef ScfRef< XclExpChPieFormat > XclExpChPieFormatRef;

// ----------------------------------------------------------------------------

/** The CH3DDATAFORMAT record containing the bar type in 3D bar charts. */
class XclExpCh3dDataFormat : public XclExpRecord
{
public:
    explicit            XclExpCh3dDataFormat();

    /** Sets 3d bar properties from the passed property set. */
    void                Convert( const ScfPropertySet& rPropSet );

private:
    virtual void        WriteBody( XclExpStream& rStrm );

private:
    XclCh3dDataFormat   maData;             /// Contents of the CH3DDATAFORMAT record.
};

typedef ScfRef< XclExpCh3dDataFormat > XclExpCh3dDataFormatRef;

// ----------------------------------------------------------------------------

/** The CHATTACHEDLABEL record that contains the type of a data point label. */
class XclExpChAttachedLabel : public XclExpUInt16Record
{
public:
    explicit            XclExpChAttachedLabel( sal_uInt16 nFlags );
};

typedef ScfRef< XclExpChAttachedLabel > XclExpChAttLabelRef;

// ----------------------------------------------------------------------------

/** Represents the CHDATAFORMAT record group containing data point properties.

    The CHDATAFORMAT group consists of: CHDATAFORMAT, CHBEGIN, CHFRAME group,
    CHMARKERFORMAT, CHPIEFORMAT, CH3DDATAFORMAT, CHSERIESFORMAT,
    CHATTACHEDLABEL, CHEND.
 */
class XclExpChDataFormat : public XclExpChGroupBase, public XclExpChFrameBase
{
public:
    explicit            XclExpChDataFormat( const XclExpChRoot& rRoot,
                            const XclChDataPointPos& rPointPos, sal_uInt16 nFormatIdx );

    /** Converts the passed data series or data point formatting. */
    void                ConvertDataSeries( const ScfPropertySet& rPropSet, const XclChExtTypeInfo& rTypeInfo );
    /** Sets default formatting for a series in a stock chart. */
    void                ConvertStockSeries( const ScfPropertySet& rPropSet, bool bCloseSymbol );
    /** Converts line formatting for the specified object (e.g. trend lines, error bars). */
    void                ConvertLine( const ScfPropertySet& rPropSet, XclChObjectType eObjType );

    /** Returns true, if this objects describes the formatting of an entire series. */
    inline bool         IsSeriesFormat() const { return maData.maPointPos.mnPointIdx == EXC_CHDATAFORMAT_ALLPOINTS; }

    /** Writes all embedded records. */
    virtual void        WriteSubRecords( XclExpStream& rStrm );

private:
    virtual void        WriteBody( XclExpStream& rStrm );

private:
    XclChDataFormat     maData;             /// Contents of the CHDATAFORMAT record.
    XclExpChMarkerFormatRef mxMarkerFmt;    /// Data point marker (CHMARKERFORMAT record).
    XclExpChPieFormatRef mxPieFmt;          /// Pie segment format (CHPIEFORMAT record).
    XclExpRecordRef     mxSeriesFmt;        /// Series properties (CHSERIESFORMAT record).
    XclExpCh3dDataFormatRef mx3dDataFmt;    /// 3D bar format (CH3DDATAFORMAT record).
    XclExpChAttLabelRef mxAttLabel;         /// Data point label type (CHATTACHEDLABEL record).
};

typedef ScfRef< XclExpChDataFormat > XclExpChDataFormatRef;

// ----------------------------------------------------------------------------

/** Represents the CHSERTRENDLINE record containing settings for a trend line. */
class XclExpChSerTrendLine : public XclExpRecord, protected XclExpChRoot
{
public:
    typedef ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XRegressionCurve > XRegressionCurveRef;

public:
    explicit            XclExpChSerTrendLine( const XclExpChRoot& rRoot );

    /** Converts the passed trend line, returns true if trend line type is supported. */
    bool                Convert( XRegressionCurveRef xRegCurve, sal_uInt16 nSeriesIdx );

    /** Returns formatting information of the trend line, created in Convert(). */
    inline XclExpChDataFormatRef GetDataFormat() const { return mxDataFmt; }
    /** Returns formatting of the equation text box, created in Convert(). */
    inline XclExpChTextRef GetDataLabel() const { return mxLabel; }

private:
    virtual void        WriteBody( XclExpStream& rStrm );

private:
    XclChSerTrendLine   maData;             /// Contents of the CHSERTRENDLINE record.
    XclExpChDataFormatRef mxDataFmt;        /// Formatting settings of the trend line.
    XclExpChTextRef     mxLabel;            /// Formatting of the equation text box.
};

typedef ScfRef< XclExpChSerTrendLine > XclExpChSerTrendLineRef;

// ----------------------------------------------------------------------------

/** Represents the CHSERERRORBAR record containing settings for error bars. */
class XclExpChSerErrorBar : public XclExpRecord, protected XclExpChRoot
{
public:
    explicit            XclExpChSerErrorBar( const XclExpChRoot& rRoot, sal_uInt8 nBarType );

    /** Converts the passed error bar settings, returns true if error bar type is supported. */
    bool                Convert( XclExpChSourceLink& rValueLink, sal_uInt16& rnValueCount, const ScfPropertySet& rPropSet );

private:
    virtual void        WriteBody( XclExpStream& rStrm );

private:
    XclChSerErrorBar    maData;             /// Contents of the CHSERERRORBAR record.
};

typedef ScfRef< XclExpChSerErrorBar > XclExpChSerErrorBarRef;

// ----------------------------------------------------------------------------

/** Represents the CHSERIES record group describing a data series in a chart.

    The CHSERIES group consists of: CHSERIES, CHBEGIN, CHSOURCELINK groups,
    CHDATAFORMAT groups, CHSERGROUP, CHSERPARENT, CHSERERRORBAR,
    CHSERTRENDLINE, CHEND.
 */
class XclExpChSeries : public XclExpChGroupBase
{
public:
    typedef ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDiagram >                      XDiagramRef;
    typedef ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries >                   XDataSeriesRef;
    typedef ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XLabeledDataSequence >    XLabeledDataSeqRef;
    typedef ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XRegressionCurve >              XRegressionCurveRef;

public:
    explicit            XclExpChSeries( const XclExpChRoot& rRoot, sal_uInt16 nSeriesIdx );

    /** Converts the passed data series (source links and formatting). */
    bool                ConvertDataSeries(
                            XDiagramRef xDiagram, XDataSeriesRef xDataSeries,
                            const XclChExtTypeInfo& rTypeInfo,
                            sal_uInt16 nGroupIdx, sal_uInt16 nFormatIdx );
    /** Converts the passed data series for stock charts. */
    bool                ConvertStockSeries(
                            XDataSeriesRef xDataSeries,
                            const ::rtl::OUString& rValueRole,
                            sal_uInt16 nGroupIdx, sal_uInt16 nFormatIdx, bool bCloseSymbol );
    /** Converts the passed error bar settings (called at trend line child series). */
    bool                ConvertTrendLine( const XclExpChSeries& rParent, XRegressionCurveRef xRegCurve );
    /** Converts the passed error bar settings (called at error bar child series). */
    bool                ConvertErrorBar( const XclExpChSeries& rParent, const ScfPropertySet& rPropSet, sal_uInt8 nBarId );
    /** Converts and inserts category ranges for all inserted series. */
    void                ConvertCategSequence( XLabeledDataSeqRef xCategSeq );

    /** Writes all embedded records. */
    virtual void        WriteSubRecords( XclExpStream& rStrm );

private:
    /** Initializes members of this series to represent a child of the passed series. */
    void                InitFromParent( const XclExpChSeries& rParent );
    /** Tries to create trend line series objects (called at parent series). */
    void                CreateTrendLines( XDataSeriesRef xDataSeries );
    /** Tries to create positive and negative error bar series objects (called at parent series). */
    void                CreateErrorBars( const ScfPropertySet& rPropSet,
                            const ::rtl::OUString& rBarPropName,
                            sal_uInt8 nPosBarId, sal_uInt8 nNegBarId );
    /** Tries to create an error bar series object (called at parent series). */
    void                CreateErrorBar( const ScfPropertySet& rPropSet,
                            const ::rtl::OUString& rShowPropName, sal_uInt8 nBarId );

    virtual void        WriteBody( XclExpStream& rStrm );

private:
    typedef XclExpRecordList< XclExpChDataFormat > XclExpChDataFormatList;

private:
    XclChSeries         maData;             /// Contents of the CHSERIES record.
    XclExpChSourceLinkRef mxTitleLink;      /// Link data for series title.
    XclExpChSourceLinkRef mxValueLink;      /// Link data for series values.
    XclExpChSourceLinkRef mxCategLink;      /// Link data for series category names.
    XclExpChSourceLinkRef mxBubbleLink;     /// Link data for series bubble sizes.
    XclExpChDataFormatRef mxSeriesFmt;      /// CHDATAFORMAT group for series format.
    XclExpChDataFormatList maPointFmts;     /// CHDATAFORMAT groups for data point formats.
    XclExpChSerTrendLineRef mxTrendLine;    /// Trend line settings (CHSERTRENDLINE record).
    XclExpChSerErrorBarRef mxErrorBar;      /// Error bar settings (CHSERERRORBAR record).
    sal_uInt16          mnGroupIdx;         /// Chart type group (CHTYPEGROUP group) this series is assigned to.
    sal_uInt16          mnSeriesIdx;        /// 0-based series index.
    sal_uInt16          mnParentIdx;        /// 0-based index of parent series (trend lines and error bars).
};

typedef ScfRef< XclExpChSeries > XclExpChSeriesRef;

// Chart type groups ==========================================================

/** Represents the chart type record for all supported chart types. */
class XclExpChType : public XclExpRecord, protected XclExpChRoot
{
public:
    typedef ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDiagram >      XDiagramRef;
    typedef ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >    XChartTypeRef;

public:
    explicit            XclExpChType( const XclExpChRoot& rRoot );

    /** Converts the passed chart type and the contained data series. */
    void                Convert( XDiagramRef xDiagram, XChartTypeRef xChartType,
                            sal_Int32 nApiAxesSetIdx, bool bSwappedAxesSet, bool bHasXLabels );
    /** Sets stacking mode (standard or percent) for the series in this chart type group. */
    void                SetStacked( bool bPercent );

    /** Returns true, if this is object represents a valid chart type. */
    inline bool         IsValidType() const { return maTypeInfo.meTypeId != EXC_CHTYPEID_UNKNOWN; }
    /** Returns the chart type info struct for the contained chart type. */
    inline const XclChTypeInfo& GetTypeInfo() const { return maTypeInfo; }

private:
    virtual void        WriteBody( XclExpStream& rStrm );

private:
    XclChType           maData;             /// Contents of the chart type record.
    XclChTypeInfo       maTypeInfo;         /// Chart type info for the contained type.
};

// ----------------------------------------------------------------------------

/** Represents the CHCHART3D record that contains 3D view settings. */
class XclExpChChart3d : public XclExpRecord
{
public:
    explicit            XclExpChChart3d();

    /** Converts 3d settings for the passed chart type. */
    void                Convert( const ScfPropertySet& rPropSet, bool b3dWallChart );
    /** Sets flag that the data points are clustered on the X axis. */
    inline void         SetClustered() { ::set_flag( maData.mnFlags, EXC_CHCHART3D_CLUSTER ); }

    /** Returns true, if the data points are clustered on the X axis. */
    inline bool         IsClustered() const { return ::get_flag( maData.mnFlags, EXC_CHCHART3D_CLUSTER ); }

private:
    virtual void        WriteBody( XclExpStream& rStrm );

private:
    XclChChart3d        maData;             /// Contents of the CHCHART3D record.
};

typedef ScfRef< XclExpChChart3d > XclExpChChart3dRef;

// ----------------------------------------------------------------------------

/** Represents the CHLEGEND record group describing the chart legend.

    The CHLEGEND group consists of: CHLEGEND, CHBEGIN, CHFRAMEPOS, CHFRAME
    group, CHTEXT group, CHEND.
 */
class XclExpChLegend : public XclExpChGroupBase
{
public:
    explicit            XclExpChLegend( const XclExpChRoot& rRoot );

    /** Converts all legend settings from the passed property set. */
    void                Convert( const ScfPropertySet& rPropSet );

    /** Writes all embedded records. */
    virtual void        WriteSubRecords( XclExpStream& rStrm );

private:
    virtual void        WriteBody( XclExpStream& rStrm );

private:
    XclChLegend         maData;             /// Contents of the CHLEGEND record.
    XclExpChFramePosRef mxFramePos;         /// Legend frame position (CHFRAMEPOS record).
    XclExpChTextRef     mxText;             /// Legend text format (CHTEXT group).
    XclExpChFrameRef    mxFrame;            /// Legend frame format (CHFRAME group).
};

typedef ScfRef< XclExpChLegend > XclExpChLegendRef;

// ----------------------------------------------------------------------------

/** Represents the CHDROPBAR record group describing pos/neg bars in line charts.

    The CHDROPBAR group consists of: CHDROPBAR, CHBEGIN, CHLINEFORMAT,
    CHAREAFORMAT, CHESCHERFORMAT group, CHEND.
 */
class XclExpChDropBar : public XclExpChGroupBase, public XclExpChFrameBase
{
public:
    explicit            XclExpChDropBar( const XclExpChRoot& rRoot, XclChObjectType eObjType );

    /** Converts and writes the contained frame data to the passed property set. */
    void                Convert( const ScfPropertySet& rPropSet );

    /** Writes all embedded records. */
    virtual void        WriteSubRecords( XclExpStream& rStrm );

private:
    virtual void        WriteBody( XclExpStream& rStrm );

private:
    XclChObjectType     meObjType;          /// Type of the dropbar.
    sal_uInt16          mnBarDist;          /// Distance between bars (CHDROPBAR record).
};

typedef ScfRef< XclExpChDropBar > XclExpChDropBarRef;

// ----------------------------------------------------------------------------

/** Represents the CHTYPEGROUP record group describing a group of series.

    The CHTYPEGROUP group consists of: CHTYPEGROUP, CHBEGIN, a chart type
    record (e.g. CHBAR, CHLINE, CHAREA, CHPIE, ...), CHCHART3D, CHLEGEND group,
    CHDROPBAR groups, CHCHARTLINE groups (CHCHARTLINE with CHLINEFORMAT),
    CHDATAFORMAT group, CHEND.
 */
class XclExpChTypeGroup : public XclExpChGroupBase
{
public:
    typedef ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDiagram >                      XDiagramRef;
    typedef ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >                    XChartTypeRef;
    typedef ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries >                   XDataSeriesRef;
    typedef ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XLabeledDataSequence >    XLabeledDataSeqRef;

public:
    explicit            XclExpChTypeGroup( const XclExpChRoot& rRoot, sal_uInt16 nGroupIdx );

    /** Converts the passed chart type to Excel type settings. */
    void                ConvertType( XDiagramRef xDiagram, XChartTypeRef xChartType,
                            sal_Int32 nApiAxesSetIdx, bool b3dChart, bool bSwappedAxesSet, bool bHasXLabels );
    /** Converts and inserts all series from the passed chart type. */
    void                ConvertSeries( XDiagramRef xDiagram, XChartTypeRef xChartType,
                            sal_Int32 nGroupAxesSetIdx, bool bPercent, bool bConnectorLines );
    /** Converts and inserts category ranges for all inserted series. */
    void                ConvertCategSequence( XLabeledDataSeqRef xCategSeq );
    /** Creates a legend object and converts all legend settings. */
    void                ConvertLegend( const ScfPropertySet& rPropSet );

    /** Returns true, if this chart type group contains at least one valid series. */
    inline bool         IsValidGroup() const { return !maSeries.IsEmpty() && maType.IsValidType(); }
    /** Returns the index of this chart type group format. */
    inline sal_uInt16   GetGroupIdx() const { return maData.mnGroupIdx; }
    /** Returns the chart type info struct for the contained chart type. */
    inline const XclChExtTypeInfo& GetTypeInfo() const { return maTypeInfo; }
    /** Returns true, if the chart is three-dimensional. */
    inline bool         Is3dChart() const { return maTypeInfo.mb3dChart; }
    /** Returns true, if chart type supports wall and floor format. */
    inline bool         Is3dWallChart() const { return Is3dChart() && (maTypeInfo.meTypeCateg != EXC_CHTYPECATEG_PIE); }
    /** Returns true, if the series in this chart type group are ordered on the Z axis. */
    inline bool         Is3dDeepChart() const { return Is3dWallChart() && mxChart3d.is() && !mxChart3d->IsClustered(); }
    /** Returns true, if this chart type can be combined with other types. */
    inline bool         IsCombinable2d() const { return !Is3dChart() && maTypeInfo.mbCombinable2d; }

    /** Writes all embedded records. */
    virtual void        WriteSubRecords( XclExpStream& rStrm );

private:
    /** Returns an unused format index to be used for the next created series. */
    sal_uInt16          GetFreeFormatIdx() const;
    /** Creates all data series of any chart type except stock charts. */
    void                CreateDataSeries( XDiagramRef xDiagram,
                            XDataSeriesRef xDataSeries );
    /** Creates all data series of a stock chart. */
    void                CreateAllStockSeries( XChartTypeRef xChartType,
                            XDataSeriesRef xDataSeries );
    /** Creates a single data series of a stock chart. */
    bool                CreateStockSeries( XDataSeriesRef xDataSeries,
                            const ::rtl::OUString& rValueRole, bool bCloseSymbol );

    virtual void        WriteBody( XclExpStream& rStrm );

private:
    typedef XclExpRecordList< XclExpChSeries >          XclExpChSeriesList;
    typedef ScfRefMap< sal_uInt16, XclExpChLineFormat > XclExpChLineFormatMap;

    XclChTypeGroup      maData;             /// Contents of the CHTYPEGROUP record.
    XclExpChType        maType;             /// Chart type (e.g. CHBAR, CHLINE, ...).
    XclChExtTypeInfo    maTypeInfo;         /// Extended chart type info.
    XclExpChSeriesList  maSeries;           /// List of series data (CHSERIES groups).
    XclExpChChart3dRef  mxChart3d;          /// 3D settings (CHCHART3D record).
    XclExpChLegendRef   mxLegend;           /// Chart legend (CHLEGEND group).
    XclExpChDropBarRef  mxUpBar;            /// White dropbars (CHDROPBAR group).
    XclExpChDropBarRef  mxDownBar;          /// Black dropbars (CHDROPBAR group).
    XclExpChLineFormatMap maChartLines;     /// Global line formats (CHCHARTLINE group).
};

typedef ScfRef< XclExpChTypeGroup > XclExpChTypeGroupRef;

// Axes =======================================================================

class XclExpChLabelRange : public XclExpRecord, protected XclExpChRoot
{
public:
    explicit            XclExpChLabelRange( const XclExpChRoot& rRoot );

    /** Converts category axis scaling settings. */
    void                Convert( const ::com::sun::star::chart2::ScaleData& rScaleData,
                            const ScfPropertySet& rChart1Axis, bool bMirrorOrient );
    /** Converts position settings of a crossing axis at this axis. */
    void                ConvertAxisPosition( const ScfPropertySet& rPropSet );
    /** Sets flag for tickmark position between categories or on categories. */
    inline void         SetTicksBetweenCateg( bool bTicksBetween )
                            { ::set_flag( maLabelData.mnFlags, EXC_CHLABELRANGE_BETWEEN, bTicksBetween ); }

private:
    virtual void        Save( XclExpStream& rStrm );
    virtual void        WriteBody( XclExpStream& rStrm );

private:
    XclChLabelRange     maLabelData;        /// Contents of the CHLABELRANGE record.
    XclChDateRange      maDateData;         /// Contents of the CHDATERANGE record.
};

typedef ScfRef< XclExpChLabelRange > XclExpChLabelRangeRef;

// ----------------------------------------------------------------------------

class XclExpChValueRange : public XclExpRecord, protected XclExpChRoot
{
public:
    explicit            XclExpChValueRange( const XclExpChRoot& rRoot );

    /** Converts value axis scaling settings. */
    void                Convert( const ::com::sun::star::chart2::ScaleData& rScaleData );
    /** Converts position settings of a crossing axis at this axis. */
    void                ConvertAxisPosition( const ScfPropertySet& rPropSet );

private:
    virtual void        WriteBody( XclExpStream& rStrm );

private:
    XclChValueRange     maData;             /// Contents of the CHVALUERANGE record.
};

typedef ScfRef< XclExpChValueRange > XclExpChValueRangeRef;

// ----------------------------------------------------------------------------

class XclExpChTick : public XclExpRecord, protected XclExpChRoot
{
public:
    explicit            XclExpChTick( const XclExpChRoot& rRoot );

    /** Converts axis tick mark settings. */
    void                Convert( const ScfPropertySet& rPropSet, const XclChExtTypeInfo& rTypeInfo, sal_uInt16 nAxisType );
    /** Sets font color and color identifier to internal data structures. */
    void                SetFontColor( const Color& rColor, sal_uInt32 nColorId );
    /** Sets text rotation to internal data structures. */
    void                SetRotation( sal_uInt16 nRotation );

private:
    virtual void        WriteBody( XclExpStream& rStrm );

private:
    XclChTick           maData;             /// Contents of the CHTICK record.
    sal_uInt32          mnTextColorId;      /// Axis labels text color identifier.
};

typedef ScfRef< XclExpChTick > XclExpChTickRef;

// ----------------------------------------------------------------------------

/** Represents the CHAXIS record group describing an entire chart axis.

    The CHAXIS group consists of: CHAXIS, CHBEGIN, CHLABELRANGE, CHEXTRANGE,
    CHVALUERANGE, CHFORMAT, CHTICK, CHFONT, CHAXISLINE groups (CHAXISLINE with
    CHLINEFORMAT, CHAREAFORMAT, and CHESCHERFORMAT group), CHEND.
 */
class XclExpChAxis : public XclExpChGroupBase, public XclExpChFontBase
{
public:
    typedef ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDiagram >  XDiagramRef;
    typedef ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XAxis >     XAxisRef;
    typedef ::com::sun::star::uno::Reference< ::com::sun::star::chart::XAxis >      XChart1AxisRef;

public:
    explicit            XclExpChAxis( const XclExpChRoot& rRoot, sal_uInt16 nAxisType );

    /** Sets font color and color identifier to internal data structures. */
    virtual void        SetFont( XclExpChFontRef xFont, const Color& rColor, sal_uInt32 nColorId );
    /** Sets text rotation to internal data structures. */
    virtual void        SetRotation( sal_uInt16 nRotation );

    /** Converts formatting and scaling settings from the passed axis. */
    void                Convert( XAxisRef xAxis, XAxisRef xCrossingAxis,
                            XChart1AxisRef xChart1Axis, const XclChExtTypeInfo& rTypeInfo );
    /** Converts and writes 3D wall/floor properties from the passed diagram. */
    void                ConvertWall( XDiagramRef xDiagram );

    /** Returns the type of this axis. */
    inline sal_uInt16   GetAxisType() const { return maData.mnType; }
    /** Returns the axis dimension index used by the chart API. */
    inline sal_Int32    GetApiAxisDimension() const { return maData.GetApiAxisDimension(); }

    /** Writes all embedded records. */
    virtual void        WriteSubRecords( XclExpStream& rStrm );

private:
    virtual void        WriteBody( XclExpStream& rStrm );

private:
    XclChAxis           maData;             /// Contents of the CHAXIS record.
    XclExpChLabelRangeRef mxLabelRange;     /// Category scaling (CHLABELRANGE record).
    XclExpChValueRangeRef mxValueRange;     /// Value scaling (CHVALUERANGE record).
    XclExpChTickRef     mxTick;             /// Axis ticks (CHTICK record).
    XclExpChFontRef     mxFont;             /// Index into font buffer (CHFONT record).
    XclExpChLineFormatRef mxAxisLine;       /// Axis line format (CHLINEFORMAT record).
    XclExpChLineFormatRef mxMajorGrid;      /// Major grid line format (CHLINEFORMAT record).
    XclExpChLineFormatRef mxMinorGrid;      /// Minor grid line format (CHLINEFORMAT record).
    XclExpChFrameRef    mxWallFrame;        /// Wall/floor format (sub records of CHFRAME group).
    sal_uInt16          mnNumFmtIdx;        /// Index into number format buffer (CHFORMAT record).
};

typedef ScfRef< XclExpChAxis > XclExpChAxisRef;

// ----------------------------------------------------------------------------

/** Represents the CHAXESSET record group describing an axes set (X/Y/Z axes).

    The CHAXESSET group consists of: CHAXESSET, CHBEGIN, CHFRAMEPOS, CHAXIS
    groups, CHTEXT groups, CHPLOTFRAME group (CHPLOTFRAME with CHFRAME group),
    CHTYPEGROUP group, CHEND.
 */
class XclExpChAxesSet : public XclExpChGroupBase
{
public:
    typedef ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDiagram >          XDiagramRef;
    typedef ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XCoordinateSystem > XCoordSystemRef;

public:
    explicit            XclExpChAxesSet( const XclExpChRoot& rRoot, sal_uInt16 nAxesSetId );

    /** Converts the passed diagram to chart record data.
        @return  First unused chart type group index. */
    sal_uInt16          Convert( XDiagramRef xDiagram, sal_uInt16 nFirstGroupIdx );

    /** Returns true, if this axes set exists (returns false if this is a dummy object). */
    inline bool         IsValidAxesSet() const { return !maTypeGroups.IsEmpty(); }
    /** Returns the index of the axes set (primary/secondary). */
    inline sal_uInt16   GetAxesSetId() const { return maData.mnAxesSetId; }
    /** Returns the axes set index used by the chart API. */
    inline sal_Int32    GetApiAxesSetIndex() const { return maData.GetApiAxesSetIndex(); }
    /** Returns true, if the chart is three-dimensional. */
    bool                Is3dChart() const;

    /** Writes all embedded records. */
    virtual void        WriteSubRecords( XclExpStream& rStrm );

private:
    /** Returns first inserted chart type group. */
    XclExpChTypeGroupRef GetFirstTypeGroup() const;
    /** Returns last inserted chart type group. */
    XclExpChTypeGroupRef GetLastTypeGroup() const;

    /** Converts a complete axis object including axis title. */
    void                ConvertAxis( XclExpChAxisRef& rxChAxis, sal_uInt16 nAxisType,
                            XclExpChTextRef& rxChAxisTitle, sal_uInt16 nTitleTarget,
                            XCoordSystemRef xCoordSystem, const XclChExtTypeInfo& rTypeInfo,
                            sal_Int32 nCrossingAxisDim );

    virtual void        WriteBody( XclExpStream& rStrm );

private:
    typedef XclExpRecordList< XclExpChTypeGroup > XclExpChTypeGroupList;

    XclChAxesSet        maData;             /// Contents of the CHAXESSET record.
    XclExpChFramePosRef mxFramePos;         /// Outer plot area position (CHFRAMEPOS record).
    XclExpChAxisRef     mxXAxis;            /// The X axis (CHAXIS group).
    XclExpChAxisRef     mxYAxis;            /// The Y axis (CHAXIS group).
    XclExpChAxisRef     mxZAxis;            /// The Z axis (CHAXIS group).
    XclExpChTextRef     mxXAxisTitle;       /// The X axis title (CHTEXT group).
    XclExpChTextRef     mxYAxisTitle;       /// The Y axis title (CHTEXT group).
    XclExpChTextRef     mxZAxisTitle;       /// The Z axis title (CHTEXT group).
    XclExpChFrameRef    mxPlotFrame;        /// Plot area (CHPLOTFRAME group).
    XclExpChTypeGroupList maTypeGroups;     /// Chart type groups (CHTYPEGROUP group).
};

typedef ScfRef< XclExpChAxesSet > XclExpChAxesSetRef;

// The chart object ===========================================================

/** Represents the CHCHART record group describing the chart contents.

    The CHCHART group consists of: CHCHART, CHBEGIN, SCL, CHPLOTGROWTH, CHFRAME
    group, CHSERIES groups, CHPROPERTIES, CHDEFAULTTEXT groups (CHDEFAULTTEXT
    with CHTEXT groups), CHUSEDAXESSETS, CHAXESSET groups, CHTEXT groups, CHEND.
 */
class XclExpChChart : public XclExpChGroupBase
{
public:
    typedef ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartDocument > XChartDocRef;

public:
    explicit            XclExpChChart( const XclExpRoot& rRoot,
                            XChartDocRef xChartDoc, const Rectangle& rChartRect );

    /** Creates, registers and returns a new data series object. */
    XclExpChSeriesRef   CreateSeries();
    /** Removes the last created data series object from the series list. */
    void                RemoveLastSeries();
    /** Stores a CHTEXT group that describes a data point label. */
    void                SetDataLabel( XclExpChTextRef xText );
    /** Sets the plot area position and size to manual mode. */
    void                SetManualPlotArea();

    /** Writes all embedded records. */
    virtual void        WriteSubRecords( XclExpStream& rStrm );

private:
    virtual void        WriteBody( XclExpStream& rStrm );

private:
    typedef XclExpRecordList< XclExpChSeries >  XclExpChSeriesList;
    typedef XclExpRecordList< XclExpChText >    XclExpChTextList;

    XclChRectangle      maRect;             /// Position of the chart on the sheet (CHCHART record).
    XclExpChSeriesList  maSeries;           /// List of series data (CHSERIES groups).
    XclExpChFrameRef    mxFrame;            /// Chart frame format (CHFRAME group).
    XclChProperties     maProps;            /// Chart properties (CHPROPERTIES record).
    XclExpChAxesSetRef  mxPrimAxesSet;      /// Primary axes set (CHAXESSET group).
    XclExpChAxesSetRef  mxSecnAxesSet;      /// Secondary axes set (CHAXESSET group).
    XclExpChTextRef     mxTitle;            /// Chart title (CHTEXT group).
    XclExpChTextList    maLabels;           /// Data point labels (CHTEXT groups).
};

// ----------------------------------------------------------------------------

/** Represents the group of DFF and OBJ records containing all drawing shapes
    embedded in the chart object.
 */
class XclExpChartDrawing : public XclExpRecordBase, protected XclExpRoot
{
public:
    explicit            XclExpChartDrawing(
                            const XclExpRoot& rRoot,
                            const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& rxModel,
                            const Size& rChartSize );
    virtual             ~XclExpChartDrawing();

    virtual void        Save( XclExpStream& rStrm );

private:
    ScfRef< XclExpObjectManager > mxObjMgr;
    ScfRef< XclExpRecordBase > mxObjRecs;
};

// ----------------------------------------------------------------------------

/** Represents the entire chart substream (all records in BOF/EOF block). */
class XclExpChart : public XclExpSubStream, protected XclExpRoot
{
public:
    typedef ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > XModelRef;

public:
    explicit            XclExpChart( const XclExpRoot& rRoot,
                            XModelRef xModel, const Rectangle& rChartRect );
};

// ============================================================================

#endif