GGRegistryImpl.mesa
Copyright Ó 1991, 1992 by Xerox Corporation. All rights reserved.
Kenneth A. Pier, July 7, 1992 10:11 am PDT
DIRECTORY
Atom, BiScrollers, GGInterfaceTypes, GGUserInput, GGProps, InputFocus, IO, PropRegistry, Rope, ViewerClasses;
GGRegistryImpl:
CEDAR
PROGRAM
IMPORTS Atom, BiScrollers, GGUserInput, InputFocus, PropRegistry, Rope = BEGIN
Viewer: TYPE = ViewerClasses.Viewer;
GGData: TYPE = GGInterfaceTypes.GGData;
STREAM: TYPE = IO.STREAM;
ROPE: TYPE = PropRegistry.ROPE;
Doc: TYPE = PropRegistry.Doc;
Key: TYPE = PropRegistry.Key;
lf: ROPE = "\l";
noFocus: ROPE = "No input focus in any viewer";
noGGFocus: ROPE = "No input focus in Gargoyle viewer";
LFNewLine:
PROC [in:
ROPE]
RETURNS [out:
ROPE] = {
IF in#
NIL
THEN {
size: INT = Rope.Size[in];
out ¬ in;
FOR index:
INT ¬ Rope.SkipTo[s: in, pos: 0, skip: "\l\r"], Rope.SkipTo[s: in, pos: index+1, skip: "\l\r"]
UNTIL index = size
DO
out ¬ Rope.Replace[base: out, start: index, len: 1, with: lf];
ENDLOOP;
};
};
GGPropGet: PropRegistry.PropGetProc = {
PROC [key: Key, doc: Doc, hint: REF] RETURNS [prop, error: ROPE];
lor: LIST OF ROPE;
extRef: GGUserInput.External;
ggData: GGData;
focus: InputFocus.Focus ¬ InputFocus.GetInputFocus[];
from: Viewer ¬ IF focus#NIL THEN focus.owner ELSE NIL;
IF from=NIL THEN RETURN [NIL, noFocus];
ggData ¬ NARROW[BiScrollers.ClientDataOfViewer[from]];
IF ggData=NIL THEN RETURN [NIL, noGGFocus];
extRef ¬ NEW[GGUserInput.ExternalRec ¬ [FALSE, key] ]; -- pass in Key
GGUserInput.EventNotify[ggData, LIST[$GetPropExternal, extRef] ];
UNTIL extRef.valid
DO GGUserInput.
WaitExternal[extRef]
ENDLOOP;
extRef action type triggers BROADCAST when completed
lor ¬
NARROW[extRef.results];
GetPropExternal returns LIST[prop, error] in extRef.results
prop ¬ LFNewLine[lor.first];
error ¬ LFNewLine[lor.rest.first];
};
GGPropList: PropRegistry.PropListProc = {
PROC [doc: Doc, hint: REF] RETURNS [props: LIST OF Key];
extRef: GGUserInput.External;
ggData: GGData;
focus: InputFocus.Focus ¬ InputFocus.GetInputFocus[];
from: Viewer ¬ IF focus#NIL THEN focus.owner ELSE NIL;
IF from=NIL THEN RETURN [NIL];
ggData ¬ NARROW[BiScrollers.ClientDataOfViewer[from]];
IF ggData=NIL THEN RETURN [NIL];
extRef ¬ NEW[GGUserInput.ExternalRec ¬ [] ];
GGUserInput.EventNotify[ggData,
LIST[$
ListPropsExternal, extRef] ];
extRef action type triggers BROADCAST when completed
UNTIL extRef.valid
DO GGUserInput.
WaitExternal[extRef]
ENDLOOP;
ListPropsExternal returns LIST OF ATOM in extRef.results
props ¬ NARROW[extRef.results];
};
GGPropRem: PropRegistry.PropRemProc = {
PROC [key: Key, doc: Doc, hint: REF, edited: BOOL];
ggData: GGData;
focus: InputFocus.Focus ¬ InputFocus.GetInputFocus[];
from: Viewer ¬ IF focus#NIL THEN focus.owner ELSE NIL;
IF from=NIL THEN RETURN;
ggData ¬ NARROW[BiScrollers.ClientDataOfViewer[from]];
IF ggData=NIL THEN RETURN;
GGUserInput.EventNotify[ggData,
LIST[$
RemoveProp, Atom.GetPName[key]] ];
no need for special RemPropExternal since nothing is returned
};
GGPropSet: PropRegistry.PropSetProc = {
PROC [key: Key, doc: Doc, hint: REF, prop: ROPE, edited: BOOL];
keyVal: Rope.ROPE;
ggData: GGData;
focus: InputFocus.Focus ¬ InputFocus.GetInputFocus[];
from: Viewer ¬ IF focus#NIL THEN focus.owner ELSE NIL;
IF from=NIL THEN RETURN;
ggData ¬ NARROW[BiScrollers.ClientDataOfViewer[from]];
IF ggData=NIL THEN RETURN;
keyVal ¬ Rope.Cat[Atom.GetPName[key], " ", prop]; -- that's what GG wants
GGUserInput.EventNotify[ggData,
LIST[$SetProp, keyVal] ];
no need for special SetPropExternal since nothing is returned
};
GGGetTarget: PropRegistry.GetTargetProc = {
PROC [doc: Doc, hint: REF] RETURNS [success: BOOL, t: Target];
success ¬ TRUE; -- LIE FOR NOW
RETURN [FALSE, [NIL, NIL]];
};
GGSetTarget: PropRegistry.SetTargetProc = {
PROC [doc: Doc, hint: REF, t: Target] RETURNS [success: BOOL, error: ROPE];
success ¬ TRUE; -- LIE FOR NOW
};
GGValidateTarget: PropRegistry.ValidateTargetProc = {
PROC [doc: Doc, hint: REF, t: Target] RETURNS [success: BOOL, error: ROPE];
v: ViewerClasses.Viewer ~ NARROW[doc];
success ¬ NOT (v.destroyed OR v.iconic);
IF NOT success THEN error ¬ IF v.destroyed THEN "target viewer destroyed" ELSE "target viewer iconic"
};
RegisterGG:
PROC = {
class: PropRegistry.RegistryClass ¬ NEW[PropRegistry.RegistryClassObj];
class¬ [
name: $ActionArea,
getProp: GGPropGet,
setProp: GGPropSet,
remProp: GGPropRem,
listProps: GGPropList,
getTarget: GGGetTarget,
setTarget: GGSetTarget,
validTarget: GGValidateTarget
];
PropRegistry.Register[class];
};
RegisterGG[];
END.