summaryrefslogtreecommitdiff
path: root/redo/control_unix.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-08-03 16:28:21 -0400
committerPietro Gagliardi <[email protected]>2014-08-03 16:28:21 -0400
commitb6d07237b423b690570e105e5f0810d35693b0d0 (patch)
treefdf2f0ec2a66f217080dfeb0b60de9e763a9bd95 /redo/control_unix.go
parentfd48be68ee957e936c272348d3f0b0bddaba5c92 (diff)
Migrated the GTK+ backend to the new Control system. Added controlParent to deal with interface issues; need to apply this to the Windows backend too.
Diffstat (limited to 'redo/control_unix.go')
-rw-r--r--redo/control_unix.go138
1 files changed, 74 insertions, 64 deletions
diff --git a/redo/control_unix.go b/redo/control_unix.go
index d0a4c18..490d5a2 100644
--- a/redo/control_unix.go
+++ b/redo/control_unix.go
@@ -11,92 +11,102 @@ import (
// #include "gtk_unix.h"
import "C"
-type controlbase struct {
- *controldefs
- widget *C.GtkWidget
+// all Controls that call base methods must be this
+type controlPrivate interface {
+ widget() *C.GtkWidget
+ Control
}
type controlParent struct {
c *C.GtkContainer
}
-func newControl(widget *C.GtkWidget) *controlbase {
- c := new(controlbase)
- c.widget = widget
- c.controldefs = new(controldefs)
- c.fsetParent = func(p *controlParent) {
- C.gtk_container_add(p.c, c.widget)
- // make sure the new widget is shown if not explicitly hidden
- c.containerShow()
- }
- c.fcontainerShow = func() {
- C.gtk_widget_show_all(c.widget)
- }
- c.fcontainerHide = func() {
- C.gtk_widget_hide(c.widget)
- }
- c.fallocate = baseallocate(c)
- c.fpreferredSize = func(d *sizing) (int, int) {
- // GTK+ 3 makes this easy: controls can tell us what their preferred size is!
- // ...actually, it tells us two things: the "minimum size" and the "natural size".
- // The "minimum size" is the smallest size we /can/ display /anything/. The "natural size" is the smallest size we would /prefer/ to display.
- // The difference? Minimum size takes into account things like truncation with ellipses: the minimum size of a label can allot just the ellipses!
- // So we use the natural size instead.
- // There is a warning about height-for-width controls, but in my tests this isn't an issue.
- // For Areas, we manually save the Area size and use that, just to be safe.
+func basesetParent(c controlPrivate, p *controlParent) {
+ C.gtk_container_add(p.c, c.widget())
+ // make sure the new widget is shown if not explicitly hidden
+ c.containerShow()
+}
+
+func basecontainerShow(c controlPrivate) {
+ C.gtk_widget_show_all(c.widget())
+}
+
+func basecontainerHide(c controlPrivate) {
+ C.gtk_widget_hide(c.widget())
+}
+
+func basepreferredSize(c controlPrivate, d *sizing) (int, int) {
+ // GTK+ 3 makes this easy: controls can tell us what their preferred size is!
+ // ...actually, it tells us two things: the "minimum size" and the "natural size".
+ // The "minimum size" is the smallest size we /can/ display /anything/. The "natural size" is the smallest size we would /prefer/ to display.
+ // The difference? Minimum size takes into account things like truncation with ellipses: the minimum size of a label can allot just the ellipses!
+ // So we use the natural size instead.
+ // There is a warning about height-for-width controls, but in my tests this isn't an issue.
+ // For Areas, we manually save the Area size and use that, just to be safe.
//TODO
/*
- if s.ctype == c_area {
- return s.areawidth, s.areaheight
- }
+ if s.ctype == c_area {
+ return s.areawidth, s.areaheight
+ }
*/
- var r C.GtkRequisition
+ var r C.GtkRequisition
- C.gtk_widget_get_preferred_size(c.widget, nil, &r)
- return int(r.width), int(r.height)
- }
- c.fcommitResize = func(a *allocation, d *sizing) {
- // as we resize on size-allocate, we have to also use size-allocate on our children
- // this is fine anyway; in fact, this allows us to move without knowing what the container is!
- // this is what GtkBox does anyway
- // thanks to tristan in irc.gimp.net/#gtk+
+ C.gtk_widget_get_preferred_size(c.widget(), nil, &r)
+ return int(r.width), int(r.height)
+}
- var r C.GtkAllocation
+func basecommitResize(c controlPrivate, a *allocation, d *sizing) {
+ dobasecommitResize(c.widget(), a, d)
+}
- r.x = C.int(a.x)
- r.y = C.int(a.y)
- r.width = C.int(a.width)
- r.height = C.int(a.height)
- C.gtk_widget_size_allocate(c.widget, &r)
- }
- c.fgetAuxResizeInfo = func(d *sizing) {
- // controls set this to true if a Label to its left should be vertically aligned to the control's top
- d.shouldVAlignTop = false
- }
- return c
+func dobasecommitResize(w *C.GtkWidget, c *allocation, d *sizing) {
+ // as we resize on size-allocate, we have to also use size-allocate on our children
+ // this is fine anyway; in fact, this allows us to move without knowing what the container is!
+ // this is what GtkBox does anyway
+ // thanks to tristan in irc.gimp.net/#gtk+
+
+ var r C.GtkAllocation
+
+ r.x = C.int(c.x)
+ r.y = C.int(c.y)
+ r.width = C.int(c.width)
+ r.height = C.int(c.height)
+ C.gtk_widget_size_allocate(w, &r)
}
-type scrolledcontrol struct {
- *controlbase
- scroller *controlbase
+func basegetAuxResizeInfo(d *sizing) {
+ // controls set this to true if a Label to its left should be vertically aligned to the control's top
+ d.shouldVAlignTop = false
+}
+
+type scroller struct {
+ scrollwidget *C.GtkWidget
scrollcontainer *C.GtkContainer
scrollwindow *C.GtkScrolledWindow
}
-func newScrolledControl(widget *C.GtkWidget, native bool) *scrolledcontrol {
- scroller := C.gtk_scrolled_window_new(nil, nil)
- s := &scrolledcontrol{
- controlbase: newControl(widget),
- scroller: newControl(scroller),
- scrollcontainer: (*C.GtkContainer)(unsafe.Pointer(scroller)),
- scrollwindow: (*C.GtkScrolledWindow)(unsafe.Pointer(scroller)),
+func newScroller(widget *C.GtkWidget, native bool) *scroller {
+ scrollwidget := C.gtk_scrolled_window_new(nil, nil)
+ s := &scroller{
+ scrollwidget: scrollwidget,
+ scrollcontainer: (*C.GtkContainer)(unsafe.Pointer(scrollwidget)),
+ scrollwindow: (*C.GtkScrolledWindow)(unsafe.Pointer(scrollwidget)),
}
// give the scrolled window a border (thanks to jlindgren in irc.gimp.net/#gtk+)
C.gtk_scrolled_window_set_shadow_type(s.scrollwindow, C.GTK_SHADOW_IN)
- C.gtk_container_add(s.scrollcontainer, s.widget)
- s.fsetParent = s.scroller.fsetParent
- s.fcommitResize = s.scroller.fcommitResize
+ // TODO use native here
+ C.gtk_container_add(s.scrollcontainer, widget)
return s
}
+
+func (s *scroller) setParent(p *controlParent) {
+ C.gtk_container_add(p.c, s.scrollwidget)
+ // TODO for when hiding/showing is implemented
+ C.gtk_widget_show_all(s.scrollwidget)
+}
+
+func (s *scroller) commitResize(c *allocation, d *sizing) {
+ dobasecommitResize(s.scrollwidget, c, d)
+}