1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
|
/*
* ion/ioncore/framedpholder.c
*
* Copyright (c) Tuomo Valkonen 2005-2009.
*
* See the included file LICENSE for details.
*/
#include <libtu/objp.h>
#include <libtu/obj.h>
#include <libtu/minmax.h>
#include "frame.h"
#include "framedpholder.h"
#include "sizehint.h"
#include "resize.h"
/*{{{ Init/deinit */
bool framedpholder_init(WFramedPHolder *ph, WPHolder *cont,
const WFramedParam *param)
{
assert(cont!=NULL);
pholder_init(&(ph->ph));
ph->cont=cont;
ph->param=*param;
watch_init(&ph->frame_watch);
return TRUE;
}
WFramedPHolder *create_framedpholder(WPHolder *cont,
const WFramedParam *param)
{
CREATEOBJ_IMPL(WFramedPHolder, framedpholder, (p, cont, param));
}
void framedpholder_deinit(WFramedPHolder *ph)
{
if(ph->cont!=NULL){
destroy_obj((Obj*)ph->cont);
ph->cont=NULL;
}
pholder_deinit(&(ph->ph));
watch_reset(&ph->frame_watch);
}
/*}}}*/
/*{{{ Attach */
typedef struct{
WRegionAttachData *data;
WFramedParam *param;
WRegion *reg_ret;
} AP;
void frame_adjust_to_initial(WFrame *frame, const WFitParams *fp,
const WFramedParam *param, WRegion *reg)
{
WRectangle rqg, mg;
WSizeHints szh;
int iw, ih;
if(!(fp->mode&(REGION_FIT_BOUNDS|REGION_FIT_WHATEVER)))
return;
mplex_managed_geom((WMPlex*)frame, &mg);
/* Adjust geometry */
if(!param->inner_geom_gravity_set){
iw=REGION_GEOM(reg).w;
ih=REGION_GEOM(reg).h;
rqg.x=REGION_GEOM(frame).x;
rqg.y=REGION_GEOM(frame).y;
}else{
int bl=mg.x;
int br=REGION_GEOM(frame).w-(mg.x+mg.w);
int bt=mg.y;
int bb=REGION_GEOM(frame).h-(mg.y+mg.h);
iw=param->inner_geom.w;
ih=param->inner_geom.h;
rqg.x=(/*fp->g.x+*/param->inner_geom.x+
xgravity_deltax(param->gravity, bl, br));
rqg.y=(/*fp->g.y+*/param->inner_geom.y+
xgravity_deltay(param->gravity, bt, bb));
}
/* Some apps seem to request geometries inconsistent with their size hints,
* so correct for that here.
* Because WGroup(CW) sets no_constrain on the size hints, we have
* to set override_no_constrain to force the frame to have the size
* of the 'bottom' of the group.
*/
region_size_hints(reg, &szh);
sizehints_correct(&szh, &iw, &ih, TRUE, TRUE);
rqg.w=maxof(1, iw+(REGION_GEOM(frame).w-mg.w));
rqg.h=maxof(1, ih+(REGION_GEOM(frame).h-mg.h));
if(!(fp->mode®ION_FIT_WHATEVER))
rectangle_constrain(&rqg, &fp->g);
region_fit((WRegion*)frame, &rqg, REGION_FIT_EXACT);
}
WRegion *framed_handler(WWindow *par,
const WFitParams *fp,
void *ap_)
{
AP *ap=(AP*)ap_;
WMPlexAttachParams mp=MPLEXATTACHPARAMS_INIT;
WFramedParam *param=ap->param;
WFrame *frame;
WRegion *reg;
frame=create_frame(par, fp, param->mode);
if(frame==NULL)
return NULL;
if(fp->mode&(REGION_FIT_BOUNDS|REGION_FIT_WHATEVER))
mp.flags|=MPLEX_ATTACH_WHATEVER;
reg=mplex_do_attach(&frame->mplex, &mp, ap->data);
ap->reg_ret=reg;
if(reg==NULL){
destroy_obj((Obj*)frame);
return NULL;
}
frame_adjust_to_initial(frame, fp, param, reg);
return (WRegion*)frame;
}
WRegion *region_attach_framed(WRegion *reg, WFramedParam *param,
WRegionAttachFn *fn, void *fn_param,
WRegionAttachData *data)
{
WRegionAttachData data2;
AP ap;
data2.type=REGION_ATTACH_NEW;
data2.u.n.fn=framed_handler;
data2.u.n.param=≈
ap.data=data;
ap.param=param;
ap.reg_ret=NULL;
return fn(reg, fn_param, &data2);
}
WRegion *framedpholder_do_attach(WFramedPHolder *ph, int flags,
WRegionAttachData *data)
{
WRegionAttachData data2;
WFrame *frame;
AP ap;
frame=(WFrame*)ph->frame_watch.obj;
if(frame!=NULL){
WMPlexAttachParams mp=MPLEXATTACHPARAMS_INIT;
return mplex_do_attach(&frame->mplex, &mp, data);
}
if(ph->cont==NULL)
return FALSE;
data2.type=REGION_ATTACH_NEW;
data2.u.n.fn=framed_handler;
data2.u.n.param=≈
ap.data=data;
ap.param=&ph->param;
ap.reg_ret=NULL;
frame=(WFrame*)pholder_do_attach(ph->cont, flags, &data2);
if(frame!=NULL){
assert(OBJ_IS(frame, WFrame));
watch_setup(&ph->frame_watch, (Obj*)frame, NULL);
}
return (flags&PHOLDER_ATTACH_RETURN_CREATEROOT
? (WRegion*)frame
: ap.reg_ret);
}
/*}}}*/
/*{{{ Other dynfuns */
bool framedpholder_do_goto(WFramedPHolder *ph)
{
WRegion *frame=(WRegion*)ph->frame_watch.obj;
if(frame!=NULL)
return region_goto((WRegion*)frame);
else if(ph->cont!=NULL)
return pholder_goto(ph->cont);
else
return FALSE;
}
WRegion *framedpholder_do_target(WFramedPHolder *ph)
{
WRegion *frame=(WRegion*)ph->frame_watch.obj;
return (frame!=NULL
? frame
: (ph->cont!=NULL
? pholder_target(ph->cont)
: NULL));
}
bool framedpholder_stale(WFramedPHolder *ph)
{
WRegion *frame=(WRegion*)ph->frame_watch.obj;
return (frame==NULL && (ph->cont==NULL || pholder_stale(ph->cont)));
}
/*}}}*/
/*{{{ Class information */
static DynFunTab framedpholder_dynfuntab[]={
{(DynFun*)pholder_do_attach,
(DynFun*)framedpholder_do_attach},
{(DynFun*)pholder_do_goto,
(DynFun*)framedpholder_do_goto},
{(DynFun*)pholder_do_target,
(DynFun*)framedpholder_do_target},
{(DynFun*)pholder_stale,
(DynFun*)framedpholder_stale},
END_DYNFUNTAB
};
IMPLCLASS(WFramedPHolder, WPHolder, framedpholder_deinit,
framedpholder_dynfuntab);
/*}}}*/
|