-
Notifications
You must be signed in to change notification settings - Fork 8
/
ExtScrollingWinControlUnit.pas
1009 lines (924 loc) · 29.3 KB
/
ExtScrollingWinControlUnit.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 ExtScrollingWinControlUnit;
interface
uses Messages, Windows, SysUtils, Classes, Graphics, Menus, Imm, Controls,
ActnList, MultiMon, Dialogs, HelpIntfs, ExtCtrls, StdCtrls, Forms, Grids,
Vcl.WinXCtrls;
type
{ Forward declarations }
TExScrollingWinControl = class;
TExControlScrollBar = class(TPersistent)
private
FControl: TExScrollingWinControl;
FIncrement: TScrollBarInc;
FPageIncrement: TScrollbarInc;
FPosition: Integer;
FRange: Integer;
FCalcRange: Integer;
FKind: TScrollBarKind;
FMargin: Word;
FVisible: Boolean;
// FTracking: Boolean;
FScaled: Boolean;
FSmooth: Boolean;
FDelay: Integer;
FButtonSize: Integer;
FColor: TColor;
FParentColor: Boolean;
FSize: Integer;
FStyle: TScrollBarStyle;
FThumbSize: Integer;
FPageDiv: Integer;
FLineDiv: Integer;
FUpdateNeeded: Boolean;
constructor Create(AControl: TExScrollingWinControl; AKind: TScrollBarKind);
procedure CalcAutoRange;
function ControlSize(ControlSB, AssumeSB: Boolean): Integer;
procedure DoSetRange(Value: Integer);
function GetScrollPos: Integer;
function NeedsScrollBarVisible: Boolean;
function IsIncrementStored: Boolean;
procedure SetButtonSize(Value: Integer);
procedure SetColor(Value: TColor);
procedure SetParentColor(Value: Boolean);
procedure SetPosition(Value: Integer);
procedure SetRange(Value: Integer);
procedure SetSize(Value: Integer);
procedure SetStyle(Value: TScrollBarStyle);
procedure SetThumbSize(Value: Integer);
procedure SetVisible(Value: Boolean);
procedure ScrollMessage(var Msg: TWMScroll);
function IsRangeStored: Boolean;
procedure Update(ControlSB, AssumeSB: Boolean);
public
procedure Assign(Source: TPersistent); override;
procedure ChangeBiDiPosition;
property Kind: TScrollBarKind read FKind;
function IsScrollBarVisible: Boolean;
property ScrollPos: Integer read GetScrollPos;
published
property ButtonSize: Integer read FButtonSize write SetButtonSize default 0;
property Color: TColor read FColor write SetColor default clBtnHighlight;
property Increment: TScrollBarInc read FIncrement write FIncrement stored IsIncrementStored default 8;
property Margin: Word read FMargin write FMargin default 0;
property ParentColor: Boolean read FParentColor write SetParentColor default True;
property Position: Integer read FPosition write SetPosition default 0;
property Range: Integer read FRange write SetRange stored IsRangeStored default 0;
property Smooth: Boolean read FSmooth write FSmooth default False;
property Size: Integer read FSize write SetSize default 0;
property Style: TScrollBarStyle read FStyle write SetStyle default ssRegular;
property ThumbSize: Integer read FThumbSize write SetThumbSize default 0;
// property Tracking: Boolean read FTracking write FTracking default False;
property Visible: Boolean read FVisible write SetVisible default True;
end;
{ TExScrollingWinControl }
TWindowState = (wsNormal, wsMinimized, wsMaximized);
TExScrollingWinControl = class(TWinControl)
private
FHorzScrollBar: TExControlScrollBar;
FVertScrollBar: TExControlScrollBar;
FAutoScroll: Boolean;
FAutoRangeCount: Integer;
FUpdatingScrollBars: Boolean;
procedure CalcAutoRange;
procedure ScaleScrollBars(M, D: Integer);
procedure SetAutoScroll(Value: Boolean);
procedure SetHorzScrollBar(Value: TExControlScrollBar);
procedure SetVertScrollBar(Value: TExControlScrollBar);
procedure UpdateScrollBars;
procedure WMSize(var Message: TWMSize); message WM_SIZE;
procedure WMHScroll(var Message: TWMHScroll); message WM_HSCROLL;
procedure WMVScroll(var Message: TWMVScroll); message WM_VSCROLL;
procedure CMBiDiModeChanged(var Message: TMessage); message CM_BIDIMODECHANGED;
// procedure CMMouseWheel(var Message: TCMMouseWheel); message CM_MOUSEWHEEL;
procedure WMMOUSEWHEEL(var Msg: TWMMouseWheel); message WM_MOUSEWHEEL;
protected
procedure AdjustClientRect(var Rect: TRect); override;
procedure AlignControls(AControl: TControl; var ARect: TRect); override;
function AutoScrollEnabled: Boolean; virtual;
procedure AutoScrollInView(AControl: TControl); virtual;
procedure ChangeScale(M, D: Integer); override;
procedure CreateParams(var Params: TCreateParams); override;
procedure CreateWnd; override;
procedure DoFlipChildren; override;
property AutoScroll: Boolean read FAutoScroll write SetAutoScroll default True;
procedure Resizing(State: TWindowState); virtual;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure DisableAutoRange;
procedure EnableAutoRange;
procedure ScrollInView(AControl: TControl);
published
property HorzScrollBar: TExControlScrollBar read FHorzScrollBar write SetHorzScrollBar;
property VertScrollBar: TExControlScrollBar read FVertScrollBar write SetVertScrollBar;
end;
{ TExScrollBox }
TExScrollBox = class(TExScrollingWinControl)
private
FBorderStyle: TBorderStyle;
FDescription: string;
FConnectionString: string;
FController: TPanel;
procedure SetBorderStyle(Value: TBorderStyle);
procedure WMNCHitTest(var Message: TMessage); message WM_NCHITTEST;
procedure CMCtl3DChanged(var Message: TMessage); message CM_CTL3DCHANGED;
protected
procedure CreateParams(var Params: TCreateParams); override;
public
constructor Create(AOwner: TComponent); override;
procedure ClearComponents;
property Description: string read FDescription write FDescription;
property ConnectionString: string read FConnectionString write FConnectionString;
property Controller: TPanel read FController write FController;
published
property Align;
property Anchors;
property AutoScroll;
property AutoSize;
property BevelEdges;
property BevelInner;
property BevelOuter;
property BevelKind;
property BevelWidth;
property BiDiMode;
property BorderStyle: TBorderStyle read FBorderStyle write SetBorderStyle default bsSingle;
property Constraints;
property DockSite;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property Color nodefault;
property Ctl3D;
property Font;
property ParentBiDiMode;
property ParentBackground default False;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property TabOrder;
property TabStop;
property Visible;
property OnCanResize;
property OnClick;
property OnConstrainedResize;
property OnContextPopup;
property OnDblClick;
property OnDockDrop;
property OnDockOver;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnGetSiteInfo;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnMouseWheel;
property OnMouseWheelDown;
property OnMouseWheelUp;
property OnResize;
property OnStartDock;
property OnStartDrag;
property OnUnDock;
end;
implementation
uses
ActiveX, Math, Printers, Consts, RTLConsts, CommCtrl, //FlatSB,
StdActns{$IFDEF MSWINDOWS}, WinHelpViewer{$ENDIF}, Themes;
{ TExControlScrollBar }
constructor TExControlScrollBar.Create(AControl: TExScrollingWinControl;
AKind: TScrollBarKind);
begin
inherited Create;
FControl := AControl;
FKind := AKind;
FPageIncrement := 80;
FIncrement := FPageIncrement div 10;
FVisible := True;
FDelay := 10;
FLineDiv := 4;
FPageDiv := 12;
FColor := clBtnHighlight;
FParentColor := True;
FUpdateNeeded := True;
end;
function TExControlScrollBar.IsIncrementStored: Boolean;
begin
Result := not Smooth;
end;
procedure TExControlScrollBar.Assign(Source: TPersistent);
begin
if Source is TExControlScrollBar then
begin
Visible := TExControlScrollBar(Source).Visible;
Range := TExControlScrollBar(Source).Range;
Position := TExControlScrollBar(Source).Position;
Increment := TExControlScrollBar(Source).Increment;
Exit;
end;
inherited Assign(Source);
end;
procedure TExControlScrollBar.ChangeBiDiPosition;
begin
if Kind = sbHorizontal then
if IsScrollBarVisible then
if not FControl.UseRightToLeftScrollBar then
Position := 0
else
Position := Range;
end;
procedure TExControlScrollBar.CalcAutoRange;
var
I: Integer;
NewRange, AlignMargin: Integer;
procedure ProcessHorz(Control: TControl);
begin
if Control.Visible then
case Control.Align of
alLeft, alNone:
if (Control.Align = alLeft) or (Control.Anchors * [akLeft, akRight] = [akLeft]) then
NewRange := Max(NewRange, Position + Control.Left + Control.Width);
alRight: Inc(AlignMargin, Control.Width);
end;
end;
procedure ProcessVert(Control: TControl);
begin
if Control.Visible then
case Control.Align of
alTop, alNone:
if (Control.Align = alTop) or (Control.Anchors * [akTop, akBottom] = [akTop]) then
NewRange := Max(NewRange, Position + Control.Top + Control.Height);
alBottom: Inc(AlignMargin, Control.Height);
end;
end;
begin
if FControl.FAutoScroll then
begin
if FControl.AutoScrollEnabled then
begin
NewRange := 0;
AlignMargin := 0;
for I := 0 to FControl.ControlCount - 1 do
if Kind = sbHorizontal then
ProcessHorz(FControl.Controls[I]) else
ProcessVert(FControl.Controls[I]);
DoSetRange(NewRange + AlignMargin + Margin);
end
else DoSetRange(0);
end;
end;
function TExControlScrollBar.IsScrollBarVisible: Boolean;
var
Style: Longint;
begin
Style := WS_HSCROLL;
if Kind = sbVertical then Style := WS_VSCROLL;
Result := (Visible) and
(GetWindowLong(FControl.Handle, GWL_STYLE) and Style <> 0);
end;
function TExControlScrollBar.ControlSize(ControlSB, AssumeSB: Boolean): Integer;
var
BorderAdjust: Integer;
function ScrollBarVisible(Code: Word): Boolean;
var
Style: Longint;
begin
Style := WS_HSCROLL;
if Code = SB_VERT then Style := WS_VSCROLL;
Result := GetWindowLong(FControl.Handle, GWL_STYLE) and Style <> 0;
end;
function Adjustment(Code, Metric: Word): Integer;
begin
Result := 0;
if not ControlSB then
if AssumeSB and not ScrollBarVisible(Code) then
Result := -(GetSystemMetrics(Metric) - BorderAdjust)
else if not AssumeSB and ScrollBarVisible(Code) then
Result := GetSystemMetrics(Metric) - BorderAdjust;
end;
begin
BorderAdjust := Integer(GetWindowLong(FControl.Handle, GWL_STYLE) and
(WS_BORDER or WS_THICKFRAME) <> 0);
if Kind = sbVertical then
Result := FControl.ClientHeight + Adjustment(SB_HORZ, SM_CXHSCROLL) else
Result := 0 {FControl.ClientWidth + Adjustment(SB_VERT, SM_CYVSCROLL)};
end;
function TExControlScrollBar.GetScrollPos: Integer;
begin
Result := 0;
if Visible then Result := Position;
end;
function TExControlScrollBar.NeedsScrollBarVisible: Boolean;
begin
Result := FRange > ControlSize(False, False);
end;
procedure TExControlScrollBar.ScrollMessage(var Msg: TWMScroll);
var
Incr, FinalIncr, Count: Integer;
CurrentTime, StartTime, ElapsedTime: Longint;
function GetRealScrollPosition: Integer;
var
SI: TScrollInfo;
Code: Integer;
begin
SI.cbSize := SizeOf(TScrollInfo);
SI.fMask := SIF_TRACKPOS;
Code := SB_HORZ;
if FKind = sbVertical then Code := SB_VERT;
Result := Msg.Pos;
if FlatSB_GetScrollInfo(FControl.Handle, Code, SI) then
Result := SI.nTrackPos;
end;
begin
with Msg do
begin
if FSmooth and (ScrollCode in [SB_LINEUP, SB_LINEDOWN, SB_PAGEUP, SB_PAGEDOWN]) then
begin
case ScrollCode of
SB_LINEUP, SB_LINEDOWN:
begin
Incr := FIncrement div FLineDiv;
FinalIncr := FIncrement mod FLineDiv;
Count := FLineDiv;
end;
SB_PAGEUP, SB_PAGEDOWN:
begin
Incr := FPageIncrement;
FinalIncr := Incr mod FPageDiv;
Incr := Incr div FPageDiv;
Count := FPageDiv;
end;
else
Count := 0;
Incr := 0;
FinalIncr := 0;
end;
CurrentTime := 0;
while Count > 0 do
begin
StartTime := GetCurrentTime;
ElapsedTime := StartTime - CurrentTime;
if ElapsedTime < FDelay then Sleep(FDelay - ElapsedTime);
CurrentTime := StartTime;
case ScrollCode of
SB_LINEUP: SetPosition(FPosition - Incr);
SB_LINEDOWN: SetPosition(FPosition + Incr);
SB_PAGEUP: SetPosition(FPosition - Incr);
SB_PAGEDOWN: SetPosition(FPosition + Incr);
end;
FControl.Update;
Dec(Count);
end;
if FinalIncr > 0 then
begin
case ScrollCode of
SB_LINEUP: SetPosition(FPosition - FinalIncr);
SB_LINEDOWN: SetPosition(FPosition + FinalIncr);
SB_PAGEUP: SetPosition(FPosition - FinalIncr);
SB_PAGEDOWN: SetPosition(FPosition + FinalIncr);
end;
end;
end
else
case ScrollCode of
SB_LINEUP: SetPosition(FPosition - FIncrement);
SB_LINEDOWN: SetPosition(FPosition + FIncrement);
SB_PAGEUP: SetPosition(FPosition - ControlSize(True, False));
SB_PAGEDOWN: SetPosition(FPosition + ControlSize(True, False));
SB_THUMBPOSITION:
if FCalcRange > 32767 then
SetPosition(GetRealScrollPosition) else
SetPosition(Pos);
SB_THUMBTRACK:
//if Tracking then 11
if FCalcRange > 32767 then
SetPosition(GetRealScrollPosition) else
SetPosition(Pos);
SB_TOP: SetPosition(0);
SB_BOTTOM: SetPosition(FCalcRange);
SB_ENDSCROLL: begin end;
end;
end;
end;
procedure TExControlScrollBar.SetButtonSize(Value: Integer);
const
SysConsts: array[TScrollBarKind] of Integer = (SM_CXHSCROLL, SM_CXVSCROLL);
var
NewValue: Integer;
begin
if Value <> ButtonSize then
begin
NewValue := Value;
if NewValue = 0 then
Value := GetSystemMetrics(SysConsts[Kind]);
FButtonSize := Value;
FUpdateNeeded := True;
FControl.UpdateScrollBars;
if NewValue = 0 then
FButtonSize := 0;
end;
end;
procedure TExControlScrollBar.SetColor(Value: TColor);
begin
if Value <> Color then
begin
FColor := Value;
FParentColor := False;
FUpdateNeeded := True;
FControl.UpdateScrollBars;
end;
end;
procedure TExControlScrollBar.SetParentColor(Value: Boolean);
begin
if ParentColor <> Value then
begin
FParentColor := Value;
if Value then Color := clBtnHighlight;
end;
end;
procedure TExControlScrollBar.SetPosition(Value: Integer);
var
Code: Word;
Form: TCustomForm;
OldPos: Integer;
begin
if csReading in FControl.ComponentState then
FPosition := Value
else
begin
if Value > FCalcRange then Value := FCalcRange
else if Value < 0 then Value := 0;
if Kind = sbHorizontal then
Code := SB_HORZ else
Code := SB_VERT;
if Value <> FPosition then
begin
OldPos := FPosition;
FPosition := Value;
if Kind = sbHorizontal then
FControl.ScrollBy(OldPos - Value, 0) else
FControl.ScrollBy(0, OldPos - Value);
if csDesigning in FControl.ComponentState then
begin
Form := GetParentForm(FControl);
if (Form <> nil) and (Form.Designer <> nil) then Form.Designer.Modified;
end;
end;
if FlatSB_GetScrollPos(FControl.Handle, Code) <> FPosition then
FlatSB_SetScrollPos(FControl.Handle, Code, FPosition, True);
end;
end;
procedure TExControlScrollBar.SetSize(Value: Integer);
const
SysConsts: array[TScrollBarKind] of Integer = (SM_CYHSCROLL, SM_CYVSCROLL);
var
NewValue: Integer;
begin
if Value <> Size then
begin
NewValue := Value;
if NewValue = 0 then
Value := GetSystemMetrics(SysConsts[Kind]);
FSize := Value;
FUpdateNeeded := True;
FControl.UpdateScrollBars;
if NewValue = 0 then
FSize := 0;
end;
end;
procedure TExControlScrollBar.SetStyle(Value: TScrollBarStyle);
begin
if Style <> Value then
begin
FStyle := Value;
FUpdateNeeded := True;
FControl.UpdateScrollBars;
end;
end;
procedure TExControlScrollBar.SetThumbSize(Value: Integer);
begin
if Value <> ThumbSize then
begin
FThumbSize := Value;
FUpdateNeeded := True;
FControl.UpdateScrollBars;
end;
end;
procedure TExControlScrollBar.DoSetRange(Value: Integer);
begin
FRange := Value;
if FRange < 0 then FRange := 0;
FControl.UpdateScrollBars;
end;
procedure TExControlScrollBar.SetRange(Value: Integer);
begin
FControl.FAutoScroll := False;
FScaled := True;
DoSetRange(Value);
end;
function TExControlScrollBar.IsRangeStored: Boolean;
begin
Result := not FControl.AutoScroll;
end;
procedure TExControlScrollBar.SetVisible(Value: Boolean);
begin
FVisible := Value;
FControl.UpdateScrollBars;
end;
procedure TExControlScrollBar.Update(ControlSB, AssumeSB: Boolean);
type
TPropKind = (pkStyle, pkButtonSize, pkThumbSize, pkSize, pkBkColor);
const
Props: array[TScrollBarKind, TPropKind] of Integer = (
{ Horizontal }
(WSB_PROP_HSTYLE, WSB_PROP_CXHSCROLL, WSB_PROP_CXHTHUMB, WSB_PROP_CYHSCROLL,
WSB_PROP_HBKGCOLOR),
{ Vertical }
(WSB_PROP_VSTYLE, WSB_PROP_CYVSCROLL, WSB_PROP_CYVTHUMB, WSB_PROP_CXVSCROLL,
WSB_PROP_VBKGCOLOR));
Kinds: array[TScrollBarKind] of Integer = (WSB_PROP_HSTYLE, WSB_PROP_VSTYLE);
Styles: array[TScrollBarStyle] of Integer = (FSB_REGULAR_MODE,
FSB_ENCARTA_MODE, FSB_FLAT_MODE);
var
Code: Word;
ScrollInfo: TScrollInfo;
procedure UpdateScrollProperties(Redraw: Boolean);
begin
FlatSB_SetScrollProp(FControl.Handle, Props[Kind, pkStyle], Styles[Style], Redraw);
if ButtonSize > 0 then
FlatSB_SetScrollProp(FControl.Handle, Props[Kind, pkButtonSize], ButtonSize, False);
if ThumbSize > 0 then
FlatSB_SetScrollProp(FControl.Handle, Props[Kind, pkThumbSize], ThumbSize, False);
if Size > 0 then
FlatSB_SetScrollProp(FControl.Handle, Props[Kind, pkSize], Size, False);
FlatSB_SetScrollProp(FControl.Handle, Props[Kind, pkBkColor],
ColorToRGB(clBtnFace), False);
end;
begin
FCalcRange := 0;
Code := SB_HORZ;
if Kind = sbVertical then Code := SB_VERT;
if Visible then
begin
FCalcRange := Range - ControlSize(ControlSB, AssumeSB);
if FCalcRange < 0 then FCalcRange := 0;
end;
ScrollInfo.cbSize := SizeOf(ScrollInfo);
ScrollInfo.fMask := SIF_ALL;
ScrollInfo.nMin := 0;
if FCalcRange > 0 then
ScrollInfo.nMax := Range else
ScrollInfo.nMax := 0;
ScrollInfo.nPage := ControlSize(ControlSB, AssumeSB) + 1;
ScrollInfo.nPos := FPosition;
ScrollInfo.nTrackPos := FPosition;
UpdateScrollProperties(FUpdateNeeded);
FUpdateNeeded := False;
{1: Âíåñåííûå èçìåíåíèÿ}
//if Code = SB_HORZ then
FlatSB_SetScrollInfo(FControl.Handle, Code, ScrollInfo, True);
SetPosition(FPosition);
FPageIncrement := (ControlSize(True, False) * 9) div 10;
if Smooth then FIncrement := FPageIncrement div 10;
end;
{ TExScrollingWinControl }
constructor TExScrollingWinControl.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := ControlStyle + [csNeedsBorderPaint];
FHorzScrollBar := TExControlScrollBar.Create(Self, sbHorizontal);
FVertScrollBar := TExControlScrollBar.Create(Self, sbVertical);
FAutoScroll := True;
end;
destructor TExScrollingWinControl.Destroy;
begin
FHorzScrollBar.Free;
FVertScrollBar.Free;
inherited Destroy;
end;
procedure TExScrollingWinControl.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
with Params.WindowClass do
style := style and not (CS_HREDRAW or CS_VREDRAW);
end;
procedure TExScrollingWinControl.CreateWnd;
begin
inherited CreateWnd;
//! Scroll bars don't move to the Left side of a TExScrollingWinControl when the
//! WS_EX_LEFTSCROLLBAR flag is set and InitializeFlatSB is called.
//! A call to UnInitializeFlatSB does nothing.
if not SysLocale.MiddleEast and
not CheckWin32Version(5, 1) then
InitializeFlatSB(Handle);
UpdateScrollBars;
end;
procedure TExScrollingWinControl.AlignControls(AControl: TControl; var ARect: TRect);
begin
CalcAutoRange;
inherited AlignControls(AControl, ARect);
end;
function TExScrollingWinControl.AutoScrollEnabled: Boolean;
begin
Result := not AutoSize and not (DockSite and UseDockManager);
end;
procedure TExScrollingWinControl.DoFlipChildren;
var
Loop: Integer;
TheWidth: Integer;
ScrollBarActive: Boolean;
FlippedList: TList;
begin
FlippedList := TList.Create;
try
TheWidth := ClientWidth;
with HorzScrollBar do begin
ScrollBarActive := (IsScrollBarVisible) and (TheWidth < Range);
if ScrollBarActive then
begin
TheWidth := Range;
Position := 0;
end;
end;
for Loop := 0 to ControlCount - 1 do with Controls[Loop] do
begin
FlippedList.Add(Controls[Loop]);
Left := TheWidth - Width - Left;
end;
{ Allow controls that have associations to realign themselves }
for Loop := 0 to FlippedList.Count - 1 do
TControl(FlippedList[Loop]).Perform(CM_ALLCHILDRENFLIPPED, 0, 0);
if ScrollBarActive then
HorzScrollBar.ChangeBiDiPosition;
finally
FlippedList.Free;
end;
end;
procedure TExScrollingWinControl.CalcAutoRange;
begin
if FAutoRangeCount <= 0 then
begin
HorzScrollBar.CalcAutoRange;
VertScrollBar.CalcAutoRange;
end;
end;
procedure TExScrollingWinControl.SetAutoScroll(Value: Boolean);
begin
if FAutoScroll <> Value then
begin
FAutoScroll := Value;
if Value then CalcAutoRange else
begin
HorzScrollBar.Range := 0;
VertScrollBar.Range := 0;
end;
end;
end;
procedure TExScrollingWinControl.SetHorzScrollBar(Value: TExControlScrollBar);
begin
FHorzScrollBar.Assign(Value);
end;
procedure TExScrollingWinControl.SetVertScrollBar(Value: TExControlScrollBar);
begin
FVertScrollBar.Assign(Value);
end;
procedure TExScrollingWinControl.UpdateScrollBars;
begin
if not FUpdatingScrollBars and HandleAllocated then
try
FUpdatingScrollBars := True;
if FVertScrollBar.NeedsScrollBarVisible then
begin
FHorzScrollBar.Update(False, True);
FVertScrollBar.Update(True, False);
end
else if FHorzScrollBar.NeedsScrollBarVisible then
begin
FVertScrollBar.Update(False, True);
FHorzScrollBar.Update(True, False);
end
else
begin
FVertScrollBar.Update(False, False);
FHorzScrollBar.Update(True, False);
end;
finally
FUpdatingScrollBars := False;
end;
end;
procedure TExScrollingWinControl.AutoScrollInView(AControl: TControl);
begin
if (AControl <> nil) and not (csLoading in AControl.ComponentState) and
not (csLoading in ComponentState) then
ScrollInView(AControl);
end;
procedure TExScrollingWinControl.DisableAutoRange;
begin
Inc(FAutoRangeCount);
end;
procedure TExScrollingWinControl.EnableAutoRange;
begin
if FAutoRangeCount > 0 then
begin
Dec(FAutoRangeCount);
if (FAutoRangeCount = 0) and (FHorzScrollBar.Visible or
FVertScrollBar.Visible) then CalcAutoRange;
end;
end;
procedure TExScrollingWinControl.ScrollInView(AControl: TControl);
var
Rect: TRect;
begin
if AControl = nil then Exit;
Rect := AControl.ClientRect;
Dec(Rect.Left, HorzScrollBar.Margin);
Inc(Rect.Right, HorzScrollBar.Margin);
Dec(Rect.Top, VertScrollBar.Margin);
Inc(Rect.Bottom, VertScrollBar.Margin);
Rect.TopLeft := ScreenToClient(AControl.ClientToScreen(Rect.TopLeft));
Rect.BottomRight := ScreenToClient(AControl.ClientToScreen(Rect.BottomRight));
if Rect.Left < 0 then
with HorzScrollBar do Position := Position + Rect.Left
else if Rect.Right > ClientWidth then
begin
if Rect.Right - Rect.Left > ClientWidth then
Rect.Right := Rect.Left + ClientWidth;
with HorzScrollBar do Position := Position + Rect.Right - ClientWidth;
end;
if Rect.Top < 0 then
with VertScrollBar do Position := Position + Rect.Top
else if Rect.Bottom > ClientHeight then
begin
if Rect.Bottom - Rect.Top > ClientHeight then
Rect.Bottom := Rect.Top + ClientHeight;
with VertScrollBar do Position := Position + Rect.Bottom - ClientHeight;
end;
end;
procedure TExScrollingWinControl.ScaleScrollBars(M, D: Integer);
begin
if M <> D then
begin
if not (csLoading in ComponentState) then
begin
HorzScrollBar.FScaled := True;
VertScrollBar.FScaled := True;
end;
HorzScrollBar.Position := 0;
VertScrollBar.Position := 0;
if not FAutoScroll then
begin
with HorzScrollBar do if FScaled then Range := MulDiv(Range, M, D);
with VertScrollBar do if FScaled then Range := MulDiv(Range, M, D);
end;
end;
HorzScrollBar.FScaled := False;
VertScrollBar.FScaled := False;
end;
procedure TExScrollingWinControl.ChangeScale(M, D: Integer);
begin
ScaleScrollBars(M, D);
inherited ChangeScale(M, D);
end;
procedure TExScrollingWinControl.Resizing(State: TWindowState);
begin
// Overridden by TCustomFrame
end;
procedure TExScrollingWinControl.WMSize(var Message: TWMSize);
var
NewState: TWindowState;
begin
Inc(FAutoRangeCount);
try
inherited;
NewState := wsNormal;
case Message.SizeType of
SIZENORMAL: NewState := wsNormal;
SIZEICONIC: NewState := wsMinimized;
SIZEFULLSCREEN: NewState := wsMaximized;
end;
Resizing(NewState);
finally
Dec(FAutoRangeCount);
end;
FUpdatingScrollBars := True;
try
CalcAutoRange;
finally
FUpdatingScrollBars := False;
end;
if FHorzScrollBar.Visible or FVertScrollBar.Visible then
UpdateScrollBars;
end;
procedure TExScrollingWinControl.WMHScroll(var Message: TWMHScroll);
begin
if (Message.ScrollBar = 0) and FHorzScrollBar.Visible then
FHorzScrollBar.ScrollMessage(Message) else
inherited;
end;
procedure TExScrollingWinControl.WMVScroll(var Message: TWMVScroll);
begin
if (Message.ScrollBar = 0) and FVertScrollBar.Visible then
begin
FVertScrollBar.ScrollMessage(Message);
end
else
inherited;
end;
procedure TExScrollingWinControl.AdjustClientRect(var Rect: TRect);
begin
Rect := Bounds(-HorzScrollBar.Position, -VertScrollBar.Position,
Max(HorzScrollBar.Range, ClientWidth), Max(ClientHeight,
VertScrollBar.Range));
inherited AdjustClientRect(Rect);
end;
procedure TExScrollingWinControl.CMBiDiModeChanged(var Message: TMessage);
var
Save: Integer;
begin
Save := Message.WParam;
try
{ prevent inherited from calling Invalidate & RecreateWnd }
if not (Self is TExScrollBox) then Message.wParam := 1;
inherited;
finally
Message.wParam := Save;
end;
if HandleAllocated then
begin
HorzScrollBar.ChangeBiDiPosition;
UpdateScrollBars;
end;
end;
procedure TExScrollingWinControl.WMMOUSEWHEEL(var Msg: TWMMouseWheel);
begin
if KeysToShiftState(Msg.Keys) = [] then
FVertScrollBar.Position:=FVertScrollBar.Position-Msg.WheelDelta
else
inherited;
end;
{ TExScrollBox }
constructor TExScrollBox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := [csAcceptsControls, csCaptureMouse, csClickEvents,
csSetCaption, csDoubleClicks];
Width := 101;
Height := 41;
FBorderStyle := bsNone;
HorzScrollBar.Visible := True;
VertScrollBar.Visible := True;
end;
procedure TExScrollBox.CreateParams(var Params: TCreateParams);
const
BorderStyles: array[TBorderStyle] of DWORD = (0, WS_BORDER);
begin
inherited CreateParams(Params);
with Params do
begin
Style := Style or BorderStyles[FBorderStyle];
if NewStyleControls and Ctl3D and (FBorderStyle = bsSingle) then
begin
Style := Style and not WS_BORDER;
ExStyle := ExStyle or WS_EX_CLIENTEDGE;
end;
end;
end;
procedure TExScrollBox.SetBorderStyle(Value: TBorderStyle);
begin
if Value <> FBorderStyle then
begin
FBorderStyle := Value;
RecreateWnd;
end;
end;
procedure TExScrollBox.WMNCHitTest(var Message: TMessage);
begin
DefaultHandler(Message);
end;
procedure TExScrollBox.ClearComponents;
var
i: integer;
Temp: TComponent;
begin
for i := ControlCount - 1 downto 0 do
begin
Temp := Controls[i];
if (Temp is TStringGrid) or (Temp is TButton) or (Temp is TActivityIndicator) then
begin
RemoveComponent(Temp);
Temp.Free;
end;
end;