Skip to content

Commit

Permalink
Merge pull request #55 from guzba/master
Browse files Browse the repository at this point in the history
mac ime
  • Loading branch information
treeform authored Jan 19, 2022
2 parents 3b3f875 + 17bb25c commit 93ffdf1
Show file tree
Hide file tree
Showing 3 changed files with 179 additions and 123 deletions.
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

0 comments on commit 93ffdf1

Please sign in to comment.