refresh pushbutton with a pixmap on it

This forum is read only. No new submissions are accepted.

Questions about motif? Contact us

2 posts / 0 new
Last post
refresh pushbutton with a pixmap on it

Submitted by orank on Mon, 01/14/2002 - 15:21. Developers
Hi ,
One way I know is this
You can create 2 pixmaps one that looks like the button is not pressed and one that looks like the button is pressed. When needed change the current pixmap to be one of the 2 pixmap?s.
Good luck

Hi I have a pushbutton with a XmNlableType == XmPIXMAP.
I change the pixmap on the button using the following function.
The problem is that the pixmaps are not changed (refreshed) until I push the pushbutton then for some reason it gets the needed event and gets repainted with the new pixmap.

How can I make the button refresh after I changed the pixmap for it.

I already tried to use XmUpdateDisplay(Widg); after the set_color_icon_pixmap is finished. It did not help.

I hope some one knows how to over come this . .

Thank you

Here is the PixMap function I use

static int set_color_icon_pixmap(button, filename)
Widget button;
char *filename;
{
Pixmap pix, old_pix, arm_pix, old_arm_pix, inactive_pix, old_inactive_pix;
Arg wargs[10];
int n;
int pix_width, pix_height, err_code=0;
Boolean recompute_size;
Dimension button_width, button_height;
unsigned char label_type;

/* retrieve the old pixpams to destroy */
n = 0;
XtSetArg(wargs[n], XmNlabelType, &label_type); n++;
XtSetArg(wargs[n], XmNlabelPixmap, &old_pix); n++;
XtGetValues(button, wargs, n);

pix = ii_motif_util_create_color_icon(XtParent(button), filename,
&pix_width, &pix_height, &err_code);

n = 0;
XtSetArg(wargs[n], XmNrecomputeSize, &recompute_size); n++;
XtSetArg(wargs[n], XmNwidth, &button_width); n++;
XtSetArg(wargs[n], XmNheight, &button_height); n++;
XtGetValues(button, wargs, n);

if ((recompute_size == FALSE) &&
pix != NULL &&
(button_height < pix_height ||
button_width < pix_width)) {
if (pix != XmUNSPECIFIED_PIXMAP)
XFreePixmap(XtDisplay(XtParent(button)), pix);
pix = NULL;
err_code = PIXMAP_TOO_BIG;
return FALSE;
}
/*
* Set pixmap resources.
*/

n = 0;

if (pix == NULL) {

pix = XCreatePixmap(ii_motif_display(),
ii_motif_get_default_root_window(ii_motif_display()), 1, 1,
DefaultDepth(ii_motif_display(),0));

#if 0
XFillRectangle(ii_motif_display(), pix,
i_x11_backgroundGC, 0, 0, 1, 1);
#endif
}

XtSetArg(wargs[n], XmNlabelType, XmPIXMAP); n++;
XtSetArg(wargs[n], XmNlabelPixmap, pix); n++;
XtSetValues(button, wargs, n);

if (label_type == XmPIXMAP && old_pix &&
old_pix != XmUNSPECIFIED_PIXMAP)
XFreePixmap(XtDisplay(XtParent(button)), old_pix);

return (err_code == 0);
}

ICS_support

XmUpdateDisplay() handles a very small set of cases -- it looks ahead in the event queue for expose events and then processes them. It would not help in this case.

What is happening, I believe, is that you are freeing one pixmap and then creating a new one -- and the new one gets the same value as the old one, so the change doesn`t take place. You can confirm this by checking the IDs of the two pixmaps and seeing whether they are identical or not. This problem can happen occasionally, two, for items such as widget IDs -- the freed value is the same as the newly-instantiated value. In both cases, a simple solution is to create the new item first and then clean up the original, so that they are sure to have different values.

In any case, pixmaps are IDs that correspond to values on the X server. The code looks a little funny to me; I don`t believe that you need to explicitly free these pixmaps. XmLabel handles that internally. I`d have to check to be sure; but I can tell that this code is freeing the pixmaps twice -- once when they are initially set, and again when they are retrieved from the XmLabel and replaced.