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 */
40 #include "cursoricon.h"
41 #include "nonclient.h"
44 #include "wine/server.h"
45 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
49 #define SWP_AGG_NOGEOMETRYCHANGE \
50 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE)
51 #define SWP_AGG_NOPOSCHANGE \
52 (SWP_AGG_NOGEOMETRYCHANGE | SWP_NOZORDER)
53 #define SWP_AGG_STATUSFLAGS \
54 (SWP_AGG_NOPOSCHANGE | SWP_FRAMECHANGED | SWP_HIDEWINDOW | SWP_SHOWWINDOW)
56 #define SWP_EX_NOCOPY 0x0001
57 #define SWP_EX_PAINTSELF 0x0002
58 #define SWP_EX_NONCLIENT 0x0004
60 #define HAS_THICKFRAME(style,exStyle) \
61 (((style) & WS_THICKFRAME) && \
62 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
64 #define ON_LEFT_BORDER(hit) \
65 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
66 #define ON_RIGHT_BORDER(hit) \
67 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
68 #define ON_TOP_BORDER(hit) \
69 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
70 #define ON_BOTTOM_BORDER(hit) \
71 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
74 /***********************************************************************
77 * Clip all children of a given window out of the visible region
79 static int clip_children( HWND parent, HWND last, HRGN hrgn, int whole_window )
84 int i, x, y, ret = SIMPLEREGION;
86 /* first check if we have anything to do */
87 if (!(list = WIN_ListChildren( parent ))) return ret;
88 for (i = 0; list[i] && list[i] != last; i++)
89 if (GetWindowLongW( list[i], GWL_STYLE ) & WS_VISIBLE) break;
90 if (!list[i] || list[i] == last) goto done; /* no children to clip */
94 WND *win = WIN_FindWndPtr( parent );
95 x = win->rectWindow.left - win->rectClient.left;
96 y = win->rectWindow.top - win->rectClient.top;
97 WIN_ReleaseWndPtr( win );
101 rectRgn = CreateRectRgn( 0, 0, 0, 0 );
103 for ( ; list[i] && list[i] != last; i++)
105 if (!(ptr = WIN_FindWndPtr( list[i] ))) continue;
106 if (ptr->dwStyle & WS_VISIBLE)
108 SetRectRgn( rectRgn, ptr->rectWindow.left + x, ptr->rectWindow.top + y,
109 ptr->rectWindow.right + x, ptr->rectWindow.bottom + y );
110 if ((ret = CombineRgn( hrgn, hrgn, rectRgn, RGN_DIFF )) == NULLREGION)
112 WIN_ReleaseWndPtr( ptr );
113 break; /* no need to go on, region is empty */
116 WIN_ReleaseWndPtr( ptr );
118 DeleteObject( rectRgn );
120 HeapFree( GetProcessHeap(), 0, list );
125 /***********************************************************************
128 * Compute the visible region of a window
130 static HRGN get_visible_region( WND *win, HWND top, UINT flags, int mode )
134 int xoffset, yoffset;
135 X11DRV_WND_DATA *data = win->pDriverData;
137 if (flags & DCX_WINDOW)
139 xoffset = win->rectWindow.left;
140 yoffset = win->rectWindow.top;
144 xoffset = win->rectClient.left;
145 yoffset = win->rectClient.top;
148 if (flags & DCX_PARENTCLIP)
149 GetClientRect( win->parent, &rect );
150 else if (flags & DCX_WINDOW)
151 rect = data->whole_rect;
153 rect = win->rectClient;
155 /* vis region is relative to the start of the client/window area */
156 OffsetRect( &rect, -xoffset, -yoffset );
158 if (!(rgn = CreateRectRgn( rect.left, rect.top, rect.right, rect.bottom ))) return 0;
160 if ((flags & DCX_CLIPCHILDREN) && (mode != ClipByChildren))
162 /* we need to clip children by hand */
163 if (clip_children( win->hwndSelf, 0, rgn, (flags & DCX_WINDOW) ) == NULLREGION) return rgn;
166 if (top && top != win->hwndSelf) /* need to clip siblings of ancestors */
168 WND *parent, *ptr = WIN_FindWndPtr( win->hwndSelf );
171 OffsetRgn( rgn, xoffset, yoffset );
174 if (ptr->dwStyle & WS_CLIPSIBLINGS)
176 if (clip_children( ptr->parent, ptr->hwndSelf, rgn, FALSE ) == NULLREGION) break;
178 if (ptr->hwndSelf == top) break;
179 if (!(parent = WIN_FindWndPtr( ptr->parent ))) break;
180 WIN_ReleaseWndPtr( ptr );
182 /* clip to parent client area */
183 if (tmp) SetRectRgn( tmp, 0, 0, ptr->rectClient.right - ptr->rectClient.left,
184 ptr->rectClient.bottom - ptr->rectClient.top );
185 else tmp = CreateRectRgn( 0, 0, ptr->rectClient.right - ptr->rectClient.left,
186 ptr->rectClient.bottom - ptr->rectClient.top );
187 CombineRgn( rgn, rgn, tmp, RGN_AND );
188 OffsetRgn( rgn, ptr->rectClient.left, ptr->rectClient.top );
189 xoffset += ptr->rectClient.left;
190 yoffset += ptr->rectClient.top;
192 WIN_ReleaseWndPtr( ptr );
193 /* make it relative to the target window again */
194 OffsetRgn( rgn, -xoffset, -yoffset );
195 if (tmp) DeleteObject( tmp );
202 /***********************************************************************
205 * Compute the portion of 'rgn' that is covered by non-clipped siblings.
206 * This is the area that is covered from X point of view, but may still need
208 * 'rgn' must be relative to the client area of the parent of 'win'.
210 static int get_covered_region( WND *win, HRGN rgn )
214 WND *parent, *ptr = WIN_FindWndPtr( win->hwndSelf );
215 int xoffset = 0, yoffset = 0;
217 tmp = CreateRectRgn( 0, 0, 0, 0 );
218 CombineRgn( tmp, rgn, 0, RGN_COPY );
220 /* to make things easier we actually build the uncovered
221 * area by removing all siblings and then we subtract that
222 * from the total region to get the covered area */
225 if (!(ptr->dwStyle & WS_CLIPSIBLINGS))
227 if (clip_children( ptr->parent, ptr->hwndSelf, tmp, FALSE ) == NULLREGION) break;
229 if (!(parent = WIN_FindWndPtr( ptr->parent ))) break;
230 WIN_ReleaseWndPtr( ptr );
232 OffsetRgn( tmp, ptr->rectClient.left, ptr->rectClient.top );
233 xoffset += ptr->rectClient.left;
234 yoffset += ptr->rectClient.top;
236 WIN_ReleaseWndPtr( ptr );
237 /* make it relative to the target window again */
238 OffsetRgn( tmp, -xoffset, -yoffset );
240 /* now subtract the computed region from the original one */
241 ret = CombineRgn( rgn, rgn, tmp, RGN_DIFF );
247 /***********************************************************************
250 * Expose a region of a given window.
252 static void expose_window( HWND hwnd, RECT *rect, HRGN rgn, int flags )
259 /* find the top most parent that doesn't clip children or siblings and
260 * invalidate the area on its parent, including all children */
261 if ((list = WIN_ListParents( hwnd )))
264 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
265 for (i = 0; list[i] && list[i] != GetDesktopWindow(); i++)
267 if (!(style & WS_CLIPSIBLINGS)) top = current;
268 style = GetWindowLongW( list[i], GWL_STYLE );
269 if (!(style & WS_CLIPCHILDREN)) top = current;
275 /* find the parent of the top window, reusing the parent list */
276 if (top == hwnd) i = 0;
279 for (i = 0; list[i]; i++) if (list[i] == top) break;
280 if (list[i] && list[i+1]) i++;
282 if (list[i] != GetDesktopWindow()) top = list[i];
283 flags &= ~RDW_FRAME; /* parent will invalidate children frame anyway */
284 flags |= RDW_ALLCHILDREN;
286 HeapFree( GetProcessHeap(), 0, list );
289 if (!top) top = hwnd;
291 /* make coords relative to top */
292 offset.x = offset.y = 0;
293 MapWindowPoints( hwnd, top, &offset, 1 );
297 OffsetRect( rect, offset.x, offset.y );
298 RedrawWindow( top, rect, 0, flags );
302 OffsetRgn( rgn, offset.x, offset.y );
303 RedrawWindow( top, NULL, rgn, flags );
308 /***********************************************************************
309 * expose_covered_parent_area
311 * Expose the parent area that has been uncovered by moving/hiding a
312 * given window, but that is still covered by other siblings (the area
313 * not covered by siblings will be exposed automatically by X).
315 static void expose_covered_parent_area( WND *win, const RECT *old_rect )
317 int ret = SIMPLEREGION;
318 HRGN hrgn = CreateRectRgnIndirect( old_rect );
320 if (win->dwStyle & WS_VISIBLE)
322 HRGN tmp = CreateRectRgnIndirect( &win->rectWindow );
323 ret = CombineRgn( hrgn, hrgn, tmp, RGN_DIFF );
327 if (ret != NULLREGION)
329 if (get_covered_region( win, hrgn ) != NULLREGION)
330 expose_window( win->parent, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
332 DeleteObject( hrgn );
336 /***********************************************************************
337 * expose_covered_window_area
339 * Expose the area of a window that is covered by other siblings.
341 static void expose_covered_window_area( WND *win, const RECT *old_client_rect, BOOL frame )
344 int ret = SIMPLEREGION;
347 hrgn = CreateRectRgn( win->rectWindow.left - win->rectClient.left,
348 win->rectWindow.top - win->rectClient.top,
349 win->rectWindow.right - win->rectWindow.left,
350 win->rectWindow.bottom - win->rectWindow.top );
352 hrgn = CreateRectRgn( 0, 0,
353 win->rectClient.right - win->rectClient.left,
354 win->rectClient.bottom - win->rectClient.top );
356 /* if the client rect didn't move we don't need to repaint it all */
357 if (old_client_rect->left == win->rectClient.left &&
358 old_client_rect->top == win->rectClient.top)
362 if (IntersectRect( &rc, old_client_rect, &win->rectClient ))
365 /* subtract the unchanged client area from the region to expose */
366 OffsetRect( &rc, -win->rectClient.left, -win->rectClient.top );
367 if ((tmp = CreateRectRgnIndirect( &rc )))
369 ret = CombineRgn( hrgn, hrgn, tmp, RGN_DIFF );
375 if (ret != NULLREGION)
377 if (get_covered_region( win, hrgn ) != NULLREGION)
378 expose_window( win->hwndSelf, NULL, hrgn,
379 RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
382 DeleteObject( hrgn );
386 /***********************************************************************
389 void X11DRV_Expose( HWND hwnd, XExposeEvent *event )
392 struct x11drv_win_data *data;
393 int flags = RDW_INVALIDATE | RDW_ERASE;
396 TRACE( "win %x (%lx) %d,%d %dx%d\n",
397 hwnd, event->window, event->x, event->y, event->width, event->height );
399 rect.left = event->x;
401 rect.right = rect.left + event->width;
402 rect.bottom = rect.top + event->height;
404 if (!(win = WIN_GetPtr( hwnd ))) return;
405 data = win->pDriverData;
407 if (event->window != data->client_window) /* whole window or icon window */
410 /* make position relative to client area instead of window */
411 OffsetRect( &rect, -data->client_rect.left, -data->client_rect.top );
413 WIN_ReleasePtr( win );
415 expose_window( hwnd, &rect, 0, flags );
419 /***********************************************************************
422 * Set the drawable, origin and dimensions for the DC associated to
425 BOOL X11DRV_GetDC( HWND hwnd, HDC hdc, HRGN hrgn, DWORD flags )
427 WND *win = WIN_GetPtr( hwnd );
429 X11DRV_WND_DATA *data = win->pDriverData;
432 POINT org, drawable_org;
433 int mode = IncludeInferiors;
435 /* don't clip siblings if using parent clip region */
436 if (flags & DCX_PARENTCLIP) flags &= ~DCX_CLIPSIBLINGS;
438 /* find the top parent in the hierarchy that isn't clipping siblings */
439 visible = (win->dwStyle & WS_VISIBLE) != 0;
443 HWND *list = WIN_ListParents( hwnd );
447 for (i = 0; list[i] != GetDesktopWindow(); i++)
449 LONG style = GetWindowLongW( list[i], GWL_STYLE );
450 if (!(style & WS_VISIBLE))
456 if (!(style & WS_CLIPSIBLINGS)) top = list[i];
458 HeapFree( GetProcessHeap(), 0, list );
460 if (!top && visible && !(flags & DCX_CLIPSIBLINGS)) top = hwnd;
465 HWND parent = GetAncestor( top, GA_PARENT );
467 if (flags & DCX_WINDOW)
469 org.x = win->rectWindow.left - win->rectClient.left;
470 org.y = win->rectWindow.top - win->rectClient.top;
473 MapWindowPoints( hwnd, parent, &org, 1 );
474 MapWindowPoints( hwnd, 0, &drawable_org, 1 );
475 /* have to use the parent so that we include siblings */
476 if (parent) drawable = X11DRV_get_client_window( parent );
477 else drawable = root_window;
481 if (IsIconic( hwnd ))
483 drawable = data->icon_window ? data->icon_window : data->whole_window;
488 else if (flags & DCX_WINDOW)
490 drawable = data->whole_window;
491 org.x = win->rectWindow.left - data->whole_rect.left;
492 org.y = win->rectWindow.top - data->whole_rect.top;
493 drawable_org.x = data->whole_rect.left - win->rectClient.left;
494 drawable_org.y = data->whole_rect.top - win->rectClient.top;
498 drawable = data->client_window;
502 if (flags & DCX_CLIPCHILDREN) mode = ClipByChildren; /* can use X11 clipping */
504 MapWindowPoints( hwnd, 0, &drawable_org, 1 );
507 X11DRV_SetDrawable( hdc, drawable, mode, &org, &drawable_org );
509 if (flags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN) ||
510 SetHookFlags16( hdc, DCHF_VALIDATEVISRGN )) /* DC was dirty */
512 /* need to recompute the visible region */
517 visRgn = get_visible_region( win, top, flags, mode );
519 if (flags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN))
520 CombineRgn( visRgn, visRgn, hrgn,
521 (flags & DCX_INTERSECTRGN) ? RGN_AND : RGN_DIFF );
523 else visRgn = CreateRectRgn( 0, 0, 0, 0 );
525 SelectVisRgn16( hdc, visRgn );
526 DeleteObject( visRgn );
529 WIN_ReleasePtr( win );
535 /***********************************************************************
536 * SWP_DoWinPosChanging
538 static BOOL SWP_DoWinPosChanging( WINDOWPOS* pWinpos, RECT* pNewWindowRect, RECT* pNewClientRect )
542 /* Send WM_WINDOWPOSCHANGING message */
544 if (!(pWinpos->flags & SWP_NOSENDCHANGING))
545 SendMessageA( pWinpos->hwnd, WM_WINDOWPOSCHANGING, 0, (LPARAM)pWinpos );
547 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return FALSE;
549 /* Calculate new position and size */
551 *pNewWindowRect = wndPtr->rectWindow;
552 *pNewClientRect = (wndPtr->dwStyle & WS_MINIMIZE) ? wndPtr->rectWindow
553 : wndPtr->rectClient;
555 if (!(pWinpos->flags & SWP_NOSIZE))
557 pNewWindowRect->right = pNewWindowRect->left + pWinpos->cx;
558 pNewWindowRect->bottom = pNewWindowRect->top + pWinpos->cy;
560 if (!(pWinpos->flags & SWP_NOMOVE))
562 pNewWindowRect->left = pWinpos->x;
563 pNewWindowRect->top = pWinpos->y;
564 pNewWindowRect->right += pWinpos->x - wndPtr->rectWindow.left;
565 pNewWindowRect->bottom += pWinpos->y - wndPtr->rectWindow.top;
567 OffsetRect( pNewClientRect, pWinpos->x - wndPtr->rectWindow.left,
568 pWinpos->y - wndPtr->rectWindow.top );
570 pWinpos->flags |= SWP_NOCLIENTMOVE | SWP_NOCLIENTSIZE;
571 WIN_ReleasePtr( wndPtr );
575 /***********************************************************************
578 static UINT SWP_DoNCCalcSize( WINDOWPOS* pWinpos, RECT* pNewWindowRect, RECT* pNewClientRect )
583 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
585 /* Send WM_NCCALCSIZE message to get new client area */
586 if( (pWinpos->flags & (SWP_FRAMECHANGED | SWP_NOSIZE)) != SWP_NOSIZE )
588 NCCALCSIZE_PARAMS params;
589 WINDOWPOS winposCopy;
591 params.rgrc[0] = *pNewWindowRect;
592 params.rgrc[1] = wndPtr->rectWindow;
593 params.rgrc[2] = wndPtr->rectClient;
594 params.lppos = &winposCopy;
595 winposCopy = *pWinpos;
596 WIN_ReleasePtr( wndPtr );
598 wvrFlags = SendMessageW( pWinpos->hwnd, WM_NCCALCSIZE, TRUE, (LPARAM)¶ms );
600 TRACE( "%d,%d-%d,%d\n", params.rgrc[0].left, params.rgrc[0].top,
601 params.rgrc[0].right, params.rgrc[0].bottom );
603 /* If the application send back garbage, ignore it */
604 if (params.rgrc[0].left <= params.rgrc[0].right &&
605 params.rgrc[0].top <= params.rgrc[0].bottom)
606 *pNewClientRect = params.rgrc[0];
608 /* FIXME: WVR_ALIGNxxx */
610 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
612 if( pNewClientRect->left != wndPtr->rectClient.left ||
613 pNewClientRect->top != wndPtr->rectClient.top )
614 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
616 if( (pNewClientRect->right - pNewClientRect->left !=
617 wndPtr->rectClient.right - wndPtr->rectClient.left) ||
618 (pNewClientRect->bottom - pNewClientRect->top !=
619 wndPtr->rectClient.bottom - wndPtr->rectClient.top) )
620 pWinpos->flags &= ~SWP_NOCLIENTSIZE;
624 if (!(pWinpos->flags & SWP_NOMOVE) &&
625 (pNewClientRect->left != wndPtr->rectClient.left ||
626 pNewClientRect->top != wndPtr->rectClient.top))
627 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
629 WIN_ReleasePtr( wndPtr );
634 /***********************************************************************
637 * fix Z order taking into account owned popups -
638 * basically we need to maintain them above the window that owns them
640 * FIXME: hide/show owned popups when owner visibility changes.
642 static HWND SWP_DoOwnedPopups(HWND hwnd, HWND hwndInsertAfter)
645 HWND owner = GetWindow( hwnd, GW_OWNER );
646 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
648 WARN("(%04x) hInsertAfter = %04x\n", hwnd, hwndInsertAfter );
650 if ((style & WS_POPUP) && owner)
652 /* make sure this popup stays above the owner */
654 HWND hwndLocalPrev = HWND_TOP;
656 if( hwndInsertAfter != HWND_TOP )
658 if ((list = WIN_ListChildren( GetDesktopWindow() )))
661 for (i = 0; list[i]; i++)
663 if (list[i] == owner) break;
664 if (list[i] != hwnd) hwndLocalPrev = list[i];
665 if (hwndLocalPrev == hwndInsertAfter) break;
667 hwndInsertAfter = hwndLocalPrev;
671 else if (style & WS_CHILD) return hwndInsertAfter;
673 if (!list) list = WIN_ListChildren( GetDesktopWindow() );
677 for (i = 0; list[i]; i++)
679 if (list[i] == hwnd) break;
680 if ((GetWindowLongW( list[i], GWL_STYLE ) & WS_POPUP) &&
681 GetWindow( list[i], GW_OWNER ) == hwnd)
683 SetWindowPos( list[i], hwndInsertAfter, 0, 0, 0, 0,
684 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE |
685 SWP_NOSENDCHANGING | SWP_DEFERERASE );
686 hwndInsertAfter = list[i];
689 HeapFree( GetProcessHeap(), 0, list );
692 return hwndInsertAfter;
696 /* fix redundant flags and values in the WINDOWPOS structure */
697 static BOOL fixup_flags( WINDOWPOS *winpos )
699 WND *wndPtr = WIN_GetPtr( winpos->hwnd );
702 if (!wndPtr || wndPtr == WND_OTHER_PROCESS)
704 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
707 winpos->hwnd = wndPtr->hwndSelf; /* make it a full handle */
709 if (wndPtr->dwStyle & WS_VISIBLE) winpos->flags &= ~SWP_SHOWWINDOW;
712 winpos->flags &= ~SWP_HIDEWINDOW;
713 if (!(winpos->flags & SWP_SHOWWINDOW)) winpos->flags |= SWP_NOREDRAW;
716 if (winpos->cx < 0) winpos->cx = 0;
717 if (winpos->cy < 0) winpos->cy = 0;
719 if ((wndPtr->rectWindow.right - wndPtr->rectWindow.left == winpos->cx) &&
720 (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top == winpos->cy))
721 winpos->flags |= SWP_NOSIZE; /* Already the right size */
723 if ((wndPtr->rectWindow.left == winpos->x) && (wndPtr->rectWindow.top == winpos->y))
724 winpos->flags |= SWP_NOMOVE; /* Already the right position */
726 if (winpos->hwnd == GetForegroundWindow())
727 winpos->flags |= SWP_NOACTIVATE; /* Already active */
728 else if ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD)
730 if (!(winpos->flags & SWP_NOACTIVATE)) /* Bring to the top when activating */
732 winpos->flags &= ~SWP_NOZORDER;
733 winpos->hwndInsertAfter = HWND_TOP;
738 /* Check hwndInsertAfter */
739 if (winpos->flags & SWP_NOZORDER) goto done;
741 /* fix sign extension */
742 if (winpos->hwndInsertAfter == (HWND)0xffff) winpos->hwndInsertAfter = HWND_TOPMOST;
743 else if (winpos->hwndInsertAfter == (HWND)0xfffe) winpos->hwndInsertAfter = HWND_NOTOPMOST;
745 /* FIXME: TOPMOST not supported yet */
746 if ((winpos->hwndInsertAfter == HWND_TOPMOST) ||
747 (winpos->hwndInsertAfter == HWND_NOTOPMOST)) winpos->hwndInsertAfter = HWND_TOP;
749 /* hwndInsertAfter must be a sibling of the window */
750 if ((winpos->hwndInsertAfter != HWND_TOP) && (winpos->hwndInsertAfter != HWND_BOTTOM))
752 winpos->hwndInsertAfter = WIN_GetFullHandle( winpos->hwndInsertAfter );
753 if (GetAncestor( winpos->hwndInsertAfter, GA_PARENT ) != wndPtr->parent) ret = FALSE;
756 /* don't need to change the Zorder of hwnd if it's already inserted
757 * after hwndInsertAfter or when inserting hwnd after itself.
759 if ((winpos->hwnd == winpos->hwndInsertAfter) ||
760 (winpos->hwnd == GetWindow( winpos->hwndInsertAfter, GW_HWNDNEXT )))
761 winpos->flags |= SWP_NOZORDER;
765 WIN_ReleasePtr( wndPtr );
770 /***********************************************************************
773 * Set/clear the WS_VISIBLE style of a window and map/unmap the X window.
775 static void set_visible_style( HWND hwnd, BOOL set )
779 if (!(win = WIN_GetPtr( hwnd ))) return;
780 if (win == WND_OTHER_PROCESS) return;
782 TRACE( "hwnd %x (%lx) set %d visible %d empty %d\n",
783 hwnd, get_whole_window(win),
784 set, (win->dwStyle & WS_VISIBLE) != 0, IsRectEmpty(&win->rectWindow) );
788 if (win->dwStyle & WS_VISIBLE) goto done;
789 WIN_SetStyle( hwnd, win->dwStyle | WS_VISIBLE );
790 if (!IsRectEmpty( &win->rectWindow ) && get_whole_window(win) && is_window_top_level(win))
792 Display *display = thread_display();
793 X11DRV_sync_window_style( display, win );
794 X11DRV_set_wm_hints( display, win );
795 TRACE( "mapping win %x\n", hwnd );
796 TSXMapWindow( display, get_whole_window(win) );
801 if (!(win->dwStyle & WS_VISIBLE)) goto done;
802 WIN_SetStyle( hwnd, win->dwStyle & ~WS_VISIBLE );
803 if (!IsRectEmpty( &win->rectWindow ) && get_whole_window(win) && is_window_top_level(win))
805 TRACE( "unmapping win %x\n", hwnd );
806 TSXUnmapWindow( thread_display(), get_whole_window(win) );
810 WIN_ReleasePtr( win );
814 /***********************************************************************
815 * SetWindowStyle (X11DRV.@)
817 * Update the X state of a window to reflect a style change
819 void X11DRV_SetWindowStyle( HWND hwnd, LONG oldStyle )
821 Display *display = thread_display();
825 if (hwnd == GetDesktopWindow()) return;
826 if (!(wndPtr = WIN_GetPtr( hwnd ))) return;
827 if (wndPtr == WND_OTHER_PROCESS) return;
829 changed = wndPtr->dwStyle ^ oldStyle;
831 if (changed & WS_VISIBLE)
833 if (!IsRectEmpty( &wndPtr->rectWindow ) && !is_window_top_level(wndPtr))
835 if (wndPtr->dwStyle & WS_VISIBLE)
837 TRACE( "mapping win %x\n", hwnd );
838 TSXMapWindow( display, get_whole_window(wndPtr) );
842 TRACE( "unmapping win %x\n", hwnd );
843 TSXUnmapWindow( display, get_whole_window(wndPtr) );
848 if (changed & WS_DISABLED)
850 if (wndPtr->dwExStyle & WS_EX_MANAGED)
854 if (!(wm_hints = XGetWMHints( display, get_whole_window(wndPtr) )))
855 wm_hints = XAllocWMHints();
858 wm_hints->flags |= InputHint;
859 wm_hints->input = !(wndPtr->dwStyle & WS_DISABLED);
860 XSetWMHints( display, get_whole_window(wndPtr), wm_hints );
866 WIN_ReleasePtr(wndPtr);
870 /***********************************************************************
871 * SetWindowPos (X11DRV.@)
873 BOOL X11DRV_SetWindowPos( WINDOWPOS *winpos )
876 RECT newWindowRect, newClientRect;
877 RECT oldWindowRect, oldClientRect;
881 TRACE( "hwnd %04x, swp (%i,%i)-(%i,%i) flags %08x\n",
882 winpos->hwnd, winpos->x, winpos->y,
883 winpos->x + winpos->cx, winpos->y + winpos->cy, winpos->flags);
885 bChangePos = !(winpos->flags & SWP_WINE_NOHOSTMOVE);
886 winpos->flags &= ~SWP_WINE_NOHOSTMOVE;
888 /* Fix redundant flags */
889 if (!fixup_flags( winpos )) return FALSE;
891 /* Check window handle */
892 if (winpos->hwnd == GetDesktopWindow()) return FALSE;
894 SWP_DoWinPosChanging( winpos, &newWindowRect, &newClientRect );
896 if (!(wndPtr = WIN_FindWndPtr( winpos->hwnd ))) return FALSE;
898 TRACE("\tcurrent (%i,%i)-(%i,%i), style %08x\n",
899 wndPtr->rectWindow.left, wndPtr->rectWindow.top,
900 wndPtr->rectWindow.right, wndPtr->rectWindow.bottom, (unsigned)wndPtr->dwStyle );
902 if((winpos->flags & (SWP_NOZORDER | SWP_HIDEWINDOW | SWP_SHOWWINDOW)) != SWP_NOZORDER)
904 if (GetAncestor( winpos->hwnd, GA_PARENT ) == GetDesktopWindow())
905 winpos->hwndInsertAfter = SWP_DoOwnedPopups( winpos->hwnd, winpos->hwndInsertAfter );
908 /* Common operations */
910 wvrFlags = SWP_DoNCCalcSize( winpos, &newWindowRect, &newClientRect );
912 if(!(winpos->flags & SWP_NOZORDER) && winpos->hwnd != winpos->hwndInsertAfter)
914 HWND parent = GetAncestor( winpos->hwnd, GA_PARENT );
915 if (parent) WIN_LinkWindow( winpos->hwnd, parent, winpos->hwndInsertAfter );
918 /* Reset active DCEs */
920 if( (((winpos->flags & SWP_AGG_NOPOSCHANGE) != SWP_AGG_NOPOSCHANGE) &&
921 wndPtr->dwStyle & WS_VISIBLE) ||
922 (winpos->flags & (SWP_HIDEWINDOW | SWP_SHOWWINDOW)) )
926 UnionRect(&rect, &newWindowRect, &wndPtr->rectWindow);
927 DCE_InvalidateDCE(wndPtr->hwndSelf, &rect);
930 oldWindowRect = wndPtr->rectWindow;
931 oldClientRect = wndPtr->rectClient;
933 /* Find out if we have to redraw the whole client rect */
935 if( oldClientRect.bottom - oldClientRect.top ==
936 newClientRect.bottom - newClientRect.top ) wvrFlags &= ~WVR_VREDRAW;
938 if( oldClientRect.right - oldClientRect.left ==
939 newClientRect.right - newClientRect.left ) wvrFlags &= ~WVR_HREDRAW;
941 /* FIXME: actually do something with WVR_VALIDRECTS */
943 WIN_SetRectangles( winpos->hwnd, &newWindowRect, &newClientRect );
945 if (get_whole_window(wndPtr)) /* don't do anything if X window not created yet */
947 Display *display = thread_display();
949 if (!(winpos->flags & SWP_SHOWWINDOW) && (winpos->flags & SWP_HIDEWINDOW))
951 /* clear the update region */
952 RedrawWindow( winpos->hwnd, NULL, 0, RDW_VALIDATE | RDW_NOFRAME |
953 RDW_NOERASE | RDW_NOINTERNALPAINT | RDW_ALLCHILDREN );
954 set_visible_style( winpos->hwnd, FALSE );
956 else if ((wndPtr->dwStyle & WS_VISIBLE) &&
957 !IsRectEmpty( &oldWindowRect ) && IsRectEmpty( &newWindowRect ))
959 /* resizing to zero size -> unmap */
960 TRACE( "unmapping zero size win %x\n", winpos->hwnd );
961 TSXUnmapWindow( display, get_whole_window(wndPtr) );
966 X11DRV_sync_whole_window_position( display, wndPtr, !(winpos->flags & SWP_NOZORDER) );
969 struct x11drv_win_data *data = wndPtr->pDriverData;
970 data->whole_rect = wndPtr->rectWindow;
971 X11DRV_window_to_X_rect( wndPtr, &data->whole_rect );
974 if (X11DRV_sync_client_window_position( display, wndPtr ) ||
975 (winpos->flags & SWP_FRAMECHANGED))
977 /* if we moved the client area, repaint the whole non-client window */
978 XClearArea( display, get_whole_window(wndPtr), 0, 0, 0, 0, True );
979 winpos->flags |= SWP_FRAMECHANGED;
981 if (winpos->flags & SWP_SHOWWINDOW)
983 set_visible_style( winpos->hwnd, TRUE );
985 else if ((wndPtr->dwStyle & WS_VISIBLE) &&
986 IsRectEmpty( &oldWindowRect ) && !IsRectEmpty( &newWindowRect ))
988 /* resizing from zero size to non-zero -> map */
989 TRACE( "mapping non zero size win %x\n", winpos->hwnd );
990 XMapWindow( display, get_whole_window(wndPtr) );
992 XFlush( display ); /* FIXME: should not be necessary */
995 else /* no X window, simply toggle the window style */
997 if (winpos->flags & SWP_SHOWWINDOW)
998 set_visible_style( winpos->hwnd, TRUE );
999 else if (winpos->flags & SWP_HIDEWINDOW)
1000 set_visible_style( winpos->hwnd, FALSE );
1003 /* manually expose the areas that X won't expose because they are still covered by something */
1005 if (!(winpos->flags & SWP_SHOWWINDOW))
1006 expose_covered_parent_area( wndPtr, &oldWindowRect );
1008 if (wndPtr->dwStyle & WS_VISIBLE)
1009 expose_covered_window_area( wndPtr, &oldClientRect, winpos->flags & SWP_FRAMECHANGED );
1011 WIN_ReleaseWndPtr(wndPtr);
1013 if (wvrFlags & WVR_REDRAW) RedrawWindow( winpos->hwnd, NULL, 0, RDW_INVALIDATE | RDW_ERASE );
1015 if( winpos->flags & SWP_HIDEWINDOW )
1016 HideCaret(winpos->hwnd);
1017 else if (winpos->flags & SWP_SHOWWINDOW)
1018 ShowCaret(winpos->hwnd);
1020 if (!(winpos->flags & SWP_NOACTIVATE))
1022 /* child windows get WM_CHILDACTIVATE message */
1023 if ((GetWindowLongW( winpos->hwnd, GWL_STYLE ) & (WS_CHILD | WS_POPUP)) == WS_CHILD)
1024 SendMessageA( winpos->hwnd, WM_CHILDACTIVATE, 0, 0 );
1026 SetForegroundWindow( winpos->hwnd );
1029 /* And last, send the WM_WINDOWPOSCHANGED message */
1031 TRACE("\tstatus flags = %04x\n", winpos->flags & SWP_AGG_STATUSFLAGS);
1033 if (((winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOPOSCHANGE))
1034 SendMessageA( winpos->hwnd, WM_WINDOWPOSCHANGED, 0, (LPARAM)winpos );
1035 /* WM_WINDOWPOSCHANGED is send even if SWP_NOSENDCHANGING is set */
1041 /***********************************************************************
1042 * WINPOS_FindIconPos
1044 * Find a suitable place for an iconic window.
1046 static POINT WINPOS_FindIconPos( WND* wndPtr, POINT pt )
1050 short x, y, xspacing, yspacing;
1052 GetClientRect( wndPtr->parent, &rectParent );
1053 if ((pt.x >= rectParent.left) && (pt.x + GetSystemMetrics(SM_CXICON) < rectParent.right) &&
1054 (pt.y >= rectParent.top) && (pt.y + GetSystemMetrics(SM_CYICON) < rectParent.bottom))
1055 return pt; /* The icon already has a suitable position */
1057 xspacing = GetSystemMetrics(SM_CXICONSPACING);
1058 yspacing = GetSystemMetrics(SM_CYICONSPACING);
1060 list = WIN_ListChildren( wndPtr->parent );
1061 y = rectParent.bottom;
1064 x = rectParent.left;
1067 /* Check if another icon already occupies this spot */
1068 /* FIXME: this is completely inefficient */
1074 for (i = 0; list[i]; i++)
1076 if (list[i] == wndPtr->hwndSelf) continue;
1077 if (!IsIconic( list[i] )) continue;
1078 if (!(childPtr = WIN_FindWndPtr( list[i] ))) continue;
1079 if ((childPtr->rectWindow.left < x + xspacing) &&
1080 (childPtr->rectWindow.right >= x) &&
1081 (childPtr->rectWindow.top <= y) &&
1082 (childPtr->rectWindow.bottom > y - yspacing))
1084 WIN_ReleaseWndPtr( childPtr );
1085 break; /* There's a window in there */
1087 WIN_ReleaseWndPtr( childPtr );
1091 /* found something here, try next spot */
1097 /* No window was found, so it's OK for us */
1098 pt.x = x + (xspacing - GetSystemMetrics(SM_CXICON)) / 2;
1099 pt.y = y - (yspacing + GetSystemMetrics(SM_CYICON)) / 2;
1100 HeapFree( GetProcessHeap(), 0, list );
1103 } while(x <= rectParent.right-xspacing);
1112 UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect )
1118 WINDOWPLACEMENT wpl;
1120 TRACE("0x%04x %u\n", hwnd, cmd );
1122 wpl.length = sizeof(wpl);
1123 GetWindowPlacement( hwnd, &wpl );
1125 if (HOOK_CallHooksA( WH_CBT, HCBT_MINMAX, (WPARAM)hwnd, cmd ))
1126 return SWP_NOSIZE | SWP_NOMOVE;
1128 if (IsIconic( hwnd ))
1130 if (cmd == SW_MINIMIZE) return SWP_NOSIZE | SWP_NOMOVE;
1131 if (!SendMessageA( hwnd, WM_QUERYOPEN, 0, 0 )) return SWP_NOSIZE | SWP_NOMOVE;
1132 swpFlags |= SWP_NOCOPYBITS;
1135 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
1137 size.x = wndPtr->rectWindow.left;
1138 size.y = wndPtr->rectWindow.top;
1143 if( wndPtr->dwStyle & WS_MAXIMIZE) wndPtr->flags |= WIN_RESTORE_MAX;
1144 else wndPtr->flags &= ~WIN_RESTORE_MAX;
1146 WIN_SetStyle( hwnd, (wndPtr->dwStyle & ~WS_MAXIMIZE) | WS_MINIMIZE );
1148 X11DRV_set_iconic_state( wndPtr );
1150 wpl.ptMinPosition = WINPOS_FindIconPos( wndPtr, wpl.ptMinPosition );
1152 SetRect( rect, wpl.ptMinPosition.x, wpl.ptMinPosition.y,
1153 GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON) );
1154 swpFlags |= SWP_NOCOPYBITS;
1158 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL );
1160 old_style = WIN_SetStyle( hwnd, (wndPtr->dwStyle & ~WS_MINIMIZE) | WS_MAXIMIZE );
1161 if (old_style & WS_MINIMIZE)
1163 WINPOS_ShowIconTitle( hwnd, FALSE );
1164 X11DRV_set_iconic_state( wndPtr );
1166 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y );
1170 old_style = WIN_SetStyle( hwnd, wndPtr->dwStyle & ~(WS_MINIMIZE|WS_MAXIMIZE) );
1171 if (old_style & WS_MINIMIZE)
1173 WINPOS_ShowIconTitle( hwnd, FALSE );
1174 X11DRV_set_iconic_state( wndPtr );
1176 if( wndPtr->flags & WIN_RESTORE_MAX)
1178 /* Restore to maximized position */
1179 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL);
1180 WIN_SetStyle( hwnd, wndPtr->dwStyle | WS_MAXIMIZE );
1181 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y );
1185 else if (!(old_style & WS_MAXIMIZE)) break;
1187 /* Restore to normal position */
1189 *rect = wpl.rcNormalPosition;
1190 rect->right -= rect->left;
1191 rect->bottom -= rect->top;
1196 WIN_ReleaseWndPtr( wndPtr );
1201 /***********************************************************************
1202 * ShowWindow (X11DRV.@)
1204 BOOL X11DRV_ShowWindow( HWND hwnd, INT cmd )
1206 WND* wndPtr = WIN_FindWndPtr( hwnd );
1207 BOOL wasVisible, showFlag;
1208 RECT newPos = {0, 0, 0, 0};
1211 if (!wndPtr) return FALSE;
1212 hwnd = wndPtr->hwndSelf; /* make it a full handle */
1214 TRACE("hwnd=%04x, cmd=%d\n", hwnd, cmd);
1216 wasVisible = (wndPtr->dwStyle & WS_VISIBLE) != 0;
1221 if (!wasVisible) goto END;
1222 swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE |
1223 SWP_NOACTIVATE | SWP_NOZORDER;
1226 case SW_SHOWMINNOACTIVE:
1227 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1229 case SW_SHOWMINIMIZED:
1230 case SW_FORCEMINIMIZE: /* FIXME: Does not work if thread is hung. */
1231 swp |= SWP_SHOWWINDOW;
1234 swp |= SWP_FRAMECHANGED;
1235 if( !(wndPtr->dwStyle & WS_MINIMIZE) )
1236 swp |= WINPOS_MinMaximize( hwnd, SW_MINIMIZE, &newPos );
1237 else swp |= SWP_NOSIZE | SWP_NOMOVE;
1240 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
1241 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
1242 if( !(wndPtr->dwStyle & WS_MAXIMIZE) )
1243 swp |= WINPOS_MinMaximize( hwnd, SW_MAXIMIZE, &newPos );
1244 else swp |= SWP_NOSIZE | SWP_NOMOVE;
1248 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1251 swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
1254 * ShowWindow has a little peculiar behavior that if the
1255 * window is already the topmost window, it will not
1258 if (GetTopWindow((HWND)0)==hwnd && (wasVisible || GetActiveWindow() == hwnd))
1259 swp |= SWP_NOACTIVATE;
1263 case SW_SHOWNOACTIVATE:
1264 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1266 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
1267 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
1269 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
1271 if( wndPtr->dwStyle & (WS_MINIMIZE | WS_MAXIMIZE) )
1272 swp |= WINPOS_MinMaximize( hwnd, SW_RESTORE, &newPos );
1273 else swp |= SWP_NOSIZE | SWP_NOMOVE;
1277 showFlag = (cmd != SW_HIDE);
1278 if (showFlag != wasVisible)
1280 SendMessageA( hwnd, WM_SHOWWINDOW, showFlag, 0 );
1281 if (!IsWindow( hwnd )) goto END;
1284 /* We can't activate a child window */
1285 if ((wndPtr->dwStyle & WS_CHILD) &&
1286 !(wndPtr->dwExStyle & WS_EX_MDICHILD))
1287 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1289 SetWindowPos( hwnd, HWND_TOP, newPos.left, newPos.top,
1290 newPos.right, newPos.bottom, LOWORD(swp) );
1293 /* FIXME: This will cause the window to be activated irrespective
1294 * of whether it is owned by the same thread. Has to be done
1298 if (hwnd == GetActiveWindow())
1299 WINPOS_ActivateOtherWindow(hwnd);
1301 /* Revert focus to parent */
1302 if (hwnd == GetFocus() || IsChild(hwnd, GetFocus()))
1303 SetFocus( GetParent(hwnd) );
1305 if (!IsWindow( hwnd )) goto END;
1306 else if( wndPtr->dwStyle & WS_MINIMIZE ) WINPOS_ShowIconTitle( hwnd, TRUE );
1308 if (wndPtr->flags & WIN_NEED_SIZE)
1310 /* should happen only in CreateWindowEx() */
1311 int wParam = SIZE_RESTORED;
1313 wndPtr->flags &= ~WIN_NEED_SIZE;
1314 if (wndPtr->dwStyle & WS_MAXIMIZE) wParam = SIZE_MAXIMIZED;
1315 else if (wndPtr->dwStyle & WS_MINIMIZE) wParam = SIZE_MINIMIZED;
1316 SendMessageA( hwnd, WM_SIZE, wParam,
1317 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
1318 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
1319 SendMessageA( hwnd, WM_MOVE, 0,
1320 MAKELONG(wndPtr->rectClient.left, wndPtr->rectClient.top) );
1324 WIN_ReleaseWndPtr(wndPtr);
1329 /**********************************************************************
1332 void X11DRV_MapNotify( HWND hwnd, XMapEvent *event )
1334 HWND hwndFocus = GetFocus();
1337 if (!(win = WIN_GetPtr( hwnd ))) return;
1339 if ((win->dwStyle & WS_VISIBLE) &&
1340 (win->dwStyle & WS_MINIMIZE) &&
1341 (win->dwExStyle & WS_EX_MANAGED))
1344 unsigned int width, height, border, depth;
1347 LONG style = (win->dwStyle & ~(WS_MINIMIZE|WS_MAXIMIZE)) | WS_VISIBLE;
1351 XGetGeometry( event->display, get_whole_window(win), &root, &x, &y, &width, &height,
1353 XTranslateCoordinates( event->display, get_whole_window(win), root, 0, 0, &x, &y, &top );
1354 wine_tsx11_unlock();
1357 rect.right = x + width;
1358 rect.bottom = y + height;
1359 X11DRV_X_to_window_rect( win, &rect );
1361 DCE_InvalidateDCE( hwnd, &win->rectWindow );
1363 if (win->flags & WIN_RESTORE_MAX) style |= WS_MAXIMIZE;
1364 WIN_SetStyle( hwnd, style );
1365 WIN_ReleasePtr( win );
1367 SendMessageA( hwnd, WM_SHOWWINDOW, SW_RESTORE, 0 );
1368 SetWindowPos( hwnd, 0, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
1369 SWP_NOZORDER | SWP_WINE_NOHOSTMOVE );
1371 else WIN_ReleasePtr( win );
1372 if (hwndFocus && IsChild( hwnd, hwndFocus )) X11DRV_SetFocus(hwndFocus); /* FIXME */
1376 /**********************************************************************
1377 * X11DRV_UnmapNotify
1379 void X11DRV_UnmapNotify( HWND hwnd, XUnmapEvent *event )
1383 if (!(win = WIN_GetPtr( hwnd ))) return;
1385 if ((win->dwStyle & WS_VISIBLE) && (win->dwExStyle & WS_EX_MANAGED))
1387 if (win->dwStyle & WS_MAXIMIZE)
1388 win->flags |= WIN_RESTORE_MAX;
1390 win->flags &= ~WIN_RESTORE_MAX;
1392 WIN_SetStyle( hwnd, (win->dwStyle & ~WS_MAXIMIZE) | WS_MINIMIZE );
1393 WIN_ReleasePtr( win );
1396 SendMessageA( hwnd, WM_SHOWWINDOW, SW_MINIMIZE, 0 );
1397 SetWindowPos( hwnd, 0, 0, 0, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON),
1398 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_WINE_NOHOSTMOVE );
1400 else WIN_ReleasePtr( win );
1404 /***********************************************************************
1407 * Synchronize internal z-order with the window manager's.
1409 static Window __get_common_ancestor( Display *display, Window A, Window B,
1410 Window** children, unsigned* total )
1412 /* find the real root window */
1414 Window root, *childrenB;
1417 while( A != B && A && B )
1419 TSXQueryTree( display, A, &root, &A, children, total );
1420 TSXQueryTree( display, B, &root, &B, &childrenB, &totalB );
1421 if( childrenB ) TSXFree( childrenB );
1422 if( *children ) TSXFree( *children ), *children = NULL;
1427 TSXQueryTree( display, A, &root, &B, children, total );
1433 static Window __get_top_decoration( Display *display, Window w, Window ancestor )
1435 Window* children, root, prev = w, parent = w;
1441 TSXQueryTree( display, w, &root, &parent, &children, &total );
1442 if( children ) TSXFree( children );
1443 } while( parent && parent != ancestor );
1444 TRACE("\t%08x -> %08x\n", (unsigned)prev, (unsigned)w );
1445 return ( parent ) ? w : 0 ;
1448 static unsigned __td_lookup( Window w, Window* list, unsigned max )
1451 for( i = max; i > 0; i-- ) if( list[i - 1] == w ) break;
1455 static HWND query_zorder( Display *display, HWND hWndCheck)
1457 HWND hwndInsertAfter = HWND_TOP;
1458 Window w, parent, *children = NULL;
1459 unsigned total, check, pos, best;
1460 HWND *list = WIN_ListChildren( GetDesktopWindow() );
1461 HWND hwndA = 0, hwndB = 0;
1464 /* find at least two managed windows */
1465 if (!list) return 0;
1466 for (i = 0; list[i]; i++)
1468 if (!(GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_MANAGED)) continue;
1469 if (!(GetWindowLongW( list[i], GWL_STYLE ) & WS_VISIBLE)) continue;
1470 if (!hwndA) hwndA = list[i];
1477 if (!hwndA || !hwndB) goto done;
1479 parent = __get_common_ancestor( display, X11DRV_get_whole_window(hwndA),
1480 X11DRV_get_whole_window(hwndB), &children, &total );
1481 if( parent && children )
1483 /* w is the ancestor if hWndCheck that is a direct descendant of 'parent' */
1485 w = __get_top_decoration( display, X11DRV_get_whole_window(hWndCheck), parent );
1487 if( w != children[total-1] ) /* check if at the top */
1489 /* X child at index 0 is at the bottom, at index total-1 is at the top */
1490 check = __td_lookup( w, children, total );
1493 /* go through all windows in Wine z-order... */
1494 for (i = 0; list[i]; i++)
1496 if (list[i] == hWndCheck) continue;
1497 if (!(GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_MANAGED)) continue;
1498 if (!(w = __get_top_decoration( display, X11DRV_get_whole_window(list[i]),
1499 parent ))) continue;
1500 pos = __td_lookup( w, children, total );
1501 if( pos < best && pos > check )
1503 /* find a nearest Wine window precedes hWndCheck in the real z-order */
1505 hwndInsertAfter = list[i];
1507 if( best - check == 1 ) break;
1511 if( children ) TSXFree( children );
1514 HeapFree( GetProcessHeap(), 0, list );
1515 return hwndInsertAfter;
1519 /***********************************************************************
1520 * X11DRV_ConfigureNotify
1522 void X11DRV_ConfigureNotify( HWND hwnd, XConfigureEvent *event )
1524 HWND oldInsertAfter;
1525 struct x11drv_win_data *data;
1529 int x = event->x, y = event->y;
1531 if (!(win = WIN_GetPtr( hwnd ))) return;
1532 data = win->pDriverData;
1536 if (!event->send_event) /* normal event, need to map coordinates to the root */
1540 XTranslateCoordinates( event->display, data->whole_window, root_window,
1541 0, 0, &x, &y, &child );
1542 wine_tsx11_unlock();
1546 rect.right = x + event->width;
1547 rect.bottom = y + event->height;
1548 TRACE( "win %x new X rect %d,%d,%dx%d (event %d,%d,%dx%d)\n",
1549 hwnd, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
1550 event->x, event->y, event->width, event->height );
1551 X11DRV_X_to_window_rect( win, &rect );
1552 WIN_ReleasePtr( win );
1555 winpos.x = rect.left;
1556 winpos.y = rect.top;
1557 winpos.cx = rect.right - rect.left;
1558 winpos.cy = rect.bottom - rect.top;
1559 winpos.flags = SWP_NOACTIVATE;
1561 /* Get Z-order (FIXME) */
1563 winpos.hwndInsertAfter = query_zorder( event->display, hwnd );
1565 /* needs to find the first Visible Window above the current one */
1566 oldInsertAfter = hwnd;
1569 oldInsertAfter = GetWindow( oldInsertAfter, GW_HWNDPREV );
1570 if (!oldInsertAfter)
1572 oldInsertAfter = HWND_TOP;
1575 if (GetWindowLongA( oldInsertAfter, GWL_STYLE ) & WS_VISIBLE) break;
1578 /* Compare what has changed */
1580 GetWindowRect( hwnd, &rect );
1581 if (rect.left == winpos.x && rect.top == winpos.y) winpos.flags |= SWP_NOMOVE;
1583 TRACE( "%04x moving from (%d,%d) to (%d,%d)\n",
1584 hwnd, rect.left, rect.top, winpos.x, winpos.y );
1586 if ((rect.right - rect.left == winpos.cx && rect.bottom - rect.top == winpos.cy) ||
1588 (IsRectEmpty( &rect ) && winpos.cx == 1 && winpos.cy == 1))
1589 winpos.flags |= SWP_NOSIZE;
1591 TRACE( "%04x resizing from (%dx%d) to (%dx%d)\n",
1592 hwnd, rect.right - rect.left, rect.bottom - rect.top,
1593 winpos.cx, winpos.cy );
1595 if (winpos.hwndInsertAfter == oldInsertAfter) winpos.flags |= SWP_NOZORDER;
1597 TRACE( "%04x restacking from after %04x to after %04x\n",
1598 hwnd, oldInsertAfter, winpos.hwndInsertAfter );
1600 /* if nothing changed, don't do anything */
1601 if (winpos.flags == (SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE)) return;
1603 SetWindowPos( hwnd, winpos.hwndInsertAfter, winpos.x, winpos.y,
1604 winpos.cx, winpos.cy, winpos.flags | SWP_WINE_NOHOSTMOVE );
1608 /***********************************************************************
1609 * SetWindowRgn (X11DRV.@)
1611 * Assign specified region to window (for non-rectangular windows)
1613 int X11DRV_SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL redraw )
1617 if ((wndPtr = WIN_GetPtr( hwnd )) == WND_OTHER_PROCESS)
1619 if (IsWindow( hwnd ))
1620 FIXME( "not supported on other process window %x\n", hwnd );
1625 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1629 if (wndPtr->hrgnWnd == hrgn)
1631 WIN_ReleasePtr( wndPtr );
1635 if (wndPtr->hrgnWnd)
1637 /* delete previous region */
1638 DeleteObject(wndPtr->hrgnWnd);
1639 wndPtr->hrgnWnd = 0;
1641 wndPtr->hrgnWnd = hrgn;
1643 #ifdef HAVE_LIBXSHAPE
1645 Display *display = thread_display();
1646 X11DRV_WND_DATA *data = wndPtr->pDriverData;
1648 if (data->whole_window)
1653 XShapeCombineMask( display, data->whole_window,
1654 ShapeBounding, 0, 0, None, ShapeSet );
1655 wine_tsx11_unlock();
1660 int x_offset, y_offset;
1662 DWORD dwBufferSize = GetRegionData(hrgn, 0, NULL);
1663 PRGNDATA pRegionData = HeapAlloc(GetProcessHeap(), 0, dwBufferSize);
1666 WIN_ReleasePtr( wndPtr );
1669 GetRegionData(hrgn, dwBufferSize, pRegionData);
1670 size = pRegionData->rdh.nCount;
1671 x_offset = wndPtr->rectWindow.left - data->whole_rect.left;
1672 y_offset = wndPtr->rectWindow.top - data->whole_rect.top;
1673 /* convert region's "Windows rectangles" to XRectangles */
1674 aXRect = HeapAlloc(GetProcessHeap(), 0, size * sizeof(*aXRect) );
1677 XRectangle* pCurrRect = aXRect;
1678 RECT *pRect = (RECT*) pRegionData->Buffer;
1679 for (; pRect < ((RECT*) pRegionData->Buffer) + size ; ++pRect, ++pCurrRect)
1681 pCurrRect->x = pRect->left + x_offset;
1682 pCurrRect->y = pRect->top + y_offset;
1683 pCurrRect->height = pRect->bottom - pRect->top;
1684 pCurrRect->width = pRect->right - pRect->left;
1686 TRACE("Rectangle %04d of %04ld data: X=%04d, Y=%04d, Height=%04d, Width=%04d.\n",
1687 pRect - (RECT*) pRegionData->Buffer,
1695 /* shape = non-rectangular windows (X11/extensions) */
1697 XShapeCombineRectangles( display, data->whole_window, ShapeBounding,
1699 pCurrRect - aXRect, ShapeSet, YXBanded );
1700 wine_tsx11_unlock();
1701 HeapFree(GetProcessHeap(), 0, aXRect );
1703 HeapFree(GetProcessHeap(), 0, pRegionData);
1707 #endif /* HAVE_LIBXSHAPE */
1709 WIN_ReleasePtr( wndPtr );
1710 if (redraw) RedrawWindow( hwnd, NULL, 0, RDW_FRAME | RDW_INVALIDATE | RDW_ERASE );
1715 /***********************************************************************
1718 * Draw the frame used when moving or resizing window.
1720 * FIXME: This causes problems in Win95 mode. (why?)
1722 static void draw_moving_frame( HDC hdc, RECT *rect, BOOL thickframe )
1726 const int width = GetSystemMetrics(SM_CXFRAME);
1727 const int height = GetSystemMetrics(SM_CYFRAME);
1729 HBRUSH hbrush = SelectObject( hdc, GetStockObject( GRAY_BRUSH ) );
1730 PatBlt( hdc, rect->left, rect->top,
1731 rect->right - rect->left - width, height, PATINVERT );
1732 PatBlt( hdc, rect->left, rect->top + height, width,
1733 rect->bottom - rect->top - height, PATINVERT );
1734 PatBlt( hdc, rect->left + width, rect->bottom - 1,
1735 rect->right - rect->left - width, -height, PATINVERT );
1736 PatBlt( hdc, rect->right - 1, rect->top, -width,
1737 rect->bottom - rect->top - height, PATINVERT );
1738 SelectObject( hdc, hbrush );
1740 else DrawFocusRect( hdc, rect );
1744 /***********************************************************************
1747 * Initialisation of a move or resize, when initiatied from a menu choice.
1748 * Return hit test code for caption or sizing border.
1750 static LONG start_size_move( HWND hwnd, WPARAM wParam, POINT *capturePoint, LONG style )
1757 GetWindowRect( hwnd, &rectWindow );
1759 if ((wParam & 0xfff0) == SC_MOVE)
1761 /* Move pointer at the center of the caption */
1763 NC_GetInsideRect( hwnd, &rect );
1764 if (style & WS_SYSMENU)
1765 rect.left += GetSystemMetrics(SM_CXSIZE) + 1;
1766 if (style & WS_MINIMIZEBOX)
1767 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1768 if (style & WS_MAXIMIZEBOX)
1769 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1770 pt.x = rectWindow.left + (rect.right - rect.left) / 2;
1771 pt.y = rectWindow.top + rect.top + GetSystemMetrics(SM_CYSIZE)/2;
1772 hittest = HTCAPTION;
1779 GetMessageW( &msg, 0, WM_KEYFIRST, WM_MOUSELAST );
1780 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
1785 hittest = NC_HandleNCHitTest( hwnd, msg.pt );
1786 if ((hittest < HTLEFT) || (hittest > HTBOTTOMRIGHT))
1798 pt.x =(rectWindow.left+rectWindow.right)/2;
1799 pt.y = rectWindow.top + GetSystemMetrics(SM_CYFRAME) / 2;
1803 pt.x =(rectWindow.left+rectWindow.right)/2;
1804 pt.y = rectWindow.bottom - GetSystemMetrics(SM_CYFRAME) / 2;
1808 pt.x = rectWindow.left + GetSystemMetrics(SM_CXFRAME) / 2;
1809 pt.y =(rectWindow.top+rectWindow.bottom)/2;
1813 pt.x = rectWindow.right - GetSystemMetrics(SM_CXFRAME) / 2;
1814 pt.y =(rectWindow.top+rectWindow.bottom)/2;
1817 case VK_ESCAPE: return 0;
1823 SetCursorPos( pt.x, pt.y );
1824 NC_HandleSetCursor( hwnd, (WPARAM)hwnd, MAKELONG( hittest, WM_MOUSEMOVE ));
1829 /***********************************************************************
1830 * set_movesize_capture
1832 static void set_movesize_capture( HWND hwnd )
1836 SERVER_START_REQ( set_capture_window )
1839 req->flags = CAPTURE_MOVESIZE;
1840 if (!wine_server_call_err( req ))
1842 previous = reply->previous;
1843 hwnd = reply->full_handle;
1847 if (previous && previous != hwnd)
1848 SendMessageW( previous, WM_CAPTURECHANGED, 0, (LPARAM)hwnd );
1852 /***********************************************************************
1853 * SysCommandSizeMove (X11DRV.@)
1855 * Perform SC_MOVE and SC_SIZE commands.
1857 void X11DRV_SysCommandSizeMove( HWND hwnd, WPARAM wParam )
1860 RECT sizingRect, mouseRect, origRect;
1863 LONG hittest = (LONG)(wParam & 0x0f);
1864 HCURSOR hDragCursor = 0, hOldCursor = 0;
1865 POINT minTrack, maxTrack;
1866 POINT capturePoint, pt;
1867 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
1868 LONG exstyle = GetWindowLongA( hwnd, GWL_EXSTYLE );
1869 BOOL thickframe = HAS_THICKFRAME( style, exstyle );
1870 BOOL iconic = style & WS_MINIMIZE;
1872 DWORD dwPoint = GetMessagePos ();
1873 BOOL DragFullWindows = FALSE;
1876 Display *old_gdi_display = NULL;
1877 Display *display = thread_display();
1879 SystemParametersInfoA(SPI_GETDRAGFULLWINDOWS, 0, &DragFullWindows, 0);
1881 pt.x = SLOWORD(dwPoint);
1882 pt.y = SHIWORD(dwPoint);
1885 if (IsZoomed(hwnd) || !IsWindowVisible(hwnd) || (exstyle & WS_EX_MANAGED)) return;
1887 if ((wParam & 0xfff0) == SC_MOVE)
1889 if (!hittest) hittest = start_size_move( hwnd, wParam, &capturePoint, style );
1890 if (!hittest) return;
1894 if (!thickframe) return;
1895 if ( hittest && hittest != HTSYSMENU ) hittest += 2;
1898 set_movesize_capture( hwnd );
1899 hittest = start_size_move( hwnd, wParam, &capturePoint, style );
1902 set_movesize_capture(0);
1908 /* Get min/max info */
1910 WINPOS_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack );
1911 GetWindowRect( hwnd, &sizingRect );
1912 if (style & WS_CHILD)
1914 parent = GetParent(hwnd);
1915 /* make sizing rect relative to parent */
1916 MapWindowPoints( 0, parent, (POINT*)&sizingRect, 2 );
1917 GetClientRect( parent, &mouseRect );
1922 SetRect(&mouseRect, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
1924 origRect = sizingRect;
1926 if (ON_LEFT_BORDER(hittest))
1928 mouseRect.left = max( mouseRect.left, sizingRect.right-maxTrack.x );
1929 mouseRect.right = min( mouseRect.right, sizingRect.right-minTrack.x );
1931 else if (ON_RIGHT_BORDER(hittest))
1933 mouseRect.left = max( mouseRect.left, sizingRect.left+minTrack.x );
1934 mouseRect.right = min( mouseRect.right, sizingRect.left+maxTrack.x );
1936 if (ON_TOP_BORDER(hittest))
1938 mouseRect.top = max( mouseRect.top, sizingRect.bottom-maxTrack.y );
1939 mouseRect.bottom = min( mouseRect.bottom,sizingRect.bottom-minTrack.y);
1941 else if (ON_BOTTOM_BORDER(hittest))
1943 mouseRect.top = max( mouseRect.top, sizingRect.top+minTrack.y );
1944 mouseRect.bottom = min( mouseRect.bottom, sizingRect.top+maxTrack.y );
1946 if (parent) MapWindowPoints( parent, 0, (LPPOINT)&mouseRect, 2 );
1948 /* Retrieve a default cache DC (without using the window style) */
1949 hdc = GetDCEx( parent, 0, DCX_CACHE );
1951 if( iconic ) /* create a cursor for dragging */
1953 hDragCursor = (HCURSOR)GetClassLongA( hwnd, GCL_HICON);
1954 if( !hDragCursor ) hDragCursor = (HCURSOR)SendMessageA( hwnd, WM_QUERYDRAGICON, 0, 0L);
1955 if( !hDragCursor ) iconic = FALSE;
1958 /* repaint the window before moving it around */
1959 RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN );
1961 SendMessageA( hwnd, WM_ENTERSIZEMOVE, 0, 0 );
1962 set_movesize_capture( hwnd );
1964 /* grab the server only when moving top-level windows without desktop */
1965 grab = (!DragFullWindows && !parent && (root_window == DefaultRootWindow(gdi_display)));
1970 XSync( gdi_display, False );
1971 XGrabServer( display );
1972 XSync( display, False );
1973 /* switch gdi display to the thread display, since the server is grabbed */
1974 old_gdi_display = gdi_display;
1975 gdi_display = display;
1977 XGrabPointer( display, X11DRV_get_whole_window(hwnd), False,
1978 PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
1979 GrabModeAsync, GrabModeAsync,
1980 parent ? X11DRV_get_client_window(parent) : root_window,
1981 None, CurrentTime );
1982 wine_tsx11_unlock();
1988 if (!GetMessageW( &msg, 0, WM_KEYFIRST, WM_MOUSELAST )) break;
1989 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
1991 /* Exit on button-up, Return, or Esc */
1992 if ((msg.message == WM_LBUTTONUP) ||
1993 ((msg.message == WM_KEYDOWN) &&
1994 ((msg.wParam == VK_RETURN) || (msg.wParam == VK_ESCAPE)))) break;
1996 if ((msg.message != WM_KEYDOWN) && (msg.message != WM_MOUSEMOVE))
1997 continue; /* We are not interested in other messages */
2001 if (msg.message == WM_KEYDOWN) switch(msg.wParam)
2003 case VK_UP: pt.y -= 8; break;
2004 case VK_DOWN: pt.y += 8; break;
2005 case VK_LEFT: pt.x -= 8; break;
2006 case VK_RIGHT: pt.x += 8; break;
2009 pt.x = max( pt.x, mouseRect.left );
2010 pt.x = min( pt.x, mouseRect.right );
2011 pt.y = max( pt.y, mouseRect.top );
2012 pt.y = min( pt.y, mouseRect.bottom );
2014 dx = pt.x - capturePoint.x;
2015 dy = pt.y - capturePoint.y;
2023 if( iconic ) /* ok, no system popup tracking */
2025 hOldCursor = SetCursor(hDragCursor);
2027 WINPOS_ShowIconTitle( hwnd, FALSE );
2029 else if(!DragFullWindows)
2030 draw_moving_frame( hdc, &sizingRect, thickframe );
2033 if (msg.message == WM_KEYDOWN) SetCursorPos( pt.x, pt.y );
2036 RECT newRect = sizingRect;
2037 WPARAM wpSizingHit = 0;
2039 if (hittest == HTCAPTION) OffsetRect( &newRect, dx, dy );
2040 if (ON_LEFT_BORDER(hittest)) newRect.left += dx;
2041 else if (ON_RIGHT_BORDER(hittest)) newRect.right += dx;
2042 if (ON_TOP_BORDER(hittest)) newRect.top += dy;
2043 else if (ON_BOTTOM_BORDER(hittest)) newRect.bottom += dy;
2044 if(!iconic && !DragFullWindows) draw_moving_frame( hdc, &sizingRect, thickframe );
2047 /* determine the hit location */
2048 if (hittest >= HTLEFT && hittest <= HTBOTTOMRIGHT)
2049 wpSizingHit = WMSZ_LEFT + (hittest - HTLEFT);
2050 SendMessageA( hwnd, WM_SIZING, wpSizingHit, (LPARAM)&newRect );
2054 if(!DragFullWindows)
2055 draw_moving_frame( hdc, &newRect, thickframe );
2057 /* To avoid any deadlocks, all the locks on the windows
2058 structures must be suspended before the SetWindowPos */
2059 iWndsLocks = WIN_SuspendWndsLock();
2060 SetWindowPos( hwnd, 0, newRect.left, newRect.top,
2061 newRect.right - newRect.left,
2062 newRect.bottom - newRect.top,
2063 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
2064 WIN_RestoreWndsLock(iWndsLocks);
2067 sizingRect = newRect;
2072 set_movesize_capture(0);
2075 if( moved ) /* restore cursors, show icon title later on */
2077 ShowCursor( FALSE );
2078 SetCursor( hOldCursor );
2081 else if (moved && !DragFullWindows)
2082 draw_moving_frame( hdc, &sizingRect, thickframe );
2084 ReleaseDC( parent, hdc );
2087 XUngrabPointer( display, CurrentTime );
2090 XSync( display, False );
2091 XUngrabServer( display );
2092 XSync( display, False );
2093 gdi_display = old_gdi_display;
2095 wine_tsx11_unlock();
2097 if (HOOK_CallHooksA( WH_CBT, HCBT_MOVESIZE, (WPARAM)hwnd, (LPARAM)&sizingRect )) moved = FALSE;
2099 SendMessageA( hwnd, WM_EXITSIZEMOVE, 0, 0 );
2100 SendMessageA( hwnd, WM_SETVISIBLE, !IsIconic(hwnd), 0L);
2102 /* window moved or resized */
2105 /* To avoid any deadlocks, all the locks on the windows
2106 structures must be suspended before the SetWindowPos */
2107 iWndsLocks = WIN_SuspendWndsLock();
2109 /* if the moving/resizing isn't canceled call SetWindowPos
2110 * with the new position or the new size of the window
2112 if (!((msg.message == WM_KEYDOWN) && (msg.wParam == VK_ESCAPE)) )
2114 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
2115 if(!DragFullWindows)
2116 SetWindowPos( hwnd, 0, sizingRect.left, sizingRect.top,
2117 sizingRect.right - sizingRect.left,
2118 sizingRect.bottom - sizingRect.top,
2119 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
2122 { /* restore previous size/position */
2124 SetWindowPos( hwnd, 0, origRect.left, origRect.top,
2125 origRect.right - origRect.left,
2126 origRect.bottom - origRect.top,
2127 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
2130 WIN_RestoreWndsLock(iWndsLocks);
2135 /* Single click brings up the system menu when iconized */
2139 if(style & WS_SYSMENU )
2140 SendMessageA( hwnd, WM_SYSCOMMAND,
2141 SC_MOUSEMENU + HTSYSMENU, MAKELONG(pt.x,pt.y));
2143 else WINPOS_ShowIconTitle( hwnd, TRUE );
2148 /***********************************************************************
2149 * ForceWindowRaise (X11DRV.@)
2151 * Raise a window on top of the X stacking order, while preserving
2152 * the correct Windows Z order.
2154 * FIXME: this should go away.
2156 void X11DRV_ForceWindowRaise( HWND hwnd )
2160 XWindowChanges winChanges;
2161 Display *display = thread_display();
2162 WND *wndPtr = WIN_FindWndPtr( hwnd );
2164 if (!wndPtr) return;
2166 if ((wndPtr->dwExStyle & WS_EX_MANAGED) ||
2167 wndPtr->parent != GetDesktopWindow() ||
2168 IsRectEmpty( &wndPtr->rectWindow ) ||
2169 !get_whole_window(wndPtr))
2171 WIN_ReleaseWndPtr( wndPtr );
2174 WIN_ReleaseWndPtr( wndPtr );
2176 /* Raise all windows up to wndPtr according to their Z order.
2177 * (it would be easier with sibling-related Below but it doesn't
2178 * work very well with SGI mwm for instance)
2180 winChanges.stack_mode = Above;
2181 if (!(list = WIN_ListChildren( GetDesktopWindow() ))) return;
2182 while (list[i] && list[i] != hwnd) i++;
2185 for ( ; i >= 0; i--)
2187 WND *ptr = WIN_FindWndPtr( list[i] );
2189 if (!IsRectEmpty( &ptr->rectWindow ) && get_whole_window(ptr))
2190 TSXReconfigureWMWindow( display, get_whole_window(ptr), 0,
2191 CWStackMode, &winChanges );
2192 WIN_ReleaseWndPtr( ptr );
2195 HeapFree( GetProcessHeap(), 0, list );