summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authorjenglish <jenglish@flightlab.com>2007-10-15 15:03:40 (GMT)
committerjenglish <jenglish@flightlab.com>2007-10-15 15:03:40 (GMT)
commit410da9d556a7306f0b2bea77db33c15a7375c315 (patch)
tree3b6a11da974ad354ed48318afb741c497b082331 /generic
parentefc99bc15db0e9e7a9b41476cff1119112348d7b (diff)
downloadtk-410da9d556a7306f0b2bea77db33c15a7375c315.zip
tk-410da9d556a7306f0b2bea77db33c15a7375c315.tar.gz
tk-410da9d556a7306f0b2bea77db33c15a7375c315.tar.bz2
generic/ttk/ttkTreeview.c: Store pointer to column table entry
instead of column index in columnNames hash table. This avoids the need for the evil PTR2INT and INT2PTR macros, and simplifies things a bit.
Diffstat (limited to 'generic')
-rw-r--r--generic/ttk/ttkTheme.h24
-rw-r--r--generic/ttk/ttkTreeview.c88
2 files changed, 39 insertions, 73 deletions
diff --git a/generic/ttk/ttkTheme.h b/generic/ttk/ttkTheme.h
index 1f69a24..1567cd0 100644
--- a/generic/ttk/ttkTheme.h
+++ b/generic/ttk/ttkTheme.h
@@ -1,4 +1,4 @@
-/* $Id: ttkTheme.h,v 1.9 2007/10/15 07:24:49 das Exp $
+/* $Id: ttkTheme.h,v 1.10 2007/10/15 15:03:41 jenglish Exp $
* Copyright (c) 2003 Joe English. Freely redistributable.
*
* Declarations for Tk theme engine.
@@ -19,28 +19,6 @@ extern "C" {
# endif
#endif
-#ifdef HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-#if !defined(INT2PTR) && !defined(PTR2INT)
-# if defined(HAVE_INTPTR_T) || defined(intptr_t)
-# define INT2PTR(p) ((void*)(intptr_t)(p))
-# define PTR2INT(p) ((int)(intptr_t)(p))
-# else
-# define INT2PTR(p) ((void*)(p))
-# define PTR2INT(p) ((int)(p))
-# endif
-#endif
-#if !defined(UINT2PTR) && !defined(PTR2UINT)
-# if defined(HAVE_UINTPTR_T) || defined(uintptr_t)
-# define UINT2PTR(p) ((void*)(uintptr_t)(p))
-# define PTR2UINT(p) ((unsigned int)(uintptr_t)(p))
-# else
-# define UINT2PTR(p) ((void*)(p))
-# define PTR2UINT(p) ((unsigned int)(p))
-# endif
-#endif
-
#define TTKAPI MODULE_SCOPE
/* Ttk syncs to the Tk version & patchlevel */
diff --git a/generic/ttk/ttkTreeview.c b/generic/ttk/ttkTreeview.c
index 20ca890..f71a163 100644
--- a/generic/ttk/ttkTreeview.c
+++ b/generic/ttk/ttkTreeview.c
@@ -1,4 +1,4 @@
-/* $Id: ttkTreeview.c,v 1.17 2007/10/15 07:24:49 das Exp $
+/* $Id: ttkTreeview.c,v 1.18 2007/10/15 15:03:41 jenglish Exp $
* Copyright (c) 2004, Joe English
*
* ttk::treeview widget implementation.
@@ -400,7 +400,7 @@ typedef struct
/* Derived resources:
*/
- Tcl_HashTable columnNames; /* Map: column name -> column index */
+ Tcl_HashTable columnNames; /* Map: column name -> column table entry */
int nColumns; /* #columns */
unsigned showFlags; /* bitmask of subparts to display */
@@ -501,14 +501,13 @@ static void DisplayLayout(
Ttk_DrawLayout(layout, state, d);
}
-/* + ColumnIndex --
- * Maps column identifier to column index.
- * Returns: -1 if not found, column index otherwise.
+/* + GetColumn --
+ * Look up column by name or number.
+ * Returns: pointer to column table entry, NULL if not found.
* Leaves an error message in interp->result on error.
- *
- * Column IDs may be specified by name or as a number.
*/
-static int ColumnIndex(Tcl_Interp *interp, Treeview *tv, Tcl_Obj *columnIDObj)
+static TreeColumn *GetColumn(
+ Tcl_Interp *interp, Treeview *tv, Tcl_Obj *columnIDObj)
{
Tcl_HashEntry *entryPtr;
int columnIndex;
@@ -518,7 +517,7 @@ static int ColumnIndex(Tcl_Interp *interp, Treeview *tv, Tcl_Obj *columnIDObj)
entryPtr = Tcl_FindHashEntry(
&tv->tree.columnNames, Tcl_GetString(columnIDObj));
if (entryPtr) {
- return PTR2INT(Tcl_GetHashValue(entryPtr));
+ return Tcl_GetHashValue(entryPtr);
}
/* Check for number:
@@ -531,16 +530,40 @@ static int ColumnIndex(Tcl_Interp *interp, Treeview *tv, Tcl_Obj *columnIDObj)
Tcl_GetString(columnIDObj),
" out of bounds",
NULL);
- return -1;
+ return NULL;
}
- return columnIndex;
+ return tv->tree.columns + columnIndex;
}
Tcl_ResetResult(interp);
Tcl_AppendResult(interp,
"Invalid column index ", Tcl_GetString(columnIDObj),
NULL);
- return -1;
+ return NULL;
+}
+
+/* + FindColumn --
+ * Look up column by name, number, or display index.
+ */
+static TreeColumn *FindColumn(
+ Tcl_Interp *interp, Treeview *tv, Tcl_Obj *columnIDObj)
+{
+ int colno;
+
+ if (sscanf(Tcl_GetString(columnIDObj), "#%d", &colno) == 1)
+ { /* Display column specification, #n */
+ if (colno >= 0 && colno < tv->tree.nDisplayColumns) {
+ return tv->tree.displayColumns[colno];
+ }
+ /* else */
+ Tcl_ResetResult(interp);
+ Tcl_AppendResult(interp,
+ "Column ", Tcl_GetString(columnIDObj), " out of range",
+ NULL);
+ return NULL;
+ }
+
+ return GetColumn(interp, tv, columnIDObj);
}
/* + FindItem --
@@ -608,32 +631,6 @@ static Tcl_Obj *ItemID(Treeview *tv, TreeItem *item)
return Tcl_NewStringObj(ItemName(tv, item), -1);
}
-/* + FindColumn --
- */
-static TreeColumn *FindColumn(
- Tcl_Interp *interp, Treeview *tv, Tcl_Obj *columnIDObj)
-{
- int column;
-
- if (sscanf(Tcl_GetString(columnIDObj), "#%d", &column) == 1)
- { /* Display column specification, #n */
- if (column >= 0 && column < tv->tree.nDisplayColumns) {
- return tv->tree.displayColumns[column];
- }
- /* else */
- Tcl_ResetResult(interp);
- Tcl_AppendResult(interp,
- "Column ", Tcl_GetString(columnIDObj), " out of range",
- NULL);
- return NULL;
- }
-
- column = ColumnIndex(interp, tv, columnIDObj);
- if (column >= 0)
- return tv->tree.columns + column;
- return 0;
-}
-
/*------------------------------------------------------------------------
* +++ Column configuration.
*/
@@ -689,7 +686,7 @@ static int TreeviewInitColumns(Tcl_Interp *interp, Treeview *tv)
Tcl_HashEntry *entryPtr = Tcl_CreateHashEntry(
&tv->tree.columnNames, Tcl_GetString(columnName), &isNew);
- Tcl_SetHashValue(entryPtr, INT2PTR(i));
+ Tcl_SetHashValue(entryPtr, tv->tree.columns + i);
InitColumn(tv->tree.columns + i);
Tk_InitOptions(
@@ -733,12 +730,11 @@ static int TreeviewInitDisplayColumns(Tcl_Interp *interp, Treeview *tv)
} else {
displayColumns = (TreeColumn**)ckalloc((ndcols+1)*sizeof(TreeColumn*));
for (index = 0; index < ndcols; ++index) {
- int columnIndex = ColumnIndex(interp, tv, dcolumns[index]);
- if (columnIndex == -1) {
+ displayColumns[index+1] = GetColumn(interp, tv, dcolumns[index]);
+ if (!displayColumns[index+1]) {
ckfree((ClientData)displayColumns);
return TCL_ERROR;
}
- displayColumns[index+1] = tv->tree.columns + columnIndex;
}
}
displayColumns[0] = &tv->tree.column0;
@@ -3080,14 +3076,6 @@ TTK_END_LAYOUT
* +++ Tree indicator element.
*/
-#ifdef UNUSED
-#if defined(WIN32)
-static const int WIN32_XDRAWLINE_HACK = 1;
-#else
-static const int WIN32_XDRAWLINE_HACK = 0;
-#endif
-#endif
-
typedef struct
{
Tcl_Obj *colorObj;