diff --git a/bindings/pascocoa/appkit/NSApplication.inc b/bindings/pascocoa/appkit/NSApplication.inc
index 4da11ebd4..9407d5546 100644
--- a/bindings/pascocoa/appkit/NSApplication.inc
+++ b/bindings/pascocoa/appkit/NSApplication.inc
@@ -45,15 +45,6 @@ const
// threading information
//typedef struct NSThreadPrivate _NSThreadPrivate;
-const
- Str_NSApplication = 'NSApplication';
-
- Str_sharedApplication = 'sharedApplication';
- Str_run = 'run';
- Str_runModalForWindow = 'runModalForWindow:';
-
- Str_orderFrontStandardAboutPanelWithOptions = 'orderFrontStandardAboutPanelWithOptions:';
-
{ An Application's startup function }
//APPKIT_EXTERN int NSApplicationMain(int argc, const char *argv[]);
@@ -94,6 +85,17 @@ APPKIT_EXTERN NSString *NSApplicationWillUpdateNotification;
APPKIT_EXTERN NSString *NSApplicationWillTerminateNotification;
APPKIT_EXTERN NSString *NSApplicationDidChangeScreenParametersNotification; }
+{ Class and method name strings }
+const
+ Str_NSApplication = 'NSApplication';
+
+ Str_sharedApplication = 'sharedApplication';
+ Str_setDelegate = 'setDelegate:';
+ Str_run = 'run';
+ Str_runModalForWindow = 'runModalForWindow:';
+
+ Str_orderFrontStandardAboutPanelWithOptions = 'orderFrontStandardAboutPanelWithOptions:';
+
{$endif}
{$endif}
{$ifdef CLASSES}
@@ -116,8 +118,8 @@ APPKIT_EXTERN NSString *NSApplicationDidChangeScreenParametersNotification; }
public
constructor sharedApplication;
-{- (void)setDelegate:(id)anObject;
-- (id)delegate;
+ procedure setDelegate(anObject: NSObject);
+{- (id)delegate;
- (NSGraphicsContext*)context;
- (void)hide:(id)sender;
- (void)unhide:(id)sender;
@@ -372,6 +374,16 @@ begin
Handle := objc_msgSend(ClassId, sel_registerName(PChar(Str_sharedApplication)), []);
end;
+procedure NSApplication.setDelegate(anObject: NSObject);
+type
+ setDelegate_t = procedure (param1: objc.id; param2: SEL; param3: objc.id); cdecl;
+var
+ vmethod: setDelegate_t;
+begin
+ vmethod := setDelegate_t(@objc_msgSend);
+ vmethod(Handle, sel_registerName(PChar(Str_setDelegate)), anObject.Handle);
+end;
+
procedure NSApplication.run;
begin
objc_msgSend(Handle, sel_registerName(PChar(Str_run)), []);
diff --git a/bindings/pascocoa/examples/statusitem/actions.pas b/bindings/pascocoa/examples/statusitem/controller.pas
similarity index 60%
rename from bindings/pascocoa/examples/statusitem/actions.pas
rename to bindings/pascocoa/examples/statusitem/controller.pas
index 86dfb023d..745323d13 100644
--- a/bindings/pascocoa/examples/statusitem/actions.pas
+++ b/bindings/pascocoa/examples/statusitem/controller.pas
@@ -1,11 +1,11 @@
{
- actions.pas
+ controller.pas
This example project is released under public domain
AUTHORS: Felipe Monteiro de Carvalho
}
-unit actions;
+unit controller;
{$mode objfpc}{$H+}
@@ -16,9 +16,9 @@ uses
type
- { TMyActionList }
+ { TMyController }
- TMyActionList = class(NSObject)
+ TMyController = class(NSObject)
public
{ Extra binding functions }
constructor Create; override;
@@ -30,11 +30,18 @@ type
end;
{ Objective-c Methods }
-procedure doShowStatusitem(param1: objc.id; param2: SEL; param3: objc.id); cdecl;
-procedure doHideStatusitem(param1: objc.id; param2: SEL; param3: objc.id); cdecl;
+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
- actionList: TMyActionList;
+ myController: TMyController;
+
+const
+ Str_doShowStatusitem = 'doShowStatusitem:';
+ Str_doHideStatusitem = 'doHideStatusitem:';
+ Str_applicationShouldTerminateAfterLastWindowClosed = 'applicationShouldTerminateAfterLastWindowClosed:';
{ Other helper functions }
function GetResourcesDir: string;
@@ -44,10 +51,10 @@ function CreateButton(AView: NSView; ATitle: shortstring;
implementation
-{ TMyActionList }
+{ TMyController }
{ Adds methods to the class }
-procedure TMyActionList.AddMethods;
+procedure TMyController.AddMethods;
begin
{ Parameters string:
@@ -55,11 +62,13 @@ begin
followed by self and _cmd (@ = id and : = SEL),
and on the end "sender" (@ = id) }
- AddMethod('doShowStatusitem:', 'v@:@', @doShowStatusitem);
- AddMethod('doHideStatusitem:', 'v@:@', @doHideStatusitem);
+ AddMethod(Str_doShowStatusItem, 'v@:@', @doShowStatusitem);
+ AddMethod(Str_doHideStatusitem, 'v@:@', @doHideStatusitem);
+ AddMethod(Str_applicationShouldTerminateAfterLastWindowClosed, 'b@:@',
+ @applicationShouldTerminateAfterLastWindowClosed);
end;
-constructor TMyActionList.Create;
+constructor TMyController.Create;
var
fileName: CFStringRef;
begin
@@ -69,28 +78,33 @@ begin
bar := NSStatusBar.systemStatusBar();
- fileName := CFStringCreateWithPascalString(nil,
- GetResourcesDir + 'icon.ico', kCFStringEncodingUTF8);
+ fileName := CFStringCreateWithPascalString(nil, GetResourcesDir + 'icon.ico', kCFStringEncodingUTF8);
image := NSImage.initWithContentsOfFile(fileName);
end;
{ Objective-c Methods }
-procedure doShowStatusitem(param1: objc.id; param2: SEL; param3: objc.id); cdecl;
+procedure doShowStatusitem(param1: objc.id; param2: SEL; sender: objc.id); cdecl;
begin
- if actionList.item <> nil then Exit;
+ if myController.item <> nil then Exit;
- actionList.item := actionList.bar.statusItemWithLength(NSSquareStatusItemLength);
- actionList.item.retain();
- actionList.item.setImage(actionList.image);
+ myController.item := myController.bar.statusItemWithLength(NSSquareStatusItemLength);
+ myController.item.retain();
+ myController.item.setImage(myController.image);
end;
-procedure doHideStatusitem(param1: objc.id; param2: SEL; param3: objc.id); cdecl;
+procedure doHideStatusitem(param1: objc.id; param2: SEL; sender: objc.id); cdecl;
begin
- if actionList.item = nil then Exit;
+ if myController.item = nil then Exit;
- actionList.item.Free;
- actionList.item := nil;
+ myController.item.Free;
+ myController.item := nil;
+end;
+
+function applicationShouldTerminateAfterLastWindowClosed(param1: objc.id;
+ param2: SEL; theApplication: objc.id): cbool; cdecl;
+begin
+ Result := objc.YES;
end;
{ Other helper functions }
diff --git a/bindings/pascocoa/examples/statusitem/statusitem.lpi b/bindings/pascocoa/examples/statusitem/statusitem.lpi
index c711d662f..dbae0221d 100644
--- a/bindings/pascocoa/examples/statusitem/statusitem.lpi
+++ b/bindings/pascocoa/examples/statusitem/statusitem.lpi
@@ -31,10 +31,10 @@
-
-
+
+
-
+
@@ -52,23 +52,25 @@
-
-
-
+
+
+
+
+
-
+
-
-
+
+
-
+
@@ -76,7 +78,7 @@
-
+
@@ -163,15 +165,15 @@
-
+
-
+
-
+
@@ -220,18 +222,16 @@
-
-
-
+
+
-
-
+
@@ -251,17 +251,17 @@
-
+
-
+
-
-
-
+
+
+
-
+
@@ -273,10 +273,10 @@
-
-
+
+
-
+
@@ -284,16 +284,32 @@
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/bindings/pascocoa/examples/statusitem/statusitem.pas b/bindings/pascocoa/examples/statusitem/statusitem.pas
index fbbd636fd..d507b0ccb 100644
--- a/bindings/pascocoa/examples/statusitem/statusitem.pas
+++ b/bindings/pascocoa/examples/statusitem/statusitem.pas
@@ -16,7 +16,7 @@ program statusitem;
{$mode delphi}
uses
- objc, ctypes, FPCMacOSAll, AppKit, Foundation, actions;
+ objc, ctypes, FPCMacOSAll, AppKit, Foundation, controller;
const
Str_Window_Title = 'StatusItem example project';
@@ -52,24 +52,26 @@ begin
CFTitle := CFStringCreateWithPascalString(nil, Str_Window_Title, kCFStringEncodingUTF8);
MainWindow.setTitle(CFTitle);
- { Initializes the action responding object }
+ { Initializes the controller object }
- actionList := TMyActionList.Create();
+ myController := TMyController.Create();
{ Adds the buttons }
CreateButton(MainWindowView, Str_Show_Button,
50.0, MainWindowRect.size.height - 50.0, 200.0, 25.0,
- 'doShowStatusitem:', actionList);
+ Str_doShowStatusItem, myController);
CreateButton(MainWindowView, Str_Hide_Button,
50.0, MainWindowRect.size.height - 100.0, 200.0, 25.0,
- 'doHideStatusitem:', actionList);
+ Str_doHideStatusItem, myController);
{ Enters main message loop }
MainWindow.orderFrontRegardless;
+ NSApp.setDelegate(myController);
+
NSApp.run;
{ Releases the AutoreleasePool }