EditToolLooksImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Doug Wyatt, January 13, 1984 2:48 pm
Russ Atkinson (RRA) June 18, 1985 4:55:55 pm PDT
DIRECTORY
Buttons USING [ButtonProc],
EditSpanSupport USING [Apply],
EditToolBuilder USING [BuildButton, BuildDataFieldPair, BuildPair, DataFieldButton, GetDataNode, ToMiddle, VGap],
EditToolPrivate USING [ChangeState, CheckPSel, DoButton, Info, mainToolInfo, Register],
Labels USING [Set],
MessageWindow USING [Append, Blink],
Rope USING [ROPE],
TEditDocument USING [Selection],
TEditInput USING [CommandProc],
TEditInputOps USING [ChangeCaretLooks, ChangeLooks],
TEditLocks USING [Lock],
TEditOps USING [GetSelData, SetTextContents],
TEditSelection USING [LockSel, pSel, SelectionRoot, UnlockDocAndPSel, UnlockSel],
TextEdit USING [FetchLooks, GetRope, Size],
TextLooks USING [allLooks, Looks, LooksToRope, noLooks, RopeToLooks],
TextNode USING [Offset, Ref, RefTextNode, Span];
EditToolLooksImpl:
CEDAR
PROGRAM
IMPORTS EditToolPrivate, EditToolBuilder, TEditLocks, TEditOps, EditSpanSupport, Labels, MessageWindow, TextEdit, TextLooks, TEditInputOps, TEditSelection
EXPORTS EditToolPrivate
= { OPEN EditToolPrivate, EditToolBuilder;
----------------------------
BuildLooksButtons:
PUBLIC
PROC [info: Info] = {
OPEN info;
[,looksArg] ← BuildDataFieldPair[layout, "Looks characters:", LooksArgButton, info, 1];
VGap[layout];
caretLooks ← FALSE;
[] ← BuildButton[layout, "Get", GetLooks, info];
[] ← BuildButton[layout, "Set", SetLooks, info];
[] ← BuildButton[layout, "Clear", ClearLooks, info];
[] ← BuildButton[layout, "Add", AddLooks, info];
[] ← BuildButton[layout, "Sub", RemoveLooks, info];
ToMiddle[layout];
[caretLooksLabel,] ←
BuildPair[layout,CaretLooksButton,caretLooks,caretLooksRope,selLooksRope,info];
};
----------------------------
looksArgAtom: LIST OF REF = Register[$LooksChars,LooksArgOp];
clearLooksArgAtom: LIST OF REF = Register[$ClearLooksChars,ClearLooksArgOp];
LooksArgButton: Buttons.ButtonProc = {
DoButton[looksArgAtom,clearLooksArgAtom, mouseButton=red] };
LooksArgOp: TEditInput.CommandProc = { LooksArg[mainToolInfo] };
LooksArg: PROC [info: Info] = { DataFieldButton[info.looksArg,FALSE] };
ClearLooksArgOp: TEditInput.CommandProc = { ClearLooksArg[mainToolInfo] };
ClearLooksArg: PROC [info: Info] = { DataFieldButton[info.looksArg,TRUE] };
----------------------------
getLooksAtom: LIST OF REF = Register[$GetLooks,GetLooksOp];
GetLooks: Buttons.ButtonProc = {
DoButton[getLooksAtom] };
GetLooksOp: TEditInput.CommandProc = { GetLooksCom[mainToolInfo] };
GetLooksCom:
PROC [info: Info] = {
OPEN info;
pSel: TEditDocument.Selection;
root: TextNode.Ref;
looks: TextLooks.Looks;
TEditSelection.LockSel[primary, "GetLooksCom"];
pSel ← TEditOps.GetSelData[];
IF ~CheckPSel[pSel]
THEN {
OPEN MessageWindow; Append["Make selection.",
TRUE]; Blink[];
TEditSelection.UnlockSel[primary]; RETURN };
root ← TEditSelection.SelectionRoot[pSel];
[] ← TEditLocks.Lock[root, "GetLooksCom", read];
IF caretLooks THEN looks ← pSel.looks -- get the looks for the caret
ELSE {
-- get the looks for the selection
first: BOOLEAN ← TRUE;
span: TextNode.Span;
GetSelLooks:
PROC [node: TextNode.RefTextNode, start, len: TextNode.Offset]
RETURNS [stop: BOOLEAN] = {
end: TextNode.Offset ← MIN[TextEdit.Size[node],start+len];
FOR i: TextNode.Offset
IN [start..end)
DO
lks: TextLooks.Looks ← TextEdit.FetchLooks[node,i];
IF first THEN { first ← FALSE; looks ← lks }
ELSE
IF lks#looks
THEN {
OPEN MessageWindow;
Append["Selection does not have uniform looks.",TRUE];
Append[" Using looks from first char."];
Blink[]; RETURN [TRUE] };
ENDLOOP;
RETURN [FALSE] };
span.start ← [pSel.start.pos.node, pSel.start.pos.where];
span.end ← [pSel.end.pos.node, pSel.end.pos.where];
EditSpanSupport.Apply[span,GetSelLooks];
IF first THEN looks ← pSel.looks -- null selection, use caret
};
TEditSelection.UnlockDocAndPSel[root];
TEditOps.SetTextContents[looksArg, TextLooks.LooksToRope[looks]];
};
----------------------------
GetLooksArg:
PROC [info: Info]
RETURNS [looks: TextLooks.Looks] = {
RETURN [TextLooks.RopeToLooks[TextEdit.GetRope[GetDataNode[info.looksArg]]]] };
ChangeLooks:
PROC [info: Info, add, rem: TextLooks.Looks] = {
pSel: TEditDocument.Selection;
TEditSelection.LockSel[primary, "EditTool.ChangeLooks"];
pSel ← TEditOps.GetSelData[];
IF ~CheckPSel[pSel]
THEN {
OPEN MessageWindow; Append["Make selection.", TRUE]; Blink[];
TEditSelection.UnlockSel[primary]; RETURN };
IF info.caretLooks
THEN
-- change the looks for the caret
TEditInputOps.ChangeCaretLooks[add, rem]
ELSE TEditInputOps.ChangeLooks[add, rem]; -- change the looks for the selection
TEditSelection.UnlockSel[primary];
};
----------------------------
setLooksAtom: LIST OF REF = Register[$DoSetLooks,SetLooksOp];
SetLooks: Buttons.ButtonProc = {
DoButton[setLooksAtom] };
SetLooksOp: TEditInput.CommandProc = { SetLooksCom[mainToolInfo] };
SetLooksCom: PROC [info: Info] = { ChangeLooks[info,GetLooksArg[info],TextLooks.allLooks] };
----------------------------
addLooksAtom: LIST OF REF = Register[$DoAddLooks,AddLooksOp];
AddLooks: Buttons.ButtonProc = {
DoButton[addLooksAtom] };
AddLooksOp: TEditInput.CommandProc = { AddLooksCom[mainToolInfo] };
AddLooksCom: PROC [info: Info] = { ChangeLooks[info,GetLooksArg[info],TextLooks.noLooks] };
----------------------------
removeLooksAtom: LIST OF REF = Register[$DoRemoveLooks,RemoveLooksOp];
RemoveLooks: Buttons.ButtonProc = {
DoButton[removeLooksAtom] };
RemoveLooksOp: TEditInput.CommandProc = { RemoveLooksCom[mainToolInfo] };
RemoveLooksCom: PROC [info: Info] = { ChangeLooks[info,TextLooks.noLooks,GetLooksArg[info]] };
----------------------------
clearLooksAtom: LIST OF REF = Register[$DoClearLooks,ClearLooksOp];
ClearLooks: Buttons.ButtonProc = {
DoButton[clearLooksAtom] };
ClearLooksOp: TEditInput.CommandProc = { ClearLooksCom[mainToolInfo] };
ClearLooksCom: PROC [info: Info] = { ChangeLooks[info,TextLooks.noLooks,TextLooks.allLooks] };
----------------------------
caretLooksRope: Rope.ROPE = "Caret looks";
selLooksRope: Rope.ROPE = "Selection looks";
caretLooksAtom: LIST OF REF = Register[$CaretLooks,CaretLooksOp];
selLooksAtom: LIST OF REF = Register[$SelectionLooks,SelectionLooksOp];
CaretLooksButton: Buttons.ButtonProc = {
ChangeState[mainToolInfo.caretLooks,caretLooksAtom,selLooksAtom] };
CaretLooksOp: TEditInput.CommandProc = { CaretLooks[mainToolInfo] };
CaretLooks:
PROC [info: Info] = {
OPEN info;
caretLooks ← TRUE;
Labels.Set[caretLooksLabel,caretLooksRope] };
SelectionLooksOp: TEditInput.CommandProc = { SelectionLooks[mainToolInfo] };
SelectionLooks:
PROC [info: Info] = {
OPEN info;
caretLooks ← FALSE;
Labels.Set[caretLooksLabel,selLooksRope] };
----------------------------
}.
..