| 1 |
namespace phoenix { |
| 2 |
|
| 3 |
Size pLabel::minimumSize() { |
| 4 |
Size size = pFont::size(hfont, label.state.text); |
| 5 |
return {size.width, size.height}; |
| 6 |
} |
| 7 |
|
| 8 |
void pLabel::setText(string text) { |
| 9 |
SetWindowText(hwnd, utf16_t(text)); |
| 10 |
InvalidateRect(hwnd, 0, false); |
| 11 |
} |
| 12 |
|
| 13 |
void pLabel::constructor() { |
| 14 |
hwnd = CreateWindow(L"phoenix_label", L"", |
| 15 |
WS_CHILD, |
| 16 |
0, 0, 0, 0, parentHwnd, (HMENU)id, GetModuleHandle(0), 0); |
| 17 |
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&label); |
| 18 |
setDefaultFont(); |
| 19 |
setText(label.state.text); |
| 20 |
synchronize(); |
| 21 |
} |
| 22 |
|
| 23 |
void pLabel::destructor() { |
| 24 |
DestroyWindow(hwnd); |
| 25 |
} |
| 26 |
|
| 27 |
void pLabel::orphan() { |
| 28 |
destructor(); |
| 29 |
constructor(); |
| 30 |
} |
| 31 |
|
| 32 |
static LRESULT CALLBACK Label_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { |
| 33 |
HWND parentHwnd = GetParent(hwnd); |
| 34 |
Label* label = (Label*)GetWindowLongPtr(hwnd, GWLP_USERDATA); |
| 35 |
if(label == nullptr) return DefWindowProc(hwnd, msg, wparam, lparam); |
| 36 |
Window* window = (Window*)label->Sizable::state.window; |
| 37 |
if(window == nullptr) return DefWindowProc(hwnd, msg, wparam, lparam); |
| 38 |
|
| 39 |
switch(msg) { |
| 40 |
case WM_GETDLGCODE: return DLGC_STATIC | DLGC_WANTCHARS; |
| 41 |
case WM_ERASEBKGND: return TRUE; |
| 42 |
case WM_PAINT: { |
| 43 |
PAINTSTRUCT ps; |
| 44 |
BeginPaint(hwnd, &ps); |
| 45 |
RECT rc; |
| 46 |
GetClientRect(hwnd, &rc); |
| 47 |
DrawThemeParentBackground(hwnd, ps.hdc, &rc); |
| 48 |
SetBkMode(ps.hdc, TRANSPARENT); |
| 49 |
SelectObject(ps.hdc, ((Widget*)label)->p.hfont); |
| 50 |
unsigned length = GetWindowTextLength(hwnd); |
| 51 |
wchar_t text[length + 1]; |
| 52 |
GetWindowText(hwnd, text, length + 1); |
| 53 |
text[length] = 0; |
| 54 |
DrawText(ps.hdc, text, -1, &rc, DT_CALCRECT | DT_END_ELLIPSIS); |
| 55 |
unsigned height = rc.bottom; |
| 56 |
GetClientRect(hwnd, &rc); |
| 57 |
rc.top = (rc.bottom - height) / 2; |
| 58 |
rc.bottom = rc.top + height; |
| 59 |
DrawText(ps.hdc, text, -1, &rc, DT_LEFT | DT_END_ELLIPSIS); |
| 60 |
EndPaint(hwnd, &ps); |
| 61 |
return FALSE; |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
return DefWindowProc(hwnd, msg, wparam, lparam); |
| 66 |
} |
| 67 |
|
| 68 |
} |