XEmacs 21.2.24 "Hecate".
[chise/xemacs-chise.git-] / lwlib / xlwtabs.c
index 99918c7..fa10a60 100644 (file)
@@ -18,7 +18,7 @@
  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  Boston, MA 02111-1307, USA.  */
  
- /* Synched up with: Tabs.c 1.23 */
+ /* Synched up with: Tabs.c 1.25 */
  
  /*
  * Tabs.c - Index Tabs composite widget
@@ -568,7 +568,11 @@ TabsResize(Widget w)
                          cw-bw*2,ch-bw*2, bw) ;
            }
          if( XtIsRealized(w) )
-           XClearWindow(XtDisplay((Widget)tw), XtWindow((Widget)tw)) ;
+           {
+             XClearWindow(XtDisplay((Widget)tw), XtWindow((Widget)tw)) ;
+             tw->tabs.needs_layout = False ;
+             XtClass(tw)->core_class.expose((Widget)tw,NULL,None) ;
+           }
        }
 
        tw->tabs.needs_layout = False ;
@@ -598,75 +602,76 @@ static    Boolean
 TabsSetValues(Widget current, Widget request, Widget new,
        ArgList args, Cardinal *num_args)
 {
-  TabsWidget curtw = (TabsWidget) current ;
-  TabsWidget tw = (TabsWidget) new ;
-  Boolean      needRedraw = False ;
-  Widget       *childP ;
-  int  i ;
+       TabsWidget curtw = (TabsWidget) current ;
+       TabsWidget tw = (TabsWidget) new ;
+       Boolean needRedraw = False ;
+       Widget  *childP ;
+       int     i ;
 
 
-  if( tw->tabs.font != curtw->tabs.font  ||
-      tw->tabs.internalWidth != curtw->tabs.internalWidth ||
-      tw->tabs.internalHeight != curtw->tabs.internalHeight )
-    {
-      tw->tabs.tab_height = 2 * tw->tabs.internalHeight + SHADWID ;
-
-      if( tw->tabs.font != NULL )
-       tw->tabs.tab_height += tw->tabs.font->max_bounds.ascent +
-         tw->tabs.font->max_bounds.descent ;
-
-      /* Tab size has changed.  Resize all tabs and request a new size */
-      for(i=0, childP=tw->composite.children;
-         i < tw->composite.num_children;
-         ++i, ++childP)
-       if( XtIsManaged(*childP) )
-         TabWidth(*childP) ;
-      PreferredSize(tw, &tw->core.width, &tw->core.height, NULL,NULL) ;
-      needRedraw = True ;
-      tw->tabs.needs_layout = True ;
-    }
+       if( tw->tabs.font != curtw->tabs.font  ||
+           tw->tabs.internalWidth != curtw->tabs.internalWidth ||
+           tw->tabs.internalHeight != curtw->tabs.internalHeight )
+       {
+         tw->tabs.tab_height = 2 * tw->tabs.internalHeight + SHADWID ;
 
-  /* TODO: if any color changes, need to recompute GCs and redraw */
+         if( tw->tabs.font != NULL )
+           tw->tabs.tab_height += tw->tabs.font->max_bounds.ascent +
+                                  tw->tabs.font->max_bounds.descent ;
 
-  if( tw->core.background_pixel != curtw->core.background_pixel ||
-      tw->core.background_pixmap != curtw->core.background_pixmap )
-    if( XtIsRealized(new) )
-      {
-       TabsFreeGCs(tw) ;
-       TabsAllocGCs(tw) ;
-       needRedraw = True ;
-      }
+         /* Tab size has changed.  Resize all tabs and request a new size */
+         for(i=0, childP=tw->composite.children;
+               i < tw->composite.num_children;
+               ++i, ++childP)
+           if( XtIsManaged(*childP) )
+             TabWidth(*childP) ;
+         PreferredSize(tw, &tw->core.width, &tw->core.height, NULL,NULL) ;
+         needRedraw = True ;
+         tw->tabs.needs_layout = True ;
+       }
 
-  if( tw->core.sensitive != curtw->core.sensitive )
-    needRedraw = True ;
+       /* TODO: if any color changes, need to recompute GCs and redraw */
 
-  /* If top widget changes, need to change stacking order, redraw tabs.
-   * Window system will handle the redraws.
-   */
+       if( tw->core.background_pixel != curtw->core.background_pixel ||
+           tw->core.background_pixmap != curtw->core.background_pixmap ||
+           tw->tabs.font != curtw->tabs.font )
+         if( XtIsRealized(new) )
+         {
+           TabsFreeGCs(tw) ;
+           TabsAllocGCs(tw) ;
+           needRedraw = True ;
+         }
 
-  if( tw->tabs.topWidget != curtw->tabs.topWidget )
-    {
-      if( XtIsRealized(tw->tabs.topWidget) )
+       if( tw->core.sensitive != curtw->core.sensitive )
+         needRedraw = True ;
+
+       /* If top widget changes, need to change stacking order, redraw tabs.
+        * Window system will handle the redraws.
+        */
+
+       if( tw->tabs.topWidget != curtw->tabs.topWidget ) 
        {
-         Widget                w = tw->tabs.topWidget ;
-         TabsConstraints       tab = (TabsConstraints) w->core.constraints ;
+         if( XtIsRealized(tw->tabs.topWidget) )
+         {
+           Widget              w = tw->tabs.topWidget ;
+           TabsConstraints     tab = (TabsConstraints) w->core.constraints ;
 
-         XRaiseWindow(XtDisplay(w), XtWindow(w)) ;
+           XRaiseWindow(XtDisplay(w), XtWindow(w)) ;
 #ifdef NEED_MOTIF
-         XtVaSetValues(curtw->tabs.topWidget, XmNtraversalOn, False, 0) ;
-         XtVaSetValues(w, XmNtraversalOn, True, 0) ;
+           XtVaSetValues(curtw->tabs.topWidget, XmNtraversalOn, False, 0) ;
+           XtVaSetValues(w, XmNtraversalOn, True, 0) ;
 #endif
 
-         if( tab->tabs.row != tw->tabs.numRows-1 )
-           TabsShuffleRows(tw) ;
+           if( tab->tabs.row != tw->tabs.numRows-1 )
+             TabsShuffleRows(tw) ;
 
-         needRedraw = True ;
+           needRedraw = True ;
+         }
+         else
+           tw->tabs.needs_layout = True ;
        }
-      else
-       tw->tabs.needs_layout = True ;
-    }
 
-  return needRedraw ;
+       return needRedraw ;
 }
 
 
@@ -820,15 +825,16 @@ TabsGeometryManager(Widget w, XtWidgetGeometry *req, XtWidgetGeometry *reply)
          Dimension     th ;            /* space used by tabs */
          Dimension     wid,hgt ;       /* Tabs widget size */
 
-         rw = tab->tabs.wid ;
-         rh = tab->tabs.hgt ;
+         rw = cw = tab->tabs.wid ;
+         rh = ch = tab->tabs.hgt ;
 
          /* find out what the resulting preferred size would be */
 
 #ifdef COMMENT
          MaxChild(tw, &cw, &ch) ;
 #endif /* COMMENT */
-         PreferredSize2(tw, tw->tabs.max_cw,tw->tabs.max_ch, &wid, &hgt) ;
+         PreferredSize2(tw,
+               cw=tw->tabs.max_cw, ch=tw->tabs.max_ch, &wid, &hgt) ;
 
          /* Ask to be resized to accommodate. */
 
@@ -1059,7 +1065,7 @@ static    void
 TabsPage(Widget w, XEvent *event, String *params, Cardinal *num_params)
 {
        TabsWidget      tw = (TabsWidget) w ;
-       Widget          newtop ;
+       Widget          newtop = NULL;
        Widget          *childP ;
        int             idx ;
        int             nc = tw->composite.num_children ;
@@ -1083,9 +1089,9 @@ TabsPage(Widget w, XEvent *event, String *params, Cardinal *num_params)
        switch( params[0][0] ) {
          case 'u':             /* up */
          case 'U':
-           if( idx == 0 )
-             idx = nc ;
-           newtop = tw->composite.children[idx-1] ;
+           if( --idx < 0 )
+             idx = nc-1 ;
+           newtop = tw->composite.children[idx] ;
            break ;
 
          case 'd':             /* down */
@@ -1097,6 +1103,7 @@ TabsPage(Widget w, XEvent *event, String *params, Cardinal *num_params)
 
          case 'h':
          case 'H':
+         default:
              newtop = tw->composite.children[0] ;
              break ;
 
@@ -1122,7 +1129,7 @@ static    void
 TabsHighlight(Widget w, XEvent *event, String *params, Cardinal *num_params)
 {
        TabsWidget      tw = (TabsWidget) w ;
-       Widget          newhl ;
+       Widget          newhl = NULL;
        Widget          *childP ;
        int             idx ;
        int             nc = tw->composite.num_children ;
@@ -1142,6 +1149,7 @@ TabsHighlight(Widget w, XEvent *event, String *params, Cardinal *num_params)
 
        else
        {
+         /* find index of currently highlit child */
          for(idx=0, childP=tw->composite.children; idx < nc; ++idx, ++childP )
            if( tw->tabs.hilight == *childP )
              break ;
@@ -1149,9 +1157,9 @@ TabsHighlight(Widget w, XEvent *event, String *params, Cardinal *num_params)
          switch( params[0][0] ) {
            case 'u':           /* up */
            case 'U':
-             if( idx == 0 )
-               idx = nc ;
-             newhl = tw->composite.children[idx-1] ;
+             if( --idx < 0 )
+               idx = nc-1 ;
+             newhl = tw->composite.children[idx] ;
              break ;
 
            case 'd':           /* down */
@@ -1170,6 +1178,10 @@ TabsHighlight(Widget w, XEvent *event, String *params, Cardinal *num_params)
            case 'E':
                newhl = tw->composite.children[nc-1] ;
                break ;
+
+           default:
+               newhl = tw->tabs.hilight ;
+               break ;
          }
        }