Added Foundation bindings

This commit is contained in:
Samuel Elgozi
2025-01-17 10:42:32 +02:00
parent 16eca1ded1
commit 19d6c01f0f
9 changed files with 136 additions and 0 deletions

View File

@@ -25,6 +25,10 @@ Block_createLocalWithParam :: proc (user_data: rawptr, user_proc: proc "c" (user
b, _ := Block_createInternalWithParam(false, user_data, user_proc, {})
return b
}
@(objc_type = Block, objc_name = "invoke")
Block_invoke :: proc "c" (self: ^Block, args: ..any) -> ^Object {
return msgSend(^Object, self, "invoke:", ..args)
}
@(private)
Internal_Block_Literal_Base :: struct {

View File

@@ -13,6 +13,23 @@ Data_init :: proc "c" (self: ^Data) -> ^Data {
return msgSend(^Data, self, "init")
}
@(objc_type = Data, objc_name = "initWithBytes")
Data_initWithBytes :: proc "c" (self: ^Data, bytes: []byte) -> ^Data {
return msgSend(^Data, self, "initWithBytes:length:", raw_data(bytes), len(bytes))
}
@(objc_type = Data, objc_name = "initWithBytesNoCopy")
Data_initWithBytesNoCopy :: proc "c" (self: ^Data, bytes: []byte, freeWhenDone: ns.BOOL) -> ^Data {
return msgSend(
^Data,
self,
"initWithBytesNoCopy:length:freeWhenDone:",
raw_data(bytes),
len(bytes),
freeWhenDone,
)
}
@(objc_type=Data, objc_name="mutableBytes")
Data_mutableBytes :: proc "c" (self: ^Data) -> rawptr {
return msgSend(rawptr, self, "mutableBytes")

View File

@@ -18,6 +18,11 @@ Date_dateWithTimeIntervalSinceNow :: proc "c" (secs: TimeInterval) -> ^Date {
return msgSend(^Date, Date, "dateWithTimeIntervalSinceNow:", secs)
}
@(objc_type=Date, objc_name="timeIntervalSince1970")
Date_timeIntervalSince1970 :: proc "c" (self: ^Date) -> f64 {
return msgSend(f64, self, "timeIntervalSince1970")
}
@(objc_type=Date, objc_name="distantFuture", objc_is_class_method=true)
Date_distantFuture :: proc "c" () -> ^Date {
return msgSend(^Date, Date, "distantFuture")

View File

@@ -30,6 +30,7 @@ MenuItem :: struct {using _: Object}
MenuItem_alloc :: proc "c" () -> ^MenuItem {
return msgSend(^MenuItem, MenuItem, "alloc")
}
@(objc_type=MenuItem, objc_name="registerActionCallback", objc_is_class_method=true)
MenuItem_registerActionCallback :: proc "c" (name: cstring, callback: MenuItemCallback) -> SEL {
s := string(name)
@@ -50,11 +51,21 @@ MenuItem_registerActionCallback :: proc "c" (name: cstring, callback: MenuItemCa
return sel
}
@(objc_type=MenuItem, objc_name="separatorItem", objc_is_class_method=true)
MenuItem_separatorItem :: proc "c" () -> ^MenuItem {
return msgSend(^MenuItem, MenuItem, "separatorItem")
}
@(objc_type=MenuItem, objc_name="init")
MenuItem_init :: proc "c" (self: ^MenuItem) -> ^MenuItem {
return msgSend(^MenuItem, self, "init")
}
@(objc_type=MenuItem, objc_name="initWithTitle")
MenuItem_initWithTitle :: proc "c" (self: ^MenuItem, title: ^String, action: SEL, keyEquivalent: ^String) -> ^MenuItem {
return msgSend(^MenuItem, self, "initWithTitle:action:keyEquivalent:", title, action, keyEquivalent)
}
@(objc_type=MenuItem, objc_name="setKeyEquivalentModifierMask")
MenuItem_setKeyEquivalentModifierMask :: proc "c" (self: ^MenuItem, modifierMask: KeyEquivalentModifierMask) {
msgSend(nil, self, "setKeyEquivalentModifierMask:", modifierMask)
@@ -75,6 +86,11 @@ MenuItem_title :: proc "c" (self: ^MenuItem) -> ^String {
return msgSend(^String, self, "title")
}
@(objc_type=MenuItem, objc_name="setTitle")
MenuItem_setTitle :: proc "c" (self: ^MenuItem, title: ^String) -> ^String {
return msgSend(^String, self, "title:", title)
}
@(objc_class="NSMenu")

View File

@@ -0,0 +1,14 @@
package objc_Foundation
@(objc_class = "NSToolbar")
Toolbar :: struct { using _: Object }
@(objc_type = Toolbar, objc_name = "alloc", objc_is_class_method = true)
Toolbar_alloc :: proc "c" () -> ^Toolbar {
return msgSend(^Toolbar, Toolbar, "alloc")
}
@(objc_type = Toolbar, objc_name = "init")
Toolbar_init :: proc "c" (self: ^Toolbar) -> ^Toolbar {
return msgSend(^Toolbar, self, "init")
}

View File

@@ -28,3 +28,8 @@ URL_initFileURLWithPath :: proc "c" (self: ^URL, path: ^String) -> ^URL {
URL_fileSystemRepresentation :: proc "c" (self: ^URL) -> cstring {
return msgSend(cstring, self, "fileSystemRepresentation")
}
@(objc_type=URL, objc_name="relativePath")
URL_relativePath :: proc "c" (self: ^URL) -> ^String {
return msgSend(^String, self, "relativePath")
}

View File

@@ -0,0 +1,24 @@
package objc_Foundation
@(objc_class = "URLRequest")
URLRequest :: struct { using _: Object }
@(objc_type = URLRequest, objc_name = "alloc", objc_is_class_method = true)
URLRequest_alloc :: proc "c" () -> ^URLRequest {
return msgSend(^URLRequest, URLRequest, "alloc")
}
@(objc_type = URLRequest, objc_name = "requestWithURL", objc_is_class_method = true)
URLRequest_requestWithURL :: proc "c" (url: ^URL) -> ^URLRequest {
return msgSend(^URLRequest, URLRequest, "requestWithURL:", url)
}
@(objc_type = URLRequest, objc_name = "init")
URLRequest_init :: proc "c" (self: ^URLRequest) -> ^URLRequest {
return msgSend(^URLRequest, URLRequest, "init")
}
@(objc_type = URLRequest, objc_name = "url")
URLRequest_url :: proc "c" (self: ^URLRequest) -> ^URL {
return msgSend(^URL, self, "URL")
}

View File

@@ -0,0 +1,19 @@
package objc_Foundation
@(objc_class = "NSURLResponse")
URLResponse :: struct { using _: Object }
@(objc_type = URLResponse, objc_name = "alloc", objc_is_class_method = true)
URLResponse_alloc :: proc "c" () -> ^URLResponse {
return msgSend(^URLResponse, URLResponse, "alloc")
}
@(objc_type = URLResponse, objc_name = "init")
URLResponse_init :: proc "c" (self: ^URLResponse) -> ^URLResponse {
return msgSend(^URLResponse, URLResponse, "init")
}
@(objc_type = URLResponse, objc_name = "initWithURL")
URLResponse_initWithURL :: proc "c" (self: ^URLResponse, url: ^URL, mime_type: ^String, length: int, encoding: ^String ) -> ^URLResponse {
return msgSend(^URLResponse, self, "initWithURL:MIMEType:expectedContentLength:textEncodingName:", url, mime_type, Integer(length), encoding)
}

View File

@@ -129,6 +129,10 @@ WindowDelegateTemplate :: struct {
windowDidExitVersionBrowser: proc(notification: ^Notification),
}
Window_Title_Visibility :: enum UInteger {
Visible,
Hidden,
}
WindowDelegate :: struct { using _: Object } // This is not the same as NSWindowDelegate
_WindowDelegateInternal :: struct {
@@ -616,6 +620,10 @@ View_setWantsLayer :: proc "c" (self: ^View, wantsLayer: BOOL) {
View_convertPointFromView :: proc "c" (self: ^View, point: Point, view: ^View) -> Point {
return msgSend(Point, self, "convertPoint:fromView:", point, view)
}
@(objc_type=View, objc_name="addSubview")
View_addSubview :: proc "c" (self: ^View, view: ^View) {
msgSend(nil, self, "addSubview:", view)
}
@(objc_class="NSWindow")
Window :: struct {using _: Responder}
@@ -748,4 +756,28 @@ Window_hasTitleBar :: proc "c" (self: ^Window) -> BOOL {
@(objc_type=Window, objc_name="orderedIndex")
Window_orderedIndex :: proc "c" (self: ^Window) -> Integer {
return msgSend(Integer, self, "orderedIndex")
}
@(objc_type=Window, objc_name="setMinSize")
Window_setMinSize :: proc "c" (self: ^Window, size: Size) {
msgSend(nil, self, "setMinSize:", size)
}
@(objc_type=Window, objc_name="setTitleVisibility")
Window_setTitleVisibility :: proc "c" (self: ^Window, visibility: Window_Title_Visibility) {
msgSend(nil, self, "setTitleVisibility:", visibility)
}
@(objc_type=Window, objc_name="performZoom")
Window_performZoom :: proc "c" (self: ^Window) {
msgSend(nil, self, "performZoom:", self)
}
@(objc_type=Window, objc_name="setFrameAutosaveName")
NSWindow_setFrameAutosaveName :: proc "c" (self: ^Window, name: ^String) {
msgSend(nil, self, "setFrameAutosaveName:", name)
}
@(objc_type=Window, objc_name="performWindowDragWithEvent")
Window_performWindowDragWithEvent :: proc "c" (self: ^Window, event: ^Event) {
msgSend(nil, self, "performWindowDragWithEvent:", event)
}
@(objc_type=Window, objc_name="setToolbar")
Window_setToolbar :: proc "c" (self: ^Window, toolbar: ^Toolbar) {
msgSend(nil, self, "setToolbar:", toolbar)
}