Removed the class creation at runtime stuff and its residue from the Go files. This also cleans up the initialization stuff on the Go side too.
This commit is contained in:
parent
11ef974b48
commit
62b3c26107
|
@ -18,10 +18,6 @@ var (
|
||||||
_NSView = objc_getClass("NSView")
|
_NSView = objc_getClass("NSView")
|
||||||
)
|
)
|
||||||
|
|
||||||
func mkAreaClass() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func makeArea(parentWindow C.id, alternate bool, s *sysData) C.id {
|
func makeArea(parentWindow C.id, alternate bool, s *sysData) C.id {
|
||||||
area := C.makeArea()
|
area := C.makeArea()
|
||||||
area = newScrollView(area)
|
area = newScrollView(area)
|
||||||
|
|
|
@ -25,18 +25,13 @@ var (
|
||||||
appDelegate C.id
|
appDelegate C.id
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
_goAppDelegate = "goAppDelegate"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
_uitask = sel_getUid("uitask:") // used by uitask_darwin.go
|
_uitask = sel_getUid("uitask:") // used by uitask_darwin.go
|
||||||
_buttonClicked = sel_getUid("buttonClicked:") // used by sysdata_darwin.go
|
_buttonClicked = sel_getUid("buttonClicked:") // used by sysdata_darwin.go
|
||||||
)
|
)
|
||||||
|
|
||||||
func mkAppDelegate() error {
|
func makeAppDelegate() {
|
||||||
appDelegate = C.makeAppDelegate()
|
appDelegate = C.makeAppDelegate()
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//export appDelegate_windowShouldClose
|
//export appDelegate_windowShouldClose
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
package ui
|
package ui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -79,77 +78,3 @@ func newScrollView(content C.id) C.id {
|
||||||
func getScrollViewContent(scrollview C.id) C.id {
|
func getScrollViewContent(scrollview C.id) C.id {
|
||||||
return C.objc_msgSend_noargs(scrollview, _documentView)
|
return C.objc_msgSend_noargs(scrollview, _documentView)
|
||||||
}
|
}
|
||||||
|
|
||||||
// These create new classes.
|
|
||||||
|
|
||||||
// selector contains the information for a new selector.
|
|
||||||
type selector struct {
|
|
||||||
name string
|
|
||||||
imp uintptr // not unsafe.Pointer because https://code.google.com/p/go/issues/detail?id=7665
|
|
||||||
itype itype
|
|
||||||
desc string // for error reporting
|
|
||||||
}
|
|
||||||
|
|
||||||
// sel_[returntype] or sel_[returntype]_[arguments] (after the required self/sel arguments)
|
|
||||||
type itype uint
|
|
||||||
const (
|
|
||||||
sel_void_id itype = iota
|
|
||||||
sel_bool_id
|
|
||||||
sel_bool
|
|
||||||
sel_void_rect
|
|
||||||
sel_terminatereply_id
|
|
||||||
sel_void
|
|
||||||
nitypes
|
|
||||||
)
|
|
||||||
|
|
||||||
var itypes = [nitypes][]C.char{
|
|
||||||
sel_void_id: []C.char{'v', '@', ':', '@', 0},
|
|
||||||
sel_bool_id: []C.char{'c', '@', ':', '@', 0},
|
|
||||||
sel_bool: []C.char{'c', '@', ':', 0},
|
|
||||||
sel_void_rect: nil, // see init() below
|
|
||||||
sel_terminatereply_id: nil,
|
|
||||||
sel_void: []C.char{'v', '@', ':', 0},
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
// see encodedNSRect in bleh_darwin.m
|
|
||||||
x := make([]C.char, 0, 256) // more than enough
|
|
||||||
x = append(x, 'v', '@', ':')
|
|
||||||
y := C.GoString(C.encodedNSRect)
|
|
||||||
for _, b := range y {
|
|
||||||
x = append(x, C.char(b))
|
|
||||||
}
|
|
||||||
x = append(x, 0)
|
|
||||||
itypes[sel_void_rect] = x
|
|
||||||
|
|
||||||
x = make([]C.char, 0, 256) // more than enough
|
|
||||||
y = C.GoString(C.encodedTerminateReply)
|
|
||||||
for _, b := range y {
|
|
||||||
x = append(x, C.char(b))
|
|
||||||
}
|
|
||||||
x = append(x, '@', ':', '@', 0)
|
|
||||||
itypes[sel_terminatereply_id] = x
|
|
||||||
}
|
|
||||||
|
|
||||||
func makeClass(name string, super C.id, sels []selector, desc string) (id C.id, err error) {
|
|
||||||
cname := C.CString(name)
|
|
||||||
defer C.free(unsafe.Pointer(cname))
|
|
||||||
|
|
||||||
// an id that describes a class is itself a Class
|
|
||||||
// thanks to Psy| in irc.freenode.net/##objc
|
|
||||||
c := C.objc_allocateClassPair(C.Class(unsafe.Pointer(super)), cname, 0)
|
|
||||||
if c == C.NilClass {
|
|
||||||
err = fmt.Errorf("unable to create Objective-C class %s for %s; reason unknown", name, desc)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
C.objc_registerClassPair(c)
|
|
||||||
for _, v := range sels {
|
|
||||||
ok := C.class_addMethod(c, sel_getUid(v.name),
|
|
||||||
C.IMP(unsafe.Pointer(v.imp)), &itypes[v.itype][0])
|
|
||||||
if ok == C.BOOL(C.NO) {
|
|
||||||
err = fmt.Errorf("unable to add selector %s to class %s (needed for %s; reason unknown)", v.name, name, v.desc)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return objc_getClass(name), nil
|
|
||||||
}
|
|
||||||
|
|
|
@ -69,16 +69,11 @@ var (
|
||||||
|
|
||||||
func initCocoa() (err error) {
|
func initCocoa() (err error) {
|
||||||
C.initBleh() // initialize bleh_darwin.m functions
|
C.initBleh() // initialize bleh_darwin.m functions
|
||||||
err = mkAppDelegate()
|
makeAppDelegate()
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if C.initCocoa(appDelegate) != C.YES {
|
if C.initCocoa(appDelegate) != C.YES {
|
||||||
err = fmt.Errorf("error setting NSApplication activation policy (basically identifies our program as a separate program; needed for several things, such as Dock icon, application menu, window resizing, etc.) (unknown reason)")
|
return fmt.Errorf("error setting NSApplication activation policy (basically identifies our program as a separate program; needed for several things, such as Dock icon, application menu, window resizing, etc.) (unknown reason)")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
err = mkAreaClass()
|
return nil
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//export appDelegate_uitask
|
//export appDelegate_uitask
|
||||||
|
|
Loading…
Reference in New Issue