Repository navigation
Expand file tree
/
Copy pathSCScrollbars.pas
More file actions
4172 lines (3542 loc) · 99.5 KB
/
Copy pathSCScrollbars.pas
File metadata and controls
4172 lines (3542 loc) · 99.5 KB
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
{*******************************************************}
{ }
{ CA SweetControls Component Library }
{ }
{ Copyright (c) 1996,2004 CodeAccelerate Corporation }
{ }
{*******************************************************}
unit SCScrollbars;
{$I SweetControls.inc}
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Extctrls, ImgList, StdActns, ActnList, Menus, SCCommon, SCConsts, SCControl;
type
TSCCustomScrollbar = class;
TSCScrollbarColors = class(TPersistent)
private
FOwner: TSCCustomScrollbar;
FActiveColor: TColor;
FBlendColors: Boolean;
FDefaultColor: TColor;
FDisabledColor: TColor;
FDownColor: TColor;
FHotColor: TColor;
FUpdateCount: Integer;
procedure SetActiveColor(Value: TColor);
procedure SetBlendColors(Value: Boolean);
procedure SetDefaultColor(Value: TColor);
procedure SetDisabledColor(Value: TColor);
procedure SetDownColor(Value: TColor);
procedure SetHotColor(Value: TColor);
protected
procedure DoChange;
function GetBlendColors: Boolean; virtual;
function GetNoneColor: TColor; virtual;
function GetActiveColor: TColor; virtual;
function GetDefaultColor: TColor; virtual;
function GetDisabledColor: TColor; virtual;
function GetDownColor: TColor; virtual;
function GetHotColor: TColor; virtual;
public
constructor Create(AOwner: TSCCustomScrollbar); virtual;
procedure Assign(Source: TPersistent); override;
function InUpdate: Boolean;
procedure BeginUpdate;
procedure EndUpdate;
published
property ActiveColor: TColor read FActiveColor write SetActiveColor default clBtnFace;
property BlendColors: Boolean read FBlendColors write SetBlendColors default False;
property DefaultColor: TColor read FDefaultColor write SetDefaultColor default clBtnFace;
property DisabledColor: TColor read FDisabledColor write SetDisabledColor default clBtnFace;
property DownColor: TColor read FDownColor write SetDownColor default clBtnFace;
property HotColor: TColor read FHotColor write SetHotColor default clBtnFace;
end;
TSCScrollbarBkColors = class(TSCScrollbarColors)
public
constructor Create(AOwner: TSCCustomScrollbar); override;
published
property BlendColors default True;
property DownColor default cl3DDkShadow;
end;
TSCScrollbarIconColors = class(TSCScrollbarColors)
protected
function GetNoneColor: TColor; override;
public
constructor Create(AOwner: TSCCustomScrollbar); override;
published
property ActiveColor default clBtnText;
property DefaultColor default clBtnText;
property DisabledColor default clBtnShadow;
property DownColor default clBtnText;
property HotColor default clBtnText;
end;
TSCCustomScrollbar = class(TSCCustomControl)
private
FFlashColor: TColor;
FFlashOnFocus: Boolean;
FBackColors: TSCScrollbarColors;
FButtonColors: TSCScrollbarColors;
FButtonIconColors: TSCScrollbarColors;
FThumbColors: TSCScrollbarColors;
FButtonLayout: TSCScrollButtonLayout;
FButtonSize: Integer;
FLargeChange: TSCScrollBarInc;
FMax: Integer;
FMin: Integer;
FKind: TSCScrollbarKind;
FPageSize: Integer;
FPosition: Integer;
FShowButtons: Boolean;
FShowSlideLine: Boolean;
FShowThumb: Boolean;
FSmallChange: TSCScrollBarInc;
FThumbLines: TSCScrollThumbline;
FThumbSize: Integer;
FTracking: Boolean;
FTrimPageSize: Boolean;
FDefH_ButtonSize: Integer;
FDefV_ButtonSize: Integer;
FDownPoint: TPoint;
FMovePoint: TPoint;
FDownPosition: Integer;
FMovingThumb: Boolean;
FPressedPart: TSCScrollerHitPart;
FHotPart: TSCScrollerHitPart;
FScrolling: Boolean;
FScrollTimer: Integer;
FSensitivity: Integer;
FShowExtraButton: Boolean;
FStyle: TSCScrollbarStyle;
FKeyboardSpeed: Integer;
FFlashOn: Boolean;
FFlashTimer: Integer;
FOnScroll: TSCScrollEvent;
procedure SetFlashColor(Value: TColor);
procedure SetFlashOnFocus(Value: Boolean);
procedure SetBackColors(Value: TSCScrollbarColors);
procedure SetButtonColors(Value: TSCScrollbarColors);
procedure SetButtonIconColors(Value: TSCScrollbarColors);
procedure SetButtonLayout(Value: TSCScrollButtonLayout);
procedure SetButtonSize(Value: Integer);
procedure SetLargeChange(Value: TSCScrollBarInc);
procedure SetMax(Value: Integer);
procedure SetMin(Value: Integer);
procedure SetKind(Value: TSCScrollbarKind);
procedure SetPageSize(Value: Integer);
procedure SetShowButtons(Value: Boolean);
procedure SetShowExtraButton(Value: Boolean);
procedure SetShowSlideLine(Value: Boolean);
procedure SetShowThumb(Value: Boolean);
procedure SetSmallChange(Value: TSCScrollBarInc);
procedure SetSensitivity(Value: Integer);
procedure SetStyle(Value: TSCScrollbarStyle);
procedure SetThumbColors(Value: TSCScrollbarColors);
procedure SetThumbLines(Value: TSCScrollThumbline);
procedure SetThumbSize(Value: Integer);
procedure SetTrimPageSize(Value: Boolean);
procedure WMGetDlgCode(var Message: TWMGetDlgCode); message WM_GETDLGCODE;
procedure WMMouseWheel(var Message: TWMMouseWheel); message WM_MOUSEWHEEL;
procedure WMTimer(var Message: TWMTimer); message WM_TIMER;
procedure StartFlash;
procedure StopFlash;
procedure StartScrolling;
procedure ScrollControl;
procedure StopScrolling;
protected
procedure Paint; override;
procedure Loaded; override;
procedure DoSettingsChanged; dynamic;
function NormalizePosition(Value: Integer): Integer;
function GetPosition: Integer; virtual;
procedure SetPosition(Value: Integer); virtual;
function CanSetValue(var Value: Integer): Boolean; dynamic;
function GetBlendValue: Word; override;
function GetBorderExColor: TColor; override;
function GetMaximumValue: Integer;
procedure StopTracking; override;
procedure MouseInControlChanged; override;
procedure FocusChanged; override;
procedure EnabledChanged; 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;
procedure ProcessScrollKey(var Key: Word; IsKeyPress: Boolean);
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
function GetBackColor: TColor;
function GetExtraBtnColor: TColor;
function GetExtraBtnIconColor: TColor;
function GetLeftBtnColor: TColor;
function GetLeftBtnIconColor: TColor;
function GetRightBtnColor: TColor;
function GetRightBtnIconColor: TColor;
function GetThumbColor: TColor;
procedure DoDrawXPFace(C: TCanvas; R: TRect; Cl, BkCl: TColor; IsThumb,
IsDown, IsHot: Boolean); virtual;
procedure DoDrawBack(C: TCanvas; R: TRect); virtual;
procedure DoDrawScrollBack(C: TCanvas; R: TRect); virtual;
procedure DoDrawExtraButton(C: TCanvas; R: TRect); virtual;
procedure DoDrawLeftButton(C: TCanvas; R: TRect); virtual;
procedure DoDrawRightButton(C: TCanvas; R: TRect); virtual;
procedure DoDrawThumb(C: TCanvas; R: TRect); virtual;
procedure DoDrawThumbLine(C: TCanvas; R: TRect; Cl: TColor); virtual;
procedure DoDrawBorder(C: TCanvas; R: TRect); virtual;
procedure DoDrawOffice12Border(C: TCanvas; R: TRect);
procedure RearrangeDefaults;
function GetButtonSize: Integer;
function GetThumbOffset: Integer;
function GetThumbSize: Integer;
function GetDefaultThumbSize(Pg: Integer): Integer;
function GetPositionPos(P: Integer): Integer;
function GetBackRectFrom(R: TRect): TRect; dynamic;
function GetBackRect: TRect; dynamic;
function GetExtraButtonRect: TRect; dynamic;
function GetLeftButtonRect: TRect; dynamic;
function GetRightButtonRect: TRect; dynamic;
function GetThumbRect: TRect; dynamic;
property FlashColor: TColor read FFlashColor write SetFlashColor default SC_FlashColor;
property FlashOnFocus: Boolean read FFlashOnFocus write SetFlashOnFocus default False;
property BackColors: TSCScrollbarColors read FBackColors write SetBackColors;
property ButtonColors: TSCScrollbarColors read FButtonColors write SetButtonColors;
property ButtonIconColors: TSCScrollbarColors read FButtonIconColors write SetButtonIconColors;
property ButtonLayout: TSCScrollButtonLayout read FButtonLayout write SetButtonLayout default scsbDefault;
property ButtonSize: Integer read FButtonSize write SetButtonSize default -1;
property ClickFocus default False;
property LargeChange: TSCScrollBarInc read FLargeChange write SetLargeChange default 1;
property Max: Integer read FMax write SetMax default 100;
property Min: Integer read FMin write SetMin default 0;
property Kind: TSCScrollbarKind read FKind write SetKind default scskHorizontal;
property PageSize: Integer read FPageSize write SetPageSize default 0;
property Position: Integer read GetPosition write SetPosition default 0;
property Sensitivity: Integer read FSensitivity write SetSensitivity default -1;
property ShowButtons: Boolean read FShowButtons write SetShowButtons default True;
property ShowExtraButton: Boolean read FShowExtraButton write SetShowExtraButton default False;
property ShowSlideLine: Boolean read FShowSlideLine write SetShowSlideLine default False;
property ShowThumb: Boolean read FShowThumb write SetShowThumb default True;
property SmallChange: TSCScrollBarInc read FSmallChange write SetSmallChange default 1;
property Style: TSCScrollbarStyle read FStyle write SetStyle default scssDefault;
property ThumbColors: TSCScrollbarColors read FThumbColors write SetThumbColors;
property ThumbLines: TSCScrollThumbline read FThumbLines write SetThumbLines default sctlNone;
property ThumbSize: Integer read FThumbSize write SetThumbSize default -1;
property Tracking: Boolean read FTracking write FTracking default True;
property TrimPageSize: Boolean read FTrimPageSize write SetTrimPageSize default True;
property OnScroll: TSCScrollEvent read FOnScroll write FOnScroll;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
function CanScroll(AsLeft: Boolean): Boolean;
function Scrolling: Boolean;
function ScrollPaused: Boolean;
procedure PauseScrolling;
procedure ResumeScrolling;
function GetPartAtPos(X, Y: Integer): TSCScrollerHitPart;
function GetDistanceIncrement(Dist: Integer): Integer;
function GetPositionAtPos(X, Y: Integer; IncParts: Boolean): Integer;
end;
TSCScrollbar = class(TSCCustomScrollbar)
published
property FlashColor;
property FlashOnFocus;
property Align;
property Anchors;
property BackColors;
property BorderProps;
property ButtonColors;
property ButtonIconColors;
property ButtonLayout;
property ButtonSize;
property ClickFocus;
property Constraints;
property Cursor;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property LargeChange;
property Max;
property Min;
property Kind;
property PageSize;
property ParentShowHint;
property Position;
property Sensitivity;
property ShowButtons;
property ShowExtraButton;
property ShowHint;
property ShowSlideLine;
property ShowThumb;
property SmallChange;
property Style;
property TabOrder;
property TabStop;
property ThumbColors;
property ThumbLines;
property ThumbSize;
property Tracking;
property TrimPageSize;
property Visible;
property OnCanResize;
property OnChange;
property OnClick;
property OnContextPopup;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseMove;
property OnMouseUp;
property OnResize;
property OnScroll;
property OnStartDock;
property OnStartDrag;
end;
implementation
const
SC_BAR_SCROLLTIMERID = 93210;
SC_BAR_FlashTIMERID = 93211;
{ TSCCustomScrollbar }
constructor TSCCustomScrollbar.Create(AOwner: TComponent);
begin
FScrolling := False;
FScrollTimer := -1;
inherited Create(AOwner);
SetBounds(Left, Top, 160, 18);
DoubleBuffered := True;
ClickFocus := False;
FDownPoint := Point(-1, -1);
FMovePoint := Point(-1, -1);
FPressedPart := scspNone;
FHotPart := scspNone;
FFlashColor := SC_FlashColor;
FFlashOnFocus := False;
FFlashOn := False;
FFlashTimer := -1;
FButtonLayout := scsbDefault;
FButtonSize := -1;
FLargeChange := 1;
FMax := 100;
FMin := 0;
FKind := scskHorizontal;
FSensitivity := -1;
FShowButtons := True;
FShowThumb := True;
FSmallChange := 1;
FStyle := scssDefault;
FThumbSize := -1;
FThumbLines := sctlNone;
FTracking := True;
FTrimPageSize := True;
FBackColors := TSCScrollbarBkColors.Create(Self);
FButtonColors := TSCScrollbarColors.Create(Self);
FButtonIconColors := TSCScrollbarIconColors.Create(Self);
FThumbColors := TSCScrollbarColors.Create(Self);
RearrangeDefaults;
end;
destructor TSCCustomScrollbar.Destroy;
begin
StopFlash;
StopScrolling;
FreeAndNil(FBackColors);
FreeAndNil(FButtonColors);
FreeAndNil(FButtonIconColors);
FreeAndNil(FThumbColors);
inherited Destroy;
end;
procedure TSCCustomScrollbar.DoSettingsChanged;
begin
Invalidate;
end;
procedure TSCCustomScrollbar.DoDrawOffice12Border(C: TCanvas; R: TRect);
var
Cl: TColor;
begin
if (FStyle = scssOffice12) and (C <> nil) and not IsRectEmpty(R) then
begin
Cl := FBackColors.DefaultColor;
if Cl = clNone then
Cl := clScrollBar;
Cl := SCCommon.scBlendColor(Cl, 12);
with C do
begin
Pen.Style := psSolid;
Pen.Mode := pmCopy;
Pen.Color := Cl;
Pen.Width := 1;
end;
if FKind = scskHorizontal then
begin
C.MoveTo(R.Left, R.Top);
C.LineTo(R.Right, R.Top);
C.MoveTo(R.Left, R.Bottom - 1);
C.LineTo(R.Right, R.Bottom - 1);
end else
begin
C.MoveTo(R.Left, R.Top);
C.LineTo(R.Left, R.Bottom);
C.MoveTo(R.Right - 1, R.Top);
C.LineTo(R.Right - 1, R.Bottom);
end;
end;
end;
function TSCCustomScrollbar.GetBackRect: TRect;
begin
Result := GetBackRectFrom(GetClientRect);
end;
function TSCCustomScrollbar.GetButtonSize: Integer;
var
R: TRect;
Ms: Integer;
begin
Result := FButtonSize;
if Result = -1 then
begin
if FKind = scskHorizontal then
Result := FDefV_ButtonSize
else
Result := FDefH_ButtonSize;
end;
if Result > 0 then
begin
R := GetClientRect;
if FKind = scskHorizontal then
Ms := (R.Right - R.Left) div 2
else
Ms := (R.Bottom - R.Top) div 2;
if Ms < 0 then
Ms := 0;
if Result > Ms then
Result := Ms;
end else
if Result < 0 then
Result := 0;
end;
function TSCCustomScrollbar.GetLeftButtonRect: TRect;
var
Bs: Integer;
begin
if not FShowButtons or (FButtonSize = 0) then
begin
Result := Rect(0, 0, 0, 0);
Exit;
end;
Result := GetClientRect;
Bs := GetButtonSize;
if FKind = scskHorizontal then
begin
if (FButtonLayout in [scsbDefault, scsbLeftTop]) or FShowExtraButton then
Result.Right := Result.Left + Bs
else begin
Dec(Result.Right, Bs);
Result.Left := Result.Right - Bs;
end;
end else
begin
if (FButtonLayout in [scsbDefault, scsbLeftTop]) or FShowExtraButton then
Result.Bottom := Result.Top + Bs
else begin
Dec(Result.Bottom, Bs);
Result.Top := Result.Bottom - Bs;
end;
end;
end;
function TSCCustomScrollbar.GetRightButtonRect: TRect;
var
Bs: Integer;
begin
if not FShowButtons or (FButtonSize = 0) then
begin
Result := Rect(0, 0, 0, 0);
Exit;
end;
Result := GetClientRect;
Bs := GetButtonSize;
if FKind = scskHorizontal then
begin
if FButtonLayout in [scsbDefault, scsbRightBottom] then
Result.Left := Result.Right - Bs
else begin
Inc(Result.Left, Bs);
Result.Right := Result.Left + Bs;
end;
end else
begin
if FButtonLayout in [scsbDefault, scsbRightBottom] then
Result.Top := Result.Bottom - Bs
else begin
Inc(Result.Top, Bs);
Result.Bottom := Result.Top + Bs;
end;
end;
end;
function TSCCustomScrollbar.GetThumbRect: TRect;
var
R1, R2: TRect;
W, P, S, Ts, Mx: Integer;
ThumbMoving: Boolean;
begin
Result := Rect(0, 0, 0, 0);
if not (Enabled and FShowThumb) then
Exit;
R1 := GetBackRect;
if IsRectEmpty(R1) then
Exit;
Mx := GetMaximumValue;
S := Mx - FMin;
if S <= 0 then Exit;
Ts := GetThumbSize;
P := NormalizePosition(Position) - FMin;
ThumbMoving := Enabled and FShowThumb and FMovingThumb and
(FThumbSize <> 0) and (FPressedPart = scspThumb) and
(FDownPoint.x > -1) and (FDownPoint.y > -1) and (FMin < Mx);
if ThumbMoving then
P := FDownPosition - FMin;
R2 := R1;
if FKind = scskHorizontal then
begin
OffsetRect(R2, -R2.Left, 0);
if Ts < R2.Right then
begin
W := R2.Right - Ts;
R2.Right := Ts;
P := Muldiv(W, P, S);
if ThumbMoving then
Inc(P, FMovePoint.x - FDownPoint.x);
OffsetRect(R2, P, 0);
end;
OffsetRect(R2, R1.Left, 0);
if R2.Right > R1.Right then
OffsetRect(R2, R1.Right - R2.Right, 0);
if R2.Left < R1.Left then
OffsetRect(R2, R1.Left - R2.Left, 0);
end else
begin
OffsetRect(R2, 0, -R2.Top);
if Ts < R2.Bottom then
begin
W := R2.Bottom - Ts;
R2.Bottom := Ts;
P := Muldiv(W, P, S);
if ThumbMoving then
Inc(P, FMovePoint.y - FDownPoint.y);
OffsetRect(R2, 0, P);
end;
OffsetRect(R2, 0, R1.Top);
if R2.Bottom > R1.Bottom then
OffsetRect(R2, 0, R1.Bottom - R2.Bottom);
if R2.Top < R1.Top then
OffsetRect(R2, 0, R1.Top - R2.Top);
end;
Result := R2;
IntersectRect(Result, Result, R1);
end;
procedure TSCCustomScrollbar.Paint;
var
R: TRect;
begin
R := GetBackRect;
DoDrawScrollBack(Canvas, R);
R := GetClientRect;
DoDrawBorder(Canvas, R);
R := GetThumbRect;
DoDrawThumb(Canvas, R);
R := GetLeftButtonRect;
DoDrawLeftButton(Canvas, R);
R := GetRightButtonRect;
DoDrawRightButton(Canvas, R);
if FShowExtraButton then
begin
R := GetExtraButtonRect;
DoDrawExtraButton(Canvas, R);
end;
end;
procedure TSCCustomScrollbar.SetBackColors(Value: TSCScrollbarColors);
begin
FBackColors.Assign(Value);
end;
procedure TSCCustomScrollbar.SetButtonColors(Value: TSCScrollbarColors);
begin
FButtonColors.Assign(Value);
end;
procedure TSCCustomScrollbar.SetButtonLayout(Value: TSCScrollButtonLayout);
begin
if FButtonLayout <> Value then
begin
FButtonLayout := Value;
DoSettingsChanged;
end;
end;
procedure TSCCustomScrollbar.SetButtonSize(Value: Integer);
begin
if Value < -1 then
Value := -1
else
if (Value > 0) and (Value < 12) then
Value := 12;
if FButtonSize <> Value then
begin
FButtonSize := Value;
if FShowButtons then
DoSettingsChanged;
end;
end;
procedure TSCCustomScrollbar.SetMax(Value: Integer);
var
Mx: Integer;
begin
if FMax <> Value then
begin
StopScrolling;
FMax := Value;
if FMin > FMax then FMin := Value;
Mx := GetMaximumValue;
if FPosition > Mx then
FPosition := Mx;
Change;
DoSettingsChanged;
end;
end;
procedure TSCCustomScrollbar.SetMin(Value: Integer);
begin
if FMin <> Value then
begin
StopScrolling;
FMin := Value;
if FMax < FMin then FMax := FMin;
if FPosition < FMin then
FPosition := FMin;
Change;
DoSettingsChanged;
end;
end;
procedure TSCCustomScrollbar.SetKind(Value: TSCScrollbarKind);
var
H: Integer;
R: TRect;
begin
if FKind <> Value then
begin
FKind := Value;
if HandleAllocated and not (IsLoading or IsReading) then
begin
R := BoundsRect;
Dec(R.Right, R.Left);
Dec(R.Bottom, R.Top);
H := R.Bottom;
R.Bottom := R.Right;
R.Right := H;
SetBounds(R.Left, R.Top, R.Right, R.Bottom);
end;
DoSettingsChanged;
end;
end;
procedure TSCCustomScrollbar.SetPosition(Value: Integer);
var
Mx: Integer;
CanScroll: Boolean;
begin
if not CanSetValue(Value) then
Exit;
Mx := GetMaximumValue;
if Value > Mx then Value := Mx;
if Value < FMin then Value := FMin;
CanScroll := True;
if (FPosition <> Value) and Assigned(FOnScroll) then
begin
FOnScroll(Self, FKind, FPosition, Value, CanScroll);
if CanScroll then
begin
Mx := GetMaximumValue;
if Value > Mx then Value := Mx;
if Value < FMin then Value := FMin;
end;
end;
if CanScroll and (FPosition <> Value) then
begin
FPosition := Value;
Change;
DoSettingsChanged;
end;
end;
procedure TSCCustomScrollbar.SetShowButtons(Value: Boolean);
begin
if FShowButtons <> Value then
begin
FShowButtons := Value;
if FButtonSize <> 0 then
DoSettingsChanged;
end;
end;
procedure TSCCustomScrollbar.SetThumbColors(Value: TSCScrollbarColors);
begin
FThumbColors.Assign(Value);
end;
procedure TSCCustomScrollbar.SetLargeChange(Value: TSCScrollBarInc);
begin
FLargeChange := Value;
DoSettingsChanged;
end;
procedure TSCCustomScrollbar.SetPageSize(Value: Integer);
begin
if FPageSize <> Value then
begin
FPageSize := Value;
DoSettingsChanged;
end;
end;
procedure TSCCustomScrollbar.SetSmallChange(Value: TSCScrollBarInc);
begin
FSmallChange := Value;
DoSettingsChanged;
end;
procedure TSCCustomScrollbar.RearrangeDefaults;
begin
FDefH_ButtonSize := GetSystemMetrics(SM_CYVTHUMB);
FDefV_ButtonSize := GetSystemMetrics(SM_CXHTHUMB);
end;
procedure TSCCustomScrollbar.SetThumbSize(Value: Integer);
begin
if Value < -1 then
Value := -1;
if FThumbSize <> Value then
begin
FThumbSize := Value;
DoSettingsChanged;
end;
end;
function TSCCustomScrollbar.GetThumbSize: Integer;
begin
Result := 0;
if not (Enabled and FShowThumb) then
Exit;
Result := FThumbSize;
if Result = -1 then
Result := GetDefaultThumbSize(PageSize);
if Result < 0 then
Result := 0;
end;
function TSCCustomScrollbar.GetPartAtPos(X, Y: Integer): TSCScrollerHitPart;
var
P: TPoint;
CR, R: TRect;
ThumbEmpty: Boolean;
begin
Result := scspNone;
P := Point(X, Y);
CR := GetClientRect;
if PtInRect(CR, P) then
begin
if FShowButtons and (FButtonSize <> 0) then
begin
R := GetLeftButtonRect;
if PtInRect(R, P) then
begin
Result := scspLeftButton;
Exit;
end;
R := GetRightButtonRect;
if PtInRect(R, P) then
begin
Result := scspRightButton;
Exit;
end;
if FShowExtraButton then
begin
R := GetExtraButtonRect;
if PtInRect(R, P) then
begin
Result := scspExtraButton;
Exit;
end;
end;
end;
ThumbEmpty := not (Enabled and FShowThumb and (FThumbSize <> 0));
R := Rect(0, 0, 0, 0);
if not ThumbEmpty then
begin
R := GetThumbRect;
ThumbEmpty := IsRectEmpty(R);
end;
if ThumbEmpty then
begin
R := GetBackRect;
if FKind = scskHorizontal then
begin
R.Right := R.Left + ((R.Right - R.Left) div 2);
R.Left := R.Right;
end else
begin
R.Bottom := R.Top + ((R.Bottom - R.Top) div 2);
R.Top := R.Bottom;
end;
end;
if not ThumbEmpty and PtInRect(R, P) then
begin
Result := scspThumb;
Exit;
end;
if FKind = scskHorizontal then
begin
if X < R.Left then
Result := scspLeftSpare
else
if X >= R.Right then
Result := scspRightSpare;
end else
begin
if Y < R.Top then
Result := scspLeftSpare
else
if Y >= R.Bottom then
Result := scspRightSpare;
end;
end;
end;
procedure TSCCustomScrollbar.DoDrawBack(C: TCanvas; R: TRect);
var
R1: TRect;
Cl, C1: TColor;
begin
if (C = nil) or IsRectEmpty(R) then Exit;
Cl := GetBackColor;
if FStyle = scssOffice12 then
begin
Cl := FBackColors.DefaultColor;
if Cl = clNone then
Cl := clScrollBar;
Cl := SCCommon.scBlendColor(Cl, 12);
end;
with C do
begin
Brush.Color := Cl;
FillRect(R);
end;
if FStyle = scssOffice12 then
begin
C1 := SCCommon.scBlendColor(Cl, 36);
if FKind = scskHorizontal then
begin
R1 := R;
R1.Bottom := R1.Top + ((R1.Bottom - R1.Top) div 5);
if not IsRectEmpty(R1) then
scDrawGradient(C, R1, scgTopToBottom, C1, Cl);
R1 := R;
R1.Top := R1.Bottom - ((R1.Bottom - R1.Top) div 5);
if not IsRectEmpty(R1) then
scDrawGradient(C, R1, scgTopToBottom, Cl, C1);
end else
begin
R1 := R;
R1.Right := R1.Left + ((R1.Right - R1.Left) div 5);
if not IsRectEmpty(R1) then
scDrawGradient(C, R1, scgLeftToRight, C1, Cl);
R1 := R;
R1.Left := R1.Right - ((R1.Right - R1.Left) div 5);
if not IsRectEmpty(R1) then
scDrawGradient(C, R1, scgLeftToRight, Cl, C1);
end;
end;
end;
procedure TSCCustomScrollbar.DoDrawScrollBack(C: TCanvas; R: TRect);
var
Cl, C1: TColor;
BR, R1, R2: TRect;
begin
if (C = nil) or IsRectEmpty(R) then Exit;