Label.c revision 5ec34c4c
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, 1035ec34c4cSmrg (XtPointer)XtDefaultForeground 1047a84e134Smrg }, 1057a84e134Smrg { 1067a84e134Smrg XtNfont, 1077a84e134Smrg XtCFont, 1087a84e134Smrg XtRFontStruct, 1097a84e134Smrg sizeof(XFontStruct*), 1107a84e134Smrg offset(label.font), 1117a84e134Smrg XtRString, 1125ec34c4cSmrg (XtPointer)XtDefaultFont 1137a84e134Smrg }, 1147a84e134Smrg { 1157a84e134Smrg XtNfontSet, 1167a84e134Smrg XtCFontSet, 1177a84e134Smrg XtRFontSet, 1187a84e134Smrg sizeof(XFontSet), 1197a84e134Smrg offset(label.fontset), 1207a84e134Smrg XtRString, 1215ec34c4cSmrg (XtPointer)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)) { 2935ec34c4cSmrg lw->label.label_height = (Dimension)height; 2945ec34c4cSmrg lw->label.label_width = (Dimension)width; 2955ec34c4cSmrg lw->label.label_len = (Dimension)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) 3175ec34c4cSmrg lw->label.label_width = (Dimension)width; 3187a84e134Smrg label = nl + 1; 3197a84e134Smrg if (*label) 3205ec34c4cSmrg lw->label.label_height = (Dimension)(lw->label.label_height + ext->max_ink_extent.height); 3217a84e134Smrg } 3227a84e134Smrg if (*label) { 3235ec34c4cSmrg int width = XmbTextEscapement(fset, label, (int)strlen(label)); 3247a84e134Smrg 3257a84e134Smrg if (width > (int)lw->label.label_width) 3265ec34c4cSmrg lw->label.label_width = (Dimension)width; 3277a84e134Smrg } 3287a84e134Smrg } 3297a84e134Smrg else { 3305ec34c4cSmrg lw->label.label_len = (Dimension)strlen(lw->label.label); 3317a84e134Smrg lw->label.label_width = 3325ec34c4cSmrg (Dimension)XmbTextEscapement(fset, lw->label.label, lw->label.label_len); 3337a84e134Smrg } 3347a84e134Smrg } 3357a84e134Smrg else { 3365ec34c4cSmrg lw->label.label_height = (Dimension)(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) 3545ec34c4cSmrg lw->label.label_width = (Dimension)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) { 3615ec34c4cSmrg int width = XTextWidth(fs, label, (int)strlen(label)); 3627a84e134Smrg 3637a84e134Smrg if (lw->label.encoding) 3645ec34c4cSmrg width = XTextWidth16(fs, (XChar2b *)label, (int)(strlen(label) / 2)); 3657a84e134Smrg else 3665ec34c4cSmrg width = XTextWidth(fs, label, (int)strlen(label)); 3677a84e134Smrg if (width > (int) lw->label.label_width) 3685ec34c4cSmrg lw->label.label_width = (Dimension)width; 3697a84e134Smrg } 3707a84e134Smrg } 3717a84e134Smrg else { 3725ec34c4cSmrg lw->label.label_len = (Dimension)strlen(lw->label.label); 3737a84e134Smrg if (lw->label.encoding) 3747a84e134Smrg lw->label.label_width = 3755ec34c4cSmrg (Dimension)XTextWidth16(fs, (XChar2b *)lw->label.label, 3767a84e134Smrg (int)lw->label.label_len / 2); 3777a84e134Smrg else 3787a84e134Smrg lw->label.label_width = 3795ec34c4cSmrg (Dimension)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) 4455ec34c4cSmrg lw->label.lbm_y = (int)((XtHeight(lw) 4465ec34c4cSmrg - ((lw->label.internal_height * 2) 4475ec34c4cSmrg + lw->label.lbm_height)) / 2); 4487a84e134Smrg else 4497a84e134Smrg lw->label.lbm_y = 0; 4507a84e134Smrg} 4517a84e134Smrg 4527a84e134Smrgstatic void 4537a84e134Smrgset_bitmap_info(LabelWidget lw) 4547a84e134Smrg{ 4557a84e134Smrg Window root; 4567a84e134Smrg int x, y; 4577a84e134Smrg unsigned int bw, depth; 4587a84e134Smrg 4597a84e134Smrg if (!(lw->label.left_bitmap 4607a84e134Smrg && XGetGeometry(XtDisplay(lw), lw->label.left_bitmap, &root, &x, &y, 4617a84e134Smrg &lw->label.lbm_width, &lw->label.lbm_height, 4627a84e134Smrg &bw, &depth))) 4637a84e134Smrg lw->label.lbm_width = lw->label.lbm_height = 0; 4647a84e134Smrg 4657a84e134Smrg compute_bitmap_offsets(lw); 4667a84e134Smrg} 4677a84e134Smrg 4687a84e134Smrg/*ARGSUSED*/ 4697a84e134Smrgstatic void 4705ec34c4cSmrgXawLabelInitialize(Widget request _X_UNUSED, Widget cnew, 4715ec34c4cSmrg ArgList args _X_UNUSED, Cardinal *num_args _X_UNUSED) 4727a84e134Smrg{ 4737a84e134Smrg LabelWidget lw = (LabelWidget)cnew; 4747a84e134Smrg 4757a84e134Smrg if (!lw->label.font) XtError("Aborting: no font found\n"); 476421c997bSmrg if (lw->simple.international && !lw->label.fontset) 4777a84e134Smrg XtError("Aborting: no fontset found\n"); 478421c997bSmrg 479421c997bSmrg if (lw->label.label == NULL) 4807a84e134Smrg lw->label.label = XtNewString(lw->core.name); 4817a84e134Smrg else 4827a84e134Smrg lw->label.label = XtNewString(lw->label.label); 4837a84e134Smrg 4847a84e134Smrg GetNormalGC(lw); 4857a84e134Smrg GetGrayGC(lw); 4867a84e134Smrg 4877a84e134Smrg SetTextWidthAndHeight(lw); 4887a84e134Smrg 4897a84e134Smrg if (XtHeight(lw) == 0) 4905ec34c4cSmrg XtHeight(lw) = (Dimension)(lw->label.label_height + 2 * lw->label.internal_height); 4917a84e134Smrg 4927a84e134Smrg set_bitmap_info(lw); /* need core.height */ 4937a84e134Smrg 4947a84e134Smrg if (XtWidth(lw) == 0) /* need label.lbm_width */ 4955ec34c4cSmrg XtWidth(lw) = (lw->label.label_width 4965ec34c4cSmrg + (2 * lw->label.internal_width) 4975ec34c4cSmrg + LEFT_OFFSET(lw)); 4987a84e134Smrg 4997a84e134Smrg lw->label.label_x = lw->label.label_y = 0; 5007a84e134Smrg (*XtClass(cnew)->core_class.resize)((Widget)lw); 5017a84e134Smrg} 5027a84e134Smrg 5037a84e134Smrg/*ARGSUSED*/ 5047a84e134Smrgstatic void 5057a84e134SmrgXawLabelRedisplay(Widget gw, XEvent *event, Region region) 5067a84e134Smrg{ 5077a84e134Smrg LabelWidget w = (LabelWidget)gw; 5087a84e134Smrg GC gc; 5097a84e134Smrg 5107a84e134Smrg if (*Superclass->core_class.expose != NULL) 5117a84e134Smrg (*Superclass->core_class.expose)(gw, event, region); 5127a84e134Smrg 5137a84e134Smrg gc = XtIsSensitive(gw) ? w->label.normal_GC : w->label.gray_GC; 5147a84e134Smrg#ifdef notdef 5157a84e134Smrg if (region != NULL) 5167a84e134Smrg XSetRegion(XtDisplay(gw), gc, region); 5177a84e134Smrg#endif /*notdef*/ 5187a84e134Smrg 5197a84e134Smrg if (w->label.pixmap == None) { 5207a84e134Smrg int len = w->label.label_len; 5217a84e134Smrg char *label = w->label.label; 5225ec34c4cSmrg Position y = (Position)(w->label.label_y + w->label.font->max_bounds.ascent); 5237a84e134Smrg Position ksy = w->label.label_y; 5247a84e134Smrg 5257a84e134Smrg /* display left bitmap */ 5267a84e134Smrg if (w->label.left_bitmap && w->label.lbm_width != 0) 5277a84e134Smrg XCopyPlane (XtDisplay(gw), w->label.left_bitmap, XtWindow(gw), gc, 5287a84e134Smrg 0, 0, w->label.lbm_width, w->label.lbm_height, 5297a84e134Smrg w->label.internal_width, 5307a84e134Smrg w->label.internal_height + w->label.lbm_y, 1L); 5317a84e134Smrg 5327a84e134Smrg if (w->simple.international == True) { 5337a84e134Smrg XFontSetExtents *ext = XExtentsOfFontSet(w->label.fontset); 5347a84e134Smrg 5355ec34c4cSmrg ksy = (ksy + XawAbs(ext->max_ink_extent.y)); 5367a84e134Smrg 5377a84e134Smrg if (len == MULTI_LINE_LABEL) { 5387a84e134Smrg char *nl; 5397a84e134Smrg 5407a84e134Smrg while ((nl = index(label, '\n')) != NULL) { 5417a84e134Smrg XmbDrawString(XtDisplay(w), XtWindow(w), w->label.fontset, 5427a84e134Smrg gc, w->label.label_x, ksy, label, 5437a84e134Smrg (int)(nl - label)); 5445ec34c4cSmrg ksy = (ksy + ext->max_ink_extent.height); 5457a84e134Smrg label = nl + 1; 5467a84e134Smrg } 5475ec34c4cSmrg len = (int)strlen(label); 5487a84e134Smrg } 5497a84e134Smrg if (len) 5507a84e134Smrg XmbDrawString(XtDisplay(w), XtWindow(w), w->label.fontset, gc, 5517a84e134Smrg w->label.label_x, ksy, label, len); 5527a84e134Smrg } 5537a84e134Smrg else { 5547a84e134Smrg if (len == MULTI_LINE_LABEL) { 5557a84e134Smrg char *nl; 5567a84e134Smrg 5577a84e134Smrg while ((nl = index(label, '\n')) != NULL) { 5587a84e134Smrg if (w->label.encoding) 5597a84e134Smrg XDrawString16(XtDisplay(gw), XtWindow(gw), gc, 5607a84e134Smrg w->label.label_x, y, 561c889a3bfSmrg (XChar2b *)label, (int)(nl - label) / 2); 5627a84e134Smrg else 5637a84e134Smrg XDrawString(XtDisplay(gw), XtWindow(gw), gc, 5647a84e134Smrg w->label.label_x, y, label, (int)(nl - label)); 5655ec34c4cSmrg y += (w->label.font->max_bounds.ascent + 5665ec34c4cSmrg w->label.font->max_bounds.descent); 5677a84e134Smrg label = nl + 1; 5687a84e134Smrg } 5695ec34c4cSmrg len = (int)strlen(label); 5707a84e134Smrg } 5717a84e134Smrg if (len) { 5727a84e134Smrg if (w->label.encoding) 5737a84e134Smrg XDrawString16(XtDisplay(gw), XtWindow(gw), gc, 574c889a3bfSmrg w->label.label_x, y, (XChar2b *)label, len / 2); 5757a84e134Smrg else 5767a84e134Smrg XDrawString(XtDisplay(gw), XtWindow(gw), gc, 5777a84e134Smrg w->label.label_x, y, label, len); 5787a84e134Smrg } 5797a84e134Smrg } 5807a84e134Smrg } 5817a84e134Smrg else if (w->label.label_len == 1) 5827a84e134Smrg XCopyPlane(XtDisplay(gw), w->label.pixmap, XtWindow(gw), gc, 5837a84e134Smrg 0, 0, w->label.label_width, w->label.label_height, 5847a84e134Smrg w->label.label_x, w->label.label_y, 1L); 5857a84e134Smrg else 5867a84e134Smrg XCopyArea(XtDisplay(gw), w->label.pixmap, XtWindow(gw), gc, 5877a84e134Smrg 0, 0, w->label.label_width, w->label.label_height, 5887a84e134Smrg w->label.label_x, w->label.label_y); 5897a84e134Smrg 5907a84e134Smrg#ifdef notdef 5917a84e134Smrg if (region != NULL) 5927a84e134Smrg XSetClipMask(XtDisplay(gw), gc, (Pixmap)None); 5937a84e134Smrg#endif /* notdef */ 5947a84e134Smrg} 5957a84e134Smrg 5967a84e134Smrgstatic void 5977a84e134Smrg_Reposition(LabelWidget lw, unsigned int width, unsigned int height, 5987a84e134Smrg Position *dx, Position *dy) 5997a84e134Smrg{ 6007a84e134Smrg Position newPos; 6015ec34c4cSmrg Position leftedge = (lw->label.internal_width + LEFT_OFFSET(lw)); 6027a84e134Smrg 6037a84e134Smrg switch (lw->label.justify) { 6047a84e134Smrg case XtJustifyLeft: 6057a84e134Smrg newPos = leftedge; 6067a84e134Smrg break; 6077a84e134Smrg case XtJustifyRight: 6085ec34c4cSmrg newPos = (Position)(width - (unsigned)(lw->label.label_width + lw->label.internal_width)); 6097a84e134Smrg break; 6107a84e134Smrg case XtJustifyCenter: 6117a84e134Smrg /*FALLTRHOUGH*/ 6127a84e134Smrg default: 6135ec34c4cSmrg newPos = (Position)((int)(width - lw->label.label_width) >> 1); 6147a84e134Smrg break; 6157a84e134Smrg } 6167a84e134Smrg if (newPos < (Position)leftedge) 6177a84e134Smrg newPos = leftedge; 6185ec34c4cSmrg *dx = (Position)(newPos - lw->label.label_x); 6197a84e134Smrg lw->label.label_x = newPos; 6207a84e134Smrg 6215ec34c4cSmrg newPos = (Position)((height - lw->label.label_height) >> 1); 6225ec34c4cSmrg *dy = (Position)(newPos - lw->label.label_y); 6237a84e134Smrg lw->label.label_y = newPos; 6247a84e134Smrg} 6257a84e134Smrg 6267a84e134Smrgstatic void 6277a84e134SmrgXawLabelResize(Widget w) 6287a84e134Smrg{ 6297a84e134Smrg LabelWidget lw = (LabelWidget)w; 6307a84e134Smrg Position dx, dy; 6317a84e134Smrg 6327a84e134Smrg _Reposition(lw, XtWidth(w), XtHeight(w), &dx, &dy); 6337a84e134Smrg compute_bitmap_offsets(lw); 6347a84e134Smrg} 6357a84e134Smrg 6367a84e134Smrg#define PIXMAP 0 6377a84e134Smrg#define WIDTH 1 6387a84e134Smrg#define HEIGHT 2 6397a84e134Smrg#define NUM_CHECKS 3 6407a84e134Smrgstatic Boolean 6417a84e134SmrgXawLabelSetValues(Widget current, Widget request, Widget cnew, 6427a84e134Smrg ArgList args, Cardinal *num_args) 6437a84e134Smrg{ 6447a84e134Smrg LabelWidget curlw = (LabelWidget)current; 6457a84e134Smrg LabelWidget reqlw = (LabelWidget)request; 6467a84e134Smrg LabelWidget newlw = (LabelWidget)cnew; 6477a84e134Smrg unsigned int i; 6487a84e134Smrg Boolean was_resized = False, redisplay = False, checks[NUM_CHECKS]; 6497a84e134Smrg 6507a84e134Smrg for (i = 0; i < NUM_CHECKS; i++) 6517a84e134Smrg checks[i] = False; 6527a84e134Smrg 6537a84e134Smrg for (i = 0; i < *num_args; i++) { 6547a84e134Smrg if (streq(XtNbitmap, args[i].name)) 6557a84e134Smrg checks[PIXMAP] = True; 6567a84e134Smrg else if (streq(XtNwidth, args[i].name)) 6577a84e134Smrg checks[WIDTH] = True; 6587a84e134Smrg else if (streq(XtNheight, args[i].name)) 6597a84e134Smrg checks[HEIGHT] = True; 6607a84e134Smrg } 6617a84e134Smrg 6627a84e134Smrg if (newlw->label.label == NULL) 6635ec34c4cSmrg newlw->label.label = (char *)newlw->core.name; 6647a84e134Smrg 6657a84e134Smrg /* 6667a84e134Smrg * resize on bitmap change 6677a84e134Smrg */ 6687a84e134Smrg if (curlw->label.left_bitmap != newlw->label.left_bitmap) 6697a84e134Smrg was_resized = True; 6707a84e134Smrg 6717a84e134Smrg if (curlw->label.encoding != newlw->label.encoding) 6727a84e134Smrg was_resized = True; 6737a84e134Smrg 674421c997bSmrg if (curlw->simple.international 6757a84e134Smrg && curlw->label.fontset != newlw->label.fontset) 6767a84e134Smrg was_resized = True; 6777a84e134Smrg 6787a84e134Smrg if (curlw->label.label != newlw->label.label) { 6797a84e134Smrg if (curlw->label.label != curlw->core.name) 6807a84e134Smrg XtFree((char *)curlw->label.label); 6817a84e134Smrg 6827a84e134Smrg if (newlw->label.label != newlw->core.name) 6837a84e134Smrg newlw->label.label = XtNewString(newlw->label.label); 6847a84e134Smrg 6857a84e134Smrg was_resized = True; 6867a84e134Smrg } 6877a84e134Smrg 6887a84e134Smrg if (was_resized || (curlw->label.font != newlw->label.font) || 6897a84e134Smrg curlw->label.justify != newlw->label.justify || checks[PIXMAP]) { 6907a84e134Smrg SetTextWidthAndHeight(newlw); 6917a84e134Smrg was_resized = True; 6927a84e134Smrg } 6937a84e134Smrg 6947a84e134Smrg /* recalculate the window size if something has changed */ 6957a84e134Smrg if (newlw->label.resize && was_resized) { 6967a84e134Smrg if (XtHeight(curlw) == XtHeight(reqlw) && !checks[HEIGHT]) 6975ec34c4cSmrg XtHeight(newlw) = (Dimension)(newlw->label.label_height + 6985ec34c4cSmrg (newlw->label.internal_height << 1)); 6997a84e134Smrg 7007a84e134Smrg set_bitmap_info(newlw); 7017a84e134Smrg 7027a84e134Smrg if (XtWidth(curlw) == XtWidth(reqlw) && !checks[WIDTH]) 7035ec34c4cSmrg XtWidth(newlw) = (newlw->label.label_width 7045ec34c4cSmrg + LEFT_OFFSET(newlw) 7055ec34c4cSmrg + (unsigned)(newlw->label.internal_width << 1)); 7067a84e134Smrg } 7077a84e134Smrg 7087a84e134Smrg if (curlw->label.foreground != newlw->label.foreground 7097a84e134Smrg || curlw->core.background_pixel != newlw->core.background_pixel 7107a84e134Smrg || curlw->label.font->fid != newlw->label.font->fid) { 7117a84e134Smrg /* The Fontset is not in the GC - don't make a new GC if FS changes! */ 7127a84e134Smrg XtReleaseGC(cnew, curlw->label.normal_GC); 7137a84e134Smrg XtReleaseGC(cnew, curlw->label.gray_GC); 7147a84e134Smrg XmuReleaseStippledPixmap(XtScreen(current), curlw->label.stipple); 7157a84e134Smrg GetNormalGC(newlw); 7167a84e134Smrg GetGrayGC(newlw); 7177a84e134Smrg redisplay = True; 7187a84e134Smrg } 7197a84e134Smrg 7207a84e134Smrg if (curlw->label.label_x != newlw->label.label_x || 7217a84e134Smrg curlw->label.label_y != newlw->label.label_y) 7227a84e134Smrg redisplay = True; 7237a84e134Smrg 7247a84e134Smrg if (curlw->label.internal_width != newlw->label.internal_width 7257a84e134Smrg || curlw->label.internal_height != newlw->label.internal_height 7267a84e134Smrg || was_resized) { 7277a84e134Smrg /* Resize() will be called if geometry changes succeed */ 7287a84e134Smrg Position dx, dy; 7297a84e134Smrg 7307a84e134Smrg _Reposition(newlw, XtWidth(curlw), XtHeight(curlw), &dx, &dy); 7317a84e134Smrg } 7327a84e134Smrg 7337a84e134Smrg return (was_resized || redisplay || 7347a84e134Smrg XtIsSensitive(current) != XtIsSensitive(cnew)); 7357a84e134Smrg} 7367a84e134Smrg 7377a84e134Smrgstatic void 7387a84e134SmrgXawLabelDestroy(Widget w) 7397a84e134Smrg{ 7407a84e134Smrg LabelWidget lw = (LabelWidget)w; 7417a84e134Smrg 7427a84e134Smrg if (lw->label.label != lw->core.name) 7437a84e134Smrg XtFree(lw->label.label); 7447a84e134Smrg XtReleaseGC(w, lw->label.normal_GC); 7457a84e134Smrg XtReleaseGC(w, lw->label.gray_GC); 7467a84e134Smrg XmuReleaseStippledPixmap(XtScreen(w), lw->label.stipple); 7477a84e134Smrg} 7487a84e134Smrg 7497a84e134Smrgstatic XtGeometryResult 7507a84e134SmrgXawLabelQueryGeometry(Widget w, XtWidgetGeometry *intended, 7517a84e134Smrg XtWidgetGeometry *preferred) 7527a84e134Smrg{ 7537a84e134Smrg LabelWidget lw = (LabelWidget)w; 7547a84e134Smrg 7557a84e134Smrg preferred->request_mode = CWWidth | CWHeight; 7565ec34c4cSmrg preferred->width = (lw->label.label_width 7575ec34c4cSmrg + (unsigned)(lw->label.internal_width << 1) 7585ec34c4cSmrg + LEFT_OFFSET(lw)); 7595ec34c4cSmrg preferred->height = (Dimension)(lw->label.label_height + 7605ec34c4cSmrg (lw->label.internal_height << 1)); 7617a84e134Smrg 7627a84e134Smrg if (((intended->request_mode & (CWWidth | CWHeight)) == (CWWidth | CWHeight)) 7637a84e134Smrg && intended->width == preferred->width 7647a84e134Smrg && intended->height == preferred->height) 7657a84e134Smrg return (XtGeometryYes); 7667a84e134Smrg else if (preferred->width == XtWidth(w) && preferred->height == XtHeight(w)) 7677a84e134Smrg return (XtGeometryNo); 7687a84e134Smrg 7697a84e134Smrg return (XtGeometryAlmost); 7707a84e134Smrg} 771