/* $Header: /afs/athena.mit.edu/astaff/project/atdev/src/drawarea/RCS/DrawingArea.c,v 1.1 90/09/15 23:29:28 crcraig Exp $ */

/* 
  Copyright (C) 1990 by the Massachusetts Institute of Technology

   Export of this software from the United States of America is assumed
   to require a specific license from the United States Government.
   It is the responsibility of any person or organization contemplating
   export to obtain such a license before exporting.

WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
distribute this software and its documentation for any purpose and
without fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright notice and
this permission notice appear in supporting documentation, and that
the name of M.I.T. not be used in advertising or publicity pertaining
to distribution of the software without specific, written prior
permission.  M.I.T. makes no representations about the suitability of
this software for any purpose.  It is provided "as is" without express
or implied warranty.

  */

#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
#include "DrawingAreaP.h"

#include <stdio.h>

#define DRAWAREA_DEFAULT_WIDTH  100
#define DRAWAREA_DEFAULT_HEIGHT 100

static void Initialize(Widget, Widget);
static void Destroy(Widget);
static void Resize(AtDrawingAreaWidget);
static void Redisplay(AtDrawingAreaWidget, XEvent *, Region);
static void InputHandler(AtDrawingAreaWidget, caddr_t, XEvent *, 
			 Boolean *);
static Boolean SetValues(Widget, Widget, Widget);

/**********************************************************************/
/*                      AtDrawingArea Resources                       */
/**********************************************************************/

#define offset(field) XtOffset(AtDrawingAreaWidget, draw.field)
static XtResource resources[] = {
  { XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel),
      offset(foreground), XtRString, "XtDefaultForeground" },
  { XtNexposeCallback, XtCCallback, XtRCallback, sizeof(XtCallbackList),
      offset(exposeCallback), XtRCallback, NULL },
  { XtNinputCallback, XtCCallback, XtRCallback, sizeof(XtCallbackList), 
      offset(inputCallback), XtRCallback, NULL },
  { XtNresizeCallback, XtCCallback, XtRCallback, sizeof(XtCallbackList), 
      offset(resizeCallback), XtRCallback, NULL },
};
#undef offset


AtDrawingAreaClassRec atDrawingAreaClassRec = {
  { /* core fields */
    /* superclass		*/	(WidgetClass) &widgetClassRec,
    /* class_name		*/	"AtDrawingArea",
    /* widget_size		*/	sizeof(AtDrawingAreaRec),
    /* class_initialize		*/	NULL,
    /* class_part_initialize	*/	NULL,
    /* class_inited		*/	FALSE,
    /* initialize		*/	Initialize,
    /* initialize_hook		*/	NULL,
    /* realize			*/	XtInheritRealize,
    /* actions			*/	NULL,
    /* num_actions		*/	0,
    /* resources		*/	resources,
    /* num_resources		*/	XtNumber(resources),
    /* xrm_class		*/	NULLQUARK,
    /* compress_motion		*/	TRUE,
    /* compress_exposure	*/	TRUE,
    /* compress_enterleave	*/	TRUE,
    /* visible_interest		*/	FALSE,
    /* destroy			*/	Destroy,
    /* resize			*/	Resize,
    /* expose			*/	Redisplay,
    /* set_values		*/	SetValues,
    /* set_values_hook		*/	NULL,
    /* set_values_almost	*/	XtInheritSetValuesAlmost,
    /* get_values_hook		*/	NULL,
    /* accept_focus		*/	NULL,
    /* version			*/	XtVersion,
    /* callback_private		*/	NULL,
    /* tm_table			*/	NULL,
    /* query_geometry		*/	XtInheritQueryGeometry,
    /* display_accelerator	*/	XtInheritDisplayAccelerator,
    /* extension		*/	NULL
  },
  { /* drawingarea fields */
    /* blurble			*/	0
  }
};

WidgetClass atDrawingAreaWidgetClass = (WidgetClass) &atDrawingAreaClassRec;

/**********************************************************************/
/*                        Initialize Method                           */
/**********************************************************************/

static void Initialize(Widget req, Widget new)

{
  XtAddEventHandler(new, (ButtonPressMask | ButtonReleaseMask |
			  KeyPressMask | KeyReleaseMask), False, 
		    InputHandler, NULL);

  if (new->core.width == 0)
    new->core.width = DRAWAREA_DEFAULT_WIDTH;
  if (new->core.height == 0)
    new->core.height = DRAWAREA_DEFAULT_HEIGHT;

  Resize((AtDrawingAreaWidget) new);
}

/**********************************************************************/
/*                           Destroy Method                           */
/**********************************************************************/

static void Destroy(Widget w)

{
  XtRemoveAllCallbacks(w, XtNexposeCallback);
  XtRemoveAllCallbacks(w, XtNresizeCallback);
  XtRemoveAllCallbacks(w, XtNinputCallback);
}

/**********************************************************************/
/*                           Resize Method                            */
/**********************************************************************/

static void Resize(AtDrawingAreaWidget da)

{
  AtDrawingAreaCallbackStruct cs;

  cs.window = XtWindow(da);
  cs.event = NULL;
  XtCallCallbackList(da, da->draw.resizeCallback, &cs);
}

/**********************************************************************/
/*                        Redisplay Method                            */
/**********************************************************************/

static void Redisplay(AtDrawingAreaWidget da, XEvent *event, Region region)

{
  AtDrawingAreaCallbackStruct cs;

  cs.window = XtWindow(da);
  cs.event = event;

  XtCallCallbackList(da, da->draw.exposeCallback, &cs);
}

/**********************************************************************/
/*                    InputHandler Event Handler                      */
/**********************************************************************/

static void InputHandler(AtDrawingAreaWidget da, caddr_t client_data,
			 XEvent *event, Boolean *dispatch)

{
  AtDrawingAreaCallbackStruct cs;

  cs.window = XtWindow(da);
  cs.event = event;

  XtCallCallbackList(da, da->draw.inputCallback, &cs);
}

/**********************************************************************/
/*                        SetValues Method                            */
/**********************************************************************/

static Boolean SetValues(Widget current, Widget request, Widget new)

{
  return False;
}
