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 {
|
||||
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){}
|
||||
|
|
|
@ -9,24 +9,14 @@
|
|||
#define toNSControl(x) ((NSControl *) (x))
|
||||
#define toNSButton(x) ((NSButton *) (x))
|
||||
|
||||
void unparent(id control)
|
||||
{
|
||||
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)
|
||||
void parent(id control, id parentid)
|
||||
{
|
||||
[[toNSWindow(parentid) contentView] addSubview:toNSView(control)];
|
||||
if (floating) // previously unparented
|
||||
[toNSView(control) release];
|
||||
// redraw since we changed controls
|
||||
windowRedraw(parentid);
|
||||
}
|
||||
|
||||
void controlSetHidden(id control, BOOL hidden)
|
||||
{
|
||||
[toNSView(control) setHidden:hidden];
|
||||
}
|
||||
|
||||
static inline void setStandardControlFont(id control)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -13,23 +13,29 @@ import "C"
|
|||
type window struct {
|
||||
id C.id
|
||||
|
||||
child Control
|
||||
|
||||
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))
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -12,12 +12,12 @@ import (
|
|||
import "C"
|
||||
|
||||
type window struct {
|
||||
*container
|
||||
|
||||
hwnd C.HWND
|
||||
shownbefore bool
|
||||
|
||||
closing *event
|
||||
|
||||
*container
|
||||
}
|
||||
|
||||
const windowclassname = ""
|
||||
|
|
Loading…
Reference in New Issue