Page 1 of 1

Cocoa [x86]

Posted: Wed May 04, 2011 3:00 pm
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.

Re: Cocoa [x86]

Posted: Fri May 06, 2011 8:31 pm
by Blood
Why on earth would you try and shoehorn Obj-C into PB? Why not just use Obj-C?

Re: Cocoa [x86]

Posted: Sat May 07, 2011 6:12 am
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.

Re: Cocoa [x86]

Posted: Tue Jul 24, 2012 5:53 pm
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.