[comp.windows.x] POPUP menu issue continue ...

yhuang@nile.ics.hawaii.EDU (Ye Huang) (06/27/91)

Hello,  David

Thanks for your replies. The first problem solved for poping up the menu.

The second one remains for which I could not popup different menus by 
depressing different buttons(Button1, Button2, and Button3). I only can
get one by btn3.

As I outlined I used the PostPopupMenu() for button events within the drawarea
to switch to  the corresponding XtManageChild(PopupMenu?) like :

PopUpMenu() {
   switch(event->button) {
        case Button3: PostMenu3; break;
        case Button2: PostMenu2; break;
        case Button1: PostMenu1; break;
        default: printf("Not available \n");
   }
}

It seems not the reason that .mwmrc has the conflict button binding as those 
are for root window. Also, in it there is binding for button3down. So, that is
seemingly not the cause.

I narrowed down the problem now futher. I put the printf in the case button2, 
and it is printed. So that shows the button2 event is trapped, but not posted.

Another thing I do not understand is that when I switch the popup3 to 1, that 
is no longer been poped up. but again the print message is shown. SO ONLY 
BUTTON3 is working.  

I think you may be right someway. How you would do if you are to realize
the same functions? Any suggestions?  I am going to try the translation 
table to do it now. But I thought my original way is reasonable.

Thanks. If you have any idea, plz do let me know!

-- Thomas 



One

E_CMA@vaxa.nerc-murchison.ac.uk (06/28/91)

> The second one remains for which I could not popup different menus by
> depressing different buttons(Button1, Button2, and Button3). I only can
> get one by btn3.

You would appear to be missing a few bits of code. Your event loop picks 
up the generic keypress events but only recognises Button3 events as
relevant to popup menus. (See the documentation for the attributes of
XmRowColumn.) To override this you must set the XmNwhichButton resource
for the menus you attach to each mouse button....

In main()
...setting XmNwhichButton  for each menu... (if you are using
 XmCreatePopupMenu, put these in the argument lists)

    XtSetArg(wargs[0], XmNwhichButton, Button1);
    XtSetValues(menu_1,wargs,1);

    XtSetArg(wargs[0], XmNwhichButton, Button2);
    XtSetValues(menu_2,wargs,1);

    XtSetArg(wargs[0], XmNwhichButton, Button3); 
    XtSetValues(menu_3,wargs,1);   

Alternatively, you can set the XmNwhichButton resource in the UIL
file if you use one,  where your popup menus are defined as unmanaged 
children of your drawing area widget. I prefer that method myself.
Button3 is the default button for popups, which is why that works already.
 
    /*
     * set up event handlers for each of the popup menus
     * insert these just before your event loop
     */
    XtAddEventHandler(host_widget,     /* = widget within which 
                                          the event is recognised*/
                      ButtonPressMask, 
                      False,
                      post_menu,
                      menu_1);  

 /* then do the same for menu_2 and menu_3... */

   XtAddEventHandler(host_widget,     
                     ButtonPressMask, 
                     False,
                     post_menu,
                     menu_2);  

   XtAddEventHandler(host_widget, 
                     ButtonPressMask, 
                     False,
                     post_menu,
                     menu_3);  
 ...

/*
 * --------------------------------------------------------------------------
 * post_menu ()
 *
 * c.f.from Young p97  make popup menu appear at sprite position
 * --------------------------------------------------------------------------
 */
void post_menu (Widget w, Widget menu, XEvent *event)
 {
  Arg wargs[10];
  int button;

   XtSetArg(wargs[0], XmNwhichButton, &button);
   XtGetValues(menu, wargs, 1);

   if(event->xbutton.button == button)
   {
        XmMenuPosition(menu,event);
        XtManageChild(menu);
   }
 }
/*
 * === End of post_menu_handler =========================================
 */

I hope the above will be of help

 Cheers
    Carolyn Allen

*************************************************************************
* Snailmail:		    *  E_Mail	                                *
*			    *  CBS%UK.AC.NERC-MURCHISON.VAXA::E_CMA     *	
* Dr C.M.Allen		    *  JANET: e_cma@uk.ac.nmh.va                *
* British Geological Survey *                                           *
* Murchison House           * 	                                        *
* West Mains Road           **                                          *
*                           *                                           *
* Edinburgh                 * Tel: 031-667-1000 x277 from U.K.		*
* Scotland                  * 						*
* EH9,3LA                   * 						*
*************************************************************************