CtMiscImpl.mesa
Copyright Ó 1985, 1992 by Xerox Corporation. All rights reserved.
Bloomenthal, July 4, 1992 12:08 pm PDT
DIRECTORY Buttons, Controls, CtBasic, CtMisc, Draw2d, Imager, ImagerBackdoor, Rope, TextNode, TiogaAccess, TiogaAccessViewers, TiogaImager, ViewerClasses;
CtMiscImpl: CEDAR PROGRAM
IMPORTS Buttons, Draw2d, Imager, ImagerBackdoor, Rope, TiogaAccess, TiogaAccessViewers, TiogaImager
EXPORTS CtMisc
~ BEGIN
Types
Context:    TYPE ~ Imager.Context;
Color:     TYPE ~ Imager.Color;
Rectangle:   TYPE ~ Imager.Rectangle;
VEC:     TYPE ~ Imager.VEC;
ROPE:     TYPE ~ Rope.ROPE;
Viewer:    TYPE ~ ViewerClasses.Viewer;
Button Miscellany
ButtonToggle: PUBLIC PROC [button: Viewer] ~ {
index: INTEGER ¬ Rope.Find[button.name, "On", 0, FALSE];
Relabel: PROC [rope: ROPE, n: NAT] ~ {
Buttons.ReLabel[button, Rope.Cat[
Rope.Substr[button.name, 0, index+1], rope, Rope.Substr[button.name, index+1+n]]];
};
IF index # -1
THEN {
Relabel["ff", 1];
Buttons.SetDisplayStyle[button, $BlackOnWhite];
}
ELSE {
index ¬ Rope.Find[button.name, "Off", 0, FALSE];
IF index # -1 THEN Relabel["n", 2];
Buttons.SetDisplayStyle[button, $WhiteOnBlack];
};
};
ButtonOn: PUBLIC PROC [button: Viewer] RETURNS [BOOL] ~ {
RETURN[Rope.Find[button.name, "on", 0, FALSE] # -1];
};
Printing
PrintTiogaSelection: PUBLIC PROC [
p: VEC,
color: Color,
context: Context ¬ NIL,
screenStyle: BOOL ¬ FALSE]
RETURNS [error: ROPE] ~ {
c: Context ~ context;
bounds: Rectangle ¬ ImagerBackdoor.GetBounds[c];
formattedNode: TiogaImager.FormattedNodes;
reader: TiogaAccessViewers.Reader ~ TiogaAccessViewers.FromSelection[];
location: TextNode.Location ~ [NARROW[TiogaAccess.GetLocation[reader].node], 0];
IF location.node = NIL THEN RETURN["Bad Text"];
IF color = NIL THEN color ¬ ImagerBackdoor.GetColor[context];
formattedNode ¬ TiogaImager.FormatNodes[location, [bounds.w, bounds.h], IF screenStyle THEN screen ELSE print];
Imager.SetColor[c, color];
TiogaImager.Render[formattedNode.box, c, [p.x, p.y]];
};
PrintRope: PUBLIC PROC [
rope: ROPE,
p: VEC,
color: Color ¬ NIL,
font: ROPE ¬ NIL,
size: REAL ¬ 14.0,
context: Context ¬ NIL]
~ {
IF font = NIL THEN font ¬ "helvetica-mrr";
Imager.SetFont[context, Imager.FindFontScaled[Rope.Concat["xerox/pressfonts/", font], size]];
IF color # NIL THEN Imager.SetColor[context, color];
Draw2d.Label[context, [p.x, ImagerBackdoor.GetBounds[context].h-p.y], rope];
};
END.