2015-04-11 21:22:19 -05:00
|
|
|
// 11 april 2015
|
2016-04-22 19:03:10 -05:00
|
|
|
#include "uipriv_windows.hpp"
|
2015-04-11 21:22:19 -05:00
|
|
|
|
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(
|
2016-04-24 14:04:36 -05:00
|
|
|
uiLabel // type name
|
2015-08-30 11:25:53 -05:00
|
|
|
)
|
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-31 16:50:23 -05:00
|
|
|
static void minimumSize(uiWindowsControl *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
|
|
|
{
|
2016-04-22 19:03:10 -05:00
|
|
|
return uiWindowsWindowText(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
|
|
|
{
|
2016-04-23 21:29:54 -05:00
|
|
|
uiWindowsSetWindowText(l->hwnd, text);
|
2015-06-03 14:49:44 -05:00
|
|
|
// changing the text might necessitate a change in the label's size
|
2016-04-29 11:20:41 -05:00
|
|
|
uiWindowsControlMinimumSizeChanged(uiWindowsControl(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;
|
|
|
|
|
2016-04-24 16:38:48 -05:00
|
|
|
l = (uiLabel *) uiNewControl(uiLabel);
|
2015-04-16 08:20:00 -05:00
|
|
|
|
2015-04-11 21:22:19 -05:00
|
|
|
wtext = toUTF16(text);
|
2015-08-31 11:33:44 -05:00
|
|
|
l->hwnd = uiWindowsEnsureCreateControlHWND(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
|
|
|
}
|