Skip to content

Commit

Permalink
Bug fix: Using list header color appropriate for the actual light/dar…
Browse files Browse the repository at this point in the history
…k column background color (list headers are not dark, unless system wide app dark mode is enabled)

Source commit: 949f6a1763afd3c5854de09f87f436cc4e625f40
  • Loading branch information
martinprikryl committed Jul 30, 2020
1 parent 7ecbbb0 commit 552fb41
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 25 deletions.
2 changes: 1 addition & 1 deletion source/forms/CustomScpExplorer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9038,7 +9038,7 @@ void __fastcall TCustomScpExplorerForm::ThemeChanged()
{
// We hoped this will refresh scrollbar colors, but it does not have any effect here.
RefreshColorMode();
WinConfiguration->ResetSysDarkTheme();
ResetSysDarkTheme();
ConfigurationChanged();
ConfigureInterface();
// Should be called for all controls
Expand Down
6 changes: 4 additions & 2 deletions source/packages/filemng/CustomDirView.pas
Original file line number Diff line number Diff line change
Expand Up @@ -921,8 +921,10 @@ procedure TCustomDirView.ClearItems;

procedure TCustomDirView.WMNotify(var Msg: TWMNotify);
begin
// This all is to make header text white in dark mode
if DarkMode and SupportsDarkMode and (FHeaderHandle <> 0) and (Msg.NMHdr^.hWndFrom = FHeaderHandle) then
// This all is to make header text white in dark mode.
if DarkMode and SupportsDarkMode and
GetSysDarkTheme and // When system app theme is light, headers are not dark
(FHeaderHandle <> 0) and (Msg.NMHdr^.hWndFrom = FHeaderHandle) then
begin
if Msg.NMHdr.code = NM_CUSTOMDRAW then
begin
Expand Down
54 changes: 53 additions & 1 deletion source/packages/my/PasTools.pas
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ function SupportsDarkMode: Boolean;
procedure AllowDarkModeForWindow(Control: TWinControl; Allow: Boolean); overload;
procedure AllowDarkModeForWindow(Handle: THandle; Allow: Boolean); overload;
procedure RefreshColorMode;
procedure ResetSysDarkTheme;
function GetSysDarkTheme: Boolean;

type
TApiPathEvent = function(Path: string): string;
Expand Down Expand Up @@ -148,7 +150,7 @@ TListBoxScrollOnDragOver = class(TCustomControlScrollOnDragOver)
implementation

uses
SysUtils, StdCtrls, Graphics, MultiMon, ShellAPI, Generics.Collections, CommCtrl, ImgList;
SysUtils, StdCtrls, Graphics, MultiMon, ShellAPI, Generics.Collections, CommCtrl, ImgList, Registry;

const
DDExpandDelay = 15000000;
Expand Down Expand Up @@ -1025,6 +1027,54 @@ procedure RefreshColorMode;
end;
end;

var
SysDarkTheme: Integer;

procedure ResetSysDarkTheme;
begin
SysDarkTheme := -1;
end;

function DoGetSysDarkTheme(RootKey: HKEY): Integer;
const
ThemesPersonalizeKey = 'Software\Microsoft\Windows\CurrentVersion\Themes\Personalize';
AppsUseLightThemeValue = 'AppsUseLightTheme';
var
Registry: TRegistry;
begin
Registry := TRegistry.Create;
try
Registry.RootKey := RootKey;
Result := -1;
if Registry.OpenKeyReadOnly(ThemesPersonalizeKey) and
Registry.ValueExists(AppsUseLightThemeValue) then
begin
if Registry.ReadBool(AppsUseLightThemeValue) then Result := 0
else Result := 1;
end;
finally
Registry.Free;
end;
end;

function GetSysDarkTheme: Boolean;
begin
if SysDarkTheme < 0 then
begin
SysDarkTheme := DoGetSysDarkTheme(HKEY_CURRENT_USER);
if SysDarkTheme < 0 then
begin
SysDarkTheme := DoGetSysDarkTheme(HKEY_LOCAL_MACHINE);
if SysDarkTheme < 0 then
begin
SysDarkTheme := 0;
end;
end;
end;

Result := (SysDarkTheme > 0);
end;

var
Lib: THandle;
OSVersionInfo: TOSVersionInfoEx;
Expand Down Expand Up @@ -1072,6 +1122,8 @@ initialization
end;
end;

ResetSysDarkTheme;

finalization
// No need to release individual image lists as they are owned by Application object.
FreeAndNil(ShellImageLists);
Expand Down
21 changes: 1 addition & 20 deletions source/windows/WinConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,6 @@ bool __fastcall TEditorList::IsDefaultList() const
//---------------------------------------------------------------------------
__fastcall TWinConfiguration::TWinConfiguration(): TCustomWinConfiguration()
{
ResetSysDarkTheme();
FInvalidDefaultTranslationMessage = L"";
FDDExtInstalled = -1;
FBookmarks = new TBookmarks();
Expand Down Expand Up @@ -2122,34 +2121,16 @@ static int __fastcall SysDarkTheme(HKEY RootKey)
return Result;
}
//---------------------------------------------------------------------------
void __fastcall TWinConfiguration::ResetSysDarkTheme()
{
FSysDarkTheme = -1;
}
//---------------------------------------------------------------------------
bool __fastcall TWinConfiguration::UseDarkTheme()
{
if (FSysDarkTheme < 0)
{
FSysDarkTheme = SysDarkTheme(HKEY_CURRENT_USER);
if (FSysDarkTheme < 0)
{
FSysDarkTheme = SysDarkTheme(HKEY_LOCAL_MACHINE);
if (FSysDarkTheme < 0)
{
FSysDarkTheme = 0;
}
}
}

switch (WinConfiguration->DarkTheme)
{
case asOn:
return true;
case asOff:
return false;
default:
return (FSysDarkTheme > 0);
return (GetSysDarkTheme() > 0);
}
}
//---------------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion source/windows/WinConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,6 @@ class TWinConfiguration : public TCustomWinConfiguration
bool __fastcall IsDDExtRunning();
bool __fastcall IsDDExtBroken();
bool __fastcall UseDarkTheme();
void __fastcall ResetSysDarkTheme();

static void __fastcall RestoreFont(const TFontConfiguration & Configuration, TFont * Font);
static void __fastcall StoreFont(TFont * Font, TFontConfiguration & Configuration);
Expand Down

0 comments on commit 552fb41

Please sign in to comment.