]> git.decadent.org.uk Git - ion3.git/blob - ioncore/basicpholder.c
[svn-upgrade] Integrating new upstream version, ion3 (20070506)
[ion3.git] / ioncore / basicpholder.c
1 /*
2  * ion/ioncore/basicpholder.c
3  *
4  * Copyright (c) Tuomo Valkonen 2005-2007. 
5  *
6  * See the included file LICENSE for details.
7  */
8
9 #include <libtu/objp.h>
10 #include <libtu/obj.h>
11 #include <libtu/pointer.h>
12
13 #include "basicpholder.h"
14
15
16 /*{{{ Init/deinit */
17
18
19 static void basicpholder_watch_handler(Watch *watch, Obj *reg)
20 {
21     WBasicPHolder *ph=FIELD_TO_STRUCT(WBasicPHolder, reg_watch, watch);
22     pholder_redirect(&(ph->ph), (WRegion*)reg);
23 }
24
25
26 bool basicpholder_init(WBasicPHolder *ph, WRegion *reg, 
27                        WBasicPHolderHandler *hnd)
28 {
29     assert(reg!=NULL && hnd!=NULL);
30     
31     pholder_init(&(ph->ph));
32
33     watch_init(&(ph->reg_watch));
34     
35     if(!watch_setup(&(ph->reg_watch), (Obj*)reg, basicpholder_watch_handler)){
36         pholder_deinit(&(ph->ph));
37         return FALSE;
38     }
39     
40     ph->hnd=hnd;
41     
42     return TRUE;
43 }
44  
45
46 WBasicPHolder *create_basicpholder(WRegion *reg, 
47                                    WBasicPHolderHandler *hnd)
48 {
49     CREATEOBJ_IMPL(WBasicPHolder, basicpholder, (p, reg, hnd));
50 }
51
52
53 void basicpholder_deinit(WBasicPHolder *ph)
54 {
55     watch_reset(&(ph->reg_watch));
56     pholder_deinit(&(ph->ph));
57 }
58
59
60 /*}}}*/
61
62
63 /*{{{ Dynfuns */
64
65
66 WRegion *basicpholder_do_attach(WBasicPHolder *ph, int flags,
67                                 WRegionAttachData *data)
68 {
69     WRegion *reg=(WRegion*)ph->reg_watch.obj;
70
71     if(reg==NULL || ph->hnd==NULL)
72         return FALSE;
73
74     return ph->hnd(reg, flags, data);
75 }
76
77
78 bool basicpholder_do_goto(WBasicPHolder *ph)
79 {
80     WRegion *reg=(WRegion*)ph->reg_watch.obj;
81     
82     if(reg!=NULL)
83         return region_goto((WRegion*)reg);
84     
85     return FALSE;
86 }
87
88
89 WRegion *basicpholder_do_target(WBasicPHolder *ph)
90 {
91     return (WRegion*)ph->reg_watch.obj;
92 }
93
94
95 /*}}}*/
96
97
98 /*{{{ Class information */
99
100
101 static DynFunTab basicpholder_dynfuntab[]={
102     {(DynFun*)pholder_do_attach, 
103      (DynFun*)basicpholder_do_attach},
104
105     {(DynFun*)pholder_do_goto, 
106      (DynFun*)basicpholder_do_goto},
107
108     {(DynFun*)pholder_do_target, 
109      (DynFun*)basicpholder_do_target},
110     
111     END_DYNFUNTAB
112 };
113
114 IMPLCLASS(WBasicPHolder, WPHolder, basicpholder_deinit, 
115           basicpholder_dynfuntab);
116
117
118 /*}}}*/
119