forked from lStewieAl/Geck-Extender
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEditorUIDarkMode.cpp
774 lines (655 loc) · 20.9 KB
/
EditorUIDarkMode.cpp
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
#include <unordered_map>
#include <unordered_set>
#include <shared_mutex>
#include <string>
#include <vssym32.h>
#include <Richedit.h>
#include <array>
#include "EditorUIDarkMode.h"
#include "Detours.h"
#include "xutil.h"
namespace EditorUIDarkMode
{
enum class ThemeType
{
None,
ScrollBar,
StatusBar,
MDIClient,
Static,
Edit,
RichEdit,
Button,
ComboBox,
Header,
ListView,
TreeView,
TabControl,
};
const std::unordered_map<std::string_view, ThemeType> TargetWindowThemes
{
{ "msctls_statusbar32", ThemeType::StatusBar },
{ "MDIClient", ThemeType::MDIClient },
{ "Static", ThemeType::Static },
{ "Edit", ThemeType::Edit },
{ "RichEdit20A", ThemeType::RichEdit },
{ "RICHEDIT50W", ThemeType::RichEdit },
{ "Button", ThemeType::Button },
{ "ComboBox", ThemeType::ComboBox },
{ "SysHeader32", ThemeType::Header },
{ "SysListView32", ThemeType::ListView },
{ "SysTreeView32", ThemeType::TreeView },
{ "SysTabControl32", ThemeType::TabControl },
};
const std::unordered_set<std::string_view> PermanentWindowSubclasses
{
"Creation Kit",
"Creation Kit SE",
"ActivatorClass",
"AlchemyClass",
"ArmorClass",
"CreatureClass",
"LockPickClass",
"NPCClass",
"WeaponClass",
"FaceClass",
"PlaneClass",
"MonitorClass",
"ViewerClass",
"SpeakerClass",
"LandClass",
"RenderWindow",
"#32770",
// "BABYGRID",
// "NiTreeCtrl",
};
std::unordered_map<HTHEME, ThemeType> ThemeHandles;
bool Initialize()
{
auto comDll = reinterpret_cast<uintptr_t>(GetModuleHandle("comctl32.dll"));
Assert(comDll);
bool result = true;
result && Detours::IATHook(comDll, "USER32.dll", "GetSysColor", (uintptr_t)&EditorUIDarkMode::Comctl32GetSysColor);
result && Detours::IATHook(comDll, "USER32.dll", "GetSysColorBrush", (uintptr_t)&EditorUIDarkMode::Comctl32GetSysColorBrush);
result && Detours::IATDelayedHook(comDll, "UxTheme.dll", "DrawThemeBackground", (uintptr_t)&EditorUIDarkMode::Comctl32DrawThemeBackground);
result && Detours::IATDelayedHook(comDll, "UxTheme.dll", "DrawThemeText", (uintptr_t)&EditorUIDarkMode::Comctl32DrawThemeText);
if (result)
{
// prevent the data dialog's listview from generating a mask for the checkmarks (to ensure visibility) - ShadeMe
SafeWrite8(0x430D66 + 1, LR_MONOCHROME);
SafeWrite16(0x430D6A + 1, 0xFFFF);
SafeWrite8(0x430D6A + 3, 0xFF);
SetWindowsHookExA(WH_CALLWNDPROC, CallWndProcCallback, nullptr, GetCurrentThreadId());
}
return result;
}
LRESULT CALLBACK CallWndProcCallback(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode == HC_ACTION)
{
auto messageData = reinterpret_cast<CWPSTRUCT*>(lParam);
switch (messageData->message)
{
case WM_CREATE:
SetWindowSubclass(messageData->hwnd, WindowSubclass, 0, reinterpret_cast<DWORD_PTR>(WindowSubclass));
break;
case WM_INITDIALOG:
SetWindowSubclass(messageData->hwnd, DialogWindowSubclass, 0, reinterpret_cast<DWORD_PTR>(DialogWindowSubclass));
break;
}
}
return CallNextHookEx(nullptr, nCode, wParam, lParam);
}
LRESULT CALLBACK WindowSubclass(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
{
constexpr COLORREF generalBackgroundColor = RGB(56, 56, 56);
constexpr COLORREF generalTextColor = RGB(255, 255, 255);
static HBRUSH generalBackgroundBrush = CreateSolidBrush(generalBackgroundColor);
switch (uMsg)
{
case WM_CTLCOLOREDIT:
case WM_CTLCOLORLISTBOX:
case WM_CTLCOLORBTN:
case WM_CTLCOLORDLG:
case WM_CTLCOLORSTATIC:
{
if (HDC hdc = reinterpret_cast<HDC>(wParam); hdc)
{
SetTextColor(hdc, generalTextColor);
SetBkColor(hdc, generalBackgroundColor);
}
return reinterpret_cast<INT_PTR>(generalBackgroundBrush);
}
break;
}
LRESULT result = DefSubclassProc(hWnd, uMsg, wParam, lParam);
switch (uMsg)
{
case WM_INITDIALOG:
case WM_CREATE:
{
// Theme settings are initialized after WM_CREATE is processed
auto themeType = ThemeType::None;
HTHEME scrollBarTheme = nullptr;
char className[256] = {};
GetClassName(hWnd, className, ARRAYSIZE(className));
if (auto itr = TargetWindowThemes.find(className); itr != TargetWindowThemes.end())
themeType = itr->second;
switch (themeType)
{
case ThemeType::MDIClient:
SetWindowSubclass(hWnd, MDIClientSubclass, 0, 0);
break;
case ThemeType::RichEdit:
{
CHARFORMAT2A format = {};
format.cbSize = sizeof(format);
format.dwMask = CFM_COLOR;
format.crTextColor = RGB(255, 255, 255);
SendMessageA(hWnd, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&format);
SendMessageA(hWnd, EM_SETBKGNDCOLOR, 0, RGB(56, 56, 56));
}
break;
case ThemeType::ListView:
SetWindowSubclass(hWnd, ListViewSubclass, 0, 0);
ListView_SetTextColor(hWnd, RGB(255, 255, 255));
ListView_SetTextBkColor(hWnd, RGB(32, 32, 32));
ListView_SetBkColor(hWnd, RGB(32, 32, 32));
scrollBarTheme = OpenThemeData(hWnd, VSCLASS_SCROLLBAR);
break;
case ThemeType::TreeView:
TreeView_SetTextColor(hWnd, RGB(255, 255, 255));
TreeView_SetBkColor(hWnd, RGB(32, 32, 32));
scrollBarTheme = OpenThemeData(hWnd, VSCLASS_SCROLLBAR);
break;
case ThemeType::TabControl:
SetWindowLongPtrA(hWnd, GWL_STYLE, (GetWindowLongPtrA(hWnd, GWL_STYLE) & ~TCS_BUTTONS) | TCS_TABS);
SetWindowTheme(hWnd, nullptr, nullptr);
break;
}
if (scrollBarTheme)
{
ThemeHandles.emplace(scrollBarTheme, ThemeType::ScrollBar);
// TODO: This is a hack...the handle should be valid as long as at least one window is still open
CloseThemeData(scrollBarTheme);
}
if (HTHEME windowTheme = GetWindowTheme(hWnd); windowTheme)
ThemeHandles.emplace(windowTheme, themeType);
if (!PermanentWindowSubclasses.count(className))
RemoveWindowSubclass(hWnd, reinterpret_cast<SUBCLASSPROC>(dwRefData), 0);
}
break;
}
return result;
}
LRESULT CALLBACK DialogWindowSubclass(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
{
constexpr COLORREF generalBackgroundColor = RGB(56, 56, 56);
static HBRUSH generalBackgroundBrush = CreateSolidBrush(generalBackgroundColor);
LRESULT result = WindowSubclass(hWnd, uMsg, wParam, lParam, uIdSubclass, dwRefData);
switch (uMsg)
{
case WM_PAINT:
{
// Special override for DialogBoxIndirectParam (MessageBox) since the bottom half doesn't get themed correctly. ReactOS
// says this is MSGBOX_IDTEXT. Standard message boxes will have 3 buttons or less.
if (GetDlgItem(hWnd, 0xFFFF))
{
int buttonCount = 0;
EnumChildWindows(hWnd, [](HWND ChildWindow, LPARAM Param)
{
char classname[256] = {};
GetClassName(ChildWindow, classname, std::size(classname));
if (!_stricmp(classname, "Button"))
(*reinterpret_cast<int*>(Param))++;
return TRUE;
}, reinterpret_cast<LPARAM>(&buttonCount));
if (buttonCount <= 3)
{
if (HDC hdc = GetDC(hWnd); hdc)
{
RECT windowArea;
GetClientRect(hWnd, &windowArea);
FillRect(hdc, &windowArea, generalBackgroundBrush);
ReleaseDC(hWnd, hdc);
}
}
}
}
break;
}
return result;
}
LRESULT CALLBACK ListViewSubclass(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
{
switch (uMsg)
{
case WM_PAINT:
{
// Paint normally, then apply custom grid lines
LRESULT result = DefSubclassProc(hWnd, uMsg, wParam, lParam);
if (HDC hdc = GetDC(hWnd); hdc)
{
RECT headerRect;
GetClientRect(ListView_GetHeader(hWnd), &headerRect);
RECT listRect;
GetClientRect(hWnd, &listRect);
HGDIOBJ oldPen = SelectObject(hdc, GetStockObject(DC_PEN));
int x = 0 - GetScrollPos(hWnd, SB_HORZ);
LVCOLUMN colInfo
{
.mask = LVCF_WIDTH,
};
for (int col = 0; ListView_GetColumn(hWnd, col, &colInfo); col++)
{
x += colInfo.cx;
// Stop drawing if outside the listview client area
if (x >= listRect.right)
break;
// Right border
std::array<POINT, 2> verts
{ {
{ x - 2, headerRect.bottom },
{ x - 2, listRect.bottom },
} };
SetDCPenColor(hdc, RGB(65, 65, 65));
Polyline(hdc, verts.data(), verts.size());
// Right border shadow
verts[0].x += 1;
verts[1].x += 1;
SetDCPenColor(hdc, RGB(29, 38, 48));
Polyline(hdc, verts.data(), verts.size());
}
SelectObject(hdc, oldPen);
ReleaseDC(hWnd, hdc);
}
return result;
}
case LVM_SETEXTENDEDLISTVIEWSTYLE:
{
// Prevent the OS grid separators from drawing
wParam &= ~static_cast<WPARAM>(LVS_EX_GRIDLINES);
lParam &= ~static_cast<LPARAM>(LVS_EX_GRIDLINES);
}
break;
}
return DefSubclassProc(hWnd, uMsg, wParam, lParam);
}
LRESULT CALLBACK MDIClientSubclass(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
{
static HBRUSH backgroundColorBrush = CreateSolidBrush(RGB(32, 32, 32));
switch (uMsg)
{
case WM_PAINT:
{
// Custom background color
if (HDC hdc = GetDC(hWnd); hdc)
{
RECT windowArea;
GetClientRect(hWnd, &windowArea);
FillRect(hdc, &windowArea, backgroundColorBrush);
ReleaseDC(hWnd, hdc);
}
}
break;
}
return DefSubclassProc(hWnd, uMsg, wParam, lParam);
}
DWORD WINAPI Comctl32GetSysColor(int nIndex)
{
switch (nIndex)
{
case COLOR_BTNFACE: return RGB(56, 56, 56);
case COLOR_BTNTEXT: return RGB(255, 255, 255);
}
return GetSysColor(nIndex);
}
HBRUSH WINAPI Comctl32GetSysColorBrush(int nIndex)
{
static HBRUSH btnFaceBrush = CreateSolidBrush(Comctl32GetSysColor(COLOR_BTNFACE));
static HBRUSH btnTextBrush = CreateSolidBrush(Comctl32GetSysColor(COLOR_BTNTEXT));
switch (nIndex)
{
case COLOR_BTNFACE: return btnFaceBrush;
case COLOR_BTNTEXT: return btnTextBrush;
}
return GetSysColorBrush(nIndex);
}
HRESULT WINAPI Comctl32DrawThemeText(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, LPCWSTR pszText, int cchText, DWORD dwTextFlags, DWORD dwTextFlags2, LPCRECT pRect)
{
SetBkMode(hdc, TRANSPARENT);
SetTextColor(hdc, RGB(255, 255, 255));
RECT temp = *pRect;
DrawTextW(hdc, pszText, cchText, &temp, dwTextFlags);
return S_OK;
}
HRESULT WINAPI Comctl32DrawThemeBackground(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, LPCRECT pRect, LPCRECT pClipRect)
{
auto themeType = ThemeType::None;
if (auto itr = ThemeHandles.find(hTheme); itr != ThemeHandles.end())
themeType = itr->second;
if (themeType == ThemeType::ScrollBar)
{
static HBRUSH scrollbarFill = CreateSolidBrush(RGB(77, 77, 77));
static HBRUSH scrollbarFillHighlighted = CreateSolidBrush(RGB(122, 122, 122));
static HBRUSH scrollbarBackground = CreateSolidBrush(RGB(23, 23, 23));
switch (iPartId)
{
case SBP_THUMBBTNHORZ: // Horizontal drag bar
case SBP_THUMBBTNVERT: // Vertical drag bar
{
if (iStateId == SCRBS_HOT || iStateId == SCRBS_PRESSED)
FillRect(hdc, pRect, scrollbarFillHighlighted);
else
FillRect(hdc, pRect, scrollbarFill);
}
return S_OK;
case SBP_LOWERTRACKHORZ:// Horizontal background
case SBP_UPPERTRACKHORZ:// Horizontal background
case SBP_LOWERTRACKVERT:// Vertical background
case SBP_UPPERTRACKVERT:// Vertical background
{
FillRect(hdc, pRect, scrollbarBackground);
}
return S_OK;
case SBP_ARROWBTN: // Arrow button
{
// Assume the perspective of the arrow pointing upward ( /\ ) in GDI coordinates. NOTE: (0, 0) is the
// top left corner of the screen. Awful code, but it works.
const int arrowWidth = std::ceil(std::abs(pRect->left - pRect->right) * 0.4f);
const int arrowHeight = std::ceil(std::abs(pRect->top - pRect->bottom) * 0.35f);
std::array<DWORD, 6> counts{ 2, 2, 2, 2, 2, 2 };
std::array<POINT, 12> verts
{ {
// Left segment
{ 0, -0 },
{ (arrowWidth / 2) + 1, -arrowHeight + 2 },
{ 0, -1 },
{ (arrowWidth / 2) + 1, -arrowHeight + 1 },
{ 0, -2 },
{ (arrowWidth / 2) + 1, -arrowHeight + 0 },
// Right segment (final vertex Y adjusted to avoid a stray pixel)
{ arrowWidth - 1, -0 },
{ arrowWidth / 2, -arrowHeight + 2 },
{ arrowWidth - 1, -1 },
{ arrowWidth / 2, -arrowHeight + 1 },
{ arrowWidth - 1, -2 },
{ arrowWidth / 2, -arrowHeight + 1 },
} };
bool isHot = false;
bool isDisabled = false;
for (auto& vert : verts)
{
switch (iStateId)
{
case ABS_UPHOT:// Up
case ABS_UPPRESSED:
isHot = true;
case ABS_UPDISABLED:
isDisabled = true;
case ABS_UPNORMAL:
case ABS_UPHOVER:
vert.x += pRect->left + arrowHeight - 1;
vert.y += pRect->bottom - arrowHeight;
break;
case ABS_DOWNHOT:// Down
case ABS_DOWNPRESSED:
isHot = true;
case ABS_DOWNDISABLED:
isDisabled = true;
case ABS_DOWNNORMAL:
case ABS_DOWNHOVER:
vert.x += pRect->left + arrowHeight - 1;
vert.y = -vert.y + pRect->top + arrowHeight - 1;
break;
case ABS_LEFTHOT:// Left
case ABS_LEFTPRESSED:
isHot = true;
case ABS_LEFTDISABLED:
isDisabled = true;
case ABS_LEFTNORMAL:
case ABS_LEFTHOVER:
std::swap(vert.x, vert.y);
vert.x += pRect->right - arrowHeight;
vert.y += pRect->top + arrowHeight - 1;
break;
case ABS_RIGHTHOT:// Right
case ABS_RIGHTPRESSED:
isHot = true;
case ABS_RIGHTDISABLED:
isDisabled = true;
case ABS_RIGHTNORMAL:
case ABS_RIGHTHOVER:
std::swap(vert.x, vert.y);
vert.x = -vert.x + pRect->left + arrowHeight - 1;
vert.y += pRect->top + arrowHeight - 1;
break;
}
}
HBRUSH fillColor = scrollbarFill;
HGDIOBJ oldPen = SelectObject(hdc, GetStockObject(DC_PEN));
if (isHot)
fillColor = scrollbarFillHighlighted;
else if (isDisabled)
fillColor = scrollbarFill;
FillRect(hdc, pRect, fillColor);
SetDCPenColor(hdc, RGB(255, 255, 255));
PolyPolyline(hdc, verts.data(), counts.data(), counts.size());
SelectObject(hdc, oldPen);
}
return S_OK;
case SBP_GRIPPERHORZ: // Horizontal resize scrollbar
case SBP_GRIPPERVERT: // Vertical resize scrollbar
case SBP_SIZEBOX: // Resize box, bottom right
case SBP_SIZEBOXBKGND: // Resize box, background, unused
break;
}
}
else if (themeType == ThemeType::StatusBar)
{
static HBRUSH statusBarBorder = CreateSolidBrush(RGB(130, 135, 144));// RGB(83, 83, 83)
static HBRUSH statusBarFill = CreateSolidBrush(RGB(56, 56, 56));
switch (iPartId)
{
case 0:
{
// Outside border (top, right)
FillRect(hdc, pRect, statusBarBorder);
}
return S_OK;
case SP_PANE:
case SP_GRIPPERPANE:
case SP_GRIPPER:
{
// Everything else
FillRect(hdc, pRect, statusBarFill);
}
return S_OK;
}
}
else if (themeType == ThemeType::Edit)
{
static HBRUSH editControlBorder = CreateSolidBrush(RGB(130, 135, 144));// RGB(83, 83, 83)
static HBRUSH editControlFill = CreateSolidBrush(RGB(32, 32, 32));
switch (iPartId)
{
case EP_EDITBORDER_NOSCROLL:
{
FillRect(hdc, pRect, editControlFill);
FrameRect(hdc, pRect, editControlBorder);
}
return S_OK;
}
}
else if (themeType == ThemeType::Button)
{
static HBRUSH buttonBorder = CreateSolidBrush(RGB(130, 135, 144));
static HBRUSH buttonBorderHighlighted = CreateSolidBrush(RGB(0, 120, 215));
static HBRUSH buttonFill = CreateSolidBrush(RGB(32, 32, 32));
static HBRUSH buttonPressed = CreateSolidBrush(RGB(83, 83, 83));
switch (iPartId)
{
case BP_PUSHBUTTON:
{
HBRUSH frameColor = buttonBorder;
HBRUSH fillColor = buttonFill;
switch (iStateId)
{
case PBS_HOT:
case PBS_DEFAULTED:
frameColor = buttonBorderHighlighted;
break;
case PBS_DISABLED:
fillColor = buttonBorder;
break;
case PBS_PRESSED:
fillColor = buttonPressed;
break;
}
FillRect(hdc, pRect, fillColor);
FrameRect(hdc, pRect, frameColor);
}
return S_OK;
case BP_CHECKBOX:
{
if (iStateId == CBS_UNCHECKEDDISABLED ||
iStateId == CBS_CHECKEDDISABLED ||
iStateId == CBS_MIXEDDISABLED ||
iStateId == CBS_IMPLICITDISABLED ||
iStateId == CBS_EXCLUDEDDISABLED)
{
FrameRect(hdc, pRect, buttonBorder);
return S_OK;
}
}
break;
}
}
else if (themeType == ThemeType::ComboBox)
{
static HBRUSH comboBoxBorder = CreateSolidBrush(RGB(130, 135, 144));// RGB(83, 83, 83)
static HBRUSH comboBoxFill = CreateSolidBrush(RGB(32, 32, 32));
switch (iPartId)
{
case CP_READONLY: // Main control
{
FillRect(hdc, pRect, iStateId == CBRO_DISABLED ? comboBoxBorder : comboBoxFill);
FrameRect(hdc, pRect, comboBoxBorder);
}
return S_OK;
case CP_BORDER: // Main control with text edit
{
// Special case: dropdown arrow needs to be drawn
DrawThemeBackground(hTheme, hdc, iPartId, iStateId, pRect, pClipRect);
FillRect(hdc, pRect, comboBoxFill);
if (iStateId == CBB_DISABLED)
FillRect(hdc, pRect, comboBoxBorder);
else
FrameRect(hdc, pRect, comboBoxBorder);
}
return S_OK;
case CP_DROPDOWNBUTTONRIGHT:// Dropdown arrow
case CP_DROPDOWNBUTTONLEFT: // Dropdown arrow
break;
case CP_DROPDOWNBUTTON:
case CP_BACKGROUND:
case CP_TRANSPARENTBACKGROUND:
case CP_CUEBANNER:
case CP_DROPDOWNITEM:
return S_OK;
}
}
else if (themeType == ThemeType::Header)
{
static HBRUSH headerFill = CreateSolidBrush(RGB(77, 77, 77));
switch (iPartId)
{
case 0:
case HP_HEADERITEM:
case HP_HEADERITEMLEFT:
case HP_HEADERITEMRIGHT:
{
HGDIOBJ oldPen = SelectObject(hdc, GetStockObject(DC_PEN));
for (int i = 0; i < 2; i++)
{
if (i == 0)
SetDCPenColor(hdc, RGB(65, 65, 65));
else
SetDCPenColor(hdc, RGB(29, 38, 48));
std::array<DWORD, 2> counts{ 2, 2 };
std::array<POINT, 4> verts
{ {
// Right border
{ pRect->right - 2 + i, pRect->top },
{ pRect->right - 2 + i, pRect->bottom },
// Bottom border
{ pRect->left - 1, pRect->bottom - 2 + i },
{ pRect->right - 2, pRect->bottom - 2 + i },
} };
PolyPolyline(hdc, verts.data(), counts.data(), counts.size());
}
// Fill background on hover (1px padding for border shadow)
if ((iPartId == 0 && iStateId == HIS_HOT) ||
(iPartId == HP_HEADERITEM && iStateId == HIS_HOT) ||
(iPartId == HP_HEADERITEMLEFT && iStateId == HILS_HOT) ||
(iPartId == HP_HEADERITEMRIGHT && iStateId == HIRS_HOT))
{
RECT padded = { pRect->left - 1, pRect->top, pRect->right - 1, pRect->bottom - 1 };
FillRect(hdc, &padded, headerFill);
}
SelectObject(hdc, oldPen);
}
return S_OK;
}
}
else if (themeType == ThemeType::TabControl)
{
static HBRUSH tabControlButtonBorder = CreateSolidBrush(RGB(130, 135, 144));// RGB(83, 83, 83)
static HBRUSH tabControlButtonFill = CreateSolidBrush(RGB(56, 56, 56));
switch (iPartId)
{
case TABP_TABITEM: // TCS_MULTILINE middle buttons
case TABP_TABITEMLEFTEDGE: // TCS_MULTILINE leftmost button
case TABP_TABITEMRIGHTEDGE: // TCS_MULTILINE rightmost button
case TABP_TABITEMBOTHEDGE: // TCS_MULTILINE ???
case TABP_TOPTABITEM: // Middle buttons
case TABP_TOPTABITEMLEFTEDGE: // Leftmost button
case TABP_TOPTABITEMRIGHTEDGE: // Rightmost button
case TABP_TOPTABITEMBOTHEDGE: // ???
{
RECT paddedRect = *pRect;
RECT insideRect = { pRect->left + 1, pRect->top + 1, pRect->right - 1, pRect->bottom - 1 };
bool isHover = (iPartId == TABP_TABITEM && iStateId == TIS_HOT) ||
(iPartId == TABP_TABITEMLEFTEDGE && iStateId == TILES_HOT) ||
(iPartId == TABP_TABITEMRIGHTEDGE && iStateId == TIRES_HOT) ||
(iPartId == TABP_TABITEMBOTHEDGE && iStateId == TIBES_HOT) ||
(iPartId == TABP_TOPTABITEM && iStateId == TTIS_HOT) ||
(iPartId == TABP_TOPTABITEMLEFTEDGE && iStateId == TTILES_HOT) ||
(iPartId == TABP_TOPTABITEMRIGHTEDGE && iStateId == TTIRES_HOT) ||
(iPartId == TABP_TOPTABITEMBOTHEDGE && iStateId == TTIBES_HOT);
if ((iPartId == TABP_TABITEM && iStateId == TIS_SELECTED) ||
(iPartId == TABP_TABITEMLEFTEDGE && iStateId == TILES_SELECTED) ||
(iPartId == TABP_TABITEMRIGHTEDGE && iStateId == TIRES_SELECTED) ||
(iPartId == TABP_TABITEMBOTHEDGE && iStateId == TIBES_SELECTED) ||
(iPartId == TABP_TOPTABITEM && iStateId == TTIS_SELECTED) ||
(iPartId == TABP_TOPTABITEMLEFTEDGE && iStateId == TTILES_SELECTED) ||
(iPartId == TABP_TOPTABITEMRIGHTEDGE && iStateId == TTIRES_SELECTED) ||
(iPartId == TABP_TOPTABITEMBOTHEDGE && iStateId == TTIBES_SELECTED))
{
paddedRect.top += 1;
paddedRect.bottom -= 2;
// Allow the rect to overlap so the bottom border outline is removed
insideRect.top += 1;
insideRect.bottom += 1;
}
FrameRect(hdc, &paddedRect, tabControlButtonBorder);
FillRect(hdc, &insideRect, isHover ? tabControlButtonBorder : tabControlButtonFill);
}
return S_OK;
case TABP_PANE:
return S_OK;
}
}
return DrawThemeBackground(hTheme, hdc, iPartId, iStateId, pRect, pClipRect);
}
}