mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 06:19:32 +02:00
Cocoa popup menu rework with IMenuItemCallback and TLCLMenuItemCallback
git-svn-id: trunk@43565 -
This commit is contained in:
parent
6a889284f0
commit
60b3cbce65
@ -27,7 +27,7 @@ uses
|
|||||||
// Libs
|
// Libs
|
||||||
CocoaAll, CocoaUtils, CocoaGDIObjects,
|
CocoaAll, CocoaUtils, CocoaGDIObjects,
|
||||||
// LCL
|
// LCL
|
||||||
LCLType, LMessages, LCLMessageGlue, Controls;
|
LCLType, Controls;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
@ -160,6 +160,10 @@ type
|
|||||||
property Enabled: Boolean read GetEnabled write SetEnabled;
|
property Enabled: Boolean read GetEnabled write SetEnabled;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
IMenuItemCallback = interface(ICommonCallBack)
|
||||||
|
procedure ItemSelected;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TCocoaMenu }
|
{ TCocoaMenu }
|
||||||
|
|
||||||
TCocoaMenu = objcclass(NSMenu)
|
TCocoaMenu = objcclass(NSMenu)
|
||||||
@ -171,7 +175,7 @@ type
|
|||||||
|
|
||||||
TCocoaMenuItem = objcclass(NSMenuItem)
|
TCocoaMenuItem = objcclass(NSMenuItem)
|
||||||
public
|
public
|
||||||
lcltarget:TObject;
|
callback:IMenuItemCallback;
|
||||||
procedure lclItemSelected(sender: id); message 'lclItemSelected:';
|
procedure lclItemSelected(sender: id); message 'lclItemSelected:';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1929,14 +1933,8 @@ end;
|
|||||||
{ TCocoaMenuITem }
|
{ TCocoaMenuITem }
|
||||||
|
|
||||||
procedure TCocoaMenuItem.lclItemSelected(sender:id);
|
procedure TCocoaMenuItem.lclItemSelected(sender:id);
|
||||||
var
|
|
||||||
Msg:TLMessage;
|
|
||||||
begin
|
begin
|
||||||
// TODO: move this to callback and call it using callback.ItemSelected
|
callback.ItemSelected;
|
||||||
FillChar(Msg{%H-}, SizeOf(Msg), 0);
|
|
||||||
Msg.msg := LM_ACTIVATE;
|
|
||||||
// debugln('send LM_Activate');
|
|
||||||
DeliverMessage(lclTarget,Msg);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
@ -14,6 +14,8 @@ uses
|
|||||||
CocoaPrivate, CocoaGDIObjects, CocoaCaret, CocoaUtils, LCLMessageGlue;
|
CocoaPrivate, CocoaGDIObjects, CocoaCaret, CocoaUtils, LCLMessageGlue;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
|
|
||||||
{ TLCLCommonCallback }
|
{ TLCLCommonCallback }
|
||||||
|
|
||||||
TLCLCommonCallback = class(TObject, ICommonCallBack)
|
TLCLCommonCallback = class(TObject, ICommonCallBack)
|
||||||
@ -98,6 +100,16 @@ type
|
|||||||
const AParams: TCreateParams): TLCLIntfHandle; override;
|
const AParams: TCreateParams): TLCLIntfHandle; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TLCLMenuItemCallback }
|
||||||
|
|
||||||
|
TLCLMenuItemCallback = class(TLCLCommonCallback, IMenuItemCallback)
|
||||||
|
private
|
||||||
|
FMenuItemTarget: TComponent;
|
||||||
|
public
|
||||||
|
constructor Create(AOwner: NSObject; AMenuItemTarget: TComponent);
|
||||||
|
procedure ItemSelected;
|
||||||
|
end;
|
||||||
|
|
||||||
const
|
const
|
||||||
DblClickThreshold = 3;// max Movement between two clicks of a DblClick
|
DblClickThreshold = 3;// max Movement between two clicks of a DblClick
|
||||||
|
|
||||||
@ -1075,5 +1087,23 @@ begin
|
|||||||
Result := TLCLIntfHandle(ctrl);
|
Result := TLCLIntfHandle(ctrl);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TLCLMenuItemCallback }
|
||||||
|
|
||||||
|
constructor TLCLMenuItemCallback.Create(AOwner: NSObject; AMenuItemTarget: TComponent);
|
||||||
|
begin
|
||||||
|
Owner := AOwner;
|
||||||
|
FMenuItemTarget:=AMenuItemTarget;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TLCLMenuItemCallback.ItemSelected;
|
||||||
|
var
|
||||||
|
Msg:TLMessage;
|
||||||
|
begin
|
||||||
|
FillChar(Msg{%H-}, SizeOf(Msg), 0);
|
||||||
|
Msg.msg := LM_ACTIVATE;
|
||||||
|
// debugln('send LM_Activate');
|
||||||
|
LCLMessageGlue.DeliverMessage(FMenuItemTarget,Msg);
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -170,7 +170,7 @@ begin
|
|||||||
objcselector('lclItemSelected:'), NSString.alloc.init);
|
objcselector('lclItemSelected:'), NSString.alloc.init);
|
||||||
ns.release;
|
ns.release;
|
||||||
item.setTarget(item);
|
item.setTarget(item);
|
||||||
TCocoaMenuItem(item).lcltarget:=AMenuItem;
|
TCocoaMenuItem(item).callback:=TLCLMenuItemCallback.Create(item, AMenuItem);
|
||||||
item.setEnabled(AMenuItem.Enabled);
|
item.setEnabled(AMenuItem.Enabled);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user