示例#1
0
static Bool
XPixmapLoader(XawParams *params, Screen *screen, Colormap colormap, int depth,
	      Pixmap *pixmap_return, Pixmap *mask_return,
	      Dimension *width_return, Dimension *height_return)
{
  XpmAttributes xpm_attributes;
  XawArgVal *argval;
  unsigned int closeness = 4000;
  static SubstitutionRec sub[] = {
    {'H',   NULL},
    {'N',   NULL},
    {'T',   "pixmaps"},
    {'P',   PROJECT_ROOT},
  };
  char *filename;

  if ((argval = XawFindArgVal(params, "closeness")) != NULL
      && argval->value)
    closeness = atoi(argval->value);

  if (params->name[0] != '/' && params->name[0] != '.')
    {
      if (!sub[0].substitution)
	sub[0].substitution = getenv("HOME");
      sub[1].substitution = params->name;
      if (pixmap_path == NULL)
	GetResourcePixmapPath(DisplayOfScreen(screen));
      filename = XtFindFile(pixmap_path, sub, XtNumber(sub), NULL);
      if (!filename)
	return (False);
    }
  else
    filename = params->name;

  xpm_attributes.colormap = colormap;
  xpm_attributes.closeness = closeness;
  xpm_attributes.valuemask = XpmSize | XpmColormap | XpmCloseness;
  if (XpmReadFileToPixmap(DisplayOfScreen(screen),
			  RootWindowOfScreen(screen), filename, pixmap_return,
			  mask_return, &xpm_attributes) == XpmSuccess)
    {
      *width_return = xpm_attributes.width;
      *height_return = xpm_attributes.height;

      return (True);
    }

  return (False);
}
示例#2
0
static Bool
BitmapLoader(XawParams *params, Screen *screen, Colormap colormap, int depth,
	     Pixmap *pixmap_return, Pixmap *mask_return,
	     Dimension *width_return, Dimension *height_return)
{
  Pixel fg, bg;
  XColor color, exact;
  Pixmap pixmap;
  unsigned int width, height;
  unsigned char *data = NULL;
  int hotX, hotY;
  XawArgVal *argval;
  Bool retval = False;
  static SubstitutionRec sub[] = {
    {'H',   NULL},
    {'N',   NULL},
    {'T',   "bitmaps"},
    {'P',   PROJECT_ROOT},
  };
  char *filename;

  fg = BlackPixelOfScreen(screen);
  bg = WhitePixelOfScreen(screen);

  if ((argval = XawFindArgVal(params, "foreground")) != NULL
      && argval->value)
    {
      if (XAllocNamedColor(DisplayOfScreen(screen), colormap, argval->value,
			   &color, &exact))
	fg = color.pixel;
      else
	return (False);
    }
  if ((argval = XawFindArgVal(params, "background")) != NULL
      && argval->value)
    {
      if (XAllocNamedColor(DisplayOfScreen(screen), colormap, argval->value,
			   &color, &exact))
	bg = color.pixel;
      else
	return (False);
    }

  if (params->name[0] != '/' && params->name[0] != '.')
    {
      if (!sub[0].substitution)
	#ifdef _MSC_VER
	sub[0].substitution = ".";
	#else
	sub[0].substitution = getenv("HOME");
	#endif
      sub[1].substitution = params->name;
      if (pixmap_path == NULL)
	GetResourcePixmapPath(DisplayOfScreen(screen));
      filename = XtFindFile(pixmap_path, sub, XtNumber(sub), NULL);
      if (!filename)
	return (FALSE);
    }
  else
    filename = params->name;

  if (XReadBitmapFileData(filename, &width, &height, &data,
			  &hotX, &hotY) == BitmapSuccess)
    {
      pixmap = XCreatePixmapFromBitmapData(DisplayOfScreen(screen),
					   RootWindowOfScreen(screen),
					   (char *)data,
					   width, height, fg, bg, depth);
      if (data)
	XFree(data);
      *pixmap_return = pixmap;
      *mask_return = None;
      *width_return = width;
      *height_return = height;

      retval = True;
    }

  if (filename != params->name)
    XtFree(filename);

  return (retval);
}
示例#3
0
// Pixmap caching utility
void MotifUI::GetPixmaps(Widget w,
                         char *name,
                         Pixmap *pixmap,
                         Pixmap *mask)
{
   // Try to find pixmap in cache
   PixmapLookupList pixmaps = pixmap_table;
   int i;
   for (i = 0; i < n_pixmaps; i++, pixmaps++)
      if (!strcmp((**pixmaps).name, name))
       {
	 *pixmap = (**pixmaps).pixmap;
	 if (mask)
	    *mask = (**pixmaps).mask;
	 return;
       }

   Pixmap _mask;
   char *s;
   SubstitutionRec subs[1];
   char *bmPath;
   char *PIXMAP_DIR = "/usr/dt/appconfig/icons/%L/%B:"
                      "/usr/dt/appconfig/icons/C/%B:"
                      "/usr/include/X11/bitmaps/%B";

   if (*name == '/')
     s = name;
   else
    {
#ifdef NO_CDE
      if ((s = getenv("XBMLANGPATH")) && *s)
#else
      if ((s = getenv("XMICONSEARCHPATH")) && *s)
#endif
       {
         bmPath = new char [strlen(s) + strlen(PIXMAP_DIR) + 2];
         sprintf(bmPath, "%s:%s", PIXMAP_DIR, s);
       }
      else
         bmPath = PIXMAP_DIR;
      subs[0].match = 'B';
      subs[0].substitution = name;
      s = XtFindFile(bmPath, subs, XtNumber(subs), NULL);
      if (bmPath != PIXMAP_DIR)
         delete [] bmPath;
    }

   struct stat statbuf;
   if (!s || stat(s, &statbuf) < 0)
    {
      *pixmap = XmUNSPECIFIED_PIXMAP;
      if (mask)
         *mask = XmUNSPECIFIED_PIXMAP;
      return;
    }

   int len = strlen(s);
   if (!strcmp(s + len - 3, ".pm"))
    {
      XpmAttributes attributes;
      memset((char *)&attributes, 0, sizeof(XpmAttributes));
#ifdef NO_CDE
      XpmReadFileToPixmap(display, root, s, pixmap, &_mask, &attributes);
#else
      _DtXpmReadFileToPixmap(display, root, s, pixmap, &_mask, &attributes);
#endif

      if (_mask)
         FillBackground(w, *pixmap, _mask);
#ifdef NO_CDE
      XpmFreeAttributes(&attributes);
#else
      _DtXpmFreeAttributes(&attributes);
#endif
    }
   else
    {
      if (UIClass() == MAIN_WINDOW)
         *pixmap = XmGetPixmapByDepth(XtScreen(w), s, white, black, depth);
      else
         *pixmap = XmGetPixmapByDepth(XtScreen(w), s, black, white, depth);
      char *s1 = new char [len + 3];
      strcpy(s1, s);
      strcpy(s1 + len - 3, "_m.bm");
      if (stat(s1, &statbuf) < 0)
         _mask = XmUNSPECIFIED_PIXMAP;
      else
       {
         _mask = XmGetPixmapByDepth(XtScreen(w), s1, white, black, 1);
         FillBackground(w, *pixmap, _mask);
       }
      delete [] s1;
    }
   if (mask)
      *mask = _mask;
   if (s != name)
      XtFree(s);

   // Add pixmap to table
   if (!(n_pixmaps % 8))
    {
      pixmaps = new PixmapLookup [n_pixmaps + 8];
      for (i = 0; i < n_pixmaps; i++)
	 pixmaps[i] = pixmap_table[i];
      for (i = n_pixmaps; i < n_pixmaps + 8; i++)
	 pixmaps[i] = new PixmapLookupStruct;
      delete []pixmap_table;
      pixmap_table = pixmaps;
    }
   pixmap_table[n_pixmaps]->name = strdup(name);
   pixmap_table[n_pixmaps]->pixmap = *pixmap;
   pixmap_table[n_pixmaps]->mask = _mask;
   n_pixmaps++;
}