home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1997 May
/
Pcwk0597.iso
/
borland
/
cb
/
setup
/
cbuilder
/
data.z
/
MENUS.INT
< prev
next >
Wrap
Text File
|
1997-02-28
|
6KB
|
151 lines
{*******************************************************}
{ }
{ Delphi Visual Component Library }
{ }
{ Copyright (c) 1995,96 Borland International }
{ }
{*******************************************************}
unit Menus;
{$S-,W-,R-}
{$C PRELOAD}
interface
uses Windows, SysUtils, Classes, Messages;
const
scShift = $2000;
scCtrl = $4000;
scAlt = $8000;
scNone = 0;
type
EMenuError = class(Exception);
TMenu = class;
TMenuBreak = (mbNone, mbBreak, mbBarBreak);
TShortCut = Low(Word)..High(Word);
TMenuChangeEvent = procedure (Sender: TObject; Rebuild: Boolean) of object;
TMenuItem = class(TComponent)
protected
procedure DefineProperties(Filer: TFiler); override;
function GetHandle: HMENU;
function GetCount: Integer;
procedure GetChildren(Proc: TGetChildProc); override;
function GetItem(Index: Integer): TMenuItem;
function GetMenuIndex: Integer;
function GetParentComponent: TComponent; override;
procedure MenuChanged(Rebuild: Boolean); virtual;
function HasParent: Boolean; override;
procedure SetBreak(Value: TMenuBreak);
procedure SetCaption(const Value: string);
procedure SetChecked(Value: Boolean);
procedure SetChildOrder(Child: TComponent; Order: Integer); override;
procedure SetDefault(Value: Boolean);
procedure SetEnabled(Value: Boolean);
procedure SetGroupIndex(Value: Byte);
procedure SetMenuIndex(Value: Integer);
procedure SetParentComponent(Value: TComponent); override;
procedure SetRadioItem(Value: Boolean);
procedure SetShortCut(Value: TShortCut);
procedure SetVisible(Value: Boolean);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Insert(Index: Integer; Item: TMenuItem);
procedure Delete(Index: Integer);
procedure Click; virtual;
function IndexOf(Item: TMenuItem): Integer;
procedure Add(Item: TMenuItem);
procedure Remove(Item: TMenuItem);
property Command: Word;
property Handle: HMENU;
property Count: Integer;
property Items[Index: Integer]: TMenuItem; default;
property MenuIndex: Integer;
property Parent: TMenuItem;
published
property Break: TMenuBreak default mbNone;
property Caption: string;
property Checked: Boolean default False;
property Default: Boolean default False;
property Enabled: Boolean default True;
property GroupIndex: Byte default 0;
property HelpContext: THelpContext default 0;
property Hint: string;
property RadioItem: Boolean default False;
property ShortCut: TShortCut;
property Visible: Boolean default True;
property OnClick: TNotifyEvent;
end;
TFindItemKind = (fkCommand, fkHandle, fkShortCut);
TMenu = class(TComponent)
protected
procedure GetChildren(Proc: TGetChildProc); override;
function GetHandle: HMENU; virtual;
procedure SetChildOrder(Child: TComponent; Order: Integer); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function DispatchCommand(ACommand: Word): Boolean;
function DispatchPopup(AHandle: HMENU): Boolean;
function FindItem(Value: Integer; Kind: TFindItemKind): TMenuItem;
function GetHelpContext(Value: Word; ByCommand: Boolean): THelpContext;
function IsShortCut(var Message: TWMKey): Boolean;
property Handle: HMENU;
property WindowHandle: HWND;
published
property Items: TMenuItem;
end;
TMainMenu = class(TMenu)
protected
function GetHandle: HMENU; override;
public
procedure Merge(Menu: TMainMenu);
procedure Unmerge(Menu: TMainMenu);
procedure PopulateOle2Menu(SharedMenu: HMenu; Groups: array of Integer;
var Widths: array of Longint);
procedure GetOle2AcceleratorTable(var AccelTable: HAccel;
var AccelCount: Integer; Groups: array of Integer);
procedure SetOle2MenuHandle(Handle: HMENU);
published
property AutoMerge: Boolean default False;
end;
TPopupAlignment = (paLeft, paRight, paCenter);
TPopupMenu = class(TMenu)
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Popup(X, Y: Integer); virtual;
property PopupComponent: TComponent;
published
property Alignment: TPopupAlignment default paLeft;
property AutoPopup: Boolean default True;
property HelpContext: THelpContext default 0;
property OnPopup: TNotifyEvent;
end;
function ShortCut(Key: Word; Shift: TShiftState): TShortCut;
procedure ShortCutToKey(ShortCut: TShortCut; var Key: Word; var Shift: TShiftState);
function ShortCutToText(ShortCut: TShortCut): string;
function TextToShortCut(Text: string): TShortCut;
function NewMenu(Owner: TComponent; const AName: string; Items: array of TMenuItem): TMainMenu;
function NewPopupMenu(Owner: TComponent; const AName: string;
Alignment: TPopupAlignment; AutoPopup: Boolean; Items: array of TMenuitem): TPopupMenu;
function NewSubMenu(const ACaption: string; hCtx: Word; const AName: string;
Items: array of TMenuItem): TMenuItem;
function NewItem(const ACaption: string; AShortCut: TShortCut;
AChecked, AEnabled: Boolean; AOnClick: TNotifyEvent; hCtx: Word;
const AName: string): TMenuItem;
function NewLine: TMenuItem;
implementation