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)),
textfielddone: newEvent(),
}
a.fpreferredSize = a.preferredSize
a.fpreferredSize = a.xpreferredSize
for _, c := range areaCallbacks {
g_signal_connect(
C.gpointer(unsafe.Pointer(a.drawingarea)),
@ -491,7 +491,7 @@ var modonlykeys = map[C.guint]Modifiers{
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
return a.width, a.height
}

View File

@ -40,7 +40,7 @@ func newArea(ab *areabase) Area {
textfielddone: newEvent(),
}
a.controlSingleHWND = newControlSingleHWND(C.newArea(unsafe.Pointer(a)))
a.fpreferredSize = a.preferredSize
a.fpreferredSize = a.xpreferredSize
a.SetSize(a.width, a.height)
a.textfield = C.newAreaTextField(a.hwnd, unsafe.Pointer(a))
C.controlSetControlFont(a.textfield)
@ -330,7 +330,7 @@ func areaResetClickCounter(data unsafe.Pointer) {
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
return a.width, a.height
}

View File

@ -24,7 +24,7 @@ func newButton(text string) *button {
controlSingleHWNDWithText: newControlSingleHWNDWithText(hwnd),
clicked: newEvent(),
}
b.fpreferredSize = b.preferredSize
b.fpreferredSize = b.xpreferredSize
b.SetText(text)
C.controlSetControlFont(b.hwnd)
C.setButtonSubclass(b.hwnd, unsafe.Pointer(b))
@ -54,7 +54,7 @@ const (
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...
var size C.SIZE

View File

@ -24,7 +24,7 @@ func newCheckbox(text string) *checkbox {
controlSingleHWNDWithText: newControlSingleHWNDWithText(hwnd),
toggled: newEvent(),
}
c.fpreferredSize = c.preferredSize
c.fpreferredSize = c.xpreferredSize
c.SetText(text)
C.controlSetControlFont(c.hwnd)
C.setCheckboxSubclass(c.hwnd, unsafe.Pointer(c))
@ -68,7 +68,7 @@ const (
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),
fromdlgunitsY(checkboxHeight, d)
}

View File

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

View File

@ -23,22 +23,22 @@ type controlSingleWidget struct {
func newControlSingleWidget(widget *C.GtkWidget) *controlSingleWidget {
c := new(controlSingleWidget)
c.controlbase = &controlbase{
fsetParent: c.setParent,
fpreferredSize: c.preferredSize,
fresize: c.resize,
fsetParent: c.xsetParent,
fpreferredSize: c.xpreferredSize,
fresize: c.xresize,
}
c.widget = widget
return c
}
func (c *controlSingleWidget) setParent(p *controlParent) {
func (c *controlSingleWidget) xsetParent(p *controlParent) {
C.gtk_container_add(p.c, c.widget)
// make sure the new widget is shown if not explicitly hidden
// TODO why did I have this again?
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!
// ...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.
@ -51,7 +51,7 @@ func (c *controlSingleWidget) preferredSize(d *sizing) (int, int) {
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
// this is fine anyway; in fact, this allows us to move without knowing what the container is!
// this is what GtkBox does anyway

View File

@ -19,8 +19,8 @@ type controlSingleHWND struct {
func newControlSingleHWND(hwnd C.HWND) *controlSingleHWND {
c := new(controlSingleHWND)
c.controlbase = &controlbase{
fsetParent: c.setParent,
fresize: c.resize,
fsetParent: c.xsetParent,
fresize: c.xresize,
fnTabStops: func() int {
// most controls count as one tab stop
return 1
@ -30,11 +30,11 @@ func newControlSingleHWND(hwnd C.HWND) *controlSingleHWND {
return c
}
func (c *controlSingleHWND) setParent(p *controlParent) {
func (c *controlSingleHWND) xsetParent(p *controlParent) {
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))
}

View File

@ -20,6 +20,8 @@ type group struct {
container *container
margined bool
chainresize func(x int, y int, width int, height int, d *sizing)
}
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.container.setParent(&controlParent{g.gcontainer})
g.fresize = g.resize
g.chainresize = g.fresize
g.fresize = g.xresize
return g
}
@ -77,10 +80,9 @@ func (g *group) SetMargined(margined bool) {
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
// TODO use a variable for this
g.controlSingleWidget.resize(x, y, width, height, d)
g.chainresize(x, y, width, height, d)
// now that the container has the correct size, we can resize the child
a := g.container.allocation(g.margined)

View File

@ -9,6 +9,7 @@ type group struct {
*controlSingleHWNDWithText
child Control
margined bool
chainresize func(x int, y int, width int, height int, d *sizing)
}
func newGroup(text string, control Control) Group {
@ -19,8 +20,9 @@ func newGroup(text string, control Control) Group {
controlSingleHWNDWithText: newControlSingleHWNDWithText(hwnd),
child: control,
}
g.fpreferredSize = g.preferredSize
g.fresize = g.resize
g.fpreferredSize = g.xpreferredSize
g.chainresize = g.fresize
g.fresize = g.xresize
g.fnTabStops = control.nTabStops // groupbox itself is not tabbable but the contents might be
g.SetText(text)
C.controlSetControlFont(g.hwnd)
@ -50,7 +52,7 @@ const (
groupYMarginBottom = 7
)
func (g *group) preferredSize(d *sizing) (width, height int) {
func (g *group) xpreferredSize(d *sizing) (width, height int) {
var r C.RECT
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)
}
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
// TODO use a variable for this
g.controlSingleHWNDWithText.resize(x, y, width, height, d)
g.chainresize(x, y, width, height, d)
// now resize the child container
var r C.RECT

View File

@ -21,7 +21,7 @@ func newLabel(text string) Label {
l := &label{
controlSingleHWNDWithText: newControlSingleHWNDWithText(hwnd),
}
l.fpreferredSize = l.preferredSize
l.fpreferredSize = l.xpreferredSize
l.fnTabStops = func() int {
// labels are not tab stops
return 0
@ -45,7 +45,7 @@ const (
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)
}

View File

@ -18,6 +18,8 @@ type tab struct {
tabs []*container
children []Control
chainresize func(x int, y int, width int, height int, d *sizing)
}
func newTab() Tab {
@ -27,7 +29,8 @@ func newTab() Tab {
container: (*C.GtkContainer)(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
C.gtk_notebook_set_scrollable(t.notebook, C.TRUE)
return t
@ -48,10 +51,9 @@ func (t *tab) Append(name string, control Control) {
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
// TODO use a variable for this
t.controlSingleWidget.resize(x, y, width, height, d)
t.chainresize(x, y, width, height, d)
// now that the containers have the correct size, we can resize the children
for i, _ := range t.tabs {

View File

@ -19,6 +19,7 @@ type tab struct {
*controlSingleHWND
tabs []*container
children []Control
chainresize func(x int, y int, width int, height int, d *sizing)
}
func newTab() Tab {
@ -28,8 +29,9 @@ func newTab() Tab {
t := &tab{
controlSingleHWND: newControlSingleHWND(hwnd),
}
t.fpreferredSize = t.preferredSize
t.fresize = t.resize
t.fpreferredSize = t.xpreferredSize
t.chainresize = t.fresize
t.fresize = t.xresize
// count tabs as 1 tab stop; the actual number of tab stops varies
C.controlSetControlFont(t.hwnd)
C.setTabSubclass(t.hwnd, unsafe.Pointer(t))
@ -74,7 +76,7 @@ func tabTabHasChildren(data unsafe.Pointer, which C.LRESULT) C.BOOL {
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 {
w, h := c.preferredSize(d)
if width < w {
@ -88,10 +90,9 @@ func (t *tab) preferredSize(d *sizing) (width, height int) {
}
// 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
// TODO use a variable for this
t.controlSingleHWND.resize(x, y, width, height, d)
t.chainresize(x, y, width, height, d)
// now resize the children
var r C.RECT

View File

@ -21,6 +21,7 @@ type table struct {
pushedrow C.int
pushedcol C.int
selected *event
chainresize func(x int, y int, width int, height int, d *sizing)
}
func finishNewTable(b *tablebase, ty reflect.Type) Table {
@ -36,8 +37,9 @@ func finishNewTable(b *tablebase, ty reflect.Type) Table {
pushedcol: -1,
selected: newEvent(),
}
t.fpreferredSize = t.preferredSize
t.fresize = t.resize
t.fpreferredSize = t.xpreferredSize
t.chainresize = t.fresize
t.fresize = t.xresize
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_SUBITEMIMAGES gives us images in subitems, which will be important when both images and checkboxes are added
@ -221,13 +223,12 @@ const (
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)
}
func (t *table) commitResize(x int, y int, width int, height int, d *sizing) {
// TODO use a variable for this
t.controlSingleHWND.resize(x, y, width, height, d)
func (t *table) xresize(x int, y int, width int, height int, d *sizing) {
t.chainresize(x, y, width, height, d)
t.RLock()
defer t.RUnlock()
t.autoresize()

View File

@ -24,7 +24,7 @@ func startNewTextField(style C.DWORD) *textfield {
controlSingleHWNDWithText: newControlSingleHWNDWithText(hwnd),
changed: newEvent(),
}
t.fpreferredSize = t.preferredSize
t.fpreferredSize = t.xpreferredSize
C.controlSetControlFont(t.hwnd)
C.setTextFieldSubclass(t.hwnd, unsafe.Pointer(t))
return t
@ -70,6 +70,6 @@ const (
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)
}