home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 October / Chip_2001-10_cd1.bin / zkuste / delphi / kompon / d123456 / CHEMPLOT.ZIP / Misc / Options.pas < prev    next >
Pascal/Delphi Source File  |  2001-07-24  |  7KB  |  220 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.   Misc;
  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. {$IFNDEF LANG_ENGLISH}
  73.     procedure DoCaptionsFromResource;
  74. {$ENDIF}
  75.     procedure DoHintsFromResource;
  76.   end;
  77.  
  78. var
  79.   OptionsForm: TOptionsForm;
  80.  
  81. implementation
  82.  
  83. {$R *.dfm}
  84.  
  85. {------------------------------------------------------------------------------
  86.     Procedure: TOptionsForm.FormCreate
  87.   Description: standard FormCreate procedure
  88.        Author: Mat Ballard
  89.  Date created: 04/25/2000
  90. Date modified: 04/25/2000 by Mat Ballard
  91.       Purpose: sets the position and fills the labels
  92.  Known Issues:
  93.  ------------------------------------------------------------------------------}
  94. procedure TOptionsForm.FormCreate(Sender: TObject);
  95. begin {Form has not yet had properties set}
  96. {$IFNDEF LANG_ENGLISH}
  97.   DoCaptionsFromResource;
  98. {$ENDIF}
  99.   DoHintsFromResource;
  100.  
  101. {$IFDEF MSWINDOWS}
  102.   {Self.PixelsPerInch := 96;}
  103.   Self.BorderStyle := bsDialog;
  104. {$ENDIF}
  105. {$IFDEF LINUX}
  106.   {Self.PixelsPerInch := 75;}
  107.   Self.BorderStyle := fbsDialog;
  108. {$ENDIF}
  109. end;
  110.  
  111.  
  112. procedure TOptionsForm.DoGeometry;
  113. var
  114.   i,
  115.   TheSize,
  116.   StrLength: Integer;
  117.   StrMax: String;
  118.   Size: Integer;
  119. begin
  120.   StrLength := 0;
  121.   StrMax := '';
  122.   for i := 0 to OptionsRadioGroup.ControlCount-1 do
  123.   begin
  124.     if (Length(TRadioButton(OptionsRadioGroup.Controls[i]).Caption) > StrLength) then
  125.     begin
  126.       StrMax := TRadioButton(OptionsRadioGroup.Controls[i]).Caption;
  127.       StrLength := Length(StrMax);
  128.     end;
  129.   end;
  130.   if (Length(OptionsRadioGroup.Caption) > StrLength) then
  131.     StrMax := OptionsRadioGroup.Caption;
  132.   StrMax := StrMax + 'WWWWW';
  133.  
  134.   TheSize := CancelBitBtn.Left + CancelBitBtn.Width - HelpBitBtn.Left;
  135.   Size := Canvas.TextWidth(StrMax);
  136.   if (Size < TheSize) then Size := TheSize;
  137.  
  138.   if (QuestionLabel.Width > Size) then
  139.     Size := QuestionLabel.Width;
  140.   OptionsRadioGroup.Width := Size;
  141.  
  142.   OptionsRadioGroup.Top := 2 * QuestionLabel.Top +
  143.                            QuestionLabel.Height;
  144.   OptionsRadioGroup.Height := (OptionsRadioGroup.Items.Count +1)*
  145.                               OKBitBtn.Height;
  146.  
  147.   OKBitBtn.Top := OptionsRadioGroup.Top +
  148.                   OptionsRadioGroup.Height +
  149.                   QuestionLabel.Top;
  150.   CancelBitBtn.Top := OKBitBtn.Top;
  151.   HelpBitBtn.Top := OKBitBtn.Top;
  152.  
  153.   ClientHeight := OKBitBtn.Top + 3 * OKBitBtn.Height div 2;
  154.   ClientWidth := 2 * QuestionLabel.Left + OptionsRadioGroup.Width;
  155.  
  156.   {HelpBitBtn.Left := Width - QuestionLabel.Left - HelpBitBtn.Width;
  157.   CancelBitBtn.Left := HelpBitBtn.Left - QuestionLabel.Left - CancelBitBtn.Width;
  158.   OKBitBtn.Left := CancelBitBtn.Left - QuestionLabel.Left - CancelBitBtn.Width;}
  159.  
  160.   Left := 10;
  161.   Top := 10;
  162. end;
  163.  
  164. {------------------------------------------------------------------------------
  165.     Procedure: TOptionsForm.DoCaptionsFromResource
  166.   Description: standard loading of labels from resources
  167.        Author: Mat Ballard
  168.  Date created: 06/25/2001
  169. Date modified: 06/25/2001 by Mat Ballard
  170.       Purpose: display in different languages
  171.  Known Issues:
  172.  ------------------------------------------------------------------------------}
  173. {$IFNDEF LANG_ENGLISH}
  174. procedure TOptionsForm.DoCaptionsFromResource;
  175. begin
  176.   Self.Caption := sOptions;
  177.   OptionsRadioGroup.Caption := sPickAnOption;
  178.   HelpBitBtn.Caption := sHelp;
  179.   OKBitBtn.Caption := sOK;
  180.   CancelBitBtn.Caption := sCancel;
  181. end;
  182. {$ENDIF}
  183.  
  184. {------------------------------------------------------------------------------
  185.     Procedure: TOptionsForm.DoHintsFromResource
  186.   Description: standard loading of hints from resources
  187.        Author: Mat Ballard
  188.  Date created: 06/25/2001
  189. Date modified: 06/25/2001 by Mat Ballard
  190.       Purpose: display hints in different languages
  191.  Known Issues:
  192.  ------------------------------------------------------------------------------}
  193. procedure TOptionsForm.DoHintsFromResource;
  194. begin
  195.   OptionsRadioGroup.Hint := sOptionsRadioGroupHint;
  196. end;
  197.  
  198.  
  199. procedure TOptionsForm.FormShow(Sender: TObject);
  200. begin {Form is ALREADY VISIBLE !}
  201.   DoGeometry;
  202.   OptionsRadioGroup.ItemIndex := 0;
  203.   TRadioButton(OptionsRadioGroup.Controls[0]).SetFocus;
  204. end;
  205.  
  206. procedure TOptionsForm.OKBitBtnClick(Sender: TObject);
  207. begin
  208. {note: if ModalResult is 0, then the form DOES NOT CLOSE,
  209.  so selection is 1..n:}
  210.   ModalResult := OptionsRadioGroup.ItemIndex + 1;
  211. end;
  212.  
  213. procedure TOptionsForm.CancelBitBtnClick(Sender: TObject);
  214. begin
  215.   ModalResult := -1;
  216. end;
  217.  
  218. end.
  219.  
  220.