2011-04-30 13:12:15 +00:00
|
|
|
Geometry pLabel::minimumGeometry() {
|
2012-04-24 13:13:42 +00:00
|
|
|
Geometry geometry = pFont::geometry(hfont, label.state.text);
|
2011-04-30 13:12:15 +00:00
|
|
|
return { 0, 0, geometry.width, geometry.height };
|
|
|
|
}
|
|
|
|
|
2011-02-27 09:11:01 +00:00
|
|
|
void pLabel::setText(const string &text) {
|
|
|
|
SetWindowText(hwnd, utf16_t(text));
|
|
|
|
InvalidateRect(hwnd, 0, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void pLabel::constructor() {
|
2012-04-24 13:13:42 +00:00
|
|
|
hwnd = CreateWindow(L"phoenix_label", L"", WS_CHILD, 0, 0, 0, 0, parentWindow->p.hwnd, (HMENU)id, GetModuleHandle(0), 0);
|
2011-02-27 09:11:01 +00:00
|
|
|
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&label);
|
|
|
|
setDefaultFont();
|
|
|
|
setText(label.state.text);
|
2012-04-24 13:13:42 +00:00
|
|
|
synchronize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void pLabel::destructor() {
|
|
|
|
DestroyWindow(hwnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
void pLabel::orphan() {
|
|
|
|
destructor();
|
|
|
|
constructor();
|
2011-02-27 09:11:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static LRESULT CALLBACK Label_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
|
|
|
|
Window *window = (Window*)GetWindowLongPtr(GetParent(hwnd), GWLP_USERDATA);
|
|
|
|
Label *label = (Label*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
|
|
|
|
if(!window || !label) return DefWindowProc(hwnd, msg, wparam, lparam);
|
|
|
|
|
2012-04-24 13:13:42 +00:00
|
|
|
if(msg == WM_GETDLGCODE) {
|
|
|
|
return DLGC_STATIC | DLGC_WANTCHARS;
|
|
|
|
}
|
|
|
|
|
2011-02-27 09:11:01 +00:00
|
|
|
if(msg == WM_ERASEBKGND) {
|
|
|
|
//background is erased during WM_PAINT to prevent flickering
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(msg == WM_PAINT) {
|
|
|
|
PAINTSTRUCT ps;
|
|
|
|
RECT rc;
|
|
|
|
BeginPaint(hwnd, &ps);
|
|
|
|
GetClientRect(hwnd, &rc);
|
|
|
|
FillRect(ps.hdc, &rc, window->p.brush ? window->p.brush : GetSysColorBrush(COLOR_3DFACE));
|
|
|
|
SetBkColor(ps.hdc, window->p.brush ? window->p.brushColor : GetSysColor(COLOR_3DFACE));
|
2012-04-24 13:13:42 +00:00
|
|
|
SelectObject(ps.hdc, ((Widget*)label)->p.hfont);
|
2011-02-27 09:11:01 +00:00
|
|
|
unsigned length = GetWindowTextLength(hwnd);
|
|
|
|
wchar_t text[length + 1];
|
|
|
|
GetWindowText(hwnd, text, length + 1);
|
|
|
|
text[length] = 0;
|
|
|
|
DrawText(ps.hdc, text, -1, &rc, DT_CALCRECT | DT_END_ELLIPSIS);
|
|
|
|
unsigned height = rc.bottom;
|
|
|
|
GetClientRect(hwnd, &rc);
|
|
|
|
rc.top = (rc.bottom - height) / 2;
|
|
|
|
rc.bottom = rc.top + height;
|
|
|
|
DrawText(ps.hdc, text, -1, &rc, DT_LEFT | DT_END_ELLIPSIS);
|
|
|
|
EndPaint(hwnd, &ps);
|
|
|
|
}
|
|
|
|
|
|
|
|
return DefWindowProc(hwnd, msg, wparam, lparam);
|
|
|
|
}
|