Преглед на файлове

Resize before page initialization.

Todo:
-Fix usual issue with needing to call HandledNeeded
-Test task dialog
-Test right-to-left
-Doc
Martijn Laan преди 3 месеца
родител
ревизия
911edd7e89

+ 4 - 6
Examples/CodeClasses.iss

@@ -34,10 +34,9 @@ var
   OKButton, CancelButton: TNewButton;
   W: Integer;
 begin
-  Form := CreateCustomForm();
+  { Keep the form from sizing vertically since we don't have any controls which can size vertically }
+  Form := CreateCustomForm(ScaleX(256), ScaleY(128), False, True);
   try
-    Form.ClientWidth := ScaleX(256);
-    Form.ClientHeight := ScaleY(128);
     Form.Caption := 'TSetupForm';
 
     Edit := TNewEdit.Create(Form);
@@ -74,10 +73,9 @@ begin
     CancelButton.Width := W;
 
     Form.ActiveControl := Edit;
-    { Keep the form from sizing vertically since we don't have any controls which can size vertically }
-    Form.KeepSizeY := True;
+
     { Center on WizardForm. Without this call it will still automatically center, but on the screen }
-    Form.FlipSizeAndCenterIfNeeded(True, WizardForm, False);
+    Form.FlipAndCenterIfNeeded(True, WizardForm, False);
 
     if Form.ShowModal() = mrOk then
       MsgBox('You clicked OK.', mbInformation, MB_OK);

+ 4 - 3
Projects/Src/Compiler.ScriptClasses.pas

@@ -335,12 +335,13 @@ begin
     RegisterMethod('function CalculateButtonWidth(const ButtonCaptions: array of String): Integer;');
     RegisterMethod('function ShouldSizeX: Boolean;');
     RegisterMethod('function ShouldSizeY: Boolean;');
-    RegisterMethod('procedure FlipSizeAndCenterIfNeeded(const ACenterInsideControl: Boolean; const CenterInsideControlCtl: TWinControl; const CenterInsideControlInsideClientArea: Boolean)');
+    RegisterMethod('procedure FlipAndCenterIfNeeded(const ACenterInsideControl: Boolean; const CenterInsideControlCtl: TWinControl; const CenterInsideControlInsideClientArea: Boolean)');
     RegisterProperty('ControlsFlipped', 'Boolean', iptr);
     RegisterProperty('FlipControlsOnShow', 'Boolean', iptrw);
-    RegisterProperty('KeepSizeY', 'Boolean', iptrw);
+    RegisterProperty('KeepSizeX', 'Boolean', iptr);
+    RegisterProperty('KeepSizeY', 'Boolean', iptr);
     RegisterProperty('RightToLeft', 'Boolean', iptr);
-    RegisterProperty('SizeAndCenterOnShow', 'Boolean', iptrw);
+    RegisterProperty('CenterOnShow', 'Boolean', iptrw);
   end;
 end;
 

+ 1 - 1
Projects/Src/Setup.MainFunc.pas

@@ -3807,7 +3807,7 @@ begin
       raise;
     end;
   end;
-  WizardForm.FlipSizeAndCenterIfNeeded(False, nil, False);
+  WizardForm.FlipAndCenterIfNeeded(False, nil, False);
   WizardForm.SetCurPage(wpWelcome);
   if InstallMode = imNormal then begin
     WizardForm.ClickToStartPage; { this won't go past wpReady  }

+ 2 - 3
Projects/Src/Setup.NewDiskForm.pas

@@ -70,7 +70,7 @@ constructor TNewDiskForm.Create(AOwner: TComponent);
 begin
   inherited;
 
-  InitializeFont;
+  InitializeFont(False, True);
 
   Caption := SetupMessages[msgChangeDiskTitle];
   PathLabel.Caption := SetupMessages[msgPathLabel];
@@ -84,10 +84,9 @@ begin
 
   SetForeground := True;
 
-  KeepSizeY := True;
   { WizardForm will not exist yet if we're being called from [Code]'s
     ExtractTemporaryFile in InitializeSetup }
-  FlipSizeAndCenterIfNeeded(Assigned(WizardForm), WizardForm, False);
+  FlipAndCenterIfNeeded(Assigned(WizardForm), WizardForm, False);
 end;
 
 function TNewDiskForm.GetSanitizedPath: String;

+ 1 - 1
Projects/Src/Setup.ScriptClasses.pas

@@ -259,7 +259,7 @@ begin
     RegisterMethod(@TSetupForm.CalculateButtonWidth, 'CalculateButtonWidth');
     RegisterMethod(@TSetupForm.ShouldSizeX, 'ShouldSizeX');
     RegisterMethod(@TSetupForm.ShouldSizeY, 'ShouldSizeY');
-    RegisterMethod(@TSetupForm.FlipSizeAndCenterIfNeeded, 'FlipSizeAndCenterIfNeeded');
+    RegisterMethod(@TSetupForm.FlipAndCenterIfNeeded, 'FlipAndCenterIfNeeded');
   end;
 end;
 

+ 3 - 1
Projects/Src/Setup.ScriptFunc.pas

@@ -294,7 +294,9 @@ var
         NewSetupForm.PopupMode := pmAuto;
         NewSetupForm.AutoScroll := False;
         NewSetupForm.BorderStyle := bsDialog;
-        NewSetupForm.InitializeFont;
+        NewSetupForm.ClientWidth := Stack.GetInt(PStart-1);
+        NewSetupForm.ClientHeight := Stack.GetInt(PStart-2);
+        NewSetupForm.InitializeFont(Stack.GetBool(PStart-3), Stack.GetBool(PStart-4));
       except
         NewSetupForm.Free;
         raise;

+ 1 - 1
Projects/Src/Setup.SelectFolderForm.pas

@@ -136,7 +136,7 @@ begin
     OKButton.Top + YDiff, W, OKButton.Height);
   ClientHeight := ClientHeight + YDiff;
 
-  FlipSizeAndCenterIfNeeded(True, WizardForm, False);
+  FlipAndCenterIfNeeded(True, WizardForm, False);
 end;
 
 constructor TSelectFolderForm.Create2(AOwner: TComponent; AStartMenu: Boolean);

+ 1 - 3
Projects/Src/Setup.SelectLanguageForm.pas

@@ -96,7 +96,7 @@ begin
 
   MainPanel.ParentBackground := False;
 
-  InitializeFont;
+  InitializeFont(False, True);
 
   Caption := SetupMessages[msgSelectLanguageTitle];
   SelectLabel.Caption := SetupMessages[msgSelectLanguageLabel];
@@ -104,8 +104,6 @@ begin
   CancelButton.Caption := SetupMessages[msgButtonCancel];
 
   IconBitmapImage.InitializeFromIcon(HInstance, PChar('MAINICON' + MainIconPostfix), clNone, [32, 48, 64]);
-
-  KeepSizeY := True;
 end;
 
 end.

+ 24 - 24
Projects/Src/Setup.SetupForm.pas

@@ -34,7 +34,7 @@ type
     FBaseUnitX, FBaseUnitY: Integer;
     FRightToLeft: Boolean;
     FFlipControlsOnShow: Boolean;
-    FSizeAndCenterOnShow: Boolean;
+    FCenterOnShow: Boolean;
     FControlsFlipped: Boolean;
     FKeepSizeX: Boolean;
     FKeepSizeY: Boolean;
@@ -49,7 +49,7 @@ type
     procedure CreateParams(var Params: TCreateParams); override;
     procedure CreateWnd; override;
     procedure FlipControlsIfNeeded;
-    procedure SizeAndCenterIfNeeded(const ACenterInsideControl: Boolean;
+    procedure CenterIfNeeded(const ACenterInsideControl: Boolean;
       const CenterInsideControlCtl: TWinControl;
       const CenterInsideControlInsideClientArea: Boolean);
     procedure VisibleChanging; override;
@@ -58,7 +58,7 @@ type
     constructor Create(AOwner: TComponent); override;
     constructor CreateNew(AOwner: TComponent; Dummy: Integer = 0); override;
     function CalculateButtonWidth(const ButtonCaptions: array of String): Integer;
-    procedure InitializeFont;
+    procedure InitializeFont(const KeepSizeX: Boolean = False; const KeepSizeY: Boolean = False);
     class function ScalePixelsX(const BaseUnitX, N: Integer): Integer; overload;
     class function ScalePixelsY(const BaseUnitY, N: Integer): Integer; overload;
     function ScalePixelsX(const N: Integer): Integer; overload;
@@ -66,7 +66,7 @@ type
     function ShouldSizeX: Boolean;
     function ShouldSizeY: Boolean;
     function ShowModal: Integer; override;
-    procedure FlipSizeAndCenterIfNeeded(const ACenterInsideControl: Boolean = False;
+    procedure FlipAndCenterIfNeeded(const ACenterInsideControl: Boolean = False;
       const CenterInsideControlCtl: TWinControl = nil;
       const CenterInsideControlInsideClientArea: Boolean = False); virtual;
     property BaseUnitX: Integer read FBaseUnitX;
@@ -74,10 +74,8 @@ type
   published
     property ControlsFlipped: Boolean read FControlsFlipped;
     property FlipControlsOnShow: Boolean read FFlipControlsOnShow write FFlipControlsOnShow;
-    property KeepSizeX: Boolean read FKeepSizeX write FKeepSizeX;
-    property KeepSizeY: Boolean read FKeepSizeY write FKeepSizeY;
     property RightToLeft: Boolean read FRightToLeft;
-    property SizeAndCenterOnShow: Boolean read FSizeAndCenterOnShow write FSizeAndCenterOnShow;
+    property CenterOnShow: Boolean read FCenterOnShow write FCenterOnShow;
     property SetForeground: Boolean read FSetForeground write FSetForeground;
   end;
 
@@ -199,7 +197,7 @@ begin
     CreateNew isn't virtual on Delphi 2 and 3 }
   FRightToLeft := LangOptions.RightToLeft;
   FFlipControlsOnShow := FRightToLeft;
-  FSizeAndCenterOnShow := True;
+  FCenterOnShow := True;
   inherited;
    { Setting BidiMode before inherited causes an AV when TControl tries to
      send CM_BIDIMODECHANGED. This is why we have additonal RTL code in
@@ -219,7 +217,7 @@ begin
     when TSetupForm.CreateNew is called explicitly }
   FRightToLeft := LangOptions.RightToLeft;
   FFlipControlsOnShow := FRightToLeft;
-  FSizeAndCenterOnShow := True;
+  FCenterOnShow := True;
   inherited;
   if FRightToLeft then
     BiDiMode := bdRightToLeft;
@@ -412,15 +410,10 @@ begin
   end;
 end;
 
-procedure TSetupForm.SizeAndCenterIfNeeded(const ACenterInsideControl: Boolean; const CenterInsideControlCtl: TWinControl; const CenterInsideControlInsideClientArea: Boolean);
+procedure TSetupForm.CenterIfNeeded(const ACenterInsideControl: Boolean; const CenterInsideControlCtl: TWinControl; const CenterInsideControlInsideClientArea: Boolean);
 begin
-  if FSizeAndCenterOnShow then begin
-    FSizeAndCenterOnShow := False;
-    { Apply custom initial size from script - depends on Align or Anchors being set on all the controls }
-    if ShouldSizeX then
-      ClientWidth := MulDiv(ClientWidth, SetupHeader.WizardSizePercentX, 100);
-    if ShouldSizeY then
-      ClientHeight := MulDiv(ClientHeight, SetupHeader.WizardSizePercentY, 100);
+  if FCenterOnShow then begin
+    FCenterOnShow := False;
     { Center }
     if ACenterInsideControl then
       CenterInsideControl(CenterInsideControlCtl, CenterInsideControlInsideClientArea)
@@ -439,19 +432,17 @@ begin
   Result := not FKeepSizeY and (SetupHeader.WizardSizePercentY > 100);
 end;
 
-procedure TSetupForm.FlipSizeAndCenterIfNeeded(const ACenterInsideControl: Boolean;
+procedure TSetupForm.FlipAndCenterIfNeeded(const ACenterInsideControl: Boolean;
   const CenterInsideControlCtl: TWinControl; const CenterInsideControlInsideClientArea: Boolean);
 begin
-  { Flipping must be done first because when flipping after sizing the flipping might get old info
-    for anchors that didn't do their work yet }
   FlipControlsIfNeeded;
-  SizeAndCenterIfNeeded(ACenterInsideControl, CenterInsideControlCtl, CenterInsideControlInsideClientArea);
+  CenterIfNeeded(ACenterInsideControl, CenterInsideControlCtl, CenterInsideControlInsideClientArea);
 end;
 
 type
   TControlAccess = class(TControl);
 
-procedure TSetupForm.InitializeFont;
+procedure TSetupForm.InitializeFont(const KeepSizeX, KeepSizeY: Boolean);
 
   procedure NewChangeScale(const Ctl: TControl; const XM, XD, YM, YD: Integer);
   var
@@ -527,11 +518,12 @@ var
   W, H: Integer;
   R: TRect;
 begin
-  { Note: Must keep the following lines in synch with Setup.ScriptFunc.pas's
+  { Set font. Note: Must keep the following lines in synch with Setup.ScriptFunc.pas's
     InitializeScaleBaseUnits }
   SetFontNameSize(Font, LangOptions.DialogFontName, LangOptions.DialogFontSize, '', 8);
   CalculateBaseUnitsFromFont(Font, FBaseUnitX, FBaseUnitY);
 
+  { Scale }
   const OrigBaseUnitX = LangOptions.DialogFontBaseScaleWidth;
   const OrigBaseUnitY = LangOptions.DialogFontBaseScaleHeight;
 
@@ -552,6 +544,14 @@ begin
       ControlAnchorsList.Free;
     end;
   end;
+
+  { Size }
+  FKeepSizeX := KeepSizeX;
+  FKeepSizeY := KeepSizeY;
+  if ShouldSizeX then
+    ClientWidth := MulDiv(ClientWidth, SetupHeader.WizardSizePercentX, 100);
+  if ShouldSizeY then
+    ClientHeight := MulDiv(ClientHeight, SetupHeader.WizardSizePercentY, 100);
 end;
 
 class function TSetupForm.ScalePixelsX(const BaseUnitX, N: Integer): Integer;
@@ -592,7 +592,7 @@ begin
   { Note: Unlike DoShow, any exceptions raised in VisibleChanging will be
     propagated out, which is what we want }
   if not Visible then
-    FlipSizeAndCenterIfNeeded;
+    FlipAndCenterIfNeeded;
   end;
 
 procedure TSetupForm.CMShowingChanged(var Message: TMessage);

+ 4 - 4
Projects/Src/Setup.TaskDialogForm.pas

@@ -128,7 +128,9 @@ begin
   FCopyFormat := ACopyFormat;
   SetForeground := ASetForeground;
 
-  InitializeFont;
+  { KeepSizeX: Already bit wider than regular task dialogs
+    KeepSizeY: UpdateHeight will set height }
+  InitializeFont(True, True);
 
   var LStyle := StyleServices(Self);
   if not LStyle.Enabled or LStyle.IsSystemStyle then
@@ -177,9 +179,7 @@ begin
     end;
   end;
 
-  KeepSizeX := True; { Already bit wider than regular task dialogs }
-  KeepSizeY := True; { UpdateHeight already set height }
-  FlipSizeAndCenterIfNeeded(Assigned(WizardForm), WizardForm, False);
+  FlipAndCenterIfNeeded(Assigned(WizardForm), WizardForm, False);
 
   if DefCommonButton > 0 then begin
     var I := DefCommonButton;

+ 1 - 3
Projects/Src/Setup.UninstallSharedFileForm.pas

@@ -66,7 +66,7 @@ constructor TUninstallSharedFileForm.Create(AOwner: TComponent);
 begin
   inherited;
 
-  InitializeFont;
+  InitializeFont(False, True);
 
   Caption := SetupMessages[msgConfirmDeleteSharedFileTitle];
   BodyLabel.Caption := SetupMessages[msgConfirmDeleteSharedFile2];
@@ -76,8 +76,6 @@ begin
   YesToAllButton.Caption := SetupMessages[msgButtonYesToAll];
   NoButton.Caption := SetupMessages[msgButtonNo];
   NoToAllButton.Caption := SetupMessages[msgButtonNoToAll];
-
-  KeepSizeY := True;
 end;
 
 procedure TUninstallSharedFileForm.CreateParams(var Params: TCreateParams);

+ 1 - 1
Projects/Src/Shared.ScriptFunc.pas

@@ -224,7 +224,7 @@ initialization
     'function CreateExtractionPage(const ACaption, ADescription: String; const OnExtractionProgress: TOnExtractionProgress): TExtractionWizardPage;',
     'function ScaleX(X: Integer): Integer;',
     'function ScaleY(Y: Integer): Integer;',
-    'function CreateCustomForm: TSetupForm;'
+    'function CreateCustomForm(const ClientWidth, ClientHeight: Integer; const KeepSizeX, KeepSizeY: Boolean): TSetupForm;'
   ];
 
   ScriptFuncTables[sftNewDiskForm] :=