2015-04-11 21:22:19 -05:00
|
|
|
// 11 april 2015
|
|
|
|
#include "uipriv_windows.h"
|
|
|
|
|
2015-08-30 11:25:53 -05:00
|
|
|
struct uiLabel {
|
|
|
|
uiWindowsControl c;
|
2015-04-17 10:13:42 -05:00
|
|
|
HWND hwnd;
|
2015-04-11 21:22:19 -05:00
|
|
|
};
|
|
|
|
|
2015-08-30 11:25:53 -05:00
|
|
|
uiWindowsDefineControl(
|
|
|
|
uiLabel, // type name
|
|
|
|
uiLabelType // type function
|
|
|
|
)
|
2015-05-29 18:48:27 -05:00
|
|
|
|
2015-04-11 21:22:19 -05:00
|
|
|
// via http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
|
|
|
|
#define labelHeight 8
|
|
|
|
|
2015-08-30 11:25:53 -05:00
|
|
|
static void minimumSize(uiControl *c, uiWindowsSizing *d, intmax_t *width, intmax_t *height)
|
2015-04-11 21:22:19 -05:00
|
|
|
{
|
2015-08-30 11:25:53 -05:00
|
|
|
uiLabel *l = uiLabel(c);
|
2015-04-17 10:13:42 -05:00
|
|
|
|
|
|
|
*width = uiWindowsWindowTextWidth(l->hwnd);
|
2015-08-30 11:25:53 -05:00
|
|
|
*height = uiWindowsDlgUnitsToY(labelHeight, d->BaseY);
|
2015-04-11 21:22:19 -05:00
|
|
|
}
|
|
|
|
|
2015-08-30 11:25:53 -05:00
|
|
|
char *uiLabelText(uiLabel *l)
|
2015-04-16 08:20:00 -05:00
|
|
|
{
|
2015-06-03 14:49:44 -05:00
|
|
|
return uiWindowsUtilText(l->hwnd);
|
2015-04-16 08:20:00 -05:00
|
|
|
}
|
|
|
|
|
2015-08-30 11:25:53 -05:00
|
|
|
void uiLabelSetText(uiLabel *l, const char *text)
|
2015-04-16 08:20:00 -05:00
|
|
|
{
|
2015-06-03 14:49:44 -05:00
|
|
|
uiWindowsUtilSetText(l->hwnd, text);
|
|
|
|
// changing the text might necessitate a change in the label's size
|
|
|
|
uiControlQueueResize(uiControl(l));
|
2015-04-16 08:20:00 -05:00
|
|
|
}
|
|
|
|
|
2015-04-16 08:33:21 -05:00
|
|
|
uiLabel *uiNewLabel(const char *text)
|
2015-04-11 21:22:19 -05:00
|
|
|
{
|
2015-08-30 11:25:53 -05:00
|
|
|
uiLabel *l;
|
2015-04-11 21:22:19 -05:00
|
|
|
WCHAR *wtext;
|
|
|
|
|
2015-08-30 11:25:53 -05:00
|
|
|
l = (uiLabel *) uiNewControl(uiLabelType());
|
2015-04-16 08:20:00 -05:00
|
|
|
|
2015-04-11 21:22:19 -05:00
|
|
|
wtext = toUTF16(text);
|
2015-05-29 19:53:12 -05:00
|
|
|
l->hwnd = uiWindowsUtilCreateControlHWND(0,
|
2015-05-29 17:03:24 -05:00
|
|
|
L"static", 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)
|
|
|
|
SS_LEFTNOWORDWRAP | SS_NOPREFIX,
|
|
|
|
hInstance, NULL,
|
|
|
|
TRUE);
|
2015-04-11 21:22:19 -05:00
|
|
|
uiFree(wtext);
|
|
|
|
|
2015-08-30 11:25:53 -05:00
|
|
|
uiWindowsFinishNewControl(l, uiLabel);
|
2015-04-11 21:22:19 -05:00
|
|
|
|
2015-08-30 11:25:53 -05:00
|
|
|
return l;
|
2015-04-11 21:22:19 -05:00
|
|
|
}
|