Service config dialog: rebuilt to match the main window exactly

Local checkpoint - NOT for public release. Ed flagged the dialog as sloppy - lists
not announcing, wrong tab order, leftover Alt+4/5/6, "Standard/Tight" instead of the
real labels, and not looking like the main window.

- Screen-reader parity: new CheckedListAccessibility.Wire (factored from the main
  window's WireCheckedListAccessibility) drives every checked list - announces
  "checked, <item>. Item N of M. Press Space to toggle." on focus and arrow, plus
  first-letter nav that never toggles. This was the core miss (lists not announcing).
- Layout parity: uses the house FormLayoutRows rows + status labels, QuietTabControl,
  AccessibleCheckBox, MnemonicLabel, and the app icon - so it reads/looks like a real tab.
- Tab order now mirrors the main window: Connectivity, then Audio send, then Audio profile.
- Alt keys renumbered for the dialog (were lifted verbatim from the I/O tab): send tab
  1-5, connectivity 1-2, profile keeps the main window's C/P/D.
- Exact main-window labels copied verbatim: codec ("PCM 48K 24 bit - uncompressed", etc.),
  packet size ("Standard (5 ms PCM, 10/20 ms Opus)" / "Small (2.5 ms ...)"), and the
  lock-to-audio-clock text + accessible description.

Gate 25/25 (dialog passes the accessibility audit: names + unique mnemonics + tab order).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Ednunp
2026-07-12 20:21:48 +01:00
co-authored by Claude Opus 4.8
parent 9a7bd6c9e8
commit 37f28d6c91
2 changed files with 176 additions and 94 deletions
@@ -0,0 +1,90 @@
using System.Windows.Forms;
namespace RemSound.App;
/// <summary>
/// Shared screen-reader wiring for a <see cref="CheckedListBox"/> — the exact behaviour the main
/// window's device lists use, factored out so dialogs (e.g. the service profile editor) announce
/// identically instead of each rolling its own. On focus and on arrow-key move it writes a spoken
/// status ("checked, VLC. Item 1 of 3. Press Space to toggle.") into both the list's
/// AccessibleDescription and a companion status label, so NVDA reads the item AND its checked state.
/// Also adds first-letter navigation that never accidentally toggles a check.
/// </summary>
internal static class CheckedListAccessibility
{
public static void Wire(CheckedListBox list, Label statusLabel, string itemKind)
{
var lastIndex = 0;
void Update(int? overrideIndex = null, bool? overrideChecked = null)
=> SetStatus(list, statusLabel, itemKind, overrideIndex, overrideChecked);
void RestoreFocus()
{
if (list.Items.Count == 0) { Update(); return; }
var target = list.SelectedIndex >= 0 ? list.SelectedIndex : Math.Clamp(lastIndex, 0, list.Items.Count - 1);
if (list.SelectedIndex != target) list.SelectedIndex = target;
lastIndex = target;
Update();
}
list.SelectedIndexChanged += (_, _) =>
{
if (list.SelectedIndex >= 0) lastIndex = list.SelectedIndex;
Update();
};
list.ItemCheck += (_, e) => Update(e.Index, e.NewValue == CheckState.Checked);
list.Enter += (_, _) => RestoreFocus();
list.GotFocus += (_, _) => RestoreFocus();
list.MouseDown += (_, args) =>
{
var index = list.IndexFromPoint(args.Location);
if (index >= 0) { list.SelectedIndex = index; lastIndex = index; }
};
// First-letter navigation that highlights the matching item without ever toggling its check
// (the default CheckedListBox key handling has been seen to toggle on a unique single-letter
// prefix). Spacebar still falls through so Space toggles as normal.
list.KeyDown += (_, args) =>
{
if (args.Modifiers != Keys.None) return;
char ch;
if (args.KeyCode >= Keys.A && args.KeyCode <= Keys.Z) ch = (char)('a' + (args.KeyCode - Keys.A));
else if (args.KeyCode >= Keys.D0 && args.KeyCode <= Keys.D9) ch = (char)('0' + (args.KeyCode - Keys.D0));
else if (args.KeyCode >= Keys.NumPad0 && args.KeyCode <= Keys.NumPad9) ch = (char)('0' + (args.KeyCode - Keys.NumPad0));
else return;
var startIdx = list.SelectedIndex < 0 ? 0 : list.SelectedIndex + 1;
for (var offset = 0; offset < list.Items.Count; offset++)
{
var idx = (startIdx + offset) % list.Items.Count;
var text = list.Items[idx]?.ToString() ?? string.Empty;
if (text.Length > 0 && char.ToLowerInvariant(text[0]) == ch) { list.SelectedIndex = idx; break; }
}
args.Handled = true;
args.SuppressKeyPress = true;
};
Update();
}
// Exact copy of MainForm.UpdateCheckedListStatus so the spoken text is word-for-word identical.
private static void SetStatus(CheckedListBox list, Label statusLabel, string itemKind, int? overrideIndex, bool? overrideChecked)
{
if (list.Items.Count == 0)
{
var emptyText = $"No {itemKind}s available.";
statusLabel.Text = emptyText;
list.AccessibleDescription = emptyText;
return;
}
var index = overrideIndex ?? (list.SelectedIndex >= 0 ? list.SelectedIndex : 0);
index = Math.Clamp(index, 0, list.Items.Count - 1);
var isChecked = overrideChecked ?? list.GetItemChecked(index);
var checkedText = isChecked ? "checked" : "not checked";
var itemText = list.Items[index]?.ToString() ?? itemKind;
var text = $"{checkedText}, {itemText}. Item {index + 1} of {list.Items.Count}. Press Space to toggle.";
statusLabel.Text = text;
list.AccessibleDescription = text;
statusLabel.AccessibleDescription = text;
}
}