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 */
42 #include "cursoricon.h"
43 #include "nonclient.h"
45 #include "wine/server.h"
46 #include "wine/debug.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
50 #define SWP_AGG_NOGEOMETRYCHANGE \
51 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE)
52 #define SWP_AGG_NOPOSCHANGE \
53 (SWP_AGG_NOGEOMETRYCHANGE | SWP_NOZORDER)
54 #define SWP_AGG_STATUSFLAGS \
55 (SWP_AGG_NOPOSCHANGE | SWP_FRAMECHANGED | SWP_HIDEWINDOW | SWP_SHOWWINDOW)
57 #define SWP_EX_NOCOPY 0x0001
58 #define SWP_EX_PAINTSELF 0x0002
59 #define SWP_EX_NONCLIENT 0x0004
61 #define HAS_THICKFRAME(style,exStyle) \
62 (((style) & WS_THICKFRAME) && \
63 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
65 #define ON_LEFT_BORDER(hit) \
66 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
67 #define ON_RIGHT_BORDER(hit) \
68 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
69 #define ON_TOP_BORDER(hit) \
70 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
71 #define ON_BOTTOM_BORDER(hit) \
72 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
75 /***********************************************************************
78 * Clip all children of a given window out of the visible region
80 static int clip_children( HWND parent, HWND last, HRGN hrgn, int whole_window )
85 int i, x, y, ret = SIMPLEREGION;
87 /* first check if we have anything to do */
88 if (!(list = WIN_ListChildren( parent ))) return ret;
89 for (i = 0; list[i] && list[i] != last; i++)
90 if (GetWindowLongW( list[i], GWL_STYLE ) & WS_VISIBLE) break;
91 if (!list[i] || list[i] == last) goto done; /* no children to clip */
95 WND *win = WIN_FindWndPtr( parent );
96 x = win->rectWindow.left - win->rectClient.left;
97 y = win->rectWindow.top - win->rectClient.top;
98 WIN_ReleaseWndPtr( win );
102 rectRgn = CreateRectRgn( 0, 0, 0, 0 );
104 for ( ; list[i] && list[i] != last; i++)
106 if (!(ptr = WIN_FindWndPtr( list[i] ))) continue;
107 if (ptr->dwStyle & WS_VISIBLE)
109 SetRectRgn( rectRgn, ptr->rectWindow.left + x, ptr->rectWindow.top + y,
110 ptr->rectWindow.right + x, ptr->rectWindow.bottom + y );
111 if ((ret = CombineRgn( hrgn, hrgn, rectRgn, RGN_DIFF )) == NULLREGION)
113 WIN_ReleaseWndPtr( ptr );
114 break; /* no need to go on, region is empty */
117 WIN_ReleaseWndPtr( ptr );
119 DeleteObject( rectRgn );
121 HeapFree( GetProcessHeap(), 0, list );
126 /***********************************************************************
129 * Compute the visible region of a window
131 static HRGN get_visible_region( WND *win, HWND top, UINT flags, int mode )
135 int xoffset, yoffset;
136 X11DRV_WND_DATA *data = win->pDriverData;
138 if (flags & DCX_WINDOW)
140 xoffset = win->rectWindow.left;
141 yoffset = win->rectWindow.top;
145 xoffset = win->rectClient.left;
146 yoffset = win->rectClient.top;
149 if (flags & DCX_PARENTCLIP)
150 GetClientRect( win->parent, &rect );
151 else if (flags & DCX_WINDOW)
152 rect = data->whole_rect;
154 rect = win->rectClient;
156 /* vis region is relative to the start of the client/window area */
157 OffsetRect( &rect, -xoffset, -yoffset );
159 if (!(rgn = CreateRectRgn( rect.left, rect.top, rect.right, rect.bottom ))) return 0;
161 if ((flags & DCX_CLIPCHILDREN) && (mode != ClipByChildren))
163 /* we need to clip children by hand */
164 if (clip_children( win->hwndSelf, 0, rgn, (flags & DCX_WINDOW) ) == NULLREGION) return rgn;
167 if (top && top != win->hwndSelf) /* need to clip siblings of ancestors */
169 WND *parent, *ptr = WIN_FindWndPtr( win->hwndSelf );
172 OffsetRgn( rgn, xoffset, yoffset );
175 if (ptr->dwStyle & WS_CLIPSIBLINGS)
177 if (clip_children( ptr->parent, ptr->hwndSelf, rgn, FALSE ) == NULLREGION) break;
179 if (ptr->hwndSelf == top) break;
180 if (!(parent = WIN_FindWndPtr( ptr->parent ))) break;
181 WIN_ReleaseWndPtr( ptr );
183 /* clip to parent client area */
184 if (tmp) SetRectRgn( tmp, 0, 0, ptr->rectClient.right - ptr->rectClient.left,
185 ptr->rectClient.bottom - ptr->rectClient.top );
186 else tmp = CreateRectRgn( 0, 0, ptr->rectClient.right - ptr->rectClient.left,
187 ptr->rectClient.bottom - ptr->rectClient.top );
188 CombineRgn( rgn, rgn, tmp, RGN_AND );
189 OffsetRgn( rgn, ptr->rectClient.left, ptr->rectClient.top );
190 xoffset += ptr->rectClient.left;
191 yoffset += ptr->rectClient.top;
193 WIN_ReleaseWndPtr( ptr );
194 /* make it relative to the target window again */
195 OffsetRgn( rgn, -xoffset, -yoffset );
196 if (tmp) DeleteObject( tmp );
203 /***********************************************************************
206 * Compute the portion of 'rgn' that is covered by non-clipped siblings.
207 * This is the area that is covered from X point of view, but may still need
209 * 'rgn' must be relative to the client area of the parent of 'win'.
211 static int get_covered_region( WND *win, HRGN rgn )
215 WND *parent, *ptr = WIN_FindWndPtr( win->hwndSelf );
216 int xoffset = 0, yoffset = 0;
218 tmp = CreateRectRgn( 0, 0, 0, 0 );
219 CombineRgn( tmp, rgn, 0, RGN_COPY );
221 /* to make things easier we actually build the uncovered
222 * area by removing all siblings and then we subtract that
223 * from the total region to get the covered area */
226 if (!(ptr->dwStyle & WS_CLIPSIBLINGS))
228 if (clip_children( ptr->parent, ptr->hwndSelf, tmp, FALSE ) == NULLREGION) break;
230 if (!(parent = WIN_FindWndPtr( ptr->parent ))) break;
231 WIN_ReleaseWndPtr( ptr );
233 OffsetRgn( tmp, ptr->rectClient.left, ptr->rectClient.top );
234 xoffset += ptr->rectClient.left;
235 yoffset += ptr->rectClient.top;
237 WIN_ReleaseWndPtr( ptr );
238 /* make it relative to the target window again */
239 OffsetRgn( tmp, -xoffset, -yoffset );
241 /* now subtract the computed region from the original one */
242 ret = CombineRgn( rgn, rgn, tmp, RGN_DIFF );
248 /***********************************************************************
251 * Expose a region of a given window.
253 static void expose_window( HWND hwnd, RECT *rect, HRGN rgn, int flags )
260 /* find the top most parent that doesn't clip children or siblings and
261 * invalidate the area on its parent, including all children */
262 if ((list = WIN_ListParents( hwnd )))
265 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
266 for (i = 0; list[i] && list[i] != GetDesktopWindow(); i++)
268 if (!(style & WS_CLIPSIBLINGS)) top = current;
269 style = GetWindowLongW( list[i], GWL_STYLE );
270 if (!(style & WS_CLIPCHILDREN)) top = current;
276 /* find the parent of the top window, reusing the parent list */
277 if (top == hwnd) i = 0;
280 for (i = 0; list[i]; i++) if (list[i] == top) break;
281 if (list[i] && list[i+1]) i++;
283 if (list[i] != GetDesktopWindow()) top = list[i];
284 flags &= ~RDW_FRAME; /* parent will invalidate children frame anyway */
285 flags |= RDW_ALLCHILDREN;
287 HeapFree( GetProcessHeap(), 0, list );
290 if (!top) top = hwnd;
292 /* make coords relative to top */
293 offset.x = offset.y = 0;
294 MapWindowPoints( hwnd, top, &offset, 1 );
298 OffsetRect( rect, offset.x, offset.y );
299 RedrawWindow( top, rect, 0, flags );
303 OffsetRgn( rgn, offset.x, offset.y );
304 RedrawWindow( top, NULL, rgn, flags );
309 /***********************************************************************
310 * expose_covered_parent_area
312 * Expose the parent area that has been uncovered by moving/hiding a
313 * given window, but that is still covered by other siblings (the area
314 * not covered by siblings will be exposed automatically by X).
316 static void expose_covered_parent_area( WND *win, const RECT *old_rect )
318 int ret = SIMPLEREGION;
319 HRGN hrgn = CreateRectRgnIndirect( old_rect );
321 if (win->dwStyle & WS_VISIBLE)
323 HRGN tmp = CreateRectRgnIndirect( &win->rectWindow );
324 ret = CombineRgn( hrgn, hrgn, tmp, RGN_DIFF );
328 if (ret != NULLREGION)
330 if (get_covered_region( win, hrgn ) != NULLREGION)
331 expose_window( win->parent, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
333 DeleteObject( hrgn );
337 /***********************************************************************
338 * expose_covered_window_area
340 * Expose the area of a window that is covered by other siblings.
342 static void expose_covered_window_area( WND *win, const RECT *old_client_rect, BOOL frame )
345 int ret = SIMPLEREGION;
348 hrgn = CreateRectRgn( win->rectWindow.left - win->rectClient.left,
349 win->rectWindow.top - win->rectClient.top,
350 win->rectWindow.right - win->rectWindow.left,
351 win->rectWindow.bottom - win->rectWindow.top );
353 hrgn = CreateRectRgn( 0, 0,
354 win->rectClient.right - win->rectClient.left,
355 win->rectClient.bottom - win->rectClient.top );
357 /* if the client rect didn't move we don't need to repaint it all */
358 if (old_client_rect->left == win->rectClient.left &&
359 old_client_rect->top == win->rectClient.top)
363 if (IntersectRect( &rc, old_client_rect, &win->rectClient ))
366 /* subtract the unchanged client area from the region to expose */
367 OffsetRect( &rc, -win->rectClient.left, -win->rectClient.top );
368 if ((tmp = CreateRectRgnIndirect( &rc )))
370 ret = CombineRgn( hrgn, hrgn, tmp, RGN_DIFF );
376 if (ret != NULLREGION)
378 if (get_covered_region( win, hrgn ) != NULLREGION)
379 expose_window( win->hwndSelf, NULL, hrgn,
380 RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
383 DeleteObject( hrgn );
387 /***********************************************************************
390 void X11DRV_Expose( HWND hwnd, XExposeEvent *event )
393 struct x11drv_win_data *data;
394 int flags = RDW_INVALIDATE | RDW_ERASE;
397 TRACE( "win %p (%lx) %d,%d %dx%d\n",
398 hwnd, event->window, event->x, event->y, event->width, event->height );
400 rect.left = event->x;
402 rect.right = rect.left + event->width;
403 rect.bottom = rect.top + event->height;
405 if (!(win = WIN_GetPtr( hwnd ))) return;
406 data = win->pDriverData;
408 if (event->window != data->client_window) /* whole window or icon window */
411 /* make position relative to client area instead of window */
412 OffsetRect( &rect, -data->client_rect.left, -data->client_rect.top );
414 WIN_ReleasePtr( win );
416 expose_window( hwnd, &rect, 0, flags );
420 /***********************************************************************
423 * Set the drawable, origin and dimensions for the DC associated to
426 BOOL X11DRV_GetDC( HWND hwnd, HDC hdc, HRGN hrgn, DWORD flags )
428 WND *win = WIN_GetPtr( hwnd );
430 X11DRV_WND_DATA *data = win->pDriverData;
433 POINT org, drawable_org;
434 int mode = IncludeInferiors;
436 /* don't clip siblings if using parent clip region */
437 if (flags & DCX_PARENTCLIP) flags &= ~DCX_CLIPSIBLINGS;
439 /* find the top parent in the hierarchy that isn't clipping siblings */
440 visible = (win->dwStyle & WS_VISIBLE) != 0;
444 HWND *list = WIN_ListParents( hwnd );
448 for (i = 0; list[i] != GetDesktopWindow(); i++)
450 LONG style = GetWindowLongW( list[i], GWL_STYLE );
451 if (!(style & WS_VISIBLE))
457 if (!(style & WS_CLIPSIBLINGS)) top = list[i];
459 HeapFree( GetProcessHeap(), 0, list );
461 if (!top && visible && !(flags & DCX_CLIPSIBLINGS)) top = hwnd;
466 HWND parent = GetAncestor( top, GA_PARENT );
468 if (flags & DCX_WINDOW)
470 org.x = win->rectWindow.left - win->rectClient.left;
471 org.y = win->rectWindow.top - win->rectClient.top;
473 MapWindowPoints( hwnd, parent, &org, 1 );
474 drawable_org.x = drawable_org.y = 0;
475 MapWindowPoints( parent, 0, &drawable_org, 1 );
476 /* have to use the parent so that we include siblings */
477 if (parent) drawable = X11DRV_get_client_window( parent );
478 else drawable = root_window;
482 if (IsIconic( hwnd ))
484 drawable = data->icon_window ? data->icon_window : data->whole_window;
489 else if (flags & DCX_WINDOW)
491 drawable = data->whole_window;
492 org.x = win->rectWindow.left - data->whole_rect.left;
493 org.y = win->rectWindow.top - data->whole_rect.top;
494 drawable_org.x = data->whole_rect.left - win->rectClient.left;
495 drawable_org.y = data->whole_rect.top - win->rectClient.top;
499 drawable = data->client_window;
503 if (flags & DCX_CLIPCHILDREN) mode = ClipByChildren; /* can use X11 clipping */
505 MapWindowPoints( hwnd, 0, &drawable_org, 1 );
508 X11DRV_SetDrawable( hdc, drawable, mode, &org, &drawable_org );
510 if (flags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN) ||
511 SetHookFlags16( HDC_16(hdc), DCHF_VALIDATEVISRGN )) /* DC was dirty */
513 /* need to recompute the visible region */
518 visRgn = get_visible_region( win, top, flags, mode );
520 if (flags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN))
521 CombineRgn( visRgn, visRgn, hrgn,
522 (flags & DCX_INTERSECTRGN) ? RGN_AND : RGN_DIFF );
524 else visRgn = CreateRectRgn( 0, 0, 0, 0 );
526 SelectVisRgn16( HDC_16(hdc), HRGN_16(visRgn) );
527 DeleteObject( visRgn );
530 WIN_ReleasePtr( win );
535 /***********************************************************************
536 * ReleaseDC (X11DRV.@)
538 void X11DRV_ReleaseDC( HWND hwnd, HDC hdc )
543 X11DRV_SetDrawable( hdc, root_window, IncludeInferiors, &org, &org );
547 /***********************************************************************
548 * SWP_DoWinPosChanging
550 static BOOL SWP_DoWinPosChanging( WINDOWPOS* pWinpos, RECT* pNewWindowRect, RECT* pNewClientRect )
554 /* Send WM_WINDOWPOSCHANGING message */
556 if (!(pWinpos->flags & SWP_NOSENDCHANGING))
557 SendMessageA( pWinpos->hwnd, WM_WINDOWPOSCHANGING, 0, (LPARAM)pWinpos );
559 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return FALSE;
561 /* Calculate new position and size */
563 *pNewWindowRect = wndPtr->rectWindow;
564 *pNewClientRect = (wndPtr->dwStyle & WS_MINIMIZE) ? wndPtr->rectWindow
565 : wndPtr->rectClient;
567 if (!(pWinpos->flags & SWP_NOSIZE))
569 pNewWindowRect->right = pNewWindowRect->left + pWinpos->cx;
570 pNewWindowRect->bottom = pNewWindowRect->top + pWinpos->cy;
572 if (!(pWinpos->flags & SWP_NOMOVE))
574 pNewWindowRect->left = pWinpos->x;
575 pNewWindowRect->top = pWinpos->y;
576 pNewWindowRect->right += pWinpos->x - wndPtr->rectWindow.left;
577 pNewWindowRect->bottom += pWinpos->y - wndPtr->rectWindow.top;
579 OffsetRect( pNewClientRect, pWinpos->x - wndPtr->rectWindow.left,
580 pWinpos->y - wndPtr->rectWindow.top );
582 pWinpos->flags |= SWP_NOCLIENTMOVE | SWP_NOCLIENTSIZE;
583 WIN_ReleasePtr( wndPtr );
587 /***********************************************************************
590 static UINT SWP_DoNCCalcSize( WINDOWPOS* pWinpos, RECT* pNewWindowRect, RECT* pNewClientRect )
595 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
597 /* Send WM_NCCALCSIZE message to get new client area */
598 if( (pWinpos->flags & (SWP_FRAMECHANGED | SWP_NOSIZE)) != SWP_NOSIZE )
600 NCCALCSIZE_PARAMS params;
601 WINDOWPOS winposCopy;
603 params.rgrc[0] = *pNewWindowRect;
604 params.rgrc[1] = wndPtr->rectWindow;
605 params.rgrc[2] = wndPtr->rectClient;
606 params.lppos = &winposCopy;
607 winposCopy = *pWinpos;
608 WIN_ReleasePtr( wndPtr );
610 wvrFlags = SendMessageW( pWinpos->hwnd, WM_NCCALCSIZE, TRUE, (LPARAM)¶ms );
612 TRACE( "(%ld,%ld)-(%ld,%ld)\n", params.rgrc[0].left, params.rgrc[0].top,
613 params.rgrc[0].right, params.rgrc[0].bottom );
615 /* If the application send back garbage, ignore it */
616 if (params.rgrc[0].left <= params.rgrc[0].right &&
617 params.rgrc[0].top <= params.rgrc[0].bottom)
618 *pNewClientRect = params.rgrc[0];
620 /* FIXME: WVR_ALIGNxxx */
622 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
624 if( pNewClientRect->left != wndPtr->rectClient.left ||
625 pNewClientRect->top != wndPtr->rectClient.top )
626 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
628 if( (pNewClientRect->right - pNewClientRect->left !=
629 wndPtr->rectClient.right - wndPtr->rectClient.left) ||
630 (pNewClientRect->bottom - pNewClientRect->top !=
631 wndPtr->rectClient.bottom - wndPtr->rectClient.top) )
632 pWinpos->flags &= ~SWP_NOCLIENTSIZE;
636 if (!(pWinpos->flags & SWP_NOMOVE) &&
637 (pNewClientRect->left != wndPtr->rectClient.left ||
638 pNewClientRect->top != wndPtr->rectClient.top))
639 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
641 WIN_ReleasePtr( wndPtr );
646 /***********************************************************************
649 * fix Z order taking into account owned popups -
650 * basically we need to maintain them above the window that owns them
652 * FIXME: hide/show owned popups when owner visibility changes.
654 static HWND SWP_DoOwnedPopups(HWND hwnd, HWND hwndInsertAfter)
657 HWND owner = GetWindow( hwnd, GW_OWNER );
658 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
660 WARN("(%p) hInsertAfter = %p\n", hwnd, hwndInsertAfter );
662 if ((style & WS_POPUP) && owner)
664 /* make sure this popup stays above the owner */
666 HWND hwndLocalPrev = HWND_TOP;
668 if( hwndInsertAfter != HWND_TOP )
670 if ((list = WIN_ListChildren( GetDesktopWindow() )))
673 for (i = 0; list[i]; i++)
675 if (list[i] == owner) break;
676 if (list[i] != hwnd) hwndLocalPrev = list[i];
677 if (hwndLocalPrev == hwndInsertAfter) break;
679 hwndInsertAfter = hwndLocalPrev;
683 else if (style & WS_CHILD) return hwndInsertAfter;
685 if (!list) list = WIN_ListChildren( GetDesktopWindow() );
689 for (i = 0; list[i]; i++)
691 if (list[i] == hwnd) break;
692 if ((GetWindowLongW( list[i], GWL_STYLE ) & WS_POPUP) &&
693 GetWindow( list[i], GW_OWNER ) == hwnd)
695 SetWindowPos( list[i], hwndInsertAfter, 0, 0, 0, 0,
696 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE |
697 SWP_NOSENDCHANGING | SWP_DEFERERASE );
698 hwndInsertAfter = list[i];
701 HeapFree( GetProcessHeap(), 0, list );
704 return hwndInsertAfter;
708 /* fix redundant flags and values in the WINDOWPOS structure */
709 static BOOL fixup_flags( WINDOWPOS *winpos )
711 WND *wndPtr = WIN_GetPtr( winpos->hwnd );
714 if (!wndPtr || wndPtr == WND_OTHER_PROCESS)
716 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
719 winpos->hwnd = wndPtr->hwndSelf; /* make it a full handle */
721 if (wndPtr->dwStyle & WS_VISIBLE) winpos->flags &= ~SWP_SHOWWINDOW;
724 winpos->flags &= ~SWP_HIDEWINDOW;
725 if (!(winpos->flags & SWP_SHOWWINDOW)) winpos->flags |= SWP_NOREDRAW;
728 if (winpos->cx < 0) winpos->cx = 0;
729 if (winpos->cy < 0) winpos->cy = 0;
731 if ((wndPtr->rectWindow.right - wndPtr->rectWindow.left == winpos->cx) &&
732 (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top == winpos->cy))
733 winpos->flags |= SWP_NOSIZE; /* Already the right size */
735 if ((wndPtr->rectWindow.left == winpos->x) && (wndPtr->rectWindow.top == winpos->y))
736 winpos->flags |= SWP_NOMOVE; /* Already the right position */
738 if (winpos->hwnd == GetForegroundWindow())
739 winpos->flags |= SWP_NOACTIVATE; /* Already active */
740 else if ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD)
742 if (!(winpos->flags & SWP_NOACTIVATE)) /* Bring to the top when activating */
744 winpos->flags &= ~SWP_NOZORDER;
745 winpos->hwndInsertAfter = HWND_TOP;
750 /* Check hwndInsertAfter */
751 if (winpos->flags & SWP_NOZORDER) goto done;
753 /* fix sign extension */
754 if (winpos->hwndInsertAfter == (HWND)0xffff) winpos->hwndInsertAfter = HWND_TOPMOST;
755 else if (winpos->hwndInsertAfter == (HWND)0xfffe) winpos->hwndInsertAfter = HWND_NOTOPMOST;
757 /* FIXME: TOPMOST not supported yet */
758 if ((winpos->hwndInsertAfter == HWND_TOPMOST) ||
759 (winpos->hwndInsertAfter == HWND_NOTOPMOST)) winpos->hwndInsertAfter = HWND_TOP;
761 /* hwndInsertAfter must be a sibling of the window */
762 if ((winpos->hwndInsertAfter != HWND_TOP) && (winpos->hwndInsertAfter != HWND_BOTTOM))
764 if (GetAncestor( winpos->hwndInsertAfter, GA_PARENT ) != wndPtr->parent) ret = FALSE;
767 /* don't need to change the Zorder of hwnd if it's already inserted
768 * after hwndInsertAfter or when inserting hwnd after itself.
770 if ((winpos->hwnd == winpos->hwndInsertAfter) ||
771 (winpos->hwnd == GetWindow( winpos->hwndInsertAfter, GW_HWNDNEXT )))
772 winpos->flags |= SWP_NOZORDER;
776 WIN_ReleasePtr( wndPtr );
781 /***********************************************************************
784 * Set/clear the WS_VISIBLE style of a window and map/unmap the X window.
786 static void set_visible_style( HWND hwnd, BOOL set )
790 if (!(win = WIN_GetPtr( hwnd ))) return;
791 if (win == WND_OTHER_PROCESS) return;
793 TRACE( "hwnd %p (%lx) set %d visible %d empty %d\n",
794 hwnd, get_whole_window(win),
795 set, (win->dwStyle & WS_VISIBLE) != 0, IsRectEmpty(&win->rectWindow) );
799 if (win->dwStyle & WS_VISIBLE) goto done;
800 WIN_SetStyle( hwnd, win->dwStyle | WS_VISIBLE );
801 if (!IsRectEmpty( &win->rectWindow ) && get_whole_window(win) && is_window_top_level(win))
803 Display *display = thread_display();
804 X11DRV_sync_window_style( display, win );
805 X11DRV_set_wm_hints( display, win );
806 TRACE( "mapping win %p\n", hwnd );
808 XMapWindow( display, get_whole_window(win) );
814 if (!(win->dwStyle & WS_VISIBLE)) goto done;
815 WIN_SetStyle( hwnd, win->dwStyle & ~WS_VISIBLE );
816 if (!IsRectEmpty( &win->rectWindow ) && get_whole_window(win) && is_window_top_level(win))
818 TRACE( "unmapping win %p\n", hwnd );
820 XUnmapWindow( thread_display(), get_whole_window(win) );
825 WIN_ReleasePtr( win );
829 /***********************************************************************
830 * SetWindowStyle (X11DRV.@)
832 * Update the X state of a window to reflect a style change
834 void X11DRV_SetWindowStyle( HWND hwnd, LONG oldStyle )
836 Display *display = thread_display();
840 if (hwnd == GetDesktopWindow()) return;
841 if (!(wndPtr = WIN_GetPtr( hwnd ))) return;
842 if (wndPtr == WND_OTHER_PROCESS) return;
844 changed = wndPtr->dwStyle ^ oldStyle;
846 if (changed & WS_VISIBLE)
848 if (!IsRectEmpty( &wndPtr->rectWindow ))
850 if (wndPtr->dwStyle & WS_VISIBLE)
852 TRACE( "mapping win %p\n", hwnd );
853 if (is_window_top_level(wndPtr))
855 X11DRV_sync_window_style( display, wndPtr );
856 X11DRV_set_wm_hints( display, wndPtr );
859 XMapWindow( display, get_whole_window(wndPtr) );
862 else if (!is_window_top_level(wndPtr)) /* don't unmap managed windows */
864 TRACE( "unmapping win %p\n", hwnd );
866 XUnmapWindow( display, get_whole_window(wndPtr) );
872 if (changed & WS_DISABLED)
874 if (wndPtr->dwExStyle & WS_EX_MANAGED)
878 if (!(wm_hints = XGetWMHints( display, get_whole_window(wndPtr) )))
879 wm_hints = XAllocWMHints();
882 wm_hints->flags |= InputHint;
883 wm_hints->input = !(wndPtr->dwStyle & WS_DISABLED);
884 XSetWMHints( display, get_whole_window(wndPtr), wm_hints );
890 WIN_ReleasePtr(wndPtr);
894 /***********************************************************************
895 * SetWindowPos (X11DRV.@)
897 BOOL X11DRV_SetWindowPos( WINDOWPOS *winpos )
900 RECT newWindowRect, newClientRect;
901 RECT oldWindowRect, oldClientRect;
905 TRACE( "hwnd %p, after %p, swp %d,%d %dx%d flags %08x\n",
906 winpos->hwnd, winpos->hwndInsertAfter, winpos->x, winpos->y,
907 winpos->cx, winpos->cy, winpos->flags);
909 bChangePos = !(winpos->flags & SWP_WINE_NOHOSTMOVE);
910 winpos->flags &= ~SWP_WINE_NOHOSTMOVE;
912 /* Check window handle */
913 if (winpos->hwnd == GetDesktopWindow()) return FALSE;
915 if (!SWP_DoWinPosChanging( winpos, &newWindowRect, &newClientRect )) return FALSE;
917 /* Fix redundant flags */
918 if (!fixup_flags( winpos )) return FALSE;
920 if (!(wndPtr = WIN_FindWndPtr( winpos->hwnd ))) return FALSE;
922 TRACE("\tcurrent (%ld,%ld)-(%ld,%ld), style %08x\n",
923 wndPtr->rectWindow.left, wndPtr->rectWindow.top,
924 wndPtr->rectWindow.right, wndPtr->rectWindow.bottom, (unsigned)wndPtr->dwStyle );
926 if((winpos->flags & (SWP_NOZORDER | SWP_HIDEWINDOW | SWP_SHOWWINDOW)) != SWP_NOZORDER)
928 if (GetAncestor( winpos->hwnd, GA_PARENT ) == GetDesktopWindow())
929 winpos->hwndInsertAfter = SWP_DoOwnedPopups( winpos->hwnd, winpos->hwndInsertAfter );
932 /* Common operations */
934 wvrFlags = SWP_DoNCCalcSize( winpos, &newWindowRect, &newClientRect );
936 if(!(winpos->flags & SWP_NOZORDER) && winpos->hwnd != winpos->hwndInsertAfter)
938 HWND parent = GetAncestor( winpos->hwnd, GA_PARENT );
939 if (parent) WIN_LinkWindow( winpos->hwnd, parent, winpos->hwndInsertAfter );
942 /* Reset active DCEs */
944 if( (((winpos->flags & SWP_AGG_NOPOSCHANGE) != SWP_AGG_NOPOSCHANGE) &&
945 wndPtr->dwStyle & WS_VISIBLE) ||
946 (winpos->flags & (SWP_HIDEWINDOW | SWP_SHOWWINDOW)) )
950 UnionRect(&rect, &newWindowRect, &wndPtr->rectWindow);
951 DCE_InvalidateDCE(wndPtr->hwndSelf, &rect);
954 oldWindowRect = wndPtr->rectWindow;
955 oldClientRect = wndPtr->rectClient;
957 /* Find out if we have to redraw the whole client rect */
959 if( oldClientRect.bottom - oldClientRect.top ==
960 newClientRect.bottom - newClientRect.top ) wvrFlags &= ~WVR_VREDRAW;
962 if( oldClientRect.right - oldClientRect.left ==
963 newClientRect.right - newClientRect.left ) wvrFlags &= ~WVR_HREDRAW;
965 /* FIXME: actually do something with WVR_VALIDRECTS */
967 WIN_SetRectangles( winpos->hwnd, &newWindowRect, &newClientRect );
969 if (get_whole_window(wndPtr)) /* don't do anything if X window not created yet */
971 Display *display = thread_display();
973 if (!(winpos->flags & SWP_SHOWWINDOW) && (winpos->flags & SWP_HIDEWINDOW))
975 /* clear the update region */
976 RedrawWindow( winpos->hwnd, NULL, 0, RDW_VALIDATE | RDW_NOFRAME |
977 RDW_NOERASE | RDW_NOINTERNALPAINT | RDW_ALLCHILDREN );
978 set_visible_style( winpos->hwnd, FALSE );
980 else if ((wndPtr->dwStyle & WS_VISIBLE) &&
981 !IsRectEmpty( &oldWindowRect ) && IsRectEmpty( &newWindowRect ))
983 /* resizing to zero size -> unmap */
984 TRACE( "unmapping zero size win %p\n", winpos->hwnd );
986 XUnmapWindow( display, get_whole_window(wndPtr) );
992 X11DRV_sync_whole_window_position( display, wndPtr, !(winpos->flags & SWP_NOZORDER) );
995 struct x11drv_win_data *data = wndPtr->pDriverData;
996 data->whole_rect = wndPtr->rectWindow;
997 X11DRV_window_to_X_rect( wndPtr, &data->whole_rect );
1000 if (X11DRV_sync_client_window_position( display, wndPtr ) ||
1001 (winpos->flags & SWP_FRAMECHANGED))
1003 /* if we moved the client area, repaint the whole non-client window */
1004 XClearArea( display, get_whole_window(wndPtr), 0, 0, 0, 0, True );
1005 winpos->flags |= SWP_FRAMECHANGED;
1007 if (winpos->flags & SWP_SHOWWINDOW)
1009 set_visible_style( winpos->hwnd, TRUE );
1011 else if ((wndPtr->dwStyle & WS_VISIBLE) &&
1012 IsRectEmpty( &oldWindowRect ) && !IsRectEmpty( &newWindowRect ))
1014 /* resizing from zero size to non-zero -> map */
1015 TRACE( "mapping non zero size win %p\n", winpos->hwnd );
1016 XMapWindow( display, get_whole_window(wndPtr) );
1018 XFlush( display ); /* FIXME: should not be necessary */
1019 wine_tsx11_unlock();
1021 else /* no X window, simply toggle the window style */
1023 if (winpos->flags & SWP_SHOWWINDOW)
1024 set_visible_style( winpos->hwnd, TRUE );
1025 else if (winpos->flags & SWP_HIDEWINDOW)
1026 set_visible_style( winpos->hwnd, FALSE );
1029 /* manually expose the areas that X won't expose because they are still covered by something */
1031 if (!(winpos->flags & SWP_SHOWWINDOW))
1032 expose_covered_parent_area( wndPtr, &oldWindowRect );
1034 if (wndPtr->dwStyle & WS_VISIBLE)
1035 expose_covered_window_area( wndPtr, &oldClientRect, winpos->flags & SWP_FRAMECHANGED );
1037 WIN_ReleaseWndPtr(wndPtr);
1039 if (wvrFlags & WVR_REDRAW) RedrawWindow( winpos->hwnd, NULL, 0, RDW_INVALIDATE | RDW_ERASE );
1041 if( winpos->flags & SWP_HIDEWINDOW )
1042 HideCaret(winpos->hwnd);
1043 else if (winpos->flags & SWP_SHOWWINDOW)
1044 ShowCaret(winpos->hwnd);
1046 if (!(winpos->flags & SWP_NOACTIVATE))
1048 /* child windows get WM_CHILDACTIVATE message */
1049 if ((GetWindowLongW( winpos->hwnd, GWL_STYLE ) & (WS_CHILD | WS_POPUP)) == WS_CHILD)
1050 SendMessageA( winpos->hwnd, WM_CHILDACTIVATE, 0, 0 );
1052 SetForegroundWindow( winpos->hwnd );
1055 /* And last, send the WM_WINDOWPOSCHANGED message */
1057 TRACE("\tstatus flags = %04x\n", winpos->flags & SWP_AGG_STATUSFLAGS);
1059 if (((winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOPOSCHANGE))
1060 SendMessageA( winpos->hwnd, WM_WINDOWPOSCHANGED, 0, (LPARAM)winpos );
1061 /* WM_WINDOWPOSCHANGED is send even if SWP_NOSENDCHANGING is set */
1067 /***********************************************************************
1068 * WINPOS_FindIconPos
1070 * Find a suitable place for an iconic window.
1072 static POINT WINPOS_FindIconPos( WND* wndPtr, POINT pt )
1076 short x, y, xspacing, yspacing;
1078 GetClientRect( wndPtr->parent, &rectParent );
1079 if ((pt.x >= rectParent.left) && (pt.x + GetSystemMetrics(SM_CXICON) < rectParent.right) &&
1080 (pt.y >= rectParent.top) && (pt.y + GetSystemMetrics(SM_CYICON) < rectParent.bottom))
1081 return pt; /* The icon already has a suitable position */
1083 xspacing = GetSystemMetrics(SM_CXICONSPACING);
1084 yspacing = GetSystemMetrics(SM_CYICONSPACING);
1086 list = WIN_ListChildren( wndPtr->parent );
1087 y = rectParent.bottom;
1090 x = rectParent.left;
1093 /* Check if another icon already occupies this spot */
1094 /* FIXME: this is completely inefficient */
1100 for (i = 0; list[i]; i++)
1102 if (list[i] == wndPtr->hwndSelf) continue;
1103 if (!IsIconic( list[i] )) continue;
1104 if (!(childPtr = WIN_FindWndPtr( list[i] ))) continue;
1105 if ((childPtr->rectWindow.left < x + xspacing) &&
1106 (childPtr->rectWindow.right >= x) &&
1107 (childPtr->rectWindow.top <= y) &&
1108 (childPtr->rectWindow.bottom > y - yspacing))
1110 WIN_ReleaseWndPtr( childPtr );
1111 break; /* There's a window in there */
1113 WIN_ReleaseWndPtr( childPtr );
1117 /* found something here, try next spot */
1123 /* No window was found, so it's OK for us */
1124 pt.x = x + (xspacing - GetSystemMetrics(SM_CXICON)) / 2;
1125 pt.y = y - (yspacing + GetSystemMetrics(SM_CYICON)) / 2;
1126 HeapFree( GetProcessHeap(), 0, list );
1129 } while(x <= rectParent.right-xspacing);
1138 UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect )
1144 WINDOWPLACEMENT wpl;
1146 TRACE("%p %u\n", hwnd, cmd );
1148 wpl.length = sizeof(wpl);
1149 GetWindowPlacement( hwnd, &wpl );
1151 if (HOOK_CallHooks( WH_CBT, HCBT_MINMAX, (WPARAM)hwnd, cmd, TRUE ))
1152 return SWP_NOSIZE | SWP_NOMOVE;
1154 if (IsIconic( hwnd ))
1156 if (cmd == SW_MINIMIZE) return SWP_NOSIZE | SWP_NOMOVE;
1157 if (!SendMessageA( hwnd, WM_QUERYOPEN, 0, 0 )) return SWP_NOSIZE | SWP_NOMOVE;
1158 swpFlags |= SWP_NOCOPYBITS;
1161 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
1163 size.x = wndPtr->rectWindow.left;
1164 size.y = wndPtr->rectWindow.top;
1169 if( wndPtr->dwStyle & WS_MAXIMIZE) wndPtr->flags |= WIN_RESTORE_MAX;
1170 else wndPtr->flags &= ~WIN_RESTORE_MAX;
1172 WIN_SetStyle( hwnd, (wndPtr->dwStyle & ~WS_MAXIMIZE) | WS_MINIMIZE );
1174 X11DRV_set_iconic_state( wndPtr );
1176 wpl.ptMinPosition = WINPOS_FindIconPos( wndPtr, wpl.ptMinPosition );
1178 SetRect( rect, wpl.ptMinPosition.x, wpl.ptMinPosition.y,
1179 GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON) );
1180 swpFlags |= SWP_NOCOPYBITS;
1184 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL );
1186 old_style = WIN_SetStyle( hwnd, (wndPtr->dwStyle & ~WS_MINIMIZE) | WS_MAXIMIZE );
1187 if (old_style & WS_MINIMIZE)
1189 WINPOS_ShowIconTitle( hwnd, FALSE );
1190 X11DRV_set_iconic_state( wndPtr );
1192 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y );
1196 old_style = WIN_SetStyle( hwnd, wndPtr->dwStyle & ~(WS_MINIMIZE|WS_MAXIMIZE) );
1197 if (old_style & WS_MINIMIZE)
1199 WINPOS_ShowIconTitle( hwnd, FALSE );
1200 X11DRV_set_iconic_state( wndPtr );
1202 if( wndPtr->flags & WIN_RESTORE_MAX)
1204 /* Restore to maximized position */
1205 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL);
1206 WIN_SetStyle( hwnd, wndPtr->dwStyle | WS_MAXIMIZE );
1207 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y );
1211 else if (!(old_style & WS_MAXIMIZE)) break;
1213 /* Restore to normal position */
1215 *rect = wpl.rcNormalPosition;
1216 rect->right -= rect->left;
1217 rect->bottom -= rect->top;
1222 WIN_ReleaseWndPtr( wndPtr );
1227 /***********************************************************************
1228 * ShowWindow (X11DRV.@)
1230 BOOL X11DRV_ShowWindow( HWND hwnd, INT cmd )
1232 WND* wndPtr = WIN_FindWndPtr( hwnd );
1233 BOOL wasVisible, showFlag;
1234 RECT newPos = {0, 0, 0, 0};
1237 if (!wndPtr) return FALSE;
1238 hwnd = wndPtr->hwndSelf; /* make it a full handle */
1240 TRACE("hwnd=%p, cmd=%d\n", hwnd, cmd);
1242 wasVisible = (wndPtr->dwStyle & WS_VISIBLE) != 0;
1247 if (!wasVisible) goto END;
1248 swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE |
1249 SWP_NOACTIVATE | SWP_NOZORDER;
1252 case SW_SHOWMINNOACTIVE:
1253 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1255 case SW_SHOWMINIMIZED:
1256 case SW_FORCEMINIMIZE: /* FIXME: Does not work if thread is hung. */
1257 swp |= SWP_SHOWWINDOW;
1260 swp |= SWP_FRAMECHANGED;
1261 if( !(wndPtr->dwStyle & WS_MINIMIZE) )
1262 swp |= WINPOS_MinMaximize( hwnd, SW_MINIMIZE, &newPos );
1263 else swp |= SWP_NOSIZE | SWP_NOMOVE;
1266 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
1267 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
1268 if( !(wndPtr->dwStyle & WS_MAXIMIZE) )
1269 swp |= WINPOS_MinMaximize( hwnd, SW_MAXIMIZE, &newPos );
1270 else swp |= SWP_NOSIZE | SWP_NOMOVE;
1274 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1277 swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
1280 * ShowWindow has a little peculiar behavior that if the
1281 * window is already the topmost window, it will not
1284 if (GetTopWindow(NULL)==hwnd && (wasVisible || GetActiveWindow() == hwnd))
1285 swp |= SWP_NOACTIVATE;
1289 case SW_SHOWNOACTIVATE:
1290 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1292 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
1293 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
1295 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
1297 if( wndPtr->dwStyle & (WS_MINIMIZE | WS_MAXIMIZE) )
1298 swp |= WINPOS_MinMaximize( hwnd, SW_RESTORE, &newPos );
1299 else swp |= SWP_NOSIZE | SWP_NOMOVE;
1303 showFlag = (cmd != SW_HIDE);
1304 if (showFlag != wasVisible)
1306 SendMessageA( hwnd, WM_SHOWWINDOW, showFlag, 0 );
1307 if (!IsWindow( hwnd )) goto END;
1310 /* We can't activate a child window */
1311 if ((wndPtr->dwStyle & WS_CHILD) &&
1312 !(wndPtr->dwExStyle & WS_EX_MDICHILD))
1313 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1315 SetWindowPos( hwnd, HWND_TOP, newPos.left, newPos.top,
1316 newPos.right, newPos.bottom, LOWORD(swp) );
1319 /* FIXME: This will cause the window to be activated irrespective
1320 * of whether it is owned by the same thread. Has to be done
1324 if (hwnd == GetActiveWindow())
1325 WINPOS_ActivateOtherWindow(hwnd);
1327 /* Revert focus to parent */
1328 if (hwnd == GetFocus() || IsChild(hwnd, GetFocus()))
1329 SetFocus( GetParent(hwnd) );
1331 if (!IsWindow( hwnd )) goto END;
1332 else if( wndPtr->dwStyle & WS_MINIMIZE ) WINPOS_ShowIconTitle( hwnd, TRUE );
1334 if (wndPtr->flags & WIN_NEED_SIZE)
1336 /* should happen only in CreateWindowEx() */
1337 int wParam = SIZE_RESTORED;
1339 wndPtr->flags &= ~WIN_NEED_SIZE;
1340 if (wndPtr->dwStyle & WS_MAXIMIZE) wParam = SIZE_MAXIMIZED;
1341 else if (wndPtr->dwStyle & WS_MINIMIZE) wParam = SIZE_MINIMIZED;
1342 SendMessageA( hwnd, WM_SIZE, wParam,
1343 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
1344 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
1345 SendMessageA( hwnd, WM_MOVE, 0,
1346 MAKELONG(wndPtr->rectClient.left, wndPtr->rectClient.top) );
1350 WIN_ReleaseWndPtr(wndPtr);
1355 /**********************************************************************
1358 void X11DRV_MapNotify( HWND hwnd, XMapEvent *event )
1360 HWND hwndFocus = GetFocus();
1363 if (!(win = WIN_GetPtr( hwnd ))) return;
1365 if ((win->dwStyle & WS_VISIBLE) &&
1366 (win->dwStyle & WS_MINIMIZE) &&
1367 (win->dwExStyle & WS_EX_MANAGED))
1370 unsigned int width, height, border, depth;
1373 LONG style = (win->dwStyle & ~(WS_MINIMIZE|WS_MAXIMIZE)) | WS_VISIBLE;
1377 XGetGeometry( event->display, get_whole_window(win), &root, &x, &y, &width, &height,
1379 XTranslateCoordinates( event->display, get_whole_window(win), root, 0, 0, &x, &y, &top );
1380 wine_tsx11_unlock();
1383 rect.right = x + width;
1384 rect.bottom = y + height;
1385 X11DRV_X_to_window_rect( win, &rect );
1387 DCE_InvalidateDCE( hwnd, &win->rectWindow );
1389 if (win->flags & WIN_RESTORE_MAX) style |= WS_MAXIMIZE;
1390 WIN_SetStyle( hwnd, style );
1391 WIN_ReleasePtr( win );
1393 SendMessageA( hwnd, WM_SHOWWINDOW, SW_RESTORE, 0 );
1394 SetWindowPos( hwnd, 0, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
1395 SWP_NOZORDER | SWP_WINE_NOHOSTMOVE );
1397 else WIN_ReleasePtr( win );
1398 if (hwndFocus && IsChild( hwnd, hwndFocus )) X11DRV_SetFocus(hwndFocus); /* FIXME */
1402 /**********************************************************************
1403 * X11DRV_UnmapNotify
1405 void X11DRV_UnmapNotify( HWND hwnd, XUnmapEvent *event )
1409 if (!(win = WIN_GetPtr( hwnd ))) return;
1411 if ((win->dwStyle & WS_VISIBLE) && (win->dwExStyle & WS_EX_MANAGED))
1413 if (win->dwStyle & WS_MAXIMIZE)
1414 win->flags |= WIN_RESTORE_MAX;
1416 win->flags &= ~WIN_RESTORE_MAX;
1418 WIN_SetStyle( hwnd, (win->dwStyle & ~WS_MAXIMIZE) | WS_MINIMIZE );
1419 WIN_ReleasePtr( win );
1422 SendMessageA( hwnd, WM_SHOWWINDOW, SW_MINIMIZE, 0 );
1423 SetWindowPos( hwnd, 0, 0, 0, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON),
1424 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_WINE_NOHOSTMOVE );
1426 else WIN_ReleasePtr( win );
1430 /***********************************************************************
1433 * Synchronize internal z-order with the window manager's.
1435 static Window __get_common_ancestor( Display *display, Window A, Window B,
1436 Window** children, unsigned* total )
1438 /* find the real root window */
1440 Window root, *childrenB;
1444 while( A != B && A && B )
1446 XQueryTree( display, A, &root, &A, children, total );
1447 XQueryTree( display, B, &root, &B, &childrenB, &totalB );
1448 if( childrenB ) XFree( childrenB );
1449 if( *children ) XFree( *children ), *children = NULL;
1454 XQueryTree( display, A, &root, &B, children, total );
1455 wine_tsx11_unlock();
1458 wine_tsx11_unlock();
1462 static Window __get_top_decoration( Display *display, Window w, Window ancestor )
1464 Window* children, root, prev = w, parent = w;
1471 XQueryTree( display, w, &root, &parent, &children, &total );
1472 if( children ) XFree( children );
1473 } while( parent && parent != ancestor );
1474 wine_tsx11_unlock();
1475 TRACE("\t%08x -> %08x\n", (unsigned)prev, (unsigned)w );
1476 return ( parent ) ? w : 0 ;
1479 static unsigned __td_lookup( Window w, Window* list, unsigned max )
1482 for( i = max; i > 0; i-- ) if( list[i - 1] == w ) break;
1486 static HWND query_zorder( Display *display, HWND hWndCheck)
1488 HWND hwndInsertAfter = HWND_TOP;
1489 Window w, parent, *children = NULL;
1490 unsigned total, check, pos, best;
1491 HWND *list = WIN_ListChildren( GetDesktopWindow() );
1492 HWND hwndA = 0, hwndB = 0;
1495 /* find at least two managed windows */
1496 if (!list) return 0;
1497 for (i = 0; list[i]; i++)
1499 if (!(GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_MANAGED)) continue;
1500 if (!(GetWindowLongW( list[i], GWL_STYLE ) & WS_VISIBLE)) continue;
1501 if (!hwndA) hwndA = list[i];
1508 if (!hwndA || !hwndB) goto done;
1510 parent = __get_common_ancestor( display, X11DRV_get_whole_window(hwndA),
1511 X11DRV_get_whole_window(hwndB), &children, &total );
1512 if( parent && children )
1514 /* w is the ancestor if hWndCheck that is a direct descendant of 'parent' */
1516 w = __get_top_decoration( display, X11DRV_get_whole_window(hWndCheck), parent );
1518 if( w != children[total-1] ) /* check if at the top */
1520 /* X child at index 0 is at the bottom, at index total-1 is at the top */
1521 check = __td_lookup( w, children, total );
1524 /* go through all windows in Wine z-order... */
1525 for (i = 0; list[i]; i++)
1527 if (list[i] == hWndCheck) continue;
1528 if (!(GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_MANAGED)) continue;
1529 if (!(w = __get_top_decoration( display, X11DRV_get_whole_window(list[i]),
1530 parent ))) continue;
1531 pos = __td_lookup( w, children, total );
1532 if( pos < best && pos > check )
1534 /* find a nearest Wine window precedes hWndCheck in the real z-order */
1536 hwndInsertAfter = list[i];
1538 if( best - check == 1 ) break;
1543 if( children ) XFree( children );
1544 wine_tsx11_unlock();
1547 HeapFree( GetProcessHeap(), 0, list );
1548 return hwndInsertAfter;
1552 /***********************************************************************
1553 * X11DRV_ConfigureNotify
1555 void X11DRV_ConfigureNotify( HWND hwnd, XConfigureEvent *event )
1557 HWND oldInsertAfter;
1558 struct x11drv_win_data *data;
1562 int x = event->x, y = event->y;
1564 if (!(win = WIN_GetPtr( hwnd ))) return;
1565 data = win->pDriverData;
1569 if (!event->send_event) /* normal event, need to map coordinates to the root */
1573 XTranslateCoordinates( event->display, data->whole_window, root_window,
1574 0, 0, &x, &y, &child );
1575 wine_tsx11_unlock();
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 );
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;
1602 oldInsertAfter = GetWindow( oldInsertAfter, GW_HWNDPREV );
1603 if (!oldInsertAfter)
1605 oldInsertAfter = HWND_TOP;
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;
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) ||
1621 (IsRectEmpty( &rect ) && winpos.cx == 1 && winpos.cy == 1))
1622 winpos.flags |= SWP_NOSIZE;
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;
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 )
1650 if ((wndPtr = WIN_GetPtr( hwnd )) == WND_OTHER_PROCESS)
1652 if (IsWindow( hwnd ))
1653 FIXME( "not supported on other process window %p\n", hwnd );
1658 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1662 if (wndPtr->hrgnWnd == hrgn)
1664 WIN_ReleasePtr( wndPtr );
1668 if (wndPtr->hrgnWnd)
1670 /* delete previous region */
1671 DeleteObject(wndPtr->hrgnWnd);
1672 wndPtr->hrgnWnd = 0;
1674 wndPtr->hrgnWnd = hrgn;
1676 #ifdef HAVE_LIBXSHAPE
1678 Display *display = thread_display();
1679 X11DRV_WND_DATA *data = wndPtr->pDriverData;
1681 if (data->whole_window)
1686 XShapeCombineMask( display, data->whole_window,
1687 ShapeBounding, 0, 0, None, ShapeSet );
1688 wine_tsx11_unlock();
1693 int x_offset, y_offset;
1695 DWORD dwBufferSize = GetRegionData(hrgn, 0, NULL);
1696 PRGNDATA pRegionData = HeapAlloc(GetProcessHeap(), 0, dwBufferSize);
1699 WIN_ReleasePtr( wndPtr );
1702 GetRegionData(hrgn, dwBufferSize, pRegionData);
1703 size = pRegionData->rdh.nCount;
1704 x_offset = wndPtr->rectWindow.left - data->whole_rect.left;
1705 y_offset = wndPtr->rectWindow.top - data->whole_rect.top;
1706 /* convert region's "Windows rectangles" to XRectangles */
1707 aXRect = HeapAlloc(GetProcessHeap(), 0, size * sizeof(*aXRect) );
1710 XRectangle* pCurrRect = aXRect;
1711 RECT *pRect = (RECT*) pRegionData->Buffer;
1712 for (; pRect < ((RECT*) pRegionData->Buffer) + size ; ++pRect, ++pCurrRect)
1714 pCurrRect->x = pRect->left + x_offset;
1715 pCurrRect->y = pRect->top + y_offset;
1716 pCurrRect->height = pRect->bottom - pRect->top;
1717 pCurrRect->width = pRect->right - pRect->left;
1719 TRACE("Rectangle %04d of %04ld data: X=%04d, Y=%04d, Height=%04d, Width=%04d.\n",
1720 pRect - (RECT*) pRegionData->Buffer,
1728 /* shape = non-rectangular windows (X11/extensions) */
1730 XShapeCombineRectangles( display, data->whole_window, ShapeBounding,
1732 pCurrRect - aXRect, ShapeSet, YXBanded );
1733 wine_tsx11_unlock();
1734 HeapFree(GetProcessHeap(), 0, aXRect );
1736 HeapFree(GetProcessHeap(), 0, pRegionData);
1740 #endif /* HAVE_LIBXSHAPE */
1742 WIN_ReleasePtr( wndPtr );
1743 if (redraw) RedrawWindow( hwnd, NULL, 0, RDW_FRAME | RDW_INVALIDATE | RDW_ERASE );
1748 /***********************************************************************
1751 * Draw the frame used when moving or resizing window.
1753 * FIXME: This causes problems in Win95 mode. (why?)
1755 static void draw_moving_frame( HDC hdc, RECT *rect, BOOL thickframe )
1759 const int width = GetSystemMetrics(SM_CXFRAME);
1760 const int height = GetSystemMetrics(SM_CYFRAME);
1762 HBRUSH hbrush = SelectObject( hdc, GetStockObject( GRAY_BRUSH ) );
1763 PatBlt( hdc, rect->left, rect->top,
1764 rect->right - rect->left - width, height, PATINVERT );
1765 PatBlt( hdc, rect->left, rect->top + height, width,
1766 rect->bottom - rect->top - height, PATINVERT );
1767 PatBlt( hdc, rect->left + width, rect->bottom - 1,
1768 rect->right - rect->left - width, -height, PATINVERT );
1769 PatBlt( hdc, rect->right - 1, rect->top, -width,
1770 rect->bottom - rect->top - height, PATINVERT );
1771 SelectObject( hdc, hbrush );
1773 else DrawFocusRect( hdc, rect );
1777 /***********************************************************************
1780 * Initialisation of a move or resize, when initiatied from a menu choice.
1781 * Return hit test code for caption or sizing border.
1783 static LONG start_size_move( HWND hwnd, WPARAM wParam, POINT *capturePoint, LONG style )
1790 GetWindowRect( hwnd, &rectWindow );
1792 if ((wParam & 0xfff0) == SC_MOVE)
1794 /* Move pointer at the center of the caption */
1796 NC_GetInsideRect( hwnd, &rect );
1797 if (style & WS_SYSMENU)
1798 rect.left += GetSystemMetrics(SM_CXSIZE) + 1;
1799 if (style & WS_MINIMIZEBOX)
1800 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1801 if (style & WS_MAXIMIZEBOX)
1802 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1803 pt.x = rectWindow.left + (rect.right - rect.left) / 2;
1804 pt.y = rectWindow.top + rect.top + GetSystemMetrics(SM_CYSIZE)/2;
1805 hittest = HTCAPTION;
1812 GetMessageW( &msg, 0, WM_KEYFIRST, WM_MOUSELAST );
1813 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
1818 hittest = NC_HandleNCHitTest( hwnd, msg.pt );
1819 if ((hittest < HTLEFT) || (hittest > HTBOTTOMRIGHT))
1831 pt.x =(rectWindow.left+rectWindow.right)/2;
1832 pt.y = rectWindow.top + GetSystemMetrics(SM_CYFRAME) / 2;
1836 pt.x =(rectWindow.left+rectWindow.right)/2;
1837 pt.y = rectWindow.bottom - GetSystemMetrics(SM_CYFRAME) / 2;
1841 pt.x = rectWindow.left + GetSystemMetrics(SM_CXFRAME) / 2;
1842 pt.y =(rectWindow.top+rectWindow.bottom)/2;
1846 pt.x = rectWindow.right - GetSystemMetrics(SM_CXFRAME) / 2;
1847 pt.y =(rectWindow.top+rectWindow.bottom)/2;
1850 case VK_ESCAPE: return 0;
1856 SetCursorPos( pt.x, pt.y );
1857 NC_HandleSetCursor( hwnd, (WPARAM)hwnd, MAKELONG( hittest, WM_MOUSEMOVE ));
1862 /***********************************************************************
1863 * set_movesize_capture
1865 static void set_movesize_capture( HWND hwnd )
1869 SERVER_START_REQ( set_capture_window )
1872 req->flags = CAPTURE_MOVESIZE;
1873 if (!wine_server_call_err( req ))
1875 previous = reply->previous;
1876 hwnd = reply->full_handle;
1880 if (previous && previous != hwnd)
1881 SendMessageW( previous, WM_CAPTURECHANGED, 0, (LPARAM)hwnd );
1885 /***********************************************************************
1886 * SysCommandSizeMove (X11DRV.@)
1888 * Perform SC_MOVE and SC_SIZE commands.
1890 void X11DRV_SysCommandSizeMove( HWND hwnd, WPARAM wParam )
1893 RECT sizingRect, mouseRect, origRect;
1896 LONG hittest = (LONG)(wParam & 0x0f);
1897 HCURSOR hDragCursor = 0, hOldCursor = 0;
1898 POINT minTrack, maxTrack;
1899 POINT capturePoint, pt;
1900 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
1901 LONG exstyle = GetWindowLongA( hwnd, GWL_EXSTYLE );
1902 BOOL thickframe = HAS_THICKFRAME( style, exstyle );
1903 BOOL iconic = style & WS_MINIMIZE;
1905 DWORD dwPoint = GetMessagePos ();
1906 BOOL DragFullWindows = FALSE;
1909 Display *old_gdi_display = NULL;
1910 Display *display = thread_display();
1912 SystemParametersInfoA(SPI_GETDRAGFULLWINDOWS, 0, &DragFullWindows, 0);
1914 pt.x = (short)LOWORD(dwPoint);
1915 pt.y = (short)HIWORD(dwPoint);
1918 if (IsZoomed(hwnd) || !IsWindowVisible(hwnd) || (exstyle & WS_EX_MANAGED)) return;
1920 if ((wParam & 0xfff0) == SC_MOVE)
1922 if (!hittest) hittest = start_size_move( hwnd, wParam, &capturePoint, style );
1923 if (!hittest) return;
1927 if (!thickframe) return;
1928 if ( hittest && ((wParam & 0xfff0) != SC_MOUSEMENU) )
1929 hittest += (HTLEFT - WMSZ_LEFT);
1932 set_movesize_capture( hwnd );
1933 hittest = start_size_move( hwnd, wParam, &capturePoint, style );
1936 set_movesize_capture(0);
1942 /* Get min/max info */
1944 WINPOS_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack );
1945 GetWindowRect( hwnd, &sizingRect );
1946 if (style & WS_CHILD)
1948 parent = GetParent(hwnd);
1949 /* make sizing rect relative to parent */
1950 MapWindowPoints( 0, parent, (POINT*)&sizingRect, 2 );
1951 GetClientRect( parent, &mouseRect );
1956 SetRect(&mouseRect, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
1958 origRect = sizingRect;
1960 if (ON_LEFT_BORDER(hittest))
1962 mouseRect.left = max( mouseRect.left, sizingRect.right-maxTrack.x );
1963 mouseRect.right = min( mouseRect.right, sizingRect.right-minTrack.x );
1965 else if (ON_RIGHT_BORDER(hittest))
1967 mouseRect.left = max( mouseRect.left, sizingRect.left+minTrack.x );
1968 mouseRect.right = min( mouseRect.right, sizingRect.left+maxTrack.x );
1970 if (ON_TOP_BORDER(hittest))
1972 mouseRect.top = max( mouseRect.top, sizingRect.bottom-maxTrack.y );
1973 mouseRect.bottom = min( mouseRect.bottom,sizingRect.bottom-minTrack.y);
1975 else if (ON_BOTTOM_BORDER(hittest))
1977 mouseRect.top = max( mouseRect.top, sizingRect.top+minTrack.y );
1978 mouseRect.bottom = min( mouseRect.bottom, sizingRect.top+maxTrack.y );
1980 if (parent) MapWindowPoints( parent, 0, (LPPOINT)&mouseRect, 2 );
1982 /* Retrieve a default cache DC (without using the window style) */
1983 hdc = GetDCEx( parent, 0, DCX_CACHE );
1985 if( iconic ) /* create a cursor for dragging */
1987 hDragCursor = (HCURSOR)GetClassLongA( hwnd, GCL_HICON);
1988 if( !hDragCursor ) hDragCursor = (HCURSOR)SendMessageA( hwnd, WM_QUERYDRAGICON, 0, 0L);
1989 if( !hDragCursor ) iconic = FALSE;
1992 /* repaint the window before moving it around */
1993 RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN );
1995 SendMessageA( hwnd, WM_ENTERSIZEMOVE, 0, 0 );
1996 set_movesize_capture( hwnd );
1998 /* grab the server only when moving top-level windows without desktop */
1999 grab = (!DragFullWindows && !parent && (root_window == DefaultRootWindow(gdi_display)));
2004 XSync( gdi_display, False );
2005 XGrabServer( display );
2006 XSync( display, False );
2007 /* switch gdi display to the thread display, since the server is grabbed */
2008 old_gdi_display = gdi_display;
2009 gdi_display = display;
2011 XGrabPointer( display, X11DRV_get_whole_window(hwnd), False,
2012 PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
2013 GrabModeAsync, GrabModeAsync,
2014 parent ? X11DRV_get_client_window(parent) : root_window,
2015 None, CurrentTime );
2016 wine_tsx11_unlock();
2022 if (!GetMessageW( &msg, 0, WM_KEYFIRST, WM_MOUSELAST )) break;
2023 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
2025 /* Exit on button-up, Return, or Esc */
2026 if ((msg.message == WM_LBUTTONUP) ||
2027 ((msg.message == WM_KEYDOWN) &&
2028 ((msg.wParam == VK_RETURN) || (msg.wParam == VK_ESCAPE)))) break;
2030 if ((msg.message != WM_KEYDOWN) && (msg.message != WM_MOUSEMOVE))
2031 continue; /* We are not interested in other messages */
2035 if (msg.message == WM_KEYDOWN) switch(msg.wParam)
2037 case VK_UP: pt.y -= 8; break;
2038 case VK_DOWN: pt.y += 8; break;
2039 case VK_LEFT: pt.x -= 8; break;
2040 case VK_RIGHT: pt.x += 8; break;
2043 pt.x = max( pt.x, mouseRect.left );
2044 pt.x = min( pt.x, mouseRect.right );
2045 pt.y = max( pt.y, mouseRect.top );
2046 pt.y = min( pt.y, mouseRect.bottom );
2048 dx = pt.x - capturePoint.x;
2049 dy = pt.y - capturePoint.y;
2057 if( iconic ) /* ok, no system popup tracking */
2059 hOldCursor = SetCursor(hDragCursor);
2061 WINPOS_ShowIconTitle( hwnd, FALSE );
2063 else if(!DragFullWindows)
2064 draw_moving_frame( hdc, &sizingRect, thickframe );
2067 if (msg.message == WM_KEYDOWN) SetCursorPos( pt.x, pt.y );
2070 RECT newRect = sizingRect;
2071 WPARAM wpSizingHit = 0;
2073 if (hittest == HTCAPTION) OffsetRect( &newRect, dx, dy );
2074 if (ON_LEFT_BORDER(hittest)) newRect.left += dx;
2075 else if (ON_RIGHT_BORDER(hittest)) newRect.right += dx;
2076 if (ON_TOP_BORDER(hittest)) newRect.top += dy;
2077 else if (ON_BOTTOM_BORDER(hittest)) newRect.bottom += dy;
2078 if(!iconic && !DragFullWindows) draw_moving_frame( hdc, &sizingRect, thickframe );
2081 /* determine the hit location */
2082 if (hittest >= HTLEFT && hittest <= HTBOTTOMRIGHT)
2083 wpSizingHit = WMSZ_LEFT + (hittest - HTLEFT);
2084 SendMessageA( hwnd, WM_SIZING, wpSizingHit, (LPARAM)&newRect );
2088 if(!DragFullWindows)
2089 draw_moving_frame( hdc, &newRect, thickframe );
2091 /* To avoid any deadlocks, all the locks on the windows
2092 structures must be suspended before the SetWindowPos */
2093 iWndsLocks = WIN_SuspendWndsLock();
2094 SetWindowPos( hwnd, 0, newRect.left, newRect.top,
2095 newRect.right - newRect.left,
2096 newRect.bottom - newRect.top,
2097 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
2098 WIN_RestoreWndsLock(iWndsLocks);
2101 sizingRect = newRect;
2106 set_movesize_capture(0);
2109 if( moved ) /* restore cursors, show icon title later on */
2111 ShowCursor( FALSE );
2112 SetCursor( hOldCursor );
2115 else if (moved && !DragFullWindows)
2116 draw_moving_frame( hdc, &sizingRect, thickframe );
2118 ReleaseDC( parent, hdc );
2121 XUngrabPointer( display, CurrentTime );
2124 XSync( display, False );
2125 XUngrabServer( display );
2126 XSync( display, False );
2127 gdi_display = old_gdi_display;
2129 wine_tsx11_unlock();
2131 if (HOOK_CallHooks( WH_CBT, HCBT_MOVESIZE, (WPARAM)hwnd, (LPARAM)&sizingRect, TRUE ))
2134 SendMessageA( hwnd, WM_EXITSIZEMOVE, 0, 0 );
2135 SendMessageA( hwnd, WM_SETVISIBLE, !IsIconic(hwnd), 0L);
2137 /* window moved or resized */
2140 /* To avoid any deadlocks, all the locks on the windows
2141 structures must be suspended before the SetWindowPos */
2142 iWndsLocks = WIN_SuspendWndsLock();
2144 /* if the moving/resizing isn't canceled call SetWindowPos
2145 * with the new position or the new size of the window
2147 if (!((msg.message == WM_KEYDOWN) && (msg.wParam == VK_ESCAPE)) )
2149 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
2150 if(!DragFullWindows)
2151 SetWindowPos( hwnd, 0, sizingRect.left, sizingRect.top,
2152 sizingRect.right - sizingRect.left,
2153 sizingRect.bottom - sizingRect.top,
2154 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
2157 { /* restore previous size/position */
2159 SetWindowPos( hwnd, 0, origRect.left, origRect.top,
2160 origRect.right - origRect.left,
2161 origRect.bottom - origRect.top,
2162 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
2165 WIN_RestoreWndsLock(iWndsLocks);
2170 /* Single click brings up the system menu when iconized */
2174 if(style & WS_SYSMENU )
2175 SendMessageA( hwnd, WM_SYSCOMMAND,
2176 SC_MOUSEMENU + HTSYSMENU, MAKELONG(pt.x,pt.y));
2178 else WINPOS_ShowIconTitle( hwnd, TRUE );
2183 /***********************************************************************
2184 * ForceWindowRaise (X11DRV.@)
2186 * Raise a window on top of the X stacking order, while preserving
2187 * the correct Windows Z order.
2189 * FIXME: this should go away.
2191 void X11DRV_ForceWindowRaise( HWND hwnd )
2195 XWindowChanges winChanges;
2196 Display *display = thread_display();
2197 WND *wndPtr = WIN_FindWndPtr( hwnd );
2199 if (!wndPtr) return;
2201 if ((wndPtr->dwExStyle & WS_EX_MANAGED) ||
2202 wndPtr->parent != GetDesktopWindow() ||
2203 IsRectEmpty( &wndPtr->rectWindow ) ||
2204 !get_whole_window(wndPtr))
2206 WIN_ReleaseWndPtr( wndPtr );
2209 WIN_ReleaseWndPtr( wndPtr );
2211 /* Raise all windows up to wndPtr according to their Z order.
2212 * (it would be easier with sibling-related Below but it doesn't
2213 * work very well with SGI mwm for instance)
2215 winChanges.stack_mode = Above;
2216 if (!(list = WIN_ListChildren( GetDesktopWindow() ))) return;
2217 while (list[i] && list[i] != hwnd) i++;
2220 for ( ; i >= 0; i--)
2222 WND *ptr = WIN_FindWndPtr( list[i] );
2224 if (!IsRectEmpty( &ptr->rectWindow ) && get_whole_window(ptr))
2227 XReconfigureWMWindow( display, get_whole_window(ptr), 0, CWStackMode, &winChanges );
2228 wine_tsx11_unlock();
2230 WIN_ReleaseWndPtr( ptr );
2233 HeapFree( GetProcessHeap(), 0, list );