Path: utzoo!utgpu!water!watmath!clyde!att!rutgers!rochester!cornell!batcomputer!itsgw!steinmetz!nepal!laymon
From: laymon@nepal.steinmetz (Marc A Laymon)
Newsgroups: comp.windows.x
Subject: changing menu widget behavior
Message-ID: <11393@steinmetz.ge.com>
Date: 27 Jun 88 22:30:42 GMT
Sender: news@steinmetz.ge.com
Reply-To: laymon@nepal.steinmetz.ge.com ()
Distribution: na
Organization: General Electric CRD, Schenectady, NY
Lines: 81


I want to create a popup menu which acts like a SunView menu, i.e. active while right 
button is down, select on right button up.  I have been using the (??HP??) menu widget,
which has the default behavior of active with all buttons up and select when the left 
button is pressed and released.  I tried to change the behavior to what I want using 
XtParseTranslationTable and XtOverrideTranslations but this did not to work.  I have 
created my own graphic widget which pops up my menu when the right button is pressed
and unpops it when the right button is released.  However, this causes the widget 
(== window) to be redrawn, losing the contents, even though I have SaveUnder set to 
true for my popup shell and menu widget.  Losing the widget contents also happens if I 
resize the outermost window.  (I am using TWM.)  I would like to be able to save and 
restore the random contents of my graphic window, but can't seem to find such functions 
in the X documentation.  I tried using XCreatePixMap and XCopyArea, but I am not sure
what the arguments for XCopyArea should be.  A PixMap for the source and the window for
the destination ?

Can anyone tell me how to get the behavior I want ?  My code to create the popup menu 
is shown below.  Thanks in advance.

/*******************************************************************
*/
void create_popup_menu ()
{
    extern XtTranslations XtParseTranslationTable () ;

    XtTranslations    new_translation ;

    Arg    widget_args[10];

    static MenuItemsList menu_list[] = 
    {
	{"COMPLETE", command1_callback, (caddr_t) 0, 0},
	{"SPAWN", spawn_graphics_window, (caddr_t) 0, 0},
	{"EXIT", quit_callback, (caddr_t) 0, 0},
	{NULL, NULL, NULL, NULL}
    } ;

    static Arg menu_list_args[] = 
    {
        {XtNmenuItemsList, (XtArgVal) menu_list }
    } ;

    static char my_default_translations[] =
	"Button3:    highlight() \n\
	 Button3:    unhighlight() \n\
	 :                notify()" ;

    static XtActionsRec actionsList[] =
    {
        {"highlight", MyHighlight},
        {"unhighlight", MyUnhighlight},
        {"notify", MyNotify}   
    } ;

    g_menu_popup = XtCreatePopupShell ("demo menu",
				    shellWidgetClass,
				    g_toplevel,
				    NULL, 0);
    XtSetArg (widget_args[0], XtNsaveUnder, 1) ;
    XtSetValues (g_menu_popup, widget_args, ONE) ;

    g_my_menu = XtCreateManagedWidget ("mylist",
				    menuWidgetClass,
				    g_menu_popup,
				    (ArgList) menu_list_args,
				    XtNumber (menu_list_args));

    new_translation = XtParseTranslationTable (my_default_translations) ;
    XtSetArg (widget_args[0], XtNsaveUnder, 1) ;
    XtSetValues (g_my_menu, widget_args, ONE) ;

    XtOverrideTranslations (g_my_menu, new_translation) ;
    g_my_menu->core.widget_class->core_class.actions = actionsList ;
    g_my_menu->core.widget_class->core_class.num_actions = XtNumber (actionsList) ;

}   /* end CREATE_POPUP_MENU */


 Marc Laymon			ARPANET: laymon@nepal.steinmetz.ge.com
 GE Corp. R&D			USENET:  steinmetz!nepal!laymon
 Schenectady, NY