PageRenderTime 44ms CodeModel.GetById 5ms RepoModel.GetById 0ms app.codeStats 0ms

/cnwizards/Bin/PSDecl/Menus.pas

http://cnpack.googlecode.com/
Pascal | 211 lines | 150 code | 21 blank | 40 comment | 0 complexity | 236380e73a3405107758a7009f42bd44 MD5 | raw file
  1. {******************************************************************************}
  2. { CnPack For Delphi/C++Builder }
  3. { ???????????????? }
  4. { (C)Copyright 2001-2011 CnPack ??? }
  5. { ------------------------------------ }
  6. { }
  7. { ?????????????????? CnPack ??????? }
  8. { ??????????? }
  9. { }
  10. { ????????????????????????????? }
  11. { ?????????????????????? CnPack ????? }
  12. { }
  13. { ??????????????? CnPack ?????????? }
  14. { ????????????? }
  15. { }
  16. { ?????http://www.cnpack.org }
  17. { ?????master@cnpack.org }
  18. { }
  19. {******************************************************************************}
  20. unit Menus;
  21. { |<PRE>
  22. ================================================================================
  23. * ?????CnPack IDE ???
  24. * ???????????? Menus ????
  25. * ???????? (zjy@cnpack.org)
  26. * ? ???????????? Borland Delphi ???????????
  27. * ??????????????? PasScript ?????
  28. * ?????PWinXP SP2 + Delphi 5.01
  29. * ?????PWin9X/2000/XP + Delphi 5/6/7
  30. * ? ? ??
  31. * ?????$Id: Menus.pas 763 2011-02-07 14:18:23Z liuxiao@cnpack.org $
  32. * ?????2006.12.26 V1.0
  33. * ????
  34. ================================================================================
  35. |</PRE>}
  36. interface
  37. uses Windows, SysUtils, Classes, Contnrs, Messages, Graphics, ImgList, ActnList;
  38. type
  39. TMenuItem = class;
  40. TMenu = class;
  41. TMenuBreak = (mbNone, mbBreak, mbBarBreak);
  42. TMenuChangeEvent = procedure (Sender: TObject; Source: TMenuItem; Rebuild: Boolean) of object;
  43. TMenuDrawItemEvent = procedure (Sender: TObject; ACanvas: TCanvas;
  44. ARect: TRect; Selected: Boolean) of object;
  45. TAdvancedMenuDrawItemEvent = procedure (Sender: TObject; ACanvas: TCanvas;
  46. ARect: TRect; State: TOwnerDrawState) of object;
  47. TMenuMeasureItemEvent = procedure (Sender: TObject; ACanvas: TCanvas;
  48. var Width, Height: Integer) of object;
  49. TMenuItemAutoFlag = (maAutomatic, maManual, maParent);
  50. TMenuAutoFlag = TMenuItemAutoFlag; // maAutomatic..maManual;
  51. { TMenuItem }
  52. TMenuItem = class(TComponent)
  53. public
  54. constructor Create(AOwner: TComponent); override;
  55. destructor Destroy; override;
  56. procedure InitiateAction; virtual;
  57. procedure Insert(Index: Integer; Item: TMenuItem);
  58. procedure Delete(Index: Integer);
  59. procedure Clear;
  60. procedure Click; virtual;
  61. function Find(ACaption: string): TMenuItem;
  62. function IndexOf(Item: TMenuItem): Integer;
  63. function IsLine: Boolean;
  64. function GetImageList: TCustomImageList;
  65. function GetParentComponent: TComponent; override;
  66. function GetParentMenu: TMenu;
  67. function HasParent: Boolean; override;
  68. function NewTopLine: Integer;
  69. function NewBottomLine: Integer;
  70. function InsertNewLineBefore(AItem: TMenuItem): Integer;
  71. function InsertNewLineAfter(AItem: TMenuItem): Integer;
  72. procedure Add(Item: TMenuItem); overload;
  73. procedure AddEx(const AItems: array of TMenuItem); overload;
  74. procedure Remove(Item: TMenuItem);
  75. function RethinkHotkeys: Boolean;
  76. function RethinkLines: Boolean;
  77. property Command: Word read FCommand;
  78. property Handle: HMENU read GetHandle;
  79. property Count: Integer read GetCount;
  80. property Items[Index: Integer]: TMenuItem read GetItem; default;
  81. property MenuIndex: Integer read GetMenuIndex write SetMenuIndex;
  82. property Parent: TMenuItem read FParent;
  83. published
  84. property Action: TBasicAction read GetAction write SetAction;
  85. property AutoHotkeys: TMenuItemAutoFlag read FAutoHotkeys write SetAutoHotkeys default maParent;
  86. property AutoLineReduction: TMenuItemAutoFlag read FAutoLineReduction write SetAutoLineReduction default maParent;
  87. property Bitmap: TBitmap read GetBitmap write SetBitmap;
  88. property Break: TMenuBreak read FBreak write SetBreak default mbNone;
  89. property Caption: string read FCaption write SetCaption stored IsCaptionStored;
  90. property Checked: Boolean read FChecked write SetChecked stored IsCheckedStored default False;
  91. property SubMenuImages: TCustomImageList read FSubMenuImages write SetSubMenuImages;
  92. property Default: Boolean read FDefault write SetDefault default False;
  93. property Enabled: Boolean read FEnabled write SetEnabled stored IsEnabledStored default True;
  94. property GroupIndex: Byte read FGroupIndex write SetGroupIndex default 0;
  95. property HelpContext: THelpContext read FHelpContext write FHelpContext stored IsHelpContextStored default 0;
  96. property Hint: string read FHint write FHint stored IsHintStored;
  97. property ImageIndex: TImageIndex read FImageIndex write SetImageIndex stored IsImageIndexStored default -1;
  98. property RadioItem: Boolean read FRadioItem write SetRadioItem default False;
  99. property ShortCut: TShortCut read FShortCut write SetShortCut stored IsShortCutStored default 0;
  100. property Visible: Boolean read FVisible write SetVisible stored IsVisibleStored default True;
  101. property OnClick: TNotifyEvent read FOnClick write FOnClick stored IsOnClickStored;
  102. property OnDrawItem: TMenuDrawItemEvent read FOnDrawItem write FOnDrawItem;
  103. property OnAdvancedDrawItem: TAdvancedMenuDrawItemEvent read FOnAdvancedDrawItem write FOnAdvancedDrawItem;
  104. property OnMeasureItem: TMenuMeasureItemEvent read FOnMeasureItem write FOnMeasureItem;
  105. end;
  106. TFindItemKind = (fkCommand, fkHandle, fkShortCut);
  107. TMenu = class(TComponent)
  108. public
  109. constructor Create(AOwner: TComponent); override;
  110. destructor Destroy; override;
  111. function DispatchCommand(ACommand: Word): Boolean;
  112. function DispatchPopup(AHandle: HMENU): Boolean;
  113. function FindItem(Value: Integer; Kind: TFindItemKind): TMenuItem;
  114. function GetHelpContext(Value: Integer; ByCommand: Boolean): THelpContext;
  115. property Images: TCustomImageList read FImages write SetImages;
  116. function IsRightToLeft: Boolean;
  117. function IsShortCut(var Message: TWMKey): Boolean; dynamic;
  118. property AutoHotkeys: TMenuAutoFlag read GetAutoHotkeys write SetAutoHotkeys default maAutomatic;
  119. property AutoLineReduction: TMenuAutoFlag read GetAutoLineReduction write SetAutoLineReduction default maAutomatic;
  120. property BiDiMode: TBiDiMode read FBiDiMode write SetBiDiMode stored IsBiDiModeStored;
  121. property Handle: HMENU read GetHandle;
  122. property OwnerDraw: Boolean read FOwnerDraw write SetOwnerDraw default False;
  123. property ParentBiDiMode: Boolean read FParentBiDiMode write SetParentBiDiMode default True;
  124. property WindowHandle: HWND read FWindowHandle write SetWindowHandle;
  125. published
  126. property Items: TMenuItem read FItems;
  127. end;
  128. TMainMenu = class(TMenu)
  129. published
  130. property AutoHotkeys;
  131. property AutoLineReduction;
  132. property AutoMerge: Boolean read FAutoMerge write SetAutoMerge default False;
  133. property BiDiMode;
  134. property Images;
  135. property OwnerDraw;
  136. property ParentBiDiMode;
  137. property OnChange;
  138. end;
  139. TPopupAlignment = (paLeft, paRight, paCenter);
  140. TTrackButton = (tbRightButton, tbLeftButton);
  141. TMenuAnimations = (maLeftToRight, maRightToLeft, maTopToBottom, maBottomToTop, maNone);
  142. TMenuAnimation = set of TMenuAnimations;
  143. TPopupMenu = class(TMenu)
  144. public
  145. constructor Create(AOwner: TComponent); override;
  146. destructor Destroy; override;
  147. procedure Popup(X, Y: Integer); virtual;
  148. property PopupComponent: TComponent read FPopupComponent write FPopupComponent;
  149. published
  150. property Alignment: TPopupAlignment read FAlignment write FAlignment default paLeft;
  151. property AutoHotkeys;
  152. property AutoLineReduction;
  153. property AutoPopup: Boolean read FAutoPopup write FAutoPopup default True;
  154. property BiDiMode;
  155. property HelpContext: THelpContext read GetHelpContext write SetHelpContext default 0;
  156. property Images;
  157. property MenuAnimation: TMenuAnimation read FMenuAnimation write FMenuAnimation default [];
  158. property OwnerDraw;
  159. property ParentBiDiMode;
  160. property TrackButton: TTrackButton read FTrackButton write FTrackButton default tbRightButton;
  161. property OnChange;
  162. property OnPopup: TNotifyEvent read FOnPopup write FOnPopup;
  163. end;
  164. function ShortCut(Key: Word; Shift: TShiftState): TShortCut;
  165. procedure ShortCutToKey(ShortCut: TShortCut; var Key: Word; var Shift: TShiftState);
  166. function ShortCutToText(ShortCut: TShortCut): string;
  167. function TextToShortCut(Text: string): TShortCut;
  168. function NewMenu(Owner: TComponent; const AName: string; Items: array of TMenuItem): TMainMenu;
  169. function NewPopupMenu(Owner: TComponent; const AName: string;
  170. Alignment: TPopupAlignment; AutoPopup: Boolean; Items: array of TMenuitem): TPopupMenu;
  171. function NewSubMenu(const ACaption: string; hCtx: Word;
  172. const AName: string; Items: array of TMenuItem; AEnabled: Boolean = True): TMenuItem;
  173. function NewItem(const ACaption: string; AShortCut: TShortCut;
  174. AChecked, AEnabled: Boolean; AOnClick: TNotifyEvent; hCtx: Word;
  175. const AName: string): TMenuItem;
  176. function NewLine: TMenuItem;
  177. const
  178. cHotkeyPrefix = '&';
  179. cLineCaption = '-';
  180. cDialogSuffix = '...';
  181. { StripHotkey removes the & escape char that marks the hotkey character(s) in
  182. the string. When the current locale is a Far East locale, this function also
  183. looks for and removes parens around the hotkey, common in Far East locales. }
  184. function StripHotkey(const Text: string): string;
  185. { GetHotkey will return the last hotkey that StripHotkey would strip. }
  186. function GetHotkey(const Text: string): string;
  187. { Similar to AnsiSameText but strips hotkeys before comparing }
  188. function AnsiSameCaption(const Text1, Text2: string): Boolean;
  189. implementation
  190. end.