2 * ion/ioncore/framedpholder.c
4 * Copyright (c) Tuomo Valkonen 2005-2008.
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));
31 watch_init(&ph->frame_watch);
37 WFramedPHolder *create_framedpholder(WPHolder *cont,
38 const WFramedParam *param)
40 CREATEOBJ_IMPL(WFramedPHolder, framedpholder, (p, cont, param));
44 void framedpholder_deinit(WFramedPHolder *ph)
47 destroy_obj((Obj*)ph->cont);
51 pholder_deinit(&(ph->ph));
52 watch_reset(&ph->frame_watch);
63 WRegionAttachData *data;
69 void frame_adjust_to_initial(WFrame *frame, const WFitParams *fp,
70 const WFramedParam *param, WRegion *reg)
74 if(!(fp->mode&(REGION_FIT_BOUNDS|REGION_FIT_WHATEVER)))
77 mplex_managed_geom((WMPlex*)frame, &mg);
80 if(!param->inner_geom_gravity_set){
81 rqg.x=REGION_GEOM(frame).x;
82 rqg.y=REGION_GEOM(frame).y;
83 rqg.w=maxof(1, REGION_GEOM(reg).w+(REGION_GEOM(frame).w-mg.w));
84 rqg.h=maxof(1, REGION_GEOM(reg).h+(REGION_GEOM(frame).h-mg.h));
87 int br=REGION_GEOM(frame).w-(mg.x+mg.w);
89 int bb=REGION_GEOM(frame).h-(mg.y+mg.h);
91 rqg.x=(/*fp->g.x+*/param->inner_geom.x+
92 xgravity_deltax(param->gravity, bl, br));
93 rqg.y=(/*fp->g.y+*/param->inner_geom.y+
94 xgravity_deltay(param->gravity, bt, bb));
95 rqg.w=maxof(1, param->inner_geom.w+(REGION_GEOM(frame).w-mg.w));
96 rqg.h=maxof(1, param->inner_geom.h+(REGION_GEOM(frame).h-mg.h));
99 if(!(fp->mode®ION_FIT_WHATEVER))
100 rectangle_constrain(&rqg, &fp->g);
102 region_fit((WRegion*)frame, &rqg, REGION_FIT_EXACT);
106 WRegion *framed_handler(WWindow *par,
107 const WFitParams *fp,
111 WMPlexAttachParams mp=MPLEXATTACHPARAMS_INIT;
112 WFramedParam *param=ap->param;
116 frame=create_frame(par, fp, param->mode);
121 if(fp->mode&(REGION_FIT_BOUNDS|REGION_FIT_WHATEVER))
122 mp.flags|=MPLEX_ATTACH_WHATEVER;
124 reg=mplex_do_attach(&frame->mplex, &mp, ap->data);
129 destroy_obj((Obj*)frame);
133 frame_adjust_to_initial(frame, fp, param, reg);
135 return (WRegion*)frame;
139 WRegion *region_attach_framed(WRegion *reg, WFramedParam *param,
140 WRegionAttachFn *fn, void *fn_param,
141 WRegionAttachData *data)
143 WRegionAttachData data2;
146 data2.type=REGION_ATTACH_NEW;
147 data2.u.n.fn=framed_handler;
154 return fn(reg, fn_param, &data2);
158 WRegion *framedpholder_do_attach(WFramedPHolder *ph, int flags,
159 WRegionAttachData *data)
161 WRegionAttachData data2;
165 frame=(WFrame*)ph->frame_watch.obj;
168 WMPlexAttachParams mp=MPLEXATTACHPARAMS_INIT;
169 return mplex_do_attach(&frame->mplex, &mp, data);
175 data2.type=REGION_ATTACH_NEW;
176 data2.u.n.fn=framed_handler;
183 frame=(WFrame*)pholder_do_attach(ph->cont, flags, &data2);
186 assert(OBJ_IS(frame, WFrame));
187 watch_setup(&ph->frame_watch, (Obj*)frame, NULL);
197 /*{{{ Other dynfuns */
200 bool framedpholder_do_goto(WFramedPHolder *ph)
202 WRegion *frame=(WRegion*)ph->frame_watch.obj;
205 return region_goto((WRegion*)frame);
206 else if(ph->cont!=NULL)
207 return pholder_goto(ph->cont);
213 WRegion *framedpholder_do_target(WFramedPHolder *ph)
215 WRegion *frame=(WRegion*)ph->frame_watch.obj;
220 ? pholder_target(ph->cont)
225 bool framedpholder_stale(WFramedPHolder *ph)
227 WRegion *frame=(WRegion*)ph->frame_watch.obj;
229 return (frame==NULL && (ph->cont==NULL || pholder_stale(ph->cont)));
236 /*{{{ Class information */
239 static DynFunTab framedpholder_dynfuntab[]={
240 {(DynFun*)pholder_do_attach,
241 (DynFun*)framedpholder_do_attach},
243 {(DynFun*)pholder_do_goto,
244 (DynFun*)framedpholder_do_goto},
246 {(DynFun*)pholder_do_target,
247 (DynFun*)framedpholder_do_target},
249 {(DynFun*)pholder_stale,
250 (DynFun*)framedpholder_stale},
255 IMPLCLASS(WFramedPHolder, WPHolder, framedpholder_deinit,
256 framedpholder_dynfuntab);