1
0
Эх сурвалжийг харах

Bug fix: Using list header color appropriate for the actual light/dark column background color (list headers are not dark, unless system wide app dark mode is enabled)

(cherry picked from commit 552fb41d8b46564d607d3d291364e545d5ff7978)

Source commit: 1f267294c40046dc59ccedcd0b8ca9e2646b6955
Martin Prikryl 5 жил өмнө
parent
commit
5e90b35566

+ 1 - 1
source/forms/CustomScpExplorer.cpp

@@ -9035,7 +9035,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

+ 4 - 2
source/packages/filemng/CustomDirView.pas

@@ -921,8 +921,10 @@ end;
 
 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

+ 53 - 1
source/packages/my/PasTools.pas

@@ -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;
@@ -148,7 +150,7 @@ type
 implementation
 
 uses
-  SysUtils, StdCtrls, Graphics, MultiMon, ShellAPI, Generics.Collections, CommCtrl, ImgList;
+  SysUtils, StdCtrls, Graphics, MultiMon, ShellAPI, Generics.Collections, CommCtrl, ImgList, Registry;
 
 const
   DDExpandDelay = 15000000;
@@ -1025,6 +1027,54 @@ begin
   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;
@@ -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);

+ 1 - 20
source/windows/WinConfiguration.cpp

@@ -472,7 +472,6 @@ bool __fastcall TEditorList::IsDefaultList() const
 //---------------------------------------------------------------------------
 __fastcall TWinConfiguration::TWinConfiguration(): TCustomWinConfiguration()
 {
-  ResetSysDarkTheme();
   FInvalidDefaultTranslationMessage = L"";
   FDDExtInstalled = -1;
   FBookmarks = new TBookmarks();
@@ -2122,26 +2121,8 @@ 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:
@@ -2149,7 +2130,7 @@ bool __fastcall TWinConfiguration::UseDarkTheme()
     case asOff:
       return false;
     default:
-      return (FSysDarkTheme > 0);
+      return (GetSysDarkTheme() > 0);
   }
 }
 //---------------------------------------------------------------------------

+ 0 - 1
source/windows/WinConfiguration.h

@@ -657,7 +657,6 @@ public:
   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);