File: Macros.h

package info (click to toggle)
gridengine 8.1.9%2Bdfsg-10
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 56,880 kB
  • sloc: ansic: 432,689; java: 87,068; cpp: 31,958; sh: 29,429; jsp: 7,757; perl: 6,336; xml: 5,828; makefile: 4,701; csh: 3,928; ruby: 2,221; tcl: 1,676; lisp: 669; yacc: 519; python: 503; lex: 361; javascript: 200
file content (613 lines) | stat: -rw-r--r-- 27,584 bytes parent folder | download | duplicates (6)
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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
/*
 * Copyright(c) 1992 Bell Communications Research, Inc. (Bellcore)
 * Copyright(c) 1995-99 Andrew Lister
 *
 *                        All rights reserved
 * Permission to use, copy, modify and distribute this material for
 * any purpose and without fee is hereby granted, provided that the
 * above copyright notice and this permission notice appear in all
 * copies, and that the name of Bellcore not be used in advertising
 * or publicity pertaining to this material without the specific,
 * prior written permission of an authorized representative of
 * Bellcore.
 *
 * BELLCORE MAKES NO REPRESENTATIONS AND EXTENDS NO WARRANTIES, EX-
 * PRESS OR IMPLIED, WITH RESPECT TO THE SOFTWARE, INCLUDING, BUT
 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR ANY PARTICULAR PURPOSE, AND THE WARRANTY AGAINST IN-
 * FRINGEMENT OF PATENTS OR OTHER INTELLECTUAL PROPERTY RIGHTS.  THE
 * SOFTWARE IS PROVIDED "AS IS", AND IN NO EVENT SHALL BELLCORE OR
 * ANY OF ITS AFFILIATES BE LIABLE FOR ANY DAMAGES, INCLUDING ANY
 * LOST PROFITS OR OTHER INCIDENTAL OR CONSEQUENTIAL DAMAGES RELAT-
 * ING TO THE SOFTWARE.
 *
 * $Id: Macros.h,v 1.1 2001-07-18 11:05:59 root Exp $
 */

/*
 * Macros.h created by Andrew Lister (6 August, 1995)
 */

#ifndef _Xbae_Macros_h
#define _Xbae_Macros_h
/*
 * Prototype wrapper
 */
#ifndef P
#if defined(__STDC__) || defined (__cplusplus)
#define P(x)                x
#else
#define P(x)                ()
#define const
#define volatile
#endif
#endif

#if XmVersion <= 1001
#include <Xm/XmP.h>
#else
#include <Xm/DrawP.h>
#endif
#include <Xm/TextP.h>
#include <Xm/PrimitiveP.h>

#if XmVersion <= 1001
#define DRAW_SHADOW(dpy, draw, tgc, bgc, sz, x, y, w, h, type)        \
    _XmDrawShadow(dpy, draw, tgc, bgc, sz, x, y, w, h)
#else
#if XmVersion >= 2000
#define DRAW_SHADOW(dpy, draw, tgc, bgc, sz, x, y, w, h, type)        \
    XmeDrawShadows(dpy, draw, tgc, bgc, x, y, w, h, sz, type)
#else
#define DRAW_SHADOW(dpy, draw, tgc, bgc, sz, x, y, w, h, type)        \
    _XmDrawShadows(dpy, draw, tgc, bgc, x, y, w, h, sz, type)
#endif
#endif

#if XmVersion <= 1001
#define DRAW_HIGHLIGHT(dpy, draw, tgc, x, y, w, h, sz, type) \
        _XmDrawSimpleHighlight(dpy, draw, tgc, x, y, w, h, sz, type)
#else
#if XmVersion >= 2000
#define DRAW_HIGHLIGHT(dpy, draw, tgc, x, y, w, h, sz, type) \
        XmeDrawHighlight(dpy, draw, tgc, x, y, w, h, sz)
#else
#define DRAW_HIGHLIGHT(dpy, draw, tgc, x, y, w, h, sz, type) \
        _XmDrawHighlight(dpy, draw, tgc, x, y, w, h, sz, type)
#endif
#endif
/*
 * Macros to retrieve our children.  Children must be created in this order.
 */
#define XbaeNumChildren                8

#define HorizScrollChild(mw)        (mw->composite.children[0])
#define VertScrollChild(mw)        (mw->composite.children[1])
#define ClipChild(mw)                (mw->composite.children[2])
#define TextChild(mw)                (mw->composite.children[3])
#define LeftClip(mw)                (mw->composite.children[4])
#define RightClip(mw)                (mw->composite.children[5])
#define TopClip(mw)                (mw->composite.children[6])
#define BottomClip(mw)                (mw->composite.children[7])

#define VISIBLE_WIDTH(mw)        ((int)ClipChild(mw)->core.width)
#define VISIBLE_HEIGHT(mw)        ((int)ClipChild(mw)->core.height)

#define VERT_ORIGIN(mw)                (mw->matrix.top_row)
#define TRAILING_VERT_ORIGIN(mw) (mw->matrix.rows - \
                                  (int)mw->matrix.trailing_fixed_rows)
#define HORIZ_ORIGIN(mw)        (mw->matrix.horiz_origin)
#define TRAILING_HORIZ_ORIGIN(mw) (mw->matrix.columns - \
                                   (int)mw->matrix.trailing_fixed_columns)

/*
 * Macros
 */

/*
 * Max and Min are defined in Xm/XmP.h in 1.1, they are deprecated in 1.2
 */
#if XmVersion >= 1002
#define Max(x, y)       (((x) > (y)) ? (x) : (y))
#define Min(x, y)       (((x) < (y)) ? (x) : (y))
#endif

#define FONT_WIDTH(mw)                (mw->matrix.font_width)

#define LABEL_WIDTH(mw)                (mw->matrix.label_font_width)

#define TEXT_WIDTH_OFFSET(mw)        (mw->matrix.cell_margin_width +\
                                 mw->matrix.cell_shadow_thickness + \
                                 mw->matrix.cell_highlight_thickness + \
                                 mw->matrix.text_shadow_thickness)

#define TEXT_HEIGHT_OFFSET(mw)        (mw->matrix.cell_margin_height +\
                                 mw->matrix.cell_shadow_thickness + \
                                 mw->matrix.cell_highlight_thickness + \
                                 mw->matrix.text_shadow_thickness)

#define COLUMN_WIDTH(mw, col)        ((mw->matrix.column_widths[col] * \
                                  FONT_WIDTH(mw)) + \
                                 ((int)TEXT_WIDTH_OFFSET(mw) * 2))

#define FONT_HEIGHT(mw)                (mw->matrix.font_height)

#define LABEL_HEIGHT(mw)        (mw->matrix.label_font_height)

#define HORIZ_SB_WIDTH(mw)        (HorizScrollChild(mw)->core.width + \
                                 2 * HorizScrollChild(mw)->core.border_width)

#define HORIZ_SB_HEIGHT(mw)        (HorizScrollChild(mw)->core.height + \
                                 2 * HorizScrollChild(mw)->core.border_width +\
                                 mw->matrix.space)

#define HORIZ_SB_SPACE(mw)        (! HorizScrollChild(mw)->core.managed ? \
                                 0 : HORIZ_SB_HEIGHT(mw))

#define HORIZ_SB_OFFSET(mw)        (((mw->matrix.scrollbar_placement == \
                                   XmTOP_LEFT) || \
                                  (mw->matrix.scrollbar_placement == \
                                   XmTOP_RIGHT)) ? HORIZ_SB_SPACE(mw) : 0)

#define HORIZ_SB_POSITION(mw)        (((mw->matrix.scrollbar_placement == \
                                   XmTOP_LEFT) || \
                                  (mw->matrix.scrollbar_placement == \
                                   XmTOP_RIGHT)) ? 0 : \
                                 TRAILING_FIXED_ROW_LABEL_OFFSET(mw))

#define VERT_SB_WIDTH(mw)        (VertScrollChild(mw)->core.width + \
                                 2 * VertScrollChild(mw)->core.border_width + \
                                 mw->matrix.space)

#define VERT_SB_HEIGHT(mw)        (VertScrollChild(mw)->core.height + \
                                 2 * VertScrollChild(mw)->core.border_width)

#define VERT_SB_SPACE(mw)        (! VertScrollChild(mw)->core.managed ? \
                                 0 : VERT_SB_WIDTH(mw))

#define VERT_SB_OFFSET(mw)        (((mw->matrix.scrollbar_placement == \
                                   XmTOP_LEFT) || \
                                 (mw->matrix.scrollbar_placement == \
                                  XmBOTTOM_LEFT)) ? VERT_SB_SPACE(mw) : 0)

#define VERT_SB_POSITION(mw)        (((mw->matrix.scrollbar_placement == \
                                   XmTOP_LEFT) || \
                                  (mw->matrix.scrollbar_placement == \
                                   XmBOTTOM_LEFT)) ? 0 : \
                                 VertScrollChild(mw)->core.x - \
                                 mw->matrix.space)
                                  
#define CLIP_HORIZ_VISIBLE_SPACE(mw) ((int)(VISIBLE_WIDTH(mw) +\
                                      FIXED_COLUMN_WIDTH(mw) + \
                                      TRAILING_FIXED_COLUMN_WIDTH(mw)))

#define CLIP_VERT_VISIBLE_SPACE(mw) ((int)(mw->matrix.cell_visible_height +\
                                      FIXED_ROW_HEIGHT(mw) + \
                                      TRAILING_FIXED_ROW_HEIGHT(mw)))

#define MATRIX_HORIZ_VISIBLE_SPACE(mw) ((int)(mw->core.width - \
                                         mw->manager.shadow_thickness - \
                                         COLUMN_LABEL_OFFSET(mw) -\
                                         VERT_SB_SPACE(mw)))

#define MATRIX_VERT_VISIBLE_SPACE(mw) ((int)(mw->core.height -\
                                        mw->manager.shadow_thickness - \
                                        ROW_LABEL_OFFSET(mw) -\
                                        HORIZ_SB_SPACE(mw)))

#define NEED_HORIZ_FILL(mw)        (mw->matrix.fill && \
                                  (MATRIX_HORIZ_VISIBLE_SPACE(mw) > \
                                    CLIP_HORIZ_VISIBLE_SPACE(mw)))

#define NEED_VERT_FILL(mw)        (mw->matrix.fill && \
                                  (MATRIX_VERT_VISIBLE_SPACE(mw) > \
                                    CLIP_VERT_VISIBLE_SPACE(mw)))

#define        FILL_HORIZ_WIDTH(mw)        (mw->core.width - VISIBLE_WIDTH(mw) - \
                                  TRAILING_FIXED_COLUMN_WIDTH(mw) - \
                                  VERT_SB_SPACE(mw) - \
                                  FIXED_COLUMN_LABEL_OFFSET(mw) - \
                                  mw->manager.shadow_thickness)

#define        FILL_VERT_HEIGHT(mw)        (mw->core.height - VISIBLE_HEIGHT(mw) - \
                                  TRAILING_FIXED_ROW_HEIGHT(mw) - \
                                  FIXED_ROW_LABEL_OFFSET(mw) - \
                                  mw->manager.shadow_thickness)

#define SANITY_CHECK_ROW(mw, row) (row = (row >= mw->matrix.rows) ? \
                                      ((mw->matrix.rows > 0) ? \
                                        mw->matrix.rows - 1 : 0) : \
                                      (row < 0) ? 0 : row)

#define SANITY_CHECK_COLUMN(mw, column) (column = \
                                            (column >= mw->matrix.columns) ? \
                                            ((mw->matrix.columns > 0) ? \
                                             mw->matrix.columns - 1 : 0) : \
                                            (column < 0) ? 0 : column)

/*
 * The text height defines the row height.  It needs to be the biggest
 * we can expect from both font and label font
 */
#define TEXT_HEIGHT(mw)                (Max(FONT_HEIGHT(mw), LABEL_HEIGHT(mw)))

#define ROW_HEIGHT(mw)                (int)((TEXT_HEIGHT_OFFSET(mw) * 2) + \
                                      TEXT_HEIGHT(mw))

#define TEXT_X_OFFSET(mw)        (int)(TEXT_WIDTH_OFFSET(mw))

#define TEXT_Y_OFFSET(mw)        (int)(mw->matrix.text_baseline)

#define LABEL_Y_OFFSET(mw)        (int)(mw->matrix.label_baseline)

#define ROW_LABEL_WIDTH(mw)        ((mw->matrix.row_labels \
                                 ? (mw->matrix.row_label_width * \
                                    LABEL_WIDTH(mw)) + \
                                 (int)TEXT_WIDTH_OFFSET(mw) * 2 : 0) + \
                                 (mw->matrix.button_labels ? \
                                 mw->matrix.cell_shadow_thickness * 2 : 0))

#define COLUMN_LABEL_HEIGHT(mw) (mw->matrix.column_labels \
                                 ? (int)TEXT_HEIGHT_OFFSET(mw) * 2 + \
                                 mw->matrix.column_label_maxlines * \
                                 LABEL_HEIGHT(mw) : 0)

#define COLUMN_POSITION(mw, column) mw->matrix.column_positions[column]
 
#define FIXED_COLUMN_WIDTH(mw)        COLUMN_POSITION(mw, mw->matrix.fixed_columns)

#define TRAILING_FIXED_COLUMN_WIDTH(mw) \
                  (mw->matrix.trailing_fixed_columns ? \
                    (COLUMN_POSITION(mw, mw->matrix.columns-1) + \
                     COLUMN_WIDTH(mw, mw->matrix.columns-1) - \
                     COLUMN_POSITION(mw, TRAILING_HORIZ_ORIGIN(mw))) : 0)

#define COLUMN_LABEL_OFFSET(mw)        (ROW_LABEL_WIDTH(mw) + \
                                 VERT_SB_OFFSET(mw) + \
                                 (int)mw->manager.shadow_thickness)

#define FIXED_COLUMN_LABEL_OFFSET(mw) (COLUMN_LABEL_OFFSET(mw) + \
                                       FIXED_COLUMN_WIDTH(mw))

#define TRAILING_FIXED_COLUMN_LABEL_OFFSET(mw) (FIXED_COLUMN_LABEL_OFFSET(mw)+\
                                                VISIBLE_WIDTH(mw))

#define FIXED_ROW_HEIGHT(mw)        ((int)mw->matrix.fixed_rows * ROW_HEIGHT(mw))

#define TRAILING_FIXED_ROW_HEIGHT(mw) ((int)mw->matrix.trailing_fixed_rows * \
                                       ROW_HEIGHT(mw))

#define ROW_LABEL_OFFSET(mw)        (COLUMN_LABEL_HEIGHT(mw) + \
                                 HORIZ_SB_OFFSET(mw) + \
                                 mw->manager.shadow_thickness)

#define FIXED_ROW_LABEL_OFFSET(mw) (ROW_LABEL_OFFSET(mw) + \
                                    FIXED_ROW_HEIGHT(mw))

#define UNATTACHED_TRAILING_ROWS_OFFSET(mw) (FIXED_ROW_LABEL_OFFSET(mw) + \
                                             VISIBLE_HEIGHT(mw))

#define ATTACHED_TRAILING_ROWS_OFFSET(mw) (mw->core.height - \
                                           mw->manager.shadow_thickness - \
                                           HORIZ_SB_SPACE(mw) - \
                                           TRAILING_FIXED_ROW_HEIGHT(mw))

#define VERT_DEAD_SPACE_HEIGHT(mw)  ((int)(ATTACHED_TRAILING_ROWS_OFFSET(mw) - \
                                     UNATTACHED_TRAILING_ROWS_OFFSET(mw)))

#define HAS_ATTACHED_TRAILING_ROWS(mw)  (mw->matrix.fill &&  \
                                         mw->matrix.trailing_attached_bottom && \
                                         mw->matrix.trailing_fixed_rows) 

#define TRAILING_FIXED_ROW_LABEL_OFFSET(mw) (HAS_ATTACHED_TRAILING_ROWS(mw) ? \
                                             ATTACHED_TRAILING_ROWS_OFFSET(mw) : \
                                             UNATTACHED_TRAILING_ROWS_OFFSET(mw))

#define NEED_VERT_DEAD_SPACE_FILL(mw) (HAS_ATTACHED_TRAILING_ROWS(mw) && \
                                      (VERT_DEAD_SPACE_HEIGHT(mw) > 0))

#define NON_FIXED_TOTAL_WIDTH(mw)         mw->matrix.non_fixed_total_width

#define CELL_TOTAL_HEIGHT(mw)        ((mw->matrix.rows - \
                                  (int) mw->matrix.fixed_rows - \
                                  (int) mw->matrix.trailing_fixed_rows) \
                                 * ROW_HEIGHT(mw))

#define IS_LEADING_FIXED_COLUMN(mw, column) (column < (int)mw->matrix.fixed_columns)

#define IS_TRAILING_FIXED_COLUMN(mw, column) (column >= TRAILING_HORIZ_ORIGIN(mw))

#define IS_FIXED_COLUMN(mw, column) (IS_LEADING_FIXED_COLUMN(mw, column) || \
                                     IS_TRAILING_FIXED_COLUMN(mw, column))

#define IS_LEADING_FIXED_ROW(mw, row) (row < (int)mw->matrix.fixed_rows)

#define IS_TRAILING_FIXED_ROW(mw, row) (row >= TRAILING_VERT_ORIGIN(mw))

#define IS_FIXED_ROW(mw, row) (IS_LEADING_FIXED_ROW(mw, row) || \
                               IS_TRAILING_FIXED_ROW(mw, row))

#define IS_FIXED(mw, row, column) (IS_FIXED_ROW(mw, row) || \
                                   IS_FIXED_COLUMN(mw, column))

#define IS_CLIPPED(mw, row, column) ((row >= (int)mw->matrix.fixed_rows) && \
                                       (column >= \
                                        (int)mw->matrix.fixed_columns) && \
                                       (row < TRAILING_VERT_ORIGIN(mw)) && \
                                       (column < TRAILING_HORIZ_ORIGIN(mw)))

/*
 * I hereby dub thee, Jay Schmidgall, as Sir Silly Macro - writer of
 * the most obsfucated macros I've ever seen - AL (26 Feb 1998)
 *
 * How do you come up with these???  The first couple are OK but
 * the last two???
 */

/* Here are some handy dandy macros to make it look cleaner in the
 * actual code. I did the vertical scrollbar stuff first, then the
 * horizontal. For the horizontal, I just referenced the other
 * orientation, and it worked. */
    
/* If we have fixed rows, the y position of the vsb must
 * be offset starting from the fixed rows. Otherwise, we
 * want it to be even with the matrix area top.  Perhaps
 * oddly, we can use this macro for both XtConfigure's. */

#define VSB_Y_POSITION(mw) (mw->matrix.fixed_rows ? \
                            FIXED_ROW_LABEL_OFFSET(mw) - \
                            HORIZ_SB_OFFSET(mw) + \
                            ((scrollbar_top && has_horiz) ? \
                             HORIZ_SB_HEIGHT(mw) : 0) : \
                            COLUMN_LABEL_HEIGHT(mw) + \
                            HORIZ_SB_OFFSET(mw))
        
#define HSB_X_POSITION(mw) (mw->matrix.fixed_columns ? \
                            FIXED_COLUMN_LABEL_OFFSET(mw) - \
                            VERT_SB_OFFSET(mw) + \
                            ((scrollbar_left && has_vert) ? \
                             VERT_SB_WIDTH(mw) : 0) : \
                            ROW_LABEL_WIDTH(mw) + VERT_SB_OFFSET(mw))
        
/* I started trying to write a comment that sort of explains this macro.
 * Then I quit. What the heck, it works. Feel free on your own to make
 * up something that reassures you. I myself have the feeling that there
 * has got to be a cleaner, better way to do this, sort of like the above
 * two seem somehow fairly clean. But this? This is some serious gaaack.
 * Same thing as above. Did VSB first, then just switched orientation
 * for HSB.
 */
#define VSB_HEIGHT(mw) ((!mw->matrix.fill) ? cell_height + \
                        mw->manager.shadow_thickness * \
                        (mw->matrix.fixed_rows || \
                         mw->matrix.trailing_fixed_rows ? \
                         (mw->matrix.fixed_rows && \
                          mw->matrix.trailing_fixed_rows ? 0 : 1) : 2) : \
                        ((TRAILING_FIXED_ROW_HEIGHT(mw) > 0) ? full_height - \
                         (mw->matrix.fixed_rows ? \
                          mw->manager.shadow_thickness : 0) - \
                         ROW_LABEL_OFFSET(mw) - FIXED_ROW_HEIGHT(mw) - \
                         TRAILING_FIXED_ROW_HEIGHT(mw) + \
                         HORIZ_SB_OFFSET(mw) : mw->core.height + \
                         (mw->matrix.fixed_rows ? 0 : \
                          mw->manager.shadow_thickness) - \
                         ROW_LABEL_OFFSET(mw) - FIXED_ROW_HEIGHT(mw) + \
                         HORIZ_SB_OFFSET(mw) - \
                         (has_horiz ? HORIZ_SB_HEIGHT(mw) : 0)))

#define HSB_WIDTH(mw) ((!mw->matrix.fill) ? cell_width + \
                       mw->manager.shadow_thickness * \
                       (mw->matrix.fixed_columns || \
                        mw->matrix.trailing_fixed_columns ? \
                        (mw->matrix.fixed_columns && \
                         mw->matrix.trailing_fixed_columns ? 0 : 1) : 2) : \
                        ((TRAILING_FIXED_COLUMN_WIDTH(mw) > 0) ? \
                         full_width - (mw->matrix.fixed_columns ? \
                                       mw->manager.shadow_thickness : 0) - \
                         COLUMN_LABEL_OFFSET(mw) - FIXED_COLUMN_WIDTH(mw) - \
                         TRAILING_FIXED_COLUMN_WIDTH(mw) + \
                         VERT_SB_OFFSET(mw) : \
                         mw->core.width + (mw->matrix.fixed_columns ? 0 :\
                                           mw->manager.shadow_thickness) - \
                         COLUMN_LABEL_OFFSET(mw) - FIXED_COLUMN_WIDTH(mw) + \
                         VERT_SB_OFFSET(mw) - \
                         (has_vert ? VERT_SB_WIDTH(mw) : 0)))

#define CELL_WINDOW(mw, row, column) \
        (IS_FIXED(mw, row, column) ? XtWindow(mw) : XtWindow(ClipChild(mw)))

/* Inline functions */
#define xbaeFreeColumnWidths(mw)        { \
                                               if (mw->matrix.column_widths) \
                                               XtFree((XtPointer) \
                                               mw->matrix.column_widths); \
                                        }

#define xbaeFreeColumnMaxLengths(mw)        { \
                                               if (mw->matrix.\
                                               column_max_lengths) \
                                               XtFree((XtPointer) \
                                               mw->matrix. \
                                               column_max_lengths); \
                                        }

#define xbaeFreeColumnPositions(mw)                { \
                                               if (mw->matrix. \
                                               column_positions) \
                                               XtFree((XtPointer) \
                                               mw->matrix. \
                                               column_positions); \
                                        }

#define xbaeFreeColumnAlignments(mw)        { \
                                               if (mw->matrix. \
                                               column_alignments) \
                                               XtFree((XtPointer) \
                                               mw->matrix. \
                                               column_alignments); \
                                        }

#define xbaeFreeColumnButtonLabels(mw)        { \
                                               if (mw->matrix. \
                                               column_button_labels) \
                                               XtFree((XtPointer) \
                                               mw->matrix. \
                                               column_button_labels); \
                                        }

#define xbaeFreeRowButtonLabels(mw)        { \
                                               if (mw->matrix. \
                                               row_button_labels) \
                                               XtFree((XtPointer) \
                                               mw->matrix. \
                                               row_button_labels); \
                                        }

#define xbaeFreeColumnLabelAlignments(mw)        { \
                                               if (mw->matrix. \
                                               column_label_alignments) \
                                               XtFree((XtPointer) \
                                               mw->matrix. \
                                               column_label_alignments); \
                                        }

#define xbaeFreeRowUserData(mw)                { \
                                               if (mw->matrix.\
                                               row_user_data) \
                                               XtFree((XtPointer) \
                                               mw->matrix.\
                                               row_user_data); \
                                        }

#define xbaeFreeColumnUserData(mw)        { \
                                               if (mw->matrix.\
                                               column_user_data) \
                                               XtFree((XtPointer) \
                                               mw->matrix.\
                                               column_user_data); \
                                        }

#define xbaeFreeRowShadowTypes(mw)        { \
                                               if (mw->matrix.\
                                               row_shadow_types) \
                                               XtFree((XtPointer) \
                                               mw->matrix.\
                                               row_shadow_types); \
                                        }

#define xbaeFreeColumnShadowTypes(mw)        { \
                                               if (mw->matrix.\
                                               column_shadow_types) \
                                               XtFree((XtPointer) \
                                               mw->matrix.\
                                               column_shadow_types); \
                                        }

#define CreateColumnPositions(mw)  (int *)XtMalloc((mw->matrix.columns+1)* \
                                                   sizeof(int))
#define YtoRow(mw, y)                        ((y) / ROW_HEIGHT(mw))


/*
 * Evaluates to 1 if two Rectangles overlap, 0 if no overlap
 */
#define OVERLAP(r1, r2) ((r1).x2 >= (r2).x1 && \
                         (r1).x1 <= (r2).x2 && \
                         (r1).y2 >= (r2).y1 && \
                         (r1).y1 <= (r2).y2)

/*
 * Intersect rectangles r1 and r2, place the result in res.
 * Result will be in r1's coord system.
 */
#define X_INTERSECT(r1, r2, res) { (res).x1 = Max((r1).x1, (r2).x1) - (r1).x1;\
    (res).x2 = Min((r1).x2, (r2).x2) - (r1).x1;}

#define Y_INTERSECT(r1, r2, res) { (res).y1 = Max((r1).y1, (r2).y1) - (r1).y1;\
    (res).y2 = Min((r1).y2, (r2).y2) - (r1).y1;}

#define INTERSECT(r1, r2, res)        { X_INTERSECT(r1, r2, res); \
    Y_INTERSECT(r1, r2, res); }

/*
 * Evaluates to 1 if the point is in the Rectangle, 0 if not
 */
#define INBOX(r, x, y)                ((((r).x2 >= x)) && \
                                  (((r).x1 <= x)) && \
                                  (((r).y2 >= y)) && \
                                  (((r).y1 <= y)))

/*
 * Macros used for Rectangle calculations.  A Rectangle is defined by it's
 * upper left and lower right corners.
 */

/*
 * Set a Rectangle. (x1,y1) is upper left corner, (x2,y2) is lower right corner
 */
#define SETRECT(r, X1, Y1, X2, Y2) { (r).x1 = X1; (r).y1 = Y1; \
    (r).x2 = X2; (r).y2 = Y2; }

#ifdef NEED_WCHAR
#define TWO_BYTE_FONT(mw)        (mw->matrix.font->max_byte1 != 0)
#endif

#ifdef NEED_24BIT_VISUAL
#define GC_PARENT_WINDOW(w)        XtWindow(get_shell_ancestor((Widget)w))
#else
#define GC_PARENT_WINDOW(w)        RootWindowOfScreen(XtScreen(w))
#endif

/*
 * End of array flags for the array type converters
 */
#define BAD_WIDTH        -1
#define BAD_MAXLENGTH        0
#define BAD_ALIGNMENT        3        /* see Xm.h */
#define BAD_PIXEL        0x10000000 /* normally 256 indices */ 


/*
 * SetClipMask flags for indicating clip areas
 */
#define CLIP_NONE                        0x0000
#define CLIP_FIXED_COLUMNS                0x0001
#define CLIP_FIXED_ROWS                        0x0002
#define CLIP_TRAILING_FIXED_COLUMNS        0x0004
#define CLIP_TRAILING_FIXED_ROWS        0x0008
#define CLIP_BETWEEN_FIXED_ROWS                0x0010
#define CLIP_VISIBLE_HEIGHT                0x0020
#define CLIP_TRAILING_HORIZ_FILL        0x0040
#define CLIP_TRAILING_VERT_FILL                0x0080
#define CLIP_COLUMN_LABELS                     0x0100
#define CLIP_ROW_LABELS                     0x0200
#define CLIP_ALL                             0x0400

/*
 * Row and Column grid shadow/line redraw reasons
 */
#define GRID_REDRAW_EXPOSE                0x0000
#define GRID_REDRAW_SCROLL_VERT                0x0001
#define GRID_REDRAW_SCROLL_HORIZ        0x0002
#define GRID_REDRAW_EDIT                (GRID_REDRAW_SCROLL_VERT | \
                                         GRID_REDRAW_SCROLL_HORIZ)
/*
 * Un/Highlight indicators
 */
#if XmVersion >= 1002
#define GRID_REDRAW_HIGHLIGHT                0x0100
#define HIGHLIGHTING_SOMETHING                0x0F
#define UNHIGHLIGHTING_SOMETHING        0xF0
#endif

/*
 * Grid shadow/line detectors
 */
#define GRID_MODE_CELL                (XmGRID_CELL_LINE & XmGRID_CELL_SHADOW)
#define GRID_MODE_ROW                (XmGRID_ROW_LINE & XmGRID_ROW_SHADOW)
#define GRID_MODE_COLUMN        (XmGRID_COLUMN_LINE & XmGRID_COLUMN_SHADOW)
#define IN_GRID_CELL_MODE(mw)        (mw->matrix.grid_type & GRID_MODE_CELL)
#define IN_GRID_ROW_MODE(mw)        (mw->matrix.grid_type & GRID_MODE_ROW)
#define IN_GRID_COLUMN_MODE(mw)        (mw->matrix.grid_type & GRID_MODE_COLUMN)

#endif /* _Xbae_Macros_h */