]> git.decadent.org.uk Git - ion3.git/blob - ioncore/tags.c
[svn-inject] Installing original source of ion3
[ion3.git] / ioncore / tags.c
1 /*
2  * ion/ioncore/tags.c
3  *
4  * Copyright (c) Tuomo Valkonen 1999-2006. 
5  *
6  * Ion is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation; either version 2.1 of the License, or
9  * (at your option) any later version.
10  */
11
12 #include <libtu/objlist.h>
13 #include <libtu/setparam.h>
14 #include "region.h"
15 #include "tags.h"
16
17
18 static ObjList *taglist=NULL;
19
20
21 /*{{{ Adding/removing tags */
22
23
24 bool region_set_tagged(WRegion *reg, int sp)
25 {
26     bool set=(reg->flags&REGION_TAGGED);
27     bool nset=libtu_do_setparam(sp, set);
28     
29     if(XOR(nset, set)){
30         if(reg->flags&REGION_TAGGED){
31             reg->flags&=~REGION_TAGGED;
32             objlist_remove(&taglist, (Obj*)reg);
33         }else{
34             reg->flags|=REGION_TAGGED;
35             objlist_insert_last(&taglist, (Obj*)reg);
36         }
37         region_notify_change(reg, "tag");
38     }
39
40     return nset;
41 }
42
43
44 /*EXTL_DOC
45  * Change tagging state of \var{reg} as defined by \var{how}
46  * (set/unset/toggle). Resulting state is returned.
47  */
48 EXTL_EXPORT_AS(WRegion, set_tagged)
49 bool region_set_tagged_extl(WRegion *reg, const char *how)
50 {
51     return region_set_tagged(reg, libtu_string_to_setparam(how));
52 }
53
54
55 /*EXTL_DOC
56  * Is \var{reg} tagged?
57  */
58 EXTL_SAFE
59 EXTL_EXPORT_MEMBER
60 bool region_is_tagged(WRegion *reg)
61 {
62     return ((reg->flags&REGION_TAGGED)!=0);
63 }
64
65
66 /*EXTL_DOC
67  * Untag all regions.
68  */
69 EXTL_EXPORT
70 void ioncore_clear_tags()
71 {
72     while(ioncore_tags_take_first()!=NULL)
73         /* nothing */;
74 }
75
76
77 /*}}}*/
78
79
80 /*{{{ Iteration */
81
82
83 /*EXTL_DOC
84  * Returns first tagged object.
85  */
86 EXTL_SAFE
87 EXTL_EXPORT
88 WRegion *ioncore_tags_first()
89 {
90     return (WRegion*)OBJLIST_FIRST(WRegion*, taglist);
91 }
92
93
94 WRegion *ioncore_tags_take_first()
95 {
96     WRegion *reg=(WRegion*)objlist_take_first(&taglist);
97     
98     if(reg!=NULL){
99         reg->flags&=~REGION_TAGGED;
100         region_notify_change(reg, "tag");
101     }
102     
103     return reg;
104 }
105
106 /*EXTL_DOC
107  * Returns a list of tagged regions.
108  */
109 EXTL_SAFE
110 EXTL_EXPORT
111 ExtlTab ioncore_tagged_list()
112 {
113     int n=0;
114     ExtlTab tab;
115     WRegion *region;
116     ObjListIterTmp tmp;
117
118     region=ioncore_tags_first();
119     if(!region)
120         return extl_table_none();
121
122     tab=extl_create_table();
123
124     FOR_ALL_ON_OBJLIST(WRegion*, region, taglist, tmp){
125         if(extl_table_seti_o(tab, n+1, (Obj*)region))
126             n++;
127     }
128
129     return tab;
130 }
131
132
133 /*}}}*/
134