2 * ion/ioncore/framedpholder.c
4 * Copyright (c) Tuomo Valkonen 2005-2007.
6 * See the included file LICENSE for details.
9 #include <libtu/objp.h>
10 #include <libtu/obj.h>
11 #include <libtu/minmax.h>
14 #include "framedpholder.h"
21 bool framedpholder_init(WFramedPHolder *ph, WPHolder *cont,
22 const WFramedParam *param)
26 pholder_init(&(ph->ph));
35 WFramedPHolder *create_framedpholder(WPHolder *cont,
36 const WFramedParam *param)
38 CREATEOBJ_IMPL(WFramedPHolder, framedpholder, (p, cont, param));
42 void framedpholder_deinit(WFramedPHolder *ph)
45 destroy_obj((Obj*)ph->cont);
49 pholder_deinit(&(ph->ph));
60 WRegionAttachData *data;
65 void frame_adjust_to_initial(WFrame *frame, const WFitParams *fp,
66 const WFramedParam *param, WRegion *reg)
70 if(!(fp->mode&(REGION_FIT_BOUNDS|REGION_FIT_WHATEVER)))
73 mplex_managed_geom((WMPlex*)frame, &mg);
76 if(!param->inner_geom_gravity_set){
77 rqg.x=REGION_GEOM(frame).x;
78 rqg.y=REGION_GEOM(frame).y;
79 rqg.w=maxof(1, REGION_GEOM(reg).w+(REGION_GEOM(frame).w-mg.w));
80 rqg.h=maxof(1, REGION_GEOM(reg).h+(REGION_GEOM(frame).h-mg.h));
83 int br=REGION_GEOM(frame).w-(mg.x+mg.w);
85 int bb=REGION_GEOM(frame).h-(mg.y+mg.h);
87 rqg.x=(/*fp->g.x+*/param->inner_geom.x+
88 xgravity_deltax(param->gravity, bl, br));
89 rqg.y=(/*fp->g.y+*/param->inner_geom.y+
90 xgravity_deltay(param->gravity, bt, bb));
91 rqg.w=maxof(1, param->inner_geom.w+(REGION_GEOM(frame).w-mg.w));
92 rqg.h=maxof(1, param->inner_geom.h+(REGION_GEOM(frame).h-mg.h));
95 if(!(fp->mode®ION_FIT_WHATEVER))
96 rectangle_constrain(&rqg, &fp->g);
98 region_fit((WRegion*)frame, &rqg, REGION_FIT_EXACT);
102 WRegion *framed_handler(WWindow *par,
103 const WFitParams *fp,
107 WMPlexAttachParams mp=MPLEXATTACHPARAMS_INIT;
108 WFramedParam *param=ap->param;
112 frame=create_frame(par, fp, param->mode);
117 if(fp->mode&(REGION_FIT_BOUNDS|REGION_FIT_WHATEVER))
118 mp.flags|=MPLEX_ATTACH_WHATEVER;
120 reg=mplex_do_attach(&frame->mplex, &mp, ap->data);
123 destroy_obj((Obj*)frame);
127 frame_adjust_to_initial(frame, fp, param, reg);
129 return (WRegion*)frame;
133 WRegion *region_attach_framed(WRegion *reg, WFramedParam *param,
134 WRegionAttachFn *fn, void *fn_param,
135 WRegionAttachData *data)
137 WRegionAttachData data2;
140 data2.type=REGION_ATTACH_NEW;
141 data2.u.n.fn=framed_handler;
147 return fn(reg, fn_param, &data2);
151 WRegion *framedpholder_do_attach(WFramedPHolder *ph, int flags,
152 WRegionAttachData *data)
154 WRegionAttachData data2;
160 data2.type=REGION_ATTACH_NEW;
161 data2.u.n.fn=framed_handler;
167 return pholder_do_attach(ph->cont, flags, &data2);
174 /*{{{ Other dynfuns */
177 bool framedpholder_do_goto(WFramedPHolder *ph)
179 return (ph->cont!=NULL
180 ? pholder_goto(ph->cont)
185 WRegion *framedpholder_do_target(WFramedPHolder *ph)
187 return (ph->cont!=NULL
188 ? pholder_target(ph->cont)
193 WPHolder *framedpholder_do_root(WFramedPHolder *ph)
200 root=pholder_root(ph->cont);
202 return (root!=ph->cont
211 /*{{{ Class information */
214 static DynFunTab framedpholder_dynfuntab[]={
215 {(DynFun*)pholder_do_attach,
216 (DynFun*)framedpholder_do_attach},
218 {(DynFun*)pholder_do_goto,
219 (DynFun*)framedpholder_do_goto},
221 {(DynFun*)pholder_do_target,
222 (DynFun*)framedpholder_do_target},
224 {(DynFun*)pholder_do_root,
225 (DynFun*)framedpholder_do_root},
230 IMPLCLASS(WFramedPHolder, WPHolder, framedpholder_deinit,
231 framedpholder_dynfuntab);