X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=lwlib%2Fxlwtabs.c;h=65af1eee796049b7683574b094c9c481860d8ef7;hb=d594935706b4234d8c0a268916669dd7f7f8389b;hp=5ef2acb467b44a58a94719367ebc74396bd9425a;hpb=41e784bb39d67f3906871511cb30805a71a6d6b3;p=chise%2Fxemacs-chise.git- diff --git a/lwlib/xlwtabs.c b/lwlib/xlwtabs.c index 5ef2acb..65af1ee 100644 --- a/lwlib/xlwtabs.c +++ b/lwlib/xlwtabs.c @@ -1,25 +1,30 @@ /* Tabs Widget for XEmacs. Copyright (C) 1999 Edward A. Falk - + This file is part of XEmacs. - + XEmacs is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + XEmacs is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with XEmacs; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - - /* Synched up with: Tabs.c 1.27 */ - + + /* Synched up with: Tabs.c 1.27. + + #### This file contains essential XEmacs related fixes to the original + verison of the Tabs widget. Be VERY careful about syncing if you ever + update to a more recent version. In general this is probably now a + bad idea. */ + /* * Tabs.c - Index Tabs composite widget * @@ -122,7 +127,7 @@ static char accelTable[] = " #augment\n\ KP_Down: highlight(down) \n\ : page(select) \n\ " ; -static XtAccelerators defaultAccelerators ; +static XtAccelerators defaultAccelerators ; /* #### Never used */ #define offset(field) XtOffsetOf(TabsRec, tabs.field) static XtResource resources[] = { @@ -401,7 +406,10 @@ WidgetClass tabsWidgetClass = (WidgetClass)&tabsClassRec; #define assert(e) #endif - +#define TabsNumChildren(tw) (((TabsWidget)tw)->composite.num_children) +#define TabVisible(tab) \ + (XtIsManaged(tab) && \ + ((TabsConstraints)((tab)->core.constraints))->tabs.visible) /**************************************************************** @@ -430,7 +438,7 @@ TabsInit(Widget request, Widget new, ArgList args, Cardinal *num_args) TabsWidget newTw = (TabsWidget)new; newTw->tabs.numRows = 0 ; - newTw->tabs.displayChildren = 0; + newTw->tabs.realRows = 0; GetPreferredSizes(newTw) ; @@ -486,6 +494,7 @@ TabsConstraintInitialize(Widget request, Widget new, { TabsConstraints tab = (TabsConstraints) new->core.constraints ; tab->tabs.greyAlloc = False ; /* defer allocation of pixel */ + tab->tabs.visible = False ; getBitmapInfo((TabsWidget)XtParent(new), tab) ; TabWidth(new) ; @@ -530,7 +539,7 @@ TabsResize(Widget w) int i ; int num_children = tw->composite.num_children ; Widget *childP ; - TabsConstraints tab ; + TabsConstraints tab ; /* #### unused */ Dimension cw,ch,bw ; /* Our size has now been dictated by the parent. Lay out the @@ -550,7 +559,7 @@ TabsResize(Widget w) { /* Loop through the tabs and assign rows & x positions */ (void) TabLayout(tw, tw->core.width, tw->core.height, NULL, False) ; - num_children = tw->tabs.displayChildren; + num_children = TabsNumChildren (tw); /* assign a top widget, bring it to bottom row. */ TabsShuffleRows(tw) ; @@ -567,7 +576,7 @@ TabsResize(Widget w) for(i=0, childP=tw->composite.children; i < num_children; ++i, ++childP) - if( XtIsManaged(*childP) ) + if( TabVisible(*childP) ) { tab = (TabsConstraints) (*childP)->core.constraints ; bw = (*childP)->core.border_width ; @@ -655,7 +664,7 @@ TabsSetValues(Widget current, Widget request, Widget new, * Window system will handle the redraws. */ - if( tw->tabs.topWidget != curtw->tabs.topWidget ) + if( tw->tabs.topWidget != curtw->tabs.topWidget ) { if( XtIsRealized(tw->tabs.topWidget) ) { @@ -757,7 +766,7 @@ TabsAcceptFocus(Widget w, Time *t) /* * Return preferred size. Happily accept anything >= our preferred size. * (TODO: is that the right thing to do? Should we always return "almost" - * if offerred more than we need?) + * if offered more than we need?) */ static XtGeometryResult @@ -932,8 +941,8 @@ TabsGeometryManager(Widget w, XtWidgetGeometry *req, XtWidgetGeometry *reply) Widget *childP = tw->composite.children ; int i,bw ; w->core.border_width = req->border_width ; - for(i=tw->tabs.displayChildren; --i >= 0; ++childP) - if( XtIsManaged(*childP) ) + for(i=TabsNumChildren (tw); --i >= 0; ++childP) + if( TabVisible(*childP) ) { bw = (*childP)->core.border_width ; XtConfigureWidget(*childP, s,tw->tabs.tab_total+s, @@ -980,6 +989,12 @@ TabsChangeManaged(Widget w) tw->tabs.topWidget->core.being_destroyed ) ) tw->tabs.topWidget = NULL ; + /* Check whether the highlight tab is still valid. */ + if( tw->tabs.hilight != NULL && + ( !XtIsManaged(tw->tabs.hilight) || + tw->tabs.hilight->core.being_destroyed ) ) + tw->tabs.hilight = NULL ; + GetPreferredSizes(tw) ; MakeSizeRequest(tw) ; @@ -995,7 +1010,7 @@ TabsChangeManaged(Widget w) */ if( tw->tabs.topWidget != NULL && XtIsRealized(tw->tabs.topWidget) ) { - for(i=tw->tabs.displayChildren; --i >= 0; ++childP) + for(i=TabsNumChildren (tw); --i >= 0; ++childP) if( !XtIsRealized(*childP) ) XtRealizeWidget(*childP) ; @@ -1060,9 +1075,9 @@ TabsSelect(Widget w, XEvent *event, String *params, Cardinal *num_params) * widget to be top of stacking order with XawTabsSetTop(). */ for(i=0, childP=tw->composite.children; - i < tw->tabs.displayChildren; + i < TabsNumChildren (tw); ++i, ++childP) - if( XtIsManaged(*childP) ) + if( TabVisible(*childP) ) { TabsConstraints tab = (TabsConstraints)(*childP)->core.constraints; if( x > tab->tabs.x && x < tab->tabs.x + tab->tabs.width && @@ -1086,7 +1101,7 @@ TabsPage(Widget w, XEvent *event, String *params, Cardinal *num_params) Widget newtop = NULL; Widget *childP ; int idx ; - int nc = tw->tabs.displayChildren ; + int nc = TabsNumChildren (tw) ; if( nc <= 0 ) return ; @@ -1150,7 +1165,7 @@ TabsHighlight(Widget w, XEvent *event, String *params, Cardinal *num_params) Widget newhl = NULL; Widget *childP ; int idx ; - int nc = tw->tabs.displayChildren ; + int nc = TabsNumChildren (tw) ; if( nc <= 0 ) return ; @@ -1255,6 +1270,7 @@ XawTabsSetTop(Widget w, Bool callCallbacks) if( !XtIsRealized(w) ) { tw->tabs.topWidget = w ; tw->tabs.needs_layout = True ; + tw->tabs.hilight = NULL; /* The highlight tab might disappear. */ return ; } @@ -1265,6 +1281,14 @@ XawTabsSetTop(Widget w, Bool callCallbacks) #endif tab = (TabsConstraints) w->core.constraints ; + + /* Unhighlight before we start messing with the stacking order. */ + if( tw->tabs.hilight != NULL ) + { + DrawHighlight(tw, tw->tabs.hilight, True) ; + tw->tabs.hilight = NULL; + } + if( tab->tabs.row == 0 ) { /* Easy case; undraw current top, undraw new top, assign new @@ -1307,8 +1331,6 @@ XawTabsSetHighlight(Widget t, Widget w) if( XtIsRealized(t) && w != tw->tabs.hilight ) { - if( tw->tabs.hilight != NULL ) - DrawHighlight(tw, tw->tabs.hilight, True) ; if( w != NULL ) DrawHighlight(tw, w, False) ; } @@ -1372,7 +1394,7 @@ DrawTabs(TabsWidget tw, Bool labels) if( !XtIsRealized((Widget)tw)) return ; - + /* draw tabs and frames by row except for the top tab, which * is drawn last. (This is inefficiently written, but should not * be too slow as long as there are not a lot of rows.) @@ -1381,9 +1403,9 @@ DrawTabs(TabsWidget tw, Bool labels) y = tw->tabs.numRows == 1 ? TABDELTA : 0 ; for(i=0; itabs.numRows; ++i, y += th) { - for( j=tw->tabs.displayChildren, childP=tw->composite.children; + for( j=TabsNumChildren (tw), childP=tw->composite.children; --j >= 0; ++childP ) - if( XtIsManaged(*childP) ) + if( TabVisible(*childP) ) { tab = (TabsConstraints)(*childP)->core.constraints; if( tab->tabs.row == i && *childP != tw->tabs.topWidget ) @@ -1692,16 +1714,13 @@ TabWidth(Widget w) static int TabLayout(TabsWidget tw, int wid, int hgt, Dimension *reply_height, Bool query_only) { - int i, row ; + int i, row, done = 0, display_rows = 0 ; int num_children = tw->composite.num_children ; Widget *childP ; Dimension w ; Position x,y ; TabsConstraints tab ; - if (!query_only) - tw->tabs.displayChildren = 0; - /* Algorithm: loop through children, assign X positions. If a tab * would extend beyond the right edge, start a new row. After all * rows are assigned, make a second pass and assign Y positions. @@ -1720,10 +1739,14 @@ TabLayout(TabsWidget tw, int wid, int hgt, Dimension *reply_height, Bool query_o { tab = (TabsConstraints) (*childP)->core.constraints ; w = tab->tabs.width ; + if( x + w > wid ) { /* new row */ - if (y + tw->tabs.tab_height > hgt) - break; - ++row ; + if (y + tw->tabs.tab_height > hgt && !done) + { + display_rows = row; + done = 1; + } + ++row; x = INDENT ; y += tw->tabs.tab_height ; } @@ -1733,12 +1756,14 @@ TabLayout(TabsWidget tw, int wid, int hgt, Dimension *reply_height, Bool query_o tab->tabs.row = row ; } x += w + SPACING ; - if (!query_only) - tw->tabs.displayChildren++; + if (!query_only && !done) + tab->tabs.visible = 1; + } - /* If there was only one row, increse the height by TABDELTA */ - if( ++row == 1 ) + /* If there was only one row, increase the height by TABDELTA */ + if( ++display_rows == 1 ) { + row++; y = TABDELTA ; if( !query_only ) for(i=num_children, childP=tw->composite.children; @@ -1752,17 +1777,18 @@ TabLayout(TabsWidget tw, int wid, int hgt, Dimension *reply_height, Bool query_o y += tw->tabs.tab_height ; } else - row = y = 0 ; + display_rows = row = y = 0 ; if( !query_only ) { tw->tabs.tab_total = y ; - tw->tabs.numRows = row ; + tw->tabs.numRows = display_rows ; + tw->tabs.realRows = row; } if( reply_height != NULL ) *reply_height = y ; - return row ; + return display_rows ; } @@ -1813,7 +1839,7 @@ TabsShuffleRows(TabsWidget tw) { TabsConstraints tab ; int move ; - int nrows ; + int real_rows, display_rows ; Widget *childP ; Dimension th = tw->tabs.tab_height ; Position bottom ; @@ -1821,7 +1847,7 @@ TabsShuffleRows(TabsWidget tw) /* There must be a top widget. If not, assign one. */ if( tw->tabs.topWidget == NULL && tw->composite.children != NULL ) - for(i=tw->composite.num_children, childP=tw->composite.children; + for(i=TabsNumChildren (tw), childP=tw->composite.children; --i >= 0; ++childP) if( XtIsManaged(*childP) ) { @@ -1831,26 +1857,31 @@ TabsShuffleRows(TabsWidget tw) if( tw->tabs.topWidget != NULL ) { - nrows = tw->tabs.numRows ; - assert( nrows > 0 ) ; + display_rows = tw->tabs.numRows ; + real_rows = tw->tabs.realRows ; + assert( display_rows >= real_rows ) ; - if( nrows > 1 ) + if( real_rows > 1 ) { tab = (TabsConstraints) tw->tabs.topWidget->core.constraints ; assert( tab != NULL ) ; - /* how far to move top row */ - move = nrows - tab->tabs.row ; + /* How far to move top row. The selected tab must be on + the bottom row of the *visible* rows. */ + move = (real_rows + 1 - display_rows) - tab->tabs.row ; + if (move < 0) + move = real_rows - move; bottom = tw->tabs.tab_total - th ; - for(i=tw->tabs.displayChildren, childP=tw->composite.children; + for(i=tw->composite.num_children, childP=tw->composite.children; --i >= 0; ++childP) if( XtIsManaged(*childP) ) { tab = (TabsConstraints) (*childP)->core.constraints ; - tab->tabs.row = (tab->tabs.row + move) % nrows ; + tab->tabs.row = (tab->tabs.row + move) % real_rows ; tab->tabs.y = bottom - tab->tabs.row * th ; + tab->tabs.visible = (tab->tabs.row < display_rows); } } } @@ -1864,7 +1895,6 @@ TabsShuffleRows(TabsWidget tw) * * This function requires that max_cw, max_ch already be set. */ - static int PreferredSize( TabsWidget tw,