summaryrefslogtreecommitdiff
path: root/src/Converters.c
blob: 9bd6493c6d2c5af84e4ff85c8b40f3f97a1e1fd9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
/*
 * Copyright (c) 1998 by The XFree86 Project, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *  
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 * Except as contained in this notice, the name of the XFree86 Project shall
 * not be used in advertising or otherwise to promote the sale, use or other
 * dealings in this Software without prior written authorization from the
 * XFree86 Project.
 */

/* $XFree86$ */

#include <stdio.h>
#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
#include <X11/Xmu/CharSet.h>
#include <X11/Xmu/SysUtil.h>
#include <X11/Xaw/Simple.h>
#include <X11/Xaw/XawInit.h>
#include "Private.h"

#ifndef OLDXAW

/*
 * Definitions
 */
#define done(type, value)			\
{						\
  if (toVal->addr != NULL)			\
    {						\
      if (toVal->size < sizeof(type))		\
	{					\
	  toVal->size = sizeof(type);		\
	  return (False);			\
	}					\
      *(type *)(toVal->addr) = (value);		\
    }						\
  else						\
    {						\
      static type static_val;			\
						\
      static_val = (value);			\
      toVal->addr = (XPointer)&static_val;	\
    }						\
  toVal->size = sizeof(type);			\
  return (True);				\
}

#define string_done(value)			\
{						\
  if (toVal->addr != NULL)			\
    {						\
      if (toVal->size < size)			\
	{					\
	  toVal->size = size;			\
	  return (False);			\
	}					\
      strcpy((char *)toVal->addr, (value));	\
    }						\
  else						\
    toVal->addr = (XPointer)(value);		\
  toVal->size = size;				\
  return (True);				\
}

/*
 * Prototypes
 */
static Boolean _XawCvtAtomToString(Display*, XrmValue*, Cardinal*,
				   XrmValue*, XrmValue*, XtPointer*);
static Boolean _XawCvtBooleanToString(Display*, XrmValue*, Cardinal*,
				      XrmValue*, XrmValue*, XtPointer*);
static Boolean _XawCvtBoolToString(Display*, XrmValue*, Cardinal*,
				   XrmValue*, XrmValue*, XtPointer*);
static Boolean _XawCvtCARD32ToString(Display*, XrmValue*, Cardinal*,
				     XrmValue*, XrmValue*, XtPointer*);
static Boolean _XawCvtCardinalToString(Display*, XrmValue*, Cardinal*,
				       XrmValue*, XrmValue*, XtPointer*);
static Boolean _XawCvtDimensionToString(Display*, XrmValue*, Cardinal*,
					XrmValue*, XrmValue*, XtPointer*);
static Boolean _XawCvtDisplayListToString(Display*, XrmValue*, Cardinal*,
				    XrmValue*, XrmValue*, XtPointer*);
static Boolean _XawCvtFontStructToString(Display*, XrmValue*, Cardinal*,
					 XrmValue*, XrmValue*, XtPointer*);
static Boolean _XawCvtIntToString(Display*, XrmValue*, Cardinal*,
					  XrmValue*, XrmValue*, XtPointer*);
static Boolean _XawCvtPixelToString(Display*, XrmValue*, Cardinal*,
				    XrmValue*, XrmValue*, XtPointer*);
static Boolean _XawCvtPixmapToString(Display*, XrmValue*, Cardinal*,
				     XrmValue*, XrmValue*, XtPointer*);
static Boolean _XawCvtShortToString(Display*, XrmValue*, Cardinal*,
				    XrmValue*, XrmValue*, XtPointer*);
static Boolean _XawCvtPositionToString(Display*, XrmValue*, Cardinal*,
				       XrmValue*, XrmValue*, XtPointer*);
static Boolean _XawCvtStringToDisplayList(Display*, XrmValue*, Cardinal*,
					  XrmValue*, XrmValue*, XtPointer*);
static Boolean _XawCvtStringToPixmap(Display*, XrmValue*, Cardinal*,
				     XrmValue*, XrmValue*, XtPointer*);
static Boolean _XawCvtUnsignedCharToString(Display*, XrmValue*, Cardinal*,
				     XrmValue*, XrmValue*, XtPointer*);
static void TypeToStringNoArgsWarning(Display*, String);

/*
 * Initialization
 */
static XtConvertArgRec PixelArgs[] = {
  {XtWidgetBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.colormap),
   sizeof(Colormap)},
};

static XtConvertArgRec DLArgs[] = {
  {XtWidgetBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.screen),
   sizeof(Screen *)},
  {XtWidgetBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.colormap),
   sizeof(Colormap)},
  {XtWidgetBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.depth),
   sizeof(int)},
};
#endif /* OLDXAW */

static String XtCToolkitError = "ToolkitError";
static String XtNconversionError = "conversionError";

#ifndef OLDXAW
static String XtNwrongParameters = "wrongParameters";

/*
 * Implementation
 */
void
XawInitializeDefaultConverters(void)
{
  static Boolean first_time = True;

  if (first_time == False)
    return;

  first_time = False;

  /* Replace with more apropriate converters */
  XtSetTypeConverter(XtRCallback, XtRString, _XawCvtCARD32ToString,
		     NULL, 0, XtCacheNone, NULL);
  XtSetTypeConverter(XtRColormap, XtRString, _XawCvtCARD32ToString,
		     NULL, 0, XtCacheNone, NULL);
  XtSetTypeConverter(XtRFunction, XtRString, _XawCvtCARD32ToString,
		     NULL, 0, XtCacheNone, NULL);
  XtSetTypeConverter(XtRPointer, XtRString, _XawCvtCARD32ToString,
		     NULL, 0, XtCacheNone, NULL);
  XtSetTypeConverter(XtRScreen, XtRString, _XawCvtCARD32ToString,
		     NULL, 0, XtCacheNone, NULL);
  XtSetTypeConverter(XtRStringArray, XtRString, _XawCvtCARD32ToString,
		     NULL, 0, XtCacheNone, NULL);
  XtSetTypeConverter(XtRVisual, XtRString, _XawCvtCARD32ToString,
		     NULL, 0, XtCacheNone, NULL);
  XtSetTypeConverter(XtRWidget, XtRString, _XawCvtCARD32ToString,
		     NULL, 0, XtCacheNone, NULL);
  XtSetTypeConverter(XtRWidgetList, XtRString, _XawCvtCARD32ToString,
		     NULL, 0, XtCacheNone, NULL);
  XtSetTypeConverter(XtRWindow, XtRString, _XawCvtCARD32ToString,
		     NULL, 0, XtCacheNone, NULL);

  XtSetTypeConverter(XtRAtom, XtRString, _XawCvtAtomToString,
		     NULL, 0, XtCacheNone, NULL);
  XtSetTypeConverter(XtRBool, XtRString,  _XawCvtBoolToString,
		     NULL, 0, XtCacheNone, NULL);
  XtSetTypeConverter(XtRBoolean, XtRString,  _XawCvtBooleanToString,
		     NULL, 0,  XtCacheNone, NULL);
  XtSetTypeConverter(XtRCardinal, XtRString, _XawCvtCardinalToString,
		     NULL, 0, XtCacheNone, NULL);
  XtSetTypeConverter(XtRDimension, XtRString, _XawCvtDimensionToString,
		     NULL, 0, XtCacheNone, NULL);
  XtSetTypeConverter(XawRDisplayList, XtRString, _XawCvtDisplayListToString,
		     NULL, 0, XtCacheNone, NULL);
  XtSetTypeConverter(XtRFontStruct, XtRString, _XawCvtFontStructToString,
		     NULL, 0, XtCacheNone, NULL);
  XtSetTypeConverter(XtRInt, XtRString, _XawCvtIntToString,
		     NULL, 0, XtCacheNone, NULL);
  XtSetTypeConverter(XtRPixel, XtRString, _XawCvtPixelToString,
		     &PixelArgs[0], XtNumber(PixelArgs), XtCacheNone, NULL);
  XtSetTypeConverter(XtRPixmap, XtRString, _XawCvtPixmapToString,
		     &DLArgs[0], XtNumber(DLArgs), XtCacheNone, NULL);
  XtSetTypeConverter(XtRPosition, XtRString, _XawCvtPositionToString,
		     NULL, 0, XtCacheNone,  NULL);
  XtSetTypeConverter(XtRShort, XtRString, _XawCvtShortToString,
		     NULL, 0, XtCacheNone,  NULL);
  XtSetTypeConverter(XtRString, XawRDisplayList, _XawCvtStringToDisplayList,
		     &DLArgs[0], XtNumber(DLArgs), XtCacheAll, NULL);
  XtSetTypeConverter(XtRString, XtRPixmap, _XawCvtStringToPixmap,
		     &DLArgs[0], XtNumber(DLArgs), XtCacheAll, NULL);
  XtSetTypeConverter(XtRUnsignedChar, XtRString, _XawCvtUnsignedCharToString,
		     NULL, 0, XtCacheNone, NULL);
}
#endif /* OLDXAW */

void
XawTypeToStringWarning(Display *dpy, String type)
{
  char fname[64];
  String params[1];
  Cardinal num_params;

  XmuSnprintf(fname, sizeof(fname), "cvt%sToString", type);

  params[0] = type;
  num_params = 1;
  XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
		  XtNconversionError, fname, XtCToolkitError,
		  "Cannot convert %s to String",
		  params, &num_params);
}

#ifndef OLDXAW
static void
TypeToStringNoArgsWarning(Display *dpy, String type)
{
  char fname[64];
  String params[1];
  Cardinal num_params;

  XmuSnprintf(fname, sizeof(fname), "cvt%sToString", type);

  params[0] = type;
  num_params = 1;
  XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
		  XtNconversionError, fname,
		  XtCToolkitError,
		  "%s to String conversion needs no extra arguments",
		  params, &num_params);
}

/*ARGSUSED*/
static Boolean
_XawCvtBooleanToString(Display *dpy, XrmValue *args, Cardinal *num_args,
		       XrmValue *fromVal, XrmValue *toVal,
		       XtPointer *converter_data)
{
  static char buffer[6];
  Cardinal size;

  if (*num_args != 0)
    TypeToStringNoArgsWarning(dpy, XtRBoolean);

  XmuSnprintf(buffer, sizeof(buffer), "%s",
	      *(Boolean *)fromVal->addr ? XtEtrue : XtEfalse);
  size = strlen(buffer) + 1;

  string_done(buffer);
}

/*ARGSUSED*/
static Boolean
_XawCvtBoolToString(Display *dpy, XrmValue *args, Cardinal *num_args,
		    XrmValue *fromVal, XrmValue *toVal,
		    XtPointer *converter_data)
{
  static char buffer[6];
  Cardinal size;

  if (*num_args != 0)
    TypeToStringNoArgsWarning(dpy, XtRBool);

  XmuSnprintf(buffer, sizeof(buffer), "%s",
	      *(Bool *)fromVal->addr ? XtEtrue : XtEfalse);
  size = strlen(buffer) + 1;

  string_done(buffer);
}

/*ARGSUSED*/
static Boolean
_XawCvtPositionToString(Display *dpy, XrmValue *args, Cardinal *num_args,
			XrmValue *fromVal, XrmValue *toVal,
			XtPointer *converter_data)
{
  static char buffer[7];
  Cardinal size;

  if (*num_args != 0)
    TypeToStringNoArgsWarning(dpy, XtRPosition);

  XmuSnprintf(buffer, sizeof(buffer), "%d", *(Position *)fromVal->addr);
  size = strlen(buffer) + 1;

  string_done(buffer);
}

/*ARGSUSED*/
static Boolean
_XawCvtShortToString(Display *dpy, XrmValue *args, Cardinal *num_args,
		     XrmValue *fromVal, XrmValue *toVal,
		     XtPointer *converter_data)
{
  static char buffer[7];
  Cardinal size;

  if (*num_args != 0)
    TypeToStringNoArgsWarning(dpy, XtRShort);

  XmuSnprintf(buffer, sizeof(buffer), "%d", *(short *)fromVal->addr);
  size = strlen(buffer) + 1;

  string_done(buffer);
}

/*ARGSUSED*/
static Boolean
_XawCvtDimensionToString(Display *dpy, XrmValue *args, Cardinal *num_args,
			 XrmValue *fromVal, XrmValue *toVal,
			 XtPointer *converter_data)
{
  static char buffer[6];
  Cardinal size;

  if (*num_args != 0)
    TypeToStringNoArgsWarning(dpy, XtRDimension);

  XmuSnprintf(buffer, sizeof(buffer), "%u", *(Dimension *)fromVal->addr);
  size = strlen(buffer) + 1;

  string_done(buffer);
}

/*ARGSUSED*/
static Boolean
_XawCvtCARD32ToString(Display *dpy, XrmValue *args, Cardinal *num_args,
		      XrmValue *fromVal, XrmValue *toVal,
		      XtPointer *converter_data)
{
  static char buffer[11];
  Cardinal size;

  if (*num_args != 0)
    TypeToStringNoArgsWarning(dpy, "CARD32");

  XmuSnprintf(buffer, sizeof(buffer), "0x%08hx", *(int *)fromVal->addr);
  size = strlen(buffer) + 1;

  string_done(buffer);
}

/*ARGSUSED*/
static Boolean
_XawCvtIntToString(Display *dpy, XrmValue *args, Cardinal *num_args,
		   XrmValue *fromVal, XrmValue *toVal,
		   XtPointer *converter_data)
{
  static char buffer[12];
  Cardinal size;

  if (*num_args != 0)
    TypeToStringNoArgsWarning(dpy, XtRInt);

  XmuSnprintf(buffer, sizeof(buffer), "%d", *(int *)fromVal->addr);
  size = strlen(buffer) + 1;

  string_done(buffer);
}

/*ARGSUSED*/
static Boolean
_XawCvtCardinalToString(Display *dpy, XrmValue *args, Cardinal *num_args,
			XrmValue *fromVal, XrmValue *toVal,
			XtPointer *converter_data)
{
  static char buffer[11];
  Cardinal size;

  if (*num_args != 0)
    TypeToStringNoArgsWarning(dpy, XtRCardinal);

  XmuSnprintf(buffer, sizeof(buffer), "%u", *(Cardinal *)fromVal->addr);
  size = strlen(buffer) + 1;

  string_done(buffer);
}

/*ARGSUSED*/
static Boolean
_XawCvtAtomToString(Display *dpy, XrmValue *args, Cardinal *num_args,
		    XrmValue *fromVal, XrmValue *toVal,
		    XtPointer *converter_data)
{
  static char *buffer = NULL;
  static char *nullatom = "NULL";
  Cardinal size;
  Atom atom;

  if (*num_args != 0)
    TypeToStringNoArgsWarning(dpy, XtRAtom);

  if (buffer && buffer != nullatom)
    XFree(buffer);

  atom = *(Atom *)fromVal[0].addr;
  if (atom == 0)
    buffer = nullatom;
  else if ((buffer = XGetAtomName(dpy, *(Atom *)fromVal[0].addr)) == NULL)
    {
      XawTypeToStringWarning(dpy, XtRAtom);
      toVal->addr = NULL;
      toVal->size = sizeof(String);
      return (False);
    }

  size = strlen(buffer) + 1;

  string_done(buffer);
}

/*ARGSUSED*/
static Boolean
_XawCvtPixelToString(Display *dpy, XrmValue *args, Cardinal *num_args,
		     XrmValue *fromVal, XrmValue *toVal,
		     XtPointer *converter_data)
{
  static char buffer[19];
  Cardinal size;
  Colormap colormap;
  XColor color;

  if (*num_args != 1)
    {
      XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
		      XtNwrongParameters, "cvtPixelToString",
		      XtCToolkitError,
		      "Pixel to String conversion needs colormap argument",
		      NULL, NULL);
      return (False);
    }

  colormap = *(Colormap *)args[0].addr;
  color.pixel = *(Pixel *)fromVal->addr;

  /* Note:
   * If we know the visual type, we can calculate the xcolor
   * without asking Xlib.
   */
  XQueryColor(dpy, colormap, &color);
  XmuSnprintf(buffer, sizeof(buffer), "rgb:%04hx/%04hx/%04hx",
	      color.red, color.green, color.blue);
  size = strlen(buffer) + 1;

  string_done(buffer);
}

/*ARGSUSED*/
static Boolean
_XawCvtFontStructToString(Display *dpy, XrmValue *args, Cardinal *num_args,
			  XrmValue *fromVal, XrmValue *toVal,
			  XtPointer *converter_data)
{
  static char buffer[128];
  Cardinal size;
  Atom atom;
  unsigned long value;

  if (*num_args != 0)
    TypeToStringNoArgsWarning(dpy, XtRFontStruct);

  if ((atom = XInternAtom(dpy, "FONT", True)) == None)
    return (False);

  size = 0;

  if (XGetFontProperty(*(XFontStruct **)fromVal->addr, atom, &value))
    {
      char *tmp = XGetAtomName(dpy, value);

      if (tmp)
	{
	  XmuSnprintf(buffer, sizeof(buffer), "%s", tmp);
	  size = strlen(tmp);
	  XFree(tmp);
	}
    }

  if (size)
    {
      ++size;
    string_done(buffer);
    }

  XawTypeToStringWarning(dpy, XtRFontStruct);

  return (False);
}

/*ARGSUSED*/
static Boolean
_XawCvtUnsignedCharToString(Display *dpy, XrmValue *args, Cardinal *num_args,
			    XrmValue *fromVal, XrmValue *toVal,
			    XtPointer *converter_data)
{
  static char buffer[4];
  Cardinal size;

  if (*num_args != 0)
    TypeToStringNoArgsWarning(dpy, XtRUnsignedChar);

  XmuSnprintf(buffer, sizeof(buffer), "%u",
	      *(unsigned char *)fromVal->addr);
  size = strlen(buffer) + 1;

  string_done(buffer);
}

/*ARGSUSED*/
static Boolean
_XawCvtStringToDisplayList(Display *dpy, XrmValue *args, Cardinal *num_args,
			   XrmValue *fromVal, XrmValue *toVal,
			   XtPointer *converter_data)
{
  XawDisplayList *dlist;
  Screen *screen;
  Colormap colormap;
  int depth;
  String commands;

  if (*num_args != 3)
    {
      XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
		      XtNwrongParameters, "cvtStringToDisplayList",
		      XtCToolkitError,
		      "String to DisplayList conversion needs screen, "
		      "colormap, and depth arguments",
		      NULL, NULL);
      return (False);
    }

  screen     = *(Screen **)args[0].addr;
  colormap   = *(Colormap *)args[1].addr;
  depth      = *(int *)args[2].addr;

  commands = (String)(fromVal[0].addr);

  dlist = XawCreateDisplayList(commands, screen, colormap, depth);

  if (!dlist)
    {
      XtDisplayStringConversionWarning(dpy, (String)fromVal->addr,
				       XawRDisplayList);
      toVal->addr = NULL;
      toVal->size = sizeof(XawDisplayList*);
      return (False);
    }

  done(XawDisplayList*, dlist);
}

/*ARGSUSED*/
static Boolean
_XawCvtDisplayListToString(Display *dpy, XrmValue *args, Cardinal *num_args,
			   XrmValue *fromVal, XrmValue *toVal,
			   XtPointer *converter_data)
{
  String buffer;
  Cardinal size;

  if (*num_args != 0)
    TypeToStringNoArgsWarning(dpy, XawRDisplayList);

  buffer = XawDisplayListString(*(XawDisplayList **)(fromVal[0].addr));
  size = strlen(buffer) + 1;

  string_done(buffer);
}

/*ARGSUSED*/
static Boolean
_XawCvtStringToPixmap(Display *dpy, XrmValue *args, Cardinal *num_args,
		      XrmValue *fromVal, XrmValue *toVal,
		      XtPointer *converter_data)
{
  XawPixmap *xaw_pixmap;
  Pixmap pixmap;
  Screen *screen;
  Colormap colormap;
  int depth;
  String name;

  if (*num_args != 3)
    {
      XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
		      XtNwrongParameters, "cvtStringToPixmap",
		      XtCToolkitError,
		      "String to Pixmap conversion needs screen, "
		      "colormap, and depth arguments",
		      NULL, NULL);
      return (False);
    }

  screen     = *(Screen **)args[0].addr;
  colormap   = *(Colormap *)args[1].addr;
  depth      = *(int *)args[2].addr;

  name = (String)(fromVal[0].addr);

  if (XmuCompareISOLatin1(name, "None") == 0)
    pixmap = None;
  else if (XmuCompareISOLatin1(name, "ParentRelative") == 0)
    pixmap = ParentRelative;
  else if (XmuCompareISOLatin1(name, "XtUnspecifiedPixmap") == 0)
    pixmap = XtUnspecifiedPixmap;
  else
    {
      xaw_pixmap = XawLoadPixmap(name, screen, colormap, depth);
      if (!xaw_pixmap)
	{
	  XtDisplayStringConversionWarning(dpy, (String)fromVal->addr,
					   XtRPixmap);
	  toVal->addr = (XtPointer)XtUnspecifiedPixmap;
	  toVal->size = sizeof(Pixmap);
	  return (False);
	}
      else
	pixmap = xaw_pixmap->pixmap;
    }

  done(Pixmap, pixmap);
}

/*ARGSUSED*/
static Boolean
_XawCvtPixmapToString(Display *dpy, XrmValue *args, Cardinal *num_args,
		      XrmValue *fromVal, XrmValue *toVal,
		      XtPointer *converter_data)
{
  XawPixmap *xaw_pixmap;
  Pixmap pixmap;
  Screen *screen;
  Colormap colormap;
  int depth;
  String buffer = NULL;
  Cardinal size;

  if (*num_args != 3)
    {
      XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
		      XtNwrongParameters, "cvtPixmapToString",
		      XtCToolkitError,
		      "Pixmap to String conversion needs screen, "
		      "colormap, and depth arguments",
		      NULL, NULL);
      return (False);
    }

  screen     = *(Screen **)args[0].addr;
  colormap   = *(Colormap *)args[1].addr;
  depth      = *(int *)args[2].addr;

  pixmap = *(Pixmap *)(fromVal[0].addr);

  switch (pixmap)
    {
    case None:
      buffer = "None";
      break;
    case ParentRelative:
      buffer = "ParentRelative";
      break;
    case XtUnspecifiedPixmap:
      buffer = "XtUnspecifiedPixmap";
      break;
    default:
      xaw_pixmap = XawPixmapFromXPixmap(pixmap, screen, colormap, depth);
      if (xaw_pixmap)
	buffer = xaw_pixmap->name;
      break;
    }

  if (!buffer)
    /* Bad Pixmap or Pixmap was not loaded by XawLoadPixmap() */
    return (_XawCvtCARD32ToString(dpy, args, num_args, fromVal, toVal,
				  converter_data));

  size = strlen(buffer) + 1;

  string_done(buffer);
}

#endif /* OLDXAW */