Xaw3_1Box.c revision 749
static char Xrcsid[] =
"$XConsortium: Box.c,v 1.43 89/12/07 20:14:26 kit Exp $";
/*********************************************************** Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts, and the Massachusetts Institute of Technology, Cambridge, Massachusetts. Permission to use, copy, modify, and distribute this software and its documentation 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 names of Digital or MIT not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. DIGITAL DISCLAIMS 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 ******************************************************************/ * Box.c - Box composite widget /**************************************************************** ****************************************************************/ /**************************************************************** * Full class record constant ****************************************************************/ /* widget_size */ sizeof(
BoxRec),
/* class_part_init */ NULL,
/* class_inited */ FALSE,
/* initialize_hook */ NULL,
/* compress_motion */ TRUE,
/* compress_exposure */ TRUE,
/* compress_enterleave*/ TRUE,
/* visible_interest */ FALSE,
/* set_values_hook */ NULL,
/* get_values_hook */ NULL,
/* callback_private */ NULL,
/* composite_class fields */ /**************************************************************** ****************************************************************/ * Do a layout, either actually assigning positions, or just calculating size. * Returns minimum width and height that will preserve the same layout. Dimension w, h;
/* Width and height needed for box */ Dimension bw,
bh;
/* Width and height needed for current widget */ /* Box width and height */ /* Line width and height */ /* Compute widget width */ /* At least one widget on this line, and * can't fit any more. Start new line if vbox. /* too narrow for this widget; we'll assume we can grow */ /* It would be nice to use window gravity, but there isn't * sufficient fine-grain control to nicely handle all * situations (e.g. when only the height changes -- * a common case). Explicit unmapping is a cheap hack * to speed things up & avoid the visual jitter as * %%% perhaps there should be a client resource to * control this. If so, we'll have to optimize to * perform the moves from the correct end so we don't * force extra exposures as children occlude each other. /* reduce width if too wide and height not filled */ /* Finish off last line */ * Calculate preferred size, given constraining box, caching it in the widget. /* parent isn't going to change w or h, so nothing to re-compute */ /* same query; current preferences are still valid */ /* else gotta do it the long way... I have a preference for tall and narrow, so if my width is constrained, I'll accept it; otherwise, I'll compute the minimum width that will fit me within the height constraint */ else /* if (constraint->request_mode & CWHeight) */ {
/* let's see if I can become any narrower */ /* height is currently ignored by DoLayout. height = (constraint->request_mode & CWHeight) ? constraint->height /* find minimum width for this height */ /* punt; over-constrained */ do {
/* find some width big enough to stay within this height */ do {
/* find minimum width */ * Actually layout the box * Try to do a new layout within the current width and height; * if that fails try to resize and do it within the box returne * TryNewLayout just says if it's possible, and doesn't actually move the kids /* at this point, preferred_width is guaranteed to not be greater than bbw->core.width unless some child is larger, so there's no point in re-computing another layout */ /* let's see if our parent will go for a new size. */ /* protect from malicious parents who change their minds */ * Take it, and assume the parent knows what it is doing. * The parent must accept this since it was returned in /* recalc bounding box; height might change */ else {
/* proposed_height != preferred_height */ * 'reply' is unused; we say only yeay or nay, never almost. /* Position request always denied */ /* Size changes must see if the new size can be accomodated */ /* Make all three fields in the request valid */ /* Save current size and set to new size */ /* Decide if new layout works: (1) new widget is smaller, (2) new widget fits in existing Box, (3) Box can be expanded to allow new widget to fit */ /* whenever a child changes his geometry, we attempt to * change ours to be the minimum enclosing size... if (((request->width + request->border_width <= width + borderWidth) && (request->height + request->border_width <= height + borderWidth)) || bbw->box.preferred_width < bbw->core.width || bbw->box.preferred_height < bbw->core.height /* Fits in existing or new space, relayout */ /* Cannot satisfy request, change back to original geometry */ };
/* if any size changes requested */ /* Any stacking changes don't make a difference, so allow if that's all */ /* Reconfigure the box */ /* need to relayout if h_space or v_space change */