2 * Window clipping functions
4 * Copyright 1993 Alexandre Julliard
7 static char Copyright
[] = "Copyright Alexandre Julliard, 1993";
16 /***********************************************************************
17 * InvalidateRgn (USER.126)
19 void InvalidateRgn( HWND hwnd
, HRGN hrgn
, BOOL erase
)
22 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
27 newRgn
= CreateRectRgn(0, 0,
28 wndPtr
->rectClient
.right
-wndPtr
->rectClient
.left
,
29 wndPtr
->rectClient
.bottom
-wndPtr
->rectClient
.top
);
33 if (!(newRgn
= CreateRectRgn( 0, 0, 0, 0 ))) return;
34 if (!wndPtr
->hrgnUpdate
) CombineRgn( newRgn
, hrgn
, 0, RGN_COPY
);
35 else CombineRgn( newRgn
, wndPtr
->hrgnUpdate
, hrgn
, RGN_OR
);
37 if (wndPtr
->hrgnUpdate
) DeleteObject( wndPtr
->hrgnUpdate
);
38 else MSG_IncPaintCount( wndPtr
->hmemTaskQ
);
39 wndPtr
->hrgnUpdate
= newRgn
;
40 if (erase
) wndPtr
->flags
|= WIN_ERASE_UPDATERGN
;
42 /* Invalidate the children overlapping the region */
44 if (wndPtr
->dwStyle
& WS_CLIPCHILDREN
) return;
45 for (hwnd
= wndPtr
->hwndChild
; (hwnd
); hwnd
= wndPtr
->hwndNext
)
47 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) break;
48 if (hrgn
&& !RectInRegion( hrgn
, &wndPtr
->rectWindow
)) continue;
49 InvalidateRgn( hwnd
, hrgn
, erase
);
54 /***********************************************************************
55 * InvalidateRect (USER.125)
57 void InvalidateRect( HWND hwnd
, LPRECT rect
, BOOL erase
)
61 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
65 if (rect
) printf( "InvalidateRect: %d %d,%d-%d,%d\n", hwnd
,
66 rect
->left
, rect
->top
, rect
->right
, rect
->bottom
);
67 else printf( "InvalidateRect: %d NULL\n", hwnd
);
69 if (rect
) hrgn
= CreateRectRgnIndirect( rect
);
70 InvalidateRgn( hwnd
, hrgn
, erase
);
71 if (hrgn
) DeleteObject( hrgn
);
75 /***********************************************************************
76 * ValidateRgn (USER.128)
78 void ValidateRgn( HWND hwnd
, HRGN hrgn
)
81 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
84 if (!wndPtr
->hrgnUpdate
) return;
85 if (!hrgn
) newRgn
= 0;
88 if (!(newRgn
= CreateRectRgn( 0, 0, 0, 0 ))) return;
89 if (CombineRgn( newRgn
, wndPtr
->hrgnUpdate
, hrgn
, RGN_DIFF
) == NULLREGION
)
91 DeleteObject( newRgn
);
95 DeleteObject( wndPtr
->hrgnUpdate
);
96 wndPtr
->hrgnUpdate
= newRgn
;
97 if (!wndPtr
->hrgnUpdate
) wndPtr
->flags
&= ~WIN_ERASE_UPDATERGN
;
101 /***********************************************************************
102 * ValidateRect (USER.127)
104 void ValidateRect( HWND hwnd
, LPRECT rect
)
108 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
111 if (rect
) hrgn
= CreateRectRgnIndirect( rect
);
112 ValidateRgn( hwnd
, hrgn
);
113 if (hrgn
) DeleteObject( hrgn
);
117 /***********************************************************************
118 * GetUpdateRect (USER.190)
120 BOOL
GetUpdateRect( HWND hwnd
, LPRECT rect
, BOOL erase
)
122 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
123 if (!wndPtr
) return FALSE
;
127 if (wndPtr
->hrgnUpdate
)
129 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
130 if (GetUpdateRgn( hwnd
, hrgn
, erase
) == ERROR
) return FALSE
;
131 GetRgnBox( hrgn
, rect
);
132 DeleteObject( hrgn
);
134 else SetRectEmpty( rect
);
136 return (wndPtr
->hrgnUpdate
!= 0);
140 /***********************************************************************
141 * GetUpdateRgn (USER.237)
143 int GetUpdateRgn( HWND hwnd
, HRGN hrgn
, BOOL erase
)
147 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
148 if (!wndPtr
) return ERROR
;
150 if (!wndPtr
->hrgnUpdate
)
152 if (!(hrgnClip
= CreateRectRgn( 0, 0, 0, 0 ))) return ERROR
;
153 retval
= CombineRgn( hrgn
, hrgnClip
, 0, RGN_COPY
);
157 hrgnClip
= CreateRectRgn( 0, 0,
158 wndPtr
->rectClient
.right
-wndPtr
->rectClient
.left
,
159 wndPtr
->rectClient
.bottom
-wndPtr
->rectClient
.top
);
160 if (!hrgnClip
) return ERROR
;
161 retval
= CombineRgn( hrgn
, wndPtr
->hrgnUpdate
, hrgnClip
, RGN_AND
);
164 HDC hdc
= GetDCEx( hwnd
, wndPtr
->hrgnUpdate
,
165 DCX_INTERSECTRGN
| DCX_USESTYLE
);
168 SendMessage( hwnd
, WM_ERASEBKGND
, hdc
, 0 );
169 ReleaseDC( hwnd
, hdc
);
173 DeleteObject( hrgnClip
);