[comp.windows.x] Label Widgets

fineberg@ANTARES.MCS.ANL.GOV (06/27/89)

I am using the Athena widgets under X11 for a tool that displaysa graphical
representation of memeory access patterns on a shared memory system.  The 
problem is that when I try to change label widgets when graphics are being
displayed the labels simply disappear from the screen.  If no graphics
are being displayed, there is no problem.  This does not make sense to me
because the code being used to change labels is the same whether graphics
are being used or not. My code for changing labels is as follows:

    Arg args[1];
    XtUnmanageChild(item);
    args[0].name = XtNlabel;
    args[0].value = (XtArgVal) string;
    XtSetValues(item, args, XtNumber(args));
    XtMapWidget(item);
    XtManageChild(item);

Also, the graphics being drawn are just rectangles  and are done with
this code:

  XSetForeground(display, gc, my_color_map[color]);
  XFillRectangle(display, surface, gc, x1, y1, x2, y2);
  if (x_batch_off)
    XFlush(display);

I would appreciate any help, 

	Sam Fineberg
	fineberg@mcs.anl.gov

kit@EXPO.LCS.MIT.EDU (Chris D. Peterson) (06/28/89)

> I am using the Athena widgets under X11 for a tool that displaysa graphical
> representation of memeory access patterns on a shared memory system.  The 
> problem is that when I try to change label widgets when graphics are being
> displayed the labels simply disappear from the screen.  If no graphics
> are being displayed, there is no problem.

From the context of the message it appears that you are writing over the label 
in the label widget.  The best method to acheive what you want is to create a
sub-class of the label widget that will display your graphics for you.  This
widget needs to take great care to draw the rectangles first and in a
different color so that the text will remain visable.

						Chris D. Peterson     
						MIT X Consortium 

Net:	 kit@expo.lcs.mit.edu
Phone:   (617) 253 - 9608	
Address: MIT - Room NE43-213

swick@ATHENA.MIT.EDU (Ralph R. Swick) (06/29/89)

> The 
> problem is that when I try to change label widgets when graphics are being
> displayed the labels simply disappear from the screen.  If no graphics
> are being displayed, there is no problem.
> ...
>    Arg args[1];
>    XtUnmanageChild(item);
>    args[0].name = XtNlabel;
>    args[0].value = (XtArgVal) string;
>    XtSetValues(item, args, XtNumber(args));
>    XtMapWidget(item);
>    XtManageChild(item);

There's some pretty strange code here, but perhaps you know best.
I can't think of many good reasons to unmanage a label before
changing it and can't think of _any_ reason to recommend explicitly
mapping a widget immediately before managing it.

It's hard to diagnose your problem without more details, but one
possible source of difficulty you may have overlooked is in the
implementation of Label.  When an XtSetValues is performed on
Label, it does not immediately repaint in its new state; instead,
it waits for an exposure event to arrive.  This was intended to
save multiple re-draws, assuming that a change in state often
meant a change in size also.

So, if your application is busy doing other output then the effect
of the XtSetValues call on Label will not be visible until you
finish the output and resume event processing.  If you want a widget
that displays its new label immediately, it is trivial to subclass
Label to do it; you can inherit all the Label methods and write
a one-line SetValues method that calls redisplay immediately.