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