mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-15 12:19:13 +02:00
carbon: Implements updating the TTrayIcon icon with InternalUpdate
git-svn-id: trunk@21589 -
This commit is contained in:
parent
747eead0bb
commit
9723014358
@ -38,6 +38,7 @@ type
|
|||||||
ACallbackName: string; ACallbackClass: NSObject): NSMenuItem;
|
ACallbackName: string; ACallbackClass: NSObject): NSMenuItem;
|
||||||
procedure ReleaseMenu();
|
procedure ReleaseMenu();
|
||||||
procedure RemoveIcon();
|
procedure RemoveIcon();
|
||||||
|
function IconToNSImage(AIcon: TIcon): NSImage;
|
||||||
{ Objective-C compatible methods }
|
{ Objective-C compatible methods }
|
||||||
class procedure HandleMenuItemClick(_self: objc.id; _cmd: SEL; sender: objc.id); cdecl; //static;
|
class procedure HandleMenuItemClick(_self: objc.id; _cmd: SEL; sender: objc.id); cdecl; //static;
|
||||||
end;
|
end;
|
||||||
@ -245,6 +246,41 @@ begin
|
|||||||
bar.removeStatusItem(item.Handle);
|
bar.removeStatusItem(item.Handle);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TPrivateCocoaCarbonTrayIcon.IconToNSImage(AIcon: TIcon): NSImage;
|
||||||
|
var
|
||||||
|
ASize: NSSize;
|
||||||
|
ACGRect: CGRect;
|
||||||
|
AcurrentContext: NSGraphicsContext;
|
||||||
|
begin
|
||||||
|
Result := nil;
|
||||||
|
|
||||||
|
if (AIcon = nil) or (AIcon.Empty) then Exit;
|
||||||
|
|
||||||
|
{ Convert our CFImageRef to a NSImage }
|
||||||
|
|
||||||
|
ASize.width := TCarbonBitmap(AIcon.Handle).Width;
|
||||||
|
ASize.height := TCarbonBitmap(AIcon.Handle).Height;
|
||||||
|
ACGRect.size.width := ASize.width;
|
||||||
|
ACGRect.size.height := ASize.height;
|
||||||
|
ACGRect.origin.x := 0;
|
||||||
|
ACGRect.origin.y := 0;
|
||||||
|
|
||||||
|
Result := NSImage.initWithSize(ASize);
|
||||||
|
Result.setCacheMode(NSImageCacheNever);
|
||||||
|
Result.lockFocus;
|
||||||
|
AcurrentContext := NSGraphicsContext.currentContext();
|
||||||
|
CGContextDrawImage(AcurrentContext.graphicsPort, ACGRect, TCarbonBitmap(AIcon.Handle).CGImage);
|
||||||
|
{$ifdef VerboseCarbonTrayIcon}
|
||||||
|
WriteLn('::[TCarbonWSCustomTrayIcon.Show]',
|
||||||
|
' AcurrentContext ', IntToHex(PtrUInt(Pointer(AcurrentContext)), 8),
|
||||||
|
' AcurrentContext.ClassID ', IntToHex(Int64(AcurrentContext.ClassID), 8),
|
||||||
|
' AcurrentContext.Handle ', IntToHex(Int64(AcurrentContext.Handle), 8),
|
||||||
|
' AcurrentContext.graphicsPort ', IntToHex(Int64(AcurrentContext.graphicsPort), 8)
|
||||||
|
);
|
||||||
|
{$endif VerboseCarbonTrayIcon}
|
||||||
|
Result.unlockFocus;
|
||||||
|
end;
|
||||||
|
|
||||||
{ Here we try to get the LCL MenuItem from the Tag and then call
|
{ Here we try to get the LCL MenuItem from the Tag and then call
|
||||||
it's OnClick method }
|
it's OnClick method }
|
||||||
class procedure TPrivateCocoaCarbonTrayIcon.HandleMenuItemClick(_self: objc.id;
|
class procedure TPrivateCocoaCarbonTrayIcon.HandleMenuItemClick(_self: objc.id;
|
||||||
@ -279,9 +315,6 @@ end;
|
|||||||
class function TCarbonWSCustomTrayIcon.Show(const ATrayIcon: TCustomTrayIcon): Boolean;
|
class function TCarbonWSCustomTrayIcon.Show(const ATrayIcon: TCustomTrayIcon): Boolean;
|
||||||
var
|
var
|
||||||
APrivateTrayIcon: TPrivateCocoaCarbonTrayIcon;
|
APrivateTrayIcon: TPrivateCocoaCarbonTrayIcon;
|
||||||
ASize: NSSize;
|
|
||||||
ACGRect: CGRect;
|
|
||||||
AcurrentContext: NSGraphicsContext;
|
|
||||||
begin
|
begin
|
||||||
{$ifdef VerboseCarbonTrayIcon}
|
{$ifdef VerboseCarbonTrayIcon}
|
||||||
WriteLn(':>[TCarbonWSCustomTrayIcon.Show]');
|
WriteLn(':>[TCarbonWSCustomTrayIcon.Show]');
|
||||||
@ -298,29 +331,9 @@ begin
|
|||||||
|
|
||||||
ATrayIcon.Handle := PtrInt(APrivateTrayIcon);
|
ATrayIcon.Handle := PtrInt(APrivateTrayIcon);
|
||||||
|
|
||||||
{ Convert our CFImageRef to a NSImage }
|
{ Converts the icon to NSImage }
|
||||||
|
|
||||||
ASize.width := TCarbonBitmap(ATrayIcon.Icon.Handle).Width;
|
APrivateTrayIcon.image := APrivateTrayIcon.IconToNSImage(ATrayIcon.Icon);
|
||||||
ASize.height := TCarbonBitmap(ATrayIcon.Icon.Handle).Height;
|
|
||||||
ACGRect.size.width := ASize.width;
|
|
||||||
ACGRect.size.height := ASize.height;
|
|
||||||
ACGRect.origin.x := 0;
|
|
||||||
ACGRect.origin.y := 0;
|
|
||||||
|
|
||||||
APrivateTrayIcon.image := NSImage.initWithSize(ASize);
|
|
||||||
APrivateTrayIcon.image.setCacheMode(NSImageCacheNever);
|
|
||||||
APrivateTrayIcon.image.lockFocus;
|
|
||||||
AcurrentContext := NSGraphicsContext.currentContext();
|
|
||||||
CGContextDrawImage(AcurrentContext.graphicsPort, ACGRect, TCarbonBitmap(ATrayIcon.Icon.Handle).CGImage);
|
|
||||||
{$ifdef VerboseCarbonTrayIcon}
|
|
||||||
WriteLn('::[TCarbonWSCustomTrayIcon.Show]',
|
|
||||||
' AcurrentContext ', IntToHex(PtrUInt(Pointer(AcurrentContext)), 8),
|
|
||||||
' AcurrentContext.ClassID ', IntToHex(Int64(AcurrentContext.ClassID), 8),
|
|
||||||
' AcurrentContext.Handle ', IntToHex(Int64(AcurrentContext.Handle), 8),
|
|
||||||
' AcurrentContext.graphicsPort ', IntToHex(Int64(AcurrentContext.graphicsPort), 8)
|
|
||||||
);
|
|
||||||
{$endif VerboseCarbonTrayIcon}
|
|
||||||
APrivateTrayIcon.image.unlockFocus;
|
|
||||||
|
|
||||||
{ Shows the icon }
|
{ Shows the icon }
|
||||||
|
|
||||||
@ -335,7 +348,8 @@ begin
|
|||||||
if ATrayIcon.PopUpMenu <> nil then
|
if ATrayIcon.PopUpMenu <> nil then
|
||||||
begin
|
begin
|
||||||
APrivateTrayIcon.menu := APrivateTrayIcon.CreateMenu(ATrayIcon.PopUpMenu);
|
APrivateTrayIcon.menu := APrivateTrayIcon.CreateMenu(ATrayIcon.PopUpMenu);
|
||||||
APrivateTrayIcon.item.setMenu(APrivateTrayIcon.menu.Handle);
|
if APrivateTrayIcon.item <> nil then
|
||||||
|
APrivateTrayIcon.item.setMenu(APrivateTrayIcon.menu.Handle);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Result := True;
|
Result := True;
|
||||||
@ -363,6 +377,13 @@ begin
|
|||||||
// The update is only necessary for a visible TTrayIcon
|
// The update is only necessary for a visible TTrayIcon
|
||||||
if not ATrayIcon.Visible then Exit;
|
if not ATrayIcon.Visible then Exit;
|
||||||
|
|
||||||
|
{ Updates the image }
|
||||||
|
|
||||||
|
APrivateTrayIcon.image.Free;
|
||||||
|
|
||||||
|
APrivateTrayIcon.image := APrivateTrayIcon.IconToNSImage(ATrayIcon.Icon);
|
||||||
|
APrivateTrayIcon.item.setImage(APrivateTrayIcon.image.Handle);
|
||||||
|
|
||||||
{ Inserts the menu }
|
{ Inserts the menu }
|
||||||
|
|
||||||
APrivateTrayIcon.ReleaseMenu();
|
APrivateTrayIcon.ReleaseMenu();
|
||||||
|
Loading…
Reference in New Issue
Block a user