From c5e5fbd909ed4bd3e788cb84cec85aee7302dedf Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Wed, 6 May 2015 18:05:07 -0400 Subject: [PATCH] Laid the foundation for proper tab navigation in uiTabs. --- ui_windows.h | 6 ++++++ windows/newcontrol.c | 4 ++++ windows/tab.c | 10 +++++++++- windows/uipriv_windows.h | 4 ++++ windows/util.c | 20 ++++++++++++++++++++ 5 files changed, 43 insertions(+), 1 deletion(-) diff --git a/ui_windows.h b/ui_windows.h index 7c24a4d1..de8dcec9 100644 --- a/ui_windows.h +++ b/ui_windows.h @@ -56,6 +56,7 @@ extern void uiWindowsControlSetText(uiControl *, const char *); struct uiControlSysFuncParams { int Func; + BOOL HasTabStops; }; enum { @@ -63,6 +64,11 @@ enum { // These are needed because while disabling a parent window does cause children to stop receiving events, they are not shown as disabled, which is not what we want. uiWindowsSysFuncContainerEnable, uiWindowsSysFuncContainerDisable, + // This is interpreted by controls that are tab stops; the control should set HasTabStops to TRUE if so, and *LEAVE IT ALONE* if not. + // You only need this if implementing your own uiControl. + // Controls created with uiWindowsMakeControl() check for the presence of WS_TABSTOP. + // The name is "has tab stops" because it is used by uiTabs to say "does the current tab page have tab stops?". + uiWindowsSysFuncHasTabStops, }; #endif diff --git a/windows/newcontrol.c b/windows/newcontrol.c index a19b8cc8..5fe97b71 100644 --- a/windows/newcontrol.c +++ b/windows/newcontrol.c @@ -118,6 +118,10 @@ static void singleSysFunc(uiControl *c, uiControlSysFuncParams *p) s->containerDisabled = 1; EnableWindow(s->hwnd, FALSE); return; + case uiWindowsSysFuncHasTabStops: + if ((getStyle(s->hwnd) & WS_TABSTOP) != 0) + p->HasTabStops = TRUE; + return; } complain("unknown p->Func %d in singleSysFunc()", p->Func); } diff --git a/windows/tab.c b/windows/tab.c index 2a9e407f..0c5874ae 100644 --- a/windows/tab.c +++ b/windows/tab.c @@ -131,6 +131,14 @@ static void tabSysFunc(uiControl *c, uiControlSysFuncParams *p) struct tabPage *page; uintmax_t i; + // we handle tab stops specially + if (p->Func == uiWindowsSysFuncHasTabStops) { + // 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); @@ -324,7 +332,7 @@ uiTab *uiNewTab(void) 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; + 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) p.hInstance = hInstance; p.useStandardControlFont = TRUE; p.onWM_COMMAND = onWM_COMMAND; diff --git a/windows/uipriv_windows.h b/windows/uipriv_windows.h index 1d1fa4a4..26345c18 100644 --- a/windows/uipriv_windows.h +++ b/windows/uipriv_windows.h @@ -52,6 +52,10 @@ extern HBRUSH hollowBrush; // util.c extern int windowClassOf(HWND, ...); extern void mapWindowRect(HWND, HWND, RECT *); +extern DWORD getStyle(HWND); +extern void setStyle(HWND, DWORD); +extern DWORD getExStyle(HWND); +extern void setExStyle(HWND, DWORD); // text.c extern WCHAR *toUTF16(const char *); diff --git a/windows/util.c b/windows/util.c index 8cb48837..caac4dd8 100644 --- a/windows/util.c +++ b/windows/util.c @@ -95,3 +95,23 @@ void mapWindowRect(HWND from, HWND to, RECT *r) logLastError("error calling MapWindowRect() in mapWindowRect()"); } } + +DWORD getStyle(HWND hwnd) +{ + return (DWORD) GetWindowLongPtrW(hwnd, GWL_STYLE); +} + +void setStyle(HWND hwnd, DWORD style) +{ + SetWindowLongPtrW(hwnd, GWL_STYLE, (LONG_PTR) style); +} + +DWORD getExStyle(HWND hwnd) +{ + return (DWORD) GetWindowLongPtrW(hwnd, GWL_EXSTYLE); +} + +void setExStyle(HWND hwnd, DWORD exstyle) +{ + SetWindowLongPtrW(hwnd, GWL_EXSTYLE, (LONG_PTR) exstyle); +}