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
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
|
/* -*- 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 .
*/
// General info:
// http://msdn.microsoft.com/en-us/library/windows/desktop/hh270423%28v=vs.85%29.aspx
// http://msdn.microsoft.com/en-us/library/windows/desktop/bb773178%28v=vs.85%29.aspx
// Useful tool to explore the themes & their rendering:
// http://privat.rejbrand.se/UxExplore.exe
// (found at http://stackoverflow.com/questions/4009701/windows-visual-themes-gallery-of-parts-and-states/4009712#4009712)
// Theme subclasses:
// http://msdn.microsoft.com/en-us/library/windows/desktop/bb773218%28v=vs.85%29.aspx
// Drawing in non-client area (general DWM-related info):
// http://msdn.microsoft.com/en-us/library/windows/desktop/bb688195%28v=vs.85%29.aspx
#include "rtl/ustring.h"
#include "osl/module.h"
#include <opengl/win/gdiimpl.hxx>
#include "vcl/svapp.hxx"
#include <vcl/settings.hxx>
#include "win/svsys.h"
#include "win/salgdi.h"
#include "win/saldata.hxx"
#include "uxtheme.h"
#include "vssym32.h"
#include <map>
#include <string>
using namespace std;
typedef map< wstring, HTHEME > ThemeMap;
static ThemeMap aThemeMap;
/****************************************************
wrap visual styles API to avoid linking against it
it is not available on all Windows platforms
*****************************************************/
class VisualStylesAPI
{
private:
typedef HTHEME (WINAPI * OpenThemeData_Proc_T) ( HWND hwnd, LPCWSTR pszClassList );
typedef HRESULT (WINAPI * CloseThemeData_Proc_T) ( HTHEME hTheme );
typedef HRESULT (WINAPI * GetThemeBackgroundContentRect_Proc_T) ( HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT *pBoundingRect, RECT *pContentRect );
typedef HRESULT (WINAPI * DrawThemeBackground_Proc_T) ( HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT *pRect, const RECT *pClipRect );
typedef HRESULT (WINAPI * DrawThemeText_Proc_T) ( HTHEME hTheme, HDC hdc, int iPartId, int iStateId, LPCWSTR pszText, int iCharCount, DWORD dwTextFlags, DWORD dwTextFlags2, const RECT *pRect );
typedef HRESULT (WINAPI * GetThemePartSize_Proc_T) ( HTHEME hTheme, HDC hdc, int iPartId, int iStateId, RECT *prc, THEMESIZE eSize, SIZE *psz );
typedef BOOL (WINAPI * IsThemeActive_Proc_T) ( void );
OpenThemeData_Proc_T lpfnOpenThemeData;
CloseThemeData_Proc_T lpfnCloseThemeData;
GetThemeBackgroundContentRect_Proc_T lpfnGetThemeBackgroundContentRect;
DrawThemeBackground_Proc_T lpfnDrawThemeBackground;
DrawThemeText_Proc_T lpfnDrawThemeText;
GetThemePartSize_Proc_T lpfnGetThemePartSize;
IsThemeActive_Proc_T lpfnIsThemeActive;
oslModule mhModule;
public:
VisualStylesAPI();
~VisualStylesAPI();
bool IsAvailable() { return (mhModule != NULL); }
HTHEME OpenThemeData( HWND hwnd, LPCWSTR pszClassList );
HRESULT CloseThemeData( HTHEME hTheme );
HRESULT GetThemeBackgroundContentRect( HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT *pBoundingRect, RECT *pContentRect );
HRESULT DrawThemeBackground( HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT *pRect, const RECT *pClipRect );
HRESULT DrawThemeText( HTHEME hTheme, HDC hdc, int iPartId, int iStateId, LPCWSTR pszText, int iCharCount, DWORD dwTextFlags, DWORD dwTextFlags2, const RECT *pRect );
HRESULT GetThemePartSize( HTHEME hTheme, HDC hdc, int iPartId, int iStateId, RECT *prc, THEMESIZE eSize, SIZE *psz );
BOOL IsThemeActive( void );
};
static VisualStylesAPI vsAPI;
VisualStylesAPI::VisualStylesAPI()
: lpfnOpenThemeData( NULL ),
lpfnCloseThemeData( NULL ),
lpfnGetThemeBackgroundContentRect( NULL ),
lpfnDrawThemeBackground( NULL ),
lpfnDrawThemeText( NULL ),
lpfnGetThemePartSize( NULL ),
lpfnIsThemeActive( NULL )
{
OUString aLibraryName( "uxtheme.dll" );
mhModule = osl_loadModule( aLibraryName.pData, SAL_LOADMODULE_DEFAULT );
if ( mhModule )
{
lpfnOpenThemeData = (OpenThemeData_Proc_T)osl_getAsciiFunctionSymbol( mhModule, "OpenThemeData" );
lpfnCloseThemeData = (CloseThemeData_Proc_T)osl_getAsciiFunctionSymbol( mhModule, "CloseThemeData" );
lpfnGetThemeBackgroundContentRect = (GetThemeBackgroundContentRect_Proc_T)osl_getAsciiFunctionSymbol( mhModule, "GetThemeBackgroundContentRect" );
lpfnDrawThemeBackground = (DrawThemeBackground_Proc_T)osl_getAsciiFunctionSymbol( mhModule, "DrawThemeBackground" );
lpfnDrawThemeText = (DrawThemeText_Proc_T)osl_getAsciiFunctionSymbol( mhModule, "DrawThemeText" );
lpfnGetThemePartSize = (GetThemePartSize_Proc_T)osl_getAsciiFunctionSymbol( mhModule, "GetThemePartSize" );
lpfnIsThemeActive = (IsThemeActive_Proc_T)osl_getAsciiFunctionSymbol( mhModule, "IsThemeActive" );
}
}
VisualStylesAPI::~VisualStylesAPI()
{
if( mhModule )
osl_unloadModule( mhModule );
}
HTHEME VisualStylesAPI::OpenThemeData( HWND hwnd, LPCWSTR pszClassList )
{
if(lpfnOpenThemeData)
return (*lpfnOpenThemeData) (hwnd, pszClassList);
else
return NULL;
}
HRESULT VisualStylesAPI::CloseThemeData( HTHEME hTheme )
{
if(lpfnCloseThemeData)
return (*lpfnCloseThemeData) (hTheme);
else
return S_FALSE;
}
HRESULT VisualStylesAPI::GetThemeBackgroundContentRect( HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT *pBoundingRect, RECT *pContentRect )
{
if(lpfnGetThemeBackgroundContentRect)
return (*lpfnGetThemeBackgroundContentRect) ( hTheme, hdc, iPartId, iStateId, pBoundingRect, pContentRect );
else
return S_FALSE;
}
HRESULT VisualStylesAPI::DrawThemeBackground( HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT *pRect, const RECT *pClipRect )
{
if(lpfnDrawThemeBackground)
return (*lpfnDrawThemeBackground) (hTheme, hdc, iPartId, iStateId, pRect, pClipRect);
else
return S_FALSE;
}
HRESULT VisualStylesAPI::DrawThemeText( HTHEME hTheme, HDC hdc, int iPartId, int iStateId, LPCWSTR pszText, int iCharCount, DWORD dwTextFlags, DWORD dwTextFlags2, const RECT *pRect )
{
if(lpfnDrawThemeText)
return (*lpfnDrawThemeText) (hTheme, hdc, iPartId, iStateId, pszText, iCharCount, dwTextFlags, dwTextFlags2, pRect);
else
return S_FALSE;
}
HRESULT VisualStylesAPI::GetThemePartSize( HTHEME hTheme, HDC hdc, int iPartId, int iStateId, RECT *prc, THEMESIZE eSize, SIZE *psz )
{
if(lpfnGetThemePartSize)
return (*lpfnGetThemePartSize) (hTheme, hdc, iPartId, iStateId, prc, eSize, psz);
else
return S_FALSE;
}
BOOL VisualStylesAPI::IsThemeActive( void )
{
if(lpfnIsThemeActive)
return (*lpfnIsThemeActive) ();
else
return FALSE;
}
/*********************************************************
* Initialize XP theming and local stuff
*********************************************************/
void SalData::initNWF( void )
{
ImplSVData* pSVData = ImplGetSVData();
// the menu bar and the top docking area should have a common background (gradient)
pSVData->maNWFData.mbMenuBarDockingAreaCommonBG = true;
}
// *********************************************************
// * Release theming handles
// ********************************************************
void SalData::deInitNWF( void )
{
ThemeMap::iterator iter = aThemeMap.begin();
while( iter != aThemeMap.end() )
{
vsAPI.CloseThemeData(iter->second);
++iter;
}
aThemeMap.clear();
if( maDwmLib )
osl_unloadModule( maDwmLib );
}
static HTHEME getThemeHandle( HWND hWnd, LPCWSTR name )
{
if( GetSalData()->mbThemeChanged )
{
// throw away invalid theme handles
GetSalData()->deInitNWF();
GetSalData()->mbThemeChanged = FALSE;
}
ThemeMap::iterator iter;
if( (iter = aThemeMap.find( name )) != aThemeMap.end() )
return iter->second;
// theme not found -> add it to map
HTHEME hTheme = vsAPI.OpenThemeData( hWnd, name );
if( hTheme != NULL )
aThemeMap[name] = hTheme;
return hTheme;
}
/*
* IsNativeControlSupported()
*
* Returns TRUE if the platform supports native
* drawing of the control defined by nPart
*/
bool WinSalGraphics::IsNativeControlSupported( ControlType nType, ControlPart nPart )
{
HTHEME hTheme = NULL;
switch( nType )
{
case CTRL_PUSHBUTTON:
case CTRL_RADIOBUTTON:
case CTRL_CHECKBOX:
if( nPart == PART_ENTIRE_CONTROL )
hTheme = getThemeHandle( mhWnd, L"Button");
break;
case CTRL_SCROLLBAR:
if( nPart == PART_DRAW_BACKGROUND_HORZ || nPart == PART_DRAW_BACKGROUND_VERT )
return FALSE; // no background painting needed
if( nPart == PART_ENTIRE_CONTROL )
hTheme = getThemeHandle( mhWnd, L"Scrollbar");
break;
case CTRL_COMBOBOX:
if( nPart == HAS_BACKGROUND_TEXTURE )
return FALSE; // we do not paint the inner part (ie the selection background/focus indication)
if( nPart == PART_ENTIRE_CONTROL )
hTheme = getThemeHandle( mhWnd, L"Edit");
else if( nPart == PART_BUTTON_DOWN )
hTheme = getThemeHandle( mhWnd, L"Combobox");
break;
case CTRL_SPINBOX:
if( nPart == PART_ENTIRE_CONTROL )
hTheme = getThemeHandle( mhWnd, L"Edit");
else if( nPart == PART_ALL_BUTTONS ||
nPart == PART_BUTTON_UP || nPart == PART_BUTTON_DOWN ||
nPart == PART_BUTTON_LEFT|| nPart == PART_BUTTON_RIGHT )
hTheme = getThemeHandle( mhWnd, L"Spin");
break;
case CTRL_SPINBUTTONS:
if( nPart == PART_ENTIRE_CONTROL || nPart == PART_ALL_BUTTONS )
hTheme = getThemeHandle( mhWnd, L"Spin");
break;
case CTRL_EDITBOX:
case CTRL_MULTILINE_EDITBOX:
if( nPart == HAS_BACKGROUND_TEXTURE )
return FALSE; // we do not paint the inner part (ie the selection background/focus indication)
//return TRUE;
if( nPart == PART_ENTIRE_CONTROL )
hTheme = getThemeHandle( mhWnd, L"Edit");
break;
case CTRL_LISTBOX:
if( nPart == HAS_BACKGROUND_TEXTURE )
return FALSE; // we do not paint the inner part (ie the selection background/focus indication)
if( nPart == PART_ENTIRE_CONTROL || nPart == PART_WINDOW )
hTheme = getThemeHandle( mhWnd, L"Listview");
else if( nPart == PART_BUTTON_DOWN )
hTheme = getThemeHandle( mhWnd, L"Combobox");
break;
case CTRL_TAB_PANE:
case CTRL_TAB_BODY:
case CTRL_TAB_ITEM:
if( nPart == PART_ENTIRE_CONTROL )
hTheme = getThemeHandle( mhWnd, L"Tab");
break;
case CTRL_TOOLBAR:
if( nPart == PART_ENTIRE_CONTROL || nPart == PART_BUTTON )
hTheme = getThemeHandle( mhWnd, L"Toolbar");
else
// use rebar theme for grip and background
hTheme = getThemeHandle( mhWnd, L"Rebar");
break;
case CTRL_MENUBAR:
if( nPart == PART_ENTIRE_CONTROL )
hTheme = getThemeHandle( mhWnd, L"Rebar");
else if( GetSalData()->mbThemeMenuSupport )
{
if( nPart == PART_MENU_ITEM )
hTheme = getThemeHandle( mhWnd, L"Menu" );
}
break;
case CTRL_MENU_POPUP:
if( GetSalData()->mbThemeMenuSupport )
{
if( nPart == PART_ENTIRE_CONTROL ||
nPart == PART_MENU_ITEM ||
nPart == PART_MENU_ITEM_CHECK_MARK ||
nPart == PART_MENU_ITEM_RADIO_MARK ||
nPart == PART_MENU_SEPARATOR )
hTheme = getThemeHandle( mhWnd, L"Menu" );
}
break;
case CTRL_PROGRESS:
if( nPart == PART_ENTIRE_CONTROL )
hTheme = getThemeHandle( mhWnd, L"Progress");
break;
case CTRL_SLIDER:
if( nPart == PART_TRACK_HORZ_AREA || nPart == PART_TRACK_VERT_AREA )
hTheme = getThemeHandle( mhWnd, L"Trackbar" );
break;
case CTRL_LISTNODE:
if( nPart == PART_ENTIRE_CONTROL )
hTheme = getThemeHandle( mhWnd, L"TreeView" );
break;
default:
hTheme = NULL;
break;
}
return (hTheme != NULL);
}
/*
* HitTestNativeControl()
*
* If the return value is TRUE, bIsInside contains information whether
* aPos was or was not inside the native widget specified by the
* nType/nPart combination.
*/
bool WinSalGraphics::hitTestNativeControl( ControlType,
ControlPart,
const Rectangle&,
const Point&,
bool& )
{
return FALSE;
}
bool ImplDrawTheme( HTHEME hTheme, HDC hDC, int iPart, int iState, RECT rc, const OUString& aStr)
{
HRESULT hr = vsAPI.DrawThemeBackground( hTheme, hDC, iPart, iState, &rc, 0);
if( aStr.getLength() )
{
RECT rcContent;
hr = vsAPI.GetThemeBackgroundContentRect( hTheme, hDC, iPart, iState, &rc, &rcContent);
hr = vsAPI.DrawThemeText( hTheme, hDC, iPart, iState,
reinterpret_cast<LPCWSTR>(aStr.getStr()), -1,
DT_CENTER | DT_VCENTER | DT_SINGLELINE,
0, &rcContent);
}
return (hr == S_OK);
}
Rectangle ImplGetThemeRect( HTHEME hTheme, HDC hDC, int iPart, int iState, const Rectangle& /* aRect */, THEMESIZE eTS = TS_TRUE )
{
SIZE aSz;
HRESULT hr = vsAPI.GetThemePartSize( hTheme, hDC, iPart, iState, NULL, eTS, &aSz ); // TS_TRUE returns optimal size
if( hr == S_OK )
return Rectangle( 0, 0, aSz.cx, aSz.cy );
else
return Rectangle();
}
// Helper functions
void ImplConvertSpinbuttonValues( int nControlPart, const ControlState& rState, const Rectangle& rRect,
int* pLunaPart, int *pLunaState, RECT *pRect )
{
if( nControlPart == PART_BUTTON_DOWN )
{
*pLunaPart = SPNP_DOWN;
if( rState & ControlState::PRESSED )
*pLunaState = DNS_PRESSED;
else if( !(rState & ControlState::ENABLED) )
*pLunaState = DNS_DISABLED;
else if( rState & ControlState::ROLLOVER )
*pLunaState = DNS_HOT;
else
*pLunaState = DNS_NORMAL;
}
if( nControlPart == PART_BUTTON_UP )
{
*pLunaPart = SPNP_UP;
if( rState & ControlState::PRESSED )
*pLunaState = UPS_PRESSED;
else if( !(rState & ControlState::ENABLED) )
*pLunaState = UPS_DISABLED;
else if( rState & ControlState::ROLLOVER )
*pLunaState = UPS_HOT;
else
*pLunaState = UPS_NORMAL;
}
if( nControlPart == PART_BUTTON_RIGHT )
{
*pLunaPart = SPNP_UPHORZ;
if( rState & ControlState::PRESSED )
*pLunaState = DNHZS_PRESSED;
else if( !(rState & ControlState::ENABLED) )
*pLunaState = DNHZS_DISABLED;
else if( rState & ControlState::ROLLOVER )
*pLunaState = DNHZS_HOT;
else
*pLunaState = DNHZS_NORMAL;
}
if( nControlPart == PART_BUTTON_LEFT )
{
*pLunaPart = SPNP_DOWNHORZ;
if( rState & ControlState::PRESSED )
*pLunaState = UPHZS_PRESSED;
else if( !(rState & ControlState::ENABLED) )
*pLunaState = UPHZS_DISABLED;
else if( rState & ControlState::ROLLOVER )
*pLunaState = UPHZS_HOT;
else
*pLunaState = UPHZS_NORMAL;
}
pRect->left = rRect.Left();
pRect->right = rRect.Right()+1;
pRect->top = rRect.Top();
pRect->bottom = rRect.Bottom()+1;
}
/// Draw an own toolbar style on Windows Vista or later, looks better there
static void impl_drawAeroToolbar( HDC hDC, RECT rc, bool bHorizontal )
{
if ( rc.top == 0 && bHorizontal )
{
const long GRADIENT_HEIGHT = 32;
long gradient_break = rc.top;
long gradient_bottom = rc.bottom - 1;
GRADIENT_RECT g_rect[1] = { { 0, 1 } };
// very slow gradient at the top (if we have space for that)
if ( gradient_bottom - rc.top > GRADIENT_HEIGHT )
{
gradient_break = gradient_bottom - GRADIENT_HEIGHT;
TRIVERTEX vert[2] = {
{ rc.left, rc.top, 0xff00, 0xff00, 0xff00, 0xff00 },
{ rc.right, gradient_break, 0xfa00, 0xfa00, 0xfa00, 0xff00 },
};
GradientFill( hDC, vert, 2, g_rect, 1, GRADIENT_FILL_RECT_V );
}
// gradient at the bottom
TRIVERTEX vert[2] = {
{ rc.left, gradient_break, 0xfa00, 0xfa00, 0xfa00, 0xff00 },
{ rc.right, gradient_bottom, 0xf000, 0xf000, 0xf000, 0xff00 }
};
GradientFill( hDC, vert, 2, g_rect, 1, GRADIENT_FILL_RECT_V );
// and a darker horizontal line under that
HPEN hpen = CreatePen( PS_SOLID, 1, RGB( 0xb0, 0xb0, 0xb0 ) );
SelectObject( hDC, hpen );
MoveToEx( hDC, rc.left, gradient_bottom, NULL );
LineTo( hDC, rc.right, gradient_bottom );
DeleteObject( hpen );
}
else
{
HBRUSH hbrush = CreateSolidBrush( RGB( 0xf0, 0xf0, 0xf0 ) );
FillRect( hDC, &rc, hbrush );
DeleteObject( hbrush );
// darker line to distinguish the toolbar and viewshell
// it is drawn only for the horizontal toolbars; it did not look well
// when done for the vertical ones too
if ( bHorizontal )
{
long from_x, from_y, to_x, to_y;
from_x = rc.left;
to_x = rc.right;
from_y = to_y = rc.top;
HPEN hpen = CreatePen( PS_SOLID, 1, RGB( 0xb0, 0xb0, 0xb0 ) );
SelectObject( hDC, hpen );
MoveToEx( hDC, from_x, from_y, NULL );
LineTo( hDC, to_x, to_y );
DeleteObject( hpen );
}
}
}
bool ImplDrawNativeControl( HDC hDC, HTHEME hTheme, RECT rc,
ControlType nType,
ControlPart nPart,
ControlState nState,
const ImplControlValue& aValue,
OUString aCaption )
{
// a listbox dropdown is actually a combobox dropdown
if( nType == CTRL_LISTBOX )
if( nPart == PART_BUTTON_DOWN )
nType = CTRL_COMBOBOX;
// draw entire combobox as a large edit box
if( nType == CTRL_COMBOBOX )
if( nPart == PART_ENTIRE_CONTROL )
nType = CTRL_EDITBOX;
// draw entire spinbox as a large edit box
if( nType == CTRL_SPINBOX )
if( nPart == PART_ENTIRE_CONTROL )
nType = CTRL_EDITBOX;
int iPart(0), iState(0);
if( nType == CTRL_SCROLLBAR )
{
HRESULT hr;
if( nPart == PART_BUTTON_UP )
{
iPart = SBP_ARROWBTN;
if( nState & ControlState::PRESSED )
iState = ABS_UPPRESSED;
else if( !(nState & ControlState::ENABLED) )
iState = ABS_UPDISABLED;
else if( nState & ControlState::ROLLOVER )
iState = ABS_UPHOT;
else
iState = ABS_UPNORMAL;
hr = vsAPI.DrawThemeBackground( hTheme, hDC, iPart, iState, &rc, 0);
return (hr == S_OK);
}
if( nPart == PART_BUTTON_DOWN )
{
iPart = SBP_ARROWBTN;
if( nState & ControlState::PRESSED )
iState = ABS_DOWNPRESSED;
else if( !(nState & ControlState::ENABLED) )
iState = ABS_DOWNDISABLED;
else if( nState & ControlState::ROLLOVER )
iState = ABS_DOWNHOT;
else
iState = ABS_DOWNNORMAL;
hr = vsAPI.DrawThemeBackground( hTheme, hDC, iPart, iState, &rc, 0);
return (hr == S_OK);
}
if( nPart == PART_BUTTON_LEFT )
{
iPart = SBP_ARROWBTN;
if( nState & ControlState::PRESSED )
iState = ABS_LEFTPRESSED;
else if( !(nState & ControlState::ENABLED) )
iState = ABS_LEFTDISABLED;
else if( nState & ControlState::ROLLOVER )
iState = ABS_LEFTHOT;
else
iState = ABS_LEFTNORMAL;
hr = vsAPI.DrawThemeBackground( hTheme, hDC, iPart, iState, &rc, 0);
return (hr == S_OK);
}
if( nPart == PART_BUTTON_RIGHT )
{
iPart = SBP_ARROWBTN;
if( nState & ControlState::PRESSED )
iState = ABS_RIGHTPRESSED;
else if( !(nState & ControlState::ENABLED) )
iState = ABS_RIGHTDISABLED;
else if( nState & ControlState::ROLLOVER )
iState = ABS_RIGHTHOT;
else
iState = ABS_RIGHTNORMAL;
hr = vsAPI.DrawThemeBackground( hTheme, hDC, iPart, iState, &rc, 0);
return (hr == S_OK);
}
if( nPart == PART_THUMB_HORZ || nPart == PART_THUMB_VERT )
{
iPart = (nPart == PART_THUMB_HORZ) ? SBP_THUMBBTNHORZ : SBP_THUMBBTNVERT;
if( nState & ControlState::PRESSED )
iState = SCRBS_PRESSED;
else if( !(nState & ControlState::ENABLED) )
iState = SCRBS_DISABLED;
else if( nState & ControlState::ROLLOVER )
iState = SCRBS_HOT;
else
iState = SCRBS_NORMAL;
SIZE sz;
vsAPI.GetThemePartSize(hTheme, hDC, iPart, iState, NULL, TS_MIN, &sz);
vsAPI.GetThemePartSize(hTheme, hDC, iPart, iState, NULL, TS_TRUE, &sz);
vsAPI.GetThemePartSize(hTheme, hDC, iPart, iState, NULL, TS_DRAW, &sz);
hr = vsAPI.DrawThemeBackground( hTheme, hDC, iPart, iState, &rc, 0);
// paint gripper on thumb if enough space
if( ( (nPart == PART_THUMB_VERT) && (rc.bottom-rc.top > 12) ) ||
( (nPart == PART_THUMB_HORZ) && (rc.right-rc.left > 12) ) )
{
iPart = (nPart == PART_THUMB_HORZ) ? SBP_GRIPPERHORZ : SBP_GRIPPERVERT;
iState = 0;
vsAPI.DrawThemeBackground( hTheme, hDC, iPart, iState, &rc, 0);
}
return (hr == S_OK);
}
if( nPart == PART_TRACK_HORZ_LEFT || nPart == PART_TRACK_HORZ_RIGHT || nPart == PART_TRACK_VERT_UPPER || nPart == PART_TRACK_VERT_LOWER )
{
switch( nPart )
{
case PART_TRACK_HORZ_LEFT: iPart = SBP_UPPERTRACKHORZ; break;
case PART_TRACK_HORZ_RIGHT: iPart = SBP_LOWERTRACKHORZ; break;
case PART_TRACK_VERT_UPPER: iPart = SBP_UPPERTRACKVERT; break;
case PART_TRACK_VERT_LOWER: iPart = SBP_LOWERTRACKVERT; break;
}
if( nState & ControlState::PRESSED )
iState = SCRBS_PRESSED;
else if( !(nState & ControlState::ENABLED) )
iState = SCRBS_DISABLED;
else if( nState & ControlState::ROLLOVER )
iState = SCRBS_HOT;
else
iState = SCRBS_NORMAL;
hr = vsAPI.DrawThemeBackground( hTheme, hDC, iPart, iState, &rc, 0);
return (hr == S_OK);
}
}
if( nType == CTRL_SPINBUTTONS && nPart == PART_ALL_BUTTONS )
{
if( aValue.getType() == CTRL_SPINBUTTONS )
{
const SpinbuttonValue* pValue = (aValue.getType() == CTRL_SPINBUTTONS) ? static_cast<const SpinbuttonValue*>(&aValue) : NULL;
RECT rect;
ImplConvertSpinbuttonValues( pValue->mnUpperPart, pValue->mnUpperState, pValue->maUpperRect, &iPart, &iState, &rect );
bool bOk = ImplDrawTheme( hTheme, hDC, iPart, iState, rect, aCaption);
if( bOk )
{
ImplConvertSpinbuttonValues( pValue->mnLowerPart, pValue->mnLowerState, pValue->maLowerRect, &iPart, &iState, &rect );
bOk = ImplDrawTheme( hTheme, hDC, iPart, iState, rect, aCaption);
}
return bOk;
}
}
if( nType == CTRL_SPINBOX )
{
// decrease spinbutton rects a little
//rc.right--;
//rc.bottom--;
if( nPart == PART_ALL_BUTTONS )
{
if( aValue.getType() == CTRL_SPINBUTTONS )
{
const SpinbuttonValue *pValue = static_cast<const SpinbuttonValue*>(&aValue);
RECT rect;
ImplConvertSpinbuttonValues( pValue->mnUpperPart, pValue->mnUpperState, pValue->maUpperRect, &iPart, &iState, &rect );
bool bOk = ImplDrawTheme( hTheme, hDC, iPart, iState, rect, aCaption);
if( bOk )
{
ImplConvertSpinbuttonValues( pValue->mnLowerPart, pValue->mnLowerState, pValue->maLowerRect, &iPart, &iState, &rect );
bOk = ImplDrawTheme( hTheme, hDC, iPart, iState, rect, aCaption);
}
return bOk;
}
}
if( nPart == PART_BUTTON_DOWN )
{
iPart = SPNP_DOWN;
if( nState & ControlState::PRESSED )
iState = DNS_PRESSED;
else if( !(nState & ControlState::ENABLED) )
iState = DNS_DISABLED;
else if( nState & ControlState::ROLLOVER )
iState = DNS_HOT;
else
iState = DNS_NORMAL;
}
if( nPart == PART_BUTTON_UP )
{
iPart = SPNP_UP;
if( nState & ControlState::PRESSED )
iState = UPS_PRESSED;
else if( !(nState & ControlState::ENABLED) )
iState = UPS_DISABLED;
else if( nState & ControlState::ROLLOVER )
iState = UPS_HOT;
else
iState = UPS_NORMAL;
}
if( nPart == PART_BUTTON_RIGHT )
{
iPart = SPNP_DOWNHORZ;
if( nState & ControlState::PRESSED )
iState = DNHZS_PRESSED;
else if( !(nState & ControlState::ENABLED) )
iState = DNHZS_DISABLED;
else if( nState & ControlState::ROLLOVER )
iState = DNHZS_HOT;
else
iState = DNHZS_NORMAL;
}
if( nPart == PART_BUTTON_LEFT )
{
iPart = SPNP_UPHORZ;
if( nState & ControlState::PRESSED )
iState = UPHZS_PRESSED;
else if( !(nState & ControlState::ENABLED) )
iState = UPHZS_DISABLED;
else if( nState & ControlState::ROLLOVER )
iState = UPHZS_HOT;
else
iState = UPHZS_NORMAL;
}
if( nPart == PART_BUTTON_LEFT || nPart == PART_BUTTON_RIGHT || nPart == PART_BUTTON_UP || nPart == PART_BUTTON_DOWN )
return ImplDrawTheme( hTheme, hDC, iPart, iState, rc, aCaption);
}
if( nType == CTRL_COMBOBOX )
{
if( nPart == PART_BUTTON_DOWN )
{
iPart = CP_DROPDOWNBUTTON;
if( nState & ControlState::PRESSED )
iState = CBXS_PRESSED;
else if( !(nState & ControlState::ENABLED) )
iState = CBXS_DISABLED;
else if( nState & ControlState::ROLLOVER )
iState = CBXS_HOT;
else
iState = CBXS_NORMAL;
return ImplDrawTheme( hTheme, hDC, iPart, iState, rc, aCaption);
}
}
if( nType == CTRL_PUSHBUTTON )
{
iPart = BP_PUSHBUTTON;
if( nState & ControlState::PRESSED )
iState = PBS_PRESSED;
else if( !(nState & ControlState::ENABLED) )
iState = PBS_DISABLED;
else if( nState & ControlState::ROLLOVER )
iState = PBS_HOT;
else if( nState & ControlState::DEFAULT )
iState = PBS_DEFAULTED;
//else if( nState & ControlState::FOCUSED )
// iState = PBS_DEFAULTED; // may need to draw focus rect
else
iState = PBS_NORMAL;
return ImplDrawTheme( hTheme, hDC, iPart, iState, rc, aCaption);
}
if( nType == CTRL_RADIOBUTTON )
{
iPart = BP_RADIOBUTTON;
bool bChecked = ( aValue.getTristateVal() == BUTTONVALUE_ON );
if( nState & ControlState::PRESSED )
iState = bChecked ? RBS_CHECKEDPRESSED : RBS_UNCHECKEDPRESSED;
else if( !(nState & ControlState::ENABLED) )
iState = bChecked ? RBS_CHECKEDDISABLED : RBS_UNCHECKEDDISABLED;
else if( nState & ControlState::ROLLOVER )
iState = bChecked ? RBS_CHECKEDHOT : RBS_UNCHECKEDHOT;
else
iState = bChecked ? RBS_CHECKEDNORMAL : RBS_UNCHECKEDNORMAL;
//if( nState & ControlState::FOCUSED )
// iState |= PBS_DEFAULTED; // may need to draw focus rect
return ImplDrawTheme( hTheme, hDC, iPart, iState, rc, aCaption);
}
if( nType == CTRL_CHECKBOX )
{
iPart = BP_CHECKBOX;
ButtonValue v = aValue.getTristateVal();
if( nState & ControlState::PRESSED )
iState = (v == BUTTONVALUE_ON) ? CBS_CHECKEDPRESSED :
( (v == BUTTONVALUE_OFF) ? CBS_UNCHECKEDPRESSED : CBS_MIXEDPRESSED );
else if( !(nState & ControlState::ENABLED) )
iState = (v == BUTTONVALUE_ON) ? CBS_CHECKEDDISABLED :
( (v == BUTTONVALUE_OFF) ? CBS_UNCHECKEDDISABLED : CBS_MIXEDDISABLED );
else if( nState & ControlState::ROLLOVER )
iState = (v == BUTTONVALUE_ON) ? CBS_CHECKEDHOT :
( (v == BUTTONVALUE_OFF) ? CBS_UNCHECKEDHOT : CBS_MIXEDHOT );
else
iState = (v == BUTTONVALUE_ON) ? CBS_CHECKEDNORMAL :
( (v == BUTTONVALUE_OFF) ? CBS_UNCHECKEDNORMAL : CBS_MIXEDNORMAL );
//if( nState & ControlState::FOCUSED )
// iState |= PBS_DEFAULTED; // may need to draw focus rect
//SIZE sz;
//THEMESIZE eSize = TS_DRAW; // TS_MIN, TS_TRUE, TS_DRAW
//vsAPI.GetThemePartSize( hTheme, hDC, iPart, iState, &rc, eSize, &sz);
return ImplDrawTheme( hTheme, hDC, iPart, iState, rc, aCaption);
}
if( ( nType == CTRL_EDITBOX ) || ( nType == CTRL_MULTILINE_EDITBOX ) )
{
iPart = EP_EDITTEXT;
if( !(nState & ControlState::ENABLED) )
iState = ETS_DISABLED;
else if( nState & ControlState::FOCUSED )
iState = ETS_FOCUSED;
else if( nState & ControlState::ROLLOVER )
iState = ETS_HOT;
else
iState = ETS_NORMAL;
return ImplDrawTheme( hTheme, hDC, iPart, iState, rc, aCaption);
}
if( nType == CTRL_LISTBOX )
{
if( nPart == PART_ENTIRE_CONTROL || nPart == PART_WINDOW )
{
iPart = LVP_EMPTYTEXT; // ??? no idea which part to choose here
return ImplDrawTheme( hTheme, hDC, iPart, iState, rc, aCaption);
}
}
if( nType == CTRL_TAB_PANE )
{
iPart = TABP_PANE;
return ImplDrawTheme( hTheme, hDC, iPart, iState, rc, aCaption);
}
if( nType == CTRL_TAB_BODY )
{
iPart = TABP_BODY;
return ImplDrawTheme( hTheme, hDC, iPart, iState, rc, aCaption);
}
if( nType == CTRL_TAB_ITEM )
{
iPart = TABP_TABITEMLEFTEDGE;
rc.bottom--;
OSL_ASSERT( aValue.getType() == CTRL_TAB_ITEM );
const TabitemValue *pValue = static_cast<const TabitemValue*>(&aValue);
if( pValue->isBothAligned() )
{
iPart = TABP_TABITEMLEFTEDGE;
rc.right--;
}
else if( pValue->isLeftAligned() )
iPart = TABP_TABITEMLEFTEDGE;
else if( pValue->isRightAligned() )
iPart = TABP_TABITEMRIGHTEDGE;
else iPart = TABP_TABITEM;
if( !(nState & ControlState::ENABLED) )
iState = TILES_DISABLED;
else if( nState & ControlState::SELECTED )
{
iState = TILES_SELECTED;
// increase the selected tab
rc.left-=2;
if( pValue && !pValue->isBothAligned() )
{
if( pValue->isLeftAligned() || pValue->isNotAligned() )
rc.right+=2;
if( pValue->isRightAligned() )
rc.right+=1;
}
rc.top-=2;
rc.bottom+=2;
}
else if( nState & ControlState::ROLLOVER )
iState = TILES_HOT;
else if( nState & ControlState::FOCUSED )
iState = TILES_FOCUSED; // may need to draw focus rect
else
iState = TILES_NORMAL;
return ImplDrawTheme( hTheme, hDC, iPart, iState, rc, aCaption);
}
if( nType == CTRL_TOOLBAR )
{
if( nPart == PART_BUTTON )
{
iPart = TP_BUTTON;
bool bChecked = ( aValue.getTristateVal() == BUTTONVALUE_ON );
if( !(nState & ControlState::ENABLED) )
//iState = TS_DISABLED;
// disabled buttons are typically not painted at all but we need visual
// feedback when travelling by keyboard over disabled entries
iState = TS_HOT;
else if( nState & ControlState::PRESSED )
iState = TS_PRESSED;
else if( nState & ControlState::ROLLOVER )
iState = bChecked ? TS_HOTCHECKED : TS_HOT;
else
iState = bChecked ? TS_CHECKED : TS_NORMAL;
return ImplDrawTheme( hTheme, hDC, iPart, iState, rc, aCaption);
}
else if( nPart == PART_THUMB_HORZ || nPart == PART_THUMB_VERT )
{
// the vertical gripper is not supported in most themes and it makes no
// sense to only support horizontal gripper
//iPart = (nPart == PART_THUMB_HORZ) ? RP_GRIPPERVERT : RP_GRIPPER;
//return ImplDrawTheme( hTheme, hDC, iPart, iState, rc, aCaption);
}
else if( nPart == PART_DRAW_BACKGROUND_HORZ || nPart == PART_DRAW_BACKGROUND_VERT )
{
if( aValue.getType() == CTRL_TOOLBAR )
{
const ToolbarValue *pValue = static_cast<const ToolbarValue*>(&aValue);
if( pValue->mbIsTopDockingArea )
rc.top = 0; // extend potential gradient to cover menu bar as well
}
// make it more compatible with Aero
if( ImplGetSVData()->maNWFData.mbDockingAreaAvoidTBFrames )
{
impl_drawAeroToolbar( hDC, rc, nPart == PART_DRAW_BACKGROUND_HORZ );
return true;
}
return ImplDrawTheme( hTheme, hDC, iPart, iState, rc, aCaption);
}
}
if( nType == CTRL_MENUBAR )
{
if( nPart == PART_ENTIRE_CONTROL )
{
if( aValue.getType() == CTRL_MENUBAR )
{
const MenubarValue *pValue = static_cast<const MenubarValue*>(&aValue);
rc.bottom += pValue->maTopDockingAreaHeight; // extend potential gradient to cover docking area as well
// make it more compatible with Aero
if( ImplGetSVData()->maNWFData.mbDockingAreaAvoidTBFrames )
{
impl_drawAeroToolbar( hDC, rc, true );
return true;
}
}
return ImplDrawTheme( hTheme, hDC, iPart, iState, rc, aCaption);
}
else if( nPart == PART_MENU_ITEM )
{
if( nState & ControlState::ENABLED )
{
if( nState & ControlState::SELECTED )
iState = MBI_PUSHED;
else if( nState & ControlState::ROLLOVER )
iState = MBI_HOT;
else
iState = MBI_NORMAL;
}
else
{
if( nState & ControlState::SELECTED )
iState = MBI_DISABLEDPUSHED;
else if( nState & ControlState::ROLLOVER )
iState = MBI_DISABLEDHOT;
else
iState = MBI_DISABLED;
}
return ImplDrawTheme( hTheme, hDC, MENU_BARITEM, iState, rc, aCaption );
}
}
if( nType == CTRL_PROGRESS )
{
if( nPart != PART_ENTIRE_CONTROL )
return FALSE;
if( ! ImplDrawTheme( hTheme, hDC, PP_BAR, iState, rc, aCaption) )
return false;
RECT aProgressRect = rc;
if( vsAPI.GetThemeBackgroundContentRect( hTheme, hDC, PP_BAR, iState, &rc, &aProgressRect) != S_OK )
return false;
long nProgressWidth = aValue.getNumericVal();
nProgressWidth *= (aProgressRect.right - aProgressRect.left);
nProgressWidth /= (rc.right - rc.left);
if( Application::GetSettings().GetLayoutRTL() )
aProgressRect.left = aProgressRect.right - nProgressWidth;
else
aProgressRect.right = aProgressRect.left + nProgressWidth;
return ImplDrawTheme( hTheme, hDC, PP_CHUNK, iState, aProgressRect, aCaption );
}
if( nType == CTRL_SLIDER )
{
iPart = (nPart == PART_TRACK_HORZ_AREA) ? TKP_TRACK : TKP_TRACKVERT;
iState = (nPart == PART_TRACK_HORZ_AREA) ? static_cast<int>(TRS_NORMAL) : static_cast<int>(TRVS_NORMAL);
Rectangle aTrackRect = ImplGetThemeRect( hTheme, hDC, iPart, iState, Rectangle() );
RECT aTRect = rc;
if( nPart == PART_TRACK_HORZ_AREA )
{
long nH = aTrackRect.GetHeight();
aTRect.top += (rc.bottom - rc.top - nH)/2;
aTRect.bottom = aTRect.top + nH;
}
else
{
long nW = aTrackRect.GetWidth();
aTRect.left += (rc.right - rc.left - nW)/2;
aTRect.right = aTRect.left + nW;
}
ImplDrawTheme( hTheme, hDC, iPart, iState, aTRect, aCaption );
RECT aThumbRect;
OSL_ASSERT( aValue.getType() == CTRL_SLIDER );
const SliderValue* pVal = static_cast<const SliderValue*>(&aValue);
aThumbRect.left = pVal->maThumbRect.Left();
aThumbRect.top = pVal->maThumbRect.Top();
aThumbRect.right = pVal->maThumbRect.Right();
aThumbRect.bottom = pVal->maThumbRect.Bottom();
iPart = (nPart == PART_TRACK_HORZ_AREA) ? TKP_THUMB : TKP_THUMBVERT;
iState = (nState & ControlState::ENABLED) ? TUS_NORMAL : TUS_DISABLED;
return ImplDrawTheme( hTheme, hDC, iPart, iState, aThumbRect, aCaption );
}
if( nType == CTRL_LISTNODE )
{
if( nPart != PART_ENTIRE_CONTROL )
return FALSE;
ButtonValue aButtonValue = aValue.getTristateVal();
iPart = TVP_GLYPH;
switch( aButtonValue )
{
case BUTTONVALUE_ON:
iState = GLPS_OPENED;
break;
case BUTTONVALUE_OFF:
iState = GLPS_CLOSED;
break;
default:
return FALSE;
}
return ImplDrawTheme( hTheme, hDC, iPart, iState, rc, aCaption );
}
if( GetSalData()->mbThemeMenuSupport )
{
if( nType == CTRL_MENU_POPUP )
{
if( nPart == PART_ENTIRE_CONTROL )
{
RECT aGutterRC = rc;
if( Application::GetSettings().GetLayoutRTL() )
{
aGutterRC.right -= aValue.getNumericVal()+1;
aGutterRC.left = aGutterRC.right-3;
}
else
{
aGutterRC.left += aValue.getNumericVal();
aGutterRC.right = aGutterRC.left+3;
}
return
ImplDrawTheme( hTheme, hDC, MENU_POPUPBACKGROUND, 0, rc, aCaption ) &&
ImplDrawTheme( hTheme, hDC, MENU_POPUPGUTTER, 0, aGutterRC, aCaption )
;
}
else if( nPart == PART_MENU_ITEM )
{
if( (nState & ControlState::ENABLED) )
iState = (nState & ControlState::SELECTED) ? MPI_HOT : MPI_NORMAL;
else
iState = (nState & ControlState::SELECTED) ? MPI_DISABLEDHOT : MPI_DISABLED;
return ImplDrawTheme( hTheme, hDC, MENU_POPUPITEM, iState, rc, aCaption );
}
else if( nPart == PART_MENU_ITEM_CHECK_MARK || nPart == PART_MENU_ITEM_RADIO_MARK )
{
if( (nState & ControlState::PRESSED) )
{
RECT aBGRect = rc;
if( aValue.getType() == CTRL_MENU_POPUP )
{
const MenupopupValue& rMVal( static_cast<const MenupopupValue&>(aValue) );
aBGRect.top = rMVal.maItemRect.Top();
aBGRect.bottom = rMVal.maItemRect.Bottom()+1; // see below in drawNativeControl
if( Application::GetSettings().GetLayoutRTL() )
{
aBGRect.right = rMVal.maItemRect.Right()+1;
aBGRect.left = aBGRect.right - (rMVal.getNumericVal()-rMVal.maItemRect.Left());
}
else
{
aBGRect.right = rMVal.getNumericVal();
aBGRect.left = rMVal.maItemRect.Left();
}
rc = aBGRect;
}
iState = (nState & ControlState::ENABLED) ? MCB_NORMAL : MCB_DISABLED;
ImplDrawTheme( hTheme, hDC, MENU_POPUPCHECKBACKGROUND, iState, aBGRect, aCaption );
if( nPart == PART_MENU_ITEM_CHECK_MARK )
iState = (nState & ControlState::ENABLED) ? MC_CHECKMARKNORMAL : MC_CHECKMARKDISABLED;
else
iState = (nState & ControlState::ENABLED) ? MC_BULLETNORMAL : MC_BULLETDISABLED;
return ImplDrawTheme( hTheme, hDC, MENU_POPUPCHECK, iState, rc, aCaption );
}
else
return true; // unchecked: do nothing
}
else if( nPart == PART_MENU_SEPARATOR )
{
// adjust for gutter position
if( Application::GetSettings().GetLayoutRTL() )
rc.right -= aValue.getNumericVal()+1;
else
rc.left += aValue.getNumericVal()+1;
Rectangle aRect( ImplGetThemeRect( hTheme, hDC,
MENU_POPUPSEPARATOR, 0, Rectangle( rc.left, rc.top, rc.right, rc.bottom ) ) );
// center the separator inside the passed rectangle
long nDY = ((rc.bottom - rc.top + 1) - aRect.GetHeight()) / 2;
rc.top += nDY;
rc.bottom = rc.top+aRect.GetHeight()-1;
return ImplDrawTheme( hTheme, hDC, MENU_POPUPSEPARATOR, 0, rc, aCaption );
}
}
}
return false;
}
/*
* DrawNativeControl()
*
* Draws the requested control described by nPart/nState.
*
* rControlRegion: The bounding region of the complete control in VCL frame coordinates.
* aValue: An optional value (tristate/numerical/string)
* aCaption: A caption or title string (like button text etc)
*/
bool WinSalGraphics::drawNativeControl( ControlType nType,
ControlPart nPart,
const Rectangle& rControlRegion,
ControlState nState,
const ImplControlValue& aValue,
const OUString& aCaption )
{
bool bOk = false;
HTHEME hTheme = NULL;
switch( nType )
{
case CTRL_PUSHBUTTON:
case CTRL_RADIOBUTTON:
case CTRL_CHECKBOX:
hTheme = getThemeHandle( mhWnd, L"Button");
break;
case CTRL_SCROLLBAR:
hTheme = getThemeHandle( mhWnd, L"Scrollbar");
break;
case CTRL_COMBOBOX:
if( nPart == PART_ENTIRE_CONTROL )
hTheme = getThemeHandle( mhWnd, L"Edit");
else if( nPart == PART_BUTTON_DOWN )
hTheme = getThemeHandle( mhWnd, L"Combobox");
break;
case CTRL_SPINBOX:
if( nPart == PART_ENTIRE_CONTROL )
hTheme = getThemeHandle( mhWnd, L"Edit");
else
hTheme = getThemeHandle( mhWnd, L"Spin");
break;
case CTRL_SPINBUTTONS:
hTheme = getThemeHandle( mhWnd, L"Spin");
break;
case CTRL_EDITBOX:
case CTRL_MULTILINE_EDITBOX:
hTheme = getThemeHandle( mhWnd, L"Edit");
break;
case CTRL_LISTBOX:
if( nPart == PART_ENTIRE_CONTROL || nPart == PART_WINDOW )
hTheme = getThemeHandle( mhWnd, L"Listview");
else if( nPart == PART_BUTTON_DOWN )
hTheme = getThemeHandle( mhWnd, L"Combobox");
break;
case CTRL_TAB_PANE:
case CTRL_TAB_BODY:
case CTRL_TAB_ITEM:
hTheme = getThemeHandle( mhWnd, L"Tab");
break;
case CTRL_TOOLBAR:
if( nPart == PART_ENTIRE_CONTROL || nPart == PART_BUTTON )
hTheme = getThemeHandle( mhWnd, L"Toolbar");
else
// use rebar for grip and background
hTheme = getThemeHandle( mhWnd, L"Rebar");
break;
case CTRL_MENUBAR:
if( nPart == PART_ENTIRE_CONTROL )
hTheme = getThemeHandle( mhWnd, L"Rebar");
else if( GetSalData()->mbThemeMenuSupport )
{
if( nPart == PART_MENU_ITEM )
hTheme = getThemeHandle( mhWnd, L"Menu" );
}
break;
case CTRL_PROGRESS:
if( nPart == PART_ENTIRE_CONTROL )
hTheme = getThemeHandle( mhWnd, L"Progress");
break;
case CTRL_LISTNODE:
if( nPart == PART_ENTIRE_CONTROL )
hTheme = getThemeHandle( mhWnd, L"TreeView");
break;
case CTRL_SLIDER:
if( nPart == PART_TRACK_HORZ_AREA || nPart == PART_TRACK_VERT_AREA )
hTheme = getThemeHandle( mhWnd, L"Trackbar" );
break;
case CTRL_MENU_POPUP:
if( GetSalData()->mbThemeMenuSupport )
{
if( nPart == PART_ENTIRE_CONTROL || nPart == PART_MENU_ITEM ||
nPart == PART_MENU_ITEM_CHECK_MARK || nPart == PART_MENU_ITEM_RADIO_MARK ||
nPart == PART_MENU_SEPARATOR
)
hTheme = getThemeHandle( mhWnd, L"Menu" );
}
break;
default:
hTheme = NULL;
break;
}
if( !hTheme )
return false;
Rectangle buttonRect = rControlRegion;
RECT rc;
rc.left = buttonRect.Left();
rc.right = buttonRect.Right()+1;
rc.top = buttonRect.Top();
rc.bottom = buttonRect.Bottom()+1;
OUString aCaptionStr(aCaption.replace('~', '&')); // translate mnemonics
WinOpenGLSalGraphicsImpl *pImpl = dynamic_cast<WinOpenGLSalGraphicsImpl*>(mpImpl.get());
if (pImpl == NULL)
{
// set default text alignment
int ta = SetTextAlign(getHDC(), TA_LEFT|TA_TOP|TA_NOUPDATECP);
bOk = ImplDrawNativeControl(getHDC(), hTheme, rc, nType, nPart, nState, aValue, aCaptionStr);
// restore alignment
SetTextAlign(getHDC(), ta);
}
else
{
// We can do OpenGL
OpenGLCompatibleDC aBlackDC(*this, buttonRect.Left(), buttonRect.Top(), buttonRect.GetWidth(), buttonRect.GetHeight());
SetTextAlign(aBlackDC.getCompatibleHDC(), TA_LEFT|TA_TOP|TA_NOUPDATECP);
aBlackDC.fill(MAKE_SALCOLOR(0, 0, 0));
OpenGLCompatibleDC aWhiteDC(*this, buttonRect.Left(), buttonRect.Top(), buttonRect.GetWidth(), buttonRect.GetHeight());
SetTextAlign(aWhiteDC.getCompatibleHDC(), TA_LEFT|TA_TOP|TA_NOUPDATECP);
aWhiteDC.fill(MAKE_SALCOLOR(0xff, 0xff, 0xff));
if (ImplDrawNativeControl(aBlackDC.getCompatibleHDC(), hTheme, rc, nType, nPart, nState, aValue, aCaptionStr) &&
ImplDrawNativeControl(aWhiteDC.getCompatibleHDC(), hTheme, rc, nType, nPart, nState, aValue, aCaptionStr))
{
pImpl->PreDraw();
boost::scoped_ptr<OpenGLTexture> pBlackTexture(aBlackDC.getTexture());
boost::scoped_ptr<OpenGLTexture> pWhiteTexture(aWhiteDC.getTexture());
if (pBlackTexture && pWhiteTexture)
{
pImpl->DrawTextureDiff(*pWhiteTexture, *pBlackTexture, aBlackDC.getTwoRect());
bOk = true;
}
pImpl->PostDraw();
}
}
return bOk;
}
/*
* GetNativeControlRegion()
*
* If the return value is TRUE, rNativeBoundingRegion
* contains the true bounding region covered by the control
* including any adornment, while rNativeContentRegion contains the area
* within the control that can be safely drawn into without drawing over
* the borders of the control.
*
* rControlRegion: The bounding region of the control in VCL frame coordinates.
* aValue: An optional value (tristate/numerical/string)
* aCaption: A caption or title string (like button text etc)
*/
bool WinSalGraphics::getNativeControlRegion( ControlType nType,
ControlPart nPart,
const Rectangle& rControlRegion,
ControlState nState,
const ImplControlValue& rControlValue,
const OUString&,
Rectangle &rNativeBoundingRegion,
Rectangle &rNativeContentRegion )
{
bool bRet = FALSE;
HDC hDC = GetDC( mhWnd );
if( nType == CTRL_TOOLBAR )
{
if( nPart == PART_THUMB_HORZ || nPart == PART_THUMB_VERT )
{
/*
// the vertical gripper is not supported in most themes and it makes no
// sense to only support horizontal gripper
HTHEME hTheme = getThemeHandle( mhWnd, L"Rebar");
if( hTheme )
{
Rectangle aRect( ImplGetThemeRect( hTheme, hDC, nPart == PART_THUMB_HORZ ? RP_GRIPPERVERT : RP_GRIPPER,
0, rControlRegion.GetBoundRect() ) );
if( nPart == PART_THUMB_HORZ && !aRect.IsEmpty() )
{
Rectangle aVertRect( 0, 0, aRect.getHeight(), aRect.getWidth() );
rNativeContentRegion = aVertRect;
}
else
rNativeContentRegion = aRect;
rNativeBoundingRegion = rNativeContentRegion;
if( !rNativeContentRegion.IsEmpty() )
bRet = TRUE;
}
*/
}
if( nPart == PART_BUTTON )
{
HTHEME hTheme = getThemeHandle( mhWnd, L"Toolbar");
if( hTheme )
{
Rectangle aRect( ImplGetThemeRect( hTheme, hDC, TP_SPLITBUTTONDROPDOWN,
TS_HOT, rControlRegion ) );
rNativeContentRegion = aRect;
rNativeBoundingRegion = rNativeContentRegion;
if( !rNativeContentRegion.IsEmpty() )
bRet = TRUE;
}
}
}
if( nType == CTRL_PROGRESS && nPart == PART_ENTIRE_CONTROL )
{
HTHEME hTheme = getThemeHandle( mhWnd, L"Progress");
if( hTheme )
{
Rectangle aRect( ImplGetThemeRect( hTheme, hDC, PP_BAR,
0, rControlRegion ) );
rNativeContentRegion = aRect;
rNativeBoundingRegion = rNativeContentRegion;
if( !rNativeContentRegion.IsEmpty() )
bRet = TRUE;
}
}
if( (nType == CTRL_LISTBOX || nType == CTRL_COMBOBOX ) && nPart == PART_ENTIRE_CONTROL )
{
HTHEME hTheme = getThemeHandle( mhWnd, L"Combobox");
if( hTheme )
{
Rectangle aBoxRect( rControlRegion );
Rectangle aRect( ImplGetThemeRect( hTheme, hDC, CP_DROPDOWNBUTTON,
CBXS_NORMAL, aBoxRect ) );
if( aRect.GetHeight() > aBoxRect.GetHeight() )
aBoxRect.Bottom() = aBoxRect.Top() + aRect.GetHeight();
if( aRect.GetWidth() > aBoxRect.GetWidth() )
aBoxRect.Right() = aBoxRect.Left() + aRect.GetWidth();
rNativeContentRegion = aBoxRect;
rNativeBoundingRegion = rNativeContentRegion;
if( !aRect.IsEmpty() )
bRet = TRUE;
}
}
if( (nType == CTRL_EDITBOX || nType == CTRL_SPINBOX) && nPart == PART_ENTIRE_CONTROL )
{
HTHEME hTheme = getThemeHandle( mhWnd, L"Edit");
if( hTheme )
{
// get border size
Rectangle aBoxRect( rControlRegion );
Rectangle aRect( ImplGetThemeRect( hTheme, hDC, EP_BACKGROUNDWITHBORDER,
EBWBS_HOT, aBoxRect ) );
// ad app font height
NONCLIENTMETRICSW aNonClientMetrics;
aNonClientMetrics.cbSize = sizeof( aNonClientMetrics );
if ( SystemParametersInfoW( SPI_GETNONCLIENTMETRICS, sizeof( aNonClientMetrics ), &aNonClientMetrics, 0 ) )
{
long nFontHeight = aNonClientMetrics.lfMessageFont.lfHeight;
if( nFontHeight < 0 )
nFontHeight = -nFontHeight;
if( aRect.GetHeight() && nFontHeight )
{
aRect.Bottom() += aRect.GetHeight();
aRect.Bottom() += nFontHeight;
if( aRect.GetHeight() > aBoxRect.GetHeight() )
aBoxRect.Bottom() = aBoxRect.Top() + aRect.GetHeight();
if( aRect.GetWidth() > aBoxRect.GetWidth() )
aBoxRect.Right() = aBoxRect.Left() + aRect.GetWidth();
rNativeContentRegion = aBoxRect;
rNativeBoundingRegion = rNativeContentRegion;
bRet = TRUE;
}
}
}
}
if( GetSalData()->mbThemeMenuSupport )
{
if( nType == CTRL_MENU_POPUP )
{
if( nPart == PART_MENU_ITEM_CHECK_MARK ||
nPart == PART_MENU_ITEM_RADIO_MARK )
{
HTHEME hTheme = getThemeHandle( mhWnd, L"Menu");
Rectangle aBoxRect( rControlRegion );
Rectangle aRect( ImplGetThemeRect( hTheme, hDC,
MENU_POPUPCHECK,
MC_CHECKMARKNORMAL,
aBoxRect ) );
if( aBoxRect.GetWidth() && aBoxRect.GetHeight() )
{
rNativeContentRegion = aRect;
rNativeBoundingRegion = rNativeContentRegion;
bRet = TRUE;
}
}
}
}
if( nType == CTRL_SLIDER && ( (nPart == PART_THUMB_HORZ) || (nPart == PART_THUMB_VERT) ) )
{
HTHEME hTheme = getThemeHandle( mhWnd, L"Trackbar");
if( hTheme )
{
int iPart = (nPart == PART_THUMB_HORZ) ? TKP_THUMB : TKP_THUMBVERT;
int iState = (nPart == PART_THUMB_HORZ) ? static_cast<int>(TUS_NORMAL) : static_cast<int>(TUVS_NORMAL);
Rectangle aThumbRect = ImplGetThemeRect( hTheme, hDC, iPart, iState, Rectangle() );
if( nPart == PART_THUMB_HORZ )
{
long nW = aThumbRect.GetWidth();
Rectangle aRect( rControlRegion );
aRect.Right() = aRect.Left() + nW - 1;
rNativeContentRegion = aRect;
rNativeBoundingRegion = rNativeContentRegion;
}
else
{
long nH = aThumbRect.GetHeight();
Rectangle aRect( rControlRegion );
aRect.Bottom() = aRect.Top() + nH - 1;
rNativeContentRegion = aRect;
rNativeBoundingRegion = rNativeContentRegion;
}
bRet = TRUE;
}
}
if ( ( nType == CTRL_TAB_ITEM ) && ( nPart == PART_ENTIRE_CONTROL ) )
{
Rectangle aControlRect( rControlRegion );
rNativeContentRegion = aControlRect;
--aControlRect.Bottom();
if( rControlValue.getType() == CTRL_TAB_ITEM )
{
const TabitemValue *pValue = static_cast<const TabitemValue*>(&rControlValue);
if ( pValue->isBothAligned() )
--aControlRect.Right();
if ( nState & ControlState::SELECTED )
{
aControlRect.Left() -= 2;
if ( pValue && !pValue->isBothAligned() )
{
if ( pValue->isLeftAligned() || pValue->isNotAligned() )
aControlRect.Right() += 2;
if ( pValue->isRightAligned() )
aControlRect.Right() += 1;
}
aControlRect.Top() -= 2;
aControlRect.Bottom() += 2;
}
}
rNativeBoundingRegion = aControlRect;
bRet = TRUE;
}
ReleaseDC( mhWnd, hDC );
return( bRet );
}
void WinSalGraphics::updateSettingsNative( AllSettings& rSettings )
{
if ( !vsAPI.IsThemeActive() )
return;
StyleSettings aStyleSettings = rSettings.GetStyleSettings();
ImplSVData* pSVData = ImplGetSVData();
// don't draw frame around each and every toolbar
pSVData->maNWFData.mbDockingAreaAvoidTBFrames = true;
// check if vista or newer runs
// in Aero theme (and similar ?) the menu text color does not change
// for selected items; also on WinXP and earlier menus are not themed
// FIXME get the color directly from the theme, not from the settings
if( aSalShlData.maVersionInfo.dwMajorVersion >= 6 )
{
Color aMenuBarTextColor = aStyleSettings.GetPersonaMenuBarTextColor().get_value_or( aStyleSettings.GetMenuTextColor() );
// in aero menuitem highlight text is drawn in the same color as normal
aStyleSettings.SetMenuHighlightTextColor( aStyleSettings.GetMenuTextColor() );
aStyleSettings.SetMenuBarRolloverTextColor( aMenuBarTextColor );
pSVData->maNWFData.mnMenuFormatBorderX = 2;
pSVData->maNWFData.mnMenuFormatBorderY = 2;
pSVData->maNWFData.maMenuBarHighlightTextColor = aMenuBarTextColor;
GetSalData()->mbThemeMenuSupport = TRUE;
}
rSettings.SetStyleSettings( aStyleSettings );
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|