Skip to content
Merged
196 changes: 196 additions & 0 deletions ReferenceTests/Retro68/ActivateEventCapture.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
/*
* Captures which Window Manager calls bring activate, update and OS events, in
* what order, and what each call leaves the windows' hilited fields. It has the
* SIZE flags of BBEdit Lite 6.1, and starts with the calls BBEdit makes to show
* its first window.
*
* It writes "ActivateEvents.txt" in its own folder, and refuses to run if that
* is already there. Each step is a line naming the calls, with the front window
* and each window's hilited as they were straight after them, then a line for
* each event that GetNextEvent returned in the half second after.
*/
#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 <Events.h>
#include <stdio.h>
#include <string.h>

static short out;
static WindowPtr a, b;

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 *name(long window)
{
if (window == 0) return "none";
if (window == (long)a) return "A";
if (window == (long)b) return "B";
return "other";
}

static void state(const char *step)
{
char text[200];
sprintf(text, "%s: front %s, A %d, B %d", step, name((long)FrontWindow()),
a ? ((WindowPeek)a)->hilited != 0 : -1, b ? ((WindowPeek)b)->hilited != 0 : -1);
line(text);
}

static void report(const EventRecord *event)
{
char text[200];
switch (event->what) {
case activateEvt:
sprintf(text, " activate %s %s", name(event->message), event->modifiers & activeFlag ? "on" : "off");
break;
case updateEvt:
sprintf(text, " update %s", name(event->message));
BeginUpdate((WindowPtr)event->message);
EndUpdate((WindowPtr)event->message);
break;
case osEvt:
sprintf(text, " os %08lx", (unsigned long)event->message);
break;
case kHighLevelEvent:
sprintf(text, " high level");
break;
default:
sprintf(text, " what %d", event->what);
}
line(text);
}

static void drain(void)
{
EventRecord event;
long until = TickCount() + 30;
while (TickCount() < until) {
SystemTask();
if (GetNextEvent(everyEvent, &event) && event.what != nullEvent)
report(&event);
}
}

static void step(const char *what)
{
state(what);
drain();
}

static WindowPtr make(short left, Boolean visible)
{
Rect bounds;
SetRect(&bounds, left, 80, left + 200, 220);
return NewWindow(0, &bounds, "\pwindow", visible, 8 /* zoomDocProc */, (WindowPtr)-1L, true, 0);
}

int main(void)
{
static const unsigned char file[] = { 18, 'A','c','t','i','v','a','t','e','E','v','e','n','t','s','.','t','x','t' };
short ref;
EventRecord event;
char text[200];

if (FSOpen(file, 0, &ref) == noErr) { FSClose(ref); return 1; }
if (Create(file, 0, 'Grph', 'TEXT') != noErr) return 2;
if (FSOpen(file, 0, &out) != noErr) return 3;

InitGraf(&qd.thePort);
InitFonts();
InitWindows();
InitMenus();
TEInit();
InitDialogs(0);
InitCursor();

/* As BBEdit shows its untitled window, before it has asked for any event. */
a = make(20, false);
state("NewWindow A invisible");
SendBehind(a, 0);
state("SendBehind A nil");
HiliteWindow(a, false);
state("HiliteWindow A false");
ShowHide(a, true);
step("ShowHide A true");
step("nothing more");

b = make(260, false);
step("NewWindow B invisible in front");
ShowWindow(b);
step("ShowWindow B");
SelectWindow(a);
step("SelectWindow A");
SelectWindow(a);
step("SelectWindow A again");
HiliteWindow(a, false);
step("HiliteWindow A false");
HiliteWindow(a, true);
step("HiliteWindow A true");
HideWindow(a);
step("HideWindow A, in front");
ShowWindow(a);
step("ShowWindow A");
ShowHide(a, false);
step("ShowHide A false");
ShowHide(a, true);
step("ShowHide A true");
SendBehind(a, 0);
step("SendBehind A nil");
BringToFront(a);
step("BringToFront A");
SelectWindow(b);
SelectWindow(a);
step("SelectWindow B, SelectWindow A");

/* What a mask without activMask leaves. */
SelectWindow(b);
state("SelectWindow B");
if (GetNextEvent(updateMask, &event)) report(&event);
line(" (after GetNextEvent updateMask)");
drain();

DisposeWindow(b);
b = 0;
step("DisposeWindow B, in front");
DisposeWindow(a);
a = 0;
step("DisposeWindow A, the last");

a = make(20, true);
step("NewWindow A visible, alone");
DisposeWindow(a);
a = make(20, false);
drain();
ShowWindow(a);
step("ShowWindow A, alone");
HideWindow(a);
step("HideWindow A, alone");
SelectWindow(a);
step("SelectWindow A, hidden");
ShowHide(a, true);
step("ShowHide A true, alone");
SelectWindow(a);
step("SelectWindow A, in front already");
DisposeWindow(a);
a = 0;
drain();

sprintf(text, "done");
line(text);
FSClose(out);
FlushVol(0, 0);
return 0;
}
24 changes: 24 additions & 0 deletions ReferenceTests/Retro68/ActivateEventCapture.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* ActivateEventCapture's SIZE: the flags BBEdit Lite 6.1 has that decide which
events it gets, replacing the Retro68 template's. */
#include "Processes.r"

resource 'SIZE' (-1) {
reserved,
acceptSuspendResumeEvents,
reserved,
canBackground,
doesActivateOnFGSwitch,
backgroundAndForeground,
dontGetFrontClicks,
ignoreChildDiedEvents,
is32BitCompatible,
isHighLevelEventAware,
localAndRemoteHLEvents,
notStationeryAware,
dontUseTextEditServices,
reserved,
reserved,
reserved,
1024 * 1024,
1024 * 1024
};
1 change: 1 addition & 0 deletions ReferenceTests/Retro68/ActivateEvents-macos-9.2.2-ppc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NewWindow A invisible: front none, A 0, B -1SendBehind A nil: front none, A 0, B -1HiliteWindow A false: front none, A 0, B -1ShowHide A true: front A, A 0, B -1 high level update Anothing more: front A, A 1, B -1NewWindow B invisible in front: front A, A 1, B 0ShowWindow B: front B, A 0, B 1 activate A off activate B on update BSelectWindow A: front A, A 1, B 0 activate B off activate A onSelectWindow A again: front A, A 1, B 0HiliteWindow A false: front A, A 0, B 0HiliteWindow A true: front A, A 1, B 0HideWindow A, in front: front B, A 0, B 1 activate A off activate B onShowWindow A: front B, A 0, B 1 update AShowHide A false: front B, A 0, B 1ShowHide A true: front B, A 0, B 1 update ASendBehind A nil: front B, A 0, B 1BringToFront A: front A, A 0, B 1SelectWindow B, SelectWindow A: front A, A 1, B 0 activate A off activate A onSelectWindow B: front B, A 0, B 1 (after GetNextEvent updateMask) activate A off activate B onDisposeWindow B, in front: front A, A 1, B -1 activate A onDisposeWindow A, the last: front none, A -1, B -1NewWindow A visible, alone: front A, A 1, B -1 activate A on update AShowWindow A, alone: front A, A 1, B -1 activate A on update AHideWindow A, alone: front none, A 0, B -1 activate A offSelectWindow A, hidden: front none, A 1, B -1 activate A onShowHide A true, alone: front A, A 1, B -1 update ASelectWindow A, in front already: front A, A 1, B -1done
Expand Down
3 changes: 3 additions & 0 deletions ReferenceTests/Retro68/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ add_application(ControlRecordCapture ControlRecordCapture.c)
add_application(ObjectSpecifierCapture ObjectSpecifierCapture.c)
target_link_libraries(ObjectSpecifierCapture ObjectSupportLib)
add_application(WindowFrameCapture WindowFrameCapture.c)
add_application(ActivateEventCapture ActivateEventCapture.c ActivateEventCapture.r)
add_application(FirstWindowCapture FirstWindowCapture.c FirstWindowCapture.r)
add_application(LaunchSequenceCapture LaunchSequenceCapture.c LaunchSequenceCapture.r)
1 change: 1 addition & 0 deletions ReferenceTests/Retro68/FirstWindow-macos-9.2.2-ppc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
events before any window: front none, A -1, B -1 high levelmore events: front none, A -1, B -1ShowHide A true: front A, A 0, B -1 update Alater: front A, A 0, B -1HiliteWindow A false, in front: front A, A 0, B -1later: front A, A 0, B -1SelectWindow A, in front, not hilited: front A, A 1, B -1 activate A onHiliteWindow A false, SelectWindow A: front A, A 1, B -1 activate A onShowHide A true again, after a window has gone: front A, A 0, B -1 update Alater: front A, A 0, B -1done
Expand Down
150 changes: 150 additions & 0 deletions ReferenceTests/Retro68/FirstWindowCapture.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/*
* Captures how the first window of a program that has already been through its
* event loop becomes the active one, shown as BBEdit Lite 6.1 shows its own:
* made invisible, sent behind nil, unhilited and shown with ShowHide. It has the
* same SIZE flags as ActivateEventCapture.
*
* It writes "FirstWindow.txt" in its own folder, and refuses to run if that is
* already there. Lines are as ActivateEventCapture's; a "later" line is the
* state half a second further on, with no Window Manager call in between.
*/
#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 <Events.h>
#include <stdio.h>
#include <string.h>

static short out;
static WindowPtr a, b;

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 *name(long window)
{
if (window == 0) return "none";
if (window == (long)a) return "A";
if (window == (long)b) return "B";
return "other";
}

static void state(const char *step)
{
char text[200];
sprintf(text, "%s: front %s, A %d, B %d", step, name((long)FrontWindow()),
a ? ((WindowPeek)a)->hilited != 0 : -1, b ? ((WindowPeek)b)->hilited != 0 : -1);
line(text);
}

static void report(const EventRecord *event)
{
char text[200];
switch (event->what) {
case activateEvt:
sprintf(text, " activate %s %s", name(event->message), event->modifiers & activeFlag ? "on" : "off");
break;
case updateEvt:
sprintf(text, " update %s", name(event->message));
BeginUpdate((WindowPtr)event->message);
EndUpdate((WindowPtr)event->message);
break;
case osEvt:
sprintf(text, " os %08lx", (unsigned long)event->message);
break;
case kHighLevelEvent:
sprintf(text, " high level");
break;
default:
sprintf(text, " what %d", event->what);
}
line(text);
}

static void drain(void)
{
EventRecord event;
long until = TickCount() + 30;
while (TickCount() < until) {
if (WaitNextEvent(everyEvent, &event, 1, 0) && event.what != nullEvent)
report(&event);
}
}

static void step(const char *what)
{
state(what);
drain();
}

static WindowPtr make(short left, Boolean visible)
{
Rect bounds;
SetRect(&bounds, left, 80, left + 200, 220);
return NewWindow(0, &bounds, "\pwindow", visible, 8 /* zoomDocProc */, (WindowPtr)-1L, true, 0);
}

static void bbedit(const char *what)
{
a = make(20, false);
SendBehind(a, 0);
HiliteWindow(a, false);
ShowHide(a, true);
step(what);
step("later");
}

int main(void)
{
static const unsigned char file[] = { 15, 'F','i','r','s','t','W','i','n','d','o','w','.','t','x','t' };
short ref;

if (FSOpen(file, 0, &ref) == noErr) { FSClose(ref); return 1; }
if (Create(file, 0, 'Grph', 'TEXT') != noErr) return 2;
if (FSOpen(file, 0, &out) != noErr) return 3;

InitGraf(&qd.thePort);
InitFonts();
InitWindows();
InitMenus();
TEInit();
InitDialogs(0);
InitCursor();

step("events before any window");
step("more events");

bbedit("ShowHide A true");
HiliteWindow(a, false);
step("HiliteWindow A false, in front");
step("later");
SelectWindow(a);
step("SelectWindow A, in front, not hilited");
HiliteWindow(a, false);
SelectWindow(a);
step("HiliteWindow A false, SelectWindow A");
DisposeWindow(a);
a = 0;
drain();

bbedit("ShowHide A true again, after a window has gone");
DisposeWindow(a);
a = 0;
drain();

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