Remove unused include X11/IntrinsicP.h.
[wine] / dlls / x11drv / clipping.c
1 /*
2  * X11DRV clipping functions
3  *
4  * Copyright 1998 Huw Davies
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
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  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "config.h"
22
23 #include <stdio.h>
24
25 #include "x11drv.h"
26 #include "wine/debug.h"
27
28 WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
29
30 /***********************************************************************
31  *           X11DRV_GetRegionData
32  *
33  * Calls GetRegionData on the given region and converts the rectangle
34  * array to XRectangle format. The returned buffer must be freed by
35  * caller using HeapFree(GetProcessHeap(),...).
36  * If hdc_lptodp is not 0, the rectangles are converted through LPtoDP.
37  */
38 RGNDATA *X11DRV_GetRegionData( HRGN hrgn, HDC hdc_lptodp )
39 {
40     RGNDATA *data;
41     DWORD size;
42     unsigned int i;
43     RECT *rect, tmp;
44     XRectangle *xrect;
45
46     if (!(size = GetRegionData( hrgn, 0, NULL ))) return NULL;
47     if (sizeof(XRectangle) > sizeof(RECT))
48     {
49         /* add extra size for XRectangle array */
50         int count = (size - sizeof(RGNDATAHEADER)) / sizeof(RECT);
51         size += count * (sizeof(XRectangle) - sizeof(RECT));
52     }
53     if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return NULL;
54     if (!GetRegionData( hrgn, size, data ))
55     {
56         HeapFree( GetProcessHeap(), 0, data );
57         return NULL;
58     }
59
60     rect = (RECT *)data->Buffer;
61     xrect = (XRectangle *)data->Buffer;
62     if (hdc_lptodp)  /* map to device coordinates */
63     {
64         LPtoDP( hdc_lptodp, (POINT *)rect, data->rdh.nCount * 2 );
65         for (i = 0; i < data->rdh.nCount; i++)
66         {
67             if (rect[i].right < rect[i].left)
68             {
69                 INT tmp = rect[i].right;
70                 rect[i].right = rect[i].left;
71                 rect[i].left = tmp;
72             }
73             if (rect[i].bottom < rect[i].top)
74             {
75                 INT tmp = rect[i].bottom;
76                 rect[i].bottom = rect[i].top;
77                 rect[i].top = tmp;
78             }
79         }
80     }
81
82     if (sizeof(XRectangle) > sizeof(RECT))
83     {
84         int j;
85         /* need to start from the end */
86         for (j = data->rdh.nCount-1; j >= 0; j--)
87         {
88             tmp = rect[j];
89             xrect[j].x      = tmp.left;
90             xrect[j].y      = tmp.top;
91             xrect[j].width  = tmp.right - tmp.left;
92             xrect[j].height = tmp.bottom - tmp.top;
93         }
94     }
95     else
96     {
97         for (i = 0; i < data->rdh.nCount; i++)
98         {
99             tmp = rect[i];
100             xrect[i].x      = tmp.left;
101             xrect[i].y      = tmp.top;
102             xrect[i].width  = tmp.right - tmp.left;
103             xrect[i].height = tmp.bottom - tmp.top;
104         }
105     }
106     return data;
107 }
108
109
110 /***********************************************************************
111  *           X11DRV_SetDeviceClipping
112  */
113 void X11DRV_SetDeviceClipping( X11DRV_PDEVICE *physDev, HRGN vis_rgn, HRGN clip_rgn )
114 {
115     RGNDATA *data;
116
117     CombineRgn( physDev->region, vis_rgn, clip_rgn, clip_rgn ? RGN_AND : RGN_COPY );
118     if (!(data = X11DRV_GetRegionData( physDev->region, 0 ))) return;
119
120     wine_tsx11_lock();
121     XSetClipRectangles( gdi_display, physDev->gc, physDev->org.x, physDev->org.y,
122                         (XRectangle *)data->Buffer, data->rdh.nCount, YXBanded );
123     wine_tsx11_unlock();
124     HeapFree( GetProcessHeap(), 0, data );
125 }