[comp.windows.x] Cascading SimpleMenuWidgets

kit@EXPO.LCS.MIT.EDU (Chris D. Peterson) (05/30/90)

> I would like to know if it is possible to cascade several
> SimpleMenuWidgets.

Has anyone sucessfully done this?  I have yet to hear of a working
implementation. 

> I have tried to do this, but I am
> having some trouble with setting the translations for
> the cascaded menu.

The simple menu entries (sme<something>ObjectClass) are not widgets, but non
windowed objects.  As such they have no translation or event management of their
own.  This is one of the reasons I think that objects are a bad idea, they
detract from the nice modular design of Xt.  "Then why did you use them?", I
hear you cry...  My major goal behind the Simple Menu widget was to make it fast
to pop up and down.  I felt that if the menus felt sluggish then they would not
be used.  I think I was able to get the feel that I wanted, but unfortunately I
had to sacrafice some of the nice things Xt gives to all widgets.

Is there any way to implement cascading menus?  I cannot think of one, short of
whacking the Simple menu code.

						Chris D. Peterson     
						MIT X Consortium 

Net:	 kit@expo.lcs.mit.edu
Phone:   (617) 253 - 9608	
Address: MIT - Room NE43-213

grunwald@foobar.colorado.edu (Dirk Grunwald) (05/30/90)

CP> > I would like to know if it is possible to cascade several
CP> > SimpleMenuWidgets.
CP> 
CP> Has anyone sucessfully done this?  I have yet to hear of a working
CP> implementation. 
--

I have a simple implementation, but you're right, it's kind of gross.
I subclassed the simple menu widget to build the ``EzMenu'' widget and
I subclasses Sme to make ``EzME''.

The EzMenu widget actually constructs EzME's on the fly, using a menu
specified by a string (see example below). All ``callbacks'' are
implemented by action routines, because I was sick of maintaining two
diff interfaces to my code (action routines & callbacks).

The EzME object enforces one of two translations on the parent widget
(which had better be an EzMenu) -- one is used if you have a submenu
(i.e. cascaded) and one is used if you don't. Popups occur on the
normal Highlight action, and popdowns on Notify & LeaveWindow.

The code for all of this (sans example) is available via anon. ftp
from foobar.colorado.edu in pub/EzMenu.shar.Z. There's no magic in
making an EzMenu, you just XtCreateManageWidget -- the hard part is
the .menu resource specification, which provides the menu layout and
associated action. There's a little unorthogonality to the design,
e.g.  for submenus, the menu label is specified by the ``(menu
"<header>"...''  string, while for the top level menu, you must use
the ``label'' resource.

It works O.K, about as well as the menus in TWM -- the only added
functionality I'd like is to see is a ``hot spot'' that you have to
move into to cause a submenu to popup -- that & it'd be nice to have
the parsing for the actions to be done via the routines in Xt, but I
couldn't figure out a way to use them.

A sample menu specification used in xtex follows:

*.xtex-page*.menu.label: XTeX Menu
*.xtex-page*.menu*.RowHeight: 16
*.xtex-page*.menu.menu:\
	(line)\
	(item "Forward" (action "xtex-page-foreward()"))\
	(item "...10 pages" (action "xtex-page-number(1) xtex-page-number(0) xtex-page-foreward() xtex-page-number-reset()"))\
	(item "Backward" (action "xtex-page-backward()"))\
	(item "...10 pages" (action "xtex-page-number(1) xtex-page-number(0) xtex-page-backward() xtex-page-number-reset()"))\
	(item "Goto..." (action "xtex-page-goto-popup()"))\
	(blank)\
	(item "Overview" (action "xtex-page-magnify(small)"))\
	(item "Detail View" (action "xtex-page-magnify(large)"))\
	(blank)\
	(item "Mark" (action "xtex-mark-page(set)"))\
	(item "Unmark" (action "xtex-mark-page(clear)"))\
	(blank)\
	(item "Reopen" (action "xtex-file(reopen) xtex-page-number-reset()"))\
	(blank)\
	(menu "Print..." \
		(line)\
		(item "This Page" \
		   (action "xtex-mark-push() xtex-mark-page(set) xtex-print-using(set)  xtex-mark-pop()"))\
		(item "All Pages" (action "xtex-print-using(all)"))\
		(item "All Marked Pages" (action "xtex-print-using(set)"))\
		(item "All Unmarked Pages" (action "xtex-print-using(clear)"))\
	)\
	(blank)\
	(menu "Ruler Units..."\
		(line)\
		(item "Inches" (action "dvi-line-units(in)"))\
		(item "Points" (action "dvi-line-units(pt)"))\
		(item "Centimeters" (action "dvi-line-units(cm)"))\
		(item "Millimeters" (action "dvi-line-units(mm)"))\
		(item "Scaled Points" (action "dvi-line-units(sp)"))\
		(item "Picas" (action "dvi-line-units(pc)"))\
		(item "Big Points" (action "dvi-line-units(bp)"))\
		(item "Didot" (action "dvi-line-units(dd)"))\
		(item "Cicero" (action "dvi-line-units(cc)"))\
	)\
	(blank)\
	(item "Quit Page" (action "xtex-page-quit()"))\
	(item "Quit XTeX" (action "xtex-quit()"))

van@HELIOS.EE.LBL.GOV (Van Jacobson) (05/30/90)

I did a simple menu entry object that allows you to cascade
SimpleMenuWidgets.  It's call is essentially identical to SmeBSB
but requires one more argument, XtNmenu, that's the name of the
menu to be popped up when this entry is highlighted.  The code
is available for anonymous ftp from ftp.ee.lbl.gov
(128.3.254.68), file SmeMenu.tar.Z.  Attached is a copy of the
README from the tarchive.

 - Van

-----------------

README for Simple Menu Entry `Menu' object, SMEMenu.
Wed May 30 02:04:17 PDT 1990

This tar contains a new `simple menu' object for the Athena widget
set that allows hierarchical menus to be built.  There are four files:

	SmeMenu.c	the `menu' simple menu entry object

	SmeMenu.h	user visible definitions for above

	SmeMenuP.h	private definitions for above

	SimpleMenu.c	slightly modified simple menu widget.  main
			change was to make XawPositionSimpleMenu action
			externally visible (so user written programs
			could position menus) and re-implement it (without
			changing semantics) so its lower level routines
			could be used by SmeMenu to position a popped-up
			menu correctly.

Use
---
SmeMenu is almost identical to SmeBSB and takes all the same label,
bitmap, etc., arguments.  There are two args added:

	XtNmenu		is the name of the menu to be popped up when
			this menu entry is selected.  This must be the
			name of a SimpleMenu widget.  This argument must
			be supplied.

	XtNpopupSelection  is a boolean that, if true, causes the popped
			up menu to be positioned at the last selected
			entry.  If false (the default), the popped up
			menu is positioned at its label.

Bugs
----
Probably.  But there's only one that I know of:  The toolkit
event logic doesn't seem to handle modal cascades very well and
you will occasionally get the message

	"Warning: XtRemoveGrab asked to remove a widget not on the list"

in well defined circumstances that I won't attempt to describe
here.  This appears to me to be a toolkit bug but, rather than
embark on a major recoding effort to fix it, I just commented
the above warning out in Xt/Event.c:RemoteGrab.

 - Van Jacobson, van@helios.ee.lbl.gov
   Lawrence Berkeley Laboratory