aboutsummaryrefslogtreecommitdiff
path: root/vendor/x11iraf/obm/ObmW/RowCol.c
blob: c37fed435636de4d02107c0b65c5fd7bc062f682 (plain) (blame)
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
/* Generated by wbuild from "RowCol.w"
** (generator version $Revision: 2.0 $ of $Date: 93/07/06 16:08:04 $)
*/
#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
#include "RowColP.h"
static void _resolve_inheritance(
#if NeedFunctionPrototypes
WidgetClass
#endif
);
static void change_managed(
#if NeedFunctionPrototypes
Widget
#endif
);
static void layout(
#if NeedFunctionPrototypes
Widget,int 
#endif
);
static XtGeometryResult  geometry_manager(
#if NeedFunctionPrototypes
Widget ,XtWidgetGeometry *,XtWidgetGeometry *
#endif
);
static void resize(
#if NeedFunctionPrototypes
Widget
#endif
);
static void initialize(
#if NeedFunctionPrototypes
Widget ,Widget,ArgList ,Cardinal *
#endif
);
static Boolean  set_values(
#if NeedFunctionPrototypes
Widget ,Widget ,Widget,ArgList ,Cardinal *
#endif
);
static char  rcsid[] = "$Header: RowCol.w,v 1.1 92/10/14 18:36:36 bert Exp $";
static void align_child(
#if NeedFunctionPrototypes
Widget,int ,int ,int ,int ,Alignment 
#endif
);
/*ARGSUSED*/static void align_child(self,cx,cy,width,height,alignment)Widget self;int  cx;int  cy;int  width;int  height;Alignment  alignment;
{
    Position x, y;

    if (alignment & XfwfLeft) x = cx;
    else if (alignment & XfwfRight) x = cx + width - ((XfwfRowColWidget)self)->core.width;
    else x = cx + (width - ((XfwfRowColWidget)self)->core.width) / 2;
    if (alignment & XfwfTop) y = cy;
    else if (alignment & XfwfBottom) y = cy + height - ((XfwfRowColWidget)self)->core.height;
    else y = cy + (height - ((XfwfRowColWidget)self)->core.height) / 2;
    XtMoveWidget(self, x, y);
}

static XtResource resources[] = {
{XtNstoreByRow,XtCStoreByRow,XtRBoolean,sizeof(((XfwfRowColRec*)NULL)->xfwfRowCol.storeByRow),XtOffsetOf(XfwfRowColRec,xfwfRowCol.storeByRow),XtRImmediate,(XtPointer)True },
{XtNrows,XtCRows,XtRInt,sizeof(((XfwfRowColRec*)NULL)->xfwfRowCol.rows),XtOffsetOf(XfwfRowColRec,xfwfRowCol.rows),XtRImmediate,(XtPointer)0 },
{XtNcolumns,XtCColumns,XtRInt,sizeof(((XfwfRowColRec*)NULL)->xfwfRowCol.columns),XtOffsetOf(XfwfRowColRec,xfwfRowCol.columns),XtRImmediate,(XtPointer)0 },
{XtNalignment,XtCAlignment,XtRAlignment,sizeof(((XfwfRowColRec*)NULL)->xfwfRowCol.alignment),XtOffsetOf(XfwfRowColRec,xfwfRowCol.alignment),XtRImmediate,(XtPointer)XfwfTopLeft },
{XtNshrinkToFit,XtCShrinkToFit,XtRBoolean,sizeof(((XfwfRowColRec*)NULL)->xfwfRowCol.shrinkToFit),XtOffsetOf(XfwfRowColRec,xfwfRowCol.shrinkToFit),XtRImmediate,(XtPointer)False },
{XtNframeType,XtCFrameType,XtRFrameType,sizeof(((XfwfRowColRec*)NULL)->xfwfFrame.frameType),XtOffsetOf(XfwfRowColRec,xfwfFrame.frameType),XtRImmediate,(XtPointer)XfwfSunken },
{XtNframeWidth,XtCFrameWidth,XtRDimension,sizeof(((XfwfRowColRec*)NULL)->xfwfFrame.frameWidth),XtOffsetOf(XfwfRowColRec,xfwfFrame.frameWidth),XtRImmediate,(XtPointer)2 },
};

XfwfRowColClassRec xfwfRowColClassRec = {
{ /* core_class part */
(WidgetClass) &xfwfBoardClassRec,
"RowCol",
sizeof(XfwfRowColRec),
NULL,
_resolve_inheritance,
FALSE,
initialize,
NULL,
XtInheritRealize,
NULL,
0,
resources,
7,
NULLQUARK,
False ,
FALSE ,
False ,
False ,
NULL,
resize,
XtInheritExpose,
set_values,
NULL,
XtInheritSetValuesAlmost,
NULL,
XtInheritAcceptFocus,
XtVersion,
NULL,
NULL,
XtInheritQueryGeometry,
XtInheritDisplayAccelerator,
NULL 
},
{ /* composite_class part */
geometry_manager,
change_managed,
XtInheritInsertChild,
XtInheritDeleteChild,
NULL
},
{ /* XfwfCommon_class part */
XtInherit_compute_inside,
XtInherit_highlight_border,
XtInherit_unhighlight_border,
XtInherit_would_accept_focus,
XtInherit_traverse,
XtInherit_choose_color,
XtInherit_lighter_color,
XtInherit_darker_color,
NULL ,
},
{ /* XfwfFrame_class part */
0
},
{ /* XfwfBoard_class part */
XtInherit_set_abs_location,
},
{ /* XfwfRowCol_class part */
layout,
},
};
WidgetClass xfwfRowColWidgetClass = (WidgetClass) &xfwfRowColClassRec;
static void _resolve_inheritance(class)
WidgetClass class;
{
  XfwfRowColWidgetClass c = (XfwfRowColWidgetClass) class;
  XfwfRowColWidgetClass super;
  static CompositeClassExtensionRec extension_rec = {
    NULL, NULLQUARK, XtCompositeExtensionVersion,
    sizeof(CompositeClassExtensionRec), True};
  CompositeClassExtensionRec *ext;
  ext = (XtPointer)XtMalloc(sizeof(*ext));
  *ext = extension_rec;
  ext->next_extension = c->composite_class.extension;
  c->composite_class.extension = ext;
  if (class == xfwfRowColWidgetClass) return;
  super = (XfwfRowColWidgetClass)class->core_class.superclass;
  if (c->xfwfRowCol_class.layout == XtInherit_layout)
    c->xfwfRowCol_class.layout = super->xfwfRowCol_class.layout;
}
/*ARGSUSED*/static void change_managed(self)Widget self;
{
    ((XfwfRowColWidgetClass)self->core.widget_class)->xfwfRowCol_class.layout(self, ((XfwfRowColWidget)self)->xfwfRowCol.shrinkToFit);
}
/*ARGSUSED*/static void layout(self,shrink)Widget self;int  shrink;
{
    int nrows, ncols, i, nchild, n;
    Position left, top, x, y;
    Dimension width, height, w, h;
    Widget child;

    nchild = 0;
    ((XfwfRowColWidget)self)->xfwfRowCol.max_width = 0;
    ((XfwfRowColWidget)self)->xfwfRowCol.max_height = 0;

    for (i = 0; i < ((XfwfRowColWidget)self)->composite.num_children; i++) {
	child = ((XfwfRowColWidget)self)->composite.children[i];
	if (! XtIsManaged(child)) continue;
	nchild++;
	((XfwfRowColWidget)self)->xfwfRowCol.max_width =
	    max(((XfwfRowColWidget)self)->xfwfRowCol.max_width,
	    ((XfwfRowColWidget)child)->core.width +
	    2*((XfwfRowColWidget)child)->core.border_width);
	((XfwfRowColWidget)self)->xfwfRowCol.max_height =
	    max(((XfwfRowColWidget)self)->xfwfRowCol.max_height,
	    ((XfwfRowColWidget)child)->core.height +
	    2*((XfwfRowColWidget)child)->core.border_width);
    }

    ((XfwfRowColWidgetClass)self->core.widget_class)->xfwfCommon_class.compute_inside(self, &left, &top, &width, &height);

    /* If there is a single child resize it to fill the window instead of
     * laying out multiple child widgets.  This allows a group widget to be
     * used to draw a labeled frame around a composite child.  09Mar94 DCT.
     */
    if (((XfwfRowColWidget)self)->composite.num_children == 1) {
	if (width > 0 && width < 16384 && height > 0 && height < 16384) {
	    /* Don't resize child if parent doesn't have a size yet.
	     */
	    child = ((XfwfRowColWidget)self)->composite.children[0];
	    w = width - 2 * child->core.border_width;
	    h = height - 2 * child->core.border_width;

	    XtResizeWidget (child, w, h,
		((XfwfRowColWidget)child)->core.border_width);
	    align_child (child, left, top, w, h, XfwfLeft|XfwfTop);

	    ((XfwfRowColWidget)self)->xfwfRowCol.max_width =
		child->core.width - 2 * child->core.border_width;
	    ((XfwfRowColWidget)self)->xfwfRowCol.max_height =
		child->core.height - 2 * child->core.border_width;

	    nrows = ncols = 1;
	    goto do_shrink;
	}
    }

    if (((XfwfRowColWidget)self)->xfwfRowCol.columns != 0) {
	ncols = ((XfwfRowColWidget)self)->xfwfRowCol.columns;
	nrows = (nchild + ncols - 1)/ncols;
    } else if (((XfwfRowColWidget)self)->xfwfRowCol.rows != 0) {
	nrows = ((XfwfRowColWidget)self)->xfwfRowCol.rows;
	ncols = (nchild + nrows - 1)/nrows;
    } else if (((XfwfRowColWidget)self)->composite.num_children == 1) {
	/* 09Mar94 DCT */
	nrows = ncols = 1;
    } else {
	ncols = ((XfwfRowColWidget)self)->xfwfRowCol.max_width != 0 ? width/((XfwfRowColWidget)self)->xfwfRowCol.max_width : 1;
	if (ncols == 0) ncols = 1;
	nrows = (nchild + ncols - 1)/ncols;
    }

    x = left;
    y = top;
    n = 0;
    if (((XfwfRowColWidget)self)->xfwfRowCol.storeByRow) {
	for (i = 0; i < ((XfwfRowColWidget)self)->composite.num_children; i++) {
	    child = ((XfwfRowColWidget)self)->composite.children[i];
	    if (! XtIsManaged(child)) continue;
	    align_child(child, x, y, ((XfwfRowColWidget)self)->xfwfRowCol.max_width, ((XfwfRowColWidget)self)->xfwfRowCol.max_height, ((XfwfRowColWidget)self)->xfwfRowCol.alignment);
	    n++;
	    if (n == ncols) {
		n = 0;
		x = left;
		y += ((XfwfRowColWidget)self)->xfwfRowCol.max_height;
	    } else
		x += ((XfwfRowColWidget)self)->xfwfRowCol.max_width;
	}
    } else {
	for (i = 0; i < ((XfwfRowColWidget)self)->composite.num_children; i++) {
	    child = ((XfwfRowColWidget)self)->composite.children[i];
	    if (! XtIsManaged(child)) continue;
	    align_child(child, x, y, ((XfwfRowColWidget)self)->xfwfRowCol.max_width, ((XfwfRowColWidget)self)->xfwfRowCol.max_height, ((XfwfRowColWidget)self)->xfwfRowCol.alignment);
	    n++;
	    if (n == nrows) {
		n = 0;
		y = top;
		x += ((XfwfRowColWidget)self)->xfwfRowCol.max_width;
	    } else
		y += ((XfwfRowColWidget)self)->xfwfRowCol.max_height;
	}
    }

do_shrink:
    if (shrink) {
	w = 2*left + ncols * ((XfwfRowColWidget)self)->xfwfRowCol.max_width;
	h = 2*top + nrows * ((XfwfRowColWidget)self)->xfwfRowCol.max_height;
	if (((XfwfRowColWidget)self)->xfwfRowCol.columns != 0)
	    XtVaSetValues(self, XtNwidth, w, XtNheight, h, NULL);
	else
	    XtVaSetValues(self, XtNheight, h, NULL);
    }
}


/*ARGSUSED*/static XtGeometryResult
geometry_manager (child,request,reply)
Widget  child;
XtWidgetGeometry * request;
XtWidgetGeometry * reply;
{
    Widget self = XtParent(child);
    Dimension newwd, newht, newbd;

    if (request->request_mode & (CWX | CWY))
	return XtGeometryNo;
    if (request->request_mode & XtCWQueryOnly)
	return XtGeometryYes;

    newwd = request->request_mode & CWWidth ?
	request->width : ((XfwfRowColWidget)child)->core.width;
    newht = request->request_mode & CWHeight ?
	request->height : ((XfwfRowColWidget)child)->core.height;
    newbd = request->request_mode & CWBorderWidth ?
	request->border_width : ((XfwfRowColWidget)child)->core.border_width;

    if (newwd == ((XfwfRowColWidget)child)->core.width &&
	newht == ((XfwfRowColWidget)child)->core.height &&
	newbd == ((XfwfRowColWidget)child)->core.border_width)
	return XtGeometryNo;

    XtResizeWidget(child, newwd, newht, newbd);

    ((XfwfRowColWidgetClass)self->core.widget_class)->xfwfRowCol_class.layout
	(self, ((XfwfRowColWidget)self)->xfwfRowCol.shrinkToFit);

    /* Since layout can resize the child widget it isn't appropriate to just
     * return XtGeometryDone here, as the FWF code does.  17Mar94 DCT.
     */
    if (newwd == ((XfwfRowColWidget)child)->core.width &&
	newht == ((XfwfRowColWidget)child)->core.height &&
	newbd == ((XfwfRowColWidget)child)->core.border_width) {

	return XtGeometryDone;

    } else {
	reply->request_mode = 0;
	if (newwd != child->core.width) {
	    reply->request_mode |= CWWidth;
	    reply->width = child->core.width;
	}
	if (newht != child->core.height) {
	    reply->request_mode |= CWHeight;
	    reply->height = child->core.height;
	}

	return XtGeometryAlmost;
    }
}

/*ARGSUSED*/static void resize(self)Widget self;
{
    if (((XfwfRowColWidget)self)->xfwfRowCol.rows == 0 && ((XfwfRowColWidget)self)->xfwfRowCol.columns == 0) ((XfwfRowColWidgetClass)self->core.widget_class)->xfwfRowCol_class.layout(self, False);
}
/*ARGSUSED*/static void initialize(request,self,args,num_args)Widget  request;Widget self;ArgList  args;Cardinal * num_args;
{
    ((XfwfRowColWidget)self)->xfwfRowCol.max_width = ((XfwfRowColWidget)self)->xfwfRowCol.max_height = 0;
}
/*ARGSUSED*/static Boolean  set_values(old,request,self,args,num_args)Widget  old;Widget  request;Widget self;ArgList  args;Cardinal * num_args;
{
    Boolean need_layout = False;
    Boolean need_redisplay = False;

    if (((XfwfRowColWidget)old)->xfwfRowCol.storeByRow != ((XfwfRowColWidget)self)->xfwfRowCol.storeByRow) need_layout = True;
    if (((XfwfRowColWidget)old)->xfwfRowCol.rows != ((XfwfRowColWidget)self)->xfwfRowCol.rows) need_layout = True;
    if (((XfwfRowColWidget)old)->xfwfRowCol.columns != ((XfwfRowColWidget)self)->xfwfRowCol.columns) need_layout = True;
    if (((XfwfRowColWidget)old)->xfwfRowCol.alignment != ((XfwfRowColWidget)self)->xfwfRowCol.alignment) need_layout = True;
    if (((XfwfRowColWidget)old)->xfwfRowCol.shrinkToFit != ((XfwfRowColWidget)self)->xfwfRowCol.shrinkToFit) need_layout = True;
    if (need_layout) {
	((XfwfRowColWidgetClass)self->core.widget_class)->xfwfRowCol_class.layout(self, ((XfwfRowColWidget)self)->xfwfRowCol.shrinkToFit);
	need_redisplay = True;
    }
    return need_redisplay;
}