Code optimization and bug fixes.

This commit is contained in:
ak47 committed 2026-10-14 20:55:28 -04:00
1 parent 4c47cc5fc4
commit b16c6968ae
11 files changed
+124 -28

No files matched your search

+28 -10
View File
@@ -105,7 +105,12 @@ static LRESULT CALLBACK edit_proc(HWND window, UINT message, WPARAM wp, LPARAM l
BOOL selected = message == EM_SETSEL;
// A dispatched arrow belongs to ordinary caret navigation. Applications
// such as MUSHclient consume history arrows before DispatchMessage instead.
if (navigation || focus) state->history_key = state->history_replaced = FALSE;
// GetMessage can dispatch cross-thread sends before retrieving another
// queued message. Those replacements are not part of the UI thread's
// pretranslated history key, even when a history boundary left it pending.
BOOL remote_replacement = message == WM_SETTEXT && InSendMessageEx(NULL) != ISMEX_NOSEND;
if (navigation || focus || message == WM_KILLFOCUS || remote_replacement)
state->history_key = state->history_replaced = FALSE;
BOOL history_replacement = message == WM_SETTEXT && state->history_key;
if (!navigation && !changing && !focus && !selected && message != EM_SETPASSWORDCHAR)
return DefSubclassProc(window, message, wp, lp);
@@ -243,7 +248,8 @@ static LRESULT CALLBACK edit_proc(HWND window, UINT message, WPARAM wp, LPARAM l
return result;
}
BOOL wine_access_watch_edit(HWND window) {
static BOOL watch_edit(HWND window, EditState **edit_state) {
if (edit_state) *edit_state = NULL;
WCHAR class_name[64];
if (!window || !GetClassNameW(window, class_name, 64)) return FALSE;
#ifdef _WIN64
@@ -253,8 +259,12 @@ BOOL wine_access_watch_edit(HWND window) {
if (!wine_access_class_matches(class_name, L"Edit")) return FALSE;
// Wine's comctl32 v5 exports GetWindowSubclass only by ordinal. Our own
// property also keeps attachment independent of the application's manifest.
if (GetPropW(window, EDIT_STATE_PROPERTY)) return FALSE;
EditState *state = calloc(1, sizeof(*state));
EditState *state = (EditState *)GetPropW(window, EDIT_STATE_PROPERTY);
if (state) {
if (edit_state) *edit_state = state;
return FALSE;
}
state = calloc(1, sizeof(*state));
if (!state) return FALSE;
if (!SetWindowSubclass(window, edit_proc, EDIT_SUBCLASS_ID, (DWORD_PTR)state)) {
free(state); return FALSE;
@@ -268,20 +278,28 @@ BOOL wine_access_watch_edit(HWND window) {
HMODULE module;
GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_PIN,
(LPCWSTR)(UINT_PTR)edit_proc, &module);
if (edit_state) *edit_state = state;
return TRUE;
}
BOOL wine_access_watch_edit(HWND window) {
return watch_edit(window, NULL);
}
__declspec(dllexport) LRESULT CALLBACK WineAccessInputHook(int code, WPARAM wp, LPARAM lp) {
if (code >= 0 && wp == PM_REMOVE) {
wine_access_watch_notifications();
HWND focus = GetFocus();
if (wine_access_watch_edit(focus))
EditState *state;
if (watch_edit(focus, &state)) {
SendMessageW(focus, RegisterWindowMessageW(EDIT_FOCUS_MESSAGE), 0, 0);
EditState *state = (EditState *)GetPropW(focus, EDIT_STATE_PROPERTY);
WCHAR class_name[64];
// Scintilla uses the same attachment property with a different state.
if (state && GetClassNameW(focus, class_name, 64) &&
wine_access_class_matches(class_name, L"Edit") && !state->busy) {
// The synchronous callback can destroy the control. Revalidate only
// on initial attachment, not for every message of an existing editor.
watch_edit(focus, &state);
}
// watch_edit returns typed state only for Edit, never for Scintilla's
// different structure stored under the same attachment property.
if (state && !state->busy) {
const MSG *message = (const MSG *)lp;
// Restrict replacement feedback to this retrieved input message.
// Timers, unrelated programmatic changes and background edits stay silent.