More Windows conversion. Not done yet.
This commit is contained in:
parent
5c06fc512b
commit
cba301abbc
|
@ -2,30 +2,29 @@
|
|||
#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)
|
||||
static BOOL onWM_COMMAND(uiControl *c, WPARAM wParam, LPARAM lParam, LRESULT *lResult)
|
||||
{
|
||||
struct button *b = (struct button *) (c->data);
|
||||
|
||||
if (HIWORD(wParam) != BN_CLICKED)
|
||||
return FALSE;
|
||||
(*(B(data)->onClicked))(c, B(data)->onClickedData);
|
||||
(*(b->onClicked))(c, b->onClickedData);
|
||||
*lResult = 0;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL onWM_NOTIFY(uiControl *c, WPARAM wParam, LPARAM lParam, void *data, LRESULT *lResult)
|
||||
static BOOL onWM_NOTIFY(uiControl *c, WPARAM wParam, LPARAM lParam, LRESULT *lResult)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void onWM_DESTROY(uiControl *c, void *data)
|
||||
static void onWM_DESTROY(uiControl *c)
|
||||
{
|
||||
struct button *b = (struct button *) data;
|
||||
struct button *b = (struct button *) (c->data);
|
||||
|
||||
uiFree(b);
|
||||
}
|
||||
|
@ -33,7 +32,7 @@ static void onWM_DESTROY(uiControl *c, void *data)
|
|||
// from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
|
||||
#define buttonHeight 14
|
||||
|
||||
static void preferredSize(uiControl *c, int baseX, int baseY, LONG internalLeading, intmax_t *width, intmax_t *height)
|
||||
static void preferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height)
|
||||
{
|
||||
HWND hwnd;
|
||||
SIZE size;
|
||||
|
@ -53,7 +52,7 @@ static void preferredSize(uiControl *c, int baseX, int baseY, LONG internalLeadi
|
|||
// Microsoft says to use a fixed width for all buttons; this isn't good enough
|
||||
// use the text width instead, with some edge padding
|
||||
*width = uiWindowsWindowTextWidth(hwnd) + (2 * GetSystemMetrics(SM_CXEDGE));
|
||||
*height = uiDlgUnitToY(buttonHeight, baseY);
|
||||
*height = uiDlgUnitToY(buttonHeight, d->sys->baseY);
|
||||
}
|
||||
|
||||
static void defaultOnClicked(uiControl *c, void *data)
|
||||
|
@ -63,13 +62,12 @@ static void defaultOnClicked(uiControl *c, void *data)
|
|||
|
||||
uiControl *uiNewButton(const char *text)
|
||||
{
|
||||
uiControl *c;
|
||||
struct button *b;
|
||||
uiWindowsNewControlParams p;
|
||||
WCHAR *wtext;
|
||||
HWND hwnd;
|
||||
|
||||
b = uiNew(struct button);
|
||||
|
||||
p.dwExStyle = 0;
|
||||
p.lpClassName = L"button";
|
||||
wtext = toUTF16(text);
|
||||
|
@ -79,18 +77,19 @@ uiControl *uiNewButton(const char *text)
|
|||
p.onWM_COMMAND = onWM_COMMAND;
|
||||
p.onWM_NOTIFY = onWM_NOTIFY;
|
||||
p.onWM_DESTROY = onWM_DESTROY;
|
||||
p.onCommandNotifyDestroyData = b;
|
||||
p.preferredSize = preferredSize;
|
||||
p.data = b;
|
||||
b->c = uiWindowsNewControl(&p);
|
||||
c = uiWindowsNewControl(&p);
|
||||
uiFree(wtext);
|
||||
|
||||
hwnd = (HWND) uiControlHandle(b->c);
|
||||
c->preferredSize = preferredSize;
|
||||
|
||||
hwnd = (HWND) uiControlHandle(c);
|
||||
SendMessageW(hwnd, WM_SETFONT, (WPARAM) hMessageFont, (LPARAM) TRUE);
|
||||
|
||||
b = uiNew(struct button);
|
||||
b->onClicked = defaultOnClicked;
|
||||
c->data = b;
|
||||
|
||||
return b->c;
|
||||
return c;
|
||||
}
|
||||
|
||||
char *uiButtonText(uiControl *c)
|
||||
|
@ -105,9 +104,8 @@ void uiButtonSetText(uiControl *c, const char *text)
|
|||
|
||||
void uiButtonOnClicked(uiControl *c, void (*f)(uiControl *, void *), void *data)
|
||||
{
|
||||
struct button *b;
|
||||
struct button *b = (struct button *) (c->data);
|
||||
|
||||
b = (struct button *) uiWindowsControlData(c);
|
||||
b->onClicked = f;
|
||||
b->onClickedData = data;
|
||||
}
|
||||
|
|
|
@ -2,15 +2,13 @@
|
|||
#include "uipriv_windows.h"
|
||||
|
||||
struct checkbox {
|
||||
uiControl *c;
|
||||
void (*onToggled)(uiControl *, void *);
|
||||
void *onToggledData;
|
||||
};
|
||||
|
||||
#define C(x) ((struct checkbox *) (x))
|
||||
|
||||
static BOOL onWM_COMMAND(uiControl *c, WPARAM wParam, LPARAM lParam, void *data, LRESULT *lResult)
|
||||
static BOOL onWM_COMMAND(uiControl *c, WPARAM wParam, LPARAM lParam, LRESULT *lResult)
|
||||
{
|
||||
struct checkbox *cc = (struct checkbox *) (c->data);
|
||||
HWND hwnd;
|
||||
WPARAM check;
|
||||
|
||||
|
@ -24,19 +22,19 @@ static BOOL onWM_COMMAND(uiControl *c, WPARAM wParam, LPARAM lParam, void *data,
|
|||
check = BST_UNCHECKED;
|
||||
SendMessage(hwnd, BM_SETCHECK, check, 0);
|
||||
|
||||
(*(C(data)->onToggled))(c, C(data)->onToggledData);
|
||||
(*(cc->onToggled))(c, cc->onToggledData);
|
||||
*lResult = 0;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL onWM_NOTIFY(uiControl *c, WPARAM wParam, LPARAM lParam, void *data, LRESULT *lResult)
|
||||
static BOOL onWM_NOTIFY(uiControl *c, WPARAM wParam, LPARAM lParam, LRESULT *lResult)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void onWM_DESTROY(uiControl *c, void *data)
|
||||
static void onWM_DESTROY(uiControl *c)
|
||||
{
|
||||
struct checkbox *cc = (struct checkbox *) data;
|
||||
struct checkbox *cc = (struct checkbox *) (c->data);
|
||||
|
||||
uiFree(cc);
|
||||
}
|
||||
|
@ -46,10 +44,10 @@ static void onWM_DESTROY(uiControl *c, void *data)
|
|||
// from http://msdn.microsoft.com/en-us/library/windows/desktop/bb226818%28v=vs.85%29.aspx
|
||||
#define checkboxXFromLeftOfBoxToLeftOfLabel 12
|
||||
|
||||
static void preferredSize(uiControl *c, int baseX, int baseY, LONG internalLeading, intmax_t *width, intmax_t *height)
|
||||
static void preferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height)
|
||||
{
|
||||
*width = uiDlgUnitToX(checkboxXFromLeftOfBoxToLeftOfLabel, baseX) + uiWindowsWindowTextWidth((HWND) uiControlHandle(c));
|
||||
*height = uiDlgUnitToY(checkboxHeight, baseY);
|
||||
*width = uiDlgUnitToX(checkboxXFromLeftOfBoxToLeftOfLabel, d->sys->baseX) + uiWindowsWindowTextWidth((HWND) uiControlHandle(c));
|
||||
*height = uiDlgUnitToY(checkboxHeight, d->sys->baseY);
|
||||
}
|
||||
|
||||
static void defaultOnToggled(uiControl *c, void *data)
|
||||
|
@ -59,13 +57,12 @@ static void defaultOnToggled(uiControl *c, void *data)
|
|||
|
||||
uiControl *uiNewCheckbox(const char *text)
|
||||
{
|
||||
struct checkbox *c;
|
||||
uiControl *c;
|
||||
struct checkbox *cc;
|
||||
uiWindowsNewControlParams p;
|
||||
WCHAR *wtext;
|
||||
HWND hwnd;
|
||||
|
||||
c = uiNew(struct checkbox);
|
||||
|
||||
p.dwExStyle = 0;
|
||||
p.lpClassName = L"button";
|
||||
wtext = toUTF16(text);
|
||||
|
@ -75,18 +72,19 @@ uiControl *uiNewCheckbox(const char *text)
|
|||
p.onWM_COMMAND = onWM_COMMAND;
|
||||
p.onWM_NOTIFY = onWM_NOTIFY;
|
||||
p.onWM_DESTROY = onWM_DESTROY;
|
||||
p.onCommandNotifyDestroyData = c;
|
||||
p.preferredSize = preferredSize;
|
||||
p.data = c;
|
||||
c->c = uiWindowsNewControl(&p);
|
||||
c = uiWindowsNewControl(&p);
|
||||
uiFree(wtext);
|
||||
|
||||
hwnd = (HWND) uiControlHandle(c->c);
|
||||
c->preferredSize = preferredSize;
|
||||
|
||||
hwnd = (HWND) uiControlHandle(c);
|
||||
SendMessageW(hwnd, WM_SETFONT, (WPARAM) hMessageFont, (LPARAM) TRUE);
|
||||
|
||||
c->onToggled = defaultOnToggled;
|
||||
cc = uiNew(struct checkbox);
|
||||
cc->onToggled = defaultOnToggled;
|
||||
c->data = cc;
|
||||
|
||||
return c->c;
|
||||
return c;
|
||||
}
|
||||
|
||||
char *uiCheckboxText(uiControl *c)
|
||||
|
@ -101,9 +99,8 @@ void uiCheckboxSetText(uiControl *c, const char *text)
|
|||
|
||||
void uiCheckboxOnToggled(uiControl *c, void (*f)(uiControl *, void *), void *data)
|
||||
{
|
||||
struct checkbox *cc;
|
||||
struct checkbox *cc = (struct checkbox *) (c->data);
|
||||
|
||||
cc = (struct checkbox *) uiWindowsControlData(c);
|
||||
cc->onToggled = f;
|
||||
cc->onToggledData = data;
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@ BOOL sharedWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *
|
|||
void resize(uiControl *control, HWND parent, RECT r, RECT margin)
|
||||
{
|
||||
uiSizing d;
|
||||
uiSizingSys sys;
|
||||
HDC dc;
|
||||
HFONT prevfont;
|
||||
TEXTMETRICW tm;
|
||||
|
@ -80,9 +81,9 @@ void resize(uiControl *control, HWND parent, RECT r, RECT margin)
|
|||
logLastError("error getting text metrics in resize()");
|
||||
if (GetTextExtentPoint32W(dc, L"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 52, &size) == 0)
|
||||
logLastError("error getting text extent point in resize()");
|
||||
d.baseX = (int) ((size.cx / 26 + 1) / 2);
|
||||
d.baseY = (int) tm.tmHeight;
|
||||
d.internalLeading = tm.tmInternalLeading;
|
||||
sys.baseX = (int) ((size.cx / 26 + 1) / 2);
|
||||
sys.baseY = (int) tm.tmHeight;
|
||||
sys.internalLeading = tm.tmInternalLeading;
|
||||
if (SelectObject(dc, prevfont) != hMessageFont)
|
||||
logLastError("error restoring previous font into device context in resize()");
|
||||
if (ReleaseDC(parent, dc) == 0)
|
||||
|
@ -93,7 +94,8 @@ void resize(uiControl *control, HWND parent, RECT r, RECT margin)
|
|||
r.bottom -= uiDlgUnitToY(margin.bottom, d.baseY);
|
||||
d.xPadding = uiDlgUnitToX(winXPadding, d.baseX);
|
||||
d.yPadding = uiDlgUnitToY(winYPadding, d.baseY);
|
||||
(*(control->resize))(control, r.left, r.top, r.right - r.left, r.bottom - r.top, &d);
|
||||
d.sys = &sys;
|
||||
uiControlResize(control, r.left, r.top, r.right - r.left, r.bottom - r.top, &d);
|
||||
}
|
||||
|
||||
void updateParent(uintptr_t h)
|
||||
|
|
|
@ -2,11 +2,8 @@
|
|||
#include "uipriv_windows.h"
|
||||
|
||||
struct entry {
|
||||
uiControl *c;
|
||||
};
|
||||
|
||||
#define E(x) ((struct entry *) (x))
|
||||
|
||||
static BOOL onWM_COMMAND(uiControl *c, WPARAM wParam, LPARAM lParam, void *data, LRESULT *lResult)
|
||||
{
|
||||
return FALSE;
|
||||
|
@ -17,9 +14,9 @@ static BOOL onWM_NOTIFY(uiControl *c, WPARAM wParam, LPARAM lParam, void *data,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
static void onWM_DESTROY(uiControl *c, void *data)
|
||||
static void onWM_DESTROY(uiControl *c)
|
||||
{
|
||||
struct entry *e = (struct entry *) data;
|
||||
struct entry *e = (struct entry *) (c->data);
|
||||
|
||||
uiFree(e);
|
||||
}
|
||||
|
@ -28,20 +25,19 @@ static void onWM_DESTROY(uiControl *c, void *data)
|
|||
#define entryWidth 107 /* this is actually the shorter progress bar width, but Microsoft only indicates as wide as necessary */
|
||||
#define entryHeight 14
|
||||
|
||||
static void preferredSize(uiControl *c, int baseX, int baseY, LONG internalLeading, intmax_t *width, intmax_t *height)
|
||||
static void preferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height)
|
||||
{
|
||||
*width = uiDlgUnitToX(entryWidth, baseX);
|
||||
*height = uiDlgUnitToY(entryHeight, baseY);
|
||||
*width = uiDlgUnitToX(entryWidth, d->sys->baseX);
|
||||
*height = uiDlgUnitToY(entryHeight, d->sys->baseY);
|
||||
}
|
||||
|
||||
uiControl *uiNewEntry(void)
|
||||
{
|
||||
uiControl *c;
|
||||
struct entry *e;
|
||||
uiWindowsNewControlParams p;
|
||||
HWND hwnd;
|
||||
|
||||
e = uiNew(struct entry);
|
||||
|
||||
p.dwExStyle = WS_EX_CLIENTEDGE;
|
||||
p.lpClassName = L"edit";
|
||||
p.lpWindowName = L"";
|
||||
|
@ -51,15 +47,17 @@ uiControl *uiNewEntry(void)
|
|||
p.onWM_COMMAND = onWM_COMMAND;
|
||||
p.onWM_NOTIFY = onWM_NOTIFY;
|
||||
p.onWM_DESTROY = onWM_DESTROY;
|
||||
p.onCommandNotifyDestroyData = e;
|
||||
p.preferredSize = preferredSize;
|
||||
p.data = e;
|
||||
e->c = uiWindowsNewControl(&p);
|
||||
c = uiWindowsNewControl(&p);
|
||||
|
||||
hwnd = (HWND) uiControlHandle(e->c);
|
||||
c->preferredSize = preferredSize;
|
||||
|
||||
hwnd = (HWND) uiControlHandle(c);
|
||||
SendMessageW(hwnd, WM_SETFONT, (WPARAM) hMessageFont, (LPARAM) TRUE);
|
||||
|
||||
return e->c;
|
||||
e = uiNew(struct entry);
|
||||
c->data = e;
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
char *uiEntryText(uiControl *c)
|
||||
|
|
Loading…
Reference in New Issue