-
Notifications
You must be signed in to change notification settings - Fork 1
/
TFlatScrollbarUnit.pas
1094 lines (968 loc) · 31.2 KB
/
TFlatScrollbarUnit.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
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit TFlatScrollbarUnit;
{******************************************************************************}
{ }
{ FlatStyle Scrollbar Unit }
{ }
{ Copyright ©2000 Lloyd Kinsella. }
{ }
{ FlatStyle is Copyright ©1998-2000 Maik Porkert. }
{ }
{ Notes: }
{ I spent about a week working on this code, as up until now FlatStyle did }
{ not have any kind of flat Encarta like scrollbar. }
{ }
{ There are "missing" features, notably if you click on the track the thumb }
{ does not auto scroll to where you clicked. Also clicking on the scroll }
{ buttons forces the thumb to be often too responsive. }
{ GetScrollInfo and SetScrollInfo Win32 API's do not work for some reason, }
{ hope to fix this soon. }
{ }
{ If you have any ideas of improvement or extra functionality then either }
{ send me the idea in an e-mail or modify a copy of this code and send it to }
{ me. I cannot promise to implement your idea but I will look into it and }
{ discuss its merits with Maik and other FlatStyle developers. }
{ }
{ I would ask that you please do not release your own FlatStyle/Encarta }
{ style scrollbars, I worked hard on this for your benefit as well as my own. }
{ }
{ If you have any ideas, code or information on the following topics, }
{ then please send it to me, it will be invaluable: }
{ }
{ Custom Scrollbars in a TScrollbox (Or similar) }
{ Custom Scrollbars in a TMemo, TRichEdit, TListBox etc... }
{ }
{ This is because the current TFlatMemo and friends use the standard }
{ Windows scrollbars and I would love to hook the TFlatScrollbar up to them! }
{ Try out hooking the scrollbars up to TMemos etc, then send us the code, }
{ but I request it MUST be compatible with Delphi 3 and in original code and }
{ not pre-compiled form (i.e DCU). }
{ }
{ E-Mail: lloydk@iname.com }
{ Web: http://www.flatstyle.de/ }
{ }
{******************************************************************************}
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, TFlatButtonUnit, FlatGraphics;
{ TFlatScrollbarThumb }
type
TFlatScrollbarThumb = class(TFlatButton)
private
FDown: Boolean;
FOldX, FOldY: Integer;
FTopLimit: Integer;
FBottomLimit: Integer;
protected
constructor Create(AOwner: TComponent); override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
public
property Color;
end;
{ TFlatScrollbarTrack }
type
TFlatScrollbarTrack = class (TCustomControl)
private
FThumb: TFlatScrollbarThumb;
FKind: TScrollBarKind;
FSmallChange: Integer;
FLargeChange: Integer;
FMin: Integer;
FMax: Integer;
FPosition: Integer;
procedure SetSmallChange(Value: Integer);
procedure SetLargeChange(Value: Integer);
procedure SetMin(Value: Integer);
procedure SetMax(Value: Integer);
procedure SetPosition(Value: Integer);
procedure SetKind(Value: TScrollBarKind);
procedure WMSize(var Message: TMessage); message WM_SIZE;
function ThumbFromPosition: Integer;
function PositionFromThumb: Integer;
procedure DoPositionChange;
procedure DoThumbHighlightColor(Value: TColor);
procedure DoThumbShadowColor(Value: TColor);
procedure DoThumbBorderColor(Value: TColor);
procedure DoThumbFocusedColor(Value: TColor);
procedure DoThumbDownColor(Value: TColor);
procedure DoThumbColor(Value: TColor);
procedure DoHScroll(var Message: TWMScroll);
procedure DoVScroll(var Message: TWMScroll);
procedure DoEnableArrows(var Message: TMessage);
procedure DoGetPos(var Message: TMessage);
procedure DoGetRange(var Message: TMessage);
procedure DoSetPos(var Message: TMessage);
procedure DoSetRange(var Message: TMessage);
procedure DoKeyDown(var Message: TWMKeyDown);
protected
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Paint; override;
published
property Align;
property Color;
property ParentColor;
property Min: Integer read FMin write SetMin;
property Max: Integer read FMax write SetMax;
property SmallChange: Integer read FSmallChange write SetSmallChange;
property LargeChange: Integer read FLargeChange write SetLargeChange;
property Position: Integer read FPosition write SetPosition;
property Kind: TScrollBarKind read FKind write SetKind;
end;
{ TFlatScrollbarButton }
type
TFlatScrollbarButton = class (TFlatButton)
private
FNewDown: Boolean;
FTimer: TTimer;
FOnDown: TNotifyEvent;
procedure DoTimer(Sender: TObject);
protected
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
published
property Align;
property OnDown: TNotifyEvent read FOnDown write FOnDown;
end;
{ TFlatScrollbar }
type
TFlatOnScroll = procedure (Sender: TObject; ScrollPos: Integer) of object;
type
TFlatScrollbar = class(TCustomControl)
private
FTrack: TFlatScrollbarTrack;
FBtnOne: TFlatScrollbarButton;
FBtnTwo: TFlatScrollbarButton;
FMin: Integer;
FMax: Integer;
FSmallChange: Integer;
FLargeChange: Integer;
FPosition: Integer;
FKind: TScrollBarKind;
FButtonHighlightColor: TColor;
FButtonShadowColor: TColor;
FButtonBorderColor: TColor;
FButtonFocusedColor: TColor;
FButtonDownColor: TColor;
FButtonColor: TColor;
FThumbHighlightColor: TColor;
FThumbShadowColor: TColor;
FThumbBorderColor: TColor;
FThumbFocusedColor: TColor;
FThumbDownColor: TColor;
FThumbColor: TColor;
FOnScroll: TFlatOnScroll;
procedure SetSmallChange(Value: Integer);
procedure SetLargeChange(Value: Integer);
procedure SetMin(Value: Integer);
procedure SetMax(Value: Integer);
procedure SetPosition(Value: Integer);
procedure SetKind(Value: TScrollBarKind);
procedure SetButtonHighlightColor(Value: TColor);
procedure SetButtonShadowColor(Value: TColor);
procedure SetButtonBorderColor(Value: TColor);
procedure SetButtonFocusedColor(Value: TColor);
procedure SetButtonDownColor(Value: TColor);
procedure SetButtonColor(Value: TColor);
procedure SetThumbHighlightColor(Value: TColor);
procedure SetThumbShadowColor(Value: TColor);
procedure SetThumbBorderColor(Value: TColor);
procedure SetThumbFocusedColor(Value: TColor);
procedure SetThumbDownColor(Value: TColor);
procedure SetThumbColor(Value: TColor);
procedure BtnOneClick(Sender: TObject);
procedure BtnTwoClick(Sender: TObject);
procedure EnableBtnOne(Value: Boolean);
procedure EnableBtnTwo(Value: Boolean);
procedure DoScroll;
procedure WMSize(var Message: TWMSize); message WM_SIZE;
procedure CNHScroll(var Message: TWMScroll); message WM_HSCROLL;
procedure CNVScroll(var Message: TWMScroll); message WM_VSCROLL;
procedure SBMEnableArrows(var Message: TMessage); message SBM_ENABLE_ARROWS;
procedure SBMGetPos(var Message: TMessage); message SBM_GETPOS;
procedure SBMGetRange(var Message: TMessage); message SBM_GETRANGE;
procedure SBMSetPos(var Message: TMessage); message SBM_SETPOS;
procedure SBMSetRange(var Message: TMessage); message SBM_SETRANGE;
procedure WMKeyDown(var Message: TWMKeyDown); message WM_KEYDOWN;
protected
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
public
published
property Min: Integer read FMin write SetMin default 0;
property Max: Integer read FMax write SetMax default 100;
property SmallChange: Integer read FSmallChange write SetSmallChange default 1;
property LargeChange: Integer read FLargeChange write SetLargeChange default 1;
property Position: Integer read FPosition write SetPosition default 0;
property Kind: TScrollBarKind read FKind write SetKind default sbVertical;
property OnScroll: TFlatOnScroll read FOnScroll write FOnScroll;
property ButtonHighlightColor: TColor read FButtonHighlightColor write SetButtonHighlightColor;
property ButtonShadowColor: TColor read FButtonShadowColor write SetButtonShadowColor;
property ButtonBorderColor: TColor read FButtonBorderColor write SetButtonBorderColor;
property ButtonFocusedColor: TColor read FButtonFocusedColor write SetButtonFocusedColor;
property ButtonDownColor: TColor read FButtonDownColor write SetButtonDownColor;
property ButtonColor: TColor read FButtonColor write SetButtonColor;
property ThumbHighlightColor: TColor read FThumbHighlightColor write SetThumbHighlightColor;
property ThumbShadowColor: TColor read FThumbShadowColor write SetThumbShadowColor;
property ThumbBorderColor: TColor read FThumbBorderColor write SetThumbBorderColor;
property ThumbFocusedColor: TColor read FThumbFocusedColor write SetThumbFocusedColor;
property ThumbDownColor: TColor read FThumbDownColor write SetThumbDownColor;
property ThumbColor: TColor read FThumbColor write SetThumbColor;
property Align;
property Color;
property ParentColor;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyUp;
property OnStartDrag;
end;
procedure Register;
implementation
{$R TFlatScrollbarUnit.RES}
{ TFlatScrollbarTrackThumb }
constructor TFlatScrollbarThumb.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
end;
procedure TFlatScrollbarThumb.MouseMove(Shift: TShiftState; X, Y: Integer);
var
iTop: Integer;
begin
if TFlatScrollbarTrack(Parent).Kind = sbVertical then
begin
FTopLimit := 0;
FBottomLimit := TFlatScrollbarTrack(Parent).Height;
if FDown = True then
begin
iTop := Top + Y - FOldY;
if iTop < FTopLimit then
begin
iTop := FTopLimit;
end;
if (iTop > FBottomLimit) or ((iTop + Height) > FBottomLimit) then
begin
iTop := FBottomLimit - Height;
end;
Top := iTop;
end;
end
else
begin
FTopLimit := 0;
FBottomLimit := TFlatScrollbarTrack(Parent).Width;
if FDown = True then
begin
iTop := Left + X - FOldX;
if iTop < FTopLimit then
begin
iTop := FTopLimit;
end;
if (iTop > FBottomLimit) or ((iTop + Width) > FBottomLimit) then
begin
iTop := FBottomLimit - Width;
end;
Left := iTop;
end;
end;
TFlatScrollbarTrack(Parent).FPosition := TFlatScrollbarTrack(Parent).PositionFromThumb;
TFlatScrollbarTrack(Parent).DoPositionChange;
inherited MouseMove(Shift,X,Y);
end;
procedure TFlatScrollbarThumb.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
FDown := False;
inherited MouseUp(Button,Shift,X,Y);
end;
procedure TFlatScrollbarThumb.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if (Button = mbleft) and not FDown then FDown := True;
FOldX := X;
FOldy := Y;
inherited MouseDown(Button,Shift,X,Y);
end;
{ TFlatScrollbarTrack }
constructor TFlatScrollbarTrack.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Color := ecLightKaki;
FThumb := TFlatScrollbarThumb.Create(Self);
FThumb.Color := ecLightBrown;
FThumb.ColorFocused := ecLightBrown;
FThumb.ColorDown := ecLightBrown;
FThumb.ColorBorder := ecLightBrown;
FThumb.ColorHighLight := ecLightBrown;
FThumb.ColorShadow := ecLightBrown;
FThumb.Height := 17;
InsertControl(FThumb);
FMin := 0;
FMax := 100;
FSmallChange := 1;
FLargeChange := 1;
FPosition := 0;
FThumb.Top := ThumbFromPosition;
end;
destructor TFlatScrollbarTrack.Destroy;
begin
FThumb.Free;
inherited Destroy;
end;
procedure TFlatScrollbarTrack.Paint;
begin
with Canvas do
begin
Brush.Color := Color;
FillRect(ClientRect);
end;
end;
procedure TFlatScrollbarTrack.SetSmallChange(Value: Integer);
begin
if Value <> FSmallChange then
begin
FSmallChange := Value;
end;
end;
procedure TFlatScrollbarTrack.SetLargeChange(Value: Integer);
begin
if Value <> FLargeChange then
begin
FLargeChange := Value;
end;
end;
procedure TFlatScrollbarTrack.SetMin(Value: Integer);
begin
if Value <> FMin then
begin
FMin := Value;
FThumb.Top := ThumbFromPosition;
end;
end;
procedure TFlatScrollbarTrack.SetMax(Value: Integer);
begin
if Value <> FMax then
begin
FMax := Value;
FThumb.Top := ThumbFromPosition;
end;
end;
procedure TFlatScrollbarTrack.SetPosition(Value: Integer);
begin
FPosition := Value;
if Position > Max then
begin
Position := Max;
end;
if Position < Min then
begin
Position := Min;
end;
case FKind of
sbVertical: FThumb.Top := ThumbFromPosition;
sbHorizontal: FThumb.Left := ThumbFromPosition;
end;
end;
procedure TFlatScrollbarTrack.SetKind(Value: TScrollBarKind);
begin
if Value <> FKind then
begin
FKind:= Value;
case FKind of
sbVertical: FThumb.Height := 17;
sbHorizontal: FThumb.Width := 17;
end;
end;
Position := FPosition;
end;
procedure TFlatScrollbarTrack.WMSize(var Message: TMessage);
begin
if FKind = sbVertical then
begin
FThumb.Width := Width;
end
else
begin
FThumb.Height := Height;
end;
end;
function TFlatScrollbarTrack.ThumbFromPosition: Integer;
var
iHW, iMin, iMax, iPosition, iResult: Integer;
begin
iHW := 0;
case FKind of
sbVertical: iHW := Height - FThumb.Height;
sbHorizontal: iHW := Width - FThumb.Width;
end;
iMin := FMin;
iMax := FMax;
iPosition := FPosition;
iResult := Round((iHW / (iMax - iMin)) * iPosition);
Result := iResult;
end;
function TFlatScrollbarTrack.PositionFromThumb: Integer;
var
iHW, iMin, iMax, iPosition, iResult: Integer;
begin
iHW := 0;
case FKind of
sbVertical: iHW := Height - FThumb.Height;
sbHorizontal: iHW := Width - FThumb.Width;
end;
iMin := FMin;
iMax := FMax;
iPosition := 0;
case FKind of
sbVertical: iPosition := FThumb.Top;
sbHorizontal: iPosition := FThumb.Left;
end;
iResult := Round(iPosition / iHW * (iMax - iMin));
Result := iResult;
end;
procedure TFlatScrollbarTrack.DoPositionChange;
begin
TFlatScrollbar(Parent).FPosition := Position;
TFlatScrollbar(Parent).DoScroll;
end;
procedure TFlatScrollbarTrack.DoThumbHighlightColor(Value: TColor);
begin
FThumb.ColorHighlight := Value;
end;
procedure TFlatScrollbarTrack.DoThumbShadowColor(Value: TColor);
begin
FThumb.ColorShadow := Value;
end;
procedure TFlatScrollbarTrack.DoThumbBorderColor(Value: TColor);
begin
FThumb.ColorBorder := Value;
end;
procedure TFlatScrollbarTrack.DoThumbFocusedColor(Value: TColor);
begin
FThumb.ColorFocused := Value;
end;
procedure TFlatScrollbarTrack.DoThumbDownColor(Value: TColor);
begin
FThumb.ColorDown := Value;
end;
procedure TFlatScrollbarTrack.DoThumbColor(Value: TColor);
begin
FThumb.Color := Value;
end;
procedure TFlatScrollbarTrack.DoHScroll(var Message: TWMScroll);
var
iPosition: Integer;
begin
case Message.ScrollCode of
SB_BOTTOM: Position := Max;
SB_LINELEFT: begin
iPosition := Position;
Dec(iPosition,SmallChange);
Position := iPosition;
end;
SB_LINERIGHT: begin
iPosition := Position;
Inc(iPosition,SmallChange);
Position := iPosition;
end;
SB_PAGELEFT: begin
iPosition := Position;
Dec(iPosition,LargeChange);
Position := iPosition;
end;
SB_PAGERIGHT: begin
iPosition := Position;
Inc(iPosition,LargeChange);
Position := iPosition;
end;
SB_THUMBPOSITION, SB_THUMBTRACK: Position := Message.Pos;
SB_TOP: Position := Min;
end;
Message.Result := 0;
end;
procedure TFlatScrollbarTrack.DoVScroll(var Message: TWMScroll);
var
iPosition: Integer;
begin
case Message.ScrollCode of
SB_BOTTOM: Position := Max;
SB_LINEUP: begin
iPosition := Position;
Dec(iPosition,SmallChange);
Position := iPosition;
end;
SB_LINEDOWN: begin
iPosition := Position;
Inc(iPosition,SmallChange);
Position := iPosition;
end;
SB_PAGEUP: begin
iPosition := Position;
Dec(iPosition,LargeChange);
Position := iPosition;
end;
SB_PAGEDOWN: begin
iPosition := Position;
Inc(iPosition,LargeChange);
Position := iPosition;
end;
SB_THUMBPOSITION, SB_THUMBTRACK: Position := Message.Pos;
SB_TOP: Position := Min;
end;
Message.Result := 0;
end;
procedure TFlatScrollbarTrack.DoEnableArrows(var Message: TMessage);
begin
if Message.WParam = ESB_DISABLE_BOTH then
begin
TFlatScrollbar(Parent).EnableBtnOne(False);
TFlatScrollbar(Parent).EnableBtnTwo(False);
end;
if Message.WParam = ESB_DISABLE_DOWN then
begin
if FKind = sbVertical then TFlatScrollbar(Parent).EnableBtnTwo(False);
end;
if Message.WParam = ESB_DISABLE_LTUP then
begin
TFlatScrollbar(Parent).EnableBtnOne(False);
end;
if Message.WParam = ESB_DISABLE_LEFT then
begin
if FKind = sbHorizontal then TFlatScrollbar(Parent).EnableBtnOne(False);
end;
if Message.WParam = ESB_DISABLE_RTDN then
begin
TFlatScrollbar(Parent).EnableBtnTwo(False);
end;
if Message.WParam = ESB_DISABLE_UP then
begin
if FKind = sbVertical then TFlatScrollbar(Parent).EnableBtnOne(False);
end;
if Message.WParam = ESB_ENABLE_BOTH then
begin
TFlatScrollbar(Parent).EnableBtnOne(True);
TFlatScrollbar(Parent).EnableBtnTwo(True);
end;
Message.Result := 1;
end;
procedure TFlatScrollbarTrack.DoGetPos(var Message: TMessage);
begin
Message.Result := Position;
end;
procedure TFlatScrollbarTrack.DoGetRange(var Message: TMessage);
begin
Message.WParam := Min;
Message.LParam := Max;
end;
procedure TFlatScrollbarTrack.DoSetPos(var Message: TMessage);
begin
Position := Message.WParam;
end;
procedure TFlatScrollbarTrack.DoSetRange(var Message: TMessage);
begin
Min := Message.WParam;
Max := Message.LParam;
end;
procedure TFlatScrollbarTrack.DoKeyDown(var Message: TWMKeyDown);
var
iPosition: Integer;
begin
iPosition := Position;
case Message.CharCode of
VK_PRIOR: Dec(iPosition,LargeChange);
VK_NEXT: Inc(iPosition,LargeChange);
VK_UP: if FKind = sbVertical then Dec(iPosition,SmallChange);
VK_DOWN: if FKind = sbVertical then Inc(iPosition,SmallChange);
VK_LEFT: if FKind = sbHorizontal then Dec(iPosition,SmallChange);
VK_RIGHT: if FKind = sbHorizontal then Inc(iPosition,SmallChange);
end;
Position := iPosition;
end;
{ TFlatScrollbarButton }
constructor TFlatScrollbarButton.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
end;
destructor TFlatScrollbarButton.Destroy;
begin
inherited Destroy;
end;
procedure TFlatScrollbarButton.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
inherited MouseDown(Button,Shift,X,Y);
FNewDown := True;
FTimer := TTimer.Create(Self);
FTimer.Interval := 10;
FTimer.OnTimer := DoTimer;
FTimer.Enabled := True;
end;
procedure TFlatScrollbarButton.MouseMove(Shift: TShiftState; X, Y: Integer);
begin
inherited MouseMove(Shift,X,Y);
end;
procedure TFlatScrollbarButton.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
inherited MouseUp(Button,Shift,X,Y);
FNewDown := False;
FTimer.Enabled := False;
FTimer.Free;
end;
procedure TFlatScrollbarButton.DoTimer(Sender: TObject);
begin
if FNewDown = True then
begin
if Assigned(FOnDown) then FOnDown(Self);
TFlatScrollbar(Parent).DoScroll;
end;
end;
{ TFlatScrollbar }
constructor TFlatScrollbar.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Width := 200;
Height := 17;
Color := ecLightKaki;
FBtnOne := TFlatScrollbarButton.Create(Self);
FBtnOne.Color := ecLightKaki;
FBtnOne.ColorFocused := ecLightKaki;
FBtnOne.ColorDown := ecLightKaki;
FBtnOne.ColorBorder := ecLightKaki;
FBtnOne.Glyph.LoadFromResourceName(hInstance,'THUMB_UP_ENABLED');
FBtnOne.OnDown := BtnOneClick;
InsertControl(FBtnOne);
FBtnTwo := TFlatScrollbarButton.Create(Self);
FBtnTwo.Color := ecLightKaki;
FBtnTwo.ColorFocused := ecLightKaki;
FBtnTwo.ColorDown := ecLightKaki;
FBtnTwo.ColorBorder := ecLightKaki;
FBtnTwo.Glyph.LoadFromResourceName(hInstance,'THUMB_DOWN_ENABLED');
FBtnTwo.OnDown := BtnTwoClick;
InsertControl(FBtnTwo);
FTrack := TFlatScrollbarTrack.Create(Self);
FTrack.Color := ecLightKaki;
FTrack.SetBounds(0,0,Width,Height);
InsertControl(FTrack);
Kind := sbVertical;
Min := 0;
Max := 100;
Position := 0;
SmallChange := 1;
LargeChange := 1;
ButtonColor := ecScrollbar;
ButtonFocusedColor := ecScrollbar;
ButtonDownColor := ecScrollbar;
ButtonBorderColor := ecScrollbar;
ButtonHighlightColor := clWhite;
ButtonShadowColor := clBlack;
ThumbColor := ecScrollbarThumb;
ThumbFocusedColor := ecScrollbarThumb;
ThumbDownColor := ecScrollbarThumb;
ThumbBorderColor := ecScrollbarThumb;
ThumbHighlightColor := ecScrollbarThumb;
ThumbShadowColor := ecScrollbarThumb;
end;
destructor TFlatScrollbar.Destroy;
begin
FTrack.Free;
FBtnOne.Free;
FBtnTwo.Free;
inherited Destroy;
end;
procedure TFlatScrollbar.SetSmallChange(Value: Integer);
begin
if Value <> FSmallChange then
begin
FSmallChange := Value;
FTrack.SmallChange := FSmallChange;
end;
end;
procedure TFlatScrollbar.SetLargeChange(Value: Integer);
begin
if Value <> FLargeChange then
begin
FLargeChange := Value;
FTrack.LargeChange := FLargeChange;
end;
end;
procedure TFlatScrollbar.SetMin(Value: Integer);
begin
if Value <> FMin then
begin
FMin := Value;
FTrack.Min := FMin;
end;
end;
procedure TFlatScrollbar.SetMax(Value: Integer);
begin
if Value <> FMax then
begin
FMax := Value;
FTrack.Max := FMax;
end;
end;
procedure TFlatScrollbar.SetPosition(Value: Integer);
begin
FPosition := Value;
if Position < Min then
begin
Position := Min;
end;
if Position > Max then
begin
Position := Max;
end;
FTrack.Position := FPosition;
end;
procedure TFlatScrollbar.SetKind(Value: TScrollBarKind);
var
i: Integer;
begin
if FKind <> Value then
begin
FKind := Value;
FTrack.Kind := FKind;
if FKind = sbVertical then
begin
FBtnOne.Glyph.LoadFromResourceName(hInstance,'THUMB_UP_ENABLED');
FBtnOne.Refresh;
FBtnTwo.Glyph.LoadFromResourceName(hInstance,'THUMB_DOWN_ENABLED');
FBtnTwo.Refresh;
end
else
begin
FBtnOne.Glyph.LoadFromResourceName(hInstance,'THUMB_LEFT_ENABLED');
FBtnOne.Refresh;
FBtnTwo.Glyph.LoadFromResourceName(hInstance,'THUMB_RIGHT_ENABLED');
FBtnTwo.Refresh;
end;
if (csDesigning in ComponentState) and not (csLoading in ComponentState) then
begin
i := Width;
Width := Height;
Height := i;
end;
end;
end;
procedure TFlatScrollbar.SetButtonHighlightColor(Value: TColor);
begin
if Value <> FButtonHighlightColor then
begin
FButtonHighlightColor := Value;
FBtnOne.ColorHighlight := ButtonHighlightColor;
FBtnTwo.ColorHighlight := ButtonHighlightColor;
end;
end;
procedure TFlatScrollbar.SetButtonShadowColor(Value: TColor);
begin
if Value <> FButtonShadowColor then
begin
FButtonShadowColor := Value;
FBtnOne.ColorShadow := ButtonShadowColor;
FBtnTwo.ColorShadow := ButtonShadowColor;
end;
end;
procedure TFlatScrollbar.SetButtonBorderColor(Value: TColor);
begin
if Value <> FButtonBorderColor then
begin
FButtonBorderColor := Value;
FBtnOne.ColorBorder := ButtonBorderColor;
FBtnTwo.ColorBorder := ButtonBorderColor;
end;
end;
procedure TFlatScrollbar.SetButtonFocusedColor(Value: TColor);
begin
if Value <> FButtonFocusedColor then
begin
FButtonFocusedColor := Value;
FBtnOne.ColorFocused := ButtonFocusedColor;
FBtnTwo.ColorFocused := ButtonFocusedColor;
end;
end;
procedure TFlatScrollbar.SetButtonDownColor(Value: TColor);
begin
if Value <> FButtonDownColor then
begin
FButtonDownColor := Value;
FBtnOne.ColorDown := ButtonDownColor;
FBtnTwo.ColorDown := ButtonDownColor;
end;
end;
procedure TFlatScrollbar.SetButtonColor(Value: TColor);
begin
if Value <> FButtonColor then
begin
FButtonColor := Value;
FBtnOne.Color := ButtonColor;
FBtnTwo.Color := ButtonColor;
end;
end;
procedure TFlatScrollbar.SetThumbHighlightColor(Value: TColor);
begin
if Value <> FThumbHighlightColor then
begin
FThumbHighlightColor := Value;
FTrack.DoThumbHighlightColor(Value);
end;
end;
procedure TFlatScrollbar.SetThumbShadowColor(Value: TColor);
begin
if Value <> FThumbShadowColor then
begin
FThumbShadowColor := Value;
FTrack.DoThumbShadowColor(Value);
end;
end;
procedure TFlatScrollbar.SetThumbBorderColor(Value: TColor);
begin
if Value <> FThumbBorderColor then
begin
FThumbBorderColor := Value;
FTrack.DoThumbBorderColor(Value);
end;
end;
procedure TFlatScrollbar.SetThumbFocusedColor(Value: TColor);
begin
if Value <> FThumbFocusedColor then
begin
FThumbFocusedColor := Value;
FTrack.DoThumbFocusedColor(Value);
end;
end;
procedure TFlatScrollbar.SetThumbDownColor(Value: TColor);
begin
if Value <> FThumbDownColor then
begin
FThumbDownColor := Value;
FTrack.DoThumbDownColor(Value);
end;
end;
procedure TFlatScrollbar.SetThumbColor(Value: TColor);
begin
if Value <> FThumbColor then
begin
FThumbColor := Value;
FTrack.DoThumbColor(Value);
end;
end;
procedure TFlatScrollbar.BtnOneClick(Sender: TObject);
var
iPosition: Integer;
begin
iPosition := Position;
Dec(iPosition,SmallChange);
Position := iPosition;
end;
procedure TFlatScrollbar.BtnTwoClick(Sender: TObject);
var
iPosition: Integer;
begin
iPosition := Position;
Inc(iPosition,SmallChange);
Position := iPosition;
end;
procedure TFlatScrollbar.EnableBtnOne(Value: Boolean);
begin
if Value = True then
begin
FBtnOne.Enabled := True;
case FKind of
sbVertical: FBtnOne.Glyph.LoadFromResourceName(hInstance,'THUMB_UP_ENABLED');
sbHorizontal: FBtnOne.Glyph.LoadFromResourceName(hInstance,'THUMB_LEFT_ENABLED');
end;
end
else
begin
case FKind of
sbVertical: FBtnOne.Glyph.LoadFromResourceName(hInstance,'THUMB_UP_DISABLED');
sbHorizontal: FBtnOne.Glyph.LoadFromResourceName(hInstance,'THUMB_LEFT_DISABLED');
end;
FBtnOne.Enabled := False;
end;
end;