Removed silencing of gtk warning logs from gtk3.22-client.
[freeciv.git] / client / gui-xaw / canvas.c
blob9817ce9392b8d5df9691cdb37b02a9159d424130
1 /*
3 Canvas.c - a widget that allows programmer-specified refresh procedures.
4 Copyright (C) 1990,93,94 Robert H. Forsman Jr.
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.
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.
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.
22 #ifdef HAVE_CONFIG_H
23 #include <fc_config.h>
24 #endif
26 #include <stdio.h>
28 #include <X11/IntrinsicP.h>
29 #include <X11/StringDefs.h>
30 #include <X11/Xaw/XawInit.h>
32 #include "gui_main.h"
33 #include "gui_stuff.h"
34 #include "canvasp.h"
36 #define offset(field) XtOffset(CanvasWidget, canvas.field)
38 static XtResource resources[] = {
39 {XtNexposeProc, XtCExposeProc, XtRFunction, sizeof(XfwfCanvasExposeProc),
40 offset(redraw), XtRFunction, NULL},
41 {XtNexposeProcData, XtCExposeProcData, XtRPointer, sizeof(XtPointer),
42 offset(redraw_data), XtRFunction, NULL},
43 {XtNresizeProc, XtCResizeProc, XtRFunction, sizeof(XfwfCanvasResizeProc),
44 offset(resize), XtRFunction, NULL},
45 {XtNresizeProcData, XtCResizeProcData, XtRPointer, sizeof(XtPointer),
46 offset(resize_data), XtRFunction, NULL},
47 {XtNvisual, XtCVisual, XtRVisual, sizeof(Visual*),
48 offset(visual), XtRImmediate, CopyFromParent},
49 {XtNBackPixmap, XtCBackPixmap, XtRBitmap, sizeof(Pixmap),
50 offset(pixmap), XtRBitmap, NULL}
54 static void CanvasRealize(Widget widget, XtValueMask *value_mask,
55 XSetWindowAttributes *attributes);
56 static void Redisplay(Widget w, XEvent *event, Region region);
57 static void ClassInitialize(void);
58 static void Resize(Widget w);
59 static void Destroy(Widget w);
60 static Boolean SetValues(Widget current,
61 Widget request,
62 Widget New,
63 ArgList args, Cardinal *nargs);
65 CanvasClassRec canvasClassRec = {
67 /* core_class fields */
68 /* superclass */ (WidgetClass) &simpleClassRec,
69 /* class_name */ "Canvas",
70 /* widget_size */ sizeof(CanvasRec),
71 /* class_initialize */ ClassInitialize,
72 /* class_part_initialize */ NULL,
73 /* class_inited */ False,
74 /* initialize */ NULL,
75 /* initialize_hook */ NULL,
76 /* realize */ CanvasRealize,
77 /* actions */ NULL,
78 /* num_actions */ 0,
79 /* resources */ resources,
80 /* num_resources */ XtNumber(resources),
81 /* xrm_class */ NULLQUARK,
82 /* compress_motion */ True,
83 /* compress_exposure */ XtExposeCompressMultiple,
84 /* compress_enterleave */ True,
85 /* visible_interest */ True,
86 /* destroy */ Destroy,
87 /* resize */ Resize,
88 /* expose */ Redisplay,
89 /* set_values */ SetValues,
90 /* set_values_hook */ NULL,
91 /* set_values_almost */ XtInheritSetValuesAlmost,
92 /* get_values_hook */ NULL,
93 /* accept_focus */ NULL,
94 /* version */ XtVersion,
95 /* callback_private */ NULL,
96 /* tm_table */ NULL,
97 /* query_geometry */ NULL,
98 /* display_accelerator */ XtInheritDisplayAccelerator,
99 /* extension */ NULL
102 XtInheritChangeSensitive /* change_sensitive */
103 }, /* SimpleClass fields initialization */
105 0 /* some stupid compilers barf on empty structures */
109 WidgetClass xfwfcanvasWidgetClass = (WidgetClass) & canvasClassRec;
112 static void CanvasRealize(Widget widget, XtValueMask *value_mask,
113 XSetWindowAttributes *attributes)
115 CanvasWidget cw = (CanvasWidget)widget;
116 cw->canvas.is_visible=0;
118 XtCreateWindow(widget, (unsigned int) InputOutput,
119 (Visual *) cw->canvas.visual, *value_mask, attributes);
121 cw->canvas.pixmap=XCreatePixmap(display, root_window,
122 cw->core.width, cw->core.height,
123 display_depth);
125 } /* CoreRealize */
127 static void Redisplay(Widget w, XEvent *event, Region region)
129 XExposeEvent *exposeEvent = (XExposeEvent *)event;
130 CanvasWidget cw = (CanvasWidget)w;
132 if (!XtIsRealized(w))
133 return;
135 if(cw->canvas.redraw) {
136 (cw->canvas.redraw)((Widget)cw,exposeEvent,region,cw->canvas.redraw_data);
138 else {
139 if(cw->canvas.is_visible)
140 XCopyArea(display, cw->canvas.pixmap, XtWindow(w),
141 civ_gc,
142 0, 0,
143 cw->core.width, cw->core.height,
144 0, 0);
145 else {
146 XSetForeground(display, fill_bg_gc, cw->core.background_pixel);
147 XFillRectangle(display, XtWindow(w), fill_bg_gc,
148 0, 0, cw->core.width, cw->core.height);
153 static Boolean SetValues(Widget current,
154 Widget request,
155 Widget New,
156 ArgList args, Cardinal *nargs)
158 int i;
159 for(i=0; i<*nargs; i++) {
160 if (strcmp(XtNexposeProc,args[i].name)==0 ||
161 strcmp(XtNexposeProcData,args[i].name)==0)
162 return True;
164 return False;
168 static void Resize(Widget w)
170 CanvasWidget cw = (CanvasWidget)w;
171 if (cw->canvas.resize)
172 (cw->canvas.resize)((Widget)cw, cw->canvas.resize_data);
174 XFreePixmap(display, cw->canvas.pixmap);
176 cw->canvas.pixmap=XCreatePixmap(display, root_window,
177 cw->core.width, cw->core.height,
178 display_depth);
181 static void Destroy(Widget w)
183 CanvasWidget cw = (CanvasWidget)w;
184 XFreePixmap(display, cw->canvas.pixmap);
187 static void ClassInitialize(void)
189 XawInitializeWidgetSet();
193 Pixmap canvas_get_backpixmap(Widget w)
195 CanvasWidget cw = (CanvasWidget)w;
196 return XtIsRealized(w) ? cw->canvas.pixmap : 0;
199 void canvas_copy_to_backpixmap(Widget w, Pixmap src)
201 CanvasWidget cw = (CanvasWidget)w;
203 XCopyArea(display, src, cw->canvas.pixmap,
204 civ_gc,
205 0, 0,
206 cw->core.width, cw->core.height,
207 0, 0);
208 cw->canvas.is_visible=1;
209 xaw_expose_now(w);
213 void canvas_show(Widget w)
215 CanvasWidget cw = (CanvasWidget)w;
216 cw->canvas.is_visible=1;
217 xaw_expose_now(w);
220 void canvas_hide(Widget w)
222 CanvasWidget cw = (CanvasWidget)w;
223 cw->canvas.is_visible=0;
224 xaw_expose_now(w);