Release 961222
[wine/gsoc-2012-control.git] / windows / nonclient.c
blob4c6a2d53503304a30094063e1b7194ce2e80147b
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, BOOL menu, DWORD exStyle)
69 if(style & WS_ICONIC) return;
70 /* Decide if the window will be managed (see CreateWindowEx) */
71 if (!(Options.managed && !(style & WS_CHILD) &&
72 ((style & (WS_DLGFRAME | WS_THICKFRAME)) ||
73 (exStyle & WS_EX_DLGMODALFRAME))))
75 if (HAS_DLGFRAME( style, exStyle ))
76 InflateRect16(rect, SYSMETRICS_CXDLGFRAME, SYSMETRICS_CYDLGFRAME );
77 else
79 if (HAS_THICKFRAME(style))
80 InflateRect16( rect, SYSMETRICS_CXFRAME, SYSMETRICS_CYFRAME );
81 if (style & WS_BORDER)
82 InflateRect16( rect, SYSMETRICS_CXBORDER, SYSMETRICS_CYBORDER);
85 if ((style & WS_CAPTION) == WS_CAPTION)
86 rect->top -= SYSMETRICS_CYCAPTION - SYSMETRICS_CYBORDER;
88 if (menu) rect->top -= SYSMETRICS_CYMENU + SYSMETRICS_CYBORDER;
90 if (style & WS_VSCROLL) rect->right += SYSMETRICS_CXVSCROLL;
91 if (style & WS_HSCROLL) rect->bottom += SYSMETRICS_CYHSCROLL;
95 /***********************************************************************
96 * AdjustWindowRect16 (USER.102)
98 BOOL16 AdjustWindowRect16( LPRECT16 rect, DWORD style, BOOL16 menu )
100 return AdjustWindowRectEx16( rect, style, menu, 0 );
104 /***********************************************************************
105 * AdjustWindowRect32 (USER32.)
107 BOOL32 AdjustWindowRect32( LPRECT32 rect, DWORD style, BOOL32 menu )
109 return AdjustWindowRectEx32( rect, style, menu, 0 );
113 /***********************************************************************
114 * AdjustWindowRectEx16 (USER.454)
116 BOOL16 AdjustWindowRectEx16( LPRECT16 rect, DWORD style,
117 BOOL16 menu, DWORD exStyle )
119 /* Correct the window style */
121 if (!(style & (WS_POPUP | WS_CHILD))) /* Overlapped window */
122 style |= WS_CAPTION;
123 style &= (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME);
124 exStyle &= WS_EX_DLGMODALFRAME;
125 if (exStyle & WS_EX_DLGMODALFRAME) style &= ~WS_THICKFRAME;
127 dprintf_nonclient(stddeb, "AdjustWindowRectEx: (%d,%d)-(%d,%d) %08lx %d %08lx\n",
128 rect->left, rect->top, rect->right, rect->bottom,
129 style, menu, exStyle );
131 NC_AdjustRect( rect, style, menu, exStyle );
132 return TRUE;
136 /***********************************************************************
137 * AdjustWindowRectEx32 (USER32.)
139 BOOL32 AdjustWindowRectEx32( LPRECT32 rect, DWORD style,
140 BOOL32 menu, DWORD exStyle )
142 RECT16 rect16;
143 BOOL32 ret;
145 CONV_RECT32TO16( rect, &rect16 );
146 ret = AdjustWindowRectEx16( &rect16, style, (BOOL16)menu, exStyle );
147 CONV_RECT16TO32( &rect16, rect );
148 return ret;
152 /*******************************************************************
153 * NC_GetMinMaxInfo
155 * Get the minimized and maximized information for a window.
157 void NC_GetMinMaxInfo( WND *wndPtr, POINT16 *maxSize, POINT16 *maxPos,
158 POINT16 *minTrack, POINT16 *maxTrack )
160 MINMAXINFO16 *MinMax;
161 short xinc, yinc;
163 if (!(MinMax = SEGPTR_NEW(MINMAXINFO16))) return;
165 /* Compute default values */
167 MinMax->ptMaxSize.x = SYSMETRICS_CXSCREEN;
168 MinMax->ptMaxSize.y = SYSMETRICS_CYSCREEN;
169 MinMax->ptMinTrackSize.x = SYSMETRICS_CXMINTRACK;
170 MinMax->ptMinTrackSize.y = SYSMETRICS_CYMINTRACK;
171 MinMax->ptMaxTrackSize.x = SYSMETRICS_CXSCREEN;
172 MinMax->ptMaxTrackSize.y = SYSMETRICS_CYSCREEN;
174 if (wndPtr->flags & WIN_MANAGED) xinc = yinc = 0;
175 else if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
177 xinc = SYSMETRICS_CXDLGFRAME;
178 yinc = SYSMETRICS_CYDLGFRAME;
180 else
182 xinc = yinc = 0;
183 if (HAS_THICKFRAME(wndPtr->dwStyle))
185 xinc += SYSMETRICS_CXFRAME;
186 yinc += SYSMETRICS_CYFRAME;
188 if (wndPtr->dwStyle & WS_BORDER)
190 xinc += SYSMETRICS_CXBORDER;
191 yinc += SYSMETRICS_CYBORDER;
194 MinMax->ptMaxSize.x += 2 * xinc;
195 MinMax->ptMaxSize.y += 2 * yinc;
197 /* Note: The '+' in the following test should really be a ||, but
198 * that would cause gcc-2.7.0 to generate incorrect code.
200 if ((wndPtr->ptMaxPos.x != -1) + (wndPtr->ptMaxPos.y != -1))
201 MinMax->ptMaxPosition = wndPtr->ptMaxPos;
202 else
204 MinMax->ptMaxPosition.x = -xinc;
205 MinMax->ptMaxPosition.y = -yinc;
208 SendMessage16( wndPtr->hwndSelf, WM_GETMINMAXINFO, 0,
209 (LPARAM)SEGPTR_GET(MinMax) );
211 /* Some sanity checks */
213 dprintf_nonclient(stddeb,
214 "NC_GetMinMaxInfo: %d %d / %d %d / %d %d / %d %d\n",
215 MinMax->ptMaxSize.x, MinMax->ptMaxSize.y,
216 MinMax->ptMaxPosition.x, MinMax->ptMaxPosition.y,
217 MinMax->ptMaxTrackSize.x, MinMax->ptMaxTrackSize.y,
218 MinMax->ptMinTrackSize.x, MinMax->ptMinTrackSize.y);
219 MinMax->ptMaxTrackSize.x = MAX( MinMax->ptMaxTrackSize.x,
220 MinMax->ptMinTrackSize.x );
221 MinMax->ptMaxTrackSize.y = MAX( MinMax->ptMaxTrackSize.y,
222 MinMax->ptMinTrackSize.y );
224 if (maxSize) *maxSize = MinMax->ptMaxSize;
225 if (maxPos) *maxPos = MinMax->ptMaxPosition;
226 if (minTrack) *minTrack = MinMax->ptMinTrackSize;
227 if (maxTrack) *maxTrack = MinMax->ptMaxTrackSize;
228 SEGPTR_FREE(MinMax);
232 /***********************************************************************
233 * NC_HandleNCCalcSize
235 * Handle a WM_NCCALCSIZE message. Called from DefWindowProc().
237 LONG NC_HandleNCCalcSize( WND *pWnd, RECT16 *winRect )
239 RECT16 tmpRect = { 0, 0, 0, 0 };
240 LONG result = 0;
242 if (pWnd->class->style & CS_VREDRAW) result |= WVR_VREDRAW;
243 if (pWnd->class->style & CS_HREDRAW) result |= WVR_HREDRAW;
245 if( !( pWnd->dwStyle & WS_MINIMIZE ) )
247 NC_AdjustRect( &tmpRect, pWnd->dwStyle, FALSE, pWnd->dwExStyle );
248 winRect->left -= tmpRect.left;
249 winRect->top -= tmpRect.top;
250 winRect->right -= tmpRect.right;
251 winRect->bottom -= tmpRect.bottom;
253 if (HAS_MENU(pWnd))
255 winRect->top += MENU_GetMenuBarHeight( pWnd->hwndSelf,
256 winRect->right - winRect->left,
257 -tmpRect.left, -tmpRect.top ) + 1;
260 return result;
264 /***********************************************************************
265 * NC_GetInsideRect
267 * Get the 'inside' rectangle of a window, i.e. the whole window rectangle
268 * but without the borders (if any).
269 * The rectangle is in window coordinates (for drawing with GetWindowDC()).
271 static void NC_GetInsideRect( HWND hwnd, RECT16 *rect )
273 WND * wndPtr = WIN_FindWndPtr( hwnd );
275 rect->top = rect->left = 0;
276 rect->right = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
277 rect->bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
279 if (wndPtr->dwStyle & WS_ICONIC) return; /* No border to remove */
280 if (wndPtr->flags & WIN_MANAGED) return;
282 /* Remove frame from rectangle */
283 if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
285 InflateRect16( rect, -SYSMETRICS_CXDLGFRAME, -SYSMETRICS_CYDLGFRAME);
286 if (wndPtr->dwExStyle & WS_EX_DLGMODALFRAME)
287 InflateRect16( rect, -1, 0 );
289 else
291 if (HAS_THICKFRAME( wndPtr->dwStyle ))
292 InflateRect16( rect, -SYSMETRICS_CXFRAME, -SYSMETRICS_CYFRAME );
293 if (wndPtr->dwStyle & WS_BORDER)
294 InflateRect16( rect, -SYSMETRICS_CXBORDER, -SYSMETRICS_CYBORDER );
299 /***********************************************************************
300 * NC_HandleNCHitTest
302 * Handle a WM_NCHITTEST message. Called from DefWindowProc().
304 LONG NC_HandleNCHitTest( HWND32 hwnd, POINT16 pt )
306 RECT16 rect;
307 WND *wndPtr = WIN_FindWndPtr( hwnd );
308 if (!wndPtr) return HTERROR;
310 dprintf_nonclient(stddeb, "NC_HandleNCHitTest: hwnd=%04x pt=%d,%d\n",
311 hwnd, pt.x, pt.y );
313 GetWindowRect16( hwnd, &rect );
314 if (!PtInRect16( &rect, pt )) return HTNOWHERE;
316 if (wndPtr->dwStyle & WS_MINIMIZE) return HTCAPTION;
318 if (!(wndPtr->flags & WIN_MANAGED))
320 /* Check borders */
321 if (HAS_THICKFRAME( wndPtr->dwStyle ))
323 InflateRect16( &rect, -SYSMETRICS_CXFRAME, -SYSMETRICS_CYFRAME );
324 if (wndPtr->dwStyle & WS_BORDER)
325 InflateRect16(&rect,-SYSMETRICS_CXBORDER,-SYSMETRICS_CYBORDER);
326 if (!PtInRect16( &rect, pt ))
328 /* Check top sizing border */
329 if (pt.y < rect.top)
331 if (pt.x < rect.left+SYSMETRICS_CXSIZE) return HTTOPLEFT;
332 if (pt.x >= rect.right-SYSMETRICS_CXSIZE) return HTTOPRIGHT;
333 return HTTOP;
335 /* Check bottom sizing border */
336 if (pt.y >= rect.bottom)
338 if (pt.x < rect.left+SYSMETRICS_CXSIZE) return HTBOTTOMLEFT;
339 if (pt.x >= rect.right-SYSMETRICS_CXSIZE) return HTBOTTOMRIGHT;
340 return HTBOTTOM;
342 /* Check left sizing border */
343 if (pt.x < rect.left)
345 if (pt.y < rect.top+SYSMETRICS_CYSIZE) return HTTOPLEFT;
346 if (pt.y >= rect.bottom-SYSMETRICS_CYSIZE) return HTBOTTOMLEFT;
347 return HTLEFT;
349 /* Check right sizing border */
350 if (pt.x >= rect.right)
352 if (pt.y < rect.top+SYSMETRICS_CYSIZE) return HTTOPRIGHT;
353 if (pt.y >= rect.bottom-SYSMETRICS_CYSIZE) return HTBOTTOMRIGHT;
354 return HTRIGHT;
358 else /* No thick frame */
360 if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
361 InflateRect16(&rect, -SYSMETRICS_CXDLGFRAME, -SYSMETRICS_CYDLGFRAME);
362 else if (wndPtr->dwStyle & WS_BORDER)
363 InflateRect16(&rect, -SYSMETRICS_CXBORDER, -SYSMETRICS_CYBORDER);
364 if (!PtInRect16( &rect, pt )) return HTBORDER;
367 /* Check caption */
369 if ((wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION)
371 rect.top += SYSMETRICS_CYCAPTION - 1;
372 if (!PtInRect16( &rect, pt ))
374 /* Check system menu */
375 if (wndPtr->dwStyle & WS_SYSMENU)
376 rect.left += SYSMETRICS_CXSIZE;
377 if (pt.x <= rect.left) return HTSYSMENU;
378 /* Check maximize box */
379 if (wndPtr->dwStyle & WS_MAXIMIZEBOX)
380 rect.right -= SYSMETRICS_CXSIZE + 1;
381 if (pt.x >= rect.right) return HTMAXBUTTON;
382 /* Check minimize box */
383 if (wndPtr->dwStyle & WS_MINIMIZEBOX)
384 rect.right -= SYSMETRICS_CXSIZE + 1;
385 if (pt.x >= rect.right) return HTMINBUTTON;
386 return HTCAPTION;
391 /* Check client area */
393 ScreenToClient16( hwnd, &pt );
394 GetClientRect16( hwnd, &rect );
395 if (PtInRect16( &rect, pt )) return HTCLIENT;
397 /* Check vertical scroll bar */
399 if (wndPtr->dwStyle & WS_VSCROLL)
401 rect.right += SYSMETRICS_CXVSCROLL;
402 if (PtInRect16( &rect, pt )) return HTVSCROLL;
405 /* Check horizontal scroll bar */
407 if (wndPtr->dwStyle & WS_HSCROLL)
409 rect.bottom += SYSMETRICS_CYHSCROLL;
410 if (PtInRect16( &rect, pt ))
412 /* Check size box */
413 if ((wndPtr->dwStyle & WS_VSCROLL) &&
414 (pt.x >= rect.right - SYSMETRICS_CXVSCROLL))
415 return HTSIZE;
416 return HTHSCROLL;
420 /* Check menu bar */
422 if (HAS_MENU(wndPtr))
424 if ((pt.y < 0) && (pt.x >= 0) && (pt.x < rect.right))
425 return HTMENU;
428 /* Should never get here */
429 return HTERROR;
433 /***********************************************************************
434 * NC_DrawSysButton
436 void NC_DrawSysButton( HWND hwnd, HDC16 hdc, BOOL down )
438 RECT16 rect;
439 HDC32 hdcMem;
440 HBITMAP32 hbitmap;
441 WND *wndPtr = WIN_FindWndPtr( hwnd );
443 if( !(wndPtr->flags & WIN_MANAGED) )
445 NC_GetInsideRect( hwnd, &rect );
446 hdcMem = CreateCompatibleDC32( hdc );
447 hbitmap = SelectObject32( hdcMem, hbitmapClose );
448 BitBlt32(hdc, rect.left, rect.top, SYSMETRICS_CXSIZE, SYSMETRICS_CYSIZE,
449 hdcMem, (wndPtr->dwStyle & WS_CHILD) ? SYSMETRICS_CXSIZE : 0, 0,
450 down ? NOTSRCCOPY : SRCCOPY );
451 SelectObject32( hdcMem, hbitmap );
452 DeleteDC32( hdcMem );
457 /***********************************************************************
458 * NC_DrawMaxButton
460 static void NC_DrawMaxButton( HWND hwnd, HDC16 hdc, BOOL down )
462 RECT16 rect;
463 WND *wndPtr = WIN_FindWndPtr( hwnd );
465 if( !(wndPtr->flags & WIN_MANAGED) )
467 NC_GetInsideRect( hwnd, &rect );
468 GRAPH_DrawBitmap( hdc, (IsZoomed(hwnd) ?
469 (down ? hbitmapRestoreD : hbitmapRestore) :
470 (down ? hbitmapMaximizeD : hbitmapMaximize)),
471 rect.right - SYSMETRICS_CXSIZE - 1, rect.top,
472 0, 0, SYSMETRICS_CXSIZE+1, SYSMETRICS_CYSIZE );
477 /***********************************************************************
478 * NC_DrawMinButton
480 static void NC_DrawMinButton( HWND hwnd, HDC16 hdc, BOOL down )
482 RECT16 rect;
483 WND *wndPtr = WIN_FindWndPtr( hwnd );
485 if( !(wndPtr->flags & WIN_MANAGED) )
487 NC_GetInsideRect( hwnd, &rect );
488 if (wndPtr->dwStyle & WS_MAXIMIZEBOX) rect.right -= SYSMETRICS_CXSIZE + 1;
489 GRAPH_DrawBitmap( hdc, (down ? hbitmapMinimizeD : hbitmapMinimize),
490 rect.right - SYSMETRICS_CXSIZE - 1, rect.top,
491 0, 0, SYSMETRICS_CXSIZE+1, SYSMETRICS_CYSIZE );
496 /***********************************************************************
497 * NC_DrawFrame
499 * Draw a window frame inside the given rectangle, and update the rectangle.
500 * The correct pen for the frame must be selected in the DC.
502 static void NC_DrawFrame( HDC16 hdc, RECT16 *rect, BOOL dlgFrame, BOOL active )
504 short width, height, tmp;
506 if (dlgFrame)
508 width = SYSMETRICS_CXDLGFRAME - 1;
509 height = SYSMETRICS_CYDLGFRAME - 1;
510 SelectObject32( hdc, active ? sysColorObjects.hbrushActiveCaption :
511 sysColorObjects.hbrushInactiveCaption );
513 else
515 width = SYSMETRICS_CXFRAME - 1;
516 height = SYSMETRICS_CYFRAME - 1;
517 SelectObject32( hdc, active ? sysColorObjects.hbrushActiveBorder :
518 sysColorObjects.hbrushInactiveBorder );
521 /* Draw frame */
522 PatBlt32( hdc, rect->left, rect->top,
523 rect->right - rect->left, height, PATCOPY );
524 PatBlt32( hdc, rect->left, rect->top,
525 width, rect->bottom - rect->top, PATCOPY );
526 PatBlt32( hdc, rect->left, rect->bottom,
527 rect->right - rect->left, -height, PATCOPY );
528 PatBlt32( hdc, rect->right, rect->top,
529 -width, rect->bottom - rect->top, PATCOPY );
531 if (dlgFrame)
533 InflateRect16( rect, -width, -height );
534 return;
537 /* Draw inner rectangle */
538 MoveTo( hdc, rect->left+width, rect->top+height );
539 LineTo32( hdc, rect->right-width-1, rect->top+height );
540 LineTo32( hdc, rect->right-width-1, rect->bottom-height-1 );
541 LineTo32( hdc, rect->left+width, rect->bottom-height-1 );
542 LineTo32( hdc, rect->left+width, rect->top+height );
544 /* Draw the decorations */
545 tmp = rect->top + SYSMETRICS_CYFRAME + SYSMETRICS_CYSIZE;
546 MoveTo( hdc, rect->left, tmp);
547 LineTo32( hdc, rect->left+width, tmp );
548 MoveTo( hdc, rect->right-width-1, tmp );
549 LineTo32( hdc, rect->right-1, tmp );
551 tmp = rect->bottom - 1 - SYSMETRICS_CYFRAME - SYSMETRICS_CYSIZE;
552 MoveTo( hdc, rect->left, tmp );
553 LineTo32( hdc, rect->left+width, tmp );
554 MoveTo( hdc, rect->right-width-1, tmp );
555 LineTo32( hdc, rect->right-1, tmp );
557 tmp = rect->left + SYSMETRICS_CXFRAME + SYSMETRICS_CXSIZE;
558 MoveTo( hdc, tmp, rect->top );
559 LineTo32( hdc, tmp, rect->top+height );
560 MoveTo( hdc, tmp, rect->bottom-height-1 );
561 LineTo32( hdc, tmp, rect->bottom-1 );
563 tmp = rect->right - 1 - SYSMETRICS_CXFRAME - SYSMETRICS_CYSIZE;
564 MoveTo( hdc, tmp, rect->top );
565 LineTo32( hdc, tmp, rect->top+height );
566 MoveTo( hdc, tmp, rect->bottom-height-1 );
567 LineTo32( hdc, tmp, rect->bottom-1 );
569 InflateRect16( rect, -width-1, -height-1 );
573 /***********************************************************************
574 * NC_DrawMovingFrame
576 * Draw the frame used when moving or resizing window.
578 static void NC_DrawMovingFrame( HDC16 hdc, RECT16 *rect, BOOL thickframe )
580 if (thickframe) FastWindowFrame( hdc, rect, SYSMETRICS_CXFRAME,
581 SYSMETRICS_CYFRAME, PATINVERT );
582 else DrawFocusRect16( hdc, rect );
586 /***********************************************************************
587 * NC_DrawCaption
589 * Draw the window caption.
590 * The correct pen for the window frame must be selected in the DC.
592 static void NC_DrawCaption( HDC16 hdc, RECT16 *rect, HWND hwnd,
593 DWORD style, BOOL active )
595 RECT16 r = *rect;
596 WND * wndPtr = WIN_FindWndPtr( hwnd );
597 char buffer[256];
599 if (wndPtr->flags & WIN_MANAGED) return;
601 if (!hbitmapClose)
603 if (!(hbitmapClose = LoadBitmap16( 0, MAKEINTRESOURCE(OBM_CLOSE) )))
604 return;
605 hbitmapMinimize = LoadBitmap16( 0, MAKEINTRESOURCE(OBM_REDUCE) );
606 hbitmapMinimizeD = LoadBitmap16( 0, MAKEINTRESOURCE(OBM_REDUCED) );
607 hbitmapMaximize = LoadBitmap16( 0, MAKEINTRESOURCE(OBM_ZOOM) );
608 hbitmapMaximizeD = LoadBitmap16( 0, MAKEINTRESOURCE(OBM_ZOOMD) );
609 hbitmapRestore = LoadBitmap16( 0, MAKEINTRESOURCE(OBM_RESTORE) );
610 hbitmapRestoreD = LoadBitmap16( 0, MAKEINTRESOURCE(OBM_RESTORED) );
613 if (wndPtr->dwExStyle & WS_EX_DLGMODALFRAME)
615 HBRUSH32 hbrushOld = SelectObject32(hdc, sysColorObjects.hbrushWindow);
616 PatBlt32( hdc, r.left, r.top, 1, r.bottom-r.top+1,PATCOPY );
617 PatBlt32( hdc, r.right-1, r.top, 1, r.bottom-r.top+1, PATCOPY );
618 PatBlt32( hdc, r.left, r.top-1, r.right-r.left, 1, PATCOPY );
619 r.left++;
620 r.right--;
621 SelectObject32( hdc, hbrushOld );
624 MoveTo( hdc, r.left, r.bottom );
625 LineTo32( hdc, r.right-1, r.bottom );
627 if (style & WS_SYSMENU)
629 NC_DrawSysButton( hwnd, hdc, FALSE );
630 r.left += SYSMETRICS_CXSIZE + 1;
631 MoveTo( hdc, r.left - 1, r.top );
632 LineTo32( hdc, r.left - 1, r.bottom );
634 if (style & WS_MAXIMIZEBOX)
636 NC_DrawMaxButton( hwnd, hdc, FALSE );
637 r.right -= SYSMETRICS_CXSIZE + 1;
639 if (style & WS_MINIMIZEBOX)
641 NC_DrawMinButton( hwnd, hdc, FALSE );
642 r.right -= SYSMETRICS_CXSIZE + 1;
645 FillRect16( hdc, &r, active ? sysColorObjects.hbrushActiveCaption :
646 sysColorObjects.hbrushInactiveCaption );
648 if (GetWindowText32A( hwnd, buffer, sizeof(buffer) ))
650 if (active) SetTextColor( hdc, GetSysColor( COLOR_CAPTIONTEXT ) );
651 else SetTextColor( hdc, GetSysColor( COLOR_INACTIVECAPTIONTEXT ) );
652 SetBkMode32( hdc, TRANSPARENT );
653 DrawText16( hdc, buffer, -1, &r,
654 DT_SINGLELINE | DT_CENTER | DT_VCENTER | DT_NOPREFIX );
659 /***********************************************************************
660 * NC_DoNCPaint
662 * Paint the non-client area. clip is currently unused.
664 void NC_DoNCPaint( HWND32 hwnd, HRGN32 clip, BOOL32 suppress_menupaint )
666 HDC32 hdc;
667 RECT16 rect;
668 BOOL32 active;
670 WND *wndPtr = WIN_FindWndPtr( hwnd );
672 if (!wndPtr || wndPtr->dwStyle & WS_MINIMIZE ||
673 !WIN_IsWindowDrawable( wndPtr, 0 )) return; /* Nothing to do */
675 active = wndPtr->flags & WIN_NCACTIVATED;
677 dprintf_nonclient(stddeb, "NC_DoNCPaint: %04x %d\n", hwnd, active );
679 if (!(hdc = GetDCEx32( hwnd, 0, DCX_USESTYLE | DCX_WINDOW ))) return;
681 if (ExcludeVisRect( hdc, wndPtr->rectClient.left-wndPtr->rectWindow.left,
682 wndPtr->rectClient.top-wndPtr->rectWindow.top,
683 wndPtr->rectClient.right-wndPtr->rectWindow.left,
684 wndPtr->rectClient.bottom-wndPtr->rectWindow.top )
685 == NULLREGION)
687 ReleaseDC32( hwnd, hdc );
688 return;
691 rect.top = rect.left = 0;
692 rect.right = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
693 rect.bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
695 SelectObject32( hdc, sysColorObjects.hpenWindowFrame );
697 if (!(wndPtr->flags & WIN_MANAGED))
699 if ((wndPtr->dwStyle & WS_BORDER) || (wndPtr->dwStyle & WS_DLGFRAME) ||
700 (wndPtr->dwExStyle & WS_EX_DLGMODALFRAME))
702 MoveTo( hdc, 0, 0 );
703 LineTo32( hdc, rect.right-1, 0 );
704 LineTo32( hdc, rect.right-1, rect.bottom-1 );
705 LineTo32( hdc, 0, rect.bottom-1 );
706 LineTo32( hdc, 0, 0 );
707 InflateRect16( &rect, -1, -1 );
710 if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
711 NC_DrawFrame( hdc, &rect, TRUE, active );
712 else if (wndPtr->dwStyle & WS_THICKFRAME)
713 NC_DrawFrame(hdc, &rect, FALSE, active );
715 if ((wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION)
717 RECT16 r = rect;
718 r.bottom = rect.top + SYSMETRICS_CYSIZE;
719 rect.top += SYSMETRICS_CYSIZE + SYSMETRICS_CYBORDER;
720 NC_DrawCaption( hdc, &r, hwnd, wndPtr->dwStyle, active );
724 if (HAS_MENU(wndPtr))
726 RECT16 r = rect;
727 r.bottom = rect.top + SYSMETRICS_CYMENU; /* default height */
728 rect.top += MENU_DrawMenuBar( hdc, &r, hwnd, suppress_menupaint );
731 /* Draw the scroll-bars */
733 if (wndPtr->dwStyle & WS_VSCROLL)
734 SCROLL_DrawScrollBar( hwnd, hdc, SB_VERT, TRUE );
735 if (wndPtr->dwStyle & WS_HSCROLL)
736 SCROLL_DrawScrollBar( hwnd, hdc, SB_HORZ, TRUE );
738 /* Draw the "size-box" */
740 if ((wndPtr->dwStyle & WS_VSCROLL) && (wndPtr->dwStyle & WS_HSCROLL))
742 RECT16 r = rect;
743 r.left = r.right - SYSMETRICS_CXVSCROLL + 1;
744 r.top = r.bottom - SYSMETRICS_CYHSCROLL + 1;
745 FillRect16( hdc, &r, sysColorObjects.hbrushScrollbar );
748 ReleaseDC32( hwnd, hdc );
753 /***********************************************************************
754 * NC_HandleNCPaint
756 * Handle a WM_NCPAINT message. Called from DefWindowProc().
758 LONG NC_HandleNCPaint( HWND32 hwnd , HRGN32 clip)
760 NC_DoNCPaint( hwnd, clip, FALSE );
761 return 0;
765 /***********************************************************************
766 * NC_HandleNCActivate
768 * Handle a WM_NCACTIVATE message. Called from DefWindowProc().
770 LONG NC_HandleNCActivate( WND *wndPtr, WPARAM16 wParam )
772 WORD wStateChange;
774 if( wParam ) wStateChange = !(wndPtr->flags & WIN_NCACTIVATED);
775 else wStateChange = wndPtr->flags & WIN_NCACTIVATED;
777 if( wStateChange )
779 if (wParam) wndPtr->flags |= WIN_NCACTIVATED;
780 else wndPtr->flags &= ~WIN_NCACTIVATED;
782 if( wndPtr->dwStyle & WS_MINIMIZE )
783 PAINT_RedrawWindow( wndPtr->hwndSelf, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_ERASENOW, 0 );
784 else
785 NC_DoNCPaint( wndPtr->hwndSelf, (HRGN32)1, FALSE );
787 return TRUE;
791 /***********************************************************************
792 * NC_HandleSetCursor
794 * Handle a WM_SETCURSOR message. Called from DefWindowProc().
796 LONG NC_HandleSetCursor( HWND32 hwnd, WPARAM16 wParam, LPARAM lParam )
798 if (hwnd != (HWND32)wParam) return 0; /* Don't set the cursor for child windows */
800 switch(LOWORD(lParam))
802 case HTERROR:
804 WORD msg = HIWORD( lParam );
805 if ((msg == WM_LBUTTONDOWN) || (msg == WM_MBUTTONDOWN) ||
806 (msg == WM_RBUTTONDOWN))
807 MessageBeep(0);
809 break;
811 case HTCLIENT:
813 WND *wndPtr;
814 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) break;
815 if (wndPtr->class->hCursor)
817 SetCursor( wndPtr->class->hCursor );
818 return TRUE;
820 else return FALSE;
823 case HTLEFT:
824 case HTRIGHT:
825 return (LONG)SetCursor( LoadCursor16( 0, IDC_SIZEWE ) );
827 case HTTOP:
828 case HTBOTTOM:
829 return (LONG)SetCursor( LoadCursor16( 0, IDC_SIZENS ) );
831 case HTTOPLEFT:
832 case HTBOTTOMRIGHT:
833 return (LONG)SetCursor( LoadCursor16( 0, IDC_SIZENWSE ) );
835 case HTTOPRIGHT:
836 case HTBOTTOMLEFT:
837 return (LONG)SetCursor( LoadCursor16( 0, IDC_SIZENESW ) );
840 /* Default cursor: arrow */
841 return (LONG)SetCursor( LoadCursor16( 0, IDC_ARROW ) );
844 /***********************************************************************
845 * NC_GetSysPopupPos
847 BOOL NC_GetSysPopupPos( WND* wndPtr, RECT16* rect )
849 if( !wndPtr->hSysMenu ) return FALSE;
851 NC_GetInsideRect( wndPtr->hwndSelf, rect );
852 OffsetRect16( rect, wndPtr->rectWindow.left, wndPtr->rectWindow.top );
853 if (wndPtr->dwStyle & WS_CHILD)
854 ClientToScreen16( wndPtr->parent->hwndSelf, (POINT16 *)rect );
855 rect->right = rect->left + SYSMETRICS_CXSIZE;
856 rect->bottom = rect->top + SYSMETRICS_CYSIZE;
857 return TRUE;
860 /***********************************************************************
861 * NC_TrackSysMenu
863 * Track a mouse button press on the system menu.
865 static void NC_TrackSysMenu( HWND hwnd, HDC16 hdc, POINT16 pt )
867 RECT16 rect;
868 WND *wndPtr = WIN_FindWndPtr( hwnd );
869 int iconic = wndPtr->dwStyle & WS_MINIMIZE;
870 HMENU16 hmenu;
872 if (!(wndPtr->dwStyle & WS_SYSMENU)) return;
874 /* If window has a menu, track the menu bar normally if it not minimized */
875 if (HAS_MENU(wndPtr) && !iconic) MENU_TrackMouseMenuBar( hwnd, pt );
876 else
878 /* Otherwise track the system menu like a normal popup menu */
880 NC_GetSysPopupPos( wndPtr, &rect );
881 if (!iconic) NC_DrawSysButton( hwnd, hdc, TRUE );
882 hmenu = GetSystemMenu(hwnd, 0);
883 MENU_InitSysMenuPopup(hmenu, wndPtr->dwStyle,
884 wndPtr->class->style);
885 TrackPopupMenu16( hmenu, TPM_LEFTALIGN | TPM_LEFTBUTTON,
886 rect.left, rect.bottom, 0, hwnd, &rect );
887 if (!iconic) NC_DrawSysButton( hwnd, hdc, FALSE );
892 /***********************************************************************
893 * NC_StartSizeMove
895 * Initialisation of a move or resize, when initiatied from a menu choice.
896 * Return hit test code for caption or sizing border.
898 static LONG NC_StartSizeMove( HWND hwnd, WPARAM16 wParam, POINT16 *capturePoint )
900 LONG hittest = 0;
901 POINT16 pt;
902 MSG16 msg;
903 WND * wndPtr = WIN_FindWndPtr( hwnd );
905 if ((wParam & 0xfff0) == SC_MOVE)
907 /* Move pointer at the center of the caption */
908 RECT16 rect;
909 NC_GetInsideRect( hwnd, &rect );
910 if (wndPtr->dwStyle & WS_SYSMENU)
911 rect.left += SYSMETRICS_CXSIZE + 1;
912 if (wndPtr->dwStyle & WS_MINIMIZEBOX)
913 rect.right -= SYSMETRICS_CXSIZE + 1;
914 if (wndPtr->dwStyle & WS_MAXIMIZEBOX)
915 rect.right -= SYSMETRICS_CXSIZE + 1;
916 pt.x = wndPtr->rectWindow.left + (rect.right - rect.left) / 2;
917 pt.y = wndPtr->rectWindow.top + rect.top + SYSMETRICS_CYSIZE/2;
918 if (wndPtr->dwStyle & WS_CHILD)
919 ClientToScreen16( wndPtr->parent->hwndSelf, &pt );
920 hittest = HTCAPTION;
922 else /* SC_SIZE */
924 SetCapture32(hwnd);
925 while(!hittest)
927 MSG_InternalGetMessage( &msg, 0, 0, MSGF_SIZE, PM_REMOVE, FALSE );
928 switch(msg.message)
930 case WM_MOUSEMOVE:
931 hittest = NC_HandleNCHitTest( hwnd, msg.pt );
932 pt = msg.pt;
933 if ((hittest < HTLEFT) || (hittest > HTBOTTOMRIGHT))
934 hittest = 0;
935 break;
937 case WM_LBUTTONUP:
938 return 0;
940 case WM_KEYDOWN:
941 switch(msg.wParam)
943 case VK_UP:
944 hittest = HTTOP;
945 pt.x =(wndPtr->rectWindow.left+wndPtr->rectWindow.right)/2;
946 pt.y = wndPtr->rectWindow.top + SYSMETRICS_CYFRAME / 2;
947 break;
948 case VK_DOWN:
949 hittest = HTBOTTOM;
950 pt.x =(wndPtr->rectWindow.left+wndPtr->rectWindow.right)/2;
951 pt.y = wndPtr->rectWindow.bottom - SYSMETRICS_CYFRAME / 2;
952 break;
953 case VK_LEFT:
954 hittest = HTLEFT;
955 pt.x = wndPtr->rectWindow.left + SYSMETRICS_CXFRAME / 2;
956 pt.y =(wndPtr->rectWindow.top+wndPtr->rectWindow.bottom)/2;
957 break;
958 case VK_RIGHT:
959 hittest = HTRIGHT;
960 pt.x = wndPtr->rectWindow.right - SYSMETRICS_CXFRAME / 2;
961 pt.y =(wndPtr->rectWindow.top+wndPtr->rectWindow.bottom)/2;
962 break;
963 case VK_RETURN:
964 case VK_ESCAPE: return 0;
969 *capturePoint = pt;
970 SetCursorPos( capturePoint->x, capturePoint->y );
971 NC_HandleSetCursor( hwnd, (WPARAM16)hwnd, MAKELONG( hittest, WM_MOUSEMOVE ));
972 return hittest;
976 /***********************************************************************
977 * NC_DoSizeMove
979 * Perform SC_MOVE and SC_SIZE commands.
981 static void NC_DoSizeMove( HWND hwnd, WORD wParam, POINT16 pt )
983 MSG16 msg;
984 RECT16 sizingRect, mouseRect;
985 HDC32 hdc;
986 LONG hittest = (LONG)(wParam & 0x0f);
987 HCURSOR16 hDragCursor = 0, hOldCursor = 0;
988 POINT16 minTrack, maxTrack, capturePoint = pt;
989 WND * wndPtr = WIN_FindWndPtr( hwnd );
990 BOOL32 thickframe = HAS_THICKFRAME( wndPtr->dwStyle );
991 BOOL32 iconic = wndPtr->dwStyle & WS_MINIMIZE;
992 int moved = 0;
994 if (IsZoomed(hwnd) || !IsWindowVisible(hwnd) ||
995 (wndPtr->flags & WIN_MANAGED)) return;
997 if ((wParam & 0xfff0) == SC_MOVE)
999 if (!(wndPtr->dwStyle & WS_CAPTION)) return;
1000 if (!hittest) hittest = NC_StartSizeMove( hwnd, wParam, &capturePoint );
1001 if (!hittest) return;
1003 else /* SC_SIZE */
1005 if (!thickframe) return;
1006 if (hittest) hittest += HTLEFT-1;
1007 else
1009 SetCapture32(hwnd);
1010 hittest = NC_StartSizeMove( hwnd, wParam, &capturePoint );
1011 if (!hittest)
1013 ReleaseCapture();
1014 return;
1019 /* Get min/max info */
1021 NC_GetMinMaxInfo( wndPtr, NULL, NULL, &minTrack, &maxTrack );
1022 sizingRect = wndPtr->rectWindow;
1023 if (wndPtr->dwStyle & WS_CHILD)
1024 GetClientRect16( wndPtr->parent->hwndSelf, &mouseRect );
1025 else SetRect16(&mouseRect, 0, 0, SYSMETRICS_CXSCREEN, SYSMETRICS_CYSCREEN);
1026 if (ON_LEFT_BORDER(hittest))
1028 mouseRect.left = MAX( mouseRect.left, sizingRect.right-maxTrack.x );
1029 mouseRect.right = MIN( mouseRect.right, sizingRect.right-minTrack.x );
1031 else if (ON_RIGHT_BORDER(hittest))
1033 mouseRect.left = MAX( mouseRect.left, sizingRect.left+minTrack.x );
1034 mouseRect.right = MIN( mouseRect.right, sizingRect.left+maxTrack.x );
1036 if (ON_TOP_BORDER(hittest))
1038 mouseRect.top = MAX( mouseRect.top, sizingRect.bottom-maxTrack.y );
1039 mouseRect.bottom = MIN( mouseRect.bottom,sizingRect.bottom-minTrack.y);
1041 else if (ON_BOTTOM_BORDER(hittest))
1043 mouseRect.top = MAX( mouseRect.top, sizingRect.top+minTrack.y );
1044 mouseRect.bottom = MIN( mouseRect.bottom, sizingRect.top+maxTrack.y );
1046 SendMessage16( hwnd, WM_ENTERSIZEMOVE, 0, 0 );
1048 if (GetCapture32() != hwnd) SetCapture32( hwnd );
1050 if (wndPtr->dwStyle & WS_CHILD)
1052 /* Retrieve a default cache DC (without using the window style) */
1053 hdc = GetDCEx32( wndPtr->parent->hwndSelf, 0, DCX_CACHE );
1055 else
1056 { /* Grab the server only when moving top-level windows without desktop */
1057 hdc = GetDC32( 0 );
1058 if (rootWindow == DefaultRootWindow(display)) XGrabServer( display );
1061 if( iconic )
1063 HICON16 hIcon = (wndPtr->class->hIcon)
1064 ? wndPtr->class->hIcon
1065 : (HICON16)SendMessage16( hwnd, WM_QUERYDRAGICON, 0, 0L);
1066 if( hIcon )
1068 hDragCursor = CURSORICON_IconToCursor( hIcon, TRUE );
1069 hOldCursor = SetCursor(hDragCursor);
1070 ShowCursor(1);
1071 } else iconic = FALSE;
1074 if( !iconic ) NC_DrawMovingFrame( hdc, &sizingRect, thickframe );
1076 while(1)
1078 int dx = 0, dy = 0;
1080 MSG_InternalGetMessage( &msg, 0, 0, MSGF_SIZE, PM_REMOVE, FALSE );
1082 /* Exit on button-up, Return, or Esc */
1083 if ((msg.message == WM_LBUTTONUP) ||
1084 ((msg.message == WM_KEYDOWN) &&
1085 ((msg.wParam == VK_RETURN) || (msg.wParam == VK_ESCAPE)))) break;
1087 if ((msg.message != WM_KEYDOWN) && (msg.message != WM_MOUSEMOVE))
1088 continue; /* We are not interested in other messages */
1090 pt = msg.pt;
1091 if (wndPtr->dwStyle & WS_CHILD)
1092 ScreenToClient16( wndPtr->parent->hwndSelf, &pt );
1094 if (msg.message == WM_KEYDOWN) switch(msg.wParam)
1096 case VK_UP: pt.y -= 8; break;
1097 case VK_DOWN: pt.y += 8; break;
1098 case VK_LEFT: pt.x -= 8; break;
1099 case VK_RIGHT: pt.x += 8; break;
1102 pt.x = MAX( pt.x, mouseRect.left );
1103 pt.x = MIN( pt.x, mouseRect.right );
1104 pt.y = MAX( pt.y, mouseRect.top );
1105 pt.y = MIN( pt.y, mouseRect.bottom );
1107 dx = pt.x - capturePoint.x;
1108 dy = pt.y - capturePoint.y;
1110 if (dx || dy)
1112 moved = 1;
1113 if (msg.message == WM_KEYDOWN) SetCursorPos( pt.x, pt.y );
1114 else
1116 RECT16 newRect = sizingRect;
1118 if (hittest == HTCAPTION) OffsetRect16( &newRect, dx, dy );
1119 if (ON_LEFT_BORDER(hittest)) newRect.left += dx;
1120 else if (ON_RIGHT_BORDER(hittest)) newRect.right += dx;
1121 if (ON_TOP_BORDER(hittest)) newRect.top += dy;
1122 else if (ON_BOTTOM_BORDER(hittest)) newRect.bottom += dy;
1123 if( !iconic )
1125 NC_DrawMovingFrame( hdc, &sizingRect, thickframe );
1126 NC_DrawMovingFrame( hdc, &newRect, thickframe );
1128 capturePoint = pt;
1129 sizingRect = newRect;
1134 ReleaseCapture();
1135 if( iconic )
1137 ShowCursor(0);
1138 SetCursor(hOldCursor);
1139 if( hDragCursor ) DestroyCursor(hDragCursor);
1141 else
1142 NC_DrawMovingFrame( hdc, &sizingRect, thickframe );
1144 if (wndPtr->dwStyle & WS_CHILD)
1145 ReleaseDC32( wndPtr->parent->hwndSelf, hdc );
1146 else
1148 ReleaseDC32( 0, hdc );
1149 if (rootWindow == DefaultRootWindow(display)) XUngrabServer( display );
1152 if (HOOK_IsHooked( WH_CBT ))
1154 RECT16* pr = SEGPTR_NEW(RECT16);
1155 if( pr )
1157 *pr = sizingRect;
1158 if( HOOK_CallHooks16( WH_CBT, HCBT_MOVESIZE, hwnd,
1159 (LPARAM)SEGPTR_GET(pr)) )
1160 sizingRect = wndPtr->rectWindow;
1161 else
1162 sizingRect = *pr;
1163 SEGPTR_FREE(pr);
1166 SendMessage16( hwnd, WM_EXITSIZEMOVE, 0, 0 );
1167 SendMessage16( hwnd, WM_SETVISIBLE, !IsIconic(hwnd), 0L);
1169 /* Single click brings up the system menu when iconized */
1171 if (!moved && (wndPtr->dwStyle & WS_MINIMIZE))
1173 NC_TrackSysMenu( hwnd, hdc, pt );
1174 return;
1177 /* If Esc key, don't move the window */
1178 if ((msg.message == WM_KEYDOWN) && (msg.wParam == VK_ESCAPE)) return;
1180 if (hittest != HTCAPTION)
1181 SetWindowPos( hwnd, 0, sizingRect.left, sizingRect.top,
1182 sizingRect.right - sizingRect.left,
1183 sizingRect.bottom - sizingRect.top,
1184 SWP_NOACTIVATE | SWP_NOZORDER );
1185 else SetWindowPos( hwnd, 0, sizingRect.left, sizingRect.top, 0, 0,
1186 SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER );
1190 /***********************************************************************
1191 * NC_TrackMinMaxBox
1193 * Track a mouse button press on the minimize or maximize box.
1195 static void NC_TrackMinMaxBox( HWND hwnd, WORD wParam )
1197 MSG16 msg;
1198 HDC32 hdc = GetWindowDC32( hwnd );
1199 BOOL pressed = TRUE;
1201 SetCapture32( hwnd );
1202 if (wParam == HTMINBUTTON) NC_DrawMinButton( hwnd, hdc, TRUE );
1203 else NC_DrawMaxButton( hwnd, hdc, TRUE );
1207 BOOL oldstate = pressed;
1208 MSG_InternalGetMessage( &msg, 0, 0, 0, PM_REMOVE, FALSE );
1210 pressed = (NC_HandleNCHitTest( hwnd, msg.pt ) == wParam);
1211 if (pressed != oldstate)
1213 if (wParam == HTMINBUTTON) NC_DrawMinButton( hwnd, hdc, pressed );
1214 else NC_DrawMaxButton( hwnd, hdc, pressed );
1216 } while (msg.message != WM_LBUTTONUP);
1218 if (wParam == HTMINBUTTON) NC_DrawMinButton( hwnd, hdc, FALSE );
1219 else NC_DrawMaxButton( hwnd, hdc, FALSE );
1221 ReleaseCapture();
1222 ReleaseDC32( hwnd, hdc );
1223 if (!pressed) return;
1225 if (wParam == HTMINBUTTON)
1226 SendMessage16( hwnd, WM_SYSCOMMAND, SC_MINIMIZE, *(LONG*)&msg.pt );
1227 else
1228 SendMessage16( hwnd, WM_SYSCOMMAND,
1229 IsZoomed(hwnd) ? SC_RESTORE : SC_MAXIMIZE, *(LONG*)&msg.pt );
1233 /***********************************************************************
1234 * NC_TrackScrollBar
1236 * Track a mouse button press on the horizontal or vertical scroll-bar.
1238 static void NC_TrackScrollBar( HWND32 hwnd, WPARAM32 wParam, POINT32 pt )
1240 MSG16 *msg;
1241 INT32 scrollbar;
1242 WND *wndPtr = WIN_FindWndPtr( hwnd );
1244 if ((wParam & 0xfff0) == SC_HSCROLL)
1246 if ((wParam & 0x0f) != HTHSCROLL) return;
1247 scrollbar = SB_HORZ;
1249 else /* SC_VSCROLL */
1251 if ((wParam & 0x0f) != HTVSCROLL) return;
1252 scrollbar = SB_VERT;
1255 if (!(msg = SEGPTR_NEW(MSG16))) return;
1256 pt.x -= wndPtr->rectWindow.left;
1257 pt.y -= wndPtr->rectWindow.top;
1258 SetCapture32( hwnd );
1259 SCROLL_HandleScrollEvent( hwnd, scrollbar, WM_LBUTTONDOWN, pt );
1263 GetMessage( SEGPTR_GET(msg), 0, 0, 0 );
1264 switch(msg->message)
1266 case WM_LBUTTONUP:
1267 case WM_MOUSEMOVE:
1268 case WM_SYSTIMER:
1269 pt.x = LOWORD(msg->lParam) + wndPtr->rectClient.left -
1270 wndPtr->rectWindow.left;
1271 pt.y = HIWORD(msg->lParam) + wndPtr->rectClient.top -
1272 wndPtr->rectWindow.top;
1273 SCROLL_HandleScrollEvent( hwnd, scrollbar, msg->message, pt );
1274 break;
1275 default:
1276 TranslateMessage( msg );
1277 DispatchMessage( msg );
1278 break;
1280 if (!IsWindow( hwnd ))
1282 ReleaseCapture();
1283 break;
1285 } while (msg->message != WM_LBUTTONUP);
1286 SEGPTR_FREE(msg);
1289 /***********************************************************************
1290 * NC_HandleNCLButtonDown
1292 * Handle a WM_NCLBUTTONDOWN message. Called from DefWindowProc().
1294 LONG NC_HandleNCLButtonDown( HWND32 hwnd, WPARAM16 wParam, LPARAM lParam )
1296 HDC32 hdc;
1298 switch(wParam) /* Hit test */
1300 case HTCAPTION:
1301 SendMessage16( hwnd, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, lParam );
1302 break;
1304 case HTSYSMENU:
1305 hdc = GetWindowDC32( hwnd );
1306 NC_TrackSysMenu( hwnd, hdc, MAKEPOINT16(lParam) );
1307 ReleaseDC32( hwnd, hdc );
1308 break;
1310 case HTMENU:
1311 SendMessage16( hwnd, WM_SYSCOMMAND, SC_MOUSEMENU, lParam );
1312 break;
1314 case HTHSCROLL:
1315 SendMessage16( hwnd, WM_SYSCOMMAND, SC_HSCROLL + HTHSCROLL, lParam );
1316 break;
1318 case HTVSCROLL:
1319 SendMessage16( hwnd, WM_SYSCOMMAND, SC_VSCROLL + HTVSCROLL, lParam );
1320 break;
1322 case HTMINBUTTON:
1323 case HTMAXBUTTON:
1324 NC_TrackMinMaxBox( hwnd, wParam );
1325 break;
1327 case HTLEFT:
1328 case HTRIGHT:
1329 case HTTOP:
1330 case HTTOPLEFT:
1331 case HTTOPRIGHT:
1332 case HTBOTTOM:
1333 case HTBOTTOMLEFT:
1334 case HTBOTTOMRIGHT:
1335 SendMessage16( hwnd, WM_SYSCOMMAND, SC_SIZE + wParam - HTLEFT+1, lParam);
1336 break;
1338 case HTBORDER:
1339 break;
1341 return 0;
1345 /***********************************************************************
1346 * NC_HandleNCLButtonDblClk
1348 * Handle a WM_NCLBUTTONDBLCLK message. Called from DefWindowProc().
1350 LONG NC_HandleNCLButtonDblClk( WND *pWnd, WPARAM16 wParam, LPARAM lParam )
1353 * if this is an icon, send a restore since we are handling
1354 * a double click
1356 if (pWnd->dwStyle & WS_MINIMIZE)
1358 SendMessage16( pWnd->hwndSelf, WM_SYSCOMMAND, SC_RESTORE, lParam );
1359 return 0;
1362 switch(wParam) /* Hit test */
1364 case HTCAPTION:
1365 /* stop processing if WS_MAXIMIZEBOX is missing */
1366 if (pWnd->dwStyle & WS_MAXIMIZEBOX)
1367 SendMessage16( pWnd->hwndSelf, WM_SYSCOMMAND,
1368 (pWnd->dwStyle & WS_MAXIMIZE) ? SC_RESTORE : SC_MAXIMIZE,
1369 lParam );
1370 break;
1372 case HTSYSMENU:
1373 if (!(pWnd->class->style & CS_NOCLOSE))
1374 SendMessage16( pWnd->hwndSelf, WM_SYSCOMMAND, SC_CLOSE, lParam );
1375 break;
1377 return 0;
1381 /***********************************************************************
1382 * NC_HandleSysCommand
1384 * Handle a WM_SYSCOMMAND message. Called from DefWindowProc().
1386 LONG NC_HandleSysCommand( HWND32 hwnd, WPARAM16 wParam, POINT16 pt )
1388 WND *wndPtr = WIN_FindWndPtr( hwnd );
1389 POINT32 pt32;
1391 dprintf_nonclient(stddeb, "Handling WM_SYSCOMMAND %x %d,%d\n",
1392 wParam, pt.x, pt.y );
1394 if (wndPtr->dwStyle & WS_CHILD && wParam != SC_KEYMENU )
1395 ScreenToClient16( wndPtr->parent->hwndSelf, &pt );
1397 switch (wParam & 0xfff0)
1399 case SC_SIZE:
1400 case SC_MOVE:
1401 NC_DoSizeMove( hwnd, wParam, pt );
1402 break;
1404 case SC_MINIMIZE:
1405 ShowWindow( hwnd, SW_MINIMIZE );
1406 break;
1408 case SC_MAXIMIZE:
1409 ShowWindow( hwnd, SW_MAXIMIZE );
1410 break;
1412 case SC_RESTORE:
1413 ShowWindow( hwnd, SW_RESTORE );
1414 break;
1416 case SC_NEXTWINDOW:
1417 case SC_PREVWINDOW:
1418 break;
1420 case SC_CLOSE:
1421 return SendMessage16( hwnd, WM_CLOSE, 0, 0 );
1423 case SC_VSCROLL:
1424 case SC_HSCROLL:
1425 CONV_POINT16TO32( &pt, &pt32 );
1426 NC_TrackScrollBar( hwnd, wParam, pt32 );
1427 break;
1429 case SC_MOUSEMENU:
1430 MENU_TrackMouseMenuBar( hwnd, pt );
1431 break;
1433 case SC_KEYMENU:
1434 MENU_TrackKbdMenuBar( wndPtr , wParam , pt.x );
1435 break;
1437 case SC_ARRANGE:
1438 break;
1440 case SC_TASKLIST:
1441 WinExec( "taskman.exe", SW_SHOWNORMAL );
1442 break;
1444 case SC_HOTKEY:
1445 break;
1447 case SC_SCREENSAVE:
1448 if (wParam == SC_ABOUTWINE)
1450 extern const char people[];
1451 ShellAbout(hwnd,"WINE",people,0);
1453 break;
1455 return 0;