Home | History | Annotate | Line # | Download | only in src
      1 /*
      2 
      3 Copyright 1987, 1988, 1998  The Open Group
      4 
      5 Permission to use, copy, modify, distribute, and sell this software and its
      6 documentation for any purpose is hereby granted without fee, provided that
      7 the above copyright notice appear in all copies and that both that
      8 copyright notice and this permission notice appear in supporting
      9 documentation.
     10 
     11 The above copyright notice and this permission notice shall be included in
     12 all copies or substantial portions of the Software.
     13 
     14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
     17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
     18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
     19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     20 
     21 Except as contained in this notice, the name of The Open Group shall not be
     22 used in advertising or otherwise to promote the sale, use or other dealings
     23 in this Software without prior written authorization from The Open Group.
     24 
     25 */
     26 
     27 /***********************************************************
     28 
     29 Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
     30 
     31                         All Rights Reserved
     32 
     33 Permission to use, copy, modify, and distribute this software and its
     34 documentation for any purpose and without fee is hereby granted,
     35 provided that the above copyright notice appear in all copies and that
     36 both that copyright notice and this permission notice appear in
     37 supporting documentation, and that the name of Digital not be
     38 used in advertising or publicity pertaining to distribution of the
     39 software without specific, written prior permission.
     40 
     41 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
     42 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
     43 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
     44 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
     45 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
     46 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
     47 SOFTWARE.
     48 
     49 ******************************************************************/
     50 
     51 #ifdef HAVE_CONFIG_H
     52 #include <config.h>
     53 #endif
     54 #include	<X11/Intrinsic.h>
     55 #include	<X11/StringDefs.h>
     56 #include	<X11/Xmu/Converters.h>
     57 #include	<X11/Xmu/Drawing.h>
     58 
     59 
     60 /*
     61  * XmuConvertStringToBitmap:
     62  *
     63  * creates a depth-1 Pixmap suitable for window manager icons.
     64  * "string" represents a bitmap(1) filename which may be absolute,
     65  * or relative to the global resource bitmapFilePath, class
     66  * BitmapFilePath.  If the resource is not defined, the default
     67  * value is the build symbol BITMAPDIR.
     68  *
     69  * shares lots of code with XmuConvertStringToCursor.
     70  *
     71  * To use, include the following in your ClassInitialize procedure:
     72 
     73 static XtConvertArgRec screenConvertArg[] = {
     74     {XtBaseOffset, (XtPointer) XtOffset(Widget, core.screen), sizeof(Screen *)}
     75 };
     76 
     77     XtAddConverter("String", "Bitmap", XmuCvtStringToBitmap,
     78 		   screenConvertArg, XtNumber(screenConvertArg));
     79  *
     80  */
     81 
     82 #define	done(address, type) \
     83 	{ (*toVal).size = sizeof(type); (*toVal).addr = (XPointer) address; }
     84 
     85 
     86 /*ARGSUSED*/
     87 void
     88 XmuCvtStringToBitmap(XrmValuePtr args, Cardinal *num_args,
     89 		     XrmValuePtr fromVal, XrmValuePtr toVal)
     90 {
     91     static Pixmap pixmap;		/* static for cvt magic */
     92     char *name = (char *)fromVal->addr;
     93     Screen *screen;
     94     Display *dpy;
     95     XrmDatabase db;
     96     String fn;
     97     unsigned int width, height;
     98     int xhot, yhot;
     99     unsigned char *data;
    100 
    101     if (*num_args != 1)
    102      XtErrorMsg("wrongParameters","cvtStringToBitmap","XtToolkitError",
    103              "String to pixmap conversion needs screen argument",
    104               (String *)NULL, (Cardinal *)NULL);
    105 
    106     if (strcmp(name, "None") == 0) {
    107 	pixmap = None;
    108 	done(&pixmap, Pixmap);
    109 	return;
    110     }
    111 
    112     if (strcmp(name, "ParentRelative") == 0) {
    113 	pixmap = ParentRelative;
    114 	done(&pixmap, Pixmap);
    115 	return;
    116     }
    117 
    118     screen = *((Screen **) args[0].addr);
    119     pixmap = XmuLocateBitmapFile (screen, name,
    120 				  NULL, 0, NULL, NULL, NULL, NULL);
    121     if (pixmap == None) {
    122 	dpy = DisplayOfScreen(screen);
    123 	db = XrmGetDatabase(dpy);
    124 	XrmSetDatabase(dpy, XtScreenDatabase(screen));
    125 	fn = XtResolvePathname(dpy, "bitmaps", name, "", NULL, NULL, 0, NULL);
    126 	if (!fn)
    127 	    fn = XtResolvePathname(dpy, "", name, ".xbm", NULL, NULL, 0, NULL);
    128 	XrmSetDatabase(dpy, db);
    129 	if (fn &&
    130 	    XmuReadBitmapDataFromFile (fn, &width, &height, &data,
    131 				       &xhot, &yhot) == BitmapSuccess) {
    132 	    pixmap = XCreatePixmapFromBitmapData (dpy,
    133 						  RootWindowOfScreen(screen),
    134 						  (char *) data, width, height,
    135 						  1, 0, 1);
    136 	    XFree ((char *)data);
    137 	}
    138     }
    139 
    140     if (pixmap != None) {
    141 	done (&pixmap, Pixmap);
    142     } else {
    143 	XtStringConversionWarning (name, "Pixmap");
    144 	return;
    145     }
    146 }
    147 
    148