summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--redo/controls_darwin.go26
-rw-r--r--redo/controls_darwin.m18
-rw-r--r--redo/objc_darwin.h4
-rw-r--r--redo/sizing_darwin.go4
-rw-r--r--redo/window_darwin.go20
-rw-r--r--redo/window_windows.go4
6 files changed, 36 insertions, 40 deletions
diff --git a/redo/controls_darwin.go b/redo/controls_darwin.go
index 8d13aaa..0c3442c 100644
--- a/redo/controls_darwin.go
+++ b/redo/controls_darwin.go
@@ -11,8 +11,6 @@ import "C"
type widgetbase struct {
id C.id
- notnew bool // to prevent unparenting a new control
- floating bool
}
func newWidget(id C.id) *widgetbase {
@@ -23,19 +21,17 @@ func newWidget(id C.id) *widgetbase {
// these few methods are embedded by all the various Controls since they all will do the same thing
-func (w *widgetbase) unparent() {
- if w.notnew {
- // redrawing the old window handled by C.unparent()
- C.unparent(w.id)
- w.floating = true
- }
+func (w *widgetbase) setParent(parent C.id) {
+ // redrawing the new window handled by C.parent()
+ C.parent(w.id, parent)
}
-func (w *widgetbase) parent(win *window) {
- // redrawing the new window handled by C.parent()
- C.parent(w.id, win.id, toBOOL(w.floating))
- w.floating = false
- w.notnew = true
+func (w *widgetbase) containerShow() {
+ C.controlSetHidden(w.id, C.NO)
+}
+
+func (w *widgetbase) containerHide() {
+ C.controlSetHidden(w.id, C.YES)
}
type button struct {
@@ -100,3 +96,7 @@ 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 85de6c8..4ec42ef 100644
--- a/redo/controls_darwin.m
+++ b/redo/controls_darwin.m
@@ -9,24 +9,14 @@
#define toNSControl(x) ((NSControl *) (x))
#define toNSButton(x) ((NSButton *) (x))
-void unparent(id control)
+void parent(id control, id parentid)
{
- NSWindow *old;
-
- [toNSView(control) retain]; // save from being freed when released by the removal selector below
- old = [toNSView(control) window];
- [toNSView(control) removeFromSuperview];
- // redraw since we changed controls
- windowRedraw((id) old);
+ [[toNSWindow(parentid) contentView] addSubview:toNSView(control)];
}
-void parent(id control, id parentid, BOOL floating)
+void controlSetHidden(id control, BOOL hidden)
{
- [[toNSWindow(parentid) contentView] addSubview:toNSView(control)];
- if (floating) // previously unparented
- [toNSView(control) release];
- // redraw since we changed controls
- windowRedraw(parentid);
+ [toNSView(control) setHidden:hidden];
}
static inline void setStandardControlFont(id control)
diff --git a/redo/objc_darwin.h b/redo/objc_darwin.h
index e69ed71..057b4a0 100644
--- a/redo/objc_darwin.h
+++ b/redo/objc_darwin.h
@@ -31,8 +31,8 @@ extern void windowClose(id);
extern void windowRedraw(id);
/* controls_darwin.m */
-extern void unparent(id);
-extern void parent(id, id, BOOL);
+extern void parent(id, id);
+extern void controlSetHidden(id, BOOL);
extern id newButton(void);
extern void buttonSetDelegate(id, void *);
extern const char *buttonText(id);
diff --git a/redo/sizing_darwin.go b/redo/sizing_darwin.go
index c23a75c..8b141c2 100644
--- a/redo/sizing_darwin.go
+++ b/redo/sizing_darwin.go
@@ -35,11 +35,11 @@ func (w *window) beginResize() (d *sizing) {
return d
}
-func (w *window) endResize(d *sizing) {
+func (c *container) endResize(d *sizing) {
// redraw
}
-func (w *window) translateAllocationCoords(allocations []*allocation, winwidth, winheight int) {
+func (c *container) translateAllocationCoords(allocations []*allocation, winwidth, winheight int) {
for _, a := range allocations {
// winheight - y because (0,0) is the bottom-left corner of the window and not the top-left corner
// (winheight - y) - height because (x, y) is the bottom-left corner of the control and not the top-left
diff --git a/redo/window_darwin.go b/redo/window_darwin.go
index 859c79a..90679bc 100644
--- a/redo/window_darwin.go
+++ b/redo/window_darwin.go
@@ -13,23 +13,29 @@ import "C"
type window struct {
id C.id
- child Control
-
closing *event
- spaced bool
+ *container
+}
+
+type controlParent interface {
+ setParent(C.id)
}
-func newWindow(title string, width int, height int) *window {
+func newWindow(title string, width int, height int, control Control) *window {
id := C.newWindow(C.intptr_t(width), C.intptr_t(height))
ctitle := C.CString(title)
defer C.free(unsafe.Pointer(ctitle))
C.windowSetTitle(id, ctitle)
w := &window{
- id: id,
- closing: newEvent(),
+ id: id,
+ closing: newEvent(),
+ container: new(container),
}
+ w.container.beginResize = w.beginResize
C.windowSetDelegate(id, unsafe.Pointer(w))
+ w.child = control
+ w.child.setParent(w.id)
return w
}
@@ -72,6 +78,6 @@ func windowClosing(xw unsafe.Pointer) C.BOOL {
//export windowResized
func windowResized(xw unsafe.Pointer, width C.uintptr_t, height C.uintptr_t) {
w := (*window)(unsafe.Pointer(xw))
- w.doresize(int(width), int(height))
+ w.resize(int(width), int(height))
fmt.Printf("new size %d x %d\n", width, height)
}
diff --git a/redo/window_windows.go b/redo/window_windows.go
index 34e8f93..96a9d5e 100644
--- a/redo/window_windows.go
+++ b/redo/window_windows.go
@@ -12,12 +12,12 @@ import (
import "C"
type window struct {
- *container
-
hwnd C.HWND
shownbefore bool
closing *event
+
+ *container
}
const windowclassname = ""