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
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* 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.
*
************************************************************************/
#include <sax/tools/converter.hxx>
#include "SchXMLPlotAreaContext.hxx"
#include "SchXMLImport.hxx"
#include "SchXMLAxisContext.hxx"
#include "SchXMLSeries2Context.hxx"
#include "SchXMLTools.hxx"
#include <tools/debug.hxx>
#include <comphelper/processfactory.hxx>
#include "xmloff/xmlnmspe.hxx"
#include <xmloff/xmlement.hxx>
#include <xmloff/nmspmap.hxx>
#include <xmloff/xmluconv.hxx>
#include <xmloff/prstylei.hxx>
#include <xmloff/xmlstyle.hxx>
#include "xexptran.hxx"
#include <cppuhelper/implbase1.hxx>
#include <com/sun/star/awt/Point.hpp>
#include <com/sun/star/awt/Size.hpp>
#include <com/sun/star/chart/ChartDataRowSource.hpp>
#include <com/sun/star/chart/X3DDisplay.hpp>
#include <com/sun/star/chart/XStatisticDisplay.hpp>
#include <com/sun/star/chart/XDiagramPositioning.hpp>
#include <com/sun/star/chart2/data/XRangeXMLConversion.hpp>
#include <com/sun/star/chart2/XChartTypeContainer.hpp>
#include <com/sun/star/chart2/XDataSeriesContainer.hpp>
#include <com/sun/star/chart2/RelativePosition.hpp>
#include <com/sun/star/drawing/CameraGeometry.hpp>
#include <com/sun/star/drawing/FillStyle.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/util/XStringMapping.hpp>
#include <com/sun/star/xml/sax/XAttributeList.hpp>
using namespace com::sun::star;
using namespace ::xmloff::token;
using ::rtl::OUString;
using com::sun::star::uno::Reference;
namespace
{
struct lcl_AxisHasCategories : public ::std::unary_function< SchXMLAxis, bool >
{
bool operator() ( const SchXMLAxis & rAxis )
{
return rAxis.bHasCategories;
}
};
OUString lcl_ConvertRange( const ::rtl::OUString & rRange, const uno::Reference< chart2::XChartDocument > & xDoc )
{
OUString aResult = rRange;
if(!xDoc.is())
return aResult;
uno::Reference< chart2::data::XRangeXMLConversion > xConversion(
xDoc->getDataProvider(), uno::UNO_QUERY );
if( xConversion.is())
aResult = xConversion->convertRangeFromXML( rRange );
return aResult;
}
} // anonymous namespace
SchXML3DSceneAttributesHelper::SchXML3DSceneAttributesHelper( SvXMLImport& rImporter )
: SdXML3DSceneAttributesHelper( rImporter )
{
}
void SchXML3DSceneAttributesHelper::getCameraDefaultFromDiagram( const uno::Reference< chart::XDiagram >& xDiagram )
{
//different defaults for camera geometry necessary to workaround wrong behaviour in old chart
//in future make this version dependent if we have versioning (metastream) for ole objects
try
{
uno::Reference< beans::XPropertySet > xProp( xDiagram, uno::UNO_QUERY );
if( xProp.is() )
{
drawing::CameraGeometry aCamGeo;
xProp->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "D3DCameraGeometry" ))) >>= aCamGeo;
maVRP.setX( aCamGeo.vrp.PositionX );
maVRP.setY( aCamGeo.vrp.PositionY );
maVRP.setZ( aCamGeo.vrp.PositionZ );
maVPN.setX( aCamGeo.vpn.DirectionX );
maVPN.setY( aCamGeo.vpn.DirectionY );
maVPN.setZ( aCamGeo.vpn.DirectionZ );
maVUP.setX( aCamGeo.vup.DirectionX );
maVUP.setY( aCamGeo.vup.DirectionY );
maVUP.setZ( aCamGeo.vup.DirectionZ );
}
}
catch( const uno::Exception & rEx )
{
#ifdef DBG_UTIL
rtl::OString aBStr(rtl::OUStringToOString(rEx.Message, RTL_TEXTENCODING_ASCII_US));
OSL_TRACE( "Exception caught for property NumberOfLines: %s", aBStr.getStr());
#else
(void)rEx; // avoid warning for pro build
#endif
}
}
SchXML3DSceneAttributesHelper::~SchXML3DSceneAttributesHelper()
{
}
SchXMLPlotAreaContext::SchXMLPlotAreaContext(
SchXMLImportHelper& rImpHelper,
SvXMLImport& rImport, const rtl::OUString& rLocalName,
const rtl::OUString& rXLinkHRefAttributeToIndicateDataProvider,
uno::Sequence< chart::ChartSeriesAddress >& rSeriesAddresses,
::rtl::OUString& rCategoriesAddress,
::rtl::OUString& rChartAddress,
bool& rbHasRangeAtPlotArea,
sal_Bool & rAllRangeAddressesAvailable,
sal_Bool & rColHasLabels,
sal_Bool & rRowHasLabels,
chart::ChartDataRowSource & rDataRowSource,
SeriesDefaultsAndStyles& rSeriesDefaultsAndStyles,
const ::rtl::OUString& aChartTypeServiceName,
tSchXMLLSequencesPerIndex & rLSequencesPerIndex,
const awt::Size & rChartSize ) :
SvXMLImportContext( rImport, XML_NAMESPACE_CHART, rLocalName ),
mrImportHelper( rImpHelper ),
mrSeriesAddresses( rSeriesAddresses ),
mrCategoriesAddress( rCategoriesAddress ),
mrSeriesDefaultsAndStyles( rSeriesDefaultsAndStyles ),
mnNumOfLinesProp( 0 ),
mbStockHasVolume( sal_False ),
mnSeries( 0 ),
m_aGlobalSeriesImportInfo( rAllRangeAddressesAvailable ),
maSceneImportHelper( rImport ),
m_aOuterPositioning( rImport ),
m_aInnerPositioning( rImport ),
mbPercentStacked(false),
m_bAxisPositionAttributeImported(false),
m_rXLinkHRefAttributeToIndicateDataProvider(rXLinkHRefAttributeToIndicateDataProvider),
mrChartAddress( rChartAddress ),
m_rbHasRangeAtPlotArea( rbHasRangeAtPlotArea ),
mrColHasLabels( rColHasLabels ),
mrRowHasLabels( rRowHasLabels ),
mrDataRowSource( rDataRowSource ),
maChartTypeServiceName( aChartTypeServiceName ),
mrLSequencesPerIndex( rLSequencesPerIndex ),
mbGlobalChartTypeUsedBySeries( false ),
maChartSize( rChartSize )
{
m_rbHasRangeAtPlotArea = false;
// get Diagram
uno::Reference< chart::XChartDocument > xDoc( rImpHelper.GetChartDocument(), uno::UNO_QUERY );
if( xDoc.is())
{
mxDiagram = xDoc->getDiagram();
mxNewDoc.set( xDoc, uno::UNO_QUERY );
maSceneImportHelper.getCameraDefaultFromDiagram( mxDiagram );
}
DBG_ASSERT( mxDiagram.is(), "Couldn't get XDiagram" );
// turn off all axes initially
uno::Any aFalseBool;
aFalseBool <<= (sal_Bool)(sal_False);
uno::Reference< lang::XServiceInfo > xInfo( mxDiagram, uno::UNO_QUERY );
uno::Reference< beans::XPropertySet > xProp( mxDiagram, uno::UNO_QUERY );
if( xInfo.is() &&
xProp.is())
{
try
{
xProp->setPropertyValue(
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "HasXAxis" )), aFalseBool );
xProp->setPropertyValue(
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "HasXAxisGrid" )), aFalseBool );
xProp->setPropertyValue(
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "HasXAxisDescription" )), aFalseBool );
xProp->setPropertyValue(
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "HasSecondaryXAxis" )), aFalseBool );
xProp->setPropertyValue(
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "HasSecondaryXAxisDescription" )), aFalseBool );
xProp->setPropertyValue(
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "HasYAxis" )), aFalseBool );
xProp->setPropertyValue(
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "HasYAxisGrid" )), aFalseBool );
xProp->setPropertyValue(
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "HasYAxisDescription" )), aFalseBool );
xProp->setPropertyValue(
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "HasSecondaryYAxis" )), aFalseBool );
xProp->setPropertyValue(
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "HasSecondaryYAxisDescription" )), aFalseBool );
xProp->setPropertyValue(
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "HasZAxis" )), aFalseBool );
xProp->setPropertyValue(
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "HasZAxisDescription" )), aFalseBool );
uno::Any aAny;
chart::ChartDataRowSource eSource = chart::ChartDataRowSource_COLUMNS;
aAny <<= eSource;
xProp->setPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "DataRowSource" )), aAny );
}
catch( const beans::UnknownPropertyException & )
{
OSL_FAIL( "Property required by service not supported" );
}
}
}
SchXMLPlotAreaContext::~SchXMLPlotAreaContext()
{}
void SchXMLPlotAreaContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
{
// parse attributes
sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
const SvXMLTokenMap& rAttrTokenMap = mrImportHelper.GetPlotAreaAttrTokenMap();
uno::Reference< chart2::XChartDocument > xNewDoc( GetImport().GetModel(), uno::UNO_QUERY );
for( sal_Int16 i = 0; i < nAttrCount; i++ )
{
rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
rtl::OUString aLocalName;
rtl::OUString aValue = xAttrList->getValueByIndex( i );
sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
switch( rAttrTokenMap.Get( nPrefix, aLocalName ))
{
case XML_TOK_PA_X:
case XML_TOK_PA_Y:
case XML_TOK_PA_WIDTH:
case XML_TOK_PA_HEIGHT:
m_aOuterPositioning.readPositioningAttribute( nPrefix, aLocalName, aValue );
break;
case XML_TOK_PA_STYLE_NAME:
msAutoStyleName = aValue;
break;
case XML_TOK_PA_CHART_ADDRESS:
mrChartAddress = lcl_ConvertRange( aValue, xNewDoc );
// indicator for getting data from the outside
m_rbHasRangeAtPlotArea = true;
break;
case XML_TOK_PA_DS_HAS_LABELS:
{
if( aValue.equals( ::xmloff::token::GetXMLToken( ::xmloff::token::XML_BOTH )))
mrColHasLabels = mrRowHasLabels = sal_True;
else if( aValue.equals( ::xmloff::token::GetXMLToken( ::xmloff::token::XML_ROW )))
mrRowHasLabels = sal_True;
else if( aValue.equals( ::xmloff::token::GetXMLToken( ::xmloff::token::XML_COLUMN )))
mrColHasLabels = sal_True;
}
break;
case XML_TOK_PA_TRANSFORM:
case XML_TOK_PA_VRP:
case XML_TOK_PA_VPN:
case XML_TOK_PA_VUP:
case XML_TOK_PA_PROJECTION:
case XML_TOK_PA_DISTANCE:
case XML_TOK_PA_FOCAL_LENGTH:
case XML_TOK_PA_SHADOW_SLANT:
case XML_TOK_PA_SHADE_MODE:
case XML_TOK_PA_AMBIENT_COLOR:
case XML_TOK_PA_LIGHTING_MODE:
maSceneImportHelper.processSceneAttribute( nPrefix, aLocalName, aValue );
break;
}
}
if( ! mxNewDoc.is())
{
uno::Reference< beans::XPropertySet > xDocProp( mrImportHelper.GetChartDocument(), uno::UNO_QUERY );
if( xDocProp.is())
{
try
{
uno::Any aAny;
aAny <<= (sal_Bool)(mrColHasLabels);
xDocProp->setPropertyValue(
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "DataSourceLabelsInFirstColumn" )),
aAny );
aAny <<= (sal_Bool)(mrRowHasLabels);
xDocProp->setPropertyValue(
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "DataSourceLabelsInFirstRow" )),
aAny );
}
catch( const beans::UnknownPropertyException & )
{
SAL_INFO( "vcl", "Properties missing" );
}
}
}
// set properties
uno::Reference< beans::XPropertySet > xProp( mxDiagram, uno::UNO_QUERY );
if( msAutoStyleName.getLength())
{
if( xProp.is())
{
const SvXMLStylesContext* pStylesCtxt = mrImportHelper.GetAutoStylesContext();
if( pStylesCtxt )
{
const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext(
mrImportHelper.GetChartFamilyID(), msAutoStyleName );
XMLPropStyleContext* pPropStyleContext =
const_cast< XMLPropStyleContext * >(
dynamic_cast< const XMLPropStyleContext * >( pStyle ) );
if( pPropStyleContext )
{
pPropStyleContext->FillPropertySet( xProp );
// get the data row source that was set without having data
xProp->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "DataRowSource" )))
>>= mrDataRowSource;
//lines on/off
//this old property is not supported fully anymore with the new chart, so we need to get the information a little bit different from similar properties
mrSeriesDefaultsAndStyles.maLinesOnProperty = SchXMLTools::getPropertyFromContext(
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Lines")), pPropStyleContext, pStylesCtxt );
//handle automatic position and size
m_aOuterPositioning.readAutomaticPositioningProperties( pPropStyleContext, pStylesCtxt );
//correct default starting angle for old 3D pies
if( SchXMLTools::isDocumentGeneratedWithOpenOfficeOlderThan3_0( GetImport().GetModel() ) )
{
bool bIs3d = false;
if( xProp.is() && ( xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Dim3D"))) >>= bIs3d ) &&
bIs3d )
{
if( maChartTypeServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.PieChartType" ))
|| maChartTypeServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.DonutChartType" )) )
{
::rtl::OUString aPropName( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StartingAngle")) );
uno::Any aAStartingAngle( SchXMLTools::getPropertyFromContext( aPropName, pPropStyleContext, pStylesCtxt ) );
if( !aAStartingAngle.hasValue() )
xProp->setPropertyValue( aPropName, uno::makeAny(sal_Int32(0)) ) ;
}
}
}
}
}
}
}
//remember default values for dataseries
if(xProp.is())
try
{
mrSeriesDefaultsAndStyles.maSymbolTypeDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SymbolType")));
mrSeriesDefaultsAndStyles.maDataCaptionDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DataCaption")));
mrSeriesDefaultsAndStyles.maErrorIndicatorDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ErrorIndicator")));
mrSeriesDefaultsAndStyles.maErrorCategoryDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ErrorCategory")));
mrSeriesDefaultsAndStyles.maConstantErrorLowDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ConstantErrorLow")));
mrSeriesDefaultsAndStyles.maConstantErrorHighDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ConstantErrorHigh")));
mrSeriesDefaultsAndStyles.maPercentageErrorDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PercentageError")));
mrSeriesDefaultsAndStyles.maErrorMarginDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ErrorMargin")));
mrSeriesDefaultsAndStyles.maMeanValueDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MeanValue")));
mrSeriesDefaultsAndStyles.maRegressionCurvesDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RegressionCurves")));
bool bStacked = false;
mrSeriesDefaultsAndStyles.maStackedDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Stacked")));
mrSeriesDefaultsAndStyles.maStackedDefault >>= bStacked;
mrSeriesDefaultsAndStyles.maPercentDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Percent")));
mrSeriesDefaultsAndStyles.maPercentDefault >>= mbPercentStacked;
mrSeriesDefaultsAndStyles.maStackedBarsConnectedDefault = xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StackedBarsConnected")));
// deep
uno::Any aDeepProperty( xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Deep"))));
// #124488# old versions store a 3d area and 3D line deep chart with Deep==false => workaround for this
if( ! (bStacked || mbPercentStacked ))
{
if( SchXMLTools::isDocumentGeneratedWithOpenOfficeOlderThan2_3( GetImport().GetModel() ) )
{
bool bIs3d = false;
if( ( xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Dim3D"))) >>= bIs3d ) &&
bIs3d )
{
if( maChartTypeServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.AreaChartType" )) ||
maChartTypeServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.LineChartType" )) )
{
aDeepProperty <<= uno::makeAny( true );
}
}
}
}
mrSeriesDefaultsAndStyles.maDeepDefault = aDeepProperty;
xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("NumberOfLines"))) >>= mnNumOfLinesProp;
xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Volume"))) >>= mbStockHasVolume;
}
catch( const uno::Exception & rEx )
{
#ifdef DBG_UTIL
rtl::OString aBStr(rtl::OUStringToOString(rEx.Message, RTL_TEXTENCODING_ASCII_US));
OSL_TRACE("PlotAreaContext:EndElement(): Exception caught: %s", aBStr.getStr());
#else
(void)rEx; // avoid warning for pro build
#endif
}
//
bool bCreateInternalDataProvider = false;
if( m_rXLinkHRefAttributeToIndicateDataProvider.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "." ) ) ) //data comes from the chart itself
bCreateInternalDataProvider = true;
else if( m_rXLinkHRefAttributeToIndicateDataProvider.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ".." ) ) ) //data comes from the parent application
bCreateInternalDataProvider = false;
else if( m_rXLinkHRefAttributeToIndicateDataProvider.getLength() ) //not supported so far to get the data by sibling objects -> fall back to chart itself
bCreateInternalDataProvider = true;
else if( !m_rbHasRangeAtPlotArea )
bCreateInternalDataProvider = true;
if( bCreateInternalDataProvider && mxNewDoc.is() )
{
// we have no complete range => we have own data, so switch the data
// provider to internal. Clone is not necessary, as we don't have any
// data yet.
mxNewDoc->createInternalDataProvider( false /* bCloneExistingData */ );
if( xProp.is() && mrDataRowSource!=chart::ChartDataRowSource_COLUMNS )
xProp->setPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "DataRowSource" )), uno::makeAny(mrDataRowSource) );
}
}
SvXMLImportContext* SchXMLPlotAreaContext::CreateChildContext(
sal_uInt16 nPrefix,
const rtl::OUString& rLocalName,
const uno::Reference< xml::sax::XAttributeList >& xAttrList )
{
SvXMLImportContext* pContext = 0;
const SvXMLTokenMap& rTokenMap = mrImportHelper.GetPlotAreaElemTokenMap();
switch( rTokenMap.Get( nPrefix, rLocalName ))
{
case XML_TOK_PA_COORDINATE_REGION_EXT:
case XML_TOK_PA_COORDINATE_REGION:
{
pContext = new SchXMLCoordinateRegionContext( GetImport(), nPrefix, rLocalName, m_aInnerPositioning );
}
break;
case XML_TOK_PA_AXIS:
{
bool bAddMissingXAxisForNetCharts = false;
bool bAdaptWrongPercentScaleValues = false;
if( SchXMLTools::isDocumentGeneratedWithOpenOfficeOlderThan2_3( GetImport().GetModel() ) )
{
//correct errors from older versions
// for NetCharts there were no xAxis exported to older files
// so we need to add the x axis here for those old NetChart files
if( maChartTypeServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.NetChartType" )) )
bAddMissingXAxisForNetCharts = true;
//Issue 59288
if( mbPercentStacked )
bAdaptWrongPercentScaleValues = true;
}
bool bAdaptXAxisOrientationForOld2DBarCharts = false;
if( SchXMLTools::isDocumentGeneratedWithOpenOfficeOlderThan2_4( GetImport().GetModel() ) )
{
//issue74660
if( maChartTypeServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.ColumnChartType" )) )
bAdaptXAxisOrientationForOld2DBarCharts = true;
}
pContext = new SchXMLAxisContext( mrImportHelper, GetImport(), rLocalName, mxDiagram, maAxes, mrCategoriesAddress,
bAddMissingXAxisForNetCharts, bAdaptWrongPercentScaleValues, bAdaptXAxisOrientationForOld2DBarCharts, m_bAxisPositionAttributeImported );
}
break;
case XML_TOK_PA_SERIES:
{
if( mxNewDoc.is())
{
pContext = new SchXMLSeries2Context(
mrImportHelper, GetImport(), rLocalName,
mxNewDoc, maAxes,
mrSeriesDefaultsAndStyles.maSeriesStyleList,
mnSeries,
mbStockHasVolume,
m_aGlobalSeriesImportInfo,
maChartTypeServiceName,
mrLSequencesPerIndex,
mbGlobalChartTypeUsedBySeries, maChartSize );
}
mnSeries++;
}
break;
case XML_TOK_PA_WALL:
pContext = new SchXMLWallFloorContext( mrImportHelper, GetImport(), nPrefix, rLocalName, mxDiagram,
SchXMLWallFloorContext::CONTEXT_TYPE_WALL );
break;
case XML_TOK_PA_FLOOR:
pContext = new SchXMLWallFloorContext( mrImportHelper, GetImport(), nPrefix, rLocalName, mxDiagram,
SchXMLWallFloorContext::CONTEXT_TYPE_FLOOR );
break;
case XML_TOK_PA_LIGHT_SOURCE:
pContext = maSceneImportHelper.create3DLightContext( nPrefix, rLocalName, xAttrList );
break;
// elements for stock charts
case XML_TOK_PA_STOCK_GAIN:
pContext = new SchXMLStockContext( mrImportHelper, GetImport(), nPrefix, rLocalName, mxDiagram,
SchXMLStockContext::CONTEXT_TYPE_GAIN );
break;
case XML_TOK_PA_STOCK_LOSS:
pContext = new SchXMLStockContext( mrImportHelper, GetImport(), nPrefix, rLocalName, mxDiagram,
SchXMLStockContext::CONTEXT_TYPE_LOSS );
break;
case XML_TOK_PA_STOCK_RANGE:
pContext = new SchXMLStockContext( mrImportHelper, GetImport(), nPrefix, rLocalName, mxDiagram,
SchXMLStockContext::CONTEXT_TYPE_RANGE );
break;
default:
pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
}
return pContext;
}
void SchXMLPlotAreaContext::EndElement()
{
// set categories
if( mrCategoriesAddress.getLength() && mxNewDoc.is())
{
uno::Reference< chart2::data::XDataProvider > xDataProvider(
mxNewDoc->getDataProvider() );
// @todo: correct coordinate system index
sal_Int32 nDimension( 0 );
::std::vector< SchXMLAxis >::const_iterator aIt(
::std::find_if( maAxes.begin(), maAxes.end(), lcl_AxisHasCategories()));
if( aIt != maAxes.end())
nDimension = static_cast< sal_Int32 >( (*aIt).eDimension );
SchXMLTools::CreateCategories(
xDataProvider, mxNewDoc, mrCategoriesAddress,
0 /* nCooSysIndex */,
nDimension, &mrLSequencesPerIndex );
}
uno::Reference< beans::XPropertySet > xDiaProp( mxDiagram, uno::UNO_QUERY );
if( xDiaProp.is())
{
sal_Bool bIsThreeDim = sal_False;
uno::Any aAny = xDiaProp->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Dim3D" )));
aAny >>= bIsThreeDim;
// set 3d scene attributes
if( bIsThreeDim )
{
// set scene attributes at diagram
maSceneImportHelper.setSceneAttributes( xDiaProp );
}
// set correct number of lines at series
if( ! m_aGlobalSeriesImportInfo.rbAllRangeAddressesAvailable &&
mnNumOfLinesProp > 0 &&
maChartTypeServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.ColumnChartType" )))
{
try
{
xDiaProp->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "NumberOfLines" )),
uno::makeAny( mnNumOfLinesProp ));
}
catch( const uno::Exception & rEx )
{
#ifdef DBG_UTIL
rtl::OString aBStr(rtl::OUStringToOString(rEx.Message, RTL_TEXTENCODING_ASCII_US));
OSL_TRACE( "Exception caught for property NumberOfLines: %s", aBStr.getStr());
#else
(void)rEx; // avoid warning for pro build
#endif
}
}
// #i32366# stock has volume
if( ( 0 == mxDiagram->getDiagramType().reverseCompareToAsciiL(
RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart.StockDiagram" ))) &&
mbStockHasVolume )
{
try
{
xDiaProp->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Volume" )),
uno::makeAny( true ));
}
catch( const uno::Exception & rEx )
{
#ifdef DBG_UTIL
rtl::OString aBStr(rtl::OUStringToOString(rEx.Message, RTL_TEXTENCODING_ASCII_US));
OSL_TRACE("Exception caught for property Volume: %s", aBStr.getStr());
#else
(void)rEx; // avoid warning for pro build
#endif
}
}
}
// set changed size and position after properties (esp. 3d)
uno::Reference< chart::XDiagramPositioning > xDiaPos( mxDiagram, uno::UNO_QUERY );
if( xDiaPos.is())
{
if( !m_aOuterPositioning.isAutomatic() )
{
if( m_aInnerPositioning.hasPosSize() )
xDiaPos->setDiagramPositionExcludingAxes( m_aInnerPositioning.getRectangle() );
else if( m_aOuterPositioning.hasPosSize() )
{
if( SchXMLTools::isDocumentGeneratedWithOpenOfficeOlderThan3_3( GetImport().GetModel() ) ) //old version of OOo did write a wrong rectangle for the diagram size
xDiaPos->setDiagramPositionIncludingAxesAndAxisTitles( m_aOuterPositioning.getRectangle() );
else
xDiaPos->setDiagramPositionIncludingAxes( m_aOuterPositioning.getRectangle() );
}
}
}
SchXMLAxisContext::CorrectAxisPositions( uno::Reference< chart2::XChartDocument >( mrImportHelper.GetChartDocument(), uno::UNO_QUERY ), maChartTypeServiceName, GetImport().GetODFVersion(), m_bAxisPositionAttributeImported );
}
// ========================================
SchXMLDataPointContext::SchXMLDataPointContext( SchXMLImportHelper& rImpHelper,
SvXMLImport& rImport, const rtl::OUString& rLocalName,
::std::list< DataRowPointStyle >& rStyleList,
const ::com::sun::star::uno::Reference<
::com::sun::star::chart2::XDataSeries >& xSeries,
sal_Int32& rIndex,
bool bSymbolSizeForSeriesIsMissingInFile ) :
SvXMLImportContext( rImport, XML_NAMESPACE_CHART, rLocalName ),
mrImportHelper( rImpHelper ),
mrStyleList( rStyleList ),
m_xSeries( xSeries ),
mrIndex( rIndex ),
mbSymbolSizeForSeriesIsMissingInFile( bSymbolSizeForSeriesIsMissingInFile )
{
}
SchXMLDataPointContext::~SchXMLDataPointContext()
{
}
void SchXMLDataPointContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
{
sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
::rtl::OUString aValue;
::rtl::OUString sAutoStyleName;
sal_Int32 nRepeat = 1;
for( sal_Int16 i = 0; i < nAttrCount; i++ )
{
rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
rtl::OUString aLocalName;
sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
if( nPrefix == XML_NAMESPACE_CHART )
{
if( IsXMLToken( aLocalName, XML_STYLE_NAME ) )
sAutoStyleName = xAttrList->getValueByIndex( i );
else if( IsXMLToken( aLocalName, XML_REPEATED ) )
nRepeat = xAttrList->getValueByIndex( i ).toInt32();
}
}
if( sAutoStyleName.getLength())
{
DataRowPointStyle aStyle(
DataRowPointStyle::DATA_POINT,
m_xSeries, mrIndex, nRepeat, sAutoStyleName );
aStyle.mbSymbolSizeForSeriesIsMissingInFile = mbSymbolSizeForSeriesIsMissingInFile;
mrStyleList.push_back( aStyle );
}
mrIndex += nRepeat;
}
// ========================================
SchXMLPositonAttributesHelper::SchXMLPositonAttributesHelper( SvXMLImport& rImporter )
: m_rImport( rImporter )
, m_aPosition(0,0)
, m_aSize(0,0)
, m_bHasSizeWidth( false )
, m_bHasSizeHeight( false )
, m_bHasPositionX( false )
, m_bHasPositionY( false )
, m_bAutoSize( false )
, m_bAutoPosition( false )
{
}
SchXMLPositonAttributesHelper::~SchXMLPositonAttributesHelper()
{
}
bool SchXMLPositonAttributesHelper::hasSize() const
{
return m_bHasSizeWidth && m_bHasSizeHeight;
}
bool SchXMLPositonAttributesHelper::hasPosition() const
{
return m_bHasPositionX && m_bHasPositionY;
}
bool SchXMLPositonAttributesHelper::hasPosSize() const
{
return hasPosition() && hasSize();
}
bool SchXMLPositonAttributesHelper::isAutomatic() const
{
return m_bAutoSize || m_bAutoPosition;
}
awt::Point SchXMLPositonAttributesHelper::getPosition() const
{
return m_aPosition;
}
awt::Size SchXMLPositonAttributesHelper::getSize() const
{
return m_aSize;
}
awt::Rectangle SchXMLPositonAttributesHelper::getRectangle() const
{
return awt::Rectangle( m_aPosition.X, m_aPosition.Y, m_aSize.Width, m_aSize.Height );
}
bool SchXMLPositonAttributesHelper::readPositioningAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue )
{
//returns true if the attribute was proccessed
bool bReturn = true;
if( XML_NAMESPACE_SVG == nPrefix )
{
if( IsXMLToken( rLocalName, XML_X ) )
{
m_rImport.GetMM100UnitConverter().convertMeasureToCore(
m_aPosition.X, rValue );
m_bHasPositionX = true;
}
else if( IsXMLToken( rLocalName, XML_Y ) )
{
m_rImport.GetMM100UnitConverter().convertMeasureToCore(
m_aPosition.Y, rValue );
m_bHasPositionY = true;
}
else if( IsXMLToken( rLocalName, XML_WIDTH ) )
{
m_rImport.GetMM100UnitConverter().convertMeasureToCore(
m_aSize.Width, rValue );
m_bHasSizeWidth = true;
}
else if( IsXMLToken( rLocalName, XML_HEIGHT ) )
{
m_rImport.GetMM100UnitConverter().convertMeasureToCore(
m_aSize.Height, rValue );
m_bHasSizeHeight = true;
}
else
bReturn = false;
}
else
bReturn = false;
return bReturn;
}
void SchXMLPositonAttributesHelper::readAutomaticPositioningProperties( XMLPropStyleContext* pPropStyleContext, const SvXMLStylesContext* pStylesCtxt )
{
if( pPropStyleContext && pStylesCtxt )
{
//handle automatic position and size
SchXMLTools::getPropertyFromContext(
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AutomaticSize")), pPropStyleContext, pStylesCtxt ) >>= m_bAutoSize;
SchXMLTools::getPropertyFromContext(
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AutomaticPosition")), pPropStyleContext, pStylesCtxt ) >>= m_bAutoPosition;
}
}
// ========================================
SchXMLCoordinateRegionContext::SchXMLCoordinateRegionContext(
SvXMLImport& rImport
, sal_uInt16 nPrefix
, const rtl::OUString& rLocalName
, SchXMLPositonAttributesHelper& rPositioning )
: SvXMLImportContext( rImport, nPrefix, rLocalName )
, m_rPositioning( rPositioning )
{
}
SchXMLCoordinateRegionContext::~SchXMLCoordinateRegionContext()
{
}
void SchXMLCoordinateRegionContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
{
// parse attributes
sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
for( sal_Int16 i = 0; i < nAttrCount; i++ )
{
rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
rtl::OUString aLocalName;
rtl::OUString aValue = xAttrList->getValueByIndex( i );
sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
m_rPositioning.readPositioningAttribute( nPrefix, aLocalName, aValue );
}
}
// ========================================
SchXMLWallFloorContext::SchXMLWallFloorContext(
SchXMLImportHelper& rImpHelper,
SvXMLImport& rImport,
sal_uInt16 nPrefix,
const rtl::OUString& rLocalName,
uno::Reference< chart::XDiagram >& xDiagram,
ContextType eContextType ) :
SvXMLImportContext( rImport, nPrefix, rLocalName ),
mrImportHelper( rImpHelper ),
mxWallFloorSupplier( xDiagram, uno::UNO_QUERY ),
meContextType( eContextType )
{
}
SchXMLWallFloorContext::~SchXMLWallFloorContext()
{
}
void SchXMLWallFloorContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
{
if( mxWallFloorSupplier.is())
{
sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
rtl::OUString sAutoStyleName;
for( sal_Int16 i = 0; i < nAttrCount; i++ )
{
rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
rtl::OUString aLocalName;
sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
if( nPrefix == XML_NAMESPACE_CHART &&
IsXMLToken( aLocalName, XML_STYLE_NAME ) )
{
sAutoStyleName = xAttrList->getValueByIndex( i );
}
}
// set properties
uno::Reference< beans::XPropertySet > xProp( ( meContextType == CONTEXT_TYPE_WALL )
? mxWallFloorSupplier->getWall()
: mxWallFloorSupplier->getFloor(),
uno::UNO_QUERY );
if( xProp.is())
{
if( sAutoStyleName.getLength())
{
const SvXMLStylesContext* pStylesCtxt = mrImportHelper.GetAutoStylesContext();
if( pStylesCtxt )
{
const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext(
mrImportHelper.GetChartFamilyID(), sAutoStyleName );
if( pStyle && pStyle->ISA( XMLPropStyleContext ))
(( XMLPropStyleContext* )pStyle )->FillPropertySet( xProp );
}
}
}
}
}
// ========================================
SchXMLStockContext::SchXMLStockContext(
SchXMLImportHelper& rImpHelper,
SvXMLImport& rImport,
sal_uInt16 nPrefix,
const rtl::OUString& rLocalName,
uno::Reference< chart::XDiagram >& xDiagram,
ContextType eContextType ) :
SvXMLImportContext( rImport, nPrefix, rLocalName ),
mrImportHelper( rImpHelper ),
mxStockPropProvider( xDiagram, uno::UNO_QUERY ),
meContextType( eContextType )
{
}
SchXMLStockContext::~SchXMLStockContext()
{
}
void SchXMLStockContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
{
if( mxStockPropProvider.is())
{
sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
rtl::OUString sAutoStyleName;
for( sal_Int16 i = 0; i < nAttrCount; i++ )
{
rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
rtl::OUString aLocalName;
sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
if( nPrefix == XML_NAMESPACE_CHART &&
IsXMLToken( aLocalName, XML_STYLE_NAME ) )
{
sAutoStyleName = xAttrList->getValueByIndex( i );
}
}
if( sAutoStyleName.getLength())
{
// set properties
uno::Reference< beans::XPropertySet > xProp;
switch( meContextType )
{
case CONTEXT_TYPE_GAIN:
xProp = mxStockPropProvider->getUpBar();
break;
case CONTEXT_TYPE_LOSS:
xProp = mxStockPropProvider->getDownBar();
break;
case CONTEXT_TYPE_RANGE:
xProp = mxStockPropProvider->getMinMaxLine();
break;
}
if( xProp.is())
{
const SvXMLStylesContext* pStylesCtxt = mrImportHelper.GetAutoStylesContext();
if( pStylesCtxt )
{
const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext(
mrImportHelper.GetChartFamilyID(), sAutoStyleName );
if( pStyle && pStyle->ISA( XMLPropStyleContext ))
(( XMLPropStyleContext* )pStyle )->FillPropertySet( xProp );
}
}
}
}
}
// ========================================
SchXMLStatisticsObjectContext::SchXMLStatisticsObjectContext(
SchXMLImportHelper& rImpHelper,
SvXMLImport& rImport,
sal_uInt16 nPrefix,
const rtl::OUString& rLocalName,
::std::list< DataRowPointStyle >& rStyleList,
const ::com::sun::star::uno::Reference<
::com::sun::star::chart2::XDataSeries >& xSeries,
ContextType eContextType,
const awt::Size & rChartSize ) :
SvXMLImportContext( rImport, nPrefix, rLocalName ),
mrImportHelper( rImpHelper ),
mrStyleList( rStyleList ),
m_xSeries( xSeries ),
meContextType( eContextType ),
maChartSize( rChartSize )
{}
SchXMLStatisticsObjectContext::~SchXMLStatisticsObjectContext()
{
}
void SchXMLStatisticsObjectContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
{
sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
::rtl::OUString aValue;
::rtl::OUString sAutoStyleName;
for( sal_Int16 i = 0; i < nAttrCount; i++ )
{
rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
rtl::OUString aLocalName;
sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
if( nPrefix == XML_NAMESPACE_CHART )
{
if( IsXMLToken( aLocalName, XML_STYLE_NAME ) )
sAutoStyleName = xAttrList->getValueByIndex( i );
}
}
// note: regression-curves must get a style-object even if there is no
// auto-style set, because they can contain an equation
if( sAutoStyleName.getLength() || meContextType == CONTEXT_TYPE_REGRESSION_CURVE )
{
DataRowPointStyle::StyleType eType = DataRowPointStyle::MEAN_VALUE;
switch( meContextType )
{
case CONTEXT_TYPE_MEAN_VALUE_LINE:
eType = DataRowPointStyle::MEAN_VALUE;
break;
case CONTEXT_TYPE_REGRESSION_CURVE:
eType = DataRowPointStyle::REGRESSION;
break;
case CONTEXT_TYPE_ERROR_INDICATOR:
eType = DataRowPointStyle::ERROR_INDICATOR;
break;
}
DataRowPointStyle aStyle(
eType, m_xSeries, -1, 1, sAutoStyleName );
mrStyleList.push_back( aStyle );
}
}
SvXMLImportContext* SchXMLStatisticsObjectContext::CreateChildContext(
sal_uInt16 nPrefix,
const rtl::OUString& rLocalName,
const uno::Reference< xml::sax::XAttributeList >& xAttrList )
{
SvXMLImportContext* pContext = 0;
if( nPrefix == XML_NAMESPACE_CHART &&
IsXMLToken( rLocalName, XML_EQUATION ) )
{
pContext = new SchXMLEquationContext(
mrImportHelper, GetImport(), nPrefix, rLocalName, m_xSeries, maChartSize, mrStyleList.back());
}
else
{
pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
}
return pContext;
}
// ========================================
SchXMLEquationContext::SchXMLEquationContext(
SchXMLImportHelper& rImpHelper,
SvXMLImport& rImport,
sal_uInt16 nPrefix,
const rtl::OUString& rLocalName,
const ::com::sun::star::uno::Reference<
::com::sun::star::chart2::XDataSeries >& xSeries,
const awt::Size & rChartSize,
DataRowPointStyle & rRegressionStyle ) :
SvXMLImportContext( rImport, nPrefix, rLocalName ),
mrImportHelper( rImpHelper ),
mrRegressionStyle( rRegressionStyle ),
m_xSeries( xSeries ),
maChartSize( rChartSize )
{}
SchXMLEquationContext::~SchXMLEquationContext()
{}
void SchXMLEquationContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
{
// parse attributes
sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
SchXMLImport& rImport = ( SchXMLImport& )GetImport();
const SvXMLTokenMap& rAttrTokenMap = mrImportHelper.GetRegEquationAttrTokenMap();
OUString sAutoStyleName;
bool bShowEquation = true;
bool bShowRSquare = false;
awt::Point aPosition;
bool bHasXPos = false;
bool bHasYPos = false;
for( sal_Int16 i = 0; i < nAttrCount; i++ )
{
rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
rtl::OUString aLocalName;
rtl::OUString aValue = xAttrList->getValueByIndex( i );
sal_uInt16 nPrefix = rImport.GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
switch( rAttrTokenMap.Get( nPrefix, aLocalName ))
{
case XML_TOK_REGEQ_POS_X:
rImport.GetMM100UnitConverter().convertMeasureToCore(
aPosition.X, aValue );
bHasXPos = true;
break;
case XML_TOK_REGEQ_POS_Y:
rImport.GetMM100UnitConverter().convertMeasureToCore(
aPosition.Y, aValue );
bHasYPos = true;
break;
case XML_TOK_REGEQ_DISPLAY_EQUATION:
::sax::Converter::convertBool(bShowEquation, aValue);
break;
case XML_TOK_REGEQ_DISPLAY_R_SQUARE:
::sax::Converter::convertBool(bShowRSquare, aValue);
break;
case XML_TOK_REGEQ_STYLE_NAME:
sAutoStyleName = aValue;
break;
}
}
if( sAutoStyleName.getLength() || bShowEquation || bShowRSquare )
{
uno::Reference< beans::XPropertySet > xEqProp;
uno::Reference< lang::XMultiServiceFactory > xFact( comphelper::getProcessServiceFactory(), uno::UNO_QUERY );
if( xFact.is())
xEqProp.set( xFact->createInstance(
::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.RegressionEquation" ))), uno::UNO_QUERY );
if( xEqProp.is())
{
if( sAutoStyleName.getLength() )
{
const SvXMLStylesContext* pStylesCtxt = mrImportHelper.GetAutoStylesContext();
if( pStylesCtxt )
{
const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext(
mrImportHelper.GetChartFamilyID(), sAutoStyleName );
// note: SvXMLStyleContext::FillPropertySet is not const
XMLPropStyleContext * pPropStyleContext =
const_cast< XMLPropStyleContext * >( dynamic_cast< const XMLPropStyleContext * >( pStyle ));
if( pPropStyleContext )
pPropStyleContext->FillPropertySet( xEqProp );
}
}
xEqProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("ShowEquation")), uno::makeAny( bShowEquation ));
xEqProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("ShowCorrelationCoefficient")), uno::makeAny( bShowRSquare ));
if( bHasXPos && bHasYPos )
{
chart2::RelativePosition aRelPos;
aRelPos.Primary = static_cast< double >( aPosition.X ) / static_cast< double >( maChartSize.Width );
aRelPos.Secondary = static_cast< double >( aPosition.Y ) / static_cast< double >( maChartSize.Height );
xEqProp->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "RelativePosition" )),
uno::makeAny( aRelPos ));
}
OSL_ASSERT( mrRegressionStyle.meType == DataRowPointStyle::REGRESSION );
mrRegressionStyle.m_xEquationProperties.set( xEqProp );
}
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|