Starts implementing image connection to TTrayIcon

git-svn-id: trunk@30387 -
This commit is contained in:
sekelsenmat 2011-04-19 18:31:40 +00:00
parent d3e86179db
commit 7381149462
2 changed files with 23 additions and 7 deletions

View File

@ -151,6 +151,17 @@ implementation
{ TCocoaBitmap }
type
// The following dummy categories fix bugs in the Cocoa bindings available in FPC
// Remove them when the FPC binding parser is fixed.
// More details:
// http://wiki.freepascal.org/FPC_PasCocoa/Differences#Sending_messages_to_id
// http://wiki.lazarus.freepascal.org/FPC_PasCocoa#Category_declaration
NSBitmapImageRepFix = objccategory external(NSBitmapImageRep)
function initWithBitmapDataPlanes_pixelsWide_pixelsHigh__colorSpaceName_bytesPerRow_bitsPerPixel(planes: PChar; width: NSInteger; height: NSInteger; bps: NSInteger; spp: NSInteger; alpha: Boolean; isPlanar_: Boolean; colorSpaceName_: NSString; rBytes: NSInteger; pBits: NSInteger): id; message 'initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bytesPerRow:bitsPerPixel:';
function initWithBitmapDataPlanes_pixelsWide_pixelsHigh__colorSpaceName_bitmapFormat_bytesPerRow_bitsPerPixel(planes: PChar; width: NSInteger; height: NSInteger; bps: NSInteger; spp: NSInteger; alpha: Boolean; isPlanar_: Boolean; colorSpaceName_: NSString; bitmapFormat_: NSBitmapFormat; rBytes: NSInteger; pBits: NSInteger): id; message 'initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bitmapFormat:bytesPerRow:bitsPerPixel:';
end;
{------------------------------------------------------------------------------
Method: TCocoaBitmap.Create
Params: AWidth - Bitmap width
@ -169,7 +180,7 @@ var
bitsPerSample: NSInteger; // How many bits in each color component
samplesPerPixel: NSInteger;// How many color components
begin
{ case ABitsPerPixel of
case ABitsPerPixel of
// Mono
1:
begin
@ -195,23 +206,23 @@ begin
end;
// Create the associated NSImageRep
imagerep := NSBitmapImageRep.alloc.initWithBitmapDataPlanes_pixelsWide_pixelsHigh_bitsPerSample_samplesPerPixel_hasAlpha_isPlanar_colorSpaceName_bytesPerRow_bitsPerPixel(
imagerep := NSBitmapImageRep(NSBitmapImageRep.alloc.initWithBitmapDataPlanes_pixelsWide_pixelsHigh__colorSpaceName_bitmapFormat_bytesPerRow_bitsPerPixel(
@AData, // planes, BitmapDataPlanes
AWidth, // width, pixelsWide
AHeight,// height, PixelsHigh
bitsPerSample,// bitsPerSample, bps
samplesPerPixel, // samplesPerPixel, sps
NO, // hasAlpha
NO, // isPlanar
False, // hasAlpha
False, // isPlanar
NSCalibratedRGBColorSpace, // colorSpaceName
0, // bitmapFormat
0, // bytesPerRow
ABitsPerPixel //bitsPerPixel
);
));
// Create the associated NSImage
image := NSImage.alloc.initWithSize(NSMakeSize(AWidth, AHeight));
image.addRepresentation(imagerep);}
image.addRepresentation(imagerep);
end;
{ TCocoaContext }

View File

@ -41,6 +41,7 @@ class function TCocoaWSCustomTrayIcon.Show(const ATrayIcon: TCustomTrayIcon): Bo
var
statusitem: NSStatusItem;
bar: NSStatusBar;
image: NSImage;
{var
APrivateTrayIcon: TPrivateCocoaCocoaTrayIcon;
ASize: NSSize;
@ -60,7 +61,11 @@ begin
// statusitem.bar := bar;
//statusicon.callback:=TLCLCommonCallback.Create(box, AWinControl);
statusitem.retain();
statusitem.setImage(TCocoaBitmap(ATrayIcon.icon.Handle).image);
if (ATrayIcon.icon <> nil) and (ATrayIcon.icon.Handle <> 0) then
begin
image := TCocoaBitmap(ATrayIcon.icon.Handle).image;
if image <> nil then statusitem.setImage(image);
end;
//Result:=TLCLIntfHandle(box);
// APrivateTrayIcon := TPrivateCocoaCocoaTrayIcon(ATrayIcon.Handle);