Release 950522
[wine.git] / windows / nonclient.c
blob8af8dd3b1800e4967b4b980a021eda58deac44ef
1 /*
2 * Non-client area window functions
4 * Copyright 1994 Alexandre Julliard
6 */
8 #include "win.h"
9 #include "class.h"
10 #include "message.h"
11 #include "sysmetrics.h"
12 #include "user.h"
13 #include "dialog.h"
14 #include "syscolor.h"
15 #include "menu.h"
16 #include "winpos.h"
17 #include "scroll.h"
18 #include "nonclient.h"
19 #include "graphics.h"
20 #include "selectors.h"
21 #include "stddebug.h"
22 /* #define DEBUG_NONCLIENT */
23 #include "debug.h"
26 static HBITMAP hbitmapClose = 0;
27 static HBITMAP hbitmapMinimize = 0;
28 static HBITMAP hbitmapMinimizeD = 0;
29 static HBITMAP hbitmapMaximize = 0;
30 static HBITMAP hbitmapMaximizeD = 0;
31 static HBITMAP hbitmapRestore = 0;
32 static HBITMAP hbitmapRestoreD = 0;
34 #define SC_ABOUTWINE (SC_SCREENSAVE+1)
36 /* Some useful macros */
37 #define HAS_DLGFRAME(style,exStyle) \
38 (((exStyle) & WS_EX_DLGMODALFRAME) || \
39 (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
41 #define HAS_THICKFRAME(style) \
42 (((style) & WS_THICKFRAME) && \
43 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
45 #define HAS_MENU(w) (!((w)->dwStyle & WS_CHILD) && ((w)->wIDmenu != 0))
47 #define ON_LEFT_BORDER(hit) \
48 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
49 #define ON_RIGHT_BORDER(hit) \
50 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
51 #define ON_TOP_BORDER(hit) \
52 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
53 #define ON_BOTTOM_BORDER(hit) \
54 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
56 /***********************************************************************
57 * NC_AdjustRect
59 * Compute the size of the window rectangle from the size of the
60 * client rectangle.
62 static void NC_AdjustRect( LPRECT rect, DWORD style, BOOL menu, DWORD exStyle )
64 if (style & WS_ICONIC) return; /* Nothing to change for an icon */
65 if (HAS_DLGFRAME( style, exStyle ))
66 InflateRect( rect, SYSMETRICS_CXDLGFRAME, SYSMETRICS_CYDLGFRAME );
67 else
69 if (HAS_THICKFRAME(style))
70 InflateRect( rect, SYSMETRICS_CXFRAME, SYSMETRICS_CYFRAME );
71 if (style & WS_BORDER)
72 InflateRect( rect, SYSMETRICS_CXBORDER, SYSMETRICS_CYBORDER );
75 if ((style & WS_CAPTION) == WS_CAPTION)
76 rect->top -= SYSMETRICS_CYCAPTION - SYSMETRICS_CYBORDER;
77 if (menu) rect->top -= SYSMETRICS_CYMENU + SYSMETRICS_CYBORDER;
79 if (style & WS_VSCROLL) rect->right += SYSMETRICS_CXVSCROLL;
80 if (style & WS_HSCROLL) rect->bottom += SYSMETRICS_CYHSCROLL;
84 /***********************************************************************
85 * AdjustWindowRect (USER.102)
87 void AdjustWindowRect( LPRECT rect, DWORD style, BOOL menu )
89 AdjustWindowRectEx( rect, style, menu, 0 );
93 /***********************************************************************
94 * AdjustWindowRectEx (USER.454)
96 void AdjustWindowRectEx( LPRECT rect, DWORD style, BOOL menu, DWORD exStyle )
98 /* Correct the window style */
100 if (!(style & (WS_POPUP | WS_CHILD))) /* Overlapped window */
101 style |= WS_CAPTION;
102 if (exStyle & WS_EX_DLGMODALFRAME) style &= ~WS_THICKFRAME;
104 dprintf_nonclient(stddeb, "AdjustWindowRectEx: (%d,%d)-(%d,%d) %08lx %d %08lx\n",
105 rect->left, rect->top, rect->right, rect->bottom, style, menu, exStyle );
107 NC_AdjustRect( rect, style, menu, exStyle );
111 /*******************************************************************
112 * NC_GetMinMaxInfo
114 * Get the minimized and maximized information for a window.
116 void NC_GetMinMaxInfo( HWND hwnd, POINT *maxSize, POINT *maxPos,
117 POINT *minTrack, POINT *maxTrack )
119 HANDLE minmaxHandle;
120 MINMAXINFO MinMax, *pMinMax;
121 short xinc, yinc;
122 WND *wndPtr = WIN_FindWndPtr( hwnd );
124 /* Compute default values */
126 MinMax.ptMaxSize.x = SYSMETRICS_CXSCREEN;
127 MinMax.ptMaxSize.y = SYSMETRICS_CYSCREEN;
128 MinMax.ptMinTrackSize.x = SYSMETRICS_CXMINTRACK;
129 MinMax.ptMinTrackSize.y = SYSMETRICS_CYMINTRACK;
130 MinMax.ptMaxTrackSize.x = SYSMETRICS_CXSCREEN;
131 MinMax.ptMaxTrackSize.y = SYSMETRICS_CYSCREEN;
133 if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
135 xinc = SYSMETRICS_CXDLGFRAME;
136 yinc = SYSMETRICS_CYDLGFRAME;
138 else
140 xinc = yinc = 0;
141 if (HAS_THICKFRAME(wndPtr->dwStyle))
143 xinc += SYSMETRICS_CXFRAME;
144 yinc += SYSMETRICS_CYFRAME;
146 if (wndPtr->dwStyle & WS_BORDER)
148 xinc += SYSMETRICS_CXBORDER;
149 yinc += SYSMETRICS_CYBORDER;
152 MinMax.ptMaxSize.x += 2 * xinc;
153 MinMax.ptMaxSize.y += 2 * yinc;
155 if ((wndPtr->ptMaxPos.x != -1) || (wndPtr->ptMaxPos.y != -1))
156 MinMax.ptMaxPosition = wndPtr->ptMaxPos;
157 else
159 MinMax.ptMaxPosition.x = -xinc;
160 MinMax.ptMaxPosition.y = -yinc;
163 minmaxHandle = USER_HEAP_ALLOC( sizeof(MINMAXINFO) );
164 if (minmaxHandle)
166 pMinMax = (MINMAXINFO *) USER_HEAP_LIN_ADDR( minmaxHandle );
167 memcpy( pMinMax, &MinMax, sizeof(MinMax) );
168 SendMessage( hwnd, WM_GETMINMAXINFO, 0,
169 USER_HEAP_SEG_ADDR(minmaxHandle) );
171 else pMinMax = &MinMax;
173 /* Some sanity checks */
175 pMinMax->ptMaxTrackSize.x = max( pMinMax->ptMaxTrackSize.x,
176 pMinMax->ptMinTrackSize.x );
177 pMinMax->ptMaxTrackSize.y = max( pMinMax->ptMaxTrackSize.y,
178 pMinMax->ptMinTrackSize.y );
180 if (maxSize) *maxSize = pMinMax->ptMaxSize;
181 if (maxPos) *maxPos = pMinMax->ptMaxPosition;
182 if (minTrack) *minTrack = pMinMax->ptMinTrackSize;
183 if (maxTrack) *maxTrack = pMinMax->ptMaxTrackSize;
184 if (minmaxHandle) USER_HEAP_FREE( minmaxHandle );
188 /***********************************************************************
189 * NC_HandleNCCalcSize
191 * Handle a WM_NCCALCSIZE message. Called from DefWindowProc().
193 LONG NC_HandleNCCalcSize( HWND hwnd, NCCALCSIZE_PARAMS *params )
195 RECT tmpRect = { 0, 0, 0, 0 };
196 WND *wndPtr = WIN_FindWndPtr( hwnd );
198 if (!wndPtr) return 0;
199 NC_AdjustRect( &tmpRect, wndPtr->dwStyle, FALSE, wndPtr->dwExStyle );
200 params->rgrc[0].left -= tmpRect.left;
201 params->rgrc[0].top -= tmpRect.top;
202 params->rgrc[0].right -= tmpRect.right;
203 params->rgrc[0].bottom -= tmpRect.bottom;
205 if (HAS_MENU(wndPtr))
207 params->rgrc[0].top += MENU_GetMenuBarHeight( hwnd,
208 params->rgrc[0].right - params->rgrc[0].left,
209 -tmpRect.left, -tmpRect.top ) + 1;
211 return 0;
215 /***********************************************************************
216 * NC_GetInsideRect
218 * Get the 'inside' rectangle of a window, i.e. the whole window rectangle
219 * but without the borders (if any).
220 * The rectangle is in window coordinates (for drawing with GetWindowDC()).
222 void NC_GetInsideRect( HWND hwnd, RECT *rect )
224 WND * wndPtr = WIN_FindWndPtr( hwnd );
226 rect->top = rect->left = 0;
227 rect->right = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
228 rect->bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
230 if (wndPtr->dwStyle & WS_ICONIC) return; /* No border to remove */
232 /* Remove frame from rectangle */
233 if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
235 InflateRect( rect, -SYSMETRICS_CXDLGFRAME, -SYSMETRICS_CYDLGFRAME);
236 if (wndPtr->dwExStyle & WS_EX_DLGMODALFRAME) InflateRect( rect, -1, 0);
238 else
240 if (HAS_THICKFRAME( wndPtr->dwStyle ))
241 InflateRect( rect, -SYSMETRICS_CXFRAME, -SYSMETRICS_CYFRAME );
242 if (wndPtr->dwStyle & WS_BORDER)
243 InflateRect( rect, -SYSMETRICS_CXBORDER, -SYSMETRICS_CYBORDER );
248 /***********************************************************************
249 * NC_HandleNCHitTest
251 * Handle a WM_NCHITTEST message. Called from DefWindowProc().
253 LONG NC_HandleNCHitTest( HWND hwnd, POINT pt )
255 RECT rect;
256 WND *wndPtr = WIN_FindWndPtr( hwnd );
257 if (!wndPtr) return HTERROR;
259 dprintf_nonclient(stddeb, "NC_HandleNCHitTest: hwnd=%x pt=%d,%d\n",
260 hwnd, pt.x, pt.y );
262 GetWindowRect( hwnd, &rect );
263 if (!PtInRect( &rect, pt )) return HTNOWHERE;
266 * if this is a iconic window, we don't care were the hit
267 * occured, only that it did occur, just return HTCAPTION
268 * so the caller knows the icon did get hit
270 if (IsIconic(hwnd))
272 return HTCAPTION; /* change this to something meaningful? */
275 /* Check borders */
276 if (HAS_THICKFRAME( wndPtr->dwStyle ))
278 InflateRect( &rect, -SYSMETRICS_CXFRAME, -SYSMETRICS_CYFRAME );
279 if (wndPtr->dwStyle & WS_BORDER)
280 InflateRect( &rect, -SYSMETRICS_CXBORDER, -SYSMETRICS_CYBORDER );
281 if (!PtInRect( &rect, pt ))
283 /* Check top sizing border */
284 if (pt.y < rect.top)
286 if (pt.x < rect.left+SYSMETRICS_CXSIZE) return HTTOPLEFT;
287 if (pt.x >= rect.right-SYSMETRICS_CXSIZE) return HTTOPRIGHT;
288 return HTTOP;
290 /* Check bottom sizing border */
291 if (pt.y >= rect.bottom)
293 if (pt.x < rect.left+SYSMETRICS_CXSIZE) return HTBOTTOMLEFT;
294 if (pt.x >= rect.right-SYSMETRICS_CXSIZE) return HTBOTTOMRIGHT;
295 return HTBOTTOM;
297 /* Check left sizing border */
298 if (pt.x < rect.left)
300 if (pt.y < rect.top+SYSMETRICS_CYSIZE) return HTTOPLEFT;
301 if (pt.y >= rect.bottom-SYSMETRICS_CYSIZE) return HTBOTTOMLEFT;
302 return HTLEFT;
304 /* Check right sizing border */
305 if (pt.x >= rect.right)
307 if (pt.y < rect.top+SYSMETRICS_CYSIZE) return HTTOPRIGHT;
308 if (pt.y >= rect.bottom-SYSMETRICS_CYSIZE) return HTBOTTOMRIGHT;
309 return HTRIGHT;
313 else /* No thick frame */
315 if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
316 InflateRect(&rect, -SYSMETRICS_CXDLGFRAME, -SYSMETRICS_CYDLGFRAME);
317 else if (wndPtr->dwStyle & WS_BORDER)
318 InflateRect(&rect, -SYSMETRICS_CXBORDER, -SYSMETRICS_CYBORDER);
319 if (!PtInRect( &rect, pt )) return HTBORDER;
322 /* Check caption */
324 if ((wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION)
326 rect.top += SYSMETRICS_CYCAPTION - 1;
327 if (!PtInRect( &rect, pt ))
329 /* Check system menu */
330 if (wndPtr->dwStyle & WS_SYSMENU)
331 rect.left += SYSMETRICS_CXSIZE;
332 if (pt.x <= rect.left) return HTSYSMENU;
333 /* Check maximize box */
334 if (wndPtr->dwStyle & WS_MAXIMIZEBOX)
335 rect.right -= SYSMETRICS_CXSIZE + 1;
336 if (pt.x >= rect.right) return HTMAXBUTTON;
337 /* Check minimize box */
338 if (wndPtr->dwStyle & WS_MINIMIZEBOX)
339 rect.right -= SYSMETRICS_CXSIZE + 1;
340 if (pt.x >= rect.right) return HTMINBUTTON;
341 return HTCAPTION;
345 /* Check client area */
347 ScreenToClient( hwnd, &pt );
348 GetClientRect( hwnd, &rect );
349 if (PtInRect( &rect, pt )) return HTCLIENT;
351 /* Check vertical scroll bar */
353 if (wndPtr->dwStyle & WS_VSCROLL)
355 rect.right += SYSMETRICS_CXVSCROLL;
356 if (PtInRect( &rect, pt )) return HTVSCROLL;
359 /* Check horizontal scroll bar */
361 if (wndPtr->dwStyle & WS_HSCROLL)
363 rect.bottom += SYSMETRICS_CYHSCROLL;
364 if (PtInRect( &rect, pt ))
366 /* Check size box */
367 if ((wndPtr->dwStyle & WS_VSCROLL) &&
368 (pt.x >= rect.right - SYSMETRICS_CXVSCROLL))
369 return HTSIZE;
370 return HTHSCROLL;
374 /* Check menu bar */
376 if (HAS_MENU(wndPtr))
378 if ((pt.y < 0) && (pt.x >= 0) && (pt.x < rect.right))
379 return HTMENU;
382 /* Should never get here */
383 return HTERROR;
387 /***********************************************************************
388 * NC_DrawSysButton
390 void NC_DrawSysButton( HWND hwnd, HDC hdc, BOOL down )
392 RECT rect;
393 HDC hdcMem;
394 HBITMAP hbitmap;
395 WND *wndPtr = WIN_FindWndPtr( hwnd );
397 NC_GetInsideRect( hwnd, &rect );
398 hdcMem = CreateCompatibleDC( hdc );
399 hbitmap = SelectObject( hdcMem, hbitmapClose );
400 BitBlt( hdc, rect.left, rect.top, SYSMETRICS_CXSIZE, SYSMETRICS_CYSIZE,
401 hdcMem, (wndPtr->dwStyle & WS_CHILD) ? SYSMETRICS_CXSIZE : 0, 0,
402 down ? NOTSRCCOPY : SRCCOPY );
403 SelectObject( hdcMem, hbitmap );
404 DeleteDC( hdcMem );
408 /***********************************************************************
409 * NC_DrawMaxButton
411 static void NC_DrawMaxButton( HWND hwnd, HDC hdc, BOOL down )
413 RECT rect;
414 NC_GetInsideRect( hwnd, &rect );
415 GRAPH_DrawBitmap( hdc, (IsZoomed(hwnd) ?
416 (down ? hbitmapRestoreD : hbitmapRestore) :
417 (down ? hbitmapMaximizeD : hbitmapMaximize)),
418 rect.right - SYSMETRICS_CXSIZE - 1, rect.top,
419 0, 0, SYSMETRICS_CXSIZE+1, SYSMETRICS_CYSIZE );
423 /***********************************************************************
424 * NC_DrawMinButton
426 static void NC_DrawMinButton( HWND hwnd, HDC hdc, BOOL down )
428 RECT rect;
429 WND *wndPtr = WIN_FindWndPtr( hwnd );
430 NC_GetInsideRect( hwnd, &rect );
431 if (wndPtr->dwStyle & WS_MAXIMIZEBOX) rect.right -= SYSMETRICS_CXSIZE + 1;
432 GRAPH_DrawBitmap( hdc, (down ? hbitmapMinimizeD : hbitmapMinimize),
433 rect.right - SYSMETRICS_CXSIZE - 1, rect.top,
434 0, 0, SYSMETRICS_CXSIZE+1, SYSMETRICS_CYSIZE );
438 /***********************************************************************
439 * NC_DrawFrame
441 * Draw a window frame inside the given rectangle, and update the rectangle.
442 * The correct pen for the frame must be selected in the DC.
444 static void NC_DrawFrame( HDC hdc, RECT *rect, BOOL dlgFrame, BOOL active )
446 short width, height, tmp;
448 if (dlgFrame)
450 width = SYSMETRICS_CXDLGFRAME - 1;
451 height = SYSMETRICS_CYDLGFRAME - 1;
452 SelectObject( hdc, active ? sysColorObjects.hbrushActiveCaption :
453 sysColorObjects.hbrushInactiveCaption );
455 else
457 width = SYSMETRICS_CXFRAME - 1;
458 height = SYSMETRICS_CYFRAME - 1;
459 SelectObject( hdc, active ? sysColorObjects.hbrushActiveBorder :
460 sysColorObjects.hbrushInactiveBorder );
463 /* Draw frame */
464 PatBlt( hdc, rect->left, rect->top,
465 rect->right - rect->left, height, PATCOPY );
466 PatBlt( hdc, rect->left, rect->top,
467 width, rect->bottom - rect->top, PATCOPY );
468 PatBlt( hdc, rect->left, rect->bottom,
469 rect->right - rect->left, -height, PATCOPY );
470 PatBlt( hdc, rect->right, rect->top,
471 -width, rect->bottom - rect->top, PATCOPY );
473 if (dlgFrame)
475 InflateRect( rect, -width, -height );
476 return;
479 /* Draw inner rectangle */
480 MoveTo( hdc, rect->left+width, rect->top+height );
481 LineTo( hdc, rect->right-width-1, rect->top+height );
482 LineTo( hdc, rect->right-width-1, rect->bottom-height-1 );
483 LineTo( hdc, rect->left+width, rect->bottom-height-1 );
484 LineTo( hdc, rect->left+width, rect->top+height );
486 /* Draw the decorations */
487 tmp = rect->top + SYSMETRICS_CYFRAME + SYSMETRICS_CYSIZE;
488 MoveTo( hdc, rect->left, tmp);
489 LineTo( hdc, rect->left+width, tmp );
490 MoveTo( hdc, rect->right-width-1, tmp );
491 LineTo( hdc, rect->right-1, tmp );
493 tmp = rect->bottom - 1 - SYSMETRICS_CYFRAME - SYSMETRICS_CYSIZE;
494 MoveTo( hdc, rect->left, tmp );
495 LineTo( hdc, rect->left+width, tmp );
496 MoveTo( hdc, rect->right-width-1, tmp );
497 LineTo( hdc, rect->right-1, tmp );
499 tmp = rect->left + SYSMETRICS_CXFRAME + SYSMETRICS_CXSIZE;
500 MoveTo( hdc, tmp, rect->top );
501 LineTo( hdc, tmp, rect->top+height );
502 MoveTo( hdc, tmp, rect->bottom-height-1 );
503 LineTo( hdc, tmp, rect->bottom-1 );
505 tmp = rect->right - 1 - SYSMETRICS_CXFRAME - SYSMETRICS_CYSIZE;
506 MoveTo( hdc, tmp, rect->top );
507 LineTo( hdc, tmp, rect->top+height );
508 MoveTo( hdc, tmp, rect->bottom-height-1 );
509 LineTo( hdc, tmp, rect->bottom-1 );
511 InflateRect( rect, -width-1, -height-1 );
515 /***********************************************************************
516 * NC_DrawMovingFrame
518 * Draw the frame used when moving or resizing window.
520 static void NC_DrawMovingFrame( HDC hdc, RECT *rect, BOOL thickframe )
522 if (thickframe)
524 SelectObject( hdc, GetStockObject( GRAY_BRUSH ) );
525 PatBlt( hdc, rect->left, rect->top,
526 rect->right - rect->left - SYSMETRICS_CXFRAME,
527 SYSMETRICS_CYFRAME, PATINVERT );
528 PatBlt( hdc, rect->left, rect->top + SYSMETRICS_CYFRAME,
529 SYSMETRICS_CXFRAME,
530 rect->bottom - rect->top - SYSMETRICS_CYFRAME, PATINVERT );
531 PatBlt( hdc, rect->left + SYSMETRICS_CXFRAME, rect->bottom,
532 rect->right - rect->left - SYSMETRICS_CXFRAME,
533 -SYSMETRICS_CYFRAME, PATINVERT );
534 PatBlt( hdc, rect->right, rect->top, -SYSMETRICS_CXFRAME,
535 rect->bottom - rect->top - SYSMETRICS_CYFRAME, PATINVERT );
537 else DrawFocusRect( hdc, rect );
541 /***********************************************************************
542 * NC_DrawCaption
544 * Draw the window caption.
545 * The correct pen for the window frame must be selected in the DC.
547 static void NC_DrawCaption( HDC hdc, RECT *rect, HWND hwnd,
548 DWORD style, BOOL active )
550 RECT r = *rect;
551 WND * wndPtr = WIN_FindWndPtr( hwnd );
552 char buffer[256];
554 if (!hbitmapClose)
556 if (!(hbitmapClose = LoadBitmap( 0, MAKEINTRESOURCE(OBM_CLOSE) )))
557 return;
558 hbitmapMinimize = LoadBitmap( 0, MAKEINTRESOURCE(OBM_REDUCE) );
559 hbitmapMinimizeD = LoadBitmap( 0, MAKEINTRESOURCE(OBM_REDUCED) );
560 hbitmapMaximize = LoadBitmap( 0, MAKEINTRESOURCE(OBM_ZOOM) );
561 hbitmapMaximizeD = LoadBitmap( 0, MAKEINTRESOURCE(OBM_ZOOMD) );
562 hbitmapRestore = LoadBitmap( 0, MAKEINTRESOURCE(OBM_RESTORE) );
563 hbitmapRestoreD = LoadBitmap( 0, MAKEINTRESOURCE(OBM_RESTORED) );
566 if (wndPtr->dwExStyle & WS_EX_DLGMODALFRAME)
568 HBRUSH hbrushOld = SelectObject( hdc, sysColorObjects.hbrushWindow );
569 PatBlt( hdc, r.left, r.top, 1, r.bottom-r.top+1,PATCOPY );
570 PatBlt( hdc, r.right-1, r.top, 1, r.bottom-r.top+1, PATCOPY );
571 PatBlt( hdc, r.left, r.top-1, r.right-r.left, 1, PATCOPY );
572 r.left++;
573 r.right--;
574 SelectObject( hdc, hbrushOld );
577 MoveTo( hdc, r.left, r.bottom );
578 LineTo( hdc, r.right-1, r.bottom );
580 if (style & WS_SYSMENU)
582 NC_DrawSysButton( hwnd, hdc, FALSE );
583 r.left += SYSMETRICS_CXSIZE + 1;
584 MoveTo( hdc, r.left - 1, r.top );
585 LineTo( hdc, r.left - 1, r.bottom );
587 if (style & WS_MAXIMIZEBOX)
589 NC_DrawMaxButton( hwnd, hdc, FALSE );
590 r.right -= SYSMETRICS_CXSIZE + 1;
592 if (style & WS_MINIMIZEBOX)
594 NC_DrawMinButton( hwnd, hdc, FALSE );
595 r.right -= SYSMETRICS_CXSIZE + 1;
598 FillRect( hdc, &r, active ? sysColorObjects.hbrushActiveCaption :
599 sysColorObjects.hbrushInactiveCaption );
601 if (GetWindowText( hwnd, buffer, 256 ))
603 if (active) SetTextColor( hdc, GetSysColor( COLOR_CAPTIONTEXT ) );
604 else SetTextColor( hdc, GetSysColor( COLOR_INACTIVECAPTIONTEXT ) );
605 SetBkMode( hdc, TRANSPARENT );
606 DrawText( hdc, buffer, -1, &r, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
611 /***********************************************************************
612 * NC_DoNCPaint
614 * Paint the non-client area.
616 void NC_DoNCPaint( HWND hwnd, BOOL active, BOOL suppress_menupaint )
618 HDC hdc;
619 RECT rect;
621 WND *wndPtr = WIN_FindWndPtr( hwnd );
623 dprintf_nonclient(stddeb, "NC_DoNCPaint: %x %d\n", hwnd, active );
624 if (!wndPtr || !(wndPtr->dwStyle & WS_VISIBLE)) return; /* Nothing to do */
626 if (!(hdc = GetDCEx( hwnd, 0, DCX_USESTYLE | DCX_WINDOW ))) return;
629 * If this is an icon, we don't want to do any more nonclient painting
630 * of the window manager.
631 * If there is a class icon to draw, draw it
633 if (IsIconic(hwnd))
635 HICON hIcon = WIN_CLASS_INFO(wndPtr).hIcon;
636 if (hIcon)
638 SendMessage(hwnd, WM_ICONERASEBKGND, hdc, 0);
639 DrawIcon(hdc, 0, 0, hIcon);
641 ReleaseDC(hwnd, hdc);
642 return;
645 if (ExcludeVisRect( hdc, wndPtr->rectClient.left-wndPtr->rectWindow.left,
646 wndPtr->rectClient.top-wndPtr->rectWindow.top,
647 wndPtr->rectClient.right-wndPtr->rectWindow.left,
648 wndPtr->rectClient.bottom-wndPtr->rectWindow.top )
649 == NULLREGION)
651 ReleaseDC( hwnd, hdc );
652 return;
655 rect.top = rect.left = 0;
656 rect.right = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
657 rect.bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
659 SelectObject( hdc, sysColorObjects.hpenWindowFrame );
661 if ((wndPtr->dwStyle & WS_BORDER) || (wndPtr->dwStyle & WS_DLGFRAME) ||
662 (wndPtr->dwExStyle & WS_EX_DLGMODALFRAME))
664 MoveTo( hdc, 0, 0 );
665 LineTo( hdc, rect.right-1, 0 );
666 LineTo( hdc, rect.right-1, rect.bottom-1 );
667 LineTo( hdc, 0, rect.bottom-1 );
668 LineTo( hdc, 0, 0 );
669 InflateRect( &rect, -1, -1 );
672 if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
673 NC_DrawFrame( hdc, &rect, TRUE, active );
674 else if (wndPtr->dwStyle & WS_THICKFRAME)
675 NC_DrawFrame(hdc, &rect, FALSE, active );
677 if ((wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION)
679 RECT r = rect;
680 r.bottom = rect.top + SYSMETRICS_CYSIZE;
681 rect.top += SYSMETRICS_CYSIZE + SYSMETRICS_CYBORDER;
682 NC_DrawCaption( hdc, &r, hwnd, wndPtr->dwStyle, active );
685 if (HAS_MENU(wndPtr))
687 RECT r = rect;
688 r.bottom = rect.top + SYSMETRICS_CYMENU; /* default height */
689 rect.top += MENU_DrawMenuBar( hdc, &r, hwnd, suppress_menupaint );
692 /* Draw the scroll-bars */
694 if (wndPtr->dwStyle & WS_VSCROLL) SCROLL_DrawScrollBar(hwnd, hdc, SB_VERT);
695 if (wndPtr->dwStyle & WS_HSCROLL) SCROLL_DrawScrollBar(hwnd, hdc, SB_HORZ);
697 /* Draw the "size-box" */
699 if ((wndPtr->dwStyle & WS_VSCROLL) && (wndPtr->dwStyle & WS_HSCROLL))
701 RECT r = rect;
702 r.left = r.right - SYSMETRICS_CXVSCROLL + 1;
703 r.top = r.bottom - SYSMETRICS_CYHSCROLL + 1;
704 FillRect( hdc, &r, sysColorObjects.hbrushScrollbar );
707 ReleaseDC( hwnd, hdc );
712 /***********************************************************************
713 * NC_HandleNCPaint
715 * Handle a WM_NCPAINT message. Called from DefWindowProc().
717 LONG NC_HandleNCPaint( HWND hwnd )
719 NC_DoNCPaint( hwnd, hwnd == GetActiveWindow(), FALSE );
720 return 0;
724 /***********************************************************************
725 * NC_HandleNCActivate
727 * Handle a WM_NCACTIVATE message. Called from DefWindowProc().
729 LONG NC_HandleNCActivate( HWND hwnd, WORD wParam )
731 NC_DoNCPaint( hwnd, wParam, FALSE );
732 return TRUE;
736 /***********************************************************************
737 * NC_HandleSetCursor
739 * Handle a WM_SETCURSOR message. Called from DefWindowProc().
741 LONG NC_HandleSetCursor( HWND hwnd, WORD wParam, LONG lParam )
743 if (hwnd != wParam) return 0; /* Don't set the cursor for child windows */
745 switch(LOWORD(lParam))
747 case HTERROR:
749 WORD msg = HIWORD( lParam );
750 if ((msg == WM_LBUTTONDOWN) || (msg == WM_MBUTTONDOWN) ||
751 (msg == WM_RBUTTONDOWN))
752 MessageBeep(0);
754 break;
756 case HTCLIENT:
758 WND *wndPtr;
759 CLASS *classPtr;
760 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) break;
761 if (!(classPtr = CLASS_FindClassPtr( wndPtr->hClass ))) break;
762 if (classPtr->wc.hCursor)
764 SetCursor( classPtr->wc.hCursor );
765 return TRUE;
767 else return FALSE;
770 case HTLEFT:
771 case HTRIGHT:
772 return SetCursor( LoadCursor( 0, IDC_SIZEWE ) );
774 case HTTOP:
775 case HTBOTTOM:
776 return SetCursor( LoadCursor( 0, IDC_SIZENS ) );
778 case HTTOPLEFT:
779 case HTBOTTOMRIGHT:
780 return SetCursor( LoadCursor( 0, IDC_SIZENWSE ) );
782 case HTTOPRIGHT:
783 case HTBOTTOMLEFT:
784 return SetCursor( LoadCursor( 0, IDC_SIZENESW ) );
787 /* Default cursor: arrow */
788 return SetCursor( LoadCursor( 0, IDC_ARROW ) );
792 /***********************************************************************
793 * NC_StartSizeMove
795 * Initialisation of a move or resize, when initiatied from a menu choice.
796 * Return hit test code for caption or sizing border.
798 static LONG NC_StartSizeMove( HWND hwnd, WORD wParam, POINT *capturePoint )
800 LONG hittest = 0;
801 POINT pt;
802 MSG msg;
803 WND * wndPtr = WIN_FindWndPtr( hwnd );
805 if ((wParam & 0xfff0) == SC_MOVE)
807 /* Move pointer at the center of the caption */
808 RECT rect;
809 NC_GetInsideRect( hwnd, &rect );
810 if (wndPtr->dwStyle & WS_SYSMENU)
811 rect.left += SYSMETRICS_CXSIZE + 1;
812 if (wndPtr->dwStyle & WS_MINIMIZEBOX)
813 rect.right -= SYSMETRICS_CXSIZE + 1;
814 if (wndPtr->dwStyle & WS_MAXIMIZEBOX)
815 rect.right -= SYSMETRICS_CXSIZE + 1;
816 pt.x = wndPtr->rectWindow.left + (rect.right - rect.left) / 2;
817 pt.y = wndPtr->rectWindow.top + rect.top + SYSMETRICS_CYSIZE/2;
818 if (wndPtr->dwStyle & WS_CHILD)
819 ClientToScreen( wndPtr->hwndParent, &pt );
820 hittest = HTCAPTION;
822 else /* SC_SIZE */
824 SetCapture(hwnd);
825 while(!hittest)
827 MSG_GetHardwareMessage( &msg );
828 switch(msg.message)
830 case WM_MOUSEMOVE:
831 hittest = NC_HandleNCHitTest( hwnd, msg.pt );
832 pt = msg.pt;
833 if ((hittest < HTLEFT) || (hittest > HTBOTTOMRIGHT))
834 hittest = 0;
835 break;
837 case WM_LBUTTONUP:
838 return 0;
840 case WM_KEYDOWN:
841 switch(msg.wParam)
843 case VK_UP:
844 hittest = HTTOP;
845 pt.x =(wndPtr->rectWindow.left+wndPtr->rectWindow.right)/2;
846 pt.y = wndPtr->rectWindow.top + SYSMETRICS_CYFRAME / 2;
847 break;
848 case VK_DOWN:
849 hittest = HTBOTTOM;
850 pt.x =(wndPtr->rectWindow.left+wndPtr->rectWindow.right)/2;
851 pt.y = wndPtr->rectWindow.bottom - SYSMETRICS_CYFRAME / 2;
852 break;
853 case VK_LEFT:
854 hittest = HTLEFT;
855 pt.x = wndPtr->rectWindow.left + SYSMETRICS_CXFRAME / 2;
856 pt.y =(wndPtr->rectWindow.top+wndPtr->rectWindow.bottom)/2;
857 break;
858 case VK_RIGHT:
859 hittest = HTRIGHT;
860 pt.x = wndPtr->rectWindow.right - SYSMETRICS_CXFRAME / 2;
861 pt.y =(wndPtr->rectWindow.top+wndPtr->rectWindow.bottom)/2;
862 break;
863 case VK_RETURN:
864 case VK_ESCAPE: return 0;
869 *capturePoint = pt;
870 SetCursorPos( capturePoint->x, capturePoint->y );
871 NC_HandleSetCursor( hwnd, hwnd, MAKELONG( hittest, WM_MOUSEMOVE ));
872 return hittest;
876 /***********************************************************************
877 * NC_DoSizeMove
879 * Perform SC_MOVE and SC_SIZE commands.
881 static void NC_DoSizeMove( HWND hwnd, WORD wParam, POINT pt )
883 MSG msg;
884 LONG hittest;
885 RECT sizingRect, mouseRect;
886 HDC hdc;
887 BOOL thickframe;
888 POINT minTrack, maxTrack, capturePoint = pt;
889 WND * wndPtr = WIN_FindWndPtr( hwnd );
891 if (IsZoomed(hwnd) || !IsWindowVisible(hwnd)) return;
892 hittest = wParam & 0x0f;
893 thickframe = HAS_THICKFRAME( wndPtr->dwStyle );
895 if ((wParam & 0xfff0) == SC_MOVE)
897 if (!(wndPtr->dwStyle & WS_CAPTION)) return;
898 if (!hittest) hittest = NC_StartSizeMove( hwnd, wParam, &capturePoint );
899 if (!hittest) return;
901 else /* SC_SIZE */
903 if (!thickframe) return;
904 if (hittest) hittest += HTLEFT-1;
905 else
907 SetCapture(hwnd);
908 hittest = NC_StartSizeMove( hwnd, wParam, &capturePoint );
909 if (!hittest)
911 ReleaseCapture();
912 return;
917 /* Get min/max info */
919 NC_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack );
920 sizingRect = wndPtr->rectWindow;
921 if (wndPtr->dwStyle & WS_CHILD)
922 GetClientRect( wndPtr->hwndParent, &mouseRect );
923 else SetRect( &mouseRect, 0, 0, SYSMETRICS_CXSCREEN, SYSMETRICS_CYSCREEN );
924 if (ON_LEFT_BORDER(hittest))
926 mouseRect.left = max( mouseRect.left, sizingRect.right-maxTrack.x );
927 mouseRect.right = min( mouseRect.right, sizingRect.right-minTrack.x );
929 else if (ON_RIGHT_BORDER(hittest))
931 mouseRect.left = max( mouseRect.left, sizingRect.left+minTrack.x );
932 mouseRect.right = min( mouseRect.right, sizingRect.left+maxTrack.x );
934 if (ON_TOP_BORDER(hittest))
936 mouseRect.top = max( mouseRect.top, sizingRect.bottom-maxTrack.y );
937 mouseRect.bottom = min( mouseRect.bottom,sizingRect.bottom-minTrack.y);
939 else if (ON_BOTTOM_BORDER(hittest))
941 mouseRect.top = max( mouseRect.top, sizingRect.top+minTrack.y );
942 mouseRect.bottom = min( mouseRect.bottom, sizingRect.top+maxTrack.y );
944 SendMessage( hwnd, WM_ENTERSIZEMOVE, 0, 0 );
946 if (GetCapture() != hwnd) SetCapture( hwnd );
948 if (wndPtr->dwStyle & WS_CHILD)
950 /* Retrieve a default cache DC (without using the window style) */
951 hdc = GetDCEx( wndPtr->hwndParent, 0, DCX_CACHE );
953 else
954 { /* Grab the server only when moving top-level windows without desktop */
955 hdc = GetDC( 0 );
956 if (rootWindow == DefaultRootWindow(display)) XGrabServer( display );
958 NC_DrawMovingFrame( hdc, &sizingRect, thickframe );
960 while(1)
962 int dx = 0, dy = 0;
964 MSG_GetHardwareMessage( &msg );
966 /* Exit on button-up, Return, or Esc */
967 if ((msg.message == WM_LBUTTONUP) ||
968 ((msg.message == WM_KEYDOWN) &&
969 ((msg.wParam == VK_RETURN) || (msg.wParam == VK_ESCAPE)))) break;
971 if ((msg.message != WM_KEYDOWN) && (msg.message != WM_MOUSEMOVE))
972 continue; /* We are not interested in other messages */
974 pt = msg.pt;
975 if (wndPtr->dwStyle & WS_CHILD)
976 ScreenToClient( wndPtr->hwndParent, &pt );
979 if (msg.message == WM_KEYDOWN) switch(msg.wParam)
981 case VK_UP: pt.y -= 8; break;
982 case VK_DOWN: pt.y += 8; break;
983 case VK_LEFT: pt.x -= 8; break;
984 case VK_RIGHT: pt.x += 8; break;
987 pt.x = max( pt.x, mouseRect.left );
988 pt.x = min( pt.x, mouseRect.right );
989 pt.y = max( pt.y, mouseRect.top );
990 pt.y = min( pt.y, mouseRect.bottom );
992 dx = pt.x - capturePoint.x;
993 dy = pt.y - capturePoint.y;
995 if (dx || dy)
997 if (msg.message == WM_KEYDOWN) SetCursorPos( pt.x, pt.y );
998 else
1000 RECT newRect = sizingRect;
1002 if (hittest == HTCAPTION) OffsetRect( &newRect, dx, dy );
1003 if (ON_LEFT_BORDER(hittest)) newRect.left += dx;
1004 else if (ON_RIGHT_BORDER(hittest)) newRect.right += dx;
1005 if (ON_TOP_BORDER(hittest)) newRect.top += dy;
1006 else if (ON_BOTTOM_BORDER(hittest)) newRect.bottom += dy;
1007 NC_DrawMovingFrame( hdc, &sizingRect, thickframe );
1008 NC_DrawMovingFrame( hdc, &newRect, thickframe );
1009 capturePoint = pt;
1010 sizingRect = newRect;
1015 NC_DrawMovingFrame( hdc, &sizingRect, thickframe );
1016 ReleaseCapture();
1017 if (wndPtr->dwStyle & WS_CHILD) ReleaseDC( wndPtr->hwndParent, hdc );
1018 else
1020 ReleaseDC( 0, hdc );
1021 if (rootWindow == DefaultRootWindow(display)) XUngrabServer( display );
1023 SendMessage( hwnd, WM_EXITSIZEMOVE, 0, 0 );
1025 /* If Esc key, don't move the window */
1026 if ((msg.message == WM_KEYDOWN) && (msg.wParam == VK_ESCAPE)) return;
1028 if (hittest != HTCAPTION)
1029 SetWindowPos( hwnd, 0, sizingRect.left, sizingRect.top,
1030 sizingRect.right - sizingRect.left,
1031 sizingRect.bottom - sizingRect.top,
1032 SWP_NOACTIVATE | SWP_NOZORDER );
1033 else SetWindowPos( hwnd, 0, sizingRect.left, sizingRect.top, 0, 0,
1034 SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER );
1038 /***********************************************************************
1039 * NC_TrackMinMaxBox
1041 * Track a mouse button press on the minimize or maximize box.
1043 static void NC_TrackMinMaxBox( HWND hwnd, WORD wParam )
1045 MSG msg;
1046 HDC hdc = GetWindowDC( hwnd );
1047 BOOL pressed = TRUE;
1049 SetCapture( hwnd );
1050 if (wParam == HTMINBUTTON) NC_DrawMinButton( hwnd, hdc, TRUE );
1051 else NC_DrawMaxButton( hwnd, hdc, TRUE );
1055 BOOL oldstate = pressed;
1056 MSG_GetHardwareMessage( &msg );
1058 pressed = (NC_HandleNCHitTest( hwnd, msg.pt ) == wParam);
1059 if (pressed != oldstate)
1061 if (wParam == HTMINBUTTON) NC_DrawMinButton( hwnd, hdc, pressed );
1062 else NC_DrawMaxButton( hwnd, hdc, pressed );
1064 } while (msg.message != WM_LBUTTONUP);
1066 if (wParam == HTMINBUTTON) NC_DrawMinButton( hwnd, hdc, FALSE );
1067 else NC_DrawMaxButton( hwnd, hdc, FALSE );
1069 ReleaseCapture();
1070 ReleaseDC( hwnd, hdc );
1071 if (!pressed) return;
1073 if (wParam == HTMINBUTTON)
1074 SendMessage( hwnd, WM_SYSCOMMAND, SC_MINIMIZE, *(LONG*)&msg.pt );
1075 else
1076 SendMessage( hwnd, WM_SYSCOMMAND,
1077 IsZoomed(hwnd) ? SC_RESTORE : SC_MAXIMIZE, *(LONG*)&msg.pt );
1081 /***********************************************************************
1082 * NC_TrackScrollBar
1084 * Track a mouse button press on the horizontal or vertical scroll-bar.
1086 static void NC_TrackScrollBar( HWND hwnd, WORD wParam, POINT pt )
1088 MSG *msg;
1089 HLOCAL hMsg;
1090 WORD scrollbar;
1091 WND *wndPtr = WIN_FindWndPtr( hwnd );
1093 if ((wParam & 0xfff0) == SC_HSCROLL)
1095 if ((wParam & 0x0f) != HTHSCROLL) return;
1096 scrollbar = SB_HORZ;
1098 else /* SC_VSCROLL */
1100 if ((wParam & 0x0f) != HTVSCROLL) return;
1101 scrollbar = SB_VERT;
1104 hMsg = USER_HEAP_ALLOC( sizeof(MSG) );
1105 msg = (MSG *) USER_HEAP_LIN_ADDR( hMsg );
1106 pt.x -= wndPtr->rectWindow.left;
1107 pt.y -= wndPtr->rectWindow.top;
1108 SetCapture( hwnd );
1109 SCROLL_HandleScrollEvent( hwnd, scrollbar, WM_LBUTTONDOWN, pt );
1113 GetMessage( USER_HEAP_SEG_ADDR(hMsg), 0, 0, 0 );
1114 switch(msg->message)
1116 case WM_LBUTTONUP:
1117 case WM_MOUSEMOVE:
1118 case WM_SYSTIMER:
1119 pt = MAKEPOINT(msg->lParam);
1120 pt.x += wndPtr->rectClient.left - wndPtr->rectWindow.left;
1121 pt.y += wndPtr->rectClient.top - wndPtr->rectWindow.top;
1122 SCROLL_HandleScrollEvent( hwnd, scrollbar, msg->message, pt );
1123 break;
1124 default:
1125 TranslateMessage( msg );
1126 DispatchMessage( msg );
1127 break;
1129 if (!IsWindow( hwnd ))
1131 ReleaseCapture();
1132 break;
1134 } while (msg->message != WM_LBUTTONUP);
1135 USER_HEAP_FREE( hMsg );
1138 /***********************************************************************
1139 * NC_TrackSysMenu
1141 * Track a mouse button press on the system menu.
1143 static void NC_TrackSysMenu( HWND hwnd, HDC hdc, POINT pt )
1145 RECT rect;
1146 WND *wndPtr = WIN_FindWndPtr( hwnd );
1148 if (!(wndPtr->dwStyle & WS_SYSMENU)) return;
1149 /* If window has a menu, track the menu bar normally */
1150 if (HAS_MENU(wndPtr)) MENU_TrackMouseMenuBar( hwnd, pt );
1151 else
1153 /* Otherwise track the system menu like a normal popup menu */
1154 NC_GetInsideRect( hwnd, &rect );
1155 OffsetRect( &rect, wndPtr->rectWindow.left, wndPtr->rectWindow.top );
1156 if (wndPtr->dwStyle & WS_CHILD)
1157 ClientToScreen( wndPtr->hwndParent, (POINT *)&rect );
1158 rect.right = rect.left + SYSMETRICS_CXSIZE;
1159 rect.bottom = rect.top + SYSMETRICS_CYSIZE;
1160 NC_DrawSysButton( hwnd, hdc, TRUE );
1161 TrackPopupMenu( wndPtr->hSysMenu, TPM_LEFTALIGN | TPM_LEFTBUTTON,
1162 rect.left, rect.bottom, 0, hwnd, &rect );
1163 NC_DrawSysButton( hwnd, hdc, FALSE );
1168 /***********************************************************************
1169 * NC_HandleNCLButtonDown
1171 * Handle a WM_NCLBUTTONDOWN message. Called from DefWindowProc().
1173 LONG NC_HandleNCLButtonDown( HWND hwnd, WORD wParam, LONG lParam )
1175 HDC hdc = GetWindowDC( hwnd );
1177 switch(wParam) /* Hit test */
1179 case HTCAPTION:
1180 SendMessage( hwnd, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, lParam );
1181 break;
1183 case HTSYSMENU:
1184 NC_TrackSysMenu( hwnd, hdc, MAKEPOINT(lParam) );
1185 break;
1187 case HTMENU:
1188 SendMessage( hwnd, WM_SYSCOMMAND, SC_MOUSEMENU, lParam );
1189 break;
1191 case HTHSCROLL:
1192 SendMessage( hwnd, WM_SYSCOMMAND, SC_HSCROLL + HTHSCROLL, lParam );
1193 break;
1195 case HTVSCROLL:
1196 SendMessage( hwnd, WM_SYSCOMMAND, SC_VSCROLL + HTVSCROLL, lParam );
1197 break;
1199 case HTMINBUTTON:
1200 case HTMAXBUTTON:
1201 NC_TrackMinMaxBox( hwnd, wParam );
1202 break;
1204 case HTLEFT:
1205 case HTRIGHT:
1206 case HTTOP:
1207 case HTTOPLEFT:
1208 case HTTOPRIGHT:
1209 case HTBOTTOM:
1210 case HTBOTTOMLEFT:
1211 case HTBOTTOMRIGHT:
1212 SendMessage( hwnd, WM_SYSCOMMAND, SC_SIZE + wParam - HTLEFT+1, lParam);
1213 break;
1215 case HTBORDER:
1216 break;
1219 ReleaseDC( hwnd, hdc );
1220 return 0;
1224 /***********************************************************************
1225 * NC_HandleNCLButtonDblClk
1227 * Handle a WM_NCLBUTTONDBLCLK message. Called from DefWindowProc().
1229 LONG NC_HandleNCLButtonDblClk( HWND hwnd, WORD wParam, LONG lParam )
1232 * if this is an icon, send a restore since we are handling
1233 * a double click
1235 if (IsIconic(hwnd))
1237 SendMessage(hwnd, WM_SYSCOMMAND, SC_RESTORE, lParam);
1238 return 0;
1241 switch(wParam) /* Hit test */
1243 case HTCAPTION:
1244 SendMessage( hwnd, WM_SYSCOMMAND,
1245 IsZoomed(hwnd) ? SC_RESTORE : SC_MAXIMIZE, lParam );
1246 break;
1248 case HTSYSMENU:
1249 SendMessage( hwnd, WM_SYSCOMMAND, SC_CLOSE, lParam );
1250 break;
1252 return 0;
1256 /***********************************************************************
1257 * NC_HandleSysCommand
1259 * Handle a WM_SYSCOMMAND message. Called from DefWindowProc().
1261 LONG NC_HandleSysCommand( HWND hwnd, WORD wParam, POINT pt )
1263 WND *wndPtr = WIN_FindWndPtr( hwnd );
1265 dprintf_nonclient(stddeb, "Handling WM_SYSCOMMAND %x %d,%d\n",
1266 wParam, pt.x, pt.y );
1268 if (wndPtr->dwStyle & WS_CHILD) ScreenToClient( wndPtr->hwndParent, &pt );
1270 switch (wParam & 0xfff0)
1272 case SC_SIZE:
1273 case SC_MOVE:
1274 NC_DoSizeMove( hwnd, wParam, pt );
1275 break;
1277 case SC_MINIMIZE:
1278 ShowWindow( hwnd, SW_MINIMIZE );
1279 break;
1281 case SC_MAXIMIZE:
1282 ShowWindow( hwnd, SW_MAXIMIZE );
1283 break;
1285 case SC_RESTORE:
1286 ShowWindow( hwnd, SW_RESTORE );
1287 break;
1289 case SC_NEXTWINDOW:
1290 case SC_PREVWINDOW:
1291 break;
1293 case SC_CLOSE:
1294 return SendMessage( hwnd, WM_CLOSE, 0, 0 );
1296 case SC_VSCROLL:
1297 case SC_HSCROLL:
1298 NC_TrackScrollBar( hwnd, wParam, pt );
1299 break;
1301 case SC_MOUSEMENU:
1302 MENU_TrackMouseMenuBar( hwnd, pt );
1303 break;
1305 case SC_KEYMENU:
1306 MENU_TrackKbdMenuBar( hwnd, wParam );
1307 break;
1309 case SC_ARRANGE:
1310 break;
1312 case SC_TASKLIST:
1313 WinExec( "taskman.exe", SW_SHOWNORMAL );
1314 break;
1316 case SC_HOTKEY:
1317 break;
1319 case SC_SCREENSAVE:
1320 if (wParam == SC_ABOUTWINE)
1322 extern const char people[];
1323 ShellAbout(hwnd,"WINE",people,0);
1325 break;
1327 return 0;