فهرست منبع

Issue 2358 – Dark theme for Authentication Progress window

https://winscp.net/tracker/2358

Source commit: afdf968e3fab22d5e2d6d28fd04c3e84379a63d0
Martin Prikryl 4 ماه پیش
والد
کامیت
e608d8ee82

+ 9 - 1
source/forms/Authenticate.cpp

@@ -210,6 +210,7 @@ TLabel * __fastcall TAuthenticateForm::GenerateLabel(int Current, UnicodeString
 {
   TLabel * Result = CreateLabel(this);
   Result->Parent = FPromptParent;
+  ApplyColorModeOnControl(Result); // noop
 
   Result->Anchors = TAnchors() << akLeft << akTop << akRight;
   Result->WordWrap = true;
@@ -229,9 +230,10 @@ TLabel * __fastcall TAuthenticateForm::GenerateLabel(int Current, UnicodeString
 //---------------------------------------------------------------------------
 TCustomEdit * __fastcall TAuthenticateForm::GenerateEdit(int Current, bool Echo)
 {
-  TEdit * Result = new TEdit(this);
+  TEdit * Result = CreateEdit(this);
   SetEditPasswordMode(Result, !Echo);
   Result->Parent = FPromptParent;
+  ApplyColorModeOnControl(Result);
 
   Result->Anchors = TAnchors() << akLeft << akTop << akRight;
   Result->Top = Current;
@@ -737,3 +739,9 @@ void __fastcall TAuthenticateForm::LinkClick(TObject * Sender)
   LabelOpen(DebugNotNull(dynamic_cast<TLabel *>(Sender)));
 }
 //---------------------------------------------------------------------------
+void __fastcall TAuthenticateForm::CreateWnd()
+{
+  TForm::CreateWnd();
+  ApplyColorMode(this);
+}
+//---------------------------------------------------------------------------

+ 1 - 0
source/forms/Authenticate.h

@@ -108,6 +108,7 @@ protected:
   void ExternalLabel(TLabel * Label);
   void __fastcall LinkClick(TObject * Sender);
   void LabelOpen(TLabel * Label);
+  virtual void __fastcall CreateWnd();
 
 private:
   void * FShowAsModalStorage;

+ 5 - 0
source/windows/GUITools.cpp

@@ -2868,6 +2868,11 @@ void __fastcall TEditEx::CreateWnd()
   SetColorModeTheme(this, L"CFD");
 }
 //---------------------------------------------------------------------------
+TEdit * CreateEdit(TComponent * AOwner)
+{
+  return new TEditEx(AOwner);
+}
+//---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
 class TMemoEx : public TMemo
 {

+ 1 - 0
source/windows/GUITools.h

@@ -43,6 +43,7 @@ TLabel * CreateLabel(TComponent * AOwner);
 TCheckBox * CreateCheckBox(TComponent * AOwner);
 void SetExplorerTheme(TWinControl * Control);
 TButton * CreateButton(TComponent * AOwner);
+TEdit * CreateEdit(TComponent * AOwner);
 TMemo * CreateMemo(TComponent * AOwner);
 void __fastcall SelectScaledImageList(TImageList * ImageList);
 void __fastcall CopyImageList(TImageList * TargetList, TImageList * SourceList);

+ 16 - 15
source/windows/VCLCommon.cpp

@@ -235,7 +235,8 @@ bool IsWindowColorControl(TControl * Control)
     (dynamic_cast<TCustomEdit *>(Control) != NULL) ||
     (dynamic_cast<TCustomComboBox *>(Control) != NULL) ||
     (dynamic_cast<TCustomListView *>(Control) != NULL) ||
-    (dynamic_cast<TCustomTreeView *>(Control) != NULL);
+    (dynamic_cast<TCustomTreeView *>(Control) != NULL) ||
+    (dynamic_cast<TCustomListBox *>(Control) != NULL);
 }
 //---------------------------------------------------------------------------
 bool UseDarkModeForControl(TControl * Control)
@@ -1110,16 +1111,9 @@ void ApplyDarkModeOnControl(TControl * Control)
     TColor BtnFaceColor = GetBtnFaceColor();
     TColor WindowColor = GetWindowColor();
 
-    if (IsWindowColorControl(Control))
-    {
-      DebugAssert((PublicControl->Color == clWindow) || (PublicControl->Color == WindowColor));
-      DebugAssert(!PublicControl->ParentColor);
-      PublicControl->Color = WindowColor;
-    }
-
     bool IsForm = (dynamic_cast<TForm *>(Control) != NULL);
     bool IsPanel = (dynamic_cast<TPanel *>(Control) != NULL);
-    if (IsForm || IsPanel)
+    if (IsWindowColorControl(Control) || IsForm || IsPanel)
     {
       if (PublicControl->ParentColor)
       {
@@ -1131,17 +1125,16 @@ void ApplyDarkModeOnControl(TControl * Control)
         {
           PublicControl->Color = WindowColor;
         }
-        else
+        else if (DebugAlwaysTrue((PublicControl->Color == clBtnFace) || (PublicControl->Color == BtnFaceColor)))
         {
-          DebugAssert((PublicControl->Color == clBtnFace) || (PublicControl->Color == BtnFaceColor));
           PublicControl->Color = BtnFaceColor;
         }
       }
+    }
 
-      if (IsForm)
-      {
-        PublicControl->Font->Color = GetWindowTextColor(PublicControl->Color);
-      }
+    if (IsForm)
+    {
+      PublicControl->Font->Color = GetWindowTextColor(PublicControl->Color);
     }
     else if (dynamic_cast<TTreeView *>(WinControl) != NULL)
     {
@@ -1182,6 +1175,14 @@ void ApplyColorMode(TForm * Form)
   }
 }
 //---------------------------------------------------------------------------
+void ApplyColorModeOnControl(TControl * Control)
+{
+  if (UseDarkModeForControl(Control))
+  {
+    ApplyDarkModeOnControl(Control);
+  }
+}
+//---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
 struct TShowAsModalStorage
 {

+ 1 - 0
source/windows/VCLCommon.h

@@ -29,6 +29,7 @@ void __fastcall ResetSystemSettings(TForm * Control);
 TColor GetControlColor(TControl * Control);
 void UseDarkMode(TForm * Form);
 void ApplyColorMode(TForm * Form);
+void ApplyColorModeOnControl(TControl * Control);
 void __fastcall LinkLabel(TStaticText * StaticText, UnicodeString Url = L"",
   TNotifyEvent OnEnter = NULL);
 void __fastcall LinkActionLabel(TStaticText * StaticText);