svn update: 48958 (latest:48959)
[framework/uifw/ecore.git] / src / lib / ecore_x / xlib / ecore_x_fixes.c
1 /*
2  * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
3  */
4
5 #ifdef HAVE_CONFIG_H
6 # include <config.h>
7 #endif
8
9 #include <stdlib.h>
10
11 #include "ecore_x_private.h"
12 #include "Ecore_X.h"
13
14 static int _fixes_available;
15 #ifdef ECORE_XFIXES
16 static int _fixes_major, _fixes_minor;
17 #endif
18
19 void
20 _ecore_x_fixes_init(void)
21 {
22 #ifdef ECORE_XFIXES
23    _fixes_major = 3;
24    _fixes_minor = 0;
25
26    LOGFN(__FILE__, __LINE__, __FUNCTION__);
27    if (XFixesQueryVersion(_ecore_x_disp, &_fixes_major, &_fixes_minor))
28      _fixes_available = 1;
29    else
30      _fixes_available = 0;
31 #else
32    _fixes_available = 0;
33 #endif
34 }
35
36 #ifdef ECORE_XFIXES
37 /* I don't know what to call this function. */
38 static XRectangle *
39 _ecore_x_rectangle_ecore_to_x(Ecore_X_Rectangle *rects, int num)
40 {
41    XRectangle *xrect;
42    int i;
43
44    if (num == 0) return NULL;
45
46    xrect = malloc(sizeof(XRectangle) * num);
47    if (!xrect) return NULL;
48    for (i = 0; i < num; i++)
49      {
50         xrect[i].x = rects[i].x;
51         xrect[i].y = rects[i].y;
52         xrect[i].width = rects[i].width;
53         xrect[i].height = rects[i].height;
54      }
55    return xrect;
56 }
57
58 static Ecore_X_Rectangle *
59 _ecore_x_rectangle_x_to_ecore(XRectangle *xrect, int num)
60 {
61    Ecore_X_Rectangle *rects;
62    int i;
63
64    if (num == 0) return NULL;
65    rects = malloc(sizeof(Ecore_X_Rectangle) * num);
66    if (!rects) return NULL;
67    for (i = 0; i < num; i++)
68      {
69         rects[i].x = xrect[i].x;
70         rects[i].y = xrect[i].y;
71         rects[i].width = xrect[i].width;
72         rects[i].height = xrect[i].height;
73      }
74    return rects;
75 }
76 #endif
77
78 EAPI Ecore_X_Region
79 ecore_x_region_new(Ecore_X_Rectangle *rects, int num)
80 {
81 #ifdef ECORE_XFIXES
82    Ecore_X_Region region;
83    XRectangle *xrect;
84
85    LOGFN(__FILE__, __LINE__, __FUNCTION__);
86    xrect = _ecore_x_rectangle_ecore_to_x(rects, num);
87    region = XFixesCreateRegion(_ecore_x_disp, xrect, num);
88    free(xrect);
89    return region;
90 #else
91    return 0;
92 #endif
93 }
94
95 EAPI Ecore_X_Region
96 ecore_x_region_new_from_bitmap(Ecore_X_Pixmap bitmap)
97 {
98 #ifdef ECORE_XFIXES
99    Ecore_X_Region region;
100
101    LOGFN(__FILE__, __LINE__, __FUNCTION__);
102    region = XFixesCreateRegionFromBitmap(_ecore_x_disp, bitmap);
103    return region;
104 #else
105    return 0;
106 #endif
107 }
108
109 EAPI Ecore_X_Region
110 ecore_x_region_new_from_window(Ecore_X_Window win, Ecore_X_Region_Type type)
111 {
112 #ifdef ECORE_XFIXES
113    Ecore_X_Region region;
114
115    LOGFN(__FILE__, __LINE__, __FUNCTION__);
116    region = XFixesCreateRegionFromWindow(_ecore_x_disp, win, type);
117    return region;
118 #else
119    return 0;
120 #endif
121 }
122
123 EAPI Ecore_X_Region
124 ecore_x_region_new_from_gc(Ecore_X_GC gc)
125 {
126 #ifdef ECORE_XFIXES
127    Ecore_X_Region region;
128
129    LOGFN(__FILE__, __LINE__, __FUNCTION__);
130    region = XFixesCreateRegionFromGC(_ecore_x_disp, gc);
131    return region;
132 #else
133    return 0;
134 #endif
135 }
136
137 EAPI Ecore_X_Region
138 ecore_x_region_new_from_picture(Ecore_X_Picture picture)
139 {
140 #ifdef ECORE_XFIXES
141    Ecore_X_Region region;
142
143    LOGFN(__FILE__, __LINE__, __FUNCTION__);
144    region = XFixesCreateRegionFromPicture(_ecore_x_disp, picture);
145    return region;
146 #else
147    return 0;
148 #endif
149 }
150
151 EAPI void
152 ecore_x_region_free(Ecore_X_Region region)
153 {
154 #ifdef ECORE_XFIXES
155    LOGFN(__FILE__, __LINE__, __FUNCTION__);
156    XFixesDestroyRegion(_ecore_x_disp, region);
157 #endif
158 }
159
160 EAPI void
161 ecore_x_region_set(Ecore_X_Region region, Ecore_X_Rectangle *rects, int num)
162 {
163 #ifdef ECORE_XFIXES
164    XRectangle *xrect = _ecore_x_rectangle_ecore_to_x(rects, num);
165    LOGFN(__FILE__, __LINE__, __FUNCTION__);
166    XFixesSetRegion(_ecore_x_disp, region, xrect, num);
167 #endif
168 }
169
170 EAPI void
171 ecore_x_region_copy(Ecore_X_Region dest, Ecore_X_Region source)
172 {
173 #ifdef ECORE_XFIXES
174    LOGFN(__FILE__, __LINE__, __FUNCTION__);
175    XFixesCopyRegion(_ecore_x_disp, dest, source);
176 #endif
177 }
178
179 EAPI void
180 ecore_x_region_combine(Ecore_X_Region dest, Ecore_X_Region source1, Ecore_X_Region source2)
181 {
182 #ifdef ECORE_XFIXES
183    LOGFN(__FILE__, __LINE__, __FUNCTION__);
184    XFixesUnionRegion(_ecore_x_disp, dest, source1, source2);
185 #endif
186 }
187
188 EAPI void
189 ecore_x_region_intersect(Ecore_X_Region dest, Ecore_X_Region source1, Ecore_X_Region source2)
190 {
191 #ifdef ECORE_XFIXES
192    LOGFN(__FILE__, __LINE__, __FUNCTION__);
193    XFixesIntersectRegion(_ecore_x_disp, dest, source1, source2);
194 #endif
195 }
196
197 EAPI void
198 ecore_x_region_subtract(Ecore_X_Region dest, Ecore_X_Region source1, Ecore_X_Region source2)
199 {
200 #ifdef ECORE_XFIXES
201    LOGFN(__FILE__, __LINE__, __FUNCTION__);
202    XFixesSubtractRegion(_ecore_x_disp, dest, source1, source2);
203 #endif
204 }
205
206 EAPI void
207 ecore_x_region_invert(Ecore_X_Region dest, Ecore_X_Rectangle *bounds, Ecore_X_Region source)
208 {
209 #ifdef ECORE_XFIXES
210    XRectangle *xbound;
211    int num = 0;
212
213    LOGFN(__FILE__, __LINE__, __FUNCTION__);
214    while (bounds + num) num++;
215    xbound = _ecore_x_rectangle_ecore_to_x(bounds, num);
216
217    XFixesInvertRegion(_ecore_x_disp, dest, xbound, source);
218 #endif
219 }
220
221 EAPI void
222 ecore_x_region_translate(Ecore_X_Region region, int dx, int dy)
223 {
224 #ifdef ECORE_XFIXES
225    LOGFN(__FILE__, __LINE__, __FUNCTION__);
226    XFixesTranslateRegion(_ecore_x_disp, region, dx, dy);
227 #endif
228 }
229
230 EAPI void
231 ecore_x_region_extents(Ecore_X_Region dest, Ecore_X_Region source)
232 {
233 #ifdef ECORE_XFIXES
234    LOGFN(__FILE__, __LINE__, __FUNCTION__);
235    XFixesRegionExtents(_ecore_x_disp, dest, source);
236 #endif
237 }
238
239 EAPI Ecore_X_Rectangle *
240 ecore_x_region_fetch(Ecore_X_Region region, int *num, Ecore_X_Rectangle *bounds){
241 #ifdef ECORE_XFIXES
242    Ecore_X_Rectangle *rects;
243    XRectangle *xrect, xbound;
244    
245    LOGFN(__FILE__, __LINE__, __FUNCTION__);
246    xrect = XFixesFetchRegionAndBounds(_ecore_x_disp, region, num, &xbound);
247    rects = _ecore_x_rectangle_x_to_ecore(xrect, *num);
248    (*bounds).x = xbound.x;
249    (*bounds).y = xbound.y;
250    (*bounds).width = xbound.width;
251    (*bounds).height = xbound.height;
252    return rects;
253 #else
254    return NULL;
255 #endif
256 }
257
258 EAPI void
259 ecore_x_region_expand(Ecore_X_Region dest, Ecore_X_Region source, unsigned int left, unsigned int right, unsigned int top, unsigned int bottom)
260 {
261 #ifdef ECORE_XFIXES
262    LOGFN(__FILE__, __LINE__, __FUNCTION__);
263    XFixesExpandRegion(_ecore_x_disp, dest, source, left, right, top, bottom);
264 #endif
265 }
266
267 EAPI void
268 ecore_x_region_gc_clip_set(Ecore_X_Region region, Ecore_X_GC gc, int x_origin, int y_origin)
269 {
270 #ifdef ECORE_XFIXES
271    LOGFN(__FILE__, __LINE__, __FUNCTION__);
272    XFixesSetGCClipRegion(_ecore_x_disp, gc, x_origin, y_origin, region);
273 #endif
274 }
275
276 EAPI void
277 ecore_x_region_window_shape_set(Ecore_X_Region region, Ecore_X_Window win, Ecore_X_Shape_Type type, int x_offset, int y_offset)
278 {
279 #ifdef ECORE_XFIXES
280    LOGFN(__FILE__, __LINE__, __FUNCTION__);
281    XFixesSetWindowShapeRegion(_ecore_x_disp, win, type, x_offset, y_offset, region);
282 #endif
283 }
284
285 EAPI void
286 ecore_x_region_picture_clip_set(Ecore_X_Region region, Ecore_X_Picture picture, int x_origin, int y_origin)
287 {
288 #ifdef ECORE_XFIXES
289    LOGFN(__FILE__, __LINE__, __FUNCTION__);
290    XFixesSetPictureClipRegion(_ecore_x_disp, picture, x_origin, y_origin, region);
291 #endif
292 }
293