home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 September / Chip_2001-09_cd1.bin / zkuste / delphi / kolekce / d12345 / MISC.ZIP / Options.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-05-02  |  4.6 KB  |  169 lines

  1. unit Options;
  2.  
  3. {$I Misc.inc}
  4.  
  5. {-----------------------------------------------------------------------------
  6. 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
  7.  
  8. http://www.mozilla.org/MPL/MPL-1.1.html
  9.  
  10. Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for the specific language governing rights and limitations under the License.
  11.  
  12. The Original Code is: Options.pas, released 12 September 2000.
  13.  
  14. The Initial Developer of the Original Code is Mat Ballard.
  15. Portions created by Mat Ballard are Copyright (C) 1999 Mat Ballard.
  16. Portions created by Microsoft are Copyright (C) 1998, 1999 Microsoft Corp.
  17. All Rights Reserved.
  18.  
  19. Contributor(s): Mat Ballard                 e-mail: mat.ballard@chemware.hypermart.net.
  20.  
  21. Last Modified: 05/25/2000
  22. Current Version: 2.00
  23.  
  24. You may retrieve the latest version of this file from:
  25.  
  26.         http://Chemware.hypermart.net/
  27.  
  28. This work was created with the Project JEDI VCL guidelines:
  29.  
  30.         http://www.delphi-jedi.org/Jedi:VCLVCL
  31.  
  32. in mind. 
  33.  
  34.  
  35. Purpose:
  36. This form is used to display a standard "About" dialog box with a few extra wrinkles.
  37.  
  38. Known Issues:
  39. -----------------------------------------------------------------------------}
  40.  
  41. interface
  42.  
  43. uses
  44.   Classes, SysUtils,
  45. {$IFDEF WINDOWS}
  46.   WinTypes, WinProcs,
  47.   Buttons, Controls, ExtCtrls, Forms, StdCtrls
  48. {$ENDIF}
  49. {$IFDEF WIN32}
  50.   Windows,
  51.   Buttons, Controls, ExtCtrls, Forms, StdCtrls
  52. {$ENDIF}
  53. {$IFDEF LINUX}
  54.   QT,
  55.   QButtons, QControls, QExtCtrls, QForms, QStdCtrls
  56. {$ENDIF}
  57.   ;
  58.  
  59. type
  60.   TOptionsForm = class(TForm)
  61.     OptionsRadioGroup: TRadioGroup;
  62.     QuestionLabel: TLabel;
  63.     OKBitBtn: TBitBtn;
  64.     HelpBitBtn: TBitBtn;
  65.     CancelBitBtn: TBitBtn;
  66.     procedure OKBitBtnClick(Sender: TObject);
  67.     procedure CancelBitBtnClick(Sender: TObject);
  68.     procedure FormCreate(Sender: TObject);
  69.     procedure FormShow(Sender: TObject);
  70.   public
  71.     procedure DoGeometry;
  72.   end;
  73.  
  74. var
  75.   OptionsForm: TOptionsForm;
  76.  
  77. implementation
  78.  
  79. {$R *.dfm}
  80.  
  81. procedure TOptionsForm.FormCreate(Sender: TObject);
  82. begin {Form has not yet had properties set}
  83. {$IFDEF MSWINDOWS}
  84.   {Self.PixelsPerInch := 96;}
  85.   Self.BorderStyle := bsDialog;
  86. {$ENDIF}
  87. {$IFDEF LINUX}
  88.   {Self.PixelsPerInch := 75;}
  89.   Self.BorderStyle := fbsDialog;
  90. {$ENDIF}
  91. end;
  92.  
  93.  
  94. procedure TOptionsForm.DoGeometry;
  95. var
  96.   i: Integer;
  97.   StrLength: Integer;
  98.   StrMax: String;
  99.   Size: Integer;
  100. begin
  101.   QuestionLabel.Left := QuestionLabel.Left;
  102.   QuestionLabel.Top := QuestionLabel.Top;
  103.  
  104.   StrLength := 0;
  105.   StrMax := '';
  106.   for i := 0 to OptionsRadioGroup.ControlCount-1 do
  107.   begin
  108.     if (Length(TRadioButton(OptionsRadioGroup.Controls[i]).Caption) > StrLength) then
  109.     begin
  110.       StrMax := TRadioButton(OptionsRadioGroup.Controls[i]).Caption;
  111.       StrLength := Length(StrMax);
  112.     end;
  113.   end;
  114.   if (Length(OptionsRadioGroup.Caption) > StrLength) then
  115.     StrMax := OptionsRadioGroup.Caption;
  116.   StrMax := StrMax + 'WWWWW';
  117.  
  118.   Size := Canvas.TextWidth(StrMax);
  119.   if (Size < 265) then Size := 265;
  120.  
  121.   if (QuestionLabel.Width > Size) then
  122.     OptionsRadioGroup.Width := QuestionLabel.Width
  123.    else
  124.     OptionsRadioGroup.Width := Size;
  125.  
  126.   OptionsRadioGroup.Top := 2 * QuestionLabel.Top +
  127.                            QuestionLabel.Height;
  128.   OptionsRadioGroup.Height := (OptionsRadioGroup.Items.Count +1)*
  129.                               OKBitBtn.Height;
  130.  
  131.   OKBitBtn.Top := OptionsRadioGroup.Top +
  132.                   OptionsRadioGroup.Height +
  133.                   QuestionLabel.Top;
  134.   CancelBitBtn.Top := OKBitBtn.Top;
  135.   HelpBitBtn.Top := OKBitBtn.Top;
  136.  
  137.   ClientHeight := OKBitBtn.Top + 3 * OKBitBtn.Height div 2;
  138.   ClientWidth := 2 * QuestionLabel.Left + OptionsRadioGroup.Width;
  139.  
  140.  
  141.   HelpBitBtn.Left := Width - QuestionLabel.Left - HelpBitBtn.Width;
  142.   CancelBitBtn.Left := HelpBitBtn.Left - QuestionLabel.Left - CancelBitBtn.Width;
  143.   OKBitBtn.Left := CancelBitBtn.Left - QuestionLabel.Left - CancelBitBtn.Width;
  144.  
  145.   Left := 10;
  146.   Top := 10;
  147. end;
  148.  
  149. procedure TOptionsForm.FormShow(Sender: TObject);
  150. begin {Form is ALREADY VISIBLE !}
  151.   DoGeometry;
  152.   OptionsRadioGroup.ItemIndex := 0;
  153.   TRadioButton(OptionsRadioGroup.Controls[0]).SetFocus;
  154. end;
  155.  
  156. procedure TOptionsForm.OKBitBtnClick(Sender: TObject);
  157. begin
  158. {note: if ModalResult is 0, then the form DOES NOT CLOSE,
  159.  so selection is 1..n:}
  160.   ModalResult := OptionsRadioGroup.ItemIndex + 1;
  161. end;
  162.  
  163. procedure TOptionsForm.CancelBitBtnClick(Sender: TObject);
  164. begin
  165.   ModalResult := -1;
  166. end;
  167.  
  168. end.
  169.  
  170.