diff --git a/redo/windows/OLDtab.c b/redo/windows/OLDtab.c index 22e817a0..075f0043 100644 --- a/redo/windows/OLDtab.c +++ b/redo/windows/OLDtab.c @@ -1,16 +1,6 @@ // 12 april 2015 #include "uipriv_windows.h" -struct tab { - uiTab t; - HWND hwnd; - struct ptrArray *pages; - void (*baseResize)(uiControl *, intmax_t, intmax_t, intmax_t, intmax_t, uiSizing *); - void (*baseEnable)(uiControl *); - void (*baseDisable)(uiControl *); - void (*baseSysFunc)(uiControl *, uiControlSysFuncParams *); -}; - // from http://msdn.microsoft.com/en-us/library/windows/desktop/bb226818%28v=vs.85%29.aspx #define tabMargin 7 @@ -42,102 +32,3 @@ static void tabPreferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_ *width = r.right - r.left; *height = r.bottom - r.top; } - -static void tabSysFunc(uiControl *c, uiControlSysFuncParams *p) -{ - struct tab *t = (struct tab *) c; - struct tabPage *page; - uintmax_t i; - - // we handle tab stops specially - if (p->Func == uiWindowsSysFuncHasTabStops) { - // if disabled, not a tab stop - if (IsWindowEnabled(t->hwnd) != 0) - // if there are no tabs, it is not a tab stop - if (t->pages->len != 0) - p->HasTabStops = TRUE; - return; - } - // otherwise distribute it throughout all pages - (*(t->baseSysFunc))(uiControl(t), p); - for (i = 0; i < t->pages->len; i++) { - page = ptrArrayIndex(t->pages, struct tabPage *, i); - uiControlSysFunc(page->control, p); - } -} - -// this is also partially where tab navigation is handled -static LRESULT CALLBACK tabSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) -{ - struct tab *t = (struct tab *) dwRefData; - RECT r; - LRESULT n; - uiControlSysFuncParams p; - struct tabPage *page; - - switch (uMsg) { - case msgHasTabStops: - n = SendMessageW(t->hwnd, TCM_GETCURSEL, 0, 0); - if (n == (LRESULT) (-1)) // no current selection == no tab stops - return FALSE; - p.Func = uiWindowsSysFuncHasTabStops; - p.HasTabStops = FALSE; - page = ptrArrayIndex(t->pages, struct tabPage *, n); - uiControlSysFunc(page->control, &p); - return p.HasTabStops; - case WM_NCDESTROY: - if (RemoveWindowSubclass(hwnd, tabSubProc, uIdSubclass) == FALSE) - logLastError("error removing Tab resize handling subclass in tabSubProc()"); - break; - } - return DefSubclassProc(hwnd, uMsg, wParam, lParam); -} - -uiTab *uiNewTab(void) -{ - struct tab *t; - uiWindowsMakeControlParams p; - - t = uiNew(struct tab); - uiTyped(t)->Type = uiTypeTab(); - - p.dwExStyle = 0; // don't set WS_EX_CONTROLPARENT yet; we do that dynamically in the message loop (see main_windows.c) - p.lpClassName = WC_TABCONTROLW; - p.lpWindowName = L""; - p.dwStyle = TCS_TOOLTIPS | WS_TABSTOP; // start with this; we will alternate between this and WS_EX_CONTROLPARENT as needed (see main.c and msgHasTabStops above and the toggling functions below) - p.hInstance = hInstance; - p.lpParam = NULL; - p.useStandardControlFont = TRUE; - p.onWM_COMMAND = onWM_COMMAND; - p.onWM_NOTIFY = onWM_NOTIFY; - p.onDestroy = onDestroy; - p.onDestroyData = t; - uiWindowsMakeControl(uiControl(t), &p); - - t->hwnd = (HWND) uiControlHandle(uiControl(t)); - t->pages = newPtrArray(); - - if (SetWindowSubclass(t->hwnd, tabSubProc, 0, (DWORD_PTR) t) == FALSE) - logLastError("error subclassing Tab to give it its own resize handler in uiNewTab()"); - - uiControl(t)->PreferredSize = tabPreferredSize; - t->baseResize = uiControl(t)->Resize; - uiControl(t)->Resize = tabResize; - uiControl(t)->ComputeChildSize = tabComputeChildSize; - t->baseEnable = uiControl(t)->Enable; - uiControl(t)->Enable = tabEnable; - t->baseDisable = uiControl(t)->Disable; - uiControl(t)->Disable = tabDisable; - // TODO ContainerEnable/ContainerDisable - t->baseSysFunc = uiControl(t)->SysFunc; - uiControl(t)->SysFunc = tabSysFunc; - - uiTab(t)->Append = tabAppend; - uiTab(t)->InsertAt = tabInsertAt; - uiTab(t)->Delete = tabDelete; - uiTab(t)->NumPages = tabNumPages; - uiTab(t)->Margined = tabMargined; - uiTab(t)->SetMargined = tabSetMargined; - - return uiTab(t); -} diff --git a/redo/windows/tab.c b/redo/windows/tab.c index bcea80cd..5843bcbd 100644 --- a/redo/windows/tab.c +++ b/redo/windows/tab.c @@ -233,6 +233,30 @@ static void tabSetMargined(uiTab *tt, uintmax_t n, int margined) uiControlQueueResize(page); } +// this handles tab navigation; see main.c for details +static LRESULT CALLBACK tabSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) +{ + struct tab *t = (struct tab *) dwRefData; + LRESULT n; + uiControl *page; + + switch (uMsg) { + case msgHasTabStops: + n = SendMessageW(t->hwnd, TCM_GETCURSEL, 0, 0); + if (n == (LRESULT) (-1)) // no current selection == no tab stops + return FALSE; + page = ptrArrayIndex(t->pages, uiControl *, n); + if (uiControlHasTabStops(page)) + return TRUE; + return FALSE; + case WM_NCDESTROY: + if (RemoveWindowSubclass(hwnd, tabSubProc, uIdSubclass) == FALSE) + logLastError("error removing Tab resize handling subclass in tabSubProc()"); + break; + } + return DefSubclassProc(hwnd, uMsg, wParam, lParam); +} + uiTab *uiNewTab(void) { struct tab *t; @@ -248,6 +272,9 @@ uiTab *uiNewTab(void) uiWindowsRegisterWM_NOTIFYHandler(t->hwnd, onWM_NOTIFY, uiControl(t)); + if (SetWindowSubclass(t->hwnd, tabSubProc, 0, (DWORD_PTR) t) == FALSE) + logLastError("error subclassing Tab to assist in tab stop handling in uiNewTab()"); + t->pages = newPtrArray(); uiControl(t)->Handle = tabHandle;