forked from pyscripter/pyscripter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TB2Item.pas
6986 lines (6458 loc) · 224 KB
/
TB2Item.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit TB2Item;
{
Toolbar2000
Copyright (C) 1998-2008 by Jordan Russell
All rights reserved.
The contents of this file are subject to the "Toolbar2000 License"; you may
not use or distribute this file except in compliance with the
"Toolbar2000 License". A copy of the "Toolbar2000 License" may be found in
TB2k-LICENSE.txt or at:
http://www.jrsoftware.org/files/tb2k/TB2k-LICENSE.txt
Alternatively, the contents of this file may be used under the terms of the
GNU General Public License (the "GPL"), in which case the provisions of the
GPL are applicable instead of those in the "Toolbar2000 License". A copy of
the GPL may be found in GPL-LICENSE.txt or at:
http://www.jrsoftware.org/files/tb2k/GPL-LICENSE.txt
If you wish to allow use of your version of this file only under the terms of
the GPL and not to allow others to use your version of this file under the
"Toolbar2000 License", indicate your decision by deleting the provisions
above and replace them with the notice and other provisions required by the
GPL. If you do not delete the provisions above, a recipient may use your
version of this file under either the "Toolbar2000 License" or the GPL.
$jrsoftware: tb2k/Source/TB2Item.pas,v 1.313 2008/09/19 16:35:48 jr Exp $
}
interface
{$I TB2Ver.inc}
{x$DEFINE TB2K_NO_ANIMATION}
{ Enabling the above define disables all menu animation. For debugging
purpose only. }
{x$DEFINE TB2K_USE_STRICT_O2K_MENU_STYLE}
{ Enabling the above define forces it to use clBtnFace for the menu color
instead of clMenu, and disables the use of flat menu borders on Windows
XP with themes enabled. }
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
{$IFDEF CLR} TB2OleMarshal, {$ENDIF}
StdCtrls, CommCtrl, Menus, ActnList, ImgList, TB2Anim;
type
TTBCustomItem = class;
TTBCustomItemClass = class of TTBCustomItem;
TTBCustomItemActionLink = class;
TTBCustomItemActionLinkClass = class of TTBCustomItemActionLink;
TTBItemViewer = class;
TTBItemViewerClass = class of TTBItemViewer;
TTBPopupWindow = class;
TTBPopupWindowClass = class of TTBPopupWindow;
TTBView = class;
TTBDoneAction = (tbdaNone, tbdaCancel, tbdaClickItem, tbdaOpenSystemMenu,
tbdaHelpContext);
TTBDoneActionData = record
DoneAction: TTBDoneAction;
{ tbdaClickItem-specific fields: }
ClickItem: TTBCustomItem;
Sound: Boolean;
{ tbdaOpenSystemMenu-specific fields: }
Wnd: HWND;
Key: Word;
{ tbdaHelpContext-specific fields: }
ContextID: Integer;
end;
TTBInsertItemProc = procedure(AParent: TComponent; AItem: TTBCustomItem) of object;
TTBItemChangedAction = (tbicInserted, tbicDeleting, tbicSubitemsChanged,
tbicSubitemsBeginUpdate, tbicSubitemsEndUpdate, tbicInvalidate,
tbicInvalidateAndResize, tbicRecreateItemViewers, tbicNameChanged,
tbicSubMenuImagesChanged);
TTBItemChangedProc = procedure(Sender: TTBCustomItem; Relayed: Boolean;
Action: TTBItemChangedAction; Index: Integer; Item: TTBCustomItem) of object;
TTBItemDisplayMode = (nbdmDefault, nbdmTextOnly, nbdmTextOnlyInMenus, nbdmImageAndText);
TTBItemOption = (tboDefault, tboDropdownArrow, tboImageAboveCaption,
tboLongHintInMenuOnly, tboNoAutoHint, tboNoRotation, tboSameWidth,
tboShowHint, tboToolbarStyle, tboToolbarSize);
TTBItemOptions = set of TTBItemOption;
TTBItemStyle = set of (tbisSubmenu, tbisSelectable, tbisSeparator,
tbisEmbeddedGroup, tbisClicksTransparent, tbisCombo, tbisNoAutoOpen,
tbisSubitemsEditable, tbisNoLineBreak, tbisRightAlign, tbisDontSelectFirst,
tbisRedrawOnSelChange, tbisRedrawOnMouseOverChange);
TTBPopupAlignment = (tbpaLeft, tbpaRight, tbpaCenter);
TTBPopupEvent = procedure(Sender: TTBCustomItem; FromLink: Boolean) of object;
TTBSelectEvent = procedure(Sender: TTBCustomItem; Viewer: TTBItemViewer;
Selecting: Boolean) of object;
ETBItemError = class(Exception);
TTBImageChangeLink = class(TChangeLink)
private
FLastWidth, FLastHeight: Integer;
end;
{$IFNDEF JR_D5}
TImageIndex = type Integer;
{$ENDIF}
TTBCustomItem = class(TComponent)
private
FActionLink: TTBCustomItemActionLink;
FAutoCheck: Boolean;
FCaption: String;
FChecked: Boolean;
FDisplayMode: TTBItemDisplayMode;
FEnabled: Boolean;
FEffectiveOptions: TTBItemOptions;
FGroupIndex: Integer;
FHelpContext: THelpContext;
FHint: String;
FImageIndex: TImageIndex;
FImages: TCustomImageList;
FImagesChangeLink: TTBImageChangeLink;
FItems: TList;
FItemStyle: TTBItemStyle;
FLinkParents: TList;
FMaskOptions: TTBItemOptions;
FOptions: TTBItemOptions;
FInheritOptions: Boolean;
FNotifyList: TList;
FOnClick: TNotifyEvent;
FOnPopup: TTBPopupEvent;
FOnSelect: TTBSelectEvent;
FParent: TTBCustomItem;
FParentComponent: TComponent;
FRadioItem: Boolean;
FShortCut: TShortCut;
FSubMenuImages: TCustomImageList;
FSubMenuImagesChangeLink: TTBImageChangeLink;
FLinkSubitems: TTBCustomItem;
FVisible: Boolean;
procedure DoActionChange(Sender: TObject);
function ChangeImages(var AImages: TCustomImageList;
const Value: TCustomImageList; var AChangeLink: TTBImageChangeLink): Boolean;
class procedure ClickWndProc(var Message: TMessage); {$IFDEF CLR} static; {$ENDIF}
function FindItemWithShortCut(AShortCut: TShortCut;
var ATopmostParent: TTBCustomItem): TTBCustomItem;
function FixOptions(const AOptions: TTBItemOptions): TTBItemOptions;
function GetAction: TBasicAction;
function GetCount: Integer;
function GetItem(Index: Integer): TTBCustomItem;
procedure ImageListChangeHandler(Sender: TObject);
procedure InternalNotify(Ancestor: TTBCustomItem; NestingLevel: Integer;
Action: TTBItemChangedAction; Index: Integer; Item: TTBCustomItem);
{$IFDEF JR_D6}
function IsAutoCheckStored: Boolean;
{$ENDIF}
function IsCaptionStored: Boolean;
function IsCheckedStored: Boolean;
function IsEnabledStored: Boolean;
function IsHelpContextStored: Boolean;
function IsHintStored: Boolean;
function IsImageIndexStored: Boolean;
function IsOnClickStored: Boolean;
function IsShortCutStored: Boolean;
function IsVisibleStored: Boolean;
procedure Notify(Action: TTBItemChangedAction; Index: Integer; Item: TTBCustomItem);
procedure RefreshOptions;
procedure SetAction(Value: TBasicAction);
procedure SetCaption(Value: String);
procedure SetChecked(Value: Boolean);
procedure SetDisplayMode(Value: TTBItemDisplayMode);
procedure SetEnabled(Value: Boolean);
procedure SetGroupIndex(Value: Integer);
procedure SetImageIndex(Value: TImageIndex);
procedure SetImages(Value: TCustomImageList);
procedure SetInheritOptions(Value: Boolean);
procedure SetLinkSubitems(Value: TTBCustomItem);
procedure SetMaskOptions(Value: TTBItemOptions);
procedure SetOptions(Value: TTBItemOptions);
procedure SetRadioItem(Value: Boolean);
procedure SetSubMenuImages(Value: TCustomImageList);
procedure SetVisible(Value: Boolean);
procedure SubMenuImagesChanged;
procedure TurnSiblingsOff;
protected
procedure ActionChange(Sender: TObject; CheckDefaults: Boolean); dynamic;
procedure Change(NeedResize: Boolean); virtual;
function CreatePopup(const ParentView: TTBView; const ParentViewer: TTBItemViewer;
const PositionAsSubmenu, SelectFirstItem, Customizing: Boolean;
const APopupPoint: TPoint; const Alignment: TTBPopupAlignment): TTBPopupWindow; virtual;
procedure DoPopup(Sender: TTBCustomItem; FromLink: Boolean); virtual;
procedure EnabledChanged; virtual;
function GetActionLinkClass: TTBCustomItemActionLinkClass; dynamic;
function GetChevronParentView: TTBView; virtual;
procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
function GetItemViewerClass(AView: TTBView): TTBItemViewerClass; virtual;
function GetPopupWindowClass: TTBPopupWindowClass; virtual;
class procedure IndexError;
procedure Loaded; override;
function NeedToRecreateViewer(AViewer: TTBItemViewer): Boolean; virtual;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
function OpenPopup(const SelectFirstItem, TrackRightButton: Boolean;
const PopupPoint: TPoint; const Alignment: TTBPopupAlignment;
const ReturnClickedItemOnly: Boolean): TTBCustomItem;
procedure RecreateItemViewers;
procedure SetChildOrder(Child: TComponent; Order: Integer); override;
procedure SetName(const NewName: TComponentName); override;
{$IFNDEF CLR}
procedure SetParentComponent(Value: TComponent); override;
{$ENDIF}
property ActionLink: TTBCustomItemActionLink read FActionLink write FActionLink;
property ItemStyle: TTBItemStyle read FItemStyle write FItemStyle;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function HasParent: Boolean; override;
function GetParentComponent: TComponent; override;
procedure Add(AItem: TTBCustomItem);
procedure Clear;
procedure Click; virtual;
function ContainsItem(AItem: TTBCustomItem): Boolean;
procedure Delete(Index: Integer);
function GetItemStyle: TTBItemStyle;
function GetShortCutText: String;
function IndexOf(AItem: TTBCustomItem): Integer;
procedure InitiateAction; virtual;
procedure Insert(NewIndex: Integer; AItem: TTBCustomItem);
function IsShortCut(var Message: TWMKey): Boolean;
procedure Move(CurIndex, NewIndex: Integer);
function Popup(X, Y: Integer; TrackRightButton: Boolean;
Alignment: TTBPopupAlignment = tbpaLeft;
ReturnClickedItemOnly: Boolean = False): TTBCustomItem;
procedure PostClick;
procedure RegisterNotification(ANotify: TTBItemChangedProc);
procedure Remove(Item: TTBCustomItem);
{$IFDEF CLR}
procedure SetParentComponent(Value: TComponent); override;
{$ENDIF}
procedure UnregisterNotification(ANotify: TTBItemChangedProc);
procedure ViewBeginUpdate;
procedure ViewEndUpdate;
property Action: TBasicAction read GetAction write SetAction;
property AutoCheck: Boolean read FAutoCheck write FAutoCheck {$IFDEF JR_D6} stored IsAutoCheckStored {$ENDIF} default False;
property Caption: String read FCaption write SetCaption stored IsCaptionStored;
property Count: Integer read GetCount;
property Checked: Boolean read FChecked write SetChecked stored IsCheckedStored default False;
property DisplayMode: TTBItemDisplayMode read FDisplayMode write SetDisplayMode default nbdmDefault;
property EffectiveOptions: TTBItemOptions read FEffectiveOptions;
property Enabled: Boolean read FEnabled write SetEnabled stored IsEnabledStored default True;
property GroupIndex: Integer read FGroupIndex write SetGroupIndex default 0;
property HelpContext: THelpContext read FHelpContext write FHelpContext stored IsHelpContextStored default 0;
property Hint: String read FHint write FHint stored IsHintStored;
property ImageIndex: TImageIndex read FImageIndex write SetImageIndex stored IsImageIndexStored default -1;
property Images: TCustomImageList read FImages write SetImages;
property InheritOptions: Boolean read FInheritOptions write SetInheritOptions default True;
property Items[Index: Integer]: TTBCustomItem read GetItem; default;
property LinkSubitems: TTBCustomItem read FLinkSubitems write SetLinkSubitems;
property MaskOptions: TTBItemOptions read FMaskOptions write SetMaskOptions default [];
property Options: TTBItemOptions read FOptions write SetOptions default [];
property Parent: TTBCustomItem read FParent;
property ParentComponent: TComponent read FParentComponent write FParentComponent;
property RadioItem: Boolean read FRadioItem write SetRadioItem default False;
property ShortCut: TShortCut read FShortCut write FShortCut stored IsShortCutStored default 0;
property SubMenuImages: TCustomImageList read FSubMenuImages write SetSubMenuImages;
property Visible: Boolean read FVisible write SetVisible stored IsVisibleStored default True;
property OnClick: TNotifyEvent read FOnClick write FOnClick stored IsOnClickStored;
property OnPopup: TTBPopupEvent read FOnPopup write FOnPopup;
property OnSelect: TTBSelectEvent read FOnSelect write FOnSelect;
end;
TTBCustomItemActionLink = class(TActionLink)
protected
FClient: TTBCustomItem;
procedure AssignClient(AClient: TObject); override;
{$IFDEF JR_D6}
function IsAutoCheckLinked: Boolean; virtual;
{$ENDIF}
function IsCaptionLinked: Boolean; override;
function IsCheckedLinked: Boolean; override;
function IsEnabledLinked: Boolean; override;
function IsHelpContextLinked: Boolean; override;
function IsHintLinked: Boolean; override;
function IsImageIndexLinked: Boolean; override;
function IsShortCutLinked: Boolean; override;
function IsVisibleLinked: Boolean; override;
function IsOnExecuteLinked: Boolean; override;
{$IFDEF JR_D6}
procedure SetAutoCheck(Value: Boolean); override;
{$ENDIF}
procedure SetCaption(const Value: String); override;
procedure SetChecked(Value: Boolean); override;
procedure SetEnabled(Value: Boolean); override;
procedure SetHelpContext(Value: THelpContext); 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;
{$IFNDEF CLR}
TTBBaseAccObject = class(TInterfacedObject, IDispatch)
{$ELSE}
TTBBaseAccObject = class(TTBStandardOleMarshalObject)
{$ENDIF}
public
procedure ClientIsDestroying; virtual; abstract;
{$IFNDEF CLR}
{ IDispatch }
function GetTypeInfoCount(out Count: Integer): HResult; stdcall;
function GetTypeInfo(Index, LocaleID: Integer; out TypeInfo): HResult; stdcall;
function GetIDsOfNames(const IID: TGUID; Names: Pointer;
NameCount, LocaleID: Integer; DispIDs: Pointer): HResult; stdcall;
function Invoke(DispID: Integer; const IID: TGUID; LocaleID: Integer;
Flags: Word; var Params; VarResult, ExcepInfo, ArgErr: Pointer): HResult; stdcall;
{$ENDIF}
end;
TTBItemViewer = class
private
FBoundsRect: TRect;
FClipped: Boolean;
FGroupLevel: Integer;
FItem: TTBCustomItem;
FOffEdge: Boolean;
FShow: Boolean;
FView: TTBView;
procedure AccSelect(const AExecute: Boolean);
function GetIndex: Integer;
protected
FAccObjectInstance: TTBBaseAccObject;
procedure CalcSize(const Canvas: TCanvas; var AWidth, AHeight: Integer);
virtual;
function CaptionShown: Boolean; dynamic;
function DoExecute: Boolean; virtual;
procedure DrawItemCaption(const Canvas: TCanvas; ARect: TRect;
const ACaption: String; ADrawDisabledShadow: Boolean; AFormat: UINT); virtual;
procedure Entering; virtual;
function GetAccRole: Integer; virtual;
function GetAccValue(var Value: WideString): Boolean; virtual;
function GetCaptionText: String; virtual;
procedure GetCursor(const Pt: TPoint; var ACursor: HCURSOR); virtual;
function GetImageList: TCustomImageList;
function ImageShown: Boolean;
function IsRotated: Boolean;
function IsToolbarSize: Boolean;
function IsPtInButtonPart(X, Y: Integer): Boolean; virtual;
procedure KeyDown(var Key: Word; Shift: TShiftState); virtual;
procedure Leaving; virtual;
procedure LosingCapture; virtual;
procedure MouseDown(Shift: TShiftState; X, Y: Integer;
var MouseDownOnMenu: Boolean); virtual;
procedure MouseMove(X, Y: Integer); virtual;
procedure MouseUp(X, Y: Integer; MouseWasDownOnMenu: Boolean); virtual;
procedure MouseWheel(WheelDelta: Integer; X, Y: Integer); virtual;
procedure Paint(const Canvas: TCanvas; const ClientAreaRect: TRect;
IsSelected, IsPushed, UseDisabledShadow: Boolean); virtual;
procedure PostAccSelect(const AExecute: Boolean);
function UsesSameWidth: Boolean; virtual;
public
State: set of (tbisInvalidated, tbisLineSep);
property BoundsRect: TRect read FBoundsRect;
property Clipped: Boolean read FClipped;
property Index: Integer read GetIndex;
property Item: TTBCustomItem read FItem;
property OffEdge: Boolean read FOffEdge;
property Show: Boolean read FShow;
property View: TTBView read FView;
constructor Create(AView: TTBView; AItem: TTBCustomItem; AGroupLevel: Integer); virtual;
destructor Destroy; override;
procedure Execute(AGivePriority: Boolean);
function GetAccObject: TTBBaseAccObject;
function GetHintText: String;
function IsAccessible: Boolean;
function IsToolbarStyle: Boolean;
function ScreenToClient(const P: TPoint): TPoint;
end;
TTBViewOrientation = (tbvoHorizontal, tbvoVertical, tbvoFloating);
TTBEnterToolbarLoopOptions = set of (tbetMouseDown, tbetExecuteSelected,
tbetFromMSAA);
TTBViewState = set of (vsModal, vsMouseInWindow, vsDrawInOrder, vsOppositePopup,
vsIgnoreFirstMouseUp, vsShowAccels, vsDropDownMenus, vsNoAnimation);
TTBViewStyle = set of (vsMenuBar, vsUseHiddenAccels, vsAlwaysShowHints);
TTBViewTimerID = (tiOpen, tiClose, tiScrollUp, tiScrollDown);
TTBViewClass = class of TTBView;
TTBView = class(TComponent)
private
FViewers: TList; { at front to minimize code size }
FActiveTimers: set of TTBViewTimerID;
FBackgroundColor: TColor;
FBaseSize: TPoint;
FCapture: Boolean;
FCaptureWnd: HWND;
FChevronOffset: Integer;
FChevronParentView: TTBView;
FChevronSize: Integer;
FCurParentItem: TTBCustomItem;
FCustomizing: Boolean;
FDoneActionData: TTBDoneActionData;
FInternalViewersAtEnd: Integer;
FInternalViewersAtFront: Integer;
FIsPopup: Boolean;
FIsToolbar: Boolean;
FMaxHeight: Integer;
FMonitorRect: TRect;
FMouseOverSelected: Boolean;
FNewViewersGetHighestPriority: Boolean;
FOpenViewer: TTBItemViewer;
FOpenViewerView: TTBView;
FOpenViewerWindow: TTBPopupWindow;
FParentView: TTBView;
FParentItem: TTBCustomItem;
FPriorityList: TList;
FOrientation: TTBViewOrientation;
FScrollOffset: Integer;
FSelected: TTBItemViewer;
FSelectedViaMouse: Boolean;
FShowDownArrow: Boolean;
FShowUpArrow: Boolean;
FState: TTBViewState;
FStyle: TTBViewStyle;
FUpdating: Integer;
FUsePriorityList: Boolean;
FValidated: Boolean;
FWindow: TWinControl;
FWrapOffset: Integer;
procedure DeletingViewer(Viewer: TTBItemViewer);
procedure DrawItem(Viewer: TTBItemViewer; DrawTo: TCanvas; Offscreen: Boolean);
procedure FreeViewers;
function GetViewer(Index: Integer): TTBItemViewer;
function GetViewerCount: Integer; {$IFDEF JR_D9} inline; {$ENDIF}
procedure ImagesChanged;
function InsertItemViewers(const NewIndex: Integer;
const AItem: TTBCustomItem; const AGroupLevel: Integer;
const AddToPriorityList, TopOfPriorityList: Boolean): Integer;
procedure ItemNotification(Ancestor: TTBCustomItem; Relayed: Boolean;
Action: TTBItemChangedAction; Index: Integer; Item: TTBCustomItem);
procedure LinkNotification(Ancestor: TTBCustomItem; Relayed: Boolean;
Action: TTBItemChangedAction; Index: Integer; Item: TTBCustomItem);
procedure RecreateItemViewer(const I: Integer);
procedure Scroll(ADown: Boolean);
procedure SetCustomizing(Value: Boolean);
procedure SetSelected(Value: TTBItemViewer);
procedure SetUsePriorityList(Value: Boolean);
procedure StartTimer(const ATimer: TTBViewTimerID; const Interval: Integer);
procedure StopAllTimers;
procedure StopTimer(const ATimer: TTBViewTimerID);
procedure UpdateCurParentItem;
protected
FAccObjectInstance: TTBBaseAccObject;
procedure AutoSize(AWidth, AHeight: Integer); virtual;
function CalculatePositions(const CanMoveControls: Boolean;
const AOrientation: TTBViewOrientation;
AWrapOffset, AChevronOffset, AChevronSize: Integer;
var ABaseSize, TotalSize: TPoint;
var AWrappedLines: Integer): Boolean;
procedure DoUpdatePositions(var ASize: TPoint); virtual;
function GetChevronItem: TTBCustomItem; virtual;
procedure GetMargins(AOrientation: TTBViewOrientation; var Margins: TRect);
virtual;
function GetMDIButtonsItem: TTBCustomItem; virtual;
function GetMDISystemMenuItem: TTBCustomItem; virtual;
function GetParentToolbarView: TTBView;
function GetRootView: TTBView;
function HandleWMGetObject(var Message: TMessage): Boolean;
procedure InitiateActions;
procedure KeyDown(var Key: Word; Shift: TShiftState); virtual;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
procedure SetAccelsVisibility(AShowAccels: Boolean);
public
constructor Create(AOwner: TComponent; AParentView: TTBView;
AParentItem: TTBCustomItem; AWindow: TWinControl;
AIsToolbar, ACustomizing, AUsePriorityList: Boolean); reintroduce; virtual;
destructor Destroy; override;
procedure BeginUpdate;
procedure CancelCapture;
procedure CancelChildPopups;
procedure CancelMode;
procedure CloseChildPopups;
function ContainsView(AView: TTBView): Boolean;
procedure DrawSubitems(ACanvas: TCanvas);
procedure EndModal;
procedure EndModalWithClick(AViewer: TTBItemViewer);
procedure EndModalWithHelp(AContextID: Integer);
procedure EndModalWithSystemMenu(AWnd: HWND; AKey: Word);
procedure EndUpdate;
procedure EnterToolbarLoop(Options: TTBEnterToolbarLoopOptions);
procedure ExecuteSelected(AGivePriority: Boolean);
function Find(Item: TTBCustomItem): TTBItemViewer;
function FirstSelectable: TTBItemViewer;
function GetAccObject: TTBBaseAccObject;
function GetCaptureWnd: HWND;
function GetFont: TFont; virtual;
procedure GetOffEdgeControlList(const List: TList);
procedure GivePriority(AViewer: TTBItemViewer);
procedure HandleHintShowMessage(var Message: TCMHintShow);
function HighestPriorityViewer: TTBItemViewer;
procedure Invalidate(AViewer: TTBItemViewer);
procedure InvalidatePositions; virtual;
function IndexOf(AViewer: TTBItemViewer): Integer;
function IsModalEnding: Boolean;
function NextSelectable(CurViewer: TTBItemViewer; GoForward: Boolean): TTBItemViewer;
function NextSelectableWithAccel(CurViewer: TTBItemViewer; Key: Char;
RequirePrimaryAccel: Boolean; var IsOnlyItemWithAccel: Boolean): TTBItemViewer;
procedure NotifyFocusEvent;
function OpenChildPopup(const SelectFirstItem: Boolean): Boolean;
procedure RecreateAllViewers;
procedure ScrollSelectedIntoView;
procedure Select(Value: TTBItemViewer; ViaMouse: Boolean);
procedure SetCapture;
procedure TryValidatePositions;
procedure UpdateSelection(const P: TPoint; const AllowNewSelection: Boolean);
function UpdatePositions: TPoint;
procedure ValidatePositions;
function ViewerFromPoint(const P: TPoint): TTBItemViewer;
property BackgroundColor: TColor read FBackgroundColor write FBackgroundColor;
property BaseSize: TPoint read FBaseSize;
property Capture: Boolean read FCapture;
property ChevronOffset: Integer read FChevronOffset write FChevronOffset;
property ChevronSize: Integer read FChevronSize write FChevronSize;
property Customizing: Boolean read FCustomizing write SetCustomizing;
property IsPopup: Boolean read FIsPopup;
property IsToolbar: Boolean read FIsToolbar;
property MouseOverSelected: Boolean read FMouseOverSelected;
property NewViewersGetHighestPriority: Boolean read FNewViewersGetHighestPriority
write FNewViewersGetHighestPriority;
property ParentView: TTBView read FParentView;
property ParentItem: TTBCustomItem read FParentItem;
property OpenViewer: TTBItemViewer read FOpenViewer;
property OpenViewerView: TTBView read FOpenViewerView;
property Orientation: TTBViewOrientation read FOrientation write FOrientation;
property Selected: TTBItemViewer read FSelected write SetSelected;
property SelectedViaMouse: Boolean read FSelectedViaMouse;
property State: TTBViewState read FState;
property Style: TTBViewStyle read FStyle write FStyle;
property UsePriorityList: Boolean read FUsePriorityList write SetUsePriorityList;
property Viewers[Index: Integer]: TTBItemViewer read GetViewer;
property ViewerCount: Integer read GetViewerCount;
property Window: TWinControl read FWindow;
property WrapOffset: Integer read FWrapOffset write FWrapOffset;
end;
TTBRootItemClass = class of TTBRootItem;
TTBRootItem = class(TTBCustomItem);
{ same as TTBCustomItem, except there's a property editor for it }
TTBItem = class(TTBCustomItem)
published
property Action;
property AutoCheck;
property Caption;
property Checked;
property DisplayMode;
property Enabled;
property GroupIndex;
property HelpContext;
property Hint;
property ImageIndex;
property Images;
property InheritOptions;
property MaskOptions;
property Options;
property RadioItem;
property ShortCut;
property Visible;
property OnClick;
property OnSelect;
end;
TTBGroupItem = class(TTBCustomItem)
public
constructor Create(AOwner: TComponent); override;
published
property InheritOptions;
property LinkSubitems;
property MaskOptions;
property Options;
end;
TTBSubmenuItem = class(TTBCustomItem)
private
function GetDropdownCombo: Boolean;
procedure SetDropdownCombo(Value: Boolean);
public
constructor Create(AOwner: TComponent); override;
published
property Action;
property AutoCheck;
property Caption;
property Checked;
//property DisplayAsToolbar;
property DisplayMode;
property DropdownCombo: Boolean read GetDropdownCombo write SetDropdownCombo default False;
property Enabled;
property GroupIndex;
property HelpContext;
property Hint;
property ImageIndex;
property Images;
property InheritOptions;
property LinkSubitems;
property MaskOptions;
property Options;
property RadioItem;
property ShortCut;
property SubMenuImages;
property Visible;
property OnClick;
property OnPopup;
property OnSelect;
end;
TTBSeparatorItem = class(TTBCustomItem)
private
FBlank: Boolean;
procedure SetBlank(Value: Boolean);
protected
function GetItemViewerClass(AView: TTBView): TTBItemViewerClass; override;
public
constructor Create(AOwner: TComponent); override;
published
property Blank: Boolean read FBlank write SetBlank default False;
property Hint;
property Visible;
end;
TTBSeparatorItemViewer = class(TTBItemViewer)
protected
procedure CalcSize(const Canvas: TCanvas;
var AWidth, AHeight: Integer); override;
procedure Paint(const Canvas: TCanvas; const ClientAreaRect: TRect;
IsSelected, IsPushed, UseDisabledShadow: Boolean); override;
function UsesSameWidth: Boolean; override;
end;
TTBControlItem = class(TTBCustomItem)
private
FControl: TControl;
FDontFreeControl: Boolean;
procedure SetControl(Value: TControl);
protected
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
property DontFreeControl: Boolean read FDontFreeControl write FDontFreeControl;
published
property Control: TControl read FControl write SetControl;
end;
TTBPopupView = class(TTBView)
protected
procedure AutoSize(AWidth, AHeight: Integer); override;
public
function GetFont: TFont; override;
end;
ITBPopupWindow = interface
['{E45CBE74-1ECF-44CB-B064-6D45B1924708}']
end;
TTBPopupWindow = class(TCustomControl, ITBPopupWindow)
private
FAccelsVisibilitySet: Boolean;
FAnimationDirection: TTBAnimationDirection;
FView: TTBView;
procedure CMHintShow(var Message: TCMHintShow); message CM_HINTSHOW;
procedure CMShowingChanged(var Message: TMessage); message CM_SHOWINGCHANGED;
procedure WMClose(var Message: TWMClose); message WM_CLOSE;
procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND;
procedure WMGetObject(var Message: TMessage); message WM_GETOBJECT;
procedure WMNCCalcSize(var Message: TWMNCCalcSize); message WM_NCCALCSIZE;
procedure WMNCPaint(var Message: TMessage); message WM_NCPAINT;
procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
procedure WMPrint(var Message: TMessage); message WM_PRINT;
procedure WMPrintClient(var Message: {$IFNDEF CLR} TMessage {$ELSE} TWMPrintClient {$ENDIF}); message WM_PRINTCLIENT;
protected
procedure CreateParams(var Params: TCreateParams); override;
procedure CreateWnd; override;
procedure DestroyWindowHandle; override;
function GetViewClass: TTBViewClass; dynamic;
procedure Paint; override;
procedure PaintScrollArrows; virtual;
public
constructor CreatePopupWindow(AOwner: TComponent; const AParentView: TTBView;
const AItem: TTBCustomItem; const ACustomizing: Boolean); virtual;
destructor Destroy; override;
property View: TTBView read FView;
end;
ITBItems = interface
['{A5C0D7CC-3EC4-4090-A0F8-3D03271877EA}']
function GetItems: TTBCustomItem;
end;
TTBItemContainer = class(TComponent, ITBItems)
private
FItem: TTBRootItem;
function GetImages: TCustomImageList;
function GetItems: TTBCustomItem;
procedure SetImages(Value: TCustomImageList);
protected
procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
property Items: TTBRootItem read FItem;
published
property Images: TCustomImageList read GetImages write SetImages;
end;
TTBPopupMenu = class(TPopupMenu, ITBItems)
private
FItem: TTBRootItem;
//procedure SetItems(Value: TTBCustomItem);
function GetImages: TCustomImageList;
function GetItems: TTBCustomItem;
function GetLinkSubitems: TTBCustomItem;
function GetOptions: TTBItemOptions;
procedure RootItemClick(Sender: TObject);
procedure SetImages(Value: TCustomImageList);
procedure SetLinkSubitems(Value: TTBCustomItem);
procedure SetOptions(Value: TTBItemOptions);
protected
{$IFNDEF JR_D5}
procedure DoPopup(Sender: TObject);
{$ENDIF}
function GetRootItemClass: TTBRootItemClass; dynamic;
procedure SetChildOrder(Child: TComponent; Order: Integer); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
function IsShortCut(var Message: TWMKey): Boolean; override;
procedure Popup(X, Y: Integer); override;
function PopupEx(X, Y: Integer; ReturnClickedItemOnly: Boolean = False): TTBCustomItem;
published
property Images: TCustomImageList read GetImages write SetImages;
property Items: TTBRootItem read FItem;
property LinkSubitems: TTBCustomItem read GetLinkSubitems write SetLinkSubitems;
property Options: TTBItemOptions read GetOptions write SetOptions default [];
end;
TTBCustomImageList = class(TImageList)
private
FCheckedImages: TCustomImageList;
FCheckedImagesChangeLink: TChangeLink;
FDisabledImages: TCustomImageList;
FDisabledImagesChangeLink: TChangeLink;
FHotImages: TCustomImageList;
FHotImagesChangeLink: TChangeLink;
FImagesBitmap: TBitmap;
FImagesBitmapMaskColor: TColor;
procedure ChangeImages(var AImageList: TCustomImageList;
Value: TCustomImageList; AChangeLink: TChangeLink);
procedure ImageListChanged(Sender: TObject);
procedure ImagesBitmapChanged(Sender: TObject);
procedure SetCheckedImages(Value: TCustomImageList);
procedure SetDisabledImages(Value: TCustomImageList);
procedure SetHotImages(Value: TCustomImageList);
procedure SetImagesBitmap(Value: TBitmap);
procedure SetImagesBitmapMaskColor(Value: TColor);
{$IFDEF CLR}
procedure WriteLeft(Writer: TWriter);
procedure WriteTop(Writer: TWriter);
{$ENDIF}
protected
procedure DefineProperties(Filer: TFiler); override;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
property CheckedImages: TCustomImageList read FCheckedImages write SetCheckedImages;
property DisabledImages: TCustomImageList read FDisabledImages write SetDisabledImages;
property HotImages: TCustomImageList read FHotImages write SetHotImages;
property ImagesBitmap: TBitmap read FImagesBitmap write SetImagesBitmap;
property ImagesBitmapMaskColor: TColor read FImagesBitmapMaskColor
write SetImagesBitmapMaskColor default clFuchsia;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure DrawState(Canvas: TCanvas; X, Y, Index: Integer;
Enabled, Selected, Checked: Boolean); virtual;
end;
TTBImageList = class(TTBCustomImageList)
published
property CheckedImages;
property DisabledImages;
property HotImages;
property ImagesBitmap;
property ImagesBitmapMaskColor;
end;
const
{$IFNDEF TB2K_USE_STRICT_O2K_MENU_STYLE}
tbMenuBkColor = clMenu;
tbMenuTextColor = clMenuText;
{$ELSE}
tbMenuBkColor = clBtnFace;
tbMenuTextColor = clBtnText;
{$ENDIF}
tbMenuVerticalMargin = 4;
tbMenuImageTextSpace = 1;
tbMenuLeftTextMargin = 2;
tbMenuRightTextMargin = 3;
tbMenuSeparatorOffset = 12;
tbMenuScrollArrowHeight = 19;
tbDropdownArrowWidth = 8;
tbDropdownArrowMargin = 3;
tbDropdownComboArrowWidth = 11;
tbDropdownComboMargin = 2;
tbLineSpacing = 6;
tbLineSepOffset = 1;
tbDockedLineSepOffset = 4;
WM_TB2K_CLICKITEM = WM_USER + $100;
function TBGetItems(const AObject: TObject): TTBCustomItem;
procedure TBInitToolbarSystemFont;
var
ToolbarFont: TFont;
implementation
uses
{$IFDEF CLR} System.Runtime.InteropServices, System.Text, System.Threading,
Types, WinUtils, {$ENDIF}
TB2Consts, TB2Common, IMM, TB2Acc, TB2Toolbar;
{$UNDEF ALLOCHWND_CLASSES}
{$IFNDEF CLR}
{$IFDEF JR_D6}
{$DEFINE ALLOCHWND_CLASSES}
{$ENDIF}
{$ENDIF}
var
LastPos: TPoint;
threadvar
ClickWndRefCount: Integer;
ClickWnd: HWND;
ClickList: TList;
type
TTBModalHandler = class
private
FCreatedWnd: Boolean;
FInited: Boolean;
FWnd: HWND;
FRootPopup: TTBPopupWindow;
FSaveFocusWnd: HWND;
procedure WndProc(var Msg: TMessage);
public
constructor Create(AExistingWnd: HWND);
destructor Destroy; override;
procedure Loop(const RootView: TTBView; const AMouseDown, AExecuteSelected,
AFromMSAA, TrackRightButton: Boolean);
property RootPopup: TTBPopupWindow read FRootPopup write FRootPopup;
property Wnd: HWND read FWnd;
end;
TItemChangedNotificationData = class
private
Proc: TTBItemChangedProc;
RefCount: Integer;
end;
{$IFNDEF CLR}
TComponentAccess = class(TComponent);
TControlAccess = class(TControl);
{$ENDIF}
const
ViewTimerBaseID = 9000;
MaxGroupLevel = 10;
{ Misc. }
function TBGetItems(const AObject: TObject): TTBCustomItem;
{ If AObject is an item, returns AObject, otherwise finds the root item
associated with AObject. If AObject is not a TTBCustomItem and does not
implement the ITBItems interface, nil is returned. }
var
Intf: ITBItems;
begin
if AObject is TTBCustomItem then
Result := TTBCustomItem(AObject)
else begin
{$IFNDEF CLR}
if AObject.GetInterface(ITBItems, Intf) then
{$ELSE}
Intf := ITBItems(AObject);
if Assigned(Intf) then
{$ENDIF}
Result := Intf.GetItems
else
Result := nil;
end;
end;
procedure DestroyClickWnd;
begin
if ClickWnd <> 0 then begin
{$IFDEF ALLOCHWND_CLASSES}Classes.{$ENDIF} DeallocateHWnd(ClickWnd);
ClickWnd := 0;
end;
FreeAndNil(ClickList);
end;
procedure ReferenceClickWnd;
begin
Inc(ClickWndRefCount);
end;
procedure ReleaseClickWnd;
begin
Dec(ClickWndRefCount);
if ClickWndRefCount = 0 then
DestroyClickWnd;
end;
procedure QueueClick(const AItem: TObject; const AArg: Integer);
{ Adds an item to ClickList and posts a message to handle it. AItem must be
either a TTBCustomItem or TTBItemViewer. }
var
I: Integer;
begin
if ClickWnd = 0 then
ClickWnd := {$IFDEF ALLOCHWND_CLASSES}Classes.{$ENDIF} AllocateHWnd(TTBCustomItem.ClickWndProc);
if ClickList = nil then
ClickList := TList.Create;
{ Add a new item to ClickList or replace an empty one }
I := ClickList.IndexOf(nil);
if I = -1 then
I := ClickList.Add(AItem)
else
ClickList[I] := AItem;
PostMessage(ClickWnd, WM_TB2K_CLICKITEM, AArg, I);
end;
procedure RemoveFromClickList(const AItem: TObject);
{ Any class that potentially calls QueueClick needs to call RemoveFromClickList
before an instance is destroyed to ensure that any references to the
instance still in ClickList are removed. }
var
I: Integer;
begin
if Assigned(ClickList) and Assigned(AItem) then
for I := 0 to ClickList.Count-1 do
if ClickList[I] = AItem then
ClickList[I] := ClickList;
{ ^ The special value of ClickList is assigned to the item instead of
of nil because we want the index to stay reserved until the
WM_TB2K_CLICKITEM message for the index is processed. We don't want
the WM_TB2K_CLICKITEM message that's still in the queue to later
refer to a different item; this would result in queued clicks being
processed in the wrong order in a case like this:
A.PostClick; B.PostClick; A.Free; C.PostClick;
C's click would end up being processed before A's, because C would
get A's index. }
end;
function ProcessDoneAction(const DoneActionData: TTBDoneActionData;
const ReturnClickedItemOnly: Boolean): TTBCustomItem;
begin
Result := nil;
case DoneActionData.DoneAction of
tbdaNone: ;
tbdaClickItem: begin
if DoneActionData.Sound and NeedToPlaySound('MenuCommand') then
PlaySystemSound('MenuCommand');
Result := DoneActionData.ClickItem;
if not ReturnClickedItemOnly then
Result.PostClick;
end;
tbdaOpenSystemMenu: begin
SendMessage(DoneActionData.Wnd, WM_SYSCOMMAND, SC_KEYMENU, DoneActionData.Key);
end;
tbdaHelpContext: begin
{ Based on code in TPopupList.WndProc: }
if Assigned(Screen.ActiveForm) and
(biHelp in Screen.ActiveForm.BorderIcons) then
Application.HelpCommand(HELP_CONTEXTPOPUP, DoneActionData.ContextID)
else
Application.HelpContext(DoneActionData.ContextID);
end;
end;
end;