1/*
2 * Copyright (c) 1998 by The XFree86 Project, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17 * THE XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 *
22 * Except as contained in this notice, the name of the XFree86 Project shall
23 * not be used in advertising or otherwise to promote the sale, use or other
24 * dealings in this Software without prior written authorization from the
25 * XFree86 Project.
26 */
27
28#ifdef HAVE_CONFIG_H
29#include <config.h>
30#endif
31#include <stdio.h>
32#include <X11/IntrinsicP.h>
33#include <X11/StringDefs.h>
34#include <X11/Xmu/CharSet.h>
35#include <X11/Xaw/Simple.h>
36#include <X11/Xaw/XawInit.h>
37#include "Private.h"
38
39#ifndef OLDXAW
40
41/*
42 * Definitions
43 */
44#define done(type, value)			\
45{						\
46  if (toVal->addr != NULL)			\
47    {						\
48      if (toVal->size < sizeof(type))		\
49	{					\
50	  toVal->size = sizeof(type);		\
51	  return (False);			\
52	}					\
53      *(type *)(toVal->addr) = (value);		\
54    }						\
55  else						\
56    {						\
57      static type static_val;			\
58						\
59      static_val = (value);			\
60      toVal->addr = (XPointer)&static_val;	\
61    }						\
62  toVal->size = sizeof(type);			\
63  return (True);				\
64}
65
66#define string_done(value)			\
67{						\
68  if (toVal->addr != NULL)			\
69    {						\
70      if (toVal->size < size)			\
71	{					\
72	  toVal->size = size;			\
73	  return (False);			\
74	}					\
75      strcpy((char *)toVal->addr, (value));	\
76    }						\
77  else						\
78    toVal->addr = (XPointer)(value);		\
79  toVal->size = size;				\
80  return (True);				\
81}
82
83/*
84 * Prototypes
85 */
86static Boolean _XawCvtAtomToString(Display*, XrmValue*, Cardinal*,
87				   XrmValue*, XrmValue*, XtPointer*);
88static Boolean _XawCvtBooleanToString(Display*, XrmValue*, Cardinal*,
89				      XrmValue*, XrmValue*, XtPointer*);
90static Boolean _XawCvtBoolToString(Display*, XrmValue*, Cardinal*,
91				   XrmValue*, XrmValue*, XtPointer*);
92static Boolean _XawCvtCARD32ToString(Display*, XrmValue*, Cardinal*,
93				     XrmValue*, XrmValue*, XtPointer*);
94static Boolean _XawCvtCardinalToString(Display*, XrmValue*, Cardinal*,
95				       XrmValue*, XrmValue*, XtPointer*);
96static Boolean _XawCvtDimensionToString(Display*, XrmValue*, Cardinal*,
97					XrmValue*, XrmValue*, XtPointer*);
98static Boolean _XawCvtDisplayListToString(Display*, XrmValue*, Cardinal*,
99				    XrmValue*, XrmValue*, XtPointer*);
100static Boolean _XawCvtFontStructToString(Display*, XrmValue*, Cardinal*,
101					 XrmValue*, XrmValue*, XtPointer*);
102static Boolean _XawCvtIntToString(Display*, XrmValue*, Cardinal*,
103					  XrmValue*, XrmValue*, XtPointer*);
104static Boolean _XawCvtPixelToString(Display*, XrmValue*, Cardinal*,
105				    XrmValue*, XrmValue*, XtPointer*);
106static Boolean _XawCvtPixmapToString(Display*, XrmValue*, Cardinal*,
107				     XrmValue*, XrmValue*, XtPointer*);
108static Boolean _XawCvtShortToString(Display*, XrmValue*, Cardinal*,
109				    XrmValue*, XrmValue*, XtPointer*);
110static Boolean _XawCvtPositionToString(Display*, XrmValue*, Cardinal*,
111				       XrmValue*, XrmValue*, XtPointer*);
112static Boolean _XawCvtStringToDisplayList(Display*, XrmValue*, Cardinal*,
113					  XrmValue*, XrmValue*, XtPointer*);
114static Boolean _XawCvtStringToPixmap(Display*, XrmValue*, Cardinal*,
115				     XrmValue*, XrmValue*, XtPointer*);
116static Boolean _XawCvtUnsignedCharToString(Display*, XrmValue*, Cardinal*,
117				     XrmValue*, XrmValue*, XtPointer*);
118static void TypeToStringNoArgsWarning(Display*, String);
119
120/*
121 * Initialization
122 */
123static XtConvertArgRec PixelArgs[] = {
124  {XtWidgetBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.colormap),
125   sizeof(Colormap)},
126};
127
128static XtConvertArgRec DLArgs[] = {
129  {XtWidgetBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.screen),
130   sizeof(Screen *)},
131  {XtWidgetBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.colormap),
132   sizeof(Colormap)},
133  {XtWidgetBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.depth),
134   sizeof(int)},
135};
136#endif /* OLDXAW */
137
138static String XtCToolkitError = "ToolkitError";
139static String XtNconversionError = "conversionError";
140
141#ifndef OLDXAW
142static String XtNwrongParameters = "wrongParameters";
143
144/*
145 * Implementation
146 */
147void
148XawInitializeDefaultConverters(void)
149{
150  static Boolean first_time = True;
151
152  if (first_time == False)
153    return;
154
155  first_time = False;
156
157  /* Replace with more appropriate converters */
158  XtSetTypeConverter(XtRCallback, XtRString, _XawCvtCARD32ToString,
159		     NULL, 0, XtCacheNone, NULL);
160  XtSetTypeConverter(XtRColormap, XtRString, _XawCvtCARD32ToString,
161		     NULL, 0, XtCacheNone, NULL);
162  XtSetTypeConverter(XtRFunction, XtRString, _XawCvtCARD32ToString,
163		     NULL, 0, XtCacheNone, NULL);
164  XtSetTypeConverter(XtRPointer, XtRString, _XawCvtCARD32ToString,
165		     NULL, 0, XtCacheNone, NULL);
166  XtSetTypeConverter(XtRScreen, XtRString, _XawCvtCARD32ToString,
167		     NULL, 0, XtCacheNone, NULL);
168  XtSetTypeConverter(XtRStringArray, XtRString, _XawCvtCARD32ToString,
169		     NULL, 0, XtCacheNone, NULL);
170  XtSetTypeConverter(XtRVisual, XtRString, _XawCvtCARD32ToString,
171		     NULL, 0, XtCacheNone, NULL);
172  XtSetTypeConverter(XtRWidget, XtRString, _XawCvtCARD32ToString,
173		     NULL, 0, XtCacheNone, NULL);
174  XtSetTypeConverter(XtRWidgetList, XtRString, _XawCvtCARD32ToString,
175		     NULL, 0, XtCacheNone, NULL);
176  XtSetTypeConverter(XtRWindow, XtRString, _XawCvtCARD32ToString,
177		     NULL, 0, XtCacheNone, NULL);
178
179  XtSetTypeConverter(XtRAtom, XtRString, _XawCvtAtomToString,
180		     NULL, 0, XtCacheNone, NULL);
181  XtSetTypeConverter(XtRBool, XtRString,  _XawCvtBoolToString,
182		     NULL, 0, XtCacheNone, NULL);
183  XtSetTypeConverter(XtRBoolean, XtRString,  _XawCvtBooleanToString,
184		     NULL, 0,  XtCacheNone, NULL);
185  XtSetTypeConverter(XtRCardinal, XtRString, _XawCvtCardinalToString,
186		     NULL, 0, XtCacheNone, NULL);
187  XtSetTypeConverter(XtRDimension, XtRString, _XawCvtDimensionToString,
188		     NULL, 0, XtCacheNone, NULL);
189  XtSetTypeConverter(XawRDisplayList, XtRString, _XawCvtDisplayListToString,
190		     NULL, 0, XtCacheNone, NULL);
191  XtSetTypeConverter(XtRFontStruct, XtRString, _XawCvtFontStructToString,
192		     NULL, 0, XtCacheNone, NULL);
193  XtSetTypeConverter(XtRInt, XtRString, _XawCvtIntToString,
194		     NULL, 0, XtCacheNone, NULL);
195  XtSetTypeConverter(XtRPixel, XtRString, _XawCvtPixelToString,
196		     &PixelArgs[0], XtNumber(PixelArgs), XtCacheNone, NULL);
197  XtSetTypeConverter(XtRPixmap, XtRString, _XawCvtPixmapToString,
198		     &DLArgs[0], XtNumber(DLArgs), XtCacheNone, NULL);
199  XtSetTypeConverter(XtRPosition, XtRString, _XawCvtPositionToString,
200		     NULL, 0, XtCacheNone,  NULL);
201  XtSetTypeConverter(XtRShort, XtRString, _XawCvtShortToString,
202		     NULL, 0, XtCacheNone,  NULL);
203  XtSetTypeConverter(XtRString, XawRDisplayList, _XawCvtStringToDisplayList,
204		     &DLArgs[0], XtNumber(DLArgs), XtCacheAll, NULL);
205  XtSetTypeConverter(XtRString, XtRPixmap, _XawCvtStringToPixmap,
206		     &DLArgs[0], XtNumber(DLArgs), XtCacheAll, NULL);
207  XtSetTypeConverter(XtRUnsignedChar, XtRString, _XawCvtUnsignedCharToString,
208		     NULL, 0, XtCacheNone, NULL);
209}
210#endif /* OLDXAW */
211
212void
213XawTypeToStringWarning(Display *dpy, String type)
214{
215  char fname[64];
216  String params[1];
217  Cardinal num_params;
218
219  snprintf(fname, sizeof(fname), "cvt%sToString", type);
220
221  params[0] = type;
222  num_params = 1;
223  XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
224		  XtNconversionError, fname, XtCToolkitError,
225		  "Cannot convert %s to String",
226		  params, &num_params);
227}
228
229#ifndef OLDXAW
230static void
231TypeToStringNoArgsWarning(Display *dpy, String type)
232{
233  char fname[64];
234  String params[1];
235  Cardinal num_params;
236
237  snprintf(fname, sizeof(fname), "cvt%sToString", type);
238
239  params[0] = type;
240  num_params = 1;
241  XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
242		  XtNconversionError, fname,
243		  XtCToolkitError,
244		  "%s to String conversion needs no extra arguments",
245		  params, &num_params);
246}
247
248/*ARGSUSED*/
249static Boolean
250_XawCvtBooleanToString(Display *dpy, XrmValue *args _X_UNUSED, Cardinal *num_args,
251		       XrmValue *fromVal, XrmValue *toVal,
252		       XtPointer *converter_data _X_UNUSED)
253{
254  static char buffer[6];
255  Cardinal size;
256
257  if (*num_args != 0)
258    TypeToStringNoArgsWarning(dpy, XtRBoolean);
259
260  snprintf(buffer, sizeof(buffer), "%s",
261	   *(Boolean *)fromVal->addr ? XtEtrue : XtEfalse);
262  size = (Cardinal)(strlen(buffer) + 1);
263
264  string_done(buffer);
265}
266
267/*ARGSUSED*/
268static Boolean
269_XawCvtBoolToString(Display *dpy, XrmValue *args _X_UNUSED, Cardinal *num_args,
270		    XrmValue *fromVal, XrmValue *toVal,
271		    XtPointer *converter_data _X_UNUSED)
272{
273  static char buffer[6];
274  Cardinal size;
275
276  if (*num_args != 0)
277    TypeToStringNoArgsWarning(dpy, XtRBool);
278
279  snprintf(buffer, sizeof(buffer), "%s",
280	   *(Bool *)fromVal->addr ? XtEtrue : XtEfalse);
281  size = (Cardinal)(strlen(buffer) + 1);
282
283  string_done(buffer);
284}
285
286/*ARGSUSED*/
287static Boolean
288_XawCvtPositionToString(Display *dpy, XrmValue *args _X_UNUSED, Cardinal *num_args,
289			XrmValue *fromVal, XrmValue *toVal,
290			XtPointer *converter_data _X_UNUSED)
291{
292  static char buffer[7];
293  Cardinal size;
294
295  if (*num_args != 0)
296    TypeToStringNoArgsWarning(dpy, XtRPosition);
297
298  snprintf(buffer, sizeof(buffer), "%d", *(Position *)fromVal->addr);
299  size = (Cardinal)(strlen(buffer) + 1);
300
301  string_done(buffer);
302}
303
304/*ARGSUSED*/
305static Boolean
306_XawCvtShortToString(Display *dpy, XrmValue *args _X_UNUSED, Cardinal *num_args,
307		     XrmValue *fromVal, XrmValue *toVal,
308		     XtPointer *converter_data _X_UNUSED)
309{
310  static char buffer[7];
311  Cardinal size;
312
313  if (*num_args != 0)
314    TypeToStringNoArgsWarning(dpy, XtRShort);
315
316  snprintf(buffer, sizeof(buffer), "%d", *(short *)fromVal->addr);
317  size = (Cardinal)(strlen(buffer) + 1);
318
319  string_done(buffer);
320}
321
322/*ARGSUSED*/
323static Boolean
324_XawCvtDimensionToString(Display *dpy, XrmValue *args _X_UNUSED, Cardinal *num_args,
325			 XrmValue *fromVal, XrmValue *toVal,
326			 XtPointer *converter_data _X_UNUSED)
327{
328  static char buffer[6];
329  Cardinal size;
330
331  if (*num_args != 0)
332    TypeToStringNoArgsWarning(dpy, XtRDimension);
333
334  snprintf(buffer, sizeof(buffer), "%u", *(Dimension *)fromVal->addr);
335  size = (Cardinal)(strlen(buffer) + 1);
336
337  string_done(buffer);
338}
339
340/*ARGSUSED*/
341static Boolean
342_XawCvtCARD32ToString(Display *dpy, XrmValue *args _X_UNUSED, Cardinal *num_args,
343		      XrmValue *fromVal, XrmValue *toVal,
344		      XtPointer *converter_data _X_UNUSED)
345{
346  static char buffer[11];
347  Cardinal size;
348
349  if (*num_args != 0)
350    TypeToStringNoArgsWarning(dpy, "CARD32");
351
352  snprintf(buffer, sizeof(buffer), "0x%08hx", *(int *)fromVal->addr);
353  size = (Cardinal)(strlen(buffer) + 1);
354
355  string_done(buffer);
356}
357
358/*ARGSUSED*/
359static Boolean
360_XawCvtIntToString(Display *dpy, XrmValue *args _X_UNUSED, Cardinal *num_args,
361		   XrmValue *fromVal, XrmValue *toVal,
362		   XtPointer *converter_data _X_UNUSED)
363{
364  static char buffer[12];
365  Cardinal size;
366
367  if (*num_args != 0)
368    TypeToStringNoArgsWarning(dpy, XtRInt);
369
370  snprintf(buffer, sizeof(buffer), "%d", *(int *)fromVal->addr);
371  size = (Cardinal)(strlen(buffer) + 1);
372
373  string_done(buffer);
374}
375
376/*ARGSUSED*/
377static Boolean
378_XawCvtCardinalToString(Display *dpy, XrmValue *args _X_UNUSED, Cardinal *num_args,
379			XrmValue *fromVal, XrmValue *toVal,
380			XtPointer *converter_data _X_UNUSED)
381{
382  static char buffer[11];
383  Cardinal size;
384
385  if (*num_args != 0)
386    TypeToStringNoArgsWarning(dpy, XtRCardinal);
387
388  snprintf(buffer, sizeof(buffer), "%u", *(Cardinal *)fromVal->addr);
389  size = (Cardinal)(strlen(buffer) + 1);
390
391  string_done(buffer);
392}
393
394/*ARGSUSED*/
395static Boolean
396_XawCvtAtomToString(Display *dpy, XrmValue *args _X_UNUSED, Cardinal *num_args,
397		    XrmValue *fromVal, XrmValue *toVal,
398		    XtPointer *converter_data _X_UNUSED)
399{
400  static char *buffer = NULL;
401  static char *nullatom = (char *)"NULL";
402  Cardinal size;
403  Atom atom;
404
405  if (*num_args != 0)
406    TypeToStringNoArgsWarning(dpy, XtRAtom);
407
408  if (buffer && buffer != nullatom)
409    XFree(buffer);
410
411  atom = *(Atom *)fromVal[0].addr;
412  if (atom == 0)
413    buffer = nullatom;
414  else if ((buffer = XGetAtomName(dpy, *(Atom *)fromVal[0].addr)) == NULL)
415    {
416      XawTypeToStringWarning(dpy, XtRAtom);
417      toVal->addr = NULL;
418      toVal->size = sizeof(String);
419      return (False);
420    }
421
422  size = (Cardinal)(strlen(buffer) + 1);
423
424  string_done(buffer);
425}
426
427/*ARGSUSED*/
428static Boolean
429_XawCvtPixelToString(Display *dpy, XrmValue *args, Cardinal *num_args,
430		     XrmValue *fromVal, XrmValue *toVal,
431		     XtPointer *converter_data _X_UNUSED)
432{
433  static char buffer[19];
434  Cardinal size;
435  Colormap colormap;
436  XColor color;
437
438  if (*num_args != 1)
439    {
440      XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
441		      XtNwrongParameters, "cvtPixelToString",
442		      XtCToolkitError,
443		      "Pixel to String conversion needs colormap argument",
444		      NULL, NULL);
445      return (False);
446    }
447
448  colormap = *(Colormap *)args[0].addr;
449  color.pixel = *(Pixel *)fromVal->addr;
450
451  /* Note:
452   * If we know the visual type, we can calculate the xcolor
453   * without asking Xlib.
454   */
455  XQueryColor(dpy, colormap, &color);
456  snprintf(buffer, sizeof(buffer), "rgb:%04hx/%04hx/%04hx",
457	   color.red, color.green, color.blue);
458  size = (Cardinal)(strlen(buffer) + 1);
459
460  string_done(buffer);
461}
462
463/*ARGSUSED*/
464static Boolean
465_XawCvtFontStructToString(Display *dpy, XrmValue *args _X_UNUSED, Cardinal *num_args,
466			  XrmValue *fromVal, XrmValue *toVal,
467			  XtPointer *converter_data _X_UNUSED)
468{
469  static char buffer[128];
470  Cardinal size;
471  Atom atom;
472  unsigned long value;
473
474  if (*num_args != 0)
475    TypeToStringNoArgsWarning(dpy, XtRFontStruct);
476
477  if ((atom = XInternAtom(dpy, "FONT", True)) == None)
478    return (False);
479
480  size = 0;
481
482  if (XGetFontProperty(*(XFontStruct **)fromVal->addr, atom, &value))
483    {
484      char *tmp = XGetAtomName(dpy, value);
485
486      if (tmp)
487	{
488	  snprintf(buffer, sizeof(buffer), "%s", tmp);
489	  size = (Cardinal)strlen(tmp);
490	  XFree(tmp);
491	}
492    }
493
494  if (size)
495    {
496      ++size;
497    string_done(buffer);
498    }
499
500  XawTypeToStringWarning(dpy, XtRFontStruct);
501
502  return (False);
503}
504
505/*ARGSUSED*/
506static Boolean
507_XawCvtUnsignedCharToString(Display *dpy, XrmValue *args _X_UNUSED, Cardinal *num_args,
508			    XrmValue *fromVal, XrmValue *toVal,
509			    XtPointer *converter_data _X_UNUSED)
510{
511  static char buffer[4];
512  Cardinal size;
513
514  if (*num_args != 0)
515    TypeToStringNoArgsWarning(dpy, XtRUnsignedChar);
516
517  snprintf(buffer, sizeof(buffer), "%u",
518	   *(unsigned char *)fromVal->addr);
519  size = (Cardinal)(strlen(buffer) + 1);
520
521  string_done(buffer);
522}
523
524/*ARGSUSED*/
525static Boolean
526_XawCvtStringToDisplayList(Display *dpy, XrmValue *args, Cardinal *num_args,
527			   XrmValue *fromVal, XrmValue *toVal,
528			   XtPointer *converter_data _X_UNUSED)
529{
530  XawDisplayList *dlist;
531  Screen *screen;
532  Colormap colormap;
533  int depth;
534  String commands;
535
536  if (*num_args != 3)
537    {
538      XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
539		      XtNwrongParameters, "cvtStringToDisplayList",
540		      XtCToolkitError,
541		      "String to DisplayList conversion needs screen, "
542		      "colormap, and depth arguments",
543		      NULL, NULL);
544      return (False);
545    }
546
547  screen     = *(Screen **)args[0].addr;
548  colormap   = *(Colormap *)args[1].addr;
549  depth      = *(int *)args[2].addr;
550
551  commands = (String)(fromVal[0].addr);
552
553  dlist = XawCreateDisplayList(commands, screen, colormap, depth);
554
555  if (!dlist)
556    {
557      XtDisplayStringConversionWarning(dpy, (String)fromVal->addr,
558				       XawRDisplayList);
559      toVal->addr = NULL;
560      toVal->size = sizeof(XawDisplayList*);
561      return (False);
562    }
563
564  done(XawDisplayList*, dlist);
565}
566
567/*ARGSUSED*/
568static Boolean
569_XawCvtDisplayListToString(Display *dpy, XrmValue *args _X_UNUSED, Cardinal *num_args,
570			   XrmValue *fromVal, XrmValue *toVal,
571			   XtPointer *converter_data _X_UNUSED)
572{
573  String buffer;
574  Cardinal size;
575
576  if (*num_args != 0)
577    TypeToStringNoArgsWarning(dpy, XawRDisplayList);
578
579  buffer = XawDisplayListString(*(XawDisplayList **)(fromVal[0].addr));
580  size = (Cardinal)(strlen(buffer) + 1);
581
582  string_done(buffer);
583}
584
585/*ARGSUSED*/
586static Boolean
587_XawCvtStringToPixmap(Display *dpy, XrmValue *args, Cardinal *num_args,
588		      XrmValue *fromVal, XrmValue *toVal,
589		      XtPointer *converter_data _X_UNUSED)
590{
591  XawPixmap *xaw_pixmap;
592  Pixmap pixmap;
593  Screen *screen;
594  Colormap colormap;
595  int depth;
596  String name;
597
598  if (*num_args != 3)
599    {
600      XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
601		      XtNwrongParameters, "cvtStringToPixmap",
602		      XtCToolkitError,
603		      "String to Pixmap conversion needs screen, "
604		      "colormap, and depth arguments",
605		      NULL, NULL);
606      return (False);
607    }
608
609  screen     = *(Screen **)args[0].addr;
610  colormap   = *(Colormap *)args[1].addr;
611  depth      = *(int *)args[2].addr;
612
613  name = (String)(fromVal[0].addr);
614
615  if (XmuCompareISOLatin1(name, "None") == 0)
616    pixmap = None;
617  else if (XmuCompareISOLatin1(name, "ParentRelative") == 0)
618    pixmap = ParentRelative;
619  else if (XmuCompareISOLatin1(name, "XtUnspecifiedPixmap") == 0)
620    pixmap = XtUnspecifiedPixmap;
621  else
622    {
623      xaw_pixmap = XawLoadPixmap(name, screen, colormap, depth);
624      if (!xaw_pixmap)
625	{
626	  XtDisplayStringConversionWarning(dpy, (String)fromVal->addr,
627					   XtRPixmap);
628	  toVal->addr = (XtPointer)XtUnspecifiedPixmap;
629	  toVal->size = sizeof(Pixmap);
630	  return (False);
631	}
632      else
633	pixmap = xaw_pixmap->pixmap;
634    }
635
636  done(Pixmap, pixmap);
637}
638
639/*ARGSUSED*/
640static Boolean
641_XawCvtPixmapToString(Display *dpy, XrmValue *args, Cardinal *num_args,
642		      XrmValue *fromVal, XrmValue *toVal,
643		      XtPointer *converter_data)
644{
645  XawPixmap *xaw_pixmap;
646  Pixmap pixmap;
647  Screen *screen;
648  Colormap colormap;
649  int depth;
650  String buffer = NULL;
651  Cardinal size;
652
653  if (*num_args != 3)
654    {
655      XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
656		      XtNwrongParameters, "cvtPixmapToString",
657		      XtCToolkitError,
658		      "Pixmap to String conversion needs screen, "
659		      "colormap, and depth arguments",
660		      NULL, NULL);
661      return (False);
662    }
663
664  screen     = *(Screen **)args[0].addr;
665  colormap   = *(Colormap *)args[1].addr;
666  depth      = *(int *)args[2].addr;
667
668  pixmap = *(Pixmap *)(fromVal[0].addr);
669
670  switch (pixmap)
671    {
672    case None:
673      buffer = "None";
674      break;
675    case ParentRelative:
676      buffer = "ParentRelative";
677      break;
678    case XtUnspecifiedPixmap:
679      buffer = "XtUnspecifiedPixmap";
680      break;
681    default:
682      xaw_pixmap = XawPixmapFromXPixmap(pixmap, screen, colormap, depth);
683      if (xaw_pixmap)
684	buffer = xaw_pixmap->name;
685      break;
686    }
687
688  if (!buffer)
689    /* Bad Pixmap or Pixmap was not loaded by XawLoadPixmap() */
690    return (_XawCvtCARD32ToString(dpy, args, num_args, fromVal, toVal,
691				  converter_data));
692
693  size = (Cardinal)(strlen(buffer) + 1);
694
695  string_done(buffer);
696}
697
698#endif /* OLDXAW */
699