Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!sdd.hp.com!hp-pcd!hpcvlx!paulm From: paulm@hpcvlx.cv.hp.com (Paul J. McClellan) Newsgroups: comp.windows.x.motif Subject: Re: PushButton Pixmap problems Message-ID: <110630020@hpcvlx.cv.hp.com> Date: 18 Oct 90 17:16:03 GMT References: <12110003@hpfcbig.SDE.HP.COM> Organization: Hewlett-Packard Co., Corvallis, OR, USA Lines: 133 Below is an example client illustrating how one can read a bitmap from a bitmap file, create a pixmap from it, and set a XmLabel's labelPixmap resource. +--------------------------------------------------------------------+ | Paul J. McClellan | paulm@cv.hp.com | | Information Technology Operation | {backbone}!hplabs!hp-pcd!paulm | | Hewlett Packard Co. | (USA) (503) 750-2493 VOICE | +--------------------------------------------------------------------+ /************************************************************************ * File: label_pixmap.c * * Reads a bitmap from a bitmap file and creates a label pixmap from it. ***********************************************************************/ #include #include #include #include #include #include /************************************************************************ * main ***********************************************************************/ main (argc, argv) int argc; char **argv; { Widget toplevel, label; /* * Initialize the Intrinsics and create the Label widget. */ toplevel = XtInitialize (argv[0], "App-notes", NULL, 0, &argc, argv); label = XmCreateLabel (toplevel, "label", NULL, 0); XtManageChild (label); /* * Read any specified bitmap file. Construct the label pixmap from it. */ if (argc && argv[1]) { Display *dpy; Screen *screen; int x, y, n; unsigned int width, height; Arg wargs[3]; Pixmap bitmap; dpy = XtDisplay (toplevel); screen = XtScreen (toplevel); if (XReadBitmapFile (dpy, RootWindowOfScreen (screen), argv[1], &width, &height, &bitmap, &x, &y) != BitmapSuccess) { fprintf (stderr, "Unable to read bitmap file %s\n", argv[1]); bitmap = NULL; } if (bitmap && (width == 0 || height == 0)) { fprintf (stderr, "Invalid bitmap file %s\n", argv[1]); bitmap = NULL; } if (bitmap) { Pixel fg, bg; Pixmap pixmap; GC gc; XGCValues gcv; /* * Get the foreground and background colors from the label widget. */ n = 0; XtSetArg (wargs[n], XtNforeground, &fg); n++; XtSetArg (wargs[n], XtNbackground, &bg); n++; XtGetValues (label, wargs, n); /* * Create a pixmap of the appropriate size, root, and depth. */ pixmap = XCreatePixmap (dpy, RootWindowOfScreen (screen), width, height, DefaultDepthOfScreen (screen)); /* * Create a GC and copy the bitmap to the pixmap. */ gcv.foreground = bg; gcv.background = bg; gc = XCreateGC (dpy, pixmap, (GCForeground|GCBackground), &gcv); /* * Fill in the background, set the foreground, copy the bitmap to * the pixmap, and free the gc. */ XFillRectangle (dpy, pixmap, gc, 0, 0, width, height); XSetForeground (dpy, gc, fg); XCopyPlane (dpy, bitmap, pixmap, gc, 0, 0, width, height, 0, 0, 1L); XFreeGC (dpy, gc); /* * Set the labelType and labelPixmap resources. */ n = 0; XtSetArg (wargs[n], XmNlabelType, XmPIXMAP); n++; XtSetArg (wargs[n], XmNlabelPixmap, pixmap); n++; XtSetValues (label, wargs, n); } } /* * Realize the widget hierarchy and enter the main loop. */ XtRealizeWidget (toplevel); XtMainLoop (); }