Fixed infinite loop for 0-length wavehdrs.
[wine/multimedia.git] / windows / nonclient.c
blob3788e47456dee6eaefa69cacb0970ca5c91e7745
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 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
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) &&
100 Options.managed &&
101 !(exStyle & WS_EX_TOOLWINDOW) &&
102 ( ((style & WS_CAPTION) == WS_CAPTION) ||
103 (style & WS_THICKFRAME)))
104 return TRUE;
105 return FALSE;
108 /***********************************************************************
109 * NC_AdjustRect
111 * Compute the size of the window rectangle from the size of the
112 * client rectangle.
114 static void NC_AdjustRect( LPRECT16 rect, DWORD style, BOOL menu,
115 DWORD exStyle )
117 if (TWEAK_WineLook > WIN31_LOOK)
118 ERR_(nonclient)("Called in Win95 mode. Aiee! Please report this.\n" );
120 if(style & WS_ICONIC) return;
121 /* Decide if the window will be managed (see CreateWindowEx) */
122 if (!WIN_WindowNeedsWMBorder(style, exStyle))
124 if (HAS_THICKFRAME( style, exStyle ))
125 InflateRect16( rect, GetSystemMetrics(SM_CXFRAME), GetSystemMetrics(SM_CYFRAME) );
126 else
127 if (HAS_DLGFRAME( style, exStyle ))
128 InflateRect16( rect, GetSystemMetrics(SM_CXDLGFRAME), GetSystemMetrics(SM_CYDLGFRAME) );
129 else
130 if (HAS_THINFRAME( style ))
131 InflateRect16( rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
133 if ((style & WS_CAPTION) == WS_CAPTION)
134 rect->top -= GetSystemMetrics(SM_CYCAPTION) - GetSystemMetrics(SM_CYBORDER);
136 if (menu) rect->top -= GetSystemMetrics(SM_CYMENU) + GetSystemMetrics(SM_CYBORDER);
138 if (style & WS_VSCROLL) {
139 rect->right += GetSystemMetrics(SM_CXVSCROLL) - 1;
140 if(!HAS_ANYFRAME( style, exStyle ))
141 rect->right++;
144 if (style & WS_HSCROLL) {
145 rect->bottom += GetSystemMetrics(SM_CYHSCROLL) - 1;
146 if(!HAS_ANYFRAME( style, exStyle ))
147 rect->bottom++;
152 /******************************************************************************
153 * NC_AdjustRectOuter95
155 * Computes the size of the "outside" parts of the window based on the
156 * parameters of the client area.
158 + PARAMS
159 * LPRECT16 rect
160 * DWORD style
161 * BOOL32 menu
162 * DWORD exStyle
164 * NOTES
165 * "Outer" parts of a window means the whole window frame, caption and
166 * menu bar. It does not include "inner" parts of the frame like client
167 * edge, static edge or scroll bars.
169 * Revision history
170 * 05-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu)
171 * Original (NC_AdjustRect95) cut & paste from NC_AdjustRect
173 * 20-Jun-1998 Eric Kohl (ekohl@abo.rhein-zeitung.de)
174 * Split NC_AdjustRect95 into NC_AdjustRectOuter95 and
175 * NC_AdjustRectInner95 and added handling of Win95 styles.
177 * 28-Jul-1999 Ove Kåven (ovek@arcticnet.no)
178 * Streamlined window style checks.
180 *****************************************************************************/
182 static void
183 NC_AdjustRectOuter95 (LPRECT16 rect, DWORD style, BOOL menu, DWORD exStyle)
185 if(style & WS_ICONIC) return;
187 /* Decide if the window will be managed (see CreateWindowEx) */
188 if (!WIN_WindowNeedsWMBorder(style, exStyle))
190 if (HAS_THICKFRAME( style, exStyle ))
191 InflateRect16( rect, GetSystemMetrics(SM_CXFRAME), GetSystemMetrics(SM_CYFRAME) );
192 else
193 if (HAS_DLGFRAME( style, exStyle ))
194 InflateRect16(rect, GetSystemMetrics(SM_CXDLGFRAME), GetSystemMetrics(SM_CYDLGFRAME) );
195 else
196 if (HAS_THINFRAME( style ))
197 InflateRect16( rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
199 if ((style & WS_CAPTION) == WS_CAPTION)
201 if (exStyle & WS_EX_TOOLWINDOW)
202 rect->top -= GetSystemMetrics(SM_CYSMCAPTION);
203 else
204 rect->top -= GetSystemMetrics(SM_CYCAPTION);
208 if (menu)
209 rect->top -= GetSystemMetrics(SM_CYMENU);
213 /******************************************************************************
214 * NC_AdjustRectInner95
216 * Computes the size of the "inside" part of the window based on the
217 * parameters of the client area.
219 + PARAMS
220 * LPRECT16 rect
221 * DWORD style
222 * DWORD exStyle
224 * NOTES
225 * "Inner" part of a window means the window frame inside of the flat
226 * window frame. It includes the client edge, the static edge and the
227 * scroll bars.
229 * Revision history
230 * 05-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu)
231 * Original (NC_AdjustRect95) cut & paste from NC_AdjustRect
233 * 20-Jun-1998 Eric Kohl (ekohl@abo.rhein-zeitung.de)
234 * Split NC_AdjustRect95 into NC_AdjustRectOuter95 and
235 * NC_AdjustRectInner95 and added handling of Win95 styles.
237 *****************************************************************************/
239 static void
240 NC_AdjustRectInner95 (LPRECT16 rect, DWORD style, DWORD exStyle)
242 if(style & WS_ICONIC) return;
244 if (exStyle & WS_EX_CLIENTEDGE)
245 InflateRect16 (rect, GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE));
247 if (exStyle & WS_EX_STATICEDGE)
248 InflateRect16 (rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
250 if (style & WS_VSCROLL) rect->right += GetSystemMetrics(SM_CXVSCROLL);
251 if (style & WS_HSCROLL) rect->bottom += GetSystemMetrics(SM_CYHSCROLL);
255 /***********************************************************************
256 * DrawCaption16 [USER.660] Draws a caption bar
258 * PARAMS
259 * hwnd [I]
260 * hdc [I]
261 * lpRect [I]
262 * uFlags [I]
264 * RETURNS
265 * Success:
266 * Failure:
269 BOOL16 WINAPI
270 DrawCaption16 (HWND16 hwnd, HDC16 hdc, const RECT16 *rect, UINT16 uFlags)
272 RECT rect32;
274 if (rect)
275 CONV_RECT16TO32 (rect, &rect32);
277 return (BOOL16)DrawCaptionTempA (hwnd, hdc, rect ? &rect32 : NULL,
278 0, 0, NULL, uFlags & 0x1F);
282 /***********************************************************************
283 * DrawCaption32 [USER32.154] Draws a caption bar
285 * PARAMS
286 * hwnd [I]
287 * hdc [I]
288 * lpRect [I]
289 * uFlags [I]
291 * RETURNS
292 * Success:
293 * Failure:
296 BOOL WINAPI
297 DrawCaption (HWND hwnd, HDC hdc, const RECT *lpRect, UINT uFlags)
299 return DrawCaptionTempA (hwnd, hdc, lpRect, 0, 0, NULL, uFlags & 0x1F);
303 /***********************************************************************
304 * DrawCaptionTemp16 [USER.657]
306 * PARAMS
308 * RETURNS
309 * Success:
310 * Failure:
313 BOOL16 WINAPI
314 DrawCaptionTemp16 (HWND16 hwnd, HDC16 hdc, const RECT16 *rect, HFONT16 hFont,
315 HICON16 hIcon, LPCSTR str, UINT16 uFlags)
317 RECT rect32;
319 if (rect)
320 CONV_RECT16TO32(rect,&rect32);
322 return (BOOL16)DrawCaptionTempA (hwnd, hdc, rect?&rect32:NULL, hFont,
323 hIcon, str, uFlags & 0x1F);
327 /***********************************************************************
328 * DrawCaptionTemp32A [USER32.599]
330 * PARAMS
332 * RETURNS
333 * Success:
334 * Failure:
337 BOOL WINAPI
338 DrawCaptionTempA (HWND hwnd, HDC hdc, const RECT *rect, HFONT hFont,
339 HICON hIcon, LPCSTR str, UINT uFlags)
341 RECT rc = *rect;
343 TRACE_(nonclient)("(%08x,%08x,%p,%08x,%08x,\"%s\",%08x)\n",
344 hwnd, hdc, rect, hFont, hIcon, str, uFlags);
346 /* drawing background */
347 if (uFlags & DC_INBUTTON) {
348 FillRect (hdc, &rc, GetSysColorBrush (COLOR_3DFACE));
350 if (uFlags & DC_ACTIVE) {
351 HBRUSH hbr = SelectObject (hdc, CACHE_GetPattern55AABrush ());
352 PatBlt (hdc, rc.left, rc.top,
353 rc.right-rc.left, rc.bottom-rc.top, 0xFA0089);
354 SelectObject (hdc, hbr);
357 else {
358 FillRect (hdc, &rc, GetSysColorBrush ((uFlags & DC_ACTIVE) ?
359 COLOR_ACTIVECAPTION : COLOR_INACTIVECAPTION));
363 /* drawing icon */
364 if ((uFlags & DC_ICON) && !(uFlags & DC_SMALLCAP)) {
365 POINT pt;
367 pt.x = rc.left + 2;
368 pt.y = (rc.bottom + rc.top - GetSystemMetrics(SM_CYSMICON)) / 2;
370 if (hIcon) {
371 DrawIconEx (hdc, pt.x, pt.y, hIcon, GetSystemMetrics(SM_CXSMICON),
372 GetSystemMetrics(SM_CYSMICON), 0, 0, DI_NORMAL);
374 else {
375 HICON hAppIcon = (HICON) GetClassLongA(hwnd, GCL_HICONSM);
376 if(!hAppIcon) hAppIcon = (HICON) GetClassLongA(hwnd, GCL_HICON);
378 DrawIconEx (hdc, pt.x, pt.y, hAppIcon, GetSystemMetrics(SM_CXSMICON),
379 GetSystemMetrics(SM_CYSMICON), 0, 0, DI_NORMAL);
382 rc.left += (rc.bottom - rc.top);
385 /* drawing text */
386 if (uFlags & DC_TEXT) {
387 HFONT hOldFont;
389 if (uFlags & DC_INBUTTON)
390 SetTextColor (hdc, GetSysColor (COLOR_BTNTEXT));
391 else if (uFlags & DC_ACTIVE)
392 SetTextColor (hdc, GetSysColor (COLOR_CAPTIONTEXT));
393 else
394 SetTextColor (hdc, GetSysColor (COLOR_INACTIVECAPTIONTEXT));
396 SetBkMode (hdc, TRANSPARENT);
398 if (hFont)
399 hOldFont = SelectObject (hdc, hFont);
400 else {
401 NONCLIENTMETRICSA nclm;
402 HFONT hNewFont;
403 nclm.cbSize = sizeof(NONCLIENTMETRICSA);
404 SystemParametersInfoA (SPI_GETNONCLIENTMETRICS, 0, &nclm, 0);
405 hNewFont = CreateFontIndirectA ((uFlags & DC_SMALLCAP) ?
406 &nclm.lfSmCaptionFont : &nclm.lfCaptionFont);
407 hOldFont = SelectObject (hdc, hNewFont);
410 if (str)
411 DrawTextA (hdc, str, -1, &rc,
412 DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX | DT_LEFT);
413 else {
414 CHAR szText[128];
415 INT nLen;
416 nLen = GetWindowTextA (hwnd, szText, 128);
417 DrawTextA (hdc, szText, nLen, &rc,
418 DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX | DT_LEFT);
421 if (hFont)
422 SelectObject (hdc, hOldFont);
423 else
424 DeleteObject (SelectObject (hdc, hOldFont));
427 /* drawing focus ??? */
428 if (uFlags & 0x2000)
429 FIXME_(nonclient)("undocumented flag (0x2000)!\n");
431 return 0;
435 /***********************************************************************
436 * DrawCaptionTemp32W [USER32.602]
438 * PARAMS
440 * RETURNS
441 * Success:
442 * Failure:
445 BOOL WINAPI
446 DrawCaptionTempW (HWND hwnd, HDC hdc, const RECT *rect, HFONT hFont,
447 HICON hIcon, LPCWSTR str, UINT uFlags)
449 LPSTR p = HEAP_strdupWtoA (GetProcessHeap (), 0, str);
450 BOOL res = DrawCaptionTempA (hwnd, hdc, rect, hFont, hIcon, p, uFlags);
451 HeapFree (GetProcessHeap (), 0, p);
452 return res;
456 /***********************************************************************
457 * AdjustWindowRect16 (USER.102)
459 BOOL16 WINAPI AdjustWindowRect16( LPRECT16 rect, DWORD style, BOOL16 menu )
461 return AdjustWindowRectEx16( rect, style, menu, 0 );
465 /***********************************************************************
466 * AdjustWindowRect32 (USER32.2)
468 BOOL WINAPI AdjustWindowRect( LPRECT rect, DWORD style, BOOL menu )
470 return AdjustWindowRectEx( rect, style, menu, 0 );
474 /***********************************************************************
475 * AdjustWindowRectEx16 (USER.454)
477 BOOL16 WINAPI AdjustWindowRectEx16( LPRECT16 rect, DWORD style,
478 BOOL16 menu, DWORD exStyle )
480 /* Correct the window style */
482 if (!(style & (WS_POPUP | WS_CHILD))) /* Overlapped window */
483 style |= WS_CAPTION;
484 style &= (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME | WS_CHILD);
485 exStyle &= (WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE |
486 WS_EX_STATICEDGE | WS_EX_TOOLWINDOW);
487 if (exStyle & WS_EX_DLGMODALFRAME) style &= ~WS_THICKFRAME;
489 TRACE_(nonclient)("(%d,%d)-(%d,%d) %08lx %d %08lx\n",
490 rect->left, rect->top, rect->right, rect->bottom,
491 style, menu, exStyle );
493 if (TWEAK_WineLook == WIN31_LOOK)
494 NC_AdjustRect( rect, style, menu, exStyle );
495 else {
496 NC_AdjustRectOuter95( rect, style, menu, exStyle );
497 NC_AdjustRectInner95( rect, style, exStyle );
500 return TRUE;
504 /***********************************************************************
505 * AdjustWindowRectEx32 (USER32.3)
507 BOOL WINAPI AdjustWindowRectEx( LPRECT rect, DWORD style,
508 BOOL menu, DWORD exStyle )
510 RECT16 rect16;
511 BOOL ret;
513 CONV_RECT32TO16( rect, &rect16 );
514 ret = AdjustWindowRectEx16( &rect16, style, (BOOL16)menu, exStyle );
515 CONV_RECT16TO32( &rect16, rect );
516 return ret;
520 /***********************************************************************
521 * NC_HandleNCCalcSize
523 * Handle a WM_NCCALCSIZE message. Called from DefWindowProc().
525 LONG NC_HandleNCCalcSize( WND *pWnd, RECT *winRect )
527 RECT16 tmpRect = { 0, 0, 0, 0 };
528 LONG result = 0;
529 UINT style = (UINT) GetClassLongA(pWnd->hwndSelf, GCL_STYLE);
531 if (style & CS_VREDRAW) result |= WVR_VREDRAW;
532 if (style & CS_HREDRAW) result |= WVR_HREDRAW;
534 if( !( pWnd->dwStyle & WS_MINIMIZE ) ) {
535 if (TWEAK_WineLook == WIN31_LOOK)
536 NC_AdjustRect( &tmpRect, pWnd->dwStyle, FALSE, pWnd->dwExStyle );
537 else
538 NC_AdjustRectOuter95( &tmpRect, pWnd->dwStyle, FALSE, pWnd->dwExStyle );
540 winRect->left -= tmpRect.left;
541 winRect->top -= tmpRect.top;
542 winRect->right -= tmpRect.right;
543 winRect->bottom -= tmpRect.bottom;
545 if (HAS_MENU(pWnd)) {
546 TRACE_(nonclient)("Calling "
547 "GetMenuBarHeight with HWND 0x%x, width %d, "
548 "at (%d, %d).\n", pWnd->hwndSelf,
549 winRect->right - winRect->left,
550 -tmpRect.left, -tmpRect.top );
552 winRect->top +=
553 MENU_GetMenuBarHeight( pWnd->hwndSelf,
554 winRect->right - winRect->left,
555 -tmpRect.left, -tmpRect.top ) + 1;
558 if (TWEAK_WineLook > WIN31_LOOK) {
559 SetRect16 (&tmpRect, 0, 0, 0, 0);
560 NC_AdjustRectInner95 (&tmpRect, pWnd->dwStyle, pWnd->dwExStyle);
561 winRect->left -= tmpRect.left;
562 winRect->top -= tmpRect.top;
563 winRect->right -= tmpRect.right;
564 winRect->bottom -= tmpRect.bottom;
567 return result;
571 /***********************************************************************
572 * NC_GetInsideRect
574 * Get the 'inside' rectangle of a window, i.e. the whole window rectangle
575 * but without the borders (if any).
576 * The rectangle is in window coordinates (for drawing with GetWindowDC()).
578 static void NC_GetInsideRect( HWND hwnd, RECT *rect )
580 WND * wndPtr = WIN_FindWndPtr( hwnd );
582 rect->top = rect->left = 0;
583 rect->right = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
584 rect->bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
586 if ((wndPtr->dwStyle & WS_ICONIC) || (wndPtr->flags & WIN_MANAGED)) goto END;
588 /* Remove frame from rectangle */
589 if (HAS_THICKFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
590 InflateRect( rect, -GetSystemMetrics(SM_CXFRAME), -GetSystemMetrics(SM_CYFRAME) );
591 else
592 if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
594 InflateRect( rect, -GetSystemMetrics(SM_CXDLGFRAME), -GetSystemMetrics(SM_CYDLGFRAME));
595 /* FIXME: this isn't in NC_AdjustRect? why not? */
596 if (wndPtr->dwExStyle & WS_EX_DLGMODALFRAME)
597 InflateRect( rect, -1, 0 );
599 else
600 if (HAS_THINFRAME( wndPtr->dwStyle ))
601 InflateRect( rect, -GetSystemMetrics(SM_CXBORDER), -GetSystemMetrics(SM_CYBORDER) );
602 END:
603 WIN_ReleaseWndPtr(wndPtr);
604 return;
608 /***********************************************************************
609 * NC_GetInsideRect95
611 * Get the 'inside' rectangle of a window, i.e. the whole window rectangle
612 * but without the borders (if any).
613 * The rectangle is in window coordinates (for drawing with GetWindowDC()).
616 static void
617 NC_GetInsideRect95 (HWND hwnd, RECT *rect)
619 WND * wndPtr = WIN_FindWndPtr( hwnd );
621 rect->top = rect->left = 0;
622 rect->right = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
623 rect->bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
625 if ((wndPtr->dwStyle & WS_ICONIC) || (wndPtr->flags & WIN_MANAGED)) goto END;
627 /* Remove frame from rectangle */
628 if (HAS_THICKFRAME (wndPtr->dwStyle, wndPtr->dwExStyle))
630 InflateRect( rect, -GetSystemMetrics(SM_CXSIZEFRAME), -GetSystemMetrics(SM_CYSIZEFRAME) );
632 else if (HAS_DLGFRAME (wndPtr->dwStyle, wndPtr->dwExStyle ))
634 InflateRect( rect, -GetSystemMetrics(SM_CXFIXEDFRAME), -GetSystemMetrics(SM_CYFIXEDFRAME));
636 else if (HAS_THINFRAME (wndPtr->dwStyle))
638 InflateRect( rect, -GetSystemMetrics(SM_CXBORDER), -GetSystemMetrics(SM_CYBORDER) );
641 /* We have additional border information if the window
642 * is a child (but not an MDI child) */
643 if ( (wndPtr->dwStyle & WS_CHILD) &&
644 ( (wndPtr->dwExStyle & WS_EX_MDICHILD) == 0 ) )
646 if (wndPtr->dwExStyle & WS_EX_CLIENTEDGE)
647 InflateRect (rect, -GetSystemMetrics(SM_CXEDGE), -GetSystemMetrics(SM_CYEDGE));
649 if (wndPtr->dwExStyle & WS_EX_STATICEDGE)
650 InflateRect (rect, -GetSystemMetrics(SM_CXBORDER), -GetSystemMetrics(SM_CYBORDER));
652 END:
653 WIN_ReleaseWndPtr(wndPtr);
654 return;
658 /***********************************************************************
659 * NC_DoNCHitTest
661 * Handle a WM_NCHITTEST message. Called from NC_HandleNcHitTest().
664 static LONG NC_DoNCHitTest (WND *wndPtr, POINT16 pt )
666 RECT16 rect;
668 TRACE_(nonclient)("hwnd=%04x pt=%d,%d\n",
669 wndPtr->hwndSelf, pt.x, pt.y );
671 GetWindowRect16 (wndPtr->hwndSelf, &rect );
672 if (!PtInRect16( &rect, pt )) return HTNOWHERE;
674 if (wndPtr->dwStyle & WS_MINIMIZE) return HTCAPTION;
676 if (!(wndPtr->flags & WIN_MANAGED))
678 /* Check borders */
679 if (HAS_THICKFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
681 InflateRect16( &rect, -GetSystemMetrics(SM_CXFRAME), -GetSystemMetrics(SM_CYFRAME) );
682 if (!PtInRect16( &rect, pt ))
684 /* Check top sizing border */
685 if (pt.y < rect.top)
687 if (pt.x < rect.left+GetSystemMetrics(SM_CXSIZE)) return HTTOPLEFT;
688 if (pt.x >= rect.right-GetSystemMetrics(SM_CXSIZE)) return HTTOPRIGHT;
689 return HTTOP;
691 /* Check bottom sizing border */
692 if (pt.y >= rect.bottom)
694 if (pt.x < rect.left+GetSystemMetrics(SM_CXSIZE)) return HTBOTTOMLEFT;
695 if (pt.x >= rect.right-GetSystemMetrics(SM_CXSIZE)) return HTBOTTOMRIGHT;
696 return HTBOTTOM;
698 /* Check left sizing border */
699 if (pt.x < rect.left)
701 if (pt.y < rect.top+GetSystemMetrics(SM_CYSIZE)) return HTTOPLEFT;
702 if (pt.y >= rect.bottom-GetSystemMetrics(SM_CYSIZE)) return HTBOTTOMLEFT;
703 return HTLEFT;
705 /* Check right sizing border */
706 if (pt.x >= rect.right)
708 if (pt.y < rect.top+GetSystemMetrics(SM_CYSIZE)) return HTTOPRIGHT;
709 if (pt.y >= rect.bottom-GetSystemMetrics(SM_CYSIZE)) return HTBOTTOMRIGHT;
710 return HTRIGHT;
714 else /* No thick frame */
716 if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
717 InflateRect16(&rect, -GetSystemMetrics(SM_CXDLGFRAME), -GetSystemMetrics(SM_CYDLGFRAME));
718 else if (HAS_THINFRAME( wndPtr->dwStyle ))
719 InflateRect16(&rect, -GetSystemMetrics(SM_CXBORDER), -GetSystemMetrics(SM_CYBORDER));
720 if (!PtInRect16( &rect, pt )) return HTBORDER;
723 /* Check caption */
725 if ((wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION)
727 rect.top += GetSystemMetrics(SM_CYCAPTION) - GetSystemMetrics(SM_CYBORDER);
728 if (!PtInRect16( &rect, pt ))
730 /* Check system menu */
731 if (wndPtr->dwStyle & WS_SYSMENU)
732 rect.left += GetSystemMetrics(SM_CXSIZE);
733 if (pt.x <= rect.left) return HTSYSMENU;
735 /* Check maximize box */
736 if (wndPtr->dwStyle & WS_MAXIMIZEBOX)
737 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
739 if (pt.x >= rect.right) return HTMAXBUTTON;
740 /* Check minimize box */
741 if (wndPtr->dwStyle & WS_MINIMIZEBOX)
742 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
743 if (pt.x >= rect.right) return HTMINBUTTON;
744 return HTCAPTION;
749 /* Check client area */
751 ScreenToClient16( wndPtr->hwndSelf, &pt );
752 GetClientRect16( wndPtr->hwndSelf, &rect );
753 if (PtInRect16( &rect, pt )) return HTCLIENT;
755 /* Check vertical scroll bar */
757 if (wndPtr->dwStyle & WS_VSCROLL)
759 rect.right += GetSystemMetrics(SM_CXVSCROLL);
760 if (PtInRect16( &rect, pt )) return HTVSCROLL;
763 /* Check horizontal scroll bar */
765 if (wndPtr->dwStyle & WS_HSCROLL)
767 rect.bottom += GetSystemMetrics(SM_CYHSCROLL);
768 if (PtInRect16( &rect, pt ))
770 /* Check size box */
771 if ((wndPtr->dwStyle & WS_VSCROLL) &&
772 (pt.x >= rect.right - GetSystemMetrics(SM_CXVSCROLL)))
773 return HTSIZE;
774 return HTHSCROLL;
778 /* Check menu bar */
780 if (HAS_MENU(wndPtr))
782 if ((pt.y < 0) && (pt.x >= 0) && (pt.x < rect.right))
783 return HTMENU;
786 /* Should never get here */
787 return HTERROR;
791 /***********************************************************************
792 * NC_DoNCHitTest95
794 * Handle a WM_NCHITTEST message. Called from NC_HandleNCHitTest().
796 * FIXME: Just a modified copy of the Win 3.1 version.
799 static LONG
800 NC_DoNCHitTest95 (WND *wndPtr, POINT16 pt )
802 RECT16 rect;
804 TRACE_(nonclient)("hwnd=%04x pt=%d,%d\n",
805 wndPtr->hwndSelf, pt.x, pt.y );
807 GetWindowRect16 (wndPtr->hwndSelf, &rect );
808 if (!PtInRect16( &rect, pt )) return HTNOWHERE;
810 if (wndPtr->dwStyle & WS_MINIMIZE) return HTCAPTION;
812 if (!(wndPtr->flags & WIN_MANAGED))
814 /* Check borders */
815 if (HAS_THICKFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
817 InflateRect16( &rect, -GetSystemMetrics(SM_CXFRAME), -GetSystemMetrics(SM_CYFRAME) );
818 if (!PtInRect16( &rect, pt ))
820 /* Check top sizing border */
821 if (pt.y < rect.top)
823 if (pt.x < rect.left+GetSystemMetrics(SM_CXSIZE)) return HTTOPLEFT;
824 if (pt.x >= rect.right-GetSystemMetrics(SM_CXSIZE)) return HTTOPRIGHT;
825 return HTTOP;
827 /* Check bottom sizing border */
828 if (pt.y >= rect.bottom)
830 if (pt.x < rect.left+GetSystemMetrics(SM_CXSIZE)) return HTBOTTOMLEFT;
831 if (pt.x >= rect.right-GetSystemMetrics(SM_CXSIZE)) return HTBOTTOMRIGHT;
832 return HTBOTTOM;
834 /* Check left sizing border */
835 if (pt.x < rect.left)
837 if (pt.y < rect.top+GetSystemMetrics(SM_CYSIZE)) return HTTOPLEFT;
838 if (pt.y >= rect.bottom-GetSystemMetrics(SM_CYSIZE)) return HTBOTTOMLEFT;
839 return HTLEFT;
841 /* Check right sizing border */
842 if (pt.x >= rect.right)
844 if (pt.y < rect.top+GetSystemMetrics(SM_CYSIZE)) return HTTOPRIGHT;
845 if (pt.y >= rect.bottom-GetSystemMetrics(SM_CYSIZE)) return HTBOTTOMRIGHT;
846 return HTRIGHT;
850 else /* No thick frame */
852 if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
853 InflateRect16(&rect, -GetSystemMetrics(SM_CXDLGFRAME), -GetSystemMetrics(SM_CYDLGFRAME));
854 else if (HAS_THINFRAME( wndPtr->dwStyle ))
855 InflateRect16(&rect, -GetSystemMetrics(SM_CXBORDER), -GetSystemMetrics(SM_CYBORDER));
856 if (!PtInRect16( &rect, pt )) return HTBORDER;
859 /* Check caption */
861 if ((wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION)
863 if (wndPtr->dwExStyle & WS_EX_TOOLWINDOW)
864 rect.top += GetSystemMetrics(SM_CYSMCAPTION) - 1;
865 else
866 rect.top += GetSystemMetrics(SM_CYCAPTION) - 1;
867 if (!PtInRect16( &rect, pt ))
869 /* Check system menu */
870 if(wndPtr->dwStyle & WS_SYSMENU)
872 /* Check if there is an user icon */
873 HICON hIcon = (HICON) GetClassLongA(wndPtr->hwndSelf, GCL_HICONSM);
874 if(!hIcon) hIcon = (HICON) GetClassLongA(wndPtr->hwndSelf, GCL_HICON);
876 /* If there is an icon associated with the window OR */
877 /* If there is no hIcon specified and this is not a modal dialog, */
878 /* there is a system menu icon. */
879 if((hIcon != 0) || (!(wndPtr->dwStyle & DS_MODALFRAME)))
880 rect.left += GetSystemMetrics(SM_CYCAPTION) - 1;
882 if (pt.x < rect.left) return HTSYSMENU;
884 /* Check close button */
885 if (wndPtr->dwStyle & WS_SYSMENU)
886 rect.right -= GetSystemMetrics(SM_CYCAPTION) - 1;
887 if (pt.x > rect.right) return HTCLOSE;
889 /* Check maximize box */
890 /* In win95 there is automatically a Maximize button when there is a minimize one*/
891 if ((wndPtr->dwStyle & WS_MAXIMIZEBOX)|| (wndPtr->dwStyle & WS_MINIMIZEBOX))
892 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
893 if (pt.x > rect.right) return HTMAXBUTTON;
895 /* Check minimize box */
896 /* In win95 there is automatically a Maximize button when there is a Maximize one*/
897 if ((wndPtr->dwStyle & WS_MINIMIZEBOX)||(wndPtr->dwStyle & WS_MAXIMIZEBOX))
898 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
900 if (pt.x > rect.right) return HTMINBUTTON;
901 return HTCAPTION;
906 /* Check client area */
908 ScreenToClient16( wndPtr->hwndSelf, &pt );
909 GetClientRect16( wndPtr->hwndSelf, &rect );
910 if (PtInRect16( &rect, pt )) return HTCLIENT;
912 /* Check vertical scroll bar */
914 if (wndPtr->dwStyle & WS_VSCROLL)
916 rect.right += GetSystemMetrics(SM_CXVSCROLL);
917 if (PtInRect16( &rect, pt )) return HTVSCROLL;
920 /* Check horizontal scroll bar */
922 if (wndPtr->dwStyle & WS_HSCROLL)
924 rect.bottom += GetSystemMetrics(SM_CYHSCROLL);
925 if (PtInRect16( &rect, pt ))
927 /* Check size box */
928 if ((wndPtr->dwStyle & WS_VSCROLL) &&
929 (pt.x >= rect.right - GetSystemMetrics(SM_CXVSCROLL)))
930 return HTSIZE;
931 return HTHSCROLL;
935 /* Check menu bar */
937 if (HAS_MENU(wndPtr))
939 if ((pt.y < 0) && (pt.x >= 0) && (pt.x < rect.right))
940 return HTMENU;
943 /* Should never get here */
944 return HTERROR;
948 /***********************************************************************
949 * NC_HandleNCHitTest
951 * Handle a WM_NCHITTEST message. Called from DefWindowProc().
953 LONG
954 NC_HandleNCHitTest (HWND hwnd , POINT16 pt)
956 LONG retvalue;
957 WND *wndPtr = WIN_FindWndPtr (hwnd);
959 if (!wndPtr)
960 return HTERROR;
962 if (TWEAK_WineLook == WIN31_LOOK)
963 retvalue = NC_DoNCHitTest (wndPtr, pt);
964 else
965 retvalue = NC_DoNCHitTest95 (wndPtr, pt);
966 WIN_ReleaseWndPtr(wndPtr);
967 return retvalue;
971 /***********************************************************************
972 * NC_DrawSysButton
974 void NC_DrawSysButton( HWND hwnd, HDC hdc, BOOL down )
976 RECT rect;
977 HDC hdcMem;
978 HBITMAP hbitmap;
979 WND *wndPtr = WIN_FindWndPtr( hwnd );
981 if( !(wndPtr->flags & WIN_MANAGED) )
983 NC_GetInsideRect( hwnd, &rect );
984 hdcMem = CreateCompatibleDC( hdc );
985 hbitmap = SelectObject( hdcMem, hbitmapClose );
986 BitBlt(hdc, rect.left, rect.top, GetSystemMetrics(SM_CXSIZE), GetSystemMetrics(SM_CYSIZE),
987 hdcMem, (wndPtr->dwStyle & WS_CHILD) ? GetSystemMetrics(SM_CXSIZE) : 0, 0,
988 down ? NOTSRCCOPY : SRCCOPY );
989 SelectObject( hdcMem, hbitmap );
990 DeleteDC( hdcMem );
992 WIN_ReleaseWndPtr(wndPtr);
996 /***********************************************************************
997 * NC_DrawMaxButton
999 static void NC_DrawMaxButton( HWND hwnd, HDC16 hdc, BOOL down )
1001 RECT rect;
1002 WND *wndPtr = WIN_FindWndPtr( hwnd );
1003 HDC hdcMem;
1005 if( !(wndPtr->flags & WIN_MANAGED) )
1007 NC_GetInsideRect( hwnd, &rect );
1008 hdcMem = CreateCompatibleDC( hdc );
1009 SelectObject( hdcMem, (IsZoomed(hwnd)
1010 ? (down ? hbitmapRestoreD : hbitmapRestore)
1011 : (down ? hbitmapMaximizeD : hbitmapMaximize)) );
1012 BitBlt( hdc, rect.right - GetSystemMetrics(SM_CXSIZE) - 1, rect.top,
1013 GetSystemMetrics(SM_CXSIZE) + 1, GetSystemMetrics(SM_CYSIZE), hdcMem, 0, 0,
1014 SRCCOPY );
1015 DeleteDC( hdcMem );
1017 WIN_ReleaseWndPtr(wndPtr);
1022 /***********************************************************************
1023 * NC_DrawMinButton
1025 static void NC_DrawMinButton( HWND hwnd, HDC16 hdc, BOOL down )
1027 RECT rect;
1028 WND *wndPtr = WIN_FindWndPtr( hwnd );
1029 HDC hdcMem;
1031 if( !(wndPtr->flags & WIN_MANAGED) )
1033 NC_GetInsideRect( hwnd, &rect );
1034 hdcMem = CreateCompatibleDC( hdc );
1035 SelectObject( hdcMem, (down ? hbitmapMinimizeD : hbitmapMinimize) );
1036 if (wndPtr->dwStyle & WS_MAXIMIZEBOX) rect.right -= GetSystemMetrics(SM_CXSIZE)+1;
1037 BitBlt( hdc, rect.right - GetSystemMetrics(SM_CXSIZE) - 1, rect.top,
1038 GetSystemMetrics(SM_CXSIZE) + 1, GetSystemMetrics(SM_CYSIZE), hdcMem, 0, 0,
1039 SRCCOPY );
1040 DeleteDC( hdcMem );
1042 WIN_ReleaseWndPtr(wndPtr);
1046 /******************************************************************************
1048 * void NC_DrawSysButton95(
1049 * HWND32 hwnd,
1050 * HDC32 hdc,
1051 * BOOL32 down )
1053 * Draws the Win95 system icon.
1055 * Revision history
1056 * 05-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu)
1057 * Original implementation from NC_DrawSysButton source.
1058 * 11-Jun-1998 Eric Kohl (ekohl@abo.rhein-zeitung.de)
1059 * Fixed most bugs.
1061 *****************************************************************************/
1063 BOOL
1064 NC_DrawSysButton95 (HWND hwnd, HDC hdc, BOOL down)
1066 WND *wndPtr = WIN_FindWndPtr( hwnd );
1068 if( !(wndPtr->flags & WIN_MANAGED) )
1070 HICON hIcon;
1071 RECT rect;
1073 NC_GetInsideRect95( hwnd, &rect );
1075 hIcon = (HICON) GetClassLongA(wndPtr->hwndSelf, GCL_HICONSM);
1076 if(!hIcon) hIcon = (HICON) GetClassLongA(wndPtr->hwndSelf, GCL_HICON);
1078 /* If there is no hIcon specified or this is not a modal dialog, */
1079 /* get the default one. */
1080 if(hIcon == 0)
1081 if (!(wndPtr->dwStyle & DS_MODALFRAME))
1082 hIcon = LoadImageA(0, MAKEINTRESOURCEA(OIC_WINEICON), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
1084 if (hIcon)
1085 DrawIconEx (hdc, rect.left + 2, rect.top + 2, hIcon,
1086 GetSystemMetrics(SM_CXSMICON),
1087 GetSystemMetrics(SM_CYSMICON),
1088 0, 0, DI_NORMAL);
1090 WIN_ReleaseWndPtr(wndPtr);
1091 return (hIcon != 0);
1093 WIN_ReleaseWndPtr(wndPtr);
1094 return FALSE;
1098 /******************************************************************************
1100 * void NC_DrawCloseButton95(
1101 * HWND32 hwnd,
1102 * HDC32 hdc,
1103 * BOOL32 down,
1104 * BOOL bGrayed )
1106 * Draws the Win95 close button.
1108 * If bGrayed is true, then draw a disabled Close button
1110 * Revision history
1111 * 11-Jun-1998 Eric Kohl (ekohl@abo.rhein-zeitung.de)
1112 * Original implementation from NC_DrawSysButton95 source.
1114 *****************************************************************************/
1116 static void NC_DrawCloseButton95 (HWND hwnd, HDC hdc, BOOL down, BOOL bGrayed)
1118 RECT rect;
1119 HDC hdcMem;
1120 WND *wndPtr = WIN_FindWndPtr( hwnd );
1122 if( !(wndPtr->flags & WIN_MANAGED) )
1124 BITMAP bmp;
1125 HBITMAP hBmp, hOldBmp;
1127 NC_GetInsideRect95( hwnd, &rect );
1129 hdcMem = CreateCompatibleDC( hdc );
1130 hBmp = down ? hbitmapCloseD : hbitmapClose;
1131 hOldBmp = SelectObject (hdcMem, hBmp);
1132 GetObjectA (hBmp, sizeof(BITMAP), &bmp);
1134 BitBlt (hdc, rect.right - (GetSystemMetrics(SM_CYCAPTION) + 1 + bmp.bmWidth) / 2,
1135 rect.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2,
1136 bmp.bmWidth, bmp.bmHeight, hdcMem, 0, 0, SRCCOPY);
1138 if(bGrayed)
1139 NC_DrawGrayButton(hdc,rect.right - (GetSystemMetrics(SM_CYCAPTION) + 1 + bmp.bmWidth) / 2 + 2,
1140 rect.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2 + 2);
1142 SelectObject (hdcMem, hOldBmp);
1143 DeleteDC (hdcMem);
1145 WIN_ReleaseWndPtr(wndPtr);
1148 /******************************************************************************
1150 * NC_DrawMaxButton95(
1151 * HWND32 hwnd,
1152 * HDC16 hdc,
1153 * BOOL32 down
1154 * BOOL bGrayed )
1156 * Draws the maximize button for Win95 style windows.
1158 * If bGrayed is true, then draw a disabled Maximize button
1160 * Bugs
1161 * Many. Spacing might still be incorrect. Need to fit a close
1162 * button between the max button and the edge.
1163 * Should scale the image with the title bar. And more...
1165 * Revision history
1166 * 05-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu)
1167 * Original implementation.
1169 *****************************************************************************/
1171 static void NC_DrawMaxButton95(HWND hwnd,HDC16 hdc,BOOL down, BOOL bGrayed)
1173 RECT rect;
1174 HDC hdcMem;
1175 WND *wndPtr = WIN_FindWndPtr( hwnd );
1177 if( !(wndPtr->flags & WIN_MANAGED))
1179 BITMAP bmp;
1180 HBITMAP hBmp,hOldBmp;
1182 NC_GetInsideRect95( hwnd, &rect );
1183 hdcMem = CreateCompatibleDC( hdc );
1184 hBmp = IsZoomed(hwnd) ?
1185 (down ? hbitmapRestoreD : hbitmapRestore ) :
1186 (down ? hbitmapMaximizeD: hbitmapMaximize);
1187 hOldBmp=SelectObject( hdcMem, hBmp );
1188 GetObjectA (hBmp, sizeof(BITMAP), &bmp);
1190 if (wndPtr->dwStyle & WS_SYSMENU)
1191 rect.right -= GetSystemMetrics(SM_CYCAPTION) + 1;
1193 BitBlt( hdc, rect.right - (GetSystemMetrics(SM_CXSIZE) + bmp.bmWidth) / 2,
1194 rect.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2,
1195 bmp.bmWidth, bmp.bmHeight, hdcMem, 0, 0, SRCCOPY );
1197 if(bGrayed)
1198 NC_DrawGrayButton(hdc, rect.right - (GetSystemMetrics(SM_CXSIZE) + bmp.bmWidth) / 2 + 2,
1199 rect.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2 + 2);
1202 SelectObject (hdcMem, hOldBmp);
1203 DeleteDC( hdcMem );
1205 WIN_ReleaseWndPtr(wndPtr);
1208 /******************************************************************************
1210 * NC_DrawMinButton95(
1211 * HWND32 hwnd,
1212 * HDC16 hdc,
1213 * BOOL32 down,
1214 * BOOL bGrayed )
1216 * Draws the minimize button for Win95 style windows.
1218 * If bGrayed is true, then draw a disabled Minimize button
1220 * Bugs
1221 * Many. Spacing is still incorrect. Should scale the image with the
1222 * title bar. And more...
1224 * Revision history
1225 * 05-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu)
1226 * Original implementation.
1228 *****************************************************************************/
1230 static void NC_DrawMinButton95(HWND hwnd,HDC16 hdc,BOOL down, BOOL bGrayed)
1232 RECT rect;
1233 HDC hdcMem;
1234 WND *wndPtr = WIN_FindWndPtr( hwnd );
1236 if( !(wndPtr->flags & WIN_MANAGED))
1239 BITMAP bmp;
1240 HBITMAP hBmp,hOldBmp;
1242 NC_GetInsideRect95( hwnd, &rect );
1244 hdcMem = CreateCompatibleDC( hdc );
1245 hBmp = down ? hbitmapMinimizeD : hbitmapMinimize;
1246 hOldBmp= SelectObject( hdcMem, hBmp );
1247 GetObjectA (hBmp, sizeof(BITMAP), &bmp);
1249 if (wndPtr->dwStyle & WS_SYSMENU)
1250 rect.right -= GetSystemMetrics(SM_CYCAPTION) + 1;
1252 /* In win 95 there is always a Maximize box when there is a Minimize one */
1253 if ((wndPtr->dwStyle & WS_MAXIMIZEBOX) || (wndPtr->dwStyle & WS_MINIMIZEBOX))
1254 rect.right += -1 - (GetSystemMetrics(SM_CXSIZE) + bmp.bmWidth) / 2;
1256 BitBlt( hdc, rect.right - (GetSystemMetrics(SM_CXSIZE) + bmp.bmWidth) / 2,
1257 rect.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2,
1258 bmp.bmWidth, bmp.bmHeight, hdcMem, 0, 0, SRCCOPY );
1260 if(bGrayed)
1261 NC_DrawGrayButton(hdc, rect.right - (GetSystemMetrics(SM_CXSIZE) + bmp.bmWidth) / 2 + 2,
1262 rect.top + (GetSystemMetrics(SM_CYCAPTION) - 1 - bmp.bmHeight) / 2 + 2);
1265 SelectObject (hdcMem, hOldBmp);
1266 DeleteDC( hdcMem );
1268 WIN_ReleaseWndPtr(wndPtr);
1271 /***********************************************************************
1272 * NC_DrawFrame
1274 * Draw a window frame inside the given rectangle, and update the rectangle.
1275 * The correct pen for the frame must be selected in the DC.
1277 static void NC_DrawFrame( HDC hdc, RECT *rect, BOOL dlgFrame,
1278 BOOL active )
1280 INT width, height;
1282 if (TWEAK_WineLook != WIN31_LOOK)
1283 ERR_(nonclient)("Called in Win95 mode. Aiee! Please report this.\n" );
1285 if (dlgFrame)
1287 width = GetSystemMetrics(SM_CXDLGFRAME) - 1;
1288 height = GetSystemMetrics(SM_CYDLGFRAME) - 1;
1289 SelectObject( hdc, GetSysColorBrush(active ? COLOR_ACTIVECAPTION :
1290 COLOR_INACTIVECAPTION) );
1292 else
1294 width = GetSystemMetrics(SM_CXFRAME) - 2;
1295 height = GetSystemMetrics(SM_CYFRAME) - 2;
1296 SelectObject( hdc, GetSysColorBrush(active ? COLOR_ACTIVEBORDER :
1297 COLOR_INACTIVEBORDER) );
1300 /* Draw frame */
1301 PatBlt( hdc, rect->left, rect->top,
1302 rect->right - rect->left, height, PATCOPY );
1303 PatBlt( hdc, rect->left, rect->top,
1304 width, rect->bottom - rect->top, PATCOPY );
1305 PatBlt( hdc, rect->left, rect->bottom - 1,
1306 rect->right - rect->left, -height, PATCOPY );
1307 PatBlt( hdc, rect->right - 1, rect->top,
1308 -width, rect->bottom - rect->top, PATCOPY );
1310 if (dlgFrame)
1312 InflateRect( rect, -width, -height );
1314 else
1316 INT decYOff = GetSystemMetrics(SM_CXFRAME) + GetSystemMetrics(SM_CXSIZE) - 1;
1317 INT decXOff = GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYSIZE) - 1;
1319 /* Draw inner rectangle */
1321 SelectObject( hdc, GetStockObject(NULL_BRUSH) );
1322 Rectangle( hdc, rect->left + width, rect->top + height,
1323 rect->right - width , rect->bottom - height );
1325 /* Draw the decorations */
1327 MoveToEx( hdc, rect->left, rect->top + decYOff, NULL );
1328 LineTo( hdc, rect->left + width, rect->top + decYOff );
1329 MoveToEx( hdc, rect->right - 1, rect->top + decYOff, NULL );
1330 LineTo( hdc, rect->right - width - 1, rect->top + decYOff );
1331 MoveToEx( hdc, rect->left, rect->bottom - decYOff, NULL );
1332 LineTo( hdc, rect->left + width, rect->bottom - decYOff );
1333 MoveToEx( hdc, rect->right - 1, rect->bottom - decYOff, NULL );
1334 LineTo( hdc, rect->right - width - 1, rect->bottom - decYOff );
1336 MoveToEx( hdc, rect->left + decXOff, rect->top, NULL );
1337 LineTo( hdc, rect->left + decXOff, rect->top + height);
1338 MoveToEx( hdc, rect->left + decXOff, rect->bottom - 1, NULL );
1339 LineTo( hdc, rect->left + decXOff, rect->bottom - height - 1 );
1340 MoveToEx( hdc, rect->right - decXOff, rect->top, NULL );
1341 LineTo( hdc, rect->right - decXOff, rect->top + height );
1342 MoveToEx( hdc, rect->right - decXOff, rect->bottom - 1, NULL );
1343 LineTo( hdc, rect->right - decXOff, rect->bottom - height - 1 );
1345 InflateRect( rect, -width - 1, -height - 1 );
1350 /******************************************************************************
1352 * void NC_DrawFrame95(
1353 * HDC32 hdc,
1354 * RECT32 *rect,
1355 * BOOL32 dlgFrame,
1356 * BOOL32 active )
1358 * Draw a window frame inside the given rectangle, and update the rectangle.
1359 * The correct pen for the frame must be selected in the DC.
1361 * Bugs
1362 * Many. First, just what IS a frame in Win95? Note that the 3D look
1363 * on the outer edge is handled by NC_DoNCPaint95. As is the inner
1364 * edge. The inner rectangle just inside the frame is handled by the
1365 * Caption code.
1367 * In short, for most people, this function should be a nop (unless
1368 * you LIKE thick borders in Win95/NT4.0 -- I've been working with
1369 * them lately, but just to get this code right). Even so, it doesn't
1370 * appear to be so. It's being worked on...
1372 * Revision history
1373 * 06-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu)
1374 * Original implementation (based on NC_DrawFrame)
1375 * 02-Jun-1998 Eric Kohl (ekohl@abo.rhein-zeitung.de)
1376 * Some minor fixes.
1377 * 29-Jun-1999 Ove Kåven (ovek@arcticnet.no)
1378 * Fixed a fix or something.
1380 *****************************************************************************/
1382 static void NC_DrawFrame95(
1383 HDC hdc,
1384 RECT *rect,
1385 BOOL dlgFrame,
1386 BOOL active )
1388 INT width, height;
1390 if (dlgFrame)
1392 width = GetSystemMetrics(SM_CXDLGFRAME) - GetSystemMetrics(SM_CXEDGE);
1393 height = GetSystemMetrics(SM_CYDLGFRAME) - GetSystemMetrics(SM_CYEDGE);
1395 else
1397 width = GetSystemMetrics(SM_CXFRAME) - GetSystemMetrics(SM_CXEDGE);
1398 height = GetSystemMetrics(SM_CYFRAME) - GetSystemMetrics(SM_CYEDGE);
1401 SelectObject( hdc, GetSysColorBrush(active ? COLOR_ACTIVEBORDER :
1402 COLOR_INACTIVEBORDER) );
1404 /* Draw frame */
1405 PatBlt( hdc, rect->left, rect->top,
1406 rect->right - rect->left, height, PATCOPY );
1407 PatBlt( hdc, rect->left, rect->top,
1408 width, rect->bottom - rect->top, PATCOPY );
1409 PatBlt( hdc, rect->left, rect->bottom - 1,
1410 rect->right - rect->left, -height, PATCOPY );
1411 PatBlt( hdc, rect->right - 1, rect->top,
1412 -width, rect->bottom - rect->top, PATCOPY );
1414 InflateRect( rect, -width, -height );
1417 /***********************************************************************
1418 * NC_DrawMovingFrame
1420 * Draw the frame used when moving or resizing window.
1422 * FIXME: This causes problems in Win95 mode. (why?)
1424 static void NC_DrawMovingFrame( HDC hdc, RECT *rect, BOOL thickframe )
1426 if (thickframe)
1428 RECT16 r16;
1429 CONV_RECT32TO16( rect, &r16 );
1430 FastWindowFrame16( hdc, &r16, GetSystemMetrics(SM_CXFRAME),
1431 GetSystemMetrics(SM_CYFRAME), PATINVERT );
1433 else DrawFocusRect( hdc, rect );
1437 /***********************************************************************
1438 * NC_DrawCaption
1440 * Draw the window caption.
1441 * The correct pen for the window frame must be selected in the DC.
1443 static void NC_DrawCaption( HDC hdc, RECT *rect, HWND hwnd,
1444 DWORD style, BOOL active )
1446 RECT r = *rect;
1447 WND * wndPtr = WIN_FindWndPtr( hwnd );
1448 char buffer[256];
1450 if (wndPtr->flags & WIN_MANAGED)
1452 WIN_ReleaseWndPtr(wndPtr);
1453 return;
1456 if (!hbitmapClose)
1458 if (!(hbitmapClose = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_CLOSE) )))
1460 WIN_ReleaseWndPtr(wndPtr);
1461 return;
1463 hbitmapCloseD = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_CLOSED) );
1464 hbitmapMinimize = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_REDUCE) );
1465 hbitmapMinimizeD = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_REDUCED) );
1466 hbitmapMaximize = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_ZOOM) );
1467 hbitmapMaximizeD = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_ZOOMD) );
1468 hbitmapRestore = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_RESTORE) );
1469 hbitmapRestoreD = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_RESTORED) );
1472 if (wndPtr->dwExStyle & WS_EX_DLGMODALFRAME)
1474 HBRUSH hbrushOld = SelectObject(hdc, GetSysColorBrush(COLOR_WINDOW) );
1475 PatBlt( hdc, r.left, r.top, 1, r.bottom-r.top+1,PATCOPY );
1476 PatBlt( hdc, r.right-1, r.top, 1, r.bottom-r.top+1, PATCOPY );
1477 PatBlt( hdc, r.left, r.top-1, r.right-r.left, 1, PATCOPY );
1478 r.left++;
1479 r.right--;
1480 SelectObject( hdc, hbrushOld );
1482 WIN_ReleaseWndPtr(wndPtr);
1483 MoveTo16( hdc, r.left, r.bottom );
1484 LineTo( hdc, r.right, r.bottom );
1486 if (style & WS_SYSMENU)
1488 NC_DrawSysButton( hwnd, hdc, FALSE );
1489 r.left += GetSystemMetrics(SM_CXSIZE) + 1;
1490 MoveTo16( hdc, r.left - 1, r.top );
1491 LineTo( hdc, r.left - 1, r.bottom );
1493 if (style & WS_MAXIMIZEBOX)
1495 NC_DrawMaxButton( hwnd, hdc, FALSE );
1496 r.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1498 if (style & WS_MINIMIZEBOX)
1500 NC_DrawMinButton( hwnd, hdc, FALSE );
1501 r.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1504 FillRect( hdc, &r, GetSysColorBrush(active ? COLOR_ACTIVECAPTION :
1505 COLOR_INACTIVECAPTION) );
1507 if (GetWindowTextA( hwnd, buffer, sizeof(buffer) ))
1509 if (active) SetTextColor( hdc, GetSysColor( COLOR_CAPTIONTEXT ) );
1510 else SetTextColor( hdc, GetSysColor( COLOR_INACTIVECAPTIONTEXT ) );
1511 SetBkMode( hdc, TRANSPARENT );
1512 DrawTextA( hdc, buffer, -1, &r,
1513 DT_SINGLELINE | DT_CENTER | DT_VCENTER | DT_NOPREFIX );
1518 /******************************************************************************
1520 * NC_DrawCaption95(
1521 * HDC32 hdc,
1522 * RECT32 *rect,
1523 * HWND32 hwnd,
1524 * DWORD style,
1525 * BOOL32 active )
1527 * Draw the window caption for Win95 style windows.
1528 * The correct pen for the window frame must be selected in the DC.
1530 * Bugs
1531 * Hey, a function that finally works! Well, almost.
1532 * It's being worked on.
1534 * Revision history
1535 * 05-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu)
1536 * Original implementation.
1537 * 02-Jun-1998 Eric Kohl (ekohl@abo.rhein-zeitung.de)
1538 * Some minor fixes.
1540 *****************************************************************************/
1542 static void NC_DrawCaption95(
1543 HDC hdc,
1544 RECT *rect,
1545 HWND hwnd,
1546 DWORD style,
1547 DWORD exStyle,
1548 BOOL active )
1550 RECT r = *rect;
1551 WND *wndPtr = WIN_FindWndPtr( hwnd );
1552 char buffer[256];
1553 HPEN hPrevPen;
1554 HMENU hSysMenu;
1556 if (wndPtr->flags & WIN_MANAGED)
1558 WIN_ReleaseWndPtr(wndPtr);
1559 return;
1561 WIN_ReleaseWndPtr(wndPtr);
1563 hPrevPen = SelectObject( hdc, GetSysColorPen(COLOR_3DFACE) );
1564 MoveToEx( hdc, r.left, r.bottom - 1, NULL );
1565 LineTo( hdc, r.right, r.bottom - 1 );
1566 SelectObject( hdc, hPrevPen );
1567 r.bottom--;
1569 FillRect( hdc, &r, GetSysColorBrush(active ? COLOR_ACTIVECAPTION :
1570 COLOR_INACTIVECAPTION) );
1572 if (!hbitmapClose) {
1573 if (!(hbitmapClose = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_CLOSE) )))
1574 return;
1575 hbitmapCloseD = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_CLOSED));
1576 hbitmapMinimize = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_REDUCE) );
1577 hbitmapMinimizeD = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_REDUCED) );
1578 hbitmapMaximize = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_ZOOM) );
1579 hbitmapMaximizeD = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_ZOOMD) );
1580 hbitmapRestore = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_RESTORE) );
1581 hbitmapRestoreD = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_RESTORED) );
1584 if ((style & WS_SYSMENU) && !(exStyle & WS_EX_TOOLWINDOW)) {
1585 if (NC_DrawSysButton95 (hwnd, hdc, FALSE))
1586 r.left += GetSystemMetrics(SM_CYCAPTION) - 1;
1589 if (style & WS_SYSMENU)
1591 UINT state;
1593 /* Go get the sysmenu */
1594 hSysMenu = GetSystemMenu(hwnd, FALSE);
1595 state = GetMenuState(hSysMenu, SC_CLOSE, MF_BYCOMMAND);
1597 /* Draw a grayed close button if disabled and a normal one if SC_CLOSE is not there */
1598 NC_DrawCloseButton95 (hwnd, hdc, FALSE,
1599 ((((state & MF_DISABLED) || (state & MF_GRAYED))) && (state != 0xFFFFFFFF)));
1600 r.right -= GetSystemMetrics(SM_CYCAPTION) - 1;
1602 if ((style & WS_MAXIMIZEBOX) || (style & WS_MINIMIZEBOX))
1604 /* In win95 the two buttons are always there */
1605 /* But if the menu item is not in the menu they're disabled*/
1607 NC_DrawMaxButton95( hwnd, hdc, FALSE, (!(style & WS_MAXIMIZEBOX)));
1608 r.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1610 NC_DrawMinButton95( hwnd, hdc, FALSE, (!(style & WS_MINIMIZEBOX)));
1611 r.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1615 if (GetWindowTextA( hwnd, buffer, sizeof(buffer) )) {
1616 NONCLIENTMETRICSA nclm;
1617 HFONT hFont, hOldFont;
1618 nclm.cbSize = sizeof(NONCLIENTMETRICSA);
1619 SystemParametersInfoA (SPI_GETNONCLIENTMETRICS, 0, &nclm, 0);
1620 if (exStyle & WS_EX_TOOLWINDOW)
1621 hFont = CreateFontIndirectA (&nclm.lfSmCaptionFont);
1622 else
1623 hFont = CreateFontIndirectA (&nclm.lfCaptionFont);
1624 hOldFont = SelectObject (hdc, hFont);
1625 if (active) SetTextColor( hdc, GetSysColor( COLOR_CAPTIONTEXT ) );
1626 else SetTextColor( hdc, GetSysColor( COLOR_INACTIVECAPTIONTEXT ) );
1627 SetBkMode( hdc, TRANSPARENT );
1628 r.left += 2;
1629 DrawTextA( hdc, buffer, -1, &r,
1630 DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX | DT_LEFT );
1631 DeleteObject (SelectObject (hdc, hOldFont));
1637 /***********************************************************************
1638 * NC_DoNCPaint
1640 * Paint the non-client area. clip is currently unused.
1642 static void NC_DoNCPaint( WND* wndPtr, HRGN clip, BOOL suppress_menupaint )
1644 HDC hdc;
1645 RECT rect;
1646 BOOL active;
1647 HWND hwnd = wndPtr->hwndSelf;
1649 if ( wndPtr->dwStyle & WS_MINIMIZE ||
1650 !WIN_IsWindowDrawable( wndPtr, 0 )) return; /* Nothing to do */
1652 active = wndPtr->flags & WIN_NCACTIVATED;
1654 TRACE_(nonclient)("%04x %d\n", hwnd, active );
1656 if (!(hdc = GetDCEx( hwnd, (clip > 1) ? clip : 0, DCX_USESTYLE | DCX_WINDOW |
1657 ((clip > 1) ? (DCX_INTERSECTRGN | DCX_KEEPCLIPRGN): 0) ))) return;
1659 if (ExcludeVisRect16( hdc, wndPtr->rectClient.left-wndPtr->rectWindow.left,
1660 wndPtr->rectClient.top-wndPtr->rectWindow.top,
1661 wndPtr->rectClient.right-wndPtr->rectWindow.left,
1662 wndPtr->rectClient.bottom-wndPtr->rectWindow.top )
1663 == NULLREGION)
1665 ReleaseDC( hwnd, hdc );
1666 return;
1669 rect.top = rect.left = 0;
1670 rect.right = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
1671 rect.bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
1673 SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
1675 if (!(wndPtr->flags & WIN_MANAGED))
1677 if (HAS_ANYFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
1679 SelectObject( hdc, GetStockObject(NULL_BRUSH) );
1680 Rectangle( hdc, 0, 0, rect.right, rect.bottom );
1681 InflateRect( &rect, -1, -1 );
1684 if (HAS_THICKFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
1685 NC_DrawFrame(hdc, &rect, FALSE, active );
1686 else if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
1687 NC_DrawFrame( hdc, &rect, TRUE, active );
1689 if ((wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION)
1691 RECT r = rect;
1692 r.bottom = rect.top + GetSystemMetrics(SM_CYSIZE);
1693 rect.top += GetSystemMetrics(SM_CYSIZE) + GetSystemMetrics(SM_CYBORDER);
1694 NC_DrawCaption( hdc, &r, hwnd, wndPtr->dwStyle, active );
1698 if (HAS_MENU(wndPtr))
1700 RECT r = rect;
1701 r.bottom = rect.top + GetSystemMetrics(SM_CYMENU); /* default height */
1702 rect.top += MENU_DrawMenuBar( hdc, &r, hwnd, suppress_menupaint );
1705 /* Draw the scroll-bars */
1707 if (wndPtr->dwStyle & WS_VSCROLL)
1708 SCROLL_DrawScrollBar( hwnd, hdc, SB_VERT, TRUE, TRUE );
1709 if (wndPtr->dwStyle & WS_HSCROLL)
1710 SCROLL_DrawScrollBar( hwnd, hdc, SB_HORZ, TRUE, TRUE );
1712 /* Draw the "size-box" */
1714 if ((wndPtr->dwStyle & WS_VSCROLL) && (wndPtr->dwStyle & WS_HSCROLL))
1716 RECT r = rect;
1717 r.left = r.right - GetSystemMetrics(SM_CXVSCROLL) + 1;
1718 r.top = r.bottom - GetSystemMetrics(SM_CYHSCROLL) + 1;
1719 if(wndPtr->dwStyle & WS_BORDER) {
1720 r.left++;
1721 r.top++;
1723 FillRect( hdc, &r, GetSysColorBrush(COLOR_SCROLLBAR) );
1726 ReleaseDC( hwnd, hdc );
1730 /******************************************************************************
1732 * void NC_DoNCPaint95(
1733 * WND *wndPtr,
1734 * HRGN32 clip,
1735 * BOOL32 suppress_menupaint )
1737 * Paint the non-client area for Win95 windows. The clip region is
1738 * currently ignored.
1740 * Bugs
1741 * grep -E -A10 -B5 \(95\)\|\(Bugs\)\|\(FIXME\) windows/nonclient.c \
1742 * misc/tweak.c controls/menu.c # :-)
1744 * Revision history
1745 * 03-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu)
1746 * Original implementation
1747 * 10-Jun-1998 Eric Kohl (ekohl@abo.rhein-zeitung.de)
1748 * Fixed some bugs.
1749 * 29-Jun-1999 Ove Kåven (ovek@arcticnet.no)
1750 * Streamlined window style checks.
1752 *****************************************************************************/
1754 static void NC_DoNCPaint95(
1755 WND *wndPtr,
1756 HRGN clip,
1757 BOOL suppress_menupaint )
1759 HDC hdc;
1760 RECT rfuzz, rect, rectClip;
1761 BOOL active;
1762 HWND hwnd = wndPtr->hwndSelf;
1764 if ( wndPtr->dwStyle & WS_MINIMIZE ||
1765 !WIN_IsWindowDrawable( wndPtr, 0 )) return; /* Nothing to do */
1767 active = wndPtr->flags & WIN_NCACTIVATED;
1769 TRACE_(nonclient)("%04x %d\n", hwnd, active );
1771 /* MSDN docs are pretty idiotic here, they say app CAN use clipRgn in the call to
1772 * GetDCEx implying that it is allowed not to use it either. However, the suggested
1773 * GetDCEx( , DCX_WINDOW | DCX_INTERSECTRGN) will cause clipRgn to be deleted
1774 * after ReleaseDC(). Now, how is the "system" supposed to tell what happened?
1777 if (!(hdc = GetDCEx( hwnd, (clip > 1) ? clip : 0, DCX_USESTYLE | DCX_WINDOW |
1778 ((clip > 1) ?(DCX_INTERSECTRGN | DCX_KEEPCLIPRGN) : 0) ))) return;
1781 if (ExcludeVisRect16( hdc, wndPtr->rectClient.left-wndPtr->rectWindow.left,
1782 wndPtr->rectClient.top-wndPtr->rectWindow.top,
1783 wndPtr->rectClient.right-wndPtr->rectWindow.left,
1784 wndPtr->rectClient.bottom-wndPtr->rectWindow.top )
1785 == NULLREGION)
1787 ReleaseDC( hwnd, hdc );
1788 return;
1791 rect.top = rect.left = 0;
1792 rect.right = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
1793 rect.bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
1795 if( clip > 1 )
1796 GetRgnBox( clip, &rectClip );
1797 else
1799 clip = 0;
1800 rectClip = rect;
1803 SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) );
1805 if(!(wndPtr->flags & WIN_MANAGED)) {
1806 if (HAS_BIGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle)) {
1807 DrawEdge (hdc, &rect, EDGE_RAISED, BF_RECT | BF_ADJUST);
1809 if (HAS_THICKFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
1810 NC_DrawFrame95(hdc, &rect, FALSE, active );
1811 else if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
1812 NC_DrawFrame95( hdc, &rect, TRUE, active );
1813 else if (HAS_THINFRAME( wndPtr->dwStyle )) {
1814 SelectObject( hdc, GetStockObject(NULL_BRUSH) );
1815 Rectangle( hdc, 0, 0, rect.right, rect.bottom );
1818 if ((wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION)
1820 RECT r = rect;
1821 if (wndPtr->dwExStyle & WS_EX_TOOLWINDOW) {
1822 r.bottom = rect.top + GetSystemMetrics(SM_CYSMCAPTION);
1823 rect.top += GetSystemMetrics(SM_CYSMCAPTION);
1825 else {
1826 r.bottom = rect.top + GetSystemMetrics(SM_CYCAPTION);
1827 rect.top += GetSystemMetrics(SM_CYCAPTION);
1829 if( !clip || IntersectRect( &rfuzz, &r, &rectClip ) )
1830 NC_DrawCaption95 (hdc, &r, hwnd, wndPtr->dwStyle,
1831 wndPtr->dwExStyle, active);
1835 if (HAS_MENU(wndPtr))
1837 RECT r = rect;
1838 r.bottom = rect.top + GetSystemMetrics(SM_CYMENU);
1840 TRACE_(nonclient)("Calling DrawMenuBar with "
1841 "rect (%d, %d)-(%d, %d)\n", r.left, r.top,
1842 r.right, r.bottom);
1844 rect.top += MENU_DrawMenuBar( hdc, &r, hwnd, suppress_menupaint ) + 1;
1847 TRACE_(nonclient)("After MenuBar, rect is (%d, %d)-(%d, %d).\n",
1848 rect.left, rect.top, rect.right, rect.bottom );
1850 if (wndPtr->dwExStyle & WS_EX_CLIENTEDGE)
1851 DrawEdge (hdc, &rect, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
1853 if (wndPtr->dwExStyle & WS_EX_STATICEDGE)
1854 DrawEdge (hdc, &rect, BDR_SUNKENOUTER, BF_RECT | BF_ADJUST);
1856 /* Draw the scroll-bars */
1858 if (wndPtr->dwStyle & WS_VSCROLL)
1859 SCROLL_DrawScrollBar( hwnd, hdc, SB_VERT, TRUE, TRUE );
1860 if (wndPtr->dwStyle & WS_HSCROLL)
1861 SCROLL_DrawScrollBar( hwnd, hdc, SB_HORZ, TRUE, TRUE );
1863 /* Draw the "size-box" */
1864 if ((wndPtr->dwStyle & WS_VSCROLL) && (wndPtr->dwStyle & WS_HSCROLL))
1866 RECT r = rect;
1867 r.left = r.right - GetSystemMetrics(SM_CXVSCROLL) + 1;
1868 r.top = r.bottom - GetSystemMetrics(SM_CYHSCROLL) + 1;
1869 FillRect( hdc, &r, GetSysColorBrush(COLOR_SCROLLBAR) );
1872 ReleaseDC( hwnd, hdc );
1878 /***********************************************************************
1879 * NC_HandleNCPaint
1881 * Handle a WM_NCPAINT message. Called from DefWindowProc().
1883 LONG NC_HandleNCPaint( HWND hwnd , HRGN clip)
1885 WND* wndPtr = WIN_FindWndPtr( hwnd );
1887 if( wndPtr && wndPtr->dwStyle & WS_VISIBLE )
1889 if( wndPtr->dwStyle & WS_MINIMIZE )
1890 WINPOS_RedrawIconTitle( hwnd );
1891 else if (TWEAK_WineLook == WIN31_LOOK)
1892 NC_DoNCPaint( wndPtr, clip, FALSE );
1893 else
1894 NC_DoNCPaint95( wndPtr, clip, FALSE );
1896 WIN_ReleaseWndPtr(wndPtr);
1897 return 0;
1901 /***********************************************************************
1902 * NC_HandleNCActivate
1904 * Handle a WM_NCACTIVATE message. Called from DefWindowProc().
1906 LONG NC_HandleNCActivate( WND *wndPtr, WPARAM16 wParam )
1908 WORD wStateChange;
1910 if( wParam ) wStateChange = !(wndPtr->flags & WIN_NCACTIVATED);
1911 else wStateChange = wndPtr->flags & WIN_NCACTIVATED;
1913 if( wStateChange )
1915 if (wParam) wndPtr->flags |= WIN_NCACTIVATED;
1916 else wndPtr->flags &= ~WIN_NCACTIVATED;
1918 if( wndPtr->dwStyle & WS_MINIMIZE )
1919 WINPOS_RedrawIconTitle( wndPtr->hwndSelf );
1920 else if (TWEAK_WineLook == WIN31_LOOK)
1921 NC_DoNCPaint( wndPtr, (HRGN)1, FALSE );
1922 else
1923 NC_DoNCPaint95( wndPtr, (HRGN)1, FALSE );
1925 return TRUE;
1929 /***********************************************************************
1930 * NC_HandleSetCursor
1932 * Handle a WM_SETCURSOR message. Called from DefWindowProc().
1934 LONG NC_HandleSetCursor( HWND hwnd, WPARAM16 wParam, LPARAM lParam )
1936 if (hwnd != (HWND)wParam) return 0; /* Don't set the cursor for child windows */
1938 switch(LOWORD(lParam))
1940 case HTERROR:
1942 WORD msg = HIWORD( lParam );
1943 if ((msg == WM_LBUTTONDOWN) || (msg == WM_MBUTTONDOWN) ||
1944 (msg == WM_RBUTTONDOWN))
1945 MessageBeep(0);
1947 break;
1949 case HTCLIENT:
1951 HICON16 hCursor = (HICON16) GetClassWord(hwnd, GCW_HCURSOR);
1952 if(hCursor) {
1953 SetCursor16(hCursor);
1954 return TRUE;
1956 return FALSE;
1959 case HTLEFT:
1960 case HTRIGHT:
1961 return (LONG)SetCursor16( LoadCursor16( 0, IDC_SIZEWE16 ) );
1963 case HTTOP:
1964 case HTBOTTOM:
1965 return (LONG)SetCursor16( LoadCursor16( 0, IDC_SIZENS16 ) );
1967 case HTTOPLEFT:
1968 case HTBOTTOMRIGHT:
1969 return (LONG)SetCursor16( LoadCursor16( 0, IDC_SIZENWSE16 ) );
1971 case HTTOPRIGHT:
1972 case HTBOTTOMLEFT:
1973 return (LONG)SetCursor16( LoadCursor16( 0, IDC_SIZENESW16 ) );
1976 /* Default cursor: arrow */
1977 return (LONG)SetCursor16( LoadCursor16( 0, IDC_ARROW16 ) );
1980 /***********************************************************************
1981 * NC_GetSysPopupPos
1983 BOOL NC_GetSysPopupPos( WND* wndPtr, RECT* rect )
1985 if( wndPtr->hSysMenu )
1987 if( wndPtr->dwStyle & WS_MINIMIZE )
1988 GetWindowRect( wndPtr->hwndSelf, rect );
1989 else
1991 if (TWEAK_WineLook == WIN31_LOOK)
1992 NC_GetInsideRect( wndPtr->hwndSelf, rect );
1993 else
1994 NC_GetInsideRect95( wndPtr->hwndSelf, rect );
1995 OffsetRect( rect, wndPtr->rectWindow.left, wndPtr->rectWindow.top);
1996 if (wndPtr->dwStyle & WS_CHILD)
1997 ClientToScreen( wndPtr->parent->hwndSelf, (POINT *)rect );
1998 if (TWEAK_WineLook == WIN31_LOOK) {
1999 rect->right = rect->left + GetSystemMetrics(SM_CXSIZE);
2000 rect->bottom = rect->top + GetSystemMetrics(SM_CYSIZE);
2002 else {
2003 rect->right = rect->left + GetSystemMetrics(SM_CYCAPTION) - 1;
2004 rect->bottom = rect->top + GetSystemMetrics(SM_CYCAPTION) - 1;
2007 return TRUE;
2009 return FALSE;
2012 /***********************************************************************
2013 * NC_StartSizeMove
2015 * Initialisation of a move or resize, when initiatied from a menu choice.
2016 * Return hit test code for caption or sizing border.
2018 static LONG NC_StartSizeMove( WND* wndPtr, WPARAM16 wParam,
2019 POINT16 *capturePoint )
2021 LONG hittest = 0;
2022 POINT16 pt;
2023 MSG msg;
2024 RECT rectWindow;
2026 GetWindowRect(wndPtr->hwndSelf,&rectWindow);
2028 if ((wParam & 0xfff0) == SC_MOVE)
2030 /* Move pointer at the center of the caption */
2031 RECT rect;
2032 if (TWEAK_WineLook == WIN31_LOOK)
2033 NC_GetInsideRect( wndPtr->hwndSelf, &rect );
2034 else
2035 NC_GetInsideRect95( wndPtr->hwndSelf, &rect );
2036 if (wndPtr->dwStyle & WS_SYSMENU)
2037 rect.left += GetSystemMetrics(SM_CXSIZE) + 1;
2038 if (wndPtr->dwStyle & WS_MINIMIZEBOX)
2039 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
2040 if (wndPtr->dwStyle & WS_MAXIMIZEBOX)
2041 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
2042 pt.x = rectWindow.left + (rect.right - rect.left) / 2;
2043 pt.y = rectWindow.top + rect.top + GetSystemMetrics(SM_CYSIZE)/2;
2044 hittest = HTCAPTION;
2045 *capturePoint = pt;
2047 else /* SC_SIZE */
2049 while(!hittest)
2051 MSG_InternalGetMessage( &msg, 0, 0, MSGF_SIZE, PM_REMOVE, FALSE, NULL );
2052 switch(msg.message)
2054 case WM_MOUSEMOVE:
2055 CONV_POINT32TO16(&msg.pt, &pt);
2056 hittest = NC_HandleNCHitTest( wndPtr->hwndSelf, pt );
2057 if ((hittest < HTLEFT) || (hittest > HTBOTTOMRIGHT))
2058 hittest = 0;
2059 break;
2061 case WM_LBUTTONUP:
2062 return 0;
2064 case WM_KEYDOWN:
2065 switch(msg.wParam)
2067 case VK_UP:
2068 hittest = HTTOP;
2069 pt.x =(rectWindow.left+rectWindow.right)/2;
2070 pt.y = rectWindow.top + GetSystemMetrics(SM_CYFRAME) / 2;
2071 break;
2072 case VK_DOWN:
2073 hittest = HTBOTTOM;
2074 pt.x =(rectWindow.left+rectWindow.right)/2;
2075 pt.y = rectWindow.bottom - GetSystemMetrics(SM_CYFRAME) / 2;
2076 break;
2077 case VK_LEFT:
2078 hittest = HTLEFT;
2079 pt.x = rectWindow.left + GetSystemMetrics(SM_CXFRAME) / 2;
2080 pt.y =(rectWindow.top+rectWindow.bottom)/2;
2081 break;
2082 case VK_RIGHT:
2083 hittest = HTRIGHT;
2084 pt.x = rectWindow.right - GetSystemMetrics(SM_CXFRAME) / 2;
2085 pt.y =(rectWindow.top+rectWindow.bottom)/2;
2086 break;
2087 case VK_RETURN:
2088 case VK_ESCAPE: return 0;
2092 *capturePoint = pt;
2094 SetCursorPos( pt.x, pt.y );
2095 NC_HandleSetCursor( wndPtr->hwndSelf,
2096 wndPtr->hwndSelf, MAKELONG( hittest, WM_MOUSEMOVE ));
2097 return hittest;
2101 /***********************************************************************
2102 * NC_DoSizeMove
2104 * Perform SC_MOVE and SC_SIZE commands. `
2106 static void NC_DoSizeMove( HWND hwnd, WORD wParam )
2108 MSG msg;
2109 RECT sizingRect, mouseRect;
2110 HDC hdc;
2111 LONG hittest = (LONG)(wParam & 0x0f);
2112 HCURSOR16 hDragCursor = 0, hOldCursor = 0;
2113 POINT minTrack, maxTrack;
2114 POINT16 capturePoint, pt;
2115 WND * wndPtr = WIN_FindWndPtr( hwnd );
2116 BOOL thickframe = HAS_THICKFRAME( wndPtr->dwStyle, wndPtr->dwExStyle );
2117 BOOL iconic = wndPtr->dwStyle & WS_MINIMIZE;
2118 BOOL moved = FALSE;
2119 DWORD dwPoint = GetMessagePos ();
2121 capturePoint = pt = *(POINT16*)&dwPoint;
2123 if (IsZoomed(hwnd) || !IsWindowVisible(hwnd) ||
2124 (wndPtr->flags & WIN_MANAGED)) goto END;
2126 if ((wParam & 0xfff0) == SC_MOVE)
2128 if (!(wndPtr->dwStyle & WS_CAPTION)) goto END;
2129 if (!hittest)
2130 hittest = NC_StartSizeMove( wndPtr, wParam, &capturePoint );
2131 if (!hittest) goto END;
2133 else /* SC_SIZE */
2135 if (!thickframe) goto END;
2136 if ( hittest && hittest != HTSYSMENU ) hittest += 2;
2137 else
2139 SetCapture(hwnd);
2140 hittest = NC_StartSizeMove( wndPtr, wParam, &capturePoint );
2141 if (!hittest)
2143 ReleaseCapture();
2144 goto END;
2149 /* Get min/max info */
2151 WINPOS_GetMinMaxInfo( wndPtr, NULL, NULL, &minTrack, &maxTrack );
2152 sizingRect = wndPtr->rectWindow;
2153 if (wndPtr->dwStyle & WS_CHILD)
2154 GetClientRect( wndPtr->parent->hwndSelf, &mouseRect );
2155 else
2156 SetRect(&mouseRect, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
2157 if (ON_LEFT_BORDER(hittest))
2159 mouseRect.left = MAX( mouseRect.left, sizingRect.right-maxTrack.x );
2160 mouseRect.right = MIN( mouseRect.right, sizingRect.right-minTrack.x );
2162 else if (ON_RIGHT_BORDER(hittest))
2164 mouseRect.left = MAX( mouseRect.left, sizingRect.left+minTrack.x );
2165 mouseRect.right = MIN( mouseRect.right, sizingRect.left+maxTrack.x );
2167 if (ON_TOP_BORDER(hittest))
2169 mouseRect.top = MAX( mouseRect.top, sizingRect.bottom-maxTrack.y );
2170 mouseRect.bottom = MIN( mouseRect.bottom,sizingRect.bottom-minTrack.y);
2172 else if (ON_BOTTOM_BORDER(hittest))
2174 mouseRect.top = MAX( mouseRect.top, sizingRect.top+minTrack.y );
2175 mouseRect.bottom = MIN( mouseRect.bottom, sizingRect.top+maxTrack.y );
2177 if (wndPtr->dwStyle & WS_CHILD)
2179 MapWindowPoints( wndPtr->parent->hwndSelf, 0,
2180 (LPPOINT)&mouseRect, 2 );
2182 SendMessage16( hwnd, WM_ENTERSIZEMOVE, 0, 0 );
2184 if (GetCapture() != hwnd) SetCapture( hwnd );
2186 if (wndPtr->dwStyle & WS_CHILD)
2188 /* Retrieve a default cache DC (without using the window style) */
2189 hdc = GetDCEx( wndPtr->parent->hwndSelf, 0, DCX_CACHE );
2191 else
2192 { /* Grab the server only when moving top-level windows without desktop */
2193 hdc = GetDC( 0 );
2196 wndPtr->pDriver->pPreSizeMove(wndPtr);
2198 if( iconic ) /* create a cursor for dragging */
2200 HICON16 hIcon = GetClassWord(wndPtr->hwndSelf, GCW_HICON);
2201 if(!hIcon) hIcon = (HICON16) SendMessage16( hwnd, WM_QUERYDRAGICON, 0, 0L);
2202 if( hIcon ) hDragCursor = CURSORICON_IconToCursor( hIcon, TRUE );
2203 if( !hDragCursor ) iconic = FALSE;
2206 if( !iconic ) NC_DrawMovingFrame( hdc, &sizingRect, thickframe );
2208 while(1)
2210 int dx = 0, dy = 0;
2212 MSG_InternalGetMessage( &msg, 0, 0, MSGF_SIZE, PM_REMOVE, FALSE, NULL );
2214 /* Exit on button-up, Return, or Esc */
2215 if ((msg.message == WM_LBUTTONUP) ||
2216 ((msg.message == WM_KEYDOWN) &&
2217 ((msg.wParam == VK_RETURN) || (msg.wParam == VK_ESCAPE)))) break;
2219 if ((msg.message != WM_KEYDOWN) && (msg.message != WM_MOUSEMOVE))
2220 continue; /* We are not interested in other messages */
2222 dwPoint = GetMessagePos ();
2223 pt = *(POINT16*)&dwPoint;
2225 if (msg.message == WM_KEYDOWN) switch(msg.wParam)
2227 case VK_UP: pt.y -= 8; break;
2228 case VK_DOWN: pt.y += 8; break;
2229 case VK_LEFT: pt.x -= 8; break;
2230 case VK_RIGHT: pt.x += 8; break;
2233 pt.x = MAX( pt.x, mouseRect.left );
2234 pt.x = MIN( pt.x, mouseRect.right );
2235 pt.y = MAX( pt.y, mouseRect.top );
2236 pt.y = MIN( pt.y, mouseRect.bottom );
2238 dx = pt.x - capturePoint.x;
2239 dy = pt.y - capturePoint.y;
2241 if (dx || dy)
2243 if( !moved )
2245 moved = TRUE;
2246 if( iconic ) /* ok, no system popup tracking */
2248 hOldCursor = SetCursor(hDragCursor);
2249 ShowCursor( TRUE );
2250 WINPOS_ShowIconTitle( wndPtr, FALSE );
2254 if (msg.message == WM_KEYDOWN) SetCursorPos( pt.x, pt.y );
2255 else
2257 RECT newRect = sizingRect;
2259 if (hittest == HTCAPTION) OffsetRect( &newRect, dx, dy );
2260 if (ON_LEFT_BORDER(hittest)) newRect.left += dx;
2261 else if (ON_RIGHT_BORDER(hittest)) newRect.right += dx;
2262 if (ON_TOP_BORDER(hittest)) newRect.top += dy;
2263 else if (ON_BOTTOM_BORDER(hittest)) newRect.bottom += dy;
2264 if( !iconic )
2266 NC_DrawMovingFrame( hdc, &sizingRect, thickframe );
2267 NC_DrawMovingFrame( hdc, &newRect, thickframe );
2269 capturePoint = pt;
2270 sizingRect = newRect;
2275 ReleaseCapture();
2276 if( iconic )
2278 if( moved ) /* restore cursors, show icon title later on */
2280 ShowCursor( FALSE );
2281 SetCursor( hOldCursor );
2283 DestroyCursor( hDragCursor );
2285 else
2286 NC_DrawMovingFrame( hdc, &sizingRect, thickframe );
2288 if (wndPtr->dwStyle & WS_CHILD)
2289 ReleaseDC( wndPtr->parent->hwndSelf, hdc );
2290 else
2292 ReleaseDC( 0, hdc );
2295 wndPtr->pDriver->pPostSizeMove(wndPtr);
2297 if (HOOK_IsHooked( WH_CBT ))
2299 RECT16* pr = SEGPTR_NEW(RECT16);
2300 if( pr )
2302 CONV_RECT32TO16( &sizingRect, pr );
2303 if( HOOK_CallHooks16( WH_CBT, HCBT_MOVESIZE, hwnd,
2304 (LPARAM)SEGPTR_GET(pr)) )
2305 sizingRect = wndPtr->rectWindow;
2306 else
2307 CONV_RECT16TO32( pr, &sizingRect );
2308 SEGPTR_FREE(pr);
2311 SendMessage16( hwnd, WM_EXITSIZEMOVE, 0, 0 );
2312 SendMessage16( hwnd, WM_SETVISIBLE, !IsIconic16(hwnd), 0L);
2314 /* window moved or resized */
2315 if (moved)
2317 /* if the moving/resizing isn't canceled call SetWindowPos
2318 * with the new position or the new size of the window
2320 if (!((msg.message == WM_KEYDOWN) && (msg.wParam == VK_ESCAPE)) )
2322 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
2323 SetWindowPos( hwnd, 0, sizingRect.left, sizingRect.top,
2324 sizingRect.right - sizingRect.left,
2325 sizingRect.bottom - sizingRect.top,
2326 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
2330 if( IsWindow(hwnd) )
2331 if( wndPtr->dwStyle & WS_MINIMIZE )
2333 /* Single click brings up the system menu when iconized */
2335 if( !moved )
2337 if( wndPtr->dwStyle & WS_SYSMENU )
2338 SendMessage16( hwnd, WM_SYSCOMMAND,
2339 SC_MOUSEMENU + HTSYSMENU, *((LPARAM*)&pt));
2341 else WINPOS_ShowIconTitle( wndPtr, TRUE );
2344 END:
2345 WIN_ReleaseWndPtr(wndPtr);
2349 /***********************************************************************
2350 * NC_TrackMinMaxBox95
2352 * Track a mouse button press on the minimize or maximize box.
2354 * The big difference between 3.1 and 95 is the disabled button state.
2355 * In win95 the system button can be disabled, so it can ignore the mouse
2356 * event.
2359 static void NC_TrackMinMaxBox95( HWND hwnd, WORD wParam )
2361 MSG msg;
2362 POINT16 pt16;
2363 HDC hdc = GetWindowDC( hwnd );
2364 BOOL pressed = TRUE;
2365 UINT state;
2366 DWORD wndStyle = GetWindowLongA( hwnd, GWL_STYLE);
2367 HMENU hSysMenu = GetSystemMenu(hwnd, FALSE);
2369 void (*paintButton)(HWND, HDC16, BOOL, BOOL);
2371 if (wParam == HTMINBUTTON)
2373 /* If the style is not present, do nothing */
2374 if (!(wndStyle & WS_MINIMIZEBOX))
2375 return;
2377 /* Check if the sysmenu item for minimize is there */
2378 state = GetMenuState(hSysMenu, SC_MINIMIZE, MF_BYCOMMAND);
2380 paintButton = &NC_DrawMinButton95;
2382 else
2384 /* If the style is not present, do nothing */
2385 if (!(wndStyle & WS_MAXIMIZEBOX))
2386 return;
2388 /* Check if the sysmenu item for maximize is there */
2389 state = GetMenuState(hSysMenu, SC_MAXIMIZE, MF_BYCOMMAND);
2391 paintButton = &NC_DrawMaxButton95;
2394 SetCapture( hwnd );
2396 (*paintButton)( hwnd, hdc, TRUE, FALSE);
2400 BOOL oldstate = pressed;
2401 MSG_InternalGetMessage( &msg, 0, 0, 0, PM_REMOVE, FALSE, NULL );
2402 CONV_POINT32TO16( &msg.pt, &pt16 );
2404 pressed = (NC_HandleNCHitTest( hwnd, pt16 ) == wParam);
2405 if (pressed != oldstate)
2406 (*paintButton)( hwnd, hdc, pressed, FALSE);
2407 } while (msg.message != WM_LBUTTONUP);
2409 (*paintButton)( hwnd, hdc, FALSE, FALSE);
2411 ReleaseCapture();
2412 ReleaseDC( hwnd, hdc );
2414 /* If the item minimize or maximize of the sysmenu are not there */
2415 /* or if the style is not present, do nothing */
2416 if ((!pressed) || (state == 0xFFFFFFFF))
2417 return;
2419 if (wParam == HTMINBUTTON)
2420 SendMessage16( hwnd, WM_SYSCOMMAND, SC_MINIMIZE, *(LONG*)&pt16 );
2421 else
2422 SendMessage16( hwnd, WM_SYSCOMMAND,
2423 IsZoomed(hwnd) ? SC_RESTORE:SC_MAXIMIZE, *(LONG*)&pt16 );
2426 /***********************************************************************
2427 * NC_TrackMinMaxBox
2429 * Track a mouse button press on the minimize or maximize box.
2431 static void NC_TrackMinMaxBox( HWND hwnd, WORD wParam )
2433 MSG msg;
2434 POINT16 pt16;
2435 HDC hdc = GetWindowDC( hwnd );
2436 BOOL pressed = TRUE;
2437 void (*paintButton)(HWND, HDC16, BOOL);
2439 SetCapture( hwnd );
2441 if (wParam == HTMINBUTTON)
2442 paintButton = &NC_DrawMinButton;
2443 else
2444 paintButton = &NC_DrawMaxButton;
2446 (*paintButton)( hwnd, hdc, TRUE);
2450 BOOL oldstate = pressed;
2451 MSG_InternalGetMessage( &msg, 0, 0, 0, PM_REMOVE, FALSE, NULL );
2452 CONV_POINT32TO16( &msg.pt, &pt16 );
2454 pressed = (NC_HandleNCHitTest( hwnd, pt16 ) == wParam);
2455 if (pressed != oldstate)
2456 (*paintButton)( hwnd, hdc, pressed);
2457 } while (msg.message != WM_LBUTTONUP);
2459 (*paintButton)( hwnd, hdc, FALSE);
2461 ReleaseCapture();
2462 ReleaseDC( hwnd, hdc );
2464 if (!pressed) return;
2466 if (wParam == HTMINBUTTON)
2467 SendMessage16( hwnd, WM_SYSCOMMAND, SC_MINIMIZE, *(LONG*)&pt16 );
2468 else
2469 SendMessage16( hwnd, WM_SYSCOMMAND,
2470 IsZoomed(hwnd) ? SC_RESTORE:SC_MAXIMIZE, *(LONG*)&pt16 );
2474 /***********************************************************************
2475 * NC_TrackCloseButton95
2477 * Track a mouse button press on the Win95 close button.
2479 static void
2480 NC_TrackCloseButton95 (HWND hwnd, WORD wParam)
2482 MSG msg;
2483 POINT16 pt16;
2484 HDC hdc;
2485 BOOL pressed = TRUE;
2486 HMENU hSysMenu = GetSystemMenu(hwnd, FALSE);
2487 UINT state;
2489 if(hSysMenu == 0)
2490 return;
2492 state = GetMenuState(hSysMenu, SC_CLOSE, MF_BYCOMMAND);
2494 /* If the item close of the sysmenu is disabled or not there do nothing */
2495 if((state & MF_DISABLED) || (state & MF_GRAYED) || (state == 0xFFFFFFFF))
2496 return;
2498 hdc = GetWindowDC( hwnd );
2500 SetCapture( hwnd );
2502 NC_DrawCloseButton95 (hwnd, hdc, TRUE, FALSE);
2506 BOOL oldstate = pressed;
2507 MSG_InternalGetMessage( &msg, 0, 0, 0, PM_REMOVE, FALSE, NULL );
2508 CONV_POINT32TO16( &msg.pt, &pt16 );
2510 pressed = (NC_HandleNCHitTest( hwnd, pt16 ) == wParam);
2511 if (pressed != oldstate)
2512 NC_DrawCloseButton95 (hwnd, hdc, pressed, FALSE);
2513 } while (msg.message != WM_LBUTTONUP);
2515 NC_DrawCloseButton95 (hwnd, hdc, FALSE, FALSE);
2517 ReleaseCapture();
2518 ReleaseDC( hwnd, hdc );
2519 if (!pressed) return;
2521 SendMessage16( hwnd, WM_SYSCOMMAND, SC_CLOSE, *(LONG*)&pt16 );
2525 /***********************************************************************
2526 * NC_TrackScrollBar
2528 * Track a mouse button press on the horizontal or vertical scroll-bar.
2530 static void NC_TrackScrollBar( HWND hwnd, WPARAM wParam, POINT pt )
2532 MSG16 *msg;
2533 INT scrollbar;
2534 WND *wndPtr = WIN_FindWndPtr( hwnd );
2536 if ((wParam & 0xfff0) == SC_HSCROLL)
2538 if ((wParam & 0x0f) != HTHSCROLL) goto END;
2539 scrollbar = SB_HORZ;
2541 else /* SC_VSCROLL */
2543 if ((wParam & 0x0f) != HTVSCROLL) goto END;
2544 scrollbar = SB_VERT;
2547 if (!(msg = SEGPTR_NEW(MSG16))) goto END;
2548 pt.x -= wndPtr->rectWindow.left;
2549 pt.y -= wndPtr->rectWindow.top;
2550 SetCapture( hwnd );
2551 SCROLL_HandleScrollEvent( hwnd, scrollbar, WM_LBUTTONDOWN, pt );
2555 GetMessage16( SEGPTR_GET(msg), 0, 0, 0 );
2556 switch(msg->message)
2558 case WM_LBUTTONUP:
2559 case WM_MOUSEMOVE:
2560 case WM_SYSTIMER:
2561 pt.x = LOWORD(msg->lParam) + wndPtr->rectClient.left -
2562 wndPtr->rectWindow.left;
2563 pt.y = HIWORD(msg->lParam) + wndPtr->rectClient.top -
2564 wndPtr->rectWindow.top;
2565 SCROLL_HandleScrollEvent( hwnd, scrollbar, msg->message, pt );
2566 break;
2567 default:
2568 TranslateMessage16( msg );
2569 DispatchMessage16( msg );
2570 break;
2572 if (!IsWindow( hwnd ))
2574 ReleaseCapture();
2575 break;
2577 } while (msg->message != WM_LBUTTONUP);
2578 SEGPTR_FREE(msg);
2579 END:
2580 WIN_ReleaseWndPtr(wndPtr);
2583 /***********************************************************************
2584 * NC_HandleNCLButtonDown
2586 * Handle a WM_NCLBUTTONDOWN message. Called from DefWindowProc().
2588 LONG NC_HandleNCLButtonDown( WND* pWnd, WPARAM16 wParam, LPARAM lParam )
2590 HWND hwnd = pWnd->hwndSelf;
2592 switch(wParam) /* Hit test */
2594 case HTCAPTION:
2595 hwnd = WIN_GetTopParent(hwnd);
2597 if( WINPOS_SetActiveWindow(hwnd, TRUE, TRUE) || (GetActiveWindow() == hwnd) )
2598 SendMessage16( pWnd->hwndSelf, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, lParam );
2599 break;
2601 case HTSYSMENU:
2602 if( pWnd->dwStyle & WS_SYSMENU )
2604 if( !(pWnd->dwStyle & WS_MINIMIZE) )
2606 HDC hDC = GetWindowDC(hwnd);
2607 if (TWEAK_WineLook == WIN31_LOOK)
2608 NC_DrawSysButton( hwnd, hDC, TRUE );
2609 else
2610 NC_DrawSysButton95( hwnd, hDC, TRUE );
2611 ReleaseDC( hwnd, hDC );
2613 SendMessage16( hwnd, WM_SYSCOMMAND, SC_MOUSEMENU + HTSYSMENU, lParam );
2615 break;
2617 case HTMENU:
2618 SendMessage16( hwnd, WM_SYSCOMMAND, SC_MOUSEMENU, lParam );
2619 break;
2621 case HTHSCROLL:
2622 SendMessage16( hwnd, WM_SYSCOMMAND, SC_HSCROLL + HTHSCROLL, lParam );
2623 break;
2625 case HTVSCROLL:
2626 SendMessage16( hwnd, WM_SYSCOMMAND, SC_VSCROLL + HTVSCROLL, lParam );
2627 break;
2629 case HTMINBUTTON:
2630 case HTMAXBUTTON:
2631 if (TWEAK_WineLook == WIN31_LOOK)
2632 NC_TrackMinMaxBox( hwnd, wParam );
2633 else
2634 NC_TrackMinMaxBox95( hwnd, wParam );
2635 break;
2637 case HTCLOSE:
2638 if (TWEAK_WineLook >= WIN95_LOOK)
2639 NC_TrackCloseButton95 (hwnd, wParam);
2640 break;
2642 case HTLEFT:
2643 case HTRIGHT:
2644 case HTTOP:
2645 case HTTOPLEFT:
2646 case HTTOPRIGHT:
2647 case HTBOTTOM:
2648 case HTBOTTOMLEFT:
2649 case HTBOTTOMRIGHT:
2650 /* make sure hittest fits into 0xf and doesn't overlap with HTSYSMENU */
2651 SendMessage16( hwnd, WM_SYSCOMMAND, SC_SIZE + wParam - 2, lParam);
2652 break;
2654 case HTBORDER:
2655 break;
2657 return 0;
2661 /***********************************************************************
2662 * NC_HandleNCLButtonDblClk
2664 * Handle a WM_NCLBUTTONDBLCLK message. Called from DefWindowProc().
2666 LONG NC_HandleNCLButtonDblClk( WND *pWnd, WPARAM16 wParam, LPARAM lParam )
2669 * if this is an icon, send a restore since we are handling
2670 * a double click
2672 if (pWnd->dwStyle & WS_MINIMIZE)
2674 SendMessage16( pWnd->hwndSelf, WM_SYSCOMMAND, SC_RESTORE, lParam );
2675 return 0;
2678 switch(wParam) /* Hit test */
2680 case HTCAPTION:
2681 /* stop processing if WS_MAXIMIZEBOX is missing */
2682 if (pWnd->dwStyle & WS_MAXIMIZEBOX)
2683 SendMessage16( pWnd->hwndSelf, WM_SYSCOMMAND,
2684 (pWnd->dwStyle & WS_MAXIMIZE) ? SC_RESTORE : SC_MAXIMIZE,
2685 lParam );
2686 break;
2688 case HTSYSMENU:
2689 if (!(GetClassWord(pWnd->hwndSelf, GCW_STYLE) & CS_NOCLOSE))
2690 SendMessage16( pWnd->hwndSelf, WM_SYSCOMMAND, SC_CLOSE, lParam );
2691 break;
2693 case HTHSCROLL:
2694 SendMessage16( pWnd->hwndSelf, WM_SYSCOMMAND, SC_HSCROLL + HTHSCROLL,
2695 lParam );
2696 break;
2698 case HTVSCROLL:
2699 SendMessage16( pWnd->hwndSelf, WM_SYSCOMMAND, SC_VSCROLL + HTVSCROLL,
2700 lParam );
2701 break;
2703 return 0;
2707 /***********************************************************************
2708 * NC_HandleSysCommand
2710 * Handle a WM_SYSCOMMAND message. Called from DefWindowProc().
2712 LONG NC_HandleSysCommand( HWND hwnd, WPARAM16 wParam, POINT16 pt )
2714 WND *wndPtr = WIN_FindWndPtr( hwnd );
2715 POINT pt32;
2716 UINT16 uCommand = wParam & 0xFFF0;
2718 TRACE_(nonclient)("Handling WM_SYSCOMMAND %x %d,%d\n",
2719 wParam, pt.x, pt.y );
2721 if (wndPtr->dwStyle & WS_CHILD && uCommand != SC_KEYMENU )
2722 ScreenToClient16( wndPtr->parent->hwndSelf, &pt );
2724 switch (uCommand)
2726 case SC_SIZE:
2727 case SC_MOVE:
2728 NC_DoSizeMove( hwnd, wParam );
2729 break;
2731 case SC_MINIMIZE:
2732 if (hwnd == GetForegroundWindow())
2733 ShowOwnedPopups(hwnd,FALSE);
2734 ShowWindow( hwnd, SW_MINIMIZE );
2735 break;
2737 case SC_MAXIMIZE:
2738 if (IsIconic(hwnd) && hwnd == GetForegroundWindow())
2739 ShowOwnedPopups(hwnd,TRUE);
2740 ShowWindow( hwnd, SW_MAXIMIZE );
2741 break;
2743 case SC_RESTORE:
2744 if (IsIconic(hwnd) && hwnd == GetForegroundWindow())
2745 ShowOwnedPopups(hwnd,TRUE);
2746 ShowWindow( hwnd, SW_RESTORE );
2747 break;
2749 case SC_CLOSE:
2750 WIN_ReleaseWndPtr(wndPtr);
2751 return SendMessage16( hwnd, WM_CLOSE, 0, 0 );
2753 case SC_VSCROLL:
2754 case SC_HSCROLL:
2755 CONV_POINT16TO32( &pt, &pt32 );
2756 NC_TrackScrollBar( hwnd, wParam, pt32 );
2757 break;
2759 case SC_MOUSEMENU:
2760 CONV_POINT16TO32( &pt, &pt32 );
2761 MENU_TrackMouseMenuBar( wndPtr, wParam & 0x000F, pt32 );
2762 break;
2764 case SC_KEYMENU:
2765 MENU_TrackKbdMenuBar( wndPtr , wParam , pt.x );
2766 break;
2768 case SC_TASKLIST:
2769 WinExec( "taskman.exe", SW_SHOWNORMAL );
2770 break;
2772 case SC_SCREENSAVE:
2773 if (wParam == SC_ABOUTWINE)
2774 ShellAboutA(hwnd,"Wine", WINE_RELEASE_INFO, 0);
2775 else
2776 if (wParam == SC_PUTMARK)
2777 TRACE_(shell)("Mark requested by user\n");
2778 break;
2780 case SC_HOTKEY:
2781 case SC_ARRANGE:
2782 case SC_NEXTWINDOW:
2783 case SC_PREVWINDOW:
2784 FIXME_(nonclient)("unimplemented!\n");
2785 break;
2787 WIN_ReleaseWndPtr(wndPtr);
2788 return 0;
2791 /*************************************************************
2792 * NC_DrawGrayButton
2794 * Stub for the grayed button of the caption
2796 *************************************************************/
2798 BOOL NC_DrawGrayButton(HDC hdc, int x, int y)
2800 HBITMAP hMaskBmp;
2801 HDC hdcMask = CreateCompatibleDC (0);
2802 HBRUSH hOldBrush;
2804 hMaskBmp = CreateBitmap (12, 10, 1, 1, lpGrayMask);
2806 if(hMaskBmp == 0)
2807 return FALSE;
2809 SelectObject (hdcMask, hMaskBmp);
2811 /* Draw the grayed bitmap using the mask */
2812 hOldBrush = SelectObject (hdc, RGB(128, 128, 128));
2813 BitBlt (hdc, x, y, 12, 10,
2814 hdcMask, 0, 0, 0xB8074A);
2816 /* Clean up */
2817 SelectObject (hdc, hOldBrush);
2818 DeleteObject(hMaskBmp);
2819 DeleteDC (hdcMask);
2821 return TRUE;