Bläddra i källkod

Added new CalculateButtonWidth function to the TSetupForm support class.

Martijn Laan 5 år sedan
förälder
incheckning
cdcadf4c76

+ 13 - 10
Examples/CodeClasses.iss

@@ -37,6 +37,7 @@ var
   Form: TSetupForm;
   Edit: TNewEdit;
   OKButton, CancelButton: TNewButton;
+  W: Integer;
 begin
   Form := CreateCustomForm();
   try
@@ -55,26 +56,28 @@ begin
 
     OKButton := TNewButton.Create(Form);
     OKButton.Parent := Form;
+    OKButton.Caption := 'OK';
     OKButton.Left := Form.ClientWidth - ScaleX(75 + 6 + 75 + 10);
     OKButton.Top := Form.ClientHeight - ScaleY(23 + 10);
-    OKButton.Width := ScaleX(75);
     OKButton.Height := ScaleY(23);
     OKButton.Anchors := [akRight, akBottom]
-    OKButton.Caption := 'OK';
     OKButton.ModalResult := mrOk;
     OKButton.Default := True;
 
     CancelButton := TNewButton.Create(Form);
     CancelButton.Parent := Form;
+    CancelButton.Caption := 'Cancel';
     CancelButton.Left := Form.ClientWidth - ScaleX(75 + 10);
     CancelButton.Top := Form.ClientHeight - ScaleY(23 + 10);
-    CancelButton.Width := ScaleX(75);
     CancelButton.Height := ScaleY(23);
     CancelButton.Anchors := [akRight, akBottom]
-    CancelButton.Caption := 'Cancel';
     CancelButton.ModalResult := mrCancel;
     CancelButton.Cancel := True;
 
+    W := Form.CalculateButtonWidth([OKButton.Caption, CancelButton.Caption]);
+    OKButton.Width := W;
+    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;
@@ -126,9 +129,9 @@ begin
   Page := CreateCustomPage(wpWelcome, 'Custom wizard page controls', 'TButton and others');
 
   Button := TNewButton.Create(Page);
-  Button.Width := ScaleX(75);
-  Button.Height := ScaleY(23);
   Button.Caption := 'TNewButton';
+  Button.Width := WizardForm.CalculateButtonWidth([Button.Caption]);
+  Button.Height := ScaleY(23);
   Button.OnClick := @ButtonOnClick;
   Button.Parent := Page.Surface;
 
@@ -176,21 +179,21 @@ begin
   Memo.Parent := Page.Surface;
 
   FormButton := TNewButton.Create(Page);
+  FormButton.Caption := 'TSetupForm';
   FormButton.Top := Memo.Top + Memo.Height + ScaleY(8);
-  FormButton.Width := ScaleX(75);
+  FormButton.Width := WizardForm.CalculateButtonWidth([FormButton.Caption]);
   FormButton.Height := ScaleY(23);
   FormButton.Anchors := [akLeft, akBottom];
-  FormButton.Caption := 'TSetupForm';
   FormButton.OnClick := @FormButtonOnClick;
   FormButton.Parent := Page.Surface;
 
   TaskDialogButton := TNewButton.Create(Page);
+  TaskDialogButton.Caption := 'TaskDialogMsgBox';
   TaskDialogButton.Top := FormButton.Top;
   TaskDialogButton.Left := FormButton.Left + FormButton.Width + ScaleX(8);
-  TaskDialogButton.Width := ScaleX(110);
+  TaskDialogButton.Width := WizardForm.CalculateButtonWidth([TaskDialogButton.Caption]);
   TaskDialogButton.Height := ScaleY(23);
   TaskDialogButton.Anchors := [akLeft, akBottom];
-  TaskDialogButton.Caption := 'TaskDialogMsgBox';
   TaskDialogButton.OnClick := @TaskDialogButtonOnClick;
   TaskDialogButton.Parent := Page.Surface;
 

+ 1 - 0
ISHelp/isxclasses.pas

@@ -732,6 +732,7 @@ TUIStateForm = class(TForm)
 end;
 
 TSetupForm = class(TUIStateForm)
+  function CalculateButtonWidth(const ButtonCaptions: array of String): Integer;
   function ShouldSizeX: Boolean;
   function ShouldSizeY: Boolean;
   procedure FlipSizeAndCenterIfNeeded(const ACenterInsideControl: Boolean; const CenterInsideControlCtl: TWinControl; const CenterInsideControlInsideClientArea: Boolean);

+ 1 - 0
Projects/ScriptClasses_C.pas

@@ -295,6 +295,7 @@ procedure RegisterSetupForm_C(Cl: TPSPascalCompiler);
 begin
   with Cl.AddClassN(Cl.FindClass('TUIStateForm'), 'TSetupForm') do
   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)');

+ 1 - 0
Projects/ScriptClasses_R.pas

@@ -187,6 +187,7 @@ procedure RegisterSetupForm_R(Cl: TPSRuntimeClassImporter);
 begin
   with Cl.Add(TSetupForm) do
   begin
+    RegisterMethod(@TSetupForm.CalculateButtonWidth, 'CalculateButtonWidth');
     RegisterMethod(@TSetupForm.ShouldSizeX, 'ShouldSizeX');
     RegisterMethod(@TSetupForm.ShouldSizeY, 'ShouldSizeY');
     RegisterMethod(@TSetupForm.FlipSizeAndCenterIfNeeded, 'FlipSizeAndCenterIfNeeded');

+ 2 - 2
Projects/ScriptDlg.pas

@@ -441,7 +441,7 @@ var
   Edit: TEdit;
   Button: TNewButton;
 begin
-  ButtonWidth := WizardForm.CalculateButtonWidth([msgButtonWizardBrowse]);
+  ButtonWidth := WizardForm.CalculateButtonWidth([SetupMessages[msgButtonWizardBrowse]]);
 
   if APrompt <> '' then begin
     PromptLabel := TNewStaticText.Create(Self);
@@ -583,7 +583,7 @@ var
   Edit: TEdit;
   Button: TNewButton;
 begin
-  ButtonWidth := WizardForm.CalculateButtonWidth([msgButtonWizardBrowse]);
+  ButtonWidth := WizardForm.CalculateButtonWidth([SetupMessages[msgButtonWizardBrowse]]);
 
   if APrompt <> '' then begin
     PromptLabel := TNewStaticText.Create(Self);

+ 2 - 2
Projects/SelFolderForm.pas

@@ -128,8 +128,8 @@ begin
   FFolderTreeView.Top := FFolderTreeView.Top + YDiff;
   NewFolderButton.Caption := SetupMessages[msgButtonNewFolder];
   NewFolderButton.Top := NewFolderButton.Top + YDiff;
-  NewFolderButton.Width := CalculateButtonWidth([msgButtonNewFolder]);
-  W := CalculateButtonWidth([msgButtonOK, msgButtonCancel]);
+  NewFolderButton.Width := CalculateButtonWidth([SetupMessages[msgButtonNewFolder]]);
+  W := CalculateButtonWidth([SetupMessages[msgButtonOK], SetupMessages[msgButtonCancel]]);
   CancelButton.Caption := SetupMessages[msgButtonCancel];
   CancelButton.SetBounds(CancelButton.Left + CancelButton.Width - W,
     CancelButton.Top + YDiff, W, CancelButton.Height);

+ 3 - 3
Projects/SetupForm.pas

@@ -47,7 +47,7 @@ type
     {$ELSE}
     constructor CreateNew(AOwner: TComponent; Dummy: Integer = 0); override;
     {$ENDIF}
-    function CalculateButtonWidth(const ButtonCaptions: array of TSetupMessageID): Integer;
+    function CalculateButtonWidth(const ButtonCaptions: array of String): Integer;
     procedure InitializeFont;
     function ScalePixelsX(const N: Integer): Integer;
     function ScalePixelsY(const N: Integer): Integer;
@@ -316,7 +316,7 @@ begin
   inherited;
 end;
 
-function TSetupForm.CalculateButtonWidth(const ButtonCaptions: array of TSetupMessageID): Integer;
+function TSetupForm.CalculateButtonWidth(const ButtonCaptions: array of String): Integer;
 var
   DC: HDC;
   I, W: Integer;
@@ -327,7 +327,7 @@ begin
   try
     SelectObject(DC, Font.Handle);
     for I := Low(ButtonCaptions) to High(ButtonCaptions) do begin
-      W := GetTextWidth(DC, SetupMessages[ButtonCaptions[I]], True) + ScalePixelsX(20);
+      W := GetTextWidth(DC, ButtonCaptions[I], True) + ScalePixelsX(20);
       if Result < W then
         Result := W;
     end;

+ 5 - 4
Projects/Wizard.pas

@@ -895,8 +895,9 @@ begin
   end;
   
   { Position the buttons, and scale their size }
-  W1 := CalculateButtonWidth([msgButtonBack, msgButtonCancel, msgButtonFinish,
-    msgButtonInstall, msgButtonNext]);  { width of each button }
+  W1 := CalculateButtonWidth([SetupMessages[msgButtonBack], SetupMessages[msgButtonCancel],
+    SetupMessages[msgButtonFinish], SetupMessages[msgButtonInstall],
+    SetupMessages[msgButtonNext]]);  { width of each button }
   W2 := ScalePixelsX(10);  { margin, and space between Next & Cancel }
 
   BackButton.Width := W1;
@@ -1008,7 +1009,7 @@ begin
   DirEdit.Top := DirEdit.Top + I;
   TryEnableAutoCompleteFileSystem(DirEdit.Handle);
   DirBrowseButton.Caption := SetupMessages[msgButtonWizardBrowse];
-  X := CalculateButtonWidth([msgButtonWizardBrowse]);
+  X := CalculateButtonWidth([SetupMessages[msgButtonWizardBrowse]]);
   DirBrowseButton.SetBounds(InnerNotebook.Width - X,
     DirBrowseButton.Top + I, X, DirBrowseButton.Height);
   DirEdit.Width := DirBrowseButton.Left - ScalePixelsX(10) - DirEdit.Left;
@@ -1053,7 +1054,7 @@ begin
   Inc(I, AdjustLabelHeight(SelectStartMenuFolderBrowseLabel));
   GroupEdit.Top := GroupEdit.Top + I;
   GroupBrowseButton.Caption := SetupMessages[msgButtonWizardBrowse];
-  X := CalculateButtonWidth([msgButtonWizardBrowse]);
+  X := CalculateButtonWidth([SetupMessages[msgButtonWizardBrowse]]);
   GroupBrowseButton.SetBounds(InnerNotebook.Width - X,
     GroupBrowseButton.Top + I, X, GroupBrowseButton.Height);
   GroupEdit.Width := GroupBrowseButton.Left - ScalePixelsX(10) - GroupEdit.Left;

+ 6 - 1
whatsnew.htm

@@ -74,7 +74,12 @@ For conditions of distribution and use, see <a href="https://jrsoftware.org/file
     <li>These new prompts also use other new messages: <a href="https://github.com/jrsoftware/issrc/commit/e5ccbc5e0b1e2327a3608b1c69d016613c88df7e">View differences in Default.isl</a> for a complete list.</li>
   </ul>
   </li>
-  <li>Pascal Scripting change: <i>Fix:</i> Support function <tt>WizardSelectComponents</tt> now also updates component sizes and the current selection's required disk space.</li>
+  <li>Pascal Scripting changes:
+  <ul>
+    <li>Added new <tt>CalculateButtonWidth</tt> function to the <tt>TSetupForm</tt> support class.</li>
+    <li><i>Fix:</i> Support function <tt>WizardSelectComponents</tt> now also updates component sizes and the current selection's required disk space.</li>
+  </ul>
+  </li>
   <li>Minor tweaks.</li>
 </ul>