Many improvements to the examples and Cocoa bindings.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@368 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
sekelsenmat
2008-03-04 09:16:58 +00:00
parent 8268740b2a
commit 958baedc78
11 changed files with 158 additions and 78 deletions

View File

@ -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;

View File

@ -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}

View File

@ -10,9 +10,7 @@
{$ifndef NSCELL_PAS_H}
{$define NSCELL_PAS_H}
{#import <Foundation/NSObject.h>
#import <Foundation/NSGeometry.h>
#import <AppKit/NSText.h>
{#import <AppKit/NSText.h>
#import <AppKit/NSParagraphStyle.h>
@class NSAttributedString, NSEvent, NSFont, NSFormatter, NSImage, NSMenu, NSText, NSView;}

View File

@ -14,8 +14,10 @@
const
Str_NSControl = 'NSControl';
Str_setStringValue = 'setStringValue:';
Str_initWithFrame = 'initWithFrame:';
Str_setTarget = 'setTarget:';
Str_setAction = 'setAction:';
Str_setStringValue = 'setStringValue:';
{$endif}
{$endif}
@ -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;

View File

@ -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);

View File

@ -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}

View File

@ -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)),

View File

@ -33,8 +33,8 @@
<Filename Value="simplewindow.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="simplewindow"/>
<CursorPos X="31" Y="58"/>
<TopLine Value="55"/>
<CursorPos X="105" Y="56"/>
<TopLine Value="52"/>
<EditorIndex Value="0"/>
<UsageCount Value="106"/>
<Loaded Value="True"/>
@ -383,44 +383,7 @@
<UsageCount Value="10"/>
</Unit52>
</Units>
<JumpHistory Count="9" HistoryIndex="8">
<Position1>
<Filename Value="../../appkit/NSApplication.inc"/>
<Caret Line="102" Column="32" TopLine="98"/>
</Position1>
<Position2>
<Filename Value="../../appkit/NSApplication.inc"/>
<Caret Line="103" Column="16" TopLine="96"/>
</Position2>
<Position3>
<Filename Value="../../appkit/AppKit.inc"/>
<Caret Line="14" Column="18" TopLine="7"/>
</Position3>
<Position4>
<Filename Value="../../appkit/AppKit.inc"/>
<Caret Line="92" Column="15" TopLine="82"/>
</Position4>
<Position5>
<Filename Value="../../appkit/NSApplication.inc"/>
<Caret Line="103" Column="16" TopLine="96"/>
</Position5>
<Position6>
<Filename Value="../../appkit/NSApplication.inc"/>
<Caret Line="320" Column="14" TopLine="307"/>
</Position6>
<Position7>
<Filename Value="../../appkit/NSApplication.inc"/>
<Caret Line="107" Column="14" TopLine="98"/>
</Position7>
<Position8>
<Filename Value="../../appkit/AppKit.inc"/>
<Caret Line="92" Column="15" TopLine="82"/>
</Position8>
<Position9>
<Filename Value="../../appkit/NSView.inc"/>
<Caret Line="364" Column="41" TopLine="360"/>
</Position9>
</JumpHistory>
<JumpHistory Count="0" HistoryIndex="-1"/>
</ProjectOptions>
<CompilerOptions>
<Version Value="5"/>

View File

@ -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);

View File

@ -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;

View File

@ -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}