2 * Non-client area window functions
4 * Copyright 1994 Alexandre Julliard
11 #include "sysmetrics.h"
14 #include "cursoricon.h"
20 #include "nonclient.h"
23 #include "selectors.h"
29 int NC_CaptionLeftNudge;
30 int NC_CaptionTopNudge;
31 int NC_SysControlNudge;
32 int NC_MaxControlNudge;
33 int NC_MinControlNudge;
34 UINT32 NC_CaptionTextFlags;
35 HBRUSH32 NC_WinHighlight95;
36 HBRUSH32 NC_WinShadow95;
38 static HBITMAP16 hbitmapClose = 0;
39 static HBITMAP16 hbitmapMinimize = 0;
40 static HBITMAP16 hbitmapMinimizeD = 0;
41 static HBITMAP16 hbitmapMaximize = 0;
42 static HBITMAP16 hbitmapMaximizeD = 0;
43 static HBITMAP16 hbitmapRestore = 0;
44 static HBITMAP16 hbitmapRestoreD = 0;
46 #define SC_ABOUTWINE (SC_SCREENSAVE+1)
48 /* Some useful macros */
49 #define HAS_DLGFRAME(style,exStyle) \
50 (((exStyle) & WS_EX_DLGMODALFRAME) || \
51 (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
53 #define HAS_THICKFRAME(style) \
54 (((style) & WS_THICKFRAME) && \
55 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
57 #define HAS_MENU(w) (!((w)->dwStyle & WS_CHILD) && ((w)->wIDmenu != 0))
59 #define ON_LEFT_BORDER(hit) \
60 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
61 #define ON_RIGHT_BORDER(hit) \
62 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
63 #define ON_TOP_BORDER(hit) \
64 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
65 #define ON_BOTTOM_BORDER(hit) \
66 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
68 /***********************************************************************
71 * Compute the size of the window rectangle from the size of the
74 static void NC_AdjustRect( LPRECT16 rect, DWORD style, BOOL32 menu,
78 ERR(nonclient, "Called in Win95 mode. Aiee! Please report this.\n" );
80 if(style & WS_ICONIC) return;
81 /* Decide if the window will be managed (see CreateWindowEx) */
82 if (!(Options.managed && !(style & WS_CHILD) &&
83 ((style & (WS_DLGFRAME | WS_THICKFRAME)) ||
84 (exStyle & WS_EX_DLGMODALFRAME))))
86 if (HAS_DLGFRAME( style, exStyle ))
87 InflateRect16(rect, SYSMETRICS_CXDLGFRAME, SYSMETRICS_CYDLGFRAME );
90 if (HAS_THICKFRAME(style))
91 InflateRect16( rect, SYSMETRICS_CXFRAME, SYSMETRICS_CYFRAME );
92 if (style & WS_BORDER)
93 InflateRect16( rect, SYSMETRICS_CXBORDER, SYSMETRICS_CYBORDER);
96 if ((style & WS_CAPTION) == WS_CAPTION)
97 rect->top -= SYSMETRICS_CYCAPTION - SYSMETRICS_CYBORDER;
99 if (menu) rect->top -= SYSMETRICS_CYMENU + SYSMETRICS_CYBORDER;
101 if (style & WS_VSCROLL) rect->right += SYSMETRICS_CXVSCROLL - 1;
102 if (style & WS_HSCROLL) rect->bottom += SYSMETRICS_CYHSCROLL - 1;
106 /******************************************************************************
114 * Computes the size of the window based on the parameters of the client
118 * Most of this code is copied from NC_AdjustRect. It shouldn't be.
119 * There are some unique things about Win 95 that are being horribly
120 * neglected here. I don't know what they are, either. :-\
123 * 05-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu)
124 * Original cut & paste from NC_AdjustRect
126 *****************************************************************************/
128 static void NC_AdjustRect95( LPRECT16 rect, DWORD style, BOOL32 menu,
131 if(style & WS_ICONIC) return;
133 /* Decide if the window will be managed (see CreateWindowEx) */
134 if (!(Options.managed && !(style & WS_CHILD) &&
135 ((style & (WS_DLGFRAME | WS_THICKFRAME)) ||
136 (exStyle & WS_EX_DLGMODALFRAME))))
138 if (HAS_DLGFRAME( style, exStyle ))
139 InflateRect16(rect, SYSMETRICS_CXDLGFRAME, SYSMETRICS_CYDLGFRAME );
142 if (HAS_THICKFRAME(style))
143 InflateRect16( rect, SYSMETRICS_CXFRAME, SYSMETRICS_CYFRAME );
144 if (style & WS_BORDER)
145 InflateRect16( rect, SYSMETRICS_CXBORDER, SYSMETRICS_CYBORDER);
148 if ((style & WS_CAPTION) == WS_CAPTION)
149 rect->top -= SYSMETRICS_CYCAPTION - SYSMETRICS_CYBORDER;
151 if (menu) rect->top -= SYSMETRICS_CYMENU + SYSMETRICS_CYBORDER + 2;
152 else if (!(style & WS_CHILD)) rect->top += SYSMETRICS_CYBORDER;
154 if (style & WS_VSCROLL) rect->right += SYSMETRICS_CXVSCROLL;
155 if (style & WS_HSCROLL) rect->bottom += SYSMETRICS_CYHSCROLL;
159 /***********************************************************************
160 * DrawCaptionTempA (USER32.599)
162 DWORD DrawCaptionTemp32A(HWND32 hwnd,HDC32 hdc,LPRECT32 rect,
163 HFONT32 hfont,DWORD x1,LPCSTR str,DWORD x2)
165 FIXME(nonclient,"(%08x,%08x,%p,%08x,%08lx,\"%s\",%08lx): stub\n",
166 hwnd,hdc,rect,hfont,x1,str,x2);
171 /***********************************************************************
172 * AdjustWindowRect16 (USER.102)
174 BOOL16 WINAPI AdjustWindowRect16( LPRECT16 rect, DWORD style, BOOL16 menu )
176 return AdjustWindowRectEx16( rect, style, menu, 0 );
180 /***********************************************************************
181 * AdjustWindowRect32 (USER32.2)
183 BOOL32 WINAPI AdjustWindowRect32( LPRECT32 rect, DWORD style, BOOL32 menu )
185 return AdjustWindowRectEx32( rect, style, menu, 0 );
189 /***********************************************************************
190 * AdjustWindowRectEx16 (USER.454)
192 BOOL16 WINAPI AdjustWindowRectEx16( LPRECT16 rect, DWORD style,
193 BOOL16 menu, DWORD exStyle )
195 /* Correct the window style */
197 if (!(style & (WS_POPUP | WS_CHILD))) /* Overlapped window */
199 style &= (WS_DLGFRAME | WS_BORDER | WS_THICKFRAME | WS_CHILD);
200 exStyle &= WS_EX_DLGMODALFRAME;
201 if (exStyle & WS_EX_DLGMODALFRAME) style &= ~WS_THICKFRAME;
203 TRACE(nonclient, "(%d,%d)-(%d,%d) %08lx %d %08lx\n",
204 rect->left, rect->top, rect->right, rect->bottom,
205 style, menu, exStyle );
208 NC_AdjustRect95( rect, style, menu, exStyle );
210 NC_AdjustRect( rect, style, menu, exStyle );
216 /***********************************************************************
217 * AdjustWindowRectEx32 (USER32.3)
219 BOOL32 WINAPI AdjustWindowRectEx32( LPRECT32 rect, DWORD style,
220 BOOL32 menu, DWORD exStyle )
225 CONV_RECT32TO16( rect, &rect16 );
226 ret = AdjustWindowRectEx16( &rect16, style, (BOOL16)menu, exStyle );
227 CONV_RECT16TO32( &rect16, rect );
232 /***********************************************************************
233 * NC_HandleNCCalcSize
235 * Handle a WM_NCCALCSIZE message. Called from DefWindowProc().
237 LONG NC_HandleNCCalcSize( WND *pWnd, RECT32 *winRect )
239 RECT16 tmpRect = { 0, 0, 0, 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_AdjustRect95( &tmpRect, pWnd->dwStyle, FALSE, pWnd->dwExStyle );
249 NC_AdjustRect( &tmpRect, pWnd->dwStyle, FALSE, pWnd->dwExStyle );
251 winRect->left -= tmpRect.left;
252 winRect->top -= tmpRect.top;
253 winRect->right -= tmpRect.right;
254 winRect->bottom -= tmpRect.bottom;
256 if (HAS_MENU(pWnd)) {
257 TRACE(nonclient, "Calling "
258 "GetMenuBarHeight with HWND 0x%x, width %d, "
259 "at (%d, %d).\n", pWnd->hwndSelf,
260 winRect->right - winRect->left,
261 -tmpRect.left, -tmpRect.top );
264 MENU_GetMenuBarHeight( pWnd->hwndSelf,
265 winRect->right - winRect->left,
266 -tmpRect.left, -tmpRect.top ) + 1;
273 /***********************************************************************
276 * Get the 'inside' rectangle of a window, i.e. the whole window rectangle
277 * but without the borders (if any).
278 * The rectangle is in window coordinates (for drawing with GetWindowDC()).
280 * FIXME: A Win95 version of this function is needed.
282 static void NC_GetInsideRect( HWND32 hwnd, RECT32 *rect )
284 WND * wndPtr = WIN_FindWndPtr( hwnd );
286 rect->top = rect->left = 0;
287 rect->right = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
288 rect->bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
290 if ((wndPtr->dwStyle & WS_ICONIC) || (wndPtr->flags & WIN_MANAGED)) return;
292 /* Remove frame from rectangle */
293 if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
295 InflateRect32( rect, -SYSMETRICS_CXDLGFRAME, -SYSMETRICS_CYDLGFRAME);
296 if (wndPtr->dwExStyle & WS_EX_DLGMODALFRAME)
297 InflateRect32( rect, -1, 0 );
301 if (HAS_THICKFRAME( wndPtr->dwStyle ))
302 InflateRect32( rect, -SYSMETRICS_CXFRAME, -SYSMETRICS_CYFRAME );
303 if (wndPtr->dwStyle & WS_BORDER)
304 InflateRect32( rect, -SYSMETRICS_CXBORDER, -SYSMETRICS_CYBORDER );
311 /***********************************************************************
314 * Handle a WM_NCHITTEST message. Called from DefWindowProc().
316 * FIXME: A Win95 version of this function is needed.
318 LONG NC_HandleNCHitTest( HWND32 hwnd, POINT16 pt )
321 WND *wndPtr = WIN_FindWndPtr( hwnd );
322 if (!wndPtr) return HTERROR;
324 TRACE(nonclient, "hwnd=%04x pt=%d,%d\n",
327 GetWindowRect16( hwnd, &rect );
328 if (!PtInRect16( &rect, pt )) return HTNOWHERE;
330 if (wndPtr->dwStyle & WS_MINIMIZE) return HTCAPTION;
332 if (!(wndPtr->flags & WIN_MANAGED))
335 if (HAS_THICKFRAME( wndPtr->dwStyle ))
337 InflateRect16( &rect, -SYSMETRICS_CXFRAME, -SYSMETRICS_CYFRAME );
338 if (wndPtr->dwStyle & WS_BORDER)
339 InflateRect16(&rect,-SYSMETRICS_CXBORDER,-SYSMETRICS_CYBORDER);
340 if (!PtInRect16( &rect, pt ))
342 /* Check top sizing border */
345 if (pt.x < rect.left+SYSMETRICS_CXSIZE) return HTTOPLEFT;
346 if (pt.x >= rect.right-SYSMETRICS_CXSIZE) return HTTOPRIGHT;
349 /* Check bottom sizing border */
350 if (pt.y >= rect.bottom)
352 if (pt.x < rect.left+SYSMETRICS_CXSIZE) return HTBOTTOMLEFT;
353 if (pt.x >= rect.right-SYSMETRICS_CXSIZE) return HTBOTTOMRIGHT;
356 /* Check left sizing border */
357 if (pt.x < rect.left)
359 if (pt.y < rect.top+SYSMETRICS_CYSIZE) return HTTOPLEFT;
360 if (pt.y >= rect.bottom-SYSMETRICS_CYSIZE) return HTBOTTOMLEFT;
363 /* Check right sizing border */
364 if (pt.x >= rect.right)
366 if (pt.y < rect.top+SYSMETRICS_CYSIZE) return HTTOPRIGHT;
367 if (pt.y >= rect.bottom-SYSMETRICS_CYSIZE) return HTBOTTOMRIGHT;
372 else /* No thick frame */
374 if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
375 InflateRect16(&rect, -SYSMETRICS_CXDLGFRAME, -SYSMETRICS_CYDLGFRAME);
376 else if (wndPtr->dwStyle & WS_BORDER)
377 InflateRect16(&rect, -SYSMETRICS_CXBORDER, -SYSMETRICS_CYBORDER);
378 if (!PtInRect16( &rect, pt )) return HTBORDER;
383 if ((wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION)
385 rect.top += SYSMETRICS_CYCAPTION - 1;
386 if (!PtInRect16( &rect, pt ))
388 /* Check system menu */
389 if (wndPtr->dwStyle & WS_SYSMENU)
390 rect.left += SYSMETRICS_CXSIZE;
391 if (pt.x <= rect.left) return HTSYSMENU;
392 /* Check maximize box */
393 if (wndPtr->dwStyle & WS_MAXIMIZEBOX)
394 rect.right -= SYSMETRICS_CXSIZE + 1;
395 if (pt.x >= rect.right) return HTMAXBUTTON;
396 /* Check minimize box */
397 if (wndPtr->dwStyle & WS_MINIMIZEBOX)
398 rect.right -= SYSMETRICS_CXSIZE + 1;
399 if (pt.x >= rect.right) return HTMINBUTTON;
405 /* Check client area */
407 ScreenToClient16( hwnd, &pt );
408 GetClientRect16( hwnd, &rect );
409 if (PtInRect16( &rect, pt )) return HTCLIENT;
411 /* Check vertical scroll bar */
413 if (wndPtr->dwStyle & WS_VSCROLL)
415 rect.right += SYSMETRICS_CXVSCROLL;
416 if (PtInRect16( &rect, pt )) return HTVSCROLL;
419 /* Check horizontal scroll bar */
421 if (wndPtr->dwStyle & WS_HSCROLL)
423 rect.bottom += SYSMETRICS_CYHSCROLL;
424 if (PtInRect16( &rect, pt ))
427 if ((wndPtr->dwStyle & WS_VSCROLL) &&
428 (pt.x >= rect.right - SYSMETRICS_CXVSCROLL))
436 if (HAS_MENU(wndPtr))
438 if ((pt.y < 0) && (pt.x >= 0) && (pt.x < rect.right))
442 /* Should never get here */
447 /***********************************************************************
450 void NC_DrawSysButton( HWND32 hwnd, HDC32 hdc, BOOL32 down )
455 WND *wndPtr = WIN_FindWndPtr( hwnd );
457 if( !(wndPtr->flags & WIN_MANAGED) )
459 NC_GetInsideRect( hwnd, &rect );
460 hdcMem = CreateCompatibleDC32( hdc );
461 hbitmap = SelectObject32( hdcMem, hbitmapClose );
462 BitBlt32(hdc, rect.left, rect.top, SYSMETRICS_CXSIZE, SYSMETRICS_CYSIZE,
463 hdcMem, (wndPtr->dwStyle & WS_CHILD) ? SYSMETRICS_CXSIZE : 0, 0,
464 down ? NOTSRCCOPY : SRCCOPY );
465 SelectObject32( hdcMem, hbitmap );
466 DeleteDC32( hdcMem );
471 /***********************************************************************
474 static void NC_DrawMaxButton( HWND32 hwnd, HDC16 hdc, BOOL32 down )
477 WND *wndPtr = WIN_FindWndPtr( hwnd );
479 if( !(wndPtr->flags & WIN_MANAGED) )
481 NC_GetInsideRect( hwnd, &rect );
482 GRAPH_DrawBitmap( hdc, (IsZoomed32(hwnd)
483 ? (down ? hbitmapRestoreD : hbitmapRestore)
484 : (down ? hbitmapMaximizeD : hbitmapMaximize)),
485 rect.right - SYSMETRICS_CXSIZE - 1, rect.top,
486 0, 0, SYSMETRICS_CXSIZE+1, SYSMETRICS_CYSIZE, FALSE );
491 /***********************************************************************
494 static void NC_DrawMinButton( HWND32 hwnd, HDC16 hdc, BOOL32 down )
497 WND *wndPtr = WIN_FindWndPtr( hwnd );
499 if( !(wndPtr->flags & WIN_MANAGED) )
501 NC_GetInsideRect( hwnd, &rect );
502 if (wndPtr->dwStyle & WS_MAXIMIZEBOX) rect.right -= SYSMETRICS_CXSIZE+1;
503 GRAPH_DrawBitmap( hdc, (down ? hbitmapMinimizeD : hbitmapMinimize),
504 rect.right - SYSMETRICS_CXSIZE - 1, rect.top,
505 0, 0, SYSMETRICS_CXSIZE+1, SYSMETRICS_CYSIZE, FALSE );
510 /******************************************************************************
512 * void NC_DrawSysButton95(
517 * Draws a fake Win95 system button. Horribly broken. We should be drawing
518 * an icon, not the X. (This will require some thought)
521 * Plain and simply doesn't work. Fails miserably for child windows.
524 * 05-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu)
525 * Original implementation from NC_DrawSysButton source.
527 *****************************************************************************/
529 void NC_DrawSysButton95(
537 WND *wndPtr = WIN_FindWndPtr( hwnd );
540 if( !(wndPtr->flags & WIN_MANAGED) )
542 NC_GetInsideRect( hwnd, &rect );
543 hdcMem = CreateCompatibleDC32( hdc );
544 hbitmap = SelectObject32( hdcMem, hbitmapClose );
545 if(GetBitmapDimensionEx32( hbitmapClose, &bmsz )) {
546 BitBlt32(hdc, rect.left + (sysMetrics[SM_CXSIZE] - bmsz.cx) / 2 +
548 rect.top + (sysMetrics[SM_CYSIZE] - bmsz.cy - 1) / 2,
550 hdcMem, 0, 0, down ? NOTSRCCOPY : SRCCOPY );
552 SelectObject32( hdcMem, hbitmap );
553 DeleteDC32( hdcMem );
560 /******************************************************************************
562 * NC_DrawMaxButton95(
567 * Draws the maximize button for Win95 style windows.
570 * Many. Spacing might still be incorrect. Need to fit a close
571 * button between the max button and the edge. Draws the wrong thing
572 * (a Win31 up-down) when maximized. Should scale the image with the
573 * title bar. And more...
576 * 05-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu)
577 * Original implementation.
579 *****************************************************************************/
581 static void NC_DrawMaxButton95(
587 WND *wndPtr = WIN_FindWndPtr( hwnd );
591 if( !(wndPtr->flags & WIN_MANAGED) &&
592 GetBitmapDimensionEx32((bm = IsZoomed32(hwnd) ?
593 (down ? hbitmapRestoreD : hbitmapRestore ) :
594 (down ? hbitmapMaximizeD : hbitmapMaximize)),
597 NC_GetInsideRect( hwnd, &rect );
599 GRAPH_DrawBitmap( hdc, bm,
600 rect.right + NC_MaxControlNudge -
601 (sysMetrics[SM_CXSIZE] + bmsz.cx) / 2,
602 rect.top + (sysMetrics[SM_CYSIZE] - bmsz.cy - 1) / 2,
603 0, 0, bmsz.cx, bmsz.cy, FALSE );
610 /******************************************************************************
612 * NC_DrawMinButton95(
617 * Draws the minimize button for Win95 style windows.
620 * Many. Spacing is still incorrect. Should scale the image with the
621 * title bar. And more...
624 * 05-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu)
625 * Original implementation.
627 *****************************************************************************/
629 static void NC_DrawMinButton95(
635 WND *wndPtr = WIN_FindWndPtr( hwnd );
639 if( !(wndPtr->flags & WIN_MANAGED) &&
640 GetBitmapDimensionEx32((bm = down ? hbitmapMinimizeD :
641 hbitmapMinimize), &bmsz)) {
643 NC_GetInsideRect( hwnd, &rect );
645 if (wndPtr->dwStyle & WS_MAXIMIZEBOX)
646 rect.right += -1 + NC_MaxControlNudge -
647 (sysMetrics[SM_CXSIZE] + bmsz.cx) / 2;
649 GRAPH_DrawBitmap( hdc, bm, rect.right + NC_MinControlNudge -
650 (sysMetrics[SM_CXSIZE] + bmsz.cx) / 2,
651 rect.top + (sysMetrics[SM_CYSIZE] - bmsz.cy - 1) / 2,
652 0, 0, bmsz.cx, bmsz.cy, FALSE );
659 /***********************************************************************
662 * Draw a window frame inside the given rectangle, and update the rectangle.
663 * The correct pen for the frame must be selected in the DC.
665 static void NC_DrawFrame( HDC32 hdc, RECT32 *rect, BOOL32 dlgFrame,
671 ERR(nonclient, "Called in Win95 mode. Aiee! Please report this.\n" );
675 width = SYSMETRICS_CXDLGFRAME - 1;
676 height = SYSMETRICS_CYDLGFRAME - 1;
677 SelectObject32( hdc, GetSysColorBrush32(active ? COLOR_ACTIVECAPTION :
678 COLOR_INACTIVECAPTION) );
682 width = SYSMETRICS_CXFRAME - 1;
683 height = SYSMETRICS_CYFRAME - 1;
684 SelectObject32( hdc, GetSysColorBrush32(active ? COLOR_ACTIVEBORDER :
685 COLOR_INACTIVEBORDER) );
689 PatBlt32( hdc, rect->left, rect->top,
690 rect->right - rect->left, height, PATCOPY );
691 PatBlt32( hdc, rect->left, rect->top,
692 width, rect->bottom - rect->top, PATCOPY );
693 PatBlt32( hdc, rect->left, rect->bottom,
694 rect->right - rect->left, -height, PATCOPY );
695 PatBlt32( hdc, rect->right, rect->top,
696 -width, rect->bottom - rect->top, PATCOPY );
700 InflateRect32( rect, -width, -height );
706 /* Draw inner rectangle */
708 GRAPH_DrawRectangle( hdc, rect->left + width,
710 rect->right - rect->left - 2*width ,
711 rect->bottom - rect->top - 2*height,
714 /* Draw the decorations */
716 lpt[4].x = lpt[0].x = rect->left;
717 lpt[5].x = lpt[1].x = rect->left + width;
718 lpt[6].x = lpt[2].x = rect->right - 1;
719 lpt[7].x = lpt[3].x = rect->right - width - 1;
721 lpt[0].y = lpt[1].y = lpt[2].y = lpt[3].y =
722 rect->top + SYSMETRICS_CYFRAME + SYSMETRICS_CYSIZE;
723 lpt[4].y = lpt[5].y = lpt[6].y = lpt[7].y =
724 rect->bottom - SYSMETRICS_CYFRAME - SYSMETRICS_CYSIZE;
726 lpt[8].x = lpt[9].x = lpt[10].x = lpt[11].x =
727 rect->left + SYSMETRICS_CXFRAME + SYSMETRICS_CXSIZE;
728 lpt[12].x = lpt[13].x = lpt[14].x = lpt[15].x =
729 rect->right - SYSMETRICS_CXFRAME - SYSMETRICS_CYSIZE;
731 lpt[12].y = lpt[8].y = rect->top;
732 lpt[13].y = lpt[9].y = rect->top + height;
733 lpt[14].y = lpt[10].y = rect->bottom - 1;
734 lpt[15].y = lpt[11].y = rect->bottom - height - 1;
736 GRAPH_DrawLines( hdc, lpt, 8, (HPEN32)0 ); /* 8 is the maximum */
737 InflateRect32( rect, -width - 1, -height - 1 );
742 /******************************************************************************
744 * void NC_DrawFrame95(
750 * Draw a window frame inside the given rectangle, and update the rectangle.
751 * The correct pen for the frame must be selected in the DC.
754 * Many. First, just what IS a frame in Win95? Note that the 3D look
755 * on the outer edge is handled by NC_DoNCPaint95. As is the inner
756 * edge. The inner rectangle just inside the frame is handled by the
759 * In short, for most people, this function should be a nop (unless
760 * you LIKE thick borders in Win95/NT4.0 -- I've been working with
761 * them lately, but just to get this code right). Even so, it doesn't
762 * appear to be so. It's being worked on...
765 * 06-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu)
766 * Original implementation (based on NC_DrawFrame)
768 *****************************************************************************/
770 static void NC_DrawFrame95(
780 width = SYSMETRICS_CXDLGFRAME - 1;
781 height = SYSMETRICS_CYDLGFRAME - 1;
782 SelectObject32( hdc, GetSysColorBrush32(active ? COLOR_ACTIVECAPTION :
783 COLOR_INACTIVECAPTION) );
787 width = sysMetrics[SM_CXFRAME] - sysMetrics[SM_CXEDGE] - 1;
788 height = sysMetrics[SM_CYFRAME] - sysMetrics[SM_CYEDGE] - 1;
789 SelectObject32( hdc, GetSysColorBrush32(active ? COLOR_ACTIVEBORDER :
790 COLOR_INACTIVEBORDER) );
794 PatBlt32( hdc, rect->left, rect->top,
795 rect->right - rect->left, height, PATCOPY );
796 PatBlt32( hdc, rect->left, rect->top,
797 width, rect->bottom - rect->top, PATCOPY );
798 PatBlt32( hdc, rect->left, rect->bottom,
799 rect->right - rect->left, -height, PATCOPY );
800 PatBlt32( hdc, rect->right, rect->top,
801 -width, rect->bottom - rect->top, PATCOPY );
803 InflateRect32( rect, -width, -height );
806 /* Draw inner rectangle */
807 GRAPH_DrawRectangle( hdc, rect->left, rect->top,
808 rect->right - rect->left,
809 rect->bottom - rect->top,
812 InflateRect32( rect, -1, -1 );
818 /***********************************************************************
821 * Draw the frame used when moving or resizing window.
823 * FIXME: This causes problems in Win95 mode. (why?)
825 static void NC_DrawMovingFrame( HDC32 hdc, RECT32 *rect, BOOL32 thickframe )
830 CONV_RECT32TO16( rect, &r16 );
831 FastWindowFrame( hdc, &r16, SYSMETRICS_CXFRAME,
832 SYSMETRICS_CYFRAME, PATINVERT );
834 else DrawFocusRect32( hdc, rect );
838 /***********************************************************************
841 * Draw the window caption.
842 * The correct pen for the window frame must be selected in the DC.
844 static void NC_DrawCaption( HDC32 hdc, RECT32 *rect, HWND32 hwnd,
845 DWORD style, BOOL32 active )
848 WND * wndPtr = WIN_FindWndPtr( hwnd );
851 if (wndPtr->flags & WIN_MANAGED) return;
855 if (!(hbitmapClose = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_CLOSE) )))
857 hbitmapMinimize = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_REDUCE) );
858 hbitmapMinimizeD = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_REDUCED) );
859 hbitmapMaximize = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_ZOOM) );
860 hbitmapMaximizeD = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_ZOOMD) );
861 hbitmapRestore = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_RESTORE) );
862 hbitmapRestoreD = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_RESTORED) );
865 if (wndPtr->dwExStyle & WS_EX_DLGMODALFRAME)
867 HBRUSH32 hbrushOld = SelectObject32(hdc, GetSysColorBrush32(COLOR_WINDOW) );
868 PatBlt32( hdc, r.left, r.top, 1, r.bottom-r.top+1,PATCOPY );
869 PatBlt32( hdc, r.right-1, r.top, 1, r.bottom-r.top+1, PATCOPY );
870 PatBlt32( hdc, r.left, r.top-1, r.right-r.left, 1, PATCOPY );
873 SelectObject32( hdc, hbrushOld );
876 MoveTo( hdc, r.left, r.bottom );
877 LineTo32( hdc, r.right, r.bottom );
879 if (style & WS_SYSMENU)
881 NC_DrawSysButton( hwnd, hdc, FALSE );
882 r.left += SYSMETRICS_CXSIZE + 1;
883 MoveTo( hdc, r.left - 1, r.top );
884 LineTo32( hdc, r.left - 1, r.bottom );
886 if (style & WS_MAXIMIZEBOX)
888 NC_DrawMaxButton( hwnd, hdc, FALSE );
889 r.right -= SYSMETRICS_CXSIZE + 1;
891 if (style & WS_MINIMIZEBOX)
893 NC_DrawMinButton( hwnd, hdc, FALSE );
894 r.right -= SYSMETRICS_CXSIZE + 1;
897 FillRect32( hdc, &r, GetSysColorBrush32(active ? COLOR_ACTIVECAPTION :
898 COLOR_INACTIVECAPTION) );
900 if (GetWindowText32A( hwnd, buffer, sizeof(buffer) ))
902 if (active) SetTextColor32( hdc, GetSysColor32( COLOR_CAPTIONTEXT ) );
903 else SetTextColor32( hdc, GetSysColor32( COLOR_INACTIVECAPTIONTEXT ) );
904 SetBkMode32( hdc, TRANSPARENT );
905 DrawText32A( hdc, buffer, -1, &r,
906 DT_SINGLELINE | DT_CENTER | DT_VCENTER | DT_NOPREFIX );
911 /******************************************************************************
920 * Draw the window caption for Win95 style windows.
921 * The correct pen for the window frame must be selected in the DC.
924 * Hey, a function that finally works! Well, almost. In Win95, the
925 * title has its own font -- not the system font. It's being worked
929 * 05-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu)
930 * Original implementation.
932 *****************************************************************************/
934 static void NC_DrawCaption95(
942 WND *wndPtr = WIN_FindWndPtr( hwnd );
945 if (wndPtr->flags & WIN_MANAGED) return;
947 FillRect32( hdc, &r, GetSysColorBrush32(active ? COLOR_ACTIVECAPTION :
948 COLOR_INACTIVECAPTION) );
951 if (!(hbitmapClose = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_CLOSE) )))
953 hbitmapMinimize = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_REDUCE) );
954 hbitmapMinimizeD = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_REDUCED) );
955 hbitmapMaximize = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_ZOOM) );
956 hbitmapMaximizeD = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_ZOOMD) );
957 hbitmapRestore = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_RESTORE) );
958 hbitmapRestoreD = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_RESTORED) );
961 if (wndPtr->dwExStyle & WS_EX_DLGMODALFRAME) {
962 HBRUSH32 hbrushOld = SelectObject32(hdc, GetSysColorBrush32(COLOR_WINDOW) );
963 PatBlt32( hdc, r.left, r.top, 1, r.bottom-r.top+1,PATCOPY );
964 PatBlt32( hdc, r.right-1, r.top, 1, r.bottom-r.top+1, PATCOPY );
965 PatBlt32( hdc, r.left, r.top-1, r.right-r.left, 1, PATCOPY );
968 SelectObject32( hdc, hbrushOld );
971 if (style & WS_SYSMENU) {
972 NC_DrawSysButton95( hwnd, hdc, FALSE );
973 r.left += SYSMETRICS_CXSIZE + 1;
975 if (style & WS_MAXIMIZEBOX) {
976 NC_DrawMaxButton95( hwnd, hdc, FALSE );
977 r.right -= SYSMETRICS_CXSIZE + 1;
979 if (style & WS_MINIMIZEBOX) {
980 NC_DrawMinButton95( hwnd, hdc, FALSE );
981 r.right -= SYSMETRICS_CXSIZE + 1;
984 if (GetWindowText32A( hwnd, buffer, sizeof(buffer) )) {
985 if (active) SetTextColor32( hdc, GetSysColor32( COLOR_CAPTIONTEXT ) );
986 else SetTextColor32( hdc, GetSysColor32( COLOR_INACTIVECAPTIONTEXT ) );
987 SetBkMode32( hdc, TRANSPARENT );
988 r.top += NC_CaptionTopNudge - 2;
989 r.left += NC_CaptionLeftNudge;
990 DrawText32A( hdc, buffer, -1, &r, NC_CaptionTextFlags );
996 /***********************************************************************
999 * Paint the non-client area. clip is currently unused.
1001 void NC_DoNCPaint( WND* wndPtr, HRGN32 clip, BOOL32 suppress_menupaint )
1006 HWND32 hwnd = wndPtr->hwndSelf;
1008 if ( wndPtr->dwStyle & WS_MINIMIZE ||
1009 !WIN_IsWindowDrawable( wndPtr, 0 )) return; /* Nothing to do */
1011 active = wndPtr->flags & WIN_NCACTIVATED;
1013 TRACE(nonclient, "%04x %d\n", hwnd, active );
1015 if (!(hdc = GetDCEx32( hwnd, 0, DCX_USESTYLE | DCX_WINDOW ))) return;
1017 if (ExcludeVisRect( hdc, wndPtr->rectClient.left-wndPtr->rectWindow.left,
1018 wndPtr->rectClient.top-wndPtr->rectWindow.top,
1019 wndPtr->rectClient.right-wndPtr->rectWindow.left,
1020 wndPtr->rectClient.bottom-wndPtr->rectWindow.top )
1023 ReleaseDC32( hwnd, hdc );
1027 rect.top = rect.left = 0;
1028 rect.right = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
1029 rect.bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
1031 SelectObject32( hdc, GetSysColorPen32(COLOR_WINDOWFRAME) );
1033 if (!(wndPtr->flags & WIN_MANAGED))
1035 if ((wndPtr->dwStyle & WS_BORDER) || (wndPtr->dwStyle & WS_DLGFRAME) ||
1036 (wndPtr->dwExStyle & WS_EX_DLGMODALFRAME))
1038 GRAPH_DrawRectangle( hdc, 0, 0,
1039 rect.right, rect.bottom, (HPEN32)0 );
1040 InflateRect32( &rect, -1, -1 );
1043 if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
1044 NC_DrawFrame( hdc, &rect, TRUE, active );
1045 else if (wndPtr->dwStyle & WS_THICKFRAME)
1046 NC_DrawFrame(hdc, &rect, FALSE, active );
1048 if ((wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION)
1051 r.bottom = rect.top + SYSMETRICS_CYSIZE;
1052 rect.top += SYSMETRICS_CYSIZE + SYSMETRICS_CYBORDER;
1053 NC_DrawCaption( hdc, &r, hwnd, wndPtr->dwStyle, active );
1057 if (HAS_MENU(wndPtr))
1060 r.bottom = rect.top + SYSMETRICS_CYMENU; /* default height */
1061 rect.top += MENU_DrawMenuBar( hdc, &r, hwnd, suppress_menupaint );
1064 /* Draw the scroll-bars */
1066 if (wndPtr->dwStyle & WS_VSCROLL)
1067 SCROLL_DrawScrollBar( hwnd, hdc, SB_VERT, TRUE );
1068 if (wndPtr->dwStyle & WS_HSCROLL)
1069 SCROLL_DrawScrollBar( hwnd, hdc, SB_HORZ, TRUE );
1071 /* Draw the "size-box" */
1073 if ((wndPtr->dwStyle & WS_VSCROLL) && (wndPtr->dwStyle & WS_HSCROLL))
1076 r.left = r.right - SYSMETRICS_CXVSCROLL + 1;
1077 r.top = r.bottom - SYSMETRICS_CYHSCROLL + 1;
1078 FillRect32( hdc, &r, GetSysColorBrush32(COLOR_SCROLLBAR) );
1081 ReleaseDC32( hwnd, hdc );
1085 /******************************************************************************
1087 * void NC_DoNCPaint95(
1090 * BOOL32 suppress_menupaint )
1092 * Paint the non-client area for Win95 windows. The clip region is
1093 * currently ignored.
1096 * grep -E -A10 -B5 \(95\)\|\(Bugs\)\|\(FIXME\) windows/nonclient.c \
1097 * misc/tweak.c controls/menu.c # :-)
1100 * 03-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu)
1101 * Original implementation
1103 *****************************************************************************/
1105 void NC_DoNCPaint95(
1108 BOOL32 suppress_menupaint )
1113 HWND32 hwnd = wndPtr->hwndSelf;
1115 if ( wndPtr->dwStyle & WS_MINIMIZE ||
1116 !WIN_IsWindowDrawable( wndPtr, 0 )) return; /* Nothing to do */
1118 active = wndPtr->flags & WIN_NCACTIVATED;
1120 TRACE(nonclient, "%04x %d\n", hwnd, active );
1122 if (!(hdc = GetDCEx32( hwnd, 0, DCX_USESTYLE | DCX_WINDOW ))) return;
1124 if (ExcludeVisRect( hdc, wndPtr->rectClient.left-wndPtr->rectWindow.left,
1125 wndPtr->rectClient.top-wndPtr->rectWindow.top,
1126 wndPtr->rectClient.right-wndPtr->rectWindow.left,
1127 wndPtr->rectClient.bottom-wndPtr->rectWindow.top )
1130 ReleaseDC32( hwnd, hdc );
1134 rect.top = rect.left = 0;
1135 rect.right = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
1136 rect.bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
1138 SelectObject32( hdc, GetSysColorPen32(COLOR_WINDOWFRAME) );
1140 if(!(wndPtr->flags & WIN_MANAGED)) {
1141 if((wndPtr->dwStyle & WS_BORDER) || (wndPtr->dwStyle & WS_DLGFRAME) ||
1142 (wndPtr->dwExStyle & WS_EX_DLGMODALFRAME)) {
1143 TWEAK_DrawReliefRect95(hdc, &rect);
1144 InflateRect32(&rect, -2, -2);
1147 if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
1148 NC_DrawFrame95( hdc, &rect, TRUE, active );
1149 else if (wndPtr->dwStyle & WS_THICKFRAME)
1150 NC_DrawFrame95(hdc, &rect, FALSE, active );
1152 if ((wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION)
1155 POINT32 sep[2] = { { rect.left,
1156 rect.top + sysMetrics[SM_CYCAPTION] - 2 },
1158 rect.top + sysMetrics[SM_CYCAPTION] - 2 } };
1160 r.bottom = rect.top + sysMetrics[SM_CYCAPTION] - 2;
1161 rect.top += sysMetrics[SM_CYCAPTION] - 2 + sysMetrics[SM_CYBORDER];
1162 NC_DrawCaption95( hdc, &r, hwnd, wndPtr->dwStyle, active );
1163 GRAPH_DrawLines( hdc, sep, 1, TWEAK_PenC095 );
1167 if (HAS_MENU(wndPtr))
1170 r.bottom = rect.top + sysMetrics[SM_CYMENU] - sysMetrics[SM_CYBORDER];
1171 r.top -= sysMetrics[SM_CYBORDER];
1173 TRACE(nonclient, "Calling DrawMenuBar with "
1174 "rect (%d, %d)-(%d, %d)\n", r.left, r.top,
1177 rect.top += MENU_DrawMenuBar( hdc, &r, hwnd, suppress_menupaint );
1180 TRACE(nonclient, "After MenuBar, rect is (%d, %d)-(%d, %d).\n",
1181 rect.left, rect.top, rect.right, rect.bottom );
1183 /* Draw the inner frames */
1184 GRAPH_DrawRectangle( hdc, rect.left, rect.top, rect.right - rect.left,
1185 rect.bottom - rect.top, TWEAK_PenC095 );
1186 InflateRect32(&rect, -1, -1);
1187 GRAPH_DrawGenericReliefRect( hdc, &rect, 1, 1, NC_WinShadow95,
1188 NC_WinHighlight95 );
1190 InflateRect32(&rect, -1, -1);
1192 /* Draw the scroll-bars */
1194 if (wndPtr->dwStyle & WS_VSCROLL)
1195 SCROLL_DrawScrollBar( hwnd, hdc, SB_VERT, TRUE );
1196 if (wndPtr->dwStyle & WS_HSCROLL)
1197 SCROLL_DrawScrollBar( hwnd, hdc, SB_HORZ, TRUE );
1199 /* Draw the "size-box" */
1200 if ((wndPtr->dwStyle & WS_VSCROLL) && (wndPtr->dwStyle & WS_HSCROLL))
1203 r.left = r.right - SYSMETRICS_CXVSCROLL + 1;
1204 r.top = r.bottom - SYSMETRICS_CYHSCROLL + 1;
1205 FillRect32( hdc, &r, GetSysColorBrush32(COLOR_SCROLLBAR) );
1208 ReleaseDC32( hwnd, hdc );
1214 /***********************************************************************
1217 * Handle a WM_NCPAINT message. Called from DefWindowProc().
1219 LONG NC_HandleNCPaint( HWND32 hwnd , HRGN32 clip)
1221 WND* wndPtr = WIN_FindWndPtr( hwnd );
1223 if( wndPtr && wndPtr->dwStyle & WS_VISIBLE )
1225 if( wndPtr->dwStyle & WS_MINIMIZE )
1226 WINPOS_RedrawIconTitle( hwnd );
1227 else if(TWEAK_Win95Look)
1228 NC_DoNCPaint95( wndPtr, clip, FALSE );
1230 NC_DoNCPaint( wndPtr, clip, FALSE );
1236 /***********************************************************************
1237 * NC_HandleNCActivate
1239 * Handle a WM_NCACTIVATE message. Called from DefWindowProc().
1241 LONG NC_HandleNCActivate( WND *wndPtr, WPARAM16 wParam )
1245 if( wParam ) wStateChange = !(wndPtr->flags & WIN_NCACTIVATED);
1246 else wStateChange = wndPtr->flags & WIN_NCACTIVATED;
1250 if (wParam) wndPtr->flags |= WIN_NCACTIVATED;
1251 else wndPtr->flags &= ~WIN_NCACTIVATED;
1253 if( wndPtr->dwStyle & WS_MINIMIZE )
1254 WINPOS_RedrawIconTitle( wndPtr->hwndSelf );
1255 else if( TWEAK_Win95Look )
1256 NC_DoNCPaint95( wndPtr, (HRGN32)1, FALSE );
1258 NC_DoNCPaint( wndPtr, (HRGN32)1, FALSE );
1264 /***********************************************************************
1265 * NC_HandleSetCursor
1267 * Handle a WM_SETCURSOR message. Called from DefWindowProc().
1269 LONG NC_HandleSetCursor( HWND32 hwnd, WPARAM16 wParam, LPARAM lParam )
1271 if (hwnd != (HWND32)wParam) return 0; /* Don't set the cursor for child windows */
1273 switch(LOWORD(lParam))
1277 WORD msg = HIWORD( lParam );
1278 if ((msg == WM_LBUTTONDOWN) || (msg == WM_MBUTTONDOWN) ||
1279 (msg == WM_RBUTTONDOWN))
1287 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) break;
1288 if (wndPtr->class->hCursor)
1290 SetCursor16( wndPtr->class->hCursor );
1298 return (LONG)SetCursor16( LoadCursor16( 0, IDC_SIZEWE16 ) );
1302 return (LONG)SetCursor16( LoadCursor16( 0, IDC_SIZENS16 ) );
1306 return (LONG)SetCursor16( LoadCursor16( 0, IDC_SIZENWSE16 ) );
1310 return (LONG)SetCursor16( LoadCursor16( 0, IDC_SIZENESW16 ) );
1313 /* Default cursor: arrow */
1314 return (LONG)SetCursor16( LoadCursor16( 0, IDC_ARROW16 ) );
1317 /***********************************************************************
1320 BOOL32 NC_GetSysPopupPos( WND* wndPtr, RECT32* rect )
1322 if( wndPtr->hSysMenu )
1324 if( wndPtr->dwStyle & WS_MINIMIZE )
1325 GetWindowRect32( wndPtr->hwndSelf, rect );
1328 NC_GetInsideRect( wndPtr->hwndSelf, rect );
1329 OffsetRect32( rect, wndPtr->rectWindow.left, wndPtr->rectWindow.top);
1330 if (wndPtr->dwStyle & WS_CHILD)
1331 ClientToScreen32( wndPtr->parent->hwndSelf, (POINT32 *)rect );
1332 rect->right = rect->left + SYSMETRICS_CXSIZE;
1333 rect->bottom = rect->top + SYSMETRICS_CYSIZE;
1340 /***********************************************************************
1343 * Initialisation of a move or resize, when initiatied from a menu choice.
1344 * Return hit test code for caption or sizing border.
1346 static LONG NC_StartSizeMove( WND* wndPtr, WPARAM16 wParam,
1347 POINT16 *capturePoint )
1353 if ((wParam & 0xfff0) == SC_MOVE)
1355 /* Move pointer at the center of the caption */
1357 NC_GetInsideRect( wndPtr->hwndSelf, &rect );
1358 if (wndPtr->dwStyle & WS_SYSMENU)
1359 rect.left += SYSMETRICS_CXSIZE + 1;
1360 if (wndPtr->dwStyle & WS_MINIMIZEBOX)
1361 rect.right -= SYSMETRICS_CXSIZE + 1;
1362 if (wndPtr->dwStyle & WS_MAXIMIZEBOX)
1363 rect.right -= SYSMETRICS_CXSIZE + 1;
1364 pt.x = wndPtr->rectWindow.left + (rect.right - rect.left) / 2;
1365 pt.y = wndPtr->rectWindow.top + rect.top + SYSMETRICS_CYSIZE/2;
1366 hittest = HTCAPTION;
1369 if (wndPtr->dwStyle & WS_CHILD)
1370 ClientToScreen16( wndPtr->parent->hwndSelf, &pt );
1376 MSG_InternalGetMessage( &msg, 0, 0, MSGF_SIZE, PM_REMOVE, FALSE );
1380 hittest = NC_HandleNCHitTest( wndPtr->hwndSelf, msg.pt );
1382 if ((hittest < HTLEFT) || (hittest > HTBOTTOMRIGHT))
1394 pt.x =(wndPtr->rectWindow.left+wndPtr->rectWindow.right)/2;
1395 pt.y = wndPtr->rectWindow.top + SYSMETRICS_CYFRAME / 2;
1399 pt.x =(wndPtr->rectWindow.left+wndPtr->rectWindow.right)/2;
1400 pt.y = wndPtr->rectWindow.bottom - SYSMETRICS_CYFRAME / 2;
1404 pt.x = wndPtr->rectWindow.left + SYSMETRICS_CXFRAME / 2;
1405 pt.y =(wndPtr->rectWindow.top+wndPtr->rectWindow.bottom)/2;
1409 pt.x = wndPtr->rectWindow.right - SYSMETRICS_CXFRAME / 2;
1410 pt.y =(wndPtr->rectWindow.top+wndPtr->rectWindow.bottom)/2;
1413 case VK_ESCAPE: return 0;
1419 SetCursorPos32( pt.x, pt.y );
1420 NC_HandleSetCursor( wndPtr->hwndSelf,
1421 wndPtr->hwndSelf, MAKELONG( hittest, WM_MOUSEMOVE ));
1426 /***********************************************************************
1429 * Perform SC_MOVE and SC_SIZE commands.
1431 static void NC_DoSizeMove( HWND32 hwnd, WORD wParam, POINT16 pt )
1434 RECT32 sizingRect, mouseRect;
1436 LONG hittest = (LONG)(wParam & 0x0f);
1437 HCURSOR16 hDragCursor = 0, hOldCursor = 0;
1438 POINT32 minTrack, maxTrack;
1439 POINT16 capturePoint = pt;
1440 WND * wndPtr = WIN_FindWndPtr( hwnd );
1441 BOOL32 thickframe = HAS_THICKFRAME( wndPtr->dwStyle );
1442 BOOL32 iconic = wndPtr->dwStyle & WS_MINIMIZE;
1443 BOOL32 moved = FALSE;
1445 if (IsZoomed32(hwnd) || !IsWindowVisible32(hwnd) ||
1446 (wndPtr->flags & WIN_MANAGED)) return;
1448 if ((wParam & 0xfff0) == SC_MOVE)
1450 if (!(wndPtr->dwStyle & WS_CAPTION)) return;
1452 hittest = NC_StartSizeMove( wndPtr, wParam, &capturePoint );
1453 if (!hittest) return;
1457 if (!thickframe) return;
1458 if ( hittest && hittest != HTSYSMENU ) hittest += 2;
1462 hittest = NC_StartSizeMove( wndPtr, wParam, &capturePoint );
1471 /* Get min/max info */
1473 WINPOS_GetMinMaxInfo( wndPtr, NULL, NULL, &minTrack, &maxTrack );
1474 sizingRect = wndPtr->rectWindow;
1475 if (wndPtr->dwStyle & WS_CHILD)
1476 GetClientRect32( wndPtr->parent->hwndSelf, &mouseRect );
1478 SetRect32(&mouseRect, 0, 0, SYSMETRICS_CXSCREEN, SYSMETRICS_CYSCREEN);
1479 if (ON_LEFT_BORDER(hittest))
1481 mouseRect.left = MAX( mouseRect.left, sizingRect.right-maxTrack.x );
1482 mouseRect.right = MIN( mouseRect.right, sizingRect.right-minTrack.x );
1484 else if (ON_RIGHT_BORDER(hittest))
1486 mouseRect.left = MAX( mouseRect.left, sizingRect.left+minTrack.x );
1487 mouseRect.right = MIN( mouseRect.right, sizingRect.left+maxTrack.x );
1489 if (ON_TOP_BORDER(hittest))
1491 mouseRect.top = MAX( mouseRect.top, sizingRect.bottom-maxTrack.y );
1492 mouseRect.bottom = MIN( mouseRect.bottom,sizingRect.bottom-minTrack.y);
1494 else if (ON_BOTTOM_BORDER(hittest))
1496 mouseRect.top = MAX( mouseRect.top, sizingRect.top+minTrack.y );
1497 mouseRect.bottom = MIN( mouseRect.bottom, sizingRect.top+maxTrack.y );
1499 SendMessage16( hwnd, WM_ENTERSIZEMOVE, 0, 0 );
1501 if (GetCapture32() != hwnd) SetCapture32( hwnd );
1503 if (wndPtr->dwStyle & WS_CHILD)
1505 /* Retrieve a default cache DC (without using the window style) */
1506 hdc = GetDCEx32( wndPtr->parent->hwndSelf, 0, DCX_CACHE );
1509 { /* Grab the server only when moving top-level windows without desktop */
1511 if (rootWindow == DefaultRootWindow(display)) TSXGrabServer( display );
1514 if( iconic ) /* create a cursor for dragging */
1516 HICON16 hIcon = (wndPtr->class->hIcon) ? wndPtr->class->hIcon
1517 : (HICON16)SendMessage16( hwnd, WM_QUERYDRAGICON, 0, 0L);
1518 if( hIcon ) hDragCursor = CURSORICON_IconToCursor( hIcon, TRUE );
1519 if( !hDragCursor ) iconic = FALSE;
1522 if( !iconic ) NC_DrawMovingFrame( hdc, &sizingRect, thickframe );
1528 MSG_InternalGetMessage( &msg, 0, 0, MSGF_SIZE, PM_REMOVE, FALSE );
1530 /* Exit on button-up, Return, or Esc */
1531 if ((msg.message == WM_LBUTTONUP) ||
1532 ((msg.message == WM_KEYDOWN) &&
1533 ((msg.wParam == VK_RETURN) || (msg.wParam == VK_ESCAPE)))) break;
1535 if ((msg.message != WM_KEYDOWN) && (msg.message != WM_MOUSEMOVE))
1536 continue; /* We are not interested in other messages */
1539 if (wndPtr->dwStyle & WS_CHILD)
1540 ScreenToClient16( wndPtr->parent->hwndSelf, &pt );
1542 if (msg.message == WM_KEYDOWN) switch(msg.wParam)
1544 case VK_UP: pt.y -= 8; break;
1545 case VK_DOWN: pt.y += 8; break;
1546 case VK_LEFT: pt.x -= 8; break;
1547 case VK_RIGHT: pt.x += 8; break;
1550 pt.x = MAX( pt.x, mouseRect.left );
1551 pt.x = MIN( pt.x, mouseRect.right );
1552 pt.y = MAX( pt.y, mouseRect.top );
1553 pt.y = MIN( pt.y, mouseRect.bottom );
1555 dx = pt.x - capturePoint.x;
1556 dy = pt.y - capturePoint.y;
1563 if( iconic ) /* ok, no system popup tracking */
1565 hOldCursor = SetCursor32(hDragCursor);
1566 ShowCursor32( TRUE );
1567 WINPOS_ShowIconTitle( wndPtr, FALSE );
1571 if (msg.message == WM_KEYDOWN) SetCursorPos32( pt.x, pt.y );
1574 RECT32 newRect = sizingRect;
1576 if (hittest == HTCAPTION) OffsetRect32( &newRect, dx, dy );
1577 if (ON_LEFT_BORDER(hittest)) newRect.left += dx;
1578 else if (ON_RIGHT_BORDER(hittest)) newRect.right += dx;
1579 if (ON_TOP_BORDER(hittest)) newRect.top += dy;
1580 else if (ON_BOTTOM_BORDER(hittest)) newRect.bottom += dy;
1583 NC_DrawMovingFrame( hdc, &sizingRect, thickframe );
1584 NC_DrawMovingFrame( hdc, &newRect, thickframe );
1587 sizingRect = newRect;
1595 if( moved ) /* restore cursors, show icon title later on */
1597 ShowCursor32( FALSE );
1598 SetCursor32( hOldCursor );
1600 DestroyCursor32( hDragCursor );
1603 NC_DrawMovingFrame( hdc, &sizingRect, thickframe );
1605 if (wndPtr->dwStyle & WS_CHILD)
1606 ReleaseDC32( wndPtr->parent->hwndSelf, hdc );
1609 ReleaseDC32( 0, hdc );
1610 if (rootWindow == DefaultRootWindow(display)) TSXUngrabServer( display );
1613 if (HOOK_IsHooked( WH_CBT ))
1615 RECT16* pr = SEGPTR_NEW(RECT16);
1618 CONV_RECT32TO16( &sizingRect, pr );
1619 if( HOOK_CallHooks16( WH_CBT, HCBT_MOVESIZE, hwnd,
1620 (LPARAM)SEGPTR_GET(pr)) )
1621 sizingRect = wndPtr->rectWindow;
1623 CONV_RECT16TO32( pr, &sizingRect );
1627 SendMessage16( hwnd, WM_EXITSIZEMOVE, 0, 0 );
1628 SendMessage16( hwnd, WM_SETVISIBLE, !IsIconic16(hwnd), 0L);
1630 if( moved && !((msg.message == WM_KEYDOWN) && (msg.wParam == VK_ESCAPE)) )
1632 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
1633 SetWindowPos32( hwnd, 0, sizingRect.left, sizingRect.top,
1634 sizingRect.right - sizingRect.left,
1635 sizingRect.bottom - sizingRect.top,
1636 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
1639 if( IsWindow32(hwnd) )
1640 if( wndPtr->dwStyle & WS_MINIMIZE )
1642 /* Single click brings up the system menu when iconized */
1646 if( wndPtr->dwStyle & WS_SYSMENU )
1647 SendMessage16( hwnd, WM_SYSCOMMAND,
1648 SC_MOUSEMENU + HTSYSMENU, *((LPARAM*)&pt));
1650 else WINPOS_ShowIconTitle( wndPtr, TRUE );
1655 /***********************************************************************
1658 * Track a mouse button press on the minimize or maximize box.
1660 static void NC_TrackMinMaxBox( HWND32 hwnd, WORD wParam )
1663 HDC32 hdc = GetWindowDC32( hwnd );
1664 BOOL32 pressed = TRUE;
1665 void (*paintButton)(HWND32, HDC16, BOOL32);
1667 SetCapture32( hwnd );
1668 if (wParam == HTMINBUTTON)
1669 paintButton = (TWEAK_Win95Look) ? &NC_DrawMinButton95 : &NC_DrawMinButton;
1671 paintButton = (TWEAK_Win95Look) ? &NC_DrawMaxButton95 : &NC_DrawMaxButton;
1673 (*paintButton)( hwnd, hdc, TRUE );
1677 BOOL32 oldstate = pressed;
1678 MSG_InternalGetMessage( &msg, 0, 0, 0, PM_REMOVE, FALSE );
1680 pressed = (NC_HandleNCHitTest( hwnd, msg.pt ) == wParam);
1681 if (pressed != oldstate)
1682 (*paintButton)( hwnd, hdc, pressed );
1683 } while (msg.message != WM_LBUTTONUP);
1685 (*paintButton)( hwnd, hdc, FALSE );
1688 ReleaseDC32( hwnd, hdc );
1689 if (!pressed) return;
1691 if (wParam == HTMINBUTTON)
1692 SendMessage16( hwnd, WM_SYSCOMMAND, SC_MINIMIZE, *(LONG*)&msg.pt );
1694 SendMessage16( hwnd, WM_SYSCOMMAND,
1695 IsZoomed32(hwnd) ? SC_RESTORE:SC_MAXIMIZE, *(LONG*)&msg.pt );
1699 /***********************************************************************
1702 * Track a mouse button press on the horizontal or vertical scroll-bar.
1704 static void NC_TrackScrollBar( HWND32 hwnd, WPARAM32 wParam, POINT32 pt )
1708 WND *wndPtr = WIN_FindWndPtr( hwnd );
1710 if ((wParam & 0xfff0) == SC_HSCROLL)
1712 if ((wParam & 0x0f) != HTHSCROLL) return;
1713 scrollbar = SB_HORZ;
1715 else /* SC_VSCROLL */
1717 if ((wParam & 0x0f) != HTVSCROLL) return;
1718 scrollbar = SB_VERT;
1721 if (!(msg = SEGPTR_NEW(MSG16))) return;
1722 pt.x -= wndPtr->rectWindow.left;
1723 pt.y -= wndPtr->rectWindow.top;
1724 SetCapture32( hwnd );
1725 SCROLL_HandleScrollEvent( hwnd, scrollbar, WM_LBUTTONDOWN, pt );
1729 GetMessage16( SEGPTR_GET(msg), 0, 0, 0 );
1730 switch(msg->message)
1735 pt.x = LOWORD(msg->lParam) + wndPtr->rectClient.left -
1736 wndPtr->rectWindow.left;
1737 pt.y = HIWORD(msg->lParam) + wndPtr->rectClient.top -
1738 wndPtr->rectWindow.top;
1739 SCROLL_HandleScrollEvent( hwnd, scrollbar, msg->message, pt );
1742 TranslateMessage16( msg );
1743 DispatchMessage16( msg );
1746 if (!IsWindow32( hwnd ))
1751 } while (msg->message != WM_LBUTTONUP);
1755 /***********************************************************************
1756 * NC_HandleNCLButtonDown
1758 * Handle a WM_NCLBUTTONDOWN message. Called from DefWindowProc().
1760 LONG NC_HandleNCLButtonDown( WND* pWnd, WPARAM16 wParam, LPARAM lParam )
1762 HWND32 hwnd = pWnd->hwndSelf;
1764 switch(wParam) /* Hit test */
1767 hwnd = WIN_GetTopParent(hwnd);
1769 if( WINPOS_SetActiveWindow(hwnd, TRUE, TRUE) || (GetActiveWindow32() == hwnd) )
1770 SendMessage16( pWnd->hwndSelf, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, lParam );
1774 if( pWnd->dwStyle & WS_SYSMENU )
1776 if( !(pWnd->dwStyle & WS_MINIMIZE) )
1778 HDC32 hDC = GetWindowDC32(hwnd);
1779 if( TWEAK_Win95Look)
1780 NC_DrawSysButton95( hwnd, hDC, TRUE );
1782 NC_DrawSysButton( hwnd, hDC, TRUE );
1783 ReleaseDC32( hwnd, hDC );
1785 SendMessage16( hwnd, WM_SYSCOMMAND, SC_MOUSEMENU + HTSYSMENU, lParam );
1790 SendMessage16( hwnd, WM_SYSCOMMAND, SC_MOUSEMENU, lParam );
1794 SendMessage16( hwnd, WM_SYSCOMMAND, SC_HSCROLL + HTHSCROLL, lParam );
1798 SendMessage16( hwnd, WM_SYSCOMMAND, SC_VSCROLL + HTVSCROLL, lParam );
1803 NC_TrackMinMaxBox( hwnd, wParam );
1814 /* make sure hittest fits into 0xf and doesn't overlap with HTSYSMENU */
1815 SendMessage16( hwnd, WM_SYSCOMMAND, SC_SIZE + wParam - 2, lParam);
1825 /***********************************************************************
1826 * NC_HandleNCLButtonDblClk
1828 * Handle a WM_NCLBUTTONDBLCLK message. Called from DefWindowProc().
1830 LONG NC_HandleNCLButtonDblClk( WND *pWnd, WPARAM16 wParam, LPARAM lParam )
1833 * if this is an icon, send a restore since we are handling
1836 if (pWnd->dwStyle & WS_MINIMIZE)
1838 SendMessage16( pWnd->hwndSelf, WM_SYSCOMMAND, SC_RESTORE, lParam );
1842 switch(wParam) /* Hit test */
1845 /* stop processing if WS_MAXIMIZEBOX is missing */
1846 if (pWnd->dwStyle & WS_MAXIMIZEBOX)
1847 SendMessage16( pWnd->hwndSelf, WM_SYSCOMMAND,
1848 (pWnd->dwStyle & WS_MAXIMIZE) ? SC_RESTORE : SC_MAXIMIZE,
1853 if (!(pWnd->class->style & CS_NOCLOSE))
1854 SendMessage16( pWnd->hwndSelf, WM_SYSCOMMAND, SC_CLOSE, lParam );
1858 SendMessage16( pWnd->hwndSelf, WM_SYSCOMMAND, SC_HSCROLL + HTHSCROLL,
1863 SendMessage16( pWnd->hwndSelf, WM_SYSCOMMAND, SC_VSCROLL + HTVSCROLL,
1871 /***********************************************************************
1872 * NC_HandleSysCommand
1874 * Handle a WM_SYSCOMMAND message. Called from DefWindowProc().
1876 LONG NC_HandleSysCommand( HWND32 hwnd, WPARAM16 wParam, POINT16 pt )
1878 WND *wndPtr = WIN_FindWndPtr( hwnd );
1880 UINT16 uCommand = wParam & 0xFFF0;
1882 TRACE(nonclient, "Handling WM_SYSCOMMAND %x %d,%d\n",
1883 wParam, pt.x, pt.y );
1885 if (wndPtr->dwStyle & WS_CHILD && uCommand != SC_KEYMENU )
1886 ScreenToClient16( wndPtr->parent->hwndSelf, &pt );
1892 NC_DoSizeMove( hwnd, wParam, pt );
1896 ShowWindow32( hwnd, SW_MINIMIZE );
1900 ShowWindow32( hwnd, SW_MAXIMIZE );
1904 ShowWindow32( hwnd, SW_RESTORE );
1908 return SendMessage16( hwnd, WM_CLOSE, 0, 0 );
1912 CONV_POINT16TO32( &pt, &pt32 );
1913 NC_TrackScrollBar( hwnd, wParam, pt32 );
1917 CONV_POINT16TO32( &pt, &pt32 );
1918 MENU_TrackMouseMenuBar( wndPtr, wParam & 0x000F, pt32 );
1922 MENU_TrackKbdMenuBar( wndPtr , wParam , pt.x );
1926 WinExec32( "taskman.exe", SW_SHOWNORMAL );
1930 if (wParam == SC_ABOUTWINE)
1931 ShellAbout32A(hwnd,"Wine", WINE_RELEASE_INFO, 0);
1938 /* FIXME: unimplemented */