| 1 |
namespace phoenix { |
| 2 |
|
| 3 |
Size pLineEdit::minimumSize() { |
| 4 |
Size size = pFont::size(hfont, lineEdit.state.text); |
| 5 |
return {size.width + 12, size.height + 10}; |
| 6 |
} |
| 7 |
|
| 8 |
void pLineEdit::setEditable(bool editable) { |
| 9 |
SendMessage(hwnd, EM_SETREADONLY, editable == false, 0); |
| 10 |
} |
| 11 |
|
| 12 |
void pLineEdit::setText(string text) { |
| 13 |
locked = true; |
| 14 |
SetWindowText(hwnd, utf16_t(text)); |
| 15 |
locked = false; |
| 16 |
} |
| 17 |
|
| 18 |
string pLineEdit::text() { |
| 19 |
unsigned length = GetWindowTextLength(hwnd); |
| 20 |
wchar_t text[length + 1]; |
| 21 |
GetWindowText(hwnd, text, length + 1); |
| 22 |
text[length] = 0; |
| 23 |
return (const char*)utf8_t(text); |
| 24 |
} |
| 25 |
|
| 26 |
void pLineEdit::constructor() { |
| 27 |
hwnd = CreateWindowEx( |
| 28 |
WS_EX_CLIENTEDGE, L"EDIT", L"", |
| 29 |
WS_CHILD | WS_TABSTOP | ES_AUTOHSCROLL | ES_AUTOVSCROLL, |
| 30 |
0, 0, 0, 0, parentHwnd, (HMENU)id, GetModuleHandle(0), 0 |
| 31 |
); |
| 32 |
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&lineEdit); |
| 33 |
setDefaultFont(); |
| 34 |
setEditable(lineEdit.state.editable); |
| 35 |
setText(lineEdit.state.text); |
| 36 |
synchronize(); |
| 37 |
} |
| 38 |
|
| 39 |
void pLineEdit::destructor() { |
| 40 |
lineEdit.state.text = text(); |
| 41 |
DestroyWindow(hwnd); |
| 42 |
} |
| 43 |
|
| 44 |
void pLineEdit::orphan() { |
| 45 |
destructor(); |
| 46 |
constructor(); |
| 47 |
} |
| 48 |
|
| 49 |
void pLineEdit::onChange() { |
| 50 |
if(locked) return; |
| 51 |
if(lineEdit.onChange) lineEdit.onChange(); |
| 52 |
} |
| 53 |
|
| 54 |
} |