]> git.decadent.org.uk Git - ion3.git/blob - ioncore/groupedpholder.c
[svn-upgrade] Integrating new upstream version, ion3 (20070506)
[ion3.git] / ioncore / groupedpholder.c
1 /*
2  * ion/ioncore/groupedpholder.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
12 #include "group.h"
13 #include "group-cw.h"
14 #include "groupedpholder.h"
15
16
17 /*{{{ Init/deinit */
18
19
20 bool groupedpholder_init(WGroupedPHolder *ph, WPHolder *cont)
21 {
22     assert(cont!=NULL);
23     
24     pholder_init(&(ph->ph));
25
26     ph->cont=cont;
27     
28     return TRUE;
29 }
30  
31
32 WGroupedPHolder *create_groupedpholder(WPHolder *cont)
33 {
34     CREATEOBJ_IMPL(WGroupedPHolder, groupedpholder, (p, cont));
35 }
36
37
38 void groupedpholder_deinit(WGroupedPHolder *ph)
39 {
40     if(ph->cont!=NULL){
41         destroy_obj((Obj*)ph->cont);
42         ph->cont=NULL;
43     }
44     
45     pholder_deinit(&(ph->ph));
46 }
47
48
49 /*}}}*/
50
51
52 /*{{{ Attach */
53
54
55 static bool grouped_do_attach_final(WGroupCW *cwg, 
56                                     WRegion *reg,
57                                     WGroupAttachParams *param)
58 {
59     if(!param->geom_set){
60         /* Comm. hack */
61         REGION_GEOM(cwg)=REGION_GEOM(reg);
62     }
63
64     param->geom_set=1;
65     param->geom.x=0;
66     param->geom.y=0;
67     param->geom.w=REGION_GEOM(reg).w;
68     param->geom.h=REGION_GEOM(reg).h;
69     param->szplcy=SIZEPOLICY_FULL_EXACT;
70     param->szplcy_set=TRUE;
71     
72     return group_do_attach_final(&cwg->grp, reg, param);
73 }
74
75
76 WRegion *grouped_handler(WWindow *par, 
77                          const WFitParams *fp, 
78                          void *frp_)
79 {
80     WRegionAttachData *data=(WRegionAttachData*)frp_;
81     WGroupAttachParams param=GROUPATTACHPARAMS_INIT;
82     WGroupCW *cwg;
83     WRegion *reg;
84     WStacking *st;
85     
86     cwg=create_groupcw(par, fp);
87     
88     if(cwg==NULL)
89         return NULL;
90     
91     param.level_set=1;
92     param.level=STACKING_LEVEL_BOTTOM;
93     param.switchto_set=1;
94     param.switchto=1;
95     param.bottom=1;
96     
97     if(!(fp->mode&REGION_FIT_WHATEVER)){
98         /* Comm. hack */
99         param.geom_set=TRUE;
100     }
101     
102     reg=region_attach_helper((WRegion*)cwg, par, fp, 
103                              (WRegionDoAttachFn*)grouped_do_attach_final,
104                              &param, data);
105     
106     if(reg==NULL){
107         destroy_obj((Obj*)cwg);
108         return NULL;
109     }
110
111     return (WRegion*)cwg;
112 }
113
114
115 WRegion *groupedpholder_do_attach(WGroupedPHolder *ph, int flags,
116                                   WRegionAttachData *data)
117 {
118     WRegionAttachData data2;
119     
120     if(ph->cont==NULL)
121         return FALSE;
122
123     data2.type=REGION_ATTACH_NEW;
124     data2.u.n.fn=grouped_handler;
125     data2.u.n.param=data;
126         
127     return pholder_do_attach(ph->cont, flags, &data2);
128 }
129
130
131 /*}}}*/
132
133
134 /*{{{ Other dynfuns */
135
136
137 bool groupedpholder_do_goto(WGroupedPHolder *ph)
138 {
139     return (ph->cont!=NULL
140             ? pholder_goto(ph->cont)
141             : FALSE);
142 }
143
144
145 WRegion *groupedpholder_do_target(WGroupedPHolder *ph)
146 {
147     return (ph->cont!=NULL
148             ? pholder_target(ph->cont)
149             : NULL);
150 }
151
152
153 WPHolder *groupedpholder_do_root(WGroupedPHolder *ph)
154 {
155     WPHolder *root;
156     
157     if(ph->cont==NULL)
158         return NULL;
159     
160     root=pholder_root(ph->cont);
161     
162     return (root!=ph->cont 
163             ? root
164             : &ph->ph);
165 }
166
167
168 /*}}}*/
169
170
171 /*{{{ Class information */
172
173
174 static DynFunTab groupedpholder_dynfuntab[]={
175     {(DynFun*)pholder_do_attach, 
176      (DynFun*)groupedpholder_do_attach},
177
178     {(DynFun*)pholder_do_goto, 
179      (DynFun*)groupedpholder_do_goto},
180
181     {(DynFun*)pholder_do_target, 
182      (DynFun*)groupedpholder_do_target},
183      
184     {(DynFun*)pholder_do_root, 
185      (DynFun*)groupedpholder_do_root},
186     
187     END_DYNFUNTAB
188 };
189
190 IMPLCLASS(WGroupedPHolder, WPHolder, groupedpholder_deinit, 
191           groupedpholder_dynfuntab);
192
193
194 /*}}}*/
195