Converters.c revision 7a84e134
17a84e134Smrg/*
27a84e134Smrg * Copyright (c) 1998 by The XFree86 Project, Inc.
37a84e134Smrg *
47a84e134Smrg * Permission is hereby granted, free of charge, to any person obtaining a
57a84e134Smrg * copy of this software and associated documentation files (the "Software"),
67a84e134Smrg * to deal in the Software without restriction, including without limitation
77a84e134Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
87a84e134Smrg * and/or sell copies of the Software, and to permit persons to whom the
97a84e134Smrg * Software is furnished to do so, subject to the following conditions:
107a84e134Smrg *
117a84e134Smrg * The above copyright notice and this permission notice shall be included in
127a84e134Smrg * all copies or substantial portions of the Software.
137a84e134Smrg *
147a84e134Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
157a84e134Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
167a84e134Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
177a84e134Smrg * THE XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
187a84e134Smrg * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
197a84e134Smrg * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
207a84e134Smrg * SOFTWARE.
217a84e134Smrg *
227a84e134Smrg * Except as contained in this notice, the name of the XFree86 Project shall
237a84e134Smrg * not be used in advertising or otherwise to promote the sale, use or other
247a84e134Smrg * dealings in this Software without prior written authorization from the
257a84e134Smrg * XFree86 Project.
267a84e134Smrg */
277a84e134Smrg
287a84e134Smrg/* $XFree86: xc/lib/Xaw/Converters.c,v 3.13 1999/06/06 08:47:54 dawes Exp $ */
297a84e134Smrg
307a84e134Smrg#ifdef HAVE_CONFIG_H
317a84e134Smrg#include <config.h>
327a84e134Smrg#endif
337a84e134Smrg#include <stdio.h>
347a84e134Smrg#include <X11/IntrinsicP.h>
357a84e134Smrg#include <X11/StringDefs.h>
367a84e134Smrg#include <X11/Xmu/CharSet.h>
377a84e134Smrg#include <X11/Xmu/SysUtil.h>
387a84e134Smrg#include <X11/Xaw/Simple.h>
397a84e134Smrg#include <X11/Xaw/XawInit.h>
407a84e134Smrg#include "Private.h"
417a84e134Smrg
427a84e134Smrg#ifndef OLDXAW
437a84e134Smrg
447a84e134Smrg/*
457a84e134Smrg * Definitions
467a84e134Smrg */
477a84e134Smrg#define done(type, value)			\
487a84e134Smrg{						\
497a84e134Smrg  if (toVal->addr != NULL)			\
507a84e134Smrg    {						\
517a84e134Smrg      if (toVal->size < sizeof(type))		\
527a84e134Smrg	{					\
537a84e134Smrg	  toVal->size = sizeof(type);		\
547a84e134Smrg	  return (False);			\
557a84e134Smrg	}					\
567a84e134Smrg      *(type *)(toVal->addr) = (value);		\
577a84e134Smrg    }						\
587a84e134Smrg  else						\
597a84e134Smrg    {						\
607a84e134Smrg      static type static_val;			\
617a84e134Smrg						\
627a84e134Smrg      static_val = (value);			\
637a84e134Smrg      toVal->addr = (XPointer)&static_val;	\
647a84e134Smrg    }						\
657a84e134Smrg  toVal->size = sizeof(type);			\
667a84e134Smrg  return (True);				\
677a84e134Smrg}
687a84e134Smrg
697a84e134Smrg#define string_done(value)			\
707a84e134Smrg{						\
717a84e134Smrg  if (toVal->addr != NULL)			\
727a84e134Smrg    {						\
737a84e134Smrg      if (toVal->size < size)			\
747a84e134Smrg	{					\
757a84e134Smrg	  toVal->size = size;			\
767a84e134Smrg	  return (False);			\
777a84e134Smrg	}					\
787a84e134Smrg      strcpy((char *)toVal->addr, (value));	\
797a84e134Smrg    }						\
807a84e134Smrg  else						\
817a84e134Smrg    toVal->addr = (XPointer)(value);		\
827a84e134Smrg  toVal->size = size;				\
837a84e134Smrg  return (True);				\
847a84e134Smrg}
857a84e134Smrg
867a84e134Smrg/*
877a84e134Smrg * Prototypes
887a84e134Smrg */
897a84e134Smrgstatic Boolean _XawCvtAtomToString(Display*, XrmValue*, Cardinal*,
907a84e134Smrg				   XrmValue*, XrmValue*, XtPointer*);
917a84e134Smrgstatic Boolean _XawCvtBooleanToString(Display*, XrmValue*, Cardinal*,
927a84e134Smrg				      XrmValue*, XrmValue*, XtPointer*);
937a84e134Smrgstatic Boolean _XawCvtBoolToString(Display*, XrmValue*, Cardinal*,
947a84e134Smrg				   XrmValue*, XrmValue*, XtPointer*);
957a84e134Smrgstatic Boolean _XawCvtCARD32ToString(Display*, XrmValue*, Cardinal*,
967a84e134Smrg				     XrmValue*, XrmValue*, XtPointer*);
977a84e134Smrgstatic Boolean _XawCvtCardinalToString(Display*, XrmValue*, Cardinal*,
987a84e134Smrg				       XrmValue*, XrmValue*, XtPointer*);
997a84e134Smrgstatic Boolean _XawCvtDimensionToString(Display*, XrmValue*, Cardinal*,
1007a84e134Smrg					XrmValue*, XrmValue*, XtPointer*);
1017a84e134Smrgstatic Boolean _XawCvtDisplayListToString(Display*, XrmValue*, Cardinal*,
1027a84e134Smrg				    XrmValue*, XrmValue*, XtPointer*);
1037a84e134Smrgstatic Boolean _XawCvtFontStructToString(Display*, XrmValue*, Cardinal*,
1047a84e134Smrg					 XrmValue*, XrmValue*, XtPointer*);
1057a84e134Smrgstatic Boolean _XawCvtIntToString(Display*, XrmValue*, Cardinal*,
1067a84e134Smrg					  XrmValue*, XrmValue*, XtPointer*);
1077a84e134Smrgstatic Boolean _XawCvtPixelToString(Display*, XrmValue*, Cardinal*,
1087a84e134Smrg				    XrmValue*, XrmValue*, XtPointer*);
1097a84e134Smrgstatic Boolean _XawCvtPixmapToString(Display*, XrmValue*, Cardinal*,
1107a84e134Smrg				     XrmValue*, XrmValue*, XtPointer*);
1117a84e134Smrgstatic Boolean _XawCvtShortToString(Display*, XrmValue*, Cardinal*,
1127a84e134Smrg				    XrmValue*, XrmValue*, XtPointer*);
1137a84e134Smrgstatic Boolean _XawCvtPositionToString(Display*, XrmValue*, Cardinal*,
1147a84e134Smrg				       XrmValue*, XrmValue*, XtPointer*);
1157a84e134Smrgstatic Boolean _XawCvtStringToDisplayList(Display*, XrmValue*, Cardinal*,
1167a84e134Smrg					  XrmValue*, XrmValue*, XtPointer*);
1177a84e134Smrgstatic Boolean _XawCvtStringToPixmap(Display*, XrmValue*, Cardinal*,
1187a84e134Smrg				     XrmValue*, XrmValue*, XtPointer*);
1197a84e134Smrgstatic Boolean _XawCvtUnsignedCharToString(Display*, XrmValue*, Cardinal*,
1207a84e134Smrg				     XrmValue*, XrmValue*, XtPointer*);
1217a84e134Smrgstatic void TypeToStringNoArgsWarning(Display*, String);
1227a84e134Smrg
1237a84e134Smrg/*
1247a84e134Smrg * Initialization
1257a84e134Smrg */
1267a84e134Smrgstatic XtConvertArgRec PixelArgs[] = {
1277a84e134Smrg  {XtWidgetBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.colormap),
1287a84e134Smrg   sizeof(Colormap)},
1297a84e134Smrg};
1307a84e134Smrg
1317a84e134Smrgstatic XtConvertArgRec DLArgs[] = {
1327a84e134Smrg  {XtWidgetBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.screen),
1337a84e134Smrg   sizeof(Screen *)},
1347a84e134Smrg  {XtWidgetBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.colormap),
1357a84e134Smrg   sizeof(Colormap)},
1367a84e134Smrg  {XtWidgetBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.depth),
1377a84e134Smrg   sizeof(int)},
1387a84e134Smrg};
1397a84e134Smrg#endif /* OLDXAW */
1407a84e134Smrg
1417a84e134Smrgstatic String XtCToolkitError = "ToolkitError";
1427a84e134Smrgstatic String XtNconversionError = "conversionError";
1437a84e134Smrg
1447a84e134Smrg#ifndef OLDXAW
1457a84e134Smrgstatic String XtNwrongParameters = "wrongParameters";
1467a84e134Smrg
1477a84e134Smrg/*
1487a84e134Smrg * Implementation
1497a84e134Smrg */
1507a84e134Smrgvoid
1517a84e134SmrgXawInitializeDefaultConverters(void)
1527a84e134Smrg{
1537a84e134Smrg  static Boolean first_time = True;
1547a84e134Smrg
1557a84e134Smrg  if (first_time == False)
1567a84e134Smrg    return;
1577a84e134Smrg
1587a84e134Smrg  first_time = False;
1597a84e134Smrg
1607a84e134Smrg  /* Replace with more apropriate converters */
1617a84e134Smrg  XtSetTypeConverter(XtRCallback, XtRString, _XawCvtCARD32ToString,
1627a84e134Smrg		     NULL, 0, XtCacheNone, NULL);
1637a84e134Smrg  XtSetTypeConverter(XtRColormap, XtRString, _XawCvtCARD32ToString,
1647a84e134Smrg		     NULL, 0, XtCacheNone, NULL);
1657a84e134Smrg  XtSetTypeConverter(XtRFunction, XtRString, _XawCvtCARD32ToString,
1667a84e134Smrg		     NULL, 0, XtCacheNone, NULL);
1677a84e134Smrg  XtSetTypeConverter(XtRPointer, XtRString, _XawCvtCARD32ToString,
1687a84e134Smrg		     NULL, 0, XtCacheNone, NULL);
1697a84e134Smrg  XtSetTypeConverter(XtRScreen, XtRString, _XawCvtCARD32ToString,
1707a84e134Smrg		     NULL, 0, XtCacheNone, NULL);
1717a84e134Smrg  XtSetTypeConverter(XtRStringArray, XtRString, _XawCvtCARD32ToString,
1727a84e134Smrg		     NULL, 0, XtCacheNone, NULL);
1737a84e134Smrg  XtSetTypeConverter(XtRVisual, XtRString, _XawCvtCARD32ToString,
1747a84e134Smrg		     NULL, 0, XtCacheNone, NULL);
1757a84e134Smrg  XtSetTypeConverter(XtRWidget, XtRString, _XawCvtCARD32ToString,
1767a84e134Smrg		     NULL, 0, XtCacheNone, NULL);
1777a84e134Smrg  XtSetTypeConverter(XtRWidgetList, XtRString, _XawCvtCARD32ToString,
1787a84e134Smrg		     NULL, 0, XtCacheNone, NULL);
1797a84e134Smrg  XtSetTypeConverter(XtRWindow, XtRString, _XawCvtCARD32ToString,
1807a84e134Smrg		     NULL, 0, XtCacheNone, NULL);
1817a84e134Smrg
1827a84e134Smrg  XtSetTypeConverter(XtRAtom, XtRString, _XawCvtAtomToString,
1837a84e134Smrg		     NULL, 0, XtCacheNone, NULL);
1847a84e134Smrg  XtSetTypeConverter(XtRBool, XtRString,  _XawCvtBoolToString,
1857a84e134Smrg		     NULL, 0, XtCacheNone, NULL);
1867a84e134Smrg  XtSetTypeConverter(XtRBoolean, XtRString,  _XawCvtBooleanToString,
1877a84e134Smrg		     NULL, 0,  XtCacheNone, NULL);
1887a84e134Smrg  XtSetTypeConverter(XtRCardinal, XtRString, _XawCvtCardinalToString,
1897a84e134Smrg		     NULL, 0, XtCacheNone, NULL);
1907a84e134Smrg  XtSetTypeConverter(XtRDimension, XtRString, _XawCvtDimensionToString,
1917a84e134Smrg		     NULL, 0, XtCacheNone, NULL);
1927a84e134Smrg  XtSetTypeConverter(XawRDisplayList, XtRString, _XawCvtDisplayListToString,
1937a84e134Smrg		     NULL, 0, XtCacheNone, NULL);
1947a84e134Smrg  XtSetTypeConverter(XtRFontStruct, XtRString, _XawCvtFontStructToString,
1957a84e134Smrg		     NULL, 0, XtCacheNone, NULL);
1967a84e134Smrg  XtSetTypeConverter(XtRInt, XtRString, _XawCvtIntToString,
1977a84e134Smrg		     NULL, 0, XtCacheNone, NULL);
1987a84e134Smrg  XtSetTypeConverter(XtRPixel, XtRString, _XawCvtPixelToString,
1997a84e134Smrg		     &PixelArgs[0], XtNumber(PixelArgs), XtCacheNone, NULL);
2007a84e134Smrg  XtSetTypeConverter(XtRPixmap, XtRString, _XawCvtPixmapToString,
2017a84e134Smrg		     &DLArgs[0], XtNumber(DLArgs), XtCacheNone, NULL);
2027a84e134Smrg  XtSetTypeConverter(XtRPosition, XtRString, _XawCvtPositionToString,
2037a84e134Smrg		     NULL, 0, XtCacheNone,  NULL);
2047a84e134Smrg  XtSetTypeConverter(XtRShort, XtRString, _XawCvtShortToString,
2057a84e134Smrg		     NULL, 0, XtCacheNone,  NULL);
2067a84e134Smrg  XtSetTypeConverter(XtRString, XawRDisplayList, _XawCvtStringToDisplayList,
2077a84e134Smrg		     &DLArgs[0], XtNumber(DLArgs), XtCacheAll, NULL);
2087a84e134Smrg  XtSetTypeConverter(XtRString, XtRPixmap, _XawCvtStringToPixmap,
2097a84e134Smrg		     &DLArgs[0], XtNumber(DLArgs), XtCacheAll, NULL);
2107a84e134Smrg  XtSetTypeConverter(XtRUnsignedChar, XtRString, _XawCvtUnsignedCharToString,
2117a84e134Smrg		     NULL, 0, XtCacheNone, NULL);
2127a84e134Smrg}
2137a84e134Smrg#endif /* OLDXAW */
2147a84e134Smrg
2157a84e134Smrgvoid
2167a84e134SmrgXawTypeToStringWarning(Display *dpy, String type)
2177a84e134Smrg{
2187a84e134Smrg  char fname[64];
2197a84e134Smrg  String params[1];
2207a84e134Smrg  Cardinal num_params;
2217a84e134Smrg
2227a84e134Smrg  XmuSnprintf(fname, sizeof(fname), "cvt%sToString", type);
2237a84e134Smrg
2247a84e134Smrg  params[0] = type;
2257a84e134Smrg  num_params = 1;
2267a84e134Smrg  XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
2277a84e134Smrg		  XtNconversionError, fname, XtCToolkitError,
2287a84e134Smrg		  "Cannot convert %s to String",
2297a84e134Smrg		  params, &num_params);
2307a84e134Smrg}
2317a84e134Smrg
2327a84e134Smrg#ifndef OLDXAW
2337a84e134Smrgstatic void
2347a84e134SmrgTypeToStringNoArgsWarning(Display *dpy, String type)
2357a84e134Smrg{
2367a84e134Smrg  char fname[64];
2377a84e134Smrg  String params[1];
2387a84e134Smrg  Cardinal num_params;
2397a84e134Smrg
2407a84e134Smrg  XmuSnprintf(fname, sizeof(fname), "cvt%sToString", type);
2417a84e134Smrg
2427a84e134Smrg  params[0] = type;
2437a84e134Smrg  num_params = 1;
2447a84e134Smrg  XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
2457a84e134Smrg		  XtNconversionError, fname,
2467a84e134Smrg		  XtCToolkitError,
2477a84e134Smrg		  "%s to String conversion needs no extra arguments",
2487a84e134Smrg		  params, &num_params);
2497a84e134Smrg}
2507a84e134Smrg
2517a84e134Smrg/*ARGSUSED*/
2527a84e134Smrgstatic Boolean
2537a84e134Smrg_XawCvtBooleanToString(Display *dpy, XrmValue *args, Cardinal *num_args,
2547a84e134Smrg		       XrmValue *fromVal, XrmValue *toVal,
2557a84e134Smrg		       XtPointer *converter_data)
2567a84e134Smrg{
2577a84e134Smrg  static char buffer[6];
2587a84e134Smrg  Cardinal size;
2597a84e134Smrg
2607a84e134Smrg  if (*num_args != 0)
2617a84e134Smrg    TypeToStringNoArgsWarning(dpy, XtRBoolean);
2627a84e134Smrg
2637a84e134Smrg  XmuSnprintf(buffer, sizeof(buffer), "%s",
2647a84e134Smrg	      *(Boolean *)fromVal->addr ? XtEtrue : XtEfalse);
2657a84e134Smrg  size = strlen(buffer) + 1;
2667a84e134Smrg
2677a84e134Smrg  string_done(buffer);
2687a84e134Smrg}
2697a84e134Smrg
2707a84e134Smrg/*ARGSUSED*/
2717a84e134Smrgstatic Boolean
2727a84e134Smrg_XawCvtBoolToString(Display *dpy, XrmValue *args, Cardinal *num_args,
2737a84e134Smrg		    XrmValue *fromVal, XrmValue *toVal,
2747a84e134Smrg		    XtPointer *converter_data)
2757a84e134Smrg{
2767a84e134Smrg  static char buffer[6];
2777a84e134Smrg  Cardinal size;
2787a84e134Smrg
2797a84e134Smrg  if (*num_args != 0)
2807a84e134Smrg    TypeToStringNoArgsWarning(dpy, XtRBool);
2817a84e134Smrg
2827a84e134Smrg  XmuSnprintf(buffer, sizeof(buffer), "%s",
2837a84e134Smrg	      *(Bool *)fromVal->addr ? XtEtrue : XtEfalse);
2847a84e134Smrg  size = strlen(buffer) + 1;
2857a84e134Smrg
2867a84e134Smrg  string_done(buffer);
2877a84e134Smrg}
2887a84e134Smrg
2897a84e134Smrg/*ARGSUSED*/
2907a84e134Smrgstatic Boolean
2917a84e134Smrg_XawCvtPositionToString(Display *dpy, XrmValue *args, Cardinal *num_args,
2927a84e134Smrg			XrmValue *fromVal, XrmValue *toVal,
2937a84e134Smrg			XtPointer *converter_data)
2947a84e134Smrg{
2957a84e134Smrg  static char buffer[7];
2967a84e134Smrg  Cardinal size;
2977a84e134Smrg
2987a84e134Smrg  if (*num_args != 0)
2997a84e134Smrg    TypeToStringNoArgsWarning(dpy, XtRPosition);
3007a84e134Smrg
3017a84e134Smrg  XmuSnprintf(buffer, sizeof(buffer), "%d", *(Position *)fromVal->addr);
3027a84e134Smrg  size = strlen(buffer) + 1;
3037a84e134Smrg
3047a84e134Smrg  string_done(buffer);
3057a84e134Smrg}
3067a84e134Smrg
3077a84e134Smrg/*ARGSUSED*/
3087a84e134Smrgstatic Boolean
3097a84e134Smrg_XawCvtShortToString(Display *dpy, XrmValue *args, Cardinal *num_args,
3107a84e134Smrg		     XrmValue *fromVal, XrmValue *toVal,
3117a84e134Smrg		     XtPointer *converter_data)
3127a84e134Smrg{
3137a84e134Smrg  static char buffer[7];
3147a84e134Smrg  Cardinal size;
3157a84e134Smrg
3167a84e134Smrg  if (*num_args != 0)
3177a84e134Smrg    TypeToStringNoArgsWarning(dpy, XtRShort);
3187a84e134Smrg
3197a84e134Smrg  XmuSnprintf(buffer, sizeof(buffer), "%d", *(short *)fromVal->addr);
3207a84e134Smrg  size = strlen(buffer) + 1;
3217a84e134Smrg
3227a84e134Smrg  string_done(buffer);
3237a84e134Smrg}
3247a84e134Smrg
3257a84e134Smrg/*ARGSUSED*/
3267a84e134Smrgstatic Boolean
3277a84e134Smrg_XawCvtDimensionToString(Display *dpy, XrmValue *args, Cardinal *num_args,
3287a84e134Smrg			 XrmValue *fromVal, XrmValue *toVal,
3297a84e134Smrg			 XtPointer *converter_data)
3307a84e134Smrg{
3317a84e134Smrg  static char buffer[6];
3327a84e134Smrg  Cardinal size;
3337a84e134Smrg
3347a84e134Smrg  if (*num_args != 0)
3357a84e134Smrg    TypeToStringNoArgsWarning(dpy, XtRDimension);
3367a84e134Smrg
3377a84e134Smrg  XmuSnprintf(buffer, sizeof(buffer), "%u", *(Dimension *)fromVal->addr);
3387a84e134Smrg  size = strlen(buffer) + 1;
3397a84e134Smrg
3407a84e134Smrg  string_done(buffer);
3417a84e134Smrg}
3427a84e134Smrg
3437a84e134Smrg/*ARGSUSED*/
3447a84e134Smrgstatic Boolean
3457a84e134Smrg_XawCvtCARD32ToString(Display *dpy, XrmValue *args, Cardinal *num_args,
3467a84e134Smrg		      XrmValue *fromVal, XrmValue *toVal,
3477a84e134Smrg		      XtPointer *converter_data)
3487a84e134Smrg{
3497a84e134Smrg  static char buffer[11];
3507a84e134Smrg  Cardinal size;
3517a84e134Smrg
3527a84e134Smrg  if (*num_args != 0)
3537a84e134Smrg    TypeToStringNoArgsWarning(dpy, "CARD32");
3547a84e134Smrg
3557a84e134Smrg  XmuSnprintf(buffer, sizeof(buffer), "0x%08hx", *(int *)fromVal->addr);
3567a84e134Smrg  size = strlen(buffer) + 1;
3577a84e134Smrg
3587a84e134Smrg  string_done(buffer);
3597a84e134Smrg}
3607a84e134Smrg
3617a84e134Smrg/*ARGSUSED*/
3627a84e134Smrgstatic Boolean
3637a84e134Smrg_XawCvtIntToString(Display *dpy, XrmValue *args, Cardinal *num_args,
3647a84e134Smrg		   XrmValue *fromVal, XrmValue *toVal,
3657a84e134Smrg		   XtPointer *converter_data)
3667a84e134Smrg{
3677a84e134Smrg  static char buffer[12];
3687a84e134Smrg  Cardinal size;
3697a84e134Smrg
3707a84e134Smrg  if (*num_args != 0)
3717a84e134Smrg    TypeToStringNoArgsWarning(dpy, XtRInt);
3727a84e134Smrg
3737a84e134Smrg  XmuSnprintf(buffer, sizeof(buffer), "%d", *(int *)fromVal->addr);
3747a84e134Smrg  size = strlen(buffer) + 1;
3757a84e134Smrg
3767a84e134Smrg  string_done(buffer);
3777a84e134Smrg}
3787a84e134Smrg
3797a84e134Smrg/*ARGSUSED*/
3807a84e134Smrgstatic Boolean
3817a84e134Smrg_XawCvtCardinalToString(Display *dpy, XrmValue *args, Cardinal *num_args,
3827a84e134Smrg			XrmValue *fromVal, XrmValue *toVal,
3837a84e134Smrg			XtPointer *converter_data)
3847a84e134Smrg{
3857a84e134Smrg  static char buffer[11];
3867a84e134Smrg  Cardinal size;
3877a84e134Smrg
3887a84e134Smrg  if (*num_args != 0)
3897a84e134Smrg    TypeToStringNoArgsWarning(dpy, XtRCardinal);
3907a84e134Smrg
3917a84e134Smrg  XmuSnprintf(buffer, sizeof(buffer), "%u", *(Cardinal *)fromVal->addr);
3927a84e134Smrg  size = strlen(buffer) + 1;
3937a84e134Smrg
3947a84e134Smrg  string_done(buffer);
3957a84e134Smrg}
3967a84e134Smrg
3977a84e134Smrg/*ARGSUSED*/
3987a84e134Smrgstatic Boolean
3997a84e134Smrg_XawCvtAtomToString(Display *dpy, XrmValue *args, Cardinal *num_args,
4007a84e134Smrg		    XrmValue *fromVal, XrmValue *toVal,
4017a84e134Smrg		    XtPointer *converter_data)
4027a84e134Smrg{
4037a84e134Smrg  static char *buffer = NULL;
4047a84e134Smrg  static char *nullatom = "NULL";
4057a84e134Smrg  Cardinal size;
4067a84e134Smrg  Atom atom;
4077a84e134Smrg
4087a84e134Smrg  if (*num_args != 0)
4097a84e134Smrg    TypeToStringNoArgsWarning(dpy, XtRAtom);
4107a84e134Smrg
4117a84e134Smrg  if (buffer && buffer != nullatom)
4127a84e134Smrg    XFree(buffer);
4137a84e134Smrg
4147a84e134Smrg  atom = *(Atom *)fromVal[0].addr;
4157a84e134Smrg  if (atom == 0)
4167a84e134Smrg    buffer = nullatom;
4177a84e134Smrg  else if ((buffer = XGetAtomName(dpy, *(Atom *)fromVal[0].addr)) == NULL)
4187a84e134Smrg    {
4197a84e134Smrg      XawTypeToStringWarning(dpy, XtRAtom);
4207a84e134Smrg      toVal->addr = NULL;
4217a84e134Smrg      toVal->size = sizeof(String);
4227a84e134Smrg      return (False);
4237a84e134Smrg    }
4247a84e134Smrg
4257a84e134Smrg  size = strlen(buffer) + 1;
4267a84e134Smrg
4277a84e134Smrg  string_done(buffer);
4287a84e134Smrg}
4297a84e134Smrg
4307a84e134Smrg/*ARGSUSED*/
4317a84e134Smrgstatic Boolean
4327a84e134Smrg_XawCvtPixelToString(Display *dpy, XrmValue *args, Cardinal *num_args,
4337a84e134Smrg		     XrmValue *fromVal, XrmValue *toVal,
4347a84e134Smrg		     XtPointer *converter_data)
4357a84e134Smrg{
4367a84e134Smrg  static char buffer[19];
4377a84e134Smrg  Cardinal size;
4387a84e134Smrg  Colormap colormap;
4397a84e134Smrg  XColor color;
4407a84e134Smrg
4417a84e134Smrg  if (*num_args != 1)
4427a84e134Smrg    {
4437a84e134Smrg      XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
4447a84e134Smrg		      XtNwrongParameters, "cvtPixelToString",
4457a84e134Smrg		      XtCToolkitError,
4467a84e134Smrg		      "Pixel to String conversion needs colormap argument",
4477a84e134Smrg		      NULL, NULL);
4487a84e134Smrg      return (False);
4497a84e134Smrg    }
4507a84e134Smrg
4517a84e134Smrg  colormap = *(Colormap *)args[0].addr;
4527a84e134Smrg  color.pixel = *(Pixel *)fromVal->addr;
4537a84e134Smrg
4547a84e134Smrg  /* Note:
4557a84e134Smrg   * If we know the visual type, we can calculate the xcolor
4567a84e134Smrg   * without asking Xlib.
4577a84e134Smrg   */
4587a84e134Smrg  XQueryColor(dpy, colormap, &color);
4597a84e134Smrg  XmuSnprintf(buffer, sizeof(buffer), "rgb:%04hx/%04hx/%04hx",
4607a84e134Smrg	      color.red, color.green, color.blue);
4617a84e134Smrg  size = strlen(buffer) + 1;
4627a84e134Smrg
4637a84e134Smrg  string_done(buffer);
4647a84e134Smrg}
4657a84e134Smrg
4667a84e134Smrg/*ARGSUSED*/
4677a84e134Smrgstatic Boolean
4687a84e134Smrg_XawCvtFontStructToString(Display *dpy, XrmValue *args, Cardinal *num_args,
4697a84e134Smrg			  XrmValue *fromVal, XrmValue *toVal,
4707a84e134Smrg			  XtPointer *converter_data)
4717a84e134Smrg{
4727a84e134Smrg  static char buffer[128];
4737a84e134Smrg  Cardinal size;
4747a84e134Smrg  Atom atom;
4757a84e134Smrg  unsigned long value;
4767a84e134Smrg
4777a84e134Smrg  if (*num_args != 0)
4787a84e134Smrg    TypeToStringNoArgsWarning(dpy, XtRFontStruct);
4797a84e134Smrg
4807a84e134Smrg  if ((atom = XInternAtom(dpy, "FONT", True)) == None)
4817a84e134Smrg    return (False);
4827a84e134Smrg
4837a84e134Smrg  size = 0;
4847a84e134Smrg
4857a84e134Smrg  if (XGetFontProperty(*(XFontStruct **)fromVal->addr, atom, &value))
4867a84e134Smrg    {
4877a84e134Smrg      char *tmp = XGetAtomName(dpy, value);
4887a84e134Smrg
4897a84e134Smrg      if (tmp)
4907a84e134Smrg	{
4917a84e134Smrg	  XmuSnprintf(buffer, sizeof(buffer), "%s", tmp);
4927a84e134Smrg	  size = strlen(tmp);
4937a84e134Smrg	  XFree(tmp);
4947a84e134Smrg	}
4957a84e134Smrg    }
4967a84e134Smrg
4977a84e134Smrg  if (size)
4987a84e134Smrg    {
4997a84e134Smrg      ++size;
5007a84e134Smrg    string_done(buffer);
5017a84e134Smrg    }
5027a84e134Smrg
5037a84e134Smrg  XawTypeToStringWarning(dpy, XtRFontStruct);
5047a84e134Smrg
5057a84e134Smrg  return (False);
5067a84e134Smrg}
5077a84e134Smrg
5087a84e134Smrg/*ARGSUSED*/
5097a84e134Smrgstatic Boolean
5107a84e134Smrg_XawCvtUnsignedCharToString(Display *dpy, XrmValue *args, Cardinal *num_args,
5117a84e134Smrg			    XrmValue *fromVal, XrmValue *toVal,
5127a84e134Smrg			    XtPointer *converter_data)
5137a84e134Smrg{
5147a84e134Smrg  static char buffer[4];
5157a84e134Smrg  Cardinal size;
5167a84e134Smrg
5177a84e134Smrg  if (*num_args != 0)
5187a84e134Smrg    TypeToStringNoArgsWarning(dpy, XtRUnsignedChar);
5197a84e134Smrg
5207a84e134Smrg  XmuSnprintf(buffer, sizeof(buffer), "%u",
5217a84e134Smrg	      *(unsigned char *)fromVal->addr);
5227a84e134Smrg  size = strlen(buffer) + 1;
5237a84e134Smrg
5247a84e134Smrg  string_done(buffer);
5257a84e134Smrg}
5267a84e134Smrg
5277a84e134Smrg/*ARGSUSED*/
5287a84e134Smrgstatic Boolean
5297a84e134Smrg_XawCvtStringToDisplayList(Display *dpy, XrmValue *args, Cardinal *num_args,
5307a84e134Smrg			   XrmValue *fromVal, XrmValue *toVal,
5317a84e134Smrg			   XtPointer *converter_data)
5327a84e134Smrg{
5337a84e134Smrg  XawDisplayList *dlist;
5347a84e134Smrg  Screen *screen;
5357a84e134Smrg  Colormap colormap;
5367a84e134Smrg  int depth;
5377a84e134Smrg  String commands;
5387a84e134Smrg
5397a84e134Smrg  if (*num_args != 3)
5407a84e134Smrg    {
5417a84e134Smrg      XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
5427a84e134Smrg		      XtNwrongParameters, "cvtStringToDisplayList",
5437a84e134Smrg		      XtCToolkitError,
5447a84e134Smrg		      "String to DisplayList conversion needs screen, "
5457a84e134Smrg		      "colormap, and depth arguments",
5467a84e134Smrg		      NULL, NULL);
5477a84e134Smrg      return (False);
5487a84e134Smrg    }
5497a84e134Smrg
5507a84e134Smrg  screen     = *(Screen **)args[0].addr;
5517a84e134Smrg  colormap   = *(Colormap *)args[1].addr;
5527a84e134Smrg  depth      = *(int *)args[2].addr;
5537a84e134Smrg
5547a84e134Smrg  commands = (String)(fromVal[0].addr);
5557a84e134Smrg
5567a84e134Smrg  dlist = XawCreateDisplayList(commands, screen, colormap, depth);
5577a84e134Smrg
5587a84e134Smrg  if (!dlist)
5597a84e134Smrg    {
5607a84e134Smrg      XtDisplayStringConversionWarning(dpy, (String)fromVal->addr,
5617a84e134Smrg				       XawRDisplayList);
5627a84e134Smrg      toVal->addr = NULL;
5637a84e134Smrg      toVal->size = sizeof(XawDisplayList*);
5647a84e134Smrg      return (False);
5657a84e134Smrg    }
5667a84e134Smrg
5677a84e134Smrg  done(XawDisplayList*, dlist);
5687a84e134Smrg}
5697a84e134Smrg
5707a84e134Smrg/*ARGSUSED*/
5717a84e134Smrgstatic Boolean
5727a84e134Smrg_XawCvtDisplayListToString(Display *dpy, XrmValue *args, Cardinal *num_args,
5737a84e134Smrg			   XrmValue *fromVal, XrmValue *toVal,
5747a84e134Smrg			   XtPointer *converter_data)
5757a84e134Smrg{
5767a84e134Smrg  String buffer;
5777a84e134Smrg  Cardinal size;
5787a84e134Smrg
5797a84e134Smrg  if (*num_args != 0)
5807a84e134Smrg    TypeToStringNoArgsWarning(dpy, XawRDisplayList);
5817a84e134Smrg
5827a84e134Smrg  buffer = XawDisplayListString(*(XawDisplayList **)(fromVal[0].addr));
5837a84e134Smrg  size = strlen(buffer) + 1;
5847a84e134Smrg
5857a84e134Smrg  string_done(buffer);
5867a84e134Smrg}
5877a84e134Smrg
5887a84e134Smrg/*ARGSUSED*/
5897a84e134Smrgstatic Boolean
5907a84e134Smrg_XawCvtStringToPixmap(Display *dpy, XrmValue *args, Cardinal *num_args,
5917a84e134Smrg		      XrmValue *fromVal, XrmValue *toVal,
5927a84e134Smrg		      XtPointer *converter_data)
5937a84e134Smrg{
5947a84e134Smrg  XawPixmap *xaw_pixmap;
5957a84e134Smrg  Pixmap pixmap;
5967a84e134Smrg  Screen *screen;
5977a84e134Smrg  Colormap colormap;
5987a84e134Smrg  int depth;
5997a84e134Smrg  String name;
6007a84e134Smrg
6017a84e134Smrg  if (*num_args != 3)
6027a84e134Smrg    {
6037a84e134Smrg      XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
6047a84e134Smrg		      XtNwrongParameters, "cvtStringToPixmap",
6057a84e134Smrg		      XtCToolkitError,
6067a84e134Smrg		      "String to Pixmap conversion needs screen, "
6077a84e134Smrg		      "colormap, and depth arguments",
6087a84e134Smrg		      NULL, NULL);
6097a84e134Smrg      return (False);
6107a84e134Smrg    }
6117a84e134Smrg
6127a84e134Smrg  screen     = *(Screen **)args[0].addr;
6137a84e134Smrg  colormap   = *(Colormap *)args[1].addr;
6147a84e134Smrg  depth      = *(int *)args[2].addr;
6157a84e134Smrg
6167a84e134Smrg  name = (String)(fromVal[0].addr);
6177a84e134Smrg
6187a84e134Smrg  if (XmuCompareISOLatin1(name, "None") == 0)
6197a84e134Smrg    pixmap = None;
6207a84e134Smrg  else if (XmuCompareISOLatin1(name, "ParentRelative") == 0)
6217a84e134Smrg    pixmap = ParentRelative;
6227a84e134Smrg  else if (XmuCompareISOLatin1(name, "XtUnspecifiedPixmap") == 0)
6237a84e134Smrg    pixmap = XtUnspecifiedPixmap;
6247a84e134Smrg  else
6257a84e134Smrg    {
6267a84e134Smrg      xaw_pixmap = XawLoadPixmap(name, screen, colormap, depth);
6277a84e134Smrg      if (!xaw_pixmap)
6287a84e134Smrg	{
6297a84e134Smrg	  XtDisplayStringConversionWarning(dpy, (String)fromVal->addr,
6307a84e134Smrg					   XtRPixmap);
6317a84e134Smrg	  toVal->addr = (XtPointer)XtUnspecifiedPixmap;
6327a84e134Smrg	  toVal->size = sizeof(Pixmap);
6337a84e134Smrg	  return (False);
6347a84e134Smrg	}
6357a84e134Smrg      else
6367a84e134Smrg	pixmap = xaw_pixmap->pixmap;
6377a84e134Smrg    }
6387a84e134Smrg
6397a84e134Smrg  done(Pixmap, pixmap);
6407a84e134Smrg}
6417a84e134Smrg
6427a84e134Smrg/*ARGSUSED*/
6437a84e134Smrgstatic Boolean
6447a84e134Smrg_XawCvtPixmapToString(Display *dpy, XrmValue *args, Cardinal *num_args,
6457a84e134Smrg		      XrmValue *fromVal, XrmValue *toVal,
6467a84e134Smrg		      XtPointer *converter_data)
6477a84e134Smrg{
6487a84e134Smrg  XawPixmap *xaw_pixmap;
6497a84e134Smrg  Pixmap pixmap;
6507a84e134Smrg  Screen *screen;
6517a84e134Smrg  Colormap colormap;
6527a84e134Smrg  int depth;
6537a84e134Smrg  String buffer = NULL;
6547a84e134Smrg  Cardinal size;
6557a84e134Smrg
6567a84e134Smrg  if (*num_args != 3)
6577a84e134Smrg    {
6587a84e134Smrg      XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
6597a84e134Smrg		      XtNwrongParameters, "cvtPixmapToString",
6607a84e134Smrg		      XtCToolkitError,
6617a84e134Smrg		      "Pixmap to String conversion needs screen, "
6627a84e134Smrg		      "colormap, and depth arguments",
6637a84e134Smrg		      NULL, NULL);
6647a84e134Smrg      return (False);
6657a84e134Smrg    }
6667a84e134Smrg
6677a84e134Smrg  screen     = *(Screen **)args[0].addr;
6687a84e134Smrg  colormap   = *(Colormap *)args[1].addr;
6697a84e134Smrg  depth      = *(int *)args[2].addr;
6707a84e134Smrg
6717a84e134Smrg  pixmap = *(Pixmap *)(fromVal[0].addr);
6727a84e134Smrg
6737a84e134Smrg  switch (pixmap)
6747a84e134Smrg    {
6757a84e134Smrg    case None:
6767a84e134Smrg      buffer = "None";
6777a84e134Smrg      break;
6787a84e134Smrg    case ParentRelative:
6797a84e134Smrg      buffer = "ParentRelative";
6807a84e134Smrg      break;
6817a84e134Smrg    case XtUnspecifiedPixmap:
6827a84e134Smrg      buffer = "XtUnspecifiedPixmap";
6837a84e134Smrg      break;
6847a84e134Smrg    default:
6857a84e134Smrg      xaw_pixmap = XawPixmapFromXPixmap(pixmap, screen, colormap, depth);
6867a84e134Smrg      if (xaw_pixmap)
6877a84e134Smrg	buffer = xaw_pixmap->name;
6887a84e134Smrg      break;
6897a84e134Smrg    }
6907a84e134Smrg
6917a84e134Smrg  if (!buffer)
6927a84e134Smrg    /* Bad Pixmap or Pixmap was not loaded by XawLoadPixmap() */
6937a84e134Smrg    return (_XawCvtCARD32ToString(dpy, args, num_args, fromVal, toVal,
6947a84e134Smrg				  converter_data));
6957a84e134Smrg
6967a84e134Smrg  size = strlen(buffer) + 1;
6977a84e134Smrg
6987a84e134Smrg  string_done(buffer);
6997a84e134Smrg}
7007a84e134Smrg
7017a84e134Smrg#endif /* OLDXAW */
702