Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ReferenceTests/Retro68/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions ReferenceTests/Retro68/ControlRecord-macos-9.2.2-ppc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Layoutsizeof(ControlRecord) -> 296offset nextControl -> 0offset contrlOwner -> 4offset contrlRect -> 8offset contrlVis -> 16offset contrlHilite -> 17offset contrlValue -> 18offset contrlMin -> 20offset contrlMax -> 22offset contrlDefProc -> 24offset contrlData -> 28offset contrlAction -> 32offset contrlRfCon -> 36offset contrlTitle -> 40# An invisible scroll bar with an empty rectangle, as BBEdit makes itNewControl 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 41NewControl invisible list -> firstGetControlVariant -> 0# A second, visibleNewControl 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 46NewControl second list -> secondfirst 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 41first after second list -> second# Showing and hidingShowControl -> 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 41ShowControl list -> secondHideControl -> 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 41HideControl list -> second# HighlightingHiliteControl 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 46HiliteControl 254 list -> secondhilite 254 parts -> 10..209:0HiliteControl 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 46HiliteControl 255 list -> secondhilite 255 parts -> 10..209:0HiliteControl 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 46HiliteControl 1 list -> secondHiliteControl 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 46HiliteControl 0 list -> secondvalue 5 of 0..10 parts -> 10..86:22 87..103:129 104..178:23 179..194:20 195..209:21# Values and rangesSetControlMaximum 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 46SetControlMaximum 100 list -> secondSetControlValue 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 46SetControlValue 50 list -> secondGetControlValue -> 50value 50 of 0..100 parts -> 10..86:22 87..103:129 104..178:23 179..194:20 195..209:21SetControlValue 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 46SetControlValue 200 list -> secondvalue 100 of 0..100 parts -> 10..162:22 163..178:129 179..194:20 195..209:21SetControlValue -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 46SetControlValue -5 list -> secondvalue 0 of 0..100 parts -> 10..26:129 27..178:23 179..194:20 195..209:21SetControlMinimum 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 46SetControlMinimum 30 above the value list -> secondGetControlMinimum -> 30SetControlMaximum 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 46SetControlMaximum 25 below the minimum list -> secondGetControlMaximum -> 25maximum below minimum parts -> 10..209:0SetControlMaximum 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 46SetControlMaximum 30 at the minimum list -> secondmaximum at minimum parts -> 10..209:0SetControlMinimum 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 46SetControlMinimum 0 list -> second# Moving, sizing and the restMoveControl 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 41MoveControl 50,60 invisible list -> secondSizeControl 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 41SizeControl 16,120 invisible list -> secondGetControlReference -> 305419896SetControlTitle -> 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 68SetControlTitle list -> second# Disposingafter 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 68after DisposeControl second list -> firstlist after DisposeControl first -> nildone
Expand Down
210 changes: 210 additions & 0 deletions ReferenceTests/Retro68/ControlRecordCapture.c
Original file line number Diff line number Diff line change
@@ -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 <Quickdraw.h>
#include <MacMemory.h>
#include <Windows.h>
#include <Files.h>
#include <Fonts.h>
#include <Menus.h>
#include <TextEdit.h>
#include <Dialogs.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>

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;
}
33 changes: 33 additions & 0 deletions ReferenceTests/Retro68/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
25 changes: 20 additions & 5 deletions Sources/GraphiteControls/Control.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,35 @@ 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,
/// and active again when the range opens. A pop-up menu keeps its
/// 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.
Expand Down
Loading
Loading