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 librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: XtCvtrs.c /main/3 1995/07/14 13:25:38 drk $ */
26 /***********************************************************
27 Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts,
28 and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
32 Permission to use, copy, modify, and distribute this software and its
33 documentation for any purpose and without fee is hereby granted,
34 provided that the above copyright notice appear in all copies and that
35 both that copyright notice and this permission notice appear in
36 supporting documentation, and that the names of Digital or MIT not be
37 used in advertising or publicity pertaining to distribution of the
38 software without specific, written prior permission.
40 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
41 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
42 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
43 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
44 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
45 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
48 ******************************************************************/
50 /* Conversion.c - implementations of resource type conversion procs */
53 #include <X11/Intrinsic.h>
54 #include <X11/IntrinsicP.h>
55 #include <X11/StringDefs.h>
57 #include <X11/keysym.h>
58 #include <X11/Xlocale.h>
63 #define done(type, value) \
65 if (toVal->addr != NULL) { \
66 if (toVal->size < sizeof(type)) { \
67 toVal->size = sizeof(type); \
70 *(type*)(toVal->addr) = (value); \
73 static type static_val; \
74 static_val = (value); \
75 toVal->addr = (XPointer)&static_val; \
77 toVal->size = sizeof(type); \
82 static void FreePixel(
92 static XtConvertArgRec xtColorConvertArgs[] = {
93 {XtWidgetBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.screen),
95 {XtWidgetBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.colormap),
101 DtkshCvtStringToPixel(
107 XtPointer *closure_ret )
109 String str = (String)fromVal->addr;
120 screen = *((Screen **) args[0].addr);
121 colormap = *((Colormap *) args[1].addr);
123 if (DtCompareISOLatin1(str, XtDefaultBackground)) {
124 *closure_ret = False;
125 done(Pixel, WhitePixelOfScreen(screen));
127 if (DtCompareISOLatin1(str, XtDefaultForeground)) {
128 *closure_ret = False;
129 done(Pixel, BlackPixelOfScreen(screen));
132 status = XAllocNamedColor(DisplayOfScreen(screen), colormap,
133 (char*)str, &screenColor, &exactColor);
136 /* Server returns a specific error code but Xlib discards it. Ugh */
137 if (XLookupColor(DisplayOfScreen(screen), colormap, (char*)str,
138 &exactColor, &screenColor)) {
139 *closure_ret = (char*)True;
140 done(Pixel, screenColor.pixel);
143 /* One last chance; see if it is a pixel number */
147 pixelValue = strtoul(str, &p, 0);
152 errmsg = GETMESSAGE(1, 1,
153 "DtkshCvtStringToPixel: The color '%s' is not defined");
154 errbuf = XtMalloc(strlen(errmsg) + strlen(str) + 10);
155 sprintf(errbuf, errmsg, str);
158 *closure_ret = False;
163 *closure_ret = False;
164 done(Pixel, pixelValue);
168 *closure_ret = (char*)True;
169 done(Pixel, screenColor.pixel);
188 screen = *((Screen **) args[0].addr);
189 colormap = *((Colormap *) args[1].addr);
192 XFreeColors( DisplayOfScreen(screen), colormap,
193 (unsigned long*)toVal->addr, 1, (unsigned long)0
203 register unsigned char *ap, *bp;
205 for (ap = (unsigned char *) first, bp = (unsigned char *) second;
206 *ap && *bp; ap++, bp++) {
207 register unsigned char a, b;
209 if ((a = *ap) != (b = *bp)) {
210 /* try lowercasing and try again */
212 if ((a >= XK_A) && (a <= XK_Z))
214 else if ((a >= XK_Agrave) && (a <= XK_Odiaeresis))
215 a += (XK_agrave - XK_Agrave);
216 else if ((a >= XK_Ooblique) && (a <= XK_Thorn))
217 a += (XK_oslash - XK_Ooblique);
219 if ((b >= XK_A) && (b <= XK_Z))
221 else if ((b >= XK_Agrave) && (b <= XK_Odiaeresis))
222 b += (XK_agrave - XK_Agrave);
223 else if ((b >= XK_Ooblique) && (b <= XK_Thorn))
224 b += (XK_oslash - XK_Ooblique);
229 return ((((int) *bp) - ((int) *ap)) == 0);
233 RegisterXtOverrideConverters( void )
235 XtSetTypeConverter(XtRString, XtRPixel,
236 (XtTypeConverter)DtkshCvtStringToPixel,
237 xtColorConvertArgs, XtNumber(xtColorConvertArgs),
238 XtCacheNone, FreePixel);