1/* 2 3Copyright 1987, 1988, 1998 The Open Group 4 5Permission to use, copy, modify, distribute, and sell this software and its 6documentation for any purpose is hereby granted without fee, provided that 7the above copyright notice appear in all copies and that both that 8copyright notice and this permission notice appear in supporting 9documentation. 10 11The above copyright notice and this permission notice shall be included in 12all copies or substantial portions of the Software. 13 14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 18AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 21Except as contained in this notice, the name of The Open Group shall not be 22used in advertising or otherwise to promote the sale, use or other dealings 23in this Software without prior written authorization from The Open Group. 24 25*/ 26 27/*********************************************************** 28 29Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts. 30 31 All Rights Reserved 32 33Permission to use, copy, modify, and distribute this software and its 34documentation for any purpose and without fee is hereby granted, 35provided that the above copyright notice appear in all copies and that 36both that copyright notice and this permission notice appear in 37supporting documentation, and that the name of Digital not be 38used in advertising or publicity pertaining to distribution of the 39software without specific, written prior permission. 40 41DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 42ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 43DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 44ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 45WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 46ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 47SOFTWARE. 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 73static 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*/ 87void 88XmuCvtStringToBitmap(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