diff --git a/bindings/pascocoa/appkit/NSApplication.inc b/bindings/pascocoa/appkit/NSApplication.inc index 825c3cd15..4da11ebd4 100644 --- a/bindings/pascocoa/appkit/NSApplication.inc +++ b/bindings/pascocoa/appkit/NSApplication.inc @@ -110,6 +110,9 @@ APPKIT_EXTERN NSString *NSApplicationDidChangeScreenParametersNotification; } //APPKIT_EXTERN const double NSAppKitVersionNumber; NSApplication = class(NSResponder) + public + { Extra binding functions } + function getClass: objc.id; override; public constructor sharedApplication; @@ -358,9 +361,14 @@ If not specified, obtain from CFBundleShortVersionString key in infoDictionary. {$endif} {$ifdef IMPLEMENTATION} +function NSApplication.getClass: objc.id; +begin + Result := objc_getClass(Str_NSApplication); +end; + constructor NSApplication.sharedApplication; begin - ClassId := objc_getClass(PChar(Str_NSApplication)); + ClassId := getClass; Handle := objc_msgSend(ClassId, sel_registerName(PChar(Str_sharedApplication)), []); end; diff --git a/bindings/pascocoa/appkit/NSButton.inc b/bindings/pascocoa/appkit/NSButton.inc index 3e2ceb78a..bc0bec3c3 100644 --- a/bindings/pascocoa/appkit/NSButton.inc +++ b/bindings/pascocoa/appkit/NSButton.inc @@ -6,6 +6,18 @@ All rights reserved. } +{$ifdef HEADER} +{$ifndef NSBUTTON_PAS_H} +{$define NSBUTTON_PAS_H} + +const + Str_NSButton = 'NSButton'; + + Str_setTitle = 'setTitle:'; + Str_setBezelStyle = 'setBezelStyle:'; + +{$endif} +{$endif} {$ifdef CLASSES} {$ifndef NSBUTTON_PAS_C} {$define NSBUTTON_PAS_C} @@ -17,10 +29,12 @@ NSButton = class(NSControl) public - -{- (NSString *)title; -- (void)setTitle:(NSString *)aString; -- (NSString *)alternateTitle; + { Extra binding functions } + function getClass: objc.id; override; + public +//- (NSString *)title; + procedure setTitle(aString: CFStringRef); +{- (NSString *)alternateTitle; - (void)setAlternateTitle:(NSString *)aString; - (NSImage *)image; - (void)setImage:(NSImage *)image; @@ -55,14 +69,14 @@ - (void)setAttributedTitle:(NSAttributedString *)aString; - (NSAttributedString *)attributedAlternateTitle; - (void)setAttributedAlternateTitle:(NSAttributedString *)obj; -@end +@end} -@interface NSButton(NSButtonBezelStyles) -- (void) setBezelStyle:(NSBezelStyle)bezelStyle; -- (NSBezelStyle)bezelStyle; -@end +//@interface NSButton(NSButtonBezelStyles) + procedure setBezelStyle(bezelStyle: NSBezelStyle); +//- (NSBezelStyle)bezelStyle; +//@end -@interface NSButton(NSButtonMixedState) +{@interface NSButton(NSButtonMixedState) - (void)setAllowsMixedState:(BOOL)flag; - (BOOL)allowsMixedState; - (void)setNextState; @@ -82,4 +96,34 @@ {$endif} {$endif} +{$ifdef IMPLEMENTATION} + +function NSButton.getClass: objc.id; +begin + Result := objc_getClass(Str_NSButton); +end; + +procedure NSButton.setTitle(aString: CFStringRef); +type + setTitle_t = procedure (param1: objc.id; param2: SEL; + param3: CFStringRef); cdecl; +var + vmethod: setTitle_t; +begin + vmethod := setTitle_t(@objc_msgSend); + vmethod(Handle, sel_registerName(PChar(Str_setTitle)), aString); +end; + +procedure NSButton.setBezelStyle(bezelStyle: NSBezelStyle); +type + setBezelStyle_t = procedure (param1: objc.id; param2: SEL; + param3: NSBezelStyle); cdecl; +var + vmethod: setBezelStyle_t; +begin + vmethod := setBezelStyle_t(@objc_msgSend); + vmethod(Handle, sel_registerName(PChar(Str_setBezelStyle)), bezelStyle); +end; + +{$endif} diff --git a/bindings/pascocoa/appkit/NSCell.inc b/bindings/pascocoa/appkit/NSCell.inc index 76cb969ee..47cdeb78b 100644 --- a/bindings/pascocoa/appkit/NSCell.inc +++ b/bindings/pascocoa/appkit/NSCell.inc @@ -10,9 +10,7 @@ {$ifndef NSCELL_PAS_H} {$define NSCELL_PAS_H} -{#import -#import -#import +{#import #import @class NSAttributedString, NSEvent, NSFont, NSFormatter, NSImage, NSMenu, NSText, NSView;} diff --git a/bindings/pascocoa/appkit/NSControl.inc b/bindings/pascocoa/appkit/NSControl.inc index 3393f50d2..1295394d9 100644 --- a/bindings/pascocoa/appkit/NSControl.inc +++ b/bindings/pascocoa/appkit/NSControl.inc @@ -14,9 +14,11 @@ const Str_NSControl = 'NSControl'; - Str_setStringValue = 'setStringValue:'; Str_initWithFrame = 'initWithFrame:'; - + Str_setTarget = 'setTarget:'; + Str_setAction = 'setAction:'; + Str_setStringValue = 'setStringValue:'; + {$endif} {$endif} {$ifdef CLASSES} @@ -34,17 +36,17 @@ const {+ (void)setCellClass:(Class)factoryId; + (Class)cellClass;} - constructor initWithFrame(frameRect: NSRect); virtual; + constructor initWithFrame(frameRect: NSRect); {- (void)sizeToFit; - (void)calcSize; - (id)cell; - (void)setCell:(NSCell *)aCell; - (id)selectedCell; -- (id)target; -- (void)setTarget:(id)anObject; -- (SEL)action; -- (void)setAction:(SEL)aSelector; -- (int)tag; +- (id)target;} + procedure setTarget(anObject: objc.id); +//- (SEL)action; + procedure setAction(aSelector: SEL); +{- (int)tag; - (void)setTag:(int)anInt; - (int)selectedTag; - (void)setIgnoresMultiClick:(BOOL)flag; @@ -150,13 +152,34 @@ type var vmethod: initWithFrame_t; begin - // Allows descendents to set a new ClassId - if ClassID = nil then ClassId := objc_getClass(PChar(Str_NSControl)); + ClassID := getClass(); allocbuf := objc_msgSend(ClassId, sel_registerName(PChar(Str_alloc)), []); vmethod := initWithFrame_t(@objc_msgSend); Handle := vmethod(allocbuf, sel_registerName(PChar(Str_initWithFrame)), frameRect); end; +procedure NSControl.setTarget(anObject: objc.id); +type + setTarget_t = procedure (param1: objc.id; param2: SEL; + param3: objc.id); cdecl; +var + vmethod: setTarget_t; +begin + vmethod := setTarget_t(@objc_msgSend); + vmethod(Handle, sel_registerName(PChar(Str_setTarget)), anObject); +end; + +procedure NSControl.setAction(aSelector: SEL); +type + setAction_t = procedure (param1: objc.id; param2: SEL; + param3: SEL); cdecl; +var + vmethod: setAction_t; +begin + vmethod := setAction_t(@objc_msgSend); + vmethod(Handle, sel_registerName(PChar(Str_setAction)), aSelector); +end; + procedure NSControl.setStringValue(aString: CFStringRef); type setStringValue_t = procedure (param1: objc.id; param2: SEL; diff --git a/bindings/pascocoa/appkit/NSStatusBar.inc b/bindings/pascocoa/appkit/NSStatusBar.inc index 4914ce11a..3ee466af3 100644 --- a/bindings/pascocoa/appkit/NSStatusBar.inc +++ b/bindings/pascocoa/appkit/NSStatusBar.inc @@ -19,6 +19,7 @@ const Str_NSStatusBar = 'NSStatusBar'; Str_systemStatusBar = 'systemStatusBar'; + Str_statusItemWithLength = 'statusItemWithLength:'; {$endif} {$endif} @@ -32,6 +33,9 @@ const {@class NSMutableArray;} NSStatusBar = class(NSObject) + public + { Extra binding functions } + function getClass: objc.id; override; public constructor systemStatusBar(); @@ -47,15 +51,28 @@ const {$endif} {$ifdef IMPLEMENTATION} +function NSStatusBar.getClass: objc.id; +begin + Result := objc_getClass(Str_NSStatusBar); +end; + constructor NSStatusBar.systemStatusBar(); begin - ClassId := objc_getClass(PChar(Str_NSStatusBar)); + ClassId := getClass(); Handle := objc_msgSend(ClassId, sel_registerName(PChar(Str_systemStatusBar)), []); end; function NSStatusBar.statusItemWithLength(length: cfloat): NSStatusItem; +type + statusItemWithLength_t = function (param1: objc.id; param2: SEL; + param3: cfloat): objc.id; cdecl; +var + vmethod: statusItemWithLength_t; + itemHandle: objc.id; begin - + vmethod := statusItemWithLength_t(@objc_msgSend); + itemHandle := vmethod(Handle, sel_registerName(PChar(Str_statusItemWithLength)), length); + Result := NSStatusItem.CreateWithHandle(itemHandle); end; procedure NSStatusBar.removeStatusItem(item: NSStatusItem); diff --git a/bindings/pascocoa/appkit/NSTextField.inc b/bindings/pascocoa/appkit/NSTextField.inc index 445350277..e167c3bba 100644 --- a/bindings/pascocoa/appkit/NSTextField.inc +++ b/bindings/pascocoa/appkit/NSTextField.inc @@ -28,7 +28,9 @@ const NSTextField = class(NSControl) public - constructor initWithFrame(frameRect: NSRect); override; + { Extra binding functions } + function getClass: objc.id; override; + public {- (void)setBackgroundColor:(NSColor *)color; - (NSColor *)backgroundColor; @@ -77,10 +79,9 @@ const {$endif} {$ifdef IMPLEMENTATION} -constructor NSTextField.initWithFrame(frameRect: NSRect); +function NSTextField.getClass: objc.id; begin - ClassId := objc_getClass(PChar(Str_NSTextField)); - inherited initWithFrame(frameRect); + Result := objc_getClass(Str_NSTextField); end; {$endif} diff --git a/bindings/pascocoa/appkit/NSWindow.inc b/bindings/pascocoa/appkit/NSWindow.inc index 757447288..7ec2d5397 100644 --- a/bindings/pascocoa/appkit/NSWindow.inc +++ b/bindings/pascocoa/appkit/NSWindow.inc @@ -101,7 +101,6 @@ const Str_initWithContentRect = 'initWithContentRect:styleMask:backing:defer:'; Str_orderFrontRegardless = 'orderFrontRegardless'; - Str_setTitle = 'setTitle:'; Str_contentView = 'contentView'; {$endif} @@ -120,6 +119,9 @@ const NSWindow = class(NSResponder) public + { Extra binding functions } + function getClass: objc.id; override; + public {+ (NSRect)frameRectForContentRect:(NSRect)cRect styleMask:(unsigned int)aStyle; @@ -477,6 +479,11 @@ const {$endif} {$ifdef IMPLEMENTATION} +function NSWindow.getClass: objc.id; +begin + Result := objc_getClass(Str_NSWindow); +end; + constructor NSWindow.initWithContentRect( contentRect: NSRect; aStyle: cuint; @@ -494,7 +501,7 @@ begin styleMask: NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask backing: NSBackingStoreBuffered defer: NO]; } - ClassId := objc_getClass(PChar(Str_NSWindow)); + ClassId := getClass(); allocbuf := objc_msgSend(ClassId, sel_registerName(PChar(Str_alloc)), []); vinit := initWithContentRect_t(@objc_msgSend); Handle := vinit(allocbuf, sel_registerName(PChar(Str_initWithContentRect)), diff --git a/bindings/pascocoa/examples/simplewindow/simplewindow.lpi b/bindings/pascocoa/examples/simplewindow/simplewindow.lpi index 9ab0c882d..f4a25aaf5 100644 --- a/bindings/pascocoa/examples/simplewindow/simplewindow.lpi +++ b/bindings/pascocoa/examples/simplewindow/simplewindow.lpi @@ -33,8 +33,8 @@ - - + + @@ -383,44 +383,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/bindings/pascocoa/examples/simplewindow/simplewindow.pas b/bindings/pascocoa/examples/simplewindow/simplewindow.pas index f1fecabe9..c991e225c 100644 --- a/bindings/pascocoa/examples/simplewindow/simplewindow.pas +++ b/bindings/pascocoa/examples/simplewindow/simplewindow.pas @@ -15,7 +15,7 @@ } program simplewindow; -{$mode delphi} +{$ifdef fpc}{$mode delphi}{$endif} uses objc, ctypes, FPCMacOSAll, AppKit, Foundation; @@ -56,12 +56,14 @@ begin MainWindow.setTitle(CFTitle); { Adds a NSTextField with a string } + + CFMessage := CFStringCreateWithPascalString(nil, Str_Window_Message, kCFStringEncodingUTF8); TextFieldRect.origin.x := 0.0; - TextFieldRect.origin.y := 0.0; + TextFieldRect.origin.y := 200.0; TextFieldRect.size.width := 300.0; - TextFieldRect.size.height := 500.0; + TextFieldRect.size.height := 100.0; TextField := NSTextField.initWithFrame(TextFieldRect); - TextField.setStringValue(CFTitle); + TextField.setStringValue(CFMessage); MainWindowView := NSView.CreateWithHandle(MainWindow.contentView); MainWindowView.addSubview(TextField); diff --git a/bindings/pascocoa/foundation/NSAutoreleasePool.inc b/bindings/pascocoa/foundation/NSAutoreleasePool.inc index 95a1e133b..b385439e6 100644 --- a/bindings/pascocoa/foundation/NSAutoreleasePool.inc +++ b/bindings/pascocoa/foundation/NSAutoreleasePool.inc @@ -22,6 +22,9 @@ const NSAutoreleasePool = class(NSObject) public constructor Create; override; + { Extra binding functions } + function getClass: objc.id; override; + public //+ (void)addObject:(id)anObject; @@ -37,10 +40,15 @@ const {$endif} {$ifdef IMPLEMENTATION} +function NSAutoreleasePool.getClass: objc.id; +begin + Result := objc_getClass(Str_NSAutoreleasePool); +end; + constructor NSAutoreleasePool.Create; begin { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; } - ClassId := objc_getClass(PChar(Str_NSAutoreleasePool)); + ClassId := getClass(); allocbuf := objc_msgSend(ClassId, sel_registerName(PChar(Str_alloc)), []); Handle := objc_msgSend(allocbuf, sel_registerName(PChar(Str_init)), []); end; diff --git a/bindings/pascocoa/foundation/NSObject.inc b/bindings/pascocoa/foundation/NSObject.inc index 2d2057cff..9eff76f94 100644 --- a/bindings/pascocoa/foundation/NSObject.inc +++ b/bindings/pascocoa/foundation/NSObject.inc @@ -67,6 +67,8 @@ {*********** Base class ***********} const + Str_NSObject = 'NSObject'; + Str_alloc = 'alloc'; Str_init = 'init'; Str_release = 'release'; @@ -103,7 +105,9 @@ FOUNDATION_EXPORT unsigned NSExtraRefCount(id object);} constructor Create; virtual; constructor CreateWithHandle(aHandle: objc.id); destructor Destroy; override; - + { Extra binding functions } + function getClass: objc.id; virtual; + public {+ (void)load; + (void)initialize; @@ -172,5 +176,10 @@ begin objc_msgSend(Handle, sel_registerName(PChar(Str_release)), []); end; +function NSObject.getClass: objc.id; +begin + Result := objc_getClass(Str_NSObject); +end; + {$endif}