| File: | Label.c |
| Location: | line 280, column 14 |
| Description: | Value stored to 'width' during its initialization is never read |
| 1 | /*********************************************************** |
| 2 | |
| 3 | Copyright (c) 1987, 1988, 1994 X Consortium |
| 4 | |
| 5 | Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | of this software and associated documentation files (the "Software"), to deal |
| 7 | in the Software without restriction, including without limitation the rights |
| 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | copies of the Software, and to permit persons to whom the Software is |
| 10 | furnished to do so, subject to the following conditions: |
| 11 | |
| 12 | The above copyright notice and this permission notice shall be included in |
| 13 | all copies or substantial portions of the Software. |
| 14 | |
| 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 19 | AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 21 | |
| 22 | Except as contained in this notice, the name of the X Consortium shall not be |
| 23 | used in advertising or otherwise to promote the sale, use or other dealings |
| 24 | in this Software without prior written authorization from the X Consortium. |
| 25 | |
| 26 | |
| 27 | Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts. |
| 28 | |
| 29 | All Rights Reserved |
| 30 | |
| 31 | Permission to use, copy, modify, and distribute this software and its |
| 32 | documentation for any purpose and without fee is hereby granted, |
| 33 | provided that the above copyright notice appear in all copies and that |
| 34 | both that copyright notice and this permission notice appear in |
| 35 | supporting documentation, and that the name of Digital not be |
| 36 | used in advertising or publicity pertaining to distribution of the |
| 37 | software without specific, written prior permission. |
| 38 | |
| 39 | DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING |
| 40 | ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL |
| 41 | DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR |
| 42 | ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, |
| 43 | WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, |
| 44 | ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS |
| 45 | SOFTWARE. |
| 46 | |
| 47 | ******************************************************************/ |
| 48 | |
| 49 | #ifdef HAVE_CONFIG_H1 |
| 50 | #include "config.h" |
| 51 | #endif |
| 52 | /* |
| 53 | * Label.c - Label widget |
| 54 | * |
| 55 | */ |
| 56 | |
| 57 | #include <X11/Xaw3d/Xaw3dP.h> |
| 58 | #include <X11/IntrinsicP.h> |
| 59 | #include <X11/StringDefs.h> |
| 60 | #include <X11/Xos.h> |
| 61 | #include <X11/Xaw3d/XawInit.h> |
| 62 | #include <X11/Xaw3d/Command.h> |
| 63 | #include <X11/Xaw3d/LabelP.h> |
| 64 | #include <X11/Xmu/Converters.h> |
| 65 | #include <X11/Xmu/Drawing.h> |
| 66 | #include <stdio.h> |
| 67 | #include <ctype.h> |
| 68 | |
| 69 | /* needed for abs() */ |
| 70 | #include <stdlib.h> |
| 71 | |
| 72 | #define streq(a,b)(strcmp( (a), (b) ) == 0) (strcmp( (a), (b) ) == 0) |
| 73 | |
| 74 | #define MULTI_LINE_LABEL32767 32767 |
| 75 | |
| 76 | |
| 77 | /**************************************************************** |
| 78 | * |
| 79 | * Full class record constant |
| 80 | * |
| 81 | ****************************************************************/ |
| 82 | |
| 83 | /* Private Data */ |
| 84 | |
| 85 | #define offset(field) XtOffsetOf(LabelRec, field)__builtin_offsetof(LabelRec, field) |
| 86 | static XtResource resources[] = { |
| 87 | {XtNforeground((char*)&XtStrings[214]), XtCForeground((char*)&XtStrings[1022]), XtRPixel((char*)&XtStrings[1754]), sizeof(Pixel), |
| 88 | offset(label.foreground), XtRString((char*)&XtStrings[1797]), XtDefaultForeground"XtDefaultForeground"}, |
| 89 | {XtNfont((char*)&XtStrings[199]), XtCFont((char*)&XtStrings[1017]), XtRFontStruct((char*)&XtStrings[1666]), sizeof(XFontStruct *), |
| 90 | offset(label.font),XtRString((char*)&XtStrings[1797]), XtDefaultFont"XtDefaultFont"}, |
| 91 | #ifdef XAW_INTERNATIONALIZATION1 |
| 92 | {XtNfontSet((char*)&XtStrings[2018]), XtCFontSet((char*)&XtStrings[2034]), XtRFontSet((char*)&XtStrings[2026]), sizeof(XFontSet ), |
| 93 | offset(label.fontset),XtRString((char*)&XtStrings[1797]), XtDefaultFontSet"XtDefaultFontSet"}, |
| 94 | #endif |
| 95 | {XtNlabel((char*)&XtStrings[429]), XtCLabel((char*)&XtStrings[1151]), XtRString((char*)&XtStrings[1797]), sizeof(String), |
| 96 | offset(label.label), XtRString((char*)&XtStrings[1797]), NULL((void*)0)}, |
| 97 | {XtNencoding"encoding", XtCEncoding"Encoding", XtRUnsignedChar((char*)&XtStrings[1828]), sizeof(unsigned char), |
| 98 | offset(label.encoding), XtRImmediate((char*)&XtStrings[1695]), (XtPointer)XawTextEncoding8bit0}, |
| 99 | {XtNjustify((char*)&XtStrings[379]), XtCJustify((char*)&XtStrings[1122]), XtRJustify((char*)&XtStrings[1722]), sizeof(XtJustify), |
| 100 | offset(label.justify), XtRImmediate((char*)&XtStrings[1695]), (XtPointer)XtJustifyCenter}, |
| 101 | {XtNinternalWidth((char*)&XtStrings[356]), XtCWidth((char*)&XtStrings[1510]), XtRDimension((char*)&XtStrings[1618]), sizeof(Dimension), |
| 102 | offset(label.internal_width), XtRImmediate((char*)&XtStrings[1695]), (XtPointer)4}, |
| 103 | {XtNinternalHeight((char*)&XtStrings[341]), XtCHeight((char*)&XtStrings[1051]), XtRDimension((char*)&XtStrings[1618]), sizeof(Dimension), |
| 104 | offset(label.internal_height), XtRImmediate((char*)&XtStrings[1695]), (XtPointer)2}, |
| 105 | {XtNleftBitmap"leftBitmap", XtCLeftBitmap"LeftBitmap", XtRBitmap((char*)&XtStrings[1549]), sizeof(Pixmap), |
| 106 | offset(label.left_bitmap), XtRImmediate((char*)&XtStrings[1695]), (XtPointer) None0L}, |
| 107 | {XtNbitmap((char*)&XtStrings[80]), XtCPixmap((char*)&XtStrings[1228]), XtRBitmap((char*)&XtStrings[1549]), sizeof(Pixmap), |
| 108 | offset(label.pixmap), XtRImmediate((char*)&XtStrings[1695]), (XtPointer)None0L}, |
| 109 | {XtNresize((char*)&XtStrings[564]), XtCResize((char*)&XtStrings[1253]), XtRBoolean((char*)&XtStrings[1561]), sizeof(Boolean), |
| 110 | offset(label.resize), XtRImmediate((char*)&XtStrings[1695]), (XtPointer)True1}, |
| 111 | {XtNshadowWidth"shadowWidth", XtCShadowWidth"ShadowWidth", XtRDimension((char*)&XtStrings[1618]), sizeof(Dimension), |
| 112 | offset(threeD.shadow_width), XtRImmediate((char*)&XtStrings[1695]), (XtPointer) 0}, |
| 113 | {XtNborderWidth((char*)&XtStrings[124]), XtCBorderWidth((char*)&XtStrings[940]), XtRDimension((char*)&XtStrings[1618]), sizeof(Dimension), |
| 114 | XtOffsetOf(RectObjRec,rectangle.border_width)__builtin_offsetof(RectObjRec, rectangle.border_width), XtRImmediate((char*)&XtStrings[1695]), |
| 115 | (XtPointer)1} |
| 116 | }; |
| 117 | #undef offset |
| 118 | |
| 119 | static void Initialize(Widget, Widget, ArgList, Cardinal *); |
| 120 | static void Resize(Widget); |
| 121 | static void Redisplay(Widget, XEvent *, Region); |
| 122 | static Boolean SetValues(Widget, Widget, Widget, ArgList, Cardinal *); |
| 123 | static void ClassInitialize(void); |
| 124 | static void Destroy(Widget); |
| 125 | static XtGeometryResult QueryGeometry(Widget, XtWidgetGeometry *, XtWidgetGeometry *); |
| 126 | |
| 127 | LabelClassRec labelClassRec = { |
| 128 | { |
| 129 | /* core_class fields */ |
| 130 | /* superclass */ (WidgetClass) &threeDClassRec, |
| 131 | /* class_name */ "Label", |
| 132 | /* widget_size */ sizeof(LabelRec), |
| 133 | /* class_initialize */ ClassInitialize, |
| 134 | /* class_part_initialize */ NULL((void*)0), |
| 135 | /* class_inited */ FALSE0, |
| 136 | /* initialize */ Initialize, |
| 137 | /* initialize_hook */ NULL((void*)0), |
| 138 | /* realize */ XtInheritRealize((XtRealizeProc) _XtInherit), |
| 139 | /* actions */ NULL((void*)0), |
| 140 | /* num_actions */ 0, |
| 141 | /* resources */ resources, |
| 142 | /* num_resources */ XtNumber(resources)((Cardinal) (sizeof(resources) / sizeof(resources[0]))), |
| 143 | /* xrm_class */ NULLQUARK((XrmQuark) 0), |
| 144 | /* compress_motion */ TRUE1, |
| 145 | /* compress_exposure */ TRUE1, |
| 146 | /* compress_enterleave */ TRUE1, |
| 147 | /* visible_interest */ FALSE0, |
| 148 | /* destroy */ Destroy, |
| 149 | /* resize */ Resize, |
| 150 | /* expose */ Redisplay, |
| 151 | /* set_values */ SetValues, |
| 152 | /* set_values_hook */ NULL((void*)0), |
| 153 | /* set_values_almost */ XtInheritSetValuesAlmost((XtAlmostProc) _XtInherit), |
| 154 | /* get_values_hook */ NULL((void*)0), |
| 155 | /* accept_focus */ NULL((void*)0), |
| 156 | /* version */ XtVersion(11 * 1000 + 6), |
| 157 | /* callback_private */ NULL((void*)0), |
| 158 | /* tm_table */ NULL((void*)0), |
| 159 | /* query_geometry */ QueryGeometry, |
| 160 | /* display_accelerator */ XtInheritDisplayAccelerator((XtStringProc) _XtInherit), |
| 161 | /* extension */ NULL((void*)0) |
| 162 | }, |
| 163 | /* Simple class fields initialization */ |
| 164 | { |
| 165 | /* change_sensitive */ XtInheritChangeSensitive((Boolean (*)(Widget))_XtInherit) |
| 166 | }, |
| 167 | /* ThreeD class fields initialization */ |
| 168 | { |
| 169 | /* shadowdraw */ XtInheritXaw3dShadowDraw((void (*)(Widget, XEvent *, Region, XtRelief, Boolean))_XtInherit ) |
| 170 | }, |
| 171 | /* Label class fields initialization */ |
| 172 | { |
| 173 | /* ignore */ 0 |
| 174 | } |
| 175 | }; |
| 176 | |
| 177 | WidgetClass labelWidgetClass = (WidgetClass)&labelClassRec; |
| 178 | |
| 179 | /**************************************************************** |
| 180 | * |
| 181 | * Private Procedures |
| 182 | * |
| 183 | ****************************************************************/ |
| 184 | |
| 185 | static void |
| 186 | ClassInitialize(void) |
| 187 | { |
| 188 | XawInitializeWidgetSet(); |
| 189 | XtAddConverter( XtRString((char*)&XtStrings[1797]), XtRJustify((char*)&XtStrings[1722]), XmuCvtStringToJustify, |
| 190 | (XtConvertArgList)NULL((void*)0), 0 ); |
| 191 | } |
| 192 | |
| 193 | /* |
| 194 | * Calculate width and height of displayed text in pixels |
| 195 | */ |
| 196 | |
| 197 | static void |
| 198 | SetTextWidthAndHeight(LabelWidget lw) |
| 199 | { |
| 200 | XFontStruct *fs = lw->label.font; |
| 201 | |
| 202 | char *nl; |
| 203 | |
| 204 | if (lw->label.pixmap != None0L) { |
| 205 | Window root; |
| 206 | int x, y; |
| 207 | unsigned int width, height, bw, depth; |
| 208 | |
| 209 | if (XGetGeometry(XtDisplay(lw)(((lw)->core.screen)->display), lw->label.pixmap, &root, &x, &y, |
| 210 | &width, &height, &bw, &depth)) { |
| 211 | lw->label.label_height = height; |
| 212 | lw->label.label_width = width; |
| 213 | lw->label.depth = depth; |
| 214 | return; |
| 215 | } |
| 216 | } |
| 217 | #ifdef XAW_INTERNATIONALIZATION1 |
| 218 | if ( lw->simple.international == True1 ) { |
| 219 | XFontSet fset = lw->label.fontset; |
| 220 | XFontSetExtents *ext = XExtentsOfFontSet(fset); |
| 221 | |
| 222 | lw->label.label_height = ext->max_ink_extent.height; |
| 223 | if (lw->label.label == NULL((void*)0)) { |
| 224 | lw->label.label_len = 0; |
| 225 | lw->label.label_width = 0; |
| 226 | } |
| 227 | else if ((nl = index(lw->label.label, '\n')) != NULL((void*)0)) { |
| 228 | char *label; |
| 229 | lw->label.label_len = MULTI_LINE_LABEL32767; |
| 230 | lw->label.label_width = 0; |
| 231 | for (label = lw->label.label; nl != NULL((void*)0); nl = index(label, '\n')) { |
| 232 | int width = XmbTextEscapement(fset, label, (int)(nl - label)); |
| 233 | |
| 234 | if (width > (int)lw->label.label_width) |
| 235 | lw->label.label_width = width; |
| 236 | label = nl + 1; |
| 237 | if (*label) |
| 238 | lw->label.label_height += |
| 239 | ext->max_ink_extent.height; |
| 240 | } |
| 241 | if (*label) { |
| 242 | int width = XmbTextEscapement(fset, label, strlen(label)); |
| 243 | |
| 244 | if (width > (int) lw->label.label_width) |
| 245 | lw->label.label_width = width; |
| 246 | } |
| 247 | } else { |
| 248 | lw->label.label_len = strlen(lw->label.label); |
| 249 | lw->label.label_width = |
| 250 | XmbTextEscapement(fset, lw->label.label, (int) lw->label.label_len); |
| 251 | } |
| 252 | |
| 253 | } else |
| 254 | #endif |
| 255 | { |
| 256 | lw->label.label_height = fs->max_bounds.ascent + fs->max_bounds.descent; |
| 257 | if (lw->label.label == NULL((void*)0)) { |
| 258 | lw->label.label_len = 0; |
| 259 | lw->label.label_width = 0; |
| 260 | } |
| 261 | else if ((nl = index(lw->label.label, '\n')) != NULL((void*)0)) { |
| 262 | char *label; |
| 263 | lw->label.label_len = MULTI_LINE_LABEL32767; |
| 264 | lw->label.label_width = 0; |
| 265 | for (label = lw->label.label; nl != NULL((void*)0); nl = index(label, '\n')) { |
| 266 | int width; |
| 267 | |
| 268 | if (lw->label.encoding) |
| 269 | width = XTextWidth16(fs, (XChar2b *)label, (int)(nl - label)/2); |
| 270 | else |
| 271 | width = XTextWidth(fs, label, (int)(nl - label)); |
| 272 | if (width > (int)lw->label.label_width) |
| 273 | lw->label.label_width = width; |
| 274 | label = nl + 1; |
| 275 | if (*label) |
| 276 | lw->label.label_height += |
| 277 | fs->max_bounds.ascent + fs->max_bounds.descent; |
| 278 | } |
| 279 | if (*label) { |
| 280 | int width = XTextWidth(fs, label, strlen(label)); |
Value stored to 'width' during its initialization is never read | |
| 281 | |
| 282 | if (lw->label.encoding) |
| 283 | width = XTextWidth16(fs, (XChar2b *)label, (int)strlen(label)/2); |
| 284 | else |
| 285 | width = XTextWidth(fs, label, strlen(label)); |
| 286 | if (width > (int) lw->label.label_width) |
| 287 | lw->label.label_width = width; |
| 288 | } |
| 289 | } else { |
| 290 | lw->label.label_len = strlen(lw->label.label); |
| 291 | if (lw->label.encoding) |
| 292 | lw->label.label_width = |
| 293 | XTextWidth16(fs, (XChar2b *)lw->label.label, |
| 294 | (int) lw->label.label_len/2); |
| 295 | else |
| 296 | lw->label.label_width = |
| 297 | XTextWidth(fs, lw->label.label, (int) lw->label.label_len); |
| 298 | } |
| 299 | |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | static void |
| 304 | GetnormalGC(LabelWidget lw) |
| 305 | { |
| 306 | XGCValues values; |
| 307 | |
| 308 | values.foreground = lw->label.foreground; |
| 309 | values.background = lw->core.background_pixel; |
| 310 | values.font = lw->label.font->fid; |
| 311 | values.graphics_exposures = False0; |
| 312 | |
| 313 | #ifdef XAW_INTERNATIONALIZATION1 |
| 314 | if ( lw->simple.international == True1 ) |
| 315 | /* Since Xmb/wcDrawString eats the font, I must use XtAllocateGC. */ |
| 316 | lw->label.normal_GC = XtAllocateGC( |
| 317 | (Widget)lw, 0, |
| 318 | (unsigned) GCForeground(1L<<2) | GCBackground(1L<<3) | GCGraphicsExposures(1L<<16), |
| 319 | &values, GCFont(1L<<14), 0 ); |
| 320 | else |
| 321 | #endif |
| 322 | lw->label.normal_GC = XtGetGC( |
| 323 | (Widget)lw, |
| 324 | (unsigned) GCForeground(1L<<2) | GCBackground(1L<<3) | GCFont(1L<<14) | GCGraphicsExposures(1L<<16), |
| 325 | &values); |
| 326 | } |
| 327 | |
| 328 | static void |
| 329 | GetgrayGC(LabelWidget lw) |
| 330 | { |
| 331 | XGCValues values; |
| 332 | |
| 333 | values.foreground = lw->label.foreground; |
| 334 | values.background = lw->core.background_pixel; |
| 335 | values.font = lw->label.font->fid; |
| 336 | values.fill_style = FillTiled1; |
| 337 | values.tile = XmuCreateStippledPixmap(XtScreen((Widget)lw)(((Widget)lw)->core.screen), |
| 338 | lw->label.foreground, |
| 339 | lw->core.background_pixel, |
| 340 | lw->core.depth); |
| 341 | values.graphics_exposures = False0; |
| 342 | |
| 343 | lw->label.stipple = values.tile; |
| 344 | #ifdef XAW_INTERNATIONALIZATION1 |
| 345 | if ( lw->simple.international == True1 ) |
| 346 | /* Since Xmb/wcDrawString eats the font, I must use XtAllocateGC. */ |
| 347 | lw->label.gray_GC = XtAllocateGC((Widget)lw, 0, |
| 348 | (unsigned) GCForeground(1L<<2) | GCBackground(1L<<3) | |
| 349 | GCTile(1L<<10) | GCFillStyle(1L<<8) | |
| 350 | GCGraphicsExposures(1L<<16), |
| 351 | &values, GCFont(1L<<14), 0); |
| 352 | else |
| 353 | #endif |
| 354 | lw->label.gray_GC = XtGetGC((Widget)lw, |
| 355 | (unsigned) GCForeground(1L<<2) | GCBackground(1L<<3) | |
| 356 | GCFont(1L<<14) | GCTile(1L<<10) | GCFillStyle(1L<<8) | |
| 357 | GCGraphicsExposures(1L<<16), |
| 358 | &values); |
| 359 | } |
| 360 | |
| 361 | static void |
| 362 | compute_bitmap_offsets (LabelWidget lw) |
| 363 | { |
| 364 | if (lw->label.lbm_height != 0) |
| 365 | lw->label.lbm_y = (lw->core.height - lw->label.lbm_height) / 2; |
| 366 | else |
| 367 | lw->label.lbm_y = 0; |
| 368 | } |
| 369 | |
| 370 | static void |
| 371 | set_bitmap_info (LabelWidget lw) |
| 372 | { |
| 373 | Window root; |
| 374 | int x, y; |
| 375 | unsigned int bw; |
| 376 | |
| 377 | if (lw->label.pixmap || !(lw->label.left_bitmap && |
| 378 | XGetGeometry (XtDisplay(lw)(((lw)->core.screen)->display), lw->label.left_bitmap, &root, &x, &y, |
| 379 | &lw->label.lbm_width, &lw->label.lbm_height, |
| 380 | &bw, &lw->label.depth))) { |
| 381 | lw->label.lbm_width = lw->label.lbm_height = 0; |
| 382 | } |
| 383 | compute_bitmap_offsets (lw); |
| 384 | } |
| 385 | |
| 386 | /* ARGSUSED */ |
| 387 | static void |
| 388 | Initialize(Widget request, Widget new, ArgList args, Cardinal *num_args) |
| 389 | { |
| 390 | LabelWidget lw = (LabelWidget) new; |
| 391 | |
| 392 | /* disable shadows if we're not a subclass of Command */ |
| 393 | if (!XtIsSubclass(new, commandWidgetClass)) |
| 394 | lw->threeD.shadow_width = 0; |
| 395 | |
| 396 | if (lw->label.label == NULL((void*)0)) |
| 397 | lw->label.label = XtNewString(lw->core.name)((lw->core.name) != ((void*)0) ? (__builtin___strcpy_chk ( XtMalloc((unsigned)strlen(lw->core.name) + 1), lw->core .name, __builtin_object_size (XtMalloc((unsigned)strlen(lw-> core.name) + 1), 2 > 1 ? 1 : 0))) : ((void*)0)); |
| 398 | else |
| 399 | lw->label.label = XtNewString(lw->label.label)((lw->label.label) != ((void*)0) ? (__builtin___strcpy_chk (XtMalloc((unsigned)strlen(lw->label.label) + 1), lw-> label.label, __builtin_object_size (XtMalloc((unsigned)strlen (lw->label.label) + 1), 2 > 1 ? 1 : 0))) : ((void*)0)); |
| 400 | |
| 401 | GetnormalGC(lw); |
| 402 | GetgrayGC(lw); |
| 403 | |
| 404 | SetTextWidthAndHeight(lw); /* label.label or label.pixmap */ |
| 405 | |
| 406 | if (lw->core.height == 0) |
| 407 | lw->core.height = lw->label.label_height + |
| 408 | 2 * lw->label.internal_height; |
| 409 | |
| 410 | set_bitmap_info(lw); /* req's core.height, sets label.lbm_* */ |
| 411 | |
| 412 | if (lw->label.lbm_height > lw->label.label_height) |
| 413 | lw->core.height = lw->label.lbm_height + |
| 414 | 2 * lw->label.internal_height; |
| 415 | |
| 416 | if (lw->core.width == 0) |
| 417 | lw->core.width = lw->label.label_width + |
| 418 | 2 * lw->label.internal_width + |
| 419 | LEFT_OFFSET(lw)((lw)->label.left_bitmap && (lw)->label.pixmap == 0L ? (lw)->label.lbm_width + (lw)->label.internal_width : 0); /* req's label.lbm_width */ |
| 420 | |
| 421 | lw->label.label_x = lw->label.label_y = 0; |
| 422 | (*XtClass(new)((new)->core.widget_class)->core_class.resize) ((Widget)lw); |
| 423 | |
| 424 | lw->label.stippled = lw->label.left_stippled = None0L; |
| 425 | } /* Initialize */ |
| 426 | |
| 427 | /* |
| 428 | * Repaint the widget window |
| 429 | */ |
| 430 | |
| 431 | /* ARGSUSED */ |
| 432 | static void |
| 433 | Redisplay(Widget gw, XEvent *event, Region region) |
| 434 | { |
| 435 | LabelWidget w = (LabelWidget) gw; |
| 436 | LabelWidgetClass lwclass = (LabelWidgetClass) XtClass (gw)((gw)->core.widget_class); |
| 437 | Pixmap pm; |
| 438 | GC gc; |
| 439 | |
| 440 | /* |
| 441 | * Don't draw shadows if Command is going to redraw them. |
| 442 | * The shadow draw method is region aware, but since 99% of |
| 443 | * all labels don't have shadows, we'll check for a shadow |
| 444 | * before we incur the function call overhead. |
| 445 | */ |
| 446 | if (!XtIsSubclass (gw, commandWidgetClass) && w->threeD.shadow_width > 0) |
| 447 | (*lwclass->threeD_class.shadowdraw) (gw, event, region, |
| 448 | w->threeD.relief, True1); |
| 449 | |
| 450 | /* |
| 451 | * now we'll see if we need to draw the rest of the label |
| 452 | */ |
| 453 | if (region != NULL((void*)0)) { |
| 454 | int x = w->label.label_x; |
| 455 | unsigned int width = w->label.label_width; |
| 456 | if (w->label.lbm_width) { |
| 457 | if (w->label.label_x > (x = w->label.internal_width)) |
| 458 | width += w->label.label_x - x; |
| 459 | } |
| 460 | if (XRectInRegion(region, x, w->label.label_y, |
| 461 | width, w->label.label_height) == RectangleOut0){ |
| 462 | return; |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | gc = XtIsSensitive(gw) ? w->label.normal_GC : w->label.gray_GC; |
| 467 | #ifdef notdef |
| 468 | if (region != NULL((void*)0)) |
| 469 | XSetRegion(XtDisplay(gw)(((gw)->core.screen)->display), gc, region); |
| 470 | #endif /*notdef*/ |
| 471 | |
| 472 | if (w->label.pixmap == None0L) { |
| 473 | int len = w->label.label_len; |
| 474 | char *label = w->label.label; |
| 475 | Position y = w->label.label_y + w->label.font->max_bounds.ascent; |
| 476 | #ifdef XAW_INTERNATIONALIZATION1 |
| 477 | Position ksy = w->label.label_y; |
| 478 | #endif |
| 479 | |
| 480 | /* display left bitmap */ |
| 481 | if (w->label.left_bitmap && w->label.lbm_width != 0) { |
| 482 | pm = w->label.left_bitmap; |
| 483 | #ifdef XAW_MULTIPLANE_PIXMAPS |
| 484 | if (!XtIsSensitive(gw)) { |
| 485 | if (w->label.left_stippled == None0L) |
| 486 | w->label.left_stippled = stipplePixmap(gw, |
| 487 | w->label.left_bitmap, w->core.colormap, |
| 488 | w->core.background_pixel, w->label.depth); |
| 489 | if (w->label.left_stippled != None0L) |
| 490 | pm = w->label.left_stippled; |
| 491 | } |
| 492 | #endif |
| 493 | |
| 494 | if (w->label.depth == 1) |
| 495 | XCopyPlane(XtDisplay(gw)(((gw)->core.screen)->display), pm, XtWindow(gw)((gw)->core.window), gc, 0, 0, |
| 496 | w->label.lbm_width, w->label.lbm_height, |
| 497 | (int) w->label.internal_width, |
| 498 | (int) w->label.lbm_y, |
| 499 | (unsigned long) 1L); |
| 500 | else |
| 501 | XCopyArea(XtDisplay(gw)(((gw)->core.screen)->display), pm, XtWindow(gw)((gw)->core.window), gc, 0, 0, |
| 502 | w->label.lbm_width, w->label.lbm_height, |
| 503 | (int) w->label.internal_width, |
| 504 | (int) w->label.lbm_y); |
| 505 | } |
| 506 | |
| 507 | #ifdef XAW_INTERNATIONALIZATION1 |
| 508 | if ( w->simple.international == True1 ) { |
| 509 | |
| 510 | XFontSetExtents *ext = XExtentsOfFontSet(w->label.fontset); |
| 511 | |
| 512 | ksy += abs(ext->max_ink_extent.y); |
| 513 | |
| 514 | if (len == MULTI_LINE_LABEL32767) { |
| 515 | char *nl; |
| 516 | while ((nl = index(label, '\n')) != NULL((void*)0)) { |
| 517 | XmbDrawString(XtDisplay(w)(((w)->core.screen)->display), XtWindow(w)((w)->core.window), w->label.fontset, gc, |
| 518 | w->label.label_x, ksy, label, (int)(nl - label)); |
| 519 | ksy += ext->max_ink_extent.height; |
| 520 | label = nl + 1; |
| 521 | } |
| 522 | len = strlen(label); |
| 523 | } |
| 524 | if (len) |
| 525 | XmbDrawString(XtDisplay(w)(((w)->core.screen)->display), XtWindow(w)((w)->core.window), w->label.fontset, gc, |
| 526 | w->label.label_x, ksy, label, len); |
| 527 | |
| 528 | } else |
| 529 | #endif |
| 530 | { /* international false, so use R5 routine */ |
| 531 | |
| 532 | if (len == MULTI_LINE_LABEL32767) { |
| 533 | char *nl; |
| 534 | while ((nl = index(label, '\n')) != NULL((void*)0)) { |
| 535 | if (w->label.encoding) |
| 536 | XDrawString16(XtDisplay(gw)(((gw)->core.screen)->display), XtWindow(gw)((gw)->core.window), gc, |
| 537 | w->label.label_x, y, |
| 538 | (XChar2b *)label, (int)(nl - label)/2); |
| 539 | else |
| 540 | XDrawString(XtDisplay(gw)(((gw)->core.screen)->display), XtWindow(gw)((gw)->core.window), gc, |
| 541 | w->label.label_x, y, label, (int)(nl - label)); |
| 542 | y += w->label.font->max_bounds.ascent + |
| 543 | w->label.font->max_bounds.descent; |
| 544 | label = nl + 1; |
| 545 | } |
| 546 | len = strlen(label); |
| 547 | } |
| 548 | if (len) { |
| 549 | if (w->label.encoding) |
| 550 | XDrawString16(XtDisplay(gw)(((gw)->core.screen)->display), XtWindow(gw)((gw)->core.window), gc, |
| 551 | w->label.label_x, y, (XChar2b *)label, len/2); |
| 552 | else |
| 553 | XDrawString(XtDisplay(gw)(((gw)->core.screen)->display), XtWindow(gw)((gw)->core.window), gc, |
| 554 | w->label.label_x, y, label, len); |
| 555 | } |
| 556 | |
| 557 | } /* endif international */ |
| 558 | |
| 559 | } else { |
| 560 | pm = w->label.pixmap; |
| 561 | #ifdef XAW_MULTIPLANE_PIXMAPS |
| 562 | if (!XtIsSensitive(gw)) { |
| 563 | if (w->label.stippled == None0L) |
| 564 | w->label.stippled = stipplePixmap(gw, |
| 565 | w->label.pixmap, w->core.colormap, |
| 566 | w->core.background_pixel, w->label.depth); |
| 567 | if (w->label.stippled != None0L) |
| 568 | pm = w->label.stippled; |
| 569 | } |
| 570 | #endif |
| 571 | |
| 572 | if (w->label.depth == 1) |
| 573 | XCopyPlane(XtDisplay(gw)(((gw)->core.screen)->display), pm, XtWindow(gw)((gw)->core.window), gc, 0, 0, |
| 574 | w->label.label_width, w->label.label_height, |
| 575 | w->label.label_x, w->label.label_y, |
| 576 | 1L); |
| 577 | else |
| 578 | XCopyArea(XtDisplay(gw)(((gw)->core.screen)->display), pm, XtWindow(gw)((gw)->core.window), gc, 0, 0, |
| 579 | w->label.label_width, w->label.label_height, |
| 580 | w->label.label_x, w->label.label_y); |
| 581 | } |
| 582 | |
| 583 | #ifdef notdef |
| 584 | if (region != NULL((void*)0)) |
| 585 | XSetClipMask(XtDisplay(gw)(((gw)->core.screen)->display), gc, (Pixmap)None0L); |
| 586 | #endif /* notdef */ |
| 587 | } |
| 588 | |
| 589 | static void |
| 590 | _Reposition(LabelWidget lw, Dimension width, Dimension height, |
| 591 | Position *dx, Position *dy) |
| 592 | { |
| 593 | Position newPos; |
| 594 | Position leftedge = lw->label.internal_width + LEFT_OFFSET(lw)((lw)->label.left_bitmap && (lw)->label.pixmap == 0L ? (lw)->label.lbm_width + (lw)->label.internal_width : 0); |
| 595 | |
| 596 | switch (lw->label.justify) { |
| 597 | case XtJustifyLeft: |
| 598 | newPos = leftedge; |
| 599 | break; |
| 600 | case XtJustifyRight: |
| 601 | newPos = width - lw->label.label_width - lw->label.internal_width; |
| 602 | break; |
| 603 | case XtJustifyCenter: |
| 604 | default: |
| 605 | newPos = (int)(width - lw->label.label_width) / 2; |
| 606 | break; |
| 607 | } |
| 608 | |
| 609 | if (newPos < (Position)leftedge) |
| 610 | newPos = leftedge; |
| 611 | *dx = newPos - lw->label.label_x; |
| 612 | lw->label.label_x = newPos; |
| 613 | |
| 614 | *dy = (newPos = (int)(height - lw->label.label_height) / 2) |
| 615 | - lw->label.label_y; |
| 616 | lw->label.label_y = newPos; |
| 617 | |
| 618 | lw->label.lbm_y = (height - lw->label.lbm_height) / 2; |
| 619 | |
| 620 | return; |
| 621 | } |
| 622 | |
| 623 | static void |
| 624 | Resize(Widget w) |
| 625 | { |
| 626 | LabelWidget lw = (LabelWidget)w; |
| 627 | Position dx, dy; |
| 628 | |
| 629 | _Reposition(lw, w->core.width, w->core.height, &dx, &dy); |
| 630 | compute_bitmap_offsets (lw); |
| 631 | } |
| 632 | |
| 633 | /* |
| 634 | * Set specified arguments into widget |
| 635 | */ |
| 636 | |
| 637 | #define PIXMAP0 0 |
| 638 | #define WIDTH1 1 |
| 639 | #define HEIGHT2 2 |
| 640 | #define NUM_CHECKS3 3 |
| 641 | |
| 642 | static Boolean |
| 643 | SetValues(Widget current, Widget request, Widget new, ArgList args, Cardinal *num_args) |
| 644 | { |
| 645 | LabelWidget curlw = (LabelWidget) current; |
| 646 | LabelWidget reqlw = (LabelWidget) request; |
| 647 | LabelWidget newlw = (LabelWidget) new; |
| 648 | int i; |
| 649 | Boolean was_resized = False0, redisplay = False0, checks[NUM_CHECKS3]; |
| 650 | |
| 651 | for (i = 0; i < NUM_CHECKS3; i++) |
| 652 | checks[i] = FALSE0; |
| 653 | for (i = 0; i < *num_args; i++) { |
| 654 | if (streq(XtNbitmap, args[i].name)(strcmp( (((char*)&XtStrings[80])), (args[i].name) ) == 0 )) |
| 655 | checks[PIXMAP0] = TRUE1; |
| 656 | if (streq(XtNwidth, args[i].name)(strcmp( (((char*)&XtStrings[872])), (args[i].name) ) == 0 )) |
| 657 | checks[WIDTH1] = TRUE1; |
| 658 | if (streq(XtNheight, args[i].name)(strcmp( (((char*)&XtStrings[234])), (args[i].name) ) == 0 )) |
| 659 | checks[HEIGHT2] = TRUE1; |
| 660 | } |
| 661 | |
| 662 | if (newlw->label.label == NULL((void*)0)) |
| 663 | newlw->label.label = newlw->core.name; |
| 664 | if (curlw->label.label != newlw->label.label) { |
| 665 | if (curlw->label.label != curlw->core.name) |
| 666 | XtFree((char *)curlw->label.label); |
| 667 | if (newlw->label.label != newlw->core.name) |
| 668 | newlw->label.label = XtNewString(newlw->label.label)((newlw->label.label) != ((void*)0) ? (__builtin___strcpy_chk (XtMalloc((unsigned)strlen(newlw->label.label) + 1), newlw ->label.label, __builtin_object_size (XtMalloc((unsigned)strlen (newlw->label.label) + 1), 2 > 1 ? 1 : 0))) : ((void*)0 )); |
| 669 | was_resized = True1; |
| 670 | } |
| 671 | |
| 672 | if (was_resized || checks[PIXMAP0] || |
| 673 | curlw->label.font != newlw->label.font || |
| 674 | #ifdef XAW_INTERNATIONALIZATION1 |
| 675 | (curlw->simple.international && |
| 676 | curlw->label.fontset != newlw->label.fontset) || |
| 677 | #endif |
| 678 | curlw->label.encoding != newlw->label.encoding || |
| 679 | curlw->label.justify != newlw->label.justify) { |
| 680 | SetTextWidthAndHeight(newlw); /* label.label or label.pixmap */ |
| 681 | was_resized = True1; |
| 682 | } |
| 683 | |
| 684 | if (curlw->label.left_bitmap != newlw->label.left_bitmap || |
| 685 | curlw->label.internal_width != newlw->label.internal_width || |
| 686 | curlw->label.internal_height != newlw->label.internal_height) |
| 687 | was_resized = True1; |
| 688 | |
| 689 | /* recalculate the window size if something has changed. */ |
| 690 | if (newlw->label.resize && was_resized) { |
| 691 | if (curlw->core.height == reqlw->core.height && !checks[HEIGHT2]) |
| 692 | newlw->core.height = newlw->label.label_height + |
| 693 | 2 * newlw->label.internal_height; |
| 694 | |
| 695 | set_bitmap_info (newlw); /* req's core.height, sets label.lbm_* */ |
| 696 | |
| 697 | if (newlw->label.lbm_height > newlw->label.label_height) |
| 698 | newlw->core.height = newlw->label.lbm_height + |
| 699 | 2 * newlw->label.internal_height; |
| 700 | |
| 701 | if (curlw->core.width == reqlw->core.width && !checks[WIDTH1]) |
| 702 | newlw->core.width = newlw->label.label_width + |
| 703 | 2 * newlw->label.internal_width + |
| 704 | LEFT_OFFSET(newlw)((newlw)->label.left_bitmap && (newlw)->label.pixmap == 0L ? (newlw)->label.lbm_width + (newlw)->label.internal_width : 0); /* req's label.lbm_width */ |
| 705 | } |
| 706 | |
| 707 | /* enforce minimum dimensions */ |
| 708 | if (newlw->label.resize) { |
| 709 | if (checks[HEIGHT2]) { |
| 710 | if (newlw->label.label_height > newlw->label.lbm_height) |
| 711 | i = newlw->label.label_height + |
| 712 | 2 * newlw->label.internal_height; |
| 713 | else |
| 714 | i = newlw->label.lbm_height + 2 * newlw->label.internal_height; |
| 715 | if (i > newlw->core.height) |
| 716 | newlw->core.height = i; |
| 717 | } |
| 718 | if (checks[WIDTH1]) { |
| 719 | i = newlw->label.label_width + 2 * newlw->label.internal_width + |
| 720 | LEFT_OFFSET(newlw)((newlw)->label.left_bitmap && (newlw)->label.pixmap == 0L ? (newlw)->label.lbm_width + (newlw)->label.internal_width : 0); /* req's label.lbm_width */ |
| 721 | if (i > newlw->core.width) |
| 722 | newlw->core.width = i; |
| 723 | } |
| 724 | } |
| 725 | |
| 726 | if (curlw->core.background_pixel != newlw->core.background_pixel || |
| 727 | curlw->label.foreground != newlw->label.foreground || |
| 728 | curlw->label.font->fid != newlw->label.font->fid) { |
| 729 | /* the fontset is not in the GC - no new GC if fontset changes */ |
| 730 | XtReleaseGC(new, curlw->label.normal_GC); |
| 731 | XtReleaseGC(new, curlw->label.gray_GC); |
| 732 | XmuReleaseStippledPixmap( XtScreen(current)((current)->core.screen), curlw->label.stipple ); |
| 733 | GetnormalGC(newlw); |
| 734 | GetgrayGC(newlw); |
| 735 | redisplay = True1; |
| 736 | } |
| 737 | |
| 738 | #ifdef XAW_MULTIPLANE_PIXMAPS |
| 739 | if (curlw->label.pixmap != newlw->label.pixmap) |
| 740 | { |
| 741 | newlw->label.stippled = None0L; |
| 742 | if (curlw->label.stippled != None0L) |
| 743 | XFreePixmap(XtDisplay(current)(((current)->core.screen)->display), curlw->label.stippled); |
| 744 | } |
| 745 | if (curlw->label.left_bitmap != newlw->label.left_bitmap) |
| 746 | { |
| 747 | newlw->label.left_stippled = None0L; |
| 748 | if (curlw->label.left_stippled != None0L) |
| 749 | XFreePixmap(XtDisplay(current)(((current)->core.screen)->display), curlw->label.left_stippled); |
| 750 | } |
| 751 | #endif |
| 752 | |
| 753 | if (was_resized) { |
| 754 | Position dx, dy; |
| 755 | |
| 756 | /* Resize() will be called if geometry changes succeed */ |
| 757 | _Reposition(newlw, curlw->core.width, curlw->core.height, &dx, &dy); |
| 758 | } |
| 759 | |
| 760 | return was_resized || redisplay || |
| 761 | XtIsSensitive(current) != XtIsSensitive(new); |
| 762 | } |
| 763 | |
| 764 | static void |
| 765 | Destroy(Widget w) |
| 766 | { |
| 767 | LabelWidget lw = (LabelWidget)w; |
| 768 | |
| 769 | if ( lw->label.label != lw->core.name ) |
| 770 | XtFree( lw->label.label ); |
| 771 | XtReleaseGC( w, lw->label.normal_GC ); |
| 772 | XtReleaseGC( w, lw->label.gray_GC); |
| 773 | #ifdef XAW_MULTIPLANE_PIXMAPS |
| 774 | if (lw->label.stippled != None0L) |
| 775 | XFreePixmap(XtDisplay(w)(((w)->core.screen)->display), lw->label.stippled); |
| 776 | if (lw->label.left_stippled != None0L) |
| 777 | XFreePixmap(XtDisplay(w)(((w)->core.screen)->display), lw->label.left_stippled); |
| 778 | #endif |
| 779 | XmuReleaseStippledPixmap( XtScreen(w)((w)->core.screen), lw->label.stipple ); |
| 780 | } |
| 781 | |
| 782 | |
| 783 | static XtGeometryResult |
| 784 | QueryGeometry(Widget w, XtWidgetGeometry *intended, XtWidgetGeometry *preferred) |
| 785 | { |
| 786 | LabelWidget lw = (LabelWidget)w; |
| 787 | |
| 788 | preferred->request_mode = CWWidth(1<<2) | CWHeight(1<<3); |
| 789 | preferred->width = (lw->label.label_width + |
| 790 | 2 * lw->label.internal_width + |
| 791 | LEFT_OFFSET(lw)((lw)->label.left_bitmap && (lw)->label.pixmap == 0L ? (lw)->label.lbm_width + (lw)->label.internal_width : 0)); |
| 792 | preferred->height = lw->label.label_height + |
| 793 | 2 * lw->label.internal_height; |
| 794 | if ( ((intended->request_mode & (CWWidth(1<<2) | CWHeight(1<<3))) |
| 795 | == (CWWidth(1<<2) | CWHeight(1<<3))) && |
| 796 | intended->width == preferred->width && |
| 797 | intended->height == preferred->height) |
| 798 | return XtGeometryYes; |
| 799 | else if (preferred->width == w->core.width && |
| 800 | preferred->height == w->core.height) |
| 801 | return XtGeometryNo; |
| 802 | else |
| 803 | return XtGeometryAlmost; |
| 804 | } |