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 || data->whole_window == DefaultRootWindow(gdi_display))
591 data->whole_rect = data->client_rect = data->window_rect = *rectWindow;
592 if (win != WND_DESKTOP)
594 win->rectWindow = *rectWindow;
595 win->rectClient = *rectClient;
596 win->dwStyle = new_style;
597 WIN_ReleasePtr( win );
604 Display *display = thread_display();
606 /* invalidate DCEs */
608 if ((((swp_flags & SWP_AGG_NOPOSCHANGE) != SWP_AGG_NOPOSCHANGE) && (new_style & WS_VISIBLE)) ||
609 (swp_flags & (SWP_HIDEWINDOW | SWP_SHOWWINDOW)))
612 UnionRect( &rect, rectWindow, &win->rectWindow );
613 invalidate_dce( hwnd, &rect );
616 win->rectWindow = *rectWindow;
617 win->rectClient = *rectClient;
618 old_style = win->dwStyle;
619 win->dwStyle = new_style;
620 data->window_rect = *rectWindow;
622 TRACE( "win %p window %s client %s style %08lx\n",
623 hwnd, wine_dbgstr_rect(rectWindow), wine_dbgstr_rect(rectClient), new_style );
625 /* FIXME: copy the valid bits */
627 if (data->whole_window && !(swp_flags & SWP_WINE_NOHOSTMOVE))
629 if ((old_style & WS_VISIBLE) && !(new_style & WS_VISIBLE))
631 /* window got hidden, unmap it */
632 TRACE( "unmapping win %p\n", hwnd );
634 XUnmapWindow( display, data->whole_window );
637 else if ((new_style & WS_VISIBLE) && !X11DRV_is_window_rect_mapped( rectWindow ))
639 /* resizing to zero size or off screen -> unmap */
640 TRACE( "unmapping zero size or off-screen win %p\n", hwnd );
642 XUnmapWindow( display, data->whole_window );
647 X11DRV_sync_window_position( display, data, swp_flags, rectClient, &new_whole_rect );
649 if (data->whole_window && !(swp_flags & SWP_WINE_NOHOSTMOVE))
651 if ((new_style & WS_VISIBLE) && !(new_style & WS_MINIMIZE) &&
652 X11DRV_is_window_rect_mapped( rectWindow ))
654 if (!(old_style & WS_VISIBLE))
656 /* window got shown, map it */
657 TRACE( "mapping win %p\n", hwnd );
658 X11DRV_sync_window_style( display, data );
659 X11DRV_set_wm_hints( display, data );
661 XMapWindow( display, data->whole_window );
664 else if ((swp_flags & (SWP_NOSIZE | SWP_NOMOVE)) != (SWP_NOSIZE | SWP_NOMOVE))
666 /* resizing from zero size to non-zero -> map */
667 TRACE( "mapping non zero size or off-screen win %p\n", hwnd );
669 XMapWindow( display, data->whole_window );
674 XFlush( display ); /* FIXME: should not be necessary */
678 WIN_ReleasePtr( win );
683 /***********************************************************************
684 * SetWindowPos (X11DRV.@)
686 BOOL X11DRV_SetWindowPos( WINDOWPOS *winpos )
688 RECT newWindowRect, newClientRect, valid_rects[2];
691 TRACE( "hwnd %p, after %p, swp %d,%d %dx%d flags %08x\n",
692 winpos->hwnd, winpos->hwndInsertAfter, winpos->x, winpos->y,
693 winpos->cx, winpos->cy, winpos->flags);
695 orig_flags = winpos->flags;
696 winpos->flags &= ~SWP_WINE_NOHOSTMOVE;
698 /* Check window handle */
699 if (winpos->hwnd == GetDesktopWindow()) return FALSE;
701 /* First make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
702 if (!(winpos->flags & SWP_NOMOVE))
704 if (winpos->x < -32768) winpos->x = -32768;
705 else if (winpos->x > 32767) winpos->x = 32767;
706 if (winpos->y < -32768) winpos->y = -32768;
707 else if (winpos->y > 32767) winpos->y = 32767;
709 if (!(winpos->flags & SWP_NOSIZE))
711 if (winpos->cx < 0) winpos->cx = 0;
712 else if (winpos->cx > 32767) winpos->cx = 32767;
713 if (winpos->cy < 0) winpos->cy = 0;
714 else if (winpos->cy > 32767) winpos->cy = 32767;
717 if (!SWP_DoWinPosChanging( winpos, &newWindowRect, &newClientRect )) return FALSE;
719 /* Fix redundant flags */
720 if (!fixup_flags( winpos )) return FALSE;
722 if((winpos->flags & (SWP_NOZORDER | SWP_HIDEWINDOW | SWP_SHOWWINDOW)) != SWP_NOZORDER)
724 if (GetAncestor( winpos->hwnd, GA_PARENT ) == GetDesktopWindow())
725 winpos->hwndInsertAfter = SWP_DoOwnedPopups( winpos->hwnd, winpos->hwndInsertAfter );
728 /* Common operations */
730 SWP_DoNCCalcSize( winpos, &newWindowRect, &newClientRect, valid_rects );
732 if (!X11DRV_set_window_pos( winpos->hwnd, winpos->hwndInsertAfter,
733 &newWindowRect, &newClientRect, orig_flags, valid_rects ))
736 if (!(orig_flags & SWP_SHOWWINDOW))
738 UINT rdw_flags = RDW_FRAME | RDW_ERASE;
739 if ( !(orig_flags & SWP_DEFERERASE) ) rdw_flags |= RDW_ERASENOW;
740 RedrawWindow( winpos->hwnd, NULL, NULL, rdw_flags );
743 if( winpos->flags & SWP_HIDEWINDOW )
744 HideCaret(winpos->hwnd);
745 else if (winpos->flags & SWP_SHOWWINDOW)
746 ShowCaret(winpos->hwnd);
748 if (!(winpos->flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW)))
750 /* child windows get WM_CHILDACTIVATE message */
751 if ((GetWindowLongW( winpos->hwnd, GWL_STYLE ) & (WS_CHILD | WS_POPUP)) == WS_CHILD)
752 SendMessageA( winpos->hwnd, WM_CHILDACTIVATE, 0, 0 );
754 SetForegroundWindow( winpos->hwnd );
757 /* And last, send the WM_WINDOWPOSCHANGED message */
759 TRACE("\tstatus flags = %04x\n", winpos->flags & SWP_AGG_STATUSFLAGS);
761 if (((winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOPOSCHANGE))
763 /* WM_WINDOWPOSCHANGED is sent even if SWP_NOSENDCHANGING is set
764 and always contains final window position.
766 winpos->x = newWindowRect.left;
767 winpos->y = newWindowRect.top;
768 winpos->cx = newWindowRect.right - newWindowRect.left;
769 winpos->cy = newWindowRect.bottom - newWindowRect.top;
770 SendMessageW( winpos->hwnd, WM_WINDOWPOSCHANGED, 0, (LPARAM)winpos );
777 /***********************************************************************
780 * Find a suitable place for an iconic window.
782 static POINT WINPOS_FindIconPos( HWND hwnd, POINT pt )
784 RECT rect, rectParent;
787 int xspacing, yspacing;
789 parent = GetAncestor( hwnd, GA_PARENT );
790 GetClientRect( parent, &rectParent );
791 if ((pt.x >= rectParent.left) && (pt.x + GetSystemMetrics(SM_CXICON) < rectParent.right) &&
792 (pt.y >= rectParent.top) && (pt.y + GetSystemMetrics(SM_CYICON) < rectParent.bottom))
793 return pt; /* The icon already has a suitable position */
795 xspacing = GetSystemMetrics(SM_CXICONSPACING);
796 yspacing = GetSystemMetrics(SM_CYICONSPACING);
798 /* Check if another icon already occupies this spot */
799 /* FIXME: this is completely inefficient */
801 hrgn = CreateRectRgn( 0, 0, 0, 0 );
802 tmp = CreateRectRgn( 0, 0, 0, 0 );
803 for (child = GetWindow( parent, GW_HWNDFIRST ); child; child = GetWindow( child, GW_HWNDNEXT ))
806 if (child == hwnd) continue;
807 if ((GetWindowLongW( child, GWL_STYLE ) & (WS_VISIBLE|WS_MINIMIZE)) != (WS_VISIBLE|WS_MINIMIZE))
809 if (!(childPtr = WIN_GetPtr( child )) || childPtr == WND_OTHER_PROCESS)
811 SetRectRgn( tmp, childPtr->rectWindow.left, childPtr->rectWindow.top,
812 childPtr->rectWindow.right, childPtr->rectWindow.bottom );
813 CombineRgn( hrgn, hrgn, tmp, RGN_OR );
814 WIN_ReleasePtr( childPtr );
818 for (rect.bottom = rectParent.bottom; rect.bottom >= yspacing; rect.bottom -= yspacing)
820 for (rect.left = rectParent.left; rect.left <= rectParent.right - xspacing; rect.left += xspacing)
822 rect.right = rect.left + xspacing;
823 rect.top = rect.bottom - yspacing;
824 if (!RectInRegion( hrgn, &rect ))
826 /* No window was found, so it's OK for us */
827 pt.x = rect.left + (xspacing - GetSystemMetrics(SM_CXICON)) / 2;
828 pt.y = rect.top + (yspacing - GetSystemMetrics(SM_CYICON)) / 2;
829 DeleteObject( hrgn );
834 DeleteObject( hrgn );
843 UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect )
851 TRACE("%p %u\n", hwnd, cmd );
853 wpl.length = sizeof(wpl);
854 GetWindowPlacement( hwnd, &wpl );
856 if (HOOK_CallHooks( WH_CBT, HCBT_MINMAX, (WPARAM)hwnd, cmd, TRUE ))
857 return SWP_NOSIZE | SWP_NOMOVE;
859 if (IsIconic( hwnd ))
861 if (cmd == SW_MINIMIZE) return SWP_NOSIZE | SWP_NOMOVE;
862 if (!SendMessageW( hwnd, WM_QUERYOPEN, 0, 0 )) return SWP_NOSIZE | SWP_NOMOVE;
863 swpFlags |= SWP_NOCOPYBITS;
869 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
870 if( wndPtr->dwStyle & WS_MAXIMIZE) wndPtr->flags |= WIN_RESTORE_MAX;
871 else wndPtr->flags &= ~WIN_RESTORE_MAX;
872 WIN_ReleasePtr( wndPtr );
874 WIN_SetStyle( hwnd, WS_MINIMIZE, WS_MAXIMIZE );
876 X11DRV_set_iconic_state( hwnd );
878 wpl.ptMinPosition = WINPOS_FindIconPos( hwnd, wpl.ptMinPosition );
880 SetRect( rect, wpl.ptMinPosition.x, wpl.ptMinPosition.y,
881 GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON) );
882 swpFlags |= SWP_NOCOPYBITS;
886 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL );
888 old_style = WIN_SetStyle( hwnd, WS_MAXIMIZE, WS_MINIMIZE );
889 if (old_style & WS_MINIMIZE)
891 WINPOS_ShowIconTitle( hwnd, FALSE );
892 X11DRV_set_iconic_state( hwnd );
894 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y );
898 old_style = WIN_SetStyle( hwnd, 0, WS_MINIMIZE | WS_MAXIMIZE );
899 if (old_style & WS_MINIMIZE)
903 WINPOS_ShowIconTitle( hwnd, FALSE );
904 X11DRV_set_iconic_state( hwnd );
906 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
907 restore_max = (wndPtr->flags & WIN_RESTORE_MAX) != 0;
908 WIN_ReleasePtr( wndPtr );
911 /* Restore to maximized position */
912 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL);
913 WIN_SetStyle( hwnd, WS_MAXIMIZE, 0 );
914 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y );
918 else if (!(old_style & WS_MAXIMIZE)) break;
920 /* Restore to normal position */
922 *rect = wpl.rcNormalPosition;
923 rect->right -= rect->left;
924 rect->bottom -= rect->top;
933 /***********************************************************************
934 * ShowWindow (X11DRV.@)
936 BOOL X11DRV_ShowWindow( HWND hwnd, INT cmd )
939 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
940 BOOL wasVisible = (style & WS_VISIBLE) != 0;
941 BOOL showFlag = TRUE;
942 RECT newPos = {0, 0, 0, 0};
945 TRACE("hwnd=%p, cmd=%d, wasVisible %d\n", hwnd, cmd, wasVisible);
950 if (!wasVisible) return FALSE;
952 swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE;
953 if (hwnd != GetActiveWindow())
954 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
957 case SW_SHOWMINNOACTIVE:
958 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
960 case SW_SHOWMINIMIZED:
961 case SW_FORCEMINIMIZE: /* FIXME: Does not work if thread is hung. */
962 swp |= SWP_SHOWWINDOW;
965 swp |= SWP_FRAMECHANGED;
966 if( !(style & WS_MINIMIZE) )
967 swp |= WINPOS_MinMaximize( hwnd, SW_MINIMIZE, &newPos );
968 else swp |= SWP_NOSIZE | SWP_NOMOVE;
971 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
972 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
973 swp |= WINPOS_MinMaximize( hwnd, SW_MAXIMIZE, &newPos );
977 swp |= SWP_NOACTIVATE | SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
978 if (style & WS_CHILD) swp |= SWP_NOZORDER;
981 if (wasVisible) return TRUE;
982 swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
986 swp |= SWP_FRAMECHANGED;
988 case SW_SHOWNOACTIVATE:
989 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
991 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
992 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
993 swp |= SWP_SHOWWINDOW;
995 if (style & (WS_MINIMIZE | WS_MAXIMIZE))
996 swp |= WINPOS_MinMaximize( hwnd, SW_RESTORE, &newPos );
997 else swp |= SWP_NOSIZE | SWP_NOMOVE;
1001 if ((showFlag != wasVisible || cmd == SW_SHOWNA) && cmd != SW_SHOWMAXIMIZED)
1003 SendMessageW( hwnd, WM_SHOWWINDOW, showFlag, 0 );
1004 if (!IsWindow( hwnd )) return wasVisible;
1007 if (!IsWindowVisible( GetAncestor( hwnd, GA_PARENT )))
1009 /* if parent is not visible simply toggle WS_VISIBLE and return */
1010 if (showFlag) WIN_SetStyle( hwnd, WS_VISIBLE, 0 );
1011 else WIN_SetStyle( hwnd, 0, WS_VISIBLE );
1015 /* ShowWindow won't activate a not being maximized child window */
1016 if ((style & WS_CHILD) && cmd != SW_MAXIMIZE)
1017 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1019 SetWindowPos( hwnd, HWND_TOP, newPos.left, newPos.top,
1020 newPos.right, newPos.bottom, LOWORD(swp) );
1027 /* FIXME: This will cause the window to be activated irrespective
1028 * of whether it is owned by the same thread. Has to be done
1032 if (hwnd == GetActiveWindow())
1033 WINPOS_ActivateOtherWindow(hwnd);
1035 /* Revert focus to parent */
1036 hFocus = GetFocus();
1037 if (hwnd == hFocus || IsChild(hwnd, hFocus))
1039 HWND parent = GetAncestor(hwnd, GA_PARENT);
1040 if (parent == GetDesktopWindow()) parent = 0;
1045 if (IsIconic(hwnd)) WINPOS_ShowIconTitle( hwnd, TRUE );
1047 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return wasVisible;
1049 if (wndPtr->flags & WIN_NEED_SIZE)
1051 /* should happen only in CreateWindowEx() */
1052 int wParam = SIZE_RESTORED;
1053 RECT client = wndPtr->rectClient;
1055 wndPtr->flags &= ~WIN_NEED_SIZE;
1056 if (wndPtr->dwStyle & WS_MAXIMIZE) wParam = SIZE_MAXIMIZED;
1057 else if (wndPtr->dwStyle & WS_MINIMIZE) wParam = SIZE_MINIMIZED;
1058 WIN_ReleasePtr( wndPtr );
1060 SendMessageW( hwnd, WM_SIZE, wParam,
1061 MAKELONG( client.right - client.left, client.bottom - client.top ));
1062 SendMessageW( hwnd, WM_MOVE, 0, MAKELONG( client.left, client.top ));
1064 else WIN_ReleasePtr( wndPtr );
1070 /**********************************************************************
1073 void X11DRV_MapNotify( HWND hwnd, XEvent *event )
1075 struct x11drv_win_data *data;
1076 HWND hwndFocus = GetFocus();
1079 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1081 if (!(win = WIN_GetPtr( hwnd ))) return;
1083 if (data->managed && (win->dwStyle & WS_VISIBLE) && (win->dwStyle & WS_MINIMIZE))
1086 unsigned int width, height, border, depth;
1089 LONG style = WS_VISIBLE;
1093 XGetGeometry( event->xmap.display, data->whole_window, &root, &x, &y, &width, &height,
1095 XTranslateCoordinates( event->xmap.display, data->whole_window, root, 0, 0, &x, &y, &top );
1096 wine_tsx11_unlock();
1099 rect.right = x + width;
1100 rect.bottom = y + height;
1101 X11DRV_X_to_window_rect( data, &rect );
1103 invalidate_dce( hwnd, &data->window_rect );
1105 if (win->flags & WIN_RESTORE_MAX) style |= WS_MAXIMIZE;
1106 WIN_SetStyle( hwnd, style, WS_MINIMIZE );
1107 WIN_ReleasePtr( win );
1109 SendMessageA( hwnd, WM_SHOWWINDOW, SW_RESTORE, 0 );
1110 SetWindowPos( hwnd, 0, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
1111 SWP_NOZORDER | SWP_WINE_NOHOSTMOVE );
1113 else WIN_ReleasePtr( win );
1114 if (hwndFocus && IsChild( hwnd, hwndFocus )) X11DRV_SetFocus(hwndFocus); /* FIXME */
1118 /**********************************************************************
1119 * X11DRV_UnmapNotify
1121 void X11DRV_UnmapNotify( HWND hwnd, XEvent *event )
1123 struct x11drv_win_data *data;
1126 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1128 if (!(win = WIN_GetPtr( hwnd ))) return;
1130 if ((win->dwStyle & WS_VISIBLE) && data->managed &&
1131 X11DRV_is_window_rect_mapped( &win->rectWindow ))
1133 if (win->dwStyle & WS_MAXIMIZE)
1134 win->flags |= WIN_RESTORE_MAX;
1136 win->flags &= ~WIN_RESTORE_MAX;
1138 WIN_SetStyle( hwnd, WS_MINIMIZE, WS_MAXIMIZE );
1139 WIN_ReleasePtr( win );
1142 SendMessageA( hwnd, WM_SHOWWINDOW, SW_MINIMIZE, 0 );
1143 SetWindowPos( hwnd, 0, 0, 0, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON),
1144 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_WINE_NOHOSTMOVE );
1146 else WIN_ReleasePtr( win );
1150 /***********************************************************************
1151 * X11DRV_handle_desktop_resize
1153 void X11DRV_handle_desktop_resize( unsigned int width, unsigned int height )
1156 HWND hwnd = GetDesktopWindow();
1158 screen_width = width;
1159 screen_height = height;
1160 TRACE("desktop %p change to (%dx%d)\n", hwnd, width, height);
1161 SetRect( &rect, 0, 0, width, height );
1162 X11DRV_set_window_pos( hwnd, 0, &rect, &rect, SWP_NOZORDER|SWP_NOMOVE|SWP_WINE_NOHOSTMOVE, NULL );
1163 SendMessageTimeoutW( HWND_BROADCAST, WM_DISPLAYCHANGE, screen_depth,
1164 MAKELPARAM( width, height ), SMTO_ABORTIFHUNG, 2000, NULL );
1168 /***********************************************************************
1169 * X11DRV_ConfigureNotify
1171 void X11DRV_ConfigureNotify( HWND hwnd, XEvent *xev )
1173 XConfigureEvent *event = &xev->xconfigure;
1174 struct x11drv_win_data *data;
1177 int cx, cy, x = event->x, y = event->y;
1180 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1184 if (!event->send_event) /* normal event, need to map coordinates to the root */
1188 XTranslateCoordinates( event->display, data->whole_window, root_window,
1189 0, 0, &x, &y, &child );
1190 wine_tsx11_unlock();
1194 rect.right = x + event->width;
1195 rect.bottom = y + event->height;
1196 TRACE( "win %p new X rect %ld,%ld,%ldx%ld (event %d,%d,%dx%d)\n",
1197 hwnd, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
1198 event->x, event->y, event->width, event->height );
1199 X11DRV_X_to_window_rect( data, &rect );
1203 cx = rect.right - rect.left;
1204 cy = rect.bottom - rect.top;
1205 flags = SWP_NOACTIVATE | SWP_NOZORDER | SWP_WINE_NOHOSTMOVE;
1207 /* Compare what has changed */
1209 GetWindowRect( hwnd, &rect );
1210 if (rect.left == x && rect.top == y) flags |= SWP_NOMOVE;
1212 TRACE( "%p moving from (%ld,%ld) to (%d,%d)\n",
1213 hwnd, rect.left, rect.top, x, y );
1215 if ((rect.right - rect.left == cx && rect.bottom - rect.top == cy) ||
1217 (IsRectEmpty( &rect ) && event->width == 1 && event->height == 1))
1219 if (flags & SWP_NOMOVE) return; /* if nothing changed, don't do anything */
1220 flags |= SWP_NOSIZE;
1223 TRACE( "%p resizing from (%ldx%ld) to (%dx%d)\n",
1224 hwnd, rect.right - rect.left, rect.bottom - rect.top, cx, cy );
1226 SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
1230 /***********************************************************************
1231 * SetWindowRgn (X11DRV.@)
1233 * Assign specified region to window (for non-rectangular windows)
1235 int X11DRV_SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL redraw )
1237 struct x11drv_win_data *data;
1239 if (!(data = X11DRV_get_win_data( hwnd )))
1241 if (IsWindow( hwnd ))
1242 FIXME( "not supported on other thread window %p\n", hwnd );
1243 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1247 #ifdef HAVE_LIBXSHAPE
1248 if (data->whole_window)
1250 Display *display = thread_display();
1255 XShapeCombineMask( display, data->whole_window,
1256 ShapeBounding, 0, 0, None, ShapeSet );
1257 wine_tsx11_unlock();
1261 RGNDATA *pRegionData = X11DRV_GetRegionData( hrgn, 0 );
1265 XShapeCombineRectangles( display, data->whole_window, ShapeBounding,
1266 data->window_rect.left - data->whole_rect.left,
1267 data->window_rect.top - data->whole_rect.top,
1268 (XRectangle *)pRegionData->Buffer,
1269 pRegionData->rdh.nCount,
1270 ShapeSet, YXBanded );
1271 wine_tsx11_unlock();
1272 HeapFree(GetProcessHeap(), 0, pRegionData);
1276 #endif /* HAVE_LIBXSHAPE */
1278 invalidate_dce( hwnd, &data->window_rect );
1283 /***********************************************************************
1286 * Draw the frame used when moving or resizing window.
1288 * FIXME: This causes problems in Win95 mode. (why?)
1290 static void draw_moving_frame( HDC hdc, RECT *rect, BOOL thickframe )
1294 const int width = GetSystemMetrics(SM_CXFRAME);
1295 const int height = GetSystemMetrics(SM_CYFRAME);
1297 HBRUSH hbrush = SelectObject( hdc, GetStockObject( GRAY_BRUSH ) );
1298 PatBlt( hdc, rect->left, rect->top,
1299 rect->right - rect->left - width, height, PATINVERT );
1300 PatBlt( hdc, rect->left, rect->top + height, width,
1301 rect->bottom - rect->top - height, PATINVERT );
1302 PatBlt( hdc, rect->left + width, rect->bottom - 1,
1303 rect->right - rect->left - width, -height, PATINVERT );
1304 PatBlt( hdc, rect->right - 1, rect->top, -width,
1305 rect->bottom - rect->top - height, PATINVERT );
1306 SelectObject( hdc, hbrush );
1308 else DrawFocusRect( hdc, rect );
1312 /***********************************************************************
1315 * Initialisation of a move or resize, when initiatied from a menu choice.
1316 * Return hit test code for caption or sizing border.
1318 static LONG start_size_move( HWND hwnd, WPARAM wParam, POINT *capturePoint, LONG style )
1325 GetWindowRect( hwnd, &rectWindow );
1327 if ((wParam & 0xfff0) == SC_MOVE)
1329 /* Move pointer at the center of the caption */
1330 RECT rect = rectWindow;
1331 /* Note: to be exactly centered we should take the different types
1332 * of border into account, but it shouldn't make more that a few pixels
1333 * of difference so let's not bother with that */
1334 rect.top += GetSystemMetrics(SM_CYBORDER);
1335 if (style & WS_SYSMENU)
1336 rect.left += GetSystemMetrics(SM_CXSIZE) + 1;
1337 if (style & WS_MINIMIZEBOX)
1338 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1339 if (style & WS_MAXIMIZEBOX)
1340 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1341 pt.x = (rect.right + rect.left) / 2;
1342 pt.y = rect.top + GetSystemMetrics(SM_CYSIZE)/2;
1343 hittest = HTCAPTION;
1351 GetMessageW( &msg, 0, WM_KEYFIRST, WM_MOUSELAST );
1352 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
1358 hittest = SendMessageW( hwnd, WM_NCHITTEST, 0, MAKELONG( pt.x, pt.y ) );
1359 if ((hittest < HTLEFT) || (hittest > HTBOTTOMRIGHT)) hittest = 0;
1370 pt.x =(rectWindow.left+rectWindow.right)/2;
1371 pt.y = rectWindow.top + GetSystemMetrics(SM_CYFRAME) / 2;
1375 pt.x =(rectWindow.left+rectWindow.right)/2;
1376 pt.y = rectWindow.bottom - GetSystemMetrics(SM_CYFRAME) / 2;
1380 pt.x = rectWindow.left + GetSystemMetrics(SM_CXFRAME) / 2;
1381 pt.y =(rectWindow.top+rectWindow.bottom)/2;
1385 pt.x = rectWindow.right - GetSystemMetrics(SM_CXFRAME) / 2;
1386 pt.y =(rectWindow.top+rectWindow.bottom)/2;
1389 case VK_ESCAPE: return 0;
1395 SetCursorPos( pt.x, pt.y );
1396 SendMessageW( hwnd, WM_SETCURSOR, (WPARAM)hwnd, MAKELONG( hittest, WM_MOUSEMOVE ));
1401 /***********************************************************************
1402 * set_movesize_capture
1404 static void set_movesize_capture( HWND hwnd )
1408 SERVER_START_REQ( set_capture_window )
1411 req->flags = CAPTURE_MOVESIZE;
1412 if (!wine_server_call_err( req ))
1414 previous = reply->previous;
1415 hwnd = reply->full_handle;
1419 if (previous && previous != hwnd)
1420 SendMessageW( previous, WM_CAPTURECHANGED, 0, (LPARAM)hwnd );
1423 /***********************************************************************
1424 * X11DRV_WMMoveResizeWindow
1426 * Tells the window manager to initiate a move or resize operation.
1429 * http://freedesktop.org/Standards/wm-spec/1.3/ar01s04.html
1430 * or search for "_NET_WM_MOVERESIZE"
1432 static void X11DRV_WMMoveResizeWindow( HWND hwnd, int x, int y, int dir )
1435 Display *display = thread_display();
1437 xev.xclient.type = ClientMessage;
1438 xev.xclient.window = X11DRV_get_whole_window(hwnd);
1439 xev.xclient.message_type = x11drv_atom(_NET_WM_MOVERESIZE);
1440 xev.xclient.serial = 0;
1441 xev.xclient.display = display;
1442 xev.xclient.send_event = True;
1443 xev.xclient.format = 32;
1444 xev.xclient.data.l[0] = x; /* x coord */
1445 xev.xclient.data.l[1] = y; /* y coord */
1446 xev.xclient.data.l[2] = dir; /* direction */
1447 xev.xclient.data.l[3] = 1; /* button */
1448 xev.xclient.data.l[4] = 0; /* unused */
1450 /* need to ungrab the pointer that may have been automatically grabbed
1451 * with a ButtonPress event */
1453 XUngrabPointer( display, CurrentTime );
1454 XSendEvent(display, root_window, False, SubstructureNotifyMask, &xev);
1455 wine_tsx11_unlock();
1458 /***********************************************************************
1459 * SysCommandSizeMove (X11DRV.@)
1461 * Perform SC_MOVE and SC_SIZE commands.
1463 void X11DRV_SysCommandSizeMove( HWND hwnd, WPARAM wParam )
1466 RECT sizingRect, mouseRect, origRect;
1469 LONG hittest = (LONG)(wParam & 0x0f);
1470 WPARAM syscommand = wParam & 0xfff0;
1471 HCURSOR hDragCursor = 0, hOldCursor = 0;
1472 POINT minTrack, maxTrack;
1473 POINT capturePoint, pt;
1474 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
1475 BOOL thickframe = HAS_THICKFRAME( style );
1476 BOOL iconic = style & WS_MINIMIZE;
1478 DWORD dwPoint = GetMessagePos ();
1479 BOOL DragFullWindows = FALSE;
1481 Window parent_win, whole_win;
1482 Display *old_gdi_display = NULL;
1483 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1484 struct x11drv_win_data *data;
1486 pt.x = (short)LOWORD(dwPoint);
1487 pt.y = (short)HIWORD(dwPoint);
1490 if (IsZoomed(hwnd) || !IsWindowVisible(hwnd)) return;
1492 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1494 /* if we are managed then we let the WM do all the work */
1498 if (syscommand == SC_MOVE)
1500 if (!hittest) dir = _NET_WM_MOVERESIZE_MOVE_KEYBOARD;
1501 else dir = _NET_WM_MOVERESIZE_MOVE;
1503 else if (!hittest) dir = _NET_WM_MOVERESIZE_SIZE_KEYBOARD;
1507 case WMSZ_LEFT: dir = _NET_WM_MOVERESIZE_SIZE_LEFT; break;
1508 case WMSZ_RIGHT: dir = _NET_WM_MOVERESIZE_SIZE_RIGHT; break;
1509 case WMSZ_TOP: dir = _NET_WM_MOVERESIZE_SIZE_TOP; break;
1510 case WMSZ_TOPLEFT: dir = _NET_WM_MOVERESIZE_SIZE_TOPLEFT; break;
1511 case WMSZ_TOPRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT; break;
1512 case WMSZ_BOTTOM: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOM; break;
1513 case WMSZ_BOTTOMLEFT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT; break;
1514 case WMSZ_BOTTOMRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT; break;
1516 ERR("Invalid hittest value: %ld\n", hittest);
1517 dir = _NET_WM_MOVERESIZE_SIZE_KEYBOARD;
1519 X11DRV_WMMoveResizeWindow( hwnd, pt.x, pt.y, dir );
1523 SystemParametersInfoA(SPI_GETDRAGFULLWINDOWS, 0, &DragFullWindows, 0);
1525 if (syscommand == SC_MOVE)
1527 if (!hittest) hittest = start_size_move( hwnd, wParam, &capturePoint, style );
1528 if (!hittest) return;
1532 if ( hittest && (syscommand != SC_MOUSEMENU) )
1533 hittest += (HTLEFT - WMSZ_LEFT);
1536 set_movesize_capture( hwnd );
1537 hittest = start_size_move( hwnd, wParam, &capturePoint, style );
1540 set_movesize_capture(0);
1546 /* Get min/max info */
1548 WINPOS_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack );
1549 GetWindowRect( hwnd, &sizingRect );
1550 if (style & WS_CHILD)
1552 parent = GetParent(hwnd);
1553 /* make sizing rect relative to parent */
1554 MapWindowPoints( 0, parent, (POINT*)&sizingRect, 2 );
1555 GetClientRect( parent, &mouseRect );
1560 SetRect(&mouseRect, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
1562 origRect = sizingRect;
1564 if (ON_LEFT_BORDER(hittest))
1566 mouseRect.left = max( mouseRect.left, sizingRect.right-maxTrack.x );
1567 mouseRect.right = min( mouseRect.right, sizingRect.right-minTrack.x );
1569 else if (ON_RIGHT_BORDER(hittest))
1571 mouseRect.left = max( mouseRect.left, sizingRect.left+minTrack.x );
1572 mouseRect.right = min( mouseRect.right, sizingRect.left+maxTrack.x );
1574 if (ON_TOP_BORDER(hittest))
1576 mouseRect.top = max( mouseRect.top, sizingRect.bottom-maxTrack.y );
1577 mouseRect.bottom = min( mouseRect.bottom,sizingRect.bottom-minTrack.y);
1579 else if (ON_BOTTOM_BORDER(hittest))
1581 mouseRect.top = max( mouseRect.top, sizingRect.top+minTrack.y );
1582 mouseRect.bottom = min( mouseRect.bottom, sizingRect.top+maxTrack.y );
1584 if (parent) MapWindowPoints( parent, 0, (LPPOINT)&mouseRect, 2 );
1586 /* Retrieve a default cache DC (without using the window style) */
1587 hdc = GetDCEx( parent, 0, DCX_CACHE );
1589 if( iconic ) /* create a cursor for dragging */
1591 hDragCursor = (HCURSOR)GetClassLongPtrW( hwnd, GCLP_HICON);
1592 if( !hDragCursor ) hDragCursor = (HCURSOR)SendMessageW( hwnd, WM_QUERYDRAGICON, 0, 0L);
1593 if( !hDragCursor ) iconic = FALSE;
1596 /* repaint the window before moving it around */
1597 RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN );
1599 SendMessageA( hwnd, WM_ENTERSIZEMOVE, 0, 0 );
1600 set_movesize_capture( hwnd );
1602 /* grab the server only when moving top-level windows without desktop */
1603 grab = (!DragFullWindows && !parent && (root_window == DefaultRootWindow(gdi_display)));
1608 XSync( gdi_display, False );
1609 XGrabServer( thread_data->display );
1610 XSync( thread_data->display, False );
1611 /* switch gdi display to the thread display, since the server is grabbed */
1612 old_gdi_display = gdi_display;
1613 gdi_display = thread_data->display;
1614 wine_tsx11_unlock();
1616 whole_win = X11DRV_get_whole_window( GetAncestor(hwnd,GA_ROOT) );
1617 parent_win = parent ? X11DRV_get_whole_window( GetAncestor(parent,GA_ROOT) ) : root_window;
1620 XGrabPointer( thread_data->display, whole_win, False,
1621 PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
1622 GrabModeAsync, GrabModeAsync, parent_win, None, CurrentTime );
1623 wine_tsx11_unlock();
1624 thread_data->grab_window = whole_win;
1630 if (!GetMessageW( &msg, 0, WM_KEYFIRST, WM_MOUSELAST )) break;
1631 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
1633 /* Exit on button-up, Return, or Esc */
1634 if ((msg.message == WM_LBUTTONUP) ||
1635 ((msg.message == WM_KEYDOWN) &&
1636 ((msg.wParam == VK_RETURN) || (msg.wParam == VK_ESCAPE)))) break;
1638 if ((msg.message != WM_KEYDOWN) && (msg.message != WM_MOUSEMOVE))
1639 continue; /* We are not interested in other messages */
1643 if (msg.message == WM_KEYDOWN) switch(msg.wParam)
1645 case VK_UP: pt.y -= 8; break;
1646 case VK_DOWN: pt.y += 8; break;
1647 case VK_LEFT: pt.x -= 8; break;
1648 case VK_RIGHT: pt.x += 8; break;
1651 pt.x = max( pt.x, mouseRect.left );
1652 pt.x = min( pt.x, mouseRect.right );
1653 pt.y = max( pt.y, mouseRect.top );
1654 pt.y = min( pt.y, mouseRect.bottom );
1656 dx = pt.x - capturePoint.x;
1657 dy = pt.y - capturePoint.y;
1665 if( iconic ) /* ok, no system popup tracking */
1667 hOldCursor = SetCursor(hDragCursor);
1669 WINPOS_ShowIconTitle( hwnd, FALSE );
1671 else if(!DragFullWindows)
1672 draw_moving_frame( hdc, &sizingRect, thickframe );
1675 if (msg.message == WM_KEYDOWN) SetCursorPos( pt.x, pt.y );
1678 RECT newRect = sizingRect;
1679 WPARAM wpSizingHit = 0;
1681 if (hittest == HTCAPTION) OffsetRect( &newRect, dx, dy );
1682 if (ON_LEFT_BORDER(hittest)) newRect.left += dx;
1683 else if (ON_RIGHT_BORDER(hittest)) newRect.right += dx;
1684 if (ON_TOP_BORDER(hittest)) newRect.top += dy;
1685 else if (ON_BOTTOM_BORDER(hittest)) newRect.bottom += dy;
1686 if(!iconic && !DragFullWindows) draw_moving_frame( hdc, &sizingRect, thickframe );
1689 /* determine the hit location */
1690 if (hittest >= HTLEFT && hittest <= HTBOTTOMRIGHT)
1691 wpSizingHit = WMSZ_LEFT + (hittest - HTLEFT);
1692 SendMessageA( hwnd, WM_SIZING, wpSizingHit, (LPARAM)&newRect );
1696 if(!DragFullWindows)
1697 draw_moving_frame( hdc, &newRect, thickframe );
1699 SetWindowPos( hwnd, 0, newRect.left, newRect.top,
1700 newRect.right - newRect.left,
1701 newRect.bottom - newRect.top,
1702 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
1704 sizingRect = newRect;
1709 set_movesize_capture(0);
1712 if( moved ) /* restore cursors, show icon title later on */
1714 ShowCursor( FALSE );
1715 SetCursor( hOldCursor );
1718 else if (moved && !DragFullWindows)
1719 draw_moving_frame( hdc, &sizingRect, thickframe );
1721 ReleaseDC( parent, hdc );
1724 XUngrabPointer( thread_data->display, CurrentTime );
1727 XSync( thread_data->display, False );
1728 XUngrabServer( thread_data->display );
1729 XSync( thread_data->display, False );
1730 gdi_display = old_gdi_display;
1732 wine_tsx11_unlock();
1733 thread_data->grab_window = None;
1735 if (HOOK_CallHooks( WH_CBT, HCBT_MOVESIZE, (WPARAM)hwnd, (LPARAM)&sizingRect, TRUE ))
1738 SendMessageA( hwnd, WM_EXITSIZEMOVE, 0, 0 );
1739 SendMessageA( hwnd, WM_SETVISIBLE, !IsIconic(hwnd), 0L);
1741 /* window moved or resized */
1744 /* if the moving/resizing isn't canceled call SetWindowPos
1745 * with the new position or the new size of the window
1747 if (!((msg.message == WM_KEYDOWN) && (msg.wParam == VK_ESCAPE)) )
1749 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
1750 if(!DragFullWindows)
1751 SetWindowPos( hwnd, 0, sizingRect.left, sizingRect.top,
1752 sizingRect.right - sizingRect.left,
1753 sizingRect.bottom - sizingRect.top,
1754 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
1757 { /* restore previous size/position */
1759 SetWindowPos( hwnd, 0, origRect.left, origRect.top,
1760 origRect.right - origRect.left,
1761 origRect.bottom - origRect.top,
1762 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
1768 /* Single click brings up the system menu when iconized */
1772 if(style & WS_SYSMENU )
1773 SendMessageA( hwnd, WM_SYSCOMMAND,
1774 SC_MOUSEMENU + HTSYSMENU, MAKELONG(pt.x,pt.y));
1776 else WINPOS_ShowIconTitle( hwnd, TRUE );