1 /* $Id: defwnd.c,v 1.28 2003/03/06 23:57:00 gvg Exp $
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(58, 110, 165) /* COLOR_BACKGROUND */,
35 RGB(0, 0, 128) /* COLOR_ACTIVECAPTION */,
36 RGB(128, 128, 128) /* COLOR_INACTIVECAPTION */,
37 RGB(192, 192, 192) /* COLOR_MENU */,
38 RGB(192, 192, 192) /* COLOR_WINDOW */,
39 RGB(192, 192, 192) /* 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, 128) /* 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(192, 192, 192) /* 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 UserDrawSysMenuButton( HWND hWnd
, HDC hDC
, BOOL down
)
216 /* FIXME: Implement AppIcon loading/displaying, if AppIcon isn't present,
217 load default (OIC_SAMPLE I believe, not sure */
220 static void UserDrawCloseButton ( HWND hWnd
, HDC hDC
, BOOL down
)
222 /* ported from wine code */
224 BOOL bInactive
= FALSE
;
226 UserGetInsideRectNC( hWnd
, &rect
);
228 if (GetWindowLongA( hWnd
, GWL_EXSTYLE
) & WS_EX_TOOLWINDOW
)
230 INT iBmpHeight
= 11; /* Windows does not use SM_CXSMSIZE and SM_CYSMSIZE */
231 INT iBmpWidth
= 11; /* it uses 11x11 for the close button in tool window */
232 INT iCaptionHeight
= GetSystemMetrics(SM_CYSMCAPTION
);
234 rect
.top
= rect
.top
+ (iCaptionHeight
- 1 - iBmpHeight
) / 2;
235 rect
.left
= rect
.right
- (iCaptionHeight
+ 1 + iBmpWidth
) / 2;
236 rect
.bottom
= rect
.top
+ iBmpHeight
;
237 rect
.right
= rect
.left
+ iBmpWidth
;
243 /* Standard close/min/max button sizes appear to be 16x14, though
244 these change with the caption size, I'll fix this soon */
245 rect
.left
= rect
.right
- 16;
246 rect
.bottom
= rect
.top
+ 14;
249 DrawFrameControl( hDC
, &rect
, DFC_CAPTION
,
251 (down
? DFCS_PUSHED
: 0) |
252 (bInactive
? DFCS_INACTIVE
: 0)) );
255 static void UserDrawMaxButton( HWND hWnd
, HDC hDC
, BOOL down
)
259 UINT flags
= IsZoomed(hWnd
) ? DFCS_CAPTIONRESTORE
: DFCS_CAPTIONMAX
;
261 UserGetInsideRectNC( hWnd
, &rect
);
264 rect
.left
= rect
.right
- (GetSystemMetrics(SM_CXSIZE
) - 1) * 2;
265 rect
.right
= rect
.left
+ (GetSystemMetrics(SM_CXSIZE
) - 2);
266 rect
.bottom
= rect
.top
+ GetSystemMetrics(SM_CYSIZE
) - 4;
268 if (down
) flags
|= DFCS_PUSHED
;
269 DrawFrameControl( hDC
, &rect
, DFC_CAPTION
, flags
);
273 static void UserDrawMinButton( HWND hWnd
, HDC hDC
, BOOL down
)
277 UINT flags
= DFCS_CAPTIONMIN
;
279 BOOL bInactive
= FALSE
;
280 UserGetInsideRectNC( hWnd
, &rect
);
283 rect
.left
= rect
.right
- ((GetSystemMetrics(SM_CXSIZE
)) * 3) + 4;
284 rect
.right
= rect
.left
+ (GetSystemMetrics(SM_CXSIZE
) - 2);
285 rect
.bottom
= rect
.top
+ GetSystemMetrics(SM_CYSIZE
) - 4;
287 if (down
) flags
|= DFCS_PUSHED
;
288 if (bInactive
) flags
|= DFCS_INACTIVE
;
289 DrawFrameControl( hDC
, &rect
, DFC_CAPTION
, flags
);
293 static void UserDrawCaptionNC( HDC hDC
, RECT
*rect
, HWND hWnd
,
294 DWORD style
, BOOL active
)
301 hbitmapClose
= LoadBitmapW( 0, MAKEINTRESOURCE(OBM_CLOSE
));
302 hbitmapMinimize
= LoadBitmapW( 0, MAKEINTRESOURCE(OBM_REDUCE
) );
303 hbitmapMinimizeD
= LoadBitmapW( 0, MAKEINTRESOURCE(OBM_REDUCED
) );
304 hbitmapMaximize
= LoadBitmapW( 0, MAKEINTRESOURCE(OBM_ZOOM
) );
305 hbitmapMaximizeD
= LoadBitmapW( 0, MAKEINTRESOURCE(OBM_ZOOMD
) );
306 hbitmapRestore
= LoadBitmapW( 0, MAKEINTRESOURCE(OBM_RESTORE
) );
307 hbitmapRestoreD
= LoadBitmapW( 0, MAKEINTRESOURCE(OBM_RESTORED
) );
310 if (GetWindowLong(hWnd
, GWL_EXSTYLE
) & WS_EX_DLGMODALFRAME
)
315 /* Fill the caption with COLOR_(IN)ACTIVECAPTION.
316 In the future this will be GradientFill() */
318 SelectObject( hDC
, GetSysColorBrush(active
? COLOR_ACTIVECAPTION
: COLOR_INACTIVECAPTION
) );
319 PatBlt(hDC
,rect
->left
+ 3, rect
->top
+ 3, rect
->right
- 6, rect
->bottom
- 1, PATCOPY
);
321 if (style
& WS_SYSMENU
)
323 UserDrawSysMenuButton( hWnd
, hDC
, FALSE
);
324 r
.left
+= GetSystemMetrics(SM_CXSIZE
) + 1;
325 UserDrawCloseButton( hWnd
, hDC
, FALSE
);
327 if (style
& WS_MAXIMIZEBOX
)
329 UserDrawMaxButton( hWnd
, hDC
, FALSE
);
330 r
.right
-= GetSystemMetrics(SM_CXSMSIZE
) + 1;
332 if (style
& WS_MINIMIZEBOX
)
334 UserDrawMinButton( hWnd
, hDC
, FALSE
);
335 r
.right
-= GetSystemMetrics(SM_CXSMSIZE
) + 1;
339 if (GetWindowTextA( hWnd
, buffer
, sizeof(buffer
) ))
341 NONCLIENTMETRICS nclm
;
342 HFONT hFont
, hOldFont
;
344 nclm
.cbSize
= sizeof(NONCLIENTMETRICS
);
345 SystemParametersInfoW(SPI_GETNONCLIENTMETRICS
, 0, &nclm
, 0);
346 if (style
& WS_EX_TOOLWINDOW
)
347 hFont
= CreateFontIndirectW(&nclm
.lfSmCaptionFont
);
349 hFont
= CreateFontIndirectW(&nclm
.lfCaptionFont
);
350 hOldFont
= SelectObject(hDC
, hFont
);
352 SetTextColor(hDC
, GetSysColor( (active
? COLOR_CAPTIONTEXT
: COLOR_INACTIVECAPTIONTEXT
) ) );
353 SetBkMode( hDC
, TRANSPARENT
);
355 /*FIXME: Need verticle centering code and other fixups */
356 TextOutA(hDC
, r
.left
+5, r
.top
+5, buffer
, strlen(buffer
));
357 DeleteObject (SelectObject (hDC
, hOldFont
));
362 UserDrawFrameNC(HDC hDC
, RECT
* rect
, BOOL dlgFrame
, BOOL active
)
364 SelectObject( hDC
, GetSysColorBrush(COLOR_WINDOW
) );
365 DrawEdge(hDC
, rect
,EDGE_RAISED
, BF_RECT
| BF_MIDDLE
);
368 void SCROLL_DrawScrollBar (HWND hWnd
, HDC hDC
, INT nBar
, BOOL arrows
, BOOL interior
);
371 DefWndDoPaintNC(HWND hWnd
, HRGN clip
)
379 Active
= GetWindowLongW(hWnd
, GWL_STYLE
) & WIN_NCACTIVATED
;
380 Style
= GetWindowLong(hWnd
, GWL_STYLE
);
381 ExStyle
= GetWindowLong(hWnd
, GWL_EXSTYLE
);
383 hDC
= GetDCEx(hWnd
, (clip
> (HRGN
)1) ? clip
: 0, DCX_USESTYLE
| DCX_WINDOW
|
384 ((clip
> (HRGN
)1) ? (DCX_INTERSECTRGN
| DCX_KEEPCLIPRGN
) : 0));
390 /* FIXME: Test whether we need to draw anything at all. */
392 GetWindowRect(hWnd
, &rect
);
393 rect
.right
= rect
.right
- rect
.left
;
394 rect
.bottom
= rect
.bottom
- rect
.top
;
395 rect
.top
= rect
.left
= 0;
397 SelectObject(hDC
, GetSysColorPen(COLOR_WINDOWFRAME
));
398 if (UserHasAnyFrameStyle(Style
, ExStyle
))
400 SelectObject(hDC
, GetStockObject(NULL_BRUSH
));
401 InflateRect(&rect
, -1, -1);
404 if (UserHasThickFrameStyle(Style
, ExStyle
))
406 UserDrawFrameNC(hDC
, &rect
, FALSE
, Active
);
408 else if (UserHasDlgFrameStyle(Style
, ExStyle
))
410 UserDrawFrameNC(hDC
, &rect
, TRUE
, Active
);
413 if (Style
& WS_CAPTION
)
416 r
.bottom
= rect
.top
+ GetSystemMetrics(SM_CYSIZE
);
417 rect
.top
+= GetSystemMetrics(SM_CYSIZE
) +
418 GetSystemMetrics(SM_CYBORDER
);
419 UserDrawCaptionNC(hDC
, &r
, hWnd
, Style
, Active
);
422 /* FIXME: Draw menu bar. */
424 DbgPrint("drawing scrollbars..\n");
425 /* Draw scrollbars */
426 if (Style
& WS_VSCROLL
)
427 SCROLL_DrawScrollBar(hWnd
, hDC
, SB_VERT
, TRUE
, TRUE
);
428 if (Style
& WS_HSCROLL
)
429 SCROLL_DrawScrollBar(hWnd
, hDC
, SB_HORZ
, TRUE
, TRUE
);
431 /* FIXME: Draw size box. */
433 ReleaseDC(hWnd
, hDC
);
437 DefWndPaintNC(HWND hWnd
, HRGN clip
)
439 if (IsWindowVisible(hWnd
))
443 DefWndRedrawIconTitle(hWnd
);
447 DefWndDoPaintNC(hWnd
, clip
);
454 DefWndHitTestNC(HWND hWnd
, POINT Point
)
457 ULONG Style
= GetWindowLong(hWnd
, GWL_STYLE
);
458 ULONG ExStyle
= GetWindowLong(hWnd
, GWL_EXSTYLE
);
460 GetWindowRect(hWnd
, &WindowRect
);
462 if (!PtInRect(&WindowRect
, Point
))
466 if (Style
& WS_MINIMIZE
)
470 if (UserHasThickFrameStyle(Style
, ExStyle
))
472 InflateRect(&WindowRect
, -GetSystemMetrics(SM_CXFRAME
),
473 -GetSystemMetrics(SM_CYFRAME
));
474 if (!PtInRect(&WindowRect
, Point
))
476 if (Point
.y
< WindowRect
.top
)
478 if (Point
.x
< (WindowRect
.left
+ GetSystemMetrics(SM_CXSIZE
)))
482 if (Point
.x
>= (WindowRect
.right
- GetSystemMetrics(SM_CXSIZE
)))
488 if (Point
.y
>= WindowRect
.bottom
)
490 if (Point
.x
< (WindowRect
.left
+ GetSystemMetrics(SM_CXSIZE
)))
492 return(HTBOTTOMLEFT
);
494 if (Point
.x
>= (WindowRect
.right
- GetSystemMetrics(SM_CXSIZE
)))
496 return(HTBOTTOMRIGHT
);
500 if (Point
.x
< WindowRect
.left
)
502 if (Point
.y
< (WindowRect
.top
+ GetSystemMetrics(SM_CYSIZE
)))
506 if (Point
.y
>= (WindowRect
.bottom
- GetSystemMetrics(SM_CYSIZE
)))
508 return(HTBOTTOMLEFT
);
512 if (Point
.x
>= WindowRect
.right
)
514 if (Point
.y
< (WindowRect
.top
+ GetSystemMetrics(SM_CYSIZE
)))
518 if (Point
.y
>= (WindowRect
.bottom
- GetSystemMetrics(SM_CYSIZE
)))
520 return(HTBOTTOMRIGHT
);
528 if (UserHasDlgFrameStyle(Style
, ExStyle
))
530 InflateRect(&WindowRect
, -GetSystemMetrics(SM_CXDLGFRAME
),
531 -GetSystemMetrics(SM_CYDLGFRAME
));
533 else if (UserHasThinFrameStyle(Style
, ExStyle
))
535 InflateRect(&WindowRect
, -GetSystemMetrics(SM_CXBORDER
),
536 -GetSystemMetrics(SM_CYBORDER
));
538 if (!PtInRect(&WindowRect
, Point
))
544 if ((Style
& WS_CAPTION
) == WS_CAPTION
)
546 WindowRect
.top
+= GetSystemMetrics(SM_CYCAPTION
) -
547 GetSystemMetrics(SM_CYBORDER
);
548 if (!PtInRect(&WindowRect
, Point
))
550 if ((Style
& WS_SYSMENU
) && !(ExStyle
& WS_EX_TOOLWINDOW
))
552 WindowRect
.left
+= GetSystemMetrics(SM_CXSIZE
);
553 WindowRect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
555 if (Point
.x
<= WindowRect
.left
)
559 if (WindowRect
.right
<= Point
.x
)
564 if (Style
& WS_MAXIMIZEBOX
)
566 WindowRect
.right
-= GetSystemMetrics(SM_CXSMSIZE
) + 1;
568 if (Point
.x
>= WindowRect
.right
)
573 if (Style
& WS_MINIMIZEBOX
)
575 WindowRect
.right
-= GetSystemMetrics(SM_CXSMSIZE
) + 1;
577 if (Point
.x
>= WindowRect
.right
)
585 ScreenToClient(hWnd
, &Point
);
586 GetClientRect(hWnd
, &WindowRect
);
588 if (PtInRect(&WindowRect
, Point
))
593 if (Style
& WS_VSCROLL
)
595 WindowRect
.right
+= GetSystemMetrics(SM_CXVSCROLL
);
596 if (PtInRect(&WindowRect
, Point
))
602 if (Style
& WS_HSCROLL
)
604 WindowRect
.bottom
+= GetSystemMetrics(SM_CYHSCROLL
);
605 if (PtInRect(&WindowRect
, Point
))
607 if ((Style
& WS_VSCROLL
) &&
608 (Point
.x
>= (WindowRect
.right
- GetSystemMetrics(SM_CXVSCROLL
))))
616 if (UserHasMenu(hWnd
, Style
))
618 if (Point
.y
< 0 && Point
.x
>= 0 && Point
.x
<= WindowRect
.right
)
628 DefWndTrackMinMaxBox(HWND hWnd
, WPARAM wParam
)
630 HDC hDC
= GetWindowDC(hWnd
);
636 if (wParam
== HTMINBUTTON
)
638 UserDrawMinButton(hWnd
, hDC
, TRUE
);
642 UserDrawMaxButton(hWnd
, hDC
, TRUE
);
647 BOOL OldState
= Pressed
;
649 GetMessageA(hWnd
, &Msg
, 0, 0);
650 if (Msg
.message
== WM_LBUTTONUP
)
654 if (Msg
.message
!= WM_MOUSEMOVE
)
659 Pressed
= DefWndHitTestNC(hWnd
, Msg
.pt
) == (LRESULT
) wParam
;
660 if (Pressed
!= OldState
)
662 if (wParam
== HTMINBUTTON
)
664 UserDrawMinButton(hWnd
, hDC
, Pressed
);
668 UserDrawMaxButton(hWnd
, hDC
, Pressed
);
675 if (wParam
== HTMINBUTTON
)
677 UserDrawMinButton(hWnd
, hDC
, FALSE
);
681 UserDrawMaxButton(hWnd
, hDC
, FALSE
);
686 ReleaseDC(hWnd
, hDC
);
693 if (wParam
== HTMINBUTTON
)
695 SendMessageA(hWnd
, WM_SYSCOMMAND
, SC_MINIMIZE
,
696 MAKELONG(Msg
.pt
.x
, Msg
.pt
.y
));
700 SendMessageA(hWnd
, WM_SYSCOMMAND
,
701 IsZoomed(hWnd
) ? SC_RESTORE
: SC_MAXIMIZE
,
702 MAKELONG(Msg
.pt
.x
, Msg
.pt
.y
));
707 DefWndDrawSysButton(HWND hWnd
, HDC hDC
, BOOL Down
)
711 HBITMAP hSavedBitmap
;
713 UserGetInsideRectNC(hWnd
, &Rect
);
714 hDCMem
= CreateCompatibleDC(hDC
);
715 hSavedBitmap
= SelectObject(hDCMem
, hbitmapClose
);
716 BitBlt(hDC
, Rect
.left
, Rect
.top
, GetSystemMetrics(SM_CXSIZE
),
717 GetSystemMetrics(SM_CYSIZE
), hDCMem
,
718 (GetWindowLong(hWnd
, GWL_STYLE
) & WS_CHILD
) ?
719 GetSystemMetrics(SM_CXSIZE
): 0, 0, Down
? NOTSRCCOPY
: SRCCOPY
);
720 SelectObject(hDCMem
, hSavedBitmap
);
725 DefWndHandleLButtonDownNC(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
731 HWND hTopWnd
= GetDesktopWindow(); //GetAncestor(hWnd, GA_ROOT); temp fix.
732 if (SetActiveWindow(hTopWnd
) || GetActiveWindow() == hTopWnd
)
734 SendMessageA(hWnd
, WM_SYSCOMMAND
, SC_MOVE
+ HTCAPTION
, lParam
);
740 if (GetWindowLong(hWnd
, GWL_STYLE
) & WS_SYSMENU
)
742 if (!(GetWindowLong(hWnd
, GWL_STYLE
) & WS_MINIMIZE
))
744 HDC hDC
= GetWindowDC(hWnd
);
745 DefWndDrawSysButton(hWnd
, hDC
, TRUE
);
746 ReleaseDC(hWnd
, hDC
);
748 SendMessageA(hWnd
, WM_SYSCOMMAND
, SC_MOUSEMENU
+ HTSYSMENU
,
755 SendMessageA(hWnd
, WM_SYSCOMMAND
, SC_MOUSEMENU
, lParam
);
759 SendMessageA(hWnd
, WM_SYSCOMMAND
, SC_HSCROLL
+ HTHSCROLL
, lParam
);
763 SendMessageA(hWnd
, WM_SYSCOMMAND
, SC_VSCROLL
+ HTVSCROLL
, lParam
);
768 DefWndTrackMinMaxBox(hWnd
, wParam
);
779 SendMessageA(hWnd
, WM_SYSCOMMAND
, SC_SIZE
+ wParam
- 2, lParam
);
787 DefWndHandleLButtonDblClkNC(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
789 /* FIXME: Implement this. */
794 DefWndHandleLButtonUpNC(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
799 SendMessageA(hWnd
, WM_CLOSE
, 0, 0);
807 DefWndHandleActiveNC(HWND hWnd
, WPARAM wParam
)
809 /* FIXME: Implement this. */
814 DefWndSetRedraw(HWND hWnd
, WPARAM wParam
)
819 DefWndHandleSetCursor(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
821 /* Not for child windows. */
822 if (hWnd
!= (HWND
)wParam
)
827 switch(LOWORD(lParam
))
831 WORD Msg
= HIWORD(lParam
);
832 if (Msg
== WM_LBUTTONDOWN
|| Msg
== WM_MBUTTONDOWN
||
833 Msg
== WM_RBUTTONDOWN
)
842 HICON hCursor
= (HICON
)GetClassLong(hWnd
, GCL_HCURSOR
);
854 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZEWE
)));
860 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZENS
)));
866 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZENWSE
)));
872 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZENESW
)));
875 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_ARROW
)));
879 DefWndHandleSysCommand(HWND hWnd
, WPARAM wParam
, POINT Pt
)
881 /* FIXME: Implement system commands. */
886 DefWndAdjustRect(RECT
* Rect
, ULONG Style
, BOOL Menu
, ULONG ExStyle
)
888 if (Style
& WS_ICONIC
)
893 if (UserHasThickFrameStyle(Style
, ExStyle
))
895 InflateRect(Rect
, GetSystemMetrics(SM_CXFRAME
),
896 GetSystemMetrics(SM_CYFRAME
));
898 else if (UserHasDlgFrameStyle(Style
, ExStyle
))
900 InflateRect(Rect
, GetSystemMetrics(SM_CXDLGFRAME
),
901 GetSystemMetrics(SM_CYDLGFRAME
));
903 else if (UserHasThinFrameStyle(Style
, ExStyle
))
905 InflateRect(Rect
, GetSystemMetrics(SM_CXBORDER
),
906 GetSystemMetrics(SM_CYBORDER
));
908 if (Style
& WS_CAPTION
)
910 Rect
->top
-= GetSystemMetrics(SM_CYCAPTION
) -
911 GetSystemMetrics(SM_CYBORDER
);
915 Rect
->top
-= GetSystemMetrics(SM_CYMENU
) + GetSystemMetrics(SM_CYBORDER
);
917 if (Style
& WS_VSCROLL
)
919 Rect
->right
+= GetSystemMetrics(SM_CXVSCROLL
) - 1;
920 if (UserHasAnyFrameStyle(Style
, ExStyle
))
925 if (Style
& WS_HSCROLL
)
927 Rect
->bottom
+= GetSystemMetrics(SM_CYHSCROLL
) - 1;
928 if (UserHasAnyFrameStyle(Style
, ExStyle
))
936 DefWndNCCalcSize(HWND hWnd
, RECT
* Rect
)
939 LONG Style
= GetClassLongW(hWnd
, GCL_STYLE
);
940 RECT TmpRect
= {0, 0, 0, 0};
942 if (Style
& CS_VREDRAW
)
944 Result
|= WVR_VREDRAW
;
946 if (Style
& CS_HREDRAW
)
948 Result
|= WVR_HREDRAW
;
951 if (!(GetWindowLong(hWnd
, GWL_STYLE
) & WS_MINIMIZE
))
953 DefWndAdjustRect(&TmpRect
, GetWindowLong(hWnd
, GWL_STYLE
),
954 FALSE
, GetWindowLong(hWnd
, GWL_EXSTYLE
));
955 Rect
->left
-= TmpRect
.left
;
956 Rect
->top
-= TmpRect
.top
;
957 Rect
->right
-= TmpRect
.right
;
958 Rect
->bottom
-= TmpRect
.bottom
;
959 /* FIXME: Adjust if the window has a menu. */
960 Rect
->bottom
= max(Rect
->top
, Rect
->bottom
);
961 Rect
->right
= max(Rect
->left
, Rect
->right
);
967 DefWndHandleWindowPosChanging(HWND hWnd
, WINDOWPOS
* Pos
)
969 /* FIXME: Implement this. */
974 User32DefWindowProc(HWND hWnd
,
984 return(DefWndPaintNC(hWnd
, (HRGN
)wParam
));
990 Point
.x
= SLOWORD(lParam
);
991 Point
.y
= SHIWORD(lParam
);
992 return(DefWndHitTestNC(hWnd
, Point
));
995 case WM_NCLBUTTONDOWN
:
997 return(DefWndHandleLButtonDownNC(hWnd
, wParam
, lParam
));
1000 case WM_NCLBUTTONUP
:
1002 return(DefWndHandleLButtonUpNC(hWnd
, wParam
, lParam
));
1005 case WM_LBUTTONDBLCLK
:
1006 case WM_NCLBUTTONDBLCLK
:
1008 return(DefWndHandleLButtonDblClkNC(hWnd
, wParam
, lParam
));
1011 case WM_NCRBUTTONDOWN
:
1013 if (wParam
== HTCAPTION
)
1023 if (hWnd
== GetCapture())
1027 Pt
.x
= SLOWORD(lParam
);
1028 Pt
.y
= SHIWORD(lParam
);
1029 ClientToScreen(hWnd
, &Pt
);
1030 lParam
= MAKELPARAM(Pt
.x
, Pt
.y
);
1033 SendMessageW(hWnd
, WM_CONTEXTMENU
, (WPARAM
)hWnd
, lParam
);
1037 SendMessageA (hWnd
, WM_CONTEXTMENU
, (WPARAM
)hWnd
, lParam
);
1042 case WM_NCRBUTTONUP
:
1044 /* Wine does nothing here. */
1048 case WM_CONTEXTMENU
:
1050 if (GetWindowLong(hWnd
, GWL_STYLE
) & WS_CHILD
)
1054 SendMessageW(GetParent(hWnd
), Msg
, wParam
, lParam
);
1058 SendMessageA(hWnd
, WM_CONTEXTMENU
, wParam
, lParam
);
1066 Pt
.x
= SLOWORD(lParam
);
1067 Pt
.y
= SHIWORD(lParam
);
1069 if (GetWindowLong(hWnd
, GWL_STYLE
) & WS_CHILD
)
1071 ScreenToClient(GetParent(hWnd
), &Pt
);
1074 HitCode
= DefWndHitTestNC(hWnd
, Pt
);
1076 if (HitCode
== HTCAPTION
|| HitCode
== HTSYSMENU
)
1078 TrackPopupMenu(GetSystemMenu(hWnd
, FALSE
),
1079 TPM_LEFTBUTTON
| TPM_RIGHTBUTTON
,
1080 Pt
.x
, Pt
.y
, 0, hWnd
, NULL
);
1088 return(DefWndHandleActiveNC(hWnd
, wParam
));
1105 HDC hDC
= BeginPaint(hWnd
, &Ps
);
1109 if (GetWindowLongW(hWnd
, GWL_STYLE
) & WS_MINIMIZE
&&
1110 (hIcon
= (HICON
)GetClassLongW(hWnd
, GCL_HICON
)) != NULL
)
1114 GetWindowRect(hWnd
, &WindowRect
);
1115 x
= (WindowRect
.right
- WindowRect
.left
-
1116 GetSystemMetrics(SM_CXICON
)) / 2;
1117 y
= (WindowRect
.bottom
- WindowRect
.top
-
1118 GetSystemMetrics(SM_CYICON
)) / 2;
1119 DrawIcon(hDC
, x
, y
, hIcon
);
1121 EndPaint(hWnd
, &Ps
);
1129 hRgn
= CreateRectRgn(0, 0, 0, 0);
1130 if (GetUpdateRgn(hWnd
, hRgn
, FALSE
) != NULLREGION
)
1132 RedrawWindow(hWnd
, NULL
, hRgn
,
1133 RDW_ERASENOW
| RDW_ERASE
| RDW_FRAME
|
1142 DefWndSetRedraw(hWnd
, wParam
);
1148 DestroyWindow(hWnd
);
1152 case WM_MOUSEACTIVATE
:
1154 if (GetWindowLong(hWnd
, GWL_STYLE
) & WS_CHILD
)
1159 Ret
= SendMessageW(GetParent(hWnd
), WM_MOUSEACTIVATE
,
1164 Ret
= SendMessageA(GetParent(hWnd
), WM_MOUSEACTIVATE
,
1172 return((LOWORD(lParam
) >= HTCLIENT
) ? MA_ACTIVATE
: MA_NOACTIVATE
);
1177 if (LOWORD(lParam
) != WA_INACTIVE
&&
1178 GetWindowLong(hWnd
, GWL_STYLE
) & WS_MINIMIZE
)
1180 /* Check if the window is minimized. */
1188 if (GetWindowLong(hWnd
, GWL_STYLE
& WS_CHILD
))
1192 return(SendMessageW(GetParent(hWnd
), WM_MOUSEWHEEL
,
1197 return(SendMessageA(GetParent(hWnd
), WM_MOUSEWHEEL
,
1205 case WM_ICONERASEBKGND
:
1208 HBRUSH hBrush
= (HBRUSH
)GetClassLongW(hWnd
, GCL_HBRBACKGROUND
);
1209 GetClipBox((HDC
)wParam
, &Rect
);
1210 FillRect((HDC
)wParam
, &Rect
, hBrush
);
1219 /* FIXME: Implement colour controls. */
1223 if (GetWindowLong(hWnd
, GWL_STYLE
) & WS_CHILD
)
1225 if (LOWORD(lParam
) < HTLEFT
|| LOWORD(lParam
) > HTBOTTOMRIGHT
)
1230 bResult
= SendMessageW(GetParent(hWnd
), WM_SETCURSOR
,
1235 bResult
= SendMessageA(GetParent(hWnd
), WM_SETCURSOR
,
1244 return(DefWndHandleSetCursor(hWnd
, wParam
, lParam
));
1250 Pt
.x
= SLOWORD(lParam
);
1251 Pt
.y
= SHIWORD(lParam
);
1252 return(DefWndHandleSysCommand(hWnd
, wParam
, Pt
));
1255 /* FIXME: Handle key messages. */
1263 /* FIXME: Check for a popup window. */
1264 if ((GetWindowLongW(hWnd
, GWL_STYLE
) & WS_VISIBLE
&& !wParam
) ||
1265 (!(GetWindowLongW(hWnd
, GWL_STYLE
) & WS_VISIBLE
) && wParam
))
1269 ShowWindow(hWnd
, wParam
? SW_SHOWNOACTIVATE
: SW_HIDE
);
1275 /* FIXME: Check for a desktop. */
1276 if (GetCapture() == hWnd
)
1288 /* FIXME: Implement this. */
1291 case WM_QUERYDROPOBJECT
:
1293 if (GetWindowLongW(hWnd
, GWL_EXSTYLE
) & WS_EX_ACCEPTFILES
)
1300 case WM_QUERYDRAGICON
:
1305 hIcon
= (HICON
)GetClassLongW(hWnd
, GCL_HICON
);
1308 return((LRESULT
)hIcon
);
1310 for (Len
= 1; Len
< 64; Len
++)
1312 if ((hIcon
= LoadIconW(NULL
, MAKEINTRESOURCE(Len
))) != NULL
)
1314 return((LRESULT
)hIcon
);
1317 return((LRESULT
)LoadIconW(0, IDI_APPLICATION
));
1320 /* FIXME: WM_ISACTIVEICON */
1322 case WM_NOTIFYFORMAT
:
1324 if (IsWindowUnicode(hWnd
))
1326 return(NFR_UNICODE
);
1336 INT Index
= (wParam
!= 0) ? GCL_HICON
: GCL_HICONSM
;
1337 HICON hOldIcon
= (HICON
)GetClassLongW(hWnd
, Index
);
1338 SetClassLongW(hWnd
, Index
, lParam
);
1339 SetWindowPos(hWnd
, 0, 0, 0, 0, 0,
1340 SWP_FRAMECHANGED
| SWP_NOSIZE
| SWP_NOMOVE
|
1341 SWP_NOACTIVATE
| SWP_NOZORDER
);
1342 return((LRESULT
)hOldIcon
);
1347 INT Index
= (wParam
!= 0) ? GCL_HICON
: GCL_HICONSM
;
1348 return(GetClassLongW(hWnd
, Index
));
1355 SendMessageW(GetParent(hWnd
), Msg
, wParam
, lParam
);
1359 SendMessageA(GetParent(hWnd
), Msg
, wParam
, lParam
);
1368 DefWindowProcA(HWND hWnd
,
1374 static LPSTR WindowTextAtom
= 0;
1381 CREATESTRUCTA
* Cs
= (CREATESTRUCTA
*)lParam
;
1382 if (HIWORD(Cs
->lpszName
))
1385 (LPSTR
)(ULONG
)GlobalAddAtomA("USER32!WindowTextAtomA");
1386 WindowText
= RtlAllocateHeap(RtlGetProcessHeap(), 0,
1387 strlen(Cs
->lpszName
) * sizeof(CHAR
));
1388 strcpy(WindowText
, Cs
->lpszName
);
1389 SetPropA(hWnd
, WindowTextAtom
, WindowText
);
1396 return(DefWndNCCalcSize(hWnd
, (RECT
*)lParam
));
1399 case WM_WINDOWPOSCHANGING
:
1401 return(DefWndHandleWindowPosChanging(hWnd
, (WINDOWPOS
*)lParam
));
1404 case WM_GETTEXTLENGTH
:
1406 if (WindowTextAtom
== 0 ||
1407 (WindowText
= GetPropA(hWnd
, WindowTextAtom
)) == NULL
)
1411 return(strlen(WindowText
));
1416 if (WindowTextAtom
== 0 ||
1417 (WindowText
= GetPropA(hWnd
, WindowTextAtom
)) == NULL
)
1421 ((PSTR
)lParam
) = '\0';
1425 strncpy((LPSTR
)lParam
, WindowText
, wParam
);
1426 return(min(wParam
, strlen(WindowText
)));
1431 if (WindowTextAtom
!= 0)
1434 (LPSTR
)(DWORD
)GlobalAddAtomA("USER32!WindowTextAtomW");
1436 if (WindowTextAtom
!= 0 &&
1437 (WindowText
= GetPropA(hWnd
, WindowTextAtom
)) == NULL
)
1439 RtlFreeHeap(RtlGetProcessHeap(), 0, WindowText
);
1441 WindowText
= RtlAllocateHeap(RtlGetProcessHeap(), 0,
1442 strlen((PSTR
)lParam
) * sizeof(CHAR
));
1443 strcpy(WindowText
, (PSTR
)lParam
);
1444 SetPropA(hWnd
, WindowTextAtom
, WindowText
);
1449 if (WindowTextAtom
!= 0 &&
1450 (WindowText
= RemovePropA(hWnd
, WindowTextAtom
)) == NULL
)
1452 RtlFreeHeap(GetProcessHeap(), 0, WindowText
);
1454 if (WindowTextAtom
!= 0)
1456 GlobalDeleteAtom((ATOM
)(ULONG
)WindowTextAtom
);
1458 /* FIXME: Destroy scroll bars here as well. */
1463 Result
= User32DefWindowProc(hWnd
, Msg
, wParam
, lParam
, FALSE
);
1471 DefWindowProcW(HWND hWnd
,
1477 static LPWSTR WindowTextAtom
= 0;
1484 CREATESTRUCTW
* Cs
= (CREATESTRUCTW
*)lParam
;
1485 if (HIWORD(Cs
->lpszName
))
1488 (LPWSTR
)(DWORD
)GlobalAddAtomW(L
"USER32!WindowTextAtomW");
1489 WindowText
= RtlAllocateHeap(RtlGetProcessHeap(), 0,
1490 wcslen(Cs
->lpszName
) * sizeof(WCHAR
));
1491 wcscpy(WindowText
, Cs
->lpszName
);
1492 SetPropW(hWnd
, WindowTextAtom
, WindowText
);
1499 return(DefWndNCCalcSize(hWnd
, (RECT
*)lParam
));
1502 case WM_WINDOWPOSCHANGING
:
1504 return(DefWndHandleWindowPosChanging(hWnd
, (WINDOWPOS
*)lParam
));
1507 case WM_GETTEXTLENGTH
:
1509 if (WindowTextAtom
== 0 ||
1510 (WindowText
= GetPropW(hWnd
, WindowTextAtom
)) == NULL
)
1514 return(wcslen(WindowText
));
1519 if (WindowTextAtom
== 0 ||
1520 (WindowText
= GetPropW(hWnd
, WindowTextAtom
)) == NULL
)
1524 ((PWSTR
)lParam
) = '\0';
1528 wcsncpy((PWSTR
)lParam
, WindowText
, wParam
);
1529 return(min(wParam
, wcslen(WindowText
)));
1534 if (WindowTextAtom
!= 0)
1537 (LPWSTR
)(DWORD
)GlobalAddAtom(L
"USER32!WindowTextAtomW");
1539 if (WindowTextAtom
!= 0 &&
1540 (WindowText
= GetPropW(hWnd
, WindowTextAtom
)) == NULL
)
1542 RtlFreeHeap(RtlGetProcessHeap(), 0, WindowText
);
1544 WindowText
= RtlAllocateHeap(RtlGetProcessHeap(), 0,
1545 wcslen((PWSTR
)lParam
) * sizeof(WCHAR
));
1546 wcscpy(WindowText
, (PWSTR
)lParam
);
1547 SetPropW(hWnd
, WindowTextAtom
, WindowText
);
1549 //FIXME: return correct code
1554 if (WindowTextAtom
!= 0 &&
1555 (WindowText
= RemovePropW(hWnd
, WindowTextAtom
)) == NULL
)
1557 RtlFreeHeap(RtlGetProcessHeap(), 0, WindowText
);
1559 if (WindowTextAtom
!= 0)
1561 GlobalDeleteAtom((ATOM
)(DWORD
)WindowTextAtom
);
1563 /* FIXME: Destroy scroll bars here as well. */
1568 Result
= User32DefWindowProc(hWnd
, Msg
, wParam
, lParam
, TRUE
);