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 */
38 #include "wine/wingdi16.h"
44 #include "cursoricon.h"
45 #include "nonclient.h"
47 #include "wine/server.h"
48 #include "wine/debug.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
52 #define SWP_AGG_NOGEOMETRYCHANGE \
53 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE)
54 #define SWP_AGG_NOPOSCHANGE \
55 (SWP_AGG_NOGEOMETRYCHANGE | SWP_NOZORDER)
56 #define SWP_AGG_STATUSFLAGS \
57 (SWP_AGG_NOPOSCHANGE | SWP_FRAMECHANGED | SWP_HIDEWINDOW | SWP_SHOWWINDOW)
59 #define SWP_EX_NOCOPY 0x0001
60 #define SWP_EX_PAINTSELF 0x0002
61 #define SWP_EX_NONCLIENT 0x0004
63 #define HAS_THICKFRAME(style,exStyle) \
64 (((style) & WS_THICKFRAME) && \
65 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
67 #define ON_LEFT_BORDER(hit) \
68 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
69 #define ON_RIGHT_BORDER(hit) \
70 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
71 #define ON_TOP_BORDER(hit) \
72 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
73 #define ON_BOTTOM_BORDER(hit) \
74 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
76 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
77 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
78 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
79 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
80 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
81 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
82 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
83 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
84 #define _NET_WM_MOVERESIZE_MOVE 8 /* movement only */
85 #define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9 /* size via keyboard */
86 #define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10 /* move via keyboard */
89 /***********************************************************************
92 * Clip all children of a given window out of the visible region
94 static int clip_children( HWND parent, HWND last, HRGN hrgn, int whole_window )
99 int i, x, y, ret = SIMPLEREGION;
101 /* first check if we have anything to do */
102 if (!(list = WIN_ListChildren( parent ))) return ret;
106 WND *win = WIN_FindWndPtr( parent );
107 x = win->rectWindow.left - win->rectClient.left;
108 y = win->rectWindow.top - win->rectClient.top;
109 WIN_ReleaseWndPtr( win );
113 rectRgn = CreateRectRgn( 0, 0, 0, 0 );
115 for (i = 0; list[i] && list[i] != last; i++)
117 if (!(ptr = WIN_FindWndPtr( list[i] ))) continue;
118 if ((ptr->dwStyle & WS_VISIBLE) && !(ptr->dwExStyle & WS_EX_TRANSPARENT))
120 SetRectRgn( rectRgn, ptr->rectWindow.left + x, ptr->rectWindow.top + y,
121 ptr->rectWindow.right + x, ptr->rectWindow.bottom + y );
122 if ((ret = CombineRgn( hrgn, hrgn, rectRgn, RGN_DIFF )) == NULLREGION)
124 WIN_ReleaseWndPtr( ptr );
125 break; /* no need to go on, region is empty */
128 WIN_ReleaseWndPtr( ptr );
130 DeleteObject( rectRgn );
131 HeapFree( GetProcessHeap(), 0, list );
136 /***********************************************************************
137 * get_server_visible_region
139 static HRGN get_server_visible_region( HWND hwnd, HWND top, UINT flags )
148 if (!(data = HeapAlloc( GetProcessHeap(), 0, sizeof(*data) + size - 1 ))) return 0;
149 SERVER_START_REQ( get_visible_region )
154 wine_server_set_reply( req, data->Buffer, size );
155 if (!(status = wine_server_call( req )))
157 size_t reply_size = wine_server_reply_size( reply );
158 data->rdh.dwSize = sizeof(data->rdh);
159 data->rdh.iType = RDH_RECTANGLES;
160 data->rdh.nCount = reply_size / sizeof(RECT);
161 data->rdh.nRgnSize = reply_size;
162 ret = ExtCreateRegion( NULL, size, data );
164 else size = reply->total_size;
167 HeapFree( GetProcessHeap(), 0, data );
168 } while (status == STATUS_BUFFER_OVERFLOW);
170 if (status) SetLastError( RtlNtStatusToDosError(status) );
175 /***********************************************************************
178 * Compute the portion of 'rgn' that is covered by non-clipped siblings.
179 * This is the area that is covered from X point of view, but may still need
181 * 'rgn' must be relative to the client area of the parent of 'win'.
183 static int get_covered_region( WND *win, HRGN rgn )
187 WND *parent, *ptr = WIN_FindWndPtr( win->hwndSelf );
188 int xoffset = 0, yoffset = 0;
190 tmp = CreateRectRgn( 0, 0, 0, 0 );
191 CombineRgn( tmp, rgn, 0, RGN_COPY );
193 /* to make things easier we actually build the uncovered
194 * area by removing all siblings and then we subtract that
195 * from the total region to get the covered area */
198 if (!(ptr->dwStyle & WS_CLIPSIBLINGS))
200 if (clip_children( ptr->parent, ptr->hwndSelf, tmp, FALSE ) == NULLREGION) break;
202 if (!(parent = WIN_FindWndPtr( ptr->parent ))) break;
203 WIN_ReleaseWndPtr( ptr );
205 OffsetRgn( tmp, ptr->rectClient.left, ptr->rectClient.top );
206 xoffset += ptr->rectClient.left;
207 yoffset += ptr->rectClient.top;
209 WIN_ReleaseWndPtr( ptr );
210 /* make it relative to the target window again */
211 OffsetRgn( tmp, -xoffset, -yoffset );
213 /* now subtract the computed region from the original one */
214 ret = CombineRgn( rgn, rgn, tmp, RGN_DIFF );
220 /***********************************************************************
223 * Expose a region of a given window.
225 static void expose_window( HWND hwnd, RECT *rect, HRGN rgn, int flags )
232 /* find the top most parent that doesn't clip children or siblings and
233 * invalidate the area on its parent, including all children */
234 if ((list = WIN_ListParents( hwnd )))
237 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
238 for (i = 0; list[i] && list[i] != GetDesktopWindow(); i++)
240 if (!(style & WS_CLIPSIBLINGS)) top = current;
241 style = GetWindowLongW( list[i], GWL_STYLE );
242 if (!(style & WS_CLIPCHILDREN)) top = current;
248 /* find the parent of the top window, reusing the parent list */
249 if (top == hwnd) i = 0;
252 for (i = 0; list[i]; i++) if (list[i] == top) break;
253 if (list[i] && list[i+1]) i++;
255 if (list[i] != GetDesktopWindow()) top = list[i];
256 flags &= ~RDW_FRAME; /* parent will invalidate children frame anyway */
257 flags |= RDW_ALLCHILDREN;
259 HeapFree( GetProcessHeap(), 0, list );
262 if (!top) top = hwnd;
264 /* make coords relative to top */
265 offset.x = offset.y = 0;
266 MapWindowPoints( hwnd, top, &offset, 1 );
270 OffsetRect( rect, offset.x, offset.y );
271 RedrawWindow( top, rect, 0, flags );
275 OffsetRgn( rgn, offset.x, offset.y );
276 RedrawWindow( top, NULL, rgn, flags );
281 /***********************************************************************
282 * expose_covered_parent_area
284 * Expose the parent area that has been uncovered by moving/hiding a
285 * given window, but that is still covered by other siblings (the area
286 * not covered by siblings will be exposed automatically by X).
288 static void expose_covered_parent_area( WND *win, const RECT *old_rect )
290 int ret = SIMPLEREGION;
291 HRGN hrgn = CreateRectRgnIndirect( old_rect );
293 if (win->dwStyle & WS_VISIBLE)
295 HRGN tmp = CreateRectRgnIndirect( &win->rectWindow );
296 ret = CombineRgn( hrgn, hrgn, tmp, RGN_DIFF );
300 if (ret != NULLREGION)
302 if (get_covered_region( win, hrgn ) != NULLREGION)
303 expose_window( win->parent, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
305 DeleteObject( hrgn );
309 /***********************************************************************
310 * expose_covered_window_area
312 * Expose the area of a window that is covered by other siblings.
314 static void expose_covered_window_area( WND *win, const RECT *old_client_rect, BOOL frame )
317 int ret = SIMPLEREGION;
320 hrgn = CreateRectRgn( win->rectWindow.left - win->rectClient.left,
321 win->rectWindow.top - win->rectClient.top,
322 win->rectWindow.right - win->rectWindow.left,
323 win->rectWindow.bottom - win->rectWindow.top );
325 hrgn = CreateRectRgn( 0, 0,
326 win->rectClient.right - win->rectClient.left,
327 win->rectClient.bottom - win->rectClient.top );
329 /* if the client rect didn't move we don't need to repaint it all */
330 if (old_client_rect->left == win->rectClient.left &&
331 old_client_rect->top == win->rectClient.top)
335 if (IntersectRect( &rc, old_client_rect, &win->rectClient ))
338 /* subtract the unchanged client area from the region to expose */
339 OffsetRect( &rc, -win->rectClient.left, -win->rectClient.top );
340 if ((tmp = CreateRectRgnIndirect( &rc )))
342 ret = CombineRgn( hrgn, hrgn, tmp, RGN_DIFF );
348 if (ret != NULLREGION)
350 if (get_covered_region( win, hrgn ) != NULLREGION)
351 expose_window( win->hwndSelf, NULL, hrgn,
352 RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
355 DeleteObject( hrgn );
359 /***********************************************************************
362 void X11DRV_Expose( HWND hwnd, XExposeEvent *event )
365 struct x11drv_win_data *data;
366 int flags = RDW_INVALIDATE | RDW_ERASE;
369 TRACE( "win %p (%lx) %d,%d %dx%d\n",
370 hwnd, event->window, event->x, event->y, event->width, event->height );
372 rect.left = event->x;
374 rect.right = rect.left + event->width;
375 rect.bottom = rect.top + event->height;
377 if (!(win = WIN_GetPtr( hwnd ))) return;
378 data = win->pDriverData;
380 if (event->window != data->client_window) /* whole window or icon window */
383 /* make position relative to client area instead of window */
384 OffsetRect( &rect, -data->client_rect.left, -data->client_rect.top );
386 WIN_ReleasePtr( win );
388 expose_window( hwnd, &rect, 0, flags );
392 /***********************************************************************
395 * Set the drawable, origin and dimensions for the DC associated to
398 BOOL X11DRV_GetDC( HWND hwnd, HDC hdc, HRGN hrgn, DWORD flags )
400 WND *win = WIN_GetPtr( hwnd );
402 X11DRV_WND_DATA *data = win->pDriverData;
403 struct x11drv_escape_set_drawable escape;
405 escape.mode = IncludeInferiors;
406 /* don't clip siblings if using parent clip region */
407 if (flags & DCX_PARENTCLIP) flags &= ~DCX_CLIPSIBLINGS;
409 top = GetAncestor( hwnd, GA_ROOT );
410 if (!top) top = GetDesktopWindow();
414 /* find the top most parent that doesn't clip siblings */
415 HWND clipping_parent = 0;
416 HWND *list = WIN_ListParents( hwnd );
420 for (i = 0; list[i] != top; i++)
422 LONG style = GetWindowLongW( list[i], GWL_STYLE );
423 if (!(style & WS_CLIPSIBLINGS)) clipping_parent = list[i];
425 HeapFree( GetProcessHeap(), 0, list );
428 clipping_parent = GetAncestor( clipping_parent, GA_PARENT );
429 else if (!(flags & DCX_CLIPSIBLINGS) || (flags & DCX_WINDOW))
430 clipping_parent = GetAncestor( hwnd, GA_PARENT );
432 clipping_parent = hwnd;
434 escape.org.x = escape.org.y = 0;
435 escape.drawable_org.x = escape.drawable_org.y = 0;
436 if (flags & DCX_WINDOW)
438 escape.org.x = win->rectWindow.left - win->rectClient.left;
439 escape.org.y = win->rectWindow.top - win->rectClient.top;
441 MapWindowPoints( hwnd, clipping_parent, &escape.org, 1 );
442 MapWindowPoints( clipping_parent, 0, &escape.drawable_org, 1 );
443 escape.drawable = X11DRV_get_client_window( clipping_parent );
447 if (IsIconic( hwnd ))
449 escape.drawable = data->icon_window ? data->icon_window : data->whole_window;
452 escape.drawable_org = escape.org;
454 else if (flags & DCX_WINDOW)
456 escape.drawable = data->whole_window;
457 escape.drawable_org.x = data->whole_rect.left;
458 escape.drawable_org.y = data->whole_rect.top;
459 escape.org.x = win->rectWindow.left - data->whole_rect.left;
460 escape.org.y = win->rectWindow.top - data->whole_rect.top;
464 escape.drawable = data->client_window;
465 escape.drawable_org.x = win->rectClient.left;
466 escape.drawable_org.y = win->rectClient.top;
472 escape.code = X11DRV_SET_DRAWABLE;
473 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
475 if (flags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN) ||
476 SetHookFlags16( HDC_16(hdc), DCHF_VALIDATEVISRGN )) /* DC was dirty */
478 /* need to recompute the visible region */
479 HRGN visRgn = get_server_visible_region( hwnd, top, flags );
481 if (flags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN))
482 CombineRgn( visRgn, visRgn, hrgn, (flags & DCX_INTERSECTRGN) ? RGN_AND : RGN_DIFF );
484 SelectVisRgn16( HDC_16(hdc), HRGN_16(visRgn) );
485 DeleteObject( visRgn );
488 WIN_ReleasePtr( win );
493 /***********************************************************************
494 * ReleaseDC (X11DRV.@)
496 void X11DRV_ReleaseDC( HWND hwnd, HDC hdc )
498 struct x11drv_escape_set_drawable escape;
500 escape.code = X11DRV_SET_DRAWABLE;
501 escape.drawable = root_window;
502 escape.mode = IncludeInferiors;
503 escape.org.x = escape.org.y = 0;
504 escape.drawable_org.x = escape.drawable_org.y = 0;
506 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
510 /***********************************************************************
511 * SWP_DoWinPosChanging
513 static BOOL SWP_DoWinPosChanging( WINDOWPOS* pWinpos, RECT* pNewWindowRect, RECT* pNewClientRect )
517 /* Send WM_WINDOWPOSCHANGING message */
519 if (!(pWinpos->flags & SWP_NOSENDCHANGING))
520 SendMessageW( pWinpos->hwnd, WM_WINDOWPOSCHANGING, 0, (LPARAM)pWinpos );
522 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return FALSE;
524 /* Calculate new position and size */
526 *pNewWindowRect = wndPtr->rectWindow;
527 *pNewClientRect = (wndPtr->dwStyle & WS_MINIMIZE) ? wndPtr->rectWindow
528 : wndPtr->rectClient;
530 if (!(pWinpos->flags & SWP_NOSIZE))
532 pNewWindowRect->right = pNewWindowRect->left + pWinpos->cx;
533 pNewWindowRect->bottom = pNewWindowRect->top + pWinpos->cy;
535 if (!(pWinpos->flags & SWP_NOMOVE))
537 pNewWindowRect->left = pWinpos->x;
538 pNewWindowRect->top = pWinpos->y;
539 pNewWindowRect->right += pWinpos->x - wndPtr->rectWindow.left;
540 pNewWindowRect->bottom += pWinpos->y - wndPtr->rectWindow.top;
542 OffsetRect( pNewClientRect, pWinpos->x - wndPtr->rectWindow.left,
543 pWinpos->y - wndPtr->rectWindow.top );
545 pWinpos->flags |= SWP_NOCLIENTMOVE | SWP_NOCLIENTSIZE;
546 WIN_ReleasePtr( wndPtr );
550 /***********************************************************************
553 static UINT SWP_DoNCCalcSize( WINDOWPOS* pWinpos, RECT* pNewWindowRect, RECT* pNewClientRect )
558 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
560 /* Send WM_NCCALCSIZE message to get new client area */
561 if( (pWinpos->flags & (SWP_FRAMECHANGED | SWP_NOSIZE)) != SWP_NOSIZE )
563 NCCALCSIZE_PARAMS params;
564 WINDOWPOS winposCopy;
566 params.rgrc[0] = *pNewWindowRect;
567 params.rgrc[1] = wndPtr->rectWindow;
568 params.rgrc[2] = wndPtr->rectClient;
569 params.lppos = &winposCopy;
570 winposCopy = *pWinpos;
571 WIN_ReleasePtr( wndPtr );
573 wvrFlags = SendMessageW( pWinpos->hwnd, WM_NCCALCSIZE, TRUE, (LPARAM)¶ms );
575 TRACE( "(%ld,%ld)-(%ld,%ld)\n", params.rgrc[0].left, params.rgrc[0].top,
576 params.rgrc[0].right, params.rgrc[0].bottom );
578 /* If the application send back garbage, ignore it */
579 if (params.rgrc[0].left <= params.rgrc[0].right &&
580 params.rgrc[0].top <= params.rgrc[0].bottom)
581 *pNewClientRect = params.rgrc[0];
583 /* FIXME: WVR_ALIGNxxx */
585 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
587 if( pNewClientRect->left != wndPtr->rectClient.left ||
588 pNewClientRect->top != wndPtr->rectClient.top )
589 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
591 if( (pNewClientRect->right - pNewClientRect->left !=
592 wndPtr->rectClient.right - wndPtr->rectClient.left) ||
593 (pNewClientRect->bottom - pNewClientRect->top !=
594 wndPtr->rectClient.bottom - wndPtr->rectClient.top) )
595 pWinpos->flags &= ~SWP_NOCLIENTSIZE;
599 if (!(pWinpos->flags & SWP_NOMOVE) &&
600 (pNewClientRect->left != wndPtr->rectClient.left ||
601 pNewClientRect->top != wndPtr->rectClient.top))
602 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
604 WIN_ReleasePtr( wndPtr );
609 /***********************************************************************
612 * fix Z order taking into account owned popups -
613 * basically we need to maintain them above the window that owns them
615 * FIXME: hide/show owned popups when owner visibility changes.
617 static HWND SWP_DoOwnedPopups(HWND hwnd, HWND hwndInsertAfter)
620 HWND owner = GetWindow( hwnd, GW_OWNER );
621 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
623 WARN("(%p) hInsertAfter = %p\n", hwnd, hwndInsertAfter );
625 if ((style & WS_POPUP) && owner)
627 /* make sure this popup stays above the owner */
629 HWND hwndLocalPrev = HWND_TOP;
631 if( hwndInsertAfter != HWND_TOP )
633 if ((list = WIN_ListChildren( GetDesktopWindow() )))
636 for (i = 0; list[i]; i++)
638 if (list[i] == owner) break;
639 if (list[i] != hwnd) hwndLocalPrev = list[i];
640 if (hwndLocalPrev == hwndInsertAfter) break;
642 hwndInsertAfter = hwndLocalPrev;
646 else if (style & WS_CHILD) return hwndInsertAfter;
648 if (!list) list = WIN_ListChildren( GetDesktopWindow() );
652 for (i = 0; list[i]; i++)
654 if (list[i] == hwnd) break;
655 if ((GetWindowLongW( list[i], GWL_STYLE ) & WS_POPUP) &&
656 GetWindow( list[i], GW_OWNER ) == hwnd)
658 SetWindowPos( list[i], hwndInsertAfter, 0, 0, 0, 0,
659 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE |
660 SWP_NOSENDCHANGING | SWP_DEFERERASE );
661 hwndInsertAfter = list[i];
664 HeapFree( GetProcessHeap(), 0, list );
667 return hwndInsertAfter;
671 /* fix redundant flags and values in the WINDOWPOS structure */
672 static BOOL fixup_flags( WINDOWPOS *winpos )
674 WND *wndPtr = WIN_GetPtr( winpos->hwnd );
677 if (!wndPtr || wndPtr == WND_OTHER_PROCESS)
679 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
682 winpos->hwnd = wndPtr->hwndSelf; /* make it a full handle */
684 /* Finally make sure that all coordinates are valid */
685 if (winpos->x < -32768) winpos->x = -32768;
686 else if (winpos->x > 32767) winpos->x = 32767;
687 if (winpos->y < -32768) winpos->y = -32768;
688 else if (winpos->y > 32767) winpos->y = 32767;
690 if (winpos->cx < 0) winpos->cx = 0;
691 else if (winpos->cx > 32767) winpos->cx = 32767;
692 if (winpos->cy < 0) winpos->cy = 0;
693 else if (winpos->cy > 32767) winpos->cy = 32767;
695 if (wndPtr->dwStyle & WS_VISIBLE) winpos->flags &= ~SWP_SHOWWINDOW;
698 winpos->flags &= ~SWP_HIDEWINDOW;
699 if (!(winpos->flags & SWP_SHOWWINDOW)) winpos->flags |= SWP_NOREDRAW;
702 if ((wndPtr->rectWindow.right - wndPtr->rectWindow.left == winpos->cx) &&
703 (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top == winpos->cy))
704 winpos->flags |= SWP_NOSIZE; /* Already the right size */
706 if ((wndPtr->rectWindow.left == winpos->x) && (wndPtr->rectWindow.top == winpos->y))
707 winpos->flags |= SWP_NOMOVE; /* Already the right position */
709 if ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD)
711 if (!(winpos->flags & SWP_NOACTIVATE)) /* Bring to the top when activating */
713 winpos->flags &= ~SWP_NOZORDER;
714 winpos->hwndInsertAfter = HWND_TOP;
718 /* Check hwndInsertAfter */
719 if (winpos->flags & SWP_NOZORDER) goto done;
721 /* fix sign extension */
722 if (winpos->hwndInsertAfter == (HWND)0xffff) winpos->hwndInsertAfter = HWND_TOPMOST;
723 else if (winpos->hwndInsertAfter == (HWND)0xfffe) winpos->hwndInsertAfter = HWND_NOTOPMOST;
725 /* FIXME: TOPMOST not supported yet */
726 if ((winpos->hwndInsertAfter == HWND_TOPMOST) ||
727 (winpos->hwndInsertAfter == HWND_NOTOPMOST)) winpos->hwndInsertAfter = HWND_TOP;
729 /* hwndInsertAfter must be a sibling of the window */
730 if (winpos->hwndInsertAfter == HWND_TOP)
732 if (GetWindow(winpos->hwnd, GW_HWNDFIRST) == winpos->hwnd)
733 winpos->flags |= SWP_NOZORDER;
735 else if (winpos->hwndInsertAfter == HWND_BOTTOM)
737 if (GetWindow(winpos->hwnd, GW_HWNDLAST) == winpos->hwnd)
738 winpos->flags |= SWP_NOZORDER;
742 if (GetAncestor( winpos->hwndInsertAfter, GA_PARENT ) != wndPtr->parent) ret = FALSE;
745 /* don't need to change the Zorder of hwnd if it's already inserted
746 * after hwndInsertAfter or when inserting hwnd after itself.
748 if ((winpos->hwnd == winpos->hwndInsertAfter) ||
749 (winpos->hwnd == GetWindow( winpos->hwndInsertAfter, GW_HWNDNEXT )))
750 winpos->flags |= SWP_NOZORDER;
754 WIN_ReleasePtr( wndPtr );
759 /***********************************************************************
762 * Set/clear the WS_VISIBLE style of a window and map/unmap the X window.
764 static void set_visible_style( HWND hwnd, BOOL set )
768 if (!(win = WIN_GetPtr( hwnd ))) return;
769 if (win == WND_OTHER_PROCESS) return;
771 TRACE( "hwnd %p (%lx) set %d visible %d empty %d\n",
772 hwnd, get_whole_window(win),
773 set, (win->dwStyle & WS_VISIBLE) != 0, IsRectEmpty(&win->rectWindow) );
777 if (win->dwStyle & WS_VISIBLE) goto done;
778 WIN_SetStyle( hwnd, win->dwStyle | WS_VISIBLE );
779 if (X11DRV_is_window_rect_mapped( &win->rectWindow ) &&
780 get_whole_window(win) && is_window_top_level(win))
782 Display *display = thread_display();
783 X11DRV_sync_window_style( display, win );
784 X11DRV_set_wm_hints( display, win );
785 TRACE( "mapping win %p\n", hwnd );
787 XMapWindow( display, get_whole_window(win) );
793 if (!(win->dwStyle & WS_VISIBLE)) goto done;
794 WIN_SetStyle( hwnd, win->dwStyle & ~WS_VISIBLE );
795 if (X11DRV_is_window_rect_mapped( &win->rectWindow ) &&
796 get_whole_window(win) && is_window_top_level(win))
798 TRACE( "unmapping win %p\n", hwnd );
800 XUnmapWindow( thread_display(), get_whole_window(win) );
805 WIN_ReleasePtr( win );
809 /***********************************************************************
810 * SetWindowStyle (X11DRV.@)
812 * Update the X state of a window to reflect a style change
814 void X11DRV_SetWindowStyle( HWND hwnd, LONG oldStyle )
816 Display *display = thread_display();
820 if (hwnd == GetDesktopWindow()) return;
821 if (!(wndPtr = WIN_GetPtr( hwnd ))) return;
822 if (wndPtr == WND_OTHER_PROCESS) return;
824 changed = wndPtr->dwStyle ^ oldStyle;
826 if (changed & WS_VISIBLE)
828 if (X11DRV_is_window_rect_mapped( &wndPtr->rectWindow ))
830 if (wndPtr->dwStyle & WS_VISIBLE)
832 TRACE( "mapping win %p\n", hwnd );
833 if (is_window_top_level(wndPtr))
835 X11DRV_sync_window_style( display, wndPtr );
836 X11DRV_set_wm_hints( display, wndPtr );
839 XMapWindow( display, get_whole_window(wndPtr) );
842 else if (!is_window_top_level(wndPtr)) /* don't unmap managed windows */
844 TRACE( "unmapping win %p\n", hwnd );
846 XUnmapWindow( display, get_whole_window(wndPtr) );
852 if (changed & WS_DISABLED)
854 if (wndPtr->dwExStyle & WS_EX_MANAGED)
858 if (!(wm_hints = XGetWMHints( display, get_whole_window(wndPtr) )))
859 wm_hints = XAllocWMHints();
862 wm_hints->flags |= InputHint;
863 wm_hints->input = !(wndPtr->dwStyle & WS_DISABLED);
864 XSetWMHints( display, get_whole_window(wndPtr), wm_hints );
870 WIN_ReleasePtr(wndPtr);
874 /***********************************************************************
875 * SetWindowPos (X11DRV.@)
877 BOOL X11DRV_SetWindowPos( WINDOWPOS *winpos )
880 RECT newWindowRect, newClientRect;
881 RECT oldWindowRect, oldClientRect;
885 TRACE( "hwnd %p, after %p, swp %d,%d %dx%d flags %08x\n",
886 winpos->hwnd, winpos->hwndInsertAfter, winpos->x, winpos->y,
887 winpos->cx, winpos->cy, winpos->flags);
889 bChangePos = !(winpos->flags & SWP_WINE_NOHOSTMOVE);
890 winpos->flags &= ~SWP_WINE_NOHOSTMOVE;
892 /* Check window handle */
893 if (winpos->hwnd == GetDesktopWindow()) return FALSE;
895 /* First make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
896 if (!(winpos->flags & SWP_NOMOVE))
898 if (winpos->x < -32768) winpos->x = -32768;
899 else if (winpos->x > 32767) winpos->x = 32767;
900 if (winpos->y < -32768) winpos->y = -32768;
901 else if (winpos->y > 32767) winpos->y = 32767;
903 if (!(winpos->flags & SWP_NOSIZE))
905 if (winpos->cx < 0) winpos->cx = 0;
906 else if (winpos->cx > 32767) winpos->cx = 32767;
907 if (winpos->cy < 0) winpos->cy = 0;
908 else if (winpos->cy > 32767) winpos->cy = 32767;
911 if (!SWP_DoWinPosChanging( winpos, &newWindowRect, &newClientRect )) return FALSE;
913 /* Fix redundant flags */
914 if (!fixup_flags( winpos )) return FALSE;
916 if (!(wndPtr = WIN_FindWndPtr( winpos->hwnd ))) return FALSE;
918 TRACE("\tcurrent (%ld,%ld)-(%ld,%ld), style %08x\n",
919 wndPtr->rectWindow.left, wndPtr->rectWindow.top,
920 wndPtr->rectWindow.right, wndPtr->rectWindow.bottom, (unsigned)wndPtr->dwStyle );
922 if((winpos->flags & (SWP_NOZORDER | SWP_HIDEWINDOW | SWP_SHOWWINDOW)) != SWP_NOZORDER)
924 if (GetAncestor( winpos->hwnd, GA_PARENT ) == GetDesktopWindow())
925 winpos->hwndInsertAfter = SWP_DoOwnedPopups( winpos->hwnd, winpos->hwndInsertAfter );
928 /* Common operations */
930 wvrFlags = SWP_DoNCCalcSize( winpos, &newWindowRect, &newClientRect );
932 if(!(winpos->flags & SWP_NOZORDER) && winpos->hwnd != winpos->hwndInsertAfter)
934 HWND parent = GetAncestor( winpos->hwnd, GA_PARENT );
935 if (parent) WIN_LinkWindow( winpos->hwnd, parent, winpos->hwndInsertAfter );
938 /* Reset active DCEs */
940 if( (((winpos->flags & SWP_AGG_NOPOSCHANGE) != SWP_AGG_NOPOSCHANGE) &&
941 wndPtr->dwStyle & WS_VISIBLE) ||
942 (winpos->flags & (SWP_HIDEWINDOW | SWP_SHOWWINDOW)) )
946 UnionRect(&rect, &newWindowRect, &wndPtr->rectWindow);
947 DCE_InvalidateDCE(wndPtr->hwndSelf, &rect);
950 oldWindowRect = wndPtr->rectWindow;
951 oldClientRect = wndPtr->rectClient;
953 /* Find out if we have to redraw the whole client rect */
955 if( oldClientRect.bottom - oldClientRect.top ==
956 newClientRect.bottom - newClientRect.top ) wvrFlags &= ~WVR_VREDRAW;
958 if( oldClientRect.right - oldClientRect.left ==
959 newClientRect.right - newClientRect.left ) wvrFlags &= ~WVR_HREDRAW;
961 /* FIXME: actually do something with WVR_VALIDRECTS */
963 X11DRV_set_window_rectangles( winpos->hwnd, &newWindowRect, &newClientRect );
965 if (get_whole_window(wndPtr)) /* don't do anything if X window not created yet */
967 Display *display = thread_display();
969 if (!(winpos->flags & SWP_SHOWWINDOW) && (winpos->flags & SWP_HIDEWINDOW))
971 /* clear the update region */
972 RedrawWindow( winpos->hwnd, NULL, 0, RDW_VALIDATE | RDW_NOFRAME |
973 RDW_NOERASE | RDW_NOINTERNALPAINT | RDW_ALLCHILDREN );
974 set_visible_style( winpos->hwnd, FALSE );
976 else if ((wndPtr->dwStyle & WS_VISIBLE) && bChangePos &&
977 X11DRV_is_window_rect_mapped( &oldWindowRect ) &&
978 !X11DRV_is_window_rect_mapped( &newWindowRect ))
980 /* resizing to zero size or off screen -> unmap */
981 TRACE( "unmapping zero size or off-screen win %p\n", winpos->hwnd );
983 XUnmapWindow( display, get_whole_window(wndPtr) );
988 X11DRV_sync_whole_window_position( display, wndPtr, !(winpos->flags & SWP_NOZORDER) );
991 struct x11drv_win_data *data = wndPtr->pDriverData;
992 data->whole_rect = wndPtr->rectWindow;
993 X11DRV_window_to_X_rect( wndPtr, &data->whole_rect );
996 if (X11DRV_sync_client_window_position( display, wndPtr ) ||
997 (winpos->flags & SWP_FRAMECHANGED))
999 /* if we moved the client area, repaint the whole non-client window */
1001 XClearArea( display, get_whole_window(wndPtr), 0, 0, 0, 0, True );
1002 wine_tsx11_unlock();
1004 if (winpos->flags & SWP_SHOWWINDOW)
1006 set_visible_style( winpos->hwnd, TRUE );
1008 else if ((wndPtr->dwStyle & WS_VISIBLE) && bChangePos &&
1009 !X11DRV_is_window_rect_mapped( &oldWindowRect ) &&
1010 X11DRV_is_window_rect_mapped( &newWindowRect ))
1012 /* resizing from zero size to non-zero -> map */
1013 TRACE( "mapping non zero size or off-screen win %p\n", winpos->hwnd );
1015 XMapWindow( display, get_whole_window(wndPtr) );
1016 wine_tsx11_unlock();
1019 XFlush( display ); /* FIXME: should not be necessary */
1020 wine_tsx11_unlock();
1022 else /* no X window, simply toggle the window style */
1024 if (winpos->flags & SWP_SHOWWINDOW)
1025 set_visible_style( winpos->hwnd, TRUE );
1026 else if (winpos->flags & SWP_HIDEWINDOW)
1027 set_visible_style( winpos->hwnd, FALSE );
1030 /* manually expose the areas that X won't expose because they are still covered by something */
1032 if (!(winpos->flags & SWP_SHOWWINDOW))
1033 expose_covered_parent_area( wndPtr, &oldWindowRect );
1035 if (wndPtr->dwStyle & WS_VISIBLE)
1036 expose_covered_window_area( wndPtr, &oldClientRect, winpos->flags & SWP_FRAMECHANGED );
1038 WIN_ReleaseWndPtr(wndPtr);
1040 if (wvrFlags & WVR_REDRAW) RedrawWindow( winpos->hwnd, NULL, 0, RDW_INVALIDATE | RDW_ERASE );
1042 if( winpos->flags & SWP_HIDEWINDOW )
1043 HideCaret(winpos->hwnd);
1044 else if (winpos->flags & SWP_SHOWWINDOW)
1045 ShowCaret(winpos->hwnd);
1047 if (!(winpos->flags & SWP_NOACTIVATE))
1049 /* child windows get WM_CHILDACTIVATE message */
1050 if ((GetWindowLongW( winpos->hwnd, GWL_STYLE ) & (WS_CHILD | WS_POPUP)) == WS_CHILD)
1051 SendMessageA( winpos->hwnd, WM_CHILDACTIVATE, 0, 0 );
1053 SetForegroundWindow( winpos->hwnd );
1056 /* And last, send the WM_WINDOWPOSCHANGED message */
1058 TRACE("\tstatus flags = %04x\n", winpos->flags & SWP_AGG_STATUSFLAGS);
1060 if (((winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOPOSCHANGE))
1062 /* WM_WINDOWPOSCHANGED is sent even if SWP_NOSENDCHANGING is set
1063 and always contains final window position.
1065 winpos->x = newWindowRect.left;
1066 winpos->y = newWindowRect.top;
1067 winpos->cx = newWindowRect.right - newWindowRect.left;
1068 winpos->cy = newWindowRect.bottom - newWindowRect.top;
1069 SendMessageW( winpos->hwnd, WM_WINDOWPOSCHANGED, 0, (LPARAM)winpos );
1076 /***********************************************************************
1077 * WINPOS_FindIconPos
1079 * Find a suitable place for an iconic window.
1081 static POINT WINPOS_FindIconPos( WND* wndPtr, POINT pt )
1085 short x, y, xspacing, yspacing;
1087 GetClientRect( wndPtr->parent, &rectParent );
1088 if ((pt.x >= rectParent.left) && (pt.x + GetSystemMetrics(SM_CXICON) < rectParent.right) &&
1089 (pt.y >= rectParent.top) && (pt.y + GetSystemMetrics(SM_CYICON) < rectParent.bottom))
1090 return pt; /* The icon already has a suitable position */
1092 xspacing = GetSystemMetrics(SM_CXICONSPACING);
1093 yspacing = GetSystemMetrics(SM_CYICONSPACING);
1095 list = WIN_ListChildren( wndPtr->parent );
1096 y = rectParent.bottom;
1099 x = rectParent.left;
1102 /* Check if another icon already occupies this spot */
1103 /* FIXME: this is completely inefficient */
1109 for (i = 0; list[i]; i++)
1111 if (list[i] == wndPtr->hwndSelf) continue;
1112 if (!IsIconic( list[i] )) continue;
1113 if (!(childPtr = WIN_FindWndPtr( list[i] ))) continue;
1114 if ((childPtr->rectWindow.left < x + xspacing) &&
1115 (childPtr->rectWindow.right >= x) &&
1116 (childPtr->rectWindow.top <= y) &&
1117 (childPtr->rectWindow.bottom > y - yspacing))
1119 WIN_ReleaseWndPtr( childPtr );
1120 break; /* There's a window in there */
1122 WIN_ReleaseWndPtr( childPtr );
1126 /* found something here, try next spot */
1132 /* No window was found, so it's OK for us */
1133 pt.x = x + (xspacing - GetSystemMetrics(SM_CXICON)) / 2;
1134 pt.y = y - (yspacing + GetSystemMetrics(SM_CYICON)) / 2;
1135 HeapFree( GetProcessHeap(), 0, list );
1138 } while(x <= rectParent.right-xspacing);
1147 UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect )
1153 WINDOWPLACEMENT wpl;
1155 TRACE("%p %u\n", hwnd, cmd );
1157 wpl.length = sizeof(wpl);
1158 GetWindowPlacement( hwnd, &wpl );
1160 if (HOOK_CallHooks( WH_CBT, HCBT_MINMAX, (WPARAM)hwnd, cmd, TRUE ))
1161 return SWP_NOSIZE | SWP_NOMOVE;
1163 if (IsIconic( hwnd ))
1165 if (cmd == SW_MINIMIZE) return SWP_NOSIZE | SWP_NOMOVE;
1166 if (!SendMessageA( hwnd, WM_QUERYOPEN, 0, 0 )) return SWP_NOSIZE | SWP_NOMOVE;
1167 swpFlags |= SWP_NOCOPYBITS;
1170 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
1172 size.x = wndPtr->rectWindow.left;
1173 size.y = wndPtr->rectWindow.top;
1178 if( wndPtr->dwStyle & WS_MAXIMIZE) wndPtr->flags |= WIN_RESTORE_MAX;
1179 else wndPtr->flags &= ~WIN_RESTORE_MAX;
1181 WIN_SetStyle( hwnd, (wndPtr->dwStyle & ~WS_MAXIMIZE) | WS_MINIMIZE );
1183 X11DRV_set_iconic_state( wndPtr );
1185 wpl.ptMinPosition = WINPOS_FindIconPos( wndPtr, wpl.ptMinPosition );
1187 SetRect( rect, wpl.ptMinPosition.x, wpl.ptMinPosition.y,
1188 GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON) );
1189 swpFlags |= SWP_NOCOPYBITS;
1193 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL );
1195 old_style = WIN_SetStyle( hwnd, (wndPtr->dwStyle & ~WS_MINIMIZE) | WS_MAXIMIZE );
1196 if (old_style & WS_MINIMIZE)
1198 WINPOS_ShowIconTitle( hwnd, FALSE );
1199 X11DRV_set_iconic_state( wndPtr );
1201 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y );
1205 old_style = WIN_SetStyle( hwnd, wndPtr->dwStyle & ~(WS_MINIMIZE|WS_MAXIMIZE) );
1206 if (old_style & WS_MINIMIZE)
1208 WINPOS_ShowIconTitle( hwnd, FALSE );
1209 X11DRV_set_iconic_state( wndPtr );
1211 if( wndPtr->flags & WIN_RESTORE_MAX)
1213 /* Restore to maximized position */
1214 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL);
1215 WIN_SetStyle( hwnd, wndPtr->dwStyle | WS_MAXIMIZE );
1216 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y );
1220 else if (!(old_style & WS_MAXIMIZE)) break;
1222 /* Restore to normal position */
1224 *rect = wpl.rcNormalPosition;
1225 rect->right -= rect->left;
1226 rect->bottom -= rect->top;
1231 WIN_ReleaseWndPtr( wndPtr );
1236 /***********************************************************************
1237 * ShowWindow (X11DRV.@)
1239 BOOL X11DRV_ShowWindow( HWND hwnd, INT cmd )
1241 WND* wndPtr = WIN_FindWndPtr( hwnd );
1242 BOOL wasVisible, showFlag;
1243 RECT newPos = {0, 0, 0, 0};
1246 if (!wndPtr) return FALSE;
1247 hwnd = wndPtr->hwndSelf; /* make it a full handle */
1249 wasVisible = (wndPtr->dwStyle & WS_VISIBLE) != 0;
1251 TRACE("hwnd=%p, cmd=%d, wasVisible %d\n", hwnd, cmd, wasVisible);
1256 if (!wasVisible) goto END;
1257 swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE |
1258 SWP_NOACTIVATE | SWP_NOZORDER;
1261 case SW_SHOWMINNOACTIVE:
1262 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1264 case SW_SHOWMINIMIZED:
1265 case SW_FORCEMINIMIZE: /* FIXME: Does not work if thread is hung. */
1266 swp |= SWP_SHOWWINDOW;
1269 swp |= SWP_FRAMECHANGED;
1270 if( !(wndPtr->dwStyle & WS_MINIMIZE) )
1271 swp |= WINPOS_MinMaximize( hwnd, SW_MINIMIZE, &newPos );
1272 else swp |= SWP_NOSIZE | SWP_NOMOVE;
1275 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
1276 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
1277 if( !(wndPtr->dwStyle & WS_MAXIMIZE) )
1278 swp |= WINPOS_MinMaximize( hwnd, SW_MAXIMIZE, &newPos );
1279 else swp |= SWP_NOSIZE | SWP_NOMOVE;
1283 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1286 if (wasVisible) goto END;
1288 swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
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 SendMessageW( 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) );
1323 /* FIXME: This will cause the window to be activated irrespective
1324 * of whether it is owned by the same thread. Has to be done
1328 if (hwnd == GetActiveWindow())
1329 WINPOS_ActivateOtherWindow(hwnd);
1331 /* Revert focus to parent */
1332 hFocus = GetFocus();
1333 if (hwnd == hFocus || IsChild(hwnd, hFocus))
1335 HWND parent = GetAncestor(hwnd, GA_PARENT);
1336 if (parent == GetDesktopWindow()) parent = 0;
1340 if (!IsWindow( hwnd )) goto END;
1341 else if( wndPtr->dwStyle & WS_MINIMIZE ) WINPOS_ShowIconTitle( hwnd, TRUE );
1343 if (wndPtr->flags & WIN_NEED_SIZE)
1345 /* should happen only in CreateWindowEx() */
1346 int wParam = SIZE_RESTORED;
1348 wndPtr->flags &= ~WIN_NEED_SIZE;
1349 if (wndPtr->dwStyle & WS_MAXIMIZE) wParam = SIZE_MAXIMIZED;
1350 else if (wndPtr->dwStyle & WS_MINIMIZE) wParam = SIZE_MINIMIZED;
1351 SendMessageA( hwnd, WM_SIZE, wParam,
1352 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
1353 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
1354 SendMessageA( hwnd, WM_MOVE, 0,
1355 MAKELONG(wndPtr->rectClient.left, wndPtr->rectClient.top) );
1359 WIN_ReleaseWndPtr(wndPtr);
1364 /**********************************************************************
1367 void X11DRV_MapNotify( HWND hwnd, XMapEvent *event )
1369 HWND hwndFocus = GetFocus();
1372 if (!(win = WIN_GetPtr( hwnd ))) return;
1374 if ((win->dwStyle & WS_VISIBLE) &&
1375 (win->dwStyle & WS_MINIMIZE) &&
1376 (win->dwExStyle & WS_EX_MANAGED))
1379 unsigned int width, height, border, depth;
1382 LONG style = (win->dwStyle & ~(WS_MINIMIZE|WS_MAXIMIZE)) | WS_VISIBLE;
1386 XGetGeometry( event->display, get_whole_window(win), &root, &x, &y, &width, &height,
1388 XTranslateCoordinates( event->display, get_whole_window(win), root, 0, 0, &x, &y, &top );
1389 wine_tsx11_unlock();
1392 rect.right = x + width;
1393 rect.bottom = y + height;
1394 X11DRV_X_to_window_rect( win, &rect );
1396 DCE_InvalidateDCE( hwnd, &win->rectWindow );
1398 if (win->flags & WIN_RESTORE_MAX) style |= WS_MAXIMIZE;
1399 WIN_SetStyle( hwnd, style );
1400 WIN_ReleasePtr( win );
1402 SendMessageA( hwnd, WM_SHOWWINDOW, SW_RESTORE, 0 );
1403 SetWindowPos( hwnd, 0, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
1404 SWP_NOZORDER | SWP_WINE_NOHOSTMOVE );
1406 else WIN_ReleasePtr( win );
1407 if (hwndFocus && IsChild( hwnd, hwndFocus )) X11DRV_SetFocus(hwndFocus); /* FIXME */
1411 /**********************************************************************
1412 * X11DRV_UnmapNotify
1414 void X11DRV_UnmapNotify( HWND hwnd, XUnmapEvent *event )
1418 if (!(win = WIN_GetPtr( hwnd ))) return;
1420 if ((win->dwStyle & WS_VISIBLE) && (win->dwExStyle & WS_EX_MANAGED) &&
1421 X11DRV_is_window_rect_mapped( &win->rectWindow ))
1423 if (win->dwStyle & WS_MAXIMIZE)
1424 win->flags |= WIN_RESTORE_MAX;
1426 win->flags &= ~WIN_RESTORE_MAX;
1428 WIN_SetStyle( hwnd, (win->dwStyle & ~WS_MAXIMIZE) | WS_MINIMIZE );
1429 WIN_ReleasePtr( win );
1432 SendMessageA( hwnd, WM_SHOWWINDOW, SW_MINIMIZE, 0 );
1433 SetWindowPos( hwnd, 0, 0, 0, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON),
1434 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_WINE_NOHOSTMOVE );
1436 else WIN_ReleasePtr( win );
1440 /***********************************************************************
1443 * Synchronize internal z-order with the window manager's.
1445 static Window __get_common_ancestor( Display *display, Window A, Window B,
1446 Window** children, unsigned* total )
1448 /* find the real root window */
1450 Window root, *childrenB;
1454 while( A != B && A && B )
1456 XQueryTree( display, A, &root, &A, children, total );
1457 XQueryTree( display, B, &root, &B, &childrenB, &totalB );
1458 if( childrenB ) XFree( childrenB );
1459 if( *children ) XFree( *children ), *children = NULL;
1464 XQueryTree( display, A, &root, &B, children, total );
1465 wine_tsx11_unlock();
1468 wine_tsx11_unlock();
1472 static Window __get_top_decoration( Display *display, Window w, Window ancestor )
1474 Window* children, root, prev = w, parent = w;
1481 XQueryTree( display, w, &root, &parent, &children, &total );
1482 if( children ) XFree( children );
1483 } while( parent && parent != ancestor );
1484 wine_tsx11_unlock();
1485 TRACE("\t%08x -> %08x\n", (unsigned)prev, (unsigned)w );
1486 return ( parent ) ? w : 0 ;
1489 static unsigned __td_lookup( Window w, Window* list, unsigned max )
1492 for( i = max; i > 0; i-- ) if( list[i - 1] == w ) break;
1496 static HWND query_zorder( Display *display, HWND hWndCheck)
1498 HWND hwndInsertAfter = HWND_TOP;
1499 Window w, parent, *children = NULL;
1500 unsigned total, check, pos, best;
1501 HWND *list = WIN_ListChildren( GetDesktopWindow() );
1502 HWND hwndA = 0, hwndB = 0;
1505 /* find at least two managed windows */
1506 if (!list) return 0;
1507 for (i = 0; list[i]; i++)
1509 if (!(GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_MANAGED)) continue;
1510 if (!(GetWindowLongW( list[i], GWL_STYLE ) & WS_VISIBLE)) continue;
1511 if (!hwndA) hwndA = list[i];
1518 if (!hwndA || !hwndB) goto done;
1520 parent = __get_common_ancestor( display, X11DRV_get_whole_window(hwndA),
1521 X11DRV_get_whole_window(hwndB), &children, &total );
1522 if( parent && children )
1524 /* w is the ancestor if hWndCheck that is a direct descendant of 'parent' */
1526 w = __get_top_decoration( display, X11DRV_get_whole_window(hWndCheck), parent );
1528 if( w != children[total-1] ) /* check if at the top */
1530 /* X child at index 0 is at the bottom, at index total-1 is at the top */
1531 check = __td_lookup( w, children, total );
1534 /* go through all windows in Wine z-order... */
1535 for (i = 0; list[i]; i++)
1537 if (list[i] == hWndCheck) continue;
1538 if (!(GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_MANAGED)) continue;
1539 if (!(w = __get_top_decoration( display, X11DRV_get_whole_window(list[i]),
1540 parent ))) continue;
1541 pos = __td_lookup( w, children, total );
1542 if( pos < best && pos > check )
1544 /* find a nearest Wine window precedes hWndCheck in the real z-order */
1546 hwndInsertAfter = list[i];
1548 if( best - check == 1 ) break;
1553 if( children ) XFree( children );
1554 wine_tsx11_unlock();
1557 HeapFree( GetProcessHeap(), 0, list );
1558 return hwndInsertAfter;
1562 /***********************************************************************
1563 * X11DRV_handle_desktop_resize
1565 void X11DRV_handle_desktop_resize( unsigned int width, unsigned int height )
1568 HWND hwnd = GetDesktopWindow();
1570 screen_width = width;
1571 screen_height = height;
1572 TRACE("desktop %p change to (%dx%d)\n", hwnd, width, height);
1573 SetRect( &rect, 0, 0, width, height );
1574 X11DRV_set_window_rectangles( hwnd, &rect, &rect );
1575 SendMessageTimeoutW( HWND_BROADCAST, WM_DISPLAYCHANGE, screen_depth,
1576 MAKELPARAM( width, height ), SMTO_ABORTIFHUNG, 2000, NULL );
1580 /***********************************************************************
1581 * X11DRV_ConfigureNotify
1583 void X11DRV_ConfigureNotify( HWND hwnd, XConfigureEvent *event )
1585 HWND oldInsertAfter;
1586 struct x11drv_win_data *data;
1590 int x = event->x, y = event->y;
1592 if (!(win = WIN_GetPtr( hwnd ))) return;
1593 data = win->pDriverData;
1597 if (!event->send_event) /* normal event, need to map coordinates to the root */
1601 XTranslateCoordinates( event->display, data->whole_window, root_window,
1602 0, 0, &x, &y, &child );
1603 wine_tsx11_unlock();
1607 rect.right = x + event->width;
1608 rect.bottom = y + event->height;
1609 TRACE( "win %p new X rect %ld,%ld,%ldx%ld (event %d,%d,%dx%d)\n",
1610 hwnd, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
1611 event->x, event->y, event->width, event->height );
1612 X11DRV_X_to_window_rect( win, &rect );
1613 WIN_ReleasePtr( win );
1616 winpos.x = rect.left;
1617 winpos.y = rect.top;
1618 winpos.cx = rect.right - rect.left;
1619 winpos.cy = rect.bottom - rect.top;
1620 winpos.flags = SWP_NOACTIVATE;
1622 /* Get Z-order (FIXME) */
1624 winpos.hwndInsertAfter = query_zorder( event->display, hwnd );
1626 /* needs to find the first Visible Window above the current one */
1627 oldInsertAfter = hwnd;
1630 oldInsertAfter = GetWindow( oldInsertAfter, GW_HWNDPREV );
1631 if (!oldInsertAfter)
1633 oldInsertAfter = HWND_TOP;
1636 if (GetWindowLongA( oldInsertAfter, GWL_STYLE ) & WS_VISIBLE) break;
1639 /* Compare what has changed */
1641 GetWindowRect( hwnd, &rect );
1642 if (rect.left == winpos.x && rect.top == winpos.y) winpos.flags |= SWP_NOMOVE;
1644 TRACE( "%p moving from (%ld,%ld) to (%d,%d)\n",
1645 hwnd, rect.left, rect.top, winpos.x, winpos.y );
1647 if ((rect.right - rect.left == winpos.cx && rect.bottom - rect.top == winpos.cy) ||
1649 (IsRectEmpty( &rect ) && winpos.cx == 1 && winpos.cy == 1))
1650 winpos.flags |= SWP_NOSIZE;
1652 TRACE( "%p resizing from (%ldx%ld) to (%dx%d)\n",
1653 hwnd, rect.right - rect.left, rect.bottom - rect.top,
1654 winpos.cx, winpos.cy );
1656 if (winpos.hwndInsertAfter == oldInsertAfter) winpos.flags |= SWP_NOZORDER;
1658 TRACE( "%p restacking from after %p to after %p\n",
1659 hwnd, oldInsertAfter, winpos.hwndInsertAfter );
1661 /* if nothing changed, don't do anything */
1662 if (winpos.flags == (SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE)) return;
1664 SetWindowPos( hwnd, winpos.hwndInsertAfter, winpos.x, winpos.y,
1665 winpos.cx, winpos.cy, winpos.flags | SWP_WINE_NOHOSTMOVE );
1669 /***********************************************************************
1670 * SetWindowRgn (X11DRV.@)
1672 * Assign specified region to window (for non-rectangular windows)
1674 int X11DRV_SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL redraw )
1678 if ((wndPtr = WIN_GetPtr( hwnd )) == WND_OTHER_PROCESS)
1680 if (IsWindow( hwnd ))
1681 FIXME( "not supported on other process window %p\n", hwnd );
1686 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1690 #ifdef HAVE_LIBXSHAPE
1692 Display *display = thread_display();
1693 X11DRV_WND_DATA *data = wndPtr->pDriverData;
1695 if (data->whole_window)
1700 XShapeCombineMask( display, data->whole_window,
1701 ShapeBounding, 0, 0, None, ShapeSet );
1702 wine_tsx11_unlock();
1706 RGNDATA *pRegionData = X11DRV_GetRegionData( hrgn, 0 );
1710 XShapeCombineRectangles( display, data->whole_window, ShapeBounding,
1711 wndPtr->rectWindow.left - data->whole_rect.left,
1712 wndPtr->rectWindow.top - data->whole_rect.top,
1713 (XRectangle *)pRegionData->Buffer,
1714 pRegionData->rdh.nCount,
1715 ShapeSet, YXBanded );
1716 wine_tsx11_unlock();
1717 HeapFree(GetProcessHeap(), 0, pRegionData);
1722 #endif /* HAVE_LIBXSHAPE */
1724 WIN_ReleasePtr( wndPtr );
1729 /***********************************************************************
1732 * Draw the frame used when moving or resizing window.
1734 * FIXME: This causes problems in Win95 mode. (why?)
1736 static void draw_moving_frame( HDC hdc, RECT *rect, BOOL thickframe )
1740 const int width = GetSystemMetrics(SM_CXFRAME);
1741 const int height = GetSystemMetrics(SM_CYFRAME);
1743 HBRUSH hbrush = SelectObject( hdc, GetStockObject( GRAY_BRUSH ) );
1744 PatBlt( hdc, rect->left, rect->top,
1745 rect->right - rect->left - width, height, PATINVERT );
1746 PatBlt( hdc, rect->left, rect->top + height, width,
1747 rect->bottom - rect->top - height, PATINVERT );
1748 PatBlt( hdc, rect->left + width, rect->bottom - 1,
1749 rect->right - rect->left - width, -height, PATINVERT );
1750 PatBlt( hdc, rect->right - 1, rect->top, -width,
1751 rect->bottom - rect->top - height, PATINVERT );
1752 SelectObject( hdc, hbrush );
1754 else DrawFocusRect( hdc, rect );
1758 /***********************************************************************
1761 * Initialisation of a move or resize, when initiatied from a menu choice.
1762 * Return hit test code for caption or sizing border.
1764 static LONG start_size_move( HWND hwnd, WPARAM wParam, POINT *capturePoint, LONG style )
1771 GetWindowRect( hwnd, &rectWindow );
1773 if ((wParam & 0xfff0) == SC_MOVE)
1775 /* Move pointer at the center of the caption */
1777 NC_GetInsideRect( hwnd, &rect );
1778 if (style & WS_SYSMENU)
1779 rect.left += GetSystemMetrics(SM_CXSIZE) + 1;
1780 if (style & WS_MINIMIZEBOX)
1781 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1782 if (style & WS_MAXIMIZEBOX)
1783 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1784 pt.x = rectWindow.left + (rect.right - rect.left) / 2;
1785 pt.y = rectWindow.top + rect.top + GetSystemMetrics(SM_CYSIZE)/2;
1786 hittest = HTCAPTION;
1793 GetMessageW( &msg, 0, WM_KEYFIRST, WM_MOUSELAST );
1794 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
1799 hittest = NC_HandleNCHitTest( hwnd, msg.pt );
1800 if ((hittest < HTLEFT) || (hittest > HTBOTTOMRIGHT))
1812 pt.x =(rectWindow.left+rectWindow.right)/2;
1813 pt.y = rectWindow.top + GetSystemMetrics(SM_CYFRAME) / 2;
1817 pt.x =(rectWindow.left+rectWindow.right)/2;
1818 pt.y = rectWindow.bottom - GetSystemMetrics(SM_CYFRAME) / 2;
1822 pt.x = rectWindow.left + GetSystemMetrics(SM_CXFRAME) / 2;
1823 pt.y =(rectWindow.top+rectWindow.bottom)/2;
1827 pt.x = rectWindow.right - GetSystemMetrics(SM_CXFRAME) / 2;
1828 pt.y =(rectWindow.top+rectWindow.bottom)/2;
1831 case VK_ESCAPE: return 0;
1837 SetCursorPos( pt.x, pt.y );
1838 NC_HandleSetCursor( hwnd, (WPARAM)hwnd, MAKELONG( hittest, WM_MOUSEMOVE ));
1843 /***********************************************************************
1844 * set_movesize_capture
1846 static void set_movesize_capture( HWND hwnd )
1850 SERVER_START_REQ( set_capture_window )
1853 req->flags = CAPTURE_MOVESIZE;
1854 if (!wine_server_call_err( req ))
1856 previous = reply->previous;
1857 hwnd = reply->full_handle;
1861 if (previous && previous != hwnd)
1862 SendMessageW( previous, WM_CAPTURECHANGED, 0, (LPARAM)hwnd );
1865 /***********************************************************************
1866 * X11DRV_WMMoveResizeWindow
1868 * Tells the window manager to initiate a move or resize operation.
1871 * http://freedesktop.org/Standards/wm-spec/1.3/ar01s04.html
1872 * or search for "_NET_WM_MOVERESIZE"
1874 static void X11DRV_WMMoveResizeWindow( HWND hwnd, int x, int y, int dir )
1877 Display *display = thread_display();
1881 /* need to ungrab the pointer that may have been automatically grabbed
1882 * with a ButtonPress event */
1883 XUngrabPointer( display, CurrentTime );
1885 xev.xclient.type = ClientMessage;
1886 xev.xclient.window = X11DRV_get_whole_window(hwnd);
1887 xev.xclient.message_type = x11drv_atom(_NET_WM_MOVERESIZE);
1888 xev.xclient.serial = 0;
1889 xev.xclient.display = display;
1890 xev.xclient.send_event = True;
1891 xev.xclient.format = 32;
1892 xev.xclient.data.l[0] = x; /* x coord */
1893 xev.xclient.data.l[1] = y; /* y coord */
1894 xev.xclient.data.l[2] = dir; /* direction */
1895 xev.xclient.data.l[3] = 1; /* button */
1896 xev.xclient.data.l[4] = 0; /* unused */
1897 XSendEvent(display, root_window, False, SubstructureNotifyMask, &xev);
1899 wine_tsx11_unlock();
1902 /***********************************************************************
1903 * SysCommandSizeMove (X11DRV.@)
1905 * Perform SC_MOVE and SC_SIZE commands.
1907 void X11DRV_SysCommandSizeMove( HWND hwnd, WPARAM wParam )
1910 RECT sizingRect, mouseRect, origRect;
1913 LONG hittest = (LONG)(wParam & 0x0f);
1914 WPARAM syscommand = wParam & 0xfff0;
1915 HCURSOR hDragCursor = 0, hOldCursor = 0;
1916 POINT minTrack, maxTrack;
1917 POINT capturePoint, pt;
1918 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
1919 LONG exstyle = GetWindowLongA( hwnd, GWL_EXSTYLE );
1920 BOOL thickframe = HAS_THICKFRAME( style, exstyle );
1921 BOOL iconic = style & WS_MINIMIZE;
1923 DWORD dwPoint = GetMessagePos ();
1924 BOOL DragFullWindows = FALSE;
1927 Display *old_gdi_display = NULL;
1928 Display *display = thread_display();
1930 pt.x = (short)LOWORD(dwPoint);
1931 pt.y = (short)HIWORD(dwPoint);
1934 if (IsZoomed(hwnd) || !IsWindowVisible(hwnd)) return;
1936 /* if we are managed then we let the WM do all the work */
1937 if (exstyle & WS_EX_MANAGED)
1940 if (syscommand == SC_MOVE)
1942 if (!hittest) dir = _NET_WM_MOVERESIZE_MOVE_KEYBOARD;
1943 else dir = _NET_WM_MOVERESIZE_MOVE;
1945 else if (!hittest) dir = _NET_WM_MOVERESIZE_SIZE_KEYBOARD;
1949 case WMSZ_LEFT: dir = _NET_WM_MOVERESIZE_SIZE_LEFT; break;
1950 case WMSZ_RIGHT: dir = _NET_WM_MOVERESIZE_SIZE_RIGHT; break;
1951 case WMSZ_TOP: dir = _NET_WM_MOVERESIZE_SIZE_TOP; break;
1952 case WMSZ_TOPLEFT: dir = _NET_WM_MOVERESIZE_SIZE_TOPLEFT; break;
1953 case WMSZ_TOPRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT; break;
1954 case WMSZ_BOTTOM: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOM; break;
1955 case WMSZ_BOTTOMLEFT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT; break;
1956 case WMSZ_BOTTOMRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT; break;
1958 ERR("Invalid hittest value: %ld\n", hittest);
1959 dir = _NET_WM_MOVERESIZE_SIZE_KEYBOARD;
1961 X11DRV_WMMoveResizeWindow( hwnd, pt.x, pt.y, dir );
1965 SystemParametersInfoA(SPI_GETDRAGFULLWINDOWS, 0, &DragFullWindows, 0);
1967 if (syscommand == SC_MOVE)
1969 if (!hittest) hittest = start_size_move( hwnd, wParam, &capturePoint, style );
1970 if (!hittest) return;
1974 if ( hittest && (syscommand != SC_MOUSEMENU) )
1975 hittest += (HTLEFT - WMSZ_LEFT);
1978 set_movesize_capture( hwnd );
1979 hittest = start_size_move( hwnd, wParam, &capturePoint, style );
1982 set_movesize_capture(0);
1988 /* Get min/max info */
1990 WINPOS_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack );
1991 GetWindowRect( hwnd, &sizingRect );
1992 if (style & WS_CHILD)
1994 parent = GetParent(hwnd);
1995 /* make sizing rect relative to parent */
1996 MapWindowPoints( 0, parent, (POINT*)&sizingRect, 2 );
1997 GetClientRect( parent, &mouseRect );
2002 SetRect(&mouseRect, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
2004 origRect = sizingRect;
2006 if (ON_LEFT_BORDER(hittest))
2008 mouseRect.left = max( mouseRect.left, sizingRect.right-maxTrack.x );
2009 mouseRect.right = min( mouseRect.right, sizingRect.right-minTrack.x );
2011 else if (ON_RIGHT_BORDER(hittest))
2013 mouseRect.left = max( mouseRect.left, sizingRect.left+minTrack.x );
2014 mouseRect.right = min( mouseRect.right, sizingRect.left+maxTrack.x );
2016 if (ON_TOP_BORDER(hittest))
2018 mouseRect.top = max( mouseRect.top, sizingRect.bottom-maxTrack.y );
2019 mouseRect.bottom = min( mouseRect.bottom,sizingRect.bottom-minTrack.y);
2021 else if (ON_BOTTOM_BORDER(hittest))
2023 mouseRect.top = max( mouseRect.top, sizingRect.top+minTrack.y );
2024 mouseRect.bottom = min( mouseRect.bottom, sizingRect.top+maxTrack.y );
2026 if (parent) MapWindowPoints( parent, 0, (LPPOINT)&mouseRect, 2 );
2028 /* Retrieve a default cache DC (without using the window style) */
2029 hdc = GetDCEx( parent, 0, DCX_CACHE );
2031 if( iconic ) /* create a cursor for dragging */
2033 hDragCursor = (HCURSOR)GetClassLongA( hwnd, GCL_HICON);
2034 if( !hDragCursor ) hDragCursor = (HCURSOR)SendMessageA( hwnd, WM_QUERYDRAGICON, 0, 0L);
2035 if( !hDragCursor ) iconic = FALSE;
2038 /* repaint the window before moving it around */
2039 RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN );
2041 SendMessageA( hwnd, WM_ENTERSIZEMOVE, 0, 0 );
2042 set_movesize_capture( hwnd );
2044 /* grab the server only when moving top-level windows without desktop */
2045 grab = (!DragFullWindows && !parent && (root_window == DefaultRootWindow(gdi_display)));
2050 XSync( gdi_display, False );
2051 XGrabServer( display );
2052 XSync( display, False );
2053 /* switch gdi display to the thread display, since the server is grabbed */
2054 old_gdi_display = gdi_display;
2055 gdi_display = display;
2057 XGrabPointer( display, X11DRV_get_whole_window(hwnd), False,
2058 PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
2059 GrabModeAsync, GrabModeAsync,
2060 parent ? X11DRV_get_client_window(parent) : root_window,
2061 None, CurrentTime );
2062 wine_tsx11_unlock();
2068 if (!GetMessageW( &msg, 0, WM_KEYFIRST, WM_MOUSELAST )) break;
2069 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
2071 /* Exit on button-up, Return, or Esc */
2072 if ((msg.message == WM_LBUTTONUP) ||
2073 ((msg.message == WM_KEYDOWN) &&
2074 ((msg.wParam == VK_RETURN) || (msg.wParam == VK_ESCAPE)))) break;
2076 if ((msg.message != WM_KEYDOWN) && (msg.message != WM_MOUSEMOVE))
2077 continue; /* We are not interested in other messages */
2081 if (msg.message == WM_KEYDOWN) switch(msg.wParam)
2083 case VK_UP: pt.y -= 8; break;
2084 case VK_DOWN: pt.y += 8; break;
2085 case VK_LEFT: pt.x -= 8; break;
2086 case VK_RIGHT: pt.x += 8; break;
2089 pt.x = max( pt.x, mouseRect.left );
2090 pt.x = min( pt.x, mouseRect.right );
2091 pt.y = max( pt.y, mouseRect.top );
2092 pt.y = min( pt.y, mouseRect.bottom );
2094 dx = pt.x - capturePoint.x;
2095 dy = pt.y - capturePoint.y;
2103 if( iconic ) /* ok, no system popup tracking */
2105 hOldCursor = SetCursor(hDragCursor);
2107 WINPOS_ShowIconTitle( hwnd, FALSE );
2109 else if(!DragFullWindows)
2110 draw_moving_frame( hdc, &sizingRect, thickframe );
2113 if (msg.message == WM_KEYDOWN) SetCursorPos( pt.x, pt.y );
2116 RECT newRect = sizingRect;
2117 WPARAM wpSizingHit = 0;
2119 if (hittest == HTCAPTION) OffsetRect( &newRect, dx, dy );
2120 if (ON_LEFT_BORDER(hittest)) newRect.left += dx;
2121 else if (ON_RIGHT_BORDER(hittest)) newRect.right += dx;
2122 if (ON_TOP_BORDER(hittest)) newRect.top += dy;
2123 else if (ON_BOTTOM_BORDER(hittest)) newRect.bottom += dy;
2124 if(!iconic && !DragFullWindows) draw_moving_frame( hdc, &sizingRect, thickframe );
2127 /* determine the hit location */
2128 if (hittest >= HTLEFT && hittest <= HTBOTTOMRIGHT)
2129 wpSizingHit = WMSZ_LEFT + (hittest - HTLEFT);
2130 SendMessageA( hwnd, WM_SIZING, wpSizingHit, (LPARAM)&newRect );
2134 if(!DragFullWindows)
2135 draw_moving_frame( hdc, &newRect, thickframe );
2137 /* To avoid any deadlocks, all the locks on the windows
2138 structures must be suspended before the SetWindowPos */
2139 iWndsLocks = WIN_SuspendWndsLock();
2140 SetWindowPos( hwnd, 0, newRect.left, newRect.top,
2141 newRect.right - newRect.left,
2142 newRect.bottom - newRect.top,
2143 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
2144 WIN_RestoreWndsLock(iWndsLocks);
2147 sizingRect = newRect;
2152 set_movesize_capture(0);
2155 if( moved ) /* restore cursors, show icon title later on */
2157 ShowCursor( FALSE );
2158 SetCursor( hOldCursor );
2161 else if (moved && !DragFullWindows)
2162 draw_moving_frame( hdc, &sizingRect, thickframe );
2164 ReleaseDC( parent, hdc );
2167 XUngrabPointer( display, CurrentTime );
2170 XSync( display, False );
2171 XUngrabServer( display );
2172 XSync( display, False );
2173 gdi_display = old_gdi_display;
2175 wine_tsx11_unlock();
2177 if (HOOK_CallHooks( WH_CBT, HCBT_MOVESIZE, (WPARAM)hwnd, (LPARAM)&sizingRect, TRUE ))
2180 SendMessageA( hwnd, WM_EXITSIZEMOVE, 0, 0 );
2181 SendMessageA( hwnd, WM_SETVISIBLE, !IsIconic(hwnd), 0L);
2183 /* window moved or resized */
2186 /* To avoid any deadlocks, all the locks on the windows
2187 structures must be suspended before the SetWindowPos */
2188 iWndsLocks = WIN_SuspendWndsLock();
2190 /* if the moving/resizing isn't canceled call SetWindowPos
2191 * with the new position or the new size of the window
2193 if (!((msg.message == WM_KEYDOWN) && (msg.wParam == VK_ESCAPE)) )
2195 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
2196 if(!DragFullWindows)
2197 SetWindowPos( hwnd, 0, sizingRect.left, sizingRect.top,
2198 sizingRect.right - sizingRect.left,
2199 sizingRect.bottom - sizingRect.top,
2200 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
2203 { /* restore previous size/position */
2205 SetWindowPos( hwnd, 0, origRect.left, origRect.top,
2206 origRect.right - origRect.left,
2207 origRect.bottom - origRect.top,
2208 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
2211 WIN_RestoreWndsLock(iWndsLocks);
2216 /* Single click brings up the system menu when iconized */
2220 if(style & WS_SYSMENU )
2221 SendMessageA( hwnd, WM_SYSCOMMAND,
2222 SC_MOUSEMENU + HTSYSMENU, MAKELONG(pt.x,pt.y));
2224 else WINPOS_ShowIconTitle( hwnd, TRUE );
2229 /***********************************************************************
2230 * ForceWindowRaise (X11DRV.@)
2232 * Raise a window on top of the X stacking order, while preserving
2233 * the correct Windows Z order.
2235 * FIXME: this should go away.
2237 void X11DRV_ForceWindowRaise( HWND hwnd )
2241 XWindowChanges winChanges;
2242 Display *display = thread_display();
2243 WND *wndPtr = WIN_FindWndPtr( hwnd );
2245 if (!wndPtr) return;
2247 if ((wndPtr->dwExStyle & WS_EX_MANAGED) ||
2248 wndPtr->parent != GetDesktopWindow() ||
2249 IsRectEmpty( &wndPtr->rectWindow ) ||
2250 !get_whole_window(wndPtr))
2252 WIN_ReleaseWndPtr( wndPtr );
2255 WIN_ReleaseWndPtr( wndPtr );
2257 /* Raise all windows up to wndPtr according to their Z order.
2258 * (it would be easier with sibling-related Below but it doesn't
2259 * work very well with SGI mwm for instance)
2261 winChanges.stack_mode = Above;
2262 if (!(list = WIN_ListChildren( GetDesktopWindow() ))) return;
2263 while (list[i] && list[i] != hwnd) i++;
2266 for ( ; i >= 0; i--)
2268 WND *ptr = WIN_FindWndPtr( list[i] );
2270 if (!IsRectEmpty( &ptr->rectWindow ) && get_whole_window(ptr))
2273 XReconfigureWMWindow( display, get_whole_window(ptr), 0, CWStackMode, &winChanges );
2274 wine_tsx11_unlock();
2276 WIN_ReleaseWndPtr( ptr );
2279 HeapFree( GetProcessHeap(), 0, list );