blob: 70b8125d5e9ba3b8b542b8074fc4b67060e57aac [file] [log] [blame]
Alexandre Julliardcdd09231994-01-12 11:12:51 +00001/*
2 * Non-client area window functions
3 *
4 * Copyright 1994 Alexandre Julliard
Alexandre Julliard234bc241994-12-10 13:02:28 +00005 *
Alexandre Julliard7cbe6571995-01-09 18:21:16 +00006 */
Alexandre Julliardcdd09231994-01-12 11:12:51 +00007
8#include "win.h"
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00009#include "class.h"
Alexandre Julliarddba420a1994-02-02 06:48:31 +000010#include "message.h"
Alexandre Julliardcdd09231994-01-12 11:12:51 +000011#include "sysmetrics.h"
Alexandre Julliarddba420a1994-02-02 06:48:31 +000012#include "user.h"
Alexandre Julliarde2991ea1995-07-29 13:09:43 +000013#include "shell.h"
Alexandre Julliard234bc241994-12-10 13:02:28 +000014#include "dialog.h"
Alexandre Julliard58199531994-04-21 01:20:00 +000015#include "syscolor.h"
Alexandre Julliard234bc241994-12-10 13:02:28 +000016#include "menu.h"
17#include "winpos.h"
18#include "scroll.h"
19#include "nonclient.h"
20#include "graphics.h"
Alexandre Julliardfa68b751995-04-03 16:55:37 +000021#include "selectors.h"
Alexandre Julliardd4719651995-12-12 18:49:11 +000022#include "stackframe.h"
Alexandre Julliardaca05781994-10-17 18:12:41 +000023#include "stddebug.h"
Alexandre Julliardecc37121994-11-22 16:31:29 +000024/* #define DEBUG_NONCLIENT */
Alexandre Julliardaca05781994-10-17 18:12:41 +000025#include "debug.h"
Alexandre Julliardd4719651995-12-12 18:49:11 +000026#include "options.h"
Alexandre Julliardaca05781994-10-17 18:12:41 +000027
Alexandre Julliardcdd09231994-01-12 11:12:51 +000028
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +000029static HBITMAP hbitmapClose = 0;
30static HBITMAP hbitmapMinimize = 0;
31static HBITMAP hbitmapMinimizeD = 0;
32static HBITMAP hbitmapMaximize = 0;
33static HBITMAP hbitmapMaximizeD = 0;
34static HBITMAP hbitmapRestore = 0;
35static HBITMAP hbitmapRestoreD = 0;
36
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +000037#define SC_ABOUTWINE (SC_SCREENSAVE+1)
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +000038
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +000039 /* Some useful macros */
40#define HAS_DLGFRAME(style,exStyle) \
Alexandre Julliard0c126c71996-02-18 18:44:41 +000041 (((exStyle) & WS_EX_DLGMODALFRAME) || \
42 (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +000043
44#define HAS_THICKFRAME(style) \
Alexandre Julliard0c126c71996-02-18 18:44:41 +000045 (((style) & WS_THICKFRAME) && \
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +000046 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
47
48#define HAS_MENU(w) (!((w)->dwStyle & WS_CHILD) && ((w)->wIDmenu != 0))
49
Alexandre Julliardfb9a9191994-03-01 19:48:04 +000050#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))
58
Alexandre Julliardcdd09231994-01-12 11:12:51 +000059/***********************************************************************
60 * NC_AdjustRect
61 *
62 * Compute the size of the window rectangle from the size of the
63 * client rectangle.
64 */
65static void NC_AdjustRect( LPRECT rect, DWORD style, BOOL menu, DWORD exStyle )
66{
Alexandre Julliard3ed37e01994-11-07 18:20:42 +000067 if (style & WS_ICONIC) return; /* Nothing to change for an icon */
Alexandre Julliardcdd09231994-01-12 11:12:51 +000068
Alexandre Julliard0c126c71996-02-18 18:44:41 +000069 /* Decide if the window will be managed (see CreateWindowEx) */
70 if (!(Options.managed && ((style & (WS_DLGFRAME | WS_THICKFRAME)) ||
71 (exStyle & WS_EX_DLGMODALFRAME))))
72 {
73 if (HAS_DLGFRAME( style, exStyle ))
74 InflateRect( rect, SYSMETRICS_CXDLGFRAME, SYSMETRICS_CYDLGFRAME );
75 else
76 {
77 if (HAS_THICKFRAME(style))
78 InflateRect( rect, SYSMETRICS_CXFRAME, SYSMETRICS_CYFRAME );
79 if (style & WS_BORDER)
80 InflateRect( rect, SYSMETRICS_CXBORDER, SYSMETRICS_CYBORDER );
81 }
82
83 if ((style & WS_CAPTION) == WS_CAPTION)
84 rect->top -= SYSMETRICS_CYCAPTION - SYSMETRICS_CYBORDER;
85 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +000086 if (menu) rect->top -= SYSMETRICS_CYMENU + SYSMETRICS_CYBORDER;
Alexandre Julliardcdd09231994-01-12 11:12:51 +000087
88 if (style & WS_VSCROLL) rect->right += SYSMETRICS_CXVSCROLL;
89 if (style & WS_HSCROLL) rect->bottom += SYSMETRICS_CYHSCROLL;
90}
91
92
93/***********************************************************************
94 * AdjustWindowRect (USER.102)
95 */
Alexandre Julliard7e56f681996-01-31 19:02:28 +000096BOOL AdjustWindowRect( LPRECT rect, DWORD style, BOOL menu )
Alexandre Julliardcdd09231994-01-12 11:12:51 +000097{
Alexandre Julliard7e56f681996-01-31 19:02:28 +000098 return AdjustWindowRectEx( rect, style, menu, 0 );
Alexandre Julliardcdd09231994-01-12 11:12:51 +000099}
100
101
102/***********************************************************************
103 * AdjustWindowRectEx (USER.454)
104 */
Alexandre Julliard7e56f681996-01-31 19:02:28 +0000105BOOL AdjustWindowRectEx( LPRECT rect, DWORD style, BOOL menu, DWORD exStyle )
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000106{
107 /* Correct the window style */
108
109 if (!(style & (WS_POPUP | WS_CHILD))) /* Overlapped window */
110 style |= WS_CAPTION;
111 if (exStyle & WS_EX_DLGMODALFRAME) style &= ~WS_THICKFRAME;
112
Alexandre Julliard59730ae1996-03-24 16:20:51 +0000113 dprintf_nonclient(stddeb, "AdjustWindowRectEx: (%d,%d)-(%d,%d) %08lx %d %08lx\n",
114 rect->left, rect->top, rect->right, rect->bottom,
115 style, menu, exStyle );
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000116
117 NC_AdjustRect( rect, style, menu, exStyle );
Alexandre Julliard7e56f681996-01-31 19:02:28 +0000118 return TRUE;
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000119}
120
121
Alexandre Julliard22945d51995-03-02 17:44:29 +0000122/*******************************************************************
123 * NC_GetMinMaxInfo
124 *
125 * Get the minimized and maximized information for a window.
126 */
127void NC_GetMinMaxInfo( HWND hwnd, POINT *maxSize, POINT *maxPos,
128 POINT *minTrack, POINT *maxTrack )
129{
Alexandre Julliardd4719651995-12-12 18:49:11 +0000130 MINMAXINFO MinMax;
Alexandre Julliard22945d51995-03-02 17:44:29 +0000131 short xinc, yinc;
132 WND *wndPtr = WIN_FindWndPtr( hwnd );
133
134 /* Compute default values */
135
136 MinMax.ptMaxSize.x = SYSMETRICS_CXSCREEN;
137 MinMax.ptMaxSize.y = SYSMETRICS_CYSCREEN;
138 MinMax.ptMinTrackSize.x = SYSMETRICS_CXMINTRACK;
139 MinMax.ptMinTrackSize.y = SYSMETRICS_CYMINTRACK;
140 MinMax.ptMaxTrackSize.x = SYSMETRICS_CXSCREEN;
141 MinMax.ptMaxTrackSize.y = SYSMETRICS_CYSCREEN;
142
Alexandre Julliard0c126c71996-02-18 18:44:41 +0000143 if (wndPtr->flags & WIN_MANAGED) xinc = yinc = 0;
Alexandre Julliardd4719651995-12-12 18:49:11 +0000144 else if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
Alexandre Julliard22945d51995-03-02 17:44:29 +0000145 {
146 xinc = SYSMETRICS_CXDLGFRAME;
147 yinc = SYSMETRICS_CYDLGFRAME;
148 }
149 else
150 {
151 xinc = yinc = 0;
152 if (HAS_THICKFRAME(wndPtr->dwStyle))
153 {
154 xinc += SYSMETRICS_CXFRAME;
155 yinc += SYSMETRICS_CYFRAME;
156 }
157 if (wndPtr->dwStyle & WS_BORDER)
158 {
159 xinc += SYSMETRICS_CXBORDER;
160 yinc += SYSMETRICS_CYBORDER;
161 }
162 }
163 MinMax.ptMaxSize.x += 2 * xinc;
164 MinMax.ptMaxSize.y += 2 * yinc;
165
Alexandre Julliarde2991ea1995-07-29 13:09:43 +0000166 /* Note: The '+' in the following test should really be a ||, but
167 * that would cause gcc-2.7.0 to generate incorrect code.
168 */
169 if ((wndPtr->ptMaxPos.x != -1) + (wndPtr->ptMaxPos.y != -1))
Alexandre Julliard22945d51995-03-02 17:44:29 +0000170 MinMax.ptMaxPosition = wndPtr->ptMaxPos;
171 else
172 {
173 MinMax.ptMaxPosition.x = -xinc;
174 MinMax.ptMaxPosition.y = -yinc;
175 }
176
Alexandre Julliardd7d4fdf1995-12-26 15:05:24 +0000177 SendMessage( hwnd, WM_GETMINMAXINFO, 0, (LPARAM)MAKE_SEGPTR(&MinMax) );
Alexandre Julliard22945d51995-03-02 17:44:29 +0000178
179 /* Some sanity checks */
180
Alexandre Julliardd4719651995-12-12 18:49:11 +0000181 dprintf_nonclient(stddeb,
182 "NC_GetMinMaxInfo: %d %d / %d %d / %d %d / %d %d\n",
Alexandre Julliardd7d4fdf1995-12-26 15:05:24 +0000183 (int)MinMax.ptMaxSize.x,(int)MinMax.ptMaxSize.y,
184 (int)MinMax.ptMaxPosition.x,(int)MinMax.ptMaxPosition.y,
185 (int)MinMax.ptMaxTrackSize.x,(int)MinMax.ptMaxTrackSize.y,
186 (int)MinMax.ptMinTrackSize.x,(int)MinMax.ptMinTrackSize.y);
Alexandre Julliardd4719651995-12-12 18:49:11 +0000187 MinMax.ptMaxTrackSize.x = MAX( MinMax.ptMaxTrackSize.x,
188 MinMax.ptMinTrackSize.x );
189 MinMax.ptMaxTrackSize.y = MAX( MinMax.ptMaxTrackSize.y,
190 MinMax.ptMinTrackSize.y );
Alexandre Julliard22945d51995-03-02 17:44:29 +0000191
Alexandre Julliardd4719651995-12-12 18:49:11 +0000192 if (maxSize) *maxSize = MinMax.ptMaxSize;
193 if (maxPos) *maxPos = MinMax.ptMaxPosition;
194 if (minTrack) *minTrack = MinMax.ptMinTrackSize;
195 if (maxTrack) *maxTrack = MinMax.ptMaxTrackSize;
Alexandre Julliard22945d51995-03-02 17:44:29 +0000196}
197
198
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000199/***********************************************************************
200 * NC_HandleNCCalcSize
201 *
202 * Handle a WM_NCCALCSIZE message. Called from DefWindowProc().
203 */
204LONG NC_HandleNCCalcSize( HWND hwnd, NCCALCSIZE_PARAMS *params )
205{
206 RECT tmpRect = { 0, 0, 0, 0 };
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +0000207 WND *wndPtr = WIN_FindWndPtr( hwnd );
208
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000209 if (!wndPtr) return 0;
Alexandre Julliard2d159fb1994-07-15 16:04:31 +0000210 NC_AdjustRect( &tmpRect, wndPtr->dwStyle, FALSE, wndPtr->dwExStyle );
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000211 params->rgrc[0].left -= tmpRect.left;
212 params->rgrc[0].top -= tmpRect.top;
213 params->rgrc[0].right -= tmpRect.right;
214 params->rgrc[0].bottom -= tmpRect.bottom;
Alexandre Julliard2d159fb1994-07-15 16:04:31 +0000215
216 if (HAS_MENU(wndPtr))
217 {
218 params->rgrc[0].top += MENU_GetMenuBarHeight( hwnd,
Alexandre Julliardf7207251994-07-23 07:57:48 +0000219 params->rgrc[0].right - params->rgrc[0].left,
220 -tmpRect.left, -tmpRect.top ) + 1;
Alexandre Julliard2d159fb1994-07-15 16:04:31 +0000221 }
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000222 return 0;
223}
224
225
226/***********************************************************************
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +0000227 * NC_GetInsideRect
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000228 *
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +0000229 * Get the 'inside' rectangle of a window, i.e. the whole window rectangle
230 * but without the borders (if any).
231 * The rectangle is in window coordinates (for drawing with GetWindowDC()).
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000232 */
Alexandre Julliard58199531994-04-21 01:20:00 +0000233void NC_GetInsideRect( HWND hwnd, RECT *rect )
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +0000234{
235 WND * wndPtr = WIN_FindWndPtr( hwnd );
236
237 rect->top = rect->left = 0;
238 rect->right = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
239 rect->bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
240
Alexandre Julliard3ed37e01994-11-07 18:20:42 +0000241 if (wndPtr->dwStyle & WS_ICONIC) return; /* No border to remove */
Alexandre Julliard0c126c71996-02-18 18:44:41 +0000242 if (wndPtr->flags & WIN_MANAGED) return;
Alexandre Julliard3ed37e01994-11-07 18:20:42 +0000243
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +0000244 /* Remove frame from rectangle */
245 if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000246 {
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +0000247 InflateRect( rect, -SYSMETRICS_CXDLGFRAME, -SYSMETRICS_CYDLGFRAME);
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000248 if (wndPtr->dwExStyle & WS_EX_DLGMODALFRAME) InflateRect( rect, -1, 0);
249 }
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +0000250 else
251 {
252 if (HAS_THICKFRAME( wndPtr->dwStyle ))
253 InflateRect( rect, -SYSMETRICS_CXFRAME, -SYSMETRICS_CYFRAME );
254 if (wndPtr->dwStyle & WS_BORDER)
255 InflateRect( rect, -SYSMETRICS_CXBORDER, -SYSMETRICS_CYBORDER );
256 }
257}
258
259
260/***********************************************************************
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000261 * NC_HandleNCHitTest
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +0000262 *
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000263 * Handle a WM_NCHITTEST message. Called from DefWindowProc().
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +0000264 */
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000265LONG NC_HandleNCHitTest( HWND hwnd, POINT pt )
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000266{
267 RECT rect;
268 WND *wndPtr = WIN_FindWndPtr( hwnd );
269 if (!wndPtr) return HTERROR;
270
Alexandre Julliard59730ae1996-03-24 16:20:51 +0000271 dprintf_nonclient(stddeb, "NC_HandleNCHitTest: hwnd=%04x pt=%d,%d\n",
272 hwnd, pt.x, pt.y );
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000273
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000274 GetWindowRect( hwnd, &rect );
275 if (!PtInRect( &rect, pt )) return HTNOWHERE;
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000276
Alexandre Julliard0c126c71996-02-18 18:44:41 +0000277 if (wndPtr->dwStyle & WS_MINIMIZE) return HTCAPTION;
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000278
Alexandre Julliard0c126c71996-02-18 18:44:41 +0000279 if (!(wndPtr->flags & WIN_MANAGED))
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000280 {
Alexandre Julliard0c126c71996-02-18 18:44:41 +0000281 /* Check borders */
282 if (HAS_THICKFRAME( wndPtr->dwStyle ))
283 {
284 InflateRect( &rect, -SYSMETRICS_CXFRAME, -SYSMETRICS_CYFRAME );
285 if (wndPtr->dwStyle & WS_BORDER)
286 InflateRect(&rect, -SYSMETRICS_CXBORDER, -SYSMETRICS_CYBORDER);
287 if (!PtInRect( &rect, pt ))
288 {
289 /* Check top sizing border */
290 if (pt.y < rect.top)
291 {
292 if (pt.x < rect.left+SYSMETRICS_CXSIZE) return HTTOPLEFT;
293 if (pt.x >= rect.right-SYSMETRICS_CXSIZE) return HTTOPRIGHT;
294 return HTTOP;
295 }
296 /* Check bottom sizing border */
297 if (pt.y >= rect.bottom)
298 {
299 if (pt.x < rect.left+SYSMETRICS_CXSIZE) return HTBOTTOMLEFT;
300 if (pt.x >= rect.right-SYSMETRICS_CXSIZE) return HTBOTTOMRIGHT;
301 return HTBOTTOM;
302 }
303 /* Check left sizing border */
304 if (pt.x < rect.left)
305 {
306 if (pt.y < rect.top+SYSMETRICS_CYSIZE) return HTTOPLEFT;
307 if (pt.y >= rect.bottom-SYSMETRICS_CYSIZE) return HTBOTTOMLEFT;
308 return HTLEFT;
309 }
310 /* Check right sizing border */
311 if (pt.x >= rect.right)
312 {
313 if (pt.y < rect.top+SYSMETRICS_CYSIZE) return HTTOPRIGHT;
314 if (pt.y >= rect.bottom-SYSMETRICS_CYSIZE) return HTBOTTOMRIGHT;
315 return HTRIGHT;
316 }
317 }
318 }
319 else /* No thick frame */
320 {
321 if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
322 InflateRect(&rect, -SYSMETRICS_CXDLGFRAME, -SYSMETRICS_CYDLGFRAME);
323 else if (wndPtr->dwStyle & WS_BORDER)
324 InflateRect(&rect, -SYSMETRICS_CXBORDER, -SYSMETRICS_CYBORDER);
325 if (!PtInRect( &rect, pt )) return HTBORDER;
326 }
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000327
Alexandre Julliard0c126c71996-02-18 18:44:41 +0000328 /* Check caption */
Alexandre Julliardf7207251994-07-23 07:57:48 +0000329
Alexandre Julliard0c126c71996-02-18 18:44:41 +0000330 if ((wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION)
331 {
332 rect.top += SYSMETRICS_CYCAPTION - 1;
333 if (!PtInRect( &rect, pt ))
334 {
335 /* Check system menu */
336 if (wndPtr->dwStyle & WS_SYSMENU)
337 rect.left += SYSMETRICS_CXSIZE;
338 if (pt.x <= rect.left) return HTSYSMENU;
339 /* Check maximize box */
340 if (wndPtr->dwStyle & WS_MAXIMIZEBOX)
341 rect.right -= SYSMETRICS_CXSIZE + 1;
342 if (pt.x >= rect.right) return HTMAXBUTTON;
343 /* Check minimize box */
344 if (wndPtr->dwStyle & WS_MINIMIZEBOX)
345 rect.right -= SYSMETRICS_CXSIZE + 1;
346 if (pt.x >= rect.right) return HTMINBUTTON;
347 return HTCAPTION;
348 }
349 }
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000350 }
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000351
Alexandre Julliardf7207251994-07-23 07:57:48 +0000352 /* Check client area */
353
354 ScreenToClient( hwnd, &pt );
355 GetClientRect( hwnd, &rect );
356 if (PtInRect( &rect, pt )) return HTCLIENT;
357
358 /* Check vertical scroll bar */
359
360 if (wndPtr->dwStyle & WS_VSCROLL)
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000361 {
Alexandre Julliardf7207251994-07-23 07:57:48 +0000362 rect.right += SYSMETRICS_CXVSCROLL;
363 if (PtInRect( &rect, pt )) return HTVSCROLL;
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000364 }
365
Alexandre Julliardf7207251994-07-23 07:57:48 +0000366 /* Check horizontal scroll bar */
367
368 if (wndPtr->dwStyle & WS_HSCROLL)
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000369 {
Alexandre Julliardf7207251994-07-23 07:57:48 +0000370 rect.bottom += SYSMETRICS_CYHSCROLL;
371 if (PtInRect( &rect, pt ))
372 {
373 /* Check size box */
374 if ((wndPtr->dwStyle & WS_VSCROLL) &&
375 (pt.x >= rect.right - SYSMETRICS_CXVSCROLL))
376 return HTSIZE;
377 return HTHSCROLL;
378 }
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000379 }
380
Alexandre Julliardf7207251994-07-23 07:57:48 +0000381 /* Check menu bar */
382
383 if (HAS_MENU(wndPtr))
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000384 {
Alexandre Julliardf7207251994-07-23 07:57:48 +0000385 if ((pt.y < 0) && (pt.x >= 0) && (pt.x < rect.right))
386 return HTMENU;
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000387 }
388
389 /* Should never get here */
390 return HTERROR;
391}
392
393
394/***********************************************************************
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +0000395 * NC_DrawSysButton
396 */
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000397void NC_DrawSysButton( HWND hwnd, HDC hdc, BOOL down )
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +0000398{
399 RECT rect;
Alexandre Julliard7cbe6571995-01-09 18:21:16 +0000400 HDC hdcMem;
401 HBITMAP hbitmap;
Alexandre Julliard1f579291994-05-25 16:25:21 +0000402 WND *wndPtr = WIN_FindWndPtr( hwnd );
Alexandre Julliard7cbe6571995-01-09 18:21:16 +0000403
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000404 NC_GetInsideRect( hwnd, &rect );
Alexandre Julliard7cbe6571995-01-09 18:21:16 +0000405 hdcMem = CreateCompatibleDC( hdc );
406 hbitmap = SelectObject( hdcMem, hbitmapClose );
407 BitBlt( hdc, rect.left, rect.top, SYSMETRICS_CXSIZE, SYSMETRICS_CYSIZE,
408 hdcMem, (wndPtr->dwStyle & WS_CHILD) ? SYSMETRICS_CXSIZE : 0, 0,
409 down ? NOTSRCCOPY : SRCCOPY );
410 SelectObject( hdcMem, hbitmap );
411 DeleteDC( hdcMem );
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +0000412}
413
414
415/***********************************************************************
416 * NC_DrawMaxButton
417 */
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000418static void NC_DrawMaxButton( HWND hwnd, HDC hdc, BOOL down )
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +0000419{
420 RECT rect;
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000421 NC_GetInsideRect( hwnd, &rect );
422 GRAPH_DrawBitmap( hdc, (IsZoomed(hwnd) ?
423 (down ? hbitmapRestoreD : hbitmapRestore) :
424 (down ? hbitmapMaximizeD : hbitmapMaximize)),
Alexandre Julliard3ed37e01994-11-07 18:20:42 +0000425 rect.right - SYSMETRICS_CXSIZE - 1, rect.top,
Alexandre Julliard7cbe6571995-01-09 18:21:16 +0000426 0, 0, SYSMETRICS_CXSIZE+1, SYSMETRICS_CYSIZE );
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +0000427}
428
429
430/***********************************************************************
431 * NC_DrawMinButton
432 */
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000433static void NC_DrawMinButton( HWND hwnd, HDC hdc, BOOL down )
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +0000434{
435 RECT rect;
436 WND *wndPtr = WIN_FindWndPtr( hwnd );
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000437 NC_GetInsideRect( hwnd, &rect );
438 if (wndPtr->dwStyle & WS_MAXIMIZEBOX) rect.right -= SYSMETRICS_CXSIZE + 1;
439 GRAPH_DrawBitmap( hdc, (down ? hbitmapMinimizeD : hbitmapMinimize),
Alexandre Julliard3ed37e01994-11-07 18:20:42 +0000440 rect.right - SYSMETRICS_CXSIZE - 1, rect.top,
Alexandre Julliard7cbe6571995-01-09 18:21:16 +0000441 0, 0, SYSMETRICS_CXSIZE+1, SYSMETRICS_CYSIZE );
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +0000442}
443
444
445/***********************************************************************
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000446 * NC_DrawFrame
447 *
448 * Draw a window frame inside the given rectangle, and update the rectangle.
Alexandre Julliardaca05781994-10-17 18:12:41 +0000449 * The correct pen for the frame must be selected in the DC.
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000450 */
Alexandre Julliardaca05781994-10-17 18:12:41 +0000451static void NC_DrawFrame( HDC hdc, RECT *rect, BOOL dlgFrame, BOOL active )
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000452{
453 short width, height, tmp;
454
455 if (dlgFrame)
456 {
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000457 width = SYSMETRICS_CXDLGFRAME - 1;
458 height = SYSMETRICS_CYDLGFRAME - 1;
Alexandre Julliardaca05781994-10-17 18:12:41 +0000459 SelectObject( hdc, active ? sysColorObjects.hbrushActiveCaption :
460 sysColorObjects.hbrushInactiveCaption );
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000461 }
462 else
463 {
464 width = SYSMETRICS_CXFRAME - 1;
465 height = SYSMETRICS_CYFRAME - 1;
Alexandre Julliardaca05781994-10-17 18:12:41 +0000466 SelectObject( hdc, active ? sysColorObjects.hbrushActiveBorder :
467 sysColorObjects.hbrushInactiveBorder );
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000468 }
469
470 /* Draw frame */
471 PatBlt( hdc, rect->left, rect->top,
472 rect->right - rect->left, height, PATCOPY );
473 PatBlt( hdc, rect->left, rect->top,
474 width, rect->bottom - rect->top, PATCOPY );
475 PatBlt( hdc, rect->left, rect->bottom,
476 rect->right - rect->left, -height, PATCOPY );
477 PatBlt( hdc, rect->right, rect->top,
478 -width, rect->bottom - rect->top, PATCOPY );
479
480 if (dlgFrame)
481 {
482 InflateRect( rect, -width, -height );
483 return;
484 }
485
486 /* Draw inner rectangle */
487 MoveTo( hdc, rect->left+width, rect->top+height );
488 LineTo( hdc, rect->right-width-1, rect->top+height );
489 LineTo( hdc, rect->right-width-1, rect->bottom-height-1 );
490 LineTo( hdc, rect->left+width, rect->bottom-height-1 );
491 LineTo( hdc, rect->left+width, rect->top+height );
492
493 /* Draw the decorations */
494 tmp = rect->top + SYSMETRICS_CYFRAME + SYSMETRICS_CYSIZE;
495 MoveTo( hdc, rect->left, tmp);
496 LineTo( hdc, rect->left+width, tmp );
497 MoveTo( hdc, rect->right-width-1, tmp );
498 LineTo( hdc, rect->right-1, tmp );
499
500 tmp = rect->bottom - 1 - SYSMETRICS_CYFRAME - SYSMETRICS_CYSIZE;
501 MoveTo( hdc, rect->left, tmp );
502 LineTo( hdc, rect->left+width, tmp );
503 MoveTo( hdc, rect->right-width-1, tmp );
504 LineTo( hdc, rect->right-1, tmp );
505
506 tmp = rect->left + SYSMETRICS_CXFRAME + SYSMETRICS_CXSIZE;
507 MoveTo( hdc, tmp, rect->top );
508 LineTo( hdc, tmp, rect->top+height );
509 MoveTo( hdc, tmp, rect->bottom-height-1 );
510 LineTo( hdc, tmp, rect->bottom-1 );
511
512 tmp = rect->right - 1 - SYSMETRICS_CXFRAME - SYSMETRICS_CYSIZE;
513 MoveTo( hdc, tmp, rect->top );
514 LineTo( hdc, tmp, rect->top+height );
515 MoveTo( hdc, tmp, rect->bottom-height-1 );
516 LineTo( hdc, tmp, rect->bottom-1 );
517
518 InflateRect( rect, -width-1, -height-1 );
519}
520
521
522/***********************************************************************
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +0000523 * NC_DrawMovingFrame
524 *
525 * Draw the frame used when moving or resizing window.
526 */
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000527static void NC_DrawMovingFrame( HDC hdc, RECT *rect, BOOL thickframe )
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +0000528{
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000529 if (thickframe)
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +0000530 {
531 SelectObject( hdc, GetStockObject( GRAY_BRUSH ) );
532 PatBlt( hdc, rect->left, rect->top,
533 rect->right - rect->left - SYSMETRICS_CXFRAME,
534 SYSMETRICS_CYFRAME, PATINVERT );
535 PatBlt( hdc, rect->left, rect->top + SYSMETRICS_CYFRAME,
536 SYSMETRICS_CXFRAME,
537 rect->bottom - rect->top - SYSMETRICS_CYFRAME, PATINVERT );
538 PatBlt( hdc, rect->left + SYSMETRICS_CXFRAME, rect->bottom,
539 rect->right - rect->left - SYSMETRICS_CXFRAME,
540 -SYSMETRICS_CYFRAME, PATINVERT );
541 PatBlt( hdc, rect->right, rect->top, -SYSMETRICS_CXFRAME,
542 rect->bottom - rect->top - SYSMETRICS_CYFRAME, PATINVERT );
543 }
544 else DrawFocusRect( hdc, rect );
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +0000545}
546
547
548/***********************************************************************
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000549 * NC_DrawCaption
550 *
551 * Draw the window caption.
552 * The correct pen for the window frame must be selected in the DC.
553 */
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000554static void NC_DrawCaption( HDC hdc, RECT *rect, HWND hwnd,
555 DWORD style, BOOL active )
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000556{
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +0000557 RECT r = *rect;
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000558 WND * wndPtr = WIN_FindWndPtr( hwnd );
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000559 char buffer[256];
560
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +0000561 if (!hbitmapClose)
562 {
563 if (!(hbitmapClose = LoadBitmap( 0, MAKEINTRESOURCE(OBM_CLOSE) )))
564 return;
565 hbitmapMinimize = LoadBitmap( 0, MAKEINTRESOURCE(OBM_REDUCE) );
566 hbitmapMinimizeD = LoadBitmap( 0, MAKEINTRESOURCE(OBM_REDUCED) );
567 hbitmapMaximize = LoadBitmap( 0, MAKEINTRESOURCE(OBM_ZOOM) );
568 hbitmapMaximizeD = LoadBitmap( 0, MAKEINTRESOURCE(OBM_ZOOMD) );
569 hbitmapRestore = LoadBitmap( 0, MAKEINTRESOURCE(OBM_RESTORE) );
570 hbitmapRestoreD = LoadBitmap( 0, MAKEINTRESOURCE(OBM_RESTORED) );
571 }
572
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000573 if (wndPtr->dwExStyle & WS_EX_DLGMODALFRAME)
574 {
Alexandre Julliard58199531994-04-21 01:20:00 +0000575 HBRUSH hbrushOld = SelectObject( hdc, sysColorObjects.hbrushWindow );
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000576 PatBlt( hdc, r.left, r.top, 1, r.bottom-r.top+1,PATCOPY );
577 PatBlt( hdc, r.right-1, r.top, 1, r.bottom-r.top+1, PATCOPY );
578 PatBlt( hdc, r.left, r.top-1, r.right-r.left, 1, PATCOPY );
579 r.left++;
580 r.right--;
581 SelectObject( hdc, hbrushOld );
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000582 }
583
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +0000584 MoveTo( hdc, r.left, r.bottom );
585 LineTo( hdc, r.right-1, r.bottom );
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000586
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000587 if (style & WS_SYSMENU)
588 {
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000589 NC_DrawSysButton( hwnd, hdc, FALSE );
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +0000590 r.left += SYSMETRICS_CXSIZE + 1;
591 MoveTo( hdc, r.left - 1, r.top );
592 LineTo( hdc, r.left - 1, r.bottom );
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000593 }
594 if (style & WS_MAXIMIZEBOX)
595 {
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000596 NC_DrawMaxButton( hwnd, hdc, FALSE );
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +0000597 r.right -= SYSMETRICS_CXSIZE + 1;
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000598 }
599 if (style & WS_MINIMIZEBOX)
600 {
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000601 NC_DrawMinButton( hwnd, hdc, FALSE );
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +0000602 r.right -= SYSMETRICS_CXSIZE + 1;
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000603 }
604
Alexandre Julliard58199531994-04-21 01:20:00 +0000605 FillRect( hdc, &r, active ? sysColorObjects.hbrushActiveCaption :
606 sysColorObjects.hbrushInactiveCaption );
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000607
608 if (GetWindowText( hwnd, buffer, 256 ))
609 {
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000610 if (active) SetTextColor( hdc, GetSysColor( COLOR_CAPTIONTEXT ) );
611 else SetTextColor( hdc, GetSysColor( COLOR_INACTIVECAPTIONTEXT ) );
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000612 SetBkMode( hdc, TRANSPARENT );
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000613 DrawText( hdc, buffer, -1, &r, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000614 }
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000615}
616
617
618/***********************************************************************
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000619 * NC_DoNCPaint
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000620 *
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000621 * Paint the non-client area.
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000622 */
Alexandre Julliard18506551995-01-24 16:21:01 +0000623void NC_DoNCPaint( HWND hwnd, BOOL active, BOOL suppress_menupaint )
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000624{
625 HDC hdc;
Alexandre Julliardecc37121994-11-22 16:31:29 +0000626 RECT rect;
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000627
628 WND *wndPtr = WIN_FindWndPtr( hwnd );
629
Alexandre Julliard59730ae1996-03-24 16:20:51 +0000630 dprintf_nonclient(stddeb, "NC_DoNCPaint: %04x %d\n", hwnd, active );
Alexandre Julliard18506551995-01-24 16:21:01 +0000631 if (!wndPtr || !(wndPtr->dwStyle & WS_VISIBLE)) return; /* Nothing to do */
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000632
Alexandre Julliard18506551995-01-24 16:21:01 +0000633 if (!(hdc = GetDCEx( hwnd, 0, DCX_USESTYLE | DCX_WINDOW ))) return;
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000634
635 /*
636 * If this is an icon, we don't want to do any more nonclient painting
637 * of the window manager.
638 * If there is a class icon to draw, draw it
639 */
640 if (IsIconic(hwnd))
641 {
Alexandre Julliardaca05781994-10-17 18:12:41 +0000642 HICON hIcon = WIN_CLASS_INFO(wndPtr).hIcon;
643 if (hIcon)
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000644 {
Alexandre Julliardaf0bae51995-10-03 17:06:08 +0000645 SendMessage(hwnd, WM_ICONERASEBKGND, (WPARAM)hdc, 0);
Alexandre Julliardaca05781994-10-17 18:12:41 +0000646 DrawIcon(hdc, 0, 0, hIcon);
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000647 }
Alexandre Julliardaca05781994-10-17 18:12:41 +0000648 ReleaseDC(hwnd, hdc);
649 return;
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000650 }
651
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000652 if (ExcludeVisRect( hdc, wndPtr->rectClient.left-wndPtr->rectWindow.left,
653 wndPtr->rectClient.top-wndPtr->rectWindow.top,
654 wndPtr->rectClient.right-wndPtr->rectWindow.left,
655 wndPtr->rectClient.bottom-wndPtr->rectWindow.top )
656 == NULLREGION)
657 {
658 ReleaseDC( hwnd, hdc );
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000659 return;
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000660 }
661
662 rect.top = rect.left = 0;
663 rect.right = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
664 rect.bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
665
Alexandre Julliard58199531994-04-21 01:20:00 +0000666 SelectObject( hdc, sysColorObjects.hpenWindowFrame );
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000667
Alexandre Julliard0c126c71996-02-18 18:44:41 +0000668 if (!(wndPtr->flags & WIN_MANAGED))
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000669 {
Alexandre Julliard0c126c71996-02-18 18:44:41 +0000670 if ((wndPtr->dwStyle & WS_BORDER) || (wndPtr->dwStyle & WS_DLGFRAME) ||
671 (wndPtr->dwExStyle & WS_EX_DLGMODALFRAME))
672 {
673 MoveTo( hdc, 0, 0 );
674 LineTo( hdc, rect.right-1, 0 );
675 LineTo( hdc, rect.right-1, rect.bottom-1 );
676 LineTo( hdc, 0, rect.bottom-1 );
677 LineTo( hdc, 0, 0 );
678 InflateRect( &rect, -1, -1 );
679 }
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000680
Alexandre Julliard0c126c71996-02-18 18:44:41 +0000681 if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle ))
682 NC_DrawFrame( hdc, &rect, TRUE, active );
683 else if (wndPtr->dwStyle & WS_THICKFRAME)
684 NC_DrawFrame(hdc, &rect, FALSE, active );
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000685
Alexandre Julliard0c126c71996-02-18 18:44:41 +0000686 if ((wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION)
687 {
688 RECT r = rect;
689 r.bottom = rect.top + SYSMETRICS_CYSIZE;
690 rect.top += SYSMETRICS_CYSIZE + SYSMETRICS_CYBORDER;
691 NC_DrawCaption( hdc, &r, hwnd, wndPtr->dwStyle, active );
692 }
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000693 }
694
Alexandre Julliardf7207251994-07-23 07:57:48 +0000695 if (HAS_MENU(wndPtr))
696 {
Alexandre Julliardf7207251994-07-23 07:57:48 +0000697 RECT r = rect;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000698 r.bottom = rect.top + SYSMETRICS_CYMENU; /* default height */
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000699 rect.top += MENU_DrawMenuBar( hdc, &r, hwnd, suppress_menupaint );
Alexandre Julliardf7207251994-07-23 07:57:48 +0000700 }
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000701
Alexandre Julliardecc37121994-11-22 16:31:29 +0000702 /* Draw the scroll-bars */
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000703
Alexandre Julliardecc37121994-11-22 16:31:29 +0000704 if (wndPtr->dwStyle & WS_VSCROLL) SCROLL_DrawScrollBar(hwnd, hdc, SB_VERT);
705 if (wndPtr->dwStyle & WS_HSCROLL) SCROLL_DrawScrollBar(hwnd, hdc, SB_HORZ);
706
707 /* Draw the "size-box" */
708
709 if ((wndPtr->dwStyle & WS_VSCROLL) && (wndPtr->dwStyle & WS_HSCROLL))
710 {
711 RECT r = rect;
712 r.left = r.right - SYSMETRICS_CXVSCROLL + 1;
713 r.top = r.bottom - SYSMETRICS_CYHSCROLL + 1;
714 FillRect( hdc, &r, sysColorObjects.hbrushScrollbar );
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000715 }
716
717 ReleaseDC( hwnd, hdc );
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000718}
719
720
Alexandre Julliard988ca971994-06-21 16:15:21 +0000721
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000722/***********************************************************************
723 * NC_HandleNCPaint
724 *
725 * Handle a WM_NCPAINT message. Called from DefWindowProc().
726 */
Alexandre Julliard18506551995-01-24 16:21:01 +0000727LONG NC_HandleNCPaint( HWND hwnd )
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000728{
Alexandre Julliardd4719651995-12-12 18:49:11 +0000729 WND *wndPtr = WIN_FindWndPtr(hwnd);
730
731 NC_DoNCPaint( hwnd, wndPtr->flags & WIN_NCACTIVATED, FALSE );
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000732 return 0;
733}
734
735
736/***********************************************************************
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000737 * NC_HandleNCActivate
738 *
739 * Handle a WM_NCACTIVATE message. Called from DefWindowProc().
740 */
Alexandre Julliardaf0bae51995-10-03 17:06:08 +0000741LONG NC_HandleNCActivate( HWND hwnd, WPARAM wParam )
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000742{
Alexandre Julliardd4719651995-12-12 18:49:11 +0000743 WND *wndPtr = WIN_FindWndPtr(hwnd);
744
745 if (wParam != 0) wndPtr->flags |= WIN_NCACTIVATED;
746 else wndPtr->flags &= ~WIN_NCACTIVATED;
747
Alexandre Julliardaf0bae51995-10-03 17:06:08 +0000748 NC_DoNCPaint( hwnd, (wParam != 0), FALSE );
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000749 return TRUE;
750}
751
752
753/***********************************************************************
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000754 * NC_HandleSetCursor
755 *
756 * Handle a WM_SETCURSOR message. Called from DefWindowProc().
757 */
Alexandre Julliardaf0bae51995-10-03 17:06:08 +0000758LONG NC_HandleSetCursor( HWND hwnd, WPARAM wParam, LPARAM lParam )
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000759{
Alexandre Julliardaf0bae51995-10-03 17:06:08 +0000760 if (hwnd != (HWND)wParam) return 0; /* Don't set the cursor for child windows */
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000761
762 switch(LOWORD(lParam))
763 {
764 case HTERROR:
765 {
766 WORD msg = HIWORD( lParam );
767 if ((msg == WM_LBUTTONDOWN) || (msg == WM_MBUTTONDOWN) ||
768 (msg == WM_RBUTTONDOWN))
769 MessageBeep(0);
770 }
771 break;
772
773 case HTCLIENT:
774 {
775 WND *wndPtr;
776 CLASS *classPtr;
777 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) break;
778 if (!(classPtr = CLASS_FindClassPtr( wndPtr->hClass ))) break;
779 if (classPtr->wc.hCursor)
780 {
Alexandre Julliardaca05781994-10-17 18:12:41 +0000781 SetCursor( classPtr->wc.hCursor );
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000782 return TRUE;
783 }
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000784 else return FALSE;
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000785 }
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000786
787 case HTLEFT:
788 case HTRIGHT:
Alexandre Julliardaf0bae51995-10-03 17:06:08 +0000789 return (LONG)SetCursor( LoadCursor( 0, IDC_SIZEWE ) );
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000790
791 case HTTOP:
792 case HTBOTTOM:
Alexandre Julliardaf0bae51995-10-03 17:06:08 +0000793 return (LONG)SetCursor( LoadCursor( 0, IDC_SIZENS ) );
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000794
795 case HTTOPLEFT:
796 case HTBOTTOMRIGHT:
Alexandre Julliardaf0bae51995-10-03 17:06:08 +0000797 return (LONG)SetCursor( LoadCursor( 0, IDC_SIZENWSE ) );
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000798
799 case HTTOPRIGHT:
800 case HTBOTTOMLEFT:
Alexandre Julliardaf0bae51995-10-03 17:06:08 +0000801 return (LONG)SetCursor( LoadCursor( 0, IDC_SIZENESW ) );
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000802 }
803
804 /* Default cursor: arrow */
Alexandre Julliardaf0bae51995-10-03 17:06:08 +0000805 return (LONG)SetCursor( LoadCursor( 0, IDC_ARROW ) );
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000806}
807
808
809/***********************************************************************
Alexandre Julliard7d654eb1996-02-25 11:36:22 +0000810 * NC_TrackSysMenu
811 *
812 * Track a mouse button press on the system menu.
813 */
814static void NC_TrackSysMenu( HWND hwnd, HDC hdc, POINT pt )
815{
816 RECT rect;
817 WND *wndPtr = WIN_FindWndPtr( hwnd );
818 int iconic = wndPtr->dwStyle & WS_MINIMIZE;
819
820 if (!(wndPtr->dwStyle & WS_SYSMENU)) return;
821 /* If window has a menu, track the menu bar normally if it not minimized */
822 if (HAS_MENU(wndPtr) && !iconic) MENU_TrackMouseMenuBar( hwnd, pt );
823 else
824 {
825 /* Otherwise track the system menu like a normal popup menu */
826 NC_GetInsideRect( hwnd, &rect );
827 OffsetRect( &rect, wndPtr->rectWindow.left, wndPtr->rectWindow.top );
828 if (wndPtr->dwStyle & WS_CHILD)
Alexandre Julliard59730ae1996-03-24 16:20:51 +0000829 ClientToScreen( wndPtr->parent->hwndSelf, (POINT *)&rect );
Alexandre Julliard7d654eb1996-02-25 11:36:22 +0000830 rect.right = rect.left + SYSMETRICS_CXSIZE;
831 rect.bottom = rect.top + SYSMETRICS_CYSIZE;
832 if (!iconic) NC_DrawSysButton( hwnd, hdc, TRUE );
833 TrackPopupMenu( wndPtr->hSysMenu, TPM_LEFTALIGN | TPM_LEFTBUTTON,
834 rect.left, rect.bottom, 0, hwnd, &rect );
835 if (!iconic) NC_DrawSysButton( hwnd, hdc, FALSE );
836 }
837}
838
839
840/***********************************************************************
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000841 * NC_StartSizeMove
842 *
843 * Initialisation of a move or resize, when initiatied from a menu choice.
844 * Return hit test code for caption or sizing border.
845 */
Alexandre Julliardaf0bae51995-10-03 17:06:08 +0000846static LONG NC_StartSizeMove( HWND hwnd, WPARAM wParam, POINT *capturePoint )
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000847{
848 LONG hittest = 0;
849 POINT pt;
850 MSG msg;
851 WND * wndPtr = WIN_FindWndPtr( hwnd );
852
853 if ((wParam & 0xfff0) == SC_MOVE)
854 {
855 /* Move pointer at the center of the caption */
856 RECT rect;
857 NC_GetInsideRect( hwnd, &rect );
858 if (wndPtr->dwStyle & WS_SYSMENU)
859 rect.left += SYSMETRICS_CXSIZE + 1;
860 if (wndPtr->dwStyle & WS_MINIMIZEBOX)
861 rect.right -= SYSMETRICS_CXSIZE + 1;
862 if (wndPtr->dwStyle & WS_MAXIMIZEBOX)
863 rect.right -= SYSMETRICS_CXSIZE + 1;
864 pt.x = wndPtr->rectWindow.left + (rect.right - rect.left) / 2;
865 pt.y = wndPtr->rectWindow.top + rect.top + SYSMETRICS_CYSIZE/2;
866 if (wndPtr->dwStyle & WS_CHILD)
Alexandre Julliard59730ae1996-03-24 16:20:51 +0000867 ClientToScreen( wndPtr->parent->hwndSelf, &pt );
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000868 hittest = HTCAPTION;
869 }
870 else /* SC_SIZE */
871 {
872 SetCapture(hwnd);
873 while(!hittest)
874 {
875 MSG_GetHardwareMessage( &msg );
876 switch(msg.message)
877 {
878 case WM_MOUSEMOVE:
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000879 hittest = NC_HandleNCHitTest( hwnd, msg.pt );
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000880 pt = msg.pt;
881 if ((hittest < HTLEFT) || (hittest > HTBOTTOMRIGHT))
882 hittest = 0;
883 break;
884
885 case WM_LBUTTONUP:
886 return 0;
887
888 case WM_KEYDOWN:
889 switch(msg.wParam)
890 {
891 case VK_UP:
892 hittest = HTTOP;
893 pt.x =(wndPtr->rectWindow.left+wndPtr->rectWindow.right)/2;
894 pt.y = wndPtr->rectWindow.top + SYSMETRICS_CYFRAME / 2;
895 break;
896 case VK_DOWN:
897 hittest = HTBOTTOM;
898 pt.x =(wndPtr->rectWindow.left+wndPtr->rectWindow.right)/2;
899 pt.y = wndPtr->rectWindow.bottom - SYSMETRICS_CYFRAME / 2;
900 break;
901 case VK_LEFT:
902 hittest = HTLEFT;
903 pt.x = wndPtr->rectWindow.left + SYSMETRICS_CXFRAME / 2;
904 pt.y =(wndPtr->rectWindow.top+wndPtr->rectWindow.bottom)/2;
905 break;
906 case VK_RIGHT:
907 hittest = HTRIGHT;
908 pt.x = wndPtr->rectWindow.right - SYSMETRICS_CXFRAME / 2;
909 pt.y =(wndPtr->rectWindow.top+wndPtr->rectWindow.bottom)/2;
910 break;
911 case VK_RETURN:
912 case VK_ESCAPE: return 0;
913 }
914 }
915 }
916 }
917 *capturePoint = pt;
918 SetCursorPos( capturePoint->x, capturePoint->y );
Alexandre Julliardd7d4fdf1995-12-26 15:05:24 +0000919 NC_HandleSetCursor( hwnd, (WPARAM)hwnd, MAKELONG( hittest, WM_MOUSEMOVE ));
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000920 return hittest;
921}
922
923
924/***********************************************************************
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000925 * NC_DoSizeMove
926 *
927 * Perform SC_MOVE and SC_SIZE commands.
928 */
929static void NC_DoSizeMove( HWND hwnd, WORD wParam, POINT pt )
930{
931 MSG msg;
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000932 LONG hittest;
933 RECT sizingRect, mouseRect;
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000934 HDC hdc;
935 BOOL thickframe;
936 POINT minTrack, maxTrack, capturePoint = pt;
937 WND * wndPtr = WIN_FindWndPtr( hwnd );
Alexandre Julliard7d654eb1996-02-25 11:36:22 +0000938 int moved = 0;
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000939
Alexandre Julliard0c126c71996-02-18 18:44:41 +0000940 if (IsZoomed(hwnd) || !IsWindowVisible(hwnd) ||
941 (wndPtr->flags & WIN_MANAGED)) return;
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000942 hittest = wParam & 0x0f;
943 thickframe = HAS_THICKFRAME( wndPtr->dwStyle );
944
945 if ((wParam & 0xfff0) == SC_MOVE)
946 {
947 if (!(wndPtr->dwStyle & WS_CAPTION)) return;
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000948 if (!hittest) hittest = NC_StartSizeMove( hwnd, wParam, &capturePoint );
949 if (!hittest) return;
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000950 }
951 else /* SC_SIZE */
952 {
953 if (!thickframe) return;
954 if (hittest) hittest += HTLEFT-1;
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000955 else
956 {
957 SetCapture(hwnd);
958 hittest = NC_StartSizeMove( hwnd, wParam, &capturePoint );
959 if (!hittest)
960 {
961 ReleaseCapture();
962 return;
963 }
964 }
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000965 }
966
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000967 /* Get min/max info */
968
Alexandre Julliard22945d51995-03-02 17:44:29 +0000969 NC_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack );
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000970 sizingRect = wndPtr->rectWindow;
971 if (wndPtr->dwStyle & WS_CHILD)
Alexandre Julliard59730ae1996-03-24 16:20:51 +0000972 GetClientRect( wndPtr->parent->hwndSelf, &mouseRect );
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000973 else SetRect( &mouseRect, 0, 0, SYSMETRICS_CXSCREEN, SYSMETRICS_CYSCREEN );
974 if (ON_LEFT_BORDER(hittest))
975 {
Alexandre Julliard902da691995-11-05 14:39:02 +0000976 mouseRect.left = MAX( mouseRect.left, sizingRect.right-maxTrack.x );
977 mouseRect.right = MIN( mouseRect.right, sizingRect.right-minTrack.x );
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000978 }
979 else if (ON_RIGHT_BORDER(hittest))
980 {
Alexandre Julliard902da691995-11-05 14:39:02 +0000981 mouseRect.left = MAX( mouseRect.left, sizingRect.left+minTrack.x );
982 mouseRect.right = MIN( mouseRect.right, sizingRect.left+maxTrack.x );
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000983 }
984 if (ON_TOP_BORDER(hittest))
985 {
Alexandre Julliard902da691995-11-05 14:39:02 +0000986 mouseRect.top = MAX( mouseRect.top, sizingRect.bottom-maxTrack.y );
987 mouseRect.bottom = MIN( mouseRect.bottom,sizingRect.bottom-minTrack.y);
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000988 }
989 else if (ON_BOTTOM_BORDER(hittest))
990 {
Alexandre Julliard902da691995-11-05 14:39:02 +0000991 mouseRect.top = MAX( mouseRect.top, sizingRect.top+minTrack.y );
992 mouseRect.bottom = MIN( mouseRect.bottom, sizingRect.top+maxTrack.y );
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000993 }
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000994 SendMessage( hwnd, WM_ENTERSIZEMOVE, 0, 0 );
995
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000996 if (GetCapture() != hwnd) SetCapture( hwnd );
997
Alexandre Julliard3ed37e01994-11-07 18:20:42 +0000998 if (wndPtr->dwStyle & WS_CHILD)
999 {
1000 /* Retrieve a default cache DC (without using the window style) */
Alexandre Julliard59730ae1996-03-24 16:20:51 +00001001 hdc = GetDCEx( wndPtr->parent->hwndSelf, 0, DCX_CACHE );
Alexandre Julliard3ed37e01994-11-07 18:20:42 +00001002 }
Alexandre Julliarddba420a1994-02-02 06:48:31 +00001003 else
Alexandre Julliard8d24ae61994-04-05 21:42:43 +00001004 { /* Grab the server only when moving top-level windows without desktop */
Alexandre Julliarddba420a1994-02-02 06:48:31 +00001005 hdc = GetDC( 0 );
Alexandre Julliard8d24ae61994-04-05 21:42:43 +00001006 if (rootWindow == DefaultRootWindow(display)) XGrabServer( display );
Alexandre Julliarddba420a1994-02-02 06:48:31 +00001007 }
Alexandre Julliarddba420a1994-02-02 06:48:31 +00001008 NC_DrawMovingFrame( hdc, &sizingRect, thickframe );
1009
1010 while(1)
1011 {
Alexandre Julliard7d654eb1996-02-25 11:36:22 +00001012 int dx = 0, dy = 0;
Alexandre Julliarddba420a1994-02-02 06:48:31 +00001013
1014 MSG_GetHardwareMessage( &msg );
1015
1016 /* Exit on button-up, Return, or Esc */
1017 if ((msg.message == WM_LBUTTONUP) ||
1018 ((msg.message == WM_KEYDOWN) &&
1019 ((msg.wParam == VK_RETURN) || (msg.wParam == VK_ESCAPE)))) break;
1020
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00001021 if ((msg.message != WM_KEYDOWN) && (msg.message != WM_MOUSEMOVE))
1022 continue; /* We are not interested in other messages */
1023
1024 pt = msg.pt;
Alexandre Julliarddba420a1994-02-02 06:48:31 +00001025 if (wndPtr->dwStyle & WS_CHILD)
Alexandre Julliard59730ae1996-03-24 16:20:51 +00001026 ScreenToClient( wndPtr->parent->hwndSelf, &pt );
Alexandre Julliarddba420a1994-02-02 06:48:31 +00001027
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00001028
1029 if (msg.message == WM_KEYDOWN) switch(msg.wParam)
Alexandre Julliarddba420a1994-02-02 06:48:31 +00001030 {
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00001031 case VK_UP: pt.y -= 8; break;
1032 case VK_DOWN: pt.y += 8; break;
1033 case VK_LEFT: pt.x -= 8; break;
1034 case VK_RIGHT: pt.x += 8; break;
1035 }
Alexandre Julliarddba420a1994-02-02 06:48:31 +00001036
Alexandre Julliard902da691995-11-05 14:39:02 +00001037 pt.x = MAX( pt.x, mouseRect.left );
1038 pt.x = MIN( pt.x, mouseRect.right );
1039 pt.y = MAX( pt.y, mouseRect.top );
1040 pt.y = MIN( pt.y, mouseRect.bottom );
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00001041
1042 dx = pt.x - capturePoint.x;
1043 dy = pt.y - capturePoint.y;
Alexandre Julliarddba420a1994-02-02 06:48:31 +00001044
1045 if (dx || dy)
1046 {
Alexandre Julliard7d654eb1996-02-25 11:36:22 +00001047 moved = 1;
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00001048 if (msg.message == WM_KEYDOWN) SetCursorPos( pt.x, pt.y );
1049 else
Alexandre Julliarddba420a1994-02-02 06:48:31 +00001050 {
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00001051 RECT newRect = sizingRect;
1052
1053 if (hittest == HTCAPTION) OffsetRect( &newRect, dx, dy );
1054 if (ON_LEFT_BORDER(hittest)) newRect.left += dx;
1055 else if (ON_RIGHT_BORDER(hittest)) newRect.right += dx;
1056 if (ON_TOP_BORDER(hittest)) newRect.top += dy;
1057 else if (ON_BOTTOM_BORDER(hittest)) newRect.bottom += dy;
1058 NC_DrawMovingFrame( hdc, &sizingRect, thickframe );
1059 NC_DrawMovingFrame( hdc, &newRect, thickframe );
1060 capturePoint = pt;
1061 sizingRect = newRect;
1062 }
Alexandre Julliarddba420a1994-02-02 06:48:31 +00001063 }
1064 }
1065
1066 NC_DrawMovingFrame( hdc, &sizingRect, thickframe );
1067 ReleaseCapture();
Alexandre Julliard7d654eb1996-02-25 11:36:22 +00001068
Alexandre Julliard59730ae1996-03-24 16:20:51 +00001069 if (wndPtr->dwStyle & WS_CHILD) ReleaseDC( wndPtr->parent->hwndSelf, hdc );
Alexandre Julliarddba420a1994-02-02 06:48:31 +00001070 else
1071 {
1072 ReleaseDC( 0, hdc );
Alexandre Julliard8d24ae61994-04-05 21:42:43 +00001073 if (rootWindow == DefaultRootWindow(display)) XUngrabServer( display );
Alexandre Julliarddba420a1994-02-02 06:48:31 +00001074 }
1075 SendMessage( hwnd, WM_EXITSIZEMOVE, 0, 0 );
Alexandre Julliardd4719651995-12-12 18:49:11 +00001076 SendMessage( hwnd, WM_SETVISIBLE, !IsIconic(hwnd), 0L);
Alexandre Julliarddba420a1994-02-02 06:48:31 +00001077
Alexandre Julliardd2e1c1a1996-03-09 16:12:43 +00001078 /* Single click brings up the system menu when iconized */
Alexandre Julliard7d654eb1996-02-25 11:36:22 +00001079
Alexandre Julliardd2e1c1a1996-03-09 16:12:43 +00001080 if (!moved && (wndPtr->dwStyle & WS_MINIMIZE))
Alexandre Julliard7d654eb1996-02-25 11:36:22 +00001081 {
1082 NC_TrackSysMenu( hwnd, hdc, pt );
1083 return;
1084 }
1085
Alexandre Julliarddba420a1994-02-02 06:48:31 +00001086 /* If Esc key, don't move the window */
1087 if ((msg.message == WM_KEYDOWN) && (msg.wParam == VK_ESCAPE)) return;
1088
1089 if (hittest != HTCAPTION)
1090 SetWindowPos( hwnd, 0, sizingRect.left, sizingRect.top,
1091 sizingRect.right - sizingRect.left,
1092 sizingRect.bottom - sizingRect.top,
1093 SWP_NOACTIVATE | SWP_NOZORDER );
1094 else SetWindowPos( hwnd, 0, sizingRect.left, sizingRect.top, 0, 0,
1095 SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER );
1096}
1097
1098
1099/***********************************************************************
1100 * NC_TrackMinMaxBox
1101 *
1102 * Track a mouse button press on the minimize or maximize box.
1103 */
1104static void NC_TrackMinMaxBox( HWND hwnd, WORD wParam )
1105{
1106 MSG msg;
1107 HDC hdc = GetWindowDC( hwnd );
1108 BOOL pressed = TRUE;
1109
1110 SetCapture( hwnd );
1111 if (wParam == HTMINBUTTON) NC_DrawMinButton( hwnd, hdc, TRUE );
1112 else NC_DrawMaxButton( hwnd, hdc, TRUE );
1113
1114 do
1115 {
1116 BOOL oldstate = pressed;
1117 MSG_GetHardwareMessage( &msg );
1118
Alexandre Julliard940d58c1994-09-16 09:24:37 +00001119 pressed = (NC_HandleNCHitTest( hwnd, msg.pt ) == wParam);
Alexandre Julliarddba420a1994-02-02 06:48:31 +00001120 if (pressed != oldstate)
1121 {
1122 if (wParam == HTMINBUTTON) NC_DrawMinButton( hwnd, hdc, pressed );
1123 else NC_DrawMaxButton( hwnd, hdc, pressed );
1124 }
1125 } while (msg.message != WM_LBUTTONUP);
1126
1127 if (wParam == HTMINBUTTON) NC_DrawMinButton( hwnd, hdc, FALSE );
1128 else NC_DrawMaxButton( hwnd, hdc, FALSE );
1129
1130 ReleaseCapture();
1131 ReleaseDC( hwnd, hdc );
1132 if (!pressed) return;
1133
1134 if (wParam == HTMINBUTTON)
1135 SendMessage( hwnd, WM_SYSCOMMAND, SC_MINIMIZE, *(LONG*)&msg.pt );
1136 else
1137 SendMessage( hwnd, WM_SYSCOMMAND,
1138 IsZoomed(hwnd) ? SC_RESTORE : SC_MAXIMIZE, *(LONG*)&msg.pt );
1139}
1140
1141
1142/***********************************************************************
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00001143 * NC_TrackScrollBar
1144 *
1145 * Track a mouse button press on the horizontal or vertical scroll-bar.
1146 */
1147static void NC_TrackScrollBar( HWND hwnd, WORD wParam, POINT pt )
1148{
Alexandre Julliardd4719651995-12-12 18:49:11 +00001149 MSG msg;
Alexandre Julliardecc37121994-11-22 16:31:29 +00001150 WORD scrollbar;
1151 WND *wndPtr = WIN_FindWndPtr( hwnd );
1152
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00001153 if ((wParam & 0xfff0) == SC_HSCROLL)
1154 {
1155 if ((wParam & 0x0f) != HTHSCROLL) return;
1156 scrollbar = SB_HORZ;
1157 }
1158 else /* SC_VSCROLL */
1159 {
1160 if ((wParam & 0x0f) != HTVSCROLL) return;
1161 scrollbar = SB_VERT;
1162 }
1163
Alexandre Julliardecc37121994-11-22 16:31:29 +00001164 pt.x -= wndPtr->rectWindow.left;
1165 pt.y -= wndPtr->rectWindow.top;
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00001166 SetCapture( hwnd );
Alexandre Julliardecc37121994-11-22 16:31:29 +00001167 SCROLL_HandleScrollEvent( hwnd, scrollbar, WM_LBUTTONDOWN, pt );
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00001168
1169 do
1170 {
Alexandre Julliardd4719651995-12-12 18:49:11 +00001171 GetMessage( MAKE_SEGPTR(&msg), 0, 0, 0 );
1172 switch(msg.message)
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00001173 {
1174 case WM_LBUTTONUP:
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00001175 case WM_MOUSEMOVE:
Alexandre Julliardecc37121994-11-22 16:31:29 +00001176 case WM_SYSTIMER:
Alexandre Julliardd4719651995-12-12 18:49:11 +00001177 pt.x = LOWORD(msg.lParam) + wndPtr->rectClient.left -
Alexandre Julliard902da691995-11-05 14:39:02 +00001178 wndPtr->rectWindow.left;
Alexandre Julliardd4719651995-12-12 18:49:11 +00001179 pt.y = HIWORD(msg.lParam) + wndPtr->rectClient.top -
Alexandre Julliard902da691995-11-05 14:39:02 +00001180 wndPtr->rectWindow.top;
Alexandre Julliardd4719651995-12-12 18:49:11 +00001181 SCROLL_HandleScrollEvent( hwnd, scrollbar, msg.message, pt );
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00001182 break;
Alexandre Julliardecc37121994-11-22 16:31:29 +00001183 default:
Alexandre Julliardd4719651995-12-12 18:49:11 +00001184 TranslateMessage( &msg );
1185 DispatchMessage( &msg );
Alexandre Julliardecc37121994-11-22 16:31:29 +00001186 break;
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00001187 }
Alexandre Julliardecc37121994-11-22 16:31:29 +00001188 if (!IsWindow( hwnd ))
1189 {
1190 ReleaseCapture();
1191 break;
1192 }
Alexandre Julliardd4719651995-12-12 18:49:11 +00001193 } while (msg.message != WM_LBUTTONUP);
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00001194}
1195
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00001196/***********************************************************************
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +00001197 * NC_HandleNCLButtonDown
Alexandre Julliardcdd09231994-01-12 11:12:51 +00001198 *
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +00001199 * Handle a WM_NCLBUTTONDOWN message. Called from DefWindowProc().
Alexandre Julliardcdd09231994-01-12 11:12:51 +00001200 */
Alexandre Julliardaf0bae51995-10-03 17:06:08 +00001201LONG NC_HandleNCLButtonDown( HWND hwnd, WPARAM wParam, LPARAM lParam )
Alexandre Julliardcdd09231994-01-12 11:12:51 +00001202{
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +00001203 HDC hdc = GetWindowDC( hwnd );
Alexandre Julliard902da691995-11-05 14:39:02 +00001204 POINT pt = { LOWORD(lParam), HIWORD(lParam) };
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +00001205
1206 switch(wParam) /* Hit test */
Alexandre Julliardcdd09231994-01-12 11:12:51 +00001207 {
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +00001208 case HTCAPTION:
Alexandre Julliarddba420a1994-02-02 06:48:31 +00001209 SendMessage( hwnd, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, lParam );
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +00001210 break;
1211
Alexandre Julliardcdd09231994-01-12 11:12:51 +00001212 case HTSYSMENU:
Alexandre Julliard902da691995-11-05 14:39:02 +00001213 NC_TrackSysMenu( hwnd, hdc, pt );
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +00001214 break;
1215
1216 case HTMENU:
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00001217 SendMessage( hwnd, WM_SYSCOMMAND, SC_MOUSEMENU, lParam );
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +00001218 break;
1219
1220 case HTHSCROLL:
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00001221 SendMessage( hwnd, WM_SYSCOMMAND, SC_HSCROLL + HTHSCROLL, lParam );
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +00001222 break;
1223
1224 case HTVSCROLL:
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00001225 SendMessage( hwnd, WM_SYSCOMMAND, SC_VSCROLL + HTVSCROLL, lParam );
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +00001226 break;
1227
1228 case HTMINBUTTON:
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +00001229 case HTMAXBUTTON:
Alexandre Julliarddba420a1994-02-02 06:48:31 +00001230 NC_TrackMinMaxBox( hwnd, wParam );
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +00001231 break;
1232
1233 case HTLEFT:
1234 case HTRIGHT:
1235 case HTTOP:
1236 case HTTOPLEFT:
1237 case HTTOPRIGHT:
1238 case HTBOTTOM:
1239 case HTBOTTOMLEFT:
1240 case HTBOTTOMRIGHT:
Alexandre Julliarddba420a1994-02-02 06:48:31 +00001241 SendMessage( hwnd, WM_SYSCOMMAND, SC_SIZE + wParam - HTLEFT+1, lParam);
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +00001242 break;
1243
1244 case HTBORDER:
1245 break;
1246 }
1247
1248 ReleaseDC( hwnd, hdc );
1249 return 0;
1250}
1251
1252
1253/***********************************************************************
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +00001254 * NC_HandleNCLButtonDblClk
1255 *
1256 * Handle a WM_NCLBUTTONDBLCLK message. Called from DefWindowProc().
1257 */
Alexandre Julliardaf0bae51995-10-03 17:06:08 +00001258LONG NC_HandleNCLButtonDblClk( HWND hwnd, WPARAM wParam, LPARAM lParam )
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +00001259{
Alexandre Julliard940d58c1994-09-16 09:24:37 +00001260 /*
1261 * if this is an icon, send a restore since we are handling
1262 * a double click
1263 */
1264 if (IsIconic(hwnd))
1265 {
1266 SendMessage(hwnd, WM_SYSCOMMAND, SC_RESTORE, lParam);
1267 return 0;
1268 }
1269
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +00001270 switch(wParam) /* Hit test */
1271 {
1272 case HTCAPTION:
Alexandre Julliard902da691995-11-05 14:39:02 +00001273 /* stop processing if WS_MAXIMIZEBOX is missing */
1274
1275 if( GetWindowLong( hwnd , GWL_STYLE) & WS_MAXIMIZEBOX )
1276 SendMessage( hwnd, WM_SYSCOMMAND,
1277 IsZoomed(hwnd) ? SC_RESTORE : SC_MAXIMIZE, lParam );
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +00001278 break;
1279
1280 case HTSYSMENU:
1281 SendMessage( hwnd, WM_SYSCOMMAND, SC_CLOSE, lParam );
Alexandre Julliardcdd09231994-01-12 11:12:51 +00001282 break;
1283 }
1284 return 0;
1285}
1286
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +00001287
1288/***********************************************************************
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +00001289 * NC_HandleSysCommand
1290 *
1291 * Handle a WM_SYSCOMMAND message. Called from DefWindowProc().
1292 */
Alexandre Julliardaf0bae51995-10-03 17:06:08 +00001293LONG NC_HandleSysCommand( HWND hwnd, WPARAM wParam, POINT pt )
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +00001294{
1295 WND *wndPtr = WIN_FindWndPtr( hwnd );
1296
Alexandre Julliard59730ae1996-03-24 16:20:51 +00001297 dprintf_nonclient(stddeb, "Handling WM_SYSCOMMAND %x %d,%d\n",
1298 wParam, pt.x, pt.y );
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +00001299
Alexandre Julliard59730ae1996-03-24 16:20:51 +00001300 if (wndPtr->dwStyle & WS_CHILD)
1301 ScreenToClient( wndPtr->parent->hwndSelf, &pt );
Alexandre Julliarddba420a1994-02-02 06:48:31 +00001302
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +00001303 switch (wParam & 0xfff0)
1304 {
1305 case SC_SIZE:
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +00001306 case SC_MOVE:
Alexandre Julliarddba420a1994-02-02 06:48:31 +00001307 NC_DoSizeMove( hwnd, wParam, pt );
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +00001308 break;
1309
1310 case SC_MINIMIZE:
Alexandre Julliard940d58c1994-09-16 09:24:37 +00001311 ShowWindow( hwnd, SW_MINIMIZE );
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +00001312 break;
1313
1314 case SC_MAXIMIZE:
1315 ShowWindow( hwnd, SW_MAXIMIZE );
1316 break;
1317
1318 case SC_RESTORE:
1319 ShowWindow( hwnd, SW_RESTORE );
1320 break;
1321
1322 case SC_NEXTWINDOW:
1323 case SC_PREVWINDOW:
1324 break;
1325
1326 case SC_CLOSE:
1327 return SendMessage( hwnd, WM_CLOSE, 0, 0 );
1328
1329 case SC_VSCROLL:
1330 case SC_HSCROLL:
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00001331 NC_TrackScrollBar( hwnd, wParam, pt );
Alexandre Julliarddba420a1994-02-02 06:48:31 +00001332 break;
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00001333
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +00001334 case SC_MOUSEMENU:
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001335 MENU_TrackMouseMenuBar( hwnd, pt );
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00001336 break;
1337
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +00001338 case SC_KEYMENU:
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001339 MENU_TrackKbdMenuBar( hwnd, wParam );
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00001340 break;
1341
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +00001342 case SC_ARRANGE:
1343 break;
1344
1345 case SC_TASKLIST:
Alexandre Julliard2787be81995-05-22 18:23:01 +00001346 WinExec( "taskman.exe", SW_SHOWNORMAL );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001347 break;
1348
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +00001349 case SC_HOTKEY:
1350 break;
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001351
1352 case SC_SCREENSAVE:
1353 if (wParam == SC_ABOUTWINE)
Alexandre Julliard2787be81995-05-22 18:23:01 +00001354 {
1355 extern const char people[];
1356 ShellAbout(hwnd,"WINE",people,0);
Alexandre Julliard3ed37e01994-11-07 18:20:42 +00001357 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001358 break;
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +00001359 }
1360 return 0;
1361}