From 620ed01a15ed34f3b5ba20c3171d326ab57a345e Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Thu, 3 Dec 2026 06:57:30 -0500 Subject: [PATCH 1/7] Add a control record probe --- ReferenceTests/Retro68/ControlRecordCapture.c | 210 ++++++++++++++++++ 1 file changed, 210 insertions(+) create mode 100644 ReferenceTests/Retro68/ControlRecordCapture.c diff --git a/ReferenceTests/Retro68/ControlRecordCapture.c b/ReferenceTests/Retro68/ControlRecordCapture.c new file mode 100644 index 0000000..1611dcd --- /dev/null +++ b/ReferenceTests/Retro68/ControlRecordCapture.c @@ -0,0 +1,210 @@ +/* + * Captures what a scroll bar's control record holds, and how the Control + * Manager calls change it, writing "ControlRecord.txt" next to itself. It + * refuses to run if that file is already there. The file is flushed after + * every line, so a call that crashes leaves the lines before it. + * + * It opens a window of its own, makes scroll bars in it and disposes of + * them. Programs read the record themselves, and BBEdit Lite 6.1 makes its + * window's scroll bars invisible, with empty rectangles, and places them + * later. Addresses are reported only as nil, set or which of the probe's + * controls and windows they are. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static short out; +static WindowPtr window; +static ControlHandle first, second; + +static void line(const char *text) +{ + long count = strlen(text); + FSWrite(out, &count, text); + count = 1; + FSWrite(out, &count, "\r"); + FlushVol(0, 0); +} + +static void number(const char *label, long value) +{ + char text[200]; + sprintf(text, "%s -> %ld", label, value); + line(text); +} + +static const char *which(ControlHandle c) +{ + if (!c) return "nil"; + if (c == first) return "first"; + if (c == second) return "second"; + return "another"; +} + +static void dump(const char *label, ControlHandle control) +{ + static char text[600]; + ControlPtr c = *control; + unsigned long proc = (unsigned long)c->contrlDefProc; + + sprintf(text, "%s -> nextControl %s owner %s rect (%d,%d,%d,%d) vis %d hilite %d value %d min %d max %d", + label, which(c->nextControl), c->contrlOwner == window ? "window" : c->contrlOwner ? "another" : "nil", + c->contrlRect.top, c->contrlRect.left, c->contrlRect.bottom, c->contrlRect.right, + (int)c->contrlVis, (int)c->contrlHilite, c->contrlValue, c->contrlMin, c->contrlMax); + sprintf(text + strlen(text), " defProc %s defProcHighByte %ld data %s action %s rfCon %ld title \"%.*s\"", + proc ? "set" : "nil", (long)(proc >> 24), c->contrlData ? "set" : "nil", + c->contrlAction ? "set" : "nil", (long)c->contrlRfCon, c->contrlTitle[0], c->contrlTitle + 1); + sprintf(text + strlen(text), " handleSize %ld", (long)GetHandleSize((Handle)control)); + line(text); + + sprintf(text, "%s list -> %s", label, which((ControlHandle)((WindowPeek)window)->controlList)); + line(text); +} + +static void layout(void) +{ + char text[200]; + number("sizeof(ControlRecord)", sizeof(ControlRecord)); +#define AT(field) sprintf(text, "offset " #field " -> %d", (int)offsetof(ControlRecord, field)); line(text) + AT(nextControl); AT(contrlOwner); AT(contrlRect); AT(contrlVis); AT(contrlHilite); AT(contrlValue); + AT(contrlMin); AT(contrlMax); AT(contrlDefProc); AT(contrlData); AT(contrlAction); AT(contrlRfCon); + AT(contrlTitle); +} + +/* The part TestControl finds at points down the middle of a vertical bar, as runs. */ +static void parts(const char *label, ControlHandle control) +{ + static char text[600]; + Rect r = (**control).contrlRect; + Point p; + short v, from, found, last = -1; + + sprintf(text, "%s parts ->", label); + p.h = (r.left + r.right) / 2; + from = r.top; + for (v = r.top; v <= r.bottom; ++v) { + p.v = v; + found = v < r.bottom ? TestControl(control, p) : -2; + if (v == r.top) last = found; + if (found != last) { + sprintf(text + strlen(text), " %d..%d:%d", from, v - 1, last); + from = v; + last = found; + } + } + line(text); +} + +int main(void) +{ + static const unsigned char name[] = { 17, 'C','o','n','t','r','o','l','R','e','c','o','r','d','.','t','x','t' }; + Rect bounds = { 60, 40, 360, 440 }, empty = { 0, 0, 0, 0 }, vertical = { 10, 20, 210, 36 }; + char text[200]; + + if (Create(name, 0, 'Grph', 'TEXT') != noErr) return 1; + if (FSOpen(name, 0, &out) != noErr) return 2; + + InitGraf(&qd.thePort); + InitFonts(); + InitWindows(); + InitMenus(); + TEInit(); + InitDialogs(0); + InitCursor(); + + line("# Layout"); + layout(); + + window = NewWindow(0, &bounds, "\pProbe", true, documentProc, (WindowPtr)-1L, true, 0); + SetPort(window); + + line("# An invisible scroll bar with an empty rectangle, as BBEdit makes it"); + first = NewControl(window, &empty, "\p", false, 0, 0, 0, scrollBarProc, 0); + dump("NewControl invisible", first); + number("GetControlVariant", GetControlVariant(first)); + + line("# A second, visible"); + second = NewControl(window, &vertical, "\pTitle", true, 5, 0, 10, scrollBarProc, 1234); + dump("NewControl second", second); + dump("first after second", first); + + line("# Showing and hiding"); + ShowControl(first); + dump("ShowControl", first); + HideControl(first); + dump("HideControl", first); + + line("# Highlighting"); + HiliteControl(second, 254); + dump("HiliteControl 254", second); + parts("hilite 254", second); + HiliteControl(second, 255); + dump("HiliteControl 255", second); + parts("hilite 255", second); + HiliteControl(second, 1); + dump("HiliteControl 1", second); + HiliteControl(second, 0); + dump("HiliteControl 0", second); + parts("value 5 of 0..10", second); + + line("# Values and ranges"); + SetControlMaximum(second, 100); + dump("SetControlMaximum 100", second); + SetControlValue(second, 50); + dump("SetControlValue 50", second); + number("GetControlValue", GetControlValue(second)); + parts("value 50 of 0..100", second); + SetControlValue(second, 200); + dump("SetControlValue 200", second); + parts("value 100 of 0..100", second); + SetControlValue(second, -5); + dump("SetControlValue -5", second); + parts("value 0 of 0..100", second); + SetControlValue(second, 20); + SetControlMinimum(second, 30); + dump("SetControlMinimum 30 above the value", second); + number("GetControlMinimum", GetControlMinimum(second)); + SetControlMaximum(second, 25); + dump("SetControlMaximum 25 below the minimum", second); + number("GetControlMaximum", GetControlMaximum(second)); + parts("maximum below minimum", second); + SetControlMaximum(second, 30); + dump("SetControlMaximum 30 at the minimum", second); + parts("maximum at minimum", second); + SetControlMinimum(second, 0); + dump("SetControlMinimum 0", second); + + line("# Moving, sizing and the rest"); + MoveControl(first, 50, 60); + dump("MoveControl 50,60 invisible", first); + SizeControl(first, 16, 120); + dump("SizeControl 16,120 invisible", first); + SetControlReference(first, 0x12345678); + number("GetControlReference", GetControlReference(first)); + SetControlTitle(first, "\pA much longer control title"); + dump("SetControlTitle", first); + + line("# Disposing"); + DisposeControl(second); + second = 0; + dump("after DisposeControl second", first); + DisposeControl(first); + first = 0; + sprintf(text, "list after DisposeControl first -> %s", ((WindowPeek)window)->controlList ? "set" : "nil"); + line(text); + + DisposeWindow(window); + line("done"); + FSClose(out); + FlushVol(0, 0); + return 0; +} From e9ad421497b828db34e920022fa546d1b6351ed6 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Thu, 3 Dec 2026 06:57:31 -0500 Subject: [PATCH 2/7] Build the control record probe --- ReferenceTests/Retro68/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/ReferenceTests/Retro68/CMakeLists.txt b/ReferenceTests/Retro68/CMakeLists.txt index 1ebb14a..3f24960 100644 --- a/ReferenceTests/Retro68/CMakeLists.txt +++ b/ReferenceTests/Retro68/CMakeLists.txt @@ -27,3 +27,4 @@ add_application(GWorldCapture GWorldCapture.c) add_application(UtilitiesCapture UtilitiesCapture.c) add_application(TrackingCapture TrackingCapture.c) add_application(AEDescLayoutCapture AEDescLayoutCapture.c) +add_application(ControlRecordCapture ControlRecordCapture.c) From 071147eb542f9c92d6b877708c4388de05914fb7 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Thu, 3 Dec 2026 06:57:31 -0500 Subject: [PATCH 3/7] Capture a scroll bar's record on Mac OS 9.2.2 --- ReferenceTests/Retro68/ControlRecord-macos-9.2.2-ppc.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 ReferenceTests/Retro68/ControlRecord-macos-9.2.2-ppc.txt diff --git a/ReferenceTests/Retro68/ControlRecord-macos-9.2.2-ppc.txt b/ReferenceTests/Retro68/ControlRecord-macos-9.2.2-ppc.txt new file mode 100644 index 0000000..fb98639 --- /dev/null +++ b/ReferenceTests/Retro68/ControlRecord-macos-9.2.2-ppc.txt @@ -0,0 +1 @@ +# Layout sizeof(ControlRecord) -> 296 offset nextControl -> 0 offset contrlOwner -> 4 offset contrlRect -> 8 offset contrlVis -> 16 offset contrlHilite -> 17 offset contrlValue -> 18 offset contrlMin -> 20 offset contrlMax -> 22 offset contrlDefProc -> 24 offset contrlData -> 28 offset contrlAction -> 32 offset contrlRfCon -> 36 offset contrlTitle -> 40 # An invisible scroll bar with an empty rectangle, as BBEdit makes it NewControl invisible -> nextControl nil owner window rect (0,0,0,0) vis 0 hilite 0 value 0 min 0 max 0 defProc set defProcHighByte 0 data set action nil rfCon 0 title "" handleSize 41 NewControl invisible list -> first GetControlVariant -> 0 # A second, visible NewControl second -> nextControl first owner window rect (10,20,210,36) vis 255 hilite 0 value 5 min 0 max 10 defProc set defProcHighByte 0 data set action nil rfCon 1234 title "Title" handleSize 46 NewControl second list -> second first after second -> nextControl nil owner window rect (0,0,0,0) vis 0 hilite 0 value 0 min 0 max 0 defProc set defProcHighByte 0 data set action nil rfCon 0 title "" handleSize 41 first after second list -> second # Showing and hiding ShowControl -> nextControl nil owner window rect (0,0,0,0) vis 255 hilite 0 value 0 min 0 max 0 defProc set defProcHighByte 0 data set action nil rfCon 0 title "" handleSize 41 ShowControl list -> second HideControl -> nextControl nil owner window rect (0,0,0,0) vis 0 hilite 0 value 0 min 0 max 0 defProc set defProcHighByte 0 data set action nil rfCon 0 title "" handleSize 41 HideControl list -> second # Highlighting HiliteControl 254 -> nextControl first owner window rect (10,20,210,36) vis 255 hilite 254 value 5 min 0 max 10 defProc set defProcHighByte 0 data set action nil rfCon 1234 title "Title" handleSize 46 HiliteControl 254 list -> second hilite 254 parts -> 10..209:0 HiliteControl 255 -> nextControl first owner window rect (10,20,210,36) vis 255 hilite 255 value 5 min 0 max 10 defProc set defProcHighByte 0 data set action nil rfCon 1234 title "Title" handleSize 46 HiliteControl 255 list -> second hilite 255 parts -> 10..209:0 HiliteControl 1 -> nextControl first owner window rect (10,20,210,36) vis 255 hilite 1 value 5 min 0 max 10 defProc set defProcHighByte 0 data set action nil rfCon 1234 title "Title" handleSize 46 HiliteControl 1 list -> second HiliteControl 0 -> nextControl first owner window rect (10,20,210,36) vis 255 hilite 0 value 5 min 0 max 10 defProc set defProcHighByte 0 data set action nil rfCon 1234 title "Title" handleSize 46 HiliteControl 0 list -> second value 5 of 0..10 parts -> 10..86:22 87..103:129 104..178:23 179..194:20 195..209:21 # Values and ranges SetControlMaximum 100 -> nextControl first owner window rect (10,20,210,36) vis 255 hilite 0 value 5 min 0 max 100 defProc set defProcHighByte 0 data set action nil rfCon 1234 title "Title" handleSize 46 SetControlMaximum 100 list -> second SetControlValue 50 -> nextControl first owner window rect (10,20,210,36) vis 255 hilite 0 value 50 min 0 max 100 defProc set defProcHighByte 0 data set action nil rfCon 1234 title "Title" handleSize 46 SetControlValue 50 list -> second GetControlValue -> 50 value 50 of 0..100 parts -> 10..86:22 87..103:129 104..178:23 179..194:20 195..209:21 SetControlValue 200 -> nextControl first owner window rect (10,20,210,36) vis 255 hilite 0 value 100 min 0 max 100 defProc set defProcHighByte 0 data set action nil rfCon 1234 title "Title" handleSize 46 SetControlValue 200 list -> second value 100 of 0..100 parts -> 10..162:22 163..178:129 179..194:20 195..209:21 SetControlValue -5 -> nextControl first owner window rect (10,20,210,36) vis 255 hilite 0 value 0 min 0 max 100 defProc set defProcHighByte 0 data set action nil rfCon 1234 title "Title" handleSize 46 SetControlValue -5 list -> second value 0 of 0..100 parts -> 10..26:129 27..178:23 179..194:20 195..209:21 SetControlMinimum 30 above the value -> nextControl first owner window rect (10,20,210,36) vis 255 hilite 0 value 30 min 30 max 100 defProc set defProcHighByte 0 data set action nil rfCon 1234 title "Title" handleSize 46 SetControlMinimum 30 above the value list -> second GetControlMinimum -> 30 SetControlMaximum 25 below the minimum -> nextControl first owner window rect (10,20,210,36) vis 255 hilite 0 value 25 min 30 max 25 defProc set defProcHighByte 0 data set action nil rfCon 1234 title "Title" handleSize 46 SetControlMaximum 25 below the minimum list -> second GetControlMaximum -> 25 maximum below minimum parts -> 10..209:0 SetControlMaximum 30 at the minimum -> nextControl first owner window rect (10,20,210,36) vis 255 hilite 0 value 30 min 30 max 30 defProc set defProcHighByte 0 data set action nil rfCon 1234 title "Title" handleSize 46 SetControlMaximum 30 at the minimum list -> second maximum at minimum parts -> 10..209:0 SetControlMinimum 0 -> nextControl first owner window rect (10,20,210,36) vis 255 hilite 0 value 30 min 0 max 30 defProc set defProcHighByte 0 data set action nil rfCon 1234 title "Title" handleSize 46 SetControlMinimum 0 list -> second # Moving, sizing and the rest MoveControl 50,60 invisible -> nextControl nil owner window rect (60,50,60,50) vis 0 hilite 0 value 0 min 0 max 0 defProc set defProcHighByte 0 data set action nil rfCon 0 title "" handleSize 41 MoveControl 50,60 invisible list -> second SizeControl 16,120 invisible -> nextControl nil owner window rect (60,50,180,66) vis 0 hilite 0 value 0 min 0 max 0 defProc set defProcHighByte 0 data set action nil rfCon 0 title "" handleSize 41 SizeControl 16,120 invisible list -> second GetControlReference -> 305419896 SetControlTitle -> nextControl nil owner window rect (60,50,180,66) vis 0 hilite 0 value 0 min 0 max 0 defProc set defProcHighByte 0 data set action nil rfCon 305419896 title "A much longer control title" handleSize 68 SetControlTitle list -> second # Disposing after DisposeControl second -> nextControl nil owner window rect (60,50,180,66) vis 0 hilite 0 value 0 min 0 max 0 defProc set defProcHighByte 0 data set action nil rfCon 305419896 title "A much longer control title" handleSize 68 after DisposeControl second list -> first list after DisposeControl first -> nil done \ No newline at end of file From eaba9cd4bc07a353c925a5b35fbdac940df1bb6e Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Thu, 3 Dec 2026 06:57:31 -0500 Subject: [PATCH 4/7] Add the guest's control record --- .../GraphiteControls/GuestControlRecord.swift | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 Sources/GraphiteControls/GuestControlRecord.swift diff --git a/Sources/GraphiteControls/GuestControlRecord.swift b/Sources/GraphiteControls/GuestControlRecord.swift new file mode 100644 index 0000000..4650165 --- /dev/null +++ b/Sources/GraphiteControls/GuestControlRecord.swift @@ -0,0 +1,68 @@ +// A control's record as the guest sees it: 40 bytes of fields and the title as +// a Pascal string, laid out as Mac OS 9.2.2 gave them (ReferenceTests/Retro68/ +// ControlRecord-macos-9.2.2-ppc.txt). The next control, the owning window and +// the definition and data handles are addresses in guest memory. + +import GraphiteCore + +public struct GuestControlRecord: Hashable, Sendable { + + /// The bytes before the title. + public static let fixedByteCount = 40 + + public var nextControl: UInt32 = 0 + public var owner: UInt32 = 0 + public var bounds: Rect = .zero + public var isVisible = false + /// contrlHilite: 0, a part code, 254 disabled or 255 inactive. + public var hilite: UInt8 = 0 + public var value: Int16 = 0 + public var minimum: Int16 = 0 + public var maximum: Int16 = 0 + public var definitionProc: UInt32 = 0 + public var dataHandle: UInt32 = 0 + public var actionProc: UInt32 = 0 + public var referenceConstant: UInt32 = 0 + public var title = PascalString() + + public init() {} + + /// The record's bytes, as many as its handle held: 40 and the title with + /// its length. A visible control's Boolean is 0xFF. + public var bytes: [UInt8] { + var writer = BigEndianWriter(capacity: Self.fixedByteCount + 1 + title.bytes.count) + writer.write(nextControl) + writer.write(owner) + writer.write(bounds) + writer.write(UInt8(isVisible ? 0xFF : 0)) + writer.write(hilite) + for word in [value, minimum, maximum] { writer.write(word) } + for long in [definitionProc, dataHandle, actionProc, referenceConstant] { writer.write(long) } + writer.write(UInt8(title.bytes.count)) + writer.write(bytes: title.bytes) + return writer.bytes + } + + /// A record read from bytes: paramErr where they end before the title does. + public init(bytes: [UInt8]) throws(MacError) { + let fixed = Self.fixedByteCount + guard bytes.count > fixed, bytes.count > fixed + Int(bytes[fixed]) else { throw .parameter } + self.init() + func word(_ offset: Int) -> UInt16 { UInt16(bytes[offset]) << 8 | UInt16(bytes[offset + 1]) } + func long(_ offset: Int) -> UInt32 { UInt32(word(offset)) << 16 | UInt32(word(offset + 2)) } + func short(_ offset: Int) -> Int16 { Int16(bitPattern: word(offset)) } + nextControl = long(0) + owner = long(4) + bounds = Rect(top: short(8), left: short(10), bottom: short(12), right: short(14)) + isVisible = bytes[16] != 0 + hilite = bytes[17] + value = short(18) + minimum = short(20) + maximum = short(22) + definitionProc = long(24) + dataHandle = long(28) + actionProc = long(32) + referenceConstant = long(36) + title = PascalString(bytes: Array(bytes[fixed + 1 ..< fixed + 1 + Int(bytes[fixed])])) + } +} From 24e86b1ad6b5f81bdb970881005aaac4d5944014 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Thu, 3 Dec 2026 06:57:31 -0500 Subject: [PATCH 5/7] Move a scroll bar's value into a changed range --- Sources/GraphiteControls/Control.swift | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/Sources/GraphiteControls/Control.swift b/Sources/GraphiteControls/Control.swift index 2e22a81..9f8798b 100644 --- a/Sources/GraphiteControls/Control.swift +++ b/Sources/GraphiteControls/Control.swift @@ -31,12 +31,18 @@ public final class Control { /// GetControlValue, SetControlValue: the control's setting — a button's /// 0, a checkbox's or radio button's 0 or 1, a scroll bar's place in /// its range, a pop-up menu's chosen item from 1. - public var value: Int32 = 0 { - didSet { value = min(max(value, minimum), max(minimum, maximum)) } + public var value: Int32 { + get { pinnedValue } + set { pinnedValue = min(max(newValue, minimum), max(minimum, maximum)) } } - /// GetControlMinimum, SetControlMinimum. - public var minimum: Int32 = 0 + private var pinnedValue: Int32 = 0 + + /// GetControlMinimum, SetControlMinimum. A scroll bar's value moves into + /// the new range, as Mac OS 9.2.2 moved it. + public var minimum: Int32 = 0 { + didSet { pinScrollBar() } + } /// GetControlMaximum, SetControlMaximum. A scroll bar whose maximum /// meets its minimum is inactive, as the classic's definition made it, @@ -44,7 +50,16 @@ public final class Control { /// menu's resource ID in its minimum and its title's width in its /// maximum, so a maximum below a minimum is allowed: the classic's own /// fields were the program's to read. - public var maximum: Int32 = 0 + /// + /// A scroll bar's value moves into the new range, and to a maximum that + /// is below the minimum. + public var maximum: Int32 = 0 { + didSet { pinScrollBar() } + } + + private func pinScrollBar() { + if kind == .scrollBar { pinnedValue = min(max(pinnedValue, minimum), maximum) } + } /// GetControlReference, SetControlReference: whatever the program /// keeps with the control. A pop-up menu keeps its menu's resource ID. From 458e0e73d8b80824569043a219162aa9d9b48035 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Thu, 3 Dec 2026 06:57:31 -0500 Subject: [PATCH 6/7] Test control records against Mac OS 9.2.2 --- .../GuestControlRecordTests.swift | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 Tests/GraphiteControlsTests/GuestControlRecordTests.swift diff --git a/Tests/GraphiteControlsTests/GuestControlRecordTests.swift b/Tests/GraphiteControlsTests/GuestControlRecordTests.swift new file mode 100644 index 0000000..d79bd63 --- /dev/null +++ b/Tests/GraphiteControlsTests/GuestControlRecordTests.swift @@ -0,0 +1,105 @@ +import Testing +import Foundation +import GraphiteCore +import GraphiteControls + +/// The control record and a scroll bar's values against what Mac OS 9.2.2 gave +/// (ReferenceTests/Retro68, ControlRecordCapture.c). +@Suite struct GuestControlRecordTests { + + private static let capture: [String] = { + let root = URL(fileURLWithPath: #filePath).deletingLastPathComponent() + .deletingLastPathComponent().deletingLastPathComponent() + let data = try! Data(contentsOf: root.appendingPathComponent("ReferenceTests/Retro68/ControlRecord-macos-9.2.2-ppc.txt")) + return String(decoding: data, as: UTF8.self).split(separator: "\r").map(String.init) + }() + + private func line(_ label: String) -> String { + Self.capture.first { $0.hasPrefix(label + " -> ") }! + } + + private func value(_ text: String, _ key: String) -> Int { + // The label before the arrow may use the same words. + let fields = text.range(of: " -> ")!.upperBound + let start = text.range(of: " \(key) ", range: fields ..< text.endIndex)!.upperBound + return Int(text[start...].prefix { $0 != " " })! + } + + private func range(_ control: Control) -> [Int] { + [Int(control.value), Int(control.minimum), Int(control.maximum)] + } + + private func range(_ label: String) -> [Int] { + let text = line(label) + return [value(text, "value"), value(text, "min"), value(text, "max")] + } + + @Test func fieldsAreWhereMacOSHasThem() throws { + var record = GuestControlRecord() + record.nextControl = 0x01020304 + record.owner = 0x05060708 + record.bounds = Rect(top: 10, left: 20, bottom: 210, right: 36) + record.isVisible = true + record.hilite = 254 + (record.value, record.minimum, record.maximum) = (5, -1, 10) + record.definitionProc = 0x11121314 + record.dataHandle = 0x15161718 + record.actionProc = 0x191A1B1C + record.referenceConstant = 1234 + record.title = "Title" + let bytes = record.bytes + #expect(bytes.count == value(line("NewControl second"), "handleSize")) + func offset(_ field: String) -> Int { Int(line("offset \(field)").split(separator: " ").last!)! } + func at(_ field: String, _ count: Int) -> [UInt8] { Array(bytes[offset(field) ..< offset(field) + count]) } + #expect(at("nextControl", 4) == [1, 2, 3, 4]) + #expect(at("contrlOwner", 4) == [5, 6, 7, 8]) + #expect(at("contrlRect", 8) == [0, 10, 0, 20, 0, 210, 0, 36]) + #expect(at("contrlVis", 1) == [255]) + #expect(at("contrlHilite", 1) == [254]) + #expect(at("contrlValue", 2) == [0, 5]) + #expect(at("contrlMin", 2) == [255, 255]) + #expect(at("contrlMax", 2) == [0, 10]) + #expect(at("contrlDefProc", 4) == [0x11, 0x12, 0x13, 0x14]) + #expect(at("contrlData", 4) == [0x15, 0x16, 0x17, 0x18]) + #expect(at("contrlAction", 4) == [0x19, 0x1A, 0x1B, 0x1C]) + #expect(at("contrlRfCon", 4) == [0, 0, 4, 210]) + #expect(at("contrlTitle", 6) == [5] + Array("Title".utf8)) + #expect(try GuestControlRecord(bytes: bytes) == record) + #expect(throws: MacError.parameter) { try GuestControlRecord(bytes: Array(bytes.dropLast())) } + } + + /// The capture's second scroll bar, its values and ranges changed in its order. + @Test func valuesMoveWithTheRangeAsCaptured() { + let bar = Control(kind: .scrollBar, bounds: Rect(top: 10, left: 20, bottom: 210, right: 36)) + bar.maximum = 10 + bar.value = 5 + #expect(range(bar) == range("NewControl second")) + bar.maximum = 100 + #expect(range(bar) == range("SetControlMaximum 100")) + bar.setValue(50) + #expect(range(bar) == range("SetControlValue 50")) + bar.setValue(200) + #expect(range(bar) == range("SetControlValue 200")) + bar.setValue(-5) + #expect(range(bar) == range("SetControlValue -5")) + bar.setValue(20) + bar.minimum = 30 + #expect(range(bar) == range("SetControlMinimum 30 above the value")) + bar.maximum = 25 + #expect(range(bar) == range("SetControlMaximum 25 below the minimum")) + bar.maximum = 30 + #expect(range(bar) == range("SetControlMaximum 30 at the minimum")) + bar.minimum = 0 + #expect(range(bar) == range("SetControlMinimum 0")) + } + + @Test func movingAndSizingAsCaptured() { + let bar = Control(kind: .scrollBar, bounds: .zero) + bar.move(h: 50, v: 60) + #expect(line("MoveControl 50,60 invisible").contains("rect (60,50,60,50)")) + #expect(bar.bounds == Rect(top: 60, left: 50, bottom: 60, right: 50)) + bar.size(width: 16, height: 120) + #expect(line("SizeControl 16,120 invisible").contains("rect (60,50,180,66)")) + #expect(bar.bounds == Rect(top: 60, left: 50, bottom: 180, right: 66)) + } +} From 416950d5bb41269869789832951fb1f736e9ca44 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Thu, 3 Dec 2026 06:57:31 -0500 Subject: [PATCH 7/7] Describe the control record capture --- ReferenceTests/Retro68/README.md | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/ReferenceTests/Retro68/README.md b/ReferenceTests/Retro68/README.md index ab23a0d..7b3ac98 100644 --- a/ReferenceTests/Retro68/README.md +++ b/ReferenceTests/Retro68/README.md @@ -849,3 +849,36 @@ An event (type `aevt`): `Descriptor.classicData()` and compares them byte for byte, apart from the leftover long and padding byte. The null-target event is not compared: its target type is not meaningful. + +## Control records + +`ControlRecordCapture.c` makes two scroll bars in a window of its own, the +first invisible with an empty rectangle as BBEdit Lite 6.1 makes its window's, +and prints the record's field offsets, then each record and the head of the +window's control list after `NewControl`, `ShowControl`, `HideControl`, +`HiliteControl`, the value and range calls, `MoveControl`, `SizeControl`, +`SetControlTitle` and `DisposeControl`, and the part `TestControl` found down +the middle of the bar. It ran from the Finder on Mac OS 9.2.2 in UTM. Its +output is `ControlRecord-macos-9.2.2-ppc.txt` (CR line endings). + +- The record is 296 bytes as a C structure: nextControl at 0, contrlOwner 4, + contrlRect 8, contrlVis 16, contrlHilite 17, contrlValue 18, contrlMin 20, + contrlMax 22, contrlDefProc 24, contrlData 28, contrlAction 32, contrlRfCon + 36, contrlTitle 40. Its handle held 40 bytes and the title with its length. +- The window's controlList was the newest control, linked by nextControl to + older ones. `DisposeControl` unlinked its control. +- A visible control's contrlVis was 255. A new control had hilite 0, a + defProc handle with a zero high byte, a data handle and no action. +- Changing the minimum or maximum moved the value into the range. With the + maximum below the minimum, the value went to the maximum. +- `MoveControl` and `SizeControl` changed an invisible control's rectangle. +- A bar highlighted 254 or 255, or whose maximum did not exceed its minimum, + had no part anywhere. +- Both arrows were at the bottom of the vertical bar, up above down: a 200 + pixel bar had page and thumb through its first 169 pixels, then 16 for the + up arrow and 15 for the down arrow. Mac OS 9 lets the user choose where the + arrows go, and `StandardControlDefinition` keeps one at each end. + +`GuestControlRecord` is the record's bytes, and `GuestControlRecordTests` +replays the offsets, the values and the rectangles. Parts and drawing are not +replayed.