Echo typed characters in Wine edit fields

This commit is contained in:
deedra committed 2026-10-12 15:31:00 -07:00
1 parent d9aa40e16c
commit a002c4cc1e
7 files changed
+154 -22

No files matched your search

+36
View File
@@ -14,6 +14,8 @@ typedef struct EditState {
WCHAR *text;
DWORD length;
BOOL busy, known, destroyed;
WCHAR pending_high;
DWORD pending_caret;
} EditState;
static void selection(HWND window, DWORD *start, DWORD *end) {
@@ -94,6 +96,8 @@ static LRESULT CALLBACK edit_proc(HWND window, UINT message, WPARAM wp, LPARAM l
message == WM_PASTE || message == WM_CUT || message == WM_CLEAR ||
message == WM_UNDO || message == EM_UNDO || message == EM_REPLACESEL ||
message == WM_SETTEXT || message == EM_SETHANDLE || message == EM_FMTLINES;
BOOL typing = message == WM_CHAR &&
((wp >= 0x20 && wp <= 0xffff && wp != 0x7f) || wp == VK_RETURN || wp == VK_TAB);
BOOL requested_focus = message == RegisterWindowMessageW(EDIT_FOCUS_MESSAGE);
BOOL focus = message == WM_SETFOCUS || requested_focus;
BOOL selected = message == EM_SETSEL;
@@ -101,6 +105,9 @@ static LRESULT CALLBACK edit_proc(HWND window, UINT message, WPARAM wp, LPARAM l
return DefSubclassProc(window, message, wp, lp);
state->busy = TRUE;
WCHAR pending_high = state->pending_high;
DWORD pending_caret = state->pending_caret;
state->pending_high = 0;
DWORD old_start = 0, old_end = 0;
selection(window, &old_start, &old_end);
BOOL password = (GetWindowLongPtrW(window, GWL_STYLE) & ES_PASSWORD) != 0;
@@ -185,6 +192,35 @@ static LRESULT CALLBACK edit_proc(HWND window, UINT message, WPARAM wp, LPARAM l
kind = message == WM_CHAR && wp == VK_BACK
? WINE_ACCESS_TEXT_BACKSPACED : WINE_ACCESS_TEXT_DELETED;
report = TRUE;
} else if (typing && !(GetWindowLongPtrW(window, GWL_STYLE) & ES_READONLY) &&
start == end && start > old_start && old_start <= old_end &&
old_end <= old_length && state->length > old_length - (old_end - old_start)) {
// Echo accepted input, including replacements that shorten a selection.
// WM_CHAR delivers supplementary characters as two UTF-16 messages.
if (wp >= 0xd800 && wp <= 0xdbff) {
state->pending_high = (WCHAR)wp;
state->pending_caret = start;
} else if (wp < 0xdc00 || wp > 0xdfff ||
(pending_high && pending_caret == old_start && old_start == old_end)) {
DWORD first = old_start;
BOOL paired = wp >= 0xdc00 && wp <= 0xdfff;
if (paired) --first;
if (state->text && start <= state->length) {
copy_range(text, state->text, first, start);
} else {
// Large documents have no full snapshot. The accepted WM_CHAR still
// supplies bounded typing feedback without copying the document.
UINT used = 0;
if (paired) text[used++] = pending_high;
text[used++] = (WCHAR)wp;
text[used] = 0;
LONG_PTR style = GetWindowLongPtrW(window, GWL_STYLE);
if (style & ES_UPPERCASE) CharUpperBuffW(text, used);
else if (style & ES_LOWERCASE) CharLowerBuffW(text, used);
}
kind = WINE_ACCESS_TEXT_INSERTED;
report = text[0] != 0;
}
}
if (report) notify_text(window, kind, text, start, end);
state->busy = FALSE;