GraphMenus.mesa, Copyright © 1985 by Xerox Corporation. All rights reserved.
Last Edited by:
Sweetsun Chen, October 22, 1985 5:08:11 pm PDT
DIRECTORY
Graph USING [CaretIndex, Error, ROPE],
GraphConvert USING [RopeOfSlope],
GraphPrivate USING [BackgroundIndex, CallWithLock, ColorMap, ColorMode, FlipToggleOnPanel, GetGraph, GraphHandle, GraphProc, Lock, PaintAll, ShowChart, ShowController, SwitchAuto, SwitchCaretVisibility, SwitchCaretBlinking, SwitchTarget, SwitchGrid, Unlock, WriteGraphFile],
GraphUtil USING [BlinkMsg, ControllerNotNil, FileFromSelection, HandleFromViewer, HandleNotNil, Print, ReplaceFileExt, SetCursorForBackgroundIndex, UseCedarColors, UseDefaultColors, UseMyColors],
Menus USING [AppendMenuEntry, CreateEntry, CreateMenu, GetNumberOfLines, Menu, MenuLine, MenuProc],
PopUpMenu USING [RequestSelection],
Terminal USING [ColorCursorPresentation, Current, SetColorCursorPresentation, Virtual],
TiogaMenuOps USING [AllLevels, FewerLevels, FirstLevelOnly, MoreLevels],
TiogaOps USING [Jump, ViewerDoc],
ViewerBLT USING [ChangeNumberOfLines],
ViewerOps USING [MoveViewer],
ViewerTools USING [SetContents];
GraphMenus: CEDAR PROGRAM
IMPORTS Menus, Graph, GraphConvert, GraphPrivate, GraphUtil, PopUpMenu, Terminal, TiogaMenuOps, ViewerBLT, ViewerOps, ViewerTools
EXPORTS GraphPrivate = { OPEN Graph, GraphPrivate, GraphUtil;
Most of the menu procs in this module acquire the lock at the beginning of execution, and release it after execution. Exceptions: those calling procs in GraphEdit.
menus
ControllerMenus: PUBLIC PROC [] RETURNS [menu: Menus.Menu] = {
menu ← Menus.CreateMenu[2];
Menus.AppendMenuEntry
[menu, Menus.CreateEntry[name: "Panel", proc: PanelProc]];
Menus.AppendMenuEntry
[menu, Menus.CreateEntry["Chart", ShowChartProc]];
Menus.AppendMenuEntry
[menu, Menus.CreateEntry[name: "Levels", proc: LevelsProc]];
switches
Menus.AppendMenuEntry[
menu, Menus.CreateEntry[name: "AutoDiv", proc: AutoDivisionsProc], 1];
Menus.AppendMenuEntry[
menu, Menus.CreateEntry[name: "AutoBounds", proc: AutoBoundsProc], 1];
Menus.AppendMenuEntry[
menu, Menus.CreateEntry[name: "Xhair1", proc: PrimXhairProc], 1];
Menus.AppendMenuEntry[
menu, Menus.CreateEntry[name: "Xhair2", proc: SecXhairProc], 1];
Menus.AppendMenuEntry[
menu, Menus.CreateEntry[name: "Slope", proc: SlopeProc], 1];
Menus.AppendMenuEntry[
menu, Menus.CreateEntry[name: "TextCaret", proc: TextCaretProc], 1];
Menus.AppendMenuEntry[
menu, Menus.CreateEntry[name: "TargetX", proc: TargetXProc], 1];
Menus.AppendMenuEntry[
menu, Menus.CreateEntry[name: "TargetY", proc: TargetYProc], 1];
Menus.AppendMenuEntry[
menu, Menus.CreateEntry[name: "GridX", proc: GridXProc], 1];
Menus.AppendMenuEntry[
menu, Menus.CreateEntry[name: "GridY", proc: GridYProc], 1];
levels menus
Menus.AppendMenuEntry[
menu, Menus.CreateEntry[name: "FirstLevelOnly", proc: FirstLevelOnlyProc], 2];
Menus.AppendMenuEntry[
menu, Menus.CreateEntry[name: "MoreLevels", proc: MoreLevelsProc], 2];
Menus.AppendMenuEntry[
menu, Menus.CreateEntry[name: "FewerLevels", proc: FewerLevelsProc], 2];
Menus.AppendMenuEntry[
menu, Menus.CreateEntry[name: "AllLevels", proc: AllLevelsProc], 2];
}; -- ControllerMenus
menuprocs
PanelProc: Menus.MenuProc = {
make the control panel appear or disappear
handle: GraphHandle ← HandleFromViewer[NARROW[parent]];
proc: GraphProc = {
IF ControllerNotNil[handle.controller] THEN { OPEN handle, handle.controller;
IF panelVisible THEN {
ViewerOps.MoveViewer[viewer: panel, x: 0, y: 0, w: panel.ww, h: 0, paint: FALSE];
ViewerOps.MoveViewer[viewer: table, x: 0, y: 0, w: table.ww, h: 1000];
}
ELSE {
ViewerOps.MoveViewer[viewer: panel, x: 0, y: 0, w: panel.ww, h: panelHeight, paint: FALSE];
ViewerOps.MoveViewer[viewer: table, x: 0, y: panelHeight, w: table.ww, h: 1000];
};
panelVisible ← NOT panelVisible;
};
};
CallWithLock[handle, proc];
}; -- Panel
ShowChartProc: Menus.MenuProc = {
handle: GraphHandle ← HandleFromViewer[NARROW[parent]];
Lock[handle];
handle.waitingGraph ← TRUE;
ShowChart[handle]; -- will unlock handle.
}; -- ShowChartProc
LevelsProc: Menus.MenuProc = {
handle: GraphHandle ← HandleFromViewer[NARROW[parent]];
IF HandleNotNil[handle] THEN {
Lock[handle]; { OPEN handle;
numLines: Menus.MenuLine ← Menus.GetNumberOfLines[controller.menu];
SELECT numLines FROM
2 => numLines ← 3;
3 => numLines ← 2;
ENDCASE => ERROR;
ViewerBLT.ChangeNumberOfLines[controller.viewer, numLines];
IF NOT controller.tableNormalized THEN {
TiogaOps.Jump[controller.table, [TiogaOps.ViewerDoc[controller.table], -1]];
controller.tableNormalized ← TRUE;
};
}; Unlock[handle];
};
}; -- SwitchesProc
AutoDivisionsProc: Menus.MenuProc = {
handle: GraphHandle ← HandleFromViewer[NARROW[parent]];
proc: GraphProc = {SwitchAuto[handle, divisions]};
CallWithLock[handle, proc];
}; -- AutoDivisionsProc
AutoBoundsProc: Menus.MenuProc = {
handle: GraphHandle ← HandleFromViewer[NARROW[parent]];
proc: GraphProc = {SwitchAuto[handle, bounds]};
CallWithLock[handle, proc];
}; -- AutoBoundsProc
PrimXhairProc: Menus.MenuProc = {SwitchCaret[parent, primary, shift, control]};
SecXhairProc: Menus.MenuProc = {SwitchCaret[parent, secondary, shift, control]};
TextCaretProc: Menus.MenuProc = {SwitchCaret[parent, text, shift, control]};
SwitchCaret: PROC[parent: REF ANY, index: CaretIndex, shift, control: BOOL] = {
handle: GraphHandle ← HandleFromViewer[NARROW[parent]];
proc: GraphProc = {
IF shift THEN SwitchCaretBlinking[handle, index]
ELSE SwitchCaretVisibility[handle, index];
};
IF NOT control THEN CallWithLock[handle, proc];
}; -- SwitchCaret
SlopeProc: Menus.MenuProc = {
handle: GraphHandle ← HandleFromViewer[NARROW[parent]];
proc: GraphProc = { OPEN handle;
graph.showSlope ← ~graph.showSlope;
IF graph.showSlope # controller.slopeOn THEN FlipToggleOnPanel[handle, $Slope];
ViewerTools.SetContents[controller.slope,
IF controller.slopeOn THEN
GraphConvert.RopeOfSlope[graph.caret[primary].place, graph.caret[secondary].place]
ELSE NIL];
};
CallWithLock[handle, proc];
}; -- SlopeProc
TargetXProc: Menus.MenuProc = {
handle: GraphHandle ← HandleFromViewer[NARROW[parent]];
proc: GraphProc = {SwitchTarget[handle, x]};
CallWithLock[handle, proc];
}; -- TargetXProc
TargetYProc: Menus.MenuProc = {
handle: GraphHandle ← HandleFromViewer[NARROW[parent]];
proc: GraphProc = {SwitchTarget[handle, y]};
CallWithLock[handle, proc];
}; -- TargetYProc
GridXProc: Menus.MenuProc = {
handle: GraphHandle ← HandleFromViewer[NARROW[parent]];
proc: GraphProc = {SwitchGrid[handle, x]};
CallWithLock[handle, proc];
}; -- GridXProc
GridYProc: Menus.MenuProc = {
handle: GraphHandle ← HandleFromViewer[NARROW[parent]];
proc: GraphProc = {SwitchGrid[handle, y]};
CallWithLock[handle, proc];
}; -- GridYProc
FirstLevelOnlyProc: Menus.MenuProc = {
handle: GraphHandle ← HandleFromViewer[NARROW[parent]];
proc: GraphProc = {TiogaMenuOps.FirstLevelOnly[handle.controller.table]};
CallWithLock[handle, proc];
}; -- FirstLevelOnlyProc
MoreLevelsProc: Menus.MenuProc = {
handle: GraphHandle ← HandleFromViewer[NARROW[parent]];
proc: GraphProc = {TiogaMenuOps.MoreLevels[handle.controller.table]};
CallWithLock[handle, proc];
}; -- MoreLevelsProc
FewerLevelsProc: Menus.MenuProc = {
handle: GraphHandle ← HandleFromViewer[NARROW[parent]];
proc: GraphProc = {TiogaMenuOps.FewerLevels[handle.controller.table]};
CallWithLock[handle, proc];
}; -- FewerLevelsProc
AllLevelsProc: Menus.MenuProc = {
handle: GraphHandle ← HandleFromViewer[NARROW[parent]];
proc: GraphProc = {TiogaMenuOps.AllLevels[handle.controller.table]};
CallWithLock[handle, proc];
}; -- AllLevelsProc
ChartMenus: PUBLIC PROC [] RETURNS [menu: Menus.Menu] = {
menu ← Menus.CreateMenu[];
Menus.AppendMenuEntry
[menu, Menus.CreateEntry["DisplayMode", SetDisplayModeProc]];
Menus.AppendMenuEntry
[menu, Menus.CreateEntry["ColorMap", SetColorMapProc]];
Menus.AppendMenuEntry
[menu, Menus.CreateEntry["Cursor", SetCursorColorProc]];
Menus.AppendMenuEntry
[menu, Menus.CreateEntry["Background", SetBackgroundIndexProc]];
Menus.AppendMenuEntry
[menu, Menus.CreateEntry[name: "Get", proc: GetGraphProc, guarded: TRUE]];
Menus.AppendMenuEntry
[menu, Menus.CreateEntry["Store", PutGraphProc]];
Menus.AppendMenuEntry
[menu, Menus.CreateEntry["Interpress", InterpressProc]];
Menus.AppendMenuEntry
[menu, Menus.CreateEntry["Repaint", RepaintProc]];
Menus.AppendMenuEntry
[menu, Menus.CreateEntry["Controller", ShowControllerProc]];
}; -- ChartMenus
menuprocs
SetDisplayModeProc: Menus.MenuProc = {
[parent: REF, clientData: REF, mouseButton: MouseButton, shift, control: BOOL]
handle: GraphHandle ← HandleFromViewer[NARROW[parent]];
proc: GraphProc = { OPEN handle;
newColorMode: ColorMode = SELECT PopUpMenu.RequestSelection[
label: "Options",
choice: LIST["color", "black and white"],
default: 1] FROM
1 => color, 2 => bw, ENDCASE => colorMode;
changed: BOOL ← handle.colorMode # newColorMode;
colorMode ← newColorMode;
IF changed THEN { -- chart.viewer (parent) # nil
SetCursorForBackgroundIndex[backgroundIndex];
PaintAll[handle];
};
};
CallWithLock[handle, proc];
}; -- SetDisplayMode
SetColorMapProc: Menus.MenuProc = {
handle: GraphHandle ← HandleFromViewer[NARROW[parent]];
proc: GraphProc = { OPEN handle;
newColorMap: ColorMap = SELECT PopUpMenu.RequestSelection[
label: "Options",
choice: LIST["mine", "Cedar", "default", "default/replace"],
default: 1] FROM
1 => mine, 2 => cedar, 3 => default, 4 => replace, ENDCASE => colorMap;
SetCursorForBackgroundIndex[backgroundIndex];
IF colorMap # newColorMap THEN {
colorMap ← newColorMap;
SELECT newColorMap FROM
mine => UseMyColors[handle];
cedar => UseCedarColors[];
default => UseDefaultColors[];
replace => UseDefaultColors[handle];
ENDCASE;
};
};
CallWithLock[handle, proc];
}; -- SetColorMapProc
SetCursorColorProc: Menus.MenuProc = {
handle: GraphHandle ← HandleFromViewer[NARROW[parent]];
proc: GraphProc = { OPEN handle;
virtual: Terminal.Virtual ← Terminal.Current[];
SELECT PopUpMenu.RequestSelection[
label: "Options",
choice: LIST["black", "white"],
default: 1] FROM
1 => [] ← Terminal.SetColorCursorPresentation[virtual, onesAreBlack];
2 => [] ← Terminal.SetColorCursorPresentation[virtual, onesAreWhite];
ENDCASE => SetCursorForBackgroundIndex[backgroundIndex]; -- *
};
CallWithLock[handle, proc];
}; -- SetCursorColorProc
SetBackgroundIndexProc: Menus.MenuProc = {
handle: GraphHandle ← HandleFromViewer[NARROW[parent]];
proc: GraphProc = { OPEN handle;
newBkGndIndex: BackgroundIndex = SELECT PopUpMenu.RequestSelection[
label: "Options",
choice: LIST["white", "gray", "dark gray", "black"],
default: 1] FROM
1 => white,
2 => gray,
3 => darkGray,
4 => black,
ENDCASE => backgroundIndex;
IF backgroundIndex # newBkGndIndex THEN {
backgroundIndex ← newBkGndIndex;
SetCursorForBackgroundIndex[backgroundIndex];
PaintAll[handle];
};
};
CallWithLock[handle, proc];
}; -- SetBackgroundIndexProc
GetGraphProc: Menus.MenuProc = {
handle: GraphHandle ← HandleFromViewer[NARROW[parent]];
proc: GraphProc = { OPEN handle;
replace: BOOL;
SELECT PopUpMenu.RequestSelection[
label: "Options",
choice: LIST["merge", "discard existing data"],
default: 1] FROM
1 => replace ← FALSE, 2 => replace ← TRUE, ENDCASE => RETURN;
file, msg: ROPE;
[file, msg] ← FileFromSelection[];
IF msg = NIL THEN {
msg ← GetGraph[handle, file ! Error => {msg ← info; CONTINUE}];
IF msg = NIL THEN UseMyColors[handle];
};
IF msg # NIL THEN BlinkMsg[msg];
};
CallWithLock[handle, proc];
}; -- GetGraphProc
PutGraphProc: Menus.MenuProc = {
handle: GraphHandle ← HandleFromViewer[NARROW[parent]];
proc: GraphProc = { OPEN handle;
file, msg: ROPE;
[file, msg] ← FileFromSelection[];
IF msg = NIL THEN {
msg ← WriteGraphFile[handle.graph, ReplaceFileExt[file, "graph"]
! Error => {msg ← info; CONTINUE}];
};
IF msg # NIL THEN BlinkMsg[msg];
};
CallWithLock[handle, proc];
}; -- PutGraphProc
WriteGraphProc: Menus.MenuProc = {
handle: GraphHandle ← HandleFromViewer[NARROW[parent]];
IF HandleNotNil[handle] THEN {
file, msg: ROPE;
[file, msg] ← FileFromSelection[];
IF msg = NIL THEN {
Lock[handle];
WriteDataFile[handle.graph, file ! Error => msg ← info];
Unlock[handle];
}
ELSE BlinkMsg[msg];
};
}; -- WriteGraphProc
InterpressProc: Menus.MenuProc = {
handle: GraphHandle ← HandleFromViewer[NARROW[parent]];
proc: GraphProc = { OPEN handle;
printingColorMode, colorModeSave: ColorMode;
okToPrint: BOOLTRUE;
SELECT PopUpMenu.RequestSelection[
label: "Options",
choice: LIST["color", "black and white"],
default: 1] FROM
1 => printingColorMode ← color;
2 => printingColorMode ← bw;
ENDCASE => {
BlinkMsg["You must choose either color or black-and-white."];
okToPrint ← FALSE;
};
IF okToPrint THEN {
colorModeSave ← colorMode;
colorMode ← printingColorMode;
Print[handle];
colorMode ← colorModeSave;
};
};
CallWithLock[handle, proc];
}; -- InterpressProc
RepaintProc: Menus.MenuProc = {
handle: GraphHandle ← HandleFromViewer[NARROW[parent]];
proc: GraphProc = { OPEN handle;
SELECT PopUpMenu.RequestSelection[
label: "Options",
choice: LIST["paint", "clear and paint"],
default: 1] FROM
1 => handle.chart.autoRepaint ← TRUE;
2 => handle.chart.autoRepaint ← FALSE;
1 => PaintAll[handle, FALSE];
2 => PaintAll[handle, TRUE];
ENDCASE;
};
CallWithLock[handle, proc];
}; -- InterpressProc
ShowControllerProc: Menus.MenuProc = {
handle: GraphHandle ← HandleFromViewer[NARROW[parent]];
CallWithLock[handle, ShowController];
}; -- ShowControllerProc
}.
LOG.
SChen, create at October 9, 1985 6:41:19 pm PDT