Native tree descriptions previously omitted state-image bits. As a result, foobar2000 Advanced Preferences read setting names without their boolean values, and changing a checkbox without moving focus could go unnoticed. Include TVIS_STATEIMAGEMASK in the native item key so polling observes state changes even when Wine omits WinEvents. Report checked and not-checked states for standard checkbox-tree images while preserving selected and expanded/collapsed states. All queries remain read-only and retain the existing target-architecture buffer layouts and bounded query behavior. Foobar2000 also uses image indexes 3 and 4 for radio choices in its Advanced settings tree. Expose those entries as radio buttons with the corresponding check state. Restrict this application-defined mapping to foobar2000.exe and its Preferences category/settings control identities. Leave unrelated state images uninterpreted rather than inventing mixed checkbox states. Extend the controls fixture with checkbox changes that emit no WinEvent, custom images, and foobar-style radio transitions. Add a foobar-controls runner mode using the application's basename. Exercise identical control IDs and images under an unrelated basename to guard against applying the compatibility mapping to other programs. Account for Wine initializing checkbox images when the fixture first appears. Document support and the manual Preferences acceptance procedure. Validation: - Controls and foobar-controls fixtures passed in both 64-bit and 32-bit. - All six CTests passed: foreground focus, MSAA states, text limits, 64/32-bit review capture, and hook safety. - Existing menu and editor integrations passed, including Unicode, selection/deletion feedback, password exclusion and read-only controls. - A private copy of foobar2000 2.26.1 exposed Advanced setting labels, numeric values, checkbox Space toggles and radio states, plus Components row names and version/module descriptions through the recording reader. - Installed the verified helper alongside the Cthulhu session-bus fix; the user subsequently confirmed that the live changes look good. Recorded events alone do not establish physical Braille acceptance. No foobar2000 settings were changed in the user's live installation.
156 lines
6.3 KiB
C++
156 lines
6.3 KiB
C++
// SPDX-License-Identifier: LGPL-2.1-or-later
|
|
#include "native_items.h"
|
|
#include "control_class.h"
|
|
#include "native_query.h"
|
|
#include <commctrl.h>
|
|
#include <cstddef>
|
|
#include <cstring>
|
|
#include <iterator>
|
|
|
|
namespace {
|
|
using native_control::query;
|
|
bool is_tab(HWND window) {
|
|
wchar_t className[128] = {};
|
|
return GetClassNameW(window, className, std::size(className)) &&
|
|
wine_access_class_matches(className, L"SysTabControl32");
|
|
}
|
|
// foobar2000's Advanced tree extends standard checkbox images with a pair
|
|
// of radio-button images. Restrict this application-defined mapping to it.
|
|
bool is_foobar_settings_tree(HWND window) {
|
|
if (GetDlgCtrlID(window) != 1181) return false;
|
|
HWND root = GetAncestor(window, GA_ROOT);
|
|
HWND categories = GetDlgItem(root, 1068);
|
|
wchar_t className[128] = {};
|
|
if (!categories || !GetClassNameW(categories, className, std::size(className)) ||
|
|
!wine_access_class_matches(className, L"SysTreeView32")) return false;
|
|
DWORD processId = 0;
|
|
GetWindowThreadProcessId(window, &processId);
|
|
HANDLE process = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, processId);
|
|
if (!process) return false;
|
|
wchar_t path[1024] = {};
|
|
DWORD length = std::size(path);
|
|
const bool known = QueryFullProcessImageNameW(process, 0, path, &length);
|
|
CloseHandle(process);
|
|
if (!known) return false;
|
|
const wchar_t *name = path;
|
|
for (const wchar_t *at = path; *at; ++at)
|
|
if (*at == L'\\' || *at == L'/') name = at + 1;
|
|
return lstrcmpiW(name, L"foobar2000.exe") == 0;
|
|
}
|
|
struct Tab32 { uint32_t mask, state, stateMask, text; int32_t capacity; };
|
|
struct Tab64 { uint32_t mask, state, stateMask, padding; uint64_t text; int32_t capacity; };
|
|
struct Tree32 {
|
|
uint32_t mask, item, state, stateMask, text;
|
|
int32_t capacity, image, selectedImage, children;
|
|
};
|
|
struct Tree64 {
|
|
uint32_t mask, padding;
|
|
uint64_t item;
|
|
uint32_t state, stateMask;
|
|
uint64_t text;
|
|
int32_t capacity, image, selectedImage, children;
|
|
};
|
|
static_assert(offsetof(Tab32, text) == 12 && offsetof(Tab64, text) == 16);
|
|
static_assert(offsetof(Tree32, text) == 16 && offsetof(Tree64, text) == 24);
|
|
constexpr size_t textOffset = 128;
|
|
constexpr int textCapacity = 1024;
|
|
constexpr size_t bufferSize = textOffset + textCapacity * sizeof(wchar_t);
|
|
}
|
|
|
|
bool is_native_item_control(HWND window) {
|
|
wchar_t className[128] = {};
|
|
return GetClassNameW(window, className, std::size(className)) &&
|
|
(wine_access_class_matches(className, L"SysTabControl32") ||
|
|
wine_access_class_matches(className, L"SysTreeView32"));
|
|
}
|
|
|
|
NativeItemKey native_item_key(HWND window) {
|
|
NativeItemKey key;
|
|
DWORD_PTR count = 0, item = 0, state = 0;
|
|
if (is_tab(window)) {
|
|
if (!query(window, TCM_GETITEMCOUNT, 0, 0, &count) || count == 0) return key;
|
|
// Keyboard focus can move before selection in button-style tab controls.
|
|
if (!query(window, TCM_GETCURFOCUS, 0, 0, &item) ||
|
|
static_cast<LONG_PTR>(item) < 0)
|
|
if (!query(window, TCM_GETCURSEL, 0, 0, &item)) return key;
|
|
if (item >= count) return key;
|
|
key.item = item + 1; // Zero means no item for both control types.
|
|
DWORD_PTR selected = 0;
|
|
if (query(window, TCM_GETCURSEL, 0, 0, &selected) && selected == item)
|
|
key.state = TVIS_SELECTED;
|
|
} else {
|
|
if (!query(window, TVM_GETCOUNT, 0, 0, &count) ||
|
|
!query(window, TVM_GETNEXTITEM, TVGN_CARET, 0, &item)) return key;
|
|
key.item = item;
|
|
if (item && query(window, TVM_GETITEMSTATE, item,
|
|
TVIS_SELECTED | TVIS_EXPANDED | TVIS_STATEIMAGEMASK, &state)) key.state = state;
|
|
}
|
|
key.count = static_cast<int>(count);
|
|
return key;
|
|
}
|
|
|
|
NativeItem read_native_item(HWND window) {
|
|
NativeItem item;
|
|
const bool tab = is_tab(window);
|
|
item.role = tab ? "page tab" : "tree";
|
|
const auto key = native_item_key(window);
|
|
item.key = key;
|
|
if (!key.item) { item.available = true; return item; }
|
|
native_control::RemoteBuffer remote(window, bufferSize);
|
|
if (!remote) return item;
|
|
const bool wow64 = remote.is32Bit();
|
|
BYTE buffer[bufferSize] = {};
|
|
const auto address = remote.address(textOffset);
|
|
if (tab && wow64) {
|
|
const Tab32 data{TCIF_TEXT, 0, 0, static_cast<uint32_t>(address), textCapacity};
|
|
memcpy(buffer, &data, sizeof(data));
|
|
} else if (tab) {
|
|
const Tab64 data{TCIF_TEXT, 0, 0, 0, address, textCapacity};
|
|
memcpy(buffer, &data, sizeof(data));
|
|
} else if (wow64) {
|
|
const Tree32 data{TVIF_TEXT | TVIF_CHILDREN, static_cast<uint32_t>(key.item),
|
|
0, 0, static_cast<uint32_t>(address), textCapacity, 0, 0, 0};
|
|
memcpy(buffer, &data, sizeof(data));
|
|
} else {
|
|
const Tree64 data{TVIF_TEXT | TVIF_CHILDREN, 0, key.item, 0, 0,
|
|
address, textCapacity, 0, 0, 0};
|
|
memcpy(buffer, &data, sizeof(data));
|
|
}
|
|
DWORD_PTR result = 0;
|
|
if (remote.write(buffer, sizeof(buffer)) &&
|
|
remote.query(window, tab ? TCM_GETITEMW : TVM_GETITEMW, tab ? key.item - 1 : 0,
|
|
&result) && result &&
|
|
remote.read(buffer, sizeof(buffer))) {
|
|
item.available = true;
|
|
wchar_t text[textCapacity] = {};
|
|
memcpy(text, buffer + textOffset, sizeof(text));
|
|
text[textCapacity - 1] = L'\0';
|
|
char utf8[textCapacity * 4] = {};
|
|
if (WideCharToMultiByte(CP_UTF8, 0, text, -1, utf8, sizeof(utf8), nullptr, nullptr))
|
|
item.text = utf8;
|
|
if (key.state & TVIS_SELECTED) item.states = "selected";
|
|
if (tab) { item.position = static_cast<int>(key.item); item.count = key.count; }
|
|
else {
|
|
item.role = "tree item";
|
|
// Query state only; never toggle the item to discover its value.
|
|
const DWORD stateImage = (key.state & TVIS_STATEIMAGEMASK) >> 12;
|
|
const bool radio = (stateImage == 3 || stateImage == 4) &&
|
|
is_foobar_settings_tree(window);
|
|
const bool checkbox = (stateImage == 1 || stateImage == 2) &&
|
|
(GetWindowLongPtrW(window, GWL_STYLE) & TVS_CHECKBOXES);
|
|
if (radio || checkbox) {
|
|
if (!item.states.empty()) item.states += ", ";
|
|
item.states += stateImage == 2 || stateImage == 4 ? "checked" : "not checked";
|
|
if (radio) item.role = "radio button";
|
|
}
|
|
int32_t children = 0;
|
|
memcpy(&children, buffer + (wow64 ? offsetof(Tree32, children) : offsetof(Tree64, children)), sizeof(children));
|
|
if (children != 0) {
|
|
if (!item.states.empty()) item.states += ", ";
|
|
item.states += key.state & TVIS_EXPANDED ? "expanded" : "collapsed";
|
|
}
|
|
}
|
|
}
|
|
return item;
|
|
}
|