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 */ 256efbcb2bfSmrg#ifndef OLDXAW 257efbcb2bfSmrg NULL, 258efbcb2bfSmrg#endif 2597a84e134Smrg }, 2607a84e134Smrg /* label */ 2617a84e134Smrg { 2627a84e134Smrg NULL, /* extension */ 2637a84e134Smrg } 2647a84e134Smrg}; 2657a84e134Smrg 2667a84e134SmrgWidgetClass labelWidgetClass = (WidgetClass)&labelClassRec; 2677a84e134Smrg 2687a84e134Smrg/* 2697a84e134Smrg * Implementation 2707a84e134Smrg */ 2717a84e134Smrgstatic void 2727a84e134SmrgXawLabelClassInitialize(void) 2737a84e134Smrg{ 2747a84e134Smrg XawInitializeWidgetSet(); 2757a84e134Smrg XtAddConverter(XtRString, XtRJustify, XmuCvtStringToJustify, NULL, 0); 2767a84e134Smrg XtSetTypeConverter(XtRJustify, XtRString, XmuCvtJustifyToString, 2777a84e134Smrg NULL, 0, XtCacheNone, NULL); 2787a84e134Smrg} 2797a84e134Smrg 2807a84e134Smrg/* 2817a84e134Smrg * Calculate width and height of displayed text in pixels 2827a84e134Smrg */ 2837a84e134Smrgstatic void 2847a84e134SmrgSetTextWidthAndHeight(LabelWidget lw) 2857a84e134Smrg{ 2867a84e134Smrg XFontStruct *fs = lw->label.font; 2877a84e134Smrg char *nl; 2887a84e134Smrg 2897a84e134Smrg if (lw->label.pixmap != None) { 2907a84e134Smrg Window root; 2917a84e134Smrg int x, y; 2927a84e134Smrg unsigned int width, height, bw, depth; 2937a84e134Smrg 2947a84e134Smrg if (XGetGeometry(XtDisplay(lw), lw->label.pixmap, &root, &x, &y, 2957a84e134Smrg &width, &height, &bw, &depth)) { 2965ec34c4cSmrg lw->label.label_height = (Dimension)height; 2975ec34c4cSmrg lw->label.label_width = (Dimension)width; 2985ec34c4cSmrg lw->label.label_len = (Dimension)depth; 2997a84e134Smrg return; 3007a84e134Smrg } 3017a84e134Smrg } 3027a84e134Smrg if (lw->simple.international == True) { 3037a84e134Smrg XFontSet fset = lw->label.fontset; 3047a84e134Smrg XFontSetExtents *ext = XExtentsOfFontSet(fset); 3057a84e134Smrg 3067a84e134Smrg lw->label.label_height = ext->max_ink_extent.height; 3077a84e134Smrg if (lw->label.label == NULL) { 3087a84e134Smrg lw->label.label_len = 0; 3097a84e134Smrg lw->label.label_width = 0; 3107a84e134Smrg } 3115b16253fSmrg else if ((nl = strchr(lw->label.label, '\n')) != NULL) { 3127a84e134Smrg char *label; 3137a84e134Smrg 3147a84e134Smrg lw->label.label_len = MULTI_LINE_LABEL; 3157a84e134Smrg lw->label.label_width = 0; 3165b16253fSmrg for (label = lw->label.label; nl != NULL; nl = strchr(label, '\n')) { 3177a84e134Smrg int width = XmbTextEscapement(fset, label, (int)(nl - label)); 3187a84e134Smrg 3197a84e134Smrg if (width > (int)lw->label.label_width) 3205ec34c4cSmrg lw->label.label_width = (Dimension)width; 3217a84e134Smrg label = nl + 1; 3227a84e134Smrg if (*label) 3235ec34c4cSmrg lw->label.label_height = (Dimension)(lw->label.label_height + ext->max_ink_extent.height); 3247a84e134Smrg } 3257a84e134Smrg if (*label) { 3265ec34c4cSmrg int width = XmbTextEscapement(fset, label, (int)strlen(label)); 3277a84e134Smrg 3287a84e134Smrg if (width > (int)lw->label.label_width) 3295ec34c4cSmrg lw->label.label_width = (Dimension)width; 3307a84e134Smrg } 3317a84e134Smrg } 3327a84e134Smrg else { 3335ec34c4cSmrg lw->label.label_len = (Dimension)strlen(lw->label.label); 3347a84e134Smrg lw->label.label_width = 3355ec34c4cSmrg (Dimension)XmbTextEscapement(fset, lw->label.label, lw->label.label_len); 3367a84e134Smrg } 3377a84e134Smrg } 3387a84e134Smrg else { 3395ec34c4cSmrg lw->label.label_height = (Dimension)(fs->max_bounds.ascent + fs->max_bounds.descent); 3407a84e134Smrg if (lw->label.label == NULL) { 3417a84e134Smrg lw->label.label_len = 0; 3427a84e134Smrg lw->label.label_width = 0; 3437a84e134Smrg } 3445b16253fSmrg else if ((nl = strchr(lw->label.label, '\n')) != NULL) { 3457a84e134Smrg char *label; 3467a84e134Smrg 3477a84e134Smrg lw->label.label_len = MULTI_LINE_LABEL; 3487a84e134Smrg lw->label.label_width = 0; 3495b16253fSmrg for (label = lw->label.label; nl != NULL; nl = strchr(label, '\n')) { 3507a84e134Smrg int width; 3517a84e134Smrg 3527a84e134Smrg if (lw->label.encoding) 353c889a3bfSmrg width = XTextWidth16(fs, (XChar2b *)label, (int)(nl - label) / 2); 3547a84e134Smrg else 3557a84e134Smrg width = XTextWidth(fs, label, (int)(nl - label)); 3567a84e134Smrg if (width > (int)lw->label.label_width) 3575ec34c4cSmrg lw->label.label_width = (Dimension)width; 3587a84e134Smrg label = nl + 1; 3597a84e134Smrg if (*label) 3607a84e134Smrg lw->label.label_height += 361efbcb2bfSmrg (Dimension)(fs->max_bounds.ascent + fs->max_bounds.descent); 3627a84e134Smrg } 3637a84e134Smrg if (*label) { 364efbcb2bfSmrg int width; 3657a84e134Smrg 3667a84e134Smrg if (lw->label.encoding) 3675ec34c4cSmrg width = XTextWidth16(fs, (XChar2b *)label, (int)(strlen(label) / 2)); 3687a84e134Smrg else 3695ec34c4cSmrg width = XTextWidth(fs, label, (int)strlen(label)); 3707a84e134Smrg if (width > (int) lw->label.label_width) 3715ec34c4cSmrg lw->label.label_width = (Dimension)width; 3727a84e134Smrg } 3737a84e134Smrg } 3747a84e134Smrg else { 3755ec34c4cSmrg lw->label.label_len = (Dimension)strlen(lw->label.label); 3767a84e134Smrg if (lw->label.encoding) 3777a84e134Smrg lw->label.label_width = 3785ec34c4cSmrg (Dimension)XTextWidth16(fs, (XChar2b *)lw->label.label, 3797a84e134Smrg (int)lw->label.label_len / 2); 3807a84e134Smrg else 3817a84e134Smrg lw->label.label_width = 3825ec34c4cSmrg (Dimension)XTextWidth(fs, lw->label.label, (int)lw->label.label_len); 3837a84e134Smrg } 3847a84e134Smrg } 3857a84e134Smrg} 3867a84e134Smrg 3877a84e134Smrgstatic void 3887a84e134SmrgGetNormalGC(LabelWidget lw) 3897a84e134Smrg{ 390efbcb2bfSmrg XGCValues values = { 391efbcb2bfSmrg .foreground = lw->label.foreground, 392efbcb2bfSmrg .background = lw->core.background_pixel, 393efbcb2bfSmrg .font = lw->label.font->fid, 394efbcb2bfSmrg .graphics_exposures = False 395efbcb2bfSmrg }; 3967a84e134Smrg 3977a84e134Smrg if (lw->simple.international == True) 3987a84e134Smrg /* Since Xmb/wcDrawString eats the font, I must use XtAllocateGC */ 3997a84e134Smrg lw->label.normal_GC = XtAllocateGC((Widget)lw, 0, 4007a84e134Smrg GCForeground | GCBackground | 4017a84e134Smrg GCGraphicsExposures, 4027a84e134Smrg &values, GCFont, 0); 4037a84e134Smrg else 4047a84e134Smrg lw->label.normal_GC = XtGetGC((Widget)lw, 4057a84e134Smrg GCForeground | GCBackground | GCFont | 4067a84e134Smrg GCGraphicsExposures, &values); 4077a84e134Smrg} 4087a84e134Smrg 4097a84e134Smrgstatic void 4107a84e134SmrgGetGrayGC(LabelWidget lw) 4117a84e134Smrg{ 412efbcb2bfSmrg XGCValues values = { 413efbcb2bfSmrg .foreground = lw->label.foreground, 414efbcb2bfSmrg .background = lw->core.background_pixel, 415efbcb2bfSmrg .font = lw->label.font->fid, 416efbcb2bfSmrg .fill_style = FillTiled, 417efbcb2bfSmrg .tile = XmuCreateStippledPixmap(XtScreen((Widget)lw), 418efbcb2bfSmrg lw->label.foreground, 419efbcb2bfSmrg lw->core.background_pixel, 420efbcb2bfSmrg lw->core.depth), 421efbcb2bfSmrg .graphics_exposures = False 422efbcb2bfSmrg }; 4237a84e134Smrg 4247a84e134Smrg lw->label.stipple = values.tile; 4257a84e134Smrg if (lw->simple.international == True) 4267a84e134Smrg /* Since Xmb/wcDrawString eats the font, I must use XtAllocateGC */ 4277a84e134Smrg lw->label.gray_GC = XtAllocateGC((Widget)lw, 0, 4287a84e134Smrg GCForeground | GCBackground | 4297a84e134Smrg GCTile | GCFillStyle | 4307a84e134Smrg GCGraphicsExposures, 4317a84e134Smrg &values, GCFont, 0); 4327a84e134Smrg else 433421c997bSmrg lw->label.gray_GC = XtGetGC((Widget)lw, 4347a84e134Smrg GCForeground | GCBackground | 4357a84e134Smrg GCFont | GCTile | GCFillStyle | 4367a84e134Smrg GCGraphicsExposures, 4377a84e134Smrg &values); 4387a84e134Smrg} 4397a84e134Smrg 4407a84e134Smrgstatic void 4417a84e134Smrgcompute_bitmap_offsets(LabelWidget lw) 4427a84e134Smrg{ 4437a84e134Smrg /* 444421c997bSmrg * bitmap will be eventually be displayed at 4457a84e134Smrg * (internal_width, internal_height + lbm_y) 4467a84e134Smrg */ 4477a84e134Smrg if (lw->label.lbm_height != 0) 4485ec34c4cSmrg lw->label.lbm_y = (int)((XtHeight(lw) 4495ec34c4cSmrg - ((lw->label.internal_height * 2) 4505ec34c4cSmrg + lw->label.lbm_height)) / 2); 4517a84e134Smrg else 4527a84e134Smrg lw->label.lbm_y = 0; 4537a84e134Smrg} 4547a84e134Smrg 4557a84e134Smrgstatic void 4567a84e134Smrgset_bitmap_info(LabelWidget lw) 4577a84e134Smrg{ 4587a84e134Smrg Window root; 4597a84e134Smrg int x, y; 4607a84e134Smrg unsigned int bw, depth; 4617a84e134Smrg 4627a84e134Smrg if (!(lw->label.left_bitmap 4637a84e134Smrg && XGetGeometry(XtDisplay(lw), lw->label.left_bitmap, &root, &x, &y, 4647a84e134Smrg &lw->label.lbm_width, &lw->label.lbm_height, 4657a84e134Smrg &bw, &depth))) 4667a84e134Smrg lw->label.lbm_width = lw->label.lbm_height = 0; 4677a84e134Smrg 4687a84e134Smrg compute_bitmap_offsets(lw); 4697a84e134Smrg} 4707a84e134Smrg 4717a84e134Smrg/*ARGSUSED*/ 4727a84e134Smrgstatic void 4735ec34c4cSmrgXawLabelInitialize(Widget request _X_UNUSED, Widget cnew, 4745ec34c4cSmrg ArgList args _X_UNUSED, Cardinal *num_args _X_UNUSED) 4757a84e134Smrg{ 4767a84e134Smrg LabelWidget lw = (LabelWidget)cnew; 4777a84e134Smrg 4787a84e134Smrg if (!lw->label.font) XtError("Aborting: no font found\n"); 479421c997bSmrg if (lw->simple.international && !lw->label.fontset) 4807a84e134Smrg XtError("Aborting: no fontset found\n"); 481421c997bSmrg 482421c997bSmrg if (lw->label.label == NULL) 4837a84e134Smrg lw->label.label = XtNewString(lw->core.name); 4847a84e134Smrg else 4857a84e134Smrg lw->label.label = XtNewString(lw->label.label); 4867a84e134Smrg 4877a84e134Smrg GetNormalGC(lw); 4887a84e134Smrg GetGrayGC(lw); 4897a84e134Smrg 4907a84e134Smrg SetTextWidthAndHeight(lw); 4917a84e134Smrg 4927a84e134Smrg if (XtHeight(lw) == 0) 4935ec34c4cSmrg XtHeight(lw) = (Dimension)(lw->label.label_height + 2 * lw->label.internal_height); 4947a84e134Smrg 4957a84e134Smrg set_bitmap_info(lw); /* need core.height */ 4967a84e134Smrg 4977a84e134Smrg if (XtWidth(lw) == 0) /* need label.lbm_width */ 498efbcb2bfSmrg XtWidth(lw) = (Dimension)(lw->label.label_width 499efbcb2bfSmrg + (unsigned)(2 * lw->label.internal_width) 500efbcb2bfSmrg + LEFT_OFFSET(lw)); 5017a84e134Smrg 5027a84e134Smrg lw->label.label_x = lw->label.label_y = 0; 5037a84e134Smrg (*XtClass(cnew)->core_class.resize)((Widget)lw); 5047a84e134Smrg} 5057a84e134Smrg 5067a84e134Smrg/*ARGSUSED*/ 5077a84e134Smrgstatic void 5087a84e134SmrgXawLabelRedisplay(Widget gw, XEvent *event, Region region) 5097a84e134Smrg{ 5107a84e134Smrg LabelWidget w = (LabelWidget)gw; 5117a84e134Smrg GC gc; 5127a84e134Smrg 5137a84e134Smrg if (*Superclass->core_class.expose != NULL) 5147a84e134Smrg (*Superclass->core_class.expose)(gw, event, region); 5157a84e134Smrg 5167a84e134Smrg gc = XtIsSensitive(gw) ? w->label.normal_GC : w->label.gray_GC; 5177a84e134Smrg 5187a84e134Smrg if (w->label.pixmap == None) { 5197a84e134Smrg int len = w->label.label_len; 5207a84e134Smrg char *label = w->label.label; 5215ec34c4cSmrg Position y = (Position)(w->label.label_y + w->label.font->max_bounds.ascent); 5227a84e134Smrg Position ksy = w->label.label_y; 5237a84e134Smrg 5247a84e134Smrg /* display left bitmap */ 5257a84e134Smrg if (w->label.left_bitmap && w->label.lbm_width != 0) 5267a84e134Smrg XCopyPlane (XtDisplay(gw), w->label.left_bitmap, XtWindow(gw), gc, 5277a84e134Smrg 0, 0, w->label.lbm_width, w->label.lbm_height, 5287a84e134Smrg w->label.internal_width, 5297a84e134Smrg w->label.internal_height + w->label.lbm_y, 1L); 5307a84e134Smrg 5317a84e134Smrg if (w->simple.international == True) { 5327a84e134Smrg XFontSetExtents *ext = XExtentsOfFontSet(w->label.fontset); 5337a84e134Smrg 534efbcb2bfSmrg ksy = (Position) (ksy + XawAbs(ext->max_ink_extent.y)); 5357a84e134Smrg 5367a84e134Smrg if (len == MULTI_LINE_LABEL) { 5377a84e134Smrg char *nl; 5387a84e134Smrg 5395b16253fSmrg while ((nl = strchr(label, '\n')) != NULL) { 5407a84e134Smrg XmbDrawString(XtDisplay(w), XtWindow(w), w->label.fontset, 5417a84e134Smrg gc, w->label.label_x, ksy, label, 5427a84e134Smrg (int)(nl - label)); 543efbcb2bfSmrg ksy = (Position) (ksy + ext->max_ink_extent.height); 5447a84e134Smrg label = nl + 1; 5457a84e134Smrg } 5465ec34c4cSmrg len = (int)strlen(label); 5477a84e134Smrg } 5487a84e134Smrg if (len) 5497a84e134Smrg XmbDrawString(XtDisplay(w), XtWindow(w), w->label.fontset, gc, 5507a84e134Smrg w->label.label_x, ksy, label, len); 5517a84e134Smrg } 5527a84e134Smrg else { 5537a84e134Smrg if (len == MULTI_LINE_LABEL) { 5547a84e134Smrg char *nl; 5557a84e134Smrg 5565b16253fSmrg while ((nl = strchr(label, '\n')) != NULL) { 5577a84e134Smrg if (w->label.encoding) 5587a84e134Smrg XDrawString16(XtDisplay(gw), XtWindow(gw), gc, 5597a84e134Smrg w->label.label_x, y, 560c889a3bfSmrg (XChar2b *)label, (int)(nl - label) / 2); 5617a84e134Smrg else 5627a84e134Smrg XDrawString(XtDisplay(gw), XtWindow(gw), gc, 5637a84e134Smrg w->label.label_x, y, label, (int)(nl - label)); 564efbcb2bfSmrg y += (Position) (w->label.font->max_bounds.ascent + 565efbcb2bfSmrg w->label.font->max_bounds.descent); 5667a84e134Smrg label = nl + 1; 5677a84e134Smrg } 5685ec34c4cSmrg len = (int)strlen(label); 5697a84e134Smrg } 5707a84e134Smrg if (len) { 5717a84e134Smrg if (w->label.encoding) 5727a84e134Smrg XDrawString16(XtDisplay(gw), XtWindow(gw), gc, 573c889a3bfSmrg w->label.label_x, y, (XChar2b *)label, len / 2); 5747a84e134Smrg else 5757a84e134Smrg XDrawString(XtDisplay(gw), XtWindow(gw), gc, 5767a84e134Smrg w->label.label_x, y, label, len); 5777a84e134Smrg } 5787a84e134Smrg } 5797a84e134Smrg } 5807a84e134Smrg else if (w->label.label_len == 1) 5817a84e134Smrg XCopyPlane(XtDisplay(gw), w->label.pixmap, XtWindow(gw), gc, 5827a84e134Smrg 0, 0, w->label.label_width, w->label.label_height, 5837a84e134Smrg w->label.label_x, w->label.label_y, 1L); 5847a84e134Smrg else 5857a84e134Smrg XCopyArea(XtDisplay(gw), w->label.pixmap, XtWindow(gw), gc, 5867a84e134Smrg 0, 0, w->label.label_width, w->label.label_height, 5877a84e134Smrg w->label.label_x, w->label.label_y); 5887a84e134Smrg} 5897a84e134Smrg 5907a84e134Smrgstatic void 5917a84e134Smrg_Reposition(LabelWidget lw, unsigned int width, unsigned int height, 5927a84e134Smrg Position *dx, Position *dy) 5937a84e134Smrg{ 5947a84e134Smrg Position newPos; 595efbcb2bfSmrg Position leftedge = (Position)(lw->label.internal_width + LEFT_OFFSET(lw)); 5967a84e134Smrg 5977a84e134Smrg switch (lw->label.justify) { 5987a84e134Smrg case XtJustifyLeft: 5997a84e134Smrg newPos = leftedge; 6007a84e134Smrg break; 6017a84e134Smrg case XtJustifyRight: 6025ec34c4cSmrg newPos = (Position)(width - (unsigned)(lw->label.label_width + lw->label.internal_width)); 6037a84e134Smrg break; 6047a84e134Smrg case XtJustifyCenter: 6057a84e134Smrg /*FALLTRHOUGH*/ 6067a84e134Smrg default: 6075ec34c4cSmrg newPos = (Position)((int)(width - lw->label.label_width) >> 1); 6087a84e134Smrg break; 6097a84e134Smrg } 6107a84e134Smrg if (newPos < (Position)leftedge) 6117a84e134Smrg newPos = leftedge; 6125ec34c4cSmrg *dx = (Position)(newPos - lw->label.label_x); 6137a84e134Smrg lw->label.label_x = newPos; 6147a84e134Smrg 6155ec34c4cSmrg newPos = (Position)((height - lw->label.label_height) >> 1); 6165ec34c4cSmrg *dy = (Position)(newPos - lw->label.label_y); 6177a84e134Smrg lw->label.label_y = newPos; 6187a84e134Smrg} 6197a84e134Smrg 6207a84e134Smrgstatic void 6217a84e134SmrgXawLabelResize(Widget w) 6227a84e134Smrg{ 6237a84e134Smrg LabelWidget lw = (LabelWidget)w; 6247a84e134Smrg Position dx, dy; 6257a84e134Smrg 6267a84e134Smrg _Reposition(lw, XtWidth(w), XtHeight(w), &dx, &dy); 6277a84e134Smrg compute_bitmap_offsets(lw); 6287a84e134Smrg} 6297a84e134Smrg 6307a84e134Smrg#define PIXMAP 0 6317a84e134Smrg#define WIDTH 1 6327a84e134Smrg#define HEIGHT 2 6337a84e134Smrg#define NUM_CHECKS 3 6347a84e134Smrgstatic Boolean 6357a84e134SmrgXawLabelSetValues(Widget current, Widget request, Widget cnew, 6367a84e134Smrg ArgList args, Cardinal *num_args) 6377a84e134Smrg{ 6387a84e134Smrg LabelWidget curlw = (LabelWidget)current; 6397a84e134Smrg LabelWidget reqlw = (LabelWidget)request; 6407a84e134Smrg LabelWidget newlw = (LabelWidget)cnew; 6417a84e134Smrg Boolean was_resized = False, redisplay = False, checks[NUM_CHECKS]; 642efbcb2bfSmrg Cardinal i; 6437a84e134Smrg 6447a84e134Smrg for (i = 0; i < NUM_CHECKS; i++) 6457a84e134Smrg checks[i] = False; 6467a84e134Smrg 6477a84e134Smrg for (i = 0; i < *num_args; i++) { 6487a84e134Smrg if (streq(XtNbitmap, args[i].name)) 6497a84e134Smrg checks[PIXMAP] = True; 6507a84e134Smrg else if (streq(XtNwidth, args[i].name)) 6517a84e134Smrg checks[WIDTH] = True; 6527a84e134Smrg else if (streq(XtNheight, args[i].name)) 6537a84e134Smrg checks[HEIGHT] = True; 6547a84e134Smrg } 6557a84e134Smrg 6567a84e134Smrg if (newlw->label.label == NULL) 6575ec34c4cSmrg newlw->label.label = (char *)newlw->core.name; 6587a84e134Smrg 6597a84e134Smrg /* 6607a84e134Smrg * resize on bitmap change 6617a84e134Smrg */ 6627a84e134Smrg if (curlw->label.left_bitmap != newlw->label.left_bitmap) 6637a84e134Smrg was_resized = True; 6647a84e134Smrg 6657a84e134Smrg if (curlw->label.encoding != newlw->label.encoding) 6667a84e134Smrg was_resized = True; 6677a84e134Smrg 668421c997bSmrg if (curlw->simple.international 6697a84e134Smrg && curlw->label.fontset != newlw->label.fontset) 6707a84e134Smrg was_resized = True; 6717a84e134Smrg 6727a84e134Smrg if (curlw->label.label != newlw->label.label) { 6737a84e134Smrg if (curlw->label.label != curlw->core.name) 6747a84e134Smrg XtFree((char *)curlw->label.label); 6757a84e134Smrg 6767a84e134Smrg if (newlw->label.label != newlw->core.name) 6777a84e134Smrg newlw->label.label = XtNewString(newlw->label.label); 6787a84e134Smrg 6797a84e134Smrg was_resized = True; 6807a84e134Smrg } 6817a84e134Smrg 6827a84e134Smrg if (was_resized || (curlw->label.font != newlw->label.font) || 6837a84e134Smrg curlw->label.justify != newlw->label.justify || checks[PIXMAP]) { 6847a84e134Smrg SetTextWidthAndHeight(newlw); 6857a84e134Smrg was_resized = True; 6867a84e134Smrg } 6877a84e134Smrg 6887a84e134Smrg /* recalculate the window size if something has changed */ 6897a84e134Smrg if (newlw->label.resize && was_resized) { 6907a84e134Smrg if (XtHeight(curlw) == XtHeight(reqlw) && !checks[HEIGHT]) 6915ec34c4cSmrg XtHeight(newlw) = (Dimension)(newlw->label.label_height + 6925ec34c4cSmrg (newlw->label.internal_height << 1)); 6937a84e134Smrg 6947a84e134Smrg set_bitmap_info(newlw); 6957a84e134Smrg 6967a84e134Smrg if (XtWidth(curlw) == XtWidth(reqlw) && !checks[WIDTH]) 697efbcb2bfSmrg XtWidth(newlw) = (Dimension)(newlw->label.label_width 698efbcb2bfSmrg + LEFT_OFFSET(newlw) 699efbcb2bfSmrg + (unsigned)(newlw->label.internal_width << 1)); 7007a84e134Smrg } 7017a84e134Smrg 7027a84e134Smrg if (curlw->label.foreground != newlw->label.foreground 7037a84e134Smrg || curlw->core.background_pixel != newlw->core.background_pixel 7047a84e134Smrg || curlw->label.font->fid != newlw->label.font->fid) { 7057a84e134Smrg /* The Fontset is not in the GC - don't make a new GC if FS changes! */ 7067a84e134Smrg XtReleaseGC(cnew, curlw->label.normal_GC); 7077a84e134Smrg XtReleaseGC(cnew, curlw->label.gray_GC); 7087a84e134Smrg XmuReleaseStippledPixmap(XtScreen(current), curlw->label.stipple); 7097a84e134Smrg GetNormalGC(newlw); 7107a84e134Smrg GetGrayGC(newlw); 7117a84e134Smrg redisplay = True; 7127a84e134Smrg } 7137a84e134Smrg 7147a84e134Smrg if (curlw->label.label_x != newlw->label.label_x || 7157a84e134Smrg curlw->label.label_y != newlw->label.label_y) 7167a84e134Smrg redisplay = True; 7177a84e134Smrg 7187a84e134Smrg if (curlw->label.internal_width != newlw->label.internal_width 7197a84e134Smrg || curlw->label.internal_height != newlw->label.internal_height 7207a84e134Smrg || was_resized) { 7217a84e134Smrg /* Resize() will be called if geometry changes succeed */ 7227a84e134Smrg Position dx, dy; 7237a84e134Smrg 7247a84e134Smrg _Reposition(newlw, XtWidth(curlw), XtHeight(curlw), &dx, &dy); 7257a84e134Smrg } 7267a84e134Smrg 7277a84e134Smrg return (was_resized || redisplay || 7287a84e134Smrg XtIsSensitive(current) != XtIsSensitive(cnew)); 7297a84e134Smrg} 7307a84e134Smrg 7317a84e134Smrgstatic void 7327a84e134SmrgXawLabelDestroy(Widget w) 7337a84e134Smrg{ 7347a84e134Smrg LabelWidget lw = (LabelWidget)w; 7357a84e134Smrg 7367a84e134Smrg if (lw->label.label != lw->core.name) 7377a84e134Smrg XtFree(lw->label.label); 7387a84e134Smrg XtReleaseGC(w, lw->label.normal_GC); 7397a84e134Smrg XtReleaseGC(w, lw->label.gray_GC); 7407a84e134Smrg XmuReleaseStippledPixmap(XtScreen(w), lw->label.stipple); 7417a84e134Smrg} 7427a84e134Smrg 7437a84e134Smrgstatic XtGeometryResult 7447a84e134SmrgXawLabelQueryGeometry(Widget w, XtWidgetGeometry *intended, 7457a84e134Smrg XtWidgetGeometry *preferred) 7467a84e134Smrg{ 7477a84e134Smrg LabelWidget lw = (LabelWidget)w; 7487a84e134Smrg 7497a84e134Smrg preferred->request_mode = CWWidth | CWHeight; 750efbcb2bfSmrg preferred->width = (Dimension)(lw->label.label_width 751efbcb2bfSmrg + (unsigned)(lw->label.internal_width << 1) 752efbcb2bfSmrg + LEFT_OFFSET(lw)); 7535ec34c4cSmrg preferred->height = (Dimension)(lw->label.label_height + 7545ec34c4cSmrg (lw->label.internal_height << 1)); 7557a84e134Smrg 7567a84e134Smrg if (((intended->request_mode & (CWWidth | CWHeight)) == (CWWidth | CWHeight)) 7577a84e134Smrg && intended->width == preferred->width 7587a84e134Smrg && intended->height == preferred->height) 7597a84e134Smrg return (XtGeometryYes); 7607a84e134Smrg else if (preferred->width == XtWidth(w) && preferred->height == XtHeight(w)) 7617a84e134Smrg return (XtGeometryNo); 7627a84e134Smrg 7637a84e134Smrg return (XtGeometryAlmost); 7647a84e134Smrg} 765