Blame src/StrToBmap.c

Packit Service 2b1f13
/*
Packit Service 2b1f13
Packit Service 2b1f13
Copyright 1987, 1988, 1998  The Open Group
Packit Service 2b1f13
Packit Service 2b1f13
Permission to use, copy, modify, distribute, and sell this software and its
Packit Service 2b1f13
documentation for any purpose is hereby granted without fee, provided that
Packit Service 2b1f13
the above copyright notice appear in all copies and that both that
Packit Service 2b1f13
copyright notice and this permission notice appear in supporting
Packit Service 2b1f13
documentation.
Packit Service 2b1f13
Packit Service 2b1f13
The above copyright notice and this permission notice shall be included in
Packit Service 2b1f13
all copies or substantial portions of the Software.
Packit Service 2b1f13
Packit Service 2b1f13
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Packit Service 2b1f13
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Packit Service 2b1f13
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
Packit Service 2b1f13
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
Packit Service 2b1f13
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
Packit Service 2b1f13
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Packit Service 2b1f13
Packit Service 2b1f13
Except as contained in this notice, the name of The Open Group shall not be
Packit Service 2b1f13
used in advertising or otherwise to promote the sale, use or other dealings
Packit Service 2b1f13
in this Software without prior written authorization from The Open Group.
Packit Service 2b1f13
Packit Service 2b1f13
*/
Packit Service 2b1f13
Packit Service 2b1f13
/***********************************************************
Packit Service 2b1f13
Packit Service 2b1f13
Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
Packit Service 2b1f13
Packit Service 2b1f13
                        All Rights Reserved
Packit Service 2b1f13
Packit Service 2b1f13
Permission to use, copy, modify, and distribute this software and its
Packit Service 2b1f13
documentation for any purpose and without fee is hereby granted,
Packit Service 2b1f13
provided that the above copyright notice appear in all copies and that
Packit Service 2b1f13
both that copyright notice and this permission notice appear in
Packit Service 2b1f13
supporting documentation, and that the name of Digital not be
Packit Service 2b1f13
used in advertising or publicity pertaining to distribution of the
Packit Service 2b1f13
software without specific, written prior permission.
Packit Service 2b1f13
Packit Service 2b1f13
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
Packit Service 2b1f13
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
Packit Service 2b1f13
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
Packit Service 2b1f13
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
Packit Service 2b1f13
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
Packit Service 2b1f13
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
Packit Service 2b1f13
SOFTWARE.
Packit Service 2b1f13
Packit Service 2b1f13
******************************************************************/
Packit Service 2b1f13
Packit Service 2b1f13
#ifdef HAVE_CONFIG_H
Packit Service 2b1f13
#include <config.h>
Packit Service 2b1f13
#endif
Packit Service 2b1f13
#include	<X11/Intrinsic.h>
Packit Service 2b1f13
#include	<X11/StringDefs.h>
Packit Service 2b1f13
#include	<X11/Xmu/Converters.h>
Packit Service 2b1f13
#include	<X11/Xmu/Drawing.h>
Packit Service 2b1f13
Packit Service 2b1f13
Packit Service 2b1f13
/*
Packit Service 2b1f13
 * XmuConvertStringToBitmap:
Packit Service 2b1f13
 *
Packit Service 2b1f13
 * creates a depth-1 Pixmap suitable for window manager icons.
Packit Service 2b1f13
 * "string" represents a bitmap(1) filename which may be absolute,
Packit Service 2b1f13
 * or relative to the global resource bitmapFilePath, class
Packit Service 2b1f13
 * BitmapFilePath.  If the resource is not defined, the default
Packit Service 2b1f13
 * value is the build symbol BITMAPDIR.
Packit Service 2b1f13
 *
Packit Service 2b1f13
 * shares lots of code with XmuConvertStringToCursor.
Packit Service 2b1f13
 *
Packit Service 2b1f13
 * To use, include the following in your ClassInitialize procedure:
Packit Service 2b1f13
Packit Service 2b1f13
static XtConvertArgRec screenConvertArg[] = {
Packit Service 2b1f13
    {XtBaseOffset, (XtPointer) XtOffset(Widget, core.screen), sizeof(Screen *)}
Packit Service 2b1f13
};
Packit Service 2b1f13
Packit Service 2b1f13
    XtAddConverter("String", "Bitmap", XmuCvtStringToBitmap,
Packit Service 2b1f13
		   screenConvertArg, XtNumber(screenConvertArg));
Packit Service 2b1f13
 *
Packit Service 2b1f13
 */
Packit Service 2b1f13
Packit Service 2b1f13
#define	done(address, type) \
Packit Service 2b1f13
	{ (*toVal).size = sizeof(type); (*toVal).addr = (XPointer) address; }
Packit Service 2b1f13
Packit Service 2b1f13
Packit Service 2b1f13
/*ARGSUSED*/
Packit Service 2b1f13
void
Packit Service 2b1f13
XmuCvtStringToBitmap(XrmValuePtr args, Cardinal *num_args,
Packit Service 2b1f13
		     XrmValuePtr fromVal, XrmValuePtr toVal)
Packit Service 2b1f13
{
Packit Service 2b1f13
    static Pixmap pixmap;		/* static for cvt magic */
Packit Service 2b1f13
    char *name = (char *)fromVal->addr;
Packit Service 2b1f13
    Screen *screen;
Packit Service 2b1f13
    Display *dpy;
Packit Service 2b1f13
    XrmDatabase db;
Packit Service 2b1f13
    String fn;
Packit Service 2b1f13
    unsigned int width, height;
Packit Service 2b1f13
    int xhot, yhot;
Packit Service 2b1f13
    unsigned char *data;
Packit Service 2b1f13
Packit Service 2b1f13
    if (*num_args != 1)
Packit Service 2b1f13
     XtErrorMsg("wrongParameters","cvtStringToBitmap","XtToolkitError",
Packit Service 2b1f13
             "String to pixmap conversion needs screen argument",
Packit Service 2b1f13
              (String *)NULL, (Cardinal *)NULL);
Packit Service 2b1f13
Packit Service 2b1f13
    if (strcmp(name, "None") == 0) {
Packit Service 2b1f13
	pixmap = None;
Packit Service 2b1f13
	done(&pixmap, Pixmap);
Packit Service 2b1f13
	return;
Packit Service 2b1f13
    }
Packit Service 2b1f13
Packit Service 2b1f13
    if (strcmp(name, "ParentRelative") == 0) {
Packit Service 2b1f13
	pixmap = ParentRelative;
Packit Service 2b1f13
	done(&pixmap, Pixmap);
Packit Service 2b1f13
	return;
Packit Service 2b1f13
    }
Packit Service 2b1f13
Packit Service 2b1f13
    screen = *((Screen **) args[0].addr);
Packit Service 2b1f13
    pixmap = XmuLocateBitmapFile (screen, name,
Packit Service 2b1f13
				  NULL, 0, NULL, NULL, NULL, NULL);
Packit Service 2b1f13
    if (pixmap == None) {
Packit Service 2b1f13
	dpy = DisplayOfScreen(screen);
Packit Service 2b1f13
	db = XrmGetDatabase(dpy);
Packit Service 2b1f13
	XrmSetDatabase(dpy, XtScreenDatabase(screen));
Packit Service 2b1f13
	fn = XtResolvePathname(dpy, "bitmaps", name, "", NULL, NULL, 0, NULL);
Packit Service 2b1f13
	if (!fn)
Packit Service 2b1f13
	    fn = XtResolvePathname(dpy, "", name, ".xbm", NULL, NULL, 0, NULL);
Packit Service 2b1f13
	XrmSetDatabase(dpy, db);
Packit Service 2b1f13
	if (fn &&
Packit Service 2b1f13
	    XmuReadBitmapDataFromFile (fn, &width, &height, &data,
Packit Service 2b1f13
				       &xhot, &yhot) == BitmapSuccess) {
Packit Service 2b1f13
	    pixmap = XCreatePixmapFromBitmapData (dpy,
Packit Service 2b1f13
						  RootWindowOfScreen(screen),
Packit Service 2b1f13
						  (char *) data, width, height,
Packit Service 2b1f13
						  1, 0, 1);
Packit Service 2b1f13
	    XFree ((char *)data);
Packit Service 2b1f13
	}
Packit Service 2b1f13
    }
Packit Service 2b1f13
Packit Service 2b1f13
    if (pixmap != None) {
Packit Service 2b1f13
	done (&pixmap, Pixmap);
Packit Service 2b1f13
    } else {
Packit Service 2b1f13
	XtStringConversionWarning (name, "Pixmap");
Packit Service 2b1f13
	return;
Packit Service 2b1f13
    }
Packit Service 2b1f13
}
Packit Service 2b1f13