diff options
Diffstat (limited to 'src/Dialog.c')
-rw-r--r-- | src/Dialog.c | 495 |
1 files changed, 254 insertions, 241 deletions
diff --git a/src/Dialog.c b/src/Dialog.c index fe77938..e2e8315 100644 --- a/src/Dialog.c +++ b/src/Dialog.c @@ -46,177 +46,214 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ - -/* NOTE: THIS IS NOT A WIDGET! Rather, this is an interface to a widget. - It implements policy, and gives a (hopefully) easier-to-use interface - than just directly making your own form. */ - +/* $XFree86: xc/lib/Xaw/Dialog.c,v 1.8 2001/12/14 19:54:39 dawes Exp $ */ #include <X11/IntrinsicP.h> -#include <X11/Xos.h> #include <X11/StringDefs.h> +#include <X11/Xos.h> #include <X11/Xmu/Misc.h> - -#include <X11/Xaw/XawInit.h> #include <X11/Xaw/AsciiText.h> +#include <X11/Xaw/Cardinals.h> #include <X11/Xaw/Command.h> #include <X11/Xaw/Label.h> #include <X11/Xaw/DialogP.h> -#include <X11/Xaw/Cardinals.h> +#include <X11/Xaw/XawInit.h> +#include "Private.h" /* * After we have set the string in the value widget we set the * string to a magic value. So that when a SetValues request is made - * on the dialog value we will notice it, and reset the string. + * on the dialog value we will notice it, and reset the string */ +#define MAGIC_VALUE ((char *)3) -#define MAGIC_VALUE ((char *) 3) +#define streq(a,b) (strcmp((a), (b)) == 0) -#define streq(a,b) (strcmp( (a), (b) ) == 0) +/* + * Class Methods + */ +static void XawDialogConstraintInitialize(Widget, Widget, + ArgList, Cardinal*); +static void XawDialogGetValuesHook(Widget, ArgList, Cardinal*); +static void XawDialogInitialize(Widget, Widget, ArgList, Cardinal*); +static Boolean XawDialogSetValues(Widget, Widget, Widget, + ArgList, Cardinal*); +/* + * Prototypes + */ +static void CreateDialogValueWidget(Widget); + +/* + * Initialization + */ static XtResource resources[] = { - {XtNlabel, XtCLabel, XtRString, sizeof(String), - XtOffsetOf(DialogRec, dialog.label), XtRString, NULL}, - {XtNvalue, XtCValue, XtRString, sizeof(String), - XtOffsetOf(DialogRec, dialog.value), XtRString, NULL}, - {XtNicon, XtCIcon, XtRBitmap, sizeof(Pixmap), - XtOffsetOf(DialogRec, dialog.icon), XtRImmediate, 0}, + { + XtNlabel, + XtCLabel, + XtRString, + sizeof(String), + XtOffsetOf(DialogRec, dialog.label), + XtRString, + NULL + }, + { + XtNvalue, + XtCValue, + XtRString, + sizeof(String), + XtOffsetOf(DialogRec, dialog.value), + XtRString, + NULL + }, + { + XtNicon, + XtCIcon, + XtRBitmap, + sizeof(Pixmap), + XtOffsetOf(DialogRec, dialog.icon), + XtRImmediate, + 0 + }, }; -static void Initialize(), ConstraintInitialize(), CreateDialogValueWidget(), - GetValuesHook(); - -static Boolean SetValues(); - DialogClassRec dialogClassRec = { - { /* core_class fields */ - /* superclass */ (WidgetClass) &formClassRec, - /* class_name */ "Dialog", - /* widget_size */ sizeof(DialogRec), - /* class_initialize */ XawInitializeWidgetSet, - /* class_part init */ NULL, - /* class_inited */ FALSE, - /* initialize */ Initialize, - /* initialize_hook */ NULL, - /* realize */ XtInheritRealize, - /* actions */ NULL, - /* num_actions */ 0, - /* resources */ resources, - /* num_resources */ XtNumber(resources), - /* xrm_class */ NULLQUARK, - /* compress_motion */ TRUE, - /* compress_exposure */ TRUE, - /* compress_enterleave*/ TRUE, - /* visible_interest */ FALSE, - /* destroy */ NULL, - /* resize */ XtInheritResize, - /* expose */ XtInheritExpose, - /* set_values */ SetValues, - /* set_values_hook */ NULL, - /* set_values_almost */ XtInheritSetValuesAlmost, - /* get_values_hook */ GetValuesHook, - /* accept_focus */ NULL, - /* version */ XtVersion, - /* callback_private */ NULL, - /* tm_table */ NULL, - /* query_geometry */ XtInheritQueryGeometry, - /* display_accelerator*/ XtInheritDisplayAccelerator, - /* extension */ NULL + /* core */ + { + (WidgetClass)&formClassRec, /* superclass */ + "Dialog", /* class_name */ + sizeof(DialogRec), /* widget_size */ + XawInitializeWidgetSet, /* class_initialize */ + NULL, /* class_part init */ + False, /* class_inited */ + XawDialogInitialize, /* initialize */ + NULL, /* initialize_hook */ + XtInheritRealize, /* realize */ + NULL, /* actions */ + 0, /* num_actions */ + resources, /* resources */ + XtNumber(resources), /* num_resources */ + NULLQUARK, /* xrm_class */ + True, /* compress_motion */ + True, /* compress_exposure */ + True, /* compress_enterleave */ + False, /* visible_interest */ + NULL, /* destroy */ + XtInheritResize, /* resize */ + XtInheritExpose, /* expose */ + XawDialogSetValues, /* set_values */ + NULL, /* set_values_hook */ + XtInheritSetValuesAlmost, /* set_values_almost */ + XawDialogGetValuesHook, /* get_values_hook */ + NULL, /* accept_focus */ + XtVersion, /* version */ + NULL, /* callback_private */ + NULL, /* tm_table */ + XtInheritQueryGeometry, /* query_geometry */ + XtInheritDisplayAccelerator, /* display_accelerator */ + NULL, /* extension */ }, - { /* composite_class fields */ - /* geometry_manager */ XtInheritGeometryManager, - /* change_managed */ XtInheritChangeManaged, - /* insert_child */ XtInheritInsertChild, - /* delete_child */ XtInheritDeleteChild, - /* extension */ NULL + /* composite */ + { + XtInheritGeometryManager, /* geometry_manager */ + XtInheritChangeManaged, /* change_managed */ + XtInheritInsertChild, /* insert_child */ + XtInheritDeleteChild, /* delete_child */ + NULL, /* extension */ }, - { /* constraint_class fields */ - /* subresourses */ NULL, - /* subresource_count */ 0, - /* constraint_size */ sizeof(DialogConstraintsRec), - /* initialize */ ConstraintInitialize, - /* destroy */ NULL, - /* set_values */ NULL, - /* extension */ NULL + /* constraint */ + { + NULL, /* subresourses */ + 0, /* subresource_count */ + sizeof(DialogConstraintsRec), /* constraint_size */ + XawDialogConstraintInitialize, /* initialize */ + NULL, /* destroy */ + NULL, /* set_values */ + NULL, /* extension */ }, - { /* form_class fields */ - /* layout */ XtInheritLayout + /* form */ + { + XtInheritLayout, /* layout */ }, - { /* dialog_class fields */ - /* empty */ 0 + /* dialog */ + { + NULL, /* extension */ } }; WidgetClass dialogWidgetClass = (WidgetClass)&dialogClassRec; -/* ARGSUSED */ -static void Initialize(request, new, args, num_args) -Widget request, new; -ArgList args; -Cardinal *num_args; +/* + * Implementation + */ +/*ARGSUSED*/ +static void +XawDialogInitialize(Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - DialogWidget dw = (DialogWidget)new; + DialogWidget dw = (DialogWidget)cnew; Arg arglist[9]; Cardinal arg_cnt = 0; - XtSetArg(arglist[arg_cnt], XtNborderWidth, 0); arg_cnt++; - XtSetArg(arglist[arg_cnt], XtNleft, XtChainLeft); arg_cnt++; + XtSetArg(arglist[arg_cnt], XtNborderWidth, 0); arg_cnt++; + XtSetArg(arglist[arg_cnt], XtNleft, XtChainLeft); arg_cnt++; if (dw->dialog.icon != (Pixmap)0) { - XtSetArg(arglist[arg_cnt], XtNbitmap, dw->dialog.icon); arg_cnt++; - XtSetArg(arglist[arg_cnt], XtNright, XtChainLeft); arg_cnt++; - dw->dialog.iconW = - XtCreateManagedWidget( "icon", labelWidgetClass, - new, arglist, arg_cnt ); + XtSetArg(arglist[arg_cnt], XtNbitmap, dw->dialog.icon); arg_cnt++; + XtSetArg(arglist[arg_cnt], XtNright, XtChainLeft); arg_cnt++; + dw->dialog.iconW = XtCreateManagedWidget("icon", labelWidgetClass, + cnew, arglist, arg_cnt); arg_cnt = 2; - XtSetArg(arglist[arg_cnt], XtNfromHoriz, dw->dialog.iconW);arg_cnt++; - } else dw->dialog.iconW = (Widget)NULL; + XtSetArg(arglist[arg_cnt], XtNfromHoriz, dw->dialog.iconW); arg_cnt++; + } + else + dw->dialog.iconW = NULL; - XtSetArg(arglist[arg_cnt], XtNlabel, dw->dialog.label); arg_cnt++; - XtSetArg(arglist[arg_cnt], XtNright, XtChainRight); arg_cnt++; + XtSetArg(arglist[arg_cnt], XtNlabel, dw->dialog.label); arg_cnt++; + XtSetArg(arglist[arg_cnt], XtNright, XtChainRight); arg_cnt++; - dw->dialog.labelW = XtCreateManagedWidget( "label", labelWidgetClass, - new, arglist, arg_cnt); + dw->dialog.labelW = XtCreateManagedWidget("label", labelWidgetClass, + cnew, arglist, arg_cnt); - if (dw->dialog.iconW != (Widget)NULL && - (dw->dialog.labelW->core.height < dw->dialog.iconW->core.height)) { - XtSetArg( arglist[0], XtNheight, dw->dialog.iconW->core.height ); - XtSetValues( dw->dialog.labelW, arglist, ONE ); + if (dw->dialog.iconW != NULL && + XtHeight(dw->dialog.labelW) < XtHeight(dw->dialog.iconW)) { + XtSetArg(arglist[0], XtNheight, XtHeight(dw->dialog.iconW)); + XtSetValues(dw->dialog.labelW, arglist, 1); } if (dw->dialog.value != NULL) - CreateDialogValueWidget( (Widget) dw); + CreateDialogValueWidget((Widget)dw); else dw->dialog.valueW = NULL; } -/* ARGSUSED */ -static void ConstraintInitialize(request, new, args, num_args) -Widget request, new; -ArgList args; -Cardinal *num_args; +/*ARGSUSED*/ +static void +XawDialogConstraintInitialize(Widget request, Widget cnew, + ArgList args, Cardinal *num_args) { - DialogWidget dw = (DialogWidget)new->core.parent; - DialogConstraints constraint = (DialogConstraints)new->core.constraints; + DialogWidget dw = (DialogWidget)cnew->core.parent; + DialogConstraints constraint = (DialogConstraints)cnew->core.constraints; - if (!XtIsSubclass(new, commandWidgetClass)) /* if not a button */ - return; /* then just use defaults */ + if (!XtIsSubclass(cnew, commandWidgetClass)) /* if not a button */ + return; /* then just use defaults */ constraint->form.left = constraint->form.right = XtChainLeft; if (dw->dialog.valueW == NULL) - constraint->form.vert_base = dw->dialog.labelW; + constraint->form.vert_base = dw->dialog.labelW; else - constraint->form.vert_base = dw->dialog.valueW; + constraint->form.vert_base = dw->dialog.valueW; if (dw->composite.num_children > 1) { WidgetList children = dw->composite.children; Widget *childP; + for (childP = children + dw->composite.num_children - 1; - childP >= children; childP-- ) { + childP >= children; childP-- ) { if (*childP == dw->dialog.labelW || *childP == dw->dialog.valueW) - break; + break; if (XtIsManaged(*childP) && - XtIsSubclass(*childP, commandWidgetClass)) { - constraint->form.horiz_base = *childP; + XtIsSubclass(*childP, commandWidgetClass)) { + constraint->form.horiz_base = *childP; break; } } @@ -226,222 +263,198 @@ Cardinal *num_args; #define ICON 0 #define LABEL 1 #define NUM_CHECKS 2 - -/* ARGSUSED */ -static Boolean SetValues(current, request, new, in_args, in_num_args) -Widget current, request, new; -ArgList in_args; -Cardinal *in_num_args; +/*ARGSUSED*/ +static Boolean +XawDialogSetValues(Widget current, Widget request, Widget cnew, + ArgList in_args, Cardinal *in_num_args) { - DialogWidget w = (DialogWidget)new; + DialogWidget w = (DialogWidget)cnew; DialogWidget old = (DialogWidget)current; Arg args[5]; Cardinal num_args; - int i; - Boolean checks[NUM_CHECKS]; + unsigned int i; + Bool checks[NUM_CHECKS]; for (i = 0; i < NUM_CHECKS; i++) - checks[i] = FALSE; + checks[i] = False; for (i = 0; i < *in_num_args; i++) { if (streq(XtNicon, in_args[i].name)) - checks[ICON] = TRUE; - if (streq(XtNlabel, in_args[i].name)) - checks[LABEL] = TRUE; + checks[ICON] = True; + else if (streq(XtNlabel, in_args[i].name)) + checks[LABEL] = True; } if (checks[ICON]) { - if (w->dialog.icon != (Pixmap)0) { - XtSetArg( args[0], XtNbitmap, w->dialog.icon ); - if (old->dialog.iconW != (Widget)NULL) { - XtSetValues( old->dialog.iconW, args, ONE ); - } else { - XtSetArg( args[1], XtNborderWidth, 0); - XtSetArg( args[2], XtNleft, XtChainLeft); - XtSetArg( args[3], XtNright, XtChainLeft); - w->dialog.iconW = - XtCreateWidget( "icon", labelWidgetClass, - new, args, FOUR ); + if (w->dialog.icon != 0) { + XtSetArg(args[0], XtNbitmap, w->dialog.icon); + if (old->dialog.iconW != NULL) + XtSetValues(old->dialog.iconW, args, 1); + else { + XtSetArg(args[1], XtNborderWidth, 0); + XtSetArg(args[2], XtNleft, XtChainLeft); + XtSetArg(args[3], XtNright, XtChainLeft); + w->dialog.iconW = XtCreateWidget("icon", labelWidgetClass, + cnew, args, 4); ((DialogConstraints)w->dialog.labelW->core.constraints)-> form.horiz_base = w->dialog.iconW; XtManageChild(w->dialog.iconW); } - } else if (old->dialog.icon != (Pixmap)0) { + } + else if (old->dialog.icon != 0) { ((DialogConstraints)w->dialog.labelW->core.constraints)-> - form.horiz_base = (Widget)NULL; + form.horiz_base = NULL; XtDestroyWidget(old->dialog.iconW); - w->dialog.iconW = (Widget)NULL; + w->dialog.iconW = NULL; } } - if ( checks[LABEL] ) { - num_args = 0; - XtSetArg( args[num_args], XtNlabel, w->dialog.label ); num_args++; - if (w->dialog.iconW != (Widget)NULL && - (w->dialog.labelW->core.height <= w->dialog.iconW->core.height)) { - XtSetArg(args[num_args], XtNheight, w->dialog.iconW->core.height); + if (checks[LABEL]) { + num_args = 0; + XtSetArg(args[num_args], XtNlabel, w->dialog.label); num_args++; + if (w->dialog.iconW != NULL && + XtHeight(w->dialog.labelW) <= XtHeight(w->dialog.iconW)) { + XtSetArg(args[num_args], XtNheight, XtHeight(w->dialog.iconW)); num_args++; } - XtSetValues( w->dialog.labelW, args, num_args ); + XtSetValues(w->dialog.labelW, args, num_args); } - if ( w->dialog.value != old->dialog.value ) { - if (w->dialog.value == NULL) /* only get here if it - wasn't NULL before. */ + if (w->dialog.value != old->dialog.value) { + if (w->dialog.value == NULL) /* only get here if it + wasn't NULL before */ XtDestroyWidget(old->dialog.valueW); - else if (old->dialog.value == NULL) { /* create a new value widget. */ - w->core.width = old->core.width; - w->core.height = old->core.height; -#ifdef notdef -/* this would be correct if Form had the same semantics on Resize - * as on MakeGeometryRequest. Unfortunately, Form botched it, so - * any subclasses will currently have to deal with the fact that - * we're about to change our real size. - */ - w->form.resize_in_layout = False; - CreateDialogValueWidget( (Widget) w); - w->core.width = w->form.preferred_width; - w->core.height = w->form.preferred_height; - w->form.resize_in_layout = True; -#else /*notdef*/ - CreateDialogValueWidget( (Widget) w); -#endif /*notdef*/ + else if (old->dialog.value == NULL) { /* create a new value widget */ + XtWidth(w) = XtWidth(old); + XtHeight(w) = XtHeight(old); + CreateDialogValueWidget(cnew); } - else { /* Widget ok, just change string. */ - Arg args[1]; - XtSetArg(args[0], XtNstring, w->dialog.value); - XtSetValues(w->dialog.valueW, args, ONE); + else { /* Widget ok, just change string */ + Arg nargs[1]; + + XtSetArg(nargs[0], XtNstring, w->dialog.value); + XtSetValues(w->dialog.valueW, nargs, 1); w->dialog.value = MAGIC_VALUE; } } - return False; + + return (False); } -/* Function Name: GetValuesHook - * Description: This is a get values hook routine that gets the - * values in the dialog. - * Arguments: w - the Text Widget. - * args - the argument list. - * num_args - the number of args. - * Returns: none. +/* + * Function: + * XawDialogGetValuesHook + * + * Parameters: + * w - Dialog Widget + * args - argument list + * num_args - number of args + * + * Description: + * This is a get values hook routine that gets the values in the dialog. */ - static void -GetValuesHook(w, args, num_args) -Widget w; -ArgList args; -Cardinal * num_args; +XawDialogGetValuesHook(Widget w, ArgList args, Cardinal *num_args) { - Arg a[1]; - String s; - DialogWidget src = (DialogWidget) w; - int i; + Arg a[1]; + String s; + DialogWidget src = (DialogWidget)w; + unsigned int i; - for (i=0; i < *num_args; i++) - if (streq(args[i].name, XtNvalue)) { - XtSetArg(a[0], XtNstring, &s); - XtGetValues(src->dialog.valueW, a, 1); - *((char **) args[i].value) = s; - } + for (i = 0; i < *num_args; i++) + if (streq(args[i].name, XtNvalue)) { + XtSetArg(a[0], XtNstring, &s); + XtGetValues(src->dialog.valueW, a, 1); + *((char **)args[i].value) = s; + } + else if (streq(args[i].name, XtNlabel)) { + XtSetArg(a[0], XtNlabel, &s); + XtGetValues(src->dialog.labelW, a, 1); + *((char **)args[i].value) = s; + } } - -/* Function Name: CreateDialogValueWidget - * Description: Creates the dialog widgets value widget. - * Arguments: w - the dialog widget. - * Returns: none. +/* + * Function: + * CreateDialogValueWidget * - * must be called only when w->dialog.value is non-nil. + * Parameters: + * w - dialog widget + * + * Description: + * Creates the dialog widgets value widget. + * + * Note + * Must be called only when w->dialog.value is non-nil */ - static void -CreateDialogValueWidget(w) -Widget w; +CreateDialogValueWidget(Widget w) { - DialogWidget dw = (DialogWidget) w; + DialogWidget dw = (DialogWidget)w; Arg arglist[10]; Cardinal num_args = 0; -#ifdef notdef - XtSetArg(arglist[num_args], XtNwidth, - dw->dialog.labelW->core.width); num_args++; /* ||| hack */ -#endif /*notdef*/ XtSetArg(arglist[num_args], XtNstring, dw->dialog.value); num_args++; XtSetArg(arglist[num_args], XtNresizable, True); num_args++; - XtSetArg(arglist[num_args], XtNresize, XawtextResizeBoth); num_args++; XtSetArg(arglist[num_args], XtNeditType, XawtextEdit); num_args++; XtSetArg(arglist[num_args], XtNfromVert, dw->dialog.labelW); num_args++; XtSetArg(arglist[num_args], XtNleft, XtChainLeft); num_args++; XtSetArg(arglist[num_args], XtNright, XtChainRight); num_args++; dw->dialog.valueW = XtCreateWidget("value", asciiTextWidgetClass, - w, arglist, num_args); + w, arglist, num_args); /* if the value widget is being added after buttons, - * then the buttons need new layout constraints. + * then the buttons need new layout constraints */ if (dw->composite.num_children > 1) { WidgetList children = dw->composite.children; Widget *childP; + for (childP = children + dw->composite.num_children - 1; childP >= children; childP-- ) { if (*childP == dw->dialog.labelW || *childP == dw->dialog.valueW) continue; + if (XtIsManaged(*childP) && - XtIsSubclass(*childP, commandWidgetClass)) { - ((DialogConstraints)(*childP)->core.constraints)-> + XtIsSubclass(*childP, commandWidgetClass)) { + ((DialogConstraints)(*childP)->core.constraints)-> form.vert_base = dw->dialog.valueW; } } } XtManageChild(dw->dialog.valueW); -/* - * Value widget gets the keyboard focus. - */ - + /* + * Value widget gets the keyboard focus + */ XtSetKeyboardFocus(w, dw->dialog.valueW); dw->dialog.value = MAGIC_VALUE; } - void -#if NeedFunctionPrototypes XawDialogAddButton(Widget dialog, _Xconst char* name, XtCallbackProc function, XtPointer param) -#else -XawDialogAddButton(dialog, name, function, param) -Widget dialog; -String name; -XtCallbackProc function; -XtPointer param; -#endif { -/* - * Correct Constraints are all set in ConstraintInitialize(). - */ + /* + * Correct Constraints are all set in ConstraintInitialize() + */ Widget button; - button = XtCreateManagedWidget( name, commandWidgetClass, dialog, - (ArgList)NULL, (Cardinal)0 ); + button = XtCreateManagedWidget(name, commandWidgetClass, dialog, NULL, 0); - if (function != NULL) /* don't add NULL callback func. */ - XtAddCallback(button, XtNcallback, function, param); + if (function != NULL) /* don't add NULL callback func */ + XtAddCallback(button, XtNcallback, function, param); } - char * -#if NeedFunctionPrototypes XawDialogGetValueString(Widget w) -#else -XawDialogGetValueString(w) -Widget w; -#endif { Arg args[1]; - char * value; + char *value; XtSetArg(args[0], XtNstring, &value); - XtGetValues( ((DialogWidget)w)->dialog.valueW, args, ONE); + XtGetValues(((DialogWidget)w)->dialog.valueW, args, 1); + return(value); } |