ntdll: Extra check for ObjectAttributes (Coverity).
[wine/multimedia.git] / dlls / winex11.drv / winpos.c
blob95afc402361841106d9a5e6372f6eaab31b5c06a
1 /*
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
22 #include "config.h"
24 #include <X11/Xlib.h>
25 #include <X11/Xutil.h>
26 #ifdef HAVE_LIBXSHAPE
27 #include <X11/extensions/shape.h>
28 #endif /* HAVE_LIBXSHAPE */
29 #include <stdarg.h>
31 #include "windef.h"
32 #include "winbase.h"
33 #include "wingdi.h"
34 #include "winuser.h"
35 #include "winerror.h"
36 #include "wownt32.h"
37 #include "wine/wingdi16.h"
39 #include "x11drv.h"
40 #include "win.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)
50 #define SWP_EX_NOCOPY 0x0001
51 #define SWP_EX_PAINTSELF 0x0002
52 #define SWP_EX_NONCLIENT 0x0004
54 #define HAS_THICKFRAME(style) \
55 (((style) & WS_THICKFRAME) && \
56 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
58 #define ON_LEFT_BORDER(hit) \
59 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
60 #define ON_RIGHT_BORDER(hit) \
61 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
62 #define ON_TOP_BORDER(hit) \
63 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
64 #define ON_BOTTOM_BORDER(hit) \
65 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
67 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
68 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
69 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
70 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
71 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
72 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
73 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
74 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
75 #define _NET_WM_MOVERESIZE_MOVE 8 /* movement only */
76 #define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9 /* size via keyboard */
77 #define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10 /* move via keyboard */
79 #define _NET_WM_STATE_REMOVE 0
80 #define _NET_WM_STATE_ADD 1
81 #define _NET_WM_STATE_TOGGLE 2
83 /***********************************************************************
84 * X11DRV_Expose
86 void X11DRV_Expose( HWND hwnd, XEvent *xev )
88 XExposeEvent *event = &xev->xexpose;
89 RECT rect;
90 struct x11drv_win_data *data;
91 int flags = RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN;
93 TRACE( "win %p (%lx) %d,%d %dx%d\n",
94 hwnd, event->window, event->x, event->y, event->width, event->height );
96 if (!(data = X11DRV_get_win_data( hwnd ))) return;
98 rect.left = event->x;
99 rect.top = event->y;
100 rect.right = rect.left + event->width;
101 rect.bottom = rect.top + event->height;
103 if (event->window == root_window)
104 OffsetRect( &rect, virtual_screen_rect.left, virtual_screen_rect.top );
106 if (rect.left < data->client_rect.left ||
107 rect.top < data->client_rect.top ||
108 rect.right > data->client_rect.right ||
109 rect.bottom > data->client_rect.bottom) flags |= RDW_FRAME;
111 SERVER_START_REQ( update_window_zorder )
113 req->window = hwnd;
114 req->rect.left = rect.left + data->whole_rect.left;
115 req->rect.top = rect.top + data->whole_rect.top;
116 req->rect.right = rect.right + data->whole_rect.left;
117 req->rect.bottom = rect.bottom + data->whole_rect.top;
118 wine_server_call( req );
120 SERVER_END_REQ;
122 /* make position relative to client area instead of window */
123 OffsetRect( &rect, -data->client_rect.left, -data->client_rect.top );
124 RedrawWindow( hwnd, &rect, 0, flags );
127 /***********************************************************************
128 * SetWindowStyle (X11DRV.@)
130 * Update the X state of a window to reflect a style change
132 void X11DRV_SetWindowStyle( HWND hwnd, DWORD old_style )
134 Display *display = thread_display();
135 struct x11drv_win_data *data;
136 DWORD new_style, changed;
138 if (hwnd == GetDesktopWindow()) return;
139 if (!(data = X11DRV_get_win_data( hwnd ))) return;
141 new_style = GetWindowLongW( hwnd, GWL_STYLE );
142 changed = new_style ^ old_style;
144 if (changed & WS_VISIBLE)
146 if (data->whole_window && X11DRV_is_window_rect_mapped( &data->window_rect ))
148 if (new_style & WS_VISIBLE)
150 TRACE( "mapping win %p\n", hwnd );
151 X11DRV_sync_window_style( display, data );
152 X11DRV_set_wm_hints( display, data );
153 wine_tsx11_lock();
154 XMapWindow( display, data->whole_window );
155 wine_tsx11_unlock();
157 /* we don't unmap windows, that causes trouble with the window manager */
159 invalidate_dce( hwnd, &data->window_rect );
162 if (changed & WS_DISABLED)
164 if (data->whole_window && data->managed)
166 XWMHints *wm_hints;
167 wine_tsx11_lock();
168 if (!(wm_hints = XGetWMHints( display, data->whole_window )))
169 wm_hints = XAllocWMHints();
170 if (wm_hints)
172 wm_hints->flags |= InputHint;
173 wm_hints->input = !(new_style & WS_DISABLED);
174 XSetWMHints( display, data->whole_window, wm_hints );
175 XFree(wm_hints);
177 wine_tsx11_unlock();
183 /***********************************************************************
184 * update_fullscreen_state
186 * Use the NETWM protocol to set the fullscreen state.
187 * This only works for mapped windows.
189 static void update_fullscreen_state( Display *display, Window win, BOOL new_fs_state )
191 XEvent xev;
193 TRACE("setting fullscreen state for window %lx to %s\n", win, new_fs_state ? "true" : "false");
195 xev.xclient.type = ClientMessage;
196 xev.xclient.window = win;
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[0] = new_fs_state ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
203 xev.xclient.data.l[1] = x11drv_atom(_NET_WM_STATE_FULLSCREEN);
204 xev.xclient.data.l[2] = 0;
205 wine_tsx11_lock();
206 XSendEvent(display, root_window, False, SubstructureRedirectMask | SubstructureNotifyMask, &xev);
207 wine_tsx11_unlock();
210 /***********************************************************************
211 * fullscreen_state_changed
213 * Check if the fullscreen state of a given window has changed
215 static BOOL fullscreen_state_changed( const struct x11drv_win_data *data,
216 const RECT *old_client_rect, const RECT *old_screen_rect,
217 BOOL *new_fs_state )
219 BOOL old_fs_state = FALSE;
221 *new_fs_state = FALSE;
223 if (old_client_rect->left <= 0 && old_client_rect->right >= old_screen_rect->right &&
224 old_client_rect->top <= 0 && old_client_rect->bottom >= old_screen_rect->bottom)
225 old_fs_state = TRUE;
227 if (data->client_rect.left <= 0 && data->client_rect.right >= screen_width &&
228 data->client_rect.top <= 0 && data->client_rect.bottom >= screen_height)
229 *new_fs_state = TRUE;
231 #if 0 /* useful to debug fullscreen state problems */
232 TRACE("hwnd %p, old rect %s, new rect %s, old screen %s, new screen (0,0-%d,%d)\n",
233 data->hwnd,
234 wine_dbgstr_rect(old_client_rect), wine_dbgstr_rect(&data->client_rect),
235 wine_dbgstr_rect(old_screen_rect), screen_width, screen_height);
236 TRACE("old fs state %d\n, new fs state = %d\n", old_fs_state, *new_fs_state);
237 #endif
238 return *new_fs_state != old_fs_state;
242 /***********************************************************************
243 * SetWindowPos (X11DRV.@)
245 BOOL X11DRV_SetWindowPos( HWND hwnd, HWND insert_after, const RECT *rectWindow,
246 const RECT *rectClient, UINT swp_flags, const RECT *valid_rects )
248 struct x11drv_win_data *data;
249 RECT new_whole_rect, old_client_rect, old_screen_rect;
250 WND *win;
251 DWORD old_style, new_style;
252 BOOL ret;
254 if (!(data = X11DRV_get_win_data( hwnd ))) return FALSE;
256 new_whole_rect = *rectWindow;
257 X11DRV_window_to_X_rect( data, &new_whole_rect );
259 old_client_rect = data->client_rect;
261 if (!IsRectEmpty( &valid_rects[0] ))
263 int x_offset = 0, y_offset = 0;
265 if (data->whole_window)
267 /* the X server will move the bits for us */
268 x_offset = data->whole_rect.left - new_whole_rect.left;
269 y_offset = data->whole_rect.top - new_whole_rect.top;
272 if (x_offset != valid_rects[1].left - valid_rects[0].left ||
273 y_offset != valid_rects[1].top - valid_rects[0].top)
275 /* FIXME: should copy the window bits here */
276 valid_rects = NULL;
280 if (!(win = WIN_GetPtr( hwnd ))) return FALSE;
281 if (win == WND_OTHER_PROCESS)
283 if (IsWindow( hwnd )) ERR( "cannot set rectangles of other process window %p\n", hwnd );
284 return FALSE;
286 SERVER_START_REQ( set_window_pos )
288 req->handle = hwnd;
289 req->previous = insert_after;
290 req->flags = swp_flags;
291 req->window.left = rectWindow->left;
292 req->window.top = rectWindow->top;
293 req->window.right = rectWindow->right;
294 req->window.bottom = rectWindow->bottom;
295 req->client.left = rectClient->left;
296 req->client.top = rectClient->top;
297 req->client.right = rectClient->right;
298 req->client.bottom = rectClient->bottom;
299 if (memcmp( rectWindow, &new_whole_rect, sizeof(RECT) ) || !IsRectEmpty( &valid_rects[0] ))
301 wine_server_add_data( req, &new_whole_rect, sizeof(new_whole_rect) );
302 if (!IsRectEmpty( &valid_rects[0] ))
303 wine_server_add_data( req, valid_rects, 2 * sizeof(*valid_rects) );
305 ret = !wine_server_call( req );
306 new_style = reply->new_style;
308 SERVER_END_REQ;
310 if (win == WND_DESKTOP || data->whole_window == DefaultRootWindow(gdi_display))
312 data->whole_rect = data->client_rect = data->window_rect = *rectWindow;
313 if (win != WND_DESKTOP)
315 win->rectWindow = *rectWindow;
316 win->rectClient = *rectClient;
317 win->dwStyle = new_style;
318 WIN_ReleasePtr( win );
320 return ret;
323 if (ret)
325 Display *display = thread_display();
327 /* invalidate DCEs */
329 if ((((swp_flags & SWP_AGG_NOPOSCHANGE) != SWP_AGG_NOPOSCHANGE) && (new_style & WS_VISIBLE)) ||
330 (swp_flags & (SWP_HIDEWINDOW | SWP_SHOWWINDOW)))
332 RECT rect;
333 UnionRect( &rect, rectWindow, &win->rectWindow );
334 invalidate_dce( hwnd, &rect );
337 win->rectWindow = *rectWindow;
338 win->rectClient = *rectClient;
339 old_style = win->dwStyle;
340 win->dwStyle = new_style;
341 data->window_rect = *rectWindow;
343 TRACE( "win %p window %s client %s style %08x\n",
344 hwnd, wine_dbgstr_rect(rectWindow), wine_dbgstr_rect(rectClient), new_style );
346 /* FIXME: copy the valid bits */
348 if (data->whole_window && !data->lock_changes)
350 if ((old_style & WS_VISIBLE) && !(new_style & WS_VISIBLE))
352 /* window got hidden, unmap it */
353 TRACE( "unmapping win %p\n", hwnd );
354 wine_tsx11_lock();
355 XUnmapWindow( display, data->whole_window );
356 wine_tsx11_unlock();
358 else if ((new_style & WS_VISIBLE) && !X11DRV_is_window_rect_mapped( rectWindow ))
360 /* resizing to zero size or off screen -> unmap */
361 TRACE( "unmapping zero size or off-screen win %p\n", hwnd );
362 wine_tsx11_lock();
363 XUnmapWindow( display, data->whole_window );
364 wine_tsx11_unlock();
368 X11DRV_sync_window_position( display, data, swp_flags, rectClient, &new_whole_rect );
370 if (data->whole_window && !data->lock_changes)
372 BOOL new_fs_state, mapped = FALSE;
374 if ((new_style & WS_VISIBLE) && !(new_style & WS_MINIMIZE) &&
375 X11DRV_is_window_rect_mapped( rectWindow ))
377 if (!(old_style & WS_VISIBLE))
379 /* window got shown, map it */
380 TRACE( "mapping win %p\n", hwnd );
381 X11DRV_sync_window_style( display, data );
382 X11DRV_set_wm_hints( display, data );
383 wine_tsx11_lock();
384 XMapWindow( display, data->whole_window );
385 wine_tsx11_unlock();
386 mapped = TRUE;
388 else if ((swp_flags & (SWP_NOSIZE | SWP_NOMOVE)) != (SWP_NOSIZE | SWP_NOMOVE))
390 /* resizing from zero size to non-zero -> map */
391 TRACE( "mapping non zero size or off-screen win %p\n", hwnd );
392 wine_tsx11_lock();
393 XMapWindow( display, data->whole_window );
394 wine_tsx11_unlock();
395 mapped = TRUE;
397 SetRect( &old_screen_rect, 0, 0, screen_width, screen_height );
398 if (fullscreen_state_changed( data, &old_client_rect, &old_screen_rect, &new_fs_state ) || mapped)
399 update_fullscreen_state( display, data->whole_window, new_fs_state );
403 WIN_ReleasePtr( win );
404 return ret;
408 /***********************************************************************
409 * WINPOS_FindIconPos
411 * Find a suitable place for an iconic window.
413 static POINT WINPOS_FindIconPos( HWND hwnd, POINT pt )
415 RECT rect, rectParent;
416 HWND parent, child;
417 HRGN hrgn, tmp;
418 int xspacing, yspacing;
420 parent = GetAncestor( hwnd, GA_PARENT );
421 GetClientRect( parent, &rectParent );
422 if ((pt.x >= rectParent.left) && (pt.x + GetSystemMetrics(SM_CXICON) < rectParent.right) &&
423 (pt.y >= rectParent.top) && (pt.y + GetSystemMetrics(SM_CYICON) < rectParent.bottom))
424 return pt; /* The icon already has a suitable position */
426 xspacing = GetSystemMetrics(SM_CXICONSPACING);
427 yspacing = GetSystemMetrics(SM_CYICONSPACING);
429 /* Check if another icon already occupies this spot */
430 /* FIXME: this is completely inefficient */
432 hrgn = CreateRectRgn( 0, 0, 0, 0 );
433 tmp = CreateRectRgn( 0, 0, 0, 0 );
434 for (child = GetWindow( parent, GW_HWNDFIRST ); child; child = GetWindow( child, GW_HWNDNEXT ))
436 WND *childPtr;
437 if (child == hwnd) continue;
438 if ((GetWindowLongW( child, GWL_STYLE ) & (WS_VISIBLE|WS_MINIMIZE)) != (WS_VISIBLE|WS_MINIMIZE))
439 continue;
440 if (!(childPtr = WIN_GetPtr( child )) || childPtr == WND_OTHER_PROCESS)
441 continue;
442 SetRectRgn( tmp, childPtr->rectWindow.left, childPtr->rectWindow.top,
443 childPtr->rectWindow.right, childPtr->rectWindow.bottom );
444 CombineRgn( hrgn, hrgn, tmp, RGN_OR );
445 WIN_ReleasePtr( childPtr );
447 DeleteObject( tmp );
449 for (rect.bottom = rectParent.bottom; rect.bottom >= yspacing; rect.bottom -= yspacing)
451 for (rect.left = rectParent.left; rect.left <= rectParent.right - xspacing; rect.left += xspacing)
453 rect.right = rect.left + xspacing;
454 rect.top = rect.bottom - yspacing;
455 if (!RectInRegion( hrgn, &rect ))
457 /* No window was found, so it's OK for us */
458 pt.x = rect.left + (xspacing - GetSystemMetrics(SM_CXICON)) / 2;
459 pt.y = rect.top + (yspacing - GetSystemMetrics(SM_CYICON)) / 2;
460 DeleteObject( hrgn );
461 return pt;
465 DeleteObject( hrgn );
466 pt.x = pt.y = 0;
467 return pt;
471 /***********************************************************************
472 * WINPOS_MinMaximize
474 UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect )
476 WND *wndPtr;
477 UINT swpFlags = 0;
478 POINT size;
479 LONG old_style;
480 WINDOWPLACEMENT wpl;
482 TRACE("%p %u\n", hwnd, cmd );
484 wpl.length = sizeof(wpl);
485 GetWindowPlacement( hwnd, &wpl );
487 if (HOOK_CallHooks( WH_CBT, HCBT_MINMAX, (WPARAM)hwnd, cmd, TRUE ))
488 return SWP_NOSIZE | SWP_NOMOVE;
490 if (IsIconic( hwnd ))
492 switch (cmd)
494 case SW_SHOWMINNOACTIVE:
495 case SW_SHOWMINIMIZED:
496 case SW_FORCEMINIMIZE:
497 case SW_MINIMIZE:
498 return SWP_NOSIZE | SWP_NOMOVE;
500 if (!SendMessageW( hwnd, WM_QUERYOPEN, 0, 0 )) return SWP_NOSIZE | SWP_NOMOVE;
501 swpFlags |= SWP_NOCOPYBITS;
504 switch( cmd )
506 case SW_SHOWMINNOACTIVE:
507 case SW_SHOWMINIMIZED:
508 case SW_FORCEMINIMIZE:
509 case SW_MINIMIZE:
510 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
511 if( wndPtr->dwStyle & WS_MAXIMIZE) wndPtr->flags |= WIN_RESTORE_MAX;
512 else wndPtr->flags &= ~WIN_RESTORE_MAX;
513 WIN_ReleasePtr( wndPtr );
515 old_style = WIN_SetStyle( hwnd, WS_MINIMIZE, WS_MAXIMIZE );
517 X11DRV_set_iconic_state( hwnd );
519 wpl.ptMinPosition = WINPOS_FindIconPos( hwnd, wpl.ptMinPosition );
521 if (!(old_style & WS_MINIMIZE)) swpFlags |= SWP_STATECHANGED;
522 SetRect( rect, wpl.ptMinPosition.x, wpl.ptMinPosition.y,
523 GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON) );
524 swpFlags |= SWP_NOCOPYBITS;
525 break;
527 case SW_MAXIMIZE:
528 old_style = GetWindowLongW( hwnd, GWL_STYLE );
529 if ((old_style & WS_MAXIMIZE) && (old_style & WS_VISIBLE)) return SWP_NOSIZE | SWP_NOMOVE;
531 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL );
533 old_style = WIN_SetStyle( hwnd, WS_MAXIMIZE, WS_MINIMIZE );
534 if (old_style & WS_MINIMIZE)
536 WINPOS_ShowIconTitle( hwnd, FALSE );
537 X11DRV_set_iconic_state( hwnd );
539 if (!(old_style & WS_MAXIMIZE)) swpFlags |= SWP_STATECHANGED;
540 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y );
541 break;
543 case SW_SHOWNOACTIVATE:
544 case SW_SHOWNORMAL:
545 case SW_RESTORE:
546 old_style = WIN_SetStyle( hwnd, 0, WS_MINIMIZE | WS_MAXIMIZE );
547 if (old_style & WS_MINIMIZE)
549 BOOL restore_max;
551 WINPOS_ShowIconTitle( hwnd, FALSE );
552 X11DRV_set_iconic_state( hwnd );
554 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
555 restore_max = (wndPtr->flags & WIN_RESTORE_MAX) != 0;
556 WIN_ReleasePtr( wndPtr );
557 if (restore_max)
559 /* Restore to maximized position */
560 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL);
561 WIN_SetStyle( hwnd, WS_MAXIMIZE, 0 );
562 swpFlags |= SWP_STATECHANGED;
563 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y );
564 break;
567 else if (!(old_style & WS_MAXIMIZE)) break;
569 swpFlags |= SWP_STATECHANGED;
571 /* Restore to normal position */
573 *rect = wpl.rcNormalPosition;
574 rect->right -= rect->left;
575 rect->bottom -= rect->top;
577 break;
580 return swpFlags;
584 /***********************************************************************
585 * ShowWindow (X11DRV.@)
587 BOOL X11DRV_ShowWindow( HWND hwnd, INT cmd )
589 WND *wndPtr;
590 HWND parent;
591 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
592 BOOL wasVisible = (style & WS_VISIBLE) != 0;
593 BOOL showFlag = TRUE;
594 RECT newPos = {0, 0, 0, 0};
595 UINT swp = 0;
597 TRACE("hwnd=%p, cmd=%d, wasVisible %d\n", hwnd, cmd, wasVisible);
599 switch(cmd)
601 case SW_HIDE:
602 if (!wasVisible) return FALSE;
603 showFlag = FALSE;
604 swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE;
605 if (hwnd != GetActiveWindow())
606 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
607 break;
609 case SW_SHOWMINNOACTIVE:
610 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
611 /* fall through */
612 case SW_MINIMIZE:
613 case SW_FORCEMINIMIZE: /* FIXME: Does not work if thread is hung. */
614 if (style & WS_CHILD) swp |= SWP_NOACTIVATE | SWP_NOZORDER;
615 /* fall through */
616 case SW_SHOWMINIMIZED:
617 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
618 swp |= WINPOS_MinMaximize( hwnd, cmd, &newPos );
619 if ((style & WS_MINIMIZE) && wasVisible) return TRUE;
620 break;
622 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
623 if (!wasVisible) swp |= SWP_SHOWWINDOW;
624 swp |= SWP_FRAMECHANGED;
625 swp |= WINPOS_MinMaximize( hwnd, SW_MAXIMIZE, &newPos );
626 if ((style & WS_MAXIMIZE) && wasVisible) return TRUE;
627 break;
629 case SW_SHOWNA:
630 swp |= SWP_NOACTIVATE | SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
631 if (style & WS_CHILD) swp |= SWP_NOZORDER;
632 break;
633 case SW_SHOW:
634 if (wasVisible) return TRUE;
635 swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
636 if (style & WS_CHILD) swp |= SWP_NOACTIVATE | SWP_NOZORDER;
637 break;
639 case SW_SHOWNOACTIVATE:
640 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
641 /* fall through */
642 case SW_RESTORE:
643 /* fall through */
644 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
645 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
646 if (!wasVisible) swp |= SWP_SHOWWINDOW;
647 if (style & (WS_MINIMIZE | WS_MAXIMIZE))
649 swp |= SWP_FRAMECHANGED;
650 swp |= WINPOS_MinMaximize( hwnd, cmd, &newPos );
652 else
654 if (wasVisible) return TRUE;
655 swp |= SWP_NOSIZE | SWP_NOMOVE;
657 if (style & WS_CHILD && !(swp & SWP_STATECHANGED)) swp |= SWP_NOACTIVATE | SWP_NOZORDER;
658 break;
661 if ((showFlag != wasVisible || cmd == SW_SHOWNA) && cmd != SW_SHOWMAXIMIZED && !(swp & SWP_STATECHANGED))
663 SendMessageW( hwnd, WM_SHOWWINDOW, showFlag, 0 );
664 if (!IsWindow( hwnd )) return wasVisible;
667 parent = GetAncestor( hwnd, GA_PARENT );
668 if (parent && !IsWindowVisible( parent ) && !(swp & SWP_STATECHANGED))
670 /* if parent is not visible simply toggle WS_VISIBLE and return */
671 if (showFlag) WIN_SetStyle( hwnd, WS_VISIBLE, 0 );
672 else WIN_SetStyle( hwnd, 0, WS_VISIBLE );
674 else
675 SetWindowPos( hwnd, HWND_TOP, newPos.left, newPos.top,
676 newPos.right, newPos.bottom, LOWORD(swp) );
678 if (cmd == SW_HIDE)
680 HWND hFocus;
682 /* FIXME: This will cause the window to be activated irrespective
683 * of whether it is owned by the same thread. Has to be done
684 * asynchronously.
687 if (hwnd == GetActiveWindow())
688 WINPOS_ActivateOtherWindow(hwnd);
690 /* Revert focus to parent */
691 hFocus = GetFocus();
692 if (hwnd == hFocus || IsChild(hwnd, hFocus))
694 HWND parent = GetAncestor(hwnd, GA_PARENT);
695 if (parent == GetDesktopWindow()) parent = 0;
696 SetFocus(parent);
700 if (IsIconic(hwnd)) WINPOS_ShowIconTitle( hwnd, TRUE );
702 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return wasVisible;
704 if (wndPtr->flags & WIN_NEED_SIZE)
706 /* should happen only in CreateWindowEx() */
707 int wParam = SIZE_RESTORED;
708 RECT client = wndPtr->rectClient;
710 wndPtr->flags &= ~WIN_NEED_SIZE;
711 if (wndPtr->dwStyle & WS_MAXIMIZE) wParam = SIZE_MAXIMIZED;
712 else if (wndPtr->dwStyle & WS_MINIMIZE) wParam = SIZE_MINIMIZED;
713 WIN_ReleasePtr( wndPtr );
715 SendMessageW( hwnd, WM_SIZE, wParam,
716 MAKELONG( client.right - client.left, client.bottom - client.top ));
717 SendMessageW( hwnd, WM_MOVE, 0, MAKELONG( client.left, client.top ));
719 else WIN_ReleasePtr( wndPtr );
721 return wasVisible;
725 /**********************************************************************
726 * X11DRV_MapNotify
728 void X11DRV_MapNotify( HWND hwnd, XEvent *event )
730 struct x11drv_win_data *data;
731 HWND hwndFocus = GetFocus();
732 WND *win;
734 if (!(data = X11DRV_get_win_data( hwnd ))) return;
736 if (!(win = WIN_GetPtr( hwnd ))) return;
738 if (data->managed && (win->dwStyle & WS_VISIBLE) && (win->dwStyle & WS_MINIMIZE))
740 int x, y;
741 unsigned int width, height, border, depth;
742 Window root, top;
743 RECT rect;
744 LONG style = WS_VISIBLE;
746 /* FIXME: hack */
747 wine_tsx11_lock();
748 XGetGeometry( event->xmap.display, data->whole_window, &root, &x, &y, &width, &height,
749 &border, &depth );
750 XTranslateCoordinates( event->xmap.display, data->whole_window, root, 0, 0, &x, &y, &top );
751 wine_tsx11_unlock();
752 rect.left = x;
753 rect.top = y;
754 rect.right = x + width;
755 rect.bottom = y + height;
756 OffsetRect( &rect, virtual_screen_rect.left, virtual_screen_rect.top );
757 X11DRV_X_to_window_rect( data, &rect );
759 invalidate_dce( hwnd, &data->window_rect );
761 if (win->flags & WIN_RESTORE_MAX) style |= WS_MAXIMIZE;
762 WIN_SetStyle( hwnd, style, WS_MINIMIZE );
763 WIN_ReleasePtr( win );
765 SendMessageW( hwnd, WM_SHOWWINDOW, SW_RESTORE, 0 );
766 data->lock_changes++;
767 SetWindowPos( hwnd, 0, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
768 SWP_NOZORDER | SWP_FRAMECHANGED | SWP_STATECHANGED );
769 data->lock_changes--;
771 else WIN_ReleasePtr( win );
772 if (hwndFocus && IsChild( hwnd, hwndFocus )) X11DRV_SetFocus(hwndFocus); /* FIXME */
776 /**********************************************************************
777 * X11DRV_UnmapNotify
779 void X11DRV_UnmapNotify( HWND hwnd, XEvent *event )
781 struct x11drv_win_data *data;
782 WND *win;
784 if (!(data = X11DRV_get_win_data( hwnd ))) return;
786 if (!(win = WIN_GetPtr( hwnd ))) return;
788 if ((win->dwStyle & WS_VISIBLE) && data->managed &&
789 X11DRV_is_window_rect_mapped( &win->rectWindow ))
791 if (win->dwStyle & WS_MAXIMIZE)
792 win->flags |= WIN_RESTORE_MAX;
793 else if (!(win->dwStyle & WS_MINIMIZE))
794 win->flags &= ~WIN_RESTORE_MAX;
796 WIN_SetStyle( hwnd, WS_MINIMIZE, WS_MAXIMIZE );
797 WIN_ReleasePtr( win );
799 EndMenu();
800 SendMessageW( hwnd, WM_SHOWWINDOW, SW_MINIMIZE, 0 );
801 data->lock_changes++;
802 SetWindowPos( hwnd, 0, 0, 0, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON),
803 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_STATECHANGED );
804 data->lock_changes--;
806 else WIN_ReleasePtr( win );
809 struct desktop_resize_data
811 RECT old_screen_rect;
812 RECT old_virtual_rect;
815 static BOOL CALLBACK update_windows_on_desktop_resize( HWND hwnd, LPARAM lparam )
817 struct x11drv_win_data *data;
818 Display *display = thread_display();
819 struct desktop_resize_data *resize_data = (struct desktop_resize_data *)lparam;
820 int mask = 0;
822 if (!(data = X11DRV_get_win_data( hwnd ))) return TRUE;
824 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE)
826 BOOL new_fs_state;
828 if (fullscreen_state_changed( data, &data->client_rect, &resize_data->old_screen_rect, &new_fs_state ))
829 update_fullscreen_state( display, data->whole_window, new_fs_state );
832 if (resize_data->old_virtual_rect.left != virtual_screen_rect.left) mask |= CWX;
833 if (resize_data->old_virtual_rect.top != virtual_screen_rect.top) mask |= CWY;
834 if (mask && data->whole_window)
836 XWindowChanges changes;
838 wine_tsx11_lock();
839 changes.x = data->whole_rect.left - virtual_screen_rect.left;
840 changes.y = data->whole_rect.top - virtual_screen_rect.top;
841 XReconfigureWMWindow( display, data->whole_window,
842 DefaultScreen(display), mask, &changes );
843 wine_tsx11_unlock();
845 return TRUE;
849 /***********************************************************************
850 * X11DRV_handle_desktop_resize
852 void X11DRV_handle_desktop_resize( unsigned int width, unsigned int height )
854 HWND hwnd = GetDesktopWindow();
855 struct x11drv_win_data *data;
856 struct desktop_resize_data resize_data;
858 if (!(data = X11DRV_get_win_data( hwnd ))) return;
860 SetRect( &resize_data.old_screen_rect, 0, 0, screen_width, screen_height );
861 resize_data.old_virtual_rect = virtual_screen_rect;
863 screen_width = width;
864 screen_height = height;
865 xinerama_init();
866 TRACE("desktop %p change to (%dx%d)\n", hwnd, width, height);
867 data->lock_changes++;
868 X11DRV_SetWindowPos( hwnd, 0, &virtual_screen_rect, &virtual_screen_rect,
869 SWP_NOZORDER|SWP_NOMOVE, NULL );
870 data->lock_changes--;
871 ClipCursor(NULL);
872 SendMessageTimeoutW( HWND_BROADCAST, WM_DISPLAYCHANGE, screen_depth,
873 MAKELPARAM( width, height ), SMTO_ABORTIFHUNG, 2000, NULL );
875 EnumWindows( update_windows_on_desktop_resize, (LPARAM)&resize_data );
879 /***********************************************************************
880 * X11DRV_ConfigureNotify
882 void X11DRV_ConfigureNotify( HWND hwnd, XEvent *xev )
884 XConfigureEvent *event = &xev->xconfigure;
885 struct x11drv_win_data *data;
886 RECT rect;
887 UINT flags;
888 int cx, cy, x = event->x, y = event->y;
890 if (!hwnd) return;
891 if (!(data = X11DRV_get_win_data( hwnd ))) return;
893 /* Get geometry */
895 if (!event->send_event) /* normal event, need to map coordinates to the root */
897 Window child;
898 wine_tsx11_lock();
899 XTranslateCoordinates( event->display, data->whole_window, root_window,
900 0, 0, &x, &y, &child );
901 wine_tsx11_unlock();
903 rect.left = x;
904 rect.top = y;
905 rect.right = x + event->width;
906 rect.bottom = y + event->height;
907 OffsetRect( &rect, virtual_screen_rect.left, virtual_screen_rect.top );
908 TRACE( "win %p new X rect %d,%d,%dx%d (event %d,%d,%dx%d)\n",
909 hwnd, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
910 event->x, event->y, event->width, event->height );
911 X11DRV_X_to_window_rect( data, &rect );
913 x = rect.left;
914 y = rect.top;
915 cx = rect.right - rect.left;
916 cy = rect.bottom - rect.top;
917 flags = SWP_NOACTIVATE | SWP_NOZORDER;
919 /* Compare what has changed */
921 GetWindowRect( hwnd, &rect );
922 if (rect.left == x && rect.top == y) flags |= SWP_NOMOVE;
923 else
924 TRACE( "%p moving from (%d,%d) to (%d,%d)\n",
925 hwnd, rect.left, rect.top, x, y );
927 if ((rect.right - rect.left == cx && rect.bottom - rect.top == cy) ||
928 IsIconic(hwnd) ||
929 (IsRectEmpty( &rect ) && event->width == 1 && event->height == 1))
931 if (flags & SWP_NOMOVE) return; /* if nothing changed, don't do anything */
932 flags |= SWP_NOSIZE;
934 else
935 TRACE( "%p resizing from (%dx%d) to (%dx%d)\n",
936 hwnd, rect.right - rect.left, rect.bottom - rect.top, cx, cy );
938 data->lock_changes++;
939 SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
940 data->lock_changes--;
944 /***********************************************************************
945 * SetWindowRgn (X11DRV.@)
947 * Assign specified region to window (for non-rectangular windows)
949 int X11DRV_SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL redraw )
951 struct x11drv_win_data *data;
953 if (!(data = X11DRV_get_win_data( hwnd )))
955 if (IsWindow( hwnd ))
956 FIXME( "not supported on other thread window %p\n", hwnd );
957 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
958 return FALSE;
961 #ifdef HAVE_LIBXSHAPE
962 if (data->whole_window)
964 Display *display = thread_display();
966 if (!hrgn)
968 wine_tsx11_lock();
969 XShapeCombineMask( display, data->whole_window,
970 ShapeBounding, 0, 0, None, ShapeSet );
971 wine_tsx11_unlock();
973 else
975 RGNDATA *pRegionData = X11DRV_GetRegionData( hrgn, 0 );
976 if (pRegionData)
978 wine_tsx11_lock();
979 XShapeCombineRectangles( display, data->whole_window, ShapeBounding,
980 data->window_rect.left - data->whole_rect.left,
981 data->window_rect.top - data->whole_rect.top,
982 (XRectangle *)pRegionData->Buffer,
983 pRegionData->rdh.nCount,
984 ShapeSet, YXBanded );
985 wine_tsx11_unlock();
986 HeapFree(GetProcessHeap(), 0, pRegionData);
990 #endif /* HAVE_LIBXSHAPE */
992 invalidate_dce( hwnd, &data->window_rect );
993 return TRUE;
997 /***********************************************************************
998 * draw_moving_frame
1000 * Draw the frame used when moving or resizing window.
1002 * FIXME: This causes problems in Win95 mode. (why?)
1004 static void draw_moving_frame( HDC hdc, RECT *rect, BOOL thickframe )
1006 if (thickframe)
1008 const int width = GetSystemMetrics(SM_CXFRAME);
1009 const int height = GetSystemMetrics(SM_CYFRAME);
1011 HBRUSH hbrush = SelectObject( hdc, GetStockObject( GRAY_BRUSH ) );
1012 PatBlt( hdc, rect->left, rect->top,
1013 rect->right - rect->left - width, height, PATINVERT );
1014 PatBlt( hdc, rect->left, rect->top + height, width,
1015 rect->bottom - rect->top - height, PATINVERT );
1016 PatBlt( hdc, rect->left + width, rect->bottom - 1,
1017 rect->right - rect->left - width, -height, PATINVERT );
1018 PatBlt( hdc, rect->right - 1, rect->top, -width,
1019 rect->bottom - rect->top - height, PATINVERT );
1020 SelectObject( hdc, hbrush );
1022 else DrawFocusRect( hdc, rect );
1026 /***********************************************************************
1027 * start_size_move
1029 * Initialisation of a move or resize, when initiatied from a menu choice.
1030 * Return hit test code for caption or sizing border.
1032 static LONG start_size_move( HWND hwnd, WPARAM wParam, POINT *capturePoint, LONG style )
1034 LONG hittest = 0;
1035 POINT pt;
1036 MSG msg;
1037 RECT rectWindow;
1039 GetWindowRect( hwnd, &rectWindow );
1041 if ((wParam & 0xfff0) == SC_MOVE)
1043 /* Move pointer at the center of the caption */
1044 RECT rect = rectWindow;
1045 /* Note: to be exactly centered we should take the different types
1046 * of border into account, but it shouldn't make more that a few pixels
1047 * of difference so let's not bother with that */
1048 rect.top += GetSystemMetrics(SM_CYBORDER);
1049 if (style & WS_SYSMENU)
1050 rect.left += GetSystemMetrics(SM_CXSIZE) + 1;
1051 if (style & WS_MINIMIZEBOX)
1052 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1053 if (style & WS_MAXIMIZEBOX)
1054 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1055 pt.x = (rect.right + rect.left) / 2;
1056 pt.y = rect.top + GetSystemMetrics(SM_CYSIZE)/2;
1057 hittest = HTCAPTION;
1058 *capturePoint = pt;
1060 else /* SC_SIZE */
1062 pt.x = pt.y = 0;
1063 while(!hittest)
1065 GetMessageW( &msg, 0, WM_KEYFIRST, WM_MOUSELAST );
1066 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
1068 switch(msg.message)
1070 case WM_MOUSEMOVE:
1071 pt = msg.pt;
1072 hittest = SendMessageW( hwnd, WM_NCHITTEST, 0, MAKELONG( pt.x, pt.y ) );
1073 if ((hittest < HTLEFT) || (hittest > HTBOTTOMRIGHT)) hittest = 0;
1074 break;
1076 case WM_LBUTTONUP:
1077 return 0;
1079 case WM_KEYDOWN:
1080 switch(msg.wParam)
1082 case VK_UP:
1083 hittest = HTTOP;
1084 pt.x =(rectWindow.left+rectWindow.right)/2;
1085 pt.y = rectWindow.top + GetSystemMetrics(SM_CYFRAME) / 2;
1086 break;
1087 case VK_DOWN:
1088 hittest = HTBOTTOM;
1089 pt.x =(rectWindow.left+rectWindow.right)/2;
1090 pt.y = rectWindow.bottom - GetSystemMetrics(SM_CYFRAME) / 2;
1091 break;
1092 case VK_LEFT:
1093 hittest = HTLEFT;
1094 pt.x = rectWindow.left + GetSystemMetrics(SM_CXFRAME) / 2;
1095 pt.y =(rectWindow.top+rectWindow.bottom)/2;
1096 break;
1097 case VK_RIGHT:
1098 hittest = HTRIGHT;
1099 pt.x = rectWindow.right - GetSystemMetrics(SM_CXFRAME) / 2;
1100 pt.y =(rectWindow.top+rectWindow.bottom)/2;
1101 break;
1102 case VK_RETURN:
1103 case VK_ESCAPE: return 0;
1107 *capturePoint = pt;
1109 SetCursorPos( pt.x, pt.y );
1110 SendMessageW( hwnd, WM_SETCURSOR, (WPARAM)hwnd, MAKELONG( hittest, WM_MOUSEMOVE ));
1111 return hittest;
1115 /***********************************************************************
1116 * set_movesize_capture
1118 static void set_movesize_capture( HWND hwnd )
1120 HWND previous = 0;
1122 SERVER_START_REQ( set_capture_window )
1124 req->handle = hwnd;
1125 req->flags = CAPTURE_MOVESIZE;
1126 if (!wine_server_call_err( req ))
1128 previous = reply->previous;
1129 hwnd = reply->full_handle;
1132 SERVER_END_REQ;
1133 if (previous && previous != hwnd)
1134 SendMessageW( previous, WM_CAPTURECHANGED, 0, (LPARAM)hwnd );
1137 /***********************************************************************
1138 * X11DRV_WMMoveResizeWindow
1140 * Tells the window manager to initiate a move or resize operation.
1142 * SEE
1143 * http://freedesktop.org/Standards/wm-spec/1.3/ar01s04.html
1144 * or search for "_NET_WM_MOVERESIZE"
1146 static void X11DRV_WMMoveResizeWindow( HWND hwnd, int x, int y, int dir )
1148 XEvent xev;
1149 Display *display = thread_display();
1151 TRACE("hwnd %p, x %d, y %d, dir %d\n", hwnd, x, y, dir);
1153 xev.xclient.type = ClientMessage;
1154 xev.xclient.window = X11DRV_get_whole_window(hwnd);
1155 xev.xclient.message_type = x11drv_atom(_NET_WM_MOVERESIZE);
1156 xev.xclient.serial = 0;
1157 xev.xclient.display = display;
1158 xev.xclient.send_event = True;
1159 xev.xclient.format = 32;
1160 xev.xclient.data.l[0] = x; /* x coord */
1161 xev.xclient.data.l[1] = y; /* y coord */
1162 xev.xclient.data.l[2] = dir; /* direction */
1163 xev.xclient.data.l[3] = 1; /* button */
1164 xev.xclient.data.l[4] = 0; /* unused */
1166 /* need to ungrab the pointer that may have been automatically grabbed
1167 * with a ButtonPress event */
1168 wine_tsx11_lock();
1169 XUngrabPointer( display, CurrentTime );
1170 XSendEvent(display, root_window, False, SubstructureNotifyMask, &xev);
1171 wine_tsx11_unlock();
1174 /***********************************************************************
1175 * SysCommandSizeMove (X11DRV.@)
1177 * Perform SC_MOVE and SC_SIZE commands.
1179 void X11DRV_SysCommandSizeMove( HWND hwnd, WPARAM wParam )
1181 MSG msg;
1182 RECT sizingRect, mouseRect, origRect;
1183 HDC hdc;
1184 HWND parent;
1185 LONG hittest = (LONG)(wParam & 0x0f);
1186 WPARAM syscommand = wParam & 0xfff0;
1187 HCURSOR hDragCursor = 0, hOldCursor = 0;
1188 POINT minTrack, maxTrack;
1189 POINT capturePoint, pt;
1190 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
1191 BOOL thickframe = HAS_THICKFRAME( style );
1192 BOOL iconic = style & WS_MINIMIZE;
1193 BOOL moved = FALSE;
1194 DWORD dwPoint = GetMessagePos ();
1195 BOOL DragFullWindows = FALSE;
1196 BOOL grab;
1197 Window parent_win, whole_win;
1198 Display *old_gdi_display = NULL;
1199 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1200 struct x11drv_win_data *data;
1202 pt.x = (short)LOWORD(dwPoint);
1203 pt.y = (short)HIWORD(dwPoint);
1204 capturePoint = pt;
1206 if (IsZoomed(hwnd) || !IsWindowVisible(hwnd)) return;
1208 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1210 TRACE("hwnd %p (%smanaged), command %04x, hittest %d, pos %d,%d\n",
1211 hwnd, data->managed ? "" : "NOT ", syscommand, hittest, pt.x, pt.y);
1213 /* if we are managed then we let the WM do all the work */
1214 if (data->managed)
1216 int dir;
1217 if (syscommand == SC_MOVE)
1219 if (!hittest) dir = _NET_WM_MOVERESIZE_MOVE_KEYBOARD;
1220 else dir = _NET_WM_MOVERESIZE_MOVE;
1222 else if (!hittest) dir = _NET_WM_MOVERESIZE_SIZE_KEYBOARD;
1223 else
1224 switch (hittest)
1226 case WMSZ_LEFT: dir = _NET_WM_MOVERESIZE_SIZE_LEFT; break;
1227 case WMSZ_RIGHT: dir = _NET_WM_MOVERESIZE_SIZE_RIGHT; break;
1228 case WMSZ_TOP: dir = _NET_WM_MOVERESIZE_SIZE_TOP; break;
1229 case WMSZ_TOPLEFT: dir = _NET_WM_MOVERESIZE_SIZE_TOPLEFT; break;
1230 case WMSZ_TOPRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT; break;
1231 case WMSZ_BOTTOM: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOM; break;
1232 case WMSZ_BOTTOMLEFT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT; break;
1233 case WMSZ_BOTTOMRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT; break;
1234 default:
1235 ERR("Invalid hittest value: %d\n", hittest);
1236 dir = _NET_WM_MOVERESIZE_SIZE_KEYBOARD;
1238 X11DRV_WMMoveResizeWindow( hwnd, pt.x, pt.y, dir );
1239 return;
1242 SystemParametersInfoA(SPI_GETDRAGFULLWINDOWS, 0, &DragFullWindows, 0);
1244 if (syscommand == SC_MOVE)
1246 if (!hittest) hittest = start_size_move( hwnd, wParam, &capturePoint, style );
1247 if (!hittest) return;
1249 else /* SC_SIZE */
1251 if ( hittest && (syscommand != SC_MOUSEMENU) )
1252 hittest += (HTLEFT - WMSZ_LEFT);
1253 else
1255 set_movesize_capture( hwnd );
1256 hittest = start_size_move( hwnd, wParam, &capturePoint, style );
1257 if (!hittest)
1259 set_movesize_capture(0);
1260 return;
1265 /* Get min/max info */
1267 WINPOS_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack );
1268 GetWindowRect( hwnd, &sizingRect );
1269 if (style & WS_CHILD)
1271 parent = GetParent(hwnd);
1272 /* make sizing rect relative to parent */
1273 MapWindowPoints( 0, parent, (POINT*)&sizingRect, 2 );
1274 GetClientRect( parent, &mouseRect );
1276 else
1278 parent = 0;
1279 mouseRect = virtual_screen_rect;
1281 origRect = sizingRect;
1283 if (ON_LEFT_BORDER(hittest))
1285 mouseRect.left = max( mouseRect.left, sizingRect.right-maxTrack.x );
1286 mouseRect.right = min( mouseRect.right, sizingRect.right-minTrack.x );
1288 else if (ON_RIGHT_BORDER(hittest))
1290 mouseRect.left = max( mouseRect.left, sizingRect.left+minTrack.x );
1291 mouseRect.right = min( mouseRect.right, sizingRect.left+maxTrack.x );
1293 if (ON_TOP_BORDER(hittest))
1295 mouseRect.top = max( mouseRect.top, sizingRect.bottom-maxTrack.y );
1296 mouseRect.bottom = min( mouseRect.bottom,sizingRect.bottom-minTrack.y);
1298 else if (ON_BOTTOM_BORDER(hittest))
1300 mouseRect.top = max( mouseRect.top, sizingRect.top+minTrack.y );
1301 mouseRect.bottom = min( mouseRect.bottom, sizingRect.top+maxTrack.y );
1303 if (parent) MapWindowPoints( parent, 0, (LPPOINT)&mouseRect, 2 );
1305 /* Retrieve a default cache DC (without using the window style) */
1306 hdc = GetDCEx( parent, 0, DCX_CACHE );
1308 if( iconic ) /* create a cursor for dragging */
1310 hDragCursor = (HCURSOR)GetClassLongPtrW( hwnd, GCLP_HICON);
1311 if( !hDragCursor ) hDragCursor = (HCURSOR)SendMessageW( hwnd, WM_QUERYDRAGICON, 0, 0L);
1312 if( !hDragCursor ) iconic = FALSE;
1315 /* repaint the window before moving it around */
1316 RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN );
1318 SendMessageW( hwnd, WM_ENTERSIZEMOVE, 0, 0 );
1319 set_movesize_capture( hwnd );
1321 /* grab the server only when moving top-level windows without desktop */
1322 grab = (!DragFullWindows && !parent && (root_window == DefaultRootWindow(gdi_display)));
1324 if (grab)
1326 wine_tsx11_lock();
1327 XSync( gdi_display, False );
1328 XGrabServer( thread_data->display );
1329 XSync( thread_data->display, False );
1330 /* switch gdi display to the thread display, since the server is grabbed */
1331 old_gdi_display = gdi_display;
1332 gdi_display = thread_data->display;
1333 wine_tsx11_unlock();
1335 whole_win = X11DRV_get_whole_window( GetAncestor(hwnd,GA_ROOT) );
1336 parent_win = parent ? X11DRV_get_whole_window( GetAncestor(parent,GA_ROOT) ) : root_window;
1338 wine_tsx11_lock();
1339 XGrabPointer( thread_data->display, whole_win, False,
1340 PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
1341 GrabModeAsync, GrabModeAsync, parent_win, None, CurrentTime );
1342 wine_tsx11_unlock();
1343 thread_data->grab_window = whole_win;
1345 while(1)
1347 int dx = 0, dy = 0;
1349 if (!GetMessageW( &msg, 0, WM_KEYFIRST, WM_MOUSELAST )) break;
1350 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
1352 /* Exit on button-up, Return, or Esc */
1353 if ((msg.message == WM_LBUTTONUP) ||
1354 ((msg.message == WM_KEYDOWN) &&
1355 ((msg.wParam == VK_RETURN) || (msg.wParam == VK_ESCAPE)))) break;
1357 if ((msg.message != WM_KEYDOWN) && (msg.message != WM_MOUSEMOVE))
1358 continue; /* We are not interested in other messages */
1360 pt = msg.pt;
1362 if (msg.message == WM_KEYDOWN) switch(msg.wParam)
1364 case VK_UP: pt.y -= 8; break;
1365 case VK_DOWN: pt.y += 8; break;
1366 case VK_LEFT: pt.x -= 8; break;
1367 case VK_RIGHT: pt.x += 8; break;
1370 pt.x = max( pt.x, mouseRect.left );
1371 pt.x = min( pt.x, mouseRect.right );
1372 pt.y = max( pt.y, mouseRect.top );
1373 pt.y = min( pt.y, mouseRect.bottom );
1375 dx = pt.x - capturePoint.x;
1376 dy = pt.y - capturePoint.y;
1378 if (dx || dy)
1380 if( !moved )
1382 moved = TRUE;
1384 if( iconic ) /* ok, no system popup tracking */
1386 hOldCursor = SetCursor(hDragCursor);
1387 ShowCursor( TRUE );
1388 WINPOS_ShowIconTitle( hwnd, FALSE );
1390 else if(!DragFullWindows)
1391 draw_moving_frame( hdc, &sizingRect, thickframe );
1394 if (msg.message == WM_KEYDOWN) SetCursorPos( pt.x, pt.y );
1395 else
1397 RECT newRect = sizingRect;
1398 WPARAM wpSizingHit = 0;
1400 if (hittest == HTCAPTION) OffsetRect( &newRect, dx, dy );
1401 if (ON_LEFT_BORDER(hittest)) newRect.left += dx;
1402 else if (ON_RIGHT_BORDER(hittest)) newRect.right += dx;
1403 if (ON_TOP_BORDER(hittest)) newRect.top += dy;
1404 else if (ON_BOTTOM_BORDER(hittest)) newRect.bottom += dy;
1405 if(!iconic && !DragFullWindows) draw_moving_frame( hdc, &sizingRect, thickframe );
1406 capturePoint = pt;
1408 /* determine the hit location */
1409 if (hittest >= HTLEFT && hittest <= HTBOTTOMRIGHT)
1410 wpSizingHit = WMSZ_LEFT + (hittest - HTLEFT);
1411 SendMessageW( hwnd, WM_SIZING, wpSizingHit, (LPARAM)&newRect );
1413 if (!iconic)
1415 if(!DragFullWindows)
1416 draw_moving_frame( hdc, &newRect, thickframe );
1417 else
1418 SetWindowPos( hwnd, 0, newRect.left, newRect.top,
1419 newRect.right - newRect.left,
1420 newRect.bottom - newRect.top,
1421 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
1423 sizingRect = newRect;
1428 set_movesize_capture(0);
1429 if( iconic )
1431 if( moved ) /* restore cursors, show icon title later on */
1433 ShowCursor( FALSE );
1434 SetCursor( hOldCursor );
1437 else if (moved && !DragFullWindows)
1438 draw_moving_frame( hdc, &sizingRect, thickframe );
1440 ReleaseDC( parent, hdc );
1442 wine_tsx11_lock();
1443 XUngrabPointer( thread_data->display, CurrentTime );
1444 if (grab)
1446 XSync( thread_data->display, False );
1447 XUngrabServer( thread_data->display );
1448 XSync( thread_data->display, False );
1449 gdi_display = old_gdi_display;
1451 wine_tsx11_unlock();
1452 thread_data->grab_window = None;
1454 if (HOOK_CallHooks( WH_CBT, HCBT_MOVESIZE, (WPARAM)hwnd, (LPARAM)&sizingRect, TRUE ))
1455 moved = FALSE;
1457 SendMessageW( hwnd, WM_EXITSIZEMOVE, 0, 0 );
1458 SendMessageW( hwnd, WM_SETVISIBLE, !IsIconic(hwnd), 0L);
1460 /* window moved or resized */
1461 if (moved)
1463 /* if the moving/resizing isn't canceled call SetWindowPos
1464 * with the new position or the new size of the window
1466 if (!((msg.message == WM_KEYDOWN) && (msg.wParam == VK_ESCAPE)) )
1468 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
1469 if(!DragFullWindows)
1470 SetWindowPos( hwnd, 0, sizingRect.left, sizingRect.top,
1471 sizingRect.right - sizingRect.left,
1472 sizingRect.bottom - sizingRect.top,
1473 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
1475 else
1476 { /* restore previous size/position */
1477 if(DragFullWindows)
1478 SetWindowPos( hwnd, 0, origRect.left, origRect.top,
1479 origRect.right - origRect.left,
1480 origRect.bottom - origRect.top,
1481 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
1485 if (IsIconic(hwnd))
1487 /* Single click brings up the system menu when iconized */
1489 if( !moved )
1491 if(style & WS_SYSMENU )
1492 SendMessageW( hwnd, WM_SYSCOMMAND,
1493 SC_MOUSEMENU + HTSYSMENU, MAKELONG(pt.x,pt.y));
1495 else WINPOS_ShowIconTitle( hwnd, TRUE );