New interface: DropSource.
[wine/wine-kai.git] / windows / nonclient.c
blobd7a2b95f9a6720d722c96088c6955c018ab5776e
1 /*
2 * Non-client area window functions
4 * Copyright 1994 Alexandre Julliard
6 */
8 #include "wine/winuser16.h"
9 #include "version.h"
10 #include "win.h"
11 #include "message.h"
12 #include "user.h"
13 #include "heap.h"
14 #include "dce.h"
15 #include "cursoricon.h"
16 #include "dialog.h"
17 #include "menu.h"
18 #include "winpos.h"
19 #include "hook.h"
20 #include "scroll.h"
21 #include "nonclient.h"
22 #include "queue.h"
23 #include "selectors.h"
24 #include "tweak.h"
25 #include "debugtools.h"
26 #include "options.h"
27 #include "shellapi.h"
28 #include "cache.h"
29 #include "bitmap.h"
31 DECLARE_DEBUG_CHANNEL(nonclient)
32 DECLARE_DEBUG_CHANNEL(shell)
34 BOOL NC_DrawGrayButton(HDC hdc, int x, int y);
36 static HBITMAP16 hbitmapClose = 0;
37 static HBITMAP16 hbitmapCloseD = 0;
38 static HBITMAP16 hbitmapMinimize = 0;
39 static HBITMAP16 hbitmapMinimizeD = 0;
40 static HBITMAP16 hbitmapMaximize = 0;
41 static HBITMAP16 hbitmapMaximizeD = 0;
42 static HBITMAP16 hbitmapRestore = 0;
43 static HBITMAP16 hbitmapRestoreD = 0;
45 BYTE lpGrayMask[] = { 0xAA, 0xA0,
46 0x55, 0x50,
47 0xAA, 0xA0,
48 0x55, 0x50,
49 0xAA, 0xA0,
50 0x55, 0x50,
51 0xAA, 0xA0,
52 0x55, 0x50,
53 0xAA, 0xA0,
54 0x55, 0x50};
56 #define SC_ABOUTWINE (SC_SCREENSAVE+1)
57 #define SC_PUTMARK (SC_SCREENSAVE+2)
59 /* Some useful macros */
60 #define HAS_DLGFRAME(style,exStyle) \
61 (((exStyle) & WS_EX_DLGMODALFRAME) || \
62 (((style) & WS_DLGFRAME) && !((style) & WS_THICKFRAME)))
64 #define HAS_THICKFRAME(style,exStyle) \
65 (((style) & WS_THICKFRAME) && \
66 !((exStyle) & WS_EX_DLGMODALFRAME))
68 #define HAS_THINFRAME(style) \
69 (((style) & WS_BORDER) || !((style) & (WS_CHILD | WS_POPUP)))
71 #define HAS_BIGFRAME(style,exStyle) \
72 (((style) & (WS_THICKFRAME | WS_DLGFRAME)) || \
73 ((exStyle) & WS_EX_DLGMODALFRAME))
75 #define HAS_ANYFRAME(style,exStyle) \
76 (((style) & (WS_THICKFRAME | WS_DLGFRAME | WS_BORDER)) || \
77 ((exStyle) & WS_EX_DLGMODALFRAME) || \
78 !((style) & (WS_CHILD | WS_POPUP)))
80 #define HAS_MENU(w) (!((w)->dwStyle & WS_CHILD) && ((w)->wIDmenu != 0))
82 #define ON_LEFT_BORDER(hit) \
83 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
84 #define ON_RIGHT_BORDER(hit) \
85 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
86 #define ON_TOP_BORDER(hit) \
87 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
88 #define ON_BOTTOM_BORDER(hit) \
89 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
91 /***********************************************************************
92 * WIN_WindowNeedsWMBorder
94 * This method defines the rules for a window to have a WM border,
95 * caption... It is used for consitency purposes.
97 BOOL WIN_WindowNeedsWMBorder( DWORD style, DWORD exStyle )
99 if (!(style & WS_CHILD) && Options.managed &&
100 (((style & WS_CAPTION) == WS_CAPTION) ||
101 (style & WS_THICKFRAME)))
102 return TRUE;
103 return FALSE;
106 /***********************************************************************
107 * NC_AdjustRect
109 * Compute the size of the window rectangle from the size of the
110 * client rectangle.
112 static void NC_AdjustRect( LPRECT16 rect, DWORD style, BOOL menu,
113 DWORD exStyle )
115 if (TWEAK_WineLook > WIN31_LOOK)
116 ERR_(nonclient)("Called in Win95 mode. Aiee! Please report this.\n" );
118 if(style & WS_ICONIC) return;
119 /* Decide if the window will be managed (see CreateWindowEx) */
120 if (!WIN_WindowNeedsWMBorder(style, exStyle))
122 if (HAS_THICKFRAME( style, exStyle ))
123 InflateRect16( rect, GetSystemMetrics(SM_CXFRAME), GetSystemMetrics(SM_CYFRAME) );
124 else
125 if (HAS_DLGFRAME( style, exStyle ))
126 InflateRect16( rect, GetSystemMetrics(SM_CXDLGFRAME), GetSystemMetrics(SM_CYDLGFRAME) );
127 else
128 if (HAS_THINFRAME( style ))
129 InflateRect16( rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
131 if ((style & WS_CAPTION) == WS_CAPTION)
132 rect->top -= GetSystemMetrics(SM_CYCAPTION) - GetSystemMetrics(SM_CYBORDER);
134 if (menu) rect->top -= GetSystemMetrics(SM_CYMENU) + GetSystemMetrics(SM_CYBORDER);
136 if (style & WS_VSCROLL) {
137 rect->right += GetSystemMetrics(SM_CXVSCROLL) - 1;
138 if(!HAS_ANYFRAME( style, exStyle ))
139 rect->right++;
142 if (style & WS_HSCROLL) {
143 rect->bottom += GetSystemMetrics(SM_CYHSCROLL) - 1;
144 if(!HAS_ANYFRAME( style, exStyle ))
145 rect->bottom++;
150 /******************************************************************************
151 * NC_AdjustRectOuter95
153 * Computes the size of the "outside" parts of the window based on the
154 * parameters of the client area.
156 + PARAMS
157 * LPRECT16 rect
158 * DWORD style
159 * BOOL32 menu
160 * DWORD exStyle
162 * NOTES
163 * "Outer" parts of a window means the whole window frame, caption and
164 * menu bar. It does not include "inner" parts of the frame like client
165 * edge, static edge or scroll bars.
167 * Revision history
168 * 05-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu)
169 * Original (NC_AdjustRect95) cut & paste from NC_AdjustRect
171 * 20-Jun-1998 Eric Kohl (ekohl@abo.rhein-zeitung.de)
172 * Split NC_AdjustRect95 into NC_AdjustRectOuter95 and
173 * NC_AdjustRectInner95 and added handling of Win95 styles.
175 * 28-Jul-1999 Ove Kåven (ovek@arcticnet.no)
176 * Streamlined window style checks.
178 *****************************************************************************/
180 static void
181 NC_AdjustRectOuter95 (LPRECT16 rect, DWORD style, BOOL menu, DWORD exStyle)
183 if(style & WS_ICONIC) return;
185 /* Decide if the window will be managed (see CreateWindowEx) */
186 if (!WIN_WindowNeedsWMBorder(style, exStyle))
188 if (HAS_THICKFRAME( style, exStyle ))
189 InflateRect16( rect, GetSystemMetrics(SM_CXFRAME), GetSystemMetrics(SM_CYFRAME) );
190 else
191 if (HAS_DLGFRAME( style, exStyle ))
192 InflateRect16(rect, GetSystemMetrics(SM_CXDLGFRAME), GetSystemMetrics(SM_CYDLGFRAME) );
193 else
194 if (HAS_THINFRAME( style ))
195 InflateRect16( rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
197 if ((style & WS_CAPTION) == WS_CAPTION)
199 if (exStyle & WS_EX_TOOLWINDOW)
200 rect->top -= GetSystemMetrics(SM_CYSMCAPTION);
201 else
202 rect->top -= GetSystemMetrics(SM_CYCAPTION);
206 if (menu)
207 rect->top -= GetSystemMetrics(SM_CYMENU);
211 /******************************************************************************
212 * NC_AdjustRectInner95
214 * Computes the size of the "inside" part of the window based on the
215 * parameters of the client area.
217 + PARAMS
218 * LPRECT16 rect
219 * DWORD style
220 * DWORD exStyle
222 * NOTES
223 * "Inner" part of a window means the window frame inside of the flat
224 * window frame. It includes the client edge, the static edge and the
225 * scroll bars.
227 * Revision history
228 * 05-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu)
229 * Original (NC_AdjustRect95) cut & paste from NC_AdjustRect
231 * 20-Jun-1998 Eric Kohl (ekohl@abo.rhein-zeitung.de)
232 * Split NC_AdjustRect95 into NC_AdjustRectOuter95 and
233 * NC_AdjustRectInner95 and added handling of Win95 styles.
235 *****************************************************************************/
237 static void
238 NC_AdjustRectInner95 (LPRECT16 rect, DWORD style, DWORD exStyle)
240 if(style & WS_ICONIC) return;
242 if (exStyle & WS_EX_CLIENTEDGE)
243 InflateRect16 (rect, GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE));
245 if (exStyle & WS_EX_STATICEDGE)
246 InflateRect16 (rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
248 if (style & WS_VSCROLL) rect->right += GetSystemMetrics(SM_CXVSCROLL);
249 if (style & WS_HSCROLL) rect->bottom += GetSystemMetrics(SM_CYHSCROLL);
253 /***********************************************************************
254 * DrawCaption16 [USER.660] Draws a caption bar
256 * PARAMS
257 * hwnd [I]
258 * hdc [I]
259 * lpRect [I]
260 * uFlags [I]
262 * RETURNS
263 * Success:
264 * Failure:
267 BOOL16 WINAPI
268 DrawCaption16 (HWND16 hwnd, HDC16 hdc, const RECT16 *rect, UINT16 uFlags)
270 RECT rect32;
272 if (rect)
273 CONV_RECT16TO32 (rect, &rect32);
275 return (BOOL16)DrawCaptionTempA (hwnd, hdc, rect ? &rect32 : NULL,
276 0, 0, NULL, uFlags & 0x1F);
280 /***********************************************************************
281 * DrawCaption32 [USER32.154] Draws a caption bar
283 * PARAMS
284 * hwnd [I]
285 * hdc [I]
286 * lpRect [I]
287 * uFlags [I]
289 * RETURNS
290 * Success:
291 * Failure:
294 BOOL WINAPI
295 DrawCaption (HWND hwnd, HDC hdc, const RECT *lpRect, UINT uFlags)
297 return DrawCaptionTempA (hwnd, hdc, lpRect, 0, 0, NULL, uFlags & 0x1F);
301 /***********************************************************************
302 * DrawCaptionTemp16 [USER.657]
304 * PARAMS
306 * RETURNS
307 * Success:
308 * Failure:
311 BOOL16 WINAPI
312 DrawCaptionTemp16 (HWND16 hwnd, HDC16 hdc, const RECT16 *rect, HFONT16 hFont,
313 HICON16 hIcon, LPCSTR str, UINT16 uFlags)
315 RECT rect32;
317 if (rect)
318 CONV_RECT16TO32(rect,&rect32);
320 return (BOOL16)DrawCaptionTempA (hwnd, hdc, rect?&rect32:NULL, hFont,
321 hIcon, str, uFlags & 0x1F);
325 /***********************************************************************
326 * DrawCaptionTemp32A [USER32.599]
328 * PARAMS
330 * RETURNS
331 * Success:
332 * Failure:
335 BOOL WINAPI
336 DrawCaptionTempA (HWND hwnd, HDC hdc, const RECT *rect, HFONT hFont,
337 HICON hIcon, LPCSTR str, UINT uFlags)
339 RECT rc = *rect;
341 TRACE_(nonclient)("(%08x,%08x,%p,%08x,%08x,\"%s\",%08x)\n",
342 hwnd, hdc, rect, hFont, hIcon, str, uFlags);
344 /* drawing background */
345 if (uFlags & DC_INBUTTON) {
346 FillRect (hdc, &rc, GetSysColorBrush (COLOR_3DFACE));
348 if (uFlags & DC_ACTIVE) {
349 HBRUSH hbr = SelectObject (hdc, CACHE_GetPattern55AABrush ());
350 PatBlt (hdc, rc.left, rc.top,
351 rc.right-rc.left, rc.bottom-rc.top, 0xFA0089);
352 SelectObject (hdc, hbr);
355 else {
356 FillRect (hdc, &rc, GetSysColorBrush ((uFlags & DC_ACTIVE) ?
357 COLOR_ACTIVECAPTION : COLOR_INACTIVECAPTION));
361 /* drawing icon */
362 if ((uFlags & DC_ICON) && !(uFlags & DC_SMALLCAP)) {
363 POINT pt;
365 pt.x = rc.left + 2;
366 pt.y = (rc.bottom + rc.top - GetSystemMetrics(SM_CYSMICON)) / 2;
368 if (hIcon) {
369 DrawIconEx (hdc, pt.x, pt.y, hIcon, GetSystemMetrics(SM_CXSMICON),
370 GetSystemMetrics(SM_CYSMICON), 0, 0, DI_NORMAL);
372 else {
373 HICON hAppIcon = (HICON) GetClassLongA(hwnd, GCL_HICONSM);
374 if(!hAppIcon) hAppIcon = (HICON) GetClassLongA(hwnd, GCL_HICON);
376 DrawIconEx (hdc, pt.x, pt.y, hAppIcon, GetSystemMetrics(SM_CXSMICON),
377 GetSystemMetrics(SM_CYSMICON), 0, 0, DI_NORMAL);
380 rc.left += (rc.bottom - rc.top);
383 /* drawing text */
384 if (uFlags & DC_TEXT) {
385 HFONT hOldFont;
387 if (uFlags & DC_INBUTTON)
388 SetTextColor (hdc, GetSysColor (COLOR_BTNTEXT));
389 else if (uFlags & DC_ACTIVE)
390 SetTextColor (hdc, GetSysColor (COLOR_CAPTIONTEXT));
391 else
392 SetTextColor (hdc, GetSysColor (COLOR_INACTIVECAPTIONTEXT));
394 SetBkMode (hdc, TRANSPARENT);
396 if (hFont)
397 hOldFont = SelectObject (hdc, hFont);
398 else {
399 NONCLIENTMETRICSA nclm;
400 HFONT hNewFont;
401 nclm.cbSize = sizeof(NONCLIENTMETRICSA);
402 SystemParametersInfoA (SPI_GETNONCLIENTMETRICS, 0, &nclm, 0);
403 hNewFont = CreateFontIndirectA ((uFlags & DC_SMALLCAP) ?
404 &nclm.lfSmCaptionFont : &nclm.lfCaptionFont);
405 hOldFont = SelectObject (hdc, hNewFont);
408 if (str)
409 DrawTextA (hdc, str, -1, &rc,
410 DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX | DT_LEFT);
411 else {
412 CHAR szText[128];
413 INT nLen;
414 nLen = GetWindowTextA (hwnd, szText, 128);
415 DrawTextA (hdc, szText, nLen, &rc,
416 DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX | DT_LEFT);
419 if (hFont)
420 SelectObject (hdc, hOldFont);
421 else
422 DeleteObject (SelectObject (hdc, hOldFont));
425 /* drawing focus ??? */
426 if (uFlags & 0x2000)
427 FIXME_(nonclient)("undocumented flag (0x2000)!\n");
429 return 0;
433 /***********************************************************************
434 * DrawCaptionTemp32W [USER32.602]
436 * PARAMS
438 * RETURNS
439 * Success:
440 * Failure:
443 BOOL WINAPI
444 DrawCaptionTempW (HWND hwnd, HDC hdc, const RECT *rect, HFONT hFont,
445 HICON hIcon, LPCWSTR str, UINT uFlags)
447 LPSTR p = HEAP_strdupWtoA (GetProcessHeap (), 0, str);
448 BOOL res = DrawCaptionTempA (hwnd, hdc, rect, hFont, hIcon, p, uFlags);
449 HeapFree (GetProcessHeap (), 0, p);
450 return res;
454 /***********************************************************************
455 * AdjustWindowRect16 (USER.102)
457 BOOL16 WINAPI AdjustWindowRect16( LPRECT16 rect, DWORD style, BOOL16 menu )
459 return AdjustWindowRectEx16( rect, style, menu, 0 );
463 /***********************************************************************
464 * AdjustWindowRect32 (USER32.2)
466 BOOL WINAPI AdjustWindowRect( LPRECT rect, DWORD style, BOOL menu )
468 return AdjustWindowRectEx( rect, style, menu, 0 );
472 /***********************************************************************
473 * AdjustWindowRectEx16 (USER.454)
475 BOOL16 WINAPI AdjustWindowRectEx16( LPRECT16 rect, DWORD style,
476 BOOL16 menu, DWORD exStyle )
478 /* Correct the window style */
480 if (!(style & (WS_POPUP | WS_CHILD))) /* Overlapped window */
481 style |= WS_CAPTION;
482 style &= (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME | WS_CHILD);
483 exStyle &= (WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE |
484 WS_EX_STATICEDGE | WS_EX_TOOLWINDOW);
485 if (exStyle & WS_EX_DLGMODALFRAME) style &= ~WS_THICKFRAME;
487 TRACE_(nonclient)("(%d,%d)-(%d,%d) %08lx %d %08lx\n",
488 rect->left, rect->top, rect->right, rect->bottom,
489 style, menu, exStyle );
491 if (TWEAK_WineLook == WIN31_LOOK)
492 NC_AdjustRect( rect, style, menu, exStyle );
493 else {
494 NC_AdjustRectOuter95( rect, style, menu, exStyle );
495 NC_AdjustRectInner95( rect, style, exStyle );
498 return TRUE;
502 /***********************************************************************
503 * AdjustWindowRectEx32 (USER32.3)
505 BOOL WINAPI AdjustWindowRectEx( LPRECT rect, DWORD style,
506 BOOL menu, DWORD exStyle )
508 RECT16 rect16;
509 BOOL ret;
511 CONV_RECT32TO16( rect, &rect16 );
512 ret = AdjustWindowRectEx16( &rect16, style, (BOOL16)menu, exStyle );
513 CONV_RECT16TO32( &rect16, rect );
514 return ret;
518 /***********************************************************************
519 * NC_HandleNCCalcSize
521 * Handle a WM_NCCALCSIZE message. Called from DefWindowProc().
523 LONG NC_HandleNCCalcSize( WND *pWnd, RECT *winRect )
525 RECT16 tmpRect = { 0, 0, 0, 0 };
526 LONG result = 0;
527 UINT style = (UINT) GetClassLongA(pWnd->hwndSelf, GCL_STYLE);
529 if (style & CS_VREDRAW) result |= WVR_VREDRAW;
530 if (style & CS_HREDRAW) result |= WVR_HREDRAW;
532 if( !( pWnd->dwStyle & WS_MINIMIZE ) ) {
533 if (TWEAK_WineLook == WIN31_LOOK)
534 NC_AdjustRect( &tmpRect, pWnd->dwStyle, FALSE, pWnd->dwExStyle );
535 else
536 NC_AdjustRectOuter95( &tmpRect, pWnd->dwStyle, FALSE, pWnd->dwExStyle );
538 winRect->left -= tmpRect.left;
539 winRect->top -= tmpRect.top;
540 winRect->right -= tmpRect.right;
541 winRect->bottom -= tmpRect.bottom;
543 if (HAS_MENU(pWnd)) {
544 TRACE_(nonclient)("Calling "
545 "GetMenuBarHeight with HWND 0x%x, width %d, "
546 "at (%d, %d).\n", pWnd->hwndSelf,
547 winRect->right - winRect->left,
548 -tmpRect.left, -tmpRect.top );
550 winRect->top +=
551 MENU_GetMenuBarHeight( pWnd->hwndSelf,
552 winRect->right - winRect->left,
553 -tmpRect.left, -tmpRect.top ) + 1;
556 if (TWEAK_WineLook > WIN31_LOOK) {
557 SetRect16 (&tmpRect, 0, 0, 0, 0);
558 NC_AdjustRectInner95 (&tmpRect, pWnd->dwStyle, pWnd->dwExStyle);
559 winRect->left -= tmpRect.left;
560 winRect->top -= tmpRect.top;
561 winRect->right -= tmpRect.right;
562 winRect->bottom -= tmpRect.bottom;
565 return result;
569 /***********************************************************************
570 * NC_GetInsideRect
572 * Get the 'inside' rectangle of a window, i.e. the whole window rectangle
573 * but without the borders (if any).
574 * The rectangle is in window coordinates (for drawing with GetWindowDC()).
576 static void NC_GetInsideRect( HWND hwnd, RECT *rect )
578 WND * wndPtr = WIN_FindWndPtr( hwnd );
580 rect->top = rect->left = 0;
581 rect->right = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
582 rect->bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
584 if ((wndPtr->dwStyle & WS_ICONIC) || (wndPtr->flags & WIN_MANAGED)) goto END;
586 /* Remove frame from rectangle */
587 if (HAS_THICKFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
588 InflateRect( rect, -GetSystemMetrics(SM_CXFRAME), -GetSystemMetrics(SM_CYFRAME) );
589 else
590 if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
592 InflateRect( rect, -GetSystemMetrics(SM_CXDLGFRAME), -GetSystemMetrics(SM_CYDLGFRAME));
593 /* FIXME: this isn't in NC_AdjustRect? why not? */
594 if (wndPtr->dwExStyle & WS_EX_DLGMODALFRAME)
595 InflateRect( rect, -1, 0 );
597 else
598 if (HAS_THINFRAME( wndPtr->dwStyle ))
599 InflateRect( rect, -GetSystemMetrics(SM_CXBORDER), -GetSystemMetrics(SM_CYBORDER) );
600 END:
601 WIN_ReleaseWndPtr(wndPtr);
602 return;
606 /***********************************************************************
607 * NC_GetInsideRect95
609 * Get the 'inside' rectangle of a window, i.e. the whole window rectangle
610 * but without the borders (if any).
611 * The rectangle is in window coordinates (for drawing with GetWindowDC()).
614 static void
615 NC_GetInsideRect95 (HWND hwnd, RECT *rect)
617 WND * wndPtr = WIN_FindWndPtr( hwnd );
619 rect->top = rect->left = 0;
620 rect->right = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
621 rect->bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
623 if ((wndPtr->dwStyle & WS_ICONIC) || (wndPtr->flags & WIN_MANAGED)) goto END;
625 /* Remove frame from rectangle */
626 if (HAS_THICKFRAME (wndPtr->dwStyle, wndPtr->dwExStyle))
628 InflateRect( rect, -GetSystemMetrics(SM_CXSIZEFRAME), -GetSystemMetrics(SM_CYSIZEFRAME) );
630 else if (HAS_DLGFRAME (wndPtr->dwStyle, wndPtr->dwExStyle ))
632 InflateRect( rect, -GetSystemMetrics(SM_CXFIXEDFRAME), -GetSystemMetrics(SM_CYFIXEDFRAME));
634 else if (HAS_THINFRAME (wndPtr->dwStyle))
636 InflateRect( rect, -GetSystemMetrics(SM_CXBORDER), -GetSystemMetrics(SM_CYBORDER) );
639 if (wndPtr->dwStyle & WS_CHILD) {
640 if (wndPtr->dwExStyle & WS_EX_CLIENTEDGE)
641 InflateRect (rect, -GetSystemMetrics(SM_CXEDGE), -GetSystemMetrics(SM_CYEDGE));
643 if (wndPtr->dwExStyle & WS_EX_STATICEDGE)
644 InflateRect (rect, -GetSystemMetrics(SM_CXBORDER), -GetSystemMetrics(SM_CYBORDER));
646 END:
647 WIN_ReleaseWndPtr(wndPtr);
648 return;
652 /***********************************************************************
653 * NC_DoNCHitTest
655 * Handle a WM_NCHITTEST message. Called from NC_HandleNcHitTest().
658 static LONG NC_DoNCHitTest (WND *wndPtr, POINT16 pt )
660 RECT16 rect;
662 TRACE_(nonclient)("hwnd=%04x pt=%d,%d\n",
663 wndPtr->hwndSelf, pt.x, pt.y );
665 GetWindowRect16 (wndPtr->hwndSelf, &rect );
666 if (!PtInRect16( &rect, pt )) return HTNOWHERE;
668 if (wndPtr->dwStyle & WS_MINIMIZE) return HTCAPTION;
670 if (!(wndPtr->flags & WIN_MANAGED))
672 /* Check borders */
673 if (HAS_THICKFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
675 InflateRect16( &rect, -GetSystemMetrics(SM_CXFRAME), -GetSystemMetrics(SM_CYFRAME) );
676 if (!PtInRect16( &rect, pt ))
678 /* Check top sizing border */
679 if (pt.y < rect.top)
681 if (pt.x < rect.left+GetSystemMetrics(SM_CXSIZE)) return HTTOPLEFT;
682 if (pt.x >= rect.right-GetSystemMetrics(SM_CXSIZE)) return HTTOPRIGHT;
683 return HTTOP;
685 /* Check bottom sizing border */
686 if (pt.y >= rect.bottom)
688 if (pt.x < rect.left+GetSystemMetrics(SM_CXSIZE)) return HTBOTTOMLEFT;
689 if (pt.x >= rect.right-GetSystemMetrics(SM_CXSIZE)) return HTBOTTOMRIGHT;
690 return HTBOTTOM;
692 /* Check left sizing border */
693 if (pt.x < rect.left)
695 if (pt.y < rect.top+GetSystemMetrics(SM_CYSIZE)) return HTTOPLEFT;
696 if (pt.y >= rect.bottom-GetSystemMetrics(SM_CYSIZE)) return HTBOTTOMLEFT;
697 return HTLEFT;
699 /* Check right sizing border */
700 if (pt.x >= rect.right)
702 if (pt.y < rect.top+GetSystemMetrics(SM_CYSIZE)) return HTTOPRIGHT;
703 if (pt.y >= rect.bottom-GetSystemMetrics(SM_CYSIZE)) return HTBOTTOMRIGHT;
704 return HTRIGHT;
708 else /* No thick frame */
710 if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
711 InflateRect16(&rect, -GetSystemMetrics(SM_CXDLGFRAME), -GetSystemMetrics(SM_CYDLGFRAME));
712 else if (HAS_THINFRAME( wndPtr->dwStyle ))
713 InflateRect16(&rect, -GetSystemMetrics(SM_CXBORDER), -GetSystemMetrics(SM_CYBORDER));
714 if (!PtInRect16( &rect, pt )) return HTBORDER;
717 /* Check caption */
719 if ((wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION)
721 rect.top += GetSystemMetrics(SM_CYCAPTION) - GetSystemMetrics(SM_CYBORDER);
722 if (!PtInRect16( &rect, pt ))
724 /* Check system menu */
725 if (wndPtr->dwStyle & WS_SYSMENU)
726 rect.left += GetSystemMetrics(SM_CXSIZE);
727 if (pt.x <= rect.left) return HTSYSMENU;
729 /* Check maximize box */
730 if (wndPtr->dwStyle & WS_MAXIMIZEBOX)
731 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
733 if (pt.x >= rect.right) return HTMAXBUTTON;
734 /* Check minimize box */
735 if (wndPtr->dwStyle & WS_MINIMIZEBOX)
736 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
737 if (pt.x >= rect.right) return HTMINBUTTON;
738 return HTCAPTION;
743 /* Check client area */
745 ScreenToClient16( wndPtr->hwndSelf, &pt );
746 GetClientRect16( wndPtr->hwndSelf, &rect );
747 if (PtInRect16( &rect, pt )) return HTCLIENT;
749 /* Check vertical scroll bar */
751 if (wndPtr->dwStyle & WS_VSCROLL)
753 rect.right += GetSystemMetrics(SM_CXVSCROLL);
754 if (PtInRect16( &rect, pt )) return HTVSCROLL;
757 /* Check horizontal scroll bar */
759 if (wndPtr->dwStyle & WS_HSCROLL)
761 rect.bottom += GetSystemMetrics(SM_CYHSCROLL);
762 if (PtInRect16( &rect, pt ))
764 /* Check size box */
765 if ((wndPtr->dwStyle & WS_VSCROLL) &&
766 (pt.x >= rect.right - GetSystemMetrics(SM_CXVSCROLL)))
767 return HTSIZE;
768 return HTHSCROLL;
772 /* Check menu bar */
774 if (HAS_MENU(wndPtr))
776 if ((pt.y < 0) && (pt.x >= 0) && (pt.x < rect.right))
777 return HTMENU;
780 /* Should never get here */
781 return HTERROR;
785 /***********************************************************************
786 * NC_DoNCHitTest95
788 * Handle a WM_NCHITTEST message. Called from NC_HandleNCHitTest().
790 * FIXME: Just a modified copy of the Win 3.1 version.
793 static LONG
794 NC_DoNCHitTest95 (WND *wndPtr, POINT16 pt )
796 RECT16 rect;
798 TRACE_(nonclient)("hwnd=%04x pt=%d,%d\n",
799 wndPtr->hwndSelf, pt.x, pt.y );
801 GetWindowRect16 (wndPtr->hwndSelf, &rect );
802 if (!PtInRect16( &rect, pt )) return HTNOWHERE;
804 if (wndPtr->dwStyle & WS_MINIMIZE) return HTCAPTION;
806 if (!(wndPtr->flags & WIN_MANAGED))
808 /* Check borders */
809 if (HAS_THICKFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
811 InflateRect16( &rect, -GetSystemMetrics(SM_CXFRAME), -GetSystemMetrics(SM_CYFRAME) );
812 if (!PtInRect16( &rect, pt ))
814 /* Check top sizing border */
815 if (pt.y < rect.top)
817 if (pt.x < rect.left+GetSystemMetrics(SM_CXSIZE)) return HTTOPLEFT;
818 if (pt.x >= rect.right-GetSystemMetrics(SM_CXSIZE)) return HTTOPRIGHT;
819 return HTTOP;
821 /* Check bottom sizing border */
822 if (pt.y >= rect.bottom)
824 if (pt.x < rect.left+GetSystemMetrics(SM_CXSIZE)) return HTBOTTOMLEFT;
825 if (pt.x >= rect.right-GetSystemMetrics(SM_CXSIZE)) return HTBOTTOMRIGHT;
826 return HTBOTTOM;
828 /* Check left sizing border */
829 if (pt.x < rect.left)
831 if (pt.y < rect.top+GetSystemMetrics(SM_CYSIZE)) return HTTOPLEFT;
832 if (pt.y >= rect.bottom-GetSystemMetrics(SM_CYSIZE)) return HTBOTTOMLEFT;
833 return HTLEFT;
835 /* Check right sizing border */
836 if (pt.x >= rect.right)
838 if (pt.y < rect.top+GetSystemMetrics(SM_CYSIZE)) return HTTOPRIGHT;
839 if (pt.y >= rect.bottom-GetSystemMetrics(SM_CYSIZE)) return HTBOTTOMRIGHT;
840 return HTRIGHT;
844 else /* No thick frame */
846 if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
847 InflateRect16(&rect, -GetSystemMetrics(SM_CXDLGFRAME), -GetSystemMetrics(SM_CYDLGFRAME));
848 else if (HAS_THINFRAME( wndPtr->dwStyle ))
849 InflateRect16(&rect, -GetSystemMetrics(SM_CXBORDER), -GetSystemMetrics(SM_CYBORDER));
850 if (!PtInRect16( &rect, pt )) return HTBORDER;
853 /* Check caption */
855 if ((wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION)
857 if (wndPtr->dwExStyle & WS_EX_TOOLWINDOW)
858 rect.top += GetSystemMetrics(SM_CYSMCAPTION) - 1;
859 else
860 rect.top += GetSystemMetrics(SM_CYCAPTION) - 1;
861 if (!PtInRect16( &rect, pt ))
863 /* Check system menu */
864 if ((wndPtr->dwStyle & WS_SYSMENU) && (!(wndPtr->dwStyle & DS_MODALFRAME)))
865 rect.left += GetSystemMetrics(SM_CYCAPTION) - 1;
866 if (pt.x < rect.left) return HTSYSMENU;
868 /* Check close button */
869 if (wndPtr->dwStyle & WS_SYSMENU)
870 rect.right -= GetSystemMetrics(SM_CYCAPTION) - 1;
871 if (pt.x > rect.right) return HTCLOSE;
873 /* Check maximize box */
874 /* In win95 there is automatically a Maximize button when there is a minimize one*/
875 if ((wndPtr->dwStyle & WS_MAXIMIZEBOX)|| (wndPtr->dwStyle & WS_MINIMIZEBOX))
876 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
877 if (pt.x > rect.right) return HTMAXBUTTON;
879 /* Check minimize box */
880 /* In win95 there is automatically a Maximize button when there is a Maximize one*/
881 if ((wndPtr->dwStyle & WS_MINIMIZEBOX)||(wndPtr->dwStyle & WS_MAXIMIZEBOX))
882 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
884 if (pt.x > rect.right) return HTMINBUTTON;
885 return HTCAPTION;
890 /* Check client area */
892 ScreenToClient16( wndPtr->hwndSelf, &pt );
893 GetClientRect16( wndPtr->hwndSelf, &rect );
894 if (PtInRect16( &rect, pt )) return HTCLIENT;
896 /* Check vertical scroll bar */
898 if (wndPtr->dwStyle & WS_VSCROLL)
900 rect.right += GetSystemMetrics(SM_CXVSCROLL);
901 if (PtInRect16( &rect, pt )) return HTVSCROLL;
904 /* Check horizontal scroll bar */
906 if (wndPtr->dwStyle & WS_HSCROLL)
908 rect.bottom += GetSystemMetrics(SM_CYHSCROLL);
909 if (PtInRect16( &rect, pt ))
911 /* Check size box */
912 if ((wndPtr->dwStyle & WS_VSCROLL) &&
913 (pt.x >= rect.right - GetSystemMetrics(SM_CXVSCROLL)))
914 return HTSIZE;
915 return HTHSCROLL;
919 /* Check menu bar */
921 if (HAS_MENU(wndPtr))
923 if ((pt.y < 0) && (pt.x >= 0) && (pt.x < rect.right))
924 return HTMENU;
927 /* Should never get here */
928 return HTERROR;
932 /***********************************************************************
933 * NC_HandleNCHitTest
935 * Handle a WM_NCHITTEST message. Called from DefWindowProc().
937 LONG
938 NC_HandleNCHitTest (HWND hwnd , POINT16 pt)
940 LONG retvalue;
941 WND *wndPtr = WIN_FindWndPtr (hwnd);
943 if (!wndPtr)
944 return HTERROR;
946 if (TWEAK_WineLook == WIN31_LOOK)
947 retvalue = NC_DoNCHitTest (wndPtr, pt);
948 else
949 retvalue = NC_DoNCHitTest95 (wndPtr, pt);
950 WIN_ReleaseWndPtr(wndPtr);
951 return retvalue;
955 /***********************************************************************
956 * NC_DrawSysButton
958 void NC_DrawSysButton( HWND hwnd, HDC hdc, BOOL down )
960 RECT rect;
961 HDC hdcMem;
962 HBITMAP hbitmap;
963 WND *wndPtr = WIN_FindWndPtr( hwnd );
965 if( !(wndPtr->flags & WIN_MANAGED) )
967 NC_GetInsideRect( hwnd, &rect );
968 hdcMem = CreateCompatibleDC( hdc );
969 hbitmap = SelectObject( hdcMem, hbitmapClose );
970 BitBlt(hdc, rect.left, rect.top, GetSystemMetrics(SM_CXSIZE), GetSystemMetrics(SM_CYSIZE),
971 hdcMem, (wndPtr->dwStyle & WS_CHILD) ? GetSystemMetrics(SM_CXSIZE) : 0, 0,
972 down ? NOTSRCCOPY : SRCCOPY );
973 SelectObject( hdcMem, hbitmap );
974 DeleteDC( hdcMem );
976 WIN_ReleaseWndPtr(wndPtr);
980 /***********************************************************************
981 * NC_DrawMaxButton
983 static void NC_DrawMaxButton( HWND hwnd, HDC16 hdc, BOOL down )
985 RECT rect;
986 WND *wndPtr = WIN_FindWndPtr( hwnd );
987 HDC hdcMem;
989 if( !(wndPtr->flags & WIN_MANAGED) )
991 NC_GetInsideRect( hwnd, &rect );
992 hdcMem = CreateCompatibleDC( hdc );
993 SelectObject( hdcMem, (IsZoomed(hwnd)
994 ? (down ? hbitmapRestoreD : hbitmapRestore)
995 : (down ? hbitmapMaximizeD : hbitmapMaximize)) );
996 BitBlt( hdc, rect.right - GetSystemMetrics(SM_CXSIZE) - 1, rect.top,
997 GetSystemMetrics(SM_CXSIZE) + 1, GetSystemMetrics(SM_CYSIZE), hdcMem, 0, 0,
998 SRCCOPY );
999 DeleteDC( hdcMem );
1001 WIN_ReleaseWndPtr(wndPtr);
1006 /***********************************************************************
1007 * NC_DrawMinButton
1009 static void NC_DrawMinButton( HWND hwnd, HDC16 hdc, BOOL down )
1011 RECT rect;
1012 WND *wndPtr = WIN_FindWndPtr( hwnd );
1013 HDC hdcMem;
1015 if( !(wndPtr->flags & WIN_MANAGED) )
1017 NC_GetInsideRect( hwnd, &rect );
1018 hdcMem = CreateCompatibleDC( hdc );
1019 SelectObject( hdcMem, (down ? hbitmapMinimizeD : hbitmapMinimize) );
1020 if (wndPtr->dwStyle & WS_MAXIMIZEBOX) rect.right -= GetSystemMetrics(SM_CXSIZE)+1;
1021 BitBlt( hdc, rect.right - GetSystemMetrics(SM_CXSIZE) - 1, rect.top,
1022 GetSystemMetrics(SM_CXSIZE) + 1, GetSystemMetrics(SM_CYSIZE), hdcMem, 0, 0,
1023 SRCCOPY );
1024 DeleteDC( hdcMem );
1026 WIN_ReleaseWndPtr(wndPtr);
1030 /******************************************************************************
1032 * void NC_DrawSysButton95(
1033 * HWND32 hwnd,
1034 * HDC32 hdc,
1035 * BOOL32 down )
1037 * Draws the Win95 system icon.
1039 * Revision history
1040 * 05-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu)
1041 * Original implementation from NC_DrawSysButton source.
1042 * 11-Jun-1998 Eric Kohl (ekohl@abo.rhein-zeitung.de)
1043 * Fixed most bugs.
1045 *****************************************************************************/
1047 BOOL
1048 NC_DrawSysButton95 (HWND hwnd, HDC hdc, BOOL down)
1050 WND *wndPtr = WIN_FindWndPtr( hwnd );
1052 if( !(wndPtr->flags & WIN_MANAGED) )
1054 HICON hIcon;
1055 RECT rect;
1057 NC_GetInsideRect95( hwnd, &rect );
1059 hIcon = (HICON) GetClassLongA(wndPtr->hwndSelf, GCL_HICONSM);
1060 if(!hIcon) hIcon = (HICON) GetClassLongA(wndPtr->hwndSelf, GCL_HICON);
1062 /* If there is no hIcon specified or this is not a modal dialog, */
1063 /* get the default one. */
1064 if(hIcon == 0)
1065 if (!(wndPtr->dwStyle & DS_MODALFRAME))
1066 hIcon = LoadImageA(0, MAKEINTRESOURCEA(OIC_WINEICON), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
1068 if (hIcon)
1069 DrawIconEx (hdc, rect.left + 2, rect.top + 2, hIcon,
1070 GetSystemMetrics(SM_CXSMICON),
1071 GetSystemMetrics(SM_CYSMICON),
1072 0, 0, DI_NORMAL);
1074 WIN_ReleaseWndPtr(wndPtr);
1075 return (hIcon != 0);
1077 WIN_ReleaseWndPtr(wndPtr);
1078 return FALSE;
1082 /******************************************************************************
1084 * void NC_DrawCloseButton95(
1085 * HWND32 hwnd,
1086 * HDC32 hdc,
1087 * BOOL32 down,
1088 * BOOL bGrayed )
1090 * Draws the Win95 close button.
1092 * If bGrayed is true, then draw a disabled Close button
1094 * Revision history
1095 * 11-Jun-1998 Eric Kohl (ekohl@abo.rhein-zeitung.de)
1096 * Original implementation from NC_DrawSysButton95 source.
1098 *****************************************************************************/
1100 static void NC_DrawCloseButton95 (HWND hwnd, HDC hdc, BOOL down, BOOL bGrayed)
1102 RECT rect;
1103 HDC hdcMem;
1104 WND *wndPtr = WIN_FindWndPtr( hwnd );
1106 if( !(wndPtr->flags & WIN_MANAGED) )
1108 BITMAP bmp;
1109 HBITMAP hBmp, hOldBmp;
1111 NC_GetInsideRect95( hwnd, &rect );
1113 hdcMem = CreateCompatibleDC( hdc );
1114 hBmp = down ? hbitmapCloseD : hbitmapClose;
1115 hOldBmp = SelectObject (hdcMem, hBmp);
1116 GetObjectA (hBmp, sizeof(BITMAP), &bmp);
1118 BitBlt (hdc, rect.right - (GetSystemMetrics(SM_CYCAPTION) + 1 + bmp.bmWidth) / 2,
1119 rect.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2,
1120 bmp.bmWidth, bmp.bmHeight, hdcMem, 0, 0, SRCCOPY);
1122 if(bGrayed)
1123 NC_DrawGrayButton(hdc,rect.right - (GetSystemMetrics(SM_CYCAPTION) + 1 + bmp.bmWidth) / 2 + 2,
1124 rect.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2 + 2);
1126 SelectObject (hdcMem, hOldBmp);
1127 DeleteDC (hdcMem);
1129 WIN_ReleaseWndPtr(wndPtr);
1132 /******************************************************************************
1134 * NC_DrawMaxButton95(
1135 * HWND32 hwnd,
1136 * HDC16 hdc,
1137 * BOOL32 down
1138 * BOOL bGrayed )
1140 * Draws the maximize button for Win95 style windows.
1142 * If bGrayed is true, then draw a disabled Maximize button
1144 * Bugs
1145 * Many. Spacing might still be incorrect. Need to fit a close
1146 * button between the max button and the edge.
1147 * Should scale the image with the title bar. And more...
1149 * Revision history
1150 * 05-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu)
1151 * Original implementation.
1153 *****************************************************************************/
1155 static void NC_DrawMaxButton95(HWND hwnd,HDC16 hdc,BOOL down, BOOL bGrayed)
1157 RECT rect;
1158 HDC hdcMem;
1159 WND *wndPtr = WIN_FindWndPtr( hwnd );
1161 if( !(wndPtr->flags & WIN_MANAGED))
1163 BITMAP bmp;
1164 HBITMAP hBmp,hOldBmp;
1166 NC_GetInsideRect95( hwnd, &rect );
1167 hdcMem = CreateCompatibleDC( hdc );
1168 hBmp = IsZoomed(hwnd) ?
1169 (down ? hbitmapRestoreD : hbitmapRestore ) :
1170 (down ? hbitmapMaximizeD: hbitmapMaximize);
1171 hOldBmp=SelectObject( hdcMem, hBmp );
1172 GetObjectA (hBmp, sizeof(BITMAP), &bmp);
1174 if (wndPtr->dwStyle & WS_SYSMENU)
1175 rect.right -= GetSystemMetrics(SM_CYCAPTION) + 1;
1177 BitBlt( hdc, rect.right - (GetSystemMetrics(SM_CXSIZE) + bmp.bmWidth) / 2,
1178 rect.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2,
1179 bmp.bmWidth, bmp.bmHeight, hdcMem, 0, 0, SRCCOPY );
1181 if(bGrayed)
1182 NC_DrawGrayButton(hdc, rect.right - (GetSystemMetrics(SM_CXSIZE) + bmp.bmWidth) / 2 + 2,
1183 rect.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2 + 2);
1186 SelectObject (hdcMem, hOldBmp);
1187 DeleteDC( hdcMem );
1189 WIN_ReleaseWndPtr(wndPtr);
1192 /******************************************************************************
1194 * NC_DrawMinButton95(
1195 * HWND32 hwnd,
1196 * HDC16 hdc,
1197 * BOOL32 down,
1198 * BOOL bGrayed )
1200 * Draws the minimize button for Win95 style windows.
1202 * If bGrayed is true, then draw a disabled Minimize button
1204 * Bugs
1205 * Many. Spacing is still incorrect. Should scale the image with the
1206 * title bar. And more...
1208 * Revision history
1209 * 05-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu)
1210 * Original implementation.
1212 *****************************************************************************/
1214 static void NC_DrawMinButton95(HWND hwnd,HDC16 hdc,BOOL down, BOOL bGrayed)
1216 RECT rect;
1217 HDC hdcMem;
1218 WND *wndPtr = WIN_FindWndPtr( hwnd );
1220 if( !(wndPtr->flags & WIN_MANAGED))
1223 BITMAP bmp;
1224 HBITMAP hBmp,hOldBmp;
1226 NC_GetInsideRect95( hwnd, &rect );
1228 hdcMem = CreateCompatibleDC( hdc );
1229 hBmp = down ? hbitmapMinimizeD : hbitmapMinimize;
1230 hOldBmp= SelectObject( hdcMem, hBmp );
1231 GetObjectA (hBmp, sizeof(BITMAP), &bmp);
1233 if (wndPtr->dwStyle & WS_SYSMENU)
1234 rect.right -= GetSystemMetrics(SM_CYCAPTION) + 1;
1236 /* In win 95 there is always a Maximize box when there is a Minimize one */
1237 if ((wndPtr->dwStyle & WS_MAXIMIZEBOX) || (wndPtr->dwStyle & WS_MINIMIZEBOX))
1238 rect.right += -1 - (GetSystemMetrics(SM_CXSIZE) + bmp.bmWidth) / 2;
1240 BitBlt( hdc, rect.right - (GetSystemMetrics(SM_CXSIZE) + bmp.bmWidth) / 2,
1241 rect.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2,
1242 bmp.bmWidth, bmp.bmHeight, hdcMem, 0, 0, SRCCOPY );
1244 if(bGrayed)
1245 NC_DrawGrayButton(hdc, rect.right - (GetSystemMetrics(SM_CXSIZE) + bmp.bmWidth) / 2 + 2,
1246 rect.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2 + 2);
1249 SelectObject (hdcMem, hOldBmp);
1250 DeleteDC( hdcMem );
1252 WIN_ReleaseWndPtr(wndPtr);
1255 /***********************************************************************
1256 * NC_DrawFrame
1258 * Draw a window frame inside the given rectangle, and update the rectangle.
1259 * The correct pen for the frame must be selected in the DC.
1261 static void NC_DrawFrame( HDC hdc, RECT *rect, BOOL dlgFrame,
1262 BOOL active )
1264 INT width, height;
1266 if (TWEAK_WineLook != WIN31_LOOK)
1267 ERR_(nonclient)("Called in Win95 mode. Aiee! Please report this.\n" );
1269 if (dlgFrame)
1271 width = GetSystemMetrics(SM_CXDLGFRAME) - 1;
1272 height = GetSystemMetrics(SM_CYDLGFRAME) - 1;
1273 SelectObject( hdc, GetSysColorBrush(active ? COLOR_ACTIVECAPTION :
1274 COLOR_INACTIVECAPTION) );
1276 else
1278 width = GetSystemMetrics(SM_CXFRAME) - 2;
1279 height = GetSystemMetrics(SM_CYFRAME) - 2;
1280 SelectObject( hdc, GetSysColorBrush(active ? COLOR_ACTIVEBORDER :
1281 COLOR_INACTIVEBORDER) );
1284 /* Draw frame */
1285 PatBlt( hdc, rect->left, rect->top,
1286 rect->right - rect->left, height, PATCOPY );
1287 PatBlt( hdc, rect->left, rect->top,
1288 width, rect->bottom - rect->top, PATCOPY );
1289 PatBlt( hdc, rect->left, rect->bottom - 1,
1290 rect->right - rect->left, -height, PATCOPY );
1291 PatBlt( hdc, rect->right - 1, rect->top,
1292 -width, rect->bottom - rect->top, PATCOPY );
1294 if (dlgFrame)
1296 InflateRect( rect, -width, -height );
1298 else
1300 INT decYOff = GetSystemMetrics(SM_CXFRAME) + GetSystemMetrics(SM_CXSIZE) - 1;
1301 INT decXOff = GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYSIZE) - 1;
1303 /* Draw inner rectangle */
1305 SelectObject( hdc, GetStockObject(NULL_BRUSH) );
1306 Rectangle( hdc, rect->left + width, rect->top + height,
1307 rect->right - width , rect->bottom - height );
1309 /* Draw the decorations */
1311 MoveToEx( hdc, rect->left, rect->top + decYOff, NULL );
1312 LineTo( hdc, rect->left + width, rect->top + decYOff );
1313 MoveToEx( hdc, rect->right - 1, rect->top + decYOff, NULL );
1314 LineTo( hdc, rect->right - width - 1, rect->top + decYOff );
1315 MoveToEx( hdc, rect->left, rect->bottom - decYOff, NULL );
1316 LineTo( hdc, rect->left + width, rect->bottom - decYOff );
1317 MoveToEx( hdc, rect->right - 1, rect->bottom - decYOff, NULL );
1318 LineTo( hdc, rect->right - width - 1, rect->bottom - decYOff );
1320 MoveToEx( hdc, rect->left + decXOff, rect->top, NULL );
1321 LineTo( hdc, rect->left + decXOff, rect->top + height);
1322 MoveToEx( hdc, rect->left + decXOff, rect->bottom - 1, NULL );
1323 LineTo( hdc, rect->left + decXOff, rect->bottom - height - 1 );
1324 MoveToEx( hdc, rect->right - decXOff, rect->top, NULL );
1325 LineTo( hdc, rect->right - decXOff, rect->top + height );
1326 MoveToEx( hdc, rect->right - decXOff, rect->bottom - 1, NULL );
1327 LineTo( hdc, rect->right - decXOff, rect->bottom - height - 1 );
1329 InflateRect( rect, -width - 1, -height - 1 );
1334 /******************************************************************************
1336 * void NC_DrawFrame95(
1337 * HDC32 hdc,
1338 * RECT32 *rect,
1339 * BOOL32 dlgFrame,
1340 * BOOL32 active )
1342 * Draw a window frame inside the given rectangle, and update the rectangle.
1343 * The correct pen for the frame must be selected in the DC.
1345 * Bugs
1346 * Many. First, just what IS a frame in Win95? Note that the 3D look
1347 * on the outer edge is handled by NC_DoNCPaint95. As is the inner
1348 * edge. The inner rectangle just inside the frame is handled by the
1349 * Caption code.
1351 * In short, for most people, this function should be a nop (unless
1352 * you LIKE thick borders in Win95/NT4.0 -- I've been working with
1353 * them lately, but just to get this code right). Even so, it doesn't
1354 * appear to be so. It's being worked on...
1356 * Revision history
1357 * 06-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu)
1358 * Original implementation (based on NC_DrawFrame)
1359 * 02-Jun-1998 Eric Kohl (ekohl@abo.rhein-zeitung.de)
1360 * Some minor fixes.
1361 * 29-Jun-1999 Ove Kåven (ovek@arcticnet.no)
1362 * Fixed a fix or something.
1364 *****************************************************************************/
1366 static void NC_DrawFrame95(
1367 HDC hdc,
1368 RECT *rect,
1369 BOOL dlgFrame,
1370 BOOL active )
1372 INT width, height;
1374 if (dlgFrame)
1376 width = GetSystemMetrics(SM_CXDLGFRAME) - GetSystemMetrics(SM_CXEDGE);
1377 height = GetSystemMetrics(SM_CYDLGFRAME) - GetSystemMetrics(SM_CYEDGE);
1379 else
1381 width = GetSystemMetrics(SM_CXFRAME) - GetSystemMetrics(SM_CXEDGE);
1382 height = GetSystemMetrics(SM_CYFRAME) - GetSystemMetrics(SM_CYEDGE);
1385 SelectObject( hdc, GetSysColorBrush(active ? COLOR_ACTIVEBORDER :
1386 COLOR_INACTIVEBORDER) );
1388 /* Draw frame */
1389 PatBlt( hdc, rect->left, rect->top,
1390 rect->right - rect->left, height, PATCOPY );
1391 PatBlt( hdc, rect->left, rect->top,
1392 width, rect->bottom - rect->top, PATCOPY );
1393 PatBlt( hdc, rect->left, rect->bottom - 1,
1394 rect->right - rect->left, -height, PATCOPY );
1395 PatBlt( hdc, rect->right - 1, rect->top,
1396 -width, rect->bottom - rect->top, PATCOPY );
1398 InflateRect( rect, -width, -height );
1401 /***********************************************************************
1402 * NC_DrawMovingFrame
1404 * Draw the frame used when moving or resizing window.
1406 * FIXME: This causes problems in Win95 mode. (why?)
1408 static void NC_DrawMovingFrame( HDC hdc, RECT *rect, BOOL thickframe )
1410 if (thickframe)
1412 RECT16 r16;
1413 CONV_RECT32TO16( rect, &r16 );
1414 FastWindowFrame16( hdc, &r16, GetSystemMetrics(SM_CXFRAME),
1415 GetSystemMetrics(SM_CYFRAME), PATINVERT );
1417 else DrawFocusRect( hdc, rect );
1421 /***********************************************************************
1422 * NC_DrawCaption
1424 * Draw the window caption.
1425 * The correct pen for the window frame must be selected in the DC.
1427 static void NC_DrawCaption( HDC hdc, RECT *rect, HWND hwnd,
1428 DWORD style, BOOL active )
1430 RECT r = *rect;
1431 WND * wndPtr = WIN_FindWndPtr( hwnd );
1432 char buffer[256];
1434 if (wndPtr->flags & WIN_MANAGED)
1436 WIN_ReleaseWndPtr(wndPtr);
1437 return;
1440 if (!hbitmapClose)
1442 if (!(hbitmapClose = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_CLOSE) )))
1444 WIN_ReleaseWndPtr(wndPtr);
1445 return;
1447 hbitmapCloseD = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_CLOSED) );
1448 hbitmapMinimize = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_REDUCE) );
1449 hbitmapMinimizeD = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_REDUCED) );
1450 hbitmapMaximize = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_ZOOM) );
1451 hbitmapMaximizeD = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_ZOOMD) );
1452 hbitmapRestore = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_RESTORE) );
1453 hbitmapRestoreD = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_RESTORED) );
1456 if (wndPtr->dwExStyle & WS_EX_DLGMODALFRAME)
1458 HBRUSH hbrushOld = SelectObject(hdc, GetSysColorBrush(COLOR_WINDOW) );
1459 PatBlt( hdc, r.left, r.top, 1, r.bottom-r.top+1,PATCOPY );
1460 PatBlt( hdc, r.right-1, r.top, 1, r.bottom-r.top+1, PATCOPY );
1461 PatBlt( hdc, r.left, r.top-1, r.right-r.left, 1, PATCOPY );
1462 r.left++;
1463 r.right--;
1464 SelectObject( hdc, hbrushOld );
1466 WIN_ReleaseWndPtr(wndPtr);
1467 MoveTo16( hdc, r.left, r.bottom );
1468 LineTo( hdc, r.right, r.bottom );
1470 if (style & WS_SYSMENU)
1472 NC_DrawSysButton( hwnd, hdc, FALSE );
1473 r.left += GetSystemMetrics(SM_CXSIZE) + 1;
1474 MoveTo16( hdc, r.left - 1, r.top );
1475 LineTo( hdc, r.left - 1, r.bottom );
1477 if (style & WS_MAXIMIZEBOX)
1479 NC_DrawMaxButton( hwnd, hdc, FALSE );
1480 r.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1482 if (style & WS_MINIMIZEBOX)
1484 NC_DrawMinButton( hwnd, hdc, FALSE );
1485 r.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1488 FillRect( hdc, &r, GetSysColorBrush(active ? COLOR_ACTIVECAPTION :
1489 COLOR_INACTIVECAPTION) );
1491 if (GetWindowTextA( hwnd, buffer, sizeof(buffer) ))
1493 if (active) SetTextColor( hdc, GetSysColor( COLOR_CAPTIONTEXT ) );
1494 else SetTextColor( hdc, GetSysColor( COLOR_INACTIVECAPTIONTEXT ) );
1495 SetBkMode( hdc, TRANSPARENT );
1496 DrawTextA( hdc, buffer, -1, &r,
1497 DT_SINGLELINE | DT_CENTER | DT_VCENTER | DT_NOPREFIX );
1502 /******************************************************************************
1504 * NC_DrawCaption95(
1505 * HDC32 hdc,
1506 * RECT32 *rect,
1507 * HWND32 hwnd,
1508 * DWORD style,
1509 * BOOL32 active )
1511 * Draw the window caption for Win95 style windows.
1512 * The correct pen for the window frame must be selected in the DC.
1514 * Bugs
1515 * Hey, a function that finally works! Well, almost.
1516 * It's being worked on.
1518 * Revision history
1519 * 05-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu)
1520 * Original implementation.
1521 * 02-Jun-1998 Eric Kohl (ekohl@abo.rhein-zeitung.de)
1522 * Some minor fixes.
1524 *****************************************************************************/
1526 static void NC_DrawCaption95(
1527 HDC hdc,
1528 RECT *rect,
1529 HWND hwnd,
1530 DWORD style,
1531 DWORD exStyle,
1532 BOOL active )
1534 RECT r = *rect;
1535 WND *wndPtr = WIN_FindWndPtr( hwnd );
1536 char buffer[256];
1537 HPEN hPrevPen;
1538 HMENU hSysMenu;
1540 if (wndPtr->flags & WIN_MANAGED)
1542 WIN_ReleaseWndPtr(wndPtr);
1543 return;
1545 WIN_ReleaseWndPtr(wndPtr);
1547 hPrevPen = SelectObject( hdc, GetSysColorPen(COLOR_3DFACE) );
1548 MoveToEx( hdc, r.left, r.bottom - 1, NULL );
1549 LineTo( hdc, r.right, r.bottom - 1 );
1550 SelectObject( hdc, hPrevPen );
1551 r.bottom--;
1553 FillRect( hdc, &r, GetSysColorBrush(active ? COLOR_ACTIVECAPTION :
1554 COLOR_INACTIVECAPTION) );
1556 if (!hbitmapClose) {
1557 if (!(hbitmapClose = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_CLOSE) )))
1558 return;
1559 hbitmapCloseD = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_CLOSED));
1560 hbitmapMinimize = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_REDUCE) );
1561 hbitmapMinimizeD = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_REDUCED) );
1562 hbitmapMaximize = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_ZOOM) );
1563 hbitmapMaximizeD = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_ZOOMD) );
1564 hbitmapRestore = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_RESTORE) );
1565 hbitmapRestoreD = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_RESTORED) );
1568 if ((style & WS_SYSMENU) && !(exStyle & WS_EX_TOOLWINDOW)) {
1569 if (NC_DrawSysButton95 (hwnd, hdc, FALSE))
1570 r.left += GetSystemMetrics(SM_CYCAPTION) - 1;
1573 if (style & WS_SYSMENU)
1575 UINT state;
1577 /* Go get the sysmenu */
1578 hSysMenu = GetSystemMenu(hwnd, FALSE);
1579 state = GetMenuState(hSysMenu, SC_CLOSE, MF_BYCOMMAND);
1581 /* Draw a grayed close button if disabled and a normal one if SC_CLOSE is not there */
1582 NC_DrawCloseButton95 (hwnd, hdc, FALSE,
1583 ((((state & MF_DISABLED) || (state & MF_GRAYED))) && (state != 0xFFFFFFFF)));
1584 r.right -= GetSystemMetrics(SM_CYCAPTION) - 1;
1586 if ((style & WS_MAXIMIZEBOX) || (style & WS_MINIMIZEBOX))
1588 /* In win95 the two buttons are always there */
1589 /* But if the menu item is not in the menu they're disabled*/
1591 NC_DrawMaxButton95( hwnd, hdc, FALSE, (!(style & WS_MAXIMIZEBOX)));
1592 r.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1594 NC_DrawMinButton95( hwnd, hdc, FALSE, (!(style & WS_MINIMIZEBOX)));
1595 r.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1599 if (GetWindowTextA( hwnd, buffer, sizeof(buffer) )) {
1600 NONCLIENTMETRICSA nclm;
1601 HFONT hFont, hOldFont;
1602 nclm.cbSize = sizeof(NONCLIENTMETRICSA);
1603 SystemParametersInfoA (SPI_GETNONCLIENTMETRICS, 0, &nclm, 0);
1604 if (exStyle & WS_EX_TOOLWINDOW)
1605 hFont = CreateFontIndirectA (&nclm.lfSmCaptionFont);
1606 else
1607 hFont = CreateFontIndirectA (&nclm.lfCaptionFont);
1608 hOldFont = SelectObject (hdc, hFont);
1609 if (active) SetTextColor( hdc, GetSysColor( COLOR_CAPTIONTEXT ) );
1610 else SetTextColor( hdc, GetSysColor( COLOR_INACTIVECAPTIONTEXT ) );
1611 SetBkMode( hdc, TRANSPARENT );
1612 r.left += 2;
1613 DrawTextA( hdc, buffer, -1, &r,
1614 DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX | DT_LEFT );
1615 DeleteObject (SelectObject (hdc, hOldFont));
1621 /***********************************************************************
1622 * NC_DoNCPaint
1624 * Paint the non-client area. clip is currently unused.
1626 static void NC_DoNCPaint( WND* wndPtr, HRGN clip, BOOL suppress_menupaint )
1628 HDC hdc;
1629 RECT rect;
1630 BOOL active;
1631 HWND hwnd = wndPtr->hwndSelf;
1633 if ( wndPtr->dwStyle & WS_MINIMIZE ||
1634 !WIN_IsWindowDrawable( wndPtr, 0 )) return; /* Nothing to do */
1636 active = wndPtr->flags & WIN_NCACTIVATED;
1638 TRACE_(nonclient)("%04x %d\n", hwnd, active );
1640 if (!(hdc = GetDCEx( hwnd, (clip > 1) ? clip : 0, DCX_USESTYLE | DCX_WINDOW |
1641 ((clip > 1) ? (DCX_INTERSECTRGN | DCX_KEEPCLIPRGN): 0) ))) return;
1643 if (ExcludeVisRect16( hdc, wndPtr->rectClient.left-wndPtr->rectWindow.left,
1644 wndPtr->rectClient.top-wndPtr->rectWindow.top,
1645 wndPtr->rectClient.right-wndPtr->rectWindow.left,
1646 wndPtr->rectClient.bottom-wndPtr->rectWindow.top )
1647 == NULLREGION)
1649 ReleaseDC( hwnd, hdc );
1650 return;
1653 rect.top = rect.left = 0;
1654 rect.right = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
1655 rect.bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
1657 SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
1659 if (!(wndPtr->flags & WIN_MANAGED))
1661 if (HAS_ANYFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
1663 SelectObject( hdc, GetStockObject(NULL_BRUSH) );
1664 Rectangle( hdc, 0, 0, rect.right, rect.bottom );
1665 InflateRect( &rect, -1, -1 );
1668 if (HAS_THICKFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
1669 NC_DrawFrame(hdc, &rect, FALSE, active );
1670 else if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
1671 NC_DrawFrame( hdc, &rect, TRUE, active );
1673 if ((wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION)
1675 RECT r = rect;
1676 r.bottom = rect.top + GetSystemMetrics(SM_CYSIZE);
1677 rect.top += GetSystemMetrics(SM_CYSIZE) + GetSystemMetrics(SM_CYBORDER);
1678 NC_DrawCaption( hdc, &r, hwnd, wndPtr->dwStyle, active );
1682 if (HAS_MENU(wndPtr))
1684 RECT r = rect;
1685 r.bottom = rect.top + GetSystemMetrics(SM_CYMENU); /* default height */
1686 rect.top += MENU_DrawMenuBar( hdc, &r, hwnd, suppress_menupaint );
1689 /* Draw the scroll-bars */
1691 if (wndPtr->dwStyle & WS_VSCROLL)
1692 SCROLL_DrawScrollBar( hwnd, hdc, SB_VERT, TRUE, TRUE );
1693 if (wndPtr->dwStyle & WS_HSCROLL)
1694 SCROLL_DrawScrollBar( hwnd, hdc, SB_HORZ, TRUE, TRUE );
1696 /* Draw the "size-box" */
1698 if ((wndPtr->dwStyle & WS_VSCROLL) && (wndPtr->dwStyle & WS_HSCROLL))
1700 RECT r = rect;
1701 r.left = r.right - GetSystemMetrics(SM_CXVSCROLL) + 1;
1702 r.top = r.bottom - GetSystemMetrics(SM_CYHSCROLL) + 1;
1703 if(wndPtr->dwStyle & WS_BORDER) {
1704 r.left++;
1705 r.top++;
1707 FillRect( hdc, &r, GetSysColorBrush(COLOR_SCROLLBAR) );
1710 ReleaseDC( hwnd, hdc );
1714 /******************************************************************************
1716 * void NC_DoNCPaint95(
1717 * WND *wndPtr,
1718 * HRGN32 clip,
1719 * BOOL32 suppress_menupaint )
1721 * Paint the non-client area for Win95 windows. The clip region is
1722 * currently ignored.
1724 * Bugs
1725 * grep -E -A10 -B5 \(95\)\|\(Bugs\)\|\(FIXME\) windows/nonclient.c \
1726 * misc/tweak.c controls/menu.c # :-)
1728 * Revision history
1729 * 03-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu)
1730 * Original implementation
1731 * 10-Jun-1998 Eric Kohl (ekohl@abo.rhein-zeitung.de)
1732 * Fixed some bugs.
1733 * 29-Jun-1999 Ove Kåven (ovek@arcticnet.no)
1734 * Streamlined window style checks.
1736 *****************************************************************************/
1738 static void NC_DoNCPaint95(
1739 WND *wndPtr,
1740 HRGN clip,
1741 BOOL suppress_menupaint )
1743 HDC hdc;
1744 RECT rfuzz, rect, rectClip;
1745 BOOL active;
1746 HWND hwnd = wndPtr->hwndSelf;
1748 if ( wndPtr->dwStyle & WS_MINIMIZE ||
1749 !WIN_IsWindowDrawable( wndPtr, 0 )) return; /* Nothing to do */
1751 active = wndPtr->flags & WIN_NCACTIVATED;
1753 TRACE_(nonclient)("%04x %d\n", hwnd, active );
1755 /* MSDN docs are pretty idiotic here, they say app CAN use clipRgn in the call to
1756 * GetDCEx implying that it is allowed not to use it either. However, the suggested
1757 * GetDCEx( , DCX_WINDOW | DCX_INTERSECTRGN) will cause clipRgn to be deleted
1758 * after ReleaseDC(). Now, how is the "system" supposed to tell what happened?
1761 if (!(hdc = GetDCEx( hwnd, (clip > 1) ? clip : 0, DCX_USESTYLE | DCX_WINDOW |
1762 ((clip > 1) ?(DCX_INTERSECTRGN | DCX_KEEPCLIPRGN) : 0) ))) return;
1765 if (ExcludeVisRect16( hdc, wndPtr->rectClient.left-wndPtr->rectWindow.left,
1766 wndPtr->rectClient.top-wndPtr->rectWindow.top,
1767 wndPtr->rectClient.right-wndPtr->rectWindow.left,
1768 wndPtr->rectClient.bottom-wndPtr->rectWindow.top )
1769 == NULLREGION)
1771 ReleaseDC( hwnd, hdc );
1772 return;
1775 rect.top = rect.left = 0;
1776 rect.right = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
1777 rect.bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
1779 if( clip > 1 )
1780 GetRgnBox( clip, &rectClip );
1781 else
1783 clip = 0;
1784 rectClip = rect;
1787 SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
1789 if(!(wndPtr->flags & WIN_MANAGED)) {
1790 if (HAS_BIGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle)) {
1791 DrawEdge (hdc, &rect, EDGE_RAISED, BF_RECT | BF_ADJUST);
1793 if (HAS_THICKFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
1794 NC_DrawFrame95(hdc, &rect, FALSE, active );
1795 else if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
1796 NC_DrawFrame95( hdc, &rect, TRUE, active );
1797 else if (HAS_THINFRAME( wndPtr->dwStyle )) {
1798 SelectObject( hdc, GetStockObject(NULL_BRUSH) );
1799 Rectangle( hdc, 0, 0, rect.right, rect.bottom );
1802 if ((wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION)
1804 RECT r = rect;
1805 if (wndPtr->dwExStyle & WS_EX_TOOLWINDOW) {
1806 r.bottom = rect.top + GetSystemMetrics(SM_CYSMCAPTION);
1807 rect.top += GetSystemMetrics(SM_CYSMCAPTION);
1809 else {
1810 r.bottom = rect.top + GetSystemMetrics(SM_CYCAPTION);
1811 rect.top += GetSystemMetrics(SM_CYCAPTION);
1813 if( !clip || IntersectRect( &rfuzz, &r, &rectClip ) )
1814 NC_DrawCaption95 (hdc, &r, hwnd, wndPtr->dwStyle,
1815 wndPtr->dwExStyle, active);
1819 if (HAS_MENU(wndPtr))
1821 RECT r = rect;
1822 r.bottom = rect.top + GetSystemMetrics(SM_CYMENU);
1824 TRACE_(nonclient)("Calling DrawMenuBar with "
1825 "rect (%d, %d)-(%d, %d)\n", r.left, r.top,
1826 r.right, r.bottom);
1828 rect.top += MENU_DrawMenuBar( hdc, &r, hwnd, suppress_menupaint ) + 1;
1831 TRACE_(nonclient)("After MenuBar, rect is (%d, %d)-(%d, %d).\n",
1832 rect.left, rect.top, rect.right, rect.bottom );
1834 if (wndPtr->dwExStyle & WS_EX_CLIENTEDGE)
1835 DrawEdge (hdc, &rect, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
1837 if (wndPtr->dwExStyle & WS_EX_STATICEDGE)
1838 DrawEdge (hdc, &rect, BDR_SUNKENOUTER, BF_RECT | BF_ADJUST);
1840 /* Draw the scroll-bars */
1842 if (wndPtr->dwStyle & WS_VSCROLL)
1843 SCROLL_DrawScrollBar( hwnd, hdc, SB_VERT, TRUE, TRUE );
1844 if (wndPtr->dwStyle & WS_HSCROLL)
1845 SCROLL_DrawScrollBar( hwnd, hdc, SB_HORZ, TRUE, TRUE );
1847 /* Draw the "size-box" */
1848 if ((wndPtr->dwStyle & WS_VSCROLL) && (wndPtr->dwStyle & WS_HSCROLL))
1850 RECT r = rect;
1851 r.left = r.right - GetSystemMetrics(SM_CXVSCROLL) + 1;
1852 r.top = r.bottom - GetSystemMetrics(SM_CYHSCROLL) + 1;
1853 FillRect( hdc, &r, GetSysColorBrush(COLOR_SCROLLBAR) );
1856 ReleaseDC( hwnd, hdc );
1862 /***********************************************************************
1863 * NC_HandleNCPaint
1865 * Handle a WM_NCPAINT message. Called from DefWindowProc().
1867 LONG NC_HandleNCPaint( HWND hwnd , HRGN clip)
1869 WND* wndPtr = WIN_FindWndPtr( hwnd );
1871 if( wndPtr && wndPtr->dwStyle & WS_VISIBLE )
1873 if( wndPtr->dwStyle & WS_MINIMIZE )
1874 WINPOS_RedrawIconTitle( hwnd );
1875 else if (TWEAK_WineLook == WIN31_LOOK)
1876 NC_DoNCPaint( wndPtr, clip, FALSE );
1877 else
1878 NC_DoNCPaint95( wndPtr, clip, FALSE );
1880 WIN_ReleaseWndPtr(wndPtr);
1881 return 0;
1885 /***********************************************************************
1886 * NC_HandleNCActivate
1888 * Handle a WM_NCACTIVATE message. Called from DefWindowProc().
1890 LONG NC_HandleNCActivate( WND *wndPtr, WPARAM16 wParam )
1892 WORD wStateChange;
1894 if( wParam ) wStateChange = !(wndPtr->flags & WIN_NCACTIVATED);
1895 else wStateChange = wndPtr->flags & WIN_NCACTIVATED;
1897 if( wStateChange )
1899 if (wParam) wndPtr->flags |= WIN_NCACTIVATED;
1900 else wndPtr->flags &= ~WIN_NCACTIVATED;
1902 if( wndPtr->dwStyle & WS_MINIMIZE )
1903 WINPOS_RedrawIconTitle( wndPtr->hwndSelf );
1904 else if (TWEAK_WineLook == WIN31_LOOK)
1905 NC_DoNCPaint( wndPtr, (HRGN)1, FALSE );
1906 else
1907 NC_DoNCPaint95( wndPtr, (HRGN)1, FALSE );
1909 return TRUE;
1913 /***********************************************************************
1914 * NC_HandleSetCursor
1916 * Handle a WM_SETCURSOR message. Called from DefWindowProc().
1918 LONG NC_HandleSetCursor( HWND hwnd, WPARAM16 wParam, LPARAM lParam )
1920 if (hwnd != (HWND)wParam) return 0; /* Don't set the cursor for child windows */
1922 switch(LOWORD(lParam))
1924 case HTERROR:
1926 WORD msg = HIWORD( lParam );
1927 if ((msg == WM_LBUTTONDOWN) || (msg == WM_MBUTTONDOWN) ||
1928 (msg == WM_RBUTTONDOWN))
1929 MessageBeep(0);
1931 break;
1933 case HTCLIENT:
1935 HICON16 hCursor = (HICON16) GetClassWord(hwnd, GCW_HCURSOR);
1936 if(hCursor) {
1937 SetCursor16(hCursor);
1938 return TRUE;
1940 return FALSE;
1943 case HTLEFT:
1944 case HTRIGHT:
1945 return (LONG)SetCursor16( LoadCursor16( 0, IDC_SIZEWE16 ) );
1947 case HTTOP:
1948 case HTBOTTOM:
1949 return (LONG)SetCursor16( LoadCursor16( 0, IDC_SIZENS16 ) );
1951 case HTTOPLEFT:
1952 case HTBOTTOMRIGHT:
1953 return (LONG)SetCursor16( LoadCursor16( 0, IDC_SIZENWSE16 ) );
1955 case HTTOPRIGHT:
1956 case HTBOTTOMLEFT:
1957 return (LONG)SetCursor16( LoadCursor16( 0, IDC_SIZENESW16 ) );
1960 /* Default cursor: arrow */
1961 return (LONG)SetCursor16( LoadCursor16( 0, IDC_ARROW16 ) );
1964 /***********************************************************************
1965 * NC_GetSysPopupPos
1967 BOOL NC_GetSysPopupPos( WND* wndPtr, RECT* rect )
1969 if( wndPtr->hSysMenu )
1971 if( wndPtr->dwStyle & WS_MINIMIZE )
1972 GetWindowRect( wndPtr->hwndSelf, rect );
1973 else
1975 if (TWEAK_WineLook == WIN31_LOOK)
1976 NC_GetInsideRect( wndPtr->hwndSelf, rect );
1977 else
1978 NC_GetInsideRect95( wndPtr->hwndSelf, rect );
1979 OffsetRect( rect, wndPtr->rectWindow.left, wndPtr->rectWindow.top);
1980 if (wndPtr->dwStyle & WS_CHILD)
1981 ClientToScreen( wndPtr->parent->hwndSelf, (POINT *)rect );
1982 if (TWEAK_WineLook == WIN31_LOOK) {
1983 rect->right = rect->left + GetSystemMetrics(SM_CXSIZE);
1984 rect->bottom = rect->top + GetSystemMetrics(SM_CYSIZE);
1986 else {
1987 rect->right = rect->left + GetSystemMetrics(SM_CYCAPTION) - 1;
1988 rect->bottom = rect->top + GetSystemMetrics(SM_CYCAPTION) - 1;
1991 return TRUE;
1993 return FALSE;
1996 /***********************************************************************
1997 * NC_StartSizeMove
1999 * Initialisation of a move or resize, when initiatied from a menu choice.
2000 * Return hit test code for caption or sizing border.
2002 static LONG NC_StartSizeMove( WND* wndPtr, WPARAM16 wParam,
2003 POINT16 *capturePoint )
2005 LONG hittest = 0;
2006 POINT16 pt;
2007 MSG msg;
2008 RECT rectWindow;
2010 GetWindowRect(wndPtr->hwndSelf,&rectWindow);
2012 if ((wParam & 0xfff0) == SC_MOVE)
2014 /* Move pointer at the center of the caption */
2015 RECT rect;
2016 if (TWEAK_WineLook == WIN31_LOOK)
2017 NC_GetInsideRect( wndPtr->hwndSelf, &rect );
2018 else
2019 NC_GetInsideRect95( wndPtr->hwndSelf, &rect );
2020 if (wndPtr->dwStyle & WS_SYSMENU)
2021 rect.left += GetSystemMetrics(SM_CXSIZE) + 1;
2022 if (wndPtr->dwStyle & WS_MINIMIZEBOX)
2023 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
2024 if (wndPtr->dwStyle & WS_MAXIMIZEBOX)
2025 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
2026 pt.x = rectWindow.left + (rect.right - rect.left) / 2;
2027 pt.y = rectWindow.top + rect.top + GetSystemMetrics(SM_CYSIZE)/2;
2028 hittest = HTCAPTION;
2029 *capturePoint = pt;
2031 else /* SC_SIZE */
2033 while(!hittest)
2035 MSG_InternalGetMessage( &msg, 0, 0, MSGF_SIZE, PM_REMOVE, FALSE );
2036 switch(msg.message)
2038 case WM_MOUSEMOVE:
2039 CONV_POINT32TO16(&msg.pt, &pt);
2040 hittest = NC_HandleNCHitTest( wndPtr->hwndSelf, pt );
2041 if ((hittest < HTLEFT) || (hittest > HTBOTTOMRIGHT))
2042 hittest = 0;
2043 break;
2045 case WM_LBUTTONUP:
2046 return 0;
2048 case WM_KEYDOWN:
2049 switch(msg.wParam)
2051 case VK_UP:
2052 hittest = HTTOP;
2053 pt.x =(rectWindow.left+rectWindow.right)/2;
2054 pt.y = rectWindow.top + GetSystemMetrics(SM_CYFRAME) / 2;
2055 break;
2056 case VK_DOWN:
2057 hittest = HTBOTTOM;
2058 pt.x =(rectWindow.left+rectWindow.right)/2;
2059 pt.y = rectWindow.bottom - GetSystemMetrics(SM_CYFRAME) / 2;
2060 break;
2061 case VK_LEFT:
2062 hittest = HTLEFT;
2063 pt.x = rectWindow.left + GetSystemMetrics(SM_CXFRAME) / 2;
2064 pt.y =(rectWindow.top+rectWindow.bottom)/2;
2065 break;
2066 case VK_RIGHT:
2067 hittest = HTRIGHT;
2068 pt.x = rectWindow.right - GetSystemMetrics(SM_CXFRAME) / 2;
2069 pt.y =(rectWindow.top+rectWindow.bottom)/2;
2070 break;
2071 case VK_RETURN:
2072 case VK_ESCAPE: return 0;
2076 *capturePoint = pt;
2078 SetCursorPos( pt.x, pt.y );
2079 NC_HandleSetCursor( wndPtr->hwndSelf,
2080 wndPtr->hwndSelf, MAKELONG( hittest, WM_MOUSEMOVE ));
2081 return hittest;
2085 /***********************************************************************
2086 * NC_DoSizeMove
2088 * Perform SC_MOVE and SC_SIZE commands. `
2090 static void NC_DoSizeMove( HWND hwnd, WORD wParam )
2092 MSG msg;
2093 RECT sizingRect, mouseRect;
2094 HDC hdc;
2095 LONG hittest = (LONG)(wParam & 0x0f);
2096 HCURSOR16 hDragCursor = 0, hOldCursor = 0;
2097 POINT minTrack, maxTrack;
2098 POINT16 capturePoint, pt;
2099 WND * wndPtr = WIN_FindWndPtr( hwnd );
2100 BOOL thickframe = HAS_THICKFRAME( wndPtr->dwStyle, wndPtr->dwExStyle );
2101 BOOL iconic = wndPtr->dwStyle & WS_MINIMIZE;
2102 BOOL moved = FALSE;
2103 DWORD dwPoint = GetMessagePos ();
2105 capturePoint = pt = *(POINT16*)&dwPoint;
2107 if (IsZoomed(hwnd) || !IsWindowVisible(hwnd) ||
2108 (wndPtr->flags & WIN_MANAGED)) goto END;
2110 if ((wParam & 0xfff0) == SC_MOVE)
2112 if (!(wndPtr->dwStyle & WS_CAPTION)) goto END;
2113 if (!hittest)
2114 hittest = NC_StartSizeMove( wndPtr, wParam, &capturePoint );
2115 if (!hittest) goto END;
2117 else /* SC_SIZE */
2119 if (!thickframe) goto END;
2120 if ( hittest && hittest != HTSYSMENU ) hittest += 2;
2121 else
2123 SetCapture(hwnd);
2124 hittest = NC_StartSizeMove( wndPtr, wParam, &capturePoint );
2125 if (!hittest)
2127 ReleaseCapture();
2128 goto END;
2133 /* Get min/max info */
2135 WINPOS_GetMinMaxInfo( wndPtr, NULL, NULL, &minTrack, &maxTrack );
2136 sizingRect = wndPtr->rectWindow;
2137 if (wndPtr->dwStyle & WS_CHILD)
2138 GetClientRect( wndPtr->parent->hwndSelf, &mouseRect );
2139 else
2140 SetRect(&mouseRect, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
2141 if (ON_LEFT_BORDER(hittest))
2143 mouseRect.left = MAX( mouseRect.left, sizingRect.right-maxTrack.x );
2144 mouseRect.right = MIN( mouseRect.right, sizingRect.right-minTrack.x );
2146 else if (ON_RIGHT_BORDER(hittest))
2148 mouseRect.left = MAX( mouseRect.left, sizingRect.left+minTrack.x );
2149 mouseRect.right = MIN( mouseRect.right, sizingRect.left+maxTrack.x );
2151 if (ON_TOP_BORDER(hittest))
2153 mouseRect.top = MAX( mouseRect.top, sizingRect.bottom-maxTrack.y );
2154 mouseRect.bottom = MIN( mouseRect.bottom,sizingRect.bottom-minTrack.y);
2156 else if (ON_BOTTOM_BORDER(hittest))
2158 mouseRect.top = MAX( mouseRect.top, sizingRect.top+minTrack.y );
2159 mouseRect.bottom = MIN( mouseRect.bottom, sizingRect.top+maxTrack.y );
2161 if (wndPtr->dwStyle & WS_CHILD)
2163 MapWindowPoints( wndPtr->parent->hwndSelf, 0,
2164 (LPPOINT)&mouseRect, 2 );
2166 SendMessage16( hwnd, WM_ENTERSIZEMOVE, 0, 0 );
2168 if (GetCapture() != hwnd) SetCapture( hwnd );
2170 if (wndPtr->dwStyle & WS_CHILD)
2172 /* Retrieve a default cache DC (without using the window style) */
2173 hdc = GetDCEx( wndPtr->parent->hwndSelf, 0, DCX_CACHE );
2175 else
2176 { /* Grab the server only when moving top-level windows without desktop */
2177 hdc = GetDC( 0 );
2180 wndPtr->pDriver->pPreSizeMove(wndPtr);
2182 if( iconic ) /* create a cursor for dragging */
2184 HICON16 hIcon = GetClassWord(wndPtr->hwndSelf, GCW_HICON);
2185 if(!hIcon) hIcon = (HICON16) SendMessage16( hwnd, WM_QUERYDRAGICON, 0, 0L);
2186 if( hIcon ) hDragCursor = CURSORICON_IconToCursor( hIcon, TRUE );
2187 if( !hDragCursor ) iconic = FALSE;
2190 if( !iconic ) NC_DrawMovingFrame( hdc, &sizingRect, thickframe );
2192 while(1)
2194 int dx = 0, dy = 0;
2196 MSG_InternalGetMessage( &msg, 0, 0, MSGF_SIZE, PM_REMOVE, FALSE );
2198 /* Exit on button-up, Return, or Esc */
2199 if ((msg.message == WM_LBUTTONUP) ||
2200 ((msg.message == WM_KEYDOWN) &&
2201 ((msg.wParam == VK_RETURN) || (msg.wParam == VK_ESCAPE)))) break;
2203 if ((msg.message != WM_KEYDOWN) && (msg.message != WM_MOUSEMOVE))
2204 continue; /* We are not interested in other messages */
2206 dwPoint = GetMessagePos ();
2207 pt = *(POINT16*)&dwPoint;
2209 if (msg.message == WM_KEYDOWN) switch(msg.wParam)
2211 case VK_UP: pt.y -= 8; break;
2212 case VK_DOWN: pt.y += 8; break;
2213 case VK_LEFT: pt.x -= 8; break;
2214 case VK_RIGHT: pt.x += 8; break;
2217 pt.x = MAX( pt.x, mouseRect.left );
2218 pt.x = MIN( pt.x, mouseRect.right );
2219 pt.y = MAX( pt.y, mouseRect.top );
2220 pt.y = MIN( pt.y, mouseRect.bottom );
2222 dx = pt.x - capturePoint.x;
2223 dy = pt.y - capturePoint.y;
2225 if (dx || dy)
2227 if( !moved )
2229 moved = TRUE;
2230 if( iconic ) /* ok, no system popup tracking */
2232 hOldCursor = SetCursor(hDragCursor);
2233 ShowCursor( TRUE );
2234 WINPOS_ShowIconTitle( wndPtr, FALSE );
2238 if (msg.message == WM_KEYDOWN) SetCursorPos( pt.x, pt.y );
2239 else
2241 RECT newRect = sizingRect;
2243 if (hittest == HTCAPTION) OffsetRect( &newRect, dx, dy );
2244 if (ON_LEFT_BORDER(hittest)) newRect.left += dx;
2245 else if (ON_RIGHT_BORDER(hittest)) newRect.right += dx;
2246 if (ON_TOP_BORDER(hittest)) newRect.top += dy;
2247 else if (ON_BOTTOM_BORDER(hittest)) newRect.bottom += dy;
2248 if( !iconic )
2250 NC_DrawMovingFrame( hdc, &sizingRect, thickframe );
2251 NC_DrawMovingFrame( hdc, &newRect, thickframe );
2253 capturePoint = pt;
2254 sizingRect = newRect;
2259 ReleaseCapture();
2260 if( iconic )
2262 if( moved ) /* restore cursors, show icon title later on */
2264 ShowCursor( FALSE );
2265 SetCursor( hOldCursor );
2267 DestroyCursor( hDragCursor );
2269 else
2270 NC_DrawMovingFrame( hdc, &sizingRect, thickframe );
2272 if (wndPtr->dwStyle & WS_CHILD)
2273 ReleaseDC( wndPtr->parent->hwndSelf, hdc );
2274 else
2276 ReleaseDC( 0, hdc );
2279 wndPtr->pDriver->pPostSizeMove(wndPtr);
2281 if (HOOK_IsHooked( WH_CBT ))
2283 RECT16* pr = SEGPTR_NEW(RECT16);
2284 if( pr )
2286 CONV_RECT32TO16( &sizingRect, pr );
2287 if( HOOK_CallHooks16( WH_CBT, HCBT_MOVESIZE, hwnd,
2288 (LPARAM)SEGPTR_GET(pr)) )
2289 sizingRect = wndPtr->rectWindow;
2290 else
2291 CONV_RECT16TO32( pr, &sizingRect );
2292 SEGPTR_FREE(pr);
2295 SendMessage16( hwnd, WM_EXITSIZEMOVE, 0, 0 );
2296 SendMessage16( hwnd, WM_SETVISIBLE, !IsIconic16(hwnd), 0L);
2298 /* window moved or resized */
2299 if (moved)
2301 /* if the moving/resizing isn't canceled call SetWindowPos
2302 * with the new position or the new size of the window
2304 if (!((msg.message == WM_KEYDOWN) && (msg.wParam == VK_ESCAPE)) )
2306 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
2307 SetWindowPos( hwnd, 0, sizingRect.left, sizingRect.top,
2308 sizingRect.right - sizingRect.left,
2309 sizingRect.bottom - sizingRect.top,
2310 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
2314 if( IsWindow(hwnd) )
2315 if( wndPtr->dwStyle & WS_MINIMIZE )
2317 /* Single click brings up the system menu when iconized */
2319 if( !moved )
2321 if( wndPtr->dwStyle & WS_SYSMENU )
2322 SendMessage16( hwnd, WM_SYSCOMMAND,
2323 SC_MOUSEMENU + HTSYSMENU, *((LPARAM*)&pt));
2325 else WINPOS_ShowIconTitle( wndPtr, TRUE );
2328 END:
2329 WIN_ReleaseWndPtr(wndPtr);
2333 /***********************************************************************
2334 * NC_TrackMinMaxBox95
2336 * Track a mouse button press on the minimize or maximize box.
2338 * The big difference between 3.1 and 95 is the disabled button state.
2339 * In win95 the system button can be disabled, so it can ignore the mouse
2340 * event.
2343 static void NC_TrackMinMaxBox95( HWND hwnd, WORD wParam )
2345 MSG msg;
2346 POINT16 pt16;
2347 HDC hdc = GetWindowDC( hwnd );
2348 BOOL pressed = TRUE;
2349 UINT state;
2350 DWORD wndStyle = GetWindowLongA( hwnd, GWL_STYLE);
2351 HMENU hSysMenu = GetSystemMenu(hwnd, FALSE);
2353 void (*paintButton)(HWND, HDC16, BOOL, BOOL);
2355 if (wParam == HTMINBUTTON)
2357 /* If the style is not present, do nothing */
2358 if (!(wndStyle & WS_MINIMIZEBOX))
2359 return;
2361 /* Check if the sysmenu item for minimize is there */
2362 state = GetMenuState(hSysMenu, SC_MINIMIZE, MF_BYCOMMAND);
2364 paintButton = &NC_DrawMinButton95;
2366 else
2368 /* If the style is not present, do nothing */
2369 if (!(wndStyle & WS_MAXIMIZEBOX))
2370 return;
2372 /* Check if the sysmenu item for maximize is there */
2373 state = GetMenuState(hSysMenu, SC_MAXIMIZE, MF_BYCOMMAND);
2375 paintButton = &NC_DrawMaxButton95;
2378 SetCapture( hwnd );
2380 (*paintButton)( hwnd, hdc, TRUE, FALSE);
2384 BOOL oldstate = pressed;
2385 MSG_InternalGetMessage( &msg, 0, 0, 0, PM_REMOVE, FALSE );
2386 CONV_POINT32TO16( &msg.pt, &pt16 );
2388 pressed = (NC_HandleNCHitTest( hwnd, pt16 ) == wParam);
2389 if (pressed != oldstate)
2390 (*paintButton)( hwnd, hdc, pressed, FALSE);
2391 } while (msg.message != WM_LBUTTONUP);
2393 (*paintButton)( hwnd, hdc, FALSE, FALSE);
2395 ReleaseCapture();
2396 ReleaseDC( hwnd, hdc );
2398 /* If the item minimize or maximize of the sysmenu are not there */
2399 /* or if the style is not present, do nothing */
2400 if ((!pressed) || (state == 0xFFFFFFFF))
2401 return;
2403 if (wParam == HTMINBUTTON)
2404 SendMessage16( hwnd, WM_SYSCOMMAND, SC_MINIMIZE, *(LONG*)&pt16 );
2405 else
2406 SendMessage16( hwnd, WM_SYSCOMMAND,
2407 IsZoomed(hwnd) ? SC_RESTORE:SC_MAXIMIZE, *(LONG*)&pt16 );
2410 /***********************************************************************
2411 * NC_TrackMinMaxBox
2413 * Track a mouse button press on the minimize or maximize box.
2415 static void NC_TrackMinMaxBox( HWND hwnd, WORD wParam )
2417 MSG msg;
2418 POINT16 pt16;
2419 HDC hdc = GetWindowDC( hwnd );
2420 BOOL pressed = TRUE;
2421 void (*paintButton)(HWND, HDC16, BOOL);
2423 SetCapture( hwnd );
2425 if (wParam == HTMINBUTTON)
2426 paintButton = &NC_DrawMinButton;
2427 else
2428 paintButton = &NC_DrawMaxButton;
2430 (*paintButton)( hwnd, hdc, TRUE);
2434 BOOL oldstate = pressed;
2435 MSG_InternalGetMessage( &msg, 0, 0, 0, PM_REMOVE, FALSE );
2436 CONV_POINT32TO16( &msg.pt, &pt16 );
2438 pressed = (NC_HandleNCHitTest( hwnd, pt16 ) == wParam);
2439 if (pressed != oldstate)
2440 (*paintButton)( hwnd, hdc, pressed);
2441 } while (msg.message != WM_LBUTTONUP);
2443 (*paintButton)( hwnd, hdc, FALSE);
2445 ReleaseCapture();
2446 ReleaseDC( hwnd, hdc );
2448 if (!pressed) return;
2450 if (wParam == HTMINBUTTON)
2451 SendMessage16( hwnd, WM_SYSCOMMAND, SC_MINIMIZE, *(LONG*)&pt16 );
2452 else
2453 SendMessage16( hwnd, WM_SYSCOMMAND,
2454 IsZoomed(hwnd) ? SC_RESTORE:SC_MAXIMIZE, *(LONG*)&pt16 );
2458 /***********************************************************************
2459 * NC_TrackCloseButton95
2461 * Track a mouse button press on the Win95 close button.
2463 static void
2464 NC_TrackCloseButton95 (HWND hwnd, WORD wParam)
2466 MSG msg;
2467 POINT16 pt16;
2468 HDC hdc;
2469 BOOL pressed = TRUE;
2470 HMENU hSysMenu = GetSystemMenu(hwnd, FALSE);
2471 UINT state;
2473 if(hSysMenu == 0)
2474 return;
2476 state = GetMenuState(hSysMenu, SC_CLOSE, MF_BYCOMMAND);
2478 /* If the item close of the sysmenu is disabled or not there do nothing */
2479 if((state & MF_DISABLED) || (state & MF_GRAYED) || (state == 0xFFFFFFFF))
2480 return;
2482 hdc = GetWindowDC( hwnd );
2484 SetCapture( hwnd );
2486 NC_DrawCloseButton95 (hwnd, hdc, TRUE, FALSE);
2490 BOOL oldstate = pressed;
2491 MSG_InternalGetMessage( &msg, 0, 0, 0, PM_REMOVE, FALSE );
2492 CONV_POINT32TO16( &msg.pt, &pt16 );
2494 pressed = (NC_HandleNCHitTest( hwnd, pt16 ) == wParam);
2495 if (pressed != oldstate)
2496 NC_DrawCloseButton95 (hwnd, hdc, pressed, FALSE);
2497 } while (msg.message != WM_LBUTTONUP);
2499 NC_DrawCloseButton95 (hwnd, hdc, FALSE, FALSE);
2501 ReleaseCapture();
2502 ReleaseDC( hwnd, hdc );
2503 if (!pressed) return;
2505 SendMessage16( hwnd, WM_SYSCOMMAND, SC_CLOSE, *(LONG*)&pt16 );
2509 /***********************************************************************
2510 * NC_TrackScrollBar
2512 * Track a mouse button press on the horizontal or vertical scroll-bar.
2514 static void NC_TrackScrollBar( HWND hwnd, WPARAM wParam, POINT pt )
2516 MSG16 *msg;
2517 INT scrollbar;
2518 WND *wndPtr = WIN_FindWndPtr( hwnd );
2520 if ((wParam & 0xfff0) == SC_HSCROLL)
2522 if ((wParam & 0x0f) != HTHSCROLL) goto END;
2523 scrollbar = SB_HORZ;
2525 else /* SC_VSCROLL */
2527 if ((wParam & 0x0f) != HTVSCROLL) goto END;
2528 scrollbar = SB_VERT;
2531 if (!(msg = SEGPTR_NEW(MSG16))) goto END;
2532 pt.x -= wndPtr->rectWindow.left;
2533 pt.y -= wndPtr->rectWindow.top;
2534 SetCapture( hwnd );
2535 SCROLL_HandleScrollEvent( hwnd, scrollbar, WM_LBUTTONDOWN, pt );
2539 GetMessage16( SEGPTR_GET(msg), 0, 0, 0 );
2540 switch(msg->message)
2542 case WM_LBUTTONUP:
2543 case WM_MOUSEMOVE:
2544 case WM_SYSTIMER:
2545 pt.x = LOWORD(msg->lParam) + wndPtr->rectClient.left -
2546 wndPtr->rectWindow.left;
2547 pt.y = HIWORD(msg->lParam) + wndPtr->rectClient.top -
2548 wndPtr->rectWindow.top;
2549 SCROLL_HandleScrollEvent( hwnd, scrollbar, msg->message, pt );
2550 break;
2551 default:
2552 TranslateMessage16( msg );
2553 DispatchMessage16( msg );
2554 break;
2556 if (!IsWindow( hwnd ))
2558 ReleaseCapture();
2559 break;
2561 } while (msg->message != WM_LBUTTONUP);
2562 SEGPTR_FREE(msg);
2563 END:
2564 WIN_ReleaseWndPtr(wndPtr);
2567 /***********************************************************************
2568 * NC_HandleNCLButtonDown
2570 * Handle a WM_NCLBUTTONDOWN message. Called from DefWindowProc().
2572 LONG NC_HandleNCLButtonDown( WND* pWnd, WPARAM16 wParam, LPARAM lParam )
2574 HWND hwnd = pWnd->hwndSelf;
2576 if(GetForegroundWindow() != hwnd)
2577 SetWindowPos( hwnd, 0, 0, 0,0,0,SWP_NOSIZE | SWP_NOMOVE | SWP_DRAWFRAME);
2579 switch(wParam) /* Hit test */
2581 case HTCAPTION:
2582 hwnd = WIN_GetTopParent(hwnd);
2584 if( WINPOS_SetActiveWindow(hwnd, TRUE, TRUE) || (GetActiveWindow() == hwnd) )
2585 SendMessage16( pWnd->hwndSelf, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, lParam );
2586 break;
2588 case HTSYSMENU:
2589 if( pWnd->dwStyle & WS_SYSMENU )
2591 if( !(pWnd->dwStyle & WS_MINIMIZE) )
2593 HDC hDC = GetWindowDC(hwnd);
2594 if (TWEAK_WineLook == WIN31_LOOK)
2595 NC_DrawSysButton( hwnd, hDC, TRUE );
2596 else
2597 NC_DrawSysButton95( hwnd, hDC, TRUE );
2598 ReleaseDC( hwnd, hDC );
2600 SendMessage16( hwnd, WM_SYSCOMMAND, SC_MOUSEMENU + HTSYSMENU, lParam );
2602 break;
2604 case HTMENU:
2605 SendMessage16( hwnd, WM_SYSCOMMAND, SC_MOUSEMENU, lParam );
2606 break;
2608 case HTHSCROLL:
2609 SendMessage16( hwnd, WM_SYSCOMMAND, SC_HSCROLL + HTHSCROLL, lParam );
2610 break;
2612 case HTVSCROLL:
2613 SendMessage16( hwnd, WM_SYSCOMMAND, SC_VSCROLL + HTVSCROLL, lParam );
2614 break;
2616 case HTMINBUTTON:
2617 case HTMAXBUTTON:
2618 if (TWEAK_WineLook == WIN31_LOOK)
2619 NC_TrackMinMaxBox( hwnd, wParam );
2620 else
2621 NC_TrackMinMaxBox95( hwnd, wParam );
2622 break;
2624 case HTCLOSE:
2625 if (TWEAK_WineLook >= WIN95_LOOK)
2626 NC_TrackCloseButton95 (hwnd, wParam);
2627 break;
2629 case HTLEFT:
2630 case HTRIGHT:
2631 case HTTOP:
2632 case HTTOPLEFT:
2633 case HTTOPRIGHT:
2634 case HTBOTTOM:
2635 case HTBOTTOMLEFT:
2636 case HTBOTTOMRIGHT:
2637 /* make sure hittest fits into 0xf and doesn't overlap with HTSYSMENU */
2638 SendMessage16( hwnd, WM_SYSCOMMAND, SC_SIZE + wParam - 2, lParam);
2639 break;
2641 case HTBORDER:
2642 break;
2644 return 0;
2648 /***********************************************************************
2649 * NC_HandleNCLButtonDblClk
2651 * Handle a WM_NCLBUTTONDBLCLK message. Called from DefWindowProc().
2653 LONG NC_HandleNCLButtonDblClk( WND *pWnd, WPARAM16 wParam, LPARAM lParam )
2656 * if this is an icon, send a restore since we are handling
2657 * a double click
2659 if (pWnd->dwStyle & WS_MINIMIZE)
2661 SendMessage16( pWnd->hwndSelf, WM_SYSCOMMAND, SC_RESTORE, lParam );
2662 return 0;
2665 switch(wParam) /* Hit test */
2667 case HTCAPTION:
2668 /* stop processing if WS_MAXIMIZEBOX is missing */
2669 if (pWnd->dwStyle & WS_MAXIMIZEBOX)
2670 SendMessage16( pWnd->hwndSelf, WM_SYSCOMMAND,
2671 (pWnd->dwStyle & WS_MAXIMIZE) ? SC_RESTORE : SC_MAXIMIZE,
2672 lParam );
2673 break;
2675 case HTSYSMENU:
2676 if (!(GetClassWord(pWnd->hwndSelf, GCW_STYLE) & CS_NOCLOSE))
2677 SendMessage16( pWnd->hwndSelf, WM_SYSCOMMAND, SC_CLOSE, lParam );
2678 break;
2680 case HTHSCROLL:
2681 SendMessage16( pWnd->hwndSelf, WM_SYSCOMMAND, SC_HSCROLL + HTHSCROLL,
2682 lParam );
2683 break;
2685 case HTVSCROLL:
2686 SendMessage16( pWnd->hwndSelf, WM_SYSCOMMAND, SC_VSCROLL + HTVSCROLL,
2687 lParam );
2688 break;
2690 return 0;
2694 /***********************************************************************
2695 * NC_HandleSysCommand
2697 * Handle a WM_SYSCOMMAND message. Called from DefWindowProc().
2699 LONG NC_HandleSysCommand( HWND hwnd, WPARAM16 wParam, POINT16 pt )
2701 WND *wndPtr = WIN_FindWndPtr( hwnd );
2702 POINT pt32;
2703 UINT16 uCommand = wParam & 0xFFF0;
2705 TRACE_(nonclient)("Handling WM_SYSCOMMAND %x %d,%d\n",
2706 wParam, pt.x, pt.y );
2708 if (wndPtr->dwStyle & WS_CHILD && uCommand != SC_KEYMENU )
2709 ScreenToClient16( wndPtr->parent->hwndSelf, &pt );
2711 switch (uCommand)
2713 case SC_SIZE:
2714 case SC_MOVE:
2715 NC_DoSizeMove( hwnd, wParam );
2716 break;
2718 case SC_MINIMIZE:
2719 ShowWindow( hwnd, SW_MINIMIZE );
2720 break;
2722 case SC_MAXIMIZE:
2723 ShowWindow( hwnd, SW_MAXIMIZE );
2724 break;
2726 case SC_RESTORE:
2727 ShowWindow( hwnd, SW_RESTORE );
2728 break;
2730 case SC_CLOSE:
2731 WIN_ReleaseWndPtr(wndPtr);
2732 return SendMessage16( hwnd, WM_CLOSE, 0, 0 );
2734 case SC_VSCROLL:
2735 case SC_HSCROLL:
2736 CONV_POINT16TO32( &pt, &pt32 );
2737 NC_TrackScrollBar( hwnd, wParam, pt32 );
2738 break;
2740 case SC_MOUSEMENU:
2741 CONV_POINT16TO32( &pt, &pt32 );
2742 MENU_TrackMouseMenuBar( wndPtr, wParam & 0x000F, pt32 );
2743 break;
2745 case SC_KEYMENU:
2746 MENU_TrackKbdMenuBar( wndPtr , wParam , pt.x );
2747 break;
2749 case SC_TASKLIST:
2750 WinExec( "taskman.exe", SW_SHOWNORMAL );
2751 break;
2753 case SC_SCREENSAVE:
2754 if (wParam == SC_ABOUTWINE)
2755 ShellAboutA(hwnd,"Wine", WINE_RELEASE_INFO, 0);
2756 else
2757 if (wParam == SC_PUTMARK)
2758 TRACE_(shell)("Mark requested by user\n");
2759 break;
2761 case SC_HOTKEY:
2762 case SC_ARRANGE:
2763 case SC_NEXTWINDOW:
2764 case SC_PREVWINDOW:
2765 FIXME_(nonclient)("unimplemented!\n");
2766 break;
2768 WIN_ReleaseWndPtr(wndPtr);
2769 return 0;
2772 /*************************************************************
2773 * NC_DrawGrayButton
2775 * Stub for the grayed button of the caption
2777 *************************************************************/
2779 BOOL NC_DrawGrayButton(HDC hdc, int x, int y)
2781 HBITMAP hMaskBmp;
2782 HDC hdcMask = CreateCompatibleDC (0);
2783 HBRUSH hOldBrush;
2785 hMaskBmp = CreateBitmap (12, 10, 1, 1, lpGrayMask);
2787 if(hMaskBmp == 0)
2788 return FALSE;
2790 SelectObject (hdcMask, hMaskBmp);
2792 /* Draw the grayed bitmap using the mask */
2793 hOldBrush = SelectObject (hdc, RGB(128, 128, 128));
2794 BitBlt (hdc, x, y, 12, 10,
2795 hdcMask, 0, 0, 0xB8074A);
2797 /* Clean up */
2798 SelectObject (hdc, hOldBrush);
2799 DeleteObject(hMaskBmp);
2800 DeleteDC (hdcMask);
2802 return TRUE;