Menu

[r111]: / trunk / Src / FmAboutDlg.pas  Maximize  Restore  History

Download this file

483 lines (444 with data), 19.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
{
* FmAboutDlg.pas
*
* Implements about dialog box.
*
* v0.1 of 30 Jan 2005 - Original version.
* v0.2 of 20 Feb 2005 - Changed name of template html file to
* dlg-about-tplt.html.
* v0.3 of 23 Feb 2005 - Changed to use new THTMLTpltDlgFrame frame instead of
* THTMLDlgFrame to process HTML template and display
* dialog content.
* v0.4 of 01 Mar 2005 - Template HTML revised. Resolved new <%ResURL%> place-
* holder with root part of res:// url to program's
* resources. New template changes appearance of dialog
* and adds "Powered by Delphi" logo.
* v0.5 of 04 Jan 2006 - Fixed problem where help failed to display because F1
* key press was not being detected.
* v0.6 of 14 Jan 2006 - Resized to accomodate revised content.
* v0.7 of 07 Apr 2006 - Removed dependency on TPJVersionInfo. Replaced with
* calls to new methods of TAppInfo.
* - Added code to replace new Registration HTML
* placeholder with registration information.
* - Made dialog box resize to accomodate size of dialog's
* HTML.
* - Added new "Register CodeSnip" button that is displayed
* only if application is unregistered and displays
* registration wizard when clicked.
* v1.0 of 04 Jun 2006 - Improved and corrected comments.
* - Removed unused unit references.
* - Added code to execute files flagged with fake
* 'execute' protocol when links clicked in browser.
* - Highlighted note that program unregistered in red.
* - Added directive to turn off unsafe type warnings.
* - Changed to derive from base class that can resize
* dialog to fit HTML content. Removed code from this
* unit that did same job.
* - Widened dialog box.
* v1.1 of 25 Oct 2006 - Removed OnBeforeNavigate2 event handler and code that
* checked for "execute:" protocol. This has now moved to
* TBrowserBaseFrame and is available to all browser
* frames that descend from it.
* - Changed so that path to license file is provided via
* HTML template rather than hard-wiring path into code
* that displays license.
* v1.2 of 26 Oct 2006 - Changed to replace LicenseFileName template id with
* path to license file rather than providing only
* directory containing license file.
* v1.3 of 07 Nov 2006 - Changed to use UCSSUtils methods to generate CSS
* attributes.
* v1.4 of 14 Nov 2006 - Removed resolution of LicenseFileName template id
* since it has been removed from the dialog box
* template.
* v1.5 of 25 Nov 2006 - Changed literal colour reference to special program
* colour constant.
* - Added .header class to frame's CSS. This is used to
* colour the dialog's header rather than hard wired
* colour formerly in HTML template file.
* v1.6 of 08 Feb 2007 - Modified to work with revised THTMLViewDlg base class
* and new form customisation and alignment framework.
* - Re-assigned form's OnCreate event handler that was
* uncoupled when handler in ancestor class was deleted.
* v1.7 of 11 Feb 2007 - Removed code that made body panel active control on
* start up. We now allow browser control to be focussed.
* v2.0 of 11 Feb 2007 - Major revision.
* - Added information about database and separated out
* heading from main body of program information. There
* is now an HTML frame containing the heading and two
* further frames giving informaion about program and
* database, hosted by a page control. Database frame
* displays list of contributors loaded from a downloaded
* file.
* - Also made other changes to accomodate modifications to
* base class:
* * Added new GetBodyPanelHeight method override to
* return required height of body panel which now
* depends on height of heading frame and page control,
* which in turn is sized to the longest of the HTML
* documents it contains.
* * Removed redundant GetBrowser method.
* v2.1 of 22 Sep 2007 - Changed "About The Database" tab to list testers as
* well as contributors.
* v2.2 of 05 Nov 2007 - Changed to use revised CSS builder classes.
* v2.3 of 21 Apr 2008 - Fixed problem with border of Title HTML frame: removed
* CSS body border property and added framing panel to
* provide body.
* v2.4 of 11 Aug 2008 - Replaced calls to ThemeServices with ThemeServicesEx.
* v2.5 of 24 Aug 2008 - Modified to work with revised contributor classes to
* get list of names of code contributors and testers.
* v2.6 of 13 Jan 2009 - Replaced control char literals with constants.
* - Made protected section strict.
* v2.7 of 25 Jan 2009 - Changed to use routines and objects from UHTMLUtils
* to generate HTML tags.
* v2.8 of 16 Jun 2009 - Added facility to display easter egg by clicking
* program icon in title HTML frame.
* - Changed to use content font in detail (tabbed) frames.
* - Added space to separate "un-registered" message from
* following prompt text.
* - Removed type qualifier from constructor call in
* TAboutDlg.Execute.
* - Widened dialog box.
*
*
* ***** BEGIN LICENSE BLOCK *****
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* The Original Code is FmAboutDlg.pas
*
* The Initial Developer of the Original Code is Peter Johnson
* (http://www.delphidabbler.com/).
*
* Portions created by the Initial Developer are Copyright (C) 2005-2009 Peter
* Johnson. All Rights Reserved.
*
* ***** END LICENSE BLOCK *****
}
unit FmAboutDlg;
interface
uses
// Delphi
Forms, ComCtrls, StdCtrls, Controls, ExtCtrls, Classes,
// Project
FmHTMLViewDlg, FrBrowserBase, FrHTMLDlg, FrHTMLTpltDlg, UCSSBuilder,
UHTMLEvents;
type
{
TAboutDlg:
Implements an about dialog box that uses web browser controls to display
information about the program and the database. HTML templates containing
the dialog box content are loaded from resources. Also provides access to
the program's easter egg.
}
TAboutDlg = class(THTMLViewDlg)
btnRegister: TButton;
bvlSeparator: TBevel;
frmDatabase: THTMLTpltDlgFrame;
frmProgram: THTMLTpltDlgFrame;
pcDetail: TPageControl;
tsDatabase: TTabSheet;
tsProgram: TTabSheet;
pnlTitle: TPanel;
frmTitle: THTMLTpltDlgFrame;
procedure btnRegisterClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
strict private
procedure HTMLEventHandler(Sender: TObject;
const EventInfo: THTMLEventInfo);
{Handles title frame's OnHTMLEvent event. Checks for easter-egg related
mouse events on icon image and acts accordingly.
@param Sender [in] Not used.
@param EventInfo [in] Object providing information about the event.
}
strict protected
procedure InitForm; override;
{Initialises form's controls.
}
procedure InitHTMLFrame; override;
{Initialises HTML frame to use required template document with
placeholders replaced by required values.
}
function GetBodyPanelHeight: Integer; override;
{Calculates required height of dialog's body panel from height of various
HTML frames.
@return Required height.
}
procedure ArrangeForm; override;
{Adjusts position of registration button on bottom button line. Called
from ancestor class.
}
procedure UpdateTitleCSS(Sender: TObject; const CSSBuilder: TCSSBuilder);
{Updates CSS used for HTML displayed in title frame.
@param Sender [in] Not used.
@param CSSBuilder [in] Object used to update CSS.
}
procedure UpdateDetailCSS(Sender: TObject; const CSSBuilder: TCSSBuilder);
{Updates CSS used for HTML displayed in detail (i.e. program and database)
frames.
@param Sender [in] Not used.
@param CSSBuilder [in] Object used to update CSS.
}
public
class procedure Execute(AOwner: TComponent);
{Displays dialog box.
@param AOwner [in] Component that owns this dialog box.
}
end;
implementation
uses
// Delphi
SysUtils, Graphics, Math, Windows {for inlining},
// Project
FmEasterEgg, FmRegistrationDlg, UAppInfo, UColours, UConsts, UContributors,
UCSSUtils, UFontHelper, UHTMLUtils, UThemesEx;
{
NOTE:
The about box uses three HTML templates. These are stored in RT_HTML resources
as:
+ "dlg-about-head-tplt.html"
+ "dlg-about-program-tplt.html"
+ "dlg-about-database-tplt.html".
The following placeholders are used in one or more of the templates. The
placeholders are replaced by their values within this unit:
<%Release%> program release number
<%Copyright%> copyright info
<%ResURL%> url of programs HTML resources
<%Registered%> info about whether program is registered
}
{$R *.dfm}
{ TAboutDlg }
procedure TAboutDlg.ArrangeForm;
{Adjusts position of registration button on bottom button line. Called from
ancestor class.
}
begin
inherited;
btnRegister.Left := pnlBody.Left;
btnRegister.Top := btnHelp.Top;
end;
procedure TAboutDlg.btnRegisterClick(Sender: TObject);
{Displays registration wizard when "Register CodeSnip" button is clicked.
@param Sender [in] Not used.
}
begin
if TRegistrationDlg.Execute(Self) then
btnRegister.Hide; // hide registration button now that program registered OK
end;
class procedure TAboutDlg.Execute(AOwner: TComponent);
{Displays dialog box.
@param AOwner [in] Component that owns this dialog box.
}
begin
with Create(AOwner) do
try
ShowModal;
finally
Free;
end;
end;
procedure TAboutDlg.FormCreate(Sender: TObject);
{Form initialisation event handler. Sets handler that updates frame's CSS.
@param Sender [in] Not used.
}
begin
inherited;
frmTitle.OnBuildCSS := UpdateTitleCSS;
frmProgram.OnBuildCSS := UpdateDetailCSS;
frmDatabase.OnBuildCSS := UpdateDetailCSS;
end;
function TAboutDlg.GetBodyPanelHeight: Integer;
{Calculates required height of dialog's body panel from height of various HTML
frames.
@return Required height.
}
begin
// Set height of title frame and page control
pnlTitle.Height := frmTitle.DocHeight;
pcDetail.ClientHeight := pcDetail.Height - tsProgram.ClientHeight
+ Max(frmProgram.DocHeight, frmDatabase.DocHeight) + 8;
// Calculate body panel height
Result := pnlTitle.Height + bvlSeparator.Height + pcDetail.Height;
end;
procedure TAboutDlg.HTMLEventHandler(Sender: TObject;
const EventInfo: THTMLEventInfo);
{Handles title frame's OnHTMLEvent event. Checks for easter-egg related mouse
events on icon image and acts accordingly.
@param Sender [in] Not used.
@param EventInfo [in] Object providing information about the event.
}
const
cIconImgId = 'icon'; // id of icon image
begin
// Check for onclick event on icon tag: display easter egg if ctrl key
// pressed. Such an event is cancelled.
if (EventInfo.DispatchId = cDocEventOnClick) and
EventInfo.Args.ctrlKey and
AnsiSameText(EventInfo.Args.srcElement.id, cIconImgId) then
begin
EventInfo.Cancelled := True;
TEasterEggForm.Execute(Self);
end;
// Check for mouse move over icon tag: change cursor to hand if ctrl key
// pressed to indicate clickable. Event permitted to bubble up.
if (EventInfo.DispatchId = cDocEventOnMouseMove) and
AnsiSameText(EventInfo.Args.srcElement.id, cIconImgId) then
begin
if EventInfo.Args.ctrlKey then
EventInfo.Args.srcElement.style.cursor := 'hand'
else
EventInfo.Args.srcElement.style.cursor := 'auto';
end;
end;
procedure TAboutDlg.InitForm;
{Initialises form's controls.
}
begin
inherited;
// Decide whether to display register button
btnRegister.Visible := not TAppInfo.IsRegistered;
end;
procedure TAboutDlg.InitHTMLFrame;
{Initialises HTML frame to use required template document with placeholders
replaced by required values.
}
resourcestring
// Registration messages
sRegisteredMessage = 'Registered to %0:s.';
sUnregisteredMessage = 'Unregistered copy:';
sRegistrationPrompt = 'Please click the button below to register CodeSnip.';
// Error string used when contributor file not available
sNoContributors = 'List not available, please update database.';
// ---------------------------------------------------------------------------
function BuildContribList(const ContribClass: TContributorsClass): string;
{Builds HTML used to display list of contributors or creates an error
message if contributor list is not available.
@param ContribClass [in] Type of contributor class to use. This determines
names that are displayed.
@return Required HTML.
}
var
Contributors: TContributors; // contributors to database
Contributor: string; // name of a contributor
DivAttrs: IHTMLAttributes; // attributes of div tag
begin
Result := '';
// Get list of contributors
Contributors := ContribClass.Create;
try
if not Contributors.IsError then
begin
for Contributor in Contributors do
Result := Result
+ MakeCompoundTag('div', MakeSafeHTMLText(Contributor))
+ EOL;
end
else
begin
// List couldn't be found: display warning message
DivAttrs := THTMLAttributes.Create;
DivAttrs.Add('class', 'warning');
Result := MakeCompoundTag(
'div', DivAttrs, MakeSafeHTMLText(sNoContributors)
);
end;
finally
FreeAndNil(Contributors);
end;
end;
// ---------------------------------------------------------------------------
var
Values: TStringList; // map of HTML placeholders to actual values
SpanAttrs: IHTMLAttributes; // attributes of span tag
begin
// Build map of placeholders to actual values
// the placeholders include all values for all three templates
Values := TStringList.Create;
try
Values.Values['Release'] := TAppInfo.ProgramReleaseInfo;
Values.Values['Copyright'] := TAppInfo.ProgramCopyright;
Values.Values['ResURL'] := MakeResourceURL(''); // URL part before res name
if TAppInfo.IsRegistered then
Values.Values['Registered'] :=
Format(sRegisteredMessage, [TAppInfo.RegisteredUser])
else
begin
SpanAttrs := THTMLAttributes.Create;
SpanAttrs.Add('class', 'warning');
Values.Values['Registered'] :=
MakeCompoundTag(
'span', SpanAttrs, MakeSafeHTMLText(sUnregisteredMessage)
) +
MakeSafeHTMLText(' ' + sRegistrationPrompt);
end;
Values.Values['ContribList'] := BuildContribList(TCodeContributors);
Values.Values['TesterList'] := BuildContribList(TTesters);
// Initialise the dialog content from HTML templates and replacement values
frmTitle.Initialise('dlg-about-head-tplt.html', Values);
pcDetail.ActivePage := tsDatabase; // display page to let browser load OK
frmDatabase.Initialise('dlg-about-database-tplt.html', Values);
pcDetail.ActivePage := tsProgram; // display page to let browser load OK
frmProgram.Initialise('dlg-about-program-tplt.html', Values);
// Handle HTML events on title frame
frmTitle.OnHTMLEvent := HTMLEventHandler;
finally
FreeAndNil(Values);
end;
end;
procedure TAboutDlg.UpdateDetailCSS(Sender: TObject;
const CSSBuilder: TCSSBuilder);
{Updates CSS used for HTML displayed in detail (i.e. program and database)
frames.
@param Sender [in] Not used.
@param CSSBuilder [in] Object used to update CSS.
}
var
ContentFont: TFont; // font used for content
begin
// Modify body's margin and, for themed windows, background colour
with CSSBuilder.Selectors['body'] do
begin
ContentFont := TFont.Create;
try
TFontHelper.SetContentFont(ContentFont, True);
AddProperty(CSSFontProps(ContentFont));
if ThemeServicesEx.ThemesEnabled then
AddProperty(CSSBackgroundColorProp(ThemeServicesEx.GetTabBodyColour));
AddProperty(UCSSUtils.CSSMarginProp(0, 2, 6, 2));
finally
FreeAndNil(ContentFont);
end;
end;
// Put border round scroll box
with CSSBuilder.AddSelector('.scrollbox') do
AddProperty(UCSSUtils.CSSBorderProp(cssAll, 1, cbsSolid, clBorder));
// Set colours and font style of contributors and testers headings
with CSSBuilder.AddSelector('.contrib-head, .tester-head') do
begin
AddProperty(CSSBackgroundColorProp(clBtnFace));
AddProperty(CSSColorProp(clBtnText));
AddProperty(CSSFontWeightProp(cfwBold));
end;
end;
procedure TAboutDlg.UpdateTitleCSS(Sender: TObject;
const CSSBuilder: TCSSBuilder);
{Updates CSS used for HTML displayed in title frame.
@param Sender [in] Not used.
@param CSSBuilder [in] Object used to update CSS.
}
begin
// Set body colour, and put border round it
with CSSBuilder.Selectors['body'] do
begin
AddProperty(CSSBackgroundColorProp(clWindow));
AddProperty(CSSPaddingProp(4));
end;
end;
end.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.