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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include <X11/Xutil.h>
27 #include <X11/extensions/shape.h>
28 #endif /* HAVE_LIBXSHAPE */
37 #include "wine/wingdi16.h"
43 #include "wine/server.h"
44 #include "wine/debug.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
48 #define SWP_AGG_NOPOSCHANGE \
49 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_NOZORDER)
50 #define SWP_AGG_STATUSFLAGS \
51 (SWP_AGG_NOPOSCHANGE | SWP_FRAMECHANGED | SWP_HIDEWINDOW | SWP_SHOWWINDOW)
53 #define SWP_EX_NOCOPY 0x0001
54 #define SWP_EX_PAINTSELF 0x0002
55 #define SWP_EX_NONCLIENT 0x0004
57 #define HAS_THICKFRAME(style) \
58 (((style) & WS_THICKFRAME) && \
59 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
61 #define ON_LEFT_BORDER(hit) \
62 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
63 #define ON_RIGHT_BORDER(hit) \
64 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
65 #define ON_TOP_BORDER(hit) \
66 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
67 #define ON_BOTTOM_BORDER(hit) \
68 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
70 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
71 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
72 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
73 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
74 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
75 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
76 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
77 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
78 #define _NET_WM_MOVERESIZE_MOVE 8 /* movement only */
79 #define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9 /* size via keyboard */
80 #define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10 /* move via keyboard */
82 #define _NET_WM_STATE_REMOVE 0
83 #define _NET_WM_STATE_ADD 1
84 #define _NET_WM_STATE_TOGGLE 2
86 /***********************************************************************
89 void X11DRV_Expose( HWND hwnd, XEvent *xev )
91 XExposeEvent *event = &xev->xexpose;
93 struct x11drv_win_data *data;
94 int flags = RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN;
96 TRACE( "win %p (%lx) %d,%d %dx%d\n",
97 hwnd, event->window, event->x, event->y, event->width, event->height );
99 if (!(data = X11DRV_get_win_data( hwnd ))) return;
101 rect.left = event->x;
103 rect.right = rect.left + event->width;
104 rect.bottom = rect.top + event->height;
106 if (rect.left < data->client_rect.left ||
107 rect.top < data->client_rect.top ||
108 rect.right > data->client_rect.right ||
109 rect.bottom > data->client_rect.bottom) flags |= RDW_FRAME;
111 SERVER_START_REQ( update_window_zorder )
114 req->rect.left = rect.left + data->whole_rect.left;
115 req->rect.top = rect.top + data->whole_rect.top;
116 req->rect.right = rect.right + data->whole_rect.left;
117 req->rect.bottom = rect.bottom + data->whole_rect.top;
118 wine_server_call( req );
122 /* make position relative to client area instead of window */
123 OffsetRect( &rect, -data->client_rect.left, -data->client_rect.top );
124 RedrawWindow( hwnd, &rect, 0, flags );
128 /***********************************************************************
129 * SWP_DoWinPosChanging
131 static BOOL SWP_DoWinPosChanging( WINDOWPOS* pWinpos, RECT* pNewWindowRect, RECT* pNewClientRect )
135 /* Send WM_WINDOWPOSCHANGING message */
137 if (!(pWinpos->flags & SWP_NOSENDCHANGING))
138 SendMessageW( pWinpos->hwnd, WM_WINDOWPOSCHANGING, 0, (LPARAM)pWinpos );
140 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) ||
141 wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return FALSE;
143 /* Calculate new position and size */
145 *pNewWindowRect = wndPtr->rectWindow;
146 *pNewClientRect = (wndPtr->dwStyle & WS_MINIMIZE) ? wndPtr->rectWindow
147 : wndPtr->rectClient;
149 if (!(pWinpos->flags & SWP_NOSIZE))
151 pNewWindowRect->right = pNewWindowRect->left + pWinpos->cx;
152 pNewWindowRect->bottom = pNewWindowRect->top + pWinpos->cy;
154 if (!(pWinpos->flags & SWP_NOMOVE))
156 pNewWindowRect->left = pWinpos->x;
157 pNewWindowRect->top = pWinpos->y;
158 pNewWindowRect->right += pWinpos->x - wndPtr->rectWindow.left;
159 pNewWindowRect->bottom += pWinpos->y - wndPtr->rectWindow.top;
161 OffsetRect( pNewClientRect, pWinpos->x - wndPtr->rectWindow.left,
162 pWinpos->y - wndPtr->rectWindow.top );
164 pWinpos->flags |= SWP_NOCLIENTMOVE | SWP_NOCLIENTSIZE;
166 TRACE( "hwnd %p, after %p, swp %d,%d %dx%d flags %08x\n",
167 pWinpos->hwnd, pWinpos->hwndInsertAfter, pWinpos->x, pWinpos->y,
168 pWinpos->cx, pWinpos->cy, pWinpos->flags );
169 TRACE( "current %s style %08lx new %s\n",
170 wine_dbgstr_rect( &wndPtr->rectWindow ), wndPtr->dwStyle,
171 wine_dbgstr_rect( pNewWindowRect ));
173 WIN_ReleasePtr( wndPtr );
178 /***********************************************************************
181 * Compute the valid rects from the old and new client rect and WVR_* flags.
182 * Helper for WM_NCCALCSIZE handling.
184 static inline void get_valid_rects( const RECT *old_client, const RECT *new_client, UINT flags,
189 if (flags & WVR_REDRAW)
191 SetRectEmpty( &valid[0] );
192 SetRectEmpty( &valid[1] );
196 if (flags & WVR_VALIDRECTS)
198 if (!IntersectRect( &valid[0], &valid[0], new_client ) ||
199 !IntersectRect( &valid[1], &valid[1], old_client ))
201 SetRectEmpty( &valid[0] );
202 SetRectEmpty( &valid[1] );
205 flags = WVR_ALIGNLEFT | WVR_ALIGNTOP;
209 valid[0] = *new_client;
210 valid[1] = *old_client;
213 /* make sure the rectangles have the same size */
214 cx = min( valid[0].right - valid[0].left, valid[1].right - valid[1].left );
215 cy = min( valid[0].bottom - valid[0].top, valid[1].bottom - valid[1].top );
217 if (flags & WVR_ALIGNBOTTOM)
219 valid[0].top = valid[0].bottom - cy;
220 valid[1].top = valid[1].bottom - cy;
224 valid[0].bottom = valid[0].top + cy;
225 valid[1].bottom = valid[1].top + cy;
227 if (flags & WVR_ALIGNRIGHT)
229 valid[0].left = valid[0].right - cx;
230 valid[1].left = valid[1].right - cx;
234 valid[0].right = valid[0].left + cx;
235 valid[1].right = valid[1].left + cx;
240 /***********************************************************************
243 static UINT SWP_DoNCCalcSize( WINDOWPOS* pWinpos, const RECT* pNewWindowRect, RECT* pNewClientRect,
249 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
251 /* Send WM_NCCALCSIZE message to get new client area */
252 if( (pWinpos->flags & (SWP_FRAMECHANGED | SWP_NOSIZE)) != SWP_NOSIZE )
254 NCCALCSIZE_PARAMS params;
255 WINDOWPOS winposCopy;
257 params.rgrc[0] = *pNewWindowRect;
258 params.rgrc[1] = wndPtr->rectWindow;
259 params.rgrc[2] = wndPtr->rectClient;
260 params.lppos = &winposCopy;
261 winposCopy = *pWinpos;
262 WIN_ReleasePtr( wndPtr );
264 wvrFlags = SendMessageW( pWinpos->hwnd, WM_NCCALCSIZE, TRUE, (LPARAM)¶ms );
266 *pNewClientRect = params.rgrc[0];
268 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
270 TRACE( "hwnd %p old win %s old client %s new win %s new client %s\n", pWinpos->hwnd,
271 wine_dbgstr_rect(&wndPtr->rectWindow), wine_dbgstr_rect(&wndPtr->rectClient),
272 wine_dbgstr_rect(pNewWindowRect), wine_dbgstr_rect(pNewClientRect) );
274 if( pNewClientRect->left != wndPtr->rectClient.left ||
275 pNewClientRect->top != wndPtr->rectClient.top )
276 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
278 if( (pNewClientRect->right - pNewClientRect->left !=
279 wndPtr->rectClient.right - wndPtr->rectClient.left))
280 pWinpos->flags &= ~SWP_NOCLIENTSIZE;
282 wvrFlags &= ~WVR_HREDRAW;
284 if (pNewClientRect->bottom - pNewClientRect->top !=
285 wndPtr->rectClient.bottom - wndPtr->rectClient.top)
286 pWinpos->flags &= ~SWP_NOCLIENTSIZE;
288 wvrFlags &= ~WVR_VREDRAW;
290 validRects[0] = params.rgrc[1];
291 validRects[1] = params.rgrc[2];
295 if (!(pWinpos->flags & SWP_NOMOVE) &&
296 (pNewClientRect->left != wndPtr->rectClient.left ||
297 pNewClientRect->top != wndPtr->rectClient.top))
298 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
301 if (pWinpos->flags & (SWP_NOCOPYBITS | SWP_NOREDRAW | SWP_SHOWWINDOW | SWP_HIDEWINDOW))
303 SetRectEmpty( &validRects[0] );
304 SetRectEmpty( &validRects[1] );
306 else get_valid_rects( &wndPtr->rectClient, pNewClientRect, wvrFlags, validRects );
308 WIN_ReleasePtr( wndPtr );
313 struct move_owned_info
319 static BOOL CALLBACK move_owned_popups( HWND hwnd, LPARAM lparam )
321 struct move_owned_info *info = (struct move_owned_info *)lparam;
323 if (hwnd == info->owner) return FALSE;
324 if ((GetWindowLongW( hwnd, GWL_STYLE ) & WS_POPUP) &&
325 GetWindow( hwnd, GW_OWNER ) == info->owner)
327 SetWindowPos( hwnd, info->insert_after, 0, 0, 0, 0,
328 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE |
329 SWP_NOSENDCHANGING | SWP_DEFERERASE );
330 info->insert_after = hwnd;
335 /***********************************************************************
338 * fix Z order taking into account owned popups -
339 * basically we need to maintain them above the window that owns them
341 * FIXME: hide/show owned popups when owner visibility changes.
343 static HWND SWP_DoOwnedPopups(HWND hwnd, HWND hwndInsertAfter)
345 HWND owner = GetWindow( hwnd, GW_OWNER );
346 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
347 struct move_owned_info info;
349 TRACE("(%p) hInsertAfter = %p\n", hwnd, hwndInsertAfter );
351 if ((style & WS_POPUP) && owner)
353 /* make sure this popup stays above the owner */
355 if( hwndInsertAfter != HWND_TOP )
357 HWND hwndLocalPrev = HWND_TOP;
358 HWND prev = GetWindow( owner, GW_HWNDPREV );
360 while (prev && prev != hwndInsertAfter)
362 if (hwndLocalPrev == HWND_TOP && GetWindowLongW( prev, GWL_STYLE ) & WS_VISIBLE)
363 hwndLocalPrev = prev;
364 prev = GetWindow( prev, GW_HWNDPREV );
366 if (!prev) hwndInsertAfter = hwndLocalPrev;
369 else if (style & WS_CHILD) return hwndInsertAfter;
372 info.insert_after = hwndInsertAfter;
373 EnumWindows( move_owned_popups, (LPARAM)&info );
374 return info.insert_after;
378 /* fix redundant flags and values in the WINDOWPOS structure */
379 static BOOL fixup_flags( WINDOWPOS *winpos )
382 WND *wndPtr = WIN_GetPtr( winpos->hwnd );
385 if (!wndPtr || wndPtr == WND_OTHER_PROCESS)
387 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
390 winpos->hwnd = wndPtr->hwndSelf; /* make it a full handle */
392 /* Finally make sure that all coordinates are valid */
393 if (winpos->x < -32768) winpos->x = -32768;
394 else if (winpos->x > 32767) winpos->x = 32767;
395 if (winpos->y < -32768) winpos->y = -32768;
396 else if (winpos->y > 32767) winpos->y = 32767;
398 if (winpos->cx < 0) winpos->cx = 0;
399 else if (winpos->cx > 32767) winpos->cx = 32767;
400 if (winpos->cy < 0) winpos->cy = 0;
401 else if (winpos->cy > 32767) winpos->cy = 32767;
403 parent = GetAncestor( winpos->hwnd, GA_PARENT );
404 if (!IsWindowVisible( parent )) winpos->flags |= SWP_NOREDRAW;
406 if (wndPtr->dwStyle & WS_VISIBLE) winpos->flags &= ~SWP_SHOWWINDOW;
409 winpos->flags &= ~SWP_HIDEWINDOW;
410 if (!(winpos->flags & SWP_SHOWWINDOW)) winpos->flags |= SWP_NOREDRAW;
413 if ((wndPtr->rectWindow.right - wndPtr->rectWindow.left == winpos->cx) &&
414 (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top == winpos->cy))
415 winpos->flags |= SWP_NOSIZE; /* Already the right size */
417 if ((wndPtr->rectWindow.left == winpos->x) && (wndPtr->rectWindow.top == winpos->y))
418 winpos->flags |= SWP_NOMOVE; /* Already the right position */
420 if ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD)
422 if (!(winpos->flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW))) /* Bring to the top when activating */
424 winpos->flags &= ~SWP_NOZORDER;
425 winpos->hwndInsertAfter = HWND_TOP;
429 /* Check hwndInsertAfter */
430 if (winpos->flags & SWP_NOZORDER) goto done;
432 /* fix sign extension */
433 if (winpos->hwndInsertAfter == (HWND)0xffff) winpos->hwndInsertAfter = HWND_TOPMOST;
434 else if (winpos->hwndInsertAfter == (HWND)0xfffe) winpos->hwndInsertAfter = HWND_NOTOPMOST;
436 /* FIXME: TOPMOST not supported yet */
437 if ((winpos->hwndInsertAfter == HWND_TOPMOST) ||
438 (winpos->hwndInsertAfter == HWND_NOTOPMOST)) winpos->hwndInsertAfter = HWND_TOP;
440 /* hwndInsertAfter must be a sibling of the window */
441 if (winpos->hwndInsertAfter == HWND_TOP)
443 if (GetWindow(winpos->hwnd, GW_HWNDFIRST) == winpos->hwnd)
444 winpos->flags |= SWP_NOZORDER;
446 else if (winpos->hwndInsertAfter == HWND_BOTTOM)
448 if (GetWindow(winpos->hwnd, GW_HWNDLAST) == winpos->hwnd)
449 winpos->flags |= SWP_NOZORDER;
453 if (GetAncestor( winpos->hwndInsertAfter, GA_PARENT ) != parent) ret = FALSE;
456 /* don't need to change the Zorder of hwnd if it's already inserted
457 * after hwndInsertAfter or when inserting hwnd after itself.
459 if ((winpos->hwnd == winpos->hwndInsertAfter) ||
460 (winpos->hwnd == GetWindow( winpos->hwndInsertAfter, GW_HWNDNEXT )))
461 winpos->flags |= SWP_NOZORDER;
465 WIN_ReleasePtr( wndPtr );
470 /***********************************************************************
471 * SetWindowStyle (X11DRV.@)
473 * Update the X state of a window to reflect a style change
475 void X11DRV_SetWindowStyle( HWND hwnd, DWORD old_style )
477 Display *display = thread_display();
478 struct x11drv_win_data *data;
479 DWORD new_style, changed;
481 if (hwnd == GetDesktopWindow()) return;
482 if (!(data = X11DRV_get_win_data( hwnd ))) return;
484 new_style = GetWindowLongW( hwnd, GWL_STYLE );
485 changed = new_style ^ old_style;
487 if (changed & WS_VISIBLE)
489 if (data->whole_window && X11DRV_is_window_rect_mapped( &data->window_rect ))
491 if (new_style & WS_VISIBLE)
493 TRACE( "mapping win %p\n", hwnd );
494 X11DRV_sync_window_style( display, data );
495 X11DRV_set_wm_hints( display, data );
497 XMapWindow( display, data->whole_window );
500 /* we don't unmap windows, that causes trouble with the window manager */
502 invalidate_dce( hwnd, &data->window_rect );
505 if (changed & WS_DISABLED)
507 if (data->whole_window && data->managed)
511 if (!(wm_hints = XGetWMHints( display, data->whole_window )))
512 wm_hints = XAllocWMHints();
515 wm_hints->flags |= InputHint;
516 wm_hints->input = !(new_style & WS_DISABLED);
517 XSetWMHints( display, data->whole_window, wm_hints );
526 /***********************************************************************
527 * update_fullscreen_state
529 * Use the NETWM protocol to set the fullscreen state.
530 * This only works for mapped windows.
532 static void update_fullscreen_state( Display *display, struct x11drv_win_data *data,
533 const RECT *old_client_rect )
536 BOOL old_fs_state = FALSE, new_fs_state = FALSE;
538 if (old_client_rect->left <= 0 && old_client_rect->right >= screen_width &&
539 old_client_rect->top <= 0 && old_client_rect->bottom >= screen_height)
542 if (data->client_rect.left <= 0 && data->client_rect.right >= screen_width &&
543 data->client_rect.top <= 0 && data->client_rect.bottom >= screen_height)
546 if (new_fs_state == old_fs_state) return;
548 TRACE("setting fullscreen state for hwnd %p to %s\n", data->hwnd, new_fs_state ? "true" : "false");
550 if (data->whole_window)
552 xev.xclient.type = ClientMessage;
553 xev.xclient.window = data->whole_window;
554 xev.xclient.message_type = x11drv_atom(_NET_WM_STATE);
555 xev.xclient.serial = 0;
556 xev.xclient.display = display;
557 xev.xclient.send_event = True;
558 xev.xclient.format = 32;
559 xev.xclient.data.l[0] = new_fs_state ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
560 xev.xclient.data.l[1] = x11drv_atom(_NET_WM_STATE_FULLSCREEN);
561 xev.xclient.data.l[2] = 0;
563 XSendEvent(display, root_window, False, SubstructureRedirectMask | SubstructureNotifyMask, &xev);
569 /***********************************************************************
570 * X11DRV_set_window_pos
572 * Set a window position and Z order.
574 BOOL X11DRV_set_window_pos( HWND hwnd, HWND insert_after, const RECT *rectWindow,
575 const RECT *rectClient, UINT swp_flags, const RECT *valid_rects )
577 struct x11drv_win_data *data;
578 RECT new_whole_rect, old_client_rect;
580 DWORD old_style, new_style;
583 if (!(data = X11DRV_get_win_data( hwnd ))) return FALSE;
585 new_whole_rect = *rectWindow;
586 X11DRV_window_to_X_rect( data, &new_whole_rect );
588 old_client_rect = data->client_rect;
590 if (!IsRectEmpty( &valid_rects[0] ))
592 int x_offset = 0, y_offset = 0;
594 if (data->whole_window)
596 /* the X server will move the bits for us */
597 x_offset = data->whole_rect.left - new_whole_rect.left;
598 y_offset = data->whole_rect.top - new_whole_rect.top;
601 if (x_offset != valid_rects[1].left - valid_rects[0].left ||
602 y_offset != valid_rects[1].top - valid_rects[0].top)
604 /* FIXME: should copy the window bits here */
609 if (!(win = WIN_GetPtr( hwnd ))) return FALSE;
610 if (win == WND_OTHER_PROCESS)
612 if (IsWindow( hwnd )) ERR( "cannot set rectangles of other process window %p\n", hwnd );
615 SERVER_START_REQ( set_window_pos )
618 req->previous = insert_after;
619 req->flags = swp_flags;
620 req->window.left = rectWindow->left;
621 req->window.top = rectWindow->top;
622 req->window.right = rectWindow->right;
623 req->window.bottom = rectWindow->bottom;
624 req->client.left = rectClient->left;
625 req->client.top = rectClient->top;
626 req->client.right = rectClient->right;
627 req->client.bottom = rectClient->bottom;
628 if (memcmp( rectWindow, &new_whole_rect, sizeof(RECT) ) || !IsRectEmpty( &valid_rects[0] ))
630 wine_server_add_data( req, &new_whole_rect, sizeof(new_whole_rect) );
631 if (!IsRectEmpty( &valid_rects[0] ))
632 wine_server_add_data( req, valid_rects, 2 * sizeof(*valid_rects) );
634 ret = !wine_server_call( req );
635 new_style = reply->new_style;
639 if (win == WND_DESKTOP || data->whole_window == DefaultRootWindow(gdi_display))
641 data->whole_rect = data->client_rect = data->window_rect = *rectWindow;
642 if (win != WND_DESKTOP)
644 win->rectWindow = *rectWindow;
645 win->rectClient = *rectClient;
646 win->dwStyle = new_style;
647 WIN_ReleasePtr( win );
654 Display *display = thread_display();
656 /* invalidate DCEs */
658 if ((((swp_flags & SWP_AGG_NOPOSCHANGE) != SWP_AGG_NOPOSCHANGE) && (new_style & WS_VISIBLE)) ||
659 (swp_flags & (SWP_HIDEWINDOW | SWP_SHOWWINDOW)))
662 UnionRect( &rect, rectWindow, &win->rectWindow );
663 invalidate_dce( hwnd, &rect );
666 win->rectWindow = *rectWindow;
667 win->rectClient = *rectClient;
668 old_style = win->dwStyle;
669 win->dwStyle = new_style;
670 data->window_rect = *rectWindow;
672 TRACE( "win %p window %s client %s style %08lx\n",
673 hwnd, wine_dbgstr_rect(rectWindow), wine_dbgstr_rect(rectClient), new_style );
675 /* FIXME: copy the valid bits */
677 if (data->whole_window && !data->lock_changes)
679 if ((old_style & WS_VISIBLE) && !(new_style & WS_VISIBLE))
681 /* window got hidden, unmap it */
682 TRACE( "unmapping win %p\n", hwnd );
684 XUnmapWindow( display, data->whole_window );
687 else if ((new_style & WS_VISIBLE) && !X11DRV_is_window_rect_mapped( rectWindow ))
689 /* resizing to zero size or off screen -> unmap */
690 TRACE( "unmapping zero size or off-screen win %p\n", hwnd );
692 XUnmapWindow( display, data->whole_window );
697 X11DRV_sync_window_position( display, data, swp_flags, rectClient, &new_whole_rect );
699 if (data->whole_window && !data->lock_changes)
701 if ((new_style & WS_VISIBLE) && !(new_style & WS_MINIMIZE) &&
702 X11DRV_is_window_rect_mapped( rectWindow ))
704 if (!(old_style & WS_VISIBLE))
706 /* window got shown, map it */
707 TRACE( "mapping win %p\n", hwnd );
708 X11DRV_sync_window_style( display, data );
709 X11DRV_set_wm_hints( display, data );
711 XMapWindow( display, data->whole_window );
714 else if ((swp_flags & (SWP_NOSIZE | SWP_NOMOVE)) != (SWP_NOSIZE | SWP_NOMOVE))
716 /* resizing from zero size to non-zero -> map */
717 TRACE( "mapping non zero size or off-screen win %p\n", hwnd );
719 XMapWindow( display, data->whole_window );
722 update_fullscreen_state( display, data, &old_client_rect );
726 WIN_ReleasePtr( win );
731 /***********************************************************************
732 * SetWindowPos (X11DRV.@)
734 BOOL X11DRV_SetWindowPos( WINDOWPOS *winpos )
736 RECT newWindowRect, newClientRect, valid_rects[2];
739 TRACE( "hwnd %p, after %p, swp %d,%d %dx%d flags %08x\n",
740 winpos->hwnd, winpos->hwndInsertAfter, winpos->x, winpos->y,
741 winpos->cx, winpos->cy, winpos->flags);
743 orig_flags = winpos->flags;
745 /* First make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
746 if (!(winpos->flags & SWP_NOMOVE))
748 if (winpos->x < -32768) winpos->x = -32768;
749 else if (winpos->x > 32767) winpos->x = 32767;
750 if (winpos->y < -32768) winpos->y = -32768;
751 else if (winpos->y > 32767) winpos->y = 32767;
753 if (!(winpos->flags & SWP_NOSIZE))
755 if (winpos->cx < 0) winpos->cx = 0;
756 else if (winpos->cx > 32767) winpos->cx = 32767;
757 if (winpos->cy < 0) winpos->cy = 0;
758 else if (winpos->cy > 32767) winpos->cy = 32767;
761 if (!SWP_DoWinPosChanging( winpos, &newWindowRect, &newClientRect )) return FALSE;
763 /* Fix redundant flags */
764 if (!fixup_flags( winpos )) return FALSE;
766 if((winpos->flags & (SWP_NOZORDER | SWP_HIDEWINDOW | SWP_SHOWWINDOW)) != SWP_NOZORDER)
768 if (GetAncestor( winpos->hwnd, GA_PARENT ) == GetDesktopWindow())
769 winpos->hwndInsertAfter = SWP_DoOwnedPopups( winpos->hwnd, winpos->hwndInsertAfter );
772 /* Common operations */
774 SWP_DoNCCalcSize( winpos, &newWindowRect, &newClientRect, valid_rects );
776 if (!X11DRV_set_window_pos( winpos->hwnd, winpos->hwndInsertAfter,
777 &newWindowRect, &newClientRect, orig_flags, valid_rects ))
780 if (!(orig_flags & SWP_SHOWWINDOW))
782 UINT rdw_flags = RDW_FRAME | RDW_ERASE;
783 if ( !(orig_flags & SWP_DEFERERASE) ) rdw_flags |= RDW_ERASENOW;
784 RedrawWindow( winpos->hwnd, NULL, NULL, rdw_flags );
787 if( winpos->flags & SWP_HIDEWINDOW )
788 HideCaret(winpos->hwnd);
789 else if (winpos->flags & SWP_SHOWWINDOW)
790 ShowCaret(winpos->hwnd);
792 if (!(winpos->flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW)))
794 /* child windows get WM_CHILDACTIVATE message */
795 if ((GetWindowLongW( winpos->hwnd, GWL_STYLE ) & (WS_CHILD | WS_POPUP)) == WS_CHILD)
796 SendMessageW( winpos->hwnd, WM_CHILDACTIVATE, 0, 0 );
798 SetForegroundWindow( winpos->hwnd );
801 /* And last, send the WM_WINDOWPOSCHANGED message */
803 TRACE("\tstatus flags = %04x\n", winpos->flags & SWP_AGG_STATUSFLAGS);
805 if (((winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOPOSCHANGE))
807 /* WM_WINDOWPOSCHANGED is sent even if SWP_NOSENDCHANGING is set
808 and always contains final window position.
810 winpos->x = newWindowRect.left;
811 winpos->y = newWindowRect.top;
812 winpos->cx = newWindowRect.right - newWindowRect.left;
813 winpos->cy = newWindowRect.bottom - newWindowRect.top;
814 SendMessageW( winpos->hwnd, WM_WINDOWPOSCHANGED, 0, (LPARAM)winpos );
821 /***********************************************************************
824 * Find a suitable place for an iconic window.
826 static POINT WINPOS_FindIconPos( HWND hwnd, POINT pt )
828 RECT rect, rectParent;
831 int xspacing, yspacing;
833 parent = GetAncestor( hwnd, GA_PARENT );
834 GetClientRect( parent, &rectParent );
835 if ((pt.x >= rectParent.left) && (pt.x + GetSystemMetrics(SM_CXICON) < rectParent.right) &&
836 (pt.y >= rectParent.top) && (pt.y + GetSystemMetrics(SM_CYICON) < rectParent.bottom))
837 return pt; /* The icon already has a suitable position */
839 xspacing = GetSystemMetrics(SM_CXICONSPACING);
840 yspacing = GetSystemMetrics(SM_CYICONSPACING);
842 /* Check if another icon already occupies this spot */
843 /* FIXME: this is completely inefficient */
845 hrgn = CreateRectRgn( 0, 0, 0, 0 );
846 tmp = CreateRectRgn( 0, 0, 0, 0 );
847 for (child = GetWindow( parent, GW_HWNDFIRST ); child; child = GetWindow( child, GW_HWNDNEXT ))
850 if (child == hwnd) continue;
851 if ((GetWindowLongW( child, GWL_STYLE ) & (WS_VISIBLE|WS_MINIMIZE)) != (WS_VISIBLE|WS_MINIMIZE))
853 if (!(childPtr = WIN_GetPtr( child )) || childPtr == WND_OTHER_PROCESS)
855 SetRectRgn( tmp, childPtr->rectWindow.left, childPtr->rectWindow.top,
856 childPtr->rectWindow.right, childPtr->rectWindow.bottom );
857 CombineRgn( hrgn, hrgn, tmp, RGN_OR );
858 WIN_ReleasePtr( childPtr );
862 for (rect.bottom = rectParent.bottom; rect.bottom >= yspacing; rect.bottom -= yspacing)
864 for (rect.left = rectParent.left; rect.left <= rectParent.right - xspacing; rect.left += xspacing)
866 rect.right = rect.left + xspacing;
867 rect.top = rect.bottom - yspacing;
868 if (!RectInRegion( hrgn, &rect ))
870 /* No window was found, so it's OK for us */
871 pt.x = rect.left + (xspacing - GetSystemMetrics(SM_CXICON)) / 2;
872 pt.y = rect.top + (yspacing - GetSystemMetrics(SM_CYICON)) / 2;
873 DeleteObject( hrgn );
878 DeleteObject( hrgn );
887 UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect )
895 TRACE("%p %u\n", hwnd, cmd );
897 wpl.length = sizeof(wpl);
898 GetWindowPlacement( hwnd, &wpl );
900 if (HOOK_CallHooks( WH_CBT, HCBT_MINMAX, (WPARAM)hwnd, cmd, TRUE ))
901 return SWP_NOSIZE | SWP_NOMOVE;
903 if (IsIconic( hwnd ))
907 case SW_SHOWMINNOACTIVE:
908 case SW_SHOWMINIMIZED:
909 case SW_FORCEMINIMIZE:
911 return SWP_NOSIZE | SWP_NOMOVE;
913 if (!SendMessageW( hwnd, WM_QUERYOPEN, 0, 0 )) return SWP_NOSIZE | SWP_NOMOVE;
914 swpFlags |= SWP_NOCOPYBITS;
919 case SW_SHOWMINNOACTIVE:
920 case SW_SHOWMINIMIZED:
921 case SW_FORCEMINIMIZE:
923 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
924 if( wndPtr->dwStyle & WS_MAXIMIZE) wndPtr->flags |= WIN_RESTORE_MAX;
925 else wndPtr->flags &= ~WIN_RESTORE_MAX;
926 WIN_ReleasePtr( wndPtr );
928 WIN_SetStyle( hwnd, WS_MINIMIZE, WS_MAXIMIZE );
930 X11DRV_set_iconic_state( hwnd );
932 wpl.ptMinPosition = WINPOS_FindIconPos( hwnd, wpl.ptMinPosition );
934 SetRect( rect, wpl.ptMinPosition.x, wpl.ptMinPosition.y,
935 GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON) );
936 swpFlags |= SWP_NOCOPYBITS;
940 old_style = GetWindowLongW( hwnd, GWL_STYLE );
941 if ((old_style & WS_MAXIMIZE) && (old_style & WS_CHILD)) return SWP_NOSIZE | SWP_NOMOVE;
943 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL );
945 old_style = WIN_SetStyle( hwnd, WS_MAXIMIZE, WS_MINIMIZE );
946 if (old_style & WS_MINIMIZE)
948 WINPOS_ShowIconTitle( hwnd, FALSE );
949 X11DRV_set_iconic_state( hwnd );
951 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y );
955 old_style = WIN_SetStyle( hwnd, 0, WS_MINIMIZE | WS_MAXIMIZE );
956 if (old_style & WS_MINIMIZE)
960 WINPOS_ShowIconTitle( hwnd, FALSE );
961 X11DRV_set_iconic_state( hwnd );
963 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
964 restore_max = (wndPtr->flags & WIN_RESTORE_MAX) != 0;
965 WIN_ReleasePtr( wndPtr );
968 /* Restore to maximized position */
969 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL);
970 WIN_SetStyle( hwnd, WS_MAXIMIZE, 0 );
971 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y );
975 else if (!(old_style & WS_MAXIMIZE)) break;
977 /* Restore to normal position */
979 *rect = wpl.rcNormalPosition;
980 rect->right -= rect->left;
981 rect->bottom -= rect->top;
990 /***********************************************************************
991 * ShowWindow (X11DRV.@)
993 BOOL X11DRV_ShowWindow( HWND hwnd, INT cmd )
997 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
998 BOOL wasVisible = (style & WS_VISIBLE) != 0;
999 BOOL showFlag = TRUE, state_change = FALSE;
1000 RECT newPos = {0, 0, 0, 0};
1003 TRACE("hwnd=%p, cmd=%d, wasVisible %d\n", hwnd, cmd, wasVisible);
1008 if (!wasVisible) return FALSE;
1010 swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE;
1011 if (hwnd != GetActiveWindow())
1012 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1015 case SW_SHOWMINNOACTIVE:
1016 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1019 case SW_FORCEMINIMIZE: /* FIXME: Does not work if thread is hung. */
1020 if (style & WS_CHILD) swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1022 case SW_SHOWMINIMIZED:
1023 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
1024 swp |= WINPOS_MinMaximize( hwnd, cmd, &newPos );
1025 if (style & WS_MINIMIZE) return wasVisible;
1026 state_change = TRUE;
1029 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
1030 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
1031 swp |= WINPOS_MinMaximize( hwnd, SW_MAXIMIZE, &newPos );
1032 if ((style & WS_MAXIMIZE) && (style & WS_CHILD)) return wasVisible;
1033 state_change = TRUE;
1037 swp |= SWP_NOACTIVATE | SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
1038 if (style & WS_CHILD) swp |= SWP_NOZORDER;
1041 if (wasVisible) return TRUE;
1042 swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
1043 if (style & WS_CHILD) swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1047 swp |= SWP_FRAMECHANGED;
1048 state_change = TRUE;
1050 case SW_SHOWNOACTIVATE:
1051 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1053 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
1054 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
1055 swp |= SWP_SHOWWINDOW;
1056 if (style & (WS_MINIMIZE | WS_MAXIMIZE))
1057 swp |= WINPOS_MinMaximize( hwnd, SW_RESTORE, &newPos );
1058 else swp |= SWP_NOSIZE | SWP_NOMOVE;
1059 if (style & WS_CHILD) swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1063 if ((showFlag != wasVisible || cmd == SW_SHOWNA) && !state_change)
1065 SendMessageW( hwnd, WM_SHOWWINDOW, showFlag, 0 );
1066 if (!IsWindow( hwnd )) return wasVisible;
1069 parent = GetAncestor( hwnd, GA_PARENT );
1070 if (parent && !IsWindowVisible( parent ) && !state_change)
1072 /* if parent is not visible simply toggle WS_VISIBLE and return */
1073 if (showFlag) WIN_SetStyle( hwnd, WS_VISIBLE, 0 );
1074 else WIN_SetStyle( hwnd, 0, WS_VISIBLE );
1078 if (style & WS_CHILD)
1082 /* it appears that Windows always adds an undocumented 0x8000
1083 * flag if the state of a window changes.
1085 swp |= SWP_STATECHANGED;
1089 SetWindowPos( hwnd, HWND_TOP, newPos.left, newPos.top,
1090 newPos.right, newPos.bottom, LOWORD(swp) );
1097 /* FIXME: This will cause the window to be activated irrespective
1098 * of whether it is owned by the same thread. Has to be done
1102 if (hwnd == GetActiveWindow())
1103 WINPOS_ActivateOtherWindow(hwnd);
1105 /* Revert focus to parent */
1106 hFocus = GetFocus();
1107 if (hwnd == hFocus || IsChild(hwnd, hFocus))
1109 HWND parent = GetAncestor(hwnd, GA_PARENT);
1110 if (parent == GetDesktopWindow()) parent = 0;
1115 if (IsIconic(hwnd)) WINPOS_ShowIconTitle( hwnd, TRUE );
1117 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return wasVisible;
1119 if (wndPtr->flags & WIN_NEED_SIZE)
1121 /* should happen only in CreateWindowEx() */
1122 int wParam = SIZE_RESTORED;
1123 RECT client = wndPtr->rectClient;
1125 wndPtr->flags &= ~WIN_NEED_SIZE;
1126 if (wndPtr->dwStyle & WS_MAXIMIZE) wParam = SIZE_MAXIMIZED;
1127 else if (wndPtr->dwStyle & WS_MINIMIZE) wParam = SIZE_MINIMIZED;
1128 WIN_ReleasePtr( wndPtr );
1130 SendMessageW( hwnd, WM_SIZE, wParam,
1131 MAKELONG( client.right - client.left, client.bottom - client.top ));
1132 SendMessageW( hwnd, WM_MOVE, 0, MAKELONG( client.left, client.top ));
1134 else WIN_ReleasePtr( wndPtr );
1140 /**********************************************************************
1143 void X11DRV_MapNotify( HWND hwnd, XEvent *event )
1145 struct x11drv_win_data *data;
1146 HWND hwndFocus = GetFocus();
1149 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1151 if (!(win = WIN_GetPtr( hwnd ))) return;
1153 if (data->managed && (win->dwStyle & WS_VISIBLE) && (win->dwStyle & WS_MINIMIZE))
1156 unsigned int width, height, border, depth;
1159 LONG style = WS_VISIBLE;
1163 XGetGeometry( event->xmap.display, data->whole_window, &root, &x, &y, &width, &height,
1165 XTranslateCoordinates( event->xmap.display, data->whole_window, root, 0, 0, &x, &y, &top );
1166 wine_tsx11_unlock();
1169 rect.right = x + width;
1170 rect.bottom = y + height;
1171 X11DRV_X_to_window_rect( data, &rect );
1173 invalidate_dce( hwnd, &data->window_rect );
1175 if (win->flags & WIN_RESTORE_MAX) style |= WS_MAXIMIZE;
1176 WIN_SetStyle( hwnd, style, WS_MINIMIZE );
1177 WIN_ReleasePtr( win );
1179 SendMessageW( hwnd, WM_SHOWWINDOW, SW_RESTORE, 0 );
1180 data->lock_changes++;
1181 SetWindowPos( hwnd, 0, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
1183 data->lock_changes--;
1185 else WIN_ReleasePtr( win );
1186 if (hwndFocus && IsChild( hwnd, hwndFocus )) X11DRV_SetFocus(hwndFocus); /* FIXME */
1190 /**********************************************************************
1191 * X11DRV_UnmapNotify
1193 void X11DRV_UnmapNotify( HWND hwnd, XEvent *event )
1195 struct x11drv_win_data *data;
1198 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1200 if (!(win = WIN_GetPtr( hwnd ))) return;
1202 if ((win->dwStyle & WS_VISIBLE) && data->managed &&
1203 X11DRV_is_window_rect_mapped( &win->rectWindow ))
1205 if (win->dwStyle & WS_MAXIMIZE)
1206 win->flags |= WIN_RESTORE_MAX;
1208 win->flags &= ~WIN_RESTORE_MAX;
1210 WIN_SetStyle( hwnd, WS_MINIMIZE, WS_MAXIMIZE );
1211 WIN_ReleasePtr( win );
1214 SendMessageW( hwnd, WM_SHOWWINDOW, SW_MINIMIZE, 0 );
1215 data->lock_changes++;
1216 SetWindowPos( hwnd, 0, 0, 0, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON),
1217 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER );
1218 data->lock_changes--;
1220 else WIN_ReleasePtr( win );
1224 /***********************************************************************
1225 * X11DRV_handle_desktop_resize
1227 void X11DRV_handle_desktop_resize( unsigned int width, unsigned int height )
1230 HWND hwnd = GetDesktopWindow();
1231 struct x11drv_win_data *data;
1233 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1234 screen_width = width;
1235 screen_height = height;
1236 TRACE("desktop %p change to (%dx%d)\n", hwnd, width, height);
1237 SetRect( &rect, 0, 0, width, height );
1238 data->lock_changes++;
1239 X11DRV_set_window_pos( hwnd, 0, &rect, &rect, SWP_NOZORDER|SWP_NOMOVE, NULL );
1240 data->lock_changes--;
1241 SendMessageTimeoutW( HWND_BROADCAST, WM_DISPLAYCHANGE, screen_depth,
1242 MAKELPARAM( width, height ), SMTO_ABORTIFHUNG, 2000, NULL );
1246 /***********************************************************************
1247 * X11DRV_ConfigureNotify
1249 void X11DRV_ConfigureNotify( HWND hwnd, XEvent *xev )
1251 XConfigureEvent *event = &xev->xconfigure;
1252 struct x11drv_win_data *data;
1255 int cx, cy, x = event->x, y = event->y;
1258 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1262 if (!event->send_event) /* normal event, need to map coordinates to the root */
1266 XTranslateCoordinates( event->display, data->whole_window, root_window,
1267 0, 0, &x, &y, &child );
1268 wine_tsx11_unlock();
1272 rect.right = x + event->width;
1273 rect.bottom = y + event->height;
1274 TRACE( "win %p new X rect %ld,%ld,%ldx%ld (event %d,%d,%dx%d)\n",
1275 hwnd, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
1276 event->x, event->y, event->width, event->height );
1277 X11DRV_X_to_window_rect( data, &rect );
1281 cx = rect.right - rect.left;
1282 cy = rect.bottom - rect.top;
1283 flags = SWP_NOACTIVATE | SWP_NOZORDER;
1285 /* Compare what has changed */
1287 GetWindowRect( hwnd, &rect );
1288 if (rect.left == x && rect.top == y) flags |= SWP_NOMOVE;
1290 TRACE( "%p moving from (%ld,%ld) to (%d,%d)\n",
1291 hwnd, rect.left, rect.top, x, y );
1293 if ((rect.right - rect.left == cx && rect.bottom - rect.top == cy) ||
1295 (IsRectEmpty( &rect ) && event->width == 1 && event->height == 1))
1297 if (flags & SWP_NOMOVE) return; /* if nothing changed, don't do anything */
1298 flags |= SWP_NOSIZE;
1301 TRACE( "%p resizing from (%ldx%ld) to (%dx%d)\n",
1302 hwnd, rect.right - rect.left, rect.bottom - rect.top, cx, cy );
1304 data->lock_changes++;
1305 SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
1306 data->lock_changes--;
1310 /***********************************************************************
1311 * SetWindowRgn (X11DRV.@)
1313 * Assign specified region to window (for non-rectangular windows)
1315 int X11DRV_SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL redraw )
1317 struct x11drv_win_data *data;
1319 if (!(data = X11DRV_get_win_data( hwnd )))
1321 if (IsWindow( hwnd ))
1322 FIXME( "not supported on other thread window %p\n", hwnd );
1323 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1327 #ifdef HAVE_LIBXSHAPE
1328 if (data->whole_window)
1330 Display *display = thread_display();
1335 XShapeCombineMask( display, data->whole_window,
1336 ShapeBounding, 0, 0, None, ShapeSet );
1337 wine_tsx11_unlock();
1341 RGNDATA *pRegionData = X11DRV_GetRegionData( hrgn, 0 );
1345 XShapeCombineRectangles( display, data->whole_window, ShapeBounding,
1346 data->window_rect.left - data->whole_rect.left,
1347 data->window_rect.top - data->whole_rect.top,
1348 (XRectangle *)pRegionData->Buffer,
1349 pRegionData->rdh.nCount,
1350 ShapeSet, YXBanded );
1351 wine_tsx11_unlock();
1352 HeapFree(GetProcessHeap(), 0, pRegionData);
1356 #endif /* HAVE_LIBXSHAPE */
1358 invalidate_dce( hwnd, &data->window_rect );
1363 /***********************************************************************
1366 * Draw the frame used when moving or resizing window.
1368 * FIXME: This causes problems in Win95 mode. (why?)
1370 static void draw_moving_frame( HDC hdc, RECT *rect, BOOL thickframe )
1374 const int width = GetSystemMetrics(SM_CXFRAME);
1375 const int height = GetSystemMetrics(SM_CYFRAME);
1377 HBRUSH hbrush = SelectObject( hdc, GetStockObject( GRAY_BRUSH ) );
1378 PatBlt( hdc, rect->left, rect->top,
1379 rect->right - rect->left - width, height, PATINVERT );
1380 PatBlt( hdc, rect->left, rect->top + height, width,
1381 rect->bottom - rect->top - height, PATINVERT );
1382 PatBlt( hdc, rect->left + width, rect->bottom - 1,
1383 rect->right - rect->left - width, -height, PATINVERT );
1384 PatBlt( hdc, rect->right - 1, rect->top, -width,
1385 rect->bottom - rect->top - height, PATINVERT );
1386 SelectObject( hdc, hbrush );
1388 else DrawFocusRect( hdc, rect );
1392 /***********************************************************************
1395 * Initialisation of a move or resize, when initiatied from a menu choice.
1396 * Return hit test code for caption or sizing border.
1398 static LONG start_size_move( HWND hwnd, WPARAM wParam, POINT *capturePoint, LONG style )
1405 GetWindowRect( hwnd, &rectWindow );
1407 if ((wParam & 0xfff0) == SC_MOVE)
1409 /* Move pointer at the center of the caption */
1410 RECT rect = rectWindow;
1411 /* Note: to be exactly centered we should take the different types
1412 * of border into account, but it shouldn't make more that a few pixels
1413 * of difference so let's not bother with that */
1414 rect.top += GetSystemMetrics(SM_CYBORDER);
1415 if (style & WS_SYSMENU)
1416 rect.left += GetSystemMetrics(SM_CXSIZE) + 1;
1417 if (style & WS_MINIMIZEBOX)
1418 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1419 if (style & WS_MAXIMIZEBOX)
1420 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1421 pt.x = (rect.right + rect.left) / 2;
1422 pt.y = rect.top + GetSystemMetrics(SM_CYSIZE)/2;
1423 hittest = HTCAPTION;
1431 GetMessageW( &msg, 0, WM_KEYFIRST, WM_MOUSELAST );
1432 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
1438 hittest = SendMessageW( hwnd, WM_NCHITTEST, 0, MAKELONG( pt.x, pt.y ) );
1439 if ((hittest < HTLEFT) || (hittest > HTBOTTOMRIGHT)) hittest = 0;
1450 pt.x =(rectWindow.left+rectWindow.right)/2;
1451 pt.y = rectWindow.top + GetSystemMetrics(SM_CYFRAME) / 2;
1455 pt.x =(rectWindow.left+rectWindow.right)/2;
1456 pt.y = rectWindow.bottom - GetSystemMetrics(SM_CYFRAME) / 2;
1460 pt.x = rectWindow.left + GetSystemMetrics(SM_CXFRAME) / 2;
1461 pt.y =(rectWindow.top+rectWindow.bottom)/2;
1465 pt.x = rectWindow.right - GetSystemMetrics(SM_CXFRAME) / 2;
1466 pt.y =(rectWindow.top+rectWindow.bottom)/2;
1469 case VK_ESCAPE: return 0;
1475 SetCursorPos( pt.x, pt.y );
1476 SendMessageW( hwnd, WM_SETCURSOR, (WPARAM)hwnd, MAKELONG( hittest, WM_MOUSEMOVE ));
1481 /***********************************************************************
1482 * set_movesize_capture
1484 static void set_movesize_capture( HWND hwnd )
1488 SERVER_START_REQ( set_capture_window )
1491 req->flags = CAPTURE_MOVESIZE;
1492 if (!wine_server_call_err( req ))
1494 previous = reply->previous;
1495 hwnd = reply->full_handle;
1499 if (previous && previous != hwnd)
1500 SendMessageW( previous, WM_CAPTURECHANGED, 0, (LPARAM)hwnd );
1503 /***********************************************************************
1504 * X11DRV_WMMoveResizeWindow
1506 * Tells the window manager to initiate a move or resize operation.
1509 * http://freedesktop.org/Standards/wm-spec/1.3/ar01s04.html
1510 * or search for "_NET_WM_MOVERESIZE"
1512 static void X11DRV_WMMoveResizeWindow( HWND hwnd, int x, int y, int dir )
1515 Display *display = thread_display();
1517 xev.xclient.type = ClientMessage;
1518 xev.xclient.window = X11DRV_get_whole_window(hwnd);
1519 xev.xclient.message_type = x11drv_atom(_NET_WM_MOVERESIZE);
1520 xev.xclient.serial = 0;
1521 xev.xclient.display = display;
1522 xev.xclient.send_event = True;
1523 xev.xclient.format = 32;
1524 xev.xclient.data.l[0] = x; /* x coord */
1525 xev.xclient.data.l[1] = y; /* y coord */
1526 xev.xclient.data.l[2] = dir; /* direction */
1527 xev.xclient.data.l[3] = 1; /* button */
1528 xev.xclient.data.l[4] = 0; /* unused */
1530 /* need to ungrab the pointer that may have been automatically grabbed
1531 * with a ButtonPress event */
1533 XUngrabPointer( display, CurrentTime );
1534 XSendEvent(display, root_window, False, SubstructureNotifyMask, &xev);
1535 wine_tsx11_unlock();
1538 /***********************************************************************
1539 * SysCommandSizeMove (X11DRV.@)
1541 * Perform SC_MOVE and SC_SIZE commands.
1543 void X11DRV_SysCommandSizeMove( HWND hwnd, WPARAM wParam )
1546 RECT sizingRect, mouseRect, origRect;
1549 LONG hittest = (LONG)(wParam & 0x0f);
1550 WPARAM syscommand = wParam & 0xfff0;
1551 HCURSOR hDragCursor = 0, hOldCursor = 0;
1552 POINT minTrack, maxTrack;
1553 POINT capturePoint, pt;
1554 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
1555 BOOL thickframe = HAS_THICKFRAME( style );
1556 BOOL iconic = style & WS_MINIMIZE;
1558 DWORD dwPoint = GetMessagePos ();
1559 BOOL DragFullWindows = FALSE;
1561 Window parent_win, whole_win;
1562 Display *old_gdi_display = NULL;
1563 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1564 struct x11drv_win_data *data;
1566 pt.x = (short)LOWORD(dwPoint);
1567 pt.y = (short)HIWORD(dwPoint);
1570 if (IsZoomed(hwnd) || !IsWindowVisible(hwnd)) return;
1572 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1574 /* if we are managed then we let the WM do all the work */
1578 if (syscommand == SC_MOVE)
1580 if (!hittest) dir = _NET_WM_MOVERESIZE_MOVE_KEYBOARD;
1581 else dir = _NET_WM_MOVERESIZE_MOVE;
1583 else if (!hittest) dir = _NET_WM_MOVERESIZE_SIZE_KEYBOARD;
1587 case WMSZ_LEFT: dir = _NET_WM_MOVERESIZE_SIZE_LEFT; break;
1588 case WMSZ_RIGHT: dir = _NET_WM_MOVERESIZE_SIZE_RIGHT; break;
1589 case WMSZ_TOP: dir = _NET_WM_MOVERESIZE_SIZE_TOP; break;
1590 case WMSZ_TOPLEFT: dir = _NET_WM_MOVERESIZE_SIZE_TOPLEFT; break;
1591 case WMSZ_TOPRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT; break;
1592 case WMSZ_BOTTOM: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOM; break;
1593 case WMSZ_BOTTOMLEFT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT; break;
1594 case WMSZ_BOTTOMRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT; break;
1596 ERR("Invalid hittest value: %ld\n", hittest);
1597 dir = _NET_WM_MOVERESIZE_SIZE_KEYBOARD;
1599 X11DRV_WMMoveResizeWindow( hwnd, pt.x, pt.y, dir );
1603 SystemParametersInfoA(SPI_GETDRAGFULLWINDOWS, 0, &DragFullWindows, 0);
1605 if (syscommand == SC_MOVE)
1607 if (!hittest) hittest = start_size_move( hwnd, wParam, &capturePoint, style );
1608 if (!hittest) return;
1612 if ( hittest && (syscommand != SC_MOUSEMENU) )
1613 hittest += (HTLEFT - WMSZ_LEFT);
1616 set_movesize_capture( hwnd );
1617 hittest = start_size_move( hwnd, wParam, &capturePoint, style );
1620 set_movesize_capture(0);
1626 /* Get min/max info */
1628 WINPOS_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack );
1629 GetWindowRect( hwnd, &sizingRect );
1630 if (style & WS_CHILD)
1632 parent = GetParent(hwnd);
1633 /* make sizing rect relative to parent */
1634 MapWindowPoints( 0, parent, (POINT*)&sizingRect, 2 );
1635 GetClientRect( parent, &mouseRect );
1640 SetRect(&mouseRect, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
1642 origRect = sizingRect;
1644 if (ON_LEFT_BORDER(hittest))
1646 mouseRect.left = max( mouseRect.left, sizingRect.right-maxTrack.x );
1647 mouseRect.right = min( mouseRect.right, sizingRect.right-minTrack.x );
1649 else if (ON_RIGHT_BORDER(hittest))
1651 mouseRect.left = max( mouseRect.left, sizingRect.left+minTrack.x );
1652 mouseRect.right = min( mouseRect.right, sizingRect.left+maxTrack.x );
1654 if (ON_TOP_BORDER(hittest))
1656 mouseRect.top = max( mouseRect.top, sizingRect.bottom-maxTrack.y );
1657 mouseRect.bottom = min( mouseRect.bottom,sizingRect.bottom-minTrack.y);
1659 else if (ON_BOTTOM_BORDER(hittest))
1661 mouseRect.top = max( mouseRect.top, sizingRect.top+minTrack.y );
1662 mouseRect.bottom = min( mouseRect.bottom, sizingRect.top+maxTrack.y );
1664 if (parent) MapWindowPoints( parent, 0, (LPPOINT)&mouseRect, 2 );
1666 /* Retrieve a default cache DC (without using the window style) */
1667 hdc = GetDCEx( parent, 0, DCX_CACHE );
1669 if( iconic ) /* create a cursor for dragging */
1671 hDragCursor = (HCURSOR)GetClassLongPtrW( hwnd, GCLP_HICON);
1672 if( !hDragCursor ) hDragCursor = (HCURSOR)SendMessageW( hwnd, WM_QUERYDRAGICON, 0, 0L);
1673 if( !hDragCursor ) iconic = FALSE;
1676 /* repaint the window before moving it around */
1677 RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN );
1679 SendMessageW( hwnd, WM_ENTERSIZEMOVE, 0, 0 );
1680 set_movesize_capture( hwnd );
1682 /* grab the server only when moving top-level windows without desktop */
1683 grab = (!DragFullWindows && !parent && (root_window == DefaultRootWindow(gdi_display)));
1688 XSync( gdi_display, False );
1689 XGrabServer( thread_data->display );
1690 XSync( thread_data->display, False );
1691 /* switch gdi display to the thread display, since the server is grabbed */
1692 old_gdi_display = gdi_display;
1693 gdi_display = thread_data->display;
1694 wine_tsx11_unlock();
1696 whole_win = X11DRV_get_whole_window( GetAncestor(hwnd,GA_ROOT) );
1697 parent_win = parent ? X11DRV_get_whole_window( GetAncestor(parent,GA_ROOT) ) : root_window;
1700 XGrabPointer( thread_data->display, whole_win, False,
1701 PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
1702 GrabModeAsync, GrabModeAsync, parent_win, None, CurrentTime );
1703 wine_tsx11_unlock();
1704 thread_data->grab_window = whole_win;
1710 if (!GetMessageW( &msg, 0, WM_KEYFIRST, WM_MOUSELAST )) break;
1711 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
1713 /* Exit on button-up, Return, or Esc */
1714 if ((msg.message == WM_LBUTTONUP) ||
1715 ((msg.message == WM_KEYDOWN) &&
1716 ((msg.wParam == VK_RETURN) || (msg.wParam == VK_ESCAPE)))) break;
1718 if ((msg.message != WM_KEYDOWN) && (msg.message != WM_MOUSEMOVE))
1719 continue; /* We are not interested in other messages */
1723 if (msg.message == WM_KEYDOWN) switch(msg.wParam)
1725 case VK_UP: pt.y -= 8; break;
1726 case VK_DOWN: pt.y += 8; break;
1727 case VK_LEFT: pt.x -= 8; break;
1728 case VK_RIGHT: pt.x += 8; break;
1731 pt.x = max( pt.x, mouseRect.left );
1732 pt.x = min( pt.x, mouseRect.right );
1733 pt.y = max( pt.y, mouseRect.top );
1734 pt.y = min( pt.y, mouseRect.bottom );
1736 dx = pt.x - capturePoint.x;
1737 dy = pt.y - capturePoint.y;
1745 if( iconic ) /* ok, no system popup tracking */
1747 hOldCursor = SetCursor(hDragCursor);
1749 WINPOS_ShowIconTitle( hwnd, FALSE );
1751 else if(!DragFullWindows)
1752 draw_moving_frame( hdc, &sizingRect, thickframe );
1755 if (msg.message == WM_KEYDOWN) SetCursorPos( pt.x, pt.y );
1758 RECT newRect = sizingRect;
1759 WPARAM wpSizingHit = 0;
1761 if (hittest == HTCAPTION) OffsetRect( &newRect, dx, dy );
1762 if (ON_LEFT_BORDER(hittest)) newRect.left += dx;
1763 else if (ON_RIGHT_BORDER(hittest)) newRect.right += dx;
1764 if (ON_TOP_BORDER(hittest)) newRect.top += dy;
1765 else if (ON_BOTTOM_BORDER(hittest)) newRect.bottom += dy;
1766 if(!iconic && !DragFullWindows) draw_moving_frame( hdc, &sizingRect, thickframe );
1769 /* determine the hit location */
1770 if (hittest >= HTLEFT && hittest <= HTBOTTOMRIGHT)
1771 wpSizingHit = WMSZ_LEFT + (hittest - HTLEFT);
1772 SendMessageW( hwnd, WM_SIZING, wpSizingHit, (LPARAM)&newRect );
1776 if(!DragFullWindows)
1777 draw_moving_frame( hdc, &newRect, thickframe );
1779 SetWindowPos( hwnd, 0, newRect.left, newRect.top,
1780 newRect.right - newRect.left,
1781 newRect.bottom - newRect.top,
1782 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
1784 sizingRect = newRect;
1789 set_movesize_capture(0);
1792 if( moved ) /* restore cursors, show icon title later on */
1794 ShowCursor( FALSE );
1795 SetCursor( hOldCursor );
1798 else if (moved && !DragFullWindows)
1799 draw_moving_frame( hdc, &sizingRect, thickframe );
1801 ReleaseDC( parent, hdc );
1804 XUngrabPointer( thread_data->display, CurrentTime );
1807 XSync( thread_data->display, False );
1808 XUngrabServer( thread_data->display );
1809 XSync( thread_data->display, False );
1810 gdi_display = old_gdi_display;
1812 wine_tsx11_unlock();
1813 thread_data->grab_window = None;
1815 if (HOOK_CallHooks( WH_CBT, HCBT_MOVESIZE, (WPARAM)hwnd, (LPARAM)&sizingRect, TRUE ))
1818 SendMessageW( hwnd, WM_EXITSIZEMOVE, 0, 0 );
1819 SendMessageW( hwnd, WM_SETVISIBLE, !IsIconic(hwnd), 0L);
1821 /* window moved or resized */
1824 /* if the moving/resizing isn't canceled call SetWindowPos
1825 * with the new position or the new size of the window
1827 if (!((msg.message == WM_KEYDOWN) && (msg.wParam == VK_ESCAPE)) )
1829 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
1830 if(!DragFullWindows)
1831 SetWindowPos( hwnd, 0, sizingRect.left, sizingRect.top,
1832 sizingRect.right - sizingRect.left,
1833 sizingRect.bottom - sizingRect.top,
1834 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
1837 { /* restore previous size/position */
1839 SetWindowPos( hwnd, 0, origRect.left, origRect.top,
1840 origRect.right - origRect.left,
1841 origRect.bottom - origRect.top,
1842 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
1848 /* Single click brings up the system menu when iconized */
1852 if(style & WS_SYSMENU )
1853 SendMessageW( hwnd, WM_SYSCOMMAND,
1854 SC_MOUSEMENU + HTSYSMENU, MAKELONG(pt.x,pt.y));
1856 else WINPOS_ShowIconTitle( hwnd, TRUE );