X11EvalImpl.mesa
Copyright Ó 1991, 1992 by Xerox Corporation. All rights reserved.
Created by Christian Jacobi, April 24, 1991 7:16 pm PDT
Christian Jacobi, March 27, 1992 11:18 am PST
DIRECTORY
Rope, X11SelectionRequestor, Xl, X11Eval;
X11EvalImpl: CEDAR PROGRAM
IMPORTS Rope, X11SelectionRequestor, Xl
EXPORTS X11Eval ~
BEGIN OPEN X11Eval;
Instance: TYPE = REF InstanceRec;
InstanceRec: TYPE = RECORD [
connection: Xl.Connection ¬ NIL,
text: Rope.ROPE ¬ NIL,
state: Result ¬ noServer,
answer: Rope.ROPE ¬ NIL,
iMadeIt: BOOL ¬ FALSE
];
MySelectionSetup: X11SelectionRequestor.SelectionSetupProc = {
i: Instance ~ NARROW[clientData];
type: Xl.XAtom ~ Xl.MakeAtom[i.connection, "STRING"];
Xl.ChangeProperty[c: connection, w: window, property: property, type: type, data: i.text];
};
MySelectionReceived: X11SelectionRequestor.SelectionReceivedProc = {
i: Instance ~ NARROW[clientData];
typeR: Rope.ROPE ¬ Xl.GetAtomName[i.connection, type];
SELECT result FROM
ok => i.state ¬ success;
none => {i.state ¬ noSelection; RETURN};
timeout => {i.state ¬ timeout; RETURN};
ENDCASE => {};
SELECT TRUE FROM
Rope.Equal[typeR, "STRING"] => i.state ¬ success;
Rope.Equal[typeR, "CRASH"] => i.state ¬ crashed;
Rope.Equal[typeR, "FAIL"] => i.state ¬ failed;
ENDCASE => i.state ¬ badProtocol;
IF value#NIL THEN {
WITH value.first SELECT FROM
r: Rope.ROPE => i.answer ¬ r;
ENDCASE => i.state ¬ badProtocol;
};
};
ErrorEvent: Xl.EventProcType = {
};
Query: PUBLIC PROC [server: REF, selection, text: Rope.ROPE, timeout: INT ¬ 5] RETURNS [state: Result ¬ noServer, answer: Rope.ROPE ¬ NIL] = {
ENABLE {
Xl.connectionNotCreated => {state ¬ noServer; answer ¬ why.reason; GOTO oops};
Xl.XError => {state ¬ noServer; answer ¬ err.explanation; GOTO oops};
};
CreateConnection: PROC [display: Rope.ROPE] = {
errorMatch: Xl.Match ¬ NEW[Xl.MatchRep ¬ [ErrorEvent, Xl.CreateEventFilter[errorNotify], NIL, i]];
i.connection ¬ Xl.CreateConnection[server: display, errorMatch: errorMatch];
i.iMadeIt ¬ TRUE;
};
i: Instance ~ NEW[InstanceRec ¬ [text: text]];
IF server=NIL
THEN CreateConnection[NIL]
ELSE
WITH server SELECT FROM
connection: Xl.Connection => i.connection ¬ connection;
display: Rope.ROPE => CreateConnection[display];
ENDCASE => ERROR;
BEGIN
insertPropertyXAtom: Xl.XAtom ~ Xl.MakeAtom[i.connection, "INSERT←PROPERTY"];
select: Xl.XAtom ~ Xl.MakeAtom[i.connection, selection];
request: X11SelectionRequestor.Request ¬ [target: insertPropertyXAtom, callback: MySelectionReceived, clientData: i, setUp: MySelectionSetup];
X11SelectionRequestor.GetSelection[c: i.connection, selection: select, timeStamp: Xl.currentTime, request: request, timeout: timeout];
answer ¬ i.answer;
state ¬ i.state;
IF i.iMadeIt THEN Xl.CloseConnection[i.connection];
END;
EXITS oops => {};
};
END.