2014-08-14 09:42:10 -05:00
|
|
|
// 25 july 2014
|
2014-07-25 14:58:24 -05:00
|
|
|
|
|
|
|
#include "winapi_windows.h"
|
|
|
|
#include "_cgo_export.h"
|
|
|
|
|
2014-08-14 09:42:10 -05:00
|
|
|
// provided for cgo's benefit
|
2014-08-01 17:25:59 -05:00
|
|
|
LPWSTR xWC_TABCONTROL = WC_TABCONTROL;
|
2014-07-25 14:58:24 -05:00
|
|
|
|
|
|
|
static LRESULT CALLBACK tabSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR id, DWORD_PTR data)
|
|
|
|
{
|
|
|
|
NMHDR *nmhdr = (NMHDR *) lParam;
|
|
|
|
LRESULT r;
|
|
|
|
|
|
|
|
switch (uMsg) {
|
|
|
|
case msgNOTIFY:
|
|
|
|
switch (nmhdr->code) {
|
|
|
|
case TCN_SELCHANGING:
|
|
|
|
r = SendMessageW(hwnd, TCM_GETCURSEL, 0, 0);
|
2014-08-14 09:42:10 -05:00
|
|
|
if (r == (LRESULT) -1) // no tab currently selected
|
2014-07-25 14:58:24 -05:00
|
|
|
return FALSE;
|
|
|
|
tabChanging((void *) data, r);
|
2014-08-14 09:42:10 -05:00
|
|
|
return FALSE; // allow change
|
2014-07-25 14:58:24 -05:00
|
|
|
case TCN_SELCHANGE:
|
|
|
|
tabChanged((void *) data, SendMessageW(hwnd, TCM_GETCURSEL, 0, 0));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return (*fv_DefSubclassProc)(hwnd, uMsg, wParam, lParam);
|
|
|
|
case WM_NCDESTROY:
|
|
|
|
if ((*fv_RemoveWindowSubclass)(hwnd, tabSubProc, id) == FALSE)
|
|
|
|
xpanic("error removing Tab subclass (which was for its own event handler)", GetLastError());
|
|
|
|
return (*fv_DefSubclassProc)(hwnd, uMsg, wParam, lParam);
|
|
|
|
default:
|
|
|
|
return (*fv_DefSubclassProc)(hwnd, uMsg, wParam, lParam);
|
|
|
|
}
|
|
|
|
xmissedmsg("Tab", "tabSubProc()", uMsg);
|
2014-08-14 09:42:10 -05:00
|
|
|
return 0; // unreached
|
2014-07-25 14:58:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void setTabSubclass(HWND hwnd, void *data)
|
|
|
|
{
|
|
|
|
if ((*fv_SetWindowSubclass)(hwnd, tabSubProc, 0, (DWORD_PTR) data) == FALSE)
|
|
|
|
xpanic("error subclassing Tab to give it its own event handler", GetLastError());
|
|
|
|
}
|
|
|
|
|
2014-08-01 17:25:59 -05:00
|
|
|
void tabAppend(HWND hwnd, LPWSTR name)
|
2014-07-25 14:58:24 -05:00
|
|
|
{
|
|
|
|
TCITEM item;
|
|
|
|
LRESULT n;
|
|
|
|
|
|
|
|
ZeroMemory(&item, sizeof (TCITEM));
|
|
|
|
item.mask = TCIF_TEXT;
|
|
|
|
item.pszText = name;
|
2014-08-14 09:42:10 -05:00
|
|
|
// MSDN's example code uses the first invalid index directly for this
|
2014-07-25 14:58:24 -05:00
|
|
|
n = SendMessageW(hwnd, TCM_GETITEMCOUNT, 0, 0);
|
|
|
|
if (SendMessageW(hwnd, TCM_INSERTITEM, (WPARAM) n, (LPARAM) (&item)) == (LRESULT) -1)
|
|
|
|
xpanic("error adding tab to Tab", GetLastError());
|
|
|
|
}
|
|
|
|
|
2014-07-25 15:06:53 -05:00
|
|
|
void tabGetContentRect(HWND hwnd, RECT *r)
|
2014-07-25 14:58:24 -05:00
|
|
|
{
|
2014-08-14 09:42:10 -05:00
|
|
|
// not &r; already a pointer (thanks MindChild in irc.efnet.net/#winprog for spotting my failure)
|
2014-07-25 14:58:24 -05:00
|
|
|
SendMessageW(hwnd, TCM_ADJUSTRECT, FALSE, (LPARAM) r);
|
|
|
|
}
|
2014-08-02 10:05:18 -05:00
|
|
|
|
2014-08-14 09:42:10 -05:00
|
|
|
// theoretically we don't need to iterate over every tab for this, but let's do it just to be safe
|
2014-08-02 10:05:18 -05:00
|
|
|
LONG tabGetTabHeight(HWND hwnd)
|
|
|
|
{
|
|
|
|
RECT r;
|
2014-08-02 11:24:04 -05:00
|
|
|
LRESULT i, n;
|
|
|
|
LONG tallest;
|
2014-08-02 10:05:18 -05:00
|
|
|
|
|
|
|
n = SendMessageW(hwnd, TCM_GETITEMCOUNT, 0, 0);
|
2014-08-14 09:42:10 -05:00
|
|
|
// if there are no tabs, then the control just draws a box over the full window rect, reserving no space for tabs; this is handled with the next line
|
2014-08-02 11:24:04 -05:00
|
|
|
tallest = 0;
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
if (SendMessageW(hwnd, TCM_GETITEMRECT, (WPARAM) i, (LPARAM) (&r)) == FALSE)
|
|
|
|
xpanic("error getting tab height for Tab.preferredSize()", GetLastError());
|
|
|
|
if (tallest < (r.bottom - r.top))
|
|
|
|
tallest = r.bottom - r.top;
|
|
|
|
}
|
|
|
|
return tallest;
|
2014-08-02 10:05:18 -05:00
|
|
|
}
|
2014-08-14 10:30:48 -05:00
|
|
|
|
|
|
|
void tabEnterChildren(HWND hwnd)
|
|
|
|
{
|
|
|
|
DWORD style, xstyle;
|
|
|
|
|
|
|
|
style = (DWORD) GetWindowLongPtrW(hwnd, GWL_STYLE);
|
|
|
|
xstyle = (DWORD) GetWindowLongPtrW(hwnd, GWL_EXSTYLE);
|
|
|
|
style &= ~((DWORD) WS_TABSTOP);
|
|
|
|
xstyle |= WS_EX_CONTROLPARENT;
|
|
|
|
SetWindowLongPtrW(hwnd, GWL_STYLE, (LONG_PTR) style);
|
|
|
|
SetWindowLongPtrW(hwnd, GWL_EXSTYLE, (LONG_PTR) xstyle);
|
|
|
|
}
|
|
|
|
|
|
|
|
void tabLeaveChildren(HWND hwnd)
|
|
|
|
{
|
|
|
|
DWORD style, xstyle;
|
|
|
|
|
|
|
|
style = (DWORD) GetWindowLongPtrW(hwnd, GWL_STYLE);
|
|
|
|
xstyle = (DWORD) GetWindowLongPtrW(hwnd, GWL_EXSTYLE);
|
|
|
|
style |= WS_TABSTOP;
|
|
|
|
xstyle &= ~((DWORD) WS_EX_CONTROLPARENT);
|
|
|
|
SetWindowLongPtrW(hwnd, GWL_STYLE, (LONG_PTR) style);
|
|
|
|
SetWindowLongPtrW(hwnd, GWL_EXSTYLE, (LONG_PTR) xstyle);
|
|
|
|
}
|