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
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <com/sun/star/style/TabStop.hpp>
#include <com/sun/star/style/LineSpacing.hpp>
#include <com/sun/star/style/LineSpacingMode.hpp>
#include <com/sun/star/uno/Sequence.hxx>
#include <libxml/xmlwriter.h>
#include <comphelper/extract.hxx>
#include <osl/diagnose.h>
#include <unotools/localedatawrapper.hxx>
#include <unotools/syslocale.hxx>
#include <tools/mapunit.hxx>
#include <svl/itempool.hxx>
#include <svl/memberid.h>
#include <editeng/editrids.hrc>
#include <editeng/lspcitem.hxx>
#include <editeng/adjustitem.hxx>
#include <editeng/orphitem.hxx>
#include <editeng/widwitem.hxx>
#include <editeng/tstpitem.hxx>
#include <editeng/pmdlitem.hxx>
#include <editeng/spltitem.hxx>
#include <editeng/hyphenzoneitem.hxx>
#include <editeng/scriptspaceitem.hxx>
#include <editeng/hngpnctitem.hxx>
#include <editeng/forbiddenruleitem.hxx>
#include <editeng/paravertalignitem.hxx>
#include <editeng/pgrditem.hxx>
#include <rtl/ustring.hxx>
#include <sal/log.hxx>
#include <editeng/memberids.h>
#include <editeng/itemtype.hxx>
#include <editeng/eerdll.hxx>
using namespace ::com::sun::star;
SfxPoolItem* SvxLineSpacingItem::CreateDefault() { return new SvxLineSpacingItem(LINE_SPACE_DEFAULT_HEIGHT, 0);}
SfxPoolItem* SvxAdjustItem::CreateDefault() { return new SvxAdjustItem(SvxAdjust::Left, 0);}
SfxPoolItem* SvxWidowsItem::CreateDefault() { return new SvxWidowsItem(0, 0);}
SfxPoolItem* SvxOrphansItem::CreateDefault() { return new SvxOrphansItem(0, 0);}
SfxPoolItem* SvxHyphenZoneItem::CreateDefault() { return new SvxHyphenZoneItem(false, 0);}
SfxPoolItem* SvxTabStopItem::CreateDefault() { return new SvxTabStopItem(0);}
SfxPoolItem* SvxFormatSplitItem::CreateDefault() { return new SvxFormatSplitItem(false, 0);}
SfxPoolItem* SvxPageModelItem::CreateDefault() { return new SvxPageModelItem(0);}
SfxPoolItem* SvxParaVertAlignItem::CreateDefault() { return new SvxParaVertAlignItem(Align::Automatic, 0);}
namespace {
enum class SvxSpecialLineSpace
{
User,
OneLine,
OnePointFiveLines,
TwoLines,
End
};
}
SvxLineSpacingItem::SvxLineSpacingItem( sal_uInt16 nHeight, const sal_uInt16 nId )
: SfxEnumItemInterface( nId )
{
nPropLineSpace = 100;
nInterLineSpace = 0;
nLineHeight = nHeight;
eLineSpaceRule = SvxLineSpaceRule::Auto;
eInterLineSpaceRule = SvxInterLineSpaceRule::Off;
}
bool SvxLineSpacingItem::operator==( const SfxPoolItem& rAttr ) const
{
assert(SfxPoolItem::operator==(rAttr));
const SvxLineSpacingItem& rLineSpace = static_cast<const SvxLineSpacingItem&>(rAttr);
return
// Same Linespacing Rule?
(eLineSpaceRule == rLineSpace.eLineSpaceRule)
// For maximum and minimum Linespacing be the size must coincide.
&& (eLineSpaceRule == SvxLineSpaceRule::Auto ||
nLineHeight == rLineSpace.nLineHeight)
// Same Linespacing Rule?
&& ( eInterLineSpaceRule == rLineSpace.eInterLineSpaceRule )
// Either set proportional or additive.
&& (( eInterLineSpaceRule == SvxInterLineSpaceRule::Off)
|| (eInterLineSpaceRule == SvxInterLineSpaceRule::Prop
&& nPropLineSpace == rLineSpace.nPropLineSpace)
|| (eInterLineSpaceRule == SvxInterLineSpaceRule::Fix
&& (nInterLineSpace == rLineSpace.nInterLineSpace)));
}
/* Who does still know why the LineSpacingItem is so complicated?
We can not use it for UNO since there are only two values:
- a sal_uInt16 for the mode
- a sal_uInt32 for all values (distance, height, rel. detail)
*/
bool SvxLineSpacingItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
{
bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
nMemberId &= ~CONVERT_TWIPS;
style::LineSpacing aLSp;
switch( eLineSpaceRule )
{
case SvxLineSpaceRule::Auto:
if(eInterLineSpaceRule == SvxInterLineSpaceRule::Fix)
{
aLSp.Mode = style::LineSpacingMode::LEADING;
aLSp.Height = ( bConvert ? static_cast<short>(convertTwipToMm100(nInterLineSpace)) : nInterLineSpace);
}
else if(eInterLineSpaceRule == SvxInterLineSpaceRule::Off)
{
aLSp.Mode = style::LineSpacingMode::PROP;
aLSp.Height = 100;
}
else
{
aLSp.Mode = style::LineSpacingMode::PROP;
aLSp.Height = nPropLineSpace;
}
break;
case SvxLineSpaceRule::Fix :
case SvxLineSpaceRule::Min :
aLSp.Mode = eLineSpaceRule == SvxLineSpaceRule::Fix ? style::LineSpacingMode::FIX : style::LineSpacingMode::MINIMUM;
aLSp.Height = ( bConvert ? static_cast<short>(convertTwipToMm100(nLineHeight)) : nLineHeight );
break;
default:
;//prevent warning about SvxLineSpaceRule::End
}
switch ( nMemberId )
{
case 0 : rVal <<= aLSp; break;
case MID_LINESPACE : rVal <<= aLSp.Mode; break;
case MID_HEIGHT : rVal <<= aLSp.Height; break;
default: OSL_FAIL("Wrong MemberId!"); break;
}
return true;
}
bool SvxLineSpacingItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
{
bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
nMemberId &= ~CONVERT_TWIPS;
// fill with current data
style::LineSpacing aLSp;
uno::Any aAny;
bool bRet = QueryValue( aAny, bConvert ? CONVERT_TWIPS : 0 ) && ( aAny >>= aLSp );
// get new data
switch ( nMemberId )
{
case 0 : bRet = (rVal >>= aLSp); break;
case MID_LINESPACE : bRet = (rVal >>= aLSp.Mode); break;
case MID_HEIGHT : bRet = (rVal >>= aLSp.Height); break;
default: OSL_FAIL("Wrong MemberId!"); break;
}
if( bRet )
{
nLineHeight = aLSp.Height;
switch( aLSp.Mode )
{
case style::LineSpacingMode::LEADING:
{
eInterLineSpaceRule = SvxInterLineSpaceRule::Fix;
eLineSpaceRule = SvxLineSpaceRule::Auto;
nInterLineSpace = aLSp.Height;
if(bConvert)
nInterLineSpace = static_cast<short>(convertMm100ToTwip(nInterLineSpace));
}
break;
case style::LineSpacingMode::PROP:
{
eLineSpaceRule = SvxLineSpaceRule::Auto;
nPropLineSpace = aLSp.Height;
if(100 == aLSp.Height)
eInterLineSpaceRule = SvxInterLineSpaceRule::Off;
else
eInterLineSpaceRule = SvxInterLineSpaceRule::Prop;
}
break;
case style::LineSpacingMode::FIX:
case style::LineSpacingMode::MINIMUM:
{
eInterLineSpaceRule = SvxInterLineSpaceRule::Off;
eLineSpaceRule = aLSp.Mode == style::LineSpacingMode::FIX ? SvxLineSpaceRule::Fix : SvxLineSpaceRule::Min;
nLineHeight = aLSp.Height;
if(bConvert)
nLineHeight = static_cast<sal_uInt16>(convertMm100ToTwip(nLineHeight));
}
break;
}
}
return bRet;
}
SvxLineSpacingItem* SvxLineSpacingItem::Clone( SfxItemPool * ) const
{
return new SvxLineSpacingItem( *this );
}
bool SvxLineSpacingItem::GetPresentation
(
SfxItemPresentation ePres,
MapUnit eCoreUnit,
MapUnit ePresUnit,
OUString& rText, const IntlWrapper& rIntl
) const
{
switch ( ePres )
{
case SfxItemPresentation::Nameless:
case SfxItemPresentation::Complete:
{
switch( GetLineSpaceRule() )
{
case SvxLineSpaceRule::Auto:
{
SvxInterLineSpaceRule eInter = GetInterLineSpaceRule();
switch( eInter )
{
// Default single line spacing
case SvxInterLineSpaceRule::Off:
rText = EditResId(RID_SVXITEMS_LINESPACING_SINGLE);
break;
// Default single line spacing
case SvxInterLineSpaceRule::Prop:
if ( 100 == GetPropLineSpace() )
{
rText = EditResId(RID_SVXITEMS_LINESPACING_SINGLE);
break;
}
// 1.15 line spacing
if ( 115 == GetPropLineSpace() )
{
rText = EditResId(RID_SVXITEMS_LINESPACING_115);
break;
}
// 1.5 line spacing
if ( 150 == GetPropLineSpace() )
{
rText = EditResId(RID_SVXITEMS_LINESPACING_15);
break;
}
// double line spacing
if ( 200 == GetPropLineSpace() )
{
rText = EditResId(RID_SVXITEMS_LINESPACING_DOUBLE);
break;
}
// the set per cent value
rText = EditResId(RID_SVXITEMS_LINESPACING_PROPORTIONAL) + " " + OUString::number(GetPropLineSpace()) + "%";
break;
case SvxInterLineSpaceRule::Fix:
rText = EditResId(RID_SVXITEMS_LINESPACING_LEADING) +
" " + GetMetricText(GetInterLineSpace(), eCoreUnit, ePresUnit, &rIntl) +
" " + EditResId(GetMetricId(ePresUnit));
break;
default: ;//prevent warning
}
}
break;
case SvxLineSpaceRule::Fix:
rText = EditResId(RID_SVXITEMS_LINESPACING_FIXED) +
" " + GetMetricText(GetLineHeight(), eCoreUnit, ePresUnit, &rIntl) +
" " + EditResId(GetMetricId(ePresUnit));
break;
case SvxLineSpaceRule::Min:
rText = EditResId(RID_SVXITEMS_LINESPACING_MIN) +
" " + GetMetricText(GetLineHeight(), eCoreUnit, ePresUnit, &rIntl) +
" " + EditResId(GetMetricId(ePresUnit));
break;
default: ;//prevent warning
}
}
}
return true;
}
sal_uInt16 SvxLineSpacingItem::GetValueCount() const
{
return sal_uInt16(SvxSpecialLineSpace::End); // SvxSpecialLineSpace::TwoLines + 1
}
sal_uInt16 SvxLineSpacingItem::GetEnumValue() const
{
SvxSpecialLineSpace nVal;
switch ( nPropLineSpace )
{
case 100: nVal = SvxSpecialLineSpace::OneLine; break;
case 150: nVal = SvxSpecialLineSpace::OnePointFiveLines; break;
case 200: nVal = SvxSpecialLineSpace::TwoLines; break;
default: nVal = SvxSpecialLineSpace::User; break;
}
return static_cast<sal_uInt16>(nVal);
}
void SvxLineSpacingItem::SetEnumValue( sal_uInt16 nVal )
{
switch ( static_cast<SvxSpecialLineSpace>(nVal) )
{
case SvxSpecialLineSpace::OneLine: nPropLineSpace = 100; break;
case SvxSpecialLineSpace::OnePointFiveLines: nPropLineSpace = 150; break;
case SvxSpecialLineSpace::TwoLines: nPropLineSpace = 200; break;
default: break;
}
}
// class SvxAdjustItem ---------------------------------------------------
SvxAdjustItem::SvxAdjustItem(const SvxAdjust eAdjst, const sal_uInt16 nId )
: SfxEnumItemInterface( nId ),
bOneBlock( false ), bLastCenter( false ), bLastBlock( false )
{
SetAdjust( eAdjst );
}
bool SvxAdjustItem::operator==( const SfxPoolItem& rAttr ) const
{
assert(SfxPoolItem::operator==(rAttr));
const SvxAdjustItem& rItem = static_cast<const SvxAdjustItem&>(rAttr);
return GetAdjust() == rItem.GetAdjust() &&
bOneBlock == rItem.bOneBlock &&
bLastCenter == rItem.bLastCenter &&
bLastBlock == rItem.bLastBlock;
}
bool SvxAdjustItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
{
nMemberId &= ~CONVERT_TWIPS;
switch( nMemberId )
{
case MID_PARA_ADJUST : rVal <<= static_cast<sal_Int16>(GetAdjust()); break;
case MID_LAST_LINE_ADJUST : rVal <<= static_cast<sal_Int16>(GetLastBlock()); break;
case MID_EXPAND_SINGLE :
{
rVal <<= bOneBlock;
break;
}
default: ;//prevent warning
}
return true;
}
bool SvxAdjustItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
{
nMemberId &= ~CONVERT_TWIPS;
switch( nMemberId )
{
case MID_PARA_ADJUST :
case MID_LAST_LINE_ADJUST :
{
sal_Int32 eVal = - 1;
::cppu::enum2int(eVal,rVal);
if(eVal >= 0 && eVal <= 4)
{
SvxAdjust eAdjust = static_cast<SvxAdjust>(eVal);
if(MID_LAST_LINE_ADJUST == nMemberId &&
eAdjust != SvxAdjust::Left &&
eAdjust != SvxAdjust::Block &&
eAdjust != SvxAdjust::Center)
return false;
nMemberId == MID_PARA_ADJUST ? SetAdjust(eAdjust) : SetLastBlock(eAdjust);
}
}
break;
case MID_EXPAND_SINGLE :
bOneBlock = Any2Bool(rVal);
break;
}
return true;
}
SvxAdjustItem* SvxAdjustItem::Clone( SfxItemPool * ) const
{
return new SvxAdjustItem( *this );
}
bool SvxAdjustItem::GetPresentation
(
SfxItemPresentation ePres,
MapUnit /*eCoreUnit*/,
MapUnit /*ePresUnit*/,
OUString& rText, const IntlWrapper&
) const
{
switch ( ePres )
{
case SfxItemPresentation::Nameless:
case SfxItemPresentation::Complete:
rText = GetValueTextByPos( static_cast<sal_uInt16>(GetAdjust()) );
return true;
default: ;//prevent warning
}
return false;
}
sal_uInt16 SvxAdjustItem::GetValueCount() const
{
return sal_uInt16(SvxAdjust::End); // SvxAdjust::BlockLine + 1
}
OUString SvxAdjustItem::GetValueTextByPos( sal_uInt16 nPos )
{
static const char* RID_SVXITEMS_ADJUST[] =
{
RID_SVXITEMS_ADJUST_LEFT,
RID_SVXITEMS_ADJUST_RIGHT,
RID_SVXITEMS_ADJUST_BLOCK,
RID_SVXITEMS_ADJUST_CENTER,
RID_SVXITEMS_ADJUST_BLOCKLINE
};
static_assert(SAL_N_ELEMENTS(RID_SVXITEMS_ADJUST) - 1 == size_t(SvxAdjust::BlockLine), "unexpected size");
assert(nPos <= sal_uInt16(SvxAdjust::BlockLine) && "enum overflow!");
return EditResId(RID_SVXITEMS_ADJUST[nPos]);
}
sal_uInt16 SvxAdjustItem::GetEnumValue() const
{
return static_cast<sal_uInt16>(GetAdjust());
}
void SvxAdjustItem::SetEnumValue( sal_uInt16 nVal )
{
SetAdjust( static_cast<SvxAdjust>(nVal) );
}
// class SvxWidowsItem ---------------------------------------------------
SvxWidowsItem::SvxWidowsItem(const sal_uInt8 nL, const sal_uInt16 nId ) :
SfxByteItem( nId, nL )
{
}
SvxWidowsItem* SvxWidowsItem::Clone( SfxItemPool * ) const
{
return new SvxWidowsItem( *this );
}
bool SvxWidowsItem::GetPresentation
(
SfxItemPresentation ePres,
MapUnit /*eCoreUnit*/,
MapUnit /*ePresUnit*/,
OUString& rText, const IntlWrapper&
) const
{
switch ( ePres )
{
case SfxItemPresentation::Nameless:
{
rText = EditResId(RID_SVXITEMS_LINES);
break;
}
case SfxItemPresentation::Complete:
{
rText = EditResId(RID_SVXITEMS_WIDOWS_COMPLETE) + " " + EditResId(RID_SVXITEMS_LINES);
break;
}
default:
{
SAL_WARN( "editeng.items", "SvxWidowsItem::GetPresentation(): unknown SfxItemPresentation" );
}
}
rText = rText.replaceFirst( "%1", OUString::number( GetValue() ) );
return true;
}
// class SvxOrphansItem --------------------------------------------------
SvxOrphansItem::SvxOrphansItem(const sal_uInt8 nL, const sal_uInt16 nId ) :
SfxByteItem( nId, nL )
{
}
SvxOrphansItem* SvxOrphansItem::Clone( SfxItemPool * ) const
{
return new SvxOrphansItem( *this );
}
bool SvxOrphansItem::GetPresentation
(
SfxItemPresentation ePres,
MapUnit /*eCoreUnit*/,
MapUnit /*ePresUnit*/,
OUString& rText, const IntlWrapper&
) const
{
switch ( ePres )
{
case SfxItemPresentation::Nameless:
{
rText = EditResId(RID_SVXITEMS_LINES);
break;
}
case SfxItemPresentation::Complete:
{
rText = EditResId(RID_SVXITEMS_ORPHANS_COMPLETE) + " " + EditResId(RID_SVXITEMS_LINES);
break;
}
default:
{
SAL_WARN( "editeng.items", "SvxOrphansItem::GetPresentation(): unknown SfxItemPresentation" );
}
}
rText = rText.replaceFirst( "%1", OUString::number( GetValue() ) );
return true;
}
// class SvxHyphenZoneItem -----------------------------------------------
SvxHyphenZoneItem::SvxHyphenZoneItem( const bool bHyph, const sal_uInt16 nId ) :
SfxPoolItem( nId ),
bHyphen(bHyph),
bPageEnd(true),
bNoCapsHyphenation(false),
nMinLead(0),
nMinTrail(0),
nMaxHyphens(255)
{
}
bool SvxHyphenZoneItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
{
nMemberId &= ~CONVERT_TWIPS;
switch(nMemberId)
{
case MID_IS_HYPHEN:
rVal <<= bHyphen;
break;
case MID_HYPHEN_MIN_LEAD:
rVal <<= static_cast<sal_Int16>(nMinLead);
break;
case MID_HYPHEN_MIN_TRAIL:
rVal <<= static_cast<sal_Int16>(nMinTrail);
break;
case MID_HYPHEN_MAX_HYPHENS:
rVal <<= static_cast<sal_Int16>(nMaxHyphens);
break;
case MID_HYPHEN_NO_CAPS:
rVal <<= bNoCapsHyphenation;
break;
}
return true;
}
bool SvxHyphenZoneItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
{
nMemberId &= ~CONVERT_TWIPS;
sal_Int16 nNewVal = 0;
if( nMemberId != MID_IS_HYPHEN && nMemberId != MID_HYPHEN_NO_CAPS )
if(!(rVal >>= nNewVal))
return false;
switch(nMemberId)
{
case MID_IS_HYPHEN:
bHyphen = Any2Bool(rVal);
break;
case MID_HYPHEN_MIN_LEAD:
nMinLead = static_cast<sal_uInt8>(nNewVal);
break;
case MID_HYPHEN_MIN_TRAIL:
nMinTrail = static_cast<sal_uInt8>(nNewVal);
break;
case MID_HYPHEN_MAX_HYPHENS:
nMaxHyphens = static_cast<sal_uInt8>(nNewVal);
break;
case MID_HYPHEN_NO_CAPS:
bNoCapsHyphenation = Any2Bool(rVal);
break;
}
return true;
}
bool SvxHyphenZoneItem::operator==( const SfxPoolItem& rAttr ) const
{
assert(SfxPoolItem::operator==(rAttr));
const SvxHyphenZoneItem& rItem = static_cast<const SvxHyphenZoneItem&>(rAttr);
return ( rItem.bHyphen == bHyphen
&& rItem.bNoCapsHyphenation == bNoCapsHyphenation
&& rItem.bPageEnd == bPageEnd
&& rItem.nMinLead == nMinLead
&& rItem.nMinTrail == nMinTrail
&& rItem.nMaxHyphens == nMaxHyphens );
}
SvxHyphenZoneItem* SvxHyphenZoneItem::Clone( SfxItemPool * ) const
{
return new SvxHyphenZoneItem( *this );
}
bool SvxHyphenZoneItem::GetPresentation
(
SfxItemPresentation ePres,
MapUnit /*eCoreUnit*/,
MapUnit /*ePresUnit*/,
OUString& rText, const IntlWrapper&
) const
{
OUString cpDelimTmp(cpDelim);
switch ( ePres )
{
case SfxItemPresentation::Nameless:
{
const char* pId = RID_SVXITEMS_HYPHEN_FALSE;
if ( bHyphen )
pId = RID_SVXITEMS_HYPHEN_TRUE;
rText = EditResId(pId) + cpDelimTmp;
pId = RID_SVXITEMS_PAGE_END_FALSE;
if ( bPageEnd )
pId = RID_SVXITEMS_PAGE_END_TRUE;
rText += EditResId(pId) + cpDelimTmp +
OUString::number( nMinLead ) + cpDelimTmp +
OUString::number( nMinTrail ) + cpDelimTmp +
OUString::number( nMaxHyphens );
return true;
}
case SfxItemPresentation::Complete:
{
const char* pId = RID_SVXITEMS_HYPHEN_FALSE;
if ( bHyphen )
pId = RID_SVXITEMS_HYPHEN_TRUE;
rText = EditResId(pId) + cpDelimTmp;
pId = RID_SVXITEMS_PAGE_END_FALSE;
if ( bPageEnd )
pId = RID_SVXITEMS_PAGE_END_TRUE;
rText += EditResId(pId) +
cpDelimTmp +
EditResId(RID_SVXITEMS_HYPHEN_MINLEAD).replaceAll("%1", OUString::number(nMinLead)) +
cpDelimTmp +
EditResId(RID_SVXITEMS_HYPHEN_MINTRAIL).replaceAll("%1", OUString::number(nMinTrail)) +
cpDelimTmp +
EditResId(RID_SVXITEMS_HYPHEN_MAX).replaceAll("%1", OUString::number(nMaxHyphens));
return true;
}
default: ;//prevent warning
}
return false;
}
// class SvxTabStop ------------------------------------------------------
SvxTabStop::SvxTabStop()
{
nTabPos = 0;
eAdjustment = SvxTabAdjust::Left;
m_cDecimal = cDfltDecimalChar;
cFill = cDfltFillChar;
}
SvxTabStop::SvxTabStop( const sal_Int32 nPos, const SvxTabAdjust eAdjst,
const sal_Unicode cDec, const sal_Unicode cFil )
{
nTabPos = nPos;
eAdjustment = eAdjst;
m_cDecimal = cDec;
cFill = cFil;
}
void SvxTabStop::fillDecimal() const
{
if ( cDfltDecimalChar == m_cDecimal )
m_cDecimal = SvtSysLocale().GetLocaleData().getNumDecimalSep()[0];
}
void SvxTabStop::dumpAsXml(xmlTextWriterPtr pWriter) const
{
xmlTextWriterStartElement(pWriter, BAD_CAST("SvxTabStop"));
xmlTextWriterWriteAttribute(pWriter, BAD_CAST("nTabPos"),
BAD_CAST(OString::number(nTabPos).getStr()));
xmlTextWriterWriteAttribute(pWriter, BAD_CAST("eAdjustment"),
BAD_CAST(OString::number(static_cast<int>(eAdjustment)).getStr()));
xmlTextWriterEndElement(pWriter);
}
// class SvxTabStopItem --------------------------------------------------
SvxTabStopItem::SvxTabStopItem( sal_uInt16 _nWhich ) :
SfxPoolItem( _nWhich ),
maTabStops()
{
const sal_uInt16 nTabs = SVX_TAB_DEFCOUNT, nDist = SVX_TAB_DEFDIST;
const SvxTabAdjust eAdjst= SvxTabAdjust::Default;
for (sal_uInt16 i = 0; i < nTabs; ++i)
{
SvxTabStop aTab( (i + 1) * nDist, eAdjst );
maTabStops.insert( aTab );
}
}
SvxTabStopItem::SvxTabStopItem( const sal_uInt16 nTabs,
const sal_uInt16 nDist,
const SvxTabAdjust eAdjst,
sal_uInt16 _nWhich ) :
SfxPoolItem( _nWhich ),
maTabStops()
{
for ( sal_uInt16 i = 0; i < nTabs; ++i )
{
SvxTabStop aTab( (i + 1) * nDist, eAdjst );
maTabStops.insert( aTab );
}
}
sal_uInt16 SvxTabStopItem::GetPos( const SvxTabStop& rTab ) const
{
SvxTabStopArr::const_iterator it = maTabStops.find( rTab );
return it != maTabStops.end() ? it - maTabStops.begin() : SVX_TAB_NOTFOUND;
}
sal_uInt16 SvxTabStopItem::GetPos( const sal_Int32 nPos ) const
{
SvxTabStopArr::const_iterator it = maTabStops.find( SvxTabStop( nPos ) );
return it != maTabStops.end() ? it - maTabStops.begin() : SVX_TAB_NOTFOUND;
}
bool SvxTabStopItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
{
bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
nMemberId &= ~CONVERT_TWIPS;
switch ( nMemberId )
{
case MID_TABSTOPS:
{
sal_uInt16 nCount = Count();
uno::Sequence< style::TabStop> aSeq(nCount);
style::TabStop* pArr = aSeq.getArray();
for(sal_uInt16 i = 0; i < nCount; i++)
{
const SvxTabStop& rTab = (*this)[i];
pArr[i].Position = bConvert ? convertTwipToMm100(rTab.GetTabPos()) : rTab.GetTabPos();
switch(rTab.GetAdjustment())
{
case SvxTabAdjust::Left : pArr[i].Alignment = style::TabAlign_LEFT; break;
case SvxTabAdjust::Right : pArr[i].Alignment = style::TabAlign_RIGHT; break;
case SvxTabAdjust::Decimal: pArr[i].Alignment = style::TabAlign_DECIMAL; break;
case SvxTabAdjust::Center : pArr[i].Alignment = style::TabAlign_CENTER; break;
default: //SvxTabAdjust::Default
pArr[i].Alignment = style::TabAlign_DEFAULT;
}
pArr[i].DecimalChar = rTab.GetDecimal();
pArr[i].FillChar = rTab.GetFill();
}
rVal <<= aSeq;
break;
}
case MID_STD_TAB:
{
const SvxTabStop &rTab = maTabStops.front();
rVal <<= static_cast<sal_Int32>(bConvert ? convertTwipToMm100(rTab.GetTabPos()) : rTab.GetTabPos());
break;
}
}
return true;
}
bool SvxTabStopItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
{
bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
nMemberId &= ~CONVERT_TWIPS;
switch ( nMemberId )
{
case MID_TABSTOPS:
{
uno::Sequence< style::TabStop> aSeq;
if(!(rVal >>= aSeq))
{
uno::Sequence < uno::Sequence < uno::Any > > aAnySeq;
if (!(rVal >>= aAnySeq))
return false;
sal_Int32 nLength = aAnySeq.getLength();
aSeq.realloc( nLength );
for ( sal_Int32 n=0; n<nLength; n++ )
{
uno::Sequence < uno::Any >& rAnySeq = aAnySeq[n];
if ( rAnySeq.getLength() == 4 )
{
if (!(rAnySeq[0] >>= aSeq[n].Position)) return false;
if (!(rAnySeq[1] >>= aSeq[n].Alignment))
{
sal_Int32 nVal = 0;
if (rAnySeq[1] >>= nVal)
aSeq[n].Alignment = static_cast<css::style::TabAlign>(nVal);
else
return false;
}
if (!(rAnySeq[2] >>= aSeq[n].DecimalChar))
{
OUString aVal;
if ( (rAnySeq[2] >>= aVal) && aVal.getLength() == 1 )
aSeq[n].DecimalChar = aVal.toChar();
else
return false;
}
if (!(rAnySeq[3] >>= aSeq[n].FillChar))
{
OUString aVal;
if ( (rAnySeq[3] >>= aVal) && aVal.getLength() == 1 )
aSeq[n].FillChar = aVal.toChar();
else
return false;
}
}
else
return false;
}
}
maTabStops.clear();
const style::TabStop* pArr = aSeq.getConstArray();
const sal_uInt16 nCount = static_cast<sal_uInt16>(aSeq.getLength());
for(sal_uInt16 i = 0; i < nCount ; i++)
{
SvxTabAdjust eAdjust = SvxTabAdjust::Default;
switch(pArr[i].Alignment)
{
case style::TabAlign_LEFT : eAdjust = SvxTabAdjust::Left; break;
case style::TabAlign_CENTER : eAdjust = SvxTabAdjust::Center; break;
case style::TabAlign_RIGHT : eAdjust = SvxTabAdjust::Right; break;
case style::TabAlign_DECIMAL: eAdjust = SvxTabAdjust::Decimal; break;
default: ;//prevent warning
}
sal_Unicode cFill = pArr[i].FillChar;
sal_Unicode cDecimal = pArr[i].DecimalChar;
SvxTabStop aTab( bConvert ? convertMm100ToTwip(pArr[i].Position) : pArr[i].Position,
eAdjust,
cDecimal,
cFill );
Insert(aTab);
}
break;
}
case MID_STD_TAB:
{
sal_Int32 nNewPos = 0;
if (!(rVal >>= nNewPos) )
return false;
if (bConvert)
nNewPos = convertMm100ToTwip ( nNewPos );
if (nNewPos <= 0)
return false;
const SvxTabStop& rTab = maTabStops.front();
SvxTabStop aNewTab ( nNewPos, rTab.GetAdjustment(), rTab.GetDecimal(), rTab.GetFill() );
Remove( 0 );
Insert( aNewTab );
break;
}
}
return true;
}
bool SvxTabStopItem::operator==( const SfxPoolItem& rAttr ) const
{
assert(SfxPoolItem::operator==(rAttr));
const SvxTabStopItem& rTSI = static_cast<const SvxTabStopItem&>(rAttr);
if ( Count() != rTSI.Count() )
return false;
for ( sal_uInt16 i = 0; i < Count(); ++i )
if( (*this)[i] != rTSI[i] )
return false;
return true;
}
SvxTabStopItem* SvxTabStopItem::Clone( SfxItemPool * ) const
{
return new SvxTabStopItem( *this );
}
bool SvxTabStopItem::GetPresentation
(
SfxItemPresentation ePres,
MapUnit eCoreUnit,
MapUnit ePresUnit,
OUString& rText, const IntlWrapper& rIntl
) const
{
rText.clear();
bool bComma = false;
for ( sal_uInt16 i = 0; i < Count(); ++i )
{
if ( SvxTabAdjust::Default != ((*this)[i]).GetAdjustment() )
{
if ( bComma )
rText += ",";
rText += GetMetricText(
((*this)[i]).GetTabPos(), eCoreUnit, ePresUnit, &rIntl );
if ( SfxItemPresentation::Complete == ePres )
{
rText += " " + EditResId(GetMetricId(ePresUnit));
}
bComma = true;
}
}
return true;
}
bool SvxTabStopItem::Insert( const SvxTabStop& rTab )
{
sal_uInt16 nTabPos = GetPos(rTab);
if(SVX_TAB_NOTFOUND != nTabPos )
Remove(nTabPos);
return maTabStops.insert( rTab ).second;
}
void SvxTabStopItem::Insert( const SvxTabStopItem* pTabs )
{
for( sal_uInt16 i = 0; i < pTabs->Count(); i++ )
{
const SvxTabStop& rTab = (*pTabs)[i];
sal_uInt16 nTabPos = GetPos(rTab);
if(SVX_TAB_NOTFOUND != nTabPos)
Remove(nTabPos);
}
for( sal_uInt16 i = 0; i < pTabs->Count(); i++ )
{
maTabStops.insert( (*pTabs)[i] );
}
}
void SvxTabStopItem::dumpAsXml(xmlTextWriterPtr pWriter) const
{
xmlTextWriterStartElement(pWriter, BAD_CAST("SvxTabStopItem"));
for (const auto& rTabStop : maTabStops)
rTabStop.dumpAsXml(pWriter);
xmlTextWriterEndElement(pWriter);
}
// class SvxFormatSplitItem -------------------------------------------------
SvxFormatSplitItem::~SvxFormatSplitItem()
{
}
SvxFormatSplitItem* SvxFormatSplitItem::Clone( SfxItemPool * ) const
{
return new SvxFormatSplitItem( *this );
}
bool SvxFormatSplitItem::GetPresentation
(
SfxItemPresentation /*ePres*/,
MapUnit /*eCoreUnit*/,
MapUnit /*ePresUnit*/,
OUString& rText, const IntlWrapper&
) const
{
const char* pId = RID_SVXITEMS_FMTSPLIT_FALSE;
if ( GetValue() )
pId = RID_SVXITEMS_FMTSPLIT_TRUE;
rText = EditResId(pId);
return true;
}
SvxPageModelItem* SvxPageModelItem::Clone( SfxItemPool* ) const
{
return new SvxPageModelItem( *this );
}
bool SvxPageModelItem::QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId ) const
{
nMemberId &= ~CONVERT_TWIPS;
switch ( nMemberId )
{
case MID_AUTO: rVal <<= bAuto; break;
case MID_NAME: rVal <<= GetValue(); break;
default: OSL_FAIL("Wrong MemberId!"); return false;
}
return true;
}
bool SvxPageModelItem::PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId )
{
nMemberId &= ~CONVERT_TWIPS;
bool bRet;
OUString aStr;
switch ( nMemberId )
{
case MID_AUTO: bRet = ( rVal >>= bAuto ); break;
case MID_NAME: bRet = ( rVal >>= aStr ); if ( bRet ) SetValue(aStr); break;
default: OSL_FAIL("Wrong MemberId!"); return false;
}
return bRet;
}
bool SvxPageModelItem::operator==( const SfxPoolItem& rAttr ) const
{
return SfxStringItem::operator==(rAttr) &&
bAuto == static_cast<const SvxPageModelItem&>( rAttr ).bAuto;
}
bool SvxPageModelItem::GetPresentation
(
SfxItemPresentation ePres,
MapUnit /*eCoreUnit*/,
MapUnit /*ePresUnit*/,
OUString& rText, const IntlWrapper&
) const
{
rText.clear();
bool bSet = !GetValue().isEmpty();
switch ( ePres )
{
case SfxItemPresentation::Nameless:
if ( bSet )
rText = GetValue();
return true;
case SfxItemPresentation::Complete:
if ( bSet )
{
rText = EditResId(RID_SVXITEMS_PAGEMODEL_COMPLETE) + GetValue();
}
return true;
default: ;//prevent warning
}
return false;
}
SvxScriptSpaceItem::SvxScriptSpaceItem( bool bOn, const sal_uInt16 nId )
: SfxBoolItem( nId, bOn )
{
}
SvxScriptSpaceItem* SvxScriptSpaceItem::Clone( SfxItemPool * ) const
{
return new SvxScriptSpaceItem( *this );
}
bool SvxScriptSpaceItem::GetPresentation(
SfxItemPresentation /*ePres*/,
MapUnit /*eCoreMetric*/, MapUnit /*ePresMetric*/,
OUString &rText, const IntlWrapper& /*rIntl*/ ) const
{
rText = EditResId( !GetValue()
? RID_SVXITEMS_SCRPTSPC_OFF
: RID_SVXITEMS_SCRPTSPC_ON );
return true;
}
SvxHangingPunctuationItem::SvxHangingPunctuationItem(
bool bOn, const sal_uInt16 nId )
: SfxBoolItem( nId, bOn )
{
}
SvxHangingPunctuationItem* SvxHangingPunctuationItem::Clone( SfxItemPool * ) const
{
return new SvxHangingPunctuationItem( *this );
}
bool SvxHangingPunctuationItem::GetPresentation(
SfxItemPresentation /*ePres*/,
MapUnit /*eCoreMetric*/, MapUnit /*ePresMetric*/,
OUString &rText, const IntlWrapper& /*rIntl*/ ) const
{
rText = EditResId( !GetValue()
? RID_SVXITEMS_HNGPNCT_OFF
: RID_SVXITEMS_HNGPNCT_ON );
return true;
}
SvxForbiddenRuleItem::SvxForbiddenRuleItem(
bool bOn, const sal_uInt16 nId )
: SfxBoolItem( nId, bOn )
{
}
SvxForbiddenRuleItem* SvxForbiddenRuleItem::Clone( SfxItemPool * ) const
{
return new SvxForbiddenRuleItem( *this );
}
bool SvxForbiddenRuleItem::GetPresentation(
SfxItemPresentation /*ePres*/,
MapUnit /*eCoreMetric*/, MapUnit /*ePresMetric*/,
OUString &rText, const IntlWrapper& /*rIntl*/ ) const
{
rText = EditResId( !GetValue()
? RID_SVXITEMS_FORBIDDEN_RULE_OFF
: RID_SVXITEMS_FORBIDDEN_RULE_ON );
return true;
}
/*************************************************************************
|* class SvxParaVertAlignItem
*************************************************************************/
SvxParaVertAlignItem::SvxParaVertAlignItem( Align nValue,
const sal_uInt16 nW )
: SfxUInt16Item( nW, static_cast<sal_uInt16>(nValue) )
{
}
SvxParaVertAlignItem* SvxParaVertAlignItem::Clone( SfxItemPool* ) const
{
return new SvxParaVertAlignItem( *this );
}
bool SvxParaVertAlignItem::GetPresentation(
SfxItemPresentation /*ePres*/,
MapUnit /*eCoreMetric*/, MapUnit /*ePresMetric*/,
OUString &rText, const IntlWrapper& ) const
{
const char* pTmp;
switch( GetValue() )
{
case Align::Automatic: pTmp = RID_SVXITEMS_PARAVERTALIGN_AUTO; break;
case Align::Top: pTmp = RID_SVXITEMS_PARAVERTALIGN_TOP; break;
case Align::Center: pTmp = RID_SVXITEMS_PARAVERTALIGN_CENTER; break;
case Align::Bottom: pTmp = RID_SVXITEMS_PARAVERTALIGN_BOTTOM; break;
default: pTmp = RID_SVXITEMS_PARAVERTALIGN_BASELINE; break;
}
rText = EditResId(pTmp);
return true;
}
bool SvxParaVertAlignItem::QueryValue( css::uno::Any& rVal,
sal_uInt8 /*nMemberId*/ ) const
{
rVal <<= static_cast<sal_Int16>(GetValue());
return true;
}
bool SvxParaVertAlignItem::PutValue( const css::uno::Any& rVal,
sal_uInt8 /*nMemberId*/ )
{
sal_Int16 nVal = sal_Int16();
if((rVal >>= nVal) && nVal >=0 && nVal <= sal_uInt16(Align::Bottom) )
{
SetValue( static_cast<Align>(nVal) );
return true;
}
else
return false;
}
SvxParaGridItem::SvxParaGridItem( bool bOn, const sal_uInt16 nId )
: SfxBoolItem( nId, bOn )
{
}
SvxParaGridItem* SvxParaGridItem::Clone( SfxItemPool * ) const
{
return new SvxParaGridItem( *this );
}
bool SvxParaGridItem::GetPresentation(
SfxItemPresentation /*ePres*/,
MapUnit /*eCoreMetric*/, MapUnit /*ePresMetric*/,
OUString &rText, const IntlWrapper& /*rIntl*/ ) const
{
rText = GetValue() ?
EditResId( RID_SVXITEMS_PARASNAPTOGRID_ON ) :
EditResId( RID_SVXITEMS_PARASNAPTOGRID_OFF );
return true;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|