Added regression test for WM_NEXTDLGCTL and default button ID
[wine/testsucceed.git] / dlls / x11drv / winpos.c
blobabf326b3a448e23c56b91473f341d55b04a259ef
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 "wownt32.h"
37 #include "wine/wingdi16.h"
39 #include "x11drv.h"
40 #include "win.h"
41 #include "winpos.h"
42 #include "dce.h"
43 #include "cursoricon.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))
76 /***********************************************************************
77 * clip_children
79 * Clip all children of a given window out of the visible region
81 static int clip_children( HWND parent, HWND last, HRGN hrgn, int whole_window )
83 HWND *list;
84 WND *ptr;
85 HRGN rectRgn;
86 int i, x, y, ret = SIMPLEREGION;
88 /* first check if we have anything to do */
89 if (!(list = WIN_ListChildren( parent ))) return ret;
91 if (whole_window)
93 WND *win = WIN_FindWndPtr( parent );
94 x = win->rectWindow.left - win->rectClient.left;
95 y = win->rectWindow.top - win->rectClient.top;
96 WIN_ReleaseWndPtr( win );
98 else x = y = 0;
100 rectRgn = CreateRectRgn( 0, 0, 0, 0 );
102 for (i = 0; list[i] && list[i] != last; i++)
104 if (!(ptr = WIN_FindWndPtr( list[i] ))) continue;
105 if ((ptr->dwStyle & WS_VISIBLE) && !(ptr->dwExStyle & WS_EX_TRANSPARENT))
107 SetRectRgn( rectRgn, ptr->rectWindow.left + x, ptr->rectWindow.top + y,
108 ptr->rectWindow.right + x, ptr->rectWindow.bottom + y );
109 if ((ret = CombineRgn( hrgn, hrgn, rectRgn, RGN_DIFF )) == NULLREGION)
111 WIN_ReleaseWndPtr( ptr );
112 break; /* no need to go on, region is empty */
115 WIN_ReleaseWndPtr( ptr );
117 DeleteObject( rectRgn );
118 HeapFree( GetProcessHeap(), 0, list );
119 return ret;
123 /***********************************************************************
124 * get_server_visible_region
126 static HRGN get_server_visible_region( HWND hwnd, HWND top, UINT flags )
128 RGNDATA *data;
129 HRGN ret = 0;
130 size_t size = 256;
131 BOOL retry = FALSE;
135 if (!(data = HeapAlloc( GetProcessHeap(), 0, sizeof(*data) + size - 1 ))) return 0;
136 SERVER_START_REQ( get_visible_region )
138 req->window = hwnd;
139 req->top_win = top;
140 req->flags = flags;
141 wine_server_set_reply( req, data->Buffer, size );
142 if (!wine_server_call_err( req ))
144 if (reply->total_size <= size)
146 size_t reply_size = wine_server_reply_size( reply );
147 data->rdh.dwSize = sizeof(data->rdh);
148 data->rdh.iType = RDH_RECTANGLES;
149 data->rdh.nCount = reply_size / sizeof(RECT);
150 data->rdh.nRgnSize = reply_size;
151 ret = ExtCreateRegion( NULL, size, data );
152 retry = FALSE;
154 else
156 size = reply->total_size;
157 retry = TRUE;
161 SERVER_END_REQ;
162 HeapFree( GetProcessHeap(), 0, data );
163 } while (retry);
164 return ret;
168 /***********************************************************************
169 * get_covered_region
171 * Compute the portion of 'rgn' that is covered by non-clipped siblings.
172 * This is the area that is covered from X point of view, but may still need
173 * to be exposed.
174 * 'rgn' must be relative to the client area of the parent of 'win'.
176 static int get_covered_region( WND *win, HRGN rgn )
178 HRGN tmp;
179 int ret;
180 WND *parent, *ptr = WIN_FindWndPtr( win->hwndSelf );
181 int xoffset = 0, yoffset = 0;
183 tmp = CreateRectRgn( 0, 0, 0, 0 );
184 CombineRgn( tmp, rgn, 0, RGN_COPY );
186 /* to make things easier we actually build the uncovered
187 * area by removing all siblings and then we subtract that
188 * from the total region to get the covered area */
189 for (;;)
191 if (!(ptr->dwStyle & WS_CLIPSIBLINGS))
193 if (clip_children( ptr->parent, ptr->hwndSelf, tmp, FALSE ) == NULLREGION) break;
195 if (!(parent = WIN_FindWndPtr( ptr->parent ))) break;
196 WIN_ReleaseWndPtr( ptr );
197 ptr = parent;
198 OffsetRgn( tmp, ptr->rectClient.left, ptr->rectClient.top );
199 xoffset += ptr->rectClient.left;
200 yoffset += ptr->rectClient.top;
202 WIN_ReleaseWndPtr( ptr );
203 /* make it relative to the target window again */
204 OffsetRgn( tmp, -xoffset, -yoffset );
206 /* now subtract the computed region from the original one */
207 ret = CombineRgn( rgn, rgn, tmp, RGN_DIFF );
208 DeleteObject( tmp );
209 return ret;
213 /***********************************************************************
214 * expose_window
216 * Expose a region of a given window.
218 static void expose_window( HWND hwnd, RECT *rect, HRGN rgn, int flags )
220 POINT offset;
221 HWND top = 0;
222 HWND *list;
223 int i;
225 /* find the top most parent that doesn't clip children or siblings and
226 * invalidate the area on its parent, including all children */
227 if ((list = WIN_ListParents( hwnd )))
229 HWND current = hwnd;
230 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
231 for (i = 0; list[i] && list[i] != GetDesktopWindow(); i++)
233 if (!(style & WS_CLIPSIBLINGS)) top = current;
234 style = GetWindowLongW( list[i], GWL_STYLE );
235 if (!(style & WS_CLIPCHILDREN)) top = current;
236 current = list[i];
239 if (top)
241 /* find the parent of the top window, reusing the parent list */
242 if (top == hwnd) i = 0;
243 else
245 for (i = 0; list[i]; i++) if (list[i] == top) break;
246 if (list[i] && list[i+1]) i++;
248 if (list[i] != GetDesktopWindow()) top = list[i];
249 flags &= ~RDW_FRAME; /* parent will invalidate children frame anyway */
250 flags |= RDW_ALLCHILDREN;
252 HeapFree( GetProcessHeap(), 0, list );
255 if (!top) top = hwnd;
257 /* make coords relative to top */
258 offset.x = offset.y = 0;
259 MapWindowPoints( hwnd, top, &offset, 1 );
261 if (rect)
263 OffsetRect( rect, offset.x, offset.y );
264 RedrawWindow( top, rect, 0, flags );
266 else
268 OffsetRgn( rgn, offset.x, offset.y );
269 RedrawWindow( top, NULL, rgn, flags );
274 /***********************************************************************
275 * expose_covered_parent_area
277 * Expose the parent area that has been uncovered by moving/hiding a
278 * given window, but that is still covered by other siblings (the area
279 * not covered by siblings will be exposed automatically by X).
281 static void expose_covered_parent_area( WND *win, const RECT *old_rect )
283 int ret = SIMPLEREGION;
284 HRGN hrgn = CreateRectRgnIndirect( old_rect );
286 if (win->dwStyle & WS_VISIBLE)
288 HRGN tmp = CreateRectRgnIndirect( &win->rectWindow );
289 ret = CombineRgn( hrgn, hrgn, tmp, RGN_DIFF );
290 DeleteObject( tmp );
293 if (ret != NULLREGION)
295 if (get_covered_region( win, hrgn ) != NULLREGION)
296 expose_window( win->parent, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
298 DeleteObject( hrgn );
302 /***********************************************************************
303 * expose_covered_window_area
305 * Expose the area of a window that is covered by other siblings.
307 static void expose_covered_window_area( WND *win, const RECT *old_client_rect, BOOL frame )
309 HRGN hrgn;
310 int ret = SIMPLEREGION;
312 if (frame)
313 hrgn = CreateRectRgn( win->rectWindow.left - win->rectClient.left,
314 win->rectWindow.top - win->rectClient.top,
315 win->rectWindow.right - win->rectWindow.left,
316 win->rectWindow.bottom - win->rectWindow.top );
317 else
318 hrgn = CreateRectRgn( 0, 0,
319 win->rectClient.right - win->rectClient.left,
320 win->rectClient.bottom - win->rectClient.top );
322 /* if the client rect didn't move we don't need to repaint it all */
323 if (old_client_rect->left == win->rectClient.left &&
324 old_client_rect->top == win->rectClient.top)
326 RECT rc;
328 if (IntersectRect( &rc, old_client_rect, &win->rectClient ))
330 HRGN tmp;
331 /* subtract the unchanged client area from the region to expose */
332 OffsetRect( &rc, -win->rectClient.left, -win->rectClient.top );
333 if ((tmp = CreateRectRgnIndirect( &rc )))
335 ret = CombineRgn( hrgn, hrgn, tmp, RGN_DIFF );
336 DeleteObject( tmp );
341 if (ret != NULLREGION)
343 if (get_covered_region( win, hrgn ) != NULLREGION)
344 expose_window( win->hwndSelf, NULL, hrgn,
345 RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
348 DeleteObject( hrgn );
352 /***********************************************************************
353 * X11DRV_Expose
355 void X11DRV_Expose( HWND hwnd, XExposeEvent *event )
357 RECT rect;
358 struct x11drv_win_data *data;
359 int flags = RDW_INVALIDATE | RDW_ERASE;
360 WND *win;
362 TRACE( "win %p (%lx) %d,%d %dx%d\n",
363 hwnd, event->window, event->x, event->y, event->width, event->height );
365 rect.left = event->x;
366 rect.top = event->y;
367 rect.right = rect.left + event->width;
368 rect.bottom = rect.top + event->height;
370 if (!(win = WIN_GetPtr( hwnd ))) return;
371 data = win->pDriverData;
373 if (event->window != data->client_window) /* whole window or icon window */
375 flags |= RDW_FRAME;
376 /* make position relative to client area instead of window */
377 OffsetRect( &rect, -data->client_rect.left, -data->client_rect.top );
379 WIN_ReleasePtr( win );
381 expose_window( hwnd, &rect, 0, flags );
385 /***********************************************************************
386 * GetDC (X11DRV.@)
388 * Set the drawable, origin and dimensions for the DC associated to
389 * a given window.
391 BOOL X11DRV_GetDC( HWND hwnd, HDC hdc, HRGN hrgn, DWORD flags )
393 WND *win = WIN_GetPtr( hwnd );
394 HWND top = 0;
395 X11DRV_WND_DATA *data = win->pDriverData;
396 struct x11drv_escape_set_drawable escape;
398 escape.mode = IncludeInferiors;
399 /* don't clip siblings if using parent clip region */
400 if (flags & DCX_PARENTCLIP) flags &= ~DCX_CLIPSIBLINGS;
402 top = GetAncestor( hwnd, GA_ROOT );
403 if (!top) top = GetDesktopWindow();
405 if (top != hwnd)
407 escape.org.x = escape.org.y = 0;
408 if (flags & DCX_WINDOW)
410 escape.org.x = win->rectWindow.left - win->rectClient.left;
411 escape.org.y = win->rectWindow.top - win->rectClient.top;
413 MapWindowPoints( hwnd, top, &escape.org, 1 );
414 escape.drawable_org.x = escape.drawable_org.y = 0;
415 MapWindowPoints( top, 0, &escape.drawable_org, 1 );
416 escape.drawable = X11DRV_get_client_window( top );
418 else
420 if (IsIconic( hwnd ))
422 escape.drawable = data->icon_window ? data->icon_window : data->whole_window;
423 escape.org.x = 0;
424 escape.org.y = 0;
425 escape.drawable_org = escape.org;
427 else if (flags & DCX_WINDOW)
429 escape.drawable = data->whole_window;
430 escape.drawable_org.x = data->whole_rect.left;
431 escape.drawable_org.y = data->whole_rect.top;
432 escape.org.x = win->rectWindow.left - data->whole_rect.left;
433 escape.org.y = win->rectWindow.top - data->whole_rect.top;
435 else
437 escape.drawable = data->client_window;
438 escape.drawable_org.x = win->rectClient.left;
439 escape.drawable_org.y = win->rectClient.top;
440 escape.org.x = 0;
441 escape.org.y = 0;
445 escape.code = X11DRV_SET_DRAWABLE;
446 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
448 if (flags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN) ||
449 SetHookFlags16( HDC_16(hdc), DCHF_VALIDATEVISRGN )) /* DC was dirty */
451 /* need to recompute the visible region */
452 HRGN visRgn = get_server_visible_region( hwnd, top, flags );
454 if (flags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN))
455 CombineRgn( visRgn, visRgn, hrgn, (flags & DCX_INTERSECTRGN) ? RGN_AND : RGN_DIFF );
457 SelectVisRgn16( HDC_16(hdc), HRGN_16(visRgn) );
458 DeleteObject( visRgn );
461 WIN_ReleasePtr( win );
462 return TRUE;
466 /***********************************************************************
467 * ReleaseDC (X11DRV.@)
469 void X11DRV_ReleaseDC( HWND hwnd, HDC hdc )
471 struct x11drv_escape_set_drawable escape;
473 escape.code = X11DRV_SET_DRAWABLE;
474 escape.drawable = root_window;
475 escape.mode = IncludeInferiors;
476 escape.org.x = escape.org.y = 0;
477 escape.drawable_org.x = escape.drawable_org.y = 0;
479 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
483 /***********************************************************************
484 * SWP_DoWinPosChanging
486 static BOOL SWP_DoWinPosChanging( WINDOWPOS* pWinpos, RECT* pNewWindowRect, RECT* pNewClientRect )
488 WND *wndPtr;
490 /* Send WM_WINDOWPOSCHANGING message */
492 if (!(pWinpos->flags & SWP_NOSENDCHANGING))
493 SendMessageW( pWinpos->hwnd, WM_WINDOWPOSCHANGING, 0, (LPARAM)pWinpos );
495 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return FALSE;
497 /* Calculate new position and size */
499 *pNewWindowRect = wndPtr->rectWindow;
500 *pNewClientRect = (wndPtr->dwStyle & WS_MINIMIZE) ? wndPtr->rectWindow
501 : wndPtr->rectClient;
503 if (!(pWinpos->flags & SWP_NOSIZE))
505 pNewWindowRect->right = pNewWindowRect->left + pWinpos->cx;
506 pNewWindowRect->bottom = pNewWindowRect->top + pWinpos->cy;
508 if (!(pWinpos->flags & SWP_NOMOVE))
510 pNewWindowRect->left = pWinpos->x;
511 pNewWindowRect->top = pWinpos->y;
512 pNewWindowRect->right += pWinpos->x - wndPtr->rectWindow.left;
513 pNewWindowRect->bottom += pWinpos->y - wndPtr->rectWindow.top;
515 OffsetRect( pNewClientRect, pWinpos->x - wndPtr->rectWindow.left,
516 pWinpos->y - wndPtr->rectWindow.top );
518 pWinpos->flags |= SWP_NOCLIENTMOVE | SWP_NOCLIENTSIZE;
519 WIN_ReleasePtr( wndPtr );
520 return TRUE;
523 /***********************************************************************
524 * SWP_DoNCCalcSize
526 static UINT SWP_DoNCCalcSize( WINDOWPOS* pWinpos, RECT* pNewWindowRect, RECT* pNewClientRect )
528 UINT wvrFlags = 0;
529 WND *wndPtr;
531 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
533 /* Send WM_NCCALCSIZE message to get new client area */
534 if( (pWinpos->flags & (SWP_FRAMECHANGED | SWP_NOSIZE)) != SWP_NOSIZE )
536 NCCALCSIZE_PARAMS params;
537 WINDOWPOS winposCopy;
539 params.rgrc[0] = *pNewWindowRect;
540 params.rgrc[1] = wndPtr->rectWindow;
541 params.rgrc[2] = wndPtr->rectClient;
542 params.lppos = &winposCopy;
543 winposCopy = *pWinpos;
544 WIN_ReleasePtr( wndPtr );
546 wvrFlags = SendMessageW( pWinpos->hwnd, WM_NCCALCSIZE, TRUE, (LPARAM)&params );
548 TRACE( "(%ld,%ld)-(%ld,%ld)\n", params.rgrc[0].left, params.rgrc[0].top,
549 params.rgrc[0].right, params.rgrc[0].bottom );
551 /* If the application send back garbage, ignore it */
552 if (params.rgrc[0].left <= params.rgrc[0].right &&
553 params.rgrc[0].top <= params.rgrc[0].bottom)
554 *pNewClientRect = params.rgrc[0];
556 /* FIXME: WVR_ALIGNxxx */
558 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
560 if( pNewClientRect->left != wndPtr->rectClient.left ||
561 pNewClientRect->top != wndPtr->rectClient.top )
562 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
564 if( (pNewClientRect->right - pNewClientRect->left !=
565 wndPtr->rectClient.right - wndPtr->rectClient.left) ||
566 (pNewClientRect->bottom - pNewClientRect->top !=
567 wndPtr->rectClient.bottom - wndPtr->rectClient.top) )
568 pWinpos->flags &= ~SWP_NOCLIENTSIZE;
570 else
572 if (!(pWinpos->flags & SWP_NOMOVE) &&
573 (pNewClientRect->left != wndPtr->rectClient.left ||
574 pNewClientRect->top != wndPtr->rectClient.top))
575 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
577 WIN_ReleasePtr( wndPtr );
578 return wvrFlags;
582 /***********************************************************************
583 * SWP_DoOwnedPopups
585 * fix Z order taking into account owned popups -
586 * basically we need to maintain them above the window that owns them
588 * FIXME: hide/show owned popups when owner visibility changes.
590 static HWND SWP_DoOwnedPopups(HWND hwnd, HWND hwndInsertAfter)
592 HWND *list = NULL;
593 HWND owner = GetWindow( hwnd, GW_OWNER );
594 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
596 WARN("(%p) hInsertAfter = %p\n", hwnd, hwndInsertAfter );
598 if ((style & WS_POPUP) && owner)
600 /* make sure this popup stays above the owner */
602 HWND hwndLocalPrev = HWND_TOP;
604 if( hwndInsertAfter != HWND_TOP )
606 if ((list = WIN_ListChildren( GetDesktopWindow() )))
608 int i;
609 for (i = 0; list[i]; i++)
611 if (list[i] == owner) break;
612 if (list[i] != hwnd) hwndLocalPrev = list[i];
613 if (hwndLocalPrev == hwndInsertAfter) break;
615 hwndInsertAfter = hwndLocalPrev;
619 else if (style & WS_CHILD) return hwndInsertAfter;
621 if (!list) list = WIN_ListChildren( GetDesktopWindow() );
622 if (list)
624 int i;
625 for (i = 0; list[i]; i++)
627 if (list[i] == hwnd) break;
628 if ((GetWindowLongW( list[i], GWL_STYLE ) & WS_POPUP) &&
629 GetWindow( list[i], GW_OWNER ) == hwnd)
631 SetWindowPos( list[i], hwndInsertAfter, 0, 0, 0, 0,
632 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE |
633 SWP_NOSENDCHANGING | SWP_DEFERERASE );
634 hwndInsertAfter = list[i];
637 HeapFree( GetProcessHeap(), 0, list );
640 return hwndInsertAfter;
644 /* fix redundant flags and values in the WINDOWPOS structure */
645 static BOOL fixup_flags( WINDOWPOS *winpos )
647 WND *wndPtr = WIN_GetPtr( winpos->hwnd );
648 BOOL ret = TRUE;
650 if (!wndPtr || wndPtr == WND_OTHER_PROCESS)
652 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
653 return FALSE;
655 winpos->hwnd = wndPtr->hwndSelf; /* make it a full handle */
657 /* Finally make sure that all coordinates are valid */
658 if (winpos->x < -32768) winpos->x = -32768;
659 else if (winpos->x > 32767) winpos->x = 32767;
660 if (winpos->y < -32768) winpos->y = -32768;
661 else if (winpos->y > 32767) winpos->y = 32767;
663 if (winpos->cx < 0) winpos->cx = 0;
664 else if (winpos->cx > 32767) winpos->cx = 32767;
665 if (winpos->cy < 0) winpos->cy = 0;
666 else if (winpos->cy > 32767) winpos->cy = 32767;
668 if (wndPtr->dwStyle & WS_VISIBLE) winpos->flags &= ~SWP_SHOWWINDOW;
669 else
671 winpos->flags &= ~SWP_HIDEWINDOW;
672 if (!(winpos->flags & SWP_SHOWWINDOW)) winpos->flags |= SWP_NOREDRAW;
675 if ((wndPtr->rectWindow.right - wndPtr->rectWindow.left == winpos->cx) &&
676 (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top == winpos->cy))
677 winpos->flags |= SWP_NOSIZE; /* Already the right size */
679 if ((wndPtr->rectWindow.left == winpos->x) && (wndPtr->rectWindow.top == winpos->y))
680 winpos->flags |= SWP_NOMOVE; /* Already the right position */
682 if (winpos->hwnd == GetActiveWindow())
683 winpos->flags |= SWP_NOACTIVATE; /* Already active */
684 else if ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD)
686 if (!(winpos->flags & SWP_NOACTIVATE)) /* Bring to the top when activating */
688 winpos->flags &= ~SWP_NOZORDER;
689 winpos->hwndInsertAfter = HWND_TOP;
693 /* Check hwndInsertAfter */
694 if (winpos->flags & SWP_NOZORDER) goto done;
696 /* fix sign extension */
697 if (winpos->hwndInsertAfter == (HWND)0xffff) winpos->hwndInsertAfter = HWND_TOPMOST;
698 else if (winpos->hwndInsertAfter == (HWND)0xfffe) winpos->hwndInsertAfter = HWND_NOTOPMOST;
700 /* FIXME: TOPMOST not supported yet */
701 if ((winpos->hwndInsertAfter == HWND_TOPMOST) ||
702 (winpos->hwndInsertAfter == HWND_NOTOPMOST)) winpos->hwndInsertAfter = HWND_TOP;
704 /* hwndInsertAfter must be a sibling of the window */
705 if (winpos->hwndInsertAfter == HWND_TOP)
707 if (GetWindow(winpos->hwnd, GW_HWNDFIRST) == winpos->hwnd)
708 winpos->flags |= SWP_NOZORDER;
710 else if (winpos->hwndInsertAfter == HWND_BOTTOM)
712 if (GetWindow(winpos->hwnd, GW_HWNDLAST) == winpos->hwnd)
713 winpos->flags |= SWP_NOZORDER;
715 else
717 if (GetAncestor( winpos->hwndInsertAfter, GA_PARENT ) != wndPtr->parent) ret = FALSE;
718 else
720 /* don't need to change the Zorder of hwnd if it's already inserted
721 * after hwndInsertAfter or when inserting hwnd after itself.
723 if ((winpos->hwnd == winpos->hwndInsertAfter) ||
724 (winpos->hwnd == GetWindow( winpos->hwndInsertAfter, GW_HWNDNEXT )))
725 winpos->flags |= SWP_NOZORDER;
728 done:
729 WIN_ReleasePtr( wndPtr );
730 return ret;
734 /***********************************************************************
735 * set_visible_style
737 * Set/clear the WS_VISIBLE style of a window and map/unmap the X window.
739 static void set_visible_style( HWND hwnd, BOOL set )
741 WND *win;
743 if (!(win = WIN_GetPtr( hwnd ))) return;
744 if (win == WND_OTHER_PROCESS) return;
746 TRACE( "hwnd %p (%lx) set %d visible %d empty %d\n",
747 hwnd, get_whole_window(win),
748 set, (win->dwStyle & WS_VISIBLE) != 0, IsRectEmpty(&win->rectWindow) );
750 if (set)
752 if (win->dwStyle & WS_VISIBLE) goto done;
753 WIN_SetStyle( hwnd, win->dwStyle | WS_VISIBLE );
754 if (X11DRV_is_window_rect_mapped( &win->rectWindow ) &&
755 get_whole_window(win) && is_window_top_level(win))
757 Display *display = thread_display();
758 X11DRV_sync_window_style( display, win );
759 X11DRV_set_wm_hints( display, win );
760 TRACE( "mapping win %p\n", hwnd );
761 wine_tsx11_lock();
762 XMapWindow( display, get_whole_window(win) );
763 wine_tsx11_unlock();
766 else
768 if (!(win->dwStyle & WS_VISIBLE)) goto done;
769 WIN_SetStyle( hwnd, win->dwStyle & ~WS_VISIBLE );
770 if (X11DRV_is_window_rect_mapped( &win->rectWindow ) &&
771 get_whole_window(win) && is_window_top_level(win))
773 TRACE( "unmapping win %p\n", hwnd );
774 wine_tsx11_lock();
775 XUnmapWindow( thread_display(), get_whole_window(win) );
776 wine_tsx11_unlock();
779 done:
780 WIN_ReleasePtr( win );
784 /***********************************************************************
785 * SetWindowStyle (X11DRV.@)
787 * Update the X state of a window to reflect a style change
789 void X11DRV_SetWindowStyle( HWND hwnd, LONG oldStyle )
791 Display *display = thread_display();
792 WND *wndPtr;
793 LONG changed;
795 if (hwnd == GetDesktopWindow()) return;
796 if (!(wndPtr = WIN_GetPtr( hwnd ))) return;
797 if (wndPtr == WND_OTHER_PROCESS) return;
799 changed = wndPtr->dwStyle ^ oldStyle;
801 if (changed & WS_VISIBLE)
803 if (X11DRV_is_window_rect_mapped( &wndPtr->rectWindow ))
805 if (wndPtr->dwStyle & WS_VISIBLE)
807 TRACE( "mapping win %p\n", hwnd );
808 if (is_window_top_level(wndPtr))
810 X11DRV_sync_window_style( display, wndPtr );
811 X11DRV_set_wm_hints( display, wndPtr );
813 wine_tsx11_lock();
814 XMapWindow( display, get_whole_window(wndPtr) );
815 wine_tsx11_unlock();
817 else if (!is_window_top_level(wndPtr)) /* don't unmap managed windows */
819 TRACE( "unmapping win %p\n", hwnd );
820 wine_tsx11_lock();
821 XUnmapWindow( display, get_whole_window(wndPtr) );
822 wine_tsx11_unlock();
827 if (changed & WS_DISABLED)
829 if (wndPtr->dwExStyle & WS_EX_MANAGED)
831 XWMHints *wm_hints;
832 wine_tsx11_lock();
833 if (!(wm_hints = XGetWMHints( display, get_whole_window(wndPtr) )))
834 wm_hints = XAllocWMHints();
835 if (wm_hints)
837 wm_hints->flags |= InputHint;
838 wm_hints->input = !(wndPtr->dwStyle & WS_DISABLED);
839 XSetWMHints( display, get_whole_window(wndPtr), wm_hints );
840 XFree(wm_hints);
842 wine_tsx11_unlock();
845 WIN_ReleasePtr(wndPtr);
849 /***********************************************************************
850 * SetWindowPos (X11DRV.@)
852 BOOL X11DRV_SetWindowPos( WINDOWPOS *winpos )
854 WND *wndPtr;
855 RECT newWindowRect, newClientRect;
856 RECT oldWindowRect, oldClientRect;
857 UINT wvrFlags = 0;
858 BOOL bChangePos;
860 TRACE( "hwnd %p, after %p, swp %d,%d %dx%d flags %08x\n",
861 winpos->hwnd, winpos->hwndInsertAfter, winpos->x, winpos->y,
862 winpos->cx, winpos->cy, winpos->flags);
864 bChangePos = !(winpos->flags & SWP_WINE_NOHOSTMOVE);
865 winpos->flags &= ~SWP_WINE_NOHOSTMOVE;
867 /* Check window handle */
868 if (winpos->hwnd == GetDesktopWindow()) return FALSE;
870 /* First make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
871 if (!(winpos->flags & SWP_NOMOVE))
873 if (winpos->x < -32768) winpos->x = -32768;
874 else if (winpos->x > 32767) winpos->x = 32767;
875 if (winpos->y < -32768) winpos->y = -32768;
876 else if (winpos->y > 32767) winpos->y = 32767;
878 if (!(winpos->flags & SWP_NOSIZE))
880 if (winpos->cx < 0) winpos->cx = 0;
881 else if (winpos->cx > 32767) winpos->cx = 32767;
882 if (winpos->cy < 0) winpos->cy = 0;
883 else if (winpos->cy > 32767) winpos->cy = 32767;
886 if (!SWP_DoWinPosChanging( winpos, &newWindowRect, &newClientRect )) return FALSE;
888 /* Fix redundant flags */
889 if (!fixup_flags( winpos )) return FALSE;
891 if (!(wndPtr = WIN_FindWndPtr( winpos->hwnd ))) return FALSE;
893 TRACE("\tcurrent (%ld,%ld)-(%ld,%ld), style %08x\n",
894 wndPtr->rectWindow.left, wndPtr->rectWindow.top,
895 wndPtr->rectWindow.right, wndPtr->rectWindow.bottom, (unsigned)wndPtr->dwStyle );
897 if((winpos->flags & (SWP_NOZORDER | SWP_HIDEWINDOW | SWP_SHOWWINDOW)) != SWP_NOZORDER)
899 if (GetAncestor( winpos->hwnd, GA_PARENT ) == GetDesktopWindow())
900 winpos->hwndInsertAfter = SWP_DoOwnedPopups( winpos->hwnd, winpos->hwndInsertAfter );
903 /* Common operations */
905 wvrFlags = SWP_DoNCCalcSize( winpos, &newWindowRect, &newClientRect );
907 if(!(winpos->flags & SWP_NOZORDER) && winpos->hwnd != winpos->hwndInsertAfter)
909 HWND parent = GetAncestor( winpos->hwnd, GA_PARENT );
910 if (parent) WIN_LinkWindow( winpos->hwnd, parent, winpos->hwndInsertAfter );
913 /* Reset active DCEs */
915 if( (((winpos->flags & SWP_AGG_NOPOSCHANGE) != SWP_AGG_NOPOSCHANGE) &&
916 wndPtr->dwStyle & WS_VISIBLE) ||
917 (winpos->flags & (SWP_HIDEWINDOW | SWP_SHOWWINDOW)) )
919 RECT rect;
921 UnionRect(&rect, &newWindowRect, &wndPtr->rectWindow);
922 DCE_InvalidateDCE(wndPtr->hwndSelf, &rect);
925 oldWindowRect = wndPtr->rectWindow;
926 oldClientRect = wndPtr->rectClient;
928 /* Find out if we have to redraw the whole client rect */
930 if( oldClientRect.bottom - oldClientRect.top ==
931 newClientRect.bottom - newClientRect.top ) wvrFlags &= ~WVR_VREDRAW;
933 if( oldClientRect.right - oldClientRect.left ==
934 newClientRect.right - newClientRect.left ) wvrFlags &= ~WVR_HREDRAW;
936 /* FIXME: actually do something with WVR_VALIDRECTS */
938 WIN_SetRectangles( winpos->hwnd, &newWindowRect, &newClientRect );
940 if (get_whole_window(wndPtr)) /* don't do anything if X window not created yet */
942 Display *display = thread_display();
944 if (!(winpos->flags & SWP_SHOWWINDOW) && (winpos->flags & SWP_HIDEWINDOW))
946 /* clear the update region */
947 RedrawWindow( winpos->hwnd, NULL, 0, RDW_VALIDATE | RDW_NOFRAME |
948 RDW_NOERASE | RDW_NOINTERNALPAINT | RDW_ALLCHILDREN );
949 set_visible_style( winpos->hwnd, FALSE );
951 else if ((wndPtr->dwStyle & WS_VISIBLE) && bChangePos &&
952 X11DRV_is_window_rect_mapped( &oldWindowRect ) &&
953 !X11DRV_is_window_rect_mapped( &newWindowRect ))
955 /* resizing to zero size or off screen -> unmap */
956 TRACE( "unmapping zero size or off-screen win %p\n", winpos->hwnd );
957 wine_tsx11_lock();
958 XUnmapWindow( display, get_whole_window(wndPtr) );
959 wine_tsx11_unlock();
962 wine_tsx11_lock();
963 if (bChangePos)
964 X11DRV_sync_whole_window_position( display, wndPtr, !(winpos->flags & SWP_NOZORDER) );
965 else
967 struct x11drv_win_data *data = wndPtr->pDriverData;
968 data->whole_rect = wndPtr->rectWindow;
969 X11DRV_window_to_X_rect( wndPtr, &data->whole_rect );
972 if (X11DRV_sync_client_window_position( display, wndPtr ) ||
973 (winpos->flags & SWP_FRAMECHANGED))
975 /* if we moved the client area, repaint the whole non-client window */
976 XClearArea( display, get_whole_window(wndPtr), 0, 0, 0, 0, True );
977 winpos->flags |= SWP_FRAMECHANGED;
979 if (winpos->flags & SWP_SHOWWINDOW)
981 set_visible_style( winpos->hwnd, TRUE );
983 else if ((wndPtr->dwStyle & WS_VISIBLE) && bChangePos &&
984 !X11DRV_is_window_rect_mapped( &oldWindowRect ) &&
985 X11DRV_is_window_rect_mapped( &newWindowRect ))
987 /* resizing from zero size to non-zero -> map */
988 TRACE( "mapping non zero size or off-screen win %p\n", winpos->hwnd );
989 XMapWindow( display, get_whole_window(wndPtr) );
991 XFlush( display ); /* FIXME: should not be necessary */
992 wine_tsx11_unlock();
994 else /* no X window, simply toggle the window style */
996 if (winpos->flags & SWP_SHOWWINDOW)
997 set_visible_style( winpos->hwnd, TRUE );
998 else if (winpos->flags & SWP_HIDEWINDOW)
999 set_visible_style( winpos->hwnd, FALSE );
1002 /* manually expose the areas that X won't expose because they are still covered by something */
1004 if (!(winpos->flags & SWP_SHOWWINDOW))
1005 expose_covered_parent_area( wndPtr, &oldWindowRect );
1007 if (wndPtr->dwStyle & WS_VISIBLE)
1008 expose_covered_window_area( wndPtr, &oldClientRect, winpos->flags & SWP_FRAMECHANGED );
1010 WIN_ReleaseWndPtr(wndPtr);
1012 if (wvrFlags & WVR_REDRAW) RedrawWindow( winpos->hwnd, NULL, 0, RDW_INVALIDATE | RDW_ERASE );
1014 if( winpos->flags & SWP_HIDEWINDOW )
1015 HideCaret(winpos->hwnd);
1016 else if (winpos->flags & SWP_SHOWWINDOW)
1017 ShowCaret(winpos->hwnd);
1019 if (!(winpos->flags & SWP_NOACTIVATE))
1021 /* child windows get WM_CHILDACTIVATE message */
1022 if ((GetWindowLongW( winpos->hwnd, GWL_STYLE ) & (WS_CHILD | WS_POPUP)) == WS_CHILD)
1023 SendMessageA( winpos->hwnd, WM_CHILDACTIVATE, 0, 0 );
1024 else
1025 SetForegroundWindow( winpos->hwnd );
1028 /* And last, send the WM_WINDOWPOSCHANGED message */
1030 TRACE("\tstatus flags = %04x\n", winpos->flags & SWP_AGG_STATUSFLAGS);
1032 if (((winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOPOSCHANGE))
1034 /* WM_WINDOWPOSCHANGED is sent even if SWP_NOSENDCHANGING is set
1035 and always contains final window position.
1037 winpos->x = newWindowRect.left;
1038 winpos->y = newWindowRect.top;
1039 winpos->cx = newWindowRect.right - newWindowRect.left;
1040 winpos->cy = newWindowRect.bottom - newWindowRect.top;
1041 SendMessageW( winpos->hwnd, WM_WINDOWPOSCHANGED, 0, (LPARAM)winpos );
1044 return TRUE;
1048 /***********************************************************************
1049 * WINPOS_FindIconPos
1051 * Find a suitable place for an iconic window.
1053 static POINT WINPOS_FindIconPos( WND* wndPtr, POINT pt )
1055 RECT rectParent;
1056 HWND *list;
1057 short x, y, xspacing, yspacing;
1059 GetClientRect( wndPtr->parent, &rectParent );
1060 if ((pt.x >= rectParent.left) && (pt.x + GetSystemMetrics(SM_CXICON) < rectParent.right) &&
1061 (pt.y >= rectParent.top) && (pt.y + GetSystemMetrics(SM_CYICON) < rectParent.bottom))
1062 return pt; /* The icon already has a suitable position */
1064 xspacing = GetSystemMetrics(SM_CXICONSPACING);
1065 yspacing = GetSystemMetrics(SM_CYICONSPACING);
1067 list = WIN_ListChildren( wndPtr->parent );
1068 y = rectParent.bottom;
1069 for (;;)
1071 x = rectParent.left;
1074 /* Check if another icon already occupies this spot */
1075 /* FIXME: this is completely inefficient */
1076 if (list)
1078 int i;
1079 WND *childPtr;
1081 for (i = 0; list[i]; i++)
1083 if (list[i] == wndPtr->hwndSelf) continue;
1084 if (!IsIconic( list[i] )) continue;
1085 if (!(childPtr = WIN_FindWndPtr( list[i] ))) continue;
1086 if ((childPtr->rectWindow.left < x + xspacing) &&
1087 (childPtr->rectWindow.right >= x) &&
1088 (childPtr->rectWindow.top <= y) &&
1089 (childPtr->rectWindow.bottom > y - yspacing))
1091 WIN_ReleaseWndPtr( childPtr );
1092 break; /* There's a window in there */
1094 WIN_ReleaseWndPtr( childPtr );
1096 if (list[i])
1098 /* found something here, try next spot */
1099 x += xspacing;
1100 continue;
1104 /* No window was found, so it's OK for us */
1105 pt.x = x + (xspacing - GetSystemMetrics(SM_CXICON)) / 2;
1106 pt.y = y - (yspacing + GetSystemMetrics(SM_CYICON)) / 2;
1107 HeapFree( GetProcessHeap(), 0, list );
1108 return pt;
1110 } while(x <= rectParent.right-xspacing);
1111 y -= yspacing;
1119 UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect )
1121 WND *wndPtr;
1122 UINT swpFlags = 0;
1123 POINT size;
1124 LONG old_style;
1125 WINDOWPLACEMENT wpl;
1127 TRACE("%p %u\n", hwnd, cmd );
1129 wpl.length = sizeof(wpl);
1130 GetWindowPlacement( hwnd, &wpl );
1132 if (HOOK_CallHooks( WH_CBT, HCBT_MINMAX, (WPARAM)hwnd, cmd, TRUE ))
1133 return SWP_NOSIZE | SWP_NOMOVE;
1135 if (IsIconic( hwnd ))
1137 if (cmd == SW_MINIMIZE) return SWP_NOSIZE | SWP_NOMOVE;
1138 if (!SendMessageA( hwnd, WM_QUERYOPEN, 0, 0 )) return SWP_NOSIZE | SWP_NOMOVE;
1139 swpFlags |= SWP_NOCOPYBITS;
1142 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
1144 size.x = wndPtr->rectWindow.left;
1145 size.y = wndPtr->rectWindow.top;
1147 switch( cmd )
1149 case SW_MINIMIZE:
1150 if( wndPtr->dwStyle & WS_MAXIMIZE) wndPtr->flags |= WIN_RESTORE_MAX;
1151 else wndPtr->flags &= ~WIN_RESTORE_MAX;
1153 WIN_SetStyle( hwnd, (wndPtr->dwStyle & ~WS_MAXIMIZE) | WS_MINIMIZE );
1155 X11DRV_set_iconic_state( wndPtr );
1157 wpl.ptMinPosition = WINPOS_FindIconPos( wndPtr, wpl.ptMinPosition );
1159 SetRect( rect, wpl.ptMinPosition.x, wpl.ptMinPosition.y,
1160 GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON) );
1161 swpFlags |= SWP_NOCOPYBITS;
1162 break;
1164 case SW_MAXIMIZE:
1165 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL );
1167 old_style = WIN_SetStyle( hwnd, (wndPtr->dwStyle & ~WS_MINIMIZE) | WS_MAXIMIZE );
1168 if (old_style & WS_MINIMIZE)
1170 WINPOS_ShowIconTitle( hwnd, FALSE );
1171 X11DRV_set_iconic_state( wndPtr );
1173 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y );
1174 break;
1176 case SW_RESTORE:
1177 old_style = WIN_SetStyle( hwnd, wndPtr->dwStyle & ~(WS_MINIMIZE|WS_MAXIMIZE) );
1178 if (old_style & WS_MINIMIZE)
1180 WINPOS_ShowIconTitle( hwnd, FALSE );
1181 X11DRV_set_iconic_state( wndPtr );
1183 if( wndPtr->flags & WIN_RESTORE_MAX)
1185 /* Restore to maximized position */
1186 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL);
1187 WIN_SetStyle( hwnd, wndPtr->dwStyle | WS_MAXIMIZE );
1188 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y );
1189 break;
1192 else if (!(old_style & WS_MAXIMIZE)) break;
1194 /* Restore to normal position */
1196 *rect = wpl.rcNormalPosition;
1197 rect->right -= rect->left;
1198 rect->bottom -= rect->top;
1200 break;
1203 WIN_ReleaseWndPtr( wndPtr );
1204 return swpFlags;
1208 /***********************************************************************
1209 * ShowWindow (X11DRV.@)
1211 BOOL X11DRV_ShowWindow( HWND hwnd, INT cmd )
1213 WND* wndPtr = WIN_FindWndPtr( hwnd );
1214 BOOL wasVisible, showFlag;
1215 RECT newPos = {0, 0, 0, 0};
1216 UINT swp = 0;
1218 if (!wndPtr) return FALSE;
1219 hwnd = wndPtr->hwndSelf; /* make it a full handle */
1221 wasVisible = (wndPtr->dwStyle & WS_VISIBLE) != 0;
1223 TRACE("hwnd=%p, cmd=%d, wasVisible %d\n", hwnd, cmd, wasVisible);
1225 switch(cmd)
1227 case SW_HIDE:
1228 if (!wasVisible) goto END;
1229 swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE |
1230 SWP_NOACTIVATE | SWP_NOZORDER;
1231 break;
1233 case SW_SHOWMINNOACTIVE:
1234 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1235 /* fall through */
1236 case SW_SHOWMINIMIZED:
1237 case SW_FORCEMINIMIZE: /* FIXME: Does not work if thread is hung. */
1238 swp |= SWP_SHOWWINDOW;
1239 /* fall through */
1240 case SW_MINIMIZE:
1241 swp |= SWP_FRAMECHANGED;
1242 if( !(wndPtr->dwStyle & WS_MINIMIZE) )
1243 swp |= WINPOS_MinMaximize( hwnd, SW_MINIMIZE, &newPos );
1244 else swp |= SWP_NOSIZE | SWP_NOMOVE;
1245 break;
1247 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
1248 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
1249 if( !(wndPtr->dwStyle & WS_MAXIMIZE) )
1250 swp |= WINPOS_MinMaximize( hwnd, SW_MAXIMIZE, &newPos );
1251 else swp |= SWP_NOSIZE | SWP_NOMOVE;
1252 break;
1254 case SW_SHOWNA:
1255 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1256 /* fall through */
1257 case SW_SHOW:
1258 if (wasVisible) goto END;
1260 swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
1261 break;
1263 case SW_SHOWNOACTIVATE:
1264 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1265 /* fall through */
1266 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
1267 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
1268 case SW_RESTORE:
1269 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
1271 if( wndPtr->dwStyle & (WS_MINIMIZE | WS_MAXIMIZE) )
1272 swp |= WINPOS_MinMaximize( hwnd, SW_RESTORE, &newPos );
1273 else swp |= SWP_NOSIZE | SWP_NOMOVE;
1274 break;
1277 showFlag = (cmd != SW_HIDE);
1278 if (showFlag != wasVisible)
1280 SendMessageW( hwnd, WM_SHOWWINDOW, showFlag, 0 );
1281 if (!IsWindow( hwnd )) goto END;
1284 /* We can't activate a child window */
1285 if ((wndPtr->dwStyle & WS_CHILD) &&
1286 !(wndPtr->dwExStyle & WS_EX_MDICHILD))
1287 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1289 SetWindowPos( hwnd, HWND_TOP, newPos.left, newPos.top,
1290 newPos.right, newPos.bottom, LOWORD(swp) );
1291 if (cmd == SW_HIDE)
1293 HWND hFocus;
1295 /* FIXME: This will cause the window to be activated irrespective
1296 * of whether it is owned by the same thread. Has to be done
1297 * asynchronously.
1300 if (hwnd == GetActiveWindow())
1301 WINPOS_ActivateOtherWindow(hwnd);
1303 /* Revert focus to parent */
1304 hFocus = GetFocus();
1305 if (hwnd == hFocus || IsChild(hwnd, hFocus))
1307 HWND parent = GetAncestor(hwnd, GA_PARENT);
1308 if (parent == GetDesktopWindow()) parent = 0;
1309 SetFocus(parent);
1312 if (!IsWindow( hwnd )) goto END;
1313 else if( wndPtr->dwStyle & WS_MINIMIZE ) WINPOS_ShowIconTitle( hwnd, TRUE );
1315 if (wndPtr->flags & WIN_NEED_SIZE)
1317 /* should happen only in CreateWindowEx() */
1318 int wParam = SIZE_RESTORED;
1320 wndPtr->flags &= ~WIN_NEED_SIZE;
1321 if (wndPtr->dwStyle & WS_MAXIMIZE) wParam = SIZE_MAXIMIZED;
1322 else if (wndPtr->dwStyle & WS_MINIMIZE) wParam = SIZE_MINIMIZED;
1323 SendMessageA( hwnd, WM_SIZE, wParam,
1324 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
1325 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
1326 SendMessageA( hwnd, WM_MOVE, 0,
1327 MAKELONG(wndPtr->rectClient.left, wndPtr->rectClient.top) );
1330 END:
1331 WIN_ReleaseWndPtr(wndPtr);
1332 return wasVisible;
1336 /**********************************************************************
1337 * X11DRV_MapNotify
1339 void X11DRV_MapNotify( HWND hwnd, XMapEvent *event )
1341 HWND hwndFocus = GetFocus();
1342 WND *win;
1344 if (!(win = WIN_GetPtr( hwnd ))) return;
1346 if ((win->dwStyle & WS_VISIBLE) &&
1347 (win->dwStyle & WS_MINIMIZE) &&
1348 (win->dwExStyle & WS_EX_MANAGED))
1350 int x, y;
1351 unsigned int width, height, border, depth;
1352 Window root, top;
1353 RECT rect;
1354 LONG style = (win->dwStyle & ~(WS_MINIMIZE|WS_MAXIMIZE)) | WS_VISIBLE;
1356 /* FIXME: hack */
1357 wine_tsx11_lock();
1358 XGetGeometry( event->display, get_whole_window(win), &root, &x, &y, &width, &height,
1359 &border, &depth );
1360 XTranslateCoordinates( event->display, get_whole_window(win), root, 0, 0, &x, &y, &top );
1361 wine_tsx11_unlock();
1362 rect.left = x;
1363 rect.top = y;
1364 rect.right = x + width;
1365 rect.bottom = y + height;
1366 X11DRV_X_to_window_rect( win, &rect );
1368 DCE_InvalidateDCE( hwnd, &win->rectWindow );
1370 if (win->flags & WIN_RESTORE_MAX) style |= WS_MAXIMIZE;
1371 WIN_SetStyle( hwnd, style );
1372 WIN_ReleasePtr( win );
1374 SendMessageA( hwnd, WM_SHOWWINDOW, SW_RESTORE, 0 );
1375 SetWindowPos( hwnd, 0, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
1376 SWP_NOZORDER | SWP_WINE_NOHOSTMOVE );
1378 else WIN_ReleasePtr( win );
1379 if (hwndFocus && IsChild( hwnd, hwndFocus )) X11DRV_SetFocus(hwndFocus); /* FIXME */
1383 /**********************************************************************
1384 * X11DRV_UnmapNotify
1386 void X11DRV_UnmapNotify( HWND hwnd, XUnmapEvent *event )
1388 WND *win;
1390 if (!(win = WIN_GetPtr( hwnd ))) return;
1392 if ((win->dwStyle & WS_VISIBLE) && (win->dwExStyle & WS_EX_MANAGED) &&
1393 X11DRV_is_window_rect_mapped( &win->rectWindow ))
1395 if (win->dwStyle & WS_MAXIMIZE)
1396 win->flags |= WIN_RESTORE_MAX;
1397 else
1398 win->flags &= ~WIN_RESTORE_MAX;
1400 WIN_SetStyle( hwnd, (win->dwStyle & ~WS_MAXIMIZE) | WS_MINIMIZE );
1401 WIN_ReleasePtr( win );
1403 EndMenu();
1404 SendMessageA( hwnd, WM_SHOWWINDOW, SW_MINIMIZE, 0 );
1405 SetWindowPos( hwnd, 0, 0, 0, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON),
1406 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_WINE_NOHOSTMOVE );
1408 else WIN_ReleasePtr( win );
1412 /***********************************************************************
1413 * query_zorder
1415 * Synchronize internal z-order with the window manager's.
1417 static Window __get_common_ancestor( Display *display, Window A, Window B,
1418 Window** children, unsigned* total )
1420 /* find the real root window */
1422 Window root, *childrenB;
1423 unsigned totalB;
1425 wine_tsx11_lock();
1426 while( A != B && A && B )
1428 XQueryTree( display, A, &root, &A, children, total );
1429 XQueryTree( display, B, &root, &B, &childrenB, &totalB );
1430 if( childrenB ) XFree( childrenB );
1431 if( *children ) XFree( *children ), *children = NULL;
1434 if( A && B )
1436 XQueryTree( display, A, &root, &B, children, total );
1437 wine_tsx11_unlock();
1438 return A;
1440 wine_tsx11_unlock();
1441 return 0 ;
1444 static Window __get_top_decoration( Display *display, Window w, Window ancestor )
1446 Window* children, root, prev = w, parent = w;
1447 unsigned total;
1449 wine_tsx11_lock();
1452 w = parent;
1453 XQueryTree( display, w, &root, &parent, &children, &total );
1454 if( children ) XFree( children );
1455 } while( parent && parent != ancestor );
1456 wine_tsx11_unlock();
1457 TRACE("\t%08x -> %08x\n", (unsigned)prev, (unsigned)w );
1458 return ( parent ) ? w : 0 ;
1461 static unsigned __td_lookup( Window w, Window* list, unsigned max )
1463 unsigned i;
1464 for( i = max; i > 0; i-- ) if( list[i - 1] == w ) break;
1465 return i;
1468 static HWND query_zorder( Display *display, HWND hWndCheck)
1470 HWND hwndInsertAfter = HWND_TOP;
1471 Window w, parent, *children = NULL;
1472 unsigned total, check, pos, best;
1473 HWND *list = WIN_ListChildren( GetDesktopWindow() );
1474 HWND hwndA = 0, hwndB = 0;
1475 int i;
1477 /* find at least two managed windows */
1478 if (!list) return 0;
1479 for (i = 0; list[i]; i++)
1481 if (!(GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_MANAGED)) continue;
1482 if (!(GetWindowLongW( list[i], GWL_STYLE ) & WS_VISIBLE)) continue;
1483 if (!hwndA) hwndA = list[i];
1484 else
1486 hwndB = list[i];
1487 break;
1490 if (!hwndA || !hwndB) goto done;
1492 parent = __get_common_ancestor( display, X11DRV_get_whole_window(hwndA),
1493 X11DRV_get_whole_window(hwndB), &children, &total );
1494 if( parent && children )
1496 /* w is the ancestor if hWndCheck that is a direct descendant of 'parent' */
1498 w = __get_top_decoration( display, X11DRV_get_whole_window(hWndCheck), parent );
1500 if( w != children[total-1] ) /* check if at the top */
1502 /* X child at index 0 is at the bottom, at index total-1 is at the top */
1503 check = __td_lookup( w, children, total );
1504 best = total;
1506 /* go through all windows in Wine z-order... */
1507 for (i = 0; list[i]; i++)
1509 if (list[i] == hWndCheck) continue;
1510 if (!(GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_MANAGED)) continue;
1511 if (!(w = __get_top_decoration( display, X11DRV_get_whole_window(list[i]),
1512 parent ))) continue;
1513 pos = __td_lookup( w, children, total );
1514 if( pos < best && pos > check )
1516 /* find a nearest Wine window precedes hWndCheck in the real z-order */
1517 best = pos;
1518 hwndInsertAfter = list[i];
1520 if( best - check == 1 ) break;
1524 wine_tsx11_lock();
1525 if( children ) XFree( children );
1526 wine_tsx11_unlock();
1528 done:
1529 HeapFree( GetProcessHeap(), 0, list );
1530 return hwndInsertAfter;
1534 /***********************************************************************
1535 * X11DRV_handle_desktop_resize
1537 void X11DRV_handle_desktop_resize( unsigned int width, unsigned int height )
1539 RECT rect;
1540 HWND hwnd = GetDesktopWindow();
1542 screen_width = width;
1543 screen_height = height;
1544 TRACE("desktop %p change to (%dx%d)\n", hwnd, width, height);
1545 SetRect( &rect, 0, 0, width, height );
1546 WIN_SetRectangles( hwnd, &rect, &rect );
1547 SendMessageTimeoutW( HWND_BROADCAST, WM_DISPLAYCHANGE, screen_depth,
1548 MAKELPARAM( width, height ), SMTO_ABORTIFHUNG, 2000, NULL );
1552 /***********************************************************************
1553 * X11DRV_ConfigureNotify
1555 void X11DRV_ConfigureNotify( HWND hwnd, XConfigureEvent *event )
1557 HWND oldInsertAfter;
1558 struct x11drv_win_data *data;
1559 WND *win;
1560 RECT rect;
1561 WINDOWPOS winpos;
1562 int x = event->x, y = event->y;
1564 if (!(win = WIN_GetPtr( hwnd ))) return;
1565 data = win->pDriverData;
1567 /* Get geometry */
1569 if (!event->send_event) /* normal event, need to map coordinates to the root */
1571 Window child;
1572 wine_tsx11_lock();
1573 XTranslateCoordinates( event->display, data->whole_window, root_window,
1574 0, 0, &x, &y, &child );
1575 wine_tsx11_unlock();
1577 rect.left = x;
1578 rect.top = y;
1579 rect.right = x + event->width;
1580 rect.bottom = y + event->height;
1581 TRACE( "win %p new X rect %ld,%ld,%ldx%ld (event %d,%d,%dx%d)\n",
1582 hwnd, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
1583 event->x, event->y, event->width, event->height );
1584 X11DRV_X_to_window_rect( win, &rect );
1585 WIN_ReleasePtr( win );
1587 winpos.hwnd = hwnd;
1588 winpos.x = rect.left;
1589 winpos.y = rect.top;
1590 winpos.cx = rect.right - rect.left;
1591 winpos.cy = rect.bottom - rect.top;
1592 winpos.flags = SWP_NOACTIVATE;
1594 /* Get Z-order (FIXME) */
1596 winpos.hwndInsertAfter = query_zorder( event->display, hwnd );
1598 /* needs to find the first Visible Window above the current one */
1599 oldInsertAfter = hwnd;
1600 for (;;)
1602 oldInsertAfter = GetWindow( oldInsertAfter, GW_HWNDPREV );
1603 if (!oldInsertAfter)
1605 oldInsertAfter = HWND_TOP;
1606 break;
1608 if (GetWindowLongA( oldInsertAfter, GWL_STYLE ) & WS_VISIBLE) break;
1611 /* Compare what has changed */
1613 GetWindowRect( hwnd, &rect );
1614 if (rect.left == winpos.x && rect.top == winpos.y) winpos.flags |= SWP_NOMOVE;
1615 else
1616 TRACE( "%p moving from (%ld,%ld) to (%d,%d)\n",
1617 hwnd, rect.left, rect.top, winpos.x, winpos.y );
1619 if ((rect.right - rect.left == winpos.cx && rect.bottom - rect.top == winpos.cy) ||
1620 IsIconic(hwnd) ||
1621 (IsRectEmpty( &rect ) && winpos.cx == 1 && winpos.cy == 1))
1622 winpos.flags |= SWP_NOSIZE;
1623 else
1624 TRACE( "%p resizing from (%ldx%ld) to (%dx%d)\n",
1625 hwnd, rect.right - rect.left, rect.bottom - rect.top,
1626 winpos.cx, winpos.cy );
1628 if (winpos.hwndInsertAfter == oldInsertAfter) winpos.flags |= SWP_NOZORDER;
1629 else
1630 TRACE( "%p restacking from after %p to after %p\n",
1631 hwnd, oldInsertAfter, winpos.hwndInsertAfter );
1633 /* if nothing changed, don't do anything */
1634 if (winpos.flags == (SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE)) return;
1636 SetWindowPos( hwnd, winpos.hwndInsertAfter, winpos.x, winpos.y,
1637 winpos.cx, winpos.cy, winpos.flags | SWP_WINE_NOHOSTMOVE );
1641 /***********************************************************************
1642 * SetWindowRgn (X11DRV.@)
1644 * Assign specified region to window (for non-rectangular windows)
1646 int X11DRV_SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL redraw )
1648 WND *wndPtr;
1650 if ((wndPtr = WIN_GetPtr( hwnd )) == WND_OTHER_PROCESS)
1652 if (IsWindow( hwnd ))
1653 FIXME( "not supported on other process window %p\n", hwnd );
1654 wndPtr = NULL;
1656 if (!wndPtr)
1658 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1659 return FALSE;
1662 #ifdef HAVE_LIBXSHAPE
1664 Display *display = thread_display();
1665 X11DRV_WND_DATA *data = wndPtr->pDriverData;
1667 if (data->whole_window)
1669 if (!hrgn)
1671 wine_tsx11_lock();
1672 XShapeCombineMask( display, data->whole_window,
1673 ShapeBounding, 0, 0, None, ShapeSet );
1674 wine_tsx11_unlock();
1676 else
1678 RGNDATA *pRegionData = X11DRV_GetRegionData( hrgn, 0 );
1679 if (pRegionData)
1681 wine_tsx11_lock();
1682 XShapeCombineRectangles( display, data->whole_window, ShapeBounding,
1683 wndPtr->rectWindow.left - data->whole_rect.left,
1684 wndPtr->rectWindow.top - data->whole_rect.top,
1685 (XRectangle *)pRegionData->Buffer,
1686 pRegionData->rdh.nCount,
1687 ShapeSet, YXBanded );
1688 wine_tsx11_unlock();
1689 HeapFree(GetProcessHeap(), 0, pRegionData);
1694 #endif /* HAVE_LIBXSHAPE */
1696 WIN_ReleasePtr( wndPtr );
1697 return TRUE;
1701 /***********************************************************************
1702 * draw_moving_frame
1704 * Draw the frame used when moving or resizing window.
1706 * FIXME: This causes problems in Win95 mode. (why?)
1708 static void draw_moving_frame( HDC hdc, RECT *rect, BOOL thickframe )
1710 if (thickframe)
1712 const int width = GetSystemMetrics(SM_CXFRAME);
1713 const int height = GetSystemMetrics(SM_CYFRAME);
1715 HBRUSH hbrush = SelectObject( hdc, GetStockObject( GRAY_BRUSH ) );
1716 PatBlt( hdc, rect->left, rect->top,
1717 rect->right - rect->left - width, height, PATINVERT );
1718 PatBlt( hdc, rect->left, rect->top + height, width,
1719 rect->bottom - rect->top - height, PATINVERT );
1720 PatBlt( hdc, rect->left + width, rect->bottom - 1,
1721 rect->right - rect->left - width, -height, PATINVERT );
1722 PatBlt( hdc, rect->right - 1, rect->top, -width,
1723 rect->bottom - rect->top - height, PATINVERT );
1724 SelectObject( hdc, hbrush );
1726 else DrawFocusRect( hdc, rect );
1730 /***********************************************************************
1731 * start_size_move
1733 * Initialisation of a move or resize, when initiatied from a menu choice.
1734 * Return hit test code for caption or sizing border.
1736 static LONG start_size_move( HWND hwnd, WPARAM wParam, POINT *capturePoint, LONG style )
1738 LONG hittest = 0;
1739 POINT pt;
1740 MSG msg;
1741 RECT rectWindow;
1743 GetWindowRect( hwnd, &rectWindow );
1745 if ((wParam & 0xfff0) == SC_MOVE)
1747 /* Move pointer at the center of the caption */
1748 RECT rect;
1749 NC_GetInsideRect( hwnd, &rect );
1750 if (style & WS_SYSMENU)
1751 rect.left += GetSystemMetrics(SM_CXSIZE) + 1;
1752 if (style & WS_MINIMIZEBOX)
1753 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1754 if (style & WS_MAXIMIZEBOX)
1755 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1756 pt.x = rectWindow.left + (rect.right - rect.left) / 2;
1757 pt.y = rectWindow.top + rect.top + GetSystemMetrics(SM_CYSIZE)/2;
1758 hittest = HTCAPTION;
1759 *capturePoint = pt;
1761 else /* SC_SIZE */
1763 while(!hittest)
1765 GetMessageW( &msg, 0, WM_KEYFIRST, WM_MOUSELAST );
1766 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
1768 switch(msg.message)
1770 case WM_MOUSEMOVE:
1771 hittest = NC_HandleNCHitTest( hwnd, msg.pt );
1772 if ((hittest < HTLEFT) || (hittest > HTBOTTOMRIGHT))
1773 hittest = 0;
1774 break;
1776 case WM_LBUTTONUP:
1777 return 0;
1779 case WM_KEYDOWN:
1780 switch(msg.wParam)
1782 case VK_UP:
1783 hittest = HTTOP;
1784 pt.x =(rectWindow.left+rectWindow.right)/2;
1785 pt.y = rectWindow.top + GetSystemMetrics(SM_CYFRAME) / 2;
1786 break;
1787 case VK_DOWN:
1788 hittest = HTBOTTOM;
1789 pt.x =(rectWindow.left+rectWindow.right)/2;
1790 pt.y = rectWindow.bottom - GetSystemMetrics(SM_CYFRAME) / 2;
1791 break;
1792 case VK_LEFT:
1793 hittest = HTLEFT;
1794 pt.x = rectWindow.left + GetSystemMetrics(SM_CXFRAME) / 2;
1795 pt.y =(rectWindow.top+rectWindow.bottom)/2;
1796 break;
1797 case VK_RIGHT:
1798 hittest = HTRIGHT;
1799 pt.x = rectWindow.right - GetSystemMetrics(SM_CXFRAME) / 2;
1800 pt.y =(rectWindow.top+rectWindow.bottom)/2;
1801 break;
1802 case VK_RETURN:
1803 case VK_ESCAPE: return 0;
1807 *capturePoint = pt;
1809 SetCursorPos( pt.x, pt.y );
1810 NC_HandleSetCursor( hwnd, (WPARAM)hwnd, MAKELONG( hittest, WM_MOUSEMOVE ));
1811 return hittest;
1815 /***********************************************************************
1816 * set_movesize_capture
1818 static void set_movesize_capture( HWND hwnd )
1820 HWND previous = 0;
1822 SERVER_START_REQ( set_capture_window )
1824 req->handle = hwnd;
1825 req->flags = CAPTURE_MOVESIZE;
1826 if (!wine_server_call_err( req ))
1828 previous = reply->previous;
1829 hwnd = reply->full_handle;
1832 SERVER_END_REQ;
1833 if (previous && previous != hwnd)
1834 SendMessageW( previous, WM_CAPTURECHANGED, 0, (LPARAM)hwnd );
1838 /***********************************************************************
1839 * SysCommandSizeMove (X11DRV.@)
1841 * Perform SC_MOVE and SC_SIZE commands.
1843 void X11DRV_SysCommandSizeMove( HWND hwnd, WPARAM wParam )
1845 MSG msg;
1846 RECT sizingRect, mouseRect, origRect;
1847 HDC hdc;
1848 HWND parent;
1849 LONG hittest = (LONG)(wParam & 0x0f);
1850 HCURSOR hDragCursor = 0, hOldCursor = 0;
1851 POINT minTrack, maxTrack;
1852 POINT capturePoint, pt;
1853 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
1854 LONG exstyle = GetWindowLongA( hwnd, GWL_EXSTYLE );
1855 BOOL thickframe = HAS_THICKFRAME( style, exstyle );
1856 BOOL iconic = style & WS_MINIMIZE;
1857 BOOL moved = FALSE;
1858 DWORD dwPoint = GetMessagePos ();
1859 BOOL DragFullWindows = FALSE;
1860 BOOL grab;
1861 int iWndsLocks;
1862 Display *old_gdi_display = NULL;
1863 Display *display = thread_display();
1865 SystemParametersInfoA(SPI_GETDRAGFULLWINDOWS, 0, &DragFullWindows, 0);
1867 pt.x = (short)LOWORD(dwPoint);
1868 pt.y = (short)HIWORD(dwPoint);
1869 capturePoint = pt;
1871 if (IsZoomed(hwnd) || !IsWindowVisible(hwnd) || (exstyle & WS_EX_MANAGED)) return;
1873 if ((wParam & 0xfff0) == SC_MOVE)
1875 if (!hittest) hittest = start_size_move( hwnd, wParam, &capturePoint, style );
1876 if (!hittest) return;
1878 else /* SC_SIZE */
1880 if (!thickframe) return;
1881 if ( hittest && ((wParam & 0xfff0) != SC_MOUSEMENU) )
1882 hittest += (HTLEFT - WMSZ_LEFT);
1883 else
1885 set_movesize_capture( hwnd );
1886 hittest = start_size_move( hwnd, wParam, &capturePoint, style );
1887 if (!hittest)
1889 set_movesize_capture(0);
1890 return;
1895 /* Get min/max info */
1897 WINPOS_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack );
1898 GetWindowRect( hwnd, &sizingRect );
1899 if (style & WS_CHILD)
1901 parent = GetParent(hwnd);
1902 /* make sizing rect relative to parent */
1903 MapWindowPoints( 0, parent, (POINT*)&sizingRect, 2 );
1904 GetClientRect( parent, &mouseRect );
1906 else
1908 parent = 0;
1909 SetRect(&mouseRect, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
1911 origRect = sizingRect;
1913 if (ON_LEFT_BORDER(hittest))
1915 mouseRect.left = max( mouseRect.left, sizingRect.right-maxTrack.x );
1916 mouseRect.right = min( mouseRect.right, sizingRect.right-minTrack.x );
1918 else if (ON_RIGHT_BORDER(hittest))
1920 mouseRect.left = max( mouseRect.left, sizingRect.left+minTrack.x );
1921 mouseRect.right = min( mouseRect.right, sizingRect.left+maxTrack.x );
1923 if (ON_TOP_BORDER(hittest))
1925 mouseRect.top = max( mouseRect.top, sizingRect.bottom-maxTrack.y );
1926 mouseRect.bottom = min( mouseRect.bottom,sizingRect.bottom-minTrack.y);
1928 else if (ON_BOTTOM_BORDER(hittest))
1930 mouseRect.top = max( mouseRect.top, sizingRect.top+minTrack.y );
1931 mouseRect.bottom = min( mouseRect.bottom, sizingRect.top+maxTrack.y );
1933 if (parent) MapWindowPoints( parent, 0, (LPPOINT)&mouseRect, 2 );
1935 /* Retrieve a default cache DC (without using the window style) */
1936 hdc = GetDCEx( parent, 0, DCX_CACHE );
1938 if( iconic ) /* create a cursor for dragging */
1940 hDragCursor = (HCURSOR)GetClassLongA( hwnd, GCL_HICON);
1941 if( !hDragCursor ) hDragCursor = (HCURSOR)SendMessageA( hwnd, WM_QUERYDRAGICON, 0, 0L);
1942 if( !hDragCursor ) iconic = FALSE;
1945 /* repaint the window before moving it around */
1946 RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN );
1948 SendMessageA( hwnd, WM_ENTERSIZEMOVE, 0, 0 );
1949 set_movesize_capture( hwnd );
1951 /* grab the server only when moving top-level windows without desktop */
1952 grab = (!DragFullWindows && !parent && (root_window == DefaultRootWindow(gdi_display)));
1954 wine_tsx11_lock();
1955 if (grab)
1957 XSync( gdi_display, False );
1958 XGrabServer( display );
1959 XSync( display, False );
1960 /* switch gdi display to the thread display, since the server is grabbed */
1961 old_gdi_display = gdi_display;
1962 gdi_display = display;
1964 XGrabPointer( display, X11DRV_get_whole_window(hwnd), False,
1965 PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
1966 GrabModeAsync, GrabModeAsync,
1967 parent ? X11DRV_get_client_window(parent) : root_window,
1968 None, CurrentTime );
1969 wine_tsx11_unlock();
1971 while(1)
1973 int dx = 0, dy = 0;
1975 if (!GetMessageW( &msg, 0, WM_KEYFIRST, WM_MOUSELAST )) break;
1976 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
1978 /* Exit on button-up, Return, or Esc */
1979 if ((msg.message == WM_LBUTTONUP) ||
1980 ((msg.message == WM_KEYDOWN) &&
1981 ((msg.wParam == VK_RETURN) || (msg.wParam == VK_ESCAPE)))) break;
1983 if ((msg.message != WM_KEYDOWN) && (msg.message != WM_MOUSEMOVE))
1984 continue; /* We are not interested in other messages */
1986 pt = msg.pt;
1988 if (msg.message == WM_KEYDOWN) switch(msg.wParam)
1990 case VK_UP: pt.y -= 8; break;
1991 case VK_DOWN: pt.y += 8; break;
1992 case VK_LEFT: pt.x -= 8; break;
1993 case VK_RIGHT: pt.x += 8; break;
1996 pt.x = max( pt.x, mouseRect.left );
1997 pt.x = min( pt.x, mouseRect.right );
1998 pt.y = max( pt.y, mouseRect.top );
1999 pt.y = min( pt.y, mouseRect.bottom );
2001 dx = pt.x - capturePoint.x;
2002 dy = pt.y - capturePoint.y;
2004 if (dx || dy)
2006 if( !moved )
2008 moved = TRUE;
2010 if( iconic ) /* ok, no system popup tracking */
2012 hOldCursor = SetCursor(hDragCursor);
2013 ShowCursor( TRUE );
2014 WINPOS_ShowIconTitle( hwnd, FALSE );
2016 else if(!DragFullWindows)
2017 draw_moving_frame( hdc, &sizingRect, thickframe );
2020 if (msg.message == WM_KEYDOWN) SetCursorPos( pt.x, pt.y );
2021 else
2023 RECT newRect = sizingRect;
2024 WPARAM wpSizingHit = 0;
2026 if (hittest == HTCAPTION) OffsetRect( &newRect, dx, dy );
2027 if (ON_LEFT_BORDER(hittest)) newRect.left += dx;
2028 else if (ON_RIGHT_BORDER(hittest)) newRect.right += dx;
2029 if (ON_TOP_BORDER(hittest)) newRect.top += dy;
2030 else if (ON_BOTTOM_BORDER(hittest)) newRect.bottom += dy;
2031 if(!iconic && !DragFullWindows) draw_moving_frame( hdc, &sizingRect, thickframe );
2032 capturePoint = pt;
2034 /* determine the hit location */
2035 if (hittest >= HTLEFT && hittest <= HTBOTTOMRIGHT)
2036 wpSizingHit = WMSZ_LEFT + (hittest - HTLEFT);
2037 SendMessageA( hwnd, WM_SIZING, wpSizingHit, (LPARAM)&newRect );
2039 if (!iconic)
2041 if(!DragFullWindows)
2042 draw_moving_frame( hdc, &newRect, thickframe );
2043 else {
2044 /* To avoid any deadlocks, all the locks on the windows
2045 structures must be suspended before the SetWindowPos */
2046 iWndsLocks = WIN_SuspendWndsLock();
2047 SetWindowPos( hwnd, 0, newRect.left, newRect.top,
2048 newRect.right - newRect.left,
2049 newRect.bottom - newRect.top,
2050 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
2051 WIN_RestoreWndsLock(iWndsLocks);
2054 sizingRect = newRect;
2059 set_movesize_capture(0);
2060 if( iconic )
2062 if( moved ) /* restore cursors, show icon title later on */
2064 ShowCursor( FALSE );
2065 SetCursor( hOldCursor );
2068 else if (moved && !DragFullWindows)
2069 draw_moving_frame( hdc, &sizingRect, thickframe );
2071 ReleaseDC( parent, hdc );
2073 wine_tsx11_lock();
2074 XUngrabPointer( display, CurrentTime );
2075 if (grab)
2077 XSync( display, False );
2078 XUngrabServer( display );
2079 XSync( display, False );
2080 gdi_display = old_gdi_display;
2082 wine_tsx11_unlock();
2084 if (HOOK_CallHooks( WH_CBT, HCBT_MOVESIZE, (WPARAM)hwnd, (LPARAM)&sizingRect, TRUE ))
2085 moved = FALSE;
2087 SendMessageA( hwnd, WM_EXITSIZEMOVE, 0, 0 );
2088 SendMessageA( hwnd, WM_SETVISIBLE, !IsIconic(hwnd), 0L);
2090 /* window moved or resized */
2091 if (moved)
2093 /* To avoid any deadlocks, all the locks on the windows
2094 structures must be suspended before the SetWindowPos */
2095 iWndsLocks = WIN_SuspendWndsLock();
2097 /* if the moving/resizing isn't canceled call SetWindowPos
2098 * with the new position or the new size of the window
2100 if (!((msg.message == WM_KEYDOWN) && (msg.wParam == VK_ESCAPE)) )
2102 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
2103 if(!DragFullWindows)
2104 SetWindowPos( hwnd, 0, sizingRect.left, sizingRect.top,
2105 sizingRect.right - sizingRect.left,
2106 sizingRect.bottom - sizingRect.top,
2107 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
2109 else
2110 { /* restore previous size/position */
2111 if(DragFullWindows)
2112 SetWindowPos( hwnd, 0, origRect.left, origRect.top,
2113 origRect.right - origRect.left,
2114 origRect.bottom - origRect.top,
2115 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
2118 WIN_RestoreWndsLock(iWndsLocks);
2121 if (IsIconic(hwnd))
2123 /* Single click brings up the system menu when iconized */
2125 if( !moved )
2127 if(style & WS_SYSMENU )
2128 SendMessageA( hwnd, WM_SYSCOMMAND,
2129 SC_MOUSEMENU + HTSYSMENU, MAKELONG(pt.x,pt.y));
2131 else WINPOS_ShowIconTitle( hwnd, TRUE );
2136 /***********************************************************************
2137 * ForceWindowRaise (X11DRV.@)
2139 * Raise a window on top of the X stacking order, while preserving
2140 * the correct Windows Z order.
2142 * FIXME: this should go away.
2144 void X11DRV_ForceWindowRaise( HWND hwnd )
2146 int i = 0;
2147 HWND *list;
2148 XWindowChanges winChanges;
2149 Display *display = thread_display();
2150 WND *wndPtr = WIN_FindWndPtr( hwnd );
2152 if (!wndPtr) return;
2154 if ((wndPtr->dwExStyle & WS_EX_MANAGED) ||
2155 wndPtr->parent != GetDesktopWindow() ||
2156 IsRectEmpty( &wndPtr->rectWindow ) ||
2157 !get_whole_window(wndPtr))
2159 WIN_ReleaseWndPtr( wndPtr );
2160 return;
2162 WIN_ReleaseWndPtr( wndPtr );
2164 /* Raise all windows up to wndPtr according to their Z order.
2165 * (it would be easier with sibling-related Below but it doesn't
2166 * work very well with SGI mwm for instance)
2168 winChanges.stack_mode = Above;
2169 if (!(list = WIN_ListChildren( GetDesktopWindow() ))) return;
2170 while (list[i] && list[i] != hwnd) i++;
2171 if (list[i])
2173 for ( ; i >= 0; i--)
2175 WND *ptr = WIN_FindWndPtr( list[i] );
2176 if (!ptr) continue;
2177 if (!IsRectEmpty( &ptr->rectWindow ) && get_whole_window(ptr))
2179 wine_tsx11_lock();
2180 XReconfigureWMWindow( display, get_whole_window(ptr), 0, CWStackMode, &winChanges );
2181 wine_tsx11_unlock();
2183 WIN_ReleaseWndPtr( ptr );
2186 HeapFree( GetProcessHeap(), 0, list );