2011-02-27 09:11:01 +00:00
|
|
|
void pTextEdit::setCursorPosition(unsigned position) {
|
2012-04-24 13:13:42 +00:00
|
|
|
if(position == ~0) position >>= 1; //Edit_SetSel takes signed type
|
2011-02-27 09:11:01 +00:00
|
|
|
Edit_SetSel(hwnd, position, position);
|
2012-04-24 13:13:42 +00:00
|
|
|
Edit_ScrollCaret(hwnd);
|
2011-02-27 09:11:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void pTextEdit::setEditable(bool editable) {
|
|
|
|
SendMessage(hwnd, EM_SETREADONLY, editable == false, (LPARAM)0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void pTextEdit::setText(const string &text) {
|
|
|
|
locked = true;
|
|
|
|
string output = text;
|
|
|
|
output.replace("\r", "");
|
|
|
|
output.replace("\n", "\r\n");
|
|
|
|
SetWindowText(hwnd, utf16_t(output));
|
|
|
|
locked = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void pTextEdit::setWordWrap(bool wordWrap) {
|
|
|
|
//ES_AUTOHSCROLL cannot be changed after widget creation.
|
|
|
|
//As a result, we must destroy and re-create widget to change this setting.
|
2012-04-24 13:13:42 +00:00
|
|
|
orphan();
|
2011-02-27 09:11:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
string pTextEdit::text() {
|
|
|
|
unsigned length = GetWindowTextLength(hwnd);
|
|
|
|
wchar_t buffer[length + 1];
|
|
|
|
GetWindowText(hwnd, buffer, length + 1);
|
|
|
|
buffer[length] = 0;
|
2011-04-30 13:12:15 +00:00
|
|
|
string text = (const char*)utf8_t(buffer);
|
2011-02-27 09:11:01 +00:00
|
|
|
text.replace("\r", "");
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
void pTextEdit::constructor() {
|
|
|
|
hwnd = CreateWindowEx(
|
|
|
|
WS_EX_CLIENTEDGE, L"EDIT", L"",
|
2012-04-24 13:13:42 +00:00
|
|
|
WS_CHILD | WS_TABSTOP | WS_VSCROLL | ES_AUTOVSCROLL | ES_MULTILINE | ES_WANTRETURN | (textEdit.state.wordWrap == false ? WS_HSCROLL | ES_AUTOHSCROLL : 0),
|
|
|
|
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)&textEdit);
|
|
|
|
setDefaultFont();
|
|
|
|
setCursorPosition(textEdit.state.cursorPosition);
|
|
|
|
setEditable(textEdit.state.editable);
|
|
|
|
setText(textEdit.state.text);
|
2012-04-24 13:13:42 +00:00
|
|
|
synchronize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void pTextEdit::destructor() {
|
|
|
|
textEdit.state.text = text();
|
|
|
|
DestroyWindow(hwnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
void pTextEdit::orphan() {
|
|
|
|
destructor();
|
|
|
|
constructor();
|
2011-02-27 09:11:01 +00:00
|
|
|
}
|