You've already forked lazarus-ccr
Improves the statusitem example.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@372 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
76
bindings/pascocoa/examples/statusitem/actions.pas
Normal file
76
bindings/pascocoa/examples/statusitem/actions.pas
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
{
|
||||||
|
actions.pas
|
||||||
|
|
||||||
|
This example project is released under public domain
|
||||||
|
|
||||||
|
AUTHORS: Felipe Monteiro de Carvalho
|
||||||
|
}
|
||||||
|
unit actions;
|
||||||
|
|
||||||
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
Classes, SysUtils, foundation, objc, appkit, FPCMacOSAll;
|
||||||
|
|
||||||
|
type
|
||||||
|
|
||||||
|
{ TMyActionList }
|
||||||
|
|
||||||
|
TMyActionList = class(NSObject)
|
||||||
|
public
|
||||||
|
{ Extra binding functions }
|
||||||
|
constructor Create; override;
|
||||||
|
procedure AddMethods;
|
||||||
|
{ Fields }
|
||||||
|
bar: NSStatusBar;
|
||||||
|
item: NSStatusItem;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ Objective-c Methods }
|
||||||
|
procedure doShowStatusitem(param1: objc.id; param2: SEL; param3: objc.id); cdecl;
|
||||||
|
|
||||||
|
var
|
||||||
|
actionList: TMyActionList;
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
{ TMyActionList }
|
||||||
|
|
||||||
|
procedure TMyActionList.AddMethods;
|
||||||
|
var
|
||||||
|
method_list: Pobjc_method_list;
|
||||||
|
begin
|
||||||
|
{ Adds methods to the class }
|
||||||
|
|
||||||
|
method_list := GetMem(SizeOf(objc_method_list)); { We can't free this until the last instance is freed }
|
||||||
|
|
||||||
|
method_list^.method_count := 1;
|
||||||
|
method_list^.method_list[0].method_name := sel_registerName('doShowStatusitem:');
|
||||||
|
{ The first parameter is the result (v = void),
|
||||||
|
followed by self and _cmd (@ = id and : = SEL),
|
||||||
|
and on the end "sender" (@ = id) }
|
||||||
|
method_list^.method_list[0].method_types := 'v@:@';
|
||||||
|
method_list^.method_list[0].method_imp := IMP(@doShowStatusitem);
|
||||||
|
class_addMethods(ClassId, method_list);
|
||||||
|
end;
|
||||||
|
|
||||||
|
constructor TMyActionList.Create;
|
||||||
|
begin
|
||||||
|
inherited Create;
|
||||||
|
|
||||||
|
AddMethods();
|
||||||
|
|
||||||
|
bar := NSStatusBar.systemStatusBar();
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ Objective-c Methods }
|
||||||
|
|
||||||
|
procedure doShowStatusitem(param1: objc.id; param2: SEL; param3: objc.id); cdecl;
|
||||||
|
begin
|
||||||
|
actionList.item := actionList.bar.statusItemWithLength(NSSquareStatusItemLength);
|
||||||
|
end;
|
||||||
|
|
||||||
|
end.
|
||||||
|
|
@ -7,7 +7,7 @@
|
|||||||
<MainUnit Value="0"/>
|
<MainUnit Value="0"/>
|
||||||
<IconPath Value="./"/>
|
<IconPath Value="./"/>
|
||||||
<TargetFileExt Value=""/>
|
<TargetFileExt Value=""/>
|
||||||
<ActiveEditorIndexAtStart Value="0"/>
|
<ActiveEditorIndexAtStart Value="1"/>
|
||||||
</General>
|
</General>
|
||||||
<VersionInfo>
|
<VersionInfo>
|
||||||
<ProjectVersion Value=""/>
|
<ProjectVersion Value=""/>
|
||||||
@ -26,15 +26,15 @@
|
|||||||
<LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
|
<LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
|
||||||
</local>
|
</local>
|
||||||
</RunParams>
|
</RunParams>
|
||||||
<Units Count="33">
|
<Units Count="34">
|
||||||
<Unit0>
|
<Unit0>
|
||||||
<Filename Value="statusitem.pas"/>
|
<Filename Value="statusitem.pas"/>
|
||||||
<IsPartOfProject Value="True"/>
|
<IsPartOfProject Value="True"/>
|
||||||
<UnitName Value="statusitem"/>
|
<UnitName Value="statusitem"/>
|
||||||
<CursorPos X="3" Y="47"/>
|
<CursorPos X="19" Y="26"/>
|
||||||
<TopLine Value="37"/>
|
<TopLine Value="54"/>
|
||||||
<EditorIndex Value="0"/>
|
<EditorIndex Value="0"/>
|
||||||
<UsageCount Value="36"/>
|
<UsageCount Value="37"/>
|
||||||
<Loaded Value="True"/>
|
<Loaded Value="True"/>
|
||||||
</Unit0>
|
</Unit0>
|
||||||
<Unit1>
|
<Unit1>
|
||||||
@ -60,7 +60,7 @@
|
|||||||
<Filename Value="../../appkit/NSAlert.inc"/>
|
<Filename Value="../../appkit/NSAlert.inc"/>
|
||||||
<CursorPos X="1" Y="12"/>
|
<CursorPos X="1" Y="12"/>
|
||||||
<TopLine Value="1"/>
|
<TopLine Value="1"/>
|
||||||
<UsageCount Value="19"/>
|
<UsageCount Value="20"/>
|
||||||
<Loaded Value="True"/>
|
<Loaded Value="True"/>
|
||||||
</Unit4>
|
</Unit4>
|
||||||
<Unit5>
|
<Unit5>
|
||||||
@ -124,8 +124,10 @@
|
|||||||
<Unit14>
|
<Unit14>
|
||||||
<Filename Value="../../appkit/NSControl.inc"/>
|
<Filename Value="../../appkit/NSControl.inc"/>
|
||||||
<CursorPos X="26" Y="147"/>
|
<CursorPos X="26" Y="147"/>
|
||||||
<TopLine Value="142"/>
|
<TopLine Value="145"/>
|
||||||
|
<EditorIndex Value="4"/>
|
||||||
<UsageCount Value="24"/>
|
<UsageCount Value="24"/>
|
||||||
|
<Loaded Value="True"/>
|
||||||
</Unit14>
|
</Unit14>
|
||||||
<Unit15>
|
<Unit15>
|
||||||
<Filename Value="/System/Library/Frameworks/AppKit.framework/Versions/C/Headers/NSView.h"/>
|
<Filename Value="/System/Library/Frameworks/AppKit.framework/Versions/C/Headers/NSView.h"/>
|
||||||
@ -158,16 +160,16 @@
|
|||||||
<UnitName Value="appkit"/>
|
<UnitName Value="appkit"/>
|
||||||
<CursorPos X="13" Y="21"/>
|
<CursorPos X="13" Y="21"/>
|
||||||
<TopLine Value="10"/>
|
<TopLine Value="10"/>
|
||||||
<EditorIndex Value="3"/>
|
<EditorIndex Value="5"/>
|
||||||
<UsageCount Value="18"/>
|
<UsageCount Value="19"/>
|
||||||
<Loaded Value="True"/>
|
<Loaded Value="True"/>
|
||||||
</Unit19>
|
</Unit19>
|
||||||
<Unit20>
|
<Unit20>
|
||||||
<Filename Value="../../appkit/NSWindow.inc"/>
|
<Filename Value="../../appkit/NSWindow.inc"/>
|
||||||
<CursorPos X="1" Y="522"/>
|
<CursorPos X="1" Y="522"/>
|
||||||
<TopLine Value="508"/>
|
<TopLine Value="21"/>
|
||||||
<EditorIndex Value="1"/>
|
<EditorIndex Value="2"/>
|
||||||
<UsageCount Value="14"/>
|
<UsageCount Value="15"/>
|
||||||
<Loaded Value="True"/>
|
<Loaded Value="True"/>
|
||||||
</Unit20>
|
</Unit20>
|
||||||
<Unit21>
|
<Unit21>
|
||||||
@ -216,24 +218,24 @@
|
|||||||
</Unit27>
|
</Unit27>
|
||||||
<Unit28>
|
<Unit28>
|
||||||
<Filename Value="../../foundation/NSObject.inc"/>
|
<Filename Value="../../foundation/NSObject.inc"/>
|
||||||
<CursorPos X="46" Y="102"/>
|
<CursorPos X="16" Y="7"/>
|
||||||
<TopLine Value="94"/>
|
<TopLine Value="1"/>
|
||||||
<EditorIndex Value="2"/>
|
<EditorIndex Value="3"/>
|
||||||
<UsageCount Value="10"/>
|
<UsageCount Value="11"/>
|
||||||
<Loaded Value="True"/>
|
<Loaded Value="True"/>
|
||||||
</Unit28>
|
</Unit28>
|
||||||
<Unit29>
|
<Unit29>
|
||||||
<Filename Value="../../appkit/NSStatusBar.inc"/>
|
<Filename Value="../../appkit/NSStatusBar.inc"/>
|
||||||
<CursorPos X="27" Y="15"/>
|
<CursorPos X="27" Y="15"/>
|
||||||
<TopLine Value="5"/>
|
<TopLine Value="36"/>
|
||||||
<EditorIndex Value="4"/>
|
<EditorIndex Value="6"/>
|
||||||
<UsageCount Value="14"/>
|
<UsageCount Value="15"/>
|
||||||
<Loaded Value="True"/>
|
<Loaded Value="True"/>
|
||||||
</Unit29>
|
</Unit29>
|
||||||
<Unit30>
|
<Unit30>
|
||||||
<Filename Value="../../foundation/NSAutoreleasePool.inc"/>
|
<Filename Value="../../foundation/NSAutoreleasePool.inc"/>
|
||||||
<CursorPos X="33" Y="43"/>
|
<CursorPos X="26" Y="19"/>
|
||||||
<TopLine Value="37"/>
|
<TopLine Value="13"/>
|
||||||
<UsageCount Value="10"/>
|
<UsageCount Value="10"/>
|
||||||
</Unit30>
|
</Unit30>
|
||||||
<Unit31>
|
<Unit31>
|
||||||
@ -248,20 +250,78 @@
|
|||||||
<TopLine Value="49"/>
|
<TopLine Value="49"/>
|
||||||
<UsageCount Value="12"/>
|
<UsageCount Value="12"/>
|
||||||
</Unit32>
|
</Unit32>
|
||||||
|
<Unit33>
|
||||||
|
<Filename Value="actions.pas"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
<UnitName Value="actions"/>
|
||||||
|
<CursorPos X="3" Y="61"/>
|
||||||
|
<TopLine Value="58"/>
|
||||||
|
<EditorIndex Value="1"/>
|
||||||
|
<UsageCount Value="21"/>
|
||||||
|
<Loaded Value="True"/>
|
||||||
|
</Unit33>
|
||||||
</Units>
|
</Units>
|
||||||
<JumpHistory Count="3" HistoryIndex="2">
|
<JumpHistory Count="15" HistoryIndex="14">
|
||||||
<Position1>
|
<Position1>
|
||||||
<Filename Value="statusitem.pas"/>
|
<Filename Value="statusitem.pas"/>
|
||||||
<Caret Line="80" Column="30" TopLine="69"/>
|
<Caret Line="38" Column="25" TopLine="29"/>
|
||||||
</Position1>
|
</Position1>
|
||||||
<Position2>
|
<Position2>
|
||||||
<Filename Value="../../appkit/NSWindow.inc"/>
|
<Filename Value="statusitem.pas"/>
|
||||||
<Caret Line="137" Column="17" TopLine="128"/>
|
<Caret Line="39" Column="22" TopLine="23"/>
|
||||||
</Position2>
|
</Position2>
|
||||||
<Position3>
|
<Position3>
|
||||||
<Filename Value="statusitem.pas"/>
|
<Filename Value="actions.pas"/>
|
||||||
<Caret Line="105" Column="15" TopLine="91"/>
|
<Caret Line="22" Column="1" TopLine="18"/>
|
||||||
</Position3>
|
</Position3>
|
||||||
|
<Position4>
|
||||||
|
<Filename Value="actions.pas"/>
|
||||||
|
<Caret Line="15" Column="41" TopLine="9"/>
|
||||||
|
</Position4>
|
||||||
|
<Position5>
|
||||||
|
<Filename Value="actions.pas"/>
|
||||||
|
<Caret Line="18" Column="33" TopLine="9"/>
|
||||||
|
</Position5>
|
||||||
|
<Position6>
|
||||||
|
<Filename Value="actions.pas"/>
|
||||||
|
<Caret Line="17" Column="31" TopLine="9"/>
|
||||||
|
</Position6>
|
||||||
|
<Position7>
|
||||||
|
<Filename Value="actions.pas"/>
|
||||||
|
<Caret Line="15" Column="59" TopLine="12"/>
|
||||||
|
</Position7>
|
||||||
|
<Position8>
|
||||||
|
<Filename Value="actions.pas"/>
|
||||||
|
<Caret Line="21" Column="3" TopLine="18"/>
|
||||||
|
</Position8>
|
||||||
|
<Position9>
|
||||||
|
<Filename Value="actions.pas"/>
|
||||||
|
<Caret Line="70" Column="1" TopLine="58"/>
|
||||||
|
</Position9>
|
||||||
|
<Position10>
|
||||||
|
<Filename Value="actions.pas"/>
|
||||||
|
<Caret Line="59" Column="12" TopLine="57"/>
|
||||||
|
</Position10>
|
||||||
|
<Position11>
|
||||||
|
<Filename Value="actions.pas"/>
|
||||||
|
<Caret Line="36" Column="1" TopLine="19"/>
|
||||||
|
</Position11>
|
||||||
|
<Position12>
|
||||||
|
<Filename Value="actions.pas"/>
|
||||||
|
<Caret Line="41" Column="14" TopLine="32"/>
|
||||||
|
</Position12>
|
||||||
|
<Position13>
|
||||||
|
<Filename Value="actions.pas"/>
|
||||||
|
<Caret Line="27" Column="1" TopLine="14"/>
|
||||||
|
</Position13>
|
||||||
|
<Position14>
|
||||||
|
<Filename Value="actions.pas"/>
|
||||||
|
<Caret Line="58" Column="15" TopLine="43"/>
|
||||||
|
</Position14>
|
||||||
|
<Position15>
|
||||||
|
<Filename Value="actions.pas"/>
|
||||||
|
<Caret Line="57" Column="1" TopLine="44"/>
|
||||||
|
</Position15>
|
||||||
</JumpHistory>
|
</JumpHistory>
|
||||||
</ProjectOptions>
|
</ProjectOptions>
|
||||||
<CompilerOptions>
|
<CompilerOptions>
|
||||||
|
@ -16,7 +16,7 @@ program statusitem;
|
|||||||
{$mode delphi}
|
{$mode delphi}
|
||||||
|
|
||||||
uses
|
uses
|
||||||
objc, ctypes, FPCMacOSAll, AppKit, Foundation;
|
objc, ctypes, FPCMacOSAll, AppKit, Foundation, actions;
|
||||||
|
|
||||||
const
|
const
|
||||||
Str_Window_Title = 'StatusItem example project';
|
Str_Window_Title = 'StatusItem example project';
|
||||||
@ -27,45 +27,10 @@ var
|
|||||||
MainWindow: NSWindow;
|
MainWindow: NSWindow;
|
||||||
MainWindowView: NSView;
|
MainWindowView: NSView;
|
||||||
MyButton: NSButton;
|
MyButton: NSButton;
|
||||||
bar: NSStatusBar;
|
|
||||||
item: NSStatusItem;
|
|
||||||
{ strings }
|
{ strings }
|
||||||
CFTitle, CFButtonText: CFStringRef;
|
CFTitle, CFButtonText: CFStringRef;
|
||||||
{ sizes }
|
{ sizes }
|
||||||
MainWindowRect, ButtonRect: NSRect;
|
MainWindowRect, ButtonRect: NSRect;
|
||||||
|
|
||||||
type
|
|
||||||
TMyWindow = class(NSWindow)
|
|
||||||
public
|
|
||||||
{ Extra binding functions }
|
|
||||||
function getClass: objc.id; override;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure doShowStatusitem(param1: objc.id; param2: SEL; param3: objc.id); cdecl;
|
|
||||||
begin
|
|
||||||
item := bar.statusItemWithLength(NSSquareStatusItemLength);
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TMyWindow.getClass: objc.id;
|
|
||||||
var
|
|
||||||
method_list: Pobjc_method_list;
|
|
||||||
begin
|
|
||||||
Result := objc_getClass(Str_NSWindow);
|
|
||||||
|
|
||||||
{ Adds methods to the class }
|
|
||||||
|
|
||||||
method_list := GetMem(SizeOf(objc_method_list)); { We can't free this until the last instance is freed }
|
|
||||||
|
|
||||||
method_list.method_count := 1;
|
|
||||||
method_list.method_list[0].method_name := sel_registerName('doShowStatusitem:');
|
|
||||||
{ The first parameter is the result (v = void),
|
|
||||||
followed by self and _cmd (@ = id and : = SEL),
|
|
||||||
and on the end "sender" (@ = id) }
|
|
||||||
method_list.method_list[0].method_types := 'v@:@';
|
|
||||||
method_list.method_list[0].method_imp := IMP(@doShowStatusitem);
|
|
||||||
class_addMethods(Result, method_list);
|
|
||||||
end;
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
{ Creates the AutoreleasePool }
|
{ Creates the AutoreleasePool }
|
||||||
pool := NSAutoreleasePool.Create;
|
pool := NSAutoreleasePool.Create;
|
||||||
@ -80,7 +45,7 @@ begin
|
|||||||
MainWindowRect.size.width := 300.0;
|
MainWindowRect.size.width := 300.0;
|
||||||
MainWindowRect.size.height := 500.0;
|
MainWindowRect.size.height := 500.0;
|
||||||
|
|
||||||
MainWindow := TMyWindow.initWithContentRect(MainWindowRect,
|
MainWindow := NSWindow.initWithContentRect(MainWindowRect,
|
||||||
NSTitledWindowMask or NSClosableWindowMask or NSMiniaturizableWindowMask or NSResizableWindowMask,
|
NSTitledWindowMask or NSClosableWindowMask or NSMiniaturizableWindowMask or NSResizableWindowMask,
|
||||||
NSBackingStoreBuffered, NO);
|
NSBackingStoreBuffered, NO);
|
||||||
MainWindowView := NSView.CreateWithHandle(MainWindow.contentView);
|
MainWindowView := NSView.CreateWithHandle(MainWindow.contentView);
|
||||||
@ -88,6 +53,10 @@ begin
|
|||||||
CFTitle := CFStringCreateWithPascalString(nil, Str_Window_Title, kCFStringEncodingUTF8);
|
CFTitle := CFStringCreateWithPascalString(nil, Str_Window_Title, kCFStringEncodingUTF8);
|
||||||
MainWindow.setTitle(CFTitle);
|
MainWindow.setTitle(CFTitle);
|
||||||
|
|
||||||
|
{ Initializes the action responding object }
|
||||||
|
|
||||||
|
actionList := TMyActionList.Create();
|
||||||
|
|
||||||
{ Puts some buttons on the window }
|
{ Puts some buttons on the window }
|
||||||
|
|
||||||
CFButtonText := CFStringCreateWithPascalString(nil, Str_Show_Button, kCFStringEncodingUTF8);
|
CFButtonText := CFStringCreateWithPascalString(nil, Str_Show_Button, kCFStringEncodingUTF8);
|
||||||
@ -99,13 +68,9 @@ begin
|
|||||||
MyButton.setStringValue(CFButtonText);
|
MyButton.setStringValue(CFButtonText);
|
||||||
MyButton.setBezelStyle(NSRoundedBezelStyle);
|
MyButton.setBezelStyle(NSRoundedBezelStyle);
|
||||||
MyButton.setAction(sel_registerName('doShowStatusitem:'));
|
MyButton.setAction(sel_registerName('doShowStatusitem:'));
|
||||||
MyButton.setTarget(MainWindow.Handle);
|
MyButton.setTarget(actionList.Handle);
|
||||||
MainWindowView.addSubview(MyButton);
|
MainWindowView.addSubview(MyButton);
|
||||||
|
|
||||||
{ Initializes the StatusBar object }
|
|
||||||
|
|
||||||
bar := NSStatusBar.systemStatusBar();
|
|
||||||
|
|
||||||
{ Enters main message loop }
|
{ Enters main message loop }
|
||||||
|
|
||||||
MainWindow.orderFrontRegardless;
|
MainWindow.orderFrontRegardless;
|
||||||
|
@ -21,7 +21,6 @@ const
|
|||||||
|
|
||||||
NSAutoreleasePool = class(NSObject)
|
NSAutoreleasePool = class(NSObject)
|
||||||
public
|
public
|
||||||
constructor Create; override;
|
|
||||||
{ Extra binding functions }
|
{ Extra binding functions }
|
||||||
function getClass: objc.id; override;
|
function getClass: objc.id; override;
|
||||||
public
|
public
|
||||||
@ -45,13 +44,5 @@ begin
|
|||||||
Result := objc_getClass(Str_NSAutoreleasePool);
|
Result := objc_getClass(Str_NSAutoreleasePool);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor NSAutoreleasePool.Create;
|
|
||||||
begin
|
|
||||||
{ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; }
|
|
||||||
ClassId := getClass();
|
|
||||||
allocbuf := objc_msgSend(ClassId, sel_registerName(PChar(Str_alloc)), []);
|
|
||||||
Handle := objc_msgSend(allocbuf, sel_registerName(PChar(Str_init)), []);
|
|
||||||
end;
|
|
||||||
|
|
||||||
{$endif}
|
{$endif}
|
||||||
|
|
||||||
|
@ -161,7 +161,9 @@ FOUNDATION_EXPORT unsigned NSExtraRefCount(id object);}
|
|||||||
|
|
||||||
constructor NSObject.Create;
|
constructor NSObject.Create;
|
||||||
begin
|
begin
|
||||||
|
ClassId := getClass();
|
||||||
|
allocbuf := objc_msgSend(ClassId, sel_registerName(PChar(Str_alloc)), []);
|
||||||
|
Handle := objc_msgSend(allocbuf, sel_registerName(PChar(Str_init)), []);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor NSObject.CreateWithHandle(aHandle: objc.id);
|
constructor NSObject.CreateWithHandle(aHandle: objc.id);
|
||||||
|
Reference in New Issue
Block a user