1
/* static char rcsid[] = "$XConsortium: StrToBmap.c,v 1.11 91/03/09 17:08:48 rws Exp $"; */
4
/***********************************************************
5
Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts,
6
and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
10
Permission to use, copy, modify, and distribute this software and its
11
documentation for any purpose and without fee is hereby granted,
12
provided that the above copyright notice appear in all copies and that
13
both that copyright notice and this permission notice appear in
14
supporting documentation, and that the names of Digital or MIT not be
15
used in advertising or publicity pertaining to distribution of the
16
software without specific, written prior permission.
18
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
19
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
20
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
21
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
22
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
23
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
26
******************************************************************/
28
#include <X11/Intrinsic.h>
29
#include <X11/StringDefs.h>
30
#include <X11/Xmu/Converters.h>
31
#include <X11/Xmu/Drawing.h>
35
* XmuConvertStringToBitmap:
37
* creates a depth-1 Pixmap suitable for window manager icons.
38
* "string" represents a bitmap(1) filename which may be absolute,
39
* or relative to the global resource bitmapFilePath, class
40
* BitmapFilePath. If the resource is not defined, the default
41
* value is the build symbol BITMAPDIR.
43
* shares lots of code with XmuConvertStringToCursor.
45
* To use, include the following in your ClassInitialize procedure:
47
static XtConvertArgRec screenConvertArg[] = {
48
{XtBaseOffset, (caddr_t) XtOffset(Widget, core.screen), sizeof(Screen *)}
51
XtAddConverter("String", "Bitmap", XmuCvtStringToBitmap,
52
screenConvertArg, XtNumber(screenConvertArg));
56
#define done(address, type) \
57
{ (*toVal).size = sizeof(type); (*toVal).addr = (caddr_t) address; }
61
void XmuCvtStringToBitmap(args, num_args, fromVal, toVal)
67
static Pixmap pixmap; /* static for cvt magic */
68
char *name = (char *)fromVal->addr;
73
unsigned int width, height;
78
XtErrorMsg("wrongParameters","cvtStringToBitmap","XtToolkitError",
79
"String to pixmap conversion needs screen argument",
80
(String *)NULL, (Cardinal *)NULL);
82
if (strcmp(name, "None") == 0) {
84
done(&pixmap, Pixmap);
88
if (strcmp(name, "ParentRelative") == 0) {
89
pixmap = ParentRelative;
90
done(&pixmap, Pixmap);
94
screen = *((Screen **) args[0].addr);
95
pixmap = XmuLocateBitmapFile (screen, name,
96
NULL, 0, NULL, NULL, NULL, NULL);
98
dpy = DisplayOfScreen(screen);
99
db = XrmGetDatabase(dpy);
100
XrmSetDatabase(dpy, XtScreenDatabase(screen));
101
fn = XtResolvePathname(dpy, "bitmaps", name, "", NULL, NULL, 0, NULL);
103
fn = XtResolvePathname(dpy, "", name, ".xbm", NULL, NULL, 0, NULL);
104
XrmSetDatabase(dpy, db);
106
XmuReadBitmapDataFromFile (fn, &width, &height, &data,
107
&xhot, &yhot) == BitmapSuccess) {
108
pixmap = XCreatePixmapFromBitmapData (dpy,
109
RootWindowOfScreen(screen),
110
(char *) data, width, height,
112
XFree ((char *)data);
116
if (pixmap != None) {
117
done (&pixmap, Pixmap);
119
XtStringConversionWarning (name, "Pixmap");