ThreeD.c

Go to the documentation of this file.
00001 /*
00002 * $KK: ThreeD.c,v 0.3 92/11/04 xx:xx:xx keithley Exp $ 
00003 */
00004 
00005 /***********************************************************
00006 Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts,
00007 and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
00008 Copyright 1992 by Kaleb Keithley
00009 
00010                         All Rights Reserved
00011 
00012 Permission to use, copy, modify, and distribute this software and its 
00013 documentation for any purpose and without fee is hereby granted, 
00014 provided that the above copyright notice appear in all copies and that
00015 both that copyright notice and this permission notice appear in 
00016 supporting documentation, and that the names of Digital, MIT, or Kaleb 
00017 Keithley not be used in advertising or publicity pertaining to distribution 
00018 of the software without specific, written prior permission.  
00019 
00020 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
00021 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
00022 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
00023 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
00024 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
00025 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
00026 SOFTWARE.
00027 
00028 ******************************************************************/
00029 
00030 #include <X11/Xlib.h>
00031 #include <X11/StringDefs.h>
00032 #include <X11/IntrinsicP.h>
00033 #include <X11/Xaw3d/XawInit.h>
00034 #include <X11/Xaw3d/ThreeDP.h>
00035 #include <X11/Xosdefs.h>
00036 
00037 /* Initialization of defaults */
00038 
00039 #define XtNtopShadowPixmap "topShadowPixmap"
00040 #define XtCTopShadowPixmap "TopShadowPixmap"
00041 #define XtNbottomShadowPixmap "bottomShadowPixmap"
00042 #define XtCBottomShadowPixmap "BottomShadowPixmap"
00043 
00044 #define offset(field) XtOffsetOf(ThreeDRec, field)
00045 
00046 static XtResource resources[] = {
00047     {XtNshadowWidth, XtCShadowWidth, XtRDimension, sizeof(Dimension),
00048         offset(threeD.shadow_width), XtRImmediate, (XtPointer) 2},
00049     {XtNtopShadowPixel, XtCTopShadowPixel, XtRPixel, sizeof(Pixel),
00050         offset(threeD.top_shadow_pixel), XtRString, XtDefaultForeground},
00051     {XtNbottomShadowPixel, XtCBottomShadowPixel, XtRPixel, sizeof(Pixel),
00052         offset(threeD.bot_shadow_pixel), XtRString, XtDefaultForeground},
00053     {XtNtopShadowPixmap, XtCTopShadowPixmap, XtRPixmap, sizeof(Pixmap),
00054         offset(threeD.top_shadow_pxmap), XtRImmediate, (XtPointer) NULL},
00055     {XtNbottomShadowPixmap, XtCBottomShadowPixmap, XtRPixmap, sizeof(Pixmap),
00056         offset(threeD.bot_shadow_pxmap), XtRImmediate, (XtPointer) NULL},
00057     {XtNtopShadowContrast, XtCTopShadowContrast, XtRInt, sizeof(int),
00058         offset(threeD.top_shadow_contrast), XtRImmediate, (XtPointer) 20},
00059     {XtNbottomShadowContrast, XtCBottomShadowContrast, XtRInt, sizeof(int),
00060         offset(threeD.bot_shadow_contrast), XtRImmediate, (XtPointer) 40},
00061     {XtNuserData, XtCUserData, XtRPointer, sizeof(XtPointer),
00062         offset(threeD.user_data), XtRPointer, (XtPointer) NULL},
00063     {XtNbeNiceToColormap, XtCBeNiceToColormap, XtRBoolean, sizeof(Boolean),
00064         offset(threeD.be_nice_to_cmap), XtRImmediate, (XtPointer) True},
00065     {XtNborderWidth, XtCBorderWidth, XtRDimension, sizeof(Dimension),
00066         XtOffsetOf(RectObjRec,rectangle.border_width), XtRImmediate,
00067         (XtPointer)0}
00068 };
00069 
00070 #undef offset
00071 
00072 static void ClassPartInitialize(), Initialize(), Destroy();
00073 static void Redisplay(), Realize(), _Xaw3dDrawShadows();
00074 static Boolean SetValues();
00075 
00076 ThreeDClassRec threeDClassRec = {
00077     { /* core fields */
00078     /* superclass               */      (WidgetClass) &simpleClassRec,
00079     /* class_name               */      "ThreeD",
00080     /* widget_size              */      sizeof(ThreeDRec),
00081     /* class_initialize         */      NULL,
00082     /* class_part_initialize    */      ClassPartInitialize,
00083     /* class_inited             */      FALSE,
00084     /* initialize               */      Initialize,
00085     /* initialize_hook          */      NULL,
00086     /* realize                  */      Realize,
00087     /* actions                  */      NULL,
00088     /* num_actions              */      0,
00089     /* resources                */      resources,
00090     /* resource_count           */      XtNumber(resources),
00091     /* xrm_class                */      NULLQUARK,
00092     /* compress_motion          */      TRUE,
00093     /* compress_exposure        */      TRUE,
00094     /* compress_enterleave      */      TRUE,
00095     /* visible_interest         */      FALSE,
00096     /* destroy                  */      Destroy,
00097     /* resize                   */      XtInheritResize,
00098     /* expose                   */      Redisplay,
00099     /* set_values               */      SetValues,
00100     /* set_values_hook          */      NULL,
00101     /* set_values_almost        */      XtInheritSetValuesAlmost,
00102     /* get_values_hook          */      NULL,
00103     /* accept_focus             */      NULL,
00104     /* version                  */      XtVersion,
00105     /* callback_private         */      NULL,
00106     /* tm_table                 */      NULL,
00107     /* query_geometry           */      XtInheritQueryGeometry,
00108     /* display_accelerator      */      XtInheritDisplayAccelerator,
00109     /* extension                */      NULL
00110     },
00111     { /* simple fields */
00112     /* change_sensitive         */      XtInheritChangeSensitive
00113     },
00114     { /* threeD fields */
00115     /* shadow draw              */      _Xaw3dDrawShadows
00116     }
00117 };
00118 
00119 WidgetClass threeDWidgetClass = (WidgetClass) &threeDClassRec;
00120 
00121 /****************************************************************
00122  *
00123  * Private Procedures
00124  *
00125  ****************************************************************/
00126 
00127 #define mbshadowpm_size 3
00128 static char mbshadowpm_bits[] = {0x05, 0x03, 0x06};
00129 
00130 #define mtshadowpm_size 3
00131 static char mtshadowpm_bits[] = {0x02, 0x04, 0x01};
00132 
00133 #define shadowpm_size 2
00134 static char shadowpm_bits[] = {0x02, 0x01};
00135 
00136 #ifdef USEGRAY
00137 #include <stdio.h>
00138 unsigned long grayPixel(dpy, scn)
00139 Display *dpy;
00140 Screen  *scn;
00141     {
00142     static XColor Gray = 
00143     {
00144         /* pixel */            0, 
00145         /* red, green, blue */ 0,0,0, 
00146         /* flags */            0,
00147         /* pad */              0
00148     };
00149     if (!Gray.pixel)
00150         {
00151         XColor exact;
00152         (void) XAllocNamedColor(dpy, DefaultColormapOfScreen (scn), 
00153                                 "gray", &Gray,&exact);  /* Blindflug */
00154         }
00155     return Gray.pixel;
00156     }
00157 #define setPixel(p,dpy,scn) grayPixel(dpy,scn)
00158 #else
00159 #define setPixel(p,dpy,scn) (p)
00160 #endif
00161 
00162 
00163 /* ARGSUSED */
00164 static void AllocTopShadowGC (w)
00165     Widget w;
00166 {
00167     ThreeDWidget        tdw = (ThreeDWidget) w;
00168     Screen              *scn = XtScreen (w);
00169     XtGCMask            valuemask;
00170     XGCValues           myXGCV;
00171 
00172     if (tdw->threeD.be_nice_to_cmap || DefaultDepthOfScreen (scn) == 1) {
00173         valuemask = GCTile | GCFillStyle;
00174         myXGCV.tile = tdw->threeD.top_shadow_pxmap;
00175         myXGCV.fill_style = FillTiled;
00176     } else {
00177         valuemask = GCForeground;
00178         myXGCV.foreground = tdw->threeD.top_shadow_pixel;
00179     }
00180     tdw->threeD.top_shadow_GC = XtGetGC(w, valuemask, &myXGCV);
00181 }
00182 
00183 /* ARGSUSED */
00184 static void AllocBotShadowGC (w)
00185     Widget w;
00186 {
00187     ThreeDWidget        tdw = (ThreeDWidget) w;
00188     Screen              *scn = XtScreen (w);
00189     XtGCMask            valuemask;
00190     XGCValues           myXGCV;
00191 
00192     if (tdw->threeD.be_nice_to_cmap || DefaultDepthOfScreen (scn) == 1) {
00193         valuemask = GCTile | GCFillStyle;
00194         myXGCV.tile = tdw->threeD.bot_shadow_pxmap;
00195         myXGCV.fill_style = FillTiled;
00196     } else {
00197         valuemask = GCForeground;
00198         myXGCV.foreground = tdw->threeD.bot_shadow_pixel;
00199     }
00200     tdw->threeD.bot_shadow_GC = XtGetGC(w, valuemask, &myXGCV);
00201 }
00202 
00203 /* ARGSUSED */
00204 static void AllocTopShadowPixmap (new)
00205     Widget new;
00206 {
00207     ThreeDWidget        tdw = (ThreeDWidget) new;
00208     Display             *dpy = XtDisplay (new);
00209     Screen              *scn = XtScreen (new);
00210     unsigned long       top_fg_pixel = 0, top_bg_pixel = 0;
00211     char                *pm_data = NULL;
00212     Boolean             create_pixmap = FALSE;
00213     unsigned int        pm_size;
00214 
00215     /*
00216      * I know, we're going to create two pixmaps for each and every
00217      * shadow'd widget.  Yeuck.  I'm semi-relying on server side
00218      * pixmap cacheing.
00219      */
00220 
00221     if (DefaultDepthOfScreen (scn) == 1) {
00222         top_fg_pixel = BlackPixelOfScreen (scn);
00223         top_bg_pixel = WhitePixelOfScreen (scn);
00224         pm_data = mtshadowpm_bits;
00225         pm_size = mtshadowpm_size;
00226         create_pixmap = TRUE;
00227     } else if (tdw->threeD.be_nice_to_cmap) {
00228         if (tdw->core.background_pixel == WhitePixelOfScreen (scn)) {
00229             top_fg_pixel = setPixel( WhitePixelOfScreen (scn), dpy, scn);
00230             top_bg_pixel = BlackPixelOfScreen (scn);
00231         } else if (tdw->core.background_pixel == BlackPixelOfScreen (scn)) {
00232             top_fg_pixel = BlackPixelOfScreen (scn);
00233             top_bg_pixel = setPixel( WhitePixelOfScreen (scn), dpy, scn);
00234         } else {
00235             top_fg_pixel = tdw->core.background_pixel;
00236             top_bg_pixel = WhitePixelOfScreen (scn);
00237         }
00238 #ifndef USEGRAY
00239         if (tdw->core.background_pixel == WhitePixelOfScreen (scn) ||
00240             tdw->core.background_pixel == BlackPixelOfScreen (scn)) {
00241             pm_data = mtshadowpm_bits;
00242             pm_size = mtshadowpm_size;
00243        } else 
00244 #endif
00245        {
00246             pm_data = shadowpm_bits;
00247             pm_size = shadowpm_size;
00248        }
00249         
00250         create_pixmap = TRUE;
00251     } else {
00252         pm_size = 0; /* keep gcc happy */
00253     }
00254 
00255     if (create_pixmap)
00256         tdw->threeD.top_shadow_pxmap = XCreatePixmapFromBitmapData (dpy,
00257                         RootWindowOfScreen (scn),
00258                         pm_data,
00259                         pm_size,
00260                         pm_size,
00261                         top_fg_pixel,
00262                         top_bg_pixel,
00263                         DefaultDepthOfScreen (scn));
00264 }
00265 
00266 /* ARGSUSED */
00267 static void AllocBotShadowPixmap (new)
00268     Widget new;
00269 {
00270     ThreeDWidget        tdw = (ThreeDWidget) new;
00271     Display             *dpy = XtDisplay (new);
00272     Screen              *scn = XtScreen (new);
00273     unsigned long       bot_fg_pixel = 0, bot_bg_pixel = 0;
00274     char                *pm_data = NULL;
00275     Boolean             create_pixmap = FALSE;
00276     unsigned int        pm_size;
00277 
00278     if (DefaultDepthOfScreen (scn) == 1) {
00279         bot_fg_pixel = BlackPixelOfScreen (scn);
00280         bot_bg_pixel = WhitePixelOfScreen (scn);
00281         pm_data = mbshadowpm_bits;
00282         pm_size = mbshadowpm_size;
00283         create_pixmap = TRUE;
00284     } else if (tdw->threeD.be_nice_to_cmap) {
00285         if (tdw->core.background_pixel == WhitePixelOfScreen (scn)) {
00286             bot_fg_pixel = WhitePixelOfScreen (scn);
00287             bot_bg_pixel = setPixel( BlackPixelOfScreen (scn), dpy, scn);
00288         } else if (tdw->core.background_pixel == BlackPixelOfScreen (scn)) {
00289             bot_fg_pixel = setPixel( BlackPixelOfScreen (scn), dpy, scn);
00290             bot_bg_pixel = BlackPixelOfScreen (scn);
00291         } else {
00292             bot_fg_pixel = tdw->core.background_pixel;
00293             bot_bg_pixel = BlackPixelOfScreen (scn);
00294         }
00295 #ifndef USEGRAY
00296         if (tdw->core.background_pixel == WhitePixelOfScreen (scn) ||
00297             tdw->core.background_pixel == BlackPixelOfScreen (scn)) {
00298             pm_data = mbshadowpm_bits;
00299             pm_size = mbshadowpm_size;
00300         } else 
00301 #endif
00302         {
00303             pm_data = shadowpm_bits;
00304             pm_size = shadowpm_size;
00305         }
00306         create_pixmap = TRUE;
00307     } else {
00308         pm_size = 0; /* keep gcc happy */
00309     }
00310 
00311     if (create_pixmap)
00312         tdw->threeD.bot_shadow_pxmap = XCreatePixmapFromBitmapData (dpy,
00313                         RootWindowOfScreen (scn),
00314                         pm_data,
00315                         pm_size,
00316                         pm_size,
00317                         bot_fg_pixel,
00318                         bot_bg_pixel,
00319                         DefaultDepthOfScreen (scn));
00320 }
00321 
00322 /* ARGSUSED */
00323 void Xaw3dComputeTopShadowRGB (new, xcol_out)
00324     Widget new;
00325     XColor *xcol_out;
00326 {
00327     if (XtIsSubclass (new, threeDWidgetClass)) {
00328         ThreeDWidget tdw = (ThreeDWidget) new;
00329         XColor get_c;
00330         double contrast;
00331         Display *dpy = XtDisplay (new);
00332         Screen *scn = XtScreen (new);
00333         Colormap cmap = DefaultColormapOfScreen (scn);
00334 
00335         get_c.pixel = tdw->core.background_pixel;
00336         if (get_c.pixel == WhitePixelOfScreen (scn) ||
00337             get_c.pixel == BlackPixelOfScreen (scn)) {
00338             contrast = (100 - tdw->threeD.top_shadow_contrast) / 100.0;
00339             xcol_out->red   = contrast * 65535.0;
00340             xcol_out->green = contrast * 65535.0;
00341             xcol_out->blue  = contrast * 65535.0;
00342         } else {
00343             contrast = 1.0 + tdw->threeD.top_shadow_contrast / 100.0;
00344             XQueryColor (dpy, cmap, &get_c);
00345 #define MIN(x,y) (unsigned short) (x < y) ? x : y
00346             xcol_out->red   = MIN (65535, (int) (contrast * (double) get_c.red));
00347             xcol_out->green = MIN (65535, (int) (contrast * (double) get_c.green));
00348             xcol_out->blue  = MIN (65535, (int) (contrast * (double) get_c.blue));
00349 #undef MIN
00350         }
00351     } else
00352         xcol_out->red = xcol_out->green = xcol_out->blue = 0;
00353 }
00354 
00355 /* ARGSUSED */
00356 static void AllocTopShadowPixel (new)
00357     Widget new;
00358 {
00359     XColor set_c;
00360     ThreeDWidget tdw = (ThreeDWidget) new;
00361     Display *dpy = XtDisplay (new);
00362     Screen *scn = XtScreen (new);
00363     Colormap cmap = DefaultColormapOfScreen (scn);
00364 
00365     Xaw3dComputeTopShadowRGB (new, &set_c);
00366     (void) XAllocColor (dpy, cmap, &set_c);
00367     tdw->threeD.top_shadow_pixel = set_c.pixel;
00368 }
00369 
00370 /* ARGSUSED */
00371 void Xaw3dComputeBottomShadowRGB (new, xcol_out)
00372     Widget new;
00373     XColor *xcol_out;
00374 {
00375     if (XtIsSubclass (new, threeDWidgetClass)) {
00376         ThreeDWidget tdw = (ThreeDWidget) new;
00377         XColor get_c;
00378         double contrast;
00379         Display *dpy = XtDisplay (new);
00380         Screen *scn = XtScreen (new);
00381         Colormap cmap = DefaultColormapOfScreen (scn);
00382 
00383         get_c.pixel = tdw->core.background_pixel;
00384         if (get_c.pixel == WhitePixelOfScreen (scn) ||
00385             get_c.pixel == BlackPixelOfScreen (scn)) {
00386             contrast = tdw->threeD.bot_shadow_contrast / 100.0;
00387             xcol_out->red   = contrast * 65535.0;
00388             xcol_out->green = contrast * 65535.0;
00389             xcol_out->blue  = contrast * 65535.0;
00390         } else {
00391             XQueryColor (dpy, cmap, &get_c);
00392             contrast = (100 - tdw->threeD.bot_shadow_contrast) / 100.0;
00393             xcol_out->red   = contrast * get_c.red;
00394             xcol_out->green = contrast * get_c.green;
00395             xcol_out->blue  = contrast * get_c.blue;
00396         }
00397     } else
00398         xcol_out->red = xcol_out->green = xcol_out->blue = 0;
00399 }
00400 
00401 /* ARGSUSED */
00402 static void AllocBotShadowPixel (new)
00403     Widget new;
00404 {
00405     XColor set_c;
00406     ThreeDWidget tdw = (ThreeDWidget) new;
00407     Display *dpy = XtDisplay (new);
00408     Screen *scn = XtScreen (new);
00409     Colormap cmap = DefaultColormapOfScreen (scn);
00410 
00411     Xaw3dComputeBottomShadowRGB (new, &set_c);
00412     (void) XAllocColor (dpy, cmap, &set_c);
00413     tdw->threeD.bot_shadow_pixel = set_c.pixel;
00414 }
00415 
00416 
00417 /* ARGSUSED */
00418 static void ClassPartInitialize (wc)
00419     WidgetClass wc;
00420 
00421 {
00422     ThreeDClassRec *tdwc = (ThreeDClassRec*) wc;
00423     ThreeDClassRec *super = (ThreeDClassRec*) tdwc->core_class.superclass;
00424 
00425     if (tdwc->threeD_class.shadowdraw == XtInheritXaw3dShadowDraw)
00426         tdwc->threeD_class.shadowdraw = super->threeD_class.shadowdraw;
00427 }
00428 
00429 
00430 /* ARGSUSED */
00431 static void Initialize (request, new, args, num_args)
00432     Widget request, new;
00433     ArgList args;
00434     Cardinal *num_args;
00435 {
00436     ThreeDWidget        tdw = (ThreeDWidget) new;
00437     Screen              *scr = XtScreen (new);
00438 
00439     if (tdw->threeD.be_nice_to_cmap || DefaultDepthOfScreen (scr) == 1) {
00440         AllocTopShadowPixmap (new);
00441         AllocBotShadowPixmap (new);
00442     } else {
00443         if (tdw->threeD.top_shadow_pixel == tdw->threeD.bot_shadow_pixel) {
00444             /* 
00445                 Eeek.  We're probably going to XQueryColor() twice 
00446                 for each widget.  Necessary because you can set the
00447                 top and bottom shadows independent of each other in
00448                 SetValues.  Some cacheing would certainly help...
00449             */
00450             AllocTopShadowPixel (new);
00451             AllocBotShadowPixel (new);
00452         }
00453         tdw->threeD.top_shadow_pxmap = tdw->threeD.bot_shadow_pxmap = (Pixmap) 0;
00454     }
00455     AllocTopShadowGC (new);
00456     AllocBotShadowGC (new);
00457 }
00458 
00459 static void Realize (gw, valueMask, attrs)
00460     Widget gw;
00461     XtValueMask *valueMask;
00462     XSetWindowAttributes *attrs;
00463 {
00464  /* 
00465   * This is necessary because Simple doesn't have a realize method
00466   * XtInheritRealize in the ThreeD class record doesn't work.  This
00467   * daisychains through Simple to the Core class realize method
00468   */
00469     (*threeDWidgetClass->core_class.superclass->core_class.realize)
00470          (gw, valueMask, attrs);
00471 }
00472 
00473 static void Destroy (w)
00474      Widget w;
00475 {
00476     ThreeDWidget tdw = (ThreeDWidget) w;
00477     XtReleaseGC (w, tdw->threeD.top_shadow_GC);
00478     XtReleaseGC (w, tdw->threeD.bot_shadow_GC);
00479     if (tdw->threeD.top_shadow_pxmap)
00480         XFreePixmap (XtDisplay (w), tdw->threeD.top_shadow_pxmap);
00481     if (tdw->threeD.bot_shadow_pxmap)
00482         XFreePixmap (XtDisplay (w), tdw->threeD.bot_shadow_pxmap);
00483 }
00484 
00485 /* ARGSUSED */
00486 static void Redisplay (w, event, region)
00487     Widget w;
00488     XEvent *event;              /* unused */
00489     Region region;              /* unused */
00490 {
00491     _Xaw3dDrawShadows (w, event, region, True);
00492 }
00493 
00494 /* ARGSUSED */
00495 static Boolean SetValues (gcurrent, grequest, gnew, args, num_args)
00496     Widget gcurrent, grequest, gnew;
00497     ArgList args;
00498     Cardinal *num_args;
00499 {
00500     ThreeDWidget current = (ThreeDWidget) gcurrent;
00501     ThreeDWidget new = (ThreeDWidget) gnew;
00502     Boolean redisplay = FALSE;
00503     Boolean alloc_top_pixel = FALSE;
00504     Boolean alloc_bot_pixel = FALSE;
00505     Boolean alloc_top_pxmap = FALSE;
00506     Boolean alloc_bot_pxmap = FALSE;
00507 
00508     (*threeDWidgetClass->core_class.superclass->core_class.set_values) 
00509         (gcurrent, grequest, gnew, NULL, 0);
00510     if (new->threeD.shadow_width != current->threeD.shadow_width)
00511         redisplay = TRUE;
00512     if (new->threeD.be_nice_to_cmap != current->threeD.be_nice_to_cmap) {
00513         if (new->threeD.be_nice_to_cmap) {
00514             alloc_top_pxmap = TRUE;
00515             alloc_bot_pxmap = TRUE;
00516         } else {
00517             alloc_top_pixel = TRUE;
00518             alloc_bot_pixel = TRUE;
00519         }
00520         redisplay = TRUE;
00521     }
00522     if (!new->threeD.be_nice_to_cmap &&
00523         new->threeD.top_shadow_contrast != current->threeD.top_shadow_contrast)
00524         alloc_top_pixel = TRUE;
00525     if (!new->threeD.be_nice_to_cmap &&
00526         new->threeD.bot_shadow_contrast != current->threeD.bot_shadow_contrast)
00527         alloc_bot_pixel = TRUE;
00528     if (alloc_top_pixel)
00529         AllocTopShadowPixel (gnew);
00530     if (alloc_bot_pixel)
00531         AllocBotShadowPixel (gnew);
00532     if (alloc_top_pxmap)
00533         AllocTopShadowPixmap (gnew);
00534     if (alloc_bot_pxmap)
00535         AllocBotShadowPixmap (gnew);
00536     if (!new->threeD.be_nice_to_cmap &&
00537         new->threeD.top_shadow_pixel != current->threeD.top_shadow_pixel)
00538         alloc_top_pixel = TRUE;
00539     if (!new->threeD.be_nice_to_cmap &&
00540         new->threeD.bot_shadow_pixel != current->threeD.bot_shadow_pixel)
00541         alloc_bot_pixel = TRUE;
00542     if (new->threeD.be_nice_to_cmap) {
00543         if (alloc_top_pxmap) {
00544             XtReleaseGC (gcurrent, current->threeD.top_shadow_GC);
00545             AllocTopShadowGC (gnew);
00546             redisplay = True;
00547         }
00548         if (alloc_bot_pxmap) {
00549             XtReleaseGC (gcurrent, current->threeD.bot_shadow_GC);
00550             AllocBotShadowGC (gnew);
00551             redisplay = True;
00552         }
00553     } else {
00554         if (alloc_top_pixel) {
00555             if (new->threeD.top_shadow_pxmap) {
00556                 XFreePixmap (XtDisplay (gnew), new->threeD.top_shadow_pxmap);
00557                 new->threeD.top_shadow_pxmap = (Pixmap) NULL;
00558             }
00559             XtReleaseGC (gcurrent, current->threeD.top_shadow_GC);
00560             AllocTopShadowGC (gnew);
00561             redisplay = True;
00562         }
00563         if (alloc_bot_pixel) {
00564             if (new->threeD.bot_shadow_pxmap) {
00565                 XFreePixmap (XtDisplay (gnew), new->threeD.bot_shadow_pxmap);
00566                 new->threeD.bot_shadow_pxmap = (Pixmap) NULL;
00567             }
00568             XtReleaseGC (gcurrent, current->threeD.bot_shadow_GC);
00569             AllocBotShadowGC (gnew);
00570             redisplay = True;
00571         }
00572     }
00573     return (redisplay);
00574 }
00575 
00576 /* ARGSUSED */
00577 static void
00578 _Xaw3dDrawShadows (gw, event, region, out)
00579     Widget gw;
00580     XEvent *event;
00581     Region region;
00582     Boolean out;
00583 {
00584     XPoint      pt[6];
00585     ThreeDWidget tdw = (ThreeDWidget) gw;
00586     Dimension   s = tdw->threeD.shadow_width;
00587     /* 
00588      * draw the shadows using the core part width and height, 
00589      * and the threeD part shadow_width.
00590      *
00591      *  no point to do anything if the shadow_width is 0 or the
00592      *  widget has not been realized.
00593      */ 
00594     if((s > 0) && XtIsRealized (gw)){
00595 
00596         Dimension       h = tdw->core.height;
00597         Dimension       w = tdw->core.width;
00598         Dimension       wms = w - s;
00599         Dimension       hms = h - s;
00600         Display         *dpy = XtDisplay (gw);
00601         Window          win = XtWindow (gw);
00602         GC              top, bot;
00603 
00604         if (out) {
00605             top = tdw->threeD.top_shadow_GC;
00606             bot = tdw->threeD.bot_shadow_GC;
00607         } else {
00608             top = tdw->threeD.bot_shadow_GC;
00609             bot = tdw->threeD.top_shadow_GC;
00610         }
00611 
00612         /* top-left shadow */
00613         if ((region == NULL) ||
00614             (XRectInRegion (region, 0, 0, w, s) != RectangleOut) ||
00615             (XRectInRegion (region, 0, 0, s, h) != RectangleOut)) {
00616 
00617             pt[0].x = 0;        pt[0].y = h;
00618             pt[1].x =           pt[1].y = 0;
00619             pt[2].x = w;        pt[2].y = 0;
00620             pt[3].x = wms;      pt[3].y = s;
00621             pt[4].x =           pt[4].y = s;
00622             pt[5].x = s;        pt[5].y = hms;
00623             XFillPolygon (dpy, win, top, pt, 6,Complex,CoordModeOrigin);
00624         }
00625 
00626         /* bottom-right shadow */
00627         if ((region == NULL) ||
00628             (XRectInRegion (region, 0, hms, w, s) != RectangleOut) ||
00629             (XRectInRegion (region, wms, 0, s, h) != RectangleOut)) {
00630 
00631             pt[0].x = 0;        pt[0].y = h;
00632             pt[1].x = w;        pt[1].y = h;
00633             pt[2].x = w;        pt[2].y = 0; 
00634             pt[3].x = wms;      pt[3].y = s;
00635             pt[4].x = wms;      pt[4].y = hms;
00636             pt[5].x = s;        pt[5].y = hms; 
00637             XFillPolygon (dpy, win, bot, pt,6, Complex,CoordModeOrigin);
00638         }
00639     }
00640 }
00641 

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