Wrote up the initial uiButton implementation. It (mostly; just needs text and for that I need to add a uiControlHandle()) works!
This commit is contained in:
parent
fecb7caa14
commit
5b36956ecb
|
@ -0,0 +1,73 @@
|
||||||
|
// 7 april 2015
|
||||||
|
#include "uipriv_windows.h"
|
||||||
|
|
||||||
|
struct button {
|
||||||
|
uiControl *c;
|
||||||
|
void (*onClicked)(uiControl *, void *);
|
||||||
|
void *onClickedData;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define B(x) ((struct button *) (x))
|
||||||
|
|
||||||
|
static BOOL onWM_COMMAND(uiControl *c, WPARAM wParam, LPARAM lParam, void *data, LRESULT *lResult)
|
||||||
|
{
|
||||||
|
if (HIWORD(wParam) != BN_CLICKED)
|
||||||
|
return FALSE;
|
||||||
|
(*(B(data)->onClicked))(c, B(data)->onClickedData);
|
||||||
|
*lResult = 0;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static BOOL onWM_NOTIFY(uiControl *c, WPARAM wParam, LPARAM lParam, void *data, LRESULT *lResult)
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void preferredSize(uiControl *c, int baseX, int baseY, LONG internalLeading, intmax_t *width, intmax_t *height)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
static void defaultOnClicked(uiControl *c, void *data)
|
||||||
|
{
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
uiControl *uiNewButton(const char *text)
|
||||||
|
{
|
||||||
|
struct button *b;
|
||||||
|
uiWindowsNewControlParams p;
|
||||||
|
WCHAR *wtext;
|
||||||
|
|
||||||
|
b = uiNew(struct button);
|
||||||
|
|
||||||
|
p.dwExStyle = 0;
|
||||||
|
p.lpClassName = L"button";
|
||||||
|
p.dwStyle = BS_PUSHBUTTON;
|
||||||
|
p.hInstance = hInstance;
|
||||||
|
p.onWM_COMMAND = onWM_COMMAND;
|
||||||
|
p.onWM_NOTIFY = onWM_NOTIFY;
|
||||||
|
p.onCommandNotifyData = b;
|
||||||
|
p.preferredSize = preferredSize;
|
||||||
|
p.data = b;
|
||||||
|
b->c = uiWindowsNewControl(&p);
|
||||||
|
|
||||||
|
wtext = toUTF16(text);
|
||||||
|
// TODO set text
|
||||||
|
uiFree(wtext);
|
||||||
|
|
||||||
|
b->onClicked = defaultOnClicked;
|
||||||
|
|
||||||
|
return b->c;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO text
|
||||||
|
|
||||||
|
void uiButtonOnClicked(uiControl *c, void (*f)(uiControl *, void *), void *data)
|
||||||
|
{
|
||||||
|
struct button *b;
|
||||||
|
|
||||||
|
b = (struct button *) uiWindowsControlData(c);
|
||||||
|
b->onClicked = f;
|
||||||
|
b->onClickedData = data;
|
||||||
|
}
|
|
@ -10,6 +10,7 @@ struct uiSingleHWNDControl {
|
||||||
BOOL (*onWM_NOTIFY)(uiControl *, WPARAM, LPARAM, void *, LRESULT *);
|
BOOL (*onWM_NOTIFY)(uiControl *, WPARAM, LPARAM, void *, LRESULT *);
|
||||||
void *onCommandNotifyData;
|
void *onCommandNotifyData;
|
||||||
void (*preferredSize)(uiControl *, int, int, LONG, intmax_t *, intmax_t *);
|
void (*preferredSize)(uiControl *, int, int, LONG, intmax_t *, intmax_t *);
|
||||||
|
void *data;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define S(c) ((uiSingleHWNDControl *) (c))
|
#define S(c) ((uiSingleHWNDControl *) (c))
|
||||||
|
@ -100,8 +101,15 @@ uiControl *uiWindowsNewControl(uiWindowsNewControlParams *p)
|
||||||
c->onCommandNotifyData = p->onCommandNotifyData;
|
c->onCommandNotifyData = p->onCommandNotifyData;
|
||||||
c->preferredSize = p->preferredSize;
|
c->preferredSize = p->preferredSize;
|
||||||
|
|
||||||
|
c->data = p->data;
|
||||||
|
|
||||||
if ((*fv_SetWindowSubclass)(c->hwnd, singleSubclassProc, 0, (DWORD_PTR) c) == FALSE)
|
if ((*fv_SetWindowSubclass)(c->hwnd, singleSubclassProc, 0, (DWORD_PTR) c) == FALSE)
|
||||||
logLastError("error subclassing Windows control in uiWindowsNewControl()");
|
logLastError("error subclassing Windows control in uiWindowsNewControl()");
|
||||||
|
|
||||||
return (uiControl *) c;
|
return (uiControl *) c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *uiWindowsControlData(uiControl *c)
|
||||||
|
{
|
||||||
|
return S(c)->data;
|
||||||
|
}
|
||||||
|
|
10
test.c
10
test.c
|
@ -9,10 +9,16 @@ int onClosing(uiWindow *w, void *data)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void onClicked(uiControl *b, void *data)
|
||||||
|
{
|
||||||
|
printf("button clicked!\n");
|
||||||
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
uiInitError *err;
|
uiInitError *err;
|
||||||
uiWindow *w;
|
uiWindow *w;
|
||||||
|
uiControl *button;
|
||||||
|
|
||||||
err = uiInit(NULL);
|
err = uiInit(NULL);
|
||||||
if (err != NULL) {
|
if (err != NULL) {
|
||||||
|
@ -25,6 +31,10 @@ int main(void)
|
||||||
uiWindowOnClosing(w, onClosing, NULL);
|
uiWindowOnClosing(w, onClosing, NULL);
|
||||||
uiWindowShow(w);
|
uiWindowShow(w);
|
||||||
|
|
||||||
|
button = uiNewButton("Click Me");
|
||||||
|
uiButtonOnClicked(button, onClicked, NULL);
|
||||||
|
uiWindowSetChild(w, button);
|
||||||
|
|
||||||
uiMain();
|
uiMain();
|
||||||
printf("after uiMain()\n");
|
printf("after uiMain()\n");
|
||||||
return 0;
|
return 0;
|
||||||
|
|
7
ui.h
7
ui.h
|
@ -15,6 +15,8 @@ void uiInitErrorFree(uiInitError *);
|
||||||
void uiMain(void);
|
void uiMain(void);
|
||||||
void uiQuit(void);
|
void uiQuit(void);
|
||||||
|
|
||||||
|
typedef struct uiControl uiControl;
|
||||||
|
|
||||||
typedef struct uiWindow uiWindow;
|
typedef struct uiWindow uiWindow;
|
||||||
uiWindow *uiNewWindow(char *, int, int);
|
uiWindow *uiNewWindow(char *, int, int);
|
||||||
void uiWindowDestroy(uiWindow *);
|
void uiWindowDestroy(uiWindow *);
|
||||||
|
@ -23,7 +25,10 @@ uintptr_t uiWindowHandle(uiWindow *);
|
||||||
void uiWindowShow(uiWindow *);
|
void uiWindowShow(uiWindow *);
|
||||||
void uiWindowHide(uiWindow *);
|
void uiWindowHide(uiWindow *);
|
||||||
void uiWindowOnClosing(uiWindow *, int (*)(uiWindow *, void *), void *);
|
void uiWindowOnClosing(uiWindow *, int (*)(uiWindow *, void *), void *);
|
||||||
|
void uiWindowSetChild(uiWindow *, uiControl *);
|
||||||
|
|
||||||
typedef struct uiControl uiControl;
|
uiControl *uiNewButton(const char *);
|
||||||
|
// TODO text
|
||||||
|
void uiButtonOnClicked(uiControl *, void (*)(uiControl *, void *), void *);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -30,8 +30,12 @@ struct uiWindowsNewControlParams {
|
||||||
// baseX and baseY are the base units used to convert between dialog units and pixels.
|
// baseX and baseY are the base units used to convert between dialog units and pixels.
|
||||||
// internalLeading is the internal leading of the control font.
|
// internalLeading is the internal leading of the control font.
|
||||||
void (*preferredSize)(uiControl *c, int baseX, int baseY, LONG internalLeading, intmax_t *width, intmax_t *height);
|
void (*preferredSize)(uiControl *c, int baseX, int baseY, LONG internalLeading, intmax_t *width, intmax_t *height);
|
||||||
|
|
||||||
|
// Data you can get with uiWindowsControlData()
|
||||||
|
void *data;
|
||||||
};
|
};
|
||||||
uiControl *uiWindowsNewControl(uiWindowsNewControlParams *);
|
uiControl *uiWindowsNewControl(uiWindowsNewControlParams *);
|
||||||
|
void *uiWindowsControlData(uiControl *);
|
||||||
|
|
||||||
// use these in your preferredSize() implementation with baseX and baseY
|
// use these in your preferredSize() implementation with baseX and baseY
|
||||||
#define uiDlgUnitToX(dlg, baseX) MulDiv((dlg), baseX, 4)
|
#define uiDlgUnitToX(dlg, baseX) MulDiv((dlg), baseX, 4)
|
||||||
|
|
|
@ -133,3 +133,9 @@ void uiWindowOnClosing(uiWindow *w, int (*f)(uiWindow *, void *), void *data)
|
||||||
w->onClosing = f;
|
w->onClosing = f;
|
||||||
w->onClosingData = data;
|
w->onClosingData = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void uiWindowSetChild(uiWindow *w, uiControl *c)
|
||||||
|
{
|
||||||
|
w->child = c;
|
||||||
|
(*(w->child->setParent))(w->child, (uintptr_t) (w->hwnd));
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue