2 * Non-client area window functions
4 * Copyright 1994 Alexandre Julliard
7 static char Copyright
[] = "Copyright Alexandre Julliard, 1994";
12 #include "sysmetrics.h"
17 static HBITMAP hbitmapClose
= 0;
18 static HBITMAP hbitmapMinimize
= 0;
19 static HBITMAP hbitmapMinimizeD
= 0;
20 static HBITMAP hbitmapMaximize
= 0;
21 static HBITMAP hbitmapMaximizeD
= 0;
22 static HBITMAP hbitmapRestore
= 0;
23 static HBITMAP hbitmapRestoreD
= 0;
25 extern void WINPOS_GetMinMaxInfo( HWND hwnd
, POINT
*maxSize
, POINT
*maxPos
,
26 POINT
*minTrack
, POINT
*maxTrack
); /* winpos.c */
27 extern void CURSOR_SetWinCursor( HWND hwnd
, HCURSOR hcursor
); /* cursor.c */
30 /* Some useful macros */
31 #define HAS_DLGFRAME(style,exStyle) \
32 (((style) & WS_DLGFRAME) && \
33 (((exStyle) & WS_EX_DLGMODALFRAME) || !((style) & WS_BORDER)))
35 #define HAS_THICKFRAME(style) \
36 (((style) & WS_THICKFRAME) && \
37 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
39 #define HAS_MENU(w) (!((w)->dwStyle & WS_CHILD) && ((w)->wIDmenu != 0))
41 #define ON_LEFT_BORDER(hit) \
42 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
43 #define ON_RIGHT_BORDER(hit) \
44 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
45 #define ON_TOP_BORDER(hit) \
46 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
47 #define ON_BOTTOM_BORDER(hit) \
48 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
50 /***********************************************************************
53 * Compute the size of the window rectangle from the size of the
56 static void NC_AdjustRect( LPRECT rect
, DWORD style
, BOOL menu
, DWORD exStyle
)
58 if (HAS_DLGFRAME( style
, exStyle
))
59 InflateRect( rect
, SYSMETRICS_CXDLGFRAME
, SYSMETRICS_CYDLGFRAME
);
62 if (HAS_THICKFRAME(style
))
63 InflateRect( rect
, SYSMETRICS_CXFRAME
, SYSMETRICS_CYFRAME
);
64 if (style
& WS_BORDER
)
65 InflateRect( rect
, SYSMETRICS_CXBORDER
, SYSMETRICS_CYBORDER
);
68 if ((style
& WS_CAPTION
) == WS_CAPTION
)
69 rect
->top
-= SYSMETRICS_CYCAPTION
- 1;
71 if (menu
) rect
->top
-= SYSMETRICS_CYMENU
+ 1;
73 if (style
& WS_VSCROLL
) rect
->right
+= SYSMETRICS_CXVSCROLL
;
74 if (style
& WS_HSCROLL
) rect
->bottom
+= SYSMETRICS_CYHSCROLL
;
78 /***********************************************************************
79 * AdjustWindowRect (USER.102)
81 void AdjustWindowRect( LPRECT rect
, DWORD style
, BOOL menu
)
83 AdjustWindowRectEx( rect
, style
, menu
, 0 );
87 /***********************************************************************
88 * AdjustWindowRectEx (USER.454)
90 void AdjustWindowRectEx( LPRECT rect
, DWORD style
, BOOL menu
, DWORD exStyle
)
92 /* Correct the window style */
94 if (!(style
& (WS_POPUP
| WS_CHILD
))) /* Overlapped window */
96 if (exStyle
& WS_EX_DLGMODALFRAME
) style
&= ~WS_THICKFRAME
;
98 #ifdef DEBUG_NONCLIENT
99 printf( "AdjustWindowRectEx: (%d,%d)-(%d,%d) %08x %d %08x\n",
100 rect
->left
, rect
->top
, rect
->right
, rect
->bottom
, style
, menu
, exStyle
);
103 NC_AdjustRect( rect
, style
, menu
, exStyle
);
107 /***********************************************************************
108 * NC_HandleNCCalcSize
110 * Handle a WM_NCCALCSIZE message. Called from DefWindowProc().
112 LONG
NC_HandleNCCalcSize( HWND hwnd
, NCCALCSIZE_PARAMS
*params
)
114 RECT tmpRect
= { 0, 0, 0, 0 };
115 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
117 if (!wndPtr
) return 0;
119 NC_AdjustRect( &tmpRect
, wndPtr
->dwStyle
,
120 HAS_MENU(wndPtr
), wndPtr
->dwExStyle
);
122 params
->rgrc
[0].left
-= tmpRect
.left
;
123 params
->rgrc
[0].top
-= tmpRect
.top
;
124 params
->rgrc
[0].right
-= tmpRect
.right
;
125 params
->rgrc
[0].bottom
-= tmpRect
.bottom
;
130 /***********************************************************************
133 * Get the 'inside' rectangle of a window, i.e. the whole window rectangle
134 * but without the borders (if any).
135 * The rectangle is in window coordinates (for drawing with GetWindowDC()).
137 static void NC_GetInsideRect( HWND hwnd
, RECT
*rect
)
139 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
141 rect
->top
= rect
->left
= 0;
142 rect
->right
= wndPtr
->rectWindow
.right
- wndPtr
->rectWindow
.left
;
143 rect
->bottom
= wndPtr
->rectWindow
.bottom
- wndPtr
->rectWindow
.top
;
145 /* Remove frame from rectangle */
146 if (HAS_DLGFRAME( wndPtr
->dwStyle
, wndPtr
->dwExStyle
))
148 InflateRect( rect
, -SYSMETRICS_CXDLGFRAME
, -SYSMETRICS_CYDLGFRAME
);
149 if (wndPtr
->dwExStyle
& WS_EX_DLGMODALFRAME
) InflateRect( rect
, -1, 0);
153 if (HAS_THICKFRAME( wndPtr
->dwStyle
))
154 InflateRect( rect
, -SYSMETRICS_CXFRAME
, -SYSMETRICS_CYFRAME
);
155 if (wndPtr
->dwStyle
& WS_BORDER
)
156 InflateRect( rect
, -SYSMETRICS_CXBORDER
, -SYSMETRICS_CYBORDER
);
161 /***********************************************************************
162 * NC_InternalNCHitTest
164 * Perform the hit test calculation, but whithout testing the capture
167 static LONG
NC_InternalNCHitTest( HWND hwnd
, POINT pt
)
170 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
171 if (!wndPtr
) return HTERROR
;
173 GetWindowRect( hwnd
, &rect
);
174 if (!PtInRect( &rect
, pt
)) return HTNOWHERE
;
175 ScreenToClient( hwnd
, &pt
);
176 GetClientRect( hwnd
, &rect
);
178 if (PtInRect( &rect
, pt
)) return HTCLIENT
;
180 /* Check vertical scroll bar */
181 if (wndPtr
->dwStyle
& WS_VSCROLL
)
183 rect
.right
+= SYSMETRICS_CXVSCROLL
;
184 if (PtInRect( &rect
, pt
)) return HTVSCROLL
;
187 /* Check horizontal scroll bar */
188 if (wndPtr
->dwStyle
& WS_HSCROLL
)
190 rect
.bottom
+= SYSMETRICS_CYHSCROLL
;
191 if (PtInRect( &rect
, pt
))
194 if ((wndPtr
->dwStyle
& WS_VSCROLL
) &&
195 (pt
.x
>= rect
.right
- SYSMETRICS_CXVSCROLL
)) return HTSIZE
;
201 if (HAS_MENU(wndPtr
))
203 rect
.top
-= SYSMETRICS_CYMENU
+ 1;
204 if (PtInRect( &rect
, pt
)) return HTMENU
;
208 if ((wndPtr
->dwStyle
& WS_CAPTION
) == WS_CAPTION
)
210 rect
.top
-= SYSMETRICS_CYCAPTION
- 1;
211 if (PtInRect( &rect
, pt
))
213 /* Check system menu */
214 if ((wndPtr
->dwStyle
& WS_SYSMENU
) && (pt
.x
<= SYSMETRICS_CXSIZE
))
216 /* Check maximize box */
217 if (wndPtr
->dwStyle
& WS_MAXIMIZEBOX
)
218 rect
.right
-= SYSMETRICS_CXSIZE
+ 1;
219 if (pt
.x
>= rect
.right
) return HTMAXBUTTON
;
220 /* Check minimize box */
221 if (wndPtr
->dwStyle
& WS_MINIMIZEBOX
)
222 rect
.right
-= SYSMETRICS_CXSIZE
+ 1;
223 if (pt
.x
>= rect
.right
) return HTMINBUTTON
;
228 /* Check non-sizing border */
229 if (!HAS_THICKFRAME( wndPtr
->dwStyle
)) return HTBORDER
;
231 /* Check top sizing border */
234 if (pt
.x
< rect
.left
+SYSMETRICS_CXSIZE
) return HTTOPLEFT
;
235 if (pt
.x
>= rect
.right
-SYSMETRICS_CXSIZE
) return HTTOPRIGHT
;
239 /* Check bottom sizing border */
240 if (pt
.y
>= rect
.bottom
)
242 if (pt
.x
< rect
.left
+SYSMETRICS_CXSIZE
) return HTBOTTOMLEFT
;
243 if (pt
.x
>= rect
.right
-SYSMETRICS_CXSIZE
) return HTBOTTOMRIGHT
;
247 /* Check left sizing border */
248 if (pt
.x
< rect
.left
)
250 if (pt
.y
< rect
.top
+SYSMETRICS_CYSIZE
) return HTTOPLEFT
;
251 if (pt
.y
>= rect
.bottom
-SYSMETRICS_CYSIZE
) return HTBOTTOMLEFT
;
255 /* Check right sizing border */
256 if (pt
.x
>= rect
.right
)
258 if (pt
.y
< rect
.top
+SYSMETRICS_CYSIZE
) return HTTOPRIGHT
;
259 if (pt
.y
>= rect
.bottom
-SYSMETRICS_CYSIZE
) return HTBOTTOMRIGHT
;
263 /* Should never get here */
268 /***********************************************************************
271 * Handle a WM_NCHITTEST message. Called from DefWindowProc().
273 LONG
NC_HandleNCHitTest( HWND hwnd
, POINT pt
)
275 #ifdef DEBUG_NONCLIENT
276 printf( "NC_HandleNCHitTest: hwnd=%x pt=%d,%d\n", hwnd
, pt
.x
, pt
.y
);
278 if (hwnd
== GetCapture()) return HTCLIENT
;
279 return NC_InternalNCHitTest( hwnd
, pt
);
283 /***********************************************************************
286 static void NC_DrawSysButton( HWND hwnd
, HDC hdc
, BOOL down
)
289 HDC hdcMem
= CreateCompatibleDC( hdc
);
292 NC_GetInsideRect( hwnd
, &rect
);
293 SelectObject( hdcMem
, hbitmapClose
);
294 BitBlt( hdc
, rect
.left
, rect
.top
, SYSMETRICS_CXSIZE
,
295 SYSMETRICS_CYSIZE
, hdcMem
, 1, 1, down
? NOTSRCCOPY
: SRCCOPY
);
301 /***********************************************************************
304 static void NC_DrawMaxButton( HWND hwnd
, HDC hdc
, BOOL down
)
307 HDC hdcMem
= CreateCompatibleDC( hdc
);
310 NC_GetInsideRect( hwnd
, &rect
);
312 SelectObject( hdcMem
, down
? hbitmapRestoreD
: hbitmapRestore
);
313 else SelectObject( hdcMem
, down
? hbitmapMaximizeD
: hbitmapMaximize
);
314 BitBlt( hdc
, rect
.right
- SYSMETRICS_CXSIZE
- 1, rect
.top
- 1,
315 SYSMETRICS_CXSIZE
+2, SYSMETRICS_CYSIZE
+2, hdcMem
, 0, 0, SRCCOPY
);
321 /***********************************************************************
324 static void NC_DrawMinButton( HWND hwnd
, HDC hdc
, BOOL down
)
327 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
328 HDC hdcMem
= CreateCompatibleDC( hdc
);
331 NC_GetInsideRect( hwnd
, &rect
);
332 if (wndPtr
->dwStyle
& WS_MAXIMIZEBOX
)
333 rect
.right
-= SYSMETRICS_CXSIZE
+ 1;
334 if (down
) SelectObject( hdcMem
, hbitmapMinimizeD
);
335 else SelectObject( hdcMem
, hbitmapMinimize
);
336 BitBlt( hdc
, rect
.right
- SYSMETRICS_CXSIZE
- 1, rect
.top
- 1,
337 SYSMETRICS_CXSIZE
+2, SYSMETRICS_CYSIZE
+2, hdcMem
, 0, 0, SRCCOPY
);
343 /***********************************************************************
346 * Draw a window frame inside the given rectangle, and update the rectangle.
347 * The correct pen and brush must be selected in the DC.
349 static void NC_DrawFrame( HDC hdc
, RECT
*rect
, BOOL dlgFrame
)
351 short width
, height
, tmp
;
355 width
= SYSMETRICS_CXDLGFRAME
- 1;
356 height
= SYSMETRICS_CYDLGFRAME
- 1;
360 width
= SYSMETRICS_CXFRAME
- 1;
361 height
= SYSMETRICS_CYFRAME
- 1;
365 PatBlt( hdc
, rect
->left
, rect
->top
,
366 rect
->right
- rect
->left
, height
, PATCOPY
);
367 PatBlt( hdc
, rect
->left
, rect
->top
,
368 width
, rect
->bottom
- rect
->top
, PATCOPY
);
369 PatBlt( hdc
, rect
->left
, rect
->bottom
,
370 rect
->right
- rect
->left
, -height
, PATCOPY
);
371 PatBlt( hdc
, rect
->right
, rect
->top
,
372 -width
, rect
->bottom
- rect
->top
, PATCOPY
);
376 InflateRect( rect
, -width
, -height
);
380 /* Draw inner rectangle */
381 MoveTo( hdc
, rect
->left
+width
, rect
->top
+height
);
382 LineTo( hdc
, rect
->right
-width
-1, rect
->top
+height
);
383 LineTo( hdc
, rect
->right
-width
-1, rect
->bottom
-height
-1 );
384 LineTo( hdc
, rect
->left
+width
, rect
->bottom
-height
-1 );
385 LineTo( hdc
, rect
->left
+width
, rect
->top
+height
);
387 /* Draw the decorations */
388 tmp
= rect
->top
+ SYSMETRICS_CYFRAME
+ SYSMETRICS_CYSIZE
;
389 MoveTo( hdc
, rect
->left
, tmp
);
390 LineTo( hdc
, rect
->left
+width
, tmp
);
391 MoveTo( hdc
, rect
->right
-width
-1, tmp
);
392 LineTo( hdc
, rect
->right
-1, tmp
);
394 tmp
= rect
->bottom
- 1 - SYSMETRICS_CYFRAME
- SYSMETRICS_CYSIZE
;
395 MoveTo( hdc
, rect
->left
, tmp
);
396 LineTo( hdc
, rect
->left
+width
, tmp
);
397 MoveTo( hdc
, rect
->right
-width
-1, tmp
);
398 LineTo( hdc
, rect
->right
-1, tmp
);
400 tmp
= rect
->left
+ SYSMETRICS_CXFRAME
+ SYSMETRICS_CXSIZE
;
401 MoveTo( hdc
, tmp
, rect
->top
);
402 LineTo( hdc
, tmp
, rect
->top
+height
);
403 MoveTo( hdc
, tmp
, rect
->bottom
-height
-1 );
404 LineTo( hdc
, tmp
, rect
->bottom
-1 );
406 tmp
= rect
->right
- 1 - SYSMETRICS_CXFRAME
- SYSMETRICS_CYSIZE
;
407 MoveTo( hdc
, tmp
, rect
->top
);
408 LineTo( hdc
, tmp
, rect
->top
+height
);
409 MoveTo( hdc
, tmp
, rect
->bottom
-height
-1 );
410 LineTo( hdc
, tmp
, rect
->bottom
-1 );
412 InflateRect( rect
, -width
-1, -height
-1 );
416 /***********************************************************************
419 * Draw the frame used when moving or resizing window.
421 static void NC_DrawMovingFrame( HDC hdc
, RECT
*rect
, BOOL thickframe
)
425 SelectObject( hdc
, GetStockObject( GRAY_BRUSH
) );
426 PatBlt( hdc
, rect
->left
, rect
->top
,
427 rect
->right
- rect
->left
- SYSMETRICS_CXFRAME
,
428 SYSMETRICS_CYFRAME
, PATINVERT
);
429 PatBlt( hdc
, rect
->left
, rect
->top
+ SYSMETRICS_CYFRAME
,
431 rect
->bottom
- rect
->top
- SYSMETRICS_CYFRAME
, PATINVERT
);
432 PatBlt( hdc
, rect
->left
+ SYSMETRICS_CXFRAME
, rect
->bottom
,
433 rect
->right
- rect
->left
- SYSMETRICS_CXFRAME
,
434 -SYSMETRICS_CYFRAME
, PATINVERT
);
435 PatBlt( hdc
, rect
->right
, rect
->top
, -SYSMETRICS_CXFRAME
,
436 rect
->bottom
- rect
->top
- SYSMETRICS_CYFRAME
, PATINVERT
);
438 else DrawFocusRect( hdc
, rect
);
442 /***********************************************************************
445 * Draw the window caption.
446 * The correct pen for the window frame must be selected in the DC.
448 static void NC_DrawCaption( HDC hdc
, RECT
*rect
, HWND hwnd
,
449 DWORD style
, BOOL active
)
452 HBRUSH hbrushCaption
;
453 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
458 if (!(hbitmapClose
= LoadBitmap( 0, MAKEINTRESOURCE(OBM_CLOSE
) )))
460 hbitmapMinimize
= LoadBitmap( 0, MAKEINTRESOURCE(OBM_REDUCE
) );
461 hbitmapMinimizeD
= LoadBitmap( 0, MAKEINTRESOURCE(OBM_REDUCED
) );
462 hbitmapMaximize
= LoadBitmap( 0, MAKEINTRESOURCE(OBM_ZOOM
) );
463 hbitmapMaximizeD
= LoadBitmap( 0, MAKEINTRESOURCE(OBM_ZOOMD
) );
464 hbitmapRestore
= LoadBitmap( 0, MAKEINTRESOURCE(OBM_RESTORE
) );
465 hbitmapRestoreD
= LoadBitmap( 0, MAKEINTRESOURCE(OBM_RESTORED
) );
468 if (wndPtr
->dwExStyle
& WS_EX_DLGMODALFRAME
)
470 HBRUSH hbrushWindow
= CreateSolidBrush(GetSysColor(COLOR_WINDOW
));
471 HBRUSH hbrushOld
= SelectObject( hdc
, hbrushWindow
);
472 PatBlt( hdc
, r
.left
, r
.top
, 1, r
.bottom
-r
.top
+1,PATCOPY
);
473 PatBlt( hdc
, r
.right
-1, r
.top
, 1, r
.bottom
-r
.top
+1, PATCOPY
);
474 PatBlt( hdc
, r
.left
, r
.top
-1, r
.right
-r
.left
, 1, PATCOPY
);
477 SelectObject( hdc
, hbrushOld
);
478 DeleteObject( hbrushWindow
);
482 hbrushCaption
= CreateSolidBrush( GetSysColor(COLOR_ACTIVECAPTION
) );
483 else hbrushCaption
= CreateSolidBrush( GetSysColor(COLOR_INACTIVECAPTION
));
485 MoveTo( hdc
, r
.left
, r
.bottom
);
486 LineTo( hdc
, r
.right
-1, r
.bottom
);
488 if (style
& WS_SYSMENU
)
490 NC_DrawSysButton( hwnd
, hdc
, FALSE
);
491 r
.left
+= SYSMETRICS_CXSIZE
+ 1;
492 MoveTo( hdc
, r
.left
- 1, r
.top
);
493 LineTo( hdc
, r
.left
- 1, r
.bottom
);
495 if (style
& WS_MAXIMIZEBOX
)
497 NC_DrawMaxButton( hwnd
, hdc
, FALSE
);
498 r
.right
-= SYSMETRICS_CXSIZE
+ 1;
500 if (style
& WS_MINIMIZEBOX
)
502 NC_DrawMinButton( hwnd
, hdc
, FALSE
);
503 r
.right
-= SYSMETRICS_CXSIZE
+ 1;
506 FillRect( hdc
, &r
, hbrushCaption
);
507 DeleteObject( hbrushCaption
);
509 if (GetWindowText( hwnd
, buffer
, 256 ))
511 if (active
) SetTextColor( hdc
, GetSysColor( COLOR_CAPTIONTEXT
) );
512 else SetTextColor( hdc
, GetSysColor( COLOR_INACTIVECAPTIONTEXT
) );
513 SetBkMode( hdc
, TRANSPARENT
);
514 DrawText( hdc
, buffer
, -1, &r
, DT_SINGLELINE
| DT_CENTER
| DT_VCENTER
);
519 /***********************************************************************
522 * Paint the non-client area.
523 * 'hrgn' is the update rgn to use (in client coords) or 1 if no update rgn.
525 void NC_DoNCPaint( HWND hwnd
, HRGN hrgn
, BOOL active
)
529 HBRUSH hbrushBorder
= 0;
532 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
534 #ifdef DEBUG_NONCLIENT
535 printf( "NC_HandleNCPaint: %d %d\n", hwnd
, hrgn
);
538 if (!wndPtr
|| !hrgn
) return;
539 if (!(wndPtr
->dwStyle
& (WS_BORDER
| WS_DLGFRAME
| WS_THICKFRAME
)))
540 return; /* Nothing to do! */
542 if (hrgn
== 1) hdc
= GetDCEx( hwnd
, 0, DCX_CACHE
| DCX_WINDOW
);
545 /* Make region relative to window area */
546 int xoffset
= wndPtr
->rectWindow
.left
- wndPtr
->rectClient
.left
;
547 int yoffset
= wndPtr
->rectWindow
.top
- wndPtr
->rectClient
.top
;
548 OffsetRgn( hrgn
, -xoffset
, -yoffset
);
549 hdc
= GetDCEx( hwnd
, hrgn
, DCX_CACHE
| DCX_WINDOW
| DCX_INTERSECTRGN
);
550 OffsetRgn( hrgn
, xoffset
, yoffset
); /* Restore region */
553 if (ExcludeVisRect( hdc
, wndPtr
->rectClient
.left
-wndPtr
->rectWindow
.left
,
554 wndPtr
->rectClient
.top
-wndPtr
->rectWindow
.top
,
555 wndPtr
->rectClient
.right
-wndPtr
->rectWindow
.left
,
556 wndPtr
->rectClient
.bottom
-wndPtr
->rectWindow
.top
)
559 ReleaseDC( hwnd
, hdc
);
563 rect
.top
= rect
.left
= 0;
564 rect
.right
= wndPtr
->rectWindow
.right
- wndPtr
->rectWindow
.left
;
565 rect
.bottom
= wndPtr
->rectWindow
.bottom
- wndPtr
->rectWindow
.top
;
567 hpenFrame
= CreatePen( PS_SOLID
, 1, GetSysColor(COLOR_WINDOWFRAME
) );
568 SelectObject( hdc
, hpenFrame
);
570 hbrushBorder
= CreateSolidBrush( GetSysColor(COLOR_ACTIVEBORDER
) );
571 else hbrushBorder
= CreateSolidBrush( GetSysColor(COLOR_INACTIVEBORDER
) );
572 SelectObject( hdc
, hbrushBorder
);
574 if ((wndPtr
->dwStyle
& WS_BORDER
) || (wndPtr
->dwStyle
& WS_DLGFRAME
))
577 LineTo( hdc
, rect
.right
-1, 0 );
578 LineTo( hdc
, rect
.right
-1, rect
.bottom
-1 );
579 LineTo( hdc
, 0, rect
.bottom
-1 );
581 InflateRect( &rect
, -1, -1 );
584 if (HAS_DLGFRAME( wndPtr
->dwStyle
, wndPtr
->dwExStyle
))
585 NC_DrawFrame( hdc
, &rect
, TRUE
);
586 else if (wndPtr
->dwStyle
& WS_THICKFRAME
)
587 NC_DrawFrame(hdc
, &rect
, FALSE
);
589 if ((wndPtr
->dwStyle
& WS_CAPTION
) == WS_CAPTION
)
592 rect
.top
+= SYSMETRICS_CYSIZE
+ 1;
593 r
.bottom
= rect
.top
- 1;
594 NC_DrawCaption( hdc
, &r
, hwnd
, wndPtr
->dwStyle
, active
);
597 if (wndPtr
->wIDmenu
!= 0 &&
598 (wndPtr
->dwStyle
& WS_CHILD
) != WS_CHILD
) {
600 CopyRect(&rect2
, &rect
);
601 /* Default MenuBar height */
602 oldbottom
= rect2
.bottom
= rect2
.top
+ SYSMETRICS_CYMENU
;
603 StdDrawMenuBar(hdc
, &rect2
, (LPPOPUPMENU
)GlobalLock(wndPtr
->wIDmenu
));
604 GlobalUnlock(wndPtr
->wIDmenu
);
605 /* Reduce ClientRect according to MenuBar height */
606 rect
.top
+= rect2
.bottom
- oldbottom
;
609 if (wndPtr
->dwStyle
& (WS_VSCROLL
| WS_HSCROLL
)) {
610 if (wndPtr
->dwStyle
& WS_VSCROLL
) {
611 int bottom
= rect
.bottom
;
612 if (wndPtr
->dwStyle
& WS_HSCROLL
) bottom
-= SYSMETRICS_CYHSCROLL
;
613 SetRect(&rect2
, rect
.right
- SYSMETRICS_CXVSCROLL
,
614 rect
.top
, rect
.right
, bottom
);
615 if (wndPtr
->dwStyle
& WS_CAPTION
) rect
.top
+= SYSMETRICS_CYSIZE
;
616 if (wndPtr
->wIDmenu
!= 0 && (wndPtr
->dwStyle
& WS_CHILD
) != WS_CHILD
)
617 rect2
.top
+= SYSMETRICS_CYMENU
;
618 StdDrawScrollBar(hwnd
, hdc
, SB_VERT
, &rect2
, (LPHEADSCROLL
)wndPtr
->VScroll
);
620 if (wndPtr
->dwStyle
& WS_HSCROLL
) {
621 int right
= rect
.right
;
622 if (wndPtr
->dwStyle
& WS_VSCROLL
) right
-= SYSMETRICS_CYVSCROLL
;
623 SetRect(&rect2
, rect
.left
, rect
.bottom
- SYSMETRICS_CYHSCROLL
,
625 StdDrawScrollBar(hwnd
, hdc
, SB_HORZ
, &rect2
, (LPHEADSCROLL
)wndPtr
->HScroll
);
628 if ((wndPtr
->dwStyle
& WS_VSCROLL
) && (wndPtr
->dwStyle
& WS_HSCROLL
))
630 HBRUSH hbrushScroll
= CreateSolidBrush( GetSysColor(COLOR_SCROLLBAR
) );
632 r
.left
= r
.right
- SYSMETRICS_CXVSCROLL
;
633 r
.top
= r
.bottom
- SYSMETRICS_CYHSCROLL
;
634 FillRect( hdc
, &r
, hbrushScroll
);
638 ReleaseDC( hwnd
, hdc
);
639 if (hbrushBorder
) DeleteObject( hbrushBorder
);
640 if (hpenFrame
) DeleteObject( hpenFrame
);
644 /***********************************************************************
647 * Handle a WM_NCPAINT message. Called from DefWindowProc().
649 LONG
NC_HandleNCPaint( HWND hwnd
, HRGN hrgn
)
651 NC_DoNCPaint( hwnd
, hrgn
, hwnd
== GetActiveWindow() );
656 /***********************************************************************
657 * NC_HandleNCActivate
659 * Handle a WM_NCACTIVATE message. Called from DefWindowProc().
661 LONG
NC_HandleNCActivate( HWND hwnd
, WORD wParam
)
663 NC_DoNCPaint( hwnd
, (HRGN
)1, wParam
);
668 /***********************************************************************
671 * Handle a WM_SETCURSOR message. Called from DefWindowProc().
673 LONG
NC_HandleSetCursor( HWND hwnd
, WORD wParam
, LONG lParam
)
675 if (hwnd
!= wParam
) return 0; /* Don't set the cursor for child windows */
677 switch(LOWORD(lParam
))
681 WORD msg
= HIWORD( lParam
);
682 if ((msg
== WM_LBUTTONDOWN
) || (msg
== WM_MBUTTONDOWN
) ||
683 (msg
== WM_RBUTTONDOWN
))
692 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) break;
693 if (!(classPtr
= CLASS_FindClassPtr( wndPtr
->hClass
))) break;
694 if (classPtr
->wc
.hCursor
)
696 CURSOR_SetWinCursor( hwnd
, classPtr
->wc
.hCursor
);
704 CURSOR_SetWinCursor( hwnd
, LoadCursor( 0, IDC_SIZEWE
) );
709 CURSOR_SetWinCursor( hwnd
, LoadCursor( 0, IDC_SIZENS
) );
714 CURSOR_SetWinCursor( hwnd
, LoadCursor( 0, IDC_SIZENWSE
) );
719 CURSOR_SetWinCursor( hwnd
, LoadCursor( 0, IDC_SIZENESW
) );
723 /* Default cursor: arrow */
724 CURSOR_SetWinCursor( hwnd
, LoadCursor( 0, IDC_ARROW
) );
729 /***********************************************************************
732 * Initialisation of a move or resize, when initiatied from a menu choice.
733 * Return hit test code for caption or sizing border.
735 static LONG
NC_StartSizeMove( HWND hwnd
, WORD wParam
, POINT
*capturePoint
)
740 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
742 if ((wParam
& 0xfff0) == SC_MOVE
)
744 /* Move pointer at the center of the caption */
746 NC_GetInsideRect( hwnd
, &rect
);
747 if (wndPtr
->dwStyle
& WS_SYSMENU
)
748 rect
.left
+= SYSMETRICS_CXSIZE
+ 1;
749 if (wndPtr
->dwStyle
& WS_MINIMIZEBOX
)
750 rect
.right
-= SYSMETRICS_CXSIZE
+ 1;
751 if (wndPtr
->dwStyle
& WS_MAXIMIZEBOX
)
752 rect
.right
-= SYSMETRICS_CXSIZE
+ 1;
753 pt
.x
= wndPtr
->rectWindow
.left
+ (rect
.right
- rect
.left
) / 2;
754 pt
.y
= wndPtr
->rectWindow
.top
+ rect
.top
+ SYSMETRICS_CYSIZE
/2;
755 if (wndPtr
->dwStyle
& WS_CHILD
)
756 ClientToScreen( wndPtr
->hwndParent
, &pt
);
764 MSG_GetHardwareMessage( &msg
);
768 hittest
= NC_InternalNCHitTest( hwnd
, msg
.pt
);
770 if ((hittest
< HTLEFT
) || (hittest
> HTBOTTOMRIGHT
))
782 pt
.x
=(wndPtr
->rectWindow
.left
+wndPtr
->rectWindow
.right
)/2;
783 pt
.y
= wndPtr
->rectWindow
.top
+ SYSMETRICS_CYFRAME
/ 2;
787 pt
.x
=(wndPtr
->rectWindow
.left
+wndPtr
->rectWindow
.right
)/2;
788 pt
.y
= wndPtr
->rectWindow
.bottom
- SYSMETRICS_CYFRAME
/ 2;
792 pt
.x
= wndPtr
->rectWindow
.left
+ SYSMETRICS_CXFRAME
/ 2;
793 pt
.y
=(wndPtr
->rectWindow
.top
+wndPtr
->rectWindow
.bottom
)/2;
797 pt
.x
= wndPtr
->rectWindow
.right
- SYSMETRICS_CXFRAME
/ 2;
798 pt
.y
=(wndPtr
->rectWindow
.top
+wndPtr
->rectWindow
.bottom
)/2;
801 case VK_ESCAPE
: return 0;
807 SetCursorPos( capturePoint
->x
, capturePoint
->y
);
808 NC_HandleSetCursor( hwnd
, hwnd
, MAKELONG( hittest
, WM_MOUSEMOVE
));
813 /***********************************************************************
816 * Perform SC_MOVE and SC_SIZE commands.
818 static void NC_DoSizeMove( HWND hwnd
, WORD wParam
, POINT pt
)
822 RECT sizingRect
, mouseRect
;
825 POINT minTrack
, maxTrack
, capturePoint
= pt
;
826 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
828 if (IsZoomed(hwnd
) || IsIconic(hwnd
) || !IsWindowVisible(hwnd
)) return;
829 hittest
= wParam
& 0x0f;
830 thickframe
= HAS_THICKFRAME( wndPtr
->dwStyle
);
832 if ((wParam
& 0xfff0) == SC_MOVE
)
834 if (!(wndPtr
->dwStyle
& WS_CAPTION
)) return;
835 if (!hittest
) hittest
= NC_StartSizeMove( hwnd
, wParam
, &capturePoint
);
836 if (!hittest
) return;
840 if (!thickframe
) return;
841 if (hittest
) hittest
+= HTLEFT
-1;
845 hittest
= NC_StartSizeMove( hwnd
, wParam
, &capturePoint
);
854 /* Get min/max info */
856 WINPOS_GetMinMaxInfo( hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
857 sizingRect
= wndPtr
->rectWindow
;
858 if (wndPtr
->dwStyle
& WS_CHILD
)
859 GetClientRect( wndPtr
->hwndParent
, &mouseRect
);
860 else SetRect( &mouseRect
, 0, 0, SYSMETRICS_CXSCREEN
, SYSMETRICS_CYSCREEN
);
861 if (ON_LEFT_BORDER(hittest
))
863 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.right
-maxTrack
.x
);
864 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.right
-minTrack
.x
);
866 else if (ON_RIGHT_BORDER(hittest
))
868 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.left
+minTrack
.x
);
869 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.left
+maxTrack
.x
);
871 if (ON_TOP_BORDER(hittest
))
873 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.bottom
-maxTrack
.y
);
874 mouseRect
.bottom
= min( mouseRect
.bottom
,sizingRect
.bottom
-minTrack
.y
);
876 else if (ON_BOTTOM_BORDER(hittest
))
878 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.top
+minTrack
.y
);
879 mouseRect
.bottom
= min( mouseRect
.bottom
, sizingRect
.top
+maxTrack
.y
);
881 SendMessage( hwnd
, WM_ENTERSIZEMOVE
, 0, 0 );
883 if (GetCapture() != hwnd
) SetCapture( hwnd
);
885 if (wndPtr
->dwStyle
& WS_CHILD
) hdc
= GetDC( wndPtr
->hwndParent
);
887 { /* Grab the server only when moving top-level windows without desktop */
889 if (rootWindow
== DefaultRootWindow(display
)) XGrabServer( display
);
891 NC_DrawMovingFrame( hdc
, &sizingRect
, thickframe
);
897 MSG_GetHardwareMessage( &msg
);
899 /* Exit on button-up, Return, or Esc */
900 if ((msg
.message
== WM_LBUTTONUP
) ||
901 ((msg
.message
== WM_KEYDOWN
) &&
902 ((msg
.wParam
== VK_RETURN
) || (msg
.wParam
== VK_ESCAPE
)))) break;
904 if ((msg
.message
!= WM_KEYDOWN
) && (msg
.message
!= WM_MOUSEMOVE
))
905 continue; /* We are not interested in other messages */
908 if (wndPtr
->dwStyle
& WS_CHILD
)
909 ScreenToClient( wndPtr
->hwndParent
, &pt
);
912 if (msg
.message
== WM_KEYDOWN
) switch(msg
.wParam
)
914 case VK_UP
: pt
.y
-= 8; break;
915 case VK_DOWN
: pt
.y
+= 8; break;
916 case VK_LEFT
: pt
.x
-= 8; break;
917 case VK_RIGHT
: pt
.x
+= 8; break;
920 pt
.x
= max( pt
.x
, mouseRect
.left
);
921 pt
.x
= min( pt
.x
, mouseRect
.right
);
922 pt
.y
= max( pt
.y
, mouseRect
.top
);
923 pt
.y
= min( pt
.y
, mouseRect
.bottom
);
925 dx
= pt
.x
- capturePoint
.x
;
926 dy
= pt
.y
- capturePoint
.y
;
930 if (msg
.message
== WM_KEYDOWN
) SetCursorPos( pt
.x
, pt
.y
);
933 RECT newRect
= sizingRect
;
935 if (hittest
== HTCAPTION
) OffsetRect( &newRect
, dx
, dy
);
936 if (ON_LEFT_BORDER(hittest
)) newRect
.left
+= dx
;
937 else if (ON_RIGHT_BORDER(hittest
)) newRect
.right
+= dx
;
938 if (ON_TOP_BORDER(hittest
)) newRect
.top
+= dy
;
939 else if (ON_BOTTOM_BORDER(hittest
)) newRect
.bottom
+= dy
;
940 NC_DrawMovingFrame( hdc
, &sizingRect
, thickframe
);
941 NC_DrawMovingFrame( hdc
, &newRect
, thickframe
);
943 sizingRect
= newRect
;
948 NC_DrawMovingFrame( hdc
, &sizingRect
, thickframe
);
950 if (wndPtr
->dwStyle
& WS_CHILD
) ReleaseDC( wndPtr
->hwndParent
, hdc
);
954 if (rootWindow
== DefaultRootWindow(display
)) XUngrabServer( display
);
956 SendMessage( hwnd
, WM_EXITSIZEMOVE
, 0, 0 );
958 /* If Esc key, don't move the window */
959 if ((msg
.message
== WM_KEYDOWN
) && (msg
.wParam
== VK_ESCAPE
)) return;
961 if (hittest
!= HTCAPTION
)
962 SetWindowPos( hwnd
, 0, sizingRect
.left
, sizingRect
.top
,
963 sizingRect
.right
- sizingRect
.left
,
964 sizingRect
.bottom
- sizingRect
.top
,
965 SWP_NOACTIVATE
| SWP_NOZORDER
);
966 else SetWindowPos( hwnd
, 0, sizingRect
.left
, sizingRect
.top
, 0, 0,
967 SWP_NOACTIVATE
| SWP_NOSIZE
| SWP_NOZORDER
);
971 /***********************************************************************
974 * Track a mouse button press on the minimize or maximize box.
976 static void NC_TrackMinMaxBox( HWND hwnd
, WORD wParam
)
979 HDC hdc
= GetWindowDC( hwnd
);
983 if (wParam
== HTMINBUTTON
) NC_DrawMinButton( hwnd
, hdc
, TRUE
);
984 else NC_DrawMaxButton( hwnd
, hdc
, TRUE
);
988 BOOL oldstate
= pressed
;
989 MSG_GetHardwareMessage( &msg
);
991 pressed
= (NC_InternalNCHitTest( hwnd
, msg
.pt
) == wParam
);
992 if (pressed
!= oldstate
)
994 if (wParam
== HTMINBUTTON
) NC_DrawMinButton( hwnd
, hdc
, pressed
);
995 else NC_DrawMaxButton( hwnd
, hdc
, pressed
);
997 } while (msg
.message
!= WM_LBUTTONUP
);
999 if (wParam
== HTMINBUTTON
) NC_DrawMinButton( hwnd
, hdc
, FALSE
);
1000 else NC_DrawMaxButton( hwnd
, hdc
, FALSE
);
1003 ReleaseDC( hwnd
, hdc
);
1004 if (!pressed
) return;
1006 if (wParam
== HTMINBUTTON
)
1007 SendMessage( hwnd
, WM_SYSCOMMAND
, SC_MINIMIZE
, *(LONG
*)&msg
.pt
);
1009 SendMessage( hwnd
, WM_SYSCOMMAND
,
1010 IsZoomed(hwnd
) ? SC_RESTORE
: SC_MAXIMIZE
, *(LONG
*)&msg
.pt
);
1014 /***********************************************************************
1017 * Track a mouse button press on the horizontal or vertical scroll-bar.
1019 static void NC_TrackScrollBar( HWND hwnd
, WORD wParam
, POINT pt
)
1023 if ((wParam
& 0xfff0) == SC_HSCROLL
)
1025 if ((wParam
& 0x0f) != HTHSCROLL
) return;
1026 scrollbar
= SB_HORZ
;
1028 else /* SC_VSCROLL */
1030 if ((wParam
& 0x0f) != HTVSCROLL
) return;
1031 scrollbar
= SB_VERT
;
1034 ScreenToClient( hwnd
, &pt
);
1035 ScrollBarButtonDown( hwnd
, scrollbar
, pt
.x
, pt
.y
);
1040 MSG_GetHardwareMessage( &msg
);
1041 ScreenToClient( msg
.hwnd
, &msg
.pt
);
1045 ScrollBarButtonUp( hwnd
, scrollbar
, msg
.pt
.x
, msg
.pt
.y
);
1048 ScrollBarMouseMove(hwnd
, scrollbar
, msg
.wParam
, msg
.pt
.x
,msg
.pt
.y
);
1051 } while (msg
.message
!= WM_LBUTTONUP
);
1056 /***********************************************************************
1057 * NC_TrackMouseMenuBar
1059 * Track a mouse events for the MenuBar.
1061 static void NC_TrackMouseMenuBar( HWND hwnd
, WORD wParam
, POINT pt
)
1066 wndPtr
= WIN_FindWndPtr(hwnd
);
1067 lppop
= (LPPOPUPMENU
)GlobalLock(wndPtr
->wIDmenu
);
1069 printf("NC_TrackMouseMenuBar // wndPtr=%08X lppop=%08X !\n", wndPtr
, lppop
);
1071 ScreenToClient(hwnd
, &pt
);
1072 pt
.y
+= lppop
->rect
.bottom
;
1074 if (!MenuButtonDown(hwnd
, lppop
, pt
.x
, pt
.y
)) {
1076 if (!GetMessage(&msg
, (HWND
)NULL
, 0, 0)) break;
1077 ScreenToClient(hwnd
, &msg
.pt
);
1078 msg
.pt
.y
+= lppop
->rect
.bottom
;
1079 switch(msg
.message
) {
1081 MenuButtonUp(hwnd
, lppop
, msg
.pt
.x
, msg
.pt
.y
);
1084 MenuMouseMove(hwnd
, lppop
, msg
.wParam
, msg
.pt
.x
, msg
.pt
.y
);
1087 TranslateMessage(&msg
);
1088 DispatchMessage(&msg
);
1091 } while (msg
.message
!= WM_LBUTTONUP
);
1094 GlobalUnlock(wndPtr
->wIDmenu
);
1098 /***********************************************************************
1099 * NC_HandleNCLButtonDown
1101 * Handle a WM_NCLBUTTONDOWN message. Called from DefWindowProc().
1103 LONG
NC_HandleNCLButtonDown( HWND hwnd
, WORD wParam
, LONG lParam
)
1105 HDC hdc
= GetWindowDC( hwnd
);
1107 switch(wParam
) /* Hit test */
1110 SendMessage( hwnd
, WM_SYSCOMMAND
, SC_MOVE
+ HTCAPTION
, lParam
);
1114 NC_DrawSysButton( hwnd
, hdc
, TRUE
);
1115 NC_TrackSysMenu(hwnd
);
1119 SendMessage( hwnd
, WM_SYSCOMMAND
, SC_MOUSEMENU
, lParam
);
1123 SendMessage( hwnd
, WM_SYSCOMMAND
, SC_HSCROLL
+ HTHSCROLL
, lParam
);
1127 SendMessage( hwnd
, WM_SYSCOMMAND
, SC_VSCROLL
+ HTVSCROLL
, lParam
);
1132 NC_TrackMinMaxBox( hwnd
, wParam
);
1143 SendMessage( hwnd
, WM_SYSCOMMAND
, SC_SIZE
+ wParam
- HTLEFT
+1, lParam
);
1150 ReleaseDC( hwnd
, hdc
);
1155 /***********************************************************************
1156 * NC_HandleNCLButtonDblClk
1158 * Handle a WM_NCLBUTTONDBLCLK message. Called from DefWindowProc().
1160 LONG
NC_HandleNCLButtonDblClk( HWND hwnd
, WORD wParam
, LONG lParam
)
1162 switch(wParam
) /* Hit test */
1165 SendMessage( hwnd
, WM_SYSCOMMAND
, SC_MAXIMIZE
, lParam
);
1169 SendMessage( hwnd
, WM_SYSCOMMAND
, SC_CLOSE
, lParam
);
1176 /***********************************************************************
1177 * NC_HandleSysCommand
1179 * Handle a WM_SYSCOMMAND message. Called from DefWindowProc().
1181 LONG
NC_HandleSysCommand( HWND hwnd
, WORD wParam
, POINT pt
)
1183 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
1185 #ifdef DEBUG_NONCLIENT
1186 printf( "Handling WM_SYSCOMMAND %x %d,%d\n", wParam
, pt
.x
, pt
.y
);
1189 if (wndPtr
->dwStyle
& WS_CHILD
) ScreenToClient( wndPtr
->hwndParent
, &pt
);
1191 switch (wParam
& 0xfff0)
1195 NC_DoSizeMove( hwnd
, wParam
, pt
);
1199 ShowWindow( hwnd
, SW_MINIMIZE
);
1203 ShowWindow( hwnd
, SW_MAXIMIZE
);
1207 ShowWindow( hwnd
, SW_RESTORE
);
1215 return SendMessage( hwnd
, WM_CLOSE
, 0, 0 );
1219 if (wndPtr
->dwStyle
& WS_CHILD
) ClientToScreen(wndPtr
->hwndParent
, &pt
);
1220 NC_TrackScrollBar( hwnd
, wParam
, pt
);
1224 NC_TrackMouseMenuBar( hwnd
, wParam
, pt
);
1228 /* NC_KeyMenuBar( hwnd, wParam, pt ); */