Avoid most references to the internals of the WND structure by passing
[wine.git] / dlls / x11drv / winpos.c
blobad3dedff1061cb7772c96e9234d6eca4b0fde76c
1 /*
2 * Window position related functions.
4 * Copyright 1993, 1994, 1995, 2001 Alexandre Julliard
5 * Copyright 1995, 1996, 1999 Alex Korobka
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "config.h"
24 #include <X11/Xlib.h>
25 #ifdef HAVE_LIBXSHAPE
26 #include <X11/IntrinsicP.h>
27 #include <X11/extensions/shape.h>
28 #endif /* HAVE_LIBXSHAPE */
29 #include <stdarg.h>
31 #include "windef.h"
32 #include "winbase.h"
33 #include "wingdi.h"
34 #include "winuser.h"
35 #include "winerror.h"
36 #include "ntstatus.h"
37 #include "wownt32.h"
38 #include "wine/wingdi16.h"
40 #include "x11drv.h"
41 #include "win.h"
42 #include "winpos.h"
43 #include "dce.h"
44 #include "nonclient.h"
46 #include "wine/server.h"
47 #include "wine/debug.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
51 #define SWP_AGG_NOGEOMETRYCHANGE \
52 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE)
53 #define SWP_AGG_NOPOSCHANGE \
54 (SWP_AGG_NOGEOMETRYCHANGE | SWP_NOZORDER)
55 #define SWP_AGG_STATUSFLAGS \
56 (SWP_AGG_NOPOSCHANGE | SWP_FRAMECHANGED | SWP_HIDEWINDOW | SWP_SHOWWINDOW)
58 #define SWP_EX_NOCOPY 0x0001
59 #define SWP_EX_PAINTSELF 0x0002
60 #define SWP_EX_NONCLIENT 0x0004
62 #define HAS_THICKFRAME(style,exStyle) \
63 (((style) & WS_THICKFRAME) && \
64 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
66 #define ON_LEFT_BORDER(hit) \
67 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
68 #define ON_RIGHT_BORDER(hit) \
69 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
70 #define ON_TOP_BORDER(hit) \
71 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
72 #define ON_BOTTOM_BORDER(hit) \
73 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
75 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
76 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
77 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
78 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
79 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
80 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
81 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
82 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
83 #define _NET_WM_MOVERESIZE_MOVE 8 /* movement only */
84 #define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9 /* size via keyboard */
85 #define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10 /* move via keyboard */
88 /***********************************************************************
89 * get_server_visible_region
91 static HRGN get_server_visible_region( HWND hwnd, HWND top, UINT flags )
93 RGNDATA *data;
94 NTSTATUS status;
95 HRGN ret = 0;
96 size_t size = 256;
100 if (!(data = HeapAlloc( GetProcessHeap(), 0, sizeof(*data) + size - 1 ))) return 0;
101 SERVER_START_REQ( get_visible_region )
103 req->window = hwnd;
104 req->top_win = top;
105 req->flags = flags;
106 wine_server_set_reply( req, data->Buffer, size );
107 if (!(status = wine_server_call( req )))
109 size_t reply_size = wine_server_reply_size( reply );
110 data->rdh.dwSize = sizeof(data->rdh);
111 data->rdh.iType = RDH_RECTANGLES;
112 data->rdh.nCount = reply_size / sizeof(RECT);
113 data->rdh.nRgnSize = reply_size;
114 ret = ExtCreateRegion( NULL, size, data );
116 else size = reply->total_size;
118 SERVER_END_REQ;
119 HeapFree( GetProcessHeap(), 0, data );
120 } while (status == STATUS_BUFFER_OVERFLOW);
122 if (status) SetLastError( RtlNtStatusToDosError(status) );
123 return ret;
127 /***********************************************************************
128 * get_top_clipping_window
130 * Get the top window to clip against (i.e. the top parent that has
131 * an associated X window).
133 static HWND get_top_clipping_window( HWND hwnd )
135 HWND ret = 0;
137 if (!using_wine_desktop) ret = GetAncestor( hwnd, GA_ROOT );
138 if (!ret) ret = GetDesktopWindow();
139 return ret;
143 /***********************************************************************
144 * expose_window
146 * Expose a region of a given window.
148 static void expose_window( HWND hwnd, RECT *rect, HRGN rgn, int flags )
150 POINT offset;
151 HWND top = 0;
152 HWND *list;
153 int i;
155 /* find the top most parent that doesn't clip children or siblings and
156 * invalidate the area on its parent, including all children */
157 if ((list = WIN_ListParents( hwnd )))
159 HWND current = hwnd;
160 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
161 for (i = 0; list[i] && list[i] != GetDesktopWindow(); i++)
163 if (!(style & WS_CLIPSIBLINGS)) top = current;
164 style = GetWindowLongW( list[i], GWL_STYLE );
165 if (!(style & WS_CLIPCHILDREN)) top = current;
166 current = list[i];
169 if (top)
171 /* find the parent of the top window, reusing the parent list */
172 if (top == hwnd) i = 0;
173 else
175 for (i = 0; list[i]; i++) if (list[i] == top) break;
176 if (list[i] && list[i+1]) i++;
178 if (list[i] != GetDesktopWindow()) top = list[i];
179 flags &= ~RDW_FRAME; /* parent will invalidate children frame anyway */
180 flags |= RDW_ALLCHILDREN;
182 HeapFree( GetProcessHeap(), 0, list );
185 if (!top) top = hwnd;
187 /* make coords relative to top */
188 offset.x = offset.y = 0;
189 MapWindowPoints( hwnd, top, &offset, 1 );
191 if (rect)
193 OffsetRect( rect, offset.x, offset.y );
194 RedrawWindow( top, rect, 0, flags );
196 else
198 OffsetRgn( rgn, offset.x, offset.y );
199 RedrawWindow( top, NULL, rgn, flags );
204 /***********************************************************************
205 * X11DRV_Expose
207 void X11DRV_Expose( HWND hwnd, XExposeEvent *event )
209 RECT rect;
210 struct x11drv_win_data *data;
211 int flags = RDW_INVALIDATE | RDW_ERASE;
213 TRACE( "win %p (%lx) %d,%d %dx%d\n",
214 hwnd, event->window, event->x, event->y, event->width, event->height );
216 if (!(data = X11DRV_get_win_data( hwnd ))) return;
218 rect.left = event->x;
219 rect.top = event->y;
220 rect.right = rect.left + event->width;
221 rect.bottom = rect.top + event->height;
223 if (event->window != data->client_window) /* whole window or icon window */
225 flags |= RDW_FRAME;
226 /* make position relative to client area instead of window */
227 OffsetRect( &rect, -data->client_rect.left, -data->client_rect.top );
230 expose_window( hwnd, &rect, 0, flags );
234 /***********************************************************************
235 * GetDC (X11DRV.@)
237 * Set the drawable, origin and dimensions for the DC associated to
238 * a given window.
240 BOOL X11DRV_GetDC( HWND hwnd, HDC hdc, HRGN hrgn, DWORD flags )
242 HWND top = get_top_clipping_window( hwnd );
243 WND *win = WIN_GetPtr( hwnd );
244 struct x11drv_win_data *data = win->pDriverData;
245 struct x11drv_escape_set_drawable escape;
247 escape.mode = IncludeInferiors;
248 /* don't clip siblings if using parent clip region */
249 if (flags & DCX_PARENTCLIP) flags &= ~DCX_CLIPSIBLINGS;
251 if (top != hwnd)
253 /* find the top most parent that doesn't clip siblings */
254 HWND clipping_parent = 0;
255 HWND *list = WIN_ListParents( hwnd );
256 if (list)
258 int i;
259 for (i = 0; list[i] != top; i++)
261 LONG style = GetWindowLongW( list[i], GWL_STYLE );
262 if (!(style & WS_CLIPSIBLINGS)) clipping_parent = list[i];
264 HeapFree( GetProcessHeap(), 0, list );
266 if (clipping_parent)
267 clipping_parent = GetAncestor( clipping_parent, GA_PARENT );
268 else if (!(flags & DCX_CLIPSIBLINGS) || (flags & DCX_WINDOW))
269 clipping_parent = GetAncestor( hwnd, GA_PARENT );
270 else
271 clipping_parent = hwnd;
273 escape.org.x = escape.org.y = 0;
274 escape.drawable_org.x = escape.drawable_org.y = 0;
275 if (flags & DCX_WINDOW)
277 escape.org.x = win->rectWindow.left - win->rectClient.left;
278 escape.org.y = win->rectWindow.top - win->rectClient.top;
280 MapWindowPoints( hwnd, clipping_parent, &escape.org, 1 );
281 MapWindowPoints( clipping_parent, 0, &escape.drawable_org, 1 );
282 escape.drawable = X11DRV_get_client_window( clipping_parent );
284 else
286 if (IsIconic( hwnd ))
288 escape.drawable = data->icon_window ? data->icon_window : data->whole_window;
289 escape.org.x = 0;
290 escape.org.y = 0;
291 escape.drawable_org = escape.org;
293 else if (flags & DCX_WINDOW)
295 escape.drawable = data->whole_window;
296 escape.drawable_org.x = data->whole_rect.left;
297 escape.drawable_org.y = data->whole_rect.top;
298 escape.org.x = win->rectWindow.left - data->whole_rect.left;
299 escape.org.y = win->rectWindow.top - data->whole_rect.top;
301 else
303 escape.drawable = data->client_window;
304 escape.drawable_org.x = win->rectClient.left;
305 escape.drawable_org.y = win->rectClient.top;
306 escape.org.x = 0;
307 escape.org.y = 0;
311 escape.code = X11DRV_SET_DRAWABLE;
312 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
314 if (flags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN) ||
315 SetHookFlags16( HDC_16(hdc), DCHF_VALIDATEVISRGN )) /* DC was dirty */
317 /* need to recompute the visible region */
318 HRGN visRgn = get_server_visible_region( hwnd, top, flags );
320 if (flags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN))
321 CombineRgn( visRgn, visRgn, hrgn, (flags & DCX_INTERSECTRGN) ? RGN_AND : RGN_DIFF );
323 SelectVisRgn16( HDC_16(hdc), HRGN_16(visRgn) );
324 DeleteObject( visRgn );
327 WIN_ReleasePtr( win );
328 return TRUE;
332 /***********************************************************************
333 * ReleaseDC (X11DRV.@)
335 void X11DRV_ReleaseDC( HWND hwnd, HDC hdc )
337 struct x11drv_escape_set_drawable escape;
339 escape.code = X11DRV_SET_DRAWABLE;
340 escape.drawable = root_window;
341 escape.mode = IncludeInferiors;
342 escape.org.x = escape.org.y = 0;
343 escape.drawable_org.x = escape.drawable_org.y = 0;
345 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
349 /***********************************************************************
350 * SWP_DoWinPosChanging
352 static BOOL SWP_DoWinPosChanging( WINDOWPOS* pWinpos, RECT* pNewWindowRect, RECT* pNewClientRect )
354 WND *wndPtr;
356 /* Send WM_WINDOWPOSCHANGING message */
358 if (!(pWinpos->flags & SWP_NOSENDCHANGING))
359 SendMessageW( pWinpos->hwnd, WM_WINDOWPOSCHANGING, 0, (LPARAM)pWinpos );
361 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return FALSE;
363 /* Calculate new position and size */
365 *pNewWindowRect = wndPtr->rectWindow;
366 *pNewClientRect = (wndPtr->dwStyle & WS_MINIMIZE) ? wndPtr->rectWindow
367 : wndPtr->rectClient;
369 if (!(pWinpos->flags & SWP_NOSIZE))
371 pNewWindowRect->right = pNewWindowRect->left + pWinpos->cx;
372 pNewWindowRect->bottom = pNewWindowRect->top + pWinpos->cy;
374 if (!(pWinpos->flags & SWP_NOMOVE))
376 pNewWindowRect->left = pWinpos->x;
377 pNewWindowRect->top = pWinpos->y;
378 pNewWindowRect->right += pWinpos->x - wndPtr->rectWindow.left;
379 pNewWindowRect->bottom += pWinpos->y - wndPtr->rectWindow.top;
381 OffsetRect( pNewClientRect, pWinpos->x - wndPtr->rectWindow.left,
382 pWinpos->y - wndPtr->rectWindow.top );
384 pWinpos->flags |= SWP_NOCLIENTMOVE | SWP_NOCLIENTSIZE;
386 TRACE( "hwnd %p, after %p, swp %d,%d %dx%d flags %08x\n",
387 pWinpos->hwnd, pWinpos->hwndInsertAfter, pWinpos->x, pWinpos->y,
388 pWinpos->cx, pWinpos->cy, pWinpos->flags );
389 TRACE( "current %s style %08lx new %s\n",
390 wine_dbgstr_rect( &wndPtr->rectWindow ), wndPtr->dwStyle,
391 wine_dbgstr_rect( pNewWindowRect ));
393 WIN_ReleasePtr( wndPtr );
394 return TRUE;
397 /***********************************************************************
398 * SWP_DoNCCalcSize
400 static UINT SWP_DoNCCalcSize( WINDOWPOS* pWinpos, const RECT* pNewWindowRect, RECT* pNewClientRect )
402 UINT wvrFlags = 0;
403 WND *wndPtr;
405 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
407 /* Send WM_NCCALCSIZE message to get new client area */
408 if( (pWinpos->flags & (SWP_FRAMECHANGED | SWP_NOSIZE)) != SWP_NOSIZE )
410 NCCALCSIZE_PARAMS params;
411 WINDOWPOS winposCopy;
413 params.rgrc[0] = *pNewWindowRect;
414 params.rgrc[1] = wndPtr->rectWindow;
415 params.rgrc[2] = wndPtr->rectClient;
416 params.lppos = &winposCopy;
417 winposCopy = *pWinpos;
418 WIN_ReleasePtr( wndPtr );
420 wvrFlags = SendMessageW( pWinpos->hwnd, WM_NCCALCSIZE, TRUE, (LPARAM)&params );
422 TRACE( "(%ld,%ld)-(%ld,%ld)\n", params.rgrc[0].left, params.rgrc[0].top,
423 params.rgrc[0].right, params.rgrc[0].bottom );
425 /* If the application sends back garbage, ignore it */
427 if (params.rgrc[0].left < pNewWindowRect->left) params.rgrc[0].left = pNewWindowRect->left;
428 if (params.rgrc[0].top < pNewWindowRect->top) params.rgrc[0].top = pNewWindowRect->top;
429 if (params.rgrc[0].right > pNewWindowRect->right) params.rgrc[0].right = pNewWindowRect->right;
430 if (params.rgrc[0].bottom > pNewWindowRect->bottom) params.rgrc[0].bottom = pNewWindowRect->bottom;
432 if (params.rgrc[0].left <= params.rgrc[0].right &&
433 params.rgrc[0].top <= params.rgrc[0].bottom)
434 *pNewClientRect = params.rgrc[0];
436 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
438 if( pNewClientRect->left != wndPtr->rectClient.left ||
439 pNewClientRect->top != wndPtr->rectClient.top )
440 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
442 if( (pNewClientRect->right - pNewClientRect->left !=
443 wndPtr->rectClient.right - wndPtr->rectClient.left) ||
444 (pNewClientRect->bottom - pNewClientRect->top !=
445 wndPtr->rectClient.bottom - wndPtr->rectClient.top) )
446 pWinpos->flags &= ~SWP_NOCLIENTSIZE;
448 else
450 if (!(pWinpos->flags & SWP_NOMOVE) &&
451 (pNewClientRect->left != wndPtr->rectClient.left ||
452 pNewClientRect->top != wndPtr->rectClient.top))
453 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
455 WIN_ReleasePtr( wndPtr );
456 return wvrFlags;
460 /***********************************************************************
461 * SWP_DoOwnedPopups
463 * fix Z order taking into account owned popups -
464 * basically we need to maintain them above the window that owns them
466 * FIXME: hide/show owned popups when owner visibility changes.
468 static HWND SWP_DoOwnedPopups(HWND hwnd, HWND hwndInsertAfter)
470 HWND *list = NULL;
471 HWND owner = GetWindow( hwnd, GW_OWNER );
472 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
474 WARN("(%p) hInsertAfter = %p\n", hwnd, hwndInsertAfter );
476 if ((style & WS_POPUP) && owner)
478 /* make sure this popup stays above the owner */
480 HWND hwndLocalPrev = HWND_TOP;
482 if( hwndInsertAfter != HWND_TOP )
484 if ((list = WIN_ListChildren( GetDesktopWindow() )))
486 int i;
487 for (i = 0; list[i]; i++)
489 if (list[i] == owner) break;
490 if (list[i] != hwnd) hwndLocalPrev = list[i];
491 if (hwndLocalPrev == hwndInsertAfter) break;
493 hwndInsertAfter = hwndLocalPrev;
497 else if (style & WS_CHILD) return hwndInsertAfter;
499 if (!list) list = WIN_ListChildren( GetDesktopWindow() );
500 if (list)
502 int i;
503 for (i = 0; list[i]; i++)
505 if (list[i] == hwnd) break;
506 if ((GetWindowLongW( list[i], GWL_STYLE ) & WS_POPUP) &&
507 GetWindow( list[i], GW_OWNER ) == hwnd)
509 SetWindowPos( list[i], hwndInsertAfter, 0, 0, 0, 0,
510 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE |
511 SWP_NOSENDCHANGING | SWP_DEFERERASE );
512 hwndInsertAfter = list[i];
515 HeapFree( GetProcessHeap(), 0, list );
518 return hwndInsertAfter;
522 /* fix redundant flags and values in the WINDOWPOS structure */
523 static BOOL fixup_flags( WINDOWPOS *winpos )
525 WND *wndPtr = WIN_GetPtr( winpos->hwnd );
526 BOOL ret = TRUE;
528 if (!wndPtr || wndPtr == WND_OTHER_PROCESS)
530 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
531 return FALSE;
533 winpos->hwnd = wndPtr->hwndSelf; /* make it a full handle */
535 /* Finally make sure that all coordinates are valid */
536 if (winpos->x < -32768) winpos->x = -32768;
537 else if (winpos->x > 32767) winpos->x = 32767;
538 if (winpos->y < -32768) winpos->y = -32768;
539 else if (winpos->y > 32767) winpos->y = 32767;
541 if (winpos->cx < 0) winpos->cx = 0;
542 else if (winpos->cx > 32767) winpos->cx = 32767;
543 if (winpos->cy < 0) winpos->cy = 0;
544 else if (winpos->cy > 32767) winpos->cy = 32767;
546 if (wndPtr->dwStyle & WS_VISIBLE) winpos->flags &= ~SWP_SHOWWINDOW;
547 else
549 winpos->flags &= ~SWP_HIDEWINDOW;
550 if (!(winpos->flags & SWP_SHOWWINDOW)) winpos->flags |= SWP_NOREDRAW;
553 if ((wndPtr->rectWindow.right - wndPtr->rectWindow.left == winpos->cx) &&
554 (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top == winpos->cy))
555 winpos->flags |= SWP_NOSIZE; /* Already the right size */
557 if ((wndPtr->rectWindow.left == winpos->x) && (wndPtr->rectWindow.top == winpos->y))
558 winpos->flags |= SWP_NOMOVE; /* Already the right position */
560 if ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD)
562 if (!(winpos->flags & SWP_NOACTIVATE)) /* Bring to the top when activating */
564 winpos->flags &= ~SWP_NOZORDER;
565 winpos->hwndInsertAfter = HWND_TOP;
569 /* Check hwndInsertAfter */
570 if (winpos->flags & SWP_NOZORDER) goto done;
572 /* fix sign extension */
573 if (winpos->hwndInsertAfter == (HWND)0xffff) winpos->hwndInsertAfter = HWND_TOPMOST;
574 else if (winpos->hwndInsertAfter == (HWND)0xfffe) winpos->hwndInsertAfter = HWND_NOTOPMOST;
576 /* FIXME: TOPMOST not supported yet */
577 if ((winpos->hwndInsertAfter == HWND_TOPMOST) ||
578 (winpos->hwndInsertAfter == HWND_NOTOPMOST)) winpos->hwndInsertAfter = HWND_TOP;
580 /* hwndInsertAfter must be a sibling of the window */
581 if (winpos->hwndInsertAfter == HWND_TOP)
583 if (GetWindow(winpos->hwnd, GW_HWNDFIRST) == winpos->hwnd)
584 winpos->flags |= SWP_NOZORDER;
586 else if (winpos->hwndInsertAfter == HWND_BOTTOM)
588 if (GetWindow(winpos->hwnd, GW_HWNDLAST) == winpos->hwnd)
589 winpos->flags |= SWP_NOZORDER;
591 else
593 if (GetAncestor( winpos->hwndInsertAfter, GA_PARENT ) != wndPtr->parent) ret = FALSE;
594 else
596 /* don't need to change the Zorder of hwnd if it's already inserted
597 * after hwndInsertAfter or when inserting hwnd after itself.
599 if ((winpos->hwnd == winpos->hwndInsertAfter) ||
600 (winpos->hwnd == GetWindow( winpos->hwndInsertAfter, GW_HWNDNEXT )))
601 winpos->flags |= SWP_NOZORDER;
604 done:
605 WIN_ReleasePtr( wndPtr );
606 return ret;
610 /***********************************************************************
611 * SetWindowStyle (X11DRV.@)
613 * Update the X state of a window to reflect a style change
615 void X11DRV_SetWindowStyle( HWND hwnd, DWORD old_style )
617 Display *display = thread_display();
618 struct x11drv_win_data *data;
619 DWORD new_style, changed;
621 if (hwnd == GetDesktopWindow()) return;
622 if (!(data = X11DRV_get_win_data( hwnd ))) return;
624 new_style = GetWindowLongW( hwnd, GWL_STYLE );
625 changed = new_style ^ old_style;
627 if (changed & WS_VISIBLE)
629 if (X11DRV_is_window_rect_mapped( &data->window_rect ))
631 if (new_style & WS_VISIBLE)
633 TRACE( "mapping win %p\n", hwnd );
634 if (is_window_top_level( hwnd ))
636 X11DRV_sync_window_style( display, data );
637 X11DRV_set_wm_hints( display, data );
639 wine_tsx11_lock();
640 XMapWindow( display, data->whole_window );
641 wine_tsx11_unlock();
643 else if (!is_window_top_level( hwnd )) /* don't unmap managed windows */
645 TRACE( "unmapping win %p\n", hwnd );
646 wine_tsx11_lock();
647 XUnmapWindow( display, data->whole_window );
648 wine_tsx11_unlock();
651 DCE_InvalidateDCE( hwnd, &data->window_rect );
654 if (changed & WS_DISABLED)
656 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_MANAGED)
658 XWMHints *wm_hints;
659 wine_tsx11_lock();
660 if (!(wm_hints = XGetWMHints( display, data->whole_window )))
661 wm_hints = XAllocWMHints();
662 if (wm_hints)
664 wm_hints->flags |= InputHint;
665 wm_hints->input = !(new_style & WS_DISABLED);
666 XSetWMHints( display, data->whole_window, wm_hints );
667 XFree(wm_hints);
669 wine_tsx11_unlock();
675 /***********************************************************************
676 * X11DRV_set_window_pos
678 * Set a window position and Z order.
680 BOOL X11DRV_set_window_pos( HWND hwnd, HWND insert_after, const RECT *rectWindow,
681 const RECT *rectClient, UINT swp_flags, UINT wvr_flags )
683 HWND top = get_top_clipping_window( hwnd );
684 WND *win = WIN_GetPtr( hwnd );
685 DWORD old_style, new_style;
686 BOOL ret;
688 if (!win) return FALSE;
689 if (win == WND_OTHER_PROCESS)
691 if (IsWindow( hwnd )) ERR( "cannot set rectangles of other process window %p\n", hwnd );
692 return FALSE;
694 old_style = win->dwStyle;
695 SERVER_START_REQ( set_window_pos )
697 req->handle = hwnd;
698 req->top_win = top;
699 req->previous = insert_after;
700 req->flags = swp_flags & ~SWP_WINE_NOHOSTMOVE;
701 req->redraw_flags = wvr_flags;
702 req->window.left = rectWindow->left;
703 req->window.top = rectWindow->top;
704 req->window.right = rectWindow->right;
705 req->window.bottom = rectWindow->bottom;
706 req->client.left = rectClient->left;
707 req->client.top = rectClient->top;
708 req->client.right = rectClient->right;
709 req->client.bottom = rectClient->bottom;
710 ret = !wine_server_call( req );
711 new_style = reply->new_style;
713 SERVER_END_REQ;
715 if (ret)
717 struct x11drv_win_data *data = win->pDriverData;
718 Display *display = thread_display();
720 /* invalidate DCEs */
722 if ((((swp_flags & SWP_AGG_NOPOSCHANGE) != SWP_AGG_NOPOSCHANGE) && (new_style & WS_VISIBLE)) ||
723 (swp_flags & (SWP_HIDEWINDOW | SWP_SHOWWINDOW)))
725 RECT rect;
726 UnionRect( &rect, rectWindow, &win->rectWindow );
727 DCE_InvalidateDCE( hwnd, &rect );
730 win->rectWindow = *rectWindow;
731 win->rectClient = *rectClient;
732 win->dwStyle = new_style;
733 data->window_rect = *rectWindow;
735 TRACE( "win %p window %s client %s style %08lx\n",
736 hwnd, wine_dbgstr_rect(rectWindow), wine_dbgstr_rect(rectClient), new_style );
738 /* FIXME: copy the valid bits */
740 if (swp_flags & SWP_WINE_NOHOSTMOVE)
742 data->whole_rect = *rectWindow;
743 X11DRV_window_to_X_rect( hwnd, &data->whole_rect );
744 if (data->client_window != data->whole_window)
745 X11DRV_sync_client_window_position( display, data, rectClient );
747 else if (data->whole_window) /* don't do anything if X window not created yet */
749 if ((old_style & WS_VISIBLE) && !(new_style & WS_VISIBLE))
751 /* window got hidden, unmap it */
752 TRACE( "unmapping win %p\n", hwnd );
753 wine_tsx11_lock();
754 XUnmapWindow( thread_display(), data->whole_window );
755 wine_tsx11_unlock();
757 else if ((new_style & WS_VISIBLE) && !X11DRV_is_window_rect_mapped( rectWindow ))
759 /* resizing to zero size or off screen -> unmap */
760 TRACE( "unmapping zero size or off-screen win %p\n", hwnd );
761 wine_tsx11_lock();
762 XUnmapWindow( display, data->whole_window );
763 wine_tsx11_unlock();
766 X11DRV_sync_whole_window_position( display, data, !(swp_flags & SWP_NOZORDER) );
767 X11DRV_sync_client_window_position( display, data, rectClient );
769 if (!(old_style & WS_VISIBLE) && (new_style & WS_VISIBLE))
771 /* window got shown, map it */
772 if (X11DRV_is_window_rect_mapped( rectWindow ))
774 TRACE( "mapping win %p\n", hwnd );
775 if (is_window_top_level( hwnd ))
777 X11DRV_sync_window_style( display, data );
778 X11DRV_set_wm_hints( display, data );
780 wine_tsx11_lock();
781 XMapWindow( display, data->whole_window );
782 wine_tsx11_unlock();
785 else if ((new_style & WS_VISIBLE) && X11DRV_is_window_rect_mapped( rectWindow ))
787 /* resizing from zero size to non-zero -> map */
788 TRACE( "mapping non zero size or off-screen win %p\n", hwnd );
789 wine_tsx11_lock();
790 XMapWindow( display, data->whole_window );
791 wine_tsx11_unlock();
793 wine_tsx11_lock();
794 XFlush( display ); /* FIXME: should not be necessary */
795 wine_tsx11_unlock();
798 WIN_ReleasePtr( win );
799 return ret;
803 /***********************************************************************
804 * SetWindowPos (X11DRV.@)
806 BOOL X11DRV_SetWindowPos( WINDOWPOS *winpos )
808 RECT newWindowRect, newClientRect;
809 UINT wvr_flags, orig_flags;
811 TRACE( "hwnd %p, after %p, swp %d,%d %dx%d flags %08x\n",
812 winpos->hwnd, winpos->hwndInsertAfter, winpos->x, winpos->y,
813 winpos->cx, winpos->cy, winpos->flags);
815 orig_flags = winpos->flags;
816 winpos->flags &= ~SWP_WINE_NOHOSTMOVE;
818 /* Check window handle */
819 if (winpos->hwnd == GetDesktopWindow()) return FALSE;
821 /* First make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
822 if (!(winpos->flags & SWP_NOMOVE))
824 if (winpos->x < -32768) winpos->x = -32768;
825 else if (winpos->x > 32767) winpos->x = 32767;
826 if (winpos->y < -32768) winpos->y = -32768;
827 else if (winpos->y > 32767) winpos->y = 32767;
829 if (!(winpos->flags & SWP_NOSIZE))
831 if (winpos->cx < 0) winpos->cx = 0;
832 else if (winpos->cx > 32767) winpos->cx = 32767;
833 if (winpos->cy < 0) winpos->cy = 0;
834 else if (winpos->cy > 32767) winpos->cy = 32767;
837 if (!SWP_DoWinPosChanging( winpos, &newWindowRect, &newClientRect )) return FALSE;
839 /* Fix redundant flags */
840 if (!fixup_flags( winpos )) return FALSE;
842 if((winpos->flags & (SWP_NOZORDER | SWP_HIDEWINDOW | SWP_SHOWWINDOW)) != SWP_NOZORDER)
844 if (GetAncestor( winpos->hwnd, GA_PARENT ) == GetDesktopWindow())
845 winpos->hwndInsertAfter = SWP_DoOwnedPopups( winpos->hwnd, winpos->hwndInsertAfter );
848 /* Common operations */
850 wvr_flags = SWP_DoNCCalcSize( winpos, &newWindowRect, &newClientRect );
852 /* FIXME: actually do something with WVR_VALIDRECTS */
854 if (!X11DRV_set_window_pos( winpos->hwnd, winpos->hwndInsertAfter,
855 &newWindowRect, &newClientRect,
856 orig_flags, wvr_flags ))
857 return FALSE;
859 if( winpos->flags & SWP_HIDEWINDOW )
860 HideCaret(winpos->hwnd);
861 else if (winpos->flags & SWP_SHOWWINDOW)
862 ShowCaret(winpos->hwnd);
864 if (!(winpos->flags & SWP_NOACTIVATE))
866 /* child windows get WM_CHILDACTIVATE message */
867 if ((GetWindowLongW( winpos->hwnd, GWL_STYLE ) & (WS_CHILD | WS_POPUP)) == WS_CHILD)
868 SendMessageA( winpos->hwnd, WM_CHILDACTIVATE, 0, 0 );
869 else
870 SetForegroundWindow( winpos->hwnd );
873 /* And last, send the WM_WINDOWPOSCHANGED message */
875 TRACE("\tstatus flags = %04x\n", winpos->flags & SWP_AGG_STATUSFLAGS);
877 if (((winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOPOSCHANGE))
879 /* WM_WINDOWPOSCHANGED is sent even if SWP_NOSENDCHANGING is set
880 and always contains final window position.
882 winpos->x = newWindowRect.left;
883 winpos->y = newWindowRect.top;
884 winpos->cx = newWindowRect.right - newWindowRect.left;
885 winpos->cy = newWindowRect.bottom - newWindowRect.top;
886 SendMessageW( winpos->hwnd, WM_WINDOWPOSCHANGED, 0, (LPARAM)winpos );
889 return TRUE;
893 /***********************************************************************
894 * WINPOS_FindIconPos
896 * Find a suitable place for an iconic window.
898 static POINT WINPOS_FindIconPos( WND* wndPtr, POINT pt )
900 RECT rectParent;
901 HWND *list;
902 short x, y, xspacing, yspacing;
904 GetClientRect( wndPtr->parent, &rectParent );
905 if ((pt.x >= rectParent.left) && (pt.x + GetSystemMetrics(SM_CXICON) < rectParent.right) &&
906 (pt.y >= rectParent.top) && (pt.y + GetSystemMetrics(SM_CYICON) < rectParent.bottom))
907 return pt; /* The icon already has a suitable position */
909 xspacing = GetSystemMetrics(SM_CXICONSPACING);
910 yspacing = GetSystemMetrics(SM_CYICONSPACING);
912 list = WIN_ListChildren( wndPtr->parent );
913 y = rectParent.bottom;
914 for (;;)
916 x = rectParent.left;
919 /* Check if another icon already occupies this spot */
920 /* FIXME: this is completely inefficient */
921 if (list)
923 int i;
924 WND *childPtr;
926 for (i = 0; list[i]; i++)
928 if (list[i] == wndPtr->hwndSelf) continue;
929 if (!IsIconic( list[i] )) continue;
930 if (!(childPtr = WIN_FindWndPtr( list[i] ))) continue;
931 if ((childPtr->rectWindow.left < x + xspacing) &&
932 (childPtr->rectWindow.right >= x) &&
933 (childPtr->rectWindow.top <= y) &&
934 (childPtr->rectWindow.bottom > y - yspacing))
936 WIN_ReleaseWndPtr( childPtr );
937 break; /* There's a window in there */
939 WIN_ReleaseWndPtr( childPtr );
941 if (list[i])
943 /* found something here, try next spot */
944 x += xspacing;
945 continue;
949 /* No window was found, so it's OK for us */
950 pt.x = x + (xspacing - GetSystemMetrics(SM_CXICON)) / 2;
951 pt.y = y - (yspacing + GetSystemMetrics(SM_CYICON)) / 2;
952 HeapFree( GetProcessHeap(), 0, list );
953 return pt;
955 } while(x <= rectParent.right-xspacing);
956 y -= yspacing;
964 UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect )
966 WND *wndPtr;
967 UINT swpFlags = 0;
968 POINT size;
969 LONG old_style;
970 WINDOWPLACEMENT wpl;
972 TRACE("%p %u\n", hwnd, cmd );
974 wpl.length = sizeof(wpl);
975 GetWindowPlacement( hwnd, &wpl );
977 if (HOOK_CallHooks( WH_CBT, HCBT_MINMAX, (WPARAM)hwnd, cmd, TRUE ))
978 return SWP_NOSIZE | SWP_NOMOVE;
980 if (IsIconic( hwnd ))
982 if (cmd == SW_MINIMIZE) return SWP_NOSIZE | SWP_NOMOVE;
983 if (!SendMessageA( hwnd, WM_QUERYOPEN, 0, 0 )) return SWP_NOSIZE | SWP_NOMOVE;
984 swpFlags |= SWP_NOCOPYBITS;
987 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
989 size.x = wndPtr->rectWindow.left;
990 size.y = wndPtr->rectWindow.top;
992 switch( cmd )
994 case SW_MINIMIZE:
995 if( wndPtr->dwStyle & WS_MAXIMIZE) wndPtr->flags |= WIN_RESTORE_MAX;
996 else wndPtr->flags &= ~WIN_RESTORE_MAX;
998 WIN_SetStyle( hwnd, (wndPtr->dwStyle & ~WS_MAXIMIZE) | WS_MINIMIZE );
1000 X11DRV_set_iconic_state( hwnd );
1002 wpl.ptMinPosition = WINPOS_FindIconPos( wndPtr, wpl.ptMinPosition );
1004 SetRect( rect, wpl.ptMinPosition.x, wpl.ptMinPosition.y,
1005 GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON) );
1006 swpFlags |= SWP_NOCOPYBITS;
1007 break;
1009 case SW_MAXIMIZE:
1010 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL );
1012 old_style = WIN_SetStyle( hwnd, (wndPtr->dwStyle & ~WS_MINIMIZE) | WS_MAXIMIZE );
1013 if (old_style & WS_MINIMIZE)
1015 WINPOS_ShowIconTitle( hwnd, FALSE );
1016 X11DRV_set_iconic_state( hwnd );
1018 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y );
1019 break;
1021 case SW_RESTORE:
1022 old_style = WIN_SetStyle( hwnd, wndPtr->dwStyle & ~(WS_MINIMIZE|WS_MAXIMIZE) );
1023 if (old_style & WS_MINIMIZE)
1025 WINPOS_ShowIconTitle( hwnd, FALSE );
1026 X11DRV_set_iconic_state( hwnd );
1028 if( wndPtr->flags & WIN_RESTORE_MAX)
1030 /* Restore to maximized position */
1031 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL);
1032 WIN_SetStyle( hwnd, wndPtr->dwStyle | WS_MAXIMIZE );
1033 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y );
1034 break;
1037 else if (!(old_style & WS_MAXIMIZE)) break;
1039 /* Restore to normal position */
1041 *rect = wpl.rcNormalPosition;
1042 rect->right -= rect->left;
1043 rect->bottom -= rect->top;
1045 break;
1048 WIN_ReleaseWndPtr( wndPtr );
1049 return swpFlags;
1053 /***********************************************************************
1054 * ShowWindow (X11DRV.@)
1056 BOOL X11DRV_ShowWindow( HWND hwnd, INT cmd )
1058 WND* wndPtr = WIN_FindWndPtr( hwnd );
1059 BOOL wasVisible, showFlag;
1060 RECT newPos = {0, 0, 0, 0};
1061 UINT swp = 0;
1063 if (!wndPtr) return FALSE;
1064 hwnd = wndPtr->hwndSelf; /* make it a full handle */
1066 wasVisible = (wndPtr->dwStyle & WS_VISIBLE) != 0;
1068 TRACE("hwnd=%p, cmd=%d, wasVisible %d\n", hwnd, cmd, wasVisible);
1070 switch(cmd)
1072 case SW_HIDE:
1073 if (!wasVisible) goto END;
1074 swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE |
1075 SWP_NOACTIVATE | SWP_NOZORDER;
1076 break;
1078 case SW_SHOWMINNOACTIVE:
1079 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1080 /* fall through */
1081 case SW_SHOWMINIMIZED:
1082 case SW_FORCEMINIMIZE: /* FIXME: Does not work if thread is hung. */
1083 swp |= SWP_SHOWWINDOW;
1084 /* fall through */
1085 case SW_MINIMIZE:
1086 swp |= SWP_FRAMECHANGED;
1087 if( !(wndPtr->dwStyle & WS_MINIMIZE) )
1088 swp |= WINPOS_MinMaximize( hwnd, SW_MINIMIZE, &newPos );
1089 else swp |= SWP_NOSIZE | SWP_NOMOVE;
1090 break;
1092 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
1093 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
1094 if( !(wndPtr->dwStyle & WS_MAXIMIZE) )
1095 swp |= WINPOS_MinMaximize( hwnd, SW_MAXIMIZE, &newPos );
1096 else swp |= SWP_NOSIZE | SWP_NOMOVE;
1097 break;
1099 case SW_SHOWNA:
1100 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1101 /* fall through */
1102 case SW_SHOW:
1103 if (wasVisible) goto END;
1105 swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
1106 break;
1108 case SW_RESTORE:
1109 swp |= SWP_FRAMECHANGED;
1110 /* fall through */
1111 case SW_SHOWNOACTIVATE:
1112 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1113 /* fall through */
1114 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
1115 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
1116 swp |= SWP_SHOWWINDOW;
1118 if( wndPtr->dwStyle & (WS_MINIMIZE | WS_MAXIMIZE) )
1119 swp |= WINPOS_MinMaximize( hwnd, SW_RESTORE, &newPos );
1120 else swp |= SWP_NOSIZE | SWP_NOMOVE;
1121 break;
1124 showFlag = (cmd != SW_HIDE);
1125 if (showFlag != wasVisible)
1127 SendMessageW( hwnd, WM_SHOWWINDOW, showFlag, 0 );
1128 if (!IsWindow( hwnd )) goto END;
1131 /* ShowWindow won't activate a not being maximized child window */
1132 if ((wndPtr->dwStyle & WS_CHILD) && cmd != SW_MAXIMIZE)
1133 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1135 SetWindowPos( hwnd, HWND_TOP, newPos.left, newPos.top,
1136 newPos.right, newPos.bottom, LOWORD(swp) );
1137 if (cmd == SW_HIDE)
1139 HWND hFocus;
1141 /* FIXME: This will cause the window to be activated irrespective
1142 * of whether it is owned by the same thread. Has to be done
1143 * asynchronously.
1146 if (hwnd == GetActiveWindow())
1147 WINPOS_ActivateOtherWindow(hwnd);
1149 /* Revert focus to parent */
1150 hFocus = GetFocus();
1151 if (hwnd == hFocus || IsChild(hwnd, hFocus))
1153 HWND parent = GetAncestor(hwnd, GA_PARENT);
1154 if (parent == GetDesktopWindow()) parent = 0;
1155 SetFocus(parent);
1158 if (!IsWindow( hwnd )) goto END;
1159 else if( wndPtr->dwStyle & WS_MINIMIZE ) WINPOS_ShowIconTitle( hwnd, TRUE );
1161 if (wndPtr->flags & WIN_NEED_SIZE)
1163 /* should happen only in CreateWindowEx() */
1164 int wParam = SIZE_RESTORED;
1166 wndPtr->flags &= ~WIN_NEED_SIZE;
1167 if (wndPtr->dwStyle & WS_MAXIMIZE) wParam = SIZE_MAXIMIZED;
1168 else if (wndPtr->dwStyle & WS_MINIMIZE) wParam = SIZE_MINIMIZED;
1169 SendMessageA( hwnd, WM_SIZE, wParam,
1170 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
1171 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
1172 SendMessageA( hwnd, WM_MOVE, 0,
1173 MAKELONG(wndPtr->rectClient.left, wndPtr->rectClient.top) );
1176 END:
1177 WIN_ReleaseWndPtr(wndPtr);
1178 return wasVisible;
1182 /**********************************************************************
1183 * X11DRV_MapNotify
1185 void X11DRV_MapNotify( HWND hwnd, XMapEvent *event )
1187 HWND hwndFocus = GetFocus();
1188 WND *win;
1190 if (!(win = WIN_GetPtr( hwnd ))) return;
1192 if ((win->dwStyle & WS_VISIBLE) &&
1193 (win->dwStyle & WS_MINIMIZE) &&
1194 (win->dwExStyle & WS_EX_MANAGED))
1196 struct x11drv_win_data *data = win->pDriverData;
1197 int x, y;
1198 unsigned int width, height, border, depth;
1199 Window root, top;
1200 RECT rect;
1201 LONG style = (win->dwStyle & ~(WS_MINIMIZE|WS_MAXIMIZE)) | WS_VISIBLE;
1203 /* FIXME: hack */
1204 wine_tsx11_lock();
1205 XGetGeometry( event->display, data->whole_window, &root, &x, &y, &width, &height,
1206 &border, &depth );
1207 XTranslateCoordinates( event->display, data->whole_window, root, 0, 0, &x, &y, &top );
1208 wine_tsx11_unlock();
1209 rect.left = x;
1210 rect.top = y;
1211 rect.right = x + width;
1212 rect.bottom = y + height;
1213 X11DRV_X_to_window_rect( hwnd, &rect );
1215 DCE_InvalidateDCE( hwnd, &win->rectWindow );
1217 if (win->flags & WIN_RESTORE_MAX) style |= WS_MAXIMIZE;
1218 WIN_SetStyle( hwnd, style );
1219 WIN_ReleasePtr( win );
1221 SendMessageA( hwnd, WM_SHOWWINDOW, SW_RESTORE, 0 );
1222 SetWindowPos( hwnd, 0, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
1223 SWP_NOZORDER | SWP_WINE_NOHOSTMOVE );
1225 else WIN_ReleasePtr( win );
1226 if (hwndFocus && IsChild( hwnd, hwndFocus )) X11DRV_SetFocus(hwndFocus); /* FIXME */
1230 /**********************************************************************
1231 * X11DRV_UnmapNotify
1233 void X11DRV_UnmapNotify( HWND hwnd, XUnmapEvent *event )
1235 WND *win;
1237 if (!(win = WIN_GetPtr( hwnd ))) return;
1239 if ((win->dwStyle & WS_VISIBLE) && (win->dwExStyle & WS_EX_MANAGED) &&
1240 X11DRV_is_window_rect_mapped( &win->rectWindow ))
1242 if (win->dwStyle & WS_MAXIMIZE)
1243 win->flags |= WIN_RESTORE_MAX;
1244 else
1245 win->flags &= ~WIN_RESTORE_MAX;
1247 WIN_SetStyle( hwnd, (win->dwStyle & ~WS_MAXIMIZE) | WS_MINIMIZE );
1248 WIN_ReleasePtr( win );
1250 EndMenu();
1251 SendMessageA( hwnd, WM_SHOWWINDOW, SW_MINIMIZE, 0 );
1252 SetWindowPos( hwnd, 0, 0, 0, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON),
1253 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_WINE_NOHOSTMOVE );
1255 else WIN_ReleasePtr( win );
1259 /***********************************************************************
1260 * query_zorder
1262 * Synchronize internal z-order with the window manager's.
1264 static Window __get_common_ancestor( Display *display, Window A, Window B,
1265 Window** children, unsigned* total )
1267 /* find the real root window */
1269 Window root, *childrenB;
1270 unsigned totalB;
1272 wine_tsx11_lock();
1273 while( A != B && A && B )
1275 XQueryTree( display, A, &root, &A, children, total );
1276 XQueryTree( display, B, &root, &B, &childrenB, &totalB );
1277 if( childrenB ) XFree( childrenB );
1278 if( *children ) XFree( *children ), *children = NULL;
1281 if( A && B )
1283 XQueryTree( display, A, &root, &B, children, total );
1284 wine_tsx11_unlock();
1285 return A;
1287 wine_tsx11_unlock();
1288 return 0 ;
1291 static Window __get_top_decoration( Display *display, Window w, Window ancestor )
1293 Window* children, root, prev = w, parent = w;
1294 unsigned total;
1296 wine_tsx11_lock();
1299 w = parent;
1300 XQueryTree( display, w, &root, &parent, &children, &total );
1301 if( children ) XFree( children );
1302 } while( parent && parent != ancestor );
1303 wine_tsx11_unlock();
1304 TRACE("\t%08x -> %08x\n", (unsigned)prev, (unsigned)w );
1305 return ( parent ) ? w : 0 ;
1308 static unsigned __td_lookup( Window w, Window* list, unsigned max )
1310 unsigned i;
1311 for( i = max; i > 0; i-- ) if( list[i - 1] == w ) break;
1312 return i;
1315 static HWND query_zorder( Display *display, HWND hWndCheck)
1317 HWND hwndInsertAfter = HWND_TOP;
1318 Window w, parent, *children = NULL;
1319 unsigned total, check, pos, best;
1320 HWND *list = WIN_ListChildren( GetDesktopWindow() );
1321 HWND hwndA = 0, hwndB = 0;
1322 int i;
1324 /* find at least two managed windows */
1325 if (!list) return 0;
1326 for (i = 0; list[i]; i++)
1328 if (!(GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_MANAGED)) continue;
1329 if (!(GetWindowLongW( list[i], GWL_STYLE ) & WS_VISIBLE)) continue;
1330 if (!hwndA) hwndA = list[i];
1331 else
1333 hwndB = list[i];
1334 break;
1337 if (!hwndA || !hwndB) goto done;
1339 parent = __get_common_ancestor( display, X11DRV_get_whole_window(hwndA),
1340 X11DRV_get_whole_window(hwndB), &children, &total );
1341 if( parent && children )
1343 /* w is the ancestor if hWndCheck that is a direct descendant of 'parent' */
1345 w = __get_top_decoration( display, X11DRV_get_whole_window(hWndCheck), parent );
1347 if( w != children[total-1] ) /* check if at the top */
1349 /* X child at index 0 is at the bottom, at index total-1 is at the top */
1350 check = __td_lookup( w, children, total );
1351 best = total;
1353 /* go through all windows in Wine z-order... */
1354 for (i = 0; list[i]; i++)
1356 if (list[i] == hWndCheck) continue;
1357 if (!(GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_MANAGED)) continue;
1358 if (!(w = __get_top_decoration( display, X11DRV_get_whole_window(list[i]),
1359 parent ))) continue;
1360 pos = __td_lookup( w, children, total );
1361 if( pos < best && pos > check )
1363 /* find a nearest Wine window precedes hWndCheck in the real z-order */
1364 best = pos;
1365 hwndInsertAfter = list[i];
1367 if( best - check == 1 ) break;
1371 wine_tsx11_lock();
1372 if( children ) XFree( children );
1373 wine_tsx11_unlock();
1375 done:
1376 HeapFree( GetProcessHeap(), 0, list );
1377 return hwndInsertAfter;
1381 /***********************************************************************
1382 * X11DRV_handle_desktop_resize
1384 void X11DRV_handle_desktop_resize( unsigned int width, unsigned int height )
1386 RECT rect;
1387 HWND hwnd = GetDesktopWindow();
1389 screen_width = width;
1390 screen_height = height;
1391 TRACE("desktop %p change to (%dx%d)\n", hwnd, width, height);
1392 SetRect( &rect, 0, 0, width, height );
1393 X11DRV_set_window_pos( hwnd, 0, &rect, &rect, SWP_NOZORDER|SWP_NOMOVE|SWP_WINE_NOHOSTMOVE, 0 );
1394 SendMessageTimeoutW( HWND_BROADCAST, WM_DISPLAYCHANGE, screen_depth,
1395 MAKELPARAM( width, height ), SMTO_ABORTIFHUNG, 2000, NULL );
1399 /***********************************************************************
1400 * X11DRV_ConfigureNotify
1402 void X11DRV_ConfigureNotify( HWND hwnd, XConfigureEvent *event )
1404 HWND oldInsertAfter;
1405 struct x11drv_win_data *data;
1406 RECT rect;
1407 WINDOWPOS winpos;
1408 int x = event->x, y = event->y;
1410 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1412 /* Get geometry */
1414 if (!event->send_event) /* normal event, need to map coordinates to the root */
1416 Window child;
1417 wine_tsx11_lock();
1418 XTranslateCoordinates( event->display, data->whole_window, root_window,
1419 0, 0, &x, &y, &child );
1420 wine_tsx11_unlock();
1422 rect.left = x;
1423 rect.top = y;
1424 rect.right = x + event->width;
1425 rect.bottom = y + event->height;
1426 TRACE( "win %p new X rect %ld,%ld,%ldx%ld (event %d,%d,%dx%d)\n",
1427 hwnd, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
1428 event->x, event->y, event->width, event->height );
1429 X11DRV_X_to_window_rect( hwnd, &rect );
1431 winpos.hwnd = hwnd;
1432 winpos.x = rect.left;
1433 winpos.y = rect.top;
1434 winpos.cx = rect.right - rect.left;
1435 winpos.cy = rect.bottom - rect.top;
1436 winpos.flags = SWP_NOACTIVATE;
1438 /* Get Z-order (FIXME) */
1440 winpos.hwndInsertAfter = query_zorder( event->display, hwnd );
1442 /* needs to find the first Visible Window above the current one */
1443 oldInsertAfter = hwnd;
1444 for (;;)
1446 oldInsertAfter = GetWindow( oldInsertAfter, GW_HWNDPREV );
1447 if (!oldInsertAfter)
1449 oldInsertAfter = HWND_TOP;
1450 break;
1452 if (GetWindowLongA( oldInsertAfter, GWL_STYLE ) & WS_VISIBLE) break;
1455 /* Compare what has changed */
1457 GetWindowRect( hwnd, &rect );
1458 if (rect.left == winpos.x && rect.top == winpos.y) winpos.flags |= SWP_NOMOVE;
1459 else
1460 TRACE( "%p moving from (%ld,%ld) to (%d,%d)\n",
1461 hwnd, rect.left, rect.top, winpos.x, winpos.y );
1463 if ((rect.right - rect.left == winpos.cx && rect.bottom - rect.top == winpos.cy) ||
1464 IsIconic(hwnd) ||
1465 (IsRectEmpty( &rect ) && winpos.cx == 1 && winpos.cy == 1))
1466 winpos.flags |= SWP_NOSIZE;
1467 else
1468 TRACE( "%p resizing from (%ldx%ld) to (%dx%d)\n",
1469 hwnd, rect.right - rect.left, rect.bottom - rect.top,
1470 winpos.cx, winpos.cy );
1472 if (winpos.hwndInsertAfter == oldInsertAfter) winpos.flags |= SWP_NOZORDER;
1473 else
1474 TRACE( "%p restacking from after %p to after %p\n",
1475 hwnd, oldInsertAfter, winpos.hwndInsertAfter );
1477 /* if nothing changed, don't do anything */
1478 if (winpos.flags == (SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE)) return;
1480 SetWindowPos( hwnd, winpos.hwndInsertAfter, winpos.x, winpos.y,
1481 winpos.cx, winpos.cy, winpos.flags | SWP_WINE_NOHOSTMOVE );
1485 /***********************************************************************
1486 * SetWindowRgn (X11DRV.@)
1488 * Assign specified region to window (for non-rectangular windows)
1490 int X11DRV_SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL redraw )
1492 struct x11drv_win_data *data;
1494 if (!(data = X11DRV_get_win_data( hwnd )))
1496 if (IsWindow( hwnd ))
1497 FIXME( "not supported on other process window %p\n", hwnd );
1498 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1499 return FALSE;
1502 #ifdef HAVE_LIBXSHAPE
1503 if (data->whole_window)
1505 Display *display = thread_display();
1507 if (!hrgn)
1509 wine_tsx11_lock();
1510 XShapeCombineMask( display, data->whole_window,
1511 ShapeBounding, 0, 0, None, ShapeSet );
1512 wine_tsx11_unlock();
1514 else
1516 RGNDATA *pRegionData = X11DRV_GetRegionData( hrgn, 0 );
1517 if (pRegionData)
1519 wine_tsx11_lock();
1520 XShapeCombineRectangles( display, data->whole_window, ShapeBounding,
1521 data->window_rect.left - data->whole_rect.left,
1522 data->window_rect.top - data->whole_rect.top,
1523 (XRectangle *)pRegionData->Buffer,
1524 pRegionData->rdh.nCount,
1525 ShapeSet, YXBanded );
1526 wine_tsx11_unlock();
1527 HeapFree(GetProcessHeap(), 0, pRegionData);
1531 #endif /* HAVE_LIBXSHAPE */
1533 return TRUE;
1537 /***********************************************************************
1538 * draw_moving_frame
1540 * Draw the frame used when moving or resizing window.
1542 * FIXME: This causes problems in Win95 mode. (why?)
1544 static void draw_moving_frame( HDC hdc, RECT *rect, BOOL thickframe )
1546 if (thickframe)
1548 const int width = GetSystemMetrics(SM_CXFRAME);
1549 const int height = GetSystemMetrics(SM_CYFRAME);
1551 HBRUSH hbrush = SelectObject( hdc, GetStockObject( GRAY_BRUSH ) );
1552 PatBlt( hdc, rect->left, rect->top,
1553 rect->right - rect->left - width, height, PATINVERT );
1554 PatBlt( hdc, rect->left, rect->top + height, width,
1555 rect->bottom - rect->top - height, PATINVERT );
1556 PatBlt( hdc, rect->left + width, rect->bottom - 1,
1557 rect->right - rect->left - width, -height, PATINVERT );
1558 PatBlt( hdc, rect->right - 1, rect->top, -width,
1559 rect->bottom - rect->top - height, PATINVERT );
1560 SelectObject( hdc, hbrush );
1562 else DrawFocusRect( hdc, rect );
1566 /***********************************************************************
1567 * start_size_move
1569 * Initialisation of a move or resize, when initiatied from a menu choice.
1570 * Return hit test code for caption or sizing border.
1572 static LONG start_size_move( HWND hwnd, WPARAM wParam, POINT *capturePoint, LONG style )
1574 LONG hittest = 0;
1575 POINT pt;
1576 MSG msg;
1577 RECT rectWindow;
1579 GetWindowRect( hwnd, &rectWindow );
1581 if ((wParam & 0xfff0) == SC_MOVE)
1583 /* Move pointer at the center of the caption */
1584 RECT rect;
1585 NC_GetInsideRect( hwnd, &rect );
1586 if (style & WS_SYSMENU)
1587 rect.left += GetSystemMetrics(SM_CXSIZE) + 1;
1588 if (style & WS_MINIMIZEBOX)
1589 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1590 if (style & WS_MAXIMIZEBOX)
1591 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1592 pt.x = rectWindow.left + (rect.right - rect.left) / 2;
1593 pt.y = rectWindow.top + rect.top + GetSystemMetrics(SM_CYSIZE)/2;
1594 hittest = HTCAPTION;
1595 *capturePoint = pt;
1597 else /* SC_SIZE */
1599 while(!hittest)
1601 GetMessageW( &msg, 0, WM_KEYFIRST, WM_MOUSELAST );
1602 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
1604 switch(msg.message)
1606 case WM_MOUSEMOVE:
1607 hittest = NC_HandleNCHitTest( hwnd, msg.pt );
1608 if ((hittest < HTLEFT) || (hittest > HTBOTTOMRIGHT))
1609 hittest = 0;
1610 break;
1612 case WM_LBUTTONUP:
1613 return 0;
1615 case WM_KEYDOWN:
1616 switch(msg.wParam)
1618 case VK_UP:
1619 hittest = HTTOP;
1620 pt.x =(rectWindow.left+rectWindow.right)/2;
1621 pt.y = rectWindow.top + GetSystemMetrics(SM_CYFRAME) / 2;
1622 break;
1623 case VK_DOWN:
1624 hittest = HTBOTTOM;
1625 pt.x =(rectWindow.left+rectWindow.right)/2;
1626 pt.y = rectWindow.bottom - GetSystemMetrics(SM_CYFRAME) / 2;
1627 break;
1628 case VK_LEFT:
1629 hittest = HTLEFT;
1630 pt.x = rectWindow.left + GetSystemMetrics(SM_CXFRAME) / 2;
1631 pt.y =(rectWindow.top+rectWindow.bottom)/2;
1632 break;
1633 case VK_RIGHT:
1634 hittest = HTRIGHT;
1635 pt.x = rectWindow.right - GetSystemMetrics(SM_CXFRAME) / 2;
1636 pt.y =(rectWindow.top+rectWindow.bottom)/2;
1637 break;
1638 case VK_RETURN:
1639 case VK_ESCAPE: return 0;
1643 *capturePoint = pt;
1645 SetCursorPos( pt.x, pt.y );
1646 NC_HandleSetCursor( hwnd, (WPARAM)hwnd, MAKELONG( hittest, WM_MOUSEMOVE ));
1647 return hittest;
1651 /***********************************************************************
1652 * set_movesize_capture
1654 static void set_movesize_capture( HWND hwnd )
1656 HWND previous = 0;
1658 SERVER_START_REQ( set_capture_window )
1660 req->handle = hwnd;
1661 req->flags = CAPTURE_MOVESIZE;
1662 if (!wine_server_call_err( req ))
1664 previous = reply->previous;
1665 hwnd = reply->full_handle;
1668 SERVER_END_REQ;
1669 if (previous && previous != hwnd)
1670 SendMessageW( previous, WM_CAPTURECHANGED, 0, (LPARAM)hwnd );
1673 /***********************************************************************
1674 * X11DRV_WMMoveResizeWindow
1676 * Tells the window manager to initiate a move or resize operation.
1678 * SEE
1679 * http://freedesktop.org/Standards/wm-spec/1.3/ar01s04.html
1680 * or search for "_NET_WM_MOVERESIZE"
1682 static void X11DRV_WMMoveResizeWindow( HWND hwnd, int x, int y, int dir )
1684 XEvent xev;
1685 Display *display = thread_display();
1687 xev.xclient.type = ClientMessage;
1688 xev.xclient.window = X11DRV_get_whole_window(hwnd);
1689 xev.xclient.message_type = x11drv_atom(_NET_WM_MOVERESIZE);
1690 xev.xclient.serial = 0;
1691 xev.xclient.display = display;
1692 xev.xclient.send_event = True;
1693 xev.xclient.format = 32;
1694 xev.xclient.data.l[0] = x; /* x coord */
1695 xev.xclient.data.l[1] = y; /* y coord */
1696 xev.xclient.data.l[2] = dir; /* direction */
1697 xev.xclient.data.l[3] = 1; /* button */
1698 xev.xclient.data.l[4] = 0; /* unused */
1700 /* need to ungrab the pointer that may have been automatically grabbed
1701 * with a ButtonPress event */
1702 wine_tsx11_lock();
1703 XUngrabPointer( display, CurrentTime );
1704 XSendEvent(display, root_window, False, SubstructureNotifyMask, &xev);
1705 wine_tsx11_unlock();
1708 /***********************************************************************
1709 * SysCommandSizeMove (X11DRV.@)
1711 * Perform SC_MOVE and SC_SIZE commands.
1713 void X11DRV_SysCommandSizeMove( HWND hwnd, WPARAM wParam )
1715 MSG msg;
1716 RECT sizingRect, mouseRect, origRect;
1717 HDC hdc;
1718 HWND parent;
1719 LONG hittest = (LONG)(wParam & 0x0f);
1720 WPARAM syscommand = wParam & 0xfff0;
1721 HCURSOR hDragCursor = 0, hOldCursor = 0;
1722 POINT minTrack, maxTrack;
1723 POINT capturePoint, pt;
1724 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
1725 LONG exstyle = GetWindowLongA( hwnd, GWL_EXSTYLE );
1726 BOOL thickframe = HAS_THICKFRAME( style, exstyle );
1727 BOOL iconic = style & WS_MINIMIZE;
1728 BOOL moved = FALSE;
1729 DWORD dwPoint = GetMessagePos ();
1730 BOOL DragFullWindows = FALSE;
1731 BOOL grab;
1732 Window parent_win, whole_win;
1733 Display *old_gdi_display = NULL;
1734 Display *display = thread_display();
1736 pt.x = (short)LOWORD(dwPoint);
1737 pt.y = (short)HIWORD(dwPoint);
1738 capturePoint = pt;
1740 if (IsZoomed(hwnd) || !IsWindowVisible(hwnd)) return;
1742 /* if we are managed then we let the WM do all the work */
1743 if (exstyle & WS_EX_MANAGED)
1745 int dir;
1746 if (syscommand == SC_MOVE)
1748 if (!hittest) dir = _NET_WM_MOVERESIZE_MOVE_KEYBOARD;
1749 else dir = _NET_WM_MOVERESIZE_MOVE;
1751 else if (!hittest) dir = _NET_WM_MOVERESIZE_SIZE_KEYBOARD;
1752 else
1753 switch (hittest)
1755 case WMSZ_LEFT: dir = _NET_WM_MOVERESIZE_SIZE_LEFT; break;
1756 case WMSZ_RIGHT: dir = _NET_WM_MOVERESIZE_SIZE_RIGHT; break;
1757 case WMSZ_TOP: dir = _NET_WM_MOVERESIZE_SIZE_TOP; break;
1758 case WMSZ_TOPLEFT: dir = _NET_WM_MOVERESIZE_SIZE_TOPLEFT; break;
1759 case WMSZ_TOPRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT; break;
1760 case WMSZ_BOTTOM: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOM; break;
1761 case WMSZ_BOTTOMLEFT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT; break;
1762 case WMSZ_BOTTOMRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT; break;
1763 default:
1764 ERR("Invalid hittest value: %ld\n", hittest);
1765 dir = _NET_WM_MOVERESIZE_SIZE_KEYBOARD;
1767 X11DRV_WMMoveResizeWindow( hwnd, pt.x, pt.y, dir );
1768 return;
1771 SystemParametersInfoA(SPI_GETDRAGFULLWINDOWS, 0, &DragFullWindows, 0);
1773 if (syscommand == SC_MOVE)
1775 if (!hittest) hittest = start_size_move( hwnd, wParam, &capturePoint, style );
1776 if (!hittest) return;
1778 else /* SC_SIZE */
1780 if ( hittest && (syscommand != SC_MOUSEMENU) )
1781 hittest += (HTLEFT - WMSZ_LEFT);
1782 else
1784 set_movesize_capture( hwnd );
1785 hittest = start_size_move( hwnd, wParam, &capturePoint, style );
1786 if (!hittest)
1788 set_movesize_capture(0);
1789 return;
1794 /* Get min/max info */
1796 WINPOS_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack );
1797 GetWindowRect( hwnd, &sizingRect );
1798 if (style & WS_CHILD)
1800 parent = GetParent(hwnd);
1801 /* make sizing rect relative to parent */
1802 MapWindowPoints( 0, parent, (POINT*)&sizingRect, 2 );
1803 GetClientRect( parent, &mouseRect );
1805 else
1807 parent = 0;
1808 SetRect(&mouseRect, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
1810 origRect = sizingRect;
1812 if (ON_LEFT_BORDER(hittest))
1814 mouseRect.left = max( mouseRect.left, sizingRect.right-maxTrack.x );
1815 mouseRect.right = min( mouseRect.right, sizingRect.right-minTrack.x );
1817 else if (ON_RIGHT_BORDER(hittest))
1819 mouseRect.left = max( mouseRect.left, sizingRect.left+minTrack.x );
1820 mouseRect.right = min( mouseRect.right, sizingRect.left+maxTrack.x );
1822 if (ON_TOP_BORDER(hittest))
1824 mouseRect.top = max( mouseRect.top, sizingRect.bottom-maxTrack.y );
1825 mouseRect.bottom = min( mouseRect.bottom,sizingRect.bottom-minTrack.y);
1827 else if (ON_BOTTOM_BORDER(hittest))
1829 mouseRect.top = max( mouseRect.top, sizingRect.top+minTrack.y );
1830 mouseRect.bottom = min( mouseRect.bottom, sizingRect.top+maxTrack.y );
1832 if (parent) MapWindowPoints( parent, 0, (LPPOINT)&mouseRect, 2 );
1834 /* Retrieve a default cache DC (without using the window style) */
1835 hdc = GetDCEx( parent, 0, DCX_CACHE );
1837 if( iconic ) /* create a cursor for dragging */
1839 hDragCursor = (HCURSOR)GetClassLongA( hwnd, GCL_HICON);
1840 if( !hDragCursor ) hDragCursor = (HCURSOR)SendMessageA( hwnd, WM_QUERYDRAGICON, 0, 0L);
1841 if( !hDragCursor ) iconic = FALSE;
1844 /* repaint the window before moving it around */
1845 RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN );
1847 SendMessageA( hwnd, WM_ENTERSIZEMOVE, 0, 0 );
1848 set_movesize_capture( hwnd );
1850 /* grab the server only when moving top-level windows without desktop */
1851 grab = (!DragFullWindows && !parent && (root_window == DefaultRootWindow(gdi_display)));
1853 if (grab)
1855 wine_tsx11_lock();
1856 XSync( gdi_display, False );
1857 XGrabServer( display );
1858 XSync( display, False );
1859 /* switch gdi display to the thread display, since the server is grabbed */
1860 old_gdi_display = gdi_display;
1861 gdi_display = display;
1862 wine_tsx11_unlock();
1864 whole_win = X11DRV_get_whole_window(hwnd);
1865 parent_win = parent ? X11DRV_get_client_window(parent) : root_window;
1867 wine_tsx11_lock();
1868 XGrabPointer( display, whole_win, False,
1869 PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
1870 GrabModeAsync, GrabModeAsync, parent_win, None, CurrentTime );
1871 wine_tsx11_unlock();
1873 while(1)
1875 int dx = 0, dy = 0;
1877 if (!GetMessageW( &msg, 0, WM_KEYFIRST, WM_MOUSELAST )) break;
1878 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
1880 /* Exit on button-up, Return, or Esc */
1881 if ((msg.message == WM_LBUTTONUP) ||
1882 ((msg.message == WM_KEYDOWN) &&
1883 ((msg.wParam == VK_RETURN) || (msg.wParam == VK_ESCAPE)))) break;
1885 if ((msg.message != WM_KEYDOWN) && (msg.message != WM_MOUSEMOVE))
1886 continue; /* We are not interested in other messages */
1888 pt = msg.pt;
1890 if (msg.message == WM_KEYDOWN) switch(msg.wParam)
1892 case VK_UP: pt.y -= 8; break;
1893 case VK_DOWN: pt.y += 8; break;
1894 case VK_LEFT: pt.x -= 8; break;
1895 case VK_RIGHT: pt.x += 8; break;
1898 pt.x = max( pt.x, mouseRect.left );
1899 pt.x = min( pt.x, mouseRect.right );
1900 pt.y = max( pt.y, mouseRect.top );
1901 pt.y = min( pt.y, mouseRect.bottom );
1903 dx = pt.x - capturePoint.x;
1904 dy = pt.y - capturePoint.y;
1906 if (dx || dy)
1908 if( !moved )
1910 moved = TRUE;
1912 if( iconic ) /* ok, no system popup tracking */
1914 hOldCursor = SetCursor(hDragCursor);
1915 ShowCursor( TRUE );
1916 WINPOS_ShowIconTitle( hwnd, FALSE );
1918 else if(!DragFullWindows)
1919 draw_moving_frame( hdc, &sizingRect, thickframe );
1922 if (msg.message == WM_KEYDOWN) SetCursorPos( pt.x, pt.y );
1923 else
1925 RECT newRect = sizingRect;
1926 WPARAM wpSizingHit = 0;
1928 if (hittest == HTCAPTION) OffsetRect( &newRect, dx, dy );
1929 if (ON_LEFT_BORDER(hittest)) newRect.left += dx;
1930 else if (ON_RIGHT_BORDER(hittest)) newRect.right += dx;
1931 if (ON_TOP_BORDER(hittest)) newRect.top += dy;
1932 else if (ON_BOTTOM_BORDER(hittest)) newRect.bottom += dy;
1933 if(!iconic && !DragFullWindows) draw_moving_frame( hdc, &sizingRect, thickframe );
1934 capturePoint = pt;
1936 /* determine the hit location */
1937 if (hittest >= HTLEFT && hittest <= HTBOTTOMRIGHT)
1938 wpSizingHit = WMSZ_LEFT + (hittest - HTLEFT);
1939 SendMessageA( hwnd, WM_SIZING, wpSizingHit, (LPARAM)&newRect );
1941 if (!iconic)
1943 if(!DragFullWindows)
1944 draw_moving_frame( hdc, &newRect, thickframe );
1945 else
1946 SetWindowPos( hwnd, 0, newRect.left, newRect.top,
1947 newRect.right - newRect.left,
1948 newRect.bottom - newRect.top,
1949 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
1951 sizingRect = newRect;
1956 set_movesize_capture(0);
1957 if( iconic )
1959 if( moved ) /* restore cursors, show icon title later on */
1961 ShowCursor( FALSE );
1962 SetCursor( hOldCursor );
1965 else if (moved && !DragFullWindows)
1966 draw_moving_frame( hdc, &sizingRect, thickframe );
1968 ReleaseDC( parent, hdc );
1970 wine_tsx11_lock();
1971 XUngrabPointer( display, CurrentTime );
1972 if (grab)
1974 XSync( display, False );
1975 XUngrabServer( display );
1976 XSync( display, False );
1977 gdi_display = old_gdi_display;
1979 wine_tsx11_unlock();
1981 if (HOOK_CallHooks( WH_CBT, HCBT_MOVESIZE, (WPARAM)hwnd, (LPARAM)&sizingRect, TRUE ))
1982 moved = FALSE;
1984 SendMessageA( hwnd, WM_EXITSIZEMOVE, 0, 0 );
1985 SendMessageA( hwnd, WM_SETVISIBLE, !IsIconic(hwnd), 0L);
1987 /* window moved or resized */
1988 if (moved)
1990 /* if the moving/resizing isn't canceled call SetWindowPos
1991 * with the new position or the new size of the window
1993 if (!((msg.message == WM_KEYDOWN) && (msg.wParam == VK_ESCAPE)) )
1995 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
1996 if(!DragFullWindows)
1997 SetWindowPos( hwnd, 0, sizingRect.left, sizingRect.top,
1998 sizingRect.right - sizingRect.left,
1999 sizingRect.bottom - sizingRect.top,
2000 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
2002 else
2003 { /* restore previous size/position */
2004 if(DragFullWindows)
2005 SetWindowPos( hwnd, 0, origRect.left, origRect.top,
2006 origRect.right - origRect.left,
2007 origRect.bottom - origRect.top,
2008 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
2012 if (IsIconic(hwnd))
2014 /* Single click brings up the system menu when iconized */
2016 if( !moved )
2018 if(style & WS_SYSMENU )
2019 SendMessageA( hwnd, WM_SYSCOMMAND,
2020 SC_MOUSEMENU + HTSYSMENU, MAKELONG(pt.x,pt.y));
2022 else WINPOS_ShowIconTitle( hwnd, TRUE );