2014-08-14 09:42:10 -05:00
|
|
|
// 17 july 2014
|
2014-07-17 21:16:32 -05:00
|
|
|
|
|
|
|
#include "winapi_windows.h"
|
2014-07-17 23:29:15 -05:00
|
|
|
#include "_cgo_export.h"
|
2014-07-17 21:16:32 -05:00
|
|
|
|
|
|
|
static LRESULT CALLBACK buttonSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR id, DWORD_PTR data)
|
|
|
|
{
|
|
|
|
switch (uMsg) {
|
|
|
|
case msgCOMMAND:
|
|
|
|
if (HIWORD(wParam) == BN_CLICKED) {
|
2014-07-17 23:29:15 -05:00
|
|
|
buttonClicked((void *) data);
|
2014-07-17 21:16:32 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return (*fv_DefSubclassProc)(hwnd, uMsg, wParam, lParam);
|
|
|
|
case WM_NCDESTROY:
|
|
|
|
if ((*fv_RemoveWindowSubclass)(hwnd, buttonSubProc, id) == FALSE)
|
|
|
|
xpanic("error removing Button 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("Button", "buttonSubProc()", uMsg);
|
2014-08-14 09:42:10 -05:00
|
|
|
return 0; // unreached
|
2014-07-17 21:16:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void setButtonSubclass(HWND hwnd, void *data)
|
|
|
|
{
|
|
|
|
if ((*fv_SetWindowSubclass)(hwnd, buttonSubProc, 0, (DWORD_PTR) data) == FALSE)
|
|
|
|
xpanic("error subclassing Button to give it its own event handler", GetLastError());
|
|
|
|
}
|
2014-07-21 20:34:52 -05:00
|
|
|
|
|
|
|
static LRESULT CALLBACK checkboxSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR id, DWORD_PTR data)
|
|
|
|
{
|
|
|
|
switch (uMsg) {
|
|
|
|
case msgCOMMAND:
|
|
|
|
if (HIWORD(wParam) == BN_CLICKED) {
|
|
|
|
WPARAM check;
|
|
|
|
|
2014-08-14 09:42:10 -05:00
|
|
|
// we didn't use BS_AUTOCHECKBOX (see controls_windows.go) so we have to manage the check state ourselves
|
2014-07-21 20:34:52 -05:00
|
|
|
check = BST_CHECKED;
|
|
|
|
if (SendMessage(hwnd, BM_GETCHECK, 0, 0) == BST_CHECKED)
|
|
|
|
check = BST_UNCHECKED;
|
|
|
|
SendMessage(hwnd, BM_SETCHECK, check, 0);
|
|
|
|
checkboxToggled((void *) data);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return (*fv_DefSubclassProc)(hwnd, uMsg, wParam, lParam);
|
|
|
|
case WM_NCDESTROY:
|
2014-07-21 20:37:06 -05:00
|
|
|
if ((*fv_RemoveWindowSubclass)(hwnd, checkboxSubProc, id) == FALSE)
|
2014-07-21 20:34:52 -05:00
|
|
|
xpanic("error removing Checkbox 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("Checkbox", "checkboxSubProc()", uMsg);
|
2014-08-14 09:42:10 -05:00
|
|
|
return 0; // unreached
|
2014-07-21 20:34:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void setCheckboxSubclass(HWND hwnd, void *data)
|
|
|
|
{
|
|
|
|
if ((*fv_SetWindowSubclass)(hwnd, checkboxSubProc, 0, (DWORD_PTR) data) == FALSE)
|
|
|
|
xpanic("error subclassing Checkbox to give it its own event handler", GetLastError());
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL checkboxChecked(HWND hwnd)
|
|
|
|
{
|
|
|
|
if (SendMessage(hwnd, BM_GETCHECK, 0, 0) == BST_UNCHECKED)
|
|
|
|
return FALSE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void checkboxSetChecked(HWND hwnd, BOOL c)
|
|
|
|
{
|
|
|
|
WPARAM check;
|
|
|
|
|
|
|
|
check = BST_CHECKED;
|
|
|
|
if (c == FALSE)
|
|
|
|
check = BST_UNCHECKED;
|
|
|
|
SendMessage(hwnd, BM_SETCHECK, check, 0);
|
|
|
|
}
|
2014-08-20 11:04:36 -05:00
|
|
|
|
|
|
|
static LRESULT CALLBACK textfieldSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR id, DWORD_PTR data)
|
|
|
|
{
|
|
|
|
switch (uMsg) {
|
|
|
|
case msgCOMMAND:
|
|
|
|
if (HIWORD(wParam) == EN_CHANGE) {
|
|
|
|
textfieldChanged((void *) data);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return (*fv_DefSubclassProc)(hwnd, uMsg, wParam, lParam);
|
|
|
|
case WM_NCDESTROY:
|
|
|
|
if ((*fv_RemoveWindowSubclass)(hwnd, textfieldSubProc, id) == FALSE)
|
|
|
|
xpanic("error removing TextField 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("TextField", "textfieldSubProc()", uMsg);
|
|
|
|
return 0; // unreached
|
|
|
|
}
|
|
|
|
|
|
|
|
void setTextFieldSubclass(HWND hwnd, void *data)
|
|
|
|
{
|
|
|
|
if ((*fv_SetWindowSubclass)(hwnd, textfieldSubProc, 0, (DWORD_PTR) data) == FALSE)
|
|
|
|
xpanic("error subclassing TextField to give it its own event handler", GetLastError());
|
|
|
|
}
|
2014-08-20 13:17:00 -05:00
|
|
|
|
|
|
|
void textfieldSetAndShowInvalidBalloonTip(HWND hwnd, WCHAR *text)
|
|
|
|
{
|
|
|
|
EDITBALLOONTIP ti;
|
|
|
|
|
|
|
|
ZeroMemory(&ti, sizeof (EDITBALLOONTIP));
|
|
|
|
ti.cbStruct = sizeof (EDITBALLOONTIP);
|
2014-08-30 13:33:55 -05:00
|
|
|
// this is required to show the error icon
|
|
|
|
// this probably should be localized...
|
|
|
|
ti.pszTitle = L"Invalid Input";
|
2014-08-20 13:17:00 -05:00
|
|
|
ti.pszText = text;
|
|
|
|
ti.ttiIcon = TTI_ERROR;
|
|
|
|
if (SendMessageW(hwnd, EM_SHOWBALLOONTIP, 0, (LPARAM) (&ti)) == FALSE)
|
|
|
|
xpanic("error showing TextField.Invalid() balloon tip", GetLastError());
|
2014-08-25 00:44:14 -05:00
|
|
|
if (MessageBeep(0xFFFFFFFF) == 0)
|
|
|
|
xpanic("error beeping in response to TextField.Invalid()", GetLastError());
|
2014-08-20 13:17:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void textfieldHideInvalidBalloonTip(HWND hwnd)
|
|
|
|
{
|
|
|
|
if (SendMessageW(hwnd, EM_HIDEBALLOONTIP, 0, 0) == FALSE)
|
|
|
|
xpanic("error hiding TextField.Invalid() balloon tip", GetLastError());
|
|
|
|
}
|
2014-10-27 09:41:10 -05:00
|
|
|
|
2014-11-05 11:59:44 -06:00
|
|
|
// also good for Textbox
|
|
|
|
int textfieldReadOnly(HWND hwnd)
|
|
|
|
{
|
|
|
|
return (GetWindowLongPtrW(hwnd, GWL_STYLE) & ES_READONLY) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// also good for Textbox
|
|
|
|
void textfieldSetReadOnly(HWND hwnd, BOOL readonly)
|
|
|
|
{
|
|
|
|
if (SendMessageW(hwnd, EM_SETREADONLY, (WPARAM) readonly, 0) == 0)
|
|
|
|
xpanic("error setting TextField/Textbox as read-only/not read-only", GetLastError());
|
|
|
|
}
|
|
|
|
|
2014-10-27 09:41:10 -05:00
|
|
|
static LRESULT CALLBACK groupSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR id, DWORD_PTR data)
|
|
|
|
{
|
|
|
|
LRESULT lResult;
|
|
|
|
RECT r;
|
|
|
|
|
|
|
|
if (sharedWndProc(hwnd, uMsg, wParam, lParam, &lResult))
|
|
|
|
return lResult;
|
|
|
|
switch (uMsg) {
|
2014-10-30 07:48:36 -05:00
|
|
|
// don't do this on WM_WINDOWPOSCHANGING; weird redraw issues will happen
|
2014-10-27 09:41:10 -05:00
|
|
|
case WM_WINDOWPOSCHANGED:
|
|
|
|
// don't use the WINDOWPOS rect here; the coordinates of the controls have to be in real client coordinates
|
|
|
|
if (GetClientRect(hwnd, &r) == 0)
|
|
|
|
xpanic("error getting client rect of Group for resizing its child Control", GetLastError());
|
|
|
|
groupResized((void *) data, r);
|
|
|
|
// and chain up
|
|
|
|
return (*fv_DefSubclassProc)(hwnd, uMsg, wParam, lParam);
|
|
|
|
case WM_NCDESTROY:
|
|
|
|
if ((*fv_RemoveWindowSubclass)(hwnd, groupSubProc, id) == FALSE)
|
|
|
|
xpanic("error removing Group 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("Group", "groupSubProc()", uMsg);
|
|
|
|
return 0; // unreached
|
|
|
|
}
|
|
|
|
|
|
|
|
void setGroupSubclass(HWND hwnd, void *data)
|
|
|
|
{
|
|
|
|
if ((*fv_SetWindowSubclass)(hwnd, groupSubProc, 0, (DWORD_PTR) data) == FALSE)
|
|
|
|
xpanic("error subclassing Group to give it its own event handler", GetLastError());
|
|
|
|
}
|
2014-10-28 14:46:13 -05:00
|
|
|
|
2014-11-01 07:35:21 -05:00
|
|
|
static LRESULT CALLBACK updownSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR id, DWORD_PTR data)
|
|
|
|
{
|
|
|
|
NMHDR *nmhdr = (NMHDR *) lParam;
|
|
|
|
|
|
|
|
switch (uMsg) {
|
|
|
|
case msgNOTIFY:
|
|
|
|
switch (nmhdr->code) {
|
|
|
|
case UDN_DELTAPOS:
|
|
|
|
spinboxUpDownClicked((void *) data, (NMUPDOWN *) lParam);
|
|
|
|
return FALSE; // allow change
|
|
|
|
}
|
|
|
|
return (*fv_DefSubclassProc)(hwnd, uMsg, wParam, lParam);
|
|
|
|
case WM_NCDESTROY:
|
|
|
|
if ((*fv_RemoveWindowSubclass)(hwnd, updownSubProc, id) == FALSE)
|
|
|
|
xpanic("error removing Spinbox up-down control 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("Spinbox up-down control", "updownSubProc()", uMsg);
|
|
|
|
return 0; // unreached
|
|
|
|
}
|
|
|
|
|
|
|
|
HWND newUpDown(HWND prevUpDown, void *data)
|
2014-10-30 09:42:59 -05:00
|
|
|
{
|
|
|
|
HWND hwnd;
|
|
|
|
HWND parent;
|
|
|
|
|
|
|
|
parent = msgwin; // for the first up-down
|
|
|
|
if (prevUpDown != NULL) {
|
|
|
|
parent = GetParent(prevUpDown);
|
|
|
|
if (parent == NULL)
|
|
|
|
xpanic("error getting parent of old up-down in Spinbox resize for new up-down", GetLastError());
|
|
|
|
if (DestroyWindow(prevUpDown) == 0)
|
|
|
|
xpanic("error destroying previous up-down in Spinbox resize", GetLastError());
|
|
|
|
}
|
|
|
|
hwnd = CreateWindowExW(0,
|
|
|
|
UPDOWN_CLASSW, L"",
|
|
|
|
// no WS_VISIBLE; we set visibility ourselves
|
|
|
|
WS_CHILD | UDS_ALIGNRIGHT | UDS_ARROWKEYS | UDS_HOTTRACK | UDS_NOTHOUSANDS | UDS_SETBUDDYINT,
|
|
|
|
// this is important; it's necessary for autosizing to work
|
|
|
|
0, 0, 0, 0,
|
|
|
|
parent, NULL, hInstance, NULL);
|
|
|
|
if (hwnd == NULL)
|
|
|
|
xpanic("error creating up-down control for Spinbox", GetLastError());
|
2014-11-01 07:35:21 -05:00
|
|
|
if ((*fv_SetWindowSubclass)(hwnd, updownSubProc, 0, (DWORD_PTR) data) == FALSE)
|
|
|
|
xpanic("error subclassing Spinbox up-down control to give it its own event handler", GetLastError());
|
2014-10-30 09:42:59 -05:00
|
|
|
return hwnd;
|
|
|
|
}
|
2014-11-02 19:49:39 -06:00
|
|
|
|
|
|
|
static LRESULT CALLBACK spinboxEditSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR id, DWORD_PTR data)
|
|
|
|
{
|
|
|
|
switch (uMsg) {
|
|
|
|
case msgCOMMAND:
|
|
|
|
if (HIWORD(wParam) == EN_CHANGE) {
|
|
|
|
spinboxEditChanged((void *) data);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return (*fv_DefSubclassProc)(hwnd, uMsg, wParam, lParam);
|
|
|
|
case WM_NCDESTROY:
|
|
|
|
if ((*fv_RemoveWindowSubclass)(hwnd, spinboxEditSubProc, id) == FALSE)
|
|
|
|
xpanic("error removing Spinbox edit control 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("Spinbox edit control", "spinboxEditSubProc()", uMsg);
|
|
|
|
return 0; // unreached
|
|
|
|
}
|
|
|
|
|
|
|
|
void setSpinboxEditSubclass(HWND hwnd, void *data)
|
|
|
|
{
|
|
|
|
if ((*fv_SetWindowSubclass)(hwnd, spinboxEditSubProc, 0, (DWORD_PTR) data) == FALSE)
|
|
|
|
xpanic("error subclassing Spinbox edit control to give it its own event handler", GetLastError());
|
2014-11-04 08:18:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// provided for cgo's benefit
|
|
|
|
LPWSTR xPROGRESS_CLASS = PROGRESS_CLASS;
|