summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-03-30 11:19:13 -0400
committerPietro Gagliardi <[email protected]>2014-03-30 11:19:13 -0400
commit08dfb5da2034c33b68d7247dd16925960b3b88a3 (patch)
tree054e95178635037bfdc8d78959a4f2bb957fab9c
parentf2d6daa9ea2203a897ee3af77105273531622aaf (diff)
Attempted to add the Area bare bones and resizing code to the Mac OS X backend. It complains that initWithFrame: is not implemented...
-rw-r--r--area_darwin.go37
-rw-r--r--bleh_darwin.m1
-rw-r--r--sysdata_darwin.go30
-rw-r--r--uitask_darwin.go4
4 files changed, 69 insertions, 3 deletions
diff --git a/area_darwin.go b/area_darwin.go
index 4f27554..a767411 100644
--- a/area_darwin.go
+++ b/area_darwin.go
@@ -15,15 +15,17 @@ import (
import "C"
const (
- _goArea = "goArea"
+ __goArea = "goArea"
)
var (
+ _goArea C.id
+
_drawRect = sel_getUid("drawRect:")
)
func mkAreaClass() error {
- areaclass, err := makeAreaClass(_goArea)
+ areaclass, err := makeAreaClass(__goArea)
if err != nil {
return fmt.Errorf("error creating Area backend class: %v", err)
}
@@ -33,12 +35,43 @@ func mkAreaClass() error {
if ok != C.BOOL(C.YES) {
return fmt.Errorf("error overriding Area drawRect: method; reason unknown")
}
+ _goArea = objc_getClass(__goArea)
return nil
}
//export areaView_drawRect
func areaView_drawRect(self C.id, rect C.struct_xrect) {
// 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
diff --git a/bleh_darwin.m b/bleh_darwin.m
index ac6182a..fb57bb3 100644
--- a/bleh_darwin.m
+++ b/bleh_darwin.m
@@ -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)
{
+printf("%s\n", class_getName(objc_getMetaClass("goArea")));
return objc_msgSend(obj, sel, OurRect());
}
diff --git a/sysdata_darwin.go b/sysdata_darwin.go
index 5b2f126..b3ee48d 100644
--- a/sysdata_darwin.go
+++ b/sysdata_darwin.go
@@ -20,6 +20,7 @@ type sysData struct {
type classData struct {
make func(parentWindow C.id, alternate bool) C.id
+ getinside func(scrollview C.id) C.id
show func(what C.id)
hide func(what C.id)
settextsel C.SEL
@@ -269,6 +270,12 @@ var classTypes = [nctypes]*classData{
show: controlShow,
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.
@@ -308,7 +315,14 @@ func (s *sysData) make(initText string, window *sysData) error {
}
s.id = <-ret
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
}
@@ -483,3 +497,17 @@ func (s *sysData) len() int {
}
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
+}
diff --git a/uitask_darwin.go b/uitask_darwin.go
index 79d582e..2d13b6e 100644
--- a/uitask_darwin.go
+++ b/uitask_darwin.go
@@ -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
err = mkAppDelegate()
+ if err != nil {
+ return
+ }
+ err = mkAreaClass()
return
}