Back to index

tetex-bin  3.0
xicon.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2001 Marcin Dalecki
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a copy
00005  * of this software and associated documentation files (the "Software"), to
00006  * deal in the Software without restriction, including without limitation the
00007  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
00008  * sell copies of the Software, and to permit persons to whom the Software is
00009  * furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included in
00012  * all copies or substantial portions of the Software.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
00017  * PAUL VOJTA OR ANY OTHER AUTHOR OF THIS SOFTWARE BE LIABLE FOR ANY CLAIM,
00018  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00020  * OTHER DEALINGS IN THE SOFTWARE.
00021  *
00022  */
00023 
00024 /*
00025  * Implement a nice and well behaved application icon.
00026  */
00027 
00028 #include "xdvi-config.h"
00029 #include "xdvi.h"
00030 #include "xicon.h"
00031 #include "util.h"
00032 #include "xdvi-debug.h"
00033 
00034 #include <X11/X.h>
00035 #include <X11/Xlib.h>
00036 #include <X11/Xutil.h>
00037 #include <X11/Xos.h>
00038 #include <X11/Xfuncs.h>
00039 #include <X11/Intrinsic.h>
00040 #include <X11/StringDefs.h>
00041 #include <X11/Shell.h>
00042 
00043 #ifdef MOTIF
00044 # include <Xm/XmStrDefs.h>
00045 #endif
00046 
00047 #if defined(HAVE_X11_XPM_H)
00048 # include <X11/xpm.h>
00049 #elif defined(HAVE_XPM_H)
00050 # include <xpm.h>
00051 #elif defined(HAVE_XM_XPMP_H)
00052 # include <Xm/XpmP.h>
00053 #endif
00054 
00055 #include "xdvi.icon"
00056 #include "pixmaps/xdvi32x32.xpm"
00057 #include "pixmaps/xdvi16x16.xpm"
00058 #include "pixmaps/xdvi48x48.xpm"
00059 void
00060 add_icon(Widget top_level,
00061         String title_name,
00062         String icon_name)
00063 {
00064 #if !HAVE_XPM
00065 
00066     static Arg args[] = {
00067        {XtNiconX, (XtArgVal) 0},
00068        {XtNiconY, (XtArgVal) 0},
00069     };
00070     static Pixmap icon_pm;
00071     static Arg temp_args4 = { XtNiconPixmap, (XtArgVal) &icon_pm };
00072 
00073     UNUSED(xdvi16x16_xpm);
00074     UNUSED(xdvi32x32_xpm);
00075     UNUSED(xdvi48x48_xpm);
00076     
00077     if (resource.icon_geometry != NULL) {
00078        int junk;
00079 
00080        (void)XGeometry(DISP, XScreenNumberOfScreen(SCRN),
00081                      resource.icon_geometry, "",
00082                      0, 0, 0, 0, 0,
00083                      (int *)&args[0].value,
00084                      (int *)&args[1].value,
00085                      &junk,
00086                      &junk);
00087        XtSetValues(top_level, args, XtNumber(args));
00088     }
00089     /* Set icon pixmap */
00090     XtGetValues(top_level, &temp_args4, 1);
00091     if (icon_pm == (Pixmap) 0) {
00092        temp_args4.value =
00093            (XtArgVal)XCreateBitmapFromData(DISP,
00094                                        RootWindowOfScreen(SCRN),
00095                                        (const char *)xdvi_bits,
00096                                        xdvi_width,
00097                                        xdvi_height);
00098        XtSetValues(top_level, &temp_args4, 1);
00099     }
00100 #else /* HAVE_XPM */
00101     
00102     /* Use Pixmaps, looking much nicer. */
00103 
00104     static Pixmap   icon = 0;
00105     static Pixmap   icon_mask = 0;
00106     static const char **pixmap_data = xdvi32x32_xpm;
00107     XIconSize     *size;
00108     int                  number_sizes;
00109     Display       *dsp;
00110     Screen        *scr;
00111     XpmAttributes   attr;
00112 
00113     UNUSED(xdvi_bits);
00114     /*
00115      * get the icon size preferred by the window manager
00116      */
00117     if (XGetIconSizes(XtDisplay(top_level), RootWindowOfScreen(SCRN),
00118                     &size, &number_sizes) != 0) {
00119        if (number_sizes > 0) {
00120            if (size->max_height >= 48 && size->max_height >= 48)
00121               pixmap_data = xdvi48x48_xpm;
00122            else if (size->max_height >= 32 && size->max_height >= 32)
00123               pixmap_data = xdvi32x32_xpm;
00124            else if (size->max_height >= 16 && size->max_height >= 16)
00125               pixmap_data = xdvi16x16_xpm;
00126        }
00127     }
00128 
00129     dsp = XtDisplay(top_level);
00130     scr = XtScreen(top_level);
00131 
00132     attr.valuemask = 0L;
00133     attr.valuemask = XpmCloseness | XpmReturnPixels | XpmColormap | XpmDepth | XpmVisual;
00134     attr.closeness = 65535; /* accuracy isn't crucial */
00135     /* use the same visual/colormap/depth as main window, else BadMatch ... */
00136     attr.visual = G_visual;
00137     attr.colormap = G_colormap;
00138     attr.depth = G_depth;
00139 
00140     if (!icon) {
00141        Window rootWindow = XtWindow(globals.widgets.top_level);
00142        ASSERT(rootWindow != 0, "");
00143        XpmCreatePixmapFromData(dsp, rootWindow, (char **)pixmap_data,
00144                             &icon, &icon_mask, &attr);
00145     }
00146 
00147 # ifdef MOTIF
00148     XtVaSetValues(top_level, XmNiconPixmap, icon, XmNiconMask, icon_mask, NULL);
00149 # else
00150     XtVaSetValues(top_level, XtNiconPixmap, icon, XtNiconMask, icon_mask, NULL);
00151 # endif
00152 
00153     XpmFreeAttributes(&attr);
00154 #endif
00155 
00156     {
00157        /* code locality ... */
00158        static Arg args[] = {
00159            { XtNtitle, (XtArgVal) 0 },
00160            { XtNiconName, (XtArgVal) 0 },
00161            { XtNinput, (XtArgVal) True },
00162        };
00163 
00164        args[0].value = (XtArgVal)title_name;
00165        args[1].value = (XtArgVal)icon_name;
00166        XtSetValues(top_level, args, XtNumber(args));
00167     }
00168 }