Fixed parenting weirdnesses.

This commit is contained in:
Pietro Gagliardi 2014-10-18 12:47:19 -04:00
parent 0f6e65188a
commit b1ac28cc93
14 changed files with 59 additions and 50 deletions

View File

@ -65,7 +65,7 @@ func newArea(ab *areabase) Area {
textfield: (*C.GtkEntry)(unsafe.Pointer(textfieldw)), textfield: (*C.GtkEntry)(unsafe.Pointer(textfieldw)),
textfielddone: newEvent(), textfielddone: newEvent(),
} }
a.fpreferredSize = a.preferredSize a.fpreferredSize = a.xpreferredSize
for _, c := range areaCallbacks { for _, c := range areaCallbacks {
g_signal_connect( g_signal_connect(
C.gpointer(unsafe.Pointer(a.drawingarea)), C.gpointer(unsafe.Pointer(a.drawingarea)),
@ -491,7 +491,7 @@ var modonlykeys = map[C.guint]Modifiers{
C.GDK_KEY_Super_R: Super, C.GDK_KEY_Super_R: Super,
} }
func (a *area) preferredSize(d *sizing) (width, height int) { func (a *area) xpreferredSize(d *sizing) (width, height int) {
// the preferred size of an Area is its size // the preferred size of an Area is its size
return a.width, a.height return a.width, a.height
} }

View File

@ -40,7 +40,7 @@ func newArea(ab *areabase) Area {
textfielddone: newEvent(), textfielddone: newEvent(),
} }
a.controlSingleHWND = newControlSingleHWND(C.newArea(unsafe.Pointer(a))) a.controlSingleHWND = newControlSingleHWND(C.newArea(unsafe.Pointer(a)))
a.fpreferredSize = a.preferredSize a.fpreferredSize = a.xpreferredSize
a.SetSize(a.width, a.height) a.SetSize(a.width, a.height)
a.textfield = C.newAreaTextField(a.hwnd, unsafe.Pointer(a)) a.textfield = C.newAreaTextField(a.hwnd, unsafe.Pointer(a))
C.controlSetControlFont(a.textfield) C.controlSetControlFont(a.textfield)
@ -330,7 +330,7 @@ func areaResetClickCounter(data unsafe.Pointer) {
a.clickCounter.reset() a.clickCounter.reset()
} }
func (a *area) preferredSize(d *sizing) (width, height int) { func (a *area) xpreferredSize(d *sizing) (width, height int) {
// the preferred size of an Area is its size // the preferred size of an Area is its size
return a.width, a.height return a.width, a.height
} }

View File

@ -24,7 +24,7 @@ func newButton(text string) *button {
controlSingleHWNDWithText: newControlSingleHWNDWithText(hwnd), controlSingleHWNDWithText: newControlSingleHWNDWithText(hwnd),
clicked: newEvent(), clicked: newEvent(),
} }
b.fpreferredSize = b.preferredSize b.fpreferredSize = b.xpreferredSize
b.SetText(text) b.SetText(text)
C.controlSetControlFont(b.hwnd) C.controlSetControlFont(b.hwnd)
C.setButtonSubclass(b.hwnd, unsafe.Pointer(b)) C.setButtonSubclass(b.hwnd, unsafe.Pointer(b))
@ -54,7 +54,7 @@ const (
buttonHeight = 14 buttonHeight = 14
) )
func (b *button) preferredSize(d *sizing) (width, height int) { func (b *button) xpreferredSize(d *sizing) (width, height int) {
// comctl32.dll version 6 thankfully provides a method to grab this... // comctl32.dll version 6 thankfully provides a method to grab this...
var size C.SIZE var size C.SIZE

View File

@ -24,7 +24,7 @@ func newCheckbox(text string) *checkbox {
controlSingleHWNDWithText: newControlSingleHWNDWithText(hwnd), controlSingleHWNDWithText: newControlSingleHWNDWithText(hwnd),
toggled: newEvent(), toggled: newEvent(),
} }
c.fpreferredSize = c.preferredSize c.fpreferredSize = c.xpreferredSize
c.SetText(text) c.SetText(text)
C.controlSetControlFont(c.hwnd) C.controlSetControlFont(c.hwnd)
C.setCheckboxSubclass(c.hwnd, unsafe.Pointer(c)) C.setCheckboxSubclass(c.hwnd, unsafe.Pointer(c))
@ -68,7 +68,7 @@ const (
checkboxXFromLeftOfBoxToLeftOfLabel = 12 checkboxXFromLeftOfBoxToLeftOfLabel = 12
) )
func (c *checkbox) preferredSize(d *sizing) (width, height int) { func (c *checkbox) xpreferredSize(d *sizing) (width, height int) {
return fromdlgunitsX(checkboxXFromLeftOfBoxToLeftOfLabel, d) + int(c.textlen), return fromdlgunitsX(checkboxXFromLeftOfBoxToLeftOfLabel, d) + int(c.textlen),
fromdlgunitsY(checkboxHeight, d) fromdlgunitsY(checkboxHeight, d)
} }

View File

@ -17,6 +17,8 @@ type controlbase struct {
fnTabStops func() int fnTabStops func() int
} }
// children should not use the same name as these, otherwise weird things will happen
func (c *controlbase) setParent(p *controlParent) { func (c *controlbase) setParent(p *controlParent) {
c.fsetParent(p) c.fsetParent(p)
} }

View File

@ -23,22 +23,22 @@ type controlSingleWidget struct {
func newControlSingleWidget(widget *C.GtkWidget) *controlSingleWidget { func newControlSingleWidget(widget *C.GtkWidget) *controlSingleWidget {
c := new(controlSingleWidget) c := new(controlSingleWidget)
c.controlbase = &controlbase{ c.controlbase = &controlbase{
fsetParent: c.setParent, fsetParent: c.xsetParent,
fpreferredSize: c.preferredSize, fpreferredSize: c.xpreferredSize,
fresize: c.resize, fresize: c.xresize,
} }
c.widget = widget c.widget = widget
return c return c
} }
func (c *controlSingleWidget) setParent(p *controlParent) { func (c *controlSingleWidget) xsetParent(p *controlParent) {
C.gtk_container_add(p.c, c.widget) C.gtk_container_add(p.c, c.widget)
// make sure the new widget is shown if not explicitly hidden // make sure the new widget is shown if not explicitly hidden
// TODO why did I have this again? // TODO why did I have this again?
C.gtk_widget_show_all(c.widget) C.gtk_widget_show_all(c.widget)
} }
func (c *controlSingleWidget) preferredSize(d *sizing) (int, int) { func (c *controlSingleWidget) xpreferredSize(d *sizing) (int, int) {
// GTK+ 3 makes this easy: controls can tell us what their preferred size is! // 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". // ...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 "minimum size" is the smallest size we /can/ display /anything/. The "natural size" is the smallest size we would /prefer/ to display.
@ -51,7 +51,7 @@ func (c *controlSingleWidget) preferredSize(d *sizing) (int, int) {
return int(r.width), int(r.height) return int(r.width), int(r.height)
} }
func (c *controlSingleWidget) resize(x int, y int, width int, height int, d *sizing) { func (c *controlSingleWidget) xresize(x int, y int, width int, height int, d *sizing) {
// as we resize on size-allocate, we have to also use size-allocate on our children // 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 fine anyway; in fact, this allows us to move without knowing what the container is!
// this is what GtkBox does anyway // this is what GtkBox does anyway

View File

@ -19,8 +19,8 @@ type controlSingleHWND struct {
func newControlSingleHWND(hwnd C.HWND) *controlSingleHWND { func newControlSingleHWND(hwnd C.HWND) *controlSingleHWND {
c := new(controlSingleHWND) c := new(controlSingleHWND)
c.controlbase = &controlbase{ c.controlbase = &controlbase{
fsetParent: c.setParent, fsetParent: c.xsetParent,
fresize: c.resize, fresize: c.xresize,
fnTabStops: func() int { fnTabStops: func() int {
// most controls count as one tab stop // most controls count as one tab stop
return 1 return 1
@ -30,11 +30,11 @@ func newControlSingleHWND(hwnd C.HWND) *controlSingleHWND {
return c return c
} }
func (c *controlSingleHWND) setParent(p *controlParent) { func (c *controlSingleHWND) xsetParent(p *controlParent) {
C.controlSetParent(c.hwnd, p.hwnd) C.controlSetParent(c.hwnd, p.hwnd)
} }
func (c *controlSingleHWND) resize(x int, y int, width int, height int, d *sizing) { func (c *controlSingleHWND) xresize(x int, y int, width int, height int, d *sizing) {
C.moveWindow(c.hwnd, C.int(x), C.int(y), C.int(width), C.int(height)) C.moveWindow(c.hwnd, C.int(x), C.int(y), C.int(width), C.int(height))
} }

View File

@ -20,6 +20,8 @@ type group struct {
container *container container *container
margined bool margined bool
chainresize func(x int, y int, width int, height int, d *sizing)
} }
func newGroup(text string, control Control) Group { func newGroup(text string, control Control) Group {
@ -54,7 +56,8 @@ func newGroup(text string, control Control) Group {
g.child.setParent(g.container.parent()) g.child.setParent(g.container.parent())
g.container.setParent(&controlParent{g.gcontainer}) g.container.setParent(&controlParent{g.gcontainer})
g.fresize = g.resize g.chainresize = g.fresize
g.fresize = g.xresize
return g return g
} }
@ -77,10 +80,9 @@ func (g *group) SetMargined(margined bool) {
g.margined = margined g.margined = margined
} }
func (g *group) resize(x int, y int, width int, height int, d *sizing) { func (g *group) xresize(x int, y int, width int, height int, d *sizing) {
// first, chain up to change the GtkFrame and its child container // first, chain up to change the GtkFrame and its child container
// TODO use a variable for this g.chainresize(x, y, width, height, d)
g.controlSingleWidget.resize(x, y, width, height, d)
// now that the container has the correct size, we can resize the child // now that the container has the correct size, we can resize the child
a := g.container.allocation(g.margined) a := g.container.allocation(g.margined)

View File

@ -9,6 +9,7 @@ type group struct {
*controlSingleHWNDWithText *controlSingleHWNDWithText
child Control child Control
margined bool margined bool
chainresize func(x int, y int, width int, height int, d *sizing)
} }
func newGroup(text string, control Control) Group { func newGroup(text string, control Control) Group {
@ -19,8 +20,9 @@ func newGroup(text string, control Control) Group {
controlSingleHWNDWithText: newControlSingleHWNDWithText(hwnd), controlSingleHWNDWithText: newControlSingleHWNDWithText(hwnd),
child: control, child: control,
} }
g.fpreferredSize = g.preferredSize g.fpreferredSize = g.xpreferredSize
g.fresize = g.resize g.chainresize = g.fresize
g.fresize = g.xresize
g.fnTabStops = control.nTabStops // groupbox itself is not tabbable but the contents might be g.fnTabStops = control.nTabStops // groupbox itself is not tabbable but the contents might be
g.SetText(text) g.SetText(text)
C.controlSetControlFont(g.hwnd) C.controlSetControlFont(g.hwnd)
@ -50,7 +52,7 @@ const (
groupYMarginBottom = 7 groupYMarginBottom = 7
) )
func (g *group) preferredSize(d *sizing) (width, height int) { func (g *group) xpreferredSize(d *sizing) (width, height int) {
var r C.RECT var r C.RECT
width, height = g.child.preferredSize(d) width, height = g.child.preferredSize(d)
@ -73,10 +75,9 @@ func (g *group) preferredSize(d *sizing) (width, height int) {
return int(r.right - r.left), int(r.bottom - r.top) return int(r.right - r.left), int(r.bottom - r.top)
} }
func (g *group) resize(x int, y int, width int, height int, d *sizing) { func (g *group) xresize(x int, y int, width int, height int, d *sizing) {
// first, chain up to the container base to keep the Z-order correct // first, chain up to the container base to keep the Z-order correct
// TODO use a variable for this g.chainresize(x, y, width, height, d)
g.controlSingleHWNDWithText.resize(x, y, width, height, d)
// now resize the child container // now resize the child container
var r C.RECT var r C.RECT

View File

@ -21,7 +21,7 @@ func newLabel(text string) Label {
l := &label{ l := &label{
controlSingleHWNDWithText: newControlSingleHWNDWithText(hwnd), controlSingleHWNDWithText: newControlSingleHWNDWithText(hwnd),
} }
l.fpreferredSize = l.preferredSize l.fpreferredSize = l.xpreferredSize
l.fnTabStops = func() int { l.fnTabStops = func() int {
// labels are not tab stops // labels are not tab stops
return 0 return 0
@ -45,7 +45,7 @@ const (
labelYOffset = 3 labelYOffset = 3
) )
func (l *label) preferredSize(d *sizing) (width, height int) { func (l *label) xpreferredSize(d *sizing) (width, height int) {
return int(l.textlen), fromdlgunitsY(labelHeight, d) return int(l.textlen), fromdlgunitsY(labelHeight, d)
} }

View File

@ -18,6 +18,8 @@ type tab struct {
tabs []*container tabs []*container
children []Control children []Control
chainresize func(x int, y int, width int, height int, d *sizing)
} }
func newTab() Tab { func newTab() Tab {
@ -27,7 +29,8 @@ func newTab() Tab {
container: (*C.GtkContainer)(unsafe.Pointer(widget)), container: (*C.GtkContainer)(unsafe.Pointer(widget)),
notebook: (*C.GtkNotebook)(unsafe.Pointer(widget)), notebook: (*C.GtkNotebook)(unsafe.Pointer(widget)),
} }
t.fresize = t.resize t.chainresize = t.fresize
t.fresize = t.xresize
// there are no scrolling arrows by default; add them in case there are too many tabs // there are no scrolling arrows by default; add them in case there are too many tabs
C.gtk_notebook_set_scrollable(t.notebook, C.TRUE) C.gtk_notebook_set_scrollable(t.notebook, C.TRUE)
return t return t
@ -48,10 +51,9 @@ func (t *tab) Append(name string, control Control) {
cname) cname)
} }
func (t *tab) resize(x int, y int, width int, height int, d *sizing) { func (t *tab) xresize(x int, y int, width int, height int, d *sizing) {
// first, chain up to change the GtkFrame and its child container // first, chain up to change the GtkFrame and its child container
// TODO use a variable for this t.chainresize(x, y, width, height, d)
t.controlSingleWidget.resize(x, y, width, height, d)
// now that the containers have the correct size, we can resize the children // now that the containers have the correct size, we can resize the children
for i, _ := range t.tabs { for i, _ := range t.tabs {

View File

@ -17,8 +17,9 @@ We'll create a dummy window using the container window class for each tab page.
type tab struct { type tab struct {
*controlSingleHWND *controlSingleHWND
tabs []*container tabs []*container
children []Control children []Control
chainresize func(x int, y int, width int, height int, d *sizing)
} }
func newTab() Tab { func newTab() Tab {
@ -28,8 +29,9 @@ func newTab() Tab {
t := &tab{ t := &tab{
controlSingleHWND: newControlSingleHWND(hwnd), controlSingleHWND: newControlSingleHWND(hwnd),
} }
t.fpreferredSize = t.preferredSize t.fpreferredSize = t.xpreferredSize
t.fresize = t.resize t.chainresize = t.fresize
t.fresize = t.xresize
// count tabs as 1 tab stop; the actual number of tab stops varies // count tabs as 1 tab stop; the actual number of tab stops varies
C.controlSetControlFont(t.hwnd) C.controlSetControlFont(t.hwnd)
C.setTabSubclass(t.hwnd, unsafe.Pointer(t)) C.setTabSubclass(t.hwnd, unsafe.Pointer(t))
@ -74,7 +76,7 @@ func tabTabHasChildren(data unsafe.Pointer, which C.LRESULT) C.BOOL {
return C.FALSE return C.FALSE
} }
func (t *tab) preferredSize(d *sizing) (width, height int) { func (t *tab) xpreferredSize(d *sizing) (width, height int) {
for _, c := range t.children { for _, c := range t.children {
w, h := c.preferredSize(d) w, h := c.preferredSize(d)
if width < w { if width < w {
@ -88,10 +90,9 @@ func (t *tab) preferredSize(d *sizing) (width, height int) {
} }
// a tab control contains other controls; size appropriately // a tab control contains other controls; size appropriately
func (t *tab) resize(x int, y int, width int, height int, d *sizing) { func (t *tab) xresize(x int, y int, width int, height int, d *sizing) {
// first, chain up to the container base to keep the Z-order correct // first, chain up to the container base to keep the Z-order correct
// TODO use a variable for this t.chainresize(x, y, width, height, d)
t.controlSingleHWND.resize(x, y, width, height, d)
// now resize the children // now resize the children
var r C.RECT var r C.RECT

View File

@ -21,6 +21,7 @@ type table struct {
pushedrow C.int pushedrow C.int
pushedcol C.int pushedcol C.int
selected *event selected *event
chainresize func(x int, y int, width int, height int, d *sizing)
} }
func finishNewTable(b *tablebase, ty reflect.Type) Table { func finishNewTable(b *tablebase, ty reflect.Type) Table {
@ -36,8 +37,9 @@ func finishNewTable(b *tablebase, ty reflect.Type) Table {
pushedcol: -1, pushedcol: -1,
selected: newEvent(), selected: newEvent(),
} }
t.fpreferredSize = t.preferredSize t.fpreferredSize = t.xpreferredSize
t.fresize = t.resize t.chainresize = t.fresize
t.fresize = t.xresize
C.setTableSubclass(t.hwnd, unsafe.Pointer(t)) C.setTableSubclass(t.hwnd, unsafe.Pointer(t))
// LVS_EX_FULLROWSELECT gives us selection across the whole row, not just the leftmost column; this makes the list view work like on other platforms // LVS_EX_FULLROWSELECT gives us selection across the whole row, not just the leftmost column; this makes the list view work like on other platforms
// LVS_EX_SUBITEMIMAGES gives us images in subitems, which will be important when both images and checkboxes are added // LVS_EX_SUBITEMIMAGES gives us images in subitems, which will be important when both images and checkboxes are added
@ -221,13 +223,12 @@ const (
tableHeight = 50 tableHeight = 50
) )
func (t *table) preferredSize(d *sizing) (width, height int) { func (t *table) xpreferredSize(d *sizing) (width, height int) {
return fromdlgunitsX(tableWidth, d), fromdlgunitsY(tableHeight, d) return fromdlgunitsX(tableWidth, d), fromdlgunitsY(tableHeight, d)
} }
func (t *table) commitResize(x int, y int, width int, height int, d *sizing) { func (t *table) xresize(x int, y int, width int, height int, d *sizing) {
// TODO use a variable for this t.chainresize(x, y, width, height, d)
t.controlSingleHWND.resize(x, y, width, height, d)
t.RLock() t.RLock()
defer t.RUnlock() defer t.RUnlock()
t.autoresize() t.autoresize()

View File

@ -24,7 +24,7 @@ func startNewTextField(style C.DWORD) *textfield {
controlSingleHWNDWithText: newControlSingleHWNDWithText(hwnd), controlSingleHWNDWithText: newControlSingleHWNDWithText(hwnd),
changed: newEvent(), changed: newEvent(),
} }
t.fpreferredSize = t.preferredSize t.fpreferredSize = t.xpreferredSize
C.controlSetControlFont(t.hwnd) C.controlSetControlFont(t.hwnd)
C.setTextFieldSubclass(t.hwnd, unsafe.Pointer(t)) C.setTextFieldSubclass(t.hwnd, unsafe.Pointer(t))
return t return t
@ -70,6 +70,6 @@ const (
textfieldHeight = 14 textfieldHeight = 14
) )
func (t *textfield) preferredSize(d *sizing) (width, height int) { func (t *textfield) xpreferredSize(d *sizing) (width, height int) {
return fromdlgunitsX(textfieldWidth, d), fromdlgunitsY(textfieldHeight, d) return fromdlgunitsX(textfieldWidth, d), fromdlgunitsY(textfieldHeight, d)
} }