Cocoa [x86]

Mac OSX specific forum
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Cocoa [x86]

Post by wilbert »

Some low level functions for those who want to experiment with porting Objective C to PureBasic
Link to userlib : http://www.w73.nl/pb/libPBObjC.zip

Procedures

OC_AutoreleasePool() - Returns a NSAutoreleasePool object.
OC_DrainAutoreleasePool (NSAutoreleasePool) - Drains a NSAutoreleasePool object.

OC_NSNumber (Float.f) - Convert a Float to a NSNumber.
OC_FloatFromNSNumber (NSNumber) - Convert a NSNumber to a Float.
OC_NSString (String.s) - Convert String to NSString.
OC_StringFromNSString (NSString) - Convert NSString to String.

OCA (ClassName.s) - Get class from class name and alloc.
OCC (ClassName.s) - Get class from class name.
OCS (SelectorName.s) - Get selector from selector name.
OCM (TheReceiver, TheSelector [, ... arguments]) - Send a message.
OCMF (TheReceiver, TheSelector [, ... arguments]) - Send a message that returns a float.
OCMS (*StructureReturnAddress, TheReceiver, TheSelector [, ... arguments]) - Send a message that returns a structure.
OCKV (TheReceiver, Key.s [, Value]) - Gets or sets a value for a key.

OC_AppleScript (Script.s) - Execute AppleScript code.


Example

Code: Select all

Structure CGRect
 x.f
 y.f
 w.f
 h.f
EndStructure

If OpenWindow(0, 0, 0, 320, 220, "Cocoa Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
  ; create a NSWindow object from the current window
  CocoaWindow = OCM(OCA("NSWindow"), OCS("initWithWindowRef:"), WindowID(0))
  
  ; get the content view of the NSWindow
  ContentView = OCM(CocoaWindow, OCS("contentView"))
  
  Frame.CGRect\x = 0
  Frame\y = y
  Frame\w = 120
  Frame\h = 30
  
  ; create and add a button
  Btn = OCM(OCA("NSButton"), OCS("initWithFrame:"), PeekL(Frame), PeekL(Frame + 4), PeekL(Frame + 8), PeekL(Frame + 12))
  OCM(Btn, OCS("setBezelStyle:"), 1)
  OCM(ContentView, OCS("addSubview:"), Btn)
  OCM(Btn, OCS("setTitle:"), OC_NSString("Cocoa Button"))  

  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
  
EndIf
The example isn't functioning properly yet.
It does show a Cocoa button but for some reason it disappears when clicked.
Last edited by wilbert on Wed May 31, 2017 3:14 pm, edited 1 time in total.
User avatar
Blood
Enthusiast
Enthusiast
Posts: 161
Joined: Tue Dec 08, 2009 8:34 pm
Location: United Kingdom

Re: Cocoa [x86]

Post by Blood »

Why on earth would you try and shoehorn Obj-C into PB? Why not just use Obj-C?
C provides the infinitely-abusable goto statement, and labels to branch to. Formally, the goto is never necessary, and in practice it is almost always easy to write code without it. We have not used goto in this book. -- K&R (2nd Ed.) : Page 65
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Cocoa [x86]

Post by wilbert »

Blood wrote:Why on earth would you try and shoehorn Obj-C into PB?
Mainly try if it is possible because I like PB and I like Obj-C.
User avatar
fsw
Addict
Addict
Posts: 1572
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: Cocoa [x86]

Post by fsw »

wilbert wrote:
Blood wrote:Why on earth would you try and shoehorn Obj-C into PB?
Mainly try if it is possible because I like PB and I like Obj-C.
@Wilbert
Never mind what some say.
Thank you for your code, will look into using it.

I am to provide the public with beneficial shocks.
Alfred Hitshock
Post Reply