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.
- */
-
-
- /*
- * toggle.c - Toggle widget
- *
- */
-
-
- #include <stdio.h>
- #include <X11/Xos.h>
- #include <ctype.h>
- #include <X11/StringDefs.h>
- #include <X11/IntrinsicP.h>
- #include <X11/XawMisc.h>
- #include "toggleP.h"
-
- /* Private Data */
-
- extern void Initialize();
- extern Boolean SetValues();
- extern void Toggle();
- extern void Unhighlight();
- extern void Highlight();
- extern void Notify();
- extern void ClassInitialize();
-
-
- static char toggleTranslations[] =
- "<Btn1Up>: toggle() notify()\n\
- <EnterWindow>: highlight() \n\
- <LeaveWindow>: unhighlight()";
-
-
- #define offset(field) XtOffset(ToggleWidget, field)
- static Dimension defwidth = 0;
- static XtState defState = XtToggleOff;
-
- static XtResource resources[] = {
- {XtNcursor, XtCCursor, XtRCursor, sizeof(Cursor),
- offset(simple.cursor), XtRString, "hand2"},
- {XtNborderWidth, XtCBorderWidth, XtRDimension, sizeof(Dimension),
- offset(core.border_width), XtRDimension, (caddr_t)&defwidth},
- {XtNstate, XtCState, XtRState, sizeof(XtState),
- offset(toggle.state), XtRState, (caddr_t)&defState},
- };
- #undef offset
-
- static XtActionsRec toggleactionsList[] =
- {
- {"toggle", Toggle},
- {"notify", Notify},
- {"highlight", Highlight},
- {"unhighlight", Unhighlight},
- };
-
- /* ...ClassData must be initialized at compile time. Must
- initialize all substructures. (Actually, last two here
- need not be initialized since not used.)
- */
- ToggleClassRec toggleClassRec = {
- {
- (WidgetClass) &commandClassRec, /* superclass */
- "Toggle", /* class_name */
- sizeof(ToggleRec), /* size */
- ClassInitialize, /* class_initialize */
- NULL, /* class_part_initialize */
- FALSE, /* class_inited */
- Initialize, /* initialize */
- NULL, /* initialize_hook */
- XtInheritRealize, /* realize */
- toggleactionsList, /* actions */
- XtNumber(toggleactionsList), /* num_actions */
- resources, /* resources */
- XtNumber(resources), /* resource_count */
- NULLQUARK, /* xrm_class */
- FALSE, /* compress_motion */
- TRUE, /* compress_exposure */
- TRUE, /* compress_enterleave */
- FALSE, /* visible_interest */
- NULL, /* destroy */
- XtInheritResize, /* resize */
- XtInheritExpose, /* expose */
- SetValues, /* set_values */
- NULL, /* set_values_hook */
- XtInheritSetValuesAlmost, /* set_values_almost */
- NULL, /* get_values_hook */
- NULL, /* accept_focus */
- XtVersion, /* version */
- NULL, /* callback_private */
- toggleTranslations, /* tm_table */
- NULL, /* query_geometry */
- XtInheritDisplayAccelerator, /* display_accelerator */
- NULL, /* extension */
- }, /* CoreClass fields initialization */
- {
- 0, /* field not used */
- }, /* LabelClass fields initialization */
- {
- 0, /* field not used */
- }, /* CommandClass fields initialization */
- {
- 0, /* field not used */
- }, /* ToggleClass fields initialization */
- };
-
- /* for public consumption */
- WidgetClass toggleWidgetClass = (WidgetClass) &toggleClassRec;
-
- /****************************************************************
- *
- * Private Procedures
- *
- ****************************************************************/
-
- static void CvtStringToState();
-
- static XrmQuark XrmQEtoggleon;
- static XrmQuark XrmQEtoggleoff;
-
- static void ClassInitialize()
- {
-
- XrmQEtoggleon = XrmStringToQuark("toggleon");
- XrmQEtoggleoff = XrmStringToQuark("toggleoff");
-
- XtAddConverter( XtRString, XtRState, CvtStringToState, NULL, 0 );
- } /* ClassInitialize */
-
- /* ARGSUSED */
- static void CvtStringToState(args, num_args, fromVal, toVal)
- XrmValuePtr *args; /* unused */
- Cardinal *num_args; /* unused */
- XrmValuePtr fromVal;
- XrmValuePtr toVal;
- {
- static XtState e;
- XrmQuark q;
- char *s = (char *) fromVal->addr;
- char lowerName[1000];
- int i;
-
- if (s == NULL) return;
-
- for (i=0; i<=strlen(s); i++) {
- char c = s[i];
- lowerName[i] = isupper(c) ? (char) tolower(c) : c;
- }
-
- q = XrmStringToQuark(lowerName);
-
- toVal->size = sizeof(XtState);
- toVal->addr = (caddr_t) &e;
-
- if (q == XrmQEtoggleon) { e = XtToggleOn; return; }
- if (q == XrmQEtoggleoff) { e = XtToggleOff; return; }
-
- toVal->size = 0;
- toVal->addr = NULL;
- };
-
- /* ARGSUSED */
- static void Initialize(request, new)
- Widget request, new;
- {
- ToggleWidget tw = (ToggleWidget)new;
-
- tw->command.set = (int)tw->toggle.state;
- if (tw->toggle.state == XtToggleOn)
- tw->label.normal_GC = tw->command.inverse_GC;
- }
-
- static Region HighlightRegion(cbw)
- ToggleWidget cbw;
- {
- static Region outerRegion = NULL, innerRegion, emptyRegion;
- XRectangle rect;
-
- if (outerRegion == NULL) {
- /* save time by allocating scratch regions only once. */
- outerRegion = XCreateRegion();
- innerRegion = XCreateRegion();
- emptyRegion = XCreateRegion();
- }
-
- rect.x = rect.y = 0;
- rect.width = cbw->core.width;
- rect.height = cbw->core.height;
- XUnionRectWithRegion( &rect, emptyRegion, outerRegion );
- rect.x = rect.y = cbw->command.highlight_thickness;
- rect.width -= cbw->command.highlight_thickness * 2;
- rect.height -= cbw->command.highlight_thickness * 2;
- XUnionRectWithRegion( &rect, emptyRegion, innerRegion );
- XSubtractRegion( outerRegion, innerRegion, outerRegion );
- return outerRegion;
- }
- /***************************
- *
- * Action Procedures
- *
- ***************************/
-
- /* ARGSUSED */
- static void Toggle(w,event,params,num_params)
- Widget w;
- XEvent *event;
- String *params; /* unused */
- Cardinal *num_params; /* unused */
- {
- ToggleWidget tw = (ToggleWidget)w;
-
- if (tw->toggle.state == XtToggleOn) {
- tw->toggle.state = XtToggleOff;
- tw->command.set = FALSE;
- tw->label.normal_GC = tw->command.normal_GC;
- tw->command.highlighted = TRUE;
- }
- else {
- tw->toggle.state = XtToggleOn;
- tw->command.set = TRUE;
- tw->label.normal_GC = tw->command.inverse_GC;
- }
- XClearArea(XtDisplay(w), XtWindow(w), 0, 0, 0, 0, TRUE);
- /* (tw->core.widget_class->core_class.expose)(w, event, NULL);*/
- }
-
- /* ARGSUSED */
- static void Notify(w,event,params,num_params)
- Widget w;
- XEvent *event;
- String *params; /* unused */
- Cardinal *num_params; /* unused */
- {
- ToggleWidget tw = (ToggleWidget)w;
- if (tw->command.callbacks != NULL)
- XtCallCallbacks(w, XtNcallback, tw->toggle.state);
- (tw->core.widget_class->core_class.expose)(w, event, NULL);
- }
-
- /* ARGSUSED */
- static void Highlight(w,event,params,num_params)
- Widget w;
- XEvent *event;
- String *params; /* unused */
- Cardinal *num_params; /* unused */
- {
- ToggleWidget tw = (ToggleWidget)w;
-
- if (tw->command.set == FALSE) {
- tw->command.highlighted = TRUE;
- (tw->core.widget_class->core_class.expose)(w, event,
- HighlightRegion(tw));
- }
- }
-
- /* ARGSUSED */
- static void Unhighlight(w,event,params,num_params)
- Widget w;
- XEvent *event;
- String *params; /* unused */
- Cardinal *num_params; /* unused */
- {
- ToggleWidget tw = (ToggleWidget)w;
-
- tw->command.highlighted = FALSE;
- if (tw->command.set == FALSE) {
- (tw->core.widget_class->core_class.expose)(w, event,
- HighlightRegion(tw));
- }
- }
-
-
- /*
- * Set specified arguments into widget
- */
- /* ARGSUSED */
- static Boolean SetValues (current, request, new)
- Widget current, request, new;
- {
- ToggleWidget tw = (ToggleWidget)current;
- ToggleWidget tnew = (ToggleWidget)new;
-
- if (tnew->toggle.state != tw->toggle.state) {
- /* the resource XtNstate is modified */
- tnew->command.set = !(tw->command.set);
- }
- else if (tnew->core.sensitive != tw->core.sensitive
- && tnew->core.sensitive) {
- /* the resource XtNsensitive is modified */
- tnew->command.set = (Boolean)tw->toggle.state;
- }
- else return FALSE;
-
- if (tnew->toggle.state == XtToggleOn)
- tnew->label.normal_GC = tnew->command.inverse_GC;
- else
- tnew->label.normal_GC = tnew->command.normal_GC;
-
- return TRUE;
- }
-