1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
// 11 april 2015
#include "uipriv_windows.hpp"
struct uiLabel {
uiWindowsControl c;
HWND hwnd;
};
uiWindowsControlAllDefaults(uiLabel)
// via http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
#define labelHeight 8
static void uiLabelMinimumSize(uiWindowsControl *c, int *width, int *height)
{
uiLabel *l = uiLabel(c);
uiWindowsSizing sizing;
int y;
*width = uiWindowsWindowTextWidth(l->hwnd);
y = labelHeight;
uiWindowsGetSizing(l->hwnd, &sizing);
uiWindowsSizingDlgUnitsToPixels(&sizing, NULL, &y);
*height = y;
}
char *uiLabelText(uiLabel *l)
{
return uiWindowsWindowText(l->hwnd);
}
void uiLabelSetText(uiLabel *l, const char *text)
{
uiWindowsSetWindowText(l->hwnd, text);
// changing the text might necessitate a change in the label's size
uiWindowsControlMinimumSizeChanged(uiWindowsControl(l));
}
uiLabel *uiNewLabel(const char *text)
{
uiLabel *l;
WCHAR *wtext;
uiWindowsNewControl(uiLabel, l);
wtext = toUTF16(text);
l->hwnd = uiWindowsEnsureCreateControlHWND(0,
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);
uiFree(wtext);
return l;
}
|