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
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
|
/* -*- 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 <memory>
#include <hintids.hxx>
#include <vcl/font.hxx>
#include <editeng/brushitem.hxx>
#include <editeng/numitem.hxx>
#include <svl/grabbagitem.hxx>
#include <fmtornt.hxx>
#include <doc.hxx>
#include <charfmt.hxx>
#include <ndtxt.hxx>
#include <docary.hxx>
#include <SwStyleNameMapper.hxx>
// Needed to load default bullet list configuration
#include <unotools/configmgr.hxx>
#include <unotools/configitem.hxx>
#include <numrule.hxx>
#include <SwNodeNum.hxx>
#include <list.hxx>
#include <algorithm>
#include <unordered_map>
#include <libxml/xmlwriter.h>
#include <rtl/ustrbuf.hxx>
#include <i18nlangtag/languagetag.hxx>
#include <unotools/saveopt.hxx>
#include <osl/diagnose.h>
#include <IDocumentListsAccess.hxx>
#include <IDocumentStylePoolAccess.hxx>
#include <IDocumentState.hxx>
#include <com/sun/star/beans/PropertyValue.hpp>
using namespace ::com::sun::star;
sal_uInt16 SwNumRule::mnRefCount = 0;
SwNumFormat* SwNumRule::maBaseFormats[ RULE_END ][ MAXLEVEL ] = {
{nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr } };
SwNumFormat* SwNumRule::maLabelAlignmentBaseFormats[ RULE_END ][ MAXLEVEL ] = {
{nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr } };
const sal_uInt16 SwNumRule::maDefNumIndents[ MAXLEVEL ] = {
//inch: 0,5 1,0 1,5 2,0 2,5 3,0 3,5 4,0 4,5 5,0
1440/4, 1440/2, 1440*3/4, 1440, 1440*5/4, 1440*3/2, 1440*7/4, 1440*2,
1440*9/4, 1440*5/2
};
OUString SwNumRule::GetOutlineRuleName()
{
return "Outline";
}
const SwNumFormat& SwNumRule::Get( sal_uInt16 i ) const
{
assert( i < MAXLEVEL && meRuleType < RULE_END );
return maFormats[ i ]
? *maFormats[ i ]
: ( meDefaultNumberFormatPositionAndSpaceMode == SvxNumberFormat::LABEL_WIDTH_AND_POSITION
? *maBaseFormats[ meRuleType ][ i ]
: *maLabelAlignmentBaseFormats[ meRuleType ][ i ] );
}
const SwNumFormat* SwNumRule::GetNumFormat( sal_uInt16 i ) const
{
const SwNumFormat * pResult = nullptr;
assert( i < MAXLEVEL && meRuleType < RULE_END );
if ( i < MAXLEVEL && meRuleType < RULE_END)
{
pResult = maFormats[ i ].get();
}
return pResult;
}
// #i91400#
void SwNumRule::SetName( const OUString & rName,
IDocumentListsAccess& rDocListAccess)
{
if ( msName != rName )
{
if (mpNumRuleMap)
{
mpNumRuleMap->erase(msName);
(*mpNumRuleMap)[rName] = this;
if ( !GetDefaultListId().isEmpty() )
{
rDocListAccess.trackChangeOfListStyleName( msName, rName );
}
}
msName = rName;
}
}
void SwNumRule::GetTextNodeList( SwNumRule::tTextNodeList& rTextNodeList ) const
{
rTextNodeList = maTextNodeList;
}
SwNumRule::tTextNodeList::size_type SwNumRule::GetTextNodeListSize() const
{
return maTextNodeList.size();
}
void SwNumRule::AddTextNode( SwTextNode& rTextNode )
{
tTextNodeList::iterator aIter =
std::find( maTextNodeList.begin(), maTextNodeList.end(), &rTextNode );
if ( aIter == maTextNodeList.end() )
{
maTextNodeList.push_back( &rTextNode );
}
}
void SwNumRule::RemoveTextNode( SwTextNode& rTextNode )
{
tTextNodeList::iterator aIter =
std::find( maTextNodeList.begin(), maTextNodeList.end(), &rTextNode );
if ( aIter != maTextNodeList.end() )
{
maTextNodeList.erase( aIter );
}
}
void SwNumRule::SetNumRuleMap(std::unordered_map<OUString, SwNumRule *> *
pNumRuleMap)
{
mpNumRuleMap = pNumRuleMap;
}
sal_uInt16 SwNumRule::GetNumIndent( sal_uInt8 nLvl )
{
OSL_ENSURE( MAXLEVEL > nLvl, "NumLevel is out of range" );
return maDefNumIndents[ nLvl ];
}
sal_uInt16 SwNumRule::GetBullIndent( sal_uInt8 nLvl )
{
OSL_ENSURE( MAXLEVEL > nLvl, "NumLevel is out of range" );
return maDefNumIndents[ nLvl ];
}
static void lcl_SetRuleChgd( SwTextNode& rNd, sal_uInt8 nLevel )
{
if( rNd.GetActualListLevel() == nLevel )
rNd.NumRuleChgd();
}
SwNumFormat::SwNumFormat() :
SvxNumberFormat(SVX_NUM_ARABIC),
SwClient( nullptr ),
m_pVertOrient(new SwFormatVertOrient( 0, text::VertOrientation::NONE))
,m_cGrfBulletCP(USHRT_MAX)//For i120928,record the cp info of graphic within bullet
{
}
SwNumFormat::SwNumFormat( const SwNumFormat& rFormat) :
SvxNumberFormat(rFormat),
SwClient( rFormat.GetRegisteredInNonConst() ),
m_pVertOrient(new SwFormatVertOrient( 0, rFormat.GetVertOrient()))
,m_cGrfBulletCP(rFormat.m_cGrfBulletCP)//For i120928,record the cp info of graphic within bullet
{
sal_Int16 eMyVertOrient = rFormat.GetVertOrient();
SetGraphicBrush( rFormat.GetBrush(), &rFormat.GetGraphicSize(),
&eMyVertOrient);
}
SwNumFormat::SwNumFormat(const SvxNumberFormat& rNumFormat, SwDoc* pDoc)
: SvxNumberFormat(rNumFormat)
, m_pVertOrient(new SwFormatVertOrient( 0, rNumFormat.GetVertOrient()))
, m_cGrfBulletCP(USHRT_MAX)
{
sal_Int16 eMyVertOrient = rNumFormat.GetVertOrient();
SetGraphicBrush( rNumFormat.GetBrush(), &rNumFormat.GetGraphicSize(),
&eMyVertOrient);
const OUString rCharStyleName = rNumFormat.SvxNumberFormat::GetCharFormatName();
if( !rCharStyleName.isEmpty() )
{
SwCharFormat* pCFormat = pDoc->FindCharFormatByName( rCharStyleName );
if( !pCFormat )
{
sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName( rCharStyleName,
SwGetPoolIdFromName::ChrFmt );
pCFormat = nId != USHRT_MAX
? pDoc->getIDocumentStylePoolAccess().GetCharFormatFromPool( nId )
: pDoc->MakeCharFormat( rCharStyleName, nullptr );
}
pCFormat->Add( this );
}
else
EndListeningAll();
}
SwNumFormat::~SwNumFormat()
{
}
// #i22362#
bool SwNumFormat::IsEnumeration() const
{
// #i30655# native numbering did not work any longer
// using this code. Therefore HBRINKM and I agreed upon defining
// IsEnumeration() as !IsItemize()
return !IsItemize();
}
bool SwNumFormat::IsItemize() const
{
bool bResult;
switch(GetNumberingType())
{
case SVX_NUM_CHAR_SPECIAL:
case SVX_NUM_BITMAP:
bResult = true;
break;
default:
bResult = false;
}
return bResult;
}
SwNumFormat& SwNumFormat::operator=( const SwNumFormat& rNumFormat)
{
SvxNumberFormat::operator=(rNumFormat);
StartListeningToSameModifyAs(rNumFormat);
//For i120928,record the cp info of graphic within bullet
m_cGrfBulletCP = rNumFormat.m_cGrfBulletCP;
return *this;
}
bool SwNumFormat::operator==( const SwNumFormat& rNumFormat) const
{
bool bRet = SvxNumberFormat::operator==(rNumFormat) &&
GetRegisteredIn() == rNumFormat.GetRegisteredIn();
return bRet;
}
void SwNumFormat::SetCharFormat( SwCharFormat* pChFormat)
{
if( pChFormat )
pChFormat->Add( this );
else
EndListeningAll();
}
void SwNumFormat::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
{
// Look for the NumRules object in the Doc where this NumFormat is set.
// The format does not need to exist!
const SwCharFormat* pFormat = nullptr;
sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0;
switch( nWhich )
{
case RES_ATTRSET_CHG:
case RES_FMT_CHG:
pFormat = GetCharFormat();
break;
}
if( pFormat && !pFormat->GetDoc()->IsInDtor() )
UpdateNumNodes( const_cast<SwDoc*>(pFormat->GetDoc()) );
else
CheckRegistration( pOld );
}
OUString SwNumFormat::GetCharFormatName() const
{
if(static_cast<const SwCharFormat*>(GetRegisteredIn()))
return static_cast<const SwCharFormat*>(GetRegisteredIn())->GetName();
return OUString();
}
void SwNumFormat::SetGraphicBrush( const SvxBrushItem* pBrushItem, const Size* pSize,
const sal_Int16* pOrient)
{
if(pOrient)
m_pVertOrient->SetVertOrient( *pOrient );
SvxNumberFormat::SetGraphicBrush( pBrushItem, pSize, pOrient);
}
void SwNumFormat::UpdateNumNodes( SwDoc* pDoc )
{
bool bDocIsModified = pDoc->getIDocumentState().IsModified();
bool bFnd = false;
for( SwNumRuleTable::size_type n = pDoc->GetNumRuleTable().size(); !bFnd && n; )
{
const SwNumRule* pRule = pDoc->GetNumRuleTable()[ --n ];
for( sal_uInt8 i = 0; i < MAXLEVEL; ++i )
if( pRule->GetNumFormat( i ) == this )
{
SwNumRule::tTextNodeList aTextNodeList;
pRule->GetTextNodeList( aTextNodeList );
for ( auto& rpTextNode : aTextNodeList )
{
lcl_SetRuleChgd( *rpTextNode, i );
}
bFnd = true;
break;
}
}
if( bFnd && !bDocIsModified )
pDoc->getIDocumentState().ResetModified();
}
const SwFormatVertOrient* SwNumFormat::GetGraphicOrientation() const
{
sal_Int16 eOrient = SvxNumberFormat::GetVertOrient();
if(text::VertOrientation::NONE == eOrient)
return nullptr;
else
{
m_pVertOrient->SetVertOrient(eOrient);
return m_pVertOrient.get();
}
}
SwNumRule::SwNumRule( const OUString& rNm,
const SvxNumberFormat::SvxNumPositionAndSpaceMode eDefaultNumberFormatPositionAndSpaceMode,
SwNumRuleType eType )
: maTextNodeList(),
maParagraphStyleList(),
mpNumRuleMap(nullptr),
msName( rNm ),
meRuleType( eType ),
mnPoolFormatId( USHRT_MAX ),
mnPoolHelpId( USHRT_MAX ),
mnPoolHlpFileId( UCHAR_MAX ),
mbAutoRuleFlag( true ),
mbInvalidRuleFlag( true ),
mbContinusNum( false ),
mbAbsSpaces( false ),
mbHidden( false ),
mbCountPhantoms( true ),
mbUsedByRedline( false ),
meDefaultNumberFormatPositionAndSpaceMode( eDefaultNumberFormatPositionAndSpaceMode ),
msDefaultListId()
{
if( !mnRefCount++ ) // for the first time, initialize
{
SwNumFormat* pFormat;
sal_uInt8 n;
// numbering:
// position-and-space mode LABEL_WIDTH_AND_POSITION:
for( n = 0; n < MAXLEVEL; ++n )
{
pFormat = new SwNumFormat;
pFormat->SetIncludeUpperLevels( 1 );
pFormat->SetStart( 1 );
pFormat->SetAbsLSpace( lNumberIndent + SwNumRule::GetNumIndent( n ) );
pFormat->SetFirstLineOffset( lNumberFirstLineOffset );
pFormat->SetSuffix( "." );
pFormat->SetBulletChar( numfunc::GetBulletChar(n));
SwNumRule::maBaseFormats[ NUM_RULE ][ n ] = pFormat;
}
// position-and-space mode LABEL_ALIGNMENT
// first line indent of general numbering in inch: -0,25 inch
const long cFirstLineIndent = -1440/4;
// indent values of general numbering in inch:
// 0,5 0,75 1,0 1,25 1,5
// 1,75 2,0 2,25 2,5 2,75
const long cIndentAt[ MAXLEVEL ] = {
1440/2, 1440*3/4, 1440, 1440*5/4, 1440*3/2,
1440*7/4, 1440*2, 1440*9/4, 1440*5/2, 1440*11/4 };
for( n = 0; n < MAXLEVEL; ++n )
{
pFormat = new SwNumFormat;
pFormat->SetIncludeUpperLevels( 1 );
pFormat->SetStart( 1 );
pFormat->SetPositionAndSpaceMode( SvxNumberFormat::LABEL_ALIGNMENT );
pFormat->SetLabelFollowedBy( SvxNumberFormat::LISTTAB );
pFormat->SetListtabPos( cIndentAt[ n ] );
pFormat->SetFirstLineIndent( cFirstLineIndent );
pFormat->SetIndentAt( cIndentAt[ n ] );
pFormat->SetSuffix( "." );
pFormat->SetBulletChar( numfunc::GetBulletChar(n));
SwNumRule::maLabelAlignmentBaseFormats[ NUM_RULE ][ n ] = pFormat;
}
// outline:
// position-and-space mode LABEL_WIDTH_AND_POSITION:
for( n = 0; n < MAXLEVEL; ++n )
{
pFormat = new SwNumFormat;
pFormat->SetNumberingType(SVX_NUM_NUMBER_NONE);
pFormat->SetIncludeUpperLevels( MAXLEVEL );
pFormat->SetStart( 1 );
pFormat->SetCharTextDistance( lOutlineMinTextDistance );
pFormat->SetBulletChar( numfunc::GetBulletChar(n));
SwNumRule::maBaseFormats[ OUTLINE_RULE ][ n ] = pFormat;
}
// position-and-space mode LABEL_ALIGNMENT:
for( n = 0; n < MAXLEVEL; ++n )
{
pFormat = new SwNumFormat;
pFormat->SetNumberingType(SVX_NUM_NUMBER_NONE);
pFormat->SetIncludeUpperLevels( MAXLEVEL );
pFormat->SetStart( 1 );
pFormat->SetPositionAndSpaceMode( SvxNumberFormat::LABEL_ALIGNMENT );
pFormat->SetBulletChar( numfunc::GetBulletChar(n));
SwNumRule::maLabelAlignmentBaseFormats[ OUTLINE_RULE ][ n ] = pFormat;
}
}
OSL_ENSURE( !msName.isEmpty(), "NumRule without a name!" );
}
SwNumRule::SwNumRule( const SwNumRule& rNumRule )
: maTextNodeList(),
maParagraphStyleList(),
mpNumRuleMap(nullptr),
msName( rNumRule.msName ),
meRuleType( rNumRule.meRuleType ),
mnPoolFormatId( rNumRule.GetPoolFormatId() ),
mnPoolHelpId( rNumRule.GetPoolHelpId() ),
mnPoolHlpFileId( rNumRule.GetPoolHlpFileId() ),
mbAutoRuleFlag( rNumRule.mbAutoRuleFlag ),
mbInvalidRuleFlag( true ),
mbContinusNum( rNumRule.mbContinusNum ),
mbAbsSpaces( rNumRule.mbAbsSpaces ),
mbHidden( rNumRule.mbHidden ),
mbCountPhantoms( true ),
mbUsedByRedline( false ),
meDefaultNumberFormatPositionAndSpaceMode( rNumRule.meDefaultNumberFormatPositionAndSpaceMode ),
msDefaultListId( rNumRule.msDefaultListId )
{
++mnRefCount;
for( sal_uInt16 n = 0; n < MAXLEVEL; ++n )
if( rNumRule.maFormats[ n ] )
Set( n, *rNumRule.maFormats[ n ] );
}
SwNumRule::~SwNumRule()
{
for (auto & i : maFormats)
i.reset();
if (mpNumRuleMap)
{
mpNumRuleMap->erase(GetName());
}
if( !--mnRefCount ) // the last one closes the door (?)
{
// Numbering:
SwNumFormat** ppFormats = &SwNumRule::maBaseFormats[0][0];
int n;
for( n = 0; n < MAXLEVEL; ++n, ++ppFormats )
{
delete *ppFormats;
*ppFormats = nullptr;
}
// Outline:
for( n = 0; n < MAXLEVEL; ++n, ++ppFormats )
{
delete *ppFormats;
*ppFormats = nullptr;
}
ppFormats = &SwNumRule::maLabelAlignmentBaseFormats[0][0];
for( n = 0; n < MAXLEVEL; ++n, ++ppFormats )
{
delete *ppFormats;
*ppFormats = nullptr;
}
for( n = 0; n < MAXLEVEL; ++n, ++ppFormats )
{
delete *ppFormats;
*ppFormats = nullptr;
}
}
maTextNodeList.clear();
maParagraphStyleList.clear();
}
void SwNumRule::CheckCharFormats( SwDoc* pDoc )
{
for(auto& rpNumFormat : maFormats)
{
if( rpNumFormat )
{
SwCharFormat* pFormat = rpNumFormat->GetCharFormat();
if( pFormat && pFormat->GetDoc() != pDoc )
{
// copy
SwNumFormat* pNew = new SwNumFormat( *rpNumFormat );
pNew->SetCharFormat( pDoc->CopyCharFormat( *pFormat ) );
rpNumFormat.reset(pNew);
}
}
}
}
SwNumRule& SwNumRule::operator=( const SwNumRule& rNumRule )
{
if( this != &rNumRule )
{
for( sal_uInt16 n = 0; n < MAXLEVEL; ++n )
Set( n, rNumRule.maFormats[ n ].get() );
meRuleType = rNumRule.meRuleType;
msName = rNumRule.msName;
mbAutoRuleFlag = rNumRule.mbAutoRuleFlag;
mbInvalidRuleFlag = true;
mbContinusNum = rNumRule.mbContinusNum;
mbAbsSpaces = rNumRule.mbAbsSpaces;
mbHidden = rNumRule.mbHidden;
mnPoolFormatId = rNumRule.GetPoolFormatId();
mnPoolHelpId = rNumRule.GetPoolHelpId();
mnPoolHlpFileId = rNumRule.GetPoolHlpFileId();
}
return *this;
}
bool SwNumRule::operator==( const SwNumRule& rRule ) const
{
bool bRet = meRuleType == rRule.meRuleType &&
msName == rRule.msName &&
mbAutoRuleFlag == rRule.mbAutoRuleFlag &&
mbContinusNum == rRule.mbContinusNum &&
mbAbsSpaces == rRule.mbAbsSpaces &&
mnPoolFormatId == rRule.GetPoolFormatId() &&
mnPoolHelpId == rRule.GetPoolHelpId() &&
mnPoolHlpFileId == rRule.GetPoolHlpFileId();
if( bRet )
{
for( sal_uInt8 n = 0; n < MAXLEVEL; ++n )
if( rRule.Get( n ) != Get( n ) )
{
bRet = false;
break;
}
}
return bRet;
}
void SwNumRule::Set( sal_uInt16 i, const SwNumFormat& rNumFormat )
{
OSL_ENSURE( i < MAXLEVEL, "Serious defect" );
if( i < MAXLEVEL )
{
if( !maFormats[ i ] || (rNumFormat != Get( i )) )
{
maFormats[ i ].reset(new SwNumFormat( rNumFormat ));
mbInvalidRuleFlag = true;
}
}
}
void SwNumRule::Set( sal_uInt16 i, const SwNumFormat* pNumFormat )
{
OSL_ENSURE( i < MAXLEVEL, "Serious defect" );
if( i >= MAXLEVEL )
return;
if( !maFormats[ i ] )
{
if( pNumFormat )
{
maFormats[ i ].reset(new SwNumFormat( *pNumFormat ));
mbInvalidRuleFlag = true;
}
}
else if( !pNumFormat )
{
maFormats[ i ].reset();
mbInvalidRuleFlag = true;
}
else if( *maFormats[i] != *pNumFormat )
{
*maFormats[ i ] = *pNumFormat;
mbInvalidRuleFlag = true;
}
}
OUString SwNumRule::MakeNumString( const SwNodeNum& rNum, bool bInclStrings ) const
{
if (rNum.IsCounted())
return MakeNumString(rNum.GetNumberVector(), bInclStrings);
return OUString();
}
OUString SwNumRule::MakeNumString( const SwNumberTree::tNumberVector & rNumVector,
const bool bInclStrings,
const bool bOnlyArabic,
const unsigned int _nRestrictToThisLevel,
SwNumRule::Extremities* pExtremities,
LanguageType nLang ) const
{
OUStringBuffer aStr;
SwNumberTree::tNumberVector::size_type nLevel = rNumVector.size() - 1;
if ( pExtremities )
pExtremities->nPrefixChars = pExtremities->nSuffixChars = 0;
if ( nLevel > _nRestrictToThisLevel )
{
nLevel = _nRestrictToThisLevel;
}
if (nLevel < MAXLEVEL)
{
const SwNumFormat& rMyNFormat = Get( static_cast<sal_uInt16>(nLevel) );
{
css::lang::Locale aLocale( LanguageTag::convertToLocale(nLang));
if (rMyNFormat.HasListFormat())
{
OUString sLevelFormat = rMyNFormat.GetListFormat();
// In this case we are ignoring GetIncludeUpperLevels: we put all
// level numbers requested by level format
for (SwNumberTree::tNumberVector::size_type i=0; i <= nLevel; ++i)
{
OUString sReplacement;
if (rNumVector[i])
{
if (bOnlyArabic)
sReplacement = OUString::number(rNumVector[i]);
else
sReplacement = Get(i).GetNumStr(rNumVector[i], aLocale);
}
else
sReplacement = "0"; // all 0 level are a 0
OUString sFind("%" + OUString::number(i + 1));
sal_Int32 nPosition = sLevelFormat.indexOf(sFind);
if (nPosition >= 0)
sLevelFormat = sLevelFormat.replaceAt(nPosition, sFind.getLength(), sReplacement);
}
// As a fallback: caller code expects nonempty string as a result.
// But if we have empty string (and had no errors before) this is valid result.
// So use classical hack with zero-width-space as a string filling.
if (sLevelFormat.isEmpty())
sLevelFormat = OUStringChar(CHAR_ZWSP);
aStr = sLevelFormat;
}
else
{
// Fallback case: level format is not defined
// So use old way with levels joining by dot "."
SwNumberTree::tNumberVector::size_type i = nLevel;
if (!IsContinusNum() &&
// - do not include upper levels, if level isn't numbered.
rMyNFormat.GetNumberingType() != SVX_NUM_NUMBER_NONE &&
rMyNFormat.GetIncludeUpperLevels()) // Just the own level?
{
sal_uInt8 n = rMyNFormat.GetIncludeUpperLevels();
if (1 < n)
{
if (i + 1 >= n)
i -= n - 1;
else
i = 0;
}
}
for (; i <= nLevel; ++i)
{
const SwNumFormat& rNFormat = Get(i);
if (SVX_NUM_NUMBER_NONE == rNFormat.GetNumberingType())
{
// Should 1.1.1 --> 2. NoNum --> 1..1 or 1.1 ??
// if( i != rNum.nMyLevel )
// aStr += ".";
continue;
}
if (rNumVector[i])
{
if (bOnlyArabic)
aStr.append(OUString::number(rNumVector[i]));
else
aStr.append(rNFormat.GetNumStr(rNumVector[i], aLocale));
}
else
aStr.append("0"); // all 0 level are a 0
if (i != nLevel && !aStr.isEmpty())
aStr.append(".");
}
// The type doesn't have any number, so don't append
// the post-/prefix string
if (bInclStrings && !bOnlyArabic &&
SVX_NUM_CHAR_SPECIAL != rMyNFormat.GetNumberingType() &&
SVX_NUM_BITMAP != rMyNFormat.GetNumberingType())
{
const OUString& sPrefix = rMyNFormat.GetPrefix();
const OUString& sSuffix = rMyNFormat.GetSuffix();
aStr.insert(0, sPrefix);
aStr.append(sSuffix);
if (pExtremities)
{
pExtremities->nPrefixChars = sPrefix.getLength();
pExtremities->nSuffixChars = sSuffix.getLength();
}
}
}
}
}
return aStr.makeStringAndClear();
}
OUString SwNumRule::MakeRefNumString( const SwNodeNum& rNodeNum,
const bool bInclSuperiorNumLabels,
const int nRestrictInclToThisLevel ) const
{
OUString aRefNumStr;
if ( rNodeNum.GetLevelInListTree() >= 0 )
{
bool bOldHadPrefix = true;
const SwNodeNum* pWorkingNodeNum( &rNodeNum );
do
{
bool bMakeNumStringForPhantom( false );
if ( pWorkingNodeNum->IsPhantom() )
{
int nListLevel = pWorkingNodeNum->GetLevelInListTree();
if (nListLevel < 0)
nListLevel = 0;
if (nListLevel >= MAXLEVEL)
nListLevel = MAXLEVEL - 1;
SwNumFormat aFormat( Get( static_cast<sal_uInt16>(nListLevel) ) );
bMakeNumStringForPhantom = aFormat.IsEnumeration() &&
SVX_NUM_NUMBER_NONE != aFormat.GetNumberingType();
}
if ( bMakeNumStringForPhantom ||
( !pWorkingNodeNum->IsPhantom() &&
pWorkingNodeNum->GetTextNode() &&
pWorkingNodeNum->GetTextNode()->HasNumber() ) )
{
Extremities aExtremities;
OUString aPrevStr = MakeNumString( pWorkingNodeNum->GetNumberVector(),
true, false, MAXLEVEL,
&aExtremities);
sal_Int32 nStrip = 0;
while ( nStrip < aExtremities.nPrefixChars )
{
const sal_Unicode c = aPrevStr[nStrip];
if ( c!='\t' && c!=' ')
break;
++nStrip;
}
if (nStrip)
{
aPrevStr = aPrevStr.copy( nStrip );
aExtremities.nPrefixChars -= nStrip;
}
if (bOldHadPrefix &&
aExtremities.nSuffixChars &&
!aExtremities.nPrefixChars
)
{
aPrevStr = aPrevStr.copy(0,
aPrevStr.getLength() - aExtremities.nSuffixChars);
}
bOldHadPrefix = ( aExtremities.nPrefixChars > 0);
aRefNumStr = aPrevStr + aRefNumStr;
}
if ( bInclSuperiorNumLabels && pWorkingNodeNum->GetLevelInListTree() > 0 )
{
sal_uInt8 n = Get( static_cast<sal_uInt16>(pWorkingNodeNum->GetLevelInListTree()) ).GetIncludeUpperLevels();
pWorkingNodeNum = dynamic_cast<SwNodeNum*>(pWorkingNodeNum->GetParent());
// skip parents, whose list label is already contained in the actual list label.
while ( pWorkingNodeNum && n > 1 )
{
pWorkingNodeNum = dynamic_cast<SwNodeNum*>(pWorkingNodeNum->GetParent());
--n;
}
}
else
{
break;
}
} while ( pWorkingNodeNum &&
pWorkingNodeNum->GetLevelInListTree() >= 0 &&
pWorkingNodeNum->GetLevelInListTree() >= nRestrictInclToThisLevel );
}
return aRefNumStr;
}
OUString SwNumRule::MakeParagraphStyleListString() const
{
OUString aParagraphStyleListString;
for (const auto& rParagraphStyle : maParagraphStyleList)
{
if (!aParagraphStyleListString.isEmpty())
aParagraphStyleListString += ", ";
aParagraphStyleListString += rParagraphStyle->GetName();
}
return aParagraphStyleListString;
}
/** Copy method of SwNumRule
A kind of copy constructor, so that the num formats are attached to the
right CharFormats of a Document.
Copies the NumFormats and returns itself. */
SwNumRule& SwNumRule::CopyNumRule( SwDoc* pDoc, const SwNumRule& rNumRule )
{
for( sal_uInt16 n = 0; n < MAXLEVEL; ++n )
{
Set( n, rNumRule.maFormats[ n ].get() );
if( maFormats[ n ] && maFormats[ n ]->GetCharFormat() &&
!pDoc->GetCharFormats()->IsAlive(maFormats[n]->GetCharFormat()))
{
// If we copy across different Documents, then copy the
// corresponding CharFormat into the new Document.
maFormats[n]->SetCharFormat( pDoc->CopyCharFormat( *maFormats[n]->
GetCharFormat() ) );
}
}
meRuleType = rNumRule.meRuleType;
msName = rNumRule.msName;
mbAutoRuleFlag = rNumRule.mbAutoRuleFlag;
mnPoolFormatId = rNumRule.GetPoolFormatId();
mnPoolHelpId = rNumRule.GetPoolHelpId();
mnPoolHlpFileId = rNumRule.GetPoolHlpFileId();
mbInvalidRuleFlag = true;
return *this;
}
void SwNumRule::SetSvxRule(const SvxNumRule& rNumRule, SwDoc* pDoc)
{
for( sal_uInt16 n = 0; n < MAXLEVEL; ++n )
{
const SvxNumberFormat* pSvxFormat = rNumRule.Get(n);
maFormats[n].reset( pSvxFormat ? new SwNumFormat(*pSvxFormat, pDoc) : nullptr );
}
mbInvalidRuleFlag = true;
mbContinusNum = rNumRule.IsContinuousNumbering();
}
SvxNumRule SwNumRule::MakeSvxNumRule() const
{
SvxNumRule aRule(SvxNumRuleFlags::CONTINUOUS | SvxNumRuleFlags::CHAR_STYLE |
SvxNumRuleFlags::ENABLE_LINKED_BMP | SvxNumRuleFlags::ENABLE_EMBEDDED_BMP,
MAXLEVEL, mbContinusNum,
meRuleType == NUM_RULE ? SvxNumRuleType::NUMBERING : SvxNumRuleType::OUTLINE_NUMBERING );
for( sal_uInt16 n = 0; n < MAXLEVEL; ++n )
{
SwNumFormat aNumFormat = Get(n);
if(aNumFormat.GetCharFormat())
aNumFormat.SetCharFormatName(aNumFormat.GetCharFormat()->GetName());
aRule.SetLevel(n, aNumFormat, maFormats[n] != nullptr);
}
return aRule;
}
void SwNumRule::SetInvalidRule(bool bFlag)
{
if (bFlag)
{
o3tl::sorted_vector< SwList* > aLists;
for ( const SwTextNode* pTextNode : maTextNodeList )
{
// #i111681# - applying patch from cmc
SwList* pList = pTextNode->GetDoc()->getIDocumentListsAccess().getListByName( pTextNode->GetListId() );
OSL_ENSURE( pList, "<SwNumRule::SetInvalidRule(..)> - list at which the text node is registered at does not exist. This is a serious issue.");
if ( pList )
{
aLists.insert( pList );
}
}
for ( auto aList : aLists )
aList->InvalidateListTree();
}
mbInvalidRuleFlag = bFlag;
}
/// change indent of all list levels by given difference
void SwNumRule::ChangeIndent( const sal_Int32 nDiff )
{
for ( sal_uInt16 i = 0; i < MAXLEVEL; ++i )
{
SwNumFormat aTmpNumFormat( Get(i) );
const SvxNumberFormat::SvxNumPositionAndSpaceMode ePosAndSpaceMode(
aTmpNumFormat.GetPositionAndSpaceMode() );
if ( ePosAndSpaceMode == SvxNumberFormat::LABEL_WIDTH_AND_POSITION )
{
auto nNewIndent = nDiff +
aTmpNumFormat.GetAbsLSpace();
if ( nNewIndent < 0 )
{
nNewIndent = 0;
}
aTmpNumFormat.SetAbsLSpace( nNewIndent );
}
else if ( ePosAndSpaceMode == SvxNumberFormat::LABEL_ALIGNMENT )
{
// adjust also the list tab position, if a list tab stop is applied
if ( aTmpNumFormat.GetLabelFollowedBy() == SvxNumberFormat::LISTTAB )
{
const long nNewListTab = aTmpNumFormat.GetListtabPos() + nDiff;
aTmpNumFormat.SetListtabPos( nNewListTab );
}
const long nNewIndent = nDiff +
aTmpNumFormat.GetIndentAt();
aTmpNumFormat.SetIndentAt( nNewIndent );
}
Set( i, aTmpNumFormat );
}
SetInvalidRule( true );
}
/// set indent of certain list level to given value
void SwNumRule::SetIndent( const short nNewIndent,
const sal_uInt16 nListLevel )
{
SwNumFormat aTmpNumFormat( Get(nListLevel) );
const SvxNumberFormat::SvxNumPositionAndSpaceMode ePosAndSpaceMode(
aTmpNumFormat.GetPositionAndSpaceMode() );
if ( ePosAndSpaceMode == SvxNumberFormat::LABEL_WIDTH_AND_POSITION )
{
aTmpNumFormat.SetAbsLSpace( nNewIndent );
}
else if ( ePosAndSpaceMode == SvxNumberFormat::LABEL_ALIGNMENT )
{
// adjust also the list tab position, if a list tab stop is applied
if ( aTmpNumFormat.GetLabelFollowedBy() == SvxNumberFormat::LISTTAB )
{
const long nNewListTab = aTmpNumFormat.GetListtabPos() +
( nNewIndent - aTmpNumFormat.GetIndentAt() );
aTmpNumFormat.SetListtabPos( nNewListTab );
}
aTmpNumFormat.SetIndentAt( nNewIndent );
}
SetInvalidRule( true );
}
/// set indent of first list level to given value and change other list level's
/// indents accordingly
void SwNumRule::SetIndentOfFirstListLevelAndChangeOthers( const short nNewIndent )
{
SwNumFormat aTmpNumFormat( Get(0) );
sal_Int32 nDiff( 0 );
const SvxNumberFormat::SvxNumPositionAndSpaceMode ePosAndSpaceMode(
aTmpNumFormat.GetPositionAndSpaceMode() );
if ( ePosAndSpaceMode == SvxNumberFormat::LABEL_WIDTH_AND_POSITION )
{
nDiff = nNewIndent
- aTmpNumFormat.GetFirstLineOffset()
- aTmpNumFormat.GetAbsLSpace();
}
else if ( ePosAndSpaceMode == SvxNumberFormat::LABEL_ALIGNMENT )
{
nDiff = nNewIndent - aTmpNumFormat.GetIndentAt();
}
if ( nDiff != 0 )
{
ChangeIndent( nDiff );
}
}
void SwNumRule::Validate()
{
o3tl::sorted_vector< SwList* > aLists;
for ( const SwTextNode* pTextNode : maTextNodeList )
{
aLists.insert( pTextNode->GetDoc()->getIDocumentListsAccess().getListByName( pTextNode->GetListId() ) );
}
for ( auto aList : aLists )
aList->ValidateListTree();
SetInvalidRule(false);
}
void SwNumRule::SetCountPhantoms(bool bCountPhantoms)
{
mbCountPhantoms = bCountPhantoms;
}
SwNumRule::tParagraphStyleList::size_type SwNumRule::GetParagraphStyleListSize() const
{
return maParagraphStyleList.size();
}
void SwNumRule::AddParagraphStyle( SwTextFormatColl& rTextFormatColl )
{
tParagraphStyleList::iterator aIter =
std::find( maParagraphStyleList.begin(), maParagraphStyleList.end(), &rTextFormatColl );
if ( aIter == maParagraphStyleList.end() )
{
maParagraphStyleList.push_back( &rTextFormatColl );
}
}
void SwNumRule::RemoveParagraphStyle( SwTextFormatColl& rTextFormatColl )
{
tParagraphStyleList::iterator aIter =
std::find( maParagraphStyleList.begin(), maParagraphStyleList.end(), &rTextFormatColl );
if ( aIter != maParagraphStyleList.end() )
{
maParagraphStyleList.erase( aIter );
}
}
void SwNumRule::dumpAsXml(xmlTextWriterPtr pWriter) const
{
xmlTextWriterStartElement(pWriter, BAD_CAST("SwNumRule"));
xmlTextWriterWriteAttribute(pWriter, BAD_CAST("msName"), BAD_CAST(msName.toUtf8().getStr()));
xmlTextWriterWriteAttribute(pWriter, BAD_CAST("mnPoolFormatId"), BAD_CAST(OString::number(mnPoolFormatId).getStr()));
xmlTextWriterWriteAttribute(pWriter, BAD_CAST("mbAutoRuleFlag"), BAD_CAST(OString::boolean(mbAutoRuleFlag).getStr()));
for (const auto& pFormat : maFormats)
{
if (!pFormat)
{
continue;
}
pFormat->dumpAsXml(pWriter);
}
xmlTextWriterEndElement(pWriter);
}
void SwNumRule::GetGrabBagItem(uno::Any& rVal) const
{
if (mpGrabBagItem)
mpGrabBagItem->QueryValue(rVal);
else
rVal <<= uno::Sequence<beans::PropertyValue>();
}
void SwNumRule::SetGrabBagItem(const uno::Any& rVal)
{
if (!mpGrabBagItem)
mpGrabBagItem = std::make_shared<SfxGrabBagItem>();
mpGrabBagItem->PutValue(rVal, 0);
}
namespace numfunc
{
namespace {
/** class containing default bullet list configuration data */
class SwDefBulletConfig : private utl::ConfigItem
{
public:
static SwDefBulletConfig& getInstance();
const OUString& GetFontname() const
{
return msFontname;
}
bool IsFontnameUserDefined() const
{
return mbUserDefinedFontname;
}
const vcl::Font& GetFont() const
{
return *mpFont;
}
sal_Unicode GetChar( sal_uInt8 p_nListLevel ) const
{
if (p_nListLevel >= MAXLEVEL)
{
p_nListLevel = MAXLEVEL - 1;
}
return mnLevelChars[p_nListLevel];
}
SwDefBulletConfig();
private:
/** sets internal default bullet configuration data to default values */
void SetToDefault();
/** returns sequence of default bullet configuration property names */
static uno::Sequence<OUString> GetPropNames();
/** loads default bullet configuration properties and applies
values to internal data */
void LoadConfig();
/** initialize font instance for default bullet list */
void InitFont();
/** catches notification about changed default bullet configuration data */
virtual void Notify( const uno::Sequence<OUString>& aPropertyNames ) override;
virtual void ImplCommit() override;
// default bullet list configuration data
OUString msFontname;
bool mbUserDefinedFontname;
FontWeight meFontWeight;
FontItalic meFontItalic;
sal_Unicode mnLevelChars[MAXLEVEL];
// default bullet list font instance
std::unique_ptr<vcl::Font> mpFont;
};
class theSwDefBulletConfig
: public rtl::Static<SwDefBulletConfig, theSwDefBulletConfig>{};
}
SwDefBulletConfig& SwDefBulletConfig::getInstance()
{
return theSwDefBulletConfig::get();
}
SwDefBulletConfig::SwDefBulletConfig()
: ConfigItem( "Office.Writer/Numbering/DefaultBulletList" ),
// default bullet font is now OpenSymbol
msFontname( OUString("OpenSymbol") ),
mbUserDefinedFontname( false ),
meFontWeight( WEIGHT_DONTKNOW ),
meFontItalic( ITALIC_NONE )
{
SetToDefault();
LoadConfig();
InitFont();
// enable notification for changes on default bullet configuration change
EnableNotification( GetPropNames() );
}
void SwDefBulletConfig::SetToDefault()
{
msFontname = "OpenSymbol";
mbUserDefinedFontname = false;
meFontWeight = WEIGHT_DONTKNOW;
meFontItalic = ITALIC_NONE;
mnLevelChars[0] = 0x2022;
mnLevelChars[1] = 0x25e6;
mnLevelChars[2] = 0x25aa;
mnLevelChars[3] = 0x2022;
mnLevelChars[4] = 0x25e6;
mnLevelChars[5] = 0x25aa;
mnLevelChars[6] = 0x2022;
mnLevelChars[7] = 0x25e6;
mnLevelChars[8] = 0x25aa;
mnLevelChars[9] = 0x2022;
}
uno::Sequence<OUString> SwDefBulletConfig::GetPropNames()
{
uno::Sequence<OUString> aPropNames(13);
OUString* pNames = aPropNames.getArray();
pNames[0] = "BulletFont/FontFamilyname";
pNames[1] = "BulletFont/FontWeight";
pNames[2] = "BulletFont/FontItalic";
pNames[3] = "BulletCharLvl1";
pNames[4] = "BulletCharLvl2";
pNames[5] = "BulletCharLvl3";
pNames[6] = "BulletCharLvl4";
pNames[7] = "BulletCharLvl5";
pNames[8] = "BulletCharLvl6";
pNames[9] = "BulletCharLvl7";
pNames[10] = "BulletCharLvl8";
pNames[11] = "BulletCharLvl9";
pNames[12] = "BulletCharLvl10";
return aPropNames;
}
void SwDefBulletConfig::LoadConfig()
{
uno::Sequence<OUString> aPropNames = GetPropNames();
uno::Sequence<uno::Any> aValues =
GetProperties( aPropNames );
const uno::Any* pValues = aValues.getConstArray();
OSL_ENSURE( aValues.getLength() == aPropNames.getLength(),
"<SwDefBulletConfig::SwDefBulletConfig()> - GetProperties failed");
if ( aValues.getLength() == aPropNames.getLength() )
{
for ( int nProp = 0; nProp < aPropNames.getLength(); ++nProp )
{
if ( pValues[nProp].hasValue() )
{
switch ( nProp )
{
case 0:
{
OUString aStr;
pValues[nProp] >>= aStr;
msFontname = aStr;
mbUserDefinedFontname = true;
}
break;
case 1:
case 2:
{
sal_Int16 nTmp = 0;
pValues[nProp] >>= nTmp;
if ( nProp == 1 )
meFontWeight = static_cast<FontWeight>(nTmp);
else if ( nProp == 2 )
meFontItalic = static_cast<FontItalic>(nTmp);
}
break;
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
case 12:
{
sal_Unicode cChar = sal_Unicode();
pValues[nProp] >>= cChar;
mnLevelChars[nProp-3] = cChar;
}
break;
}
}
}
}
}
void SwDefBulletConfig::InitFont()
{
mpFont.reset( new vcl::Font( msFontname, OUString(), Size( 0, 14 ) ) );
mpFont->SetWeight( meFontWeight );
mpFont->SetItalic( meFontItalic );
mpFont->SetCharSet( RTL_TEXTENCODING_SYMBOL );
}
void SwDefBulletConfig::Notify( const uno::Sequence<OUString>& )
{
SetToDefault();
LoadConfig();
InitFont();
}
void SwDefBulletConfig::ImplCommit()
{
}
OUString const & GetDefBulletFontname()
{
return SwDefBulletConfig::getInstance().GetFontname();
}
bool IsDefBulletFontUserDefined()
{
return SwDefBulletConfig::getInstance().IsFontnameUserDefined();
}
const vcl::Font& GetDefBulletFont()
{
return SwDefBulletConfig::getInstance().GetFont();
}
sal_Unicode GetBulletChar( sal_uInt8 nLevel )
{
return SwDefBulletConfig::getInstance().GetChar( nLevel );
}
namespace {
/** class containing configuration data about user interface behavior
regarding lists and list items.
configuration item about behavior of <TAB>/<SHIFT-TAB>-key at first
position of first list item
*/
class SwNumberingUIBehaviorConfig : private utl::ConfigItem
{
public:
static SwNumberingUIBehaviorConfig& getInstance();
bool ChangeIndentOnTabAtFirstPosOfFirstListItem() const
{
return mbChangeIndentOnTabAtFirstPosOfFirstListItem;
}
SwNumberingUIBehaviorConfig();
private:
/** sets internal configuration data to default values */
void SetToDefault();
/** returns sequence of configuration property names */
static css::uno::Sequence<OUString> GetPropNames();
/** loads configuration properties and applies values to internal data */
void LoadConfig();
/** catches notification about changed configuration data */
virtual void Notify( const css::uno::Sequence<OUString>& aPropertyNames ) override;
virtual void ImplCommit() override;
// configuration data
bool mbChangeIndentOnTabAtFirstPosOfFirstListItem;
};
class theSwNumberingUIBehaviorConfig : public rtl::Static<SwNumberingUIBehaviorConfig, theSwNumberingUIBehaviorConfig>{};
}
SwNumberingUIBehaviorConfig& SwNumberingUIBehaviorConfig::getInstance()
{
return theSwNumberingUIBehaviorConfig::get();
}
SwNumberingUIBehaviorConfig::SwNumberingUIBehaviorConfig()
: ConfigItem( "Office.Writer/Numbering/UserInterfaceBehavior" ),
mbChangeIndentOnTabAtFirstPosOfFirstListItem( true )
{
SetToDefault();
LoadConfig();
// enable notification for changes on configuration change
EnableNotification( GetPropNames() );
}
void SwNumberingUIBehaviorConfig::SetToDefault()
{
mbChangeIndentOnTabAtFirstPosOfFirstListItem = true;
}
css::uno::Sequence<OUString> SwNumberingUIBehaviorConfig::GetPropNames()
{
css::uno::Sequence<OUString> aPropNames { "ChangeIndentOnTabAtFirstPosOfFirstListItem" };
return aPropNames;
}
void SwNumberingUIBehaviorConfig::ImplCommit() {}
void SwNumberingUIBehaviorConfig::LoadConfig()
{
css::uno::Sequence<OUString> aPropNames = GetPropNames();
css::uno::Sequence<css::uno::Any> aValues = GetProperties( aPropNames );
const css::uno::Any* pValues = aValues.getConstArray();
OSL_ENSURE( aValues.getLength() == aPropNames.getLength(),
"<SwNumberingUIBehaviorConfig::LoadConfig()> - GetProperties failed");
if ( aValues.getLength() == aPropNames.getLength() )
{
for ( int nProp = 0; nProp < aPropNames.getLength(); ++nProp )
{
if ( pValues[nProp].hasValue() )
{
switch ( nProp )
{
case 0:
{
pValues[nProp] >>= mbChangeIndentOnTabAtFirstPosOfFirstListItem;
}
break;
default:
{
OSL_FAIL( "<SwNumberingUIBehaviorConfig::LoadConfig()> - unknown configuration property");
}
}
}
}
}
}
void SwNumberingUIBehaviorConfig::Notify( const css::uno::Sequence<OUString>& )
{
SetToDefault();
LoadConfig();
}
bool ChangeIndentOnTabAtFirstPosOfFirstListItem()
{
return SwNumberingUIBehaviorConfig::getInstance().ChangeIndentOnTabAtFirstPosOfFirstListItem();
}
SvxNumberFormat::SvxNumPositionAndSpaceMode GetDefaultPositionAndSpaceMode()
{
if (utl::ConfigManager::IsFuzzing())
return SvxNumberFormat::LABEL_ALIGNMENT;
SvxNumberFormat::SvxNumPositionAndSpaceMode ePosAndSpaceMode;
SvtSaveOptions aSaveOptions;
switch (aSaveOptions.GetODFSaneDefaultVersion())
{
case SvtSaveOptions::ODFSVER_010:
case SvtSaveOptions::ODFSVER_011:
{
ePosAndSpaceMode = SvxNumberFormat::LABEL_WIDTH_AND_POSITION;
}
break;
default: // >= ODFSVER_012
{
ePosAndSpaceMode = SvxNumberFormat::LABEL_ALIGNMENT;
}
}
return ePosAndSpaceMode;
}
}
void SwNumRuleTable::dumpAsXml(xmlTextWriterPtr pWriter) const
{
xmlTextWriterStartElement(pWriter, BAD_CAST("SwNumRuleTable"));
for (SwNumRule* pNumRule : *this)
pNumRule->dumpAsXml(pWriter);
xmlTextWriterEndElement(pWriter);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|