home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume8 / ball2 / part01 / xball / DrawingA.c next >
C/C++ Source or Header  |  1990-06-26  |  5KB  |  163 lines

  1. /* DrawingA.c: The DrawingArea Widget Methods */
  2.  
  3. /* Copyright 1990, David Nedde
  4. /*
  5. /* This software is released into the public domain.
  6. /* Permission to use, copy, modify, and distribute this
  7. /* software and its documentation for any purpose and without fee
  8. /* is granted provided that the above copyright notice appears in all copies.
  9. /* It is provided "as is" without express or implied warranty.
  10. */
  11.  
  12. #include <X11/IntrinsicP.h>
  13. #include <X11/StringDefs.h>
  14. #include "DrawingAP.h"
  15.  
  16. static void    Initialize();
  17. static void    Redisplay();
  18. static void    input_draw();
  19. static void    motion_draw();
  20. static void    resize_draw();
  21.  
  22. static char defaultTranslations[] = "<BtnDown>: input() \n <BtnUp>: input() \n <KeyDown>: input() \n <KeyUp>: input() \n <Motion>: motion() \n <Configure>: resize()";
  23. static XtActionsRec actionsList[] = {
  24.   { "input",  (XtActionProc)input_draw },
  25.   { "motion", (XtActionProc)motion_draw },
  26.   { "resize", (XtActionProc)resize_draw },
  27. };
  28.  
  29. /* Default instance record values */
  30. static XtResource resources[] = {
  31.   {XtNexposeCallback, XtCCallback, XtRCallback, sizeof(caddr_t),
  32.      XtOffset(DrawingAreaWidget, drawing_area.expose_callbacks), 
  33.      XtRCallback, NULL },
  34.   {XtNinputCallback, XtCCallback, XtRCallback, sizeof(caddr_t),
  35.      XtOffset(DrawingAreaWidget, drawing_area.input_callbacks), 
  36.      XtRCallback, NULL },
  37.   {XtNmotionCallback, XtCCallback, XtRCallback, sizeof(caddr_t),
  38.      XtOffset(DrawingAreaWidget, drawing_area.motion_callbacks), 
  39.      XtRCallback, NULL },
  40.   {XtNresizeCallback, XtCCallback, XtRCallback, sizeof(caddr_t),
  41.      XtOffset(DrawingAreaWidget, drawing_area.resize_callbacks), 
  42.      XtRCallback, NULL },
  43. };
  44.  
  45.  
  46. DrawingAreaClassRec drawingAreaClassRec = {
  47.   /* CoreClassPart */
  48. {
  49.   (WidgetClass) &widgetClassRec,    /* superclass          */    
  50.     "DrawingArea",            /* class_name          */
  51.     sizeof(DrawingAreaRec),        /* size              */
  52.     NULL,                /* class_initialize      */
  53.     NULL,                /* class_part_initialize  */
  54.     FALSE,                /* class_inited          */
  55.     Initialize,                /* initialize          */
  56.     NULL,                /* initialize_hook      */
  57.     XtInheritRealize,            /* realize          */
  58.     actionsList,            /* actions          */
  59.     XtNumber(actionsList),        /* num_actions          */
  60.     resources,                /* resources          */
  61.     XtNumber(resources),        /* resource_count      */
  62.     NULLQUARK,                /* xrm_class          */
  63.     FALSE,                /* compress_motion      */
  64.     FALSE,                /* compress_exposure      */
  65.     TRUE,                /* compress_enterleave    */
  66.     FALSE,                /* visible_interest      */
  67.     NULL,                /* destroy          */
  68.     NULL,                /* resize          */
  69.     Redisplay,                /* expose          */
  70.     NULL,                /* set_values          */
  71.     NULL,                /* set_values_hook      */
  72.     XtInheritSetValuesAlmost,        /* set_values_almost      */
  73.     NULL,                /* get_values_hook      */
  74.     NULL,                /* accept_focus          */
  75.     XtVersion,                /* version          */
  76.     NULL,                /* callback_private      */
  77.     defaultTranslations,        /* tm_table          */
  78.     XtInheritQueryGeometry,        /* query_geometry      */
  79.     XtInheritDisplayAccelerator,    /* display_accelerator      */
  80.     NULL                /* extension          */
  81.   },  /* CoreClass fields initialization */
  82.   {
  83.     0,                                     /* field not used    */
  84.   },  /* LabelClass fields initialization */
  85.   {
  86.     0,                                     /* field not used    */
  87.   },  /* DrawingAreaClass fields initialization */
  88. };
  89.  
  90.   
  91. WidgetClass drawingAreaWidgetClass = (WidgetClass)&drawingAreaClassRec;
  92.  
  93.  
  94. static void Initialize( request, new)
  95. DrawingAreaWidget request, new;
  96. {
  97.   if (request->core.width == 0)
  98.     new->core.width = 100;
  99.   if (request->core.height == 0)
  100.     new->core.height = 100;
  101. }
  102.  
  103.  
  104. /* Invoke expose callbacks */
  105. static void Redisplay(w, event, region)
  106. DrawingAreaWidget w;
  107. XEvent         *event;
  108. Region          region;
  109. {
  110.   XawDrawingAreaCallbackStruct cb;
  111.  
  112.   cb.reason = XawCR_EXPOSE;
  113.   cb.event  = event;
  114.   cb.window = XtWindow(w);
  115.   XtCallCallbacks(w, XtNexposeCallback, &cb);
  116. }
  117.  
  118. /* Invoke resize callbacks */
  119. static void resize_draw(w, event, args, n_args)
  120. DrawingAreaWidget w;
  121. XEvent         *event;
  122. char         *args[];
  123. int          n_args;
  124. {
  125.   XawDrawingAreaCallbackStruct cb;
  126.  
  127.   cb.reason = XawCR_RESIZE;
  128.   cb.event  = event;
  129.   cb.window = XtWindow(w);
  130.   XtCallCallbacks(w, XtNresizeCallback, &cb);
  131. }
  132.  
  133. /* Invoke input callbacks */
  134. static void input_draw(w, event, args, n_args)
  135. DrawingAreaWidget w;
  136. XEvent         *event;
  137. char         *args[];
  138. int          n_args;
  139. {
  140.   XawDrawingAreaCallbackStruct cb;
  141.  
  142.   cb.reason = XawCR_INPUT;
  143.   cb.event  = event;
  144.   cb.window = XtWindow(w);
  145.   XtCallCallbacks(w, XtNinputCallback, &cb);
  146. }
  147.  
  148. /* Invoke motion callbacks */
  149. static void motion_draw(w, event, args, n_args)
  150. DrawingAreaWidget w;
  151. XEvent         *event;
  152. char         *args[];
  153. int          n_args;
  154. {
  155.   XawDrawingAreaCallbackStruct cb;
  156.  
  157.   cb.reason = XawCR_MOTION;
  158.   cb.event  = event;
  159.   cb.window = XtWindow(w);
  160.   XtCallCallbacks(w, XtNmotionCallback, &cb);
  161. }
  162.  
  163.