1 /*
2  * Copyright 1991 Massachusetts Institute of Technology
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and its
5  * documentation for any purpose is hereby granted without fee, provided that
6  * the above copyright notice appear in all copies and that both that
7  * copyright notice and this permission notice appear in supporting
8  * documentation, and that the name of M.I.T. not be used in advertising or
9  * publicity pertaining to distribution of the software without specific,
10  * written prior permission.  M.I.T. makes no representations about the
11  * suitability of this software for any purpose.  It is provided "as is"
12  * without express or implied warranty.
13  *
14  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
16  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
18  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
19  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20  *
21  * Author:  Keith Packard, MIT X Consortium
22  */
23 
24 #ifndef _XawLayoutP_h
25 #define _XawLayoutP_h
26 
27 #if defined(LAYOUT)
28 # include "Layout.h"
29 #else
30 # include <X11/Xaw3dxft/Layout.h>
31 #endif
32 
33 #include <X11/ConstrainP.h>
34 
35 #ifdef MOTIF
36 # include "Xm/ManagerP.h"
37 #endif
38 
39 #define GlueEqual(a,b)	((a).order == (b).order && (a).value == (b).value)
40 
41 #define AddGlue(r,a,b)	if (a.order == b.order) { \
42 			    r.order = a.order; \
43 			    r.value = a.value + b.value; \
44 			} else { \
45 			    if (a.order > b.order) \
46 				r = a; \
47 			    else \
48 				r = b; \
49 			}
50 
51 #define MinGlue(r,a,b)	if (a.order == b.order) { \
52 			    r.order = a.order; \
53 			    if (a.value > b.value) \
54 				r.value = b.value; \
55 			    else \
56 				r.value = a.value; \
57 			} else { \
58 			    if (a.order > b.order) \
59 				r = b; \
60 			    else \
61 				r = a; \
62 			}
63 
64 #define SubGlue(r,a,b)	if (a.order == b.order) { \
65 			    r.order = a.order; \
66 			    r.value = a.value - b.value; \
67 			} else { \
68 			    if (a.order > b.order) \
69 				r = a; \
70 			    else { \
71 				r.order = b.order; \
72 				r.value = -b.value; \
73 			    } \
74 			}
75 
76 #define ZeroGlue(g)	((g).value = 0, (g).order = 0, (g).expr = 0)
77 #define IsZeroGlue(g)	((g).value == 0)
78 
79 #define QuarkToWidget(l,q)  XtNameToWidget((Widget) l, \
80 					   (char *) XrmQuarkToString(q));
81 
82 typedef enum _BoxType { BoxBox, WidgetBox, GlueBox, VariableBox } BoxType;
83 
84 typedef enum _LayoutDirection {
85     LayoutHorizontal = 0, LayoutVertical = 1
86 } LayoutDirection;
87 
88 typedef enum _Operator {
89     Plus, Minus, Times, Divide, Percent
90 } Operator;
91 
92 typedef enum _ExprType {
93     Constant,
94     Binary,
95     Unary,
96     Width,
97     Height,
98     Variable
99 } ExprType;
100 
101 typedef struct _Expr *ExprPtr;
102 
103 typedef struct _Expr {
104     ExprType	type;
105     union {
106 	double	    constant;
107 	struct {
108 	    Operator	op;
109 	    ExprPtr	left, right;
110 	} binary;
111 	struct {
112 	    Operator    op;
113 	    ExprPtr	down;
114 	} unary;
115 	XrmQuark    width;
116 	XrmQuark    height;
117 	XrmQuark    variable;
118     } u;
119 } ExprRec;
120 
121 typedef struct _Glue {
122     int		order;
123     double	value;
124     ExprPtr	expr;
125 } GlueRec, *GluePtr;
126 
127 typedef struct _BoxParams {
128     GlueRec stretch[2];
129     GlueRec shrink[2];
130 } BoxParamsRec, *BoxParamsPtr;
131 
132 typedef struct _Box *BoxPtr;
133 
134 typedef BoxPtr	LayoutPtr;
135 
136 typedef struct _Box {
137     BoxPtr	    nextSibling;
138     BoxPtr	    parent;
139     BoxParamsRec    params;
140     int		    size[2];
141     int		    natural[2];
142     BoxType	    type;
143     union {
144 	struct {
145 	    BoxPtr	    firstChild;
146 	    LayoutDirection dir;
147 	} box;
148 	struct {
149 	    XrmQuark	    quark;
150 	    Widget	    widget;
151 	} widget;
152 	struct {
153 	    ExprPtr	    expr;
154 	} glue;
155 	struct {
156 	    XrmQuark	    quark;
157 	    ExprPtr	    expr;
158 	} variable;
159     } u;
160 } LBoxRec; /* this conflicted with Box's BoxRec, besides, it's not used anywhere */
161 
162 typedef struct _SubInfo {
163     int	    naturalSize[2];
164     int	    naturalBw;
165 } SubInfoRec, *SubInfoPtr;
166 
167 /* #define New(t) (t *) malloc(sizeof (t)) */
168 #define New(t)      (t *) XtCalloc(1,sizeof (t))
169 #define Dispose(p)  XtFree((char *) p)
170 #define Some(t,n)   (t*) XtMalloc(sizeof(t) * n)
171 #define More(p,t,n) ((p)? (t *) XtRealloc((char *) p, sizeof(t)*n):Some(t,n)
172 
173 /*********************************************************************
174  *
175  * Layout Widget Private Data
176  *
177  *********************************************************************/
178 
179 /* New fields for the Layout widget class record */
180 
181 typedef struct _LayoutClassPart {
182     int foo;			/* keep compiler happy. */
183 } LayoutClassPart;
184 
185 /* Full Class record declaration */
186 typedef struct _LayoutClassRec {
187     CoreClassPart       core_class;
188     CompositeClassPart  composite_class;
189     ConstraintClassPart constraint_class;
190 #ifdef MOTIF
191     XmManagerClassPart  manager_class;
192 #endif
193     LayoutClassPart     layout_class;
194 } LayoutClassRec;
195 
196 extern LayoutClassRec layoutClassRec;
197 
198 typedef struct _LayoutConstraintsRec {
199 #ifdef MOTIF
200     XmManagerConstraintPart  manager;
201 #endif
202     SubInfoRec	layout;
203 } LayoutConstraintsRec, *LayoutConstraints;
204 
205 #define SubInfo(w)  (&(((LayoutConstraints) (w)->core.constraints)->layout))
206 
207 /* New Fields for the Layout widget record */
208 
209 typedef struct {
210     /* resources */
211     LayoutPtr	layout;
212     Boolean	debug;
213 } LayoutPart;
214 
215 /**************************************************************************
216  *
217  * Full instance record declaration
218  *
219  **************************************************************************/
220 
221 typedef struct _LayoutRec {
222     CorePart       core;
223     CompositePart  composite;
224     ConstraintPart constraint;
225 #ifdef MOTIF
226     XmManagerPart  manager;
227 #endif
228     LayoutPart     layout;
229 } LayoutRec;
230 #endif
231