Label.c revision 421c997b
17a84e134Smrg/*********************************************************** 27a84e134Smrg 37a84e134SmrgCopyright 1987, 1988, 1994, 1998 The Open Group 47a84e134Smrg 57a84e134SmrgPermission to use, copy, modify, distribute, and sell this software and its 67a84e134Smrgdocumentation for any purpose is hereby granted without fee, provided that 77a84e134Smrgthe above copyright notice appear in all copies and that both that 87a84e134Smrgcopyright notice and this permission notice appear in supporting 97a84e134Smrgdocumentation. 107a84e134Smrg 117a84e134SmrgThe above copyright notice and this permission notice shall be included in 127a84e134Smrgall copies or substantial portions of the Software. 137a84e134Smrg 147a84e134SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 157a84e134SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 167a84e134SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 177a84e134SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 187a84e134SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 197a84e134SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 207a84e134Smrg 217a84e134SmrgExcept as contained in this notice, the name of The Open Group shall not be 227a84e134Smrgused in advertising or otherwise to promote the sale, use or other dealings 237a84e134Smrgin this Software without prior written authorization from The Open Group. 247a84e134Smrg 257a84e134Smrg 267a84e134SmrgCopyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts. 277a84e134Smrg 287a84e134Smrg All Rights Reserved 297a84e134Smrg 30421c997bSmrgPermission to use, copy, modify, and distribute this software and its 31421c997bSmrgdocumentation for any purpose and without fee is hereby granted, 327a84e134Smrgprovided that the above copyright notice appear in all copies and that 33421c997bSmrgboth that copyright notice and this permission notice appear in 347a84e134Smrgsupporting documentation, and that the name of Digital not be 357a84e134Smrgused in advertising or publicity pertaining to distribution of the 36421c997bSmrgsoftware without specific, written prior permission. 377a84e134Smrg 387a84e134SmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 397a84e134SmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 407a84e134SmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 417a84e134SmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 427a84e134SmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 437a84e134SmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 447a84e134SmrgSOFTWARE. 457a84e134Smrg 467a84e134Smrg******************************************************************/ 477a84e134Smrg 487a84e134Smrg#ifdef HAVE_CONFIG_H 497a84e134Smrg#include <config.h> 507a84e134Smrg#endif 517a84e134Smrg#include <stdio.h> 527a84e134Smrg#include <ctype.h> 537a84e134Smrg#include <X11/IntrinsicP.h> 547a84e134Smrg#include <X11/StringDefs.h> 557a84e134Smrg#include <X11/Xos.h> 567a84e134Smrg#include <X11/Xmu/Converters.h> 577a84e134Smrg#include <X11/Xmu/Drawing.h> 587a84e134Smrg#include <X11/Xaw/LabelP.h> 597a84e134Smrg#include <X11/Xaw/XawInit.h> 607a84e134Smrg#include "Private.h" 617a84e134Smrg 627a84e134Smrg#define streq(a, b) (strcmp((a), (b)) == 0) 637a84e134Smrg 647a84e134Smrg#define MULTI_LINE_LABEL 32767 657a84e134Smrg 667a84e134Smrg#ifdef CRAY 677a84e134Smrg#define WORD64 687a84e134Smrg#endif 697a84e134Smrg 707a84e134Smrg/* 717a84e134Smrg * Class Methods 727a84e134Smrg */ 737a84e134Smrgstatic void XawLabelClassInitialize(void); 747a84e134Smrgstatic void XawLabelDestroy(Widget); 757a84e134Smrgstatic void XawLabelInitialize(Widget, Widget, ArgList, Cardinal*); 767a84e134Smrgstatic XtGeometryResult XawLabelQueryGeometry(Widget, XtWidgetGeometry*, 777a84e134Smrg XtWidgetGeometry*); 787a84e134Smrgstatic void XawLabelRedisplay(Widget, XEvent*, Region); 797a84e134Smrgstatic void XawLabelResize(Widget); 807a84e134Smrgstatic Boolean XawLabelSetValues(Widget, Widget, Widget, 817a84e134Smrg ArgList, Cardinal*); 827a84e134Smrg 837a84e134Smrg/* 847a84e134Smrg * Prototypes 857a84e134Smrg */ 867a84e134Smrg#ifdef WORD64 877a84e134Smrgstatic int _XawLabelWidth16(XFontStruct*, char*, int); 887a84e134Smrgstatic void _XawLabelDraw16(Display*, Drawable, GC, int, int, char*, int); 897a84e134Smrg#endif 907a84e134Smrgstatic void compute_bitmap_offsets(LabelWidget); 917a84e134Smrgstatic void GetGrayGC(LabelWidget); 927a84e134Smrgstatic void GetNormalGC(LabelWidget); 937a84e134Smrgstatic void _Reposition(LabelWidget, unsigned int, unsigned int, 947a84e134Smrg Position*, Position*); 957a84e134Smrgstatic void set_bitmap_info(LabelWidget); 967a84e134Smrgstatic void SetTextWidthAndHeight(LabelWidget); 977a84e134Smrg 987a84e134Smrg/* 997a84e134Smrg * Initialization 1007a84e134Smrg */ 1017a84e134Smrg#define offset(field) XtOffsetOf(LabelRec, field) 1027a84e134Smrgstatic XtResource resources[] = { 1037a84e134Smrg { 1047a84e134Smrg XtNforeground, 1057a84e134Smrg XtCForeground, 1067a84e134Smrg XtRPixel, 1077a84e134Smrg sizeof(Pixel), 1087a84e134Smrg offset(label.foreground), 1097a84e134Smrg XtRString, 1107a84e134Smrg XtDefaultForeground 1117a84e134Smrg }, 1127a84e134Smrg { 1137a84e134Smrg XtNfont, 1147a84e134Smrg XtCFont, 1157a84e134Smrg XtRFontStruct, 1167a84e134Smrg sizeof(XFontStruct*), 1177a84e134Smrg offset(label.font), 1187a84e134Smrg XtRString, 1197a84e134Smrg XtDefaultFont 1207a84e134Smrg }, 1217a84e134Smrg { 1227a84e134Smrg XtNfontSet, 1237a84e134Smrg XtCFontSet, 1247a84e134Smrg XtRFontSet, 1257a84e134Smrg sizeof(XFontSet), 1267a84e134Smrg offset(label.fontset), 1277a84e134Smrg XtRString, 1287a84e134Smrg XtDefaultFontSet 1297a84e134Smrg }, 1307a84e134Smrg { 1317a84e134Smrg XtNlabel, 1327a84e134Smrg XtCLabel, 1337a84e134Smrg XtRString, 1347a84e134Smrg sizeof(String), 1357a84e134Smrg offset(label.label), 1367a84e134Smrg XtRString, 1377a84e134Smrg NULL 1387a84e134Smrg }, 1397a84e134Smrg { 1407a84e134Smrg XtNencoding, 1417a84e134Smrg XtCEncoding, 1427a84e134Smrg XtRUnsignedChar, 1437a84e134Smrg sizeof(unsigned char), 1447a84e134Smrg offset(label.encoding), 1457a84e134Smrg XtRImmediate, 1467a84e134Smrg (XtPointer)XawTextEncoding8bit 1477a84e134Smrg }, 1487a84e134Smrg { 1497a84e134Smrg XtNjustify, 1507a84e134Smrg XtCJustify, 1517a84e134Smrg XtRJustify, 1527a84e134Smrg sizeof(XtJustify), 1537a84e134Smrg offset(label.justify), 1547a84e134Smrg XtRImmediate, 1557a84e134Smrg (XtPointer)XtJustifyCenter 1567a84e134Smrg }, 1577a84e134Smrg { 1587a84e134Smrg XtNinternalWidth, 1597a84e134Smrg XtCWidth, 1607a84e134Smrg XtRDimension, 1617a84e134Smrg sizeof(Dimension), 1627a84e134Smrg offset(label.internal_width), 1637a84e134Smrg XtRImmediate, 1647a84e134Smrg (XtPointer)4 1657a84e134Smrg }, 1667a84e134Smrg { 1677a84e134Smrg XtNinternalHeight, 1687a84e134Smrg XtCHeight, 1697a84e134Smrg XtRDimension, 1707a84e134Smrg sizeof(Dimension), 1717a84e134Smrg offset(label.internal_height), 1727a84e134Smrg XtRImmediate, 1737a84e134Smrg (XtPointer)2 1747a84e134Smrg }, 1757a84e134Smrg { 1767a84e134Smrg XtNleftBitmap, 1777a84e134Smrg XtCLeftBitmap, 1787a84e134Smrg XtRBitmap, 1797a84e134Smrg sizeof(Pixmap), 1807a84e134Smrg offset(label.left_bitmap), 1817a84e134Smrg XtRImmediate, 1827a84e134Smrg (XtPointer)None 1837a84e134Smrg }, 1847a84e134Smrg { 1857a84e134Smrg XtNbitmap, 1867a84e134Smrg XtCPixmap, 1877a84e134Smrg XtRBitmap, 1887a84e134Smrg sizeof(Pixmap), 1897a84e134Smrg offset(label.pixmap), 1907a84e134Smrg XtRImmediate, 1917a84e134Smrg (XtPointer)None 1927a84e134Smrg }, 1937a84e134Smrg { 1947a84e134Smrg XtNresize, 1957a84e134Smrg XtCResize, 1967a84e134Smrg XtRBoolean, 1977a84e134Smrg sizeof(Boolean), 1987a84e134Smrg offset(label.resize), 1997a84e134Smrg XtRImmediate, 2007a84e134Smrg (XtPointer)True 2017a84e134Smrg }, 2027a84e134Smrg { 2037a84e134Smrg XtNlabelX, 2047a84e134Smrg XtCPosition, 2057a84e134Smrg XtRPosition, 2067a84e134Smrg sizeof(Position), 2077a84e134Smrg offset(label.label_x), 2087a84e134Smrg XtRImmediate, 2097a84e134Smrg (XtPointer)0 2107a84e134Smrg }, 2117a84e134Smrg { 2127a84e134Smrg XtNlabelY, 2137a84e134Smrg XtCPosition, 2147a84e134Smrg XtRPosition, 2157a84e134Smrg sizeof(Position), 2167a84e134Smrg offset(label.label_y), 2177a84e134Smrg XtRImmediate, 2187a84e134Smrg (XtPointer)0 2197a84e134Smrg }, 2207a84e134Smrg}; 2217a84e134Smrg#undef offset 2227a84e134Smrg 2237a84e134Smrg#define Superclass (&simpleClassRec) 2247a84e134SmrgLabelClassRec labelClassRec = { 2257a84e134Smrg /* core */ 2267a84e134Smrg { 2277a84e134Smrg (WidgetClass)&simpleClassRec, /* superclass */ 2287a84e134Smrg "Label", /* class_name */ 2297a84e134Smrg sizeof(LabelRec), /* widget_size */ 2307a84e134Smrg XawLabelClassInitialize, /* class_initialize */ 2317a84e134Smrg NULL, /* class_part_initialize */ 2327a84e134Smrg False, /* class_inited */ 2337a84e134Smrg XawLabelInitialize, /* initialize */ 2347a84e134Smrg NULL, /* initialize_hook */ 2357a84e134Smrg XtInheritRealize, /* realize */ 2367a84e134Smrg NULL, /* actions */ 2377a84e134Smrg 0, /* num_actions */ 2387a84e134Smrg resources, /* resources */ 2397a84e134Smrg XtNumber(resources), /* num_resources */ 2407a84e134Smrg NULLQUARK, /* xrm_class */ 2417a84e134Smrg True, /* compress_motion */ 2427a84e134Smrg True, /* compress_exposure */ 2437a84e134Smrg True, /* compress_enterleave */ 2447a84e134Smrg False, /* visible_interest */ 2457a84e134Smrg XawLabelDestroy, /* destroy */ 2467a84e134Smrg XawLabelResize, /* resize */ 2477a84e134Smrg XawLabelRedisplay, /* expose */ 2487a84e134Smrg XawLabelSetValues, /* set_values */ 2497a84e134Smrg NULL, /* set_values_hook */ 2507a84e134Smrg XtInheritSetValuesAlmost, /* set_values_almost */ 2517a84e134Smrg NULL, /* get_values_hook */ 2527a84e134Smrg NULL, /* accept_focus */ 2537a84e134Smrg XtVersion, /* version */ 2547a84e134Smrg NULL, /* callback_private */ 2557a84e134Smrg NULL, /* tm_table */ 2567a84e134Smrg XawLabelQueryGeometry, /* query_geometry */ 2577a84e134Smrg XtInheritDisplayAccelerator, /* display_accelerator */ 2587a84e134Smrg NULL, /* extension */ 2597a84e134Smrg }, 2607a84e134Smrg /* simple */ 2617a84e134Smrg { 2627a84e134Smrg XtInheritChangeSensitive, /* change_sensitive */ 2637a84e134Smrg }, 2647a84e134Smrg /* label */ 2657a84e134Smrg { 2667a84e134Smrg NULL, /* extension */ 2677a84e134Smrg } 2687a84e134Smrg}; 2697a84e134Smrg 2707a84e134SmrgWidgetClass labelWidgetClass = (WidgetClass)&labelClassRec; 2717a84e134Smrg 2727a84e134Smrg/* 2737a84e134Smrg * Implementation 2747a84e134Smrg */ 2757a84e134Smrgstatic void 2767a84e134SmrgXawLabelClassInitialize(void) 2777a84e134Smrg{ 2787a84e134Smrg XawInitializeWidgetSet(); 2797a84e134Smrg XtAddConverter(XtRString, XtRJustify, XmuCvtStringToJustify, NULL, 0); 2807a84e134Smrg XtSetTypeConverter(XtRJustify, XtRString, XmuCvtJustifyToString, 2817a84e134Smrg NULL, 0, XtCacheNone, NULL); 2827a84e134Smrg} 2837a84e134Smrg 2847a84e134Smrg#ifndef WORD64 2857a84e134Smrg#define TXT16 XChar2b 2867a84e134Smrg#else 2877a84e134Smrg#define TXT16 char 2887a84e134Smrg 2897a84e134Smrgstatic XChar2b *buf2b; 2907a84e134Smrgstatic int buf2blen = 0; 2917a84e134Smrg 2927a84e134Smrgstatic int 2937a84e134Smrg_XawLabelWidth16(XFontStruct *fs, char *str, int n) 2947a84e134Smrg{ 2957a84e134Smrg int i; 2967a84e134Smrg XChar2b *ptr; 2977a84e134Smrg 2987a84e134Smrg if (n > buf2blen) { 2997a84e134Smrg buf2b = (XChar2b *)XtRealloc((char *)buf2b, n * sizeof(XChar2b)); 3007a84e134Smrg buf2blen = n; 3017a84e134Smrg } 3027a84e134Smrg for (ptr = buf2b, i = n; --i >= 0; ptr++) { 3037a84e134Smrg ptr->byte1 = *str++; 3047a84e134Smrg ptr->byte2 = *str++; 3057a84e134Smrg } 3067a84e134Smrg 3077a84e134Smrg return (XTextWidth16(fs, buf2b, n)); 3087a84e134Smrg} 3097a84e134Smrg 3107a84e134Smrgstatic void 3117a84e134Smrg_XawLabelDraw16(Display *dpy, Drawable d, GC gc, int x, int y, 3127a84e134Smrg char *str, int n) 3137a84e134Smrg{ 3147a84e134Smrg int i; 3157a84e134Smrg XChar2b *ptr; 3167a84e134Smrg 3177a84e134Smrg if (n > buf2blen) { 3187a84e134Smrg buf2b = (XChar2b *)XtRealloc((char *)buf2b, n * sizeof(XChar2b)); 3197a84e134Smrg buf2blen = n; 3207a84e134Smrg } 3217a84e134Smrg for (ptr = buf2b, i = n; --i >= 0; ptr++) { 3227a84e134Smrg ptr->byte1 = *str++; 3237a84e134Smrg ptr->byte2 = *str++; 3247a84e134Smrg } 3257a84e134Smrg XDrawString16(dpy, d, gc, x, y, buf2b, n); 3267a84e134Smrg} 3277a84e134Smrg 3287a84e134Smrg#define XTextWidth16 _XawLabelWidth16 3297a84e134Smrg#define XDrawString16 _XawLabelDraw16 3307a84e134Smrg#endif /* WORD64 */ 3317a84e134Smrg 3327a84e134Smrg/* 3337a84e134Smrg * Calculate width and height of displayed text in pixels 3347a84e134Smrg */ 3357a84e134Smrgstatic void 3367a84e134SmrgSetTextWidthAndHeight(LabelWidget lw) 3377a84e134Smrg{ 3387a84e134Smrg XFontStruct *fs = lw->label.font; 3397a84e134Smrg char *nl; 3407a84e134Smrg 3417a84e134Smrg if (lw->label.pixmap != None) { 3427a84e134Smrg Window root; 3437a84e134Smrg int x, y; 3447a84e134Smrg unsigned int width, height, bw, depth; 3457a84e134Smrg 3467a84e134Smrg if (XGetGeometry(XtDisplay(lw), lw->label.pixmap, &root, &x, &y, 3477a84e134Smrg &width, &height, &bw, &depth)) { 3487a84e134Smrg lw->label.label_height = height; 3497a84e134Smrg lw->label.label_width = width; 3507a84e134Smrg lw->label.label_len = depth; 3517a84e134Smrg return; 3527a84e134Smrg } 3537a84e134Smrg } 3547a84e134Smrg if (lw->simple.international == True) { 3557a84e134Smrg XFontSet fset = lw->label.fontset; 3567a84e134Smrg XFontSetExtents *ext = XExtentsOfFontSet(fset); 3577a84e134Smrg 3587a84e134Smrg lw->label.label_height = ext->max_ink_extent.height; 3597a84e134Smrg if (lw->label.label == NULL) { 3607a84e134Smrg lw->label.label_len = 0; 3617a84e134Smrg lw->label.label_width = 0; 3627a84e134Smrg } 3637a84e134Smrg else if ((nl = index(lw->label.label, '\n')) != NULL) { 3647a84e134Smrg char *label; 3657a84e134Smrg 3667a84e134Smrg lw->label.label_len = MULTI_LINE_LABEL; 3677a84e134Smrg lw->label.label_width = 0; 3687a84e134Smrg for (label = lw->label.label; nl != NULL; nl = index(label, '\n')) { 3697a84e134Smrg int width = XmbTextEscapement(fset, label, (int)(nl - label)); 3707a84e134Smrg 3717a84e134Smrg if (width > (int)lw->label.label_width) 3727a84e134Smrg lw->label.label_width = width; 3737a84e134Smrg label = nl + 1; 3747a84e134Smrg if (*label) 3757a84e134Smrg lw->label.label_height += ext->max_ink_extent.height; 3767a84e134Smrg } 3777a84e134Smrg if (*label) { 3787a84e134Smrg int width = XmbTextEscapement(fset, label, strlen(label)); 3797a84e134Smrg 3807a84e134Smrg if (width > (int)lw->label.label_width) 3817a84e134Smrg lw->label.label_width = width; 3827a84e134Smrg } 3837a84e134Smrg } 3847a84e134Smrg else { 3857a84e134Smrg lw->label.label_len = strlen(lw->label.label); 3867a84e134Smrg lw->label.label_width = 3877a84e134Smrg XmbTextEscapement(fset, lw->label.label, lw->label.label_len); 3887a84e134Smrg } 3897a84e134Smrg } 3907a84e134Smrg else { 3917a84e134Smrg lw->label.label_height = fs->max_bounds.ascent + fs->max_bounds.descent; 3927a84e134Smrg if (lw->label.label == NULL) { 3937a84e134Smrg lw->label.label_len = 0; 3947a84e134Smrg lw->label.label_width = 0; 3957a84e134Smrg } 3967a84e134Smrg else if ((nl = index(lw->label.label, '\n')) != NULL) { 3977a84e134Smrg char *label; 3987a84e134Smrg 3997a84e134Smrg lw->label.label_len = MULTI_LINE_LABEL; 4007a84e134Smrg lw->label.label_width = 0; 4017a84e134Smrg for (label = lw->label.label; nl != NULL; nl = index(label, '\n')) { 4027a84e134Smrg int width; 4037a84e134Smrg 4047a84e134Smrg if (lw->label.encoding) 4057a84e134Smrg width = XTextWidth16(fs, (TXT16*)label, (int)(nl - label) / 2); 4067a84e134Smrg else 4077a84e134Smrg width = XTextWidth(fs, label, (int)(nl - label)); 4087a84e134Smrg if (width > (int)lw->label.label_width) 4097a84e134Smrg lw->label.label_width = width; 4107a84e134Smrg label = nl + 1; 4117a84e134Smrg if (*label) 4127a84e134Smrg lw->label.label_height += 4137a84e134Smrg fs->max_bounds.ascent + fs->max_bounds.descent; 4147a84e134Smrg } 4157a84e134Smrg if (*label) { 4167a84e134Smrg int width = XTextWidth(fs, label, strlen(label)); 4177a84e134Smrg 4187a84e134Smrg if (lw->label.encoding) 4197a84e134Smrg width = XTextWidth16(fs, (TXT16*)label, strlen(label) / 2); 4207a84e134Smrg else 4217a84e134Smrg width = XTextWidth(fs, label, strlen(label)); 4227a84e134Smrg if (width > (int) lw->label.label_width) 4237a84e134Smrg lw->label.label_width = width; 4247a84e134Smrg } 4257a84e134Smrg } 4267a84e134Smrg else { 4277a84e134Smrg lw->label.label_len = strlen(lw->label.label); 4287a84e134Smrg if (lw->label.encoding) 4297a84e134Smrg lw->label.label_width = 4307a84e134Smrg XTextWidth16(fs, (TXT16*)lw->label.label, 4317a84e134Smrg (int)lw->label.label_len / 2); 4327a84e134Smrg else 4337a84e134Smrg lw->label.label_width = 4347a84e134Smrg XTextWidth(fs, lw->label.label, (int)lw->label.label_len); 4357a84e134Smrg } 4367a84e134Smrg } 4377a84e134Smrg} 4387a84e134Smrg 4397a84e134Smrgstatic void 4407a84e134SmrgGetNormalGC(LabelWidget lw) 4417a84e134Smrg{ 4427a84e134Smrg XGCValues values; 4437a84e134Smrg 4447a84e134Smrg values.foreground = lw->label.foreground; 4457a84e134Smrg values.background = lw->core.background_pixel; 4467a84e134Smrg values.font = lw->label.font->fid; 4477a84e134Smrg values.graphics_exposures = False; 4487a84e134Smrg 4497a84e134Smrg if (lw->simple.international == True) 4507a84e134Smrg /* Since Xmb/wcDrawString eats the font, I must use XtAllocateGC */ 4517a84e134Smrg lw->label.normal_GC = XtAllocateGC((Widget)lw, 0, 4527a84e134Smrg GCForeground | GCBackground | 4537a84e134Smrg GCGraphicsExposures, 4547a84e134Smrg &values, GCFont, 0); 4557a84e134Smrg else 4567a84e134Smrg lw->label.normal_GC = XtGetGC((Widget)lw, 4577a84e134Smrg GCForeground | GCBackground | GCFont | 4587a84e134Smrg GCGraphicsExposures, &values); 4597a84e134Smrg} 4607a84e134Smrg 4617a84e134Smrgstatic void 4627a84e134SmrgGetGrayGC(LabelWidget lw) 4637a84e134Smrg{ 4647a84e134Smrg XGCValues values; 4657a84e134Smrg 4667a84e134Smrg values.foreground = lw->label.foreground; 4677a84e134Smrg values.background = lw->core.background_pixel; 4687a84e134Smrg values.font = lw->label.font->fid; 4697a84e134Smrg values.fill_style = FillTiled; 4707a84e134Smrg values.tile = XmuCreateStippledPixmap(XtScreen((Widget)lw), 471421c997bSmrg lw->label.foreground, 4727a84e134Smrg lw->core.background_pixel, 4737a84e134Smrg lw->core.depth); 4747a84e134Smrg values.graphics_exposures = False; 4757a84e134Smrg 4767a84e134Smrg lw->label.stipple = values.tile; 4777a84e134Smrg if (lw->simple.international == True) 4787a84e134Smrg /* Since Xmb/wcDrawString eats the font, I must use XtAllocateGC */ 4797a84e134Smrg lw->label.gray_GC = XtAllocateGC((Widget)lw, 0, 4807a84e134Smrg GCForeground | GCBackground | 4817a84e134Smrg GCTile | GCFillStyle | 4827a84e134Smrg GCGraphicsExposures, 4837a84e134Smrg &values, GCFont, 0); 4847a84e134Smrg else 485421c997bSmrg lw->label.gray_GC = XtGetGC((Widget)lw, 4867a84e134Smrg GCForeground | GCBackground | 4877a84e134Smrg GCFont | GCTile | GCFillStyle | 4887a84e134Smrg GCGraphicsExposures, 4897a84e134Smrg &values); 4907a84e134Smrg} 4917a84e134Smrg 4927a84e134Smrgstatic void 4937a84e134Smrgcompute_bitmap_offsets(LabelWidget lw) 4947a84e134Smrg{ 4957a84e134Smrg /* 496421c997bSmrg * bitmap will be eventually be displayed at 4977a84e134Smrg * (internal_width, internal_height + lbm_y) 4987a84e134Smrg */ 4997a84e134Smrg if (lw->label.lbm_height != 0) 5007a84e134Smrg lw->label.lbm_y = (XtHeight(lw) - (lw->label.internal_height * 2 + 5017a84e134Smrg lw->label.lbm_height)) / 2; 5027a84e134Smrg else 5037a84e134Smrg lw->label.lbm_y = 0; 5047a84e134Smrg} 5057a84e134Smrg 5067a84e134Smrgstatic void 5077a84e134Smrgset_bitmap_info(LabelWidget lw) 5087a84e134Smrg{ 5097a84e134Smrg Window root; 5107a84e134Smrg int x, y; 5117a84e134Smrg unsigned int bw, depth; 5127a84e134Smrg 5137a84e134Smrg if (!(lw->label.left_bitmap 5147a84e134Smrg && XGetGeometry(XtDisplay(lw), lw->label.left_bitmap, &root, &x, &y, 5157a84e134Smrg &lw->label.lbm_width, &lw->label.lbm_height, 5167a84e134Smrg &bw, &depth))) 5177a84e134Smrg lw->label.lbm_width = lw->label.lbm_height = 0; 5187a84e134Smrg 5197a84e134Smrg compute_bitmap_offsets(lw); 5207a84e134Smrg} 5217a84e134Smrg 5227a84e134Smrg/*ARGSUSED*/ 5237a84e134Smrgstatic void 5247a84e134SmrgXawLabelInitialize(Widget request, Widget cnew, 5257a84e134Smrg ArgList args, Cardinal *num_args) 5267a84e134Smrg{ 5277a84e134Smrg LabelWidget lw = (LabelWidget)cnew; 5287a84e134Smrg 5297a84e134Smrg if (!lw->label.font) XtError("Aborting: no font found\n"); 530421c997bSmrg if (lw->simple.international && !lw->label.fontset) 5317a84e134Smrg XtError("Aborting: no fontset found\n"); 532421c997bSmrg 533421c997bSmrg if (lw->label.label == NULL) 5347a84e134Smrg lw->label.label = XtNewString(lw->core.name); 5357a84e134Smrg else 5367a84e134Smrg lw->label.label = XtNewString(lw->label.label); 5377a84e134Smrg 5387a84e134Smrg GetNormalGC(lw); 5397a84e134Smrg GetGrayGC(lw); 5407a84e134Smrg 5417a84e134Smrg SetTextWidthAndHeight(lw); 5427a84e134Smrg 5437a84e134Smrg if (XtHeight(lw) == 0) 5447a84e134Smrg XtHeight(lw) = lw->label.label_height + 2 * lw->label.internal_height; 5457a84e134Smrg 5467a84e134Smrg set_bitmap_info(lw); /* need core.height */ 5477a84e134Smrg 5487a84e134Smrg if (XtWidth(lw) == 0) /* need label.lbm_width */ 5497a84e134Smrg XtWidth(lw) = lw->label.label_width + 2 * lw->label.internal_width + 5507a84e134Smrg LEFT_OFFSET(lw); 5517a84e134Smrg 5527a84e134Smrg lw->label.label_x = lw->label.label_y = 0; 5537a84e134Smrg (*XtClass(cnew)->core_class.resize)((Widget)lw); 5547a84e134Smrg} 5557a84e134Smrg 5567a84e134Smrg/*ARGSUSED*/ 5577a84e134Smrgstatic void 5587a84e134SmrgXawLabelRedisplay(Widget gw, XEvent *event, Region region) 5597a84e134Smrg{ 5607a84e134Smrg LabelWidget w = (LabelWidget)gw; 5617a84e134Smrg GC gc; 5627a84e134Smrg 5637a84e134Smrg if (*Superclass->core_class.expose != NULL) 5647a84e134Smrg (*Superclass->core_class.expose)(gw, event, region); 5657a84e134Smrg 5667a84e134Smrg gc = XtIsSensitive(gw) ? w->label.normal_GC : w->label.gray_GC; 5677a84e134Smrg#ifdef notdef 5687a84e134Smrg if (region != NULL) 5697a84e134Smrg XSetRegion(XtDisplay(gw), gc, region); 5707a84e134Smrg#endif /*notdef*/ 5717a84e134Smrg 5727a84e134Smrg if (w->label.pixmap == None) { 5737a84e134Smrg int len = w->label.label_len; 5747a84e134Smrg char *label = w->label.label; 5757a84e134Smrg Position y = w->label.label_y + w->label.font->max_bounds.ascent; 5767a84e134Smrg Position ksy = w->label.label_y; 5777a84e134Smrg 5787a84e134Smrg /* display left bitmap */ 5797a84e134Smrg if (w->label.left_bitmap && w->label.lbm_width != 0) 5807a84e134Smrg XCopyPlane (XtDisplay(gw), w->label.left_bitmap, XtWindow(gw), gc, 5817a84e134Smrg 0, 0, w->label.lbm_width, w->label.lbm_height, 5827a84e134Smrg w->label.internal_width, 5837a84e134Smrg w->label.internal_height + w->label.lbm_y, 1L); 5847a84e134Smrg 5857a84e134Smrg if (w->simple.international == True) { 5867a84e134Smrg XFontSetExtents *ext = XExtentsOfFontSet(w->label.fontset); 5877a84e134Smrg 5887a84e134Smrg ksy += XawAbs(ext->max_ink_extent.y); 5897a84e134Smrg 5907a84e134Smrg if (len == MULTI_LINE_LABEL) { 5917a84e134Smrg char *nl; 5927a84e134Smrg 5937a84e134Smrg while ((nl = index(label, '\n')) != NULL) { 5947a84e134Smrg XmbDrawString(XtDisplay(w), XtWindow(w), w->label.fontset, 5957a84e134Smrg gc, w->label.label_x, ksy, label, 5967a84e134Smrg (int)(nl - label)); 5977a84e134Smrg ksy += ext->max_ink_extent.height; 5987a84e134Smrg label = nl + 1; 5997a84e134Smrg } 6007a84e134Smrg len = strlen(label); 6017a84e134Smrg } 6027a84e134Smrg if (len) 6037a84e134Smrg XmbDrawString(XtDisplay(w), XtWindow(w), w->label.fontset, gc, 6047a84e134Smrg w->label.label_x, ksy, label, len); 6057a84e134Smrg } 6067a84e134Smrg else { 6077a84e134Smrg if (len == MULTI_LINE_LABEL) { 6087a84e134Smrg char *nl; 6097a84e134Smrg 6107a84e134Smrg while ((nl = index(label, '\n')) != NULL) { 6117a84e134Smrg if (w->label.encoding) 6127a84e134Smrg XDrawString16(XtDisplay(gw), XtWindow(gw), gc, 6137a84e134Smrg w->label.label_x, y, 6147a84e134Smrg (TXT16*)label, (int)(nl - label) / 2); 6157a84e134Smrg else 6167a84e134Smrg XDrawString(XtDisplay(gw), XtWindow(gw), gc, 6177a84e134Smrg w->label.label_x, y, label, (int)(nl - label)); 618421c997bSmrg y += w->label.font->max_bounds.ascent + 6197a84e134Smrg w->label.font->max_bounds.descent; 6207a84e134Smrg label = nl + 1; 6217a84e134Smrg } 6227a84e134Smrg len = strlen(label); 6237a84e134Smrg } 6247a84e134Smrg if (len) { 6257a84e134Smrg if (w->label.encoding) 6267a84e134Smrg XDrawString16(XtDisplay(gw), XtWindow(gw), gc, 6277a84e134Smrg w->label.label_x, y, (TXT16*)label, len / 2); 6287a84e134Smrg else 6297a84e134Smrg XDrawString(XtDisplay(gw), XtWindow(gw), gc, 6307a84e134Smrg w->label.label_x, y, label, len); 6317a84e134Smrg } 6327a84e134Smrg } 6337a84e134Smrg } 6347a84e134Smrg else if (w->label.label_len == 1) 6357a84e134Smrg XCopyPlane(XtDisplay(gw), w->label.pixmap, XtWindow(gw), gc, 6367a84e134Smrg 0, 0, w->label.label_width, w->label.label_height, 6377a84e134Smrg w->label.label_x, w->label.label_y, 1L); 6387a84e134Smrg else 6397a84e134Smrg XCopyArea(XtDisplay(gw), w->label.pixmap, XtWindow(gw), gc, 6407a84e134Smrg 0, 0, w->label.label_width, w->label.label_height, 6417a84e134Smrg w->label.label_x, w->label.label_y); 6427a84e134Smrg 6437a84e134Smrg#ifdef notdef 6447a84e134Smrg if (region != NULL) 6457a84e134Smrg XSetClipMask(XtDisplay(gw), gc, (Pixmap)None); 6467a84e134Smrg#endif /* notdef */ 6477a84e134Smrg} 6487a84e134Smrg 6497a84e134Smrgstatic void 6507a84e134Smrg_Reposition(LabelWidget lw, unsigned int width, unsigned int height, 6517a84e134Smrg Position *dx, Position *dy) 6527a84e134Smrg{ 6537a84e134Smrg Position newPos; 6547a84e134Smrg Position leftedge = lw->label.internal_width + LEFT_OFFSET(lw); 6557a84e134Smrg 6567a84e134Smrg switch (lw->label.justify) { 6577a84e134Smrg case XtJustifyLeft: 6587a84e134Smrg newPos = leftedge; 6597a84e134Smrg break; 6607a84e134Smrg case XtJustifyRight: 6617a84e134Smrg newPos = width - (lw->label.label_width + lw->label.internal_width); 6627a84e134Smrg break; 6637a84e134Smrg case XtJustifyCenter: 6647a84e134Smrg /*FALLTRHOUGH*/ 6657a84e134Smrg default: 6667a84e134Smrg newPos = (int)(width - lw->label.label_width) >> 1; 6677a84e134Smrg break; 6687a84e134Smrg } 6697a84e134Smrg if (newPos < (Position)leftedge) 6707a84e134Smrg newPos = leftedge; 6717a84e134Smrg *dx = newPos - lw->label.label_x; 6727a84e134Smrg lw->label.label_x = newPos; 6737a84e134Smrg 6747a84e134Smrg newPos = (height - lw->label.label_height) >> 1; 6757a84e134Smrg *dy = newPos - lw->label.label_y; 6767a84e134Smrg lw->label.label_y = newPos; 6777a84e134Smrg} 6787a84e134Smrg 6797a84e134Smrgstatic void 6807a84e134SmrgXawLabelResize(Widget w) 6817a84e134Smrg{ 6827a84e134Smrg LabelWidget lw = (LabelWidget)w; 6837a84e134Smrg Position dx, dy; 6847a84e134Smrg 6857a84e134Smrg _Reposition(lw, XtWidth(w), XtHeight(w), &dx, &dy); 6867a84e134Smrg compute_bitmap_offsets(lw); 6877a84e134Smrg} 6887a84e134Smrg 6897a84e134Smrg#define PIXMAP 0 6907a84e134Smrg#define WIDTH 1 6917a84e134Smrg#define HEIGHT 2 6927a84e134Smrg#define NUM_CHECKS 3 6937a84e134Smrgstatic Boolean 6947a84e134SmrgXawLabelSetValues(Widget current, Widget request, Widget cnew, 6957a84e134Smrg ArgList args, Cardinal *num_args) 6967a84e134Smrg{ 6977a84e134Smrg LabelWidget curlw = (LabelWidget)current; 6987a84e134Smrg LabelWidget reqlw = (LabelWidget)request; 6997a84e134Smrg LabelWidget newlw = (LabelWidget)cnew; 7007a84e134Smrg unsigned int i; 7017a84e134Smrg Boolean was_resized = False, redisplay = False, checks[NUM_CHECKS]; 7027a84e134Smrg 7037a84e134Smrg for (i = 0; i < NUM_CHECKS; i++) 7047a84e134Smrg checks[i] = False; 7057a84e134Smrg 7067a84e134Smrg for (i = 0; i < *num_args; i++) { 7077a84e134Smrg if (streq(XtNbitmap, args[i].name)) 7087a84e134Smrg checks[PIXMAP] = True; 7097a84e134Smrg else if (streq(XtNwidth, args[i].name)) 7107a84e134Smrg checks[WIDTH] = True; 7117a84e134Smrg else if (streq(XtNheight, args[i].name)) 7127a84e134Smrg checks[HEIGHT] = True; 7137a84e134Smrg } 7147a84e134Smrg 7157a84e134Smrg if (newlw->label.label == NULL) 7167a84e134Smrg newlw->label.label = newlw->core.name; 7177a84e134Smrg 7187a84e134Smrg /* 7197a84e134Smrg * resize on bitmap change 7207a84e134Smrg */ 7217a84e134Smrg if (curlw->label.left_bitmap != newlw->label.left_bitmap) 7227a84e134Smrg was_resized = True; 7237a84e134Smrg 7247a84e134Smrg if (curlw->label.encoding != newlw->label.encoding) 7257a84e134Smrg was_resized = True; 7267a84e134Smrg 727421c997bSmrg if (curlw->simple.international 7287a84e134Smrg && curlw->label.fontset != newlw->label.fontset) 7297a84e134Smrg was_resized = True; 7307a84e134Smrg 7317a84e134Smrg if (curlw->label.label != newlw->label.label) { 7327a84e134Smrg if (curlw->label.label != curlw->core.name) 7337a84e134Smrg XtFree((char *)curlw->label.label); 7347a84e134Smrg 7357a84e134Smrg if (newlw->label.label != newlw->core.name) 7367a84e134Smrg newlw->label.label = XtNewString(newlw->label.label); 7377a84e134Smrg 7387a84e134Smrg was_resized = True; 7397a84e134Smrg } 7407a84e134Smrg 7417a84e134Smrg if (was_resized || (curlw->label.font != newlw->label.font) || 7427a84e134Smrg curlw->label.justify != newlw->label.justify || checks[PIXMAP]) { 7437a84e134Smrg SetTextWidthAndHeight(newlw); 7447a84e134Smrg was_resized = True; 7457a84e134Smrg } 7467a84e134Smrg 7477a84e134Smrg /* recalculate the window size if something has changed */ 7487a84e134Smrg if (newlw->label.resize && was_resized) { 7497a84e134Smrg if (XtHeight(curlw) == XtHeight(reqlw) && !checks[HEIGHT]) 7507a84e134Smrg XtHeight(newlw) = newlw->label.label_height + 7517a84e134Smrg (newlw->label.internal_height << 1); 7527a84e134Smrg 7537a84e134Smrg set_bitmap_info(newlw); 7547a84e134Smrg 7557a84e134Smrg if (XtWidth(curlw) == XtWidth(reqlw) && !checks[WIDTH]) 7567a84e134Smrg XtWidth(newlw) = newlw->label.label_width + LEFT_OFFSET(newlw) + 7577a84e134Smrg (newlw->label.internal_width << 1); 7587a84e134Smrg } 7597a84e134Smrg 7607a84e134Smrg if (curlw->label.foreground != newlw->label.foreground 7617a84e134Smrg || curlw->core.background_pixel != newlw->core.background_pixel 7627a84e134Smrg || curlw->label.font->fid != newlw->label.font->fid) { 7637a84e134Smrg /* The Fontset is not in the GC - don't make a new GC if FS changes! */ 7647a84e134Smrg XtReleaseGC(cnew, curlw->label.normal_GC); 7657a84e134Smrg XtReleaseGC(cnew, curlw->label.gray_GC); 7667a84e134Smrg XmuReleaseStippledPixmap(XtScreen(current), curlw->label.stipple); 7677a84e134Smrg GetNormalGC(newlw); 7687a84e134Smrg GetGrayGC(newlw); 7697a84e134Smrg redisplay = True; 7707a84e134Smrg } 7717a84e134Smrg 7727a84e134Smrg if (curlw->label.label_x != newlw->label.label_x || 7737a84e134Smrg curlw->label.label_y != newlw->label.label_y) 7747a84e134Smrg redisplay = True; 7757a84e134Smrg 7767a84e134Smrg if (curlw->label.internal_width != newlw->label.internal_width 7777a84e134Smrg || curlw->label.internal_height != newlw->label.internal_height 7787a84e134Smrg || was_resized) { 7797a84e134Smrg /* Resize() will be called if geometry changes succeed */ 7807a84e134Smrg Position dx, dy; 7817a84e134Smrg 7827a84e134Smrg _Reposition(newlw, XtWidth(curlw), XtHeight(curlw), &dx, &dy); 7837a84e134Smrg } 7847a84e134Smrg 7857a84e134Smrg return (was_resized || redisplay || 7867a84e134Smrg XtIsSensitive(current) != XtIsSensitive(cnew)); 7877a84e134Smrg} 7887a84e134Smrg 7897a84e134Smrgstatic void 7907a84e134SmrgXawLabelDestroy(Widget w) 7917a84e134Smrg{ 7927a84e134Smrg LabelWidget lw = (LabelWidget)w; 7937a84e134Smrg 7947a84e134Smrg if (lw->label.label != lw->core.name) 7957a84e134Smrg XtFree(lw->label.label); 7967a84e134Smrg XtReleaseGC(w, lw->label.normal_GC); 7977a84e134Smrg XtReleaseGC(w, lw->label.gray_GC); 7987a84e134Smrg XmuReleaseStippledPixmap(XtScreen(w), lw->label.stipple); 7997a84e134Smrg} 8007a84e134Smrg 8017a84e134Smrgstatic XtGeometryResult 8027a84e134SmrgXawLabelQueryGeometry(Widget w, XtWidgetGeometry *intended, 8037a84e134Smrg XtWidgetGeometry *preferred) 8047a84e134Smrg{ 8057a84e134Smrg LabelWidget lw = (LabelWidget)w; 8067a84e134Smrg 8077a84e134Smrg preferred->request_mode = CWWidth | CWHeight; 8087a84e134Smrg preferred->width = lw->label.label_width + 8097a84e134Smrg (lw->label.internal_width << 1) + LEFT_OFFSET(lw); 8107a84e134Smrg preferred->height = lw->label.label_height + 8117a84e134Smrg (lw->label.internal_height << 1); 8127a84e134Smrg 8137a84e134Smrg if (((intended->request_mode & (CWWidth | CWHeight)) == (CWWidth | CWHeight)) 8147a84e134Smrg && intended->width == preferred->width 8157a84e134Smrg && intended->height == preferred->height) 8167a84e134Smrg return (XtGeometryYes); 8177a84e134Smrg else if (preferred->width == XtWidth(w) && preferred->height == XtHeight(w)) 8187a84e134Smrg return (XtGeometryNo); 8197a84e134Smrg 8207a84e134Smrg return (XtGeometryAlmost); 8217a84e134Smrg} 822