|
| 1 | +{ |
| 2 | + * This Source Code Form is subject to the terms of the Mozilla Public License, |
| 3 | + * v. 2.0. If a copy of the MPL was not distributed with this file, You can |
| 4 | + * obtain one at http://mozilla.org/MPL/2.0/ |
| 5 | + * |
| 6 | + * Copyright (C) 2020, Peter Johnson (gravatar.com/delphidabbler). |
| 7 | + * |
| 8 | + * Implements dialogue box that may be displayed the first time CodeSnip 4.x.x |
| 9 | + * is run after an update. The dialogue box displays a HTML page that draws |
| 10 | + * attention to key changes in the updated version of CodeSnip. |
| 11 | +} |
| 12 | + |
| 13 | + |
| 14 | +unit FirstRun.FmWhatsNew; |
| 15 | + |
| 16 | +interface |
| 17 | + |
| 18 | + |
| 19 | +uses |
| 20 | + // VCL |
| 21 | + Controls, |
| 22 | + Forms, |
| 23 | + StdCtrls, |
| 24 | + ExtCtrls, |
| 25 | + Classes, |
| 26 | + // Project |
| 27 | + FirstRun.FmWhatsNew.FrHTML, |
| 28 | + FmGenericViewDlg, |
| 29 | + FrBrowserBase, |
| 30 | + IntfAligner, |
| 31 | + UBaseObjects; |
| 32 | + |
| 33 | + |
| 34 | +type |
| 35 | + /// <summary>Dialogue box that may be displayed the first time CodeSnip 4.x.x |
| 36 | + /// is run after an update. The dialogue box displays a HTML page that draws |
| 37 | + /// attention to key changes in the updated version of CodeSnip.</summary> |
| 38 | + TWhatsNewDlg = class(TGenericViewDlg, INoPublicConstruct) |
| 39 | + frmHTML: TWhatsNewHTMLFrame; |
| 40 | + strict private |
| 41 | + type |
| 42 | + /// <summary>Custom form aligner class for wizard.</summary> |
| 43 | + TAligner = class(TInterfacedObject, IFormAligner) |
| 44 | + public |
| 45 | + /// <summary>Aligns dialogue box at centre of primary monitor. |
| 46 | + /// </summary> |
| 47 | + procedure AlignForm(const AForm: TCustomForm); |
| 48 | + end; |
| 49 | + strict protected |
| 50 | + /// <summary>Returns instance of form aligner object.</summary> |
| 51 | + function GetAligner: IFormAligner; override; |
| 52 | + /// <summary>Sets form caption and loads HTML to be displayed from |
| 53 | + /// resources.</summary> |
| 54 | + procedure ConfigForm; override; |
| 55 | + /// <summary>Sets size of the HTML section of the display and aranges other |
| 56 | + /// controls around that.</summary> |
| 57 | + procedure ArrangeForm; override; |
| 58 | + /// <summary>Modifies window creation parameters to ensure the dialgue box |
| 59 | + /// displays a button in the task bar.</summary> |
| 60 | + /// <remarks>This is necessary because the dialogue box is displayed before |
| 61 | + /// CodeSnip's main window is shown, so there is no suitable button |
| 62 | + /// displayed yet.</remarks> |
| 63 | + procedure CreateParams(var Params: TCreateParams); override; |
| 64 | + public |
| 65 | + /// <summary>Displays dialogue box with given owner.</summary> |
| 66 | + class procedure Execute(AOwner: TComponent); |
| 67 | + end; |
| 68 | + |
| 69 | + |
| 70 | +implementation |
| 71 | + |
| 72 | + |
| 73 | +uses |
| 74 | + // VCL |
| 75 | + SysUtils, |
| 76 | + Math, |
| 77 | + Windows, |
| 78 | + // Project |
| 79 | + UAppInfo, |
| 80 | + UConsts, |
| 81 | + UEncodings, |
| 82 | + UResourceUtils, |
| 83 | + UStructs; |
| 84 | + |
| 85 | +{$R *.dfm} |
| 86 | + |
| 87 | + |
| 88 | +{ TWhatsNewDlg } |
| 89 | + |
| 90 | +procedure TWhatsNewDlg.ArrangeForm; |
| 91 | +const |
| 92 | + cBodyWidth = 500; |
| 93 | + cBodyHeight = 450; |
| 94 | +begin |
| 95 | + pnlBody.Width := cBodyWidth; |
| 96 | + pnlBody.Height := cBodyHeight; |
| 97 | + inherited; |
| 98 | +end; |
| 99 | + |
| 100 | +procedure TWhatsNewDlg.ConfigForm; |
| 101 | +resourcestring |
| 102 | + sDlgTitle = 'Welcome to CodeSnip v%s'; |
| 103 | +begin |
| 104 | + Caption := Format(sDlgTitle, [TAppInfo.ProgramReleaseVersion]); |
| 105 | + frmHTML.Initialise( |
| 106 | + LoadResourceAsString(HInstance, 'dlg-whatsnew.html', RT_HTML, etUTF8) |
| 107 | + ); |
| 108 | +end; |
| 109 | + |
| 110 | +procedure TWhatsNewDlg.CreateParams(var Params: TCreateParams); |
| 111 | +begin |
| 112 | + inherited; |
| 113 | + Params.ExStyle := Params.ExStyle OR WS_EX_APPWINDOW; |
| 114 | +end; |
| 115 | + |
| 116 | +class procedure TWhatsNewDlg.Execute(AOwner: TComponent); |
| 117 | +begin |
| 118 | + with InternalCreate(AOwner) do |
| 119 | + try |
| 120 | + ShowModal; |
| 121 | + finally |
| 122 | + Free; |
| 123 | + end; |
| 124 | +end; |
| 125 | + |
| 126 | +function TWhatsNewDlg.GetAligner: IFormAligner; |
| 127 | +begin |
| 128 | + Result := TAligner.Create; |
| 129 | +end; |
| 130 | + |
| 131 | +{ TWhatsNewDlg.TAligner } |
| 132 | + |
| 133 | +procedure TWhatsNewDlg.TAligner.AlignForm(const AForm: TCustomForm); |
| 134 | +var |
| 135 | + WorkArea: TRectEx; |
| 136 | +begin |
| 137 | + // This form is designed for display centred on desktop, so assume it fits |
| 138 | + WorkArea := Screen.WorkAreaRect; |
| 139 | + AForm.Left := WorkArea.Left + (WorkArea.Width - AForm.Width) div 2; |
| 140 | + AForm.Top := WorkArea.Top + (WorkArea.Height - AForm.Height) div 2; |
| 141 | +end; |
| 142 | + |
| 143 | +end. |
| 144 | + |
0 commit comments