Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mac ime #55

Merged
merged 2 commits into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 60 additions & 19 deletions src/windy/platforms/macos/macdefs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ proc class_addProtocol*(cls: Class, protocol: Protocol): BOOL

{.pop.}

proc s*(s: string): SEL =
template s*(s: string): SEL =
sel_registerName(s.cstring)

template addClass*(className, superName: string, cls: Class, body: untyped) =
Expand Down Expand Up @@ -127,9 +127,9 @@ type
NSOpenGLPixelFormat* = distinct NSObject
NSOpenGLContext* = distinct NSObject
NSTrackingArea* = distinct NSObject
NSResponder* = distinct NSObject
NSImage* = distinct NSObject
NSCursor* = distinct NSObject
NSTextInputContext* = distinct NSObject

const
NSNotFound* = int.high
Expand Down Expand Up @@ -175,6 +175,16 @@ var
NSPasteboardTypeString* {.importc.}: NSPasteboardType
NSDefaultRunLoopMode* {.importc.}: NSRunLoopMode

proc locationInWindow*(event: NSEvent): NSPoint =
proc send(self: ID, op: SEL): NSPoint
{.importc:"objc_msgSend_fpret", cdecl, dynlib:"libobjc.dylib".}
send(
event.ID,
sel_registerName("locationInWindow".cstring)
)

{.push inline.}

proc NSMakeRect*(x, y, w, h: float64): NSRect =
CGRect(
origin: CGPoint(x: x, y: y),
Expand Down Expand Up @@ -228,6 +238,12 @@ proc callSuper*(sender: ID, cmd: SEL) =
cmd
)

proc retain*(id: ID) =
discard objc_msgSend(
id,
sel_registerName("retain".cstring)
)

proc release*(id: ID) =
discard objc_msgSend(
id,
Expand Down Expand Up @@ -257,6 +273,13 @@ proc UTF8String(s: NSString): cstring =
proc `$`*(s: NSString): string =
$s.UTF8String

proc stringWithString*(_: typedesc[NSString], s: NSString): NSString =
objc_msgSend(
objc_getClass("NSString".cstring).ID,
s"stringWithString:",
s
).NSString

proc getBytes*(
s: NSString,
buffer: pointer,
Expand Down Expand Up @@ -297,14 +320,6 @@ proc doubleClickInterval*(_: typedesc[NSEvent]): float64 =
s"doubleClickInterval"
).float64

proc locationInWindow*(event: NSEvent): NSPoint =
proc send(self: ID, op: SEL): NSPoint
{.importc:"objc_msgSend_fpret", cdecl, dynlib:"libobjc.dylib".}
send(
event.ID,
s"locationInWindow"
)

proc scrollingDeltaX*(event: NSEvent): float64 =
objc_msgSend_fpret(
event.ID,
Expand Down Expand Up @@ -358,11 +373,11 @@ proc bytes*(data: NSData): pointer =
s"bytes"
))

proc length*(obj: NSData | NSString): int =
proc length*(obj: NSData | NSString): uint =
objc_msgSend(
obj.ID,
s"length"
).int
).uint

proc array*(_: typedesc[NSArray]): NSArray =
objc_msgSend(
Expand Down Expand Up @@ -797,6 +812,12 @@ proc addCursorRect*(view: NSview, rect: NSRect, cursor: NSCursor) =
cursor
)

proc inputContext*(view: NSView): NSTextInputContext =
objc_msgSend(
view.ID,
s"inputContext"
).NSTextInputContext

proc initWithAttributes*(
pixelFormat: NSOpenGLPixelFormat,
attribs: ptr NSOpenGLPixelFormatAttribute
Expand Down Expand Up @@ -874,13 +895,6 @@ proc initWithRect*(
0.ID
)

proc interpretKeyEvents*(responder: NSResponder, events: NSArray) =
discard objc_msgSend(
responder.ID,
s"interpretKeyEvents:",
events
)

proc initWithData*(image: NSImage, data: NSData) =
discard objc_msgSend(
image.ID,
Expand All @@ -895,3 +909,30 @@ proc initWithImage*(cursor: NSCursor, image: NSImage, hotspot: NSPoint) =
image,
hotspot
)

proc discardMarkedText*(context: NSTextInputContext) =
discard objc_msgSend(
context.ID,
s"discardMarkedText",
)

proc handleEvent*(context: NSTextInputContext, event: NSEvent): bool =
objc_msgSend(
context.ID,
s"handleEvent:",
event
).int != 0

proc deactivate*(context: NSTextInputContext) =
discard objc_msgSend(
context.ID,
s"deactivate",
)

proc activate*(context: NSTextInputContext) =
discard objc_msgSend(
context.ID,
s"activate",
)

{.pop.}
Loading