[comp.windows.x] Athena SimpleMenu Widget

nancie@hal.CSS.GOV (Nancie Matson) (05/03/90)

I am trying to use the Athena SimpleMenu Widget to create a
popup menu inside a viewport widget.  According to the
X11R4 documentation in order to position the widget I need
to add XawPositionSimpleMenuWidget to the translation table
of the widget that will do the popping up of the menu.
When I try this, the menu never appears.  Also, I have
written a set of callbacks for each entry in the menu, but
each time I try to select an entry nothing happens (the
menu just get's popped down).

I would like to find out if anyone has some sample code for
using the SimpleMenu widget as a popup.  I have examples that
use the MenuButton, but I haven't had much luck with them.

Also, I have tried to set numerous resources for the wiget
including foreground  color for the entries, but It doesn't
seem to be working.  Any ideas?

-------------------------------------------------------------------
Here is the code for generating the Widget:

    menu = XtCreatePopupShell("menu",simpleMenuWidgetClass,viewport,
		               NULL,0);
    for (i=0; i<NUM_MENU_ITEMS; i++)
    {
       item = menu_entries[i];
       entry = XtCreateManagedWidget(item,smeBSBObjectClass,
		      		     menu,NULL,0);
       XtAddCallback(entry,XtNcallback,MenuSelect,(caddr_t) i);
    }
    XtAddActions(MenuActs,XtNumber(MenuActs));

    void MenuSelect(w,pane_num,call_data)
    Widget  w;
    int     pane_num;
    caddr_t call_data;
    {
       Arg      arglist[1];
       Cardinal num_args = 0;
 
       if (pane_num == 0)
          ChangeColorMap(&map);
       else if (pane_num == 2)
       {
          XtDestroyWidget (toplevel);
          exit(0);
       }
       menu_stat[pane_num] = !menu_stat[pane_num];
       return;
    }  

RESOURCES:
NmrdMap*form*viewport.translations:\
	<BtnDown>:	XawPositionSimpleMenu(menu)
NmrdMap*menu*label:			Main Menu
NmrdMap*form*viewport*menuLabel*foreground:	Red
NmrdMap*form*viewport*menu*foreground:		Red
NmrdMap*form*viewport*menu*background:		White
NmrdMap*menu*geometry:			100x135
NmrdMap*form*viewport*menu*rowHeight:		25
NmrdMap*form*viewport*menu*borderColor:		PaleGrey
NmrdMap*form*viewport*menu*borderWidth:		3
NmrdMap*form*viewport*menu*cursor:		sb_right_arrow
NmrdMap*form*viewport*menu*menuOnScreen:	True

----------------------------------------------------------------
Currently, label,geometry,borderColor,borderWidth,cursor and 
MenuOnScreen work, but the others don't.

Thanx for any help!

Nancie Matson
Ensco, Inc.

converse@EXPO.LCS.MIT.EDU (Donna Converse) (05/04/90)

> I am trying to use the Athena SimpleMenu Widget to create a
> popup menu inside a viewport widget.  According to the
> X11R4 documentation in order to position the widget I need
> to add XawPositionSimpleMenuWidget to the translation table
> of the widget that will do the popping up of the menu.
> When I try this, the menu never appears.

> NmrdMap*form*viewport.translations:\
> 	<BtnDown>:	XawPositionSimpleMenu(menu)

You need to call MenuPopup in this translation.  There is an example
of this in section 4.2.3 of the Athena documentation.  

A related issue is whether any children of the viewport are interested
in button down events -- if they are, and you have a translation like
the one above, the children will no longer see button down events.

> Also, I have
> written a set of callbacks for each entry in the menu, but
> each time I try to select an entry nothing happens (the
> menu just get's popped down).

Your code fragments look okay, except I don't know what you mischief you
are doing with XtAddActions after you create the menus. 

Technically, the client_data is an XtPointer type, which you should cast
to an int.

> I would like to find out if anyone has some sample code for
> using the SimpleMenu widget as a popup.  I have examples that
> use the MenuButton, but I haven't had much luck with them.

The command menus of xmh can be accessed as popup menus.  They aren't,
by default, provided as popups, because it is a difficult interaction
technique for xmh users, and because the CommandButtonCount
resource provides a better alternative to pull-down menus and accelerators.

There are some sample translations in clients/xmh/Xmh.sample you can toy 
with to invoke them as popups.  Menus are built the same way whether they
are to be used as pull-downs or popups, or both; xmh can use them both ways.
Using popup menus, you have to consider what widget will be the menu's parent,
and what default translations to provide for popping up the menu.
You're doing fine.

> Also, I have tried to set numerous resources for the wiget
> including foreground  color for the entries, but It doesn't
> seem to be working.  Any ideas?

> NmrdMap*menu*label:			Main Menu

Don't you want this to be menu.label?

> NmrdMap*form*viewport*menuLabel*foreground:	Red
> NmrdMap*form*viewport*menu*foreground:		Red
> NmrdMap*form*viewport*menu*background:		White
> NmrdMap*menu*geometry:			100x135
> NmrdMap*form*viewport*menu*rowHeight:		25
> NmrdMap*form*viewport*menu*borderColor:		PaleGrey
> NmrdMap*form*viewport*menu*borderWidth:		3
> NmrdMap*form*viewport*menu*cursor:		sb_right_arrow
> NmrdMap*form*viewport*menu*menuOnScreen:	True
> 
> ----------------------------------------------------------------
> Currently, label,geometry,borderColor,borderWidth,cursor and 
> MenuOnScreen work, but the others don't.

I can't explain why your colors aren't working.  Unless red and white
can't be found or created in the colormap.


Donna Converse
converse@expo.lcs.mit.edu