aboutsummaryrefslogtreecommitdiff
path: root/generic/tkZinc.c
diff options
context:
space:
mode:
authorlecoanet2002-07-05 14:29:07 +0000
committerlecoanet2002-07-05 14:29:07 +0000
commitba8620c0f754346a586c47aa2338c74836baf23e (patch)
tree791499a2e93e72b916da5d52467cf7056a6af05c /generic/tkZinc.c
parentfbe49d361c9b866219037cff216f7d89634d3009 (diff)
downloadtkzinc-ba8620c0f754346a586c47aa2338c74836baf23e.zip
tkzinc-ba8620c0f754346a586c47aa2338c74836baf23e.tar.gz
tkzinc-ba8620c0f754346a586c47aa2338c74836baf23e.tar.bz2
tkzinc-ba8620c0f754346a586c47aa2338c74836baf23e.tar.xz
* Utilisation de la m�thode HasTag pour la recherche d'un tag
dans un item. * (FindItems): Ajout de la m�thode ancestors qui permet de retrouver les anc�tres d'un item en une seule fois (�ventuellement avec filtrage sur un tag).
Diffstat (limited to 'generic/tkZinc.c')
-rw-r--r--generic/tkZinc.c114
1 files changed, 41 insertions, 73 deletions
diff --git a/generic/tkZinc.c b/generic/tkZinc.c
index ef300bf..a21f8f6 100644
--- a/generic/tkZinc.c
+++ b/generic/tkZinc.c
@@ -1190,8 +1190,6 @@ TagSearchEvalExpr(TagSearchExpr *expr, /* Search expression */
* to be a tag, else operand expected */
int negate_result; /* Pending negation of next tag value */
Tk_Uid uid;
- Tk_Uid *tags;
- int count;
int result=0; /* Value of expr so far */
int paren_depth;
@@ -1205,20 +1203,10 @@ TagSearchEvalExpr(TagSearchExpr *expr, /* Search expression */
* assert(expr->index < expr->length);
*/
uid = expr->uids[expr->index++];
- result = 0;
/*
* set result 1 if tag is found in item's tags
*/
- if (item->tags) {
- tags = (Tk_Uid *) ZnListArray(item->tags);
- count = ZnListSize(item->tags);
- for (; count > 0; tags++, count--) {
- if (*tags == uid) {
- result = 1;
- break;
- }
- }
- }
+ result = ITEM.HasTag(item, uid) ? 1 : 0;
}
else if (uid == neg_tag_val_uid) {
negate_result = ! negate_result;
@@ -1226,20 +1214,10 @@ TagSearchEvalExpr(TagSearchExpr *expr, /* Search expression */
* assert(expr->index < expr->length);
*/
uid = expr->uids[expr->index++];
- result = 0;
/*
* set result 1 if tag is found in item's tags
*/
- if (item->tags) {
- tags = (Tk_Uid *) ZnListArray(item->tags);
- count = ZnListSize(item->tags);
- for (; count > 0; tags++, count--) {
- if (*tags == uid) {
- result = 1;
- break;
- }
- }
- }
+ result = ITEM.HasTag(item, uid) ? 1 : 0;
}
else if (uid == paren_uid) {
/*
@@ -1650,8 +1628,6 @@ static Item
ZnTagSearchFirst(TagSearch *search) /* Record describing tag search */
{
Item item, previous;
- Tk_Uid *tags;
- int count;
/* short circuit impossible searches for null tags */
if (search->over == True) {
@@ -1704,17 +1680,10 @@ ZnTagSearchFirst(TagSearch *search) /* Record describing tag search */
/*
* Optimized single-tag search
*/
- Tk_Uid uid = search->expr->uid;
- if (item->tags) {
- tags = (Tk_Uid *) ZnListArray(item->tags);
- count = ZnListSize(item->tags);
- for (; count > 0; tags++, count--) {
- if (*tags == uid) {
- search->previous = previous;
- search->current = item;
- return item;
- }
- }
+ if (ITEM.HasTag(item, search->expr->uid)) {
+ search->previous = previous;
+ search->current = item;
+ return item;
}
}
else {
@@ -1802,8 +1771,6 @@ static Item
ZnTagSearchNext(TagSearch *search) /* Record describing search in progress. */
{
Item item, previous;
- Tk_Uid *tags;
- int count;
if (search->over) {
return ZN_NO_ITEM;
@@ -1888,17 +1855,10 @@ ZnTagSearchNext(TagSearch *search) /* Record describing search in progress. */
/*
* Optimized single-tag search
*/
- Tk_Uid uid = search->expr->uid;
- if (item->tags) {
- tags = (Tk_Uid *) ZnListArray(item->tags);
- count = ZnListSize(item->tags);
- for ( ; count > 0; tags++, count--) {
- if (*tags == uid) {
- search->previous = previous;
- search->current = item;
- return item;
- }
- }
+ if (ITEM.HasTag(item, search->expr->uid)) {
+ search->previous = previous;
+ search->current = item;
+ return item;
}
}
else {
@@ -2129,11 +2089,11 @@ FindItems(WidgetInfo *wi,
ZnBool recursive = True;
ZnPickStruct ps;
static char *search_cmd_strings[] = {
- "above", "atpriority", "below", "closest", "enclosed",
+ "above", "ancestors", "atpriority", "below", "closest", "enclosed",
"overlapping", "withtag", "withtype", NULL
};
enum search_cmds {
- ZN_S_ABOVE, ZN_S_ATPRIORITY, ZN_S_BELOW, ZN_S_CLOSEST,
+ ZN_S_ABOVE, ZN_S_ANCESTORS, ZN_S_ATPRIORITY, ZN_S_BELOW, ZN_S_CLOSEST,
ZN_S_ENCLOSED, ZN_S_OVERLAPPING, ZN_S_WITHTAG, ZN_S_WITHTYPE
};
@@ -2167,6 +2127,32 @@ FindItems(WidgetInfo *wi,
}
}
break;
+ /*
+ * ancestors
+ */
+ case ZN_S_ANCESTORS:
+ {
+ Tk_Uid uid = NULL;
+ if ((argc != first+2) && (argc != first+3)) {
+ Tcl_WrongNumArgs(wi->interp, first+1, args, "tagOrId ?withTag?");
+ return ZN_ERROR;
+ }
+ result = ZnItemWithTagOrId(wi, args[first+1], &item, search_var);
+ if (result == ZN_ERROR) {
+ return ZN_ERROR;
+ }
+ item = item->parent;
+ if (argc == first+3) {
+ uid = Tk_GetUid(Tcl_GetString(args[first+2]));
+ }
+ while (item != ZN_NO_ITEM) {
+ if (!uid || ITEM.HasTag(item, uid)) {
+ ZnDoItem(wi->interp, item, ZN_NO_PART, tag_uid);
+ }
+ item = item->parent;
+ }
+ }
+ break;
/*
* atpriority
*/
@@ -3666,9 +3652,6 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */
*/
case ZN_W_HASTAG:
{
- Tk_Uid tag_uid;
- Tk_Uid *tags;
-
if (argc != 4) {
Tcl_WrongNumArgs(interp, 1, args, "hastag tagOrId tag");
goto error;
@@ -3677,24 +3660,9 @@ WidgetObjCmd(ClientData client_data, /* Information about the widget. */
if ((result == ZN_ERROR) || (item == ZN_NO_ITEM)) {
goto error;
}
- if (!item->tags || !ZnListSize(item->tags)) {
- l = NewBooleanObj(0);
- Tcl_SetObjResult(interp, l);
- }
- else {
- num = ZnListSize(item->tags);
- tag_uid = Tk_GetUid(Tcl_GetString(args[3]));
- tags = (Tk_Uid *) ZnListArray(item->tags);
- for (i = 0; i < num; i++) {
- if (tags[i] == tag_uid) {
- l = NewBooleanObj(1);
- Tcl_SetObjResult(interp, l);
- goto done;
- }
- }
- l = NewBooleanObj(0);
- Tcl_SetObjResult(interp, l);
- }
+ l = NewBooleanObj(ITEM.HasTag(item,
+ Tk_GetUid(Tcl_GetString(args[3]))));
+ Tcl_SetObjResult(interp, l);
}
break;
/*