diff --git a/redo/containers_darwin.go b/redo/containers_darwin.go new file mode 100644 index 0000000..b42708c --- /dev/null +++ b/redo/containers_darwin.go @@ -0,0 +1,52 @@ +// 25 july 2014 + +package ui + +import ( + "unsafe" +) + +// #include "objc_darwin.h" +import "C" + +type tab struct { + *widgetbase + + containers []*container +} + +func newTab() Tab { + t := new(tab) + id := C.newTab(unsafe.Pointer(t)) + t.widgetbase = newWidget(id) + return t +} + +func (t *tab) Append(name string, control Control) { + // TODO isolate and standardize + c := new(container) + // don't set beginResize; this container's resize() will be a recursive call + t.containers = append(t.containers, c) + cname := C.CString(name) + defer C.free(unsafe.Pointer(cname)) + tabview := C.tabAppend(t.id, cname) + c.child = control + c.child.setParent(tabview) +} + +func (t *tab) allocate(x int, y int, width int, height int, d *sizing) []*allocation { + // set up the recursive calls + for _, c := range t.containers { + c.d = d + } + // and prepare the tabbed control itself + return t.widgetbase.allocate(x, y, width, height, d) +} + +//export tabResized +func tabResized(data unsafe.Pointer, width C.intptr_t, height C.intptr_t) { + t := (*tab)(unsafe.Pointer(data)) + for _, c := range t.containers { + c.resize(int(width), int(height)) + } +} diff --git a/redo/containers_darwin.m b/redo/containers_darwin.m new file mode 100644 index 0000000..0d3c33e --- /dev/null +++ b/redo/containers_darwin.m @@ -0,0 +1,46 @@ +// 25 july 2014 + +#import "objc_darwin.h" +#import "_cgo_export.h" +#import + +#define toNSTabView(x) ((NSTabView *) (x)) + +@interface goTabView : NSTabView { +@public + void *gotab; +} +@end + +@implementation goTabView + +- (void)setFrame:(NSRect)r +{ + NSRect content; + + [super setFrame:r]; + content = [self contentRect]; + tabResized(self->gotab, (intptr_t) content.size.width, (intptr_t) content.size.height); +} + +@end + +id newTab(void *gotab) +{ + goTabView *t; + + t = [[goTabView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]; + // TODO font + t->gotab = gotab; + return (id) t; +} + +id tabAppend(id t, char *name) +{ + NSTabViewItem *i; + + i = [[NSTabViewItem alloc] initWithIdentifier:nil]; + [i setLabel:[NSString stringWithUTF8String:name]]; + [toNSTabView(t) addTabViewItem:i]; + return (id) [i view]; +} diff --git a/redo/containers_unix.go b/redo/containers_unix.go index 2bae60b..6687994 100644 --- a/redo/containers_unix.go +++ b/redo/containers_unix.go @@ -1,3 +1,5 @@ +// +build !windows,!darwin + // 25 july 2014 package ui diff --git a/redo/controls_darwin.go b/redo/controls_darwin.go index 0c3442c..02b2d64 100644 --- a/redo/controls_darwin.go +++ b/redo/controls_darwin.go @@ -96,7 +96,3 @@ func (c *checkbox) Checked() bool { func (c *checkbox) SetChecked(checked bool) { C.checkboxSetChecked(c.id, toBOOL(checked)) } - -//TODO -func newTab() Tab{return newButton("tab")} -func(*button)Append(string,Control){} diff --git a/redo/controls_darwin.m b/redo/controls_darwin.m index 4ec42ef..ecb4abd 100644 --- a/redo/controls_darwin.m +++ b/redo/controls_darwin.m @@ -11,7 +11,7 @@ void parent(id control, id parentid) { - [[toNSWindow(parentid) contentView] addSubview:toNSView(control)]; + [toNSView(parentid) addSubview:toNSView(control)]; } void controlSetHidden(id control, BOOL hidden) diff --git a/redo/objc_darwin.h b/redo/objc_darwin.h index 057b4a0..6795698 100644 --- a/redo/objc_darwin.h +++ b/redo/objc_darwin.h @@ -28,6 +28,7 @@ extern void windowSetTitle(id, const char *); extern void windowShow(id); extern void windowHide(id); extern void windowClose(id); +extern id windowContentView(id); extern void windowRedraw(id); /* controls_darwin.m */ @@ -44,4 +45,8 @@ extern void checkboxSetChecked(id, BOOL); /* sizing_darwin.m */ extern void moveControl(id, intptr_t, intptr_t, intptr_t, intptr_t); +/* containers_darwin.m */ +extern id newTab(void *); +extern id tabAppend(id, char *); + #endif diff --git a/redo/window_darwin.go b/redo/window_darwin.go index 90679bc..16f8b9f 100644 --- a/redo/window_darwin.go +++ b/redo/window_darwin.go @@ -35,7 +35,7 @@ func newWindow(title string, width int, height int, control Control) *window { w.container.beginResize = w.beginResize C.windowSetDelegate(id, unsafe.Pointer(w)) w.child = control - w.child.setParent(w.id) + w.child.setParent(C.windowContentView(w.id)) return w } diff --git a/redo/window_darwin.m b/redo/window_darwin.m index 20e26e4..a923ef5 100644 --- a/redo/window_darwin.m +++ b/redo/window_darwin.m @@ -80,6 +80,11 @@ void windowClose(id win) [toNSWindow(win) close]; } +id windowContentView(id win) +{ + return (id) [toNSWindow(win) contentView]; +} + // fake a resize event under certain conditions; see each invocation for details void windowRedraw(id win) {