1 /* $XConsortium: MenuButton.c,v 1.21 95/06/26 20:35:12 kaleb Exp $ */
2
3 /*
4 Copyright (c) 1989, 1994 X Consortium
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
23 Except as contained in this notice, the name of the X Consortium shall not be
24 used in advertising or otherwise to promote the sale, use or other dealings
25 in this Software without prior written authorization from the X Consortium.
26 *
27 */
28
29
30 /***********************************************************************
31 *
32 * Pixcomm Widget
33 *
34 ***********************************************************************/
35
36 /*
37 * Pixcomm.c - Source code for PixCommand widget.
38 */
39
40 #ifdef HAVE_CONFIG_H
41 #include <fc_config.h>
42 #endif
43
44 #include <stdio.h>
45
46 #include <X11/IntrinsicP.h>
47 #include <X11/StringDefs.h>
48 #include <X11/Xmu/Misc.h>
49 #include <X11/Xaw/XawInit.h>
50 #include <X11/Xmu/Converters.h>
51 #include <X11/extensions/shape.h>
52
53 #include "pixcomm.h"
54 #include "pixcommp.h"
55 #include "gui_main.h"
56 #include "gui_stuff.h"
57
58 static void Notify(Widget w, XEvent *event,
59 String *params, Cardinal *num_params);
60 static void ClassInitialize(void);
61
62 static void Realize(Widget w, Mask *valueMask,
63 XSetWindowAttributes *attributes);
64 static void Resize(Widget w);
65 static void Destroy(Widget w);
66
67 static XtActionsRec actionsList[] = {
68 {"notify", Notify}
69 };
70
71 #define Superclass ((CommandWidgetClass)&commandClassRec)
72
73 /****************************************************************
74 *
75 * Full class record constant
76 *
77 ****************************************************************/
78
79 /* Private Data */
80
81 PixcommClassRec pixcommClassRec = {
82 {
83 (WidgetClass) Superclass, /* superclass */
84 "Pixcomm", /* class_name */
85 sizeof(PixcommRec), /* size */
86 ClassInitialize, /* class_initialize */
87 NULL, /* class_part_initialize */
88 FALSE, /* class_inited */
89 NULL, /* initialize */
90 NULL, /* initialize_hook */
91 Realize, /* realize */
92 actionsList, /* actions */
93 XtNumber(actionsList), /* num_actions */
94 NULL, /* resources */
95 0, /* resource_count */
96 NULLQUARK, /* xrm_class */
97 FALSE, /* compress_motion */
98 TRUE, /* compress_exposure */
99 TRUE, /* compress_enterleave */
100 FALSE, /* visible_interest */
101 Destroy, /* destroy */
102 Resize, /* resize */
103 XtInheritExpose, /* expose */
104 NULL, /* set_values */
105 NULL, /* set_values_hook */
106 XtInheritSetValuesAlmost, /* set_values_almost */
107 NULL, /* get_values_hook */
108 NULL, /* accept_focus */
109 XtVersion, /* version */
110 NULL, /* callback_private */
111 XtInheritTranslations, /* tm_table */
112 XtInheritQueryGeometry, /* query_geometry */
113 XtInheritDisplayAccelerator, /* display_accelerator */
114 NULL /* extension */
115 }, /* CoreClass fields initialization */
116 {
117 XtInheritChangeSensitive /* change_sensitive */
118 }, /* SimpleClass fields initialization */
119 #if defined(HAVE_LIBXAW3D)
120 {
121 XtInheritXaw3dShadowDraw, /* shadowdraw */
122 }, /* ThreeD Class fields initialization */
123 #endif
124 {
125 0, /* field not used */
126 }, /* LabelClass fields initialization */
127 {
128 0, /* field not used */
129 }, /* CommandClass fields initialization */
130 {
131 0, /* field not used */
132 } /* PixcommClass fields initialization */
133 };
134
135 /* for public consumption */
136 WidgetClass pixcommWidgetClass = (WidgetClass) &pixcommClassRec;
137
138 /* ARGSUSED */
Notify(Widget w,XEvent * event,String * params,Cardinal * num_params)139 static void Notify(Widget w, XEvent *event, String *params /* unused */,
140 Cardinal *num_params /* unused */)
141 {
142 PixcommWidget pw = (PixcommWidget)w;
143
144 /* check to be sure state is still Set so that user can cancel
145 the action (e.g. by moving outside the window, in the default
146 bindings.
147 */
148 if (pw->command.set)
149 XtCallCallbackList(w, pw->command.callbacks, (XtPointer) event);
150 }
151
Realize(Widget w,Mask * valueMask,XSetWindowAttributes * attributes)152 static void Realize(Widget w, Mask *valueMask,
153 XSetWindowAttributes *attributes)
154 {
155 PixcommWidget pw = (PixcommWidget) w;
156
157 (*pixcommWidgetClass->core_class.superclass->core_class.realize)
158 (w, valueMask, attributes);
159
160 pw->pixcomm.back_store=XCreatePixmap(display, root_window,
161 pw->core.width, pw->core.height,
162 display_depth);
163 XSetForeground(display, fill_bg_gc, pw->core.background_pixel);
164 XFillRectangle(display, pw->pixcomm.back_store, fill_bg_gc,
165 0, 0, pw->core.width, pw->core.height);
166 XtVaSetValues(w, XtNbitmap, pw->pixcomm.back_store, NULL);
167 }
168
169
170
Destroy(Widget w)171 static void Destroy(Widget w)
172 {
173 PixcommWidget pw=(PixcommWidget)w;
174
175 if(!XtIsRealized(w))
176 return;
177 if(pw->pixcomm.back_store)
178 XFreePixmap(display, pw->pixcomm.back_store);
179 }
180
181
Resize(Widget w)182 static void Resize(Widget w)
183 {
184 PixcommWidget pw=(PixcommWidget)w;
185
186 if(!XtIsRealized(w))
187 return;
188 if(pw->pixcomm.back_store)
189 XFreePixmap(display, pw->pixcomm.back_store);
190
191 pw->pixcomm.back_store=XCreatePixmap(display, root_window,
192 pw->core.width, pw->core.height,
193 display_depth);
194
195 XSetForeground(display, fill_bg_gc, pw->core.background_pixel);
196 XFillRectangle(display, pw->pixcomm.back_store, fill_bg_gc,
197 0, 0, pw->core.width, pw->core.height);
198 XtVaSetValues(w, XtNbitmap, pw->pixcomm.back_store, NULL);
199 (*pixcommWidgetClass->core_class.superclass->core_class.resize)(w);
200 }
201
202
203
204 /****************************************************************
205 *
206 * Private Procedures
207 *
208 ****************************************************************/
ClassInitialize(void)209 static void ClassInitialize(void)
210 {
211 XawInitializeWidgetSet();
212 }
213
XawPixcommPixmap(Widget w)214 Pixmap XawPixcommPixmap(Widget w)
215 {
216 PixcommWidget pw = (PixcommWidget)w;
217 return XtIsRealized(w) ? pw->pixcomm.back_store : 0;
218 }
219
XawPixcommCopyTo(Widget w,Pixmap src)220 void XawPixcommCopyTo(Widget w, Pixmap src)
221 {
222 PixcommWidget pw = (PixcommWidget)w;
223
224 XCopyArea(display, src, pw->pixcomm.back_store,
225 civ_gc,
226 0, 0,
227 pw->core.width, pw->core.height,
228 0, 0);
229 xaw_expose_now(w);
230 }
231
XawPixcommClear(Widget w)232 void XawPixcommClear(Widget w)
233 {
234 PixcommWidget pw = (PixcommWidget)w;
235
236 XSetForeground(display, fill_bg_gc, pw->core.background_pixel);
237 XFillRectangle(display, pw->pixcomm.back_store, fill_bg_gc,
238 0, 0, pw->core.width, pw->core.height);
239 xaw_expose_now(w);
240 }
241