2 * ion/ioncore/framedpholder.c
4 * Copyright (c) Tuomo Valkonen 2005-2006.
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.
12 #include <libtu/objp.h>
13 #include <libtu/obj.h>
14 #include <libtu/minmax.h>
17 #include "framedpholder.h"
24 bool framedpholder_init(WFramedPHolder *ph, WPHolder *cont,
25 const WFramedParam *param)
29 pholder_init(&(ph->ph));
38 WFramedPHolder *create_framedpholder(WPHolder *cont,
39 const WFramedParam *param)
41 CREATEOBJ_IMPL(WFramedPHolder, framedpholder, (p, cont, param));
45 void framedpholder_deinit(WFramedPHolder *ph)
48 destroy_obj((Obj*)ph->cont);
52 pholder_deinit(&(ph->ph));
63 WRegionAttachData *data;
68 WRegion *framed_handler(WWindow *par,
73 WMPlexAttachParams mp=MPLEXATTACHPARAMS_INIT;
74 WFramedParam *param=ap->param;
79 if(param->mkframe!=NULL)
80 frame=(WFrame*)(param->mkframe)(par, fp);
82 frame=create_frame(par, fp, FRAME_MODE_FLOATING);
87 if(fp->mode&(REGION_FIT_BOUNDS|REGION_FIT_WHATEVER))
88 mp.flags|=MPLEX_ATTACH_WHATEVER;
90 reg=mplex_do_attach(&frame->mplex, &mp, ap->data);
93 destroy_obj((Obj*)frame);
97 if(!(fp->mode&(REGION_FIT_BOUNDS|REGION_FIT_WHATEVER)))
98 return (WRegion*)frame;
100 mplex_managed_geom((WMPlex*)frame, &mg);
102 /* Adjust geometry */
103 if(!param->inner_geom_gravity_set){
104 rqg.x=REGION_GEOM(frame).x;
105 rqg.y=REGION_GEOM(frame).y;
106 rqg.w=maxof(1, REGION_GEOM(reg).w+(REGION_GEOM(frame).w-mg.w));
107 rqg.h=maxof(1, REGION_GEOM(reg).h+(REGION_GEOM(frame).h-mg.h));
110 int br=REGION_GEOM(frame).w-(mg.x+mg.w);
112 int bb=REGION_GEOM(frame).h-(mg.y+mg.h);
114 rqg.x=(fp->g.x+param->inner_geom.x+
115 xgravity_deltax(param->gravity, bl, br));
116 rqg.y=(fp->g.y+param->inner_geom.y+
117 xgravity_deltay(param->gravity, bt, bb));
118 rqg.w=maxof(1, param->inner_geom.w+(REGION_GEOM(frame).w-mg.w));
119 rqg.h=maxof(1, param->inner_geom.h+(REGION_GEOM(frame).h-mg.h));
122 if(!(fp->mode®ION_FIT_WHATEVER))
123 rectangle_constrain(&rqg, &fp->g);
125 region_fit((WRegion*)frame, &rqg, REGION_FIT_EXACT);
127 return (WRegion*)frame;
131 WRegion *region_attach_framed(WRegion *reg, WFramedParam *param,
132 WRegionAttachFn *fn, void *fn_param,
133 WRegionAttachData *data)
135 WRegionAttachData data2;
138 data2.type=REGION_ATTACH_NEW;
139 data2.u.n.fn=framed_handler;
145 return fn(reg, fn_param, &data2);
149 WRegion *framedpholder_do_attach(WFramedPHolder *ph, int flags,
150 WRegionAttachData *data)
152 WRegionAttachData data2;
158 data2.type=REGION_ATTACH_NEW;
159 data2.u.n.fn=framed_handler;
165 return pholder_attach_(ph->cont, flags, &data2);
172 /*{{{ Other dynfuns */
175 bool framedpholder_do_goto(WFramedPHolder *ph)
178 return pholder_goto(ph->cont);
184 WRegion *framedpholder_do_target(WFramedPHolder *ph)
187 return pholder_target(ph->cont);
196 /*{{{ Class information */
199 static DynFunTab framedpholder_dynfuntab[]={
200 {(DynFun*)pholder_do_attach,
201 (DynFun*)framedpholder_do_attach},
203 {(DynFun*)pholder_do_goto,
204 (DynFun*)framedpholder_do_goto},
206 {(DynFun*)pholder_do_target,
207 (DynFun*)framedpholder_do_target},
212 IMPLCLASS(WFramedPHolder, WPHolder, framedpholder_deinit,
213 framedpholder_dynfuntab);