1*c2c66affSColin Finck /*
2*c2c66affSColin Finck * ReactOS kernel
3*c2c66affSColin Finck * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
4*c2c66affSColin Finck *
5*c2c66affSColin Finck * This program is free software; you can redistribute it and/or modify
6*c2c66affSColin Finck * it under the terms of the GNU General Public License as published by
7*c2c66affSColin Finck * the Free Software Foundation; either version 2 of the License, or
8*c2c66affSColin Finck * (at your option) any later version.
9*c2c66affSColin Finck *
10*c2c66affSColin Finck * This program is distributed in the hope that it will be useful,
11*c2c66affSColin Finck * but WITHOUT ANY WARRANTY; without even the implied warranty of
12*c2c66affSColin Finck * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13*c2c66affSColin Finck * GNU General Public License for more details.
14*c2c66affSColin Finck *
15*c2c66affSColin Finck * You should have received a copy of the GNU General Public License
16*c2c66affSColin Finck * along with this program; if not, write to the Free Software
17*c2c66affSColin Finck * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18*c2c66affSColin Finck */
19*c2c66affSColin Finck /*
20*c2c66affSColin Finck * PROJECT: ReactOS user32.dll
21*c2c66affSColin Finck * FILE: win32ss/user/user32/windows/paint.c
22*c2c66affSColin Finck * PURPOSE: Input
23*c2c66affSColin Finck * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
24*c2c66affSColin Finck * UPDATE HISTORY:
25*c2c66affSColin Finck * 09-05-2001 CSH Created
26*c2c66affSColin Finck */
27*c2c66affSColin Finck
28*c2c66affSColin Finck /* INCLUDES ******************************************************************/
29*c2c66affSColin Finck
30*c2c66affSColin Finck #include <user32.h>
31*c2c66affSColin Finck
32*c2c66affSColin Finck static HBRUSH FrameBrushes[13];
33*c2c66affSColin Finck static HBITMAP hHatch;
34*c2c66affSColin Finck const DWORD HatchBitmap[4] = {0x5555AAAA, 0x5555AAAA, 0x5555AAAA, 0x5555AAAA};
35*c2c66affSColin Finck
36*c2c66affSColin Finck BOOL WINAPI MirrorRgn(HWND hwnd, HRGN hrgn);
37*c2c66affSColin Finck BOOL WINAPI PolyPatBlt(HDC,DWORD,PPATRECT,INT,ULONG);
38*c2c66affSColin Finck
39*c2c66affSColin Finck /* FUNCTIONS *****************************************************************/
40*c2c66affSColin Finck
41*c2c66affSColin Finck INT
42*c2c66affSColin Finck WINAPI
MirrorWindowRect(PWND pWnd,LPRECT lprc)43*c2c66affSColin Finck MirrorWindowRect( PWND pWnd, LPRECT lprc)
44*c2c66affSColin Finck {
45*c2c66affSColin Finck INT Ret = pWnd->rcWindow.right - pWnd->rcWindow.left - lprc->left;
46*c2c66affSColin Finck lprc->left = pWnd->rcWindow.right - pWnd->rcWindow.left - lprc->right;
47*c2c66affSColin Finck lprc->right = Ret;
48*c2c66affSColin Finck return Ret;
49*c2c66affSColin Finck }
50*c2c66affSColin Finck
51*c2c66affSColin Finck VOID
CreateFrameBrushes(VOID)52*c2c66affSColin Finck CreateFrameBrushes(VOID)
53*c2c66affSColin Finck {
54*c2c66affSColin Finck FrameBrushes[0] = CreateSolidBrush(RGB(0,0,0));
55*c2c66affSColin Finck FrameBrushes[1] = CreateSolidBrush(RGB(0,0,128));
56*c2c66affSColin Finck FrameBrushes[2] = CreateSolidBrush(RGB(10,36,106));
57*c2c66affSColin Finck FrameBrushes[3] = CreateSolidBrush(RGB(128,128,128));
58*c2c66affSColin Finck FrameBrushes[4] = CreateSolidBrush(RGB(181,181,181));
59*c2c66affSColin Finck FrameBrushes[5] = CreateSolidBrush(RGB(212,208,200));
60*c2c66affSColin Finck FrameBrushes[6] = CreateSolidBrush(RGB(236,233,216));
61*c2c66affSColin Finck FrameBrushes[7] = CreateSolidBrush(RGB(255,255,255));
62*c2c66affSColin Finck FrameBrushes[8] = CreateSolidBrush(RGB(49,106,197));
63*c2c66affSColin Finck FrameBrushes[9] = CreateSolidBrush(RGB(58,110,165));
64*c2c66affSColin Finck FrameBrushes[10] = CreateSolidBrush(RGB(64,64,64));
65*c2c66affSColin Finck FrameBrushes[11] = CreateSolidBrush(RGB(255,255,225));
66*c2c66affSColin Finck hHatch = CreateBitmap(8, 8, 1, 1, HatchBitmap);
67*c2c66affSColin Finck FrameBrushes[12] = CreatePatternBrush(hHatch);
68*c2c66affSColin Finck }
69*c2c66affSColin Finck
70*c2c66affSColin Finck VOID
DeleteFrameBrushes(VOID)71*c2c66affSColin Finck DeleteFrameBrushes(VOID)
72*c2c66affSColin Finck {
73*c2c66affSColin Finck unsigned Brush;
74*c2c66affSColin Finck
75*c2c66affSColin Finck for (Brush = 0; Brush < sizeof(FrameBrushes) / sizeof(HBRUSH); Brush++)
76*c2c66affSColin Finck {
77*c2c66affSColin Finck if (NULL != FrameBrushes[Brush])
78*c2c66affSColin Finck {
79*c2c66affSColin Finck DeleteObject(FrameBrushes[Brush]);
80*c2c66affSColin Finck FrameBrushes[Brush] = NULL;
81*c2c66affSColin Finck }
82*c2c66affSColin Finck }
83*c2c66affSColin Finck if (NULL != hHatch)
84*c2c66affSColin Finck {
85*c2c66affSColin Finck DeleteObject(hHatch);
86*c2c66affSColin Finck hHatch = NULL;
87*c2c66affSColin Finck }
88*c2c66affSColin Finck }
89*c2c66affSColin Finck
90*c2c66affSColin Finck
91*c2c66affSColin Finck /*
92*c2c66affSColin Finck * @implemented
93*c2c66affSColin Finck */
94*c2c66affSColin Finck BOOL
95*c2c66affSColin Finck WINAPI
GetUpdateRect(HWND Wnd,LPRECT Rect,BOOL Erase)96*c2c66affSColin Finck GetUpdateRect(
97*c2c66affSColin Finck HWND Wnd,
98*c2c66affSColin Finck LPRECT Rect,
99*c2c66affSColin Finck BOOL Erase)
100*c2c66affSColin Finck {
101*c2c66affSColin Finck PWND pWnd;
102*c2c66affSColin Finck
103*c2c66affSColin Finck pWnd = ValidateHwnd(Wnd);
104*c2c66affSColin Finck if (!pWnd)
105*c2c66affSColin Finck return FALSE;
106*c2c66affSColin Finck
107*c2c66affSColin Finck if ( pWnd->hrgnUpdate ||
108*c2c66affSColin Finck pWnd->state & (WNDS_SENDERASEBACKGROUND|WNDS_SENDNCPAINT|WNDS_UPDATEDIRTY|WNDS_PAINTNOTPROCESSED))
109*c2c66affSColin Finck {
110*c2c66affSColin Finck return NtUserGetUpdateRect(Wnd, Rect, Erase);
111*c2c66affSColin Finck }
112*c2c66affSColin Finck
113*c2c66affSColin Finck if (Rect)
114*c2c66affSColin Finck { // Did the Rgn update? No! Back set and shutup!
115*c2c66affSColin Finck Rect->left = Rect->right = Rect->top = Rect->bottom = 0;
116*c2c66affSColin Finck }
117*c2c66affSColin Finck return FALSE; // msdn: "If there is no update region, the return value is zero."
118*c2c66affSColin Finck
119*c2c66affSColin Finck }
120*c2c66affSColin Finck
121*c2c66affSColin Finck
122*c2c66affSColin Finck /*
123*c2c66affSColin Finck * @implemented
124*c2c66affSColin Finck */
125*c2c66affSColin Finck int
126*c2c66affSColin Finck WINAPI
GetUpdateRgn(HWND hWnd,HRGN hRgn,BOOL bErase)127*c2c66affSColin Finck GetUpdateRgn(
128*c2c66affSColin Finck HWND hWnd,
129*c2c66affSColin Finck HRGN hRgn,
130*c2c66affSColin Finck BOOL bErase)
131*c2c66affSColin Finck {
132*c2c66affSColin Finck PWND pWnd;
133*c2c66affSColin Finck
134*c2c66affSColin Finck if (!hRgn)
135*c2c66affSColin Finck {
136*c2c66affSColin Finck SetLastError(ERROR_INVALID_HANDLE);
137*c2c66affSColin Finck return ERROR;
138*c2c66affSColin Finck }
139*c2c66affSColin Finck
140*c2c66affSColin Finck pWnd = ValidateHwnd(hWnd);
141*c2c66affSColin Finck if (!pWnd)
142*c2c66affSColin Finck return ERROR;
143*c2c66affSColin Finck
144*c2c66affSColin Finck if ( pWnd->hrgnUpdate ||
145*c2c66affSColin Finck pWnd->state & (WNDS_SENDERASEBACKGROUND|WNDS_SENDNCPAINT|WNDS_UPDATEDIRTY|WNDS_PAINTNOTPROCESSED))
146*c2c66affSColin Finck {
147*c2c66affSColin Finck return NtUserGetUpdateRgn(hWnd, hRgn, bErase);
148*c2c66affSColin Finck }
149*c2c66affSColin Finck SetRectRgn(hRgn, 0, 0, 0, 0);
150*c2c66affSColin Finck return NULLREGION;
151*c2c66affSColin Finck }
152*c2c66affSColin Finck
153*c2c66affSColin Finck
154*c2c66affSColin Finck /*
155*c2c66affSColin Finck * @implemented
156*c2c66affSColin Finck */
157*c2c66affSColin Finck BOOL WINAPI
ScrollDC(HDC hDC,int dx,int dy,CONST RECT * lprcScroll,CONST RECT * lprcClip,HRGN hrgnUpdate,LPRECT lprcUpdate)158*c2c66affSColin Finck ScrollDC(
159*c2c66affSColin Finck HDC hDC,
160*c2c66affSColin Finck int dx,
161*c2c66affSColin Finck int dy,
162*c2c66affSColin Finck CONST RECT *lprcScroll,
163*c2c66affSColin Finck CONST RECT *lprcClip,
164*c2c66affSColin Finck HRGN hrgnUpdate,
165*c2c66affSColin Finck LPRECT lprcUpdate)
166*c2c66affSColin Finck {
167*c2c66affSColin Finck if (hDC == NULL) return FALSE;
168*c2c66affSColin Finck
169*c2c66affSColin Finck if (dx == 0 && dy == 0)
170*c2c66affSColin Finck {
171*c2c66affSColin Finck if (hrgnUpdate) SetRectRgn(hrgnUpdate, 0, 0, 0, 0);
172*c2c66affSColin Finck if (lprcUpdate) lprcUpdate->left = lprcUpdate->right =
173*c2c66affSColin Finck lprcUpdate->top = lprcUpdate->bottom = 0;
174*c2c66affSColin Finck return TRUE;
175*c2c66affSColin Finck }
176*c2c66affSColin Finck
177*c2c66affSColin Finck return NtUserScrollDC( hDC,
178*c2c66affSColin Finck dx,
179*c2c66affSColin Finck dy,
180*c2c66affSColin Finck lprcScroll,
181*c2c66affSColin Finck lprcClip,
182*c2c66affSColin Finck hrgnUpdate,
183*c2c66affSColin Finck lprcUpdate);
184*c2c66affSColin Finck }
185*c2c66affSColin Finck
186*c2c66affSColin Finck /*
187*c2c66affSColin Finck * @implemented
188*c2c66affSColin Finck */
189*c2c66affSColin Finck int
190*c2c66affSColin Finck WINAPI
SetWindowRgn(HWND hWnd,HRGN hRgn,BOOL bRedraw)191*c2c66affSColin Finck SetWindowRgn(
192*c2c66affSColin Finck HWND hWnd,
193*c2c66affSColin Finck HRGN hRgn,
194*c2c66affSColin Finck BOOL bRedraw)
195*c2c66affSColin Finck {
196*c2c66affSColin Finck BOOL Hook;
197*c2c66affSColin Finck int Ret = 0;
198*c2c66affSColin Finck
199*c2c66affSColin Finck LoadUserApiHook();
200*c2c66affSColin Finck
201*c2c66affSColin Finck Hook = BeginIfHookedUserApiHook();
202*c2c66affSColin Finck
203*c2c66affSColin Finck /* Bypass SEH and go direct. */
204*c2c66affSColin Finck if (!Hook)
205*c2c66affSColin Finck {
206*c2c66affSColin Finck Ret = NtUserSetWindowRgn(hWnd, hRgn, bRedraw);
207*c2c66affSColin Finck if (Ret)
208*c2c66affSColin Finck DeleteObject(hRgn);
209*c2c66affSColin Finck return Ret;
210*c2c66affSColin Finck }
211*c2c66affSColin Finck
212*c2c66affSColin Finck _SEH2_TRY
213*c2c66affSColin Finck {
214*c2c66affSColin Finck Ret = guah.SetWindowRgn(hWnd, hRgn, bRedraw);
215*c2c66affSColin Finck }
216*c2c66affSColin Finck _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
217*c2c66affSColin Finck {
218*c2c66affSColin Finck }
219*c2c66affSColin Finck _SEH2_END;
220*c2c66affSColin Finck
221*c2c66affSColin Finck EndUserApiHook();
222*c2c66affSColin Finck
223*c2c66affSColin Finck return Ret;
224*c2c66affSColin Finck }
225*c2c66affSColin Finck
226*c2c66affSColin Finck /*
227*c2c66affSColin Finck * @implemented
228*c2c66affSColin Finck */
229*c2c66affSColin Finck BOOL
230*c2c66affSColin Finck WINAPI
UpdateWindow(HWND hWnd)231*c2c66affSColin Finck UpdateWindow(
232*c2c66affSColin Finck HWND hWnd)
233*c2c66affSColin Finck {
234*c2c66affSColin Finck PWND pWnd = ValidateHwnd(hWnd);
235*c2c66affSColin Finck
236*c2c66affSColin Finck if (!pWnd)
237*c2c66affSColin Finck return FALSE;
238*c2c66affSColin Finck
239*c2c66affSColin Finck if ( pWnd->hrgnUpdate ||
240*c2c66affSColin Finck pWnd->state & WNDS_INTERNALPAINT ||
241*c2c66affSColin Finck pWnd->spwndChild )
242*c2c66affSColin Finck {
243*c2c66affSColin Finck return NtUserxUpdateWindow(hWnd);
244*c2c66affSColin Finck }
245*c2c66affSColin Finck return TRUE;
246*c2c66affSColin Finck }
247*c2c66affSColin Finck
248*c2c66affSColin Finck /*
249*c2c66affSColin Finck * @implemented
250*c2c66affSColin Finck */
251*c2c66affSColin Finck BOOL
252*c2c66affSColin Finck WINAPI
ValidateRgn(HWND hWnd,HRGN hRgn)253*c2c66affSColin Finck ValidateRgn(
254*c2c66affSColin Finck HWND hWnd,
255*c2c66affSColin Finck HRGN hRgn)
256*c2c66affSColin Finck {
257*c2c66affSColin Finck return NtUserxValidateRgn(hWnd, hRgn);
258*c2c66affSColin Finck }
259*c2c66affSColin Finck
260*c2c66affSColin Finck /*
261*c2c66affSColin Finck * @implemented
262*c2c66affSColin Finck */
263*c2c66affSColin Finck int
264*c2c66affSColin Finck WINAPI
GetWindowRgn(HWND hWnd,HRGN hRgn)265*c2c66affSColin Finck GetWindowRgn(
266*c2c66affSColin Finck HWND hWnd,
267*c2c66affSColin Finck HRGN hRgn)
268*c2c66affSColin Finck {
269*c2c66affSColin Finck PWND pWnd;
270*c2c66affSColin Finck int Ret;
271*c2c66affSColin Finck
272*c2c66affSColin Finck if (!hRgn)
273*c2c66affSColin Finck return ERROR;
274*c2c66affSColin Finck
275*c2c66affSColin Finck pWnd = ValidateHwnd(hWnd);
276*c2c66affSColin Finck
277*c2c66affSColin Finck if (!pWnd || !pWnd->hrgnClip || pWnd->state2 & WNDS2_MAXIMIZEDMONITORREGION)
278*c2c66affSColin Finck return ERROR;
279*c2c66affSColin Finck
280*c2c66affSColin Finck Ret = CombineRgn(hRgn, pWnd->hrgnClip, NULL, RGN_COPY);
281*c2c66affSColin Finck
282*c2c66affSColin Finck if (!Ret)
283*c2c66affSColin Finck return ERROR;
284*c2c66affSColin Finck /*
285*c2c66affSColin Finck if (hWnd != GetDesktopWindow()) // pWnd->fnid != FNID_DESKTOP)
286*c2c66affSColin Finck Ret = OffsetRgn(hRgn, -pWnd->rcWindow.left, -pWnd->rcWindow.top);
287*c2c66affSColin Finck */
288*c2c66affSColin Finck if (pWnd->ExStyle & WS_EX_LAYOUTRTL)
289*c2c66affSColin Finck MirrorRgn(hWnd, hRgn);
290*c2c66affSColin Finck
291*c2c66affSColin Finck return Ret;
292*c2c66affSColin Finck }
293*c2c66affSColin Finck
294*c2c66affSColin Finck /*
295*c2c66affSColin Finck * @implemented
296*c2c66affSColin Finck */
297*c2c66affSColin Finck int
298*c2c66affSColin Finck WINAPI
GetWindowRgnBox(HWND hWnd,LPRECT lprc)299*c2c66affSColin Finck GetWindowRgnBox(
300*c2c66affSColin Finck HWND hWnd,
301*c2c66affSColin Finck LPRECT lprc)
302*c2c66affSColin Finck {
303*c2c66affSColin Finck PWND pWnd;
304*c2c66affSColin Finck int Ret;
305*c2c66affSColin Finck
306*c2c66affSColin Finck if (!lprc)
307*c2c66affSColin Finck return ERROR;
308*c2c66affSColin Finck
309*c2c66affSColin Finck pWnd = ValidateHwnd(hWnd);
310*c2c66affSColin Finck
311*c2c66affSColin Finck if (!pWnd || !pWnd->hrgnClip || pWnd->state2 & WNDS2_MAXIMIZEDMONITORREGION)
312*c2c66affSColin Finck return ERROR;
313*c2c66affSColin Finck
314*c2c66affSColin Finck Ret = GetRgnBox(pWnd->hrgnClip, lprc);
315*c2c66affSColin Finck
316*c2c66affSColin Finck if (!Ret)
317*c2c66affSColin Finck return ERROR;
318*c2c66affSColin Finck /*
319*c2c66affSColin Finck if (hWnd != GetDesktopWindow()) // pWnd->fnid != FNID_DESKTOP)
320*c2c66affSColin Finck OffsetRect(lprc, -pWnd->rcWindow.left, -pWnd->rcWindow.top);
321*c2c66affSColin Finck */
322*c2c66affSColin Finck if (pWnd->ExStyle & WS_EX_LAYOUTRTL)
323*c2c66affSColin Finck MirrorWindowRect(pWnd, lprc);
324*c2c66affSColin Finck
325*c2c66affSColin Finck return Ret;
326*c2c66affSColin Finck }
327*c2c66affSColin Finck
328*c2c66affSColin Finck
329*c2c66affSColin Finck const BYTE MappingTable[33] = {5,9,2,3,5,7,0,0,0,7,5,5,3,2,7,5,3,3,0,5,7,10,5,0,11,4,1,1,3,8,6,12,7};
330*c2c66affSColin Finck /*
331*c2c66affSColin Finck * @implemented
332*c2c66affSColin Finck */
333*c2c66affSColin Finck BOOL
334*c2c66affSColin Finck WINAPI
DrawFrame(HDC hDc,RECT * r,DWORD width,DWORD type)335*c2c66affSColin Finck DrawFrame(
336*c2c66affSColin Finck HDC hDc,
337*c2c66affSColin Finck RECT *r,
338*c2c66affSColin Finck DWORD width,
339*c2c66affSColin Finck DWORD type
340*c2c66affSColin Finck )
341*c2c66affSColin Finck {
342*c2c66affSColin Finck DWORD rop;
343*c2c66affSColin Finck DWORD brush;
344*c2c66affSColin Finck HBRUSH hbrFrame;
345*c2c66affSColin Finck PATRECT p[4];
346*c2c66affSColin Finck if (NULL == FrameBrushes[0])
347*c2c66affSColin Finck {
348*c2c66affSColin Finck CreateFrameBrushes();
349*c2c66affSColin Finck }
350*c2c66affSColin Finck if (type & 4)
351*c2c66affSColin Finck {
352*c2c66affSColin Finck rop = PATINVERT;
353*c2c66affSColin Finck }
354*c2c66affSColin Finck else
355*c2c66affSColin Finck {
356*c2c66affSColin Finck rop = PATCOPY;
357*c2c66affSColin Finck }
358*c2c66affSColin Finck brush = type / 8;
359*c2c66affSColin Finck if (brush >= 33)
360*c2c66affSColin Finck {
361*c2c66affSColin Finck brush = 32;
362*c2c66affSColin Finck }
363*c2c66affSColin Finck brush = MappingTable[brush];
364*c2c66affSColin Finck hbrFrame = FrameBrushes[brush];
365*c2c66affSColin Finck p[0].hBrush = hbrFrame;
366*c2c66affSColin Finck p[1].hBrush = hbrFrame;
367*c2c66affSColin Finck p[2].hBrush = hbrFrame;
368*c2c66affSColin Finck p[3].hBrush = hbrFrame;
369*c2c66affSColin Finck p[0].r.left = r->left;
370*c2c66affSColin Finck p[0].r.top = r->top;
371*c2c66affSColin Finck p[0].r.right = r->right - r->left;
372*c2c66affSColin Finck p[0].r.bottom = width;
373*c2c66affSColin Finck p[1].r.left = r->left;
374*c2c66affSColin Finck p[1].r.top = r->bottom - width;
375*c2c66affSColin Finck p[1].r.right = r->right - r->left;
376*c2c66affSColin Finck p[1].r.bottom = width;
377*c2c66affSColin Finck p[2].r.left = r->left;
378*c2c66affSColin Finck p[2].r.top = r->top + width;
379*c2c66affSColin Finck p[2].r.right = width;
380*c2c66affSColin Finck p[2].r.bottom = r->bottom - r->top - (width * 2);
381*c2c66affSColin Finck p[3].r.left = r->right - width;
382*c2c66affSColin Finck p[3].r.top = r->top + width;
383*c2c66affSColin Finck p[3].r.right = width;
384*c2c66affSColin Finck p[3].r.bottom = r->bottom - r->top - (width * 2);
385*c2c66affSColin Finck return PolyPatBlt(hDc,rop,p,4,0);
386*c2c66affSColin Finck }
387