APPROVE COMMIT sjt-xft
Make the geometry manager in Falk's tabs widget more Xt-conforming.
Suppress some lingering currently uninteresting debug output.
I don't think behavior should change, but with Xt undefined behavior
is hard to predict.
Index: lwlib/ChangeLog
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/lwlib/ChangeLog,v
retrieving revision 1.64.2.5
diff -u -r1.64.2.5 ChangeLog
--- lwlib/ChangeLog	22 Feb 2005 13:03:20 -0000	1.64.2.5
+++ lwlib/ChangeLog	7 Mar 2005 01:57:42 -0000
@@ -0,0 +1,8 @@
+2005-03-07  Stephen J. Turnbull  <stephen(a)xemacs.org>
+
+	* lwlib-Xaw.c (debug_gauge): Fix and suppress gauge debug message.
+
+	* xlwtabs.c (TabsGeometryManager): Suppress "kludging" message, too.
+	(TabsGeometryManager): Make straight the paths of the layout, or
+	at least improve the approximation to Xt conventions by 50%.
+
Index: lwlib/lwlib-Xaw.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/lwlib/lwlib-Xaw.c,v
retrieving revision 1.11.2.1
diff -u -r1.11.2.1 lwlib-Xaw.c
--- lwlib/lwlib-Xaw.c	10 Dec 2004 06:43:25 -0000	1.11.2.1
+++ lwlib/lwlib-Xaw.c	7 Mar 2005 01:57:42 -0000
@@ -801,14 +801,14 @@
   return label;
 }
 
-static int debug_gauge = 1;
+static int debug_gauge = 0;
 
 static void
 lw_debug_print_xt_arglist (ArgList al, int ac)
 {
   int i;
   for (i = 0; i < ac; i++)
-    fprintf (stderr, "Widget has arg of type %s with value %lu.\n",
+    fprintf (stderr, "Widget has arg %s with value %lu.\n",
 	     al[i].name, (unsigned long) al[i].value);
 }
 
Index: lwlib/xlwtabs.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/lwlib/xlwtabs.c,v
retrieving revision 1.4.2.7
diff -u -r1.4.2.7 xlwtabs.c
--- lwlib/xlwtabs.c	22 Feb 2005 13:03:20 -0000	1.4.2.7
+++ lwlib/xlwtabs.c	7 Mar 2005 01:57:43 -0000
@@ -902,62 +902,72 @@
 	TabsWidget	 control = (TabsWidget) XtParent(tab);
 	Dimension	 s = SHADWID;
 	TabsConstraints	 constraint = (TabsConstraints) tab->core.constraints;
-	XtGeometryResult result;
+	XtGeometryResult result, best_offer = XtGeometryYes;
 	Dimension	 rw, rh;
 
 	static int debug_count = 0;
         static int debug_mask = 1;
 
-	/* Position request always denied
-	   #### This is the wrong way to do this.  If other parts of the
-	   request can be satisfied, should return XtGeometryAlmost. */
-
-	if (((request->request_mode & CWX) && request->x != tab->core.x)
||
-	    ((request->request_mode & CWY) && request->y != tab->core.y)
||
-	    !constraint->tabs.resizable)
+	/* Position request cannot be satisfied, so if tabs are not resizable,
+	   no request can be satisfied: return XGeometryNo. */
+	if (!constraint->tabs.resizable)
 	  return XtGeometryNo;
 
-	/* Make all three fields in the request valid */
-	if (!(request->request_mode & CWWidth))
-	  request->width = tab->core.width;
-	if (!(request->request_mode & CWHeight))
-	  request->height = tab->core.height;
-	if (!(request->request_mode & CWBorderWidth))
-	  request->border_width = tab->core.border_width;
+	/* Assume we will refuse these; toggle iff we accept them.
+	   Reply won't specify any fields not in the request. */
+	reply->request_mode = request->request_mode;
+	reply->x = tab->core.x;
+	reply->y = tab->core.y;
+
+	/* If a position request would result in a change, best offer is
+	   XtGeometryAlmost.  Otherwise toggle reply->request_mode. */
+	if ((request->request_mode & CWX) && request->x != tab->core.x)
+	  best_offer = XtGeometryAlmost;
+	else
+	  reply->request_mode &= ~CWX;
+	if ((request->request_mode & CWY) && request->y != tab->core.y)
+	  best_offer = XtGeometryAlmost;
+	else
+	  reply->request_mode &= ~CWY;
+
+	/* Make all three fields in the reply valid */
+	reply->width = (request->request_mode & CWWidth)
+		       ? request->width : tab->core.width;
+	reply->height = (request->request_mode & CWHeight)
+			? request->height : tab->core.height;
+	reply->border_width = (request->request_mode & CWBorderWidth)
+			      ? request->border_width : tab->core.border_width;
+
+	/* check if we can already offer a compromise */
+	if (best_offer == XtGeometryAlmost &&
+	    reply->width == tab->core.width &&
+	    reply->height == tab->core.height &&
+	    reply->border_width == tab->core.border_width)
+	  return best_offer;
 
 #ifndef DONT_DEBUG_REQUESTS
-#define DBG_REQUEST_PRINT(field,size)					\
+#define DBG_REQUEST_PRINT(name,field,size)				\
 do {									\
-  if (request->field > size)						\
+  if (reply->field > size)						\
     {									\
       if (++debug_count == debug_mask)					\
 	{								\
 	  debug_mask <<= 1;						\
-	  fprintf (stderr, "ridiculous request #%d: field %d > %d\n",	\
-		   debug_count, request->field, size);			\
+	  fprintf (stderr, "ridiculous %s request #%d: %d > %d\n",	\
+		   name, debug_count, reply->field, size);		\
 	}								\
-      request->field = tab->core.field;					\
+      reply->field = tab->core.field;					\
     }									\
 } while (0)
 
-	DBG_REQUEST_PRINT (width,1024);
-	DBG_REQUEST_PRINT (height,768);
-	DBG_REQUEST_PRINT (border_width,100);
+	DBG_REQUEST_PRINT ("width",width,1024);
+	DBG_REQUEST_PRINT ("height",height,768);
+	DBG_REQUEST_PRINT ("border_width",border_width,30);
 #undef DBG_REQUEST_PRINT
 #endif
 
-#if 0
-	/* #### this is NONSENSE, isn't it?
-	   AFAICT XtMakeGeometryRequest would already have returned
-	   XtGeometryYes in this case. */
-	if (request->width == tab->core.width &&
-	    request->height == tab->core.height &&
-	    request->border_width == tab->core.border_width)
-	  return XtGeometryNo;
-#endif
-
-	rw = request->width + 2 * request->border_width;
-	rh = request->height + 2 * request->border_width;
+	rw = reply->width + 2 * reply->border_width;
+	rh = reply->height + 2 * reply->border_width;
 
 	/* find out how big the children want to be now */
 	MaxChild (control, tab, rw, rh);
@@ -1004,7 +1014,7 @@
 
 	  /* Would my size change?  If so, ask to be resized. */
 
-	  if( wid != control->core.width || hgt != control->core.height )
+	  if (wid != control->core.width || hgt != control->core.height)
 	  {
 	    Dimension oldWid = control->core.width,
 		      oldHgt = control->core.height;
@@ -1019,8 +1029,8 @@
 	     * offer the child a compromise, then make this a query only.
 	     */
 
-	    if( (request->request_mode & XtCWQueryOnly)  || rw < cw || rh < ch )
-	      myrequest.request_mode |= XtCWQueryOnly ;
+	    if ((request->request_mode & XtCWQueryOnly) || rw < cw || rh < ch)
+	      myrequest.request_mode |= XtCWQueryOnly;
 
 	    result = XtMakeGeometryRequest ((Widget) control,
 					    &myrequest, &myreply);
@@ -1040,7 +1050,7 @@
 	     * resulting Tabs widget size would be.
 	     */
 
-	    switch( result ) {
+	    switch (result) {
 	      case XtGeometryYes:
 	      case XtGeometryDone:
 		control->tabs.needs_layout = True;
@@ -1074,9 +1084,10 @@
 		 get triggered forever after */
 	      int n = control->composite.num_children;
 	      ah = control->tabs.tab_height;
-	      fprintf (stderr, "Kludging around %d != 1 rows, #children = %d,"
-		       " total height %d, using %d.\n",
-		       check_nrows, n, th, ah);
+	      if (debug_tabs > 0)
+		fprintf (stderr, "Kludging around %d != 1 rows,"
+			 " #children = %d, total height %d, using %d.\n",
+			 check_nrows, n, th, ah);
 	    }
 
 	  /* OK, make our decision.  If requested size is >= max sibling
@@ -1084,19 +1095,22 @@
 	   * we accept.  Otherwise, we offer a compromise.
 	   */
 
-	  if( rw == aw && rh == ah )
+	  if (rw == aw && rh == ah)
 	  {
 	    /* Acceptable.  If this wasn't a query, change *all* children
 	     * to this size.
 	     */
-	    if( request->request_mode & XtCWQueryOnly )
-	      return XtGeometryYes ;
+	    if (request->request_mode & XtCWQueryOnly)
+	      {
+		control->tabs.needs_layout = False;
+		return XtGeometryYes ;
+	      }
 	    else
 	    {
 	      Widget	*childP = control->composite.children;
-	      int	i,bw;
+	      int	i, bw;
 	      tab->core.border_width = request->border_width;
-	      for(i = TabsNumChildren (control); --i >= 0; ++childP)
+	      for (i = TabsNumChildren (control); --i >= 0; ++childP)
 		if (TabVisible (*childP))
 		{
 		  bw = (*childP)->core.border_width;
@@ -1119,8 +1133,7 @@
 	   */
 	  reply->width  = aw - 2 * request->border_width ;
 	  reply->height = ah - 2 * request->border_width ;
-	  reply->border_width = request->border_width ;
-	  reply->request_mode = CWWidth | CWHeight | CWBorderWidth ;
+	  control->tabs.needs_layout = False;
 	  return XtGeometryAlmost ;
 	}
 
@@ -2129,8 +2142,8 @@
 
 
 
-	/* Find max preferred child size.  Returned sizes include child
-	 * border widths.  If except is non-null, don't ask that one.
+	/* Find max preferred child size and store in control widget.
+	 * If except is non-null, don't ask that one.
 	 */
 
 static	void
-- 
Institute of Policy and Planning Sciences     
http://turnbull.sk.tsukuba.ac.jp
University of Tsukuba                    Tennodai 1-1-1 Tsukuba 305-8573 JAPAN
               Ask not how you can "do" free software business;
              ask what your business can "do for" free software.