mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 18:39:28 +02:00
applied win32 menu patch from Micha Nelissen
git-svn-id: trunk@4308 -
This commit is contained in:
parent
71f77609fd
commit
b3a9406869
@ -106,10 +106,30 @@ end;
|
|||||||
|
|
||||||
|
|
||||||
------------------------------------------------------------------------------}
|
------------------------------------------------------------------------------}
|
||||||
function TMenu.FindItem(Value: Integer; Kind: TFindItemKind): TMenuItem;
|
function TMenu.FindItem(AValue: Integer; Kind: TFindItemKind): TMenuItem;
|
||||||
|
|
||||||
|
function Find(Item: TMenuItem): TMenuItem;
|
||||||
|
var
|
||||||
|
I: Integer;
|
||||||
|
begin
|
||||||
|
Result := nil;
|
||||||
|
if Item=nil then exit;
|
||||||
|
if ((Kind = fkCommand) and (AValue = Item.Command))
|
||||||
|
or ((Kind = fkHandle) and (AValue = Integer(Item.FHandle)))
|
||||||
|
or ((Kind = fkShortCut) and (AValue = Item.ShortCut)) then
|
||||||
|
begin
|
||||||
|
Result := Item;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
for I := 0 to Item.GetCount - 1 do begin
|
||||||
|
Result:=Find(Item[I]);
|
||||||
|
if Result<>nil then
|
||||||
|
Exit;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
//TODO: FINISH TMenu:FINDITEM
|
Result:=Find(Items);
|
||||||
Result:=nil;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
@ -186,6 +206,19 @@ begin
|
|||||||
if not HandleAllocated then CreateHandle;
|
if not HandleAllocated then CreateHandle;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TMenu.DispatchCommand(ACommand: Word): Boolean;
|
||||||
|
var
|
||||||
|
Item: TMenuItem;
|
||||||
|
begin
|
||||||
|
Result := False;
|
||||||
|
Item := FindItem(ACommand, fkCommand);
|
||||||
|
if Item <> nil then
|
||||||
|
begin
|
||||||
|
Item.Click;
|
||||||
|
Result := True;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
Function: TMenu.IsRightToLeft
|
Function: TMenu.IsRightToLeft
|
||||||
Params:
|
Params:
|
||||||
@ -204,6 +237,9 @@ end;
|
|||||||
{ =============================================================================
|
{ =============================================================================
|
||||||
|
|
||||||
$Log$
|
$Log$
|
||||||
|
Revision 1.18 2003/06/24 15:57:55 mattias
|
||||||
|
applied win32 menu patch from Micha Nelissen
|
||||||
|
|
||||||
Revision 1.17 2003/06/13 06:05:49 mattias
|
Revision 1.17 2003/06/13 06:05:49 mattias
|
||||||
started context diff
|
started context diff
|
||||||
|
|
||||||
|
@ -89,6 +89,7 @@ begin
|
|||||||
FChecked := False;
|
FChecked := False;
|
||||||
FVisible := True;
|
FVisible := True;
|
||||||
FEnabled := True;
|
FEnabled := True;
|
||||||
|
FCommand := UniqueCommand;
|
||||||
//writeln('TMenuItem.Create END TheOwner=',TheOwner.Name,':',TheOwner.ClassName);
|
//writeln('TMenuItem.Create END TheOwner=',TheOwner.Name,':',TheOwner.ClassName);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -169,6 +170,7 @@ begin
|
|||||||
FItems:=nil;
|
FItems:=nil;
|
||||||
if FParent<>nil then
|
if FParent<>nil then
|
||||||
FParent.FItems.Remove(Self);
|
FParent.FItems.Remove(Self);
|
||||||
|
if FCommand <> 0 then CommandPool[FCommand] := False;
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -953,6 +955,9 @@ end;
|
|||||||
{ =============================================================================
|
{ =============================================================================
|
||||||
|
|
||||||
$Log$
|
$Log$
|
||||||
|
Revision 1.35 2003/06/24 15:57:55 mattias
|
||||||
|
applied win32 menu patch from Micha Nelissen
|
||||||
|
|
||||||
Revision 1.34 2003/05/18 10:42:58 mattias
|
Revision 1.34 2003/05/18 10:42:58 mattias
|
||||||
implemented deleting empty submenus
|
implemented deleting empty submenus
|
||||||
|
|
||||||
@ -1083,6 +1088,9 @@ end;
|
|||||||
|
|
||||||
|
|
||||||
$Log$
|
$Log$
|
||||||
|
Revision 1.35 2003/06/24 15:57:55 mattias
|
||||||
|
applied win32 menu patch from Micha Nelissen
|
||||||
|
|
||||||
Revision 1.34 2003/05/18 10:42:58 mattias
|
Revision 1.34 2003/05/18 10:42:58 mattias
|
||||||
implemented deleting empty submenus
|
implemented deleting empty submenus
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
// {$C+}
|
// {$C+}
|
||||||
// {$DEFINE ASSERT_IS_ON}
|
// {$DEFINE ASSERT_IS_ON}
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
Method: TWin32Object.Create
|
Method: TWin32Object.Create
|
||||||
Params: None
|
Params: None
|
||||||
@ -228,14 +229,17 @@ Procedure TWin32Object.SetLabel(Sender: TObject; Data: Pointer);
|
|||||||
{In Win32 Menu items that are created without a initial caption default to disabled,
|
{In Win32 Menu items that are created without a initial caption default to disabled,
|
||||||
the next three lines are to counter that.}
|
the next three lines are to counter that.}
|
||||||
fMask:=MIIM_STATE or MIIM_TYPE or MIIM_ID;
|
fMask:=MIIM_STATE or MIIM_TYPE or MIIM_ID;
|
||||||
GetMenuItemInfo((Sender as TMenuItem).Parent.Handle, integer((Sender as TMenuItem).Handle) and $FFFF, false, @MenuInfo);
|
GetMenuItemInfo((Sender as TMenuItem).Parent.Handle,
|
||||||
if (Sender as TMenuItem).Enabled then fState := fState and (not (MFS_DISABLED or MFS_GRAYED));
|
(Sender as TMenuItem).Command, false, @MenuInfo);
|
||||||
|
if (Sender as TMenuItem).Enabled then
|
||||||
|
fState := fState and (not (MFS_DISABLED or MFS_GRAYED));
|
||||||
|
|
||||||
fMask:=MIIM_TYPE or MIIM_STATE;
|
fMask:=MIIM_TYPE or MIIM_STATE;
|
||||||
fType:=Style;
|
fType:=Style;
|
||||||
dwTypeData:=Data;
|
dwTypeData:=Data;
|
||||||
end;
|
end;
|
||||||
SetMenuItemInfo((Sender as TMenuItem).Parent.Handle, integer((Sender as TMenuItem).Handle) and $FFFF, false, @MenuInfo);
|
SetMenuItemInfo((Sender as TMenuItem).Parent.Handle,
|
||||||
|
(Sender as TMenuItem).Command, false, @MenuInfo);
|
||||||
DrawMenuBar(((Sender as TMenuItem).Owner as TWinControl).Handle);
|
DrawMenuBar(((Sender as TMenuItem).Owner as TWinControl).Handle);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
@ -532,6 +536,7 @@ Begin
|
|||||||
Else If Sender Is TMenuItem Then
|
Else If Sender Is TMenuItem Then
|
||||||
Begin
|
Begin
|
||||||
DeleteMenu((Sender as TMenuItem).Parent.Handle, Handle, MF_BYCOMMAND);
|
DeleteMenu((Sender as TMenuItem).Parent.Handle, Handle, MF_BYCOMMAND);
|
||||||
|
{ release menu item id }
|
||||||
DrawMenuBar(((Sender as TMenuItem).Owner as TWinControl).Handle);
|
DrawMenuBar(((Sender as TMenuItem).Owner as TWinControl).Handle);
|
||||||
End
|
End
|
||||||
Else
|
Else
|
||||||
@ -2591,11 +2596,13 @@ Begin
|
|||||||
cbSize:=sizeof(MENUITEMINFO);
|
cbSize:=sizeof(MENUITEMINFO);
|
||||||
fMask:=MIIM_SUBMENU;
|
fMask:=MIIM_SUBMENU;
|
||||||
end;
|
end;
|
||||||
GetMenuItemInfo(ParentOfParent, (ParentMenuHandle) and $FFFF, false, @MenuInfo);
|
GetMenuItemInfo(ParentOfParent, (Sender as TMenuItem).Command,
|
||||||
|
false, @MenuInfo);
|
||||||
if MenuInfo.hSubmenu=0 then // the parent menu item is not yet defined with submenu flag
|
if MenuInfo.hSubmenu=0 then // the parent menu item is not yet defined with submenu flag
|
||||||
begin
|
begin
|
||||||
MenuInfo.hSubmenu:=ParentMenuHandle;
|
MenuInfo.hSubmenu:=ParentMenuHandle;
|
||||||
SetMenuItemInfo(ParentOfParent, Integer(ParentMenuHandle) and $FFFF, false, MenuInfo);
|
SetMenuItemInfo(ParentOfParent, (Sender as TMenuItem).Command,
|
||||||
|
false, MenuInfo);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -2607,7 +2614,6 @@ Begin
|
|||||||
fMask:=Mask;
|
fMask:=Mask;
|
||||||
fType:=Style;
|
fType:=Style;
|
||||||
{fState:=MFS_ENABLED;} {not needed}
|
{fState:=MFS_ENABLED;} {not needed}
|
||||||
wID:=integer(MenuHandle) and $FFFF; {value is only 16 bit wide!}
|
|
||||||
hSubmenu:=MenuHandle;
|
hSubmenu:=MenuHandle;
|
||||||
{hbmpChecked:=0;
|
{hbmpChecked:=0;
|
||||||
hbmpUnchecked:=0;} {not needed}
|
hbmpUnchecked:=0;} {not needed}
|
||||||
@ -2659,6 +2665,9 @@ End;
|
|||||||
|
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
|
Revision 1.53 2003/06/24 15:57:55 mattias
|
||||||
|
applied win32 menu patch from Micha Nelissen
|
||||||
|
|
||||||
Revision 1.52 2003/06/24 08:32:03 mattias
|
Revision 1.52 2003/06/24 08:32:03 mattias
|
||||||
applied menu fix from Micha Nelissen
|
applied menu fix from Micha Nelissen
|
||||||
|
|
||||||
|
@ -162,7 +162,7 @@ Begin
|
|||||||
if BChecked then CheckFlag := MF_CHECKED
|
if BChecked then CheckFlag := MF_CHECKED
|
||||||
else CheckFlag := MF_UNCHECKED;
|
else CheckFlag := MF_UNCHECKED;
|
||||||
CheckFlag := CheckFlag or MF_BYCOMMAND;
|
CheckFlag := CheckFlag or MF_BYCOMMAND;
|
||||||
PrevState := Windows.CheckMenuItem(FMenu, HndMenu, CheckFlag);
|
PrevState := Windows.CheckMenuItem(FMenu, UIDEnableItem, CheckFlag);
|
||||||
Result := PrevState = MF_ENABLED;
|
Result := PrevState = MF_ENABLED;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
@ -822,7 +822,7 @@ Begin
|
|||||||
if BEnable then EnableFlag := MF_ENABLED
|
if BEnable then EnableFlag := MF_ENABLED
|
||||||
else EnableFlag := MF_GRAYED;
|
else EnableFlag := MF_GRAYED;
|
||||||
EnableFlag := EnableFlag or MF_BYCOMMAND;
|
EnableFlag := EnableFlag or MF_BYCOMMAND;
|
||||||
Result := Windows.EnableMenuItem(FMenu, HndMenu, EnableFlag);
|
Result := Windows.EnableMenuItem(FMenu, UIDEnableItem, EnableFlag);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
@ -2322,6 +2322,9 @@ end;
|
|||||||
{ =============================================================================
|
{ =============================================================================
|
||||||
|
|
||||||
$Log$
|
$Log$
|
||||||
|
Revision 1.34 2003/06/24 15:57:55 mattias
|
||||||
|
applied win32 menu patch from Micha Nelissen
|
||||||
|
|
||||||
Revision 1.33 2003/03/25 08:12:39 mattias
|
Revision 1.33 2003/03/25 08:12:39 mattias
|
||||||
patch from Martin Smat for menu items and default messages
|
patch from Martin Smat for menu items and default messages
|
||||||
|
|
||||||
|
25
lcl/menus.pp
25
lcl/menus.pp
@ -184,6 +184,7 @@ type
|
|||||||
property Items[Index: Integer]: TMenuItem read GetItem; default;
|
property Items[Index: Integer]: TMenuItem read GetItem; default;
|
||||||
property MenuIndex: Integer read GetMenuIndex write SetMenuIndex;
|
property MenuIndex: Integer read GetMenuIndex write SetMenuIndex;
|
||||||
property Parent: TMenuItem read GetParent;
|
property Parent: TMenuItem read GetParent;
|
||||||
|
property Command: integer read FCommand;
|
||||||
published
|
published
|
||||||
property AutoCheck: boolean read FAutoCheck write SetAutoCheck default False;
|
property AutoCheck: boolean read FAutoCheck write SetAutoCheck default False;
|
||||||
property Caption: String read FCaption write SetCaption
|
property Caption: String read FCaption write SetCaption
|
||||||
@ -240,10 +241,12 @@ type
|
|||||||
FCompStyle: LongInt;
|
FCompStyle: LongInt;
|
||||||
constructor Create(AOwner: TComponent); override;
|
constructor Create(AOwner: TComponent); override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
function FindItem(Value: Integer; Kind: TFindItemKind) : TMenuItem;
|
function FindItem(AValue: Integer; Kind: TFindItemKind) : TMenuItem;
|
||||||
function HandleAllocated: Boolean;
|
function HandleAllocated: Boolean;
|
||||||
Function IsRightToLeft: Boolean;
|
Function IsRightToLeft: Boolean;
|
||||||
procedure HandleNeeded;
|
procedure HandleNeeded;
|
||||||
|
function DispatchCommand(ACommand: Word): Boolean;
|
||||||
|
public
|
||||||
property Handle: HMenu read GetHandle;
|
property Handle: HMenu read GetHandle;
|
||||||
property Parent: TComponent read FParent write SetParent;
|
property Parent: TComponent read FParent write SetParent;
|
||||||
published
|
published
|
||||||
@ -309,6 +312,19 @@ procedure Register;
|
|||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
|
||||||
|
{ Menu command managment }
|
||||||
|
|
||||||
|
var
|
||||||
|
CommandPool: TBits;
|
||||||
|
|
||||||
|
function UniqueCommand: Word;
|
||||||
|
begin
|
||||||
|
if CommandPool=nil then
|
||||||
|
CommandPool:=TBits.Create(32);
|
||||||
|
Result := CommandPool.OpenBit;
|
||||||
|
CommandPool[Result] := True;
|
||||||
|
end;
|
||||||
|
|
||||||
function ShortCutToText(ShortCut: TShortCut): string;
|
function ShortCutToText(ShortCut: TShortCut): string;
|
||||||
begin
|
begin
|
||||||
Result:=ShortCutToShortCutText(ShortCut);
|
Result:=ShortCutToShortCutText(ShortCut);
|
||||||
@ -358,11 +374,18 @@ end;
|
|||||||
initialization
|
initialization
|
||||||
DesignerMenuItemClick:=nil;
|
DesignerMenuItemClick:=nil;
|
||||||
ActivePopupMenu:=nil;
|
ActivePopupMenu:=nil;
|
||||||
|
CommandPool := nil;
|
||||||
|
|
||||||
|
finalization
|
||||||
|
FreeThenNil(CommandPool);
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
|
Revision 1.48 2003/06/24 15:57:55 mattias
|
||||||
|
applied win32 menu patch from Micha Nelissen
|
||||||
|
|
||||||
Revision 1.47 2003/06/24 15:23:10 mattias
|
Revision 1.47 2003/06/24 15:23:10 mattias
|
||||||
deleted unused code
|
deleted unused code
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user