summaryrefslogtreecommitdiffstats
path: root/generic/tkTreeUtils.c
diff options
context:
space:
mode:
authortreectrl <treectrl>2005-09-16 23:24:20 (GMT)
committertreectrl <treectrl>2005-09-16 23:24:20 (GMT)
commit57aa137a3d2ccd20c7fd09baa635e3933eee4d5e (patch)
tree3f32116bcc8503352a4ba14546c0081a024589c7 /generic/tkTreeUtils.c
parentbf00b9981a50c5594017ed97e252b84548732128 (diff)
downloadtktreectrl-57aa137a3d2ccd20c7fd09baa635e3933eee4d5e.zip
tktreectrl-57aa137a3d2ccd20c7fd09baa635e3933eee4d5e.tar.gz
tktreectrl-57aa137a3d2ccd20c7fd09baa635e3933eee4d5e.tar.bz2
Converted to tab+space indentation.
Diffstat (limited to 'generic/tkTreeUtils.c')
-rw-r--r--generic/tkTreeUtils.c2024
1 files changed, 1012 insertions, 1012 deletions
diff --git a/generic/tkTreeUtils.c b/generic/tkTreeUtils.c
index 20592d9..14ef441 100644
--- a/generic/tkTreeUtils.c
+++ b/generic/tkTreeUtils.c
@@ -5,7 +5,7 @@
*
* Copyright (c) 2002-2005 Tim Baker
*
- * RCS: @(#) $Id: tkTreeUtils.c,v 1.35 2005/09/14 21:38:55 treectrl Exp $
+ * RCS: @(#) $Id: tkTreeUtils.c,v 1.36 2005/09/16 23:25:17 treectrl Exp $
*/
#include "tkTreeCtrl.h"
@@ -26,16 +26,16 @@ static PixPatHandle gPenPat = NULL;
*/
static int PadAmountOptionSet _ANSI_ARGS_((ClientData clientData,
- Tcl_Interp *interp, Tk_Window tkwin,
- Tcl_Obj **value, char *recordPtr, int internalOffset,
- char *saveInternalPtr, int flags));
+ Tcl_Interp *interp, Tk_Window tkwin,
+ Tcl_Obj **value, char *recordPtr, int internalOffset,
+ char *saveInternalPtr, int flags));
static Tcl_Obj *PadAmountOptionGet _ANSI_ARGS_((ClientData clientData,
- Tk_Window tkwin, char *recordPtr, int internalOffset));
+ Tk_Window tkwin, char *recordPtr, int internalOffset));
static void PadAmountOptionRestore _ANSI_ARGS_((ClientData clientData,
- Tk_Window tkwin, char *internalPtr,
- char *saveInternalPtr));
+ Tk_Window tkwin, char *internalPtr,
+ char *saveInternalPtr));
static void PadAmountOptionFree _ANSI_ARGS_((ClientData clientData,
- Tk_Window tkwin, char *internalPtr));
+ Tk_Window tkwin, char *internalPtr));
/*
* The following Tk_ObjCustomOption structure can be used as clientData entry
@@ -54,107 +54,107 @@ Tk_ObjCustomOption PadAmountOption = {
void FormatResult(Tcl_Interp *interp, char *fmt, ...)
{
- va_list ap;
- char buf[256];
+ va_list ap;
+ char buf[256];
- va_start(ap, fmt);
- vsprintf(buf, fmt, ap);
- va_end(ap);
- Tcl_SetResult(interp, buf, TCL_VOLATILE);
+ va_start(ap, fmt);
+ vsprintf(buf, fmt, ap);
+ va_end(ap);
+ Tcl_SetResult(interp, buf, TCL_VOLATILE);
}
int Ellipsis(Tk_Font tkfont, char *string, int numBytes, int *maxPixels, char *ellipsis, int force)
{
- char staticStr[256], *tmpStr = staticStr;
- int pixels, pixelsTest, bytesThatFit, bytesTest;
- int ellipsisNumBytes = strlen(ellipsis);
+ char staticStr[256], *tmpStr = staticStr;
+ int pixels, pixelsTest, bytesThatFit, bytesTest;
+ int ellipsisNumBytes = strlen(ellipsis);
- bytesThatFit = Tk_MeasureChars(tkfont, string, numBytes, *maxPixels, 0,
- &pixels);
+ bytesThatFit = Tk_MeasureChars(tkfont, string, numBytes, *maxPixels, 0,
+ &pixels);
- /* The whole string fits. No ellipsis needed (unless forced) */
- if ((bytesThatFit == numBytes) && !force)
- {
- (*maxPixels) = pixels;
- return numBytes;
- }
+ /* The whole string fits. No ellipsis needed (unless forced) */
+ if ((bytesThatFit == numBytes) && !force)
+ {
+ (*maxPixels) = pixels;
+ return numBytes;
+ }
- if (bytesThatFit <= 1)
- {
- (*maxPixels) = pixels;
- return -bytesThatFit;
- }
+ if (bytesThatFit <= 1)
+ {
+ (*maxPixels) = pixels;
+ return -bytesThatFit;
+ }
- /* Strip off one character at a time, adding ellipsis, until it fits */
- if (force)
- bytesTest = bytesThatFit;
- else
- bytesTest = Tcl_UtfPrev(string + bytesThatFit, string) - string;
- if (bytesTest + ellipsisNumBytes > sizeof(staticStr))
- tmpStr = ckalloc(bytesTest + ellipsisNumBytes);
- memcpy(tmpStr, string, bytesTest);
- while (bytesTest > 0)
+ /* Strip off one character at a time, adding ellipsis, until it fits */
+ if (force)
+ bytesTest = bytesThatFit;
+ else
+ bytesTest = Tcl_UtfPrev(string + bytesThatFit, string) - string;
+ if (bytesTest + ellipsisNumBytes > sizeof(staticStr))
+ tmpStr = ckalloc(bytesTest + ellipsisNumBytes);
+ memcpy(tmpStr, string, bytesTest);
+ while (bytesTest > 0)
+ {
+ memcpy(tmpStr + bytesTest, ellipsis, ellipsisNumBytes);
+ numBytes = Tk_MeasureChars(tkfont, tmpStr,
+ bytesTest + ellipsisNumBytes,
+ *maxPixels, 0, &pixelsTest);
+ if (numBytes == bytesTest + ellipsisNumBytes)
{
- memcpy(tmpStr + bytesTest, ellipsis, ellipsisNumBytes);
- numBytes = Tk_MeasureChars(tkfont, tmpStr,
- bytesTest + ellipsisNumBytes,
- *maxPixels, 0, &pixelsTest);
- if (numBytes == bytesTest + ellipsisNumBytes)
- {
- (*maxPixels) = pixelsTest;
- if (tmpStr != staticStr)
- ckfree(tmpStr);
- return bytesTest;
- }
- bytesTest = Tcl_UtfPrev(string + bytesTest, string) - string;
+ (*maxPixels) = pixelsTest;
+ if (tmpStr != staticStr)
+ ckfree(tmpStr);
+ return bytesTest;
}
+ bytesTest = Tcl_UtfPrev(string + bytesTest, string) - string;
+ }
- /* No single char + ellipsis fits. Return number of chars that fit */
- /* Negative tells caller to not add ellipsis */
- (*maxPixels) = pixels;
- if (tmpStr != staticStr)
- ckfree(tmpStr);
- return -bytesThatFit;
+ /* No single char + ellipsis fits. Return number of chars that fit */
+ /* Negative tells caller to not add ellipsis */
+ (*maxPixels) = pixels;
+ if (tmpStr != staticStr)
+ ckfree(tmpStr);
+ return -bytesThatFit;
}
/* Draws a horizontal 1-pixel tall dotted line */
void HDotLine(TreeCtrl *tree, Drawable drawable, GC gc, int x1, int y1, int x2)
{
#ifdef WIN32
- TkWinDCState state;
- HDC dc;
- HPEN pen, oldPen;
- int nw;
- int wx = x1 + tree->drawableXOrigin;
- int wy = y1 + tree->drawableYOrigin;
-
- dc = TkWinGetDrawableDC(tree->display, drawable, &state);
- SetROP2(dc, R2_COPYPEN);
-
- pen = CreatePen(PS_SOLID, 1, gc->foreground);
- oldPen = SelectObject(dc, pen);
-
- nw = !(wx & 1) == !(wy & 1);
- for (x1 += !nw; x1 < x2; x1 += 2)
- {
- MoveToEx(dc, x1, y1, NULL);
- LineTo(dc, x1 + 1, y1);
- }
+ TkWinDCState state;
+ HDC dc;
+ HPEN pen, oldPen;
+ int nw;
+ int wx = x1 + tree->drawableXOrigin;
+ int wy = y1 + tree->drawableYOrigin;
+
+ dc = TkWinGetDrawableDC(tree->display, drawable, &state);
+ SetROP2(dc, R2_COPYPEN);
+
+ pen = CreatePen(PS_SOLID, 1, gc->foreground);
+ oldPen = SelectObject(dc, pen);
+
+ nw = !(wx & 1) == !(wy & 1);
+ for (x1 += !nw; x1 < x2; x1 += 2)
+ {
+ MoveToEx(dc, x1, y1, NULL);
+ LineTo(dc, x1 + 1, y1);
+ }
- SelectObject(dc, oldPen);
- DeleteObject(pen);
+ SelectObject(dc, oldPen);
+ DeleteObject(pen);
- TkWinReleaseDrawableDC(drawable, dc, &state);
+ TkWinReleaseDrawableDC(drawable, dc, &state);
#else
- int nw;
- int wx = x1 + tree->drawableXOrigin;
- int wy = y1 + tree->drawableYOrigin;
-
- nw = !(wx & 1) == !(wy & 1);
- for (x1 += !nw; x1 < x2; x1 += 2)
- {
- XDrawPoint(tree->display, drawable, gc, x1, y1);
- }
+ int nw;
+ int wx = x1 + tree->drawableXOrigin;
+ int wy = y1 + tree->drawableYOrigin;
+
+ nw = !(wx & 1) == !(wy & 1);
+ for (x1 += !nw; x1 < x2; x1 += 2)
+ {
+ XDrawPoint(tree->display, drawable, gc, x1, y1);
+ }
#endif
}
@@ -162,40 +162,40 @@ void HDotLine(TreeCtrl *tree, Drawable drawable, GC gc, int x1, int y1, int x2)
void VDotLine(TreeCtrl *tree, Drawable drawable, GC gc, int x1, int y1, int y2)
{
#ifdef WIN32
- TkWinDCState state;
- HDC dc;
- HPEN pen, oldPen;
- int nw;
- int wx = x1 + tree->drawableXOrigin;
- int wy = y1 + tree->drawableYOrigin;
-
- dc = TkWinGetDrawableDC(tree->display, drawable, &state);
- SetROP2(dc, R2_COPYPEN);
-
- pen = CreatePen(PS_SOLID, 1, gc->foreground);
- oldPen = SelectObject(dc, pen);
-
- nw = !(wx & 1) == !(wy & 1);
- for (y1 += !nw; y1 < y2; y1 += 2)
- {
- MoveToEx(dc, x1, y1, NULL);
- LineTo(dc, x1 + 1, y1);
- }
+ TkWinDCState state;
+ HDC dc;
+ HPEN pen, oldPen;
+ int nw;
+ int wx = x1 + tree->drawableXOrigin;
+ int wy = y1 + tree->drawableYOrigin;
+
+ dc = TkWinGetDrawableDC(tree->display, drawable, &state);
+ SetROP2(dc, R2_COPYPEN);
+
+ pen = CreatePen(PS_SOLID, 1, gc->foreground);
+ oldPen = SelectObject(dc, pen);
+
+ nw = !(wx & 1) == !(wy & 1);
+ for (y1 += !nw; y1 < y2; y1 += 2)
+ {
+ MoveToEx(dc, x1, y1, NULL);
+ LineTo(dc, x1 + 1, y1);
+ }
- SelectObject(dc, oldPen);
- DeleteObject(pen);
+ SelectObject(dc, oldPen);
+ DeleteObject(pen);
- TkWinReleaseDrawableDC(drawable, dc, &state);
+ TkWinReleaseDrawableDC(drawable, dc, &state);
#else
- int nw;
- int wx = x1 + tree->drawableXOrigin;
- int wy = y1 + tree->drawableYOrigin;
-
- nw = !(wx & 1) == !(wy & 1);
- for (y1 += !nw; y1 < y2; y1 += 2)
- {
- XDrawPoint(tree->display, drawable, gc, x1, y1);
- }
+ int nw;
+ int wx = x1 + tree->drawableXOrigin;
+ int wy = y1 + tree->drawableYOrigin;
+
+ nw = !(wx & 1) == !(wy & 1);
+ for (y1 += !nw; y1 < y2; y1 += 2)
+ {
+ XDrawPoint(tree->display, drawable, gc, x1, y1);
+ }
#endif
}
@@ -203,486 +203,486 @@ void VDotLine(TreeCtrl *tree, Drawable drawable, GC gc, int x1, int y1, int y2)
void DrawActiveOutline(TreeCtrl *tree, Drawable drawable, int x, int y, int width, int height, int open)
{
#ifdef WIN32
- int wx = x + tree->drawableXOrigin;
- int wy = y + tree->drawableYOrigin;
- int w = !(open & 0x01);
- int n = !(open & 0x02);
- int e = !(open & 0x04);
- int s = !(open & 0x08);
- int nw, ne, sw, se;
- int i;
- TkWinDCState state;
- HDC dc;
+ int wx = x + tree->drawableXOrigin;
+ int wy = y + tree->drawableYOrigin;
+ int w = !(open & 0x01);
+ int n = !(open & 0x02);
+ int e = !(open & 0x04);
+ int s = !(open & 0x08);
+ int nw, ne, sw, se;
+ int i;
+ TkWinDCState state;
+ HDC dc;
- /* Dots on even pixels only */
- nw = !(wx & 1) == !(wy & 1);
- ne = !((wx + width - 1) & 1) == !(wy & 1);
- sw = !(wx & 1) == !((wy + height - 1) & 1);
- se = !((wx + width - 1) & 1) == !((wy + height - 1) & 1);
+ /* Dots on even pixels only */
+ nw = !(wx & 1) == !(wy & 1);
+ ne = !((wx + width - 1) & 1) == !(wy & 1);
+ sw = !(wx & 1) == !((wy + height - 1) & 1);
+ se = !((wx + width - 1) & 1) == !((wy + height - 1) & 1);
- dc = TkWinGetDrawableDC(tree->display, drawable, &state);
- SetROP2(dc, R2_NOT);
+ dc = TkWinGetDrawableDC(tree->display, drawable, &state);
+ SetROP2(dc, R2_NOT);
- if (w) /* left */
+ if (w) /* left */
+ {
+ for (i = !nw; i < height; i += 2)
{
- for (i = !nw; i < height; i += 2)
- {
- MoveToEx(dc, x, y + i, NULL);
- LineTo(dc, x + 1, y + i);
- }
+ MoveToEx(dc, x, y + i, NULL);
+ LineTo(dc, x + 1, y + i);
}
- if (n) /* top */
+ }
+ if (n) /* top */
+ {
+ for (i = nw ? w * 2 : 1; i < width; i += 2)
{
- for (i = nw ? w * 2 : 1; i < width; i += 2)
- {
- MoveToEx(dc, x + i, y, NULL);
- LineTo(dc, x + i + 1, y);
- }
+ MoveToEx(dc, x + i, y, NULL);
+ LineTo(dc, x + i + 1, y);
}
- if (e) /* right */
+ }
+ if (e) /* right */
+ {
+ for (i = ne ? n * 2 : 1; i < height; i += 2)
{
- for (i = ne ? n * 2 : 1; i < height; i += 2)
- {
- MoveToEx(dc, x + width - 1, y + i, NULL);
- LineTo(dc, x + width, y + i);
- }
+ MoveToEx(dc, x + width - 1, y + i, NULL);
+ LineTo(dc, x + width, y + i);
}
- if (s) /* bottom */
+ }
+ if (s) /* bottom */
+ {
+ for (i = sw ? w * 2 : 1; i < width - (se && e); i += 2)
{
- for (i = sw ? w * 2 : 1; i < width - (se && e); i += 2)
- {
- MoveToEx(dc, x + i, y + height - 1, NULL);
- LineTo(dc, x + i + 1, y + height - 1);
- }
+ MoveToEx(dc, x + i, y + height - 1, NULL);
+ LineTo(dc, x + i + 1, y + height - 1);
}
+ }
- TkWinReleaseDrawableDC(drawable, dc, &state);
+ TkWinReleaseDrawableDC(drawable, dc, &state);
#else /* WIN32 */
- int wx = x + tree->drawableXOrigin;
- int wy = y + tree->drawableYOrigin;
- int w = !(open & 0x01);
- int n = !(open & 0x02);
- int e = !(open & 0x04);
- int s = !(open & 0x08);
- int nw, ne, sw, se;
- int i;
- XGCValues gcValues;
- unsigned long gcMask;
- GC gc;
-
- /* Dots on even pixels only */
- nw = !(wx & 1) == !(wy & 1);
- ne = !((wx + width - 1) & 1) == !(wy & 1);
- sw = !(wx & 1) == !((wy + height - 1) & 1);
- se = !((wx + width - 1) & 1) == !((wy + height - 1) & 1);
+ int wx = x + tree->drawableXOrigin;
+ int wy = y + tree->drawableYOrigin;
+ int w = !(open & 0x01);
+ int n = !(open & 0x02);
+ int e = !(open & 0x04);
+ int s = !(open & 0x08);
+ int nw, ne, sw, se;
+ int i;
+ XGCValues gcValues;
+ unsigned long gcMask;
+ GC gc;
+
+ /* Dots on even pixels only */
+ nw = !(wx & 1) == !(wy & 1);
+ ne = !((wx + width - 1) & 1) == !(wy & 1);
+ sw = !(wx & 1) == !((wy + height - 1) & 1);
+ se = !((wx + width - 1) & 1) == !((wy + height - 1) & 1);
#if defined(MAC_TCL) || defined(MAC_OSX_TK)
- gcValues.function = GXxor;
+ gcValues.function = GXxor;
#else
- gcValues.function = GXinvert;
+ gcValues.function = GXinvert;
#endif
- gcMask = GCFunction;
- gc = Tk_GetGC(tree->tkwin, gcMask, &gcValues);
+ gcMask = GCFunction;
+ gc = Tk_GetGC(tree->tkwin, gcMask, &gcValues);
- if (w) /* left */
+ if (w) /* left */
+ {
+ for (i = !nw; i < height; i += 2)
{
- for (i = !nw; i < height; i += 2)
- {
- XDrawPoint(tree->display, drawable, gc, x, y + i);
- }
+ XDrawPoint(tree->display, drawable, gc, x, y + i);
}
- if (n) /* top */
+ }
+ if (n) /* top */
+ {
+ for (i = nw ? w * 2 : 1; i < width; i += 2)
{
- for (i = nw ? w * 2 : 1; i < width; i += 2)
- {
- XDrawPoint(tree->display, drawable, gc, x + i, y);
- }
+ XDrawPoint(tree->display, drawable, gc, x + i, y);
}
- if (e) /* right */
+ }
+ if (e) /* right */
+ {
+ for (i = ne ? n * 2 : 1; i < height; i += 2)
{
- for (i = ne ? n * 2 : 1; i < height; i += 2)
- {
- XDrawPoint(tree->display, drawable, gc, x + width - 1, y + i);
- }
+ XDrawPoint(tree->display, drawable, gc, x + width - 1, y + i);
}
- if (s) /* bottom */
+ }
+ if (s) /* bottom */
+ {
+ for (i = sw ? w * 2 : 1; i < width - (se && e); i += 2)
{
- for (i = sw ? w * 2 : 1; i < width - (se && e); i += 2)
- {
- XDrawPoint(tree->display, drawable, gc, x + i, y + height - 1);
- }
+ XDrawPoint(tree->display, drawable, gc, x + i, y + height - 1);
}
+ }
- Tk_FreeGC(tree->display, gc);
+ Tk_FreeGC(tree->display, gc);
#endif
}
void DotRect(TreeCtrl *tree, Drawable drawable, int x, int y, int width, int height)
{
- DrawActiveOutline(tree, drawable, x, y, width, height, 0);
+ DrawActiveOutline(tree, drawable, x, y, width, height, 0);
}
struct DotStatePriv
{
- TreeCtrl *tree;
- Drawable drawable;
+ TreeCtrl *tree;
+ Drawable drawable;
#ifdef WIN32
- HDC dc;
- TkWinDCState dcState;
- HRGN rgn;
+ HDC dc;
+ TkWinDCState dcState;
+ HRGN rgn;
#elif defined(MAC_OSX_TK)
- CGrafPtr saveWorld;
- GDHandle saveDevice;
+ CGrafPtr saveWorld;
+ GDHandle saveDevice;
#else
- GC gc;
- TkRegion rgn;
+ GC gc;
+ TkRegion rgn;
#endif
};
void DotRect_Setup(TreeCtrl *tree, Drawable drawable, DotState *p)
{
- struct DotStatePriv *dotState = (struct DotStatePriv *) p;
+ struct DotStatePriv *dotState = (struct DotStatePriv *) p;
#ifdef WIN32
#elif defined(MAC_OSX_TK)
- GWorldPtr destPort;
+ GWorldPtr destPort;
#else
- XGCValues gcValues;
- unsigned long mask;
- XRectangle xrect;
+ XGCValues gcValues;
+ unsigned long mask;
+ XRectangle xrect;
#endif
- if (sizeof(*dotState) > sizeof(*p))
- panic("DotRect_Setup: DotState hack is too small");
+ if (sizeof(*dotState) > sizeof(*p))
+ panic("DotRect_Setup: DotState hack is too small");
- dotState->tree = tree;
- dotState->drawable = drawable;
+ dotState->tree = tree;
+ dotState->drawable = drawable;
#ifdef WIN32
- dotState->dc = TkWinGetDrawableDC(tree->display, drawable, &dotState->dcState);
-
- /* XOR drawing */
- SetROP2(dotState->dc, R2_NOT);
-
- /* Keep drawing inside the contentbox */
- dotState->rgn = CreateRectRgn(
- tree->inset,
- tree->inset + Tree_HeaderHeight(tree),
- Tk_Width(tree->tkwin) - tree->inset,
- Tk_Height(tree->tkwin) - tree->inset);
- SelectClipRgn(dotState->dc, dotState->rgn);
+ dotState->dc = TkWinGetDrawableDC(tree->display, drawable, &dotState->dcState);
+
+ /* XOR drawing */
+ SetROP2(dotState->dc, R2_NOT);
+
+ /* Keep drawing inside the contentbox */
+ dotState->rgn = CreateRectRgn(
+ tree->inset,
+ tree->inset + Tree_HeaderHeight(tree),
+ Tk_Width(tree->tkwin) - tree->inset,
+ Tk_Height(tree->tkwin) - tree->inset);
+ SelectClipRgn(dotState->dc, dotState->rgn);
#elif defined(MAC_OSX_TK)
- tree->display->request++;
- destPort = TkMacOSXGetDrawablePort(drawable);
- GetGWorld(&dotState->saveWorld, &dotState->saveDevice);
- SetGWorld(destPort, NULL);
- TkMacOSXSetUpClippingRgn(drawable);
- PenNormal();
- PenMode(patXor);
- ShowPen();
- /* FIXME: clipping region */
+ tree->display->request++;
+ destPort = TkMacOSXGetDrawablePort(drawable);
+ GetGWorld(&dotState->saveWorld, &dotState->saveDevice);
+ SetGWorld(destPort, NULL);
+ TkMacOSXSetUpClippingRgn(drawable);
+ PenNormal();
+ PenMode(patXor);
+ ShowPen();
+ /* FIXME: clipping region */
#else
- gcValues.line_style = LineOnOffDash;
- gcValues.line_width = 1;
- gcValues.dash_offset = 0;
- gcValues.dashes = 1;
+ gcValues.line_style = LineOnOffDash;
+ gcValues.line_width = 1;
+ gcValues.dash_offset = 0;
+ gcValues.dashes = 1;
#if defined(MAC_TCL)
- gcValues.function = GXxor;
+ gcValues.function = GXxor;
#else
- gcValues.function = GXinvert;
+ gcValues.function = GXinvert;
#endif
- mask = GCLineWidth | GCLineStyle | GCDashList | GCDashOffset | GCFunction;
- dotState->gc = Tk_GetGC(tree->tkwin, mask, &gcValues);
-
- /* Keep drawing inside the contentbox */
- dotState->rgn = TkCreateRegion();
- xrect.x = tree->inset;
- xrect.y = tree->inset + Tree_HeaderHeight(tree);
- xrect.width = Tk_Width(tree->tkwin) - tree->inset - xrect.x;
- xrect.height = Tk_Height(tree->tkwin) - tree->inset - xrect.y;
- TkUnionRectWithRegion(&xrect, dotState->rgn, dotState->rgn);
- TkSetRegion(tree->display, dotState->gc, dotState->rgn);
+ mask = GCLineWidth | GCLineStyle | GCDashList | GCDashOffset | GCFunction;
+ dotState->gc = Tk_GetGC(tree->tkwin, mask, &gcValues);
+
+ /* Keep drawing inside the contentbox */
+ dotState->rgn = TkCreateRegion();
+ xrect.x = tree->inset;
+ xrect.y = tree->inset + Tree_HeaderHeight(tree);
+ xrect.width = Tk_Width(tree->tkwin) - tree->inset - xrect.x;
+ xrect.height = Tk_Height(tree->tkwin) - tree->inset - xrect.y;
+ TkUnionRectWithRegion(&xrect, dotState->rgn, dotState->rgn);
+ TkSetRegion(tree->display, dotState->gc, dotState->rgn);
#endif
}
void DotRect_Draw(DotState *p, int x, int y, int width, int height)
{
- struct DotStatePriv *dotState = (struct DotStatePriv *) p;
+ struct DotStatePriv *dotState = (struct DotStatePriv *) p;
#ifdef WIN32
#if 1
- RECT rect;
+ RECT rect;
- rect.left = x;
- rect.right = x + width;
- rect.top = y;
- rect.bottom = y + height;
- DrawFocusRect(dotState->dc, &rect);
+ rect.left = x;
+ rect.right = x + width;
+ rect.top = y;
+ rect.bottom = y + height;
+ DrawFocusRect(dotState->dc, &rect);
#else
- HDC dc = dotState->dc;
- int i;
- int wx = x + dotState->tree->drawableXOrigin;
- int wy = y + dotState->tree->drawableYOrigin;
- int nw, ne, sw, se;
-
- /* Dots on even pixels only */
- nw = !(wx & 1) == !(wy & 1);
- ne = !((wx + width - 1) & 1) == !(wy & 1);
- sw = !(wx & 1) == !((wy + height - 1) & 1);
- se = !((wx + width - 1) & 1) == !((wy + height - 1) & 1);
-
- for (i = !nw; i < height; i += 2)
- {
- MoveToEx(dc, x, y + i, NULL);
- LineTo(dc, x + 1, y + i);
- }
- for (i = nw ? 2 : 1; i < width; i += 2)
- {
- MoveToEx(dc, x + i, y, NULL);
- LineTo(dc, x + i + 1, y);
- }
- for (i = ne ? 2 : 1; i < height; i += 2)
- {
- MoveToEx(dc, x + width - 1, y + i, NULL);
- LineTo(dc, x + width, y + i);
- }
- for (i = sw ? 2 : 1; i < width - se; i += 2)
- {
- MoveToEx(dc, x + i, y + height - 1, NULL);
- LineTo(dc, x + i + 1, y + height - 1);
- }
+ HDC dc = dotState->dc;
+ int i;
+ int wx = x + dotState->tree->drawableXOrigin;
+ int wy = y + dotState->tree->drawableYOrigin;
+ int nw, ne, sw, se;
+
+ /* Dots on even pixels only */
+ nw = !(wx & 1) == !(wy & 1);
+ ne = !((wx + width - 1) & 1) == !(wy & 1);
+ sw = !(wx & 1) == !((wy + height - 1) & 1);
+ se = !((wx + width - 1) & 1) == !((wy + height - 1) & 1);
+
+ for (i = !nw; i < height; i += 2)
+ {
+ MoveToEx(dc, x, y + i, NULL);
+ LineTo(dc, x + 1, y + i);
+ }
+ for (i = nw ? 2 : 1; i < width; i += 2)
+ {
+ MoveToEx(dc, x + i, y, NULL);
+ LineTo(dc, x + i + 1, y);
+ }
+ for (i = ne ? 2 : 1; i < height; i += 2)
+ {
+ MoveToEx(dc, x + width - 1, y + i, NULL);
+ LineTo(dc, x + width, y + i);
+ }
+ for (i = sw ? 2 : 1; i < width - se; i += 2)
+ {
+ MoveToEx(dc, x + i, y + height - 1, NULL);
+ LineTo(dc, x + i + 1, y + height - 1);
+ }
#endif
#elif defined(MAC_OSX_TK)
MacDrawable *macWin = (MacDrawable *) dotState->drawable;
- int i;
- int wx = x + dotState->tree->drawableXOrigin;
- int wy = y + dotState->tree->drawableYOrigin;
- int nw, ne, sw, se;
-
- /* Dots on even pixels only */
- nw = !(wx & 1) == !(wy & 1);
- ne = !((wx + width - 1) & 1) == !(wy & 1);
- sw = !(wx & 1) == !((wy + height - 1) & 1);
- se = !((wx + width - 1) & 1) == !((wy + height - 1) & 1);
-
- x += macWin->xOff;
- y += macWin->yOff;
-
- for (i = !nw; i < height; i += 2)
- {
- MoveTo(x, y + i);
- LineTo(x, y + i);
- }
- for (i = nw ? 2 : 1; i < width; i += 2)
- {
- MoveTo(x + i, y);
- LineTo(x + i, y);
- }
- for (i = ne ? 2 : 1; i < height; i += 2)
- {
- MoveTo(x + width, y + i);
- LineTo(x + width, y + i);
- }
- for (i = sw ? 2 : 1; i < width - se; i += 2)
- {
- MoveTo(x + i, y + height - 1);
- LineTo(x + i, y + height - 1);
- }
+ int i;
+ int wx = x + dotState->tree->drawableXOrigin;
+ int wy = y + dotState->tree->drawableYOrigin;
+ int nw, ne, sw, se;
+
+ /* Dots on even pixels only */
+ nw = !(wx & 1) == !(wy & 1);
+ ne = !((wx + width - 1) & 1) == !(wy & 1);
+ sw = !(wx & 1) == !((wy + height - 1) & 1);
+ se = !((wx + width - 1) & 1) == !((wy + height - 1) & 1);
+
+ x += macWin->xOff;
+ y += macWin->yOff;
+
+ for (i = !nw; i < height; i += 2)
+ {
+ MoveTo(x, y + i);
+ LineTo(x, y + i);
+ }
+ for (i = nw ? 2 : 1; i < width; i += 2)
+ {
+ MoveTo(x + i, y);
+ LineTo(x + i, y);
+ }
+ for (i = ne ? 2 : 1; i < height; i += 2)
+ {
+ MoveTo(x + width, y + i);
+ LineTo(x + width, y + i);
+ }
+ for (i = sw ? 2 : 1; i < width - se; i += 2)
+ {
+ MoveTo(x + i, y + height - 1);
+ LineTo(x + i, y + height - 1);
+ }
#else /* MAC_OSX_TK */
- XDrawRectangle(dotState->tree->display, dotState->drawable, dotState->gc,
- x, y, width - 1, height - 1);
+ XDrawRectangle(dotState->tree->display, dotState->drawable, dotState->gc,
+ x, y, width - 1, height - 1);
#endif
}
void DotRect_Restore(DotState *p)
{
- struct DotStatePriv *dotState = (struct DotStatePriv *) p;
+ struct DotStatePriv *dotState = (struct DotStatePriv *) p;
#ifdef WIN32
- SelectClipRgn(dotState->dc, NULL);
- DeleteObject(dotState->rgn);
- TkWinReleaseDrawableDC(dotState->drawable, dotState->dc, &dotState->dcState);
+ SelectClipRgn(dotState->dc, NULL);
+ DeleteObject(dotState->rgn);
+ TkWinReleaseDrawableDC(dotState->drawable, dotState->dc, &dotState->dcState);
#elif defined(MAC_OSX_TK)
- HidePen();
- /* FIXME: clipping region */
- SetGWorld(dotState->saveWorld, dotState->saveDevice);
+ HidePen();
+ /* FIXME: clipping region */
+ SetGWorld(dotState->saveWorld, dotState->saveDevice);
#else
- XSetClipMask(dotState->tree->display, dotState->gc, None);
- Tk_FreeGC(dotState->tree->display, dotState->gc);
+ XSetClipMask(dotState->tree->display, dotState->gc, None);
+ Tk_FreeGC(dotState->tree->display, dotState->gc);
#endif
}
#ifdef MAC_OSX_TK
void DrawXORLine(Display *display, Drawable drawable, int x1, int y1,
- int x2, int y2)
+ int x2, int y2)
{
MacDrawable *macWin = (MacDrawable *) drawable;
- CGrafPtr saveWorld;
- GDHandle saveDevice;
- GWorldPtr destPort;
-
- destPort = TkMacOSXGetDrawablePort(drawable);
- display->request++;
- GetGWorld(&saveWorld, &saveDevice);
- SetGWorld(destPort, NULL);
- TkMacOSXSetUpClippingRgn(drawable);
+ CGrafPtr saveWorld;
+ GDHandle saveDevice;
+ GWorldPtr destPort;
+
+ destPort = TkMacOSXGetDrawablePort(drawable);
+ display->request++;
+ GetGWorld(&saveWorld, &saveDevice);
+ SetGWorld(destPort, NULL);
+ TkMacOSXSetUpClippingRgn(drawable);
#if 1
- PenNormal();
+ PenNormal();
#else
- TkMacOSXSetUpGraphicsPort(gc, destPort);
+ TkMacOSXSetUpGraphicsPort(gc, destPort);
#endif
- PenMode(patXor);
- ShowPen();
- MoveTo(macWin->xOff + x1, macWin->yOff + y1);
- LineTo(macWin->xOff + x2, macWin->yOff + y2);
- HidePen();
- SetGWorld(saveWorld, saveDevice);
+ PenMode(patXor);
+ ShowPen();
+ MoveTo(macWin->xOff + x1, macWin->yOff + y1);
+ LineTo(macWin->xOff + x2, macWin->yOff + y2);
+ HidePen();
+ SetGWorld(saveWorld, saveDevice);
}
#endif
void Tk_FillRegion(Display *display, Drawable drawable, GC gc, TkRegion rgn)
{
#ifdef WIN32
- HDC dc;
- TkWinDCState dcState;
- HBRUSH brush;
-
- dc = TkWinGetDrawableDC(display, drawable, &dcState);
- SetROP2(dc, R2_COPYPEN);
- brush = CreateSolidBrush(gc->foreground);
- FillRgn(dc, (HRGN) rgn, brush);
- DeleteObject(brush);
- TkWinReleaseDrawableDC(drawable, dc, &dcState);
+ HDC dc;
+ TkWinDCState dcState;
+ HBRUSH brush;
+
+ dc = TkWinGetDrawableDC(display, drawable, &dcState);
+ SetROP2(dc, R2_COPYPEN);
+ brush = CreateSolidBrush(gc->foreground);
+ FillRgn(dc, (HRGN) rgn, brush);
+ DeleteObject(brush);
+ TkWinReleaseDrawableDC(drawable, dc, &dcState);
#elif defined(MAC_OSX_TK)
MacDrawable *macWin = (MacDrawable *) drawable;
- CGrafPtr saveWorld;
- GDHandle saveDevice;
- GWorldPtr destPort;
- RGBColor macColor;
-
- destPort = TkMacOSXGetDrawablePort(drawable);
- if (gPenPat == NULL)
- gPenPat = NewPixPat();
- if (TkSetMacColor(gc->foreground, &macColor) == true)
- MakeRGBPat(gPenPat, &macColor);
- display->request++;
- GetGWorld(&saveWorld, &saveDevice);
- SetGWorld(destPort, NULL);
- TkMacOSXSetUpClippingRgn(drawable);
- TkMacOSXSetUpGraphicsPort(gc, destPort);
- OffsetRgn((RgnHandle) rgn, macWin->xOff, macWin->yOff);
- ShowPen(); /* seemed to work without this */
- FillCRgn((RgnHandle) rgn, gPenPat);
- HidePen(); /* seemed to work without this */
- OffsetRgn((RgnHandle) rgn, -macWin->xOff, -macWin->yOff);
- SetGWorld(saveWorld, saveDevice);
+ CGrafPtr saveWorld;
+ GDHandle saveDevice;
+ GWorldPtr destPort;
+ RGBColor macColor;
+
+ destPort = TkMacOSXGetDrawablePort(drawable);
+ if (gPenPat == NULL)
+ gPenPat = NewPixPat();
+ if (TkSetMacColor(gc->foreground, &macColor) == true)
+ MakeRGBPat(gPenPat, &macColor);
+ display->request++;
+ GetGWorld(&saveWorld, &saveDevice);
+ SetGWorld(destPort, NULL);
+ TkMacOSXSetUpClippingRgn(drawable);
+ TkMacOSXSetUpGraphicsPort(gc, destPort);
+ OffsetRgn((RgnHandle) rgn, macWin->xOff, macWin->yOff);
+ ShowPen(); /* seemed to work without this */
+ FillCRgn((RgnHandle) rgn, gPenPat);
+ HidePen(); /* seemed to work without this */
+ OffsetRgn((RgnHandle) rgn, -macWin->xOff, -macWin->yOff);
+ SetGWorld(saveWorld, saveDevice);
#else
- XRectangle box;
+ XRectangle box;
- TkClipBox(rgn, &box);
- TkSetRegion(display, gc, rgn);
- XFillRectangle(display, drawable, gc, box.x, box.y, box.width, box.height);
- XSetClipMask(display, gc, None);
+ TkClipBox(rgn, &box);
+ TkSetRegion(display, gc, rgn);
+ XFillRectangle(display, drawable, gc, box.x, box.y, box.width, box.height);
+ XSetClipMask(display, gc, None);
#endif
}
void Tk_OffsetRegion(TkRegion region, int xOffset, int yOffset)
{
#ifdef WIN32
- OffsetRgn((HRGN) region, xOffset, yOffset);
+ OffsetRgn((HRGN) region, xOffset, yOffset);
#elif defined(MAC_TCL) || defined(MAC_OSX_TK)
- OffsetRgn((RgnHandle) region, (short) xOffset, (short) yOffset);
+ OffsetRgn((RgnHandle) region, (short) xOffset, (short) yOffset);
#else
- XOffsetRegion((Region) region, xOffset, yOffset);
+ XOffsetRegion((Region) region, xOffset, yOffset);
#endif
}
int Tree_ScrollWindow(TreeCtrl *tree, GC gc, int x, int y,
- int width, int height, int dx, int dy, TkRegion damageRgn)
+ int width, int height, int dx, int dy, TkRegion damageRgn)
{
- int result = TkScrollWindow(tree->tkwin, gc, x, y, width, height, dx, dy,
- damageRgn);
+ int result = TkScrollWindow(tree->tkwin, gc, x, y, width, height, dx, dy,
+ damageRgn);
#if defined(MAC_TCL) || defined(MAC_OSX_TK)
- {
- MacDrawable *macWin = (MacDrawable *) Tk_WindowId(tree->tkwin);
- /* BUG IN TK? */
- OffsetRgn((RgnHandle) damageRgn, -macWin->xOff, -macWin->yOff);
- }
+ {
+ MacDrawable *macWin = (MacDrawable *) Tk_WindowId(tree->tkwin);
+ /* BUG IN TK? */
+ OffsetRgn((RgnHandle) damageRgn, -macWin->xOff, -macWin->yOff);
+ }
#endif
- return result;
+ return result;
}
void UnsetClipMask(TreeCtrl *tree, Drawable drawable, GC gc)
{
- XSetClipMask(tree->display, gc, None);
+ XSetClipMask(tree->display, gc, None);
#ifdef WIN32
- /* Tk_DrawChars does not clear the clip region */
- if (drawable == Tk_WindowId(tree->tkwin)) {
- HDC dc;
- TkWinDCState dcState;
-
- dc = TkWinGetDrawableDC(tree->display, drawable, &dcState);
- SelectClipRgn(dc, NULL);
- TkWinReleaseDrawableDC(drawable, dc, &dcState);
- }
+ /* Tk_DrawChars does not clear the clip region */
+ if (drawable == Tk_WindowId(tree->tkwin)) {
+ HDC dc;
+ TkWinDCState dcState;
+
+ dc = TkWinGetDrawableDC(tree->display, drawable, &dcState);
+ SelectClipRgn(dc, NULL);
+ TkWinReleaseDrawableDC(drawable, dc, &dcState);
+ }
#endif
}
void Tree_DrawBitmapWithGC(TreeCtrl *tree, Pixmap bitmap, Drawable drawable,
- GC gc, int src_x, int src_y, int width, int height, int dest_x, int dest_y)
+ GC gc, int src_x, int src_y, int width, int height, int dest_x, int dest_y)
{
#ifdef WIN32
- TkpClipMask *clipPtr = (TkpClipMask *) gc->clip_mask;
+ TkpClipMask *clipPtr = (TkpClipMask *) gc->clip_mask;
#endif
- XSetClipOrigin(tree->display, gc, dest_x, dest_y);
+ XSetClipOrigin(tree->display, gc, dest_x, dest_y);
#ifdef WIN32
- /*
- * It seems as though the device context is not set up properly
- * when drawing a transparent bitmap into a window. Normally Tk draws
- * into an offscreen pixmap which gets a temporary device context.
- * This fixes a bug with -doublebuffer none in the demo "Bitmaps".
- */
- if (drawable == Tk_WindowId(tree->tkwin)) {
- if ((clipPtr != NULL) &&
- (clipPtr->type == TKP_CLIP_PIXMAP) &&
- (clipPtr->value.pixmap == bitmap)) {
- HDC dc;
- TkWinDCState dcState;
-
- dc = TkWinGetDrawableDC(tree->display, drawable, &dcState);
- SetTextColor(dc, RGB(0,0,0));
- SetBkColor(dc, RGB(255,255,255));
- TkWinReleaseDrawableDC(drawable, dc, &dcState);
- }
+ /*
+ * It seems as though the device context is not set up properly
+ * when drawing a transparent bitmap into a window. Normally Tk draws
+ * into an offscreen pixmap which gets a temporary device context.
+ * This fixes a bug with -doublebuffer none in the demo "Bitmaps".
+ */
+ if (drawable == Tk_WindowId(tree->tkwin)) {
+ if ((clipPtr != NULL) &&
+ (clipPtr->type == TKP_CLIP_PIXMAP) &&
+ (clipPtr->value.pixmap == bitmap)) {
+ HDC dc;
+ TkWinDCState dcState;
+
+ dc = TkWinGetDrawableDC(tree->display, drawable, &dcState);
+ SetTextColor(dc, RGB(0,0,0));
+ SetBkColor(dc, RGB(255,255,255));
+ TkWinReleaseDrawableDC(drawable, dc, &dcState);
}
+ }
#endif
- XCopyPlane(tree->display, bitmap, drawable, gc,
- src_x, src_y, (unsigned int) width, (unsigned int) height,
- dest_x, dest_y, 1);
- XSetClipOrigin(tree->display, gc, 0, 0);
+ XCopyPlane(tree->display, bitmap, drawable, gc,
+ src_x, src_y, (unsigned int) width, (unsigned int) height,
+ dest_x, dest_y, 1);
+ XSetClipOrigin(tree->display, gc, 0, 0);
}
void Tree_DrawBitmap(TreeCtrl *tree, Pixmap bitmap, Drawable drawable,
- XColor *fg, XColor *bg,
- int src_x, int src_y, int width, int height, int dest_x, int dest_y)
+ XColor *fg, XColor *bg,
+ int src_x, int src_y, int width, int height, int dest_x, int dest_y)
{
- XGCValues gcValues;
- GC gc;
- unsigned long mask = 0;
+ XGCValues gcValues;
+ GC gc;
+ unsigned long mask = 0;
- if (fg != NULL) {
- gcValues.foreground = fg->pixel;
- mask |= GCForeground;
- }
- if (bg != NULL) {
- gcValues.background = bg->pixel;
- mask |= GCBackground;
- } else {
- gcValues.clip_mask = bitmap;
- mask |= GCClipMask;
- }
- gcValues.graphics_exposures = False;
- mask |= GCGraphicsExposures;
- gc = Tk_GetGC(tree->tkwin, mask, &gcValues);
- Tree_DrawBitmapWithGC(tree, bitmap, drawable, gc,
- src_x, src_y, width, height, dest_x, dest_y);
- Tk_FreeGC(tree->display, gc);
+ if (fg != NULL) {
+ gcValues.foreground = fg->pixel;
+ mask |= GCForeground;
+ }
+ if (bg != NULL) {
+ gcValues.background = bg->pixel;
+ mask |= GCBackground;
+ } else {
+ gcValues.clip_mask = bitmap;
+ mask |= GCClipMask;
+ }
+ gcValues.graphics_exposures = False;
+ mask |= GCGraphicsExposures;
+ gc = Tk_GetGC(tree->tkwin, mask, &gcValues);
+ Tree_DrawBitmapWithGC(tree, bitmap, drawable, gc,
+ src_x, src_y, width, height, dest_x, dest_y);
+ Tk_FreeGC(tree->display, gc);
}
/*
@@ -691,11 +691,11 @@ void Tree_DrawBitmap(TreeCtrl *tree, Pixmap bitmap, Drawable drawable,
*/
#if (TK_MAJOR_VERSION == 8) && (TK_MINOR_VERSION < 5)
#define TK_PHOTOPUTBLOCK(interp, hdl, blk, x, y, w, h, cr) \
- Tk_PhotoPutBlock(hdl, blk, x, y, w, h, cr)
+ Tk_PhotoPutBlock(hdl, blk, x, y, w, h, cr)
#define TK_PHOTOPUTZOOMEDBLOCK(interp, hdl, blk, x, y, w, h, \
- zx, zy, sx, sy, cr) \
- Tk_PhotoPutZoomedBlock(hdl, blk, x, y, w, h, \
- zx, zy, sx, sy, cr)
+ zx, zy, sx, sy, cr) \
+ Tk_PhotoPutZoomedBlock(hdl, blk, x, y, w, h, \
+ zx, zy, sx, sy, cr)
#else
#define TK_PHOTOPUTBLOCK Tk_PhotoPutBlock
#define TK_PHOTOPUTZOOMEDBLOCK Tk_PhotoPutZoomedBlock
@@ -863,49 +863,49 @@ void XImage2Photo(Tcl_Interp *interp, Tk_PhotoHandle photoH, XImage *ximage, int
typedef struct LayoutChunk
{
- CONST char *start; /* Pointer to simple string to be displayed.
- * * This is a pointer into the TkTextLayout's
- * * string. */
- int numBytes; /* The number of bytes in this chunk. */
- int numChars; /* The number of characters in this chunk. */
- int numDisplayChars; /* The number of characters to display when
- * * this chunk is displayed. Can be less than
- * * numChars if extra space characters were
- * * absorbed by the end of the chunk. This
- * * will be < 0 if this is a chunk that is
- * * holding a tab or newline. */
- int x, y; /* The origin of the first character in this
+ CONST char *start; /* Pointer to simple string to be displayed.
+ * * This is a pointer into the TkTextLayout's
+ * * string. */
+ int numBytes; /* The number of bytes in this chunk. */
+ int numChars; /* The number of characters in this chunk. */
+ int numDisplayChars; /* The number of characters to display when
+ * * this chunk is displayed. Can be less than
+ * * numChars if extra space characters were
+ * * absorbed by the end of the chunk. This
+ * * will be < 0 if this is a chunk that is
+ * * holding a tab or newline. */
+ int x, y; /* The origin of the first character in this
* * chunk with respect to the upper-left hand
* * corner of the TextLayout. */
- int totalWidth; /* Width in pixels of this chunk. Used
- * * when hit testing the invisible spaces at
- * * the end of a chunk. */
- int displayWidth; /* Width in pixels of the displayable
- * * characters in this chunk. Can be less than
- * * width if extra space characters were
- * * absorbed by the end of the chunk. */
- int ellipsis; /* TRUE if adding "..." */
+ int totalWidth; /* Width in pixels of this chunk. Used
+ * * when hit testing the invisible spaces at
+ * * the end of a chunk. */
+ int displayWidth; /* Width in pixels of the displayable
+ * * characters in this chunk. Can be less than
+ * * width if extra space characters were
+ * * absorbed by the end of the chunk. */
+ int ellipsis; /* TRUE if adding "..." */
} LayoutChunk;
typedef struct LayoutInfo
{
- Tk_Font tkfont; /* The font used when laying out the text. */
- CONST char *string; /* The string that was layed out. */
- int numLines; /* Number of lines */
- int width; /* The maximum width of all lines in the
+ Tk_Font tkfont; /* The font used when laying out the text. */
+ CONST char *string; /* The string that was layed out. */
+ int numLines; /* Number of lines */
+ int width; /* The maximum width of all lines in the
* * text layout. */
- int height;
- int numChunks; /* Number of chunks actually used in
- * * following array. */
- int totalWidth;
+ int height;
+ int numChunks; /* Number of chunks actually used in
+ * * following array. */
+ int totalWidth;
#define TEXTLAYOUT_ALLOCHAX
#ifdef TEXTLAYOUT_ALLOCHAX
- int maxChunks;
- struct LayoutInfo *nextFree;
+ int maxChunks;
+ struct LayoutInfo *nextFree;
#endif
- LayoutChunk chunks[1]; /* Array of chunks. The actual size will
- * * be maxChunks. THIS FIELD MUST BE THE LAST
- * * IN THE STRUCTURE. */
+ LayoutChunk chunks[1]; /* Array of chunks. The actual size will
+ * * be maxChunks. THIS FIELD MUST BE THE LAST
+ * * IN THE STRUCTURE. */
} LayoutInfo;
#ifdef TEXTLAYOUT_ALLOCHAX
@@ -918,506 +918,506 @@ static LayoutChunk *NewChunk(LayoutInfo **layoutPtrPtr,
#else
static LayoutChunk *NewChunk(LayoutInfo **layoutPtrPtr, int *maxPtr,
#endif
- CONST char *start, int numBytes, int curX, int newX, int y)
+ CONST char *start, int numBytes, int curX, int newX, int y)
{
- LayoutInfo *layoutPtr;
- LayoutChunk *chunkPtr;
+ LayoutInfo *layoutPtr;
+ LayoutChunk *chunkPtr;
#ifdef TEXTLAYOUT_ALLOCHAX
- int numChars;
+ int numChars;
#else
- int maxChunks, numChars;
+ int maxChunks, numChars;
#endif
- size_t s;
+ size_t s;
- layoutPtr = *layoutPtrPtr;
+ layoutPtr = *layoutPtrPtr;
#ifdef TEXTLAYOUT_ALLOCHAX
- if (layoutPtr->numChunks == layoutPtr->maxChunks)
- {
- layoutPtr->maxChunks *= 2;
- s = sizeof(LayoutInfo) + ((layoutPtr->maxChunks - 1) * sizeof(LayoutChunk));
- layoutPtr = (LayoutInfo *) ckrealloc((char *) layoutPtr, s);
+ if (layoutPtr->numChunks == layoutPtr->maxChunks)
+ {
+ layoutPtr->maxChunks *= 2;
+ s = sizeof(LayoutInfo) + ((layoutPtr->maxChunks - 1) * sizeof(LayoutChunk));
+ layoutPtr = (LayoutInfo *) ckrealloc((char *) layoutPtr, s);
- *layoutPtrPtr = layoutPtr;
- }
+ *layoutPtrPtr = layoutPtr;
+ }
#else
- maxChunks = *maxPtr;
- if (layoutPtr->numChunks == maxChunks)
- {
- maxChunks *= 2;
- s = sizeof(LayoutInfo) + ((maxChunks - 1) * sizeof(LayoutChunk));
- layoutPtr = (LayoutInfo *) ckrealloc((char *) layoutPtr, s);
-
- *layoutPtrPtr = layoutPtr;
- *maxPtr = maxChunks;
- }
+ maxChunks = *maxPtr;
+ if (layoutPtr->numChunks == maxChunks)
+ {
+ maxChunks *= 2;
+ s = sizeof(LayoutInfo) + ((maxChunks - 1) * sizeof(LayoutChunk));
+ layoutPtr = (LayoutInfo *) ckrealloc((char *) layoutPtr, s);
+
+ *layoutPtrPtr = layoutPtr;
+ *maxPtr = maxChunks;
+ }
#endif
- numChars = Tcl_NumUtfChars(start, numBytes);
- chunkPtr = &layoutPtr->chunks[layoutPtr->numChunks];
- chunkPtr->start = start;
- chunkPtr->numBytes = numBytes;
- chunkPtr->numChars = numChars;
- chunkPtr->numDisplayChars = numChars;
- chunkPtr->x = curX;
- chunkPtr->y = y;
- chunkPtr->totalWidth = newX - curX;
- chunkPtr->displayWidth = newX - curX;
- chunkPtr->ellipsis = FALSE;
- layoutPtr->numChunks++;
-
- return chunkPtr;
+ numChars = Tcl_NumUtfChars(start, numBytes);
+ chunkPtr = &layoutPtr->chunks[layoutPtr->numChunks];
+ chunkPtr->start = start;
+ chunkPtr->numBytes = numBytes;
+ chunkPtr->numChars = numChars;
+ chunkPtr->numDisplayChars = numChars;
+ chunkPtr->x = curX;
+ chunkPtr->y = y;
+ chunkPtr->totalWidth = newX - curX;
+ chunkPtr->displayWidth = newX - curX;
+ chunkPtr->ellipsis = FALSE;
+ layoutPtr->numChunks++;
+
+ return chunkPtr;
}
TextLayout TextLayout_Compute(
- Tk_Font tkfont, /* Font that will be used to display text. */
- CONST char *string, /* String whose dimensions are to be
- ** computed. */
- int numChars, /* Number of characters to consider from
- ** string, or < 0 for strlen(). */
- int wrapLength, /* Longest permissible line length, in
- ** pixels. <= 0 means no automatic wrapping:
- ** just let lines get as long as needed. */
- Tk_Justify justify, /* How to justify lines. */
- int maxLines,
- int flags /* Flag bits OR-ed together.
- ** TK_IGNORE_TABS means that tab characters
- ** should not be expanded. TK_IGNORE_NEWLINES
- ** means that newline characters should not
- ** cause a line break. */
- )
-{
- CONST char *start, *end, *special;
- int n, y, bytesThisChunk, maxChunks;
- int baseline, height, curX, newX, maxWidth;
- LayoutInfo *layoutPtr;
- LayoutChunk *chunkPtr;
- Tk_FontMetrics fm;
- Tcl_DString lineBuffer;
- int *lineLengths;
- int curLine;
- int tabWidth = 20; /* FIXME */
-
- Tcl_DStringInit(&lineBuffer);
-
- Tk_GetFontMetrics(tkfont, &fm);
- height = fm.ascent + fm.descent;
-
- if (numChars < 0)
- numChars = Tcl_NumUtfChars(string, -1);
- if (wrapLength == 0)
- wrapLength = -1;
+ Tk_Font tkfont, /* Font that will be used to display text. */
+ CONST char *string, /* String whose dimensions are to be
+ ** computed. */
+ int numChars, /* Number of characters to consider from
+ ** string, or < 0 for strlen(). */
+ int wrapLength, /* Longest permissible line length, in
+ ** pixels. <= 0 means no automatic wrapping:
+ ** just let lines get as long as needed. */
+ Tk_Justify justify, /* How to justify lines. */
+ int maxLines,
+ int flags /* Flag bits OR-ed together.
+ ** TK_IGNORE_TABS means that tab characters
+ ** should not be expanded. TK_IGNORE_NEWLINES
+ ** means that newline characters should not
+ ** cause a line break. */
+ )
+{
+ CONST char *start, *end, *special;
+ int n, y, bytesThisChunk, maxChunks;
+ int baseline, height, curX, newX, maxWidth;
+ LayoutInfo *layoutPtr;
+ LayoutChunk *chunkPtr;
+ Tk_FontMetrics fm;
+ Tcl_DString lineBuffer;
+ int *lineLengths;
+ int curLine;
+ int tabWidth = 20; /* FIXME */
+
+ Tcl_DStringInit(&lineBuffer);
+
+ Tk_GetFontMetrics(tkfont, &fm);
+ height = fm.ascent + fm.descent;
+
+ if (numChars < 0)
+ numChars = Tcl_NumUtfChars(string, -1);
+ if (wrapLength == 0)
+ wrapLength = -1;
#ifdef TEXTLAYOUT_ALLOCHAX
- Tcl_MutexLock(&textLayoutMutex);
- if (freeLayoutInfo != NULL)
- {
- layoutPtr = freeLayoutInfo;
- freeLayoutInfo = layoutPtr->nextFree;
- }
- else
- {
- maxChunks = 1;
- layoutPtr = (LayoutInfo *) ckalloc(sizeof(LayoutInfo) +
- (maxChunks - 1) * sizeof(LayoutChunk));
- layoutPtr->maxChunks = maxChunks;
- }
- Tcl_MutexUnlock(&textLayoutMutex);
-#else
+ Tcl_MutexLock(&textLayoutMutex);
+ if (freeLayoutInfo != NULL)
+ {
+ layoutPtr = freeLayoutInfo;
+ freeLayoutInfo = layoutPtr->nextFree;
+ }
+ else
+ {
maxChunks = 1;
+ layoutPtr = (LayoutInfo *) ckalloc(sizeof(LayoutInfo) +
+ (maxChunks - 1) * sizeof(LayoutChunk));
+ layoutPtr->maxChunks = maxChunks;
+ }
+ Tcl_MutexUnlock(&textLayoutMutex);
+#else
+ maxChunks = 1;
- layoutPtr = (LayoutInfo *) ckalloc(sizeof(LayoutInfo) + (maxChunks -
- 1) * sizeof(LayoutChunk));
+ layoutPtr = (LayoutInfo *) ckalloc(sizeof(LayoutInfo) + (maxChunks -
+ 1) * sizeof(LayoutChunk));
#endif
- layoutPtr->tkfont = tkfont;
- layoutPtr->string = string;
- layoutPtr->numChunks = 0;
- layoutPtr->numLines = 0;
+ layoutPtr->tkfont = tkfont;
+ layoutPtr->string = string;
+ layoutPtr->numChunks = 0;
+ layoutPtr->numLines = 0;
- baseline = fm.ascent;
- maxWidth = 0;
+ baseline = fm.ascent;
+ maxWidth = 0;
- curX = 0;
+ curX = 0;
- end = Tcl_UtfAtIndex(string, numChars);
- special = string;
+ end = Tcl_UtfAtIndex(string, numChars);
+ special = string;
- flags &= TK_WHOLE_WORDS | TK_IGNORE_TABS | TK_IGNORE_NEWLINES;
- flags |= TK_AT_LEAST_ONE;
- for (start = string; start < end;)
+ flags &= TK_WHOLE_WORDS | TK_IGNORE_TABS | TK_IGNORE_NEWLINES;
+ flags |= TK_AT_LEAST_ONE;
+ for (start = string; start < end;)
+ {
+ if (start >= special)
{
- if (start >= special)
+ for (special = start; special < end; special++)
+ {
+ if (!(flags & TK_IGNORE_NEWLINES))
{
- for (special = start; special < end; special++)
- {
- if (!(flags & TK_IGNORE_NEWLINES))
- {
- if ((*special == '\n') || (*special == '\r'))
- break;
- }
- if (!(flags & TK_IGNORE_TABS))
- {
- if (*special == '\t')
- break;
- }
- }
+ if ((*special == '\n') || (*special == '\r'))
+ break;
}
-
- chunkPtr = NULL;
- if (start < special)
+ if (!(flags & TK_IGNORE_TABS))
{
- bytesThisChunk = Tk_MeasureChars(tkfont, start, special - start,
- wrapLength - curX, flags, &newX);
- newX += curX;
- flags &= ~TK_AT_LEAST_ONE;
- if (bytesThisChunk > 0)
- {
+ if (*special == '\t')
+ break;
+ }
+ }
+ }
+
+ chunkPtr = NULL;
+ if (start < special)
+ {
+ bytesThisChunk = Tk_MeasureChars(tkfont, start, special - start,
+ wrapLength - curX, flags, &newX);
+ newX += curX;
+ flags &= ~TK_AT_LEAST_ONE;
+ if (bytesThisChunk > 0)
+ {
#ifdef TEXTLAYOUT_ALLOCHAX
- chunkPtr = NewChunk(&layoutPtr, start,
+ chunkPtr = NewChunk(&layoutPtr, start,
#else
- chunkPtr = NewChunk(&layoutPtr, &maxChunks, start,
+ chunkPtr = NewChunk(&layoutPtr, &maxChunks, start,
#endif
- bytesThisChunk, curX, newX, baseline);
- start += bytesThisChunk;
- curX = newX;
- }
- }
+ bytesThisChunk, curX, newX, baseline);
+ start += bytesThisChunk;
+ curX = newX;
+ }
+ }
- if ((start == special) && (special < end))
- {
- chunkPtr = NULL;
- if (*special == '\t')
- {
- newX = curX + tabWidth;
- newX -= newX % tabWidth;
+ if ((start == special) && (special < end))
+ {
+ chunkPtr = NULL;
+ if (*special == '\t')
+ {
+ newX = curX + tabWidth;
+ newX -= newX % tabWidth;
#ifdef TEXTLAYOUT_ALLOCHAX
- NewChunk(&layoutPtr, start, 1, curX, newX,
+ NewChunk(&layoutPtr, start, 1, curX, newX,
#else
- NewChunk(&layoutPtr, &maxChunks, start, 1, curX, newX,
+ NewChunk(&layoutPtr, &maxChunks, start, 1, curX, newX,
#endif
- baseline)->numDisplayChars = -1;
- start++;
- if ((start < end) && ((wrapLength <= 0) ||
- (newX <= wrapLength)))
- {
- curX = newX;
- flags &= ~TK_AT_LEAST_ONE;
- continue;
- }
- }
- else
- {
+ baseline)->numDisplayChars = -1;
+ start++;
+ if ((start < end) && ((wrapLength <= 0) ||
+ (newX <= wrapLength)))
+ {
+ curX = newX;
+ flags &= ~TK_AT_LEAST_ONE;
+ continue;
+ }
+ }
+ else
+ {
#ifdef TEXTLAYOUT_ALLOCHAX
- NewChunk(&layoutPtr, start, 1, curX, curX,
+ NewChunk(&layoutPtr, start, 1, curX, curX,
#else
- NewChunk(&layoutPtr, &maxChunks, start, 1, curX, curX,
+ NewChunk(&layoutPtr, &maxChunks, start, 1, curX, curX,
#endif
- baseline)->numDisplayChars = -1;
- start++;
- goto wrapLine;
- }
- }
+ baseline)->numDisplayChars = -1;
+ start++;
+ goto wrapLine;
+ }
+ }
- while ((start < end) && isspace(UCHAR(*start)))
- {
- if (!(flags & TK_IGNORE_NEWLINES))
- {
- if ((*start == '\n') || (*start == '\r'))
- break;
- }
- if (!(flags & TK_IGNORE_TABS))
- {
- if (*start == '\t')
- break;
- }
- start++;
- }
- if (chunkPtr != NULL)
- {
- CONST char *end;
-
- end = chunkPtr->start + chunkPtr->numBytes;
- bytesThisChunk = start - end;
- if (bytesThisChunk > 0)
- {
- bytesThisChunk =
- Tk_MeasureChars(tkfont, end, bytesThisChunk, -1, 0,
- &chunkPtr->totalWidth);
- chunkPtr->numBytes += bytesThisChunk;
- chunkPtr->numChars += Tcl_NumUtfChars(end, bytesThisChunk);
- chunkPtr->totalWidth += curX;
- }
- }
+ while ((start < end) && isspace(UCHAR(*start)))
+ {
+ if (!(flags & TK_IGNORE_NEWLINES))
+ {
+ if ((*start == '\n') || (*start == '\r'))
+ break;
+ }
+ if (!(flags & TK_IGNORE_TABS))
+ {
+ if (*start == '\t')
+ break;
+ }
+ start++;
+ }
+ if (chunkPtr != NULL)
+ {
+ CONST char *end;
+
+ end = chunkPtr->start + chunkPtr->numBytes;
+ bytesThisChunk = start - end;
+ if (bytesThisChunk > 0)
+ {
+ bytesThisChunk =
+ Tk_MeasureChars(tkfont, end, bytesThisChunk, -1, 0,
+ &chunkPtr->totalWidth);
+ chunkPtr->numBytes += bytesThisChunk;
+ chunkPtr->numChars += Tcl_NumUtfChars(end, bytesThisChunk);
+ chunkPtr->totalWidth += curX;
+ }
+ }
wrapLine:
- flags |= TK_AT_LEAST_ONE;
+ flags |= TK_AT_LEAST_ONE;
- if (curX > maxWidth)
- maxWidth = curX;
+ if (curX > maxWidth)
+ maxWidth = curX;
- Tcl_DStringAppend(&lineBuffer, (char *) &curX, sizeof(curX));
+ Tcl_DStringAppend(&lineBuffer, (char *) &curX, sizeof(curX));
- curX = 0;
- baseline += height;
- layoutPtr->numLines++;
+ curX = 0;
+ baseline += height;
+ layoutPtr->numLines++;
- if ((maxLines > 0) && (layoutPtr->numLines >= maxLines))
- break;
- }
+ if ((maxLines > 0) && (layoutPtr->numLines >= maxLines))
+ break;
+ }
- if (start >= end)
- if ((layoutPtr->numChunks > 0) && !(flags & TK_IGNORE_NEWLINES))
+ if (start >= end)
+ if ((layoutPtr->numChunks > 0) && !(flags & TK_IGNORE_NEWLINES))
+ {
+ if (layoutPtr->chunks[layoutPtr->numChunks - 1].start[0] == '\n')
{
- if (layoutPtr->chunks[layoutPtr->numChunks - 1].start[0] == '\n')
- {
- chunkPtr =
+ chunkPtr =
#ifdef TEXTLAYOUT_ALLOCHAX
- NewChunk(&layoutPtr, start, 0, curX, curX,
+ NewChunk(&layoutPtr, start, 0, curX, curX,
#else
- NewChunk(&layoutPtr, &maxChunks, start, 0, curX, curX,
+ NewChunk(&layoutPtr, &maxChunks, start, 0, curX, curX,
#endif
- baseline);
- chunkPtr->numDisplayChars = -1;
- Tcl_DStringAppend(&lineBuffer, (char *) &curX, sizeof(curX));
- baseline += height;
- }
+ baseline);
+ chunkPtr->numDisplayChars = -1;
+ Tcl_DStringAppend(&lineBuffer, (char *) &curX, sizeof(curX));
+ baseline += height;
}
+ }
#if 1
- /* Fiddle with chunks on the last line to add ellipsis if there is some
- * text remaining */
- if ((start < end) && (layoutPtr->numChunks > 0))
+ /* Fiddle with chunks on the last line to add ellipsis if there is some
+ * text remaining */
+ if ((start < end) && (layoutPtr->numChunks > 0))
+ {
+ char *ellipsis = "...";
+ int ellipsisLen = strlen(ellipsis);
+ char staticStr[256], *buf = staticStr;
+
+ chunkPtr = &layoutPtr->chunks[layoutPtr->numChunks - 1];
+ if (wrapLength > 0)
{
- char *ellipsis = "...";
- int ellipsisLen = strlen(ellipsis);
- char staticStr[256], *buf = staticStr;
-
- chunkPtr = &layoutPtr->chunks[layoutPtr->numChunks - 1];
- if (wrapLength > 0)
- {
- y = chunkPtr->y;
- for (n = layoutPtr->numChunks - 1; n >= 0; n--)
- {
- chunkPtr = &layoutPtr->chunks[n];
-
- /* Only consider the last line */
- if (chunkPtr->y != y)
- break;
-
- if (chunkPtr->start[0] == '\n')
- continue;
-
- newX = chunkPtr->totalWidth - 1;
- if (chunkPtr->x + chunkPtr->totalWidth < wrapLength)
- newX = wrapLength - chunkPtr->x;
- bytesThisChunk = Ellipsis(tkfont, (char *) chunkPtr->start,
- chunkPtr->numBytes, &newX, ellipsis, TRUE);
- if (bytesThisChunk > 0)
- {
- chunkPtr->numBytes = bytesThisChunk;
- chunkPtr->numChars = Tcl_NumUtfChars(chunkPtr->start, bytesThisChunk);
- chunkPtr->numDisplayChars = chunkPtr->numChars;
- chunkPtr->ellipsis = TRUE;
- chunkPtr->displayWidth = newX;
- chunkPtr->totalWidth = newX;
- lineLengths = (int *) Tcl_DStringValue(&lineBuffer);
- lineLengths[layoutPtr->numLines - 1] = chunkPtr->x + newX;
- if (chunkPtr->x + newX > maxWidth)
- maxWidth = chunkPtr->x + newX;
- break;
- }
- }
- }
- else
+ y = chunkPtr->y;
+ for (n = layoutPtr->numChunks - 1; n >= 0; n--)
+ {
+ chunkPtr = &layoutPtr->chunks[n];
+
+ /* Only consider the last line */
+ if (chunkPtr->y != y)
+ break;
+
+ if (chunkPtr->start[0] == '\n')
+ continue;
+
+ newX = chunkPtr->totalWidth - 1;
+ if (chunkPtr->x + chunkPtr->totalWidth < wrapLength)
+ newX = wrapLength - chunkPtr->x;
+ bytesThisChunk = Ellipsis(tkfont, (char *) chunkPtr->start,
+ chunkPtr->numBytes, &newX, ellipsis, TRUE);
+ if (bytesThisChunk > 0)
{
- if (chunkPtr->start[0] == '\n')
- {
- if (layoutPtr->numChunks == 1)
- goto finish;
- if (layoutPtr->chunks[layoutPtr->numChunks - 2].y != chunkPtr->y)
- goto finish;
- chunkPtr = &layoutPtr->chunks[layoutPtr->numChunks - 2];
- }
-
- if (chunkPtr->numBytes + ellipsisLen > sizeof(staticStr))
- buf = ckalloc(chunkPtr->numBytes + ellipsisLen);
- memcpy(buf, chunkPtr->start, chunkPtr->numBytes);
- memcpy(buf + chunkPtr->numBytes, ellipsis, ellipsisLen);
- Tk_MeasureChars(tkfont, buf,
- chunkPtr->numBytes + ellipsisLen, -1, 0,
- &chunkPtr->displayWidth);
- chunkPtr->totalWidth = chunkPtr->displayWidth;
- chunkPtr->ellipsis = TRUE;
- lineLengths = (int *) Tcl_DStringValue(&lineBuffer);
- lineLengths[layoutPtr->numLines - 1] = chunkPtr->x + chunkPtr->displayWidth;
- if (chunkPtr->x + chunkPtr->displayWidth > maxWidth)
- maxWidth = chunkPtr->x + chunkPtr->displayWidth;
- if (buf != staticStr)
- ckfree(buf);
+ chunkPtr->numBytes = bytesThisChunk;
+ chunkPtr->numChars = Tcl_NumUtfChars(chunkPtr->start, bytesThisChunk);
+ chunkPtr->numDisplayChars = chunkPtr->numChars;
+ chunkPtr->ellipsis = TRUE;
+ chunkPtr->displayWidth = newX;
+ chunkPtr->totalWidth = newX;
+ lineLengths = (int *) Tcl_DStringValue(&lineBuffer);
+ lineLengths[layoutPtr->numLines - 1] = chunkPtr->x + newX;
+ if (chunkPtr->x + newX > maxWidth)
+ maxWidth = chunkPtr->x + newX;
+ break;
}
+ }
}
+ else
+ {
+ if (chunkPtr->start[0] == '\n')
+ {
+ if (layoutPtr->numChunks == 1)
+ goto finish;
+ if (layoutPtr->chunks[layoutPtr->numChunks - 2].y != chunkPtr->y)
+ goto finish;
+ chunkPtr = &layoutPtr->chunks[layoutPtr->numChunks - 2];
+ }
+
+ if (chunkPtr->numBytes + ellipsisLen > sizeof(staticStr))
+ buf = ckalloc(chunkPtr->numBytes + ellipsisLen);
+ memcpy(buf, chunkPtr->start, chunkPtr->numBytes);
+ memcpy(buf + chunkPtr->numBytes, ellipsis, ellipsisLen);
+ Tk_MeasureChars(tkfont, buf,
+ chunkPtr->numBytes + ellipsisLen, -1, 0,
+ &chunkPtr->displayWidth);
+ chunkPtr->totalWidth = chunkPtr->displayWidth;
+ chunkPtr->ellipsis = TRUE;
+ lineLengths = (int *) Tcl_DStringValue(&lineBuffer);
+ lineLengths[layoutPtr->numLines - 1] = chunkPtr->x + chunkPtr->displayWidth;
+ if (chunkPtr->x + chunkPtr->displayWidth > maxWidth)
+ maxWidth = chunkPtr->x + chunkPtr->displayWidth;
+ if (buf != staticStr)
+ ckfree(buf);
+ }
+ }
finish:
#endif
- layoutPtr->width = maxWidth;
- layoutPtr->height = baseline - fm.ascent;
+ layoutPtr->width = maxWidth;
+ layoutPtr->height = baseline - fm.ascent;
layoutPtr->totalWidth = 0;
- if (layoutPtr->numChunks == 0)
- {
- layoutPtr->height = height;
-
- layoutPtr->numChunks = 1;
- layoutPtr->chunks[0].start = string;
- layoutPtr->chunks[0].numBytes = 0;
- layoutPtr->chunks[0].numChars = 0;
- layoutPtr->chunks[0].numDisplayChars = -1;
- layoutPtr->chunks[0].x = 0;
- layoutPtr->chunks[0].y = fm.ascent;
- layoutPtr->chunks[0].totalWidth = 0;
- layoutPtr->chunks[0].displayWidth = 0;
- }
- else
+ if (layoutPtr->numChunks == 0)
+ {
+ layoutPtr->height = height;
+
+ layoutPtr->numChunks = 1;
+ layoutPtr->chunks[0].start = string;
+ layoutPtr->chunks[0].numBytes = 0;
+ layoutPtr->chunks[0].numChars = 0;
+ layoutPtr->chunks[0].numDisplayChars = -1;
+ layoutPtr->chunks[0].x = 0;
+ layoutPtr->chunks[0].y = fm.ascent;
+ layoutPtr->chunks[0].totalWidth = 0;
+ layoutPtr->chunks[0].displayWidth = 0;
+ }
+ else
+ {
+ curLine = 0;
+ chunkPtr = layoutPtr->chunks;
+ y = chunkPtr->y;
+ lineLengths = (int *) Tcl_DStringValue(&lineBuffer);
+ for (n = 0; n < layoutPtr->numChunks; n++)
{
- curLine = 0;
- chunkPtr = layoutPtr->chunks;
+ int extra;
+
+ if (chunkPtr->y != y)
+ {
+ curLine++;
y = chunkPtr->y;
- lineLengths = (int *) Tcl_DStringValue(&lineBuffer);
- for (n = 0; n < layoutPtr->numChunks; n++)
- {
- int extra;
-
- if (chunkPtr->y != y)
- {
- curLine++;
- y = chunkPtr->y;
- }
- extra = maxWidth - lineLengths[curLine];
- if (justify == TK_JUSTIFY_CENTER)
- {
- chunkPtr->x += extra / 2;
- }
- else if (justify == TK_JUSTIFY_RIGHT)
- {
- chunkPtr->x += extra;
- }
+ }
+ extra = maxWidth - lineLengths[curLine];
+ if (justify == TK_JUSTIFY_CENTER)
+ {
+ chunkPtr->x += extra / 2;
+ }
+ else if (justify == TK_JUSTIFY_RIGHT)
+ {
+ chunkPtr->x += extra;
+ }
if (chunkPtr->x + chunkPtr->totalWidth > layoutPtr->totalWidth)
- layoutPtr->totalWidth = chunkPtr->x + chunkPtr->totalWidth;
- chunkPtr++;
- }
-/* dbwin("totalWidth %d displayWidth %d\n", layoutPtr->totalWidth, maxWidth); */
- Tcl_DStringFree(&lineBuffer);
+ layoutPtr->totalWidth = chunkPtr->x + chunkPtr->totalWidth;
+ chunkPtr++;
}
+/* dbwin("totalWidth %d displayWidth %d\n", layoutPtr->totalWidth, maxWidth); */
+ Tcl_DStringFree(&lineBuffer);
+ }
- /* We don't want single-line text layouts for text elements, but it happens for column titles */
+ /* We don't want single-line text layouts for text elements, but it happens for column titles */
/* if (layoutPtr->numLines == 1)
- dbwin("WARNING: single-line TextLayout created\n"); */
+ dbwin("WARNING: single-line TextLayout created\n"); */
- return (TextLayout) layoutPtr;
+ return (TextLayout) layoutPtr;
}
void TextLayout_Free(TextLayout textLayout)
{
- LayoutInfo *layoutPtr = (LayoutInfo *) textLayout;
+ LayoutInfo *layoutPtr = (LayoutInfo *) textLayout;
#ifdef TEXTLAYOUT_ALLOCHAX
- Tcl_MutexLock(&textLayoutMutex);
- layoutPtr->nextFree = freeLayoutInfo;
- freeLayoutInfo = layoutPtr;
- Tcl_MutexUnlock(&textLayoutMutex);
+ Tcl_MutexLock(&textLayoutMutex);
+ layoutPtr->nextFree = freeLayoutInfo;
+ freeLayoutInfo = layoutPtr;
+ Tcl_MutexUnlock(&textLayoutMutex);
#else
- ckfree((char *) layoutPtr);
+ ckfree((char *) layoutPtr);
#endif
}
void TextLayout_Size(TextLayout textLayout, int *widthPtr, int *heightPtr)
{
- LayoutInfo *layoutPtr = (LayoutInfo *) textLayout;
+ LayoutInfo *layoutPtr = (LayoutInfo *) textLayout;
- if (widthPtr != NULL)
- (*widthPtr) = layoutPtr->width;
- if (heightPtr != NULL)
- (*heightPtr) = layoutPtr->height;
+ if (widthPtr != NULL)
+ (*widthPtr) = layoutPtr->width;
+ if (heightPtr != NULL)
+ (*heightPtr) = layoutPtr->height;
}
int TextLayout_TotalWidth(TextLayout textLayout)
{
- LayoutInfo *layoutPtr = (LayoutInfo *) textLayout;
+ LayoutInfo *layoutPtr = (LayoutInfo *) textLayout;
- return layoutPtr->totalWidth;
+ return layoutPtr->totalWidth;
}
void TextLayout_Draw(
- Display *display, /* Display on which to draw. */
- Drawable drawable, /* Window or pixmap in which to draw. */
- GC gc, /* Graphics context to use for drawing text. */
- TextLayout layout, /* Layout information, from a previous call
- * * to Tk_ComputeTextLayout(). */
- int x, int y, /* Upper-left hand corner of rectangle in
+ Display *display, /* Display on which to draw. */
+ Drawable drawable, /* Window or pixmap in which to draw. */
+ GC gc, /* Graphics context to use for drawing text. */
+ TextLayout layout, /* Layout information, from a previous call
+ * * to Tk_ComputeTextLayout(). */
+ int x, int y, /* Upper-left hand corner of rectangle in
* * which to draw (pixels). */
- int firstChar, /* The index of the first character to draw
- * * from the given text item. 0 specfies the
- * * beginning. */
- int lastChar /* The index just after the last character
- * * to draw from the given text item. A number
- * * < 0 means to draw all characters. */
+ int firstChar, /* The index of the first character to draw
+ * * from the given text item. 0 specfies the
+ * * beginning. */
+ int lastChar /* The index just after the last character
+ * * to draw from the given text item. A number
+ * * < 0 means to draw all characters. */
)
{
- LayoutInfo *layoutPtr = (LayoutInfo *) layout;
- int i, numDisplayChars, drawX;
- CONST char *firstByte;
- CONST char *lastByte;
- LayoutChunk *chunkPtr;
-
- if (lastChar < 0)
- lastChar = 100000000;
- chunkPtr = layoutPtr->chunks;
- for (i = 0; i < layoutPtr->numChunks; i++)
+ LayoutInfo *layoutPtr = (LayoutInfo *) layout;
+ int i, numDisplayChars, drawX;
+ CONST char *firstByte;
+ CONST char *lastByte;
+ LayoutChunk *chunkPtr;
+
+ if (lastChar < 0)
+ lastChar = 100000000;
+ chunkPtr = layoutPtr->chunks;
+ for (i = 0; i < layoutPtr->numChunks; i++)
+ {
+ numDisplayChars = chunkPtr->numDisplayChars;
+ if ((numDisplayChars > 0) && (firstChar < numDisplayChars))
{
- numDisplayChars = chunkPtr->numDisplayChars;
- if ((numDisplayChars > 0) && (firstChar < numDisplayChars))
- {
- if (firstChar <= 0)
- {
- drawX = 0;
- firstChar = 0;
- firstByte = chunkPtr->start;
- }
- else
- {
- firstByte = Tcl_UtfAtIndex(chunkPtr->start, firstChar);
- Tk_MeasureChars(layoutPtr->tkfont, chunkPtr->start,
- firstByte - chunkPtr->start, -1, 0, &drawX);
- }
- if (lastChar < numDisplayChars)
- numDisplayChars = lastChar;
- lastByte = Tcl_UtfAtIndex(chunkPtr->start, numDisplayChars);
+ if (firstChar <= 0)
+ {
+ drawX = 0;
+ firstChar = 0;
+ firstByte = chunkPtr->start;
+ }
+ else
+ {
+ firstByte = Tcl_UtfAtIndex(chunkPtr->start, firstChar);
+ Tk_MeasureChars(layoutPtr->tkfont, chunkPtr->start,
+ firstByte - chunkPtr->start, -1, 0, &drawX);
+ }
+ if (lastChar < numDisplayChars)
+ numDisplayChars = lastChar;
+ lastByte = Tcl_UtfAtIndex(chunkPtr->start, numDisplayChars);
#if 1
- if (chunkPtr->ellipsis)
- {
- char staticStr[256], *buf = staticStr;
- char *ellipsis = "...";
- int ellipsisLen = strlen(ellipsis);
-
- if ((lastByte - firstByte) + ellipsisLen > sizeof(staticStr))
- buf = ckalloc((lastByte - firstByte) + ellipsisLen);
- memcpy(buf, firstByte, (lastByte - firstByte));
- memcpy(buf + (lastByte - firstByte), ellipsis, ellipsisLen);
- Tk_DrawChars(display, drawable, gc, layoutPtr->tkfont,
- buf, (lastByte - firstByte) + ellipsisLen,
- x + chunkPtr->x + drawX, y + chunkPtr->y);
- if (buf != staticStr)
- ckfree(buf);
- }
- else
+ if (chunkPtr->ellipsis)
+ {
+ char staticStr[256], *buf = staticStr;
+ char *ellipsis = "...";
+ int ellipsisLen = strlen(ellipsis);
+
+ if ((lastByte - firstByte) + ellipsisLen > sizeof(staticStr))
+ buf = ckalloc((lastByte - firstByte) + ellipsisLen);
+ memcpy(buf, firstByte, (lastByte - firstByte));
+ memcpy(buf + (lastByte - firstByte), ellipsis, ellipsisLen);
+ Tk_DrawChars(display, drawable, gc, layoutPtr->tkfont,
+ buf, (lastByte - firstByte) + ellipsisLen,
+ x + chunkPtr->x + drawX, y + chunkPtr->y);
+ if (buf != staticStr)
+ ckfree(buf);
+ }
+ else
#endif
- Tk_DrawChars(display, drawable, gc, layoutPtr->tkfont,
- firstByte, lastByte - firstByte, x + chunkPtr->x + drawX,
- y + chunkPtr->y);
- }
- firstChar -= chunkPtr->numChars;
- lastChar -= chunkPtr->numChars;
- if (lastChar <= 0)
- break;
- chunkPtr++;
+ Tk_DrawChars(display, drawable, gc, layoutPtr->tkfont,
+ firstByte, lastByte - firstByte, x + chunkPtr->x + drawX,
+ y + chunkPtr->y);
}
+ firstChar -= chunkPtr->numChars;
+ lastChar -= chunkPtr->numChars;
+ if (lastChar <= 0)
+ break;
+ chunkPtr++;
+ }
}
/*
@@ -2428,11 +2428,11 @@ typedef struct AllocData AllocData;
struct AllocElem
{
- AllocElem *next;
- int free;
- char body[1]; /* First byte of client's space. Actual
- * size of this field will be larger than
- * one. */
+ AllocElem *next;
+ int free;
+ char body[1]; /* First byte of client's space. Actual
+ * size of this field will be larger than
+ * one. */
};
/*
@@ -2442,14 +2442,14 @@ struct AllocElem
struct AllocList
{
- int size; /* Size of every AllocElem.body[] */
- AllocElem *head;
- AllocList *next; /* Points to an AllocList with a different .size */
- AllocElem **blocks; /* Array of pointers to allocated blocks. The blocks
- * may contain a different number of elements. */
- int blockCount; /* Number of array elements in .blocks */
- int blockSize; /* The number of AllocElems per block to allocate.
- * Starts at 16 and gets double up to 1024. */
+ int size; /* Size of every AllocElem.body[] */
+ AllocElem *head;
+ AllocList *next; /* Points to an AllocList with a different .size */
+ AllocElem **blocks; /* Array of pointers to allocated blocks. The blocks
+ * may contain a different number of elements. */
+ int blockCount; /* Number of array elements in .blocks */
+ int blockSize; /* The number of AllocElems per block to allocate.
+ * Starts at 16 and gets double up to 1024. */
};
/*
@@ -2458,7 +2458,7 @@ struct AllocList
struct AllocData
{
- AllocList *freeLists;
+ AllocList *freeLists;
};
/*
@@ -2468,129 +2468,129 @@ struct AllocData
*/
#define BODY_OFFSET \
- ((unsigned long) (&((AllocElem *) 0)->body))
+ ((unsigned long) (&((AllocElem *) 0)->body))
char *AllocHax_Alloc(ClientData data, int size)
{
- AllocList *freeLists = ((AllocData *) data)->freeLists;
- AllocList *freeList = freeLists;
- AllocElem *elem, *result;
- int i;
-
- while ((freeList != NULL) && (freeList->size != size))
- freeList = freeList->next;
-
- if (freeList == NULL) {
- freeList = (AllocList *) ckalloc(sizeof(AllocList));
- freeList->size = size;
- freeList->head = NULL;
- freeList->next = freeLists;
- freeList->blocks = NULL;
- freeList->blockCount = 0;
- freeList->blockSize = 16;
- freeLists = freeList;
- ((AllocData *) data)->freeLists = freeLists;
- }
+ AllocList *freeLists = ((AllocData *) data)->freeLists;
+ AllocList *freeList = freeLists;
+ AllocElem *elem, *result;
+ int i;
- if (freeList->head != NULL) {
- elem = freeList->head;
- freeList->head = elem->next;
- result = elem;
- } else {
- AllocElem *block;
- unsigned elemSize = TCL_ALIGN(sizeof(AllocElem) + size);
- freeList->blockCount += 1;
- freeList->blocks = (AllocElem **) ckrealloc((char *) freeList->blocks,
- sizeof(AllocElem *) * freeList->blockCount);
- block = (AllocElem *) ckalloc(elemSize * freeList->blockSize);
- freeList->blocks[freeList->blockCount - 1] = block;
+ while ((freeList != NULL) && (freeList->size != size))
+ freeList = freeList->next;
+
+ if (freeList == NULL) {
+ freeList = (AllocList *) ckalloc(sizeof(AllocList));
+ freeList->size = size;
+ freeList->head = NULL;
+ freeList->next = freeLists;
+ freeList->blocks = NULL;
+ freeList->blockCount = 0;
+ freeList->blockSize = 16;
+ freeLists = freeList;
+ ((AllocData *) data)->freeLists = freeLists;
+ }
+
+ if (freeList->head != NULL) {
+ elem = freeList->head;
+ freeList->head = elem->next;
+ result = elem;
+ } else {
+ AllocElem *block;
+ unsigned elemSize = TCL_ALIGN(sizeof(AllocElem) + size);
+ freeList->blockCount += 1;
+ freeList->blocks = (AllocElem **) ckrealloc((char *) freeList->blocks,
+ sizeof(AllocElem *) * freeList->blockCount);
+ block = (AllocElem *) ckalloc(elemSize * freeList->blockSize);
+ freeList->blocks[freeList->blockCount - 1] = block;
/* dbwin("AllocHax_Alloc alloc %d of size %d\n", freeList->blockSize, size); */
- freeList->head = block;
- elem = freeList->head;
- for (i = 1; i < freeList->blockSize - 1; i++) {
- elem->free = 1;
- elem->next = (AllocElem *) (((char *) freeList->head) +
- elemSize * i);
- elem = elem->next;
- }
- elem->next = NULL;
- elem->free = 1;
- result = freeList->head;
- freeList->head = result->next;
- if (freeList->blockSize < 1024)
- freeList->blockSize *= 2;
+ freeList->head = block;
+ elem = freeList->head;
+ for (i = 1; i < freeList->blockSize - 1; i++) {
+ elem->free = 1;
+ elem->next = (AllocElem *) (((char *) freeList->head) +
+ elemSize * i);
+ elem = elem->next;
}
+ elem->next = NULL;
+ elem->free = 1;
+ result = freeList->head;
+ freeList->head = result->next;
+ if (freeList->blockSize < 1024)
+ freeList->blockSize *= 2;
+ }
- if (!result->free)
- panic("AllocHax_Alloc: element not marked free");
+ if (!result->free)
+ panic("AllocHax_Alloc: element not marked free");
- result->free = 0;
- return result->body;
+ result->free = 0;
+ return result->body;
}
void AllocHax_Free(ClientData data, char *ptr, int size)
{
- AllocList *freeLists = ((AllocData *) data)->freeLists;
- AllocList *freeList = freeLists;
- AllocElem *elem;
+ AllocList *freeLists = ((AllocData *) data)->freeLists;
+ AllocList *freeList = freeLists;
+ AllocElem *elem;
- /*
- * See comment from Tcl_DbCkfree before you change the following
- * line.
- */
+ /*
+ * See comment from Tcl_DbCkfree before you change the following
+ * line.
+ */
- elem = (AllocElem *) (((unsigned long) ptr) - BODY_OFFSET);
+ elem = (AllocElem *) (((unsigned long) ptr) - BODY_OFFSET);
- if (elem->free)
- panic("AllocHax_Free: element already marked free");
+ if (elem->free)
+ panic("AllocHax_Free: element already marked free");
- while (freeList != NULL && freeList->size != size)
- freeList = freeList->next;
- if (freeList == NULL)
- panic("AllocHax_Free: can't find free list for size %d", size);
+ while (freeList != NULL && freeList->size != size)
+ freeList = freeList->next;
+ if (freeList == NULL)
+ panic("AllocHax_Free: can't find free list for size %d", size);
- WIPE(elem->body, size);
- elem->next = freeList->head;
- elem->free = 1;
- freeList->head = elem;
+ WIPE(elem->body, size);
+ elem->next = freeList->head;
+ elem->free = 1;
+ freeList->head = elem;
}
char *AllocHax_CAlloc(ClientData data, int size, int count, int roundUp)
{
- int n = (count / roundUp) * roundUp + ((count % roundUp) ? roundUp : 0);
- return AllocHax_Alloc(data, size * n);
+ int n = (count / roundUp) * roundUp + ((count % roundUp) ? roundUp : 0);
+ return AllocHax_Alloc(data, size * n);
}
void AllocHax_CFree(ClientData data, char *ptr, int size, int count, int roundUp)
{
- int n = (count / roundUp) * roundUp + ((count % roundUp) ? roundUp : 0);
- AllocHax_Free(data, ptr, size * n);
+ int n = (count / roundUp) * roundUp + ((count % roundUp) ? roundUp : 0);
+ AllocHax_Free(data, ptr, size * n);
}
ClientData AllocHax_Init(void)
{
- AllocData *data = (AllocData *) ckalloc(sizeof(AllocData));
- data->freeLists = NULL;
- return data;
+ AllocData *data = (AllocData *) ckalloc(sizeof(AllocData));
+ data->freeLists = NULL;
+ return data;
}
void AllocHax_Finalize(ClientData data)
{
- AllocList *freeList = ((AllocData *) data)->freeLists;
- int i;
+ AllocList *freeList = ((AllocData *) data)->freeLists;
+ int i;
- while (freeList != NULL) {
- AllocList *nextList = freeList->next;
- for (i = 0; i < freeList->blockCount; i++) {
- AllocElem *block = freeList->blocks[i];
- ckfree((char *) block);
- }
- ckfree((char *) freeList->blocks);
- ckfree((char *) freeList);
- freeList = nextList;
+ while (freeList != NULL) {
+ AllocList *nextList = freeList->next;
+ for (i = 0; i < freeList->blockCount; i++) {
+ AllocElem *block = freeList->blocks[i];
+ ckfree((char *) block);
}
+ ckfree((char *) freeList->blocks);
+ ckfree((char *) freeList);
+ freeList = nextList;
+ }
- ckfree((char *) data);
+ ckfree((char *) data);
}
#endif /* ALLOC_HAX */