Mercurial > hg > xemacs-beta
comparison lwlib/xlwtabs.c @ 448:3078fd1074e8 r21-2-39
Import from CVS: tag r21-2-39
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:38:25 +0200 |
parents | 1ccc32a20af4 |
children | b39c14581166 |
comparison
equal
deleted
inserted
replaced
447:4fc5f13f3bd3 | 448:3078fd1074e8 |
---|---|
64 #include <stdio.h> | 64 #include <stdio.h> |
65 | 65 |
66 #include <X11/Xlib.h> | 66 #include <X11/Xlib.h> |
67 #include <X11/IntrinsicP.h> | 67 #include <X11/IntrinsicP.h> |
68 #include <X11/StringDefs.h> | 68 #include <X11/StringDefs.h> |
69 | |
70 #include "lwlib-internal.h" | |
69 #include "../src/xmu.h" | 71 #include "../src/xmu.h" |
70 #include "xlwtabsP.h" | 72 #include "xlwtabsP.h" |
71 #include "xlwgcs.h" | 73 #include "xlwgcs.h" |
72 | 74 |
73 #define MIN_WID 10 | 75 #define MIN_WID 10 |
265 static void DrawBorder( TabsWidget tw, Widget child, Bool undraw) ; | 267 static void DrawBorder( TabsWidget tw, Widget child, Bool undraw) ; |
266 static void DrawHighlight( TabsWidget tw, Widget child, Bool undraw) ; | 268 static void DrawHighlight( TabsWidget tw, Widget child, Bool undraw) ; |
267 static void UndrawTab( TabsWidget tw, Widget child) ; | 269 static void UndrawTab( TabsWidget tw, Widget child) ; |
268 | 270 |
269 static void TabWidth( Widget w) ; | 271 static void TabWidth( Widget w) ; |
270 static int TabLayout( TabsWidget, int wid, int hgt, Dimension *r_hgt, | 272 static int TabLayout( TabsWidget, Dimension wid, Dimension hgt, Dimension *r_hgt, |
271 Bool query_only) ; | 273 Bool query_only) ; |
272 static void GetPreferredSizes(TabsWidget) ; | 274 static void GetPreferredSizes(TabsWidget) ; |
273 static void MaxChild(TabsWidget, Widget except, Dimension, Dimension) ; | 275 static void MaxChild(TabsWidget, Widget except, Dimension, Dimension) ; |
274 static void TabsShuffleRows( TabsWidget tw) ; | 276 static void TabsShuffleRows( TabsWidget tw) ; |
275 static int PreferredSize( TabsWidget, | 277 static int PreferredSize( TabsWidget, |
276 Dimension *reply_width, Dimension *reply_height, | 278 Dimension *reply_width, Dimension *reply_height, |
277 Dimension *reply_cw, Dimension *reply_ch) ; | 279 Dimension *reply_cw, Dimension *reply_ch) ; |
278 static int PreferredSize2( TabsWidget, int cw, int ch, | 280 static int PreferredSize2( TabsWidget, Dimension cw, Dimension ch, |
279 Dimension *rw, Dimension *rh) ; | 281 Dimension *rw, Dimension *rh) ; |
280 static int PreferredSize3( TabsWidget, int wid, int hgt, | 282 static int PreferredSize3( TabsWidget, Dimension wid, Dimension hgt, |
281 Dimension *rw, Dimension *rh) ; | 283 Dimension *rw, Dimension *rh) ; |
282 static void MakeSizeRequest(TabsWidget) ; | 284 static void MakeSizeRequest(TabsWidget) ; |
283 | 285 |
284 static void TabsAllocGCs(TabsWidget) ; | 286 static void TabsAllocGCs(TabsWidget) ; |
285 static void TabsFreeGCs(TabsWidget) ; | 287 static void TabsFreeGCs(TabsWidget) ; |
390 } | 392 } |
391 }; | 393 }; |
392 | 394 |
393 WidgetClass tabsWidgetClass = (WidgetClass)&tabsClassRec; | 395 WidgetClass tabsWidgetClass = (WidgetClass)&tabsClassRec; |
394 | 396 |
395 | |
396 | |
397 #ifdef DEBUG | |
398 #ifdef __STDC__ | |
399 #define assert(e) \ | |
400 if(!(e)) fprintf(stderr,"yak! %s at %s:%d\n",#e,__FILE__,__LINE__) | |
401 #else | |
402 #define assert(e) \ | |
403 if(!(e)) fprintf(stderr,"yak! e at %s:%d\n",__FILE__,__LINE__) | |
404 #endif | |
405 #else | |
406 #define assert(e) | |
407 #endif | |
408 | |
409 #define TabsNumChildren(tw) (((TabsWidget)tw)->composite.num_children) | 397 #define TabsNumChildren(tw) (((TabsWidget)tw)->composite.num_children) |
410 #define TabVisible(tab) \ | 398 #define TabVisible(tab) \ |
411 (XtIsManaged(tab) && \ | 399 (XtIsManaged(tab) && \ |
412 ((TabsConstraints)((tab)->core.constraints))->tabs.visible) | 400 ((TabsConstraints)((tab)->core.constraints))->tabs.visible) |
413 | 401 |
568 * same: just inside the frame. Sizes are also all the same. | 556 * same: just inside the frame. Sizes are also all the same. |
569 */ | 557 */ |
570 | 558 |
571 tw->tabs.child_width = cw = tw->core.width - 2 * SHADWID ; | 559 tw->tabs.child_width = cw = tw->core.width - 2 * SHADWID ; |
572 tw->tabs.child_height = ch = | 560 tw->tabs.child_height = ch = |
573 tw->core.height - tw->tabs.tab_total - 2 * SHADWID ; | 561 tw->core.height < (tw->tabs.tab_total + 2 * SHADWID) ? 0 : |
574 | 562 tw->core.height - tw->tabs.tab_total - 2 * SHADWID ; |
575 | 563 |
576 for(i=0, childP=tw->composite.children; | 564 for(i=0, childP=tw->composite.children; |
577 i < num_children; | 565 i < num_children; |
578 ++i, ++childP) | 566 ++i, ++childP) |
579 if( TabVisible(*childP) ) | 567 if( XtIsManaged(*childP) ) |
580 { | 568 { |
581 tab = (TabsConstraints) (*childP)->core.constraints ; | 569 tab = (TabsConstraints) (*childP)->core.constraints ; |
582 bw = (*childP)->core.border_width ; | 570 bw = (*childP)->core.border_width ; |
583 XtConfigureWidget(*childP, SHADWID,tw->tabs.tab_total+SHADWID, | 571 /* Don't do anything if we can't see any of the child. */ |
584 cw-bw*2,ch-bw*2, bw) ; | 572 if (ch >= bw*2 && ch > 0 && cw >= bw*2 && cw > 0) |
573 XtConfigureWidget(*childP, SHADWID,tw->tabs.tab_total+SHADWID, | |
574 cw-bw*2,ch-bw*2, bw) ; | |
585 } | 575 } |
586 if( XtIsRealized(w) ) { | 576 if( XtIsRealized(w) ) { |
587 XClearWindow(XtDisplay((Widget)tw), XtWindow((Widget)tw)) ; | 577 XClearWindow(XtDisplay((Widget)tw), XtWindow((Widget)tw)) ; |
588 /* should not be necessary to explicitly repaint after a | 578 /* should not be necessary to explicitly repaint after a |
589 * resize, but XEmacs folks tell me it is. | 579 * resize, but XEmacs folks tell me it is. |
871 XtWidgetGeometry myrequest, myreply ; | 861 XtWidgetGeometry myrequest, myreply ; |
872 | 862 |
873 myrequest.width = wid ; | 863 myrequest.width = wid ; |
874 myrequest.height = hgt ; | 864 myrequest.height = hgt ; |
875 myrequest.request_mode = CWWidth | CWHeight ; | 865 myrequest.request_mode = CWWidth | CWHeight ; |
876 | 866 |
867 assert (wid > 0 && hgt > 0); | |
877 /* If child is only querying, or if we're going to have to | 868 /* If child is only querying, or if we're going to have to |
878 * offer the child a compromise, then make this a query only. | 869 * offer the child a compromise, then make this a query only. |
879 */ | 870 */ |
880 | 871 |
881 if( (req->request_mode & XtCWQueryOnly) || rw < cw || rh < ch ) | 872 if( (req->request_mode & XtCWQueryOnly) || rw < cw || rh < ch ) |
1503 { | 1494 { |
1504 GC topgc = tw->tabs.topGC ; | 1495 GC topgc = tw->tabs.topGC ; |
1505 GC botgc = tw->tabs.botGC ; | 1496 GC botgc = tw->tabs.botGC ; |
1506 Dimension s = SHADWID ; | 1497 Dimension s = SHADWID ; |
1507 Dimension ch = tw->tabs.child_height ; | 1498 Dimension ch = tw->tabs.child_height ; |
1508 Draw3dBox((Widget)tw, 0,tw->tabs.tab_total, | 1499 if (ch > 0) |
1509 tw->core.width, ch+2*s, s, topgc, botgc) ; | 1500 Draw3dBox((Widget)tw, 0,tw->tabs.tab_total, |
1501 tw->core.width, ch+2*s, s, topgc, botgc) ; | |
1502 else | |
1503 { | |
1504 Widget w = tw->tabs.topWidget ; | |
1505 if (w != NULL) | |
1506 { | |
1507 TabsConstraints tab = (TabsConstraints) w->core.constraints ; | |
1508 Draw3dBox((Widget)tw, 0,tw->core.height - 2*s, | |
1509 tab->tabs.x, 2*s, s, topgc, botgc); | |
1510 Draw3dBox((Widget)tw, tab->tabs.x + tab->tabs.width, | |
1511 tw->core.height - 2*s, | |
1512 tw->core.width - tab->tabs.x - tab->tabs.width, 2*s, s, | |
1513 topgc, botgc); | |
1514 } | |
1515 else | |
1516 Draw3dBox((Widget)tw, 0,tw->core.height - 2*s, | |
1517 tw->core.width, 2*s, s, topgc, botgc) ; | |
1518 } | |
1510 } | 1519 } |
1511 | 1520 |
1512 | 1521 |
1513 /* draw trim around a tab or underneath a row of tabs */ | 1522 /* draw trim around a tab or underneath a row of tabs */ |
1514 | 1523 |
1710 * TODO: if they require more than two rows and the total height:width | 1719 * TODO: if they require more than two rows and the total height:width |
1711 * ratio is more than 2:1, then try something else. | 1720 * ratio is more than 2:1, then try something else. |
1712 */ | 1721 */ |
1713 | 1722 |
1714 static int | 1723 static int |
1715 TabLayout(TabsWidget tw, int wid, int hgt, Dimension *reply_height, Bool query_only) | 1724 TabLayout(TabsWidget tw, |
1725 Dimension wid, | |
1726 Dimension hgt, | |
1727 Dimension *reply_height, Bool query_only) | |
1716 { | 1728 { |
1717 int i, row, done = 0, display_rows = 0 ; | 1729 int i, row, done = 0, display_rows = 0 ; |
1718 int num_children = tw->composite.num_children ; | 1730 int num_children = tw->composite.num_children ; |
1719 Widget *childP ; | 1731 Widget *childP ; |
1720 Dimension w ; | 1732 Dimension w ; |
1815 int i ; | 1827 int i ; |
1816 Widget *childP = tw->composite.children ; | 1828 Widget *childP = tw->composite.children ; |
1817 XtWidgetGeometry preferred ; | 1829 XtWidgetGeometry preferred ; |
1818 | 1830 |
1819 for(i=tw->composite.num_children; --i >=0; ++childP) | 1831 for(i=tw->composite.num_children; --i >=0; ++childP) |
1820 if( XtIsManaged(*childP) && *childP != except ) | 1832 if( TabVisible (*childP) /*XtIsManaged(*childP)*/ && *childP != except ) |
1821 { | 1833 { |
1822 (void) XtQueryGeometry(*childP, NULL, &preferred) ; | 1834 (void) XtQueryGeometry(*childP, NULL, &preferred) ; |
1823 cw = Max(cw, preferred.width + preferred.border_width * 2 ) ; | 1835 cw = Max(cw, preferred.width + preferred.border_width * 2 ) ; |
1824 ch = Max(ch, preferred.height + preferred.border_width * 2 ) ; | 1836 ch = Max(ch, preferred.height + preferred.border_width * 2 ) ; |
1825 } | 1837 } |
1857 | 1869 |
1858 if( tw->tabs.topWidget != NULL ) | 1870 if( tw->tabs.topWidget != NULL ) |
1859 { | 1871 { |
1860 display_rows = tw->tabs.numRows ; | 1872 display_rows = tw->tabs.numRows ; |
1861 real_rows = tw->tabs.realRows ; | 1873 real_rows = tw->tabs.realRows ; |
1862 assert( display_rows >= real_rows ) ; | 1874 assert( display_rows <= real_rows ) ; |
1863 | 1875 |
1864 if( real_rows > 1 ) | 1876 if( real_rows > 1 ) |
1865 { | 1877 { |
1866 tab = (TabsConstraints) tw->tabs.topWidget->core.constraints ; | 1878 tab = (TabsConstraints) tw->tabs.topWidget->core.constraints ; |
1867 assert( tab != NULL ) ; | 1879 assert( tab != NULL ) ; |
1957 /* Find preferred size, given size of children. */ | 1969 /* Find preferred size, given size of children. */ |
1958 | 1970 |
1959 static int | 1971 static int |
1960 PreferredSize2( | 1972 PreferredSize2( |
1961 TabsWidget tw, | 1973 TabsWidget tw, |
1962 int cw, /* child width, height */ | 1974 Dimension cw, /* child width, height */ |
1963 int ch, | 1975 Dimension ch, |
1964 Dimension *reply_width, /* total widget size */ | 1976 Dimension *reply_width, /* total widget size */ |
1965 Dimension *reply_height) | 1977 Dimension *reply_height) |
1966 { | 1978 { |
1967 Dimension s = SHADWID ; | 1979 Dimension s = SHADWID ; |
1980 int ret; | |
1968 | 1981 |
1969 /* make room for shadow frame */ | 1982 /* make room for shadow frame */ |
1970 cw += s*2 ; | 1983 cw += s*2 ; |
1971 ch += s*2 ; | 1984 ch += s*2 ; |
1972 | 1985 |
1973 return PreferredSize3(tw, cw, ch, reply_width, reply_height) ; | 1986 ret = PreferredSize3(tw, cw, ch, reply_width, reply_height) ; |
1987 | |
1988 assert (*reply_width > 0 && *reply_height > 0); | |
1989 return ret; | |
1974 } | 1990 } |
1975 | 1991 |
1976 | 1992 |
1977 /* Find preferred size, given size of children+shadow. */ | 1993 /* Find preferred size, given size of children+shadow. */ |
1978 | 1994 |
1979 static int | 1995 static int |
1980 PreferredSize3( | 1996 PreferredSize3( |
1981 TabsWidget tw, | 1997 TabsWidget tw, |
1982 int wid, /* child width, height */ | 1998 Dimension wid, /* child width, height */ |
1983 int hgt, | 1999 Dimension hgt, |
1984 Dimension *reply_width, /* total widget size */ | 2000 Dimension *reply_width, /* total widget size */ |
1985 Dimension *reply_height) | 2001 Dimension *reply_height) |
1986 { | 2002 { |
1987 Dimension th ; /* space used by tabs */ | 2003 Dimension th ; /* space used by tabs */ |
1988 int nrows ; | 2004 int nrows ; |