749N/Astatic char Xrcsid[] =
"$XConsortium: Box.c,v 1.43 89/12/07 20:14:26 kit Exp $";
749N/A/*********************************************************** 749N/ACopyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts, 749N/Aand the Massachusetts Institute of Technology, Cambridge, Massachusetts. 749N/APermission to use, copy, modify, and distribute this software and its 749N/Adocumentation for any purpose and without fee is hereby granted, 749N/Aprovided that the above copyright notice appear in all copies and that 749N/Aboth that copyright notice and this permission notice appear in 749N/Asupporting documentation, and that the names of Digital or MIT not be 749N/Aused in advertising or publicity pertaining to distribution of the 749N/Asoftware without specific, written prior permission. 749N/ADIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 749N/AALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 749N/ADIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 749N/AANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 749N/AWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 749N/AARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 749N/A******************************************************************/ 749N/A/**************************************************************** 749N/A ****************************************************************/ 749N/A/**************************************************************** 749N/A * Full class record constant 749N/A ****************************************************************/ 749N/A /* class_name */ "Box",
749N/A/* composite_class fields */ 749N/A/**************************************************************** 749N/A ****************************************************************/ 749N/A * Do a layout, either actually assigning positions, or just calculating size. 749N/A * Returns minimum width and height that will preserve the same layout. 749N/A /* Box width and height */ 749N/A /* Line width and height */ 749N/A /* Compute widget width */ 749N/A /* At least one widget on this line, and 749N/A * can't fit any more. Start new line if vbox. 749N/A /* too narrow for this widget; we'll assume we can grow */ 749N/A /* It would be nice to use window gravity, but there isn't 749N/A * sufficient fine-grain control to nicely handle all 749N/A * situations (e.g. when only the height changes -- 749N/A * a common case). Explicit unmapping is a cheap hack 749N/A * to speed things up & avoid the visual jitter as 749N/A * %%% perhaps there should be a client resource to 749N/A * control this. If so, we'll have to optimize to 749N/A * perform the moves from the correct end so we don't 749N/A * force extra exposures as children occlude each other. 749N/A /* reduce width if too wide and height not filled */ 749N/A /* Finish off last line */ 749N/A * Calculate preferred size, given constraining box, caching it in the widget. 749N/A /* parent isn't going to change w or h, so nothing to re-compute */ 749N/A /* same query; current preferences are still valid */ 749N/A /* else gotta do it the long way... 749N/A I have a preference for tall and narrow, so if my width is 749N/A constrained, I'll accept it; otherwise, I'll compute the minimum 749N/A width that will fit me within the height constraint */ 749N/A else /* if (constraint->request_mode & CWHeight) */ {
749N/A /* let's see if I can become any narrower */ 749N/A /* height is currently ignored by DoLayout. 749N/A height = (constraint->request_mode & CWHeight) ? constraint->height 749N/A /* find minimum width for this height */ 749N/A /* punt; over-constrained */ 749N/A do {
/* find some width big enough to stay within this height */ 749N/A do {
/* find minimum width */ 749N/A * Actually layout the box 749N/A * Try to do a new layout within the current width and height; 749N/A * if that fails try to resize and do it within the box returne 749N/A * TryNewLayout just says if it's possible, and doesn't actually move the kids 749N/A /* at this point, preferred_width is guaranteed to not be greater 749N/A than bbw->core.width unless some child is larger, so there's no 749N/A point in re-computing another layout */ 749N/A /* let's see if our parent will go for a new size. */ 749N/A /* protect from malicious parents who change their minds */ 749N/A * Take it, and assume the parent knows what it is doing. 749N/A * The parent must accept this since it was returned in 749N/A /* recalc bounding box; height might change */ 749N/A else {
/* proposed_height != preferred_height */ 749N/A * 'reply' is unused; we say only yeay or nay, never almost. 749N/A /* Position request always denied */ 749N/A /* Size changes must see if the new size can be accomodated */ 749N/A /* Make all three fields in the request valid */ 749N/A /* Save current size and set to new size */ 749N/A /* Decide if new layout works: (1) new widget is smaller, 749N/A (2) new widget fits in existing Box, (3) Box can be 749N/A expanded to allow new widget to fit */ 749N/A/* whenever a child changes his geometry, we attempt to 749N/A * change ours to be the minimum enclosing size... 749N/A if (((request->width + request->border_width <= width + borderWidth) && 749N/A (request->height + request->border_width <= height + borderWidth)) 749N/A || bbw->box.preferred_width < bbw->core.width 749N/A || TryNewLayout(bbw)) { 749N/A /* Fits in existing or new space, relayout */ 749N/A /* Cannot satisfy request, change back to original geometry */ 749N/A };
/* if any size changes requested */ 749N/A /* Any stacking changes don't make a difference, so allow if that's all */ 749N/A /* Reconfigure the box */ 749N/A /* need to relayout if h_space or v_space change */