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 "BoxP.h" /* Box private header file */
- #include "LabelGadge.h" /* To check LabelGadgets */
-
- #define Offset(field) XtOffsetOf(BoxRec, box.field)
-
- static XtResource resources[] = {
- {XtNmargin, XtCMargin, XtRDimension, sizeof(Dimension),
- Offset(margin), XtRImmediate, (XtPointer) 10},
- };
-
- #undef Offset
-
- /* Forward declarations */
-
- static void ChangeManaged(), Initialize(), InsertChild(),
- DeleteChild(), Redisplay();
- static XtGeometryResult GeometryManager();
- static Boolean SetValues(), AcceptFocus();
-
- static CompositeClassExtensionRec compositeExtension = {
- /* next_extension */ NULL,
- /* record_type */ NULLQUARK,
- /* version */ XtCompositeExtensionVersion,
- /* record_size */ sizeof(CompositeClassExtensionRec),
- /* accepts_objects */ TRUE
- };
-
- BoxClassRec boxClassRec = {
- /* Core class part */
- {
- /* superclass */ (WidgetClass) &compositeClassRec,
- /* class_name */ "Box",
- /* widget_size */ sizeof(BoxRec),
- /* class_initialize */ NULL,
- /* class_part_initialize */ 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 */ XtExposeCompressMultiple,
- /* compress_enterleave */ TRUE,
- /* visible_interest */ FALSE,
- /* destroy */ NULL,
- /* resize */ NULL,
- /* expose */ Redisplay,
- /* set_values */ SetValues,
- /* set_values_hook */ NULL,
- /* set_values_almost */ XtInheritSetValuesAlmost,
- /* get_values_hook */ NULL,
- /* accept_focus */ AcceptFocus,
- /* version */ XtVersion,
- /* callback offsets */ NULL,
- /* tm_table */ NULL,
- /* query_geometry */ XtInheritQueryGeometry,
- /* display_accelerator */ NULL,
- /* extension */ NULL,
- },
- /* Composite class part */
- {
- /* geometry_manager */ GeometryManager,
- /* change_managed */ ChangeManaged,
- /* insert_child */ InsertChild,
- /* delete_child */ DeleteChild,
- /* extension */ (XtPointer) &compositeExtension,
- },
- /* Box class part */
- {
- /* extension */ NULL,
- }
- };
-
- WidgetClass boxWidgetClass = (WidgetClass) &boxClassRec;
-
- static void DeleteChild(w)
- Widget w;
- {
- BoxWidget box = (BoxWidget) XtParent(w);
-
- if (box->box.last_focus == w) box->box.last_focus = NULL;
-
- (*((CompositeWidgetClass)(boxWidgetClass->core_class.superclass))->
- composite_class.delete_child) (w);
- }
-
- static void InsertChild(w)
- Widget w;
- {
- String params[2];
- Cardinal num_params;
- Widget parent = XtParent(w);
-
- if (!XtIsWidget(w) && !XtIsSubclass(w, labelGadgetClass)) {
- params[0] = XtClass(w)->core_class.class_name;
- params[1] = XtClass(parent)->core_class.class_name;
- num_params = 2;
- XtAppErrorMsg(XtWidgetToApplicationContext(w),
- "childError", "class", "WidgetError",
- "Children of class %s cannot be added to %n widgets",
- params, &num_params);
- }
-
- (*((CompositeWidgetClass)(boxWidgetClass->core_class.superclass))->
- composite_class.insert_child) (w);
- }
-
- static void Initialize(req, new, args, num_args)
- Widget req, new;
- ArgList args;
- Cardinal *num_args;
- {
- ((BoxWidget) new)->box.last_focus = NULL;
- }
-
- static void CalculateNewSize(box, width, height)
- BoxWidget box;
- register Dimension *width, *height;
- {
- register Widget child;
- register int i;
- int right, bottom;
-
- *width = *height = 0;
-
- for (i = 0; i < box->composite.num_children; i++) {
- child = box->composite.children[i];
- if (!XtIsManaged(child)) continue;
- right = child->core.x + child->core.width +
- 2 * child->core.border_width;
- bottom = child->core.y + child->core.height +
- 2 * child->core.border_width;
- if (right > (int) *width) *width = right;
- if (bottom > (int) *height) *height = bottom;
- }
-
- *width += box->box.margin;
- *height += box->box.margin;
-
- if (*width == 0) *width = 1;
- if (*height == 0) *height = 1;
- }
-
- static void ChangeManaged(w)
- Widget w;
- {
- BoxWidget box = (BoxWidget) w;
- XtWidgetGeometry request;
- XtGeometryResult result;
-
- CalculateNewSize(box, &request.width, &request.height);
-
- if (request.width != box->core.width ||
- request.height != box->core.height) {
- request.request_mode = CWWidth | CWHeight;
- do {
- result = XtMakeGeometryRequest(w, &request, &request);
- } while (result == XtGeometryAlmost);
- }
- }
-
- static XtGeometryResult GeometryManager(w, desired, allowed)
- Widget w;
- XtWidgetGeometry *desired, *allowed;
- {
- BoxWidget box = (BoxWidget) XtParent(w);
- XtWidgetGeometry request;
- XtGeometryResult result;
-
- #define Wants(flag) (desired->request_mode & flag)
-
- if (Wants(XtCWQueryOnly)) return XtGeometryYes;
-
- if (Wants(CWWidth)) w->core.width = desired->width;
- if (Wants(CWHeight)) w->core.height = desired->height;
- if (Wants(CWX)) w->core.x = desired->x;
- if (Wants(CWY)) w->core.y = desired->y;
- if (Wants(CWBorderWidth)) {
- w->core.border_width = desired->border_width;
- }
-
- CalculateNewSize(box, &request.width, &request.height);
-
- if (request.width != box->core.width ||
- request.height != box->core.height) {
- request.request_mode = CWWidth | CWHeight;
- do {
- result = XtMakeGeometryRequest((Widget) box,
- &request, &request);
- } while (result == XtGeometryAlmost);
- }
-
- return XtGeometryYes;
-
- #undef Wants
- }
-
- static Boolean SetValues(old, req, new, args, num_args)
- Widget old, req, new;
- ArgList args;
- Cardinal *num_args;
- {
- register BoxWidget oldbox = (BoxWidget) old;
- register BoxWidget newbox = (BoxWidget) new;
-
- if (newbox->box.margin != oldbox->box.margin ||
- newbox->core.width == 0 || newbox->core.height == 0) {
- CalculateNewSize(newbox, &newbox->core.width,
- &newbox->core.height);
- }
-
- return FALSE;
- }
-
- static Boolean AcceptFocus(w, time)
- Widget w;
- Time *time;
- {
- BoxWidget box = (BoxWidget) w;
- register int i;
-
- if (box->box.last_focus != NULL &&
- XtIsManaged(box->box.last_focus)) {
- if (XtCallAcceptFocus(box->box.last_focus, time)) {
- return TRUE;
- }
- }
-
- for (i = 0; i < box->composite.num_children; i++) {
- if (!XtIsManaged(box->composite.children[i])) continue;
- if (XtCallAcceptFocus(box->composite.children[i], time)) {
- box->box.last_focus = box->composite.children[i];
- return TRUE;
- }
- }
-
- box->box.last_focus = NULL;
- return FALSE;
- }
- static void Redisplay(w, event, region)
- Widget w;
- XEvent *event;
- Region region;
- {
- CompositeWidget comp = (CompositeWidget) w;
- int i;
- Widget c; /* child */
-
- for (i = 0; i < comp->composite.num_children; i++) {
- c = comp->composite.children[i];
- if (XtIsManaged(c) && XtIsSubclass(c, labelGadgetClass) &&
- XRectInRegion(region, c->core.x, c->core.y,
- c->core.width + 2*c->core.border_width,
- c->core.height + 2*c->core.border_width)
- != RectangleOut) {
- (*(XtClass(c)->core_class.expose))(c, event, region);
- }
- }
- }
-