Began migrating the Windows code away from using container entirely. This is going to be a mess for Tab... hopefully only a short-term one.

This commit is contained in:
Pietro Gagliardi 2014-10-26 14:43:45 -04:00
parent acc8157bea
commit db80156eba
5 changed files with 39 additions and 26 deletions

View File

@ -89,13 +89,13 @@ const (
paddingDialogUnits = 4 paddingDialogUnits = 4
) )
func (w *window) beginResize() (d *sizing) { func beginResize(hwnd C.HWND) (d *sizing) {
var baseX, baseY C.int var baseX, baseY C.int
var internalLeading C.LONG var internalLeading C.LONG
d = new(sizing) d = new(sizing)
C.calculateBaseUnits(w.hwnd, &baseX, &baseY, &internalLeading) C.calculateBaseUnits(hwnd, &baseX, &baseY, &internalLeading)
d.baseX = baseX d.baseX = baseX
d.baseY = baseY d.baseY = baseY
d.internalLeading = internalLeading d.internalLeading = internalLeading

View File

@ -10,6 +10,8 @@ static LRESULT CALLBACK tabSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM l
{ {
NMHDR *nmhdr = (NMHDR *) lParam; NMHDR *nmhdr = (NMHDR *) lParam;
LRESULT r; LRESULT r;
RECT resizeRect;
WINDOWPOS *wp;
switch (uMsg) { switch (uMsg) {
case msgNOTIFY: case msgNOTIFY:
@ -27,6 +29,17 @@ static LRESULT CALLBACK tabSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM l
return (*fv_DefSubclassProc)(hwnd, uMsg, wParam, lParam); return (*fv_DefSubclassProc)(hwnd, uMsg, wParam, lParam);
case msgTabCurrentTabHasChildren: case msgTabCurrentTabHasChildren:
return (LRESULT) tabTabHasChildren((void *) data, SendMessageW(hwnd, TCM_GETCURSEL, 0, 0)); return (LRESULT) tabTabHasChildren((void *) data, SendMessageW(hwnd, TCM_GETCURSEL, 0, 0));
case WM_WINDOWPOSCHANGING:
case WM_WINDOWPOSCHANGED:
wp = (WINDOWPOS *) lParam;
resizeRect.left = wp->x;
resizeRect.top = wp->y;
resizeRect.right = wp->x + wp->cx;
resizeRect.bottom = wp->y + wp->cy;
tabGetContentRect(hwnd, &resizeRect);
tabResized((void *) data, resizeRect);
// and chain up
return (*fv_DefSubclassProc)(hwnd, uMsg, wParam, lParam);
case WM_NCDESTROY: case WM_NCDESTROY:
if ((*fv_RemoveWindowSubclass)(hwnd, tabSubProc, id) == FALSE) if ((*fv_RemoveWindowSubclass)(hwnd, tabSubProc, id) == FALSE)
xpanic("error removing Tab subclass (which was for its own event handler)", GetLastError()); xpanic("error removing Tab subclass (which was for its own event handler)", GetLastError());

View File

@ -20,6 +20,7 @@ type tab struct {
tabs []*container tabs []*container
children []Control children []Control
chainresize func(x int, y int, width int, height int, d *sizing) chainresize func(x int, y int, width int, height int, d *sizing)
current int
} }
func newTab() Tab { func newTab() Tab {
@ -28,6 +29,7 @@ func newTab() Tab {
0) // don't set WS_EX_CONTROLPARENT here; see uitask_windows.c 0) // don't set WS_EX_CONTROLPARENT here; see uitask_windows.c
t := &tab{ t := &tab{
controlSingleHWND: newControlSingleHWND(hwnd), controlSingleHWND: newControlSingleHWND(hwnd),
current: -1,
} }
t.fpreferredSize = t.xpreferredSize t.fpreferredSize = t.xpreferredSize
t.chainresize = t.fresize t.chainresize = t.fresize
@ -61,7 +63,9 @@ func tabChanging(data unsafe.Pointer, current C.LRESULT) {
//export tabChanged //export tabChanged
func tabChanged(data unsafe.Pointer, new C.LRESULT) { func tabChanged(data unsafe.Pointer, new C.LRESULT) {
t := (*tab)(data) t := (*tab)(data)
t.tabs[int(new)].show() t.current = int(new)
// TODO resize the new tab
t.tabs[t.current].show()
} }
//export tabTabHasChildren //export tabTabHasChildren
@ -89,27 +93,22 @@ func (t *tab) xpreferredSize(d *sizing) (width, height int) {
return width, height + int(C.tabGetTabHeight(t.hwnd)) return width, height + int(C.tabGetTabHeight(t.hwnd))
} }
// a tab control contains other controls; size appropriately // no need to resize the other controls; we do that in tabResized() which is called by the tab subclass handler
func (t *tab) xresize(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 // just chain up to the container base to keep the Z-order correct
t.chainresize(x, y, width, height, d) t.chainresize(x, y, width, height, d)
}
// now resize the children
var r C.RECT //export tabResized
func tabResized(data unsafe.Pointer, r C.RECT) {
// figure out what the rect for each child is... t := (*tab)(data)
// the tab contents are children of the tab itself, so ignore x and y, which are relative to the window! if t.current == -1 { // nothing to do
r.left = C.LONG(0) return
r.top = C.LONG(0) }
r.right = C.LONG(width) d := beginResize(t.hwnd)
r.bottom = C.LONG(height) // only need to resize the current tab; we resize new tabs when the tab changes in tabChanged() above
C.tabGetContentRect(t.hwnd, &r) // because each widget is actually a child of the Window, the origin is the one we calculated above
// and resize tabs t.tabs[t.current].resize(int(r.left), int(r.top), int(r.right - r.left), int(r.bottom - r.top), d)
// don't resize just the current tab; resize all tabs! // TODO get the actual client rect
for i, _ := range t.tabs { t.children[t.current].resize(int(0), int(0), int(r.right - r.left), int(r.bottom - r.top), d)
// because each widget is actually a child of the Window, the origin is the one we calculated above
t.tabs[i].resize(int(r.left), int(r.top), int(r.right - r.left), int(r.bottom - r.top), d)
// TODO get the actual client rect
t.children[i].resize(int(0), int(0), int(r.right - r.left), int(r.bottom - r.top), d)
}
} }

View File

@ -28,7 +28,8 @@ static LRESULT CALLBACK windowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARA
if (FillRect((HDC) wParam, &r, windowBackground) == 0) if (FillRect((HDC) wParam, &r, windowBackground) == 0)
xpanic("error filling WM_PRINTCLIENT DC with window background color", GetLastError()); xpanic("error filling WM_PRINTCLIENT DC with window background color", GetLastError());
return lResult; return lResult;
case WM_SIZE: case WM_WINDOWPOSCHANGING:
case WM_WINDOWPOSCHANGED:
if (GetClientRect(hwnd, &r) == 0) if (GetClientRect(hwnd, &r) == 0)
xpanic("error getting client rect for Window in WM_SIZE", GetLastError()); xpanic("error getting client rect for Window in WM_SIZE", GetLastError());
windowResize(data, &r); windowResize(data, &r);

View File

@ -86,7 +86,7 @@ func (w *window) SetMargined(margined bool) {
//export windowResize //export windowResize
func windowResize(data unsafe.Pointer, r *C.RECT) { func windowResize(data unsafe.Pointer, r *C.RECT) {
w := (*window)(data) w := (*window)(data)
d := w.beginResize() d := beginResize(w.hwnd)
if w.margined { if w.margined {
marginRectDLU(r, marginDialogUnits, marginDialogUnits, marginDialogUnits, marginDialogUnits, d) marginRectDLU(r, marginDialogUnits, marginDialogUnits, marginDialogUnits, marginDialogUnits, d)
} }