Release 950727
[wine/multimedia.git] / windows / nonclient.c
bloba192262f2f125ed7c8e2cea81d8501aadf610580
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 "shell.h"
14 #include "dialog.h"
15 #include "syscolor.h"
16 #include "menu.h"
17 #include "winpos.h"
18 #include "scroll.h"
19 #include "nonclient.h"
20 #include "graphics.h"
21 #include "selectors.h"
22 #include "stddebug.h"
23 /* #define DEBUG_NONCLIENT */
24 #include "debug.h"
27 static HBITMAP hbitmapClose = 0;
28 static HBITMAP hbitmapMinimize = 0;
29 static HBITMAP hbitmapMinimizeD = 0;
30 static HBITMAP hbitmapMaximize = 0;
31 static HBITMAP hbitmapMaximizeD = 0;
32 static HBITMAP hbitmapRestore = 0;
33 static HBITMAP hbitmapRestoreD = 0;
35 #define SC_ABOUTWINE (SC_SCREENSAVE+1)
37 /* Some useful macros */
38 #define HAS_DLGFRAME(style,exStyle) \
39 (((exStyle) & WS_EX_DLGMODALFRAME) || \
40 (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
42 #define HAS_THICKFRAME(style) \
43 (((style) & WS_THICKFRAME) && \
44 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
46 #define HAS_MENU(w) (!((w)->dwStyle & WS_CHILD) && ((w)->wIDmenu != 0))
48 #define ON_LEFT_BORDER(hit) \
49 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
50 #define ON_RIGHT_BORDER(hit) \
51 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
52 #define ON_TOP_BORDER(hit) \
53 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
54 #define ON_BOTTOM_BORDER(hit) \
55 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
57 /***********************************************************************
58 * NC_AdjustRect
60 * Compute the size of the window rectangle from the size of the
61 * client rectangle.
63 static void NC_AdjustRect( LPRECT rect, DWORD style, BOOL menu, DWORD exStyle )
65 if (style & WS_ICONIC) return; /* Nothing to change for an icon */
66 if (HAS_DLGFRAME( style, exStyle ))
67 InflateRect( rect, SYSMETRICS_CXDLGFRAME, SYSMETRICS_CYDLGFRAME );
68 else
70 if (HAS_THICKFRAME(style))
71 InflateRect( rect, SYSMETRICS_CXFRAME, SYSMETRICS_CYFRAME );
72 if (style & WS_BORDER)
73 InflateRect( rect, SYSMETRICS_CXBORDER, SYSMETRICS_CYBORDER );
76 if ((style & WS_CAPTION) == WS_CAPTION)
77 rect->top -= SYSMETRICS_CYCAPTION - SYSMETRICS_CYBORDER;
78 if (menu) rect->top -= SYSMETRICS_CYMENU + SYSMETRICS_CYBORDER;
80 if (style & WS_VSCROLL) rect->right += SYSMETRICS_CXVSCROLL;
81 if (style & WS_HSCROLL) rect->bottom += SYSMETRICS_CYHSCROLL;
85 /***********************************************************************
86 * AdjustWindowRect (USER.102)
88 void AdjustWindowRect( LPRECT rect, DWORD style, BOOL menu )
90 AdjustWindowRectEx( rect, style, menu, 0 );
94 /***********************************************************************
95 * AdjustWindowRectEx (USER.454)
97 void AdjustWindowRectEx( LPRECT rect, DWORD style, BOOL menu, DWORD exStyle )
99 /* Correct the window style */
101 if (!(style & (WS_POPUP | WS_CHILD))) /* Overlapped window */
102 style |= WS_CAPTION;
103 if (exStyle & WS_EX_DLGMODALFRAME) style &= ~WS_THICKFRAME;
105 dprintf_nonclient(stddeb, "AdjustWindowRectEx: (%d,%d)-(%d,%d) %08lx %d %08lx\n",
106 rect->left, rect->top, rect->right, rect->bottom, style, menu, exStyle );
108 NC_AdjustRect( rect, style, menu, exStyle );
112 /*******************************************************************
113 * NC_GetMinMaxInfo
115 * Get the minimized and maximized information for a window.
117 void NC_GetMinMaxInfo( HWND hwnd, POINT *maxSize, POINT *maxPos,
118 POINT *minTrack, POINT *maxTrack )
120 HANDLE minmaxHandle;
121 MINMAXINFO MinMax, *pMinMax;
122 short xinc, yinc;
123 WND *wndPtr = WIN_FindWndPtr( hwnd );
125 /* Compute default values */
127 MinMax.ptMaxSize.x = SYSMETRICS_CXSCREEN;
128 MinMax.ptMaxSize.y = SYSMETRICS_CYSCREEN;
129 MinMax.ptMinTrackSize.x = SYSMETRICS_CXMINTRACK;
130 MinMax.ptMinTrackSize.y = SYSMETRICS_CYMINTRACK;
131 MinMax.ptMaxTrackSize.x = SYSMETRICS_CXSCREEN;
132 MinMax.ptMaxTrackSize.y = SYSMETRICS_CYSCREEN;
134 if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
136 xinc = SYSMETRICS_CXDLGFRAME;
137 yinc = SYSMETRICS_CYDLGFRAME;
139 else
141 xinc = yinc = 0;
142 if (HAS_THICKFRAME(wndPtr->dwStyle))
144 xinc += SYSMETRICS_CXFRAME;
145 yinc += SYSMETRICS_CYFRAME;
147 if (wndPtr->dwStyle & WS_BORDER)
149 xinc += SYSMETRICS_CXBORDER;
150 yinc += SYSMETRICS_CYBORDER;
153 MinMax.ptMaxSize.x += 2 * xinc;
154 MinMax.ptMaxSize.y += 2 * yinc;
156 /* Note: The '+' in the following test should really be a ||, but
157 * that would cause gcc-2.7.0 to generate incorrect code.
159 if ((wndPtr->ptMaxPos.x != -1) + (wndPtr->ptMaxPos.y != -1))
160 MinMax.ptMaxPosition = wndPtr->ptMaxPos;
161 else
163 MinMax.ptMaxPosition.x = -xinc;
164 MinMax.ptMaxPosition.y = -yinc;
167 minmaxHandle = USER_HEAP_ALLOC( sizeof(MINMAXINFO) );
168 if (minmaxHandle)
170 pMinMax = (MINMAXINFO *) USER_HEAP_LIN_ADDR( minmaxHandle );
171 memcpy( pMinMax, &MinMax, sizeof(MinMax) );
172 SendMessage( hwnd, WM_GETMINMAXINFO, 0,
173 USER_HEAP_SEG_ADDR(minmaxHandle) );
175 else pMinMax = &MinMax;
177 /* Some sanity checks */
179 pMinMax->ptMaxTrackSize.x = max( pMinMax->ptMaxTrackSize.x,
180 pMinMax->ptMinTrackSize.x );
181 pMinMax->ptMaxTrackSize.y = max( pMinMax->ptMaxTrackSize.y,
182 pMinMax->ptMinTrackSize.y );
184 if (maxSize) *maxSize = pMinMax->ptMaxSize;
185 if (maxPos) *maxPos = pMinMax->ptMaxPosition;
186 if (minTrack) *minTrack = pMinMax->ptMinTrackSize;
187 if (maxTrack) *maxTrack = pMinMax->ptMaxTrackSize;
188 if (minmaxHandle) USER_HEAP_FREE( minmaxHandle );
192 /***********************************************************************
193 * NC_HandleNCCalcSize
195 * Handle a WM_NCCALCSIZE message. Called from DefWindowProc().
197 LONG NC_HandleNCCalcSize( HWND hwnd, NCCALCSIZE_PARAMS *params )
199 RECT tmpRect = { 0, 0, 0, 0 };
200 WND *wndPtr = WIN_FindWndPtr( hwnd );
202 if (!wndPtr) return 0;
203 NC_AdjustRect( &tmpRect, wndPtr->dwStyle, FALSE, wndPtr->dwExStyle );
204 params->rgrc[0].left -= tmpRect.left;
205 params->rgrc[0].top -= tmpRect.top;
206 params->rgrc[0].right -= tmpRect.right;
207 params->rgrc[0].bottom -= tmpRect.bottom;
209 if (HAS_MENU(wndPtr))
211 params->rgrc[0].top += MENU_GetMenuBarHeight( hwnd,
212 params->rgrc[0].right - params->rgrc[0].left,
213 -tmpRect.left, -tmpRect.top ) + 1;
215 return 0;
219 /***********************************************************************
220 * NC_GetInsideRect
222 * Get the 'inside' rectangle of a window, i.e. the whole window rectangle
223 * but without the borders (if any).
224 * The rectangle is in window coordinates (for drawing with GetWindowDC()).
226 void NC_GetInsideRect( HWND hwnd, RECT *rect )
228 WND * wndPtr = WIN_FindWndPtr( hwnd );
230 rect->top = rect->left = 0;
231 rect->right = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
232 rect->bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
234 if (wndPtr->dwStyle & WS_ICONIC) return; /* No border to remove */
236 /* Remove frame from rectangle */
237 if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
239 InflateRect( rect, -SYSMETRICS_CXDLGFRAME, -SYSMETRICS_CYDLGFRAME);
240 if (wndPtr->dwExStyle & WS_EX_DLGMODALFRAME) InflateRect( rect, -1, 0);
242 else
244 if (HAS_THICKFRAME( wndPtr->dwStyle ))
245 InflateRect( rect, -SYSMETRICS_CXFRAME, -SYSMETRICS_CYFRAME );
246 if (wndPtr->dwStyle & WS_BORDER)
247 InflateRect( rect, -SYSMETRICS_CXBORDER, -SYSMETRICS_CYBORDER );
252 /***********************************************************************
253 * NC_HandleNCHitTest
255 * Handle a WM_NCHITTEST message. Called from DefWindowProc().
257 LONG NC_HandleNCHitTest( HWND hwnd, POINT pt )
259 RECT rect;
260 WND *wndPtr = WIN_FindWndPtr( hwnd );
261 if (!wndPtr) return HTERROR;
263 dprintf_nonclient(stddeb, "NC_HandleNCHitTest: hwnd=%x pt=%d,%d\n",
264 hwnd, pt.x, pt.y );
266 GetWindowRect( hwnd, &rect );
267 if (!PtInRect( &rect, pt )) return HTNOWHERE;
270 * if this is a iconic window, we don't care were the hit
271 * occured, only that it did occur, just return HTCAPTION
272 * so the caller knows the icon did get hit
274 if (IsIconic(hwnd))
276 return HTCAPTION; /* change this to something meaningful? */
279 /* Check borders */
280 if (HAS_THICKFRAME( wndPtr->dwStyle ))
282 InflateRect( &rect, -SYSMETRICS_CXFRAME, -SYSMETRICS_CYFRAME );
283 if (wndPtr->dwStyle & WS_BORDER)
284 InflateRect( &rect, -SYSMETRICS_CXBORDER, -SYSMETRICS_CYBORDER );
285 if (!PtInRect( &rect, pt ))
287 /* Check top sizing border */
288 if (pt.y < rect.top)
290 if (pt.x < rect.left+SYSMETRICS_CXSIZE) return HTTOPLEFT;
291 if (pt.x >= rect.right-SYSMETRICS_CXSIZE) return HTTOPRIGHT;
292 return HTTOP;
294 /* Check bottom sizing border */
295 if (pt.y >= rect.bottom)
297 if (pt.x < rect.left+SYSMETRICS_CXSIZE) return HTBOTTOMLEFT;
298 if (pt.x >= rect.right-SYSMETRICS_CXSIZE) return HTBOTTOMRIGHT;
299 return HTBOTTOM;
301 /* Check left sizing border */
302 if (pt.x < rect.left)
304 if (pt.y < rect.top+SYSMETRICS_CYSIZE) return HTTOPLEFT;
305 if (pt.y >= rect.bottom-SYSMETRICS_CYSIZE) return HTBOTTOMLEFT;
306 return HTLEFT;
308 /* Check right sizing border */
309 if (pt.x >= rect.right)
311 if (pt.y < rect.top+SYSMETRICS_CYSIZE) return HTTOPRIGHT;
312 if (pt.y >= rect.bottom-SYSMETRICS_CYSIZE) return HTBOTTOMRIGHT;
313 return HTRIGHT;
317 else /* No thick frame */
319 if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
320 InflateRect(&rect, -SYSMETRICS_CXDLGFRAME, -SYSMETRICS_CYDLGFRAME);
321 else if (wndPtr->dwStyle & WS_BORDER)
322 InflateRect(&rect, -SYSMETRICS_CXBORDER, -SYSMETRICS_CYBORDER);
323 if (!PtInRect( &rect, pt )) return HTBORDER;
326 /* Check caption */
328 if ((wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION)
330 rect.top += SYSMETRICS_CYCAPTION - 1;
331 if (!PtInRect( &rect, pt ))
333 /* Check system menu */
334 if (wndPtr->dwStyle & WS_SYSMENU)
335 rect.left += SYSMETRICS_CXSIZE;
336 if (pt.x <= rect.left) return HTSYSMENU;
337 /* Check maximize box */
338 if (wndPtr->dwStyle & WS_MAXIMIZEBOX)
339 rect.right -= SYSMETRICS_CXSIZE + 1;
340 if (pt.x >= rect.right) return HTMAXBUTTON;
341 /* Check minimize box */
342 if (wndPtr->dwStyle & WS_MINIMIZEBOX)
343 rect.right -= SYSMETRICS_CXSIZE + 1;
344 if (pt.x >= rect.right) return HTMINBUTTON;
345 return HTCAPTION;
349 /* Check client area */
351 ScreenToClient( hwnd, &pt );
352 GetClientRect( hwnd, &rect );
353 if (PtInRect( &rect, pt )) return HTCLIENT;
355 /* Check vertical scroll bar */
357 if (wndPtr->dwStyle & WS_VSCROLL)
359 rect.right += SYSMETRICS_CXVSCROLL;
360 if (PtInRect( &rect, pt )) return HTVSCROLL;
363 /* Check horizontal scroll bar */
365 if (wndPtr->dwStyle & WS_HSCROLL)
367 rect.bottom += SYSMETRICS_CYHSCROLL;
368 if (PtInRect( &rect, pt ))
370 /* Check size box */
371 if ((wndPtr->dwStyle & WS_VSCROLL) &&
372 (pt.x >= rect.right - SYSMETRICS_CXVSCROLL))
373 return HTSIZE;
374 return HTHSCROLL;
378 /* Check menu bar */
380 if (HAS_MENU(wndPtr))
382 if ((pt.y < 0) && (pt.x >= 0) && (pt.x < rect.right))
383 return HTMENU;
386 /* Should never get here */
387 return HTERROR;
391 /***********************************************************************
392 * NC_DrawSysButton
394 void NC_DrawSysButton( HWND hwnd, HDC hdc, BOOL down )
396 RECT rect;
397 HDC hdcMem;
398 HBITMAP hbitmap;
399 WND *wndPtr = WIN_FindWndPtr( hwnd );
401 NC_GetInsideRect( hwnd, &rect );
402 hdcMem = CreateCompatibleDC( hdc );
403 hbitmap = SelectObject( hdcMem, hbitmapClose );
404 BitBlt( hdc, rect.left, rect.top, SYSMETRICS_CXSIZE, SYSMETRICS_CYSIZE,
405 hdcMem, (wndPtr->dwStyle & WS_CHILD) ? SYSMETRICS_CXSIZE : 0, 0,
406 down ? NOTSRCCOPY : SRCCOPY );
407 SelectObject( hdcMem, hbitmap );
408 DeleteDC( hdcMem );
412 /***********************************************************************
413 * NC_DrawMaxButton
415 static void NC_DrawMaxButton( HWND hwnd, HDC hdc, BOOL down )
417 RECT rect;
418 NC_GetInsideRect( hwnd, &rect );
419 GRAPH_DrawBitmap( hdc, (IsZoomed(hwnd) ?
420 (down ? hbitmapRestoreD : hbitmapRestore) :
421 (down ? hbitmapMaximizeD : hbitmapMaximize)),
422 rect.right - SYSMETRICS_CXSIZE - 1, rect.top,
423 0, 0, SYSMETRICS_CXSIZE+1, SYSMETRICS_CYSIZE );
427 /***********************************************************************
428 * NC_DrawMinButton
430 static void NC_DrawMinButton( HWND hwnd, HDC hdc, BOOL down )
432 RECT rect;
433 WND *wndPtr = WIN_FindWndPtr( hwnd );
434 NC_GetInsideRect( hwnd, &rect );
435 if (wndPtr->dwStyle & WS_MAXIMIZEBOX) rect.right -= SYSMETRICS_CXSIZE + 1;
436 GRAPH_DrawBitmap( hdc, (down ? hbitmapMinimizeD : hbitmapMinimize),
437 rect.right - SYSMETRICS_CXSIZE - 1, rect.top,
438 0, 0, SYSMETRICS_CXSIZE+1, SYSMETRICS_CYSIZE );
442 /***********************************************************************
443 * NC_DrawFrame
445 * Draw a window frame inside the given rectangle, and update the rectangle.
446 * The correct pen for the frame must be selected in the DC.
448 static void NC_DrawFrame( HDC hdc, RECT *rect, BOOL dlgFrame, BOOL active )
450 short width, height, tmp;
452 if (dlgFrame)
454 width = SYSMETRICS_CXDLGFRAME - 1;
455 height = SYSMETRICS_CYDLGFRAME - 1;
456 SelectObject( hdc, active ? sysColorObjects.hbrushActiveCaption :
457 sysColorObjects.hbrushInactiveCaption );
459 else
461 width = SYSMETRICS_CXFRAME - 1;
462 height = SYSMETRICS_CYFRAME - 1;
463 SelectObject( hdc, active ? sysColorObjects.hbrushActiveBorder :
464 sysColorObjects.hbrushInactiveBorder );
467 /* Draw frame */
468 PatBlt( hdc, rect->left, rect->top,
469 rect->right - rect->left, height, PATCOPY );
470 PatBlt( hdc, rect->left, rect->top,
471 width, rect->bottom - rect->top, PATCOPY );
472 PatBlt( hdc, rect->left, rect->bottom,
473 rect->right - rect->left, -height, PATCOPY );
474 PatBlt( hdc, rect->right, rect->top,
475 -width, rect->bottom - rect->top, PATCOPY );
477 if (dlgFrame)
479 InflateRect( rect, -width, -height );
480 return;
483 /* Draw inner rectangle */
484 MoveTo( hdc, rect->left+width, rect->top+height );
485 LineTo( hdc, rect->right-width-1, rect->top+height );
486 LineTo( hdc, rect->right-width-1, rect->bottom-height-1 );
487 LineTo( hdc, rect->left+width, rect->bottom-height-1 );
488 LineTo( hdc, rect->left+width, rect->top+height );
490 /* Draw the decorations */
491 tmp = rect->top + SYSMETRICS_CYFRAME + SYSMETRICS_CYSIZE;
492 MoveTo( hdc, rect->left, tmp);
493 LineTo( hdc, rect->left+width, tmp );
494 MoveTo( hdc, rect->right-width-1, tmp );
495 LineTo( hdc, rect->right-1, tmp );
497 tmp = rect->bottom - 1 - SYSMETRICS_CYFRAME - SYSMETRICS_CYSIZE;
498 MoveTo( hdc, rect->left, tmp );
499 LineTo( hdc, rect->left+width, tmp );
500 MoveTo( hdc, rect->right-width-1, tmp );
501 LineTo( hdc, rect->right-1, tmp );
503 tmp = rect->left + SYSMETRICS_CXFRAME + SYSMETRICS_CXSIZE;
504 MoveTo( hdc, tmp, rect->top );
505 LineTo( hdc, tmp, rect->top+height );
506 MoveTo( hdc, tmp, rect->bottom-height-1 );
507 LineTo( hdc, tmp, rect->bottom-1 );
509 tmp = rect->right - 1 - SYSMETRICS_CXFRAME - SYSMETRICS_CYSIZE;
510 MoveTo( hdc, tmp, rect->top );
511 LineTo( hdc, tmp, rect->top+height );
512 MoveTo( hdc, tmp, rect->bottom-height-1 );
513 LineTo( hdc, tmp, rect->bottom-1 );
515 InflateRect( rect, -width-1, -height-1 );
519 /***********************************************************************
520 * NC_DrawMovingFrame
522 * Draw the frame used when moving or resizing window.
524 static void NC_DrawMovingFrame( HDC hdc, RECT *rect, BOOL thickframe )
526 if (thickframe)
528 SelectObject( hdc, GetStockObject( GRAY_BRUSH ) );
529 PatBlt( hdc, rect->left, rect->top,
530 rect->right - rect->left - SYSMETRICS_CXFRAME,
531 SYSMETRICS_CYFRAME, PATINVERT );
532 PatBlt( hdc, rect->left, rect->top + SYSMETRICS_CYFRAME,
533 SYSMETRICS_CXFRAME,
534 rect->bottom - rect->top - SYSMETRICS_CYFRAME, PATINVERT );
535 PatBlt( hdc, rect->left + SYSMETRICS_CXFRAME, rect->bottom,
536 rect->right - rect->left - SYSMETRICS_CXFRAME,
537 -SYSMETRICS_CYFRAME, PATINVERT );
538 PatBlt( hdc, rect->right, rect->top, -SYSMETRICS_CXFRAME,
539 rect->bottom - rect->top - SYSMETRICS_CYFRAME, PATINVERT );
541 else DrawFocusRect( hdc, rect );
545 /***********************************************************************
546 * NC_DrawCaption
548 * Draw the window caption.
549 * The correct pen for the window frame must be selected in the DC.
551 static void NC_DrawCaption( HDC hdc, RECT *rect, HWND hwnd,
552 DWORD style, BOOL active )
554 RECT r = *rect;
555 WND * wndPtr = WIN_FindWndPtr( hwnd );
556 char buffer[256];
558 if (!hbitmapClose)
560 if (!(hbitmapClose = LoadBitmap( 0, MAKEINTRESOURCE(OBM_CLOSE) )))
561 return;
562 hbitmapMinimize = LoadBitmap( 0, MAKEINTRESOURCE(OBM_REDUCE) );
563 hbitmapMinimizeD = LoadBitmap( 0, MAKEINTRESOURCE(OBM_REDUCED) );
564 hbitmapMaximize = LoadBitmap( 0, MAKEINTRESOURCE(OBM_ZOOM) );
565 hbitmapMaximizeD = LoadBitmap( 0, MAKEINTRESOURCE(OBM_ZOOMD) );
566 hbitmapRestore = LoadBitmap( 0, MAKEINTRESOURCE(OBM_RESTORE) );
567 hbitmapRestoreD = LoadBitmap( 0, MAKEINTRESOURCE(OBM_RESTORED) );
570 if (wndPtr->dwExStyle & WS_EX_DLGMODALFRAME)
572 HBRUSH hbrushOld = SelectObject( hdc, sysColorObjects.hbrushWindow );
573 PatBlt( hdc, r.left, r.top, 1, r.bottom-r.top+1,PATCOPY );
574 PatBlt( hdc, r.right-1, r.top, 1, r.bottom-r.top+1, PATCOPY );
575 PatBlt( hdc, r.left, r.top-1, r.right-r.left, 1, PATCOPY );
576 r.left++;
577 r.right--;
578 SelectObject( hdc, hbrushOld );
581 MoveTo( hdc, r.left, r.bottom );
582 LineTo( hdc, r.right-1, r.bottom );
584 if (style & WS_SYSMENU)
586 NC_DrawSysButton( hwnd, hdc, FALSE );
587 r.left += SYSMETRICS_CXSIZE + 1;
588 MoveTo( hdc, r.left - 1, r.top );
589 LineTo( hdc, r.left - 1, r.bottom );
591 if (style & WS_MAXIMIZEBOX)
593 NC_DrawMaxButton( hwnd, hdc, FALSE );
594 r.right -= SYSMETRICS_CXSIZE + 1;
596 if (style & WS_MINIMIZEBOX)
598 NC_DrawMinButton( hwnd, hdc, FALSE );
599 r.right -= SYSMETRICS_CXSIZE + 1;
602 FillRect( hdc, &r, active ? sysColorObjects.hbrushActiveCaption :
603 sysColorObjects.hbrushInactiveCaption );
605 if (GetWindowText( hwnd, buffer, 256 ))
607 if (active) SetTextColor( hdc, GetSysColor( COLOR_CAPTIONTEXT ) );
608 else SetTextColor( hdc, GetSysColor( COLOR_INACTIVECAPTIONTEXT ) );
609 SetBkMode( hdc, TRANSPARENT );
610 DrawText( hdc, buffer, -1, &r, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
615 /***********************************************************************
616 * NC_DoNCPaint
618 * Paint the non-client area.
620 void NC_DoNCPaint( HWND hwnd, BOOL active, BOOL suppress_menupaint )
622 HDC hdc;
623 RECT rect;
625 WND *wndPtr = WIN_FindWndPtr( hwnd );
627 dprintf_nonclient(stddeb, "NC_DoNCPaint: %x %d\n", hwnd, active );
628 if (!wndPtr || !(wndPtr->dwStyle & WS_VISIBLE)) return; /* Nothing to do */
630 if (!(hdc = GetDCEx( hwnd, 0, DCX_USESTYLE | DCX_WINDOW ))) return;
633 * If this is an icon, we don't want to do any more nonclient painting
634 * of the window manager.
635 * If there is a class icon to draw, draw it
637 if (IsIconic(hwnd))
639 HICON hIcon = WIN_CLASS_INFO(wndPtr).hIcon;
640 if (hIcon)
642 SendMessage(hwnd, WM_ICONERASEBKGND, hdc, 0);
643 DrawIcon(hdc, 0, 0, hIcon);
645 ReleaseDC(hwnd, hdc);
646 return;
649 if (ExcludeVisRect( hdc, wndPtr->rectClient.left-wndPtr->rectWindow.left,
650 wndPtr->rectClient.top-wndPtr->rectWindow.top,
651 wndPtr->rectClient.right-wndPtr->rectWindow.left,
652 wndPtr->rectClient.bottom-wndPtr->rectWindow.top )
653 == NULLREGION)
655 ReleaseDC( hwnd, hdc );
656 return;
659 rect.top = rect.left = 0;
660 rect.right = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
661 rect.bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
663 SelectObject( hdc, sysColorObjects.hpenWindowFrame );
665 if ((wndPtr->dwStyle & WS_BORDER) || (wndPtr->dwStyle & WS_DLGFRAME) ||
666 (wndPtr->dwExStyle & WS_EX_DLGMODALFRAME))
668 MoveTo( hdc, 0, 0 );
669 LineTo( hdc, rect.right-1, 0 );
670 LineTo( hdc, rect.right-1, rect.bottom-1 );
671 LineTo( hdc, 0, rect.bottom-1 );
672 LineTo( hdc, 0, 0 );
673 InflateRect( &rect, -1, -1 );
676 if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
677 NC_DrawFrame( hdc, &rect, TRUE, active );
678 else if (wndPtr->dwStyle & WS_THICKFRAME)
679 NC_DrawFrame(hdc, &rect, FALSE, active );
681 if ((wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION)
683 RECT r = rect;
684 r.bottom = rect.top + SYSMETRICS_CYSIZE;
685 rect.top += SYSMETRICS_CYSIZE + SYSMETRICS_CYBORDER;
686 NC_DrawCaption( hdc, &r, hwnd, wndPtr->dwStyle, active );
689 if (HAS_MENU(wndPtr))
691 RECT r = rect;
692 r.bottom = rect.top + SYSMETRICS_CYMENU; /* default height */
693 rect.top += MENU_DrawMenuBar( hdc, &r, hwnd, suppress_menupaint );
696 /* Draw the scroll-bars */
698 if (wndPtr->dwStyle & WS_VSCROLL) SCROLL_DrawScrollBar(hwnd, hdc, SB_VERT);
699 if (wndPtr->dwStyle & WS_HSCROLL) SCROLL_DrawScrollBar(hwnd, hdc, SB_HORZ);
701 /* Draw the "size-box" */
703 if ((wndPtr->dwStyle & WS_VSCROLL) && (wndPtr->dwStyle & WS_HSCROLL))
705 RECT r = rect;
706 r.left = r.right - SYSMETRICS_CXVSCROLL + 1;
707 r.top = r.bottom - SYSMETRICS_CYHSCROLL + 1;
708 FillRect( hdc, &r, sysColorObjects.hbrushScrollbar );
711 ReleaseDC( hwnd, hdc );
716 /***********************************************************************
717 * NC_HandleNCPaint
719 * Handle a WM_NCPAINT message. Called from DefWindowProc().
721 LONG NC_HandleNCPaint( HWND hwnd )
723 NC_DoNCPaint( hwnd, hwnd == GetActiveWindow(), FALSE );
724 return 0;
728 /***********************************************************************
729 * NC_HandleNCActivate
731 * Handle a WM_NCACTIVATE message. Called from DefWindowProc().
733 LONG NC_HandleNCActivate( HWND hwnd, WORD wParam )
735 NC_DoNCPaint( hwnd, wParam, FALSE );
736 return TRUE;
740 /***********************************************************************
741 * NC_HandleSetCursor
743 * Handle a WM_SETCURSOR message. Called from DefWindowProc().
745 LONG NC_HandleSetCursor( HWND hwnd, WORD wParam, LONG lParam )
747 if (hwnd != wParam) return 0; /* Don't set the cursor for child windows */
749 switch(LOWORD(lParam))
751 case HTERROR:
753 WORD msg = HIWORD( lParam );
754 if ((msg == WM_LBUTTONDOWN) || (msg == WM_MBUTTONDOWN) ||
755 (msg == WM_RBUTTONDOWN))
756 MessageBeep(0);
758 break;
760 case HTCLIENT:
762 WND *wndPtr;
763 CLASS *classPtr;
764 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) break;
765 if (!(classPtr = CLASS_FindClassPtr( wndPtr->hClass ))) break;
766 if (classPtr->wc.hCursor)
768 SetCursor( classPtr->wc.hCursor );
769 return TRUE;
771 else return FALSE;
774 case HTLEFT:
775 case HTRIGHT:
776 return SetCursor( LoadCursor( 0, IDC_SIZEWE ) );
778 case HTTOP:
779 case HTBOTTOM:
780 return SetCursor( LoadCursor( 0, IDC_SIZENS ) );
782 case HTTOPLEFT:
783 case HTBOTTOMRIGHT:
784 return SetCursor( LoadCursor( 0, IDC_SIZENWSE ) );
786 case HTTOPRIGHT:
787 case HTBOTTOMLEFT:
788 return SetCursor( LoadCursor( 0, IDC_SIZENESW ) );
791 /* Default cursor: arrow */
792 return SetCursor( LoadCursor( 0, IDC_ARROW ) );
796 /***********************************************************************
797 * NC_StartSizeMove
799 * Initialisation of a move or resize, when initiatied from a menu choice.
800 * Return hit test code for caption or sizing border.
802 static LONG NC_StartSizeMove( HWND hwnd, WORD wParam, POINT *capturePoint )
804 LONG hittest = 0;
805 POINT pt;
806 MSG msg;
807 WND * wndPtr = WIN_FindWndPtr( hwnd );
809 if ((wParam & 0xfff0) == SC_MOVE)
811 /* Move pointer at the center of the caption */
812 RECT rect;
813 NC_GetInsideRect( hwnd, &rect );
814 if (wndPtr->dwStyle & WS_SYSMENU)
815 rect.left += SYSMETRICS_CXSIZE + 1;
816 if (wndPtr->dwStyle & WS_MINIMIZEBOX)
817 rect.right -= SYSMETRICS_CXSIZE + 1;
818 if (wndPtr->dwStyle & WS_MAXIMIZEBOX)
819 rect.right -= SYSMETRICS_CXSIZE + 1;
820 pt.x = wndPtr->rectWindow.left + (rect.right - rect.left) / 2;
821 pt.y = wndPtr->rectWindow.top + rect.top + SYSMETRICS_CYSIZE/2;
822 if (wndPtr->dwStyle & WS_CHILD)
823 ClientToScreen( wndPtr->hwndParent, &pt );
824 hittest = HTCAPTION;
826 else /* SC_SIZE */
828 SetCapture(hwnd);
829 while(!hittest)
831 MSG_GetHardwareMessage( &msg );
832 switch(msg.message)
834 case WM_MOUSEMOVE:
835 hittest = NC_HandleNCHitTest( hwnd, msg.pt );
836 pt = msg.pt;
837 if ((hittest < HTLEFT) || (hittest > HTBOTTOMRIGHT))
838 hittest = 0;
839 break;
841 case WM_LBUTTONUP:
842 return 0;
844 case WM_KEYDOWN:
845 switch(msg.wParam)
847 case VK_UP:
848 hittest = HTTOP;
849 pt.x =(wndPtr->rectWindow.left+wndPtr->rectWindow.right)/2;
850 pt.y = wndPtr->rectWindow.top + SYSMETRICS_CYFRAME / 2;
851 break;
852 case VK_DOWN:
853 hittest = HTBOTTOM;
854 pt.x =(wndPtr->rectWindow.left+wndPtr->rectWindow.right)/2;
855 pt.y = wndPtr->rectWindow.bottom - SYSMETRICS_CYFRAME / 2;
856 break;
857 case VK_LEFT:
858 hittest = HTLEFT;
859 pt.x = wndPtr->rectWindow.left + SYSMETRICS_CXFRAME / 2;
860 pt.y =(wndPtr->rectWindow.top+wndPtr->rectWindow.bottom)/2;
861 break;
862 case VK_RIGHT:
863 hittest = HTRIGHT;
864 pt.x = wndPtr->rectWindow.right - SYSMETRICS_CXFRAME / 2;
865 pt.y =(wndPtr->rectWindow.top+wndPtr->rectWindow.bottom)/2;
866 break;
867 case VK_RETURN:
868 case VK_ESCAPE: return 0;
873 *capturePoint = pt;
874 SetCursorPos( capturePoint->x, capturePoint->y );
875 NC_HandleSetCursor( hwnd, hwnd, MAKELONG( hittest, WM_MOUSEMOVE ));
876 return hittest;
880 /***********************************************************************
881 * NC_DoSizeMove
883 * Perform SC_MOVE and SC_SIZE commands.
885 static void NC_DoSizeMove( HWND hwnd, WORD wParam, POINT pt )
887 MSG msg;
888 LONG hittest;
889 RECT sizingRect, mouseRect;
890 HDC hdc;
891 BOOL thickframe;
892 POINT minTrack, maxTrack, capturePoint = pt;
893 WND * wndPtr = WIN_FindWndPtr( hwnd );
895 if (IsZoomed(hwnd) || !IsWindowVisible(hwnd)) return;
896 hittest = wParam & 0x0f;
897 thickframe = HAS_THICKFRAME( wndPtr->dwStyle );
899 if ((wParam & 0xfff0) == SC_MOVE)
901 if (!(wndPtr->dwStyle & WS_CAPTION)) return;
902 if (!hittest) hittest = NC_StartSizeMove( hwnd, wParam, &capturePoint );
903 if (!hittest) return;
905 else /* SC_SIZE */
907 if (!thickframe) return;
908 if (hittest) hittest += HTLEFT-1;
909 else
911 SetCapture(hwnd);
912 hittest = NC_StartSizeMove( hwnd, wParam, &capturePoint );
913 if (!hittest)
915 ReleaseCapture();
916 return;
921 /* Get min/max info */
923 NC_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack );
924 sizingRect = wndPtr->rectWindow;
925 if (wndPtr->dwStyle & WS_CHILD)
926 GetClientRect( wndPtr->hwndParent, &mouseRect );
927 else SetRect( &mouseRect, 0, 0, SYSMETRICS_CXSCREEN, SYSMETRICS_CYSCREEN );
928 if (ON_LEFT_BORDER(hittest))
930 mouseRect.left = max( mouseRect.left, sizingRect.right-maxTrack.x );
931 mouseRect.right = min( mouseRect.right, sizingRect.right-minTrack.x );
933 else if (ON_RIGHT_BORDER(hittest))
935 mouseRect.left = max( mouseRect.left, sizingRect.left+minTrack.x );
936 mouseRect.right = min( mouseRect.right, sizingRect.left+maxTrack.x );
938 if (ON_TOP_BORDER(hittest))
940 mouseRect.top = max( mouseRect.top, sizingRect.bottom-maxTrack.y );
941 mouseRect.bottom = min( mouseRect.bottom,sizingRect.bottom-minTrack.y);
943 else if (ON_BOTTOM_BORDER(hittest))
945 mouseRect.top = max( mouseRect.top, sizingRect.top+minTrack.y );
946 mouseRect.bottom = min( mouseRect.bottom, sizingRect.top+maxTrack.y );
948 SendMessage( hwnd, WM_ENTERSIZEMOVE, 0, 0 );
950 if (GetCapture() != hwnd) SetCapture( hwnd );
952 if (wndPtr->dwStyle & WS_CHILD)
954 /* Retrieve a default cache DC (without using the window style) */
955 hdc = GetDCEx( wndPtr->hwndParent, 0, DCX_CACHE );
957 else
958 { /* Grab the server only when moving top-level windows without desktop */
959 hdc = GetDC( 0 );
960 if (rootWindow == DefaultRootWindow(display)) XGrabServer( display );
962 NC_DrawMovingFrame( hdc, &sizingRect, thickframe );
964 while(1)
966 int dx = 0, dy = 0;
968 MSG_GetHardwareMessage( &msg );
970 /* Exit on button-up, Return, or Esc */
971 if ((msg.message == WM_LBUTTONUP) ||
972 ((msg.message == WM_KEYDOWN) &&
973 ((msg.wParam == VK_RETURN) || (msg.wParam == VK_ESCAPE)))) break;
975 if ((msg.message != WM_KEYDOWN) && (msg.message != WM_MOUSEMOVE))
976 continue; /* We are not interested in other messages */
978 pt = msg.pt;
979 if (wndPtr->dwStyle & WS_CHILD)
980 ScreenToClient( wndPtr->hwndParent, &pt );
983 if (msg.message == WM_KEYDOWN) switch(msg.wParam)
985 case VK_UP: pt.y -= 8; break;
986 case VK_DOWN: pt.y += 8; break;
987 case VK_LEFT: pt.x -= 8; break;
988 case VK_RIGHT: pt.x += 8; break;
991 pt.x = max( pt.x, mouseRect.left );
992 pt.x = min( pt.x, mouseRect.right );
993 pt.y = max( pt.y, mouseRect.top );
994 pt.y = min( pt.y, mouseRect.bottom );
996 dx = pt.x - capturePoint.x;
997 dy = pt.y - capturePoint.y;
999 if (dx || dy)
1001 if (msg.message == WM_KEYDOWN) SetCursorPos( pt.x, pt.y );
1002 else
1004 RECT newRect = sizingRect;
1006 if (hittest == HTCAPTION) OffsetRect( &newRect, dx, dy );
1007 if (ON_LEFT_BORDER(hittest)) newRect.left += dx;
1008 else if (ON_RIGHT_BORDER(hittest)) newRect.right += dx;
1009 if (ON_TOP_BORDER(hittest)) newRect.top += dy;
1010 else if (ON_BOTTOM_BORDER(hittest)) newRect.bottom += dy;
1011 NC_DrawMovingFrame( hdc, &sizingRect, thickframe );
1012 NC_DrawMovingFrame( hdc, &newRect, thickframe );
1013 capturePoint = pt;
1014 sizingRect = newRect;
1019 NC_DrawMovingFrame( hdc, &sizingRect, thickframe );
1020 ReleaseCapture();
1021 if (wndPtr->dwStyle & WS_CHILD) ReleaseDC( wndPtr->hwndParent, hdc );
1022 else
1024 ReleaseDC( 0, hdc );
1025 if (rootWindow == DefaultRootWindow(display)) XUngrabServer( display );
1027 SendMessage( hwnd, WM_EXITSIZEMOVE, 0, 0 );
1029 /* If Esc key, don't move the window */
1030 if ((msg.message == WM_KEYDOWN) && (msg.wParam == VK_ESCAPE)) return;
1032 if (hittest != HTCAPTION)
1033 SetWindowPos( hwnd, 0, sizingRect.left, sizingRect.top,
1034 sizingRect.right - sizingRect.left,
1035 sizingRect.bottom - sizingRect.top,
1036 SWP_NOACTIVATE | SWP_NOZORDER );
1037 else SetWindowPos( hwnd, 0, sizingRect.left, sizingRect.top, 0, 0,
1038 SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER );
1042 /***********************************************************************
1043 * NC_TrackMinMaxBox
1045 * Track a mouse button press on the minimize or maximize box.
1047 static void NC_TrackMinMaxBox( HWND hwnd, WORD wParam )
1049 MSG msg;
1050 HDC hdc = GetWindowDC( hwnd );
1051 BOOL pressed = TRUE;
1053 SetCapture( hwnd );
1054 if (wParam == HTMINBUTTON) NC_DrawMinButton( hwnd, hdc, TRUE );
1055 else NC_DrawMaxButton( hwnd, hdc, TRUE );
1059 BOOL oldstate = pressed;
1060 MSG_GetHardwareMessage( &msg );
1062 pressed = (NC_HandleNCHitTest( hwnd, msg.pt ) == wParam);
1063 if (pressed != oldstate)
1065 if (wParam == HTMINBUTTON) NC_DrawMinButton( hwnd, hdc, pressed );
1066 else NC_DrawMaxButton( hwnd, hdc, pressed );
1068 } while (msg.message != WM_LBUTTONUP);
1070 if (wParam == HTMINBUTTON) NC_DrawMinButton( hwnd, hdc, FALSE );
1071 else NC_DrawMaxButton( hwnd, hdc, FALSE );
1073 ReleaseCapture();
1074 ReleaseDC( hwnd, hdc );
1075 if (!pressed) return;
1077 if (wParam == HTMINBUTTON)
1078 SendMessage( hwnd, WM_SYSCOMMAND, SC_MINIMIZE, *(LONG*)&msg.pt );
1079 else
1080 SendMessage( hwnd, WM_SYSCOMMAND,
1081 IsZoomed(hwnd) ? SC_RESTORE : SC_MAXIMIZE, *(LONG*)&msg.pt );
1085 /***********************************************************************
1086 * NC_TrackScrollBar
1088 * Track a mouse button press on the horizontal or vertical scroll-bar.
1090 static void NC_TrackScrollBar( HWND hwnd, WORD wParam, POINT pt )
1092 MSG *msg;
1093 HLOCAL hMsg;
1094 WORD scrollbar;
1095 WND *wndPtr = WIN_FindWndPtr( hwnd );
1097 if ((wParam & 0xfff0) == SC_HSCROLL)
1099 if ((wParam & 0x0f) != HTHSCROLL) return;
1100 scrollbar = SB_HORZ;
1102 else /* SC_VSCROLL */
1104 if ((wParam & 0x0f) != HTVSCROLL) return;
1105 scrollbar = SB_VERT;
1108 hMsg = USER_HEAP_ALLOC( sizeof(MSG) );
1109 msg = (MSG *) USER_HEAP_LIN_ADDR( hMsg );
1110 pt.x -= wndPtr->rectWindow.left;
1111 pt.y -= wndPtr->rectWindow.top;
1112 SetCapture( hwnd );
1113 SCROLL_HandleScrollEvent( hwnd, scrollbar, WM_LBUTTONDOWN, pt );
1117 GetMessage( USER_HEAP_SEG_ADDR(hMsg), 0, 0, 0 );
1118 switch(msg->message)
1120 case WM_LBUTTONUP:
1121 case WM_MOUSEMOVE:
1122 case WM_SYSTIMER:
1123 pt = MAKEPOINT(msg->lParam);
1124 pt.x += wndPtr->rectClient.left - wndPtr->rectWindow.left;
1125 pt.y += wndPtr->rectClient.top - wndPtr->rectWindow.top;
1126 SCROLL_HandleScrollEvent( hwnd, scrollbar, msg->message, pt );
1127 break;
1128 default:
1129 TranslateMessage( msg );
1130 DispatchMessage( msg );
1131 break;
1133 if (!IsWindow( hwnd ))
1135 ReleaseCapture();
1136 break;
1138 } while (msg->message != WM_LBUTTONUP);
1139 USER_HEAP_FREE( hMsg );
1142 /***********************************************************************
1143 * NC_TrackSysMenu
1145 * Track a mouse button press on the system menu.
1147 static void NC_TrackSysMenu( HWND hwnd, HDC hdc, POINT pt )
1149 RECT rect;
1150 WND *wndPtr = WIN_FindWndPtr( hwnd );
1152 if (!(wndPtr->dwStyle & WS_SYSMENU)) return;
1153 /* If window has a menu, track the menu bar normally */
1154 if (HAS_MENU(wndPtr)) MENU_TrackMouseMenuBar( hwnd, pt );
1155 else
1157 /* Otherwise track the system menu like a normal popup menu */
1158 NC_GetInsideRect( hwnd, &rect );
1159 OffsetRect( &rect, wndPtr->rectWindow.left, wndPtr->rectWindow.top );
1160 if (wndPtr->dwStyle & WS_CHILD)
1161 ClientToScreen( wndPtr->hwndParent, (POINT *)&rect );
1162 rect.right = rect.left + SYSMETRICS_CXSIZE;
1163 rect.bottom = rect.top + SYSMETRICS_CYSIZE;
1164 NC_DrawSysButton( hwnd, hdc, TRUE );
1165 TrackPopupMenu( wndPtr->hSysMenu, TPM_LEFTALIGN | TPM_LEFTBUTTON,
1166 rect.left, rect.bottom, 0, hwnd, &rect );
1167 NC_DrawSysButton( hwnd, hdc, FALSE );
1172 /***********************************************************************
1173 * NC_HandleNCLButtonDown
1175 * Handle a WM_NCLBUTTONDOWN message. Called from DefWindowProc().
1177 LONG NC_HandleNCLButtonDown( HWND hwnd, WORD wParam, LONG lParam )
1179 HDC hdc = GetWindowDC( hwnd );
1181 switch(wParam) /* Hit test */
1183 case HTCAPTION:
1184 SendMessage( hwnd, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, lParam );
1185 break;
1187 case HTSYSMENU:
1188 NC_TrackSysMenu( hwnd, hdc, MAKEPOINT(lParam) );
1189 break;
1191 case HTMENU:
1192 SendMessage( hwnd, WM_SYSCOMMAND, SC_MOUSEMENU, lParam );
1193 break;
1195 case HTHSCROLL:
1196 SendMessage( hwnd, WM_SYSCOMMAND, SC_HSCROLL + HTHSCROLL, lParam );
1197 break;
1199 case HTVSCROLL:
1200 SendMessage( hwnd, WM_SYSCOMMAND, SC_VSCROLL + HTVSCROLL, lParam );
1201 break;
1203 case HTMINBUTTON:
1204 case HTMAXBUTTON:
1205 NC_TrackMinMaxBox( hwnd, wParam );
1206 break;
1208 case HTLEFT:
1209 case HTRIGHT:
1210 case HTTOP:
1211 case HTTOPLEFT:
1212 case HTTOPRIGHT:
1213 case HTBOTTOM:
1214 case HTBOTTOMLEFT:
1215 case HTBOTTOMRIGHT:
1216 SendMessage( hwnd, WM_SYSCOMMAND, SC_SIZE + wParam - HTLEFT+1, lParam);
1217 break;
1219 case HTBORDER:
1220 break;
1223 ReleaseDC( hwnd, hdc );
1224 return 0;
1228 /***********************************************************************
1229 * NC_HandleNCLButtonDblClk
1231 * Handle a WM_NCLBUTTONDBLCLK message. Called from DefWindowProc().
1233 LONG NC_HandleNCLButtonDblClk( HWND hwnd, WORD wParam, LONG lParam )
1236 * if this is an icon, send a restore since we are handling
1237 * a double click
1239 if (IsIconic(hwnd))
1241 SendMessage(hwnd, WM_SYSCOMMAND, SC_RESTORE, lParam);
1242 return 0;
1245 switch(wParam) /* Hit test */
1247 case HTCAPTION:
1248 SendMessage( hwnd, WM_SYSCOMMAND,
1249 IsZoomed(hwnd) ? SC_RESTORE : SC_MAXIMIZE, lParam );
1250 break;
1252 case HTSYSMENU:
1253 SendMessage( hwnd, WM_SYSCOMMAND, SC_CLOSE, lParam );
1254 break;
1256 return 0;
1260 /***********************************************************************
1261 * NC_HandleSysCommand
1263 * Handle a WM_SYSCOMMAND message. Called from DefWindowProc().
1265 LONG NC_HandleSysCommand( HWND hwnd, WORD wParam, POINT pt )
1267 WND *wndPtr = WIN_FindWndPtr( hwnd );
1269 dprintf_nonclient(stddeb, "Handling WM_SYSCOMMAND %x %d,%d\n",
1270 wParam, pt.x, pt.y );
1272 if (wndPtr->dwStyle & WS_CHILD) ScreenToClient( wndPtr->hwndParent, &pt );
1274 switch (wParam & 0xfff0)
1276 case SC_SIZE:
1277 case SC_MOVE:
1278 NC_DoSizeMove( hwnd, wParam, pt );
1279 break;
1281 case SC_MINIMIZE:
1282 ShowWindow( hwnd, SW_MINIMIZE );
1283 break;
1285 case SC_MAXIMIZE:
1286 ShowWindow( hwnd, SW_MAXIMIZE );
1287 break;
1289 case SC_RESTORE:
1290 ShowWindow( hwnd, SW_RESTORE );
1291 break;
1293 case SC_NEXTWINDOW:
1294 case SC_PREVWINDOW:
1295 break;
1297 case SC_CLOSE:
1298 return SendMessage( hwnd, WM_CLOSE, 0, 0 );
1300 case SC_VSCROLL:
1301 case SC_HSCROLL:
1302 NC_TrackScrollBar( hwnd, wParam, pt );
1303 break;
1305 case SC_MOUSEMENU:
1306 MENU_TrackMouseMenuBar( hwnd, pt );
1307 break;
1309 case SC_KEYMENU:
1310 MENU_TrackKbdMenuBar( hwnd, wParam );
1311 break;
1313 case SC_ARRANGE:
1314 break;
1316 case SC_TASKLIST:
1317 WinExec( "taskman.exe", SW_SHOWNORMAL );
1318 break;
1320 case SC_HOTKEY:
1321 break;
1323 case SC_SCREENSAVE:
1324 if (wParam == SC_ABOUTWINE)
1326 extern const char people[];
1327 ShellAbout(hwnd,"WINE",people,0);
1329 break;
1331 return 0;