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