Browse Source

Make use of TStyleManager.FormBorderStyle which I didn't know about before. Prime benefit is SetupForm not having to update StyleElements anymore.

Martijn Laan 1 day ago
parent
commit
2bff8c54a9

+ 9 - 0
Components/Themes.pas

@@ -138,11 +138,15 @@ type
   TSystemHook = (shMenus, shDialogs, shToolTips);
   TSystemHooks = set of TSystemHook;
 
+  TFormBorderStyle = (fbsCurrentStyle, fbsSystemStyle);
+
   TStyleManager = class
     type TStyleServicesHandle = type Pointer;
     class var AutoDiscoverStyleResources: Boolean;
     class var SystemHooks: TSystemHooks;
     class var SystemStyleName: String;
+    class var FormBorderStyle: TFormBorderStyle;
+    class constructor Create;
     class procedure SetStyle(Handle: TStyleServicesHandle);
     class function TryLoadFromResource(Instance: HINST; const ResourceName: string;
       ResourceType: PChar; var Handle: TStyleServicesHandle): Boolean;
@@ -253,6 +257,11 @@ end;
 
 { TStyleManager }
 
+class constructor TStyleManager.Create;
+begin
+  FormBorderStyle := fbsSystemStyle;
+end;
+
 class procedure TStyleManager.SetStyle(Handle: TStyleServicesHandle);
 begin
 end;

+ 2 - 0
Projects/Src/Setup.MainFunc.pas

@@ -3482,6 +3482,8 @@ begin
           {$ENDIF}
           then begin
             TStyleManager.SetStyle(Handle);
+            if not (shWizardBorderStyled in SetupHeader.Options) then
+              TStyleManager.FormBorderStyle := fbsSystemStyle;
             CustomWizardBackground := SetupHeader.WizardBackColor <> clNone;
             if CustomWizardBackground then begin
               TCustomStyleEngine.RegisterStyleHook(TSetupForm, TFormBackgroundStyleHook);

+ 2 - 10
Projects/Src/Setup.SetupForm.pas

@@ -18,7 +18,6 @@ unit Setup.SetupForm;
   -LangOptions.DialogFontBaseScaleWidth
   -LangOptions.DialogFontBaseScaleHeight
   -SetupHeader.WizardLightControlStyling
-  -shWizardBorderStyled in SetupHeader.Options
   -shWizardKeepAspectRatio in SetupHeader.Options
   Also requires following globals to be set, but 0 is allowed:
   -SetupHeader.WizardSizePercentX
@@ -436,12 +435,6 @@ procedure TSetupForm.CreateWnd;
   end;
 
 begin
-  { Updating StyleElements causes a RecreateWnd if Handle is allocated
-    which is why we update it before calling inherited. See also
-    related SetDarkTitleBar call below. }
-  if not (shWizardBorderStyled in SetupHeader.Options) then
-    StyleElements := StyleElements - [seBorder];
-
   { DisableChildControlsStylesAsNeeded works both before and after
     calling inherited. But it does require the child controls to have
     no handle allocated, which is why it's in CreateWnd and not in
@@ -460,9 +453,8 @@ begin
     AddToWindowMessageFilterEx(Handle, WM_QueryCancelAutoPlay);
 
   { SetDarkTitleBar requires Handle to be allocated, which is why we
-    we call it after calling inherited. See also related StyleElements
-    update above. }
-  if not (seBorder in StyleElements) then
+    we call it after calling inherited. }
+  if (TStyleManager.FormBorderStyle = fbsSystemStyle) or not (seBorder in StyleElements) then
     SetDarkTitleBar(Self, IsDarkInstallMode);
 
   { We don't use the Scaled property for scaling and this means the CurrentPPI property will not be

+ 2 - 0
Projects/Src/Setup.Uninstall.pas

@@ -587,6 +587,8 @@ begin
       {$ENDIF }
       then begin
         TStyleManager.SetStyle(Handle);
+        if not (shWizardBorderStyled in SetupHeader.Options) then
+          TStyleManager.FormBorderStyle := fbsSystemStyle;
         CustomWizardBackground := (SetupHeader.WizardBackColor <> clNone) and
           (SetupHeader.WizardBackColor <> clWindow); { Unlike Setup, Uninstall doesn't support background images which is why this extra check is here }
         if CustomWizardBackground then begin

+ 4 - 3
Projects/Src/Shared.CommonFunc.Vcl.pas

@@ -67,8 +67,8 @@ implementation
 {$IFEND}
 
 uses
-  DwmApi, Consts, PathFunc,
-  {$IFDEF USETASKDIALOGFORM} CommCtrl, Themes, Setup.TaskDialogForm, {$ENDIF}
+  DwmApi, Consts, PathFunc, Themes,
+  {$IFDEF USETASKDIALOGFORM} CommCtrl, Setup.TaskDialogForm, {$ENDIF}
   {$IFDEF SETUPPROJ} Setup.InstFunc, {$ENDIF}
   Shared.CommonFunc;
 
@@ -284,7 +284,8 @@ begin
     Unlike this article we check for Windows 10 Version 2004 because that's the first version
     that introduced DWMWA_USE_IMMERSIVE_DARK_MODE as 20 (the now documented value) instead of 19 }
   if CurrentWindowsVersionAtLeast(10, 0, 19041) then begin
-    Form.StyleElements := Form.StyleElements - [seBorder];
+    if TStyleManager.FormBorderStyle = fbsCurrentStyle then
+      Form.StyleElements := Form.StyleElements - [seBorder];
     const DWMWA_USE_IMMERSIVE_DARK_MODE = 20;
     var value: BOOL := Dark;
     DwmSetWindowAttribute(Form.Handle, DWMWA_USE_IMMERSIVE_DARK_MODE, @value, SizeOf(value));