2015-04-11 21:22:19 -05:00
|
|
|
// 11 april 2015
|
|
|
|
#include "uipriv_windows.h"
|
|
|
|
|
|
|
|
struct label {
|
2015-04-16 08:20:00 -05:00
|
|
|
uiLabel l;
|
2015-04-11 21:22:19 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
static BOOL onWM_COMMAND(uiControl *c, WORD code, LRESULT *lResult)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL onWM_NOTIFY(uiControl *c, NMHDR *nm, LRESULT *lResult)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void onWM_DESTROY(uiControl *c)
|
|
|
|
{
|
2015-04-16 08:20:00 -05:00
|
|
|
struct label *l = (struct label *) c;
|
2015-04-11 21:22:19 -05:00
|
|
|
|
|
|
|
uiFree(l);
|
|
|
|
}
|
|
|
|
|
|
|
|
// via http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
|
|
|
|
#define labelHeight 8
|
|
|
|
|
|
|
|
static void preferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height)
|
|
|
|
{
|
2015-04-12 22:14:56 -05:00
|
|
|
*width = uiWindowsWindowTextWidth(uiControlHWND(c));
|
2015-04-11 21:22:19 -05:00
|
|
|
*height = uiDlgUnitsToY(labelHeight, d->sys->baseY);
|
|
|
|
}
|
|
|
|
|
2015-04-16 08:20:00 -05:00
|
|
|
static char *getText(uiLabel *l)
|
|
|
|
{
|
|
|
|
return uiWindowsControlText(uiControl(l));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setText(uiLabel *l, const char *text)
|
|
|
|
{
|
|
|
|
uiWindowsControlSetText(uiControl(l), text);
|
|
|
|
}
|
|
|
|
|
2015-04-11 21:22:19 -05:00
|
|
|
uiControl *uiNewLabel(const char *text)
|
|
|
|
{
|
|
|
|
struct label *l;
|
|
|
|
uiWindowsNewControlParams p;
|
|
|
|
WCHAR *wtext;
|
|
|
|
|
2015-04-16 08:20:00 -05:00
|
|
|
l = uiNew(struct label);
|
|
|
|
|
2015-04-11 21:22:19 -05:00
|
|
|
p.dwExStyle = 0;
|
|
|
|
p.lpClassName = L"static";
|
|
|
|
wtext = toUTF16(text);
|
|
|
|
p.lpWindowName = wtext;
|
|
|
|
// SS_LEFTNOWORDWRAP clips text past the end; SS_NOPREFIX avoids accelerator translation
|
|
|
|
// controls are vertically aligned to the top by default (thanks Xeek in irc.freenode.net/#winapi)
|
|
|
|
p.dwStyle = SS_LEFTNOWORDWRAP | SS_NOPREFIX;
|
|
|
|
p.hInstance = hInstance;
|
|
|
|
p.useStandardControlFont = TRUE;
|
|
|
|
p.onWM_COMMAND = onWM_COMMAND;
|
|
|
|
p.onWM_NOTIFY = onWM_NOTIFY;
|
|
|
|
p.onWM_DESTROY = onWM_DESTROY;
|
2015-04-16 08:20:00 -05:00
|
|
|
uiWindowsNewControl(uiControl(l), &p);
|
2015-04-11 21:22:19 -05:00
|
|
|
uiFree(wtext);
|
|
|
|
|
2015-04-16 08:20:00 -05:00
|
|
|
uiControl(l)->PreferredSize = preferredSize;
|
2015-04-11 21:22:19 -05:00
|
|
|
|
2015-04-16 08:20:00 -05:00
|
|
|
uiLabel(l)->Text = getText;
|
|
|
|
uiLabel(l)->SetText = setText;
|
2015-04-11 21:22:19 -05:00
|
|
|
|
2015-04-16 08:20:00 -05:00
|
|
|
return uiLabel(l);
|
2015-04-11 21:22:19 -05:00
|
|
|
}
|