source: trunk/athena/lib/Xj/StrToPixmap.c @ 12242

Revision 12242, 2.1 KB checked in by ghudson, 26 years ago (diff)
Move Jets sources here from athena/bin/dash/src/lib, and autoconfiscate.
Line 
1/*
2 * $Source: /afs/dev.mit.edu/source/repository/athena/lib/Xj/StrToPixmap.c,v $
3 * $Author: ghudson $
4 *
5 * Copyright 1990, 1991 by the Massachusetts Institute of Technology.
6 *
7 * For copying and distribution information, please see the file
8 * <mit-copyright.h>.
9 *
10 */
11
12#if  (!defined(lint))  &&  (!defined(SABER))
13static char *rcsid =
14"$Header: /afs/dev.mit.edu/source/repository/athena/lib/Xj/StrToPixmap.c,v 1.1 1998-12-17 16:23:08 ghudson Exp $";
15#endif
16
17#include "mit-copyright.h"
18#include "Jets.h"
19
20#ifndef BITMAPDIR
21#define BITMAPDIR "/usr/lib/X11/bitmaps"
22#endif
23static char *bitmapdir = BITMAPDIR;
24
25/*
26 * String to Pixmap conversion
27 */
28int StrToPixmap(display, window, where, resource, type, address)
29     Display *display;
30     Window window;
31     caddr_t where;
32     XjResource *resource;
33     char *type;
34     caddr_t address;
35{
36  XjPixmap *newPixmap = NULL;
37  XjPixmap p;
38  char errtext[100];
39  char *error = "error reading bitmap %s%s";
40  char *no_mem = ", no memory";
41  char *ptr = (char *) address;
42  int status = 1;
43
44  if (ptr == NULL)
45    {
46      *((XjPixmap **)((char *)where + resource->resource_offset)) = NULL;
47      return 0;
48    }
49
50  switch(XReadBitmapFile(display, window,
51                         ptr, &p.width, &p.height,
52                         &p.pixmap, &p.hot_x, &p.hot_y))
53    {
54    case BitmapOpenFailed:
55    case BitmapFileInvalid:
56      if (ptr[0] != '/')
57        {
58          char *new_ptr;
59          int ret;
60
61          new_ptr = (char *) XjMalloc(strlen(ptr)
62                                      + strlen(bitmapdir) + 2);
63          sprintf(new_ptr, "%s/%s", bitmapdir, ptr);
64          ret = StrToPixmap(display, window, where, resource, type, new_ptr);
65          XjFree(new_ptr);
66          if (!ret)
67            return 0;
68        }
69      sprintf(errtext, error, ptr, "");
70      XjWarning(errtext);
71      break;
72
73    case BitmapNoMemory:
74      sprintf(errtext, error, ptr, no_mem);
75      XjWarning(errtext);
76      break;
77
78    case BitmapSuccess:
79      newPixmap = (XjPixmap *)XjMalloc((unsigned) sizeof(XjPixmap));
80      memcpy(newPixmap, &p, sizeof(XjPixmap));
81      status = 0;
82      break;
83    }
84
85  *((XjPixmap **)((char *)where + resource->resource_offset)) = newPixmap;
86
87  return status;
88}
Note: See TracBrowser for help on using the repository browser.