StrToBmap.c

Go to the documentation of this file.
00001 /* $Xorg: StrToBmap.c,v 1.4 2001/02/09 02:03:53 xorgcvs Exp $ */
00002 
00003 /*
00004 
00005 Copyright 1987, 1988, 1998  The Open Group
00006 
00007 Permission to use, copy, modify, distribute, and sell this software and its
00008 documentation for any purpose is hereby granted without fee, provided that
00009 the above copyright notice appear in all copies and that both that
00010 copyright notice and this permission notice appear in supporting
00011 documentation.
00012 
00013 The above copyright notice and this permission notice shall be included in
00014 all copies or substantial portions of the Software.
00015 
00016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
00019 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00020 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00021 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00022 
00023 Except as contained in this notice, the name of The Open Group shall not be
00024 used in advertising or otherwise to promote the sale, use or other dealings
00025 in this Software without prior written authorization from The Open Group.
00026 
00027 */
00028 
00029 /***********************************************************
00030 
00031 Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
00032 
00033                         All Rights Reserved
00034 
00035 Permission to use, copy, modify, and distribute this software and its 
00036 documentation for any purpose and without fee is hereby granted, 
00037 provided that the above copyright notice appear in all copies and that
00038 both that copyright notice and this permission notice appear in 
00039 supporting documentation, and that the name of Digital not be
00040 used in advertising or publicity pertaining to distribution of the
00041 software without specific, written prior permission.  
00042 
00043 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
00044 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
00045 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
00046 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
00047 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
00048 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
00049 SOFTWARE.
00050 
00051 ******************************************************************/
00052 /* $XFree86: xc/lib/Xmu/StrToBmap.c,v 1.5 2001/01/17 19:42:57 dawes Exp $ */
00053 
00054 #include        <X11/Intrinsic.h>
00055 #include        <X11/StringDefs.h>
00056 #include        <X11/Xmu/Converters.h>
00057 #include        <X11/Xmu/Drawing.h>
00058 
00059 
00060 /*
00061  * XmuConvertStringToBitmap:
00062  *
00063  * creates a depth-1 Pixmap suitable for window manager icons.
00064  * "string" represents a bitmap(1) filename which may be absolute,
00065  * or relative to the global resource bitmapFilePath, class
00066  * BitmapFilePath.  If the resource is not defined, the default
00067  * value is the build symbol BITMAPDIR.
00068  *
00069  * shares lots of code with XmuConvertStringToCursor.  
00070  *
00071  * To use, include the following in your ClassInitialize procedure:
00072 
00073 static XtConvertArgRec screenConvertArg[] = {
00074     {XtBaseOffset, (XtPointer) XtOffset(Widget, core.screen), sizeof(Screen *)}
00075 };
00076 
00077     XtAddConverter("String", "Bitmap", XmuCvtStringToBitmap,
00078                    screenConvertArg, XtNumber(screenConvertArg));
00079  *
00080  */
00081 
00082 #define done(address, type) \
00083         { (*toVal).size = sizeof(type); (*toVal).addr = (XPointer) address; }
00084 
00085 
00086 /*ARGSUSED*/
00087 void
00088 XmuCvtStringToBitmap(XrmValuePtr args, Cardinal *num_args,
00089                      XrmValuePtr fromVal, XrmValuePtr toVal)
00090 {
00091     static Pixmap pixmap;               /* static for cvt magic */
00092     char *name = (char *)fromVal->addr;
00093     Screen *screen;
00094     Display *dpy;
00095     XrmDatabase db;
00096     String fn;
00097     unsigned int width, height;
00098     int xhot, yhot;
00099     unsigned char *data;
00100 
00101     if (*num_args != 1)
00102      XtErrorMsg("wrongParameters","cvtStringToBitmap","XtToolkitError",
00103              "String to pixmap conversion needs screen argument",
00104               (String *)NULL, (Cardinal *)NULL);
00105 
00106     if (strcmp(name, "None") == 0) {
00107         pixmap = None;
00108         done(&pixmap, Pixmap);
00109         return;
00110     }
00111 
00112     if (strcmp(name, "ParentRelative") == 0) {
00113         pixmap = ParentRelative;
00114         done(&pixmap, Pixmap);
00115         return;
00116     }
00117 
00118     screen = *((Screen **) args[0].addr);
00119     pixmap = XmuLocateBitmapFile (screen, name,
00120                                   NULL, 0, NULL, NULL, NULL, NULL);
00121     if (pixmap == None) {
00122         dpy = DisplayOfScreen(screen);
00123         db = XrmGetDatabase(dpy);
00124         XrmSetDatabase(dpy, XtScreenDatabase(screen));
00125         fn = XtResolvePathname(dpy, "bitmaps", name, "", NULL, NULL, 0, NULL);
00126         if (!fn)
00127             fn = XtResolvePathname(dpy, "", name, ".xbm", NULL, NULL, 0, NULL);
00128         XrmSetDatabase(dpy, db);
00129         if (fn &&
00130             XmuReadBitmapDataFromFile (fn, &width, &height, &data,
00131                                        &xhot, &yhot) == BitmapSuccess) {
00132             pixmap = XCreatePixmapFromBitmapData (dpy,
00133                                                   RootWindowOfScreen(screen),
00134                                                   (char *) data, width, height,
00135                                                   1, 0, 1);
00136             XFree ((char *)data);
00137         }
00138     }
00139 
00140     if (pixmap != None) {
00141         done (&pixmap, Pixmap);
00142     } else {
00143         XtStringConversionWarning (name, "Pixmap");
00144         return;
00145     }
00146 }
00147 

Generated on Sun Mar 4 15:03:56 2007 for Scilab [trunk] by  doxygen 1.5.1