home *** CD-ROM | disk | FTP | other *** search
- /***********************************************************
- Copyright 1990 by Digital Equipment Corporation, Maynard, Massachusetts.
-
- All Rights Reserved
-
- Permission to use, copy, modify, and distribute these examples for any
- purpose and without fee is hereby granted, provided that the above
- copyright notice appear in all copies and that both that copyright
- notice and this permission notice appear in supporting documentation,
- and that the name of Digital not be used in advertising or publicity
- pertaining to distribution of the software without specific, written
- prior permission.
-
- DIGITAL AND THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
- SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
- FITNESS, IN NO EVENT SHALL DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT
- OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
- OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
- OR PERFORMANCE OF THIS SOFTWARE.
-
- ******************************************************************/
-
- #include <X11/IntrinsicP.h> /* Intrinsics header file */
- #include <X11/StringDefs.h> /* Resource string definitions */
- #include "Confirm1P.h" /* Confirm private header file */
- #include "Label.h" /* Label public header file */
- #include "Pushbutton.h" /* Pushbutton public header file */
-
- #define Offset(field) XtOffsetOf(ConfirmRec, confirm.field)
-
- static XtResource resources[] = {
- {XtNmargin, XtCMargin, XtRDimension, sizeof(Dimension),
- Offset(margin), XtRImmediate, (XtPointer) 10},
- {XtNlabel, XtCLabel, XtRString, sizeof(String),
- Offset(label), XtRString, "Click to confirm"},
- {XtNbuttonLabel, XtCButtonLabel, XtRString, sizeof(String),
- Offset(button_label), XtRString, "OK"},
- {XtNcallback, XtCCallback, XtRCallback, sizeof(XtPointer),
- Offset(callback), XtRCallback, (XtPointer) NULL},
- {XtNlabelWidget, XtCReadOnly, XtRWidget, sizeof(Widget),
- Offset(label_widget), XtRImmediate, (XtPointer) NULL},
- {XtNbuttonWidget, XtCReadOnly, XtRWidget, sizeof(Widget),
- Offset(button_widget), XtRImmediate, (XtPointer) NULL}
- };
-
- #undef Offset
-
- #define LabelChild(w) (((ConfirmWidget) w)->confirm.label_widget)
- #define ButtonChild(w) (((ConfirmWidget) w)->confirm.button_widget)
-
- /* Forward declarations */
-
- static void Initialize(), PositionChildren(), Realize(), Destroy();
- static Boolean SetValues();
-
- ConfirmClassRec confirmClassRec = {
- /* Core class part */
- {
- /* superclass */ (WidgetClass) &widgetClassRec,
- /* class_name */ "Confirm",
- /* widget_size */ sizeof(ConfirmRec),
- /* class_initialize */ NULL,
- /* class_part_initialize */ NULL,
- /* class_inited */ FALSE,
- /* initialize */ Initialize,
- /* initialize_hook */ NULL,
- /* realize */ Realize,
- /* actions */ NULL,
- /* num_actions */ 0,
- /* resources */ resources,
- /* num_resources */ XtNumber(resources),
- /* xrm_class */ NULLQUARK,
- /* compress_motion */ TRUE,
- /* compress_exposure */ XtExposeCompressMultiple,
- /* compress_enterleave */ TRUE,
- /* visible_interest */ FALSE,
- /* destroy */ Destroy,
- /* resize */ PositionChildren,
- /* expose */ NULL,
- /* set_values */ SetValues,
- /* set_values_hook */ NULL,
- /* set_values_almost */ XtInheritSetValuesAlmost,
- /* get_values_hook */ NULL,
- /* accept_focus */ NULL,
- /* version */ XtVersion,
- /* callback offsets */ NULL,
- /* tm_table */ NULL,
- /* query_geometry */ XtInheritQueryGeometry,
- /* display_accelerator */ NULL,
- /* extension */ NULL,
- },
- /* Confirm class part */
- {
- /* extension */ NULL,
- }
- };
-
- WidgetClass confirmWidgetClass = (WidgetClass) &confirmClassRec;
-
- static void Callback(w, call_data, client_data)
- Widget w;
- XtPointer call_data, client_data;
- {
- ConfirmWidget confirm = (ConfirmWidget) XtParent(w);
-
- if (XtIsShell(XtParent(confirm))) XtPopdown(XtParent(confirm));
- XtCallCallbackList(confirm, confirm->confirm.callback,
- (XtPointer) NULL);
- }
-
- static void CalculateSize(cw, width, height)
- ConfirmWidget cw;
- Dimension *width, *height;
- {
- int label_width = LabelChild(cw)->core.width +
- 2 * LabelChild(cw)->core.border_width,
- button_width = ButtonChild(cw)->core.width +
- 2 * ButtonChild(cw)->core.border_width,
- max;
-
- max = label_width > button_width ? label_width : button_width;
-
- *width = max + 2 * cw->confirm.margin;
- *height = LabelChild(cw)->core.height +
- ButtonChild(cw)->core.height +
- 2 * (LabelChild(cw)->core.border_width +
- ButtonChild(cw)->core.border_width) +
- 3 * cw->confirm.margin;
- }
-
- static void PositionChildren(cw)
- ConfirmWidget cw;
- {
- int label_width = LabelChild(cw)->core.width +
- 2 * LabelChild(cw)->core.border_width,
- button_width = ButtonChild(cw)->core.width +
- 2 * ButtonChild(cw)->core.border_width;
-
- XtMoveWidget(LabelChild(cw), (cw->core.width - label_width) / 2,
- cw->confirm.margin);
- XtMoveWidget(ButtonChild(cw), (cw->core.width - button_width) / 2,
- 2 * cw->confirm.margin +
- 2 * LabelChild(cw)->core.border_width +
- LabelChild(cw)->core.height);
- }
-
- static void Initialize(req, new, args, num_args)
- Widget req, new;
- ArgList args;
- Cardinal *num_args;
- {
- ConfirmWidget cw = (ConfirmWidget) new;
- Arg arg[1];
-
- cw->confirm.label = XtNewString(cw->confirm.label);
- XtSetArg(arg[0], XtNlabel, cw->confirm.label);
- LabelChild(cw) = XtCreateWidget("label", labelWidgetClass,
- new, arg, 1);
-
- cw->confirm.button_label = XtNewString(cw->confirm.button_label);
- XtSetArg(arg[0], XtNlabel, cw->confirm.button_label);
- ButtonChild(cw) = XtCreateWidget("button", pushbuttonWidgetClass,
- new, arg, 1);
- XtAddCallback(ButtonChild(cw), XtNcallback, Callback, NULL);
-
- CalculateSize(cw, &cw->core.width, &cw->core.height);
- PositionChildren(cw);
- }
-
- static void Realize(w, valueMask, attributes)
- Widget w;
- XtValueMask *valueMask;
- XSetWindowAttributes *attributes;
- {
- (*confirmWidgetClass->core_class.superclass->core_class.realize)
- (w, valueMask, attributes);
- XtRealizeWidget(LabelChild(w));
- XtRealizeWidget(ButtonChild(w));
- XMapSubwindows(XtDisplay(w), XtWindow(w));
- }
-
- static void Destroy(w)
- Widget w;
- {
- ConfirmWidget cw = (ConfirmWidget) w;
-
- XtFree((char *) cw->confirm.label);
- XtFree((char *) cw->confirm.button_label);
-
- XtDestroyWidget(LabelChild(w));
- XtDestroyWidget(ButtonChild(w));
- }
-
- static Boolean SetValues(old, req, new, args, num_args)
- Widget old, req, new;
- ArgList args;
- Cardinal *num_args;
- {
- register ConfirmWidget oldcw = (ConfirmWidget) old;
- register ConfirmWidget newcw = (ConfirmWidget) new;
- Arg arg[1];
- Boolean resize = FALSE;
-
- #define NE(field) (oldcw->field != newcw->field)
-
- /* We don't let these change */
- LabelChild(newcw) = LabelChild(oldcw);
- ButtonChild(newcw) = ButtonChild(oldcw);
-
- if (NE(confirm.label)) {
- XtFree((char *) oldcw->confirm.label);
- newcw->confirm.label = XtNewString(newcw->confirm.label);
- XtSetArg(arg[0], XtNlabel, newcw->confirm.label);
- XtSetValues(LabelChild(newcw), arg, 1);
- resize = TRUE;
- }
-
- if (NE(confirm.button_label)) {
- XtFree((char *) oldcw->confirm.button_label);
- newcw->confirm.button_label =
- XtNewString(newcw->confirm.button_label);
- XtSetArg(arg[0], XtNlabel, newcw->confirm.button_label);
- XtSetValues(ButtonChild(newcw), arg, 1);
- resize = TRUE;
- }
-
- if (NE(confirm.margin) || resize) {
- CalculateSize(newcw, &newcw->core.width, &newcw->core.height);
- }
-
- return FALSE;
- #undef NE
- }
-