diff --git a/src/Canvas.cpp b/src/Canvas.cpp index 61081e752d08..56e2b2423d32 100644 --- a/src/Canvas.cpp +++ b/src/Canvas.cpp @@ -981,7 +981,7 @@ static void DrawDocument(MainWindow* win, HDC hdc, RECT* rcArea) { if (renderDelay != 0) { HFONT fontRightTxt = CreateSimpleFont(hdc, "MS Shell Dlg", 14); HGDIOBJ hPrevFont = SelectObject(hdc, fontRightTxt); - auto col = gCurrentTheme->window.textColor; + auto col = ThemeWindowTextColor(); SetTextColor(hdc, col); if (renderDelay != RENDER_DELAY_FAILED) { if (renderDelay < REPAINT_MESSAGE_DELAY_IN_MS) { diff --git a/src/CanvasAboutUI.cpp b/src/CanvasAboutUI.cpp index 1d7e3b28ce5d..632e08c6f08a 100644 --- a/src/CanvasAboutUI.cpp +++ b/src/CanvasAboutUI.cpp @@ -31,7 +31,7 @@ static void OnPaintAbout(MainWindow* win) { PAINTSTRUCT ps; HDC hdc = BeginPaint(win->hwndCanvas, &ps); - auto txtCol = gCurrentTheme->window.textColor; + auto txtCol = ThemeWindowTextColor(); auto bgCol = GetMainWindowBackgroundColor(); if (HasPermission(Perm::SavePreferences | Perm::DiskAccess) && gGlobalPrefs->rememberOpenedFiles && gGlobalPrefs->showStartPage) { diff --git a/src/Caption.cpp b/src/Caption.cpp index 93ab4114ffb3..e88820059aec 100644 --- a/src/Caption.cpp +++ b/src/Caption.cpp @@ -561,7 +561,7 @@ static void DrawCaptionButton(DRAWITEMSTRUCT* item, MainWindow* win) { } // draw the three lines // COLORREF c = win->caption->textColor; - COLORREF c = gCurrentTheme->window.textColor; + COLORREF c = ThemeWindowTextColor(); u8 r, g, b; UnpackColor(c, r, g, b); float width = floor((float)rc.dy / 8.0f); diff --git a/src/HomePage.cpp b/src/HomePage.cpp index 74fec0a9c7ff..7a788cd05931 100644 --- a/src/HomePage.cpp +++ b/src/HomePage.cpp @@ -143,7 +143,7 @@ static void DrawSumatraVersion(HDC hdc, Rect rect) { pt.x += txtSize.dx; } - SetTextColor(hdc, gCurrentTheme->window.textColor); + SetTextColor(hdc, ThemeWindowTextColor()); int x = mainRect.x + mainRect.dx + DpiScale(hdc, kInnerPadding); int y = mainRect.y; @@ -163,7 +163,7 @@ static Rect DrawHideFrequentlyReadLink(HWND hwnd, HDC hdc, const char* txt) { w.withUnderline = true; Size txtSize = w.Measure(true); - auto col = gCurrentTheme->window.linkColor; + auto col = ThemeWindowLinkColor(); ScopedSelectObject pen(hdc, CreatePen(PS_SOLID, 1, col), true); SetTextColor(hdc, col); @@ -212,10 +212,10 @@ static TempStr TrimGitTemp(char* s) { It transcribes the design I did in graphics software - hopeless to understand without seeing the design. */ static void DrawAbout(HWND hwnd, HDC hdc, Rect rect, Vec& staticLinks) { - auto col = gCurrentTheme->window.textColor; + auto col = ThemeWindowTextColor(); AutoDeletePen penBorder(CreatePen(PS_SOLID, ABOUT_LINE_OUTER_SIZE, col)); AutoDeletePen penDivideLine(CreatePen(PS_SOLID, ABOUT_LINE_SEP_SIZE, col)); - col = gCurrentTheme->window.linkColor; + col = ThemeWindowLinkColor(); AutoDeletePen penLinkLine(CreatePen(PS_SOLID, ABOUT_LINE_SEP_SIZE, col)); HFONT fontLeftTxt = CreateSimpleFont(hdc, kLeftTextFont, kLeftTextFontSize); @@ -248,7 +248,7 @@ static void DrawAbout(HWND hwnd, HDC hdc, Rect rect, Vec& stati DrawSumatraVersion(hdc, titleRect); /* render attribution box */ - col = gCurrentTheme->window.textColor; + col = ThemeWindowTextColor(); SetTextColor(hdc, col); SetBkMode(hdc, TRANSPARENT); @@ -271,9 +271,9 @@ static void DrawAbout(HWND hwnd, HDC hdc, Rect rect, Vec& stati for (AboutLayoutInfoEl* el = gAboutLayoutInfo; el->leftTxt; el++) { bool hasUrl = HasPermission(Perm::DiskAccess) && el->url; if (hasUrl) { - col = gCurrentTheme->window.linkColor; + col = ThemeWindowLinkColor(); } else { - col = gCurrentTheme->window.textColor; + col = ThemeWindowTextColor(); } SetTextColor(hdc, col); char* s = (char*)el->rightTxt; @@ -642,7 +642,7 @@ void DrawHomePage(HDC hdc, const HomePageLayout& l) { const Rect& r = l.bAppWithVer; DrawSumatraVersion(hdc, r); - auto color = gCurrentTheme->window.textColor; + auto color = ThemeWindowTextColor(); ScopedSelectObject pen(hdc, CreatePen(PS_SOLID, 1, color), true); DrawLine(hdc, l.bLine); } @@ -658,10 +658,10 @@ void DrawHomePage(MainWindow* win, HDC hdc, const FileHistory& fileHistory, COLO LayoutHomePage(hdc, rc, layout); HWND hwnd = win->hwndFrame; - auto color = gCurrentTheme->window.textColor; + auto color = ThemeWindowTextColor(); AutoDeletePen penThumbBorder(CreatePen(PS_SOLID, kThumbsBorderDx, color)); - color = gCurrentTheme->window.linkColor; + color = ThemeWindowLinkColor(); AutoDeletePen penLinkLine(CreatePen(PS_SOLID, 1, color)); HFONT fontText = CreateSimpleFont(hdc, "MS Shell Dlg", 14); @@ -678,7 +678,7 @@ void DrawHomePage(MainWindow* win, HDC hdc, const FileHistory& fileHistory, COLO /* render recent files list */ SelectObject(hdc, penThumbBorder); SetBkMode(hdc, TRANSPARENT); - color = gCurrentTheme->window.textColor; + color = ThemeWindowTextColor(); SetTextColor(hdc, color); Rect& titleBox = layout.bAppWithVer; @@ -785,7 +785,7 @@ void DrawHomePage(MainWindow* win, HDC hdc, const FileHistory& fileHistory, COLO kThumbsMarginTop + thumbsRows * kThumbnailDy + (thumbsRows - 1) * kThumbsSpaceBetweenY + kThumbsMarginBottom; rc.dy = kThumbsBottomBoxDy; - color = gCurrentTheme->window.linkColor; + color = ThemeWindowLinkColor(); SetTextColor(hdc, color); SelectObject(hdc, penLinkLine); diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 30ce97afc745..06a3650db960 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -625,7 +625,7 @@ void LinkHandler::GotoNamedDest(const char* name) { void UpdateControlsColors(MainWindow* win) { COLORREF bgCol = GetControlBackgroundColor(); - COLORREF txtCol = gCurrentTheme->window.textColor; + COLORREF txtCol = ThemeWindowTextColor(); // logfa("retrieved doc colors in tree control: 0x%x 0x%x\n", treeTxtCol, treeBgCol); diff --git a/src/Menu.cpp b/src/Menu.cpp index fb1c3a16cb70..8fd9bb8e0929 100644 --- a/src/Menu.cpp +++ b/src/Menu.cpp @@ -1918,7 +1918,7 @@ void FreeMenuOwnerDrawInfoData(HMENU hmenu) { }; } void MarkMenuOwnerDraw(HMENU hmenu) { - if (!gCurrentTheme->colorizeControls) { + if (!ThemeColorizeControls()) { return; } WCHAR buf[1024]; @@ -2052,7 +2052,7 @@ void MenuCustomDrawItem(HWND hwnd, DRAWITEMSTRUCT* dis) { ScopedSelectFont restoreFont(hdc, font); COLORREF bgCol = GetMainWindowBackgroundColor(); - COLORREF txtCol = gCurrentTheme->window.textColor; + COLORREF txtCol = ThemeWindowTextColor(); // TODO: if isDisabled, pick a color that represents disabled // either add it to theme definition or auto-generate // (lighter if dark color, darker if light color) diff --git a/src/Notifications.cpp b/src/Notifications.cpp index ee80e7b96754..522087db7d9b 100644 --- a/src/Notifications.cpp +++ b/src/Notifications.cpp @@ -326,13 +326,13 @@ void NotificationWnd::OnPaint(HDC hdcIn, PAINTSTRUCT* ps) { ScopedSelectObject fontPrev(hdc, font); - COLORREF colBg = gCurrentTheme->notifications.backgroundColor; + COLORREF colBg = ThemeNotificationsBackgroundColor(); COLORREF colBorder = MkGray(0xdd); - COLORREF colTxt = gCurrentTheme->notifications.textColor; + COLORREF colTxt = ThemeNotificationsTextColor(); if (highlight) { - colBg = gCurrentTheme->notifications.highlightColor; + colBg = ThemeNotificationsHighlightColor(); colBorder = colBg; - colTxt = gCurrentTheme->notifications.highlightTextColor; + colTxt = ThemeNotificationsHighlightTextColor(); } // COLORREF colBg = MkRgb(0xff, 0xff, 0x5c); // COLORREF colBg = MkGray(0xff); @@ -374,7 +374,7 @@ void NotificationWnd::OnPaint(HDC hdcIn, PAINTSTRUCT* ps) { rc = rProgress; int progressWidth = rc.dx; - COLORREF col = gCurrentTheme->notifications.progressColor; + COLORREF col = ThemeNotificationsProgressColor(); Pen pen(GdiRgbFromCOLORREF(col)); grc = {rc.x, rc.y, rc.dx, rc.dy}; graphics.DrawRectangle(&pen, grc); diff --git a/src/SumatraPDF.cpp b/src/SumatraPDF.cpp index f7e9d60f3bad..2cdbf87371d0 100644 --- a/src/SumatraPDF.cpp +++ b/src/SumatraPDF.cpp @@ -5497,14 +5497,14 @@ LRESULT CALLBACK WndProcSumatraFrame(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) return FrameOnCommand(win, hwnd, msg, wp, lp); case WM_MEASUREITEM: - if (gCurrentTheme->colorizeControls) { + if (ThemeColorizeControls()) { MenuCustomDrawMesureItem(hwnd, (MEASUREITEMSTRUCT*)lp); return TRUE; } break; case WM_DRAWITEM: - if (gCurrentTheme->colorizeControls) { + if (ThemeColorizeControls()) { MenuCustomDrawItem(hwnd, (DRAWITEMSTRUCT*)lp); return TRUE; } diff --git a/src/SumatraProperties.cpp b/src/SumatraProperties.cpp index 0c8c407275f4..23b9f06a1280 100644 --- a/src/SumatraProperties.cpp +++ b/src/SumatraProperties.cpp @@ -615,7 +615,7 @@ static void DrawProperties(HWND hwnd, HDC hdc) { auto col = GetMainWindowBackgroundColor(); FillRect(hdc, rcClient, col); - col = gCurrentTheme->window.textColor; + col = ThemeWindowTextColor(); SetTextColor(hdc, col); /* render text on the left*/ diff --git a/src/Theme.cpp b/src/Theme.cpp index dd74d773015b..f2d2fb32456e 100644 --- a/src/Theme.cpp +++ b/src/Theme.cpp @@ -30,6 +30,43 @@ constexpr COLORREF kColWhite = 0xFFFFFF; // #define kColWhiteish 0xEBEBF9 // #define kColDarkGray 0x424242 +constexpr const int kThemeCount = 3; + +struct MainWindowStyle { + // Background color of recently added, about, and properties menus + COLORREF backgroundColor; + // Background color of controls, menus, non-client areas, etc. + COLORREF controlBackgroundColor; + // Text color of recently added, about, and properties menus + COLORREF textColor; + // Link color on recently added, about, and properties menus + COLORREF linkColor; +}; + +struct NotificationStyle { + // Background color of the notification window + COLORREF backgroundColor; + // Text color of the notification window + COLORREF textColor; + // Color of the highlight box that surrounds the text when a notification is highlighted + COLORREF highlightColor; + // Color of the text when a notification is highlighted + COLORREF highlightTextColor; + // Background color of the progress bar in the notification window + COLORREF progressColor; +}; + +struct Theme { + // Name of the theme + const char* name; + // Style of the main window + MainWindowStyle window; + // Style of notifications + NotificationStyle notifications; + // Whether or not we colorize standard Windows controls and window areas + bool colorizeControls; +}; + // clang-format off static Theme gThemeLight = { // Theme Name @@ -234,7 +271,7 @@ void GetDocumentColors(COLORREF& text, COLORREF& bg) { // if we're inverting in non-default themes, the colors // should match the colors of the window // TODO: this probably only makes sense for dark themes - text = gCurrentTheme->window.textColor; + text = ThemeWindowTextColor(); bg = gCurrentTheme->window.backgroundColor; if (IsLightColor(bg)) { bg = AdjustLightness2(bg, -8); @@ -261,3 +298,43 @@ COLORREF GetMainWindowBackgroundColor() { } return bgColor; } + +COLORREF ThemeWindowBackgroundColor() { + return gCurrentTheme->window.backgroundColor; +} + +COLORREF ThemeWindowTextColor() { + return gCurrentTheme->window.textColor; +} + +COLORREF ThemeWindowControlBackgroundColor() { + return gCurrentTheme->window.controlBackgroundColor; +} + +COLORREF ThemeWindowLinkColor() { + return gCurrentTheme->window.linkColor; +} + +COLORREF ThemeNotificationsBackgroundColor() { + return gCurrentTheme->notifications.backgroundColor; +} + +COLORREF ThemeNotificationsTextColor() { + return gCurrentTheme->notifications.textColor; +} + +COLORREF ThemeNotificationsHighlightColor() { + return gCurrentTheme->notifications.highlightColor; +} + +COLORREF ThemeNotificationsHighlightTextColor() { + return gCurrentTheme->notifications.highlightTextColor; +} + +COLORREF ThemeNotificationsProgressColor() { + return gCurrentTheme->notifications.progressColor; +} + +bool ThemeColorizeControls() { + return gCurrentTheme->colorizeControls; +} diff --git a/src/Theme.h b/src/Theme.h index c03e1f8f5f78..43aa50b32604 100644 --- a/src/Theme.h +++ b/src/Theme.h @@ -3,45 +3,6 @@ License: GPLv3 */ #include "utils/BaseUtil.h" -// The number of themes -constexpr const int kThemeCount = 3; - -struct MainWindowStyle { - // Background color of recently added, about, and properties menus - COLORREF backgroundColor; - // Background color of controls, menus, non-client areas, etc. - COLORREF controlBackgroundColor; - // Text color of recently added, about, and properties menus - COLORREF textColor; - // Link color on recently added, about, and properties menus - COLORREF linkColor; -}; - -struct NotificationStyle { - // Background color of the notification window - COLORREF backgroundColor; - // Text color of the notification window - COLORREF textColor; - // Color of the highlight box that surrounds the text when a notification is highlighted - COLORREF highlightColor; - // Color of the text when a notification is highlighted - COLORREF highlightTextColor; - // Background color of the progress bar in the notification window - COLORREF progressColor; -}; - -struct Theme { - // Name of the theme - const char* name; - // Style of the main window - MainWindowStyle window; - // Style of notifications - NotificationStyle notifications; - // Whether or not we colorize standard Windows controls and window areas - bool colorizeControls; -}; - -extern Theme* gCurrentTheme; void SelectNextTheme(); void SetThemeByIndex(int); @@ -55,3 +16,14 @@ int GetCurrentThemeIndex(); void GetDocumentColors(COLORREF& text, COLORREF& bg); COLORREF GetMainWindowBackgroundColor(); COLORREF GetControlBackgroundColor(); + +COLORREF ThemeWindowBackgroundColor(); +COLORREF ThemeWindowTextColor(); +COLORREF ThemeWindowControlBackgroundColor(); +COLORREF ThemeWindowLinkColor(); +COLORREF ThemeNotificationsBackgroundColor(); +COLORREF ThemeNotificationsTextColor(); +COLORREF ThemeNotificationsHighlightColor(); +COLORREF ThemeNotificationsHighlightTextColor(); +COLORREF ThemeNotificationsProgressColor(); +bool ThemeColorizeControls(); diff --git a/src/Toolbar.cpp b/src/Toolbar.cpp index 615c7ad36d83..fbd706820e73 100644 --- a/src/Toolbar.cpp +++ b/src/Toolbar.cpp @@ -292,11 +292,11 @@ void UpdateFindbox(MainWindow* win) { LRESULT CALLBACK BgSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) { - if (WM_ERASEBKGND == uMsg && gCurrentTheme->colorizeControls) { + if (WM_ERASEBKGND == uMsg && ThemeColorizeControls()) { HDC hdc = (HDC)wParam; RECT rect; GetClientRect(hWnd, &rect); - SetTextColor(hdc, gCurrentTheme->window.textColor); + SetTextColor(hdc, ThemeWindowTextColor()); SetBkColor(hdc, GetControlBackgroundColor()); auto bg = CreateSolidBrush(GetControlBackgroundColor()); FillRect(hdc, &rect, bg); @@ -328,7 +328,7 @@ static LRESULT CALLBACK WndProcToolbar(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp if ((win->hwndFindBg != hStatic && win->hwndPageBg != hStatic) || theme::IsAppThemed()) { // Set color used in "Page:" and "Find:" labels auto col = RGB(0x00, 0x00, 0x00); - SetTextColor(hdc, gCurrentTheme->window.textColor); + SetTextColor(hdc, ThemeWindowTextColor()); SetBkMode(hdc, TRANSPARENT); return (LRESULT)win->brControlBgColor; } diff --git a/src/wingui/WinGui.cpp b/src/wingui/WinGui.cpp index e10ad0c740e3..65d66a84b7da 100644 --- a/src/wingui/WinGui.cpp +++ b/src/wingui/WinGui.cpp @@ -3445,7 +3445,6 @@ void TabsCtrl::Paint(HDC hdc, RECT& rc) { gfx.SetTextRenderingHint(TextRenderingHintClearTypeGridFit); gfx.SetPageUnit(UnitPixel); - Theme* theme = gCurrentTheme; SolidBrush br(GdipCol(GetControlBackgroundColor())); Font f(hdc, GetDefaultGuiFont()); @@ -3463,7 +3462,7 @@ void TabsCtrl::Paint(HDC hdc, RECT& rc) { Rect r; Gdiplus::RectF rTxt; - COLORREF textColor = theme->window.textColor; + COLORREF textColor = ThemeWindowTextColor(); COLORREF tabBgSelected = GetControlBackgroundColor(); COLORREF tabBgHighlight; COLORREF tabBgBackground;