1 /* 2 * Copyright (c) 1992 Bell Communications Research, Inc. (Bellcore) 3 * Copyright (c) 1995-99 Andrew Lister 4 * Copyright � 1999, 2000, 2001, 2002, 2003, 2004 by the LessTif Developers. 5 * 6 * All rights reserved 7 * Permission to use, copy, modify and distribute this material for 8 * any purpose and without fee is hereby granted, provided that the 9 * above copyright notice and this permission notice appear in all 10 * copies, and that the name of Bellcore not be used in advertising 11 * or publicity pertaining to this material without the specific, 12 * prior written permission of an authorized representative of 13 * Bellcore. 14 * 15 * BELLCORE MAKES NO REPRESENTATIONS AND EXTENDS NO WARRANTIES, EX- 16 * PRESS OR IMPLIED, WITH RESPECT TO THE SOFTWARE, INCLUDING, BUT 17 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 18 * FITNESS FOR ANY PARTICULAR PURPOSE, AND THE WARRANTY AGAINST IN- 19 * FRINGEMENT OF PATENTS OR OTHER INTELLECTUAL PROPERTY RIGHTS. THE 20 * SOFTWARE IS PROVIDED "AS IS", AND IN NO EVENT SHALL BELLCORE OR 21 * ANY OF ITS AFFILIATES BE LIABLE FOR ANY DAMAGES, INCLUDING ANY 22 * LOST PROFITS OR OTHER INCIDENTAL OR CONSEQUENTIAL DAMAGES RELAT- 23 * ING TO THE SOFTWARE. 24 * 25 * $Id: Macros.h,v 1.74 2006/05/16 19:59:53 tobiasoed Exp $ 26 */ 27 28 /* 29 * Macros.h created by Andrew Lister (6 August, 1995) 30 */ 31 32 #ifndef _Xbae_Macros_h 33 #define _Xbae_Macros_h 34 35 #include <Xm/DrawP.h> 36 #include <Xm/TextP.h> 37 #include <Xm/PrimitiveP.h> 38 39 40 #ifdef __cplusplus 41 extern "C" { 42 #endif 43 44 /* 45 * The third parameter is a string added for debugging purposes. 46 */ 47 #if (XmVersion >= 2000) 48 #define DRAW_SHADOW(dpy, draw, dbg, tgc, bgc, sz, x, y, w, h, type) \ 49 do { \ 50 DEBUGOUT(_XbaeDebug(__FILE__, NULL, \ 51 "XmeDrawShadows(%s) [%d,%d,%d,%d - %d %s]\n", \ 52 dbg, x, y, w, h, sz, _XbaeDebugShadowTypeToString(type))); \ 53 XmeDrawShadows(dpy, draw, tgc, bgc, x, y, w, h, sz, type); \ 54 } while(0) 55 #else 56 #define DRAW_SHADOW(dpy, draw, dbg, tgc, bgc, sz, x, y, w, h, type) \ 57 do { \ 58 DEBUGOUT(_XbaeDebug(__FILE__, NULL, \ 59 "_XmDrawShadows(%s) [%d,%d,%d,%d - %d %s]\n", \ 60 dbg, x, y, w, h, sz, _XbaeDebugShadowTypeToString(type))); \ 61 _XmDrawShadows(dpy, draw, tgc, bgc, x, y, w, h, sz, type); \ 62 } while(0) 63 #endif 64 65 #if XmVersion >= 2000 66 #define DRAW_HIGHLIGHT(dpy, draw, gc, x, y, w, h, sz, type) \ 67 XmeDrawHighlight(dpy, draw, gc, x, y, w, h, sz) 68 #else 69 #define DRAW_HIGHLIGHT(dpy, draw, gc, x, y, w, h, sz, type) \ 70 _XmDrawHighlight(dpy, draw, gc, x, y, w, h, sz, type) 71 #endif 72 /* 73 * Macros to retrieve our children. 74 */ 75 #define HorizScrollChild(mw) ((mw)->matrix.horizontal_sb) 76 #define VertScrollChild(mw) ((mw)->matrix.vertical_sb) 77 #define TextField(mw) ((mw)->matrix.text_field) 78 79 #define CenterClip(mw) ((mw)->matrix.center_clip) 80 #define LeftClip(mw) ((mw)->matrix.left_clip) 81 #define RightClip(mw) ((mw)->matrix.right_clip) 82 #define TopClip(mw) ((mw)->matrix.top_clip) 83 #define BottomClip(mw) ((mw)->matrix.bottom_clip) 84 #define RowLabelClip(mw) ((mw)->matrix.row_label_clip) 85 #define ColumnLabelClip(mw) ((mw)->matrix.column_label_clip) 86 87 #define VISIBLE_NON_FIXED_WIDTH(mw) ((mw)->matrix.visible_non_fixed_width) 88 #define VISIBLE_NON_FIXED_HEIGHT(mw) ((mw)->matrix.visible_non_fixed_height) 89 90 #define VISIBLE_FIXED_COLUMN_WIDTH(mw) ((mw)->matrix.visible_fixed_column_width) 91 #define VISIBLE_FIXED_ROW_HEIGHT(mw) ((mw)->matrix.visible_fixed_row_height) 92 93 #define VISIBLE_TRAILING_FIXED_COLUMN_WIDTH(mw) ((mw)->matrix.visible_trailing_fixed_column_width) 94 #define VISIBLE_TRAILING_FIXED_ROW_HEIGHT(mw) ((mw)->matrix.visible_trailing_fixed_row_height) 95 96 /* 97 * SGO: changed the meaning of VERT_ORIGIN: 98 * now it contains the pixel position of the first row, same as 99 * HORIZ_ORIGIN, the top_row should now be accessed by TOP_ROW 100 * Tobias: I killed the top_row/left_column resource use 101 * xbaeTopRow/xbaeLeftColumn instaead 102 */ 103 #define VERT_ORIGIN(mw) ((mw)->matrix.vert_origin) 104 #define HORIZ_ORIGIN(mw) ((mw)->matrix.horiz_origin) 105 #define TRAILING_ROW_ORIGIN(mw) ((mw)->matrix.rows - (mw)->matrix.trailing_fixed_rows) 106 #define TRAILING_COLUMN_ORIGIN(mw) ((mw)->matrix.columns - (mw)->matrix.trailing_fixed_columns) 107 108 /* 109 * Macros 110 */ 111 112 #ifndef Max 113 #define Max(x, y) (((x) > (y)) ? (x) : (y)) 114 #endif 115 #ifndef Min 116 #define Min(x, y) (((x) < (y)) ? (x) : (y)) 117 #endif 118 119 #define CELL_BORDER_WIDTH(mw) ( \ 120 (mw)->matrix.cell_shadow_thickness + \ 121 (mw)->matrix.cell_highlight_thickness + \ 122 (mw)->matrix.text_shadow_thickness + \ 123 (mw)->matrix.cell_margin_width) 124 125 #define CELL_BORDER_HEIGHT(mw) ( \ 126 (mw)->matrix.cell_shadow_thickness + \ 127 (mw)->matrix.cell_highlight_thickness + \ 128 (mw)->matrix.text_shadow_thickness + \ 129 (mw)->matrix.cell_margin_height) 130 131 #define CELL_FONT_WIDTH(mw) ((mw)->matrix.cell_font.width) 132 #define CELL_FONT_HEIGHT(mw) ((mw)->matrix.cell_font.height) 133 #define CELL_BASELINE(mw) ((mw)->matrix.cell_baseline) 134 135 #define LABEL_FONT_WIDTH(mw) ((mw)->matrix.label_font.width) 136 #define LABEL_FONT_HEIGHT(mw) ((mw)->matrix.label_font.height) 137 #define ROW_LABEL_BASELINE(mw) ((mw)->matrix.row_label_baseline) 138 #define COLUMN_LABEL_BASELINE(mw) (- (mw)->matrix.label_font.y) 139 140 /* 141 * The text height defines the row height. It needs to be the biggest 142 * we can expect from both font and label font 143 */ 144 #define TEXT_HEIGHT(mw) (Max(CELL_FONT_HEIGHT(mw), LABEL_FONT_HEIGHT(mw))) 145 146 147 #define ROW_LABEL_WIDTH(mw) ( \ 148 ((mw)->matrix.row_labels || (mw)->matrix.xmrow_labels) \ 149 ? ((mw)->matrix.row_label_width) \ 150 ? 2 * CELL_BORDER_WIDTH(mw) + (mw)->matrix.row_label_width * LABEL_FONT_WIDTH(mw) \ 151 : 2 * CELL_BORDER_WIDTH(mw) + (mw)->matrix.row_label_maxlength * LABEL_FONT_WIDTH(mw) \ 152 : 0) 153 154 #define COLUMN_LABEL_HEIGHT(mw) ( \ 155 ((mw)->matrix.column_labels || (mw)->matrix.xmcolumn_labels) \ 156 ? 2 * CELL_BORDER_HEIGHT(mw) + (mw)->matrix.column_label_maxlines * LABEL_FONT_HEIGHT(mw) \ 157 : 0) 158 159 #define DEFAULT_ROW_HEIGHT(mw) ( \ 160 ((mw)->matrix.row_height_in_pixels) \ 161 ? (1 * TEXT_HEIGHT(mw) + 2 * CELL_BORDER_HEIGHT(mw)) \ 162 : 1) 163 164 #define DEFAULT_COLUMN_WIDTH(mw) ( \ 165 ((mw)->matrix.column_width_in_pixels) \ 166 ? (5 * CELL_FONT_WIDTH(mw) + 2 * CELL_BORDER_WIDTH(mw)) \ 167 : 5) 168 169 170 171 #define SCROLLBAR_TOP(mw) ( \ 172 (mw)->matrix.scrollbar_placement == XmTOP_LEFT || \ 173 (mw)->matrix.scrollbar_placement == XmTOP_RIGHT \ 174 ) 175 176 #define HORIZ_SB_WIDTH(mw) (HorizScrollChild(mw)->core.width + \ 177 2 * HorizScrollChild(mw)->core.border_width) 178 179 #define HORIZ_SB_HEIGHT(mw) (HorizScrollChild(mw)->core.height + \ 180 2 * HorizScrollChild(mw)->core.border_width +\ 181 (mw)->matrix.space) 182 183 #define HORIZ_SB_SPACE(mw) (! HorizScrollChild(mw)->core.managed ? 0 : HORIZ_SB_HEIGHT(mw)) 184 185 #define HORIZ_SB_OFFSET(mw) ((SCROLLBAR_TOP(mw)) ? HORIZ_SB_SPACE(mw) : 0) 186 187 188 #define SCROLLBAR_LEFT(mw) ( \ 189 (mw)->matrix.scrollbar_placement == XmTOP_LEFT || \ 190 (mw)->matrix.scrollbar_placement == XmBOTTOM_LEFT \ 191 ) 192 193 #define VERT_SB_WIDTH(mw) (VertScrollChild(mw)->core.width + \ 194 2 * VertScrollChild(mw)->core.border_width + \ 195 (mw)->matrix.space) 196 197 #define VERT_SB_HEIGHT(mw) (VertScrollChild(mw)->core.height + \ 198 2 * VertScrollChild(mw)->core.border_width) 199 200 #define VERT_SB_SPACE(mw) (! VertScrollChild(mw)->core.managed ? 0 : VERT_SB_WIDTH(mw)) 201 202 #define VERT_SB_OFFSET(mw) ((SCROLLBAR_LEFT(mw)) ? VERT_SB_SPACE(mw) : 0) 203 204 205 206 #if 1 /* Whether or not to check each column_position access for debugging */ 207 #define COLUMN_POSITION(mw, column) (mw)->matrix.column_positions[column] 208 #define ROW_POSITION(mw, row) (mw)->matrix.row_positions[row] 209 #else 210 #define COLUMN_POSITION(mw, column) xbaeCheckColumnPosition(mw, column) 211 #define ROW_POSITION(mw, row) xbaeCheckRowPosition(mw, row) 212 #endif 213 214 #define TOTAL_HEIGHT(mw) ROW_POSITION(mw, (mw)->matrix.rows) 215 #define TOTAL_WIDTH(mw) COLUMN_POSITION(mw, (mw)->matrix.columns) 216 217 #define FIXED_COLUMN_WIDTH(mw) COLUMN_POSITION(mw, (mw)->matrix.fixed_columns) 218 #define FIXED_ROW_HEIGHT(mw) ROW_POSITION(mw, (mw)->matrix.fixed_rows) 219 220 #define ROW_HEIGHT(mw, row) \ 221 (ROW_POSITION(mw, row + 1) - ROW_POSITION(mw, row)) 222 #define COLUMN_WIDTH(mw, column) \ 223 (COLUMN_POSITION(mw, column + 1) - COLUMN_POSITION(mw, column)) 224 225 #define TRAILING_FIXED_ROW_HEIGHT(mw) \ 226 (ROW_POSITION(mw, (mw)->matrix.rows) - ROW_POSITION(mw, TRAILING_ROW_ORIGIN(mw))) 227 #define TRAILING_FIXED_COLUMN_WIDTH(mw) \ 228 (COLUMN_POSITION(mw, (mw)->matrix.columns) - COLUMN_POSITION(mw, TRAILING_COLUMN_ORIGIN(mw))) 229 230 #define NON_FIXED_HEIGHT(mw) \ 231 (ROW_POSITION(mw, TRAILING_ROW_ORIGIN(mw)) - ROW_POSITION(mw, (mw)->matrix.fixed_rows)) 232 #define NON_FIXED_WIDTH(mw) \ 233 (COLUMN_POSITION(mw, TRAILING_COLUMN_ORIGIN(mw)) - COLUMN_POSITION(mw, (mw)->matrix.fixed_columns)) 234 235 #define FIXED_COLUMN_POSITION(mw) (ROW_LABEL_WIDTH(mw) + \ 236 VERT_SB_OFFSET(mw) + (mw)->manager.shadow_thickness) 237 #define FIXED_ROW_POSITION(mw) (COLUMN_LABEL_HEIGHT(mw) + \ 238 HORIZ_SB_OFFSET(mw) + (mw)->manager.shadow_thickness) 239 240 #define NON_FIXED_COLUMN_POSITION(mw) \ 241 (FIXED_COLUMN_POSITION(mw) + VISIBLE_FIXED_COLUMN_WIDTH(mw)) 242 #define NON_FIXED_ROW_POSITION(mw) \ 243 (FIXED_ROW_POSITION(mw) + VISIBLE_FIXED_ROW_HEIGHT(mw)) 244 245 #define TRAILING_FIXED_COLUMN_POSITION(mw) \ 246 (NON_FIXED_COLUMN_POSITION(mw) + VISIBLE_NON_FIXED_WIDTH(mw)) 247 #define TRAILING_FIXED_ROW_POSITION(mw) \ 248 (NON_FIXED_ROW_POSITION(mw) + VISIBLE_NON_FIXED_HEIGHT(mw)) 249 250 #define MATRIX_VISIBLE_WIDTH(mw) ((int)((mw)->core.width - \ 251 2 * (mw)->manager.shadow_thickness - \ 252 ROW_LABEL_WIDTH(mw) - \ 253 VERT_SB_SPACE(mw))) 254 #define MATRIX_VISIBLE_HEIGHT(mw) ((int)((mw)->core.height -\ 255 2 * (mw)->manager.shadow_thickness - \ 256 COLUMN_LABEL_HEIGHT(mw) -\ 257 HORIZ_SB_SPACE(mw))) 258 259 #define EMPTY_HEIGHT(mw) ( \ 260 MATRIX_VISIBLE_HEIGHT(mw) > TOTAL_HEIGHT(mw) \ 261 ? MATRIX_VISIBLE_HEIGHT(mw) - TOTAL_HEIGHT(mw) \ 262 : 0) 263 #define EMPTY_WIDTH(mw) ( \ 264 MATRIX_VISIBLE_WIDTH(mw) > TOTAL_WIDTH(mw) \ 265 ? MATRIX_VISIBLE_WIDTH(mw) - TOTAL_WIDTH(mw) \ 266 : 0) 267 268 #define FILL_ROW(mw) ( \ 269 ((mw)->matrix.non_fixed_detached_top && (mw)->matrix.fixed_rows) \ 270 ? ((mw)->matrix.fixed_rows - 1) \ 271 : ((mw)->matrix.trailing_attached_bottom && (mw)->matrix.trailing_fixed_rows) \ 272 ? (TRAILING_ROW_ORIGIN(mw) - 1) \ 273 : ((mw)->matrix.rows - 1)) 274 275 #define FILL_COLUMN(mw) ( \ 276 ((mw)->matrix.non_fixed_detached_left && (mw)->matrix.fixed_columns) \ 277 ? ((mw)->matrix.fixed_columns - 1) \ 278 : ((mw)->matrix.trailing_attached_right && (mw)->matrix.trailing_fixed_columns) \ 279 ? (TRAILING_COLUMN_ORIGIN(mw) - 1) \ 280 : ((mw)->matrix.columns - 1)) 281 282 #define IS_FILL_ROW(mw, row) ((mw)->matrix.fill && row == FILL_ROW(mw)) 283 #define IS_FILL_COLUMN(mw, column) ((mw)->matrix.fill && column == FILL_COLUMN(mw)) 284 285 286 287 288 #define IS_LEADING_FIXED_COLUMN(mw, column) (column < (mw)->matrix.fixed_columns) 289 290 #define IS_TRAILING_FIXED_COLUMN(mw, column) (column >= TRAILING_COLUMN_ORIGIN(mw)) 291 292 #define IS_FIXED_COLUMN(mw, column) (IS_LEADING_FIXED_COLUMN(mw, column) || \ 293 IS_TRAILING_FIXED_COLUMN(mw, column)) 294 295 #define IS_NON_FIXED_COLUMN(mw, column) (column >= (mw)->matrix.fixed_columns && \ 296 column < TRAILING_COLUMN_ORIGIN(mw)) 297 298 299 #define IS_LEADING_FIXED_ROW(mw, row) (row < (mw)->matrix.fixed_rows) 300 301 #define IS_TRAILING_FIXED_ROW(mw, row) (row >= TRAILING_ROW_ORIGIN(mw)) 302 303 #define IS_FIXED_ROW(mw, row) (IS_LEADING_FIXED_ROW(mw, row) || \ 304 IS_TRAILING_FIXED_ROW(mw, row)) 305 306 #define IS_NON_FIXED_ROW(mw, row) (row >= (mw)->matrix.fixed_rows && \ 307 row < TRAILING_ROW_ORIGIN(mw)) 308 309 310 #define IS_FIXED(mw, row, column) (IS_FIXED_ROW(mw, row) || \ 311 IS_FIXED_COLUMN(mw, column)) 312 313 314 /* Inline functions */ 315 316 #define xbaeFreeArray(array) \ 317 do{ \ 318 if(array) { \ 319 XtFree((XtPointer) array); \ 320 array = NULL; \ 321 } \ 322 } while(0) 323 324 #define xbaeFreeColumnWidths(mw) \ 325 xbaeFreeArray((mw)->matrix.column_widths) 326 327 #define xbaeFreeRowHeights(mw) \ 328 xbaeFreeArray((mw)->matrix.row_heights) 329 330 #define xbaeFreeColumnMaxLengths(mw) \ 331 xbaeFreeArray((mw)->matrix.column_max_lengths) 332 333 #define xbaeFreeColumnPositions(mw) \ 334 xbaeFreeArray((mw)->matrix.column_positions) 335 336 #define xbaeFreeRowPositions(mw) \ 337 xbaeFreeArray((mw)->matrix.row_positions) 338 339 #define xbaeFreeColumnAlignments(mw) \ 340 xbaeFreeArray((mw)->matrix.column_alignments) 341 342 #define xbaeFreeColumnButtonLabels(mw) \ 343 xbaeFreeArray((mw)->matrix.column_button_labels) 344 345 #define xbaeFreeShowColumnArrows(mw) \ 346 xbaeFreeArray((mw)->matrix.show_column_arrows) 347 348 #define xbaeFreeColumnFontBold(mw) \ 349 xbaeFreeArray((mw)->matrix.column_font_bold) 350 351 #define xbaeFreeRowButtonLabels(mw) \ 352 xbaeFreeArray((mw)->matrix.row_button_labels) 353 354 #define xbaeFreeColumnLabelAlignments(mw) \ 355 xbaeFreeArray((mw)->matrix.column_label_alignments) 356 357 #define xbaeFreeRowUserData(mw) \ 358 xbaeFreeArray((mw)->matrix.row_user_data) 359 360 #define xbaeFreeColumnUserData(mw) \ 361 xbaeFreeArray((mw)->matrix.column_user_data) 362 363 #define xbaeFreeRowShadowTypes(mw) \ 364 xbaeFreeArray((mw)->matrix.row_shadow_types) 365 366 #define xbaeFreeColumnShadowTypes(mw) \ 367 xbaeFreeArray((mw)->matrix.column_shadow_types) 368 369 #define CreateRowPositions(mw) \ 370 (int *)XtMalloc(((mw)->matrix.rows+1) * sizeof(int)) 371 #define CreateColumnPositions(mw) \ 372 (int *)XtMalloc(((mw)->matrix.columns+1) * sizeof(int)) 373 374 375 #ifdef NEED_WCHAR 376 #define TWO_BYTE_FONT(mw) ((mw)->matrix.font->max_byte1 != 0) 377 #endif 378 379 #define GC_PARENT_WINDOW(w) XtWindow(_XbaeGetShellAncestor((Widget)w)) 380 381 /* 382 * End of array flags for the array type converters 383 */ 384 #define BAD_SIZE -1 385 #define BAD_MAXLENGTH -1 386 #define BAD_SHADOW ((unsigned char) -1U) /* see Xm.h */ 387 #define BAD_ALIGNMENT 3 /* see Xm.h */ 388 #define BAD_PIXEL 0x10000000 /* normally 256 indices */ 389 390 /* 391 * SetClipMask flags for indicating clip areas 392 */ 393 #define CLIP_FIXED_COLUMNS 0x0001 394 #define CLIP_FIXED_ROWS 0x0002 395 #define CLIP_TRAILING_FIXED_COLUMNS 0x0004 396 #define CLIP_TRAILING_FIXED_ROWS 0x0008 397 #define CLIP_VISIBLE_WIDTH 0x0010 398 #define CLIP_VISIBLE_HEIGHT 0x0020 399 #define CLIP_TRAILING_HORIZ_FILL 0x0040 400 #define CLIP_TRAILING_VERT_FILL 0x0080 401 #define CLIP_COLUMN_LABELS 0x0100 402 #define CLIP_ROW_LABELS 0x0200 403 404 /* 405 * Grid shadow/line detectors 406 */ 407 #define GRID_MODE_ROW (XmGRID_ROW_LINE & XmGRID_ROW_SHADOW) 408 #define GRID_MODE_COLUMN (XmGRID_COLUMN_LINE & XmGRID_COLUMN_SHADOW) 409 #define GRID_MODE_SHADOW (XmGRID_CELL_SHADOW & XmGRID_ROW_SHADOW & XmGRID_COLUMN_SHADOW) 410 411 #define IN_GRID_ROW_MODE(mw) ((mw)->matrix.grid_type & GRID_MODE_ROW) 412 #define IN_GRID_COLUMN_MODE(mw) ((mw)->matrix.grid_type & GRID_MODE_COLUMN) 413 #define IN_GRID_SHADOW_MODE(mw) ((mw)->matrix.grid_type & GRID_MODE_SHADOW) 414 #define IN_GRID_LINE_MODE(mw) ((mw)->matrix.grid_type && !IN_GRID_SHADOW_MODE(mw)) 415 416 #ifdef __cplusplus 417 } 418 #endif 419 420 421 #endif /* _Xbae_Macros_h */ 422