GGValueEventImpl.mesa
Copyright © 1992 by Xerox Corporation. All rights reserved.
Bier, June 30, 1993 11:20 pm PDT
Contents: Registered Gargoyle actions that return values using the GGFutureValue interface.
DIRECTORY
Feedback, FutureValues, GGInterfaceTypes, GGModelTypes, GGScene, GGSliceOps, GGUserInput, Imager, ImagerColorPrivate, IO, Rope;
GGValueEventImpl: CEDAR PROGRAM
IMPORTS Feedback, FutureValues, GGScene, GGSliceOps, GGUserInput, ImagerColorPrivate, IO
= BEGIN
Color: TYPE = Imager.Color;
FutureValue: TYPE = FutureValues.FutureValue;
GGData: TYPE = GGInterfaceTypes.GGData;
ROPE: TYPE = Rope.ROPE;
Slice: TYPE = GGModelTypes.Slice;
SliceDescriptor: TYPE = GGModelTypes.SliceDescriptor;
UserInputProc: TYPE = GGUserInput.UserInputProc;
GetSelectedSlices: UserInputProc = {
fv: FutureValue ¬ NARROW[event.rest.first];
slices: LIST OF SliceDescriptor ¬ GGScene.ListSelectedSlices[ggData.scene, first, normal];
fv.value ¬ slices;
FutureValues.NowAvailable[fv];
};
GetAreaColor: UserInputProc = {
fv: FutureValue ¬ NARROW[event.rest.first];
errorRope: ROPE;
color: Color;
success: BOOL ¬ TRUE;
[color, success, errorRope] ¬ GetColorOfSelectedSlice[TRUE, ggData, "GetAreaColor"];
fv.value ¬ color;
FutureValues.NowAvailable[fv];
};
GetLineColor: UserInputProc = {
fv: FutureValue ¬ NARROW[event.rest.first];
errorRope: ROPE;
color: Color;
success: BOOL ¬ TRUE;
[color, success, errorRope] ¬ GetColorOfSelectedSlice[FALSE, ggData, "GetLineColor"];
fv.value ¬ color;
FutureValues.NowAvailable[fv];
};
GetColorOfSelectedSlice: PROC [fill: BOOL, ggData: GGData, opName: ROPE] RETURNS [color: Color, success: BOOL ¬ TRUE, error: ROPE ¬ NIL] = {
aborted: BOOL ¬ FALSE;
sliceD: SliceDescriptor;
UniqueColorOrAbort: PROC [thisD: SliceDescriptor] RETURNS [done: BOOL ¬ FALSE] = {
thisColor: Color;
isUnique: BOOL ¬ TRUE;
IF sliceD = NIL THEN {
sliceD ¬ thisD;
IF fill THEN [color, isUnique] ¬ GGSliceOps.GetFillColor[thisD.slice, thisD.parts]
ELSE [color, isUnique] ¬ GGSliceOps.GetStrokeColor[thisD.slice, thisD.parts];
done ¬ NOT isUnique;
}
ELSE {
IF fill THEN [color, isUnique] ¬ GGSliceOps.GetFillColor[thisD.slice, thisD.parts]
ELSE [color, isUnique] ¬ GGSliceOps.GetStrokeColor[thisD.slice, thisD.parts];
IF NOT isUnique OR NOT ImagerColorPrivate.ColorEqual[thisColor, color] THEN done ¬ TRUE
};
};
aborted ¬ GGScene.WalkSelectedSlices[ggData.scene, first, UniqueColorOrAbort, normal];
IF aborted OR sliceD = NIL THEN {
error ¬ ReportSelectionProblems[aborted, sliceD, opName, ggData];
success ¬ FALSE;
};
};
ReportSelectionProblems: PROC [aborted: BOOL, sliceD: SliceDescriptor, opName: ROPE, ggData: GGData] RETURNS [error: ROPE] = {
IF aborted THEN {
error ¬ IO.PutFR1["%g failed: there is more than one value for this key", [rope[opName]] ];
Feedback.PutF[ggData.router, oneLiner, $Complaint, "%g failed: there is more than one value for this key", [rope[opName]] ];
}
ELSE IF sliceD = NIL THEN {
error ¬ IO.PutFR1["%g failed: no objects are targeted", [rope[opName]] ];
Feedback.PutF[ggData.router, oneLiner, $Complaint, "%g failed: no objects are selected", [rope[opName]] ];
};
};
RegisterEventProcs: PROC = {
OPEN GGUserInput;
RegisterAction[$GetSelectedSlices, GetSelectedSlices, none, FALSE];
RegisterAction[$GetAreaColor, GetAreaColor, none, FALSE];
RegisterAction[$GetLineColor, GetLineColor, none, FALSE];
};
RegisterEventProcs[];
END.