Improves Carbon-Cocoa TTrayIcon implementation

git-svn-id: trunk@15152 -
This commit is contained in:
sekelsenmat 2008-05-15 10:15:06 +00:00
parent 234a0df160
commit b7864b218e
5 changed files with 177 additions and 115 deletions

View File

@ -1,68 +1,71 @@
<?xml version="1.0"?>
<CONFIG>
<ProjectOptions>
<PathDelim Value="\"/>
<Version Value="6"/>
<General>
<Flags>
<SaveClosedFiles Value="False"/>
<SaveOnlyProjectUnits Value="True"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<IconPath Value=".\"/>
<TargetFileExt Value=""/>
</General>
<PublishOptions>
<Version Value="2"/>
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
<ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/>
</PublishOptions>
<RunParams>
<local>
<FormatVersion Value="1"/>
<LaunchingApplication PathPlusParams="\usr\X11R6\bin\xterm -T 'Lazarus Run Output' -e $(LazarusDir)\tools\runwait.sh $(TargetCmdLine)"/>
</local>
</RunParams>
<RequiredPackages Count="1">
<Item1>
<PackageName Value="LCL"/>
</Item1>
</RequiredPackages>
<Units Count="3">
<Unit0>
<Filename Value="wndtray.dpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="wndtray"/>
</Unit0>
<Unit1>
<Filename Value="frmtest.pas"/>
<ComponentName Value="Form1"/>
<HasResources Value="True"/>
<IsPartOfProject Value="True"/>
<ResourceFilename Value="frmtest.lrs"/>
<UnitName Value="frmtest"/>
</Unit1>
<Unit2>
<Filename Value="wscommontrayicon.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="wscommontrayicon"/>
</Unit2>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="5"/>
<PathDelim Value="\"/>
<CodeGeneration>
<Generate Value="Faster"/>
</CodeGeneration>
<Linking>
<Options>
<LinkerOptions Value="-framework Qt4Intf -framework carbon -lobjc"/>
</Options>
</Linking>
<Other>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
</CONFIG>
<?xml version="1.0"?>
<CONFIG>
<ProjectOptions>
<PathDelim Value="/"/>
<Version Value="6"/>
<General>
<Flags>
<SaveClosedFiles Value="False"/>
<SaveOnlyProjectUnits Value="True"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<IconPath Value="./"/>
<TargetFileExt Value=""/>
</General>
<PublishOptions>
<Version Value="2"/>
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
<ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/>
</PublishOptions>
<RunParams>
<local>
<FormatVersion Value="1"/>
<LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
</local>
</RunParams>
<RequiredPackages Count="1">
<Item1>
<PackageName Value="LCL"/>
</Item1>
</RequiredPackages>
<Units Count="3">
<Unit0>
<Filename Value="wndtray.dpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="wndtray"/>
</Unit0>
<Unit1>
<Filename Value="frmtest.pas"/>
<ComponentName Value="Form1"/>
<HasResources Value="True"/>
<IsPartOfProject Value="True"/>
<ResourceBaseClass Value="Form"/>
<ResourceFilename Value="frmtest.lrs"/>
<UnitName Value="frmtest"/>
</Unit1>
<Unit2>
<Filename Value="wscommontrayicon.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="wscommontrayicon"/>
</Unit2>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="5"/>
<SearchPaths>
<SrcPath Value="/Users/felipe/Programas/lazarus-ccr/bindings/objc/;/Users/felipe/Programas/lazarus-ccr/bindings/pascocoa/applicationservices/coregraphics/;/Users/felipe/Programas/lazarus-ccr/bindings/pascocoa/appkit/;/Users/felipe/Programas/lazarus-ccr/bindings/pascocoa/foundation/"/>
</SearchPaths>
<CodeGeneration>
<Generate Value="Faster"/>
</CodeGeneration>
<Linking>
<Options>
<LinkerOptions Value="-framework Qt4Intf -framework carbon -lobjc"/>
</Options>
</Linking>
<Other>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
</CONFIG>

View File

@ -1,37 +1,38 @@
<?xml version="1.0"?>
<CONFIG>
<ProjectSession>
<PathDelim Value="\"/>
<Version Value="6"/>
<Units Count="3">
<Unit0>
<Filename Value="wndtray.dpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="wndtray"/>
<UsageCount Value="23"/>
</Unit0>
<Unit1>
<Filename Value="frmtest.pas"/>
<ComponentName Value="Form1"/>
<HasResources Value="True"/>
<IsPartOfProject Value="True"/>
<ResourceFilename Value="frmtest.lrs"/>
<UnitName Value="frmtest"/>
<CursorPos X="7" Y="51"/>
<TopLine Value="60"/>
<EditorIndex Value="0"/>
<UsageCount Value="23"/>
<Loaded Value="True"/>
</Unit1>
<Unit2>
<Filename Value="wscommontrayicon.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="wscommontrayicon"/>
<UsageCount Value="23"/>
</Unit2>
</Units>
<General>
<ActiveEditorIndexAtStart Value="0"/>
</General>
</ProjectSession>
</CONFIG>
<?xml version="1.0"?>
<CONFIG>
<ProjectSession>
<PathDelim Value="/"/>
<Version Value="6"/>
<Units Count="3">
<Unit0>
<Filename Value="wndtray.dpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="wndtray"/>
<UsageCount Value="23"/>
</Unit0>
<Unit1>
<Filename Value="frmtest.pas"/>
<ComponentName Value="Form1"/>
<HasResources Value="True"/>
<IsPartOfProject Value="True"/>
<ResourceBaseClass Value="Form"/>
<ResourceFilename Value="frmtest.lrs"/>
<UnitName Value="frmtest"/>
<CursorPos X="69" Y="67"/>
<TopLine Value="126"/>
<EditorIndex Value="0"/>
<UsageCount Value="23"/>
<Loaded Value="True"/>
</Unit1>
<Unit2>
<Filename Value="wscommontrayicon.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="wscommontrayicon"/>
<UsageCount Value="23"/>
</Unit2>
</Units>
<General>
<ActiveEditorIndexAtStart Value="0"/>
</General>
</ProjectSession>
</CONFIG>

View File

@ -36,19 +36,23 @@ interface
{$I carbondebug.inc}
uses
// rtl+ftl
// rtl+ftl
Types, Classes, SysUtils, Math, FPCAdds,
// carbon bindings
// carbon bindings
FPCMacOSAll,
// interfacebase
// Cocoa bindings
{$ifdef CarbonUseCocoa}
foundation,
{$endif}
// interfacebase
InterfaceBase,
// widgetset
// widgetset
CarbonGDIObjects,
{$ifdef DebugBitmaps}
CarbonDebug,
{$endif}
glgrab,
// LCL
{$ifdef DebugBitmaps}
CarbonDebug,
{$endif}
glgrab,
// LCL
LCLStrConsts, LMessages, LCLMessageGlue, LCLProc, LCLIntf, LCLType,
GraphType, GraphMath, Graphics, Controls, Forms, Dialogs, Menus, Maps, Themes;
@ -68,6 +72,10 @@ type
FOpenEventHandlerUPP: AEEventHandlerUPP;
FQuitEventHandlerUPP: AEEventHandlerUPP;
{$ifdef CarbonUseCocoa}
pool: NSAutoreleasePool;
{$endif}
function RawImage_DescriptionFromCarbonBitmap(out ADesc: TRawImageDescription; ABitmap: TCarbonBitmap): Boolean;
function RawImage_FromCarbonBitmap(out ARawImage: TRawImage; ABitmap, AMask: TCarbonBitmap; const ARect: TRect): Boolean;
function GetImagePixelData(AImage: CGImageRef; var bitmapByteCount: PtrUInt): Pointer;

View File

@ -538,6 +538,11 @@ begin
FCaptureWidget := 0;
RegisterEvents;
// if using Cocoa, we need an autorelease pool
{$ifdef CarbonUseCocoa}
pool := NSAutoreleasePool.Create;
{$endif}
end;
{------------------------------------------------------------------------------
@ -553,6 +558,11 @@ begin
inherited Destroy;
CarbonWidgetSet := nil;
// if using Cocoa, release autorelease the pool
{$ifdef CarbonUseCocoa}
if pool <> nil then pool := NSAutoreleasePool.Create;
{$endif}
end;
{------------------------------------------------------------------------------

View File

@ -5,7 +5,7 @@
{ TCarbonWSCustomTrayIcon }
type
TPrivateTrayIcon = class(NSObject)
TPrivateCocoaCarbonTrayIcon = class(TObject)
public
{ Fields }
bar: NSStatusBar;
@ -14,12 +14,52 @@ type
end;
class function TCarbonWSCustomTrayIcon.Hide(const ATrayIcon: TCustomTrayIcon): Boolean;
var
APrivateTrayIcon: TPrivateCocoaCarbonTrayIcon;
begin
APrivateTrayIcon := TPrivateCocoaCarbonTrayIcon(ATrayIcon.Handle);
if APrivateTrayIcon.item <> nil then
begin
APrivateTrayIcon.item.Free;
APrivateTrayIcon.item := nil;
end;
Result := True;
end;
class function TCarbonWSCustomTrayIcon.Show(const ATrayIcon: TCustomTrayIcon): Boolean;
var
APrivateTrayIcon: TPrivateCocoaCarbonTrayIcon;
begin
Result := False;
{ Creates the handle }
APrivateTrayIcon := TPrivateCocoaCarbonTrayIcon.Create;
APrivateTrayIcon.bar := NSStatusBar.systemStatusBar();
ATrayIcon.Handle := PtrInt(APrivateTrayIcon);
{ Convert our CFImageRef to a NSImage }
{ NSImage* image = [[NSImage alloc] initWithSize:rect.size];
[image lockFocus];
CGContextDrawImage([[NSGraphicsContext currentContext]
graphicsPort], *(CGRect*)&rect, imageRef);
[image unlockFocus];}
// APrivateTrayIcon.image := NSImage.initWithSize_rect_size
{ Shows the icon }
if APrivateTrayIcon.item <> nil then Exit;
APrivateTrayIcon.item := APrivateTrayIcon.bar.statusItemWithLength(NSSquareStatusItemLength);
APrivateTrayIcon.item.retain();
APrivateTrayIcon.item.setImage(APrivateTrayIcon.image);
Result := True;
end;