home *** CD-ROM | disk | FTP | other *** search
/ PC Shareware 1999 March / PCShareware-3-99.iso / IMPLE / DJGPP.RAR / DJGPP2 / XLIB-APP.ZIP / TMP / XMINE / CANVAS.C < prev    next >
C/C++ Source or Header  |  1994-09-03  |  4KB  |  129 lines

  1. /*
  2.  
  3.     Canvas.c - a widget that allows programmer-specified refresh procedures.
  4.     Copyright (C) 1990 Robert H. Forsman Jr.
  5.  
  6.     This library is free software; you can redistribute it and/or
  7.     modify it under the terms of the GNU Library General Public
  8.     License as published by the Free Software Foundation; either
  9.     version 2 of the License, or (at your option) any later version.
  10.  
  11.     This library is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.     Library General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU Library General Public
  17.     License along with this library; if not, write to the Free
  18.     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20.  */
  21.  
  22. /* slightly modified to use "here" includes - jw */
  23.  
  24. #include <X11/IntrinsP.h>
  25. #include <X11/StringDefs.h>
  26.  
  27. #include <stdio.h>
  28.  
  29. #include "CanvasP.h"
  30.  
  31. #define offset(field) XtOffset(CanvasWidget, canvas.field)
  32.  
  33. static XtResource resources[] = {
  34.   {XtNexposeProc, XtCExposeProc, XtRFunction, sizeof(XfwfCanvasExposeProc),
  35.      offset(redraw),    XtRFunction, NULL},
  36.   {XtNexposeProcData, XtCExposeProcData, XtRPointer, sizeof(XtPointer),
  37.      offset(redraw_data), XtRFunction, NULL},
  38.   {XtNresizeProc, XtCResizeProc, XtRFunction, sizeof(XfwfCanvasResizeProc),
  39.      offset(resize),    XtRFunction, NULL},
  40.   {XtNresizeProcData, XtCResizeProcData, XtRPointer, sizeof(XtPointer),
  41.      offset(resize_data), XtRFunction, NULL},
  42. };
  43.  
  44.  
  45. static void Redisplay();
  46. static void Resize();
  47. static Boolean SetValues();
  48.  
  49.  
  50. CanvasClassRec canvasClassRec = {
  51.     {
  52.     /* core_class fields     */
  53.     /* superclass           */ (WidgetClass) &widgetClassRec,
  54.     /* class_name           */ "Canvas",
  55.     /* widget_size           */ sizeof(CanvasRec),
  56.     /* class_initialize        */ NULL,
  57.     /* class_part_initialize     */ NULL,
  58.     /* class_inited            */ False,
  59.     /* initialize           */ NULL,
  60.     /* initialize_hook         */ NULL,
  61.     /* realize               */ XtInheritRealize,
  62.     /* actions               */ NULL,
  63.     /* num_actions           */ 0,
  64.     /* resources           */ resources,
  65.     /* num_resources           */ XtNumber(resources),
  66.     /* xrm_class           */ NULLQUARK,
  67.     /* compress_motion           */ True,
  68.     /* compress_exposure       */ XtExposeCompressMultiple,
  69.     /* compress_enterleave     */ True,
  70.     /* visible_interest           */ True,
  71.     /* destroy               */ NULL,
  72.     /* resize               */ Resize,
  73.     /* expose               */ Redisplay,
  74.     /* set_values           */ SetValues,
  75.     /* set_values_hook         */ NULL,
  76.     /* set_values_almost     */ XtInheritSetValuesAlmost,
  77.     /* get_values_hook         */ NULL,
  78.     /* accept_focus          */ NULL,
  79.     /* version             */ XtVersion,
  80.     /* callback_private        */ NULL,
  81.     /* tm_table                */ NULL,
  82.     /* query_geometry         */ NULL,
  83.     /* display_accelerator       */ XtInheritDisplayAccelerator,
  84.     /* extension                 */ NULL
  85.     },
  86.     {
  87.       0 /* some stupid compilers barf on empty structures */
  88.     },
  89. };
  90.  
  91. WidgetClass canvasWidgetClass = (WidgetClass) & canvasClassRec;
  92.  
  93.  
  94. static void Redisplay(w, event, region)
  95. Widget w;
  96. XExposeEvent *event;
  97. Region region;
  98. {
  99.   CanvasWidget    cw = (CanvasWidget)w;
  100.   if (!XtIsRealized(w))
  101.     return;
  102.  
  103.   if (cw->canvas.redraw)
  104.     (cw->canvas.redraw)((Widget)cw,event,region,cw->canvas.redraw_data);
  105.  
  106. }
  107.  
  108. static Boolean SetValues(current, request, new, args, nargs)
  109. CanvasWidget current, request, new;
  110. ArgList args;
  111. Cardinal *nargs;
  112. {
  113.   int    i;
  114.   for(i=0; i<*nargs; i++) {
  115.     if (strcmp(XtNexposeProc,args[i].name)==0 ||
  116.     strcmp(XtNexposeProcData,args[i].name)==0)
  117.       return True;
  118.   }
  119.   return False;
  120. }
  121.  
  122.  
  123. static void Resize(cw)
  124. CanvasWidget cw;
  125. {
  126.   if (cw->canvas.resize)
  127.     (cw->canvas.resize)((Widget)cw, cw->canvas.resize_data);
  128. }
  129.