Repository navigation
Expand file tree
/
Copy pathSCStatusBar.pas
More file actions
3774 lines (3191 loc) · 93.6 KB
/
Copy pathSCStatusBar.pas
File metadata and controls
3774 lines (3191 loc) · 93.6 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 SCStatusBar;
{$I SweetControls.inc}
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
SCConsts, SCControl, SCCommon, TypInfo, Extctrls, ImgList, StdActns,
ActnList;
type
TSCCustomStatusBar = class;
TSCStatusPanel = class;
TSCPanelAlign = (scpaLeft, scpaRight);
TSCStatusPanelStyle = (scpsAnimation, scpsControl, scpsGauge,
scpsImage, scpsImageAndText, scpsOwnerDraw, scpsText);
TSCStatusPanelBevel = (scpbNone, scpbLowered, scpbRaised, scpbFlat,
scpb3DLowered, scpb3DRaised);
TSCBarStyle = (scbsStatusWindows, scbsStatusMac, scbsStatusOffice12,
scbsStatusXP);
TSCStatusPanelActionLink = class(TActionLink)
protected
FClient: TSCStatusPanel;
procedure AssignClient(AClient: TObject); override;
function IsCaptionLinked: Boolean; override;
function IsEnabledLinked: Boolean; override;
function IsHintLinked: Boolean; override;
function IsImageIndexLinked: Boolean; override;
function IsShortCutLinked: Boolean; override;
function IsVisibleLinked: Boolean; override;
function IsOnExecuteLinked: Boolean; override;
procedure SetCaption(const Value: string); override;
procedure SetEnabled(Value: Boolean); override;
procedure SetHint(const Value: string); override;
procedure SetImageIndex(Value: Integer); override;
procedure SetShortCut(Value: TShortCut); override;
procedure SetVisible(Value: Boolean); override;
procedure SetOnExecute(Value: TNotifyEvent); override;
end;
TSCStatusPanelActionLinkClass = class of TSCStatusPanelActionLink;
TSCStatusGaugeStyle = (scsg3d, scsgClasic, scsgSliced, scsgSlicedGradient,
scsgGradient, scsgRaised, scsgXP);
TSCStatusPanelGauge = class(TPersistent)
private
FColor: TColor;
FEndColor: TColor;
FPosition: Word;
FStyle: TSCStatusGaugeStyle;
FMin: Integer;
FMax: Integer;
FCaption: String;
FOnChange: TNotifyEvent;
FNotifyLocked: Boolean;
procedure SetCaption(const Value: String);
procedure SetColor(Value: TColor);
procedure SetEndColor(Value: TColor);
procedure SetMin(Value: Integer);
procedure SetMax(Value: Integer);
procedure SetPosition(Value: Word);
procedure SetStyle(Value: TSCStatusGaugeStyle);
protected
procedure DoChange; virtual;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
public
constructor Create; virtual;
procedure Assign(Source: TPersistent); override;
published
property Caption: String read FCaption write SetCaption;
property Color: TColor read FColor write SetColor default clHighlight;
property EndColor: TColor read FEndColor write SetEndColor default clAqua;
property Min: Integer read FMin write SetMin default 0;
property Max: Integer read FMax write SetMax default 100;
property Position: Word read FPosition write SetPosition default 0;
property Style: TSCStatusGaugeStyle read FStyle write SetStyle default scsgClasic;
end;
TSCStatusPanel = class(TCollectionItem)
private
FText: string;
FWidth: Integer;
FAlignment: TAlignment;
FAutoSize: Boolean;
FBevel: TSCStatusPanelBevel;
FStyle: TSCStatusPanelStyle;
FColor: TColor;
FParentColor: Boolean;
FImageIndex: TImageIndex;
FAnimationStart: TImageIndex;
FAnimationStop: TImageIndex;
FAnimateTimer: TTimer;
FAnimationInterval: Cardinal;
FAnimate: Boolean;
FVisible: Boolean;
FEnabled: Boolean;
FActionLink: TSCStatusPanelActionLink;
FIndent: Integer;
FEndEllipsis: Boolean;
FGauge: TSCStatusPanelGauge;
FBorderColor: TColor;
FHint: String;
FShowing: Boolean;
FFlash: Boolean;
FFlashShowPause: Cardinal;
FFlashHidePause: Cardinal;
FFlashTimer: TTimer;
FFontColor: TColor;
FCurAnimateIndex: TImageIndex;
FOnAnimate: TNotifyEvent;
FOnClick: TNotifyEvent;
FOnDblClick: TNotifyEvent;
FOnMouseDown: TMouseEvent;
FOnMouseMove: TMouseMoveEvent;
FOnMouseUp: TMouseEvent;
FControl: TControl;
function GetAction: TBasicAction;
procedure SetAction(const Value: TBasicAction);
procedure SetAlignment(Value: TAlignment);
procedure SetAnimationStart(Value: TImageIndex);
procedure SetAnimationStop(Value: TImageIndex);
function GetAnimationInterval: Cardinal;
procedure SetAnimationInterval(Value: Cardinal);
function GetAnimate: Boolean;
procedure SetAnimate(Value: Boolean);
procedure SetAutoSize(Value: Boolean);
procedure SetBevel(Value: TSCStatusPanelBevel);
procedure SetBorderColor(Value: TColor);
procedure SetColor(Value: TColor);
procedure SetControl(Value: TControl);
procedure SetEnabled(Value: Boolean);
procedure SetEndEllipsis(Value: Boolean);
procedure SetFlash(Value: Boolean);
procedure SetFlashShowPause(Value: Cardinal);
procedure SetFlashHidePause(Value: Cardinal);
procedure SetFontColor(Value: TColor);
procedure SetGauge(Value: TSCStatusPanelGauge);
procedure SetImageIndex(Value: TImageIndex);
procedure SetIndent(Value : Integer);
procedure SetParentColor(Value: Boolean);
function GetStatusBar: TSCCustomStatusBar;
procedure SetStyle(Value: TSCStatusPanelStyle);
procedure SetText(const Value: string);
procedure SetVisible(Value: Boolean);
procedure SetWidth(Value: Integer);
procedure DoChange(AllItems: Boolean; Force: Boolean = False);
protected
function GetDisplayName: string; override;
function GetParentColor: TColor; virtual;
procedure Notification(AComponent: TComponent; Operation: TOperation); virtual;
procedure FreeNotification(AComponent: TComponent);
procedure RemoveFreeNotification(AComponent: TComponent);
function IsCaptionStored: Boolean;
function IsEnabledStored: Boolean;
function IsHintStored: Boolean;
function IsImageIndexStored: Boolean;
function IsOnClickStored: Boolean;
function IsVisibleStored: Boolean;
procedure DoActionChange(Sender: TObject);
procedure GaugeChanged(Sender: TObject);
function OwnerState: TComponentState;
function GetImages: TCustomImageList;
procedure InitiateAnimation;
function InitiateAnimationTimer: TTimer;
procedure ReleaseAnimationTimer;
procedure AnimateThis(Sender: TObject);
procedure InitiateFlashing;
function InitiateFlashTimer: TTimer;
procedure ReleaseFlashTimer;
procedure FlashMe(Sender: TObject);
function GetActionLinkClass: TSCStatusPanelActionLinkClass; dynamic;
procedure ActionChange(Sender: TObject; CheckDefaults: Boolean); dynamic;
property ActionLink: TSCStatusPanelActionLink read FActionLink write FActionLink;
property CurAnimateIndex: TImageIndex read FCurAnimateIndex;
property StatusBar: TSCCustomStatusBar read GetStatusbar;
public
constructor Create(Collection: TCollection); override;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
procedure ResetCurAnimation;
property Showing: Boolean read FShowing;
published
property Action: TBasicAction read GetAction write SetAction;
property Alignment: TAlignment read FAlignment write SetAlignment default taLeftJustify;
property Control: TControl read FControl write SetControl;
{ Animation }
property AnimationStart: TImageIndex read FAnimationStart write SetAnimationStart default -1;
property AnimationStop: TImageIndex read FAnimationStop write SetAnimationStop default -1;
property AnimationInterval: Cardinal read GetAnimationInterval write SetAnimationInterval default 1000;
property Animate: Boolean read GetAnimate write SetAnimate stored True default False;
property AutoSize: Boolean read FAutoSize write SetAutoSize default False;
property Bevel: TSCStatusPanelBevel read FBevel write SetBevel default scpbLowered;
property BorderColor: TColor read FBorderColor write SetBorderColor default clBtnShadow;
property Color: TColor read FColor write SetColor default clBtnFace;
property Enabled: Boolean read FEnabled write SetEnabled stored IsEnabledStored default True;
property EndEllipsis: Boolean read FEndEllipsis write SetEndEllipsis default True;
property Flash: Boolean read FFlash write SetFlash stored True default False;
property FlashHidePause: Cardinal read FFlashHidePause write SetFlashHidePause default 200;
property FlashShowPause: Cardinal read FFlashShowPause write SetFlashShowPause default 500;
property FontColor: TColor read FFontColor write SetFontColor default clNone;
property Gauge: TSCStatusPanelGauge read FGauge write SetGauge;
property Hint: String read FHint write FHint;
property ImageIndex: TImageIndex read FImageIndex write SetImageIndex stored IsImageIndexStored default -1;
property Indent: Integer read FIndent write SetIndent default 0;
property ParentColor: Boolean read FParentColor write SetParentColor default True;
property Style: TSCStatusPanelStyle read FStyle write SetStyle default scpsText;
property Text: string read FText write SetText stored IsCaptionStored;
property Visible: Boolean read FVisible write SetVisible stored IsVisibleStored default True;
property Width: Integer read FWidth write SetWidth default 50;
property OnAnimate: TNotifyEvent read FOnAnimate write FOnAnimate;
property OnClick: TNotifyEvent read FOnClick write FOnClick stored IsOnClickStored;
property OnDblClick: TNotifyEvent read FOnDblClick write FOnDblClick;
property OnMouseDown: TMouseEvent read FOnMouseDown write FOnMouseDown;
property OnMouseMove: TMouseMoveEvent read FOnMouseMove write FOnMouseMove;
property OnMouseUp: TMouseEvent read FOnMouseUp write FOnMouseUp;
end;
TSCStatusPanels = class(TCollection)
private
FStatusBar: TSCCustomStatusBar;
function GetItem(Index: Integer): TSCStatusPanel;
procedure SetItem(Index: Integer; Value: TSCStatusPanel);
protected
function GetOwner: TPersistent; override;
procedure Update(Item: TCollectionItem); override;
public
constructor Create(StatusBar: TSCCustomStatusBar);
function Add: TSCStatusPanel;
{$IFDEF SC_DELPHI5_AND_EARLY}
property Owner: TSCCustomStatusBar read FStatusBar;
{$ENDIF}
property Items[Index: Integer]: TSCStatusPanel read GetItem write SetItem; default;
end;
TSCDrawStatusEvent = procedure(StatusBar: TSCCustomStatusBar; Panel: TSCStatusPanel;
StatusCanvas: TCanvas; const Rect: TRect) of object;
TSCCustomStatusBar = class(TSCCustomControl)
private
FPanels: TSCStatusPanels;
FSimpleText: string;
FSimplePanel: Boolean;
FUseSystemFont: Boolean;
FSizeGrip: Boolean;
FLeftSpace: Cardinal;
FStyle: TSCBarStyle;
FAutoHint: Boolean;
FPanelAlign: TSCPanelAlign;
FOnHint: TNotifyEvent;
FOnDrawPanel: TSCDrawStatusEvent;
FSzGripClick: Boolean;
FOldCursor: TCursor;
FMouseDownPanel: Integer;
FPanelDblClicked: Boolean;
procedure SetPanelAlign(Value: TSCPanelAlign);
procedure SetStyle(Value: TSCBarStyle);
procedure SetPanels(Value: TSCStatusPanels);
procedure SetSimplePanel(Value: Boolean);
procedure SetSimpleText(const Value: string);
procedure SetLeftSpace(Value: Cardinal);
procedure SetSizeGrip(Value: Boolean);
procedure SetUseSystemFont(const Value: Boolean);
procedure CMColorChanged(var Message: TMessage); message CM_COLORCHANGED;
procedure CMHintShow(var Message: TMessage); message CM_HINTSHOW;
procedure CMParentColorChanged(var Message: TMessage); message CM_PARENTCOLORCHANGED;
procedure CMParentFontChanged(var Message: TMessage); message CM_PARENTFONTCHANGED;
procedure CMSysColorChange(var Message: TMessage); message CM_SYSCOLORCHANGE;
procedure CMWinIniChange(var Message: TMessage); message CM_WININICHANGE;
procedure CMSysFontChanged(var Message: TMessage); message CM_SYSFONTCHANGED;
procedure WMMove(var Message: TWMMove); message WM_MOVE;
procedure WMSize(var Message: TWMSize); message WM_SIZE;
protected
procedure Paint; override;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
procedure AlignControls(AControl: TControl; var Rect: TRect); override;
function GetGradientDark(AColor: TColor): TColor;
function GetGradientLight(AColor: TColor): TColor;
function GetGradientPreLight(AColor: TColor): TColor;
function GetMacSpace: Integer;
function GetSimpleLeft: Integer;
function GetPanelSpacing: Integer;
function GetSizeGripWidth: Integer;
procedure StopTracking; override;
procedure DoDockOver(Source: TDragDockObject; X, Y: Integer; State: TDragState;
var Accept: Boolean); override;
function DoHint: Boolean; virtual;
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 SyncToSystemFont;
procedure PanelControlAssigned(Panel: TSCStatusPanel; AControl: TControl);
function GetPanelSpace: Word; dynamic;
procedure UpdatePanelColors(OldColor: TColor);
procedure UpdatePanel(Index: Integer; Repaint: Boolean); dynamic;
procedure UpdatePanels; dynamic;
function GetDefaultBackColor: TColor; override;
function GetMacClientWidth: Integer;
function CalculateImageRect(Panel: TSCStatusPanel; R: TRect): TRect; reintroduce;
function SizerRect: TRect; dynamic;
procedure DrawOffice12Face(ACanvas: TCanvas; ARect: TRect);
procedure DoDrawSpace(PanelCanvas: TCanvas; const R: TRect);
procedure DoDrawPanel(Panel: TSCStatusPanel; PanelCanvas: TCanvas; const R: TRect);
procedure DoDrawImagePanel(Panel: TSCStatusPanel; PanelCanvas: TCanvas; const R: TRect);
procedure DoDrawAnimatePanel(Panel: TSCStatusPanel; PanelCanvas: TCanvas; const R: TRect);
procedure DoDrawTextPanel(Panel: TSCStatusPanel; PanelCanvas: TCanvas; const R: TRect);
procedure DoDrawGaugePanel(Panel: TSCStatusPanel; PanelCanvas: TCanvas; const R: TRect);
procedure DoDrawPanelBorder(Panel: TSCStatusPanel; PanelCanvas: TCanvas; const R: TRect);
procedure DoDrawMacBorder(ACanvas: TCanvas);
procedure DoDrawXPBorder(ACanvas: TCanvas);
procedure DoDrawOffice12Border(ACanvas: TCanvas);
procedure DoDrawWinSizer(ACanvas: TCanvas);
procedure DoDrawMacSizer(ACanvas: TCanvas);
procedure DoDrawXPSizer(ACanvas: TCanvas);
procedure DoDrawOffice12Sizer(ACanvas: TCanvas);
property Align default alBottom;
property AutoHint: Boolean read FAutoHint write FAutoHint default False;
property Color default clBtnFace;
property LeftSpace: Cardinal read FLeftSpace write SetLeftSpace default 0;
property PanelAlign: TSCPanelAlign read FPanelAlign write SetPanelAlign default scpaLeft;
property Panels: TSCStatusPanels read FPanels write SetPanels;
property ParentColor default False;
property ParentFont default False;
property SimplePanel: Boolean read FSimplePanel write SetSimplePanel default False;
property SimpleText: string read FSimpleText write SetSimpleText;
property SizeGrip: Boolean read FSizeGrip write SetSizeGrip default True;
property Style: TSCBarStyle read FStyle write SetStyle default scbsStatusWindows;
property UseSystemFont: Boolean read FUseSystemFont write SetUseSystemFont default True;
property OnDrawPanel: TSCDrawStatusEvent read FOnDrawPanel write FOnDrawPanel;
property OnHint: TNotifyEvent read FOnHint write FOnHint;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
function ExecuteAction(Action: TBasicAction): Boolean; override;
function GetLastVisiblePanel: Integer;
function GetClickedPanel: Integer; dynamic;
function IsSizeGrip(X, Y: Integer): Boolean; dynamic;
function PanelAtPos(P: TPoint): Integer; dynamic;
function ClientToPanel(P: TPoint): TPoint;
function PanelRect(Panel: TSCStatusPanel): TRect;
end;
TSCStatusBar = class(TSCCustomStatusBar)
published
property Align;
property Anchors;
property AutoHint;
property Color;
property Constraints;
property Cursor;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property Font;
property Hint;
property Images;
property LeftSpace;
property PanelAlign;
property Panels;
property ParentColor;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property SimplePanel;
property SimpleText;
property SizeGrip;
property ShowHint;
property Style;
property Tag;
property UseSystemFont;
property Visible;
property OnCanResize;
property OnClick;
property OnConstrainedResize;
property OnContextPopup;
property OnDockDrop;
property OnDockOver;
property OnDragDrop;
property OnDragOver;
property OnDblClick;
property OnDrawPanel;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnGetSiteInfo;
property OnHint;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnResize;
property OnStartDock;
property OnStartDrag;
end;
TSCControlSizerStyle = (sccsWindows, sccsMac, sccsXP);
TSCControlSizer = class(TSCCustomControl)
private
FStyle: TSCControlSizerStyle;
procedure SetStyle(Value: TSCControlSizerStyle);
procedure CMColorChanged(var Message: TMessage); message CM_COLORCHANGED;
procedure CMParentColorChanged(var Message: TWMNoParams); message CM_PARENTCOLORCHANGED;
procedure CMSysColorChange(var Message: TMessage); message CM_SYSCOLORCHANGE;
procedure WMMove(var Message: TWMMove); message WM_MOVE;
procedure WMSize(var Message: TWMSize); message WM_SIZE;
protected
procedure Paint; override;
procedure DoDrawWinSizer(ACanvas: TCanvas); dynamic;
procedure DoDrawMacSizer(ACanvas: TCanvas); dynamic;
procedure DoDrawXPSizer(ACanvas: TCanvas); dynamic;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
function GetBlendValue: Word; override;
property BlendColor default False;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
published
property BorderProps;
property Color default clBtnFace;
property Cursor default crSizeNWSE;
property ParentColor default False;
property Style: TSCControlSizerStyle read FStyle write SetStyle default sccsWindows;
property Transparent;
property Visible;
end;
implementation
const
SC_SizeGripWidth = 16;
SC_PanelSpace = 2;
SC_MacSpace = 4;
SC_SimpleLeft = 4;
type
TWinControlFake = class(TWinControl);
{ TSCCustomStatusBar }
function TSCCustomStatusBar.CalculateImageRect(Panel: TSCStatusPanel;
R: TRect): TRect;
begin
Result := R;
if (Panel = nil) or not (Panel.Style in [scpsAnimation,
scpsImage, scpsImageAndText]) then
begin
Result.Right := Result.Left;
Exit;
end;
InflateRect(Result, -2, 0);
if Panel.Bevel in [scpb3DLowered, scpb3DRaised] then
InflateRect(Result, -1, -1);
if Result.Bottom < Result.Top then
Result.Bottom := Result.Top;
if Result.Right < Result.Left then
Result.Right := Result.Left;
if Images = nil then
begin
case Panel.Alignment of
taLeftJustify, taCenter:
Result.Right := Result.Left;
taRightJustify:
Result.Left := Result.Right;
end;
Exit;
end;
case Panel.Style of
scpsAnimation:
begin
if not IsValidImage(Panel.CurAnimateIndex) or
(Images.Width = 0) or (Images.Height = 0) then
begin
case Panel.Alignment of
taLeftJustify, taCenter:
Result.Right := Result.Left;
taRightJustify:
Result.Left := Result.Right;
end;
Exit;
end;
end;
scpsImage, scpsImageAndText:
begin
if not IsValidImage(Panel.ImageIndex) or
(Images.Width = 0) or (Images.Height = 0) then
begin
case Panel.Alignment of
taLeftJustify, taCenter:
Result.Right := Result.Left;
taRightJustify:
Result.Left := Result.Right;
end;
Exit;
end;
end;
end;
if Result.Bottom - Result.Top <> Images.Height then
begin
Inc(Result.Top,
((Result.Bottom - Result.Top) - Images.Height) div 2);
Result.Bottom := Result.Top + Images.Height;
end;
if Result.Right - Result.Left > Images.Width then
begin
case Panel.Alignment of
taLeftJustify:
Result.Right := Result.Left + Images.Width;
taRightJustify:
Result.Left := Result.Right - Images.Width;
taCenter:
begin
Inc(Result.Left,
((Result.Right - Result.Left) - Images.Width) div 2);
Result.Right := Result.Left + Images.Width;
end;
end;
end;
if Result.Right < Result.Left then
Result.Right := Result.Left;
if Result.Bottom < Result.Top then
Result.Bottom := Result.Top;
end;
function TSCCustomStatusBar.PanelRect(Panel: TSCStatusPanel): TRect;
var
CRect: TRect;
P: TSCStatusPanel;
Pw, ExSpace, I, CLeft,
CRight, VisibleCount: Integer;
begin
CRect := ClientRect;
Inc(CRect.Left, FLeftSpace);
ExSpace := GetPanelSpace;
case Style of
scbsStatusWindows:
begin
Inc(CRect.Top, 2);
if SizeGrip then Dec(CRect.Right, GetSizeGripWidth);
end;
scbsStatusMac:
begin
Dec(CRect.Right, GetSizeGripWidth + 4);
Inc(CRect.Left, GetMacSpace);
Inc(CRect.Top, 1);
Dec(CRect.Bottom, 2);
end;
scbsStatusOffice12:
begin
if SizeGrip then Dec(CRect.Right, GetSizeGripWidth);
end;
scbsStatusXP:
begin
if SizeGrip then Dec(CRect.Right, GetSizeGripWidth);
InflateRect(CRect, -2, -2);
Inc(CRect.Top, 2);
end;
else begin
Result := CRect;
Exit;
end;
end;
if IsRectEmpty(CRect) then
begin
with CRect do
begin
Bottom := Top;
Right := Left;
end;
Result := CRect;
Exit;
end;
if SimplePanel or (Panel = nil) then
begin
Result := CRect;
Exit;
end;
CLeft := CRect.Left;
CRight := CRect.Right;
VisibleCount := 0;
for I := 0 to Panels.Count-1 do
if Panels[I].Visible then
Inc(VisibleCount);
Canvas.Font := Self.Font;
if FPanelAlign = scpaLeft then
begin
Result := CRect;
for I := 0 to Panels.Count - 1 do
begin
P := Panels[I];
Pw := P.Width;
if (VisibleCount > 1) and (Pw > 0) and P.Visible and P.AutoSize and
(P.Style in [scpsImageAndText, scpsText]) and (P.Text <> '') then
begin
Pw := Canvas.TextWidth(P.Text) + 4 + P.Indent;
Inc(Pw, 4);
if P.Bevel in [scpb3DLowered, scpb3DRaised] then
Inc(Pw, 2);
if Style = scbsStatusMac then
Inc(Pw, GetMacSpace);
if (P.Style = scpsImageAndText) and IsValidImage(P.ImageIndex) then
Inc(Pw, Images.Width);
end;
if P = Panel then
begin
if Panel.Index < Panels.Count-1 then
CRect.Right := CRect.Left + Pw;
Break;
end;
Inc(CRect.Left, GetPanelSpacing + ExSpace + Pw);
if CRect.Left >= CRect.Right then
begin
CRect.Left := CRect.Right;
Break;
end;
end;
if CRect.Right > CRight then
CRect.Right := CRight;
Result := CRect;
end else
begin
Result := CRect;
for I := Panels.Count - 1 downto 0 do
begin
P := Panels[I];
Pw := P.Width;
if (VisibleCount > 1) and (Pw > 0) and P.Visible and P.AutoSize and
(P.Style in [scpsImageAndText, scpsText]) and (P.Text <> '') then
begin
Pw := Canvas.TextWidth(P.Text) + 4 + P.Indent;
Inc(Pw, 4);
if P.Bevel in [scpb3DLowered, scpb3DRaised] then
Inc(Pw, 2);
if Style = scbsStatusMac then
Inc(Pw, GetMacSpace);
if (P.Style = scpsImageAndText) and IsValidImage(P.ImageIndex) then
Inc(Pw, Images.Width);
end;
if P = Panel then
begin
if Panel.Index > 0 then
CRect.Left := CRect.Right - Pw;
Break;
end;
Dec(CRect.Right, GetPanelSpacing + ExSpace + Pw);
if CRect.Left >= CRect.Right then
begin
CRect.Left := CRect.Right;
Break;
end;
end;
if CRect.Left < CLeft then
CRect.Left := CLeft;
Result := CRect;
end;
if Result.Right < Result.Left then
Result.Right := Result.Left;
end;
function TSCCustomStatusBar.ClientToPanel(P: TPoint): TPoint;
var
Pnl: Integer;
R: TRect;
begin
Result := P;
Pnl := PanelAtPos(P);
if (Pnl > -1) and (Pnl < Panels.Count) then
begin
R := PanelRect(Panels[Pnl]);
Result.X := P.X - R.Left;
Result.Y := P.Y - R.Top;
end;
end;
procedure TSCCustomStatusBar.CMColorChanged(var Message: TMessage);
begin
inherited;
UpdatePanelColors(Canvas.Brush.Color);
Invalidate;
end;
procedure TSCCustomStatusBar.CMHintShow(var Message: TMessage);
const
EmptyHint = '';
var
P: TPoint;
Indx: Integer;
HRect: TRect;
begin
inherited;
with TCMHintShow(Message) do
begin
P := HintInfo.CursorPos;
Indx := PanelAtPos(P);
if (Indx > -1) and (Indx < Panels.Count) then
begin
HintInfo.CursorRect := PanelRect(Panels[Indx]);
if (Panels[Indx].Hint = '') or
not (Panels[Indx].Visible and Panels[Indx].Enabled) then
begin
HintInfo.HintStr := EmptyHint;
Result := 1;
end else
HintInfo.HintStr := Panels[Indx].Hint;
end else
if IsSizeGrip(P.X, P.Y) then
begin
HintInfo.CursorRect := SizerRect;
HintInfo.HintStr := EmptyHint;
Result := 1;
end else
begin
Indx := PanelAtPos(Point(P.X + 1, P.Y));
if (Indx > -1) and (Indx < Panels.Count) then
begin
HRect := ClientRect;
HRect.Left := P.X - 1;
HRect.Right := P.X + 1;
HintInfo.CursorRect := HRect;
end else
begin
Indx := PanelAtPos(Point(P.X - 1, P.Y));
if (Indx > -1) and (Indx < Panels.Count) then
begin
HRect := ClientRect;
HRect.Left := P.X;
HRect.Right := P.X + 2;
HintInfo.CursorRect := HRect;
end else
begin
HRect := ClientRect;
HRect.Bottom := HRect.Top + 2;
if (Self.Style = scbsStatusMac) or (Self.SizeGrip and
(Self.Style in [scbsStatusOffice12, scbsStatusWindows, scbsStatusXP])) then
Dec(HRect.Right, GetSizeGripWidth);
if (HRect.Right > HRect.Left) and PtInRect(HRect, P) then
HintInfo.CursorRect := HRect;
end;
end;
end;
end;
end;
procedure TSCCustomStatusBar.CMParentColorChanged(var Message: TMessage);
begin
inherited;
if ParentColor then
begin
UpdatePanelColors(Canvas.Brush.Color);
Invalidate;
end;
end;
procedure TSCCustomStatusBar.CMParentFontChanged(var Message: TMessage);
begin
inherited;
if FUseSystemFont and ParentFont then FUseSystemFont := False;
end;
procedure TSCCustomStatusBar.CMSysColorChange(var Message: TMessage);
begin
inherited;
UpdatePanelColors(Canvas.Brush.Color);
Invalidate;
end;
procedure TSCCustomStatusBar.CMSysFontChanged(var Message: TMessage);
begin
inherited;
SyncToSystemFont;
end;
procedure TSCCustomStatusBar.CMWinIniChange(var Message: TMessage);
begin
inherited;
if (Message.WParam = 0) or (Message.WParam = SPI_SETNONCLIENTMETRICS) then
SyncToSystemFont;
end;
constructor TSCCustomStatusBar.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := [csCaptureMouse, csClickEvents, csDoubleClicks, csOpaque];
DoubleBuffered := True;
Color := clBtnFace;
ParentColor := False;
ParentFont := False;
Height := 19;
Align := alBottom;
FPanelAlign := scpaLeft;
FOldCursor := Cursor;
FMouseDownPanel := -1;
FPanels := TSCStatusPanels.Create(Self);
FSizeGrip := True;
ParentFont := False;
FUseSystemFont := True;
FStyle := scbsStatusWindows;
SyncToSystemFont;
end;
destructor TSCCustomStatusBar.Destroy;
begin
FreeAndNil(FPanels);
inherited Destroy;
end;
function TSCCustomStatusBar.DoHint: Boolean;
begin
Result := False;
if Assigned(FOnHint) then
begin
FOnHint(Self);
Result := True;
end;
end;
procedure TSCCustomStatusBar.DoDrawAnimatePanel(Panel: TSCStatusPanel;
PanelCanvas: TCanvas; const R: TRect);
var
R2: TRect;
begin
if (Panel = nil) or not Panel.Visible or (Images = nil) or
(Panel.Flash and not Panel.Showing) then
Exit;
R2 := R;
R2 := CalculateImageRect(Panel, R2);
if (Panel.CurAnimateIndex = -1) or
(Panel.CurAnimateIndex > Images.Count-1) or
(R2.Right <= R2.Left) or (R2.Bottom <= R2.Top) then Exit;
Images.Draw(PanelCanvas, R2.Left, R2.Top,
Panel.CurAnimateIndex, Panel.Enabled and Enabled);
end;
procedure TSCCustomStatusBar.DoDrawGaugePanel(Panel: TSCStatusPanel;
PanelCanvas: TCanvas; const R: TRect);
var
Text: String;
R1, R2, R3: TRect;
I, PW, Range,
BasePos, Slice, SliceCnt: Integer;
BrushStyle: TBrushStyle;
Cs, Ce, C1, C2,
BrushColor, PenColor: TColor;
DoSlice, IsGradient: Boolean;
begin
if (Panel = nil) or not Panel.Visible or SimplePanel or
(Panel.Flash and not Panel.Showing) then
Exit;
with Panel.Gauge do
begin
Cs := Color;
if Cs = clNone then Cs := Panel.Color;
Ce := EndColor;
if Ce = clNone then Ce := Cs;
DoSlice := FStyle in [scsgSliced, scsgSlicedGradient, scsgXP];
IsGradient := (Cs <> Ce) and (FStyle in [scsg3d, scsgXP,
scsgSlicedGradient, scsgGradient]);
Range := FMax - FMin;
BasePos := FPosition - FMin;
end;
with PanelCanvas do
begin
R2 := R;
InflateRect(R2, -1, -1);
if Panel.Bevel in [scpb3DLowered, scpb3DRaised] then
InflateRect(R2, -1, -1);
PW := 0;
if not ((Range = 0) or (BasePos > Range) or (BasePos < 0)) then
PW := Round((R2.Right - R2.Left) * (BasePos/Range));
case Panel.Alignment of
taLeftJustify:
R2.Right := R2.Left + PW;
taRightJustify:
R2.Left := R2.Right - PW;
taCenter:
begin
Inc(R2.Left, ((R2.Right - R2.Left) - PW) div 2);
R2.Right := R2.Left + PW;
end;
end;
if R2.Right > R.Right - 1 then
R2.Right := R.Right - 1;
if R2.Left < R.Left + 1 then
R2.Left := R.Left + 1;
if R2.Right < R2.Left then
R2.Right := R2.Left;
BrushStyle := Brush.Style;
BrushColor := Brush.Color;
PenColor := Pen.Color;
try