1 /*
2 * Motif Tools Library, Version 3.1
3 * $Id: WidgetType.c,v 1.1.1.1 2001/02/10 13:51:26 motiftools Exp $
4 *
5 * Written by David Flanagan.
6 * Copyright (c) 1992-2001 by David Flanagan.
7 * All Rights Reserved. See the file COPYRIGHT for details.
8 * This is open source software. See the file LICENSE for details.
9 * There is no warranty for this software. See NO_WARRANTY for details.
10 *
11 * $Log: WidgetType.c,v $
12 * Revision 1.1.1.1 2001/02/10 13:51:26 motiftools
13 * Initial import of Xmt310 to CVS
14 *
15 *
16 */
17
18 #include <Xmt/XmtP.h>
19 #include <Xmt/WidgetType.h>
20 #include <Xmt/Hash.h>
21
22 static XmtHashTable widget_type_table = NULL;
23
24 /* requires a permanently allocated string */
25 #if NeedFunctionPrototypes
XmtRegisterWidgetClass(StringConst name,WidgetClass wclass)26 void XmtRegisterWidgetClass(StringConst name, WidgetClass wclass)
27 #else
28 void XmtRegisterWidgetClass(name, wclass)
29 StringConst name;
30 WidgetClass wclass;
31 #endif
32 {
33 XmtWidgetType *t = XtNew(XmtWidgetType);
34
35 if (widget_type_table == NULL) widget_type_table = XmtHashTableCreate(5);
36
37 t->name = (String) name;
38 t->wclass = wclass;
39 t->constructor = NULL;
40 t->set_value_proc = NULL;
41 t->get_value_proc = NULL;
42 t->popup = False;
43
44 XmtHashTableStore(widget_type_table,
45 (XtPointer)XrmPermStringToQuark(name),
46 (XtPointer)t);
47 }
48
49 /* requires a permanently allocated string */
50 #if NeedFunctionPrototypes
XmtRegisterWidgetConstructor(StringConst name,XmtWidgetConstructor constructor)51 void XmtRegisterWidgetConstructor(StringConst name,
52 XmtWidgetConstructor constructor)
53 #else
54 void XmtRegisterWidgetConstructor(name, constructor)
55 StringConst name;
56 XmtWidgetConstructor constructor;
57 #endif
58 {
59 XmtWidgetType *t = XtNew(XmtWidgetType);
60
61 if (widget_type_table == NULL) widget_type_table = XmtHashTableCreate(5);
62
63 t->name = (String) name;
64 t->wclass = NULL;
65 t->constructor = constructor;
66 t->set_value_proc = NULL;
67 t->get_value_proc = NULL;
68 t->popup = False;
69
70 XmtHashTableStore(widget_type_table,
71 (XtPointer)XrmPermStringToQuark(name),
72 (XtPointer)t);
73 }
74
75 /* requires a permanently allocated string */
76 #if NeedFunctionPrototypes
XmtRegisterPopupClass(StringConst name,WidgetClass wclass)77 void XmtRegisterPopupClass(StringConst name, WidgetClass wclass)
78 #else
79 void XmtRegisterPopupClass(name, wclass)
80 StringConst name;
81 WidgetClass wclass;
82 #endif
83 {
84 XmtWidgetType *t = XtNew(XmtWidgetType);
85
86 if (widget_type_table == NULL) widget_type_table = XmtHashTableCreate(5);
87
88 t->name = (String) name;
89 t->wclass = wclass;
90 t->constructor = NULL;
91 t->set_value_proc = NULL;
92 t->get_value_proc = NULL;
93 t->popup = True;
94
95 XmtHashTableStore(widget_type_table,
96 (XtPointer)XrmPermStringToQuark(name),
97 (XtPointer)t);
98 }
99
100 /* requires a permanently allocated string */
101 #if NeedFunctionPrototypes
XmtRegisterPopupConstructor(StringConst name,XmtWidgetConstructor constructor)102 void XmtRegisterPopupConstructor(StringConst name,
103 XmtWidgetConstructor constructor)
104 #else
105 void XmtRegisterPopupConstructor(name, constructor)
106 StringConst name;
107 XmtWidgetConstructor constructor;
108 #endif
109 {
110 XmtWidgetType *t = XtNew(XmtWidgetType);
111
112 if (widget_type_table == NULL) widget_type_table = XmtHashTableCreate(5);
113
114 t->name = (String) name;
115 t->wclass = NULL;
116 t->constructor = constructor;
117 t->set_value_proc = NULL;
118 t->get_value_proc = NULL;
119 t->popup = True;
120
121 XmtHashTableStore(widget_type_table,
122 (XtPointer)XrmPermStringToQuark(name),
123 (XtPointer)t);
124 }
125
126
127 #if NeedFunctionPrototypes
XmtRegisterWidgetTypes(XmtWidgetType * types,Cardinal num_types)128 void XmtRegisterWidgetTypes(XmtWidgetType *types, Cardinal num_types)
129 #else
130 void XmtRegisterWidgetTypes(types, num_types)
131 XmtWidgetType *types;
132 Cardinal num_types;
133 #endif
134 {
135 int i;
136
137 if (widget_type_table == NULL) widget_type_table = XmtHashTableCreate(5);
138
139 for(i=0; i < num_types; i++) {
140 XmtHashTableStore(widget_type_table,
141 (XtPointer)XrmPermStringToQuark(types[i].name),
142 (XtPointer) &types[i]);
143 }
144 }
145
146 #if NeedVarargsPrototypes
XmtVaRegisterWidgetClasses(StringConst name,WidgetClass wclass,...)147 void XmtVaRegisterWidgetClasses(StringConst name, WidgetClass wclass, ...)
148 #else
149 void XmtVaRegisterWidgetClasses(name, wclass, va_alist)
150 String name;
151 WidgetClass wclass;
152 va_dcl
153 #endif
154 {
155 va_list var;
156
157 XmtRegisterWidgetClass(name, wclass);
158 Va_start(var, wclass);
159 while((name = va_arg(var, StringConst)) != NULL) {
160 wclass = va_arg(var, WidgetClass);
161 XmtRegisterWidgetClass(name, wclass);
162 }
163 va_end(var);
164 }
165
166 #if NeedVarargsPrototypes
XmtVaRegisterWidgetConstructors(StringConst name,XmtWidgetConstructor constructor,...)167 void XmtVaRegisterWidgetConstructors(StringConst name,
168 XmtWidgetConstructor constructor, ...)
169 #else
170 void XmtVaRegisterWidgetConstructors(name, constructor, va_alist)
171 StringConst name;
172 XmtWidgetConstructor constructor;
173 va_dcl
174 #endif
175 {
176 va_list var;
177
178 Va_start(var, constructor);
179 while(name != NULL) {
180 XmtRegisterWidgetConstructor(name, constructor);
181 name = va_arg(var, StringConst);
182 if (name) constructor = va_arg(var, XmtWidgetConstructor);
183 }
184 va_end(var);
185 }
186
187 #if NeedFunctionPrototypes
XmtLookupWidgetType(StringConst name)188 XmtWidgetType *XmtLookupWidgetType(StringConst name)
189 #else
190 XmtWidgetType *XmtLookupWidgetType(name)
191 StringConst name;
192 #endif
193 {
194 XmtWidgetType *type;
195
196 if (widget_type_table == NULL) return NULL;
197
198 if (XmtHashTableLookup(widget_type_table,
199 (XtPointer) XrmStringToQuark(name),
200 (XtPointer *) &type))
201 return type;
202 else
203 return NULL;
204 }
205
206 #if NeedFunctionPrototypes
XmtCreateWidgetType(StringConst name,XmtWidgetType * type,Widget parent,ArgList args,Cardinal num_args)207 Widget XmtCreateWidgetType(StringConst name, XmtWidgetType *type,
208 Widget parent, ArgList args, Cardinal num_args)
209 #else
210 Widget XmtCreateWidgetType(name, type, parent, args, num_args)
211 StringConst name;
212 XmtWidgetType *type;
213 Widget parent;
214 ArgList args;
215 Cardinal num_args;
216 #endif
217 {
218 if (!type) return NULL;
219
220 if (!type->popup && !XtIsComposite(parent)) {
221 XmtWarningMsg("XmtCreateWidgetType", "badParent",
222 "Can't create %s widget '%s'\n\tas a child of %s widget '%s'.\n\tThe parent is not a Composite widget.",
223 type->name, (String)name,
224 XtClass(parent)->core_class.class_name, XtName(parent));
225 return NULL;
226 }
227
228 if (type->wclass) {
229 if (type->popup)
230 return XtCreatePopupShell(name, type->wclass,parent,args,num_args);
231 else
232 return XtCreateWidget(name, type->wclass, parent, args, num_args);
233 }
234 else if (type->constructor)
235 return (*type->constructor)(parent, (String)name, args, num_args);
236
237 return NULL;
238 }
239