WalnutDisplayerMenusImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Willie-Sue, May 28, 1985 4:57:32 pm PDT
Contents: Implementation of the menus for WalnutMsgSet displayers.
(Changed message set version number to be part of viewer information, rather than part of message set buttons)
(Changed to use TiogaButtons - May 6, 1985)
DIRECTORY
Menus USING [MouseButton, Menu, MenuEntry, MenuLine, MenuProc,
AppendMenuEntry, ChangeNumberOfLines, CreateMenu, CreateEntry, GetNumberOfLines, GetLine, SetLine],
Rope,
TiogaMenuOps USING [AllLevels, FewerLevels, FirstLevelOnly, MoreLevels, Normalize,
Position, PrevPlace],
TiogaOps USING [SearchDir, FindDef, FindText, FindWord],
ViewerBLT USING [ChangeNumberOfLines],
ViewerClasses USING [Viewer],
ViewerOps USING [BlinkIcon, FetchProp],
WalnutDisplayerInternal USING [MsgGvId],
WalnutMsgSetDisplayerPrivate USING [MsgSetInfo, MsgSetFieldHandle, MsgInfo,
AddProc, CategoriesProc, DeleteProc, DisplayProc, MoveToProc, NewMailProc,
PrintSelectedProc],
WalnutPrintOps USING [MsgSetPrintProc],
WalnutViewer USING [CreateMenuEntry],
WalnutWindowInternal USING [MsgSetButton, walnutQueue];
WalnutDisplayerMenusImpl: CEDAR PROGRAM
IMPORTS
Rope,
WalnutDisplayerInternal, WalnutMsgSetDisplayerPrivate,
WalnutPrintOps, WalnutViewer, WalnutWindowInternal,
Menus, TiogaMenuOps, TiogaOps,
ViewerBLT, ViewerOps
EXPORTS
WalnutMsgSetDisplayerPrivate
SHARES
Menus =
BEGIN OPEN WalnutMsgSetDisplayerPrivate;
Types
Viewer: TYPE = ViewerClasses.Viewer;
ROPE: TYPE = Rope.ROPE;
Menus used in message set displays
displayerMenu: PUBLIC Menus.Menu ← Menus.CreateMenu[];
activeMenu: PUBLIC Menus.Menu ← Menus.CreateMenu[];
deletedMenu: PUBLIC Menus.Menu ← Menus.CreateMenu[];
buildingMenu: PUBLIC Menus.Menu ← Menus.CreateMenu[];
readOnlyMenu: PUBLIC Menus.Menu ← Menus.CreateMenu[];
placesMenuEntry: Menus.MenuEntry;
levelsMenuEntry: Menus.MenuEntry;
opsMenuEntry: Menus.MenuEntry;
Error message
FindProc: Menus.MenuProc = {
msViewer: Viewer = NARROW[parent];
msI: MsgSetInfo = NARROW[ViewerOps.FetchProp[msViewer, $MsgSetInfo]];
IF ~TiogaOps.FindText[
viewer: msI.tiogaViewer,
whichDir: GetDirection[mouseButton],
which: feedback,
case: ~shift]
THEN ViewerOps.BlinkIcon[msViewer];
};
WordProc: Menus.MenuProc = {
msViewer: Viewer = NARROW[parent];
msI: MsgSetInfo = NARROW[ViewerOps.FetchProp[msViewer, $MsgSetInfo]];
IF ~TiogaOps.FindWord[
viewer: msI.tiogaViewer,
whichDir: GetDirection[mouseButton],
which: feedback,
case: ~shift]
THEN ViewerOps.BlinkIcon[msViewer];
};
DefProc: Menus.MenuProc = {
msViewer: Viewer = NARROW[parent];
msI: MsgSetInfo = NARROW[ViewerOps.FetchProp[msViewer, $MsgSetInfo]];
IF ~TiogaOps.FindDef[
viewer: msI.tiogaViewer,
whichDir: GetDirection[mouseButton],
which: feedback,
case: ~shift]
THEN ViewerOps.BlinkIcon[msViewer];
};
PositionProc: Menus.MenuProc = {
msViewer: Viewer = NARROW[parent];
msI: MsgSetInfo = NARROW[ViewerOps.FetchProp[msViewer, $MsgSetInfo]];
TiogaMenuOps.Position[msI.tiogaViewer];
};
NormalizeProc: Menus.MenuProc = {
msViewer: Viewer = NARROW[parent];
msI: MsgSetInfo = NARROW[ViewerOps.FetchProp[msViewer, $MsgSetInfo]];
TiogaMenuOps.Normalize[msI.tiogaViewer];
};
PrevPlaceProc: Menus.MenuProc = {
msViewer: Viewer = NARROW[parent];
msI: MsgSetInfo = NARROW[ViewerOps.FetchProp[msViewer, $MsgSetInfo]];
TiogaMenuOps.PrevPlace[msI.tiogaViewer];
};
FirstOnlyProc: Menus.MenuProc = {
msViewer: Viewer = NARROW[parent];
msI: MsgSetInfo = NARROW[ViewerOps.FetchProp[msViewer, $MsgSetInfo]];
TiogaMenuOps.FirstLevelOnly[msI.tiogaViewer];
};
MoreLevelsProc: Menus.MenuProc = {
msViewer: Viewer = NARROW[parent];
msI: MsgSetInfo = NARROW[ViewerOps.FetchProp[msViewer, $MsgSetInfo]];
TiogaMenuOps.MoreLevels[msI.tiogaViewer];
};
FewerLevelsProc: Menus.MenuProc = {
msViewer: Viewer = NARROW[parent];
msI: MsgSetInfo = NARROW[ViewerOps.FetchProp[msViewer, $MsgSetInfo]];
TiogaMenuOps.FewerLevels[msI.tiogaViewer];
};
AllLevelsProc: Menus.MenuProc = {
msViewer: Viewer = NARROW[parent];
msI: MsgSetInfo = NARROW[ViewerOps.FetchProp[msViewer, $MsgSetInfo]];
TiogaMenuOps.AllLevels[msI.tiogaViewer];
};
GVIDProc: Menus.MenuProc = {
msViewer: Viewer = NARROW[parent];
msI: MsgSetInfo = NARROW[ViewerOps.FetchProp[msViewer, $MsgSetInfo]];
selected: MsgSetFieldHandle = msI.selected;
IF selected = NIL THEN RETURN;
WalnutDisplayerInternal.MsgGvId[selected.msgInfo.msg, mouseButton#red];
};
LevelsProc: Menus.MenuProc = { ChangeMenu[NARROW[parent], levelsMenuEntry] };
OpsProc: Menus.MenuProc = { ChangeMenu[NARROW[parent], opsMenuEntry] };
PlacesProc: Menus.MenuProc = { ChangeMenu[NARROW[parent], placesMenuEntry] };
GetDirection: PROC[mb: Menus.MouseButton] RETURNS[sd: TiogaOps.SearchDir] = {
SELECT mb FROM
red => RETURN[forwards];
yellow => RETURN[anywhere];
blue => RETURN[backwards];
ENDCASE;
};
Getting the menu changed
ChangeMenu: PROC [viewer: ViewerClasses.Viewer, subMenu: Menus.MenuEntry] = {
menu: Menus.Menu = viewer.menu;
found: BOOLFALSE;
numLines: Menus.MenuLine = Menus.GetNumberOfLines[menu];
newLines: Menus.MenuLine ← numLines;
FOR i: Menus.MenuLine IN [1..numLines) DO -- see if already showing the submenu
IF Rope.Equal[Menus.GetLine[menu,i].name, subMenu.name] THEN { -- yes, so remove it
FOR j: Menus.MenuLine IN (i..numLines) DO
Menus.SetLine[menu, j-1, Menus.GetLine[menu, j]];
ENDLOOP;
Menus.ChangeNumberOfLines[menu, newLast-1];
newLines ← newLines-1;
found ← TRUE; EXIT
};
ENDLOOP;
IF ~found THEN { -- add it. do insertion sort to get it in the right place
GoesBefore: PROC [m1, m2: Menus.MenuEntry] RETURNS [BOOL] = {
Priority: PROC [m: Menus.MenuEntry] RETURNS [INTEGER] = {
higher priority means goes above in series of submenus
looks at rope for first item to identify the subMenu.
RETURN [SELECT TRUE FROM
Rope.Equal[m.name, "Find"] => 2,
Rope.Equal[m.name, "FirstLevelOnly"] => 1,
Rope.Equal[m.name, "Categories"] => 0,
ENDCASE => -1 -- unknown menu goes at bottom -- ]
};
RETURN [Priority[m1] > Priority[m2]]
};
newLast: Menus.MenuLine = MIN[numLines, LAST[Menus.MenuLine]];
newLines ← newLines+1;
Menus.ChangeNumberOfLines[menu, newLast+1];
FOR i: Menus.MenuLine IN [1..numLines) DO
IF GoesBefore[subMenu, Menus.GetLine[menu, i]] THEN { -- put it here
FOR j: Menus.MenuLine DECREASING IN (i..newLast] DO
Menus.SetLine[menu, j, Menus.GetLine[menu, j-1]]; ENDLOOP;
Menus.SetLine[menu, i, subMenu];
found ← TRUE; EXIT
};
ENDLOOP;
IF ~found THEN Menus.SetLine[menu, newLast, subMenu];
};
ViewerOps.EstablishViewerPosition[viewer, viewer.wx, viewer.wy, viewer.ww, viewer.wh];
ViewerOps.PaintViewer[viewer, all];
ViewerBLT.ChangeNumberOfLines[viewer, newLines];
};
* * * * * * * * * * * * * * * * * * * * * *
BuildDisplayerMenus: PROC =
BEGIN OPEN WalnutWindowInternal;
Menu for generic Displayer
Menus.AppendMenuEntry[displayerMenu,
WalnutViewer.CreateMenuEntry[walnutQueue, "MoveTo", MoveToProc]];
Menus.AppendMenuEntry[displayerMenu,
WalnutViewer.CreateMenuEntry[walnutQueue, "Display", DisplayProc]];
Menus.AppendMenuEntry[displayerMenu,
WalnutViewer.CreateMenuEntry[walnutQueue, "Delete", DeleteProc]];
Menus.AppendMenuEntry[displayerMenu,
WalnutViewer.CreateMenuEntry[walnutQueue, "AddTo", AddProc]];
Menus.AppendMenuEntry[displayerMenu, Menus.CreateEntry["Places", PlacesProc]];
Menus.AppendMenuEntry[displayerMenu, Menus.CreateEntry["Levels", LevelsProc]];
Menus.AppendMenuEntry[displayerMenu, Menus.CreateEntry["MsgOps", OpsProc]];
second line
Menus.AppendMenuEntry[displayerMenu,
WalnutViewer.CreateMenuEntry[walnutQueue, "Find", FindProc], 1];
Menus.AppendMenuEntry[displayerMenu,
WalnutViewer.CreateMenuEntry[walnutQueue, "Word", WordProc], 1];
Menus.AppendMenuEntry[displayerMenu,
WalnutViewer.CreateMenuEntry[walnutQueue, "Def", DefProc], 1];
Menus.AppendMenuEntry[displayerMenu,
WalnutViewer.CreateMenuEntry[walnutQueue, "Position", PositionProc], 1];
Menus.AppendMenuEntry[displayerMenu,
WalnutViewer.CreateMenuEntry[walnutQueue, "Normalize", NormalizeProc], 1];
Menus.AppendMenuEntry[displayerMenu,
WalnutViewer.CreateMenuEntry[walnutQueue, "PrevPlace", PrevPlaceProc], 1];
placesMenuEntry ← Menus.GetLine[displayerMenu, 1];
third line
Menus.AppendMenuEntry[displayerMenu,
WalnutViewer.CreateMenuEntry[walnutQueue, "FirstLevelOnly", FirstOnlyProc], 2];
Menus.AppendMenuEntry[displayerMenu,
WalnutViewer.CreateMenuEntry[walnutQueue, "MoreLevels", MoreLevelsProc], 2];
Menus.AppendMenuEntry[displayerMenu,
WalnutViewer.CreateMenuEntry[walnutQueue, "FewerLevels", FewerLevelsProc], 2];
Menus.AppendMenuEntry[displayerMenu,
WalnutViewer.CreateMenuEntry[walnutQueue, "AllLevels", AllLevelsProc], 2];
levelsMenuEntry ← Menus.GetLine[displayerMenu, 2];
fourth line
Menus.AppendMenuEntry[displayerMenu,
WalnutViewer.CreateMenuEntry[walnutQueue, "Categories", CategoriesProc], 3];
Menus.AppendMenuEntry[displayerMenu,
WalnutViewer.CreateMenuEntry[q: walnutQueue, name: "Print",
proc: WalnutPrintOps.MsgSetPrintProc, guarded: TRUE], 3];
Menus.AppendMenuEntry[displayerMenu,
WalnutViewer.CreateMenuEntry[walnutQueue, "PrintSel", PrintSelectedProc], 3];
Menus.AppendMenuEntry[displayerMenu,
WalnutViewer.CreateMenuEntry[walnutQueue, "gvID", GVIDProc], 3];
opsMenuEntry ← Menus.GetLine[displayerMenu, 3];
Menus.ChangeNumberOfLines[displayerMenu, 1];
Menu for Active
Menus.AppendMenuEntry[activeMenu,
WalnutViewer.CreateMenuEntry[walnutQueue, "MoveTo", MoveToProc]];
Menus.AppendMenuEntry[activeMenu,
WalnutViewer.CreateMenuEntry[walnutQueue, "Display", DisplayProc]];
Menus.AppendMenuEntry[activeMenu,
WalnutViewer.CreateMenuEntry[walnutQueue, "Delete", DeleteProc]];
Menus.AppendMenuEntry[activeMenu,
WalnutViewer.CreateMenuEntry[walnutQueue, "AddTo", AddProc]];
Menus.AppendMenuEntry[activeMenu,
Menus.CreateEntry["NewMail", NewMailProc]];  -- "immediate"
Menus.AppendMenuEntry[activeMenu, Menus.CreateEntry["Places", PlacesProc]];
Menus.AppendMenuEntry[activeMenu, Menus.CreateEntry["Levels", LevelsProc]];
Menus.AppendMenuEntry[activeMenu, Menus.CreateEntry["MsgOps", OpsProc]];
second line
Menus.SetLine[activeMenu, 1, placesMenuEntry];
third line
Menus.SetLine[activeMenu, 2, levelsMenuEntry];
fourth line
Menus.SetLine[activeMenu, 3, opsMenuEntry];
Menus.ChangeNumberOfLines[activeMenu, 1];
Menu for Deleted
Menus.AppendMenuEntry[deletedMenu,
WalnutViewer.CreateMenuEntry[walnutQueue, "MoveTo", MoveToProc]];
Menus.AppendMenuEntry[deletedMenu,
WalnutViewer.CreateMenuEntry[walnutQueue, "Display", DisplayProc]];
Menus.AppendMenuEntry[deletedMenu, Menus.CreateEntry["Places", PlacesProc]];
Menus.AppendMenuEntry[deletedMenu, Menus.CreateEntry["Levels", LevelsProc]];
Menus.AppendMenuEntry[deletedMenu, Menus.CreateEntry["MsgOps", OpsProc]];
second line
Menus.SetLine[deletedMenu, 1, placesMenuEntry];
third line
Menus.SetLine[deletedMenu, 2, levelsMenuEntry];
fourth line
Menus.SetLine[deletedMenu, 2, levelsMenuEntry];
Menus.ChangeNumberOfLines[deletedMenu, 1];
Menu for ReadOnly database
Menus.AppendMenuEntry[readOnlyMenu,
WalnutViewer.CreateMenuEntry[walnutQueue, "Display", DisplayProc]];
Menus.AppendMenuEntry[readOnlyMenu, Menus.CreateEntry["Places", PlacesProc]];
Menus.AppendMenuEntry[readOnlyMenu, Menus.CreateEntry["Levels", LevelsProc]];
Menus.AppendMenuEntry[readOnlyMenu, Menus.CreateEntry["MsgOps", OpsProc]];
second line
Menus.SetLine[readOnlyMenu, 1, placesMenuEntry];
third line
Menus.SetLine[readOnlyMenu, 2, levelsMenuEntry];
fourth line
Menus.SetLine[readOnlyMenu, 2, levelsMenuEntry];
Menus.ChangeNumberOfLines[readOnlyMenu, 1];
END;
* * * * * * * * * * * * * * * * * * * * * * * * *
start code
BuildDisplayerMenus[];
END.