1{
2 /***************************************************************************
3                                  Spin.pp
4                                  --------
5
6                   Initial Revision  : Fri Apr 23 1999 10:29am
7			Shane Miller
8			mailing list:lazarus@miraclec.com
9
10 ***************************************************************************/
11
12 *****************************************************************************
13  This file is part of the Lazarus Component Library (LCL)
14
15  See the file COPYING.modifiedLGPL.txt, included in this distribution,
16  for details about the license.
17 *****************************************************************************
18}
19
20unit Spin;
21
22{$mode objfpc}{$H+}
23
24interface
25
26uses
27  Types, Classes, Controls, SysUtils, LCLType, LCLProc, StdCtrls, Math;
28
29type
30  { TCustomFloatSpinEdit }
31
32  TCustomFloatSpinEdit = class(TCustomEdit)
33  private const
34    DefIncrement = 1;
35    DefDecimals = 2;
36    DefMaxValue = 100;
37  private
38    FIncrement: Double;
39    FDecimals: Integer;
40    FMaxValue: Double;
41    FMinValue: Double;
42    FValue: Double;
43    FValueEmpty: Boolean;
44    FUpdatePending: Boolean;
45    FValueChanged: Boolean;
46    function GetValue: Double;
47    procedure UpdateControl;
48    function MaxValueStored: Boolean;
49    function IncrementStored: Boolean;
50  protected
51    class procedure WSRegisterClass; override;
52    function  RealGetText: TCaption; override;
53    procedure RealSetText(const AValue: TCaption); override;
54    procedure TextChanged; override;
55    procedure SetDecimals(ADecimals: Integer); virtual;
56    procedure SetValue(const AValue: Double); virtual;
57    procedure SetMaxValue(const AValue: Double); virtual;
58    procedure SetMinValue(const AValue: Double); virtual;
59    procedure SetValueEmpty(const AValue: Boolean); virtual;
60    procedure SetIncrement(const AIncrement: Double); virtual;
61    procedure InitializeWnd; override;
62    procedure FinalizeWnd; override;
63    procedure Loaded; override;
64    procedure KeyPress(var Key: char); override;
65    class function GetControlClassDefaultSize: TSize; override;
66  public
67    constructor Create(TheOwner: TComponent); override;
68    function GetLimitedValue(const AValue: Double): Double; virtual;
69    function ValueToStr(const AValue: Double): String; virtual;
70    function StrToValue(const S: String): Double; virtual;
71  public
72    property DecimalPlaces: Integer read FDecimals write SetDecimals default DefDecimals;
73    property Increment: Double read FIncrement write SetIncrement stored IncrementStored nodefault;
74    property MinValue: Double read FMinValue write SetMinValue;
75    property MaxValue: Double read FMaxValue write SetMaxValue stored MaxValueStored nodefault;
76    property Value: Double read GetValue write SetValue;
77    property ValueEmpty: Boolean read FValueEmpty write SetValueEmpty default False;
78  end;
79
80  { TFloatSpinEdit }
81
82  TFloatSpinEdit = class(TCustomFloatSpinEdit)
83  public
84    property AutoSelected;
85  published
86    property Align;
87    property Alignment;
88    property Anchors;
89    property AutoSelect;
90    property AutoSize;
91    property BorderSpacing;
92    property Color;
93    property Constraints;
94    property DecimalPlaces;
95    property Enabled;
96    property Font;
97    property Increment;
98    property MaxValue;
99    property MinValue;
100    property OnChange;
101    property OnChangeBounds;
102    property OnClick;
103    property OnEditingDone;
104    property OnEnter;
105    property OnExit;
106    property OnKeyDown;
107    property OnKeyPress;
108    property OnKeyUp;
109    property OnMouseDown;
110    property OnMouseEnter;
111    property OnMouseLeave;
112    property OnMouseMove;
113    property OnMouseUp;
114    property OnMouseWheel;
115    property OnMouseWheelDown;
116    property OnMouseWheelUp;
117    property OnResize;
118    property OnUTF8KeyPress;
119    property ParentColor;
120    property ParentFont;
121    property ParentShowHint;
122    property PopupMenu;
123    property ReadOnly;
124    property ShowHint;
125    property TabStop;
126    property TabOrder;
127    property Value;
128    property Visible;
129  end;
130
131
132  { TCustomSpinEdit }
133
134  TCustomSpinEdit = class(TCustomFloatSpinEdit)
135  private
136    function GetIncrement: integer;
137    function GetMaxValue: integer;
138    function GetMinValue: integer;
139    function GetValue: integer;
140  protected
141    procedure SetMaxValue(const AValue: integer); overload; virtual;
142    procedure SetMinValue(const AValue: integer); overload; virtual;
143    procedure SetIncrement(const AValue: integer); overload; virtual;
144    procedure SetValue(const AValue: integer); overload; virtual;
145  public
146    constructor Create(TheOwner: TComponent); override;
147    function GetLimitedValue(const AValue: Double): Double; override;
148  public
149    property Value: integer read GetValue write SetValue default 0;
150    property MinValue: integer read GetMinValue write SetMinValue default 0;
151    property MaxValue: integer read GetMaxValue write SetMaxValue default 100;
152    property Increment: integer read GetIncrement write SetIncrement default 1;
153  end;
154
155
156  { TSpinEdit }
157
158  TSpinEdit = class(TCustomSpinEdit)
159  public
160    property AutoSelected;
161  published
162    property Align;
163    property Alignment;
164    property Anchors;
165    property AutoSelect;
166    property AutoSize;
167    property BorderSpacing;
168    property Color;
169    property Constraints;
170    property Enabled;
171    property Font;
172    property Increment;
173    property MaxValue;
174    property MinValue;
175    property OnChange;
176    property OnChangeBounds;
177    property OnClick;
178    property OnEditingDone;
179    property OnEnter;
180    property OnExit;
181    Property OnKeyDown;
182    property OnKeyPress;
183    Property OnKeyUp;
184    property OnMouseDown;
185    property OnMouseEnter;
186    property OnMouseLeave;
187    property OnMouseMove;
188    property OnMouseUp;
189    property OnMouseWheel;
190    property OnMouseWheelDown;
191    property OnMouseWheelUp;
192    property OnResize;
193    property OnUTF8KeyPress;
194    property ParentColor;
195    property ParentFont;
196    property ParentShowHint;
197    property PopupMenu;
198    property ReadOnly;
199    property ShowHint;
200    property TabStop;
201    property TabOrder;
202    property Value;
203    property Visible;
204  end;
205
206
207procedure Register;
208
209implementation
210
211uses
212  WSSpin;
213
214procedure Register;
215begin
216  RegisterComponents('Misc', [TSpinEdit, TFloatSpinEdit]);
217end;
218
219{$I spinedit.inc}
220
221end.
222
223