begeddov@software.ORG (Gabriel Beged-Dov) (10/02/88)
The staticRaster and menuButton in the HP widgets manipulate XImages. staticRaster is probably closest to a XImage label button, although menuButton is more flexible. staticRaster keeps the image for drawing so that it is may be more appropriate for applications that update the image. menuButton converts the XImage to a pixmap and uses the pixmap for display. HP hasn't included a stringToXImage converter in the release. I have found that this can make the widgets more fun to use. I have included an old ineffecient one I wrote based on Jef Poskanzer's pixmap converter. It uses XReadBitmapFile and pixmaps although this generates unnecessary server requests. A better way would be to read in the bits directly as has been discussed by many people. Oh well... The only recent change I made was to conform to resource database handling in the R3 intrinsics. --------------------------------------------------------------------------- #ifndef BITMAPDIR #define BITMAPDIR "/usr/include/X11/bitmaps" #endif #ifndef done #define done(address, type) \ { (*toVal).size = sizeof(type); (*toVal).addr = (caddr_t)address; } #endif /* * GBB 4/25/88 * Convert a string to an Ximage. The string must be the name of * file containing an X11 bitmap description */ static void CvtStringToXImage(args,num_args, from_val, toVal) XrmValuePtr args; Cardinal * num_args; /* unused */ XrmValuePtr from_val; XrmValuePtr toVal; { char *name = (String) from_val->addr; char error_buf[80]; Screen * screen; int bitmap_rtn, foo, width, height; static char* bitmap_file_path = NULL; char filename[MAXPATHLEN]; Pixmap pix; static XImage * image; XrmDataBase db; if (name == NULL) return; if (*num_args != 1) XtError("String to Pixmap conversion needs screen argument"); screen = *((Screen **) args[0].addr); #ifdef R3 db = XtDataBase(DisplayOfScreen(screen)); #else db = XtDefaultDB; #endif if ( name[0] == '/' || name[0] == '.' ) strcpy( filename, name ); else { if (bitmap_file_path == NULL) { XrmName xrm_name[3]; XrmClass xrm_class[3]; XrmRepresentation rep_type; XrmValue value; xrm_name[0] = XtApplicationName; xrm_name[1] = StringToQuark( "bitmapFilePath" ); xrm_name[2] = NULL; xrm_class[0] = XtApplicationClass; xrm_class[1] = StringToQuark( "BitmapFilePath" ); xrm_class[2] = NULL; if (XrmQGetResource( db, xrm_name, xrm_class, &rep_type, &value ) && rep_type == StringToQuark(XtRString)) bitmap_file_path = value.addr; else bitmap_file_path = BITMAPDIR; } sprintf( filename, "%s/%s", bitmap_file_path, name ); } if (XReadBitmapFile( DisplayOfScreen(screen), RootWindowOfScreen(screen), filename, &width, &height, &pix, &foo, &foo ) != BitmapSuccess) { sprintf(error_buf, "could not create ximage from file %s.", filename); XtError(error_buf); } image = XGetImage(screen->display, pix, 0, 0, width, height, XAllPlanes(), XYPixmap); /* * We had to pass XGetImage XYPixmap as format but we actually want * XYBitmap as format so that XPutImage will use the foreground and * background values in the GC. */ image->format = XYBitmap; XFreePixmap(screen->display, pix); done(&image, XImage *); } ---------------------------------------------------------------------------- Gabe Beged-Dov csnet: begeddov@software.org Software Productivity Consortium 1880 N. Campus Commons Dr. Reston, VA 22091 arpanet: begeddov%software.org@relay.cs.net
RWS@ZERMATT.LCS.MIT.EDU (Robert Scheifler) (10/02/88)
Date: Sat, 1 Oct 88 17:03:57 EDT From: Gabriel Beged-Dov <begeddov%software.org@relay.cs.net> It uses XReadBitmapFile and pixmaps although this generates unnecessary server requests. A better way would be to read in the bits directly as has been discussed by many people. Oh well... Such a function will exist in a utility library in R3.