Updated the GTK+ backend to have the new parenting and sizing changes. Now to implement Tab! ...though I should probably implement the changes on Mac OS X first.

This commit is contained in:
Pietro Gagliardi 2014-07-25 19:44:32 -04:00
parent 010c97d686
commit d1702d33e0
3 changed files with 32 additions and 36 deletions

View File

@ -15,8 +15,6 @@ import "C"
type widgetbase struct {
widget *C.GtkWidget
parentw *window
floating bool
}
func newWidget(w *C.GtkWidget) *widgetbase {
@ -27,31 +25,18 @@ func newWidget(w *C.GtkWidget) *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.parentw != nil {
// add another reference so it doesn't get removed by accident
C.g_object_ref(C.gpointer(unsafe.Pointer(w.widget)))
// we unref this in parent() below
w.floating = true
C.gtk_container_remove(w.parentw.layoutc, w.widget)
// redraw since we changed controls (by queueing a resize; thanks Jasper in irc.gimp.net/#gtk+)
C.gtk_widget_queue_resize(w.parentw.layoutw)
w.parentw = nil
}
}
func (w *widgetbase) parent(win *window) {
C.gtk_container_add(win.layoutc, w.widget)
w.parentw = win
// was previously parented; unref our saved ref
if w.floating {
C.g_object_unref(C.gpointer(unsafe.Pointer(w.widget)))
w.floating = false
}
func (w *widgetbase) setParent(c *C.GtkContainer) {
C.gtk_container_add(c, w.widget)
// make sure the new widget is shown
C.gtk_widget_show_all(w.widget)
// redraw since we changed controls (see above)
C.gtk_widget_queue_resize(win.layoutw)
}
func (w *widgetbase) containerShow() {
C.gtk_widget_show_all(w.widget)
}
func (w *widgetbase) containerHide() {
C.gtk_widget_hide(w.widget)
}
type button struct {
@ -135,3 +120,7 @@ func (c *checkbox) Checked() bool {
func (c *checkbox) SetChecked(checked bool) {
C.gtk_toggle_button_set_active(c.toggle, togbool(checked))
}
//TODO
func newTab() Tab{return newButton("tab")}
func(*button)Append(string,Control){}

View File

@ -35,11 +35,12 @@ func (w *window) beginResize() (d *sizing) {
return d
}
func (w *window) endResize(d *sizing) {
C.gtk_widget_queue_draw(w.widget)
func (c *container) endResize(d *sizing) {
// TODO
// C.gtk_widget_queue_draw(w.widget)
}
func (w *window) translateAllocationCoords(allocations []*allocation, winwidth, winheight int) {
func (c *container) translateAllocationCoords(allocations []*allocation, winwidth, winheight int) {
// no need for coordinate conversion with gtk+
}

View File

@ -16,7 +16,7 @@ import "C"
type window struct {
widget *C.GtkWidget
container *C.GtkContainer
wc *C.GtkContainer
bin *C.GtkBin
window *C.GtkWindow
@ -24,28 +24,32 @@ type window struct {
layoutc *C.GtkContainer
layout *C.GtkLayout
child Control
closing *event
spaced bool
*container
}
func newWindow(title string, width int, height int) *window {
type controlParent interface {
setParent(*C.GtkContainer)
}
func newWindow(title string, width int, height int, control Control) *window {
widget := C.gtk_window_new(C.GTK_WINDOW_TOPLEVEL)
ctitle := togstr(title)
defer freegstr(ctitle)
layoutw := C.gtk_layout_new(nil, nil)
w := &window{
widget: widget,
container: (*C.GtkContainer)(unsafe.Pointer(widget)),
wc: (*C.GtkContainer)(unsafe.Pointer(widget)),
bin: (*C.GtkBin)(unsafe.Pointer(widget)),
window: (*C.GtkWindow)(unsafe.Pointer(widget)),
layoutw: layoutw,
layoutc: (*C.GtkContainer)(unsafe.Pointer(layoutw)),
layout: (*C.GtkLayout)(unsafe.Pointer(layoutw)),
closing: newEvent(),
container: new(container),
}
w.container.beginResize = w.beginResize
C.gtk_window_set_title(w.window, ctitle)
g_signal_connect(
C.gpointer(unsafe.Pointer(w.window)),
@ -62,7 +66,9 @@ func newWindow(title string, width int, height int) *window {
C.GCallback(C.windowResizing),
C.gpointer(unsafe.Pointer(w)))
C.gtk_window_resize(w.window, C.gint(width), C.gint(height))
C.gtk_container_add(w.container, layoutw)
C.gtk_container_add(w.wc, layoutw)
w.child = control
w.child.setParent(w.layoutc)
return w
}
@ -105,6 +111,6 @@ func windowClosing(wid *C.GtkWidget, e *C.GdkEvent, data C.gpointer) C.gboolean
//export windowResizing
func windowResizing(wid *C.GtkWidget, r *C.GdkRectangle, data C.gpointer) {
w := (*window)(unsafe.Pointer(data))
w.doresize(int(r.width), int(r.height))
w.resize(int(r.width), int(r.height))
fmt.Printf("new size %d x %d\n", r.width, r.height)
}