home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 October / Chip_2001-10_cd1.bin / zkuste / delphi / kompon / d123456 / CHEMPLOT.ZIP / TPlot / Ptedit.pas < prev    next >
Pascal/Delphi Source File  |  2001-07-26  |  13KB  |  425 lines

  1. unit Ptedit;
  2.  
  3. {$I Plot.inc}
  4.  
  5. {-----------------------------------------------------------------------------
  6. The contents of this file are subject to the Q Public License
  7. ("QPL"); you may not use this file except in compliance
  8. with the QPL. You may obtain a copy of the QPL from 
  9. the file QPL.html in this distribution, derived from:
  10.  
  11. http://www.trolltech.com/products/download/freelicense/license.html
  12.  
  13. The QPL prohibits development of proprietary software. 
  14. There is a Professional Version of this software available for this. 
  15. Contact sales@chemware.hypermart.net for more information.
  16.  
  17. Software distributed under the QPL is distributed on an "AS IS" basis,
  18. WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the QPL for
  19. the specific language governing rights and limitations under the QPL.
  20.  
  21. The Original Code is: PtEdit.pas, released 12 September 2000.
  22.  
  23. The Initial Developer of the Original Code is Mat Ballard.
  24. Portions created by Mat Ballard are Copyright (C) 1999 Mat Ballard.
  25. Portions created by Microsoft are Copyright (C) 1998, 1999 Microsoft Corp.
  26. All Rights Reserved.
  27.  
  28. Contributor(s): Mat Ballard                 e-mail: mat.ballard@chemware.hypermart.net.
  29.  
  30. Last Modified: 12/06/2000
  31. Current Version: 2.00
  32.  
  33. You may retrieve the latest version of this file from:
  34.  
  35.         http://Chemware.hypermart.net/
  36.  
  37. This work was created with the Project JEDI VCL guidelines:
  38.  
  39.         http://www.delphi-jedi.org/Jedi:VCLVCL
  40.  
  41. in mind.
  42.  
  43. Purpose:
  44. To facilitate user manipluation of Point values.
  45.  
  46. Known Issues: BCB problems with Spinedit - resolved by dynamic creation
  47.               of different controls depending on compiler
  48. -----------------------------------------------------------------------------}
  49.  
  50. interface
  51.  
  52. uses
  53.   Classes, SysUtils,
  54. {$IFDEF WINDOWS}
  55.   WinTypes, WinProcs,
  56.   Buttons, ComCtrls, Controls, Forms, Graphics, StdCtrls,
  57.   Spin,
  58. {$ENDIF}
  59. {$IFDEF WIN32}
  60.   Windows,
  61.   Buttons, ComCtrls, Controls, Forms, Graphics, StdCtrls,
  62.   {$IFDEF DELPHI}
  63.   Spin,
  64.   {$ENDIF}
  65. {$ENDIF}
  66. {$IFDEF LINUX}
  67.   QButtons, QComCtrls, QControls, QForms, QGraphics, QStdCtrls,
  68. {$ENDIF}
  69.  
  70.   Axis, Misc, Nedit, Plotdefs, Slidebar;
  71.  
  72. type
  73.   TPointEditorForm = class(TForm)
  74.     HelpBitBtn: TBitBtn;
  75.     CancelBitBtn: TBitBtn;
  76.     OKBitBtn: TBitBtn;
  77.     DeleteBitBtn: TBitBtn;
  78.     AddBitBtn: TBitBtn;
  79.     DataGroupBox: TGroupBox;
  80.     Label1: TLabel;
  81.     YDataLabel: TLabel;
  82.     ScreenGroupBox: TGroupBox;
  83.     Label3: TLabel;
  84.     YScreenLabel: TLabel;
  85.     DetailsLabel: TLabel;
  86.     XStringDataEdit: TEdit;
  87.     XScreenNEdit: TNEdit;
  88.     YScreenNEdit: TNEdit;
  89.     XDataNEdit: TNEdit;
  90.     YDataNEdit: TNEdit;
  91.     ApplyBitBtn: TBitBtn;
  92.     PointSlideBar: TSlideBar;
  93.     IndexLabel: TLabel;
  94.  
  95.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  96.     procedure FormCreate(Sender: TObject);
  97.     procedure CancelBitBtnClick(Sender: TObject);
  98.     procedure PointSlideBarChange(Sender: TObject);
  99.     procedure ApplyBitBtnClick(Sender: TObject);
  100.     procedure XDataNEditKeyPress(Sender: TObject; var Key: Char);
  101.     procedure XScreenNEditKeyPress(Sender: TObject; var Key: Char);
  102. {$IFDEF MSWINDOWS}
  103.     procedure PointEditChange(Sender: TObject);
  104. {$ENDIF}
  105. {$IFDEF LINUX}
  106.     procedure PointEditChanged(Sender: TObject; NewValue: Integer);
  107. {$ENDIF}
  108.   private
  109.     XData, YData: pSingleArray;
  110.     XStringData: TStringList;
  111.     XAxis, YAxis: TAxis;
  112.     SpinLock: Boolean;
  113.  
  114.   public
  115. {$IFDEF BCB}
  116.     PointNEdit: TNEdit;
  117.     PointUpDown: TUpDown;
  118. {$ELSE}
  119.     PointSpinEdit: TSpinEdit;
  120. {$ENDIF}
  121.     TheSeries: TObject;
  122.  
  123.     procedure Init(
  124.       FXData, FYData: pSingleArray;
  125.       FXStringData: TStringList;
  126.       FXAxis, FYAxisCurrent: TAxis);
  127.     procedure FillData(ThePoint: Integer);
  128. {$IFNDEF LANG_ENGLISH}
  129.     procedure DoCaptionsFromResource;
  130. {$ENDIF}
  131.     procedure DoHintsFromResource;
  132.   end;
  133.  
  134. var
  135.   PointNEditorForm: TPointEditorForm;
  136.  
  137. implementation
  138.  
  139. {$R *.dfm}
  140.  
  141. uses
  142.   Data;
  143.  
  144. {------------------------------------------------------------------------------
  145.     Procedure: TPointEditorForm.FormCreate
  146.   Description: standard FormCreate procedure
  147.        Author: Mat Ballard
  148.  Date created: 04/25/2000
  149. Date modified: 04/25/2000 by Mat Ballard
  150.       Purpose: sets the position
  151.  Known Issues:
  152.  ------------------------------------------------------------------------------}
  153. procedure TPointEditorForm.FormCreate(Sender: TObject);
  154. var
  155.   i: Integer;
  156. begin
  157. {$IFNDEF LANG_ENGLISH}
  158.   DoCaptionsFromResource;
  159. {$ENDIF}
  160.   DoHintsFromResource;
  161.  
  162. {set combo and edit box widths:}
  163.   for i := 0 to Self.ComponentCount - 1 do
  164.     if (Self.Components[i] is TNEdit) then
  165.       TControl(Self.Components[i]).Width := 88
  166.     else if (Self.Components[i] is TBitBtn) then
  167.       TControl(Self.Components[i]).Width := 97;
  168.  
  169.   SetDialogGeometry(Self, ApplyBitBtn, DetailsLabel.Left);
  170.  
  171.   SpinLock := FALSE;
  172.  
  173. {$IFDEF BCB}
  174.   PointNEdit := TNEdit.Create(Self);
  175.   PointNEdit.Parent := Self;
  176.   PointNEdit.Left := PointSlideBar.Left + PointSlideBar.Width + 1;
  177.   PointNEdit.Top := PointSlideBar.Top;
  178.   PointNEdit.OnChange := PointEditChange;
  179.  
  180.   PointUpDown := TUpDown.Create(Self);
  181.   PointUpDown.Parent := Self;
  182.   PointUpDown.Associate := PointNEdit;
  183.  
  184.   {PointNEdit.Right := ScreenGroupBox.Right - PointUpDown.Width;}
  185.   PointNEdit.Width :=
  186.     ScreenGroupBox.Left + ScreenGroupBox.Width -
  187.     PointUpDown.Width - PointNEdit.Left;
  188.   //PointNEdit.TabOrder := 1;
  189.  
  190. {$ELSE}
  191.   PointSpinEdit := TSpinEdit.Create(Self);
  192.   PointSpinEdit.Parent := Self;
  193.   PointSpinEdit.Left := PointSlideBar.Left + PointSlideBar.Width + 1;
  194.   PointSpinEdit.Top := PointSlideBar.Top;
  195.   {$IFDEF MSWINDOWS}
  196.   PointSpinEdit.OnChange := PointEditChange;
  197.   {$ENDIF}
  198.   {$IFDEF LINUX}
  199.   PointSpinEdit.OnChanged := PointEditChanged;
  200.   {$ENDIF}
  201.   {PointSpinEdit.Right := ScreenGroupBox.Right;}
  202.   PointSpinEdit.Width :=
  203.     ScreenGroupBox.Left + ScreenGroupBox.Width -
  204.     PointSpinEdit.Left;
  205.   //PointSpinEdit.TabOrder := 1;
  206. {$ENDIF}
  207. end;
  208.  
  209. {------------------------------------------------------------------------------
  210.     Procedure: TPointEditorForm.DoCaptionsFromResource
  211.   Description: standard loading of labels from resources
  212.        Author: Mat Ballard
  213.  Date created: 06/25/2001
  214. Date modified: 06/25/2001 by Mat Ballard
  215.       Purpose: display in different languages
  216.  Known Issues:
  217.  ------------------------------------------------------------------------------}
  218. {$IFNDEF LANG_ENGLISH}
  219. procedure TPointEditorForm.DoCaptionsFromResource;
  220. begin
  221.   Self.Caption := sPoint + ' ' + sEditor;
  222.   IndexLabel.Caption := sTheIndexOfThePoint;
  223.   DataGroupBox.Caption := sData;
  224.   ScreenGroupBox.Caption := sScreen;
  225.   AddBitBtn.Caption := '&' + sAdd;
  226.   DeleteBitBtn.Caption := '&' + sDelete;
  227.   HelpBitBtn.Caption := sHelp;
  228.   OKBitBtn.Caption := sOK;
  229.   CancelBitBtn.Caption := sCancel;
  230.   ApplyBitBtn.Caption := sApply;
  231. end;
  232. {$ENDIF}
  233.  
  234. {------------------------------------------------------------------------------
  235.     Procedure: TPointEditorForm.DoHintsFromResource
  236.   Description: standard loading of Hints from resources
  237.        Author: Mat Ballard
  238.  Date created: 06/25/2001
  239. Date modified: 06/25/2001 by Mat Ballard
  240.       Purpose: display in different languages
  241.  Known Issues:
  242.  ------------------------------------------------------------------------------}
  243. procedure TPointEditorForm.DoHintsFromResource;
  244. begin
  245.   ApplyBitBtn.Hint := sApplyHint;
  246.   AddBitBtn.Hint := sAddBitBtnHint;
  247.   DeleteBitBtn.Hint := sDeleteBitBtnHint;
  248. end;
  249.  
  250. {------------------------------------------------------------------------------
  251.     Procedure: TPointEditorForm.Init
  252.   Description: initializes pointers to data and axes
  253.        Author: Mat Ballard
  254.  Date created: 04/25/2000
  255. Date modified: 05/04/2000 by Mat Ballard
  256.       Purpose: user management of data
  257.  Known Issues:
  258.  ------------------------------------------------------------------------------}
  259. procedure TPointEditorForm.Init(
  260.   FXData, FYData: pSingleArray;
  261.   FXStringData: TStringList;
  262.   FXAxis, FYAxisCurrent: TAxis);
  263. begin
  264.   XData := FXData;
  265.   YData := FYData;
  266.   XStringData := FXStringData;
  267.   XAxis := FXAxis;
  268.   YAxis := FYAxisCurrent;
  269. end;
  270.  
  271. {------------------------------------------------------------------------------
  272.     Procedure: TPointEditorForm.FormClose
  273.   Description: standard FormClose procedure
  274.        Author: Mat Ballard
  275.  Date created: 04/25/2000
  276. Date modified: 04/25/2000 by Mat Ballard
  277.       Purpose: checks for valid user input
  278.  Known Issues:
  279.  ------------------------------------------------------------------------------}
  280. procedure TPointEditorForm.FormClose(Sender: TObject;
  281.   var Action: TCloseAction);
  282. var
  283.   Test: Single;
  284. begin
  285. {Check that floating point values are valid:}
  286.   Action := caHide;
  287.   if (DataGroupBox.Enabled = TRUE) then
  288.   begin
  289.     try
  290.       Test := XDataNEdit.AsReal;
  291.       Test := Test + YDataNEdit.AsReal;
  292. {We do the above and below the squelch the warning messages.}
  293.       Tag := Trunc(Test);
  294.     except
  295. {Prevent closure:}
  296.       Action := caNone;
  297.     end;
  298.   end;
  299. end;
  300.  
  301. {------------------------------------------------------------------------------
  302.     Procedure: TPointEditorForm.FillData
  303.   Description: Gets the point data
  304.        Author: Mat Ballard
  305.  Date created: 04/25/2000
  306. Date modified: 04/25/2000 by Mat Ballard
  307.       Purpose: Synchronization of the two controls
  308.  Known Issues:
  309.  ------------------------------------------------------------------------------}
  310. procedure TPointEditorForm.FillData(ThePoint: Integer);
  311. begin
  312.   if ((ThePoint < 0) or (ThePoint > PointSlideBar.Position)) then raise
  313.     ERangeError.CreateFmt(sFillData1,
  314.       [ThePoint, PointSlideBar.Position]);
  315.  
  316.   XDataNEdit.AsReal := XData^[ThePoint];
  317.   YDataNEdit.AsReal := YData^[ThePoint];
  318.  
  319.   XScreenNEdit.AsInteger := XAxis.FofX(XData^[ThePoint]);
  320.   YScreenNEdit.AsInteger := YAxis.FofY(YData^[ThePoint]);
  321.  
  322.   if ((XStringData <> nil) and
  323.       (XStringData.Count > ThePoint)) then
  324.   begin
  325.     XStringDataEdit.Text := XStringData.Strings[ThePoint];
  326.     XStringDataEdit.Visible := TRUE;
  327.   end
  328.   else
  329.     XStringDataEdit.Visible := FALSE;
  330. end;
  331.  
  332. {------------------------------------------------------------------------------
  333.     Procedure: TPointEditorForm.CancelBitBtnClick
  334.   Description: Standard Cancel button event handler
  335.        Author: Mat Ballard
  336.  Date created: 04/25/2000
  337. Date modified: 04/25/2000 by Mat Ballard
  338.       Purpose: Disables the DataGroupBox, and hence prevents checking of edit boxes for validity
  339.  Known Issues:
  340.  ------------------------------------------------------------------------------}
  341. procedure TPointEditorForm.CancelBitBtnClick(Sender: TObject);
  342. begin
  343.   DataGroupBox.Enabled := FALSE;
  344. end;
  345.  
  346. {------------------------------------------------------------------------------
  347.     Procedure: TPointEditorForm.PointSlideBarChange
  348.   Description: Sets the value of PointNEdit
  349.        Author: Mat Ballard
  350.  Date created: 04/25/2000
  351. Date modified: 04/25/2000 by Mat Ballard
  352.       Purpose: Synchronization of the two controls
  353.  Known Issues:
  354.  ------------------------------------------------------------------------------}
  355. procedure TPointEditorForm.PointSlideBarChange(Sender: TObject);
  356. begin
  357.   if (not SpinLock) then
  358.   begin
  359.     SpinLock := TRUE;
  360. {$IFDEF BCB}
  361.     PointNEdit.AsInteger := PointSlideBar.Position;
  362. {$ELSE}
  363.     PointSpinEdit.Value := PointSlideBar.Position;
  364. {$ENDIF}
  365.     FillData(PointSlideBar.Position);
  366.     SpinLock := FALSE;
  367.   end;
  368.   //DataGroupBox.Enabled := TRUE;
  369.   //ScreenGroupBox.Enabled := TRUE;
  370. end;
  371.  
  372. {$IFDEF MSWINDOWS}
  373. procedure TPointEditorForm.PointEditChange(Sender: TObject);
  374. begin
  375.   if (not SpinLock) then
  376.   begin
  377.     SpinLock := TRUE;
  378. {$IFDEF BCB}
  379.     PointSlideBar.Position := PointNEdit.AsInteger;
  380. {$ELSE}
  381.     PointSlideBar.Position := PointSpinEdit.Value;
  382. {$ENDIF}
  383.     FillData(PointSlideBar.Position);
  384.     SpinLock := FALSE;
  385.   end;
  386. end;
  387. {$ENDIF}
  388.  
  389. {$IFDEF LINUX}
  390. procedure TPointEditorForm.PointEditChanged(Sender: TObject; NewValue: Integer);
  391. begin
  392.   if (not SpinLock) then
  393.   begin
  394.     SpinLock := TRUE;
  395. {$IFDEF BCB}
  396.     PointSlideBar.Position := PointNEdit.AsInteger;
  397. {$ELSE}
  398.     PointSlideBar.Position := NewValue;
  399. {$ENDIF}
  400.     FillData(PointSlideBar.Position);
  401.     SpinLock := FALSE;
  402.   end;
  403. end;
  404. {$ENDIF}
  405.  
  406. procedure TPointEditorForm.ApplyBitBtnClick(Sender: TObject);
  407. begin
  408.   TSeries(TheSeries).ApplyPointChange(Self, mrOK);
  409. end;
  410.  
  411. procedure TPointEditorForm.XDataNEditKeyPress(Sender: TObject;
  412.   var Key: Char);
  413. begin
  414.   ScreenGroupBox.Enabled := FALSE;
  415. end;
  416.  
  417. procedure TPointEditorForm.XScreenNEditKeyPress(Sender: TObject;
  418.   var Key: Char);
  419. begin
  420.   DataGroupBox.Enabled := FALSE;
  421. end;
  422.  
  423.  
  424. end.
  425.