[comp.windows.x] Help on XtUnrealize !

gteo@swift.cs.tcd.ie (03/09/91)

Hello,
	I have this little test program which really annoys me. I used 
Motif (1.0A).
The program shows one application shell widget witha push button on it. Pressing
the push button causes another shell widget to appear. Everything behave 
properly at this stage. Click on the PB1 again causes the second shell widget
to disappear from the screen. Click on PB1 again, the second shell widget
reappears on screen, now PB2 does not response to button press or any such 
thing at all. I run the program on a DECStation 3100 with Ultrix Work 
System 4.0.
	Has anyone come across similar problem would like to help me out of
this one, please.

Thank you very much,

Ghee Teo.


/******************************************************************************
 * File: testrzl.c
 * Purpose: To test XtRealizeWidget and XtUnrealizeWidget 
 *
 * Date: 6/3/91
 *****************************************************************************/

#include <stdio.h>
#include <Xm/Xm.h>
#include <X11/Shell.h>
#include <Xm/PushB.h>

static Widget view1, view2, pb1, pb2;

showit(w, client_data, call_data)
Widget w;
caddr_t client_data;
XmAnyCallbackStruct *call_data;
{
static i=0;
	if (i%2==0) {
	XtRealizeWidget(view2);
	}
	else {
	XtUnrealizeWidget(view2);
	}
	i++;
}

exithere(w, client_data, call_data)
Widget w;
caddr_t client_data;
XmAnyCallbackStruct *call_data;
{
	printf("Good Bye\n");
	exit(0);
}

/*
 *  Main program
 */
int main(argc, argv)
int argc;
char **argv;
{
     /*
     *  Declare the variables to contain the two widget ids
     */
    Arg arglist[10] ;
    Cardinal i;
    Display *dpy;
    XtAppContext app;

     /*  Initialize the toolkit.  This call returns the id of the "toplevel"
     *  widget. 
     */

    printf("Calling XtInitilize\n");
    XtToolkitInitialize();
    app = XtCreateApplicationContext();
    dpy = XtOpenDisplay(app, "", argv[0], "testrzl", NULL, 0, &argc, argv);
    view1 = XtAppCreateShell(app, "VIEW1", applicationShellWidgetClass, dpy, NULL,0);
    view2 = XtAppCreateShell(app, "VIEW2", shellWidgetClass, dpy, NULL,0);
    i=0;
    XtSetArg(arglist[i], XmNlabelString, XmStringCreate("PB1", XmSTRING_DEFAULT_CHARSET)); i++;
    XtSetArg(arglist[i], XmNwidth, 100); i++;
    XtSetArg(arglist[i], XmNheight, 100); i++;
    pb1 = XtCreateManagedWidget("pb1", xmPushButtonWidgetClass, view1, arglist, i);
    i=0;
    XtSetArg(arglist[i], XmNlabelString, XmStringCreate("PB2", XmSTRING_DEFAULT_CHARSET)); i++;
    XtSetArg(arglist[i], XmNwidth, 100); i++;
    XtSetArg(arglist[i], XmNheight, 100); i++;
    pb2 = XtCreateManagedWidget("Pb2", xmPushButtonWidgetClass, view2, arglist, i);
    XtAddCallback(pb1, XmNactivateCallback, showit, NULL);

    XtRealizeWidget(view1);
    
    /*
     *  Loop and process events
     */

    XtAppMainLoop(app);
}