[comp.windows.x] using XtIsManaged or XtIsRealized

chapman@lll-lcc.UUCP (Carol Chapman) (04/14/89)

I am using X11R3 with the Athena widgets.  I have a large viewport
widget within which I would like to display 3 color digitized images.
I have created 3 Core widgets to hold each of these images.  The
images will change depending on what the user wants to look at, so I
need to be able to "wipe out" the image in a Core widget and then redo
it with the new image.  The following is the routine I am attempting
to use for this purpose, but I get a unix segmentation violation when
I get to the line involving XtIsManaged.  I tried replacing
XtIsManaged with XtIsRealized, but I get the same error.  What is
wrong?

carol
---------------------------------------------------------------------------

static void make_dig_image_widget(image_widget, width, height, image_name)
	Widget *image_widget;
	unsigned int width, height;
	char *image_name;
{
  Arg args[10];
  Cardinal num_args = 0;
  Boolean already_exists = False;

  already_exists = XtIsManaged(*image_widget);
  if (already_exists)  /* the widget has been used before */  {
     XtUnmanageChild(*image_widget);
     XtSetValues(args[num_args], XtNheight, height); num_args++;
     XtSetValues(args[num_args], XtNwidth, width); num_args++;
     XtManageChild(*image_widget);
  }  /* of if */
  else  /* this is the first time the widget is to be used */  {
     XtSetArg(args[num_args], XtNheight, height); num_args++;
     XtSetArg(args[num_args], XtNwidth, width); num_args++;
     *image_widget = XtCreateManagedWidget(image_name, widgetClass,
           image_viewport, args, num_args);
  }  /* of else */
}


-- 
-------------------------------------------------------------------------------
Livermore Lab            (chapman@lll-crg.llnl.gov or chapman@lll-lcc.llnl.gov)
P.O. Box 808, L-153      Tel. (415) 423-7876
Livermore, CA  94550     "Never own anything that you have to FEED or PAINT." 

converse@EXPO.LCS.MIT.EDU (Donna Converse) (04/14/89)

>I get a unix segmentation violation when
>I get to the line involving XtIsManaged. 


The posted code uses XtIsManaged as a test of existence. 
The function XtIsManaged tests whether an existing widget is 
managed.  If XtIsManaged is passed a nonexisting widget, 
it is not guaranteed to return false.  

To test existence, you could explicitly initialize widget 
variables to NULL at the time of the variable definition,
then test that the variable is not null to determine existence.


 Donna

converse@EXPO.LCS.MIT.EDU (Donna Converse) (04/14/89)

Your original question:

> The
>images will change depending on what the user wants to look at, so I
>need to be able to "wipe out" the image in a Core widget and then redo
>it with the new image.

Set the window background pixel to the white pixel of the screen,
then clear the window:

XSetWindowBackground(dpy, win, WhitePixel(dpy, screen_number));
XClearWindow(dpy, win);

kit@EXPO.LCS.MIT.EDU (Chris D. Peterson) (04/15/89)

> Your original question:

> > The
> >images will change depending on what the user wants to look at, so I
> >need to be able to "wipe out" the image in a Core widget and then redo
> >it with the new image.

> Set the window background pixel to the white pixel of the screen,
> then clear the window:

> XSetWindowBackground(dpy, win, WhitePixel(dpy, screen_number));
> XClearWindow(dpy, win);


From Carol's message it is not clear what is necessary to redraw the window.
If you are drawing the image from an exposure handler then you will need
to make a call to XClearArea() with exposures set to TRUE.  If you are
using a background pixmap you can get by with making a call to XClearWindow()
after you have set the background pixmap.  This will cause the server to
refresh your window from the background pixmap.  In any case I don't believe
that it is necessary to call XSetWindowBackground().


                                                Chris D. Peterson
                                                MIT X Consortium