Skip to content
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ Any UI it shows will be drawn with [Cacao](https://github.com/PureSwift/Cacao).
| `Graphite2D` | QuickDraw's pixels (1 to 8 bits indexed, 16 and 32 bits direct, big-endian on every CPU, in memory of its own or a program's), colors and the system's color tables, regions as real regions with QuickDraw's region records, patterns, transfer modes, ports, devices and offscreen worlds; drawing rectangles, ovals, round rectangles, arcs, polygons, regions and lines with the pen, and CopyBits, CopyMask and ScrollRect between any depths; PICT pictures, version 1 and 2, with PackBits and QuickTime-compressed images through a decoder the host gives. |
| `GraphiteText` | Fonts: faces and their metrics, the Font Manager's family numbers and names with the classic fonts' and their substitutes, a built-in bitmap system font (from Pomme) and `NFNT` bitmap fonts, and QuickDraw's text in a port's font, face, size and mode, with the styles a face hasn't drawn from its plain glyphs as Mac OS 9.2.2 drew them; ATSUI-style layouts with styled runs, line breaking, measuring, hit testing and drawing, and the text in PICT pictures; and, with the `FreeType` trait (on by default), faces from TrueType, OpenType and other outline fonts, found by family name in the system's font folders. |
| `GraphiteSound` | The Sound Manager: sampled sounds from `'snd '` resources (formats 1 and 2, with the standard, compressed and extended headers) and AIFF and AIFF-C files, read to 16-bit PCM; the µ-law, A-law and IMA4 codecs (MACE is recognized but not decoded yet); sound channels with queued commands (`SndDoCommand`) including `callBackCmd`, `waitCmd` and `syncCmd`, immediate ones, volume, pan, pitch, loops and completion; a mixer that renders them to stereo float frames, for an audio device the host provides; and the frequencies of MIDI notes. |
| `GraphiteWindows` | The Window Manager: windows of every class, from documents, dialogs and alerts to palettes, sheets and drawers, each with the standard Mac OS 8 and 9 frame or a window definition the host brings (the WDEF); the window list ordered by layer, `FrontWindow`, and the active document and the active palette; `FindWindow` and every part of a frame; showing, hiding, selecting, zooming between the user and standard states, collapsing; `MoveWindow`, `SizeWindow` and `SetWindowBounds`, with centering, cascading and the alert position; each window's content in an offscreen buffer with its visible region — what no window in front covers — its update region with `BeginUpdate` and `EndUpdate`, and the part of it the host is told to flush. |
| `GraphiteMenus` | The Menu Manager: menus and their items — text in MacRoman, marks (the check mark and the diamond), icons, styles, keyboard equivalents with their modifiers, submenus by menu ID, command IDs — built with `AppendMenu`'s metacharacter strings or item by item; checked, enabled and disabled; the menu bar with `InsertMenu`'s order and its hierarchical list, `GetMenuHandle`, `MenuKey` and `EnableMenuCommand`; menu definitions (the MDEF) with the standard definition's sizes and item geometry; and `'MENU'` resources read with every field as the classic kept it, enable flags and submenus included. |
| `GraphiteWindows` | The Window Manager: windows of every class, from documents, dialogs and alerts to palettes, sheets and drawers, each with the standard Mac OS 8 and 9 frame or a window definition the host brings (the WDEF); the window list ordered by layer, `FrontWindow`, and the active document and the active palette; `FindWindow` and every part of a frame; showing, hiding, selecting, zooming between the user and standard states, collapsing; close box and drag tracking (`TrackGoAway`, `DragWindow`) fed by the host's loop; `MoveWindow`, `SizeWindow` and `SetWindowBounds`, with centering, cascading and the alert position; each window's content in an offscreen buffer with its visible region — what no window in front covers — its update region with `BeginUpdate` and `EndUpdate`, and the part of it the host is told to flush. |
| `GraphiteMenus` | The Menu Manager: menus and their items — text in MacRoman, marks (the check mark and the diamond), icons, styles, keyboard equivalents with their modifiers, submenus by menu ID, command IDs — built with `AppendMenu`'s metacharacter strings or item by item; checked, enabled and disabled; the menu bar with `InsertMenu`'s order and its hierarchical list, `GetMenuHandle`, `MenuKey` and `EnableMenuCommand`; menu definitions (the MDEF) with the standard definition's sizes and item geometry; `MenuSelect`'s tracking and `MenuChoice`, fed by the host's loop and layout; and `'MENU'` resources read with every field as the classic kept it, enable flags and submenus included. |
| `GraphiteControls` | The Control Manager: controls of the classic's five kinds — buttons, checkboxes, radio buttons, scroll bars and pop-up menus, their control definition IDs and the `useWFont` variation read as the kind beneath it; values, ranges and the pinning SetControlValue did, with the pop-up menu's resource ID and title width in its minimum and maximum as the classic kept them; titles, reference values, command IDs, identifiers, enabling, disabling, activating and `HiliteControl`'s pressed part; the parts a point hits (inButton, inCheckBox, a scroll bar's arrows, pages and thumb), the fixed-size thumb of the classic's scroll bars and the value a drag names; a window's control list, FindControl, GetControlByID and Carbon's root control; and `'CNTL'` resources read field by field. |
| `Graphite` | Re-exports the modules above. |

Expand Down
1 change: 1 addition & 0 deletions ReferenceTests/Retro68/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ add_application(CopyBitsCapture CopyBitsCapture.c)
add_application(TextCapture TextCapture.c TextCapture.r)
add_application(GWorldCapture GWorldCapture.c)
add_application(UtilitiesCapture UtilitiesCapture.c)
add_application(TrackingCapture TrackingCapture.c)
21 changes: 21 additions & 0 deletions ReferenceTests/Retro68/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -769,3 +769,24 @@ from the Finder on Mac OS 9.2.2 in UTM. It writes `Utilities.txt`, kept here as
`UtilitiesCaptureTests` makes the probe's calls through libQuickDraw and
compares every line but the slope calls', which are not QuickDraw's. All match.

## Window and menu tracking

`TrackingCapture.c` records what `TrackGoAway`, `DragWindow` and `MenuSelect`
do with a press and release of the mouse, into
`Tracking-macos-9.2.2-ppc.txt` (CR line endings). It needs someone, or
something, at the mouse: the front window's title says what to do at each of
its 12 steps. The button has to stay down while the pointer moves; drags too
quick for Mac OS to follow give a useless capture.

- `TrackGoAway` answers true where the button is released on the close box.
- `DragWindow` moves the window as far as the pointer moved. Released outside
its limit rectangle, even by 14 pixels, the window stays where it was. A
window behind comes to the front.
- A release on a dimmed item or outside the menus answers 0, and `MenuChoice`
still names the menu, with the dimmed item's number or 0. A choice leaves
the menu's title hilited.
- A click on a title leaves the menu open.
- Menu items are 16 pixels tall and a separator 6.

Not captured: a drag at the limit's edges, a rear window released outside the
limit (Graphite selects it), a drag with the Command key, and submenus.
1 change: 1 addition & 0 deletions ReferenceTests/Retro68/Tracking-macos-9.2.2-ppc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Layoutscreen (0,0,480,640) menuBarHeight 20 lastRight 82menu 129 left 10 width 95 height 70 items 5menu 130 left 45 width 61 height 32 items 2# step 1: press (138,203) FindWindow 6 windowbefore -> window content (150,200,270,440) visible 1 hilited 1 rear content (300,120,400,360) visible 1 hilited 0 front windowTrackGoAway -> 1 released (138,203)mouseUp left in queue 0after -> window content (150,200,270,440) visible 1 hilited 1 rear content (300,120,400,360) visible 1 hilited 0 front window# step 2: press (138,203) FindWindow 6 windowbefore -> window content (150,200,270,440) visible 1 hilited 1 rear content (300,120,400,360) visible 1 hilited 0 front windowTrackGoAway -> 0 released (329,468)mouseUp left in queue 0after -> window content (150,200,270,440) visible 1 hilited 1 rear content (300,120,400,360) visible 1 hilited 0 front window# step 3: press (136,240) FindWindow 4 windowbefore -> window content (150,200,270,440) visible 1 hilited 1 rear content (300,120,400,360) visible 1 hilited 0 front windowDragWindow window released (166,279)mouseUp left in queue 0after -> window content (180,239,300,479) visible 1 hilited 1 rear content (300,120,400,360) visible 1 hilited 0 front window# step 4: press (136,240) FindWindow 4 windowbefore -> window content (150,200,270,440) visible 1 hilited 1 rear content (300,120,400,360) visible 1 hilited 0 front windowDragWindow window released (458,621)mouseUp left in queue 0after -> window content (150,200,270,440) visible 1 hilited 1 rear content (300,120,400,360) visible 1 hilited 0 front window# step 5: press (136,240) FindWindow 4 windowbefore -> window content (150,200,270,440) visible 1 hilited 1 rear content (300,120,400,360) visible 1 hilited 0 front windowDragWindow window released (136,514)mouseUp left in queue 0after -> window content (150,200,270,440) visible 1 hilited 1 rear content (300,120,400,360) visible 1 hilited 0 front window# step 6: press (136,240) FindWindow 4 windowbefore -> window content (150,200,270,440) visible 1 hilited 1 rear content (300,120,400,360) visible 1 hilited 0 front windowDragWindow window released (136,240)mouseUp left in queue 0after -> window content (150,200,270,440) visible 1 hilited 1 rear content (300,120,400,360) visible 1 hilited 0 front window# step 7: press (287,170) FindWindow 4 rearbefore -> window content (150,200,270,440) visible 1 hilited 1 rear content (300,120,400,360) visible 1 hilited 0 front windowDragWindow rear released (309,200)mouseUp left in queue 0after -> window content (150,200,270,440) visible 1 hilited 0 rear content (322,150,422,390) visible 1 hilited 1 front rear# step 8: press (9,24) FindWindow 1 nilbefore -> window content (150,200,270,440) visible 1 hilited 1 rear content (300,120,400,360) visible 1 hilited 0 front windowMenuSelect -> menu 129 item 1 released (27,50) TheMenu 129MenuChoice -> 129,1mouseUp left in queue 0after -> window content (150,200,270,440) visible 1 hilited 1 rear content (300,120,400,360) visible 1 hilited 0 front window# step 9: press (9,24) FindWindow 1 nilbefore -> window content (150,200,270,440) visible 1 hilited 1 rear content (300,120,400,360) visible 1 hilited 0 front windowMenuSelect -> menu 0 item 0 released (65,50) TheMenu 0MenuChoice -> 129,4mouseUp left in queue 0after -> window content (150,200,270,440) visible 1 hilited 1 rear content (300,120,400,360) visible 1 hilited 0 front window# step 10: press (9,24) FindWindow 1 nilbefore -> window content (150,200,270,440) visible 1 hilited 1 rear content (300,120,400,360) visible 1 hilited 0 front windowMenuSelect -> menu 0 item 0 released (351,389) TheMenu 0MenuChoice -> 129,0mouseUp left in queue 0after -> window content (150,200,270,440) visible 1 hilited 1 rear content (300,120,400,360) visible 1 hilited 0 front window# step 11: press (9,61) FindWindow 1 nilbefore -> window content (150,200,270,440) visible 1 hilited 1 rear content (300,120,400,360) visible 1 hilited 0 front windowMenuSelect -> menu 130 item 2 released (44,77) TheMenu 130MenuChoice -> 130,2mouseUp left in queue 0after -> window content (150,200,270,440) visible 1 hilited 1 rear content (300,120,400,360) visible 1 hilited 0 front window# step 12: press (9,24) FindWindow 1 nilbefore -> window content (150,200,270,440) visible 1 hilited 1 rear content (300,120,400,360) visible 1 hilited 0 front windowMenuSelect -> menu 0 item 0 released (229,334) TheMenu 0MenuChoice -> 129,0mouseUp left in queue 0after -> window content (150,200,270,440) visible 1 hilited 1 rear content (300,120,400,360) visible 1 hilited 0 front windowdone
Expand Down
227 changes: 227 additions & 0 deletions ReferenceTests/Retro68/TrackingCapture.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
/*
* Captures what TrackGoAway, DragWindow and MenuSelect do with a press and
* release of the mouse, writing "Tracking.txt" next to itself. It refuses to
* run if that file is already there. The file is flushed after every line.
*
* It needs a person (or a driver) at the mouse. The front window's title says
* what to do next; every press is recorded with where it was released, so the
* pointer need not be placed exactly. A key press ends the probe early.
*
* 1 press the close box, release inside it
* 2 press the close box, release well outside it
* 3 drag the title bar a short way, staying inside the limit
* 4 drag the title bar far below and right of the limit
* 5 drag the title bar to just past the limit's right edge
* 6 click the title bar without moving
* 7 drag the other (rear) window's title bar a short way
* 8 press File, release on New
* 9 press File, release on the dimmed Close
* 10 press File, release outside every menu
* 11 press Edit, release on Copy
* 12 click File without dragging, then click elsewhere
*
* The drag limit is (60,60,400,500), as top, left, bottom, right.
*/
#include <Quickdraw.h>
#include <MacMemory.h>
#include <Windows.h>
#include <Events.h>
#include <Menus.h>
#include <Files.h>
#include <Fonts.h>
#include <TextEdit.h>
#include <Dialogs.h>
#include <stdio.h>
#include <string.h>

enum { kSteps = 12 };

static short out;
static WindowPtr window, rear;
static MenuHandle fileMenu, editMenu;

static void line(const char *text)
{
long count = strlen(text);
FSWrite(out, &count, text);
count = 1;
FSWrite(out, &count, "\r");
FlushVol(0, 0);
}

static const char *which(const void *p)
{
if (!p) return "nil";
if (p == (const void *)window) return "window";
if (p == (const void *)rear) return "rear";
return "another";
}

static Point mouse(void)
{
Point p;
GrafPtr saved, screen;
GetPort(&saved);
GetWMgrPort(&screen);
SetPort(screen);
GetMouse(&p);
LocalToGlobal(&p);
SetPort(saved);
return p;
}

static void place(char *text, const char *name, WindowPtr w)
{
Rect r = (**((WindowPeek)w)->contRgn).rgnBBox;
sprintf(text + strlen(text), " %s content (%d,%d,%d,%d) visible %d hilited %d", name,
r.top, r.left, r.bottom, r.right, (int)(unsigned char)((WindowPeek)w)->visible,
(int)(unsigned char)((WindowPeek)w)->hilited);
}

static void state(const char *label)
{
char text[400];
sprintf(text, "%s ->", label);
place(text, "window", window);
place(text, "rear", rear);
sprintf(text + strlen(text), " front %s", which(FrontWindow()));
line(text);
}

static void reset(int step)
{
static const char *names[] = {
"1 close box, release inside", "2 close box, release outside", "3 drag a little",
"4 drag far down right", "5 drag just past right limit", "6 click title", "7 drag rear window",
"8 File > New", "9 File > Close (dimmed)", "10 File, release outside", "11 Edit > Copy",
"12 click File, click away"
};
Str255 title;
size_t n;
EventRecord ignored;

ShowWindow(window);
MoveWindow(window, 200, 150, false);
MoveWindow(rear, 120, 300, false);
SelectWindow(window);
n = strlen(names[step]);
title[0] = (unsigned char)n;
memcpy(title + 1, names[step], n);
SetWTitle(window, title);
while (GetNextEvent(updateMask | activMask, &ignored))
if (ignored.what == updateEvt) {
BeginUpdate((WindowPtr)ignored.message);
EndUpdate((WindowPtr)ignored.message);
}
FlushEvents(everyEvent, 0);
}

static void layout(void)
{
/* The menu list: the last entry's offset, the bar's right edge and the
definition, then each menu's handle and left edge. */
Handle list = *(Handle *)0x0A1C;
char text[300];
short last = *(short *)*list, offset;
EventRecord ignored;

sprintf(text, "screen (%d,%d,%d,%d) menuBarHeight %d lastRight %d", qd.screenBits.bounds.top,
qd.screenBits.bounds.left, qd.screenBits.bounds.bottom, qd.screenBits.bounds.right,
(int)GetMBarHeight(), (int)*(short *)(*list + 2));
line(text);
for (offset = 6; offset <= last; offset += 6) {
MenuHandle m = *(MenuHandle *)(*list + offset);
short left = *(short *)(*list + offset + 4);
CalcMenuSize(m);
sprintf(text, "menu %d left %d width %d height %d items %d", (**m).menuID, left, (**m).menuWidth,
(**m).menuHeight, (int)CountMItems(m));
line(text);
}
(void)ignored;
}

int main(void)
{
static const unsigned char name[] = { 12, 'T','r','a','c','k','i','n','g','.','t','x','t' };
Rect front = { 150, 200, 270, 440 }, back = { 300, 120, 400, 360 }, limit = { 60, 60, 400, 500 };
EventRecord event;
char text[400];
int step = 0;

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();

fileMenu = NewMenu(129, "\pFile");
AppendMenu(fileMenu, "\pNew/N;Open\311;(-;(Close;Quit/Q");
InsertMenu(fileMenu, 0);
editMenu = NewMenu(130, "\pEdit");
AppendMenu(editMenu, "\pCut;Copy");
InsertMenu(editMenu, 0);
DrawMenuBar();

rear = NewWindow(0, &back, "\prear", true, noGrowDocProc, (WindowPtr)-1L, true, 0);
window = NewWindow(0, &front, "\pwindow", true, noGrowDocProc, (WindowPtr)-1L, true, 0);

line("# Layout");
layout();
reset(0);

while (step < kSteps) {
WindowPtr hit = 0;
short part;
Point end;

if (!WaitNextEvent(everyEvent, &event, 10, 0)) continue;
if (event.what == keyDown) break;
if (event.what == updateEvt) {
BeginUpdate((WindowPtr)event.message);
EndUpdate((WindowPtr)event.message);
}
if (event.what != mouseDown) continue;

part = FindWindow(event.where, &hit);
sprintf(text, "# step %d: press (%d,%d) FindWindow %d %s", step + 1, event.where.v, event.where.h,
part, which(hit));
line(text);
/* A press somewhere the step doesn't ask for is not counted. */
if (step < 2 ? part != inGoAway : step < 7 ? part != inDrag : part != inMenuBar) continue;

state("before");
if (part == inGoAway) {
Boolean result = TrackGoAway(hit, event.where);
end = mouse();
sprintf(text, "TrackGoAway -> %d released (%d,%d)", (int)(result != 0), end.v, end.h);
} else if (part == inDrag) {
DragWindow(hit, event.where, &limit);
end = mouse();
sprintf(text, "DragWindow %s released (%d,%d)", which(hit), end.v, end.h);
} else {
long choice = MenuSelect(event.where);
end = mouse();
sprintf(text, "MenuSelect -> menu %d item %d released (%d,%d) TheMenu %d",
(int)(short)(choice >> 16), (int)(short)choice, end.v, end.h, (int)*(short *)0x0A26);
line(text);
sprintf(text, "MenuChoice -> %ld,%ld", MenuChoice() >> 16, MenuChoice() & 0xFFFF);
HiliteMenu(0);
}
line(text);
sprintf(text, "mouseUp left in queue %d", (int)(EventAvail(mUpMask, &event) != 0));
line(text);
state("after");

if (++step < kSteps) reset(step);
}

line("done");
FSClose(out);
FlushVol(0, 0);
return 0;
}
Loading
Loading