Release 970215
[wine/multimedia.git] / windows / nonclient.c
blobd4001a1d36c746d715a65488bd7a66901a630dd3
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( HWND32 hwnd, RECT32 *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 InflateRect32( rect, -SYSMETRICS_CXDLGFRAME, -SYSMETRICS_CYDLGFRAME);
286 if (wndPtr->dwExStyle & WS_EX_DLGMODALFRAME)
287 InflateRect32( rect, -1, 0 );
289 else
291 if (HAS_THICKFRAME( wndPtr->dwStyle ))
292 InflateRect32( rect, -SYSMETRICS_CXFRAME, -SYSMETRICS_CYFRAME );
293 if (wndPtr->dwStyle & WS_BORDER)
294 InflateRect32( 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( HWND32 hwnd, HDC32 hdc, BOOL32 down )
438 RECT32 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( HWND32 hwnd, HDC16 hdc, BOOL down )
462 RECT32 rect;
463 WND *wndPtr = WIN_FindWndPtr( hwnd );
465 if( !(wndPtr->flags & WIN_MANAGED) )
467 NC_GetInsideRect( hwnd, &rect );
468 GRAPH_DrawBitmap( hdc, (IsZoomed32(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( HWND32 hwnd, HDC16 hdc, BOOL down )
482 RECT32 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, HWND32 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, GetSysColor32( COLOR_CAPTIONTEXT ) );
651 else SetTextColor( hdc, GetSysColor32( 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 RECT32 r;
727 CONV_RECT16TO32( &rect, &r );
728 r.bottom = rect.top + SYSMETRICS_CYMENU; /* default height */
729 rect.top += MENU_DrawMenuBar( hdc, &r, hwnd, suppress_menupaint );
732 /* Draw the scroll-bars */
734 if (wndPtr->dwStyle & WS_VSCROLL)
735 SCROLL_DrawScrollBar( hwnd, hdc, SB_VERT, TRUE );
736 if (wndPtr->dwStyle & WS_HSCROLL)
737 SCROLL_DrawScrollBar( hwnd, hdc, SB_HORZ, TRUE );
739 /* Draw the "size-box" */
741 if ((wndPtr->dwStyle & WS_VSCROLL) && (wndPtr->dwStyle & WS_HSCROLL))
743 RECT16 r = rect;
744 r.left = r.right - SYSMETRICS_CXVSCROLL + 1;
745 r.top = r.bottom - SYSMETRICS_CYHSCROLL + 1;
746 FillRect16( hdc, &r, sysColorObjects.hbrushScrollbar );
749 ReleaseDC32( hwnd, hdc );
754 /***********************************************************************
755 * NC_HandleNCPaint
757 * Handle a WM_NCPAINT message. Called from DefWindowProc().
759 LONG NC_HandleNCPaint( HWND32 hwnd , HRGN32 clip)
761 NC_DoNCPaint( hwnd, clip, FALSE );
762 return 0;
766 /***********************************************************************
767 * NC_HandleNCActivate
769 * Handle a WM_NCACTIVATE message. Called from DefWindowProc().
771 LONG NC_HandleNCActivate( WND *wndPtr, WPARAM16 wParam )
773 WORD wStateChange;
775 if( wParam ) wStateChange = !(wndPtr->flags & WIN_NCACTIVATED);
776 else wStateChange = wndPtr->flags & WIN_NCACTIVATED;
778 if( wStateChange )
780 if (wParam) wndPtr->flags |= WIN_NCACTIVATED;
781 else wndPtr->flags &= ~WIN_NCACTIVATED;
783 if( wndPtr->dwStyle & WS_MINIMIZE )
784 PAINT_RedrawWindow( wndPtr->hwndSelf, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_ERASENOW, 0 );
785 else
786 NC_DoNCPaint( wndPtr->hwndSelf, (HRGN32)1, FALSE );
788 return TRUE;
792 /***********************************************************************
793 * NC_HandleSetCursor
795 * Handle a WM_SETCURSOR message. Called from DefWindowProc().
797 LONG NC_HandleSetCursor( HWND32 hwnd, WPARAM16 wParam, LPARAM lParam )
799 if (hwnd != (HWND32)wParam) return 0; /* Don't set the cursor for child windows */
801 switch(LOWORD(lParam))
803 case HTERROR:
805 WORD msg = HIWORD( lParam );
806 if ((msg == WM_LBUTTONDOWN) || (msg == WM_MBUTTONDOWN) ||
807 (msg == WM_RBUTTONDOWN))
808 MessageBeep32(0);
810 break;
812 case HTCLIENT:
814 WND *wndPtr;
815 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) break;
816 if (wndPtr->class->hCursor)
818 SetCursor16( wndPtr->class->hCursor );
819 return TRUE;
821 else return FALSE;
824 case HTLEFT:
825 case HTRIGHT:
826 return (LONG)SetCursor16( LoadCursor16( 0, IDC_SIZEWE ) );
828 case HTTOP:
829 case HTBOTTOM:
830 return (LONG)SetCursor16( LoadCursor16( 0, IDC_SIZENS ) );
832 case HTTOPLEFT:
833 case HTBOTTOMRIGHT:
834 return (LONG)SetCursor16( LoadCursor16( 0, IDC_SIZENWSE ) );
836 case HTTOPRIGHT:
837 case HTBOTTOMLEFT:
838 return (LONG)SetCursor16( LoadCursor16( 0, IDC_SIZENESW ) );
841 /* Default cursor: arrow */
842 return (LONG)SetCursor16( LoadCursor16( 0, IDC_ARROW ) );
845 /***********************************************************************
846 * NC_GetSysPopupPos
848 BOOL32 NC_GetSysPopupPos( WND* wndPtr, RECT32* rect )
850 if( wndPtr->hSysMenu )
852 if( wndPtr->dwStyle & WS_MINIMIZE )
853 GetWindowRect32( wndPtr->hwndSelf, rect );
854 else
856 NC_GetInsideRect( wndPtr->hwndSelf, rect );
857 OffsetRect32( rect, wndPtr->rectWindow.left, wndPtr->rectWindow.top);
858 if (wndPtr->dwStyle & WS_CHILD)
859 ClientToScreen32( wndPtr->parent->hwndSelf, (POINT32 *)rect );
860 rect->right = rect->left + SYSMETRICS_CXSIZE;
861 rect->bottom = rect->top + SYSMETRICS_CYSIZE;
863 return TRUE;
865 return FALSE;
868 /***********************************************************************
869 * NC_TrackSysMenu
871 * Track a mouse button press on the system menu.
873 static void NC_TrackSysMenu( HWND32 hwnd, POINT16 pt )
875 WND* wndPtr = WIN_FindWndPtr( hwnd );
877 if (wndPtr->dwStyle & WS_SYSMENU)
879 int iconic, on = 1;
881 iconic = wndPtr->dwStyle & WS_MINIMIZE;
883 if( !iconic )
885 HDC16 hdc = GetWindowDC32(hwnd);
886 RECT32 rect;
887 RECT16 rTrack;
888 BOOL32 bNew, bTrack = TRUE;
889 MSG16 msg;
891 NC_GetSysPopupPos( wndPtr, &rect );
892 CONV_RECT32TO16( &rect, &rTrack );
893 MapWindowPoints16( 0, hwnd, (LPPOINT16)&rTrack, 2 );
895 /* track mouse while waiting for WM_LBUTTONUP */
897 NC_DrawSysButton( hwnd, hdc, bTrack );
898 SetCapture32(hwnd);
901 msg.message = WM_NULL;
902 PeekMessage16( &msg, 0, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE);
903 if( msg.message == WM_MOUSEMOVE )
905 if( (bNew = PtInRect16(&rTrack, MAKEPOINT16(msg.lParam))) )
906 { if( bTrack ) continue; }
907 else
908 { if(!bTrack ) continue; }
909 NC_DrawSysButton( hwnd, hdc, bTrack = bNew);
911 } while( msg.message != WM_LBUTTONUP );
913 ReleaseCapture();
914 ReleaseDC32(hwnd, hdc);
915 on = PtInRect16(&rTrack, MAKEPOINT16(msg.lParam));
918 if( on )
919 SendMessage16( hwnd, WM_SYSCOMMAND,
920 SC_MOUSEMENU + HTSYSMENU, *((LPARAM*)&pt));
925 /***********************************************************************
926 * NC_StartSizeMove
928 * Initialisation of a move or resize, when initiatied from a menu choice.
929 * Return hit test code for caption or sizing border.
931 static LONG NC_StartSizeMove( HWND32 hwnd, WPARAM16 wParam,
932 POINT16 *capturePoint )
934 LONG hittest = 0;
935 POINT16 pt;
936 MSG16 msg;
937 WND * wndPtr = WIN_FindWndPtr( hwnd );
939 if ((wParam & 0xfff0) == SC_MOVE)
941 /* Move pointer at the center of the caption */
942 RECT32 rect;
943 NC_GetInsideRect( hwnd, &rect );
944 if (wndPtr->dwStyle & WS_SYSMENU)
945 rect.left += SYSMETRICS_CXSIZE + 1;
946 if (wndPtr->dwStyle & WS_MINIMIZEBOX)
947 rect.right -= SYSMETRICS_CXSIZE + 1;
948 if (wndPtr->dwStyle & WS_MAXIMIZEBOX)
949 rect.right -= SYSMETRICS_CXSIZE + 1;
950 pt.x = wndPtr->rectWindow.left + (rect.right - rect.left) / 2;
951 pt.y = wndPtr->rectWindow.top + rect.top + SYSMETRICS_CYSIZE/2;
952 if (wndPtr->dwStyle & WS_CHILD)
953 ClientToScreen16( wndPtr->parent->hwndSelf, &pt );
954 hittest = HTCAPTION;
956 else /* SC_SIZE */
958 SetCapture32(hwnd);
959 while(!hittest)
961 MSG_InternalGetMessage( &msg, 0, 0, MSGF_SIZE, PM_REMOVE, FALSE );
962 switch(msg.message)
964 case WM_MOUSEMOVE:
965 hittest = NC_HandleNCHitTest( hwnd, msg.pt );
966 pt = msg.pt;
967 if ((hittest < HTLEFT) || (hittest > HTBOTTOMRIGHT))
968 hittest = 0;
969 break;
971 case WM_LBUTTONUP:
972 return 0;
974 case WM_KEYDOWN:
975 switch(msg.wParam)
977 case VK_UP:
978 hittest = HTTOP;
979 pt.x =(wndPtr->rectWindow.left+wndPtr->rectWindow.right)/2;
980 pt.y = wndPtr->rectWindow.top + SYSMETRICS_CYFRAME / 2;
981 break;
982 case VK_DOWN:
983 hittest = HTBOTTOM;
984 pt.x =(wndPtr->rectWindow.left+wndPtr->rectWindow.right)/2;
985 pt.y = wndPtr->rectWindow.bottom - SYSMETRICS_CYFRAME / 2;
986 break;
987 case VK_LEFT:
988 hittest = HTLEFT;
989 pt.x = wndPtr->rectWindow.left + SYSMETRICS_CXFRAME / 2;
990 pt.y =(wndPtr->rectWindow.top+wndPtr->rectWindow.bottom)/2;
991 break;
992 case VK_RIGHT:
993 hittest = HTRIGHT;
994 pt.x = wndPtr->rectWindow.right - SYSMETRICS_CXFRAME / 2;
995 pt.y =(wndPtr->rectWindow.top+wndPtr->rectWindow.bottom)/2;
996 break;
997 case VK_RETURN:
998 case VK_ESCAPE: return 0;
1003 *capturePoint = pt;
1004 SetCursorPos32( capturePoint->x, capturePoint->y );
1005 NC_HandleSetCursor( hwnd, (WPARAM16)hwnd, MAKELONG( hittest, WM_MOUSEMOVE ));
1006 return hittest;
1010 /***********************************************************************
1011 * NC_DoSizeMove
1013 * Perform SC_MOVE and SC_SIZE commands.
1015 static void NC_DoSizeMove( HWND32 hwnd, WORD wParam, POINT16 pt )
1017 MSG16 msg;
1018 RECT16 sizingRect, mouseRect;
1019 HDC32 hdc;
1020 LONG hittest = (LONG)(wParam & 0x0f);
1021 HCURSOR16 hDragCursor = 0, hOldCursor = 0;
1022 POINT16 minTrack, maxTrack, capturePoint = pt;
1023 WND * wndPtr = WIN_FindWndPtr( hwnd );
1024 BOOL32 thickframe = HAS_THICKFRAME( wndPtr->dwStyle );
1025 BOOL32 iconic = wndPtr->dwStyle & WS_MINIMIZE;
1026 int moved = 0;
1028 if (IsZoomed32(hwnd) || !IsWindowVisible32(hwnd) ||
1029 (wndPtr->flags & WIN_MANAGED)) return;
1031 if ((wParam & 0xfff0) == SC_MOVE)
1033 if (!(wndPtr->dwStyle & WS_CAPTION)) return;
1034 if (!hittest) hittest = NC_StartSizeMove( hwnd, wParam, &capturePoint );
1035 if (!hittest) return;
1037 else /* SC_SIZE */
1039 if (!thickframe) return;
1040 if (hittest) hittest += HTLEFT-1;
1041 else
1043 SetCapture32(hwnd);
1044 hittest = NC_StartSizeMove( hwnd, wParam, &capturePoint );
1045 if (!hittest)
1047 ReleaseCapture();
1048 return;
1053 /* Get min/max info */
1055 NC_GetMinMaxInfo( wndPtr, NULL, NULL, &minTrack, &maxTrack );
1056 sizingRect = wndPtr->rectWindow;
1057 if (wndPtr->dwStyle & WS_CHILD)
1058 GetClientRect16( wndPtr->parent->hwndSelf, &mouseRect );
1059 else SetRect16(&mouseRect, 0, 0, SYSMETRICS_CXSCREEN, SYSMETRICS_CYSCREEN);
1060 if (ON_LEFT_BORDER(hittest))
1062 mouseRect.left = MAX( mouseRect.left, sizingRect.right-maxTrack.x );
1063 mouseRect.right = MIN( mouseRect.right, sizingRect.right-minTrack.x );
1065 else if (ON_RIGHT_BORDER(hittest))
1067 mouseRect.left = MAX( mouseRect.left, sizingRect.left+minTrack.x );
1068 mouseRect.right = MIN( mouseRect.right, sizingRect.left+maxTrack.x );
1070 if (ON_TOP_BORDER(hittest))
1072 mouseRect.top = MAX( mouseRect.top, sizingRect.bottom-maxTrack.y );
1073 mouseRect.bottom = MIN( mouseRect.bottom,sizingRect.bottom-minTrack.y);
1075 else if (ON_BOTTOM_BORDER(hittest))
1077 mouseRect.top = MAX( mouseRect.top, sizingRect.top+minTrack.y );
1078 mouseRect.bottom = MIN( mouseRect.bottom, sizingRect.top+maxTrack.y );
1080 SendMessage16( hwnd, WM_ENTERSIZEMOVE, 0, 0 );
1082 if (GetCapture32() != hwnd) SetCapture32( hwnd );
1084 if (wndPtr->dwStyle & WS_CHILD)
1086 /* Retrieve a default cache DC (without using the window style) */
1087 hdc = GetDCEx32( wndPtr->parent->hwndSelf, 0, DCX_CACHE );
1089 else
1090 { /* Grab the server only when moving top-level windows without desktop */
1091 hdc = GetDC32( 0 );
1092 if (rootWindow == DefaultRootWindow(display)) XGrabServer( display );
1095 if( iconic )
1097 HICON16 hIcon = (wndPtr->class->hIcon)
1098 ? wndPtr->class->hIcon
1099 : (HICON16)SendMessage16( hwnd, WM_QUERYDRAGICON, 0, 0L);
1100 if( hIcon )
1102 hDragCursor = CURSORICON_IconToCursor( hIcon, TRUE );
1103 hOldCursor = SetCursor32(hDragCursor);
1104 ShowCursor32( TRUE );
1105 } else iconic = FALSE;
1108 if( !iconic ) NC_DrawMovingFrame( hdc, &sizingRect, thickframe );
1110 while(1)
1112 int dx = 0, dy = 0;
1114 MSG_InternalGetMessage( &msg, 0, 0, MSGF_SIZE, PM_REMOVE, FALSE );
1116 /* Exit on button-up, Return, or Esc */
1117 if ((msg.message == WM_LBUTTONUP) ||
1118 ((msg.message == WM_KEYDOWN) &&
1119 ((msg.wParam == VK_RETURN) || (msg.wParam == VK_ESCAPE)))) break;
1121 if ((msg.message != WM_KEYDOWN) && (msg.message != WM_MOUSEMOVE))
1122 continue; /* We are not interested in other messages */
1124 pt = msg.pt;
1125 if (wndPtr->dwStyle & WS_CHILD)
1126 ScreenToClient16( wndPtr->parent->hwndSelf, &pt );
1128 if (msg.message == WM_KEYDOWN) switch(msg.wParam)
1130 case VK_UP: pt.y -= 8; break;
1131 case VK_DOWN: pt.y += 8; break;
1132 case VK_LEFT: pt.x -= 8; break;
1133 case VK_RIGHT: pt.x += 8; break;
1136 pt.x = MAX( pt.x, mouseRect.left );
1137 pt.x = MIN( pt.x, mouseRect.right );
1138 pt.y = MAX( pt.y, mouseRect.top );
1139 pt.y = MIN( pt.y, mouseRect.bottom );
1141 dx = pt.x - capturePoint.x;
1142 dy = pt.y - capturePoint.y;
1144 if (dx || dy)
1146 moved = 1;
1147 if (msg.message == WM_KEYDOWN) SetCursorPos32( pt.x, pt.y );
1148 else
1150 RECT16 newRect = sizingRect;
1152 if (hittest == HTCAPTION) OffsetRect16( &newRect, dx, dy );
1153 if (ON_LEFT_BORDER(hittest)) newRect.left += dx;
1154 else if (ON_RIGHT_BORDER(hittest)) newRect.right += dx;
1155 if (ON_TOP_BORDER(hittest)) newRect.top += dy;
1156 else if (ON_BOTTOM_BORDER(hittest)) newRect.bottom += dy;
1157 if( !iconic )
1159 NC_DrawMovingFrame( hdc, &sizingRect, thickframe );
1160 NC_DrawMovingFrame( hdc, &newRect, thickframe );
1162 capturePoint = pt;
1163 sizingRect = newRect;
1168 ReleaseCapture();
1169 if( iconic )
1171 ShowCursor32( FALSE );
1172 SetCursor32(hOldCursor);
1173 if( hDragCursor ) DestroyCursor32( hDragCursor );
1175 else
1176 NC_DrawMovingFrame( hdc, &sizingRect, thickframe );
1178 if (wndPtr->dwStyle & WS_CHILD)
1179 ReleaseDC32( wndPtr->parent->hwndSelf, hdc );
1180 else
1182 ReleaseDC32( 0, hdc );
1183 if (rootWindow == DefaultRootWindow(display)) XUngrabServer( display );
1186 if (HOOK_IsHooked( WH_CBT ))
1188 RECT16* pr = SEGPTR_NEW(RECT16);
1189 if( pr )
1191 *pr = sizingRect;
1192 if( HOOK_CallHooks16( WH_CBT, HCBT_MOVESIZE, hwnd,
1193 (LPARAM)SEGPTR_GET(pr)) )
1194 sizingRect = wndPtr->rectWindow;
1195 else
1196 sizingRect = *pr;
1197 SEGPTR_FREE(pr);
1200 SendMessage16( hwnd, WM_EXITSIZEMOVE, 0, 0 );
1201 SendMessage16( hwnd, WM_SETVISIBLE, !IsIconic16(hwnd), 0L);
1203 /* Single click brings up the system menu when iconized */
1205 if (!moved && (wndPtr->dwStyle & WS_MINIMIZE))
1207 NC_TrackSysMenu( hwnd, pt );
1208 return;
1211 /* If Esc key, don't move the window */
1212 if ((msg.message == WM_KEYDOWN) && (msg.wParam == VK_ESCAPE)) return;
1214 if (hittest != HTCAPTION)
1215 SetWindowPos32( hwnd, 0, sizingRect.left, sizingRect.top,
1216 sizingRect.right - sizingRect.left,
1217 sizingRect.bottom - sizingRect.top,
1218 SWP_NOACTIVATE | SWP_NOZORDER );
1219 else SetWindowPos32( hwnd, 0, sizingRect.left, sizingRect.top, 0, 0,
1220 SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER );
1224 /***********************************************************************
1225 * NC_TrackMinMaxBox
1227 * Track a mouse button press on the minimize or maximize box.
1229 static void NC_TrackMinMaxBox( HWND32 hwnd, WORD wParam )
1231 MSG16 msg;
1232 HDC32 hdc = GetWindowDC32( hwnd );
1233 BOOL pressed = TRUE;
1235 SetCapture32( hwnd );
1236 if (wParam == HTMINBUTTON) NC_DrawMinButton( hwnd, hdc, TRUE );
1237 else NC_DrawMaxButton( hwnd, hdc, TRUE );
1241 BOOL oldstate = pressed;
1242 MSG_InternalGetMessage( &msg, 0, 0, 0, PM_REMOVE, FALSE );
1244 pressed = (NC_HandleNCHitTest( hwnd, msg.pt ) == wParam);
1245 if (pressed != oldstate)
1247 if (wParam == HTMINBUTTON) NC_DrawMinButton( hwnd, hdc, pressed );
1248 else NC_DrawMaxButton( hwnd, hdc, pressed );
1250 } while (msg.message != WM_LBUTTONUP);
1252 if (wParam == HTMINBUTTON) NC_DrawMinButton( hwnd, hdc, FALSE );
1253 else NC_DrawMaxButton( hwnd, hdc, FALSE );
1255 ReleaseCapture();
1256 ReleaseDC32( hwnd, hdc );
1257 if (!pressed) return;
1259 if (wParam == HTMINBUTTON)
1260 SendMessage16( hwnd, WM_SYSCOMMAND, SC_MINIMIZE, *(LONG*)&msg.pt );
1261 else
1262 SendMessage16( hwnd, WM_SYSCOMMAND,
1263 IsZoomed32(hwnd) ? SC_RESTORE:SC_MAXIMIZE, *(LONG*)&msg.pt );
1267 /***********************************************************************
1268 * NC_TrackScrollBar
1270 * Track a mouse button press on the horizontal or vertical scroll-bar.
1272 static void NC_TrackScrollBar( HWND32 hwnd, WPARAM32 wParam, POINT32 pt )
1274 MSG16 *msg;
1275 INT32 scrollbar;
1276 WND *wndPtr = WIN_FindWndPtr( hwnd );
1278 if ((wParam & 0xfff0) == SC_HSCROLL)
1280 if ((wParam & 0x0f) != HTHSCROLL) return;
1281 scrollbar = SB_HORZ;
1283 else /* SC_VSCROLL */
1285 if ((wParam & 0x0f) != HTVSCROLL) return;
1286 scrollbar = SB_VERT;
1289 if (!(msg = SEGPTR_NEW(MSG16))) return;
1290 pt.x -= wndPtr->rectWindow.left;
1291 pt.y -= wndPtr->rectWindow.top;
1292 SetCapture32( hwnd );
1293 SCROLL_HandleScrollEvent( hwnd, scrollbar, WM_LBUTTONDOWN, pt );
1297 GetMessage( SEGPTR_GET(msg), 0, 0, 0 );
1298 switch(msg->message)
1300 case WM_LBUTTONUP:
1301 case WM_MOUSEMOVE:
1302 case WM_SYSTIMER:
1303 pt.x = LOWORD(msg->lParam) + wndPtr->rectClient.left -
1304 wndPtr->rectWindow.left;
1305 pt.y = HIWORD(msg->lParam) + wndPtr->rectClient.top -
1306 wndPtr->rectWindow.top;
1307 SCROLL_HandleScrollEvent( hwnd, scrollbar, msg->message, pt );
1308 break;
1309 default:
1310 TranslateMessage16( msg );
1311 DispatchMessage16( msg );
1312 break;
1314 if (!IsWindow( hwnd ))
1316 ReleaseCapture();
1317 break;
1319 } while (msg->message != WM_LBUTTONUP);
1320 SEGPTR_FREE(msg);
1323 /***********************************************************************
1324 * NC_HandleNCLButtonDown
1326 * Handle a WM_NCLBUTTONDOWN message. Called from DefWindowProc().
1328 LONG NC_HandleNCLButtonDown( HWND32 hwnd, WPARAM16 wParam, LPARAM lParam )
1330 switch(wParam) /* Hit test */
1332 case HTCAPTION:
1333 SendMessage16( hwnd, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, lParam );
1334 break;
1336 case HTSYSMENU:
1337 NC_TrackSysMenu( hwnd, MAKEPOINT16(lParam) );
1338 break;
1340 case HTMENU:
1341 SendMessage16( hwnd, WM_SYSCOMMAND, SC_MOUSEMENU, lParam );
1342 break;
1344 case HTHSCROLL:
1345 SendMessage16( hwnd, WM_SYSCOMMAND, SC_HSCROLL + HTHSCROLL, lParam );
1346 break;
1348 case HTVSCROLL:
1349 SendMessage16( hwnd, WM_SYSCOMMAND, SC_VSCROLL + HTVSCROLL, lParam );
1350 break;
1352 case HTMINBUTTON:
1353 case HTMAXBUTTON:
1354 NC_TrackMinMaxBox( hwnd, wParam );
1355 break;
1357 case HTLEFT:
1358 case HTRIGHT:
1359 case HTTOP:
1360 case HTTOPLEFT:
1361 case HTTOPRIGHT:
1362 case HTBOTTOM:
1363 case HTBOTTOMLEFT:
1364 case HTBOTTOMRIGHT:
1365 SendMessage16( hwnd, WM_SYSCOMMAND, SC_SIZE + wParam - HTLEFT+1, lParam);
1366 break;
1368 case HTBORDER:
1369 break;
1371 return 0;
1375 /***********************************************************************
1376 * NC_HandleNCLButtonDblClk
1378 * Handle a WM_NCLBUTTONDBLCLK message. Called from DefWindowProc().
1380 LONG NC_HandleNCLButtonDblClk( WND *pWnd, WPARAM16 wParam, LPARAM lParam )
1383 * if this is an icon, send a restore since we are handling
1384 * a double click
1386 if (pWnd->dwStyle & WS_MINIMIZE)
1388 SendMessage16( pWnd->hwndSelf, WM_SYSCOMMAND, SC_RESTORE, lParam );
1389 return 0;
1392 switch(wParam) /* Hit test */
1394 case HTCAPTION:
1395 /* stop processing if WS_MAXIMIZEBOX is missing */
1396 if (pWnd->dwStyle & WS_MAXIMIZEBOX)
1397 SendMessage16( pWnd->hwndSelf, WM_SYSCOMMAND,
1398 (pWnd->dwStyle & WS_MAXIMIZE) ? SC_RESTORE : SC_MAXIMIZE,
1399 lParam );
1400 break;
1402 case HTSYSMENU:
1403 if (!(pWnd->class->style & CS_NOCLOSE))
1404 SendMessage16( pWnd->hwndSelf, WM_SYSCOMMAND, SC_CLOSE, lParam );
1405 break;
1407 return 0;
1411 /***********************************************************************
1412 * NC_HandleSysCommand
1414 * Handle a WM_SYSCOMMAND message. Called from DefWindowProc().
1416 LONG NC_HandleSysCommand( HWND32 hwnd, WPARAM16 wParam, POINT16 pt )
1418 WND *wndPtr = WIN_FindWndPtr( hwnd );
1419 POINT32 pt32;
1421 dprintf_nonclient(stddeb, "Handling WM_SYSCOMMAND %x %d,%d\n",
1422 wParam, pt.x, pt.y );
1424 if (wndPtr->dwStyle & WS_CHILD && wParam != SC_KEYMENU )
1425 ScreenToClient16( wndPtr->parent->hwndSelf, &pt );
1427 switch (wParam & 0xfff0)
1429 case SC_SIZE:
1430 case SC_MOVE:
1431 NC_DoSizeMove( hwnd, wParam, pt );
1432 break;
1434 case SC_MINIMIZE:
1435 ShowWindow32( hwnd, SW_MINIMIZE );
1436 break;
1438 case SC_MAXIMIZE:
1439 ShowWindow32( hwnd, SW_MAXIMIZE );
1440 break;
1442 case SC_RESTORE:
1443 ShowWindow32( hwnd, SW_RESTORE );
1444 break;
1446 case SC_CLOSE:
1447 return SendMessage16( hwnd, WM_CLOSE, 0, 0 );
1449 case SC_VSCROLL:
1450 case SC_HSCROLL:
1451 CONV_POINT16TO32( &pt, &pt32 );
1452 NC_TrackScrollBar( hwnd, wParam, pt32 );
1453 break;
1455 case SC_MOUSEMENU:
1456 CONV_POINT16TO32( &pt, &pt32 );
1457 MENU_TrackMouseMenuBar( wndPtr, wParam & 0x000F, pt32 );
1458 break;
1460 case SC_KEYMENU:
1461 MENU_TrackKbdMenuBar( wndPtr , wParam , pt.x );
1462 break;
1464 case SC_TASKLIST:
1465 WinExec32( "taskman.exe", SW_SHOWNORMAL );
1466 break;
1468 case SC_SCREENSAVE:
1469 if (wParam == SC_ABOUTWINE)
1471 extern const char people[];
1472 ShellAbout32A(hwnd,"Wine",people,0);
1474 break;
1476 case SC_HOTKEY:
1477 case SC_ARRANGE:
1478 case SC_NEXTWINDOW:
1479 case SC_PREVWINDOW:
1480 /* FIXME: unimplemented */
1481 break;
1483 return 0;