Browse Source

Make sure we don't realign the outer pages too early (before InitializeFont is called). Think this got triggered by the HandledNeeded calls.

Also avoids doing any unneeded realigning when the window size isn't actually changing, making sure we don't interfere with existing scripts which might do odd things like changing WizardBitmapImage.Align to alClient - see recent ng post.

Using alCustom on the controls and TWizardForm.OnAlignPosition instead of OnResize might also work and be cleaner but didn't try.

PS: I really dislike this kind of VCL programming...
Martijn Laan 6 years ago
parent
commit
d6a9c742b7
2 changed files with 49 additions and 37 deletions
  1. 0 1
      Projects/Wizard.dfm
  2. 49 36
      Projects/Wizard.pas

+ 0 - 1
Projects/Wizard.dfm

@@ -15,7 +15,6 @@ object WizardForm: TWizardForm
   OldCreateOrder = True
   OldCreateOrder = True
   Scaled = False
   Scaled = False
   OnClose = FormClose
   OnClose = FormClose
-  OnResize = FormResize
   DesignSize = (
   DesignSize = (
     497
     497
     360)
     360)

+ 49 - 36
Projects/Wizard.pas

@@ -169,7 +169,6 @@ type
     procedure UserInfoEditChange(Sender: TObject);
     procedure UserInfoEditChange(Sender: TObject);
     procedure DirBrowseButtonClick(Sender: TObject);
     procedure DirBrowseButtonClick(Sender: TObject);
     procedure GroupBrowseButtonClick(Sender: TObject);
     procedure GroupBrowseButtonClick(Sender: TObject);
-    procedure FormResize(Sender: TObject);
   private
   private
     { Private declarations }
     { Private declarations }
     FPageList: TList;
     FPageList: TList;
@@ -186,10 +185,12 @@ type
     DoneWithWizard: Boolean;
     DoneWithWizard: Boolean;
     PrepareToInstallNeedsRestart: Boolean;
     PrepareToInstallNeedsRestart: Boolean;
     procedure AdjustFocus;
     procedure AdjustFocus;
+    procedure AnchorOuterPagesOnResize(Sender: TObject);
     procedure CalcCurrentComponentsSpace;
     procedure CalcCurrentComponentsSpace;
     procedure ChangeReadyLabel(const S: String);
     procedure ChangeReadyLabel(const S: String);
     function CheckSerialOk: Boolean;
     function CheckSerialOk: Boolean;
     procedure CreateTaskButtons(const SelectedComponents: TStringList);
     procedure CreateTaskButtons(const SelectedComponents: TStringList);
+    procedure EnableAnchorOuterPagesOnResize;
     procedure FindPreviousData;
     procedure FindPreviousData;
     function GetPreviousPageID: Integer;
     function GetPreviousPageID: Integer;
     function PrepareToInstall(const WizardComponents, WizardTasks: TStringList): String;
     function PrepareToInstall(const WizardComponents, WizardTasks: TStringList): String;
@@ -767,6 +768,7 @@ begin
     ClientWidth := SaveClientWidth;
     ClientWidth := SaveClientWidth;
     ClientHeight := SaveClientHeight;
     ClientHeight := SaveClientHeight;
     if shWizardResizable in SetupHeader.Options then begin
     if shWizardResizable in SetupHeader.Options then begin
+      EnableAnchorOuterPagesOnResize;
       { Do not allow user to resize it smaller than the current size. }
       { Do not allow user to resize it smaller than the current size. }
       Constraints.MinHeight := Height;
       Constraints.MinHeight := Height;
       Constraints.MinWidth := Width;
       Constraints.MinWidth := Width;
@@ -1165,13 +1167,55 @@ begin
     NoIconsCheck.Visible := False;
     NoIconsCheck.Visible := False;
 end;
 end;
 
 
+procedure TWizardForm.AnchorOuterPagesOnResize(Sender: TObject);
+
+  procedure AnchorOuterPage(const Page: TNewNotebookPage;
+    const BitmapImage: TBitmapImage);
+  var
+    Ctl: TControl;
+    I, NewLeft, NewWidth: Integer;
+  begin
+    if BaseUnitX = 0 then
+      InternalError('AnchorOuterPage: BaseUnitX = 0');
+
+    NewWidth := MulDiv(BitmapImage.Height, 164, 314);
+    if ControlsFlipped then
+      BitmapImage.Left := ClientWidth - NewWidth;
+    BitmapImage.Width := NewWidth;
+    for I := 0 to Page.ControlCount-1 do begin
+      Ctl := Page.Controls[I];
+      if Ctl <> BitmapImage then begin
+        NewLeft := BitmapImage.Width + ScalePixelsX(12); // 12 is space between bitmap and controls
+        Ctl.Width := ClientWidth - ScalePixelsX(20) - NewLeft; //20 is space between controls and right border
+        if not ControlsFlipped then
+          Ctl.Left := NewLeft;
+      end;
+    end;
+  end;
+
+begin
+  { WizardBitmapImage(2)'s size is already corrected by the Anchors property but
+    this doesn't keep the aspect ratio. Calculate and set new width to restore
+    the aspect ratio and update all the other controls in the page for this. }
+  AnchorOuterPage(WelcomePage, WizardBitmapImage);
+  AnchorOuterPage(FinishedPage, WizardBitmapImage2);
+end;
+
+procedure TWizardForm.EnableAnchorOuterPagesOnResize;
+begin
+  OnResize := AnchorOuterPagesOnResize;
+end;
+
 procedure TWizardForm.SizeAndCenter;
 procedure TWizardForm.SizeAndCenter;
 begin
 begin
   { Apply custom initial size from script }
   { Apply custom initial size from script }
-  if SetupHeader.WizardSizePercentX > 100 then
-    ClientWidth := MulDiv(ClientWidth, SetupHeader.WizardSizePercentX, 100);
-  if SetupHeader.WizardSizePercentY > 100 then
-    ClientHeight := MulDiv(ClientHeight, SetupHeader.WizardSizePercentY, 100);
+  if (SetupHeader.WizardSizePercentX > 100) or (SetupHeader.WizardSizePercentY > 100) then begin
+    EnableAnchorOuterPagesOnResize;
+    if SetupHeader.WizardSizePercentX > 100 then
+      ClientWidth := MulDiv(ClientWidth, SetupHeader.WizardSizePercentX, 100);
+    if SetupHeader.WizardSizePercentY > 100 then
+      ClientHeight := MulDiv(ClientHeight, SetupHeader.WizardSizePercentY, 100);
+  end;
 
 
   { Center }
   { Center }
   if shWindowVisible in SetupHeader.Options then
   if shWindowVisible in SetupHeader.Options then
@@ -2401,37 +2445,6 @@ begin
   Action := caNone;
   Action := caNone;
 end;
 end;
 
 
-procedure TWizardForm.FormResize(Sender: TObject);
-
-  procedure AnchorOuterPage(const Page: TNewNotebookPage;
-    const BitmapImage: TBitmapImage);
-  var
-    Ctl: TControl;
-    I, NewLeft, NewWidth: Integer;
-  begin
-    NewWidth := MulDiv(BitmapImage.Height, 164, 314);
-    if ControlsFlipped then
-      BitmapImage.Left := ClientWidth - NewWidth;
-    BitmapImage.Width := NewWidth;
-    for I := 0 to Page.ControlCount-1 do begin
-      Ctl := Page.Controls[I];
-      if Ctl <> BitmapImage then begin
-        NewLeft := BitmapImage.Width + ScalePixelsX(12); // 12 is space between bitmap and controls
-        Ctl.Width := ClientWidth - ScalePixelsX(20) - NewLeft; //20 is space between controls and right border
-        if not ControlsFlipped then
-          Ctl.Left := NewLeft;
-      end;
-    end;
-  end;
-
-begin
-  { WizardBitmapImage(2)'s size is already corrected by the Anchors property but
-    this doesn't keep the aspect ratio. Calculate and set new width to restore
-    the aspect ratio and update all the other controls in the page for this. }
-  AnchorOuterPage(WelcomePage, WizardBitmapImage);
-  AnchorOuterPage(FinishedPage, WizardBitmapImage2);
-end;
-
 procedure TWizardForm.TypesComboChange(Sender: TObject);
 procedure TWizardForm.TypesComboChange(Sender: TObject);
 var
 var
   TypeEntry: PSetupTypeEntry;
   TypeEntry: PSetupTypeEntry;