2 * Window position related functions.
4 * Copyright 1993, 1994, 1995, 2001 Alexandre Julliard
5 * Copyright 1995, 1996, 1999 Alex Korobka
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include <X11/Xutil.h>
27 #include <X11/extensions/shape.h>
28 #endif /* HAVE_LIBXSHAPE */
36 #include "wine/wingdi16.h"
41 #include "wine/server.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
46 #define SWP_AGG_NOPOSCHANGE \
47 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_NOZORDER)
49 #define SWP_EX_NOCOPY 0x0001
50 #define SWP_EX_PAINTSELF 0x0002
51 #define SWP_EX_NONCLIENT 0x0004
53 #define HAS_THICKFRAME(style) \
54 (((style) & WS_THICKFRAME) && \
55 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
57 #define ON_LEFT_BORDER(hit) \
58 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
59 #define ON_RIGHT_BORDER(hit) \
60 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
61 #define ON_TOP_BORDER(hit) \
62 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
63 #define ON_BOTTOM_BORDER(hit) \
64 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
66 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
67 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
68 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
69 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
70 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
71 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
72 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
73 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
74 #define _NET_WM_MOVERESIZE_MOVE 8 /* movement only */
75 #define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9 /* size via keyboard */
76 #define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10 /* move via keyboard */
78 #define _NET_WM_STATE_REMOVE 0
79 #define _NET_WM_STATE_ADD 1
80 #define _NET_WM_STATE_TOGGLE 2
82 static const char managed_prop[] = "__wine_x11_managed";
84 /***********************************************************************
87 void X11DRV_Expose( HWND hwnd, XEvent *xev )
89 XExposeEvent *event = &xev->xexpose;
91 struct x11drv_win_data *data;
92 int flags = RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN;
94 TRACE( "win %p (%lx) %d,%d %dx%d\n",
95 hwnd, event->window, event->x, event->y, event->width, event->height );
97 if (!(data = X11DRV_get_win_data( hwnd ))) return;
101 rect.right = rect.left + event->width;
102 rect.bottom = rect.top + event->height;
104 if (event->window == root_window)
105 OffsetRect( &rect, virtual_screen_rect.left, virtual_screen_rect.top );
107 if (rect.left < data->client_rect.left ||
108 rect.top < data->client_rect.top ||
109 rect.right > data->client_rect.right ||
110 rect.bottom > data->client_rect.bottom) flags |= RDW_FRAME;
112 SERVER_START_REQ( update_window_zorder )
115 req->rect.left = rect.left + data->whole_rect.left;
116 req->rect.top = rect.top + data->whole_rect.top;
117 req->rect.right = rect.right + data->whole_rect.left;
118 req->rect.bottom = rect.bottom + data->whole_rect.top;
119 wine_server_call( req );
123 /* make position relative to client area instead of window */
124 OffsetRect( &rect, -data->client_rect.left, -data->client_rect.top );
125 RedrawWindow( hwnd, &rect, 0, flags );
128 /***********************************************************************
129 * SetWindowStyle (X11DRV.@)
131 * Update the X state of a window to reflect a style change
133 void X11DRV_SetWindowStyle( HWND hwnd, DWORD old_style )
135 Display *display = thread_display();
136 struct x11drv_win_data *data;
137 DWORD new_style, changed;
139 if (hwnd == GetDesktopWindow()) return;
140 if (!(data = X11DRV_get_win_data( hwnd ))) return;
142 new_style = GetWindowLongW( hwnd, GWL_STYLE );
143 changed = new_style ^ old_style;
145 if (changed & WS_VISIBLE)
147 if (data->whole_window && X11DRV_is_window_rect_mapped( &data->window_rect ))
149 if (new_style & WS_VISIBLE)
151 TRACE( "mapping win %p\n", hwnd );
152 X11DRV_sync_window_style( display, data );
153 X11DRV_set_wm_hints( display, data );
155 XMapWindow( display, data->whole_window );
158 /* we don't unmap windows, that causes trouble with the window manager */
160 invalidate_dce( hwnd, &data->window_rect );
163 if (changed & WS_DISABLED)
165 if (data->whole_window && data->wm_hints)
168 data->wm_hints->input = !(new_style & WS_DISABLED);
169 XSetWMHints( display, data->whole_window, data->wm_hints );
176 /***********************************************************************
179 static void update_wm_states( Display *display, struct x11drv_win_data *data, BOOL force )
181 static const unsigned int state_atoms[NB_WM_STATES] =
183 XATOM__NET_WM_STATE_FULLSCREEN,
186 DWORD i, new_state = 0;
189 if (!data->managed) return;
191 if (data->client_rect.left <= 0 && data->client_rect.right >= screen_width &&
192 data->client_rect.top <= 0 && data->client_rect.bottom >= screen_height)
193 new_state |= (1 << WM_STATE_FULLSCREEN);
195 xev.xclient.type = ClientMessage;
196 xev.xclient.window = data->whole_window;
197 xev.xclient.message_type = x11drv_atom(_NET_WM_STATE);
198 xev.xclient.serial = 0;
199 xev.xclient.display = display;
200 xev.xclient.send_event = True;
201 xev.xclient.format = 32;
202 xev.xclient.data.l[2] = 0;
203 xev.xclient.data.l[3] = 1;
205 for (i = 0; i < NB_WM_STATES; i++)
207 if (!((data->wm_state ^ new_state) & (1 << i))) /* unchanged */
209 /* if forced, we only add states, we don't remove them */
210 if (!force || !(new_state & (1 << i))) continue;
213 TRACE( "setting wm state %u for window %p/%lx to %u prev %u\n",
214 i, data->hwnd, data->whole_window,
215 (new_state & (1 << i)) != 0, (data->wm_state & (1 << i)) != 0 );
217 xev.xclient.data.l[0] = (new_state & (1 << i)) ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
218 xev.xclient.data.l[1] = X11DRV_Atoms[state_atoms[i] - FIRST_XATOM];
220 XSendEvent( display, root_window, False, SubstructureRedirectMask | SubstructureNotifyMask, &xev );
223 data->wm_state = new_state;
227 /***********************************************************************
228 * SetWindowPos (X11DRV.@)
230 BOOL X11DRV_SetWindowPos( HWND hwnd, HWND insert_after, const RECT *rectWindow,
231 const RECT *rectClient, UINT swp_flags, const RECT *valid_rects )
233 Display *display = thread_display();
234 struct x11drv_win_data *data;
235 RECT new_whole_rect, old_client_rect;
237 DWORD old_style, new_style;
238 BOOL ret, make_managed = FALSE;
240 if (!(data = X11DRV_get_win_data( hwnd ))) return FALSE;
242 /* check if we need to switch the window to managed */
243 if (!data->managed && data->whole_window && managed_mode &&
244 root_window == DefaultRootWindow( display ) &&
245 data->whole_window != root_window)
247 if (is_window_managed( hwnd, swp_flags, rectWindow ))
249 TRACE( "making win %p/%lx managed\n", hwnd, data->whole_window );
251 data->managed = TRUE;
252 SetPropA( hwnd, managed_prop, (HANDLE)1 );
256 new_whole_rect = *rectWindow;
257 X11DRV_window_to_X_rect( data, &new_whole_rect );
259 old_client_rect = data->client_rect;
261 if (!(win = WIN_GetPtr( hwnd ))) return FALSE;
262 if (win == WND_OTHER_PROCESS)
264 if (IsWindow( hwnd )) ERR( "cannot set rectangles of other process window %p\n", hwnd );
267 SERVER_START_REQ( set_window_pos )
270 req->previous = insert_after;
271 req->flags = swp_flags;
272 req->window.left = rectWindow->left;
273 req->window.top = rectWindow->top;
274 req->window.right = rectWindow->right;
275 req->window.bottom = rectWindow->bottom;
276 req->client.left = rectClient->left;
277 req->client.top = rectClient->top;
278 req->client.right = rectClient->right;
279 req->client.bottom = rectClient->bottom;
280 if (memcmp( rectWindow, &new_whole_rect, sizeof(RECT) ) || !IsRectEmpty( &valid_rects[0] ))
282 wine_server_add_data( req, &new_whole_rect, sizeof(new_whole_rect) );
283 if (!IsRectEmpty( &valid_rects[0] ))
284 wine_server_add_data( req, valid_rects, 2 * sizeof(*valid_rects) );
286 ret = !wine_server_call( req );
287 new_style = reply->new_style;
291 if (win == WND_DESKTOP || data->whole_window == DefaultRootWindow(gdi_display))
293 data->whole_rect = data->client_rect = data->window_rect = *rectWindow;
294 if (win != WND_DESKTOP)
296 win->rectWindow = *rectWindow;
297 win->rectClient = *rectClient;
298 win->dwStyle = new_style;
299 WIN_ReleasePtr( win );
306 /* invalidate DCEs */
308 if ((((swp_flags & SWP_AGG_NOPOSCHANGE) != SWP_AGG_NOPOSCHANGE) && (new_style & WS_VISIBLE)) ||
309 (swp_flags & (SWP_HIDEWINDOW | SWP_SHOWWINDOW)))
312 UnionRect( &rect, rectWindow, &win->rectWindow );
313 invalidate_dce( hwnd, &rect );
316 win->rectWindow = *rectWindow;
317 win->rectClient = *rectClient;
318 old_style = win->dwStyle;
319 win->dwStyle = new_style;
320 data->window_rect = *rectWindow;
322 TRACE( "win %p window %s client %s style %08x\n",
323 hwnd, wine_dbgstr_rect(rectWindow), wine_dbgstr_rect(rectClient), new_style );
325 if (make_managed && (old_style & WS_VISIBLE))
328 XUnmapWindow( display, data->whole_window );
330 old_style &= ~WS_VISIBLE; /* force it to be mapped again below */
333 if (!IsRectEmpty( &valid_rects[0] ))
335 int x_offset = 0, y_offset = 0;
337 if (data->whole_window)
339 /* the X server will move the bits for us */
340 x_offset = data->whole_rect.left - new_whole_rect.left;
341 y_offset = data->whole_rect.top - new_whole_rect.top;
344 if (x_offset != valid_rects[1].left - valid_rects[0].left ||
345 y_offset != valid_rects[1].top - valid_rects[0].top)
347 /* FIXME: should copy the window bits here */
348 RECT invalid_rect = valid_rects[0];
350 /* invalid_rects are relative to the client area */
351 OffsetRect( &invalid_rect, -rectClient->left, -rectClient->top );
352 RedrawWindow( hwnd, &invalid_rect, NULL, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
357 if (data->whole_window && !data->lock_changes)
359 if ((old_style & WS_VISIBLE) && !(new_style & WS_VISIBLE))
361 /* window got hidden, unmap it */
362 TRACE( "unmapping win %p\n", hwnd );
364 XUnmapWindow( display, data->whole_window );
367 else if ((new_style & WS_VISIBLE) && !X11DRV_is_window_rect_mapped( rectWindow ))
369 /* resizing to zero size or off screen -> unmap */
370 TRACE( "unmapping zero size or off-screen win %p\n", hwnd );
372 XUnmapWindow( display, data->whole_window );
377 X11DRV_sync_window_position( display, data, swp_flags, rectClient, &new_whole_rect );
379 if (data->whole_window && !data->lock_changes)
383 if ((new_style & WS_VISIBLE) && !(new_style & WS_MINIMIZE) &&
384 X11DRV_is_window_rect_mapped( rectWindow ))
386 if (!(old_style & WS_VISIBLE))
388 /* window got shown, map it */
389 TRACE( "mapping win %p\n", hwnd );
392 else if ((swp_flags & (SWP_NOSIZE | SWP_NOMOVE)) != (SWP_NOSIZE | SWP_NOMOVE))
394 /* resizing from zero size to non-zero -> map */
395 TRACE( "mapping non zero size or off-screen win %p\n", hwnd );
399 if (mapped || (swp_flags & SWP_FRAMECHANGED))
400 X11DRV_set_wm_hints( display, data );
404 X11DRV_sync_window_style( display, data );
406 XMapWindow( display, data->whole_window );
410 update_wm_states( display, data, mapped );
414 WIN_ReleasePtr( win );
419 /***********************************************************************
422 * Find a suitable place for an iconic window.
424 static POINT WINPOS_FindIconPos( HWND hwnd, POINT pt )
426 RECT rect, rectParent;
429 int xspacing, yspacing;
431 parent = GetAncestor( hwnd, GA_PARENT );
432 GetClientRect( parent, &rectParent );
433 if ((pt.x >= rectParent.left) && (pt.x + GetSystemMetrics(SM_CXICON) < rectParent.right) &&
434 (pt.y >= rectParent.top) && (pt.y + GetSystemMetrics(SM_CYICON) < rectParent.bottom))
435 return pt; /* The icon already has a suitable position */
437 xspacing = GetSystemMetrics(SM_CXICONSPACING);
438 yspacing = GetSystemMetrics(SM_CYICONSPACING);
440 /* Check if another icon already occupies this spot */
441 /* FIXME: this is completely inefficient */
443 hrgn = CreateRectRgn( 0, 0, 0, 0 );
444 tmp = CreateRectRgn( 0, 0, 0, 0 );
445 for (child = GetWindow( parent, GW_HWNDFIRST ); child; child = GetWindow( child, GW_HWNDNEXT ))
448 if (child == hwnd) continue;
449 if ((GetWindowLongW( child, GWL_STYLE ) & (WS_VISIBLE|WS_MINIMIZE)) != (WS_VISIBLE|WS_MINIMIZE))
451 if (!(childPtr = WIN_GetPtr( child )) || childPtr == WND_OTHER_PROCESS)
453 SetRectRgn( tmp, childPtr->rectWindow.left, childPtr->rectWindow.top,
454 childPtr->rectWindow.right, childPtr->rectWindow.bottom );
455 CombineRgn( hrgn, hrgn, tmp, RGN_OR );
456 WIN_ReleasePtr( childPtr );
460 for (rect.bottom = rectParent.bottom; rect.bottom >= yspacing; rect.bottom -= yspacing)
462 for (rect.left = rectParent.left; rect.left <= rectParent.right - xspacing; rect.left += xspacing)
464 rect.right = rect.left + xspacing;
465 rect.top = rect.bottom - yspacing;
466 if (!RectInRegion( hrgn, &rect ))
468 /* No window was found, so it's OK for us */
469 pt.x = rect.left + (xspacing - GetSystemMetrics(SM_CXICON)) / 2;
470 pt.y = rect.top + (yspacing - GetSystemMetrics(SM_CYICON)) / 2;
471 DeleteObject( hrgn );
476 DeleteObject( hrgn );
482 /***********************************************************************
485 UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect )
493 TRACE("%p %u\n", hwnd, cmd );
495 wpl.length = sizeof(wpl);
496 GetWindowPlacement( hwnd, &wpl );
498 if (HOOK_CallHooks( WH_CBT, HCBT_MINMAX, (WPARAM)hwnd, cmd, TRUE ))
499 return SWP_NOSIZE | SWP_NOMOVE;
501 if (IsIconic( hwnd ))
505 case SW_SHOWMINNOACTIVE:
506 case SW_SHOWMINIMIZED:
507 case SW_FORCEMINIMIZE:
509 return SWP_NOSIZE | SWP_NOMOVE;
511 if (!SendMessageW( hwnd, WM_QUERYOPEN, 0, 0 )) return SWP_NOSIZE | SWP_NOMOVE;
512 swpFlags |= SWP_NOCOPYBITS;
517 case SW_SHOWMINNOACTIVE:
518 case SW_SHOWMINIMIZED:
519 case SW_FORCEMINIMIZE:
521 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
522 if( wndPtr->dwStyle & WS_MAXIMIZE) wndPtr->flags |= WIN_RESTORE_MAX;
523 else wndPtr->flags &= ~WIN_RESTORE_MAX;
524 WIN_ReleasePtr( wndPtr );
526 old_style = WIN_SetStyle( hwnd, WS_MINIMIZE, WS_MAXIMIZE );
528 X11DRV_set_iconic_state( hwnd );
530 wpl.ptMinPosition = WINPOS_FindIconPos( hwnd, wpl.ptMinPosition );
532 if (!(old_style & WS_MINIMIZE)) swpFlags |= SWP_STATECHANGED;
533 SetRect( rect, wpl.ptMinPosition.x, wpl.ptMinPosition.y,
534 GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON) );
535 swpFlags |= SWP_NOCOPYBITS;
539 old_style = GetWindowLongW( hwnd, GWL_STYLE );
540 if ((old_style & WS_MAXIMIZE) && (old_style & WS_VISIBLE)) return SWP_NOSIZE | SWP_NOMOVE;
542 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL );
544 old_style = WIN_SetStyle( hwnd, WS_MAXIMIZE, WS_MINIMIZE );
545 if (old_style & WS_MINIMIZE)
547 WINPOS_ShowIconTitle( hwnd, FALSE );
548 X11DRV_set_iconic_state( hwnd );
550 if (!(old_style & WS_MAXIMIZE)) swpFlags |= SWP_STATECHANGED;
551 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y );
554 case SW_SHOWNOACTIVATE:
557 old_style = WIN_SetStyle( hwnd, 0, WS_MINIMIZE | WS_MAXIMIZE );
558 if (old_style & WS_MINIMIZE)
562 WINPOS_ShowIconTitle( hwnd, FALSE );
563 X11DRV_set_iconic_state( hwnd );
565 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
566 restore_max = (wndPtr->flags & WIN_RESTORE_MAX) != 0;
567 WIN_ReleasePtr( wndPtr );
570 /* Restore to maximized position */
571 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL);
572 WIN_SetStyle( hwnd, WS_MAXIMIZE, 0 );
573 swpFlags |= SWP_STATECHANGED;
574 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y );
578 else if (!(old_style & WS_MAXIMIZE)) break;
580 swpFlags |= SWP_STATECHANGED;
582 /* Restore to normal position */
584 *rect = wpl.rcNormalPosition;
585 rect->right -= rect->left;
586 rect->bottom -= rect->top;
595 /***********************************************************************
596 * ShowWindow (X11DRV.@)
598 BOOL X11DRV_ShowWindow( HWND hwnd, INT cmd )
602 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
603 BOOL wasVisible = (style & WS_VISIBLE) != 0;
604 BOOL showFlag = TRUE;
605 RECT newPos = {0, 0, 0, 0};
608 TRACE("hwnd=%p, cmd=%d, wasVisible %d\n", hwnd, cmd, wasVisible);
613 if (!wasVisible) return FALSE;
615 swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE;
616 if (hwnd != GetActiveWindow())
617 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
620 case SW_SHOWMINNOACTIVE:
621 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
624 case SW_FORCEMINIMIZE: /* FIXME: Does not work if thread is hung. */
625 if (style & WS_CHILD) swp |= SWP_NOACTIVATE | SWP_NOZORDER;
627 case SW_SHOWMINIMIZED:
628 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
629 swp |= WINPOS_MinMaximize( hwnd, cmd, &newPos );
630 if ((style & WS_MINIMIZE) && wasVisible) return TRUE;
633 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
634 if (!wasVisible) swp |= SWP_SHOWWINDOW;
635 swp |= SWP_FRAMECHANGED;
636 swp |= WINPOS_MinMaximize( hwnd, SW_MAXIMIZE, &newPos );
637 if ((style & WS_MAXIMIZE) && wasVisible) return TRUE;
641 swp |= SWP_NOACTIVATE | SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
642 if (style & WS_CHILD) swp |= SWP_NOZORDER;
645 if (wasVisible) return TRUE;
646 swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
647 if (style & WS_CHILD) swp |= SWP_NOACTIVATE | SWP_NOZORDER;
650 case SW_SHOWNOACTIVATE:
651 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
655 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
656 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
657 if (!wasVisible) swp |= SWP_SHOWWINDOW;
658 if (style & (WS_MINIMIZE | WS_MAXIMIZE))
660 swp |= SWP_FRAMECHANGED;
661 swp |= WINPOS_MinMaximize( hwnd, cmd, &newPos );
665 if (wasVisible) return TRUE;
666 swp |= SWP_NOSIZE | SWP_NOMOVE;
668 if (style & WS_CHILD && !(swp & SWP_STATECHANGED)) swp |= SWP_NOACTIVATE | SWP_NOZORDER;
672 if ((showFlag != wasVisible || cmd == SW_SHOWNA) && cmd != SW_SHOWMAXIMIZED && !(swp & SWP_STATECHANGED))
674 SendMessageW( hwnd, WM_SHOWWINDOW, showFlag, 0 );
675 if (!IsWindow( hwnd )) return wasVisible;
678 parent = GetAncestor( hwnd, GA_PARENT );
679 if (parent && !IsWindowVisible( parent ) && !(swp & SWP_STATECHANGED))
681 /* if parent is not visible simply toggle WS_VISIBLE and return */
682 if (showFlag) WIN_SetStyle( hwnd, WS_VISIBLE, 0 );
683 else WIN_SetStyle( hwnd, 0, WS_VISIBLE );
686 SetWindowPos( hwnd, HWND_TOP, newPos.left, newPos.top,
687 newPos.right, newPos.bottom, LOWORD(swp) );
693 /* FIXME: This will cause the window to be activated irrespective
694 * of whether it is owned by the same thread. Has to be done
698 if (hwnd == GetActiveWindow())
699 WINPOS_ActivateOtherWindow(hwnd);
701 /* Revert focus to parent */
703 if (hwnd == hFocus || IsChild(hwnd, hFocus))
705 HWND parent = GetAncestor(hwnd, GA_PARENT);
706 if (parent == GetDesktopWindow()) parent = 0;
711 if (IsIconic(hwnd)) WINPOS_ShowIconTitle( hwnd, TRUE );
713 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return wasVisible;
715 if (wndPtr->flags & WIN_NEED_SIZE)
717 /* should happen only in CreateWindowEx() */
718 int wParam = SIZE_RESTORED;
719 RECT client = wndPtr->rectClient;
721 wndPtr->flags &= ~WIN_NEED_SIZE;
722 if (wndPtr->dwStyle & WS_MAXIMIZE) wParam = SIZE_MAXIMIZED;
723 else if (wndPtr->dwStyle & WS_MINIMIZE) wParam = SIZE_MINIMIZED;
724 WIN_ReleasePtr( wndPtr );
726 SendMessageW( hwnd, WM_SIZE, wParam,
727 MAKELONG( client.right - client.left, client.bottom - client.top ));
728 SendMessageW( hwnd, WM_MOVE, 0, MAKELONG( client.left, client.top ));
730 else WIN_ReleasePtr( wndPtr );
732 /* if previous state was minimized Windows sets focus to the window */
733 if (style & WS_MINIMIZE) SetFocus( hwnd );
739 /**********************************************************************
742 void X11DRV_MapNotify( HWND hwnd, XEvent *event )
744 struct x11drv_win_data *data;
745 HWND hwndFocus = GetFocus();
748 if (!(data = X11DRV_get_win_data( hwnd ))) return;
750 if (!(win = WIN_GetPtr( hwnd ))) return;
752 if (data->managed && (win->dwStyle & WS_VISIBLE) && (win->dwStyle & WS_MINIMIZE))
755 unsigned int width, height, border, depth;
758 LONG style = WS_VISIBLE;
762 XGetGeometry( event->xmap.display, data->whole_window, &root, &x, &y, &width, &height,
764 XTranslateCoordinates( event->xmap.display, data->whole_window, root, 0, 0, &x, &y, &top );
768 rect.right = x + width;
769 rect.bottom = y + height;
770 OffsetRect( &rect, virtual_screen_rect.left, virtual_screen_rect.top );
771 X11DRV_X_to_window_rect( data, &rect );
773 invalidate_dce( hwnd, &data->window_rect );
775 if (win->flags & WIN_RESTORE_MAX) style |= WS_MAXIMIZE;
776 WIN_SetStyle( hwnd, style, WS_MINIMIZE );
777 WIN_ReleasePtr( win );
779 SendMessageW( hwnd, WM_SHOWWINDOW, SW_RESTORE, 0 );
780 data->lock_changes++;
781 SetWindowPos( hwnd, 0, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
782 SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED | SWP_STATECHANGED );
783 data->lock_changes--;
785 else WIN_ReleasePtr( win );
786 if (hwndFocus && IsChild( hwnd, hwndFocus )) X11DRV_SetFocus(hwndFocus); /* FIXME */
790 /**********************************************************************
793 void X11DRV_UnmapNotify( HWND hwnd, XEvent *event )
795 struct x11drv_win_data *data;
798 if (!(data = X11DRV_get_win_data( hwnd ))) return;
800 if (!(win = WIN_GetPtr( hwnd ))) return;
802 if ((win->dwStyle & WS_VISIBLE) && data->managed &&
803 X11DRV_is_window_rect_mapped( &win->rectWindow ))
805 if (win->dwStyle & WS_MAXIMIZE)
806 win->flags |= WIN_RESTORE_MAX;
807 else if (!(win->dwStyle & WS_MINIMIZE))
808 win->flags &= ~WIN_RESTORE_MAX;
810 WIN_SetStyle( hwnd, WS_MINIMIZE, WS_MAXIMIZE );
811 WIN_ReleasePtr( win );
814 SendMessageW( hwnd, WM_SHOWWINDOW, SW_MINIMIZE, 0 );
815 data->lock_changes++;
816 SetWindowPos( hwnd, 0, 0, 0, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON),
817 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_STATECHANGED );
818 data->lock_changes--;
820 else WIN_ReleasePtr( win );
823 struct desktop_resize_data
825 RECT old_screen_rect;
826 RECT old_virtual_rect;
829 static BOOL CALLBACK update_windows_on_desktop_resize( HWND hwnd, LPARAM lparam )
831 struct x11drv_win_data *data;
832 Display *display = thread_display();
833 struct desktop_resize_data *resize_data = (struct desktop_resize_data *)lparam;
836 if (!(data = X11DRV_get_win_data( hwnd ))) return TRUE;
838 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE)
840 /* update the full screen state */
841 update_wm_states( display, data, FALSE );
844 if (resize_data->old_virtual_rect.left != virtual_screen_rect.left) mask |= CWX;
845 if (resize_data->old_virtual_rect.top != virtual_screen_rect.top) mask |= CWY;
846 if (mask && data->whole_window)
848 XWindowChanges changes;
851 changes.x = data->whole_rect.left - virtual_screen_rect.left;
852 changes.y = data->whole_rect.top - virtual_screen_rect.top;
853 XReconfigureWMWindow( display, data->whole_window,
854 DefaultScreen(display), mask, &changes );
861 /***********************************************************************
862 * X11DRV_handle_desktop_resize
864 void X11DRV_handle_desktop_resize( unsigned int width, unsigned int height )
866 HWND hwnd = GetDesktopWindow();
867 struct x11drv_win_data *data;
868 struct desktop_resize_data resize_data;
870 if (!(data = X11DRV_get_win_data( hwnd ))) return;
872 SetRect( &resize_data.old_screen_rect, 0, 0, screen_width, screen_height );
873 resize_data.old_virtual_rect = virtual_screen_rect;
875 screen_width = width;
876 screen_height = height;
878 TRACE("desktop %p change to (%dx%d)\n", hwnd, width, height);
879 data->lock_changes++;
880 X11DRV_SetWindowPos( hwnd, 0, &virtual_screen_rect, &virtual_screen_rect,
881 SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE, NULL );
882 data->lock_changes--;
884 SendMessageTimeoutW( HWND_BROADCAST, WM_DISPLAYCHANGE, screen_depth,
885 MAKELPARAM( width, height ), SMTO_ABORTIFHUNG, 2000, NULL );
887 EnumWindows( update_windows_on_desktop_resize, (LPARAM)&resize_data );
891 /***********************************************************************
892 * X11DRV_ConfigureNotify
894 void X11DRV_ConfigureNotify( HWND hwnd, XEvent *xev )
896 XConfigureEvent *event = &xev->xconfigure;
897 struct x11drv_win_data *data;
900 int cx, cy, x = event->x, y = event->y;
903 if (!(data = X11DRV_get_win_data( hwnd ))) return;
907 if (!event->send_event) /* normal event, need to map coordinates to the root */
911 XTranslateCoordinates( event->display, data->whole_window, root_window,
912 0, 0, &x, &y, &child );
917 rect.right = x + event->width;
918 rect.bottom = y + event->height;
919 OffsetRect( &rect, virtual_screen_rect.left, virtual_screen_rect.top );
920 TRACE( "win %p new X rect %d,%d,%dx%d (event %d,%d,%dx%d)\n",
921 hwnd, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
922 event->x, event->y, event->width, event->height );
923 X11DRV_X_to_window_rect( data, &rect );
927 cx = rect.right - rect.left;
928 cy = rect.bottom - rect.top;
929 flags = SWP_NOACTIVATE | SWP_NOZORDER;
931 /* Compare what has changed */
933 GetWindowRect( hwnd, &rect );
934 if (rect.left == x && rect.top == y) flags |= SWP_NOMOVE;
936 TRACE( "%p moving from (%d,%d) to (%d,%d)\n",
937 hwnd, rect.left, rect.top, x, y );
939 if ((rect.right - rect.left == cx && rect.bottom - rect.top == cy) ||
941 (IsRectEmpty( &rect ) && event->width == 1 && event->height == 1))
943 if (flags & SWP_NOMOVE) return; /* if nothing changed, don't do anything */
947 TRACE( "%p resizing from (%dx%d) to (%dx%d)\n",
948 hwnd, rect.right - rect.left, rect.bottom - rect.top, cx, cy );
950 data->lock_changes++;
951 SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
952 data->lock_changes--;
956 /***********************************************************************
957 * SetWindowRgn (X11DRV.@)
959 * Assign specified region to window (for non-rectangular windows)
961 int X11DRV_SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL redraw )
963 struct x11drv_win_data *data;
965 if (!(data = X11DRV_get_win_data( hwnd )))
967 if (IsWindow( hwnd ))
968 FIXME( "not supported on other thread window %p\n", hwnd );
969 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
973 #ifdef HAVE_LIBXSHAPE
974 if (data->whole_window)
976 Display *display = thread_display();
981 XShapeCombineMask( display, data->whole_window,
982 ShapeBounding, 0, 0, None, ShapeSet );
987 RGNDATA *pRegionData = X11DRV_GetRegionData( hrgn, 0 );
991 XShapeCombineRectangles( display, data->whole_window, ShapeBounding,
992 data->window_rect.left - data->whole_rect.left,
993 data->window_rect.top - data->whole_rect.top,
994 (XRectangle *)pRegionData->Buffer,
995 pRegionData->rdh.nCount,
996 ShapeSet, YXBanded );
998 HeapFree(GetProcessHeap(), 0, pRegionData);
1002 #endif /* HAVE_LIBXSHAPE */
1004 invalidate_dce( hwnd, &data->window_rect );
1009 /***********************************************************************
1012 * Draw the frame used when moving or resizing window.
1014 * FIXME: This causes problems in Win95 mode. (why?)
1016 static void draw_moving_frame( HDC hdc, RECT *rect, BOOL thickframe )
1020 const int width = GetSystemMetrics(SM_CXFRAME);
1021 const int height = GetSystemMetrics(SM_CYFRAME);
1023 HBRUSH hbrush = SelectObject( hdc, GetStockObject( GRAY_BRUSH ) );
1024 PatBlt( hdc, rect->left, rect->top,
1025 rect->right - rect->left - width, height, PATINVERT );
1026 PatBlt( hdc, rect->left, rect->top + height, width,
1027 rect->bottom - rect->top - height, PATINVERT );
1028 PatBlt( hdc, rect->left + width, rect->bottom - 1,
1029 rect->right - rect->left - width, -height, PATINVERT );
1030 PatBlt( hdc, rect->right - 1, rect->top, -width,
1031 rect->bottom - rect->top - height, PATINVERT );
1032 SelectObject( hdc, hbrush );
1034 else DrawFocusRect( hdc, rect );
1038 /***********************************************************************
1041 * Initialisation of a move or resize, when initiatied from a menu choice.
1042 * Return hit test code for caption or sizing border.
1044 static LONG start_size_move( HWND hwnd, WPARAM wParam, POINT *capturePoint, LONG style )
1051 GetWindowRect( hwnd, &rectWindow );
1053 if ((wParam & 0xfff0) == SC_MOVE)
1055 /* Move pointer at the center of the caption */
1056 RECT rect = rectWindow;
1057 /* Note: to be exactly centered we should take the different types
1058 * of border into account, but it shouldn't make more that a few pixels
1059 * of difference so let's not bother with that */
1060 rect.top += GetSystemMetrics(SM_CYBORDER);
1061 if (style & WS_SYSMENU)
1062 rect.left += GetSystemMetrics(SM_CXSIZE) + 1;
1063 if (style & WS_MINIMIZEBOX)
1064 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1065 if (style & WS_MAXIMIZEBOX)
1066 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1067 pt.x = (rect.right + rect.left) / 2;
1068 pt.y = rect.top + GetSystemMetrics(SM_CYSIZE)/2;
1069 hittest = HTCAPTION;
1077 GetMessageW( &msg, 0, WM_KEYFIRST, WM_MOUSELAST );
1078 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
1084 hittest = SendMessageW( hwnd, WM_NCHITTEST, 0, MAKELONG( pt.x, pt.y ) );
1085 if ((hittest < HTLEFT) || (hittest > HTBOTTOMRIGHT)) hittest = 0;
1096 pt.x =(rectWindow.left+rectWindow.right)/2;
1097 pt.y = rectWindow.top + GetSystemMetrics(SM_CYFRAME) / 2;
1101 pt.x =(rectWindow.left+rectWindow.right)/2;
1102 pt.y = rectWindow.bottom - GetSystemMetrics(SM_CYFRAME) / 2;
1106 pt.x = rectWindow.left + GetSystemMetrics(SM_CXFRAME) / 2;
1107 pt.y =(rectWindow.top+rectWindow.bottom)/2;
1111 pt.x = rectWindow.right - GetSystemMetrics(SM_CXFRAME) / 2;
1112 pt.y =(rectWindow.top+rectWindow.bottom)/2;
1115 case VK_ESCAPE: return 0;
1121 SetCursorPos( pt.x, pt.y );
1122 SendMessageW( hwnd, WM_SETCURSOR, (WPARAM)hwnd, MAKELONG( hittest, WM_MOUSEMOVE ));
1127 /***********************************************************************
1128 * set_movesize_capture
1130 static void set_movesize_capture( HWND hwnd )
1134 SERVER_START_REQ( set_capture_window )
1137 req->flags = CAPTURE_MOVESIZE;
1138 if (!wine_server_call_err( req ))
1140 previous = reply->previous;
1141 hwnd = reply->full_handle;
1145 if (previous && previous != hwnd)
1146 SendMessageW( previous, WM_CAPTURECHANGED, 0, (LPARAM)hwnd );
1149 /***********************************************************************
1150 * X11DRV_WMMoveResizeWindow
1152 * Tells the window manager to initiate a move or resize operation.
1155 * http://freedesktop.org/Standards/wm-spec/1.3/ar01s04.html
1156 * or search for "_NET_WM_MOVERESIZE"
1158 static BOOL X11DRV_WMMoveResizeWindow( HWND hwnd, int x, int y, WPARAM wparam )
1160 WPARAM syscommand = wparam & 0xfff0;
1161 WPARAM hittest = wparam & 0x0f;
1164 Display *display = thread_display();
1166 if (syscommand == SC_MOVE)
1168 if (!hittest) dir = _NET_WM_MOVERESIZE_MOVE_KEYBOARD;
1169 else dir = _NET_WM_MOVERESIZE_MOVE;
1173 /* windows without WS_THICKFRAME are not resizable through the window manager */
1174 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_THICKFRAME)) return FALSE;
1178 case WMSZ_LEFT: dir = _NET_WM_MOVERESIZE_SIZE_LEFT; break;
1179 case WMSZ_RIGHT: dir = _NET_WM_MOVERESIZE_SIZE_RIGHT; break;
1180 case WMSZ_TOP: dir = _NET_WM_MOVERESIZE_SIZE_TOP; break;
1181 case WMSZ_TOPLEFT: dir = _NET_WM_MOVERESIZE_SIZE_TOPLEFT; break;
1182 case WMSZ_TOPRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT; break;
1183 case WMSZ_BOTTOM: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOM; break;
1184 case WMSZ_BOTTOMLEFT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT; break;
1185 case WMSZ_BOTTOMRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT; break;
1186 default: dir = _NET_WM_MOVERESIZE_SIZE_KEYBOARD; break;
1190 TRACE("hwnd %p, x %d, y %d, dir %d\n", hwnd, x, y, dir);
1192 xev.xclient.type = ClientMessage;
1193 xev.xclient.window = X11DRV_get_whole_window(hwnd);
1194 xev.xclient.message_type = x11drv_atom(_NET_WM_MOVERESIZE);
1195 xev.xclient.serial = 0;
1196 xev.xclient.display = display;
1197 xev.xclient.send_event = True;
1198 xev.xclient.format = 32;
1199 xev.xclient.data.l[0] = x; /* x coord */
1200 xev.xclient.data.l[1] = y; /* y coord */
1201 xev.xclient.data.l[2] = dir; /* direction */
1202 xev.xclient.data.l[3] = 1; /* button */
1203 xev.xclient.data.l[4] = 0; /* unused */
1205 /* need to ungrab the pointer that may have been automatically grabbed
1206 * with a ButtonPress event */
1208 XUngrabPointer( display, CurrentTime );
1209 XSendEvent(display, root_window, False, SubstructureNotifyMask, &xev);
1210 wine_tsx11_unlock();
1214 /***********************************************************************
1215 * SysCommandSizeMove (X11DRV.@)
1217 * Perform SC_MOVE and SC_SIZE commands.
1219 void X11DRV_SysCommandSizeMove( HWND hwnd, WPARAM wParam )
1222 RECT sizingRect, mouseRect, origRect;
1225 LONG hittest = (LONG)(wParam & 0x0f);
1226 WPARAM syscommand = wParam & 0xfff0;
1227 HCURSOR hDragCursor = 0, hOldCursor = 0;
1228 POINT minTrack, maxTrack;
1229 POINT capturePoint, pt;
1230 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
1231 BOOL thickframe = HAS_THICKFRAME( style );
1232 BOOL iconic = style & WS_MINIMIZE;
1234 DWORD dwPoint = GetMessagePos ();
1235 BOOL DragFullWindows = TRUE;
1236 Window parent_win, whole_win;
1237 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1238 struct x11drv_win_data *data;
1240 pt.x = (short)LOWORD(dwPoint);
1241 pt.y = (short)HIWORD(dwPoint);
1244 if (IsZoomed(hwnd) || !IsWindowVisible(hwnd)) return;
1246 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1248 TRACE("hwnd %p (%smanaged), command %04lx, hittest %d, pos %d,%d\n",
1249 hwnd, data->managed ? "" : "NOT ", syscommand, hittest, pt.x, pt.y);
1251 /* if we are managed then we let the WM do all the work */
1252 if (data->managed && X11DRV_WMMoveResizeWindow( hwnd, pt.x, pt.y, wParam )) return;
1254 if (syscommand == SC_MOVE)
1256 if (!hittest) hittest = start_size_move( hwnd, wParam, &capturePoint, style );
1257 if (!hittest) return;
1261 if ( hittest && (syscommand != SC_MOUSEMENU) )
1262 hittest += (HTLEFT - WMSZ_LEFT);
1265 set_movesize_capture( hwnd );
1266 hittest = start_size_move( hwnd, wParam, &capturePoint, style );
1269 set_movesize_capture(0);
1275 /* Get min/max info */
1277 WINPOS_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack );
1278 GetWindowRect( hwnd, &sizingRect );
1279 if (style & WS_CHILD)
1281 parent = GetParent(hwnd);
1282 /* make sizing rect relative to parent */
1283 MapWindowPoints( 0, parent, (POINT*)&sizingRect, 2 );
1284 GetClientRect( parent, &mouseRect );
1289 mouseRect = virtual_screen_rect;
1291 origRect = sizingRect;
1293 if (ON_LEFT_BORDER(hittest))
1295 mouseRect.left = max( mouseRect.left, sizingRect.right-maxTrack.x );
1296 mouseRect.right = min( mouseRect.right, sizingRect.right-minTrack.x );
1298 else if (ON_RIGHT_BORDER(hittest))
1300 mouseRect.left = max( mouseRect.left, sizingRect.left+minTrack.x );
1301 mouseRect.right = min( mouseRect.right, sizingRect.left+maxTrack.x );
1303 if (ON_TOP_BORDER(hittest))
1305 mouseRect.top = max( mouseRect.top, sizingRect.bottom-maxTrack.y );
1306 mouseRect.bottom = min( mouseRect.bottom,sizingRect.bottom-minTrack.y);
1308 else if (ON_BOTTOM_BORDER(hittest))
1310 mouseRect.top = max( mouseRect.top, sizingRect.top+minTrack.y );
1311 mouseRect.bottom = min( mouseRect.bottom, sizingRect.top+maxTrack.y );
1313 if (parent) MapWindowPoints( parent, 0, (LPPOINT)&mouseRect, 2 );
1315 /* Retrieve a default cache DC (without using the window style) */
1316 hdc = GetDCEx( parent, 0, DCX_CACHE );
1318 if( iconic ) /* create a cursor for dragging */
1320 hDragCursor = (HCURSOR)GetClassLongPtrW( hwnd, GCLP_HICON);
1321 if( !hDragCursor ) hDragCursor = (HCURSOR)SendMessageW( hwnd, WM_QUERYDRAGICON, 0, 0L);
1322 if( !hDragCursor ) iconic = FALSE;
1325 /* repaint the window before moving it around */
1326 RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN );
1328 SendMessageW( hwnd, WM_ENTERSIZEMOVE, 0, 0 );
1329 set_movesize_capture( hwnd );
1331 /* we only allow disabling the full window drag for child windows, or in desktop mode */
1332 /* otherwise we'd need to grab the server and we want to avoid that */
1333 if (parent || (root_window != DefaultRootWindow(gdi_display)))
1334 SystemParametersInfoA(SPI_GETDRAGFULLWINDOWS, 0, &DragFullWindows, 0);
1336 whole_win = X11DRV_get_whole_window( GetAncestor(hwnd,GA_ROOT) );
1337 parent_win = parent ? X11DRV_get_whole_window( GetAncestor(parent,GA_ROOT) ) : root_window;
1340 XGrabPointer( thread_data->display, whole_win, False,
1341 PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
1342 GrabModeAsync, GrabModeAsync, parent_win, None, CurrentTime );
1343 wine_tsx11_unlock();
1344 thread_data->grab_window = whole_win;
1350 if (!GetMessageW( &msg, 0, WM_KEYFIRST, WM_MOUSELAST )) break;
1351 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
1353 /* Exit on button-up, Return, or Esc */
1354 if ((msg.message == WM_LBUTTONUP) ||
1355 ((msg.message == WM_KEYDOWN) &&
1356 ((msg.wParam == VK_RETURN) || (msg.wParam == VK_ESCAPE)))) break;
1358 if ((msg.message != WM_KEYDOWN) && (msg.message != WM_MOUSEMOVE))
1359 continue; /* We are not interested in other messages */
1363 if (msg.message == WM_KEYDOWN) switch(msg.wParam)
1365 case VK_UP: pt.y -= 8; break;
1366 case VK_DOWN: pt.y += 8; break;
1367 case VK_LEFT: pt.x -= 8; break;
1368 case VK_RIGHT: pt.x += 8; break;
1371 pt.x = max( pt.x, mouseRect.left );
1372 pt.x = min( pt.x, mouseRect.right );
1373 pt.y = max( pt.y, mouseRect.top );
1374 pt.y = min( pt.y, mouseRect.bottom );
1376 dx = pt.x - capturePoint.x;
1377 dy = pt.y - capturePoint.y;
1385 if( iconic ) /* ok, no system popup tracking */
1387 hOldCursor = SetCursor(hDragCursor);
1389 WINPOS_ShowIconTitle( hwnd, FALSE );
1391 else if(!DragFullWindows)
1392 draw_moving_frame( hdc, &sizingRect, thickframe );
1395 if (msg.message == WM_KEYDOWN) SetCursorPos( pt.x, pt.y );
1398 RECT newRect = sizingRect;
1399 WPARAM wpSizingHit = 0;
1401 if (hittest == HTCAPTION) OffsetRect( &newRect, dx, dy );
1402 if (ON_LEFT_BORDER(hittest)) newRect.left += dx;
1403 else if (ON_RIGHT_BORDER(hittest)) newRect.right += dx;
1404 if (ON_TOP_BORDER(hittest)) newRect.top += dy;
1405 else if (ON_BOTTOM_BORDER(hittest)) newRect.bottom += dy;
1406 if(!iconic && !DragFullWindows) draw_moving_frame( hdc, &sizingRect, thickframe );
1409 /* determine the hit location */
1410 if (hittest >= HTLEFT && hittest <= HTBOTTOMRIGHT)
1411 wpSizingHit = WMSZ_LEFT + (hittest - HTLEFT);
1412 SendMessageW( hwnd, WM_SIZING, wpSizingHit, (LPARAM)&newRect );
1416 if(!DragFullWindows)
1417 draw_moving_frame( hdc, &newRect, thickframe );
1419 SetWindowPos( hwnd, 0, newRect.left, newRect.top,
1420 newRect.right - newRect.left,
1421 newRect.bottom - newRect.top,
1422 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
1424 sizingRect = newRect;
1429 set_movesize_capture(0);
1432 if( moved ) /* restore cursors, show icon title later on */
1434 ShowCursor( FALSE );
1435 SetCursor( hOldCursor );
1438 else if (moved && !DragFullWindows)
1439 draw_moving_frame( hdc, &sizingRect, thickframe );
1441 ReleaseDC( parent, hdc );
1444 XUngrabPointer( thread_data->display, CurrentTime );
1445 wine_tsx11_unlock();
1446 thread_data->grab_window = None;
1448 if (HOOK_CallHooks( WH_CBT, HCBT_MOVESIZE, (WPARAM)hwnd, (LPARAM)&sizingRect, TRUE ))
1451 SendMessageW( hwnd, WM_EXITSIZEMOVE, 0, 0 );
1452 SendMessageW( hwnd, WM_SETVISIBLE, !IsIconic(hwnd), 0L);
1454 /* window moved or resized */
1457 /* if the moving/resizing isn't canceled call SetWindowPos
1458 * with the new position or the new size of the window
1460 if (!((msg.message == WM_KEYDOWN) && (msg.wParam == VK_ESCAPE)) )
1462 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
1463 if(!DragFullWindows)
1464 SetWindowPos( hwnd, 0, sizingRect.left, sizingRect.top,
1465 sizingRect.right - sizingRect.left,
1466 sizingRect.bottom - sizingRect.top,
1467 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
1470 { /* restore previous size/position */
1472 SetWindowPos( hwnd, 0, origRect.left, origRect.top,
1473 origRect.right - origRect.left,
1474 origRect.bottom - origRect.top,
1475 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
1481 /* Single click brings up the system menu when iconized */
1485 if(style & WS_SYSMENU )
1486 SendMessageW( hwnd, WM_SYSCOMMAND,
1487 SC_MOUSEMENU + HTSYSMENU, MAKELONG(pt.x,pt.y));
1489 else WINPOS_ShowIconTitle( hwnd, TRUE );