home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 May / Chip_2002-05_cd1.bin / zkuste / delphi / kompon / d123456 / PJABOUT.ZIP / PJAbout.pas < prev   
Pascal/Delphi Source File  |  2002-03-09  |  18KB  |  454 lines

  1. { ##
  2.   @FILE                     PJAbout.pas
  3.   @COMMENTS                 About Dialog Box component source file
  4.   @PROJECT_NAME             About Dialog Box Component
  5.   @PROJECT_DESC             Component that displays an about dialog box
  6.   @OTHER_NAMES              + Original unit name was AboutBox.pas
  7.                             + Changed to PJAbout.pas at v3.2
  8.   @AUTHOR                   Peter Johnson, LLANARTH, Ceredigion, Wales, UK
  9.   @EMAIL                    peter.johnson@openlink.org
  10.   @WEBSITE                  http://www.pjsoft.contactbox.co.uk/
  11.   @COPYRIGHT                ⌐ Peter D Johnson, 1998-2002.
  12.   @LEGAL_NOTICE             This component and source code is placed in the
  13.                             public domain. It may be freely copied and
  14.                             circulated on a not for profit basis providing that
  15.                             the code is unmodified and this notice and
  16.                             information about the author and his copyright
  17.                             remains attached to the source code.
  18.   @DEPENDENCIES             + PJSoft VerInfo unit v1 for Delphi 1.
  19.                             + PJSoft PJVersionInfo unit v3.0 for Delphi 2-6.
  20.   @HISTORY(
  21.     @REVISION(
  22.       @VERSION              1.0
  23.       @DATE                 16/02/1998
  24.       @COMMENTS             Original version - 16 bit only.
  25.     )
  26.     @REVISION(
  27.       @VERSION              2.0
  28.       @DATE                 25/04/1998
  29.       @COMMENTS             + Added VersionInfo property to link to any
  30.                               TPJVersionInfo component on form to allow text in
  31.                               dialog box to come from file version info instead
  32.                               of ProgramName, Version, Copyright and Notes
  33.                               properties.
  34.                             + Replaced Caption property with a Title property
  35.                               which has same effect but has name in common with
  36.                               other VCL dialog box components.
  37.                             + Added button height property to control height of
  38.                               Done button.
  39.     )
  40.     @REVISION(
  41.       @VERSION              2.1
  42.       @DATE                 01/08/1998
  43.       @COMMENTS             Added HelpContext property to allow help to be
  44.                             displayed when F1 is pressed if property has a value
  45.                             > 0.
  46.     )
  47.     @REVISION(
  48.       @VERSION              2.2
  49.       @DATE                 01/08/1998
  50.       @COMMENTS             Made appearance of glyphs on buttons depend on state
  51.                             of system global variable MsgDlgGlyphs - if this
  52.                             value is false it overrides ButtonGlyph property and
  53.                             glyphs do not appear on buttons - if the value is
  54.                             true the appearance of glyphs depends on the
  55.                             ButtonGlyph property.
  56.     )
  57.     @REVISION(
  58.       @VERSION              3.0
  59.       @DATE                 06/12/1998
  60.       @COMMENTS             + Made compatible with Delphi 1 & 2.
  61.                             + Made appearance of glyphs on buttons depend on
  62.                               state of new property AutoDetectGlyphs. If this is
  63.                               true (default) then whether buttons are displayed
  64.                               depends on whether 16 or 32 bit Delphi is being
  65.                               used. With 16 bit Delphi, appearance of glyphs
  66.                               depends on MsgDlgGlyphs typed constant (which is
  67.                               same default behaviour as v2.2). With 32 bit
  68.                               Delphi no glyphs will appear when AutoDetectGlyphs
  69.                               is true, which conforms with behaviour of
  70.                               MessageDlgXXX procedures.
  71.     )
  72.     @REVISION(
  73.       @VERSION              3.0.1
  74.       @DATE                 09/04/1999
  75.       @COMMENTS             Changed installation palette to "PJ Stuff" from
  76.                             "Own".
  77.     )
  78.     @REVISION(
  79.       @VERSION              3.1
  80.       @DATE                 27/11/1999
  81.       @COMMENTS             + Made compatible with Delphi 1, 2, 3 & 4.
  82.                             + Fixed potential bug where UseButtonGlyphProperty
  83.                               variable in Execute method was not being set under
  84.                               some conditions.
  85.                             + Replaced reference to VerInfo unit with reference
  86.                               to VInfo unit when compiled under 32 bit Delphi
  87.                               (VerInfo name clashes with an existing unit in
  88.                               Delphi v3 and v4).
  89.                             + Moved declaration of TAboutDlg form class from
  90.                               implementation to interface section to allow to
  91.                               compile under Delphi 4.
  92.     )
  93.     @REVISION(
  94.       @VERSION              3.2
  95.       @DATE                 09/03/2002
  96.       @COMMENTS             + Replaced reference to VInfo unit with reference to
  97.                               PJVersionInfo when compiled under 32 bit Delphi.
  98.                             + Changed form name to TPJAboutBoxForm.
  99.                             + Added Notification method override to remove
  100.                               reference to version information component if that
  101.                               component is deleted.
  102.                             + Added new ButtonWidth property.
  103.                             + Made default button height and width properties
  104.                               different when compiled under 16 and 32 bit
  105.                               Delphi. These value reflect the default button
  106.                               sizes used by 16 and 32 bit Delphi.
  107.                             + Changed dialog box font size to 8 when compiled
  108.                               under 32 bit Delphi. This font size now conforms
  109.                               to Windows 95 standards.
  110.                             + Changed component palette from 'PJ Stuff' to
  111.                               'PJSoft'.
  112.     )
  113.   )
  114. }
  115.  
  116.  
  117. unit PJAbout;
  118.  
  119. interface
  120.  
  121. uses
  122.   { Delphi }
  123.   Forms, ExtCtrls, StdCtrls, Buttons, Classes, Controls,
  124.   { PJSoft components }
  125.   {$IFDEF WIN32}
  126.     PJVersionInfo;
  127.   {$ELSE}
  128.     VerInfo;
  129.   {$ENDIF}
  130.  
  131. {$R *.DFM}
  132.  
  133. type
  134.  
  135.   {
  136.   TPJAboutBoxForm:
  137.     Form class that defines the about box component's dialog box.
  138.   }
  139.   TPJAboutBoxForm = class(TForm)
  140.     Bevel1: TBevel;
  141.     Bevel2: TBevel;
  142.     Bevel3: TBevel;
  143.     ProgramLbl: TLabel;
  144.     VersionLbl: TLabel;
  145.     CopyrightLbl: TLabel;
  146.     NotesLbl: TLabel;
  147.     IconImg: TImage;
  148.     DoneBtn: TBitBtn;
  149.   end;
  150.  
  151.   {
  152.   TPJAboutBtnPlacing:
  153.     Determines horizontal placement of OK button in about dialog.
  154.   }
  155.   TPJAboutBtnPlacing = (abpLeft, abpCentre, abpRight);
  156.  
  157.   {
  158.   TPJAboutBtnKinds:
  159.     Determines caption of about dialog's OK button.
  160.   }
  161.   TPJAboutBtnKinds = (abkOK, abkDone, abkClose, abkCancel);
  162.  
  163.   {
  164.   TPJAboutBtnGlyphs:
  165.     Determines the glyph displayed on about dialog's OK button.
  166.   }
  167.   TPJAboutBtnGlyphs = (abgOK, abgCancel, abgIgnore, abgClose, abgNone);
  168.  
  169.   {
  170.   TPJAboutBoxDlg:
  171.     The about box component class.
  172.   }
  173.   TPJAboutBoxDlg = class(TComponent)
  174.   private
  175.     {Property storage}
  176.     fTitle: string;
  177.     fProgramName: string;
  178.     fVersion: string;
  179.     fCopyright: string;
  180.     fNotes: string;
  181.     fButtonPlacing: TPJAboutBtnPlacing;
  182.     fButtonKind: TPJAboutBtnKinds;
  183.     fButtonGlyph: TPJAboutBtnGlyphs;
  184.     fAutoDetectGlyphs: Boolean;
  185.     fButtonHeight: Integer;
  186.     fButtonWidth: Integer;
  187.     fCentreDlg: Boolean;
  188.     fDlgLeft: Integer;
  189.     fDlgTop: Integer;
  190.     fVersionInfo: TPJVersionInfo;
  191.     fHelpContext: THelpContext;
  192.   protected
  193.     procedure Notification(AComponent: TComponent;
  194.       Operation: TOperation); override;
  195.       {Check to see if any linked version info component is being deleted and
  196.       clear reference to it if so}
  197.   public
  198.     constructor Create(AOwner: TComponent); override;
  199.       {Component constructor}
  200.     procedure Execute;
  201.       {Execute method displays the dialog box}
  202.   published
  203.     property Title: string
  204.       read fTitle write fTitle;
  205.       {The text appearing in the dialog box title bar - default is "About"}
  206.     property ProgramName: string
  207.       read fProgramName write fProgramName;
  208.       {The name of the program - appears on 1st line of about box - ignored if
  209.       the VersionInfo property is assigned}
  210.     property Version: string
  211.       read fVersion write fVersion;
  212.       {The program version - appears on 2nd line of about box - ignored if the
  213.       VersionInfo property is assigned}
  214.     property Copyright: string
  215.       read fCopyright write fCopyright;
  216.       {The program copyright message - appears on 3rd line of about box -
  217.       ignored if the VersionInfo property is assigned}
  218.     property Notes: string
  219.       read fNotes write fNotes;
  220.       {Notes about program - text wraps up to 3 lines - last entry in about box
  221.       - ignored if the VersionInfo property is assigned}
  222.     property ButtonPlacing: TPJAboutBtnPlacing
  223.       read fButtonPlacing write fButtonPlacing default abpCentre;
  224.       {Where to place "Done" button - left, centre or right of bottom of box}
  225.     property ButtonKind: TPJAboutBtnKinds
  226.       read fButtonKind write fButtonKind default abkOK;
  227.       {Kind of button - determines text that appears: 'OK', 'Cancel', 'Done' or
  228.       'Close'}
  229.     property ButtonGlyph: TPJAboutBtnGlyphs
  230.       read fButtonGlyph write fButtonGlyph default abgOK;
  231.       {Glyph (if any) that appears on button. If AutoDetectGylphs property is
  232.       true then whether this property has an effect depends on system settings}
  233.     property AutoDetectGlyphs: Boolean
  234.       read fAutoDetectGlyphs write fAutoDetectGlyphs default True;
  235.       {Determine whether to display glyphs according to ButtonGlyph property
  236.       (when this property is false) or whether to display glyphs according to
  237.       system settings. In Delphi 1 this depends on state of MsgDlgGlyphs typed
  238.       constant (if it's true then glyphs are displayed per ButtonGlyphs property
  239.       and not otherwise) while in Delphi 2 glyphs aren't displayed}
  240.     property ButtonHeight: Integer
  241.       read fButtonHeight write fButtonHeight
  242.       {$IFDEF WIN32}
  243.         default 25;
  244.       {$ELSE}
  245.         default 33;
  246.       {$ENDIF}
  247.       {The height of the button}
  248.     property ButtonWidth: Integer
  249.       read fButtonWidth write fButtonWidth
  250.       {$IFDEF WIN32}
  251.         default 75;
  252.       {$ELSE}
  253.         default 89;
  254.       {$ENDIF}
  255.       {The width of the button}
  256.     property DlgLeft: Integer
  257.       read fDlgLeft write fDlgLeft stored True;
  258.       {Position of left side of about box on screen - ignored if CentreDlg is
  259.       true}
  260.     property DlgTop: Integer
  261.       read fDlgTop write fDlgTop stored True;
  262.       {Position of top side of about box on screen - ignored if CentreDlg is
  263.       true}
  264.     property CentreDlg: Boolean
  265.       read fCentreDlg write fCentreDlg stored True default True;
  266.       {About box is centred on screen when this property is true, and positioned
  267.       according to DlgLeft and DlgTop when false}
  268.     property VersionInfo: TPJVersionInfo
  269.       read fVersionInfo write fVersionInfo;
  270.       {Link to a TPJVersionInfo component. If this property is not nil then the
  271.       ProductName, ProductVersion, LegalCopyright & Comments properties of the
  272.       control are used instead of the ProgramName, Version, Copyright and Notes
  273.       properties of this component}
  274.     property HelpContext: THelpContext
  275.       read fHelpContext write fHelpContext;
  276.       {Sets help context for dialog box - if this is non-zero pressing F1 when
  277.       dialog box is displayed causes help topic with given context number in
  278.       application's help file to be displayed}
  279.   end;
  280.  
  281. procedure Register;
  282.   {Register this component}
  283.  
  284. implementation
  285.  
  286. uses
  287.   { Delphi }
  288.   {$IFDEF WIN32}
  289.     Windows;
  290.   {$ELSE}
  291.     WinTypes, WinProcs, Dialogs;
  292.   {$ENDIF}
  293.  
  294. { Component registration routine }
  295.  
  296. procedure Register;
  297.   {Register this component}
  298. begin
  299.   RegisterComponents('PJSoft', [TPJAboutBoxDlg]);
  300. end;
  301.  
  302. { TPJAboutBoxDlg }
  303.  
  304. constructor TPJAboutBoxDlg.Create(AOwner: TComponent);
  305.   {Component constructor}
  306. begin
  307.   inherited Create(AOwner);
  308.   {Set default values for properties}
  309.   fButtonPlacing := abpCentre;      {place button at centre of box}
  310.   fButtonKind := abkOK;             {button kind is "OK"}
  311.   fButtonGlyph := abgOK;            {use OK glyph}
  312.   {$IFDEF WIN32}
  313.     fButtonHeight := 25;            {default button height - 32 bit}
  314.     fButtonWidth := 75;             {default button width - 32 bit}
  315.   {$ELSE}
  316.     fButtonHeight := 33;            {default button height - 16 bit}
  317.     fButtonWidth := 89;             {default button width - 16 bit}
  318.   {$ENDIF}
  319.   fTitle := 'About';                {default caption is "About"}
  320.   fCentreDlg := True;               {ensures dialog box is centred}
  321.   fAutoDetectGlyphs := True;        {default property value}
  322. end;
  323.  
  324. procedure TPJAboutBoxDlg.Execute;
  325.   {Execute method displays the dialog box}
  326. var
  327.   Box: TPJAboutBoxForm;              {the instance of the dialog box}
  328.   UseButtonGlyphProperty: Boolean;   {flag true if to use ButtonGlyph property}
  329. begin
  330.   {Create the dialog box instance}
  331.   Box := TPJAboutBoxForm.Create(Application);
  332.   try
  333.     {$IFDEF WIN32}
  334.       Box.Font.Size := 8;
  335.     {$ENDIF}
  336.     {Set caption}
  337.     Box.Caption := fTitle;
  338.     {Decide whether to use version info or to use properties for dialog's text}
  339.     if fVersionInfo <> nil then
  340.     begin
  341.       {Get displayed text from linked TPJVersionInfo component properties}
  342.       Box.ProgramLbl.Caption := fVersionInfo.ProductName;
  343.       Box.VersionLbl.Caption := fVersionInfo.ProductVersion;
  344.       Box.CopyrightLbl.Caption := fVersionInfo.LegalCopyright;
  345.       Box.NotesLbl.Caption := fVersionInfo.Comments;
  346.     end
  347.     else
  348.     begin
  349.       {No linked TPJVersionInfo: get displayed text from string properties}
  350.       {set program name, if none specified use application title}
  351.       if ProgramName = '' then
  352.         Box.ProgramLbl.Caption := Application.Title
  353.       else
  354.         Box.ProgramLbl.Caption := ProgramName;
  355.       {set version, copyright and notes}
  356.       Box.VersionLbl.Caption := Version;
  357.       Box.CopyrightLbl.Caption := Copyright;
  358.       Box.NotesLbl.Caption := Notes;
  359.     end;
  360.     {Set icon to application icon}
  361.     Box.IconImg.Picture.Graphic := Application.Icon;
  362.     {Configure done button}
  363.     {set button size}
  364.     Box.DoneBtn.Height := fButtonHeight;
  365.     Box.DoneBtn.Width := fButtonWidth;
  366.     {place button horizontally}
  367.     case ButtonPlacing of
  368.       abpLeft:
  369.         Box.DoneBtn.Left := Box.Bevel1.Left;
  370.       abpRight:
  371.         Box.DoneBtn.Left := Box.Bevel1.Width + Box.Bevel1.Left
  372.           - Box.DoneBtn.Width;
  373.       abpCentre:
  374.         Box.DoneBtn.Left := (Box.ClientWidth - Box.DoneBtn.Width) div 2;
  375.     end;
  376.     {decide whether to use button glyph property, depending on value of
  377.     AutoDetectGlyphs property and whether using 16 bit or 32 bit Delphi}
  378.     if fAutoDetectGlyphs then
  379.     begin
  380.       {$IFDEF WIN32}
  381.         UseButtonGlyphProperty := False;
  382.       {$ELSE}
  383.         UseButtonGlyphProperty := MsgDlgGlyphs;
  384.       {$ENDIF}
  385.     end
  386.     else
  387.       UseButtonGlyphProperty := True;
  388.     {set button's glyph if required}
  389.     if UseButtonGlyphProperty then
  390.       {use ButtonGlyph property: load bitmap resource included by TBitBtn}
  391.       case ButtonGlyph of
  392.         abgOK:
  393.           Box.DoneBtn.Glyph.Handle := LoadBitmap(HInstance, 'BBOK');
  394.         abgCancel:
  395.           Box.DoneBtn.Glyph.Handle := LoadBitmap(HInstance, 'BBCANCEL');
  396.         abgIgnore:
  397.           Box.DoneBtn.Glyph.Handle := LoadBitmap(HInstance, 'BBIGNORE');
  398.         abgClose:
  399.           Box.DoneBtn.Glyph.Handle := LoadBitmap(HInstance, 'BBCLOSE');
  400.         abgNone:
  401.           Box.DoneBtn.Glyph := nil;
  402.       end
  403.     else
  404.       {ignore ButtonGlyphs property: don't use glyphs}
  405.       Box.DoneBtn.Glyph := nil;
  406.     {set correct button text according to button kind property}
  407.     case ButtonKind of
  408.       abkOK: Box.DoneBtn.Caption := 'OK';
  409.       abkDone: Box.DoneBtn.Caption := 'Done';
  410.       abkClose: Box.DoneBtn.Caption := 'Close';
  411.       abkCancel: Box.DoneBtn.Caption := 'Cancel';
  412.     end;
  413.     {adjust dialog box height according to button height}
  414.     Box.ClientHeight := 166 + fButtonHeight;
  415.     {Position dialog on screen per positioning properties}
  416.     if fCentreDlg then
  417.     begin
  418.       {centre on screen - ignore DlgLeft & DlgTop}
  419.       Box.Left := (Screen.Width - Box.Width) div 2;
  420.       Box.Top := (Screen.Height - Box.Height) div 2;
  421.     end
  422.     else
  423.     begin
  424.       {position per DlgLeft and DlgTop and adjust to keep on screen}
  425.       if fDlgLeft + Box.Width > Screen.Width then
  426.         Box.Left := Screen.Width - Box.Width
  427.       else
  428.         Box.Left := fDlgLeft;
  429.       if fDlgTop + Box.Height > Screen.Height then
  430.         Box.Top := Screen.Height - Box.Height
  431.       else
  432.         Box.Top := fDlgTop;
  433.     end;
  434.     {Set required help context for about box: displays help on pressing F1 key}
  435.     Box.HelpContext := fHelpContext;
  436.     {Show the about box}
  437.     Box.ShowModal;
  438.   finally
  439.     {Free the instance of the about box}
  440.     Box.Free;
  441.   end;
  442. end;
  443.  
  444. procedure TPJAboutBoxDlg.Notification(AComponent: TComponent;
  445.   Operation: TOperation);
  446.   {Check to see if any linked version info component is being deleted and clear
  447.   reference to it if so}
  448. begin
  449.   if (Operation = opRemove) and (AComponent = fVersionInfo) then
  450.     fVersionInfo := nil;
  451. end;
  452.  
  453. end.
  454.