Attempted to add the Area bare bones and resizing code to the Mac OS X backend. It complains that initWithFrame: is not implemented...

This commit is contained in:
Pietro Gagliardi 2014-03-30 11:19:13 -04:00
parent f2d6daa9ea
commit 08dfb5da20
4 changed files with 69 additions and 3 deletions

View File

@ -15,15 +15,17 @@ import (
import "C" import "C"
const ( const (
_goArea = "goArea" __goArea = "goArea"
) )
var ( var (
_goArea C.id
_drawRect = sel_getUid("drawRect:") _drawRect = sel_getUid("drawRect:")
) )
func mkAreaClass() error { func mkAreaClass() error {
areaclass, err := makeAreaClass(_goArea) areaclass, err := makeAreaClass(__goArea)
if err != nil { if err != nil {
return fmt.Errorf("error creating Area backend class: %v", err) return fmt.Errorf("error creating Area backend class: %v", err)
} }
@ -33,12 +35,43 @@ func mkAreaClass() error {
if ok != C.BOOL(C.YES) { if ok != C.BOOL(C.YES) {
return fmt.Errorf("error overriding Area drawRect: method; reason unknown") return fmt.Errorf("error overriding Area drawRect: method; reason unknown")
} }
_goArea = objc_getClass(__goArea)
return nil return nil
} }
//export areaView_drawRect //export areaView_drawRect
func areaView_drawRect(self C.id, rect C.struct_xrect) { func areaView_drawRect(self C.id, rect C.struct_xrect) {
// TODO // TODO
fmt.Println(rect)
}
// TODO combine these with the listbox functions?
func newAreaScrollView(area C.id) C.id {
scrollview := objc_alloc(_NSScrollView)
scrollview = objc_msgSend_rect(scrollview, _initWithFrame,
0, 0, 100, 100)
C.objc_msgSend_bool(scrollview, _setHasHorizontalScroller, C.BOOL(C.YES))
C.objc_msgSend_bool(scrollview, _setHasVerticalScroller, C.BOOL(C.YES))
C.objc_msgSend_bool(scrollview, _setAutohidesScrollers, C.BOOL(C.YES))
C.objc_msgSend_id(scrollview, _setDocumentView, area)
return scrollview
}
func areaInScrollView(scrollview C.id) C.id {
return C.objc_msgSend_noargs(scrollview, _documentView)
}
func makeArea(parentWindow C.id, alternate bool) C.id {
area := objc_alloc(_goArea)
println(area)
area = objc_msgSend_rect(area, _initWithFrame,
0, 0, 100, 100)
println("out")
// TODO others?
area = newAreaScrollView(area)
addControl(parentWindow, area)
return area
} }
// TODO combine the below with the delegate stuff // TODO combine the below with the delegate stuff

View File

@ -93,6 +93,7 @@ struct xrect objc_msgSend_stret_rect_noargs(id obj, SEL sel)
id _objc_msgSend_rect(id obj, SEL sel, int64_t x, int64_t y, int64_t w, int64_t h) id _objc_msgSend_rect(id obj, SEL sel, int64_t x, int64_t y, int64_t w, int64_t h)
{ {
printf("%s\n", class_getName(objc_getMetaClass("goArea")));
return objc_msgSend(obj, sel, OurRect()); return objc_msgSend(obj, sel, OurRect());
} }

View File

@ -20,6 +20,7 @@ type sysData struct {
type classData struct { type classData struct {
make func(parentWindow C.id, alternate bool) C.id make func(parentWindow C.id, alternate bool) C.id
getinside func(scrollview C.id) C.id
show func(what C.id) show func(what C.id)
hide func(what C.id) hide func(what C.id)
settextsel C.SEL settextsel C.SEL
@ -269,6 +270,12 @@ var classTypes = [nctypes]*classData{
show: controlShow, show: controlShow,
hide: controlHide, hide: controlHide,
}, },
c_area: &classData{
make: makeArea,
getinside: areaInScrollView,
show: controlShow,
hide: controlHide,
},
} }
// I need to access sysData from appDelegate, but appDelegate doesn't store any data. So, this. // I need to access sysData from appDelegate, but appDelegate doesn't store any data. So, this.
@ -308,7 +315,14 @@ func (s *sysData) make(initText string, window *sysData) error {
} }
s.id = <-ret s.id = <-ret
s.setText(initText) s.setText(initText)
addSysData(s.id, s) if ct.getinside != nil {
uitask <- func() {
ret <- ct.getinside(s.id)
}
addSysData(<-ret, s)
} else {
addSysData(s.id, s)
}
return nil return nil
} }
@ -483,3 +497,17 @@ func (s *sysData) len() int {
} }
return <-ret return <-ret
} }
func (s *sysData) setAreaSize(width int, height int) {
ret := make(chan struct{})
defer close(ret)
uitask <- func() {
area := areaInScrollView(s.id)
println(C.GoString(C.object_getClassName(area)))
objc_msgSend_rect_bool(area, _setFrameDisplay,
int(0), int(0), width, height,
C.BOOL(C.YES)) // redraw
ret <- struct{}{}
}
<-ret
}

View File

@ -93,6 +93,10 @@ func initCocoa() (NSApp C.id, err error) {
} }
C.objc_msgSend_bool(NSApp, _activateIgnoringOtherApps, C.BOOL(C.YES)) // TODO actually do C.NO here? Russ Cox does YES in his devdraw; the docs say the Finder does NO C.objc_msgSend_bool(NSApp, _activateIgnoringOtherApps, C.BOOL(C.YES)) // TODO actually do C.NO here? Russ Cox does YES in his devdraw; the docs say the Finder does NO
err = mkAppDelegate() err = mkAppDelegate()
if err != nil {
return
}
err = mkAreaClass()
return return
} }