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