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 hbitmapClose;
24 static HBITMAP hbitmapMinimize;
25 static HBITMAP hbitmapMinimizeD;
26 static HBITMAP hbitmapMaximize;
27 static HBITMAP hbitmapMaximizeD;
28 static HBITMAP hbitmapRestore;
29 static HBITMAP hbitmapRestoreD;
31 static COLORREF SysColours[] =
33 RGB(224, 224, 224) /* COLOR_SCROLLBAR */,
34 RGB(192, 192, 192) /* COLOR_BACKGROUND */,
35 RGB(0, 64, 128) /* COLOR_ACTIVECAPTION */,
36 RGB(255, 255, 255) /* COLOR_INACTIVECAPTION */,
37 RGB(255, 255, 255) /* COLOR_MENU */,
38 RGB(255, 255, 255) /* COLOR_WINDOW */,
39 RGB(0, 0, 0) /* COLOR_WINDOWFRAME */,
40 RGB(0, 0, 0) /* COLOR_MENUTEXT */,
41 RGB(0, 0, 0) /* COLOR_WINDOWTEXT */,
42 RGB(255, 255, 255) /* COLOR_CAPTIONTEXT */,
43 RGB(128, 128, 128) /* COLOR_ACTIVEBORDER */,
44 RGB(255, 255, 255) /* COLOR_INACTIVEBORDER */,
45 RGB(255, 255, 232) /* COLOR_APPWORKSPACE */,
46 RGB(224, 224, 224) /* COLOR_HILIGHT */,
47 RGB(0, 0, 0) /* COLOR_HILIGHTTEXT */,
48 RGB(192, 192, 192) /* COLOR_BTNFACE */,
49 RGB(128, 128, 128) /* COLOR_BTNSHADOW */,
50 RGB(192, 192, 192) /* COLOR_GRAYTEXT */,
51 RGB(0, 0, 0) /* COLOR_BTNTEXT */,
52 RGB(0, 0, 0) /* COLOR_INACTIVECAPTIONTEXT */,
53 RGB(255, 255, 255) /* COLOR_BTNHILIGHT */,
54 RGB(32, 32, 32) /* COLOR_3DDKSHADOW */,
55 RGB(192, 192, 192) /* COLOR_3DLIGHT */,
56 RGB(0, 0, 0) /* COLOR_INFOTEXT */,
57 RGB(255, 255, 192) /* COLOR_INFOBK */,
58 RGB(184, 180, 184) /* COLOR_ALTERNATEBTNFACE */,
59 RGB(0, 0, 255) /* COLOR_HOTLIGHT */,
60 RGB(16, 132, 208) /* COLOR_GRADIENTACTIVECAPTION */,
61 RGB(181, 181, 181) /* COLOR_GRADIENTINACTIVECAPTION */,
64 static ATOM AtomInternalPos;
66 /* FUNCTIONS *****************************************************************/
69 UserSetupInternalPos(VOID)
72 AtomInternalPos = GlobalAddAtomA(Str);
75 /* ReactOS extension */
77 GetSysColorPen(int nIndex)
79 return(CreatePen(PS_SOLID, 1, SysColours[nIndex]));
83 GetSysColorBrush(int nIndex)
85 return(CreateSolidBrush(SysColours[nIndex]));
90 DefFrameProcA(HWND hWnd,
100 DefFrameProcW(HWND hWnd,
111 DefWndRedrawIconTitle(HWND hWnd)
113 PINTERNALPOS lpPos = (PINTERNALPOS)GetPropA(hWnd,
114 (LPSTR)(DWORD)AtomInternalPos);
117 if (lpPos->IconTitle != NULL)
119 SendMessageA(lpPos->IconTitle, WM_SHOWWINDOW, TRUE, 0);
120 InvalidateRect(lpPos->IconTitle, NULL, TRUE);
128 UserHasMenu(HWND hWnd, ULONG Style)
130 return(!(Style & WS_CHILD) && GetWindowLong(hWnd, GWL_ID) != 0);
134 UserHasAnyFrameStyle(ULONG Style, ULONG ExStyle)
136 return((Style & (WS_THICKFRAME | WS_DLGFRAME | WS_BORDER)) ||
137 (ExStyle & WS_EX_DLGMODALFRAME) ||
138 (!(Style & (WS_CHILD | WS_POPUP))));
142 UserHasDlgFrameStyle(ULONG Style, ULONG ExStyle)
144 return((ExStyle & WS_EX_DLGMODALFRAME) ||
145 ((Style & WS_DLGFRAME) && (!(Style & WS_THICKFRAME))));
149 UserHasThickFrameStyle(ULONG Style, ULONG ExStyle)
151 return((Style & WS_THICKFRAME) &&
152 (!((Style & (WS_DLGFRAME | WS_BORDER)) == WS_DLGFRAME)));
156 UserHasThinFrameStyle(ULONG Style, ULONG ExStyle)
158 return((Style & WS_BORDER) ||
159 (!(Style & (WS_CHILD | WS_POPUP))));
163 UserHasBigFrameStyle(ULONG Style, ULONG ExStyle)
165 return((Style & (WS_THICKFRAME | WS_DLGFRAME)) ||
166 (ExStyle & WS_EX_DLGMODALFRAME));
169 void UserGetInsideRectNC( HWND hwnd, RECT *rect )
175 Style = GetWindowLong(hwnd, GWL_STYLE);
176 ExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
177 GetWindowRect(hwnd, &WindowRect);
178 rect->top = rect->left = 0;
179 rect->right = WindowRect.right - WindowRect.left;
180 rect->bottom = WindowRect.bottom - WindowRect.top;
182 if (Style & WS_ICONIC)
187 /* Remove frame from rectangle */
188 if (UserHasThickFrameStyle(Style, ExStyle ))
190 InflateRect( rect, -GetSystemMetrics(SM_CXFRAME),
191 -GetSystemMetrics(SM_CYFRAME) );
195 if (UserHasDlgFrameStyle(Style, ExStyle ))
197 InflateRect( rect, -GetSystemMetrics(SM_CXDLGFRAME),
198 -GetSystemMetrics(SM_CYDLGFRAME));
199 /* FIXME: this isn't in NC_AdjustRect? why not? */
200 if (ExStyle & WS_EX_DLGMODALFRAME)
201 InflateRect( rect, -1, 0 );
205 if (UserHasThinFrameStyle(Style, ExStyle))
207 InflateRect(rect, -GetSystemMetrics(SM_CXBORDER),
208 -GetSystemMetrics(SM_CYBORDER));
214 void UserDrawSysButton( HWND hwnd, HDC hdc, BOOL down )
221 Style = GetWindowLong(hwnd, GWL_STYLE);
222 UserGetInsideRectNC( hwnd, &rect );
223 hdcMem = CreateCompatibleDC( hdc );
224 hbitmap = SelectObject( hdcMem, hbitmapClose );
225 BitBlt(hdc, rect.left, rect.top, GetSystemMetrics(SM_CXSIZE),
226 GetSystemMetrics(SM_CYSIZE), hdcMem,
227 (Style & WS_CHILD) ? GetSystemMetrics(SM_CXSIZE) : 0, 0,
228 down ? NOTSRCCOPY : SRCCOPY );
229 SelectObject( hdcMem, hbitmap );
233 static void UserDrawMaxButton( HWND hwnd, HDC hdc, BOOL down )
238 UserGetInsideRectNC( hwnd, &rect );
239 hdcMem = CreateCompatibleDC( hdc );
240 SelectObject( hdcMem, (IsZoomed(hwnd)
241 ? (down ? hbitmapRestoreD : hbitmapRestore)
242 : (down ? hbitmapMaximizeD : hbitmapMaximize)) );
243 BitBlt( hdc, rect.right - GetSystemMetrics(SM_CXSMSIZE) - 1, rect.top,
244 GetSystemMetrics(SM_CXSMSIZE) + 1, GetSystemMetrics(SM_CYSMSIZE), hdcMem, 0, 0,
249 static void UserDrawMinButton( HWND hwnd, HDC hdc, BOOL down)
254 UserGetInsideRectNC(hwnd, &rect);
255 hdcMem = CreateCompatibleDC(hdc);
256 SelectObject(hdcMem, (down ? hbitmapMinimizeD : hbitmapMinimize));
257 if (GetWindowLong(hwnd, GWL_STYLE) & WS_MAXIMIZEBOX)
259 rect.right -= GetSystemMetrics(SM_CXSMSIZE)+1;
261 BitBlt( hdc, rect.right - GetSystemMetrics(SM_CXSMSIZE) - 1, rect.top,
262 GetSystemMetrics(SM_CXSMSIZE) + 1, GetSystemMetrics(SM_CYSMSIZE),
268 static void UserDrawCaptionNC( HDC hdc, RECT *rect, HWND hwnd,
269 DWORD style, BOOL active )
276 hbitmapClose = LoadBitmapW( 0, MAKEINTRESOURCE(OBM_CLOSE));
277 hbitmapMinimize = LoadBitmapW( 0, MAKEINTRESOURCE(OBM_REDUCE) );
278 hbitmapMinimizeD = LoadBitmapW( 0, MAKEINTRESOURCE(OBM_REDUCED) );
279 hbitmapMaximize = LoadBitmapW( 0, MAKEINTRESOURCE(OBM_ZOOM) );
280 hbitmapMaximizeD = LoadBitmapW( 0, MAKEINTRESOURCE(OBM_ZOOMD) );
281 hbitmapRestore = LoadBitmapW( 0, MAKEINTRESOURCE(OBM_RESTORE) );
282 hbitmapRestoreD = LoadBitmapW( 0, MAKEINTRESOURCE(OBM_RESTORED) );
285 if (GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_DLGMODALFRAME)
287 HBRUSH hbrushOld = SelectObject(hdc, GetSysColorBrush(COLOR_WINDOW) );
288 PatBlt( hdc, r.left, r.top, 1, r.bottom-r.top+1,PATCOPY );
289 PatBlt( hdc, r.right-1, r.top, 1, r.bottom-r.top+1, PATCOPY );
290 PatBlt( hdc, r.left, r.top-1, r.right-r.left, 1, PATCOPY );
293 SelectObject( hdc, hbrushOld );
296 MoveToEx( hdc, r.left, r.bottom, NULL );
297 LineTo( hdc, r.right, r.bottom );
299 if (style & WS_SYSMENU)
301 UserDrawSysButton( hwnd, hdc, FALSE );
302 r.left += GetSystemMetrics(SM_CXSIZE) + 1;
303 MoveToEx( hdc, r.left - 1, r.top, NULL );
304 LineTo( hdc, r.left - 1, r.bottom );
306 if (style & WS_MAXIMIZEBOX)
308 UserDrawMaxButton( hwnd, hdc, FALSE );
309 r.right -= GetSystemMetrics(SM_CXSMSIZE) + 1;
311 if (style & WS_MINIMIZEBOX)
313 UserDrawMinButton( hwnd, hdc, FALSE );
314 r.right -= GetSystemMetrics(SM_CXSMSIZE) + 1;
317 FillRect( hdc, &r, GetSysColorBrush(active ? COLOR_ACTIVECAPTION :
318 COLOR_INACTIVECAPTION) );
320 if (GetWindowTextA( hwnd, buffer, sizeof(buffer) ))
322 NONCLIENTMETRICS nclm;
323 HFONT hFont, hOldFont;
325 nclm.cbSize = sizeof(NONCLIENTMETRICS);
326 SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, 0, &nclm, 0);
327 if (style & WS_EX_TOOLWINDOW)
328 hFont = CreateFontIndirectW(&nclm.lfSmCaptionFont);
330 hFont = CreateFontIndirectW(&nclm.lfCaptionFont);
331 hOldFont = SelectObject(hdc, hFont);
333 if (active) SetTextColor( hdc, GetSysColor( COLOR_CAPTIONTEXT ) );
334 else SetTextColor( hdc, GetSysColor( COLOR_INACTIVECAPTIONTEXT ) );
335 SetBkMode( hdc, TRANSPARENT );
336 /*DrawTextA( hdc, buffer, -1, &r,
337 DT_SINGLELINE | DT_CENTER | DT_VCENTER | DT_NOPREFIX );*/
338 TextOutA(hdc, r.left+5, r.top+2, buffer, strlen(buffer));
339 DeleteObject (SelectObject (hdc, hOldFont));
344 UserDrawFrameNC(HDC hdc, RECT* rect, BOOL dlgFrame, BOOL active)
350 width = GetSystemMetrics(SM_CXDLGFRAME) - 1;
351 height = GetSystemMetrics(SM_CYDLGFRAME) - 1;
352 SelectObject( hdc, GetSysColorBrush(active ? COLOR_ACTIVECAPTION :
353 COLOR_INACTIVECAPTION) );
357 width = GetSystemMetrics(SM_CXFRAME) - 2;
358 height = GetSystemMetrics(SM_CYFRAME) - 2;
359 SelectObject( hdc, GetSysColorBrush(active ? COLOR_ACTIVEBORDER :
360 COLOR_INACTIVEBORDER) );
364 PatBlt( hdc, rect->left, rect->top,
365 rect->right - rect->left, height, PATCOPY );
366 PatBlt( hdc, rect->left, rect->top,
367 width, rect->bottom - rect->top, PATCOPY );
368 PatBlt( hdc, rect->left, rect->bottom - 1,
369 rect->right - rect->left, -height, PATCOPY );
370 PatBlt( hdc, rect->right - 1, rect->top,
371 -width, rect->bottom - rect->top, PATCOPY );
375 InflateRect( rect, -width, -height );
379 INT decYOff = GetSystemMetrics(SM_CXFRAME) +
380 GetSystemMetrics(SM_CXSIZE) - 1;
381 INT decXOff = GetSystemMetrics(SM_CYFRAME) +
382 GetSystemMetrics(SM_CYSIZE) - 1;
384 /* Draw inner rectangle */
386 SelectObject( hdc, GetStockObject(NULL_BRUSH) );
387 Rectangle( hdc, rect->left + width, rect->top + height,
388 rect->right - width , rect->bottom - height );
390 /* Draw the decorations */
392 MoveToEx( hdc, rect->left, rect->top + decYOff, NULL );
393 LineTo( hdc, rect->left + width, rect->top + decYOff );
394 MoveToEx( hdc, rect->right - 1, rect->top + decYOff, NULL );
395 LineTo( hdc, rect->right - width - 1, rect->top + decYOff );
396 MoveToEx( hdc, rect->left, rect->bottom - decYOff, NULL );
397 LineTo( hdc, rect->left + width, rect->bottom - decYOff );
398 MoveToEx( hdc, rect->right - 1, rect->bottom - decYOff, NULL );
399 LineTo( hdc, rect->right - width - 1, rect->bottom - decYOff );
401 MoveToEx( hdc, rect->left + decXOff, rect->top, NULL );
402 LineTo( hdc, rect->left + decXOff, rect->top + height);
403 MoveToEx( hdc, rect->left + decXOff, rect->bottom - 1, NULL );
404 LineTo( hdc, rect->left + decXOff, rect->bottom - height - 1 );
405 MoveToEx( hdc, rect->right - decXOff, rect->top, NULL );
406 LineTo( hdc, rect->right - decXOff, rect->top + height );
407 MoveToEx( hdc, rect->right - decXOff, rect->bottom - 1, NULL );
408 LineTo( hdc, rect->right - decXOff, rect->bottom - height - 1 );
410 InflateRect( rect, -width - 1, -height - 1 );
414 void SCROLL_DrawScrollBar (HWND hwnd, HDC hdc, INT nBar, BOOL arrows, BOOL interior);
417 DefWndDoPaintNC(HWND hWnd, HRGN clip)
425 Active = GetWindowLongW(hWnd, GWL_STYLE) & WIN_NCACTIVATED;
426 Style = GetWindowLong(hWnd, GWL_STYLE);
427 ExStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
429 hDc = GetDCEx(hWnd, (clip > (HRGN)1) ? clip : 0, DCX_USESTYLE | DCX_WINDOW |
430 ((clip > (HRGN)1) ? (DCX_INTERSECTRGN | DCX_KEEPCLIPRGN) : 0));
436 /* FIXME: Test whether we need to draw anything at all. */
438 GetWindowRect(hWnd, &rect);
439 rect.right = rect.right - rect.left;
440 rect.bottom = rect.bottom - rect.top;
441 rect.top = rect.left = 0;
443 SelectObject(hDc, GetSysColorPen(COLOR_WINDOWFRAME));
444 if (UserHasAnyFrameStyle(Style, ExStyle))
446 SelectObject(hDc, GetStockObject(NULL_BRUSH));
447 Rectangle(hDc, 0, 0, rect.right, rect.bottom);
448 InflateRect(&rect, -1, -1);
451 if (UserHasThickFrameStyle(Style, ExStyle))
453 UserDrawFrameNC(hDc, &rect, FALSE, Active);
455 else if (UserHasDlgFrameStyle(Style, ExStyle))
457 UserDrawFrameNC(hDc, &rect, TRUE, Active);
460 if (Style & WS_CAPTION)
463 r.bottom = rect.top + GetSystemMetrics(SM_CYSIZE);
464 rect.top += GetSystemMetrics(SM_CYSIZE) +
465 GetSystemMetrics(SM_CYBORDER);
466 UserDrawCaptionNC(hDc, &r, hWnd, Style, Active);
469 /* FIXME: Draw menu bar. */
471 DbgPrint("drawing scrollbars..\n");
472 /* Draw scrollbars */
473 if (Style & WS_VSCROLL)
474 SCROLL_DrawScrollBar(hWnd, hDc, SB_VERT, TRUE, TRUE);
475 if (Style & WS_HSCROLL)
476 SCROLL_DrawScrollBar(hWnd, hDc, SB_HORZ, TRUE, TRUE);
478 /* FIXME: Draw size box. */
480 ReleaseDC(hWnd, hDc);
484 DefWndPaintNC(HWND hWnd, HRGN clip)
486 if (IsWindowVisible(hWnd))
490 DefWndRedrawIconTitle(hWnd);
494 DefWndDoPaintNC(hWnd, clip);
501 DefWndHitTestNC(HWND hWnd, POINT Point)
504 ULONG Style = GetWindowLong(hWnd, GWL_STYLE);
505 ULONG ExStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
507 GetWindowRect(hWnd, &WindowRect);
509 if (!PtInRect(&WindowRect, Point))
513 if (Style & WS_MINIMIZE)
517 if (UserHasThickFrameStyle(Style, ExStyle))
519 InflateRect(&WindowRect, -GetSystemMetrics(SM_CXFRAME),
520 -GetSystemMetrics(SM_CYFRAME));
521 if (!PtInRect(&WindowRect, Point))
523 if (Point.y < WindowRect.top)
525 if (Point.x < (WindowRect.left + GetSystemMetrics(SM_CXSIZE)))
529 if (Point.x >= (WindowRect.right - GetSystemMetrics(SM_CXSIZE)))
535 if (Point.y >= WindowRect.bottom)
537 if (Point.x < (WindowRect.left + GetSystemMetrics(SM_CXSIZE)))
539 return(HTBOTTOMLEFT);
541 if (Point.x >= (WindowRect.right - GetSystemMetrics(SM_CXSIZE)))
543 return(HTBOTTOMRIGHT);
547 if (Point.x < WindowRect.left)
549 if (Point.y < (WindowRect.top + GetSystemMetrics(SM_CYSIZE)))
553 if (Point.y >= (WindowRect.bottom - GetSystemMetrics(SM_CYSIZE)))
555 return(HTBOTTOMLEFT);
559 if (Point.x >= WindowRect.right)
561 if (Point.y < (WindowRect.top + GetSystemMetrics(SM_CYSIZE)))
565 if (Point.y >= (WindowRect.bottom - GetSystemMetrics(SM_CYSIZE)))
567 return(HTBOTTOMRIGHT);
575 if (UserHasDlgFrameStyle(Style, ExStyle))
577 InflateRect(&WindowRect, -GetSystemMetrics(SM_CXDLGFRAME),
578 -GetSystemMetrics(SM_CYDLGFRAME));
580 else if (UserHasThinFrameStyle(Style, ExStyle))
582 InflateRect(&WindowRect, -GetSystemMetrics(SM_CXBORDER),
583 -GetSystemMetrics(SM_CYBORDER));
585 if (!PtInRect(&WindowRect, Point))
591 if ((Style & WS_CAPTION) == WS_CAPTION)
593 WindowRect.top += GetSystemMetrics(SM_CYCAPTION) -
594 GetSystemMetrics(SM_CYBORDER);
595 if (!PtInRect(&WindowRect, Point))
597 if ((Style & WS_SYSMENU) && !(ExStyle & WS_EX_TOOLWINDOW))
599 WindowRect.left += GetSystemMetrics(SM_CXSIZE);
601 if (Point.x <= WindowRect.left)
606 if (Style & WS_MAXIMIZEBOX)
608 WindowRect.right -= GetSystemMetrics(SM_CXSMSIZE) + 1;
610 if (Point.x >= WindowRect.right)
615 if (Style & WS_MINIMIZEBOX)
617 WindowRect.right -= GetSystemMetrics(SM_CXSMSIZE) + 1;
619 if (Point.x >= WindowRect.right)
627 ScreenToClient(hWnd, &Point);
628 GetClientRect(hWnd, &WindowRect);
630 if (PtInRect(&WindowRect, Point))
635 if (Style & WS_VSCROLL)
637 WindowRect.right += GetSystemMetrics(SM_CXVSCROLL);
638 if (PtInRect(&WindowRect, Point))
644 if (Style & WS_HSCROLL)
646 WindowRect.bottom += GetSystemMetrics(SM_CYHSCROLL);
647 if (PtInRect(&WindowRect, Point))
649 if ((Style & WS_VSCROLL) &&
650 (Point.x >= (WindowRect.right - GetSystemMetrics(SM_CXVSCROLL))))
658 if (UserHasMenu(hWnd, Style))
660 if (Point.y < 0 && Point.x >= 0 && Point.x <= WindowRect.right)
670 DefWndTrackMinMaxBox(HWND hWnd, WPARAM wParam)
672 HDC hDC = GetWindowDC(hWnd);
678 if (wParam == HTMINBUTTON)
680 UserDrawMinButton(hWnd, hDC, TRUE);
684 UserDrawMaxButton(hWnd, hDC, TRUE);
689 BOOL OldState = Pressed;
691 GetMessageA(hWnd, &Msg, 0, 0);
692 if (Msg.message == WM_LBUTTONUP)
696 if (Msg.message != WM_MOUSEMOVE)
701 Pressed = DefWndHitTestNC(hWnd, Msg.pt) == (LRESULT) wParam;
702 if (Pressed != OldState)
704 if (wParam == HTMINBUTTON)
706 UserDrawMinButton(hWnd, hDC, Pressed);
710 UserDrawMaxButton(hWnd, hDC, Pressed);
717 if (wParam == HTMINBUTTON)
719 UserDrawMinButton(hWnd, hDC, FALSE);
723 UserDrawMaxButton(hWnd, hDC, FALSE);
728 ReleaseDC(hWnd, hDC);
735 if (wParam == HTMINBUTTON)
737 SendMessageA(hWnd, WM_SYSCOMMAND, SC_MINIMIZE,
738 MAKELONG(Msg.pt.x, Msg.pt.y));
742 SendMessageA(hWnd, WM_SYSCOMMAND,
743 IsZoomed(hWnd) ? SC_RESTORE : SC_MAXIMIZE,
744 MAKELONG(Msg.pt.x, Msg.pt.y));
749 DefWndDrawSysButton(HWND hWnd, HDC hDC, BOOL Down)
753 HBITMAP hSavedBitmap;
755 UserGetInsideRectNC(hWnd, &Rect);
756 hDcMem = CreateCompatibleDC(hDC);
757 hSavedBitmap = SelectObject(hDcMem, hbitmapClose);
758 BitBlt(hDC, Rect.left, Rect.top, GetSystemMetrics(SM_CXSIZE),
759 GetSystemMetrics(SM_CYSIZE), hDcMem,
760 (GetWindowLong(hWnd, GWL_STYLE) & WS_CHILD) ?
761 GetSystemMetrics(SM_CXSIZE): 0, 0, Down ? NOTSRCCOPY : SRCCOPY);
762 SelectObject(hDcMem, hSavedBitmap);
767 DefWndHandleLButtonDownNC(HWND hWnd, WPARAM wParam, LPARAM lParam)
773 HWND hTopWnd = GetAncestor(hWnd, GA_ROOT);
774 if (SetActiveWindow(hTopWnd) || GetActiveWindow() == hTopWnd)
776 SendMessageA(hWnd, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, lParam);
782 if (GetWindowLong(hWnd, GWL_STYLE) & WS_SYSMENU)
784 if (!(GetWindowLong(hWnd, GWL_STYLE) & WS_MINIMIZE))
786 HDC hDC = GetWindowDC(hWnd);
787 DefWndDrawSysButton(hWnd, hDC, TRUE);
788 ReleaseDC(hWnd, hDC);
790 SendMessageA(hWnd, WM_SYSCOMMAND, SC_MOUSEMENU + HTSYSMENU,
797 SendMessageA(hWnd, WM_SYSCOMMAND, SC_MOUSEMENU, lParam);
801 SendMessageA(hWnd, WM_SYSCOMMAND, SC_HSCROLL + HTHSCROLL, lParam);
805 SendMessageA(hWnd, WM_SYSCOMMAND, SC_VSCROLL + HTVSCROLL, lParam);
810 DefWndTrackMinMaxBox(hWnd, wParam);
821 SendMessageA(hWnd, WM_SYSCOMMAND, SC_SIZE + wParam - 2, lParam);
828 DefWndHandleLButtonDblClkNC(HWND hWnd, WPARAM wParam, LPARAM lParam)
830 /* FIXME: Implement this. */
835 DefWndHandleActiveNC(HWND hWnd, WPARAM wParam)
837 /* FIXME: Implement this. */
842 DefWndSetRedraw(HWND hWnd, WPARAM wParam)
847 DefWndHandleSetCursor(HWND hWnd, WPARAM wParam, LPARAM lParam)
849 /* Not for child windows. */
850 if (hWnd != (HWND)wParam)
855 switch(LOWORD(lParam))
859 WORD Msg = HIWORD(lParam);
860 if (Msg == WM_LBUTTONDOWN || Msg == WM_MBUTTONDOWN ||
861 Msg == WM_RBUTTONDOWN)
870 HICON hCursor = (HICON)GetClassLong(hWnd, GCL_HCURSOR);
882 return((LRESULT)SetCursor(LoadCursorW(0, IDC_SIZEWE)));
888 return((LRESULT)SetCursor(LoadCursorW(0, IDC_SIZENS)));
894 return((LRESULT)SetCursor(LoadCursorW(0, IDC_SIZENWSE)));
900 return((LRESULT)SetCursor(LoadCursorW(0, IDC_SIZENESW)));
903 return((LRESULT)SetCursor(LoadCursorW(0, IDC_ARROW)));
907 DefWndHandleSysCommand(HWND hWnd, WPARAM wParam, POINT Pt)
909 /* FIXME: Implement system commands. */
914 DefWndAdjustRect(RECT* Rect, ULONG Style, BOOL Menu, ULONG ExStyle)
916 if (Style & WS_ICONIC)
921 if (UserHasThickFrameStyle(Style, ExStyle))
923 InflateRect(Rect, GetSystemMetrics(SM_CXFRAME),
924 GetSystemMetrics(SM_CYFRAME));
926 else if (UserHasDlgFrameStyle(Style, ExStyle))
928 InflateRect(Rect, GetSystemMetrics(SM_CXDLGFRAME),
929 GetSystemMetrics(SM_CYDLGFRAME));
931 else if (UserHasThinFrameStyle(Style, ExStyle))
933 InflateRect(Rect, GetSystemMetrics(SM_CXBORDER),
934 GetSystemMetrics(SM_CYBORDER));
936 if (Style & WS_CAPTION)
938 Rect->top -= GetSystemMetrics(SM_CYCAPTION) -
939 GetSystemMetrics(SM_CYBORDER);
943 Rect->top -= GetSystemMetrics(SM_CYMENU) + GetSystemMetrics(SM_CYBORDER);
945 if (Style & WS_VSCROLL)
947 Rect->right += GetSystemMetrics(SM_CXVSCROLL) - 1;
948 if (UserHasAnyFrameStyle(Style, ExStyle))
953 if (Style & WS_HSCROLL)
955 Rect->bottom += GetSystemMetrics(SM_CYHSCROLL) - 1;
956 if (UserHasAnyFrameStyle(Style, ExStyle))
964 DefWndNCCalcSize(HWND hWnd, RECT* Rect)
967 LONG Style = GetClassLongW(hWnd, GCL_STYLE);
968 RECT TmpRect = {0, 0, 0, 0};
970 if (Style & CS_VREDRAW)
972 Result |= WVR_VREDRAW;
974 if (Style & CS_HREDRAW)
976 Result |= WVR_HREDRAW;
979 if (!(GetWindowLong(hWnd, GWL_STYLE) & WS_MINIMIZE))
981 DefWndAdjustRect(&TmpRect, GetWindowLong(hWnd, GWL_STYLE),
982 FALSE, GetWindowLong(hWnd, GWL_EXSTYLE));
983 Rect->left -= TmpRect.left;
984 Rect->top -= TmpRect.top;
985 Rect->right -= TmpRect.right;
986 Rect->bottom -= TmpRect.bottom;
987 /* FIXME: Adjust if the window has a menu. */
988 Rect->bottom = max(Rect->top, Rect->bottom);
989 Rect->right = max(Rect->left, Rect->right);
995 DefWndHandleWindowPosChanging(HWND hWnd, WINDOWPOS* Pos)
997 /* FIXME: Implement this. */
1002 User32DefWindowProc(HWND hWnd,
1012 return(DefWndPaintNC(hWnd, (HRGN)wParam));
1018 Point.x = SLOWORD(lParam);
1019 Point.y = SHIWORD(lParam);
1020 return(DefWndHitTestNC(hWnd, Point));
1023 case WM_NCLBUTTONDOWN:
1025 return(DefWndHandleLButtonDownNC(hWnd, wParam, lParam));
1028 case WM_LBUTTONDBLCLK:
1029 case WM_NCLBUTTONDBLCLK:
1031 return(DefWndHandleLButtonDblClkNC(hWnd, wParam, lParam));
1034 case WM_NCRBUTTONDOWN:
1036 if (wParam == HTCAPTION)
1046 if (hWnd == GetCapture())
1050 Pt.x = SLOWORD(lParam);
1051 Pt.y = SHIWORD(lParam);
1052 ClientToScreen(hWnd, &Pt);
1053 lParam = MAKELPARAM(Pt.x, Pt.y);
1056 SendMessageW(hWnd, WM_CONTEXTMENU, (WPARAM)hWnd, lParam);
1060 SendMessageA (hWnd, WM_CONTEXTMENU, (WPARAM)hWnd, lParam);
1065 case WM_NCRBUTTONUP:
1067 /* Wine does nothing here. */
1071 case WM_CONTEXTMENU:
1073 if (GetWindowLong(hWnd, GWL_STYLE) & WS_CHILD)
1077 SendMessageW(GetParent(hWnd), Msg, wParam, lParam);
1081 SendMessageA(hWnd, WM_CONTEXTMENU, wParam, lParam);
1089 Pt.x = SLOWORD(lParam);
1090 Pt.y = SHIWORD(lParam);
1092 if (GetWindowLong(hWnd, GWL_STYLE) & WS_CHILD)
1094 ScreenToClient(GetParent(hWnd), &Pt);
1097 HitCode = DefWndHitTestNC(hWnd, Pt);
1099 if (HitCode == HTCAPTION || HitCode == HTSYSMENU)
1101 TrackPopupMenu(GetSystemMenu(hWnd, FALSE),
1102 TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
1103 Pt.x, Pt.y, 0, hWnd, NULL);
1111 return(DefWndHandleActiveNC(hWnd, wParam));
1128 HDC hDc = BeginPaint(hWnd, &Ps);
1132 if (GetWindowLongW(hWnd, GWL_STYLE) & WS_MINIMIZE &&
1133 (hIcon = (HICON)GetClassLongW(hWnd, GCL_HICON)) != NULL)
1137 GetWindowRect(hWnd, &WindowRect);
1138 x = (WindowRect.right - WindowRect.left -
1139 GetSystemMetrics(SM_CXICON)) / 2;
1140 y = (WindowRect.bottom - WindowRect.top -
1141 GetSystemMetrics(SM_CYICON)) / 2;
1142 DrawIcon(hDc, x, y, hIcon);
1144 EndPaint(hWnd, &Ps);
1152 hRgn = CreateRectRgn(0, 0, 0, 0);
1153 if (GetUpdateRgn(hWnd, hRgn, FALSE) != NULLREGION)
1155 RedrawWindow(hWnd, NULL, hRgn,
1156 RDW_ERASENOW | RDW_ERASE | RDW_FRAME |
1165 DefWndSetRedraw(hWnd, wParam);
1171 DestroyWindow(hWnd);
1175 case WM_MOUSEACTIVATE:
1177 if (GetWindowLong(hWnd, GWL_STYLE) & WS_CHILD)
1182 Ret = SendMessageW(GetParent(hWnd), WM_MOUSEACTIVATE,
1187 Ret = SendMessageA(GetParent(hWnd), WM_MOUSEACTIVATE,
1195 return((LOWORD(lParam) >= HTCLIENT) ? MA_ACTIVATE : MA_NOACTIVATE);
1200 if (LOWORD(lParam) != WA_INACTIVE &&
1201 GetWindowLong(hWnd, GWL_STYLE) & WS_MINIMIZE)
1203 /* Check if the window is minimized. */
1211 if (GetWindowLong(hWnd, GWL_STYLE & WS_CHILD))
1215 return(SendMessageW(GetParent(hWnd), WM_MOUSEWHEEL,
1220 return(SendMessageA(GetParent(hWnd), WM_MOUSEWHEEL,
1228 case WM_ICONERASEBKGND:
1231 HBRUSH hBrush = (HBRUSH)GetClassLongW(hWnd, GCL_HBRBACKGROUND);
1232 GetClipBox((HDC)wParam, &Rect);
1233 FillRect((HDC)wParam, &Rect, hBrush);
1242 /* FIXME: Implement colour controls. */
1246 if (GetWindowLong(hWnd, GWL_STYLE) & WS_CHILD)
1248 if (LOWORD(lParam) < HTLEFT || LOWORD(lParam) > HTBOTTOMRIGHT)
1253 bResult = SendMessageW(GetParent(hWnd), WM_SETCURSOR,
1258 bResult = SendMessageA(GetParent(hWnd), WM_SETCURSOR,
1267 return(DefWndHandleSetCursor(hWnd, wParam, lParam));
1273 Pt.x = SLOWORD(lParam);
1274 Pt.y = SHIWORD(lParam);
1275 return(DefWndHandleSysCommand(hWnd, wParam, Pt));
1278 /* FIXME: Handle key messages. */
1286 /* FIXME: Check for a popup window. */
1287 if ((GetWindowLongW(hWnd, GWL_STYLE) & WS_VISIBLE && !wParam) ||
1288 (!(GetWindowLongW(hWnd, GWL_STYLE) & WS_VISIBLE) && wParam))
1292 ShowWindow(hWnd, wParam ? SW_SHOWNOACTIVATE : SW_HIDE);
1298 /* FIXME: Check for a desktop. */
1299 if (GetCapture() == hWnd)
1311 /* FIXME: Implement this. */
1314 case WM_QUERYDROPOBJECT:
1316 if (GetWindowLongW(hWnd, GWL_EXSTYLE) & WS_EX_ACCEPTFILES)
1323 case WM_QUERYDRAGICON:
1328 hIcon = (HICON)GetClassLongW(hWnd, GCL_HICON);
1331 return((LRESULT)hIcon);
1333 for (Len = 1; Len < 64; Len++)
1335 if ((hIcon = LoadIconW(NULL, MAKEINTRESOURCE(Len))) != NULL)
1337 return((LRESULT)hIcon);
1340 return((LRESULT)LoadIconW(0, IDI_APPLICATION));
1343 /* FIXME: WM_ISACTIVEICON */
1345 case WM_NOTIFYFORMAT:
1347 if (IsWindowUnicode(hWnd))
1349 return(NFR_UNICODE);
1359 INT Index = (wParam != 0) ? GCL_HICON : GCL_HICONSM;
1360 HICON hOldIcon = (HICON)GetClassLongW(hWnd, Index);
1361 SetClassLongW(hWnd, Index, lParam);
1362 SetWindowPos(hWnd, 0, 0, 0, 0, 0,
1363 SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE |
1364 SWP_NOACTIVATE | SWP_NOZORDER);
1365 return((LRESULT)hOldIcon);
1370 INT Index = (wParam != 0) ? GCL_HICON : GCL_HICONSM;
1371 return(GetClassLongW(hWnd, Index));
1378 SendMessageW(GetParent(hWnd), Msg, wParam, lParam);
1382 SendMessageA(GetParent(hWnd), Msg, wParam, lParam);
1391 DefWindowProcA(HWND hWnd,
1397 static LPSTR WindowTextAtom = 0;
1404 CREATESTRUCTA* Cs = (CREATESTRUCTA*)lParam;
1405 if (HIWORD(Cs->lpszName))
1408 (LPSTR)(ULONG)GlobalAddAtomA("USER32!WindowTextAtomA");
1409 WindowText = RtlAllocateHeap(RtlGetProcessHeap(), 0,
1410 strlen(Cs->lpszName) * sizeof(CHAR));
1411 strcpy(WindowText, Cs->lpszName);
1412 SetPropA(hWnd, WindowTextAtom, WindowText);
1419 return(DefWndNCCalcSize(hWnd, (RECT*)lParam));
1422 case WM_WINDOWPOSCHANGING:
1424 return(DefWndHandleWindowPosChanging(hWnd, (WINDOWPOS*)lParam));
1427 case WM_GETTEXTLENGTH:
1429 if (WindowTextAtom == 0 ||
1430 (WindowText = GetPropA(hWnd, WindowTextAtom)) == NULL)
1434 return(strlen(WindowText));
1439 if (WindowTextAtom == 0 ||
1440 (WindowText = GetPropA(hWnd, WindowTextAtom)) == NULL)
1444 ((PSTR)lParam) = '\0';
1448 strncpy((LPSTR)lParam, WindowText, wParam);
1449 return(min(wParam, strlen(WindowText)));
1454 if (WindowTextAtom != 0)
1457 (LPSTR)(DWORD)GlobalAddAtomA("USER32!WindowTextAtomW");
1459 if (WindowTextAtom != 0 &&
1460 (WindowText = GetPropA(hWnd, WindowTextAtom)) == NULL)
1462 RtlFreeHeap(RtlGetProcessHeap(), 0, WindowText);
1464 WindowText = RtlAllocateHeap(RtlGetProcessHeap(), 0,
1465 strlen((PSTR)lParam) * sizeof(CHAR));
1466 strcpy(WindowText, (PSTR)lParam);
1467 SetPropA(hWnd, WindowTextAtom, WindowText);
1472 if (WindowTextAtom != 0 &&
1473 (WindowText = RemovePropA(hWnd, WindowTextAtom)) == NULL)
1475 RtlFreeHeap(GetProcessHeap(), 0, WindowText);
1477 if (WindowTextAtom != 0)
1479 GlobalDeleteAtom((ATOM)(ULONG)WindowTextAtom);
1481 /* FIXME: Destroy scroll bars here as well. */
1486 Result = User32DefWindowProc(hWnd, Msg, wParam, lParam, FALSE);
1494 DefWindowProcW(HWND hWnd,
1500 static LPWSTR WindowTextAtom = 0;
1507 CREATESTRUCTW* Cs = (CREATESTRUCTW*)lParam;
1508 if (HIWORD(Cs->lpszName))
1511 (LPWSTR)(DWORD)GlobalAddAtomW(L"USER32!WindowTextAtomW");
1512 WindowText = RtlAllocateHeap(RtlGetProcessHeap(), 0,
1513 wcslen(Cs->lpszName) * sizeof(WCHAR));
1514 wcscpy(WindowText, Cs->lpszName);
1515 SetPropW(hWnd, WindowTextAtom, WindowText);
1522 return(DefWndNCCalcSize(hWnd, (RECT*)lParam));
1525 case WM_WINDOWPOSCHANGING:
1527 return(DefWndHandleWindowPosChanging(hWnd, (WINDOWPOS*)lParam));
1530 case WM_GETTEXTLENGTH:
1532 if (WindowTextAtom == 0 ||
1533 (WindowText = GetPropW(hWnd, WindowTextAtom)) == NULL)
1537 return(wcslen(WindowText));
1542 if (WindowTextAtom == 0 ||
1543 (WindowText = GetPropW(hWnd, WindowTextAtom)) == NULL)
1547 ((PWSTR)lParam) = '\0';
1551 wcsncpy((PWSTR)lParam, WindowText, wParam);
1552 return(min(wParam, wcslen(WindowText)));
1557 if (WindowTextAtom != 0)
1560 (LPWSTR)(DWORD)GlobalAddAtom(L"USER32!WindowTextAtomW");
1562 if (WindowTextAtom != 0 &&
1563 (WindowText = GetPropW(hWnd, WindowTextAtom)) == NULL)
1565 RtlFreeHeap(RtlGetProcessHeap(), 0, WindowText);
1567 WindowText = RtlAllocateHeap(RtlGetProcessHeap(), 0,
1568 wcslen((PWSTR)lParam) * sizeof(WCHAR));
1569 wcscpy(WindowText, (PWSTR)lParam);
1570 SetPropW(hWnd, WindowTextAtom, WindowText);
1572 //FIXME: return correct code
1577 if (WindowTextAtom != 0 &&
1578 (WindowText = RemovePropW(hWnd, WindowTextAtom)) == NULL)
1580 RtlFreeHeap(RtlGetProcessHeap(), 0, WindowText);
1582 if (WindowTextAtom != 0)
1584 GlobalDeleteAtom((ATOM)(DWORD)WindowTextAtom);
1586 /* FIXME: Destroy scroll bars here as well. */
1591 Result = User32DefWindowProc(hWnd, Msg, wParam, lParam, TRUE);