- fix dirty flag on shelllink loading and saving
[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     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         /* need to start from the end */
85         for (i = data->rdh.nCount-1; i >=0; i--)
86         {
87             tmp = rect[i];
88             xrect[i].x      = tmp.left;
89             xrect[i].y      = tmp.top;
90             xrect[i].width  = tmp.right - tmp.left;
91             xrect[i].height = tmp.bottom - tmp.top;
92         }
93     }
94     else
95     {
96         for (i = 0; i < data->rdh.nCount; i++)
97         {
98             tmp = rect[i];
99             xrect[i].x      = tmp.left;
100             xrect[i].y      = tmp.top;
101             xrect[i].width  = tmp.right - tmp.left;
102             xrect[i].height = tmp.bottom - tmp.top;
103         }
104     }
105     return data;
106 }
107
108
109 /***********************************************************************
110  *           X11DRV_SetDeviceClipping
111  */
112 void X11DRV_SetDeviceClipping( X11DRV_PDEVICE *physDev, HRGN vis_rgn, HRGN clip_rgn )
113 {
114     RGNDATA *data;
115
116     CombineRgn( physDev->region, vis_rgn, clip_rgn, clip_rgn ? RGN_AND : RGN_COPY );
117     if (!(data = X11DRV_GetRegionData( physDev->region, 0 ))) return;
118
119     wine_tsx11_lock();
120     XSetClipRectangles( gdi_display, physDev->gc, physDev->org.x, physDev->org.y,
121                         (XRectangle *)data->Buffer, data->rdh.nCount, YXBanded );
122     wine_tsx11_unlock();
123     HeapFree( GetProcessHeap(), 0, data );
124 }