1 /*************************************<+>*************************************
2  *****************************************************************************
3  **
4  **   File:        WorkSpace.c
5  **
6  **   Project:     X Widgets
7  **
8  **   Description: Contains code for workSpace widget class.
9  **
10  *****************************************************************************
11  **
12  **   Copyright (c) 1988 by Hewlett-Packard Company
13  **   Copyright (c) 1988 by the Massachusetts Institute of Technology
14  **
15  **   Permission to use, copy, modify, and distribute this software
16  **   and its documentation for any purpose and without fee is hereby
17  **   granted, provided that the above copyright notice appear in all
18  **   copies and that both that copyright notice and this permission
19  **   notice appear in supporting documentation, and that the names of
20  **   Hewlett-Packard or  M.I.T.  not be used in advertising or publicity
21  **   pertaining to distribution of the software without specific, written
22  **   prior permission.
23  **
24  *****************************************************************************
25  *************************************<+>*************************************/
26 
27 
28 #include <stdio.h>
29 #include <string.h>
30 #include <ctype.h>
31 #include <X11/StringDefs.h>
32 #include <X11/keysymdef.h>
33 #include <X11/IntrinsicP.h>
34 #include <X11/Intrinsic.h>
35 #include <Xw/Xw.h>
36 #include <Xw/XwP.h>
37 #include <Xw/WorkSpace.h>
38 #include <Xw/WorkSpaceP.h>
39 
40 
41 /*  Event procedures referenced in the actions list  */
42 
43 static void KeyDown();
44 static void KeyUp();
45 static void Select();
46 static void Release();
47 
48 
49 /*  Default translation table and action list  */
50 
51 static char defaultTranslations[] =
52     "<KeyDown>:         keydown()\n\
53      <KeyUp>:           keyup()\n\
54      <BtnDown>:         select()\n\
55      <BtnUp>:           release()\n\
56      <EnterWindow>:     enter()\n\
57      <LeaveWindow>:     leave()";
58 
59 
60 static XtActionsRec actionsList[] =
61 {
62   { "keydown",  (XtActionProc) KeyDown              },
63   { "keyup",    (XtActionProc) KeyUp                },
64   { "select",   (XtActionProc) Select               },
65   { "release",  (XtActionProc) Release              },
66   { "enter",    (XtActionProc) _XwPrimitiveEnter    },
67   { "leave",    (XtActionProc) _XwPrimitiveLeave    },
68  };
69 
70 
71 /*  Resource list for WorkSpace  */
72 
73 static XtResource resources[] =
74 {
75    {
76       XtNexpose, XtCCallback, XtRCallback, sizeof (caddr_t),
77       XtOffset (XwWorkSpaceWidget, workSpace.expose),
78       XtRPointer, (caddr_t) NULL
79    },
80 
81    {
82       XtNresize, XtCCallback, XtRCallback, sizeof (caddr_t),
83       XtOffset (XwWorkSpaceWidget, workSpace.resize),
84       XtRPointer, (caddr_t) NULL
85    },
86 
87    {
88       XtNkeyDown, XtCCallback, XtRCallback, sizeof (caddr_t),
89       XtOffset (XwWorkSpaceWidget, workSpace.key_down),
90       XtRPointer, (caddr_t) NULL
91    },
92 
93    {
94       XtNkeyUp, XtCCallback, XtRCallback, sizeof (caddr_t),
95       XtOffset (XwWorkSpaceWidget, workSpace.key_up),
96       XtRPointer, (caddr_t) NULL
97    }
98 };
99 
100 
101 /*  Static routine definitions  */
102 
103 static void      Initialize();
104 static void    Redisplay();
105 static void    Resize();
106 static void    Destroy();
107 static Boolean SetValues();
108 
109 
110 /*  The WorkSpace class record definition  */
111 
112 XwWorkSpaceClassRec XwworkSpaceClassRec =
113 {
114    {
115       (WidgetClass) &XwprimitiveClassRec, /* superclass	         */
116       "XwWorkSpace",                    /* class_name	         */
117       sizeof(XwWorkSpaceRec),           /* widget_size           */
118       NULL,                             /* class_initialize      */
119       NULL,                             /* class_part_initialize */
120       FALSE,                            /* class_inited          */
121       (XtInitProc) Initialize,          /* initialize	         */
122       NULL,                             /* initialize_hook       */
123       _XwRealize,                       /* realize	         */
124       actionsList,                      /* actions               */
125       XtNumber(actionsList),            /* num_actions    	 */
126       resources,                        /* resources	         */
127       XtNumber(resources),              /* num_resources         */
128       NULLQUARK,                        /* xrm_class	         */
129       TRUE,                             /* compress_motion       */
130       TRUE,                             /* compress_exposure     */
131       TRUE,                             /* compress_enterleave   */
132       FALSE,                            /* visible_interest      */
133       (XtWidgetProc) Destroy,           /* destroy               */
134       (XtWidgetProc) Resize,            /* resize                */
135       (XtExposeProc) Redisplay,         /* expose                */
136       (XtSetValuesFunc) SetValues,      /* set_values	         */
137       NULL,                             /* set_values_hook       */
138       XtInheritSetValuesAlmost,         /* set_values_almost     */
139       NULL,                             /* get_values_hook       */
140       NULL,                             /* accept_focus	         */
141       XtVersion,                        /* version               */
142       NULL,                             /* callback private      */
143       defaultTranslations,              /* tm_table              */
144       NULL,                             /* query_geometry        */
145     /* display_accelerator	*/	XtInheritDisplayAccelerator,
146     /* extension		*/	NULL
147    },
148 
149    {
150       NULL,         /* Primitive border_highlight   */
151       NULL,         /* Primitive border_unhighlight */
152       NULL,         /* Primitive select_proc        */
153       NULL,         /* Primitive release_proc       */
154       NULL,         /* Primitive toggle_proc        */
155    }
156 };
157 
158 WidgetClass XwworkSpaceWidgetClass = (WidgetClass) &XwworkSpaceClassRec;
159 
160 
161 
162 
163 /************************************************************************
164  *
165  *  Initialize
166  *     The main widget instance initialization routine.
167  *
168  ************************************************************************/
169 
Initialize(request,new)170 static void Initialize (request, new)
171 XwWorkSpaceWidget request, new;
172 
173 {
174    if (request -> core.width == 0)
175       new -> core.width += 20;
176    if (request -> core.height == 0)
177       new -> core.height += 20;
178 }
179 
180 
181 
182 
183 /************************************************************************
184  *
185  *  Redisplay
186  *	Draw the traversal/enter border, and
187  *	invoke the application exposure callbacks.
188  *
189  ************************************************************************/
190 
Redisplay(hw,event,region)191 static void Redisplay (hw, event, region)
192 XwWorkSpaceWidget hw;
193 XEvent * event;
194 Region region;
195 
196 {
197    if (hw -> primitive.highlighted)
198       _XwHighlightBorder (hw);
199    else if (hw -> primitive.display_highlighted)
200       _XwUnhighlightBorder (hw);
201 
202    XtCallCallbacks ((Widget)hw, XtNexpose, region);
203 }
204 
205 
206 
207 
208 /************************************************************************
209  *
210  *  Resize
211  *     Invoke the application resize callbacks.
212  *
213  ************************************************************************/
214 
Resize(hw)215 static void Resize (hw)
216 XwWorkSpaceWidget hw;
217 
218 {
219    XtCallCallbacks ((Widget)hw, XtNresize, NULL);
220 }
221 
222 
223 
224 
225 /************************************************************************
226  *
227  *  Destroy
228  *	Remove the callback lists.
229  *
230  ************************************************************************/
231 
Destroy(hw)232 static void Destroy (hw)
233 XwWorkSpaceWidget hw;
234 
235 {
236    XtRemoveAllCallbacks ((Widget)hw, XtNexpose);
237    XtRemoveAllCallbacks ((Widget)hw, XtNresize);
238    XtRemoveAllCallbacks ((Widget)hw, XtNkeyDown);
239 }
240 
241 
242 
243 
244 /************************************************************************
245  *
246  *  SetValues
247  *
248  ************************************************************************/
249 
SetValues(current,request,new)250 static Boolean SetValues (current, request, new)
251 XwWorkSpaceWidget current, request, new;
252 
253 {
254    return (False);
255 }
256 
257 
258 
259 
260 /************************************************************************
261  *
262  *  KeyDown
263  *     This function processes key presses occuring on the workSpace.
264  *
265  ************************************************************************/
266 
KeyDown(hw,event)267 static void KeyDown (hw, event)
268 XwWorkSpaceWidget hw;
269 XButtonPressedEvent * event;
270 
271 {
272    XtCallCallbacks ((Widget)hw, XtNkeyDown, event);
273 }
274 
275 
276 /************************************************************************
277  *
278  *  KeyUp
279  *     This function processes key releases occuring on the workSpace.
280  *
281  ************************************************************************/
282 
KeyUp(hw,event)283 static void KeyUp (hw, event)
284 XwWorkSpaceWidget hw;
285 XButtonPressedEvent * event;
286 
287 {
288    XtCallCallbacks ((Widget)hw, XtNkeyUp, event);
289 }
290 
291 
292 
293 
294 /************************************************************************
295  *
296  *  Select
297  *     This function processes selections occuring on the workSpace.
298  *
299  ************************************************************************/
300 
Select(hw,event)301 static void Select (hw, event)
302 XwWorkSpaceWidget hw;
303 XButtonPressedEvent * event;
304 
305 {
306    XtCallCallbacks ((Widget)hw, XtNselect, event);
307 }
308 
309 
310 
311 
312 /************************************************************************
313  *
314  *  Release
315  *     This function processes releases occuring on the workSpace.
316  *
317  ************************************************************************/
318 
Release(hw,event)319 static void Release (hw, event)
320 XwWorkSpaceWidget   hw;
321 XEvent * event;
322 
323 {
324    XtCallCallbacks ((Widget)hw, XtNrelease, event);
325 }
326