Release 970305
[wine/multimedia.git] / windows / nonclient.c
blobd04d7df8ec5309842f11d1e23e42aa2697beae11
1 /*
2 * Non-client area window functions
4 * Copyright 1994 Alexandre Julliard
6 */
8 #include "win.h"
9 #include "message.h"
10 #include "sysmetrics.h"
11 #include "user.h"
12 #include "heap.h"
13 #include "shell.h"
14 #include "dialog.h"
15 #include "syscolor.h"
16 #include "menu.h"
17 #include "winpos.h"
18 #include "hook.h"
19 #include "scroll.h"
20 #include "nonclient.h"
21 #include "graphics.h"
22 #include "queue.h"
23 #include "selectors.h"
24 #include "stddebug.h"
25 #include "debug.h"
26 #include "options.h"
29 static HBITMAP16 hbitmapClose = 0;
30 static HBITMAP16 hbitmapMinimize = 0;
31 static HBITMAP16 hbitmapMinimizeD = 0;
32 static HBITMAP16 hbitmapMaximize = 0;
33 static HBITMAP16 hbitmapMaximizeD = 0;
34 static HBITMAP16 hbitmapRestore = 0;
35 static HBITMAP16 hbitmapRestoreD = 0;
37 #define SC_ABOUTWINE (SC_SCREENSAVE+1)
39 /* Some useful macros */
40 #define HAS_DLGFRAME(style,exStyle) \
41 (((exStyle) & WS_EX_DLGMODALFRAME) || \
42 (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
44 #define HAS_THICKFRAME(style) \
45 (((style) & WS_THICKFRAME) && \
46 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
48 #define HAS_MENU(w) (!((w)->dwStyle & WS_CHILD) && ((w)->wIDmenu != 0))
50 #define ON_LEFT_BORDER(hit) \
51 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
52 #define ON_RIGHT_BORDER(hit) \
53 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
54 #define ON_TOP_BORDER(hit) \
55 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
56 #define ON_BOTTOM_BORDER(hit) \
57 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
59 extern HCURSOR16 CURSORICON_IconToCursor( HICON16, BOOL32 );
61 /***********************************************************************
62 * NC_AdjustRect
64 * Compute the size of the window rectangle from the size of the
65 * client rectangle.
67 static void NC_AdjustRect( LPRECT16 rect, DWORD style, BOOL32 menu,
68 DWORD exStyle )
70 if(style & WS_ICONIC) return;
71 /* Decide if the window will be managed (see CreateWindowEx) */
72 if (!(Options.managed && !(style & WS_CHILD) &&
73 ((style & (WS_DLGFRAME | WS_THICKFRAME)) ||
74 (exStyle & WS_EX_DLGMODALFRAME))))
76 if (HAS_DLGFRAME( style, exStyle ))
77 InflateRect16(rect, SYSMETRICS_CXDLGFRAME, SYSMETRICS_CYDLGFRAME );
78 else
80 if (HAS_THICKFRAME(style))
81 InflateRect16( rect, SYSMETRICS_CXFRAME, SYSMETRICS_CYFRAME );
82 if (style & WS_BORDER)
83 InflateRect16( rect, SYSMETRICS_CXBORDER, SYSMETRICS_CYBORDER);
86 if ((style & WS_CAPTION) == WS_CAPTION)
87 rect->top -= SYSMETRICS_CYCAPTION - SYSMETRICS_CYBORDER;
89 if (menu) rect->top -= SYSMETRICS_CYMENU + SYSMETRICS_CYBORDER;
91 if (style & WS_VSCROLL) rect->right += SYSMETRICS_CXVSCROLL;
92 if (style & WS_HSCROLL) rect->bottom += SYSMETRICS_CYHSCROLL;
96 /***********************************************************************
97 * AdjustWindowRect16 (USER.102)
99 BOOL16 AdjustWindowRect16( LPRECT16 rect, DWORD style, BOOL16 menu )
101 return AdjustWindowRectEx16( rect, style, menu, 0 );
105 /***********************************************************************
106 * AdjustWindowRect32 (USER32.)
108 BOOL32 AdjustWindowRect32( LPRECT32 rect, DWORD style, BOOL32 menu )
110 return AdjustWindowRectEx32( rect, style, menu, 0 );
114 /***********************************************************************
115 * AdjustWindowRectEx16 (USER.454)
117 BOOL16 AdjustWindowRectEx16( LPRECT16 rect, DWORD style,
118 BOOL16 menu, DWORD exStyle )
120 /* Correct the window style */
122 if (!(style & (WS_POPUP | WS_CHILD))) /* Overlapped window */
123 style |= WS_CAPTION;
124 style &= (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME);
125 exStyle &= WS_EX_DLGMODALFRAME;
126 if (exStyle & WS_EX_DLGMODALFRAME) style &= ~WS_THICKFRAME;
128 dprintf_nonclient(stddeb, "AdjustWindowRectEx: (%d,%d)-(%d,%d) %08lx %d %08lx\n",
129 rect->left, rect->top, rect->right, rect->bottom,
130 style, menu, exStyle );
132 NC_AdjustRect( rect, style, menu, exStyle );
133 return TRUE;
137 /***********************************************************************
138 * AdjustWindowRectEx32 (USER32.)
140 BOOL32 AdjustWindowRectEx32( LPRECT32 rect, DWORD style,
141 BOOL32 menu, DWORD exStyle )
143 RECT16 rect16;
144 BOOL32 ret;
146 CONV_RECT32TO16( rect, &rect16 );
147 ret = AdjustWindowRectEx16( &rect16, style, (BOOL16)menu, exStyle );
148 CONV_RECT16TO32( &rect16, rect );
149 return ret;
153 /*******************************************************************
154 * NC_GetMinMaxInfo
156 * Get the minimized and maximized information for a window.
158 void NC_GetMinMaxInfo( WND *wndPtr, POINT16 *maxSize, POINT16 *maxPos,
159 POINT16 *minTrack, POINT16 *maxTrack )
161 MINMAXINFO16 *MinMax;
162 short xinc, yinc;
164 if (!(MinMax = SEGPTR_NEW(MINMAXINFO16))) return;
166 /* Compute default values */
168 MinMax->ptMaxSize.x = SYSMETRICS_CXSCREEN;
169 MinMax->ptMaxSize.y = SYSMETRICS_CYSCREEN;
170 MinMax->ptMinTrackSize.x = SYSMETRICS_CXMINTRACK;
171 MinMax->ptMinTrackSize.y = SYSMETRICS_CYMINTRACK;
172 MinMax->ptMaxTrackSize.x = SYSMETRICS_CXSCREEN;
173 MinMax->ptMaxTrackSize.y = SYSMETRICS_CYSCREEN;
175 if (wndPtr->flags & WIN_MANAGED) xinc = yinc = 0;
176 else if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
178 xinc = SYSMETRICS_CXDLGFRAME;
179 yinc = SYSMETRICS_CYDLGFRAME;
181 else
183 xinc = yinc = 0;
184 if (HAS_THICKFRAME(wndPtr->dwStyle))
186 xinc += SYSMETRICS_CXFRAME;
187 yinc += SYSMETRICS_CYFRAME;
189 if (wndPtr->dwStyle & WS_BORDER)
191 xinc += SYSMETRICS_CXBORDER;
192 yinc += SYSMETRICS_CYBORDER;
195 MinMax->ptMaxSize.x += 2 * xinc;
196 MinMax->ptMaxSize.y += 2 * yinc;
198 /* Note: The '+' in the following test should really be a ||, but
199 * that would cause gcc-2.7.0 to generate incorrect code.
201 if ((wndPtr->ptMaxPos.x != -1) + (wndPtr->ptMaxPos.y != -1))
202 MinMax->ptMaxPosition = wndPtr->ptMaxPos;
203 else
205 MinMax->ptMaxPosition.x = -xinc;
206 MinMax->ptMaxPosition.y = -yinc;
209 SendMessage16( wndPtr->hwndSelf, WM_GETMINMAXINFO, 0,
210 (LPARAM)SEGPTR_GET(MinMax) );
212 /* Some sanity checks */
214 dprintf_nonclient(stddeb,
215 "NC_GetMinMaxInfo: %d %d / %d %d / %d %d / %d %d\n",
216 MinMax->ptMaxSize.x, MinMax->ptMaxSize.y,
217 MinMax->ptMaxPosition.x, MinMax->ptMaxPosition.y,
218 MinMax->ptMaxTrackSize.x, MinMax->ptMaxTrackSize.y,
219 MinMax->ptMinTrackSize.x, MinMax->ptMinTrackSize.y);
220 MinMax->ptMaxTrackSize.x = MAX( MinMax->ptMaxTrackSize.x,
221 MinMax->ptMinTrackSize.x );
222 MinMax->ptMaxTrackSize.y = MAX( MinMax->ptMaxTrackSize.y,
223 MinMax->ptMinTrackSize.y );
225 if (maxSize) *maxSize = MinMax->ptMaxSize;
226 if (maxPos) *maxPos = MinMax->ptMaxPosition;
227 if (minTrack) *minTrack = MinMax->ptMinTrackSize;
228 if (maxTrack) *maxTrack = MinMax->ptMaxTrackSize;
229 SEGPTR_FREE(MinMax);
233 /***********************************************************************
234 * NC_HandleNCCalcSize
236 * Handle a WM_NCCALCSIZE message. Called from DefWindowProc().
238 LONG NC_HandleNCCalcSize( WND *pWnd, RECT16 *winRect )
240 RECT16 tmpRect = { 0, 0, 0, 0 };
241 LONG result = 0;
243 if (pWnd->class->style & CS_VREDRAW) result |= WVR_VREDRAW;
244 if (pWnd->class->style & CS_HREDRAW) result |= WVR_HREDRAW;
246 if( !( pWnd->dwStyle & WS_MINIMIZE ) )
248 NC_AdjustRect( &tmpRect, pWnd->dwStyle, FALSE, pWnd->dwExStyle );
249 winRect->left -= tmpRect.left;
250 winRect->top -= tmpRect.top;
251 winRect->right -= tmpRect.right;
252 winRect->bottom -= tmpRect.bottom;
254 if (HAS_MENU(pWnd))
256 winRect->top += MENU_GetMenuBarHeight( pWnd->hwndSelf,
257 winRect->right - winRect->left,
258 -tmpRect.left, -tmpRect.top ) + 1;
261 return result;
265 /***********************************************************************
266 * NC_GetInsideRect
268 * Get the 'inside' rectangle of a window, i.e. the whole window rectangle
269 * but without the borders (if any).
270 * The rectangle is in window coordinates (for drawing with GetWindowDC()).
272 static void NC_GetInsideRect( HWND32 hwnd, RECT32 *rect )
274 WND * wndPtr = WIN_FindWndPtr( hwnd );
276 rect->top = rect->left = 0;
277 rect->right = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
278 rect->bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
280 if (wndPtr->dwStyle & WS_ICONIC) return; /* No border to remove */
281 if (wndPtr->flags & WIN_MANAGED) return;
283 /* Remove frame from rectangle */
284 if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
286 InflateRect32( rect, -SYSMETRICS_CXDLGFRAME, -SYSMETRICS_CYDLGFRAME);
287 if (wndPtr->dwExStyle & WS_EX_DLGMODALFRAME)
288 InflateRect32( rect, -1, 0 );
290 else
292 if (HAS_THICKFRAME( wndPtr->dwStyle ))
293 InflateRect32( rect, -SYSMETRICS_CXFRAME, -SYSMETRICS_CYFRAME );
294 if (wndPtr->dwStyle & WS_BORDER)
295 InflateRect32( rect, -SYSMETRICS_CXBORDER, -SYSMETRICS_CYBORDER );
300 /***********************************************************************
301 * NC_HandleNCHitTest
303 * Handle a WM_NCHITTEST message. Called from DefWindowProc().
305 LONG NC_HandleNCHitTest( HWND32 hwnd, POINT16 pt )
307 RECT16 rect;
308 WND *wndPtr = WIN_FindWndPtr( hwnd );
309 if (!wndPtr) return HTERROR;
311 dprintf_nonclient(stddeb, "NC_HandleNCHitTest: hwnd=%04x pt=%d,%d\n",
312 hwnd, pt.x, pt.y );
314 GetWindowRect16( hwnd, &rect );
315 if (!PtInRect16( &rect, pt )) return HTNOWHERE;
317 if (wndPtr->dwStyle & WS_MINIMIZE) return HTCAPTION;
319 if (!(wndPtr->flags & WIN_MANAGED))
321 /* Check borders */
322 if (HAS_THICKFRAME( wndPtr->dwStyle ))
324 InflateRect16( &rect, -SYSMETRICS_CXFRAME, -SYSMETRICS_CYFRAME );
325 if (wndPtr->dwStyle & WS_BORDER)
326 InflateRect16(&rect,-SYSMETRICS_CXBORDER,-SYSMETRICS_CYBORDER);
327 if (!PtInRect16( &rect, pt ))
329 /* Check top sizing border */
330 if (pt.y < rect.top)
332 if (pt.x < rect.left+SYSMETRICS_CXSIZE) return HTTOPLEFT;
333 if (pt.x >= rect.right-SYSMETRICS_CXSIZE) return HTTOPRIGHT;
334 return HTTOP;
336 /* Check bottom sizing border */
337 if (pt.y >= rect.bottom)
339 if (pt.x < rect.left+SYSMETRICS_CXSIZE) return HTBOTTOMLEFT;
340 if (pt.x >= rect.right-SYSMETRICS_CXSIZE) return HTBOTTOMRIGHT;
341 return HTBOTTOM;
343 /* Check left sizing border */
344 if (pt.x < rect.left)
346 if (pt.y < rect.top+SYSMETRICS_CYSIZE) return HTTOPLEFT;
347 if (pt.y >= rect.bottom-SYSMETRICS_CYSIZE) return HTBOTTOMLEFT;
348 return HTLEFT;
350 /* Check right sizing border */
351 if (pt.x >= rect.right)
353 if (pt.y < rect.top+SYSMETRICS_CYSIZE) return HTTOPRIGHT;
354 if (pt.y >= rect.bottom-SYSMETRICS_CYSIZE) return HTBOTTOMRIGHT;
355 return HTRIGHT;
359 else /* No thick frame */
361 if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
362 InflateRect16(&rect, -SYSMETRICS_CXDLGFRAME, -SYSMETRICS_CYDLGFRAME);
363 else if (wndPtr->dwStyle & WS_BORDER)
364 InflateRect16(&rect, -SYSMETRICS_CXBORDER, -SYSMETRICS_CYBORDER);
365 if (!PtInRect16( &rect, pt )) return HTBORDER;
368 /* Check caption */
370 if ((wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION)
372 rect.top += SYSMETRICS_CYCAPTION - 1;
373 if (!PtInRect16( &rect, pt ))
375 /* Check system menu */
376 if (wndPtr->dwStyle & WS_SYSMENU)
377 rect.left += SYSMETRICS_CXSIZE;
378 if (pt.x <= rect.left) return HTSYSMENU;
379 /* Check maximize box */
380 if (wndPtr->dwStyle & WS_MAXIMIZEBOX)
381 rect.right -= SYSMETRICS_CXSIZE + 1;
382 if (pt.x >= rect.right) return HTMAXBUTTON;
383 /* Check minimize box */
384 if (wndPtr->dwStyle & WS_MINIMIZEBOX)
385 rect.right -= SYSMETRICS_CXSIZE + 1;
386 if (pt.x >= rect.right) return HTMINBUTTON;
387 return HTCAPTION;
392 /* Check client area */
394 ScreenToClient16( hwnd, &pt );
395 GetClientRect16( hwnd, &rect );
396 if (PtInRect16( &rect, pt )) return HTCLIENT;
398 /* Check vertical scroll bar */
400 if (wndPtr->dwStyle & WS_VSCROLL)
402 rect.right += SYSMETRICS_CXVSCROLL;
403 if (PtInRect16( &rect, pt )) return HTVSCROLL;
406 /* Check horizontal scroll bar */
408 if (wndPtr->dwStyle & WS_HSCROLL)
410 rect.bottom += SYSMETRICS_CYHSCROLL;
411 if (PtInRect16( &rect, pt ))
413 /* Check size box */
414 if ((wndPtr->dwStyle & WS_VSCROLL) &&
415 (pt.x >= rect.right - SYSMETRICS_CXVSCROLL))
416 return HTSIZE;
417 return HTHSCROLL;
421 /* Check menu bar */
423 if (HAS_MENU(wndPtr))
425 if ((pt.y < 0) && (pt.x >= 0) && (pt.x < rect.right))
426 return HTMENU;
429 /* Should never get here */
430 return HTERROR;
434 /***********************************************************************
435 * NC_DrawSysButton
437 void NC_DrawSysButton( HWND32 hwnd, HDC32 hdc, BOOL32 down )
439 RECT32 rect;
440 HDC32 hdcMem;
441 HBITMAP32 hbitmap;
442 WND *wndPtr = WIN_FindWndPtr( hwnd );
444 if( !(wndPtr->flags & WIN_MANAGED) )
446 NC_GetInsideRect( hwnd, &rect );
447 hdcMem = CreateCompatibleDC32( hdc );
448 hbitmap = SelectObject32( hdcMem, hbitmapClose );
449 BitBlt32(hdc, rect.left, rect.top, SYSMETRICS_CXSIZE, SYSMETRICS_CYSIZE,
450 hdcMem, (wndPtr->dwStyle & WS_CHILD) ? SYSMETRICS_CXSIZE : 0, 0,
451 down ? NOTSRCCOPY : SRCCOPY );
452 SelectObject32( hdcMem, hbitmap );
453 DeleteDC32( hdcMem );
458 /***********************************************************************
459 * NC_DrawMaxButton
461 static void NC_DrawMaxButton( HWND32 hwnd, HDC16 hdc, BOOL32 down )
463 RECT32 rect;
464 WND *wndPtr = WIN_FindWndPtr( hwnd );
466 if( !(wndPtr->flags & WIN_MANAGED) )
468 NC_GetInsideRect( hwnd, &rect );
469 GRAPH_DrawBitmap( hdc, (IsZoomed32(hwnd) ?
470 (down ? hbitmapRestoreD : hbitmapRestore) :
471 (down ? hbitmapMaximizeD : hbitmapMaximize)),
472 rect.right - SYSMETRICS_CXSIZE - 1, rect.top,
473 0, 0, SYSMETRICS_CXSIZE+1, SYSMETRICS_CYSIZE );
478 /***********************************************************************
479 * NC_DrawMinButton
481 static void NC_DrawMinButton( HWND32 hwnd, HDC16 hdc, BOOL32 down )
483 RECT32 rect;
484 WND *wndPtr = WIN_FindWndPtr( hwnd );
486 if( !(wndPtr->flags & WIN_MANAGED) )
488 NC_GetInsideRect( hwnd, &rect );
489 if (wndPtr->dwStyle & WS_MAXIMIZEBOX) rect.right -= SYSMETRICS_CXSIZE+1;
490 GRAPH_DrawBitmap( hdc, (down ? hbitmapMinimizeD : hbitmapMinimize),
491 rect.right - SYSMETRICS_CXSIZE - 1, rect.top,
492 0, 0, SYSMETRICS_CXSIZE+1, SYSMETRICS_CYSIZE );
497 /***********************************************************************
498 * NC_DrawFrame
500 * Draw a window frame inside the given rectangle, and update the rectangle.
501 * The correct pen for the frame must be selected in the DC.
503 static void NC_DrawFrame( HDC16 hdc, RECT16 *rect, BOOL32 dlgFrame,
504 BOOL32 active )
506 short width, height, tmp;
508 if (dlgFrame)
510 width = SYSMETRICS_CXDLGFRAME - 1;
511 height = SYSMETRICS_CYDLGFRAME - 1;
512 SelectObject32( hdc, active ? sysColorObjects.hbrushActiveCaption :
513 sysColorObjects.hbrushInactiveCaption );
515 else
517 width = SYSMETRICS_CXFRAME - 1;
518 height = SYSMETRICS_CYFRAME - 1;
519 SelectObject32( hdc, active ? sysColorObjects.hbrushActiveBorder :
520 sysColorObjects.hbrushInactiveBorder );
523 /* Draw frame */
524 PatBlt32( hdc, rect->left, rect->top,
525 rect->right - rect->left, height, PATCOPY );
526 PatBlt32( hdc, rect->left, rect->top,
527 width, rect->bottom - rect->top, PATCOPY );
528 PatBlt32( hdc, rect->left, rect->bottom,
529 rect->right - rect->left, -height, PATCOPY );
530 PatBlt32( hdc, rect->right, rect->top,
531 -width, rect->bottom - rect->top, PATCOPY );
533 if (dlgFrame)
535 InflateRect16( rect, -width, -height );
536 return;
539 /* Draw inner rectangle */
540 MoveTo( hdc, rect->left+width, rect->top+height );
541 LineTo32( hdc, rect->right-width-1, rect->top+height );
542 LineTo32( hdc, rect->right-width-1, rect->bottom-height-1 );
543 LineTo32( hdc, rect->left+width, rect->bottom-height-1 );
544 LineTo32( hdc, rect->left+width, rect->top+height );
546 /* Draw the decorations */
547 tmp = rect->top + SYSMETRICS_CYFRAME + SYSMETRICS_CYSIZE;
548 MoveTo( hdc, rect->left, tmp);
549 LineTo32( hdc, rect->left+width, tmp );
550 MoveTo( hdc, rect->right-width-1, tmp );
551 LineTo32( hdc, rect->right-1, tmp );
553 tmp = rect->bottom - 1 - SYSMETRICS_CYFRAME - SYSMETRICS_CYSIZE;
554 MoveTo( hdc, rect->left, tmp );
555 LineTo32( hdc, rect->left+width, tmp );
556 MoveTo( hdc, rect->right-width-1, tmp );
557 LineTo32( hdc, rect->right-1, tmp );
559 tmp = rect->left + SYSMETRICS_CXFRAME + SYSMETRICS_CXSIZE;
560 MoveTo( hdc, tmp, rect->top );
561 LineTo32( hdc, tmp, rect->top+height );
562 MoveTo( hdc, tmp, rect->bottom-height-1 );
563 LineTo32( hdc, tmp, rect->bottom-1 );
565 tmp = rect->right - 1 - SYSMETRICS_CXFRAME - SYSMETRICS_CYSIZE;
566 MoveTo( hdc, tmp, rect->top );
567 LineTo32( hdc, tmp, rect->top+height );
568 MoveTo( hdc, tmp, rect->bottom-height-1 );
569 LineTo32( hdc, tmp, rect->bottom-1 );
571 InflateRect16( rect, -width-1, -height-1 );
575 /***********************************************************************
576 * NC_DrawMovingFrame
578 * Draw the frame used when moving or resizing window.
580 static void NC_DrawMovingFrame( HDC16 hdc, RECT16 *rect, BOOL32 thickframe )
582 if (thickframe) FastWindowFrame( hdc, rect, SYSMETRICS_CXFRAME,
583 SYSMETRICS_CYFRAME, PATINVERT );
584 else DrawFocusRect16( hdc, rect );
588 /***********************************************************************
589 * NC_DrawCaption
591 * Draw the window caption.
592 * The correct pen for the window frame must be selected in the DC.
594 static void NC_DrawCaption( HDC16 hdc, RECT16 *rect, HWND32 hwnd,
595 DWORD style, BOOL32 active )
597 RECT16 r = *rect;
598 WND * wndPtr = WIN_FindWndPtr( hwnd );
599 char buffer[256];
601 if (wndPtr->flags & WIN_MANAGED) return;
603 if (!hbitmapClose)
605 if (!(hbitmapClose = LoadBitmap16( 0, MAKEINTRESOURCE(OBM_CLOSE) )))
606 return;
607 hbitmapMinimize = LoadBitmap16( 0, MAKEINTRESOURCE(OBM_REDUCE) );
608 hbitmapMinimizeD = LoadBitmap16( 0, MAKEINTRESOURCE(OBM_REDUCED) );
609 hbitmapMaximize = LoadBitmap16( 0, MAKEINTRESOURCE(OBM_ZOOM) );
610 hbitmapMaximizeD = LoadBitmap16( 0, MAKEINTRESOURCE(OBM_ZOOMD) );
611 hbitmapRestore = LoadBitmap16( 0, MAKEINTRESOURCE(OBM_RESTORE) );
612 hbitmapRestoreD = LoadBitmap16( 0, MAKEINTRESOURCE(OBM_RESTORED) );
615 if (wndPtr->dwExStyle & WS_EX_DLGMODALFRAME)
617 HBRUSH32 hbrushOld = SelectObject32(hdc, sysColorObjects.hbrushWindow);
618 PatBlt32( hdc, r.left, r.top, 1, r.bottom-r.top+1,PATCOPY );
619 PatBlt32( hdc, r.right-1, r.top, 1, r.bottom-r.top+1, PATCOPY );
620 PatBlt32( hdc, r.left, r.top-1, r.right-r.left, 1, PATCOPY );
621 r.left++;
622 r.right--;
623 SelectObject32( hdc, hbrushOld );
626 MoveTo( hdc, r.left, r.bottom );
627 LineTo32( hdc, r.right-1, r.bottom );
629 if (style & WS_SYSMENU)
631 NC_DrawSysButton( hwnd, hdc, FALSE );
632 r.left += SYSMETRICS_CXSIZE + 1;
633 MoveTo( hdc, r.left - 1, r.top );
634 LineTo32( hdc, r.left - 1, r.bottom );
636 if (style & WS_MAXIMIZEBOX)
638 NC_DrawMaxButton( hwnd, hdc, FALSE );
639 r.right -= SYSMETRICS_CXSIZE + 1;
641 if (style & WS_MINIMIZEBOX)
643 NC_DrawMinButton( hwnd, hdc, FALSE );
644 r.right -= SYSMETRICS_CXSIZE + 1;
647 FillRect16( hdc, &r, active ? sysColorObjects.hbrushActiveCaption :
648 sysColorObjects.hbrushInactiveCaption );
650 if (GetWindowText32A( hwnd, buffer, sizeof(buffer) ))
652 if (active) SetTextColor32( hdc, GetSysColor32( COLOR_CAPTIONTEXT ) );
653 else SetTextColor32( hdc, GetSysColor32( COLOR_INACTIVECAPTIONTEXT ) );
654 SetBkMode32( hdc, TRANSPARENT );
655 DrawText16( hdc, buffer, -1, &r,
656 DT_SINGLELINE | DT_CENTER | DT_VCENTER | DT_NOPREFIX );
661 /***********************************************************************
662 * NC_DoNCPaint
664 * Paint the non-client area. clip is currently unused.
666 void NC_DoNCPaint( HWND32 hwnd, HRGN32 clip, BOOL32 suppress_menupaint )
668 HDC32 hdc;
669 RECT16 rect;
670 BOOL32 active;
672 WND *wndPtr = WIN_FindWndPtr( hwnd );
674 if (!wndPtr || wndPtr->dwStyle & WS_MINIMIZE ||
675 !WIN_IsWindowDrawable( wndPtr, 0 )) return; /* Nothing to do */
677 active = wndPtr->flags & WIN_NCACTIVATED;
679 dprintf_nonclient(stddeb, "NC_DoNCPaint: %04x %d\n", hwnd, active );
681 if (!(hdc = GetDCEx32( hwnd, 0, DCX_USESTYLE | DCX_WINDOW ))) return;
683 if (ExcludeVisRect( hdc, wndPtr->rectClient.left-wndPtr->rectWindow.left,
684 wndPtr->rectClient.top-wndPtr->rectWindow.top,
685 wndPtr->rectClient.right-wndPtr->rectWindow.left,
686 wndPtr->rectClient.bottom-wndPtr->rectWindow.top )
687 == NULLREGION)
689 ReleaseDC32( hwnd, hdc );
690 return;
693 rect.top = rect.left = 0;
694 rect.right = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
695 rect.bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
697 SelectObject32( hdc, sysColorObjects.hpenWindowFrame );
699 if (!(wndPtr->flags & WIN_MANAGED))
701 if ((wndPtr->dwStyle & WS_BORDER) || (wndPtr->dwStyle & WS_DLGFRAME) ||
702 (wndPtr->dwExStyle & WS_EX_DLGMODALFRAME))
704 MoveTo( hdc, 0, 0 );
705 LineTo32( hdc, rect.right-1, 0 );
706 LineTo32( hdc, rect.right-1, rect.bottom-1 );
707 LineTo32( hdc, 0, rect.bottom-1 );
708 LineTo32( hdc, 0, 0 );
709 InflateRect16( &rect, -1, -1 );
712 if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
713 NC_DrawFrame( hdc, &rect, TRUE, active );
714 else if (wndPtr->dwStyle & WS_THICKFRAME)
715 NC_DrawFrame(hdc, &rect, FALSE, active );
717 if ((wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION)
719 RECT16 r = rect;
720 r.bottom = rect.top + SYSMETRICS_CYSIZE;
721 rect.top += SYSMETRICS_CYSIZE + SYSMETRICS_CYBORDER;
722 NC_DrawCaption( hdc, &r, hwnd, wndPtr->dwStyle, active );
726 if (HAS_MENU(wndPtr))
728 RECT32 r;
729 CONV_RECT16TO32( &rect, &r );
730 r.bottom = rect.top + SYSMETRICS_CYMENU; /* default height */
731 rect.top += MENU_DrawMenuBar( hdc, &r, hwnd, suppress_menupaint );
734 /* Draw the scroll-bars */
736 if (wndPtr->dwStyle & WS_VSCROLL)
737 SCROLL_DrawScrollBar( hwnd, hdc, SB_VERT, TRUE );
738 if (wndPtr->dwStyle & WS_HSCROLL)
739 SCROLL_DrawScrollBar( hwnd, hdc, SB_HORZ, TRUE );
741 /* Draw the "size-box" */
743 if ((wndPtr->dwStyle & WS_VSCROLL) && (wndPtr->dwStyle & WS_HSCROLL))
745 RECT16 r = rect;
746 r.left = r.right - SYSMETRICS_CXVSCROLL + 1;
747 r.top = r.bottom - SYSMETRICS_CYHSCROLL + 1;
748 FillRect16( hdc, &r, sysColorObjects.hbrushScrollbar );
751 ReleaseDC32( hwnd, hdc );
756 /***********************************************************************
757 * NC_HandleNCPaint
759 * Handle a WM_NCPAINT message. Called from DefWindowProc().
761 LONG NC_HandleNCPaint( HWND32 hwnd , HRGN32 clip)
763 NC_DoNCPaint( hwnd, clip, FALSE );
764 return 0;
768 /***********************************************************************
769 * NC_HandleNCActivate
771 * Handle a WM_NCACTIVATE message. Called from DefWindowProc().
773 LONG NC_HandleNCActivate( WND *wndPtr, WPARAM16 wParam )
775 WORD wStateChange;
777 if( wParam ) wStateChange = !(wndPtr->flags & WIN_NCACTIVATED);
778 else wStateChange = wndPtr->flags & WIN_NCACTIVATED;
780 if( wStateChange )
782 if (wParam) wndPtr->flags |= WIN_NCACTIVATED;
783 else wndPtr->flags &= ~WIN_NCACTIVATED;
785 if( wndPtr->dwStyle & WS_MINIMIZE )
786 PAINT_RedrawWindow( wndPtr->hwndSelf, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_ERASENOW, 0 );
787 else
788 NC_DoNCPaint( wndPtr->hwndSelf, (HRGN32)1, FALSE );
790 return TRUE;
794 /***********************************************************************
795 * NC_HandleSetCursor
797 * Handle a WM_SETCURSOR message. Called from DefWindowProc().
799 LONG NC_HandleSetCursor( HWND32 hwnd, WPARAM16 wParam, LPARAM lParam )
801 if (hwnd != (HWND32)wParam) return 0; /* Don't set the cursor for child windows */
803 switch(LOWORD(lParam))
805 case HTERROR:
807 WORD msg = HIWORD( lParam );
808 if ((msg == WM_LBUTTONDOWN) || (msg == WM_MBUTTONDOWN) ||
809 (msg == WM_RBUTTONDOWN))
810 MessageBeep32(0);
812 break;
814 case HTCLIENT:
816 WND *wndPtr;
817 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) break;
818 if (wndPtr->class->hCursor)
820 SetCursor16( wndPtr->class->hCursor );
821 return TRUE;
823 else return FALSE;
826 case HTLEFT:
827 case HTRIGHT:
828 return (LONG)SetCursor16( LoadCursor16( 0, IDC_SIZEWE ) );
830 case HTTOP:
831 case HTBOTTOM:
832 return (LONG)SetCursor16( LoadCursor16( 0, IDC_SIZENS ) );
834 case HTTOPLEFT:
835 case HTBOTTOMRIGHT:
836 return (LONG)SetCursor16( LoadCursor16( 0, IDC_SIZENWSE ) );
838 case HTTOPRIGHT:
839 case HTBOTTOMLEFT:
840 return (LONG)SetCursor16( LoadCursor16( 0, IDC_SIZENESW ) );
843 /* Default cursor: arrow */
844 return (LONG)SetCursor16( LoadCursor16( 0, IDC_ARROW ) );
847 /***********************************************************************
848 * NC_GetSysPopupPos
850 BOOL32 NC_GetSysPopupPos( WND* wndPtr, RECT32* rect )
852 if( wndPtr->hSysMenu )
854 if( wndPtr->dwStyle & WS_MINIMIZE )
855 GetWindowRect32( wndPtr->hwndSelf, rect );
856 else
858 NC_GetInsideRect( wndPtr->hwndSelf, rect );
859 OffsetRect32( rect, wndPtr->rectWindow.left, wndPtr->rectWindow.top);
860 if (wndPtr->dwStyle & WS_CHILD)
861 ClientToScreen32( wndPtr->parent->hwndSelf, (POINT32 *)rect );
862 rect->right = rect->left + SYSMETRICS_CXSIZE;
863 rect->bottom = rect->top + SYSMETRICS_CYSIZE;
865 return TRUE;
867 return FALSE;
870 /***********************************************************************
871 * NC_TrackSysMenu
873 * Track a mouse button press on the system menu.
875 static void NC_TrackSysMenu( HWND32 hwnd, POINT16 pt )
877 WND* wndPtr = WIN_FindWndPtr( hwnd );
879 if (wndPtr->dwStyle & WS_SYSMENU)
881 int iconic, on = 1;
883 iconic = wndPtr->dwStyle & WS_MINIMIZE;
885 if( !iconic )
887 HDC16 hdc = GetWindowDC32(hwnd);
888 RECT32 rect;
889 RECT16 rTrack;
890 BOOL32 bNew, bTrack = TRUE;
891 MSG16 msg;
893 NC_GetSysPopupPos( wndPtr, &rect );
894 CONV_RECT32TO16( &rect, &rTrack );
895 MapWindowPoints16( 0, hwnd, (LPPOINT16)&rTrack, 2 );
897 /* track mouse while waiting for WM_LBUTTONUP */
899 NC_DrawSysButton( hwnd, hdc, bTrack );
900 SetCapture32(hwnd);
903 msg.message = WM_NULL;
904 PeekMessage16( &msg, 0, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE);
905 if( msg.message == WM_MOUSEMOVE )
907 if( (bNew = PtInRect16(&rTrack, MAKEPOINT16(msg.lParam))) )
908 { if( bTrack ) continue; }
909 else
910 { if(!bTrack ) continue; }
911 NC_DrawSysButton( hwnd, hdc, bTrack = bNew);
913 } while( msg.message != WM_LBUTTONUP );
915 ReleaseCapture();
916 ReleaseDC32(hwnd, hdc);
917 on = PtInRect16(&rTrack, MAKEPOINT16(msg.lParam));
920 if( on )
921 SendMessage16( hwnd, WM_SYSCOMMAND,
922 SC_MOUSEMENU + HTSYSMENU, *((LPARAM*)&pt));
927 /***********************************************************************
928 * NC_StartSizeMove
930 * Initialisation of a move or resize, when initiatied from a menu choice.
931 * Return hit test code for caption or sizing border.
933 static LONG NC_StartSizeMove( HWND32 hwnd, WPARAM16 wParam,
934 POINT16 *capturePoint )
936 LONG hittest = 0;
937 POINT16 pt;
938 MSG16 msg;
939 WND * wndPtr = WIN_FindWndPtr( hwnd );
941 if ((wParam & 0xfff0) == SC_MOVE)
943 /* Move pointer at the center of the caption */
944 RECT32 rect;
945 NC_GetInsideRect( hwnd, &rect );
946 if (wndPtr->dwStyle & WS_SYSMENU)
947 rect.left += SYSMETRICS_CXSIZE + 1;
948 if (wndPtr->dwStyle & WS_MINIMIZEBOX)
949 rect.right -= SYSMETRICS_CXSIZE + 1;
950 if (wndPtr->dwStyle & WS_MAXIMIZEBOX)
951 rect.right -= SYSMETRICS_CXSIZE + 1;
952 pt.x = wndPtr->rectWindow.left + (rect.right - rect.left) / 2;
953 pt.y = wndPtr->rectWindow.top + rect.top + SYSMETRICS_CYSIZE/2;
954 if (wndPtr->dwStyle & WS_CHILD)
955 ClientToScreen16( wndPtr->parent->hwndSelf, &pt );
956 hittest = HTCAPTION;
958 else /* SC_SIZE */
960 SetCapture32(hwnd);
961 while(!hittest)
963 MSG_InternalGetMessage( &msg, 0, 0, MSGF_SIZE, PM_REMOVE, FALSE );
964 switch(msg.message)
966 case WM_MOUSEMOVE:
967 hittest = NC_HandleNCHitTest( hwnd, msg.pt );
968 pt = msg.pt;
969 if ((hittest < HTLEFT) || (hittest > HTBOTTOMRIGHT))
970 hittest = 0;
971 break;
973 case WM_LBUTTONUP:
974 return 0;
976 case WM_KEYDOWN:
977 switch(msg.wParam)
979 case VK_UP:
980 hittest = HTTOP;
981 pt.x =(wndPtr->rectWindow.left+wndPtr->rectWindow.right)/2;
982 pt.y = wndPtr->rectWindow.top + SYSMETRICS_CYFRAME / 2;
983 break;
984 case VK_DOWN:
985 hittest = HTBOTTOM;
986 pt.x =(wndPtr->rectWindow.left+wndPtr->rectWindow.right)/2;
987 pt.y = wndPtr->rectWindow.bottom - SYSMETRICS_CYFRAME / 2;
988 break;
989 case VK_LEFT:
990 hittest = HTLEFT;
991 pt.x = wndPtr->rectWindow.left + SYSMETRICS_CXFRAME / 2;
992 pt.y =(wndPtr->rectWindow.top+wndPtr->rectWindow.bottom)/2;
993 break;
994 case VK_RIGHT:
995 hittest = HTRIGHT;
996 pt.x = wndPtr->rectWindow.right - SYSMETRICS_CXFRAME / 2;
997 pt.y =(wndPtr->rectWindow.top+wndPtr->rectWindow.bottom)/2;
998 break;
999 case VK_RETURN:
1000 case VK_ESCAPE: return 0;
1005 *capturePoint = pt;
1006 SetCursorPos32( capturePoint->x, capturePoint->y );
1007 NC_HandleSetCursor( hwnd, (WPARAM16)hwnd, MAKELONG( hittest, WM_MOUSEMOVE ));
1008 return hittest;
1012 /***********************************************************************
1013 * NC_DoSizeMove
1015 * Perform SC_MOVE and SC_SIZE commands.
1017 static void NC_DoSizeMove( HWND32 hwnd, WORD wParam, POINT16 pt )
1019 MSG16 msg;
1020 RECT16 sizingRect, mouseRect;
1021 HDC32 hdc;
1022 LONG hittest = (LONG)(wParam & 0x0f);
1023 HCURSOR16 hDragCursor = 0, hOldCursor = 0;
1024 POINT16 minTrack, maxTrack, capturePoint = pt;
1025 WND * wndPtr = WIN_FindWndPtr( hwnd );
1026 BOOL32 thickframe = HAS_THICKFRAME( wndPtr->dwStyle );
1027 BOOL32 iconic = wndPtr->dwStyle & WS_MINIMIZE;
1028 int moved = 0;
1030 if (IsZoomed32(hwnd) || !IsWindowVisible32(hwnd) ||
1031 (wndPtr->flags & WIN_MANAGED)) return;
1033 if ((wParam & 0xfff0) == SC_MOVE)
1035 if (!(wndPtr->dwStyle & WS_CAPTION)) return;
1036 if (!hittest) hittest = NC_StartSizeMove( hwnd, wParam, &capturePoint );
1037 if (!hittest) return;
1039 else /* SC_SIZE */
1041 if (!thickframe) return;
1042 if (hittest) hittest += HTLEFT-1;
1043 else
1045 SetCapture32(hwnd);
1046 hittest = NC_StartSizeMove( hwnd, wParam, &capturePoint );
1047 if (!hittest)
1049 ReleaseCapture();
1050 return;
1055 /* Get min/max info */
1057 NC_GetMinMaxInfo( wndPtr, NULL, NULL, &minTrack, &maxTrack );
1058 sizingRect = wndPtr->rectWindow;
1059 if (wndPtr->dwStyle & WS_CHILD)
1060 GetClientRect16( wndPtr->parent->hwndSelf, &mouseRect );
1061 else SetRect16(&mouseRect, 0, 0, SYSMETRICS_CXSCREEN, SYSMETRICS_CYSCREEN);
1062 if (ON_LEFT_BORDER(hittest))
1064 mouseRect.left = MAX( mouseRect.left, sizingRect.right-maxTrack.x );
1065 mouseRect.right = MIN( mouseRect.right, sizingRect.right-minTrack.x );
1067 else if (ON_RIGHT_BORDER(hittest))
1069 mouseRect.left = MAX( mouseRect.left, sizingRect.left+minTrack.x );
1070 mouseRect.right = MIN( mouseRect.right, sizingRect.left+maxTrack.x );
1072 if (ON_TOP_BORDER(hittest))
1074 mouseRect.top = MAX( mouseRect.top, sizingRect.bottom-maxTrack.y );
1075 mouseRect.bottom = MIN( mouseRect.bottom,sizingRect.bottom-minTrack.y);
1077 else if (ON_BOTTOM_BORDER(hittest))
1079 mouseRect.top = MAX( mouseRect.top, sizingRect.top+minTrack.y );
1080 mouseRect.bottom = MIN( mouseRect.bottom, sizingRect.top+maxTrack.y );
1082 SendMessage16( hwnd, WM_ENTERSIZEMOVE, 0, 0 );
1084 if (GetCapture32() != hwnd) SetCapture32( hwnd );
1086 if (wndPtr->dwStyle & WS_CHILD)
1088 /* Retrieve a default cache DC (without using the window style) */
1089 hdc = GetDCEx32( wndPtr->parent->hwndSelf, 0, DCX_CACHE );
1091 else
1092 { /* Grab the server only when moving top-level windows without desktop */
1093 hdc = GetDC32( 0 );
1094 if (rootWindow == DefaultRootWindow(display)) XGrabServer( display );
1097 if( iconic )
1099 HICON16 hIcon = (wndPtr->class->hIcon)
1100 ? wndPtr->class->hIcon
1101 : (HICON16)SendMessage16( hwnd, WM_QUERYDRAGICON, 0, 0L);
1102 if( hIcon )
1104 hDragCursor = CURSORICON_IconToCursor( hIcon, TRUE );
1105 hOldCursor = SetCursor32(hDragCursor);
1106 ShowCursor32( TRUE );
1107 } else iconic = FALSE;
1110 if( !iconic ) NC_DrawMovingFrame( hdc, &sizingRect, thickframe );
1112 while(1)
1114 int dx = 0, dy = 0;
1116 MSG_InternalGetMessage( &msg, 0, 0, MSGF_SIZE, PM_REMOVE, FALSE );
1118 /* Exit on button-up, Return, or Esc */
1119 if ((msg.message == WM_LBUTTONUP) ||
1120 ((msg.message == WM_KEYDOWN) &&
1121 ((msg.wParam == VK_RETURN) || (msg.wParam == VK_ESCAPE)))) break;
1123 if ((msg.message != WM_KEYDOWN) && (msg.message != WM_MOUSEMOVE))
1124 continue; /* We are not interested in other messages */
1126 pt = msg.pt;
1127 if (wndPtr->dwStyle & WS_CHILD)
1128 ScreenToClient16( wndPtr->parent->hwndSelf, &pt );
1130 if (msg.message == WM_KEYDOWN) switch(msg.wParam)
1132 case VK_UP: pt.y -= 8; break;
1133 case VK_DOWN: pt.y += 8; break;
1134 case VK_LEFT: pt.x -= 8; break;
1135 case VK_RIGHT: pt.x += 8; break;
1138 pt.x = MAX( pt.x, mouseRect.left );
1139 pt.x = MIN( pt.x, mouseRect.right );
1140 pt.y = MAX( pt.y, mouseRect.top );
1141 pt.y = MIN( pt.y, mouseRect.bottom );
1143 dx = pt.x - capturePoint.x;
1144 dy = pt.y - capturePoint.y;
1146 if (dx || dy)
1148 moved = 1;
1149 if (msg.message == WM_KEYDOWN) SetCursorPos32( pt.x, pt.y );
1150 else
1152 RECT16 newRect = sizingRect;
1154 if (hittest == HTCAPTION) OffsetRect16( &newRect, dx, dy );
1155 if (ON_LEFT_BORDER(hittest)) newRect.left += dx;
1156 else if (ON_RIGHT_BORDER(hittest)) newRect.right += dx;
1157 if (ON_TOP_BORDER(hittest)) newRect.top += dy;
1158 else if (ON_BOTTOM_BORDER(hittest)) newRect.bottom += dy;
1159 if( !iconic )
1161 NC_DrawMovingFrame( hdc, &sizingRect, thickframe );
1162 NC_DrawMovingFrame( hdc, &newRect, thickframe );
1164 capturePoint = pt;
1165 sizingRect = newRect;
1170 ReleaseCapture();
1171 if( iconic )
1173 ShowCursor32( FALSE );
1174 SetCursor32(hOldCursor);
1175 if( hDragCursor ) DestroyCursor32( hDragCursor );
1177 else
1178 NC_DrawMovingFrame( hdc, &sizingRect, thickframe );
1180 if (wndPtr->dwStyle & WS_CHILD)
1181 ReleaseDC32( wndPtr->parent->hwndSelf, hdc );
1182 else
1184 ReleaseDC32( 0, hdc );
1185 if (rootWindow == DefaultRootWindow(display)) XUngrabServer( display );
1188 if (HOOK_IsHooked( WH_CBT ))
1190 RECT16* pr = SEGPTR_NEW(RECT16);
1191 if( pr )
1193 *pr = sizingRect;
1194 if( HOOK_CallHooks16( WH_CBT, HCBT_MOVESIZE, hwnd,
1195 (LPARAM)SEGPTR_GET(pr)) )
1196 sizingRect = wndPtr->rectWindow;
1197 else
1198 sizingRect = *pr;
1199 SEGPTR_FREE(pr);
1202 SendMessage16( hwnd, WM_EXITSIZEMOVE, 0, 0 );
1203 SendMessage16( hwnd, WM_SETVISIBLE, !IsIconic16(hwnd), 0L);
1205 /* Single click brings up the system menu when iconized */
1207 if (!moved && (wndPtr->dwStyle & WS_MINIMIZE))
1209 NC_TrackSysMenu( hwnd, pt );
1210 return;
1213 /* If Esc key, don't move the window */
1214 if ((msg.message == WM_KEYDOWN) && (msg.wParam == VK_ESCAPE)) return;
1216 if (hittest != HTCAPTION)
1217 SetWindowPos32( hwnd, 0, sizingRect.left, sizingRect.top,
1218 sizingRect.right - sizingRect.left,
1219 sizingRect.bottom - sizingRect.top,
1220 SWP_NOACTIVATE | SWP_NOZORDER );
1221 else SetWindowPos32( hwnd, 0, sizingRect.left, sizingRect.top, 0, 0,
1222 SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER );
1226 /***********************************************************************
1227 * NC_TrackMinMaxBox
1229 * Track a mouse button press on the minimize or maximize box.
1231 static void NC_TrackMinMaxBox( HWND32 hwnd, WORD wParam )
1233 MSG16 msg;
1234 HDC32 hdc = GetWindowDC32( hwnd );
1235 BOOL32 pressed = TRUE;
1237 SetCapture32( hwnd );
1238 if (wParam == HTMINBUTTON) NC_DrawMinButton( hwnd, hdc, TRUE );
1239 else NC_DrawMaxButton( hwnd, hdc, TRUE );
1243 BOOL32 oldstate = pressed;
1244 MSG_InternalGetMessage( &msg, 0, 0, 0, PM_REMOVE, FALSE );
1246 pressed = (NC_HandleNCHitTest( hwnd, msg.pt ) == wParam);
1247 if (pressed != oldstate)
1249 if (wParam == HTMINBUTTON) NC_DrawMinButton( hwnd, hdc, pressed );
1250 else NC_DrawMaxButton( hwnd, hdc, pressed );
1252 } while (msg.message != WM_LBUTTONUP);
1254 if (wParam == HTMINBUTTON) NC_DrawMinButton( hwnd, hdc, FALSE );
1255 else NC_DrawMaxButton( hwnd, hdc, FALSE );
1257 ReleaseCapture();
1258 ReleaseDC32( hwnd, hdc );
1259 if (!pressed) return;
1261 if (wParam == HTMINBUTTON)
1262 SendMessage16( hwnd, WM_SYSCOMMAND, SC_MINIMIZE, *(LONG*)&msg.pt );
1263 else
1264 SendMessage16( hwnd, WM_SYSCOMMAND,
1265 IsZoomed32(hwnd) ? SC_RESTORE:SC_MAXIMIZE, *(LONG*)&msg.pt );
1269 /***********************************************************************
1270 * NC_TrackScrollBar
1272 * Track a mouse button press on the horizontal or vertical scroll-bar.
1274 static void NC_TrackScrollBar( HWND32 hwnd, WPARAM32 wParam, POINT32 pt )
1276 MSG16 *msg;
1277 INT32 scrollbar;
1278 WND *wndPtr = WIN_FindWndPtr( hwnd );
1280 if ((wParam & 0xfff0) == SC_HSCROLL)
1282 if ((wParam & 0x0f) != HTHSCROLL) return;
1283 scrollbar = SB_HORZ;
1285 else /* SC_VSCROLL */
1287 if ((wParam & 0x0f) != HTVSCROLL) return;
1288 scrollbar = SB_VERT;
1291 if (!(msg = SEGPTR_NEW(MSG16))) return;
1292 pt.x -= wndPtr->rectWindow.left;
1293 pt.y -= wndPtr->rectWindow.top;
1294 SetCapture32( hwnd );
1295 SCROLL_HandleScrollEvent( hwnd, scrollbar, WM_LBUTTONDOWN, pt );
1299 GetMessage16( SEGPTR_GET(msg), 0, 0, 0 );
1300 switch(msg->message)
1302 case WM_LBUTTONUP:
1303 case WM_MOUSEMOVE:
1304 case WM_SYSTIMER:
1305 pt.x = LOWORD(msg->lParam) + wndPtr->rectClient.left -
1306 wndPtr->rectWindow.left;
1307 pt.y = HIWORD(msg->lParam) + wndPtr->rectClient.top -
1308 wndPtr->rectWindow.top;
1309 SCROLL_HandleScrollEvent( hwnd, scrollbar, msg->message, pt );
1310 break;
1311 default:
1312 TranslateMessage16( msg );
1313 DispatchMessage16( msg );
1314 break;
1316 if (!IsWindow32( hwnd ))
1318 ReleaseCapture();
1319 break;
1321 } while (msg->message != WM_LBUTTONUP);
1322 SEGPTR_FREE(msg);
1325 /***********************************************************************
1326 * NC_HandleNCLButtonDown
1328 * Handle a WM_NCLBUTTONDOWN message. Called from DefWindowProc().
1330 LONG NC_HandleNCLButtonDown( HWND32 hwnd, WPARAM16 wParam, LPARAM lParam )
1332 switch(wParam) /* Hit test */
1334 case HTCAPTION:
1335 SendMessage16( hwnd, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, lParam );
1336 break;
1338 case HTSYSMENU:
1339 NC_TrackSysMenu( hwnd, MAKEPOINT16(lParam) );
1340 break;
1342 case HTMENU:
1343 SendMessage16( hwnd, WM_SYSCOMMAND, SC_MOUSEMENU, lParam );
1344 break;
1346 case HTHSCROLL:
1347 SendMessage16( hwnd, WM_SYSCOMMAND, SC_HSCROLL + HTHSCROLL, lParam );
1348 break;
1350 case HTVSCROLL:
1351 SendMessage16( hwnd, WM_SYSCOMMAND, SC_VSCROLL + HTVSCROLL, lParam );
1352 break;
1354 case HTMINBUTTON:
1355 case HTMAXBUTTON:
1356 NC_TrackMinMaxBox( hwnd, wParam );
1357 break;
1359 case HTLEFT:
1360 case HTRIGHT:
1361 case HTTOP:
1362 case HTTOPLEFT:
1363 case HTTOPRIGHT:
1364 case HTBOTTOM:
1365 case HTBOTTOMLEFT:
1366 case HTBOTTOMRIGHT:
1367 SendMessage16( hwnd, WM_SYSCOMMAND, SC_SIZE + wParam - HTLEFT+1, lParam);
1368 break;
1370 case HTBORDER:
1371 break;
1373 return 0;
1377 /***********************************************************************
1378 * NC_HandleNCLButtonDblClk
1380 * Handle a WM_NCLBUTTONDBLCLK message. Called from DefWindowProc().
1382 LONG NC_HandleNCLButtonDblClk( WND *pWnd, WPARAM16 wParam, LPARAM lParam )
1385 * if this is an icon, send a restore since we are handling
1386 * a double click
1388 if (pWnd->dwStyle & WS_MINIMIZE)
1390 SendMessage16( pWnd->hwndSelf, WM_SYSCOMMAND, SC_RESTORE, lParam );
1391 return 0;
1394 switch(wParam) /* Hit test */
1396 case HTCAPTION:
1397 /* stop processing if WS_MAXIMIZEBOX is missing */
1398 if (pWnd->dwStyle & WS_MAXIMIZEBOX)
1399 SendMessage16( pWnd->hwndSelf, WM_SYSCOMMAND,
1400 (pWnd->dwStyle & WS_MAXIMIZE) ? SC_RESTORE : SC_MAXIMIZE,
1401 lParam );
1402 break;
1404 case HTSYSMENU:
1405 if (!(pWnd->class->style & CS_NOCLOSE))
1406 SendMessage16( pWnd->hwndSelf, WM_SYSCOMMAND, SC_CLOSE, lParam );
1407 break;
1409 return 0;
1413 /***********************************************************************
1414 * NC_HandleSysCommand
1416 * Handle a WM_SYSCOMMAND message. Called from DefWindowProc().
1418 LONG NC_HandleSysCommand( HWND32 hwnd, WPARAM16 wParam, POINT16 pt )
1420 WND *wndPtr = WIN_FindWndPtr( hwnd );
1421 POINT32 pt32;
1423 dprintf_nonclient(stddeb, "Handling WM_SYSCOMMAND %x %d,%d\n",
1424 wParam, pt.x, pt.y );
1426 if (wndPtr->dwStyle & WS_CHILD && wParam != SC_KEYMENU )
1427 ScreenToClient16( wndPtr->parent->hwndSelf, &pt );
1429 switch (wParam & 0xfff0)
1431 case SC_SIZE:
1432 case SC_MOVE:
1433 NC_DoSizeMove( hwnd, wParam, pt );
1434 break;
1436 case SC_MINIMIZE:
1437 ShowWindow32( hwnd, SW_MINIMIZE );
1438 break;
1440 case SC_MAXIMIZE:
1441 ShowWindow32( hwnd, SW_MAXIMIZE );
1442 break;
1444 case SC_RESTORE:
1445 ShowWindow32( hwnd, SW_RESTORE );
1446 break;
1448 case SC_CLOSE:
1449 return SendMessage16( hwnd, WM_CLOSE, 0, 0 );
1451 case SC_VSCROLL:
1452 case SC_HSCROLL:
1453 CONV_POINT16TO32( &pt, &pt32 );
1454 NC_TrackScrollBar( hwnd, wParam, pt32 );
1455 break;
1457 case SC_MOUSEMENU:
1458 CONV_POINT16TO32( &pt, &pt32 );
1459 MENU_TrackMouseMenuBar( wndPtr, wParam & 0x000F, pt32 );
1460 break;
1462 case SC_KEYMENU:
1463 MENU_TrackKbdMenuBar( wndPtr , wParam , pt.x );
1464 break;
1466 case SC_TASKLIST:
1467 WinExec32( "taskman.exe", SW_SHOWNORMAL );
1468 break;
1470 case SC_SCREENSAVE:
1471 if (wParam == SC_ABOUTWINE)
1473 extern const char people[];
1474 ShellAbout32A(hwnd,"Wine",people,0);
1476 break;
1478 case SC_HOTKEY:
1479 case SC_ARRANGE:
1480 case SC_NEXTWINDOW:
1481 case SC_PREVWINDOW:
1482 /* FIXME: unimplemented */
1483 break;
1485 return 0;