Authors: David Hammerton <david@transgaming.com>, Peter Hunnisett <peter@transgaming...
[wine.git] / dlls / x11drv / winpos.c
blobc4be59f694cf3b336e1686c1be218d532ab42109
1 /*
2 * Window position related functions.
4 * Copyright 1993, 1994, 1995, 2001 Alexandre Julliard
5 * Copyright 1995, 1996, 1999 Alex Korobka
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "config.h"
24 #include "ts_xlib.h"
25 #include "ts_xutil.h"
26 #include "ts_shape.h"
28 #include "winbase.h"
29 #include "wingdi.h"
30 #include "winuser.h"
31 #include "winerror.h"
33 #include "x11drv.h"
34 #include "hook.h"
35 #include "win.h"
36 #include "winpos.h"
37 #include "dce.h"
38 #include "cursoricon.h"
39 #include "nonclient.h"
40 #include "message.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
46 #define SWP_AGG_NOGEOMETRYCHANGE \
47 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE)
48 #define SWP_AGG_NOPOSCHANGE \
49 (SWP_AGG_NOGEOMETRYCHANGE | SWP_NOZORDER)
50 #define SWP_AGG_STATUSFLAGS \
51 (SWP_AGG_NOPOSCHANGE | SWP_FRAMECHANGED | SWP_HIDEWINDOW | SWP_SHOWWINDOW)
53 #define SWP_EX_NOCOPY 0x0001
54 #define SWP_EX_PAINTSELF 0x0002
55 #define SWP_EX_NONCLIENT 0x0004
57 #define HAS_THICKFRAME(style,exStyle) \
58 (((style) & WS_THICKFRAME) && \
59 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
61 #define ON_LEFT_BORDER(hit) \
62 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
63 #define ON_RIGHT_BORDER(hit) \
64 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
65 #define ON_TOP_BORDER(hit) \
66 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
67 #define ON_BOTTOM_BORDER(hit) \
68 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
71 /***********************************************************************
72 * clip_children
74 * Clip all children of a given window out of the visible region
76 static int clip_children( HWND parent, HWND last, HRGN hrgn, int whole_window )
78 HWND *list;
79 WND *ptr;
80 HRGN rectRgn;
81 int i, x, y, ret = SIMPLEREGION;
83 /* first check if we have anything to do */
84 if (!(list = WIN_ListChildren( parent ))) return ret;
85 for (i = 0; list[i] && list[i] != last; i++)
86 if (GetWindowLongW( list[i], GWL_STYLE ) & WS_VISIBLE) break;
87 if (!list[i] || list[i] == last) goto done; /* no children to clip */
89 if (whole_window)
91 WND *win = WIN_FindWndPtr( parent );
92 x = win->rectWindow.left - win->rectClient.left;
93 y = win->rectWindow.top - win->rectClient.top;
94 WIN_ReleaseWndPtr( win );
96 else x = y = 0;
98 rectRgn = CreateRectRgn( 0, 0, 0, 0 );
100 for ( ; list[i] && list[i] != last; i++)
102 if (!(ptr = WIN_FindWndPtr( list[i] ))) continue;
103 if (ptr->dwStyle & WS_VISIBLE)
105 SetRectRgn( rectRgn, ptr->rectWindow.left + x, ptr->rectWindow.top + y,
106 ptr->rectWindow.right + x, ptr->rectWindow.bottom + y );
107 if ((ret = CombineRgn( hrgn, hrgn, rectRgn, RGN_DIFF )) == NULLREGION)
109 WIN_ReleaseWndPtr( ptr );
110 break; /* no need to go on, region is empty */
113 WIN_ReleaseWndPtr( ptr );
115 DeleteObject( rectRgn );
116 done:
117 HeapFree( GetProcessHeap(), 0, list );
118 return ret;
122 /***********************************************************************
123 * get_visible_region
125 * Compute the visible region of a window
127 static HRGN get_visible_region( WND *win, HWND top, UINT flags, int mode )
129 HRGN rgn;
130 RECT rect;
131 int xoffset, yoffset;
132 X11DRV_WND_DATA *data = win->pDriverData;
134 if (flags & DCX_WINDOW)
136 xoffset = win->rectWindow.left;
137 yoffset = win->rectWindow.top;
139 else
141 xoffset = win->rectClient.left;
142 yoffset = win->rectClient.top;
145 if (flags & DCX_PARENTCLIP)
146 GetClientRect( win->parent, &rect );
147 else if (flags & DCX_WINDOW)
148 rect = data->whole_rect;
149 else
150 rect = win->rectClient;
152 /* vis region is relative to the start of the client/window area */
153 OffsetRect( &rect, -xoffset, -yoffset );
155 if (!(rgn = CreateRectRgn( rect.left, rect.top, rect.right, rect.bottom ))) return 0;
157 if ((flags & DCX_CLIPCHILDREN) && (mode != ClipByChildren))
159 /* we need to clip children by hand */
160 if (clip_children( win->hwndSelf, 0, rgn, (flags & DCX_WINDOW) ) == NULLREGION) return rgn;
163 if (top && top != win->hwndSelf) /* need to clip siblings of ancestors */
165 WND *parent, *ptr = WIN_FindWndPtr( win->hwndSelf );
166 HRGN tmp = 0;
168 OffsetRgn( rgn, xoffset, yoffset );
169 for (;;)
171 if (ptr->dwStyle & WS_CLIPSIBLINGS)
173 if (clip_children( ptr->parent, ptr->hwndSelf, rgn, FALSE ) == NULLREGION) break;
175 if (ptr->hwndSelf == top) break;
176 if (!(parent = WIN_FindWndPtr( ptr->parent ))) break;
177 WIN_ReleaseWndPtr( ptr );
178 ptr = parent;
179 /* clip to parent client area */
180 if (tmp) SetRectRgn( tmp, 0, 0, ptr->rectClient.right - ptr->rectClient.left,
181 ptr->rectClient.bottom - ptr->rectClient.top );
182 else tmp = CreateRectRgn( 0, 0, ptr->rectClient.right - ptr->rectClient.left,
183 ptr->rectClient.bottom - ptr->rectClient.top );
184 CombineRgn( rgn, rgn, tmp, RGN_AND );
185 OffsetRgn( rgn, ptr->rectClient.left, ptr->rectClient.top );
186 xoffset += ptr->rectClient.left;
187 yoffset += ptr->rectClient.top;
189 WIN_ReleaseWndPtr( ptr );
190 /* make it relative to the target window again */
191 OffsetRgn( rgn, -xoffset, -yoffset );
192 if (tmp) DeleteObject( tmp );
195 return rgn;
199 /***********************************************************************
200 * get_covered_region
202 * Compute the portion of 'rgn' that is covered by non-clipped siblings.
203 * This is the area that is covered from X point of view, but may still need
204 * to be exposed.
205 * 'rgn' must be relative to the client area of the parent of 'win'.
207 static int get_covered_region( WND *win, HRGN rgn )
209 HRGN tmp;
210 int ret;
211 WND *parent, *ptr = WIN_FindWndPtr( win->hwndSelf );
212 int xoffset = 0, yoffset = 0;
214 tmp = CreateRectRgn( 0, 0, 0, 0 );
215 CombineRgn( tmp, rgn, 0, RGN_COPY );
217 /* to make things easier we actually build the uncovered
218 * area by removing all siblings and then we subtract that
219 * from the total region to get the covered area */
220 for (;;)
222 if (!(ptr->dwStyle & WS_CLIPSIBLINGS))
224 if (clip_children( ptr->parent, ptr->hwndSelf, tmp, FALSE ) == NULLREGION) break;
226 if (!(parent = WIN_FindWndPtr( ptr->parent ))) break;
227 WIN_ReleaseWndPtr( ptr );
228 ptr = parent;
229 OffsetRgn( tmp, ptr->rectClient.left, ptr->rectClient.top );
230 xoffset += ptr->rectClient.left;
231 yoffset += ptr->rectClient.top;
233 WIN_ReleaseWndPtr( ptr );
234 /* make it relative to the target window again */
235 OffsetRgn( tmp, -xoffset, -yoffset );
237 /* now subtract the computed region from the original one */
238 ret = CombineRgn( rgn, rgn, tmp, RGN_DIFF );
239 DeleteObject( tmp );
240 return ret;
244 /***********************************************************************
245 * expose_window
247 * Expose a region of a given window.
249 static void expose_window( HWND hwnd, RECT *rect, HRGN rgn, int flags )
251 POINT offset;
252 HWND top = 0;
253 HWND *list;
254 int i;
256 /* find the top most parent that doesn't clip children or siblings and
257 * invalidate the area on its parent, including all children */
258 if ((list = WIN_ListParents( hwnd )))
260 HWND current = hwnd;
261 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
262 for (i = 0; list[i] && list[i] != GetDesktopWindow(); i++)
264 if (!(style & WS_CLIPSIBLINGS)) top = current;
265 style = GetWindowLongW( list[i], GWL_STYLE );
266 if (!(style & WS_CLIPCHILDREN)) top = current;
267 current = list[i];
270 if (top)
272 /* find the parent of the top window, reusing the parent list */
273 if (top == hwnd) i = 0;
274 else
276 for (i = 0; list[i]; i++) if (list[i] == top) break;
277 if (list[i] && list[i+1]) i++;
279 if (list[i] != GetDesktopWindow()) top = list[i];
280 flags &= ~RDW_FRAME; /* parent will invalidate children frame anyway */
281 flags |= RDW_ALLCHILDREN;
283 HeapFree( GetProcessHeap(), 0, list );
286 if (!top) top = hwnd;
288 /* make coords relative to top */
289 offset.x = offset.y = 0;
290 MapWindowPoints( hwnd, top, &offset, 1 );
292 if (rect)
294 OffsetRect( rect, offset.x, offset.y );
295 RedrawWindow( top, rect, 0, flags );
297 else
299 OffsetRgn( rgn, offset.x, offset.y );
300 RedrawWindow( top, NULL, rgn, flags );
305 /***********************************************************************
306 * expose_covered_parent_area
308 * Expose the parent area that has been uncovered by moving/hiding a
309 * given window, but that is still covered by other siblings (the area
310 * not covered by siblings will be exposed automatically by X).
312 static void expose_covered_parent_area( WND *win, const RECT *old_rect )
314 int ret = SIMPLEREGION;
315 HRGN hrgn = CreateRectRgnIndirect( old_rect );
317 if (win->dwStyle & WS_VISIBLE)
319 HRGN tmp = CreateRectRgnIndirect( &win->rectWindow );
320 ret = CombineRgn( hrgn, hrgn, tmp, RGN_DIFF );
321 DeleteObject( tmp );
324 if (ret != NULLREGION)
326 if (get_covered_region( win, hrgn ) != NULLREGION)
327 expose_window( win->parent, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
329 DeleteObject( hrgn );
333 /***********************************************************************
334 * expose_covered_window_area
336 * Expose the area of a window that is covered by other siblings.
338 static void expose_covered_window_area( WND *win, const RECT *old_client_rect, BOOL frame )
340 HRGN hrgn;
341 int ret = SIMPLEREGION;
343 if (frame)
344 hrgn = CreateRectRgn( win->rectWindow.left - win->rectClient.left,
345 win->rectWindow.top - win->rectClient.top,
346 win->rectWindow.right - win->rectWindow.left,
347 win->rectWindow.bottom - win->rectWindow.top );
348 else
349 hrgn = CreateRectRgn( 0, 0,
350 win->rectClient.right - win->rectClient.left,
351 win->rectClient.bottom - win->rectClient.top );
353 /* if the client rect didn't move we don't need to repaint it all */
354 if (old_client_rect->left == win->rectClient.left &&
355 old_client_rect->top == win->rectClient.top)
357 RECT rc;
359 if (IntersectRect( &rc, old_client_rect, &win->rectClient ))
361 HRGN tmp;
362 /* subtract the unchanged client area from the region to expose */
363 OffsetRect( &rc, -win->rectClient.left, -win->rectClient.top );
364 if ((tmp = CreateRectRgnIndirect( &rc )))
366 ret = CombineRgn( hrgn, hrgn, tmp, RGN_DIFF );
367 DeleteObject( tmp );
372 if (ret != NULLREGION)
374 if (get_covered_region( win, hrgn ) != NULLREGION)
375 expose_window( win->hwndSelf, NULL, hrgn,
376 RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
379 DeleteObject( hrgn );
383 /***********************************************************************
384 * X11DRV_Expose
386 void X11DRV_Expose( HWND hwnd, XExposeEvent *event )
388 RECT rect;
389 struct x11drv_win_data *data;
390 int flags = RDW_INVALIDATE | RDW_ERASE;
391 WND *win;
393 TRACE( "win %x (%lx) %d,%d %dx%d\n",
394 hwnd, event->window, event->x, event->y, event->width, event->height );
396 rect.left = event->x;
397 rect.top = event->y;
398 rect.right = rect.left + event->width;
399 rect.bottom = rect.top + event->height;
401 if (!(win = WIN_GetPtr( hwnd ))) return;
402 data = win->pDriverData;
404 if (event->window != data->client_window) /* whole window or icon window */
406 flags |= RDW_FRAME;
407 /* make position relative to client area instead of window */
408 OffsetRect( &rect, -data->client_rect.left, -data->client_rect.top );
410 WIN_ReleasePtr( win );
412 expose_window( hwnd, &rect, 0, flags );
416 /***********************************************************************
417 * GetDC (X11DRV.@)
419 * Set the drawable, origin and dimensions for the DC associated to
420 * a given window.
422 BOOL X11DRV_GetDC( HWND hwnd, HDC hdc, HRGN hrgn, DWORD flags )
424 WND *win = WIN_GetPtr( hwnd );
425 HWND top = 0;
426 X11DRV_WND_DATA *data = win->pDriverData;
427 Drawable drawable;
428 BOOL visible;
429 POINT org, drawable_org;
430 int mode = IncludeInferiors;
432 /* don't clip siblings if using parent clip region */
433 if (flags & DCX_PARENTCLIP) flags &= ~DCX_CLIPSIBLINGS;
435 /* find the top parent in the hierarchy that isn't clipping siblings */
436 visible = (win->dwStyle & WS_VISIBLE) != 0;
438 if (visible)
440 HWND *list = WIN_ListParents( hwnd );
441 if (list)
443 int i;
444 for (i = 0; list[i] != GetDesktopWindow(); i++)
446 LONG style = GetWindowLongW( list[i], GWL_STYLE );
447 if (!(style & WS_VISIBLE))
449 visible = FALSE;
450 top = 0;
451 break;
453 if (!(style & WS_CLIPSIBLINGS)) top = list[i];
455 HeapFree( GetProcessHeap(), 0, list );
457 if (!top && visible && !(flags & DCX_CLIPSIBLINGS)) top = hwnd;
460 if (top)
462 HWND parent = GetAncestor( top, GA_PARENT );
463 org.x = org.y = 0;
464 if (flags & DCX_WINDOW)
466 org.x = win->rectWindow.left - win->rectClient.left;
467 org.y = win->rectWindow.top - win->rectClient.top;
469 drawable_org = org;
470 MapWindowPoints( hwnd, parent, &org, 1 );
471 MapWindowPoints( hwnd, 0, &drawable_org, 1 );
472 /* have to use the parent so that we include siblings */
473 if (parent) drawable = X11DRV_get_client_window( parent );
474 else drawable = root_window;
476 else
478 if (IsIconic( hwnd ))
480 drawable = data->icon_window ? data->icon_window : data->whole_window;
481 org.x = 0;
482 org.y = 0;
483 drawable_org = org;
485 else if (flags & DCX_WINDOW)
487 drawable = data->whole_window;
488 org.x = win->rectWindow.left - data->whole_rect.left;
489 org.y = win->rectWindow.top - data->whole_rect.top;
490 drawable_org.x = data->whole_rect.left - win->rectClient.left;
491 drawable_org.y = data->whole_rect.top - win->rectClient.top;
493 else
495 drawable = data->client_window;
496 org.x = 0;
497 org.y = 0;
498 drawable_org = org;
499 if (flags & DCX_CLIPCHILDREN) mode = ClipByChildren; /* can use X11 clipping */
501 MapWindowPoints( hwnd, 0, &drawable_org, 1 );
504 X11DRV_SetDrawable( hdc, drawable, mode, &org, &drawable_org );
506 if (flags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN) ||
507 SetHookFlags16( hdc, DCHF_VALIDATEVISRGN )) /* DC was dirty */
509 /* need to recompute the visible region */
510 HRGN visRgn;
512 if (visible)
514 visRgn = get_visible_region( win, top, flags, mode );
516 if (flags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN))
517 CombineRgn( visRgn, visRgn, hrgn,
518 (flags & DCX_INTERSECTRGN) ? RGN_AND : RGN_DIFF );
520 else visRgn = CreateRectRgn( 0, 0, 0, 0 );
522 SelectVisRgn16( hdc, visRgn );
523 DeleteObject( visRgn );
526 WIN_ReleasePtr( win );
527 return TRUE;
532 /***********************************************************************
533 * SWP_DoWinPosChanging
535 static BOOL SWP_DoWinPosChanging( WINDOWPOS* pWinpos, RECT* pNewWindowRect, RECT* pNewClientRect )
537 WND *wndPtr;
539 /* Send WM_WINDOWPOSCHANGING message */
541 if (!(pWinpos->flags & SWP_NOSENDCHANGING))
542 SendMessageA( pWinpos->hwnd, WM_WINDOWPOSCHANGING, 0, (LPARAM)pWinpos );
544 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return FALSE;
546 /* Calculate new position and size */
548 *pNewWindowRect = wndPtr->rectWindow;
549 *pNewClientRect = (wndPtr->dwStyle & WS_MINIMIZE) ? wndPtr->rectWindow
550 : wndPtr->rectClient;
552 if (!(pWinpos->flags & SWP_NOSIZE))
554 pNewWindowRect->right = pNewWindowRect->left + pWinpos->cx;
555 pNewWindowRect->bottom = pNewWindowRect->top + pWinpos->cy;
557 if (!(pWinpos->flags & SWP_NOMOVE))
559 pNewWindowRect->left = pWinpos->x;
560 pNewWindowRect->top = pWinpos->y;
561 pNewWindowRect->right += pWinpos->x - wndPtr->rectWindow.left;
562 pNewWindowRect->bottom += pWinpos->y - wndPtr->rectWindow.top;
564 OffsetRect( pNewClientRect, pWinpos->x - wndPtr->rectWindow.left,
565 pWinpos->y - wndPtr->rectWindow.top );
567 pWinpos->flags |= SWP_NOCLIENTMOVE | SWP_NOCLIENTSIZE;
568 WIN_ReleasePtr( wndPtr );
569 return TRUE;
572 /***********************************************************************
573 * SWP_DoNCCalcSize
575 static UINT SWP_DoNCCalcSize( WINDOWPOS* pWinpos, RECT* pNewWindowRect, RECT* pNewClientRect )
577 UINT wvrFlags = 0;
578 WND *wndPtr;
580 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
582 /* Send WM_NCCALCSIZE message to get new client area */
583 if( (pWinpos->flags & (SWP_FRAMECHANGED | SWP_NOSIZE)) != SWP_NOSIZE )
585 NCCALCSIZE_PARAMS params;
586 WINDOWPOS winposCopy;
588 params.rgrc[0] = *pNewWindowRect;
589 params.rgrc[1] = wndPtr->rectWindow;
590 params.rgrc[2] = wndPtr->rectClient;
591 params.lppos = &winposCopy;
592 winposCopy = *pWinpos;
593 WIN_ReleasePtr( wndPtr );
595 wvrFlags = SendMessageW( pWinpos->hwnd, WM_NCCALCSIZE, TRUE, (LPARAM)&params );
597 TRACE( "%d,%d-%d,%d\n", params.rgrc[0].left, params.rgrc[0].top,
598 params.rgrc[0].right, params.rgrc[0].bottom );
600 /* If the application send back garbage, ignore it */
601 if (params.rgrc[0].left <= params.rgrc[0].right &&
602 params.rgrc[0].top <= params.rgrc[0].bottom)
603 *pNewClientRect = params.rgrc[0];
605 /* FIXME: WVR_ALIGNxxx */
607 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
609 if( pNewClientRect->left != wndPtr->rectClient.left ||
610 pNewClientRect->top != wndPtr->rectClient.top )
611 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
613 if( (pNewClientRect->right - pNewClientRect->left !=
614 wndPtr->rectClient.right - wndPtr->rectClient.left) ||
615 (pNewClientRect->bottom - pNewClientRect->top !=
616 wndPtr->rectClient.bottom - wndPtr->rectClient.top) )
617 pWinpos->flags &= ~SWP_NOCLIENTSIZE;
619 else
621 if (!(pWinpos->flags & SWP_NOMOVE) &&
622 (pNewClientRect->left != wndPtr->rectClient.left ||
623 pNewClientRect->top != wndPtr->rectClient.top))
624 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
626 WIN_ReleasePtr( wndPtr );
627 return wvrFlags;
631 /***********************************************************************
632 * SWP_DoOwnedPopups
634 * fix Z order taking into account owned popups -
635 * basically we need to maintain them above the window that owns them
637 * FIXME: hide/show owned popups when owner visibility changes.
639 static HWND SWP_DoOwnedPopups(HWND hwnd, HWND hwndInsertAfter)
641 HWND *list = NULL;
642 HWND owner = GetWindow( hwnd, GW_OWNER );
643 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
645 WARN("(%04x) hInsertAfter = %04x\n", hwnd, hwndInsertAfter );
647 if ((style & WS_POPUP) && owner)
649 /* make sure this popup stays above the owner */
651 HWND hwndLocalPrev = HWND_TOP;
653 if( hwndInsertAfter != HWND_TOP )
655 if ((list = WIN_ListChildren( GetDesktopWindow() )))
657 int i;
658 for (i = 0; list[i]; i++)
660 if (list[i] == owner) break;
661 if (list[i] != hwnd) hwndLocalPrev = list[i];
662 if (hwndLocalPrev == hwndInsertAfter) break;
664 hwndInsertAfter = hwndLocalPrev;
668 else if (style & WS_CHILD) return hwndInsertAfter;
670 if (!list) list = WIN_ListChildren( GetDesktopWindow() );
671 if (list)
673 int i;
674 for (i = 0; list[i]; i++)
676 if (list[i] == hwnd) break;
677 if ((GetWindowLongW( list[i], GWL_STYLE ) & WS_POPUP) &&
678 GetWindow( list[i], GW_OWNER ) == hwnd)
680 SetWindowPos( list[i], hwndInsertAfter, 0, 0, 0, 0,
681 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE |
682 SWP_NOSENDCHANGING | SWP_DEFERERASE );
683 hwndInsertAfter = list[i];
686 HeapFree( GetProcessHeap(), 0, list );
689 return hwndInsertAfter;
693 /* fix redundant flags and values in the WINDOWPOS structure */
694 static BOOL fixup_flags( WINDOWPOS *winpos )
696 WND *wndPtr = WIN_GetPtr( winpos->hwnd );
697 BOOL ret = TRUE;
699 if (!wndPtr || wndPtr == WND_OTHER_PROCESS)
701 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
702 return FALSE;
704 winpos->hwnd = wndPtr->hwndSelf; /* make it a full handle */
706 if (wndPtr->dwStyle & WS_VISIBLE) winpos->flags &= ~SWP_SHOWWINDOW;
707 else
709 winpos->flags &= ~SWP_HIDEWINDOW;
710 if (!(winpos->flags & SWP_SHOWWINDOW)) winpos->flags |= SWP_NOREDRAW;
713 if (winpos->cx < 0) winpos->cx = 0;
714 if (winpos->cy < 0) winpos->cy = 0;
716 if ((wndPtr->rectWindow.right - wndPtr->rectWindow.left == winpos->cx) &&
717 (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top == winpos->cy))
718 winpos->flags |= SWP_NOSIZE; /* Already the right size */
720 if ((wndPtr->rectWindow.left == winpos->x) && (wndPtr->rectWindow.top == winpos->y))
721 winpos->flags |= SWP_NOMOVE; /* Already the right position */
723 if (winpos->hwnd == GetForegroundWindow())
724 winpos->flags |= SWP_NOACTIVATE; /* Already active */
725 else if ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD)
727 if (!(winpos->flags & SWP_NOACTIVATE)) /* Bring to the top when activating */
729 winpos->flags &= ~SWP_NOZORDER;
730 winpos->hwndInsertAfter = HWND_TOP;
731 goto done;
735 /* Check hwndInsertAfter */
736 if (winpos->flags & SWP_NOZORDER) goto done;
738 /* fix sign extension */
739 if (winpos->hwndInsertAfter == (HWND)0xffff) winpos->hwndInsertAfter = HWND_TOPMOST;
740 else if (winpos->hwndInsertAfter == (HWND)0xfffe) winpos->hwndInsertAfter = HWND_NOTOPMOST;
742 /* FIXME: TOPMOST not supported yet */
743 if ((winpos->hwndInsertAfter == HWND_TOPMOST) ||
744 (winpos->hwndInsertAfter == HWND_NOTOPMOST)) winpos->hwndInsertAfter = HWND_TOP;
746 /* hwndInsertAfter must be a sibling of the window */
747 if ((winpos->hwndInsertAfter != HWND_TOP) && (winpos->hwndInsertAfter != HWND_BOTTOM))
749 winpos->hwndInsertAfter = WIN_GetFullHandle( winpos->hwndInsertAfter );
750 if (GetAncestor( winpos->hwndInsertAfter, GA_PARENT ) != wndPtr->parent) ret = FALSE;
751 else
753 /* don't need to change the Zorder of hwnd if it's already inserted
754 * after hwndInsertAfter or when inserting hwnd after itself.
756 if ((winpos->hwnd == winpos->hwndInsertAfter) ||
757 (winpos->hwnd == GetWindow( winpos->hwndInsertAfter, GW_HWNDNEXT )))
758 winpos->flags |= SWP_NOZORDER;
761 done:
762 WIN_ReleasePtr( wndPtr );
763 return ret;
767 /***********************************************************************
768 * SetWindowStyle (X11DRV.@)
770 * Update the X state of a window to reflect a style change
772 void X11DRV_SetWindowStyle( HWND hwnd, LONG oldStyle )
774 Display *display = thread_display();
775 WND *wndPtr;
776 LONG changed;
778 if (hwnd == GetDesktopWindow()) return;
779 if (!(wndPtr = WIN_GetPtr( hwnd ))) return;
780 if (wndPtr == WND_OTHER_PROCESS) return;
782 changed = wndPtr->dwStyle ^ oldStyle;
784 if (changed & WS_VISIBLE)
786 if (!IsRectEmpty( &wndPtr->rectWindow ))
788 if (wndPtr->dwStyle & WS_VISIBLE)
790 TRACE( "mapping win %x\n", hwnd );
791 TSXMapWindow( display, get_whole_window(wndPtr) );
793 else
795 TRACE( "unmapping win %x\n", hwnd );
796 TSXUnmapWindow( display, get_whole_window(wndPtr) );
801 if (changed & WS_DISABLED)
803 if (wndPtr->dwExStyle & WS_EX_MANAGED)
805 XWMHints *wm_hints;
806 wine_tsx11_lock();
807 if (!(wm_hints = XGetWMHints( display, get_whole_window(wndPtr) )))
808 wm_hints = XAllocWMHints();
809 if (wm_hints)
811 wm_hints->flags |= InputHint;
812 wm_hints->input = !(wndPtr->dwStyle & WS_DISABLED);
813 XSetWMHints( display, get_whole_window(wndPtr), wm_hints );
814 XFree(wm_hints);
816 wine_tsx11_unlock();
819 WIN_ReleasePtr(wndPtr);
823 /***********************************************************************
824 * SetWindowPos (X11DRV.@)
826 BOOL X11DRV_SetWindowPos( WINDOWPOS *winpos )
828 WND *wndPtr;
829 RECT newWindowRect, newClientRect;
830 RECT oldWindowRect, oldClientRect;
831 UINT wvrFlags = 0;
832 BOOL bChangePos;
834 TRACE( "hwnd %04x, swp (%i,%i)-(%i,%i) flags %08x\n",
835 winpos->hwnd, winpos->x, winpos->y,
836 winpos->x + winpos->cx, winpos->y + winpos->cy, winpos->flags);
838 bChangePos = !(winpos->flags & SWP_WINE_NOHOSTMOVE);
839 winpos->flags &= ~SWP_WINE_NOHOSTMOVE;
841 /* Fix redundant flags */
842 if (!fixup_flags( winpos )) return FALSE;
844 /* Check window handle */
845 if (winpos->hwnd == GetDesktopWindow()) return FALSE;
847 SWP_DoWinPosChanging( winpos, &newWindowRect, &newClientRect );
849 if (!(wndPtr = WIN_FindWndPtr( winpos->hwnd ))) return FALSE;
851 TRACE("\tcurrent (%i,%i)-(%i,%i), style %08x\n",
852 wndPtr->rectWindow.left, wndPtr->rectWindow.top,
853 wndPtr->rectWindow.right, wndPtr->rectWindow.bottom, (unsigned)wndPtr->dwStyle );
855 if((winpos->flags & (SWP_NOZORDER | SWP_HIDEWINDOW | SWP_SHOWWINDOW)) != SWP_NOZORDER)
857 if (GetAncestor( winpos->hwnd, GA_PARENT ) == GetDesktopWindow())
858 winpos->hwndInsertAfter = SWP_DoOwnedPopups( winpos->hwnd, winpos->hwndInsertAfter );
861 /* Common operations */
863 wvrFlags = SWP_DoNCCalcSize( winpos, &newWindowRect, &newClientRect );
865 if(!(winpos->flags & SWP_NOZORDER) && winpos->hwnd != winpos->hwndInsertAfter)
867 HWND parent = GetAncestor( winpos->hwnd, GA_PARENT );
868 if (parent) WIN_LinkWindow( winpos->hwnd, parent, winpos->hwndInsertAfter );
871 /* Reset active DCEs */
873 if( (((winpos->flags & SWP_AGG_NOPOSCHANGE) != SWP_AGG_NOPOSCHANGE) &&
874 wndPtr->dwStyle & WS_VISIBLE) ||
875 (winpos->flags & (SWP_HIDEWINDOW | SWP_SHOWWINDOW)) )
877 RECT rect;
879 UnionRect(&rect, &newWindowRect, &wndPtr->rectWindow);
880 DCE_InvalidateDCE(wndPtr->hwndSelf, &rect);
883 oldWindowRect = wndPtr->rectWindow;
884 oldClientRect = wndPtr->rectClient;
886 /* Find out if we have to redraw the whole client rect */
888 if( oldClientRect.bottom - oldClientRect.top ==
889 newClientRect.bottom - newClientRect.top ) wvrFlags &= ~WVR_VREDRAW;
891 if( oldClientRect.right - oldClientRect.left ==
892 newClientRect.right - newClientRect.left ) wvrFlags &= ~WVR_HREDRAW;
894 /* FIXME: actually do something with WVR_VALIDRECTS */
896 WIN_SetRectangles( winpos->hwnd, &newWindowRect, &newClientRect );
898 if (get_whole_window(wndPtr)) /* don't do anything if X window not created yet */
900 Display *display = thread_display();
902 if (!(winpos->flags & SWP_SHOWWINDOW) && (winpos->flags & SWP_HIDEWINDOW))
904 /* clear the update region */
905 RedrawWindow( winpos->hwnd, NULL, 0, RDW_VALIDATE | RDW_NOFRAME |
906 RDW_NOERASE | RDW_NOINTERNALPAINT | RDW_ALLCHILDREN );
907 WIN_SetStyle( winpos->hwnd, wndPtr->dwStyle & ~WS_VISIBLE );
909 else if ((wndPtr->dwStyle & WS_VISIBLE) &&
910 !IsRectEmpty( &oldWindowRect ) && IsRectEmpty( &newWindowRect ))
912 /* resizing to zero size -> unmap */
913 TRACE( "unmapping zero size win %x\n", winpos->hwnd );
914 TSXUnmapWindow( display, get_whole_window(wndPtr) );
917 wine_tsx11_lock();
918 if (bChangePos)
919 X11DRV_sync_whole_window_position( display, wndPtr, !(winpos->flags & SWP_NOZORDER) );
920 else
922 struct x11drv_win_data *data = wndPtr->pDriverData;
923 data->whole_rect = wndPtr->rectWindow;
924 X11DRV_window_to_X_rect( wndPtr, &data->whole_rect );
927 if (X11DRV_sync_client_window_position( display, wndPtr ) ||
928 (winpos->flags & SWP_FRAMECHANGED))
930 /* if we moved the client area, repaint the whole non-client window */
931 XClearArea( display, get_whole_window(wndPtr), 0, 0, 0, 0, True );
932 winpos->flags |= SWP_FRAMECHANGED;
934 if (winpos->flags & SWP_SHOWWINDOW)
936 WIN_SetStyle( winpos->hwnd, wndPtr->dwStyle | WS_VISIBLE );
938 else if ((wndPtr->dwStyle & WS_VISIBLE) &&
939 IsRectEmpty( &oldWindowRect ) && !IsRectEmpty( &newWindowRect ))
941 /* resizing from zero size to non-zero -> map */
942 TRACE( "mapping non zero size win %x\n", winpos->hwnd );
943 XMapWindow( display, get_whole_window(wndPtr) );
945 XFlush( display ); /* FIXME: should not be necessary */
946 wine_tsx11_unlock();
948 else /* no X window, simply toggle the window style */
950 if (winpos->flags & SWP_SHOWWINDOW)
951 WIN_SetStyle( winpos->hwnd, wndPtr->dwStyle | WS_VISIBLE );
952 else if (winpos->flags & SWP_HIDEWINDOW)
953 WIN_SetStyle( winpos->hwnd, wndPtr->dwStyle & ~WS_VISIBLE );
956 /* manually expose the areas that X won't expose because they are still covered by something */
958 if (!(winpos->flags & SWP_SHOWWINDOW))
959 expose_covered_parent_area( wndPtr, &oldWindowRect );
961 if (wndPtr->dwStyle & WS_VISIBLE)
962 expose_covered_window_area( wndPtr, &oldClientRect, winpos->flags & SWP_FRAMECHANGED );
964 WIN_ReleaseWndPtr(wndPtr);
966 if (wvrFlags & WVR_REDRAW) RedrawWindow( winpos->hwnd, NULL, 0, RDW_INVALIDATE | RDW_ERASE );
968 if (winpos->hwnd == CARET_GetHwnd())
970 if( winpos->flags & SWP_HIDEWINDOW )
971 HideCaret(winpos->hwnd);
972 else if (winpos->flags & SWP_SHOWWINDOW)
973 ShowCaret(winpos->hwnd);
976 if (!(winpos->flags & SWP_NOACTIVATE))
978 /* child windows get WM_CHILDACTIVATE message */
979 if ((GetWindowLongW( winpos->hwnd, GWL_STYLE ) & (WS_CHILD | WS_POPUP)) == WS_CHILD)
980 SendMessageA( winpos->hwnd, WM_CHILDACTIVATE, 0, 0 );
981 else
982 SetActiveWindow( winpos->hwnd );
985 /* And last, send the WM_WINDOWPOSCHANGED message */
987 TRACE("\tstatus flags = %04x\n", winpos->flags & SWP_AGG_STATUSFLAGS);
989 if (((winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOPOSCHANGE) &&
990 !(winpos->flags & SWP_NOSENDCHANGING))
991 SendMessageA( winpos->hwnd, WM_WINDOWPOSCHANGED, 0, (LPARAM)winpos );
993 return TRUE;
997 /***********************************************************************
998 * WINPOS_FindIconPos
1000 * Find a suitable place for an iconic window.
1002 static POINT WINPOS_FindIconPos( WND* wndPtr, POINT pt )
1004 RECT rectParent;
1005 HWND *list;
1006 short x, y, xspacing, yspacing;
1008 GetClientRect( wndPtr->parent, &rectParent );
1009 if ((pt.x >= rectParent.left) && (pt.x + GetSystemMetrics(SM_CXICON) < rectParent.right) &&
1010 (pt.y >= rectParent.top) && (pt.y + GetSystemMetrics(SM_CYICON) < rectParent.bottom))
1011 return pt; /* The icon already has a suitable position */
1013 xspacing = GetSystemMetrics(SM_CXICONSPACING);
1014 yspacing = GetSystemMetrics(SM_CYICONSPACING);
1016 list = WIN_ListChildren( wndPtr->parent );
1017 y = rectParent.bottom;
1018 for (;;)
1020 x = rectParent.left;
1023 /* Check if another icon already occupies this spot */
1024 /* FIXME: this is completely inefficient */
1025 if (list)
1027 int i;
1028 WND *childPtr;
1030 for (i = 0; list[i]; i++)
1032 if (list[i] == wndPtr->hwndSelf) continue;
1033 if (!IsIconic( list[i] )) continue;
1034 if (!(childPtr = WIN_FindWndPtr( list[i] ))) continue;
1035 if ((childPtr->rectWindow.left < x + xspacing) &&
1036 (childPtr->rectWindow.right >= x) &&
1037 (childPtr->rectWindow.top <= y) &&
1038 (childPtr->rectWindow.bottom > y - yspacing))
1040 WIN_ReleaseWndPtr( childPtr );
1041 break; /* There's a window in there */
1043 WIN_ReleaseWndPtr( childPtr );
1045 if (list[i])
1047 /* found something here, try next spot */
1048 x += xspacing;
1049 continue;
1053 /* No window was found, so it's OK for us */
1054 pt.x = x + (xspacing - GetSystemMetrics(SM_CXICON)) / 2;
1055 pt.y = y - (yspacing + GetSystemMetrics(SM_CYICON)) / 2;
1056 return pt;
1058 } while(x <= rectParent.right-xspacing);
1059 y -= yspacing;
1067 UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect )
1069 WND *wndPtr;
1070 UINT swpFlags = 0;
1071 POINT size;
1072 LONG old_style;
1073 WINDOWPLACEMENT wpl;
1075 TRACE("0x%04x %u\n", hwnd, cmd );
1077 wpl.length = sizeof(wpl);
1078 GetWindowPlacement( hwnd, &wpl );
1080 if (HOOK_CallHooksA( WH_CBT, HCBT_MINMAX, (WPARAM)hwnd, cmd ))
1081 return SWP_NOSIZE | SWP_NOMOVE;
1083 if (IsIconic( hwnd ))
1085 if (cmd == SW_MINIMIZE) return SWP_NOSIZE | SWP_NOMOVE;
1086 if (!SendMessageA( hwnd, WM_QUERYOPEN, 0, 0 )) return SWP_NOSIZE | SWP_NOMOVE;
1087 swpFlags |= SWP_NOCOPYBITS;
1090 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
1092 size.x = wndPtr->rectWindow.left;
1093 size.y = wndPtr->rectWindow.top;
1095 switch( cmd )
1097 case SW_MINIMIZE:
1098 if( wndPtr->dwStyle & WS_MAXIMIZE) wndPtr->flags |= WIN_RESTORE_MAX;
1099 else wndPtr->flags &= ~WIN_RESTORE_MAX;
1101 WIN_SetStyle( hwnd, (wndPtr->dwStyle & ~WS_MAXIMIZE) | WS_MINIMIZE );
1103 X11DRV_set_iconic_state( wndPtr );
1105 wpl.ptMinPosition = WINPOS_FindIconPos( wndPtr, wpl.ptMinPosition );
1107 SetRect( rect, wpl.ptMinPosition.x, wpl.ptMinPosition.y,
1108 GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON) );
1109 swpFlags |= SWP_NOCOPYBITS;
1110 break;
1112 case SW_MAXIMIZE:
1113 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL );
1115 old_style = WIN_SetStyle( hwnd, (wndPtr->dwStyle & ~WS_MINIMIZE) | WS_MAXIMIZE );
1116 if (old_style & WS_MINIMIZE)
1118 WINPOS_ShowIconTitle( hwnd, FALSE );
1119 X11DRV_set_iconic_state( wndPtr );
1121 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y );
1122 break;
1124 case SW_RESTORE:
1125 old_style = WIN_SetStyle( hwnd, wndPtr->dwStyle & ~(WS_MINIMIZE|WS_MAXIMIZE) );
1126 if (old_style & WS_MINIMIZE)
1128 WINPOS_ShowIconTitle( hwnd, FALSE );
1129 X11DRV_set_iconic_state( wndPtr );
1131 if( wndPtr->flags & WIN_RESTORE_MAX)
1133 /* Restore to maximized position */
1134 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL);
1135 WIN_SetStyle( hwnd, wndPtr->dwStyle | WS_MAXIMIZE );
1136 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y );
1137 break;
1140 else if (!(old_style & WS_MAXIMIZE)) break;
1142 /* Restore to normal position */
1144 *rect = wpl.rcNormalPosition;
1145 rect->right -= rect->left;
1146 rect->bottom -= rect->top;
1148 break;
1151 WIN_ReleaseWndPtr( wndPtr );
1152 return swpFlags;
1156 /***********************************************************************
1157 * ShowWindow (X11DRV.@)
1159 BOOL X11DRV_ShowWindow( HWND hwnd, INT cmd )
1161 WND* wndPtr = WIN_FindWndPtr( hwnd );
1162 BOOL wasVisible, showFlag;
1163 RECT newPos = {0, 0, 0, 0};
1164 UINT swp = 0;
1166 if (!wndPtr) return FALSE;
1167 hwnd = wndPtr->hwndSelf; /* make it a full handle */
1169 TRACE("hwnd=%04x, cmd=%d\n", hwnd, cmd);
1171 wasVisible = (wndPtr->dwStyle & WS_VISIBLE) != 0;
1173 switch(cmd)
1175 case SW_HIDE:
1176 if (!wasVisible) goto END;
1177 swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE |
1178 SWP_NOACTIVATE | SWP_NOZORDER;
1179 break;
1181 case SW_SHOWMINNOACTIVE:
1182 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1183 /* fall through */
1184 case SW_SHOWMINIMIZED:
1185 case SW_FORCEMINIMIZE: /* FIXME: Does not work if thread is hung. */
1186 swp |= SWP_SHOWWINDOW;
1187 /* fall through */
1188 case SW_MINIMIZE:
1189 swp |= SWP_FRAMECHANGED;
1190 if( !(wndPtr->dwStyle & WS_MINIMIZE) )
1191 swp |= WINPOS_MinMaximize( hwnd, SW_MINIMIZE, &newPos );
1192 else swp |= SWP_NOSIZE | SWP_NOMOVE;
1193 break;
1195 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
1196 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
1197 if( !(wndPtr->dwStyle & WS_MAXIMIZE) )
1198 swp |= WINPOS_MinMaximize( hwnd, SW_MAXIMIZE, &newPos );
1199 else swp |= SWP_NOSIZE | SWP_NOMOVE;
1200 break;
1202 case SW_SHOWNA:
1203 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1204 /* fall through */
1205 case SW_SHOW:
1206 swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
1209 * ShowWindow has a little peculiar behavior that if the
1210 * window is already the topmost window, it will not
1211 * activate it.
1213 if (GetTopWindow((HWND)0)==hwnd && (wasVisible || GetActiveWindow() == hwnd))
1214 swp |= SWP_NOACTIVATE;
1216 break;
1218 case SW_SHOWNOACTIVATE:
1219 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1220 /* fall through */
1221 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
1222 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
1223 case SW_RESTORE:
1224 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
1226 if( wndPtr->dwStyle & (WS_MINIMIZE | WS_MAXIMIZE) )
1227 swp |= WINPOS_MinMaximize( hwnd, SW_RESTORE, &newPos );
1228 else swp |= SWP_NOSIZE | SWP_NOMOVE;
1229 break;
1232 showFlag = (cmd != SW_HIDE);
1233 if (showFlag != wasVisible)
1235 SendMessageA( hwnd, WM_SHOWWINDOW, showFlag, 0 );
1236 if (!IsWindow( hwnd )) goto END;
1239 /* We can't activate a child window */
1240 if ((wndPtr->dwStyle & WS_CHILD) &&
1241 !(wndPtr->dwExStyle & WS_EX_MDICHILD))
1242 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1244 SetWindowPos( hwnd, HWND_TOP, newPos.left, newPos.top,
1245 newPos.right, newPos.bottom, LOWORD(swp) );
1246 if (cmd == SW_HIDE)
1248 /* FIXME: This will cause the window to be activated irrespective
1249 * of whether it is owned by the same thread. Has to be done
1250 * asynchronously.
1253 if (hwnd == GetActiveWindow())
1254 WINPOS_ActivateOtherWindow(hwnd);
1256 /* Revert focus to parent */
1257 if (hwnd == GetFocus() || IsChild(hwnd, GetFocus()))
1258 SetFocus( GetParent(hwnd) );
1260 if (!IsWindow( hwnd )) goto END;
1261 else if( wndPtr->dwStyle & WS_MINIMIZE ) WINPOS_ShowIconTitle( hwnd, TRUE );
1263 if (wndPtr->flags & WIN_NEED_SIZE)
1265 /* should happen only in CreateWindowEx() */
1266 int wParam = SIZE_RESTORED;
1268 wndPtr->flags &= ~WIN_NEED_SIZE;
1269 if (wndPtr->dwStyle & WS_MAXIMIZE) wParam = SIZE_MAXIMIZED;
1270 else if (wndPtr->dwStyle & WS_MINIMIZE) wParam = SIZE_MINIMIZED;
1271 SendMessageA( hwnd, WM_SIZE, wParam,
1272 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
1273 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
1274 SendMessageA( hwnd, WM_MOVE, 0,
1275 MAKELONG(wndPtr->rectClient.left, wndPtr->rectClient.top) );
1278 END:
1279 WIN_ReleaseWndPtr(wndPtr);
1280 return wasVisible;
1284 /**********************************************************************
1285 * X11DRV_MapNotify
1287 void X11DRV_MapNotify( HWND hwnd, XMapEvent *event )
1289 HWND hwndFocus = GetFocus();
1290 WND *win;
1292 if (!(win = WIN_GetPtr( hwnd ))) return;
1294 if ((win->dwStyle & WS_VISIBLE) &&
1295 (win->dwStyle & WS_MINIMIZE) &&
1296 (win->dwExStyle & WS_EX_MANAGED))
1298 int x, y;
1299 unsigned int width, height, border, depth;
1300 Window root, top;
1301 RECT rect;
1302 LONG style = (win->dwStyle & ~(WS_MINIMIZE|WS_MAXIMIZE)) | WS_VISIBLE;
1304 /* FIXME: hack */
1305 wine_tsx11_lock();
1306 XGetGeometry( event->display, get_whole_window(win), &root, &x, &y, &width, &height,
1307 &border, &depth );
1308 XTranslateCoordinates( event->display, get_whole_window(win), root, 0, 0, &x, &y, &top );
1309 wine_tsx11_unlock();
1310 rect.left = x;
1311 rect.top = y;
1312 rect.right = x + width;
1313 rect.bottom = y + height;
1314 X11DRV_X_to_window_rect( win, &rect );
1316 DCE_InvalidateDCE( hwnd, &win->rectWindow );
1318 if (win->flags & WIN_RESTORE_MAX) style |= WS_MAXIMIZE;
1319 WIN_SetStyle( hwnd, style );
1320 WIN_ReleasePtr( win );
1322 WIN_InternalShowOwnedPopups( hwnd, TRUE, TRUE );
1323 SendMessageA( hwnd, WM_SHOWWINDOW, SW_RESTORE, 0 );
1324 SetWindowPos( hwnd, 0, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
1325 SWP_NOZORDER | SWP_WINE_NOHOSTMOVE );
1327 else WIN_ReleasePtr( win );
1328 if (hwndFocus && IsChild( hwnd, hwndFocus )) X11DRV_SetFocus(hwndFocus); /* FIXME */
1332 /**********************************************************************
1333 * X11DRV_UnmapNotify
1335 void X11DRV_UnmapNotify( HWND hwnd, XUnmapEvent *event )
1337 WND *win;
1339 if (!(win = WIN_GetPtr( hwnd ))) return;
1341 if ((win->dwStyle & WS_VISIBLE) && (win->dwExStyle & WS_EX_MANAGED))
1343 if (win->dwStyle & WS_MAXIMIZE)
1344 win->flags |= WIN_RESTORE_MAX;
1345 else
1346 win->flags &= ~WIN_RESTORE_MAX;
1348 WIN_SetStyle( hwnd, (win->dwStyle & ~WS_MAXIMIZE) | WS_MINIMIZE );
1349 WIN_ReleasePtr( win );
1351 EndMenu();
1352 SendMessageA( hwnd, WM_SHOWWINDOW, SW_MINIMIZE, 0 );
1353 SetWindowPos( hwnd, 0, 0, 0, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON),
1354 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_WINE_NOHOSTMOVE );
1356 WIN_InternalShowOwnedPopups( hwnd, FALSE, TRUE );
1358 else WIN_ReleasePtr( win );
1362 /***********************************************************************
1363 * query_zorder
1365 * Synchronize internal z-order with the window manager's.
1367 static Window __get_common_ancestor( Display *display, Window A, Window B,
1368 Window** children, unsigned* total )
1370 /* find the real root window */
1372 Window root, *childrenB;
1373 unsigned totalB;
1375 while( A != B && A && B )
1377 TSXQueryTree( display, A, &root, &A, children, total );
1378 TSXQueryTree( display, B, &root, &B, &childrenB, &totalB );
1379 if( childrenB ) TSXFree( childrenB );
1380 if( *children ) TSXFree( *children ), *children = NULL;
1383 if( A && B )
1385 TSXQueryTree( display, A, &root, &B, children, total );
1386 return A;
1388 return 0 ;
1391 static Window __get_top_decoration( Display *display, Window w, Window ancestor )
1393 Window* children, root, prev = w, parent = w;
1394 unsigned total;
1398 w = parent;
1399 TSXQueryTree( display, w, &root, &parent, &children, &total );
1400 if( children ) TSXFree( children );
1401 } while( parent && parent != ancestor );
1402 TRACE("\t%08x -> %08x\n", (unsigned)prev, (unsigned)w );
1403 return ( parent ) ? w : 0 ;
1406 static unsigned __td_lookup( Window w, Window* list, unsigned max )
1408 unsigned i;
1409 for( i = max - 1; i >= 0; i-- ) if( list[i] == w ) break;
1410 return i;
1413 static HWND query_zorder( Display *display, HWND hWndCheck)
1415 HWND hwndInsertAfter = HWND_TOP;
1416 Window w, parent, *children = NULL;
1417 unsigned total, check, pos, best;
1418 HWND *list = WIN_ListChildren( GetDesktopWindow() );
1419 HWND hwndA = 0, hwndB = 0;
1420 int i;
1422 /* find at least two managed windows */
1423 if (!list) return 0;
1424 for (i = 0; list[i]; i++)
1426 if (!(GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_MANAGED)) continue;
1427 if (!(GetWindowLongW( list[i], GWL_STYLE ) & WS_VISIBLE)) continue;
1428 if (!hwndA) hwndA = list[i];
1429 else
1431 hwndB = list[i];
1432 break;
1435 if (!hwndA || !hwndB) goto done;
1437 parent = __get_common_ancestor( display, X11DRV_get_whole_window(hwndA),
1438 X11DRV_get_whole_window(hwndB), &children, &total );
1439 if( parent && children )
1441 /* w is the ancestor if hWndCheck that is a direct descendant of 'parent' */
1443 w = __get_top_decoration( display, X11DRV_get_whole_window(hWndCheck), parent );
1445 if( w != children[total-1] ) /* check if at the top */
1447 /* X child at index 0 is at the bottom, at index total-1 is at the top */
1448 check = __td_lookup( w, children, total );
1449 best = total;
1451 /* go through all windows in Wine z-order... */
1452 for (i = 0; list[i]; i++)
1454 if (list[i] == hWndCheck) continue;
1455 if (!(GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_MANAGED)) continue;
1456 if (!(w = __get_top_decoration( display, X11DRV_get_whole_window(list[i]),
1457 parent ))) continue;
1458 pos = __td_lookup( w, children, total );
1459 if( pos < best && pos > check )
1461 /* find a nearest Wine window precedes hWndCheck in the real z-order */
1462 best = pos;
1463 hwndInsertAfter = list[i];
1465 if( best - check == 1 ) break;
1469 if( children ) TSXFree( children );
1471 done:
1472 HeapFree( GetProcessHeap(), 0, list );
1473 return hwndInsertAfter;
1477 /***********************************************************************
1478 * X11DRV_ConfigureNotify
1480 void X11DRV_ConfigureNotify( HWND hwnd, XConfigureEvent *event )
1482 HWND oldInsertAfter;
1483 struct x11drv_win_data *data;
1484 WND *win;
1485 RECT rect;
1486 WINDOWPOS winpos;
1487 int x = event->x, y = event->y;
1489 if (!(win = WIN_GetPtr( hwnd ))) return;
1490 data = win->pDriverData;
1492 /* Get geometry */
1494 if (!event->send_event) /* normal event, need to map coordinates to the root */
1496 Window child;
1497 wine_tsx11_lock();
1498 XTranslateCoordinates( event->display, data->whole_window, root_window,
1499 0, 0, &x, &y, &child );
1500 wine_tsx11_unlock();
1502 rect.left = x;
1503 rect.top = y;
1504 rect.right = x + event->width;
1505 rect.bottom = y + event->height;
1506 TRACE( "win %x new X rect %d,%d,%dx%d (event %d,%d,%dx%d)\n",
1507 hwnd, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
1508 event->x, event->y, event->width, event->height );
1509 X11DRV_X_to_window_rect( win, &rect );
1510 WIN_ReleasePtr( win );
1512 winpos.hwnd = hwnd;
1513 winpos.x = rect.left;
1514 winpos.y = rect.top;
1515 winpos.cx = rect.right - rect.left;
1516 winpos.cy = rect.bottom - rect.top;
1517 winpos.flags = SWP_NOACTIVATE;
1519 /* Get Z-order (FIXME) */
1521 winpos.hwndInsertAfter = query_zorder( event->display, hwnd );
1523 /* needs to find the first Visible Window above the current one */
1524 oldInsertAfter = hwnd;
1525 for (;;)
1527 oldInsertAfter = GetWindow( oldInsertAfter, GW_HWNDPREV );
1528 if (!oldInsertAfter)
1530 oldInsertAfter = HWND_TOP;
1531 break;
1533 if (GetWindowLongA( oldInsertAfter, GWL_STYLE ) & WS_VISIBLE) break;
1536 /* Compare what has changed */
1538 GetWindowRect( hwnd, &rect );
1539 if (rect.left == winpos.x && rect.top == winpos.y) winpos.flags |= SWP_NOMOVE;
1540 else
1541 TRACE( "%04x moving from (%d,%d) to (%d,%d)\n",
1542 hwnd, rect.left, rect.top, winpos.x, winpos.y );
1544 if ((rect.right - rect.left == winpos.cx && rect.bottom - rect.top == winpos.cy) ||
1545 IsIconic(hwnd) ||
1546 (IsRectEmpty( &rect ) && winpos.cx == 1 && winpos.cy == 1))
1547 winpos.flags |= SWP_NOSIZE;
1548 else
1549 TRACE( "%04x resizing from (%dx%d) to (%dx%d)\n",
1550 hwnd, rect.right - rect.left, rect.bottom - rect.top,
1551 winpos.cx, winpos.cy );
1553 if (winpos.hwndInsertAfter == oldInsertAfter) winpos.flags |= SWP_NOZORDER;
1554 else
1555 TRACE( "%04x restacking from after %04x to after %04x\n",
1556 hwnd, oldInsertAfter, winpos.hwndInsertAfter );
1558 /* if nothing changed, don't do anything */
1559 if (winpos.flags == (SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE)) return;
1561 SetWindowPos( hwnd, winpos.hwndInsertAfter, winpos.x, winpos.y,
1562 winpos.cx, winpos.cy, winpos.flags | SWP_WINE_NOHOSTMOVE );
1566 /***********************************************************************
1567 * SetWindowRgn (X11DRV.@)
1569 * Assign specified region to window (for non-rectangular windows)
1571 int X11DRV_SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL redraw )
1573 WND *wndPtr;
1575 if ((wndPtr = WIN_GetPtr( hwnd )) == WND_OTHER_PROCESS)
1577 if (IsWindow( hwnd ))
1578 FIXME( "not supported on other process window %x\n", hwnd );
1579 wndPtr = NULL;
1581 if (!wndPtr)
1583 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1584 return FALSE;
1587 if (wndPtr->hrgnWnd == hrgn)
1589 WIN_ReleasePtr( wndPtr );
1590 return TRUE;
1593 if (wndPtr->hrgnWnd)
1595 /* delete previous region */
1596 DeleteObject(wndPtr->hrgnWnd);
1597 wndPtr->hrgnWnd = 0;
1599 wndPtr->hrgnWnd = hrgn;
1601 #ifdef HAVE_LIBXSHAPE
1603 Display *display = thread_display();
1604 X11DRV_WND_DATA *data = wndPtr->pDriverData;
1606 if (data->whole_window)
1608 if (!hrgn)
1610 TSXShapeCombineMask( display, data->whole_window,
1611 ShapeBounding, 0, 0, None, ShapeSet );
1613 else
1615 XRectangle *aXRect;
1616 int x_offset, y_offset;
1617 DWORD size;
1618 DWORD dwBufferSize = GetRegionData(hrgn, 0, NULL);
1619 PRGNDATA pRegionData = HeapAlloc(GetProcessHeap(), 0, dwBufferSize);
1620 if (!pRegionData)
1622 WIN_ReleasePtr( wndPtr );
1623 return TRUE;
1625 GetRegionData(hrgn, dwBufferSize, pRegionData);
1626 size = pRegionData->rdh.nCount;
1627 x_offset = wndPtr->rectWindow.left - data->whole_rect.left;
1628 y_offset = wndPtr->rectWindow.top - data->whole_rect.top;
1629 /* convert region's "Windows rectangles" to XRectangles */
1630 aXRect = HeapAlloc(GetProcessHeap(), 0, size * sizeof(*aXRect) );
1631 if (aXRect)
1633 XRectangle* pCurrRect = aXRect;
1634 RECT *pRect = (RECT*) pRegionData->Buffer;
1635 for (; pRect < ((RECT*) pRegionData->Buffer) + size ; ++pRect, ++pCurrRect)
1637 pCurrRect->x = pRect->left + x_offset;
1638 pCurrRect->y = pRect->top + y_offset;
1639 pCurrRect->height = pRect->bottom - pRect->top;
1640 pCurrRect->width = pRect->right - pRect->left;
1642 TRACE("Rectangle %04d of %04ld data: X=%04d, Y=%04d, Height=%04d, Width=%04d.\n",
1643 pRect - (RECT*) pRegionData->Buffer,
1644 size,
1645 pCurrRect->x,
1646 pCurrRect->y,
1647 pCurrRect->height,
1648 pCurrRect->width);
1651 /* shape = non-rectangular windows (X11/extensions) */
1652 TSXShapeCombineRectangles( display, data->whole_window, ShapeBounding,
1653 0, 0, aXRect,
1654 pCurrRect - aXRect, ShapeSet, YXBanded );
1655 HeapFree(GetProcessHeap(), 0, aXRect );
1657 HeapFree(GetProcessHeap(), 0, pRegionData);
1661 #endif /* HAVE_LIBXSHAPE */
1663 WIN_ReleasePtr( wndPtr );
1664 if (redraw) RedrawWindow( hwnd, NULL, 0, RDW_FRAME | RDW_INVALIDATE | RDW_ERASE );
1665 return TRUE;
1669 /***********************************************************************
1670 * draw_moving_frame
1672 * Draw the frame used when moving or resizing window.
1674 * FIXME: This causes problems in Win95 mode. (why?)
1676 static void draw_moving_frame( HDC hdc, RECT *rect, BOOL thickframe )
1678 if (thickframe)
1680 const int width = GetSystemMetrics(SM_CXFRAME);
1681 const int height = GetSystemMetrics(SM_CYFRAME);
1683 HBRUSH hbrush = SelectObject( hdc, GetStockObject( GRAY_BRUSH ) );
1684 PatBlt( hdc, rect->left, rect->top,
1685 rect->right - rect->left - width, height, PATINVERT );
1686 PatBlt( hdc, rect->left, rect->top + height, width,
1687 rect->bottom - rect->top - height, PATINVERT );
1688 PatBlt( hdc, rect->left + width, rect->bottom - 1,
1689 rect->right - rect->left - width, -height, PATINVERT );
1690 PatBlt( hdc, rect->right - 1, rect->top, -width,
1691 rect->bottom - rect->top - height, PATINVERT );
1692 SelectObject( hdc, hbrush );
1694 else DrawFocusRect( hdc, rect );
1698 /***********************************************************************
1699 * start_size_move
1701 * Initialisation of a move or resize, when initiatied from a menu choice.
1702 * Return hit test code for caption or sizing border.
1704 static LONG start_size_move( HWND hwnd, WPARAM wParam, POINT *capturePoint, LONG style )
1706 LONG hittest = 0;
1707 POINT pt;
1708 MSG msg;
1709 RECT rectWindow;
1711 GetWindowRect( hwnd, &rectWindow );
1713 if ((wParam & 0xfff0) == SC_MOVE)
1715 /* Move pointer at the center of the caption */
1716 RECT rect;
1717 NC_GetInsideRect( hwnd, &rect );
1718 if (style & WS_SYSMENU)
1719 rect.left += GetSystemMetrics(SM_CXSIZE) + 1;
1720 if (style & WS_MINIMIZEBOX)
1721 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1722 if (style & WS_MAXIMIZEBOX)
1723 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1724 pt.x = rectWindow.left + (rect.right - rect.left) / 2;
1725 pt.y = rectWindow.top + rect.top + GetSystemMetrics(SM_CYSIZE)/2;
1726 hittest = HTCAPTION;
1727 *capturePoint = pt;
1729 else /* SC_SIZE */
1731 while(!hittest)
1733 GetMessageW( &msg, 0, WM_KEYFIRST, WM_MOUSELAST );
1734 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
1736 switch(msg.message)
1738 case WM_MOUSEMOVE:
1739 hittest = NC_HandleNCHitTest( hwnd, msg.pt );
1740 if ((hittest < HTLEFT) || (hittest > HTBOTTOMRIGHT))
1741 hittest = 0;
1742 break;
1744 case WM_LBUTTONUP:
1745 return 0;
1747 case WM_KEYDOWN:
1748 switch(msg.wParam)
1750 case VK_UP:
1751 hittest = HTTOP;
1752 pt.x =(rectWindow.left+rectWindow.right)/2;
1753 pt.y = rectWindow.top + GetSystemMetrics(SM_CYFRAME) / 2;
1754 break;
1755 case VK_DOWN:
1756 hittest = HTBOTTOM;
1757 pt.x =(rectWindow.left+rectWindow.right)/2;
1758 pt.y = rectWindow.bottom - GetSystemMetrics(SM_CYFRAME) / 2;
1759 break;
1760 case VK_LEFT:
1761 hittest = HTLEFT;
1762 pt.x = rectWindow.left + GetSystemMetrics(SM_CXFRAME) / 2;
1763 pt.y =(rectWindow.top+rectWindow.bottom)/2;
1764 break;
1765 case VK_RIGHT:
1766 hittest = HTRIGHT;
1767 pt.x = rectWindow.right - GetSystemMetrics(SM_CXFRAME) / 2;
1768 pt.y =(rectWindow.top+rectWindow.bottom)/2;
1769 break;
1770 case VK_RETURN:
1771 case VK_ESCAPE: return 0;
1775 *capturePoint = pt;
1777 SetCursorPos( pt.x, pt.y );
1778 NC_HandleSetCursor( hwnd, (WPARAM)hwnd, MAKELONG( hittest, WM_MOUSEMOVE ));
1779 return hittest;
1783 /***********************************************************************
1784 * SysCommandSizeMove (X11DRV.@)
1786 * Perform SC_MOVE and SC_SIZE commands.
1788 void X11DRV_SysCommandSizeMove( HWND hwnd, WPARAM wParam )
1790 MSG msg;
1791 RECT sizingRect, mouseRect, origRect;
1792 HDC hdc;
1793 HWND parent;
1794 LONG hittest = (LONG)(wParam & 0x0f);
1795 HCURSOR16 hDragCursor = 0, hOldCursor = 0;
1796 POINT minTrack, maxTrack;
1797 POINT capturePoint, pt;
1798 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
1799 LONG exstyle = GetWindowLongA( hwnd, GWL_EXSTYLE );
1800 BOOL thickframe = HAS_THICKFRAME( style, exstyle );
1801 BOOL iconic = style & WS_MINIMIZE;
1802 BOOL moved = FALSE;
1803 DWORD dwPoint = GetMessagePos ();
1804 BOOL DragFullWindows = FALSE;
1805 BOOL grab;
1806 int iWndsLocks;
1807 Display *old_gdi_display = NULL;
1808 Display *display = thread_display();
1810 SystemParametersInfoA(SPI_GETDRAGFULLWINDOWS, 0, &DragFullWindows, 0);
1812 pt.x = SLOWORD(dwPoint);
1813 pt.y = SHIWORD(dwPoint);
1814 capturePoint = pt;
1816 if (IsZoomed(hwnd) || !IsWindowVisible(hwnd) || (exstyle & WS_EX_MANAGED)) return;
1818 if ((wParam & 0xfff0) == SC_MOVE)
1820 if (!hittest) hittest = start_size_move( hwnd, wParam, &capturePoint, style );
1821 if (!hittest) return;
1823 else /* SC_SIZE */
1825 if (!thickframe) return;
1826 if ( hittest && hittest != HTSYSMENU ) hittest += 2;
1827 else
1829 SetCapture(hwnd);
1830 hittest = start_size_move( hwnd, wParam, &capturePoint, style );
1831 if (!hittest)
1833 ReleaseCapture();
1834 return;
1839 /* Get min/max info */
1841 WINPOS_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack );
1842 GetWindowRect( hwnd, &sizingRect );
1843 if (style & WS_CHILD)
1845 parent = GetParent(hwnd);
1846 /* make sizing rect relative to parent */
1847 MapWindowPoints( 0, parent, (POINT*)&sizingRect, 2 );
1848 GetClientRect( parent, &mouseRect );
1850 else
1852 parent = 0;
1853 SetRect(&mouseRect, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
1855 origRect = sizingRect;
1857 if (ON_LEFT_BORDER(hittest))
1859 mouseRect.left = max( mouseRect.left, sizingRect.right-maxTrack.x );
1860 mouseRect.right = min( mouseRect.right, sizingRect.right-minTrack.x );
1862 else if (ON_RIGHT_BORDER(hittest))
1864 mouseRect.left = max( mouseRect.left, sizingRect.left+minTrack.x );
1865 mouseRect.right = min( mouseRect.right, sizingRect.left+maxTrack.x );
1867 if (ON_TOP_BORDER(hittest))
1869 mouseRect.top = max( mouseRect.top, sizingRect.bottom-maxTrack.y );
1870 mouseRect.bottom = min( mouseRect.bottom,sizingRect.bottom-minTrack.y);
1872 else if (ON_BOTTOM_BORDER(hittest))
1874 mouseRect.top = max( mouseRect.top, sizingRect.top+minTrack.y );
1875 mouseRect.bottom = min( mouseRect.bottom, sizingRect.top+maxTrack.y );
1877 if (parent) MapWindowPoints( parent, 0, (LPPOINT)&mouseRect, 2 );
1879 /* Retrieve a default cache DC (without using the window style) */
1880 hdc = GetDCEx( parent, 0, DCX_CACHE );
1882 if( iconic ) /* create a cursor for dragging */
1884 hDragCursor = GetClassLongA( hwnd, GCL_HICON);
1885 if( !hDragCursor ) hDragCursor = (HCURSOR)SendMessageA( hwnd, WM_QUERYDRAGICON, 0, 0L);
1886 if( !hDragCursor ) iconic = FALSE;
1889 /* repaint the window before moving it around */
1890 RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN );
1892 SendMessageA( hwnd, WM_ENTERSIZEMOVE, 0, 0 );
1893 SetCapture( hwnd );
1895 /* grab the server only when moving top-level windows without desktop */
1896 grab = (!DragFullWindows && !parent && (root_window == DefaultRootWindow(gdi_display)));
1898 wine_tsx11_lock();
1899 if (grab)
1901 XSync( gdi_display, False );
1902 XGrabServer( display );
1903 XSync( display, False );
1904 /* switch gdi display to the thread display, since the server is grabbed */
1905 old_gdi_display = gdi_display;
1906 gdi_display = display;
1908 XGrabPointer( display, X11DRV_get_whole_window(hwnd), False,
1909 PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
1910 GrabModeAsync, GrabModeAsync,
1911 parent ? X11DRV_get_client_window(parent) : root_window,
1912 None, CurrentTime );
1913 wine_tsx11_unlock();
1915 while(1)
1917 int dx = 0, dy = 0;
1919 if (!GetMessageW( &msg, 0, WM_KEYFIRST, WM_MOUSELAST )) break;
1920 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
1922 /* Exit on button-up, Return, or Esc */
1923 if ((msg.message == WM_LBUTTONUP) ||
1924 ((msg.message == WM_KEYDOWN) &&
1925 ((msg.wParam == VK_RETURN) || (msg.wParam == VK_ESCAPE)))) break;
1927 if ((msg.message != WM_KEYDOWN) && (msg.message != WM_MOUSEMOVE))
1928 continue; /* We are not interested in other messages */
1930 pt = msg.pt;
1932 if (msg.message == WM_KEYDOWN) switch(msg.wParam)
1934 case VK_UP: pt.y -= 8; break;
1935 case VK_DOWN: pt.y += 8; break;
1936 case VK_LEFT: pt.x -= 8; break;
1937 case VK_RIGHT: pt.x += 8; break;
1940 pt.x = max( pt.x, mouseRect.left );
1941 pt.x = min( pt.x, mouseRect.right );
1942 pt.y = max( pt.y, mouseRect.top );
1943 pt.y = min( pt.y, mouseRect.bottom );
1945 dx = pt.x - capturePoint.x;
1946 dy = pt.y - capturePoint.y;
1948 if (dx || dy)
1950 if( !moved )
1952 moved = TRUE;
1954 if( iconic ) /* ok, no system popup tracking */
1956 hOldCursor = SetCursor(hDragCursor);
1957 ShowCursor( TRUE );
1958 WINPOS_ShowIconTitle( hwnd, FALSE );
1960 else if(!DragFullWindows)
1961 draw_moving_frame( hdc, &sizingRect, thickframe );
1964 if (msg.message == WM_KEYDOWN) SetCursorPos( pt.x, pt.y );
1965 else
1967 RECT newRect = sizingRect;
1968 WPARAM wpSizingHit = 0;
1970 if (hittest == HTCAPTION) OffsetRect( &newRect, dx, dy );
1971 if (ON_LEFT_BORDER(hittest)) newRect.left += dx;
1972 else if (ON_RIGHT_BORDER(hittest)) newRect.right += dx;
1973 if (ON_TOP_BORDER(hittest)) newRect.top += dy;
1974 else if (ON_BOTTOM_BORDER(hittest)) newRect.bottom += dy;
1975 if(!iconic && !DragFullWindows) draw_moving_frame( hdc, &sizingRect, thickframe );
1976 capturePoint = pt;
1978 /* determine the hit location */
1979 if (hittest >= HTLEFT && hittest <= HTBOTTOMRIGHT)
1980 wpSizingHit = WMSZ_LEFT + (hittest - HTLEFT);
1981 SendMessageA( hwnd, WM_SIZING, wpSizingHit, (LPARAM)&newRect );
1983 if (!iconic)
1985 if(!DragFullWindows)
1986 draw_moving_frame( hdc, &newRect, thickframe );
1987 else {
1988 /* To avoid any deadlocks, all the locks on the windows
1989 structures must be suspended before the SetWindowPos */
1990 iWndsLocks = WIN_SuspendWndsLock();
1991 SetWindowPos( hwnd, 0, newRect.left, newRect.top,
1992 newRect.right - newRect.left,
1993 newRect.bottom - newRect.top,
1994 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
1995 WIN_RestoreWndsLock(iWndsLocks);
1998 sizingRect = newRect;
2003 ReleaseCapture();
2004 if( iconic )
2006 if( moved ) /* restore cursors, show icon title later on */
2008 ShowCursor( FALSE );
2009 SetCursor( hOldCursor );
2012 else if (moved && !DragFullWindows)
2013 draw_moving_frame( hdc, &sizingRect, thickframe );
2015 ReleaseDC( parent, hdc );
2017 wine_tsx11_lock();
2018 XUngrabPointer( display, CurrentTime );
2019 if (grab)
2021 XSync( display, False );
2022 XUngrabServer( display );
2023 XSync( display, False );
2024 gdi_display = old_gdi_display;
2026 wine_tsx11_unlock();
2028 if (HOOK_CallHooksA( WH_CBT, HCBT_MOVESIZE, (WPARAM)hwnd, (LPARAM)&sizingRect )) moved = FALSE;
2030 SendMessageA( hwnd, WM_EXITSIZEMOVE, 0, 0 );
2031 SendMessageA( hwnd, WM_SETVISIBLE, !IsIconic(hwnd), 0L);
2033 /* window moved or resized */
2034 if (moved)
2036 /* To avoid any deadlocks, all the locks on the windows
2037 structures must be suspended before the SetWindowPos */
2038 iWndsLocks = WIN_SuspendWndsLock();
2040 /* if the moving/resizing isn't canceled call SetWindowPos
2041 * with the new position or the new size of the window
2043 if (!((msg.message == WM_KEYDOWN) && (msg.wParam == VK_ESCAPE)) )
2045 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
2046 if(!DragFullWindows)
2047 SetWindowPos( hwnd, 0, sizingRect.left, sizingRect.top,
2048 sizingRect.right - sizingRect.left,
2049 sizingRect.bottom - sizingRect.top,
2050 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
2052 else
2053 { /* restore previous size/position */
2054 if(DragFullWindows)
2055 SetWindowPos( hwnd, 0, origRect.left, origRect.top,
2056 origRect.right - origRect.left,
2057 origRect.bottom - origRect.top,
2058 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
2061 WIN_RestoreWndsLock(iWndsLocks);
2064 if (IsIconic(hwnd))
2066 /* Single click brings up the system menu when iconized */
2068 if( !moved )
2070 if(style & WS_SYSMENU )
2071 SendMessageA( hwnd, WM_SYSCOMMAND,
2072 SC_MOUSEMENU + HTSYSMENU, MAKELONG(pt.x,pt.y));
2074 else WINPOS_ShowIconTitle( hwnd, TRUE );
2079 /***********************************************************************
2080 * ForceWindowRaise (X11DRV.@)
2082 * Raise a window on top of the X stacking order, while preserving
2083 * the correct Windows Z order.
2085 * FIXME: this should go away.
2087 void X11DRV_ForceWindowRaise( HWND hwnd )
2089 int i = 0;
2090 HWND *list;
2091 XWindowChanges winChanges;
2092 Display *display = thread_display();
2093 WND *wndPtr = WIN_FindWndPtr( hwnd );
2095 if (!wndPtr) return;
2097 if ((wndPtr->dwExStyle & WS_EX_MANAGED) ||
2098 wndPtr->parent != GetDesktopWindow() ||
2099 IsRectEmpty( &wndPtr->rectWindow ) ||
2100 !get_whole_window(wndPtr))
2102 WIN_ReleaseWndPtr( wndPtr );
2103 return;
2105 WIN_ReleaseWndPtr( wndPtr );
2107 /* Raise all windows up to wndPtr according to their Z order.
2108 * (it would be easier with sibling-related Below but it doesn't
2109 * work very well with SGI mwm for instance)
2111 winChanges.stack_mode = Above;
2112 if (!(list = WIN_ListChildren( GetDesktopWindow() ))) return;
2113 while (list[i] && list[i] != hwnd) i++;
2114 if (list[i])
2116 for ( ; i >= 0; i--)
2118 WND *ptr = WIN_FindWndPtr( list[i] );
2119 if (!ptr) continue;
2120 if (!IsRectEmpty( &ptr->rectWindow ) && get_whole_window(ptr))
2121 TSXReconfigureWMWindow( display, get_whole_window(ptr), 0,
2122 CWStackMode, &winChanges );
2123 WIN_ReleaseWndPtr( ptr );
2126 HeapFree( GetProcessHeap(), 0, list );