dpnet: Assign to structs instead of using memcpy.
[wine.git] / dlls / winex11.drv / winpos.c
blob13aec41e2381764e7114778eea1a5047a0cf1264
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 #include <stdarg.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "wingdi.h"
31 #include "winuser.h"
32 #include "winerror.h"
33 #include "wine/wingdi16.h"
35 #include "x11drv.h"
36 #include "win.h"
38 #include "wine/server.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
43 #define SWP_AGG_NOPOSCHANGE \
44 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_NOZORDER)
46 #define SWP_EX_NOCOPY 0x0001
47 #define SWP_EX_PAINTSELF 0x0002
48 #define SWP_EX_NONCLIENT 0x0004
50 #define HAS_THICKFRAME(style) \
51 (((style) & WS_THICKFRAME) && \
52 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
54 #define ON_LEFT_BORDER(hit) \
55 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
56 #define ON_RIGHT_BORDER(hit) \
57 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
58 #define ON_TOP_BORDER(hit) \
59 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
60 #define ON_BOTTOM_BORDER(hit) \
61 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
63 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
64 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
65 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
66 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
67 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
68 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
69 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
70 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
71 #define _NET_WM_MOVERESIZE_MOVE 8 /* movement only */
72 #define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9 /* size via keyboard */
73 #define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10 /* move via keyboard */
75 #define _NET_WM_STATE_REMOVE 0
76 #define _NET_WM_STATE_ADD 1
77 #define _NET_WM_STATE_TOGGLE 2
79 static const char managed_prop[] = "__wine_x11_managed";
81 /***********************************************************************
82 * X11DRV_Expose
84 void X11DRV_Expose( HWND hwnd, XEvent *xev )
86 XExposeEvent *event = &xev->xexpose;
87 RECT rect;
88 struct x11drv_win_data *data;
89 int flags = RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN;
91 TRACE( "win %p (%lx) %d,%d %dx%d\n",
92 hwnd, event->window, event->x, event->y, event->width, event->height );
94 if (!(data = X11DRV_get_win_data( hwnd ))) return;
96 if (event->window == data->whole_window)
98 rect.left = data->whole_rect.left + event->x;
99 rect.top = data->whole_rect.top + event->y;
100 flags |= RDW_FRAME;
102 else
104 rect.left = data->client_rect.left + event->x;
105 rect.top = data->client_rect.top + event->y;
107 rect.right = rect.left + event->width;
108 rect.bottom = rect.top + event->height;
110 if (event->window == root_window)
111 OffsetRect( &rect, virtual_screen_rect.left, virtual_screen_rect.top );
113 SERVER_START_REQ( update_window_zorder )
115 req->window = hwnd;
116 req->rect.left = rect.left;
117 req->rect.top = rect.top;
118 req->rect.right = rect.right;
119 req->rect.bottom = rect.bottom;
120 wine_server_call( req );
122 SERVER_END_REQ;
124 /* make position relative to client area instead of parent */
125 OffsetRect( &rect, -data->client_rect.left, -data->client_rect.top );
126 RedrawWindow( hwnd, &rect, 0, flags );
129 /***********************************************************************
130 * SetWindowStyle (X11DRV.@)
132 * Update the X state of a window to reflect a style change
134 void X11DRV_SetWindowStyle( HWND hwnd, DWORD old_style )
136 Display *display = thread_display();
137 struct x11drv_win_data *data;
138 DWORD new_style, changed;
140 if (hwnd == GetDesktopWindow()) return;
141 new_style = GetWindowLongW( hwnd, GWL_STYLE );
142 changed = new_style ^ old_style;
144 if ((changed & WS_VISIBLE) && (new_style & WS_VISIBLE))
146 /* we don't unmap windows, that causes trouble with the window manager */
147 if (!(data = X11DRV_get_win_data( hwnd )) &&
148 !(data = X11DRV_create_win_data( hwnd ))) return;
150 if (data->whole_window && X11DRV_is_window_rect_mapped( &data->window_rect ))
152 X11DRV_set_wm_hints( display, data );
153 if (!data->mapped)
155 TRACE( "mapping win %p\n", hwnd );
156 X11DRV_sync_window_style( display, data );
157 wine_tsx11_lock();
158 XMapWindow( display, data->whole_window );
159 wine_tsx11_unlock();
160 data->mapped = TRUE;
165 if (changed & WS_DISABLED)
167 data = X11DRV_get_win_data( hwnd );
168 if (data && data->wm_hints)
170 wine_tsx11_lock();
171 data->wm_hints->input = !(new_style & WS_DISABLED);
172 XSetWMHints( display, data->whole_window, data->wm_hints );
173 wine_tsx11_unlock();
179 /***********************************************************************
180 * update_wm_states
182 static void update_wm_states( Display *display, struct x11drv_win_data *data, BOOL force )
184 static const unsigned int state_atoms[NB_WM_STATES] =
186 XATOM__NET_WM_STATE_FULLSCREEN,
187 XATOM__NET_WM_STATE_ABOVE,
188 XATOM__NET_WM_STATE_SKIP_PAGER,
189 XATOM__NET_WM_STATE_SKIP_TASKBAR
192 DWORD i, ex_style, new_state = 0;
193 XEvent xev;
195 if (!data->managed) return;
196 if (!data->mapped) return;
198 if (data->whole_rect.left <= 0 && data->whole_rect.right >= screen_width &&
199 data->whole_rect.top <= 0 && data->whole_rect.bottom >= screen_height)
200 new_state |= (1 << WM_STATE_FULLSCREEN);
202 ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE );
203 if (ex_style & WS_EX_TOPMOST)
204 new_state |= (1 << WM_STATE_ABOVE);
205 if (ex_style & WS_EX_TOOLWINDOW)
206 new_state |= (1 << WM_STATE_SKIP_TASKBAR) | (1 << WM_STATE_SKIP_PAGER);
208 xev.xclient.type = ClientMessage;
209 xev.xclient.window = data->whole_window;
210 xev.xclient.message_type = x11drv_atom(_NET_WM_STATE);
211 xev.xclient.serial = 0;
212 xev.xclient.display = display;
213 xev.xclient.send_event = True;
214 xev.xclient.format = 32;
215 xev.xclient.data.l[2] = 0;
216 xev.xclient.data.l[3] = 1;
218 for (i = 0; i < NB_WM_STATES; i++)
220 if (!((data->wm_state ^ new_state) & (1 << i))) /* unchanged */
222 /* if forced, we only add states, we don't remove them */
223 if (!force || !(new_state & (1 << i))) continue;
226 TRACE( "setting wm state %u for window %p/%lx to %u prev %u\n",
227 i, data->hwnd, data->whole_window,
228 (new_state & (1 << i)) != 0, (data->wm_state & (1 << i)) != 0 );
230 xev.xclient.data.l[0] = (new_state & (1 << i)) ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
231 xev.xclient.data.l[1] = X11DRV_Atoms[state_atoms[i] - FIRST_XATOM];
232 wine_tsx11_lock();
233 XSendEvent( display, root_window, False, SubstructureRedirectMask | SubstructureNotifyMask, &xev );
234 wine_tsx11_unlock();
236 data->wm_state = new_state;
240 /***********************************************************************
241 * move_window_bits
243 * Move the window bits when a window is moved.
245 static void move_window_bits( struct x11drv_win_data *data, const RECT *old_rect, const RECT *new_rect,
246 const RECT *old_client_rect )
248 RECT src_rect = *old_rect;
249 RECT dst_rect = *new_rect;
250 HDC hdc_src, hdc_dst;
251 INT code;
252 HRGN rgn = 0;
253 HWND parent = 0;
255 if (!data->whole_window)
257 OffsetRect( &dst_rect, -data->window_rect.left, -data->window_rect.top );
258 parent = GetAncestor( data->hwnd, GA_PARENT );
259 hdc_src = GetDCEx( parent, 0, DCX_CACHE );
260 hdc_dst = GetDCEx( data->hwnd, 0, DCX_CACHE | DCX_WINDOW );
262 else
264 OffsetRect( &dst_rect, -data->client_rect.left, -data->client_rect.top );
265 /* make src rect relative to the old position of the window */
266 OffsetRect( &src_rect, -old_client_rect->left, -old_client_rect->top );
267 if (dst_rect.left == src_rect.left && dst_rect.top == src_rect.top) return;
268 hdc_src = hdc_dst = GetDCEx( data->hwnd, 0, DCX_CACHE );
271 code = X11DRV_START_EXPOSURES;
272 ExtEscape( hdc_dst, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
274 TRACE( "copying bits for win %p/%lx/%lx %s -> %s\n",
275 data->hwnd, data->whole_window, data->client_window,
276 wine_dbgstr_rect(&src_rect), wine_dbgstr_rect(&dst_rect) );
277 BitBlt( hdc_dst, dst_rect.left, dst_rect.top,
278 dst_rect.right - dst_rect.left, dst_rect.bottom - dst_rect.top,
279 hdc_src, src_rect.left, src_rect.top, SRCCOPY );
281 code = X11DRV_END_EXPOSURES;
282 ExtEscape( hdc_dst, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, sizeof(rgn), (LPSTR)&rgn );
284 ReleaseDC( data->hwnd, hdc_dst );
285 if (hdc_src != hdc_dst) ReleaseDC( parent, hdc_src );
287 if (rgn)
289 if (!data->whole_window)
291 /* map region to client rect since we are using DCX_WINDOW */
292 OffsetRgn( rgn, data->window_rect.left - data->client_rect.left,
293 data->window_rect.top - data->client_rect.top );
294 RedrawWindow( data->hwnd, NULL, rgn,
295 RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ALLCHILDREN );
297 else RedrawWindow( data->hwnd, NULL, rgn, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
298 DeleteObject( rgn );
302 /***********************************************************************
303 * SetWindowPos (X11DRV.@)
305 void X11DRV_SetWindowPos( HWND hwnd, HWND insert_after, UINT swp_flags,
306 const RECT *rectWindow, const RECT *rectClient,
307 const RECT *visible_rect, const RECT *valid_rects )
309 Display *display = thread_display();
310 struct x11drv_win_data *data = X11DRV_get_win_data( hwnd );
311 DWORD new_style = GetWindowLongW( hwnd, GWL_STYLE );
312 RECT old_window_rect, old_whole_rect, old_client_rect;
314 if (!data)
316 /* create the win data if the window is being made visible */
317 if (!(new_style & WS_VISIBLE)) return;
318 if (!(data = X11DRV_create_win_data( hwnd ))) return;
321 /* check if we need to switch the window to managed */
322 if (!data->managed && data->whole_window && is_window_managed( hwnd, swp_flags, rectWindow ))
324 TRACE( "making win %p/%lx managed\n", hwnd, data->whole_window );
325 data->managed = TRUE;
326 SetPropA( hwnd, managed_prop, (HANDLE)1 );
327 if (data->mapped)
329 wine_tsx11_lock();
330 XUnmapWindow( display, data->whole_window );
331 wine_tsx11_unlock();
332 data->mapped = FALSE;
336 old_window_rect = data->window_rect;
337 old_whole_rect = data->whole_rect;
338 old_client_rect = data->client_rect;
339 data->window_rect = *rectWindow;
340 data->whole_rect = *rectWindow;
341 data->client_rect = *rectClient;
342 X11DRV_window_to_X_rect( data, &data->whole_rect );
343 if (memcmp( &visible_rect, &data->whole_rect, sizeof(RECT) ))
345 TRACE( "%p: need to update visible rect %s -> %s\n", hwnd,
346 wine_dbgstr_rect(visible_rect), wine_dbgstr_rect(&data->whole_rect) );
347 SERVER_START_REQ( set_window_visible_rect )
349 req->handle = hwnd;
350 req->flags = swp_flags;
351 req->visible.left = data->whole_rect.left;
352 req->visible.top = data->whole_rect.top;
353 req->visible.right = data->whole_rect.right;
354 req->visible.bottom = data->whole_rect.bottom;
355 wine_server_call( req );
357 SERVER_END_REQ;
360 TRACE( "win %p window %s client %s style %08x\n",
361 hwnd, wine_dbgstr_rect(rectWindow), wine_dbgstr_rect(rectClient), new_style );
363 if (!IsRectEmpty( &valid_rects[0] ))
365 int x_offset = old_whole_rect.left - data->whole_rect.left;
366 int y_offset = old_whole_rect.top - data->whole_rect.top;
368 /* if all that happened is that the whole window moved, copy everything */
369 if (!(swp_flags & SWP_FRAMECHANGED) &&
370 old_whole_rect.right - data->whole_rect.right == x_offset &&
371 old_whole_rect.bottom - data->whole_rect.bottom == y_offset &&
372 old_client_rect.left - data->client_rect.left == x_offset &&
373 old_client_rect.right - data->client_rect.right == x_offset &&
374 old_client_rect.top - data->client_rect.top == y_offset &&
375 old_client_rect.bottom - data->client_rect.bottom == y_offset &&
376 !memcmp( &valid_rects[0], &data->client_rect, sizeof(RECT) ))
378 /* if we have an X window the bits will be moved by the X server */
379 if (!data->whole_window)
380 move_window_bits( data, &old_whole_rect, &data->whole_rect, &old_client_rect );
382 else
383 move_window_bits( data, &valid_rects[1], &valid_rects[0], &old_client_rect );
386 X11DRV_sync_client_position( display, data, swp_flags, &old_client_rect, &old_whole_rect );
388 if (!data->whole_window || data->lock_changes) return; /* nothing more to do */
390 if (data->mapped && (!(new_style & WS_VISIBLE) || !X11DRV_is_window_rect_mapped( rectWindow )))
392 TRACE( "unmapping win %p\n", hwnd );
393 wine_tsx11_lock();
394 XUnmapWindow( display, data->whole_window );
395 wine_tsx11_unlock();
396 data->mapped = FALSE;
399 X11DRV_sync_window_position( display, data, swp_flags, &old_client_rect, &old_whole_rect );
401 if ((new_style & WS_VISIBLE) && !(new_style & WS_MINIMIZE) &&
402 X11DRV_is_window_rect_mapped( rectWindow ))
404 BOOL was_mapped = data->mapped;
406 if (!data->mapped || (swp_flags & SWP_FRAMECHANGED))
407 X11DRV_set_wm_hints( display, data );
409 if (!data->mapped)
411 TRACE( "mapping win %p\n", hwnd );
412 X11DRV_sync_window_style( display, data );
413 wine_tsx11_lock();
414 XMapWindow( display, data->whole_window );
415 XFlush( display );
416 wine_tsx11_unlock();
417 data->mapped = TRUE;
419 update_wm_states( display, data, !was_mapped );
424 /***********************************************************************
425 * WINPOS_FindIconPos
427 * Find a suitable place for an iconic window.
429 static POINT WINPOS_FindIconPos( HWND hwnd, POINT pt )
431 RECT rect, rectParent;
432 HWND parent, child;
433 HRGN hrgn, tmp;
434 int xspacing, yspacing;
436 parent = GetAncestor( hwnd, GA_PARENT );
437 GetClientRect( parent, &rectParent );
438 if ((pt.x >= rectParent.left) && (pt.x + GetSystemMetrics(SM_CXICON) < rectParent.right) &&
439 (pt.y >= rectParent.top) && (pt.y + GetSystemMetrics(SM_CYICON) < rectParent.bottom))
440 return pt; /* The icon already has a suitable position */
442 xspacing = GetSystemMetrics(SM_CXICONSPACING);
443 yspacing = GetSystemMetrics(SM_CYICONSPACING);
445 /* Check if another icon already occupies this spot */
446 /* FIXME: this is completely inefficient */
448 hrgn = CreateRectRgn( 0, 0, 0, 0 );
449 tmp = CreateRectRgn( 0, 0, 0, 0 );
450 for (child = GetWindow( parent, GW_HWNDFIRST ); child; child = GetWindow( child, GW_HWNDNEXT ))
452 WND *childPtr;
453 if (child == hwnd) continue;
454 if ((GetWindowLongW( child, GWL_STYLE ) & (WS_VISIBLE|WS_MINIMIZE)) != (WS_VISIBLE|WS_MINIMIZE))
455 continue;
456 if (!(childPtr = WIN_GetPtr( child )) || childPtr == WND_OTHER_PROCESS)
457 continue;
458 SetRectRgn( tmp, childPtr->rectWindow.left, childPtr->rectWindow.top,
459 childPtr->rectWindow.right, childPtr->rectWindow.bottom );
460 CombineRgn( hrgn, hrgn, tmp, RGN_OR );
461 WIN_ReleasePtr( childPtr );
463 DeleteObject( tmp );
465 for (rect.bottom = rectParent.bottom; rect.bottom >= yspacing; rect.bottom -= yspacing)
467 for (rect.left = rectParent.left; rect.left <= rectParent.right - xspacing; rect.left += xspacing)
469 rect.right = rect.left + xspacing;
470 rect.top = rect.bottom - yspacing;
471 if (!RectInRegion( hrgn, &rect ))
473 /* No window was found, so it's OK for us */
474 pt.x = rect.left + (xspacing - GetSystemMetrics(SM_CXICON)) / 2;
475 pt.y = rect.top + (yspacing - GetSystemMetrics(SM_CYICON)) / 2;
476 DeleteObject( hrgn );
477 return pt;
481 DeleteObject( hrgn );
482 pt.x = pt.y = 0;
483 return pt;
487 /***********************************************************************
488 * WINPOS_MinMaximize
490 UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect )
492 WND *wndPtr;
493 UINT swpFlags = 0;
494 POINT size;
495 LONG old_style;
496 WINDOWPLACEMENT wpl;
498 TRACE("%p %u\n", hwnd, cmd );
500 wpl.length = sizeof(wpl);
501 GetWindowPlacement( hwnd, &wpl );
503 if (HOOK_CallHooks( WH_CBT, HCBT_MINMAX, (WPARAM)hwnd, cmd, TRUE ))
504 return SWP_NOSIZE | SWP_NOMOVE;
506 if (IsIconic( hwnd ))
508 switch (cmd)
510 case SW_SHOWMINNOACTIVE:
511 case SW_SHOWMINIMIZED:
512 case SW_FORCEMINIMIZE:
513 case SW_MINIMIZE:
514 return SWP_NOSIZE | SWP_NOMOVE;
516 if (!SendMessageW( hwnd, WM_QUERYOPEN, 0, 0 )) return SWP_NOSIZE | SWP_NOMOVE;
517 swpFlags |= SWP_NOCOPYBITS;
520 switch( cmd )
522 case SW_SHOWMINNOACTIVE:
523 case SW_SHOWMINIMIZED:
524 case SW_FORCEMINIMIZE:
525 case SW_MINIMIZE:
526 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
527 if( wndPtr->dwStyle & WS_MAXIMIZE) wndPtr->flags |= WIN_RESTORE_MAX;
528 else wndPtr->flags &= ~WIN_RESTORE_MAX;
529 WIN_ReleasePtr( wndPtr );
531 old_style = WIN_SetStyle( hwnd, WS_MINIMIZE, WS_MAXIMIZE );
533 X11DRV_set_iconic_state( hwnd );
535 wpl.ptMinPosition = WINPOS_FindIconPos( hwnd, wpl.ptMinPosition );
537 if (!(old_style & WS_MINIMIZE)) swpFlags |= SWP_STATECHANGED;
538 SetRect( rect, wpl.ptMinPosition.x, wpl.ptMinPosition.y,
539 GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON) );
540 swpFlags |= SWP_NOCOPYBITS;
541 break;
543 case SW_MAXIMIZE:
544 old_style = GetWindowLongW( hwnd, GWL_STYLE );
545 if ((old_style & WS_MAXIMIZE) && (old_style & WS_VISIBLE)) return SWP_NOSIZE | SWP_NOMOVE;
547 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL );
549 old_style = WIN_SetStyle( hwnd, WS_MAXIMIZE, WS_MINIMIZE );
550 if (old_style & WS_MINIMIZE)
552 WINPOS_ShowIconTitle( hwnd, FALSE );
553 X11DRV_set_iconic_state( hwnd );
555 if (!(old_style & WS_MAXIMIZE)) swpFlags |= SWP_STATECHANGED;
556 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y );
557 break;
559 case SW_SHOWNOACTIVATE:
560 case SW_SHOWNORMAL:
561 case SW_RESTORE:
562 old_style = WIN_SetStyle( hwnd, 0, WS_MINIMIZE | WS_MAXIMIZE );
563 if (old_style & WS_MINIMIZE)
565 BOOL restore_max;
567 WINPOS_ShowIconTitle( hwnd, FALSE );
568 X11DRV_set_iconic_state( hwnd );
570 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
571 restore_max = (wndPtr->flags & WIN_RESTORE_MAX) != 0;
572 WIN_ReleasePtr( wndPtr );
573 if (restore_max)
575 /* Restore to maximized position */
576 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL);
577 WIN_SetStyle( hwnd, WS_MAXIMIZE, 0 );
578 swpFlags |= SWP_STATECHANGED;
579 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y );
580 break;
583 else if (!(old_style & WS_MAXIMIZE)) break;
585 swpFlags |= SWP_STATECHANGED;
587 /* Restore to normal position */
589 *rect = wpl.rcNormalPosition;
590 rect->right -= rect->left;
591 rect->bottom -= rect->top;
593 break;
596 return swpFlags;
600 /***********************************************************************
601 * ShowWindow (X11DRV.@)
603 BOOL X11DRV_ShowWindow( HWND hwnd, INT cmd )
605 WND *wndPtr;
606 HWND parent;
607 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
608 BOOL wasVisible = (style & WS_VISIBLE) != 0;
609 BOOL showFlag = TRUE;
610 RECT newPos = {0, 0, 0, 0};
611 UINT swp = 0;
613 TRACE("hwnd=%p, cmd=%d, wasVisible %d\n", hwnd, cmd, wasVisible);
615 switch(cmd)
617 case SW_HIDE:
618 if (!wasVisible) return FALSE;
619 showFlag = FALSE;
620 swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE;
621 if (hwnd != GetActiveWindow())
622 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
623 break;
625 case SW_SHOWMINNOACTIVE:
626 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
627 /* fall through */
628 case SW_MINIMIZE:
629 case SW_FORCEMINIMIZE: /* FIXME: Does not work if thread is hung. */
630 if (style & WS_CHILD) swp |= SWP_NOACTIVATE | SWP_NOZORDER;
631 /* fall through */
632 case SW_SHOWMINIMIZED:
633 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
634 swp |= WINPOS_MinMaximize( hwnd, cmd, &newPos );
635 if ((style & WS_MINIMIZE) && wasVisible) return TRUE;
636 break;
638 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
639 if (!wasVisible) swp |= SWP_SHOWWINDOW;
640 swp |= SWP_FRAMECHANGED;
641 swp |= WINPOS_MinMaximize( hwnd, SW_MAXIMIZE, &newPos );
642 if ((style & WS_MAXIMIZE) && wasVisible) return TRUE;
643 break;
645 case SW_SHOWNA:
646 swp |= SWP_NOACTIVATE | SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
647 if (style & WS_CHILD) swp |= SWP_NOZORDER;
648 break;
649 case SW_SHOW:
650 if (wasVisible) return TRUE;
651 swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
652 if (style & WS_CHILD) swp |= SWP_NOACTIVATE | SWP_NOZORDER;
653 break;
655 case SW_SHOWNOACTIVATE:
656 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
657 /* fall through */
658 case SW_RESTORE:
659 /* fall through */
660 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
661 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
662 if (!wasVisible) swp |= SWP_SHOWWINDOW;
663 if (style & (WS_MINIMIZE | WS_MAXIMIZE))
665 swp |= SWP_FRAMECHANGED;
666 swp |= WINPOS_MinMaximize( hwnd, cmd, &newPos );
668 else
670 if (wasVisible) return TRUE;
671 swp |= SWP_NOSIZE | SWP_NOMOVE;
673 if (style & WS_CHILD && !(swp & SWP_STATECHANGED)) swp |= SWP_NOACTIVATE | SWP_NOZORDER;
674 break;
677 if ((showFlag != wasVisible || cmd == SW_SHOWNA) && cmd != SW_SHOWMAXIMIZED && !(swp & SWP_STATECHANGED))
679 SendMessageW( hwnd, WM_SHOWWINDOW, showFlag, 0 );
680 if (!IsWindow( hwnd )) return wasVisible;
683 parent = GetAncestor( hwnd, GA_PARENT );
684 if (parent && !IsWindowVisible( parent ) && !(swp & SWP_STATECHANGED))
686 /* if parent is not visible simply toggle WS_VISIBLE and return */
687 if (showFlag) WIN_SetStyle( hwnd, WS_VISIBLE, 0 );
688 else WIN_SetStyle( hwnd, 0, WS_VISIBLE );
690 else
691 SetWindowPos( hwnd, HWND_TOP, newPos.left, newPos.top,
692 newPos.right, newPos.bottom, LOWORD(swp) );
694 if (cmd == SW_HIDE)
696 HWND hFocus;
698 /* FIXME: This will cause the window to be activated irrespective
699 * of whether it is owned by the same thread. Has to be done
700 * asynchronously.
703 if (hwnd == GetActiveWindow())
704 WINPOS_ActivateOtherWindow(hwnd);
706 /* Revert focus to parent */
707 hFocus = GetFocus();
708 if (hwnd == hFocus || IsChild(hwnd, hFocus))
710 HWND parent = GetAncestor(hwnd, GA_PARENT);
711 if (parent == GetDesktopWindow()) parent = 0;
712 SetFocus(parent);
716 if (IsIconic(hwnd)) WINPOS_ShowIconTitle( hwnd, TRUE );
718 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return wasVisible;
720 if (wndPtr->flags & WIN_NEED_SIZE)
722 /* should happen only in CreateWindowEx() */
723 int wParam = SIZE_RESTORED;
724 RECT client = wndPtr->rectClient;
726 wndPtr->flags &= ~WIN_NEED_SIZE;
727 if (wndPtr->dwStyle & WS_MAXIMIZE) wParam = SIZE_MAXIMIZED;
728 else if (wndPtr->dwStyle & WS_MINIMIZE) wParam = SIZE_MINIMIZED;
729 WIN_ReleasePtr( wndPtr );
731 SendMessageW( hwnd, WM_SIZE, wParam,
732 MAKELONG( client.right - client.left, client.bottom - client.top ));
733 SendMessageW( hwnd, WM_MOVE, 0, MAKELONG( client.left, client.top ));
735 else WIN_ReleasePtr( wndPtr );
737 /* if previous state was minimized Windows sets focus to the window */
738 if (style & WS_MINIMIZE) SetFocus( hwnd );
740 return wasVisible;
744 /**********************************************************************
745 * X11DRV_MapNotify
747 void X11DRV_MapNotify( HWND hwnd, XEvent *event )
749 struct x11drv_win_data *data;
750 HWND hwndFocus = GetFocus();
751 WND *win;
753 if (!(data = X11DRV_get_win_data( hwnd ))) return;
755 if (!(win = WIN_GetPtr( hwnd ))) return;
757 if (data->managed && (win->dwStyle & WS_VISIBLE) && (win->dwStyle & WS_MINIMIZE))
759 int x, y;
760 unsigned int width, height, border, depth;
761 Window root, top;
762 RECT rect;
763 LONG style = WS_VISIBLE;
765 /* FIXME: hack */
766 wine_tsx11_lock();
767 XGetGeometry( event->xmap.display, data->whole_window, &root, &x, &y, &width, &height,
768 &border, &depth );
769 XTranslateCoordinates( event->xmap.display, data->whole_window, root, 0, 0, &x, &y, &top );
770 wine_tsx11_unlock();
771 rect.left = x;
772 rect.top = y;
773 rect.right = x + width;
774 rect.bottom = y + height;
775 OffsetRect( &rect, virtual_screen_rect.left, virtual_screen_rect.top );
776 X11DRV_X_to_window_rect( data, &rect );
778 if (win->flags & WIN_RESTORE_MAX) style |= WS_MAXIMIZE;
779 WIN_SetStyle( hwnd, style, WS_MINIMIZE );
780 WIN_ReleasePtr( win );
782 SendMessageW( hwnd, WM_SHOWWINDOW, SW_RESTORE, 0 );
783 data->lock_changes++;
784 SetWindowPos( hwnd, 0, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
785 SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED | SWP_STATECHANGED );
786 data->lock_changes--;
788 else WIN_ReleasePtr( win );
789 if (hwndFocus && IsChild( hwnd, hwndFocus )) X11DRV_SetFocus(hwndFocus); /* FIXME */
793 /**********************************************************************
794 * X11DRV_UnmapNotify
796 void X11DRV_UnmapNotify( HWND hwnd, XEvent *event )
798 struct x11drv_win_data *data;
799 WND *win;
801 if (!(data = X11DRV_get_win_data( hwnd ))) return;
803 if (!(win = WIN_GetPtr( hwnd ))) return;
805 if ((win->dwStyle & WS_VISIBLE) && data->managed &&
806 X11DRV_is_window_rect_mapped( &win->rectWindow ))
808 if (win->dwStyle & WS_MAXIMIZE)
809 win->flags |= WIN_RESTORE_MAX;
810 else if (!(win->dwStyle & WS_MINIMIZE))
811 win->flags &= ~WIN_RESTORE_MAX;
813 WIN_SetStyle( hwnd, WS_MINIMIZE, WS_MAXIMIZE );
814 WIN_ReleasePtr( win );
816 EndMenu();
817 SendMessageW( hwnd, WM_SHOWWINDOW, SW_MINIMIZE, 0 );
818 data->lock_changes++;
819 SetWindowPos( hwnd, 0, 0, 0, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON),
820 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_STATECHANGED );
821 data->lock_changes--;
823 else WIN_ReleasePtr( win );
826 struct desktop_resize_data
828 RECT old_screen_rect;
829 RECT old_virtual_rect;
832 static BOOL CALLBACK update_windows_on_desktop_resize( HWND hwnd, LPARAM lparam )
834 struct x11drv_win_data *data;
835 Display *display = thread_display();
836 struct desktop_resize_data *resize_data = (struct desktop_resize_data *)lparam;
837 int mask = 0;
839 if (!(data = X11DRV_get_win_data( hwnd ))) return TRUE;
841 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE)
843 /* update the full screen state */
844 update_wm_states( display, data, FALSE );
847 if (resize_data->old_virtual_rect.left != virtual_screen_rect.left) mask |= CWX;
848 if (resize_data->old_virtual_rect.top != virtual_screen_rect.top) mask |= CWY;
849 if (mask && data->whole_window)
851 XWindowChanges changes;
853 wine_tsx11_lock();
854 changes.x = data->whole_rect.left - virtual_screen_rect.left;
855 changes.y = data->whole_rect.top - virtual_screen_rect.top;
856 XReconfigureWMWindow( display, data->whole_window,
857 DefaultScreen(display), mask, &changes );
858 wine_tsx11_unlock();
860 return TRUE;
864 /***********************************************************************
865 * X11DRV_resize_desktop
867 void X11DRV_resize_desktop( unsigned int width, unsigned int height )
869 HWND hwnd = GetDesktopWindow();
870 struct desktop_resize_data resize_data;
872 SetRect( &resize_data.old_screen_rect, 0, 0, screen_width, screen_height );
873 resize_data.old_virtual_rect = virtual_screen_rect;
875 xinerama_init( width, height );
877 if (GetWindowThreadProcessId( hwnd, NULL ) != GetCurrentThreadId())
879 SendMessageW( hwnd, WM_X11DRV_RESIZE_DESKTOP, 0, MAKELPARAM( width, height ) );
881 else
883 TRACE( "desktop %p change to (%dx%d)\n", hwnd, width, height );
884 SetWindowPos( hwnd, 0, virtual_screen_rect.left, virtual_screen_rect.top,
885 virtual_screen_rect.right - virtual_screen_rect.left,
886 virtual_screen_rect.bottom - virtual_screen_rect.top,
887 SWP_NOZORDER | SWP_NOACTIVATE | SWP_DEFERERASE );
888 SendMessageTimeoutW( HWND_BROADCAST, WM_DISPLAYCHANGE, screen_bpp,
889 MAKELPARAM( width, height ), SMTO_ABORTIFHUNG, 2000, NULL );
892 EnumWindows( update_windows_on_desktop_resize, (LPARAM)&resize_data );
896 /***********************************************************************
897 * X11DRV_ConfigureNotify
899 void X11DRV_ConfigureNotify( HWND hwnd, XEvent *xev )
901 XConfigureEvent *event = &xev->xconfigure;
902 struct x11drv_win_data *data;
903 RECT rect;
904 UINT flags;
905 int cx, cy, x = event->x, y = event->y;
907 if (!hwnd) return;
908 if (!(data = X11DRV_get_win_data( hwnd ))) return;
910 /* Get geometry */
912 if (!event->send_event) /* normal event, need to map coordinates to the root */
914 Window child;
915 wine_tsx11_lock();
916 XTranslateCoordinates( event->display, data->whole_window, root_window,
917 0, 0, &x, &y, &child );
918 wine_tsx11_unlock();
920 rect.left = x;
921 rect.top = y;
922 rect.right = x + event->width;
923 rect.bottom = y + event->height;
924 OffsetRect( &rect, virtual_screen_rect.left, virtual_screen_rect.top );
925 TRACE( "win %p new X rect %d,%d,%dx%d (event %d,%d,%dx%d)\n",
926 hwnd, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
927 event->x, event->y, event->width, event->height );
928 X11DRV_X_to_window_rect( data, &rect );
930 x = rect.left;
931 y = rect.top;
932 cx = rect.right - rect.left;
933 cy = rect.bottom - rect.top;
934 flags = SWP_NOACTIVATE | SWP_NOZORDER;
936 /* Compare what has changed */
938 GetWindowRect( hwnd, &rect );
939 if (rect.left == x && rect.top == y) flags |= SWP_NOMOVE;
940 else
941 TRACE( "%p moving from (%d,%d) to (%d,%d)\n",
942 hwnd, rect.left, rect.top, x, y );
944 if ((rect.right - rect.left == cx && rect.bottom - rect.top == cy) ||
945 IsIconic(hwnd) ||
946 (IsRectEmpty( &rect ) && event->width == 1 && event->height == 1))
948 if (flags & SWP_NOMOVE) return; /* if nothing changed, don't do anything */
949 flags |= SWP_NOSIZE;
951 else
952 TRACE( "%p resizing from (%dx%d) to (%dx%d)\n",
953 hwnd, rect.right - rect.left, rect.bottom - rect.top, cx, cy );
955 data->lock_changes++;
956 SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
957 data->lock_changes--;
961 /***********************************************************************
962 * draw_moving_frame
964 * Draw the frame used when moving or resizing window.
966 * FIXME: This causes problems in Win95 mode. (why?)
968 static void draw_moving_frame( HDC hdc, RECT *rect, BOOL thickframe )
970 if (thickframe)
972 const int width = GetSystemMetrics(SM_CXFRAME);
973 const int height = GetSystemMetrics(SM_CYFRAME);
975 HBRUSH hbrush = SelectObject( hdc, GetStockObject( GRAY_BRUSH ) );
976 PatBlt( hdc, rect->left, rect->top,
977 rect->right - rect->left - width, height, PATINVERT );
978 PatBlt( hdc, rect->left, rect->top + height, width,
979 rect->bottom - rect->top - height, PATINVERT );
980 PatBlt( hdc, rect->left + width, rect->bottom - 1,
981 rect->right - rect->left - width, -height, PATINVERT );
982 PatBlt( hdc, rect->right - 1, rect->top, -width,
983 rect->bottom - rect->top - height, PATINVERT );
984 SelectObject( hdc, hbrush );
986 else DrawFocusRect( hdc, rect );
990 /***********************************************************************
991 * start_size_move
993 * Initialization of a move or resize, when initiated from a menu choice.
994 * Return hit test code for caption or sizing border.
996 static LONG start_size_move( HWND hwnd, WPARAM wParam, POINT *capturePoint, LONG style )
998 LONG hittest = 0;
999 POINT pt;
1000 MSG msg;
1001 RECT rectWindow;
1003 GetWindowRect( hwnd, &rectWindow );
1005 if ((wParam & 0xfff0) == SC_MOVE)
1007 /* Move pointer at the center of the caption */
1008 RECT rect = rectWindow;
1009 /* Note: to be exactly centered we should take the different types
1010 * of border into account, but it shouldn't make more than a few pixels
1011 * of difference so let's not bother with that */
1012 rect.top += GetSystemMetrics(SM_CYBORDER);
1013 if (style & WS_SYSMENU)
1014 rect.left += GetSystemMetrics(SM_CXSIZE) + 1;
1015 if (style & WS_MINIMIZEBOX)
1016 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1017 if (style & WS_MAXIMIZEBOX)
1018 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1019 pt.x = (rect.right + rect.left) / 2;
1020 pt.y = rect.top + GetSystemMetrics(SM_CYSIZE)/2;
1021 hittest = HTCAPTION;
1022 *capturePoint = pt;
1024 else /* SC_SIZE */
1026 pt.x = pt.y = 0;
1027 while(!hittest)
1029 GetMessageW( &msg, 0, WM_KEYFIRST, WM_MOUSELAST );
1030 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
1032 switch(msg.message)
1034 case WM_MOUSEMOVE:
1035 pt = msg.pt;
1036 hittest = SendMessageW( hwnd, WM_NCHITTEST, 0, MAKELONG( pt.x, pt.y ) );
1037 if ((hittest < HTLEFT) || (hittest > HTBOTTOMRIGHT)) hittest = 0;
1038 break;
1040 case WM_LBUTTONUP:
1041 return 0;
1043 case WM_KEYDOWN:
1044 switch(msg.wParam)
1046 case VK_UP:
1047 hittest = HTTOP;
1048 pt.x =(rectWindow.left+rectWindow.right)/2;
1049 pt.y = rectWindow.top + GetSystemMetrics(SM_CYFRAME) / 2;
1050 break;
1051 case VK_DOWN:
1052 hittest = HTBOTTOM;
1053 pt.x =(rectWindow.left+rectWindow.right)/2;
1054 pt.y = rectWindow.bottom - GetSystemMetrics(SM_CYFRAME) / 2;
1055 break;
1056 case VK_LEFT:
1057 hittest = HTLEFT;
1058 pt.x = rectWindow.left + GetSystemMetrics(SM_CXFRAME) / 2;
1059 pt.y =(rectWindow.top+rectWindow.bottom)/2;
1060 break;
1061 case VK_RIGHT:
1062 hittest = HTRIGHT;
1063 pt.x = rectWindow.right - GetSystemMetrics(SM_CXFRAME) / 2;
1064 pt.y =(rectWindow.top+rectWindow.bottom)/2;
1065 break;
1066 case VK_RETURN:
1067 case VK_ESCAPE: return 0;
1071 *capturePoint = pt;
1073 SetCursorPos( pt.x, pt.y );
1074 SendMessageW( hwnd, WM_SETCURSOR, (WPARAM)hwnd, MAKELONG( hittest, WM_MOUSEMOVE ));
1075 return hittest;
1079 /***********************************************************************
1080 * set_movesize_capture
1082 static void set_movesize_capture( HWND hwnd )
1084 HWND previous = 0;
1086 SERVER_START_REQ( set_capture_window )
1088 req->handle = hwnd;
1089 req->flags = CAPTURE_MOVESIZE;
1090 if (!wine_server_call_err( req ))
1092 previous = reply->previous;
1093 hwnd = reply->full_handle;
1096 SERVER_END_REQ;
1097 if (previous && previous != hwnd)
1098 SendMessageW( previous, WM_CAPTURECHANGED, 0, (LPARAM)hwnd );
1101 /***********************************************************************
1102 * X11DRV_WMMoveResizeWindow
1104 * Tells the window manager to initiate a move or resize operation.
1106 * SEE
1107 * http://freedesktop.org/Standards/wm-spec/1.3/ar01s04.html
1108 * or search for "_NET_WM_MOVERESIZE"
1110 static BOOL X11DRV_WMMoveResizeWindow( HWND hwnd, int x, int y, WPARAM wparam )
1112 WPARAM syscommand = wparam & 0xfff0;
1113 WPARAM hittest = wparam & 0x0f;
1114 int dir;
1115 XEvent xev;
1116 Display *display = thread_display();
1118 if (syscommand == SC_MOVE)
1120 if (!hittest) dir = _NET_WM_MOVERESIZE_MOVE_KEYBOARD;
1121 else dir = _NET_WM_MOVERESIZE_MOVE;
1123 else
1125 /* windows without WS_THICKFRAME are not resizable through the window manager */
1126 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_THICKFRAME)) return FALSE;
1128 switch (hittest)
1130 case WMSZ_LEFT: dir = _NET_WM_MOVERESIZE_SIZE_LEFT; break;
1131 case WMSZ_RIGHT: dir = _NET_WM_MOVERESIZE_SIZE_RIGHT; break;
1132 case WMSZ_TOP: dir = _NET_WM_MOVERESIZE_SIZE_TOP; break;
1133 case WMSZ_TOPLEFT: dir = _NET_WM_MOVERESIZE_SIZE_TOPLEFT; break;
1134 case WMSZ_TOPRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT; break;
1135 case WMSZ_BOTTOM: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOM; break;
1136 case WMSZ_BOTTOMLEFT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT; break;
1137 case WMSZ_BOTTOMRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT; break;
1138 default: dir = _NET_WM_MOVERESIZE_SIZE_KEYBOARD; break;
1142 TRACE("hwnd %p, x %d, y %d, dir %d\n", hwnd, x, y, dir);
1144 xev.xclient.type = ClientMessage;
1145 xev.xclient.window = X11DRV_get_whole_window(hwnd);
1146 xev.xclient.message_type = x11drv_atom(_NET_WM_MOVERESIZE);
1147 xev.xclient.serial = 0;
1148 xev.xclient.display = display;
1149 xev.xclient.send_event = True;
1150 xev.xclient.format = 32;
1151 xev.xclient.data.l[0] = x; /* x coord */
1152 xev.xclient.data.l[1] = y; /* y coord */
1153 xev.xclient.data.l[2] = dir; /* direction */
1154 xev.xclient.data.l[3] = 1; /* button */
1155 xev.xclient.data.l[4] = 0; /* unused */
1157 /* need to ungrab the pointer that may have been automatically grabbed
1158 * with a ButtonPress event */
1159 wine_tsx11_lock();
1160 XUngrabPointer( display, CurrentTime );
1161 XSendEvent(display, root_window, False, SubstructureNotifyMask, &xev);
1162 wine_tsx11_unlock();
1163 return TRUE;
1166 /***********************************************************************
1167 * SysCommandSizeMove (X11DRV.@)
1169 * Perform SC_MOVE and SC_SIZE commands.
1171 void X11DRV_SysCommandSizeMove( HWND hwnd, WPARAM wParam )
1173 MSG msg;
1174 RECT sizingRect, mouseRect, origRect;
1175 HDC hdc;
1176 HWND parent;
1177 LONG hittest = (LONG)(wParam & 0x0f);
1178 WPARAM syscommand = wParam & 0xfff0;
1179 HCURSOR hDragCursor = 0, hOldCursor = 0;
1180 POINT minTrack, maxTrack;
1181 POINT capturePoint, pt;
1182 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
1183 BOOL thickframe = HAS_THICKFRAME( style );
1184 BOOL iconic = style & WS_MINIMIZE;
1185 BOOL moved = FALSE;
1186 DWORD dwPoint = GetMessagePos ();
1187 BOOL DragFullWindows = TRUE;
1188 Window parent_win, grab_win;
1189 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1190 struct x11drv_win_data *data;
1192 pt.x = (short)LOWORD(dwPoint);
1193 pt.y = (short)HIWORD(dwPoint);
1194 capturePoint = pt;
1196 if (IsZoomed(hwnd) || !IsWindowVisible(hwnd)) return;
1198 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1200 TRACE("hwnd %p (%smanaged), command %04lx, hittest %d, pos %d,%d\n",
1201 hwnd, data->managed ? "" : "NOT ", syscommand, hittest, pt.x, pt.y);
1203 /* if we are managed then we let the WM do all the work */
1204 if (data->managed && X11DRV_WMMoveResizeWindow( hwnd, pt.x, pt.y, wParam )) return;
1206 if (syscommand == SC_MOVE)
1208 if (!hittest) hittest = start_size_move( hwnd, wParam, &capturePoint, style );
1209 if (!hittest) return;
1211 else /* SC_SIZE */
1213 if ( hittest && (syscommand != SC_MOUSEMENU) )
1214 hittest += (HTLEFT - WMSZ_LEFT);
1215 else
1217 set_movesize_capture( hwnd );
1218 hittest = start_size_move( hwnd, wParam, &capturePoint, style );
1219 if (!hittest)
1221 set_movesize_capture(0);
1222 return;
1227 /* Get min/max info */
1229 WINPOS_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack );
1230 GetWindowRect( hwnd, &sizingRect );
1231 if (style & WS_CHILD)
1233 parent = GetParent(hwnd);
1234 /* make sizing rect relative to parent */
1235 MapWindowPoints( 0, parent, (POINT*)&sizingRect, 2 );
1236 GetClientRect( parent, &mouseRect );
1238 else
1240 parent = 0;
1241 mouseRect = virtual_screen_rect;
1243 origRect = sizingRect;
1245 if (ON_LEFT_BORDER(hittest))
1247 mouseRect.left = max( mouseRect.left, sizingRect.right-maxTrack.x );
1248 mouseRect.right = min( mouseRect.right, sizingRect.right-minTrack.x );
1250 else if (ON_RIGHT_BORDER(hittest))
1252 mouseRect.left = max( mouseRect.left, sizingRect.left+minTrack.x );
1253 mouseRect.right = min( mouseRect.right, sizingRect.left+maxTrack.x );
1255 if (ON_TOP_BORDER(hittest))
1257 mouseRect.top = max( mouseRect.top, sizingRect.bottom-maxTrack.y );
1258 mouseRect.bottom = min( mouseRect.bottom,sizingRect.bottom-minTrack.y);
1260 else if (ON_BOTTOM_BORDER(hittest))
1262 mouseRect.top = max( mouseRect.top, sizingRect.top+minTrack.y );
1263 mouseRect.bottom = min( mouseRect.bottom, sizingRect.top+maxTrack.y );
1265 if (parent) MapWindowPoints( parent, 0, (LPPOINT)&mouseRect, 2 );
1267 /* Retrieve a default cache DC (without using the window style) */
1268 hdc = GetDCEx( parent, 0, DCX_CACHE );
1270 if( iconic ) /* create a cursor for dragging */
1272 hDragCursor = (HCURSOR)GetClassLongPtrW( hwnd, GCLP_HICON);
1273 if( !hDragCursor ) hDragCursor = (HCURSOR)SendMessageW( hwnd, WM_QUERYDRAGICON, 0, 0L);
1274 if( !hDragCursor ) iconic = FALSE;
1277 /* repaint the window before moving it around */
1278 RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN );
1280 SendMessageW( hwnd, WM_ENTERSIZEMOVE, 0, 0 );
1281 set_movesize_capture( hwnd );
1283 /* we only allow disabling the full window drag for child windows, or in desktop mode */
1284 /* otherwise we'd need to grab the server and we want to avoid that */
1285 if (parent || (root_window != DefaultRootWindow(gdi_display)))
1286 SystemParametersInfoA(SPI_GETDRAGFULLWINDOWS, 0, &DragFullWindows, 0);
1288 grab_win = X11DRV_get_client_window( GetAncestor(hwnd,GA_ROOT) );
1289 parent_win = parent ? X11DRV_get_client_window( GetAncestor(parent,GA_ROOT) ) : root_window;
1291 wine_tsx11_lock();
1292 XGrabPointer( thread_data->display, grab_win, False,
1293 PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
1294 GrabModeAsync, GrabModeAsync, parent_win, None, CurrentTime );
1295 wine_tsx11_unlock();
1296 thread_data->grab_window = grab_win;
1298 while(1)
1300 int dx = 0, dy = 0;
1302 if (!GetMessageW( &msg, 0, 0, 0 )) break;
1303 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
1305 /* Exit on button-up, Return, or Esc */
1306 if ((msg.message == WM_LBUTTONUP) ||
1307 ((msg.message == WM_KEYDOWN) &&
1308 ((msg.wParam == VK_RETURN) || (msg.wParam == VK_ESCAPE)))) break;
1310 if ((msg.message != WM_KEYDOWN) && (msg.message != WM_MOUSEMOVE))
1312 TranslateMessage( &msg );
1313 DispatchMessageW( &msg );
1314 continue; /* We are not interested in other messages */
1317 pt = msg.pt;
1319 if (msg.message == WM_KEYDOWN) switch(msg.wParam)
1321 case VK_UP: pt.y -= 8; break;
1322 case VK_DOWN: pt.y += 8; break;
1323 case VK_LEFT: pt.x -= 8; break;
1324 case VK_RIGHT: pt.x += 8; break;
1327 pt.x = max( pt.x, mouseRect.left );
1328 pt.x = min( pt.x, mouseRect.right );
1329 pt.y = max( pt.y, mouseRect.top );
1330 pt.y = min( pt.y, mouseRect.bottom );
1332 dx = pt.x - capturePoint.x;
1333 dy = pt.y - capturePoint.y;
1335 if (dx || dy)
1337 if( !moved )
1339 moved = TRUE;
1341 if( iconic ) /* ok, no system popup tracking */
1343 hOldCursor = SetCursor(hDragCursor);
1344 ShowCursor( TRUE );
1345 WINPOS_ShowIconTitle( hwnd, FALSE );
1347 else if(!DragFullWindows)
1348 draw_moving_frame( hdc, &sizingRect, thickframe );
1351 if (msg.message == WM_KEYDOWN) SetCursorPos( pt.x, pt.y );
1352 else
1354 RECT newRect = sizingRect;
1355 WPARAM wpSizingHit = 0;
1357 if (hittest == HTCAPTION) OffsetRect( &newRect, dx, dy );
1358 if (ON_LEFT_BORDER(hittest)) newRect.left += dx;
1359 else if (ON_RIGHT_BORDER(hittest)) newRect.right += dx;
1360 if (ON_TOP_BORDER(hittest)) newRect.top += dy;
1361 else if (ON_BOTTOM_BORDER(hittest)) newRect.bottom += dy;
1362 if(!iconic && !DragFullWindows) draw_moving_frame( hdc, &sizingRect, thickframe );
1363 capturePoint = pt;
1365 /* determine the hit location */
1366 if (hittest >= HTLEFT && hittest <= HTBOTTOMRIGHT)
1367 wpSizingHit = WMSZ_LEFT + (hittest - HTLEFT);
1368 SendMessageW( hwnd, WM_SIZING, wpSizingHit, (LPARAM)&newRect );
1370 if (!iconic)
1372 if(!DragFullWindows)
1373 draw_moving_frame( hdc, &newRect, thickframe );
1374 else
1375 SetWindowPos( hwnd, 0, newRect.left, newRect.top,
1376 newRect.right - newRect.left,
1377 newRect.bottom - newRect.top,
1378 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
1380 sizingRect = newRect;
1385 set_movesize_capture(0);
1386 if( iconic )
1388 if( moved ) /* restore cursors, show icon title later on */
1390 ShowCursor( FALSE );
1391 SetCursor( hOldCursor );
1394 else if (moved && !DragFullWindows)
1396 draw_moving_frame( hdc, &sizingRect, thickframe );
1397 /* make sure the moving frame is erased before we move the window */
1398 wine_tsx11_lock();
1399 XFlush( gdi_display );
1400 wine_tsx11_unlock();
1403 ReleaseDC( parent, hdc );
1405 wine_tsx11_lock();
1406 XUngrabPointer( thread_data->display, CurrentTime );
1407 wine_tsx11_unlock();
1408 thread_data->grab_window = None;
1410 if (HOOK_CallHooks( WH_CBT, HCBT_MOVESIZE, (WPARAM)hwnd, (LPARAM)&sizingRect, TRUE ))
1411 moved = FALSE;
1413 SendMessageW( hwnd, WM_EXITSIZEMOVE, 0, 0 );
1414 SendMessageW( hwnd, WM_SETVISIBLE, !IsIconic(hwnd), 0L);
1416 /* window moved or resized */
1417 if (moved)
1419 /* if the moving/resizing isn't canceled call SetWindowPos
1420 * with the new position or the new size of the window
1422 if (!((msg.message == WM_KEYDOWN) && (msg.wParam == VK_ESCAPE)) )
1424 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
1425 if(!DragFullWindows)
1426 SetWindowPos( hwnd, 0, sizingRect.left, sizingRect.top,
1427 sizingRect.right - sizingRect.left,
1428 sizingRect.bottom - sizingRect.top,
1429 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
1431 else
1432 { /* restore previous size/position */
1433 if(DragFullWindows)
1434 SetWindowPos( hwnd, 0, origRect.left, origRect.top,
1435 origRect.right - origRect.left,
1436 origRect.bottom - origRect.top,
1437 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
1441 if (IsIconic(hwnd))
1443 /* Single click brings up the system menu when iconized */
1445 if( !moved )
1447 if(style & WS_SYSMENU )
1448 SendMessageW( hwnd, WM_SYSCOMMAND,
1449 SC_MOUSEMENU + HTSYSMENU, MAKELONG(pt.x,pt.y));
1451 else WINPOS_ShowIconTitle( hwnd, TRUE );