]> git.decadent.org.uk Git - ion3.git/blob - ioncore/tags.c
Update cfg_kludge_flash for Flash 10
[ion3.git] / ioncore / tags.c
1 /*
2  * ion/ioncore/tags.c
3  *
4  * Copyright (c) Tuomo Valkonen 1999-2009. 
5  *
6  * See the included file LICENSE for details.
7  */
8
9 #include <libtu/objlist.h>
10 #include <libtu/setparam.h>
11
12 #include "global.h"
13 #include "region.h"
14 #include "tags.h"
15 #include "extlconv.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, ioncore_g.notifies.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  * (one of \codestr{set}, \codestr{unset}, or \codestr{toggle}).
47  * The resulting state is returned.
48  */
49 EXTL_EXPORT_AS(WRegion, set_tagged)
50 bool region_set_tagged_extl(WRegion *reg, const char *how)
51 {
52     return region_set_tagged(reg, libtu_string_to_setparam(how));
53 }
54
55
56 /*EXTL_DOC
57  * Is \var{reg} tagged?
58  */
59 EXTL_SAFE
60 EXTL_EXPORT_MEMBER
61 bool region_is_tagged(WRegion *reg)
62 {
63     return ((reg->flags&REGION_TAGGED)!=0);
64 }
65
66
67 /*EXTL_DOC
68  * Untag all regions.
69  */
70 EXTL_EXPORT
71 void ioncore_tagged_clear()
72 {
73     while(ioncore_tagged_first(TRUE)!=NULL)
74         /* nothing */;
75 }
76
77
78 /*}}}*/
79
80
81 /*{{{ Iteration */
82
83
84 /*EXTL_DOC
85  * Returns first tagged object, untagging it as well if \var{untag} is set.
86  */
87 EXTL_SAFE
88 EXTL_EXPORT
89 WRegion *ioncore_tagged_first(bool untag)
90 {
91     WRegion *reg;
92     
93     if(!untag){
94         reg=(WRegion*)OBJLIST_FIRST(WRegion*, taglist);
95     }else{
96         reg=(WRegion*)objlist_take_first(&taglist);
97     
98         if(reg!=NULL){
99             reg->flags&=~REGION_TAGGED;
100             region_notify_change(reg, ioncore_g.notifies.tag);
101         }
102     }
103     
104     return reg;
105 }
106
107
108 /*EXTL_DOC
109  * Iterate over tagged regions until \var{iterfn} returns \code{false}.
110  * The function is called in protected mode.
111  * This routine returns \code{true} if it reaches the end of list
112  * without this happening.
113  */
114 EXTL_SAFE
115 EXTL_EXPORT
116 bool ioncore_tagged_i(ExtlFn iterfn)
117 {
118     return extl_iter_objlist(iterfn, taglist);
119 }
120
121
122 /*}}}*/
123