73) How can I have a Pixmap in a Label?

Answer: From Bob Hays (bobhays@spss.com)

    Pixmap px_disarm, px_disarm_insens;

    Widget Label1;
    Pixel   foreground, background;
    Arg     args[4];
    Arg     arg[] = {
                { XmNforeground, &foreground },
                { XmNbackground, &background }
    };

    Label1 = XmCreateLabel ( Shell1, "Label1",
                                       (Arg *) NULL, (Cardinal) 0 );
    XtGetValues ( Label1, arg, XtNumber ( arg ) );
    px_disarm =
      XCreatePixmapFromBitmapData(display,
                                DefaultRootWindow(display),
                                mtn_bits, mtn_width, mtn_height,
                                foreground,
                                background,
                                DefaultDepth(display,DefaultScreen(display)));
    px_disarm_insens =
      XCreatePixmapFromBitmapData(display,
                                DefaultRootWindow(display),
                                mtn_ins_bits, mtn_ins_width, mtn_ins_height,
                                foreground,
                                background,
                                DefaultDepth(display,DefaultScreen(display)));

    n = 0;
    XtSetArg(args[n], XmNlabelType, XmPIXMAP);  n++;
    XtSetArg(args[n], XmNlabelPixmap, px_disarm);  n++;
    XtSetArg(args[n], XmNlabelInsensitivePixmap, px_disarm_insens ); n++;
    XtSetValues ( Label1, args, n );
    XtManageChild(Label1);

That will cause the foreground and background of your pixmap to be inherited
from the one that would be used by OSF/Motif when the label is displayed.  The
advantage is that this will utilize any resource values the user may have
requested without looking explicitly into the resource database.  And, you
will have a pixmap handy if the application insensitizes the label (without an
XmNlabelInsensitivePixmap your label will go empty if made insensitive).

[Bob's original code was for a PushButton. Just change all Label to PushButton
for them.]
Go Back Up

Go To Previous

Go To Next