Просмотр исходного кода

UnsupportedDarkThemeWindows counter

Source commit: 027dc5c64608601944c35d34c63398f1c76abd20
Martin Prikryl 6 месяцев назад
Родитель
Сommit
75cf13653a

+ 1 - 0
source/forms/CustomScpExplorer.cpp

@@ -299,6 +299,7 @@ __fastcall TCustomScpExplorerForm::TCustomScpExplorerForm(TComponent* Owner):
   // Start loading drive data, so that they are ready once we need them for StartCreationDirectoryMonitorsOnEachDrive
   // (necessary for "explorer" only, as "commander" loads it for its drive menu)
   DriveInfo->NeedData();
+  UsesCustomColorMode(this);
 }
 //---------------------------------------------------------------------------
 __fastcall TCustomScpExplorerForm::~TCustomScpExplorerForm()

+ 1 - 0
source/forms/Editor.cpp

@@ -776,6 +776,7 @@ __fastcall TEditorForm::TEditorForm(TComponent* Owner)
   UseSystemSettings(this);
   UseDesktopFont(StatusBar);
   FixFormIcons(this);
+  UsesCustomColorMode(this);
 }
 //---------------------------------------------------------------------------
 __fastcall TEditorForm::~TEditorForm()

+ 51 - 0
source/windows/VCLCommon.cpp

@@ -40,10 +40,12 @@ public:
   {
     WindowStateBeforeMimimize = wsNormal;
     DarkMode = false;
+    DarkModeCustom = false;
   }
 
   TWindowState WindowStateBeforeMimimize;
   bool DarkMode;
+  bool DarkModeCustom;
 };
 //---------------------------------------------------------------------------
 static TFormCustomizationComponent * GetFormCustomizationComponent(TCustomForm * Form)
@@ -638,6 +640,42 @@ static void __fastcall ChangeFormPixelsPerInch(TForm * Form)
   ChangeControlScale(Form);
 }
 //---------------------------------------------------------------------------
+void CollectFormUsage(TForm * Form)
+{
+  if (WinConfiguration->UseDarkTheme())
+  {
+    TFormCustomizationComponent * CustomizationComponent = GetFormCustomizationComponent(Form);
+    if (!CustomizationComponent->DarkMode && !CustomizationComponent->DarkModeCustom)
+    {
+      const UnicodeString CounterName = L"UnsupportedDarkThemeWindows";
+      std::unique_ptr<TStrings> Windows(CommaTextToStringList(Configuration->Usage->Get(CounterName)));
+
+      UnicodeString ClassName = Form->ClassName();
+      ClassName = RemoveSuffix(ClassName, L"Dialog");
+      UnicodeString TPrefix = L"T";
+      if (StartsStr(TPrefix, ClassName))
+      {
+        ClassName.Delete(1, TPrefix.Length());
+      }
+
+      int Index = Windows->IndexOf(ClassName);
+      if (Index >= 0)
+      {
+        Windows->Delete(Index);
+      }
+
+      Windows->Insert(0, ClassName);
+
+      while (Windows->Count > 4)
+      {
+        Windows->Delete(Windows->Count - 1);
+      }
+
+      Configuration->Usage->Set(CounterName, Windows->CommaText);
+    }
+  }
+}
+//---------------------------------------------------------------------------
 static void __fastcall FormShowingChanged(TForm * Form, TWndMethod WndProc, TMessage & Message)
 {
   if (IsMainFormLike(Form))
@@ -779,6 +817,11 @@ static void __fastcall FormShowingChanged(TForm * Form, TWndMethod WndProc, TMes
         SWP_NOZORDER + SWP_NOACTIVATE);
     }
   }
+
+  if (Form->Showing && Configuration->Usage->Collect)
+  {
+    CollectFormUsage();
+  }
 }
 //---------------------------------------------------------------------------
 TWindowState GetWindowStateBeforeMimimize(TForm * Form)
@@ -1186,6 +1229,14 @@ void ApplyColorMode(TForm * Form)
   }
 }
 //---------------------------------------------------------------------------
+void UsesCustomColorMode(TForm * Form)
+{
+  if (WinConfiguration->UseDarkTheme())
+  {
+    GetFormCustomizationComponent(Form)->DarkModeCustom = true;
+  }
+}
+//---------------------------------------------------------------------------
 void ApplyColorModeOnControl(TControl * Control)
 {
   if (UseDarkModeForControl(Control))

+ 1 - 0
source/windows/VCLCommon.h

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