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