Label.c

Go to the documentation of this file.
00001 /* $XConsortium: Label.c,v 1.97 94/04/17 20:12:12 kaleb Exp $ */
00002 
00003 /***********************************************************
00004 
00005 Copyright (c) 1987, 1988, 1994  X Consortium
00006 
00007 Permission is hereby granted, free of charge, to any person obtaining a copy
00008 of this software and associated documentation files (the "Software"), to deal
00009 in the Software without restriction, including without limitation the rights
00010 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00011 copies of the Software, and to permit persons to whom the Software is
00012 furnished to do so, subject to the following conditions:
00013 
00014 The above copyright notice and this permission notice shall be included in
00015 all copies or substantial portions of the Software.
00016 
00017 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00018 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
00020 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00021 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00022 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00023 
00024 Except as contained in this notice, the name of the X Consortium shall not be
00025 used in advertising or otherwise to promote the sale, use or other dealings
00026 in this Software without prior written authorization from the X Consortium.
00027 
00028 
00029 Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
00030 
00031                         All Rights Reserved
00032 
00033 Permission to use, copy, modify, and distribute this software and its 
00034 documentation for any purpose and without fee is hereby granted, 
00035 provided that the above copyright notice appear in all copies and that
00036 both that copyright notice and this permission notice appear in 
00037 supporting documentation, and that the name of Digital not be
00038 used in advertising or publicity pertaining to distribution of the
00039 software without specific, written prior permission.  
00040 
00041 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
00042 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
00043 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
00044 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
00045 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
00046 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
00047 SOFTWARE.
00048 
00049 ******************************************************************/
00050 
00051 /*
00052  * Label.c - Label widget
00053  *
00054  */
00055 
00056 #include <X11/IntrinsicP.h>
00057 #include <X11/StringDefs.h>
00058 #include <X11/Xos.h>
00059 #include <X11/Xaw3d/XawInit.h>
00060 #include <X11/Xaw3d/LabelP.h>
00061 #include <X11/Xmu/Converters.h>
00062 #include <X11/Xmu/Drawing.h>
00063 #include <stdio.h>
00064 #include <ctype.h>
00065 
00066 /* needed for abs() */
00067 #ifndef X_NOT_STDC_ENV
00068 #include <stdlib.h>
00069 #else
00070 int abs();
00071 #endif
00072 
00073 #define streq(a,b) (strcmp( (a), (b) ) == 0)
00074 
00075 #define MULTI_LINE_LABEL 32767
00076 
00077 #ifdef CRAY
00078 #define WORD64
00079 #endif
00080 
00081 /****************************************************************
00082  *
00083  * Full class record constant
00084  *
00085  ****************************************************************/
00086 
00087 /* Private Data */
00088 
00089 #define offset(field) XtOffsetOf(LabelRec, field)
00090 static XtResource resources[] = {
00091     {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel),
00092         offset(label.foreground), XtRString, XtDefaultForeground},
00093     {XtNfont,  XtCFont, XtRFontStruct, sizeof(XFontStruct *),
00094         offset(label.font),XtRString, XtDefaultFont},
00095     {XtNfontSet,  XtCFontSet, XtRFontSet, sizeof(XFontSet ),
00096         offset(label.fontset),XtRString, XtDefaultFontSet},
00097     {XtNlabel,  XtCLabel, XtRString, sizeof(String),
00098         offset(label.label), XtRString, NULL},
00099     {XtNencoding, XtCEncoding, XtRUnsignedChar, sizeof(unsigned char),
00100         offset(label.encoding), XtRImmediate, (XtPointer)XawTextEncoding8bit},
00101     {XtNjustify, XtCJustify, XtRJustify, sizeof(XtJustify),
00102         offset(label.justify), XtRImmediate, (XtPointer)XtJustifyCenter},
00103     {XtNinternalWidth, XtCWidth, XtRDimension,  sizeof(Dimension),
00104         offset(label.internal_width), XtRImmediate, (XtPointer)4},
00105     {XtNinternalHeight, XtCHeight, XtRDimension, sizeof(Dimension),
00106         offset(label.internal_height), XtRImmediate, (XtPointer)2},
00107     {XtNleftBitmap, XtCLeftBitmap, XtRBitmap, sizeof(Pixmap),
00108        offset(label.left_bitmap), XtRImmediate, (XtPointer) None},
00109     {XtNbitmap, XtCPixmap, XtRBitmap, sizeof(Pixmap),
00110         offset(label.pixmap), XtRImmediate, (XtPointer)None},
00111     {XtNresize, XtCResize, XtRBoolean, sizeof(Boolean),
00112         offset(label.resize), XtRImmediate, (XtPointer)True},
00113     {XtNshadowWidth, XtCShadowWidth, XtRDimension, sizeof(Dimension),
00114         offset(threeD.shadow_width), XtRImmediate, (XtPointer) 0},
00115     {XtNborderWidth, XtCBorderWidth, XtRDimension, sizeof(Dimension),
00116          XtOffsetOf(RectObjRec,rectangle.border_width), XtRImmediate,
00117          (XtPointer)1}
00118 };
00119 #undef offset
00120 
00121 static void Initialize();
00122 static void Resize();
00123 static void Redisplay();
00124 static Boolean SetValues();
00125 static void ClassInitialize();
00126 static void Destroy();
00127 static XtGeometryResult QueryGeometry();
00128 
00129 LabelClassRec labelClassRec = {
00130   {
00131 /* core_class fields */ 
00132     /* superclass               */      (WidgetClass) &threeDClassRec,
00133     /* class_name               */      "Label",
00134     /* widget_size              */      sizeof(LabelRec),
00135     /* class_initialize         */      ClassInitialize,
00136     /* class_part_initialize    */      NULL,
00137     /* class_inited             */      FALSE,
00138     /* initialize               */      Initialize,
00139     /* initialize_hook          */      NULL,
00140     /* realize                  */      XtInheritRealize,
00141     /* actions                  */      NULL,
00142     /* num_actions              */      0,
00143     /* resources                */      resources,
00144     /* num_resources            */      XtNumber(resources),
00145     /* xrm_class                */      NULLQUARK,
00146     /* compress_motion          */      TRUE,
00147     /* compress_exposure        */      TRUE,
00148     /* compress_enterleave      */      TRUE,
00149     /* visible_interest         */      FALSE,
00150     /* destroy                  */      Destroy,
00151     /* resize                   */      Resize,
00152     /* expose                   */      Redisplay,
00153     /* set_values               */      SetValues,
00154     /* set_values_hook          */      NULL,
00155     /* set_values_almost        */      XtInheritSetValuesAlmost,
00156     /* get_values_hook          */      NULL,
00157     /* accept_focus             */      NULL,
00158     /* version                  */      XtVersion,
00159     /* callback_private         */      NULL,
00160     /* tm_table                 */      NULL,
00161     /* query_geometry           */      QueryGeometry,
00162     /* display_accelerator      */      XtInheritDisplayAccelerator,
00163     /* extension                */      NULL
00164   },
00165 /* Simple class fields initialization */
00166   {
00167     /* change_sensitive         */      XtInheritChangeSensitive
00168   },
00169 /* ThreeD class fields initialization */
00170   {
00171     /* shadowdraw               */      XtInheritXaw3dShadowDraw
00172   },
00173 /* Label class fields initialization */
00174   {
00175     /* ignore                   */      0
00176   }
00177 };
00178 WidgetClass labelWidgetClass = (WidgetClass)&labelClassRec;
00179 /****************************************************************
00180  *
00181  * Private Procedures
00182  *
00183  ****************************************************************/
00184 
00185 static void ClassInitialize()
00186 {
00187     XawInitializeWidgetSet();
00188     XtAddConverter( XtRString, XtRJustify, XmuCvtStringToJustify, 
00189                     (XtConvertArgList)NULL, 0 );
00190 }
00191 
00192 #ifndef WORD64
00193 
00194 #define TXT16 XChar2b
00195 
00196 #else
00197 
00198 #define TXT16 char
00199 
00200 static XChar2b *buf2b;
00201 static int buf2blen = 0;
00202 
00203 _XawLabelWidth16(fs, str, n)
00204     XFontStruct *fs;
00205     char *str;
00206     int n;
00207 {
00208     int i;
00209     XChar2b *ptr;
00210 
00211     if (n > buf2blen) {
00212         buf2b = (XChar2b *)XtRealloc((char *)buf2b, n * sizeof(XChar2b));
00213         buf2blen = n;
00214     }
00215     for (ptr = buf2b, i = n; --i >= 0; ptr++) {
00216         ptr->byte1 = *str++;
00217         ptr->byte2 = *str++;
00218     }
00219     return XTextWidth16(fs, buf2b, n);
00220 }
00221 
00222 _XawLabelDraw16(dpy, d, gc, x, y, str, n)
00223     Display *dpy;
00224     Drawable d;
00225     GC gc;
00226     int x, y;
00227     char *str;
00228     int n;
00229 {
00230     int i;
00231     XChar2b *ptr;
00232 
00233     if (n > buf2blen) {
00234         buf2b = (XChar2b *)XtRealloc((char *)buf2b, n * sizeof(XChar2b));
00235         buf2blen = n;
00236     }
00237     for (ptr = buf2b, i = n; --i >= 0; ptr++) {
00238         ptr->byte1 = *str++;
00239         ptr->byte2 = *str++;
00240     }
00241     XDrawString16(dpy, d, gc, x, y, buf2b, n);
00242 }
00243 
00244 #define XTextWidth16 _XawLabelWidth16
00245 #define XDrawString16 _XawLabelDraw16
00246 
00247 #endif /* WORD64 */
00248 
00249 /*
00250  * Calculate width and height of displayed text in pixels
00251  */
00252 
00253 static void SetTextWidthAndHeight(lw)
00254     LabelWidget lw;
00255 {
00256     XFontStruct *fs = lw->label.font;
00257 
00258     char *nl;
00259 
00260     if (lw->label.pixmap != None) {
00261         Window root;
00262         int x, y;
00263         unsigned int width, height, bw, depth;
00264         if (XGetGeometry(XtDisplay(lw), lw->label.pixmap, &root, &x, &y,
00265                          &width, &height, &bw, &depth)) {
00266             lw->label.label_height = height;
00267             lw->label.label_width = width;
00268             lw->label.label_len = depth;
00269             return;
00270         }
00271     }
00272     if ( lw->simple.international == True ) {
00273 
00274       XFontSet  fset = lw->label.fontset;
00275       XFontSetExtents *ext = XExtentsOfFontSet(fset);
00276 
00277       lw->label.label_height = ext->max_ink_extent.height;
00278       if (lw->label.label == NULL) {
00279           lw->label.label_len = 0;
00280           lw->label.label_width = 0;
00281       }
00282       else if ((nl = index(lw->label.label, '\n')) != NULL) {
00283           char *label;
00284           lw->label.label_len = MULTI_LINE_LABEL;
00285           lw->label.label_width = 0;
00286           for (label = lw->label.label; nl != NULL; nl = index(label, '\n')) {
00287               int width = XmbTextEscapement(fset, label, (int)(nl - label));
00288 
00289               if (width > (int)lw->label.label_width)
00290                   lw->label.label_width = width;
00291               label = nl + 1;
00292               if (*label)
00293                   lw->label.label_height +=
00294                       ext->max_ink_extent.height;
00295           }
00296           if (*label) {
00297               int width = XmbTextEscapement(fset, label, strlen(label));
00298 
00299               if (width > (int) lw->label.label_width)
00300                   lw->label.label_width = width;
00301           }
00302       } else {
00303           lw->label.label_len = strlen(lw->label.label);
00304           lw->label.label_width =
00305               XmbTextEscapement(fset, lw->label.label, (int) lw->label.label_len);
00306       }
00307 
00308     } else {
00309 
00310         lw->label.label_height = fs->max_bounds.ascent + fs->max_bounds.descent;
00311         if (lw->label.label == NULL) {
00312             lw->label.label_len = 0;
00313             lw->label.label_width = 0;
00314         }
00315         else if ((nl = index(lw->label.label, '\n')) != NULL) {
00316             char *label;
00317             lw->label.label_len = MULTI_LINE_LABEL;
00318             lw->label.label_width = 0;
00319             for (label = lw->label.label; nl != NULL; nl = index(label, '\n')) {
00320                 int width;
00321 
00322                 if (lw->label.encoding)
00323                     width = XTextWidth16(fs, (TXT16*)label, (int)(nl - label)/2);
00324                 else
00325                     width = XTextWidth(fs, label, (int)(nl - label));
00326                 if (width > (int)lw->label.label_width)
00327                     lw->label.label_width = width;
00328                 label = nl + 1;
00329                 if (*label)
00330                     lw->label.label_height +=
00331                         fs->max_bounds.ascent + fs->max_bounds.descent;
00332             }
00333             if (*label) {
00334                 int width = XTextWidth(fs, label, strlen(label));
00335 
00336                 if (lw->label.encoding)
00337                     width = XTextWidth16(fs, (TXT16*)label, (int)strlen(label)/2);
00338                 else
00339                     width = XTextWidth(fs, label, strlen(label));
00340                 if (width > (int) lw->label.label_width)
00341                     lw->label.label_width = width;
00342             }
00343         } else {
00344             lw->label.label_len = strlen(lw->label.label);
00345             if (lw->label.encoding)
00346                 lw->label.label_width =
00347                     XTextWidth16(fs, (TXT16*)lw->label.label,
00348                                  (int) lw->label.label_len/2);
00349             else
00350                 lw->label.label_width =
00351                     XTextWidth(fs, lw->label.label, (int) lw->label.label_len);
00352         }
00353 
00354     }
00355 }
00356 
00357 static void GetnormalGC(lw)
00358     LabelWidget lw;
00359 {
00360     XGCValues   values;
00361 
00362     values.foreground   = lw->label.foreground;
00363     values.background   = lw->core.background_pixel;
00364     values.font         = lw->label.font->fid;
00365     values.graphics_exposures = False;
00366 
00367     if ( lw->simple.international == True )
00368         /* Since Xmb/wcDrawString eats the font, I must use XtAllocateGC. */
00369         lw->label.normal_GC = XtAllocateGC(
00370                 (Widget)lw, 0,
00371         (unsigned) GCForeground | GCBackground | GCGraphicsExposures,
00372         &values, GCFont, 0 );
00373     else
00374         lw->label.normal_GC = XtGetGC(
00375         (Widget)lw,
00376         (unsigned) GCForeground | GCBackground | GCFont | GCGraphicsExposures,
00377         &values);
00378 }
00379 
00380 static void GetgrayGC(lw)
00381     LabelWidget lw;
00382 {
00383     XGCValues   values;
00384 
00385     values.foreground = lw->label.foreground;
00386     values.background = lw->core.background_pixel;
00387     values.font       = lw->label.font->fid;
00388     values.fill_style = FillTiled;
00389     values.tile       = XmuCreateStippledPixmap(XtScreen((Widget)lw),
00390                                                 lw->label.foreground, 
00391                                                 lw->core.background_pixel,
00392                                                 lw->core.depth);
00393     values.graphics_exposures = False;
00394 
00395     lw->label.stipple = values.tile;
00396     if ( lw->simple.international == True )
00397         /* Since Xmb/wcDrawString eats the font, I must use XtAllocateGC. */
00398         lw->label.gray_GC = XtAllocateGC((Widget)lw,  0,
00399                                 (unsigned) GCForeground | GCBackground |
00400                                            GCTile | GCFillStyle |
00401                                            GCGraphicsExposures,
00402                                 &values, GCFont, 0);
00403     else
00404         lw->label.gray_GC = XtGetGC((Widget)lw, 
00405                                 (unsigned) GCForeground | GCBackground |
00406                                            GCFont | GCTile | GCFillStyle |
00407                                            GCGraphicsExposures,
00408                                 &values);
00409 }
00410 
00411 static void compute_bitmap_offsets (lw)
00412     LabelWidget lw;
00413 {
00414     /*
00415      * bitmap will be eventually be displayed at 
00416      * (internal_width, internal_height + lbm_y)
00417      */
00418     if (lw->label.lbm_height != 0) {
00419         lw->label.lbm_y = (lw->core.height -
00420                           (lw->threeD.shadow_width * 2 + 
00421                            lw->label.internal_height * 2 +
00422                            lw->label.lbm_height)) / 2;
00423     } else {
00424         lw->label.lbm_y = 0;
00425     }
00426 }
00427 
00428 
00429 static void set_bitmap_info (lw)
00430     LabelWidget lw;
00431 {
00432     Window root;
00433     int x, y;
00434     unsigned int bw, depth;
00435 
00436     if (!(lw->label.left_bitmap &&
00437           XGetGeometry (XtDisplay(lw), lw->label.left_bitmap, &root, &x, &y,
00438                         &lw->label.lbm_width, &lw->label.lbm_height,
00439                         &bw, &depth))) {
00440         lw->label.lbm_width = lw->label.lbm_height = 0;
00441     }
00442     compute_bitmap_offsets (lw);
00443 }
00444 
00445 
00446 
00447 /* ARGSUSED */
00448 static void Initialize(request, new, args, num_args)
00449     Widget request, new;
00450     ArgList args;
00451     Cardinal *num_args;
00452 {
00453     LabelWidget lw = (LabelWidget) new;
00454 
00455     if (lw->label.label == NULL) 
00456         lw->label.label = XtNewString(lw->core.name);
00457     else {
00458         lw->label.label = XtNewString(lw->label.label);
00459     }
00460 
00461     GetnormalGC(lw);
00462     GetgrayGC(lw);
00463 
00464     SetTextWidthAndHeight(lw);
00465 
00466     if (lw->core.height == 0)
00467         lw->core.height = lw->label.label_height +
00468                             2 * lw->label.internal_height +
00469                             2 * lw->threeD.shadow_width;
00470 
00471     set_bitmap_info (lw);               /* need core.height */
00472 
00473     if (lw->core.width == 0)            /* need label.lbm_width */
00474         lw->core.width = (lw->label.label_width +
00475                             2 * lw->label.internal_width +
00476                             2 * lw->threeD.shadow_width +
00477                             LEFT_OFFSET(lw));
00478 
00479     lw->label.label_x = lw->label.label_y = 0;
00480     (*XtClass(new)->core_class.resize) ((Widget)lw);
00481 
00482 } /* Initialize */
00483 
00484 /*
00485  * Repaint the widget window
00486  */
00487 
00488 /* ARGSUSED */
00489 static void Redisplay(gw, event, region)
00490     Widget gw;
00491     XEvent *event;
00492     Region region;
00493 {
00494     extern WidgetClass commandWidgetClass;
00495     LabelWidget w = (LabelWidget) gw;
00496     LabelWidgetClass lwclass = (LabelWidgetClass) XtClass (gw);
00497     GC gc;
00498 
00499     /* 
00500      * Don't draw shadows if command is going to redraw them.
00501      * The shadow draw method is region aware, but since 99% of
00502      * all labels don't have shadows, we'll check for a shadow
00503      * before we incur the function call overhead.
00504      */
00505     if (!XtIsSubclass (gw, commandWidgetClass) && w->threeD.shadow_width > 0)
00506         (*lwclass->threeD_class.shadowdraw) (gw, event, region, True);
00507 
00508     /*
00509      * now we'll see if we need to draw the rest of the label
00510      */
00511     if (region != NULL) {
00512         int x = w->label.label_x;
00513         unsigned int width = w->label.label_width;
00514         if (w->label.lbm_width) {
00515             if (w->label.label_x > (x = w->label.internal_width))
00516                 width += w->label.label_x - x;
00517         }
00518         if (XRectInRegion(region, x, w->label.label_y,
00519                          width, w->label.label_height) == RectangleOut){
00520             return;
00521         }
00522     }
00523 
00524     gc = XtIsSensitive(gw) ? w->label.normal_GC : w->label.gray_GC;
00525 #ifdef notdef
00526     if (region != NULL)
00527         XSetRegion(XtDisplay(gw), gc, region);
00528 #endif /*notdef*/
00529 
00530     if (w->label.pixmap == None) {
00531         int len = w->label.label_len;
00532         char *label = w->label.label;
00533         Position y = w->label.label_y + w->label.font->max_bounds.ascent;
00534         Position ksy = w->label.label_y;
00535 
00536         /* display left bitmap */
00537         if (w->label.left_bitmap && w->label.lbm_width != 0) {
00538             XCopyPlane (XtDisplay(gw), w->label.left_bitmap, XtWindow(gw), gc,
00539                        0, 0, w->label.lbm_width, w->label.lbm_height,
00540                        (int) w->label.internal_width
00541                         + w->threeD.shadow_width,
00542                        (int) w->label.internal_height 
00543                         + w->threeD.shadow_width
00544                         + w->label.lbm_y, 
00545                        (unsigned long) 1L);
00546         }
00547 
00548         if ( w->simple.international == True ) {
00549 
00550             XFontSetExtents *ext = XExtentsOfFontSet(w->label.fontset);
00551 
00552             ksy += abs(ext->max_ink_extent.y);
00553 
00554             if (len == MULTI_LINE_LABEL) {
00555                 char *nl;
00556                 while ((nl = index(label, '\n')) != NULL) {
00557                     XmbDrawString(XtDisplay(w), XtWindow(w), w->label.fontset, gc,
00558                                 w->label.label_x, ksy, label, (int)(nl - label));
00559                     ksy += ext->max_ink_extent.height;
00560                     label = nl + 1;
00561                 }
00562                 len = strlen(label);
00563             }
00564             if (len)
00565                 XmbDrawString(XtDisplay(w), XtWindow(w), w->label.fontset, gc,
00566                               w->label.label_x, ksy, label, len);
00567 
00568         } else { /*international false, so use R5 routine */
00569 
00570             if (len == MULTI_LINE_LABEL) {
00571                 char *nl;
00572                 while ((nl = index(label, '\n')) != NULL) {
00573                     if (w->label.encoding)
00574                         XDrawString16(XtDisplay(gw), XtWindow(gw), gc,
00575                                                 w->label.label_x, y,
00576                                                 (TXT16*)label, (int)(nl - label)/2);
00577                     else
00578                         XDrawString(XtDisplay(gw), XtWindow(gw), gc,
00579                                         w->label.label_x, y, label, (int)(nl - label));
00580                     y += w->label.font->max_bounds.ascent + 
00581                                         w->label.font->max_bounds.descent;
00582                     label = nl + 1;
00583                 }
00584                 len = strlen(label);
00585             }
00586             if (len) {
00587                 if (w->label.encoding)
00588                     XDrawString16(XtDisplay(gw), XtWindow(gw), gc,
00589                              w->label.label_x, y, (TXT16*)label, len/2);
00590                 else
00591                     XDrawString(XtDisplay(gw), XtWindow(gw), gc,
00592                            w->label.label_x, y, label, len);
00593             }
00594 
00595         } /*endif international*/
00596 
00597     } else if (w->label.label_len == 1) { /* depth */
00598         XCopyPlane(XtDisplay(gw), w->label.pixmap, XtWindow(gw), gc,
00599                                 0, 0, w->label.label_width, w->label.label_height,
00600                                 w->label.label_x, w->label.label_y, 1L);
00601     } else {
00602         XCopyArea(XtDisplay(gw), w->label.pixmap, XtWindow(gw), gc,
00603                                 0, 0, w->label.label_width, w->label.label_height,
00604                                 w->label.label_x, w->label.label_y);
00605     }
00606 
00607 #ifdef notdef
00608     if (region != NULL)
00609         XSetClipMask(XtDisplay(gw), gc, (Pixmap)None);
00610 #endif /* notdef */
00611 }
00612 
00613 static void _Reposition(lw, width, height, dx, dy)
00614     LabelWidget lw;
00615     Dimension width, height;
00616     Position *dx, *dy;
00617 {
00618     Position newPos;
00619     Position leftedge = lw->label.internal_width + LEFT_OFFSET(lw) +
00620                         lw->threeD.shadow_width;
00621 
00622     switch (lw->label.justify) {
00623 
00624         case XtJustifyLeft   :
00625             newPos = leftedge;
00626             break;
00627 
00628         case XtJustifyRight  :
00629             newPos = width -
00630                 (lw->label.label_width 
00631                         + lw->label.internal_width 
00632                         + lw->threeD.shadow_width);
00633             break;
00634 
00635         case XtJustifyCenter :
00636         default:
00637             newPos = (int)(width - lw->label.label_width) / 2;
00638             break;
00639     }
00640     if (newPos < (Position)leftedge)
00641         newPos = leftedge;
00642     *dx = newPos - lw->label.label_x;
00643     lw->label.label_x = newPos;
00644     *dy = (newPos = (int)(height - lw->label.label_height) / 2)
00645           - lw->label.label_y;
00646     lw->label.label_y = newPos;
00647     return;
00648 }
00649 
00650 static void Resize(w)
00651     Widget w;
00652 {
00653     LabelWidget lw = (LabelWidget)w;
00654     Position dx, dy;
00655 
00656     _Reposition(lw, w->core.width, w->core.height, &dx, &dy);
00657     compute_bitmap_offsets (lw);
00658 }
00659 
00660 /*
00661  * Set specified arguments into widget
00662  */
00663 
00664 #define PIXMAP 0
00665 #define WIDTH 1
00666 #define HEIGHT 2
00667 #define NUM_CHECKS 3
00668 
00669 static Boolean SetValues(current, request, new, args, num_args)
00670     Widget current, request, new;
00671     ArgList args;
00672     Cardinal *num_args;
00673 {
00674     LabelWidget curlw = (LabelWidget) current;
00675     LabelWidget reqlw = (LabelWidget) request;
00676     LabelWidget newlw = (LabelWidget) new;
00677     int i;
00678     Boolean was_resized = False, redisplay = False, checks[NUM_CHECKS];
00679 
00680     for (i = 0; i < NUM_CHECKS; i++)
00681         checks[i] = FALSE;
00682 
00683     for (i = 0; i < *num_args; i++) {
00684         if (streq(XtNbitmap, args[i].name))
00685             checks[PIXMAP] = TRUE;
00686         if (streq(XtNwidth, args[i].name))
00687             checks[WIDTH] = TRUE;
00688         if (streq(XtNheight, args[i].name))
00689             checks[HEIGHT] = TRUE;
00690     }
00691 
00692     if (newlw->label.label == NULL) {
00693         newlw->label.label = newlw->core.name;
00694     }
00695 
00696     /*
00697      * resize on bitmap change
00698      */
00699     if (curlw->label.left_bitmap != newlw->label.left_bitmap) {
00700         was_resized = True;
00701     }
00702 
00703     if (curlw->label.encoding != newlw->label.encoding)
00704         was_resized = True;
00705 
00706     if ( (curlw->label.fontset != newlw->label.fontset) &&
00707                                          curlw->simple.international ){
00708         was_resized = True;
00709     }
00710     if (curlw->label.label != newlw->label.label) {
00711         if (curlw->label.label != curlw->core.name)
00712             XtFree( (char *)curlw->label.label );
00713 
00714         if (newlw->label.label != newlw->core.name) {
00715             newlw->label.label = XtNewString( newlw->label.label );
00716         }
00717         was_resized = True;
00718     }
00719 
00720     if (was_resized || (curlw->label.font != newlw->label.font) ||
00721         (curlw->label.justify != newlw->label.justify) || checks[PIXMAP]) {
00722 
00723         SetTextWidthAndHeight(newlw);
00724         was_resized = True;
00725     }
00726 
00727     /* recalculate the window size if something has changed. */
00728     if (newlw->label.resize && was_resized) {
00729         if ((curlw->core.height == reqlw->core.height) && !checks[HEIGHT])
00730             newlw->core.height = (newlw->label.label_height +
00731                                     2 * newlw->label.internal_height +
00732                                     2 * newlw->threeD.shadow_width);
00733 
00734         set_bitmap_info (newlw);
00735 
00736         if ((curlw->core.width == reqlw->core.width) && !checks[WIDTH])
00737             newlw->core.width = (newlw->label.label_width +
00738                                     LEFT_OFFSET(newlw) +
00739                                     2 * newlw->label.internal_width +
00740                                     2 * newlw->threeD.shadow_width);
00741     }
00742 
00743     if (curlw->label.foreground         != newlw->label.foreground
00744         || curlw->core.background_pixel != newlw->core.background_pixel
00745         || curlw->label.font->fid       != newlw->label.font->fid         ) {
00746 
00747         /* The Fontset is not in the GC - don't make a new GC if FS changes! */
00748 
00749         XtReleaseGC(new, curlw->label.normal_GC);
00750         XtReleaseGC(new, curlw->label.gray_GC);
00751         XmuReleaseStippledPixmap( XtScreen(current), curlw->label.stipple );
00752         GetnormalGC(newlw);
00753         GetgrayGC(newlw);
00754         redisplay = True;
00755     }
00756 
00757     if ((curlw->label.internal_width != newlw->label.internal_width)
00758         || (curlw->label.internal_height != newlw->label.internal_height)
00759         || was_resized) {
00760         /* Resize() will be called if geometry changes succeed */
00761         Position dx, dy;
00762         _Reposition(newlw, curlw->core.width, curlw->core.height, &dx, &dy);
00763     }
00764 
00765     return was_resized || redisplay ||
00766            XtIsSensitive(current) != XtIsSensitive(new);
00767 }
00768 
00769 static void Destroy(w)
00770     Widget w;
00771 {
00772     LabelWidget lw = (LabelWidget)w;
00773 
00774     if ( lw->label.label != lw->core.name )
00775         XtFree( lw->label.label );
00776     XtReleaseGC( w, lw->label.normal_GC );
00777     XtReleaseGC( w, lw->label.gray_GC);
00778     XmuReleaseStippledPixmap( XtScreen(w), lw->label.stipple );
00779 }
00780 
00781 
00782 static XtGeometryResult QueryGeometry(w, intended, preferred)
00783     Widget w;
00784     XtWidgetGeometry *intended, *preferred;
00785 {
00786     LabelWidget lw = (LabelWidget)w;
00787 
00788     preferred->request_mode = CWWidth | CWHeight;
00789     preferred->width = (lw->label.label_width + 
00790                             2 * lw->label.internal_width +
00791                             2 * lw->threeD.shadow_width +
00792                             LEFT_OFFSET(lw));
00793     preferred->height = lw->label.label_height + 
00794                             2 * lw->label.internal_height +
00795                             2 * lw->threeD.shadow_width;
00796     if (  ((intended->request_mode & (CWWidth | CWHeight))
00797                 == (CWWidth | CWHeight)) &&
00798           intended->width == preferred->width &&
00799           intended->height == preferred->height)
00800         return XtGeometryYes;
00801     else if (preferred->width == w->core.width &&
00802              preferred->height == w->core.height)
00803         return XtGeometryNo;
00804     else
00805         return XtGeometryAlmost;
00806 }

Generated on Sun Mar 4 15:03:55 2007 for Scilab [trunk] by  doxygen 1.5.1