-
Notifications
You must be signed in to change notification settings - Fork 33
/
HGM.Controls.SpinEdit.pas
804 lines (725 loc) · 21.2 KB
/
HGM.Controls.SpinEdit.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
{*******************************************************}
{ }
{ Delphi Visual Component Library }
{ }
{ Copyright(c) 2016 Embarcadero Technologies, Inc. }
{ All rights reserved }
{ }
{*******************************************************}
unit HGM.Controls.SpinEdit;
interface
uses
Winapi.Windows, System.Classes, Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.Controls, Winapi.Messages, System.SysUtils, HGM.Common,
Vcl.Forms, Vcl.Graphics, Vcl.Menus, Vcl.Buttons;
const
InitRepeatPause = 400; { pause before repeat timer (ms) }
RepeatPause = 100; { pause before hint window displays (ms)}
type
TNumGlyphs = Vcl.Buttons.TNumGlyphs;
TTimerSpeedButton = class;
{ TSpinButton }
TSpinButton = class(TWinControl)
private
FUpButton: TTimerSpeedButton;
FDownButton: TTimerSpeedButton;
FFocusedButton: TTimerSpeedButton;
FFocusControl: TWinControl;
FOnUpClick: TNotifyEvent;
FOnDownClick: TNotifyEvent;
FLightButtons: Boolean;
function CreateButton(ADownButton: Boolean): TTimerSpeedButton;
function GetUpGlyph: TBitmap;
function GetDownGlyph: TBitmap;
procedure SetUpGlyph(Value: TBitmap);
procedure SetDownGlyph(Value: TBitmap);
function GetUpNumGlyphs: TNumGlyphs;
function GetDownNumGlyphs: TNumGlyphs;
procedure SetUpNumGlyphs(Value: TNumGlyphs);
procedure SetDownNumGlyphs(Value: TNumGlyphs);
procedure BtnClick(Sender: TObject);
procedure BtnMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure SetFocusBtn(Btn: TTimerSpeedButton);
procedure AdjustSize(var W, H: Integer); reintroduce;
procedure WMSize(var Message: TWMSize); message WM_SIZE;
procedure WMSetFocus(var Message: TWMSetFocus); message WM_SETFOCUS;
procedure WMKillFocus(var Message: TWMKillFocus); message WM_KILLFOCUS;
procedure WMGetDlgCode(var Message: TWMGetDlgCode); message WM_GETDLGCODE;
procedure WMEraseBkgnd(var Message: TWmEraseBkgnd); message WM_ERASEBKGND;
procedure SetLightButtons(const Value: Boolean);
protected
procedure Loaded; override;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
procedure CreateWnd; override;
public
constructor Create(AOwner: TComponent); override;
procedure SetBounds(ALeft, ATop, AWidth, AHeight: Integer); override;
published
property Align;
property Anchors;
property Constraints;
property Ctl3D;
property DownGlyph: TBitmap read GetDownGlyph write SetDownGlyph;
property DownNumGlyphs: TNumGlyphs read GetDownNumGlyphs write SetDownNumGlyphs default 1;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property FocusControl: TWinControl read FFocusControl write FFocusControl;
property ParentCtl3D;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property TabOrder;
property TabStop;
property UpGlyph: TBitmap read GetUpGlyph write SetUpGlyph;
property UpNumGlyphs: TNumGlyphs read GetUpNumGlyphs write SetUpNumGlyphs default 1;
property StyleElements;
property Visible;
property OnDownClick: TNotifyEvent read FOnDownClick write FOnDownClick;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnStartDock;
property OnStartDrag;
property OnUpClick: TNotifyEvent read FOnUpClick write FOnUpClick;
property LightButtons: Boolean read FLightButtons write SetLightButtons;
end;
{ TSpinEdit }
TlkSpinEdit = class(TCustomEdit)
private
FMinValue: LongInt;
FMaxValue: LongInt;
FIncrement: LongInt;
FButton: TSpinButton;
FEditorEnabled: Boolean;
FOnChange: TNotifyEvent;
FLightButtons: Boolean;
//function GetMinHeight: Integer;
function GetValue: LongInt;
function CheckValue(NewValue: LongInt): LongInt;
procedure SetValue(NewValue: LongInt);
procedure SetEditRect;
procedure WMSize(var Message: TWMSize); message WM_SIZE;
procedure CMEnter(var Message: TCMGotFocus); message CM_ENTER;
procedure CMExit(var Message: TCMExit); message CM_EXIT;
procedure WMPaste(var Message: TWMPaste); message WM_PASTE;
procedure WMMouseWheel(var Message: TWMMouseWheel); message WM_MOUSEWHEEL;
procedure WMCut(var Message: TWMCut); message WM_CUT;
procedure WMGetDlgCode(var Message: TWMGetDlgCode); message WM_GETDLGCODE;
procedure WMChange(var message: TWMKeyUp); message WM_KEYUP;
procedure DoChange;
procedure SetLightButtons(const Value: Boolean);
protected
function IsValidChar(Key: Char): Boolean; virtual;
procedure UpClick(Sender: TObject); virtual;
procedure DownClick(Sender: TObject); virtual;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure KeyPress(var Key: Char); override;
procedure CreateParams(var Params: TCreateParams); override;
procedure CreateWnd; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
property Button: TSpinButton read FButton;
published
property Align;
property Anchors;
property AutoSelect;
property AutoSize;
property BorderStyle;
property BevelEdges;
property BevelInner;
property BevelKind default bkNone;
property BevelOuter;
property BevelWidth;
property Color;
property Constraints;
property Ctl3D;
property DragCursor;
property DragMode;
property EditorEnabled: Boolean read FEditorEnabled write FEditorEnabled default True;
property Enabled;
property Font;
property Increment: LongInt read FIncrement write FIncrement default 1;
property MaxLength;
property MaxValue: LongInt read FMaxValue write FMaxValue;
property MinValue: LongInt read FMinValue write FMinValue;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ReadOnly;
property ShowHint;
property TabOrder;
property TabStop;
property Value: LongInt read GetValue write SetValue;
property Visible;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnStartDrag;
property LightButtons: Boolean read FLightButtons write SetLightButtons;
property StyleElements;
end;
{ TTimerSpeedButton }
TTimeBtnState = set of (tbFocusRect, tbAllowTimer);
TTimerSpeedButton = class(TSpeedButton)
private
FRepeatTimer: TTimer;
FTimeBtnState: TTimeBtnState;
FDownButton: Boolean;
procedure TimerExpired(Sender: TObject);
protected
procedure Paint; override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
public
destructor Destroy; override;
property TimeBtnState: TTimeBtnState read FTimeBtnState write FTimeBtnState;
end;
procedure Register;
implementation
{$R hSpin.res}
uses
Vcl.Themes, Vcl.GraphUtil;
procedure Register;
begin
RegisterComponents(PackageName, [TlkSpinEdit]);
end;
{ TSpinButton }
constructor TSpinButton.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := ControlStyle - [csAcceptsControls, csSetCaption] + [csFramed, csOpaque];
{ Frames don't look good around the buttons when themes are on }
if StyleServices.Enabled then
ControlStyle := ControlStyle - [csFramed];
FUpButton := CreateButton(False);
FDownButton := CreateButton(True);
FUpButton.Flat := True;
FDownButton.Flat := True;
UpGlyph := nil;
DownGlyph := nil;
Width := 20;
Height := 25;
FFocusedButton := FUpButton;
end;
function TSpinButton.CreateButton(ADownButton: Boolean): TTimerSpeedButton;
begin
Result := TTimerSpeedButton.Create(Self);
Result.OnClick := BtnClick;
Result.OnMouseDown := BtnMouseDown;
Result.Visible := True;
Result.Enabled := True;
Result.TimeBtnState := [tbAllowTimer];
Result.FDownButton := ADownButton;
Result.Parent := Self;
end;
procedure TSpinButton.CreateWnd;
begin
inherited;
DoubleBuffered := StyleServices.Enabled;
end;
procedure TSpinButton.Notification(AComponent: TComponent; Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (Operation = opRemove) and (AComponent = FFocusControl) then
FFocusControl := nil;
end;
procedure TSpinButton.AdjustSize(var W, H: Integer);
begin
if (FUpButton = nil) or (csLoading in ComponentState) then
Exit;
if W < 15 then
W := 15;
FUpButton.SetBounds(0, 0, W, H div 2 + 2);
FDownButton.SetBounds(0, FUpButton.Height - 2, W, H - (H div 2) + 1);
end;
procedure TSpinButton.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
var
W, H: Integer;
begin
W := AWidth;
H := AHeight;
AdjustSize(W, H);
inherited SetBounds(ALeft, ATop, W, H);
end;
procedure TSpinButton.WMEraseBkgnd(var Message: TWMEraseBkgnd);
var
Canvas: TCanvas;
begin
if TStyleManager.IsCustomStyleActive then
begin
Canvas := TCanvas.Create;
Canvas.Handle := Message.DC;
try
Canvas.Brush.Color := StyleServices.GetSystemColor(clBtnFace);
Canvas.FillRect(ClientRect);
finally
Canvas.Handle := 0;
Canvas.Free;
end;
Message.Result := 1;
end
else
inherited;
end;
procedure TSpinButton.WMSize(var Message: TWMSize);
var
W, H: Integer;
begin
inherited;
{ check for minimum size }
W := Width;
H := Height;
AdjustSize(W, H);
if (W <> Width) or (H <> Height) then
inherited SetBounds(Left, Top, W, H);
Message.Result := 0;
end;
procedure TSpinButton.WMSetFocus(var Message: TWMSetFocus);
begin
FFocusedButton.TimeBtnState := FFocusedButton.TimeBtnState + [tbFocusRect];
FFocusedButton.Invalidate;
end;
procedure TSpinButton.WMKillFocus(var Message: TWMKillFocus);
begin
FFocusedButton.TimeBtnState := FFocusedButton.TimeBtnState - [tbFocusRect];
FFocusedButton.Invalidate;
end;
procedure TSpinButton.KeyDown(var Key: Word; Shift: TShiftState);
begin
case Key of
VK_UP:
begin
SetFocusBtn(FUpButton);
FUpButton.Click;
end;
VK_DOWN:
begin
SetFocusBtn(FDownButton);
FDownButton.Click;
end;
VK_SPACE:
FFocusedButton.Click;
end;
end;
procedure TSpinButton.BtnMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if Button = mbLeft then
begin
SetFocusBtn(TTimerSpeedButton(Sender));
if (FFocusControl <> nil) and FFocusControl.TabStop and FFocusControl.CanFocus and (GetFocus <> FFocusControl.Handle) then
FFocusControl.SetFocus
else if TabStop and (GetFocus <> Handle) and CanFocus then
SetFocus;
end;
end;
procedure TSpinButton.BtnClick(Sender: TObject);
begin
if Sender = FUpButton then
begin
if Assigned(FOnUpClick) then
FOnUpClick(Self);
end
else if Assigned(FOnDownClick) then
FOnDownClick(Self);
end;
procedure TSpinButton.SetFocusBtn(Btn: TTimerSpeedButton);
begin
if TabStop and CanFocus and (Btn <> FFocusedButton) then
begin
FFocusedButton.TimeBtnState := FFocusedButton.TimeBtnState - [tbFocusRect];
FFocusedButton := Btn;
if (GetFocus = Handle) then
begin
FFocusedButton.TimeBtnState := FFocusedButton.TimeBtnState + [tbFocusRect];
Invalidate;
end;
end;
end;
procedure TSpinButton.WMGetDlgCode(var Message: TWMGetDlgCode);
begin
Message.Result := DLGC_WANTARROWS;
end;
procedure TSpinButton.Loaded;
var
W, H: Integer;
begin
inherited Loaded;
W := Width;
H := Height;
AdjustSize(W, H);
if (W <> Width) or (H <> Height) then
inherited SetBounds(Left, Top, W, H);
end;
function TSpinButton.GetUpGlyph: TBitmap;
begin
Result := FUpButton.Glyph;
end;
procedure TSpinButton.SetUpGlyph(Value: TBitmap);
begin
if Value <> nil then
FUpButton.Glyph := Value
else
begin
if LightButtons then
FUpButton.Glyph.Handle := LoadBitmap(HInstance, 'lkSpinUpLight')
else
FUpButton.Glyph.Handle := LoadBitmap(HInstance, 'lkSpinUp');
FUpButton.NumGlyphs := 1;
FUpButton.Invalidate;
end;
end;
function TSpinButton.GetUpNumGlyphs: TNumGlyphs;
begin
Result := FUpButton.NumGlyphs;
end;
procedure TSpinButton.SetUpNumGlyphs(Value: TNumGlyphs);
begin
FUpButton.NumGlyphs := Value;
end;
function TSpinButton.GetDownGlyph: TBitmap;
begin
Result := FDownButton.Glyph;
end;
procedure TSpinButton.SetLightButtons(const Value: Boolean);
begin
FLightButtons := Value;
SetUpGlyph(nil);
SetDownGlyph(nil);
end;
procedure TSpinButton.SetDownGlyph(Value: TBitmap);
begin
if Value <> nil then
FDownButton.Glyph := Value
else
begin
if LightButtons then
FDownButton.Glyph.Handle := LoadBitmap(HInstance, 'lkSpinDownLight')
else
FDownButton.Glyph.Handle := LoadBitmap(HInstance, 'lkSpinDown');
FDownButton.NumGlyphs := 1;
FDownButton.Invalidate;
end;
end;
function TSpinButton.GetDownNumGlyphs: TNumGlyphs;
begin
Result := FDownButton.NumGlyphs;
end;
procedure TSpinButton.SetDownNumGlyphs(Value: TNumGlyphs);
begin
FDownButton.NumGlyphs := Value;
end;
{ TSpinEdit }
constructor TlkSpinEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FButton := TSpinButton.Create(Self);
FButton.Width := 15;
FButton.Height := 17;
FButton.Visible := True;
FButton.Parent := Self;
FButton.FocusControl := Self;
FButton.OnUpClick := UpClick;
FButton.OnDownClick := DownClick;
FButton.LightButtons := False;
Text := '0';
ControlStyle := ControlStyle - [csSetCaption];
FIncrement := 1;
FEditorEnabled := True;
ParentBackground := False;
end;
destructor TlkSpinEdit.Destroy;
begin
FButton := nil;
inherited Destroy;
end;
procedure TlkSpinEdit.GetChildren(Proc: TGetChildProc; Root: TComponent);
begin
end;
procedure TlkSpinEdit.KeyDown(var Key: Word; Shift: TShiftState);
begin
if Key = VK_UP then
UpClick(Self)
else if Key = VK_DOWN then
DownClick(Self);
inherited KeyDown(Key, Shift);
end;
procedure TlkSpinEdit.KeyPress(var Key: Char);
begin
if not IsValidChar(Key) then
begin
Key := #0;
MessageBeep(0)
end;
if Key <> #0 then
inherited KeyPress(Key);
end;
function TlkSpinEdit.IsValidChar(Key: Char): Boolean;
begin
Result := (CharInSet(Key, [FormatSettings.DecimalSeparator, '+', '-', '0'..'9'])) or ((Key < #32) and (Key <> Chr(VK_RETURN)));
if not FEditorEnabled and Result and ((Key >= #32) or (Key = Char(VK_BACK)) or (Key = Char(VK_DELETE))) then
Result := False;
end;
procedure TlkSpinEdit.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
{ Params.Style := Params.Style and not WS_BORDER; }
Params.Style := Params.Style or ES_MULTILINE or WS_CLIPCHILDREN;
end;
procedure TlkSpinEdit.CreateWnd;
begin
inherited CreateWnd;
SetEditRect;
end;
procedure TlkSpinEdit.SetLightButtons(const Value: Boolean);
begin
FLightButtons := Value;
FButton.LightButtons := FLightButtons;
if not (csLoading in ComponentState) then
Repaint;
end;
procedure TlkSpinEdit.SetEditRect;
var
Loc: TRect;
begin
SendMessage(Handle, EM_GETRECT, 0, IntPtr(@Loc));
Loc.Bottom := ClientHeight + 1; {+1 is workaround for windows paint bug}
Loc.Right := ClientWidth - FButton.Width - 0;
Loc.Top := 1;
Loc.Left := 3;
SendMessage(Handle, EM_SETRECTNP, 0, IntPtr(@Loc));
SendMessage(Handle, EM_GETRECT, 0, IntPtr(@Loc)); {debug}
end;
procedure TlkSpinEdit.WMSize(var Message: TWMSize);
var
MinHeight: Integer;
begin
inherited;
MinHeight := 0; //GetMinHeight;
{ text edit bug: if size to less than minheight, then edit ctrl does
not display the text }
if Height < MinHeight then
Height := MinHeight
else if FButton <> nil then
begin
if NewStyleControls and Ctl3D then
FButton.SetBounds(Width - FButton.Width - 2, 0, FButton.Width, Height - 2)
else
FButton.SetBounds(Width - FButton.Width - 1, 1, FButton.Width, Height - 3);
SetEditRect;
end;
end;
{
function TlkSpinEdit.GetMinHeight: Integer;
var
DC: HDC;
SaveFont: HFont;
I: Integer;
SysMetrics, Metrics: TTextMetric;
begin
DC := GetDC(0);
GetTextMetrics(DC, SysMetrics);
SaveFont := SelectObject(DC, Font.Handle);
GetTextMetrics(DC, Metrics);
SelectObject(DC, SaveFont);
ReleaseDC(0, DC);
I := SysMetrics.tmHeight;
if I > Metrics.tmHeight then I := Metrics.tmHeight;
Result := Metrics.tmHeight + I div 4 + GetSystemMetrics(SM_CYBORDER) * 4 + 2;
end; }
procedure TlkSpinEdit.UpClick(Sender: TObject);
begin
if ReadOnly then
MessageBeep(0)
else
begin
Value := Value + FIncrement;
DoChange;
end;
end;
procedure TlkSpinEdit.DoChange;
begin
if Assigned(FOnChange) then
FOnChange(Self);
end;
procedure TlkSpinEdit.DownClick(Sender: TObject);
begin
if ReadOnly then
MessageBeep(0)
else
begin
Value := Value - FIncrement;
DoChange;
end;
end;
procedure TlkSpinEdit.WMPaste(var Message: TWMPaste);
begin
if not FEditorEnabled or ReadOnly then
Exit;
inherited;
end;
procedure TlkSpinEdit.WMChange(var message: TWMKeyUp);
begin
inherited;
DoChange;
end;
procedure TlkSpinEdit.WMCut(var Message: TWMPaste);
begin
if not FEditorEnabled or ReadOnly then
Exit;
inherited;
end;
procedure TlkSpinEdit.WMGetDlgCode(var Message: TWMGetDlgCode);
begin
inherited;
Message.Result := Message.Result and not DLGC_WANTALLKEYS;
end;
procedure TlkSpinEdit.WMMouseWheel(var Message: TWMMouseWheel);
begin
if Message.WheelDelta > 0 then
UpClick(Self)
else
DownClick(Self);
end;
procedure TlkSpinEdit.CMExit(var Message: TCMExit);
begin
inherited;
if CheckValue(Value) <> Value then
begin
SetValue(Value);
DoChange;
end;
end;
function TlkSpinEdit.GetValue: LongInt;
begin
Result := StrToIntDef(Text, FMinValue);
end;
procedure TlkSpinEdit.SetValue(NewValue: LongInt);
begin
Text := IntToStr(CheckValue(NewValue));
end;
function TlkSpinEdit.CheckValue(NewValue: LongInt): LongInt;
begin
Result := NewValue;
if (FMaxValue <> FMinValue) then
begin
if NewValue < FMinValue then
Result := FMinValue
else if NewValue > FMaxValue then
Result := FMaxValue;
end;
end;
procedure TlkSpinEdit.CMEnter(var Message: TCMGotFocus);
begin
if AutoSelect and not (csLButtonDown in ControlState) then
SelectAll;
inherited;
end;
{TTimerSpeedButton}
destructor TTimerSpeedButton.Destroy;
begin
if FRepeatTimer <> nil then
FRepeatTimer.Free;
inherited Destroy;
end;
procedure TTimerSpeedButton.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
inherited MouseDown(Button, Shift, X, Y);
if tbAllowTimer in FTimeBtnState then
begin
if FRepeatTimer = nil then
FRepeatTimer := TTimer.Create(Self);
FRepeatTimer.OnTimer := TimerExpired;
FRepeatTimer.Interval := InitRepeatPause;
FRepeatTimer.Enabled := True;
end;
end;
procedure TTimerSpeedButton.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
inherited MouseUp(Button, Shift, X, Y);
if FRepeatTimer <> nil then
FRepeatTimer.Enabled := False;
end;
procedure TTimerSpeedButton.TimerExpired(Sender: TObject);
begin
FRepeatTimer.Interval := RepeatPause;
if (FState = bsDown) and MouseCapture then
begin
try
Click;
except
FRepeatTimer.Enabled := False;
raise;
end;
end;
end;
procedure TTimerSpeedButton.Paint;
var
R: TRect;
Details: TThemedElementDetails;
ArrowColor: TColor;
P: TPoint;
SaveIndex: Integer;
begin
if TStyleManager.IsCustomStyleActive and (Parent <> nil) and (Parent is TSpinButton) and (seClient in Parent.StyleElements) then
begin
if not Enabled then
Details := StyleServices.GetElementDetails(ttbButtonDisabled)
else if FState in [bsDown, bsExclusive] then
Details := StyleServices.GetElementDetails(ttbButtonPressed)
else if MouseInControl then
Details := StyleServices.GetElementDetails(ttbButtonHot)
else
Details := StyleServices.GetElementDetails(ttbButtonNormal);
R := Bounds(0, 0, Width, Height);
SaveIndex := SaveDC(Canvas.Handle);
try
if Transparent then
StyleServices.DrawParentBackground(0, Canvas.Handle, nil, True)
else
PerformEraseBackground(Self, Canvas.Handle);
StyleServices.DrawElement(Canvas.Handle, Details, R);
finally
RestoreDC(Canvas.Handle, SaveIndex);
end;
if not StyleServices.GetElementColor(Details, ecTextColor, ArrowColor) then
ArrowColor := StyleServices.GetSystemColor(clBtnText);
Canvas.Pen.Color := ArrowColor;
P.X := R.CenterPoint.X - 3;
P.Y := R.CenterPoint.Y - 2;
if FDownButton then
DrawArrow(Canvas, sdDown, P, 3)
else
DrawArrow(Canvas, sdUp, P, 3);
end
else
inherited Paint;
if tbFocusRect in FTimeBtnState then
begin
R := Bounds(0, 0, Width, Height);
InflateRect(R, -3, -3);
if FState = bsDown then
OffsetRect(R, 1, 1);
DrawFocusRect(Canvas.Handle, R);
end;
end;
end.