forked from dim-s/soulengine
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdsCategoryButtons.pas
4628 lines (4216 loc) · 135 KB
/
dsCategoryButtons.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
{*******************************************************}
{ }
{ Delphi Visual Component Library }
{ }
{ Copyright(c) 2016 Embarcadero Technologies, Inc. }
{ All rights reserved }
{ }
{*******************************************************}
unit dsCategoryButtons;
{.$DEFINE LAZARUS}
{.$MODE Delphi}
interface
{$WARN UNIT_PLATFORM OFF}
uses
NxThemesSupport,
{$IF DEFINED(CLR)}
WinUtils,
{$ENDIF}
System.UITypes, Winapi.Windows, Winapi.Messages, Vcl.ImgList, System.Classes,
Vcl.Forms, Vcl.Graphics, Vcl.StdCtrls, Vcl.ExtCtrls,
Vcl.GraphUtil, Vcl.ActnList, Vcl.Themes, Controls;
{$IFDEF VER230} {$DEFINE isVER230} {$ENDIF}
{$IFDEF VER330} {$DEFINE isVER230} {$ENDIF}
{$IFDEF VER320} {$DEFINE isVER230} {$ENDIF}
{$IFDEF VER310} {$DEFINE isVER230} {$ENDIF}
{$IFDEF VER300} {$DEFINE isVER230} {$ENDIF}
{$IFDEF VER290} {$DEFINE isVER230} {$ENDIF}
{$IFDEF VER280} {$DEFINE isVER230} {$ENDIF}
{$IFDEF VER270} {$DEFINE isVER230} {$ENDIF}
{$IFDEF VER260} {$DEFINE isVER230} {$ENDIF}
{$IFDEF VER250} {$DEFINE isVER230} {$ENDIF}
{$IFDEF VER240} {$DEFINE isVER230} {$ENDIF}
const
crDragCopy = TCursor(-23); { New cursor, with a plus for copying }
type
TBaseItem = class;
TBaseButtonItem = class;
TBaseButtonItemClass = class of TBaseButtonItem;
TButtonItem = class;
TButtonItemClass = class of TButtonItem;
TButtonCategory = class;
TButtonCategoryClass = class of TButtonCategory;
TButtonCategories = class;
TButtonCategoriesClass = class of TButtonCategories;
TButtonItemActionLink = class;
TButtonItemActionLinkClass = class of TButtonItemActionLink;
TItemCollection = class;
{ TCategoryButtonsl }
TButtonDrawState = set of (
bdsSelected, // Item is selected and in the "down" state
bdsHot, // Item has the mouse over it
bdsFocused, // Item should show focus
bdsDown, // Item is being pressed by the user
bdsDragged, // The drag image for that button is being drawn
bdsInsertLeft, // Show that an item can be inserted to the left of this item
bdsInsertTop, // Show that an item can be inserted above this item
bdsInsertRight, // Show that an item can be inserted to the right of this item
bdsInsertBottom // Show that an item can be inserted below this item
);
TCatButtonFlow = (cbfVertical, cbfHorizontal);
TCatButtonOptions = set of (boAllowReorder, boAllowCopyingButtons,
boFullSize, boGradientFill, boShowCaptions, boVerticalCategoryCaptions,
boBoldCaptions, boUsePlusMinus, boCaptionOnlyBorder);
TCatButtonEvent = procedure(Sender: TObject; const Button: TButtonItem) of object;
TCatButtonCategoryEvent = procedure(Sender: TObject; const Category: TButtonCategory) of object;
TCatButtonGetHint = procedure(Sender: TObject; const Button: TButtonItem;
const Category: TButtonCategory; var HintStr: string; var Handled: Boolean) of object;
TCatButtonDrawEvent = procedure(Sender: TObject;
const Button: TButtonItem; Canvas: TCanvas; Rect: TRect;
State: TButtonDrawState) of object;
TCatButtonDrawIconEvent = procedure(Sender: TObject;
const Button: TButtonItem; Canvas: TCanvas; Rect: TRect;
State: TButtonDrawState; var TextOffset: Integer) of object;
TCatButtonReorderEvent = procedure(Sender: TObject; const Button: TButtonItem;
const SourceCategory, TargetCategory: TButtonCategory) of object;
TCatButtonCopyEvent = procedure(Sender: TObject;
const SourceButton, CopiedButton: TButtonItem) of object;
TCatButtonEditingEvent = procedure(Sender: TObject; Item: TBaseItem;
var AllowEdit: Boolean) of object;
TCatButtonEditedEvent = procedure(Sender: TObject; Item: TBaseItem; var S: string) of object;
TCatButtonCancelEditEvent = procedure(Sender: TObject; const Item: TBaseItem) of object;
TCategoryReorderEvent = procedure(Sender: TObject; const SourceCategory,
TargetCategory: TButtonCategory) of object;
TCategoryCollapseEvent = procedure(Sender: TObject;
const Category: TButtonCategory) of object;
TCategoryButtons = class(TCustomControl)
{$IF DEFINED(CLR)}
strict private
class var
FCursorHandle: TSafeCursorHandle;
class constructor Create;
{$ENDIF}
strict private
FButtonFlow: TCatButtonFlow;
FCollapsedHeight: Integer;
FDownButton: TButtonItem;
FDragButton: TButtonItem;
FHotButton: TButtonItem;
FDragCategory: TButtonCategory;
FDragStartPos: TPoint;
FDragStarted: Boolean;
FArrowColor: TColor;
FArrowShadow: TColor;
FCollapseGlyph: TImage;
FExpandGlyph: TImage;
FGlyphOpacity: Byte;
FDragImageList: TDragImageList;
FGradientDirection: TGradientDirection;
FBackGradientDirection: TGradientDirection;
FGutterSize: Integer;
FScrollSize: Integer;
FSideBufferSize: Integer;
FImageChangeLink: TChangeLink;
FImages: TCustomImageList;
FInsertLeft,
FInsertTop,
FInsertRight,
FInsertBottom: TBaseItem;
FIgnoreUpdate: Boolean;
FScrollBarMax: Integer;
FScrollBarPos: Integer;
FPageAmount: Integer;
FButtonCategories: TButtonCategories;
FButtonOptions: TCatButtonOptions;
FButtonWidth, FButtonHeight: Integer;
FBorderStyle: TBorderStyle;
FSelectedItem: TBaseItem;
FFocusedItem: TBaseItem;
FStyle: Boolean;
FMouseInControl: Boolean;
FScrollBarShown: Boolean;
FBackgroundGradientColor: TColor;
FHotButtonColor: TColor;
FSelectedButtonColor: TColor;
FRegularButtonColor: TColor;
FInplaceEdit: TCustomEdit;
FPanPoint: TPoint;
FOnButtonClicked: TCatButtonEvent;
FOnCategoryClicked: TCatButtonCategoryEvent;
FOnCopyButton: TCatButtonCopyEvent;
FOnSelectedButtonChange: TCatButtonEvent;
FOnSelectedCategoryChange: TCatButtonCategoryEvent;
FOnHotButton: TCatButtonEvent;
FOnGetHint: TCatButtonGetHint;
FOnDrawIcon: TCatButtonDrawIconEvent;
FOnDrawText: TCatButtonDrawEvent;
FOnDrawButton: TCatButtonDrawEvent;
FOnBeforeDrawButton: TCatButtonDrawEvent;
FOnAfterDrawButton: TCatButtonDrawEvent;
FOnReorderButton: TCatButtonReorderEvent;
FOnEditing: TCatButtonEditingEvent;
FOnEdited: TCatButtonEditedEvent;
FOnCancelEdit: TCatButtonCancelEditEvent;
FOnReorderCategory: TCategoryReorderEvent;
FOnCategoryCollapase: TCategoryCollapseEvent;
class constructor Create;
class destructor Destroy;
procedure AdjustCategoryBounds(const Category: TButtonCategory;
var CategoryBounds: TRect; IgnoreButtonFlow: Boolean = False);
procedure AutoScroll(ScrollCode: TScrollCode);
function CalcButtonsPerRow: Integer;
function CalcButtonsPerCol: Integer;
procedure CalcBufferSizes;
function CalcCategoryHeight(const Category: TButtonCategory;
const ButtonsPerRow: Integer): Integer;
function CalcCategoryWidth(const Category: TButtonCategory;
const ButtonsPerCol: Integer): Integer;
procedure DrawCategory(const Category: TButtonCategory;
const Canvas: TCanvas; StartingPos: Integer);
procedure GetCategoryBounds(const Category: TButtonCategory;
const StartingPos: Integer; var CategoryBounds,
ButtonBounds: TRect);
function GetChevronBounds(const CategoryBounds: TRect): TRect;
function GetIndexOfFirstCategory: Integer;
function GetNextButtonInGroup(const StartingItem: TBaseItem;
GoForward: Boolean): TBaseItem;
function GetNextButton(const StartingItem: TBaseItem;
GoForward: Boolean): TBaseItem;
function GetScrollOffset: Integer;
function GetScrollBuffer: Integer;
procedure ImageListChange(Sender: TObject);
procedure ScrollPosChanged(ScrollCode: TScrollCode;
ScrollPos: Integer);
procedure SetOnDrawButton(const Value: TCatButtonDrawEvent);
procedure SetOnDrawIcon(const Value: TCatButtonDrawIconEvent);
procedure SetBackgroundGradientColor(const Value: TColor);
procedure SetBackGradientDirection(const Value: TGradientDirection);
procedure SetBorderStyle(const Value: TBorderStyle);
procedure SetButtonCategories(const Value: TButtonCategories);
procedure SetButtonFlow(const Value: TCatButtonFlow);
procedure SetButtonHeight(const Value: Integer);
procedure SetButtonWidth(const Value: Integer);
procedure SetCatButtonOptions(const Value: TCatButtonOptions);
procedure SetDragButton(const Value: TButtonItem);
procedure SetFocusedItem(const Value: TBaseItem);
procedure SetGradientDirection(const Value: TGradientDirection);
procedure SetHotButtonColor(const Value: TColor);
procedure SetImages(const Value: TCustomImageList);
procedure SetRegularButtonColor(const Value: TColor);
procedure SetSelectedItem(const Value: TBaseItem);
procedure SetSelectedButtonColor(const Value: TColor);
function IsStyleEnabled: Boolean;
function ShouldScrollDown(out Delay: DWORD): Boolean;
function ShouldScrollUp(out Delay: DWORD): Boolean;
procedure ShowScrollBar(const Visible: Boolean);
procedure CMFontchanged(var Message: TMessage); message CM_FONTCHANGED;
procedure CMHintShow(var Message: TCMHintShow); message CM_HINTSHOW;
procedure CNKeydown(var Message: TWMKeyDown); message CN_KEYDOWN;
procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND;
procedure WMMouseLeave(var Message: TMessage); message WM_MOUSELEAVE;
procedure WMVScroll(var Message: TWMVScroll); message WM_VSCROLL;
procedure WMHScroll(var Message: TWMVScroll); message WM_HSCROLL;
procedure WMSetFocus(var Message: TWMSetFocus); message WM_SETFOCUS;
procedure WMKillFocus(var Message: TWMKillFocus); message WM_KILLFOCUS;
procedure WMSize(var Message: TWMSize); message WM_SIZE;
protected
procedure SetExpandGlyph(Value:TImage);
procedure SetCollapseGlyph(Value:TImage);
procedure FSetArrowShadow(Value:TColor);
procedure FSetStyle(Value:Boolean);
procedure FSetArrowColor(Value:TColor);
procedure SetGlyphOpacity(Value:Byte);
procedure BeginAutoDrag; override;
function CanEdit(Item: TBaseItem): Boolean; dynamic;
procedure CreateHandle; override;
procedure CreateParams(var Params: TCreateParams); override;
procedure DoBeginDrag(Immediate: Boolean; Threshold: Integer); virtual;
procedure DoCopyButton(const Button: TButtonItem;
const TargetCategory: TButtonCategory; const TargetButton: TButtonItem); dynamic;
procedure DoEndDrag(Target: TObject; X: Integer; Y: Integer); override;
procedure DoGesture(const EventInfo: TGestureEventInfo; var Handled: Boolean); override;
procedure DoHotButton; dynamic;
procedure DoReorderButton(const Button: TButtonItem;
const TargetCategory: TButtonCategory; const TargetButton: TButtonItem); dynamic;
procedure DoReorderCategory(const SourceCategory,
TargetCategory: TButtonCategory); dynamic;
procedure DoStartDrag(var DragObject: TDragObject); override;
procedure DoItemClicked(const Item: TBaseItem); dynamic;
procedure DoItemNotify(Item: TCollectionItem; Action: TCollectionNotification);
procedure DoItemUpdate(Item: TCollectionItem);
function DoMouseWheelUp(Shift: TShiftState; MousePos: TPoint): Boolean; override;
function DoMouseWheelDown(Shift: TShiftState; MousePos: TPoint): Boolean; override;
procedure DoSelectedItemChanged(const Item: TBaseItem); dynamic;
procedure DragOver(Source: TObject; X: Integer; Y: Integer;
State: TDragState; var Accept: Boolean); override;
procedure DrawButton(const Button: TButtonItem; Canvas: TCanvas;
Rect: TRect; State: TButtonDrawState); virtual;
function Edit(const Item: TBaseItem): Boolean; virtual;
procedure EndEdit(Cancel: Boolean);
function GetAllowReorder: Boolean; dynamic;
function GetCurrentCategory: TButtonCategory; virtual;
function GetButtonCategoriesClass: TButtonCategoriesClass; virtual;
function GetButtonCategoryClass: TButtonCategoryClass; virtual;
function GetButtonItemClass: TButtonItemClass; virtual;
function GetInplaceEditBounds(const Item: TBaseItem): TRect;
function GetScrollPos: Integer;
function HasVerticalCaption(const Category: TButtonCategory): Boolean;
function IsTouchPropertyStored(AProperty: TTouchProperty): Boolean; override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X: Integer; Y: Integer); override;
procedure MouseMove(Shift: TShiftState; X: Integer; Y: Integer); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X: Integer; Y: Integer); override;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
procedure Paint; override;
procedure Resize; override;
procedure ScrollRectIntoView(const Rect: TRect; PlaceOnTop: Boolean = False);
procedure SetScrollPos(const Value: Integer);
procedure WndProc(var Message: TMessage); override;
published
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
procedure DragDrop(Source: TObject; X: Integer; Y: Integer); override;
procedure GenerateDragImage;
function GetButtonAt(X, Y: Integer; Category: TButtonCategory = nil): TButtonItem;
function GetButtonRect(const Item: TBaseItem): TRect;
function GetCategoryAt(X, Y: Integer): TButtonCategory;
function GetCategoryRect(const Category: TButtonCategory; ButtonOnly: Boolean = False): TRect;
function GetDragImages: TDragImageList; override;
procedure GetTargetAt(X, Y: Integer; var TargetButton: TButtonItem;
var TargetCategory: TButtonCategory);
function IsEditing: Boolean;
procedure RemoveInsertionPoints;
procedure ScrollIntoView(const Item: TBaseItem);
procedure SetInsertionButton(InsertionButton: TButtonItem;
InsertionCategory: TButtonCategory);
procedure UpdateAllButtons;
procedure UpdateButton(const Item: TBaseItem);
property CurrentCategory: TButtonCategory read GetCurrentCategory;
property DragButton: TButtonItem read FDragButton write SetDragButton;
property DragCategory: TButtonCategory read FDragCategory write FDragCategory;
property DragImageList: TDragImageList read FDragImageList;
property SelectedItem: TBaseItem read FSelectedItem write SetSelectedItem;
property FocusedItem: TBaseItem read FFocusedItem write SetFocusedItem;
property Style: Boolean read FStyle write FSetStyle;
property ArrowColor: TColor read FArrowColor write FsetArrowColor;
property ArrowShadow: TColor read FArrowShadow write FsetArrowShadow;
property ExpandGlyph: TImage read FExpandGlyph write SetExpandGlyph;
property CollapseGlyph: TImage read FCollapseGlyph write SetCollapseGlyph;
property GlyphOpacity: Byte read FGlyphOpacity write SetGlyphOpacity;
property Align;
property Anchors;
property BackgroundGradientColor: TColor read FBackgroundGradientColor write SetBackgroundGradientColor default clNone;
property BackgroundGradientDirection: TGradientDirection read FBackGradientDirection write SetBackGradientDirection default gdHorizontal;
property BevelEdges;
property BevelInner;
property BevelOuter;
property BevelKind;
property BevelWidth;
property BorderWidth;
property BorderStyle: TBorderStyle read FBorderStyle write SetBorderStyle default bsSingle;
property ButtonFlow: TCatButtonFlow read FButtonFlow write SetButtonFlow;
property ButtonHeight: Integer read FButtonHeight write SetButtonHeight default 24;
property ButtonWidth: Integer read FButtonWidth write SetButtonWidth default 24;
property ButtonOptions: TCatButtonOptions read FButtonOptions
write SetCatButtonOptions default [boGradientFill, boShowCaptions, boVerticalCategoryCaptions];
property Categories: TButtonCategories read FButtonCategories write SetButtonCategories;
property Color default clWindow;
property Cursor;
property DockSite;
property DoubleBuffered;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property Font;
property GradientDirection: TGradientDirection read FGradientDirection write SetGradientDirection default gdHorizontal;
property Height default 100;
property HotButtonColor: TColor read FHotButtonColor write SetHotButtonColor default $00EFD3C6;
property Images: TCustomImageList read FImages write SetImages;
property ParentDoubleBuffered;
property PopupMenu;
property RegularButtonColor: TColor read FRegularButtonColor write SetRegularButtonColor nodefault;
property SelectedButtonColor: TColor read FSelectedButtonColor write SetSelectedButtonColor nodefault;
property ShowHint;
property TabOrder;
property TabStop default True;
property Touch;
property Visible;
property StyleElements;
property Width default 100;
property OnAlignInsertBefore;
property OnAlignPosition;
property OnAfterDrawButton: TCatButtonDrawEvent read FOnAfterDrawButton write FOnAfterDrawButton;
property OnBeforeDrawButton: TCatButtonDrawEvent read FOnBeforeDrawButton write FOnBeforeDrawButton;
property OnButtonClicked: TCatButtonEvent read FOnButtonClicked write FOnButtonClicked;
property OnCancelEdit: TCatButtonCancelEditEvent read FOnCancelEdit write FOnCancelEdit;
property OnCategoryCollapase: TCategoryCollapseEvent read FOnCategoryCollapase write FOnCategoryCollapase;
property OnCategoryClicked: TCatButtonCategoryEvent read FOnCategoryClicked write FOnCategoryClicked;
property OnClick;
property OnContextPopup;
property OnCopyButton: TCatButtonCopyEvent read FOnCopyButton write FOnCopyButton;
property OnDockDrop;
property OnDockOver;
property OnDragDrop;
property OnDragOver;
property OnDrawButton: TCatButtonDrawEvent read FOnDrawButton write SetOnDrawButton;
property OnDrawIcon: TCatButtonDrawIconEvent read FOnDrawIcon write SetOnDrawIcon;
property OnDrawText: TCatButtonDrawEvent read FOnDrawText write FOnDrawText;
property OnEditing: TCatButtonEditingEvent read FOnEditing write FOnEditing;
property OnEdited: TCatButtonEditedEvent read FOnEdited write FOnEdited;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnGesture;
property OnGetHint: TCatButtonGetHint read FOnGetHint write FOnGetHint;
property OnHotButton: TCatButtonEvent read FOnHotButton write FOnHotButton;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseActivate;
property OnMouseDown;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseMove;
property OnMouseUp;
property OnMouseWheel;
property OnMouseWheelDown;
property OnMouseWheelUp;
property OnReorderButton: TCatButtonReorderEvent read FOnReorderButton write FOnReorderButton;
property OnReorderCategory: TCategoryReorderEvent read FOnReorderCategory write FOnReorderCategory;
property OnSelectedItemChange: TCatButtonEvent read FOnSelectedButtonChange write FOnSelectedButtonChange; // This is really OnSelectedButtonChange
property OnSelectedCategoryChange: TCatButtonCategoryEvent read FOnSelectedCategoryChange write FOnSelectedCategoryChange;
property OnStartDock;
property OnStartDrag;
end;
{ TBaseItem }
TBaseItem = class(TCollectionItem)
strict private
FCaption: string;
FInterfaceData: IInterface;
protected
function GetBounds: TRect; virtual; abstract;
function IsCaptionStored: Boolean; virtual;
procedure SetCaption(const Value: string);
protected // friend
function GetFirstSibling: TBaseItem;
function GetLastSibling: TBaseItem;
function GetNextSibling(Distance: Integer = 1): TBaseItem;
function GetPrevSibling(Distance: Integer = 1): TBaseItem;
public
function EditText: Boolean;
procedure EndEdit(Cancel: Boolean);
procedure ScrollIntoView; virtual; abstract;
property Bounds: TRect read GetBounds;
property InterfaceData: IInterface read FInterfaceData write FInterfaceData;
property Caption: string read FCaption write SetCaption stored IsCaptionStored;
end;
{ TBaseButtonItem }
TBaseButtonItem = class(TBaseItem)
strict private
FActionLink: TButtonItemActionLink;
FImageIndex: {$IFDEF isVER230}System.UITypes.TImageIndex{$ELSE}TImageIndex{$ENDIF};
FData: TCustomData;
FHint: string;
FOnClick: TNotifyEvent;
protected
procedure ActionChange(Sender: TObject; CheckDefaults: Boolean); virtual;
procedure DoActionChange(Sender: TObject);
function GetAction: TBasicAction;
function GetActionLinkClass: TButtonItemActionLinkClass; virtual;
function GetBounds: TRect; override;
function GetDisplayName: string; override;
function GetNotifyTarget: TComponent; virtual; abstract;
function IsCaptionStored: Boolean; override;
function IsHintStored: Boolean;
function IsImageIndexStored: Boolean;
function IsOnClickStored: Boolean;
procedure SetAction(const Value: TBasicAction);
procedure SetImageIndex(const Value: {$IFDEF isVER230}System.UITypes.TImageIndex{$ELSE}TImageIndex{$ENDIF});
public
constructor Create(Collection: TCollection); override;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
property ActionLink: TButtonItemActionLink read FActionLink write FActionLink;
property Data: TCustomData read FData write FData;
published
property Action: TBasicAction read GetAction write SetAction;
property Caption;
property Hint: string read FHint write FHint stored IsHintStored;
property ImageIndex: {$IFDEF isVER230}System.UITypes.TImageIndex{$ELSE}TImageIndex{$ENDIF} read FImageIndex write SetImageIndex stored IsImageIndexStored;
property OnClick: TNotifyEvent read FOnClick write FOnClick stored IsOnClickStored;
end;
{ TButtonItem }
TButtonItem = class(TBaseButtonItem)
protected
function GetBounds: TRect; override;
function GetCategory: TButtonCategory;
function GetCategoryButtons: TCategoryButtons;
function GetNotifyTarget: TComponent; override;
public
procedure Assign(Source: TPersistent); override;
procedure ScrollIntoView; override;
property Category: TButtonCategory read GetCategory;
published
property CategoryButtons: TCategoryButtons read GetCategoryButtons;
end;
{ TItemCollection}
TItemCollection = class(TCollection)
strict private
FCategoryButtons: TCategoryButtons;
strict protected
procedure Notify(Item: TCollectionItem; Action: TCollectionNotification); override;
public
constructor Create(const ACategoryButtons: TCategoryButtons;
const ItemClass: TCollectionItemClass); overload; virtual;
property CategoryButtons: TCategoryButtons read FCategoryButtons;
end;
{ TButtonCollection }
TButtonCollection = class(TItemCollection)
strict private
FCategory: TButtonCategory;
protected
function GetItem(Index: Integer): TButtonItem;
function GetOwner: TPersistent; override;
procedure SetItem(Index: Integer; const Value: TButtonItem);
procedure Update(Item: TCollectionItem); override;
public
constructor Create(const ACategory: TButtonCategory);
function Add: TButtonItem;
function AddItem(Item: TButtonItem; Index: Integer): TButtonItem;
function Insert(Index: Integer): TButtonItem;
property Category: TButtonCategory read FCategory;
property Items[Index: Integer]: TButtonItem read GetItem write SetItem; default;
end;
{ TButtonCategory }
TButtonCategory = class(TBaseItem)
strict private
FCollapsed: Boolean;
FColor: TColor;
FGradientColor: TColor;
FTextColor: TColor;
FItems: TButtonCollection;
{ Information for caching drawing state }
FStart: Integer;
FEnd: Integer;
FData: TCustomData;
protected
function GetBounds: TRect; override;
function GetCategories: TButtonCategories;
function GetCategoryButtons: TCategoryButtons;
procedure SetItems(const Value: TButtonCollection);
procedure SetCollapsed(const Value: Boolean);
procedure SetColor(const Value: TColor);
procedure SetGradientColor(const Value: TColor);
procedure SetIndex(Value: Integer); override;
procedure SetTextColor(const Value: TColor);
protected // friend
property StartOffset: Integer read FStart write FStart;
property EndOffset: Integer read FEnd write FEnd;
public
constructor Create(Collection: TCollection); override;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
function GetButtonRect(ButtonOnly: Boolean): TRect;
function IndexOf(const Caption: string): Integer;
procedure ScrollIntoView; override;
property Categories: TButtonCategories read GetCategories;
property Bounds: TRect read GetBounds;
property Data: TCustomData read FData write FData;
published
property Caption;
property CategoryButtons: TCategoryButtons read GetCategoryButtons;
property Color: TColor read FColor write SetColor;
property Collapsed: Boolean read FCollapsed write SetCollapsed;
property GradientColor: TColor read FGradientColor write SetGradientColor default clNone;
property Items: TButtonCollection read FItems write SetItems;
property TextColor: TColor read FTextColor write SetTextColor default clWindowText;
end;
{ TButtonCategories }
TButtonCategories = class(TItemCollection)
strict private
FOriginalID: Integer;
protected
function GetItem(Index: Integer): TButtonCategory;
function GetOwner: TPersistent; override;
function GetUpdateCount: Integer;
function GetVisibleCount: Integer;
procedure SetItem(Index: Integer; const Value: TButtonCategory);
procedure Update(Item: TCollectionItem); override;
property UpdateCount: Integer read GetUpdateCount;
public
constructor Create(const CategoryButtons: TCategoryButtons); overload; virtual;
function Add: TButtonCategory;
function AddItem(Item: TButtonCategory; Index: Integer): TButtonCategory;
procedure BeginUpdate; override;
function IndexOf(const Caption: string): Integer;
function Insert(Index: Integer): TButtonCategory;
function ItemAt(const Index: Integer): TBaseItem;
function ItemIndex(const Caption: string): Integer;
property Items[Index: Integer]: TButtonCategory read GetItem write SetItem; default;
property VisibleCount: Integer read GetVisibleCount;
end;
{ TButtonItemActionLink }
TButtonItemActionLink = class(TActionLink)
strict private
FClient: TBaseButtonItem;
protected
procedure AssignClient(AClient: TObject); override;
function IsCaptionLinked: Boolean; override;
function IsHintLinked: Boolean; override;
function IsImageIndexLinked: Boolean; override;
function IsOnExecuteLinked: Boolean; override;
procedure SetCaption(const Value: string); override;
procedure SetHint(const Value: string); override;
procedure SetImageIndex(Value: Integer); override;
procedure SetOnExecute(Value: TNotifyEvent); override;
public
function DoShowHint(var HintStr: string): Boolean; virtual;
end;
implementation
uses
{$IF DEFINED(CLR)}
System.Runtime.InteropServices, System.Security.Permissions, System.Threading,
{$ENDIF} System.SysUtils, System.Types;
{$R dsCategoryButtons.res} { Contains the Copy DragCursor }
type
{ TInplaceEdit }
TInplaceEdit = class(TCustomEdit)
private
FItem: TBaseItem;
FCategoryButtons: TCategoryButtons;
procedure CNKeydown(var Message: TWMKeyDown); message CN_KEYDOWN;
protected
procedure DblClick; override;
procedure DeActivate;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure KeyPress(var Key: Char); override;
procedure KeyUp(var Key: Word; Shift: TShiftState); override;
procedure BoundsChanged; virtual;
procedure WndProc(var Message: TMessage); override;
property CategoryButtons: TCategoryButtons read FCategoryButtons;
public
constructor Create(AOwner: TComponent); override;
procedure Initialize(const AItem: TBaseItem; const ABounds: TRect;
AColor: TColor; const AText: string);
property Item: TBaseItem read FItem;
end;
constructor TInplaceEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FCategoryButtons := AOwner as TCategoryButtons;
Parent := FCategoryButtons;
ParentCtl3D := False;
Ctl3D := False;
TabStop := False;
BorderStyle := bsNone;
DoubleBuffered := False;
end;
procedure TInplaceEdit.Initialize(const AItem: TBaseItem; const ABounds: TRect;
AColor: TColor; const AText: string);
begin
FItem := AItem;
if AItem is TButtonItem then
BorderStyle := bsSingle;
with ABounds do
SetWindowPos(Handle, HWND_TOP, Left, Top, Right - Left, Bottom - Top,
SWP_SHOWWINDOW or SWP_NOREDRAW);
BoundsChanged;
if CategoryButtons.Focused then
Winapi.Windows.SetFocus(Handle);
Color := AColor;
Text := AText;
SelectAll;
end;
procedure TInplaceEdit.CNKeydown(var Message: TWMKeyDown);
begin
inherited;
case Message.CharCode of
VK_ESCAPE, VK_RETURN:
CategoryButtons.Dispatch(Message);
end;
end;
procedure TInplaceEdit.DblClick;
begin
CategoryButtons.DblClick;
end;
procedure TInplaceEdit.DeActivate;
begin
Hide;
DestroyHandle;
end;
procedure TInplaceEdit.KeyDown(var Key: Word; Shift: TShiftState);
begin
CategoryButtons.KeyDown(Key, Shift);
end;
procedure TInplaceEdit.KeyPress(var Key: Char);
begin
CategoryButtons.KeyPress(Key);
end;
procedure TInplaceEdit.KeyUp(var Key: Word; Shift: TShiftState);
begin
CategoryButtons.KeyUp(Key, Shift);
end;
procedure TInplaceEdit.WndProc(var Message: TMessage);
begin
case Message.Msg of
WM_SETFOCUS:
begin
if (GetParentForm(Self) = nil) or GetParentForm(Self).SetFocusedControl(CategoryButtons) then
Dispatch(Message);
Exit;
end;
WM_KILLFOCUS, WM_MOUSEWHEEL, WM_CANCELMODE:
begin
CategoryButtons.WndProc(Message);
Exit;
end;
end;
inherited WndProc(Message);
end;
procedure TInplaceEdit.BoundsChanged;
var
R: TRect;
begin
R := Rect(2, 2, Width - 2, Height);
SendStructMessage(Handle, EM_SETRECTNP, 0, R);
SendMessage(Handle, EM_SCROLLCARET, 0, 0);
end;
{ TCategoryButtons }
{$IF DEFINED(CLR)}
class constructor TCategoryButtons.Create;
var
LHandle: HCURSOR;
begin
// Add our drag/copy cursor image
LHandle := LoadCursor(HInstance, 'CAT_DRAG_COPY'); // Do not localize
FCursorHandle := TSafeCursorHandle.Create(LHandle);
Screen.Cursors[crDragCopy] := LHandle;
end;
{$ENDIF}
class constructor TCategoryButtons.Create;
begin
TCustomStyleEngine.RegisterStyleHook(TCategoryButtons, TScrollingStyleHook);
end;
constructor TCategoryButtons.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Width := 100;
Height := 100;
ControlStyle := [csDoubleClicks, csCaptureMouse, csDisplayDragImage, csClickEvents, csPannable];
FButtonCategories := GetButtonCategoriesClass.Create(Self);
FGlyphOpacity := 255;
FArrowShadow := clBlack;
FArrowColor := clBtnFace;
FExpandGlyph:=TImage.Create(self);
FExpandGlyph.Transparent := True;
FExpandGlyph.Center := False;
FExpandGlyph.Stretch := True;
FExpandGlyph.Proportional := True;
FCollapseGlyph:=TImage.Create(self);
FCollapseGlyph.Transparent := True;
FCollapseGlyph.Stretch := True;
FCollapseGlyph.Proportional := True;
FCollapseGlyph.Center := False;
FBorderStyle := bsSingle;
FButtonWidth := 24;
FButtonHeight := 24;
FGradientDirection := gdHorizontal;
FImageChangeLink := TChangeLink.Create;
FImageChangeLink.OnChange := ImageListChange;
FDoubleBuffered := True;
FDragImageList := TDragImageList.Create(nil);
FButtonOptions := [boGradientFill, boShowCaptions, boVerticalCategoryCaptions];
FHotButtonColor := $00EFD3C6;
FSelectedButtonColor := GetShadowColor(clBtnFace, -10);
FRegularButtonColor := GetHighlightColor(clBtnFace, 15);
FBackgroundGradientColor := clNone;
TabStop := True;
Color := clWindow;
Touch.InteractiveGestures := [igPan, igPressAndTap];
Touch.InteractiveGestureOptions := [igoPanInertia,
igoPanSingleFingerHorizontal, igoPanSingleFingerVertical,
igoPanGutter, igoParentPassthrough];
end;
class destructor TCategoryButtons.Destroy;
begin
TCustomStyleEngine.UnRegisterStyleHook(TCategoryButtons, TScrollingStyleHook);
end;
destructor TCategoryButtons.Destroy;
begin
FSelectedItem := nil;
FFocusedItem := nil;
FDownButton := nil;
FDragButton := nil;
FHotButton := nil;
FreeAndNil(FDragImageList);
FreeAndNil(FButtonCategories);
FreeAndNil(FImageChangeLink);
inherited;
end;
function TCategoryButtons.IsStyleEnabled: Boolean;
begin
Result := StyleServices.Enabled;
if Result and TStyleManager.IsCustomStyleActive and not (seClient in StyleElements) then
Result := False;
end;
procedure TCategoryButtons.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
if (FBorderStyle = bsSingle) then
begin
Params.Style := Params.Style and not WS_BORDER;
Params.ExStyle := Params.ExStyle or WS_EX_CLIENTEDGE;
end;
with Params do
WindowClass.style := WindowClass.style and not (CS_HREDRAW or CS_VREDRAW);
end;
function TCategoryButtons.GetScrollOffset: Integer;
begin
Result := FScrollBarPos * FScrollSize;
end;
function TCategoryButtons.GetButtonRect(const Item: TBaseItem): TRect;
var
ButtonsPerRow: Integer;
Row, Col: Integer;
StartingPos: Integer;
Button: TButtonItem;
CategoryBounds, ButtonBounds: TRect;
begin
if Item is TButtonItem then
begin
{ Translate the current virtual position to the actual position }
Button := Item as TButtonItem;
StartingPos := Button.Category.StartOffset - GetScrollOffset;
ButtonBounds := Rect(0,0,0,0);
GetCategoryBounds(Button.Category, StartingPos, CategoryBounds, ButtonBounds);
if not IsRectEmpty(ButtonBounds) then
begin
if FButtonFlow = cbfVertical then
ButtonsPerRow := CalcButtonsPerRow
else
ButtonsPerRow := (ButtonBounds.Right - ButtonBounds.Left) div FButtonWidth;
Row := Button.Index div ButtonsPerRow;
Result.Top := ButtonBounds.Top + Row*FButtonHeight;
if (FButtonFlow = cbfVertical) and (boFullSize in FButtonOptions) then
begin
Result.Left := ButtonBounds.Left;
Result.Right := ButtonBounds.Right;
end
else
begin
Col := Button.Index mod ButtonsPerRow;
Result.Left := ButtonBounds.Left + Col*FButtonWidth;
Result.Right := Result.Left + FButtonWidth;
end;
Result.Bottom := Result.Top + FButtonHeight;
end;
end
else
Result := Item.Bounds;
end;
procedure TCategoryButtons.ImageListChange(Sender: TObject);
begin
UpdateAllButtons;
end;
procedure TCategoryButtons.Notification(AComponent: TComponent;
Operation: TOperation);
var
I, J: Integer;
begin
inherited;
if (Operation = opRemove) then
begin
if AComponent = Images then
Images := nil
else
if AComponent is TBasicAction then
for I := 0 to FButtonCategories.Count - 1 do
for J := 0 to FButtonCategories[I].Items.Count - 1 do
if AComponent = FButtonCategories[I].Items[J].Action then
FButtonCategories[I].Items[J].Action := nil;
end;
end;
const
cBorderBuffer = 5;
function TCategoryButtons.CalcCategoryHeight(const Category: TButtonCategory;
const ButtonsPerRow: Integer): Integer;
var
RowCount: Integer;
begin
if Category.Collapsed or (Category.Items = nil) or (Category.Items.Count = 0) then
Result := FCollapsedHeight + cBorderBuffer
else
begin
RowCount := Category.Items.Count div ButtonsPerRow;
if Category.Items.Count mod ButtonsPerRow <> 0 then
Inc(RowCount);
Result := RowCount * FButtonHeight + cBorderBuffer;
if not (boVerticalCategoryCaptions in ButtonOptions) then
Result := Result + FGutterSize;
end;
end;
function TCategoryButtons.CalcCategoryWidth(const Category: TButtonCategory;
const ButtonsPerCol: Integer): Integer;
var
ColCount: Integer;
begin
if Category.Collapsed or (Category.Items = nil) or (Category.Items.Count = 0) then
Result := FCollapsedHeight + cBorderBuffer
else
begin
ColCount := Category.Items.Count div ButtonsPerCol;
if Category.Items.Count mod ButtonsPerCol <> 0 then
Inc(ColCount);
Result := ColCount * FButtonWidth + cBorderBuffer;
if boVerticalCategoryCaptions in ButtonOptions then
Result := Result + FGutterSize;
end;
end;
procedure TCategoryButtons.AdjustCategoryBounds(const Category: TButtonCategory;
var CategoryBounds: TRect; IgnoreButtonFlow: Boolean = False);
begin
// Adjust a the category bounds to collapsed dimensions (even if not collapsed)
if (IgnoreButtonFlow or (FButtonFlow = cbfVertical)) and not Category.Collapsed
and (Category.Items <> nil) and (Category.Items.Count > 0) then
begin
if (boVerticalCategoryCaptions in ButtonOptions) then
begin
CategoryBounds.Right := CategoryBounds.Left + FCollapsedHeight + cBorderBuffer;
CategoryBounds.Bottom := CategoryBounds.Bottom - 3;
end
else
CategoryBounds.Bottom := CategoryBounds.Top + FCollapsedHeight + cBorderBuffer - 2
end;
end;
procedure TCategoryButtons.GetCategoryBounds(const Category: TButtonCategory;
const StartingPos: Integer; var CategoryBounds, ButtonBounds: TRect);
var
CatHeight, CatWidth: Integer;
ButtonsPerRow, ButtonsPerCol: Integer;
XStart, YStart: Integer;
XEnd, YEnd: Integer;
begin
if FButtonFlow = cbfVertical then
begin
{ 2 Pixel buffer on each side }
XStart := 2;
XEnd := ClientWidth - 2;
ButtonsPerRow := CalcButtonsPerRow;
CatHeight := CalcCategoryHeight(Category, ButtonsPerRow);
with CategoryBounds do
begin
Left := XStart;
Top := StartingPos + 1;
Right := XEnd;
Bottom := StartingPos + CatHeight - 1;
end;
if not Category.Collapsed and (Category.Items <> nil) then
begin
if boCaptionOnlyBorder in ButtonOptions then
with CategoryBounds do
Inc(Bottom, 3);
with ButtonBounds do
begin
if boVerticalCategoryCaptions in ButtonOptions then
begin
Left := XStart + FGutterSize + cBorderBuffer;
Top := StartingPos;
end
else
begin
Left := XStart + 2;