                                        /*-------------------------------
                                         |    example3.c                |
                                         -------------------------------*/
#include <Xm/PushB.h>
#include <X11/xpm.h>
                                        /*-------------------------------------
                                         |              MAIN                  |
                                         ------------------------------------*/
int main(argc, argv)
  unsigned int argc;
  char **argv;
{
   Widget toplevel, pb;
   XtAppContext context;
   Display *dpy;
   Pixmap pix_returned, mask, button_pixmap;
   XpmAttributes xpmatts;
   static char *filename = "xterm.xpm";
   Pixel fg, bg;
   XGCValues gcvals;
   long gcmask = 0L , dynamic_mask = 0L , dont_care_mask = 0L;
   GC gc;

     
					   	    /* Initialize the toolkit */
   toplevel = XtAppInitialize(&context, "Example3", NULL, 0, &argc, argv,
                              NULL, NULL, 0);
   dpy = XtDisplay(toplevel);

   xpmatts.closeness = 40000;
   xpmatts.valuemask = XpmSize | XpmCloseness;
   if( XpmReadFileToPixmap(dpy, DefaultRootWindow(dpy), filename,
			&pix_returned, &mask, &xpmatts) == XpmSuccess )
	{

		button_pixmap = XCreatePixmap(dpy, pix_returned,
					xpmatts.width, xpmatts.height, 
					DefaultDepth( (dpy), DefaultScreen(dpy) ) );

						     /* Create the pushbutton */
		pb = XtVaCreateManagedWidget("pb", xmPushButtonWidgetClass, toplevel,
					XmNwidth, 100,
					XmNheight, 100,
					XmNlabelType, XmPIXMAP,
					XmNlabelPixmap, button_pixmap,
					NULL);

	   XtVaGetValues(pb, XmNbackground, &bg,
			 	XmNforeground, &fg,
				NULL);

   		gcmask = GCForeground | GCBackground;
   		gcvals.foreground = bg;
   		gcvals.background = fg;
   		gc = XtAllocateGC(pb, DefaultDepth( (dpy), DefaultScreen(dpy) ),
							 	gcmask, &gcvals,
								dynamic_mask, dont_care_mask);

   		XFillRectangle(dpy, button_pixmap, gc, 0, 0, 
							xpmatts.width, xpmatts.height);
   		XSetClipMask(dpy, gc, mask);
   		XSetClipOrigin(dpy, gc, 0, 0);
   		XCopyArea(dpy, pix_returned, button_pixmap, gc,
        		        0, 0, xpmatts.width, xpmatts.height, 0, 0 );
	}
	else
	{
		pb = XtVaCreateManagedWidget("pb", xmPushButtonWidgetClass, toplevel,
					XmNwidth, 100,
					XmNheight, 100,
					NULL);
	}

   if(pix_returned )
	XFreePixmap(dpy, pix_returned);
   if(mask )
	XFreePixmap(dpy, mask);

					      /* Realize the top level widget */
   XtRealizeWidget(toplevel);

   XtAppMainLoop(context);

}/*------------------------------------------------------------ End of MAIN --*/
