dtinfo subtree dtinfo
[oweals/cde.git] / cde / programs / dtinfo / dtinfo / src / Widgets / Pixmap.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
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
22  */
23 /* $XConsortium: Pixmap.c /main/3 1996/06/11 16:45:33 cde-hal $ */
24 #include <stdio.h>
25
26 #include <X11/IntrinsicP.h>
27 #include <X11/Intrinsic.h>
28 #include <X11/CoreP.h>
29 #include <X11/StringDefs.h>
30 #include "PixmapP.h"
31
32 #ifdef DEBUG
33 #define ON_DEBUG(x) x
34 #else
35 #define ON_DEBUG(x)
36 #endif
37
38 static Boolean SetValues();
39 static void Initialize();
40 static void Destroy();
41 static void Resize();
42 static void ReDisplay();
43 static XtGeometryResult QueryGeometry();
44
45 static char *defaultTranslations[] = {""};
46
47 /*
48 static XtActionsRec actions[] =
49 {
50 };
51 */
52
53 static XtResource resources[] = {
54   { XtNpixmap, XtCPixmap, XtRPixmap, sizeof(Pixmap),
55       XtOffset(PixmapWidget, pixmap.pixmap), XtRPixmap, 0},
56 };
57
58 PixmapClassRec  pixmapClassRec = {
59   { /* core fields */
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,
69     /* actions                  */      NULL,
70     /* num_actions              */      0,
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,
79     /* resize                   */      Resize,
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,
91     /* extension                */      NULL
92   },
93     {
94       /* Pixmap class fields */
95       0,                        /* ignore */
96     }
97 };
98
99 WidgetClass pixmapWidgetClass = (WidgetClass)&pixmapClassRec;
100
101 static void
102 Initialize(req, new, args, nargs )
103 PixmapWidget req, new ;
104 ArgList args ;
105 Cardinal *nargs ;
106 {
107   XtGCMask  value_mask ;
108   XGCValues values ;
109
110
111   ON_DEBUG(fprintf(stderr, "PixmapWidget:\tInitialize()\n"));
112
113   if ((new->core.width  == 0) ||
114       (new->core.height == 0)){
115
116     Dimension width, height ;
117     XtVaGetValues(XtParent(new),
118                   XtNwidth, &width,
119                   XtNheight, &height,
120                   (char*)0);
121
122     if (new->core.width == 0)
123       new->core.width = width ;
124
125     if (new->core.height == 0)
126       new->core.height = height ;
127   }
128
129   /* avoid bogus Pixmap value */
130   new->pixmap.pixmap = 0 ;
131
132   /* get gc */
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);
137 }
138
139 static void
140 Resize(w)
141 PixmapWidget w ;
142 {
143   ON_DEBUG(fprintf(stderr, "PixmapWidget: RESIZE (%d, %d)\n",
144                    w->core.width, w->core.height));
145 }
146
147 static void
148 Destroy(w)
149 PixmapWidget w;
150 {
151   if (w->pixmap.pixmap != 0)
152     {
153       ON_DEBUG(fprintf(stderr, "Hey, free the pixmap\n"));
154     }
155 }
156
157 static Boolean
158 SetValues(current, request, new, args, num_args)
159 PixmapWidget current, request, new ;
160 ArgList args ;
161 Cardinal *num_args ;
162 {
163   Window root ;
164   int x, y ;
165   unsigned int width, height, border_width, depth ;
166   Boolean needs_redisplay=FALSE ;
167
168   ON_DEBUG(fprintf(stderr, "PixmapWidget: SetValues\n"));
169
170   if (current->pixmap.pixmap != new->pixmap.pixmap)
171     {
172       XtWidgetGeometry request, reply ;
173       /* get pixmap size */
174       XGetGeometry(XtDisplay(new),
175                    new->pixmap.pixmap,
176                    &root, 
177                    &x, &y, 
178                    &width, &height,
179                    &border_width,
180                    &depth);
181       new->pixmap.width = width ;
182       new->pixmap.height = height ;
183
184       request.request_mode = CWWidth | CWHeight ;
185       request.width = width ;
186       request.height = height ;
187       XtMakeGeometryRequest((Widget)new, &request, &reply);
188
189     }
190   return needs_redisplay ;
191 }
192
193
194 static XtGeometryResult
195 QueryGeometry(w, proposed, answer)
196 PixmapWidget w ;
197 XtWidgetGeometry *proposed, *answer;
198 {
199   ON_DEBUG(fprintf(stderr, "PixmapWidget:\tQueryGeometry()\n"));
200 #ifdef DEBUG
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);
209
210 #endif
211
212   memcpy(proposed, answer, sizeof(XtWidgetGeometry));
213
214   return XtGeometryYes ;
215 }
216
217 #ifndef DEBUG
218 #define DEBUG
219 #endif
220
221 static void
222 ReDisplay(w, event)
223 PixmapWidget w ;
224 XExposeEvent *event ;
225 {
226   ON_DEBUG(fprintf(stderr, "PixmapWidget: EXPOSE\n"));
227
228   if (w->pixmap.pixmap != 0)
229     {
230       Display *display = XtDisplay(w);
231       XRectangle rect[1] ;
232       rect[0].x = event->x ;
233       rect[0].y = event->y ;
234       rect[0].width = event->width ;
235       rect[0].height = event->height ;
236
237       ON_DEBUG(fprintf(stderr, "XCopyArea(%d, %d, %d, %d)\n",
238                        event->x, event->y,
239                        event->width, event->height));
240
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  */
246                          rect,         /* rect[]  */
247                          1,            /* num rects  */
248                          Unsorted);    /* ordering  */
249
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 */
258
259       /* unset clip mask */
260       XSetClipMask(XtDisplay(w), w->pixmap.gc, None);
261     }
262 }
263
264 void
265 PixmapWidgetDimensions(Widget w, Dimension *width, Dimension *height)
266 {
267   if (IsPixmapWidget(w))
268     {
269       PixmapWidget pw = (PixmapWidget) w ;
270       *width  = pw->pixmap.width ;
271       *height = pw->pixmap.height ;
272     }
273   else
274     {
275       *width = 0 ;
276       *height = 0 ;
277     }
278 }