home *** CD-ROM | disk | FTP | other *** search
- /* Systems Sciences Laboratory, Webster Research Center */
-
- static char *PROGRAM_information[] =
- {
- "Copyright (c) 1988 Xerox Corporation. All rights reserved.",
- "$Header$",
- "$Locker$"
- }
- ;
-
- /*
- * Copyright protection claimed includes all forms and matters of copyrightable
- * material and information now allowed by statutory or judicial lay or
- * herinafter granted, including without limitation, material generated from
- * the software programs which are displayed on the screen such as icons,
- * screen display looks, etc.
- */
-
-
- /* NOTE: This is modelled after the dialog 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. */
-
-
- #include <X11/Xlib.h>
- #include <X11/Xos.h>
- #include <X11/IntrinsicP.h>
- #include <X11/XawMisc.h>
- #include <X11/StringDefs.h>
- #include <X11/AsciiText.h>
- #include <X11/Command.h>
- #include <X11/Label.h>
- #include "optionP.h"
- #include "toggleP.h"
- #include <ctype.h>
-
- #define offset(field) XtOffset(OptionWidget, field)
-
-
- static XtResource resourcelist[] = {
- {XtNlabel, XtCLabel, XtRString, sizeof(String),
- offset(option.label), XtRString, NULL},
- {XtNorientation, XtCOrientation, XtROrientation, sizeof(XtOrientation),
- offset(option.orientation), XtRString, "orientVertical"},
- };
-
- extern void Initialize(), ConstraintInitialize();
- extern Boolean SetValues();
- extern void DoOption();
-
- OptionClassRec optionClassRec = {
- { /* core_class fields */
- /* superclass */ (WidgetClass) &formClassRec,
- /* class_name */ "Option",
- /* widget_size */ sizeof(OptionRec),
- /* class_initialize */ NULL,
- /* class_part init */ NULL,
- /* class_inited */ FALSE,
- /* initialize */ Initialize,
- /* initialize_hook */ NULL,
- /* realize */ XtInheritRealize,
- /* actions */ NULL,
- /* num_actions */ 0,
- /* resources */ resourcelist,
- /* num_resources */ XtNumber(resourcelist),
- /* 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 */ NULL,
- /* accept_focus */ NULL,
- /* version */ XtVersion,
- /* callback_private */ NULL,
- /* tm_table */ NULL,
- /* query_geometry */ NULL,
- /* display_accelerator*/ XtInheritDisplayAccelerator,
- /* extension */ NULL,
-
- },
- { /* composite_class fields */
- /* geometry_manager */ XtInheritGeometryManager,
- /* change_managed */ XtInheritChangeManaged,
- /* insert_child */ XtInheritInsertChild,
- /* delete_child */ XtInheritDeleteChild,
- /* extension */ NULL,
- },
- { /* constraint_class fields */
- /* subresourses */ NULL,
- /* subresource_count */ 0,
- /* constraint_size */ sizeof(OptionConstraintsRec),
- /* initialize */ ConstraintInitialize,
- /* destroy */ NULL,
- /* set_values */ NULL
- },
- { /* form_class fields */
- /* empty */ 0
- },
- { /* option_class fields */
- /* empty */ 0
- }
- };
-
- WidgetClass optionWidgetClass = (WidgetClass)&optionClassRec;
-
- /****************************************************************
- *
- * Private Procedures
- *
- ****************************************************************/
-
- /* ARGSUSED */
- static void Initialize(request, new)
- Widget request, new;
- {
- OptionWidget dw = (OptionWidget)new;
- static Arg label_args[] = {
- {XtNlabel, (XtArgVal)NULL},
- {XtNborderWidth, (XtArgVal) 0}
- };
-
- label_args[0].value = (XtArgVal)dw->option.label;
- dw->option.labelW = XtCreateManagedWidget( "label",
- labelWidgetClass, new,
- label_args, XtNumber(label_args) );
- dw->option.select = 0;
- }
-
-
- /* ARGSUSED */
- static void ConstraintInitialize(request, new)
- Widget request, new;
- {
- OptionWidget dw = (OptionWidget)new->core.parent;
- WidgetList children = dw->composite.children;
- OptionConstraints constraint = (OptionConstraints)new->core.constraints;
- Widget *childP;
-
- if (!XtIsSubclass(new, toggleWidgetClass)) /* if not a toggle */
- return; /* then just use defaults */
-
- constraint->form.left = constraint->form.right = XtChainLeft;
- constraint->form.vert_base = dw->option.labelW;
-
- if (dw->composite.num_children > 1) {
- for (childP = children + dw->composite.num_children - 1;
- childP >= children; childP-- ) {
- if (*childP == dw->option.labelW)
- break;
- if (XtIsManaged(*childP) &&
- XtIsSubclass(*childP, toggleWidgetClass)) {
- if (dw->option.orientation == XtorientHorizontal)
- constraint->form.horiz_base = *childP;
- else constraint->form.vert_base = *childP;
- break;
- }
- }
- }
- }
-
- /***************************
- *
- * Action Procedures
- *
- ***************************/
-
- static void DoOption(w, client_data, call_data)
- Widget w;
- caddr_t client_data, call_data;
- {
- ToggleWidget tw = (ToggleWidget)w;
- OptionWidget parent = (OptionWidget)tw->core.parent;
- XtState newstate = (XtState)call_data;
- Arg togglearg[1];
- Boolean found = 0;
- int i = 1;
-
- if (newstate == XtToggleOff) {
- /* the currently selected toggle button is selected */
- XtSetArg(togglearg[0], XtNstate, XtToggleOn);
- XtSetValues(w, togglearg, (Cardinal)1);
- return;
- }
- else {
- XtSetArg(togglearg[0], XtNstate, XtToggleOff);
-
- XtSetValues(parent->composite.children[parent->option.select],
- togglearg, (Cardinal)1);
- }
-
- while (!found && i < parent->composite.num_children)
- if ((Widget)parent->composite.children[i] == w) {
- found = 1;
- parent->option.select = i;
- break;
- }
- else i++;
- }
-
- /* ARGSUSED */
- static Boolean SetValues(current, request, new)
- Widget current, request, new;
- {
- return False;
- }
-
- void DoHorizontalOption(parent, left, upper)
- OptionWidget parent;
- Widget *left, *upper;
- {
- *left = (Widget) parent->option.label;
-
- if ( (parent->composite.num_children > 1) )
- *upper = (Widget)parent->
- composite.children[parent->composite.num_children - 1];
- else *upper = (Widget)NULL;
- }
-
- void DoVerticalOption(parent, left, upper)
- OptionWidget parent;
- Widget *left, *upper;
- {
- *upper = (Widget)parent->
- composite.children[parent->composite.num_children - 1];
-
- *left = (Widget)NULL;
- }
-
- void XtOptionAddOption(option, name, set)
- Widget option;
- char *name;
- Boolean set;
- {
- OptionWidget parent = (OptionWidget)option;
- Widget left, upper;
- Arg togglearg[1];
- static XtCallbackRec callbackList[] = { {NULL, NULL}, {NULL, NULL} };
-
- static Arg arglist[] = {
- {XtNfromHoriz, (XtArgVal) NULL},
- {XtNfromVert, (XtArgVal) NULL},
- {XtNstate, (XtArgVal) NULL},
- {XtNcallback,(XtArgVal)callbackList},
- {XtNleft, (XtArgVal) XtChainLeft},
- {XtNright, (XtArgVal) XtChainLeft},
- {XtNtop, (XtArgVal) XtChainTop},
- {XtNbottom, (XtArgVal) XtChainTop}
- };
-
- if (parent->option.orientation == XtorientHorizontal)
- DoHorizontalOption(parent, &left, &upper);
- else DoVerticalOption(parent, &left, &upper);
-
- arglist[0].value = (XtArgVal)left;
- arglist[1].value = (XtArgVal)upper;
-
- if (set && parent->option.select != 0) {
- arglist[2].value = (XtArgVal)XtToggleOn;
- /* reset existing toggle widget */
- XtSetArg(togglearg[0], XtNstate, XtToggleOff);
- XtSetValues(parent->composite.children[parent->option.select],
- togglearg, (Cardinal)1);
- parent->option.select = parent->composite.num_children;
- }
- else if (parent->option.select == 0) {
- arglist[2].value = (XtArgVal)XtToggleOn;
- parent->option.select = parent->composite.num_children;
- }
- else arglist[2].value = (XtArgVal)XtToggleOff;
-
- callbackList[0].callback = DoOption;
-
- XtCreateManagedWidget(name, toggleWidgetClass, option,
- arglist, XtNumber(arglist) );
- }
-
-
- int XtOptionGetSelection(w)
- Widget w;
- {
- return ((OptionWidget)w)->option.select;
- }
-
- void XtOptionSetSelection(w, index)
- Widget w;
- int index;
- {
- Arg toggleargs[1];
- OptionWidget parent = (OptionWidget)w;
-
- XtSetArg(toggleargs[0], XtNstate, XtToggleOff);
- XtSetValues(parent->composite.children[parent->option.select],
- toggleargs, XtNumber(toggleargs));
-
- XtSetArg(toggleargs[0], XtNstate, XtToggleOn);
- XtSetValues(parent->composite.children[index],
- toggleargs, XtNumber(toggleargs));
- parent->option.select = index;
- }
-