3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS user32.dll
5 * FILE: lib/user32/windows/window.c
6 * PURPOSE: Window management
7 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
9 * 06-06-2001 CSH Created
12 /* INCLUDES ******************************************************************/
18 #include <user32/wininternal.h>
21 /* GLOBALS *******************************************************************/
23 static HBITMAP hbSysMenu;
24 /* TODO: widgets will be cached here.
25 static HBITMAP hbClose;
26 static HBITMAP hbCloseD;
27 static HBITMAP hbMinimize;
28 static HBITMAP hbMinimizeD;
29 static HBITMAP hbRestore;
30 static HBITMAP hbRestoreD;
31 static HBITMAP hbMaximize;
32 static HBITMAP hbScrUp;
33 static HBITMAP hbScrDwn;
34 static HBITMAP hbScrLeft;
35 static HBITMAP hbScrRight;
37 static COLORREF SysColours[] =
39 RGB(224, 224, 224) /* COLOR_SCROLLBAR */,
40 RGB(58, 110, 165) /* COLOR_BACKGROUND */,
41 RGB(0, 0, 128) /* COLOR_ACTIVECAPTION */,
42 RGB(128, 128, 128) /* COLOR_INACTIVECAPTION */,
43 RGB(192, 192, 192) /* COLOR_MENU */,
44 RGB(192, 192, 192) /* COLOR_WINDOW */,
45 RGB(192, 192, 192) /* COLOR_WINDOWFRAME */,
46 RGB(0, 0, 0) /* COLOR_MENUTEXT */,
47 RGB(0, 0, 0) /* COLOR_WINDOWTEXT */,
48 RGB(255, 255, 255) /* COLOR_CAPTIONTEXT */,
49 RGB(128, 128, 128) /* COLOR_ACTIVEBORDER */,
50 RGB(255, 255, 255) /* COLOR_INACTIVEBORDER */,
51 RGB(255, 255, 232) /* COLOR_APPWORKSPACE */,
52 RGB(224, 224, 224) /* COLOR_HILIGHT */,
53 RGB(0, 0, 128) /* COLOR_HILIGHTTEXT */,
54 RGB(192, 192, 192) /* COLOR_BTNFACE */,
55 RGB(128, 128, 128) /* COLOR_BTNSHADOW */,
56 RGB(192, 192, 192) /* COLOR_GRAYTEXT */,
57 RGB(0, 0, 0) /* COLOR_BTNTEXT */,
58 RGB(192, 192, 192) /* COLOR_INACTIVECAPTIONTEXT */,
59 RGB(255, 255, 255) /* COLOR_BTNHILIGHT */,
60 RGB(32, 32, 32) /* COLOR_3DDKSHADOW */,
61 RGB(192, 192, 192) /* COLOR_3DLIGHT */,
62 RGB(0, 0, 0) /* COLOR_INFOTEXT */,
63 RGB(255, 255, 192) /* COLOR_INFOBK */,
64 RGB(184, 180, 184) /* COLOR_ALTERNATEBTNFACE */,
65 RGB(0, 0, 255) /* COLOR_HOTLIGHT */,
66 RGB(16, 132, 208) /* COLOR_GRADIENTACTIVECAPTION */,
67 RGB(181, 181, 181) /* COLOR_GRADIENTINACTIVECAPTION */,
70 static ATOM AtomInternalPos;
72 /* FUNCTIONS *****************************************************************/
74 BOOL IsMaxBoxActive(HWND hWnd)
76 ULONG uStyle = GetWindowLong( hWnd, GWL_STYLE );
77 return (uStyle & WS_MAXIMIZEBOX);
80 BOOL IsCloseBoxActive( HWND hWnd )
82 ULONG uStyle = GetWindowLong(hWnd, GWL_STYLE );
83 return ( uStyle & WS_SYSMENU );
86 BOOL IsMinBoxActive( HWND hWnd )
88 ULONG uStyle = GetWindowLong( hWnd, GWL_STYLE );
89 return (uStyle & WS_MINIMIZEBOX);
92 INT UIGetFrameSizeX( HWND hWnd )
94 ULONG uStyle = GetWindowLong( hWnd, GWL_STYLE );
96 if ( uStyle & WS_THICKFRAME )
97 return GetSystemMetrics( SM_CXSIZEFRAME );
99 return GetSystemMetrics( SM_CXFRAME );
102 INT UIGetFrameSizeY( HWND hWnd )
104 ULONG uStyle = GetWindowLong( hWnd, GWL_STYLE );
106 if ( uStyle & WS_THICKFRAME )
107 return GetSystemMetrics( SM_CYSIZEFRAME );
109 return GetSystemMetrics( SM_CYFRAME );
113 UserSetupInternalPos( VOID )
116 AtomInternalPos = GlobalAddAtomA(Str);
120 GetSysColorPen( int nIndex )
122 return(CreatePen(PS_SOLID, 1, SysColours[nIndex]));
126 GetSysColorBrush( int nIndex )
128 return(CreateSolidBrush(SysColours[nIndex]));
133 DefFrameProcA( HWND hWnd,
142 static LRESULT WINAPI DefButtonWndProc( HWND hWnd, UINT uMsg,
143 WPARAM wParam, LPARAM lParam )
149 static LRESULT WINAPI DefDesktopWndProc( HWND hWnd, UINT uMsg,
150 WPARAM wParam, LPARAM lParam )
157 DefFrameProcW(HWND hWnd,
168 DefWndRedrawIconTitle(HWND hWnd)
170 PINTERNALPOS lpPos = (PINTERNALPOS)GetPropA(hWnd,
171 (LPSTR)(DWORD)AtomInternalPos);
174 if (lpPos->IconTitle != NULL)
176 SendMessageA(lpPos->IconTitle, WM_SHOWWINDOW, TRUE, 0);
177 InvalidateRect(lpPos->IconTitle, NULL, TRUE);
185 UserHasMenu(HWND hWnd, ULONG Style)
187 return(!(Style & WS_CHILD) && GetWindowLong(hWnd, GWL_ID) != 0);
191 UserHasAnyFrameStyle(ULONG Style, ULONG ExStyle)
193 return((Style & (WS_THICKFRAME | WS_DLGFRAME | WS_BORDER)) ||
194 (ExStyle & WS_EX_DLGMODALFRAME) ||
195 (!(Style & (WS_CHILD | WS_POPUP))));
199 UserHasDlgFrameStyle(ULONG Style, ULONG ExStyle)
201 return((ExStyle & WS_EX_DLGMODALFRAME) ||
202 ((Style & WS_DLGFRAME) && (!(Style & WS_THICKFRAME))));
206 UserHasThickFrameStyle(ULONG Style, ULONG ExStyle)
208 return((Style & WS_THICKFRAME) &&
209 (!((Style & (WS_DLGFRAME | WS_BORDER)) == WS_DLGFRAME)));
213 UserHasThinFrameStyle(ULONG Style, ULONG ExStyle)
215 return((Style & WS_BORDER) ||
216 (!(Style & (WS_CHILD | WS_POPUP))));
220 UserHasBigFrameStyle(ULONG Style, ULONG ExStyle)
222 return((Style & (WS_THICKFRAME | WS_DLGFRAME)) ||
223 (ExStyle & WS_EX_DLGMODALFRAME));
226 INT GetFrameSize(HWND hWnd)
231 uStyle = GetWindowLong(hWnd, GWL_STYLE);
232 uExStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
234 if (UserHasThinFrameStyle(uStyle, uExStyle))
236 return GetSystemMetrics( SM_CXBORDER );
238 else if (UserHasDlgFrameStyle(uStyle, uExStyle))
240 return GetSystemMetrics( SM_CXDLGFRAME );
242 return GetSystemMetrics( SM_CXFRAME );
245 void UserGetInsideRectNC( HWND hWnd, RECT *rect )
251 Style = GetWindowLong(hWnd, GWL_STYLE);
252 ExStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
253 GetWindowRect(hWnd, &WindowRect);
254 rect->top = rect->left = 0;
255 rect->right = WindowRect.right - WindowRect.left;
256 rect->bottom = WindowRect.bottom - WindowRect.top;
258 if (Style & WS_ICONIC)
263 /* Remove frame from rectangle */
264 if (UserHasThickFrameStyle(Style, ExStyle ))
266 InflateRect( rect, -GetSystemMetrics(SM_CXFRAME),
267 -GetSystemMetrics(SM_CYFRAME) );
271 if (UserHasDlgFrameStyle(Style, ExStyle ))
273 InflateRect( rect, -GetSystemMetrics(SM_CXDLGFRAME),
274 -GetSystemMetrics(SM_CYDLGFRAME));
275 /* FIXME: this isn't in NC_AdjustRect? why not? */
276 if (ExStyle & WS_EX_DLGMODALFRAME)
277 InflateRect( rect, -1, 0 );
281 if (UserHasThinFrameStyle(Style, ExStyle))
283 InflateRect(rect, -GetSystemMetrics(SM_CXBORDER),
284 -GetSystemMetrics(SM_CYBORDER));
290 void UserDrawSysMenuButton( HWND hWnd, HDC hDC, BOOL down )
294 HBITMAP hSavedBitmap;
296 hbSysMenu = LoadBitmap(0, MAKEINTRESOURCE(OBM_CLOSE));
297 UserGetInsideRectNC(hWnd, &Rect);
298 hDcMem = CreateCompatibleDC(hDC);
299 hSavedBitmap = SelectObject(hDcMem, hbSysMenu);
300 BitBlt(hDC, Rect.left + 2, Rect.top +
302 (GetWindowLong(hWnd, GWL_STYLE) & WS_CHILD) ?
303 GetSystemMetrics(SM_CXSIZE): 0, 0, SRCCOPY);
304 SelectObject(hDcMem, hSavedBitmap);
308 /* FIXME: Cache bitmaps, then just bitblt instead of calling DFC() (and
309 wasting precious CPU cycles) every time */
311 static void UserDrawCloseButton ( HWND hWnd, HDC hDC, BOOL bDown )
315 BOOL bToolWindow = GetWindowLongA( hWnd, GWL_EXSTYLE ) & WS_EX_TOOLWINDOW;
316 INT iBmpWidth = (bToolWindow ? GetSystemMetrics(SM_CXSMSIZE) :
317 GetSystemMetrics(SM_CXSIZE)) - 2;
318 INT iBmpHeight = (bToolWindow ? GetSystemMetrics(SM_CYSMSIZE) :
319 GetSystemMetrics(SM_CYSIZE) - 4);
320 INT OffsetX = UIGetFrameSizeY( hWnd );
321 INT OffsetY = UIGetFrameSizeY( hWnd );
324 if(!(GetWindowLong( hWnd, GWL_STYLE ) & WS_SYSMENU))
328 GetWindowRect( hWnd, &rect );
330 rect.right = rect.right - rect.left;
331 rect.bottom = rect.bottom - rect.top;
332 rect.left = rect.top = 0;
334 rect.right - OffsetX - iBmpWidth - 3,
336 rect.right - OffsetX - 3,
337 rect.top + iBmpHeight + OffsetY + 2 );
339 DrawFrameControl( hDC, &rect, DFC_CAPTION,
341 (bDown ? DFCS_PUSHED : 0) |
342 (IsCloseBoxActive(hWnd) ? 0 : DFCS_INACTIVE)) );
345 static void UserDrawMaxButton( HWND hWnd, HDC hDC, BOOL bDown )
349 INT iBmpWidth = GetSystemMetrics(SM_CXSIZE) - 2;
350 INT iBmpHeight = GetSystemMetrics(SM_CYSIZE) - 4;
352 INT OffsetX = UIGetFrameSizeY( hWnd );
353 INT OffsetY = UIGetFrameSizeY( hWnd );
355 GetWindowRect( hWnd, &rect );
357 if (!IsMinBoxActive(hWnd) && !IsMaxBoxActive(hWnd))
359 if ((GetWindowLongA( hWnd, GWL_EXSTYLE ) & WS_EX_TOOLWINDOW) == TRUE)
360 return; /* ToolWindows don't have min/max buttons */
362 rect.right = rect.right - rect.left;
363 rect.bottom = rect.bottom - rect.top;
364 rect.left = rect.top = 0;
366 rect.right - OffsetX - (iBmpWidth*2) - 5,
368 rect.right - iBmpWidth - OffsetX - 5,
369 rect.top + iBmpHeight + OffsetY + 2 );
371 DrawFrameControl( hDC, &rect, DFC_CAPTION,
372 (IsZoomed(hWnd) ? DFCS_CAPTIONRESTORE : DFCS_CAPTIONMAX) |
373 (bDown ? DFCS_PUSHED : 0) |
374 (IsMaxBoxActive(hWnd) ? 0 : DFCS_INACTIVE) );
378 static void UserDrawMinButton( HWND hWnd, HDC hDC, BOOL bDown )
382 INT iBmpWidth = GetSystemMetrics(SM_CXSIZE) - 2;
383 INT iBmpHeight = GetSystemMetrics(SM_CYSIZE) - 4;
385 INT OffsetX = UIGetFrameSizeX( hWnd );
386 INT OffsetY = UIGetFrameSizeY( hWnd );
388 GetWindowRect( hWnd, &rect );
390 if (!IsMinBoxActive(hWnd) && !IsMaxBoxActive(hWnd))
392 if ((GetWindowLongA( hWnd, GWL_EXSTYLE ) & WS_EX_TOOLWINDOW) == TRUE)
393 return; /* ToolWindows don't have min/max buttons */
395 rect.right = rect.right - rect.left;
396 rect.bottom = rect.bottom - rect.top;
397 rect.left = rect.top = 0;
399 rect.right - OffsetX - (iBmpWidth*3) - 5,
401 rect.right - (iBmpWidth * 2) - OffsetX - 5,
402 rect.top + iBmpHeight + OffsetY + 2 );
403 DrawFrameControl( hDC, &rect, DFC_CAPTION,
404 DFCS_CAPTIONMIN | (bDown ? DFCS_PUSHED : 0) |
405 (IsMinBoxActive(hWnd) ? 0 : DFCS_INACTIVE) );
408 static void UserDrawCaptionNC( HDC hDC, RECT *rect, HWND hWnd,
409 DWORD style, BOOL active )
413 /* Implement and Use DrawCaption() */
414 SelectObject( hDC, GetSysColorBrush(active ? COLOR_ACTIVECAPTION : COLOR_INACTIVECAPTION) );
415 PatBlt(hDC,rect->left + GetSystemMetrics(SM_CXFRAME), rect->top +
416 GetSystemMetrics(SM_CYFRAME), rect->right - (GetSystemMetrics(SM_CXFRAME) * 2) - 1, rect->top +
417 GetSystemMetrics(SM_CYCAPTION) - 1, PATCOPY );
419 if (style & WS_SYSMENU)
421 UserDrawSysMenuButton( hWnd, hDC, FALSE);
422 r.left += GetSystemMetrics(SM_CXSIZE) + 1;
423 UserDrawCloseButton( hWnd, hDC, FALSE);
424 r.right -= GetSystemMetrics(SM_CXSMSIZE) + 1;
425 UserDrawMinButton(hWnd, hDC, FALSE);
426 UserDrawMaxButton(hWnd, hDC, FALSE);
428 if (GetWindowTextA( hWnd, buffer, sizeof(buffer) ))
430 NONCLIENTMETRICS nclm;
431 HFONT hFont, hOldFont;
433 nclm.cbSize = sizeof(NONCLIENTMETRICS);
434 SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, 0, &nclm, 0);
435 SetTextColor(hDC, SysColours[ active ? COLOR_CAPTIONTEXT : COLOR_INACTIVECAPTIONTEXT]);
436 SetBkMode( hDC, TRANSPARENT );
437 if (style & WS_EX_TOOLWINDOW)
438 hFont = CreateFontIndirectW(&nclm.lfSmCaptionFont);
440 hFont = CreateFontIndirectW(&nclm.lfCaptionFont);
441 hOldFont = SelectObject(hDC, hFont);
442 TextOutA(hDC, r.left + (GetSystemMetrics(SM_CXDLGFRAME) * 2), (r.top / 2) + (((int) nclm.lfCaptionFont.lfHeight) / 2) + (GetSystemMetrics(SM_CXDLGFRAME) / 2), buffer, strlen(buffer));
443 DeleteObject (SelectObject (hDC, hOldFont));
448 UserDrawFrameNC(HDC hDC, RECT* rect, BOOL dlgFrame, BOOL active)
450 SelectObject( hDC, GetSysColorBrush(COLOR_WINDOW) );
451 DrawEdge(hDC, rect,EDGE_RAISED, BF_RECT | BF_MIDDLE);
454 void SCROLL_DrawScrollBar (HWND hWnd, HDC hDC, INT nBar, BOOL arrows, BOOL interior);
457 DefWndDoPaintNC(HWND hWnd, HRGN clip)
464 Active = GetWindowLongW(hWnd, GWL_STYLE) & WIN_NCACTIVATED;
465 Style = GetWindowLong(hWnd, GWL_STYLE);
466 ExStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
468 hDC = GetDCEx(hWnd, (clip > (HRGN)1) ? clip : 0, DCX_USESTYLE | DCX_WINDOW |
469 ((clip > (HRGN)1) ? (DCX_INTERSECTRGN | DCX_KEEPCLIPRGN) : 0));
475 /* FIXME: Test whether we need to draw anything at all. */
477 GetWindowRect(hWnd, &rect);
478 rect.right = rect.right - rect.left;
479 rect.bottom = rect.bottom - rect.top;
480 rect.top = rect.left = 0;
481 SelectObject(hDC, GetSysColorPen(COLOR_WINDOWFRAME));
482 if (UserHasThickFrameStyle(Style, ExStyle))
484 UserDrawFrameNC(hDC, &rect, FALSE, Active);
486 else if (UserHasDlgFrameStyle(Style, ExStyle))
488 UserDrawFrameNC(hDC, &rect, TRUE, Active);
490 if (Style & WS_CAPTION)
493 r.bottom = rect.top + GetSystemMetrics(SM_CYSIZE);
494 rect.top += GetSystemMetrics(SM_CYSIZE) +
495 GetSystemMetrics(SM_CYBORDER);
496 UserDrawCaptionNC(hDC, &r, hWnd, Style, Active);
499 /* FIXME: Draw menu bar. */
501 DbgPrint("drawing scrollbars..\n");
502 /* Draw scrollbars */
503 if (Style & WS_VSCROLL)
504 SCROLL_DrawScrollBar(hWnd, hDC, SB_VERT, TRUE, TRUE);
505 if (Style & WS_HSCROLL)
506 SCROLL_DrawScrollBar(hWnd, hDC, SB_HORZ, TRUE, TRUE);
508 /* FIXME: Draw size box.*/
510 ReleaseDC(hWnd, hDC);
515 DefWndPaintNC(HWND hWnd, HRGN clip)
517 if (IsWindowVisible(hWnd))
521 DefWndRedrawIconTitle(hWnd);
525 DefWndDoPaintNC(hWnd, clip);
532 DefWndHitTestNC(HWND hWnd, POINT Point)
535 ULONG Style = GetWindowLong(hWnd, GWL_STYLE);
536 ULONG ExStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
538 GetWindowRect(hWnd, &WindowRect);
539 if (!PtInRect(&WindowRect, Point))
544 if (Style & WS_MINIMIZE)
548 if (UserHasThickFrameStyle(Style, ExStyle))
550 InflateRect(&WindowRect, -GetSystemMetrics(SM_CXFRAME),
551 -GetSystemMetrics(SM_CYFRAME));
552 if (!PtInRect(&WindowRect, Point))
554 if (Point.y < WindowRect.top)
556 if (Point.x < (WindowRect.left + GetSystemMetrics(SM_CXSIZE)))
560 if (Point.x >= (WindowRect.right - GetSystemMetrics(SM_CXSIZE)))
566 if (Point.y >= WindowRect.bottom)
568 if (Point.x < (WindowRect.left + GetSystemMetrics(SM_CXSIZE)))
570 return(HTBOTTOMLEFT);
572 if (Point.x >= (WindowRect.right - GetSystemMetrics(SM_CXSIZE)))
574 return(HTBOTTOMRIGHT);
578 if (Point.x < WindowRect.left)
580 if (Point.y < (WindowRect.top + GetSystemMetrics(SM_CYSIZE)))
584 if (Point.y >= (WindowRect.bottom - GetSystemMetrics(SM_CYSIZE)))
586 return(HTBOTTOMLEFT);
590 if (Point.x >= WindowRect.right)
592 if (Point.y < (WindowRect.top + GetSystemMetrics(SM_CYSIZE)))
596 if (Point.y >= (WindowRect.bottom - GetSystemMetrics(SM_CYSIZE)))
598 return(HTBOTTOMRIGHT);
606 if (UserHasDlgFrameStyle(Style, ExStyle))
608 InflateRect(&WindowRect, -GetSystemMetrics(SM_CXDLGFRAME),
609 -GetSystemMetrics(SM_CYDLGFRAME));
611 else if (UserHasThinFrameStyle(Style, ExStyle))
613 InflateRect(&WindowRect, -GetSystemMetrics(SM_CXBORDER),
614 -GetSystemMetrics(SM_CYBORDER));
616 if (!PtInRect(&WindowRect, Point))
622 if ((Style & WS_CAPTION) == WS_CAPTION)
624 WindowRect.top += GetSystemMetrics(SM_CYCAPTION) -
625 GetSystemMetrics(SM_CYBORDER);
626 if (!PtInRect(&WindowRect, Point))
628 if ((Style & WS_SYSMENU) && !(ExStyle & WS_EX_TOOLWINDOW))
630 WindowRect.left += GetSystemMetrics(SM_CXSIZE);
631 WindowRect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
633 if (Point.x <= WindowRect.left)
637 if (WindowRect.right <= Point.x)
642 if (Style & WS_MAXIMIZEBOX || Style & WS_MINIMIZEBOX)
644 WindowRect.right -= GetSystemMetrics(SM_CXSIZE) - 2;
646 if (Point.x >= WindowRect.right)
651 if (Style & WS_MINIMIZEBOX)
653 WindowRect.right -= GetSystemMetrics(SM_CXSIZE) - 2;
655 if (Point.x >= WindowRect.right)
663 ScreenToClient(hWnd, &Point);
664 GetClientRect(hWnd, &WindowRect);
666 if (PtInRect(&WindowRect, Point))
671 if (Style & WS_VSCROLL)
673 WindowRect.right += GetSystemMetrics(SM_CXVSCROLL);
674 if (PtInRect(&WindowRect, Point))
680 if (Style & WS_HSCROLL)
682 WindowRect.bottom += GetSystemMetrics(SM_CYHSCROLL);
683 if (PtInRect(&WindowRect, Point))
685 if ((Style & WS_VSCROLL) &&
686 (Point.x >= (WindowRect.right - GetSystemMetrics(SM_CXVSCROLL))))
694 if (UserHasMenu(hWnd, Style))
696 if (Point.y < 0 && Point.x >= 0 && Point.x <= WindowRect.right)
706 DefWndDrawSysButton(HWND hWnd, HDC hDC, BOOL Down)
711 DefWndHandleLButtonDownNC(HWND hWnd, WPARAM wParam, LPARAM lParam)
717 HWND hTopWnd = GetDesktopWindow(); //GetAncestor(hWnd, GA_ROOT); temp fix.
718 if (SetActiveWindow(hTopWnd) || GetActiveWindow() == hTopWnd)
720 SendMessageA(hWnd, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, lParam);
726 if (GetWindowLong(hWnd, GWL_STYLE) & WS_SYSMENU)
728 if (!(GetWindowLong(hWnd, GWL_STYLE) & WS_MINIMIZE))
730 HDC hDC = GetWindowDC(hWnd);
731 DefWndDrawSysButton(hWnd, hDC, TRUE);
732 ReleaseDC(hWnd, hDC);
734 SendMessageA(hWnd, WM_SYSCOMMAND, SC_MOUSEMENU + HTSYSMENU,
741 SendMessageA(hWnd, WM_SYSCOMMAND, SC_MOUSEMENU, lParam);
746 SendMessageA(hWnd, WM_SYSCOMMAND, SC_HSCROLL + HTHSCROLL, lParam);
751 SendMessageA(hWnd, WM_SYSCOMMAND, SC_VSCROLL + HTVSCROLL, lParam);
756 UserDrawMinButton(hWnd, GetWindowDC(hWnd), IsMinBoxActive(hWnd) );
761 UserDrawMaxButton(hWnd,GetWindowDC(hWnd), IsMaxBoxActive(hWnd) );
766 UserDrawCloseButton(hWnd,GetWindowDC(hWnd),TRUE);
778 SendMessageA(hWnd, WM_SYSCOMMAND, SC_SIZE + wParam - 2, lParam);
786 DefWndHandleLButtonDblClkNC(HWND hWnd, WPARAM wParam, LPARAM lParam)
792 DefWndHandleLButtonUpNC(HWND hWnd, WPARAM wParam, LPARAM lParam)
794 UserDrawMinButton(hWnd,GetWindowDC(hWnd),FALSE);
795 UserDrawMaxButton(hWnd,GetWindowDC(hWnd),FALSE);
796 UserDrawCloseButton(hWnd,GetWindowDC(hWnd),FALSE);
801 SendMessageA(hWnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
806 SendMessageA(hWnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
811 SendMessageA(hWnd, WM_CLOSE, 0, 0);
812 SendMessageA(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0);
820 DefWndHandleActiveNC(HWND hWnd, WPARAM wParam)
822 /* FIXME: Implement this. */
827 DefWndSetRedraw(HWND hWnd, WPARAM wParam)
832 DefWndHandleSetCursor(HWND hWnd, WPARAM wParam, LPARAM lParam)
834 /* Not for child windows. */
835 if (hWnd != (HWND)wParam)
840 switch(LOWORD(lParam))
844 WORD Msg = HIWORD(lParam);
845 if (Msg == WM_LBUTTONDOWN || Msg == WM_MBUTTONDOWN ||
846 Msg == WM_RBUTTONDOWN)
855 HICON hCursor = (HICON)GetClassLong(hWnd, GCL_HCURSOR);
867 return((LRESULT)SetCursor(LoadCursorW(0, IDC_SIZEWE)));
873 return((LRESULT)SetCursor(LoadCursorW(0, IDC_SIZENS)));
879 return((LRESULT)SetCursor(LoadCursorW(0, IDC_SIZENWSE)));
885 return((LRESULT)SetCursor(LoadCursorW(0, IDC_SIZENESW)));
888 return((LRESULT)SetCursor(LoadCursorW(0, IDC_ARROW)));
892 DefWndHandleSysCommand(HWND hWnd, WPARAM wParam, POINT Pt)
894 /* FIXME: Implement system commands. */
899 DefWndAdjustRect(RECT* Rect, ULONG Style, BOOL Menu, ULONG ExStyle)
901 if (Style & WS_ICONIC)
906 if (UserHasThickFrameStyle(Style, ExStyle))
908 InflateRect(Rect, GetSystemMetrics(SM_CXFRAME),
909 GetSystemMetrics(SM_CYFRAME));
911 else if (UserHasDlgFrameStyle(Style, ExStyle))
913 InflateRect(Rect, GetSystemMetrics(SM_CXDLGFRAME),
914 GetSystemMetrics(SM_CYDLGFRAME));
916 else if (UserHasThinFrameStyle(Style, ExStyle))
918 InflateRect(Rect, GetSystemMetrics(SM_CXBORDER),
919 GetSystemMetrics(SM_CYBORDER));
921 if (Style & WS_CAPTION)
923 Rect->top -= GetSystemMetrics(SM_CYCAPTION) -
924 GetSystemMetrics(SM_CYBORDER);
928 Rect->top -= GetSystemMetrics(SM_CYMENU) + GetSystemMetrics(SM_CYBORDER);
930 if (Style & WS_VSCROLL)
932 Rect->right += GetSystemMetrics(SM_CXVSCROLL) - 1;
933 if (UserHasAnyFrameStyle(Style, ExStyle))
938 if (Style & WS_HSCROLL)
940 Rect->bottom += GetSystemMetrics(SM_CYHSCROLL) - 1;
941 if (UserHasAnyFrameStyle(Style, ExStyle))
949 DefWndNCCalcSize(HWND hWnd, RECT* Rect)
952 LONG Style = GetClassLongW(hWnd, GCL_STYLE);
953 RECT TmpRect = {0, 0, 0, 0};
955 if (Style & CS_VREDRAW)
957 Result |= WVR_VREDRAW;
959 if (Style & CS_HREDRAW)
961 Result |= WVR_HREDRAW;
964 if (!(GetWindowLong(hWnd, GWL_STYLE) & WS_MINIMIZE))
966 DefWndAdjustRect(&TmpRect, GetWindowLong(hWnd, GWL_STYLE),
967 FALSE, GetWindowLong(hWnd, GWL_EXSTYLE));
968 Rect->left -= TmpRect.left;
969 Rect->top -= TmpRect.top;
970 Rect->right -= TmpRect.right;
971 Rect->bottom -= TmpRect.bottom;
972 /* FIXME: Adjust if the window has a menu. */
973 Rect->bottom = max(Rect->top, Rect->bottom);
974 Rect->right = max(Rect->left, Rect->right);
980 DefWndHandleWindowPosChanging(HWND hWnd, WINDOWPOS* Pos)
986 User32DefWindowProc(HWND hWnd,
996 return(DefWndPaintNC(hWnd, (HRGN)wParam));
998 case WM_WINDOWPOSCHANGING:
1000 DbgPrint("WM_WINDOWPOSCHANGING\n\n");
1005 Point.x = SLOWORD(lParam);
1006 Point.y = SHIWORD(lParam);
1007 return(DefWndHitTestNC(hWnd, Point));
1010 case WM_NCLBUTTONDOWN:
1012 return(DefWndHandleLButtonDownNC(hWnd, wParam, lParam));
1015 case WM_NCLBUTTONUP:
1017 return(DefWndHandleLButtonUpNC(hWnd, wParam, lParam));
1020 case WM_LBUTTONDBLCLK:
1021 case WM_NCLBUTTONDBLCLK:
1023 return(DefWndHandleLButtonDblClkNC(hWnd, wParam, lParam));
1026 case WM_NCRBUTTONDOWN:
1028 if (wParam == HTCAPTION)
1041 if (hWnd == GetCapture())
1045 Pt.x = SLOWORD(lParam);
1046 Pt.y = SHIWORD(lParam);
1047 ClientToScreen(hWnd, &Pt);
1048 lParam = MAKELPARAM(Pt.x, Pt.y);
1051 SendMessageW(hWnd, WM_CONTEXTMENU, (WPARAM)hWnd, lParam);
1055 SendMessageA (hWnd, WM_CONTEXTMENU, (WPARAM)hWnd, lParam);
1060 case WM_NCRBUTTONUP:
1062 /* Wine does nothing here. */
1066 case WM_CONTEXTMENU:
1068 if (GetWindowLong(hWnd, GWL_STYLE) & WS_CHILD)
1072 SendMessageW(GetParent(hWnd), Msg, wParam, lParam);
1076 SendMessageA(hWnd, WM_CONTEXTMENU, wParam, lParam);
1084 Pt.x = SLOWORD(lParam);
1085 Pt.y = SHIWORD(lParam);
1087 if (GetWindowLong(hWnd, GWL_STYLE) & WS_CHILD)
1089 ScreenToClient(GetParent(hWnd), &Pt);
1092 HitCode = DefWndHitTestNC(hWnd, Pt);
1094 if (HitCode == HTCAPTION || HitCode == HTSYSMENU)
1096 TrackPopupMenu(GetSystemMenu(hWnd, FALSE),
1097 TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
1098 Pt.x, Pt.y, 0, hWnd, NULL);
1106 return(DefWndHandleActiveNC(hWnd, wParam));
1123 HDC hDC = BeginPaint(hWnd, &Ps);
1128 if (GetWindowLongW(hWnd, GWL_STYLE) & WS_MINIMIZE &&
1129 (hIcon = (HICON)GetClassLongW(hWnd, GCL_HICON)) != NULL)
1133 GetWindowRect(hWnd, &WindowRect);
1134 x = (WindowRect.right - WindowRect.left -
1135 GetSystemMetrics(SM_CXICON)) / 2;
1136 y = (WindowRect.bottom - WindowRect.top -
1137 GetSystemMetrics(SM_CYICON)) / 2;
1138 DrawIcon(hDC, x, y, hIcon);
1140 EndPaint(hWnd, &Ps);
1148 hRgn = CreateRectRgn(0, 0, 0, 0);
1149 if (GetUpdateRgn(hWnd, hRgn, FALSE) != NULLREGION)
1151 RedrawWindow(hWnd, NULL, hRgn,
1152 RDW_ERASENOW | RDW_ERASE | RDW_FRAME |
1161 DefWndSetRedraw(hWnd, wParam);
1167 DestroyWindow(hWnd);
1171 case WM_MOUSEACTIVATE:
1173 if (GetWindowLong(hWnd, GWL_STYLE) & WS_CHILD)
1178 Ret = SendMessageW(GetParent(hWnd), WM_MOUSEACTIVATE,
1183 Ret = SendMessageA(GetParent(hWnd), WM_MOUSEACTIVATE,
1191 return((LOWORD(lParam) >= HTCLIENT) ? MA_ACTIVATE : MA_NOACTIVATE);
1196 if (LOWORD(lParam) != WA_INACTIVE &&
1197 GetWindowLong(hWnd, GWL_STYLE) & WS_MINIMIZE)
1199 /* Check if the window is minimized. */
1207 if (GetWindowLong(hWnd, GWL_STYLE & WS_CHILD))
1211 return(SendMessageW(GetParent(hWnd), WM_MOUSEWHEEL,
1216 return(SendMessageA(GetParent(hWnd), WM_MOUSEWHEEL,
1224 case WM_ICONERASEBKGND:
1228 HBRUSH hBrush = (HBRUSH)GetClassLongW(hWnd, GCL_HBRBACKGROUND);
1229 GetClipBox((HDC)wParam, &Rect);
1230 FillRect((HDC)wParam, &Rect, hBrush);
1239 /* FIXME: Implement colour controls. */
1243 if (GetWindowLong(hWnd, GWL_STYLE) & WS_CHILD)
1245 if (LOWORD(lParam) < HTLEFT || LOWORD(lParam) > HTBOTTOMRIGHT)
1250 bResult = SendMessageW(GetParent(hWnd), WM_SETCURSOR,
1255 bResult = SendMessageA(GetParent(hWnd), WM_SETCURSOR,
1264 return(DefWndHandleSetCursor(hWnd, wParam, lParam));
1270 Pt.x = SLOWORD(lParam);
1271 Pt.y = SHIWORD(lParam);
1272 return(DefWndHandleSysCommand(hWnd, wParam, Pt));
1275 /* FIXME: Handle key messages. */
1283 /* FIXME: Not done correctly */
1284 if ((GetWindowLongW(hWnd, GWL_STYLE) & WS_VISIBLE && !wParam) ||
1285 (!(GetWindowLongW(hWnd, GWL_STYLE) & WS_VISIBLE) && wParam))
1289 ShowWindow(hWnd, wParam ? SW_SHOWNA : SW_HIDE);
1295 /* FIXME: Check for a desktop. */
1296 if (GetCapture() == hWnd)
1308 /* FIXME: Implement this. */
1311 case WM_QUERYDROPOBJECT:
1313 if (GetWindowLongW(hWnd, GWL_EXSTYLE) & WS_EX_ACCEPTFILES)
1320 case WM_QUERYDRAGICON:
1325 hIcon = (HICON)GetClassLongW(hWnd, GCL_HICON);
1328 return((LRESULT)hIcon);
1330 for (Len = 1; Len < 64; Len++)
1332 if ((hIcon = LoadIconW(NULL, MAKEINTRESOURCE(Len))) != NULL)
1334 return((LRESULT)hIcon);
1337 return((LRESULT)LoadIconW(0, IDI_APPLICATION));
1340 /* FIXME: WM_ISACTIVEICON */
1342 case WM_NOTIFYFORMAT:
1344 if (IsWindowUnicode(hWnd))
1346 return(NFR_UNICODE);
1356 INT Index = (wParam != 0) ? GCL_HICON : GCL_HICONSM;
1357 HICON hOldIcon = (HICON)GetClassLongW(hWnd, Index);
1358 SetClassLongW(hWnd, Index, lParam);
1359 SetWindowPos(hWnd, 0, 0, 0, 0, 0,
1360 SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE |
1361 SWP_NOACTIVATE | SWP_NOZORDER);
1362 return((LRESULT)hOldIcon);
1367 INT Index = (wParam != 0) ? GCL_HICON : GCL_HICONSM;
1368 return(GetClassLongW(hWnd, Index));
1375 SendMessageW(GetParent(hWnd), Msg, wParam, lParam);
1379 SendMessageA(GetParent(hWnd), Msg, wParam, lParam);
1388 DefWindowProcA(HWND hWnd,
1394 static LPSTR WindowTextAtom = 0;
1401 CREATESTRUCTA* Cs = (CREATESTRUCTA*)lParam;
1402 if (HIWORD(Cs->lpszName))
1405 (LPSTR)(ULONG)GlobalAddAtomA("USER32!WindowTextAtomA");
1406 WindowText = RtlAllocateHeap(RtlGetProcessHeap(), 0,
1407 strlen(Cs->lpszName) * sizeof(CHAR));
1408 strcpy(WindowText, Cs->lpszName);
1409 SetPropA(hWnd, WindowTextAtom, WindowText);
1416 return(DefWndNCCalcSize(hWnd, (RECT*)lParam));
1419 case WM_WINDOWPOSCHANGING:
1421 return(DefWndHandleWindowPosChanging(hWnd, (WINDOWPOS*)lParam));
1424 case WM_GETTEXTLENGTH:
1426 if (WindowTextAtom == 0 ||
1427 (WindowText = GetPropA(hWnd, WindowTextAtom)) == NULL)
1431 return(strlen(WindowText));
1436 if (WindowTextAtom == 0 ||
1437 (WindowText = GetPropA(hWnd, WindowTextAtom)) == NULL)
1441 ((PSTR)lParam) = '\0';
1445 strncpy((LPSTR)lParam, WindowText, wParam);
1446 return(min(wParam, strlen(WindowText)));
1451 if (WindowTextAtom != 0)
1454 (LPSTR)(DWORD)GlobalAddAtomA("USER32!WindowTextAtomW");
1456 if (WindowTextAtom != 0 &&
1457 (WindowText = GetPropA(hWnd, WindowTextAtom)) == NULL)
1459 RtlFreeHeap(RtlGetProcessHeap(), 0, WindowText);
1461 WindowText = RtlAllocateHeap(RtlGetProcessHeap(), 0,
1462 strlen((PSTR)lParam) * sizeof(CHAR));
1463 strcpy(WindowText, (PSTR)lParam);
1464 SetPropA(hWnd, WindowTextAtom, WindowText);
1469 if (WindowTextAtom != 0 &&
1470 (WindowText = RemovePropA(hWnd, WindowTextAtom)) == NULL)
1472 RtlFreeHeap(GetProcessHeap(), 0, WindowText);
1474 if (WindowTextAtom != 0)
1476 GlobalDeleteAtom((ATOM)(ULONG)WindowTextAtom);
1482 Result = User32DefWindowProc(hWnd, Msg, wParam, lParam, FALSE);
1490 DefWindowProcW(HWND hWnd,
1496 static LPWSTR WindowTextAtom = 0;
1503 CREATESTRUCTW* Cs = (CREATESTRUCTW*)lParam;
1504 if (HIWORD(Cs->lpszName))
1507 (LPWSTR)(DWORD)GlobalAddAtomW(L"USER32!WindowTextAtomW");
1508 WindowText = RtlAllocateHeap(RtlGetProcessHeap(), 0,
1509 wcslen(Cs->lpszName) * sizeof(WCHAR));
1510 wcscpy(WindowText, Cs->lpszName);
1511 SetPropW(hWnd, WindowTextAtom, WindowText);
1518 return(DefWndNCCalcSize(hWnd, (RECT*)lParam));
1521 case WM_WINDOWPOSCHANGING:
1523 return(DefWndHandleWindowPosChanging(hWnd, (WINDOWPOS*)lParam));
1526 case WM_GETTEXTLENGTH:
1528 if (WindowTextAtom == 0 ||
1529 (WindowText = GetPropW(hWnd, WindowTextAtom)) == NULL)
1533 return(wcslen(WindowText));
1538 if (WindowTextAtom == 0 ||
1539 (WindowText = GetPropW(hWnd, WindowTextAtom)) == NULL)
1543 ((PWSTR)lParam) = '\0';
1547 wcsncpy((PWSTR)lParam, WindowText, wParam);
1548 return(min(wParam, wcslen(WindowText)));
1553 if (WindowTextAtom != 0)
1556 (LPWSTR)(DWORD)GlobalAddAtom(L"USER32!WindowTextAtomW");
1558 if (WindowTextAtom != 0 &&
1559 (WindowText = GetPropW(hWnd, WindowTextAtom)) == NULL)
1561 RtlFreeHeap(RtlGetProcessHeap(), 0, WindowText);
1563 WindowText = RtlAllocateHeap(RtlGetProcessHeap(), 0,
1564 wcslen((PWSTR)lParam) * sizeof(WCHAR));
1565 wcscpy(WindowText, (PWSTR)lParam);
1566 SetPropW(hWnd, WindowTextAtom, WindowText);
1568 //FIXME: return correct code
1573 if (WindowTextAtom != 0 &&
1574 (WindowText = RemovePropW(hWnd, WindowTextAtom)) == NULL)
1576 RtlFreeHeap(RtlGetProcessHeap(), 0, WindowText);
1578 if (WindowTextAtom != 0)
1580 GlobalDeleteAtom((ATOM)(DWORD)WindowTextAtom);
1587 Result = User32DefWindowProc(hWnd, Msg, wParam, lParam, TRUE);