push 583922ece91f6a3e6a32c772f3574cd16e6257fa
[wine/hacks.git] / dlls / winex11.drv / winpos.c
blob71c05f522fdabac190a875f5bfa5ca0c2e033cf6
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 "wine/wingdi16.h"
38 #include "x11drv.h"
39 #include "win.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 /***********************************************************************
85 * X11DRV_Expose
87 void X11DRV_Expose( HWND hwnd, XEvent *xev )
89 XExposeEvent *event = &xev->xexpose;
90 RECT rect;
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;
99 rect.left = event->x;
100 rect.top = event->y;
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 )
114 req->window = hwnd;
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 );
121 SERVER_END_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 );
154 wine_tsx11_lock();
155 XMapWindow( display, data->whole_window );
156 wine_tsx11_unlock();
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)
167 wine_tsx11_lock();
168 data->wm_hints->input = !(new_style & WS_DISABLED);
169 XSetWMHints( display, data->whole_window, data->wm_hints );
170 wine_tsx11_unlock();
176 /***********************************************************************
177 * update_wm_states
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,
184 XATOM__NET_WM_STATE_SKIP_PAGER,
185 XATOM__NET_WM_STATE_SKIP_TASKBAR
188 DWORD i, ex_style, new_state = 0;
189 XEvent xev;
191 if (!data->managed) return;
193 if (data->client_rect.left <= 0 && data->client_rect.right >= screen_width &&
194 data->client_rect.top <= 0 && data->client_rect.bottom >= screen_height)
195 new_state |= (1 << WM_STATE_FULLSCREEN);
197 ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE );
198 if (ex_style & WS_EX_TOOLWINDOW)
199 new_state |= (1 << WM_STATE_SKIP_TASKBAR) | (1 << WM_STATE_SKIP_PAGER);
201 xev.xclient.type = ClientMessage;
202 xev.xclient.window = data->whole_window;
203 xev.xclient.message_type = x11drv_atom(_NET_WM_STATE);
204 xev.xclient.serial = 0;
205 xev.xclient.display = display;
206 xev.xclient.send_event = True;
207 xev.xclient.format = 32;
208 xev.xclient.data.l[2] = 0;
209 xev.xclient.data.l[3] = 1;
211 for (i = 0; i < NB_WM_STATES; i++)
213 if (!((data->wm_state ^ new_state) & (1 << i))) /* unchanged */
215 /* if forced, we only add states, we don't remove them */
216 if (!force || !(new_state & (1 << i))) continue;
219 TRACE( "setting wm state %u for window %p/%lx to %u prev %u\n",
220 i, data->hwnd, data->whole_window,
221 (new_state & (1 << i)) != 0, (data->wm_state & (1 << i)) != 0 );
223 xev.xclient.data.l[0] = (new_state & (1 << i)) ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
224 xev.xclient.data.l[1] = X11DRV_Atoms[state_atoms[i] - FIRST_XATOM];
225 wine_tsx11_lock();
226 XSendEvent( display, root_window, False, SubstructureRedirectMask | SubstructureNotifyMask, &xev );
227 wine_tsx11_unlock();
229 data->wm_state = new_state;
233 /***********************************************************************
234 * SetWindowPos (X11DRV.@)
236 BOOL X11DRV_SetWindowPos( HWND hwnd, HWND insert_after, const RECT *rectWindow,
237 const RECT *rectClient, UINT swp_flags, const RECT *valid_rects )
239 Display *display = thread_display();
240 struct x11drv_win_data *data;
241 RECT new_whole_rect, old_client_rect;
242 WND *win;
243 DWORD old_style, new_style;
244 BOOL ret, make_managed = FALSE;
246 if (!(data = X11DRV_get_win_data( hwnd ))) return FALSE;
248 /* check if we need to switch the window to managed */
249 if (!data->managed && data->whole_window && managed_mode &&
250 root_window == DefaultRootWindow( display ) &&
251 data->whole_window != root_window)
253 if (is_window_managed( hwnd, swp_flags, rectWindow ))
255 TRACE( "making win %p/%lx managed\n", hwnd, data->whole_window );
256 make_managed = TRUE;
257 data->managed = TRUE;
258 SetPropA( hwnd, managed_prop, (HANDLE)1 );
262 new_whole_rect = *rectWindow;
263 X11DRV_window_to_X_rect( data, &new_whole_rect );
265 old_client_rect = data->client_rect;
267 if (!(win = WIN_GetPtr( hwnd ))) return FALSE;
268 if (win == WND_OTHER_PROCESS)
270 if (IsWindow( hwnd )) ERR( "cannot set rectangles of other process window %p\n", hwnd );
271 return FALSE;
273 SERVER_START_REQ( set_window_pos )
275 req->handle = hwnd;
276 req->previous = insert_after;
277 req->flags = swp_flags;
278 req->window.left = rectWindow->left;
279 req->window.top = rectWindow->top;
280 req->window.right = rectWindow->right;
281 req->window.bottom = rectWindow->bottom;
282 req->client.left = rectClient->left;
283 req->client.top = rectClient->top;
284 req->client.right = rectClient->right;
285 req->client.bottom = rectClient->bottom;
286 if (memcmp( rectWindow, &new_whole_rect, sizeof(RECT) ) || !IsRectEmpty( &valid_rects[0] ))
288 wine_server_add_data( req, &new_whole_rect, sizeof(new_whole_rect) );
289 if (!IsRectEmpty( &valid_rects[0] ))
290 wine_server_add_data( req, valid_rects, 2 * sizeof(*valid_rects) );
292 ret = !wine_server_call( req );
293 new_style = reply->new_style;
295 SERVER_END_REQ;
297 if (win == WND_DESKTOP || data->whole_window == DefaultRootWindow(gdi_display))
299 data->whole_rect = data->client_rect = data->window_rect = *rectWindow;
300 if (win != WND_DESKTOP)
302 win->rectWindow = *rectWindow;
303 win->rectClient = *rectClient;
304 win->dwStyle = new_style;
305 WIN_ReleasePtr( win );
307 return ret;
310 if (ret)
312 /* invalidate DCEs */
314 if ((((swp_flags & SWP_AGG_NOPOSCHANGE) != SWP_AGG_NOPOSCHANGE) && (new_style & WS_VISIBLE)) ||
315 (swp_flags & (SWP_HIDEWINDOW | SWP_SHOWWINDOW)))
317 RECT rect;
318 UnionRect( &rect, rectWindow, &win->rectWindow );
319 invalidate_dce( hwnd, &rect );
322 win->rectWindow = *rectWindow;
323 win->rectClient = *rectClient;
324 old_style = win->dwStyle;
325 win->dwStyle = new_style;
326 data->window_rect = *rectWindow;
328 TRACE( "win %p window %s client %s style %08x\n",
329 hwnd, wine_dbgstr_rect(rectWindow), wine_dbgstr_rect(rectClient), new_style );
331 if (make_managed && (old_style & WS_VISIBLE))
333 wine_tsx11_lock();
334 XUnmapWindow( display, data->whole_window );
335 wine_tsx11_unlock();
336 old_style &= ~WS_VISIBLE; /* force it to be mapped again below */
339 if (!IsRectEmpty( &valid_rects[0] ))
341 int x_offset = 0, y_offset = 0;
343 if (data->whole_window)
345 /* the X server will move the bits for us */
346 x_offset = data->whole_rect.left - new_whole_rect.left;
347 y_offset = data->whole_rect.top - new_whole_rect.top;
350 if (x_offset != valid_rects[1].left - valid_rects[0].left ||
351 y_offset != valid_rects[1].top - valid_rects[0].top)
353 /* FIXME: should copy the window bits here */
354 RECT invalid_rect = valid_rects[0];
356 /* invalid_rects are relative to the client area */
357 OffsetRect( &invalid_rect, -rectClient->left, -rectClient->top );
358 RedrawWindow( hwnd, &invalid_rect, NULL, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN );
363 if (data->whole_window && !data->lock_changes)
365 if ((old_style & WS_VISIBLE) && !(new_style & WS_VISIBLE))
367 /* window got hidden, unmap it */
368 TRACE( "unmapping win %p\n", hwnd );
369 wine_tsx11_lock();
370 XUnmapWindow( display, data->whole_window );
371 wine_tsx11_unlock();
373 else if ((new_style & WS_VISIBLE) && !X11DRV_is_window_rect_mapped( rectWindow ))
375 /* resizing to zero size or off screen -> unmap */
376 TRACE( "unmapping zero size or off-screen win %p\n", hwnd );
377 wine_tsx11_lock();
378 XUnmapWindow( display, data->whole_window );
379 wine_tsx11_unlock();
383 X11DRV_sync_window_position( display, data, swp_flags, rectClient, &new_whole_rect );
385 if (data->whole_window && !data->lock_changes)
387 BOOL mapped = FALSE;
389 if ((new_style & WS_VISIBLE) && !(new_style & WS_MINIMIZE) &&
390 X11DRV_is_window_rect_mapped( rectWindow ))
392 if (!(old_style & WS_VISIBLE))
394 /* window got shown, map it */
395 TRACE( "mapping win %p\n", hwnd );
396 mapped = TRUE;
398 else if ((swp_flags & (SWP_NOSIZE | SWP_NOMOVE)) != (SWP_NOSIZE | SWP_NOMOVE))
400 /* resizing from zero size to non-zero -> map */
401 TRACE( "mapping non zero size or off-screen win %p\n", hwnd );
402 mapped = TRUE;
405 if (mapped || (swp_flags & SWP_FRAMECHANGED))
406 X11DRV_set_wm_hints( display, data );
408 if (mapped)
410 X11DRV_sync_window_style( display, data );
411 wine_tsx11_lock();
412 XMapWindow( display, data->whole_window );
413 XFlush( display );
414 wine_tsx11_unlock();
416 update_wm_states( display, data, mapped );
420 WIN_ReleasePtr( win );
421 return ret;
425 /***********************************************************************
426 * WINPOS_FindIconPos
428 * Find a suitable place for an iconic window.
430 static POINT WINPOS_FindIconPos( HWND hwnd, POINT pt )
432 RECT rect, rectParent;
433 HWND parent, child;
434 HRGN hrgn, tmp;
435 int xspacing, yspacing;
437 parent = GetAncestor( hwnd, GA_PARENT );
438 GetClientRect( parent, &rectParent );
439 if ((pt.x >= rectParent.left) && (pt.x + GetSystemMetrics(SM_CXICON) < rectParent.right) &&
440 (pt.y >= rectParent.top) && (pt.y + GetSystemMetrics(SM_CYICON) < rectParent.bottom))
441 return pt; /* The icon already has a suitable position */
443 xspacing = GetSystemMetrics(SM_CXICONSPACING);
444 yspacing = GetSystemMetrics(SM_CYICONSPACING);
446 /* Check if another icon already occupies this spot */
447 /* FIXME: this is completely inefficient */
449 hrgn = CreateRectRgn( 0, 0, 0, 0 );
450 tmp = CreateRectRgn( 0, 0, 0, 0 );
451 for (child = GetWindow( parent, GW_HWNDFIRST ); child; child = GetWindow( child, GW_HWNDNEXT ))
453 WND *childPtr;
454 if (child == hwnd) continue;
455 if ((GetWindowLongW( child, GWL_STYLE ) & (WS_VISIBLE|WS_MINIMIZE)) != (WS_VISIBLE|WS_MINIMIZE))
456 continue;
457 if (!(childPtr = WIN_GetPtr( child )) || childPtr == WND_OTHER_PROCESS)
458 continue;
459 SetRectRgn( tmp, childPtr->rectWindow.left, childPtr->rectWindow.top,
460 childPtr->rectWindow.right, childPtr->rectWindow.bottom );
461 CombineRgn( hrgn, hrgn, tmp, RGN_OR );
462 WIN_ReleasePtr( childPtr );
464 DeleteObject( tmp );
466 for (rect.bottom = rectParent.bottom; rect.bottom >= yspacing; rect.bottom -= yspacing)
468 for (rect.left = rectParent.left; rect.left <= rectParent.right - xspacing; rect.left += xspacing)
470 rect.right = rect.left + xspacing;
471 rect.top = rect.bottom - yspacing;
472 if (!RectInRegion( hrgn, &rect ))
474 /* No window was found, so it's OK for us */
475 pt.x = rect.left + (xspacing - GetSystemMetrics(SM_CXICON)) / 2;
476 pt.y = rect.top + (yspacing - GetSystemMetrics(SM_CYICON)) / 2;
477 DeleteObject( hrgn );
478 return pt;
482 DeleteObject( hrgn );
483 pt.x = pt.y = 0;
484 return pt;
488 /***********************************************************************
489 * WINPOS_MinMaximize
491 UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect )
493 WND *wndPtr;
494 UINT swpFlags = 0;
495 POINT size;
496 LONG old_style;
497 WINDOWPLACEMENT wpl;
499 TRACE("%p %u\n", hwnd, cmd );
501 wpl.length = sizeof(wpl);
502 GetWindowPlacement( hwnd, &wpl );
504 if (HOOK_CallHooks( WH_CBT, HCBT_MINMAX, (WPARAM)hwnd, cmd, TRUE ))
505 return SWP_NOSIZE | SWP_NOMOVE;
507 if (IsIconic( hwnd ))
509 switch (cmd)
511 case SW_SHOWMINNOACTIVE:
512 case SW_SHOWMINIMIZED:
513 case SW_FORCEMINIMIZE:
514 case SW_MINIMIZE:
515 return SWP_NOSIZE | SWP_NOMOVE;
517 if (!SendMessageW( hwnd, WM_QUERYOPEN, 0, 0 )) return SWP_NOSIZE | SWP_NOMOVE;
518 swpFlags |= SWP_NOCOPYBITS;
521 switch( cmd )
523 case SW_SHOWMINNOACTIVE:
524 case SW_SHOWMINIMIZED:
525 case SW_FORCEMINIMIZE:
526 case SW_MINIMIZE:
527 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
528 if( wndPtr->dwStyle & WS_MAXIMIZE) wndPtr->flags |= WIN_RESTORE_MAX;
529 else wndPtr->flags &= ~WIN_RESTORE_MAX;
530 WIN_ReleasePtr( wndPtr );
532 old_style = WIN_SetStyle( hwnd, WS_MINIMIZE, WS_MAXIMIZE );
534 X11DRV_set_iconic_state( hwnd );
536 wpl.ptMinPosition = WINPOS_FindIconPos( hwnd, wpl.ptMinPosition );
538 if (!(old_style & WS_MINIMIZE)) swpFlags |= SWP_STATECHANGED;
539 SetRect( rect, wpl.ptMinPosition.x, wpl.ptMinPosition.y,
540 GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON) );
541 swpFlags |= SWP_NOCOPYBITS;
542 break;
544 case SW_MAXIMIZE:
545 old_style = GetWindowLongW( hwnd, GWL_STYLE );
546 if ((old_style & WS_MAXIMIZE) && (old_style & WS_VISIBLE)) return SWP_NOSIZE | SWP_NOMOVE;
548 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL );
550 old_style = WIN_SetStyle( hwnd, WS_MAXIMIZE, WS_MINIMIZE );
551 if (old_style & WS_MINIMIZE)
553 WINPOS_ShowIconTitle( hwnd, FALSE );
554 X11DRV_set_iconic_state( hwnd );
556 if (!(old_style & WS_MAXIMIZE)) swpFlags |= SWP_STATECHANGED;
557 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y );
558 break;
560 case SW_SHOWNOACTIVATE:
561 case SW_SHOWNORMAL:
562 case SW_RESTORE:
563 old_style = WIN_SetStyle( hwnd, 0, WS_MINIMIZE | WS_MAXIMIZE );
564 if (old_style & WS_MINIMIZE)
566 BOOL restore_max;
568 WINPOS_ShowIconTitle( hwnd, FALSE );
569 X11DRV_set_iconic_state( hwnd );
571 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
572 restore_max = (wndPtr->flags & WIN_RESTORE_MAX) != 0;
573 WIN_ReleasePtr( wndPtr );
574 if (restore_max)
576 /* Restore to maximized position */
577 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL);
578 WIN_SetStyle( hwnd, WS_MAXIMIZE, 0 );
579 swpFlags |= SWP_STATECHANGED;
580 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y );
581 break;
584 else if (!(old_style & WS_MAXIMIZE)) break;
586 swpFlags |= SWP_STATECHANGED;
588 /* Restore to normal position */
590 *rect = wpl.rcNormalPosition;
591 rect->right -= rect->left;
592 rect->bottom -= rect->top;
594 break;
597 return swpFlags;
601 /***********************************************************************
602 * ShowWindow (X11DRV.@)
604 BOOL X11DRV_ShowWindow( HWND hwnd, INT cmd )
606 WND *wndPtr;
607 HWND parent;
608 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
609 BOOL wasVisible = (style & WS_VISIBLE) != 0;
610 BOOL showFlag = TRUE;
611 RECT newPos = {0, 0, 0, 0};
612 UINT swp = 0;
614 TRACE("hwnd=%p, cmd=%d, wasVisible %d\n", hwnd, cmd, wasVisible);
616 switch(cmd)
618 case SW_HIDE:
619 if (!wasVisible) return FALSE;
620 showFlag = FALSE;
621 swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE;
622 if (hwnd != GetActiveWindow())
623 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
624 break;
626 case SW_SHOWMINNOACTIVE:
627 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
628 /* fall through */
629 case SW_MINIMIZE:
630 case SW_FORCEMINIMIZE: /* FIXME: Does not work if thread is hung. */
631 if (style & WS_CHILD) swp |= SWP_NOACTIVATE | SWP_NOZORDER;
632 /* fall through */
633 case SW_SHOWMINIMIZED:
634 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
635 swp |= WINPOS_MinMaximize( hwnd, cmd, &newPos );
636 if ((style & WS_MINIMIZE) && wasVisible) return TRUE;
637 break;
639 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
640 if (!wasVisible) swp |= SWP_SHOWWINDOW;
641 swp |= SWP_FRAMECHANGED;
642 swp |= WINPOS_MinMaximize( hwnd, SW_MAXIMIZE, &newPos );
643 if ((style & WS_MAXIMIZE) && wasVisible) return TRUE;
644 break;
646 case SW_SHOWNA:
647 swp |= SWP_NOACTIVATE | SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
648 if (style & WS_CHILD) swp |= SWP_NOZORDER;
649 break;
650 case SW_SHOW:
651 if (wasVisible) return TRUE;
652 swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
653 if (style & WS_CHILD) swp |= SWP_NOACTIVATE | SWP_NOZORDER;
654 break;
656 case SW_SHOWNOACTIVATE:
657 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
658 /* fall through */
659 case SW_RESTORE:
660 /* fall through */
661 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
662 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
663 if (!wasVisible) swp |= SWP_SHOWWINDOW;
664 if (style & (WS_MINIMIZE | WS_MAXIMIZE))
666 swp |= SWP_FRAMECHANGED;
667 swp |= WINPOS_MinMaximize( hwnd, cmd, &newPos );
669 else
671 if (wasVisible) return TRUE;
672 swp |= SWP_NOSIZE | SWP_NOMOVE;
674 if (style & WS_CHILD && !(swp & SWP_STATECHANGED)) swp |= SWP_NOACTIVATE | SWP_NOZORDER;
675 break;
678 if ((showFlag != wasVisible || cmd == SW_SHOWNA) && cmd != SW_SHOWMAXIMIZED && !(swp & SWP_STATECHANGED))
680 SendMessageW( hwnd, WM_SHOWWINDOW, showFlag, 0 );
681 if (!IsWindow( hwnd )) return wasVisible;
684 parent = GetAncestor( hwnd, GA_PARENT );
685 if (parent && !IsWindowVisible( parent ) && !(swp & SWP_STATECHANGED))
687 /* if parent is not visible simply toggle WS_VISIBLE and return */
688 if (showFlag) WIN_SetStyle( hwnd, WS_VISIBLE, 0 );
689 else WIN_SetStyle( hwnd, 0, WS_VISIBLE );
691 else
692 SetWindowPos( hwnd, HWND_TOP, newPos.left, newPos.top,
693 newPos.right, newPos.bottom, LOWORD(swp) );
695 if (cmd == SW_HIDE)
697 HWND hFocus;
699 /* FIXME: This will cause the window to be activated irrespective
700 * of whether it is owned by the same thread. Has to be done
701 * asynchronously.
704 if (hwnd == GetActiveWindow())
705 WINPOS_ActivateOtherWindow(hwnd);
707 /* Revert focus to parent */
708 hFocus = GetFocus();
709 if (hwnd == hFocus || IsChild(hwnd, hFocus))
711 HWND parent = GetAncestor(hwnd, GA_PARENT);
712 if (parent == GetDesktopWindow()) parent = 0;
713 SetFocus(parent);
717 if (IsIconic(hwnd)) WINPOS_ShowIconTitle( hwnd, TRUE );
719 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return wasVisible;
721 if (wndPtr->flags & WIN_NEED_SIZE)
723 /* should happen only in CreateWindowEx() */
724 int wParam = SIZE_RESTORED;
725 RECT client = wndPtr->rectClient;
727 wndPtr->flags &= ~WIN_NEED_SIZE;
728 if (wndPtr->dwStyle & WS_MAXIMIZE) wParam = SIZE_MAXIMIZED;
729 else if (wndPtr->dwStyle & WS_MINIMIZE) wParam = SIZE_MINIMIZED;
730 WIN_ReleasePtr( wndPtr );
732 SendMessageW( hwnd, WM_SIZE, wParam,
733 MAKELONG( client.right - client.left, client.bottom - client.top ));
734 SendMessageW( hwnd, WM_MOVE, 0, MAKELONG( client.left, client.top ));
736 else WIN_ReleasePtr( wndPtr );
738 /* if previous state was minimized Windows sets focus to the window */
739 if (style & WS_MINIMIZE) SetFocus( hwnd );
741 return wasVisible;
745 /**********************************************************************
746 * X11DRV_MapNotify
748 void X11DRV_MapNotify( HWND hwnd, XEvent *event )
750 struct x11drv_win_data *data;
751 HWND hwndFocus = GetFocus();
752 WND *win;
754 if (!(data = X11DRV_get_win_data( hwnd ))) return;
756 if (!(win = WIN_GetPtr( hwnd ))) return;
758 if (data->managed && (win->dwStyle & WS_VISIBLE) && (win->dwStyle & WS_MINIMIZE))
760 int x, y;
761 unsigned int width, height, border, depth;
762 Window root, top;
763 RECT rect;
764 LONG style = WS_VISIBLE;
766 /* FIXME: hack */
767 wine_tsx11_lock();
768 XGetGeometry( event->xmap.display, data->whole_window, &root, &x, &y, &width, &height,
769 &border, &depth );
770 XTranslateCoordinates( event->xmap.display, data->whole_window, root, 0, 0, &x, &y, &top );
771 wine_tsx11_unlock();
772 rect.left = x;
773 rect.top = y;
774 rect.right = x + width;
775 rect.bottom = y + height;
776 OffsetRect( &rect, virtual_screen_rect.left, virtual_screen_rect.top );
777 X11DRV_X_to_window_rect( data, &rect );
779 invalidate_dce( hwnd, &data->window_rect );
781 if (win->flags & WIN_RESTORE_MAX) style |= WS_MAXIMIZE;
782 WIN_SetStyle( hwnd, style, WS_MINIMIZE );
783 WIN_ReleasePtr( win );
785 SendMessageW( hwnd, WM_SHOWWINDOW, SW_RESTORE, 0 );
786 data->lock_changes++;
787 SetWindowPos( hwnd, 0, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
788 SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED | SWP_STATECHANGED );
789 data->lock_changes--;
791 else WIN_ReleasePtr( win );
792 if (hwndFocus && IsChild( hwnd, hwndFocus )) X11DRV_SetFocus(hwndFocus); /* FIXME */
796 /**********************************************************************
797 * X11DRV_UnmapNotify
799 void X11DRV_UnmapNotify( HWND hwnd, XEvent *event )
801 struct x11drv_win_data *data;
802 WND *win;
804 if (!(data = X11DRV_get_win_data( hwnd ))) return;
806 if (!(win = WIN_GetPtr( hwnd ))) return;
808 if ((win->dwStyle & WS_VISIBLE) && data->managed &&
809 X11DRV_is_window_rect_mapped( &win->rectWindow ))
811 if (win->dwStyle & WS_MAXIMIZE)
812 win->flags |= WIN_RESTORE_MAX;
813 else if (!(win->dwStyle & WS_MINIMIZE))
814 win->flags &= ~WIN_RESTORE_MAX;
816 WIN_SetStyle( hwnd, WS_MINIMIZE, WS_MAXIMIZE );
817 WIN_ReleasePtr( win );
819 EndMenu();
820 SendMessageW( hwnd, WM_SHOWWINDOW, SW_MINIMIZE, 0 );
821 data->lock_changes++;
822 SetWindowPos( hwnd, 0, 0, 0, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON),
823 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_STATECHANGED );
824 data->lock_changes--;
826 else WIN_ReleasePtr( win );
829 struct desktop_resize_data
831 RECT old_screen_rect;
832 RECT old_virtual_rect;
835 static BOOL CALLBACK update_windows_on_desktop_resize( HWND hwnd, LPARAM lparam )
837 struct x11drv_win_data *data;
838 Display *display = thread_display();
839 struct desktop_resize_data *resize_data = (struct desktop_resize_data *)lparam;
840 int mask = 0;
842 if (!(data = X11DRV_get_win_data( hwnd ))) return TRUE;
844 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE)
846 /* update the full screen state */
847 update_wm_states( display, data, FALSE );
850 if (resize_data->old_virtual_rect.left != virtual_screen_rect.left) mask |= CWX;
851 if (resize_data->old_virtual_rect.top != virtual_screen_rect.top) mask |= CWY;
852 if (mask && data->whole_window)
854 XWindowChanges changes;
856 wine_tsx11_lock();
857 changes.x = data->whole_rect.left - virtual_screen_rect.left;
858 changes.y = data->whole_rect.top - virtual_screen_rect.top;
859 XReconfigureWMWindow( display, data->whole_window,
860 DefaultScreen(display), mask, &changes );
861 wine_tsx11_unlock();
863 return TRUE;
867 /***********************************************************************
868 * X11DRV_handle_desktop_resize
870 void X11DRV_handle_desktop_resize( unsigned int width, unsigned int height )
872 HWND hwnd = GetDesktopWindow();
873 struct x11drv_win_data *data;
874 struct desktop_resize_data resize_data;
876 if (!(data = X11DRV_get_win_data( hwnd ))) return;
878 SetRect( &resize_data.old_screen_rect, 0, 0, screen_width, screen_height );
879 resize_data.old_virtual_rect = virtual_screen_rect;
881 screen_width = width;
882 screen_height = height;
883 xinerama_init();
884 TRACE("desktop %p change to (%dx%d)\n", hwnd, width, height);
885 data->lock_changes++;
886 X11DRV_SetWindowPos( hwnd, 0, &virtual_screen_rect, &virtual_screen_rect,
887 SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE, NULL );
888 data->lock_changes--;
889 ClipCursor(NULL);
890 SendMessageTimeoutW( HWND_BROADCAST, WM_DISPLAYCHANGE, screen_depth,
891 MAKELPARAM( width, height ), SMTO_ABORTIFHUNG, 2000, NULL );
893 EnumWindows( update_windows_on_desktop_resize, (LPARAM)&resize_data );
897 /***********************************************************************
898 * X11DRV_ConfigureNotify
900 void X11DRV_ConfigureNotify( HWND hwnd, XEvent *xev )
902 XConfigureEvent *event = &xev->xconfigure;
903 struct x11drv_win_data *data;
904 RECT rect;
905 UINT flags;
906 int cx, cy, x = event->x, y = event->y;
908 if (!hwnd) return;
909 if (!(data = X11DRV_get_win_data( hwnd ))) return;
911 /* Get geometry */
913 if (!event->send_event) /* normal event, need to map coordinates to the root */
915 Window child;
916 wine_tsx11_lock();
917 XTranslateCoordinates( event->display, data->whole_window, root_window,
918 0, 0, &x, &y, &child );
919 wine_tsx11_unlock();
921 rect.left = x;
922 rect.top = y;
923 rect.right = x + event->width;
924 rect.bottom = y + event->height;
925 OffsetRect( &rect, virtual_screen_rect.left, virtual_screen_rect.top );
926 TRACE( "win %p new X rect %d,%d,%dx%d (event %d,%d,%dx%d)\n",
927 hwnd, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
928 event->x, event->y, event->width, event->height );
929 X11DRV_X_to_window_rect( data, &rect );
931 x = rect.left;
932 y = rect.top;
933 cx = rect.right - rect.left;
934 cy = rect.bottom - rect.top;
935 flags = SWP_NOACTIVATE | SWP_NOZORDER;
937 /* Compare what has changed */
939 GetWindowRect( hwnd, &rect );
940 if (rect.left == x && rect.top == y) flags |= SWP_NOMOVE;
941 else
942 TRACE( "%p moving from (%d,%d) to (%d,%d)\n",
943 hwnd, rect.left, rect.top, x, y );
945 if ((rect.right - rect.left == cx && rect.bottom - rect.top == cy) ||
946 IsIconic(hwnd) ||
947 (IsRectEmpty( &rect ) && event->width == 1 && event->height == 1))
949 if (flags & SWP_NOMOVE) return; /* if nothing changed, don't do anything */
950 flags |= SWP_NOSIZE;
952 else
953 TRACE( "%p resizing from (%dx%d) to (%dx%d)\n",
954 hwnd, rect.right - rect.left, rect.bottom - rect.top, cx, cy );
956 data->lock_changes++;
957 SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
958 data->lock_changes--;
962 /***********************************************************************
963 * SetWindowRgn (X11DRV.@)
965 * Assign specified region to window (for non-rectangular windows)
967 int X11DRV_SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL redraw )
969 struct x11drv_win_data *data;
971 if (!(data = X11DRV_get_win_data( hwnd )))
973 if (IsWindow( hwnd ))
974 FIXME( "not supported on other thread window %p\n", hwnd );
975 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
976 return FALSE;
979 #ifdef HAVE_LIBXSHAPE
980 if (data->whole_window)
982 Display *display = thread_display();
984 if (!hrgn)
986 wine_tsx11_lock();
987 XShapeCombineMask( display, data->whole_window,
988 ShapeBounding, 0, 0, None, ShapeSet );
989 wine_tsx11_unlock();
991 else
993 RGNDATA *pRegionData = X11DRV_GetRegionData( hrgn, 0 );
994 if (pRegionData)
996 wine_tsx11_lock();
997 XShapeCombineRectangles( display, data->whole_window, ShapeBounding,
998 data->window_rect.left - data->whole_rect.left,
999 data->window_rect.top - data->whole_rect.top,
1000 (XRectangle *)pRegionData->Buffer,
1001 pRegionData->rdh.nCount,
1002 ShapeSet, YXBanded );
1003 wine_tsx11_unlock();
1004 HeapFree(GetProcessHeap(), 0, pRegionData);
1008 #endif /* HAVE_LIBXSHAPE */
1010 invalidate_dce( hwnd, &data->window_rect );
1011 return TRUE;
1015 /***********************************************************************
1016 * draw_moving_frame
1018 * Draw the frame used when moving or resizing window.
1020 * FIXME: This causes problems in Win95 mode. (why?)
1022 static void draw_moving_frame( HDC hdc, RECT *rect, BOOL thickframe )
1024 if (thickframe)
1026 const int width = GetSystemMetrics(SM_CXFRAME);
1027 const int height = GetSystemMetrics(SM_CYFRAME);
1029 HBRUSH hbrush = SelectObject( hdc, GetStockObject( GRAY_BRUSH ) );
1030 PatBlt( hdc, rect->left, rect->top,
1031 rect->right - rect->left - width, height, PATINVERT );
1032 PatBlt( hdc, rect->left, rect->top + height, width,
1033 rect->bottom - rect->top - height, PATINVERT );
1034 PatBlt( hdc, rect->left + width, rect->bottom - 1,
1035 rect->right - rect->left - width, -height, PATINVERT );
1036 PatBlt( hdc, rect->right - 1, rect->top, -width,
1037 rect->bottom - rect->top - height, PATINVERT );
1038 SelectObject( hdc, hbrush );
1040 else DrawFocusRect( hdc, rect );
1044 /***********************************************************************
1045 * start_size_move
1047 * Initialisation of a move or resize, when initiatied from a menu choice.
1048 * Return hit test code for caption or sizing border.
1050 static LONG start_size_move( HWND hwnd, WPARAM wParam, POINT *capturePoint, LONG style )
1052 LONG hittest = 0;
1053 POINT pt;
1054 MSG msg;
1055 RECT rectWindow;
1057 GetWindowRect( hwnd, &rectWindow );
1059 if ((wParam & 0xfff0) == SC_MOVE)
1061 /* Move pointer at the center of the caption */
1062 RECT rect = rectWindow;
1063 /* Note: to be exactly centered we should take the different types
1064 * of border into account, but it shouldn't make more that a few pixels
1065 * of difference so let's not bother with that */
1066 rect.top += GetSystemMetrics(SM_CYBORDER);
1067 if (style & WS_SYSMENU)
1068 rect.left += GetSystemMetrics(SM_CXSIZE) + 1;
1069 if (style & WS_MINIMIZEBOX)
1070 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1071 if (style & WS_MAXIMIZEBOX)
1072 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1073 pt.x = (rect.right + rect.left) / 2;
1074 pt.y = rect.top + GetSystemMetrics(SM_CYSIZE)/2;
1075 hittest = HTCAPTION;
1076 *capturePoint = pt;
1078 else /* SC_SIZE */
1080 pt.x = pt.y = 0;
1081 while(!hittest)
1083 GetMessageW( &msg, 0, WM_KEYFIRST, WM_MOUSELAST );
1084 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
1086 switch(msg.message)
1088 case WM_MOUSEMOVE:
1089 pt = msg.pt;
1090 hittest = SendMessageW( hwnd, WM_NCHITTEST, 0, MAKELONG( pt.x, pt.y ) );
1091 if ((hittest < HTLEFT) || (hittest > HTBOTTOMRIGHT)) hittest = 0;
1092 break;
1094 case WM_LBUTTONUP:
1095 return 0;
1097 case WM_KEYDOWN:
1098 switch(msg.wParam)
1100 case VK_UP:
1101 hittest = HTTOP;
1102 pt.x =(rectWindow.left+rectWindow.right)/2;
1103 pt.y = rectWindow.top + GetSystemMetrics(SM_CYFRAME) / 2;
1104 break;
1105 case VK_DOWN:
1106 hittest = HTBOTTOM;
1107 pt.x =(rectWindow.left+rectWindow.right)/2;
1108 pt.y = rectWindow.bottom - GetSystemMetrics(SM_CYFRAME) / 2;
1109 break;
1110 case VK_LEFT:
1111 hittest = HTLEFT;
1112 pt.x = rectWindow.left + GetSystemMetrics(SM_CXFRAME) / 2;
1113 pt.y =(rectWindow.top+rectWindow.bottom)/2;
1114 break;
1115 case VK_RIGHT:
1116 hittest = HTRIGHT;
1117 pt.x = rectWindow.right - GetSystemMetrics(SM_CXFRAME) / 2;
1118 pt.y =(rectWindow.top+rectWindow.bottom)/2;
1119 break;
1120 case VK_RETURN:
1121 case VK_ESCAPE: return 0;
1125 *capturePoint = pt;
1127 SetCursorPos( pt.x, pt.y );
1128 SendMessageW( hwnd, WM_SETCURSOR, (WPARAM)hwnd, MAKELONG( hittest, WM_MOUSEMOVE ));
1129 return hittest;
1133 /***********************************************************************
1134 * set_movesize_capture
1136 static void set_movesize_capture( HWND hwnd )
1138 HWND previous = 0;
1140 SERVER_START_REQ( set_capture_window )
1142 req->handle = hwnd;
1143 req->flags = CAPTURE_MOVESIZE;
1144 if (!wine_server_call_err( req ))
1146 previous = reply->previous;
1147 hwnd = reply->full_handle;
1150 SERVER_END_REQ;
1151 if (previous && previous != hwnd)
1152 SendMessageW( previous, WM_CAPTURECHANGED, 0, (LPARAM)hwnd );
1155 /***********************************************************************
1156 * X11DRV_WMMoveResizeWindow
1158 * Tells the window manager to initiate a move or resize operation.
1160 * SEE
1161 * http://freedesktop.org/Standards/wm-spec/1.3/ar01s04.html
1162 * or search for "_NET_WM_MOVERESIZE"
1164 static BOOL X11DRV_WMMoveResizeWindow( HWND hwnd, int x, int y, WPARAM wparam )
1166 WPARAM syscommand = wparam & 0xfff0;
1167 WPARAM hittest = wparam & 0x0f;
1168 int dir;
1169 XEvent xev;
1170 Display *display = thread_display();
1172 if (syscommand == SC_MOVE)
1174 if (!hittest) dir = _NET_WM_MOVERESIZE_MOVE_KEYBOARD;
1175 else dir = _NET_WM_MOVERESIZE_MOVE;
1177 else
1179 /* windows without WS_THICKFRAME are not resizable through the window manager */
1180 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_THICKFRAME)) return FALSE;
1182 switch (hittest)
1184 case WMSZ_LEFT: dir = _NET_WM_MOVERESIZE_SIZE_LEFT; break;
1185 case WMSZ_RIGHT: dir = _NET_WM_MOVERESIZE_SIZE_RIGHT; break;
1186 case WMSZ_TOP: dir = _NET_WM_MOVERESIZE_SIZE_TOP; break;
1187 case WMSZ_TOPLEFT: dir = _NET_WM_MOVERESIZE_SIZE_TOPLEFT; break;
1188 case WMSZ_TOPRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT; break;
1189 case WMSZ_BOTTOM: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOM; break;
1190 case WMSZ_BOTTOMLEFT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT; break;
1191 case WMSZ_BOTTOMRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT; break;
1192 default: dir = _NET_WM_MOVERESIZE_SIZE_KEYBOARD; break;
1196 TRACE("hwnd %p, x %d, y %d, dir %d\n", hwnd, x, y, dir);
1198 xev.xclient.type = ClientMessage;
1199 xev.xclient.window = X11DRV_get_whole_window(hwnd);
1200 xev.xclient.message_type = x11drv_atom(_NET_WM_MOVERESIZE);
1201 xev.xclient.serial = 0;
1202 xev.xclient.display = display;
1203 xev.xclient.send_event = True;
1204 xev.xclient.format = 32;
1205 xev.xclient.data.l[0] = x; /* x coord */
1206 xev.xclient.data.l[1] = y; /* y coord */
1207 xev.xclient.data.l[2] = dir; /* direction */
1208 xev.xclient.data.l[3] = 1; /* button */
1209 xev.xclient.data.l[4] = 0; /* unused */
1211 /* need to ungrab the pointer that may have been automatically grabbed
1212 * with a ButtonPress event */
1213 wine_tsx11_lock();
1214 XUngrabPointer( display, CurrentTime );
1215 XSendEvent(display, root_window, False, SubstructureNotifyMask, &xev);
1216 wine_tsx11_unlock();
1217 return TRUE;
1220 /***********************************************************************
1221 * SysCommandSizeMove (X11DRV.@)
1223 * Perform SC_MOVE and SC_SIZE commands.
1225 void X11DRV_SysCommandSizeMove( HWND hwnd, WPARAM wParam )
1227 MSG msg;
1228 RECT sizingRect, mouseRect, origRect;
1229 HDC hdc;
1230 HWND parent;
1231 LONG hittest = (LONG)(wParam & 0x0f);
1232 WPARAM syscommand = wParam & 0xfff0;
1233 HCURSOR hDragCursor = 0, hOldCursor = 0;
1234 POINT minTrack, maxTrack;
1235 POINT capturePoint, pt;
1236 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
1237 BOOL thickframe = HAS_THICKFRAME( style );
1238 BOOL iconic = style & WS_MINIMIZE;
1239 BOOL moved = FALSE;
1240 DWORD dwPoint = GetMessagePos ();
1241 BOOL DragFullWindows = TRUE;
1242 Window parent_win, whole_win;
1243 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1244 struct x11drv_win_data *data;
1246 pt.x = (short)LOWORD(dwPoint);
1247 pt.y = (short)HIWORD(dwPoint);
1248 capturePoint = pt;
1250 if (IsZoomed(hwnd) || !IsWindowVisible(hwnd)) return;
1252 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1254 TRACE("hwnd %p (%smanaged), command %04lx, hittest %d, pos %d,%d\n",
1255 hwnd, data->managed ? "" : "NOT ", syscommand, hittest, pt.x, pt.y);
1257 /* if we are managed then we let the WM do all the work */
1258 if (data->managed && X11DRV_WMMoveResizeWindow( hwnd, pt.x, pt.y, wParam )) return;
1260 if (syscommand == SC_MOVE)
1262 if (!hittest) hittest = start_size_move( hwnd, wParam, &capturePoint, style );
1263 if (!hittest) return;
1265 else /* SC_SIZE */
1267 if ( hittest && (syscommand != SC_MOUSEMENU) )
1268 hittest += (HTLEFT - WMSZ_LEFT);
1269 else
1271 set_movesize_capture( hwnd );
1272 hittest = start_size_move( hwnd, wParam, &capturePoint, style );
1273 if (!hittest)
1275 set_movesize_capture(0);
1276 return;
1281 /* Get min/max info */
1283 WINPOS_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack );
1284 GetWindowRect( hwnd, &sizingRect );
1285 if (style & WS_CHILD)
1287 parent = GetParent(hwnd);
1288 /* make sizing rect relative to parent */
1289 MapWindowPoints( 0, parent, (POINT*)&sizingRect, 2 );
1290 GetClientRect( parent, &mouseRect );
1292 else
1294 parent = 0;
1295 mouseRect = virtual_screen_rect;
1297 origRect = sizingRect;
1299 if (ON_LEFT_BORDER(hittest))
1301 mouseRect.left = max( mouseRect.left, sizingRect.right-maxTrack.x );
1302 mouseRect.right = min( mouseRect.right, sizingRect.right-minTrack.x );
1304 else if (ON_RIGHT_BORDER(hittest))
1306 mouseRect.left = max( mouseRect.left, sizingRect.left+minTrack.x );
1307 mouseRect.right = min( mouseRect.right, sizingRect.left+maxTrack.x );
1309 if (ON_TOP_BORDER(hittest))
1311 mouseRect.top = max( mouseRect.top, sizingRect.bottom-maxTrack.y );
1312 mouseRect.bottom = min( mouseRect.bottom,sizingRect.bottom-minTrack.y);
1314 else if (ON_BOTTOM_BORDER(hittest))
1316 mouseRect.top = max( mouseRect.top, sizingRect.top+minTrack.y );
1317 mouseRect.bottom = min( mouseRect.bottom, sizingRect.top+maxTrack.y );
1319 if (parent) MapWindowPoints( parent, 0, (LPPOINT)&mouseRect, 2 );
1321 /* Retrieve a default cache DC (without using the window style) */
1322 hdc = GetDCEx( parent, 0, DCX_CACHE );
1324 if( iconic ) /* create a cursor for dragging */
1326 hDragCursor = (HCURSOR)GetClassLongPtrW( hwnd, GCLP_HICON);
1327 if( !hDragCursor ) hDragCursor = (HCURSOR)SendMessageW( hwnd, WM_QUERYDRAGICON, 0, 0L);
1328 if( !hDragCursor ) iconic = FALSE;
1331 /* repaint the window before moving it around */
1332 RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN );
1334 SendMessageW( hwnd, WM_ENTERSIZEMOVE, 0, 0 );
1335 set_movesize_capture( hwnd );
1337 /* we only allow disabling the full window drag for child windows, or in desktop mode */
1338 /* otherwise we'd need to grab the server and we want to avoid that */
1339 if (parent || (root_window != DefaultRootWindow(gdi_display)))
1340 SystemParametersInfoA(SPI_GETDRAGFULLWINDOWS, 0, &DragFullWindows, 0);
1342 whole_win = X11DRV_get_whole_window( GetAncestor(hwnd,GA_ROOT) );
1343 parent_win = parent ? X11DRV_get_whole_window( GetAncestor(parent,GA_ROOT) ) : root_window;
1345 wine_tsx11_lock();
1346 XGrabPointer( thread_data->display, whole_win, False,
1347 PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
1348 GrabModeAsync, GrabModeAsync, parent_win, None, CurrentTime );
1349 wine_tsx11_unlock();
1350 thread_data->grab_window = whole_win;
1352 while(1)
1354 int dx = 0, dy = 0;
1356 if (!GetMessageW( &msg, 0, WM_KEYFIRST, WM_MOUSELAST )) break;
1357 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
1359 /* Exit on button-up, Return, or Esc */
1360 if ((msg.message == WM_LBUTTONUP) ||
1361 ((msg.message == WM_KEYDOWN) &&
1362 ((msg.wParam == VK_RETURN) || (msg.wParam == VK_ESCAPE)))) break;
1364 if ((msg.message != WM_KEYDOWN) && (msg.message != WM_MOUSEMOVE))
1365 continue; /* We are not interested in other messages */
1367 pt = msg.pt;
1369 if (msg.message == WM_KEYDOWN) switch(msg.wParam)
1371 case VK_UP: pt.y -= 8; break;
1372 case VK_DOWN: pt.y += 8; break;
1373 case VK_LEFT: pt.x -= 8; break;
1374 case VK_RIGHT: pt.x += 8; break;
1377 pt.x = max( pt.x, mouseRect.left );
1378 pt.x = min( pt.x, mouseRect.right );
1379 pt.y = max( pt.y, mouseRect.top );
1380 pt.y = min( pt.y, mouseRect.bottom );
1382 dx = pt.x - capturePoint.x;
1383 dy = pt.y - capturePoint.y;
1385 if (dx || dy)
1387 if( !moved )
1389 moved = TRUE;
1391 if( iconic ) /* ok, no system popup tracking */
1393 hOldCursor = SetCursor(hDragCursor);
1394 ShowCursor( TRUE );
1395 WINPOS_ShowIconTitle( hwnd, FALSE );
1397 else if(!DragFullWindows)
1398 draw_moving_frame( hdc, &sizingRect, thickframe );
1401 if (msg.message == WM_KEYDOWN) SetCursorPos( pt.x, pt.y );
1402 else
1404 RECT newRect = sizingRect;
1405 WPARAM wpSizingHit = 0;
1407 if (hittest == HTCAPTION) OffsetRect( &newRect, dx, dy );
1408 if (ON_LEFT_BORDER(hittest)) newRect.left += dx;
1409 else if (ON_RIGHT_BORDER(hittest)) newRect.right += dx;
1410 if (ON_TOP_BORDER(hittest)) newRect.top += dy;
1411 else if (ON_BOTTOM_BORDER(hittest)) newRect.bottom += dy;
1412 if(!iconic && !DragFullWindows) draw_moving_frame( hdc, &sizingRect, thickframe );
1413 capturePoint = pt;
1415 /* determine the hit location */
1416 if (hittest >= HTLEFT && hittest <= HTBOTTOMRIGHT)
1417 wpSizingHit = WMSZ_LEFT + (hittest - HTLEFT);
1418 SendMessageW( hwnd, WM_SIZING, wpSizingHit, (LPARAM)&newRect );
1420 if (!iconic)
1422 if(!DragFullWindows)
1423 draw_moving_frame( hdc, &newRect, thickframe );
1424 else
1425 SetWindowPos( hwnd, 0, newRect.left, newRect.top,
1426 newRect.right - newRect.left,
1427 newRect.bottom - newRect.top,
1428 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
1430 sizingRect = newRect;
1435 set_movesize_capture(0);
1436 if( iconic )
1438 if( moved ) /* restore cursors, show icon title later on */
1440 ShowCursor( FALSE );
1441 SetCursor( hOldCursor );
1444 else if (moved && !DragFullWindows)
1445 draw_moving_frame( hdc, &sizingRect, thickframe );
1447 ReleaseDC( parent, hdc );
1449 wine_tsx11_lock();
1450 XUngrabPointer( thread_data->display, CurrentTime );
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 );