NewCvt.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $XConsortium: NewCvt.c /main/5 1996/03/26 19:53:53 drk $
  24. *
  25. * (c) Copyright 1996 Digital Equipment Corporation.
  26. * (c) Copyright 1990,1996 Hewlett-Packard Company.
  27. * (c) Copyright 1996 International Business Machines Corp.
  28. * (c) Copyright 1996 Sun Microsystems, Inc.
  29. * (c) Copyright 1996 Novell, Inc.
  30. * (c) Copyright 1996 FUJITSU LIMITED.
  31. * (c) Copyright 1996 Hitachi.
  32. */
  33. /**---------------------------------------------------------------------
  34. ***
  35. *** file: NewCvt.c
  36. ***
  37. *** project: Motif Widgets
  38. ***
  39. *** description: Source code for new MotifPlus resource converters.
  40. ***
  41. ***-------------------------------------------------------------------*/
  42. /*-------------------------------------------------------------
  43. ** Include Files
  44. */
  45. #include <Dt/DialogBox.h>
  46. #include <Dt/Icon.h>
  47. #include <Dt/TitleBox.h>
  48. #include "DtWidgetI.h"
  49. #include <ctype.h>
  50. extern void _DtRegisterNewConverters( void ) ;
  51. /******** Static Function Declarations ********/
  52. static Boolean _StringsAreEqual(
  53. String in_str,
  54. String test_str) ;
  55. static void _DtCvtStringToBehavior(
  56. XrmValuePtr args,
  57. Cardinal *num_args,
  58. XrmValue *from_val,
  59. XrmValue *to_val) ;
  60. static void _DtCvtStringToChildType(
  61. XrmValuePtr args,
  62. Cardinal *num_args,
  63. XrmValue *from_val,
  64. XrmValue *to_val) ;
  65. static void _DtCvtStringToFillMode(
  66. XrmValuePtr args,
  67. Cardinal *num_args,
  68. XrmValue *from_val,
  69. XrmValue *to_val) ;
  70. static void _DtCvtStringToPixmapPosition(
  71. XrmValuePtr args,
  72. Cardinal *num_args,
  73. XrmValue *from_val,
  74. XrmValue *to_val) ;
  75. static void _DtCvtStringToStringPosition(
  76. XrmValuePtr args,
  77. Cardinal *num_args,
  78. XrmValue *from_val,
  79. XrmValue *to_val) ;
  80. static void _DtCvtStringToTitlePosition(
  81. XrmValuePtr args,
  82. Cardinal *num_args,
  83. XrmValue *from_val,
  84. XrmValue *to_val) ;
  85. /******** End Static Function Declarations ********/
  86. /*-------------------------------------------------------------
  87. ** _DtRegisterNewConverters
  88. ** Convert MotifPlus resource converters.
  89. */
  90. void
  91. _DtRegisterNewConverters( void )
  92. {
  93. static Boolean new_converters_registered = False;
  94. if (!new_converters_registered)
  95. {
  96. _DtProcessLock();
  97. if (!new_converters_registered)
  98. {
  99. /* Register new converters. */
  100. XtAddConverter (XmRString, XmRBehavior,
  101. _DtCvtStringToBehavior, NULL, 0);
  102. XtAddConverter (XmRString, XmRChildType,
  103. _DtCvtStringToChildType, NULL, 0);
  104. XtAddConverter (XmRString, XmRFillMode,
  105. _DtCvtStringToFillMode, NULL, 0);
  106. XtAddConverter (XmRString, XmRPixmapPosition,
  107. _DtCvtStringToPixmapPosition, NULL, 0);
  108. XtAddConverter (XmRString, XmRStringPosition,
  109. _DtCvtStringToStringPosition, NULL, 0);
  110. XtAddConverter (XmRString, XmRTitlePosition,
  111. _DtCvtStringToTitlePosition, NULL, 0);
  112. new_converters_registered = True;
  113. }
  114. _DtProcessUnlock();
  115. }
  116. }
  117. /*-------------------------------------------------------------
  118. ** _StringsAreEqual
  119. ** Compare possibly mixed case string with lowercase string.
  120. */
  121. static Boolean
  122. _StringsAreEqual(
  123. String in_str,
  124. String test_str )
  125. {
  126. int i, j;
  127. for (;;)
  128. {
  129. i = *in_str;
  130. j = *test_str;
  131. if (isupper (i))
  132. i = tolower (i);
  133. if (i != j) return (False);
  134. if (i == 0) return (True);
  135. in_str++;
  136. test_str++;
  137. }
  138. }
  139. /*-------------------------------------------------------------
  140. ** _DtCvtStringToBehavior
  141. ** Convert XmRString to XmRBehavior.
  142. */
  143. static void
  144. _DtCvtStringToBehavior(
  145. XrmValuePtr args,
  146. Cardinal *num_args,
  147. XrmValue *from_val,
  148. XrmValue *to_val )
  149. {
  150. String string = (String) from_val->addr;
  151. static unsigned char value;
  152. to_val->size = sizeof (unsigned char);
  153. to_val->addr = (XtPointer) &value;
  154. if (_StringsAreEqual (string, STR_ICON_LABEL))
  155. value = XmICON_LABEL;
  156. else if (_StringsAreEqual (string, STR_ICON_BUTTON))
  157. value = XmICON_BUTTON;
  158. else if (_StringsAreEqual (string, STR_ICON_TOGGLE))
  159. value = XmICON_TOGGLE;
  160. else if (_StringsAreEqual (string, STR_ICON_DRAG))
  161. value = XmICON_DRAG;
  162. else
  163. {
  164. to_val->size = 0;
  165. to_val->addr = NULL;
  166. XtStringConversionWarning ((String) from_val->addr,
  167. XmRBehavior);
  168. }
  169. }
  170. /*-------------------------------------------------------------
  171. ** _DtCvtStringToChildType
  172. ** Convert XmRString to XmRChildType.
  173. */
  174. static void
  175. _DtCvtStringToChildType(
  176. XrmValuePtr args,
  177. Cardinal *num_args,
  178. XrmValue *from_val,
  179. XrmValue *to_val )
  180. {
  181. String string = (String) from_val->addr;
  182. static unsigned char value;
  183. to_val->size = sizeof (unsigned char);
  184. to_val->addr = (XtPointer) &value;
  185. if (_StringsAreEqual (string, STR_WORK_AREA))
  186. value = XmWORK_AREA;
  187. else if (_StringsAreEqual (string, STR_TITLE_AREA))
  188. value = XmTITLE_AREA;
  189. else if (_StringsAreEqual (string, STR_SEPARATOR))
  190. value = XmSEPARATOR;
  191. else if (_StringsAreEqual (string, STR_BUTTON))
  192. value = XmBUTTON;
  193. else
  194. {
  195. to_val->size = 0;
  196. to_val->addr = NULL;
  197. XtStringConversionWarning ((String) from_val->addr,
  198. XmRChildType);
  199. }
  200. }
  201. /*-------------------------------------------------------------
  202. ** _DtCvtStringToFillMode
  203. ** Convert XmRString to XmRFillMode.
  204. */
  205. static void
  206. _DtCvtStringToFillMode(
  207. XrmValuePtr args,
  208. Cardinal *num_args,
  209. XrmValue *from_val,
  210. XrmValue *to_val )
  211. {
  212. String string = (String) from_val->addr;
  213. static unsigned char value;
  214. to_val->size = sizeof (unsigned char);
  215. to_val->addr = (XtPointer) &value;
  216. if (_StringsAreEqual (string, STR_FILL_NONE))
  217. value = XmFILL_NONE;
  218. else if (_StringsAreEqual (string, STR_FILL_PARENT))
  219. value = XmFILL_PARENT;
  220. else if (_StringsAreEqual (string, STR_FILL_SELF))
  221. value = XmFILL_SELF;
  222. else if (_StringsAreEqual (string, STR_FILL_TRANSPARENT))
  223. value = XmFILL_TRANSPARENT;
  224. else
  225. {
  226. to_val->size = 0;
  227. to_val->addr = NULL;
  228. XtStringConversionWarning ((String) from_val->addr,
  229. XmRFillMode);
  230. }
  231. }
  232. /*-------------------------------------------------------------
  233. ** _DtCvtStringToPixmapPosition
  234. ** Convert string to pixmap position.
  235. */
  236. static void
  237. _DtCvtStringToPixmapPosition(
  238. XrmValuePtr args,
  239. Cardinal *num_args,
  240. XrmValue *from_val,
  241. XrmValue *to_val )
  242. {
  243. String string = (String) from_val->addr;
  244. static unsigned char value;
  245. to_val->size = sizeof (unsigned char);
  246. to_val->addr = (XtPointer) &value;
  247. if (_StringsAreEqual (string, STR_PIXMAP_TOP))
  248. value = XmPIXMAP_TOP;
  249. else if (_StringsAreEqual (string, STR_PIXMAP_BOTTOM))
  250. value = XmPIXMAP_BOTTOM;
  251. else if (_StringsAreEqual (string, STR_PIXMAP_LEFT))
  252. value = XmPIXMAP_LEFT;
  253. else if (_StringsAreEqual (string, STR_PIXMAP_RIGHT))
  254. value = XmPIXMAP_RIGHT;
  255. else if (_StringsAreEqual (string, "pixmap_middle"))
  256. value = XmPIXMAP_MIDDLE;
  257. else
  258. {
  259. to_val->size = 0;
  260. to_val->addr = NULL;
  261. XtStringConversionWarning ((String) from_val->addr,
  262. XmRPixmapPosition);
  263. }
  264. }
  265. /*-------------------------------------------------------------
  266. ** _DtCvtStringToStringPosition
  267. ** Convert XmRString to XmRStringPosition.
  268. */
  269. static void
  270. _DtCvtStringToStringPosition(
  271. XrmValuePtr args,
  272. Cardinal *num_args,
  273. XrmValue *from_val,
  274. XrmValue *to_val )
  275. {
  276. String string = (String) from_val->addr;
  277. static unsigned char value;
  278. to_val->size = sizeof (unsigned char);
  279. to_val->addr = (XtPointer) &value;
  280. if (_StringsAreEqual (string, STR_STRING_TOP))
  281. value = XmSTRING_TOP;
  282. else if (_StringsAreEqual (string, STR_STRING_BOTTOM))
  283. value = XmSTRING_BOTTOM;
  284. else if (_StringsAreEqual (string, STR_STRING_LEFT))
  285. value = XmSTRING_LEFT;
  286. else if (_StringsAreEqual (string, STR_STRING_RIGHT))
  287. value = XmSTRING_RIGHT;
  288. else
  289. {
  290. to_val->size = 0;
  291. to_val->addr = NULL;
  292. XtStringConversionWarning ((String) from_val->addr,
  293. XmRStringPosition);
  294. }
  295. }
  296. /*-------------------------------------------------------------
  297. ** _DtCvtStringToTitlePosition
  298. ** Convert XmRString to XmRTitlePosition.
  299. */
  300. static void
  301. _DtCvtStringToTitlePosition(
  302. XrmValuePtr args,
  303. Cardinal *num_args,
  304. XrmValue *from_val,
  305. XrmValue *to_val )
  306. {
  307. String string = (String) from_val->addr;
  308. static unsigned char value;
  309. to_val->size = sizeof (unsigned char);
  310. to_val->addr = (XtPointer) &value;
  311. if (_StringsAreEqual (string, STR_TITLE_TOP))
  312. value = XmTITLE_TOP;
  313. else if (_StringsAreEqual (string, STR_TITLE_BOTTOM))
  314. value = XmTITLE_BOTTOM;
  315. else
  316. {
  317. to_val->size = 0;
  318. to_val->addr = NULL;
  319. XtStringConversionWarning ((String) from_val->addr,
  320. XmRTitlePosition);
  321. }
  322. }