1 /*************************************<+>*************************************
2 *****************************************************************************
8 ** Description: Contains a function to register all of the resource
9 ** type converters used within Xw and the converter
12 *****************************************************************************
14 ** Copyright (c) 1988 by Hewlett-Packard Company
15 ** Copyright (c) 1988 by the Massachusetts Institute of Technology
17 ** Permission to use, copy, modify, and distribute this software
18 ** and its documentation for any purpose and without fee is hereby
19 ** granted, provided that the above copyright notice appear in all
20 ** copies and that both that copyright notice and this permission
21 ** notice appear in supporting documentation, and that the names of
22 ** Hewlett-Packard or M.I.T. not be used in advertising or publicity
23 ** pertaining to distribution of the software without specific, written
26 *****************************************************************************
27 *************************************<+>*************************************/
34 #include <X11/IntrinsicP.h>
35 #include <X11/Intrinsic.h>
38 #include <Xw/TextEdit.h>
39 #include <X11/StringDefs.h>
42 static void _XwCvtStringToTraversalType ();
43 static void _XwCvtStringToHighlightStyle ();
44 static void _XwCvtStringToTileType();
45 static void _XwCvtStringToLayoutPolicy();
46 static void _XwCvtStringToLabelLocation();
47 static Boolean
StringsAreEqual();
48 static void _XwCvtStringToAlignment();
49 static void _XwCvtStringToWidgetType();
50 static void _XwCvtStringToSelectionMethod();
51 static void _XwCvtStringToSelectionStyle();
52 static void _XwCvtStringToSelectionBias();
53 static void _XwCvtStringToElementHighlight();
54 static void _XwCvtStringToDestroyMode();
55 static void _XwCvtStringToGravity ();
56 static void _XwCvtStringToTitlePositionType();
57 static void _XwCvtStringToLabelType();
58 static void _XwCvtStringToTitleType();
59 static void _XwCvtLongToLong();
60 static void CvtStringToEditMode();
61 static void CvtStringToSourceType();
62 static void CvtStringToWrap();
63 static void CvtStringToWrapBreak();
64 static void CvtStringToWrapForm();
65 static void CvtStringToScroll();
66 static void CvtStringToGrow();
69 unsigned char *string
;
73 #define NUMVALUESETS 7
74 #define XwEditTypeValueSetNum 0
75 #define XwSourceTypeValueSetNum 1
76 #define XwWrapValueSetNum 2
77 #define XwWrapFormValueSetNum 3
78 #define XwWrapBreakValueSetNum 4
79 #define XwScrollValueSetNum 5
80 #define XwGrowValueSetNum 6
82 static XwSetValuePair XwEditTypeValueSet
[] =
83 { {(unsigned char *)"edit", (int) XwtextEdit
},
84 {(unsigned char *)"append", (int) XwtextAppend
},
85 {(unsigned char *)"read", (int) XwtextRead
},
87 static XwSetValuePair XwSourceTypeValueSet
[] =
88 {{(unsigned char *)"stringsrc", (int) XwstringSrc
},
89 {(unsigned char *)"disksrc", (int) XwdiskSrc
},
90 {(unsigned char *)"userdefined", (int) XwprogDefinedSrc
},
92 static XwSetValuePair XwWrapValueSet
[] =
93 {{(unsigned char *)"wrapoff", (int) XwWrapOff
},
94 {(unsigned char *)"softwrap", (int) XwSoftWrap
},
95 {(unsigned char *)"hardwrap", (int) XwHardWrap
},
97 static XwSetValuePair XwWrapFormValueSet
[] =
98 {{(unsigned char *)"sourceform", (int) XwSourceForm
},
99 {(unsigned char *)"displayform", (int) XwDisplayForm
},
101 static XwSetValuePair XwWrapBreakValueSet
[] =
102 {{(unsigned char *)"wrapany", (int) XwWrapAny
},
103 {(unsigned char *)"wrapwhitespace", (int) XwWrapWhiteSpace
},
105 static XwSetValuePair XwScrollValueSet
[] =
106 {{(unsigned char *)"autoscrolloff", (int) XwAutoScrollOff
},
107 {(unsigned char *)"autoscrollvertical", (int) XwAutoScrollVertical
},
108 {(unsigned char *)"autoscrollhorizontal", (int) XwAutoScrollHorizontal
},
109 {(unsigned char *)"autoscrollboth", (int) XwAutoScrollBoth
},
111 static XwSetValuePair XwGrowValueSet
[] =
112 {{(unsigned char *)"growoff", (int) XwGrowOff
},
113 {(unsigned char *)"growhorizontal", (int) XwGrowHorizontal
},
114 {(unsigned char *)"growvertical", (int) XwGrowVertical
},
115 {(unsigned char *)"growboth", (int) XwGrowBoth
},
118 static XwSetValuePair
*valuepairsets
[NUMVALUESETS
];
120 /************************************************************************
122 * XwRegisterConverters
123 * Register all of the Xw resource type converters. Retain a
124 * flag indicating whether the converters have already been
127 ************************************************************************/
129 XwRegisterConverters ()
131 static Boolean registered
= False
;
135 XtAddConverter (XtRString
, XtRTraversalType
,
136 _XwCvtStringToTraversalType
, NULL
, 0);
137 XtAddConverter (XtRString
, XtRLayout
,
138 _XwCvtStringToLayoutPolicy
, NULL
, 0);
139 XtAddConverter (XtRString
, XtRHighlightStyle
,
140 _XwCvtStringToHighlightStyle
, NULL
, 0);
141 XtAddConverter (XtRString
, XtRTileType
,
142 _XwCvtStringToTileType
, NULL
, 0);
143 XtAddConverter (XtRString
, XtRLabelLocation
,
144 _XwCvtStringToLabelLocation
, NULL
, 0);
145 XtAddConverter (XtRString
, XtRAlignment
,
146 _XwCvtStringToAlignment
, NULL
, 0);
147 XtAddConverter (XtRString
, XtRWidgetType
,
148 _XwCvtStringToWidgetType
, NULL
, 0);
149 XtAddConverter (XtRString
, XtRGravity
,
150 _XwCvtStringToGravity
, NULL
,0);
151 XtAddConverter (XtRString
, XtRTitlePositionType
,
152 _XwCvtStringToTitlePositionType
, NULL
, 0);
153 XtAddConverter (XtRString
, XtRTitleType
, _XwCvtStringToTitleType
,
155 XtAddConverter (XtRString
, XtRLabelType
, _XwCvtStringToLabelType
,
157 XtAddConverter (XtRLong
, XtRLong
, _XwCvtLongToLong
, NULL
, 0);
159 valuepairsets
[XwEditTypeValueSetNum
] = XwEditTypeValueSet
;
160 valuepairsets
[XwSourceTypeValueSetNum
] = XwSourceTypeValueSet
;
161 valuepairsets
[XwWrapValueSetNum
] = XwWrapValueSet
;
162 valuepairsets
[XwWrapFormValueSetNum
] = XwWrapFormValueSet
;
163 valuepairsets
[XwWrapBreakValueSetNum
] = XwWrapBreakValueSet
;
164 valuepairsets
[XwScrollValueSetNum
] = XwScrollValueSet
;
165 valuepairsets
[XwGrowValueSetNum
] = XwGrowValueSet
;
167 XtAddConverter(XtRString
, XtREditMode
, CvtStringToEditMode
, NULL
, 0);
168 XtAddConverter(XtRString
, XtRSourceType
, CvtStringToSourceType
, NULL
, 0);
169 XtAddConverter(XtRString
, XtRWrap
, CvtStringToWrap
, NULL
, 0);
170 XtAddConverter(XtRString
, XtRWrapBreak
, CvtStringToWrapBreak
, NULL
, 0);
171 XtAddConverter(XtRString
, XtRWrapForm
, CvtStringToWrapForm
, NULL
, 0);
172 XtAddConverter(XtRString
, XtRScroll
, CvtStringToScroll
, NULL
, 0);
173 XtAddConverter(XtRString
, XtRGrow
, CvtStringToGrow
, NULL
, 0);
182 /************************************************************************
184 * Resource Conversion Functions
185 * The following set of functions are used by the resource
186 * manager to convert the resource types defined for this class.
188 ************************************************************************/
191 /* Convert a string to a traversal type. */
193 static void _XwCvtStringToTraversalType (args
, numArgs
, fromVal
, toVal
)
200 char * in_str
= (char *) (fromVal
->addr
);
205 if (((*in_str
) == 'H') || ((*in_str
) == 'h'))
207 if (StringsAreEqual (in_str
, "highlight_traversal"))
208 i
= XwHIGHLIGHT_TRAVERSAL
;
209 else if (StringsAreEqual (in_str
, "highlight_enter"))
210 i
= XwHIGHLIGHT_ENTER
;
213 (*toVal
).size
= sizeof (int);
214 (*toVal
).addr
= (caddr_t
) &i
;
217 /******************************************************/
218 /* Convert a string to a ButtonClass Label Location. */
219 /******************************************************/
220 static void _XwCvtStringToLabelLocation (args
, numArgs
, fromVal
, toVal
)
227 char * in_str
= (char *) (fromVal
->addr
);
230 if (((*in_str
)== 'L') || ((*in_str
)=='l'))
232 if (StringsAreEqual(in_str
,"left")) i
= XwLEFT
;
237 (*toVal
).size
= sizeof (int);
238 (*toVal
).addr
= (caddr_t
) &i
;
241 /********************************************************/
242 /* Convert a string to ManagerClass layout mode type. */
243 /********************************************************/
244 static void _XwCvtStringToLayoutPolicy (args
, numArgs
, fromVal
, toVal
)
251 char * in_str
= (char *) (fromVal
->addr
);
260 if (StringsAreEqual(in_str
,"ignore")) i
= XwIGNORE
;
265 if (StringsAreEqual(in_str
,"maximize")) i
= XwMAXIMIZE
;
269 (*toVal
).size
= sizeof (int);
270 (*toVal
).addr
= (caddr_t
) &i
;
275 static Boolean
StringsAreEqual(in_str
, test_str
)
276 char *in_str
, *test_str
;
285 if (isupper(i
)) i
= tolower(i
);
286 if (isupper(j
)) j
= tolower(j
);
287 if (i
!= j
) return (False
);
288 if (i
== 0) return (True
);
296 /* Convert a string to a highlight type. */
298 static void _XwCvtStringToHighlightStyle (args
, numArgs
, fromVal
, toVal
)
305 char * in_str
= (char *) (fromVal
->addr
);
308 i
= XwWIDGET_DEFINED
;
310 if (((*in_str
) == 'P') || ((*in_str
) == 'p'))
311 if (StringsAreEqual (in_str
, "pattern_border"))
312 i
= XwPATTERN_BORDER
;
314 (*toVal
).size
= sizeof (int);
315 (*toVal
).addr
= (caddr_t
) &i
;
318 /* Convert a string to an tile type. */
320 static void _XwCvtStringToTileType (args
, numArgs
, fromVal
, toVal
)
327 char * in_str
= (char *) (fromVal
->addr
);
336 if (StringsAreEqual (in_str
, "foreground")) i
= XwFOREGROUND
;
341 if (StringsAreEqual (in_str
, "background")) i
= XwBACKGROUND
;
346 (*toVal
).size
= sizeof (int);
347 (*toVal
).addr
= (caddr_t
) &i
;
351 /*************************************<->*************************************
353 * static void _XwCvtStringToAlignment()
355 * XrmValue *p_fromVal;
360 * This is a type conversion procedure for the resource manager.
361 * converts strings to type XwAlignment. The conversion is case
366 * See "Xlib - C Language X Interface Protocol Version 11"
370 * See "Xlib - C Language X Interface Protocol Version 11"
376 *************************************<->***********************************/
377 static void _XwCvtStringToAlignment(args
,num
,p_fromVal
,toVal
)
383 static XwAlignment Align
= XwALIGN_LEFT
;
385 Boolean match
= FALSE
;
387 from_str
= (char *) (p_fromVal
->addr
);
388 toVal
->addr
= (caddr_t
) &Align
;
389 toVal
->size
= sizeof(XwAlignment
);
395 if (match
= StringsAreEqual(from_str
,"left"))
396 Align
= XwALIGN_LEFT
;
400 if (match
= StringsAreEqual(from_str
,"center"))
401 Align
= XwALIGN_CENTER
;
405 if (match
= StringsAreEqual(from_str
,"right"))
406 Align
= XwALIGN_RIGHT
;
410 if (match
= StringsAreEqual(from_str
,"none"))
411 Align
= XwALIGN_NONE
;
426 /*************************************<->*************************************
428 * static void _XwCvtStringToWidgetType()
430 * XrmValue *p_fromVal;
435 * This is a type conversion procedure for the resource manager.
436 * converts strings to type XwWidgetType. The conversion is case
441 * See "Xlib - C Language X Interface Protocol Version 11"
445 * See "Xlib - C Language X Interface Protocol Version 11"
451 *************************************<->***********************************/
452 static void _XwCvtStringToWidgetType(args
,num
,p_fromVal
,toVal
)
458 static XwWidgetType WType
= XwUNKNOWN
;
460 Boolean match
= FALSE
;
462 from_str
= (char *) (p_fromVal
->addr
);
463 toVal
->addr
= (caddr_t
) &WType
;
464 toVal
->size
= sizeof(XwWidgetType
);
470 if (match
= StringsAreEqual(from_str
,"title"))
475 if (match
= StringsAreEqual(from_str
,"pulldown"))
480 if (match
= StringsAreEqual(from_str
,"work space"))
481 WType
= XwWORK_SPACE
;
485 if (match
= StringsAreEqual(from_str
,"unknown"))
503 /************************************************************************
505 * _XwCvtStringToGravity
506 * Convert a resource string to a gravity value.
508 ************************************************************************/
510 static void _XwCvtStringToGravity (args
, numArgs
, fromVal
, toVal
)
517 static int gravity
= CenterGravity
;
519 Boolean match
= FALSE
;
521 from_str
= (char *) (fromVal
->addr
);
522 toVal
->addr
= (caddr_t
) &gravity
;
523 toVal
->size
= sizeof(int);
529 if (match
= StringsAreEqual(from_str
,"NorthGravity"))
530 gravity
= NorthGravity
;
531 else if (match
= StringsAreEqual(from_str
,"NorthWestGravity"))
532 gravity
= NorthWestGravity
;
533 else if (match
= StringsAreEqual(from_str
,"NorthEastGravity"))
534 gravity
= NorthEastGravity
;
538 if (match
= StringsAreEqual(from_str
,"SouthGravity"))
539 gravity
= SouthGravity
;
540 else if (match
= StringsAreEqual(from_str
,"SouthWestGravity"))
541 gravity
= SouthWestGravity
;
542 else if (match
= StringsAreEqual(from_str
,"SouthEastGravity"))
543 gravity
= SouthEastGravity
;
547 if (match
= StringsAreEqual(from_str
,"WestGravity"))
548 gravity
= WestGravity
;
552 if (match
= StringsAreEqual(from_str
,"EastGravity"))
553 gravity
= EastGravity
;
557 if (match
= StringsAreEqual(from_str
,"CenterGravity"))
558 gravity
= CenterGravity
;
572 static void _XwCvtStringToTitleType (args
, num_args
, fromVal
, toVal
)
581 String source
= (String
) fromVal
->addr
;
585 if (strcmp ("string", source
) == 0)
587 else if (strcmp ("image", source
) == 0)
589 else if (strcmp ("rect", source
) == 0)
595 "MenuPane: Unknown title type specified; using string title");
601 XtWarning ("MenuPane: Unknown title type specified; using string title");
604 (*toVal
).size
= sizeof(int);
605 (*toVal
).addr
= (caddr_t
) &i
;
609 static void _XwCvtStringToLabelType (args
, num_args
, fromVal
, toVal
)
619 if (strcmp ("string", (char *) fromVal
->addr
) == 0)
621 else if (strcmp ("image", (char *) fromVal
->addr
) == 0)
627 ("MenuButton: Unknown label type specified; using string label");
630 (*toVal
).size
= sizeof(int);
631 (*toVal
).addr
= (caddr_t
) &i
;
634 static void _XwCvtStringToTitlePositionType (args
, num_args
, fromVal
, toVal
)
643 String source
= (char *) fromVal
->addr
;
647 /* Force the comparison to be case insensitive */
648 for (i
= 0; i
< XwStrlen(source
); i
++)
650 if (isupper (source
[i
]))
651 source
[i
] = tolower(source
[i
]);
654 if (strcmp ("bottom", source
) == 0)
656 else if (strcmp ("top", source
) == 0)
658 else if (strcmp ("both", source
) == 0)
659 i
= XwTOP
| XwBOTTOM
;
663 XtWarning ("Cascade: Invalid title position; position set to top");
669 XtWarning ("Cascade: Invalid title position; position set to top");
672 (*toVal
).size
= sizeof(int);
673 (*toVal
).addr
= (caddr_t
) &i
;
676 /*---------------------------------------------------------------------------*/
677 /* Type long to type long conversion (mostly to satisfy picky 64-bit OSF) */
678 /*---------------------------------------------------------------------------*/
680 static void _XwCvtLongToLong (args
, num_args
, fromVal
, toVal
)
688 long result
= (long) fromVal
->addr
;
691 XtWarning ("SourceStr: Invalid max_size; max_size set to -1");
694 (*toVal
).size
= sizeof(long);
695 (*toVal
).addr
= (caddr_t
) &result
;
698 /*--------------------------------------------------------------------------+*/
699 static void SetConverter(fromVal
, toVal
, setNum
)
700 /*--------------------------------------------------------------------------+*/
701 XrmValuePtr fromVal
, toVal
;
707 unsigned char *fromstr
;
709 fromstr
= (unsigned char *)fromVal
->addr
;
710 ptr
= valuepairsets
[setNum
];
711 for(j
=0; *ptr
[j
].string
; j
++)
712 if (!strcmp(ptr
[j
].string
, fromstr
)) {
713 value
= ptr
[j
].value
;
714 toVal
->size
= sizeof(int);
715 toVal
->addr
= (caddr_t
)&value
;
722 /*--------------------------------------------------------------------------+*/
723 static void CvtStringToEditMode(args
, num_args
, fromVal
, toVal
)
724 /*--------------------------------------------------------------------------+*/
725 XrmValuePtr
*args
; /* unused */
726 Cardinal
*num_args
; /* unused */
730 SetConverter(fromVal
, toVal
, XwEditTypeValueSetNum
);
733 /*--------------------------------------------------------------------------+*/
734 static void CvtStringToSourceType(args
, num_args
, fromVal
, toVal
)
735 /*--------------------------------------------------------------------------+*/
736 XrmValuePtr
*args
; /* unused */
737 Cardinal
*num_args
; /* unused */
741 SetConverter(fromVal
, toVal
, XwSourceTypeValueSetNum
);
744 /*--------------------------------------------------------------------------+*/
745 static void CvtStringToWrap(args
, num_args
, fromVal
, toVal
)
746 /*--------------------------------------------------------------------------+*/
747 XrmValuePtr
*args
; /* unused */
748 Cardinal
*num_args
; /* unused */
752 SetConverter(fromVal
, toVal
, XwWrapValueSetNum
);
755 /*--------------------------------------------------------------------------+*/
756 static void CvtStringToWrapForm(args
, num_args
, fromVal
, toVal
)
757 /*--------------------------------------------------------------------------+*/
758 XrmValuePtr
*args
; /* unused */
759 Cardinal
*num_args
; /* unused */
763 SetConverter(fromVal
, toVal
, XwWrapFormValueSetNum
);
766 /*--------------------------------------------------------------------------+*/
767 static void CvtStringToWrapBreak(args
, num_args
, fromVal
, toVal
)
768 /*--------------------------------------------------------------------------+*/
769 XrmValuePtr
*args
; /* unused */
770 Cardinal
*num_args
; /* unused */
774 SetConverter(fromVal
, toVal
, XwWrapBreakValueSetNum
);
777 /*--------------------------------------------------------------------------+*/
778 static void CvtStringToScroll(args
, num_args
, fromVal
, toVal
)
779 /*--------------------------------------------------------------------------+*/
780 XrmValuePtr
*args
; /* unused */
781 Cardinal
*num_args
; /* unused */
785 SetConverter(fromVal
, toVal
, XwScrollValueSetNum
);
788 /*--------------------------------------------------------------------------+*/
789 static void CvtStringToGrow(args
, num_args
, fromVal
, toVal
)
790 /*--------------------------------------------------------------------------+*/
791 XrmValuePtr
*args
; /* unused */
792 Cardinal
*num_args
; /* unused */
796 SetConverter(fromVal
, toVal
, XwGrowValueSetNum
);