DIRECTORY Process USING [Milliseconds], Rope USING [ROPE]; Menus: CEDAR DEFINITIONS = BEGIN Menu: TYPE = REF MenuRec; MenuEntry: TYPE = REF MenuEntryRec; MenuLine: TYPE = [0..5); CreateMenu: PROC [lines: MenuLine _ 1] RETURNS [menu: Menu] = INLINE {RETURN[NEW[MenuRec _ [linesUsed: lines]]]} ; CopyMenu: PROC [old: Menu] RETURNS [new: Menu] ; MouseButton: TYPE = { red, yellow, blue } ; ClickProc, MenuProc: TYPE = PROC [parent: REF ANY, clientData: REF ANY _ NIL, mouseButton: MouseButton _ red, shift, control: BOOL _ FALSE] ; CreateEntry: PROC [name: Rope.ROPE, proc: ClickProc, clientData: REF ANY _ NIL, documentation: REF ANY _ NIL, fork: BOOL _ TRUE, guarded: BOOL _ FALSE] RETURNS [entry: MenuEntry] ; CopyEntry: PROC [oldEntry: MenuEntry] RETURNS [newEntry: MenuEntry] = INLINE {RETURN[NEW[MenuEntryRec _ oldEntry^]]} ; SetGuarded: PROC [entry: MenuEntry, guard: BOOL] = INLINE {entry.guarded _ guard; entry.guardState _ IF guard THEN guarded ELSE armed} ; SetClientData: PROC [entry: MenuEntry, newData: REF ANY] RETURNS [oldData: REF ANY] = INLINE {oldData _ entry.clientData; entry.clientData _ newData} ; SetDocumentation: PROC [entry: MenuEntry, newDoc: REF ANY] RETURNS [oldDoc: REF ANY] = INLINE {oldDoc _ entry.documentation; entry.documentation _ newDoc} ; FindEntry: PROC [menu: Menu, entryName: Rope.ROPE] RETURNS [entry: MenuEntry] ; AppendMenuEntry: PROC [menu: Menu, entry: MenuEntry, line: MenuLine _ 0] ; InsertMenuEntry: PROC [menu: Menu, entry: MenuEntry, line: MenuLine _ 0] ; ReplaceMenuEntry: PROC [menu: Menu, oldEntry: MenuEntry, newEntry: MenuEntry _ NIL] ; targetNotFound: SIGNAL ; ChangeNumberOfLines: PROC [menu: Menu, newLines: MenuLine] = INLINE {menu.linesUsed _ newLines} ; GetNumberOfLines: PROC [menu: Menu] RETURNS [lines: MenuLine] = INLINE {RETURN[menu.linesUsed]} ; SetLine: PROC [menu: Menu, line: MenuLine, entryList: MenuEntry] = INLINE {menu.lines[line] _ entryList; menu.linesUsed _ MAX[menu.linesUsed, line+1]} ; GetLine: PROC [menu: Menu, line: MenuLine] RETURNS [entryList: MenuEntry] = INLINE {RETURN[menu.lines[line]]} ; MenuRec: TYPE = PRIVATE RECORD [ lines: ARRAY MenuLine OF MenuEntry _ ALL[NIL], x, y: INTEGER _ 0, linesUsed: MenuLine _ 1, lineInverted: MenuLine _ 0, inverted: MenuEntry _ NIL ]; MenuEntryRec: TYPE = PRIVATE MONITORED RECORD [ -- 15 words link: MenuEntry _ NIL, name: Rope.ROPE, proc: ClickProc, width: INTEGER _ 0, xPos: INTEGER _ 0, clientData: REF ANY _ NIL, documentation: REF ANY _ NIL, fork: BOOL _ TRUE, greyed: BOOL _ FALSE, guarded: BOOL _ FALSE, guardState: GuardState _ armed ]; GuardState: TYPE = { guarded, arming, armed }; armingTime: Process.Milliseconds = 100; -- cover removal time. armedTime: Process.Milliseconds = 5000; -- unguarded interval. END. XMenus.mesa; Written by S. McGregor Last Edited by: McGregor, July 13, 1983 10:57 am Last Edited by: Maxwell, December 17, 1982 9:58 am Menus are the "button-like" commands displayed across the top of a viewer. A MenuEntry is an individual item in a menu Creating menus Create a new menu with some number of lines of entries Copy a menu and all of its entries Menu and Button notifications Mouse buttons from left to right For menus, the parent field will contain the parent Viewer; for buttons, parent will be the button Viewer itself. Use NARROW to convert a REF ANY to a Viewer. mouseButton indicates how the user invoked the button or menu. shift and control indicate the state of the shift and control keys when the menu or button was invoked. Operations on MenuEntries Create an item that can be added to a menu. 'name' is the text that will be displayed to the user, 'proc' is the procedure that will get called when the user invokes the menu, 'clientData' is arbitray data that will be passed to the proc, 'documentation' may either be a Rope.ROPE or a REF ClickProc and will either be displayed in the message window or called respectively when a guarded entry has its cover removed. 'fork' will FORK and Detach a separate process when the proc is called, 'guarded' menu items have a diagonal cross-hatch pattern over the text that is removed when the user clicks at the menu item. Only if the user clicks at a guarded menu item while the 'cover' is off will the proc be called. Operations on Menus Search for an entry given the name. Will return NIL if target name not found. Add a new menu entry to the end of a line Add a new menu entry to the front of a line Change an existing entry in a menu. If newEntry is NIL then the oldEntry will be deleted. Will raise targetNotFound if target entry not found. Menu private stuff below; no user seviceable parts ΚΑ– "cedar" style˜JšΟc"™"Jšœ!™0Jšœ2™2J™šΟk ˜ Jšœžœ˜Jšœžœžœ˜J˜—Jšœžœž˜ J˜J˜JšJ™JJšœžœžœ ˜J˜Jš+™+Jšœ žœžœ˜#J˜J˜Jš™J˜Jšœ žœ ˜J˜šΟn œžœžœž˜DJšœžœžœ"˜-Jš6™6J˜—šŸœžœ žœ˜0Jš"™"J˜J˜—Jš™J˜šœ žœ˜+Jš ™ J˜—šŸ œŸœžœžœ žœžœžœžœžœ˜MJšœ0žœžœ˜?JšΘ™ΘJ˜J˜—Jš™J˜š Ÿ œžœ žœžœžœžœ˜OJšœžœžœžœžœžœ žœžœ˜GJšžœ˜JšΛ™ΛJ˜—šŸ œžœžœ˜EJšžœžœžœ˜0J˜—šŸ œžœžœ˜2Jšžœ,žœžœ žœ ˜UJ˜—šŸ œžœžœžœžœ žœžœ˜UJšžœ;˜AJ˜—šŸœžœžœžœžœ žœžœ˜VJšžœ?˜EJ˜J˜—Jš™J˜šŸ œžœžœžœ˜OJšN™NJ˜—šŸœžœ5˜JJš)™)J˜—šŸœžœ5˜JJš+™+J˜—šŸœžœ9žœ˜UJšZ™ZJš4™4Jšœžœ˜J˜—šŸœžœ#˜Jšœ(˜>J˜Jšžœ˜J˜J˜—…— δύ