2 * Window position related functions.
4 * Copyright 1993, 1994, 1995, 2001 Alexandre Julliard
5 * Copyright 1995, 1996, 1999 Alex Korobka
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <X11/extensions/shape.h>
27 #endif /* HAVE_LIBXSHAPE */
36 #include "wine/wingdi16.h"
42 #include "wine/server.h"
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
47 #define SWP_AGG_NOPOSCHANGE \
48 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_NOZORDER)
49 #define SWP_AGG_STATUSFLAGS \
50 (SWP_AGG_NOPOSCHANGE | SWP_FRAMECHANGED | SWP_HIDEWINDOW | SWP_SHOWWINDOW)
52 #define SWP_EX_NOCOPY 0x0001
53 #define SWP_EX_PAINTSELF 0x0002
54 #define SWP_EX_NONCLIENT 0x0004
56 #define HAS_THICKFRAME(style) \
57 (((style) & WS_THICKFRAME) && \
58 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
60 #define ON_LEFT_BORDER(hit) \
61 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
62 #define ON_RIGHT_BORDER(hit) \
63 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
64 #define ON_TOP_BORDER(hit) \
65 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
66 #define ON_BOTTOM_BORDER(hit) \
67 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
69 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
70 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
71 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
72 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
73 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
74 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
75 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
76 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
77 #define _NET_WM_MOVERESIZE_MOVE 8 /* movement only */
78 #define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9 /* size via keyboard */
79 #define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10 /* move via keyboard */
82 /***********************************************************************
85 void X11DRV_Expose( HWND hwnd, XEvent *xev )
87 XExposeEvent *event = &xev->xexpose;
89 struct x11drv_win_data *data;
90 int flags = RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN;
92 TRACE( "win %p (%lx) %d,%d %dx%d\n",
93 hwnd, event->window, event->x, event->y, event->width, event->height );
95 if (!(data = X11DRV_get_win_data( hwnd ))) return;
99 rect.right = rect.left + event->width;
100 rect.bottom = rect.top + event->height;
102 if (rect.left < data->client_rect.left ||
103 rect.top < data->client_rect.top ||
104 rect.right > data->client_rect.right ||
105 rect.bottom > data->client_rect.bottom) flags |= RDW_FRAME;
107 SERVER_START_REQ( update_window_zorder )
110 req->rect.left = rect.left + data->whole_rect.left;
111 req->rect.top = rect.top + data->whole_rect.top;
112 req->rect.right = rect.right + data->whole_rect.left;
113 req->rect.bottom = rect.bottom + data->whole_rect.top;
114 wine_server_call( req );
118 /* make position relative to client area instead of window */
119 OffsetRect( &rect, -data->client_rect.left, -data->client_rect.top );
120 RedrawWindow( hwnd, &rect, 0, flags );
124 /***********************************************************************
125 * SWP_DoWinPosChanging
127 static BOOL SWP_DoWinPosChanging( WINDOWPOS* pWinpos, RECT* pNewWindowRect, RECT* pNewClientRect )
131 /* Send WM_WINDOWPOSCHANGING message */
133 if (!(pWinpos->flags & SWP_NOSENDCHANGING))
134 SendMessageW( pWinpos->hwnd, WM_WINDOWPOSCHANGING, 0, (LPARAM)pWinpos );
136 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return FALSE;
138 /* Calculate new position and size */
140 *pNewWindowRect = wndPtr->rectWindow;
141 *pNewClientRect = (wndPtr->dwStyle & WS_MINIMIZE) ? wndPtr->rectWindow
142 : wndPtr->rectClient;
144 if (!(pWinpos->flags & SWP_NOSIZE))
146 pNewWindowRect->right = pNewWindowRect->left + pWinpos->cx;
147 pNewWindowRect->bottom = pNewWindowRect->top + pWinpos->cy;
149 if (!(pWinpos->flags & SWP_NOMOVE))
151 pNewWindowRect->left = pWinpos->x;
152 pNewWindowRect->top = pWinpos->y;
153 pNewWindowRect->right += pWinpos->x - wndPtr->rectWindow.left;
154 pNewWindowRect->bottom += pWinpos->y - wndPtr->rectWindow.top;
156 OffsetRect( pNewClientRect, pWinpos->x - wndPtr->rectWindow.left,
157 pWinpos->y - wndPtr->rectWindow.top );
159 pWinpos->flags |= SWP_NOCLIENTMOVE | SWP_NOCLIENTSIZE;
161 TRACE( "hwnd %p, after %p, swp %d,%d %dx%d flags %08x\n",
162 pWinpos->hwnd, pWinpos->hwndInsertAfter, pWinpos->x, pWinpos->y,
163 pWinpos->cx, pWinpos->cy, pWinpos->flags );
164 TRACE( "current %s style %08lx new %s\n",
165 wine_dbgstr_rect( &wndPtr->rectWindow ), wndPtr->dwStyle,
166 wine_dbgstr_rect( pNewWindowRect ));
168 WIN_ReleasePtr( wndPtr );
173 /***********************************************************************
176 * Compute the valid rects from the old and new client rect and WVR_* flags.
177 * Helper for WM_NCCALCSIZE handling.
179 static inline void get_valid_rects( const RECT *old_client, const RECT *new_client, UINT flags,
184 if (flags & WVR_REDRAW)
186 SetRectEmpty( &valid[0] );
187 SetRectEmpty( &valid[1] );
191 if (flags & WVR_VALIDRECTS)
193 if (!IntersectRect( &valid[0], &valid[0], new_client ) ||
194 !IntersectRect( &valid[1], &valid[1], old_client ))
196 SetRectEmpty( &valid[0] );
197 SetRectEmpty( &valid[1] );
200 flags = WVR_ALIGNLEFT | WVR_ALIGNTOP;
204 valid[0] = *new_client;
205 valid[1] = *old_client;
208 /* make sure the rectangles have the same size */
209 cx = min( valid[0].right - valid[0].left, valid[1].right - valid[1].left );
210 cy = min( valid[0].bottom - valid[0].top, valid[1].bottom - valid[1].top );
212 if (flags & WVR_ALIGNBOTTOM)
214 valid[0].top = valid[0].bottom - cy;
215 valid[1].top = valid[1].bottom - cy;
219 valid[0].bottom = valid[0].top + cy;
220 valid[1].bottom = valid[1].top + cy;
222 if (flags & WVR_ALIGNRIGHT)
224 valid[0].left = valid[0].right - cx;
225 valid[1].left = valid[1].right - cx;
229 valid[0].right = valid[0].left + cx;
230 valid[1].right = valid[1].left + cx;
235 /***********************************************************************
238 static UINT SWP_DoNCCalcSize( WINDOWPOS* pWinpos, const RECT* pNewWindowRect, RECT* pNewClientRect,
244 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
246 /* Send WM_NCCALCSIZE message to get new client area */
247 if( (pWinpos->flags & (SWP_FRAMECHANGED | SWP_NOSIZE)) != SWP_NOSIZE )
249 NCCALCSIZE_PARAMS params;
250 WINDOWPOS winposCopy;
252 params.rgrc[0] = *pNewWindowRect;
253 params.rgrc[1] = wndPtr->rectWindow;
254 params.rgrc[2] = wndPtr->rectClient;
255 params.lppos = &winposCopy;
256 winposCopy = *pWinpos;
257 WIN_ReleasePtr( wndPtr );
259 wvrFlags = SendMessageW( pWinpos->hwnd, WM_NCCALCSIZE, TRUE, (LPARAM)¶ms );
261 *pNewClientRect = params.rgrc[0];
263 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
265 TRACE( "hwnd %p old win %s old client %s new win %s new client %s\n", pWinpos->hwnd,
266 wine_dbgstr_rect(&wndPtr->rectWindow), wine_dbgstr_rect(&wndPtr->rectClient),
267 wine_dbgstr_rect(pNewWindowRect), wine_dbgstr_rect(pNewClientRect) );
269 if( pNewClientRect->left != wndPtr->rectClient.left ||
270 pNewClientRect->top != wndPtr->rectClient.top )
271 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
273 if( (pNewClientRect->right - pNewClientRect->left !=
274 wndPtr->rectClient.right - wndPtr->rectClient.left))
275 pWinpos->flags &= ~SWP_NOCLIENTSIZE;
277 wvrFlags &= ~WVR_HREDRAW;
279 if (pNewClientRect->bottom - pNewClientRect->top !=
280 wndPtr->rectClient.bottom - wndPtr->rectClient.top)
281 pWinpos->flags &= ~SWP_NOCLIENTSIZE;
283 wvrFlags &= ~WVR_VREDRAW;
285 validRects[0] = params.rgrc[1];
286 validRects[1] = params.rgrc[2];
290 if (!(pWinpos->flags & SWP_NOMOVE) &&
291 (pNewClientRect->left != wndPtr->rectClient.left ||
292 pNewClientRect->top != wndPtr->rectClient.top))
293 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
296 if (pWinpos->flags & (SWP_NOCOPYBITS | SWP_NOREDRAW | SWP_SHOWWINDOW | SWP_HIDEWINDOW))
298 SetRectEmpty( &validRects[0] );
299 SetRectEmpty( &validRects[1] );
301 else get_valid_rects( &wndPtr->rectClient, pNewClientRect, wvrFlags, validRects );
303 WIN_ReleasePtr( wndPtr );
308 struct move_owned_info
314 static BOOL CALLBACK move_owned_popups( HWND hwnd, LPARAM lparam )
316 struct move_owned_info *info = (struct move_owned_info *)lparam;
318 if (hwnd == info->owner) return FALSE;
319 if ((GetWindowLongW( hwnd, GWL_STYLE ) & WS_POPUP) &&
320 GetWindow( hwnd, GW_OWNER ) == info->owner)
322 SetWindowPos( hwnd, info->insert_after, 0, 0, 0, 0,
323 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE |
324 SWP_NOSENDCHANGING | SWP_DEFERERASE );
325 info->insert_after = hwnd;
330 /***********************************************************************
333 * fix Z order taking into account owned popups -
334 * basically we need to maintain them above the window that owns them
336 * FIXME: hide/show owned popups when owner visibility changes.
338 static HWND SWP_DoOwnedPopups(HWND hwnd, HWND hwndInsertAfter)
340 HWND owner = GetWindow( hwnd, GW_OWNER );
341 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
342 struct move_owned_info info;
344 TRACE("(%p) hInsertAfter = %p\n", hwnd, hwndInsertAfter );
346 if ((style & WS_POPUP) && owner)
348 /* make sure this popup stays above the owner */
350 if( hwndInsertAfter != HWND_TOP )
352 HWND hwndLocalPrev = HWND_TOP;
353 HWND prev = GetWindow( owner, GW_HWNDPREV );
355 while (prev && prev != hwndInsertAfter)
357 if (hwndLocalPrev == HWND_TOP && GetWindowLongW( prev, GWL_STYLE ) & WS_VISIBLE)
358 hwndLocalPrev = prev;
359 prev = GetWindow( prev, GW_HWNDPREV );
361 if (!prev) hwndInsertAfter = hwndLocalPrev;
364 else if (style & WS_CHILD) return hwndInsertAfter;
367 info.insert_after = hwndInsertAfter;
368 EnumWindows( move_owned_popups, (LPARAM)&info );
369 return info.insert_after;
373 /* fix redundant flags and values in the WINDOWPOS structure */
374 static BOOL fixup_flags( WINDOWPOS *winpos )
377 WND *wndPtr = WIN_GetPtr( winpos->hwnd );
380 if (!wndPtr || wndPtr == WND_OTHER_PROCESS)
382 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
385 winpos->hwnd = wndPtr->hwndSelf; /* make it a full handle */
387 /* Finally make sure that all coordinates are valid */
388 if (winpos->x < -32768) winpos->x = -32768;
389 else if (winpos->x > 32767) winpos->x = 32767;
390 if (winpos->y < -32768) winpos->y = -32768;
391 else if (winpos->y > 32767) winpos->y = 32767;
393 if (winpos->cx < 0) winpos->cx = 0;
394 else if (winpos->cx > 32767) winpos->cx = 32767;
395 if (winpos->cy < 0) winpos->cy = 0;
396 else if (winpos->cy > 32767) winpos->cy = 32767;
398 parent = GetAncestor( winpos->hwnd, GA_PARENT );
399 if (!IsWindowVisible( parent )) winpos->flags |= SWP_NOREDRAW;
401 if (wndPtr->dwStyle & WS_VISIBLE) winpos->flags &= ~SWP_SHOWWINDOW;
404 winpos->flags &= ~SWP_HIDEWINDOW;
405 if (!(winpos->flags & SWP_SHOWWINDOW)) winpos->flags |= SWP_NOREDRAW;
408 if ((wndPtr->rectWindow.right - wndPtr->rectWindow.left == winpos->cx) &&
409 (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top == winpos->cy))
410 winpos->flags |= SWP_NOSIZE; /* Already the right size */
412 if ((wndPtr->rectWindow.left == winpos->x) && (wndPtr->rectWindow.top == winpos->y))
413 winpos->flags |= SWP_NOMOVE; /* Already the right position */
415 if ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD)
417 if (!(winpos->flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW))) /* Bring to the top when activating */
419 winpos->flags &= ~SWP_NOZORDER;
420 winpos->hwndInsertAfter = HWND_TOP;
424 /* Check hwndInsertAfter */
425 if (winpos->flags & SWP_NOZORDER) goto done;
427 /* fix sign extension */
428 if (winpos->hwndInsertAfter == (HWND)0xffff) winpos->hwndInsertAfter = HWND_TOPMOST;
429 else if (winpos->hwndInsertAfter == (HWND)0xfffe) winpos->hwndInsertAfter = HWND_NOTOPMOST;
431 /* FIXME: TOPMOST not supported yet */
432 if ((winpos->hwndInsertAfter == HWND_TOPMOST) ||
433 (winpos->hwndInsertAfter == HWND_NOTOPMOST)) winpos->hwndInsertAfter = HWND_TOP;
435 /* hwndInsertAfter must be a sibling of the window */
436 if (winpos->hwndInsertAfter == HWND_TOP)
438 if (GetWindow(winpos->hwnd, GW_HWNDFIRST) == winpos->hwnd)
439 winpos->flags |= SWP_NOZORDER;
441 else if (winpos->hwndInsertAfter == HWND_BOTTOM)
443 if (GetWindow(winpos->hwnd, GW_HWNDLAST) == winpos->hwnd)
444 winpos->flags |= SWP_NOZORDER;
448 if (GetAncestor( winpos->hwndInsertAfter, GA_PARENT ) != parent) ret = FALSE;
451 /* don't need to change the Zorder of hwnd if it's already inserted
452 * after hwndInsertAfter or when inserting hwnd after itself.
454 if ((winpos->hwnd == winpos->hwndInsertAfter) ||
455 (winpos->hwnd == GetWindow( winpos->hwndInsertAfter, GW_HWNDNEXT )))
456 winpos->flags |= SWP_NOZORDER;
460 WIN_ReleasePtr( wndPtr );
465 /***********************************************************************
466 * SetWindowStyle (X11DRV.@)
468 * Update the X state of a window to reflect a style change
470 void X11DRV_SetWindowStyle( HWND hwnd, DWORD old_style )
472 Display *display = thread_display();
473 struct x11drv_win_data *data;
474 DWORD new_style, changed;
476 if (hwnd == GetDesktopWindow()) return;
477 if (!(data = X11DRV_get_win_data( hwnd ))) return;
479 new_style = GetWindowLongW( hwnd, GWL_STYLE );
480 changed = new_style ^ old_style;
482 if (changed & WS_VISIBLE)
484 if (data->whole_window && X11DRV_is_window_rect_mapped( &data->window_rect ))
486 if (new_style & WS_VISIBLE)
488 TRACE( "mapping win %p\n", hwnd );
489 X11DRV_sync_window_style( display, data );
490 X11DRV_set_wm_hints( display, data );
492 XMapWindow( display, data->whole_window );
495 /* we don't unmap windows, that causes trouble with the window manager */
497 invalidate_dce( hwnd, &data->window_rect );
500 if (changed & WS_DISABLED)
502 if (data->whole_window && data->managed)
506 if (!(wm_hints = XGetWMHints( display, data->whole_window )))
507 wm_hints = XAllocWMHints();
510 wm_hints->flags |= InputHint;
511 wm_hints->input = !(new_style & WS_DISABLED);
512 XSetWMHints( display, data->whole_window, wm_hints );
521 /***********************************************************************
522 * X11DRV_set_window_pos
524 * Set a window position and Z order.
526 BOOL X11DRV_set_window_pos( HWND hwnd, HWND insert_after, const RECT *rectWindow,
527 const RECT *rectClient, UINT swp_flags, const RECT *valid_rects )
529 struct x11drv_win_data *data;
532 DWORD old_style, new_style;
535 if (!(data = X11DRV_get_win_data( hwnd ))) return FALSE;
537 new_whole_rect = *rectWindow;
538 X11DRV_window_to_X_rect( data, &new_whole_rect );
540 if (!IsRectEmpty( &valid_rects[0] ))
542 int x_offset = 0, y_offset = 0;
544 if (data->whole_window)
546 /* the X server will move the bits for us */
547 x_offset = data->whole_rect.left - new_whole_rect.left;
548 y_offset = data->whole_rect.top - new_whole_rect.top;
551 if (x_offset != valid_rects[1].left - valid_rects[0].left ||
552 y_offset != valid_rects[1].top - valid_rects[0].top)
554 /* FIXME: should copy the window bits here */
559 if (!(win = WIN_GetPtr( hwnd ))) return FALSE;
560 if (win == WND_OTHER_PROCESS)
562 if (IsWindow( hwnd )) ERR( "cannot set rectangles of other process window %p\n", hwnd );
565 SERVER_START_REQ( set_window_pos )
568 req->previous = insert_after;
569 req->flags = swp_flags & ~SWP_WINE_NOHOSTMOVE;
570 req->window.left = rectWindow->left;
571 req->window.top = rectWindow->top;
572 req->window.right = rectWindow->right;
573 req->window.bottom = rectWindow->bottom;
574 req->client.left = rectClient->left;
575 req->client.top = rectClient->top;
576 req->client.right = rectClient->right;
577 req->client.bottom = rectClient->bottom;
578 if (memcmp( rectWindow, &new_whole_rect, sizeof(RECT) ) || !IsRectEmpty( &valid_rects[0] ))
580 wine_server_add_data( req, &new_whole_rect, sizeof(new_whole_rect) );
581 if (!IsRectEmpty( &valid_rects[0] ))
582 wine_server_add_data( req, valid_rects, 2 * sizeof(*valid_rects) );
584 ret = !wine_server_call( req );
585 new_style = reply->new_style;
589 if (win == WND_DESKTOP)
591 data->whole_rect = data->client_rect = data->window_rect = *rectWindow;
597 Display *display = thread_display();
599 /* invalidate DCEs */
601 if ((((swp_flags & SWP_AGG_NOPOSCHANGE) != SWP_AGG_NOPOSCHANGE) && (new_style & WS_VISIBLE)) ||
602 (swp_flags & (SWP_HIDEWINDOW | SWP_SHOWWINDOW)))
605 UnionRect( &rect, rectWindow, &win->rectWindow );
606 invalidate_dce( hwnd, &rect );
609 win->rectWindow = *rectWindow;
610 win->rectClient = *rectClient;
611 old_style = win->dwStyle;
612 win->dwStyle = new_style;
613 data->window_rect = *rectWindow;
615 TRACE( "win %p window %s client %s style %08lx\n",
616 hwnd, wine_dbgstr_rect(rectWindow), wine_dbgstr_rect(rectClient), new_style );
618 /* FIXME: copy the valid bits */
620 if (data->whole_window && !(swp_flags & SWP_WINE_NOHOSTMOVE))
622 if ((old_style & WS_VISIBLE) && !(new_style & WS_VISIBLE))
624 /* window got hidden, unmap it */
625 TRACE( "unmapping win %p\n", hwnd );
627 XUnmapWindow( display, data->whole_window );
630 else if ((new_style & WS_VISIBLE) && !X11DRV_is_window_rect_mapped( rectWindow ))
632 /* resizing to zero size or off screen -> unmap */
633 TRACE( "unmapping zero size or off-screen win %p\n", hwnd );
635 XUnmapWindow( display, data->whole_window );
640 X11DRV_sync_window_position( display, data, swp_flags, rectClient, &new_whole_rect );
642 if (data->whole_window && !(swp_flags & SWP_WINE_NOHOSTMOVE))
644 if ((new_style & WS_VISIBLE) && !(new_style & WS_MINIMIZE) &&
645 X11DRV_is_window_rect_mapped( rectWindow ))
647 if (!(old_style & WS_VISIBLE))
649 /* window got shown, map it */
650 TRACE( "mapping win %p\n", hwnd );
651 X11DRV_sync_window_style( display, data );
652 X11DRV_set_wm_hints( display, data );
654 XMapWindow( display, data->whole_window );
657 else if ((swp_flags & (SWP_NOSIZE | SWP_NOMOVE)) != (SWP_NOSIZE | SWP_NOMOVE))
659 /* resizing from zero size to non-zero -> map */
660 TRACE( "mapping non zero size or off-screen win %p\n", hwnd );
662 XMapWindow( display, data->whole_window );
667 XFlush( display ); /* FIXME: should not be necessary */
671 WIN_ReleasePtr( win );
676 /***********************************************************************
677 * SetWindowPos (X11DRV.@)
679 BOOL X11DRV_SetWindowPos( WINDOWPOS *winpos )
681 RECT newWindowRect, newClientRect, valid_rects[2];
684 TRACE( "hwnd %p, after %p, swp %d,%d %dx%d flags %08x\n",
685 winpos->hwnd, winpos->hwndInsertAfter, winpos->x, winpos->y,
686 winpos->cx, winpos->cy, winpos->flags);
688 orig_flags = winpos->flags;
689 winpos->flags &= ~SWP_WINE_NOHOSTMOVE;
691 /* Check window handle */
692 if (winpos->hwnd == GetDesktopWindow()) return FALSE;
694 /* First make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
695 if (!(winpos->flags & SWP_NOMOVE))
697 if (winpos->x < -32768) winpos->x = -32768;
698 else if (winpos->x > 32767) winpos->x = 32767;
699 if (winpos->y < -32768) winpos->y = -32768;
700 else if (winpos->y > 32767) winpos->y = 32767;
702 if (!(winpos->flags & SWP_NOSIZE))
704 if (winpos->cx < 0) winpos->cx = 0;
705 else if (winpos->cx > 32767) winpos->cx = 32767;
706 if (winpos->cy < 0) winpos->cy = 0;
707 else if (winpos->cy > 32767) winpos->cy = 32767;
710 if (!SWP_DoWinPosChanging( winpos, &newWindowRect, &newClientRect )) return FALSE;
712 /* Fix redundant flags */
713 if (!fixup_flags( winpos )) return FALSE;
715 if((winpos->flags & (SWP_NOZORDER | SWP_HIDEWINDOW | SWP_SHOWWINDOW)) != SWP_NOZORDER)
717 if (GetAncestor( winpos->hwnd, GA_PARENT ) == GetDesktopWindow())
718 winpos->hwndInsertAfter = SWP_DoOwnedPopups( winpos->hwnd, winpos->hwndInsertAfter );
721 /* Common operations */
723 SWP_DoNCCalcSize( winpos, &newWindowRect, &newClientRect, valid_rects );
725 if (!X11DRV_set_window_pos( winpos->hwnd, winpos->hwndInsertAfter,
726 &newWindowRect, &newClientRect, orig_flags, valid_rects ))
729 if (!(orig_flags & SWP_SHOWWINDOW))
731 UINT rdw_flags = RDW_FRAME | RDW_ERASE;
732 if ( !(orig_flags & SWP_DEFERERASE) ) rdw_flags |= RDW_ERASENOW;
733 RedrawWindow( winpos->hwnd, NULL, NULL, rdw_flags );
736 if( winpos->flags & SWP_HIDEWINDOW )
737 HideCaret(winpos->hwnd);
738 else if (winpos->flags & SWP_SHOWWINDOW)
739 ShowCaret(winpos->hwnd);
741 if (!(winpos->flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW)))
743 /* child windows get WM_CHILDACTIVATE message */
744 if ((GetWindowLongW( winpos->hwnd, GWL_STYLE ) & (WS_CHILD | WS_POPUP)) == WS_CHILD)
745 SendMessageA( winpos->hwnd, WM_CHILDACTIVATE, 0, 0 );
747 SetForegroundWindow( winpos->hwnd );
750 /* And last, send the WM_WINDOWPOSCHANGED message */
752 TRACE("\tstatus flags = %04x\n", winpos->flags & SWP_AGG_STATUSFLAGS);
754 if (((winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOPOSCHANGE))
756 /* WM_WINDOWPOSCHANGED is sent even if SWP_NOSENDCHANGING is set
757 and always contains final window position.
759 winpos->x = newWindowRect.left;
760 winpos->y = newWindowRect.top;
761 winpos->cx = newWindowRect.right - newWindowRect.left;
762 winpos->cy = newWindowRect.bottom - newWindowRect.top;
763 SendMessageW( winpos->hwnd, WM_WINDOWPOSCHANGED, 0, (LPARAM)winpos );
770 /***********************************************************************
773 * Find a suitable place for an iconic window.
775 static POINT WINPOS_FindIconPos( HWND hwnd, POINT pt )
777 RECT rect, rectParent;
780 int xspacing, yspacing;
782 parent = GetAncestor( hwnd, GA_PARENT );
783 GetClientRect( parent, &rectParent );
784 if ((pt.x >= rectParent.left) && (pt.x + GetSystemMetrics(SM_CXICON) < rectParent.right) &&
785 (pt.y >= rectParent.top) && (pt.y + GetSystemMetrics(SM_CYICON) < rectParent.bottom))
786 return pt; /* The icon already has a suitable position */
788 xspacing = GetSystemMetrics(SM_CXICONSPACING);
789 yspacing = GetSystemMetrics(SM_CYICONSPACING);
791 /* Check if another icon already occupies this spot */
792 /* FIXME: this is completely inefficient */
794 hrgn = CreateRectRgn( 0, 0, 0, 0 );
795 tmp = CreateRectRgn( 0, 0, 0, 0 );
796 for (child = GetWindow( parent, GW_HWNDFIRST ); child; child = GetWindow( child, GW_HWNDNEXT ))
799 if (child == hwnd) continue;
800 if ((GetWindowLongW( child, GWL_STYLE ) & (WS_VISIBLE|WS_MINIMIZE)) != (WS_VISIBLE|WS_MINIMIZE))
802 if (!(childPtr = WIN_GetPtr( child )) || childPtr == WND_OTHER_PROCESS)
804 SetRectRgn( tmp, childPtr->rectWindow.left, childPtr->rectWindow.top,
805 childPtr->rectWindow.right, childPtr->rectWindow.bottom );
806 CombineRgn( hrgn, hrgn, tmp, RGN_OR );
807 WIN_ReleasePtr( childPtr );
811 for (rect.bottom = rectParent.bottom; rect.bottom >= yspacing; rect.bottom -= yspacing)
813 for (rect.left = rectParent.left; rect.left <= rectParent.right - xspacing; rect.left += xspacing)
815 rect.right = rect.left + xspacing;
816 rect.top = rect.bottom - yspacing;
817 if (!RectInRegion( hrgn, &rect ))
819 /* No window was found, so it's OK for us */
820 pt.x = rect.left + (xspacing - GetSystemMetrics(SM_CXICON)) / 2;
821 pt.y = rect.top + (yspacing - GetSystemMetrics(SM_CYICON)) / 2;
822 DeleteObject( hrgn );
827 DeleteObject( hrgn );
836 UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect )
844 TRACE("%p %u\n", hwnd, cmd );
846 wpl.length = sizeof(wpl);
847 GetWindowPlacement( hwnd, &wpl );
849 if (HOOK_CallHooks( WH_CBT, HCBT_MINMAX, (WPARAM)hwnd, cmd, TRUE ))
850 return SWP_NOSIZE | SWP_NOMOVE;
852 if (IsIconic( hwnd ))
854 if (cmd == SW_MINIMIZE) return SWP_NOSIZE | SWP_NOMOVE;
855 if (!SendMessageW( hwnd, WM_QUERYOPEN, 0, 0 )) return SWP_NOSIZE | SWP_NOMOVE;
856 swpFlags |= SWP_NOCOPYBITS;
862 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
863 if( wndPtr->dwStyle & WS_MAXIMIZE) wndPtr->flags |= WIN_RESTORE_MAX;
864 else wndPtr->flags &= ~WIN_RESTORE_MAX;
865 WIN_ReleasePtr( wndPtr );
867 WIN_SetStyle( hwnd, WS_MINIMIZE, WS_MAXIMIZE );
869 X11DRV_set_iconic_state( hwnd );
871 wpl.ptMinPosition = WINPOS_FindIconPos( hwnd, wpl.ptMinPosition );
873 SetRect( rect, wpl.ptMinPosition.x, wpl.ptMinPosition.y,
874 GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON) );
875 swpFlags |= SWP_NOCOPYBITS;
879 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL );
881 old_style = WIN_SetStyle( hwnd, WS_MAXIMIZE, WS_MINIMIZE );
882 if (old_style & WS_MINIMIZE)
884 WINPOS_ShowIconTitle( hwnd, FALSE );
885 X11DRV_set_iconic_state( hwnd );
887 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y );
891 old_style = WIN_SetStyle( hwnd, 0, WS_MINIMIZE | WS_MAXIMIZE );
892 if (old_style & WS_MINIMIZE)
896 WINPOS_ShowIconTitle( hwnd, FALSE );
897 X11DRV_set_iconic_state( hwnd );
899 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
900 restore_max = (wndPtr->flags & WIN_RESTORE_MAX) != 0;
901 WIN_ReleasePtr( wndPtr );
904 /* Restore to maximized position */
905 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL);
906 WIN_SetStyle( hwnd, WS_MAXIMIZE, 0 );
907 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y );
911 else if (!(old_style & WS_MAXIMIZE)) break;
913 /* Restore to normal position */
915 *rect = wpl.rcNormalPosition;
916 rect->right -= rect->left;
917 rect->bottom -= rect->top;
926 /***********************************************************************
927 * ShowWindow (X11DRV.@)
929 BOOL X11DRV_ShowWindow( HWND hwnd, INT cmd )
932 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
933 BOOL wasVisible = (style & WS_VISIBLE) != 0;
934 BOOL showFlag = TRUE;
935 RECT newPos = {0, 0, 0, 0};
938 if (hwnd == GetDesktopWindow()) return FALSE;
940 TRACE("hwnd=%p, cmd=%d, wasVisible %d\n", hwnd, cmd, wasVisible);
945 if (!wasVisible) return FALSE;
947 swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE;
948 if (hwnd != GetActiveWindow())
949 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
952 case SW_SHOWMINNOACTIVE:
953 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
955 case SW_SHOWMINIMIZED:
956 case SW_FORCEMINIMIZE: /* FIXME: Does not work if thread is hung. */
957 swp |= SWP_SHOWWINDOW;
960 swp |= SWP_FRAMECHANGED;
961 if( !(style & WS_MINIMIZE) )
962 swp |= WINPOS_MinMaximize( hwnd, SW_MINIMIZE, &newPos );
963 else swp |= SWP_NOSIZE | SWP_NOMOVE;
966 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
967 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
968 swp |= WINPOS_MinMaximize( hwnd, SW_MAXIMIZE, &newPos );
972 swp |= SWP_NOACTIVATE | SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
973 if (style & WS_CHILD) swp |= SWP_NOZORDER;
976 if (wasVisible) return TRUE;
977 swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
981 swp |= SWP_FRAMECHANGED;
983 case SW_SHOWNOACTIVATE:
984 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
986 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
987 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
988 swp |= SWP_SHOWWINDOW;
990 if (style & (WS_MINIMIZE | WS_MAXIMIZE))
991 swp |= WINPOS_MinMaximize( hwnd, SW_RESTORE, &newPos );
992 else swp |= SWP_NOSIZE | SWP_NOMOVE;
996 if ((showFlag != wasVisible || cmd == SW_SHOWNA) && cmd != SW_SHOWMAXIMIZED)
998 SendMessageW( hwnd, WM_SHOWWINDOW, showFlag, 0 );
999 if (!IsWindow( hwnd )) return wasVisible;
1002 if (!IsWindowVisible( GetAncestor( hwnd, GA_PARENT )))
1004 /* if parent is not visible simply toggle WS_VISIBLE and return */
1005 if (showFlag) WIN_SetStyle( hwnd, WS_VISIBLE, 0 );
1006 else WIN_SetStyle( hwnd, 0, WS_VISIBLE );
1010 /* ShowWindow won't activate a not being maximized child window */
1011 if ((style & WS_CHILD) && cmd != SW_MAXIMIZE)
1012 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1014 SetWindowPos( hwnd, HWND_TOP, newPos.left, newPos.top,
1015 newPos.right, newPos.bottom, LOWORD(swp) );
1022 /* FIXME: This will cause the window to be activated irrespective
1023 * of whether it is owned by the same thread. Has to be done
1027 if (hwnd == GetActiveWindow())
1028 WINPOS_ActivateOtherWindow(hwnd);
1030 /* Revert focus to parent */
1031 hFocus = GetFocus();
1032 if (hwnd == hFocus || IsChild(hwnd, hFocus))
1034 HWND parent = GetAncestor(hwnd, GA_PARENT);
1035 if (parent == GetDesktopWindow()) parent = 0;
1040 if (IsIconic(hwnd)) WINPOS_ShowIconTitle( hwnd, TRUE );
1042 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return wasVisible;
1044 if (wndPtr->flags & WIN_NEED_SIZE)
1046 /* should happen only in CreateWindowEx() */
1047 int wParam = SIZE_RESTORED;
1048 RECT client = wndPtr->rectClient;
1050 wndPtr->flags &= ~WIN_NEED_SIZE;
1051 if (wndPtr->dwStyle & WS_MAXIMIZE) wParam = SIZE_MAXIMIZED;
1052 else if (wndPtr->dwStyle & WS_MINIMIZE) wParam = SIZE_MINIMIZED;
1053 WIN_ReleasePtr( wndPtr );
1055 SendMessageW( hwnd, WM_SIZE, wParam,
1056 MAKELONG( client.right - client.left, client.bottom - client.top ));
1057 SendMessageW( hwnd, WM_MOVE, 0, MAKELONG( client.left, client.top ));
1059 else WIN_ReleasePtr( wndPtr );
1065 /**********************************************************************
1068 void X11DRV_MapNotify( HWND hwnd, XEvent *event )
1070 struct x11drv_win_data *data;
1071 HWND hwndFocus = GetFocus();
1074 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1076 if (!(win = WIN_GetPtr( hwnd ))) return;
1078 if (data->managed && (win->dwStyle & WS_VISIBLE) && (win->dwStyle & WS_MINIMIZE))
1081 unsigned int width, height, border, depth;
1084 LONG style = WS_VISIBLE;
1088 XGetGeometry( event->xmap.display, data->whole_window, &root, &x, &y, &width, &height,
1090 XTranslateCoordinates( event->xmap.display, data->whole_window, root, 0, 0, &x, &y, &top );
1091 wine_tsx11_unlock();
1094 rect.right = x + width;
1095 rect.bottom = y + height;
1096 X11DRV_X_to_window_rect( data, &rect );
1098 invalidate_dce( hwnd, &data->window_rect );
1100 if (win->flags & WIN_RESTORE_MAX) style |= WS_MAXIMIZE;
1101 WIN_SetStyle( hwnd, style, WS_MINIMIZE );
1102 WIN_ReleasePtr( win );
1104 SendMessageA( hwnd, WM_SHOWWINDOW, SW_RESTORE, 0 );
1105 SetWindowPos( hwnd, 0, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
1106 SWP_NOZORDER | SWP_WINE_NOHOSTMOVE );
1108 else WIN_ReleasePtr( win );
1109 if (hwndFocus && IsChild( hwnd, hwndFocus )) X11DRV_SetFocus(hwndFocus); /* FIXME */
1113 /**********************************************************************
1114 * X11DRV_UnmapNotify
1116 void X11DRV_UnmapNotify( HWND hwnd, XEvent *event )
1118 struct x11drv_win_data *data;
1121 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1123 if (!(win = WIN_GetPtr( hwnd ))) return;
1125 if ((win->dwStyle & WS_VISIBLE) && data->managed &&
1126 X11DRV_is_window_rect_mapped( &win->rectWindow ))
1128 if (win->dwStyle & WS_MAXIMIZE)
1129 win->flags |= WIN_RESTORE_MAX;
1131 win->flags &= ~WIN_RESTORE_MAX;
1133 WIN_SetStyle( hwnd, WS_MINIMIZE, WS_MAXIMIZE );
1134 WIN_ReleasePtr( win );
1137 SendMessageA( hwnd, WM_SHOWWINDOW, SW_MINIMIZE, 0 );
1138 SetWindowPos( hwnd, 0, 0, 0, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON),
1139 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_WINE_NOHOSTMOVE );
1141 else WIN_ReleasePtr( win );
1145 /***********************************************************************
1146 * X11DRV_handle_desktop_resize
1148 void X11DRV_handle_desktop_resize( unsigned int width, unsigned int height )
1151 HWND hwnd = GetDesktopWindow();
1153 screen_width = width;
1154 screen_height = height;
1155 TRACE("desktop %p change to (%dx%d)\n", hwnd, width, height);
1156 SetRect( &rect, 0, 0, width, height );
1157 X11DRV_set_window_pos( hwnd, 0, &rect, &rect, SWP_NOZORDER|SWP_NOMOVE|SWP_WINE_NOHOSTMOVE, NULL );
1158 SendMessageTimeoutW( HWND_BROADCAST, WM_DISPLAYCHANGE, screen_depth,
1159 MAKELPARAM( width, height ), SMTO_ABORTIFHUNG, 2000, NULL );
1163 /***********************************************************************
1164 * X11DRV_ConfigureNotify
1166 void X11DRV_ConfigureNotify( HWND hwnd, XEvent *xev )
1168 XConfigureEvent *event = &xev->xconfigure;
1169 struct x11drv_win_data *data;
1172 int cx, cy, x = event->x, y = event->y;
1175 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1179 if (!event->send_event) /* normal event, need to map coordinates to the root */
1183 XTranslateCoordinates( event->display, data->whole_window, root_window,
1184 0, 0, &x, &y, &child );
1185 wine_tsx11_unlock();
1189 rect.right = x + event->width;
1190 rect.bottom = y + event->height;
1191 TRACE( "win %p new X rect %ld,%ld,%ldx%ld (event %d,%d,%dx%d)\n",
1192 hwnd, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
1193 event->x, event->y, event->width, event->height );
1194 X11DRV_X_to_window_rect( data, &rect );
1198 cx = rect.right - rect.left;
1199 cy = rect.bottom - rect.top;
1200 flags = SWP_NOACTIVATE | SWP_NOZORDER | SWP_WINE_NOHOSTMOVE;
1202 /* Compare what has changed */
1204 GetWindowRect( hwnd, &rect );
1205 if (rect.left == x && rect.top == y) flags |= SWP_NOMOVE;
1207 TRACE( "%p moving from (%ld,%ld) to (%d,%d)\n",
1208 hwnd, rect.left, rect.top, x, y );
1210 if ((rect.right - rect.left == cx && rect.bottom - rect.top == cy) ||
1212 (IsRectEmpty( &rect ) && event->width == 1 && event->height == 1))
1214 if (flags & SWP_NOMOVE) return; /* if nothing changed, don't do anything */
1215 flags |= SWP_NOSIZE;
1218 TRACE( "%p resizing from (%ldx%ld) to (%dx%d)\n",
1219 hwnd, rect.right - rect.left, rect.bottom - rect.top, cx, cy );
1221 SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
1225 /***********************************************************************
1226 * SetWindowRgn (X11DRV.@)
1228 * Assign specified region to window (for non-rectangular windows)
1230 int X11DRV_SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL redraw )
1232 struct x11drv_win_data *data;
1234 if (!(data = X11DRV_get_win_data( hwnd )))
1236 if (IsWindow( hwnd ))
1237 FIXME( "not supported on other thread window %p\n", hwnd );
1238 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1242 #ifdef HAVE_LIBXSHAPE
1243 if (data->whole_window)
1245 Display *display = thread_display();
1250 XShapeCombineMask( display, data->whole_window,
1251 ShapeBounding, 0, 0, None, ShapeSet );
1252 wine_tsx11_unlock();
1256 RGNDATA *pRegionData = X11DRV_GetRegionData( hrgn, 0 );
1260 XShapeCombineRectangles( display, data->whole_window, ShapeBounding,
1261 data->window_rect.left - data->whole_rect.left,
1262 data->window_rect.top - data->whole_rect.top,
1263 (XRectangle *)pRegionData->Buffer,
1264 pRegionData->rdh.nCount,
1265 ShapeSet, YXBanded );
1266 wine_tsx11_unlock();
1267 HeapFree(GetProcessHeap(), 0, pRegionData);
1271 #endif /* HAVE_LIBXSHAPE */
1273 invalidate_dce( hwnd, &data->window_rect );
1278 /***********************************************************************
1281 * Draw the frame used when moving or resizing window.
1283 * FIXME: This causes problems in Win95 mode. (why?)
1285 static void draw_moving_frame( HDC hdc, RECT *rect, BOOL thickframe )
1289 const int width = GetSystemMetrics(SM_CXFRAME);
1290 const int height = GetSystemMetrics(SM_CYFRAME);
1292 HBRUSH hbrush = SelectObject( hdc, GetStockObject( GRAY_BRUSH ) );
1293 PatBlt( hdc, rect->left, rect->top,
1294 rect->right - rect->left - width, height, PATINVERT );
1295 PatBlt( hdc, rect->left, rect->top + height, width,
1296 rect->bottom - rect->top - height, PATINVERT );
1297 PatBlt( hdc, rect->left + width, rect->bottom - 1,
1298 rect->right - rect->left - width, -height, PATINVERT );
1299 PatBlt( hdc, rect->right - 1, rect->top, -width,
1300 rect->bottom - rect->top - height, PATINVERT );
1301 SelectObject( hdc, hbrush );
1303 else DrawFocusRect( hdc, rect );
1307 /***********************************************************************
1310 * Initialisation of a move or resize, when initiatied from a menu choice.
1311 * Return hit test code for caption or sizing border.
1313 static LONG start_size_move( HWND hwnd, WPARAM wParam, POINT *capturePoint, LONG style )
1320 GetWindowRect( hwnd, &rectWindow );
1322 if ((wParam & 0xfff0) == SC_MOVE)
1324 /* Move pointer at the center of the caption */
1325 RECT rect = rectWindow;
1326 /* Note: to be exactly centered we should take the different types
1327 * of border into account, but it shouldn't make more that a few pixels
1328 * of difference so let's not bother with that */
1329 rect.top += GetSystemMetrics(SM_CYBORDER);
1330 if (style & WS_SYSMENU)
1331 rect.left += GetSystemMetrics(SM_CXSIZE) + 1;
1332 if (style & WS_MINIMIZEBOX)
1333 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1334 if (style & WS_MAXIMIZEBOX)
1335 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1336 pt.x = (rect.right + rect.left) / 2;
1337 pt.y = rect.top + GetSystemMetrics(SM_CYSIZE)/2;
1338 hittest = HTCAPTION;
1346 GetMessageW( &msg, 0, WM_KEYFIRST, WM_MOUSELAST );
1347 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
1353 hittest = SendMessageW( hwnd, WM_NCHITTEST, 0, MAKELONG( pt.x, pt.y ) );
1354 if ((hittest < HTLEFT) || (hittest > HTBOTTOMRIGHT)) hittest = 0;
1365 pt.x =(rectWindow.left+rectWindow.right)/2;
1366 pt.y = rectWindow.top + GetSystemMetrics(SM_CYFRAME) / 2;
1370 pt.x =(rectWindow.left+rectWindow.right)/2;
1371 pt.y = rectWindow.bottom - GetSystemMetrics(SM_CYFRAME) / 2;
1375 pt.x = rectWindow.left + GetSystemMetrics(SM_CXFRAME) / 2;
1376 pt.y =(rectWindow.top+rectWindow.bottom)/2;
1380 pt.x = rectWindow.right - GetSystemMetrics(SM_CXFRAME) / 2;
1381 pt.y =(rectWindow.top+rectWindow.bottom)/2;
1384 case VK_ESCAPE: return 0;
1390 SetCursorPos( pt.x, pt.y );
1391 SendMessageW( hwnd, WM_SETCURSOR, (WPARAM)hwnd, MAKELONG( hittest, WM_MOUSEMOVE ));
1396 /***********************************************************************
1397 * set_movesize_capture
1399 static void set_movesize_capture( HWND hwnd )
1403 SERVER_START_REQ( set_capture_window )
1406 req->flags = CAPTURE_MOVESIZE;
1407 if (!wine_server_call_err( req ))
1409 previous = reply->previous;
1410 hwnd = reply->full_handle;
1414 if (previous && previous != hwnd)
1415 SendMessageW( previous, WM_CAPTURECHANGED, 0, (LPARAM)hwnd );
1418 /***********************************************************************
1419 * X11DRV_WMMoveResizeWindow
1421 * Tells the window manager to initiate a move or resize operation.
1424 * http://freedesktop.org/Standards/wm-spec/1.3/ar01s04.html
1425 * or search for "_NET_WM_MOVERESIZE"
1427 static void X11DRV_WMMoveResizeWindow( HWND hwnd, int x, int y, int dir )
1430 Display *display = thread_display();
1432 xev.xclient.type = ClientMessage;
1433 xev.xclient.window = X11DRV_get_whole_window(hwnd);
1434 xev.xclient.message_type = x11drv_atom(_NET_WM_MOVERESIZE);
1435 xev.xclient.serial = 0;
1436 xev.xclient.display = display;
1437 xev.xclient.send_event = True;
1438 xev.xclient.format = 32;
1439 xev.xclient.data.l[0] = x; /* x coord */
1440 xev.xclient.data.l[1] = y; /* y coord */
1441 xev.xclient.data.l[2] = dir; /* direction */
1442 xev.xclient.data.l[3] = 1; /* button */
1443 xev.xclient.data.l[4] = 0; /* unused */
1445 /* need to ungrab the pointer that may have been automatically grabbed
1446 * with a ButtonPress event */
1448 XUngrabPointer( display, CurrentTime );
1449 XSendEvent(display, root_window, False, SubstructureNotifyMask, &xev);
1450 wine_tsx11_unlock();
1453 /***********************************************************************
1454 * SysCommandSizeMove (X11DRV.@)
1456 * Perform SC_MOVE and SC_SIZE commands.
1458 void X11DRV_SysCommandSizeMove( HWND hwnd, WPARAM wParam )
1461 RECT sizingRect, mouseRect, origRect;
1464 LONG hittest = (LONG)(wParam & 0x0f);
1465 WPARAM syscommand = wParam & 0xfff0;
1466 HCURSOR hDragCursor = 0, hOldCursor = 0;
1467 POINT minTrack, maxTrack;
1468 POINT capturePoint, pt;
1469 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
1470 BOOL thickframe = HAS_THICKFRAME( style );
1471 BOOL iconic = style & WS_MINIMIZE;
1473 DWORD dwPoint = GetMessagePos ();
1474 BOOL DragFullWindows = FALSE;
1476 Window parent_win, whole_win;
1477 Display *old_gdi_display = NULL;
1478 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1479 struct x11drv_win_data *data;
1481 pt.x = (short)LOWORD(dwPoint);
1482 pt.y = (short)HIWORD(dwPoint);
1485 if (IsZoomed(hwnd) || !IsWindowVisible(hwnd)) return;
1487 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1489 /* if we are managed then we let the WM do all the work */
1493 if (syscommand == SC_MOVE)
1495 if (!hittest) dir = _NET_WM_MOVERESIZE_MOVE_KEYBOARD;
1496 else dir = _NET_WM_MOVERESIZE_MOVE;
1498 else if (!hittest) dir = _NET_WM_MOVERESIZE_SIZE_KEYBOARD;
1502 case WMSZ_LEFT: dir = _NET_WM_MOVERESIZE_SIZE_LEFT; break;
1503 case WMSZ_RIGHT: dir = _NET_WM_MOVERESIZE_SIZE_RIGHT; break;
1504 case WMSZ_TOP: dir = _NET_WM_MOVERESIZE_SIZE_TOP; break;
1505 case WMSZ_TOPLEFT: dir = _NET_WM_MOVERESIZE_SIZE_TOPLEFT; break;
1506 case WMSZ_TOPRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT; break;
1507 case WMSZ_BOTTOM: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOM; break;
1508 case WMSZ_BOTTOMLEFT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT; break;
1509 case WMSZ_BOTTOMRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT; break;
1511 ERR("Invalid hittest value: %ld\n", hittest);
1512 dir = _NET_WM_MOVERESIZE_SIZE_KEYBOARD;
1514 X11DRV_WMMoveResizeWindow( hwnd, pt.x, pt.y, dir );
1518 SystemParametersInfoA(SPI_GETDRAGFULLWINDOWS, 0, &DragFullWindows, 0);
1520 if (syscommand == SC_MOVE)
1522 if (!hittest) hittest = start_size_move( hwnd, wParam, &capturePoint, style );
1523 if (!hittest) return;
1527 if ( hittest && (syscommand != SC_MOUSEMENU) )
1528 hittest += (HTLEFT - WMSZ_LEFT);
1531 set_movesize_capture( hwnd );
1532 hittest = start_size_move( hwnd, wParam, &capturePoint, style );
1535 set_movesize_capture(0);
1541 /* Get min/max info */
1543 WINPOS_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack );
1544 GetWindowRect( hwnd, &sizingRect );
1545 if (style & WS_CHILD)
1547 parent = GetParent(hwnd);
1548 /* make sizing rect relative to parent */
1549 MapWindowPoints( 0, parent, (POINT*)&sizingRect, 2 );
1550 GetClientRect( parent, &mouseRect );
1555 SetRect(&mouseRect, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
1557 origRect = sizingRect;
1559 if (ON_LEFT_BORDER(hittest))
1561 mouseRect.left = max( mouseRect.left, sizingRect.right-maxTrack.x );
1562 mouseRect.right = min( mouseRect.right, sizingRect.right-minTrack.x );
1564 else if (ON_RIGHT_BORDER(hittest))
1566 mouseRect.left = max( mouseRect.left, sizingRect.left+minTrack.x );
1567 mouseRect.right = min( mouseRect.right, sizingRect.left+maxTrack.x );
1569 if (ON_TOP_BORDER(hittest))
1571 mouseRect.top = max( mouseRect.top, sizingRect.bottom-maxTrack.y );
1572 mouseRect.bottom = min( mouseRect.bottom,sizingRect.bottom-minTrack.y);
1574 else if (ON_BOTTOM_BORDER(hittest))
1576 mouseRect.top = max( mouseRect.top, sizingRect.top+minTrack.y );
1577 mouseRect.bottom = min( mouseRect.bottom, sizingRect.top+maxTrack.y );
1579 if (parent) MapWindowPoints( parent, 0, (LPPOINT)&mouseRect, 2 );
1581 /* Retrieve a default cache DC (without using the window style) */
1582 hdc = GetDCEx( parent, 0, DCX_CACHE );
1584 if( iconic ) /* create a cursor for dragging */
1586 hDragCursor = (HCURSOR)GetClassLongPtrW( hwnd, GCLP_HICON);
1587 if( !hDragCursor ) hDragCursor = (HCURSOR)SendMessageW( hwnd, WM_QUERYDRAGICON, 0, 0L);
1588 if( !hDragCursor ) iconic = FALSE;
1591 /* repaint the window before moving it around */
1592 RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN );
1594 SendMessageA( hwnd, WM_ENTERSIZEMOVE, 0, 0 );
1595 set_movesize_capture( hwnd );
1597 /* grab the server only when moving top-level windows without desktop */
1598 grab = (!DragFullWindows && !parent && (root_window == DefaultRootWindow(gdi_display)));
1603 XSync( gdi_display, False );
1604 XGrabServer( thread_data->display );
1605 XSync( thread_data->display, False );
1606 /* switch gdi display to the thread display, since the server is grabbed */
1607 old_gdi_display = gdi_display;
1608 gdi_display = thread_data->display;
1609 wine_tsx11_unlock();
1611 whole_win = X11DRV_get_whole_window( GetAncestor(hwnd,GA_ROOT) );
1612 parent_win = parent ? X11DRV_get_whole_window( GetAncestor(parent,GA_ROOT) ) : root_window;
1615 XGrabPointer( thread_data->display, whole_win, False,
1616 PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
1617 GrabModeAsync, GrabModeAsync, parent_win, None, CurrentTime );
1618 wine_tsx11_unlock();
1619 thread_data->grab_window = whole_win;
1625 if (!GetMessageW( &msg, 0, WM_KEYFIRST, WM_MOUSELAST )) break;
1626 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
1628 /* Exit on button-up, Return, or Esc */
1629 if ((msg.message == WM_LBUTTONUP) ||
1630 ((msg.message == WM_KEYDOWN) &&
1631 ((msg.wParam == VK_RETURN) || (msg.wParam == VK_ESCAPE)))) break;
1633 if ((msg.message != WM_KEYDOWN) && (msg.message != WM_MOUSEMOVE))
1634 continue; /* We are not interested in other messages */
1638 if (msg.message == WM_KEYDOWN) switch(msg.wParam)
1640 case VK_UP: pt.y -= 8; break;
1641 case VK_DOWN: pt.y += 8; break;
1642 case VK_LEFT: pt.x -= 8; break;
1643 case VK_RIGHT: pt.x += 8; break;
1646 pt.x = max( pt.x, mouseRect.left );
1647 pt.x = min( pt.x, mouseRect.right );
1648 pt.y = max( pt.y, mouseRect.top );
1649 pt.y = min( pt.y, mouseRect.bottom );
1651 dx = pt.x - capturePoint.x;
1652 dy = pt.y - capturePoint.y;
1660 if( iconic ) /* ok, no system popup tracking */
1662 hOldCursor = SetCursor(hDragCursor);
1664 WINPOS_ShowIconTitle( hwnd, FALSE );
1666 else if(!DragFullWindows)
1667 draw_moving_frame( hdc, &sizingRect, thickframe );
1670 if (msg.message == WM_KEYDOWN) SetCursorPos( pt.x, pt.y );
1673 RECT newRect = sizingRect;
1674 WPARAM wpSizingHit = 0;
1676 if (hittest == HTCAPTION) OffsetRect( &newRect, dx, dy );
1677 if (ON_LEFT_BORDER(hittest)) newRect.left += dx;
1678 else if (ON_RIGHT_BORDER(hittest)) newRect.right += dx;
1679 if (ON_TOP_BORDER(hittest)) newRect.top += dy;
1680 else if (ON_BOTTOM_BORDER(hittest)) newRect.bottom += dy;
1681 if(!iconic && !DragFullWindows) draw_moving_frame( hdc, &sizingRect, thickframe );
1684 /* determine the hit location */
1685 if (hittest >= HTLEFT && hittest <= HTBOTTOMRIGHT)
1686 wpSizingHit = WMSZ_LEFT + (hittest - HTLEFT);
1687 SendMessageA( hwnd, WM_SIZING, wpSizingHit, (LPARAM)&newRect );
1691 if(!DragFullWindows)
1692 draw_moving_frame( hdc, &newRect, thickframe );
1694 SetWindowPos( hwnd, 0, newRect.left, newRect.top,
1695 newRect.right - newRect.left,
1696 newRect.bottom - newRect.top,
1697 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
1699 sizingRect = newRect;
1704 set_movesize_capture(0);
1707 if( moved ) /* restore cursors, show icon title later on */
1709 ShowCursor( FALSE );
1710 SetCursor( hOldCursor );
1713 else if (moved && !DragFullWindows)
1714 draw_moving_frame( hdc, &sizingRect, thickframe );
1716 ReleaseDC( parent, hdc );
1719 XUngrabPointer( thread_data->display, CurrentTime );
1722 XSync( thread_data->display, False );
1723 XUngrabServer( thread_data->display );
1724 XSync( thread_data->display, False );
1725 gdi_display = old_gdi_display;
1727 wine_tsx11_unlock();
1728 thread_data->grab_window = None;
1730 if (HOOK_CallHooks( WH_CBT, HCBT_MOVESIZE, (WPARAM)hwnd, (LPARAM)&sizingRect, TRUE ))
1733 SendMessageA( hwnd, WM_EXITSIZEMOVE, 0, 0 );
1734 SendMessageA( hwnd, WM_SETVISIBLE, !IsIconic(hwnd), 0L);
1736 /* window moved or resized */
1739 /* if the moving/resizing isn't canceled call SetWindowPos
1740 * with the new position or the new size of the window
1742 if (!((msg.message == WM_KEYDOWN) && (msg.wParam == VK_ESCAPE)) )
1744 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
1745 if(!DragFullWindows)
1746 SetWindowPos( hwnd, 0, sizingRect.left, sizingRect.top,
1747 sizingRect.right - sizingRect.left,
1748 sizingRect.bottom - sizingRect.top,
1749 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
1752 { /* restore previous size/position */
1754 SetWindowPos( hwnd, 0, origRect.left, origRect.top,
1755 origRect.right - origRect.left,
1756 origRect.bottom - origRect.top,
1757 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
1763 /* Single click brings up the system menu when iconized */
1767 if(style & WS_SYSMENU )
1768 SendMessageA( hwnd, WM_SYSCOMMAND,
1769 SC_MOUSEMENU + HTSYSMENU, MAKELONG(pt.x,pt.y));
1771 else WINPOS_ShowIconTitle( hwnd, TRUE );