comparison lwlib/xlwtabs.c @ 3397:6aa26bef0527

[xemacs-hg @ 2006-05-12 19:25:28 by stephent] Stop trashing xftFont resources. <87mzdnxd1j.fsf@tleepslib.sk.tsukuba.ac.jp>
author stephent
date Fri, 12 May 2006 19:25:29 +0000
parents 174eb4da74fb
children 382b11fa8866
comparison
equal deleted inserted replaced
3396:af3bfea5c60e 3397:6aa26bef0527
148 {XtNselectInsensitive, XtCSelectInsensitive, XtRBoolean, sizeof(Boolean), 148 {XtNselectInsensitive, XtCSelectInsensitive, XtRBoolean, sizeof(Boolean),
149 offset(selectInsensitive), XtRImmediate, (XtPointer) True}, 149 offset(selectInsensitive), XtRImmediate, (XtPointer) True},
150 {XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *), 150 {XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *),
151 offset(font), XtRString, (XtPointer) XtDefaultFont}, 151 offset(font), XtRString, (XtPointer) XtDefaultFont},
152 #ifdef USE_XFT_TABS 152 #ifdef USE_XFT_TABS
153 /* #### Maybe use "-*-helvetica-bold-r-*-*-*-120-*-*-*-*-iso8859-1" here? */ 153 /* #### Maybe use "-*-helvetica-bold-r-*-*-*-120-*-*-*-*-iso8859-1" here?
154 {XtNxftFont, XtCXftFont, XtRString, sizeof (String), 154 or XtDefaultFont? */
155 offset(renderFontSpec), XtRString, 155 {XtNfcFontName, XtCFcFontName, XtRString, sizeof(String),
156 (XtPointer) "AirCut-16" /* XtDefaultFont */}, 156 offset(fcFontName), XtRString, (XtPointer) "AirCut-16" },
157 /* #### This needs to be fixed to give a proper type and converter for
158 XftFonts. See also xlwmenu.c. */
159 {XtNxftFont, XtCXftFont, XtRPointer, sizeof(XtPointer),
160 offset(renderFont), XtRPointer, (XtPointer) NULL },
157 #endif 161 #endif
158 {XtNinternalWidth, XtCWidth, XtRDimension, sizeof(Dimension), 162 {XtNinternalWidth, XtCWidth, XtRDimension, sizeof(Dimension),
159 offset(internalWidth), XtRImmediate, (XtPointer)4 }, 163 offset(internalWidth), XtRImmediate, (XtPointer)4 },
160 {XtNinternalHeight, XtCHeight, XtRDimension, sizeof(Dimension), 164 {XtNinternalHeight, XtCHeight, XtRDimension, sizeof(Dimension),
161 offset(internalHeight), XtRImmediate, (XtPointer)4 }, 165 offset(internalHeight), XtRImmediate, (XtPointer)4 },
479 to do this right, we should add a new Xt Resource type + 483 to do this right, we should add a new Xt Resource type +
480 conversion function 484 conversion function
481 */ 485 */
482 newTw->tabs.renderFont = 486 newTw->tabs.renderFont =
483 xft_open_font_by_name (XtDisplay ((Widget) newTw), 487 xft_open_font_by_name (XtDisplay ((Widget) newTw),
484 newTw->tabs.renderFontSpec); 488 newTw->tabs.fcFontName);
485 if (newTw->tabs.renderFont != NULL) 489 if (newTw->tabs.renderFont != NULL)
486 #if XFT_USE_HEIGHT_NOT_ASCENT_DESCENT 490 #if XFT_USE_HEIGHT_NOT_ASCENT_DESCENT
487 newTw->tabs.tab_height += newTw->tabs.renderFont->height; 491 newTw->tabs.tab_height += newTw->tabs.renderFont->height;
488 #else 492 #else
489 newTw->tabs.tab_height += newTw->tabs.renderFont->ascent + 493 newTw->tabs.tab_height += newTw->tabs.renderFont->ascent +
1087 { 1091 {
1088 /* this rarely gets triggered, but when it does it seems to 1092 /* this rarely gets triggered, but when it does it seems to
1089 get triggered forever after */ 1093 get triggered forever after */
1090 int n = control->composite.num_children; 1094 int n = control->composite.num_children;
1091 ah = control->tabs.tab_height; 1095 ah = control->tabs.tab_height;
1092 if (debug_tabs > 0) 1096 if (debug_tabs > 1)
1093 fprintf (stderr, "Kludging around %d != 1 rows," 1097 fprintf (stderr, "Kludging around %d != 1 rows,"
1094 " #children = %d, total height %d, using %d.\n", 1098 " #children = %d, total height %d, using %d.\n",
1095 check_nrows, n, th, ah); 1099 check_nrows, n, th, ah);
1096 } 1100 }
1097 1101
1614 DrawTab(TabsWidget tw, Widget child, Bool labels) 1618 DrawTab(TabsWidget tw, Widget child, Bool labels)
1615 { 1619 {
1616 GC gc ; 1620 GC gc ;
1617 int x,y ; 1621 int x,y ;
1618 1622
1619 if (debug_tabs > 1) fprintf (stderr, "DrawTab called.\n"); 1623 if (debug_tabs > 2) fprintf (stderr, "DrawTab called.\n");
1620 1624
1621 if( !XtIsRealized((Widget)tw)) 1625 if( !XtIsRealized((Widget)tw))
1622 return ; 1626 return ;
1623 1627
1624 DrawBorder(tw, child, False) ; 1628 DrawBorder(tw, child, False) ;
1710 XftColorAllocName (dpy, visual, cmap, "wheat", &colorDBG); 1714 XftColorAllocName (dpy, visual, cmap, "wheat", &colorDBG);
1711 XftTextExtents8 (dpy, renderFont, (FcChar8 *) lbl, 1715 XftTextExtents8 (dpy, renderFont, (FcChar8 *) lbl,
1712 (int) strlen (lbl), &glyphinfo); 1716 (int) strlen (lbl), &glyphinfo);
1713 /* #### unnecessary? for the moment, give visual extent */ 1717 /* #### unnecessary? for the moment, give visual extent */
1714 /* draw background rect */ 1718 /* draw background rect */
1715 #if 1
1716 if (debug_tabs > 2) 1719 if (debug_tabs > 2)
1717 { 1720 {
1718 fprintf (stderr, "background color: pixel=%08lx, r=%04x," 1721 fprintf (stderr, "background color: pixel=%08lx, r=%04x,"
1719 " g=%04x, b=%04x, alpha=%04x.\n", 1722 " g=%04x, b=%04x, alpha=%04x.\n",
1720 colorDBG.pixel, colorDBG.color.red, 1723 colorDBG.pixel, colorDBG.color.red,
1723 fprintf (stderr, "label geometry: x=%d, y=%d, xOff=%d," 1726 fprintf (stderr, "label geometry: x=%d, y=%d, xOff=%d,"
1724 " yOff=%d, width=%d, height=%d\n", 1727 " yOff=%d, width=%d, height=%d\n",
1725 glyphinfo.x, glyphinfo.y, glyphinfo.xOff, 1728 glyphinfo.x, glyphinfo.y, glyphinfo.xOff,
1726 glyphinfo.yOff, glyphinfo.width, glyphinfo.height); 1729 glyphinfo.yOff, glyphinfo.width, glyphinfo.height);
1727 } 1730 }
1728 XftDrawRect (xftDraw, &colorDBG, 1731 if (debug_tabs > 2)
1729 /* left, top, width, height */ 1732 XftDrawRect (xftDraw, &colorDBG,
1730 x+tab->tabs.l_x-glyphinfo.x, 1733 /* left, top, width, height */
1731 y+tab->tabs.l_y-glyphinfo.y, 1734 x+tab->tabs.l_x-glyphinfo.x,
1732 glyphinfo.width, glyphinfo.height); 1735 y+tab->tabs.l_y-glyphinfo.y,
1733 #endif 1736 glyphinfo.width, glyphinfo.height);
1737
1734 /* draw text */ 1738 /* draw text */
1735 if (debug_tabs > 2) 1739 if (debug_tabs > 1)
1736 { 1740 {
1737 FcValue name;
1738 FcValue size;
1739 FcPatternGet (renderFont->pattern, FC_FAMILY, 0, &name);
1740 FcPatternGet (renderFont->pattern, FC_SIZE, 0, &size);
1741 fprintf (stderr, "label: %s.\n", lbl); 1741 fprintf (stderr, "label: %s.\n", lbl);
1742 fprintf (stderr, "foreground color: pixel=%08lx, r=%04x," 1742 fprintf (stderr, "foreground color: pixel=%08lx, r=%04x,"
1743 " g=%04x, b=%04x, alpha=%04x.\n", 1743 " g=%04x, b=%04x, alpha=%04x.\n",
1744 color.pixel, color.color.red, color.color.green, 1744 color.pixel, color.color.red, color.color.green,
1745 color.color.blue, color.color.alpha); 1745 color.color.blue, color.color.alpha);
1746 fprintf (stderr, "extent: x=%d, y=%d, xOffset=%d," 1746 fprintf (stderr, "extent: x=%d, y=%d, xOffset=%d,"
1747 " yOffset=%d, height=%d, width=%d.\n", 1747 " yOffset=%d, height=%d, width=%d.\n",
1748 glyphinfo.x, glyphinfo.y, glyphinfo.xOff, 1748 glyphinfo.x, glyphinfo.y, glyphinfo.xOff,
1749 glyphinfo.yOff, glyphinfo.height, glyphinfo.width); 1749 glyphinfo.yOff, glyphinfo.height, glyphinfo.width);
1750 }
1751 if (debug_tabs > 0)
1752 {
1753 FcValue name;
1754 FcValue size;
1755 FcPatternGet (renderFont->pattern, FC_FAMILY, 0, &name);
1756 FcPatternGet (renderFont->pattern, FC_SIZE, 0, &size);
1750 fprintf (stderr, "font: name=%s-%.1f," 1757 fprintf (stderr, "font: name=%s-%.1f,"
1751 " height=%d, ascent=%d, descent=%d.\n", 1758 " height=%d, ascent=%d, descent=%d.\n",
1752 name.u.s, size.u.d, renderFont->height, 1759 name.u.s, size.u.d, renderFont->height,
1753 renderFont->ascent, renderFont->descent); 1760 renderFont->ascent, renderFont->descent);
1754 } 1761 }
2063 x = INDENT ; 2070 x = INDENT ;
2064 y = 0 ; 2071 y = 0 ;
2065 /* If wid or hgt is 0, we want to guess our own dimensions. 2072 /* If wid or hgt is 0, we want to guess our own dimensions.
2066 Currently the guessing functions are broken.... 2073 Currently the guessing functions are broken....
2067 #### When PreferredSize*() get fixed, fix this too. */ 2074 #### When PreferredSize*() get fixed, fix this too. */
2068 if (debug_tabs > 0) 2075 if (debug_tabs > 1)
2069 fprintf (stderr, "arg=%d,", wid); 2076 fprintf (stderr, "arg=%d,", wid);
2070 wid = (wid ? wid : tw->core.width) - INDENT ; 2077 wid = (wid ? wid : tw->core.width) - INDENT ;
2071 hgt = hgt ? hgt : tw->core.height; 2078 hgt = hgt ? hgt : tw->core.height;
2072 if (debug_tabs > 0) 2079 if (debug_tabs > 1)
2073 fprintf (stderr, "wid=%d: x,w,y=", wid); 2080 fprintf (stderr, "wid=%d: x,w,y=", wid);
2074 for(i=num_children, childP=tw->composite.children; --i >= 0; ++childP) 2081 for(i=num_children, childP=tw->composite.children; --i >= 0; ++childP)
2075 if( XtIsManaged(*childP) ) 2082 if( XtIsManaged(*childP) )
2076 { 2083 {
2077 tab = (TabsConstraints) (*childP)->core.constraints ; 2084 tab = (TabsConstraints) (*childP)->core.constraints ;
2078 w = tab->tabs.width ; 2085 w = tab->tabs.width ;
2079 2086
2080 if (debug_tabs > 0) 2087 if (debug_tabs > 1)
2081 fprintf (stderr, "%d,%d,%d;", x, w, y); 2088 fprintf (stderr, "%d,%d,%d;", x, w, y);
2082 if( x + w > wid ) { /* new row */ 2089 if( x + w > wid ) { /* new row */
2083 /* #### algorithm is not robust to wid < child's width */ 2090 /* #### algorithm is not robust to wid < child's width */
2084 ++row; 2091 ++row;
2085 x = INDENT ; 2092 x = INDENT ;
2098 x += w + SPACING ; 2105 x += w + SPACING ;
2099 if (!query_only && !done) 2106 if (!query_only && !done)
2100 tab->tabs.visible = 1; 2107 tab->tabs.visible = 1;
2101 2108
2102 } 2109 }
2103 if (debug_tabs > 0) 2110 if (debug_tabs > 1)
2104 fprintf (stderr, "\n"); 2111 fprintf (stderr, "\n");
2105 /* If there was only one row, increase the height by TABDELTA */ 2112 /* If there was only one row, increase the height by TABDELTA */
2106 if( ++display_rows == 1 ) 2113 if( ++display_rows == 1 )
2107 { 2114 {
2108 y = TABDELTA ; 2115 y = TABDELTA ;
2125 tw->tabs.tab_total = y ; 2132 tw->tabs.tab_total = y ;
2126 tw->tabs.numRows = display_rows ; 2133 tw->tabs.numRows = display_rows ;
2127 tw->tabs.realRows = row; 2134 tw->tabs.realRows = row;
2128 } 2135 }
2129 2136
2130 if (debug_tabs > 0 && (row > 1 || display_rows > 1)) 2137 if (debug_tabs > 1 && (row > 1 || display_rows > 1))
2131 fprintf (stderr, "tab: %d display rows, #children = %d," 2138 fprintf (stderr, "tab: %d display rows, #children = %d,"
2132 " total height %d, total rows %d%s.\n", 2139 " total height %d, total rows %d%s.\n",
2133 display_rows, num_children, y, row, 2140 display_rows, num_children, y, row,
2134 query_only ? " (query)" : ""); 2141 query_only ? " (query)" : "");
2135 2142