2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $TOG: icon.c /main/5 1998/01/09 15:29:53 cshi $ */
25 * (c) Copyright 1993, 1994 Hewlett-Packard Company
26 * (c) Copyright 1993, 1994 International Business Machines Corp.
27 * (c) Copyright 1993, 1994 Novell, Inc.
28 * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
31 #define NO_RES_DISPLAY 0
32 #define LOW_RES_DISPLAY 1
33 #define VGA_RES_DISPLAY 2
34 #define MED_RES_DISPLAY 3
35 #define HIGH_RES_DISPLAY 4
37 #define DTCM_STD_ICON "IcCM"
38 #define DTCM_INV_ICON "IcCMinv"
45 /* XXX: Defined in Xm/IconFile.h but the file isn't installed??? */
47 * values for icon magnitude
49 #define XmUNSPECIFIED_ICON_SIZE 0
50 #define XmLARGE_ICON_SIZE 1
51 #define XmMEDIUM_ICON_SIZE 2
52 #define XmSMALL_ICON_SIZE 3
53 #define XmTINY_ICON_SIZE 4
54 extern String XmGetIconFileName(
56 String imageInstanceName,
57 String imageClassName,
61 /* XXX: Private routines, but what are my other choices? */
62 extern Pixmap _DtGetMask(Screen *screen, char *image_name);
63 extern int _DtGetDisplayResolution(Display *disp, int screen);
65 static Boolean load_icon(Calendar *c, IconInfo *icon, char *icon_name, int size, Pixel, Pixel);
76 XIconSize *icon_sizes;
78 if (XGetIconSizes(dpy, XRootWindowOfScreen(screen),
79 &icon_sizes, &icon_size_count) == 0)
82 /* Calendar icons are either 32x32 or 48x48 */
83 if (size == XmLARGE_ICON_SIZE)
88 for (i = 0; i < icon_size_count; i++) {
89 if (icon_sizes[i].min_width <= cal_icon_size &&
90 icon_sizes[i].max_width >= cal_icon_size &&
91 icon_sizes[i].min_height <= cal_icon_size &&
92 icon_sizes[i].max_height >= cal_icon_size) {
98 /* If we are here then WM doesn't want us to use this icon
99 * size. If we are using 48x48 then we can see if 32x32 will
102 if (size == XmLARGE_ICON_SIZE)
105 for (i = 0; i < icon_size_count; i++) {
106 if (icon_sizes[i].min_width <= cal_icon_size &&
107 icon_sizes[i].max_width >= cal_icon_size &&
108 icon_sizes[i].min_height <= cal_icon_size &&
109 icon_sizes[i].max_height >= cal_icon_size) {
112 return (XmMEDIUM_ICON_SIZE);
120 * We load two icons. The main icon used when the tool is iconic and an
121 * inverted icon that is used during flashing when a reminder occurs.
131 Screen *screen = XtScreen(c->frame);
134 c->icon = (IconInfo *) ckalloc(sizeof(IconInfo));
135 if (!c->icon_inverted)
136 c->icon_inverted = (IconInfo *) ckalloc(sizeof(IconInfo));
138 XtVaGetValues(c->canvas,
143 resolution = _DtGetDisplayResolution(XtDisplay(c->frame),
144 XScreenNumberOfScreen(screen));
147 * The CDE spec says we use a large icon in high and medium
148 * resolution. We use a medium size icon in low res.
150 switch (resolution) {
151 case HIGH_RES_DISPLAY:
152 case MED_RES_DISPLAY:
153 size = XmLARGE_ICON_SIZE;
155 case LOW_RES_DISPLAY:
157 size = XmMEDIUM_ICON_SIZE;
161 /* See if the resolution size we have chosen is acceptable by the WM */
162 if (!(size = wm_icon_preference(XtDisplay(c->frame), screen, size))) {
164 c->icon_inverted->icon = 0;
168 if (!load_icon(c, c->icon, DTCM_STD_ICON, size, fg, bg))
172 * If we are color we load a color icon that has been inverted
173 * by a graphic's artist. If we are mono or reduced color we take
174 * our one bit deep pixmap and invert it ourself by switching fg and
177 if (c->icon->icon_depth >= 8) {
178 if (!load_icon(c, c->icon_inverted, DTCM_INV_ICON, size,
182 /* Reverse fg/bg on STD_ICON to get inverted icon. */
183 /* XXX: This probably won't work on 1 < depth < 8 visuals */
184 if (!load_icon(c, c->icon_inverted, DTCM_STD_ICON, size,
203 unsigned int border_width;
204 Screen *screen = XtScreen(c->frame);
206 if (!(icon_filename = XmGetIconFileName(screen, NULL, icon_name,
212 if ((icon->icon = XmGetPixmap(screen, icon_filename, fg, bg)) ==
213 XmUNSPECIFIED_PIXMAP) {
219 if ((icon->icon_mask = _DtGetMask(screen, icon_filename)) ==
220 XmUNSPECIFIED_PIXMAP) {
227 /* Store away the size of the icon */
228 XGetGeometry(XtDisplay(c->frame),
232 &icon->icon_width, &icon->icon_height,
233 &border_width, &icon->icon_depth);
235 XtFree(icon_filename);
248 XmDestroyPixmap(XtScreen(c->frame), icon->icon);
253 XmDestroyPixmap(XtScreen(c->frame), icon->icon_mask);
264 Cal_Font *font = c->fonts->iconfont;
270 Screen *s = XtScreen(c->canvas);
276 if (!(c->icon && c->icon->icon && c->icon->icon_mask))
279 dpy = XtDisplayOfObject(c->frame);
281 current_time = now();
282 XtVaSetValues(c->frame, XmNiconName, months[month(current_time)], NULL);
285 if (c->icon->icon_depth == 1) {
286 XtVaGetValues(c->canvas,
291 fg = BlackPixelOfScreen(s);
292 bg = WhitePixelOfScreen(s);
295 gc_vals.foreground = fg;
296 gc_vals.function = GXcopy;
297 gc_vals.fill_style = FillSolid;
298 gc = XCreateGC(xc->display, c->icon->icon, GCForeground | GCFunction |
299 GCFillStyle, &gc_vals);
301 /* painting new date */
302 /* day of the month */
303 (void) sprintf(buf, "%d", dom(current_time));
304 len = cm_strlen(buf);
305 CalTextExtents(font, buf, len, &nop, &nop, &width, &height);
306 x = c->icon->icon_width/2 - width/2 - 1;
307 y = c->icon->icon_height - 2 * (c->icon->icon_height - height) / 3;
309 CalDrawString(dpy, c->icon->icon, font, gc, x, y, buf, len);
311 gc_vals.foreground = bg;
312 XChangeGC(xc->display, gc, GCForeground, &gc_vals);
313 if (c->icon_inverted && c->icon_inverted->icon
314 && c->icon_inverted->icon_mask)
315 CalDrawString(dpy, c->icon_inverted->icon, font,
318 XFreeGC(xc->display, gc);
323 paint_icon(Calendar *c)
326 /* Free the old pixmaps since they have the wrong date in them. */
327 if (c->icon && c->icon->icon)
328 free_icon(c, c->icon);
329 if (c->icon_inverted && c->icon_inverted->icon)
330 free_icon(c, c->icon_inverted);
332 /* Load the icon, mask and related info into calendar->icon */
333 load_icons(calendar);
337 XtVaSetValues(c->frame, XmNiconPixmap, NULL, NULL);
339 if (c->icon && c->icon->icon && c->icon->icon_mask)
340 XtVaSetValues(c->frame,
341 XmNiconPixmap, c->icon->icon,
342 XmNiconMask, c->icon->icon_mask,