2 * Window position related functions.
4 * Copyright 1993, 1994, 1995, 2001 Alexandre Julliard
5 * Copyright 1995, 1996, 1999 Alex Korobka
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include <X11/Xutil.h>
33 #include "wine/wingdi16.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 /***********************************************************************
84 void X11DRV_Expose( HWND hwnd, XEvent *xev )
86 XExposeEvent *event = &xev->xexpose;
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 rect.left = data->whole_rect.left + event->x;
97 rect.top = data->whole_rect.top + event->y;
98 rect.right = rect.left + event->width;
99 rect.bottom = rect.top + event->height;
101 if (event->window == root_window)
102 OffsetRect( &rect, virtual_screen_rect.left, virtual_screen_rect.top );
104 if (rect.left < data->client_rect.left ||
105 rect.top < data->client_rect.top ||
106 rect.right > data->client_rect.right ||
107 rect.bottom > data->client_rect.bottom) flags |= RDW_FRAME;
109 SERVER_START_REQ( update_window_zorder )
112 req->rect.left = rect.left;
113 req->rect.top = rect.top;
114 req->rect.right = rect.right;
115 req->rect.bottom = rect.bottom;
116 wine_server_call( req );
120 /* make position relative to client area instead of parent */
121 OffsetRect( &rect, -data->client_rect.left, -data->client_rect.top );
122 RedrawWindow( hwnd, &rect, 0, flags );
125 /***********************************************************************
126 * SetWindowStyle (X11DRV.@)
128 * Update the X state of a window to reflect a style change
130 void X11DRV_SetWindowStyle( HWND hwnd, DWORD old_style )
132 Display *display = thread_display();
133 struct x11drv_win_data *data;
134 DWORD new_style, changed;
136 if (hwnd == GetDesktopWindow()) return;
137 if (!(data = X11DRV_get_win_data( hwnd ))) return;
139 new_style = GetWindowLongW( hwnd, GWL_STYLE );
140 changed = new_style ^ old_style;
142 if (changed & WS_VISIBLE)
144 if (data->whole_window && (new_style & WS_VISIBLE) &&
145 X11DRV_is_window_rect_mapped( &data->window_rect ))
147 X11DRV_set_wm_hints( display, data );
150 TRACE( "mapping win %p\n", hwnd );
151 X11DRV_sync_window_style( display, data );
153 XMapWindow( display, data->whole_window );
158 /* 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->wm_hints)
167 data->wm_hints->input = !(new_style & WS_DISABLED);
168 XSetWMHints( display, data->whole_window, data->wm_hints );
175 /***********************************************************************
178 static void update_wm_states( Display *display, struct x11drv_win_data *data, BOOL force )
180 static const unsigned int state_atoms[NB_WM_STATES] =
182 XATOM__NET_WM_STATE_FULLSCREEN,
183 XATOM__NET_WM_STATE_ABOVE,
184 XATOM__NET_WM_STATE_SKIP_PAGER,
185 XATOM__NET_WM_STATE_SKIP_TASKBAR
188 DWORD i, ex_style, new_state = 0;
191 if (!data->managed) return;
192 if (!data->mapped) return;
194 if (data->whole_rect.left <= 0 && data->whole_rect.right >= screen_width &&
195 data->whole_rect.top <= 0 && data->whole_rect.bottom >= screen_height)
196 new_state |= (1 << WM_STATE_FULLSCREEN);
198 ex_style = GetWindowLongW( data->hwnd, GWL_EXSTYLE );
199 if (ex_style & WS_EX_TOPMOST)
200 new_state |= (1 << WM_STATE_ABOVE);
201 if (ex_style & WS_EX_TOOLWINDOW)
202 new_state |= (1 << WM_STATE_SKIP_TASKBAR) | (1 << WM_STATE_SKIP_PAGER);
204 xev.xclient.type = ClientMessage;
205 xev.xclient.window = data->whole_window;
206 xev.xclient.message_type = x11drv_atom(_NET_WM_STATE);
207 xev.xclient.serial = 0;
208 xev.xclient.display = display;
209 xev.xclient.send_event = True;
210 xev.xclient.format = 32;
211 xev.xclient.data.l[2] = 0;
212 xev.xclient.data.l[3] = 1;
214 for (i = 0; i < NB_WM_STATES; i++)
216 if (!((data->wm_state ^ new_state) & (1 << i))) /* unchanged */
218 /* if forced, we only add states, we don't remove them */
219 if (!force || !(new_state & (1 << i))) continue;
222 TRACE( "setting wm state %u for window %p/%lx to %u prev %u\n",
223 i, data->hwnd, data->whole_window,
224 (new_state & (1 << i)) != 0, (data->wm_state & (1 << i)) != 0 );
226 xev.xclient.data.l[0] = (new_state & (1 << i)) ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
227 xev.xclient.data.l[1] = X11DRV_Atoms[state_atoms[i] - FIRST_XATOM];
229 XSendEvent( display, root_window, False, SubstructureRedirectMask | SubstructureNotifyMask, &xev );
232 data->wm_state = new_state;
236 /***********************************************************************
239 * Move the window bits when a window is moved.
241 static void move_window_bits( struct x11drv_win_data *data, const RECT *old_rect, const RECT *new_rect,
242 const RECT *old_whole_rect )
244 RECT src_rect = *old_rect;
245 RECT dst_rect = *new_rect;
246 HDC hdc_src, hdc_dst;
251 if (!data->whole_window)
253 OffsetRect( &dst_rect, -data->window_rect.left, -data->window_rect.top );
254 parent = GetAncestor( data->hwnd, GA_PARENT );
255 hdc_src = GetDCEx( parent, 0, DCX_CACHE );
256 hdc_dst = GetDCEx( data->hwnd, 0, DCX_CACHE | DCX_WINDOW );
260 OffsetRect( &dst_rect, -data->whole_rect.left, -data->whole_rect.top );
261 /* make src rect relative to the old position of the window */
262 OffsetRect( &src_rect, -old_whole_rect->left, -old_whole_rect->top );
263 if (dst_rect.left == src_rect.left && dst_rect.top == src_rect.top) return;
264 /* now make them relative to window rect for DCX_WINDOW */
265 OffsetRect( &dst_rect, data->whole_rect.left - data->window_rect.left,
266 data->whole_rect.top - data->window_rect.top );
267 OffsetRect( &src_rect, data->whole_rect.left - data->window_rect.left,
268 data->whole_rect.top - data->window_rect.top );
269 hdc_src = hdc_dst = GetDCEx( data->hwnd, 0, DCX_CACHE | DCX_WINDOW );
272 code = X11DRV_START_EXPOSURES;
273 ExtEscape( hdc_dst, X11DRV_ESCAPE, sizeof(code), (LPSTR)&code, 0, NULL );
275 TRACE( "copying bits for win %p/%lx %s -> %s\n",
276 data->hwnd, data->whole_window, 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 );
289 OffsetRgn( rgn, data->window_rect.left - data->client_rect.left,
290 data->window_rect.top - data->client_rect.top );
291 RedrawWindow( data->hwnd, NULL, rgn, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE | RDW_ALLCHILDREN );
296 /***********************************************************************
297 * set_server_window_pos
299 * Set the window pos on the server side only. Helper for SetWindowPos.
301 static BOOL set_server_window_pos( HWND hwnd, HWND insert_after, const RECT *rectWindow,
302 const RECT *rectClient, UINT swp_flags, const RECT *valid_rects,
308 if (!(win = WIN_GetPtr( hwnd ))) return FALSE;
309 if (win == WND_DESKTOP || win == WND_OTHER_PROCESS) return FALSE;
311 SERVER_START_REQ( set_window_pos )
314 req->previous = insert_after;
315 req->flags = swp_flags;
316 req->window.left = rectWindow->left;
317 req->window.top = rectWindow->top;
318 req->window.right = rectWindow->right;
319 req->window.bottom = rectWindow->bottom;
320 req->client.left = rectClient->left;
321 req->client.top = rectClient->top;
322 req->client.right = rectClient->right;
323 req->client.bottom = rectClient->bottom;
324 if (!IsRectEmpty( &valid_rects[0] ))
325 wine_server_add_data( req, valid_rects, 2 * sizeof(*valid_rects) );
326 if ((ret = !wine_server_call( req )))
328 win->dwStyle = reply->new_style;
329 win->dwExStyle = reply->new_ex_style;
330 win->rectWindow = *rectWindow;
331 win->rectClient = *rectClient;
332 visible_rect->left = reply->visible.left;
333 visible_rect->top = reply->visible.top;
334 visible_rect->right = reply->visible.right;
335 visible_rect->bottom = reply->visible.bottom;
340 WIN_ReleasePtr( win );
345 /***********************************************************************
346 * SetWindowPos (X11DRV.@)
348 BOOL X11DRV_SetWindowPos( HWND hwnd, HWND insert_after, const RECT *rectWindow,
349 const RECT *rectClient, UINT swp_flags, const RECT *valid_rects )
351 Display *display = thread_display();
352 struct x11drv_win_data *data;
353 RECT old_window_rect, old_whole_rect, old_client_rect, visible_rect;
356 if (!(data = X11DRV_get_win_data( hwnd ))) return FALSE;
358 if (!set_server_window_pos( hwnd, insert_after, rectWindow, rectClient, swp_flags,
359 valid_rects, &visible_rect ))
362 if (data->whole_window == DefaultRootWindow(gdi_display))
364 data->whole_rect = data->client_rect = data->window_rect = *rectWindow;
368 /* check if we need to switch the window to managed */
369 if (!data->managed && data->whole_window && managed_mode &&
370 root_window == DefaultRootWindow( display ) &&
371 is_window_managed( hwnd, swp_flags, rectWindow ))
373 TRACE( "making win %p/%lx managed\n", hwnd, data->whole_window );
374 data->managed = TRUE;
375 SetPropA( hwnd, managed_prop, (HANDLE)1 );
379 XUnmapWindow( display, data->whole_window );
381 data->mapped = FALSE;
385 new_style = GetWindowLongW( hwnd, GWL_STYLE );
386 old_window_rect = data->window_rect;
387 old_whole_rect = data->whole_rect;
388 old_client_rect = data->client_rect;
389 data->window_rect = *rectWindow;
390 data->whole_rect = *rectWindow;
391 data->client_rect = *rectClient;
392 X11DRV_window_to_X_rect( data, &data->whole_rect );
393 if (memcmp( &visible_rect, &data->whole_rect, sizeof(RECT) ))
395 TRACE( "%p: need to update visible rect %s -> %s\n", hwnd,
396 wine_dbgstr_rect(&visible_rect), wine_dbgstr_rect(&data->whole_rect) );
397 SERVER_START_REQ( set_window_visible_rect )
400 req->flags = swp_flags;
401 req->visible.left = data->whole_rect.left;
402 req->visible.top = data->whole_rect.top;
403 req->visible.right = data->whole_rect.right;
404 req->visible.bottom = data->whole_rect.bottom;
405 wine_server_call( req );
410 /* invalidate DCEs */
411 if ((((swp_flags & SWP_AGG_NOPOSCHANGE) != SWP_AGG_NOPOSCHANGE) && (new_style & WS_VISIBLE)) ||
412 (swp_flags & (SWP_HIDEWINDOW | SWP_SHOWWINDOW)))
415 UnionRect( &rect, rectWindow, &old_window_rect );
416 invalidate_dce( hwnd, &rect );
419 TRACE( "win %p window %s client %s style %08x\n",
420 hwnd, wine_dbgstr_rect(rectWindow), wine_dbgstr_rect(rectClient), new_style );
422 if (!IsRectEmpty( &valid_rects[0] ))
424 int x_offset = old_whole_rect.left - data->whole_rect.left;
425 int y_offset = old_whole_rect.top - data->whole_rect.top;
427 /* if all that happened is that the whole window moved, copy everything */
428 if (!(swp_flags & SWP_FRAMECHANGED) &&
429 old_whole_rect.right - data->whole_rect.right == x_offset &&
430 old_whole_rect.bottom - data->whole_rect.bottom == y_offset &&
431 old_client_rect.left - data->client_rect.left == x_offset &&
432 old_client_rect.right - data->client_rect.right == x_offset &&
433 old_client_rect.top - data->client_rect.top == y_offset &&
434 old_client_rect.bottom - data->client_rect.bottom == y_offset &&
435 !memcmp( &valid_rects[0], &data->client_rect, sizeof(RECT) ))
437 /* if we have an X window the bits will be moved by the X server */
438 if (!data->whole_window)
439 move_window_bits( data, &old_whole_rect, &data->whole_rect, &old_whole_rect );
442 move_window_bits( data, &valid_rects[1], &valid_rects[0], &old_whole_rect );
445 if (data->gl_drawable &&
446 data->client_rect.right-data->client_rect.left == old_client_rect.right-old_client_rect.left &&
447 data->client_rect.bottom-data->client_rect.top == old_client_rect.bottom-old_client_rect.top)
448 X11DRV_sync_gl_drawable( display, data );
450 if (!data->whole_window || data->lock_changes) return TRUE; /* nothing more to do */
452 if (data->mapped && (!(new_style & WS_VISIBLE) || !X11DRV_is_window_rect_mapped( rectWindow )))
454 TRACE( "unmapping win %p\n", hwnd );
456 XUnmapWindow( display, data->whole_window );
458 data->mapped = FALSE;
461 X11DRV_sync_window_position( display, data, swp_flags, &old_client_rect, &old_whole_rect );
463 if ((new_style & WS_VISIBLE) && !(new_style & WS_MINIMIZE) &&
464 X11DRV_is_window_rect_mapped( rectWindow ))
466 BOOL was_mapped = data->mapped;
468 if (!data->mapped || (swp_flags & SWP_FRAMECHANGED))
469 X11DRV_set_wm_hints( display, data );
473 TRACE( "mapping win %p\n", hwnd );
474 X11DRV_sync_window_style( display, data );
476 XMapWindow( display, data->whole_window );
481 update_wm_states( display, data, !was_mapped );
488 /***********************************************************************
491 * Find a suitable place for an iconic window.
493 static POINT WINPOS_FindIconPos( HWND hwnd, POINT pt )
495 RECT rect, rectParent;
498 int xspacing, yspacing;
500 parent = GetAncestor( hwnd, GA_PARENT );
501 GetClientRect( parent, &rectParent );
502 if ((pt.x >= rectParent.left) && (pt.x + GetSystemMetrics(SM_CXICON) < rectParent.right) &&
503 (pt.y >= rectParent.top) && (pt.y + GetSystemMetrics(SM_CYICON) < rectParent.bottom))
504 return pt; /* The icon already has a suitable position */
506 xspacing = GetSystemMetrics(SM_CXICONSPACING);
507 yspacing = GetSystemMetrics(SM_CYICONSPACING);
509 /* Check if another icon already occupies this spot */
510 /* FIXME: this is completely inefficient */
512 hrgn = CreateRectRgn( 0, 0, 0, 0 );
513 tmp = CreateRectRgn( 0, 0, 0, 0 );
514 for (child = GetWindow( parent, GW_HWNDFIRST ); child; child = GetWindow( child, GW_HWNDNEXT ))
517 if (child == hwnd) continue;
518 if ((GetWindowLongW( child, GWL_STYLE ) & (WS_VISIBLE|WS_MINIMIZE)) != (WS_VISIBLE|WS_MINIMIZE))
520 if (!(childPtr = WIN_GetPtr( child )) || childPtr == WND_OTHER_PROCESS)
522 SetRectRgn( tmp, childPtr->rectWindow.left, childPtr->rectWindow.top,
523 childPtr->rectWindow.right, childPtr->rectWindow.bottom );
524 CombineRgn( hrgn, hrgn, tmp, RGN_OR );
525 WIN_ReleasePtr( childPtr );
529 for (rect.bottom = rectParent.bottom; rect.bottom >= yspacing; rect.bottom -= yspacing)
531 for (rect.left = rectParent.left; rect.left <= rectParent.right - xspacing; rect.left += xspacing)
533 rect.right = rect.left + xspacing;
534 rect.top = rect.bottom - yspacing;
535 if (!RectInRegion( hrgn, &rect ))
537 /* No window was found, so it's OK for us */
538 pt.x = rect.left + (xspacing - GetSystemMetrics(SM_CXICON)) / 2;
539 pt.y = rect.top + (yspacing - GetSystemMetrics(SM_CYICON)) / 2;
540 DeleteObject( hrgn );
545 DeleteObject( hrgn );
551 /***********************************************************************
554 UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect )
562 TRACE("%p %u\n", hwnd, cmd );
564 wpl.length = sizeof(wpl);
565 GetWindowPlacement( hwnd, &wpl );
567 if (HOOK_CallHooks( WH_CBT, HCBT_MINMAX, (WPARAM)hwnd, cmd, TRUE ))
568 return SWP_NOSIZE | SWP_NOMOVE;
570 if (IsIconic( hwnd ))
574 case SW_SHOWMINNOACTIVE:
575 case SW_SHOWMINIMIZED:
576 case SW_FORCEMINIMIZE:
578 return SWP_NOSIZE | SWP_NOMOVE;
580 if (!SendMessageW( hwnd, WM_QUERYOPEN, 0, 0 )) return SWP_NOSIZE | SWP_NOMOVE;
581 swpFlags |= SWP_NOCOPYBITS;
586 case SW_SHOWMINNOACTIVE:
587 case SW_SHOWMINIMIZED:
588 case SW_FORCEMINIMIZE:
590 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
591 if( wndPtr->dwStyle & WS_MAXIMIZE) wndPtr->flags |= WIN_RESTORE_MAX;
592 else wndPtr->flags &= ~WIN_RESTORE_MAX;
593 WIN_ReleasePtr( wndPtr );
595 old_style = WIN_SetStyle( hwnd, WS_MINIMIZE, WS_MAXIMIZE );
597 X11DRV_set_iconic_state( hwnd );
599 wpl.ptMinPosition = WINPOS_FindIconPos( hwnd, wpl.ptMinPosition );
601 if (!(old_style & WS_MINIMIZE)) swpFlags |= SWP_STATECHANGED;
602 SetRect( rect, wpl.ptMinPosition.x, wpl.ptMinPosition.y,
603 GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON) );
604 swpFlags |= SWP_NOCOPYBITS;
608 old_style = GetWindowLongW( hwnd, GWL_STYLE );
609 if ((old_style & WS_MAXIMIZE) && (old_style & WS_VISIBLE)) return SWP_NOSIZE | SWP_NOMOVE;
611 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL );
613 old_style = WIN_SetStyle( hwnd, WS_MAXIMIZE, WS_MINIMIZE );
614 if (old_style & WS_MINIMIZE)
616 WINPOS_ShowIconTitle( hwnd, FALSE );
617 X11DRV_set_iconic_state( hwnd );
619 if (!(old_style & WS_MAXIMIZE)) swpFlags |= SWP_STATECHANGED;
620 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y );
623 case SW_SHOWNOACTIVATE:
626 old_style = WIN_SetStyle( hwnd, 0, WS_MINIMIZE | WS_MAXIMIZE );
627 if (old_style & WS_MINIMIZE)
631 WINPOS_ShowIconTitle( hwnd, FALSE );
632 X11DRV_set_iconic_state( hwnd );
634 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
635 restore_max = (wndPtr->flags & WIN_RESTORE_MAX) != 0;
636 WIN_ReleasePtr( wndPtr );
639 /* Restore to maximized position */
640 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL);
641 WIN_SetStyle( hwnd, WS_MAXIMIZE, 0 );
642 swpFlags |= SWP_STATECHANGED;
643 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y );
647 else if (!(old_style & WS_MAXIMIZE)) break;
649 swpFlags |= SWP_STATECHANGED;
651 /* Restore to normal position */
653 *rect = wpl.rcNormalPosition;
654 rect->right -= rect->left;
655 rect->bottom -= rect->top;
664 /***********************************************************************
665 * ShowWindow (X11DRV.@)
667 BOOL X11DRV_ShowWindow( HWND hwnd, INT cmd )
671 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
672 BOOL wasVisible = (style & WS_VISIBLE) != 0;
673 BOOL showFlag = TRUE;
674 RECT newPos = {0, 0, 0, 0};
677 TRACE("hwnd=%p, cmd=%d, wasVisible %d\n", hwnd, cmd, wasVisible);
682 if (!wasVisible) return FALSE;
684 swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE;
685 if (hwnd != GetActiveWindow())
686 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
689 case SW_SHOWMINNOACTIVE:
690 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
693 case SW_FORCEMINIMIZE: /* FIXME: Does not work if thread is hung. */
694 if (style & WS_CHILD) swp |= SWP_NOACTIVATE | SWP_NOZORDER;
696 case SW_SHOWMINIMIZED:
697 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
698 swp |= WINPOS_MinMaximize( hwnd, cmd, &newPos );
699 if ((style & WS_MINIMIZE) && wasVisible) return TRUE;
702 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
703 if (!wasVisible) swp |= SWP_SHOWWINDOW;
704 swp |= SWP_FRAMECHANGED;
705 swp |= WINPOS_MinMaximize( hwnd, SW_MAXIMIZE, &newPos );
706 if ((style & WS_MAXIMIZE) && wasVisible) return TRUE;
710 swp |= SWP_NOACTIVATE | SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
711 if (style & WS_CHILD) swp |= SWP_NOZORDER;
714 if (wasVisible) return TRUE;
715 swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
716 if (style & WS_CHILD) swp |= SWP_NOACTIVATE | SWP_NOZORDER;
719 case SW_SHOWNOACTIVATE:
720 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
724 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
725 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
726 if (!wasVisible) swp |= SWP_SHOWWINDOW;
727 if (style & (WS_MINIMIZE | WS_MAXIMIZE))
729 swp |= SWP_FRAMECHANGED;
730 swp |= WINPOS_MinMaximize( hwnd, cmd, &newPos );
734 if (wasVisible) return TRUE;
735 swp |= SWP_NOSIZE | SWP_NOMOVE;
737 if (style & WS_CHILD && !(swp & SWP_STATECHANGED)) swp |= SWP_NOACTIVATE | SWP_NOZORDER;
741 if ((showFlag != wasVisible || cmd == SW_SHOWNA) && cmd != SW_SHOWMAXIMIZED && !(swp & SWP_STATECHANGED))
743 SendMessageW( hwnd, WM_SHOWWINDOW, showFlag, 0 );
744 if (!IsWindow( hwnd )) return wasVisible;
747 parent = GetAncestor( hwnd, GA_PARENT );
748 if (parent && !IsWindowVisible( parent ) && !(swp & SWP_STATECHANGED))
750 /* if parent is not visible simply toggle WS_VISIBLE and return */
751 if (showFlag) WIN_SetStyle( hwnd, WS_VISIBLE, 0 );
752 else WIN_SetStyle( hwnd, 0, WS_VISIBLE );
755 SetWindowPos( hwnd, HWND_TOP, newPos.left, newPos.top,
756 newPos.right, newPos.bottom, LOWORD(swp) );
762 /* FIXME: This will cause the window to be activated irrespective
763 * of whether it is owned by the same thread. Has to be done
767 if (hwnd == GetActiveWindow())
768 WINPOS_ActivateOtherWindow(hwnd);
770 /* Revert focus to parent */
772 if (hwnd == hFocus || IsChild(hwnd, hFocus))
774 HWND parent = GetAncestor(hwnd, GA_PARENT);
775 if (parent == GetDesktopWindow()) parent = 0;
780 if (IsIconic(hwnd)) WINPOS_ShowIconTitle( hwnd, TRUE );
782 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return wasVisible;
784 if (wndPtr->flags & WIN_NEED_SIZE)
786 /* should happen only in CreateWindowEx() */
787 int wParam = SIZE_RESTORED;
788 RECT client = wndPtr->rectClient;
790 wndPtr->flags &= ~WIN_NEED_SIZE;
791 if (wndPtr->dwStyle & WS_MAXIMIZE) wParam = SIZE_MAXIMIZED;
792 else if (wndPtr->dwStyle & WS_MINIMIZE) wParam = SIZE_MINIMIZED;
793 WIN_ReleasePtr( wndPtr );
795 SendMessageW( hwnd, WM_SIZE, wParam,
796 MAKELONG( client.right - client.left, client.bottom - client.top ));
797 SendMessageW( hwnd, WM_MOVE, 0, MAKELONG( client.left, client.top ));
799 else WIN_ReleasePtr( wndPtr );
801 /* if previous state was minimized Windows sets focus to the window */
802 if (style & WS_MINIMIZE) SetFocus( hwnd );
808 /**********************************************************************
811 void X11DRV_MapNotify( HWND hwnd, XEvent *event )
813 struct x11drv_win_data *data;
814 HWND hwndFocus = GetFocus();
817 if (!(data = X11DRV_get_win_data( hwnd ))) return;
819 if (!(win = WIN_GetPtr( hwnd ))) return;
821 if (data->managed && (win->dwStyle & WS_VISIBLE) && (win->dwStyle & WS_MINIMIZE))
824 unsigned int width, height, border, depth;
827 LONG style = WS_VISIBLE;
831 XGetGeometry( event->xmap.display, data->whole_window, &root, &x, &y, &width, &height,
833 XTranslateCoordinates( event->xmap.display, data->whole_window, root, 0, 0, &x, &y, &top );
837 rect.right = x + width;
838 rect.bottom = y + height;
839 OffsetRect( &rect, virtual_screen_rect.left, virtual_screen_rect.top );
840 X11DRV_X_to_window_rect( data, &rect );
842 invalidate_dce( hwnd, &data->window_rect );
844 if (win->flags & WIN_RESTORE_MAX) style |= WS_MAXIMIZE;
845 WIN_SetStyle( hwnd, style, WS_MINIMIZE );
846 WIN_ReleasePtr( win );
848 SendMessageW( hwnd, WM_SHOWWINDOW, SW_RESTORE, 0 );
849 data->lock_changes++;
850 SetWindowPos( hwnd, 0, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
851 SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED | SWP_STATECHANGED );
852 data->lock_changes--;
854 else WIN_ReleasePtr( win );
855 if (hwndFocus && IsChild( hwnd, hwndFocus )) X11DRV_SetFocus(hwndFocus); /* FIXME */
859 /**********************************************************************
862 void X11DRV_UnmapNotify( HWND hwnd, XEvent *event )
864 struct x11drv_win_data *data;
867 if (!(data = X11DRV_get_win_data( hwnd ))) return;
869 if (!(win = WIN_GetPtr( hwnd ))) return;
871 if ((win->dwStyle & WS_VISIBLE) && data->managed &&
872 X11DRV_is_window_rect_mapped( &win->rectWindow ))
874 if (win->dwStyle & WS_MAXIMIZE)
875 win->flags |= WIN_RESTORE_MAX;
876 else if (!(win->dwStyle & WS_MINIMIZE))
877 win->flags &= ~WIN_RESTORE_MAX;
879 WIN_SetStyle( hwnd, WS_MINIMIZE, WS_MAXIMIZE );
880 WIN_ReleasePtr( win );
883 SendMessageW( hwnd, WM_SHOWWINDOW, SW_MINIMIZE, 0 );
884 data->lock_changes++;
885 SetWindowPos( hwnd, 0, 0, 0, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON),
886 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_STATECHANGED );
887 data->lock_changes--;
889 else WIN_ReleasePtr( win );
892 struct desktop_resize_data
894 RECT old_screen_rect;
895 RECT old_virtual_rect;
898 static BOOL CALLBACK update_windows_on_desktop_resize( HWND hwnd, LPARAM lparam )
900 struct x11drv_win_data *data;
901 Display *display = thread_display();
902 struct desktop_resize_data *resize_data = (struct desktop_resize_data *)lparam;
905 if (!(data = X11DRV_get_win_data( hwnd ))) return TRUE;
907 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE)
909 /* update the full screen state */
910 update_wm_states( display, data, FALSE );
913 if (resize_data->old_virtual_rect.left != virtual_screen_rect.left) mask |= CWX;
914 if (resize_data->old_virtual_rect.top != virtual_screen_rect.top) mask |= CWY;
915 if (mask && data->whole_window)
917 XWindowChanges changes;
920 changes.x = data->whole_rect.left - virtual_screen_rect.left;
921 changes.y = data->whole_rect.top - virtual_screen_rect.top;
922 XReconfigureWMWindow( display, data->whole_window,
923 DefaultScreen(display), mask, &changes );
930 /***********************************************************************
931 * X11DRV_resize_desktop
933 void X11DRV_resize_desktop( unsigned int width, unsigned int height )
935 HWND hwnd = GetDesktopWindow();
936 struct x11drv_win_data *data;
937 struct desktop_resize_data resize_data;
939 SetRect( &resize_data.old_screen_rect, 0, 0, screen_width, screen_height );
940 resize_data.old_virtual_rect = virtual_screen_rect;
942 xinerama_init( width, height );
944 if (!(data = X11DRV_get_win_data( hwnd )))
946 SendMessageW( hwnd, WM_X11DRV_RESIZE_DESKTOP, 0, MAKELPARAM( width, height ) );
950 TRACE( "desktop %p change to (%dx%d)\n", hwnd, width, height );
951 SetWindowPos( hwnd, 0, virtual_screen_rect.left, virtual_screen_rect.top,
952 virtual_screen_rect.right - virtual_screen_rect.left,
953 virtual_screen_rect.bottom - virtual_screen_rect.top,
954 SWP_NOZORDER | SWP_NOACTIVATE );
955 SendMessageTimeoutW( HWND_BROADCAST, WM_DISPLAYCHANGE, screen_bpp,
956 MAKELPARAM( width, height ), SMTO_ABORTIFHUNG, 2000, NULL );
959 EnumWindows( update_windows_on_desktop_resize, (LPARAM)&resize_data );
963 /***********************************************************************
964 * X11DRV_ConfigureNotify
966 void X11DRV_ConfigureNotify( HWND hwnd, XEvent *xev )
968 XConfigureEvent *event = &xev->xconfigure;
969 struct x11drv_win_data *data;
972 int cx, cy, x = event->x, y = event->y;
975 if (!(data = X11DRV_get_win_data( hwnd ))) return;
979 if (!event->send_event) /* normal event, need to map coordinates to the root */
983 XTranslateCoordinates( event->display, data->whole_window, root_window,
984 0, 0, &x, &y, &child );
989 rect.right = x + event->width;
990 rect.bottom = y + event->height;
991 OffsetRect( &rect, virtual_screen_rect.left, virtual_screen_rect.top );
992 TRACE( "win %p new X rect %d,%d,%dx%d (event %d,%d,%dx%d)\n",
993 hwnd, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
994 event->x, event->y, event->width, event->height );
995 X11DRV_X_to_window_rect( data, &rect );
999 cx = rect.right - rect.left;
1000 cy = rect.bottom - rect.top;
1001 flags = SWP_NOACTIVATE | SWP_NOZORDER;
1003 /* Compare what has changed */
1005 GetWindowRect( hwnd, &rect );
1006 if (rect.left == x && rect.top == y) flags |= SWP_NOMOVE;
1008 TRACE( "%p moving from (%d,%d) to (%d,%d)\n",
1009 hwnd, rect.left, rect.top, x, y );
1011 if ((rect.right - rect.left == cx && rect.bottom - rect.top == cy) ||
1013 (IsRectEmpty( &rect ) && event->width == 1 && event->height == 1))
1015 if (flags & SWP_NOMOVE) return; /* if nothing changed, don't do anything */
1016 flags |= SWP_NOSIZE;
1019 TRACE( "%p resizing from (%dx%d) to (%dx%d)\n",
1020 hwnd, rect.right - rect.left, rect.bottom - rect.top, cx, cy );
1022 data->lock_changes++;
1023 SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
1024 data->lock_changes--;
1028 /***********************************************************************
1031 * Draw the frame used when moving or resizing window.
1033 * FIXME: This causes problems in Win95 mode. (why?)
1035 static void draw_moving_frame( HDC hdc, RECT *rect, BOOL thickframe )
1039 const int width = GetSystemMetrics(SM_CXFRAME);
1040 const int height = GetSystemMetrics(SM_CYFRAME);
1042 HBRUSH hbrush = SelectObject( hdc, GetStockObject( GRAY_BRUSH ) );
1043 PatBlt( hdc, rect->left, rect->top,
1044 rect->right - rect->left - width, height, PATINVERT );
1045 PatBlt( hdc, rect->left, rect->top + height, width,
1046 rect->bottom - rect->top - height, PATINVERT );
1047 PatBlt( hdc, rect->left + width, rect->bottom - 1,
1048 rect->right - rect->left - width, -height, PATINVERT );
1049 PatBlt( hdc, rect->right - 1, rect->top, -width,
1050 rect->bottom - rect->top - height, PATINVERT );
1051 SelectObject( hdc, hbrush );
1053 else DrawFocusRect( hdc, rect );
1057 /***********************************************************************
1060 * Initialization of a move or resize, when initiated from a menu choice.
1061 * Return hit test code for caption or sizing border.
1063 static LONG start_size_move( HWND hwnd, WPARAM wParam, POINT *capturePoint, LONG style )
1070 GetWindowRect( hwnd, &rectWindow );
1072 if ((wParam & 0xfff0) == SC_MOVE)
1074 /* Move pointer at the center of the caption */
1075 RECT rect = rectWindow;
1076 /* Note: to be exactly centered we should take the different types
1077 * of border into account, but it shouldn't make more than a few pixels
1078 * of difference so let's not bother with that */
1079 rect.top += GetSystemMetrics(SM_CYBORDER);
1080 if (style & WS_SYSMENU)
1081 rect.left += GetSystemMetrics(SM_CXSIZE) + 1;
1082 if (style & WS_MINIMIZEBOX)
1083 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1084 if (style & WS_MAXIMIZEBOX)
1085 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1086 pt.x = (rect.right + rect.left) / 2;
1087 pt.y = rect.top + GetSystemMetrics(SM_CYSIZE)/2;
1088 hittest = HTCAPTION;
1096 GetMessageW( &msg, 0, WM_KEYFIRST, WM_MOUSELAST );
1097 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
1103 hittest = SendMessageW( hwnd, WM_NCHITTEST, 0, MAKELONG( pt.x, pt.y ) );
1104 if ((hittest < HTLEFT) || (hittest > HTBOTTOMRIGHT)) hittest = 0;
1115 pt.x =(rectWindow.left+rectWindow.right)/2;
1116 pt.y = rectWindow.top + GetSystemMetrics(SM_CYFRAME) / 2;
1120 pt.x =(rectWindow.left+rectWindow.right)/2;
1121 pt.y = rectWindow.bottom - GetSystemMetrics(SM_CYFRAME) / 2;
1125 pt.x = rectWindow.left + GetSystemMetrics(SM_CXFRAME) / 2;
1126 pt.y =(rectWindow.top+rectWindow.bottom)/2;
1130 pt.x = rectWindow.right - GetSystemMetrics(SM_CXFRAME) / 2;
1131 pt.y =(rectWindow.top+rectWindow.bottom)/2;
1134 case VK_ESCAPE: return 0;
1140 SetCursorPos( pt.x, pt.y );
1141 SendMessageW( hwnd, WM_SETCURSOR, (WPARAM)hwnd, MAKELONG( hittest, WM_MOUSEMOVE ));
1146 /***********************************************************************
1147 * set_movesize_capture
1149 static void set_movesize_capture( HWND hwnd )
1153 SERVER_START_REQ( set_capture_window )
1156 req->flags = CAPTURE_MOVESIZE;
1157 if (!wine_server_call_err( req ))
1159 previous = reply->previous;
1160 hwnd = reply->full_handle;
1164 if (previous && previous != hwnd)
1165 SendMessageW( previous, WM_CAPTURECHANGED, 0, (LPARAM)hwnd );
1168 /***********************************************************************
1169 * X11DRV_WMMoveResizeWindow
1171 * Tells the window manager to initiate a move or resize operation.
1174 * http://freedesktop.org/Standards/wm-spec/1.3/ar01s04.html
1175 * or search for "_NET_WM_MOVERESIZE"
1177 static BOOL X11DRV_WMMoveResizeWindow( HWND hwnd, int x, int y, WPARAM wparam )
1179 WPARAM syscommand = wparam & 0xfff0;
1180 WPARAM hittest = wparam & 0x0f;
1183 Display *display = thread_display();
1185 if (syscommand == SC_MOVE)
1187 if (!hittest) dir = _NET_WM_MOVERESIZE_MOVE_KEYBOARD;
1188 else dir = _NET_WM_MOVERESIZE_MOVE;
1192 /* windows without WS_THICKFRAME are not resizable through the window manager */
1193 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_THICKFRAME)) return FALSE;
1197 case WMSZ_LEFT: dir = _NET_WM_MOVERESIZE_SIZE_LEFT; break;
1198 case WMSZ_RIGHT: dir = _NET_WM_MOVERESIZE_SIZE_RIGHT; break;
1199 case WMSZ_TOP: dir = _NET_WM_MOVERESIZE_SIZE_TOP; break;
1200 case WMSZ_TOPLEFT: dir = _NET_WM_MOVERESIZE_SIZE_TOPLEFT; break;
1201 case WMSZ_TOPRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT; break;
1202 case WMSZ_BOTTOM: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOM; break;
1203 case WMSZ_BOTTOMLEFT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT; break;
1204 case WMSZ_BOTTOMRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT; break;
1205 default: dir = _NET_WM_MOVERESIZE_SIZE_KEYBOARD; break;
1209 TRACE("hwnd %p, x %d, y %d, dir %d\n", hwnd, x, y, dir);
1211 xev.xclient.type = ClientMessage;
1212 xev.xclient.window = X11DRV_get_whole_window(hwnd);
1213 xev.xclient.message_type = x11drv_atom(_NET_WM_MOVERESIZE);
1214 xev.xclient.serial = 0;
1215 xev.xclient.display = display;
1216 xev.xclient.send_event = True;
1217 xev.xclient.format = 32;
1218 xev.xclient.data.l[0] = x; /* x coord */
1219 xev.xclient.data.l[1] = y; /* y coord */
1220 xev.xclient.data.l[2] = dir; /* direction */
1221 xev.xclient.data.l[3] = 1; /* button */
1222 xev.xclient.data.l[4] = 0; /* unused */
1224 /* need to ungrab the pointer that may have been automatically grabbed
1225 * with a ButtonPress event */
1227 XUngrabPointer( display, CurrentTime );
1228 XSendEvent(display, root_window, False, SubstructureNotifyMask, &xev);
1229 wine_tsx11_unlock();
1233 /***********************************************************************
1234 * SysCommandSizeMove (X11DRV.@)
1236 * Perform SC_MOVE and SC_SIZE commands.
1238 void X11DRV_SysCommandSizeMove( HWND hwnd, WPARAM wParam )
1241 RECT sizingRect, mouseRect, origRect;
1244 LONG hittest = (LONG)(wParam & 0x0f);
1245 WPARAM syscommand = wParam & 0xfff0;
1246 HCURSOR hDragCursor = 0, hOldCursor = 0;
1247 POINT minTrack, maxTrack;
1248 POINT capturePoint, pt;
1249 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
1250 BOOL thickframe = HAS_THICKFRAME( style );
1251 BOOL iconic = style & WS_MINIMIZE;
1253 DWORD dwPoint = GetMessagePos ();
1254 BOOL DragFullWindows = TRUE;
1255 Window parent_win, whole_win;
1256 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1257 struct x11drv_win_data *data;
1259 pt.x = (short)LOWORD(dwPoint);
1260 pt.y = (short)HIWORD(dwPoint);
1263 if (IsZoomed(hwnd) || !IsWindowVisible(hwnd)) return;
1265 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1267 TRACE("hwnd %p (%smanaged), command %04lx, hittest %d, pos %d,%d\n",
1268 hwnd, data->managed ? "" : "NOT ", syscommand, hittest, pt.x, pt.y);
1270 /* if we are managed then we let the WM do all the work */
1271 if (data->managed && X11DRV_WMMoveResizeWindow( hwnd, pt.x, pt.y, wParam )) return;
1273 if (syscommand == SC_MOVE)
1275 if (!hittest) hittest = start_size_move( hwnd, wParam, &capturePoint, style );
1276 if (!hittest) return;
1280 if ( hittest && (syscommand != SC_MOUSEMENU) )
1281 hittest += (HTLEFT - WMSZ_LEFT);
1284 set_movesize_capture( hwnd );
1285 hittest = start_size_move( hwnd, wParam, &capturePoint, style );
1288 set_movesize_capture(0);
1294 /* Get min/max info */
1296 WINPOS_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack );
1297 GetWindowRect( hwnd, &sizingRect );
1298 if (style & WS_CHILD)
1300 parent = GetParent(hwnd);
1301 /* make sizing rect relative to parent */
1302 MapWindowPoints( 0, parent, (POINT*)&sizingRect, 2 );
1303 GetClientRect( parent, &mouseRect );
1308 mouseRect = virtual_screen_rect;
1310 origRect = sizingRect;
1312 if (ON_LEFT_BORDER(hittest))
1314 mouseRect.left = max( mouseRect.left, sizingRect.right-maxTrack.x );
1315 mouseRect.right = min( mouseRect.right, sizingRect.right-minTrack.x );
1317 else if (ON_RIGHT_BORDER(hittest))
1319 mouseRect.left = max( mouseRect.left, sizingRect.left+minTrack.x );
1320 mouseRect.right = min( mouseRect.right, sizingRect.left+maxTrack.x );
1322 if (ON_TOP_BORDER(hittest))
1324 mouseRect.top = max( mouseRect.top, sizingRect.bottom-maxTrack.y );
1325 mouseRect.bottom = min( mouseRect.bottom,sizingRect.bottom-minTrack.y);
1327 else if (ON_BOTTOM_BORDER(hittest))
1329 mouseRect.top = max( mouseRect.top, sizingRect.top+minTrack.y );
1330 mouseRect.bottom = min( mouseRect.bottom, sizingRect.top+maxTrack.y );
1332 if (parent) MapWindowPoints( parent, 0, (LPPOINT)&mouseRect, 2 );
1334 /* Retrieve a default cache DC (without using the window style) */
1335 hdc = GetDCEx( parent, 0, DCX_CACHE );
1337 if( iconic ) /* create a cursor for dragging */
1339 hDragCursor = (HCURSOR)GetClassLongPtrW( hwnd, GCLP_HICON);
1340 if( !hDragCursor ) hDragCursor = (HCURSOR)SendMessageW( hwnd, WM_QUERYDRAGICON, 0, 0L);
1341 if( !hDragCursor ) iconic = FALSE;
1344 /* repaint the window before moving it around */
1345 RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN );
1347 SendMessageW( hwnd, WM_ENTERSIZEMOVE, 0, 0 );
1348 set_movesize_capture( hwnd );
1350 /* we only allow disabling the full window drag for child windows, or in desktop mode */
1351 /* otherwise we'd need to grab the server and we want to avoid that */
1352 if (parent || (root_window != DefaultRootWindow(gdi_display)))
1353 SystemParametersInfoA(SPI_GETDRAGFULLWINDOWS, 0, &DragFullWindows, 0);
1355 whole_win = X11DRV_get_whole_window( GetAncestor(hwnd,GA_ROOT) );
1356 parent_win = parent ? X11DRV_get_whole_window( GetAncestor(parent,GA_ROOT) ) : root_window;
1359 XGrabPointer( thread_data->display, whole_win, False,
1360 PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
1361 GrabModeAsync, GrabModeAsync, parent_win, None, CurrentTime );
1362 wine_tsx11_unlock();
1363 thread_data->grab_window = whole_win;
1369 if (!GetMessageW( &msg, 0, 0, 0 )) break;
1370 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
1372 /* Exit on button-up, Return, or Esc */
1373 if ((msg.message == WM_LBUTTONUP) ||
1374 ((msg.message == WM_KEYDOWN) &&
1375 ((msg.wParam == VK_RETURN) || (msg.wParam == VK_ESCAPE)))) break;
1377 if ((msg.message != WM_KEYDOWN) && (msg.message != WM_MOUSEMOVE))
1379 TranslateMessage( &msg );
1380 DispatchMessageW( &msg );
1381 continue; /* We are not interested in other messages */
1386 if (msg.message == WM_KEYDOWN) switch(msg.wParam)
1388 case VK_UP: pt.y -= 8; break;
1389 case VK_DOWN: pt.y += 8; break;
1390 case VK_LEFT: pt.x -= 8; break;
1391 case VK_RIGHT: pt.x += 8; break;
1394 pt.x = max( pt.x, mouseRect.left );
1395 pt.x = min( pt.x, mouseRect.right );
1396 pt.y = max( pt.y, mouseRect.top );
1397 pt.y = min( pt.y, mouseRect.bottom );
1399 dx = pt.x - capturePoint.x;
1400 dy = pt.y - capturePoint.y;
1408 if( iconic ) /* ok, no system popup tracking */
1410 hOldCursor = SetCursor(hDragCursor);
1412 WINPOS_ShowIconTitle( hwnd, FALSE );
1414 else if(!DragFullWindows)
1415 draw_moving_frame( hdc, &sizingRect, thickframe );
1418 if (msg.message == WM_KEYDOWN) SetCursorPos( pt.x, pt.y );
1421 RECT newRect = sizingRect;
1422 WPARAM wpSizingHit = 0;
1424 if (hittest == HTCAPTION) OffsetRect( &newRect, dx, dy );
1425 if (ON_LEFT_BORDER(hittest)) newRect.left += dx;
1426 else if (ON_RIGHT_BORDER(hittest)) newRect.right += dx;
1427 if (ON_TOP_BORDER(hittest)) newRect.top += dy;
1428 else if (ON_BOTTOM_BORDER(hittest)) newRect.bottom += dy;
1429 if(!iconic && !DragFullWindows) draw_moving_frame( hdc, &sizingRect, thickframe );
1432 /* determine the hit location */
1433 if (hittest >= HTLEFT && hittest <= HTBOTTOMRIGHT)
1434 wpSizingHit = WMSZ_LEFT + (hittest - HTLEFT);
1435 SendMessageW( hwnd, WM_SIZING, wpSizingHit, (LPARAM)&newRect );
1439 if(!DragFullWindows)
1440 draw_moving_frame( hdc, &newRect, thickframe );
1442 SetWindowPos( hwnd, 0, newRect.left, newRect.top,
1443 newRect.right - newRect.left,
1444 newRect.bottom - newRect.top,
1445 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
1447 sizingRect = newRect;
1452 set_movesize_capture(0);
1455 if( moved ) /* restore cursors, show icon title later on */
1457 ShowCursor( FALSE );
1458 SetCursor( hOldCursor );
1461 else if (moved && !DragFullWindows)
1463 draw_moving_frame( hdc, &sizingRect, thickframe );
1464 /* make sure the moving frame is erased before we move the window */
1466 XFlush( gdi_display );
1467 wine_tsx11_unlock();
1470 ReleaseDC( parent, hdc );
1473 XUngrabPointer( thread_data->display, CurrentTime );
1474 wine_tsx11_unlock();
1475 thread_data->grab_window = None;
1477 if (HOOK_CallHooks( WH_CBT, HCBT_MOVESIZE, (WPARAM)hwnd, (LPARAM)&sizingRect, TRUE ))
1480 SendMessageW( hwnd, WM_EXITSIZEMOVE, 0, 0 );
1481 SendMessageW( hwnd, WM_SETVISIBLE, !IsIconic(hwnd), 0L);
1483 /* window moved or resized */
1486 /* if the moving/resizing isn't canceled call SetWindowPos
1487 * with the new position or the new size of the window
1489 if (!((msg.message == WM_KEYDOWN) && (msg.wParam == VK_ESCAPE)) )
1491 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
1492 if(!DragFullWindows)
1493 SetWindowPos( hwnd, 0, sizingRect.left, sizingRect.top,
1494 sizingRect.right - sizingRect.left,
1495 sizingRect.bottom - sizingRect.top,
1496 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
1499 { /* restore previous size/position */
1501 SetWindowPos( hwnd, 0, origRect.left, origRect.top,
1502 origRect.right - origRect.left,
1503 origRect.bottom - origRect.top,
1504 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
1510 /* Single click brings up the system menu when iconized */
1514 if(style & WS_SYSMENU )
1515 SendMessageW( hwnd, WM_SYSCOMMAND,
1516 SC_MOUSEMENU + HTSYSMENU, MAKELONG(pt.x,pt.y));
1518 else WINPOS_ShowIconTitle( hwnd, TRUE );