Пример #1
0
int
loadPixmap (Display * dpy, MyPixmap * pm, char *dir, char *file,
	    XpmColorSymbol * cs, int n)
{
  char filename[512];
  XpmAttributes attr;

#ifdef DEBUG
  printf ("entering loadPixmap\n");
#endif

  pm->pixmap = None;
  pm->mask = None;
  pm->width = 1;
  pm->height = 1;
  snprintf (filename, sizeof (filename), "%s/%s", dir, file);
  attr.colorsymbols = cs;
  attr.numsymbols = n;
  attr.valuemask = XpmSize;
  if (n > 0 && cs)
    attr.valuemask = attr.valuemask | XpmColorSymbols;
  if (XpmReadFileToPixmap
      (dpy, XDefaultRootWindow (dpy), filename, &pm->pixmap, &pm->mask,
       &attr))
    return False;
  pm->width = attr.width;
  pm->height = attr.height;
  XpmFreeAttributes (&attr);
  return True;
}
Пример #2
0
static void DrawTray(winlist_t *win)
{
    XpmAttributes attributes;
    Pixmap tray, mask, shapemask;
    GC shapegc, traygc;
    attributes.valuemask = 0;
    XpmCreatePixmapFromData(gui->display, win->window,
			oxim_tray, &tray, &mask, &attributes);

    tray_w = attributes.width;
    tray_h = attributes.height;

    shapemask = XCreatePixmap(gui->display, win->window,
			win->width , win->height , 1);

    traygc = XCreateGC(gui->display, tray, 0, 0);
    shapegc = XCreateGC(gui->display, shapemask, 0, 0);

    XFillRectangle(gui->display, shapemask, shapegc, 0, 0,
		win->width, win->height);

    int sw = (win->width - tray_w) / 2;
    int sh = (win->height - tray_h) / 2;
    int new_x = (sw > 0) ? sw : 0;
    int new_y = (sh > 0) ? sh : 0;

    if (mask)
    {
	XCopyArea(gui->display, mask, shapemask, shapegc, 0, 0,
		tray_w, tray_h, new_x, new_y);
	XFreePixmap(gui->display, mask);
    }
    else
    {
	XSetForeground(gui->display, shapegc, 1);
	XFillRectangle(gui->display, shapemask, shapegc, new_x, new_y,
		tray_w, tray_h);
    }

    XShapeCombineMask(gui->display, win->window, ShapeBounding,
		0, 0, shapemask, ShapeSet);
/*    XShapeCombineMask(gui->display, win->window, ShapeClip,
		0, 0, shapemask, ShapeSet);*/
    XCopyArea(gui->display, tray, win->window, traygc, 0, 0,
		win->width, win->height, new_x, new_y);

    XpmFreeAttributes(&attributes);
    XFreePixmap(gui->display, tray);
    XFreePixmap(gui->display, shapemask);
    XFreeGC(gui->display, shapegc);
    XFreeGC(gui->display, traygc);    
}
Пример #3
0
void gui_Draw_Image(winlist_t *win, int x, int y, char **xpm_data)
{
    XImage *image, *mask;
    XpmAttributes attr;
    Window w = win->window;
    GC pgc = XCreateGC(gui->display, w, 0, NULL);
    unsigned int px, py;
    unsigned long mask_val, img_val;

    bzero(&attr, sizeof(attr));
    XpmCreateImageFromData(gui->display, xpm_data, &image, &mask, &attr);
    if (mask)
    {
	for (py=0 ; py < attr.height ; py++)
	{
	    for (px=0 ; px < attr.width ; px++)
	    {
		mask_val = XGetPixel(mask, px, py);
		/* 要顯示的點 */
		if (mask_val)
		{
		    img_val = XGetPixel(image, px, py);
        	    XSetForeground(gui->display, pgc, img_val);
		    XDrawPoint(gui->display, w, pgc, px+x, py+y);
		}
	    }
	}
    }
    else
    {
	XPutImage(gui->display, w, DefaultGC(gui->display, gui->screen),
                image, 0, 0, x, y, attr.width, attr.height);
    }
    XDestroyImage(image);

    if (mask)
    {
	XDestroyImage(mask);
    }
    XpmFreeAttributes(&attr);
    XFreeGC(gui->display, pgc);
}
Пример #4
0
/*
    建立 Tray 
*/
void gui_tray_init(void)
{
    winlist_t *win = NULL;

    if (gui->tray_win)
    {
	//return;
	win = gui->tray_win;
    }
    else
    {
#if 0
	//manager_window = XGetSelectionOwner(gui->display, selection_atom);
	manager_window = ManagerWindow(gui->display, gui->screen);

	if (manager_window != None)
	{
	    Atom visual_atom = XInternAtom(gui->display, "_NET_SYSTEM_TRAY_VISUAL", False);

	    Atom type;
	    int format;
	    union {
		    unsigned long *prop;
		    unsigned char *prop_ch;
	    } prop = { NULL };
	    unsigned long nitems;
	    unsigned long bytes_after;
	    int result;

	    type = None;
	    result = XGetWindowProperty (gui->display,
					manager_window,
					visual_atom,
					0, sizeof(long), False,
					XA_VISUALID,
					&type, &format, &nitems,
					&bytes_after, &(prop.prop_ch));

	    Visual *default_xvisual;
	    
	    if (result == 0 &&
		type == XA_VISUALID && nitems == 1 && format == 32)
		{
		    VisualID visual_id = prop.prop[0];
		    visual = x11_screen_lookup_visual (visual_id);
		}
	}
#endif
#if 1
/*        Atom actual_type;
        int actual_format;
        unsigned long nitems, bytes_remaining;
        unsigned char *data = 0;
        int result = XGetWindowProperty(gui->display, manager_window, visual_atom, 0, 1,
                                        False, XA_VISUALID, &actual_type,
                                        &actual_format, &nitems, &bytes_remaining, &data);
        VisualID vid = 0;
        if (result == Success && data && actual_type == XA_VISUALID && actual_format == 32 &&
                nitems == 1 && bytes_remaining == 0)
            vid = *(VisualID*)data;
        if (data)
            XFree(data);
        if (vid == 0)
            return;
*/
        uint mask = VisualScreenMask;
        XVisualInfo *vi, rvi;
        int count=0, i;
        //rvi.visualid = vid;
	rvi.screen = gui->screen;
        vi = XGetVisualInfo(gui->display, mask, &rvi, &count);
	for(i=0; i<count; i++)
	{
	      if (vi[i].depth == 32 &&
		  (vi[i].red_mask   == 0xff0000 &&
		   vi[i].green_mask == 0x00ff00 &&
		   vi[i].blue_mask  == 0x0000ff))
		{
			//printf("rgba_visual=%d\n", vi[i].visual->visualid);
			visual = &vi[i];
			break;
		}
	}
        /*if (vi) {
            //visual = vi[0];
	    visual = &vi[0];
	    //return;
            //XFree((char*)vi);
        }*/
#endif

	if(visual && visual->visual)
	    win = gui_new_win_tray((XVisualInfo*)visual);
	else
	    win = gui_new_win();
    }

    /* Tray 不需要邊框 */
    XSetWindowBorderWidth(gui->display, win->window, 0);

    XSetWindowAttributes win_attr;
    win_attr.override_redirect = True;
    XChangeWindowAttributes(gui->display, win->window,
			CWOverrideRedirect, &win_attr);

    Pixmap tray, mask;
    XpmAttributes attributes;
    attributes.valuemask = 0;

    if (!ProcessTrayIcon(gui->display, win->window, oxim_tray, &icon, &icon_mask,
				&picon)) 
    {
	//fprintf(stderr, "failed to get inactive icon image\n");
	return;
    }
#if 1
    if(visual && visual->visual)
    {
	/* GCs for copy and drawing on mask */
	XGCValues gv;
	gv.foreground = BlackPixel(gui->display, gui->screen);
	gv.background = BlackPixel(gui->display, gui->screen);
	//GC gc = XCreateGC(gui->display, win->window, GCBackground|GCForeground, &gv);
	GC gc = XCreateGC(gui->display, aw, GCBackground|GCForeground, &gv);

	XSetClipMask(gui->display, gc, icon_mask);
    }
#endif
    XpmCreatePixmapFromData(gui->display, win->window,
		oxim_tray, &tray, &mask, &attributes);
    tray_w = attributes.width;
    tray_h = attributes.height;

    win->width  = tray_w;
    win->height = tray_h;

    XpmFreeAttributes(&attributes);
    XFreePixmap(gui->display, tray);
    if (mask)
    {
	XFreePixmap(gui->display, mask);
    }
    win->pos_x = 0;
    win->pos_y = 0;

    win->win_draw_func = NULL;
    win->win_event_func = gui_focus_event;

    XSizeHints *size_hints = XAllocSizeHints();
    size_hints->flags = PMinSize | PMaxSize;
    size_hints->min_width = win->width;
    size_hints->min_height = win->height;
    size_hints->max_width = win->width;
    size_hints->max_height = win->height;
    XSetWMNormalHints(gui->display, win->window, size_hints);
    XFree(size_hints);

    Atom xembed_info = XInternAtom(gui->display, "_XEMBED_INFO", False);
    unsigned int mapping[2];
    mapping[0] = 0; /* ver 0 */
    mapping[1] = 1; /* request mapping */
    XChangeProperty(gui->display, win->window, xembed_info, xembed_info,
			32, PropModeReplace, (unsigned char *)mapping, 2);
    gui->tray_win = win;
}
Пример #5
0
Boolean Xvars::load_pixmap(Drawable* pixmap,Drawable* mask,
                           int dpyNum,char** xpmBits,Boolean fullSize) {
  // Just load XPM as is.
  if (fullSize) {
    XpmAttributes attr;
    attr.valuemask = XpmCloseness;
    attr.closeness = XPM_CLOSENESS;
    attr.alloc_close_colors = True;

    int val = 
      XpmCreatePixmapFromData(dpy[dpyNum],root[dpyNum],
                              xpmBits,
                              pixmap,mask,
                              &attr);
    XpmFreeAttributes(&attr);

    Boolean ret = (val == XpmSuccess);
    if (!*pixmap || (mask && !*mask)) {
      ret = False;
    }

    return ret; 
  }


  //// Load image and mask into memory, reduce them and put them up to the
  //// display server as a new pixmap and mask

  XImage* srcImage;
  XImage* srcMask;
  Size srcSize;

  // Load in src image from supplied data.
  XpmAttributes attr;
  attr.valuemask = XpmReturnPixels | XpmCloseness;
  attr.closeness = XPM_CLOSENESS;
  attr.alloc_close_colors = True;

  // Perhaps should use XpmReturnAllocPixels, neither gives the transparent 
  // value.
  int val = 
    XpmCreateImageFromData(dpy[dpyNum],
                           xpmBits,
                           &srcImage,(mask ? &srcMask : (XImage**)NULL),
                           &attr);
  srcSize.width = attr.width;
  srcSize.height = attr.height;
  if (val != XpmSuccess) {
    XpmFreeAttributes(&attr);
    return False;
  }
  // Must be even size.
  assert((srcSize.width % 2 == 0) && 
         (srcSize.height % 2 == 0));
  int depth = srcImage->depth;
  int bitmap_pad = srcImage->bitmap_pad;

  // Size of reduced, destination image.
  Size destSize;
  destSize.set(srcSize.width / 2,srcSize.height / 2);
  
  // Create image for dest data.
  char* destData = 
    new_bytes_for_image(destSize,depth,bitmap_pad);
  XImage *destImage = 
    XCreateImage(dpy[dpyNum],visual[dpyNum],depth,ZPixmap,0,
                 destData,destSize.width,destSize.height,
                 bitmap_pad,0);
  assert(destImage);

  // Create dest mask if needed.
  XImage *destMask;
  if (mask) {
    assert(srcMask->depth == 1);
    char* destMaskData = 
      new_bytes_for_image(destSize,1,bitmap_pad);
    destMask = 
      XCreateImage(dpy[dpyNum],visual[dpyNum],1,ZPixmap,0,
                   destMaskData,destSize.width,destSize.height,
                   bitmap_pad,0);
    assert(destMask);
  }
    
  // Do the pixel reduction.
  //  unstretch_image(dpyNum,destImage,srcImage,attr.pixels,attr.npixels);
  unstretch_image(dpyNum,destImage,srcImage,
                  attr.pixels,attr.npixels);
  if (mask) {
    unstretch_image(dpyNum,destMask,srcMask,NULL,0);
  }

  // Kill src image and mask.
  XpmFreeAttributes(&attr);
  XDestroyImage(srcImage);  
  if (mask) {
    XDestroyImage(srcMask);
  }
      
  // Create dest pixmap and mask
  *pixmap = XCreatePixmap(dpy[dpyNum],root[dpyNum],
                          destSize.width,destSize.height,
                          depth);
  if (!*pixmap) {
    // Should do more cleanup.
    return False;
  }
  if (mask) {
    *mask = XCreatePixmap(dpy[dpyNum],root[dpyNum],
                          destSize.width,destSize.height,
                          1);
    if (!*mask) {
      // Should do more cleanup.
      return False;
    }
  }

  // Put dest image and mask up to the display server.
  put_image(dpyNum,*pixmap,destImage,destSize);
  if (mask) {
    put_image(dpyNum,*mask,destMask,destSize);
  }

  // Kill dest image and mask
  destroy_image(destImage);
  if (mask) {
    destroy_image(destMask);
  }
  return True;
}
Пример #6
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++;
}
Пример #7
0
JError
JXImage::CreateFromXPM
	(
	JXDisplay*			display,
	const JCharacter*	fileName,
	JXImage**			image
	)
{
#ifdef _J_HAS_XPM

	JXColormap* colormap = display->GetColormap();

	Pixmap image_pixmap = None;
	Pixmap mask_pixmap  = None;

	XpmAttributes attr;
	attr.valuemask          = XpmVisual | XpmColormap | XpmDepth |
							  XpmExactColors | XpmCloseness |
							  XpmColorKey | XpmAllocCloseColors |
							  XpmReturnAllocPixels;
	attr.visual             = colormap->GetVisual();
	attr.colormap           = colormap->GetXColormap();
	attr.depth              = display->GetDepth();
	attr.color_key          = XPM_COLOR;
	attr.alloc_pixels       = NULL;
	attr.nalloc_pixels      = 0;
	attr.alloc_close_colors = kJTrue;	// so we can free all resulting pixels
	attr.exactColors        = 1;
	attr.closeness          = 0;

	const int xpmErr =
		XpmReadFileToPixmap(*display, display->GetRootWindow(),
							const_cast<JCharacter*>(fileName),
							&image_pixmap, &mask_pixmap, &attr);
	if (xpmErr == XpmOpenFailed && JFileExists(fileName))
		{
		return JAccessDenied(fileName);
		}
	else if (xpmErr == XpmOpenFailed)
		{
		return JDirEntryDoesNotExist(fileName);
		}
	else if (xpmErr == XpmFileInvalid)
		{
		return FileIsNotXPM(fileName);
		}
	else if (xpmErr == XpmNoMemory)
		{
		return JNoProcessMemory();
		}
	else if (xpmErr == XpmColorFailed || xpmErr == XpmColorError)
		{
		if (image_pixmap != None)
			{
			XFreePixmap(*display, image_pixmap);
			}
		if (mask_pixmap != None)
			{
			XFreePixmap(*display, mask_pixmap);
			}
		if (attr.alloc_pixels != NULL)
			{
			XFreeColors(*display, attr.colormap, attr.alloc_pixels, attr.nalloc_pixels, 0);
			}
		XpmFreeAttributes(&attr);
		return TooManyColors();
		}

	// create image and mask

	*image = new JXImage(display, image_pixmap);
	assert( *image != NULL );

	XFreePixmap(*display, image_pixmap);

	if (mask_pixmap != None)
		{
		JXImageMask* mask = new JXImageMask(display, mask_pixmap);
		assert( mask != NULL );
		(**image).SetMask(mask);

		XFreePixmap(*display, mask_pixmap);
		}

	// free pixels so X has usage count of 1

	XFreeColors(*display, attr.colormap, attr.alloc_pixels, attr.nalloc_pixels, 0);

	// clean up

	XpmFreeAttributes(&attr);
	return JNoError();

#else

	return XPMNotAvailable();

#endif
}
Пример #8
0
Файл: draw.c Проект: dylex/dzen
char *
parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
	/* bitmaps */
	unsigned int bm_w, bm_h;
	int bm_xh, bm_yh;
	/* rectangles, cirlcles*/
	int rectw, recth, rectx, recty;
	/* positioning */
	int n_posx, n_posy, set_posy=0;
	int px=0, py=0, opx=0;
	int i, next_pos=0, j=0, h=0, tw=0;
	/* buffer pos */
	const char *linep=NULL;
	/* fonts */
	int font_was_set=0;
	/* position */
	int pos_is_fixed = 0;
	/* block alignment */
	int block_align = -1;
	int block_width = -1;
	/* clickable area y tracking */
	int max_y=-1;

	/* temp buffers */
	char lbuf[MAX_LINE_LEN], *rbuf = NULL;

	/* parser state */
	int t=-1, nobg=0;
	char *tval=NULL;

	/* X stuff */
	long lastfg = dzen.norm[ColFG], lastbg = dzen.norm[ColBG];
	Fnt *cur_fnt = NULL;
#ifndef DZEN_XFT
	XGCValues gcv;
#endif
	Drawable pm=0, bm;
#ifdef DZEN_XPM
	int free_xpm_attrib = 0;
	Pixmap xpm_pm;
	XpmAttributes xpma;
	XpmColorSymbol xpms;
#endif

#ifdef DZEN_XFT
	XftDraw *xftd=NULL;
	XftColor xftc;
	char *xftcs;
	int xftcs_f=0;
	char *xftcs_bg;
	int xftcs_bgf=0;

	xftcs    = (char *)dzen.fg;
    xftcs_bg = (char *)dzen.bg;
#endif

	/* icon cache */
	int ip;

	/* parse line and return the text without control commands */
	if(nodraw) {
		rbuf = emalloc(MAX_LINE_LEN);
		rbuf[0] = '\0';
		if( (lnr + dzen.slave_win.first_line_vis) >= dzen.slave_win.tcnt)
			line = NULL;
		else
			line = dzen.slave_win.tbuf[dzen.slave_win.first_line_vis+lnr];

	}
	/* parse line and render text */
	else {
		h = dzen.font.height;
		py = (dzen.line_height - h) / 2;
		xorig[LNR2WINDOW(lnr)] = 0;
		
		if(lnr != -1) {
			pm = XCreatePixmap(dzen.dpy, RootWindow(dzen.dpy, DefaultScreen(dzen.dpy)), dzen.slave_win.width,
					dzen.line_height, DefaultDepth(dzen.dpy, dzen.screen));
		}
		else {
			pm = XCreatePixmap(dzen.dpy, RootWindow(dzen.dpy, DefaultScreen(dzen.dpy)), dzen.title_win.width,
					dzen.line_height, DefaultDepth(dzen.dpy, dzen.screen));
		}

#ifdef DZEN_XFT
		xftd = XftDrawCreate(dzen.dpy, pm, DefaultVisual(dzen.dpy, dzen.screen), 
				DefaultColormap(dzen.dpy, dzen.screen));
#endif

		if(!reverse) {
			XSetForeground(dzen.dpy, dzen.tgc, dzen.norm[ColBG]);
#ifdef DZEN_XPM
			xpms.pixel = dzen.norm[ColBG];
#endif
#ifdef DZEN_XFT
			xftcs_bg = (char *)dzen.bg;
			xftcs_bgf = 0;
#endif
		}
		else {
			XSetForeground(dzen.dpy, dzen.tgc, dzen.norm[ColFG]);
#ifdef DZEN_XPM
			xpms.pixel = dzen.norm[ColFG];
#endif
		}
		XFillRectangle(dzen.dpy, pm, dzen.tgc, 0, 0, dzen.w, dzen.h);

		if(!reverse) {
			XSetForeground(dzen.dpy, dzen.tgc, dzen.norm[ColFG]);
		}
		else {
			XSetForeground(dzen.dpy, dzen.tgc, dzen.norm[ColBG]);
		}

#ifdef DZEN_XPM
		xpms.name = NULL;
		xpms.value = (char *)"none";

		xpma.colormap = DefaultColormap(dzen.dpy, dzen.screen);
		xpma.depth = DefaultDepth(dzen.dpy, dzen.screen);
		xpma.visual = DefaultVisual(dzen.dpy, dzen.screen);
		xpma.colorsymbols = &xpms;
		xpma.numsymbols = 1;
		xpma.valuemask = XpmColormap|XpmDepth|XpmVisual|XpmColorSymbols;
#endif

#ifndef DZEN_XFT 
		if(!dzen.font.set){
			gcv.font = dzen.font.xfont->fid;
			XChangeGC(dzen.dpy, dzen.tgc, GCFont, &gcv);
		}
#endif
		cur_fnt = &dzen.font;

		if( lnr != -1 && (lnr + dzen.slave_win.first_line_vis >= dzen.slave_win.tcnt)) {
			XCopyArea(dzen.dpy, pm, dzen.slave_win.drawable[lnr], dzen.gc,
					0, 0, px, dzen.line_height, xorig[LNR2WINDOW(lnr)], 0);
			XFreePixmap(dzen.dpy, pm);
			return NULL;
		}
	}

	linep = line;
	while(1) {
		if(*linep == ESC_CHAR || *linep == '\0') {
			lbuf[j] = '\0';

			/* clear _lock_x at EOL so final width is correct */
			if(*linep=='\0')
				pos_is_fixed=0;

			if(nodraw) {
				strcat(rbuf, lbuf);
			}
			else {
				if(t != -1 && tval) {
					switch(t) {
						case icon:
							if(MAX_ICON_CACHE && (ip=search_icon_cache(tval)) != -1) {
								int y;
								XCopyArea(dzen.dpy, icons[ip].p, pm, dzen.tgc,
										0, 0, icons[ip].w, icons[ip].h, px, y=(set_posy ? py :
										(dzen.line_height >= (signed)icons[ip].h ?
										(dzen.line_height - icons[ip].h)/2 : 0)));
								px += !pos_is_fixed ? icons[ip].w : 0;
								max_y = MAX(max_y, y+icons[ip].h);
							} else {
								int y;
								if(XReadBitmapFile(dzen.dpy, pm, tval, &bm_w,
											&bm_h, &bm, &bm_xh, &bm_yh) == BitmapSuccess
										&& (h/2 + px + (signed)bm_w < dzen.w)) {
									setcolor(&pm, px, bm_w, lastfg, lastbg, reverse, nobg);

									XCopyPlane(dzen.dpy, bm, pm, dzen.tgc,
											0, 0, bm_w, bm_h, px, y=(set_posy ? py :
											(dzen.line_height >= (int)bm_h ?
												(dzen.line_height - (int)bm_h)/2 : 0)), 1);
									XFreePixmap(dzen.dpy, bm);
									px += !pos_is_fixed ? bm_w : 0;
									max_y = MAX(max_y, y+bm_h);
								}
#ifdef DZEN_XPM
								else if(XpmReadFileToPixmap(dzen.dpy, dzen.title_win.win, tval, &xpm_pm, NULL, &xpma) == XpmSuccess) {
									setcolor(&pm, px, xpma.width, lastfg, lastbg, reverse, nobg);

									if(MAX_ICON_CACHE)
										cache_icon(tval, xpm_pm, xpma.width, xpma.height);

									XCopyArea(dzen.dpy, xpm_pm, pm, dzen.tgc,
											0, 0, xpma.width, xpma.height, px, y=(set_posy ? py :
											(dzen.line_height >= (int)xpma.height ?
												(dzen.line_height - (int)xpma.height)/2 : 0)));
									px += !pos_is_fixed ? xpma.width : 0;
									max_y = MAX(max_y, y+xpma.height);

									/* freed by cache_icon() */
									//XFreePixmap(dzen.dpy, xpm_pm);
									free_xpm_attrib = 1;
								}
#endif
							}
							break;


						case rect:
							get_rect_vals(tval, &rectw, &recth, &rectx, &recty);
							recth = recth > dzen.line_height ? dzen.line_height : recth;
							if(set_posy)
								py += recty;
							recty =	recty == 0 ? (dzen.line_height - recth)/2 :
								(dzen.line_height - recth)/2 + recty;
							px += !pos_is_fixed ? rectx : 0;
							setcolor(&pm, px, rectw, lastfg, lastbg, reverse, nobg);

							XFillRectangle(dzen.dpy, pm, dzen.tgc, px,
									set_posy ? py :
									((int)recty < 0 ? dzen.line_height + recty : recty),
									rectw, recth);

							px += !pos_is_fixed ? rectw : 0;
							break;

						case recto:
							get_rect_vals(tval, &rectw, &recth, &rectx, &recty);
							if (!rectw) break;

							recth = recth > dzen.line_height ? dzen.line_height-2 : recth-1;
							if(set_posy)
								py += recty;
							recty =	recty == 0 ? (dzen.line_height - recth)/2 :
								(dzen.line_height - recth)/2 + recty;
							px = (rectx == 0) ? px : rectx+px;
							/* prevent from stairs effect when rounding recty */
							if (!((dzen.line_height - recth) % 2)) recty--;
							setcolor(&pm, px, rectw, lastfg, lastbg, reverse, nobg);
							XDrawRectangle(dzen.dpy, pm, dzen.tgc, px,
									set_posy ? py :
									((int)recty<0 ? dzen.line_height + recty : recty), rectw-1, recth);
							px += !pos_is_fixed ? rectw : 0;
							break;

						case circle:
							rectx = get_circle_vals(tval, &rectw, &recth);
							setcolor(&pm, px, rectw, lastfg, lastbg, reverse, nobg);
							XFillArc(dzen.dpy, pm, dzen.tgc, px, set_posy ? py :(dzen.line_height - rectw)/2,
									rectw, rectw, 90*64, rectx>1?recth*64:64*360);
							px += !pos_is_fixed ? rectw : 0;
							break;

						case circleo:
							rectx = get_circle_vals(tval, &rectw, &recth);
							setcolor(&pm, px, rectw, lastfg, lastbg, reverse, nobg);
							XDrawArc(dzen.dpy, pm, dzen.tgc, px, set_posy ? py : (dzen.line_height - rectw)/2,
									rectw, rectw, 90*64, rectx>1?recth*64:64*360);
							px += !pos_is_fixed ? rectw : 0;
							break;

						case pos:
							if(tval[0]) {
								int r=0;
								r = get_pos_vals(tval, &n_posx, &n_posy);
								if( (r == 1 && !set_posy))
									set_posy=0;
								else if (r == 5) {
									switch(n_posx) {
										case LOCK_X:
											pos_is_fixed = 1;
											break;
										case UNLOCK_X:
											pos_is_fixed = 0;
											break;
										case LEFT:
											px = 0;
											break;
										case RIGHT:
											px = dzen.w;
											break;
										case CENTER:
											px = dzen.w/2;
											break;
										case BOTTOM:
											set_posy = 1;
											py = dzen.line_height;
											break;
										case TOP:
											set_posy = 1;
											py = 0;
											break;
									}
								} else
									set_posy=1;

								if(r != 2)
									px = px+n_posx<0? 0 : px + n_posx;
								if(r != 1) 
									py += n_posy;
							} else {
								set_posy = 0;
								py = (dzen.line_height - dzen.font.height) / 2;
							}
							break;

						case abspos:
							if(tval[0]) {
								int r=0;
								if( (r=get_pos_vals(tval, &n_posx, &n_posy)) == 1 && !set_posy)
									set_posy=0;
								else
									set_posy=1;

								n_posx = n_posx < 0 ? n_posx*-1 : n_posx;
								if(r != 2)
									px = n_posx;
								if(r != 1)
									py = n_posy;
							} else {
								set_posy = 0;
								py = (dzen.line_height - dzen.font.height) / 2;
							}
							break;

						case ibg:
							nobg = atoi(tval);
							break;

						case bg:
							lastbg = tval[0] ? (unsigned)getcolor(tval) : dzen.norm[ColBG];
#ifdef DZEN_XFT
							if(xftcs_bgf) free(xftcs_bg);				
							if(tval[0]) {
								xftcs_bg = estrdup(tval);
								xftcs_bgf = 1;
							} else {
								xftcs_bg = (char *)dzen.bg;
								xftcs_bgf = 0;
							}
#endif							

							break;

						case fg:
							lastfg = tval[0] ? (unsigned)getcolor(tval) : dzen.norm[ColFG];
							XSetForeground(dzen.dpy, dzen.tgc, lastfg);
#ifdef DZEN_XFT
							if(tval[0]) {
								xftcs = estrdup(tval);
								xftcs_f = 1;
							} else {
								xftcs = (char *)dzen.fg;
								xftcs_f = 0;
							}
#endif							
							break;

						case fn:
							if(tval[0]) {
#ifndef DZEN_XFT		
								if(!strncmp(tval, "dfnt", 4)) {
									cur_fnt = &(dzen.fnpl[atoi(tval+4)]);

									if(!cur_fnt->set) {
										gcv.font = cur_fnt->xfont->fid;
										XChangeGC(dzen.dpy, dzen.tgc, GCFont, &gcv);
									}
								}
								else
#endif					
									setfont(tval);
							}
							else {
								cur_fnt = &dzen.font;
#ifndef DZEN_XFT		
								if(!cur_fnt->set){
									gcv.font = cur_fnt->xfont->fid;
									XChangeGC(dzen.dpy, dzen.tgc, GCFont, &gcv);
								}
#else
							setfont(dzen.fnt ? dzen.fnt : FONT);
#endif								
							}
							py = set_posy ? py : (dzen.line_height - cur_fnt->height) / 2;
							font_was_set = 1;
							break;
						case ca:
						{
							sens_w *w = &window_sens[LNR2WINDOW(lnr)];
							
							if(tval[0]) {
								click_a *area = &((*w).sens_areas[(*w).sens_areas_cnt]);
								if((*w).sens_areas_cnt < MAX_CLICKABLE_AREAS) {
									get_sens_area(tval, 
											&(*area).button, 
											LNR2WINDOW(lnr)*MAX_CLICKABLE_AREAS+(*w).sens_areas_cnt);
									(*area).start_x = px;
									(*area).start_y = py;
									(*area).end_y = py;
									max_y = py;
									(*area).active = 0;
									if(lnr == -1) {
										(*area).win = dzen.title_win.win;
									} else {
										(*area).win = dzen.slave_win.line[lnr];
									}
									(*w).sens_areas_cnt++;
								}
							} else {
									//find most recent unclosed area
									for(i = (*w).sens_areas_cnt - 1; i >= 0; i--)
										if(!(*w).sens_areas[i].active)
											break;
									if(i >= 0 && i < MAX_CLICKABLE_AREAS) {
										(*w).sens_areas[i].end_x = px;
										(*w).sens_areas[i].end_y = max_y;
										(*w).sens_areas[i].active = 1;
								}
							}
						}	break;
						case ba:
							if(tval[0])
								get_block_align_vals(tval, &block_align, &block_width);
							else
								block_align=block_width=-1;
							break;
					}
					free(tval);
				}

				/* check if text is longer than window's width */
				tw = textnw(cur_fnt, lbuf, strlen(lbuf));
				while((((tw + px) > (dzen.w)) || (block_align!=-1 && tw>block_width)) && j>=0) {
					lbuf[--j] = '\0';
					tw = textnw(cur_fnt, lbuf, strlen(lbuf));
				}
				
				opx = px;

				/* draw background for block */
				if(block_align!=-1 && !nobg) {
					setcolor(&pm, px, rectw, lastbg, lastbg, 0, nobg);
					XFillRectangle(dzen.dpy, pm, dzen.tgc, px, 0, block_width, dzen.line_height);
				}

				if(block_align==ALIGNRIGHT)
					px += (block_width - tw);
				else if(block_align==ALIGNCENTER)
					px += (block_width/2) - (tw/2);

				if(!nobg)
					setcolor(&pm, px, tw, lastfg, lastbg, reverse, nobg);
				
#ifndef DZEN_XFT
				if(cur_fnt->set)
					XmbDrawString(dzen.dpy, pm, cur_fnt->set,
							dzen.tgc, px, py + cur_fnt->ascent, lbuf, strlen(lbuf));
				else
					XDrawString(dzen.dpy, pm, dzen.tgc, px, py+dzen.font.ascent, lbuf, strlen(lbuf));
#else
				if(reverse) {
				XftColorAllocName(dzen.dpy, DefaultVisual(dzen.dpy, dzen.screen),
						DefaultColormap(dzen.dpy, dzen.screen),  xftcs_bg,  &xftc);
				} else {
				XftColorAllocName(dzen.dpy, DefaultVisual(dzen.dpy, dzen.screen),
						DefaultColormap(dzen.dpy, dzen.screen),  xftcs,  &xftc);
				}

				XftDrawStringUtf8(xftd, &xftc, 
						cur_fnt->xftfont, px, py + dzen.font.xftfont->ascent, (const FcChar8 *)lbuf, strlen(lbuf));

				if(xftcs_f) {
					free(xftcs);
					xftcs_f = 0;
				}
				if(xftcs_bgf) {
					free(xftcs_bg);
					xftcs_bgf = 0;
				}

#endif

				max_y = MAX(max_y, py+dzen.font.height);

				if(block_align==-1) {
					if(!pos_is_fixed || *linep =='\0')
						px += tw;
				} else {
					if(pos_is_fixed)
						px = opx;
					else
						px = opx+block_width;
				}

				block_align=block_width=-1;
			}

			if(*linep=='\0')
				break;

			j=0; t=-1; tval=NULL;
			next_pos = get_token(linep, &t, &tval);
			linep += next_pos;

			/* ^^ escapes */
			if(next_pos == 0)
				lbuf[j++] = *linep++;
		}
		else
			lbuf[j++] = *linep;

		linep++;
	}

	if(!nodraw) {
		/* expand/shrink dynamically */
		if(dzen.title_win.expand && lnr == -1){
			i = px;
			switch(dzen.title_win.expand) {
				case left:
					/* grow left end */
					otx = dzen.title_win.x_right_corner - i > dzen.title_win.x ?
						dzen.title_win.x_right_corner - i : dzen.title_win.x;
					XMoveResizeWindow(dzen.dpy, dzen.title_win.win, otx, dzen.title_win.y, px, dzen.line_height);
					break;
				case right:
					XResizeWindow(dzen.dpy, dzen.title_win.win, px, dzen.line_height);
					break;
			}

		} else {
			if(align == ALIGNLEFT)
				xorig[LNR2WINDOW(lnr)] = 0;
			if(align == ALIGNCENTER) {
				xorig[LNR2WINDOW(lnr)] = (lnr != -1) ?
					(dzen.slave_win.width - px)/2 :
					(dzen.title_win.width - px)/2;
			}
			else if(align == ALIGNRIGHT) {
				xorig[LNR2WINDOW(lnr)] = (lnr != -1) ?
					(dzen.slave_win.width - px) :
					(dzen.title_win.width - px);
			}
		}


		if(lnr != -1) {
			XCopyArea(dzen.dpy, pm, dzen.slave_win.drawable[lnr], dzen.gc,
                    0, 0, dzen.w, dzen.line_height, xorig[LNR2WINDOW(lnr)], 0);
		}
		else {
			XCopyArea(dzen.dpy, pm, dzen.title_win.drawable, dzen.gc,
					0, 0, dzen.w, dzen.line_height, xorig[LNR2WINDOW(lnr)], 0);
		}
		XFreePixmap(dzen.dpy, pm);

		/* reset font to default */
		if(font_was_set)
			setfont(dzen.fnt ? dzen.fnt : FONT);

#ifdef DZEN_XPM
		if(free_xpm_attrib) {
			XFreeColors(dzen.dpy, xpma.colormap, xpma.pixels, xpma.npixels, xpma.depth);
			XpmFreeAttributes(&xpma);
		}
#endif

#ifdef DZEN_XFT
		XftDrawDestroy(xftd);
#endif
	}

	return nodraw ? rbuf : NULL;
}
Пример #9
0
static Boolean
create_pixmap(Widget parent, int iconidx, Pixmap *sen, Pixmap *insen)
{
    static Boolean first_time = True;
    static Window rootWindow;
    static XpmColorSymbol color[5] = {
	{"none", "none", 0},
	{"iconColor1", NULL, 0},
	{"bottomShadowColor", NULL, 0},
	{"topShadowColor", NULL, 0},
	{"selectColor", NULL, 0}
    };
    static int screenNum;
    static Pixmap tools_map;
    static Pixmap tools_mask;
    static Pixmap shade_map;
    static Pixmap shade_mask;
    
    int		    status = 0;
    XpmAttributes   attr;
    Pixmap	    map;
    Pixmap	    mask;
    static String pixmap_file_path = NULL; /* note: never free()d */
	
    ASSERT(iconidx >= 0, "index must be positive");
    
    if (first_time) {
	/* FIXME: We use a dummy window here to get the correct depth/visual for the
	   pixmap creation (cant use globals.widgets.top_level since it's not realized
	   yet and realizing it now would result in wrong dimensions) ... */
	Widget dummy = XtVaAppCreateShell("xdvi", "Xdvi",
					  transientShellWidgetClass, DISP,
					  XtNdepth, G_depth,
					  XtNvisual, G_visual,
					  XtNcolormap, G_colormap,
					  XtNmappedWhenManaged, False,
					  NULL);
	XtRealizeWidget(dummy); /* note: doesn't pop it up */
	rootWindow = XtWindow(dummy);
	screenNum = DefaultScreen(XtDisplay(globals.widgets.top_level));
	ASSERT(rootWindow != 0, "");
	XtVaGetValues(parent,
		      XmNbackground, &color[BACKGROUND].pixel,
		      XmNforeground, &color[FOREGROUND].pixel,
		      XmNbottomShadowColor, &color[BOTTOM_SHADOW].pixel,
		      XmNtopShadowColor, &color[TOP_SHADOW].pixel,
		      XmNhighlightColor, &color[HIGHLIGHT].pixel,
		      NULL);
	/* try to locate the XPM file with the toolbar pixmaps */
	pixmap_file_path = XtResolvePathname(DISP,
					     "pixmaps",
					     resource.toolbar_pixmap_file,
					     (String)NULL,		/* suffix */
					     (String)NULL,		/* use default path */
					     (Substitution)NULL,	/* substitutions */
					     0,				/* number of substitutions */
					     (XtFilePredicate)NULL);	/* return True iff file exists */

	TRACE_GUI((stderr, "pixmap file search via XtResolvePathname: %s => %s",
		   resource.toolbar_pixmap_file, pixmap_file_path ? (char*)pixmap_file_path : "<NULL>"));
	if (pixmap_file_path == NULL) {
	    pixmap_file_path = (String)kpse_find_file(resource.toolbar_pixmap_file,
						      kpse_program_text_format,
						      0);
	    TRACE_GUI((stderr,
		       "pixmap file search via kpse_find_file: %s => %s",
		       resource.toolbar_pixmap_file,
		       pixmap_file_path ? (char*)pixmap_file_path : "<NULL>"));
	    if (pixmap_file_path == NULL) {
		TRACE_GUI((stderr, "No installed toolbar pixmap found, using built-in pixmap."));
	    }
	}
    }
    
    /* Setup the color subsititution table */
    attr.valuemask = XpmColorSymbols | XpmCloseness | XpmColormap | XpmDepth | XpmVisual;
    attr.closeness = 65535;	/* accuracy isn't crucial */
    attr.colorsymbols = color;
    attr.numsymbols = XtNumber(color);
    attr.visual = G_visual;
    attr.colormap = G_colormap;
    attr.depth = G_depth;
    
    /* Create the "sensitive" pixmap */
    if (!tools_map) {
	if (pixmap_file_path != NULL) {
	    status = XpmReadFileToPixmap(XtDisplay(globals.widgets.top_level), rootWindow,
					 pixmap_file_path, &tools_map, &tools_mask, &attr);
	}
	else {
	    status = XpmCreatePixmapFromData(XtDisplay(globals.widgets.top_level), rootWindow,
					     (char **)toolbar_xpm, &tools_map, &tools_mask, &attr);
	}
    }
    else
	status = XpmSuccess;

    map = tools_map;
    mask = tools_mask;

    if (status == XpmSuccess) {
	static Pixmap tmp_mask;
	static GC gc;

	if (first_time) {
	    tmp_mask = XCreatePixmap(XtDisplay(globals.widgets.top_level), rootWindow, PIXMAP_WIDTH, PIXMAP_HEIGHT, 1);
	    gc = XCreateGC(XtDisplay(globals.widgets.top_level), tmp_mask, 0, NULL);
	}
	XCopyArea(XtDisplay(globals.widgets.top_level),
		  mask, tmp_mask, gc, iconidx * PIXMAP_WIDTH, 0, PIXMAP_WIDTH, PIXMAP_HEIGHT, 0, 0);

	mask = tmp_mask;
    }
    else { /* something went wrong */
	popup_message(globals.widgets.top_level,
		      MSG_ERR,
		      "Something's wrong with your XPM file - "
		      "try to load it into an image editor and fix the problem.",
		      "Xpm error: %s - switching toolbar off.",
		      XpmGetErrorString(status));
	sen = insen = NULL;
	resource.expert_mode ^= XPRT_SHOW_TOOLBAR;
	return False;
    }

    XpmFreeAttributes(&attr);
    
    if (map != 0) {
	static GC back_gc, bots_gc;

	if (first_time) {
	    XGCValues   gcvalues;

	    gcvalues.foreground = color[BACKGROUND].pixel;
	    back_gc = XCreateGC(XtDisplay(globals.widgets.top_level), rootWindow, GCForeground, &gcvalues);

	    gcvalues.foreground = color[BOTTOM_SHADOW].pixel;
	    bots_gc = XCreateGC(XtDisplay(globals.widgets.top_level), rootWindow, GCForeground, &gcvalues);
	}

	/* Need to create new Pixmaps with the mask applied. */
	XSetClipMask(XtDisplay(globals.widgets.top_level), bots_gc, mask);

	/* Create the "sensitive" pixmap. */
	*sen = XCreatePixmap(XtDisplay(globals.widgets.top_level), rootWindow, PIXMAP_WIDTH, PIXMAP_HEIGHT,
			     G_depth);
	XFillRectangle(XtDisplay(globals.widgets.top_level), *sen, back_gc, 0, 0, PIXMAP_WIDTH, PIXMAP_HEIGHT);
	if (iconidx != -1)
	    XCopyArea(XtDisplay(globals.widgets.top_level), map, *sen, bots_gc,
		      iconidx * PIXMAP_WIDTH, 0, PIXMAP_WIDTH, PIXMAP_HEIGHT, 0, 0);
	else
	    XCopyArea(XtDisplay(globals.widgets.top_level), map, *sen, bots_gc,
		      0, 0, PIXMAP_WIDTH, PIXMAP_HEIGHT, 0, 0);

	if (iconidx == -1)
	    XFreePixmap(XtDisplay(globals.widgets.top_level), map);

	/* Create the "insensitive" pixmap. */
	if (insen != NULL) {
	    Pixmap map;
	    Pixmap mask;

	    attr.valuemask = XpmColorSymbols | XpmCloseness | XpmColorKey | XpmColormap | XpmDepth | XpmVisual;
	    attr.closeness = 65535;	/* accuracy isn't crucial */
	    attr.colorsymbols = color;
	    attr.numsymbols = XtNumber(color);
	    attr.color_key = XPM_MONO;
	    attr.visual = G_visual;
	    attr.colormap = G_colormap;
	    attr.depth = G_depth;


	    if (!shade_map) {
		if (pixmap_file_path != NULL) {
		    status = XpmReadFileToPixmap(XtDisplay(globals.widgets.top_level), rootWindow,
						 pixmap_file_path, &shade_map, &shade_mask, &attr);
		}
		else {
		    status = XpmCreatePixmapFromData(XtDisplay(globals.widgets.top_level), rootWindow,
						     (char **)toolbar_xpm, &shade_map, &shade_mask, &attr);
		}
	    }
	    else
		status = XpmSuccess;

	    map = shade_map;
	    mask = shade_mask;

	    if (status == XpmSuccess) {
		static Pixmap tmp_mask;
		static GC gc;

		if (first_time) {
		    tmp_mask = XCreatePixmap(XtDisplay(globals.widgets.top_level), rootWindow,
					     PIXMAP_WIDTH, PIXMAP_HEIGHT, 1);
		    gc = XCreateGC(XtDisplay(globals.widgets.top_level), tmp_mask, 0, NULL);
		}

		XCopyArea(XtDisplay(globals.widgets.top_level), mask, tmp_mask, gc,
			  iconidx * PIXMAP_WIDTH, 0,
			  PIXMAP_WIDTH, PIXMAP_HEIGHT,
			  0, 0);

		mask = tmp_mask;
	    }
	    else { /* something went wrong */
		popup_message(globals.widgets.top_level,
			      MSG_ERR,
			      "Something's wrong with your XPM file - "
			      "try to load it into an image editor and fix the problem.",
			      "Xpm error: %s - switching toolbar off.",
			      XpmGetErrorString(status));
		sen = insen = NULL;
		resource.expert_mode ^= XPRT_SHOW_TOOLBAR;
		return False;
	    }

	    if (mask != 0) {
		static GC   tops_gc;

		if (first_time) {
		    XGCValues   gcvalues;

		    gcvalues.foreground = color[TOP_SHADOW].pixel;
		    tops_gc = XCreateGC(XtDisplay(globals.widgets.top_level), rootWindow, GCForeground, &gcvalues);
		}

		/* Need to create new Pixmaps with the mask applied. */
		XSetClipMask(XtDisplay(globals.widgets.top_level), bots_gc, mask);
		XSetClipMask(XtDisplay(globals.widgets.top_level), tops_gc, mask);
		XSetClipOrigin(XtDisplay(globals.widgets.top_level), tops_gc, 1, 1);

		*insen = XCreatePixmap(XtDisplay(globals.widgets.top_level), rootWindow, PIXMAP_WIDTH, PIXMAP_HEIGHT,
				       G_depth);

		XFillRectangle(XtDisplay(globals.widgets.top_level), *insen, back_gc, 0, 0,
			       PIXMAP_WIDTH, PIXMAP_HEIGHT);
		XFillRectangle(XtDisplay(globals.widgets.top_level), *insen, tops_gc, 1, 1,
			       PIXMAP_WIDTH - 1, PIXMAP_HEIGHT - 1);
		XFillRectangle(XtDisplay(globals.widgets.top_level), *insen, bots_gc, 0, 0, PIXMAP_WIDTH, PIXMAP_HEIGHT);

		if (iconidx == -1)
		    XFreePixmap(XtDisplay(globals.widgets.top_level), map);
	    }

	    XpmFreeAttributes(&attr);
	}
    }
    
    first_time = False;
    return True;
}
Пример #10
0
int
main(int argc, char **argv)
{
  Widget toplevel, rc, one;
  XtAppContext app;

  XtSetLanguageProc(NULL, NULL, NULL);

  toplevel = XtVaAppInitialize(&app, "BubbleButtonTest", NULL, 0, &argc, argv, NULL, NULL);

  rc = XmCreateRowColumn(toplevel, "RC", NULL, 0);

  one = XltCreateBubbleButton(rc, "BubbleButton1", NULL, 0);
  XtAddCallback(one, XmNactivateCallback, (XtCallbackProc)Callback, NULL);
  {
  XmString string;

  string = XmStringCreateSimple("MouseOver");
  XtVaSetValues(one,
  	XmNalignment, XmALIGNMENT_CENTER,
  	XltNmouseOverString, string,
  	NULL);
  XmStringFree(string);
  }
  XtManageChild(one);
  one = XltCreateBubbleButton(rc, "BubbleButton2", NULL, 0);
  {
    Pixmap pixmap;
    Pixmap pixmap_insens;
    XpmAttributes attrib;
    GC gc;

    {
	XpmColorSymbol colors[1];

	XtVaGetValues(one,
		      XmNbackground, &colors[0].pixel,
		      NULL);
	colors[0].name = NULL;
	colors[0].value = "None";
	attrib.valuemask = XpmCloseness | XpmColorSymbols;
	attrib.closeness = 40000;
	attrib.colorsymbols = colors;
	attrib.numsymbols = 1;
	XpmCreatePixmapFromData(XtDisplay(one),
				XRootWindowOfScreen(XtScreen(one)),
				dates,
				&pixmap,
				NULL,
				&attrib);

	pixmap_insens = XCreatePixmap(XtDisplay(one),
				      pixmap,
				      attrib.width,
				      attrib.height,
				      DefaultDepthOfScreen(XtScreen(one)));
	gc = XDefaultGCOfScreen(XtScreen(one));
	XSetFunction(XtDisplay(one),gc,GXcopy);
	XCopyArea(XtDisplay(one),
		  pixmap,
		  pixmap_insens,
		  gc,
		  0, 0,
		  attrib.width, attrib.height,
		  0, 0);
	XSetFillStyle(XtDisplay(one), gc, FillStippled);
	XSetStipple(XtDisplay(one), gc,
		    XmGetPixmapByDepth(XtScreen(one),
				       "25_foreground",
				       1 /*WhitePixelOfScreen(XtScreen(ToolBar))*/,
				       0 /*BlackPixelOfScreen(XtScreen(ToolBar))*/,
				       1));
	XFillRectangle(XtDisplay(one),
		       pixmap_insens,
		       gc,
		       0, 0,
		       attrib.width + 1, attrib.height + 1);

	XpmFreeAttributes(&attrib);

	XtVaSetValues(one,
		      XmNalignment, XmALIGNMENT_CENTER,
		      XmNlabelType, XmPIXMAP,
		      XmNlabelPixmap, pixmap,
		      XltNmouseOverPixmap, pixmap_insens,
		      NULL);
    }
  }
  XtAddCallback(one, XmNactivateCallback, (XtCallbackProc)Callback, NULL);
  XtManageChild(one);

  XtManageChild(rc);

  XtRealizeWidget(toplevel);
  XtAppMainLoop(app);

  exit(0);
}
Пример #11
0
Icon *ReadIcon( char *fn, Icon *icon, Bool err )
{
	XWindowAttributes root_attr;
	XpmAttributes attr;
	int x, y, xhot, yhot;
	Pixmap bitmap;
	Icon *newicon;
	char *path;

	if( icon==NULL )		newicon = (Icon *)calloc( 1, sizeof(Icon) );
	else		newicon = icon;
	if((path = LookUpFiles( Scr.IconPath, fn, R_OK ))==NULL ){
		if( err )
			DrawErrMsgOnMenu( "Can't Find file ", fn );
		return NULL;
	}
	XGetWindowAttributes(dpy,Scr.Root,&root_attr); 
	attr.colormap = root_attr.colormap;
	attr.closeness = 40000; /* Allow for "similar" colors */
	attr.valuemask = XpmSize | XpmReturnPixels | XpmColormap | XpmCloseness;
	if( XpmReadFileToPixmap( dpy, Scr.Root, path,
						   &newicon->icon, &newicon->mask,
						   &attr ) != XpmSuccess &&
       XReadBitmapFile( dpy, Scr.Root, path, &newicon->width, &newicon->height,
					   &bitmap, &xhot, &yhot) !=BitmapSuccess ){
 		if( err )
			DrawErrMsgOnMenu( "Can't Read ICON ", fn );
		if( icon==NULL )
			free( newicon );
		newicon = NULL;
	}
	else{
		if( newicon->icon ){
			newicon->width = attr.width;
			newicon->height = attr.height;
			newicon->kind = PIXMAP;
		}
		else{
			newicon->icon = XCreatePixmap( dpy, Scr.Root,
										  newicon->width, newicon->height,
										  Scr.d_depth );
			newicon->mask = XCreatePixmap( dpy, Scr.Root,
										  newicon->width, newicon->height,
										  Scr.d_depth );
			XCopyPlane( dpy, bitmap, newicon->icon, Scr.BlackGC, 0, 0,
					   newicon->width, newicon->height, 0, 0, 1 );
			XCopyPlane( dpy, bitmap, newicon->mask, Scr.WhiteGC, 0, 0,
					   newicon->width, newicon->height, 0, 0, 1 );

			newicon->kind = BITMAP;
			XFreePixmap( dpy, bitmap );
		}
		newicon->lighticon = XCreatePixmap( dpy, newicon->icon,
										   newicon->width, newicon->height,
										   Scr.d_depth );
		XCopyArea( dpy, newicon->icon, newicon->lighticon,
				  DefaultGC( dpy, Scr.screen ),
				  0, 0, attr.width, attr.height, 0, 0 );
		for( y=0; y<newicon->height; y++ )
			for( x=y%2; x<newicon->width; x+=2 )
				XDrawPoint( dpy, newicon->lighticon, Scr.WhiteGC, x, y );
	}
	if( path!=NULL )	free( path );

	XpmFreeAttributes( &attr );
	return newicon;
}
Пример #12
0
/*
 * Set the pixmap.
 */
    static void
set_pixmap(XmEnhancedButtonWidget eb)
{
    /* Configure defines XPMATTRIBUTES_TYPE as XpmAttributes or as
     * XpmAttributes_21, depending on what is in Xm/XpmP.h. */
    XPMATTRIBUTES_TYPE   attr;
    Pixmap	    sen_pix;
    Window	    root;
    static XpmColorSymbol color[8] = {
	{"none", "none", 0},
	{"None", "none", 0},
	{"background", NULL, 0},
	{"foreground", NULL, 0},
	{"bottomShadowColor", NULL, 0},
	{"topShadowColor", NULL, 0},
	{"highlightColor", NULL, 0},
	{"armColor", NULL, 0}
    };
    int		    scr;
    Display	    *dpy = XtDisplay(eb);
    int		    x;
    int		    y;
    unsigned int    height, width, border, depth;
    int		    status = 0;
    Pixmap	    mask;
    Pixmap	    pix = None;
    Pixmap	    arm_pix = None;
    Pixmap	    ins_pix = None;
    Pixmap	    high_pix = None;
    char	    **data = (char **) eb->enhancedbutton.pixmap_data;
    char	    *fname = (char *) eb->enhancedbutton.pixmap_file;
    int		    shift;
    GC		    gc;

    /* Make sure there is a default value for the pixmap.
     */
    if (!data)
	return;

    gc = XtGetGC((Widget)eb, (XtGCMask)0, NULL);

    scr = DefaultScreen(dpy);
    root = RootWindow(dpy, scr);

    eb->label.pixmap = None;

    eb->enhancedbutton.pixmap_depth = 0;
    eb->enhancedbutton.pixmap_width = 0;
    eb->enhancedbutton.pixmap_height = 0;
    eb->enhancedbutton.normal_pixmap = None;
    eb->enhancedbutton.armed_pixmap = None;
    eb->enhancedbutton.highlight_pixmap = None;
    eb->enhancedbutton.insensitive_pixmap = None;

    /* We use dynamic colors, get them now. */
    motif_get_toolbar_colors(
	    &eb->core.background_pixel,
	    &eb->primitive.foreground,
	    &eb->primitive.bottom_shadow_color,
	    &eb->primitive.top_shadow_color,
	    &eb->primitive.highlight_color);

    /* Setup color subsititution table. */
    color[0].pixel = eb->core.background_pixel;
    color[1].pixel = eb->core.background_pixel;
    color[2].pixel = eb->core.background_pixel;
    color[3].pixel = eb->primitive.foreground;
    color[4].pixel = eb->core.background_pixel;
    color[5].pixel = eb->primitive.top_shadow_color;
    color[6].pixel = eb->primitive.highlight_color;
    color[7].pixel = eb->pushbutton.arm_color;

    /* Create the "sensitive" pixmap. */
    attr.valuemask = XpmColorSymbols | XpmCloseness;
    attr.closeness = 65535;	/* accuracy isn't crucial */
    attr.colorsymbols = color;
    attr.numsymbols = XtNumber(color);

    if (fname)
	status = XpmReadFileToPixmap(dpy, root, fname, &pix, &mask, &attr);
    if (!fname || status != XpmSuccess)
	status = XpmCreatePixmapFromData(dpy, root, data, &pix, &mask, &attr);

    /* If something failed, we will fill in the default pixmap. */
    if (status != XpmSuccess)
	status = XpmCreatePixmapFromData(dpy, root, blank_xpm, &pix,
								&mask, &attr);

    XpmFreeAttributes(&attr);

    XGetGeometry(dpy, pix, &root, &x, &y, &width, &height, &border, &depth);

    if (eb->enhancedbutton.label_location == (int)XmTOP
	    || eb->enhancedbutton.label_location == (int)XmBOTTOM)
	shift = eb->primitive.shadow_thickness / 2;
    else
	shift = eb->primitive.shadow_thickness / 2;

    if (shift < 1)
	shift = 1;

    sen_pix = XCreatePixmap(dpy, root, width + shift, height + shift, depth);

    XSetForeground(dpy, gc, eb->core.background_pixel);
    XFillRectangle(dpy, sen_pix, gc, 0, 0, width + shift, height + shift);
    XSetClipMask(dpy, gc, mask);
    XSetClipOrigin(dpy, gc, shift, shift);
    XCopyArea(dpy, pix, sen_pix, gc, 0, 0, width, height, shift, shift);

    /* Create the "highlight" pixmap. */
    color[4].pixel = eb->primitive.bottom_shadow_color;
#ifdef XpmAllocColor /* SGI doesn't have it */
    attr.valuemask = XpmColorSymbols | XpmCloseness | XpmAllocColor;
    attr.alloc_color = alloc_color;
#else
    attr.valuemask = XpmColorSymbols | XpmCloseness;
#endif
    attr.closeness = 65535;	/* accuracy isn't crucial */
    attr.colorsymbols = color;
    attr.numsymbols = XtNumber(color);

    status = XpmCreatePixmapFromData(dpy, root, data, &pix, NULL, &attr);
    XpmFreeAttributes(&attr);

    high_pix = XCreatePixmap(dpy, root, width + shift, height + shift, depth);

#if 1
    XSetForeground(dpy, gc, eb->core.background_pixel);
#else
    XSetForeground(dpy, gc, eb->primitive.top_shadow_color);
#endif
    XSetClipMask(dpy, gc, None);
    XFillRectangle(dpy, high_pix, gc, 0, 0, width + shift, height + shift);
    XSetClipMask(dpy, gc, mask);
    XSetClipOrigin(dpy, gc, 0, 0);
    XCopyArea(dpy, pix, high_pix, gc, 0, 0, width, height, 0, 0);

    arm_pix = XCreatePixmap(dpy, pix, width + shift, height + shift, depth);

    if (eb->pushbutton.fill_on_arm)
	XSetForeground(dpy, gc, eb->pushbutton.arm_color);
    else
	XSetForeground(dpy, gc, eb->core.background_pixel);
    XSetClipOrigin(dpy, gc, shift, shift);
    XSetClipMask(dpy, gc, None);
    XFillRectangle(dpy, arm_pix, gc, 0, 0, width + shift, height + shift);
    XSetClipMask(dpy, gc, mask);
    XSetClipOrigin(dpy, gc, 2 * shift, 2 * shift);
    XCopyArea(dpy, pix, arm_pix, gc, 0, 0, width, height, 2 * shift, 2 * shift);

    XFreePixmap(dpy, pix);
    XFreePixmap(dpy, mask);

    /* Create the "insensitive" pixmap. */
    attr.valuemask = XpmColorSymbols | XpmCloseness | XpmColorKey;
    attr.closeness = 65535;	/* accuracy isn't crucial */
    attr.colorsymbols = color;
    attr.numsymbols = sizeof(color) / sizeof(color[0]);
    attr.color_key = XPM_MONO;
    status = XpmCreatePixmapFromData(dpy, root, data, &pix, &mask, &attr);

    /* Need to create new Pixmaps with the mask applied. */

    ins_pix = XCreatePixmap(dpy, root, width + shift, height + shift, depth);

    XSetForeground(dpy, gc, eb->core.background_pixel);
    XSetClipOrigin(dpy, gc, 0, 0);
    XSetClipMask(dpy, gc, None);
    XFillRectangle(dpy, ins_pix, gc, 0, 0, width + shift, height + shift);
    XSetClipMask(dpy, gc, mask);
    XSetForeground(dpy, gc, eb->primitive.top_shadow_color);
    XSetClipOrigin(dpy, gc, 2 * shift, 2 * shift);
    XFillRectangle(dpy, ins_pix, gc, 2 * shift, 2 * shift, width, height);
    XSetForeground(dpy, gc, eb->primitive.bottom_shadow_color);
    XSetClipOrigin(dpy, gc, shift, shift);
    XFillRectangle(dpy, ins_pix, gc, 0, 0, width + shift, height + shift);
    XtReleaseGC((Widget) eb, gc);

    XpmFreeAttributes(&attr);

    eb->enhancedbutton.pixmap_depth = depth;
    eb->enhancedbutton.pixmap_width = width;
    eb->enhancedbutton.pixmap_height = height;
    eb->enhancedbutton.normal_pixmap = sen_pix;
    eb->enhancedbutton.highlight_pixmap = high_pix;
    eb->enhancedbutton.insensitive_pixmap = ins_pix;
    eb->enhancedbutton.armed_pixmap = arm_pix;

    eb->enhancedbutton.doing_setvalues = True;
    eb->enhancedbutton.doing_setvalues = False;

    XFreePixmap(dpy, pix);
    XFreePixmap(dpy, mask);
}
Пример #13
0
/*
 *   main
 */
int main(int argc, char *argv[]) {

struct tm	*gTime, *gmt;
struct stat	fi;
XEvent		event;
Pixmap		NewPixmap, NewShapeMask;
XpmAttributes	Attributes;
Colormap	cmap;
int		n, s, m, dt1, dt2, dt3, len;
int 		Year, Month, Day;
int		Hours, Mins, Secs;
int		i, j, Width, Height, yoff, fd, Flag;
long		CurrentLocalTime;
double		UT, hour24(), jd(), CurrentJD, OldFileUT, FileUT;
char		command[1040], ImageName[256];
int           havePixmap= 0;










    /*
     *  Parse any command line arguments.
     */
    ParseCMDLine(argc, argv);


    /*
     *  Figure out what the name of the image xpm file should be...
     */
    len = strlen(ImageURL);
    for (j = 0, i=0; i<len; ++i){ if (ImageURL[i] == '/') j = i; }
    strcpy(ImageName, ImageURL+j+1);
    sprintf(XpmFileName, "%s/.wmGrabImage/%s.xpm", getenv("HOME"), ImageName);
    sprintf(ImageFileName, "%s/.wmGrabImage/%s", getenv("HOME"), ImageName);


    openXwindow(argc, argv, wmGrabImage_master, wmGrabImage_mask_bits, wmGrabImage_mask_width, wmGrabImage_mask_height);

    cmap = DefaultColormap(display, DefaultScreen(display));



    /*
     *  Loop until we die
     */
    n = 32000;
    s = 32000;
    m = 32000;
    dt1 = 32000;
    dt2 = 32000;
    dt3 = 32000;
    DblClkDelay = 32000;
    UpToDate = 0;
    FileUT = -999.0;
    Flag = 1;
    NewShapeMask = 0;
    Attributes.nalloc_pixels = 0;
    while(1) {




	/*
	 *  Keep track of # of seconds
	 */
	if (m > 100){

	    m = 0;
	    ++dt1;
	    ++dt2;
	    ++dt3;

	} else {

	    /*
	     *  Increment counter
	     */
	    ++m;

	}






	/*
	 *  Double Click Delays
	 *  Keep track of click events. If Delay too long, set GotFirstClick's to False.
	 */
	if (DblClkDelay > 15) {

	    DblClkDelay = 0;
	    GotFirstClick1 = 0; GotDoubleClick1 = 0;
	    GotFirstClick2 = 0; GotDoubleClick2 = 0;
	    GotFirstClick3 = 0; GotDoubleClick3 = 0;

	} else {

	    ++DblClkDelay;

	}














	/*
	 *   Process any pending X events.
	 */
        while(XPending(display)){
            XNextEvent(display, &event);
            switch(event.type){
                case Expose:
                        RedrawWindow();
                        break;
                case ButtonPress:
                        pressEvent(&event.xbutton);
                        break;
                case ButtonRelease:
                        break;
            }
        }












	/*
	 *  Draw window.
	 */
	if (ForceUpdate||Flag){



            /*
             *  Compute Current Julian Date
             */
            CurrentLocalTime = time(CurrentTime);
            gTime = gmtime(&CurrentLocalTime);
            Year  = gTime->tm_year+1900;
            Month = gTime->tm_mon+1;
            Day   = gTime->tm_mday;
            Hours = gTime->tm_hour;
            Mins  = gTime->tm_min;
            Secs  = gTime->tm_sec;
            UT = (double)Hours + (double)Mins/60.0 + (double)Secs/3600.0;
            CurrentJD = jd(Year, Month, Day, UT);


	    /*
	     * Clear window.
	     */
	    copyXPMArea(5, 69, 54, 54, 5, 5);



	    if (havePixmap) {
	      /*
	       * free up the colors, if we alloc'd some before
	       */
	      if (Attributes.nalloc_pixels > 0)
		XFreeColors(display, cmap,  Attributes.alloc_pixels,
			    Attributes.nalloc_pixels, 0);
		/*
		 *  Free last pixmap -- we dont need it anymore...
		 *  A ShapeMask is returned if the Pixmap had the color None used.
		 *  We could probably change Transparent to None to make use of this, but for now,
		 *  lets just ignore it...
		 */
		if ( NewShapeMask != 0 )
		  XFreePixmap(display, NewShapeMask);
		XFreePixmap(display, NewPixmap);

		XpmFreeAttributes(&Attributes);

		havePixmap= 0;
	    }
	    /*
	     *   Grab new pixmap. Accept a reasonable color match.
	     */
	    Attributes.valuemask   = XpmExactColors | XpmCloseness | XpmReturnAllocPixels;
	    Attributes.exactColors = 0;
	    Attributes.closeness   = 40000;
	    if (XpmReadFileToPixmap(display, Root, XpmFileName, &NewPixmap, &NewShapeMask, &Attributes) >= 0){



		Height = Attributes.height;
		Width  = Attributes.width;
		yoff   = (CenterImage) ? (54 - Height)/2 : 0;
	        XCopyArea(display, NewPixmap, wmgen.pixmap, NormalGC, 0, 0, Width, Height, 5, 5+yoff);


		Flag = 0;
		ForceUpdate = 0;
		havePixmap= 1;
	    }






	    /*
	     * Make changes visible
	     */
	    RedrawWindow();



	}





	/*
	 *  Check xpm file status
	 */
	if (dt2 > 1){

	    dt2 = 0;

	    if ( (fd = open(XpmFileName, O_RDONLY)) >= 0 ) {

		fstat(fd, &fi);
		close(fd);
		gmt = gmtime(&fi.st_mtime);
		OldFileUT = FileUT;
		FileUT = (double)gmt->tm_hour + (double)gmt->tm_min/60.0 + (double)gmt->tm_sec/3600.0;
		if (FileUT != OldFileUT) ForceUpdate = 1;

	    }


	}









	/*
	 *  Check every 5 min if the values are not up to date...
	 */

	if (ForceUpdate2||(dt3 > UpdateDELAY)){

	    dt3 = 0;

	    /*
	     *  Execute Perl script to grab the Latest METAR Report
	     */
	    if (ConvertGeometry != NULL)
	      sprintf(command, "GrabImage %s %s &", ImageURL, ConvertGeometry);
	    else
	      sprintf(command, "GrabImage %s &", ImageURL);
	    system(command);

	    ForceUpdate = 1;
	    ForceUpdate2 = 0;

	}





	/*
	 *  Wait for next update
	 */
	usleep(DELAY);


     }



}