]> git.decadent.org.uk Git - ion3.git/blob - ioncore/tags.c
f01385d301c8d1f507fe64eca491136cf0de1e1c
[ion3.git] / ioncore / tags.c
1 /*
2  * ion/ioncore/tags.c
3  *
4  * Copyright (c) Tuomo Valkonen 1999-2007. 
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
15 #include "global.h"
16 #include "region.h"
17 #include "tags.h"
18 #include "extlconv.h"
19
20
21 static ObjList *taglist=NULL;
22
23
24 /*{{{ Adding/removing tags */
25
26
27 bool region_set_tagged(WRegion *reg, int sp)
28 {
29     bool set=(reg->flags&REGION_TAGGED);
30     bool nset=libtu_do_setparam(sp, set);
31     
32     if(XOR(nset, set)){
33         if(reg->flags&REGION_TAGGED){
34             reg->flags&=~REGION_TAGGED;
35             objlist_remove(&taglist, (Obj*)reg);
36         }else{
37             reg->flags|=REGION_TAGGED;
38             objlist_insert_last(&taglist, (Obj*)reg);
39         }
40         region_notify_change(reg, ioncore_g.notifies.tag);
41     }
42
43     return nset;
44 }
45
46
47 /*EXTL_DOC
48  * Change tagging state of \var{reg} as defined by \var{how}
49  * (set/unset/toggle). Resulting state is returned.
50  */
51 EXTL_EXPORT_AS(WRegion, set_tagged)
52 bool region_set_tagged_extl(WRegion *reg, const char *how)
53 {
54     return region_set_tagged(reg, libtu_string_to_setparam(how));
55 }
56
57
58 /*EXTL_DOC
59  * Is \var{reg} tagged?
60  */
61 EXTL_SAFE
62 EXTL_EXPORT_MEMBER
63 bool region_is_tagged(WRegion *reg)
64 {
65     return ((reg->flags&REGION_TAGGED)!=0);
66 }
67
68
69 /*EXTL_DOC
70  * Untag all regions.
71  */
72 EXTL_EXPORT
73 void ioncore_tagged_clear()
74 {
75     while(ioncore_tagged_first(TRUE)!=NULL)
76         /* nothing */;
77 }
78
79
80 /*}}}*/
81
82
83 /*{{{ Iteration */
84
85
86 /*EXTL_DOC
87  * Returns first tagged object, untagging it as well if \var{untag}is set.
88  */
89 EXTL_SAFE
90 EXTL_EXPORT
91 WRegion *ioncore_tagged_first(bool untag)
92 {
93     WRegion *reg;
94     
95     if(!untag){
96         reg=(WRegion*)OBJLIST_FIRST(WRegion*, taglist);
97     }else{
98         reg=(WRegion*)objlist_take_first(&taglist);
99     
100         if(reg!=NULL){
101             reg->flags&=~REGION_TAGGED;
102             region_notify_change(reg, ioncore_g.notifies.tag);
103         }
104     }
105     
106     return reg;
107 }
108
109
110 /*EXTL_DOC
111  * Iterate over tagged regions until \var{iterfn} returns \code{false}.
112  * The function itself returns \code{true} if it reaches the end of list
113  * without this happening.
114  */
115 EXTL_SAFE
116 EXTL_EXPORT
117 bool ioncore_tagged_i(ExtlFn iterfn)
118 {
119     return extl_iter_objlist(iterfn, taglist);
120 }
121
122
123 /*}}}*/
124