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
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
|
/*************************************************************************
*
* 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.
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_svtools.hxx"
#define _CTRLBOX_CXX
#include <tools/debug.hxx>
#ifndef _APP_HXX
#include <vcl/svapp.hxx>
#endif
#ifndef _FIELD_HXX
#include <vcl/field.hxx>
#endif
#include <comphelper/processfactory.hxx>
#include <unotools/charclass.hxx>
#include <svtools/svtdata.hxx>
#include <svl/svtools.hrc>
#include <ctrlbox.hxx>
#include <ctrltool.hxx>
#include <vcl/i18nhelp.hxx>
#define IMGTEXTSPACE 2
#define EXTRAFONTSIZE 5
static sal_Unicode aImplSymbolFontText[] = {0xF021,0xF032,0xF043,0xF054,0xF065,0xF076,0xF0B7,0xF0C8,0};
static sal_Unicode aImplStarSymbolText[] = {0x2706,0x2704,0x270D,0xE033,0x2211,0x2288,0};
// ========================================================================
// ColorListBox
// ========================================================================
// --------------------
// - ImplColorListData -
// --------------------
struct ImplColorListData
{
Color aColor;
BOOL bColor;
ImplColorListData() : aColor( COL_BLACK ) { bColor = FALSE; }
ImplColorListData( const Color& rColor ) : aColor( rColor ) { bColor = TRUE; }
};
DECLARE_LIST( ImpColorList, ImplColorListData* )
// -----------------------------------------------------------------------
void ColorListBox::ImplInit()
{
pColorList = new ImpColorList( 256, 64 );
aImageSize.Width() = GetTextWidth( XubString( RTL_CONSTASCII_USTRINGPARAM( "xxx" ) ) );
aImageSize.Height() = GetTextHeight();
aImageSize.Height() -= 2;
EnableUserDraw( TRUE );
SetUserItemSize( aImageSize );
}
// -----------------------------------------------------------------------
void ColorListBox::ImplDestroyColorEntries()
{
for ( USHORT n = (USHORT) pColorList->Count(); n; )
{
ImplColorListData* pData = pColorList->GetObject( --n );
delete pData;
}
pColorList->Clear();
}
// -----------------------------------------------------------------------
ColorListBox::ColorListBox( Window* pParent, WinBits nWinStyle ) :
ListBox( pParent, nWinStyle )
{
ImplInit();
}
// -----------------------------------------------------------------------
ColorListBox::ColorListBox( Window* pParent, const ResId& rResId ) :
ListBox( pParent, rResId )
{
ImplInit();
}
// -----------------------------------------------------------------------
ColorListBox::~ColorListBox()
{
ImplDestroyColorEntries();
delete pColorList;
}
// -----------------------------------------------------------------------
USHORT ColorListBox::InsertEntry( const XubString& rStr, USHORT nPos )
{
nPos = ListBox::InsertEntry( rStr, nPos );
if ( nPos != LISTBOX_ERROR )
{
ImplColorListData* pData = new ImplColorListData;
pColorList->Insert( pData, nPos );
}
return nPos;
}
// -----------------------------------------------------------------------
USHORT ColorListBox::InsertEntry( const Color& rColor, const XubString& rStr,
USHORT nPos )
{
nPos = ListBox::InsertEntry( rStr, nPos );
if ( nPos != LISTBOX_ERROR )
{
ImplColorListData* pData = new ImplColorListData( rColor );
pColorList->Insert( pData, nPos );
}
return nPos;
}
// -----------------------------------------------------------------------
void ColorListBox::InsertAutomaticEntry()
{
// insert the "Automatic"-entry always on the first position
InsertEntry( Color( COL_AUTO ), SvtResId( STR_SVT_AUTOMATIC_COLOR ), 0 );
}
// -----------------------------------------------------------------------
void ColorListBox::RemoveEntry( USHORT nPos )
{
ListBox::RemoveEntry( nPos );
delete pColorList->Remove( nPos );
}
// -----------------------------------------------------------------------
void ColorListBox::Clear()
{
ImplDestroyColorEntries();
ListBox::Clear();
}
// -----------------------------------------------------------------------
void ColorListBox::CopyEntries( const ColorListBox& rBox )
{
// Liste leeren
ImplDestroyColorEntries();
// Daten kopieren
USHORT nCount = (USHORT) rBox.pColorList->Count();
for ( USHORT n = 0; n < nCount; n++ )
{
ImplColorListData* pData = rBox.pColorList->GetObject( n );
USHORT nPos = InsertEntry( rBox.GetEntry( n ), LISTBOX_APPEND );
if ( nPos != LISTBOX_ERROR )
pColorList->Insert( new ImplColorListData( *pData ), nPos );
}
}
// -----------------------------------------------------------------------
USHORT ColorListBox::GetEntryPos( const Color& rColor ) const
{
for( USHORT n = (USHORT) pColorList->Count(); n; )
{
ImplColorListData* pData = pColorList->GetObject( --n );
if ( pData->bColor && ( pData->aColor == rColor ) )
return n;
}
return LISTBOX_ENTRY_NOTFOUND;
}
// -----------------------------------------------------------------------
Color ColorListBox::GetEntryColor( USHORT nPos ) const
{
Color aColor;
ImplColorListData* pData = pColorList->GetObject( nPos );
if ( pData && pData->bColor )
aColor = pData->aColor;
return aColor;
}
// -----------------------------------------------------------------------
void ColorListBox::UserDraw( const UserDrawEvent& rUDEvt )
{
ImplColorListData* pData = pColorList->GetObject( rUDEvt.GetItemId() );
if ( pData )
{
if ( pData->bColor )
{
Point aPos( rUDEvt.GetRect().TopLeft() );
aPos.X() += 2;
aPos.Y() += ( rUDEvt.GetRect().GetHeight() - aImageSize.Height() ) / 2;
rUDEvt.GetDevice()->Push();
rUDEvt.GetDevice()->SetFillColor( pData->aColor );
rUDEvt.GetDevice()->SetLineColor( rUDEvt.GetDevice()->GetTextColor() );
rUDEvt.GetDevice()->DrawRect( Rectangle( aPos, aImageSize ) );
rUDEvt.GetDevice()->Pop();
ListBox::DrawEntry( rUDEvt, FALSE, TRUE, FALSE );
}
else
ListBox::DrawEntry( rUDEvt, FALSE, TRUE, TRUE );
}
else
ListBox::DrawEntry( rUDEvt, TRUE, TRUE, FALSE );
}
// =======================================================================
// LineListBox
// =======================================================================
// -------------------
// - ImpListListData -
// -------------------
struct ImpLineListData
{
long nLine1;
long nLine2;
long nDistance;
};
DECLARE_LIST( ImpLineList, ImpLineListData* )
// -----------------------------------------------------------------------
inline const Color& LineListBox::GetPaintColor( void ) const
{
return maPaintCol;
}
// -----------------------------------------------------------------------
void LineListBox::ImpGetLine( long nLine1, long nLine2, long nDistance,
Bitmap& rBmp, XubString& rStr )
{
Size aSize = GetOutputSizePixel();
aSize.Width() -= 20;
aSize.Width() -= aTxtSize.Width();
aSize.Height() = aTxtSize.Height();
// SourceUnit nach Twips
if ( eSourceUnit == FUNIT_POINT )
{
nLine1 *= 20;
nLine2 *= 20;
nDistance *= 20;
}
else if ( eSourceUnit == FUNIT_MM )
{
nLine1 *= 14440;
nLine1 /= 254;
nLine2 *= 14440;
nLine2 /= 254;
nDistance *= 14440;
nDistance /= 254;
}
// Linien malen
aSize = aVirDev.PixelToLogic( aSize );
long nPix = aVirDev.PixelToLogic( Size( 0, 1 ) ).Height();
long n1 = nLine1 / 100;
long n2 = nLine2 / 100;
long nDist = nDistance / 100;
n1 += nPix-1;
n1 -= n1%nPix;
if ( n2 )
{
nDist += nPix-1;
nDist -= nDist%nPix;
n2 += nPix-1;
n2 -= n2%nPix;
}
long nVirHeight = n1+nDist+n2;
if ( nVirHeight > aSize.Height() )
aSize.Height() = nVirHeight;
// negative Breiten muss und darf man nicht painten
if ( aSize.Width() > 0 )
{
Size aVirSize = aVirDev.LogicToPixel( aSize );
if ( aVirDev.GetOutputSizePixel() != aVirSize )
aVirDev.SetOutputSizePixel( aVirSize );
aVirDev.SetFillColor( GetSettings().GetStyleSettings().GetFieldColor() );
aVirDev.DrawRect( Rectangle( Point(), aSize ) );
aVirDev.SetFillColor( GetPaintColor() );
aVirDev.DrawRect( Rectangle( 0, 0, aSize.Width(), n1-nPix ) );
if ( n2 )
{
aVirDev.DrawRect( Rectangle( 0, n1+nDist,
aSize.Width(), n1+nDist+n2-nPix ) );
}
rBmp = aVirDev.GetBitmap( Point(), Size( aSize.Width(), n1+nDist+n2 ) );
}
// Twips nach Unit
if ( eUnit == FUNIT_POINT )
{
nLine1 /= 20;
nLine2 /= 20;
nDistance /= 20;
rStr.AssignAscii( " pt" );
}
else if ( eUnit == FUNIT_MM )
{
nLine1 *= 254;
nLine1 /= 14400;
nLine2 *= 254;
nLine2 /= 14400;
nDistance *= 254;
nDistance /= 14400;
rStr.AssignAscii( " mm" );
}
String aNum( GetSettings().GetLocaleI18nHelper().GetNum( nLine1+nLine2+nDistance, 2 ) );
rStr.Insert( aNum, 0 );
}
// -----------------------------------------------------------------------
void LineListBox::ImplInit()
{
aTxtSize.Width() = GetTextWidth( XubString( RTL_CONSTASCII_USTRINGPARAM( "99,99 mm" ) ) );
aTxtSize.Height() = GetTextHeight();
pLineList = new ImpLineList;
eUnit = FUNIT_POINT;
eSourceUnit = FUNIT_POINT;
aVirDev.SetLineColor();
aVirDev.SetMapMode( MapMode( MAP_TWIP ) );
UpdatePaintLineColor();
}
// -----------------------------------------------------------------------
LineListBox::LineListBox( Window* pParent, WinBits nWinStyle ) :
ListBox( pParent, nWinStyle ),
aColor( COL_BLACK ),
maPaintCol( COL_BLACK )
{
ImplInit();
}
// -----------------------------------------------------------------------
LineListBox::LineListBox( Window* pParent, const ResId& rResId ) :
ListBox( pParent, rResId ),
aColor( COL_BLACK ),
maPaintCol( COL_BLACK )
{
ImplInit();
}
// -----------------------------------------------------------------------
LineListBox::~LineListBox()
{
ULONG n = 0;
ULONG nCount = pLineList->Count();
while ( n < nCount )
{
ImpLineListData* pData = pLineList->GetObject( n );
if ( pData )
delete pData;
n++;
}
delete pLineList;
}
// -----------------------------------------------------------------------
USHORT LineListBox::InsertEntry( const XubString& rStr, USHORT nPos )
{
nPos = ListBox::InsertEntry( rStr, nPos );
if ( nPos != LISTBOX_ERROR )
pLineList->Insert( NULL, nPos );
return nPos;
}
// -----------------------------------------------------------------------
USHORT LineListBox::InsertEntry( long nLine1, long nLine2, long nDistance,
USHORT nPos )
{
XubString aStr;
Bitmap aBmp;
ImpGetLine( nLine1, nLine2, nDistance, aBmp, aStr );
nPos = ListBox::InsertEntry( aStr, aBmp, nPos );
if ( nPos != LISTBOX_ERROR )
{
ImpLineListData* pData = new ImpLineListData;
pData->nLine1 = nLine1;
pData->nLine2 = nLine2;
pData->nDistance = nDistance;
pLineList->Insert( pData, nPos );
}
return nPos;
}
// -----------------------------------------------------------------------
void LineListBox::RemoveEntry( USHORT nPos )
{
ListBox::RemoveEntry( nPos );
ImpLineListData* pData = pLineList->Remove( nPos );
if ( pData )
delete pData;
}
// -----------------------------------------------------------------------
void LineListBox::Clear()
{
ULONG n = 0;
ULONG nCount = pLineList->Count();
while ( n < nCount )
{
ImpLineListData* pData = pLineList->GetObject( n );
if ( pData )
delete pData;
n++;
}
pLineList->Clear();
ListBox::Clear();
}
// -----------------------------------------------------------------------
USHORT LineListBox::GetEntryPos( long nLine1, long nLine2,
long nDistance ) const
{
ULONG n = 0;
ULONG nCount = pLineList->Count();
while ( n < nCount )
{
ImpLineListData* pData = pLineList->GetObject( n );
if ( pData )
{
if ( (pData->nLine1 == nLine1) &&
(pData->nLine2 == nLine2) &&
(pData->nDistance == nDistance) )
return (USHORT)n;
}
n++;
}
return LISTBOX_ENTRY_NOTFOUND;
}
// -----------------------------------------------------------------------
long LineListBox::GetEntryLine1( USHORT nPos ) const
{
ImpLineListData* pData = pLineList->GetObject( nPos );
if ( pData )
return pData->nLine1;
else
return 0;
}
// -----------------------------------------------------------------------
long LineListBox::GetEntryLine2( USHORT nPos ) const
{
ImpLineListData* pData = pLineList->GetObject( nPos );
if ( pData )
return pData->nLine2;
else
return 0;
}
// -----------------------------------------------------------------------
long LineListBox::GetEntryDistance( USHORT nPos ) const
{
ImpLineListData* pData = pLineList->GetObject( nPos );
if ( pData )
return pData->nDistance;
else
return 0;
}
// -----------------------------------------------------------------------
void LineListBox::UpdateLineColors( void )
{
if( UpdatePaintLineColor() )
{
ULONG nCount = pLineList->Count();
if( !nCount )
return;
XubString aStr;
Bitmap aBmp;
// exchange entries which containing lines
SetUpdateMode( FALSE );
USHORT nSelEntry = GetSelectEntryPos();
for( ULONG n = 0 ; n < nCount ; ++n )
{
ImpLineListData* pData = pLineList->GetObject( n );
if( pData )
{
// exchange listbox data
ListBox::RemoveEntry( USHORT( n ) );
ImpGetLine( pData->nLine1, pData->nLine2, pData->nDistance, aBmp, aStr );
ListBox::InsertEntry( aStr, aBmp, USHORT( n ) );
}
}
if( nSelEntry != LISTBOX_ENTRY_NOTFOUND )
SelectEntryPos( nSelEntry );
SetUpdateMode( TRUE );
Invalidate();
}
}
// -----------------------------------------------------------------------
BOOL LineListBox::UpdatePaintLineColor( void )
{
BOOL bRet = TRUE;
const StyleSettings& rSettings = GetSettings().GetStyleSettings();
Color aNewCol( rSettings.GetWindowColor().IsDark()? rSettings.GetLabelTextColor() : aColor );
bRet = aNewCol != maPaintCol;
if( bRet )
maPaintCol = aNewCol;
return bRet;
}
// -----------------------------------------------------------------------
void LineListBox::DataChanged( const DataChangedEvent& rDCEvt )
{
ListBox::DataChanged( rDCEvt );
if( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
UpdateLineColors();
}
// ===================================================================
// FontNameBox
// ===================================================================
struct ImplFontNameListData
{
FontInfo maInfo;
USHORT mnType;
ImplFontNameListData( const FontInfo& rInfo,
USHORT nType ) :
maInfo( rInfo ),
mnType( nType )
{}
};
DECLARE_LIST( ImplFontList, ImplFontNameListData* )
// -------------------------------------------------------------------
FontNameBox::FontNameBox( Window* pParent, WinBits nWinStyle ) :
ComboBox( pParent, nWinStyle )
{
InitBitmaps();
mpFontList = NULL;
mbWYSIWYG = FALSE;
mbSymbols = FALSE;
}
// -------------------------------------------------------------------
FontNameBox::FontNameBox( Window* pParent, const ResId& rResId ) :
ComboBox( pParent, rResId )
{
InitBitmaps();
mpFontList = NULL;
mbWYSIWYG = FALSE;
mbSymbols = FALSE;
}
// -------------------------------------------------------------------
FontNameBox::~FontNameBox()
{
ImplDestroyFontList();
}
// -------------------------------------------------------------------
void FontNameBox::DataChanged( const DataChangedEvent& rDCEvt )
{
ComboBox::DataChanged( rDCEvt );
if( rDCEvt.GetType() == DATACHANGED_SETTINGS && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
InitBitmaps();
}
// -------------------------------------------------------------------
void FontNameBox::InitBitmaps( void )
{
BOOL bHC = GetSettings().GetStyleSettings().GetHighContrastMode();
maImagePrinterFont = Image( SvtResId( bHC? RID_IMG_PRINTERFONT_HC : RID_IMG_PRINTERFONT ) );
maImageBitmapFont = Image( SvtResId( bHC? RID_IMG_BITMAPFONT_HC : RID_IMG_BITMAPFONT ) );
maImageScalableFont = Image( SvtResId( bHC? RID_IMG_SCALABLEFONT_HC : RID_IMG_SCALABLEFONT ) );
}
// -------------------------------------------------------------------
void FontNameBox::ImplDestroyFontList()
{
if ( mpFontList )
{
ImplFontNameListData* pInfo = mpFontList->First();
while ( pInfo )
{
delete pInfo;
pInfo = mpFontList->Next();
}
delete mpFontList;
}
}
// -------------------------------------------------------------------
void FontNameBox::Fill( const FontList* pList )
{
// store old text and clear box
XubString aOldText = GetText();
Clear();
ImplDestroyFontList();
mpFontList = new ImplFontList;
// insert fonts
USHORT nFontCount = pList->GetFontNameCount();
for ( USHORT i = 0; i < nFontCount; i++ )
{
const FontInfo& rFontInfo = pList->GetFontName( i );
ULONG nIndex = InsertEntry( rFontInfo.GetName() );
if ( nIndex != LISTBOX_ERROR )
{
USHORT nType = pList->GetFontNameType( i );
ImplFontNameListData* pData = new ImplFontNameListData( rFontInfo, nType );
mpFontList->Insert( pData, nIndex );
}
}
ImplCalcUserItemSize();
// restore text
if ( aOldText.Len() )
SetText( aOldText );
}
// -------------------------------------------------------------------
void FontNameBox::EnableWYSIWYG( BOOL bEnable )
{
if ( bEnable != mbWYSIWYG )
{
mbWYSIWYG = bEnable;
EnableUserDraw( mbWYSIWYG | mbSymbols );
ImplCalcUserItemSize();
}
}
// -------------------------------------------------------------------
void FontNameBox::EnableSymbols( BOOL bEnable )
{
if ( bEnable != mbSymbols )
{
mbSymbols = bEnable;
EnableUserDraw( mbWYSIWYG | mbSymbols );
ImplCalcUserItemSize();
}
}
// -------------------------------------------------------------------
void FontNameBox::ImplCalcUserItemSize()
{
Size aUserItemSz;
if ( mbWYSIWYG && mpFontList )
{
USHORT nMaxLen = 0;
BOOL bSymbolFont = FALSE;
BOOL bStarSymbol = FALSE;
for ( USHORT n = GetEntryCount(); n; )
{
ImplFontNameListData* pData = mpFontList->GetObject( --n );
XubString aFontName = pData->maInfo.GetName();
if ( aFontName.Len() > nMaxLen )
nMaxLen = aFontName.Len();
if ( pData->maInfo.GetCharSet() == RTL_TEXTENCODING_SYMBOL )
bSymbolFont = TRUE;
// starsymbol is a unicode font, but gets WYSIWIG symbols
if( aFontName.EqualsIgnoreCaseAscii( "starsymbol" )
|| aFontName.EqualsIgnoreCaseAscii( "opensymbol" ) )
bSymbolFont = bStarSymbol = TRUE;
}
// guess maximimum width
Size aOneCharSz( GetTextWidth( String( 'X' ) ), GetTextHeight() );
Size aSz( aOneCharSz );
aSz.Width() *= nMaxLen;
// only XX% of width, because ListBox calculates the normal width...
aSz.Width() *= 1;
aSz.Width() /= 10;
if ( bSymbolFont )
{
int nLength = sizeof(aImplSymbolFontText)/sizeof(aImplSymbolFontText[0]) - 1;
int nLength2 = sizeof(aImplStarSymbolText)/sizeof(aImplStarSymbolText[0]) - 1;
if( bStarSymbol && (nLength < nLength2) )
nLength = nLength2;
aSz.Width() += aOneCharSz.Width() * nLength;
}
aSz.Height() *= 14;
aSz.Height() /= 10;
aUserItemSz = aSz;
}
if ( mbSymbols )
{
Size aSz = maImageScalableFont.GetSizePixel();
aUserItemSz.Width() += aSz.Width() + IMGTEXTSPACE;
if ( aSz.Height() > aUserItemSz.Height() )
aUserItemSz.Height() = aSz.Height();
}
SetUserItemSize( aUserItemSz );
}
// -------------------------------------------------------------------
void FontNameBox::UserDraw( const UserDrawEvent& rUDEvt )
{
ImplFontNameListData* pData = mpFontList->GetObject( rUDEvt.GetItemId() );
const FontInfo& rInfo = pData->maInfo;
USHORT nType = pData->mnType;
Point aTopLeft = rUDEvt.GetRect().TopLeft();
long nX = aTopLeft.X();
long nH = rUDEvt.GetRect().GetHeight();
if ( mbSymbols )
{
nX += IMGTEXTSPACE;
Image* pImg = NULL;
if ( (nType & (FONTLIST_FONTNAMETYPE_PRINTER | FONTLIST_FONTNAMETYPE_SCREEN)) == FONTLIST_FONTNAMETYPE_PRINTER )
pImg = &maImagePrinterFont;
else if ( nType & FONTLIST_FONTNAMETYPE_SCALABLE )
pImg = &maImageScalableFont;
else
pImg = &maImageBitmapFont;
if ( pImg )
{
Point aPos( nX, aTopLeft.Y() + (nH-pImg->GetSizePixel().Height())/2 );
rUDEvt.GetDevice()->DrawImage( aPos, *pImg );
}
// X immer um gleiche Breite aendern, auch wenn kein Image ausgegeben.
nX += maImagePrinterFont.GetSizePixel().Width();
}
if ( mbWYSIWYG && mpFontList )
{
nX += IMGTEXTSPACE;
bool bSymbolFont = (rInfo.GetCharSet() == RTL_TEXTENCODING_SYMBOL);
// starsymbol is a unicode font, but cannot display its own name
const bool bOpenSymbol = rInfo.GetName().EqualsIgnoreCaseAscii( "starsymbol" )
|| rInfo.GetName().EqualsIgnoreCaseAscii( "opensymbol" );
bSymbolFont |= bOpenSymbol;
if( bSymbolFont )
{
String aText( rInfo.GetName() );
aText.AppendAscii( " " );
Point aPos( nX, aTopLeft.Y() + (nH-rUDEvt.GetDevice()->GetTextHeight())/2 );
rUDEvt.GetDevice()->DrawText( aPos, aText );
nX += rUDEvt.GetDevice()->GetTextWidth( aText );
}
Color aTextColor = rUDEvt.GetDevice()->GetTextColor();
Font aOldFont( rUDEvt.GetDevice()->GetFont() );
Size aSize( aOldFont.GetSize() );
aSize.Height() += EXTRAFONTSIZE;
Font aFont( rInfo );
aFont.SetSize( aSize );
rUDEvt.GetDevice()->SetFont( aFont );
rUDEvt.GetDevice()->SetTextColor( aTextColor );
FontCharMap aFontCharMap;
bool bHasCharMap = rUDEvt.GetDevice()->GetFontCharMap( aFontCharMap );
String aString;
if( !bSymbolFont )
{
// preview the font name
aString = rInfo.GetName();
// reset font if the name cannot be display in the preview font
if( STRING_LEN != rUDEvt.GetDevice()->HasGlyphs( aFont, aString ) )
rUDEvt.GetDevice()->SetFont( aOldFont );
}
else if( bHasCharMap )
{
// use some sample characters available in the font
sal_Unicode aText[8];
// start just above the PUA used by most symbol fonts
sal_uInt32 cNewChar = 0xFF00;
#ifdef QUARTZ
// on MacOSX there are too many non-presentable symbols above the codepoint 0x0192
if( !bOpenSymbol )
cNewChar = 0x0192;
#endif
const int nMaxCount = sizeof(aText)/sizeof(*aText) - 1;
int nSkip = aFontCharMap.GetCharCount() / nMaxCount;
if( nSkip > 10 )
nSkip = 10;
else if( nSkip <= 0 )
nSkip = 1;
for( int i = 0; i < nMaxCount; ++i )
{
sal_uInt32 cOldChar = cNewChar;
for( int j = nSkip; --j >= 0; )
cNewChar = aFontCharMap.GetPrevChar( cNewChar );
if( cOldChar == cNewChar )
break;
aText[ i ] = static_cast<sal_Unicode>(cNewChar); // TODO: support UCS4 samples
aText[ i+1 ] = 0;
}
aString = String( aText );
}
else
{
const sal_Unicode* pText = aImplSymbolFontText;
if( bOpenSymbol )
pText = aImplStarSymbolText;
aString = String( pText );
}
long nTextHeight = rUDEvt.GetDevice()->GetTextHeight();
Point aPos( nX, aTopLeft.Y() + (nH-nTextHeight)/2 );
rUDEvt.GetDevice()->DrawText( aPos, aString );
rUDEvt.GetDevice()->SetFont( aOldFont );
DrawEntry( rUDEvt, FALSE, FALSE); // draw seperator
}
else
{
DrawEntry( rUDEvt, TRUE, TRUE );
}
}
// ===================================================================
// FontStyleBox
// ===================================================================
FontStyleBox::FontStyleBox( Window* pParent, WinBits nWinStyle ) :
ComboBox( pParent, nWinStyle )
{
}
// -------------------------------------------------------------------
FontStyleBox::FontStyleBox( Window* pParent, const ResId& rResId ) :
ComboBox( pParent, rResId )
{
aLastStyle = GetText();
}
// -------------------------------------------------------------------
FontStyleBox::~FontStyleBox()
{
}
// -------------------------------------------------------------------
void FontStyleBox::Select()
{
// keep text over fill operation
aLastStyle = GetText();
ComboBox::Select();
}
// -------------------------------------------------------------------
void FontStyleBox::LoseFocus()
{
// keep text over fill operation
aLastStyle = GetText();
ComboBox::LoseFocus();
}
// -------------------------------------------------------------------
void FontStyleBox::Modify()
{
CharClass aChrCls( ::comphelper::getProcessServiceFactory(),
GetSettings().GetLocale() );
XubString aStr = GetText();
USHORT nEntryCount = GetEntryCount();
if ( GetEntryPos( aStr ) == COMBOBOX_ENTRY_NOTFOUND )
{
aChrCls.toUpper( aStr );
for ( USHORT i = 0; i < nEntryCount; i++ )
{
XubString aEntryText = GetEntry( i );
aChrCls.toUpper( aEntryText );
if ( aStr == aEntryText )
{
SetText( GetEntry( i ) );
break;
}
}
}
ComboBox::Modify();
}
// -------------------------------------------------------------------
void FontStyleBox::Fill( const XubString& rName, const FontList* pList )
{
// note: this method must call ComboBox::SetText(),
// else aLastStyle will overwritten
// store prior selection position and clear box
XubString aOldText = GetText();
USHORT nPos = GetEntryPos( aOldText );
Clear();
// does a font with this name already exist?
sal_Handle hFontInfo = pList->GetFirstFontInfo( rName );
if ( hFontInfo )
{
XubString aStyleText;
FontWeight eLastWeight = WEIGHT_DONTKNOW;
FontItalic eLastItalic = ITALIC_NONE;
FontWidth eLastWidth = WIDTH_DONTKNOW;
BOOL bNormal = FALSE;
BOOL bItalic = FALSE;
BOOL bBold = FALSE;
BOOL bBoldItalic = FALSE;
BOOL bInsert = FALSE;
FontInfo aInfo;
while ( hFontInfo )
{
aInfo = pList->GetFontInfo( hFontInfo );
FontWeight eWeight = aInfo.GetWeight();
FontItalic eItalic = aInfo.GetItalic();
FontWidth eWidth = aInfo.GetWidthType();
// Only if the attributes are different, we insert the
// Font to avoid double Entries in different languages
if ( (eWeight != eLastWeight) || (eItalic != eLastItalic) ||
(eWidth != eLastWidth) )
{
if ( bInsert )
InsertEntry( aStyleText );
if ( eWeight <= WEIGHT_NORMAL )
{
if ( eItalic != ITALIC_NONE )
bItalic = TRUE;
else
bNormal = TRUE;
}
else
{
if ( eItalic != ITALIC_NONE )
bBoldItalic = TRUE;
else
bBold = TRUE;
}
// For wrong StyleNames we replace this with the correct once
aStyleText = pList->GetStyleName( aInfo );
bInsert = GetEntryPos( aStyleText ) == LISTBOX_ENTRY_NOTFOUND;
if ( !bInsert )
{
aStyleText = pList->GetStyleName( eWeight, eItalic );
bInsert = GetEntryPos( aStyleText ) == LISTBOX_ENTRY_NOTFOUND;
}
eLastWeight = eWeight;
eLastItalic = eItalic;
eLastWidth = eWidth;
}
else
{
if ( bInsert )
{
// If we have two names for the same attributes
// we prefer the translated standard names
const XubString& rAttrStyleText = pList->GetStyleName( eWeight, eItalic );
if ( rAttrStyleText != aStyleText )
{
XubString aTempStyleText = pList->GetStyleName( aInfo );
if ( rAttrStyleText == aTempStyleText )
aStyleText = rAttrStyleText;
bInsert = GetEntryPos( aStyleText ) == LISTBOX_ENTRY_NOTFOUND;
}
}
}
if ( !bItalic && (aStyleText == pList->GetItalicStr()) )
bItalic = TRUE;
else if ( !bBold && (aStyleText == pList->GetBoldStr()) )
bBold = TRUE;
else if ( !bBoldItalic && (aStyleText == pList->GetBoldItalicStr()) )
bBoldItalic = TRUE;
hFontInfo = pList->GetNextFontInfo( hFontInfo );
}
if ( bInsert )
InsertEntry( aStyleText );
// Bestimmte Styles als Nachbildung
if ( bNormal )
{
if ( !bItalic )
InsertEntry( pList->GetItalicStr() );
if ( !bBold )
InsertEntry( pList->GetBoldStr() );
}
if ( !bBoldItalic )
{
if ( bNormal || bItalic || bBold )
InsertEntry( pList->GetBoldItalicStr() );
}
if ( aOldText.Len() )
{
if ( GetEntryPos( aLastStyle ) != LISTBOX_ENTRY_NOTFOUND )
ComboBox::SetText( aLastStyle );
else
{
if ( nPos >= GetEntryCount() )
ComboBox::SetText( GetEntry( 0 ) );
else
ComboBox::SetText( GetEntry( nPos ) );
}
}
}
else
{
// Wenn Font nicht, dann Standard-Styles einfuegen
InsertEntry( pList->GetNormalStr() );
InsertEntry( pList->GetItalicStr() );
InsertEntry( pList->GetBoldStr() );
InsertEntry( pList->GetBoldItalicStr() );
if ( aOldText.Len() )
{
if ( nPos > GetEntryCount() )
ComboBox::SetText( GetEntry( 0 ) );
else
ComboBox::SetText( GetEntry( nPos ) );
}
}
}
// ===================================================================
// FontSizeBox
// ===================================================================
FontSizeBox::FontSizeBox( Window* pParent, WinBits nWinSize ) :
MetricBox( pParent, nWinSize )
{
ImplInit();
}
// -----------------------------------------------------------------------
FontSizeBox::FontSizeBox( Window* pParent, const ResId& rResId ) :
MetricBox( pParent, rResId )
{
ImplInit();
}
// -----------------------------------------------------------------------
FontSizeBox::~FontSizeBox()
{
}
// -----------------------------------------------------------------------
void FontSizeBox::ImplInit()
{
EnableAutocomplete( FALSE );
bRelativeMode = FALSE;
bPtRelative = FALSE;
bRelative = FALSE;
bStdSize = FALSE;
pFontList = NULL;
SetShowTrailingZeros( FALSE );
SetDecimalDigits( 1 );
SetMin( 20 );
SetMax( 9999 );
SetProminentEntryType( PROMINENT_MIDDLE );
}
// -----------------------------------------------------------------------
void FontSizeBox::Reformat()
{
FontSizeNames aFontSizeNames( GetSettings().GetUILanguage() );
if ( !bRelativeMode || !aFontSizeNames.IsEmpty() )
{
long nNewValue = aFontSizeNames.Name2Size( GetText() );
if ( nNewValue)
{
mnLastValue = nNewValue;
return;
}
}
MetricBox::Reformat();
}
// -----------------------------------------------------------------------
void FontSizeBox::Modify()
{
MetricBox::Modify();
if ( bRelativeMode )
{
XubString aStr = GetText();
aStr.EraseLeadingChars();
BOOL bNewMode = bRelative;
BOOL bOldPtRelMode = bPtRelative;
if ( bRelative )
{
bPtRelative = FALSE;
const xub_Unicode* pStr = aStr.GetBuffer();
while ( *pStr )
{
if ( ((*pStr < '0') || (*pStr > '9')) && (*pStr != '%') )
{
if ( ('-' == *pStr || '+' == *pStr) && !bPtRelative )
bPtRelative = TRUE;
else if ( bPtRelative && 'p' == *pStr && 't' == *++pStr )
;
else
{
bNewMode = FALSE;
break;
}
}
pStr++;
}
}
else
{
if ( STRING_NOTFOUND != aStr.Search( '%' ) )
{
bNewMode = TRUE;
bPtRelative = FALSE;
}
if ( '-' == aStr.GetChar( 0 ) || '+' == aStr.GetChar( 0 ) )
{
bNewMode = TRUE;
bPtRelative = TRUE;
}
}
if ( bNewMode != bRelative || bPtRelative != bOldPtRelMode )
SetRelative( bNewMode );
}
}
// -----------------------------------------------------------------------
void FontSizeBox::Fill( const FontInfo* pInfo, const FontList* pList )
{
// remember for relative mode
pFontList = pList;
// no font sizes need to be set for relative mode
if ( bRelative )
return;
// query font sizes
const long* pTempAry;
const long* pAry = 0;
if( pInfo )
{
aFontInfo = *pInfo;
pAry = pList->GetSizeAry( *pInfo );
}
else
{
pAry = pList->GetStdSizeAry();
}
// first insert font size names (for simplified/traditional chinese)
FontSizeNames aFontSizeNames( GetSettings().GetUILanguage() );
if ( pAry == pList->GetStdSizeAry() )
{
// for standard sizes we don't need to bother
if ( bStdSize && GetEntryCount() && aFontSizeNames.IsEmpty() )
return;
bStdSize = TRUE;
}
else
bStdSize = FALSE;
Selection aSelection = GetSelection();
XubString aStr = GetText();
Clear();
USHORT nPos = 0;
if ( !aFontSizeNames.IsEmpty() )
{
if ( pAry == pList->GetStdSizeAry() )
{
// for scalable fonts all font size names
ULONG nCount = aFontSizeNames.Count();
for( ULONG i = 0; i < nCount; i++ )
{
String aSizeName = aFontSizeNames.GetIndexName( i );
long nSize = aFontSizeNames.GetIndexSize( i );
ComboBox::InsertEntry( aSizeName, nPos );
ComboBox::SetEntryData( nPos, (void*)(-nSize) ); // mark as special
nPos++;
}
}
else
{
// for fixed size fonts only selectable font size names
pTempAry = pAry;
while ( *pTempAry )
{
String aSizeName = aFontSizeNames.Size2Name( *pTempAry );
if ( aSizeName.Len() )
{
ComboBox::InsertEntry( aSizeName, nPos );
ComboBox::SetEntryData( nPos, (void*)(-(*pTempAry)) ); // mark as special
nPos++;
}
pTempAry++;
}
}
}
// then insert numerical font size values
pTempAry = pAry;
while ( *pTempAry )
{
InsertValue( *pTempAry, FUNIT_NONE, nPos );
ComboBox::SetEntryData( nPos, (void*)(*pTempAry) );
nPos++;
pTempAry++;
}
SetText( aStr );
SetSelection( aSelection );
}
// -----------------------------------------------------------------------
void FontSizeBox::EnableRelativeMode( USHORT nMin, USHORT nMax, USHORT nStep )
{
bRelativeMode = TRUE;
nRelMin = nMin;
nRelMax = nMax;
nRelStep = nStep;
SetUnit( FUNIT_POINT );
}
// -----------------------------------------------------------------------
void FontSizeBox::EnablePtRelativeMode( short nMin, short nMax, short nStep )
{
bRelativeMode = TRUE;
nPtRelMin = nMin;
nPtRelMax = nMax;
nPtRelStep = nStep;
SetUnit( FUNIT_POINT );
}
// -----------------------------------------------------------------------
void FontSizeBox::SetRelative( BOOL bNewRelative )
{
if ( bRelativeMode )
{
Selection aSelection = GetSelection();
XubString aStr = GetText();
aStr.EraseLeadingChars();
if ( bNewRelative )
{
bRelative = TRUE;
bStdSize = FALSE;
if ( bPtRelative )
{
SetDecimalDigits( 1 );
SetMin( nPtRelMin );
SetMax( nPtRelMax );
SetUnit( FUNIT_POINT );
Clear();
short i = nPtRelMin, n = 0;
// JP 30.06.98: more than 100 values are not useful
while ( i <= nPtRelMax && n++ < 100 )
{
InsertValue( i );
i = i + nPtRelStep;
}
}
else
{
SetDecimalDigits( 0 );
SetMin( nRelMin );
SetMax( nRelMax );
SetCustomUnitText( '%' );
SetUnit( FUNIT_CUSTOM );
Clear();
USHORT i = nRelMin;
while ( i <= nRelMax )
{
InsertValue( i );
i = i + nRelStep;
}
}
}
else
{
bRelative = bPtRelative = FALSE;
SetDecimalDigits( 1 );
SetMin( 20 );
SetMax( 9999 );
SetUnit( FUNIT_POINT );
if ( pFontList )
Fill( &aFontInfo, pFontList );
}
SetText( aStr );
SetSelection( aSelection );
}
}
// -----------------------------------------------------------------------
XubString FontSizeBox::CreateFieldText( sal_Int64 nValue ) const
{
XubString sRet( MetricBox::CreateFieldText( nValue ) );
if ( bRelativeMode && bPtRelative && (0 <= nValue) && sRet.Len() )
sRet.Insert( '+', 0 );
return sRet;
}
// -----------------------------------------------------------------------
void FontSizeBox::SetValue( sal_Int64 nNewValue, FieldUnit eInUnit )
{
if ( !bRelative )
{
sal_Int64 nTempValue = MetricField::ConvertValue( nNewValue, GetBaseValue(), GetDecimalDigits(), eInUnit, GetUnit() );
FontSizeNames aFontSizeNames( GetSettings().GetUILanguage() );
// conversion loses precision; however font sizes should
// never have a problem with that
String aName = aFontSizeNames.Size2Name( static_cast<long>(nTempValue) );
if ( aName.Len() && (GetEntryPos( aName ) != LISTBOX_ENTRY_NOTFOUND) )
{
mnLastValue = nTempValue;
SetText( aName );
mnFieldValue = mnLastValue;
SetEmptyFieldValueData( FALSE );
return;
}
}
MetricBox::SetValue( nNewValue, eInUnit );
}
// -----------------------------------------------------------------------
void FontSizeBox::SetValue( sal_Int64 nNewValue )
{
SetValue( nNewValue, FUNIT_NONE );
}
// -----------------------------------------------------------------------
sal_Int64 FontSizeBox::GetValue( USHORT nPos, FieldUnit eOutUnit ) const
{
if ( !bRelative )
{
sal_Int64 nComboVal = static_cast<sal_Int64>(reinterpret_cast<long>(ComboBox::GetEntryData( nPos )));
if ( nComboVal < 0 ) // marked as special?
{
return MetricField::ConvertValue( -nComboVal, mnBaseValue, GetDecimalDigits(),
meUnit, eOutUnit );
}
}
// do normal font size processing
sal_Int64 nRetValue = MetricBox::GetValue( nPos, eOutUnit );
return nRetValue;
}
// -----------------------------------------------------------------------
sal_Int64 FontSizeBox::GetValue( FieldUnit eOutUnit ) const
{
if ( !bRelative )
{
FontSizeNames aFontSizeNames( GetSettings().GetUILanguage() );
sal_Int64 nValue = aFontSizeNames.Name2Size( GetText() );
if ( nValue)
return MetricField::ConvertValue( nValue, GetBaseValue(), GetDecimalDigits(), GetUnit(), eOutUnit );
}
return MetricBox::GetValue( eOutUnit );
}
// -----------------------------------------------------------------------
sal_Int64 FontSizeBox::GetValue() const
{
// implementation not inline, because it is a virtual function
return GetValue( FUNIT_NONE );
}
// -----------------------------------------------------------------------
void FontSizeBox::SetUserValue( sal_Int64 nNewValue, FieldUnit eInUnit )
{
if ( !bRelative )
{
sal_Int64 nTempValue = MetricField::ConvertValue( nNewValue, GetBaseValue(), GetDecimalDigits(), eInUnit, GetUnit() );
FontSizeNames aFontSizeNames( GetSettings().GetUILanguage() );
// conversion loses precision
// however font sizes should never have a problem with that
String aName = aFontSizeNames.Size2Name( static_cast<long>(nTempValue) );
if ( aName.Len() && (GetEntryPos( aName ) != LISTBOX_ENTRY_NOTFOUND) )
{
mnLastValue = nTempValue;
SetText( aName );
return;
}
}
MetricBox::SetUserValue( nNewValue, eInUnit );
}
|