Improves controller of the statusitem example.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@377 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
sekelsenmat
2008-03-12 01:29:11 +00:00
parent d3b0c99a9c
commit 43d2119108
3 changed files with 63 additions and 63 deletions

View File

@ -7,7 +7,7 @@
} }
unit controller; unit controller;
{$mode objfpc}{$H+} {$mode delphi}
interface interface
@ -23,49 +23,49 @@ type
{ Extra binding functions } { Extra binding functions }
constructor Create; override; constructor Create; override;
procedure AddMethods; procedure AddMethods;
{ Objective-c Methods }
class procedure doShowStatusitem(_self: objc.id; _cmd: SEL; sender: objc.id); cdecl;
class procedure doHideStatusitem(_self: objc.id; _cmd: SEL; sender: objc.id); cdecl;
class function applicationShouldTerminateAfterLastWindowClosed(_self: objc.id;
_cmd: SEL; theApplication: objc.id): cbool; cdecl;
{ Other helper functions }
function GetResourcesDir: string;
function CreateButton(AView: NSView; ATitle: shortstring;
AX, AY, AWidth, AHeight: Double;
ACallbackName: string; ACallbackClass: NSObject): NSButton;
{ Fields } { Fields }
bar: NSStatusBar; bar: NSStatusBar;
item: NSStatusItem; item: NSStatusItem;
image: NSImage; image: NSImage;
end; end;
{ Objective-c Methods }
procedure doShowStatusitem(param1: objc.id; param2: SEL; sender: objc.id); cdecl;
procedure doHideStatusitem(param1: objc.id; param2: SEL; sender: objc.id); cdecl;
function applicationShouldTerminateAfterLastWindowClosed(param1: objc.id;
param2: SEL; theApplication: objc.id): cbool; cdecl;
var
myController: TMyController;
const const
Str_doShowStatusitem = 'doShowStatusitem:'; Str_doShowStatusitem = 'doShowStatusitem:';
Str_doHideStatusitem = 'doHideStatusitem:'; Str_doHideStatusitem = 'doHideStatusitem:';
Str_applicationShouldTerminateAfterLastWindowClosed = 'applicationShouldTerminateAfterLastWindowClosed:'; Str_applicationShouldTerminateAfterLastWindowClosed = 'applicationShouldTerminateAfterLastWindowClosed:';
{ Other helper functions } var
function GetResourcesDir: string; myController: TMyController;
function CreateButton(AView: NSView; ATitle: shortstring;
AX, AY, AWidth, AHeight: Double;
ACallbackName: string; ACallbackClass: NSObject): NSButton;
implementation implementation
{ TMyController } { TMyController }
{ Adds methods to the class } {@@
procedure TMyController.AddMethods; Adds methods to the class
begin
{ Parameters string: Details of the parameters string:
The first parameter is the result (v = void), The first parameter is the result (v = void),
followed by self and _cmd (@ = id and : = SEL), followed by self and _cmd (@ = id and : = SEL),
and on the end "sender" (@ = id) } and on the end "sender" (@ = id)
}
AddMethod(Str_doShowStatusItem, 'v@:@', @doShowStatusitem); procedure TMyController.AddMethods;
AddMethod(Str_doHideStatusitem, 'v@:@', @doHideStatusitem); begin
AddMethod(Str_doShowStatusItem, 'v@:@', Pointer(doShowStatusitem));
AddMethod(Str_doHideStatusitem, 'v@:@', Pointer(doHideStatusitem));
AddMethod(Str_applicationShouldTerminateAfterLastWindowClosed, 'b@:@', AddMethod(Str_applicationShouldTerminateAfterLastWindowClosed, 'b@:@',
@applicationShouldTerminateAfterLastWindowClosed); Pointer(applicationShouldTerminateAfterLastWindowClosed));
end; end;
constructor TMyController.Create; constructor TMyController.Create;
@ -84,7 +84,7 @@ end;
{ Objective-c Methods } { Objective-c Methods }
procedure doShowStatusitem(param1: objc.id; param2: SEL; sender: objc.id); cdecl; class procedure TMyController.doShowStatusitem(_self: objc.id; _cmd: SEL; sender: objc.id); cdecl;
begin begin
if myController.item <> nil then Exit; if myController.item <> nil then Exit;
@ -93,7 +93,7 @@ begin
myController.item.setImage(myController.image); myController.item.setImage(myController.image);
end; end;
procedure doHideStatusitem(param1: objc.id; param2: SEL; sender: objc.id); cdecl; class procedure TMyController.doHideStatusitem(_self: objc.id; _cmd: SEL; sender: objc.id); cdecl;
begin begin
if myController.item = nil then Exit; if myController.item = nil then Exit;
@ -101,15 +101,15 @@ begin
myController.item := nil; myController.item := nil;
end; end;
function applicationShouldTerminateAfterLastWindowClosed(param1: objc.id; class function TMyController.applicationShouldTerminateAfterLastWindowClosed(_self: objc.id;
param2: SEL; theApplication: objc.id): cbool; cdecl; _cmd: SEL; theApplication: objc.id): cbool; cdecl;
begin begin
Result := objc.YES; Result := objc.YES;
end; end;
{ Other helper functions } { Other helper functions }
function GetResourcesDir: string; function TMyController.GetResourcesDir: string;
const const
BundleResourcesDirectory = '/Contents/Resources/'; BundleResourcesDirectory = '/Contents/Resources/';
var var
@ -127,7 +127,7 @@ begin
Result := pathStr + BundleResourcesDirectory; Result := pathStr + BundleResourcesDirectory;
end; end;
function CreateButton(AView: NSView; ATitle: shortstring; function TMyController.CreateButton(AView: NSView; ATitle: shortstring;
AX, AY, AWidth, AHeight: Double; AX, AY, AWidth, AHeight: Double;
ACallbackName: string; ACallbackClass: NSObject): NSButton; ACallbackName: string; ACallbackClass: NSObject): NSButton;
var var

View File

@ -31,10 +31,10 @@
<Filename Value="statusitem.pas"/> <Filename Value="statusitem.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="statusitem"/> <UnitName Value="statusitem"/>
<CursorPos X="24" Y="71"/> <CursorPos X="18" Y="36"/>
<TopLine Value="59"/> <TopLine Value="1"/>
<EditorIndex Value="0"/> <EditorIndex Value="0"/>
<UsageCount Value="42"/> <UsageCount Value="44"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit0> </Unit0>
<Unit1> <Unit1>
@ -55,14 +55,14 @@
<CursorPos X="3" Y="140"/> <CursorPos X="3" Y="140"/>
<TopLine Value="130"/> <TopLine Value="130"/>
<EditorIndex Value="5"/> <EditorIndex Value="5"/>
<UsageCount Value="12"/> <UsageCount Value="13"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit3> </Unit3>
<Unit4> <Unit4>
<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="23"/> <UsageCount Value="24"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit4> </Unit4>
<Unit5> <Unit5>
@ -70,15 +70,15 @@
<CursorPos X="1" Y="129"/> <CursorPos X="1" Y="129"/>
<TopLine Value="113"/> <TopLine Value="113"/>
<EditorIndex Value="2"/> <EditorIndex Value="2"/>
<UsageCount Value="16"/> <UsageCount Value="17"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit5> </Unit5>
<Unit6> <Unit6>
<Filename Value="../../appkit/AppKit.inc"/> <Filename Value="../../appkit/AppKit.inc"/>
<CursorPos X="23" Y="56"/> <CursorPos X="10" Y="39"/>
<TopLine Value="44"/> <TopLine Value="21"/>
<EditorIndex Value="9"/> <EditorIndex Value="8"/>
<UsageCount Value="14"/> <UsageCount Value="15"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit6> </Unit6>
<Unit7> <Unit7>
@ -162,10 +162,10 @@
<Unit19> <Unit19>
<Filename Value="../../appkit/appkit.pas"/> <Filename Value="../../appkit/appkit.pas"/>
<UnitName Value="appkit"/> <UnitName Value="appkit"/>
<CursorPos X="13" Y="21"/> <CursorPos X="10" Y="39"/>
<TopLine Value="15"/> <TopLine Value="21"/>
<EditorIndex Value="8"/> <EditorIndex Value="8"/>
<UsageCount Value="22"/> <UsageCount Value="23"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit19> </Unit19>
<Unit20> <Unit20>
@ -173,7 +173,7 @@
<CursorPos X="17" Y="99"/> <CursorPos X="17" Y="99"/>
<TopLine Value="92"/> <TopLine Value="92"/>
<EditorIndex Value="4"/> <EditorIndex Value="4"/>
<UsageCount Value="18"/> <UsageCount Value="19"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit20> </Unit20>
<Unit21> <Unit21>
@ -228,10 +228,10 @@
</Unit28> </Unit28>
<Unit29> <Unit29>
<Filename Value="../../appkit/NSStatusBar.inc"/> <Filename Value="../../appkit/NSStatusBar.inc"/>
<CursorPos X="10" Y="61"/> <CursorPos X="10" Y="39"/>
<TopLine Value="36"/> <TopLine Value="21"/>
<EditorIndex Value="10"/> <EditorIndex Value="8"/>
<UsageCount Value="18"/> <UsageCount Value="19"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit29> </Unit29>
<Unit30> <Unit30>
@ -251,17 +251,17 @@
<CursorPos X="10" Y="82"/> <CursorPos X="10" Y="82"/>
<TopLine Value="73"/> <TopLine Value="73"/>
<EditorIndex Value="6"/> <EditorIndex Value="6"/>
<UsageCount Value="13"/> <UsageCount Value="14"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit32> </Unit32>
<Unit33> <Unit33>
<Filename Value="controller.pas"/> <Filename Value="controller.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="controller"/> <UnitName Value="controller"/>
<CursorPos X="42" Y="92"/> <CursorPos X="6" Y="105"/>
<TopLine Value="83"/> <TopLine Value="92"/>
<EditorIndex Value="1"/> <EditorIndex Value="1"/>
<UsageCount Value="26"/> <UsageCount Value="28"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit33> </Unit33>
<Unit34> <Unit34>
@ -276,7 +276,7 @@
<CursorPos X="1" Y="185"/> <CursorPos X="1" Y="185"/>
<TopLine Value="169"/> <TopLine Value="169"/>
<EditorIndex Value="3"/> <EditorIndex Value="3"/>
<UsageCount Value="25"/> <UsageCount Value="26"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit35> </Unit35>
<Unit36> <Unit36>
@ -284,7 +284,7 @@
<CursorPos X="14" Y="35"/> <CursorPos X="14" Y="35"/>
<TopLine Value="113"/> <TopLine Value="113"/>
<EditorIndex Value="7"/> <EditorIndex Value="7"/>
<UsageCount Value="12"/> <UsageCount Value="13"/>
<Loaded Value="True"/> <Loaded Value="True"/>
<SyntaxHighlighter Value="C++"/> <SyntaxHighlighter Value="C++"/>
</Unit36> </Unit36>
@ -295,20 +295,20 @@
<Caret Line="1" Column="1" TopLine="1"/> <Caret Line="1" Column="1" TopLine="1"/>
</Position1> </Position1>
<Position2> <Position2>
<Filename Value="../../appkit/NSApplication.inc"/> <Filename Value="controller.pas"/>
<Caret Line="3" Column="37" TopLine="1"/> <Caret Line="71" Column="17" TopLine="69"/>
</Position2> </Position2>
<Position3> <Position3>
<Filename Value="controller.pas"/> <Filename Value="controller.pas"/>
<Caret Line="61" Column="22" TopLine="43"/> <Caret Line="10" Column="14" TopLine="1"/>
</Position3> </Position3>
<Position4> <Position4>
<Filename Value="controller.pas"/> <Filename Value="controller.pas"/>
<Caret Line="99" Column="15" TopLine="85"/> <Caret Line="65" Column="69" TopLine="55"/>
</Position4> </Position4>
<Position5> <Position5>
<Filename Value="controller.pas"/> <Filename Value="statusitem.pas"/>
<Caret Line="90" Column="36" TopLine="81"/> <Caret Line="70" Column="13" TopLine="25"/>
</Position5> </Position5>
</JumpHistory> </JumpHistory>
</ProjectOptions> </ProjectOptions>

View File

@ -58,11 +58,11 @@ begin
{ Adds the buttons } { Adds the buttons }
CreateButton(MainWindowView, Str_Show_Button, myController.CreateButton(MainWindowView, Str_Show_Button,
50.0, MainWindowRect.size.height - 50.0, 200.0, 25.0, 50.0, MainWindowRect.size.height - 50.0, 200.0, 25.0,
Str_doShowStatusItem, myController); Str_doShowStatusItem, myController);
CreateButton(MainWindowView, Str_Hide_Button, myController.CreateButton(MainWindowView, Str_Hide_Button,
50.0, MainWindowRect.size.height - 100.0, 200.0, 25.0, 50.0, MainWindowRect.size.height - 100.0, 200.0, 25.0,
Str_doHideStatusItem, myController); Str_doHideStatusItem, myController);