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-17 10:13:42 -05:00
|
|
|
HWND hwnd;
|
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;
|
|
|
|
}
|
|
|
|
|
2015-04-18 17:02:16 -05:00
|
|
|
static void onDestroy(void *data)
|
2015-04-11 21:22:19 -05:00
|
|
|
{
|
2015-04-18 17:02:16 -05:00
|
|
|
struct label *l = (struct label *) data;
|
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
|
|
|
|
|
2015-05-04 13:56:26 -05:00
|
|
|
static void labelPreferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height)
|
2015-04-11 21:22:19 -05:00
|
|
|
{
|
2015-04-17 10:13:42 -05:00
|
|
|
struct label *l = (struct label *) c;
|
|
|
|
|
|
|
|
*width = uiWindowsWindowTextWidth(l->hwnd);
|
2015-04-11 21:22:19 -05:00
|
|
|
*height = uiDlgUnitsToY(labelHeight, d->sys->baseY);
|
|
|
|
}
|
|
|
|
|
2015-04-17 10:13:42 -05:00
|
|
|
static char *labelText(uiLabel *l)
|
2015-04-16 08:20:00 -05:00
|
|
|
{
|
|
|
|
return uiWindowsControlText(uiControl(l));
|
|
|
|
}
|
|
|
|
|
2015-04-17 10:13:42 -05:00
|
|
|
static void labelSetText(uiLabel *l, const char *text)
|
2015-04-16 08:20:00 -05:00
|
|
|
{
|
|
|
|
uiWindowsControlSetText(uiControl(l), text);
|
|
|
|
}
|
|
|
|
|
2015-04-16 08:33:21 -05:00
|
|
|
uiLabel *uiNewLabel(const char *text)
|
2015-04-11 21:22:19 -05:00
|
|
|
{
|
|
|
|
struct label *l;
|
2015-05-02 19:51:00 -05:00
|
|
|
uiWindowsMakeControlParams p;
|
2015-04-11 21:22:19 -05:00
|
|
|
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;
|
2015-04-18 17:02:16 -05:00
|
|
|
p.onDestroy = onDestroy;
|
|
|
|
p.onDestroyData = l;
|
2015-05-02 19:51:00 -05:00
|
|
|
uiWindowsMakeControl(uiControl(l), &p);
|
2015-04-11 21:22:19 -05:00
|
|
|
uiFree(wtext);
|
|
|
|
|
2015-04-29 09:46:09 -05:00
|
|
|
l->hwnd = (HWND) uiControlHandle(uiControl(l));
|
2015-04-17 10:13:42 -05:00
|
|
|
|
2015-05-04 13:56:26 -05:00
|
|
|
uiControl(l)->PreferredSize = labelPreferredSize;
|
2015-04-11 21:22:19 -05:00
|
|
|
|
2015-04-17 10:13:42 -05:00
|
|
|
uiLabel(l)->Text = labelText;
|
|
|
|
uiLabel(l)->SetText = labelSetText;
|
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
|
|
|
}
|