Blame GLwDrawA.c

Packit Service 7a208c
/*
Packit Service 7a208c
 * (c) Copyright 1993, Silicon Graphics, Inc.
Packit Service 7a208c
 * ALL RIGHTS RESERVED 
Packit Service 7a208c
 * Permission to use, copy, modify, and distribute this software for 
Packit Service 7a208c
 * any purpose and without fee is hereby granted, provided that the above
Packit Service 7a208c
 * copyright notice appear in all copies and that both the copyright notice
Packit Service 7a208c
 * and this permission notice appear in supporting documentation, and that 
Packit Service 7a208c
 * the name of Silicon Graphics, Inc. not be used in advertising
Packit Service 7a208c
 * or publicity pertaining to distribution of the software without specific,
Packit Service 7a208c
 * written prior permission. 
Packit Service 7a208c
 *
Packit Service 7a208c
 * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
Packit Service 7a208c
 * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
Packit Service 7a208c
 * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
Packit Service 7a208c
 * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
Packit Service 7a208c
 * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
Packit Service 7a208c
 * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
Packit Service 7a208c
 * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
Packit Service 7a208c
 * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
Packit Service 7a208c
 * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
Packit Service 7a208c
 * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
Packit Service 7a208c
 * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
Packit Service 7a208c
 * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
Packit Service 7a208c
 * 
Packit Service 7a208c
 * 
Packit Service 7a208c
 * US Government Users Restricted Rights 
Packit Service 7a208c
 * Use, duplication, or disclosure by the Government is subject to
Packit Service 7a208c
 * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
Packit Service 7a208c
 * (c)(1)(ii) of the Rights in Technical Data and Computer Software
Packit Service 7a208c
 * clause at DFARS 252.227-7013 and/or in similar or successor
Packit Service 7a208c
 * clauses in the FAR or the DOD or NASA FAR Supplement.
Packit Service 7a208c
 * Unpublished-- rights reserved under the copyright laws of the
Packit Service 7a208c
 * United States.  Contractor/manufacturer is Silicon Graphics,
Packit Service 7a208c
 * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
Packit Service 7a208c
 *
Packit Service 7a208c
 * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
Packit Service 7a208c
 */
Packit Service 7a208c
Packit Service 7a208c
/*
Packit Service 7a208c
 *
Packit Service 7a208c
 * This file has been slightly modified from the original for use with Mesa
Packit Service 7a208c
 *
Packit Service 7a208c
 *     Jeroen van der Zijp
Packit Service 7a208c
 *
Packit Service 7a208c
 *     jvz@cyberia.cfdrc.com
Packit Service 7a208c
 *
Packit Service 7a208c
 */
Packit Service 7a208c
#include <X11/IntrinsicP.h>
Packit Service 7a208c
#include <X11/StringDefs.h>
Packit Service 7a208c
#include <GL/glx.h>
Packit Service 7a208c
#include <GL/gl.h>
Packit Service 7a208c
#ifdef __GLX_MOTIF
Packit Service 7a208c
#include <Xm/PrimitiveP.h>
Packit Service 7a208c
#include "GLwMDrawAP.h"
Packit Service 7a208c
#else 
Packit Service 7a208c
#include "GLwDrawAP.h"
Packit Service 7a208c
#endif 
Packit Service 7a208c
#include <assert.h>
Packit Service 7a208c
#include <stdio.h>
Packit Service 7a208c
Packit Service 7a208c
#ifdef __GLX_MOTIF
Packit Service 7a208c
#define GLwDrawingAreaWidget             GLwMDrawingAreaWidget
Packit Service 7a208c
#define GLwDrawingAreaClassRec           GLwMDrawingAreaClassRec
Packit Service 7a208c
#define glwDrawingAreaClassRec           glwMDrawingAreaClassRec
Packit Service 7a208c
#define glwDrawingAreaWidgetClass        glwMDrawingAreaWidgetClass
Packit Service 7a208c
#define GLwDrawingAreaRec                GLwMDrawingAreaRec
Packit Service 7a208c
#endif 
Packit Service 7a208c
Packit Service 7a208c
#define ATTRIBLIST_SIZE 32
Packit Service 7a208c
Packit Service 7a208c
#define offset(field) XtOffset(GLwDrawingAreaWidget,glwDrawingArea.field)
Packit Service 7a208c
Packit Service 7a208c
Packit Service 7a208c
/* forward definitions */
Packit Service 7a208c
static void createColormap(GLwDrawingAreaWidget w,int offset,XrmValue *value);
Packit Service 7a208c
static void Initialize(GLwDrawingAreaWidget req,GLwDrawingAreaWidget neww,ArgList args,Cardinal *num_args);
Packit Service 7a208c
static void Realize(Widget w,Mask *valueMask,XSetWindowAttributes *attributes);
Packit Service 7a208c
static void Redraw(GLwDrawingAreaWidget w,XEvent *event,Region region);
Packit Service 7a208c
static void Resize(GLwDrawingAreaWidget glw);
Packit Service 7a208c
static void Destroy(GLwDrawingAreaWidget glw);
Packit Service 7a208c
static void glwInput(GLwDrawingAreaWidget glw,XEvent *event,String *params,Cardinal *numParams);
Packit Service 7a208c
Packit Service 7a208c
Packit Service 7a208c
Packit Service 7a208c
static char defaultTranslations[] =
Packit Service 7a208c
#ifdef __GLX_MOTIF
Packit Service 7a208c
     "<Key>osfHelp:PrimitiveHelp() \n"
Packit Service 7a208c
#endif
Packit Service 7a208c
    "<KeyDown>:   glwInput() \n\
Packit Service 7a208c
     <KeyUp>:     glwInput() \n\
Packit Service 7a208c
     <BtnDown>:   glwInput() \n\
Packit Service 7a208c
     <BtnUp>:     glwInput() \n\
Packit Service 7a208c
     <BtnMotion>: glwInput() ";
Packit Service 7a208c
Packit Service 7a208c
Packit Service 7a208c
static XtActionsRec actions[] = {
Packit Service 7a208c
  {"glwInput",(XtActionProc)glwInput},                /* key or mouse input */
Packit Service 7a208c
  };
Packit Service 7a208c
Packit Service 7a208c
Packit Service 7a208c
/*
Packit Service 7a208c
 * There is a bit of unusual handling of the resources here.
Packit Service 7a208c
 * Because Xt insists on allocating the colormap resource when it is
Packit Service 7a208c
 * processing the core resources (even if we redeclare the colormap
Packit Service 7a208c
 * resource here, we need to do a little trick.  When Xt first allocates
Packit Service 7a208c
 * the colormap, we allow it to allocate the default one, since we have
Packit Service 7a208c
 * not yet determined the appropriate visual (which is determined from
Packit Service 7a208c
 * resources parsed after the colormap).  We also let it allocate colors
Packit Service 7a208c
 * in that default colormap.
Packit Service 7a208c
 *
Packit Service 7a208c
 * In the initialize proc we calculate the actual visual.  Then, we
Packit Service 7a208c
 * reobtain the colormap resource using XtGetApplicationResources in
Packit Service 7a208c
 * the initialize proc.  If requested, we also reallocate colors in
Packit Service 7a208c
 * that colormap using the same method.
Packit Service 7a208c
 */
Packit Service 7a208c
Packit Service 7a208c
static XtResource resources[] = {
Packit Service 7a208c
  /* The GLX attributes.  Add any new attributes here */
Packit Service 7a208c
Packit Service 7a208c
  {GLwNbufferSize, GLwCBufferSize, XtRInt, sizeof (int),
Packit Service 7a208c
       offset(bufferSize), XtRImmediate, (XtPointer) 0},
Packit Service 7a208c
  
Packit Service 7a208c
  {GLwNlevel, GLwCLevel, XtRInt, sizeof (int),
Packit Service 7a208c
       offset(level), XtRImmediate, (XtPointer) 0},
Packit Service 7a208c
  
Packit Service 7a208c
  {GLwNrgba, GLwCRgba, XtRBoolean, sizeof (Boolean),
Packit Service 7a208c
       offset(rgba), XtRImmediate, (XtPointer) FALSE},
Packit Service 7a208c
  
Packit Service 7a208c
  {GLwNdoublebuffer, GLwCDoublebuffer, XtRBoolean, sizeof (Boolean),
Packit Service 7a208c
       offset(doublebuffer), XtRImmediate, (XtPointer) FALSE},
Packit Service 7a208c
  
Packit Service 7a208c
  {GLwNstereo, GLwCStereo, XtRBoolean, sizeof (Boolean),
Packit Service 7a208c
       offset(stereo), XtRImmediate, (XtPointer) FALSE},
Packit Service 7a208c
  
Packit Service 7a208c
  {GLwNauxBuffers, GLwCAuxBuffers, XtRInt, sizeof (int),
Packit Service 7a208c
       offset(auxBuffers), XtRImmediate, (XtPointer) 0},
Packit Service 7a208c
  
Packit Service 7a208c
  {GLwNredSize, GLwCColorSize, XtRInt, sizeof (int),
Packit Service 7a208c
       offset(redSize), XtRImmediate, (XtPointer) 1},
Packit Service 7a208c
  
Packit Service 7a208c
  {GLwNgreenSize, GLwCColorSize, XtRInt, sizeof (int),
Packit Service 7a208c
       offset(greenSize), XtRImmediate, (XtPointer) 1},
Packit Service 7a208c
  
Packit Service 7a208c
  {GLwNblueSize, GLwCColorSize, XtRInt, sizeof (int),
Packit Service 7a208c
       offset(blueSize), XtRImmediate, (XtPointer) 1},
Packit Service 7a208c
  
Packit Service 7a208c
  {GLwNalphaSize, GLwCAlphaSize, XtRInt, sizeof (int),
Packit Service 7a208c
       offset(alphaSize), XtRImmediate, (XtPointer) 0},
Packit Service 7a208c
  
Packit Service 7a208c
  {GLwNdepthSize, GLwCDepthSize, XtRInt, sizeof (int),
Packit Service 7a208c
       offset(depthSize), XtRImmediate, (XtPointer) 0},
Packit Service 7a208c
  
Packit Service 7a208c
  {GLwNstencilSize, GLwCStencilSize, XtRInt, sizeof (int),
Packit Service 7a208c
       offset(stencilSize), XtRImmediate, (XtPointer) 0},
Packit Service 7a208c
  
Packit Service 7a208c
  {GLwNaccumRedSize, GLwCAccumColorSize, XtRInt, sizeof (int),
Packit Service 7a208c
       offset(accumRedSize), XtRImmediate, (XtPointer) 0},
Packit Service 7a208c
  
Packit Service 7a208c
  {GLwNaccumGreenSize, GLwCAccumColorSize, XtRInt, sizeof (int),
Packit Service 7a208c
       offset(accumGreenSize), XtRImmediate, (XtPointer) 0},
Packit Service 7a208c
  
Packit Service 7a208c
  {GLwNaccumBlueSize, GLwCAccumColorSize, XtRInt, sizeof (int),
Packit Service 7a208c
       offset(accumBlueSize), XtRImmediate, (XtPointer) 0},
Packit Service 7a208c
  
Packit Service 7a208c
  {GLwNaccumAlphaSize, GLwCAccumAlphaSize, XtRInt, sizeof (int),
Packit Service 7a208c
       offset(accumAlphaSize), XtRImmediate, (XtPointer) 0},
Packit Service 7a208c
  
Packit Service 7a208c
  /* the attribute list */
Packit Service 7a208c
  {GLwNattribList, GLwCAttribList, XtRPointer, sizeof(int *),
Packit Service 7a208c
       offset(attribList), XtRImmediate, (XtPointer) NULL},
Packit Service 7a208c
Packit Service 7a208c
  /* the visual info */
Packit Service 7a208c
  {GLwNvisualInfo, GLwCVisualInfo, GLwRVisualInfo, sizeof (XVisualInfo *),
Packit Service 7a208c
       offset(visualInfo), XtRImmediate, (XtPointer) NULL},
Packit Service 7a208c
Packit Service 7a208c
  /* miscellaneous resources */
Packit Service 7a208c
  {GLwNinstallColormap, GLwCInstallColormap, XtRBoolean, sizeof (Boolean),
Packit Service 7a208c
       offset(installColormap), XtRImmediate, (XtPointer) TRUE},
Packit Service 7a208c
Packit Service 7a208c
  {GLwNallocateBackground, GLwCAllocateColors, XtRBoolean, sizeof (Boolean),
Packit Service 7a208c
       offset(allocateBackground), XtRImmediate, (XtPointer) FALSE},
Packit Service 7a208c
Packit Service 7a208c
  {GLwNallocateOtherColors, GLwCAllocateColors, XtRBoolean, sizeof (Boolean),
Packit Service 7a208c
       offset(allocateOtherColors), XtRImmediate, (XtPointer) FALSE},
Packit Service 7a208c
Packit Service 7a208c
  {GLwNinstallBackground, GLwCInstallBackground, XtRBoolean, sizeof (Boolean),
Packit Service 7a208c
       offset(installBackground), XtRImmediate, (XtPointer) TRUE},
Packit Service 7a208c
Packit Service 7a208c
  {GLwNginitCallback, GLwCCallback, XtRCallback, sizeof (XtCallbackList),
Packit Service 7a208c
       offset(ginitCallback), XtRImmediate, (XtPointer) NULL},
Packit Service 7a208c
Packit Service 7a208c
  {GLwNinputCallback, GLwCCallback, XtRCallback, sizeof (XtCallbackList),
Packit Service 7a208c
       offset(inputCallback), XtRImmediate, (XtPointer) NULL},
Packit Service 7a208c
Packit Service 7a208c
  {GLwNresizeCallback, GLwCCallback, XtRCallback, sizeof (XtCallbackList),
Packit Service 7a208c
       offset(resizeCallback), XtRImmediate, (XtPointer) NULL},
Packit Service 7a208c
Packit Service 7a208c
  {GLwNexposeCallback, GLwCCallback, XtRCallback, sizeof (XtCallbackList),
Packit Service 7a208c
       offset(exposeCallback), XtRImmediate, (XtPointer) NULL},
Packit Service 7a208c
Packit Service 7a208c
  /* Changes to Motif primitive resources */
Packit Service 7a208c
#ifdef __GLX_MOTIF
Packit Service 7a208c
  {XmNtraversalOn, XmCTraversalOn, XmRBoolean, sizeof (Boolean),
Packit Service 7a208c
   XtOffset (GLwDrawingAreaWidget, primitive.traversal_on), XmRImmediate,
Packit Service 7a208c
   (XtPointer)FALSE},
Packit Service 7a208c
  
Packit Service 7a208c
  /* highlighting is normally disabled, as when Motif tries to disable
Packit Service 7a208c
   * highlighting, it tries to reset the color back to the parent's
Packit Service 7a208c
   * background (usually Motif blue).  Unfortunately, that is in a
Packit Service 7a208c
   * different colormap, and doesn't work too well.
Packit Service 7a208c
   */
Packit Service 7a208c
  {XmNhighlightOnEnter, XmCHighlightOnEnter, XmRBoolean, sizeof (Boolean),
Packit Service 7a208c
   XtOffset (GLwDrawingAreaWidget, primitive.highlight_on_enter),
Packit Service 7a208c
   XmRImmediate, (XtPointer) FALSE},
Packit Service 7a208c
  
Packit Service 7a208c
  {XmNhighlightThickness, XmCHighlightThickness, XmRHorizontalDimension,
Packit Service 7a208c
   sizeof (Dimension),
Packit Service 7a208c
   XtOffset (GLwDrawingAreaWidget, primitive.highlight_thickness),
Packit Service 7a208c
   XmRImmediate, (XtPointer) 0},
Packit Service 7a208c
#endif 
Packit Service 7a208c
  };
Packit Service 7a208c
Packit Service 7a208c
Packit Service 7a208c
/*
Packit Service 7a208c
** The following resources are reobtained using XtGetApplicationResources
Packit Service 7a208c
** in the initialize proc.
Packit Service 7a208c
*/
Packit Service 7a208c
Packit Service 7a208c
/* The colormap */
Packit Service 7a208c
static XtResource initializeResources[] = {
Packit Service 7a208c
  /* reobtain the colormap with the new visual */
Packit Service 7a208c
  {XtNcolormap, XtCColormap, XtRColormap, sizeof(Colormap),
Packit Service 7a208c
   XtOffset(GLwDrawingAreaWidget, core.colormap),
Packit Service 7a208c
   XtRCallProc,(XtPointer) createColormap},
Packit Service 7a208c
  };
Packit Service 7a208c
Packit Service 7a208c
Packit Service 7a208c
/* reallocate any colors we need in the new colormap */
Packit Service 7a208c
  
Packit Service 7a208c
/* The background is obtained only if the allocateBackground resource is TRUE*/
Packit Service 7a208c
static XtResource backgroundResources[] = {
Packit Service 7a208c
#ifdef __GLX_MOTIF
Packit Service 7a208c
  {XmNbackground, XmCBackground,XmRPixel, 
Packit Service 7a208c
   sizeof(Pixel),XtOffset(GLwDrawingAreaWidget,core.background_pixel),
Packit Service 7a208c
   XmRString,(XtPointer)"lightgrey"},
Packit Service 7a208c
   /*XmRCallProc,(XtPointer)_XmBackgroundColorDefault},*/
Packit Service 7a208c
Packit Service 7a208c
  {XmNbackgroundPixmap,XmCPixmap,XmRXmBackgroundPixmap, 
Packit Service 7a208c
   sizeof(Pixmap),XtOffset(GLwDrawingAreaWidget,core.background_pixmap),
Packit Service 7a208c
   XmRImmediate,(XtPointer)XmUNSPECIFIED_PIXMAP},
Packit Service 7a208c
Packit Service 7a208c
#else
Packit Service 7a208c
  {XtNbackground,XtCBackground,XtRPixel,sizeof(Pixel),
Packit Service 7a208c
   XtOffset(GLwDrawingAreaWidget,core.background_pixel),
Packit Service 7a208c
   XtRString,(XtPointer)"lightgrey"},
Packit Service 7a208c
   /*XtRString,(XtPointer)"XtDefaultBackground"},*/
Packit Service 7a208c
Packit Service 7a208c
  {XtNbackgroundPixmap, XtCPixmap, XtRPixmap, sizeof(Pixmap),
Packit Service 7a208c
   XtOffset(GLwDrawingAreaWidget,core.background_pixmap),
Packit Service 7a208c
   XtRImmediate,(XtPointer)XtUnspecifiedPixmap},
Packit Service 7a208c
#endif  
Packit Service 7a208c
  };
Packit Service 7a208c
Packit Service 7a208c
Packit Service 7a208c
Packit Service 7a208c
/* The other colors such as the foreground are allocated only if
Packit Service 7a208c
 * allocateOtherColors are set.  These resources only exist in Motif.
Packit Service 7a208c
 */
Packit Service 7a208c
#ifdef __GLX_MOTIF
Packit Service 7a208c
static XtResource otherColorResources[] = {
Packit Service 7a208c
  {XmNforeground,XmCForeground,XmRPixel, 
Packit Service 7a208c
   sizeof(Pixel),XtOffset(GLwDrawingAreaWidget,primitive.foreground),
Packit Service 7a208c
   XmRString,(XtPointer)"lightgrey"},
Packit Service 7a208c
   /*XmRCallProc, (XtPointer) _XmForegroundColorDefault},*/
Packit Service 7a208c
Packit Service 7a208c
  {XmNhighlightColor,XmCHighlightColor,XmRPixel,sizeof(Pixel),
Packit Service 7a208c
   XtOffset(GLwDrawingAreaWidget,primitive.highlight_color),
Packit Service 7a208c
   XmRString,(XtPointer)"lightgrey"},
Packit Service 7a208c
   /*XmRCallProc,(XtPointer)_XmHighlightColorDefault},*/
Packit Service 7a208c
Packit Service 7a208c
  {XmNhighlightPixmap,XmCHighlightPixmap,XmRPrimHighlightPixmap,
Packit Service 7a208c
   sizeof(Pixmap),
Packit Service 7a208c
   XtOffset(GLwDrawingAreaWidget,primitive.highlight_pixmap),
Packit Service 7a208c
   XmRImmediate,(XtPointer)XmUNSPECIFIED_PIXMAP},
Packit Service 7a208c
   /*XmRCallProc,(XtPointer)_XmPrimitiveHighlightPixmapDefault},*/
Packit Service 7a208c
  };
Packit Service 7a208c
#endif
Packit Service 7a208c
Packit Service 7a208c
Packit Service 7a208c
#undef offset
Packit Service 7a208c
Packit Service 7a208c
Packit Service 7a208c
GLwDrawingAreaClassRec glwDrawingAreaClassRec = {
Packit Service 7a208c
  { /* core fields */
Packit Service 7a208c
#ifdef __GLX_MOTIF
Packit Service 7a208c
    /* superclass                */        (WidgetClass) &xmPrimitiveClassRec,
Packit Service 7a208c
    /* class_name                */        "GLwMDrawingArea",
Packit Service 7a208c
#else /* not __GLX_MOTIF */
Packit Service 7a208c
    /* superclass                */        (WidgetClass) &widgetClassRec,
Packit Service 7a208c
    /* class_name                */        "GLwDrawingArea",
Packit Service 7a208c
#endif /* __GLX_MOTIF */
Packit Service 7a208c
    /* widget_size               */        sizeof(GLwDrawingAreaRec),
Packit Service 7a208c
    /* class_initialize          */        NULL,
Packit Service 7a208c
    /* class_part_initialize     */        NULL,
Packit Service 7a208c
    /* class_inited              */        FALSE,
Packit Service 7a208c
    /* initialize                */        (XtInitProc) Initialize,
Packit Service 7a208c
    /* initialize_hook           */        NULL,
Packit Service 7a208c
    /* realize                   */        Realize,
Packit Service 7a208c
    /* actions                   */        actions,
Packit Service 7a208c
    /* num_actions               */        XtNumber(actions),
Packit Service 7a208c
    /* resources                 */        resources,
Packit Service 7a208c
    /* num_resources             */        XtNumber(resources),
Packit Service 7a208c
    /* xrm_class                 */        NULLQUARK,
Packit Service 7a208c
    /* compress_motion           */        TRUE,
Packit Service 7a208c
    /* compress_exposure         */        TRUE,
Packit Service 7a208c
    /* compress_enterleave       */        TRUE,
Packit Service 7a208c
    /* visible_interest          */        TRUE,
Packit Service 7a208c
    /* destroy                   */        (XtWidgetProc) Destroy,
Packit Service 7a208c
    /* resize                    */        (XtWidgetProc) Resize,
Packit Service 7a208c
    /* expose                    */        (XtExposeProc) Redraw,
Packit Service 7a208c
    /* set_values                */        NULL,
Packit Service 7a208c
    /* set_values_hook           */        NULL,
Packit Service 7a208c
    /* set_values_almost         */        XtInheritSetValuesAlmost,
Packit Service 7a208c
    /* get_values_hook           */        NULL,
Packit Service 7a208c
    /* accept_focus              */        NULL,
Packit Service 7a208c
    /* version                   */        XtVersion,
Packit Service 7a208c
    /* callback_private          */        NULL,
Packit Service 7a208c
    /* tm_table                  */        defaultTranslations,
Packit Service 7a208c
    /* query_geometry            */        XtInheritQueryGeometry,
Packit Service 7a208c
    /* display_accelerator       */        XtInheritDisplayAccelerator,
Packit Service 7a208c
    /* extension                 */        NULL
Packit Service 7a208c
  },
Packit Service 7a208c
#ifdef __GLX_MOTIF /* primitive resources */
Packit Service 7a208c
  {
Packit Service 7a208c
    /* border_highlight          */        XmInheritBorderHighlight,
Packit Service 7a208c
    /* border_unhighlight        */        XmInheritBorderUnhighlight,
Packit Service 7a208c
    /* translations              */        XtInheritTranslations,
Packit Service 7a208c
    /* arm_and_activate          */        NULL,
Packit Service 7a208c
    /* get_resources             */        NULL,
Packit Service 7a208c
    /* num get_resources         */        0,
Packit Service 7a208c
    /* extension                 */        NULL,                                
Packit Service 7a208c
  }
Packit Service 7a208c
#endif 
Packit Service 7a208c
  };
Packit Service 7a208c
Packit Service 7a208c
WidgetClass glwDrawingAreaWidgetClass=(WidgetClass)&glwDrawingAreaClassRec;
Packit Service 7a208c
Packit Service 7a208c
Packit Service 7a208c
Packit Service 7a208c
static void error(Widget w,char* string){
Packit Service 7a208c
  char buf[100];
Packit Service 7a208c
#ifdef __GLX_MOTIF
Packit Service 7a208c
  sprintf(buf,"GLwMDrawingArea: %s\n",string);
Packit Service 7a208c
#else
Packit Service 7a208c
  sprintf(buf,"GLwDrawingArea: %s\n",string);
Packit Service 7a208c
#endif
Packit Service 7a208c
  XtAppError(XtWidgetToApplicationContext(w),buf);
Packit Service 7a208c
  }
Packit Service 7a208c
Packit Service 7a208c
Packit Service 7a208c
static void warning(Widget w,char* string){
Packit Service 7a208c
  char buf[100];
Packit Service 7a208c
#ifdef __GLX_MOTIF
Packit Service 7a208c
  sprintf (buf, "GLwMDraw: %s\n", string);
Packit Service 7a208c
#else
Packit Service 7a208c
  sprintf (buf, "GLwDraw: %s\n", string);
Packit Service 7a208c
#endif
Packit Service 7a208c
  XtAppWarning(XtWidgetToApplicationContext(w), buf);
Packit Service 7a208c
  }
Packit Service 7a208c
Packit Service 7a208c
Packit Service 7a208c
Packit Service 7a208c
/* Initialize the attribList based on the attributes */
Packit Service 7a208c
static void createAttribList(GLwDrawingAreaWidget w){
Packit Service 7a208c
  int *ptr;
Packit Service 7a208c
  w->glwDrawingArea.attribList = (int*)XtMalloc(ATTRIBLIST_SIZE*sizeof(int));
Packit Service 7a208c
  if(!w->glwDrawingArea.attribList){
Packit Service 7a208c
    error((Widget)w,"Unable to allocate attribute list");
Packit Service 7a208c
    }
Packit Service 7a208c
  ptr = w->glwDrawingArea.attribList;
Packit Service 7a208c
  *ptr++ = GLX_BUFFER_SIZE;
Packit Service 7a208c
  *ptr++ = w->glwDrawingArea.bufferSize;
Packit Service 7a208c
  *ptr++ = GLX_LEVEL;
Packit Service 7a208c
  *ptr++ = w->glwDrawingArea.level;
Packit Service 7a208c
  if(w->glwDrawingArea.rgba) *ptr++ = GLX_RGBA;
Packit Service 7a208c
  if(w->glwDrawingArea.doublebuffer) *ptr++ = GLX_DOUBLEBUFFER;
Packit Service 7a208c
  if(w->glwDrawingArea.stereo) *ptr++ = GLX_STEREO;
Packit Service 7a208c
  *ptr++ = GLX_AUX_BUFFERS;
Packit Service 7a208c
  *ptr++ = w->glwDrawingArea.auxBuffers;
Packit Service 7a208c
  *ptr++ = GLX_RED_SIZE;
Packit Service 7a208c
  *ptr++ = w->glwDrawingArea.redSize;
Packit Service 7a208c
  *ptr++ = GLX_GREEN_SIZE;
Packit Service 7a208c
  *ptr++ = w->glwDrawingArea.greenSize;
Packit Service 7a208c
  *ptr++ = GLX_BLUE_SIZE;
Packit Service 7a208c
  *ptr++ = w->glwDrawingArea.blueSize;
Packit Service 7a208c
  *ptr++ = GLX_ALPHA_SIZE;
Packit Service 7a208c
  *ptr++ = w->glwDrawingArea.alphaSize;
Packit Service 7a208c
  *ptr++ = GLX_DEPTH_SIZE;
Packit Service 7a208c
  *ptr++ = w->glwDrawingArea.depthSize;
Packit Service 7a208c
  *ptr++ = GLX_STENCIL_SIZE;
Packit Service 7a208c
  *ptr++ = w->glwDrawingArea.stencilSize;
Packit Service 7a208c
  *ptr++ = GLX_ACCUM_RED_SIZE;
Packit Service 7a208c
  *ptr++ = w->glwDrawingArea.accumRedSize;
Packit Service 7a208c
  *ptr++ = GLX_ACCUM_GREEN_SIZE;
Packit Service 7a208c
  *ptr++ = w->glwDrawingArea.accumGreenSize;
Packit Service 7a208c
  *ptr++ = GLX_ACCUM_BLUE_SIZE;
Packit Service 7a208c
  *ptr++ = w->glwDrawingArea.accumBlueSize;
Packit Service 7a208c
  *ptr++ = GLX_ACCUM_ALPHA_SIZE;
Packit Service 7a208c
  *ptr++ = w->glwDrawingArea.accumAlphaSize;
Packit Service 7a208c
  *ptr++ = None;
Packit Service 7a208c
  assert((ptr-w->glwDrawingArea.attribList)
Packit Service 7a208c
  }
Packit Service 7a208c
Packit Service 7a208c
Packit Service 7a208c
Packit Service 7a208c
/* Initialize the visualInfo based on the attribute list */
Packit Service 7a208c
static void createVisualInfo(GLwDrawingAreaWidget w){
Packit Service 7a208c
  assert(w->glwDrawingArea.attribList);
Packit Service 7a208c
  w->glwDrawingArea.visualInfo=glXChooseVisual(XtDisplay(w),XScreenNumberOfScreen(XtScreen(w)),w->glwDrawingArea.attribList);
Packit Service 7a208c
  if(!w->glwDrawingArea.visualInfo) error((Widget)w,"requested visual not supported");
Packit Service 7a208c
  }
Packit Service 7a208c
Packit Service 7a208c
Packit Service 7a208c
Packit Service 7a208c
/* Initialize the colormap based on the visual info.
Packit Service 7a208c
 * This routine maintains a cache of visual-infos to colormaps.  If two
Packit Service 7a208c
 * widgets share the same visual info, they share the same colormap.
Packit Service 7a208c
 * This function is called by the callProc of the colormap resource entry.
Packit Service 7a208c
 */
Packit Service 7a208c
static void createColormap(GLwDrawingAreaWidget w,int offset,XrmValue *value){
Packit Service 7a208c
  static struct cmapCache { Visual *visual; Colormap cmap; } *cmapCache;
Packit Service 7a208c
  static int cacheEntries=0;
Packit Service 7a208c
  static int cacheMalloced=0;
Packit Service 7a208c
  register int i;
Packit Service 7a208c
    
Packit Service 7a208c
  assert(w->glwDrawingArea.visualInfo);
Packit Service 7a208c
Packit Service 7a208c
  /* see if we can find it in the cache */
Packit Service 7a208c
  for(i=0; i
Packit Service 7a208c
    if(cmapCache[i].visual==w->glwDrawingArea.visualInfo->visual){
Packit Service 7a208c
      value->addr=(XtPointer)(&cmapCache[i].cmap);
Packit Service 7a208c
      return;
Packit Service 7a208c
      }
Packit Service 7a208c
    }
Packit Service 7a208c
Packit Service 7a208c
  /* not in the cache, create a new entry */
Packit Service 7a208c
  if(cacheEntries >= cacheMalloced){
Packit Service 7a208c
    /* need to malloc a new one.  Since we are likely to have only a
Packit Service 7a208c
     * few colormaps, we allocate one the first time, and double
Packit Service 7a208c
     * each subsequent time.
Packit Service 7a208c
     */
Packit Service 7a208c
    if(cacheMalloced==0){
Packit Service 7a208c
      cacheMalloced=1;
Packit Service 7a208c
      cmapCache=(struct cmapCache*)XtMalloc(sizeof(struct cmapCache));
Packit Service 7a208c
      }
Packit Service 7a208c
    else{
Packit Service 7a208c
      cacheMalloced<<=1;
Packit Service 7a208c
      cmapCache=(struct cmapCache*)XtRealloc((char*)cmapCache,sizeof(struct cmapCache)*cacheMalloced);
Packit Service 7a208c
      }
Packit Service 7a208c
    }
Packit Service 7a208c
       
Packit Service 7a208c
  cmapCache[cacheEntries].cmap=XCreateColormap(XtDisplay(w),
Packit Service 7a208c
                                               RootWindow(XtDisplay(w),
Packit Service 7a208c
                                               w->glwDrawingArea.visualInfo->screen),
Packit Service 7a208c
                                               w->glwDrawingArea.visualInfo->visual,
Packit Service 7a208c
                                               AllocNone);
Packit Service 7a208c
  cmapCache[cacheEntries].visual=w->glwDrawingArea.visualInfo->visual;
Packit Service 7a208c
  value->addr=(XtPointer)(&cmapCache[cacheEntries++].cmap);
Packit Service 7a208c
  }
Packit Service 7a208c
Packit Service 7a208c
Packit Service 7a208c
Packit Service 7a208c
static void Initialize(GLwDrawingAreaWidget req,GLwDrawingAreaWidget neww,ArgList args,Cardinal *num_args){
Packit Service 7a208c
Packit Service 7a208c
  /* fix size */
Packit Service 7a208c
  if(req->core.width==0) neww->core.width=100;
Packit Service 7a208c
  if(req->core.height==0) neww->core.height=100;
Packit Service 7a208c
Packit Service 7a208c
  /* create the attribute list if needed */
Packit Service 7a208c
  neww->glwDrawingArea.myList=FALSE;
Packit Service 7a208c
  if(neww->glwDrawingArea.attribList==NULL){
Packit Service 7a208c
    neww->glwDrawingArea.myList=TRUE;
Packit Service 7a208c
    createAttribList(neww);
Packit Service 7a208c
    }
Packit Service 7a208c
Packit Service 7a208c
  /* Gotta have it */
Packit Service 7a208c
  assert(neww->glwDrawingArea.attribList);
Packit Service 7a208c
Packit Service 7a208c
  /* determine the visual info if needed */
Packit Service 7a208c
  neww->glwDrawingArea.myVisual=FALSE;
Packit Service 7a208c
  if(neww->glwDrawingArea.visualInfo==NULL){
Packit Service 7a208c
    neww->glwDrawingArea.myVisual=TRUE;
Packit Service 7a208c
    createVisualInfo(neww);
Packit Service 7a208c
    }
Packit Service 7a208c
Packit Service 7a208c
  /* Gotta have that too */
Packit Service 7a208c
  assert(neww->glwDrawingArea.visualInfo);
Packit Service 7a208c
Packit Service 7a208c
  neww->core.depth=neww->glwDrawingArea.visualInfo->depth;
Packit Service 7a208c
Packit Service 7a208c
  /* Reobtain the colormap and colors in it using XtGetApplicationResources*/
Packit Service 7a208c
  XtGetApplicationResources((Widget)neww,neww,initializeResources,XtNumber(initializeResources),args,*num_args);
Packit Service 7a208c
Packit Service 7a208c
  /* obtain the color resources if appropriate */
Packit Service 7a208c
  if(req->glwDrawingArea.allocateBackground){
Packit Service 7a208c
    XtGetApplicationResources((Widget)neww,neww,backgroundResources,XtNumber(backgroundResources),args,*num_args);
Packit Service 7a208c
    }
Packit Service 7a208c
Packit Service 7a208c
#ifdef __GLX_MOTIF
Packit Service 7a208c
  if(req->glwDrawingArea.allocateOtherColors){
Packit Service 7a208c
    XtGetApplicationResources((Widget)neww,neww,otherColorResources,XtNumber(otherColorResources),args,*num_args);
Packit Service 7a208c
    }
Packit Service 7a208c
#endif 
Packit Service 7a208c
  }
Packit Service 7a208c
Packit Service 7a208c
Packit Service 7a208c
Packit Service 7a208c
static void Realize(Widget w,Mask *valueMask,XSetWindowAttributes *attributes){
Packit Service 7a208c
  register GLwDrawingAreaWidget glw=(GLwDrawingAreaWidget)w;
Packit Service 7a208c
  GLwDrawingAreaCallbackStruct cb;
Packit Service 7a208c
  Widget parentShell;
Packit Service 7a208c
  Status status;
Packit Service 7a208c
  Window windows[2],*windowsReturn,*windowList;
Packit Service 7a208c
  int countReturn,i;
Packit Service 7a208c
   
Packit Service 7a208c
  /* if we haven't requested that the background be both installed and
Packit Service 7a208c
   * allocated, don't install it.
Packit Service 7a208c
   */
Packit Service 7a208c
  if(!(glw->glwDrawingArea.installBackground && glw->glwDrawingArea.allocateBackground)){
Packit Service 7a208c
    *valueMask&=~CWBackPixel;
Packit Service 7a208c
    }
Packit Service 7a208c
 
Packit Service 7a208c
  XtCreateWindow(w,(unsigned int)InputOutput,glw->glwDrawingArea.visualInfo->visual,*valueMask,attributes);
Packit Service 7a208c
Packit Service 7a208c
  /* if appropriate, call XSetWMColormapWindows to install the colormap */
Packit Service 7a208c
  if(glw->glwDrawingArea.installColormap){
Packit Service 7a208c
Packit Service 7a208c
    /* Get parent shell */
Packit Service 7a208c
    for(parentShell=XtParent(w); parentShell&&!XtIsShell(parentShell); parentShell=XtParent(parentShell));
Packit Service 7a208c
Packit Service 7a208c
    if(parentShell && XtWindow(parentShell)){
Packit Service 7a208c
Packit Service 7a208c
      /* check to see if there is already a property */
Packit Service 7a208c
      status=XGetWMColormapWindows(XtDisplay(parentShell),XtWindow(parentShell),&windowsReturn,&countReturn);
Packit Service 7a208c
            
Packit Service 7a208c
      /* if no property, just create one */
Packit Service 7a208c
      if(!status){
Packit Service 7a208c
        windows[0]=XtWindow(w);
Packit Service 7a208c
        windows[1]=XtWindow(parentShell);
Packit Service 7a208c
        XSetWMColormapWindows(XtDisplay(parentShell),XtWindow(parentShell),windows,2);
Packit Service 7a208c
        }
Packit Service 7a208c
Packit Service 7a208c
      /* there was a property, add myself to the beginning */
Packit Service 7a208c
      else{
Packit Service 7a208c
        windowList=(Window *)XtMalloc((sizeof(Window))*(countReturn+1));
Packit Service 7a208c
        windowList[0]=XtWindow(w);
Packit Service 7a208c
        for(i=0; i
Packit Service 7a208c
        XSetWMColormapWindows(XtDisplay(parentShell),XtWindow(parentShell),windowList,countReturn+1);
Packit Service 7a208c
        XtFree((char*)windowList);
Packit Service 7a208c
        XtFree((char*)windowsReturn);
Packit Service 7a208c
        }
Packit Service 7a208c
      }
Packit Service 7a208c
    else{
Packit Service 7a208c
      warning(w,"Could not set colormap property on parent shell");
Packit Service 7a208c
      }
Packit Service 7a208c
    }
Packit Service 7a208c
Packit Service 7a208c
  /* Invoke callbacks */
Packit Service 7a208c
  cb.reason=GLwCR_GINIT;
Packit Service 7a208c
  cb.event=NULL;
Packit Service 7a208c
  cb.width=glw->core.width;
Packit Service 7a208c
  cb.height=glw->core.height;
Packit Service 7a208c
  XtCallCallbackList((Widget)glw,glw->glwDrawingArea.ginitCallback,&cb;;
Packit Service 7a208c
  }
Packit Service 7a208c
Packit Service 7a208c
Packit Service 7a208c
Packit Service 7a208c
static void Redraw(GLwDrawingAreaWidget w,XEvent *event,Region region){
Packit Service 7a208c
  GLwDrawingAreaCallbackStruct cb;
Packit Service 7a208c
  if(!XtIsRealized((Widget)w)) return;
Packit Service 7a208c
  cb.reason=GLwCR_EXPOSE;
Packit Service 7a208c
  cb.event=event;
Packit Service 7a208c
  cb.width=w->core.width;
Packit Service 7a208c
  cb.height=w->core.height;
Packit Service 7a208c
  XtCallCallbackList((Widget)w,w->glwDrawingArea.exposeCallback,&cb;;
Packit Service 7a208c
  }
Packit Service 7a208c
Packit Service 7a208c
Packit Service 7a208c
Packit Service 7a208c
static void Resize(GLwDrawingAreaWidget glw){
Packit Service 7a208c
  GLwDrawingAreaCallbackStruct cb;
Packit Service 7a208c
  if(!XtIsRealized((Widget)glw)) return;
Packit Service 7a208c
  cb.reason=GLwCR_RESIZE;
Packit Service 7a208c
  cb.event=NULL;
Packit Service 7a208c
  cb.width=glw->core.width;
Packit Service 7a208c
  cb.height=glw->core.height;
Packit Service 7a208c
  XtCallCallbackList((Widget)glw,glw->glwDrawingArea.resizeCallback,&cb;;
Packit Service 7a208c
  }
Packit Service 7a208c
Packit Service 7a208c
Packit Service 7a208c
Packit Service 7a208c
static void Destroy(GLwDrawingAreaWidget glw){
Packit Service 7a208c
  Window *windowsReturn;
Packit Service 7a208c
  Widget parentShell;
Packit Service 7a208c
  Status status;
Packit Service 7a208c
  int countReturn;
Packit Service 7a208c
  register int i;
Packit Service 7a208c
Packit Service 7a208c
  if(glw->glwDrawingArea.myList && glw->glwDrawingArea.attribList){
Packit Service 7a208c
    XtFree((XtPointer)glw->glwDrawingArea.attribList);
Packit Service 7a208c
    }
Packit Service 7a208c
Packit Service 7a208c
  if(glw->glwDrawingArea.myVisual && glw->glwDrawingArea.visualInfo){
Packit Service 7a208c
    XtFree((XtPointer)glw->glwDrawingArea.visualInfo);
Packit Service 7a208c
    }
Packit Service 7a208c
Packit Service 7a208c
  /* if my colormap was installed, remove it */
Packit Service 7a208c
  if(glw->glwDrawingArea.installColormap){
Packit Service 7a208c
Packit Service 7a208c
    /* Get parent shell */
Packit Service 7a208c
    for(parentShell=XtParent(glw); parentShell&&!XtIsShell(parentShell); parentShell=XtParent(parentShell));
Packit Service 7a208c
Packit Service 7a208c
    if(parentShell && XtWindow(parentShell)){
Packit Service 7a208c
Packit Service 7a208c
      /* make sure there is a property */
Packit Service 7a208c
      status=XGetWMColormapWindows(XtDisplay(parentShell),XtWindow(parentShell),&windowsReturn,&countReturn);
Packit Service 7a208c
            
Packit Service 7a208c
      /* if no property, just return.  If there was a property, continue */
Packit Service 7a208c
      if(status){
Packit Service 7a208c
Packit Service 7a208c
        /* search for a match */
Packit Service 7a208c
        for(i=0; i
Packit Service 7a208c
          if(windowsReturn[i]==XtWindow(glw)){
Packit Service 7a208c
Packit Service 7a208c
            /* we found a match, now copy the rest down */
Packit Service 7a208c
            for(i++; i
Packit Service 7a208c
Packit Service 7a208c
            XSetWMColormapWindows(XtDisplay(parentShell),XtWindow(parentShell),windowsReturn,countReturn-1);
Packit Service 7a208c
            break; 
Packit Service 7a208c
            }
Packit Service 7a208c
          }
Packit Service 7a208c
        XtFree((char *)windowsReturn);
Packit Service 7a208c
        }
Packit Service 7a208c
      }
Packit Service 7a208c
    }
Packit Service 7a208c
  }
Packit Service 7a208c
Packit Service 7a208c
Packit Service 7a208c
Packit Service 7a208c
/* Action routine for keyboard and mouse events */
Packit Service 7a208c
static void glwInput(GLwDrawingAreaWidget glw,XEvent *event,String *params,Cardinal *numParams){
Packit Service 7a208c
  GLwDrawingAreaCallbackStruct cb;
Packit Service 7a208c
  cb.reason=GLwCR_INPUT;
Packit Service 7a208c
  cb.event=event;
Packit Service 7a208c
  cb.width=glw->core.width;
Packit Service 7a208c
  cb.height=glw->core.height;
Packit Service 7a208c
  XtCallCallbackList((Widget)glw,glw->glwDrawingArea.inputCallback,&cb;;
Packit Service 7a208c
  }
Packit Service 7a208c
Packit Service 7a208c
Packit Service 7a208c
#ifdef __GLX_MOTIF
Packit Service 7a208c
Packit Service 7a208c
/* Create routine */
Packit Service 7a208c
Widget GLwCreateMDrawingArea(Widget parent, char *name,ArgList arglist,Cardinal argcount){
Packit Service 7a208c
  return XtCreateWidget(name,glwMDrawingAreaWidgetClass, parent, arglist,argcount);
Packit Service 7a208c
  }
Packit Service 7a208c
Packit Service 7a208c
#endif
Packit Service 7a208c
Packit Service 7a208c
Packit Service 7a208c
#ifndef __GLX_MOTIF
Packit Service 7a208c
Packit Service 7a208c
/* Make context current */
Packit Service 7a208c
void GLwDrawingAreaMakeCurrent(Widget w,GLXContext ctx){
Packit Service 7a208c
  glXMakeCurrent(XtDisplay(w),XtWindow(w),ctx);
Packit Service 7a208c
  }
Packit Service 7a208c
Packit Service 7a208c
Packit Service 7a208c
/* Swap buffers convenience function */
Packit Service 7a208c
void GLwDrawingAreaSwapBuffers(Widget w){
Packit Service 7a208c
  glXSwapBuffers(XtDisplay(w),XtWindow(w));
Packit Service 7a208c
  }
Packit Service 7a208c
Packit Service 7a208c
#endif