Migrated uiButton.
This commit is contained in:
parent
c0cd20683a
commit
1790de24c8
|
@ -6,8 +6,11 @@ struct button {
|
||||||
HWND hwnd;
|
HWND hwnd;
|
||||||
void (*onClicked)(uiButton *, void *);
|
void (*onClicked)(uiButton *, void *);
|
||||||
void *onClickedData;
|
void *onClickedData;
|
||||||
|
void (*baseCommitDestroy)(uiControl *);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
uiDefineControlType(uiButton, uiTypeButton, struct button)
|
||||||
|
|
||||||
static BOOL onWM_COMMAND(uiControl *c, HWND hwnd, WORD code, LRESULT *lResult)
|
static BOOL onWM_COMMAND(uiControl *c, HWND hwnd, WORD code, LRESULT *lResult)
|
||||||
{
|
{
|
||||||
struct button *b = (struct button *) c;
|
struct button *b = (struct button *) c;
|
||||||
|
@ -19,12 +22,12 @@ static BOOL onWM_COMMAND(uiControl *c, HWND hwnd, WORD code, LRESULT *lResult)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void onDestroy(void *data)
|
static void buttonCommitDestroy(uiControl *c)
|
||||||
{
|
{
|
||||||
struct button *b = (struct button *) data;
|
struct button *b = (struct button *) c;
|
||||||
|
|
||||||
uiWindowsUnregisterWM_COMMANDHandler(b->hwnd);
|
uiWindowsUnregisterWM_COMMANDHandler(b->hwnd);
|
||||||
uiFree(b);
|
(*(b->baseCommitDestroy))(uiControl(b));
|
||||||
}
|
}
|
||||||
|
|
||||||
// from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
|
// from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
|
||||||
|
@ -77,31 +80,25 @@ static void buttonOnClicked(uiButton *bb, void (*f)(uiButton *, void *), void *d
|
||||||
uiButton *uiNewButton(const char *text)
|
uiButton *uiNewButton(const char *text)
|
||||||
{
|
{
|
||||||
struct button *b;
|
struct button *b;
|
||||||
uiWindowsMakeControlParams p;
|
|
||||||
WCHAR *wtext;
|
WCHAR *wtext;
|
||||||
|
|
||||||
b = uiNew(struct button);
|
b = (struct button *) uiWindowsNewControl(uiTypeButton());
|
||||||
uiTyped(b)->Type = uiTypeButton();
|
|
||||||
|
|
||||||
p.dwExStyle = 0;
|
|
||||||
p.lpClassName = L"button";
|
|
||||||
wtext = toUTF16(text);
|
wtext = toUTF16(text);
|
||||||
p.lpWindowName = wtext;
|
b->hwnd = uiWindowsUtilCreateControlHWND(0,
|
||||||
p.dwStyle = BS_PUSHBUTTON | WS_TABSTOP;
|
L"button", wtext,
|
||||||
p.hInstance = hInstance;
|
BS_PUSHBUTTON | WS_TABSTOP,
|
||||||
p.lpParam = NULL;
|
hInstance, NULL,
|
||||||
p.useStandardControlFont = TRUE;
|
TRUE);
|
||||||
p.onDestroy = onDestroy;
|
|
||||||
p.onDestroyData = b;
|
|
||||||
uiWindowsMakeControl(uiControl(b), &p);
|
|
||||||
uiFree(wtext);
|
uiFree(wtext);
|
||||||
|
|
||||||
b->hwnd = (HWND) uiControlHandle(uiControl(b));
|
|
||||||
uiWindowsRegisterWM_COMMANDHandler(b->hwnd, onWM_COMMAND, uiControl(b));
|
uiWindowsRegisterWM_COMMANDHandler(b->hwnd, onWM_COMMAND, uiControl(b));
|
||||||
|
|
||||||
b->onClicked = defaultOnClicked;
|
b->onClicked = defaultOnClicked;
|
||||||
|
|
||||||
uiControl(b)->PreferredSize = buttonPreferredSize;
|
uiControl(b)->PreferredSize = buttonPreferredSize;
|
||||||
|
b->baseCommitDestroy = uiControl(b)->CommitDestroy;
|
||||||
|
uiControl(b)->CommitDestroy = buttonCommitDestroy;
|
||||||
|
|
||||||
uiButton(b)->Text = buttonText;
|
uiButton(b)->Text = buttonText;
|
||||||
uiButton(b)->SetText = buttonSetText;
|
uiButton(b)->SetText = buttonSetText;
|
||||||
|
|
Loading…
Reference in New Issue