-
-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathframedpholder.c
236 lines (161 loc) · 4.72 KB
/
framedpholder.c
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
/*
* notion/ioncore/framedpholder.c
*
* Copyright (c) the Notion team 2013.
* Copyright (c) Tuomo Valkonen 2005-2007.
*
* 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"
/*{{{ 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;
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));
}
/*}}}*/
/*{{{ Attach */
typedef struct{
WRegionAttachData *data;
WFramedParam *param;
} AP;
void frame_adjust_to_initial(WFrame *frame, const WFitParams *fp,
const WFramedParam *param, WRegion *reg)
{
WRectangle rqg, mg;
if(!(fp->mode&(REGION_FIT_BOUNDS|REGION_FIT_WHATEVER)))
return;
mplex_managed_geom((WMPlex*)frame, &mg);
/* Adjust geometry */
if(!param->inner_geom_gravity_set){
rqg.x=REGION_GEOM(frame).x;
rqg.y=REGION_GEOM(frame).y;
rqg.w=MAXOF(1, REGION_GEOM(reg).w+(REGION_GEOM(frame).w-mg.w));
rqg.h=MAXOF(1, REGION_GEOM(reg).h+(REGION_GEOM(frame).h-mg.h));
}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);
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));
rqg.w=MAXOF(1, param->inner_geom.w+(REGION_GEOM(frame).w-mg.w));
rqg.h=MAXOF(1, param->inner_geom.h+(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, "Framed PHolder Frame");
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);
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;
return fn(reg, fn_param, &data2);
}
WRegion *framedpholder_do_attach(WFramedPHolder *ph, int flags,
WRegionAttachData *data)
{
WRegionAttachData data2;
AP ap;
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;
return pholder_do_attach(ph->cont, flags, &data2);
}
/*}}}*/
/*{{{ Other dynfuns */
bool framedpholder_do_goto(WFramedPHolder *ph)
{
return (ph->cont!=NULL
? pholder_goto(ph->cont)
: FALSE);
}
WRegion *framedpholder_do_target(WFramedPHolder *ph)
{
return (ph->cont!=NULL
? pholder_target(ph->cont)
: NULL);
}
WPHolder *framedpholder_do_root(WFramedPHolder *ph)
{
WPHolder *root;
if(ph->cont==NULL)
return NULL;
root=pholder_root(ph->cont);
return (root!=ph->cont
? root
: &ph->ph);
}
/*}}}*/
/*{{{ 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_do_root,
(DynFun*)framedpholder_do_root},
END_DYNFUNTAB
};
IMPLCLASS(WFramedPHolder, WPHolder, framedpholder_deinit,
framedpholder_dynfuntab);
/*}}}*/