Label.c revision c889a3bf
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 677a84e134Smrg/* 687a84e134Smrg * Class Methods 697a84e134Smrg */ 707a84e134Smrgstatic void XawLabelClassInitialize(void); 717a84e134Smrgstatic void XawLabelDestroy(Widget); 727a84e134Smrgstatic void XawLabelInitialize(Widget, Widget, ArgList, Cardinal*); 737a84e134Smrgstatic XtGeometryResult XawLabelQueryGeometry(Widget, XtWidgetGeometry*, 747a84e134Smrg XtWidgetGeometry*); 757a84e134Smrgstatic void XawLabelRedisplay(Widget, XEvent*, Region); 767a84e134Smrgstatic void XawLabelResize(Widget); 777a84e134Smrgstatic Boolean XawLabelSetValues(Widget, Widget, Widget, 787a84e134Smrg ArgList, Cardinal*); 797a84e134Smrg 807a84e134Smrg/* 817a84e134Smrg * Prototypes 827a84e134Smrg */ 837a84e134Smrgstatic void compute_bitmap_offsets(LabelWidget); 847a84e134Smrgstatic void GetGrayGC(LabelWidget); 857a84e134Smrgstatic void GetNormalGC(LabelWidget); 867a84e134Smrgstatic void _Reposition(LabelWidget, unsigned int, unsigned int, 877a84e134Smrg Position*, Position*); 887a84e134Smrgstatic void set_bitmap_info(LabelWidget); 897a84e134Smrgstatic void SetTextWidthAndHeight(LabelWidget); 907a84e134Smrg 917a84e134Smrg/* 927a84e134Smrg * Initialization 937a84e134Smrg */ 947a84e134Smrg#define offset(field) XtOffsetOf(LabelRec, field) 957a84e134Smrgstatic XtResource resources[] = { 967a84e134Smrg { 977a84e134Smrg XtNforeground, 987a84e134Smrg XtCForeground, 997a84e134Smrg XtRPixel, 1007a84e134Smrg sizeof(Pixel), 1017a84e134Smrg offset(label.foreground), 1027a84e134Smrg XtRString, 1037a84e134Smrg XtDefaultForeground 1047a84e134Smrg }, 1057a84e134Smrg { 1067a84e134Smrg XtNfont, 1077a84e134Smrg XtCFont, 1087a84e134Smrg XtRFontStruct, 1097a84e134Smrg sizeof(XFontStruct*), 1107a84e134Smrg offset(label.font), 1117a84e134Smrg XtRString, 1127a84e134Smrg XtDefaultFont 1137a84e134Smrg }, 1147a84e134Smrg { 1157a84e134Smrg XtNfontSet, 1167a84e134Smrg XtCFontSet, 1177a84e134Smrg XtRFontSet, 1187a84e134Smrg sizeof(XFontSet), 1197a84e134Smrg offset(label.fontset), 1207a84e134Smrg XtRString, 1217a84e134Smrg XtDefaultFontSet 1227a84e134Smrg }, 1237a84e134Smrg { 1247a84e134Smrg XtNlabel, 1257a84e134Smrg XtCLabel, 1267a84e134Smrg XtRString, 1277a84e134Smrg sizeof(String), 1287a84e134Smrg offset(label.label), 1297a84e134Smrg XtRString, 1307a84e134Smrg NULL 1317a84e134Smrg }, 1327a84e134Smrg { 1337a84e134Smrg XtNencoding, 1347a84e134Smrg XtCEncoding, 1357a84e134Smrg XtRUnsignedChar, 1367a84e134Smrg sizeof(unsigned char), 1377a84e134Smrg offset(label.encoding), 1387a84e134Smrg XtRImmediate, 1397a84e134Smrg (XtPointer)XawTextEncoding8bit 1407a84e134Smrg }, 1417a84e134Smrg { 1427a84e134Smrg XtNjustify, 1437a84e134Smrg XtCJustify, 1447a84e134Smrg XtRJustify, 1457a84e134Smrg sizeof(XtJustify), 1467a84e134Smrg offset(label.justify), 1477a84e134Smrg XtRImmediate, 1487a84e134Smrg (XtPointer)XtJustifyCenter 1497a84e134Smrg }, 1507a84e134Smrg { 1517a84e134Smrg XtNinternalWidth, 1527a84e134Smrg XtCWidth, 1537a84e134Smrg XtRDimension, 1547a84e134Smrg sizeof(Dimension), 1557a84e134Smrg offset(label.internal_width), 1567a84e134Smrg XtRImmediate, 1577a84e134Smrg (XtPointer)4 1587a84e134Smrg }, 1597a84e134Smrg { 1607a84e134Smrg XtNinternalHeight, 1617a84e134Smrg XtCHeight, 1627a84e134Smrg XtRDimension, 1637a84e134Smrg sizeof(Dimension), 1647a84e134Smrg offset(label.internal_height), 1657a84e134Smrg XtRImmediate, 1667a84e134Smrg (XtPointer)2 1677a84e134Smrg }, 1687a84e134Smrg { 1697a84e134Smrg XtNleftBitmap, 1707a84e134Smrg XtCLeftBitmap, 1717a84e134Smrg XtRBitmap, 1727a84e134Smrg sizeof(Pixmap), 1737a84e134Smrg offset(label.left_bitmap), 1747a84e134Smrg XtRImmediate, 1757a84e134Smrg (XtPointer)None 1767a84e134Smrg }, 1777a84e134Smrg { 1787a84e134Smrg XtNbitmap, 1797a84e134Smrg XtCPixmap, 1807a84e134Smrg XtRBitmap, 1817a84e134Smrg sizeof(Pixmap), 1827a84e134Smrg offset(label.pixmap), 1837a84e134Smrg XtRImmediate, 1847a84e134Smrg (XtPointer)None 1857a84e134Smrg }, 1867a84e134Smrg { 1877a84e134Smrg XtNresize, 1887a84e134Smrg XtCResize, 1897a84e134Smrg XtRBoolean, 1907a84e134Smrg sizeof(Boolean), 1917a84e134Smrg offset(label.resize), 1927a84e134Smrg XtRImmediate, 1937a84e134Smrg (XtPointer)True 1947a84e134Smrg }, 1957a84e134Smrg { 1967a84e134Smrg XtNlabelX, 1977a84e134Smrg XtCPosition, 1987a84e134Smrg XtRPosition, 1997a84e134Smrg sizeof(Position), 2007a84e134Smrg offset(label.label_x), 2017a84e134Smrg XtRImmediate, 2027a84e134Smrg (XtPointer)0 2037a84e134Smrg }, 2047a84e134Smrg { 2057a84e134Smrg XtNlabelY, 2067a84e134Smrg XtCPosition, 2077a84e134Smrg XtRPosition, 2087a84e134Smrg sizeof(Position), 2097a84e134Smrg offset(label.label_y), 2107a84e134Smrg XtRImmediate, 2117a84e134Smrg (XtPointer)0 2127a84e134Smrg }, 2137a84e134Smrg}; 2147a84e134Smrg#undef offset 2157a84e134Smrg 2167a84e134Smrg#define Superclass (&simpleClassRec) 2177a84e134SmrgLabelClassRec labelClassRec = { 2187a84e134Smrg /* core */ 2197a84e134Smrg { 2207a84e134Smrg (WidgetClass)&simpleClassRec, /* superclass */ 2217a84e134Smrg "Label", /* class_name */ 2227a84e134Smrg sizeof(LabelRec), /* widget_size */ 2237a84e134Smrg XawLabelClassInitialize, /* class_initialize */ 2247a84e134Smrg NULL, /* class_part_initialize */ 2257a84e134Smrg False, /* class_inited */ 2267a84e134Smrg XawLabelInitialize, /* initialize */ 2277a84e134Smrg NULL, /* initialize_hook */ 2287a84e134Smrg XtInheritRealize, /* realize */ 2297a84e134Smrg NULL, /* actions */ 2307a84e134Smrg 0, /* num_actions */ 2317a84e134Smrg resources, /* resources */ 2327a84e134Smrg XtNumber(resources), /* num_resources */ 2337a84e134Smrg NULLQUARK, /* xrm_class */ 2347a84e134Smrg True, /* compress_motion */ 2357a84e134Smrg True, /* compress_exposure */ 2367a84e134Smrg True, /* compress_enterleave */ 2377a84e134Smrg False, /* visible_interest */ 2387a84e134Smrg XawLabelDestroy, /* destroy */ 2397a84e134Smrg XawLabelResize, /* resize */ 2407a84e134Smrg XawLabelRedisplay, /* expose */ 2417a84e134Smrg XawLabelSetValues, /* set_values */ 2427a84e134Smrg NULL, /* set_values_hook */ 2437a84e134Smrg XtInheritSetValuesAlmost, /* set_values_almost */ 2447a84e134Smrg NULL, /* get_values_hook */ 2457a84e134Smrg NULL, /* accept_focus */ 2467a84e134Smrg XtVersion, /* version */ 2477a84e134Smrg NULL, /* callback_private */ 2487a84e134Smrg NULL, /* tm_table */ 2497a84e134Smrg XawLabelQueryGeometry, /* query_geometry */ 2507a84e134Smrg XtInheritDisplayAccelerator, /* display_accelerator */ 2517a84e134Smrg NULL, /* extension */ 2527a84e134Smrg }, 2537a84e134Smrg /* simple */ 2547a84e134Smrg { 2557a84e134Smrg XtInheritChangeSensitive, /* change_sensitive */ 2567a84e134Smrg }, 2577a84e134Smrg /* label */ 2587a84e134Smrg { 2597a84e134Smrg NULL, /* extension */ 2607a84e134Smrg } 2617a84e134Smrg}; 2627a84e134Smrg 2637a84e134SmrgWidgetClass labelWidgetClass = (WidgetClass)&labelClassRec; 2647a84e134Smrg 2657a84e134Smrg/* 2667a84e134Smrg * Implementation 2677a84e134Smrg */ 2687a84e134Smrgstatic void 2697a84e134SmrgXawLabelClassInitialize(void) 2707a84e134Smrg{ 2717a84e134Smrg XawInitializeWidgetSet(); 2727a84e134Smrg XtAddConverter(XtRString, XtRJustify, XmuCvtStringToJustify, NULL, 0); 2737a84e134Smrg XtSetTypeConverter(XtRJustify, XtRString, XmuCvtJustifyToString, 2747a84e134Smrg NULL, 0, XtCacheNone, NULL); 2757a84e134Smrg} 2767a84e134Smrg 2777a84e134Smrg/* 2787a84e134Smrg * Calculate width and height of displayed text in pixels 2797a84e134Smrg */ 2807a84e134Smrgstatic void 2817a84e134SmrgSetTextWidthAndHeight(LabelWidget lw) 2827a84e134Smrg{ 2837a84e134Smrg XFontStruct *fs = lw->label.font; 2847a84e134Smrg char *nl; 2857a84e134Smrg 2867a84e134Smrg if (lw->label.pixmap != None) { 2877a84e134Smrg Window root; 2887a84e134Smrg int x, y; 2897a84e134Smrg unsigned int width, height, bw, depth; 2907a84e134Smrg 2917a84e134Smrg if (XGetGeometry(XtDisplay(lw), lw->label.pixmap, &root, &x, &y, 2927a84e134Smrg &width, &height, &bw, &depth)) { 2937a84e134Smrg lw->label.label_height = height; 2947a84e134Smrg lw->label.label_width = width; 2957a84e134Smrg lw->label.label_len = depth; 2967a84e134Smrg return; 2977a84e134Smrg } 2987a84e134Smrg } 2997a84e134Smrg if (lw->simple.international == True) { 3007a84e134Smrg XFontSet fset = lw->label.fontset; 3017a84e134Smrg XFontSetExtents *ext = XExtentsOfFontSet(fset); 3027a84e134Smrg 3037a84e134Smrg lw->label.label_height = ext->max_ink_extent.height; 3047a84e134Smrg if (lw->label.label == NULL) { 3057a84e134Smrg lw->label.label_len = 0; 3067a84e134Smrg lw->label.label_width = 0; 3077a84e134Smrg } 3087a84e134Smrg else if ((nl = index(lw->label.label, '\n')) != NULL) { 3097a84e134Smrg char *label; 3107a84e134Smrg 3117a84e134Smrg lw->label.label_len = MULTI_LINE_LABEL; 3127a84e134Smrg lw->label.label_width = 0; 3137a84e134Smrg for (label = lw->label.label; nl != NULL; nl = index(label, '\n')) { 3147a84e134Smrg int width = XmbTextEscapement(fset, label, (int)(nl - label)); 3157a84e134Smrg 3167a84e134Smrg if (width > (int)lw->label.label_width) 3177a84e134Smrg lw->label.label_width = width; 3187a84e134Smrg label = nl + 1; 3197a84e134Smrg if (*label) 3207a84e134Smrg lw->label.label_height += ext->max_ink_extent.height; 3217a84e134Smrg } 3227a84e134Smrg if (*label) { 3237a84e134Smrg int width = XmbTextEscapement(fset, label, strlen(label)); 3247a84e134Smrg 3257a84e134Smrg if (width > (int)lw->label.label_width) 3267a84e134Smrg lw->label.label_width = width; 3277a84e134Smrg } 3287a84e134Smrg } 3297a84e134Smrg else { 3307a84e134Smrg lw->label.label_len = strlen(lw->label.label); 3317a84e134Smrg lw->label.label_width = 3327a84e134Smrg XmbTextEscapement(fset, lw->label.label, lw->label.label_len); 3337a84e134Smrg } 3347a84e134Smrg } 3357a84e134Smrg else { 3367a84e134Smrg lw->label.label_height = fs->max_bounds.ascent + fs->max_bounds.descent; 3377a84e134Smrg if (lw->label.label == NULL) { 3387a84e134Smrg lw->label.label_len = 0; 3397a84e134Smrg lw->label.label_width = 0; 3407a84e134Smrg } 3417a84e134Smrg else if ((nl = index(lw->label.label, '\n')) != NULL) { 3427a84e134Smrg char *label; 3437a84e134Smrg 3447a84e134Smrg lw->label.label_len = MULTI_LINE_LABEL; 3457a84e134Smrg lw->label.label_width = 0; 3467a84e134Smrg for (label = lw->label.label; nl != NULL; nl = index(label, '\n')) { 3477a84e134Smrg int width; 3487a84e134Smrg 3497a84e134Smrg if (lw->label.encoding) 350c889a3bfSmrg width = XTextWidth16(fs, (XChar2b *)label, (int)(nl - label) / 2); 3517a84e134Smrg else 3527a84e134Smrg width = XTextWidth(fs, label, (int)(nl - label)); 3537a84e134Smrg if (width > (int)lw->label.label_width) 3547a84e134Smrg lw->label.label_width = width; 3557a84e134Smrg label = nl + 1; 3567a84e134Smrg if (*label) 3577a84e134Smrg lw->label.label_height += 3587a84e134Smrg fs->max_bounds.ascent + fs->max_bounds.descent; 3597a84e134Smrg } 3607a84e134Smrg if (*label) { 3617a84e134Smrg int width = XTextWidth(fs, label, strlen(label)); 3627a84e134Smrg 3637a84e134Smrg if (lw->label.encoding) 364c889a3bfSmrg width = XTextWidth16(fs, (XChar2b *)label, strlen(label) / 2); 3657a84e134Smrg else 3667a84e134Smrg width = XTextWidth(fs, label, strlen(label)); 3677a84e134Smrg if (width > (int) lw->label.label_width) 3687a84e134Smrg lw->label.label_width = width; 3697a84e134Smrg } 3707a84e134Smrg } 3717a84e134Smrg else { 3727a84e134Smrg lw->label.label_len = strlen(lw->label.label); 3737a84e134Smrg if (lw->label.encoding) 3747a84e134Smrg lw->label.label_width = 375c889a3bfSmrg XTextWidth16(fs, (XChar2b *)lw->label.label, 3767a84e134Smrg (int)lw->label.label_len / 2); 3777a84e134Smrg else 3787a84e134Smrg lw->label.label_width = 3797a84e134Smrg XTextWidth(fs, lw->label.label, (int)lw->label.label_len); 3807a84e134Smrg } 3817a84e134Smrg } 3827a84e134Smrg} 3837a84e134Smrg 3847a84e134Smrgstatic void 3857a84e134SmrgGetNormalGC(LabelWidget lw) 3867a84e134Smrg{ 3877a84e134Smrg XGCValues values; 3887a84e134Smrg 3897a84e134Smrg values.foreground = lw->label.foreground; 3907a84e134Smrg values.background = lw->core.background_pixel; 3917a84e134Smrg values.font = lw->label.font->fid; 3927a84e134Smrg values.graphics_exposures = False; 3937a84e134Smrg 3947a84e134Smrg if (lw->simple.international == True) 3957a84e134Smrg /* Since Xmb/wcDrawString eats the font, I must use XtAllocateGC */ 3967a84e134Smrg lw->label.normal_GC = XtAllocateGC((Widget)lw, 0, 3977a84e134Smrg GCForeground | GCBackground | 3987a84e134Smrg GCGraphicsExposures, 3997a84e134Smrg &values, GCFont, 0); 4007a84e134Smrg else 4017a84e134Smrg lw->label.normal_GC = XtGetGC((Widget)lw, 4027a84e134Smrg GCForeground | GCBackground | GCFont | 4037a84e134Smrg GCGraphicsExposures, &values); 4047a84e134Smrg} 4057a84e134Smrg 4067a84e134Smrgstatic void 4077a84e134SmrgGetGrayGC(LabelWidget lw) 4087a84e134Smrg{ 4097a84e134Smrg XGCValues values; 4107a84e134Smrg 4117a84e134Smrg values.foreground = lw->label.foreground; 4127a84e134Smrg values.background = lw->core.background_pixel; 4137a84e134Smrg values.font = lw->label.font->fid; 4147a84e134Smrg values.fill_style = FillTiled; 4157a84e134Smrg values.tile = XmuCreateStippledPixmap(XtScreen((Widget)lw), 416421c997bSmrg lw->label.foreground, 4177a84e134Smrg lw->core.background_pixel, 4187a84e134Smrg lw->core.depth); 4197a84e134Smrg values.graphics_exposures = False; 4207a84e134Smrg 4217a84e134Smrg lw->label.stipple = values.tile; 4227a84e134Smrg if (lw->simple.international == True) 4237a84e134Smrg /* Since Xmb/wcDrawString eats the font, I must use XtAllocateGC */ 4247a84e134Smrg lw->label.gray_GC = XtAllocateGC((Widget)lw, 0, 4257a84e134Smrg GCForeground | GCBackground | 4267a84e134Smrg GCTile | GCFillStyle | 4277a84e134Smrg GCGraphicsExposures, 4287a84e134Smrg &values, GCFont, 0); 4297a84e134Smrg else 430421c997bSmrg lw->label.gray_GC = XtGetGC((Widget)lw, 4317a84e134Smrg GCForeground | GCBackground | 4327a84e134Smrg GCFont | GCTile | GCFillStyle | 4337a84e134Smrg GCGraphicsExposures, 4347a84e134Smrg &values); 4357a84e134Smrg} 4367a84e134Smrg 4377a84e134Smrgstatic void 4387a84e134Smrgcompute_bitmap_offsets(LabelWidget lw) 4397a84e134Smrg{ 4407a84e134Smrg /* 441421c997bSmrg * bitmap will be eventually be displayed at 4427a84e134Smrg * (internal_width, internal_height + lbm_y) 4437a84e134Smrg */ 4447a84e134Smrg if (lw->label.lbm_height != 0) 4457a84e134Smrg lw->label.lbm_y = (XtHeight(lw) - (lw->label.internal_height * 2 + 4467a84e134Smrg lw->label.lbm_height)) / 2; 4477a84e134Smrg else 4487a84e134Smrg lw->label.lbm_y = 0; 4497a84e134Smrg} 4507a84e134Smrg 4517a84e134Smrgstatic void 4527a84e134Smrgset_bitmap_info(LabelWidget lw) 4537a84e134Smrg{ 4547a84e134Smrg Window root; 4557a84e134Smrg int x, y; 4567a84e134Smrg unsigned int bw, depth; 4577a84e134Smrg 4587a84e134Smrg if (!(lw->label.left_bitmap 4597a84e134Smrg && XGetGeometry(XtDisplay(lw), lw->label.left_bitmap, &root, &x, &y, 4607a84e134Smrg &lw->label.lbm_width, &lw->label.lbm_height, 4617a84e134Smrg &bw, &depth))) 4627a84e134Smrg lw->label.lbm_width = lw->label.lbm_height = 0; 4637a84e134Smrg 4647a84e134Smrg compute_bitmap_offsets(lw); 4657a84e134Smrg} 4667a84e134Smrg 4677a84e134Smrg/*ARGSUSED*/ 4687a84e134Smrgstatic void 4697a84e134SmrgXawLabelInitialize(Widget request, Widget cnew, 4707a84e134Smrg ArgList args, Cardinal *num_args) 4717a84e134Smrg{ 4727a84e134Smrg LabelWidget lw = (LabelWidget)cnew; 4737a84e134Smrg 4747a84e134Smrg if (!lw->label.font) XtError("Aborting: no font found\n"); 475421c997bSmrg if (lw->simple.international && !lw->label.fontset) 4767a84e134Smrg XtError("Aborting: no fontset found\n"); 477421c997bSmrg 478421c997bSmrg if (lw->label.label == NULL) 4797a84e134Smrg lw->label.label = XtNewString(lw->core.name); 4807a84e134Smrg else 4817a84e134Smrg lw->label.label = XtNewString(lw->label.label); 4827a84e134Smrg 4837a84e134Smrg GetNormalGC(lw); 4847a84e134Smrg GetGrayGC(lw); 4857a84e134Smrg 4867a84e134Smrg SetTextWidthAndHeight(lw); 4877a84e134Smrg 4887a84e134Smrg if (XtHeight(lw) == 0) 4897a84e134Smrg XtHeight(lw) = lw->label.label_height + 2 * lw->label.internal_height; 4907a84e134Smrg 4917a84e134Smrg set_bitmap_info(lw); /* need core.height */ 4927a84e134Smrg 4937a84e134Smrg if (XtWidth(lw) == 0) /* need label.lbm_width */ 4947a84e134Smrg XtWidth(lw) = lw->label.label_width + 2 * lw->label.internal_width + 4957a84e134Smrg LEFT_OFFSET(lw); 4967a84e134Smrg 4977a84e134Smrg lw->label.label_x = lw->label.label_y = 0; 4987a84e134Smrg (*XtClass(cnew)->core_class.resize)((Widget)lw); 4997a84e134Smrg} 5007a84e134Smrg 5017a84e134Smrg/*ARGSUSED*/ 5027a84e134Smrgstatic void 5037a84e134SmrgXawLabelRedisplay(Widget gw, XEvent *event, Region region) 5047a84e134Smrg{ 5057a84e134Smrg LabelWidget w = (LabelWidget)gw; 5067a84e134Smrg GC gc; 5077a84e134Smrg 5087a84e134Smrg if (*Superclass->core_class.expose != NULL) 5097a84e134Smrg (*Superclass->core_class.expose)(gw, event, region); 5107a84e134Smrg 5117a84e134Smrg gc = XtIsSensitive(gw) ? w->label.normal_GC : w->label.gray_GC; 5127a84e134Smrg#ifdef notdef 5137a84e134Smrg if (region != NULL) 5147a84e134Smrg XSetRegion(XtDisplay(gw), gc, region); 5157a84e134Smrg#endif /*notdef*/ 5167a84e134Smrg 5177a84e134Smrg if (w->label.pixmap == None) { 5187a84e134Smrg int len = w->label.label_len; 5197a84e134Smrg char *label = w->label.label; 5207a84e134Smrg Position y = w->label.label_y + w->label.font->max_bounds.ascent; 5217a84e134Smrg Position ksy = w->label.label_y; 5227a84e134Smrg 5237a84e134Smrg /* display left bitmap */ 5247a84e134Smrg if (w->label.left_bitmap && w->label.lbm_width != 0) 5257a84e134Smrg XCopyPlane (XtDisplay(gw), w->label.left_bitmap, XtWindow(gw), gc, 5267a84e134Smrg 0, 0, w->label.lbm_width, w->label.lbm_height, 5277a84e134Smrg w->label.internal_width, 5287a84e134Smrg w->label.internal_height + w->label.lbm_y, 1L); 5297a84e134Smrg 5307a84e134Smrg if (w->simple.international == True) { 5317a84e134Smrg XFontSetExtents *ext = XExtentsOfFontSet(w->label.fontset); 5327a84e134Smrg 5337a84e134Smrg ksy += XawAbs(ext->max_ink_extent.y); 5347a84e134Smrg 5357a84e134Smrg if (len == MULTI_LINE_LABEL) { 5367a84e134Smrg char *nl; 5377a84e134Smrg 5387a84e134Smrg while ((nl = index(label, '\n')) != NULL) { 5397a84e134Smrg XmbDrawString(XtDisplay(w), XtWindow(w), w->label.fontset, 5407a84e134Smrg gc, w->label.label_x, ksy, label, 5417a84e134Smrg (int)(nl - label)); 5427a84e134Smrg ksy += ext->max_ink_extent.height; 5437a84e134Smrg label = nl + 1; 5447a84e134Smrg } 5457a84e134Smrg len = strlen(label); 5467a84e134Smrg } 5477a84e134Smrg if (len) 5487a84e134Smrg XmbDrawString(XtDisplay(w), XtWindow(w), w->label.fontset, gc, 5497a84e134Smrg w->label.label_x, ksy, label, len); 5507a84e134Smrg } 5517a84e134Smrg else { 5527a84e134Smrg if (len == MULTI_LINE_LABEL) { 5537a84e134Smrg char *nl; 5547a84e134Smrg 5557a84e134Smrg while ((nl = index(label, '\n')) != NULL) { 5567a84e134Smrg if (w->label.encoding) 5577a84e134Smrg XDrawString16(XtDisplay(gw), XtWindow(gw), gc, 5587a84e134Smrg w->label.label_x, y, 559c889a3bfSmrg (XChar2b *)label, (int)(nl - label) / 2); 5607a84e134Smrg else 5617a84e134Smrg XDrawString(XtDisplay(gw), XtWindow(gw), gc, 5627a84e134Smrg w->label.label_x, y, label, (int)(nl - label)); 563421c997bSmrg y += w->label.font->max_bounds.ascent + 5647a84e134Smrg w->label.font->max_bounds.descent; 5657a84e134Smrg label = nl + 1; 5667a84e134Smrg } 5677a84e134Smrg len = strlen(label); 5687a84e134Smrg } 5697a84e134Smrg if (len) { 5707a84e134Smrg if (w->label.encoding) 5717a84e134Smrg XDrawString16(XtDisplay(gw), XtWindow(gw), gc, 572c889a3bfSmrg w->label.label_x, y, (XChar2b *)label, len / 2); 5737a84e134Smrg else 5747a84e134Smrg XDrawString(XtDisplay(gw), XtWindow(gw), gc, 5757a84e134Smrg w->label.label_x, y, label, len); 5767a84e134Smrg } 5777a84e134Smrg } 5787a84e134Smrg } 5797a84e134Smrg else if (w->label.label_len == 1) 5807a84e134Smrg XCopyPlane(XtDisplay(gw), w->label.pixmap, XtWindow(gw), gc, 5817a84e134Smrg 0, 0, w->label.label_width, w->label.label_height, 5827a84e134Smrg w->label.label_x, w->label.label_y, 1L); 5837a84e134Smrg else 5847a84e134Smrg XCopyArea(XtDisplay(gw), w->label.pixmap, XtWindow(gw), gc, 5857a84e134Smrg 0, 0, w->label.label_width, w->label.label_height, 5867a84e134Smrg w->label.label_x, w->label.label_y); 5877a84e134Smrg 5887a84e134Smrg#ifdef notdef 5897a84e134Smrg if (region != NULL) 5907a84e134Smrg XSetClipMask(XtDisplay(gw), gc, (Pixmap)None); 5917a84e134Smrg#endif /* notdef */ 5927a84e134Smrg} 5937a84e134Smrg 5947a84e134Smrgstatic void 5957a84e134Smrg_Reposition(LabelWidget lw, unsigned int width, unsigned int height, 5967a84e134Smrg Position *dx, Position *dy) 5977a84e134Smrg{ 5987a84e134Smrg Position newPos; 5997a84e134Smrg Position leftedge = lw->label.internal_width + LEFT_OFFSET(lw); 6007a84e134Smrg 6017a84e134Smrg switch (lw->label.justify) { 6027a84e134Smrg case XtJustifyLeft: 6037a84e134Smrg newPos = leftedge; 6047a84e134Smrg break; 6057a84e134Smrg case XtJustifyRight: 6067a84e134Smrg newPos = width - (lw->label.label_width + lw->label.internal_width); 6077a84e134Smrg break; 6087a84e134Smrg case XtJustifyCenter: 6097a84e134Smrg /*FALLTRHOUGH*/ 6107a84e134Smrg default: 6117a84e134Smrg newPos = (int)(width - lw->label.label_width) >> 1; 6127a84e134Smrg break; 6137a84e134Smrg } 6147a84e134Smrg if (newPos < (Position)leftedge) 6157a84e134Smrg newPos = leftedge; 6167a84e134Smrg *dx = newPos - lw->label.label_x; 6177a84e134Smrg lw->label.label_x = newPos; 6187a84e134Smrg 6197a84e134Smrg newPos = (height - lw->label.label_height) >> 1; 6207a84e134Smrg *dy = newPos - lw->label.label_y; 6217a84e134Smrg lw->label.label_y = newPos; 6227a84e134Smrg} 6237a84e134Smrg 6247a84e134Smrgstatic void 6257a84e134SmrgXawLabelResize(Widget w) 6267a84e134Smrg{ 6277a84e134Smrg LabelWidget lw = (LabelWidget)w; 6287a84e134Smrg Position dx, dy; 6297a84e134Smrg 6307a84e134Smrg _Reposition(lw, XtWidth(w), XtHeight(w), &dx, &dy); 6317a84e134Smrg compute_bitmap_offsets(lw); 6327a84e134Smrg} 6337a84e134Smrg 6347a84e134Smrg#define PIXMAP 0 6357a84e134Smrg#define WIDTH 1 6367a84e134Smrg#define HEIGHT 2 6377a84e134Smrg#define NUM_CHECKS 3 6387a84e134Smrgstatic Boolean 6397a84e134SmrgXawLabelSetValues(Widget current, Widget request, Widget cnew, 6407a84e134Smrg ArgList args, Cardinal *num_args) 6417a84e134Smrg{ 6427a84e134Smrg LabelWidget curlw = (LabelWidget)current; 6437a84e134Smrg LabelWidget reqlw = (LabelWidget)request; 6447a84e134Smrg LabelWidget newlw = (LabelWidget)cnew; 6457a84e134Smrg unsigned int i; 6467a84e134Smrg Boolean was_resized = False, redisplay = False, checks[NUM_CHECKS]; 6477a84e134Smrg 6487a84e134Smrg for (i = 0; i < NUM_CHECKS; i++) 6497a84e134Smrg checks[i] = False; 6507a84e134Smrg 6517a84e134Smrg for (i = 0; i < *num_args; i++) { 6527a84e134Smrg if (streq(XtNbitmap, args[i].name)) 6537a84e134Smrg checks[PIXMAP] = True; 6547a84e134Smrg else if (streq(XtNwidth, args[i].name)) 6557a84e134Smrg checks[WIDTH] = True; 6567a84e134Smrg else if (streq(XtNheight, args[i].name)) 6577a84e134Smrg checks[HEIGHT] = True; 6587a84e134Smrg } 6597a84e134Smrg 6607a84e134Smrg if (newlw->label.label == NULL) 6617a84e134Smrg newlw->label.label = newlw->core.name; 6627a84e134Smrg 6637a84e134Smrg /* 6647a84e134Smrg * resize on bitmap change 6657a84e134Smrg */ 6667a84e134Smrg if (curlw->label.left_bitmap != newlw->label.left_bitmap) 6677a84e134Smrg was_resized = True; 6687a84e134Smrg 6697a84e134Smrg if (curlw->label.encoding != newlw->label.encoding) 6707a84e134Smrg was_resized = True; 6717a84e134Smrg 672421c997bSmrg if (curlw->simple.international 6737a84e134Smrg && curlw->label.fontset != newlw->label.fontset) 6747a84e134Smrg was_resized = True; 6757a84e134Smrg 6767a84e134Smrg if (curlw->label.label != newlw->label.label) { 6777a84e134Smrg if (curlw->label.label != curlw->core.name) 6787a84e134Smrg XtFree((char *)curlw->label.label); 6797a84e134Smrg 6807a84e134Smrg if (newlw->label.label != newlw->core.name) 6817a84e134Smrg newlw->label.label = XtNewString(newlw->label.label); 6827a84e134Smrg 6837a84e134Smrg was_resized = True; 6847a84e134Smrg } 6857a84e134Smrg 6867a84e134Smrg if (was_resized || (curlw->label.font != newlw->label.font) || 6877a84e134Smrg curlw->label.justify != newlw->label.justify || checks[PIXMAP]) { 6887a84e134Smrg SetTextWidthAndHeight(newlw); 6897a84e134Smrg was_resized = True; 6907a84e134Smrg } 6917a84e134Smrg 6927a84e134Smrg /* recalculate the window size if something has changed */ 6937a84e134Smrg if (newlw->label.resize && was_resized) { 6947a84e134Smrg if (XtHeight(curlw) == XtHeight(reqlw) && !checks[HEIGHT]) 6957a84e134Smrg XtHeight(newlw) = newlw->label.label_height + 6967a84e134Smrg (newlw->label.internal_height << 1); 6977a84e134Smrg 6987a84e134Smrg set_bitmap_info(newlw); 6997a84e134Smrg 7007a84e134Smrg if (XtWidth(curlw) == XtWidth(reqlw) && !checks[WIDTH]) 7017a84e134Smrg XtWidth(newlw) = newlw->label.label_width + LEFT_OFFSET(newlw) + 7027a84e134Smrg (newlw->label.internal_width << 1); 7037a84e134Smrg } 7047a84e134Smrg 7057a84e134Smrg if (curlw->label.foreground != newlw->label.foreground 7067a84e134Smrg || curlw->core.background_pixel != newlw->core.background_pixel 7077a84e134Smrg || curlw->label.font->fid != newlw->label.font->fid) { 7087a84e134Smrg /* The Fontset is not in the GC - don't make a new GC if FS changes! */ 7097a84e134Smrg XtReleaseGC(cnew, curlw->label.normal_GC); 7107a84e134Smrg XtReleaseGC(cnew, curlw->label.gray_GC); 7117a84e134Smrg XmuReleaseStippledPixmap(XtScreen(current), curlw->label.stipple); 7127a84e134Smrg GetNormalGC(newlw); 7137a84e134Smrg GetGrayGC(newlw); 7147a84e134Smrg redisplay = True; 7157a84e134Smrg } 7167a84e134Smrg 7177a84e134Smrg if (curlw->label.label_x != newlw->label.label_x || 7187a84e134Smrg curlw->label.label_y != newlw->label.label_y) 7197a84e134Smrg redisplay = True; 7207a84e134Smrg 7217a84e134Smrg if (curlw->label.internal_width != newlw->label.internal_width 7227a84e134Smrg || curlw->label.internal_height != newlw->label.internal_height 7237a84e134Smrg || was_resized) { 7247a84e134Smrg /* Resize() will be called if geometry changes succeed */ 7257a84e134Smrg Position dx, dy; 7267a84e134Smrg 7277a84e134Smrg _Reposition(newlw, XtWidth(curlw), XtHeight(curlw), &dx, &dy); 7287a84e134Smrg } 7297a84e134Smrg 7307a84e134Smrg return (was_resized || redisplay || 7317a84e134Smrg XtIsSensitive(current) != XtIsSensitive(cnew)); 7327a84e134Smrg} 7337a84e134Smrg 7347a84e134Smrgstatic void 7357a84e134SmrgXawLabelDestroy(Widget w) 7367a84e134Smrg{ 7377a84e134Smrg LabelWidget lw = (LabelWidget)w; 7387a84e134Smrg 7397a84e134Smrg if (lw->label.label != lw->core.name) 7407a84e134Smrg XtFree(lw->label.label); 7417a84e134Smrg XtReleaseGC(w, lw->label.normal_GC); 7427a84e134Smrg XtReleaseGC(w, lw->label.gray_GC); 7437a84e134Smrg XmuReleaseStippledPixmap(XtScreen(w), lw->label.stipple); 7447a84e134Smrg} 7457a84e134Smrg 7467a84e134Smrgstatic XtGeometryResult 7477a84e134SmrgXawLabelQueryGeometry(Widget w, XtWidgetGeometry *intended, 7487a84e134Smrg XtWidgetGeometry *preferred) 7497a84e134Smrg{ 7507a84e134Smrg LabelWidget lw = (LabelWidget)w; 7517a84e134Smrg 7527a84e134Smrg preferred->request_mode = CWWidth | CWHeight; 7537a84e134Smrg preferred->width = lw->label.label_width + 7547a84e134Smrg (lw->label.internal_width << 1) + LEFT_OFFSET(lw); 7557a84e134Smrg preferred->height = lw->label.label_height + 7567a84e134Smrg (lw->label.internal_height << 1); 7577a84e134Smrg 7587a84e134Smrg if (((intended->request_mode & (CWWidth | CWHeight)) == (CWWidth | CWHeight)) 7597a84e134Smrg && intended->width == preferred->width 7607a84e134Smrg && intended->height == preferred->height) 7617a84e134Smrg return (XtGeometryYes); 7627a84e134Smrg else if (preferred->width == XtWidth(w) && preferred->height == XtHeight(w)) 7637a84e134Smrg return (XtGeometryNo); 7647a84e134Smrg 7657a84e134Smrg return (XtGeometryAlmost); 7667a84e134Smrg} 767