home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / windows / x / 15294 < prev    next >
Encoding:
Text File  |  1992-08-16  |  4.2 KB  |  155 lines

  1. Path: sparky!uunet!munnari.oz.au!mel.dit.csiro.au!yarra!melba.bby.oz.au!gnb
  2. From: gnb@duke.bby.com.au (Gregory N. Bond)
  3. Newsgroups: comp.windows.x
  4. Subject: Re: colored icons, possible?
  5. Message-ID: <GNB.92Aug17144413@duke.bby.com.au>
  6. Date: 17 Aug 92 04:44:13 GMT
  7. References: <m0mFQqv-0000DMC@sparc.conware.de>
  8. Sender: usenet@melba.bby.oz.au (news READER id)
  9. Organization: Burdett, Buckeridge & Young, Melbourne, Australia
  10. Lines: 141
  11. In-Reply-To: sommer@conware.de's message of 4 Aug 92 18:45:48 GMT
  12. Nntp-Posting-Host: duke
  13.  
  14. >>>>> On 4 Aug 92 18:45:48 GMT, sommer@conware.de (Juergen Sommer) said:
  15. Juergen> is there a way to color icons with more than 2 colors? 
  16. Juergen> Preferably with xview or Xt.
  17.  
  18. Get and install the XPM library.  Then use this code to set the Icon
  19. window for your top level shell:
  20.  
  21. Greg.
  22.  
  23. --------- cut here ----
  24. static char RCSId[] = "$Header: /a/baby/export/home/gnb/RCS/XpmMakeIcon.c,v 1.2 1992/05/13 06:26:01 shn Exp $";
  25.  
  26. /*
  27.  * Given a char ** containing an xpm icon, make the current icon
  28.  * window match that pixmap.
  29.  * 
  30.  * $Log: XpmMakeIcon.c,v $
  31.  * Revision 1.2  1992/05/13  06:26:01  shn
  32.  * New home: /usr/local/bby/src/lib/xutils
  33.  *
  34.  * Revision 1.1  1992/02/12  04:18:21  gnb
  35.  * Initial revision
  36.  *
  37.  * 
  38.  */
  39.  
  40.  
  41. #include <stdio.h>
  42. #ifdef __STDC__
  43. #include <stdlib.h>
  44. #else
  45. #define const /**/
  46. #endif 
  47. #include <strings.h>
  48.  
  49. #include <X11/Intrinsic.h>
  50. #include <X11/Shell.h>        /* for the iconWindow define */
  51. #include <X11/xpm.h>
  52. #include "xutils.h"
  53.  
  54. extern void bzero P((void *, size_t));
  55.  
  56. /*
  57.  * Set the icon from the given pixmap and attributes.  Make sure the
  58.  * icon window is big enough.  Free the resources we sucked in in the
  59.  * process.  Guts taken from the SetIconPixmap routine, stolen from
  60.  * Heller pp 588-589.
  61.  */
  62. static void set_icon P((Widget, Pixmap, XpmAttributes *));
  63. static void set_icon(shell, pm, attr)
  64. Widget shell;
  65. Pixmap pm;
  66. XpmAttributes *attr;
  67. {
  68.      Window window;
  69.      Display *dpy = XtDisplay(shell);
  70.      Screen *scr = XtScreen(shell);
  71.      
  72.      /* Get the current icon window (if any) */
  73.      XtVaGetValues(shell, XtNiconWindow, &window, NULL);
  74.  
  75.      if (!window) {
  76.       /* Create one.  as big as the image requires. */
  77.       window = XCreateSimpleWindow(dpy, RootWindowOfScreen(scr),
  78.                        0, 0, attr->width,
  79.                        attr->height, (unsigned)0,
  80.                        CopyFromParent, CopyFromParent);
  81.       if (window)
  82.            /* Now tell the shell this is our iconWindow */
  83.            XtVaSetValues(shell, XtNiconWindow, window, NULL);
  84.      } else {
  85.       /* Make the window the correct size */
  86.       XResizeWindow(dpy, window, attr->width, attr->height); 
  87.      }
  88.  
  89.      if (!window) {
  90.       /*
  91.        * Can't create window etc; rely instead on the iconPixmap
  92.        * resource - which hopefully wont get a Bad_Match
  93.        */
  94.       XtVaSetValues(shell, XtNiconPixmap, pm, NULL);
  95.      } else {
  96.       /* 
  97.        * Set the window's background pixmap to out image, then
  98.        * refresh it
  99.        */
  100.       XSetWindowBackgroundPixmap(dpy, window, pm);
  101.       XClearWindow(dpy, window);
  102.      }
  103.      
  104.      /* Now delete all the allocated stuff */
  105.      XFreePixmap(dpy, pm);
  106.      XpmFreeAttributes(attr);
  107. }
  108.  
  109.  
  110. /*
  111.  * Two ways of accessing it - data and file
  112.  */
  113.  
  114. void XpmMakeIconFromData(shell, xpm_data)
  115. Widget shell;
  116. char **xpm_data; 
  117. {
  118.      int ret;
  119.      Pixmap pm;
  120.      XpmAttributes attr;
  121.  
  122.      if (!XtWindow(shell)) XtRealizeWidget(shell);
  123.      
  124.      bzero(&attr, sizeof (XpmAttributes)); 
  125.      ret = XpmCreatePixmapFromData(XtDisplay(shell), XtWindow(shell),
  126.                    xpm_data, &pm, NULL, &attr);
  127.      if (ret == XpmSuccess) 
  128.       set_icon(shell, pm, &attr); 
  129. }
  130.  
  131. void XpmMakeIconFromFile(shell, xpm_file)
  132. Widget shell;
  133. const char *xpm_file;
  134. {
  135.      int ret = *RCSId;
  136.      Pixmap pm;
  137.      XpmAttributes attr;
  138.  
  139.      if (!XtWindow(shell)) XtRealizeWidget(shell);
  140.      
  141.      bzero((char *)&attr, sizeof (XpmAttributes)); 
  142.      ret = XpmReadFileToPixmap(XtDisplay(shell),
  143.                    XtWindow(shell), xpm_file,
  144.                    &pm, NULL, &attr);
  145.      if (ret == XpmSuccess) 
  146.       set_icon(shell, pm, &attr); 
  147. }
  148.  
  149.  
  150. ---- cut here --------
  151. --
  152. Gregory Bond <gnb@bby.com.au> Burdett Buckeridge & Young Ltd Melbourne Australia
  153. ``USL has never sold long distance.  You're going after the wrong men in black 
  154.   hats.  (Or, in the case of Plan 9, black space suits)'' - Tom Limoncelli
  155.