Bug Summary

File:Label.c
Location:line 361, column 7
Description:Value stored to 'width' during its initialization is never read

Annotated Source Code

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