1 /***********************************************************
3 Copyright 1987, 1988, 1994, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
26 Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
30 Permission to use, copy, modify, and distribute this software and its
31 documentation for any purpose and without fee is hereby granted,
32 provided that the above copyright notice appear in all copies and that
33 both that copyright notice and this permission notice appear in
34 supporting documentation, and that the name of Digital not be
35 used in advertising or publicity pertaining to distribution of the
36 software without specific, written prior permission.
38 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
39 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
40 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
41 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
42 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
43 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
46 ******************************************************************/
51 #include <X11/IntrinsicP.h>
52 #include <X11/StringDefs.h>
54 #include <X11/Xmu/Misc.h>
55 #include <X11/Xaw/AsciiText.h>
56 #include <X11/Xaw/Cardinals.h>
57 #include <X11/Xaw/Command.h>
58 #include <X11/Xaw/Label.h>
59 #include <X11/Xaw/DialogP.h>
60 #include <X11/Xaw/XawInit.h>
64 * After we have set the string in the value widget we set the
65 * string to a magic value. So that when a SetValues request is made
66 * on the dialog value we will notice it, and reset the string
68 #define MAGIC_VALUE ((char *)3)
70 #define streq(a,b) (strcmp((a), (b)) == 0)
75 static void XawDialogConstraintInitialize(Widget, Widget,
77 static void XawDialogGetValuesHook(Widget, ArgList, Cardinal*);
78 static void XawDialogInitialize(Widget, Widget, ArgList, Cardinal*);
79 static Boolean XawDialogSetValues(Widget, Widget, Widget,
85 static void CreateDialogValueWidget(Widget);
90 static XtResource resources[] = {
96 XtOffsetOf(DialogRec, dialog.label),
105 XtOffsetOf(DialogRec, dialog.value),
114 XtOffsetOf(DialogRec, dialog.icon),
120 DialogClassRec dialogClassRec = {
123 (WidgetClass)&formClassRec, /* superclass */
124 "Dialog", /* class_name */
125 sizeof(DialogRec), /* widget_size */
126 XawInitializeWidgetSet, /* class_initialize */
127 NULL, /* class_part init */
128 False, /* class_inited */
129 XawDialogInitialize, /* initialize */
130 NULL, /* initialize_hook */
131 XtInheritRealize, /* realize */
134 resources, /* resources */
135 XtNumber(resources), /* num_resources */
136 NULLQUARK, /* xrm_class */
137 True, /* compress_motion */
138 True, /* compress_exposure */
139 True, /* compress_enterleave */
140 False, /* visible_interest */
142 XtInheritResize, /* resize */
143 XtInheritExpose, /* expose */
144 XawDialogSetValues, /* set_values */
145 NULL, /* set_values_hook */
146 XtInheritSetValuesAlmost, /* set_values_almost */
147 XawDialogGetValuesHook, /* get_values_hook */
148 NULL, /* accept_focus */
149 XtVersion, /* version */
150 NULL, /* callback_private */
152 XtInheritQueryGeometry, /* query_geometry */
153 XtInheritDisplayAccelerator, /* display_accelerator */
154 NULL, /* extension */
158 XtInheritGeometryManager, /* geometry_manager */
159 XtInheritChangeManaged, /* change_managed */
160 XtInheritInsertChild, /* insert_child */
161 XtInheritDeleteChild, /* delete_child */
162 NULL, /* extension */
166 NULL, /* subresourses */
167 0, /* subresource_count */
168 sizeof(DialogConstraintsRec), /* constraint_size */
169 XawDialogConstraintInitialize, /* initialize */
171 NULL, /* set_values */
172 NULL, /* extension */
176 XtInheritLayout, /* layout */
180 NULL, /* extension */
184 WidgetClass dialogWidgetClass = (WidgetClass)&dialogClassRec;
191 XawDialogInitialize(Widget request, Widget cnew,
192 ArgList args, Cardinal *num_args)
194 DialogWidget dw = (DialogWidget)cnew;
196 Cardinal arg_cnt = 0;
198 XtSetArg(arglist[arg_cnt], XtNborderWidth, 0); arg_cnt++;
199 XtSetArg(arglist[arg_cnt], XtNleft, XtChainLeft); arg_cnt++;
201 if (dw->dialog.icon != (Pixmap)0) {
202 XtSetArg(arglist[arg_cnt], XtNbitmap, dw->dialog.icon); arg_cnt++;
203 XtSetArg(arglist[arg_cnt], XtNright, XtChainLeft); arg_cnt++;
204 dw->dialog.iconW = XtCreateManagedWidget("icon", labelWidgetClass,
205 cnew, arglist, arg_cnt);
207 XtSetArg(arglist[arg_cnt], XtNfromHoriz, dw->dialog.iconW); arg_cnt++;
210 dw->dialog.iconW = NULL;
212 XtSetArg(arglist[arg_cnt], XtNlabel, dw->dialog.label); arg_cnt++;
213 XtSetArg(arglist[arg_cnt], XtNright, XtChainRight); arg_cnt++;
215 dw->dialog.labelW = XtCreateManagedWidget("label", labelWidgetClass,
216 cnew, arglist, arg_cnt);
218 if (dw->dialog.iconW != NULL &&
219 XtHeight(dw->dialog.labelW) < XtHeight(dw->dialog.iconW)) {
220 XtSetArg(arglist[0], XtNheight, XtHeight(dw->dialog.iconW));
221 XtSetValues(dw->dialog.labelW, arglist, 1);
223 if (dw->dialog.value != NULL)
224 CreateDialogValueWidget((Widget)dw);
226 dw->dialog.valueW = NULL;
231 XawDialogConstraintInitialize(Widget request, Widget cnew,
232 ArgList args, Cardinal *num_args)
234 DialogWidget dw = (DialogWidget)cnew->core.parent;
235 DialogConstraints constraint = (DialogConstraints)cnew->core.constraints;
237 if (!XtIsSubclass(cnew, commandWidgetClass)) /* if not a button */
238 return; /* then just use defaults */
240 constraint->form.left = constraint->form.right = XtChainLeft;
241 if (dw->dialog.valueW == NULL)
242 constraint->form.vert_base = dw->dialog.labelW;
244 constraint->form.vert_base = dw->dialog.valueW;
246 if (dw->composite.num_children > 1) {
247 WidgetList children = dw->composite.children;
250 for (childP = children + dw->composite.num_children - 1;
251 childP >= children; childP-- ) {
252 if (*childP == dw->dialog.labelW || *childP == dw->dialog.valueW)
254 if (XtIsManaged(*childP) &&
255 XtIsSubclass(*childP, commandWidgetClass)) {
256 constraint->form.horiz_base = *childP;
268 XawDialogSetValues(Widget current, Widget request, Widget cnew,
269 ArgList in_args, Cardinal *in_num_args)
271 DialogWidget w = (DialogWidget)cnew;
272 DialogWidget old = (DialogWidget)current;
276 Bool checks[NUM_CHECKS];
278 for (i = 0; i < NUM_CHECKS; i++)
281 for (i = 0; i < *in_num_args; i++) {
282 if (streq(XtNicon, in_args[i].name))
284 else if (streq(XtNlabel, in_args[i].name))
285 checks[LABEL] = True;
289 if (w->dialog.icon != 0) {
290 XtSetArg(args[0], XtNbitmap, w->dialog.icon);
291 if (old->dialog.iconW != NULL)
292 XtSetValues(old->dialog.iconW, args, 1);
294 XtSetArg(args[1], XtNborderWidth, 0);
295 XtSetArg(args[2], XtNleft, XtChainLeft);
296 XtSetArg(args[3], XtNright, XtChainLeft);
297 w->dialog.iconW = XtCreateWidget("icon", labelWidgetClass,
299 ((DialogConstraints)w->dialog.labelW->core.constraints)->
300 form.horiz_base = w->dialog.iconW;
301 XtManageChild(w->dialog.iconW);
304 else if (old->dialog.icon != 0) {
305 ((DialogConstraints)w->dialog.labelW->core.constraints)->
306 form.horiz_base = NULL;
307 XtDestroyWidget(old->dialog.iconW);
308 w->dialog.iconW = NULL;
314 XtSetArg(args[num_args], XtNlabel, w->dialog.label); num_args++;
315 if (w->dialog.iconW != NULL &&
316 XtHeight(w->dialog.labelW) <= XtHeight(w->dialog.iconW)) {
317 XtSetArg(args[num_args], XtNheight, XtHeight(w->dialog.iconW));
320 XtSetValues(w->dialog.labelW, args, num_args);
323 if (w->dialog.value != old->dialog.value) {
324 if (w->dialog.value == NULL) /* only get here if it
325 wasn't NULL before */
326 XtDestroyWidget(old->dialog.valueW);
327 else if (old->dialog.value == NULL) { /* create a new value widget */
328 XtWidth(w) = XtWidth(old);
329 XtHeight(w) = XtHeight(old);
330 CreateDialogValueWidget(cnew);
332 else { /* Widget ok, just change string */
335 XtSetArg(nargs[0], XtNstring, w->dialog.value);
336 XtSetValues(w->dialog.valueW, nargs, 1);
337 w->dialog.value = MAGIC_VALUE;
346 * XawDialogGetValuesHook
350 * args - argument list
351 * num_args - number of args
354 * This is a get values hook routine that gets the values in the dialog.
357 XawDialogGetValuesHook(Widget w, ArgList args, Cardinal *num_args)
361 DialogWidget src = (DialogWidget)w;
364 for (i = 0; i < *num_args; i++)
365 if (streq(args[i].name, XtNvalue)) {
366 XtSetArg(a[0], XtNstring, &s);
367 XtGetValues(src->dialog.valueW, a, 1);
368 *((char **)args[i].value) = s;
370 else if (streq(args[i].name, XtNlabel)) {
371 XtSetArg(a[0], XtNlabel, &s);
372 XtGetValues(src->dialog.labelW, a, 1);
373 *((char **)args[i].value) = s;
379 * CreateDialogValueWidget
385 * Creates the dialog widgets value widget.
388 * Must be called only when w->dialog.value is non-nil
391 CreateDialogValueWidget(Widget w)
393 DialogWidget dw = (DialogWidget)w;
395 Cardinal num_args = 0;
397 XtSetArg(arglist[num_args], XtNstring, dw->dialog.value); num_args++;
398 XtSetArg(arglist[num_args], XtNresizable, True); num_args++;
399 XtSetArg(arglist[num_args], XtNeditType, XawtextEdit); num_args++;
400 XtSetArg(arglist[num_args], XtNfromVert, dw->dialog.labelW); num_args++;
401 XtSetArg(arglist[num_args], XtNleft, XtChainLeft); num_args++;
402 XtSetArg(arglist[num_args], XtNright, XtChainRight); num_args++;
404 dw->dialog.valueW = XtCreateWidget("value", asciiTextWidgetClass,
405 w, arglist, num_args);
407 /* if the value widget is being added after buttons,
408 * then the buttons need new layout constraints
410 if (dw->composite.num_children > 1) {
411 WidgetList children = dw->composite.children;
414 for (childP = children + dw->composite.num_children - 1;
415 childP >= children; childP-- ) {
416 if (*childP == dw->dialog.labelW || *childP == dw->dialog.valueW)
419 if (XtIsManaged(*childP) &&
420 XtIsSubclass(*childP, commandWidgetClass)) {
421 ((DialogConstraints)(*childP)->core.constraints)->
422 form.vert_base = dw->dialog.valueW;
426 XtManageChild(dw->dialog.valueW);
429 * Value widget gets the keyboard focus
431 XtSetKeyboardFocus(w, dw->dialog.valueW);
432 dw->dialog.value = MAGIC_VALUE;
436 XawDialogAddButton(Widget dialog, _Xconst char* name, XtCallbackProc function,
440 * Correct Constraints are all set in ConstraintInitialize()
444 button = XtCreateManagedWidget(name, commandWidgetClass, dialog, NULL, 0);
446 if (function != NULL) /* don't add NULL callback func */
447 XtAddCallback(button, XtNcallback, function, param);
451 XawDialogGetValueString(Widget w)
456 XtSetArg(args[0], XtNstring, &value);
457 XtGetValues(((DialogWidget)w)->dialog.valueW, args, 1);