2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: Pixmap.c /main/3 1996/06/11 16:45:33 cde-hal $ */
26 #include <X11/IntrinsicP.h>
27 #include <X11/Intrinsic.h>
28 #include <X11/CoreP.h>
29 #include <X11/StringDefs.h>
38 static Boolean SetValues();
39 static void Initialize();
40 static void Destroy();
42 static void ReDisplay();
43 static XtGeometryResult QueryGeometry();
45 static char *defaultTranslations[] = {""};
48 static XtActionsRec actions[] =
53 static XtResource resources[] = {
54 { XtNpixmap, XtCPixmap, XtRPixmap, sizeof(Pixmap),
55 XtOffset(PixmapWidget, pixmap.pixmap), XtRPixmap, 0},
58 PixmapClassRec pixmapClassRec = {
60 /* superclass */ (WidgetClass) &coreClassRec,
61 /* class_name */ "Pixmap",
62 /* widget_size */ sizeof(PixmapRec),
63 /* class_initialize */ NULL,
64 /* class_part_initialize */ NULL,
65 /* class_inited */ FALSE,
66 /* initialize */ Initialize,
67 /* initialize_hook */ NULL,
68 /* realize */ XtInheritRealize,
71 /* resources */ resources,
72 /* num_resources */ XtNumber(resources),
73 /* xrm_class */ NULLQUARK,
74 /* compress_motion */ TRUE,
75 /* compress_exposure */ FALSE,
76 /* compress_enterleave */ TRUE,
77 /* visible_interest */ FALSE,
78 /* destroy */ Destroy,
80 /* expose */ ReDisplay,
81 /* set_values */ SetValues,
82 /* set_values_hook */ NULL,
83 /* set_values_almost */ XtInheritSetValuesAlmost,
84 /* get_values_hook */ NULL,
85 /* accept_focus */ NULL,
86 /* version */ XtVersion,
87 /* callback_private */ NULL,
88 /* tm_table */ 0, /* defaultTranslations*/
89 /* query_geometry */ QueryGeometry,
90 /* display_accelerator */ XtInheritDisplayAccelerator,
94 /* Pixmap class fields */
99 WidgetClass pixmapWidgetClass = (WidgetClass)&pixmapClassRec;
102 Initialize(req, new, args, nargs )
103 PixmapWidget req, new ;
107 XtGCMask value_mask ;
111 ON_DEBUG(fprintf(stderr, "PixmapWidget:\tInitialize()\n"));
113 if ((new->core.width == 0) ||
114 (new->core.height == 0)){
116 Dimension width, height ;
117 XtVaGetValues(XtParent(new),
122 if (new->core.width == 0)
123 new->core.width = width ;
125 if (new->core.height == 0)
126 new->core.height = height ;
129 /* avoid bogus Pixmap value */
130 new->pixmap.pixmap = 0 ;
133 value_mask = GCFunction | GCBackground ;
134 values.function = GXcopy ;
135 values.background = new->core.background_pixel ;
136 new->pixmap.gc = XtGetGC((Widget)new, value_mask, &values);
143 ON_DEBUG(fprintf(stderr, "PixmapWidget: RESIZE (%d, %d)\n",
144 w->core.width, w->core.height));
151 if (w->pixmap.pixmap != 0)
153 ON_DEBUG(fprintf(stderr, "Hey, free the pixmap\n"));
158 SetValues(current, request, new, args, num_args)
159 PixmapWidget current, request, new ;
165 unsigned int width, height, border_width, depth ;
166 Boolean needs_redisplay=FALSE ;
168 ON_DEBUG(fprintf(stderr, "PixmapWidget: SetValues\n"));
170 if (current->pixmap.pixmap != new->pixmap.pixmap)
172 XtWidgetGeometry request, reply ;
173 /* get pixmap size */
174 XGetGeometry(XtDisplay(new),
181 new->pixmap.width = width ;
182 new->pixmap.height = height ;
184 request.request_mode = CWWidth | CWHeight ;
185 request.width = width ;
186 request.height = height ;
187 XtMakeGeometryRequest((Widget)new, &request, &reply);
190 return needs_redisplay ;
194 static XtGeometryResult
195 QueryGeometry(w, proposed, answer)
197 XtWidgetGeometry *proposed, *answer;
199 ON_DEBUG(fprintf(stderr, "PixmapWidget:\tQueryGeometry()\n"));
201 if (proposed->request_mode & CWX)
202 fprintf(stderr, "X: %d ==> %d\n", w->core.x, proposed->x);
203 if (proposed->request_mode & CWY)
204 fprintf(stderr, "Y: %d ==> %d\n", w->core.y, proposed->y);
205 if (proposed->request_mode & CWWidth)
206 fprintf(stderr, "Width: %d ==> %d\n", w->core.width, proposed->width);
207 if (proposed->request_mode & CWHeight)
208 fprintf(stderr, "Height: %d ==> %d\n", w->core.height, proposed->height);
212 memcpy(proposed, answer, sizeof(XtWidgetGeometry));
214 return XtGeometryYes ;
224 XExposeEvent *event ;
226 ON_DEBUG(fprintf(stderr, "PixmapWidget: EXPOSE\n"));
228 if (w->pixmap.pixmap != 0)
230 Display *display = XtDisplay(w);
232 rect[0].x = event->x ;
233 rect[0].y = event->y ;
234 rect[0].width = event->width ;
235 rect[0].height = event->height ;
237 ON_DEBUG(fprintf(stderr, "XCopyArea(%d, %d, %d, %d)\n",
239 event->width, event->height));
241 /* wastefull...could only copy required data - jbm */
242 XSetClipRectangles(display,
243 w->pixmap.gc, /* gc */
244 0, /* clip x origin */
245 0, /* clip y origin */
248 Unsorted); /* ordering */
250 XCopyArea(XtDisplay(w), /* display */
251 w->pixmap.pixmap, /* src */
252 XtWindow(w), /* dest */
253 w->pixmap.gc, /* gc */
254 0, 0, /* src_x, src_y */
255 w->pixmap.width, /* pixmap width */
256 w->pixmap.height, /* pixmap height */
257 0, 0); /* dest_x, dest_y */
259 /* unset clip mask */
260 XSetClipMask(XtDisplay(w), w->pixmap.gc, None);
265 PixmapWidgetDimensions(Widget w, Dimension *width, Dimension *height)
267 if (IsPixmapWidget(w))
269 PixmapWidget pw = (PixmapWidget) w ;
270 *width = pw->pixmap.width ;
271 *height = pw->pixmap.height ;