mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-13 05:29:51 +02:00
carbon: Implements checking the visibility of the TTrayIcon menu via private method
git-svn-id: trunk@21714 -
This commit is contained in:
parent
30535703d0
commit
048acfbea7
@ -41,14 +41,19 @@ type
|
||||
procedure RemoveIcon();
|
||||
function ConvertTIconToNSImage(AIcon: TIcon): NSImage;
|
||||
function ConvertTBitmapToNSImage(ABitmap: TBitmap): NSImage;
|
||||
function IsMenuVisible: Boolean;
|
||||
{ Objective-C compatible methods }
|
||||
class procedure HandleMenuItemClick(_self: objc.id; _cmd: SEL; sender: objc.id); cdecl; //static;
|
||||
class procedure HandleMenuWillOpen(_self: objc.id; _cmd: SEL; sender: objc.id); cdecl; //static;
|
||||
class procedure HandleMenuDidClose(_self: objc.id; _cmd: SEL; sender: objc.id); cdecl; //static;
|
||||
end;
|
||||
|
||||
const
|
||||
Str_TPrivateCocoaCarbonTrayIcon = 'TTrayIcon';
|
||||
|
||||
Str_HandleMenuItemClick = 'HandleMenuItemClick';
|
||||
Str_HandleMenuWillOpen = 'menuWillOpen:';
|
||||
Str_HandleMenuDidClose = 'menuDidClose:';
|
||||
|
||||
{ TPrivateCocoaCarbonTrayIcon }
|
||||
|
||||
@ -64,6 +69,8 @@ const
|
||||
procedure TPrivateCocoaCarbonTrayIcon.AddMethods;
|
||||
begin
|
||||
AddMethod(Str_HandleMenuItemClick, 'v@:@', Pointer(HandleMenuItemClick));
|
||||
AddMethod(Str_HandleMenuWillOpen, 'v@:@', Pointer(HandleMenuWillOpen));
|
||||
AddMethod(Str_HandleMenuDidClose, 'v@:@', Pointer(HandleMenuDidClose));
|
||||
end;
|
||||
|
||||
constructor TPrivateCocoaCarbonTrayIcon.Create;
|
||||
@ -103,7 +110,7 @@ end;
|
||||
|
||||
class function TPrivateCocoaCarbonTrayIcon.getClass: objc.id;
|
||||
begin
|
||||
Result := objc_getClass(Str_NSObject);
|
||||
Result := objc_getClass({Str_TPrivateCocoaCarbonTrayIcon} Str_NSObject);
|
||||
end;
|
||||
|
||||
{Removes/replaces all occurences of a character from a string}
|
||||
@ -131,6 +138,8 @@ var
|
||||
Item: NSMenuItem;
|
||||
begin
|
||||
Result := NSMenu.initWithTitle(EmptyMenuTitle);
|
||||
// Result.setVersion(0);
|
||||
Result.setDelegate(Self.Handle);
|
||||
|
||||
for i := 0 to APopUpMenu.Items.Count - 1 do
|
||||
begin
|
||||
@ -335,10 +344,27 @@ begin
|
||||
Result.unlockFocus;
|
||||
end;
|
||||
|
||||
function _NSGetCarbonMenu(AMenu: objc.id {NSMenu}): MenuRef; cdecl; external name '_NSGetCarbonMenu';
|
||||
|
||||
function TPrivateCocoaCarbonTrayIcon.IsMenuVisible: Boolean;
|
||||
var
|
||||
CarbonMenu: MenuRef;
|
||||
theMenuTrackingData: MenuTrackingData;
|
||||
begin
|
||||
Result := False;
|
||||
|
||||
if menu = nil then Exit;
|
||||
|
||||
CarbonMenu := _NSGetCarbonMenu(menu.Handle);
|
||||
if CarbonMenu = nil then Exit;
|
||||
|
||||
Result := GetMenuTrackingData(CarbonMenu, theMenuTrackingData) = noErr;
|
||||
end;
|
||||
|
||||
{ Here we try to get the LCL MenuItem from the Tag and then call
|
||||
it's OnClick method }
|
||||
class procedure TPrivateCocoaCarbonTrayIcon.HandleMenuItemClick(_self: objc.id;
|
||||
_cmd: SEL; sender: objc.id); cdecl;
|
||||
_cmd: SEL; sender: objc.id); cdecl; //static;
|
||||
var
|
||||
AMenuItem: NSMenuItem;
|
||||
LCLMenu: TMenuItem;
|
||||
@ -348,6 +374,28 @@ begin
|
||||
if (LCLMenu <> nil) and Assigned(LCLMenu.OnClick) then LCLMenu.OnClick(LCLMenu);
|
||||
end;
|
||||
|
||||
class procedure TPrivateCocoaCarbonTrayIcon.HandleMenuWillOpen(_self: objc.id;
|
||||
_cmd: SEL; sender: objc.id); cdecl; //static;
|
||||
var
|
||||
AMenu: NSMenu;
|
||||
LCLMenu: TPopUpMenu;
|
||||
begin
|
||||
AMenu := NSMenu.CreateWithHandle(sender);
|
||||
// LCLMenu := TPopUpMenu(PtrInt(AMenu.menuRepresentation()));
|
||||
// if (LCLMenu <> nil) and Assigned(LCLMenu.OnPopUp) then LCLMenu.OnPopUp(LCLMenu);
|
||||
end;
|
||||
|
||||
class procedure TPrivateCocoaCarbonTrayIcon.HandleMenuDidClose(_self: objc.id;
|
||||
_cmd: SEL; sender: objc.id); cdecl; //static;
|
||||
var
|
||||
AMenu: NSMenu;
|
||||
LCLMenu: TPopUpMenu;
|
||||
begin
|
||||
AMenu := NSMenu.CreateWithHandle(sender);
|
||||
// LCLMenu := TPopUpMenu(PtrInt(AMenu.menuRepresentation()));
|
||||
// if (LCLMenu <> nil) and Assigned(LCLMenu.OnClose) then LCLMenu.OnClose(LCLMenu);
|
||||
end;
|
||||
|
||||
{ TCarbonWSCustomTrayIcon }
|
||||
|
||||
class function TCarbonWSCustomTrayIcon.Hide(const ATrayIcon: TCustomTrayIcon): Boolean;
|
||||
@ -459,5 +507,18 @@ begin
|
||||
Result := Point(0, 0);
|
||||
end;
|
||||
|
||||
class function TCarbonWSCustomTrayIcon.IsTrayIconMenuVisible(const ATrayIcon: TCustomTrayIcon): Boolean;
|
||||
var
|
||||
APrivateTrayIcon: TPrivateCocoaCarbonTrayIcon;
|
||||
begin
|
||||
Result := False;
|
||||
|
||||
APrivateTrayIcon := TPrivateCocoaCarbonTrayIcon(ATrayIcon.Handle);
|
||||
|
||||
if APrivateTrayIcon = nil then Exit;
|
||||
|
||||
Result := APrivateTrayIcon.IsMenuVisible;
|
||||
end;
|
||||
|
||||
{$endif CarbonUseCocoa}
|
||||
|
||||
|
@ -185,6 +185,7 @@ type
|
||||
class procedure InternalUpdate(const ATrayIcon: TCustomTrayIcon); override;
|
||||
class function ShowBalloonHint(const ATrayIcon: TCustomTrayIcon): Boolean; override;
|
||||
class function GetPosition(const ATrayIcon: TCustomTrayIcon): TPoint; override;
|
||||
class function IsTrayIconMenuVisible(const ATrayIcon: TCustomTrayIcon): Boolean;
|
||||
{$endif CarbonUseCocoa}
|
||||
end;
|
||||
|
||||
|
@ -155,8 +155,8 @@
|
||||
function target: objc.id;
|
||||
procedure setAction(_aSelector: SEL);
|
||||
function action: SEL;
|
||||
procedure setTag(_anInt: Integer);
|
||||
function tag: Integer;
|
||||
procedure setTag(_anInt: PtrInt);
|
||||
function tag: PtrInt;
|
||||
procedure setRepresentedObject(_anObject: objc.id);
|
||||
function representedObject: objc.id;
|
||||
{.$ifdef MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3}
|
||||
@ -555,9 +555,9 @@ begin
|
||||
Result := SEL(objc_msgSend(Handle, sel_registerName(PChar(StrNSMenuItem_action)), []));
|
||||
end;
|
||||
|
||||
procedure NSMenuItem.setTag(_anInt: Integer);
|
||||
procedure NSMenuItem.setTag(_anInt: PtrInt);
|
||||
type
|
||||
TmsgSendWrapper = procedure (param1: objc.id; param2: SEL;_anInt: Integer); cdecl;
|
||||
TmsgSendWrapper = procedure (param1: objc.id; param2: SEL;_anInt: PtrInt); cdecl;
|
||||
var
|
||||
vmethod: TmsgSendWrapper;
|
||||
begin
|
||||
@ -565,7 +565,7 @@ begin
|
||||
vmethod(Handle, sel_registerName(PChar(StrNSMenuItem_setTag)), _anInt);
|
||||
end;
|
||||
|
||||
function NSMenuItem.tag: Integer;
|
||||
function NSMenuItem.tag: PtrInt;
|
||||
begin
|
||||
Result := Integer(objc_msgSend(Handle, sel_registerName(PChar(StrNSMenuItem_tag)), []));
|
||||
end;
|
||||
|
@ -19,6 +19,9 @@ const
|
||||
Str_alloc = 'alloc';
|
||||
Str_init = 'init';
|
||||
|
||||
Str_version = 'version';
|
||||
Str_setVersion = 'setVersion:';
|
||||
|
||||
{*************** Basic protocols ***************}
|
||||
|
||||
Str_retain = 'retain';
|
||||
@ -92,10 +95,10 @@ FOUNDATION_EXPORT unsigned NSExtraRefCount(id object);}
|
||||
+ (BOOL)instancesRespondToSelector:(SEL)aSelector;
|
||||
+ (BOOL)conformsToProtocol:(Protocol *)protocol;
|
||||
- (IMP)methodForSelector:(SEL)aSelector;
|
||||
+ (IMP)instanceMethodForSelector:(SEL)aSelector;
|
||||
+ (int)version;
|
||||
+ (void)setVersion:(int)aVersion;
|
||||
- (void)doesNotRecognizeSelector:(SEL)aSelector;
|
||||
+ (IMP)instanceMethodForSelector:(SEL)aSelector;}
|
||||
function version: PtrInt;
|
||||
procedure setVersion(aVersion: PtrInt);
|
||||
{- (void)doesNotRecognizeSelector:(SEL)aSelector;
|
||||
- (void)forwardInvocation:(NSInvocation *)anInvocation;
|
||||
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector;
|
||||
|
||||
@ -292,6 +295,21 @@ begin
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
function NSObject.version: PtrInt;
|
||||
begin
|
||||
Result := PtrInt(objc_msgSend(Handle, sel_registerName(PChar(Str_version)), []));
|
||||
end;
|
||||
|
||||
procedure NSObject.setVersion(aVersion: PtrInt);
|
||||
type
|
||||
TmsgSendWrapper = procedure (param1: objc.id; param2: SEL;_anInt: PtrInt); cdecl;
|
||||
var
|
||||
vmethod: TmsgSendWrapper;
|
||||
begin
|
||||
vmethod := TmsgSendWrapper(@objc_msgSend);
|
||||
vmethod(Handle, sel_registerName(PChar(Str_setVersion)), aVersion);
|
||||
end;
|
||||
|
||||
{*************** Basic protocols ***************}
|
||||
|
||||
function NSObject.retain: objc.id;
|
||||
|
Loading…
Reference in New Issue
Block a user