Repository navigation
Expand file tree
/
Copy pathSCButtonSet.pas
More file actions
3965 lines (3344 loc) · 107 KB
/
Copy pathSCButtonSet.pas
File metadata and controls
3965 lines (3344 loc) · 107 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 SCButtonSet;
{$I SweetControls.inc}
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Extctrls, ImgList, StdActns, ActnList, Menus, SCCommon, SCConsts, SCControl,
SCBitmap;
type
TSCButtonSet = class;
TSCButtonSetButton = class;
TSCButtonSetActionLink = class(TActionLink)
protected
FClient: TSCButtonSetButton;
procedure AssignClient(AClient: TObject); override;
function IsCaptionLinked: Boolean; override;
function IsCheckedLinked: 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 SetChecked(Value: Boolean); 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;
TSCButtonSetActionLinkClass = class of TSCButtonSetActionLink;
TSCButtonSetButton = class(TCollectionItem)
private
FAlignment: TLeftRight;
FCancel: Boolean;
FCaption: string;
FColor: TColor;
FData: TObject;
FDown: Boolean;
FEnabled: Boolean;
FImageIndex: TImageIndex;
FLockChange: Boolean;
FHint: String;
FModalResult: TModalResult;
FParentColor: Boolean;
FPopupMenu: TPopupMenu;
FTag: Integer;
FVisible: Boolean;
FWidth: Integer;
FActionLink: TSCButtonSetActionLink;
FOnClick: TNotifyEvent;
FOnDblClick: TNotifyEvent;
FOnMouseDown: TMouseEvent;
FOnMouseMove: TMouseMoveEvent;
FOnMouseUp: TMouseEvent;
function GetAction: TBasicAction;
procedure SetAction(const Value: TBasicAction);
procedure SetAlignment(Value: TLeftRight);
procedure SetCaption(const Value: string);
procedure SetColor(Value: TColor);
procedure SetDown(Value: Boolean);
procedure SetEnabled(Value: Boolean);
function GetFocused: Boolean;
procedure SetFocused(Value: Boolean);
procedure SetImageIndex(Value: TImageIndex);
procedure SetParentColor(Value: Boolean);
procedure SetPopupMenu(Value: TPopupMenu);
procedure SetVisible(Value: Boolean);
procedure SetWidth(Value: Integer);
protected
procedure Notification(AComponent: TComponent;
Operation: TOperation); virtual;
procedure UpdateFocus;
procedure DoChanged(IsVisibleChange, AllItems: Boolean);
function GetDisplayName: string; override;
function IsAutoSized: Boolean;
function IsCaptionStored: Boolean;
function IsDownStored: Boolean;
function IsEnabledStored: Boolean;
function IsHintStored: Boolean;
function IsImageIndexStored: Boolean;
function IsOnClickStored: Boolean;
function IsVisibleStored: Boolean;
procedure DoActionChange(Sender: TObject);
function OwnerState: TComponentState;
function GetButtonSet: TSCButtonSet;
function GetImages: TCustomImageList;
procedure UpdateButtonSelection; virtual;
function GetActionLinkClass: TSCButtonSetActionLinkClass; dynamic;
procedure ActionChange(Sender: TObject; CheckDefaults: Boolean); dynamic;
property ActionLink: TSCButtonSetActionLink read FActionLink write FActionLink;
public
constructor Create(Collection: TCollection); override;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
property ButtonSet: TSCButtonSet read GetButtonSet;
property Data: TObject read FData write FData;
published
property Action: TBasicAction read GetAction write SetAction;
property Alignment: TLeftRight read FAlignment write SetAlignment default taLeftJustify;
property Cancel: Boolean read FCancel write FCancel default False;
property Caption: string read FCaption write SetCaption stored IsCaptionStored;
property Color: TColor read FColor write SetColor default clBtnFace;
property Down: Boolean read FDown write SetDown stored IsDownStored default False;
property Enabled: Boolean read FEnabled write SetEnabled stored IsEnabledStored default True;
property Hint: String read FHint write FHint;
property ImageIndex: TImageIndex read FImageIndex write SetImageIndex stored IsImageIndexStored default -1;
property ModalResult: TModalResult read FModalResult write FModalResult default 0;
property ParentColor: Boolean read FParentColor write SetParentColor default True;
property PopupMenu: TPopupMenu read FPopupMenu write SetPopupMenu;
property Tag: Integer read FTag write FTag default 0;
property Visible: Boolean read FVisible write SetVisible stored IsVisibleStored default True;
property Width: Integer read FWidth write SetWidth default 75;
property Focused: Boolean read GetFocused write SetFocused stored False default False;
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;
TSCButtonSetButtons = class(TCollection)
private
FButtonSet: TSCButtonSet;
function GetItem(Index: Integer): TSCButtonSetButton;
procedure SetItem(Index: Integer; Value: TSCButtonSetButton);
protected
function GetOwner: TPersistent; override;
procedure Update(Item: TCollectionItem); override;
public
constructor Create(ButtonSet: TSCButtonSet);
function Add: TSCButtonSetButton;
{$IFDEF SC_DELPHI5_AND_EARLY}
property Owner: TSCButtonSet read FButtonSet;
{$ENDIF}
property Items[Index: Integer]: TSCButtonSetButton read GetItem write SetItem; default;
end;
TSCButtonChangeEvent = procedure(Sender: TObject; NewButton: Integer;
var AllowChange: Boolean) of object;
TSCDrawButtonEvent = procedure(Sender: TObject; AButton: TSCButtonSetButton;
ACanvas: TCanvas; const ARect: TRect) of object;
TSCOwnerDrawEvent = procedure(Sender: TObject; ACanvas: TCanvas;
const ARect: TRect) of object;
TSCButtonSetPaintStyle = (scbpsDefault, scbpsFlat, scbpsMac, scbpsMacSquare,
scbpsMacDefault, scbpsMacSpeed, scbpsNew, scbpsOfficeXP, scbpsSpeed, scbpsXP);
TSCButtonSetStyle = (scbsDefault, scbsChecked, scbsRadio);
TSCButtonSetState = (scstPressed, scstDown, scstHot);
TSCButtonSetStates = set of TSCButtonSetState;
TSCButtonSet = class(TSCCustomControl)
private
FAllowAllUp: Boolean;
FButtonIndex: Integer;
FButtons: TSCButtonSetButtons;
FFlatColor: TColor;
FFocusedStyle: TFontStyles;
FHideFocusRect: Boolean;
FHorizontalSpace: Integer;
FImageIndent: Integer;
FPaintStyle: TSCButtonSetPaintStyle;
FResetWidths: Boolean;
FSeperation: Integer;
FStyle: TSCButtonSetStyle;
FUseSystemFont: Boolean;
FMouseInBtn: Integer;
FMouseDownBtn: Integer;
FClickedBtn: Integer;
FDblClicked: Boolean;
function GetActiveButton: TSCButtonSetButton;
procedure SetAllowAllUp(const Value: Boolean);
procedure SetButtonIndex(Value: Integer);
procedure SetButtons(Value: TSCButtonSetButtons);
procedure SetFlatColor(const Value: TColor);
procedure SetFocusedStyle(const Value: TFontStyles);
procedure SetHideFocusRect(const Value : Boolean);
procedure SetHorizontalSpace(Value: Integer);
procedure SetImageIndent(Value: Integer);
procedure SetPaintStyle(const Value: TSCButtonSetPaintStyle);
procedure SetResetWidths(const Value: Boolean);
procedure SetSeperation(Value: Integer);
procedure SetStyle(const Value: TSCButtonSetStyle);
procedure SetUseSystemFont(const Value: Boolean);
procedure CMHintShow(var Message: TMessage); message CM_HINTSHOW;
procedure CMParentFontChanged(var Message: TMessage); message CM_PARENTFONTCHANGED;
procedure CMSysFontChanged(var Message: TMessage); message CM_SYSFONTCHANGED;
procedure CMDialogKey(var Message: TCMDialogKey); message CM_DIALOGKEY;
procedure CMDialogChar(var Message: TCMDialogChar); message CM_DIALOGCHAR;
procedure WMGetDlgCode(var Message: TWMGetDlgCode); message WM_GETDLGCODE;
procedure UpdateDowns(Index: Integer = -1);
procedure DoBtnClick(Index: Integer);
procedure DoBtnDblClick(Index: Integer);
procedure DoBtnMouseDown(Index: Integer; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure DoBtnMouseMove(Index: Integer; Shift: TShiftState; X, Y: Integer);
procedure DoBtnMouseUp(Index: Integer; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
protected
procedure Paint; override;
procedure AdjustSize; override;
procedure Loaded; override;
function CanAutoSize(var NewWidth, NewHeight: Integer): Boolean; override;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
procedure AdjustBounds; override;
procedure SetAutoSize(Value: Boolean); override;
function CanGetFocus: Boolean; override;
function GetBlendValue: Word; override;
procedure ImageListChange(Sender: TObject); override;
procedure StopTracking; override;
procedure MouseInControlChanged; override;
procedure KeyDown(var Key: Word; Shift: TShiftState); 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;
function DownButtonCount: Integer;
function CanDoDown(Index: Integer; DownState: Boolean): Boolean;
function GetSeperatorWidth: Integer; virtual;
function GetFrameWidth: Integer; virtual;
function GetPopupArrowWidth: Integer; virtual;
function GetButtonHeight: Integer; virtual;
function GetButtonFrameWidth: Integer; virtual;
function GetButtonBounds(Index: Integer; AsAutoSized, CheckVisible: Boolean;
BtnHeight: Integer = -1): TRect; virtual;
function GetButtonRect(Index: Integer; BtnHeight: Integer = -1): TRect; virtual;
procedure UpdateButton(Index: Integer); virtual;
procedure UpdateButtons; dynamic;
procedure SyncToSystemFont;
procedure DoDrawButton(C: TCanvas; R: TRect; Index: Integer;
DrawFrame: Boolean = False);
procedure DoDrawOfficeXP(ACanvas: TCanvas; R: TRect; Index: Integer); virtual;
procedure DoDrawDefault(ACanvas: TCanvas; R: TRect; Index: Integer); virtual;
procedure DoDrawMac(ACanvas: TCanvas; R: TRect; Index: Integer); virtual;
procedure DoDrawSpeed(ACanvas: TCanvas; R: TRect; Index: Integer); virtual;
procedure DoDrawNew(ACanvas: TCanvas; R: TRect; Index: Integer); virtual;
procedure DoDrawXP(ACanvas: TCanvas; R: TRect; Index: Integer); virtual;
procedure DoDrawButtons(ACanvas: TCanvas; X, Y: Integer);
procedure DoDrawArrow(ACanvas: TCanvas; X, Y: Integer; AColor: TColor); virtual;
procedure DoDrawSeperator(ACanvas: TCanvas; R: TRect); virtual;
procedure DoDrawFrame(ACanvas: TCanvas; R: TRect); virtual;
property ButtonFrameWidth: Integer read GetButtonFrameWidth;
property ButtonHeight: Integer read GetButtonHeight;
property FrameWidth: Integer read GetFrameWidth;
property PopupArrowWidth: Integer read GetPopupArrowWidth;
property SeperatorWidth: Integer read GetSeperatorWidth;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
function GetButtonAtPos(P: TPoint): Integer;
function ButtonRect(Index: Integer): TRect;
function ClientToButton(P: TPoint): TPoint;
function ButtonRectangle: TRect;
function VisibleCount: Integer;
function IsValidButton(Index: Integer): Boolean;
procedure DoResetWidths;
property ActiveButton: TSCButtonSetButton read GetActiveButton;
published
property Style: TSCButtonSetStyle read FStyle write SetStyle default scbsDefault;
property Align default alNone;
property AllowAllUp: Boolean read FAllowAllUp write SetAllowAllUp default False;
property Anchors;
property AutoSize;
property BlendColor default False;
property ButtonIndex: Integer read FButtonIndex write SetButtonIndex default -1;
property Buttons: TSCButtonSetButtons read FButtons write SetButtons;
property Color default clBtnFace;
property Constraints;
property Cursor;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property FlatColor: TColor read FFlatColor write SetFlatColor default clBtnShadow;
property FocusedStyle: TFontStyles read FFocusedStyle write SetFocusedStyle default [fsBold];
property Font;
property HideFocusRect: Boolean read FHideFocusRect write SetHideFocusRect default False;
property Hint;
property HorizontalSpace: Integer read FHorizontalSpace write SetHorizontalSpace default 0;
property ImageIndent: Integer read FImageIndent write SetImageIndent default 2;
property Images;
property Indent;
property PaintStyle: TSCButtonSetPaintStyle read FPaintStyle write SetPaintStyle default scbpsNew;
property ParentColor default False;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ResetWidths: Boolean read FResetWidths write SetResetWidths stored False default False;
property ShowHint;
property TabOrder;
property TabStop default True;
property Tag;
property Seperation: Integer read FSeperation write SetSeperation default 0;
property UseSystemFont: Boolean read FUseSystemFont write SetUseSystemFont default False;
property OnClick;
property OnCanResize;
property OnConstrainedResize;
property OnContextPopup;
property OnDockDrop;
property OnDockOver;
property OnDragDrop;
property OnDragOver;
property OnDblClick;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnGetSiteInfo;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnResize;
property OnStartDock;
property OnStartDrag;
end;
implementation
{ TSCButtonSetButton }
procedure TSCButtonSetButton.ActionChange(Sender: TObject;
CheckDefaults: Boolean);
begin
if Action is TCustomAction then
try
if Collection <> nil then Collection.BeginUpdate;
with TCustomAction(Sender) do
begin
if not CheckDefaults or (Self.Caption = '') then
Self.Caption := Caption;
if not CheckDefaults or (Self.Enabled = True) then
Self.Enabled := Enabled;
if not CheckDefaults or (Self.ImageIndex = -1) then
Self.ImageIndex := ImageIndex;
if not CheckDefaults or (Self.Visible = True) then
Self.Visible := Visible;
if not CheckDefaults or not Assigned(Self.OnClick) then
Self.OnClick := OnExecute;
end;
finally
if Collection <> nil then Collection.EndUpdate;
end;
end;
procedure TSCButtonSetButton.Assign(Source: TPersistent);
begin
if Source is TSCButtonSetButton then
begin
FLockChange := True;
Collection.BeginUpdate;
try
with TSCButtonSetButton(Source) do
begin
Self.Action := Action;
Self.Alignment := Alignment;
Self.Cancel := Cancel;
Self.Caption := Caption;
Self.Color := Color;
Self.Down := Down;
Self.Enabled := Enabled;
Self.Hint := Hint;
Self.ImageIndex := ImageIndex;
Self.ModalResult := ModalResult;
Self.ParentColor := ParentColor;
Self.PopupMenu := PopupMenu;
Self.Visible := Visible;
Self.Width := Width;
Self.Tag := Tag;
Self.Focused := Focused;
end;
finally
FLockChange := False;
Collection.EndUpdate;
end;
end else
inherited Assign(Source);
end;
constructor TSCButtonSetButton.Create(Collection: TCollection);
begin
FWidth := 75;
FImageIndex := -1;
inherited Create(Collection);
FColor := clBtnFace;
FEnabled := True;
FParentColor := True;
FTag := 0;
FVisible := True;
end;
destructor TSCButtonSetButton.Destroy;
begin
FreeAndNil(FActionLink);
inherited Destroy;
end;
procedure TSCButtonSetButton.DoActionChange(Sender: TObject);
begin
if Sender = Action then ActionChange(Sender, False);
end;
function TSCButtonSetButton.GetAction: TBasicAction;
begin
if FActionLink <> nil then
Result := FActionLink.Action else
Result := nil;
end;
function TSCButtonSetButton.GetActionLinkClass: TSCButtonSetActionLinkClass;
begin
Result := TSCButtonSetActionLink;
end;
function TSCButtonSetButton.GetDisplayName: string;
begin
Result := Caption;
if Result = '' then
Result := inherited GetDisplayName;
end;
function TSCButtonSetButton.GetImages: TCustomImageList;
var
AButtonSet: TSCButtonSet;
begin
Result := nil;
AButtonSet := ButtonSet;
if AButtonSet <> nil then
Result := AButtonSet.Images;
end;
function TSCButtonSetButton.IsAutoSized: Boolean;
begin
Result := TSCButtonSetButtons(Collection).FButtonSet.AutoSize;
end;
function TSCButtonSetButton.IsCaptionStored: Boolean;
begin
Result := (ActionLink = nil) or not FActionLink.IsCaptionLinked;
end;
function TSCButtonSetButton.IsEnabledStored: Boolean;
begin
Result := (ActionLink = nil) or not FActionLink.IsEnabledLinked;
end;
function TSCButtonSetButton.IsHintStored: Boolean;
begin
Result := (ActionLink = nil) or not FActionLink.IsHintLinked;
end;
function TSCButtonSetButton.IsImageIndexStored: Boolean;
begin
Result := (ActionLink = nil) or not FActionLink.IsImageIndexLinked;
end;
function TSCButtonSetButton.IsOnClickStored: Boolean;
begin
Result := (ActionLink = nil) or not FActionLink.IsOnExecuteLinked;
end;
function TSCButtonSetButton.IsVisibleStored: Boolean;
begin
Result := (ActionLink = nil) or not FActionLink.IsVisibleLinked;
end;
function TSCButtonSetButton.OwnerState: TComponentState;
begin
Result := [];
if TSCButtonSetButtons(Collection).FButtonSet <> nil then
Result := TSCButtonSetButtons(Collection).FButtonSet.ComponentState;
end;
procedure TSCButtonSetButton.SetAction(const Value: TBasicAction);
begin
if Value = nil then
FreeAndNil(FActionLink)
else begin
if FActionLink = nil then
FActionLink := GetActionLinkClass.Create(Self);
FActionLink.Action := Value;
FActionLink.OnChange := DoActionChange;
ActionChange(Value, csLoading in Value.ComponentState);
end;
end;
procedure TSCButtonSetButton.SetAlignment(Value: TLeftRight);
begin
if FAlignment <> Value then
begin
FAlignment := Value;
DoChanged(False, False);
end;
end;
procedure TSCButtonSetButton.SetEnabled(Value: Boolean);
begin
if FEnabled <> Value then
begin
FEnabled := Value;
UpdateFocus;
DoChanged(False, False);
end;
end;
procedure TSCButtonSetButton.SetImageIndex(Value: TImageIndex);
begin
if FImageIndex <> Value then
begin
FImageIndex := Value;
DoChanged(False, IsAutoSized);
end;
end;
procedure TSCButtonSetButton.SetCaption(const Value: string);
begin
if FCaption <> Value then
begin
FCaption := Value;
DoChanged(False, IsAutoSized);
end;
end;
procedure TSCButtonSetButton.SetVisible(Value: Boolean);
begin
if FVisible <> Value then
begin
FVisible := Value;
UpdateFocus;
DoChanged(True, True);
end;
end;
procedure TSCButtonSetButton.SetWidth(Value: Integer);
begin
if Value < 0 then Value := 0;
if FWidth <> Value then
begin
FWidth := Value;
DoChanged(False, True);
end;
end;
procedure TSCButtonSetButton.UpdateButtonSelection;
var
I: Integer;
begin
for I := 0 to Collection.Count-1 do
if Collection.Items[I] <> Self then
TSCButtonSetButton(Collection.Items[I]).Focused := False;
end;
procedure TSCButtonSetButton.Notification(AComponent: TComponent;
Operation: TOperation);
begin
if (Operation = opRemove) and (FPopupMenu <> nil) and
(AComponent = FPopupMenu) then
PopupMenu := nil;
end;
procedure TSCButtonSetButton.DoChanged(IsVisibleChange, AllItems: Boolean);
begin
if not FLockChange and (IsVisibleChange or Visible) then
Changed(IsVisibleChange or AllItems);
end;
procedure TSCButtonSetButton.SetFocused(Value: Boolean);
var
Indx: Integer;
IsFocused: Boolean;
AButtonSet: TSCButtonSet;
begin
Value := FEnabled and FVisible and Value;
AButtonSet := ButtonSet;
if AButtonSet = nil then Exit;
IsFocused := AButtonSet.ButtonIndex = Self.Index;
if IsFocused <> Value then
begin
Indx := -1;
if not IsFocused then Indx := Self.Index;
AButtonSet.ButtonIndex := Indx;
DoChanged(False, True);
end;
end;
function TSCButtonSetButton.GetFocused: Boolean;
var
AButtonSet: TSCButtonSet;
begin
AButtonSet := ButtonSet;
Result := (AButtonSet <> nil) and (AButtonSet.ButtonIndex = Self.Index);
end;
function TSCButtonSetButton.GetButtonSet: TSCButtonSet;
begin
Result := nil;
if (Collection <> nil) and (Collection is TSCButtonSetButtons) then
Result := TSCButtonSetButtons(Collection).FButtonSet;
end;
procedure TSCButtonSetButton.UpdateFocus;
begin
Focused := FEnabled and FVisible and Focused;
end;
procedure TSCButtonSetButton.SetDown(Value: Boolean);
var
AButtonSet: TSCButtonSet;
begin
if FDown <> Value then
begin
AButtonSet := GetButtonSet;
if (AButtonSet <> nil) and
not AButtonSet.CanDoDown(Self.Index, Value) then Exit;
FDown := Value;
if FDown and (AButtonSet <> nil) then
AButtonSet.UpdateDowns(Self.Index);
DoChanged(False, False);
end;
end;
function TSCButtonSetButton.IsDownStored: Boolean;
begin
Result := (ActionLink = nil) or not FActionLink.IsCheckedLinked;
end;
procedure TSCButtonSetButton.SetPopupMenu(Value: TPopupMenu);
var
AButtonSet: TSCButtonSet;
begin
if FPopupMenu <> Value then
begin
FPopupMenu := Value;
AButtonSet := ButtonSet;
if AButtonSet = nil then Exit;
DoChanged(False, AButtonSet.AutoSize);
end;
end;
procedure TSCButtonSetButton.SetColor(Value: TColor);
begin
if FColor <> Value then
begin
FColor := Value;
if not (csLoading in OwnerState) then
FParentColor := False;
if not FParentColor then
DoChanged(False, False);
end;
end;
procedure TSCButtonSetButton.SetParentColor(Value: Boolean);
var
AButtonSet: TSCButtonSet;
begin
if FParentColor <> Value then
begin
FParentColor := Value;
if FParentColor then
begin
AButtonSet := GetButtonSet;
if AButtonSet <> nil then
FColor := AButtonSet.Color;
end;
DoChanged(False, False);
end;
end;
{ TSCButtonSetButtons }
function TSCButtonSetButtons.Add: TSCButtonSetButton;
begin
Result := TSCButtonSetButton(inherited Add);
end;
constructor TSCButtonSetButtons.Create(ButtonSet: TSCButtonSet);
begin
inherited Create(TSCButtonSetButton);
FButtonSet := ButtonSet;
end;
function TSCButtonSetButtons.GetItem(Index: Integer): TSCButtonSetButton;
begin
Result := TSCButtonSetButton(inherited GetItem(Index));
end;
function TSCButtonSetButtons.GetOwner: TPersistent;
begin
Result := FButtonSet;
end;
procedure TSCButtonSetButtons.SetItem(Index: Integer; Value: TSCButtonSetButton);
begin
inherited SetItem(Index, Value);
end;
procedure TSCButtonSetButtons.Update(Item: TCollectionItem);
begin
if Item <> nil then
FButtonSet.UpdateButton(Item.Index) else
FButtonSet.UpdateButtons;
end;
{ TSCButtonSet }
procedure TSCButtonSet.AdjustSize;
var
W, H: Integer;
begin
if not CanGetClientRect then Exit;
W := Width; H := Height;
if AutoSize then inherited AdjustSize;
if (W = Width) and (H = Height) then Invalidate;
end;
function TSCButtonSet.ButtonRectangle: TRect;
var
I, BtnHeight,
FrmWidth, SepWidth: Integer;
AButton: TSCButtonSetButton;
R: TRect;
begin
FrmWidth := FrameWidth;
if FrmWidth < 0 then FrmWidth := 0;
Result := Rect(0, 0, 2*FrmWidth, 2*FrmWidth);
if (FButtons <> nil) and
(FButtons.Count > 0) and CanGetClientRect then
begin
Result := Rect(0, 0, 0, 0);
SepWidth := SeperatorWidth;
if SepWidth < 0 then SepWidth := 0;
BtnHeight := GetButtonHeight;
for I := 0 to FButtons.Count-1 do
begin
AButton := FButtons[I];
if not AButton.Visible then Continue;
R := GetButtonBounds(I, AutoSize, True, BtnHeight);
OffsetRect(R, -R.Left, -R.Top);
Inc(Result.Right, R.Right + SepWidth);
end;
Dec(Result.Right, SepWidth);
Result.Bottom := Result.Top + BtnHeight;
if FrmWidth > 0 then
InflateRect(Result, FrmWidth, FrmWidth);
OffsetRect(Result, -Result.Left, -Result.Top);
end;
end;
function TSCButtonSet.CanAutoSize(var NewWidth,
NewHeight: Integer): Boolean;
var
R: TRect;
begin
Result := True;
if (FButtons <> nil) and (FButtons.Count > 0) then
begin
R := ButtonRectangle;
OffsetRect(R, -R.Left, -R.Top);
if R.Right < 0 then R.Right := 0;
if R.Bottom < 0 then R.Bottom := 0;
if Align in [alNone, alLeft, alRight] then
NewWidth := R.Right;
if Align in [alNone, alTop, alBottom] then
NewHeight := R.Bottom;
end;
end;
constructor TSCButtonSet.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := [csCaptureMouse, csClickEvents, csDoubleClicks, csOpaque];
SetBounds(Left, Top, 75, 25);
BlendColor := False;
Color := clBtnFace;
ParentColor := False;
TabStop := True;
FMouseInBtn := -1;
FMouseDownBtn := -1;
FDblClicked := False;
FAllowAllUp := False;
FButtons := TSCButtonSetButtons.Create(Self);
FButtonIndex := -1;
FFlatColor := clBtnShadow;
FFocusedStyle := [fsBold];
FHorizontalSpace := 0;
FImageIndent := 2;
FPaintStyle := scbpsNew;
FSeperation := 0;
FStyle := scbsDefault;
FUseSystemFont := False;
end;
destructor TSCButtonSet.Destroy;
begin
FreeAndNil(FButtons);
inherited Destroy;
end;
procedure TSCButtonSet.DoDrawButton(C: TCanvas; R: TRect;
Index: Integer; DrawFrame: Boolean);
var
// BtnRgn: HRGN;
SR: Integer;
FR, CR: TRect;
begin
if (C = nil) or not CanGetClientRect or IsRectEmpty(R) then
Exit;
// BtnRgn := CreateRectRgnIndirect(R);
// SelectClipRgn(C.Handle, BtnRgn);
SR := IntersectClipRect(C.Handle, R.Left, R.Top, R.Right, R.Bottom);
try
if SR = NULLREGION then
Exit;
case FPaintStyle of
scbpsXP:
DoDrawXP(C, R, Index);
scbpsDefault:
DoDrawDefault(C, R, Index);
scbpsMac, scbpsMacSquare:
DoDrawMac(C, R, Index);
scbpsSpeed, scbpsFlat,
scbpsMacDefault, scbpsMacSpeed:
DoDrawSpeed(C, R, Index);
scbpsOfficeXP:
DoDrawOfficeXP(C, R, Index);
scbpsNew:
DoDrawNew(C, R, Index);
end;
finally
// DeleteObject(BtnRgn);
SelectClipRgn(C.Handle, 0);
end;
if DrawFrame then
begin
CR := ClientRect;
FR := ButtonRectangle;
IntersectRect(FR, FR, CR);
FR.Top := CR.Top;
FR.Bottom := CR.Bottom;
if not IsRectEmpty(FR) then
DoDrawFrame(C, FR);
end;
end;
procedure TSCButtonSet.DoDrawButtons(ACanvas: TCanvas; X, Y: Integer);
var
I, BtnHeight,
SepWidth, FrmWidth: Integer;
LimitExited: Boolean;
CR, BtnR, R: TRect;
AButton: TSCButtonSetButton;
begin
if (ACanvas = nil) or not CanGetClientRect then Exit;
CR := ClientRect;
if IsRectEmpty(CR) then Exit;
FrmWidth := FrameWidth;
if FrmWidth < 0 then FrmWidth := 0;
InflateRect(CR, -FrmWidth, -FrmWidth);
try
if IsRectEmpty(CR) then Exit;
OffsetRect(CR, X, Y);
R := CR;
BtnHeight := GetButtonHeight;
if BtnHeight < 0 then BtnHeight := 0;
R.Bottom := R.Top;
Inc(R.Bottom, BtnHeight);
SepWidth := SeperatorWidth;
if SepWidth < 0 then SepWidth := 0;
R.Right := R.Left;
LimitExited := False;
for I := 0 to FButtons.Count-1 do
begin
if LimitExited then Exit;
AButton := FButtons[I];
if not AButton.Visible then Continue;
BtnR := GetButtonBounds(I, AutoSize, True);
OffsetRect(BtnR, -BtnR.Left, 0);
Inc(R.Right, BtnR.Right);
LimitExited := R.Right >= CR.Right;
if LimitExited then
begin
R.Right := CR.Right;
if IsRectEmpty(R) then Exit;
end;
if not IsRectEmpty(R) then
begin
DoDrawButton(ACanvas, R, I);
R.Left := R.Right;
if (SepWidth > 0) and (I < FButtons.Count-1) then
begin
Inc(R.Right, SepWidth);
DoDrawSeperator(ACanvas, R);
R.Left := R.Right;
end;
end;
end;
finally
InflateRect(CR, FrmWidth, FrmWidth);
R := ButtonRectangle;
IntersectRect(R, R, CR);
R.Top := CR.Top;
R.Bottom := CR.Bottom;
if not IsRectEmpty(R) then DoDrawFrame(ACanvas, R);
end;
end;
procedure TSCButtonSet.DoDrawFrame(ACanvas: TCanvas; R: TRect);
var
CR: TRect;
BtnFaceLight, BtnShadowDark,
BtnFaceExLight, HighlightLight,