Skip to content

Commit

Permalink
consistent naming of Theme*Color() functions
Browse files Browse the repository at this point in the history
  • Loading branch information
kjk committed Nov 2, 2023
1 parent e978027 commit 9efd623
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 32 deletions.
6 changes: 3 additions & 3 deletions src/Canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ static void PaintPageFrameAndShadow(HDC hdc, Rect& bounds, Rect& pageRect, bool
#else
static void PaintPageFrameAndShadow(HDC hdc, Rect& bounds, Rect&, bool) {
AutoDeletePen pen(CreatePen(PS_NULL, 0, 0));
auto col = GetMainWindowBackgroundColor();
auto col = ThemeMainWindowBackgroundColor();
AutoDeleteBrush brush(CreateSolidBrush(col));
ScopedSelectPen restorePen(hdc, pen);
ScopedSelectObject restoreBrush(hdc, brush);
Expand Down Expand Up @@ -892,7 +892,7 @@ static void DrawDocument(MainWindow* win, HDC hdc, RECT* rcArea) {
AutoDeleteBrush brush = CreateSolidBrush(WIN_COL_BLACK);
FillRect(hdc, rcArea, brush);
} else if (0 == nGCols) {
auto col = GetMainWindowBackgroundColor();
auto col = ThemeMainWindowBackgroundColor();
AutoDeleteBrush brush = CreateSolidBrush(col);
FillRect(hdc, rcArea, brush);
} else {
Expand Down Expand Up @@ -1568,7 +1568,7 @@ static void OnPaintError(MainWindow* win) {

HFONT fontRightTxt = CreateSimpleFont(hdc, "MS Shell Dlg", 14);
HGDIOBJ hPrevFont = SelectObject(hdc, fontRightTxt);
auto bgCol = GetMainWindowBackgroundColor();
auto bgCol = ThemeMainWindowBackgroundColor();
AutoDeleteBrush bgBrush = CreateSolidBrush(bgCol);
FillRect(hdc, &ps.rcPaint, bgBrush);
// TODO: should this be "Error opening %s"?
Expand Down
2 changes: 1 addition & 1 deletion src/CanvasAboutUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static void OnPaintAbout(MainWindow* win) {
HDC hdc = BeginPaint(win->hwndCanvas, &ps);

auto txtCol = ThemeWindowTextColor();
auto bgCol = GetMainWindowBackgroundColor();
auto bgCol = ThemeMainWindowBackgroundColor();
if (HasPermission(Perm::SavePreferences | Perm::DiskAccess) && gGlobalPrefs->rememberOpenedFiles &&
gGlobalPrefs->showStartPage) {
DrawHomePage(win, win->buffer->GetDC(), gFileHistory, txtCol, bgCol);
Expand Down
2 changes: 1 addition & 1 deletion src/Caption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void CaptionInfo::UpdateColors(bool activeWindow) {
: GetSysColor(COLOR_INACTIVECAPTIONTEXT);
}
if (gGlobalPrefs->useTabs) {
COLORREF col = GetControlBackgroundColor();
COLORREF col = ThemeControlBackgroundColor();
dwm::SetCaptionColor(::GetParent(hwnd), col);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/HomePage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ static void DrawAbout(HWND hwnd, HDC hdc, Rect rect, Vec<StaticLinkInfo*>& stati
ScopedSelectObject font(hdc, fontLeftTxt); /* Just to remember the orig font */

Rect rc = ClientRect(hwnd);
col = GetMainWindowBackgroundColor();
col = ThemeMainWindowBackgroundColor();
AutoDeleteBrush brushAboutBg = CreateSolidBrush(col);
FillRect(hdc, rc, brushAboutBg);

Expand Down Expand Up @@ -666,7 +666,7 @@ void DrawHomePage(MainWindow* win, HDC hdc, const FileHistory& fileHistory, COLO

HFONT fontText = CreateSimpleFont(hdc, "MS Shell Dlg", 14);

color = GetMainWindowBackgroundColor();
color = ThemeMainWindowBackgroundColor();
FillRect(hdc, rc, color);

bool isRtl = IsUIRightToLeft();
Expand Down
2 changes: 1 addition & 1 deletion src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ void LinkHandler::GotoNamedDest(const char* name) {
}

void UpdateControlsColors(MainWindow* win) {
COLORREF bgCol = GetControlBackgroundColor();
COLORREF bgCol = ThemeControlBackgroundColor();
COLORREF txtCol = ThemeWindowTextColor();

// logfa("retrieved doc colors in tree control: 0x%x 0x%x\n", treeTxtCol, treeBgCol);
Expand Down
2 changes: 1 addition & 1 deletion src/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2039,7 +2039,7 @@ void MenuCustomDrawItem(HWND hwnd, DRAWITEMSTRUCT* dis) {
HFONT font = GetMenuFont();
ScopedSelectFont restoreFont(hdc, font);

COLORREF bgCol = GetMainWindowBackgroundColor();
COLORREF bgCol = ThemeMainWindowBackgroundColor();
COLORREF txtCol = ThemeWindowTextColor();
// TODO: if isDisabled, pick a color that represents disabled
// either add it to theme definition or auto-generate
Expand Down
8 changes: 4 additions & 4 deletions src/SumatraPDF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1447,7 +1447,7 @@ static MainWindow* CreateMainWindow() {
if (!win->isMenuHidden) {
SetMenu(win->hwndFrame, win->menu);
}
win->brControlBgColor = CreateSolidBrush(GetControlBackgroundColor());
win->brControlBgColor = CreateSolidBrush(ThemeControlBackgroundColor());

ShowWindow(win->hwndCanvas, SW_SHOW);
UpdateWindow(win->hwndCanvas);
Expand Down Expand Up @@ -1536,7 +1536,7 @@ void DeleteMainWindow(MainWindow* win) {

static void UpdateThemeForWindow(MainWindow* win) {
DeleteObject(win->brControlBgColor);
win->brControlBgColor = CreateSolidBrush(GetControlBackgroundColor());
win->brControlBgColor = CreateSolidBrush(ThemeControlBackgroundColor());

UpdateControlsColors(win);
RebuildMenuBarForWindow(win);
Expand Down Expand Up @@ -2124,8 +2124,8 @@ static void RerenderFixedPage() {
}

void UpdateDocumentColors() {
COLORREF text, bg;
GetDocumentColors(text, bg);
COLORREF bg;
COLORREF text = ThemeDocumentColors(bg);
// logfa("retrieved doc colors in UpdateDocumentColors: 0x%x 0x%x\n", text, bg);

if ((text == gRenderCache.textColor) && (bg == gRenderCache.backgroundColor)) {
Expand Down
2 changes: 1 addition & 1 deletion src/SumatraProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ static void DrawProperties(HWND hwnd, HDC hdc) {
SetBkMode(hdc, TRANSPARENT);

Rect rcClient = ClientRect(hwnd);
auto col = GetMainWindowBackgroundColor();
auto col = ThemeMainWindowBackgroundColor();
FillRect(hdc, rcClient, col);

col = ThemeWindowTextColor();
Expand Down
2 changes: 1 addition & 1 deletion src/SumatraStartup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) {

gCrashOnOpen = flags.crashOnOpen;

GetDocumentColors(gRenderCache.textColor, gRenderCache.backgroundColor);
gRenderCache.textColor = ThemeDocumentColors(gRenderCache.backgroundColor);
// logfa("retrieved doc colors in WinMain: 0x%x 0x%x\n", gRenderCache.textColor, gRenderCache.backgroundColor);

gIsStartup = true;
Expand Down
13 changes: 7 additions & 6 deletions src/Theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ void SetCurrentThemeFromSettings() {
}
}

void GetDocumentColors(COLORREF& text, COLORREF& bg) {
text = kColBlack;
COLORREF ThemeDocumentColors(COLORREF& bg) {
COLORREF text = kColBlack;
bg = kColWhite;

if (currentThemeIndex == 0) {
Expand All @@ -263,8 +263,7 @@ void GetDocumentColors(COLORREF& text, COLORREF& bg) {
} else {
parsedCol = GetPrefsColor(gGlobalPrefs->fixedPageUI.textColor);
}
text = parsedCol->col;
return;
return parsedCol->col;
}

if (gGlobalPrefs->fixedPageUI.invertColors) {
Expand All @@ -279,15 +278,17 @@ void GetDocumentColors(COLORREF& text, COLORREF& bg) {
bg = AdjustLightness2(bg, 8);
}
}

return text;
}

COLORREF GetControlBackgroundColor() {
COLORREF ThemeControlBackgroundColor() {
// note: we can change it in ThemeUpdateAfterLoadSettings()
return gCurrentTheme->window.controlBackgroundColor;
}

// TODO: migrate from prefs to theme.
COLORREF GetMainWindowBackgroundColor() {
COLORREF ThemeMainWindowBackgroundColor() {
COLORREF bgColor = gCurrentTheme->window.backgroundColor;
if (currentThemeIndex == 0) {
// Special behavior for light theme.
Expand Down
10 changes: 3 additions & 7 deletions src/Theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@ void SetCurrentThemeFromSettings();

int GetCurrentThemeIndex();

// These functions take into account both gPrefs and the theme.
// Access to these colors must go through them until everything is
// configured through themes.
void GetDocumentColors(COLORREF& text, COLORREF& bg);
COLORREF GetMainWindowBackgroundColor();
COLORREF GetControlBackgroundColor();

COLORREF ThemeDocumentColors(COLORREF&);
COLORREF ThemeMainWindowBackgroundColor();
COLORREF ThemeControlBackgroundColor();
COLORREF ThemeWindowBackgroundColor();
COLORREF ThemeWindowTextColor();
COLORREF ThemeWindowControlBackgroundColor();
Expand Down
4 changes: 2 additions & 2 deletions src/Toolbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,8 @@ LRESULT CALLBACK BgSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar
RECT rect;
GetClientRect(hWnd, &rect);
SetTextColor(hdc, ThemeWindowTextColor());
SetBkColor(hdc, GetControlBackgroundColor());
auto bg = CreateSolidBrush(GetControlBackgroundColor());
SetBkColor(hdc, ThemeControlBackgroundColor());
auto bg = CreateSolidBrush(ThemeControlBackgroundColor());
FillRect(hdc, &rect, bg);
DeleteObject(bg);
return 1;
Expand Down
4 changes: 2 additions & 2 deletions src/wingui/WinGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3444,7 +3444,7 @@ void TabsCtrl::Paint(HDC hdc, RECT& rc) {
gfx.SetTextRenderingHint(TextRenderingHintClearTypeGridFit);
gfx.SetPageUnit(UnitPixel);

SolidBrush br(GdipCol(GetControlBackgroundColor()));
SolidBrush br(GdipCol(ThemeControlBackgroundColor()));

Font f(hdc, GetDefaultGuiFont());

Expand All @@ -3462,7 +3462,7 @@ void TabsCtrl::Paint(HDC hdc, RECT& rc) {
Gdiplus::RectF rTxt;

COLORREF textColor = ThemeWindowTextColor();
COLORREF tabBgSelected = GetControlBackgroundColor();
COLORREF tabBgSelected = ThemeControlBackgroundColor();
COLORREF tabBgHighlight;
COLORREF tabBgBackground;
if (IsLightColor(tabBgSelected)) {
Expand Down

0 comments on commit 9efd623

Please sign in to comment.