summaryrefslogtreecommitdiffstats
path: root/Tools/msi/bundle/bootstrap/PythonBootstrapperApplication.cpp
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@microsoft.com>2015-05-31 23:39:46 (GMT)
committerSteve Dower <steve.dower@microsoft.com>2015-05-31 23:39:46 (GMT)
commit83f34aa4f856201ac4fab3509707e012c1f984f8 (patch)
treea3fd769de16eacaf7fd7fcd0bade712c364bf101 /Tools/msi/bundle/bootstrap/PythonBootstrapperApplication.cpp
parent4640b300e32fda6f2a5fffc54de9d6e0cd5941d2 (diff)
downloadcpython-83f34aa4f856201ac4fab3509707e012c1f984f8.zip
cpython-83f34aa4f856201ac4fab3509707e012c1f984f8.tar.gz
cpython-83f34aa4f856201ac4fab3509707e012c1f984f8.tar.bz2
Issue #24293: Adds mapping from explicit colours to system colours to correctly handle user themes.
Diffstat (limited to 'Tools/msi/bundle/bootstrap/PythonBootstrapperApplication.cpp')
-rw-r--r--Tools/msi/bundle/bootstrap/PythonBootstrapperApplication.cpp57
1 files changed, 52 insertions, 5 deletions
diff --git a/Tools/msi/bundle/bootstrap/PythonBootstrapperApplication.cpp b/Tools/msi/bundle/bootstrap/PythonBootstrapperApplication.cpp
index 7f5af74..0c40be5 100644
--- a/Tools/msi/bundle/bootstrap/PythonBootstrapperApplication.cpp
+++ b/Tools/msi/bundle/bootstrap/PythonBootstrapperApplication.cpp
@@ -1475,6 +1475,8 @@ private:
POINT ptCursor = { };
HMONITOR hMonitor = nullptr;
MONITORINFO mi = { };
+ COLORREF fg, bg;
+ HBRUSH bgBrush;
// If the theme did not provide an icon, try using the icon from the bundle engine.
if (!hIcon) {
@@ -1484,12 +1486,23 @@ private:
}
}
+ fg = RGB(0, 0, 0);
+ bg = RGB(255, 255, 255);
+ bgBrush = (HBRUSH)(COLOR_WINDOW+1);
+ if (_theme->dwFontId < _theme->cFonts) {
+ THEME_FONT *font = &_theme->rgFonts[_theme->dwFontId];
+ fg = font->crForeground;
+ bg = font->crBackground;
+ bgBrush = font->hBackground;
+ RemapColor(&fg, &bg, &bgBrush);
+ }
+
// Register the window class and create the window.
wc.lpfnWndProc = PythonBootstrapperApplication::WndProc;
wc.hInstance = _hModule;
wc.hIcon = hIcon;
wc.hCursor = ::LoadCursorW(nullptr, (LPCWSTR)IDC_ARROW);
- wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
+ wc.hbrBackground = bgBrush;
wc.lpszMenuName = nullptr;
wc.lpszClassName = PYBA_WINDOW_CLASS;
if (!::RegisterClassW(&wc)) {
@@ -1704,12 +1717,12 @@ private:
}
break;
+ case WM_CTLCOLORSTATIC:
case WM_CTLCOLORBTN:
if (pBA) {
- HWND button = (HWND)lParam;
- DWORD style = GetWindowLong(button, GWL_STYLE) & BS_TYPEMASK;
- if (style == BS_COMMANDLINK || style == BS_DEFCOMMANDLINK) {
- return (LRESULT)pBA->_theme->rgFonts[pBA->_theme->dwFontId].hBackground;
+ HBRUSH brush = nullptr;
+ if (pBA->SetControlColor((HWND)lParam, (HDC)wParam, &brush)) {
+ return (LRESULT)brush;
}
}
break;
@@ -1782,6 +1795,40 @@ private:
return SUCCEEDED(hr);
}
+ void RemapColor(COLORREF *fg, COLORREF *bg, HBRUSH *bgBrush) {
+ if (*fg == RGB(0, 0, 0)) {
+ *fg = GetSysColor(COLOR_WINDOWTEXT);
+ } else if (*fg == RGB(128, 128, 128)) {
+ *fg = GetSysColor(COLOR_GRAYTEXT);
+ }
+ if (*bgBrush && *bg == RGB(255, 255, 255)) {
+ *bg = GetSysColor(COLOR_WINDOW);
+ *bgBrush = GetSysColorBrush(COLOR_WINDOW);
+ }
+ }
+
+ BOOL SetControlColor(HWND hWnd, HDC hDC, HBRUSH *brush) {
+ for (int i = 0; i < _theme->cControls; ++i) {
+ if (_theme->rgControls[i].hWnd != hWnd) {
+ continue;
+ }
+
+ DWORD fontId = _theme->rgControls[i].dwFontId;
+ if (fontId > _theme->cFonts) {
+ fontId = 0;
+ }
+ THEME_FONT *fnt = &_theme->rgFonts[fontId];
+
+ COLORREF fg = fnt->crForeground, bg = fnt->crBackground;
+ *brush = fnt->hBackground;
+ RemapColor(&fg, &bg, brush);
+ SetTextColor(hDC, fg);
+ SetBkColor(hDC, bg);
+
+ return TRUE;
+ }
+ return FALSE;
+ }
//
// OnShowFailure - display the failure page.