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 >
Pascal/Delphi Source File  |  2001-05-02  |  5KB  |  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. procedure TOptionsForm.DoGeometry;
  94. var
  95.   i: Integer;
  96.   StrLength: Integer;
  97.   StrMax: String;
  98.   Size: Integer;
  99. begin
  100.   QuestionLabel.Left := QuestionLabel.Left;
  101.   QuestionLabel.Top := QuestionLabel.Top;
  102.  
  103.   StrLength := 0;
  104.   StrMax := '';
  105.   for i := 0 to OptionsRadioGroup.ControlCount-1 do
  106.   begin
  107.     if (Length(TRadioButton(OptionsRadioGroup.Controls[i]).Caption) > StrLength) then
  108.     begin
  109.       StrMax := TRadioButton(OptionsRadioGroup.Controls[i]).Caption;
  110.       StrLength := Length(StrMax);
  111.     end;
  112.   end;
  113.   if (Length(OptionsRadioGroup.Caption) > StrLength) then
  114.     StrMax := OptionsRadioGroup.Caption;
  115.   StrMax := StrMax + 'WWWWW';
  116.  
  117.   Size := Canvas.TextWidth(StrMax);
  118.   if (Size < 265) then Size := 265;
  119.  
  120.   if (QuestionLabel.Width > Size) then
  121.     OptionsRadioGroup.Width := QuestionLabel.Width
  122.    else
  123.     OptionsRadioGroup.Width := Size;
  124.  
  125.   OptionsRadioGroup.Top := 2 * QuestionLabel.Top +
  126.                            QuestionLabel.Height;
  127.   OptionsRadioGroup.Height := (OptionsRadioGroup.Items.Count +1)*
  128.                               OKBitBtn.Height;
  129.  
  130.   OKBitBtn.Top := OptionsRadioGroup.Top +
  131.                   OptionsRadioGroup.Height +
  132.                   QuestionLabel.Top;
  133.   CancelBitBtn.Top := OKBitBtn.Top;
  134.   HelpBitBtn.Top := OKBitBtn.Top;
  135.  
  136.   ClientHeight := OKBitBtn.Top + 3 * OKBitBtn.Height div 2;
  137.   ClientWidth := 2 * QuestionLabel.Left + OptionsRadioGroup.Width;
  138.  
  139.  
  140.   HelpBitBtn.Left := Width - QuestionLabel.Left - HelpBitBtn.Width;
  141.   CancelBitBtn.Left := HelpBitBtn.Left - QuestionLabel.Left - CancelBitBtn.Width;
  142.   OKBitBtn.Left := CancelBitBtn.Left - QuestionLabel.Left - CancelBitBtn.Width;
  143.  
  144.   Left := 10;
  145.   Top := 10;
  146. end;
  147.  
  148. procedure TOptionsForm.FormShow(Sender: TObject);
  149. begin {Form is ALREADY VISIBLE !}
  150.   DoGeometry;
  151.   OptionsRadioGroup.ItemIndex := 0;
  152.   TRadioButton(OptionsRadioGroup.Controls[0]).SetFocus;
  153. end;
  154.  
  155. procedure TOptionsForm.OKBitBtnClick(Sender: TObject);
  156. begin
  157. {note: if ModalResult is 0, then the form DOES NOT CLOSE,
  158.  so selection is 1..n:}
  159.   ModalResult := OptionsRadioGroup.ItemIndex + 1;
  160. end;
  161.  
  162. procedure TOptionsForm.CancelBitBtnClick(Sender: TObject);
  163. begin
  164.   ModalResult := -1;
  165. end;
  166.  
  167. end.
  168.  
  169.