Implemented the various parenting and sizing changes on the Mac OS X backend; also moved a line in window_windows.go around for consistency.
This commit is contained in:
parent
d1702d33e0
commit
3d5e8feba4
|
@ -11,8 +11,6 @@ import "C"
|
||||||
|
|
||||||
type widgetbase struct {
|
type widgetbase struct {
|
||||||
id C.id
|
id C.id
|
||||||
notnew bool // to prevent unparenting a new control
|
|
||||||
floating bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newWidget(id C.id) *widgetbase {
|
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
|
// these few methods are embedded by all the various Controls since they all will do the same thing
|
||||||
|
|
||||||
func (w *widgetbase) unparent() {
|
func (w *widgetbase) setParent(parent C.id) {
|
||||||
if w.notnew {
|
// redrawing the new window handled by C.parent()
|
||||||
// redrawing the old window handled by C.unparent()
|
C.parent(w.id, parent)
|
||||||
C.unparent(w.id)
|
|
||||||
w.floating = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *widgetbase) parent(win *window) {
|
func (w *widgetbase) containerShow() {
|
||||||
// redrawing the new window handled by C.parent()
|
C.controlSetHidden(w.id, C.NO)
|
||||||
C.parent(w.id, win.id, toBOOL(w.floating))
|
}
|
||||||
w.floating = false
|
|
||||||
w.notnew = true
|
func (w *widgetbase) containerHide() {
|
||||||
|
C.controlSetHidden(w.id, C.YES)
|
||||||
}
|
}
|
||||||
|
|
||||||
type button struct {
|
type button struct {
|
||||||
|
@ -100,3 +96,7 @@ func (c *checkbox) Checked() bool {
|
||||||
func (c *checkbox) SetChecked(checked bool) {
|
func (c *checkbox) SetChecked(checked bool) {
|
||||||
C.checkboxSetChecked(c.id, toBOOL(checked))
|
C.checkboxSetChecked(c.id, toBOOL(checked))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO
|
||||||
|
func newTab() Tab{return newButton("tab")}
|
||||||
|
func(*button)Append(string,Control){}
|
||||||
|
|
|
@ -9,24 +9,14 @@
|
||||||
#define toNSControl(x) ((NSControl *) (x))
|
#define toNSControl(x) ((NSControl *) (x))
|
||||||
#define toNSButton(x) ((NSButton *) (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);
|
|
||||||
}
|
|
||||||
|
|
||||||
void parent(id control, id parentid, BOOL floating)
|
|
||||||
{
|
{
|
||||||
[[toNSWindow(parentid) contentView] addSubview:toNSView(control)];
|
[[toNSWindow(parentid) contentView] addSubview:toNSView(control)];
|
||||||
if (floating) // previously unparented
|
}
|
||||||
[toNSView(control) release];
|
|
||||||
// redraw since we changed controls
|
void controlSetHidden(id control, BOOL hidden)
|
||||||
windowRedraw(parentid);
|
{
|
||||||
|
[toNSView(control) setHidden:hidden];
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void setStandardControlFont(id control)
|
static inline void setStandardControlFont(id control)
|
||||||
|
|
|
@ -31,8 +31,8 @@ extern void windowClose(id);
|
||||||
extern void windowRedraw(id);
|
extern void windowRedraw(id);
|
||||||
|
|
||||||
/* controls_darwin.m */
|
/* controls_darwin.m */
|
||||||
extern void unparent(id);
|
extern void parent(id, id);
|
||||||
extern void parent(id, id, BOOL);
|
extern void controlSetHidden(id, BOOL);
|
||||||
extern id newButton(void);
|
extern id newButton(void);
|
||||||
extern void buttonSetDelegate(id, void *);
|
extern void buttonSetDelegate(id, void *);
|
||||||
extern const char *buttonText(id);
|
extern const char *buttonText(id);
|
||||||
|
|
|
@ -35,11 +35,11 @@ func (w *window) beginResize() (d *sizing) {
|
||||||
return d
|
return d
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) endResize(d *sizing) {
|
func (c *container) endResize(d *sizing) {
|
||||||
// redraw
|
// redraw
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) translateAllocationCoords(allocations []*allocation, winwidth, winheight int) {
|
func (c *container) translateAllocationCoords(allocations []*allocation, winwidth, winheight int) {
|
||||||
for _, a := range allocations {
|
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 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
|
// (winheight - y) - height because (x, y) is the bottom-left corner of the control and not the top-left
|
||||||
|
|
|
@ -13,23 +13,29 @@ import "C"
|
||||||
type window struct {
|
type window struct {
|
||||||
id C.id
|
id C.id
|
||||||
|
|
||||||
child Control
|
|
||||||
|
|
||||||
closing *event
|
closing *event
|
||||||
|
|
||||||
spaced bool
|
*container
|
||||||
}
|
}
|
||||||
|
|
||||||
func newWindow(title string, width int, height int) *window {
|
type controlParent interface {
|
||||||
|
setParent(C.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
func newWindow(title string, width int, height int, control Control) *window {
|
||||||
id := C.newWindow(C.intptr_t(width), C.intptr_t(height))
|
id := C.newWindow(C.intptr_t(width), C.intptr_t(height))
|
||||||
ctitle := C.CString(title)
|
ctitle := C.CString(title)
|
||||||
defer C.free(unsafe.Pointer(ctitle))
|
defer C.free(unsafe.Pointer(ctitle))
|
||||||
C.windowSetTitle(id, ctitle)
|
C.windowSetTitle(id, ctitle)
|
||||||
w := &window{
|
w := &window{
|
||||||
id: id,
|
id: id,
|
||||||
closing: newEvent(),
|
closing: newEvent(),
|
||||||
|
container: new(container),
|
||||||
}
|
}
|
||||||
|
w.container.beginResize = w.beginResize
|
||||||
C.windowSetDelegate(id, unsafe.Pointer(w))
|
C.windowSetDelegate(id, unsafe.Pointer(w))
|
||||||
|
w.child = control
|
||||||
|
w.child.setParent(w.id)
|
||||||
return w
|
return w
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,6 +78,6 @@ func windowClosing(xw unsafe.Pointer) C.BOOL {
|
||||||
//export windowResized
|
//export windowResized
|
||||||
func windowResized(xw unsafe.Pointer, width C.uintptr_t, height C.uintptr_t) {
|
func windowResized(xw unsafe.Pointer, width C.uintptr_t, height C.uintptr_t) {
|
||||||
w := (*window)(unsafe.Pointer(xw))
|
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)
|
fmt.Printf("new size %d x %d\n", width, height)
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,12 +12,12 @@ import (
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
type window struct {
|
type window struct {
|
||||||
*container
|
|
||||||
|
|
||||||
hwnd C.HWND
|
hwnd C.HWND
|
||||||
shownbefore bool
|
shownbefore bool
|
||||||
|
|
||||||
closing *event
|
closing *event
|
||||||
|
|
||||||
|
*container
|
||||||
}
|
}
|
||||||
|
|
||||||
const windowclassname = ""
|
const windowclassname = ""
|
||||||
|
|
Loading…
Reference in New Issue