summaryrefslogtreecommitdiffstats
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
parentbf00b9981a50c5594017ed97e252b84548732128 (diff)
downloadtktreectrl-57aa137a3d2ccd20c7fd09baa635e3933eee4d5e.zip
tktreectrl-57aa137a3d2ccd20c7fd09baa635e3933eee4d5e.tar.gz
tktreectrl-57aa137a3d2ccd20c7fd09baa635e3933eee4d5e.tar.bz2
Converted to tab+space indentation.
-rw-r--r--generic/tkTreeDrag.c770
-rw-r--r--generic/tkTreeElem.h182
-rw-r--r--generic/tkTreeMarquee.c602
-rw-r--r--generic/tkTreeUtils.c2024
4 files changed, 1789 insertions, 1789 deletions
diff --git a/generic/tkTreeDrag.c b/generic/tkTreeDrag.c
index 4192faf..09e695e 100644
--- a/generic/tkTreeDrag.c
+++ b/generic/tkTreeDrag.c
@@ -5,7 +5,7 @@
*
* Copyright (c) 2002-2005 Tim Baker
*
- * RCS: @(#) $Id: tkTreeDrag.c,v 1.13 2005/07/12 02:50:34 treectrl Exp $
+ * RCS: @(#) $Id: tkTreeDrag.c,v 1.14 2005/09/16 23:24:20 treectrl Exp $
*/
#include "tkTreeCtrl.h"
@@ -15,472 +15,472 @@ typedef struct DragImage DragImage;
struct DragElem
{
- int x, y, width, height;
- DragElem *next;
+ int x, y, width, height;
+ DragElem *next;
};
struct DragImage
{
- TreeCtrl *tree;
- Tk_OptionTable optionTable;
- int visible;
- int x, y; /* offset to draw at in canvas coords */
- int bounds[4]; /* bounds of all DragElems */
- DragElem *elem;
- int onScreen; /* TRUE if is displayed */
- int sx, sy; /* Window coords where displayed */
+ TreeCtrl *tree;
+ Tk_OptionTable optionTable;
+ int visible;
+ int x, y; /* offset to draw at in canvas coords */
+ int bounds[4]; /* bounds of all DragElems */
+ DragElem *elem;
+ int onScreen; /* TRUE if is displayed */
+ int sx, sy; /* Window coords where displayed */
};
#define DRAG_CONF_VISIBLE 0x0001
static Tk_OptionSpec optionSpecs[] = {
- {TK_OPTION_BOOLEAN, "-visible", (char *) NULL, (char *) NULL,
- "0", -1, Tk_Offset(DragImage, visible),
- 0, (ClientData) NULL, DRAG_CONF_VISIBLE},
- {TK_OPTION_END, (char *) NULL, (char *) NULL, (char *) NULL,
- (char *) NULL, 0, -1, 0, 0, 0}
+ {TK_OPTION_BOOLEAN, "-visible", (char *) NULL, (char *) NULL,
+ "0", -1, Tk_Offset(DragImage, visible),
+ 0, (ClientData) NULL, DRAG_CONF_VISIBLE},
+ {TK_OPTION_END, (char *) NULL, (char *) NULL, (char *) NULL,
+ (char *) NULL, 0, -1, 0, 0, 0}
};
static DragElem *DragElem_Alloc(DragImage *dragImage)
{
- DragElem *elem = (DragElem *) ckalloc(sizeof(DragElem));
- DragElem *walk = dragImage->elem;
- memset(elem, '\0', sizeof(DragElem));
- if (dragImage->elem == NULL)
- dragImage->elem = elem;
- else
- {
- while (walk->next != NULL)
- walk = walk->next;
- walk->next = elem;
- }
- return elem;
+ DragElem *elem = (DragElem *) ckalloc(sizeof(DragElem));
+ DragElem *walk = dragImage->elem;
+ memset(elem, '\0', sizeof(DragElem));
+ if (dragImage->elem == NULL)
+ dragImage->elem = elem;
+ else
+ {
+ while (walk->next != NULL)
+ walk = walk->next;
+ walk->next = elem;
+ }
+ return elem;
}
static DragElem *DragElem_Free(DragImage *dragImage, DragElem *elem)
{
- DragElem *next = elem->next;
- WFREE(elem, DragElem);
- return next;
+ DragElem *next = elem->next;
+ WFREE(elem, DragElem);
+ return next;
}
int TreeDragImage_Init(TreeCtrl *tree)
{
- DragImage *dragImage;
-
- dragImage = (DragImage *) ckalloc(sizeof(DragImage));
- memset(dragImage, '\0', sizeof(DragImage));
- dragImage->tree = tree;
- dragImage->optionTable = Tk_CreateOptionTable(tree->interp, optionSpecs);
- if (Tk_InitOptions(tree->interp, (char *) dragImage, dragImage->optionTable,
- tree->tkwin) != TCL_OK)
- {
- WFREE(dragImage, DragImage);
- return TCL_ERROR;
- }
- tree->dragImage = (TreeDragImage) dragImage;
- return TCL_OK;
+ DragImage *dragImage;
+
+ dragImage = (DragImage *) ckalloc(sizeof(DragImage));
+ memset(dragImage, '\0', sizeof(DragImage));
+ dragImage->tree = tree;
+ dragImage->optionTable = Tk_CreateOptionTable(tree->interp, optionSpecs);
+ if (Tk_InitOptions(tree->interp, (char *) dragImage, dragImage->optionTable,
+ tree->tkwin) != TCL_OK)
+ {
+ WFREE(dragImage, DragImage);
+ return TCL_ERROR;
+ }
+ tree->dragImage = (TreeDragImage) dragImage;
+ return TCL_OK;
}
void TreeDragImage_Free(TreeDragImage dragImage_)
{
- DragImage *dragImage = (DragImage *) dragImage_;
- DragElem *elem = dragImage->elem;
-
- while (elem != NULL)
- elem = DragElem_Free(dragImage, elem);
- Tk_FreeConfigOptions((char *) dragImage, dragImage->optionTable,
- dragImage->tree->tkwin);
- WFREE(dragImage, DragImage);
+ DragImage *dragImage = (DragImage *) dragImage_;
+ DragElem *elem = dragImage->elem;
+
+ while (elem != NULL)
+ elem = DragElem_Free(dragImage, elem);
+ Tk_FreeConfigOptions((char *) dragImage, dragImage->optionTable,
+ dragImage->tree->tkwin);
+ WFREE(dragImage, DragImage);
}
void TreeDragImage_Display(TreeDragImage dragImage_)
{
- DragImage *dragImage = (DragImage *) dragImage_;
- TreeCtrl *tree = dragImage->tree;
-
- if (!dragImage->onScreen && dragImage->visible)
- {
- dragImage->sx = 0 - tree->xOrigin;
- dragImage->sy = 0 - tree->yOrigin;
- TreeDragImage_Draw(dragImage_, Tk_WindowId(tree->tkwin), dragImage->sx, dragImage->sy);
- dragImage->onScreen = TRUE;
- }
+ DragImage *dragImage = (DragImage *) dragImage_;
+ TreeCtrl *tree = dragImage->tree;
+
+ if (!dragImage->onScreen && dragImage->visible)
+ {
+ dragImage->sx = 0 - tree->xOrigin;
+ dragImage->sy = 0 - tree->yOrigin;
+ TreeDragImage_Draw(dragImage_, Tk_WindowId(tree->tkwin), dragImage->sx, dragImage->sy);
+ dragImage->onScreen = TRUE;
+ }
}
void TreeDragImage_Undisplay(TreeDragImage dragImage_)
{
- DragImage *dragImage = (DragImage *) dragImage_;
- TreeCtrl *tree = dragImage->tree;
-
- if (dragImage->onScreen)
- {
- TreeDragImage_Draw(dragImage_, Tk_WindowId(tree->tkwin), dragImage->sx, dragImage->sy);
- dragImage->onScreen = FALSE;
- }
+ DragImage *dragImage = (DragImage *) dragImage_;
+ TreeCtrl *tree = dragImage->tree;
+
+ if (dragImage->onScreen)
+ {
+ TreeDragImage_Draw(dragImage_, Tk_WindowId(tree->tkwin), dragImage->sx, dragImage->sy);
+ dragImage->onScreen = FALSE;
+ }
}
static int DragImage_Config(DragImage *dragImage, int objc, Tcl_Obj *CONST objv[])
{
- TreeCtrl *tree = dragImage->tree;
- Tk_SavedOptions savedOptions;
+ TreeCtrl *tree = dragImage->tree;
+ Tk_SavedOptions savedOptions;
int error;
Tcl_Obj *errorResult = NULL;
- int mask;
+ int mask;
- for (error = 0; error <= 1; error++)
+ for (error = 0; error <= 1; error++)
+ {
+ if (error == 0)
{
- if (error == 0)
- {
- if (Tk_SetOptions(tree->interp, (char *) dragImage, dragImage->optionTable,
- objc, objv, tree->tkwin, &savedOptions, &mask) != TCL_OK)
- {
- mask = 0;
- continue;
- }
+ if (Tk_SetOptions(tree->interp, (char *) dragImage, dragImage->optionTable,
+ objc, objv, tree->tkwin, &savedOptions, &mask) != TCL_OK)
+ {
+ mask = 0;
+ continue;
+ }
- /* xxx */
+ /* xxx */
- Tk_FreeSavedOptions(&savedOptions);
- break;
- }
- else
- {
- errorResult = Tcl_GetObjResult(tree->interp);
- Tcl_IncrRefCount(errorResult);
- Tk_RestoreSavedOptions(&savedOptions);
+ Tk_FreeSavedOptions(&savedOptions);
+ break;
+ }
+ else
+ {
+ errorResult = Tcl_GetObjResult(tree->interp);
+ Tcl_IncrRefCount(errorResult);
+ Tk_RestoreSavedOptions(&savedOptions);
- /* xxx */
+ /* xxx */
- Tcl_SetObjResult(tree->interp, errorResult);
- Tcl_DecrRefCount(errorResult);
- return TCL_ERROR;
- }
+ Tcl_SetObjResult(tree->interp, errorResult);
+ Tcl_DecrRefCount(errorResult);
+ return TCL_ERROR;
}
+ }
- if (mask & DRAG_CONF_VISIBLE)
- {
- TreeDragImage_Undisplay((TreeDragImage) dragImage);
- TreeDragImage_Display((TreeDragImage) dragImage);
- }
+ if (mask & DRAG_CONF_VISIBLE)
+ {
+ TreeDragImage_Undisplay((TreeDragImage) dragImage);
+ TreeDragImage_Display((TreeDragImage) dragImage);
+ }
- return TCL_OK;
+ return TCL_OK;
}
void TreeDragImage_Draw(TreeDragImage dragImage_, Drawable drawable, int x, int y)
{
- DragImage *dragImage = (DragImage *) dragImage_;
- TreeCtrl *tree = dragImage->tree;
- DragElem *elem = dragImage->elem;
- DotState dotState;
+ DragImage *dragImage = (DragImage *) dragImage_;
+ TreeCtrl *tree = dragImage->tree;
+ DragElem *elem = dragImage->elem;
+ DotState dotState;
/* if (!dragImage->visible)
- return; */
- if (elem == NULL)
- return;
-
- DotRect_Setup(tree, drawable, &dotState);
-
- while (elem != NULL)
- {
- DotRect_Draw(&dotState,
- x + dragImage->x + elem->x,
- y + dragImage->y + elem->y,
- elem->width, elem->height);
- elem = elem->next;
- }
-
- DotRect_Restore(&dotState);
+ return; */
+ if (elem == NULL)
+ return;
+
+ DotRect_Setup(tree, drawable, &dotState);
+
+ while (elem != NULL)
+ {
+ DotRect_Draw(&dotState,
+ x + dragImage->x + elem->x,
+ y + dragImage->y + elem->y,
+ elem->width, elem->height);
+ elem = elem->next;
+ }
+
+ DotRect_Restore(&dotState);
}
int DragImageCmd(ClientData clientData, Tcl_Interp *interp, int objc,
Tcl_Obj *CONST objv[])
{
- TreeCtrl *tree = (TreeCtrl *) clientData;
- DragImage *dragImage = (DragImage *) tree->dragImage;
- static CONST char *commandNames[] = { "add", "cget", "clear", "configure",
- "offset", (char *) NULL };
- enum { COMMAND_ADD, COMMAND_CGET, COMMAND_CLEAR, COMMAND_CONFIGURE,
- COMMAND_OFFSET };
- int index;
-
- if (objc < 3)
+ TreeCtrl *tree = (TreeCtrl *) clientData;
+ DragImage *dragImage = (DragImage *) tree->dragImage;
+ static CONST char *commandNames[] = { "add", "cget", "clear", "configure",
+ "offset", (char *) NULL };
+ enum { COMMAND_ADD, COMMAND_CGET, COMMAND_CLEAR, COMMAND_CONFIGURE,
+ COMMAND_OFFSET };
+ int index;
+
+ if (objc < 3)
+ {
+ Tcl_WrongNumArgs(interp, 2, objv, "command ?arg arg ...?");
+ return TCL_ERROR;
+ }
+
+ if (Tcl_GetIndexFromObj(interp, objv[2], commandNames, "command", 0,
+ &index) != TCL_OK)
+ {
+ return TCL_ERROR;
+ }
+
+ switch (index)
+ {
+ /* T dragimage add I ?C? ?E ...? */
+ case COMMAND_ADD:
{
- Tcl_WrongNumArgs(interp, 2, objv, "command ?arg arg ...?");
+ XRectangle staticRects[STATIC_SIZE], *rects = staticRects;
+ TreeItem item;
+ TreeItemColumn itemColumn = NULL;
+ TreeColumn treeColumn;
+ int i, count, columnIndex = -1;
+ int indent, width, totalWidth;
+ int x, y, w, h;
+ DragElem *elem;
+ StyleDrawArgs drawArgs;
+ int result = TCL_OK;
+
+ if (objc < 4)
+ {
+ Tcl_WrongNumArgs(interp, 3, objv, "item ?column? ?element ...?");
return TCL_ERROR;
- }
+ }
- if (Tcl_GetIndexFromObj(interp, objv[2], commandNames, "command", 0,
- &index) != TCL_OK)
- {
+ if (TreeItem_FromObj(tree, objv[3], &item, 0) != TCL_OK)
return TCL_ERROR;
- }
- switch (index)
- {
- /* T dragimage add I ?C? ?E ...? */
- case COMMAND_ADD:
+ /* Validate all of the arguments, even if the command would exit
+ * early without needing to check those arguments. */
+ if (objc > 4)
+ {
+ if (TreeItem_ColumnFromObj(tree, item, objv[4], &itemColumn, &columnIndex) != TCL_OK)
+ return TCL_ERROR;
+ if (objc > 5)
{
- XRectangle staticRects[STATIC_SIZE], *rects = staticRects;
- TreeItem item;
- TreeItemColumn itemColumn = NULL;
- TreeColumn treeColumn;
- int i, count, columnIndex = -1;
- int indent, width, totalWidth;
- int x, y, w, h;
- DragElem *elem;
- StyleDrawArgs drawArgs;
- int result = TCL_OK;
-
- if (objc < 4)
+ if ((itemColumn == NULL) ||
+ (TreeItemColumn_GetStyle(tree, itemColumn) == NULL)) {
+ FormatResult(interp,
+ "item %s%d column %s%d has no style",
+ tree->itemPrefix, TreeItem_GetID(tree, item),
+ tree->columnPrefix,
+ TreeColumn_GetID(Tree_FindColumn(tree, columnIndex)));
+ return TCL_ERROR;
+ }
+ drawArgs.tree = tree;
+ drawArgs.style = TreeItemColumn_GetStyle(tree, itemColumn);
+ if (TreeStyle_ValidateElements(&drawArgs,
+ objc - 5, objv + 5) != TCL_OK)
+ return TCL_ERROR;
+ }
+ }
+
+ if (Tree_ItemBbox(tree, item, &x, &y, &w, &h) < 0)
+ return TCL_OK;
+ if (w < 1 || h < 1)
+ return TCL_OK;
+
+ drawArgs.tree = tree;
+ drawArgs.drawable = None;
+ drawArgs.state = TreeItem_GetState(tree, item);
+ drawArgs.y = y;
+ drawArgs.height = h;
+
+ TreeDragImage_Undisplay(tree->dragImage);
+
+ if (objc > 4)
+ {
+ treeColumn = Tree_FindColumn(tree, columnIndex);
+ if (!TreeColumn_Visible(treeColumn))
+ goto doneAdd;
+ drawArgs.style = TreeItemColumn_GetStyle(tree, itemColumn);
+ totalWidth = 0;
+ treeColumn = tree->columns;
+ for (i = 0; i < columnIndex; i++)
+ {
+ totalWidth += TreeColumn_UseWidth(treeColumn);
+ treeColumn = TreeColumn_Next(treeColumn);
+ }
+ if (treeColumn == tree->columnTree)
+ indent = TreeItem_Indent(tree, item);
+ else
+ indent = 0;
+ drawArgs.indent = indent;
+ drawArgs.x = x + totalWidth;
+ drawArgs.width = TreeColumn_UseWidth(treeColumn);
+ drawArgs.justify = TreeColumn_Justify(treeColumn);
+ if (objc - 5 > STATIC_SIZE)
+ STATIC_ALLOC(rects, XRectangle, objc - 5);
+ count = TreeStyle_GetElemRects(&drawArgs, objc - 5, objv + 5, rects);
+ if (count == -1)
+ {
+ result = TCL_ERROR;
+ goto doneAdd;
+ }
+ for (i = 0; i < count; i++)
+ {
+ elem = DragElem_Alloc(dragImage);
+ elem->x = rects[i].x;
+ elem->y = rects[i].y;
+ elem->width = rects[i].width;
+ elem->height = rects[i].height;
+ }
+ }
+ else
+ {
+ totalWidth = 0;
+ treeColumn = tree->columns;
+ itemColumn = TreeItem_GetFirstColumn(tree, item);
+ while (itemColumn != NULL)
+ {
+ if (!TreeColumn_Visible(treeColumn))
+ goto nextColumn;
+ width = TreeColumn_UseWidth(treeColumn);
+ if (treeColumn == tree->columnTree)
+ indent = TreeItem_Indent(tree, item);
+ else
+ indent = 0;
+ drawArgs.style = TreeItemColumn_GetStyle(tree, itemColumn);
+ if (drawArgs.style != NULL)
+ {
+ drawArgs.indent = indent;
+ drawArgs.x = x + totalWidth;
+ drawArgs.width = width;
+ drawArgs.justify = TreeColumn_Justify(treeColumn);
+ count = TreeStyle_NumElements(tree, drawArgs.style);
+ STATIC_ALLOC(rects, XRectangle, count);
+ count = TreeStyle_GetElemRects(&drawArgs, 0, NULL, rects);
+ if (count == -1)
{
- Tcl_WrongNumArgs(interp, 3, objv, "item ?column? ?element ...?");
- return TCL_ERROR;
+ result = TCL_ERROR;
+ goto doneAdd;
}
-
- if (TreeItem_FromObj(tree, objv[3], &item, 0) != TCL_OK)
- return TCL_ERROR;
-
- /* Validate all of the arguments, even if the command would exit
- * early without needing to check those arguments. */
- if (objc > 4)
+ for (i = 0; i < count; i++)
{
- if (TreeItem_ColumnFromObj(tree, item, objv[4], &itemColumn, &columnIndex) != TCL_OK)
- return TCL_ERROR;
- if (objc > 5)
- {
- if ((itemColumn == NULL) ||
- (TreeItemColumn_GetStyle(tree, itemColumn) == NULL)) {
- FormatResult(interp,
- "item %s%d column %s%d has no style",
- tree->itemPrefix, TreeItem_GetID(tree, item),
- tree->columnPrefix,
- TreeColumn_GetID(Tree_FindColumn(tree, columnIndex)));
- return TCL_ERROR;
- }
- drawArgs.tree = tree;
- drawArgs.style = TreeItemColumn_GetStyle(tree, itemColumn);
- if (TreeStyle_ValidateElements(&drawArgs,
- objc - 5, objv + 5) != TCL_OK)
- return TCL_ERROR;
- }
+ elem = DragElem_Alloc(dragImage);
+ elem->x = rects[i].x;
+ elem->y = rects[i].y;
+ elem->width = rects[i].width;
+ elem->height = rects[i].height;
}
-
- if (Tree_ItemBbox(tree, item, &x, &y, &w, &h) < 0)
- return TCL_OK;
- if (w < 1 || h < 1)
- return TCL_OK;
-
- drawArgs.tree = tree;
- drawArgs.drawable = None;
- drawArgs.state = TreeItem_GetState(tree, item);
- drawArgs.y = y;
- drawArgs.height = h;
-
- TreeDragImage_Undisplay(tree->dragImage);
-
- if (objc > 4)
+ if (rects != staticRects)
{
- treeColumn = Tree_FindColumn(tree, columnIndex);
- if (!TreeColumn_Visible(treeColumn))
- goto doneAdd;
- drawArgs.style = TreeItemColumn_GetStyle(tree, itemColumn);
- totalWidth = 0;
- treeColumn = tree->columns;
- for (i = 0; i < columnIndex; i++)
- {
- totalWidth += TreeColumn_UseWidth(treeColumn);
- treeColumn = TreeColumn_Next(treeColumn);
- }
- if (treeColumn == tree->columnTree)
- indent = TreeItem_Indent(tree, item);
- else
- indent = 0;
- drawArgs.indent = indent;
- drawArgs.x = x + totalWidth;
- drawArgs.width = TreeColumn_UseWidth(treeColumn);
- drawArgs.justify = TreeColumn_Justify(treeColumn);
- if (objc - 5 > STATIC_SIZE)
- STATIC_ALLOC(rects, XRectangle, objc - 5);
- count = TreeStyle_GetElemRects(&drawArgs, objc - 5, objv + 5, rects);
- if (count == -1)
- {
- result = TCL_ERROR;
- goto doneAdd;
- }
- for (i = 0; i < count; i++)
- {
- elem = DragElem_Alloc(dragImage);
- elem->x = rects[i].x;
- elem->y = rects[i].y;
- elem->width = rects[i].width;
- elem->height = rects[i].height;
- }
+ ckfree((char *) rects);
+ rects = staticRects;
}
- else
- {
- totalWidth = 0;
- treeColumn = tree->columns;
- itemColumn = TreeItem_GetFirstColumn(tree, item);
- while (itemColumn != NULL)
- {
- if (!TreeColumn_Visible(treeColumn))
- goto nextColumn;
- width = TreeColumn_UseWidth(treeColumn);
- if (treeColumn == tree->columnTree)
- indent = TreeItem_Indent(tree, item);
- else
- indent = 0;
- drawArgs.style = TreeItemColumn_GetStyle(tree, itemColumn);
- if (drawArgs.style != NULL)
- {
- drawArgs.indent = indent;
- drawArgs.x = x + totalWidth;
- drawArgs.width = width;
- drawArgs.justify = TreeColumn_Justify(treeColumn);
- count = TreeStyle_NumElements(tree, drawArgs.style);
- STATIC_ALLOC(rects, XRectangle, count);
- count = TreeStyle_GetElemRects(&drawArgs, 0, NULL, rects);
- if (count == -1)
- {
- result = TCL_ERROR;
- goto doneAdd;
- }
- for (i = 0; i < count; i++)
- {
- elem = DragElem_Alloc(dragImage);
- elem->x = rects[i].x;
- elem->y = rects[i].y;
- elem->width = rects[i].width;
- elem->height = rects[i].height;
- }
- if (rects != staticRects)
- {
- ckfree((char *) rects);
- rects = staticRects;
- }
- }
- totalWidth += width;
+ }
+ totalWidth += width;
nextColumn:
- treeColumn = TreeColumn_Next(treeColumn);
- itemColumn = TreeItemColumn_GetNext(tree, itemColumn);
- }
- }
- dragImage->bounds[0] = 100000;
- dragImage->bounds[1] = 100000;
- dragImage->bounds[2] = -100000;
- dragImage->bounds[3] = -100000;
- for (elem = dragImage->elem;
- elem != NULL;
- elem = elem->next)
- {
- if (elem->x < dragImage->bounds[0])
- dragImage->bounds[0] = elem->x;
- if (elem->y < dragImage->bounds[1])
- dragImage->bounds[1] = elem->y;
- if (elem->x + elem->width > dragImage->bounds[2])
- dragImage->bounds[2] = elem->x + elem->width;
- if (elem->y + elem->height > dragImage->bounds[3])
- dragImage->bounds[3] = elem->y + elem->height;
- }
-doneAdd:
- if (rects != staticRects)
- ckfree((char *) rects);
- TreeDragImage_Display(tree->dragImage);
- return result;
+ treeColumn = TreeColumn_Next(treeColumn);
+ itemColumn = TreeItemColumn_GetNext(tree, itemColumn);
}
+ }
+ dragImage->bounds[0] = 100000;
+ dragImage->bounds[1] = 100000;
+ dragImage->bounds[2] = -100000;
+ dragImage->bounds[3] = -100000;
+ for (elem = dragImage->elem;
+ elem != NULL;
+ elem = elem->next)
+ {
+ if (elem->x < dragImage->bounds[0])
+ dragImage->bounds[0] = elem->x;
+ if (elem->y < dragImage->bounds[1])
+ dragImage->bounds[1] = elem->y;
+ if (elem->x + elem->width > dragImage->bounds[2])
+ dragImage->bounds[2] = elem->x + elem->width;
+ if (elem->y + elem->height > dragImage->bounds[3])
+ dragImage->bounds[3] = elem->y + elem->height;
+ }
+doneAdd:
+ if (rects != staticRects)
+ ckfree((char *) rects);
+ TreeDragImage_Display(tree->dragImage);
+ return result;
+ }
- /* T dragimage cget option */
- case COMMAND_CGET:
- {
- Tcl_Obj *resultObjPtr;
+ /* T dragimage cget option */
+ case COMMAND_CGET:
+ {
+ Tcl_Obj *resultObjPtr;
- if (objc != 4)
- {
- Tcl_WrongNumArgs(interp, 3, objv, "option");
- return TCL_ERROR;
- }
- resultObjPtr = Tk_GetOptionValue(interp, (char *) dragImage,
- dragImage->optionTable, objv[3], tree->tkwin);
- if (resultObjPtr == NULL)
- return TCL_ERROR;
- Tcl_SetObjResult(interp, resultObjPtr);
- break;
- }
+ if (objc != 4)
+ {
+ Tcl_WrongNumArgs(interp, 3, objv, "option");
+ return TCL_ERROR;
+ }
+ resultObjPtr = Tk_GetOptionValue(interp, (char *) dragImage,
+ dragImage->optionTable, objv[3], tree->tkwin);
+ if (resultObjPtr == NULL)
+ return TCL_ERROR;
+ Tcl_SetObjResult(interp, resultObjPtr);
+ break;
+ }
- /* T dragimage clear */
- case COMMAND_CLEAR:
- {
- if (objc != 3)
- {
- Tcl_WrongNumArgs(interp, 3, objv, (char *) NULL);
- return TCL_ERROR;
- }
- if (dragImage->elem != NULL)
- {
- DragElem *elem = dragImage->elem;
- TreeDragImage_Undisplay(tree->dragImage);
+ /* T dragimage clear */
+ case COMMAND_CLEAR:
+ {
+ if (objc != 3)
+ {
+ Tcl_WrongNumArgs(interp, 3, objv, (char *) NULL);
+ return TCL_ERROR;
+ }
+ if (dragImage->elem != NULL)
+ {
+ DragElem *elem = dragImage->elem;
+ TreeDragImage_Undisplay(tree->dragImage);
/* if (dragImage->visible)
- DragImage_Redraw(dragImage); */
- while (elem != NULL)
- elem = DragElem_Free(dragImage, elem);
- dragImage->elem = NULL;
- }
- break;
- }
+ DragImage_Redraw(dragImage); */
+ while (elem != NULL)
+ elem = DragElem_Free(dragImage, elem);
+ dragImage->elem = NULL;
+ }
+ break;
+ }
- /* T dragimage configure ?option? ?value? ?option value ...? */
- case COMMAND_CONFIGURE:
- {
- Tcl_Obj *resultObjPtr;
+ /* T dragimage configure ?option? ?value? ?option value ...? */
+ case COMMAND_CONFIGURE:
+ {
+ Tcl_Obj *resultObjPtr;
- if (objc < 3)
- {
- Tcl_WrongNumArgs(interp, 3, objv, "?option? ?value?");
- return TCL_ERROR;
- }
- if (objc <= 4)
- {
- resultObjPtr = Tk_GetOptionInfo(interp, (char *) dragImage,
- dragImage->optionTable,
- (objc == 3) ? (Tcl_Obj *) NULL : objv[3],
- tree->tkwin);
- if (resultObjPtr == NULL)
- return TCL_ERROR;
- Tcl_SetObjResult(interp, resultObjPtr);
- break;
- }
- return DragImage_Config(dragImage, objc - 3, objv + 3);
- }
+ if (objc < 3)
+ {
+ Tcl_WrongNumArgs(interp, 3, objv, "?option? ?value?");
+ return TCL_ERROR;
+ }
+ if (objc <= 4)
+ {
+ resultObjPtr = Tk_GetOptionInfo(interp, (char *) dragImage,
+ dragImage->optionTable,
+ (objc == 3) ? (Tcl_Obj *) NULL : objv[3],
+ tree->tkwin);
+ if (resultObjPtr == NULL)
+ return TCL_ERROR;
+ Tcl_SetObjResult(interp, resultObjPtr);
+ break;
+ }
+ return DragImage_Config(dragImage, objc - 3, objv + 3);
+ }
- /* T dragimage offset ?x y? */
- case COMMAND_OFFSET:
- {
- int x, y;
+ /* T dragimage offset ?x y? */
+ case COMMAND_OFFSET:
+ {
+ int x, y;
- if (objc != 3 && objc != 5)
- {
- Tcl_WrongNumArgs(interp, 3, objv, "?x y?");
- return TCL_ERROR;
- }
- if (objc == 3)
- {
- FormatResult(interp, "%d %d", dragImage->x, dragImage->y);
- break;
- }
- if (Tcl_GetIntFromObj(interp, objv[3], &x) != TCL_OK)
- return TCL_ERROR;
- if (Tcl_GetIntFromObj(interp, objv[4], &y) != TCL_OK)
- return TCL_ERROR;
- TreeDragImage_Undisplay(tree->dragImage);
+ if (objc != 3 && objc != 5)
+ {
+ Tcl_WrongNumArgs(interp, 3, objv, "?x y?");
+ return TCL_ERROR;
+ }
+ if (objc == 3)
+ {
+ FormatResult(interp, "%d %d", dragImage->x, dragImage->y);
+ break;
+ }
+ if (Tcl_GetIntFromObj(interp, objv[3], &x) != TCL_OK)
+ return TCL_ERROR;
+ if (Tcl_GetIntFromObj(interp, objv[4], &y) != TCL_OK)
+ return TCL_ERROR;
+ TreeDragImage_Undisplay(tree->dragImage);
/* if (dragImage->visible)
- DragImage_Redraw(dragImage); */
- dragImage->x = x;
- dragImage->y = y;
- TreeDragImage_Display(tree->dragImage);
- break;
- }
+ DragImage_Redraw(dragImage); */
+ dragImage->x = x;
+ dragImage->y = y;
+ TreeDragImage_Display(tree->dragImage);
+ break;
}
+ }
- return TCL_OK;
+ return TCL_OK;
}
diff --git a/generic/tkTreeElem.h b/generic/tkTreeElem.h
index 49c27e2..84e03ce 100644
--- a/generic/tkTreeElem.h
+++ b/generic/tkTreeElem.h
@@ -5,7 +5,7 @@
*
* Copyright (c) 2002-2005 Tim Baker
*
- * RCS: @(#) $Id: tkTreeElem.h,v 1.16 2005/07/10 22:17:47 treectrl Exp $
+ * RCS: @(#) $Id: tkTreeElem.h,v 1.17 2005/09/16 23:24:33 treectrl Exp $
*/
typedef struct ElementType ElementType;
@@ -14,89 +14,89 @@ typedef struct ElementArgs ElementArgs;
struct ElementArgs
{
- TreeCtrl *tree;
- Element *elem;
- int state;
- struct {
- TreeItem item;
- TreeItemColumn column;
- } create;
- struct {
- int noop;
- } delete;
- struct {
- int objc;
- Tcl_Obj *CONST *objv;
- int flagSelf;
- } config;
- struct {
- int x;
- int y;
- int width;
- int height;
+ TreeCtrl *tree;
+ Element *elem;
+ int state;
+ struct {
+ TreeItem item;
+ TreeItemColumn column;
+ } create;
+ struct {
+ int noop;
+ } delete;
+ struct {
+ int objc;
+ Tcl_Obj *CONST *objv;
+ int flagSelf;
+ } config;
+ struct {
+ int x;
+ int y;
+ int width;
+ int height;
#define STICKY_W 0x1000 /* These values must match ELF_STICKY_xxx */
#define STICKY_N 0x2000
#define STICKY_E 0x4000
#define STICKY_S 0x8000
- int sticky;
- Drawable drawable;
- } display;
- struct {
- int fixedWidth;
- int fixedHeight;
- int maxWidth;
- int maxHeight;
- int width;
- int height;
- } needed;
- struct {
- int fixedWidth;
- int height;
- } height;
- struct {
- int flagTree;
- int flagMaster;
- int flagSelf;
- } change;
- struct {
- int state1;
- int state2;
- } states;
- struct {
- Tcl_Obj *obj;
- } actual;
- struct {
- int visible;
- } screen;
+ int sticky;
+ Drawable drawable;
+ } display;
+ struct {
+ int fixedWidth;
+ int fixedHeight;
+ int maxWidth;
+ int maxHeight;
+ int width;
+ int height;
+ } needed;
+ struct {
+ int fixedWidth;
+ int height;
+ } height;
+ struct {
+ int flagTree;
+ int flagMaster;
+ int flagSelf;
+ } change;
+ struct {
+ int state1;
+ int state2;
+ } states;
+ struct {
+ Tcl_Obj *obj;
+ } actual;
+ struct {
+ int visible;
+ } screen;
};
struct ElementType
{
- char *name; /* "image", "text" */
- int size; /* size of an Element */
- Tk_OptionSpec *optionSpecs;
- Tk_OptionTable optionTable;
- int (*createProc)(ElementArgs *args);
- void (*deleteProc)(ElementArgs *args);
- int (*configProc)(ElementArgs *args);
- void (*displayProc)(ElementArgs *args);
- void (*neededProc)(ElementArgs *args);
- void (*heightProc)(ElementArgs *args);
- int (*changeProc)(ElementArgs *args);
- int (*stateProc)(ElementArgs *args);
- int (*undefProc)(ElementArgs *args);
- int (*actualProc)(ElementArgs *args);
- void (*onScreenProc)(ElementArgs *args);
- ElementType *next;
+ char *name; /* "image", "text" */
+ int size; /* size of an Element */
+ Tk_OptionSpec *optionSpecs;
+ Tk_OptionTable optionTable;
+ int (*createProc)(ElementArgs *args);
+ void (*deleteProc)(ElementArgs *args);
+ int (*configProc)(ElementArgs *args);
+ void (*displayProc)(ElementArgs *args);
+ void (*neededProc)(ElementArgs *args);
+ void (*heightProc)(ElementArgs *args);
+ int (*changeProc)(ElementArgs *args);
+ int (*stateProc)(ElementArgs *args);
+ int (*undefProc)(ElementArgs *args);
+ int (*actualProc)(ElementArgs *args);
+ void (*onScreenProc)(ElementArgs *args);
+ ElementType *next;
};
/* list of these for each style */
struct Element
{
- Tk_Uid name; /* "elem2", "eText" etc */
- ElementType *typePtr;
- Element *master; /* NULL if this is master */
- /* type-specific data here */
+ Tk_Uid name; /* "elem2", "eText" etc */
+ ElementType *typePtr;
+ Element *master; /* NULL if this is master */
+ /* type-specific data here */
};
extern ElementType elemTypeBitmap;
@@ -122,28 +122,28 @@ extern TreeIterate Tree_ElementIterateNext(TreeIterate iter_);
extern Element *Tree_ElementIterateGet(TreeIterate iter_);
extern void Tree_ElementIterateChanged(TreeIterate iter_, int mask);
extern void Tree_ElementChangedItself(TreeCtrl *tree, TreeItem item,
- TreeItemColumn column, Element *elem, int mask);
-
+ TreeItemColumn column, Element *elem, int mask);
+
typedef struct TreeCtrlStubs TreeCtrlStubs;
struct TreeCtrlStubs
{
- int (*TreeCtrl_RegisterElementType)(Tcl_Interp *interp, ElementType *typePtr);
- void (*Tree_RedrawElement)(TreeCtrl *tree, TreeItem item, Element *elem);
- TreeIterate (*Tree_ElementIterateBegin)(TreeCtrl *tree, ElementType *elemTypePtr);
- TreeIterate (*Tree_ElementIterateNext)(TreeIterate iter_);
- Element *(*Tree_ElementIterateGet)(TreeIterate iter_);
- void (*Tree_ElementIterateChanged)(TreeIterate iter_, int mask);
- void (*PerStateInfo_Free)(TreeCtrl *tree, PerStateType *typePtr, PerStateInfo *pInfo);
- int (*PerStateInfo_FromObj)(TreeCtrl *tree, StateFromObjProc proc, PerStateType *typePtr, PerStateInfo *pInfo);
- PerStateData *(*PerStateInfo_ForState)(TreeCtrl *tree, PerStateType *typePtr, PerStateInfo *pInfo, int state, int *match);
- Tcl_Obj *(*PerStateInfo_ObjForState)(TreeCtrl *tree, PerStateType *typePtr, PerStateInfo *pInfo, int state, int *match);
- int (*PerStateInfo_Undefine)(TreeCtrl *tree, PerStateType *typePtr, PerStateInfo *pInfo, int state);
- PerStateType *pstBoolean;
- int (*PerStateBoolean_ForState)(TreeCtrl *tree, PerStateInfo *pInfo, int state, int *match);
- void (*PSTSave)(PerStateInfo *pInfo, PerStateInfo *pSave);
- void (*PSTRestore)(TreeCtrl *tree, PerStateType *typePtr, PerStateInfo *pInfo, PerStateInfo *pSave);
- int (*TreeStateFromObj)(TreeCtrl *tree, Tcl_Obj *obj, int *stateOff, int *stateOn);
- int (*BooleanCO_Init)(Tk_OptionSpec *optionTable, CONST char *optionName);
- int (*StringTableCO_Init)(Tk_OptionSpec *optionTable, CONST char *optionName, CONST char **tablePtr);
+ int (*TreeCtrl_RegisterElementType)(Tcl_Interp *interp, ElementType *typePtr);
+ void (*Tree_RedrawElement)(TreeCtrl *tree, TreeItem item, Element *elem);
+ TreeIterate (*Tree_ElementIterateBegin)(TreeCtrl *tree, ElementType *elemTypePtr);
+ TreeIterate (*Tree_ElementIterateNext)(TreeIterate iter_);
+ Element *(*Tree_ElementIterateGet)(TreeIterate iter_);
+ void (*Tree_ElementIterateChanged)(TreeIterate iter_, int mask);
+ void (*PerStateInfo_Free)(TreeCtrl *tree, PerStateType *typePtr, PerStateInfo *pInfo);
+ int (*PerStateInfo_FromObj)(TreeCtrl *tree, StateFromObjProc proc, PerStateType *typePtr, PerStateInfo *pInfo);
+ PerStateData *(*PerStateInfo_ForState)(TreeCtrl *tree, PerStateType *typePtr, PerStateInfo *pInfo, int state, int *match);
+ Tcl_Obj *(*PerStateInfo_ObjForState)(TreeCtrl *tree, PerStateType *typePtr, PerStateInfo *pInfo, int state, int *match);
+ int (*PerStateInfo_Undefine)(TreeCtrl *tree, PerStateType *typePtr, PerStateInfo *pInfo, int state);
+ PerStateType *pstBoolean;
+ int (*PerStateBoolean_ForState)(TreeCtrl *tree, PerStateInfo *pInfo, int state, int *match);
+ void (*PSTSave)(PerStateInfo *pInfo, PerStateInfo *pSave);
+ void (*PSTRestore)(TreeCtrl *tree, PerStateType *typePtr, PerStateInfo *pInfo, PerStateInfo *pSave);
+ int (*TreeStateFromObj)(TreeCtrl *tree, Tcl_Obj *obj, int *stateOff, int *stateOn);
+ int (*BooleanCO_Init)(Tk_OptionSpec *optionTable, CONST char *optionName);
+ int (*StringTableCO_Init)(Tk_OptionSpec *optionTable, CONST char *optionName, CONST char **tablePtr);
};
diff --git a/generic/tkTreeMarquee.c b/generic/tkTreeMarquee.c
index 18ee2d0..22c0532 100644
--- a/generic/tkTreeMarquee.c
+++ b/generic/tkTreeMarquee.c
@@ -5,7 +5,7 @@
*
* Copyright (c) 2002-2005 Tim Baker
*
- * RCS: @(#) $Id: tkTreeMarquee.c,v 1.5 2005/07/12 02:50:34 treectrl Exp $
+ * RCS: @(#) $Id: tkTreeMarquee.c,v 1.6 2005/09/16 23:24:54 treectrl Exp $
*/
#include "tkTreeCtrl.h"
@@ -14,362 +14,362 @@ typedef struct Marquee Marquee;
struct Marquee
{
- TreeCtrl *tree;
- Tk_OptionTable optionTable;
- int visible;
- int x1, y1, x2, y2;
- int onScreen;
- int sx, sy;
+ TreeCtrl *tree;
+ Tk_OptionTable optionTable;
+ int visible;
+ int x1, y1, x2, y2;
+ int onScreen;
+ int sx, sy;
};
#define MARQ_CONF_VISIBLE 0x0001
static Tk_OptionSpec optionSpecs[] = {
- {TK_OPTION_BOOLEAN, "-visible", (char *) NULL, (char *) NULL,
- "0", -1, Tk_Offset(Marquee, visible),
- 0, (ClientData) NULL, MARQ_CONF_VISIBLE},
- {TK_OPTION_END, (char *) NULL, (char *) NULL, (char *) NULL,
- (char *) NULL, 0, -1, 0, 0, 0}
+ {TK_OPTION_BOOLEAN, "-visible", (char *) NULL, (char *) NULL,
+ "0", -1, Tk_Offset(Marquee, visible),
+ 0, (ClientData) NULL, MARQ_CONF_VISIBLE},
+ {TK_OPTION_END, (char *) NULL, (char *) NULL, (char *) NULL,
+ (char *) NULL, 0, -1, 0, 0, 0}
};
int TreeMarquee_Init(TreeCtrl *tree)
{
- Marquee *marquee;
-
- marquee = (Marquee *) ckalloc(sizeof(Marquee));
- memset(marquee, '\0', sizeof(Marquee));
- marquee->tree = tree;
- marquee->optionTable = Tk_CreateOptionTable(tree->interp, optionSpecs);
- if (Tk_InitOptions(tree->interp, (char *) marquee, marquee->optionTable,
- tree->tkwin) != TCL_OK)
- {
- WFREE(marquee, Marquee);
- return TCL_ERROR;
- }
- tree->marquee = (TreeMarquee) marquee;
- return TCL_OK;
+ Marquee *marquee;
+
+ marquee = (Marquee *) ckalloc(sizeof(Marquee));
+ memset(marquee, '\0', sizeof(Marquee));
+ marquee->tree = tree;
+ marquee->optionTable = Tk_CreateOptionTable(tree->interp, optionSpecs);
+ if (Tk_InitOptions(tree->interp, (char *) marquee, marquee->optionTable,
+ tree->tkwin) != TCL_OK)
+ {
+ WFREE(marquee, Marquee);
+ return TCL_ERROR;
+ }
+ tree->marquee = (TreeMarquee) marquee;
+ return TCL_OK;
}
void TreeMarquee_Free(TreeMarquee marquee_)
{
- Marquee *marquee = (Marquee *) marquee_;
+ Marquee *marquee = (Marquee *) marquee_;
- Tk_FreeConfigOptions((char *) marquee, marquee->optionTable,
- marquee->tree->tkwin);
- WFREE(marquee, Marquee);
+ Tk_FreeConfigOptions((char *) marquee, marquee->optionTable,
+ marquee->tree->tkwin);
+ WFREE(marquee, Marquee);
}
void TreeMarquee_Display(TreeMarquee marquee_)
{
- Marquee *marquee = (Marquee *) marquee_;
- TreeCtrl *tree = marquee->tree;
-
- if (!marquee->onScreen && marquee->visible)
- {
- marquee->sx = 0 - tree->xOrigin;
- marquee->sy = 0 - tree->yOrigin;
- TreeMarquee_Draw(marquee_, Tk_WindowId(tree->tkwin), marquee->sx, marquee->sy);
- marquee->onScreen = TRUE;
- }
+ Marquee *marquee = (Marquee *) marquee_;
+ TreeCtrl *tree = marquee->tree;
+
+ if (!marquee->onScreen && marquee->visible)
+ {
+ marquee->sx = 0 - tree->xOrigin;
+ marquee->sy = 0 - tree->yOrigin;
+ TreeMarquee_Draw(marquee_, Tk_WindowId(tree->tkwin), marquee->sx, marquee->sy);
+ marquee->onScreen = TRUE;
+ }
}
void TreeMarquee_Undisplay(TreeMarquee marquee_)
{
- Marquee *marquee = (Marquee *) marquee_;
- TreeCtrl *tree = marquee->tree;
-
- if (marquee->onScreen)
- {
- TreeMarquee_Draw(marquee_, Tk_WindowId(tree->tkwin), marquee->sx, marquee->sy);
- marquee->onScreen = FALSE;
- }
+ Marquee *marquee = (Marquee *) marquee_;
+ TreeCtrl *tree = marquee->tree;
+
+ if (marquee->onScreen)
+ {
+ TreeMarquee_Draw(marquee_, Tk_WindowId(tree->tkwin), marquee->sx, marquee->sy);
+ marquee->onScreen = FALSE;
+ }
}
void TreeMarquee_Draw(TreeMarquee marquee_, Drawable drawable, int x1, int y1)
{
- Marquee *marquee = (Marquee *) marquee_;
- TreeCtrl *tree = marquee->tree;
- int x, y, w, h;
- DotState dotState;
+ Marquee *marquee = (Marquee *) marquee_;
+ TreeCtrl *tree = marquee->tree;
+ int x, y, w, h;
+ DotState dotState;
/* if (!marquee->visible)
- return; */
+ return; */
- x = MIN(marquee->x1, marquee->x2);
- w = abs(marquee->x1 - marquee->x2) + 1;
- y = MIN(marquee->y1, marquee->y2);
- h = abs(marquee->y1 - marquee->y2) + 1;
+ x = MIN(marquee->x1, marquee->x2);
+ w = abs(marquee->x1 - marquee->x2) + 1;
+ y = MIN(marquee->y1, marquee->y2);
+ h = abs(marquee->y1 - marquee->y2) + 1;
- DotRect_Setup(tree, drawable, &dotState);
- DotRect_Draw(&dotState, x1 + x, y1 + y, w, h);
- DotRect_Restore(&dotState);
+ DotRect_Setup(tree, drawable, &dotState);
+ DotRect_Draw(&dotState, x1 + x, y1 + y, w, h);
+ DotRect_Restore(&dotState);
}
static int Marquee_Config(Marquee *marquee, int objc, Tcl_Obj *CONST objv[])
{
- TreeCtrl *tree = marquee->tree;
- Tk_SavedOptions savedOptions;
+ TreeCtrl *tree = marquee->tree;
+ Tk_SavedOptions savedOptions;
int error;
Tcl_Obj *errorResult = NULL;
- int mask;
+ int mask;
- for (error = 0; error <= 1; error++)
+ for (error = 0; error <= 1; error++)
+ {
+ if (error == 0)
{
- if (error == 0)
- {
- if (Tk_SetOptions(tree->interp, (char *) marquee, marquee->optionTable,
- objc, objv, tree->tkwin, &savedOptions, &mask) != TCL_OK)
- {
- mask = 0;
- continue;
- }
-
- /* xxx */
-
- Tk_FreeSavedOptions(&savedOptions);
- break;
- }
- else
- {
- errorResult = Tcl_GetObjResult(tree->interp);
- Tcl_IncrRefCount(errorResult);
- Tk_RestoreSavedOptions(&savedOptions);
-
- /* xxx */
-
- Tcl_SetObjResult(tree->interp, errorResult);
- Tcl_DecrRefCount(errorResult);
- return TCL_ERROR;
- }
- }
+ if (Tk_SetOptions(tree->interp, (char *) marquee, marquee->optionTable,
+ objc, objv, tree->tkwin, &savedOptions, &mask) != TCL_OK)
+ {
+ mask = 0;
+ continue;
+ }
+
+ /* xxx */
- if (mask & MARQ_CONF_VISIBLE)
+ Tk_FreeSavedOptions(&savedOptions);
+ break;
+ }
+ else
{
- TreeMarquee_Undisplay((TreeMarquee) marquee);
- TreeMarquee_Display((TreeMarquee) marquee);
+ errorResult = Tcl_GetObjResult(tree->interp);
+ Tcl_IncrRefCount(errorResult);
+ Tk_RestoreSavedOptions(&savedOptions);
+
+ /* xxx */
+
+ Tcl_SetObjResult(tree->interp, errorResult);
+ Tcl_DecrRefCount(errorResult);
+ return TCL_ERROR;
}
+ }
+
+ if (mask & MARQ_CONF_VISIBLE)
+ {
+ TreeMarquee_Undisplay((TreeMarquee) marquee);
+ TreeMarquee_Display((TreeMarquee) marquee);
+ }
- return TCL_OK;
+ return TCL_OK;
}
int TreeMarqueeCmd(ClientData clientData, Tcl_Interp *interp, int objc,
Tcl_Obj *CONST objv[])
{
- TreeCtrl *tree = (TreeCtrl *) clientData;
- Marquee *marquee = (Marquee *) tree->marquee;
- static CONST char *commandNames[] = { "anchor", "cget", "configure",
- "coords", "corner", "identify", (char *) NULL };
- enum { COMMAND_ANCHOR, COMMAND_CGET, COMMAND_CONFIGURE, COMMAND_COORDS,
- COMMAND_CORNER, COMMAND_IDENTIFY };
- int index;
-
- if (objc < 3)
+ TreeCtrl *tree = (TreeCtrl *) clientData;
+ Marquee *marquee = (Marquee *) tree->marquee;
+ static CONST char *commandNames[] = { "anchor", "cget", "configure",
+ "coords", "corner", "identify", (char *) NULL };
+ enum { COMMAND_ANCHOR, COMMAND_CGET, COMMAND_CONFIGURE, COMMAND_COORDS,
+ COMMAND_CORNER, COMMAND_IDENTIFY };
+ int index;
+
+ if (objc < 3)
+ {
+ Tcl_WrongNumArgs(interp, 2, objv, "command ?arg arg ...?");
+ return TCL_ERROR;
+ }
+
+ if (Tcl_GetIndexFromObj(interp, objv[2], commandNames, "command", 0,
+ &index) != TCL_OK)
+ {
+ return TCL_ERROR;
+ }
+
+ switch (index)
+ {
+ /* T marquee anchor ?x y?*/
+ case COMMAND_ANCHOR:
+ {
+ int x, y;
+
+ if (objc != 3 && objc != 5)
+ {
+ Tcl_WrongNumArgs(interp, 3, objv, "?x y?");
+ return TCL_ERROR;
+ }
+ if (objc == 3)
+ {
+ FormatResult(interp, "%d %d", marquee->x1, marquee->y1);
+ break;
+ }
+ if (Tcl_GetIntFromObj(interp, objv[3], &x) != TCL_OK)
+ return TCL_ERROR;
+ if (Tcl_GetIntFromObj(interp, objv[4], &y) != TCL_OK)
+ return TCL_ERROR;
+ if ((x == marquee->x1) && (y == marquee->y1))
+ break;
+ TreeMarquee_Undisplay(tree->marquee);
+ marquee->x1 = x;
+ marquee->y1 = y;
+ TreeMarquee_Display(tree->marquee);
+ break;
+ }
+
+ /* T marquee cget option */
+ case COMMAND_CGET:
+ {
+ Tcl_Obj *resultObjPtr;
+
+ if (objc != 4)
+ {
+ Tcl_WrongNumArgs(interp, 3, objv, "option");
+ return TCL_ERROR;
+ }
+ resultObjPtr = Tk_GetOptionValue(interp, (char *) marquee,
+ marquee->optionTable, objv[3], tree->tkwin);
+ if (resultObjPtr == NULL)
+ return TCL_ERROR;
+ Tcl_SetObjResult(interp, resultObjPtr);
+ break;
+ }
+
+ /* T marquee configure ?option? ?value? ?option value ...? */
+ case COMMAND_CONFIGURE:
+ {
+ Tcl_Obj *resultObjPtr;
+
+ if (objc < 3)
+ {
+ Tcl_WrongNumArgs(interp, 3, objv, "?option? ?value?");
+ return TCL_ERROR;
+ }
+ if (objc <= 4)
+ {
+ resultObjPtr = Tk_GetOptionInfo(interp, (char *) marquee,
+ marquee->optionTable,
+ (objc == 3) ? (Tcl_Obj *) NULL : objv[3],
+ tree->tkwin);
+ if (resultObjPtr == NULL)
+ return TCL_ERROR;
+ Tcl_SetObjResult(interp, resultObjPtr);
+ break;
+ }
+ return Marquee_Config(marquee, objc - 3, objv + 3);
+ }
+
+ /* T marquee coords ?x y x y? */
+ case COMMAND_COORDS:
{
- Tcl_WrongNumArgs(interp, 2, objv, "command ?arg arg ...?");
+ int x1, y1, x2, y2;
+
+ if (objc != 3 && objc != 7)
+ {
+ Tcl_WrongNumArgs(interp, 3, objv, "?x y x y?");
+ return TCL_ERROR;
+ }
+ if (objc == 3)
+ {
+ FormatResult(interp, "%d %d %d %d", marquee->x1, marquee->y1,
+ marquee->x2, marquee->y2);
+ break;
+ }
+ if (Tcl_GetIntFromObj(interp, objv[3], &x1) != TCL_OK)
+ return TCL_ERROR;
+ if (Tcl_GetIntFromObj(interp, objv[4], &y1) != TCL_OK)
+ return TCL_ERROR;
+ if (Tcl_GetIntFromObj(interp, objv[5], &x2) != TCL_OK)
return TCL_ERROR;
+ if (Tcl_GetIntFromObj(interp, objv[6], &y2) != TCL_OK)
+ return TCL_ERROR;
+ if (x1 == marquee->x1 && y1 == marquee->y1 &&
+ x2 == marquee->x2 && y2 == marquee->y2)
+ break;
+ TreeMarquee_Undisplay(tree->marquee);
+ marquee->x1 = x1;
+ marquee->y1 = y1;
+ marquee->x2 = x2;
+ marquee->y2 = y2;
+ TreeMarquee_Display(tree->marquee);
+ break;
}
- if (Tcl_GetIndexFromObj(interp, objv[2], commandNames, "command", 0,
- &index) != TCL_OK)
+ /* T marquee corner ?x y?*/
+ case COMMAND_CORNER:
{
+ int x, y;
+
+ if (objc != 3 && objc != 5)
+ {
+ Tcl_WrongNumArgs(interp, 3, objv, "?x y?");
+ return TCL_ERROR;
+ }
+ if (objc == 3)
+ {
+ FormatResult(interp, "%d %d", marquee->x2, marquee->y2);
+ break;
+ }
+ if (Tcl_GetIntFromObj(interp, objv[3], &x) != TCL_OK)
return TCL_ERROR;
+ if (Tcl_GetIntFromObj(interp, objv[4], &y) != TCL_OK)
+ return TCL_ERROR;
+ if (x == marquee->x2 && y == marquee->y2)
+ break;
+ TreeMarquee_Undisplay(tree->marquee);
+ marquee->x2 = x;
+ marquee->y2 = y;
+ TreeMarquee_Display(tree->marquee);
+ break;
}
- switch (index)
+ /* T marquee identify */
+ case COMMAND_IDENTIFY:
{
- /* T marquee anchor ?x y?*/
- case COMMAND_ANCHOR:
- {
- int x, y;
-
- if (objc != 3 && objc != 5)
- {
- Tcl_WrongNumArgs(interp, 3, objv, "?x y?");
- return TCL_ERROR;
- }
- if (objc == 3)
- {
- FormatResult(interp, "%d %d", marquee->x1, marquee->y1);
- break;
- }
- if (Tcl_GetIntFromObj(interp, objv[3], &x) != TCL_OK)
- return TCL_ERROR;
- if (Tcl_GetIntFromObj(interp, objv[4], &y) != TCL_OK)
- return TCL_ERROR;
- if ((x == marquee->x1) && (y == marquee->y1))
- break;
- TreeMarquee_Undisplay(tree->marquee);
- marquee->x1 = x;
- marquee->y1 = y;
- TreeMarquee_Display(tree->marquee);
- break;
- }
-
- /* T marquee cget option */
- case COMMAND_CGET:
- {
- Tcl_Obj *resultObjPtr;
-
- if (objc != 4)
- {
- Tcl_WrongNumArgs(interp, 3, objv, "option");
- return TCL_ERROR;
- }
- resultObjPtr = Tk_GetOptionValue(interp, (char *) marquee,
- marquee->optionTable, objv[3], tree->tkwin);
- if (resultObjPtr == NULL)
- return TCL_ERROR;
- Tcl_SetObjResult(interp, resultObjPtr);
- break;
- }
-
- /* T marquee configure ?option? ?value? ?option value ...? */
- case COMMAND_CONFIGURE:
- {
- Tcl_Obj *resultObjPtr;
-
- if (objc < 3)
- {
- Tcl_WrongNumArgs(interp, 3, objv, "?option? ?value?");
- return TCL_ERROR;
- }
- if (objc <= 4)
- {
- resultObjPtr = Tk_GetOptionInfo(interp, (char *) marquee,
- marquee->optionTable,
- (objc == 3) ? (Tcl_Obj *) NULL : objv[3],
- tree->tkwin);
- if (resultObjPtr == NULL)
- return TCL_ERROR;
- Tcl_SetObjResult(interp, resultObjPtr);
- break;
- }
- return Marquee_Config(marquee, objc - 3, objv + 3);
- }
-
- /* T marquee coords ?x y x y? */
- case COMMAND_COORDS:
- {
- int x1, y1, x2, y2;
-
- if (objc != 3 && objc != 7)
- {
- Tcl_WrongNumArgs(interp, 3, objv, "?x y x y?");
- return TCL_ERROR;
- }
- if (objc == 3)
- {
- FormatResult(interp, "%d %d %d %d", marquee->x1, marquee->y1,
- marquee->x2, marquee->y2);
- break;
- }
- if (Tcl_GetIntFromObj(interp, objv[3], &x1) != TCL_OK)
- return TCL_ERROR;
- if (Tcl_GetIntFromObj(interp, objv[4], &y1) != TCL_OK)
- return TCL_ERROR;
- if (Tcl_GetIntFromObj(interp, objv[5], &x2) != TCL_OK)
- return TCL_ERROR;
- if (Tcl_GetIntFromObj(interp, objv[6], &y2) != TCL_OK)
- return TCL_ERROR;
- if (x1 == marquee->x1 && y1 == marquee->y1 &&
- x2 == marquee->x2 && y2 == marquee->y2)
- break;
- TreeMarquee_Undisplay(tree->marquee);
- marquee->x1 = x1;
- marquee->y1 = y1;
- marquee->x2 = x2;
- marquee->y2 = y2;
- TreeMarquee_Display(tree->marquee);
- break;
- }
-
- /* T marquee corner ?x y?*/
- case COMMAND_CORNER:
- {
- int x, y;
-
- if (objc != 3 && objc != 5)
- {
- Tcl_WrongNumArgs(interp, 3, objv, "?x y?");
- return TCL_ERROR;
- }
- if (objc == 3)
- {
- FormatResult(interp, "%d %d", marquee->x2, marquee->y2);
- break;
- }
- if (Tcl_GetIntFromObj(interp, objv[3], &x) != TCL_OK)
- return TCL_ERROR;
- if (Tcl_GetIntFromObj(interp, objv[4], &y) != TCL_OK)
- return TCL_ERROR;
- if (x == marquee->x2 && y == marquee->y2)
- break;
- TreeMarquee_Undisplay(tree->marquee);
- marquee->x2 = x;
- marquee->y2 = y;
- TreeMarquee_Display(tree->marquee);
- break;
- }
-
- /* T marquee identify */
- case COMMAND_IDENTIFY:
- {
- int x1, y1, x2, y2, n = 0;
- int totalWidth = Tree_TotalWidth(tree);
- int totalHeight = Tree_TotalHeight(tree);
- TreeItem *items;
- Tcl_Obj *listObj;
-
- if (objc != 3)
- {
- Tcl_WrongNumArgs(interp, 3, objv, (char *) NULL);
- return TCL_ERROR;
- }
-
- x1 = MIN(marquee->x1, marquee->x2);
- x2 = MAX(marquee->x1, marquee->x2);
- y1 = MIN(marquee->y1, marquee->y2);
- y2 = MAX(marquee->y1, marquee->y2);
-
- if (x2 <= 0)
- break;
- if (x1 >= totalWidth)
- break;
-
- if (y2 <= 0)
- break;
- if (y1 >= totalHeight)
- break;
-
- if (x1 < 0)
- x1 = 0;
- if (x2 > totalWidth)
- x2 = totalWidth;
-
- if (y1 < 0)
- y1 = 0;
- if (y2 > totalHeight)
- y2 = totalHeight;
-
- items = Tree_ItemsInArea(tree, x1, y1, x2, y2);
- if (items == NULL)
- break;
-
- listObj = Tcl_NewListObj(0, NULL);
- while (items[n] != NULL)
- {
- Tcl_Obj *subListObj = Tcl_NewListObj(0, NULL);
- Tcl_ListObjAppendElement(interp, subListObj,
- TreeItem_ToObj(tree, items[n]));
- TreeItem_Identify2(tree, items[n], x1, y1, x2, y2, subListObj);
- Tcl_ListObjAppendElement(interp, listObj, subListObj);
- n++;
- }
- ckfree((char *) items);
- Tcl_SetObjResult(interp, listObj);
- break;
- }
+ int x1, y1, x2, y2, n = 0;
+ int totalWidth = Tree_TotalWidth(tree);
+ int totalHeight = Tree_TotalHeight(tree);
+ TreeItem *items;
+ Tcl_Obj *listObj;
+
+ if (objc != 3)
+ {
+ Tcl_WrongNumArgs(interp, 3, objv, (char *) NULL);
+ return TCL_ERROR;
+ }
+
+ x1 = MIN(marquee->x1, marquee->x2);
+ x2 = MAX(marquee->x1, marquee->x2);
+ y1 = MIN(marquee->y1, marquee->y2);
+ y2 = MAX(marquee->y1, marquee->y2);
+
+ if (x2 <= 0)
+ break;
+ if (x1 >= totalWidth)
+ break;
+
+ if (y2 <= 0)
+ break;
+ if (y1 >= totalHeight)
+ break;
+
+ if (x1 < 0)
+ x1 = 0;
+ if (x2 > totalWidth)
+ x2 = totalWidth;
+
+ if (y1 < 0)
+ y1 = 0;
+ if (y2 > totalHeight)
+ y2 = totalHeight;
+
+ items = Tree_ItemsInArea(tree, x1, y1, x2, y2);
+ if (items == NULL)
+ break;
+
+ listObj = Tcl_NewListObj(0, NULL);
+ while (items[n] != NULL)
+ {
+ Tcl_Obj *subListObj = Tcl_NewListObj(0, NULL);
+ Tcl_ListObjAppendElement(interp, subListObj,
+ TreeItem_ToObj(tree, items[n]));
+ TreeItem_Identify2(tree, items[n], x1, y1, x2, y2, subListObj);
+ Tcl_ListObjAppendElement(interp, listObj, subListObj);
+ n++;
+ }
+ ckfree((char *) items);
+ Tcl_SetObjResult(interp, listObj);
+ break;
}
+ }
- return TCL_OK;
+ return TCL_OK;
}
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 */