Removed WIN_GetDesktop().
[wine/hacks.git] / dlls / x11drv / winpos.c
blob3470ea479e1abbfbfaab9b902a8df51bdd57c72f
1 /*
2 * Window position related functions.
4 * Copyright 1993, 1994, 1995, 2001 Alexandre Julliard
5 * Copyright 1995, 1996, 1999 Alex Korobka
6 */
8 #include "config.h"
10 #include "ts_xlib.h"
11 #include "ts_xutil.h"
12 #include "ts_shape.h"
14 #include "winbase.h"
15 #include "wingdi.h"
16 #include "winuser.h"
18 #include "x11drv.h"
19 #include "hook.h"
20 #include "win.h"
21 #include "winpos.h"
22 #include "region.h"
23 #include "dce.h"
24 #include "cursoricon.h"
25 #include "nonclient.h"
26 #include "message.h"
28 #include "debugtools.h"
30 DEFAULT_DEBUG_CHANNEL(x11drv);
32 #define SWP_AGG_NOGEOMETRYCHANGE \
33 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE)
34 #define SWP_AGG_NOPOSCHANGE \
35 (SWP_AGG_NOGEOMETRYCHANGE | SWP_NOZORDER)
36 #define SWP_AGG_STATUSFLAGS \
37 (SWP_AGG_NOPOSCHANGE | SWP_FRAMECHANGED | SWP_HIDEWINDOW | SWP_SHOWWINDOW)
39 #define SWP_EX_NOCOPY 0x0001
40 #define SWP_EX_PAINTSELF 0x0002
41 #define SWP_EX_NONCLIENT 0x0004
43 #define HAS_THICKFRAME(style,exStyle) \
44 (((style) & WS_THICKFRAME) && \
45 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
47 #define ON_LEFT_BORDER(hit) \
48 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
49 #define ON_RIGHT_BORDER(hit) \
50 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
51 #define ON_TOP_BORDER(hit) \
52 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
53 #define ON_BOTTOM_BORDER(hit) \
54 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
57 /***********************************************************************
58 * clip_children
60 * Clip all children of a given window out of the visible region
62 static int clip_children( WND *win, WND *last, HRGN hrgn, int whole_window )
64 WND *ptr;
65 HRGN rectRgn;
66 int x, y, ret = SIMPLEREGION;
68 /* first check if we have anything to do */
69 for (ptr = win->child; ptr && ptr != last; ptr = ptr->next)
70 if (ptr->dwStyle & WS_VISIBLE) break;
71 if (!ptr || ptr == last) return ret; /* no children to clip */
73 if (whole_window)
75 x = win->rectWindow.left - win->rectClient.left;
76 y = win->rectWindow.top - win->rectClient.top;
78 else x = y = 0;
80 rectRgn = CreateRectRgn( 0, 0, 0, 0 );
81 while (ptr && ptr != last)
83 if (ptr->dwStyle & WS_VISIBLE)
85 SetRectRgn( rectRgn, ptr->rectWindow.left + x, ptr->rectWindow.top + y,
86 ptr->rectWindow.right + x, ptr->rectWindow.bottom + y );
87 if ((ret = CombineRgn( hrgn, hrgn, rectRgn, RGN_DIFF )) == NULLREGION)
88 break; /* no need to go on, region is empty */
90 ptr = ptr->next;
92 DeleteObject( rectRgn );
93 return ret;
97 /***********************************************************************
98 * get_visible_region
100 * Compute the visible region of a window
102 static HRGN get_visible_region( WND *win, WND *top, UINT flags, int mode )
104 HRGN rgn;
105 RECT rect;
106 int xoffset, yoffset;
107 X11DRV_WND_DATA *data = win->pDriverData;
109 if (flags & DCX_WINDOW)
111 xoffset = win->rectWindow.left;
112 yoffset = win->rectWindow.top;
114 else
116 xoffset = win->rectClient.left;
117 yoffset = win->rectClient.top;
120 if (flags & DCX_PARENTCLIP)
121 GetClientRect( win->parent->hwndSelf, &rect );
122 else if (flags & DCX_WINDOW)
123 rect = data->whole_rect;
124 else
125 rect = win->rectClient;
127 /* vis region is relative to the start of the client/window area */
128 OffsetRect( &rect, -xoffset, -yoffset );
130 if (!(rgn = CreateRectRgn( rect.left, rect.top, rect.right, rect.bottom ))) return 0;
132 if ((flags & DCX_CLIPCHILDREN) && (mode != ClipByChildren))
134 /* we need to clip children by hand */
135 if (clip_children( win, NULL, rgn, (flags & DCX_WINDOW) ) == NULLREGION) return rgn;
138 if (top && top != win) /* need to clip siblings of ancestors */
140 WND *ptr = win;
141 HRGN tmp = 0;
143 OffsetRgn( rgn, xoffset, yoffset );
144 for (;;)
146 if (ptr->dwStyle & WS_CLIPSIBLINGS)
148 if (clip_children( ptr->parent, ptr, rgn, FALSE ) == NULLREGION) break;
150 if (ptr == top) break;
151 ptr = ptr->parent;
152 /* clip to parent client area */
153 if (tmp) SetRectRgn( tmp, 0, 0, ptr->rectClient.right - ptr->rectClient.left,
154 ptr->rectClient.bottom - ptr->rectClient.top );
155 else tmp = CreateRectRgn( 0, 0, ptr->rectClient.right - ptr->rectClient.left,
156 ptr->rectClient.bottom - ptr->rectClient.top );
157 CombineRgn( rgn, rgn, tmp, RGN_AND );
158 OffsetRgn( rgn, ptr->rectClient.left, ptr->rectClient.top );
159 xoffset += ptr->rectClient.left;
160 yoffset += ptr->rectClient.top;
162 /* make it relative to the target window again */
163 OffsetRgn( rgn, -xoffset, -yoffset );
164 if (tmp) DeleteObject( tmp );
167 return rgn;
171 /***********************************************************************
172 * get_covered_region
174 * Compute the portion of 'rgn' that is covered by non-clipped siblings.
175 * This is the area that is covered from X point of view, but may still need
176 * to be exposed.
177 * 'rgn' must be relative to the client area of the parent of 'win'.
179 static int get_covered_region( WND *win, HRGN rgn )
181 HRGN tmp;
182 int ret;
183 WND *ptr = win;
184 int xoffset = 0, yoffset = 0;
186 tmp = CreateRectRgn( 0, 0, 0, 0 );
187 CombineRgn( tmp, rgn, 0, RGN_COPY );
189 /* to make things easier we actually build the uncovered
190 * area by removing all siblings and then we subtract that
191 * from the total region to get the covered area */
192 for (;;)
194 if (!(ptr->dwStyle & WS_CLIPSIBLINGS))
196 if (clip_children( ptr->parent, ptr, tmp, FALSE ) == NULLREGION) break;
198 if (!(ptr = ptr->parent)) break;
199 OffsetRgn( tmp, ptr->rectClient.left, ptr->rectClient.top );
200 xoffset += ptr->rectClient.left;
201 yoffset += ptr->rectClient.top;
203 /* make it relative to the target window again */
204 OffsetRgn( tmp, -xoffset, -yoffset );
206 /* now subtract the computed region from the original one */
207 ret = CombineRgn( rgn, rgn, tmp, RGN_DIFF );
208 DeleteObject( tmp );
209 return ret;
213 /***********************************************************************
214 * expose_window
216 * Expose a region of a given window.
218 static void expose_window( WND *win, RECT *rect, HRGN rgn, int flags )
220 WND *ptr, *top;
221 int xoffset = 0, yoffset = 0;
223 /* find the top most parent that doesn't clip children or siblings and
224 * invalidate the area on its parent, including all children */
225 top = NULL;
226 for (ptr = win; ptr && ptr->parent; ptr = ptr->parent)
228 if (!(ptr->dwStyle & WS_CLIPSIBLINGS)) top = ptr;
229 if (!(ptr->parent->dwStyle & WS_CLIPCHILDREN)) top = ptr;
232 if (top)
234 if (top->parent && top->parent->hwndSelf != GetDesktopWindow()) top = top->parent;
235 flags &= ~RDW_FRAME; /* parent will invalidate children frame anyway */
236 flags |= RDW_ALLCHILDREN;
238 else top = win;
240 /* make coords relative to top */
241 for (ptr = win; ptr != top; ptr = ptr->parent)
243 xoffset += ptr->rectClient.left;
244 yoffset += ptr->rectClient.top;
247 if (rect)
249 OffsetRect( rect, xoffset, yoffset );
250 RedrawWindow( top->hwndSelf, rect, 0, flags );
252 else
254 OffsetRgn( rgn, xoffset, yoffset );
255 RedrawWindow( top->hwndSelf, NULL, rgn, flags );
260 /***********************************************************************
261 * expose_covered_parent_area
263 * Expose the parent area that has been uncovered by moving/hiding a
264 * given window, but that is still covered by other siblings (the area
265 * not covered by siblings will be exposed automatically by X).
267 static void expose_covered_parent_area( WND *win, const RECT *old_rect )
269 int ret = SIMPLEREGION;
270 HRGN hrgn = CreateRectRgnIndirect( old_rect );
272 if (win->dwStyle & WS_VISIBLE)
274 HRGN tmp = CreateRectRgnIndirect( &win->rectWindow );
275 ret = CombineRgn( hrgn, hrgn, tmp, RGN_DIFF );
276 DeleteObject( tmp );
279 if (ret != NULLREGION)
281 if (get_covered_region( win, hrgn ) != NULLREGION)
282 expose_window( win->parent, NULL, hrgn, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
284 DeleteObject( hrgn );
288 /***********************************************************************
289 * expose_covered_window_area
291 * Expose the area of a window that is covered by other siblings.
293 static void expose_covered_window_area( WND *win, const RECT *old_client_rect, BOOL frame )
295 HRGN hrgn;
296 int ret = SIMPLEREGION;
298 if (frame)
299 hrgn = CreateRectRgn( win->rectWindow.left - win->rectClient.left,
300 win->rectWindow.top - win->rectClient.top,
301 win->rectWindow.right - win->rectWindow.left,
302 win->rectWindow.bottom - win->rectWindow.top );
303 else
304 hrgn = CreateRectRgn( 0, 0,
305 win->rectClient.right - win->rectClient.left,
306 win->rectClient.bottom - win->rectClient.top );
308 /* if the client rect didn't move we don't need to repaint it all */
309 if (old_client_rect->left == win->rectClient.left &&
310 old_client_rect->top == win->rectClient.top)
312 RECT rc;
314 if (IntersectRect( &rc, old_client_rect, &win->rectClient ))
316 HRGN tmp;
317 /* subtract the unchanged client area from the region to expose */
318 OffsetRect( &rc, -win->rectClient.left, -win->rectClient.top );
319 if ((tmp = CreateRectRgnIndirect( &rc )))
321 ret = CombineRgn( hrgn, hrgn, tmp, RGN_DIFF );
322 DeleteObject( tmp );
327 if (ret != NULLREGION)
329 if (get_covered_region( win, hrgn ) != NULLREGION)
330 expose_window( win, NULL, hrgn,
331 RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN );
334 DeleteObject( hrgn );
338 /***********************************************************************
339 * X11DRV_Expose
341 void X11DRV_Expose( HWND hwnd, XExposeEvent *event )
343 RECT rect;
344 struct x11drv_win_data *data;
345 int flags = RDW_INVALIDATE | RDW_ERASE;
346 WND *win;
348 TRACE( "win %x (%lx) %d,%d %dx%d\n",
349 hwnd, event->window, event->x, event->y, event->width, event->height );
351 rect.left = event->x;
352 rect.top = event->y;
353 rect.right = rect.left + event->width;
354 rect.bottom = rect.top + event->height;
356 if (!(win = WIN_FindWndPtr(hwnd))) return;
357 data = win->pDriverData;
359 if (event->window != data->client_window) /* whole window or icon window */
361 flags |= RDW_FRAME;
362 /* make position relative to client area instead of window */
363 OffsetRect( &rect, -data->client_rect.left, -data->client_rect.top );
366 expose_window( win, &rect, 0, flags );
367 WIN_ReleaseWndPtr( win );
371 /***********************************************************************
372 * GetDC (X11DRV.@)
374 * Set the drawable, origin and dimensions for the DC associated to
375 * a given window.
377 BOOL X11DRV_GetDC( HWND hwnd, HDC hdc, HRGN hrgn, DWORD flags )
379 WND *win = WIN_FindWndPtr( hwnd );
380 WND *ptr, *top;
381 X11DRV_WND_DATA *data = win->pDriverData;
382 Drawable drawable;
383 BOOL visible;
384 int org_x, org_y, mode = IncludeInferiors;
386 /* don't clip siblings if using parent clip region */
387 if (flags & DCX_PARENTCLIP) flags &= ~DCX_CLIPSIBLINGS;
389 /* find the top parent in the hierarchy that isn't clipping siblings */
390 top = NULL;
391 visible = (win->dwStyle & WS_VISIBLE) != 0;
393 if (visible)
395 for (ptr = win->parent; ptr && ptr->parent; ptr = ptr->parent)
397 if (!(ptr->dwStyle & WS_VISIBLE))
399 visible = FALSE;
400 top = NULL;
401 break;
403 if (!(ptr->dwStyle & WS_CLIPSIBLINGS)) top = ptr;
405 if (!top && visible && !(flags & DCX_CLIPSIBLINGS)) top = win;
408 if (top)
410 org_x = org_y = 0;
411 if (flags & DCX_WINDOW)
413 org_x = win->rectWindow.left - win->rectClient.left;
414 org_y = win->rectWindow.top - win->rectClient.top;
416 for (ptr = win; ptr != top->parent; ptr = ptr->parent)
418 org_x += ptr->rectClient.left;
419 org_y += ptr->rectClient.top;
421 /* have to use the parent so that we include siblings */
422 if (top->parent) drawable = get_client_window( top->parent );
423 else drawable = root_window;
425 else
427 if (IsIconic( hwnd ))
429 drawable = data->icon_window ? data->icon_window : data->whole_window;
430 org_x = 0;
431 org_y = 0;
433 else if (flags & DCX_WINDOW)
435 drawable = data->whole_window;
436 org_x = win->rectWindow.left - data->whole_rect.left;
437 org_y = win->rectWindow.top - data->whole_rect.top;
439 else
441 drawable = data->client_window;
442 org_x = 0;
443 org_y = 0;
444 if (flags & DCX_CLIPCHILDREN) mode = ClipByChildren; /* can use X11 clipping */
448 X11DRV_SetDrawable( hdc, drawable, mode, org_x, org_y );
450 if (flags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN) ||
451 SetHookFlags16( hdc, DCHF_VALIDATEVISRGN )) /* DC was dirty */
453 /* need to recompute the visible region */
454 HRGN visRgn;
456 if (visible)
458 visRgn = get_visible_region( win, top, flags, mode );
460 if (flags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN))
461 CombineRgn( visRgn, visRgn, hrgn,
462 (flags & DCX_INTERSECTRGN) ? RGN_AND : RGN_DIFF );
464 /* make it relative to the drawable origin */
465 OffsetRgn( visRgn, org_x, org_y );
467 else visRgn = CreateRectRgn( 0, 0, 0, 0 );
469 SelectVisRgn16( hdc, visRgn );
470 DeleteObject( visRgn );
473 WIN_ReleaseWndPtr( win );
474 return TRUE;
479 /***********************************************************************
480 * SWP_DoWinPosChanging
482 static BOOL SWP_DoWinPosChanging( WINDOWPOS* pWinpos, RECT* pNewWindowRect, RECT* pNewClientRect )
484 WND *wndPtr;
486 /* Send WM_WINDOWPOSCHANGING message */
488 if (!(pWinpos->flags & SWP_NOSENDCHANGING))
489 SendMessageA( pWinpos->hwnd, WM_WINDOWPOSCHANGING, 0, (LPARAM)pWinpos );
491 if (!(wndPtr = WIN_FindWndPtr( pWinpos->hwnd ))) return FALSE;
493 /* Calculate new position and size */
495 *pNewWindowRect = wndPtr->rectWindow;
496 *pNewClientRect = (wndPtr->dwStyle & WS_MINIMIZE) ? wndPtr->rectWindow
497 : wndPtr->rectClient;
499 if (!(pWinpos->flags & SWP_NOSIZE))
501 pNewWindowRect->right = pNewWindowRect->left + pWinpos->cx;
502 pNewWindowRect->bottom = pNewWindowRect->top + pWinpos->cy;
504 if (!(pWinpos->flags & SWP_NOMOVE))
506 pNewWindowRect->left = pWinpos->x;
507 pNewWindowRect->top = pWinpos->y;
508 pNewWindowRect->right += pWinpos->x - wndPtr->rectWindow.left;
509 pNewWindowRect->bottom += pWinpos->y - wndPtr->rectWindow.top;
511 OffsetRect( pNewClientRect, pWinpos->x - wndPtr->rectWindow.left,
512 pWinpos->y - wndPtr->rectWindow.top );
514 pWinpos->flags |= SWP_NOCLIENTMOVE | SWP_NOCLIENTSIZE;
515 WIN_ReleaseWndPtr( wndPtr );
516 return TRUE;
519 /***********************************************************************
520 * SWP_DoNCCalcSize
522 static UINT SWP_DoNCCalcSize( WND* wndPtr, WINDOWPOS* pWinpos,
523 RECT* pNewWindowRect, RECT* pNewClientRect )
525 UINT wvrFlags = 0;
527 /* Send WM_NCCALCSIZE message to get new client area */
528 if( (pWinpos->flags & (SWP_FRAMECHANGED | SWP_NOSIZE)) != SWP_NOSIZE )
530 wvrFlags = WINPOS_SendNCCalcSize( pWinpos->hwnd, TRUE, pNewWindowRect,
531 &wndPtr->rectWindow, &wndPtr->rectClient,
532 pWinpos, pNewClientRect );
533 /* FIXME: WVR_ALIGNxxx */
535 if( pNewClientRect->left != wndPtr->rectClient.left ||
536 pNewClientRect->top != wndPtr->rectClient.top )
537 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
539 if( (pNewClientRect->right - pNewClientRect->left !=
540 wndPtr->rectClient.right - wndPtr->rectClient.left) ||
541 (pNewClientRect->bottom - pNewClientRect->top !=
542 wndPtr->rectClient.bottom - wndPtr->rectClient.top) )
543 pWinpos->flags &= ~SWP_NOCLIENTSIZE;
545 else
546 if( !(pWinpos->flags & SWP_NOMOVE) && (pNewClientRect->left != wndPtr->rectClient.left ||
547 pNewClientRect->top != wndPtr->rectClient.top) )
548 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
549 return wvrFlags;
552 /***********************************************************************
553 * SWP_DoOwnedPopups
555 * fix Z order taking into account owned popups -
556 * basically we need to maintain them above the window that owns them
558 * FIXME: hide/show owned popups when owner visibility changes.
560 static HWND SWP_DoOwnedPopups(WND* pDesktop, WND* wndPtr, HWND hwndInsertAfter, WORD flags)
562 WND *w = WIN_LockWndPtr(pDesktop->child);
564 WARN("(%04x) hInsertAfter = %04x\n", wndPtr->hwndSelf, hwndInsertAfter );
566 if( (wndPtr->dwStyle & WS_POPUP) && wndPtr->owner )
568 /* make sure this popup stays above the owner */
570 HWND hwndLocalPrev = HWND_TOP;
572 if( hwndInsertAfter != HWND_TOP )
574 while( w && w != wndPtr->owner )
576 if (w != wndPtr) hwndLocalPrev = w->hwndSelf;
577 if( hwndLocalPrev == hwndInsertAfter ) break;
578 WIN_UpdateWndPtr(&w,w->next);
580 hwndInsertAfter = hwndLocalPrev;
583 else if( wndPtr->dwStyle & WS_CHILD )
584 goto END;
586 WIN_UpdateWndPtr(&w, pDesktop->child);
588 while( w )
590 if( w == wndPtr ) break;
592 if( (w->dwStyle & WS_POPUP) && w->owner == wndPtr )
594 SetWindowPos(w->hwndSelf, hwndInsertAfter, 0, 0, 0, 0,
595 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING | SWP_DEFERERASE);
596 hwndInsertAfter = w->hwndSelf;
598 WIN_UpdateWndPtr(&w, w->next);
601 END:
602 WIN_ReleaseWndPtr(w);
603 return hwndInsertAfter;
607 /* fix redundant flags and values in the WINDOWPOS structure */
608 static BOOL fixup_flags( WINDOWPOS *winpos )
610 WND *wndPtr = WIN_FindWndPtr( winpos->hwnd );
611 BOOL ret = TRUE;
613 if (!wndPtr) return FALSE;
615 if (wndPtr->dwStyle & WS_VISIBLE) winpos->flags &= ~SWP_SHOWWINDOW;
616 else
618 winpos->flags &= ~SWP_HIDEWINDOW;
619 if (!(winpos->flags & SWP_SHOWWINDOW)) winpos->flags |= SWP_NOREDRAW;
622 if (winpos->cx < 0) winpos->cx = 0;
623 if (winpos->cy < 0) winpos->cy = 0;
625 if ((wndPtr->rectWindow.right - wndPtr->rectWindow.left == winpos->cx) &&
626 (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top == winpos->cy))
627 winpos->flags |= SWP_NOSIZE; /* Already the right size */
629 if ((wndPtr->rectWindow.left == winpos->x) && (wndPtr->rectWindow.top == winpos->y))
630 winpos->flags |= SWP_NOMOVE; /* Already the right position */
632 if (winpos->hwnd == GetForegroundWindow())
633 winpos->flags |= SWP_NOACTIVATE; /* Already active */
634 else if ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD)
636 if (!(winpos->flags & SWP_NOACTIVATE)) /* Bring to the top when activating */
638 winpos->flags &= ~SWP_NOZORDER;
639 winpos->hwndInsertAfter = HWND_TOP;
640 goto done;
644 /* Check hwndInsertAfter */
646 /* FIXME: TOPMOST not supported yet */
647 if ((winpos->hwndInsertAfter == HWND_TOPMOST) ||
648 (winpos->hwndInsertAfter == HWND_NOTOPMOST)) winpos->hwndInsertAfter = HWND_TOP;
650 /* hwndInsertAfter must be a sibling of the window */
651 if ((winpos->hwndInsertAfter != HWND_TOP) && (winpos->hwndInsertAfter != HWND_BOTTOM))
653 WND* wnd = WIN_FindWndPtr(winpos->hwndInsertAfter);
654 if (wnd)
656 if (wnd->parent != wndPtr->parent) ret = FALSE;
657 else
659 /* don't need to change the Zorder of hwnd if it's already inserted
660 * after hwndInsertAfter or when inserting hwnd after itself.
662 if ((wnd->next == wndPtr ) || (winpos->hwnd == winpos->hwndInsertAfter))
663 winpos->flags |= SWP_NOZORDER;
665 WIN_ReleaseWndPtr(wnd);
668 done:
669 WIN_ReleaseWndPtr(wndPtr);
670 return ret;
674 /***********************************************************************
675 * SetWindowPos (X11DRV.@)
677 BOOL X11DRV_SetWindowPos( WINDOWPOS *winpos )
679 WND *wndPtr;
680 RECT newWindowRect, newClientRect;
681 RECT oldWindowRect, oldClientRect;
682 UINT wvrFlags = 0;
683 BOOL bChangePos;
685 TRACE( "hwnd %04x, swp (%i,%i)-(%i,%i) flags %08x\n",
686 winpos->hwnd, winpos->x, winpos->y,
687 winpos->x + winpos->cx, winpos->y + winpos->cy, winpos->flags);
689 bChangePos = !(winpos->flags & SWP_WINE_NOHOSTMOVE);
690 winpos->flags &= ~SWP_WINE_NOHOSTMOVE;
692 /* Check window handle */
693 if (winpos->hwnd == GetDesktopWindow()) return FALSE;
695 /* Fix redundant flags */
696 if (!fixup_flags( winpos )) return FALSE;
698 SWP_DoWinPosChanging( winpos, &newWindowRect, &newClientRect );
700 if (!(wndPtr = WIN_FindWndPtr( winpos->hwnd ))) return FALSE;
702 TRACE("\tcurrent (%i,%i)-(%i,%i), style %08x\n",
703 wndPtr->rectWindow.left, wndPtr->rectWindow.top,
704 wndPtr->rectWindow.right, wndPtr->rectWindow.bottom, (unsigned)wndPtr->dwStyle );
706 if((winpos->flags & (SWP_NOZORDER | SWP_HIDEWINDOW | SWP_SHOWWINDOW)) != SWP_NOZORDER)
708 if( wndPtr->parent->hwndSelf == GetDesktopWindow() )
709 winpos->hwndInsertAfter = SWP_DoOwnedPopups( wndPtr->parent, wndPtr,
710 winpos->hwndInsertAfter, winpos->flags );
713 /* Common operations */
715 wvrFlags = SWP_DoNCCalcSize( wndPtr, winpos, &newWindowRect, &newClientRect );
717 if(!(winpos->flags & SWP_NOZORDER) && winpos->hwnd != winpos->hwndInsertAfter)
719 if ( WIN_UnlinkWindow( winpos->hwnd ) )
720 WIN_LinkWindow( winpos->hwnd, winpos->hwndInsertAfter );
723 /* Reset active DCEs */
725 if( (((winpos->flags & SWP_AGG_NOPOSCHANGE) != SWP_AGG_NOPOSCHANGE) &&
726 wndPtr->dwStyle & WS_VISIBLE) ||
727 (winpos->flags & (SWP_HIDEWINDOW | SWP_SHOWWINDOW)) )
729 RECT rect;
731 UnionRect(&rect, &newWindowRect, &wndPtr->rectWindow);
732 DCE_InvalidateDCE(wndPtr, &rect);
735 oldWindowRect = wndPtr->rectWindow;
736 oldClientRect = wndPtr->rectClient;
738 /* Find out if we have to redraw the whole client rect */
740 if( oldClientRect.bottom - oldClientRect.top ==
741 newClientRect.bottom - newClientRect.top ) wvrFlags &= ~WVR_VREDRAW;
743 if( oldClientRect.right - oldClientRect.left ==
744 newClientRect.right - newClientRect.left ) wvrFlags &= ~WVR_HREDRAW;
746 /* FIXME: actually do something with WVR_VALIDRECTS */
748 wndPtr->rectWindow = newWindowRect;
749 wndPtr->rectClient = newClientRect;
751 if (winpos->flags & SWP_SHOWWINDOW) wndPtr->dwStyle |= WS_VISIBLE;
752 else if (winpos->flags & SWP_HIDEWINDOW)
754 /* clear the update region */
755 RedrawWindow( winpos->hwnd, NULL, 0, RDW_VALIDATE | RDW_NOFRAME | RDW_NOERASE |
756 RDW_NOINTERNALPAINT | RDW_ALLCHILDREN );
757 wndPtr->dwStyle &= ~WS_VISIBLE;
760 if (get_whole_window(wndPtr)) /* don't do anything if X window not created yet */
762 Display *display = thread_display();
764 wine_tsx11_lock();
765 if (!(winpos->flags & SWP_SHOWWINDOW) && (winpos->flags & SWP_HIDEWINDOW))
767 if (!IsRectEmpty( &oldWindowRect ))
769 XUnmapWindow( display, get_whole_window(wndPtr) );
770 TRACE( "unmapping win %x\n", winpos->hwnd );
772 else TRACE( "not unmapping zero size win %x\n", winpos->hwnd );
774 else if ((wndPtr->dwStyle & WS_VISIBLE) &&
775 !IsRectEmpty( &oldWindowRect ) && IsRectEmpty( &newWindowRect ))
777 /* resizing to zero size -> unmap */
778 TRACE( "unmapping zero size win %x\n", winpos->hwnd );
779 XUnmapWindow( display, get_whole_window(wndPtr) );
782 if (bChangePos)
783 X11DRV_sync_whole_window_position( display, wndPtr, !(winpos->flags & SWP_NOZORDER) );
784 else
786 struct x11drv_win_data *data = wndPtr->pDriverData;
787 data->whole_rect = wndPtr->rectWindow;
788 X11DRV_window_to_X_rect( wndPtr, &data->whole_rect );
791 if (X11DRV_sync_client_window_position( display, wndPtr ) ||
792 (winpos->flags & SWP_FRAMECHANGED))
794 /* if we moved the client area, repaint the whole non-client window */
795 XClearArea( display, get_whole_window(wndPtr), 0, 0, 0, 0, True );
796 winpos->flags |= SWP_FRAMECHANGED;
798 if (winpos->flags & SWP_SHOWWINDOW)
800 if (!IsRectEmpty( &newWindowRect ))
802 XMapWindow( display, get_whole_window(wndPtr) );
803 TRACE( "mapping win %x\n", winpos->hwnd );
805 else TRACE( "not mapping win %x, size is zero\n", winpos->hwnd );
807 else if ((wndPtr->dwStyle & WS_VISIBLE) &&
808 IsRectEmpty( &oldWindowRect ) && !IsRectEmpty( &newWindowRect ))
810 /* resizing from zero size to non-zero -> map */
811 TRACE( "mapping non zero size win %x\n", winpos->hwnd );
812 XMapWindow( display, get_whole_window(wndPtr) );
814 XFlush( display ); /* FIXME: should not be necessary */
815 wine_tsx11_unlock();
818 /* manually expose the areas that X won't expose because they are still covered by something */
820 if (!(winpos->flags & SWP_SHOWWINDOW))
821 expose_covered_parent_area( wndPtr, &oldWindowRect );
823 if (wndPtr->dwStyle & WS_VISIBLE)
824 expose_covered_window_area( wndPtr, &oldClientRect, winpos->flags & SWP_FRAMECHANGED );
826 WIN_ReleaseWndPtr(wndPtr);
828 if (wvrFlags & WVR_REDRAW) RedrawWindow( winpos->hwnd, NULL, 0, RDW_INVALIDATE | RDW_ERASE );
830 if (winpos->hwnd == CARET_GetHwnd())
832 if( winpos->flags & SWP_HIDEWINDOW )
833 HideCaret(winpos->hwnd);
834 else if (winpos->flags & SWP_SHOWWINDOW)
835 ShowCaret(winpos->hwnd);
838 if (!(winpos->flags & SWP_NOACTIVATE))
839 WINPOS_ChangeActiveWindow( winpos->hwnd, FALSE );
841 /* And last, send the WM_WINDOWPOSCHANGED message */
843 TRACE("\tstatus flags = %04x\n", winpos->flags & SWP_AGG_STATUSFLAGS);
845 if (((winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOPOSCHANGE) &&
846 !(winpos->flags & SWP_NOSENDCHANGING))
847 SendMessageA( winpos->hwnd, WM_WINDOWPOSCHANGED, 0, (LPARAM)winpos );
849 return TRUE;
853 /***********************************************************************
854 * WINPOS_FindIconPos
856 * Find a suitable place for an iconic window.
858 static POINT WINPOS_FindIconPos( WND* wndPtr, POINT pt )
860 RECT rectParent;
861 short x, y, xspacing, yspacing;
863 GetClientRect( wndPtr->parent->hwndSelf, &rectParent );
864 if ((pt.x >= rectParent.left) && (pt.x + GetSystemMetrics(SM_CXICON) < rectParent.right) &&
865 (pt.y >= rectParent.top) && (pt.y + GetSystemMetrics(SM_CYICON) < rectParent.bottom))
866 return pt; /* The icon already has a suitable position */
868 xspacing = GetSystemMetrics(SM_CXICONSPACING);
869 yspacing = GetSystemMetrics(SM_CYICONSPACING);
871 y = rectParent.bottom;
872 for (;;)
874 x = rectParent.left;
877 /* Check if another icon already occupies this spot */
878 WND *childPtr = WIN_LockWndPtr(wndPtr->parent->child);
879 while (childPtr)
881 if ((childPtr->dwStyle & WS_MINIMIZE) && (childPtr != wndPtr))
883 if ((childPtr->rectWindow.left < x + xspacing) &&
884 (childPtr->rectWindow.right >= x) &&
885 (childPtr->rectWindow.top <= y) &&
886 (childPtr->rectWindow.bottom > y - yspacing))
887 break; /* There's a window in there */
889 WIN_UpdateWndPtr(&childPtr,childPtr->next);
891 WIN_ReleaseWndPtr(childPtr);
892 if (!childPtr) /* No window was found, so it's OK for us */
894 pt.x = x + (xspacing - GetSystemMetrics(SM_CXICON)) / 2;
895 pt.y = y - (yspacing + GetSystemMetrics(SM_CYICON)) / 2;
896 return pt;
898 x += xspacing;
899 } while(x <= rectParent.right-xspacing);
900 y -= yspacing;
908 UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect )
910 WND *wndPtr = WIN_FindWndPtr( hwnd );
911 UINT swpFlags = 0;
912 POINT size;
913 WINDOWPLACEMENT wpl;
915 TRACE("0x%04x %u\n", hwnd, cmd );
917 wpl.length = sizeof(wpl);
918 GetWindowPlacement( hwnd, &wpl );
920 size.x = wndPtr->rectWindow.left;
921 size.y = wndPtr->rectWindow.top;
923 if (!HOOK_CallHooksA(WH_CBT, HCBT_MINMAX, wndPtr->hwndSelf, cmd))
925 if( wndPtr->dwStyle & WS_MINIMIZE )
927 if( !SendMessageA( wndPtr->hwndSelf, WM_QUERYOPEN, 0, 0L ) )
929 swpFlags = SWP_NOSIZE | SWP_NOMOVE;
930 goto done;
932 swpFlags |= SWP_NOCOPYBITS;
934 switch( cmd )
936 case SW_MINIMIZE:
937 if( wndPtr->dwStyle & WS_MAXIMIZE)
939 wndPtr->flags |= WIN_RESTORE_MAX;
940 wndPtr->dwStyle &= ~WS_MAXIMIZE;
942 else
943 wndPtr->flags &= ~WIN_RESTORE_MAX;
944 wndPtr->dwStyle |= WS_MINIMIZE;
946 X11DRV_set_iconic_state( wndPtr );
948 wpl.ptMinPosition = WINPOS_FindIconPos( wndPtr, wpl.ptMinPosition );
950 SetRect( rect, wpl.ptMinPosition.x, wpl.ptMinPosition.y,
951 GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON) );
952 swpFlags |= SWP_NOCOPYBITS;
953 break;
955 case SW_MAXIMIZE:
956 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL );
958 if( wndPtr->dwStyle & WS_MINIMIZE )
960 wndPtr->dwStyle &= ~WS_MINIMIZE;
961 WINPOS_ShowIconTitle( hwnd, FALSE );
962 X11DRV_set_iconic_state( wndPtr );
964 wndPtr->dwStyle |= WS_MAXIMIZE;
966 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y );
967 break;
969 case SW_RESTORE:
970 if( wndPtr->dwStyle & WS_MINIMIZE )
972 wndPtr->dwStyle &= ~WS_MINIMIZE;
973 WINPOS_ShowIconTitle( hwnd, FALSE );
974 X11DRV_set_iconic_state( wndPtr );
976 if( wndPtr->flags & WIN_RESTORE_MAX)
978 /* Restore to maximized position */
979 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL);
980 wndPtr->dwStyle |= WS_MAXIMIZE;
981 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y );
982 break;
985 else
986 if( !(wndPtr->dwStyle & WS_MAXIMIZE) )
988 swpFlags = (UINT16)(-1);
989 goto done;
991 else wndPtr->dwStyle &= ~WS_MAXIMIZE;
993 /* Restore to normal position */
995 *rect = wpl.rcNormalPosition;
996 rect->right -= rect->left;
997 rect->bottom -= rect->top;
999 break;
1001 } else swpFlags |= SWP_NOSIZE | SWP_NOMOVE;
1003 done:
1004 WIN_ReleaseWndPtr( wndPtr );
1005 return swpFlags;
1009 /***********************************************************************
1010 * ShowWindow (X11DRV.@)
1012 BOOL X11DRV_ShowWindow( HWND hwnd, INT cmd )
1014 WND* wndPtr = WIN_FindWndPtr( hwnd );
1015 BOOL wasVisible, showFlag;
1016 RECT newPos = {0, 0, 0, 0};
1017 UINT swp = 0;
1019 if (!wndPtr) return FALSE;
1021 TRACE("hwnd=%04x, cmd=%d\n", hwnd, cmd);
1023 wasVisible = (wndPtr->dwStyle & WS_VISIBLE) != 0;
1025 switch(cmd)
1027 case SW_HIDE:
1028 if (!wasVisible) goto END;;
1029 swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE |
1030 SWP_NOACTIVATE | SWP_NOZORDER;
1031 break;
1033 case SW_SHOWMINNOACTIVE:
1034 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1035 /* fall through */
1036 case SW_SHOWMINIMIZED:
1037 swp |= SWP_SHOWWINDOW;
1038 /* fall through */
1039 case SW_MINIMIZE:
1040 swp |= SWP_FRAMECHANGED;
1041 if( !(wndPtr->dwStyle & WS_MINIMIZE) )
1042 swp |= WINPOS_MinMaximize( hwnd, SW_MINIMIZE, &newPos );
1043 else swp |= SWP_NOSIZE | SWP_NOMOVE;
1044 break;
1046 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
1047 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
1048 if( !(wndPtr->dwStyle & WS_MAXIMIZE) )
1049 swp |= WINPOS_MinMaximize( hwnd, SW_MAXIMIZE, &newPos );
1050 else swp |= SWP_NOSIZE | SWP_NOMOVE;
1051 break;
1053 case SW_SHOWNA:
1054 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1055 /* fall through */
1056 case SW_SHOW:
1057 swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
1060 * ShowWindow has a little peculiar behavior that if the
1061 * window is already the topmost window, it will not
1062 * activate it.
1064 if (GetTopWindow((HWND)0)==hwnd && (wasVisible || GetActiveWindow() == hwnd))
1065 swp |= SWP_NOACTIVATE;
1067 break;
1069 case SW_SHOWNOACTIVATE:
1070 swp |= SWP_NOZORDER;
1071 if (GetActiveWindow()) swp |= SWP_NOACTIVATE;
1072 /* fall through */
1073 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
1074 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
1075 case SW_RESTORE:
1076 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
1078 if( wndPtr->dwStyle & (WS_MINIMIZE | WS_MAXIMIZE) )
1079 swp |= WINPOS_MinMaximize( hwnd, SW_RESTORE, &newPos );
1080 else swp |= SWP_NOSIZE | SWP_NOMOVE;
1081 break;
1084 showFlag = (cmd != SW_HIDE);
1085 if (showFlag != wasVisible)
1087 SendMessageA( hwnd, WM_SHOWWINDOW, showFlag, 0 );
1088 if (!IsWindow( hwnd )) goto END;
1091 /* We can't activate a child window */
1092 if ((wndPtr->dwStyle & WS_CHILD) &&
1093 !(wndPtr->dwExStyle & WS_EX_MDICHILD))
1094 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1096 SetWindowPos( hwnd, HWND_TOP, newPos.left, newPos.top,
1097 newPos.right, newPos.bottom, LOWORD(swp) );
1098 if (cmd == SW_HIDE)
1100 /* FIXME: This will cause the window to be activated irrespective
1101 * of whether it is owned by the same thread. Has to be done
1102 * asynchronously.
1105 if (hwnd == GetActiveWindow())
1106 WINPOS_ActivateOtherWindow(hwnd);
1108 /* Revert focus to parent */
1109 if (hwnd == GetFocus() || IsChild(hwnd, GetFocus()))
1110 SetFocus( GetParent(hwnd) );
1112 if (!IsWindow( hwnd )) goto END;
1113 else if( wndPtr->dwStyle & WS_MINIMIZE ) WINPOS_ShowIconTitle( hwnd, TRUE );
1115 if (wndPtr->flags & WIN_NEED_SIZE)
1117 /* should happen only in CreateWindowEx() */
1118 int wParam = SIZE_RESTORED;
1120 wndPtr->flags &= ~WIN_NEED_SIZE;
1121 if (wndPtr->dwStyle & WS_MAXIMIZE) wParam = SIZE_MAXIMIZED;
1122 else if (wndPtr->dwStyle & WS_MINIMIZE) wParam = SIZE_MINIMIZED;
1123 SendMessageA( hwnd, WM_SIZE, wParam,
1124 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
1125 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
1126 SendMessageA( hwnd, WM_MOVE, 0,
1127 MAKELONG(wndPtr->rectClient.left, wndPtr->rectClient.top) );
1130 END:
1131 WIN_ReleaseWndPtr(wndPtr);
1132 return wasVisible;
1136 /**********************************************************************
1137 * X11DRV_MapNotify
1139 void X11DRV_MapNotify( HWND hwnd, XMapEvent *event )
1141 HWND hwndFocus = GetFocus();
1142 WND *win;
1144 if (!(win = WIN_FindWndPtr( hwnd ))) return;
1146 if ((win->dwStyle & WS_VISIBLE) &&
1147 (win->dwStyle & WS_MINIMIZE) &&
1148 (win->dwExStyle & WS_EX_MANAGED))
1150 int x, y;
1151 unsigned int width, height, border, depth;
1152 Window root, top;
1153 RECT rect;
1155 DCE_InvalidateDCE( win, &win->rectWindow );
1156 win->dwStyle &= ~WS_MINIMIZE;
1157 win->dwStyle |= WS_VISIBLE;
1158 WIN_InternalShowOwnedPopups( hwnd, TRUE, TRUE );
1160 if (win->flags & WIN_RESTORE_MAX)
1161 win->dwStyle |= WS_MAXIMIZE;
1162 else
1163 win->dwStyle &= ~WS_MAXIMIZE;
1165 /* FIXME: hack */
1166 wine_tsx11_lock();
1167 XGetGeometry( event->display, get_whole_window(win), &root, &x, &y, &width, &height,
1168 &border, &depth );
1169 XTranslateCoordinates( event->display, get_whole_window(win), root, 0, 0, &x, &y, &top );
1170 wine_tsx11_unlock();
1171 rect.left = x;
1172 rect.top = y;
1173 rect.right = x + width;
1174 rect.bottom = y + height;
1175 X11DRV_X_to_window_rect( win, &rect );
1177 SendMessageA( hwnd, WM_SHOWWINDOW, SW_RESTORE, 0 );
1178 SetWindowPos( hwnd, 0, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
1179 SWP_NOZORDER | SWP_WINE_NOHOSTMOVE );
1181 if (hwndFocus && IsChild( hwnd, hwndFocus )) X11DRV_SetFocus(hwndFocus); /* FIXME */
1182 WIN_ReleaseWndPtr( win );
1186 /**********************************************************************
1187 * X11DRV_UnmapNotify
1189 void X11DRV_UnmapNotify( HWND hwnd, XUnmapEvent *event )
1191 WND *win;
1193 if (!(win = WIN_FindWndPtr( hwnd ))) return;
1195 if ((win->dwStyle & WS_VISIBLE) && (win->dwExStyle & WS_EX_MANAGED))
1197 EndMenu();
1198 SendMessageA( hwnd, WM_SHOWWINDOW, SW_MINIMIZE, 0 );
1200 win->flags &= ~WIN_RESTORE_MAX;
1201 win->dwStyle |= WS_MINIMIZE;
1203 if (win->dwStyle & WS_MAXIMIZE)
1205 win->flags |= WIN_RESTORE_MAX;
1206 win->dwStyle &= ~WS_MAXIMIZE;
1209 SetWindowPos( hwnd, 0, 0, 0, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON),
1210 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_WINE_NOHOSTMOVE );
1212 WIN_InternalShowOwnedPopups( hwnd, FALSE, TRUE );
1214 WIN_ReleaseWndPtr( win );
1218 /***********************************************************************
1219 * query_zorder
1221 * Synchronize internal z-order with the window manager's.
1223 static BOOL __check_query_condition( WND** pWndA, WND** pWndB )
1225 /* return TRUE if we have at least two managed windows */
1227 for( *pWndB = NULL; *pWndA; *pWndA = (*pWndA)->next )
1228 if( ((*pWndA)->dwExStyle & WS_EX_MANAGED) &&
1229 ((*pWndA)->dwStyle & WS_VISIBLE )) break;
1230 if( *pWndA )
1231 for( *pWndB = (*pWndA)->next; *pWndB; *pWndB = (*pWndB)->next )
1232 if( ((*pWndB)->dwExStyle & WS_EX_MANAGED) &&
1233 ((*pWndB)->dwStyle & WS_VISIBLE )) break;
1234 return ((*pWndB) != NULL);
1237 static Window __get_common_ancestor( Display *display, Window A, Window B,
1238 Window** children, unsigned* total )
1240 /* find the real root window */
1242 Window root, *childrenB;
1243 unsigned totalB;
1245 while( A != B && A && B )
1247 TSXQueryTree( display, A, &root, &A, children, total );
1248 TSXQueryTree( display, B, &root, &B, &childrenB, &totalB );
1249 if( childrenB ) TSXFree( childrenB );
1250 if( *children ) TSXFree( *children ), *children = NULL;
1253 if( A && B )
1255 TSXQueryTree( display, A, &root, &B, children, total );
1256 return A;
1258 return 0 ;
1261 static Window __get_top_decoration( Display *display, Window w, Window ancestor )
1263 Window* children, root, prev = w, parent = w;
1264 unsigned total;
1268 w = parent;
1269 TSXQueryTree( display, w, &root, &parent, &children, &total );
1270 if( children ) TSXFree( children );
1271 } while( parent && parent != ancestor );
1272 TRACE("\t%08x -> %08x\n", (unsigned)prev, (unsigned)w );
1273 return ( parent ) ? w : 0 ;
1276 static unsigned __td_lookup( Window w, Window* list, unsigned max )
1278 unsigned i;
1279 for( i = max - 1; i >= 0; i-- ) if( list[i] == w ) break;
1280 return i;
1283 static HWND query_zorder( Display *display, HWND hWndCheck)
1285 HWND hwndInsertAfter = HWND_TOP;
1286 WND *pWndCheck = WIN_FindWndPtr(hWndCheck);
1287 WND *top = WIN_FindWndPtr( GetTopWindow(0) );
1288 WND *pWnd, *pWndZ = top;
1289 Window w, parent, *children = NULL;
1290 unsigned total, check, pos, best;
1292 if( !__check_query_condition(&pWndZ, &pWnd) )
1294 WIN_ReleaseWndPtr(pWndCheck);
1295 WIN_ReleaseWndPtr(top);
1296 return hwndInsertAfter;
1298 WIN_LockWndPtr(pWndZ);
1299 WIN_LockWndPtr(pWnd);
1300 WIN_ReleaseWndPtr(top);
1302 parent = __get_common_ancestor( display, get_whole_window(pWndZ),
1303 get_whole_window(pWnd), &children, &total );
1304 if( parent && children )
1306 /* w is the ancestor if pWndCheck that is a direct descendant of 'parent' */
1308 w = __get_top_decoration( display, get_whole_window(pWndCheck), parent );
1310 if( w != children[total-1] ) /* check if at the top */
1312 /* X child at index 0 is at the bottom, at index total-1 is at the top */
1313 check = __td_lookup( w, children, total );
1314 best = total;
1316 for( WIN_UpdateWndPtr(&pWnd,pWndZ); pWnd;WIN_UpdateWndPtr(&pWnd,pWnd->next))
1318 /* go through all windows in Wine z-order... */
1320 if( pWnd != pWndCheck )
1322 if( !(pWnd->dwExStyle & WS_EX_MANAGED) ||
1323 !(w = __get_top_decoration( display, get_whole_window(pWnd), parent )) )
1324 continue;
1325 pos = __td_lookup( w, children, total );
1326 if( pos < best && pos > check )
1328 /* find a nearest Wine window precedes
1329 * pWndCheck in the real z-order... */
1330 best = pos;
1331 hwndInsertAfter = pWnd->hwndSelf;
1333 if( best - check == 1 ) break;
1338 if( children ) TSXFree( children );
1339 WIN_ReleaseWndPtr(pWnd);
1340 WIN_ReleaseWndPtr(pWndZ);
1341 WIN_ReleaseWndPtr(pWndCheck);
1342 return hwndInsertAfter;
1346 /***********************************************************************
1347 * X11DRV_ConfigureNotify
1349 void X11DRV_ConfigureNotify( HWND hwnd, XConfigureEvent *event )
1351 HWND oldInsertAfter;
1352 struct x11drv_win_data *data;
1353 WND *win;
1354 RECT rect;
1355 WINDOWPOS winpos;
1356 int x = event->x, y = event->y;
1358 if (!(win = WIN_FindWndPtr( hwnd ))) return;
1359 data = win->pDriverData;
1361 /* Get geometry */
1363 if (!event->send_event) /* normal event, need to map coordinates to the root */
1365 Window child;
1366 wine_tsx11_lock();
1367 XTranslateCoordinates( event->display, data->whole_window, root_window,
1368 0, 0, &x, &y, &child );
1369 wine_tsx11_unlock();
1371 rect.left = x;
1372 rect.top = y;
1373 rect.right = x + event->width;
1374 rect.bottom = y + event->height;
1375 TRACE( "win %x new X rect %d,%d,%dx%d (event %d,%d,%dx%d)\n",
1376 hwnd, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
1377 event->x, event->y, event->width, event->height );
1378 X11DRV_X_to_window_rect( win, &rect );
1379 WIN_ReleaseWndPtr( win );
1381 winpos.hwnd = hwnd;
1382 winpos.x = rect.left;
1383 winpos.y = rect.top;
1384 winpos.cx = rect.right - rect.left;
1385 winpos.cy = rect.bottom - rect.top;
1386 winpos.flags = SWP_NOACTIVATE;
1388 /* Get Z-order (FIXME) */
1390 winpos.hwndInsertAfter = query_zorder( event->display, hwnd );
1392 /* needs to find the first Visible Window above the current one */
1393 oldInsertAfter = hwnd;
1394 for (;;)
1396 oldInsertAfter = GetWindow( oldInsertAfter, GW_HWNDPREV );
1397 if (!oldInsertAfter)
1399 oldInsertAfter = HWND_TOP;
1400 break;
1402 if (GetWindowLongA( oldInsertAfter, GWL_STYLE ) & WS_VISIBLE) break;
1405 /* Compare what has changed */
1407 GetWindowRect( hwnd, &rect );
1408 if (rect.left == winpos.x && rect.top == winpos.y) winpos.flags |= SWP_NOMOVE;
1409 else
1410 TRACE( "%04x moving from (%d,%d) to (%d,%d)\n",
1411 hwnd, rect.left, rect.top, winpos.x, winpos.y );
1413 if (rect.right - rect.left == winpos.cx &&
1414 rect.bottom - rect.top == winpos.cy) winpos.flags |= SWP_NOSIZE;
1415 else
1416 TRACE( "%04x resizing from (%dx%d) to (%dx%d)\n",
1417 hwnd, rect.right - rect.left, rect.bottom - rect.top,
1418 winpos.cx, winpos.cy );
1420 if (winpos.hwndInsertAfter == oldInsertAfter) winpos.flags |= SWP_NOZORDER;
1421 else
1422 TRACE( "%04x restacking from after %04x to after %04x\n",
1423 hwnd, oldInsertAfter, winpos.hwndInsertAfter );
1425 /* if nothing changed, don't do anything */
1426 if (winpos.flags == (SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE)) return;
1428 SetWindowPos( hwnd, winpos.hwndInsertAfter, winpos.x, winpos.y,
1429 winpos.cx, winpos.cy, winpos.flags | SWP_WINE_NOHOSTMOVE );
1433 /***********************************************************************
1434 * SetWindowRgn (X11DRV.@)
1436 * Assign specified region to window (for non-rectangular windows)
1438 BOOL X11DRV_SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL redraw )
1440 RECT rect;
1441 WND *wndPtr = WIN_FindWndPtr(hwnd);
1442 int ret = FALSE;
1444 if (!wndPtr) return FALSE;
1446 if (wndPtr->hrgnWnd == hrgn)
1448 ret = TRUE;
1449 goto done;
1452 if (hrgn) /* verify that region really exists */
1454 if (GetRgnBox( hrgn, &rect ) == ERROR) goto done;
1457 if (wndPtr->hrgnWnd)
1459 /* delete previous region */
1460 DeleteObject(wndPtr->hrgnWnd);
1461 wndPtr->hrgnWnd = 0;
1463 wndPtr->hrgnWnd = hrgn;
1465 #ifdef HAVE_LIBXSHAPE
1467 Display *display = thread_display();
1468 X11DRV_WND_DATA *data = wndPtr->pDriverData;
1470 if (data->whole_window)
1472 if (!hrgn)
1474 TSXShapeCombineMask( display, data->whole_window,
1475 ShapeBounding, 0, 0, None, ShapeSet );
1477 else
1479 XRectangle *aXRect;
1480 int x_offset, y_offset;
1481 DWORD size;
1482 DWORD dwBufferSize = GetRegionData(hrgn, 0, NULL);
1483 PRGNDATA pRegionData = HeapAlloc(GetProcessHeap(), 0, dwBufferSize);
1484 if (!pRegionData) goto done;
1486 GetRegionData(hrgn, dwBufferSize, pRegionData);
1487 size = pRegionData->rdh.nCount;
1488 x_offset = wndPtr->rectWindow.left - data->whole_rect.left;
1489 y_offset = wndPtr->rectWindow.top - data->whole_rect.top;
1490 /* convert region's "Windows rectangles" to XRectangles */
1491 aXRect = HeapAlloc(GetProcessHeap(), 0, size * sizeof(*aXRect) );
1492 if (aXRect)
1494 XRectangle* pCurrRect = aXRect;
1495 RECT *pRect = (RECT*) pRegionData->Buffer;
1496 for (; pRect < ((RECT*) pRegionData->Buffer) + size ; ++pRect, ++pCurrRect)
1498 pCurrRect->x = pRect->left + x_offset;
1499 pCurrRect->y = pRect->top + y_offset;
1500 pCurrRect->height = pRect->bottom - pRect->top;
1501 pCurrRect->width = pRect->right - pRect->left;
1503 TRACE("Rectangle %04d of %04ld data: X=%04d, Y=%04d, Height=%04d, Width=%04d.\n",
1504 pRect - (RECT*) pRegionData->Buffer,
1505 size,
1506 pCurrRect->x,
1507 pCurrRect->y,
1508 pCurrRect->height,
1509 pCurrRect->width);
1512 /* shape = non-rectangular windows (X11/extensions) */
1513 TSXShapeCombineRectangles( display, data->whole_window, ShapeBounding,
1514 0, 0, aXRect,
1515 pCurrRect - aXRect, ShapeSet, YXBanded );
1516 HeapFree(GetProcessHeap(), 0, aXRect );
1518 HeapFree(GetProcessHeap(), 0, pRegionData);
1522 #endif /* HAVE_LIBXSHAPE */
1524 if (redraw) RedrawWindow( hwnd, NULL, 0, RDW_FRAME | RDW_INVALIDATE | RDW_ERASE );
1525 ret = TRUE;
1527 done:
1528 WIN_ReleaseWndPtr(wndPtr);
1529 return ret;
1533 /***********************************************************************
1534 * draw_moving_frame
1536 * Draw the frame used when moving or resizing window.
1538 * FIXME: This causes problems in Win95 mode. (why?)
1540 static void draw_moving_frame( HDC hdc, RECT *rect, BOOL thickframe )
1542 if (thickframe)
1544 const int width = GetSystemMetrics(SM_CXFRAME);
1545 const int height = GetSystemMetrics(SM_CYFRAME);
1547 HBRUSH hbrush = SelectObject( hdc, GetStockObject( GRAY_BRUSH ) );
1548 PatBlt( hdc, rect->left, rect->top,
1549 rect->right - rect->left - width, height, PATINVERT );
1550 PatBlt( hdc, rect->left, rect->top + height, width,
1551 rect->bottom - rect->top - height, PATINVERT );
1552 PatBlt( hdc, rect->left + width, rect->bottom - 1,
1553 rect->right - rect->left - width, -height, PATINVERT );
1554 PatBlt( hdc, rect->right - 1, rect->top, -width,
1555 rect->bottom - rect->top - height, PATINVERT );
1556 SelectObject( hdc, hbrush );
1558 else DrawFocusRect( hdc, rect );
1562 /***********************************************************************
1563 * start_size_move
1565 * Initialisation of a move or resize, when initiatied from a menu choice.
1566 * Return hit test code for caption or sizing border.
1568 static LONG start_size_move( HWND hwnd, WPARAM wParam, POINT *capturePoint, LONG style )
1570 LONG hittest = 0;
1571 POINT pt;
1572 MSG msg;
1573 RECT rectWindow;
1575 GetWindowRect( hwnd, &rectWindow );
1577 if ((wParam & 0xfff0) == SC_MOVE)
1579 /* Move pointer at the center of the caption */
1580 RECT rect;
1581 NC_GetInsideRect( hwnd, &rect );
1582 if (style & WS_SYSMENU)
1583 rect.left += GetSystemMetrics(SM_CXSIZE) + 1;
1584 if (style & WS_MINIMIZEBOX)
1585 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1586 if (style & WS_MAXIMIZEBOX)
1587 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1588 pt.x = rectWindow.left + (rect.right - rect.left) / 2;
1589 pt.y = rectWindow.top + rect.top + GetSystemMetrics(SM_CYSIZE)/2;
1590 hittest = HTCAPTION;
1591 *capturePoint = pt;
1593 else /* SC_SIZE */
1595 while(!hittest)
1597 GetMessageW( &msg, 0, WM_KEYFIRST, WM_MOUSELAST );
1598 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
1600 switch(msg.message)
1602 case WM_MOUSEMOVE:
1603 hittest = NC_HandleNCHitTest( hwnd, msg.pt );
1604 if ((hittest < HTLEFT) || (hittest > HTBOTTOMRIGHT))
1605 hittest = 0;
1606 break;
1608 case WM_LBUTTONUP:
1609 return 0;
1611 case WM_KEYDOWN:
1612 switch(msg.wParam)
1614 case VK_UP:
1615 hittest = HTTOP;
1616 pt.x =(rectWindow.left+rectWindow.right)/2;
1617 pt.y = rectWindow.top + GetSystemMetrics(SM_CYFRAME) / 2;
1618 break;
1619 case VK_DOWN:
1620 hittest = HTBOTTOM;
1621 pt.x =(rectWindow.left+rectWindow.right)/2;
1622 pt.y = rectWindow.bottom - GetSystemMetrics(SM_CYFRAME) / 2;
1623 break;
1624 case VK_LEFT:
1625 hittest = HTLEFT;
1626 pt.x = rectWindow.left + GetSystemMetrics(SM_CXFRAME) / 2;
1627 pt.y =(rectWindow.top+rectWindow.bottom)/2;
1628 break;
1629 case VK_RIGHT:
1630 hittest = HTRIGHT;
1631 pt.x = rectWindow.right - GetSystemMetrics(SM_CXFRAME) / 2;
1632 pt.y =(rectWindow.top+rectWindow.bottom)/2;
1633 break;
1634 case VK_RETURN:
1635 case VK_ESCAPE: return 0;
1639 *capturePoint = pt;
1641 SetCursorPos( pt.x, pt.y );
1642 NC_HandleSetCursor( hwnd, hwnd, MAKELONG( hittest, WM_MOUSEMOVE ));
1643 return hittest;
1647 /***********************************************************************
1648 * SysCommandSizeMove (X11DRV.@)
1650 * Perform SC_MOVE and SC_SIZE commands.
1652 void X11DRV_SysCommandSizeMove( HWND hwnd, WPARAM wParam )
1654 MSG msg;
1655 RECT sizingRect, mouseRect, origRect;
1656 HDC hdc;
1657 HWND parent;
1658 LONG hittest = (LONG)(wParam & 0x0f);
1659 HCURSOR16 hDragCursor = 0, hOldCursor = 0;
1660 POINT minTrack, maxTrack;
1661 POINT capturePoint, pt;
1662 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
1663 LONG exstyle = GetWindowLongA( hwnd, GWL_EXSTYLE );
1664 BOOL thickframe = HAS_THICKFRAME( style, exstyle );
1665 BOOL iconic = style & WS_MINIMIZE;
1666 BOOL moved = FALSE;
1667 DWORD dwPoint = GetMessagePos ();
1668 BOOL DragFullWindows = FALSE;
1669 BOOL grab;
1670 int iWndsLocks;
1671 Display *old_gdi_display = NULL;
1672 Display *display = thread_display();
1674 SystemParametersInfoA(SPI_GETDRAGFULLWINDOWS, 0, &DragFullWindows, 0);
1676 pt.x = SLOWORD(dwPoint);
1677 pt.y = SHIWORD(dwPoint);
1678 capturePoint = pt;
1680 if (IsZoomed(hwnd) || !IsWindowVisible(hwnd) || (exstyle & WS_EX_MANAGED)) return;
1682 if ((wParam & 0xfff0) == SC_MOVE)
1684 if (!hittest) hittest = start_size_move( hwnd, wParam, &capturePoint, style );
1685 if (!hittest) return;
1687 else /* SC_SIZE */
1689 if (!thickframe) return;
1690 if ( hittest && hittest != HTSYSMENU ) hittest += 2;
1691 else
1693 SetCapture(hwnd);
1694 hittest = start_size_move( hwnd, wParam, &capturePoint, style );
1695 if (!hittest)
1697 ReleaseCapture();
1698 return;
1703 /* Get min/max info */
1705 WINPOS_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack );
1706 GetWindowRect( hwnd, &sizingRect );
1707 if (style & WS_CHILD)
1709 parent = GetParent(hwnd);
1710 /* make sizing rect relative to parent */
1711 MapWindowPoints( 0, parent, (POINT*)&sizingRect, 2 );
1712 GetClientRect( parent, &mouseRect );
1714 else
1716 parent = 0;
1717 SetRect(&mouseRect, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
1719 origRect = sizingRect;
1721 if (ON_LEFT_BORDER(hittest))
1723 mouseRect.left = max( mouseRect.left, sizingRect.right-maxTrack.x );
1724 mouseRect.right = min( mouseRect.right, sizingRect.right-minTrack.x );
1726 else if (ON_RIGHT_BORDER(hittest))
1728 mouseRect.left = max( mouseRect.left, sizingRect.left+minTrack.x );
1729 mouseRect.right = min( mouseRect.right, sizingRect.left+maxTrack.x );
1731 if (ON_TOP_BORDER(hittest))
1733 mouseRect.top = max( mouseRect.top, sizingRect.bottom-maxTrack.y );
1734 mouseRect.bottom = min( mouseRect.bottom,sizingRect.bottom-minTrack.y);
1736 else if (ON_BOTTOM_BORDER(hittest))
1738 mouseRect.top = max( mouseRect.top, sizingRect.top+minTrack.y );
1739 mouseRect.bottom = min( mouseRect.bottom, sizingRect.top+maxTrack.y );
1741 if (parent) MapWindowPoints( parent, 0, (LPPOINT)&mouseRect, 2 );
1743 /* Retrieve a default cache DC (without using the window style) */
1744 hdc = GetDCEx( parent, 0, DCX_CACHE );
1746 if( iconic ) /* create a cursor for dragging */
1748 HICON hIcon = GetClassLongA( hwnd, GCL_HICON);
1749 if(!hIcon) hIcon = (HICON)SendMessageA( hwnd, WM_QUERYDRAGICON, 0, 0L);
1750 if( hIcon ) hDragCursor = CURSORICON_IconToCursor( hIcon, TRUE );
1751 if( !hDragCursor ) iconic = FALSE;
1754 /* repaint the window before moving it around */
1755 RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN );
1757 SendMessageA( hwnd, WM_ENTERSIZEMOVE, 0, 0 );
1758 SetCapture( hwnd );
1760 /* grab the server only when moving top-level windows without desktop */
1761 grab = (!DragFullWindows && !parent && (root_window == DefaultRootWindow(gdi_display)));
1763 wine_tsx11_lock();
1764 if (grab)
1766 XSync( gdi_display, False );
1767 XGrabServer( display );
1768 XSync( display, False );
1769 /* switch gdi display to the thread display, since the server is grabbed */
1770 old_gdi_display = gdi_display;
1771 gdi_display = display;
1773 XGrabPointer( display, X11DRV_get_whole_window(hwnd), False,
1774 PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
1775 GrabModeAsync, GrabModeAsync,
1776 parent ? X11DRV_get_client_window(parent) : root_window,
1777 None, CurrentTime );
1778 wine_tsx11_unlock();
1780 while(1)
1782 int dx = 0, dy = 0;
1784 if (!GetMessageW( &msg, 0, WM_KEYFIRST, WM_MOUSELAST )) break;
1785 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
1787 /* Exit on button-up, Return, or Esc */
1788 if ((msg.message == WM_LBUTTONUP) ||
1789 ((msg.message == WM_KEYDOWN) &&
1790 ((msg.wParam == VK_RETURN) || (msg.wParam == VK_ESCAPE)))) break;
1792 if ((msg.message != WM_KEYDOWN) && (msg.message != WM_MOUSEMOVE))
1793 continue; /* We are not interested in other messages */
1795 pt = msg.pt;
1797 if (msg.message == WM_KEYDOWN) switch(msg.wParam)
1799 case VK_UP: pt.y -= 8; break;
1800 case VK_DOWN: pt.y += 8; break;
1801 case VK_LEFT: pt.x -= 8; break;
1802 case VK_RIGHT: pt.x += 8; break;
1805 pt.x = max( pt.x, mouseRect.left );
1806 pt.x = min( pt.x, mouseRect.right );
1807 pt.y = max( pt.y, mouseRect.top );
1808 pt.y = min( pt.y, mouseRect.bottom );
1810 dx = pt.x - capturePoint.x;
1811 dy = pt.y - capturePoint.y;
1813 if (dx || dy)
1815 if( !moved )
1817 moved = TRUE;
1819 if( iconic ) /* ok, no system popup tracking */
1821 hOldCursor = SetCursor(hDragCursor);
1822 ShowCursor( TRUE );
1823 WINPOS_ShowIconTitle( hwnd, FALSE );
1825 else if(!DragFullWindows)
1826 draw_moving_frame( hdc, &sizingRect, thickframe );
1829 if (msg.message == WM_KEYDOWN) SetCursorPos( pt.x, pt.y );
1830 else
1832 RECT newRect = sizingRect;
1833 WPARAM wpSizingHit = 0;
1835 if (hittest == HTCAPTION) OffsetRect( &newRect, dx, dy );
1836 if (ON_LEFT_BORDER(hittest)) newRect.left += dx;
1837 else if (ON_RIGHT_BORDER(hittest)) newRect.right += dx;
1838 if (ON_TOP_BORDER(hittest)) newRect.top += dy;
1839 else if (ON_BOTTOM_BORDER(hittest)) newRect.bottom += dy;
1840 if(!iconic && !DragFullWindows) draw_moving_frame( hdc, &sizingRect, thickframe );
1841 capturePoint = pt;
1843 /* determine the hit location */
1844 if (hittest >= HTLEFT && hittest <= HTBOTTOMRIGHT)
1845 wpSizingHit = WMSZ_LEFT + (hittest - HTLEFT);
1846 SendMessageA( hwnd, WM_SIZING, wpSizingHit, (LPARAM)&newRect );
1848 if (!iconic)
1850 if(!DragFullWindows)
1851 draw_moving_frame( hdc, &newRect, thickframe );
1852 else {
1853 /* To avoid any deadlocks, all the locks on the windows
1854 structures must be suspended before the SetWindowPos */
1855 iWndsLocks = WIN_SuspendWndsLock();
1856 SetWindowPos( hwnd, 0, newRect.left, newRect.top,
1857 newRect.right - newRect.left,
1858 newRect.bottom - newRect.top,
1859 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
1860 WIN_RestoreWndsLock(iWndsLocks);
1863 sizingRect = newRect;
1868 ReleaseCapture();
1869 if( iconic )
1871 if( moved ) /* restore cursors, show icon title later on */
1873 ShowCursor( FALSE );
1874 SetCursor( hOldCursor );
1876 DestroyCursor( hDragCursor );
1878 else if (moved && !DragFullWindows)
1879 draw_moving_frame( hdc, &sizingRect, thickframe );
1881 ReleaseDC( parent, hdc );
1883 wine_tsx11_lock();
1884 XUngrabPointer( display, CurrentTime );
1885 if (grab)
1887 XSync( display, False );
1888 XUngrabServer( display );
1889 XSync( display, False );
1890 gdi_display = old_gdi_display;
1892 wine_tsx11_unlock();
1894 if (HOOK_CallHooksA( WH_CBT, HCBT_MOVESIZE, hwnd, (LPARAM)&sizingRect )) moved = FALSE;
1896 SendMessageA( hwnd, WM_EXITSIZEMOVE, 0, 0 );
1897 SendMessageA( hwnd, WM_SETVISIBLE, !IsIconic(hwnd), 0L);
1899 /* window moved or resized */
1900 if (moved)
1902 /* To avoid any deadlocks, all the locks on the windows
1903 structures must be suspended before the SetWindowPos */
1904 iWndsLocks = WIN_SuspendWndsLock();
1906 /* if the moving/resizing isn't canceled call SetWindowPos
1907 * with the new position or the new size of the window
1909 if (!((msg.message == WM_KEYDOWN) && (msg.wParam == VK_ESCAPE)) )
1911 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
1912 if(!DragFullWindows)
1913 SetWindowPos( hwnd, 0, sizingRect.left, sizingRect.top,
1914 sizingRect.right - sizingRect.left,
1915 sizingRect.bottom - sizingRect.top,
1916 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
1918 else
1919 { /* restore previous size/position */
1920 if(DragFullWindows)
1921 SetWindowPos( hwnd, 0, origRect.left, origRect.top,
1922 origRect.right - origRect.left,
1923 origRect.bottom - origRect.top,
1924 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
1927 WIN_RestoreWndsLock(iWndsLocks);
1930 if (IsIconic(hwnd))
1932 /* Single click brings up the system menu when iconized */
1934 if( !moved )
1936 if(style & WS_SYSMENU )
1937 SendMessageA( hwnd, WM_SYSCOMMAND,
1938 SC_MOUSEMENU + HTSYSMENU, MAKELONG(pt.x,pt.y));
1940 else WINPOS_ShowIconTitle( hwnd, TRUE );
1945 /***********************************************************************
1946 * ForceWindowRaise (X11DRV.@)
1948 * Raise a window on top of the X stacking order, while preserving
1949 * the correct Windows Z order.
1951 * FIXME: this should go away.
1953 void X11DRV_ForceWindowRaise( HWND hwnd )
1955 XWindowChanges winChanges;
1956 Display *display = thread_display();
1957 WND *wndPrev, *wndPtr = WIN_FindWndPtr( hwnd );
1959 if (!wndPtr) return;
1961 if ((wndPtr->dwExStyle & WS_EX_MANAGED) ||
1962 wndPtr->parent->hwndSelf != GetDesktopWindow() ||
1963 IsRectEmpty( &wndPtr->rectWindow ) ||
1964 !get_whole_window(wndPtr))
1966 WIN_ReleaseWndPtr( wndPtr );
1967 return;
1970 /* Raise all windows up to wndPtr according to their Z order.
1971 * (it would be easier with sibling-related Below but it doesn't
1972 * work very well with SGI mwm for instance)
1974 winChanges.stack_mode = Above;
1975 while (wndPtr)
1977 if (!IsRectEmpty( &wndPtr->rectWindow ) && get_whole_window(wndPtr))
1978 TSXReconfigureWMWindow( display, get_whole_window(wndPtr), 0,
1979 CWStackMode, &winChanges );
1980 wndPrev = wndPtr->parent->child;
1981 if (wndPrev == wndPtr) break;
1982 while (wndPrev && (wndPrev->next != wndPtr)) wndPrev = wndPrev->next;
1983 WIN_UpdateWndPtr( &wndPtr, wndPrev );
1985 WIN_ReleaseWndPtr( wndPtr );