1/*
2 * Copyright 1987, 1998  The Open Group
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation.
9 *
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
16 * OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
17 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 *
20 * Except as contained in this notice, the name of The Open Group shall not be
21 * used in advertising or otherwise to promote the sale, use or other dealings
22 * in this Software without prior written authorization from The Open Group.
23 */
24
25/*
26 * Copyright 2002 Red Hat Inc., Durham, North Carolina.
27 *
28 * All Rights Reserved.
29 *
30 * Permission is hereby granted, free of charge, to any person obtaining
31 * a copy of this software and associated documentation files (the
32 * "Software"), to deal in the Software without restriction, including
33 * without limitation on the rights to use, copy, modify, merge,
34 * publish, distribute, sublicense, and/or sell copies of the Software,
35 * and to permit persons to whom the Software is furnished to do so,
36 * subject to the following conditions:
37 *
38 * The above copyright notice and this permission notice (including the
39 * next paragraph) shall be included in all copies or substantial
40 * portions of the Software.
41 *
42 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
43 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
45 * NON-INFRINGEMENT.  IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
46 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
47 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
48 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
49 * SOFTWARE.
50 */
51
52/*
53 * Authors:
54 *   Rickard E. (Rik) Faith <faith@redhat.com>
55 *
56 * This file was originally taken from xc/lib/Xaw/Template.c
57 */
58
59#include <X11/IntrinsicP.h>
60#include <X11/StringDefs.h>
61#include "CanvasP.h"
62
63static void CanvasInitialize(Widget request, Widget w,
64                             ArgList args, Cardinal *num_args)
65{
66}
67
68static void CanvasExpose(Widget w, XEvent *event, Region region)
69{
70    CanvasExposeDataRec data;
71
72    data.w      = w;
73    data.event  = event;
74    data.region = region;
75
76    if (!XtIsRealized(w)) return;
77    XtCallCallbacks(w, XtNcanvasExposeCallback, (XtPointer)&data);
78}
79
80static void CanvasResize(Widget w)
81{
82    if (!XtIsRealized(w)) return;
83    XtCallCallbacks(w, XtNcanvasResizeCallback, (XtPointer)w);
84}
85
86static void CanvasAction(Widget w, XEvent *event,
87                         String *params, Cardinal *num_params)
88{
89    XtCallCallbacks(w, XtNcallback, (XtPointer)event);
90}
91
92#define offset(field) XtOffsetOf(CanvasRec, canvas.field)
93static XtResource resources[] = {
94    { XtNcallback, XtCCallback, XtRCallback,
95      sizeof(XtCallbackList), offset(input_callback), XtRCallback, NULL },
96    { XtNcanvasExposeCallback, XtCcanvasExposeCallback, XtRCallback,
97      sizeof(XtCallbackList), offset(expose_callback), XtRCallback, NULL },
98    { XtNcanvasResizeCallback, XtCcanvasResizeCallback, XtRCallback,
99      sizeof(XtCallbackList), offset(resize_callback), XtRCallback, NULL },
100};
101#undef offset
102
103static XtActionsRec actions[] =
104{
105    {"canvas",	CanvasAction},
106};
107
108static char translations[] =
109"<Key>:    canvas()\n\
110<Motion>:  canvas()\n\
111<BtnDown>: canvas()\n\
112<BtnUp>: canvas()\n\
113"
114;
115
116#define Superclass	(&widgetClassRec)
117CanvasClassRec canvasClassRec = {
118    /* core */
119    {
120        (WidgetClass)Superclass,        /* superclass */
121        "Canvas",			/* class_name */
122        sizeof(CanvasRec),		/* widget_size */
123        NULL,				/* class_initialize */
124        NULL,				/* class_part_initialize */
125        False,				/* class_inited */
126        CanvasInitialize,		/* initialize */
127        NULL,				/* initialize_hook */
128        XtInheritRealize,		/* realize */
129        actions,			/* actions */
130        XtNumber(actions),		/* num_actions */
131        resources,			/* resources */
132        XtNumber(resources),		/* num_resources */
133        NULLQUARK,			/* xrm_class */
134        True,				/* compress_motion */
135        True,				/* compress_exposure */
136        True,				/* compress_enterleave */
137        False,				/* visible_interest */
138        NULL,				/* destroy */
139        CanvasResize,			/* resize */
140        CanvasExpose,                   /* expose */
141        NULL,				/* set_values */
142        NULL,				/* set_values_hook */
143        XtInheritSetValuesAlmost,	/* set_values_almost */
144        NULL,				/* get_values_hook */
145        NULL,				/* accept_focus */
146        XtVersion,			/* version */
147        NULL,				/* callback_private */
148        translations,			/* tm_table */
149        XtInheritQueryGeometry,		/* query_geometry */
150        XtInheritDisplayAccelerator,	/* display_accelerator */
151        NULL,				/* extension */
152    },
153    /* canvas */
154    {
155        NULL,				/* extension */
156    }
157};
158
159WidgetClass canvasWidgetClass = (WidgetClass)&canvasClassRec;
160