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
26 #include <X11/IntrinsicP.h>
27 #include <X11/extensions/shape.h>
28 #endif /* HAVE_LIBXSHAPE */
37 #include "wine/wingdi16.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 /***********************************************************************
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 )
86 int i, x, y, ret = SIMPLEREGION;
88 /* first check if we have anything to do */
89 if (!(list = WIN_ListChildren( parent ))) return ret;
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 );
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 );
123 /***********************************************************************
126 * Compute the visible region of a window
128 static HRGN get_visible_region( WND *win, HWND top, UINT flags, int mode )
132 int xoffset, yoffset;
133 X11DRV_WND_DATA *data = win->pDriverData;
135 if (flags & DCX_WINDOW)
137 xoffset = win->rectWindow.left;
138 yoffset = win->rectWindow.top;
142 xoffset = win->rectClient.left;
143 yoffset = win->rectClient.top;
146 if (flags & DCX_PARENTCLIP)
147 GetClientRect( win->parent, &rect );
148 else if (flags & DCX_WINDOW)
149 rect = data->whole_rect;
151 rect = win->rectClient;
153 /* vis region is relative to the start of the client/window area */
154 OffsetRect( &rect, -xoffset, -yoffset );
156 if (!(rgn = CreateRectRgn( rect.left, rect.top, rect.right, rect.bottom ))) return 0;
158 if ((flags & DCX_CLIPCHILDREN) && (mode != ClipByChildren))
160 /* we need to clip children by hand */
161 if (clip_children( win->hwndSelf, 0, rgn, (flags & DCX_WINDOW) ) == NULLREGION) return rgn;
164 if (top && top != win->hwndSelf) /* need to clip siblings of ancestors */
166 WND *parent, *ptr = WIN_FindWndPtr( win->hwndSelf );
169 OffsetRgn( rgn, xoffset, yoffset );
172 if (ptr->dwStyle & WS_CLIPSIBLINGS)
174 if (clip_children( ptr->parent, ptr->hwndSelf, rgn, FALSE ) == NULLREGION) break;
176 if (ptr->hwndSelf == top) break;
177 if (!(parent = WIN_FindWndPtr( ptr->parent ))) break;
178 WIN_ReleaseWndPtr( ptr );
180 /* clip to parent client area */
181 if (tmp) SetRectRgn( tmp, 0, 0, ptr->rectClient.right - ptr->rectClient.left,
182 ptr->rectClient.bottom - ptr->rectClient.top );
183 else tmp = CreateRectRgn( 0, 0, ptr->rectClient.right - ptr->rectClient.left,
184 ptr->rectClient.bottom - ptr->rectClient.top );
185 CombineRgn( rgn, rgn, tmp, RGN_AND );
186 OffsetRgn( rgn, ptr->rectClient.left, ptr->rectClient.top );
187 xoffset += ptr->rectClient.left;
188 yoffset += ptr->rectClient.top;
190 WIN_ReleaseWndPtr( ptr );
191 /* make it relative to the target window again */
192 OffsetRgn( rgn, -xoffset, -yoffset );
193 if (tmp) DeleteObject( tmp );
200 /***********************************************************************
203 * Compute the portion of 'rgn' that is covered by non-clipped siblings.
204 * This is the area that is covered from X point of view, but may still need
206 * 'rgn' must be relative to the client area of the parent of 'win'.
208 static int get_covered_region( WND *win, HRGN rgn )
212 WND *parent, *ptr = WIN_FindWndPtr( win->hwndSelf );
213 int xoffset = 0, yoffset = 0;
215 tmp = CreateRectRgn( 0, 0, 0, 0 );
216 CombineRgn( tmp, rgn, 0, RGN_COPY );
218 /* to make things easier we actually build the uncovered
219 * area by removing all siblings and then we subtract that
220 * from the total region to get the covered area */
223 if (!(ptr->dwStyle & WS_CLIPSIBLINGS))
225 if (clip_children( ptr->parent, ptr->hwndSelf, tmp, FALSE ) == NULLREGION) break;
227 if (!(parent = WIN_FindWndPtr( ptr->parent ))) break;
228 WIN_ReleaseWndPtr( ptr );
230 OffsetRgn( tmp, ptr->rectClient.left, ptr->rectClient.top );
231 xoffset += ptr->rectClient.left;
232 yoffset += ptr->rectClient.top;
234 WIN_ReleaseWndPtr( ptr );
235 /* make it relative to the target window again */
236 OffsetRgn( tmp, -xoffset, -yoffset );
238 /* now subtract the computed region from the original one */
239 ret = CombineRgn( rgn, rgn, tmp, RGN_DIFF );
245 /***********************************************************************
248 * Expose a region of a given window.
250 static void expose_window( HWND hwnd, RECT *rect, HRGN rgn, int flags )
257 /* find the top most parent that doesn't clip children or siblings and
258 * invalidate the area on its parent, including all children */
259 if ((list = WIN_ListParents( hwnd )))
262 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
263 for (i = 0; list[i] && list[i] != GetDesktopWindow(); i++)
265 if (!(style & WS_CLIPSIBLINGS)) top = current;
266 style = GetWindowLongW( list[i], GWL_STYLE );
267 if (!(style & WS_CLIPCHILDREN)) top = current;
273 /* find the parent of the top window, reusing the parent list */
274 if (top == hwnd) i = 0;
277 for (i = 0; list[i]; i++) if (list[i] == top) break;
278 if (list[i] && list[i+1]) i++;
280 if (list[i] != GetDesktopWindow()) top = list[i];
281 flags &= ~RDW_FRAME; /* parent will invalidate children frame anyway */
282 flags |= RDW_ALLCHILDREN;
284 HeapFree( GetProcessHeap(), 0, list );
287 if (!top) top = hwnd;
289 /* make coords relative to top */
290 offset.x = offset.y = 0;
291 MapWindowPoints( hwnd, top, &offset, 1 );
295 OffsetRect( rect, offset.x, offset.y );
296 RedrawWindow( top, rect, 0, flags );
300 OffsetRgn( rgn, offset.x, offset.y );
301 RedrawWindow( top, NULL, rgn, flags );
306 /***********************************************************************
307 * expose_covered_parent_area
309 * Expose the parent area that has been uncovered by moving/hiding a
310 * given window, but that is still covered by other siblings (the area
311 * not covered by siblings will be exposed automatically by X).
313 static void expose_covered_parent_area( WND *win, const RECT *old_rect )
315 int ret = SIMPLEREGION;
316 HRGN hrgn = CreateRectRgnIndirect( old_rect );
318 if (win->dwStyle & WS_VISIBLE)
320 HRGN tmp = CreateRectRgnIndirect( &win->rectWindow );
321 ret = CombineRgn( hrgn, hrgn, tmp, RGN_DIFF );
325 if (ret != NULLREGION)
327 if (get_covered_region( win, hrgn ) != NULLREGION)
328 expose_window( win->parent, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
330 DeleteObject( hrgn );
334 /***********************************************************************
335 * expose_covered_window_area
337 * Expose the area of a window that is covered by other siblings.
339 static void expose_covered_window_area( WND *win, const RECT *old_client_rect, BOOL frame )
342 int ret = SIMPLEREGION;
345 hrgn = CreateRectRgn( win->rectWindow.left - win->rectClient.left,
346 win->rectWindow.top - win->rectClient.top,
347 win->rectWindow.right - win->rectWindow.left,
348 win->rectWindow.bottom - win->rectWindow.top );
350 hrgn = CreateRectRgn( 0, 0,
351 win->rectClient.right - win->rectClient.left,
352 win->rectClient.bottom - win->rectClient.top );
354 /* if the client rect didn't move we don't need to repaint it all */
355 if (old_client_rect->left == win->rectClient.left &&
356 old_client_rect->top == win->rectClient.top)
360 if (IntersectRect( &rc, old_client_rect, &win->rectClient ))
363 /* subtract the unchanged client area from the region to expose */
364 OffsetRect( &rc, -win->rectClient.left, -win->rectClient.top );
365 if ((tmp = CreateRectRgnIndirect( &rc )))
367 ret = CombineRgn( hrgn, hrgn, tmp, RGN_DIFF );
373 if (ret != NULLREGION)
375 if (get_covered_region( win, hrgn ) != NULLREGION)
376 expose_window( win->hwndSelf, NULL, hrgn,
377 RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
380 DeleteObject( hrgn );
384 /***********************************************************************
387 void X11DRV_Expose( HWND hwnd, XExposeEvent *event )
390 struct x11drv_win_data *data;
391 int flags = RDW_INVALIDATE | RDW_ERASE;
394 TRACE( "win %p (%lx) %d,%d %dx%d\n",
395 hwnd, event->window, event->x, event->y, event->width, event->height );
397 rect.left = event->x;
399 rect.right = rect.left + event->width;
400 rect.bottom = rect.top + event->height;
402 if (!(win = WIN_GetPtr( hwnd ))) return;
403 data = win->pDriverData;
405 if (event->window != data->client_window) /* whole window or icon window */
408 /* make position relative to client area instead of window */
409 OffsetRect( &rect, -data->client_rect.left, -data->client_rect.top );
411 WIN_ReleasePtr( win );
413 expose_window( hwnd, &rect, 0, flags );
417 /***********************************************************************
420 * Set the drawable, origin and dimensions for the DC associated to
423 BOOL X11DRV_GetDC( HWND hwnd, HDC hdc, HRGN hrgn, DWORD flags )
425 WND *win = WIN_GetPtr( hwnd );
427 X11DRV_WND_DATA *data = win->pDriverData;
428 struct x11drv_escape_set_drawable escape;
431 escape.mode = IncludeInferiors;
432 /* don't clip siblings if using parent clip region */
433 if (flags & DCX_PARENTCLIP) flags &= ~DCX_CLIPSIBLINGS;
435 /* find the top parent in the hierarchy that isn't clipping siblings */
436 visible = (win->dwStyle & WS_VISIBLE) != 0;
440 HWND *list = WIN_ListParents( hwnd );
444 for (i = 0; list[i] != GetDesktopWindow(); i++)
446 LONG style = GetWindowLongW( list[i], GWL_STYLE );
447 if (!(style & WS_VISIBLE))
453 if (!(style & WS_CLIPSIBLINGS)) top = list[i];
455 HeapFree( GetProcessHeap(), 0, list );
457 if (!top && visible && !(flags & DCX_CLIPSIBLINGS)) top = hwnd;
462 HWND parent = GetAncestor( top, GA_PARENT );
463 escape.org.x = escape.org.y = 0;
464 if (flags & DCX_WINDOW)
466 escape.org.x = win->rectWindow.left - win->rectClient.left;
467 escape.org.y = win->rectWindow.top - win->rectClient.top;
469 MapWindowPoints( hwnd, parent, &escape.org, 1 );
470 escape.drawable_org.x = escape.drawable_org.y = 0;
471 MapWindowPoints( parent, 0, &escape.drawable_org, 1 );
472 /* have to use the parent so that we include siblings */
473 if (parent) escape.drawable = X11DRV_get_client_window( parent );
474 else escape.drawable = root_window;
478 if (IsIconic( hwnd ))
480 escape.drawable = data->icon_window ? data->icon_window : data->whole_window;
483 escape.drawable_org = escape.org;
485 else if (flags & DCX_WINDOW)
487 escape.drawable = data->whole_window;
488 escape.org.x = win->rectWindow.left - data->whole_rect.left;
489 escape.org.y = win->rectWindow.top - data->whole_rect.top;
490 escape.drawable_org.x = data->whole_rect.left - win->rectClient.left;
491 escape.drawable_org.y = data->whole_rect.top - win->rectClient.top;
495 escape.drawable = data->client_window;
498 escape.drawable_org = escape.org;
499 if (flags & DCX_CLIPCHILDREN) escape.mode = ClipByChildren; /* can use X11 clipping */
501 MapWindowPoints( hwnd, 0, &escape.drawable_org, 1 );
504 escape.code = X11DRV_SET_DRAWABLE;
505 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
507 if (flags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN) ||
508 SetHookFlags16( HDC_16(hdc), DCHF_VALIDATEVISRGN )) /* DC was dirty */
510 /* need to recompute the visible region */
515 visRgn = get_visible_region( win, top, flags, escape.mode );
517 if (flags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN))
518 CombineRgn( visRgn, visRgn, hrgn,
519 (flags & DCX_INTERSECTRGN) ? RGN_AND : RGN_DIFF );
521 else visRgn = CreateRectRgn( 0, 0, 0, 0 );
523 SelectVisRgn16( HDC_16(hdc), HRGN_16(visRgn) );
524 DeleteObject( visRgn );
527 WIN_ReleasePtr( win );
532 /***********************************************************************
533 * ReleaseDC (X11DRV.@)
535 void X11DRV_ReleaseDC( HWND hwnd, HDC hdc )
537 struct x11drv_escape_set_drawable escape;
539 escape.code = X11DRV_SET_DRAWABLE;
540 escape.drawable = root_window;
541 escape.mode = IncludeInferiors;
542 escape.org.x = escape.org.y = 0;
543 escape.drawable_org.x = escape.drawable_org.y = 0;
545 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
549 /***********************************************************************
550 * SWP_DoWinPosChanging
552 static BOOL SWP_DoWinPosChanging( WINDOWPOS* pWinpos, RECT* pNewWindowRect, RECT* pNewClientRect )
556 /* Send WM_WINDOWPOSCHANGING message */
558 if (!(pWinpos->flags & SWP_NOSENDCHANGING))
559 SendMessageA( pWinpos->hwnd, WM_WINDOWPOSCHANGING, 0, (LPARAM)pWinpos );
561 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return FALSE;
563 /* Calculate new position and size */
565 *pNewWindowRect = wndPtr->rectWindow;
566 *pNewClientRect = (wndPtr->dwStyle & WS_MINIMIZE) ? wndPtr->rectWindow
567 : wndPtr->rectClient;
569 if (!(pWinpos->flags & SWP_NOSIZE))
571 pNewWindowRect->right = pNewWindowRect->left + pWinpos->cx;
572 pNewWindowRect->bottom = pNewWindowRect->top + pWinpos->cy;
574 if (!(pWinpos->flags & SWP_NOMOVE))
576 pNewWindowRect->left = pWinpos->x;
577 pNewWindowRect->top = pWinpos->y;
578 pNewWindowRect->right += pWinpos->x - wndPtr->rectWindow.left;
579 pNewWindowRect->bottom += pWinpos->y - wndPtr->rectWindow.top;
581 OffsetRect( pNewClientRect, pWinpos->x - wndPtr->rectWindow.left,
582 pWinpos->y - wndPtr->rectWindow.top );
584 pWinpos->flags |= SWP_NOCLIENTMOVE | SWP_NOCLIENTSIZE;
585 WIN_ReleasePtr( wndPtr );
589 /***********************************************************************
592 static UINT SWP_DoNCCalcSize( WINDOWPOS* pWinpos, RECT* pNewWindowRect, RECT* pNewClientRect )
597 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
599 /* Send WM_NCCALCSIZE message to get new client area */
600 if( (pWinpos->flags & (SWP_FRAMECHANGED | SWP_NOSIZE)) != SWP_NOSIZE )
602 NCCALCSIZE_PARAMS params;
603 WINDOWPOS winposCopy;
605 params.rgrc[0] = *pNewWindowRect;
606 params.rgrc[1] = wndPtr->rectWindow;
607 params.rgrc[2] = wndPtr->rectClient;
608 params.lppos = &winposCopy;
609 winposCopy = *pWinpos;
610 WIN_ReleasePtr( wndPtr );
612 wvrFlags = SendMessageW( pWinpos->hwnd, WM_NCCALCSIZE, TRUE, (LPARAM)¶ms );
614 TRACE( "(%ld,%ld)-(%ld,%ld)\n", params.rgrc[0].left, params.rgrc[0].top,
615 params.rgrc[0].right, params.rgrc[0].bottom );
617 /* If the application send back garbage, ignore it */
618 if (params.rgrc[0].left <= params.rgrc[0].right &&
619 params.rgrc[0].top <= params.rgrc[0].bottom)
620 *pNewClientRect = params.rgrc[0];
622 /* FIXME: WVR_ALIGNxxx */
624 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
626 if( pNewClientRect->left != wndPtr->rectClient.left ||
627 pNewClientRect->top != wndPtr->rectClient.top )
628 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
630 if( (pNewClientRect->right - pNewClientRect->left !=
631 wndPtr->rectClient.right - wndPtr->rectClient.left) ||
632 (pNewClientRect->bottom - pNewClientRect->top !=
633 wndPtr->rectClient.bottom - wndPtr->rectClient.top) )
634 pWinpos->flags &= ~SWP_NOCLIENTSIZE;
638 if (!(pWinpos->flags & SWP_NOMOVE) &&
639 (pNewClientRect->left != wndPtr->rectClient.left ||
640 pNewClientRect->top != wndPtr->rectClient.top))
641 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
643 WIN_ReleasePtr( wndPtr );
648 /***********************************************************************
651 * fix Z order taking into account owned popups -
652 * basically we need to maintain them above the window that owns them
654 * FIXME: hide/show owned popups when owner visibility changes.
656 static HWND SWP_DoOwnedPopups(HWND hwnd, HWND hwndInsertAfter)
659 HWND owner = GetWindow( hwnd, GW_OWNER );
660 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
662 WARN("(%p) hInsertAfter = %p\n", hwnd, hwndInsertAfter );
664 if ((style & WS_POPUP) && owner)
666 /* make sure this popup stays above the owner */
668 HWND hwndLocalPrev = HWND_TOP;
670 if( hwndInsertAfter != HWND_TOP )
672 if ((list = WIN_ListChildren( GetDesktopWindow() )))
675 for (i = 0; list[i]; i++)
677 if (list[i] == owner) break;
678 if (list[i] != hwnd) hwndLocalPrev = list[i];
679 if (hwndLocalPrev == hwndInsertAfter) break;
681 hwndInsertAfter = hwndLocalPrev;
685 else if (style & WS_CHILD) return hwndInsertAfter;
687 if (!list) list = WIN_ListChildren( GetDesktopWindow() );
691 for (i = 0; list[i]; i++)
693 if (list[i] == hwnd) break;
694 if ((GetWindowLongW( list[i], GWL_STYLE ) & WS_POPUP) &&
695 GetWindow( list[i], GW_OWNER ) == hwnd)
697 SetWindowPos( list[i], hwndInsertAfter, 0, 0, 0, 0,
698 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE |
699 SWP_NOSENDCHANGING | SWP_DEFERERASE );
700 hwndInsertAfter = list[i];
703 HeapFree( GetProcessHeap(), 0, list );
706 return hwndInsertAfter;
710 /* fix redundant flags and values in the WINDOWPOS structure */
711 static BOOL fixup_flags( WINDOWPOS *winpos )
713 WND *wndPtr = WIN_GetPtr( winpos->hwnd );
716 if (!wndPtr || wndPtr == WND_OTHER_PROCESS)
718 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
721 winpos->hwnd = wndPtr->hwndSelf; /* make it a full handle */
723 if (wndPtr->dwStyle & WS_VISIBLE) winpos->flags &= ~SWP_SHOWWINDOW;
726 winpos->flags &= ~SWP_HIDEWINDOW;
727 if (!(winpos->flags & SWP_SHOWWINDOW)) winpos->flags |= SWP_NOREDRAW;
730 if (winpos->cx < 0) winpos->cx = 0;
731 if (winpos->cy < 0) winpos->cy = 0;
733 if ((wndPtr->rectWindow.right - wndPtr->rectWindow.left == winpos->cx) &&
734 (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top == winpos->cy))
735 winpos->flags |= SWP_NOSIZE; /* Already the right size */
737 if ((wndPtr->rectWindow.left == winpos->x) && (wndPtr->rectWindow.top == winpos->y))
738 winpos->flags |= SWP_NOMOVE; /* Already the right position */
740 if (winpos->hwnd == GetForegroundWindow())
741 winpos->flags |= SWP_NOACTIVATE; /* Already active */
742 else if ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD)
744 if (!(winpos->flags & SWP_NOACTIVATE)) /* Bring to the top when activating */
746 winpos->flags &= ~SWP_NOZORDER;
747 winpos->hwndInsertAfter = HWND_TOP;
752 /* Check hwndInsertAfter */
753 if (winpos->flags & SWP_NOZORDER) goto done;
755 /* fix sign extension */
756 if (winpos->hwndInsertAfter == (HWND)0xffff) winpos->hwndInsertAfter = HWND_TOPMOST;
757 else if (winpos->hwndInsertAfter == (HWND)0xfffe) winpos->hwndInsertAfter = HWND_NOTOPMOST;
759 /* FIXME: TOPMOST not supported yet */
760 if ((winpos->hwndInsertAfter == HWND_TOPMOST) ||
761 (winpos->hwndInsertAfter == HWND_NOTOPMOST)) winpos->hwndInsertAfter = HWND_TOP;
763 /* hwndInsertAfter must be a sibling of the window */
764 if ((winpos->hwndInsertAfter != HWND_TOP) && (winpos->hwndInsertAfter != HWND_BOTTOM))
766 if (GetAncestor( winpos->hwndInsertAfter, GA_PARENT ) != wndPtr->parent) ret = FALSE;
769 /* don't need to change the Zorder of hwnd if it's already inserted
770 * after hwndInsertAfter or when inserting hwnd after itself.
772 if ((winpos->hwnd == winpos->hwndInsertAfter) ||
773 (winpos->hwnd == GetWindow( winpos->hwndInsertAfter, GW_HWNDNEXT )))
774 winpos->flags |= SWP_NOZORDER;
778 WIN_ReleasePtr( wndPtr );
783 /***********************************************************************
786 * Set/clear the WS_VISIBLE style of a window and map/unmap the X window.
788 static void set_visible_style( HWND hwnd, BOOL set )
792 if (!(win = WIN_GetPtr( hwnd ))) return;
793 if (win == WND_OTHER_PROCESS) return;
795 TRACE( "hwnd %p (%lx) set %d visible %d empty %d\n",
796 hwnd, get_whole_window(win),
797 set, (win->dwStyle & WS_VISIBLE) != 0, IsRectEmpty(&win->rectWindow) );
801 if (win->dwStyle & WS_VISIBLE) goto done;
802 WIN_SetStyle( hwnd, win->dwStyle | WS_VISIBLE );
803 if (!IsRectEmpty( &win->rectWindow ) && get_whole_window(win) && is_window_top_level(win))
805 Display *display = thread_display();
806 X11DRV_sync_window_style( display, win );
807 X11DRV_set_wm_hints( display, win );
808 TRACE( "mapping win %p\n", hwnd );
810 XMapWindow( display, get_whole_window(win) );
816 if (!(win->dwStyle & WS_VISIBLE)) goto done;
817 WIN_SetStyle( hwnd, win->dwStyle & ~WS_VISIBLE );
818 if (!IsRectEmpty( &win->rectWindow ) && get_whole_window(win) && is_window_top_level(win))
820 TRACE( "unmapping win %p\n", hwnd );
822 XUnmapWindow( thread_display(), get_whole_window(win) );
827 WIN_ReleasePtr( win );
831 /***********************************************************************
832 * SetWindowStyle (X11DRV.@)
834 * Update the X state of a window to reflect a style change
836 void X11DRV_SetWindowStyle( HWND hwnd, LONG oldStyle )
838 Display *display = thread_display();
842 if (hwnd == GetDesktopWindow()) return;
843 if (!(wndPtr = WIN_GetPtr( hwnd ))) return;
844 if (wndPtr == WND_OTHER_PROCESS) return;
846 changed = wndPtr->dwStyle ^ oldStyle;
848 if (changed & WS_VISIBLE)
850 if (!IsRectEmpty( &wndPtr->rectWindow ))
852 if (wndPtr->dwStyle & WS_VISIBLE)
854 TRACE( "mapping win %p\n", hwnd );
855 if (is_window_top_level(wndPtr))
857 X11DRV_sync_window_style( display, wndPtr );
858 X11DRV_set_wm_hints( display, wndPtr );
861 XMapWindow( display, get_whole_window(wndPtr) );
864 else if (!is_window_top_level(wndPtr)) /* don't unmap managed windows */
866 TRACE( "unmapping win %p\n", hwnd );
868 XUnmapWindow( display, get_whole_window(wndPtr) );
874 if (changed & WS_DISABLED)
876 if (wndPtr->dwExStyle & WS_EX_MANAGED)
880 if (!(wm_hints = XGetWMHints( display, get_whole_window(wndPtr) )))
881 wm_hints = XAllocWMHints();
884 wm_hints->flags |= InputHint;
885 wm_hints->input = !(wndPtr->dwStyle & WS_DISABLED);
886 XSetWMHints( display, get_whole_window(wndPtr), wm_hints );
892 WIN_ReleasePtr(wndPtr);
896 /***********************************************************************
897 * SetWindowPos (X11DRV.@)
899 BOOL X11DRV_SetWindowPos( WINDOWPOS *winpos )
902 RECT newWindowRect, newClientRect;
903 RECT oldWindowRect, oldClientRect;
907 TRACE( "hwnd %p, after %p, swp %d,%d %dx%d flags %08x\n",
908 winpos->hwnd, winpos->hwndInsertAfter, winpos->x, winpos->y,
909 winpos->cx, winpos->cy, winpos->flags);
911 bChangePos = !(winpos->flags & SWP_WINE_NOHOSTMOVE);
912 winpos->flags &= ~SWP_WINE_NOHOSTMOVE;
914 /* Check window handle */
915 if (winpos->hwnd == GetDesktopWindow()) return FALSE;
917 if (!SWP_DoWinPosChanging( winpos, &newWindowRect, &newClientRect )) return FALSE;
919 /* Fix redundant flags */
920 if (!fixup_flags( winpos )) return FALSE;
922 if (!(wndPtr = WIN_FindWndPtr( winpos->hwnd ))) return FALSE;
924 TRACE("\tcurrent (%ld,%ld)-(%ld,%ld), style %08x\n",
925 wndPtr->rectWindow.left, wndPtr->rectWindow.top,
926 wndPtr->rectWindow.right, wndPtr->rectWindow.bottom, (unsigned)wndPtr->dwStyle );
928 if((winpos->flags & (SWP_NOZORDER | SWP_HIDEWINDOW | SWP_SHOWWINDOW)) != SWP_NOZORDER)
930 if (GetAncestor( winpos->hwnd, GA_PARENT ) == GetDesktopWindow())
931 winpos->hwndInsertAfter = SWP_DoOwnedPopups( winpos->hwnd, winpos->hwndInsertAfter );
934 /* Common operations */
936 wvrFlags = SWP_DoNCCalcSize( winpos, &newWindowRect, &newClientRect );
938 if(!(winpos->flags & SWP_NOZORDER) && winpos->hwnd != winpos->hwndInsertAfter)
940 HWND parent = GetAncestor( winpos->hwnd, GA_PARENT );
941 if (parent) WIN_LinkWindow( winpos->hwnd, parent, winpos->hwndInsertAfter );
944 /* Reset active DCEs */
946 if( (((winpos->flags & SWP_AGG_NOPOSCHANGE) != SWP_AGG_NOPOSCHANGE) &&
947 wndPtr->dwStyle & WS_VISIBLE) ||
948 (winpos->flags & (SWP_HIDEWINDOW | SWP_SHOWWINDOW)) )
952 UnionRect(&rect, &newWindowRect, &wndPtr->rectWindow);
953 DCE_InvalidateDCE(wndPtr->hwndSelf, &rect);
956 oldWindowRect = wndPtr->rectWindow;
957 oldClientRect = wndPtr->rectClient;
959 /* Find out if we have to redraw the whole client rect */
961 if( oldClientRect.bottom - oldClientRect.top ==
962 newClientRect.bottom - newClientRect.top ) wvrFlags &= ~WVR_VREDRAW;
964 if( oldClientRect.right - oldClientRect.left ==
965 newClientRect.right - newClientRect.left ) wvrFlags &= ~WVR_HREDRAW;
967 /* FIXME: actually do something with WVR_VALIDRECTS */
969 WIN_SetRectangles( winpos->hwnd, &newWindowRect, &newClientRect );
971 if (get_whole_window(wndPtr)) /* don't do anything if X window not created yet */
973 Display *display = thread_display();
975 if (!(winpos->flags & SWP_SHOWWINDOW) && (winpos->flags & SWP_HIDEWINDOW))
977 /* clear the update region */
978 RedrawWindow( winpos->hwnd, NULL, 0, RDW_VALIDATE | RDW_NOFRAME |
979 RDW_NOERASE | RDW_NOINTERNALPAINT | RDW_ALLCHILDREN );
980 set_visible_style( winpos->hwnd, FALSE );
982 else if ((wndPtr->dwStyle & WS_VISIBLE) &&
983 !IsRectEmpty( &oldWindowRect ) && IsRectEmpty( &newWindowRect ))
985 /* resizing to zero size -> unmap */
986 TRACE( "unmapping zero size win %p\n", winpos->hwnd );
988 XUnmapWindow( display, get_whole_window(wndPtr) );
994 X11DRV_sync_whole_window_position( display, wndPtr, !(winpos->flags & SWP_NOZORDER) );
997 struct x11drv_win_data *data = wndPtr->pDriverData;
998 data->whole_rect = wndPtr->rectWindow;
999 X11DRV_window_to_X_rect( wndPtr, &data->whole_rect );
1002 if (X11DRV_sync_client_window_position( display, wndPtr ) ||
1003 (winpos->flags & SWP_FRAMECHANGED))
1005 /* if we moved the client area, repaint the whole non-client window */
1006 XClearArea( display, get_whole_window(wndPtr), 0, 0, 0, 0, True );
1007 winpos->flags |= SWP_FRAMECHANGED;
1009 if (winpos->flags & SWP_SHOWWINDOW)
1011 set_visible_style( winpos->hwnd, TRUE );
1013 else if ((wndPtr->dwStyle & WS_VISIBLE) &&
1014 IsRectEmpty( &oldWindowRect ) && !IsRectEmpty( &newWindowRect ))
1016 /* resizing from zero size to non-zero -> map */
1017 TRACE( "mapping non zero size win %p\n", winpos->hwnd );
1018 XMapWindow( display, get_whole_window(wndPtr) );
1020 XFlush( display ); /* FIXME: should not be necessary */
1021 wine_tsx11_unlock();
1023 else /* no X window, simply toggle the window style */
1025 if (winpos->flags & SWP_SHOWWINDOW)
1026 set_visible_style( winpos->hwnd, TRUE );
1027 else if (winpos->flags & SWP_HIDEWINDOW)
1028 set_visible_style( winpos->hwnd, FALSE );
1031 /* manually expose the areas that X won't expose because they are still covered by something */
1033 if (!(winpos->flags & SWP_SHOWWINDOW))
1034 expose_covered_parent_area( wndPtr, &oldWindowRect );
1036 if (wndPtr->dwStyle & WS_VISIBLE)
1037 expose_covered_window_area( wndPtr, &oldClientRect, winpos->flags & SWP_FRAMECHANGED );
1039 WIN_ReleaseWndPtr(wndPtr);
1041 if (wvrFlags & WVR_REDRAW) RedrawWindow( winpos->hwnd, NULL, 0, RDW_INVALIDATE | RDW_ERASE );
1043 if( winpos->flags & SWP_HIDEWINDOW )
1044 HideCaret(winpos->hwnd);
1045 else if (winpos->flags & SWP_SHOWWINDOW)
1046 ShowCaret(winpos->hwnd);
1048 if (!(winpos->flags & SWP_NOACTIVATE))
1050 /* child windows get WM_CHILDACTIVATE message */
1051 if ((GetWindowLongW( winpos->hwnd, GWL_STYLE ) & (WS_CHILD | WS_POPUP)) == WS_CHILD)
1052 SendMessageA( winpos->hwnd, WM_CHILDACTIVATE, 0, 0 );
1054 SetForegroundWindow( winpos->hwnd );
1057 /* And last, send the WM_WINDOWPOSCHANGED message */
1059 TRACE("\tstatus flags = %04x\n", winpos->flags & SWP_AGG_STATUSFLAGS);
1061 if (((winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOPOSCHANGE))
1062 SendMessageA( winpos->hwnd, WM_WINDOWPOSCHANGED, 0, (LPARAM)winpos );
1063 /* WM_WINDOWPOSCHANGED is send even if SWP_NOSENDCHANGING is set */
1069 /***********************************************************************
1070 * WINPOS_FindIconPos
1072 * Find a suitable place for an iconic window.
1074 static POINT WINPOS_FindIconPos( WND* wndPtr, POINT pt )
1078 short x, y, xspacing, yspacing;
1080 GetClientRect( wndPtr->parent, &rectParent );
1081 if ((pt.x >= rectParent.left) && (pt.x + GetSystemMetrics(SM_CXICON) < rectParent.right) &&
1082 (pt.y >= rectParent.top) && (pt.y + GetSystemMetrics(SM_CYICON) < rectParent.bottom))
1083 return pt; /* The icon already has a suitable position */
1085 xspacing = GetSystemMetrics(SM_CXICONSPACING);
1086 yspacing = GetSystemMetrics(SM_CYICONSPACING);
1088 list = WIN_ListChildren( wndPtr->parent );
1089 y = rectParent.bottom;
1092 x = rectParent.left;
1095 /* Check if another icon already occupies this spot */
1096 /* FIXME: this is completely inefficient */
1102 for (i = 0; list[i]; i++)
1104 if (list[i] == wndPtr->hwndSelf) continue;
1105 if (!IsIconic( list[i] )) continue;
1106 if (!(childPtr = WIN_FindWndPtr( list[i] ))) continue;
1107 if ((childPtr->rectWindow.left < x + xspacing) &&
1108 (childPtr->rectWindow.right >= x) &&
1109 (childPtr->rectWindow.top <= y) &&
1110 (childPtr->rectWindow.bottom > y - yspacing))
1112 WIN_ReleaseWndPtr( childPtr );
1113 break; /* There's a window in there */
1115 WIN_ReleaseWndPtr( childPtr );
1119 /* found something here, try next spot */
1125 /* No window was found, so it's OK for us */
1126 pt.x = x + (xspacing - GetSystemMetrics(SM_CXICON)) / 2;
1127 pt.y = y - (yspacing + GetSystemMetrics(SM_CYICON)) / 2;
1128 HeapFree( GetProcessHeap(), 0, list );
1131 } while(x <= rectParent.right-xspacing);
1140 UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect )
1146 WINDOWPLACEMENT wpl;
1148 TRACE("%p %u\n", hwnd, cmd );
1150 wpl.length = sizeof(wpl);
1151 GetWindowPlacement( hwnd, &wpl );
1153 if (HOOK_CallHooks( WH_CBT, HCBT_MINMAX, (WPARAM)hwnd, cmd, TRUE ))
1154 return SWP_NOSIZE | SWP_NOMOVE;
1156 if (IsIconic( hwnd ))
1158 if (cmd == SW_MINIMIZE) return SWP_NOSIZE | SWP_NOMOVE;
1159 if (!SendMessageA( hwnd, WM_QUERYOPEN, 0, 0 )) return SWP_NOSIZE | SWP_NOMOVE;
1160 swpFlags |= SWP_NOCOPYBITS;
1163 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
1165 size.x = wndPtr->rectWindow.left;
1166 size.y = wndPtr->rectWindow.top;
1171 if( wndPtr->dwStyle & WS_MAXIMIZE) wndPtr->flags |= WIN_RESTORE_MAX;
1172 else wndPtr->flags &= ~WIN_RESTORE_MAX;
1174 WIN_SetStyle( hwnd, (wndPtr->dwStyle & ~WS_MAXIMIZE) | WS_MINIMIZE );
1176 X11DRV_set_iconic_state( wndPtr );
1178 wpl.ptMinPosition = WINPOS_FindIconPos( wndPtr, wpl.ptMinPosition );
1180 SetRect( rect, wpl.ptMinPosition.x, wpl.ptMinPosition.y,
1181 GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON) );
1182 swpFlags |= SWP_NOCOPYBITS;
1186 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL );
1188 old_style = WIN_SetStyle( hwnd, (wndPtr->dwStyle & ~WS_MINIMIZE) | WS_MAXIMIZE );
1189 if (old_style & WS_MINIMIZE)
1191 WINPOS_ShowIconTitle( hwnd, FALSE );
1192 X11DRV_set_iconic_state( wndPtr );
1194 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y );
1198 old_style = WIN_SetStyle( hwnd, wndPtr->dwStyle & ~(WS_MINIMIZE|WS_MAXIMIZE) );
1199 if (old_style & WS_MINIMIZE)
1201 WINPOS_ShowIconTitle( hwnd, FALSE );
1202 X11DRV_set_iconic_state( wndPtr );
1204 if( wndPtr->flags & WIN_RESTORE_MAX)
1206 /* Restore to maximized position */
1207 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL);
1208 WIN_SetStyle( hwnd, wndPtr->dwStyle | WS_MAXIMIZE );
1209 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y );
1213 else if (!(old_style & WS_MAXIMIZE)) break;
1215 /* Restore to normal position */
1217 *rect = wpl.rcNormalPosition;
1218 rect->right -= rect->left;
1219 rect->bottom -= rect->top;
1224 WIN_ReleaseWndPtr( wndPtr );
1229 /***********************************************************************
1230 * ShowWindow (X11DRV.@)
1232 BOOL X11DRV_ShowWindow( HWND hwnd, INT cmd )
1234 WND* wndPtr = WIN_FindWndPtr( hwnd );
1235 BOOL wasVisible, showFlag;
1236 RECT newPos = {0, 0, 0, 0};
1239 if (!wndPtr) return FALSE;
1240 hwnd = wndPtr->hwndSelf; /* make it a full handle */
1242 TRACE("hwnd=%p, cmd=%d\n", hwnd, cmd);
1244 wasVisible = (wndPtr->dwStyle & WS_VISIBLE) != 0;
1249 if (!wasVisible) goto END;
1250 swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE |
1251 SWP_NOACTIVATE | SWP_NOZORDER;
1254 case SW_SHOWMINNOACTIVE:
1255 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1257 case SW_SHOWMINIMIZED:
1258 case SW_FORCEMINIMIZE: /* FIXME: Does not work if thread is hung. */
1259 swp |= SWP_SHOWWINDOW;
1262 swp |= SWP_FRAMECHANGED;
1263 if( !(wndPtr->dwStyle & WS_MINIMIZE) )
1264 swp |= WINPOS_MinMaximize( hwnd, SW_MINIMIZE, &newPos );
1265 else swp |= SWP_NOSIZE | SWP_NOMOVE;
1268 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
1269 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
1270 if( !(wndPtr->dwStyle & WS_MAXIMIZE) )
1271 swp |= WINPOS_MinMaximize( hwnd, SW_MAXIMIZE, &newPos );
1272 else swp |= SWP_NOSIZE | SWP_NOMOVE;
1276 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1279 swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
1282 * ShowWindow has a little peculiar behavior that if the
1283 * window is already the topmost window, it will not
1286 if (GetTopWindow(NULL)==hwnd && (wasVisible || GetActiveWindow() == hwnd))
1287 swp |= SWP_NOACTIVATE;
1291 case SW_SHOWNOACTIVATE:
1292 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1294 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
1295 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
1297 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
1299 if( wndPtr->dwStyle & (WS_MINIMIZE | WS_MAXIMIZE) )
1300 swp |= WINPOS_MinMaximize( hwnd, SW_RESTORE, &newPos );
1301 else swp |= SWP_NOSIZE | SWP_NOMOVE;
1305 showFlag = (cmd != SW_HIDE);
1306 if (showFlag != wasVisible)
1308 SendMessageA( hwnd, WM_SHOWWINDOW, showFlag, 0 );
1309 if (!IsWindow( hwnd )) goto END;
1312 /* We can't activate a child window */
1313 if ((wndPtr->dwStyle & WS_CHILD) &&
1314 !(wndPtr->dwExStyle & WS_EX_MDICHILD))
1315 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1317 SetWindowPos( hwnd, HWND_TOP, newPos.left, newPos.top,
1318 newPos.right, newPos.bottom, LOWORD(swp) );
1321 /* FIXME: This will cause the window to be activated irrespective
1322 * of whether it is owned by the same thread. Has to be done
1326 if (hwnd == GetActiveWindow())
1327 WINPOS_ActivateOtherWindow(hwnd);
1329 /* Revert focus to parent */
1330 if (hwnd == GetFocus() || IsChild(hwnd, GetFocus()))
1331 SetFocus( GetParent(hwnd) );
1333 if (!IsWindow( hwnd )) goto END;
1334 else if( wndPtr->dwStyle & WS_MINIMIZE ) WINPOS_ShowIconTitle( hwnd, TRUE );
1336 if (wndPtr->flags & WIN_NEED_SIZE)
1338 /* should happen only in CreateWindowEx() */
1339 int wParam = SIZE_RESTORED;
1341 wndPtr->flags &= ~WIN_NEED_SIZE;
1342 if (wndPtr->dwStyle & WS_MAXIMIZE) wParam = SIZE_MAXIMIZED;
1343 else if (wndPtr->dwStyle & WS_MINIMIZE) wParam = SIZE_MINIMIZED;
1344 SendMessageA( hwnd, WM_SIZE, wParam,
1345 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
1346 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
1347 SendMessageA( hwnd, WM_MOVE, 0,
1348 MAKELONG(wndPtr->rectClient.left, wndPtr->rectClient.top) );
1352 WIN_ReleaseWndPtr(wndPtr);
1357 /**********************************************************************
1360 void X11DRV_MapNotify( HWND hwnd, XMapEvent *event )
1362 HWND hwndFocus = GetFocus();
1365 if (!(win = WIN_GetPtr( hwnd ))) return;
1367 if ((win->dwStyle & WS_VISIBLE) &&
1368 (win->dwStyle & WS_MINIMIZE) &&
1369 (win->dwExStyle & WS_EX_MANAGED))
1372 unsigned int width, height, border, depth;
1375 LONG style = (win->dwStyle & ~(WS_MINIMIZE|WS_MAXIMIZE)) | WS_VISIBLE;
1379 XGetGeometry( event->display, get_whole_window(win), &root, &x, &y, &width, &height,
1381 XTranslateCoordinates( event->display, get_whole_window(win), root, 0, 0, &x, &y, &top );
1382 wine_tsx11_unlock();
1385 rect.right = x + width;
1386 rect.bottom = y + height;
1387 X11DRV_X_to_window_rect( win, &rect );
1389 DCE_InvalidateDCE( hwnd, &win->rectWindow );
1391 if (win->flags & WIN_RESTORE_MAX) style |= WS_MAXIMIZE;
1392 WIN_SetStyle( hwnd, style );
1393 WIN_ReleasePtr( win );
1395 SendMessageA( hwnd, WM_SHOWWINDOW, SW_RESTORE, 0 );
1396 SetWindowPos( hwnd, 0, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
1397 SWP_NOZORDER | SWP_WINE_NOHOSTMOVE );
1399 else WIN_ReleasePtr( win );
1400 if (hwndFocus && IsChild( hwnd, hwndFocus )) X11DRV_SetFocus(hwndFocus); /* FIXME */
1404 /**********************************************************************
1405 * X11DRV_UnmapNotify
1407 void X11DRV_UnmapNotify( HWND hwnd, XUnmapEvent *event )
1411 if (!(win = WIN_GetPtr( hwnd ))) return;
1413 if ((win->dwStyle & WS_VISIBLE) && (win->dwExStyle & WS_EX_MANAGED))
1415 if (win->dwStyle & WS_MAXIMIZE)
1416 win->flags |= WIN_RESTORE_MAX;
1418 win->flags &= ~WIN_RESTORE_MAX;
1420 WIN_SetStyle( hwnd, (win->dwStyle & ~WS_MAXIMIZE) | WS_MINIMIZE );
1421 WIN_ReleasePtr( win );
1424 SendMessageA( hwnd, WM_SHOWWINDOW, SW_MINIMIZE, 0 );
1425 SetWindowPos( hwnd, 0, 0, 0, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON),
1426 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_WINE_NOHOSTMOVE );
1428 else WIN_ReleasePtr( win );
1432 /***********************************************************************
1435 * Synchronize internal z-order with the window manager's.
1437 static Window __get_common_ancestor( Display *display, Window A, Window B,
1438 Window** children, unsigned* total )
1440 /* find the real root window */
1442 Window root, *childrenB;
1446 while( A != B && A && B )
1448 XQueryTree( display, A, &root, &A, children, total );
1449 XQueryTree( display, B, &root, &B, &childrenB, &totalB );
1450 if( childrenB ) XFree( childrenB );
1451 if( *children ) XFree( *children ), *children = NULL;
1456 XQueryTree( display, A, &root, &B, children, total );
1457 wine_tsx11_unlock();
1460 wine_tsx11_unlock();
1464 static Window __get_top_decoration( Display *display, Window w, Window ancestor )
1466 Window* children, root, prev = w, parent = w;
1473 XQueryTree( display, w, &root, &parent, &children, &total );
1474 if( children ) XFree( children );
1475 } while( parent && parent != ancestor );
1476 wine_tsx11_unlock();
1477 TRACE("\t%08x -> %08x\n", (unsigned)prev, (unsigned)w );
1478 return ( parent ) ? w : 0 ;
1481 static unsigned __td_lookup( Window w, Window* list, unsigned max )
1484 for( i = max; i > 0; i-- ) if( list[i - 1] == w ) break;
1488 static HWND query_zorder( Display *display, HWND hWndCheck)
1490 HWND hwndInsertAfter = HWND_TOP;
1491 Window w, parent, *children = NULL;
1492 unsigned total, check, pos, best;
1493 HWND *list = WIN_ListChildren( GetDesktopWindow() );
1494 HWND hwndA = 0, hwndB = 0;
1497 /* find at least two managed windows */
1498 if (!list) return 0;
1499 for (i = 0; list[i]; i++)
1501 if (!(GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_MANAGED)) continue;
1502 if (!(GetWindowLongW( list[i], GWL_STYLE ) & WS_VISIBLE)) continue;
1503 if (!hwndA) hwndA = list[i];
1510 if (!hwndA || !hwndB) goto done;
1512 parent = __get_common_ancestor( display, X11DRV_get_whole_window(hwndA),
1513 X11DRV_get_whole_window(hwndB), &children, &total );
1514 if( parent && children )
1516 /* w is the ancestor if hWndCheck that is a direct descendant of 'parent' */
1518 w = __get_top_decoration( display, X11DRV_get_whole_window(hWndCheck), parent );
1520 if( w != children[total-1] ) /* check if at the top */
1522 /* X child at index 0 is at the bottom, at index total-1 is at the top */
1523 check = __td_lookup( w, children, total );
1526 /* go through all windows in Wine z-order... */
1527 for (i = 0; list[i]; i++)
1529 if (list[i] == hWndCheck) continue;
1530 if (!(GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_MANAGED)) continue;
1531 if (!(w = __get_top_decoration( display, X11DRV_get_whole_window(list[i]),
1532 parent ))) continue;
1533 pos = __td_lookup( w, children, total );
1534 if( pos < best && pos > check )
1536 /* find a nearest Wine window precedes hWndCheck in the real z-order */
1538 hwndInsertAfter = list[i];
1540 if( best - check == 1 ) break;
1545 if( children ) XFree( children );
1546 wine_tsx11_unlock();
1549 HeapFree( GetProcessHeap(), 0, list );
1550 return hwndInsertAfter;
1554 /***********************************************************************
1555 * X11DRV_ConfigureNotify
1557 void X11DRV_ConfigureNotify( HWND hwnd, XConfigureEvent *event )
1559 HWND oldInsertAfter;
1560 struct x11drv_win_data *data;
1564 int x = event->x, y = event->y;
1566 if (!(win = WIN_GetPtr( hwnd ))) return;
1567 data = win->pDriverData;
1571 if (!event->send_event) /* normal event, need to map coordinates to the root */
1575 XTranslateCoordinates( event->display, data->whole_window, root_window,
1576 0, 0, &x, &y, &child );
1577 wine_tsx11_unlock();
1581 rect.right = x + event->width;
1582 rect.bottom = y + event->height;
1583 TRACE( "win %p new X rect %ld,%ld,%ldx%ld (event %d,%d,%dx%d)\n",
1584 hwnd, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
1585 event->x, event->y, event->width, event->height );
1586 X11DRV_X_to_window_rect( win, &rect );
1587 WIN_ReleasePtr( win );
1590 winpos.x = rect.left;
1591 winpos.y = rect.top;
1592 winpos.cx = rect.right - rect.left;
1593 winpos.cy = rect.bottom - rect.top;
1594 winpos.flags = SWP_NOACTIVATE;
1596 /* Get Z-order (FIXME) */
1598 winpos.hwndInsertAfter = query_zorder( event->display, hwnd );
1600 /* needs to find the first Visible Window above the current one */
1601 oldInsertAfter = hwnd;
1604 oldInsertAfter = GetWindow( oldInsertAfter, GW_HWNDPREV );
1605 if (!oldInsertAfter)
1607 oldInsertAfter = HWND_TOP;
1610 if (GetWindowLongA( oldInsertAfter, GWL_STYLE ) & WS_VISIBLE) break;
1613 /* Compare what has changed */
1615 GetWindowRect( hwnd, &rect );
1616 if (rect.left == winpos.x && rect.top == winpos.y) winpos.flags |= SWP_NOMOVE;
1618 TRACE( "%p moving from (%ld,%ld) to (%d,%d)\n",
1619 hwnd, rect.left, rect.top, winpos.x, winpos.y );
1621 if ((rect.right - rect.left == winpos.cx && rect.bottom - rect.top == winpos.cy) ||
1623 (IsRectEmpty( &rect ) && winpos.cx == 1 && winpos.cy == 1))
1624 winpos.flags |= SWP_NOSIZE;
1626 TRACE( "%p resizing from (%ldx%ld) to (%dx%d)\n",
1627 hwnd, rect.right - rect.left, rect.bottom - rect.top,
1628 winpos.cx, winpos.cy );
1630 if (winpos.hwndInsertAfter == oldInsertAfter) winpos.flags |= SWP_NOZORDER;
1632 TRACE( "%p restacking from after %p to after %p\n",
1633 hwnd, oldInsertAfter, winpos.hwndInsertAfter );
1635 /* if nothing changed, don't do anything */
1636 if (winpos.flags == (SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE)) return;
1638 SetWindowPos( hwnd, winpos.hwndInsertAfter, winpos.x, winpos.y,
1639 winpos.cx, winpos.cy, winpos.flags | SWP_WINE_NOHOSTMOVE );
1643 /***********************************************************************
1644 * SetWindowRgn (X11DRV.@)
1646 * Assign specified region to window (for non-rectangular windows)
1648 int X11DRV_SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL redraw )
1652 if ((wndPtr = WIN_GetPtr( hwnd )) == WND_OTHER_PROCESS)
1654 if (IsWindow( hwnd ))
1655 FIXME( "not supported on other process window %p\n", hwnd );
1660 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1664 if (wndPtr->hrgnWnd == hrgn)
1666 WIN_ReleasePtr( wndPtr );
1670 if (wndPtr->hrgnWnd)
1672 /* delete previous region */
1673 DeleteObject(wndPtr->hrgnWnd);
1674 wndPtr->hrgnWnd = 0;
1676 wndPtr->hrgnWnd = hrgn;
1678 #ifdef HAVE_LIBXSHAPE
1680 Display *display = thread_display();
1681 X11DRV_WND_DATA *data = wndPtr->pDriverData;
1683 if (data->whole_window)
1688 XShapeCombineMask( display, data->whole_window,
1689 ShapeBounding, 0, 0, None, ShapeSet );
1690 wine_tsx11_unlock();
1695 int x_offset, y_offset;
1697 DWORD dwBufferSize = GetRegionData(hrgn, 0, NULL);
1698 PRGNDATA pRegionData = HeapAlloc(GetProcessHeap(), 0, dwBufferSize);
1701 WIN_ReleasePtr( wndPtr );
1704 GetRegionData(hrgn, dwBufferSize, pRegionData);
1705 size = pRegionData->rdh.nCount;
1706 x_offset = wndPtr->rectWindow.left - data->whole_rect.left;
1707 y_offset = wndPtr->rectWindow.top - data->whole_rect.top;
1708 /* convert region's "Windows rectangles" to XRectangles */
1709 aXRect = HeapAlloc(GetProcessHeap(), 0, size * sizeof(*aXRect) );
1712 XRectangle* pCurrRect = aXRect;
1713 RECT *pRect = (RECT*) pRegionData->Buffer;
1714 for (; pRect < ((RECT*) pRegionData->Buffer) + size ; ++pRect, ++pCurrRect)
1716 pCurrRect->x = pRect->left + x_offset;
1717 pCurrRect->y = pRect->top + y_offset;
1718 pCurrRect->height = pRect->bottom - pRect->top;
1719 pCurrRect->width = pRect->right - pRect->left;
1721 TRACE("Rectangle %04d of %04ld data: X=%04d, Y=%04d, Height=%04d, Width=%04d.\n",
1722 pRect - (RECT*) pRegionData->Buffer,
1730 /* shape = non-rectangular windows (X11/extensions) */
1732 XShapeCombineRectangles( display, data->whole_window, ShapeBounding,
1734 pCurrRect - aXRect, ShapeSet, YXBanded );
1735 wine_tsx11_unlock();
1736 HeapFree(GetProcessHeap(), 0, aXRect );
1738 HeapFree(GetProcessHeap(), 0, pRegionData);
1742 #endif /* HAVE_LIBXSHAPE */
1744 WIN_ReleasePtr( wndPtr );
1745 if (redraw) RedrawWindow( hwnd, NULL, 0, RDW_FRAME | RDW_INVALIDATE | RDW_ERASE );
1750 /***********************************************************************
1753 * Draw the frame used when moving or resizing window.
1755 * FIXME: This causes problems in Win95 mode. (why?)
1757 static void draw_moving_frame( HDC hdc, RECT *rect, BOOL thickframe )
1761 const int width = GetSystemMetrics(SM_CXFRAME);
1762 const int height = GetSystemMetrics(SM_CYFRAME);
1764 HBRUSH hbrush = SelectObject( hdc, GetStockObject( GRAY_BRUSH ) );
1765 PatBlt( hdc, rect->left, rect->top,
1766 rect->right - rect->left - width, height, PATINVERT );
1767 PatBlt( hdc, rect->left, rect->top + height, width,
1768 rect->bottom - rect->top - height, PATINVERT );
1769 PatBlt( hdc, rect->left + width, rect->bottom - 1,
1770 rect->right - rect->left - width, -height, PATINVERT );
1771 PatBlt( hdc, rect->right - 1, rect->top, -width,
1772 rect->bottom - rect->top - height, PATINVERT );
1773 SelectObject( hdc, hbrush );
1775 else DrawFocusRect( hdc, rect );
1779 /***********************************************************************
1782 * Initialisation of a move or resize, when initiatied from a menu choice.
1783 * Return hit test code for caption or sizing border.
1785 static LONG start_size_move( HWND hwnd, WPARAM wParam, POINT *capturePoint, LONG style )
1792 GetWindowRect( hwnd, &rectWindow );
1794 if ((wParam & 0xfff0) == SC_MOVE)
1796 /* Move pointer at the center of the caption */
1798 NC_GetInsideRect( hwnd, &rect );
1799 if (style & WS_SYSMENU)
1800 rect.left += GetSystemMetrics(SM_CXSIZE) + 1;
1801 if (style & WS_MINIMIZEBOX)
1802 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1803 if (style & WS_MAXIMIZEBOX)
1804 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1805 pt.x = rectWindow.left + (rect.right - rect.left) / 2;
1806 pt.y = rectWindow.top + rect.top + GetSystemMetrics(SM_CYSIZE)/2;
1807 hittest = HTCAPTION;
1814 GetMessageW( &msg, 0, WM_KEYFIRST, WM_MOUSELAST );
1815 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
1820 hittest = NC_HandleNCHitTest( hwnd, msg.pt );
1821 if ((hittest < HTLEFT) || (hittest > HTBOTTOMRIGHT))
1833 pt.x =(rectWindow.left+rectWindow.right)/2;
1834 pt.y = rectWindow.top + GetSystemMetrics(SM_CYFRAME) / 2;
1838 pt.x =(rectWindow.left+rectWindow.right)/2;
1839 pt.y = rectWindow.bottom - GetSystemMetrics(SM_CYFRAME) / 2;
1843 pt.x = rectWindow.left + GetSystemMetrics(SM_CXFRAME) / 2;
1844 pt.y =(rectWindow.top+rectWindow.bottom)/2;
1848 pt.x = rectWindow.right - GetSystemMetrics(SM_CXFRAME) / 2;
1849 pt.y =(rectWindow.top+rectWindow.bottom)/2;
1852 case VK_ESCAPE: return 0;
1858 SetCursorPos( pt.x, pt.y );
1859 NC_HandleSetCursor( hwnd, (WPARAM)hwnd, MAKELONG( hittest, WM_MOUSEMOVE ));
1864 /***********************************************************************
1865 * set_movesize_capture
1867 static void set_movesize_capture( HWND hwnd )
1871 SERVER_START_REQ( set_capture_window )
1874 req->flags = CAPTURE_MOVESIZE;
1875 if (!wine_server_call_err( req ))
1877 previous = reply->previous;
1878 hwnd = reply->full_handle;
1882 if (previous && previous != hwnd)
1883 SendMessageW( previous, WM_CAPTURECHANGED, 0, (LPARAM)hwnd );
1887 /***********************************************************************
1888 * SysCommandSizeMove (X11DRV.@)
1890 * Perform SC_MOVE and SC_SIZE commands.
1892 void X11DRV_SysCommandSizeMove( HWND hwnd, WPARAM wParam )
1895 RECT sizingRect, mouseRect, origRect;
1898 LONG hittest = (LONG)(wParam & 0x0f);
1899 HCURSOR hDragCursor = 0, hOldCursor = 0;
1900 POINT minTrack, maxTrack;
1901 POINT capturePoint, pt;
1902 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
1903 LONG exstyle = GetWindowLongA( hwnd, GWL_EXSTYLE );
1904 BOOL thickframe = HAS_THICKFRAME( style, exstyle );
1905 BOOL iconic = style & WS_MINIMIZE;
1907 DWORD dwPoint = GetMessagePos ();
1908 BOOL DragFullWindows = FALSE;
1911 Display *old_gdi_display = NULL;
1912 Display *display = thread_display();
1914 SystemParametersInfoA(SPI_GETDRAGFULLWINDOWS, 0, &DragFullWindows, 0);
1916 pt.x = (short)LOWORD(dwPoint);
1917 pt.y = (short)HIWORD(dwPoint);
1920 if (IsZoomed(hwnd) || !IsWindowVisible(hwnd) || (exstyle & WS_EX_MANAGED)) return;
1922 if ((wParam & 0xfff0) == SC_MOVE)
1924 if (!hittest) hittest = start_size_move( hwnd, wParam, &capturePoint, style );
1925 if (!hittest) return;
1929 if (!thickframe) return;
1930 if ( hittest && ((wParam & 0xfff0) != SC_MOUSEMENU) )
1931 hittest += (HTLEFT - WMSZ_LEFT);
1934 set_movesize_capture( hwnd );
1935 hittest = start_size_move( hwnd, wParam, &capturePoint, style );
1938 set_movesize_capture(0);
1944 /* Get min/max info */
1946 WINPOS_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack );
1947 GetWindowRect( hwnd, &sizingRect );
1948 if (style & WS_CHILD)
1950 parent = GetParent(hwnd);
1951 /* make sizing rect relative to parent */
1952 MapWindowPoints( 0, parent, (POINT*)&sizingRect, 2 );
1953 GetClientRect( parent, &mouseRect );
1958 SetRect(&mouseRect, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
1960 origRect = sizingRect;
1962 if (ON_LEFT_BORDER(hittest))
1964 mouseRect.left = max( mouseRect.left, sizingRect.right-maxTrack.x );
1965 mouseRect.right = min( mouseRect.right, sizingRect.right-minTrack.x );
1967 else if (ON_RIGHT_BORDER(hittest))
1969 mouseRect.left = max( mouseRect.left, sizingRect.left+minTrack.x );
1970 mouseRect.right = min( mouseRect.right, sizingRect.left+maxTrack.x );
1972 if (ON_TOP_BORDER(hittest))
1974 mouseRect.top = max( mouseRect.top, sizingRect.bottom-maxTrack.y );
1975 mouseRect.bottom = min( mouseRect.bottom,sizingRect.bottom-minTrack.y);
1977 else if (ON_BOTTOM_BORDER(hittest))
1979 mouseRect.top = max( mouseRect.top, sizingRect.top+minTrack.y );
1980 mouseRect.bottom = min( mouseRect.bottom, sizingRect.top+maxTrack.y );
1982 if (parent) MapWindowPoints( parent, 0, (LPPOINT)&mouseRect, 2 );
1984 /* Retrieve a default cache DC (without using the window style) */
1985 hdc = GetDCEx( parent, 0, DCX_CACHE );
1987 if( iconic ) /* create a cursor for dragging */
1989 hDragCursor = (HCURSOR)GetClassLongA( hwnd, GCL_HICON);
1990 if( !hDragCursor ) hDragCursor = (HCURSOR)SendMessageA( hwnd, WM_QUERYDRAGICON, 0, 0L);
1991 if( !hDragCursor ) iconic = FALSE;
1994 /* repaint the window before moving it around */
1995 RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN );
1997 SendMessageA( hwnd, WM_ENTERSIZEMOVE, 0, 0 );
1998 set_movesize_capture( hwnd );
2000 /* grab the server only when moving top-level windows without desktop */
2001 grab = (!DragFullWindows && !parent && (root_window == DefaultRootWindow(gdi_display)));
2006 XSync( gdi_display, False );
2007 XGrabServer( display );
2008 XSync( display, False );
2009 /* switch gdi display to the thread display, since the server is grabbed */
2010 old_gdi_display = gdi_display;
2011 gdi_display = display;
2013 XGrabPointer( display, X11DRV_get_whole_window(hwnd), False,
2014 PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
2015 GrabModeAsync, GrabModeAsync,
2016 parent ? X11DRV_get_client_window(parent) : root_window,
2017 None, CurrentTime );
2018 wine_tsx11_unlock();
2024 if (!GetMessageW( &msg, 0, WM_KEYFIRST, WM_MOUSELAST )) break;
2025 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
2027 /* Exit on button-up, Return, or Esc */
2028 if ((msg.message == WM_LBUTTONUP) ||
2029 ((msg.message == WM_KEYDOWN) &&
2030 ((msg.wParam == VK_RETURN) || (msg.wParam == VK_ESCAPE)))) break;
2032 if ((msg.message != WM_KEYDOWN) && (msg.message != WM_MOUSEMOVE))
2033 continue; /* We are not interested in other messages */
2037 if (msg.message == WM_KEYDOWN) switch(msg.wParam)
2039 case VK_UP: pt.y -= 8; break;
2040 case VK_DOWN: pt.y += 8; break;
2041 case VK_LEFT: pt.x -= 8; break;
2042 case VK_RIGHT: pt.x += 8; break;
2045 pt.x = max( pt.x, mouseRect.left );
2046 pt.x = min( pt.x, mouseRect.right );
2047 pt.y = max( pt.y, mouseRect.top );
2048 pt.y = min( pt.y, mouseRect.bottom );
2050 dx = pt.x - capturePoint.x;
2051 dy = pt.y - capturePoint.y;
2059 if( iconic ) /* ok, no system popup tracking */
2061 hOldCursor = SetCursor(hDragCursor);
2063 WINPOS_ShowIconTitle( hwnd, FALSE );
2065 else if(!DragFullWindows)
2066 draw_moving_frame( hdc, &sizingRect, thickframe );
2069 if (msg.message == WM_KEYDOWN) SetCursorPos( pt.x, pt.y );
2072 RECT newRect = sizingRect;
2073 WPARAM wpSizingHit = 0;
2075 if (hittest == HTCAPTION) OffsetRect( &newRect, dx, dy );
2076 if (ON_LEFT_BORDER(hittest)) newRect.left += dx;
2077 else if (ON_RIGHT_BORDER(hittest)) newRect.right += dx;
2078 if (ON_TOP_BORDER(hittest)) newRect.top += dy;
2079 else if (ON_BOTTOM_BORDER(hittest)) newRect.bottom += dy;
2080 if(!iconic && !DragFullWindows) draw_moving_frame( hdc, &sizingRect, thickframe );
2083 /* determine the hit location */
2084 if (hittest >= HTLEFT && hittest <= HTBOTTOMRIGHT)
2085 wpSizingHit = WMSZ_LEFT + (hittest - HTLEFT);
2086 SendMessageA( hwnd, WM_SIZING, wpSizingHit, (LPARAM)&newRect );
2090 if(!DragFullWindows)
2091 draw_moving_frame( hdc, &newRect, thickframe );
2093 /* To avoid any deadlocks, all the locks on the windows
2094 structures must be suspended before the SetWindowPos */
2095 iWndsLocks = WIN_SuspendWndsLock();
2096 SetWindowPos( hwnd, 0, newRect.left, newRect.top,
2097 newRect.right - newRect.left,
2098 newRect.bottom - newRect.top,
2099 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
2100 WIN_RestoreWndsLock(iWndsLocks);
2103 sizingRect = newRect;
2108 set_movesize_capture(0);
2111 if( moved ) /* restore cursors, show icon title later on */
2113 ShowCursor( FALSE );
2114 SetCursor( hOldCursor );
2117 else if (moved && !DragFullWindows)
2118 draw_moving_frame( hdc, &sizingRect, thickframe );
2120 ReleaseDC( parent, hdc );
2123 XUngrabPointer( display, CurrentTime );
2126 XSync( display, False );
2127 XUngrabServer( display );
2128 XSync( display, False );
2129 gdi_display = old_gdi_display;
2131 wine_tsx11_unlock();
2133 if (HOOK_CallHooks( WH_CBT, HCBT_MOVESIZE, (WPARAM)hwnd, (LPARAM)&sizingRect, TRUE ))
2136 SendMessageA( hwnd, WM_EXITSIZEMOVE, 0, 0 );
2137 SendMessageA( hwnd, WM_SETVISIBLE, !IsIconic(hwnd), 0L);
2139 /* window moved or resized */
2142 /* To avoid any deadlocks, all the locks on the windows
2143 structures must be suspended before the SetWindowPos */
2144 iWndsLocks = WIN_SuspendWndsLock();
2146 /* if the moving/resizing isn't canceled call SetWindowPos
2147 * with the new position or the new size of the window
2149 if (!((msg.message == WM_KEYDOWN) && (msg.wParam == VK_ESCAPE)) )
2151 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
2152 if(!DragFullWindows)
2153 SetWindowPos( hwnd, 0, sizingRect.left, sizingRect.top,
2154 sizingRect.right - sizingRect.left,
2155 sizingRect.bottom - sizingRect.top,
2156 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
2159 { /* restore previous size/position */
2161 SetWindowPos( hwnd, 0, origRect.left, origRect.top,
2162 origRect.right - origRect.left,
2163 origRect.bottom - origRect.top,
2164 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
2167 WIN_RestoreWndsLock(iWndsLocks);
2172 /* Single click brings up the system menu when iconized */
2176 if(style & WS_SYSMENU )
2177 SendMessageA( hwnd, WM_SYSCOMMAND,
2178 SC_MOUSEMENU + HTSYSMENU, MAKELONG(pt.x,pt.y));
2180 else WINPOS_ShowIconTitle( hwnd, TRUE );
2185 /***********************************************************************
2186 * ForceWindowRaise (X11DRV.@)
2188 * Raise a window on top of the X stacking order, while preserving
2189 * the correct Windows Z order.
2191 * FIXME: this should go away.
2193 void X11DRV_ForceWindowRaise( HWND hwnd )
2197 XWindowChanges winChanges;
2198 Display *display = thread_display();
2199 WND *wndPtr = WIN_FindWndPtr( hwnd );
2201 if (!wndPtr) return;
2203 if ((wndPtr->dwExStyle & WS_EX_MANAGED) ||
2204 wndPtr->parent != GetDesktopWindow() ||
2205 IsRectEmpty( &wndPtr->rectWindow ) ||
2206 !get_whole_window(wndPtr))
2208 WIN_ReleaseWndPtr( wndPtr );
2211 WIN_ReleaseWndPtr( wndPtr );
2213 /* Raise all windows up to wndPtr according to their Z order.
2214 * (it would be easier with sibling-related Below but it doesn't
2215 * work very well with SGI mwm for instance)
2217 winChanges.stack_mode = Above;
2218 if (!(list = WIN_ListChildren( GetDesktopWindow() ))) return;
2219 while (list[i] && list[i] != hwnd) i++;
2222 for ( ; i >= 0; i--)
2224 WND *ptr = WIN_FindWndPtr( list[i] );
2226 if (!IsRectEmpty( &ptr->rectWindow ) && get_whole_window(ptr))
2229 XReconfigureWMWindow( display, get_whole_window(ptr), 0, CWStackMode, &winChanges );
2230 wine_tsx11_unlock();
2232 WIN_ReleaseWndPtr( ptr );
2235 HeapFree( GetProcessHeap(), 0, list );