2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: cmnutils.c /main/4 1995/11/01 16:11:47 rswiston $ */
24 /***************************************************************************/
26 /* Utility Functions */
28 /***************************************************************************/
33 #include <Xm/RowColumnP.h>
34 #include <Xm/MessageB.h>
39 /********************************************************************************/
40 /* countItems - counts the number of items in a null terminated array */
41 /* INPUT: char **items - null terminated array */
42 /* OUTPUT: int lcv - number of items in array */
43 /********************************************************************************/
44 int countItems (char **items)
53 for (lcv = 0; items[lcv]; lcv++);
58 /********************************************************************************/
59 /* TextStringsToXmStrings - Given an array of C text strings returns an */
60 /* array of XmStrings. */
61 /* INPUT: char **text_strings - array of C style strings */
62 /* OUTPUT: XmStringTable xmstrings - an array Motif compound strings */
63 /********************************************************************************/
64 XmStringTable TextStringsToXmStrings (char **text_strings)
66 XmStringTable xmstrings = NULL;
70 count = countItems (text_strings);
71 xmstrings = (XmStringTable) calloc (sizeof(XmString), (count));
72 for (lcv = 0; lcv < count; lcv++)
73 xmstrings[lcv] = (XmString) XmStringCreateSimple (text_strings[lcv]);
75 return ((XmStringTable)xmstrings);
78 /********************************************************************************/
79 /* XmStringToText - Given an XmString returns a C character text string. */
80 /* INPUT: XmString xmstring - a Motif compound string */
81 /* OUTPUT: char *text_string - C style string */
82 /********************************************************************************/
83 char *XmStringToText (XmString xmstring)
85 XmStringContext context;
86 XmStringCharSet charset;
87 XmStringDirection direction;
89 char *text_string = NULL, *temp = NULL;
91 text_string = (char *)calloc (1, sizeof (char));
94 if (!XmStringInitContext (&context, xmstring)) {
95 printf("Can't convert compound string.\n");
98 while (XmStringGetNextSegment (context, &temp, &charset,
99 &direction, &separator)) {
100 text_string = (char *)realloc (text_string, strlen (temp)+1);
101 if (text_string == NULL) {
102 printf("Can't allocate space for file name.\n");
105 text_string = strcpy(text_string, temp);
108 XmStringFreeContext(context);
111 return (text_string);
114 /********************************************************************************/
115 /* delete_all_list_items - removes all items from a list box */
116 /* INPUT: Widget list - id of list widget */
118 /********************************************************************************/
119 void delete_all_list_items (Widget list)
123 XtVaGetValues (list, XmNitemCount, &item_count, NULL);
124 if (item_count > 0) {
125 XmListDeleteItemsPos (list, item_count, 1);
130 /********************************************************************************/
131 /* clear_text_field - removes any text from a text field */
132 /* INPUT: Widget textfield - id of text widget */
134 /********************************************************************************/
135 void clear_text_field (Widget textfield)
137 XmTextPosition last_pos;
140 last_pos = XmTextGetLastPosition (textfield);
141 XmTextReplace (textfield, 0, last_pos, empty);
146 /********************************************************************************/
147 /* clear_text - removes any text from a text widget */
148 /* INPUT: Widget textwid - id of text widget */
150 /********************************************************************************/
151 void clear_text (Widget textwid)
153 XmTextPosition last_pos;
156 last_pos = XmTextGetLastPosition (textwid);
157 XmTextReplace (textwid, 0, last_pos, empty);