home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!munnari.oz.au!mel.dit.csiro.au!yarra!melba.bby.oz.au!gnb
- From: gnb@duke.bby.com.au (Gregory N. Bond)
- Newsgroups: comp.windows.x
- Subject: Re: colored icons, possible?
- Message-ID: <GNB.92Aug17144413@duke.bby.com.au>
- Date: 17 Aug 92 04:44:13 GMT
- References: <m0mFQqv-0000DMC@sparc.conware.de>
- Sender: usenet@melba.bby.oz.au (news READER id)
- Organization: Burdett, Buckeridge & Young, Melbourne, Australia
- Lines: 141
- In-Reply-To: sommer@conware.de's message of 4 Aug 92 18:45:48 GMT
- Nntp-Posting-Host: duke
-
- >>>>> On 4 Aug 92 18:45:48 GMT, sommer@conware.de (Juergen Sommer) said:
- Juergen> is there a way to color icons with more than 2 colors?
- Juergen> Preferably with xview or Xt.
-
- Get and install the XPM library. Then use this code to set the Icon
- window for your top level shell:
-
- Greg.
-
- --------- cut here ----
- static char RCSId[] = "$Header: /a/baby/export/home/gnb/RCS/XpmMakeIcon.c,v 1.2 1992/05/13 06:26:01 shn Exp $";
-
- /*
- * Given a char ** containing an xpm icon, make the current icon
- * window match that pixmap.
- *
- * $Log: XpmMakeIcon.c,v $
- * Revision 1.2 1992/05/13 06:26:01 shn
- * New home: /usr/local/bby/src/lib/xutils
- *
- * Revision 1.1 1992/02/12 04:18:21 gnb
- * Initial revision
- *
- *
- */
-
-
- #include <stdio.h>
- #ifdef __STDC__
- #include <stdlib.h>
- #else
- #define const /**/
- #endif
- #include <strings.h>
-
- #include <X11/Intrinsic.h>
- #include <X11/Shell.h> /* for the iconWindow define */
- #include <X11/xpm.h>
- #include "xutils.h"
-
- extern void bzero P((void *, size_t));
-
- /*
- * Set the icon from the given pixmap and attributes. Make sure the
- * icon window is big enough. Free the resources we sucked in in the
- * process. Guts taken from the SetIconPixmap routine, stolen from
- * Heller pp 588-589.
- */
- static void set_icon P((Widget, Pixmap, XpmAttributes *));
- static void set_icon(shell, pm, attr)
- Widget shell;
- Pixmap pm;
- XpmAttributes *attr;
- {
- Window window;
- Display *dpy = XtDisplay(shell);
- Screen *scr = XtScreen(shell);
-
- /* Get the current icon window (if any) */
- XtVaGetValues(shell, XtNiconWindow, &window, NULL);
-
- if (!window) {
- /* Create one. as big as the image requires. */
- window = XCreateSimpleWindow(dpy, RootWindowOfScreen(scr),
- 0, 0, attr->width,
- attr->height, (unsigned)0,
- CopyFromParent, CopyFromParent);
- if (window)
- /* Now tell the shell this is our iconWindow */
- XtVaSetValues(shell, XtNiconWindow, window, NULL);
- } else {
- /* Make the window the correct size */
- XResizeWindow(dpy, window, attr->width, attr->height);
- }
-
- if (!window) {
- /*
- * Can't create window etc; rely instead on the iconPixmap
- * resource - which hopefully wont get a Bad_Match
- */
- XtVaSetValues(shell, XtNiconPixmap, pm, NULL);
- } else {
- /*
- * Set the window's background pixmap to out image, then
- * refresh it
- */
- XSetWindowBackgroundPixmap(dpy, window, pm);
- XClearWindow(dpy, window);
- }
-
- /* Now delete all the allocated stuff */
- XFreePixmap(dpy, pm);
- XpmFreeAttributes(attr);
- }
-
-
- /*
- * Two ways of accessing it - data and file
- */
-
- void XpmMakeIconFromData(shell, xpm_data)
- Widget shell;
- char **xpm_data;
- {
- int ret;
- Pixmap pm;
- XpmAttributes attr;
-
- if (!XtWindow(shell)) XtRealizeWidget(shell);
-
- bzero(&attr, sizeof (XpmAttributes));
- ret = XpmCreatePixmapFromData(XtDisplay(shell), XtWindow(shell),
- xpm_data, &pm, NULL, &attr);
- if (ret == XpmSuccess)
- set_icon(shell, pm, &attr);
- }
-
- void XpmMakeIconFromFile(shell, xpm_file)
- Widget shell;
- const char *xpm_file;
- {
- int ret = *RCSId;
- Pixmap pm;
- XpmAttributes attr;
-
- if (!XtWindow(shell)) XtRealizeWidget(shell);
-
- bzero((char *)&attr, sizeof (XpmAttributes));
- ret = XpmReadFileToPixmap(XtDisplay(shell),
- XtWindow(shell), xpm_file,
- &pm, NULL, &attr);
- if (ret == XpmSuccess)
- set_icon(shell, pm, &attr);
- }
-
-
- ---- cut here --------
- --
- Gregory Bond <gnb@bby.com.au> Burdett Buckeridge & Young Ltd Melbourne Australia
- ``USL has never sold long distance. You're going after the wrong men in black
- hats. (Or, in the case of Plan 9, black space suits)'' - Tom Limoncelli
-