1 /*
2  * Copyright(c) 1992 Bell Communications Research, Inc. (Bellcore)
3  * Copyright(c) 1995-99 Andrew Lister
4  *
5  *                        All rights reserved
6  * Permission to use, copy, modify and distribute this material for
7  * any purpose and without fee is hereby granted, provided that the
8  * above copyright notice and this permission notice appear in all
9  * copies, and that the name of Bellcore not be used in advertising
10  * or publicity pertaining to this material without the specific,
11  * prior written permission of an authorized representative of
12  * Bellcore.
13  *
14  * BELLCORE MAKES NO REPRESENTATIONS AND EXTENDS NO WARRANTIES, EX-
15  * PRESS OR IMPLIED, WITH RESPECT TO THE SOFTWARE, INCLUDING, BUT
16  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS FOR ANY PARTICULAR PURPOSE, AND THE WARRANTY AGAINST IN-
18  * FRINGEMENT OF PATENTS OR OTHER INTELLECTUAL PROPERTY RIGHTS.  THE
19  * SOFTWARE IS PROVIDED "AS IS", AND IN NO EVENT SHALL BELLCORE OR
20  * ANY OF ITS AFFILIATES BE LIABLE FOR ANY DAMAGES, INCLUDING ANY
21  * LOST PROFITS OR OTHER INCIDENTAL OR CONSEQUENTIAL DAMAGES RELAT-
22  * ING TO THE SOFTWARE.
23  *
24  * $Id: Macros.h,v 1.1 1999/09/11 01:25:37 fnevgeny Exp $
25  */
26 
27 /*
28  * Macros.h created by Andrew Lister (6 August, 1995)
29  */
30 
31 #ifndef _Xbae_Macros_h
32 #define _Xbae_Macros_h
33 /*
34  * Prototype wrapper
35  */
36 #ifndef P
37 #if defined(__STDC__) || defined (__cplusplus)
38 #define P(x)		x
39 #else
40 #define P(x)		()
41 #define const
42 #define volatile
43 #endif
44 #endif
45 
46 #if XmVersion <= 1001
47 #include <Xm/XmP.h>
48 #else
49 #include <Xm/DrawP.h>
50 #endif
51 #include <Xm/TextP.h>
52 #include <Xm/PrimitiveP.h>
53 
54 #if XmVersion <= 1001
55 #define DRAW_SHADOW(dpy, draw, tgc, bgc, sz, x, y, w, h, type)	\
56     _XmDrawShadow(dpy, draw, tgc, bgc, sz, x, y, w, h)
57 #else
58 #if XmVersion >= 2000
59 #define DRAW_SHADOW(dpy, draw, tgc, bgc, sz, x, y, w, h, type)	\
60     XmeDrawShadows(dpy, draw, tgc, bgc, x, y, w, h, sz, type)
61 #else
62 #define DRAW_SHADOW(dpy, draw, tgc, bgc, sz, x, y, w, h, type)	\
63     _XmDrawShadows(dpy, draw, tgc, bgc, x, y, w, h, sz, type)
64 #endif
65 #endif
66 
67 #if XmVersion <= 1001
68 #define DRAW_HIGHLIGHT(dpy, draw, tgc, x, y, w, h, sz, type) \
69 	_XmDrawSimpleHighlight(dpy, draw, tgc, x, y, w, h, sz, type)
70 #else
71 #if XmVersion >= 2000
72 #define DRAW_HIGHLIGHT(dpy, draw, tgc, x, y, w, h, sz, type) \
73 	XmeDrawHighlight(dpy, draw, tgc, x, y, w, h, sz)
74 #else
75 #define DRAW_HIGHLIGHT(dpy, draw, tgc, x, y, w, h, sz, type) \
76 	_XmDrawHighlight(dpy, draw, tgc, x, y, w, h, sz, type)
77 #endif
78 #endif
79 /*
80  * Macros to retrieve our children.  Children must be created in this order.
81  */
82 #define XbaeNumChildren		8
83 
84 #define HorizScrollChild(mw)	(mw->composite.children[0])
85 #define VertScrollChild(mw)	(mw->composite.children[1])
86 #define ClipChild(mw)		(mw->composite.children[2])
87 #define TextChild(mw)		(mw->composite.children[3])
88 #define LeftClip(mw)		(mw->composite.children[4])
89 #define RightClip(mw)		(mw->composite.children[5])
90 #define TopClip(mw)		(mw->composite.children[6])
91 #define BottomClip(mw)		(mw->composite.children[7])
92 
93 #define VISIBLE_WIDTH(mw)	((int)ClipChild(mw)->core.width)
94 #define VISIBLE_HEIGHT(mw)	((int)ClipChild(mw)->core.height)
95 
96 #define VERT_ORIGIN(mw)		(mw->matrix.top_row)
97 #define TRAILING_VERT_ORIGIN(mw) (mw->matrix.rows - \
98 				  (int)mw->matrix.trailing_fixed_rows)
99 #define HORIZ_ORIGIN(mw)	(mw->matrix.horiz_origin)
100 #define TRAILING_HORIZ_ORIGIN(mw) (mw->matrix.columns - \
101 				   (int)mw->matrix.trailing_fixed_columns)
102 
103 /*
104  * Macros
105  */
106 
107 /*
108  * Max and Min are defined in Xm/XmP.h in 1.1, they are deprecated in 1.2
109  */
110 #if XmVersion >= 1002
111 #define Max(x, y)       (((x) > (y)) ? (x) : (y))
112 #define Min(x, y)       (((x) < (y)) ? (x) : (y))
113 #endif
114 
115 #define FONT_WIDTH(mw)		(mw->matrix.font_width)
116 
117 #define LABEL_WIDTH(mw)		(mw->matrix.label_font_width)
118 
119 #define TEXT_WIDTH_OFFSET(mw)	(mw->matrix.cell_margin_width +\
120 				 mw->matrix.cell_shadow_thickness + \
121 				 mw->matrix.cell_highlight_thickness + \
122 				 mw->matrix.text_shadow_thickness)
123 
124 #define TEXT_HEIGHT_OFFSET(mw)	(mw->matrix.cell_margin_height +\
125 				 mw->matrix.cell_shadow_thickness + \
126 				 mw->matrix.cell_highlight_thickness + \
127 				 mw->matrix.text_shadow_thickness)
128 
129 #define COLUMN_WIDTH(mw, col)	((mw->matrix.column_widths[col] * \
130 				  FONT_WIDTH(mw)) + \
131 				 ((int)TEXT_WIDTH_OFFSET(mw) * 2))
132 
133 #define FONT_HEIGHT(mw)		(mw->matrix.font_height)
134 
135 #define LABEL_HEIGHT(mw)	(mw->matrix.label_font_height)
136 
137 #define HORIZ_SB_WIDTH(mw)	(HorizScrollChild(mw)->core.width + \
138 				 2 * HorizScrollChild(mw)->core.border_width)
139 
140 #define HORIZ_SB_HEIGHT(mw)	(HorizScrollChild(mw)->core.height + \
141 				 2 * HorizScrollChild(mw)->core.border_width +\
142 				 mw->matrix.space)
143 
144 #define HORIZ_SB_SPACE(mw)	(! HorizScrollChild(mw)->core.managed ? \
145 				 0 : HORIZ_SB_HEIGHT(mw))
146 
147 #define HORIZ_SB_OFFSET(mw)	(((mw->matrix.scrollbar_placement == \
148 				   XmTOP_LEFT) || \
149 				  (mw->matrix.scrollbar_placement == \
150 				   XmTOP_RIGHT)) ? HORIZ_SB_SPACE(mw) : 0)
151 
152 #define HORIZ_SB_POSITION(mw)	(((mw->matrix.scrollbar_placement == \
153 				   XmTOP_LEFT) || \
154 				  (mw->matrix.scrollbar_placement == \
155 				   XmTOP_RIGHT)) ? 0 : \
156 				 TRAILING_FIXED_ROW_LABEL_OFFSET(mw))
157 
158 #define VERT_SB_WIDTH(mw)	(VertScrollChild(mw)->core.width + \
159 				 2 * VertScrollChild(mw)->core.border_width + \
160 				 mw->matrix.space)
161 
162 #define VERT_SB_HEIGHT(mw)	(VertScrollChild(mw)->core.height + \
163 				 2 * VertScrollChild(mw)->core.border_width)
164 
165 #define VERT_SB_SPACE(mw)	(! VertScrollChild(mw)->core.managed ? \
166 				 0 : VERT_SB_WIDTH(mw))
167 
168 #define VERT_SB_OFFSET(mw)	(((mw->matrix.scrollbar_placement == \
169 				   XmTOP_LEFT) || \
170 				 (mw->matrix.scrollbar_placement == \
171 				  XmBOTTOM_LEFT)) ? VERT_SB_SPACE(mw) : 0)
172 
173 #define VERT_SB_POSITION(mw)	(((mw->matrix.scrollbar_placement == \
174 				   XmTOP_LEFT) || \
175 				  (mw->matrix.scrollbar_placement == \
176 				   XmBOTTOM_LEFT)) ? 0 : \
177 				 VertScrollChild(mw)->core.x - \
178 				 mw->matrix.space)
179 
180 #define CLIP_HORIZ_VISIBLE_SPACE(mw) ((int)(VISIBLE_WIDTH(mw) +\
181 				      FIXED_COLUMN_WIDTH(mw) + \
182 				      TRAILING_FIXED_COLUMN_WIDTH(mw)))
183 
184 #define CLIP_VERT_VISIBLE_SPACE(mw) ((int)(mw->matrix.cell_visible_height +\
185 				      FIXED_ROW_HEIGHT(mw) + \
186 				      TRAILING_FIXED_ROW_HEIGHT(mw)))
187 
188 #define MATRIX_HORIZ_VISIBLE_SPACE(mw) ((int)(mw->core.width - \
189 					 mw->manager.shadow_thickness - \
190 					 COLUMN_LABEL_OFFSET(mw) -\
191 					 VERT_SB_SPACE(mw)))
192 
193 #define MATRIX_VERT_VISIBLE_SPACE(mw) ((int)(mw->core.height -\
194 					mw->manager.shadow_thickness - \
195 					ROW_LABEL_OFFSET(mw) -\
196 					HORIZ_SB_SPACE(mw)))
197 
198 #define NEED_HORIZ_FILL(mw)	(mw->matrix.fill && \
199 				  (MATRIX_HORIZ_VISIBLE_SPACE(mw) > \
200 				    CLIP_HORIZ_VISIBLE_SPACE(mw)))
201 
202 #define NEED_VERT_FILL(mw)	(mw->matrix.fill && \
203 				  (MATRIX_VERT_VISIBLE_SPACE(mw) > \
204 				    CLIP_VERT_VISIBLE_SPACE(mw)))
205 
206 #define	FILL_HORIZ_WIDTH(mw)	(mw->core.width - VISIBLE_WIDTH(mw) - \
207 				  TRAILING_FIXED_COLUMN_WIDTH(mw) - \
208 				  VERT_SB_SPACE(mw) - \
209 				  FIXED_COLUMN_LABEL_OFFSET(mw) - \
210 				  mw->manager.shadow_thickness)
211 
212 #define	FILL_VERT_HEIGHT(mw)	(mw->core.height - VISIBLE_HEIGHT(mw) - \
213 				  TRAILING_FIXED_ROW_HEIGHT(mw) - \
214 				  FIXED_ROW_LABEL_OFFSET(mw) - \
215 				  mw->manager.shadow_thickness)
216 
217 #define SANITY_CHECK_ROW(mw, row) (row = (row >= mw->matrix.rows) ? \
218 				      ((mw->matrix.rows > 0) ? \
219 					mw->matrix.rows - 1 : 0) : \
220 				      (row < 0) ? 0 : row)
221 
222 #define SANITY_CHECK_COLUMN(mw, column) (column = \
223 					    (column >= mw->matrix.columns) ? \
224 					    ((mw->matrix.columns > 0) ? \
225 					     mw->matrix.columns - 1 : 0) : \
226 					    (column < 0) ? 0 : column)
227 
228 /*
229  * The text height defines the row height.  It needs to be the biggest
230  * we can expect from both font and label font
231  */
232 #define TEXT_HEIGHT(mw)		(Max(FONT_HEIGHT(mw), LABEL_HEIGHT(mw)))
233 
234 #define ROW_HEIGHT(mw)		(int)((TEXT_HEIGHT_OFFSET(mw) * 2) + \
235 				      TEXT_HEIGHT(mw))
236 
237 #define TEXT_X_OFFSET(mw)	(int)(TEXT_WIDTH_OFFSET(mw))
238 
239 #define TEXT_Y_OFFSET(mw)	(int)(mw->matrix.text_baseline)
240 
241 #define LABEL_Y_OFFSET(mw)	(int)(mw->matrix.label_baseline)
242 
243 #define ROW_LABEL_WIDTH(mw)	((mw->matrix.row_labels \
244 				 ? (mw->matrix.row_label_width * \
245 				    LABEL_WIDTH(mw)) + \
246 				 (int)TEXT_WIDTH_OFFSET(mw) * 2 : 0) + \
247 				 (mw->matrix.button_labels ? \
248 				 mw->matrix.cell_shadow_thickness * 2 : 0))
249 
250 #define COLUMN_LABEL_HEIGHT(mw) (mw->matrix.column_labels \
251 				 ? (int)TEXT_HEIGHT_OFFSET(mw) * 2 + \
252 				 mw->matrix.column_label_maxlines * \
253 				 LABEL_HEIGHT(mw) : 0)
254 
255 #define COLUMN_POSITION(mw, column) mw->matrix.column_positions[column]
256 
257 #define FIXED_COLUMN_WIDTH(mw)	COLUMN_POSITION(mw, mw->matrix.fixed_columns)
258 
259 #define TRAILING_FIXED_COLUMN_WIDTH(mw) \
260                   (mw->matrix.trailing_fixed_columns ? \
261 		    (COLUMN_POSITION(mw, mw->matrix.columns-1) + \
262 		     COLUMN_WIDTH(mw, mw->matrix.columns-1) - \
263 		     COLUMN_POSITION(mw, TRAILING_HORIZ_ORIGIN(mw))) : 0)
264 
265 #define COLUMN_LABEL_OFFSET(mw)	(ROW_LABEL_WIDTH(mw) + \
266 				 VERT_SB_OFFSET(mw) + \
267 				 (int)mw->manager.shadow_thickness)
268 
269 #define FIXED_COLUMN_LABEL_OFFSET(mw) (COLUMN_LABEL_OFFSET(mw) + \
270 				       FIXED_COLUMN_WIDTH(mw))
271 
272 #define TRAILING_FIXED_COLUMN_LABEL_OFFSET(mw) (FIXED_COLUMN_LABEL_OFFSET(mw)+\
273 						VISIBLE_WIDTH(mw))
274 
275 #define FIXED_ROW_HEIGHT(mw)	((int)mw->matrix.fixed_rows * ROW_HEIGHT(mw))
276 
277 #define TRAILING_FIXED_ROW_HEIGHT(mw) ((int)mw->matrix.trailing_fixed_rows * \
278 				       ROW_HEIGHT(mw))
279 
280 #define ROW_LABEL_OFFSET(mw)	(COLUMN_LABEL_HEIGHT(mw) + \
281 				 HORIZ_SB_OFFSET(mw) + \
282 				 mw->manager.shadow_thickness)
283 
284 #define FIXED_ROW_LABEL_OFFSET(mw) (ROW_LABEL_OFFSET(mw) + \
285 				    FIXED_ROW_HEIGHT(mw))
286 
287 #define UNATTACHED_TRAILING_ROWS_OFFSET(mw) (FIXED_ROW_LABEL_OFFSET(mw) + \
288 					     VISIBLE_HEIGHT(mw))
289 
290 #define ATTACHED_TRAILING_ROWS_OFFSET(mw) (mw->core.height - \
291 					   mw->manager.shadow_thickness - \
292 					   HORIZ_SB_SPACE(mw) - \
293 					   TRAILING_FIXED_ROW_HEIGHT(mw))
294 
295 #define VERT_DEAD_SPACE_HEIGHT(mw)  ((int)(ATTACHED_TRAILING_ROWS_OFFSET(mw) - \
296 				     UNATTACHED_TRAILING_ROWS_OFFSET(mw)))
297 
298 #define HAS_ATTACHED_TRAILING_ROWS(mw)  (mw->matrix.fill &&  \
299 					 mw->matrix.trailing_attached_bottom && \
300 					 mw->matrix.trailing_fixed_rows)
301 
302 #define TRAILING_FIXED_ROW_LABEL_OFFSET(mw) (HAS_ATTACHED_TRAILING_ROWS(mw) ? \
303 					     ATTACHED_TRAILING_ROWS_OFFSET(mw) : \
304 					     UNATTACHED_TRAILING_ROWS_OFFSET(mw))
305 
306 #define NEED_VERT_DEAD_SPACE_FILL(mw) (HAS_ATTACHED_TRAILING_ROWS(mw) && \
307 				      (VERT_DEAD_SPACE_HEIGHT(mw) > 0))
308 
309 #define NON_FIXED_TOTAL_WIDTH(mw) 	mw->matrix.non_fixed_total_width
310 
311 #define CELL_TOTAL_HEIGHT(mw)	((mw->matrix.rows - \
312 				  (int) mw->matrix.fixed_rows - \
313 				  (int) mw->matrix.trailing_fixed_rows) \
314 				 * ROW_HEIGHT(mw))
315 
316 #define IS_LEADING_FIXED_COLUMN(mw, column) (column < (int)mw->matrix.fixed_columns)
317 
318 #define IS_TRAILING_FIXED_COLUMN(mw, column) (column >= TRAILING_HORIZ_ORIGIN(mw))
319 
320 #define IS_FIXED_COLUMN(mw, column) (IS_LEADING_FIXED_COLUMN(mw, column) || \
321 				     IS_TRAILING_FIXED_COLUMN(mw, column))
322 
323 #define IS_LEADING_FIXED_ROW(mw, row) (row < (int)mw->matrix.fixed_rows)
324 
325 #define IS_TRAILING_FIXED_ROW(mw, row) (row >= TRAILING_VERT_ORIGIN(mw))
326 
327 #define IS_FIXED_ROW(mw, row) (IS_LEADING_FIXED_ROW(mw, row) || \
328 			       IS_TRAILING_FIXED_ROW(mw, row))
329 
330 #define IS_FIXED(mw, row, column) (IS_FIXED_ROW(mw, row) || \
331 				   IS_FIXED_COLUMN(mw, column))
332 
333 #define IS_CLIPPED(mw, row, column) ((row >= (int)mw->matrix.fixed_rows) && \
334 				       (column >= \
335 					(int)mw->matrix.fixed_columns) && \
336 				       (row < TRAILING_VERT_ORIGIN(mw)) && \
337 				       (column < TRAILING_HORIZ_ORIGIN(mw)))
338 
339 /*
340  * I hereby dub thee, Jay Schmidgall, as Sir Silly Macro - writer of
341  * the most obsfucated macros I've ever seen - AL (26 Feb 1998)
342  *
343  * How do you come up with these???  The first couple are OK but
344  * the last two???
345  */
346 
347 /* Here are some handy dandy macros to make it look cleaner in the
348  * actual code. I did the vertical scrollbar stuff first, then the
349  * horizontal. For the horizontal, I just referenced the other
350  * orientation, and it worked. */
351 
352 /* If we have fixed rows, the y position of the vsb must
353  * be offset starting from the fixed rows. Otherwise, we
354  * want it to be even with the matrix area top.  Perhaps
355  * oddly, we can use this macro for both XtConfigure's. */
356 
357 #define VSB_Y_POSITION(mw) (mw->matrix.fixed_rows ? \
358 			    FIXED_ROW_LABEL_OFFSET(mw) - \
359 			    HORIZ_SB_OFFSET(mw) + \
360 			    ((scrollbar_top && has_horiz) ? \
361 			     HORIZ_SB_HEIGHT(mw) : 0) : \
362 			    COLUMN_LABEL_HEIGHT(mw) + \
363 			    HORIZ_SB_OFFSET(mw))
364 
365 #define HSB_X_POSITION(mw) (mw->matrix.fixed_columns ? \
366 			    FIXED_COLUMN_LABEL_OFFSET(mw) - \
367 			    VERT_SB_OFFSET(mw) + \
368 			    ((scrollbar_left && has_vert) ? \
369 			     VERT_SB_WIDTH(mw) : 0) : \
370 			    ROW_LABEL_WIDTH(mw) + VERT_SB_OFFSET(mw))
371 
372 /* I started trying to write a comment that sort of explains this macro.
373  * Then I quit. What the heck, it works. Feel free on your own to make
374  * up something that reassures you. I myself have the feeling that there
375  * has got to be a cleaner, better way to do this, sort of like the above
376  * two seem somehow fairly clean. But this? This is some serious gaaack.
377  * Same thing as above. Did VSB first, then just switched orientation
378  * for HSB.
379  */
380 #define VSB_HEIGHT(mw) ((!mw->matrix.fill) ? cell_height + \
381 			mw->manager.shadow_thickness * \
382 			(mw->matrix.fixed_rows || \
383 			 mw->matrix.trailing_fixed_rows ? \
384 			 (mw->matrix.fixed_rows && \
385 			  mw->matrix.trailing_fixed_rows ? 0 : 1) : 2) : \
386 			((TRAILING_FIXED_ROW_HEIGHT(mw) > 0) ? full_height - \
387 			 (mw->matrix.fixed_rows ? \
388 			  mw->manager.shadow_thickness : 0) - \
389 			 ROW_LABEL_OFFSET(mw) - FIXED_ROW_HEIGHT(mw) - \
390 			 TRAILING_FIXED_ROW_HEIGHT(mw) + \
391 			 HORIZ_SB_OFFSET(mw) : mw->core.height + \
392 			 (mw->matrix.fixed_rows ? 0 : \
393 			  mw->manager.shadow_thickness) - \
394 			 ROW_LABEL_OFFSET(mw) - FIXED_ROW_HEIGHT(mw) + \
395 			 HORIZ_SB_OFFSET(mw) - \
396 			 (has_horiz ? HORIZ_SB_HEIGHT(mw) : 0)))
397 
398 #define HSB_WIDTH(mw) ((!mw->matrix.fill) ? cell_width + \
399 		       mw->manager.shadow_thickness * \
400 		       (mw->matrix.fixed_columns || \
401 			mw->matrix.trailing_fixed_columns ? \
402 			(mw->matrix.fixed_columns && \
403 			 mw->matrix.trailing_fixed_columns ? 0 : 1) : 2) : \
404 			((TRAILING_FIXED_COLUMN_WIDTH(mw) > 0) ? \
405 			 full_width - (mw->matrix.fixed_columns ? \
406 				       mw->manager.shadow_thickness : 0) - \
407 			 COLUMN_LABEL_OFFSET(mw) - FIXED_COLUMN_WIDTH(mw) - \
408 			 TRAILING_FIXED_COLUMN_WIDTH(mw) + \
409 			 VERT_SB_OFFSET(mw) : \
410 			 mw->core.width + (mw->matrix.fixed_columns ? 0 :\
411 					   mw->manager.shadow_thickness) - \
412 			 COLUMN_LABEL_OFFSET(mw) - FIXED_COLUMN_WIDTH(mw) + \
413 			 VERT_SB_OFFSET(mw) - \
414 			 (has_vert ? VERT_SB_WIDTH(mw) : 0)))
415 
416 #define CELL_WINDOW(mw, row, column) \
417 	(IS_FIXED(mw, row, column) ? XtWindow(mw) : XtWindow(ClipChild(mw)))
418 
419 /* Inline functions */
420 #define xbaeFreeColumnWidths(mw)	{ \
421 					       if (mw->matrix.column_widths) \
422 					       XtFree((XtPointer) \
423 					       mw->matrix.column_widths); \
424 					}
425 
426 #define xbaeFreeColumnMaxLengths(mw)	{ \
427 					       if (mw->matrix.\
428 					       column_max_lengths) \
429 					       XtFree((XtPointer) \
430 					       mw->matrix. \
431 					       column_max_lengths); \
432 					}
433 
434 #define xbaeFreeColumnPositions(mw)		{ \
435 					       if (mw->matrix. \
436 					       column_positions) \
437 					       XtFree((XtPointer) \
438 					       mw->matrix. \
439 					       column_positions); \
440 					}
441 
442 #define xbaeFreeColumnAlignments(mw)	{ \
443 					       if (mw->matrix. \
444 					       column_alignments) \
445 					       XtFree((XtPointer) \
446 					       mw->matrix. \
447 					       column_alignments); \
448 					}
449 
450 #define xbaeFreeColumnButtonLabels(mw)	{ \
451 					       if (mw->matrix. \
452 					       column_button_labels) \
453 					       XtFree((XtPointer) \
454 					       mw->matrix. \
455 					       column_button_labels); \
456 					}
457 
458 #define xbaeFreeRowButtonLabels(mw)	{ \
459 					       if (mw->matrix. \
460 					       row_button_labels) \
461 					       XtFree((XtPointer) \
462 					       mw->matrix. \
463 					       row_button_labels); \
464 					}
465 
466 #define xbaeFreeColumnLabelAlignments(mw)	{ \
467 					       if (mw->matrix. \
468 					       column_label_alignments) \
469 					       XtFree((XtPointer) \
470 					       mw->matrix. \
471 					       column_label_alignments); \
472 					}
473 
474 #define xbaeFreeRowUserData(mw)		{ \
475 					       if (mw->matrix.\
476 					       row_user_data) \
477 					       XtFree((XtPointer) \
478 					       mw->matrix.\
479 					       row_user_data); \
480 					}
481 
482 #define xbaeFreeColumnUserData(mw)	{ \
483 					       if (mw->matrix.\
484 					       column_user_data) \
485 					       XtFree((XtPointer) \
486 					       mw->matrix.\
487 					       column_user_data); \
488 					}
489 
490 #define xbaeFreeRowShadowTypes(mw)	{ \
491 					       if (mw->matrix.\
492 					       row_shadow_types) \
493 					       XtFree((XtPointer) \
494 					       mw->matrix.\
495 					       row_shadow_types); \
496 					}
497 
498 #define xbaeFreeColumnShadowTypes(mw)	{ \
499 					       if (mw->matrix.\
500 					       column_shadow_types) \
501 					       XtFree((XtPointer) \
502 					       mw->matrix.\
503 					       column_shadow_types); \
504 					}
505 
506 #define CreateColumnPositions(mw)  (int *)XtMalloc((mw->matrix.columns+1)* \
507 						   sizeof(int))
508 #define YtoRow(mw, y)			((y) / ROW_HEIGHT(mw))
509 
510 
511 /*
512  * Evaluates to 1 if two Rectangles overlap, 0 if no overlap
513  */
514 #define OVERLAP(r1, r2) ((r1).x2 >= (r2).x1 && \
515 			 (r1).x1 <= (r2).x2 && \
516 			 (r1).y2 >= (r2).y1 && \
517 			 (r1).y1 <= (r2).y2)
518 
519 /*
520  * Intersect rectangles r1 and r2, place the result in res.
521  * Result will be in r1's coord system.
522  */
523 #define X_INTERSECT(r1, r2, res) { (res).x1 = Max((r1).x1, (r2).x1) - (r1).x1;\
524     (res).x2 = Min((r1).x2, (r2).x2) - (r1).x1;}
525 
526 #define Y_INTERSECT(r1, r2, res) { (res).y1 = Max((r1).y1, (r2).y1) - (r1).y1;\
527     (res).y2 = Min((r1).y2, (r2).y2) - (r1).y1;}
528 
529 #define INTERSECT(r1, r2, res)	{ X_INTERSECT(r1, r2, res); \
530     Y_INTERSECT(r1, r2, res); }
531 
532 /*
533  * Evaluates to 1 if the point is in the Rectangle, 0 if not
534  */
535 #define INBOX(r, x, y)		((((r).x2 >= x)) && \
536 				  (((r).x1 <= x)) && \
537 				  (((r).y2 >= y)) && \
538 				  (((r).y1 <= y)))
539 
540 /*
541  * Macros used for Rectangle calculations.  A Rectangle is defined by it's
542  * upper left and lower right corners.
543  */
544 
545 /*
546  * Set a Rectangle. (x1,y1) is upper left corner, (x2,y2) is lower right corner
547  */
548 #define SETRECT(r, X1, Y1, X2, Y2) { (r).x1 = X1; (r).y1 = Y1; \
549     (r).x2 = X2; (r).y2 = Y2; }
550 
551 #ifdef NEED_WCHAR
552 #define TWO_BYTE_FONT(mw)	(mw->matrix.font->max_byte1 != 0)
553 #endif
554 
555 #ifdef NEED_24BIT_VISUAL
556 #define GC_PARENT_WINDOW(w)	XtWindow(get_shell_ancestor((Widget)w))
557 #else
558 #define GC_PARENT_WINDOW(w)	RootWindowOfScreen(XtScreen(w))
559 #endif
560 
561 /*
562  * End of array flags for the array type converters
563  */
564 #define BAD_WIDTH	-1
565 #define BAD_MAXLENGTH	0
566 #define BAD_ALIGNMENT	3	/* see Xm.h */
567 #define BAD_PIXEL	0x10000000 /* normally 256 indices */
568 
569 
570 /*
571  * SetClipMask flags for indicating clip areas
572  */
573 #define CLIP_NONE			0x0000
574 #define CLIP_FIXED_COLUMNS		0x0001
575 #define CLIP_FIXED_ROWS			0x0002
576 #define CLIP_TRAILING_FIXED_COLUMNS	0x0004
577 #define CLIP_TRAILING_FIXED_ROWS	0x0008
578 #define CLIP_BETWEEN_FIXED_ROWS		0x0010
579 #define CLIP_VISIBLE_HEIGHT		0x0020
580 #define CLIP_TRAILING_HORIZ_FILL	0x0040
581 #define CLIP_TRAILING_VERT_FILL		0x0080
582 #define CLIP_COLUMN_LABELS     		0x0100
583 #define CLIP_ROW_LABELS     		0x0200
584 #define CLIP_ALL	     		0x0400
585 
586 /*
587  * Row and Column grid shadow/line redraw reasons
588  */
589 #define GRID_REDRAW_EXPOSE		0x0000
590 #define GRID_REDRAW_SCROLL_VERT		0x0001
591 #define GRID_REDRAW_SCROLL_HORIZ	0x0002
592 #define GRID_REDRAW_EDIT		(GRID_REDRAW_SCROLL_VERT | \
593 					 GRID_REDRAW_SCROLL_HORIZ)
594 /*
595  * Un/Highlight indicators
596  */
597 #if XmVersion >= 1002
598 #define GRID_REDRAW_HIGHLIGHT		0x0100
599 #define HIGHLIGHTING_SOMETHING		0x0F
600 #define UNHIGHLIGHTING_SOMETHING	0xF0
601 #endif
602 
603 /*
604  * Grid shadow/line detectors
605  */
606 #define GRID_MODE_CELL		(XmGRID_CELL_LINE & XmGRID_CELL_SHADOW)
607 #define GRID_MODE_ROW		(XmGRID_ROW_LINE & XmGRID_ROW_SHADOW)
608 #define GRID_MODE_COLUMN	(XmGRID_COLUMN_LINE & XmGRID_COLUMN_SHADOW)
609 #define IN_GRID_CELL_MODE(mw)	(mw->matrix.grid_type & GRID_MODE_CELL)
610 #define IN_GRID_ROW_MODE(mw)	(mw->matrix.grid_type & GRID_MODE_ROW)
611 #define IN_GRID_COLUMN_MODE(mw)	(mw->matrix.grid_type & GRID_MODE_COLUMN)
612 
613 #endif /* _Xbae_Macros_h */
614