Release 960331
[wine.git] / windows / nonclient.c
blobc94ca9c573ea255df35530873f391c0331c667b9
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 "queue.h"
22 #include "selectors.h"
23 #include "stackframe.h"
24 #include "stddebug.h"
25 /* #define DEBUG_NONCLIENT */
26 #include "debug.h"
27 #include "options.h"
30 static HBITMAP hbitmapClose = 0;
31 static HBITMAP hbitmapMinimize = 0;
32 static HBITMAP hbitmapMinimizeD = 0;
33 static HBITMAP hbitmapMaximize = 0;
34 static HBITMAP hbitmapMaximizeD = 0;
35 static HBITMAP hbitmapRestore = 0;
36 static HBITMAP hbitmapRestoreD = 0;
38 #define SC_ABOUTWINE (SC_SCREENSAVE+1)
40 /* Some useful macros */
41 #define HAS_DLGFRAME(style,exStyle) \
42 (((exStyle) & WS_EX_DLGMODALFRAME) || \
43 (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
45 #define HAS_THICKFRAME(style) \
46 (((style) & WS_THICKFRAME) && \
47 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
49 #define HAS_MENU(w) (!((w)->dwStyle & WS_CHILD) && ((w)->wIDmenu != 0))
51 #define ON_LEFT_BORDER(hit) \
52 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
53 #define ON_RIGHT_BORDER(hit) \
54 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
55 #define ON_TOP_BORDER(hit) \
56 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
57 #define ON_BOTTOM_BORDER(hit) \
58 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
60 /***********************************************************************
61 * NC_AdjustRect
63 * Compute the size of the window rectangle from the size of the
64 * client rectangle.
66 static void NC_AdjustRect( LPRECT rect, DWORD style, BOOL menu, DWORD exStyle )
68 if (style & WS_ICONIC) return; /* Nothing to change for an icon */
70 /* Decide if the window will be managed (see CreateWindowEx) */
71 if (!(Options.managed && ((style & (WS_DLGFRAME | WS_THICKFRAME)) ||
72 (exStyle & WS_EX_DLGMODALFRAME))))
74 if (HAS_DLGFRAME( style, exStyle ))
75 InflateRect( rect, SYSMETRICS_CXDLGFRAME, SYSMETRICS_CYDLGFRAME );
76 else
78 if (HAS_THICKFRAME(style))
79 InflateRect( rect, SYSMETRICS_CXFRAME, SYSMETRICS_CYFRAME );
80 if (style & WS_BORDER)
81 InflateRect( rect, SYSMETRICS_CXBORDER, SYSMETRICS_CYBORDER );
84 if ((style & WS_CAPTION) == WS_CAPTION)
85 rect->top -= SYSMETRICS_CYCAPTION - SYSMETRICS_CYBORDER;
87 if (menu) rect->top -= SYSMETRICS_CYMENU + SYSMETRICS_CYBORDER;
89 if (style & WS_VSCROLL) rect->right += SYSMETRICS_CXVSCROLL;
90 if (style & WS_HSCROLL) rect->bottom += SYSMETRICS_CYHSCROLL;
94 /***********************************************************************
95 * AdjustWindowRect (USER.102)
97 BOOL AdjustWindowRect( LPRECT rect, DWORD style, BOOL menu )
99 return AdjustWindowRectEx( rect, style, menu, 0 );
103 /***********************************************************************
104 * AdjustWindowRectEx (USER.454)
106 BOOL AdjustWindowRectEx( LPRECT rect, DWORD style, BOOL menu, DWORD exStyle )
108 /* Correct the window style */
110 if (!(style & (WS_POPUP | WS_CHILD))) /* Overlapped window */
111 style |= WS_CAPTION;
112 if (exStyle & WS_EX_DLGMODALFRAME) style &= ~WS_THICKFRAME;
114 dprintf_nonclient(stddeb, "AdjustWindowRectEx: (%d,%d)-(%d,%d) %08lx %d %08lx\n",
115 rect->left, rect->top, rect->right, rect->bottom,
116 style, menu, exStyle );
118 NC_AdjustRect( rect, style, menu, exStyle );
119 return TRUE;
123 /*******************************************************************
124 * NC_GetMinMaxInfo
126 * Get the minimized and maximized information for a window.
128 void NC_GetMinMaxInfo( HWND hwnd, POINT *maxSize, POINT *maxPos,
129 POINT *minTrack, POINT *maxTrack )
131 MINMAXINFO MinMax;
132 short xinc, yinc;
133 WND *wndPtr = WIN_FindWndPtr( hwnd );
135 /* Compute default values */
137 MinMax.ptMaxSize.x = SYSMETRICS_CXSCREEN;
138 MinMax.ptMaxSize.y = SYSMETRICS_CYSCREEN;
139 MinMax.ptMinTrackSize.x = SYSMETRICS_CXMINTRACK;
140 MinMax.ptMinTrackSize.y = SYSMETRICS_CYMINTRACK;
141 MinMax.ptMaxTrackSize.x = SYSMETRICS_CXSCREEN;
142 MinMax.ptMaxTrackSize.y = SYSMETRICS_CYSCREEN;
144 if (wndPtr->flags & WIN_MANAGED) xinc = yinc = 0;
145 else if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
147 xinc = SYSMETRICS_CXDLGFRAME;
148 yinc = SYSMETRICS_CYDLGFRAME;
150 else
152 xinc = yinc = 0;
153 if (HAS_THICKFRAME(wndPtr->dwStyle))
155 xinc += SYSMETRICS_CXFRAME;
156 yinc += SYSMETRICS_CYFRAME;
158 if (wndPtr->dwStyle & WS_BORDER)
160 xinc += SYSMETRICS_CXBORDER;
161 yinc += SYSMETRICS_CYBORDER;
164 MinMax.ptMaxSize.x += 2 * xinc;
165 MinMax.ptMaxSize.y += 2 * yinc;
167 /* Note: The '+' in the following test should really be a ||, but
168 * that would cause gcc-2.7.0 to generate incorrect code.
170 if ((wndPtr->ptMaxPos.x != -1) + (wndPtr->ptMaxPos.y != -1))
171 MinMax.ptMaxPosition = wndPtr->ptMaxPos;
172 else
174 MinMax.ptMaxPosition.x = -xinc;
175 MinMax.ptMaxPosition.y = -yinc;
178 SendMessage( hwnd, WM_GETMINMAXINFO, 0, (LPARAM)MAKE_SEGPTR(&MinMax) );
180 /* Some sanity checks */
182 dprintf_nonclient(stddeb,
183 "NC_GetMinMaxInfo: %d %d / %d %d / %d %d / %d %d\n",
184 (int)MinMax.ptMaxSize.x,(int)MinMax.ptMaxSize.y,
185 (int)MinMax.ptMaxPosition.x,(int)MinMax.ptMaxPosition.y,
186 (int)MinMax.ptMaxTrackSize.x,(int)MinMax.ptMaxTrackSize.y,
187 (int)MinMax.ptMinTrackSize.x,(int)MinMax.ptMinTrackSize.y);
188 MinMax.ptMaxTrackSize.x = MAX( MinMax.ptMaxTrackSize.x,
189 MinMax.ptMinTrackSize.x );
190 MinMax.ptMaxTrackSize.y = MAX( MinMax.ptMaxTrackSize.y,
191 MinMax.ptMinTrackSize.y );
193 if (maxSize) *maxSize = MinMax.ptMaxSize;
194 if (maxPos) *maxPos = MinMax.ptMaxPosition;
195 if (minTrack) *minTrack = MinMax.ptMinTrackSize;
196 if (maxTrack) *maxTrack = MinMax.ptMaxTrackSize;
200 /***********************************************************************
201 * NC_HandleNCCalcSize
203 * Handle a WM_NCCALCSIZE message. Called from DefWindowProc().
205 LONG NC_HandleNCCalcSize( HWND hwnd, NCCALCSIZE_PARAMS *params )
207 RECT tmpRect = { 0, 0, 0, 0 };
208 WND *wndPtr = WIN_FindWndPtr( hwnd );
210 if (!wndPtr) return 0;
211 NC_AdjustRect( &tmpRect, wndPtr->dwStyle, FALSE, wndPtr->dwExStyle );
212 params->rgrc[0].left -= tmpRect.left;
213 params->rgrc[0].top -= tmpRect.top;
214 params->rgrc[0].right -= tmpRect.right;
215 params->rgrc[0].bottom -= tmpRect.bottom;
217 if (HAS_MENU(wndPtr))
219 params->rgrc[0].top += MENU_GetMenuBarHeight( hwnd,
220 params->rgrc[0].right - params->rgrc[0].left,
221 -tmpRect.left, -tmpRect.top ) + 1;
223 return 0;
227 /***********************************************************************
228 * NC_GetInsideRect
230 * Get the 'inside' rectangle of a window, i.e. the whole window rectangle
231 * but without the borders (if any).
232 * The rectangle is in window coordinates (for drawing with GetWindowDC()).
234 void NC_GetInsideRect( HWND hwnd, RECT *rect )
236 WND * wndPtr = WIN_FindWndPtr( hwnd );
238 rect->top = rect->left = 0;
239 rect->right = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
240 rect->bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
242 if (wndPtr->dwStyle & WS_ICONIC) return; /* No border to remove */
243 if (wndPtr->flags & WIN_MANAGED) return;
245 /* Remove frame from rectangle */
246 if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
248 InflateRect( rect, -SYSMETRICS_CXDLGFRAME, -SYSMETRICS_CYDLGFRAME);
249 if (wndPtr->dwExStyle & WS_EX_DLGMODALFRAME) InflateRect( rect, -1, 0);
251 else
253 if (HAS_THICKFRAME( wndPtr->dwStyle ))
254 InflateRect( rect, -SYSMETRICS_CXFRAME, -SYSMETRICS_CYFRAME );
255 if (wndPtr->dwStyle & WS_BORDER)
256 InflateRect( rect, -SYSMETRICS_CXBORDER, -SYSMETRICS_CYBORDER );
261 /***********************************************************************
262 * NC_HandleNCHitTest
264 * Handle a WM_NCHITTEST message. Called from DefWindowProc().
266 LONG NC_HandleNCHitTest( HWND hwnd, POINT pt )
268 RECT rect;
269 WND *wndPtr = WIN_FindWndPtr( hwnd );
270 if (!wndPtr) return HTERROR;
272 dprintf_nonclient(stddeb, "NC_HandleNCHitTest: hwnd=%04x pt=%d,%d\n",
273 hwnd, pt.x, pt.y );
275 GetWindowRect( hwnd, &rect );
276 if (!PtInRect( &rect, pt )) return HTNOWHERE;
278 if (wndPtr->dwStyle & WS_MINIMIZE) return HTCAPTION;
280 if (!(wndPtr->flags & WIN_MANAGED))
282 /* Check borders */
283 if (HAS_THICKFRAME( wndPtr->dwStyle ))
285 InflateRect( &rect, -SYSMETRICS_CXFRAME, -SYSMETRICS_CYFRAME );
286 if (wndPtr->dwStyle & WS_BORDER)
287 InflateRect(&rect, -SYSMETRICS_CXBORDER, -SYSMETRICS_CYBORDER);
288 if (!PtInRect( &rect, pt ))
290 /* Check top sizing border */
291 if (pt.y < rect.top)
293 if (pt.x < rect.left+SYSMETRICS_CXSIZE) return HTTOPLEFT;
294 if (pt.x >= rect.right-SYSMETRICS_CXSIZE) return HTTOPRIGHT;
295 return HTTOP;
297 /* Check bottom sizing border */
298 if (pt.y >= rect.bottom)
300 if (pt.x < rect.left+SYSMETRICS_CXSIZE) return HTBOTTOMLEFT;
301 if (pt.x >= rect.right-SYSMETRICS_CXSIZE) return HTBOTTOMRIGHT;
302 return HTBOTTOM;
304 /* Check left sizing border */
305 if (pt.x < rect.left)
307 if (pt.y < rect.top+SYSMETRICS_CYSIZE) return HTTOPLEFT;
308 if (pt.y >= rect.bottom-SYSMETRICS_CYSIZE) return HTBOTTOMLEFT;
309 return HTLEFT;
311 /* Check right sizing border */
312 if (pt.x >= rect.right)
314 if (pt.y < rect.top+SYSMETRICS_CYSIZE) return HTTOPRIGHT;
315 if (pt.y >= rect.bottom-SYSMETRICS_CYSIZE) return HTBOTTOMRIGHT;
316 return HTRIGHT;
320 else /* No thick frame */
322 if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
323 InflateRect(&rect, -SYSMETRICS_CXDLGFRAME, -SYSMETRICS_CYDLGFRAME);
324 else if (wndPtr->dwStyle & WS_BORDER)
325 InflateRect(&rect, -SYSMETRICS_CXBORDER, -SYSMETRICS_CYBORDER);
326 if (!PtInRect( &rect, pt )) return HTBORDER;
329 /* Check caption */
331 if ((wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION)
333 rect.top += SYSMETRICS_CYCAPTION - 1;
334 if (!PtInRect( &rect, pt ))
336 /* Check system menu */
337 if (wndPtr->dwStyle & WS_SYSMENU)
338 rect.left += SYSMETRICS_CXSIZE;
339 if (pt.x <= rect.left) return HTSYSMENU;
340 /* Check maximize box */
341 if (wndPtr->dwStyle & WS_MAXIMIZEBOX)
342 rect.right -= SYSMETRICS_CXSIZE + 1;
343 if (pt.x >= rect.right) return HTMAXBUTTON;
344 /* Check minimize box */
345 if (wndPtr->dwStyle & WS_MINIMIZEBOX)
346 rect.right -= SYSMETRICS_CXSIZE + 1;
347 if (pt.x >= rect.right) return HTMINBUTTON;
348 return HTCAPTION;
353 /* Check client area */
355 ScreenToClient( hwnd, &pt );
356 GetClientRect( hwnd, &rect );
357 if (PtInRect( &rect, pt )) return HTCLIENT;
359 /* Check vertical scroll bar */
361 if (wndPtr->dwStyle & WS_VSCROLL)
363 rect.right += SYSMETRICS_CXVSCROLL;
364 if (PtInRect( &rect, pt )) return HTVSCROLL;
367 /* Check horizontal scroll bar */
369 if (wndPtr->dwStyle & WS_HSCROLL)
371 rect.bottom += SYSMETRICS_CYHSCROLL;
372 if (PtInRect( &rect, pt ))
374 /* Check size box */
375 if ((wndPtr->dwStyle & WS_VSCROLL) &&
376 (pt.x >= rect.right - SYSMETRICS_CXVSCROLL))
377 return HTSIZE;
378 return HTHSCROLL;
382 /* Check menu bar */
384 if (HAS_MENU(wndPtr))
386 if ((pt.y < 0) && (pt.x >= 0) && (pt.x < rect.right))
387 return HTMENU;
390 /* Should never get here */
391 return HTERROR;
395 /***********************************************************************
396 * NC_DrawSysButton
398 void NC_DrawSysButton( HWND hwnd, HDC hdc, BOOL down )
400 RECT rect;
401 HDC hdcMem;
402 HBITMAP hbitmap;
403 WND *wndPtr = WIN_FindWndPtr( hwnd );
405 NC_GetInsideRect( hwnd, &rect );
406 hdcMem = CreateCompatibleDC( hdc );
407 hbitmap = SelectObject( hdcMem, hbitmapClose );
408 BitBlt( hdc, rect.left, rect.top, SYSMETRICS_CXSIZE, SYSMETRICS_CYSIZE,
409 hdcMem, (wndPtr->dwStyle & WS_CHILD) ? SYSMETRICS_CXSIZE : 0, 0,
410 down ? NOTSRCCOPY : SRCCOPY );
411 SelectObject( hdcMem, hbitmap );
412 DeleteDC( hdcMem );
416 /***********************************************************************
417 * NC_DrawMaxButton
419 static void NC_DrawMaxButton( HWND hwnd, HDC hdc, BOOL down )
421 RECT rect;
422 NC_GetInsideRect( hwnd, &rect );
423 GRAPH_DrawBitmap( hdc, (IsZoomed(hwnd) ?
424 (down ? hbitmapRestoreD : hbitmapRestore) :
425 (down ? hbitmapMaximizeD : hbitmapMaximize)),
426 rect.right - SYSMETRICS_CXSIZE - 1, rect.top,
427 0, 0, SYSMETRICS_CXSIZE+1, SYSMETRICS_CYSIZE );
431 /***********************************************************************
432 * NC_DrawMinButton
434 static void NC_DrawMinButton( HWND hwnd, HDC hdc, BOOL down )
436 RECT rect;
437 WND *wndPtr = WIN_FindWndPtr( hwnd );
438 NC_GetInsideRect( hwnd, &rect );
439 if (wndPtr->dwStyle & WS_MAXIMIZEBOX) rect.right -= SYSMETRICS_CXSIZE + 1;
440 GRAPH_DrawBitmap( hdc, (down ? hbitmapMinimizeD : hbitmapMinimize),
441 rect.right - SYSMETRICS_CXSIZE - 1, rect.top,
442 0, 0, SYSMETRICS_CXSIZE+1, SYSMETRICS_CYSIZE );
446 /***********************************************************************
447 * NC_DrawFrame
449 * Draw a window frame inside the given rectangle, and update the rectangle.
450 * The correct pen for the frame must be selected in the DC.
452 static void NC_DrawFrame( HDC hdc, RECT *rect, BOOL dlgFrame, BOOL active )
454 short width, height, tmp;
456 if (dlgFrame)
458 width = SYSMETRICS_CXDLGFRAME - 1;
459 height = SYSMETRICS_CYDLGFRAME - 1;
460 SelectObject( hdc, active ? sysColorObjects.hbrushActiveCaption :
461 sysColorObjects.hbrushInactiveCaption );
463 else
465 width = SYSMETRICS_CXFRAME - 1;
466 height = SYSMETRICS_CYFRAME - 1;
467 SelectObject( hdc, active ? sysColorObjects.hbrushActiveBorder :
468 sysColorObjects.hbrushInactiveBorder );
471 /* Draw frame */
472 PatBlt( hdc, rect->left, rect->top,
473 rect->right - rect->left, height, PATCOPY );
474 PatBlt( hdc, rect->left, rect->top,
475 width, rect->bottom - rect->top, PATCOPY );
476 PatBlt( hdc, rect->left, rect->bottom,
477 rect->right - rect->left, -height, PATCOPY );
478 PatBlt( hdc, rect->right, rect->top,
479 -width, rect->bottom - rect->top, PATCOPY );
481 if (dlgFrame)
483 InflateRect( rect, -width, -height );
484 return;
487 /* Draw inner rectangle */
488 MoveTo( hdc, rect->left+width, rect->top+height );
489 LineTo( hdc, rect->right-width-1, rect->top+height );
490 LineTo( hdc, rect->right-width-1, rect->bottom-height-1 );
491 LineTo( hdc, rect->left+width, rect->bottom-height-1 );
492 LineTo( hdc, rect->left+width, rect->top+height );
494 /* Draw the decorations */
495 tmp = rect->top + SYSMETRICS_CYFRAME + SYSMETRICS_CYSIZE;
496 MoveTo( hdc, rect->left, tmp);
497 LineTo( hdc, rect->left+width, tmp );
498 MoveTo( hdc, rect->right-width-1, tmp );
499 LineTo( hdc, rect->right-1, tmp );
501 tmp = rect->bottom - 1 - SYSMETRICS_CYFRAME - SYSMETRICS_CYSIZE;
502 MoveTo( hdc, rect->left, tmp );
503 LineTo( hdc, rect->left+width, tmp );
504 MoveTo( hdc, rect->right-width-1, tmp );
505 LineTo( hdc, rect->right-1, tmp );
507 tmp = rect->left + SYSMETRICS_CXFRAME + SYSMETRICS_CXSIZE;
508 MoveTo( hdc, tmp, rect->top );
509 LineTo( hdc, tmp, rect->top+height );
510 MoveTo( hdc, tmp, rect->bottom-height-1 );
511 LineTo( hdc, tmp, rect->bottom-1 );
513 tmp = rect->right - 1 - SYSMETRICS_CXFRAME - SYSMETRICS_CYSIZE;
514 MoveTo( hdc, tmp, rect->top );
515 LineTo( hdc, tmp, rect->top+height );
516 MoveTo( hdc, tmp, rect->bottom-height-1 );
517 LineTo( hdc, tmp, rect->bottom-1 );
519 InflateRect( rect, -width-1, -height-1 );
523 /***********************************************************************
524 * NC_DrawMovingFrame
526 * Draw the frame used when moving or resizing window.
528 static void NC_DrawMovingFrame( HDC hdc, RECT *rect, BOOL thickframe )
530 if (thickframe)
532 SelectObject( hdc, GetStockObject( GRAY_BRUSH ) );
533 PatBlt( hdc, rect->left, rect->top,
534 rect->right - rect->left - SYSMETRICS_CXFRAME,
535 SYSMETRICS_CYFRAME, PATINVERT );
536 PatBlt( hdc, rect->left, rect->top + SYSMETRICS_CYFRAME,
537 SYSMETRICS_CXFRAME,
538 rect->bottom - rect->top - SYSMETRICS_CYFRAME, PATINVERT );
539 PatBlt( hdc, rect->left + SYSMETRICS_CXFRAME, rect->bottom,
540 rect->right - rect->left - SYSMETRICS_CXFRAME,
541 -SYSMETRICS_CYFRAME, PATINVERT );
542 PatBlt( hdc, rect->right, rect->top, -SYSMETRICS_CXFRAME,
543 rect->bottom - rect->top - SYSMETRICS_CYFRAME, PATINVERT );
545 else DrawFocusRect( hdc, rect );
549 /***********************************************************************
550 * NC_DrawCaption
552 * Draw the window caption.
553 * The correct pen for the window frame must be selected in the DC.
555 static void NC_DrawCaption( HDC hdc, RECT *rect, HWND hwnd,
556 DWORD style, BOOL active )
558 RECT r = *rect;
559 WND * wndPtr = WIN_FindWndPtr( hwnd );
560 char buffer[256];
562 if (!hbitmapClose)
564 if (!(hbitmapClose = LoadBitmap( 0, MAKEINTRESOURCE(OBM_CLOSE) )))
565 return;
566 hbitmapMinimize = LoadBitmap( 0, MAKEINTRESOURCE(OBM_REDUCE) );
567 hbitmapMinimizeD = LoadBitmap( 0, MAKEINTRESOURCE(OBM_REDUCED) );
568 hbitmapMaximize = LoadBitmap( 0, MAKEINTRESOURCE(OBM_ZOOM) );
569 hbitmapMaximizeD = LoadBitmap( 0, MAKEINTRESOURCE(OBM_ZOOMD) );
570 hbitmapRestore = LoadBitmap( 0, MAKEINTRESOURCE(OBM_RESTORE) );
571 hbitmapRestoreD = LoadBitmap( 0, MAKEINTRESOURCE(OBM_RESTORED) );
574 if (wndPtr->dwExStyle & WS_EX_DLGMODALFRAME)
576 HBRUSH hbrushOld = SelectObject( hdc, sysColorObjects.hbrushWindow );
577 PatBlt( hdc, r.left, r.top, 1, r.bottom-r.top+1,PATCOPY );
578 PatBlt( hdc, r.right-1, r.top, 1, r.bottom-r.top+1, PATCOPY );
579 PatBlt( hdc, r.left, r.top-1, r.right-r.left, 1, PATCOPY );
580 r.left++;
581 r.right--;
582 SelectObject( hdc, hbrushOld );
585 MoveTo( hdc, r.left, r.bottom );
586 LineTo( hdc, r.right-1, r.bottom );
588 if (style & WS_SYSMENU)
590 NC_DrawSysButton( hwnd, hdc, FALSE );
591 r.left += SYSMETRICS_CXSIZE + 1;
592 MoveTo( hdc, r.left - 1, r.top );
593 LineTo( hdc, r.left - 1, r.bottom );
595 if (style & WS_MAXIMIZEBOX)
597 NC_DrawMaxButton( hwnd, hdc, FALSE );
598 r.right -= SYSMETRICS_CXSIZE + 1;
600 if (style & WS_MINIMIZEBOX)
602 NC_DrawMinButton( hwnd, hdc, FALSE );
603 r.right -= SYSMETRICS_CXSIZE + 1;
606 FillRect( hdc, &r, active ? sysColorObjects.hbrushActiveCaption :
607 sysColorObjects.hbrushInactiveCaption );
609 if (GetWindowText( hwnd, buffer, 256 ))
611 if (active) SetTextColor( hdc, GetSysColor( COLOR_CAPTIONTEXT ) );
612 else SetTextColor( hdc, GetSysColor( COLOR_INACTIVECAPTIONTEXT ) );
613 SetBkMode( hdc, TRANSPARENT );
614 DrawText( hdc, buffer, -1, &r, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
619 /***********************************************************************
620 * NC_DoNCPaint
622 * Paint the non-client area. clip is currently unused.
624 void NC_DoNCPaint( HWND hwnd, HRGN clip, BOOL suppress_menupaint )
626 HDC hdc;
627 RECT rect;
628 BOOL active;
630 WND *wndPtr = WIN_FindWndPtr( hwnd );
632 if (!wndPtr || !(wndPtr->dwStyle & WS_VISIBLE)) return; /* Nothing to do */
634 active = wndPtr->flags & WIN_NCACTIVATED;
636 dprintf_nonclient(stddeb, "NC_DoNCPaint: %04x %d\n", hwnd, active );
638 if (!(hdc = GetDCEx( hwnd, 0, DCX_USESTYLE | DCX_WINDOW ))) return;
641 * If this is an icon, we don't want to do any more nonclient painting
642 * of the window manager.
643 * If there is a class icon to draw, draw it
645 if (IsIconic(hwnd))
647 HICON hIcon = WIN_CLASS_INFO(wndPtr).hIcon;
648 if (hIcon)
650 SendMessage(hwnd, WM_ICONERASEBKGND, (WPARAM)hdc, 0);
651 DrawIcon(hdc, 0, 0, hIcon);
653 ReleaseDC(hwnd, hdc);
654 wndPtr->flags &= ~WIN_INTERNAL_PAINT;
655 if( wndPtr->hrgnUpdate )
657 DeleteObject( wndPtr->hrgnUpdate );
658 QUEUE_DecPaintCount( wndPtr->hmemTaskQ );
659 wndPtr->hrgnUpdate = 0;
661 return;
664 if (ExcludeVisRect( hdc, wndPtr->rectClient.left-wndPtr->rectWindow.left,
665 wndPtr->rectClient.top-wndPtr->rectWindow.top,
666 wndPtr->rectClient.right-wndPtr->rectWindow.left,
667 wndPtr->rectClient.bottom-wndPtr->rectWindow.top )
668 == NULLREGION)
670 ReleaseDC( hwnd, hdc );
671 return;
674 rect.top = rect.left = 0;
675 rect.right = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
676 rect.bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
678 SelectObject( hdc, sysColorObjects.hpenWindowFrame );
680 if (!(wndPtr->flags & WIN_MANAGED))
682 if ((wndPtr->dwStyle & WS_BORDER) || (wndPtr->dwStyle & WS_DLGFRAME) ||
683 (wndPtr->dwExStyle & WS_EX_DLGMODALFRAME))
685 MoveTo( hdc, 0, 0 );
686 LineTo( hdc, rect.right-1, 0 );
687 LineTo( hdc, rect.right-1, rect.bottom-1 );
688 LineTo( hdc, 0, rect.bottom-1 );
689 LineTo( hdc, 0, 0 );
690 InflateRect( &rect, -1, -1 );
693 if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
694 NC_DrawFrame( hdc, &rect, TRUE, active );
695 else if (wndPtr->dwStyle & WS_THICKFRAME)
696 NC_DrawFrame(hdc, &rect, FALSE, active );
698 if ((wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION)
700 RECT r = rect;
701 r.bottom = rect.top + SYSMETRICS_CYSIZE;
702 rect.top += SYSMETRICS_CYSIZE + SYSMETRICS_CYBORDER;
703 NC_DrawCaption( hdc, &r, hwnd, wndPtr->dwStyle, active );
707 if (HAS_MENU(wndPtr))
709 RECT r = rect;
710 r.bottom = rect.top + SYSMETRICS_CYMENU; /* default height */
711 rect.top += MENU_DrawMenuBar( hdc, &r, hwnd, suppress_menupaint );
714 /* Draw the scroll-bars */
716 if (wndPtr->dwStyle & WS_VSCROLL) SCROLL_DrawScrollBar(hwnd, hdc, SB_VERT);
717 if (wndPtr->dwStyle & WS_HSCROLL) SCROLL_DrawScrollBar(hwnd, hdc, SB_HORZ);
719 /* Draw the "size-box" */
721 if ((wndPtr->dwStyle & WS_VSCROLL) && (wndPtr->dwStyle & WS_HSCROLL))
723 RECT r = rect;
724 r.left = r.right - SYSMETRICS_CXVSCROLL + 1;
725 r.top = r.bottom - SYSMETRICS_CYHSCROLL + 1;
726 FillRect( hdc, &r, sysColorObjects.hbrushScrollbar );
729 ReleaseDC( hwnd, hdc );
734 /***********************************************************************
735 * NC_HandleNCPaint
737 * Handle a WM_NCPAINT message. Called from DefWindowProc().
739 LONG NC_HandleNCPaint( HWND hwnd , HRGN clip)
741 NC_DoNCPaint( hwnd, clip, FALSE );
742 return 0;
746 /***********************************************************************
747 * NC_HandleNCActivate
749 * Handle a WM_NCACTIVATE message. Called from DefWindowProc().
751 LONG NC_HandleNCActivate( HWND hwnd, WPARAM wParam )
753 WND *wndPtr = WIN_FindWndPtr(hwnd);
755 if (wParam != 0) wndPtr->flags |= WIN_NCACTIVATED;
756 else wndPtr->flags &= ~WIN_NCACTIVATED;
758 NC_DoNCPaint( hwnd, (HRGN)1, FALSE );
759 return TRUE;
763 /***********************************************************************
764 * NC_HandleSetCursor
766 * Handle a WM_SETCURSOR message. Called from DefWindowProc().
768 LONG NC_HandleSetCursor( HWND hwnd, WPARAM wParam, LPARAM lParam )
770 if (hwnd != (HWND)wParam) return 0; /* Don't set the cursor for child windows */
772 switch(LOWORD(lParam))
774 case HTERROR:
776 WORD msg = HIWORD( lParam );
777 if ((msg == WM_LBUTTONDOWN) || (msg == WM_MBUTTONDOWN) ||
778 (msg == WM_RBUTTONDOWN))
779 MessageBeep(0);
781 break;
783 case HTCLIENT:
785 WND *wndPtr;
786 CLASS *classPtr;
787 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) break;
788 if (!(classPtr = CLASS_FindClassPtr( wndPtr->hClass ))) break;
789 if (classPtr->wc.hCursor)
791 SetCursor( classPtr->wc.hCursor );
792 return TRUE;
794 else return FALSE;
797 case HTLEFT:
798 case HTRIGHT:
799 return (LONG)SetCursor( LoadCursor( 0, IDC_SIZEWE ) );
801 case HTTOP:
802 case HTBOTTOM:
803 return (LONG)SetCursor( LoadCursor( 0, IDC_SIZENS ) );
805 case HTTOPLEFT:
806 case HTBOTTOMRIGHT:
807 return (LONG)SetCursor( LoadCursor( 0, IDC_SIZENWSE ) );
809 case HTTOPRIGHT:
810 case HTBOTTOMLEFT:
811 return (LONG)SetCursor( LoadCursor( 0, IDC_SIZENESW ) );
814 /* Default cursor: arrow */
815 return (LONG)SetCursor( LoadCursor( 0, IDC_ARROW ) );
819 /***********************************************************************
820 * NC_TrackSysMenu
822 * Track a mouse button press on the system menu.
824 static void NC_TrackSysMenu( HWND hwnd, HDC hdc, POINT pt )
826 RECT rect;
827 WND *wndPtr = WIN_FindWndPtr( hwnd );
828 int iconic = wndPtr->dwStyle & WS_MINIMIZE;
830 if (!(wndPtr->dwStyle & WS_SYSMENU)) return;
831 /* If window has a menu, track the menu bar normally if it not minimized */
832 if (HAS_MENU(wndPtr) && !iconic) MENU_TrackMouseMenuBar( hwnd, pt );
833 else
835 /* Otherwise track the system menu like a normal popup menu */
836 NC_GetInsideRect( hwnd, &rect );
837 OffsetRect( &rect, wndPtr->rectWindow.left, wndPtr->rectWindow.top );
838 if (wndPtr->dwStyle & WS_CHILD)
839 ClientToScreen( wndPtr->parent->hwndSelf, (POINT *)&rect );
840 rect.right = rect.left + SYSMETRICS_CXSIZE;
841 rect.bottom = rect.top + SYSMETRICS_CYSIZE;
842 if (!iconic) NC_DrawSysButton( hwnd, hdc, TRUE );
843 TrackPopupMenu( wndPtr->hSysMenu, TPM_LEFTALIGN | TPM_LEFTBUTTON,
844 rect.left, rect.bottom, 0, hwnd, &rect );
845 if (!iconic) NC_DrawSysButton( hwnd, hdc, FALSE );
850 /***********************************************************************
851 * NC_StartSizeMove
853 * Initialisation of a move or resize, when initiatied from a menu choice.
854 * Return hit test code for caption or sizing border.
856 static LONG NC_StartSizeMove( HWND hwnd, WPARAM wParam, POINT *capturePoint )
858 LONG hittest = 0;
859 POINT pt;
860 MSG msg;
861 WND * wndPtr = WIN_FindWndPtr( hwnd );
863 if ((wParam & 0xfff0) == SC_MOVE)
865 /* Move pointer at the center of the caption */
866 RECT rect;
867 NC_GetInsideRect( hwnd, &rect );
868 if (wndPtr->dwStyle & WS_SYSMENU)
869 rect.left += SYSMETRICS_CXSIZE + 1;
870 if (wndPtr->dwStyle & WS_MINIMIZEBOX)
871 rect.right -= SYSMETRICS_CXSIZE + 1;
872 if (wndPtr->dwStyle & WS_MAXIMIZEBOX)
873 rect.right -= SYSMETRICS_CXSIZE + 1;
874 pt.x = wndPtr->rectWindow.left + (rect.right - rect.left) / 2;
875 pt.y = wndPtr->rectWindow.top + rect.top + SYSMETRICS_CYSIZE/2;
876 if (wndPtr->dwStyle & WS_CHILD)
877 ClientToScreen( wndPtr->parent->hwndSelf, &pt );
878 hittest = HTCAPTION;
880 else /* SC_SIZE */
882 SetCapture(hwnd);
883 while(!hittest)
885 MSG_GetHardwareMessage( &msg );
886 switch(msg.message)
888 case WM_MOUSEMOVE:
889 hittest = NC_HandleNCHitTest( hwnd, msg.pt );
890 pt = msg.pt;
891 if ((hittest < HTLEFT) || (hittest > HTBOTTOMRIGHT))
892 hittest = 0;
893 break;
895 case WM_LBUTTONUP:
896 return 0;
898 case WM_KEYDOWN:
899 switch(msg.wParam)
901 case VK_UP:
902 hittest = HTTOP;
903 pt.x =(wndPtr->rectWindow.left+wndPtr->rectWindow.right)/2;
904 pt.y = wndPtr->rectWindow.top + SYSMETRICS_CYFRAME / 2;
905 break;
906 case VK_DOWN:
907 hittest = HTBOTTOM;
908 pt.x =(wndPtr->rectWindow.left+wndPtr->rectWindow.right)/2;
909 pt.y = wndPtr->rectWindow.bottom - SYSMETRICS_CYFRAME / 2;
910 break;
911 case VK_LEFT:
912 hittest = HTLEFT;
913 pt.x = wndPtr->rectWindow.left + SYSMETRICS_CXFRAME / 2;
914 pt.y =(wndPtr->rectWindow.top+wndPtr->rectWindow.bottom)/2;
915 break;
916 case VK_RIGHT:
917 hittest = HTRIGHT;
918 pt.x = wndPtr->rectWindow.right - SYSMETRICS_CXFRAME / 2;
919 pt.y =(wndPtr->rectWindow.top+wndPtr->rectWindow.bottom)/2;
920 break;
921 case VK_RETURN:
922 case VK_ESCAPE: return 0;
927 *capturePoint = pt;
928 SetCursorPos( capturePoint->x, capturePoint->y );
929 NC_HandleSetCursor( hwnd, (WPARAM)hwnd, MAKELONG( hittest, WM_MOUSEMOVE ));
930 return hittest;
934 /***********************************************************************
935 * NC_DoSizeMove
937 * Perform SC_MOVE and SC_SIZE commands.
939 static void NC_DoSizeMove( HWND hwnd, WORD wParam, POINT pt )
941 MSG msg;
942 LONG hittest;
943 RECT sizingRect, mouseRect;
944 HDC hdc;
945 BOOL thickframe;
946 POINT minTrack, maxTrack, capturePoint = pt;
947 WND * wndPtr = WIN_FindWndPtr( hwnd );
948 int moved = 0;
950 if (IsZoomed(hwnd) || !IsWindowVisible(hwnd) ||
951 (wndPtr->flags & WIN_MANAGED)) return;
952 hittest = wParam & 0x0f;
953 thickframe = HAS_THICKFRAME( wndPtr->dwStyle );
955 if ((wParam & 0xfff0) == SC_MOVE)
957 if (!(wndPtr->dwStyle & WS_CAPTION)) return;
958 if (!hittest) hittest = NC_StartSizeMove( hwnd, wParam, &capturePoint );
959 if (!hittest) return;
961 else /* SC_SIZE */
963 if (!thickframe) return;
964 if (hittest) hittest += HTLEFT-1;
965 else
967 SetCapture(hwnd);
968 hittest = NC_StartSizeMove( hwnd, wParam, &capturePoint );
969 if (!hittest)
971 ReleaseCapture();
972 return;
977 /* Get min/max info */
979 NC_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack );
980 sizingRect = wndPtr->rectWindow;
981 if (wndPtr->dwStyle & WS_CHILD)
982 GetClientRect( wndPtr->parent->hwndSelf, &mouseRect );
983 else SetRect( &mouseRect, 0, 0, SYSMETRICS_CXSCREEN, SYSMETRICS_CYSCREEN );
984 if (ON_LEFT_BORDER(hittest))
986 mouseRect.left = MAX( mouseRect.left, sizingRect.right-maxTrack.x );
987 mouseRect.right = MIN( mouseRect.right, sizingRect.right-minTrack.x );
989 else if (ON_RIGHT_BORDER(hittest))
991 mouseRect.left = MAX( mouseRect.left, sizingRect.left+minTrack.x );
992 mouseRect.right = MIN( mouseRect.right, sizingRect.left+maxTrack.x );
994 if (ON_TOP_BORDER(hittest))
996 mouseRect.top = MAX( mouseRect.top, sizingRect.bottom-maxTrack.y );
997 mouseRect.bottom = MIN( mouseRect.bottom,sizingRect.bottom-minTrack.y);
999 else if (ON_BOTTOM_BORDER(hittest))
1001 mouseRect.top = MAX( mouseRect.top, sizingRect.top+minTrack.y );
1002 mouseRect.bottom = MIN( mouseRect.bottom, sizingRect.top+maxTrack.y );
1004 SendMessage( hwnd, WM_ENTERSIZEMOVE, 0, 0 );
1006 if (GetCapture() != hwnd) SetCapture( hwnd );
1008 if (wndPtr->dwStyle & WS_CHILD)
1010 /* Retrieve a default cache DC (without using the window style) */
1011 hdc = GetDCEx( wndPtr->parent->hwndSelf, 0, DCX_CACHE );
1013 else
1014 { /* Grab the server only when moving top-level windows without desktop */
1015 hdc = GetDC( 0 );
1016 if (rootWindow == DefaultRootWindow(display)) XGrabServer( display );
1018 NC_DrawMovingFrame( hdc, &sizingRect, thickframe );
1020 while(1)
1022 int dx = 0, dy = 0;
1024 MSG_GetHardwareMessage( &msg );
1026 /* Exit on button-up, Return, or Esc */
1027 if ((msg.message == WM_LBUTTONUP) ||
1028 ((msg.message == WM_KEYDOWN) &&
1029 ((msg.wParam == VK_RETURN) || (msg.wParam == VK_ESCAPE)))) break;
1031 if ((msg.message != WM_KEYDOWN) && (msg.message != WM_MOUSEMOVE))
1032 continue; /* We are not interested in other messages */
1034 pt = msg.pt;
1035 if (wndPtr->dwStyle & WS_CHILD)
1036 ScreenToClient( wndPtr->parent->hwndSelf, &pt );
1039 if (msg.message == WM_KEYDOWN) switch(msg.wParam)
1041 case VK_UP: pt.y -= 8; break;
1042 case VK_DOWN: pt.y += 8; break;
1043 case VK_LEFT: pt.x -= 8; break;
1044 case VK_RIGHT: pt.x += 8; break;
1047 pt.x = MAX( pt.x, mouseRect.left );
1048 pt.x = MIN( pt.x, mouseRect.right );
1049 pt.y = MAX( pt.y, mouseRect.top );
1050 pt.y = MIN( pt.y, mouseRect.bottom );
1052 dx = pt.x - capturePoint.x;
1053 dy = pt.y - capturePoint.y;
1055 if (dx || dy)
1057 moved = 1;
1058 if (msg.message == WM_KEYDOWN) SetCursorPos( pt.x, pt.y );
1059 else
1061 RECT newRect = sizingRect;
1063 if (hittest == HTCAPTION) OffsetRect( &newRect, dx, dy );
1064 if (ON_LEFT_BORDER(hittest)) newRect.left += dx;
1065 else if (ON_RIGHT_BORDER(hittest)) newRect.right += dx;
1066 if (ON_TOP_BORDER(hittest)) newRect.top += dy;
1067 else if (ON_BOTTOM_BORDER(hittest)) newRect.bottom += dy;
1068 NC_DrawMovingFrame( hdc, &sizingRect, thickframe );
1069 NC_DrawMovingFrame( hdc, &newRect, thickframe );
1070 capturePoint = pt;
1071 sizingRect = newRect;
1076 NC_DrawMovingFrame( hdc, &sizingRect, thickframe );
1077 ReleaseCapture();
1079 if (wndPtr->dwStyle & WS_CHILD) ReleaseDC( wndPtr->parent->hwndSelf, hdc );
1080 else
1082 ReleaseDC( 0, hdc );
1083 if (rootWindow == DefaultRootWindow(display)) XUngrabServer( display );
1085 SendMessage( hwnd, WM_EXITSIZEMOVE, 0, 0 );
1086 SendMessage( hwnd, WM_SETVISIBLE, !IsIconic(hwnd), 0L);
1088 /* Single click brings up the system menu when iconized */
1090 if (!moved && (wndPtr->dwStyle & WS_MINIMIZE))
1092 NC_TrackSysMenu( hwnd, hdc, pt );
1093 return;
1096 /* If Esc key, don't move the window */
1097 if ((msg.message == WM_KEYDOWN) && (msg.wParam == VK_ESCAPE)) return;
1099 if (hittest != HTCAPTION)
1100 SetWindowPos( hwnd, 0, sizingRect.left, sizingRect.top,
1101 sizingRect.right - sizingRect.left,
1102 sizingRect.bottom - sizingRect.top,
1103 SWP_NOACTIVATE | SWP_NOZORDER );
1104 else SetWindowPos( hwnd, 0, sizingRect.left, sizingRect.top, 0, 0,
1105 SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER );
1109 /***********************************************************************
1110 * NC_TrackMinMaxBox
1112 * Track a mouse button press on the minimize or maximize box.
1114 static void NC_TrackMinMaxBox( HWND hwnd, WORD wParam )
1116 MSG msg;
1117 HDC hdc = GetWindowDC( hwnd );
1118 BOOL pressed = TRUE;
1120 SetCapture( hwnd );
1121 if (wParam == HTMINBUTTON) NC_DrawMinButton( hwnd, hdc, TRUE );
1122 else NC_DrawMaxButton( hwnd, hdc, TRUE );
1126 BOOL oldstate = pressed;
1127 MSG_GetHardwareMessage( &msg );
1129 pressed = (NC_HandleNCHitTest( hwnd, msg.pt ) == wParam);
1130 if (pressed != oldstate)
1132 if (wParam == HTMINBUTTON) NC_DrawMinButton( hwnd, hdc, pressed );
1133 else NC_DrawMaxButton( hwnd, hdc, pressed );
1135 } while (msg.message != WM_LBUTTONUP);
1137 if (wParam == HTMINBUTTON) NC_DrawMinButton( hwnd, hdc, FALSE );
1138 else NC_DrawMaxButton( hwnd, hdc, FALSE );
1140 ReleaseCapture();
1141 ReleaseDC( hwnd, hdc );
1142 if (!pressed) return;
1144 if (wParam == HTMINBUTTON)
1145 SendMessage( hwnd, WM_SYSCOMMAND, SC_MINIMIZE, *(LONG*)&msg.pt );
1146 else
1147 SendMessage( hwnd, WM_SYSCOMMAND,
1148 IsZoomed(hwnd) ? SC_RESTORE : SC_MAXIMIZE, *(LONG*)&msg.pt );
1152 /***********************************************************************
1153 * NC_TrackScrollBar
1155 * Track a mouse button press on the horizontal or vertical scroll-bar.
1157 static void NC_TrackScrollBar( HWND hwnd, WORD wParam, POINT pt )
1159 MSG msg;
1160 WORD scrollbar;
1161 WND *wndPtr = WIN_FindWndPtr( hwnd );
1163 if ((wParam & 0xfff0) == SC_HSCROLL)
1165 if ((wParam & 0x0f) != HTHSCROLL) return;
1166 scrollbar = SB_HORZ;
1168 else /* SC_VSCROLL */
1170 if ((wParam & 0x0f) != HTVSCROLL) return;
1171 scrollbar = SB_VERT;
1174 pt.x -= wndPtr->rectWindow.left;
1175 pt.y -= wndPtr->rectWindow.top;
1176 SetCapture( hwnd );
1177 SCROLL_HandleScrollEvent( hwnd, scrollbar, WM_LBUTTONDOWN, pt );
1181 GetMessage( MAKE_SEGPTR(&msg), 0, 0, 0 );
1182 switch(msg.message)
1184 case WM_LBUTTONUP:
1185 case WM_MOUSEMOVE:
1186 case WM_SYSTIMER:
1187 pt.x = LOWORD(msg.lParam) + wndPtr->rectClient.left -
1188 wndPtr->rectWindow.left;
1189 pt.y = HIWORD(msg.lParam) + wndPtr->rectClient.top -
1190 wndPtr->rectWindow.top;
1191 SCROLL_HandleScrollEvent( hwnd, scrollbar, msg.message, pt );
1192 break;
1193 default:
1194 TranslateMessage( &msg );
1195 DispatchMessage( &msg );
1196 break;
1198 if (!IsWindow( hwnd ))
1200 ReleaseCapture();
1201 break;
1203 } while (msg.message != WM_LBUTTONUP);
1206 /***********************************************************************
1207 * NC_HandleNCLButtonDown
1209 * Handle a WM_NCLBUTTONDOWN message. Called from DefWindowProc().
1211 LONG NC_HandleNCLButtonDown( HWND hwnd, WPARAM wParam, LPARAM lParam )
1213 HDC hdc = GetWindowDC( hwnd );
1214 POINT pt = { LOWORD(lParam), HIWORD(lParam) };
1216 switch(wParam) /* Hit test */
1218 case HTCAPTION:
1219 SendMessage( hwnd, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, lParam );
1220 break;
1222 case HTSYSMENU:
1223 NC_TrackSysMenu( hwnd, hdc, pt );
1224 break;
1226 case HTMENU:
1227 SendMessage( hwnd, WM_SYSCOMMAND, SC_MOUSEMENU, lParam );
1228 break;
1230 case HTHSCROLL:
1231 SendMessage( hwnd, WM_SYSCOMMAND, SC_HSCROLL + HTHSCROLL, lParam );
1232 break;
1234 case HTVSCROLL:
1235 SendMessage( hwnd, WM_SYSCOMMAND, SC_VSCROLL + HTVSCROLL, lParam );
1236 break;
1238 case HTMINBUTTON:
1239 case HTMAXBUTTON:
1240 NC_TrackMinMaxBox( hwnd, wParam );
1241 break;
1243 case HTLEFT:
1244 case HTRIGHT:
1245 case HTTOP:
1246 case HTTOPLEFT:
1247 case HTTOPRIGHT:
1248 case HTBOTTOM:
1249 case HTBOTTOMLEFT:
1250 case HTBOTTOMRIGHT:
1251 SendMessage( hwnd, WM_SYSCOMMAND, SC_SIZE + wParam - HTLEFT+1, lParam);
1252 break;
1254 case HTBORDER:
1255 break;
1258 ReleaseDC( hwnd, hdc );
1259 return 0;
1263 /***********************************************************************
1264 * NC_HandleNCLButtonDblClk
1266 * Handle a WM_NCLBUTTONDBLCLK message. Called from DefWindowProc().
1268 LONG NC_HandleNCLButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam )
1271 * if this is an icon, send a restore since we are handling
1272 * a double click
1274 if (IsIconic(hwnd))
1276 SendMessage(hwnd, WM_SYSCOMMAND, SC_RESTORE, lParam);
1277 return 0;
1280 switch(wParam) /* Hit test */
1282 case HTCAPTION:
1283 /* stop processing if WS_MAXIMIZEBOX is missing */
1285 if( GetWindowLong( hwnd , GWL_STYLE) & WS_MAXIMIZEBOX )
1286 SendMessage( hwnd, WM_SYSCOMMAND,
1287 IsZoomed(hwnd) ? SC_RESTORE : SC_MAXIMIZE, lParam );
1288 break;
1290 case HTSYSMENU:
1291 SendMessage( hwnd, WM_SYSCOMMAND, SC_CLOSE, lParam );
1292 break;
1294 return 0;
1298 /***********************************************************************
1299 * NC_HandleSysCommand
1301 * Handle a WM_SYSCOMMAND message. Called from DefWindowProc().
1303 LONG NC_HandleSysCommand( HWND hwnd, WPARAM wParam, POINT pt )
1305 WND *wndPtr = WIN_FindWndPtr( hwnd );
1307 dprintf_nonclient(stddeb, "Handling WM_SYSCOMMAND %x %d,%d\n",
1308 wParam, pt.x, pt.y );
1310 if (wndPtr->dwStyle & WS_CHILD && wParam != SC_KEYMENU )
1311 ScreenToClient( wndPtr->parent->hwndSelf, &pt );
1313 switch (wParam & 0xfff0)
1315 case SC_SIZE:
1316 case SC_MOVE:
1317 NC_DoSizeMove( hwnd, wParam, pt );
1318 break;
1320 case SC_MINIMIZE:
1321 ShowWindow( hwnd, SW_MINIMIZE );
1322 break;
1324 case SC_MAXIMIZE:
1325 ShowWindow( hwnd, SW_MAXIMIZE );
1326 break;
1328 case SC_RESTORE:
1329 ShowWindow( hwnd, SW_RESTORE );
1330 break;
1332 case SC_NEXTWINDOW:
1333 case SC_PREVWINDOW:
1334 break;
1336 case SC_CLOSE:
1337 return SendMessage( hwnd, WM_CLOSE, 0, 0 );
1339 case SC_VSCROLL:
1340 case SC_HSCROLL:
1341 NC_TrackScrollBar( hwnd, wParam, pt );
1342 break;
1344 case SC_MOUSEMENU:
1345 MENU_TrackMouseMenuBar( hwnd, pt );
1346 break;
1348 case SC_KEYMENU:
1349 MENU_TrackKbdMenuBar( wndPtr , wParam , pt.x );
1350 break;
1352 case SC_ARRANGE:
1353 break;
1355 case SC_TASKLIST:
1356 WinExec( "taskman.exe", SW_SHOWNORMAL );
1357 break;
1359 case SC_HOTKEY:
1360 break;
1362 case SC_SCREENSAVE:
1363 if (wParam == SC_ABOUTWINE)
1365 extern const char people[];
1366 ShellAbout(hwnd,"WINE",people,0);
1368 break;
1370 return 0;