3 Copyright 1987, 1988, 1998 The Open Group
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
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
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.
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.
27 /***********************************************************
29 Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
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.
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
49 ******************************************************************/
54 #include <X11/Intrinsic.h>
55 #include <X11/StringDefs.h>
56 #include <X11/Xmu/Converters.h>
57 #include <X11/Xmu/Drawing.h>
61 * XmuConvertStringToBitmap:
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.
69 * shares lots of code with XmuConvertStringToCursor.
71 * To use, include the following in your ClassInitialize procedure:
73 static XtConvertArgRec screenConvertArg[] = {
74 {XtBaseOffset, (XtPointer) XtOffset(Widget, core.screen), sizeof(Screen *)}
77 XtAddConverter("String", "Bitmap", XmuCvtStringToBitmap,
78 screenConvertArg, XtNumber(screenConvertArg));
82 #define done(address, type) \
83 { (*toVal).size = sizeof(type); (*toVal).addr = (XPointer) address; }
88 XmuCvtStringToBitmap(XrmValuePtr args, Cardinal *num_args,
89 XrmValuePtr fromVal, XrmValuePtr toVal)
91 static Pixmap pixmap; /* static for cvt magic */
92 char *name = (char *)fromVal->addr;
97 unsigned int width, height;
102 XtErrorMsg("wrongParameters","cvtStringToBitmap","XtToolkitError",
103 "String to pixmap conversion needs screen argument",
104 (String *)NULL, (Cardinal *)NULL);
106 if (strcmp(name, "None") == 0) {
108 done(&pixmap, Pixmap);
112 if (strcmp(name, "ParentRelative") == 0) {
113 pixmap = ParentRelative;
114 done(&pixmap, Pixmap);
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);
127 fn = XtResolvePathname(dpy, "", name, ".xbm", NULL, NULL, 0, NULL);
128 XrmSetDatabase(dpy, db);
130 XmuReadBitmapDataFromFile (fn, &width, &height, &data,
131 &xhot, &yhot) == BitmapSuccess) {
132 pixmap = XCreatePixmapFromBitmapData (dpy,
133 RootWindowOfScreen(screen),
134 (char *) data, width, height,
136 XFree ((char *)data);
140 if (pixmap != None) {
141 done (&pixmap, Pixmap);
143 XtStringConversionWarning (name, "Pixmap");