Explorar el Código

Add TLinkLabel examples and also an example for AdjustLabelHeight. Undo the AdjustLabelHeight AutoSize change from previous commit.

Martijn Laan hace 1 año
padre
commit
242cf579dc
Se han modificado 4 ficheros con 54 adiciones y 28 borrados
  1. 51 25
      Examples/CodeClasses.iss
  2. 0 2
      Projects/Src/Wizard.pas
  3. 2 0
      iscrypt.iss
  4. 1 1
      whatsnew.htm

+ 51 - 25
Examples/CodeClasses.iss

@@ -105,6 +105,16 @@ begin
   end;
 end;
 
+procedure LinkLabelOnLinkClick(Sender: TObject; const Link: string; LinkType: TSysLinkType);
+var
+  ErrorCode: Integer;
+begin
+  if (LinkType = sltID) and (Link = 'jrsoftware') then
+    ShellExecAsOriginalUser('open', 'https://jrsoftware.org', '', '', SW_SHOWNORMAL, ewNoWait, ErrorCode)
+  else if LinkType = sltURL then  
+    ShellExecAsOriginalUser('open', Link, '', '', SW_SHOWNORMAL, ewNoWait, ErrorCode);
+end;
+
 procedure CreateTheWizardPages;
 var
   Page: TWizardPage;
@@ -116,7 +126,8 @@ var
   Memo: TNewMemo;
   ComboBox: TNewComboBox;
   ListBox: TNewListBox;
-  StaticText, ProgressBarLabel: TNewStaticText;
+  StaticText, StaticText2, ProgressBarLabel: TNewStaticText;
+  LinkLabel: TNewLinkLabel;
   ProgressBar, ProgressBar2, ProgressBar3: TNewProgressBar;
   CheckListBox, CheckListBox2: TNewCheckListBox;
   FolderTreeView: TFolderTreeView;
@@ -222,14 +233,39 @@ begin
   StaticText.Top := ListBox.Top + ListBox.Height + ScaleY(8);
   StaticText.Anchors := [akLeft, akRight, akBottom];
   StaticText.Caption := 'TNewStaticText';
-  StaticText.AutoSize := True;
   StaticText.Parent := Page.Surface;
 
+  StaticText2 := TNewStaticText.Create(Page);
+  StaticText2.AutoSize := False;
+  StaticText2.Left := StaticText.Width + ScaleX(32);
+  StaticText2.Top := StaticText.Top;
+  StaticText2.Anchors := [akLeft, akRight, akBottom];
+  StaticText2.WordWrap := True;
+  StaticText2.Caption := 'TNewStaticText with more text and an adjusted label height so it''s multi-line.';
+  StaticText2.Width := 2 * StaticText.Width;
+  StaticText2.Parent := Page.Surface;
+
+  WizardForm.AdjustLabelHeight(StaticText2);
+
+  LinkLabel := TNewLinkLabel.Create(Page);
+  LinkLabel.AutoSize := False;
+  LinkLabel.Left := StaticText2.Left;
+  LinkLabel.Top := StaticText2.Top + StaticText2.Height + ScaleY(8);
+  LinkLabel.Anchors := [akLeft, akRight, akBottom];
+  LinkLabel.Caption := 'TNew<a id="jrsoftware">Link</a>Label with more text and an adjusted label height so it''s multi-line with a second <a id="jrsoftware">link</a> on the second line.';
+  LinkLabel.Width := StaticText2.Width;
+  LinkLabel.OnLinkClick := @LinkLabelOnLinkClick;
+  LinkLabel.Parent := Page.Surface;
+
+  WizardForm.AdjustLinkLabelHeight(LinkLabel);
+
+  { TNewProgressBar }
+
+  Page := CreateCustomPage(Page.ID, 'Custom wizard page controls', 'TNewProgressBar');
+
   ProgressBarLabel := TNewStaticText.Create(Page);
-  ProgressBarLabel.Top := StaticText.Top + StaticText.Height + ScaleY(8);
-  ProgressBarLabel.Anchors := [akLeft, akBottom];
+  ProgressBarLabel.Anchors := [akLeft, akTop];
   ProgressBarLabel.Caption := 'TNewProgressBar';
-  ProgressBarLabel.AutoSize := True;
   ProgressBarLabel.Parent := Page.Surface;
 
   ProgressBar := TNewProgressBar.Create(Page);
@@ -237,7 +273,7 @@ begin
   ProgressBar.Top := ProgressBarLabel.Top;
   ProgressBar.Width := Page.SurfaceWidth - ProgressBar.Left;
   ProgressBar.Height := ProgressBarLabel.Height + ScaleY(8);
-  ProgressBar.Anchors := [akLeft, akRight, akBottom];
+  ProgressBar.Anchors := [akLeft, akRight, akTop];
   ProgressBar.Parent := Page.Surface;
   ProgressBar.Position := 25;
 
@@ -246,7 +282,7 @@ begin
   ProgressBar2.Top := ProgressBar.Top + ProgressBar.Height + ScaleY(4);
   ProgressBar2.Width := Page.SurfaceWidth - ProgressBar.Left;
   ProgressBar2.Height := ProgressBarLabel.Height + ScaleY(8);
-  ProgressBar2.Anchors := [akLeft, akRight, akBottom];
+  ProgressBar2.Anchors := [akLeft, akRight, akTop];
   ProgressBar2.Parent := Page.Surface;
   ProgressBar2.Position := 50;
   ProgressBar2.State := npbsError;
@@ -256,7 +292,7 @@ begin
   ProgressBar3.Top := ProgressBar2.Top + ProgressBar2.Height + ScaleY(4);
   ProgressBar3.Width := Page.SurfaceWidth - ProgressBar.Left;
   ProgressBar3.Height := ProgressBarLabel.Height + ScaleY(8);
-  ProgressBar3.Anchors := [akLeft, akRight, akBottom];
+  ProgressBar3.Anchors := [akLeft, akRight, akTop];
   ProgressBar3.Parent := Page.Surface;
   ProgressBar3.Style := npbstMarquee;
   
@@ -367,17 +403,10 @@ begin
   MsgBox('This demo shows some features of the various form objects and control classes.', mbInformation, mb_Ok);
 end;
 
-procedure URLLabelOnClick(Sender: TObject);
-var
-  ErrorCode: Integer;
-begin
-  ShellExecAsOriginalUser('open', 'http://www.innosetup.com/', '', '', SW_SHOWNORMAL, ewNoWait, ErrorCode);
-end;
-
 procedure CreateAboutButtonAndURLLabel(ParentForm: TSetupForm; CancelButton: TNewButton);
 var
   AboutButton: TNewButton;
-  URLLabel: TNewStaticText;
+  URLLabel: TNewLinkLabel;
 begin
   AboutButton := TNewButton.Create(ParentForm);
   AboutButton.Left := ParentForm.ClientWidth - CancelButton.Left - CancelButton.Width;
@@ -389,17 +418,14 @@ begin
   AboutButton.OnClick := @AboutButtonOnClick;
   AboutButton.Parent := ParentForm;
 
-  URLLabel := TNewStaticText.Create(ParentForm);
-  URLLabel.Caption := 'www.innosetup.com';
-  URLLabel.Cursor := crHand;
-  URLLabel.OnClick := @URLLabelOnClick;
-  URLLabel.Parent := ParentForm;
-  { Alter Font *after* setting Parent so the correct defaults are inherited first }
-  URLLabel.Font.Style := URLLabel.Font.Style + [fsUnderline];
-  URLLabel.Font.Color := clHotLight
-  URLLabel.Top := AboutButton.Top + AboutButton.Height - URLLabel.Height - 2;
+  URLLabel := TNewLinkLabel.Create(ParentForm);
   URLLabel.Left := AboutButton.Left + AboutButton.Width + ScaleX(20);
+  URLLabel.Top := AboutButton.Top + AboutButton.Height - URLLabel.Height - 2;
   URLLabel.Anchors := [akLeft, akBottom];
+  URLLabel.Caption := '<a href="https://jrsoftware.org">jrsoftware.org</a>';
+  URLLabel.OnLinkClick := @LinkLabelOnLinkClick;
+  URLLabel.UseVisualStyle := True;
+  URLLabel.Parent := ParentForm;
 end;
 
 procedure InitializeWizard();

+ 0 - 2
Projects/Src/Wizard.pas

@@ -542,13 +542,11 @@ function TWizardForm.AdjustLabelHeight(const ALabel: TNewStaticText): Integer;
 { Increases or decreases a label's height so that all text fits.
   Returns the difference in height. }
 begin
-  ALabel.AutoSize := False;
   Result := ALabel.AdjustHeight;
 end;
 
 function TWizardForm.AdjustLinkLabelHeight(const ALinkLabel: TNewLinkLabel): Integer;
 begin
-  ALinkLabel.AutoSize := False;
   Result := ALinkLabel.AdjustHeight;
 end;
 

+ 2 - 0
iscrypt.iss

@@ -59,6 +59,7 @@ begin
 
   Label1 := TNewStaticText.Create(Page);
   with Label1 do begin
+    AutoSize := False;
     Left := WizardForm.SelectDirLabel.Left;
     Width := Page.SurfaceWidth - Left;
     Anchors := [akLeft, akTop, akRight];
@@ -70,6 +71,7 @@ begin
 
   Label2 := TNewStaticText.Create(Page);
   with Label2 do begin
+    AutoSize := False;
     Top := Label1.Top + Label1.Height + ScaleY(12);
     Width := Page.SurfaceWidth;
     Anchors := [akLeft, akTop, akRight];

+ 1 - 1
whatsnew.htm

@@ -145,7 +145,7 @@ end;</pre>
   <li>Pascal Scripting changes: 
     <ul>
     <li>Added support functions <tt>UTF8Encode</tt> and <tt>UTF8Decode</tt> to encode a Unicode string into a UTF-8 encoded ANSI string and vice versa.</li>
-    <li>Added support class <tt>TNewLinkLabel</tt> which can display text with embedded links and internally uses a Windows SysLink control. See the <i>CodeClasses.iss</i> example script for examples.</li>
+    <li>Added support class <tt>TNewLinkLabel</tt> which can display multi-line text with embedded links and internally uses a Windows SysLink control. See the <i>CodeClasses.iss</i> example script for examples.</li>
     <li><tt>TWizardForm</tt>: Added new <tt>AdjustLinkLabelHeight</tt> function.</li>
     <li>Type <tt>TShellFolderID</tt> was removed because it wasn't used by any support function.</li>
     </ul>