File: DrawingA.c

package info (click to toggle)
3dchess 0.8.1-24
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 548 kB
  • sloc: ansic: 3,035; makefile: 46
file content (175 lines) | stat: -rw-r--r-- 5,140 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/* DrawingA.c: The DrawingArea Widget Methods */

/* Copyright 1990, David Nedde
 *
 * Permission to use, copy, modify, and distribute this
 * software and its documentation for any purpose and without fee
 * is granted provided that the above copyright notice appears in all copies.
 * It is provided "as is" without express or implied warranty.
 */

#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
#include <X11/CoreP.h>
#include <X11/Xaw/SimpleP.h>
#include "../include/DrawingAP.h"

static void	Initialize();
static void	Destroy();
static void	Redisplay();
static void	input_draw();
static void	motion_draw();
static void	resize_draw();

static char defaultTranslations[] = "<BtnDown>: input() \n <BtnUp>: input() \n <KeyDown>: input() \n <KeyUp>: input() \n <Motion>: motion() \n <Configure>: resize()";
static XtActionsRec actionsList[] = {
  { "input",  (XtActionProc)input_draw },
  { "motion", (XtActionProc)motion_draw },
  { "resize", (XtActionProc)resize_draw },
};

/* Default instance record values */
static XtResource resources[] = {
  {XtNexposeCallback, XtCCallback, XtRCallback, sizeof(caddr_t),
     XtOffset(DrawingAreaWidget, drawing_area.expose_callback), 
     XtRCallback, NULL },
  {XtNinputCallback, XtCCallback, XtRCallback, sizeof(caddr_t),
     XtOffset(DrawingAreaWidget, drawing_area.input_callback), 
     XtRCallback, NULL },
  {XtNmotionCallback, XtCCallback, XtRCallback, sizeof(caddr_t),
     XtOffset(DrawingAreaWidget, drawing_area.motion_callback), 
     XtRCallback, NULL },
  {XtNresizeCallback, XtCCallback, XtRCallback, sizeof(caddr_t),
     XtOffset(DrawingAreaWidget, drawing_area.resize_callback), 
     XtRCallback, NULL },
};


DrawingAreaClassRec drawingAreaClassRec = {
  /* CoreClassPart */
{
  (WidgetClass) &simpleClassRec,	/* superclass		  */	
    "DrawingArea",			/* class_name		  */
    sizeof(DrawingAreaRec),		/* size			  */
    NULL,				/* class_initialize	  */
    NULL,				/* class_part_initialize  */
    FALSE,				/* class_inited		  */
    Initialize,				/* initialize		  */
    NULL,				/* initialize_hook	  */
    XtInheritRealize,			/* realize		  */
    actionsList,			/* actions		  */
    XtNumber(actionsList),		/* num_actions		  */
    resources,				/* resources		  */
    XtNumber(resources),		/* resource_count	  */
    NULLQUARK,				/* xrm_class		  */
    FALSE,				/* compress_motion	  */
    FALSE,				/* compress_exposure	  */
    TRUE,				/* compress_enterleave    */
    FALSE,				/* visible_interest	  */
    Destroy,				/* destroy		  */
    NULL,				/* resize		  */
    Redisplay,				/* expose		  */
    NULL,				/* set_values		  */
    NULL,				/* set_values_hook	  */
    XtInheritSetValuesAlmost,		/* set_values_almost	  */
    NULL,				/* get_values_hook	  */
    NULL,				/* accept_focus		  */
    XtVersion,				/* version		  */
    NULL,				/* callback_private	  */
    defaultTranslations,		/* tm_table		  */
    XtInheritQueryGeometry,		/* query_geometry	  */
    XtInheritDisplayAccelerator,	/* display_accelerator	  */
    NULL				/* extension		  */
  },  /* CoreClass fields initialization */
  {
    /* change_sensitive		*/	XtInheritChangeSensitive
  },  /* SimpleClass fields initialization */
  {
    0,                                     /* field not used    */
  },  /* DrawingAreaClass fields initialization */
};

  
WidgetClass drawingAreaWidgetClass = (WidgetClass)&drawingAreaClassRec;


static void Initialize( request, new)
DrawingAreaWidget request, new;
{
  if (request->core.width == 0)
    new->core.width = 100;
  if (request->core.height == 0)
    new->core.height = 100;
}




static void Destroy( w)
DrawingAreaWidget w;
{
  XtRemoveAllCallbacks((Widget)w, XtNexposeCallback);
  XtRemoveAllCallbacks((Widget)w, XtNinputCallback);
  XtRemoveAllCallbacks((Widget)w, XtNmotionCallback);
  XtRemoveAllCallbacks((Widget)w, XtNresizeCallback);
}


/* Invoke expose callbacks */
static void Redisplay(w, event, region)
DrawingAreaWidget w;
XEvent		 *event;
Region		  region;
{
  XawDrawingAreaCallbackStruct cb;

  cb.reason = XawCR_EXPOSE;
  cb.event  = event;
  cb.window = XtWindow(w);
  XtCallCallbacks((Widget)w, XtNexposeCallback, (char *)&cb);
}

/* Invoke resize callbacks */
static void resize_draw(w, event, args, n_args)
DrawingAreaWidget w;
XEvent		 *event;
char		 *args[];
int		  n_args;
{
  XawDrawingAreaCallbackStruct cb;

  cb.reason = XawCR_RESIZE;
  cb.event  = event;
  cb.window = XtWindow(w);
  XtCallCallbacks((Widget)w, XtNresizeCallback, (char *)&cb);
}

/* Invoke input callbacks */
static void input_draw(w, event, args, n_args)
DrawingAreaWidget w;
XEvent		 *event;
char		 *args[];
int		  n_args;
{
  XawDrawingAreaCallbackStruct cb;

  cb.reason = XawCR_INPUT;
  cb.event  = event;
  cb.window = XtWindow(w);
  XtCallCallbacks((Widget)w, XtNinputCallback, (char *)&cb);
}

/* Invoke motion callbacks */
static void motion_draw(w, event, args, n_args)
DrawingAreaWidget w;
XEvent		 *event;
char		 *args[];
int		  n_args;
{
  XawDrawingAreaCallbackStruct cb;

  cb.reason = XawCR_MOTION;
  cb.event  = event;
  cb.window = XtWindow(w);
  XtCallCallbacks((Widget)w, XtNmotionCallback, (char *)&cb);
}