SlatePagesImpl.mesa
Copyright Ó 1992, 1993 by Xerox Corporation. All rights reserved.
Christian Jacobi, December 28, 1992 3:17 pm PST
Christian Jacobi, March 6, 1993 4:21 pm PST
DIRECTORY
ImagerSample,
List,
PropList,
SF,
SlatePrivateTypes,
Slate,
XlBitmap;
SlatePagesImpl: CEDAR MONITOR
IMPORTS ImagerSample, List, PropList, SlatePrivateTypes, Slate, XlBitmap
EXPORTS Slate, SlatePrivateTypes ~
BEGIN OPEN Slate;
SessionPrivateRec: PUBLIC TYPE = SlatePrivateTypes.SessionPrivateRec;
InstancePrivateRec: PUBLIC TYPE = SlatePrivateTypes.InstancePrivateRec;
AnyPage: PROC [session: Session] RETURNS [page: Page ¬ NIL] = {
sessionPrivate: REF SessionPrivateRec ¬ session.private;
list: List.LORA ¬ sessionPrivate.pageList;
IF list#NIL THEN RETURN [NARROW[list.first]];
};
CurrentListOfPages: PUBLIC PROC [sesion: Session] RETURNS [list: LIST OF Page ¬ NIL] = {
tail: LIST OF Page ¬ NIL;
Each: PageProc = {
l: LIST OF Page ¬ LIST[page];
IF tail=NIL THEN list ¬ l ELSE tail.rest ¬ l;
tail ¬ l
};
[] ¬ EnumeratePages[sesion, Each]
};
EnumeratePages: PUBLIC PROC [session: Session, eachPage: PageProc, clientData: REF ¬ NIL] RETURNS [quit: BOOL ¬ FALSE] = {
Each: PROC [p: REF ANY] RETURNS [quit: BOOL] = {
quit ¬ eachPage[page: NARROW[p, Page], clientData: clientData].quit
};
sessionPrivate: REF SessionPrivateRec ¬ session.private;
list: List.LORA ¬ sessionPrivate.pageList;
WHILE list # NIL DO
IF Each[list.first].quit THEN RETURN;
list ¬ list.rest;
ENDLOOP;
};
defaultPageSize: PUBLIC <<SlatePrivateTypes>> SF.Vec ¬ [s: 480, f: 640];
NewPage: PUBLIC PROC [session: Session, sz: SF.Vec ¬ [0, 0], initial: ImagerSample.RasterSampleMap, properties: PropList.List ¬ NIL, bpp: INT ¬ 0] RETURNS [page: Page] = {
bm: XlBitmap.Bitmap; contents: ImagerSample.SampleMap;
IF sz.f<=0 OR sz.s<=0 THEN sz ¬ SlatePrivateTypes.defaultPageSize;
IF bpp<=0 THEN bpp ¬ 1;
bm ¬ XlBitmap.Create[sz, bpp];
contents ¬ XlBitmap.GetSM[bm];
ImagerSample.Clear[contents];
IF initial#NIL THEN ImagerSample.Transfer[dst: contents, src: initial];
page ¬ NEW[PageRec ¬ [
session: session,
activeArea: bm,
properties: PropList.NewCopy[properties]
]];
CallGlobalEvent[instance: NIL, session: NIL, event: $NewPage, callData: page];
IF session#NIL THEN {
sessionPrivate: REF SessionPrivateRec ¬ session.private;
Monitored: ENTRY PROC [] = {
sessionPrivate.pageList ¬ List.Append[sessionPrivate.pageList, LIST[page]];
};
IF sessionPrivate=NIL THEN ERROR;
Monitored[];
CallGlobalEvent[instance: NIL, session: session, event: $AddPage0, callData: page];
CallGlobalForAllInstancesOfSession[session: session, event: $AddPage, callData: page];
};
};
RemovePage: PUBLIC PROC [page: Page] = {
session: Session ¬ page.session;
IF session#NIL THEN {
sessionPrivate: REF SessionPrivateRec ¬ session.private;
oldActivePage: Page ¬ ActivePage[session];
Monitored: ENTRY PROC [] = INLINE {
page.session ¬ NIL;
sessionPrivate.pageList ¬ List.Remove[page, sessionPrivate.pageList];
IF session.activePage=page THEN session.activePage ¬ NIL;
};
IF sessionPrivate=NIL THEN ERROR;
Monitored[];
CallGlobalEvent[instance: NIL, session: session, event: $RemovePage0, callData: page];
CallGlobalForAllInstancesOfSession[session: session, event: $RemovePage, callData: page];
IF oldActivePage=page AND session.activePage=NIL THEN {
page: Page ¬ AnyPage[session];
IF page#NIL THEN ActivatePage[page];
};
};
CallGlobalEvent[instance: NIL, session: NIL, event: $DestroyPage, callData: page];
};
ActivePage: PUBLIC PROC [session: Session] RETURNS [page: Page] = {
RETURN [session.activePage]
};
ActivatePage: PUBLIC PROC [page: Page] = {
session: Session ~ page.session;
IF session=NIL THEN ERROR;
IF page#ActivePage[session] THEN {
oldActivePage: Page ¬ NIL;
Monitored: ENTRY PROC [] = INLINE { --yep, we are protecting the structure, not the pixels
oldActivePage ¬ session.activePage;
session.activePage ¬ page;
};
Monitored[];
CallGlobalEvent[instance: NIL, session: session, event: $DeActivatePage0, callData: oldActivePage];
CallGlobalForAllInstancesOfSession[session: session, event: $DeActivatePage, callData: oldActivePage];
CallGlobalEvent[instance: NIL, session: session, event: $ActivatePage0, callData: page];
CallGlobalForAllInstancesOfSession[session: session, event: $ActivatePage, callData: page];
};
};
END.