Try to always keep the server window Z-order in sync with the X11 one
[wine/hacks.git] / dlls / x11drv / winpos.c
blobd5469702f94077af31ec43b57a7d51e3e753b1d8
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "config.h"
24 #include <X11/Xlib.h>
25 #ifdef HAVE_LIBXSHAPE
26 #include <X11/IntrinsicP.h>
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 "ntstatus.h"
37 #include "wownt32.h"
38 #include "wine/wingdi16.h"
40 #include "x11drv.h"
41 #include "win.h"
42 #include "winpos.h"
43 #include "dce.h"
45 #include "wine/server.h"
46 #include "wine/debug.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
50 #define SWP_AGG_NOPOSCHANGE \
51 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_NOZORDER)
52 #define SWP_AGG_STATUSFLAGS \
53 (SWP_AGG_NOPOSCHANGE | SWP_FRAMECHANGED | SWP_HIDEWINDOW | SWP_SHOWWINDOW)
55 #define SWP_EX_NOCOPY 0x0001
56 #define SWP_EX_PAINTSELF 0x0002
57 #define SWP_EX_NONCLIENT 0x0004
59 #define HAS_THICKFRAME(style) \
60 (((style) & WS_THICKFRAME) && \
61 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
63 #define ON_LEFT_BORDER(hit) \
64 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
65 #define ON_RIGHT_BORDER(hit) \
66 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
67 #define ON_TOP_BORDER(hit) \
68 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
69 #define ON_BOTTOM_BORDER(hit) \
70 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
72 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
73 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
74 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
75 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
76 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
77 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
78 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
79 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
80 #define _NET_WM_MOVERESIZE_MOVE 8 /* movement only */
81 #define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9 /* size via keyboard */
82 #define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10 /* move via keyboard */
85 /***********************************************************************
86 * get_server_visible_region
88 static HRGN get_server_visible_region( HWND hwnd, UINT flags )
90 RGNDATA *data;
91 NTSTATUS status;
92 HRGN ret = 0;
93 size_t size = 256;
97 if (!(data = HeapAlloc( GetProcessHeap(), 0, sizeof(*data) + size - 1 ))) return 0;
98 SERVER_START_REQ( get_visible_region )
100 req->window = hwnd;
101 req->flags = flags;
102 wine_server_set_reply( req, data->Buffer, size );
103 if (!(status = wine_server_call( req )))
105 size_t reply_size = wine_server_reply_size( reply );
106 data->rdh.dwSize = sizeof(data->rdh);
107 data->rdh.iType = RDH_RECTANGLES;
108 data->rdh.nCount = reply_size / sizeof(RECT);
109 data->rdh.nRgnSize = reply_size;
110 ret = ExtCreateRegion( NULL, size, data );
112 else size = reply->total_size;
114 SERVER_END_REQ;
115 HeapFree( GetProcessHeap(), 0, data );
116 } while (status == STATUS_BUFFER_OVERFLOW);
118 if (status) SetLastError( RtlNtStatusToDosError(status) );
119 return ret;
123 /***********************************************************************
124 * get_top_clipping_window
126 * Get the top window to clip against (i.e. the top parent that has
127 * an associated X window).
129 static HWND get_top_clipping_window( HWND hwnd )
131 HWND ret = GetAncestor( hwnd, GA_ROOT );
132 if (!ret) ret = GetDesktopWindow();
133 return ret;
137 /***********************************************************************
138 * X11DRV_Expose
140 void X11DRV_Expose( HWND hwnd, XEvent *xev )
142 XExposeEvent *event = &xev->xexpose;
143 RECT rect;
144 struct x11drv_win_data *data;
145 int flags = RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN;
147 TRACE( "win %p (%lx) %d,%d %dx%d\n",
148 hwnd, event->window, event->x, event->y, event->width, event->height );
150 if (!(data = X11DRV_get_win_data( hwnd ))) return;
152 rect.left = event->x;
153 rect.top = event->y;
154 rect.right = rect.left + event->width;
155 rect.bottom = rect.top + event->height;
157 if (rect.left < data->client_rect.left ||
158 rect.top < data->client_rect.top ||
159 rect.right > data->client_rect.right ||
160 rect.bottom > data->client_rect.bottom) flags |= RDW_FRAME;
162 SERVER_START_REQ( update_window_zorder )
164 req->window = hwnd;
165 req->rect.left = rect.left + data->whole_rect.left;
166 req->rect.top = rect.top + data->whole_rect.top;
167 req->rect.right = rect.right + data->whole_rect.left;
168 req->rect.bottom = rect.bottom + data->whole_rect.top;
169 wine_server_call( req );
171 SERVER_END_REQ;
173 /* make position relative to client area instead of window */
174 OffsetRect( &rect, -data->client_rect.left, -data->client_rect.top );
175 RedrawWindow( hwnd, &rect, 0, flags );
179 /***********************************************************************
180 * GetDC (X11DRV.@)
182 * Set the drawable, origin and dimensions for the DC associated to
183 * a given window.
185 BOOL X11DRV_GetDC( HWND hwnd, HDC hdc, HRGN hrgn, DWORD flags )
187 HWND top = get_top_clipping_window( hwnd );
188 struct x11drv_escape_set_drawable escape;
189 struct x11drv_win_data *data;
191 escape.mode = IncludeInferiors;
192 /* don't clip siblings if using parent clip region */
193 if (flags & DCX_PARENTCLIP) flags &= ~DCX_CLIPSIBLINGS;
195 if (top != hwnd || !(data = X11DRV_get_win_data( hwnd )))
197 POINT client_offset;
199 if (flags & DCX_WINDOW)
201 RECT rect;
202 GetWindowRect( hwnd, &rect );
203 escape.org.x = rect.left;
204 escape.org.y = rect.top;
205 MapWindowPoints( 0, top, &escape.org, 1 );
206 escape.drawable_org.x = rect.left - escape.org.x;
207 escape.drawable_org.y = rect.top - escape.org.y;
209 else
211 escape.org.x = escape.org.y = 0;
212 escape.drawable_org.x = escape.drawable_org.y = 0;
213 MapWindowPoints( hwnd, top, &escape.org, 1 );
214 MapWindowPoints( top, 0, &escape.drawable_org, 1 );
217 /* now make origins relative to the X window and not the client area */
218 client_offset = X11DRV_get_client_area_offset( top );
219 escape.org.x += client_offset.x;
220 escape.org.y += client_offset.y;
221 escape.drawable_org.x -= client_offset.x;
222 escape.drawable_org.y -= client_offset.y;
223 escape.drawable = X11DRV_get_whole_window( top );
225 else
227 if (IsIconic( hwnd ))
229 escape.drawable = data->icon_window ? data->icon_window : data->whole_window;
230 escape.org.x = 0;
231 escape.org.y = 0;
232 escape.drawable_org = escape.org;
233 MapWindowPoints( hwnd, 0, &escape.drawable_org, 1 );
235 else
237 escape.drawable = data->whole_window;
238 escape.drawable_org.x = data->whole_rect.left;
239 escape.drawable_org.y = data->whole_rect.top;
240 if (flags & DCX_WINDOW)
242 escape.org.x = data->window_rect.left - data->whole_rect.left;
243 escape.org.y = data->window_rect.top - data->whole_rect.top;
245 else
247 escape.org.x = data->client_rect.left;
248 escape.org.y = data->client_rect.top;
253 escape.code = X11DRV_SET_DRAWABLE;
254 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
256 if (flags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN) ||
257 SetHookFlags16( HDC_16(hdc), DCHF_VALIDATEVISRGN )) /* DC was dirty */
259 /* need to recompute the visible region */
260 HRGN visRgn = get_server_visible_region( hwnd, flags );
262 if (flags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN))
263 CombineRgn( visRgn, visRgn, hrgn, (flags & DCX_INTERSECTRGN) ? RGN_AND : RGN_DIFF );
265 SelectVisRgn16( HDC_16(hdc), HRGN_16(visRgn) );
266 DeleteObject( visRgn );
268 return TRUE;
272 /***********************************************************************
273 * ReleaseDC (X11DRV.@)
275 void X11DRV_ReleaseDC( HWND hwnd, HDC hdc )
277 struct x11drv_escape_set_drawable escape;
279 escape.code = X11DRV_SET_DRAWABLE;
280 escape.drawable = root_window;
281 escape.mode = IncludeInferiors;
282 escape.org.x = escape.org.y = 0;
283 escape.drawable_org.x = escape.drawable_org.y = 0;
285 ExtEscape( hdc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL );
289 /***********************************************************************
290 * SWP_DoWinPosChanging
292 static BOOL SWP_DoWinPosChanging( WINDOWPOS* pWinpos, RECT* pNewWindowRect, RECT* pNewClientRect )
294 WND *wndPtr;
296 /* Send WM_WINDOWPOSCHANGING message */
298 if (!(pWinpos->flags & SWP_NOSENDCHANGING))
299 SendMessageW( pWinpos->hwnd, WM_WINDOWPOSCHANGING, 0, (LPARAM)pWinpos );
301 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return FALSE;
303 /* Calculate new position and size */
305 *pNewWindowRect = wndPtr->rectWindow;
306 *pNewClientRect = (wndPtr->dwStyle & WS_MINIMIZE) ? wndPtr->rectWindow
307 : wndPtr->rectClient;
309 if (!(pWinpos->flags & SWP_NOSIZE))
311 pNewWindowRect->right = pNewWindowRect->left + pWinpos->cx;
312 pNewWindowRect->bottom = pNewWindowRect->top + pWinpos->cy;
314 if (!(pWinpos->flags & SWP_NOMOVE))
316 pNewWindowRect->left = pWinpos->x;
317 pNewWindowRect->top = pWinpos->y;
318 pNewWindowRect->right += pWinpos->x - wndPtr->rectWindow.left;
319 pNewWindowRect->bottom += pWinpos->y - wndPtr->rectWindow.top;
321 OffsetRect( pNewClientRect, pWinpos->x - wndPtr->rectWindow.left,
322 pWinpos->y - wndPtr->rectWindow.top );
324 pWinpos->flags |= SWP_NOCLIENTMOVE | SWP_NOCLIENTSIZE;
326 TRACE( "hwnd %p, after %p, swp %d,%d %dx%d flags %08x\n",
327 pWinpos->hwnd, pWinpos->hwndInsertAfter, pWinpos->x, pWinpos->y,
328 pWinpos->cx, pWinpos->cy, pWinpos->flags );
329 TRACE( "current %s style %08lx new %s\n",
330 wine_dbgstr_rect( &wndPtr->rectWindow ), wndPtr->dwStyle,
331 wine_dbgstr_rect( pNewWindowRect ));
333 WIN_ReleasePtr( wndPtr );
334 return TRUE;
338 /***********************************************************************
339 * get_valid_rects
341 * Compute the valid rects from the old and new client rect and WVR_* flags.
342 * Helper for WM_NCCALCSIZE handling.
344 static inline void get_valid_rects( const RECT *old_client, const RECT *new_client, UINT flags,
345 RECT *valid )
347 int cx, cy;
349 if (flags & WVR_REDRAW)
351 SetRectEmpty( &valid[0] );
352 SetRectEmpty( &valid[1] );
353 return;
356 if (flags & WVR_VALIDRECTS)
358 if (!IntersectRect( &valid[0], &valid[0], new_client ) ||
359 !IntersectRect( &valid[1], &valid[1], old_client ))
361 SetRectEmpty( &valid[0] );
362 SetRectEmpty( &valid[1] );
363 return;
365 flags = WVR_ALIGNLEFT | WVR_ALIGNTOP;
367 else
369 valid[0] = *new_client;
370 valid[1] = *old_client;
373 /* make sure the rectangles have the same size */
374 cx = min( valid[0].right - valid[0].left, valid[1].right - valid[1].left );
375 cy = min( valid[0].bottom - valid[0].top, valid[1].bottom - valid[1].top );
377 if (flags & WVR_ALIGNBOTTOM)
379 valid[0].top = valid[0].bottom - cy;
380 valid[1].top = valid[1].bottom - cy;
382 else
384 valid[0].bottom = valid[0].top + cy;
385 valid[1].bottom = valid[1].top + cy;
387 if (flags & WVR_ALIGNRIGHT)
389 valid[0].left = valid[0].right - cx;
390 valid[1].left = valid[1].right - cx;
392 else
394 valid[0].right = valid[0].left + cx;
395 valid[1].right = valid[1].left + cx;
400 /***********************************************************************
401 * SWP_DoNCCalcSize
403 static UINT SWP_DoNCCalcSize( WINDOWPOS* pWinpos, const RECT* pNewWindowRect, RECT* pNewClientRect,
404 RECT *validRects )
406 UINT wvrFlags = 0;
407 WND *wndPtr;
409 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
411 /* Send WM_NCCALCSIZE message to get new client area */
412 if( (pWinpos->flags & (SWP_FRAMECHANGED | SWP_NOSIZE)) != SWP_NOSIZE )
414 NCCALCSIZE_PARAMS params;
415 WINDOWPOS winposCopy;
417 params.rgrc[0] = *pNewWindowRect;
418 params.rgrc[1] = wndPtr->rectWindow;
419 params.rgrc[2] = wndPtr->rectClient;
420 params.lppos = &winposCopy;
421 winposCopy = *pWinpos;
422 WIN_ReleasePtr( wndPtr );
424 wvrFlags = SendMessageW( pWinpos->hwnd, WM_NCCALCSIZE, TRUE, (LPARAM)&params );
426 *pNewClientRect = params.rgrc[0];
428 if (!(wndPtr = WIN_GetPtr( pWinpos->hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
430 TRACE( "hwnd %p old win %s old client %s new win %s new client %s\n", pWinpos->hwnd,
431 wine_dbgstr_rect(&wndPtr->rectWindow), wine_dbgstr_rect(&wndPtr->rectClient),
432 wine_dbgstr_rect(pNewWindowRect), wine_dbgstr_rect(pNewClientRect) );
434 if( pNewClientRect->left != wndPtr->rectClient.left ||
435 pNewClientRect->top != wndPtr->rectClient.top )
436 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
438 if( (pNewClientRect->right - pNewClientRect->left !=
439 wndPtr->rectClient.right - wndPtr->rectClient.left))
440 pWinpos->flags &= ~SWP_NOCLIENTSIZE;
441 else
442 wvrFlags &= ~WVR_HREDRAW;
444 if (pNewClientRect->bottom - pNewClientRect->top !=
445 wndPtr->rectClient.bottom - wndPtr->rectClient.top)
446 pWinpos->flags &= ~SWP_NOCLIENTSIZE;
447 else
448 wvrFlags &= ~WVR_VREDRAW;
450 validRects[0] = params.rgrc[1];
451 validRects[1] = params.rgrc[2];
453 else
455 if (!(pWinpos->flags & SWP_NOMOVE) &&
456 (pNewClientRect->left != wndPtr->rectClient.left ||
457 pNewClientRect->top != wndPtr->rectClient.top))
458 pWinpos->flags &= ~SWP_NOCLIENTMOVE;
461 if (pWinpos->flags & (SWP_NOCOPYBITS | SWP_NOREDRAW | SWP_SHOWWINDOW | SWP_HIDEWINDOW))
463 SetRectEmpty( &validRects[0] );
464 SetRectEmpty( &validRects[1] );
466 else get_valid_rects( &wndPtr->rectClient, pNewClientRect, wvrFlags, validRects );
468 WIN_ReleasePtr( wndPtr );
469 return wvrFlags;
473 /***********************************************************************
474 * SWP_DoOwnedPopups
476 * fix Z order taking into account owned popups -
477 * basically we need to maintain them above the window that owns them
479 * FIXME: hide/show owned popups when owner visibility changes.
481 static HWND SWP_DoOwnedPopups(HWND hwnd, HWND hwndInsertAfter)
483 HWND *list = NULL;
484 HWND owner = GetWindow( hwnd, GW_OWNER );
485 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
487 WARN("(%p) hInsertAfter = %p\n", hwnd, hwndInsertAfter );
489 if ((style & WS_POPUP) && owner)
491 /* make sure this popup stays above the owner */
493 HWND hwndLocalPrev = HWND_TOP;
495 if( hwndInsertAfter != HWND_TOP )
497 if ((list = WIN_ListChildren( GetDesktopWindow() )))
499 int i;
500 for (i = 0; list[i]; i++)
502 if (list[i] == owner) break;
503 if (list[i] != hwnd) hwndLocalPrev = list[i];
504 if (hwndLocalPrev == hwndInsertAfter) break;
506 hwndInsertAfter = hwndLocalPrev;
510 else if (style & WS_CHILD) return hwndInsertAfter;
512 if (!list) list = WIN_ListChildren( GetDesktopWindow() );
513 if (list)
515 int i;
516 for (i = 0; list[i]; i++)
518 if (list[i] == hwnd) break;
519 if ((GetWindowLongW( list[i], GWL_STYLE ) & WS_POPUP) &&
520 GetWindow( list[i], GW_OWNER ) == hwnd)
522 SetWindowPos( list[i], hwndInsertAfter, 0, 0, 0, 0,
523 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE |
524 SWP_NOSENDCHANGING | SWP_DEFERERASE );
525 hwndInsertAfter = list[i];
528 HeapFree( GetProcessHeap(), 0, list );
531 return hwndInsertAfter;
535 /* fix redundant flags and values in the WINDOWPOS structure */
536 static BOOL fixup_flags( WINDOWPOS *winpos )
538 HWND parent;
539 WND *wndPtr = WIN_GetPtr( winpos->hwnd );
540 BOOL ret = TRUE;
542 if (!wndPtr || wndPtr == WND_OTHER_PROCESS)
544 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
545 return FALSE;
547 winpos->hwnd = wndPtr->hwndSelf; /* make it a full handle */
549 /* Finally make sure that all coordinates are valid */
550 if (winpos->x < -32768) winpos->x = -32768;
551 else if (winpos->x > 32767) winpos->x = 32767;
552 if (winpos->y < -32768) winpos->y = -32768;
553 else if (winpos->y > 32767) winpos->y = 32767;
555 if (winpos->cx < 0) winpos->cx = 0;
556 else if (winpos->cx > 32767) winpos->cx = 32767;
557 if (winpos->cy < 0) winpos->cy = 0;
558 else if (winpos->cy > 32767) winpos->cy = 32767;
560 parent = GetAncestor( winpos->hwnd, GA_PARENT );
561 if (!IsWindowVisible( parent )) winpos->flags |= SWP_NOREDRAW;
563 if (wndPtr->dwStyle & WS_VISIBLE) winpos->flags &= ~SWP_SHOWWINDOW;
564 else
566 winpos->flags &= ~SWP_HIDEWINDOW;
567 if (!(winpos->flags & SWP_SHOWWINDOW)) winpos->flags |= SWP_NOREDRAW;
570 if ((wndPtr->rectWindow.right - wndPtr->rectWindow.left == winpos->cx) &&
571 (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top == winpos->cy))
572 winpos->flags |= SWP_NOSIZE; /* Already the right size */
574 if ((wndPtr->rectWindow.left == winpos->x) && (wndPtr->rectWindow.top == winpos->y))
575 winpos->flags |= SWP_NOMOVE; /* Already the right position */
577 if ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD)
579 if (!(winpos->flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW))) /* Bring to the top when activating */
581 winpos->flags &= ~SWP_NOZORDER;
582 winpos->hwndInsertAfter = HWND_TOP;
586 /* Check hwndInsertAfter */
587 if (winpos->flags & SWP_NOZORDER) goto done;
589 /* fix sign extension */
590 if (winpos->hwndInsertAfter == (HWND)0xffff) winpos->hwndInsertAfter = HWND_TOPMOST;
591 else if (winpos->hwndInsertAfter == (HWND)0xfffe) winpos->hwndInsertAfter = HWND_NOTOPMOST;
593 /* FIXME: TOPMOST not supported yet */
594 if ((winpos->hwndInsertAfter == HWND_TOPMOST) ||
595 (winpos->hwndInsertAfter == HWND_NOTOPMOST)) winpos->hwndInsertAfter = HWND_TOP;
597 /* hwndInsertAfter must be a sibling of the window */
598 if (winpos->hwndInsertAfter == HWND_TOP)
600 if (GetWindow(winpos->hwnd, GW_HWNDFIRST) == winpos->hwnd)
601 winpos->flags |= SWP_NOZORDER;
603 else if (winpos->hwndInsertAfter == HWND_BOTTOM)
605 if (GetWindow(winpos->hwnd, GW_HWNDLAST) == winpos->hwnd)
606 winpos->flags |= SWP_NOZORDER;
608 else
610 if (GetAncestor( winpos->hwndInsertAfter, GA_PARENT ) != parent) ret = FALSE;
611 else
613 /* don't need to change the Zorder of hwnd if it's already inserted
614 * after hwndInsertAfter or when inserting hwnd after itself.
616 if ((winpos->hwnd == winpos->hwndInsertAfter) ||
617 (winpos->hwnd == GetWindow( winpos->hwndInsertAfter, GW_HWNDNEXT )))
618 winpos->flags |= SWP_NOZORDER;
621 done:
622 WIN_ReleasePtr( wndPtr );
623 return ret;
627 /***********************************************************************
628 * SetWindowStyle (X11DRV.@)
630 * Update the X state of a window to reflect a style change
632 void X11DRV_SetWindowStyle( HWND hwnd, DWORD old_style )
634 Display *display = thread_display();
635 struct x11drv_win_data *data;
636 DWORD new_style, changed;
638 if (hwnd == GetDesktopWindow()) return;
639 if (!(data = X11DRV_get_win_data( hwnd ))) return;
641 new_style = GetWindowLongW( hwnd, GWL_STYLE );
642 changed = new_style ^ old_style;
644 if (changed & WS_VISIBLE)
646 if (data->whole_window && X11DRV_is_window_rect_mapped( &data->window_rect ))
648 if (new_style & WS_VISIBLE)
650 TRACE( "mapping win %p\n", hwnd );
651 X11DRV_sync_window_style( display, data );
652 X11DRV_set_wm_hints( display, data );
653 wine_tsx11_lock();
654 XMapWindow( display, data->whole_window );
655 wine_tsx11_unlock();
657 /* we don't unmap windows, that causes trouble with the window manager */
659 DCE_InvalidateDCE( hwnd, &data->window_rect );
662 if (changed & WS_DISABLED)
664 if (data->whole_window && data->managed)
666 XWMHints *wm_hints;
667 wine_tsx11_lock();
668 if (!(wm_hints = XGetWMHints( display, data->whole_window )))
669 wm_hints = XAllocWMHints();
670 if (wm_hints)
672 wm_hints->flags |= InputHint;
673 wm_hints->input = !(new_style & WS_DISABLED);
674 XSetWMHints( display, data->whole_window, wm_hints );
675 XFree(wm_hints);
677 wine_tsx11_unlock();
683 /***********************************************************************
684 * X11DRV_set_window_pos
686 * Set a window position and Z order.
688 BOOL X11DRV_set_window_pos( HWND hwnd, HWND insert_after, const RECT *rectWindow,
689 const RECT *rectClient, UINT swp_flags, const RECT *valid_rects )
691 struct x11drv_win_data *data;
692 RECT new_whole_rect;
693 WND *win;
694 DWORD old_style, new_style;
695 BOOL ret;
697 if (!(data = X11DRV_get_win_data( hwnd ))) return FALSE;
699 new_whole_rect = *rectWindow;
700 X11DRV_window_to_X_rect( data, &new_whole_rect );
702 if (!IsRectEmpty( &valid_rects[0] ))
704 int x_offset = 0, y_offset = 0;
706 if (data->whole_window)
708 /* the X server will move the bits for us */
709 x_offset = data->whole_rect.left - new_whole_rect.left;
710 y_offset = data->whole_rect.top - new_whole_rect.top;
713 if (x_offset != valid_rects[1].left - valid_rects[0].left ||
714 y_offset != valid_rects[1].top - valid_rects[0].top)
716 /* FIXME: should copy the window bits here */
717 valid_rects = NULL;
721 if (!(win = WIN_GetPtr( hwnd ))) return FALSE;
722 if (win == WND_OTHER_PROCESS)
724 if (IsWindow( hwnd )) ERR( "cannot set rectangles of other process window %p\n", hwnd );
725 return FALSE;
727 old_style = win->dwStyle;
728 SERVER_START_REQ( set_window_pos )
730 req->handle = hwnd;
731 req->previous = insert_after;
732 req->flags = swp_flags & ~SWP_WINE_NOHOSTMOVE;
733 req->window.left = rectWindow->left;
734 req->window.top = rectWindow->top;
735 req->window.right = rectWindow->right;
736 req->window.bottom = rectWindow->bottom;
737 req->client.left = rectClient->left;
738 req->client.top = rectClient->top;
739 req->client.right = rectClient->right;
740 req->client.bottom = rectClient->bottom;
741 if (memcmp( rectWindow, &new_whole_rect, sizeof(RECT) ) || !IsRectEmpty( &valid_rects[0] ))
743 wine_server_add_data( req, &new_whole_rect, sizeof(new_whole_rect) );
744 if (!IsRectEmpty( &valid_rects[0] ))
745 wine_server_add_data( req, valid_rects, 2 * sizeof(*valid_rects) );
747 ret = !wine_server_call( req );
748 new_style = reply->new_style;
750 SERVER_END_REQ;
752 if (ret)
754 Display *display = thread_display();
756 /* invalidate DCEs */
758 if ((((swp_flags & SWP_AGG_NOPOSCHANGE) != SWP_AGG_NOPOSCHANGE) && (new_style & WS_VISIBLE)) ||
759 (swp_flags & (SWP_HIDEWINDOW | SWP_SHOWWINDOW)))
761 RECT rect;
762 UnionRect( &rect, rectWindow, &win->rectWindow );
763 DCE_InvalidateDCE( hwnd, &rect );
766 win->rectWindow = *rectWindow;
767 win->rectClient = *rectClient;
768 win->dwStyle = new_style;
769 data->window_rect = *rectWindow;
771 TRACE( "win %p window %s client %s style %08lx\n",
772 hwnd, wine_dbgstr_rect(rectWindow), wine_dbgstr_rect(rectClient), new_style );
774 /* FIXME: copy the valid bits */
776 if (data->whole_window && !(swp_flags & SWP_WINE_NOHOSTMOVE))
778 if ((old_style & WS_VISIBLE) && !(new_style & WS_VISIBLE))
780 /* window got hidden, unmap it */
781 TRACE( "unmapping win %p\n", hwnd );
782 wine_tsx11_lock();
783 XUnmapWindow( display, data->whole_window );
784 wine_tsx11_unlock();
786 else if ((new_style & WS_VISIBLE) && !X11DRV_is_window_rect_mapped( rectWindow ))
788 /* resizing to zero size or off screen -> unmap */
789 TRACE( "unmapping zero size or off-screen win %p\n", hwnd );
790 wine_tsx11_lock();
791 XUnmapWindow( display, data->whole_window );
792 wine_tsx11_unlock();
796 X11DRV_sync_window_position( display, data, swp_flags, rectClient, &new_whole_rect );
798 if (data->whole_window && !(swp_flags & SWP_WINE_NOHOSTMOVE))
800 if (!(old_style & WS_VISIBLE) && (new_style & WS_VISIBLE))
802 /* window got shown, map it */
803 if (X11DRV_is_window_rect_mapped( rectWindow ))
805 TRACE( "mapping win %p\n", hwnd );
806 X11DRV_sync_window_style( display, data );
807 X11DRV_set_wm_hints( display, data );
808 wine_tsx11_lock();
809 XMapWindow( display, data->whole_window );
810 wine_tsx11_unlock();
813 else if ((new_style & WS_VISIBLE) && X11DRV_is_window_rect_mapped( rectWindow ))
815 /* resizing from zero size to non-zero -> map */
816 TRACE( "mapping non zero size or off-screen win %p\n", hwnd );
817 wine_tsx11_lock();
818 XMapWindow( display, data->whole_window );
819 wine_tsx11_unlock();
821 wine_tsx11_lock();
822 XFlush( display ); /* FIXME: should not be necessary */
823 wine_tsx11_unlock();
826 WIN_ReleasePtr( win );
827 return ret;
831 /***********************************************************************
832 * SetWindowPos (X11DRV.@)
834 BOOL X11DRV_SetWindowPos( WINDOWPOS *winpos )
836 RECT newWindowRect, newClientRect, valid_rects[2];
837 UINT orig_flags;
839 TRACE( "hwnd %p, after %p, swp %d,%d %dx%d flags %08x\n",
840 winpos->hwnd, winpos->hwndInsertAfter, winpos->x, winpos->y,
841 winpos->cx, winpos->cy, winpos->flags);
843 orig_flags = winpos->flags;
844 winpos->flags &= ~SWP_WINE_NOHOSTMOVE;
846 /* Check window handle */
847 if (winpos->hwnd == GetDesktopWindow()) return FALSE;
849 /* First make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
850 if (!(winpos->flags & SWP_NOMOVE))
852 if (winpos->x < -32768) winpos->x = -32768;
853 else if (winpos->x > 32767) winpos->x = 32767;
854 if (winpos->y < -32768) winpos->y = -32768;
855 else if (winpos->y > 32767) winpos->y = 32767;
857 if (!(winpos->flags & SWP_NOSIZE))
859 if (winpos->cx < 0) winpos->cx = 0;
860 else if (winpos->cx > 32767) winpos->cx = 32767;
861 if (winpos->cy < 0) winpos->cy = 0;
862 else if (winpos->cy > 32767) winpos->cy = 32767;
865 if (!SWP_DoWinPosChanging( winpos, &newWindowRect, &newClientRect )) return FALSE;
867 /* Fix redundant flags */
868 if (!fixup_flags( winpos )) return FALSE;
870 if((winpos->flags & (SWP_NOZORDER | SWP_HIDEWINDOW | SWP_SHOWWINDOW)) != SWP_NOZORDER)
872 if (GetAncestor( winpos->hwnd, GA_PARENT ) == GetDesktopWindow())
873 winpos->hwndInsertAfter = SWP_DoOwnedPopups( winpos->hwnd, winpos->hwndInsertAfter );
876 /* Common operations */
878 SWP_DoNCCalcSize( winpos, &newWindowRect, &newClientRect, valid_rects );
880 if (!X11DRV_set_window_pos( winpos->hwnd, winpos->hwndInsertAfter,
881 &newWindowRect, &newClientRect, orig_flags, valid_rects ))
882 return FALSE;
884 if( winpos->flags & SWP_HIDEWINDOW )
885 HideCaret(winpos->hwnd);
886 else if (winpos->flags & SWP_SHOWWINDOW)
887 ShowCaret(winpos->hwnd);
889 if (!(winpos->flags & (SWP_NOACTIVATE|SWP_HIDEWINDOW)))
891 /* child windows get WM_CHILDACTIVATE message */
892 if ((GetWindowLongW( winpos->hwnd, GWL_STYLE ) & (WS_CHILD | WS_POPUP)) == WS_CHILD)
893 SendMessageA( winpos->hwnd, WM_CHILDACTIVATE, 0, 0 );
894 else
895 SetForegroundWindow( winpos->hwnd );
898 /* And last, send the WM_WINDOWPOSCHANGED message */
900 TRACE("\tstatus flags = %04x\n", winpos->flags & SWP_AGG_STATUSFLAGS);
902 if (((winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOPOSCHANGE))
904 /* WM_WINDOWPOSCHANGED is sent even if SWP_NOSENDCHANGING is set
905 and always contains final window position.
907 winpos->x = newWindowRect.left;
908 winpos->y = newWindowRect.top;
909 winpos->cx = newWindowRect.right - newWindowRect.left;
910 winpos->cy = newWindowRect.bottom - newWindowRect.top;
911 SendMessageW( winpos->hwnd, WM_WINDOWPOSCHANGED, 0, (LPARAM)winpos );
914 return TRUE;
918 /***********************************************************************
919 * WINPOS_FindIconPos
921 * Find a suitable place for an iconic window.
923 static POINT WINPOS_FindIconPos( WND* wndPtr, POINT pt )
925 RECT rectParent;
926 HWND *list;
927 short x, y, xspacing, yspacing;
929 GetClientRect( wndPtr->parent, &rectParent );
930 if ((pt.x >= rectParent.left) && (pt.x + GetSystemMetrics(SM_CXICON) < rectParent.right) &&
931 (pt.y >= rectParent.top) && (pt.y + GetSystemMetrics(SM_CYICON) < rectParent.bottom))
932 return pt; /* The icon already has a suitable position */
934 xspacing = GetSystemMetrics(SM_CXICONSPACING);
935 yspacing = GetSystemMetrics(SM_CYICONSPACING);
937 list = WIN_ListChildren( wndPtr->parent );
938 y = rectParent.bottom;
939 for (;;)
941 x = rectParent.left;
944 /* Check if another icon already occupies this spot */
945 /* FIXME: this is completely inefficient */
946 if (list)
948 int i;
949 WND *childPtr;
951 for (i = 0; list[i]; i++)
953 if (list[i] == wndPtr->hwndSelf) continue;
954 if (!IsIconic( list[i] )) continue;
955 if (!(childPtr = WIN_GetPtr( list[i] )) || childPtr == WND_OTHER_PROCESS)
956 continue;
957 if ((childPtr->rectWindow.left < x + xspacing) &&
958 (childPtr->rectWindow.right >= x) &&
959 (childPtr->rectWindow.top <= y) &&
960 (childPtr->rectWindow.bottom > y - yspacing))
962 WIN_ReleasePtr( childPtr );
963 break; /* There's a window in there */
965 WIN_ReleasePtr( childPtr );
967 if (list[i])
969 /* found something here, try next spot */
970 x += xspacing;
971 continue;
975 /* No window was found, so it's OK for us */
976 pt.x = x + (xspacing - GetSystemMetrics(SM_CXICON)) / 2;
977 pt.y = y - (yspacing + GetSystemMetrics(SM_CYICON)) / 2;
978 HeapFree( GetProcessHeap(), 0, list );
979 return pt;
981 } while(x <= rectParent.right-xspacing);
982 y -= yspacing;
990 UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect )
992 WND *wndPtr;
993 UINT swpFlags = 0;
994 POINT size;
995 LONG old_style;
996 WINDOWPLACEMENT wpl;
998 TRACE("%p %u\n", hwnd, cmd );
1000 wpl.length = sizeof(wpl);
1001 GetWindowPlacement( hwnd, &wpl );
1003 if (HOOK_CallHooks( WH_CBT, HCBT_MINMAX, (WPARAM)hwnd, cmd, TRUE ))
1004 return SWP_NOSIZE | SWP_NOMOVE;
1006 if (IsIconic( hwnd ))
1008 if (cmd == SW_MINIMIZE) return SWP_NOSIZE | SWP_NOMOVE;
1009 if (!SendMessageA( hwnd, WM_QUERYOPEN, 0, 0 )) return SWP_NOSIZE | SWP_NOMOVE;
1010 swpFlags |= SWP_NOCOPYBITS;
1013 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
1015 size.x = wndPtr->rectWindow.left;
1016 size.y = wndPtr->rectWindow.top;
1018 switch( cmd )
1020 case SW_MINIMIZE:
1021 if( wndPtr->dwStyle & WS_MAXIMIZE) wndPtr->flags |= WIN_RESTORE_MAX;
1022 else wndPtr->flags &= ~WIN_RESTORE_MAX;
1024 WIN_SetStyle( hwnd, WS_MINIMIZE, WS_MAXIMIZE );
1026 X11DRV_set_iconic_state( hwnd );
1028 wpl.ptMinPosition = WINPOS_FindIconPos( wndPtr, wpl.ptMinPosition );
1030 SetRect( rect, wpl.ptMinPosition.x, wpl.ptMinPosition.y,
1031 GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON) );
1032 swpFlags |= SWP_NOCOPYBITS;
1033 break;
1035 case SW_MAXIMIZE:
1036 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL );
1038 old_style = WIN_SetStyle( hwnd, WS_MAXIMIZE, WS_MINIMIZE );
1039 if (old_style & WS_MINIMIZE)
1041 WINPOS_ShowIconTitle( hwnd, FALSE );
1042 X11DRV_set_iconic_state( hwnd );
1044 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y );
1045 break;
1047 case SW_RESTORE:
1048 old_style = WIN_SetStyle( hwnd, 0, WS_MINIMIZE | WS_MAXIMIZE );
1049 if (old_style & WS_MINIMIZE)
1051 WINPOS_ShowIconTitle( hwnd, FALSE );
1052 X11DRV_set_iconic_state( hwnd );
1054 if( wndPtr->flags & WIN_RESTORE_MAX)
1056 /* Restore to maximized position */
1057 WINPOS_GetMinMaxInfo( hwnd, &size, &wpl.ptMaxPosition, NULL, NULL);
1058 WIN_SetStyle( hwnd, WS_MAXIMIZE, 0 );
1059 SetRect( rect, wpl.ptMaxPosition.x, wpl.ptMaxPosition.y, size.x, size.y );
1060 break;
1063 else if (!(old_style & WS_MAXIMIZE)) break;
1065 /* Restore to normal position */
1067 *rect = wpl.rcNormalPosition;
1068 rect->right -= rect->left;
1069 rect->bottom -= rect->top;
1071 break;
1074 WIN_ReleaseWndPtr( wndPtr );
1075 return swpFlags;
1079 /***********************************************************************
1080 * ShowWindow (X11DRV.@)
1082 BOOL X11DRV_ShowWindow( HWND hwnd, INT cmd )
1084 WND* wndPtr = WIN_FindWndPtr( hwnd );
1085 BOOL wasVisible, showFlag;
1086 RECT newPos = {0, 0, 0, 0};
1087 UINT swp = 0;
1089 if (!wndPtr) return FALSE;
1090 hwnd = wndPtr->hwndSelf; /* make it a full handle */
1092 wasVisible = (wndPtr->dwStyle & WS_VISIBLE) != 0;
1094 TRACE("hwnd=%p, cmd=%d, wasVisible %d\n", hwnd, cmd, wasVisible);
1096 switch(cmd)
1098 case SW_HIDE:
1099 if (!wasVisible) goto END;
1100 swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER;
1101 break;
1103 case SW_SHOWMINNOACTIVE:
1104 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1105 /* fall through */
1106 case SW_SHOWMINIMIZED:
1107 case SW_FORCEMINIMIZE: /* FIXME: Does not work if thread is hung. */
1108 swp |= SWP_SHOWWINDOW;
1109 /* fall through */
1110 case SW_MINIMIZE:
1111 swp |= SWP_FRAMECHANGED;
1112 if( !(wndPtr->dwStyle & WS_MINIMIZE) )
1113 swp |= WINPOS_MinMaximize( hwnd, SW_MINIMIZE, &newPos );
1114 else swp |= SWP_NOSIZE | SWP_NOMOVE;
1115 break;
1117 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
1118 swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
1119 if( !(wndPtr->dwStyle & WS_MAXIMIZE) )
1120 swp |= WINPOS_MinMaximize( hwnd, SW_MAXIMIZE, &newPos );
1121 else swp |= SWP_NOSIZE | SWP_NOMOVE;
1122 break;
1124 case SW_SHOWNA:
1125 swp |= SWP_NOACTIVATE | SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
1126 if( wndPtr->dwStyle & WS_CHILD) swp |= SWP_NOZORDER;
1127 break;
1128 case SW_SHOW:
1129 if (wasVisible) goto END;
1131 swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
1132 break;
1134 case SW_RESTORE:
1135 swp |= SWP_FRAMECHANGED;
1136 /* fall through */
1137 case SW_SHOWNOACTIVATE:
1138 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1139 /* fall through */
1140 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
1141 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
1142 swp |= SWP_SHOWWINDOW;
1144 if( wndPtr->dwStyle & (WS_MINIMIZE | WS_MAXIMIZE) )
1145 swp |= WINPOS_MinMaximize( hwnd, SW_RESTORE, &newPos );
1146 else swp |= SWP_NOSIZE | SWP_NOMOVE;
1147 break;
1150 showFlag = (cmd != SW_HIDE);
1151 if (showFlag != wasVisible || cmd == SW_SHOWNA)
1153 SendMessageW( hwnd, WM_SHOWWINDOW, showFlag, 0 );
1154 if (!IsWindow( hwnd )) goto END;
1157 /* ShowWindow won't activate a not being maximized child window */
1158 if ((wndPtr->dwStyle & WS_CHILD) && cmd != SW_MAXIMIZE)
1159 swp |= SWP_NOACTIVATE | SWP_NOZORDER;
1161 SetWindowPos( hwnd, HWND_TOP, newPos.left, newPos.top,
1162 newPos.right, newPos.bottom, LOWORD(swp) );
1163 if (cmd == SW_HIDE)
1165 HWND hFocus;
1167 /* FIXME: This will cause the window to be activated irrespective
1168 * of whether it is owned by the same thread. Has to be done
1169 * asynchronously.
1172 if (hwnd == GetActiveWindow())
1173 WINPOS_ActivateOtherWindow(hwnd);
1175 /* Revert focus to parent */
1176 hFocus = GetFocus();
1177 if (hwnd == hFocus || IsChild(hwnd, hFocus))
1179 HWND parent = GetAncestor(hwnd, GA_PARENT);
1180 if (parent == GetDesktopWindow()) parent = 0;
1181 SetFocus(parent);
1184 if (!IsWindow( hwnd )) goto END;
1185 else if( wndPtr->dwStyle & WS_MINIMIZE ) WINPOS_ShowIconTitle( hwnd, TRUE );
1187 if (wndPtr->flags & WIN_NEED_SIZE)
1189 /* should happen only in CreateWindowEx() */
1190 int wParam = SIZE_RESTORED;
1192 wndPtr->flags &= ~WIN_NEED_SIZE;
1193 if (wndPtr->dwStyle & WS_MAXIMIZE) wParam = SIZE_MAXIMIZED;
1194 else if (wndPtr->dwStyle & WS_MINIMIZE) wParam = SIZE_MINIMIZED;
1195 SendMessageA( hwnd, WM_SIZE, wParam,
1196 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
1197 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
1198 SendMessageA( hwnd, WM_MOVE, 0,
1199 MAKELONG(wndPtr->rectClient.left, wndPtr->rectClient.top) );
1202 END:
1203 WIN_ReleaseWndPtr(wndPtr);
1204 return wasVisible;
1208 /**********************************************************************
1209 * X11DRV_MapNotify
1211 void X11DRV_MapNotify( HWND hwnd, XEvent *event )
1213 struct x11drv_win_data *data;
1214 HWND hwndFocus = GetFocus();
1215 WND *win;
1217 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1219 if (!(win = WIN_GetPtr( hwnd ))) return;
1221 if (data->managed && (win->dwStyle & WS_VISIBLE) && (win->dwStyle & WS_MINIMIZE))
1223 int x, y;
1224 unsigned int width, height, border, depth;
1225 Window root, top;
1226 RECT rect;
1227 LONG style = WS_VISIBLE;
1229 /* FIXME: hack */
1230 wine_tsx11_lock();
1231 XGetGeometry( event->xmap.display, data->whole_window, &root, &x, &y, &width, &height,
1232 &border, &depth );
1233 XTranslateCoordinates( event->xmap.display, data->whole_window, root, 0, 0, &x, &y, &top );
1234 wine_tsx11_unlock();
1235 rect.left = x;
1236 rect.top = y;
1237 rect.right = x + width;
1238 rect.bottom = y + height;
1239 X11DRV_X_to_window_rect( data, &rect );
1241 DCE_InvalidateDCE( hwnd, &data->window_rect );
1243 if (win->flags & WIN_RESTORE_MAX) style |= WS_MAXIMIZE;
1244 WIN_SetStyle( hwnd, style, WS_MINIMIZE );
1245 WIN_ReleasePtr( win );
1247 SendMessageA( hwnd, WM_SHOWWINDOW, SW_RESTORE, 0 );
1248 SetWindowPos( hwnd, 0, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
1249 SWP_NOZORDER | SWP_WINE_NOHOSTMOVE );
1251 else WIN_ReleasePtr( win );
1252 if (hwndFocus && IsChild( hwnd, hwndFocus )) X11DRV_SetFocus(hwndFocus); /* FIXME */
1256 /**********************************************************************
1257 * X11DRV_UnmapNotify
1259 void X11DRV_UnmapNotify( HWND hwnd, XEvent *event )
1261 struct x11drv_win_data *data;
1262 WND *win;
1264 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1266 if (!(win = WIN_GetPtr( hwnd ))) return;
1268 if ((win->dwStyle & WS_VISIBLE) && data->managed &&
1269 X11DRV_is_window_rect_mapped( &win->rectWindow ))
1271 if (win->dwStyle & WS_MAXIMIZE)
1272 win->flags |= WIN_RESTORE_MAX;
1273 else
1274 win->flags &= ~WIN_RESTORE_MAX;
1276 WIN_SetStyle( hwnd, WS_MINIMIZE, WS_MAXIMIZE );
1277 WIN_ReleasePtr( win );
1279 EndMenu();
1280 SendMessageA( hwnd, WM_SHOWWINDOW, SW_MINIMIZE, 0 );
1281 SetWindowPos( hwnd, 0, 0, 0, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON),
1282 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_WINE_NOHOSTMOVE );
1284 else WIN_ReleasePtr( win );
1288 /***********************************************************************
1289 * X11DRV_handle_desktop_resize
1291 void X11DRV_handle_desktop_resize( unsigned int width, unsigned int height )
1293 RECT rect;
1294 HWND hwnd = GetDesktopWindow();
1296 screen_width = width;
1297 screen_height = height;
1298 TRACE("desktop %p change to (%dx%d)\n", hwnd, width, height);
1299 SetRect( &rect, 0, 0, width, height );
1300 X11DRV_set_window_pos( hwnd, 0, &rect, &rect, SWP_NOZORDER|SWP_NOMOVE|SWP_WINE_NOHOSTMOVE, NULL );
1301 SendMessageTimeoutW( HWND_BROADCAST, WM_DISPLAYCHANGE, screen_depth,
1302 MAKELPARAM( width, height ), SMTO_ABORTIFHUNG, 2000, NULL );
1306 /***********************************************************************
1307 * X11DRV_ConfigureNotify
1309 void X11DRV_ConfigureNotify( HWND hwnd, XEvent *xev )
1311 XConfigureEvent *event = &xev->xconfigure;
1312 struct x11drv_win_data *data;
1313 RECT rect;
1314 UINT flags;
1315 int cx, cy, x = event->x, y = event->y;
1317 if (!hwnd) return;
1318 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1320 /* Get geometry */
1322 if (!event->send_event) /* normal event, need to map coordinates to the root */
1324 Window child;
1325 wine_tsx11_lock();
1326 XTranslateCoordinates( event->display, data->whole_window, root_window,
1327 0, 0, &x, &y, &child );
1328 wine_tsx11_unlock();
1330 rect.left = x;
1331 rect.top = y;
1332 rect.right = x + event->width;
1333 rect.bottom = y + event->height;
1334 TRACE( "win %p new X rect %ld,%ld,%ldx%ld (event %d,%d,%dx%d)\n",
1335 hwnd, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
1336 event->x, event->y, event->width, event->height );
1337 X11DRV_X_to_window_rect( data, &rect );
1339 x = rect.left;
1340 y = rect.top;
1341 cx = rect.right - rect.left;
1342 cy = rect.bottom - rect.top;
1343 flags = SWP_NOACTIVATE | SWP_NOZORDER | SWP_WINE_NOHOSTMOVE;
1345 /* Compare what has changed */
1347 GetWindowRect( hwnd, &rect );
1348 if (rect.left == x && rect.top == y) flags |= SWP_NOMOVE;
1349 else
1350 TRACE( "%p moving from (%ld,%ld) to (%d,%d)\n",
1351 hwnd, rect.left, rect.top, x, y );
1353 if ((rect.right - rect.left == cx && rect.bottom - rect.top == cy) ||
1354 IsIconic(hwnd) ||
1355 (IsRectEmpty( &rect ) && cx == 1 && cy == 1))
1357 if (flags & SWP_NOMOVE) return; /* if nothing changed, don't do anything */
1358 flags |= SWP_NOSIZE;
1360 else
1361 TRACE( "%p resizing from (%ldx%ld) to (%dx%d)\n",
1362 hwnd, rect.right - rect.left, rect.bottom - rect.top, cx, cy );
1364 SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
1368 /***********************************************************************
1369 * SetWindowRgn (X11DRV.@)
1371 * Assign specified region to window (for non-rectangular windows)
1373 int X11DRV_SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL redraw )
1375 struct x11drv_win_data *data;
1377 if (!(data = X11DRV_get_win_data( hwnd )))
1379 if (IsWindow( hwnd ))
1380 FIXME( "not supported on other thread window %p\n", hwnd );
1381 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1382 return FALSE;
1385 #ifdef HAVE_LIBXSHAPE
1386 if (data->whole_window)
1388 Display *display = thread_display();
1390 if (!hrgn)
1392 wine_tsx11_lock();
1393 XShapeCombineMask( display, data->whole_window,
1394 ShapeBounding, 0, 0, None, ShapeSet );
1395 wine_tsx11_unlock();
1397 else
1399 RGNDATA *pRegionData = X11DRV_GetRegionData( hrgn, 0 );
1400 if (pRegionData)
1402 wine_tsx11_lock();
1403 XShapeCombineRectangles( display, data->whole_window, ShapeBounding,
1404 data->window_rect.left - data->whole_rect.left,
1405 data->window_rect.top - data->whole_rect.top,
1406 (XRectangle *)pRegionData->Buffer,
1407 pRegionData->rdh.nCount,
1408 ShapeSet, YXBanded );
1409 wine_tsx11_unlock();
1410 HeapFree(GetProcessHeap(), 0, pRegionData);
1414 #endif /* HAVE_LIBXSHAPE */
1416 return TRUE;
1420 /***********************************************************************
1421 * draw_moving_frame
1423 * Draw the frame used when moving or resizing window.
1425 * FIXME: This causes problems in Win95 mode. (why?)
1427 static void draw_moving_frame( HDC hdc, RECT *rect, BOOL thickframe )
1429 if (thickframe)
1431 const int width = GetSystemMetrics(SM_CXFRAME);
1432 const int height = GetSystemMetrics(SM_CYFRAME);
1434 HBRUSH hbrush = SelectObject( hdc, GetStockObject( GRAY_BRUSH ) );
1435 PatBlt( hdc, rect->left, rect->top,
1436 rect->right - rect->left - width, height, PATINVERT );
1437 PatBlt( hdc, rect->left, rect->top + height, width,
1438 rect->bottom - rect->top - height, PATINVERT );
1439 PatBlt( hdc, rect->left + width, rect->bottom - 1,
1440 rect->right - rect->left - width, -height, PATINVERT );
1441 PatBlt( hdc, rect->right - 1, rect->top, -width,
1442 rect->bottom - rect->top - height, PATINVERT );
1443 SelectObject( hdc, hbrush );
1445 else DrawFocusRect( hdc, rect );
1449 /***********************************************************************
1450 * start_size_move
1452 * Initialisation of a move or resize, when initiatied from a menu choice.
1453 * Return hit test code for caption or sizing border.
1455 static LONG start_size_move( HWND hwnd, WPARAM wParam, POINT *capturePoint, LONG style )
1457 LONG hittest = 0;
1458 POINT pt;
1459 MSG msg;
1460 RECT rectWindow;
1462 GetWindowRect( hwnd, &rectWindow );
1464 if ((wParam & 0xfff0) == SC_MOVE)
1466 /* Move pointer at the center of the caption */
1467 RECT rect = rectWindow;
1468 /* Note: to be exactly centered we should take the different types
1469 * of border into account, but it shouldn't make more that a few pixels
1470 * of difference so let's not bother with that */
1471 rect.top += GetSystemMetrics(SM_CYBORDER);
1472 if (style & WS_SYSMENU)
1473 rect.left += GetSystemMetrics(SM_CXSIZE) + 1;
1474 if (style & WS_MINIMIZEBOX)
1475 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1476 if (style & WS_MAXIMIZEBOX)
1477 rect.right -= GetSystemMetrics(SM_CXSIZE) + 1;
1478 pt.x = (rect.right + rect.left) / 2;
1479 pt.y = rect.top + GetSystemMetrics(SM_CYSIZE)/2;
1480 hittest = HTCAPTION;
1481 *capturePoint = pt;
1483 else /* SC_SIZE */
1485 while(!hittest)
1487 GetMessageW( &msg, 0, WM_KEYFIRST, WM_MOUSELAST );
1488 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
1490 switch(msg.message)
1492 case WM_MOUSEMOVE:
1493 pt = msg.pt;
1494 hittest = SendMessageW( hwnd, WM_NCHITTEST, 0, MAKELONG( pt.x, pt.y ) );
1495 if ((hittest < HTLEFT) || (hittest > HTBOTTOMRIGHT)) hittest = 0;
1496 break;
1498 case WM_LBUTTONUP:
1499 return 0;
1501 case WM_KEYDOWN:
1502 switch(msg.wParam)
1504 case VK_UP:
1505 hittest = HTTOP;
1506 pt.x =(rectWindow.left+rectWindow.right)/2;
1507 pt.y = rectWindow.top + GetSystemMetrics(SM_CYFRAME) / 2;
1508 break;
1509 case VK_DOWN:
1510 hittest = HTBOTTOM;
1511 pt.x =(rectWindow.left+rectWindow.right)/2;
1512 pt.y = rectWindow.bottom - GetSystemMetrics(SM_CYFRAME) / 2;
1513 break;
1514 case VK_LEFT:
1515 hittest = HTLEFT;
1516 pt.x = rectWindow.left + GetSystemMetrics(SM_CXFRAME) / 2;
1517 pt.y =(rectWindow.top+rectWindow.bottom)/2;
1518 break;
1519 case VK_RIGHT:
1520 hittest = HTRIGHT;
1521 pt.x = rectWindow.right - GetSystemMetrics(SM_CXFRAME) / 2;
1522 pt.y =(rectWindow.top+rectWindow.bottom)/2;
1523 break;
1524 case VK_RETURN:
1525 case VK_ESCAPE: return 0;
1529 *capturePoint = pt;
1531 SetCursorPos( pt.x, pt.y );
1532 SendMessageW( hwnd, WM_SETCURSOR, (WPARAM)hwnd, MAKELONG( hittest, WM_MOUSEMOVE ));
1533 return hittest;
1537 /***********************************************************************
1538 * set_movesize_capture
1540 static void set_movesize_capture( HWND hwnd )
1542 HWND previous = 0;
1544 SERVER_START_REQ( set_capture_window )
1546 req->handle = hwnd;
1547 req->flags = CAPTURE_MOVESIZE;
1548 if (!wine_server_call_err( req ))
1550 previous = reply->previous;
1551 hwnd = reply->full_handle;
1554 SERVER_END_REQ;
1555 if (previous && previous != hwnd)
1556 SendMessageW( previous, WM_CAPTURECHANGED, 0, (LPARAM)hwnd );
1559 /***********************************************************************
1560 * X11DRV_WMMoveResizeWindow
1562 * Tells the window manager to initiate a move or resize operation.
1564 * SEE
1565 * http://freedesktop.org/Standards/wm-spec/1.3/ar01s04.html
1566 * or search for "_NET_WM_MOVERESIZE"
1568 static void X11DRV_WMMoveResizeWindow( HWND hwnd, int x, int y, int dir )
1570 XEvent xev;
1571 Display *display = thread_display();
1573 xev.xclient.type = ClientMessage;
1574 xev.xclient.window = X11DRV_get_whole_window(hwnd);
1575 xev.xclient.message_type = x11drv_atom(_NET_WM_MOVERESIZE);
1576 xev.xclient.serial = 0;
1577 xev.xclient.display = display;
1578 xev.xclient.send_event = True;
1579 xev.xclient.format = 32;
1580 xev.xclient.data.l[0] = x; /* x coord */
1581 xev.xclient.data.l[1] = y; /* y coord */
1582 xev.xclient.data.l[2] = dir; /* direction */
1583 xev.xclient.data.l[3] = 1; /* button */
1584 xev.xclient.data.l[4] = 0; /* unused */
1586 /* need to ungrab the pointer that may have been automatically grabbed
1587 * with a ButtonPress event */
1588 wine_tsx11_lock();
1589 XUngrabPointer( display, CurrentTime );
1590 XSendEvent(display, root_window, False, SubstructureNotifyMask, &xev);
1591 wine_tsx11_unlock();
1594 /***********************************************************************
1595 * SysCommandSizeMove (X11DRV.@)
1597 * Perform SC_MOVE and SC_SIZE commands.
1599 void X11DRV_SysCommandSizeMove( HWND hwnd, WPARAM wParam )
1601 MSG msg;
1602 RECT sizingRect, mouseRect, origRect;
1603 HDC hdc;
1604 HWND parent;
1605 LONG hittest = (LONG)(wParam & 0x0f);
1606 WPARAM syscommand = wParam & 0xfff0;
1607 HCURSOR hDragCursor = 0, hOldCursor = 0;
1608 POINT minTrack, maxTrack;
1609 POINT capturePoint, pt;
1610 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
1611 BOOL thickframe = HAS_THICKFRAME( style );
1612 BOOL iconic = style & WS_MINIMIZE;
1613 BOOL moved = FALSE;
1614 DWORD dwPoint = GetMessagePos ();
1615 BOOL DragFullWindows = FALSE;
1616 BOOL grab;
1617 Window parent_win, whole_win;
1618 Display *old_gdi_display = NULL;
1619 struct x11drv_thread_data *thread_data = x11drv_thread_data();
1620 struct x11drv_win_data *data;
1622 pt.x = (short)LOWORD(dwPoint);
1623 pt.y = (short)HIWORD(dwPoint);
1624 capturePoint = pt;
1626 if (IsZoomed(hwnd) || !IsWindowVisible(hwnd)) return;
1628 if (!(data = X11DRV_get_win_data( hwnd ))) return;
1630 /* if we are managed then we let the WM do all the work */
1631 if (data->managed)
1633 int dir;
1634 if (syscommand == SC_MOVE)
1636 if (!hittest) dir = _NET_WM_MOVERESIZE_MOVE_KEYBOARD;
1637 else dir = _NET_WM_MOVERESIZE_MOVE;
1639 else if (!hittest) dir = _NET_WM_MOVERESIZE_SIZE_KEYBOARD;
1640 else
1641 switch (hittest)
1643 case WMSZ_LEFT: dir = _NET_WM_MOVERESIZE_SIZE_LEFT; break;
1644 case WMSZ_RIGHT: dir = _NET_WM_MOVERESIZE_SIZE_RIGHT; break;
1645 case WMSZ_TOP: dir = _NET_WM_MOVERESIZE_SIZE_TOP; break;
1646 case WMSZ_TOPLEFT: dir = _NET_WM_MOVERESIZE_SIZE_TOPLEFT; break;
1647 case WMSZ_TOPRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_TOPRIGHT; break;
1648 case WMSZ_BOTTOM: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOM; break;
1649 case WMSZ_BOTTOMLEFT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT; break;
1650 case WMSZ_BOTTOMRIGHT: dir = _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT; break;
1651 default:
1652 ERR("Invalid hittest value: %ld\n", hittest);
1653 dir = _NET_WM_MOVERESIZE_SIZE_KEYBOARD;
1655 X11DRV_WMMoveResizeWindow( hwnd, pt.x, pt.y, dir );
1656 return;
1659 SystemParametersInfoA(SPI_GETDRAGFULLWINDOWS, 0, &DragFullWindows, 0);
1661 if (syscommand == SC_MOVE)
1663 if (!hittest) hittest = start_size_move( hwnd, wParam, &capturePoint, style );
1664 if (!hittest) return;
1666 else /* SC_SIZE */
1668 if ( hittest && (syscommand != SC_MOUSEMENU) )
1669 hittest += (HTLEFT - WMSZ_LEFT);
1670 else
1672 set_movesize_capture( hwnd );
1673 hittest = start_size_move( hwnd, wParam, &capturePoint, style );
1674 if (!hittest)
1676 set_movesize_capture(0);
1677 return;
1682 /* Get min/max info */
1684 WINPOS_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack );
1685 GetWindowRect( hwnd, &sizingRect );
1686 if (style & WS_CHILD)
1688 parent = GetParent(hwnd);
1689 /* make sizing rect relative to parent */
1690 MapWindowPoints( 0, parent, (POINT*)&sizingRect, 2 );
1691 GetClientRect( parent, &mouseRect );
1693 else
1695 parent = 0;
1696 SetRect(&mouseRect, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
1698 origRect = sizingRect;
1700 if (ON_LEFT_BORDER(hittest))
1702 mouseRect.left = max( mouseRect.left, sizingRect.right-maxTrack.x );
1703 mouseRect.right = min( mouseRect.right, sizingRect.right-minTrack.x );
1705 else if (ON_RIGHT_BORDER(hittest))
1707 mouseRect.left = max( mouseRect.left, sizingRect.left+minTrack.x );
1708 mouseRect.right = min( mouseRect.right, sizingRect.left+maxTrack.x );
1710 if (ON_TOP_BORDER(hittest))
1712 mouseRect.top = max( mouseRect.top, sizingRect.bottom-maxTrack.y );
1713 mouseRect.bottom = min( mouseRect.bottom,sizingRect.bottom-minTrack.y);
1715 else if (ON_BOTTOM_BORDER(hittest))
1717 mouseRect.top = max( mouseRect.top, sizingRect.top+minTrack.y );
1718 mouseRect.bottom = min( mouseRect.bottom, sizingRect.top+maxTrack.y );
1720 if (parent) MapWindowPoints( parent, 0, (LPPOINT)&mouseRect, 2 );
1722 /* Retrieve a default cache DC (without using the window style) */
1723 hdc = GetDCEx( parent, 0, DCX_CACHE );
1725 if( iconic ) /* create a cursor for dragging */
1727 hDragCursor = (HCURSOR)GetClassLongPtrW( hwnd, GCLP_HICON);
1728 if( !hDragCursor ) hDragCursor = (HCURSOR)SendMessageW( hwnd, WM_QUERYDRAGICON, 0, 0L);
1729 if( !hDragCursor ) iconic = FALSE;
1732 /* repaint the window before moving it around */
1733 RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN );
1735 SendMessageA( hwnd, WM_ENTERSIZEMOVE, 0, 0 );
1736 set_movesize_capture( hwnd );
1738 /* grab the server only when moving top-level windows without desktop */
1739 grab = (!DragFullWindows && !parent && (root_window == DefaultRootWindow(gdi_display)));
1741 if (grab)
1743 wine_tsx11_lock();
1744 XSync( gdi_display, False );
1745 XGrabServer( thread_data->display );
1746 XSync( thread_data->display, False );
1747 /* switch gdi display to the thread display, since the server is grabbed */
1748 old_gdi_display = gdi_display;
1749 gdi_display = thread_data->display;
1750 wine_tsx11_unlock();
1752 whole_win = X11DRV_get_whole_window( GetAncestor(hwnd,GA_ROOT) );
1753 parent_win = parent ? X11DRV_get_whole_window( GetAncestor(parent,GA_ROOT) ) : root_window;
1755 wine_tsx11_lock();
1756 XGrabPointer( thread_data->display, whole_win, False,
1757 PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
1758 GrabModeAsync, GrabModeAsync, parent_win, None, CurrentTime );
1759 wine_tsx11_unlock();
1760 thread_data->grab_window = whole_win;
1762 while(1)
1764 int dx = 0, dy = 0;
1766 if (!GetMessageW( &msg, 0, WM_KEYFIRST, WM_MOUSELAST )) break;
1767 if (CallMsgFilterW( &msg, MSGF_SIZE )) continue;
1769 /* Exit on button-up, Return, or Esc */
1770 if ((msg.message == WM_LBUTTONUP) ||
1771 ((msg.message == WM_KEYDOWN) &&
1772 ((msg.wParam == VK_RETURN) || (msg.wParam == VK_ESCAPE)))) break;
1774 if ((msg.message != WM_KEYDOWN) && (msg.message != WM_MOUSEMOVE))
1775 continue; /* We are not interested in other messages */
1777 pt = msg.pt;
1779 if (msg.message == WM_KEYDOWN) switch(msg.wParam)
1781 case VK_UP: pt.y -= 8; break;
1782 case VK_DOWN: pt.y += 8; break;
1783 case VK_LEFT: pt.x -= 8; break;
1784 case VK_RIGHT: pt.x += 8; break;
1787 pt.x = max( pt.x, mouseRect.left );
1788 pt.x = min( pt.x, mouseRect.right );
1789 pt.y = max( pt.y, mouseRect.top );
1790 pt.y = min( pt.y, mouseRect.bottom );
1792 dx = pt.x - capturePoint.x;
1793 dy = pt.y - capturePoint.y;
1795 if (dx || dy)
1797 if( !moved )
1799 moved = TRUE;
1801 if( iconic ) /* ok, no system popup tracking */
1803 hOldCursor = SetCursor(hDragCursor);
1804 ShowCursor( TRUE );
1805 WINPOS_ShowIconTitle( hwnd, FALSE );
1807 else if(!DragFullWindows)
1808 draw_moving_frame( hdc, &sizingRect, thickframe );
1811 if (msg.message == WM_KEYDOWN) SetCursorPos( pt.x, pt.y );
1812 else
1814 RECT newRect = sizingRect;
1815 WPARAM wpSizingHit = 0;
1817 if (hittest == HTCAPTION) OffsetRect( &newRect, dx, dy );
1818 if (ON_LEFT_BORDER(hittest)) newRect.left += dx;
1819 else if (ON_RIGHT_BORDER(hittest)) newRect.right += dx;
1820 if (ON_TOP_BORDER(hittest)) newRect.top += dy;
1821 else if (ON_BOTTOM_BORDER(hittest)) newRect.bottom += dy;
1822 if(!iconic && !DragFullWindows) draw_moving_frame( hdc, &sizingRect, thickframe );
1823 capturePoint = pt;
1825 /* determine the hit location */
1826 if (hittest >= HTLEFT && hittest <= HTBOTTOMRIGHT)
1827 wpSizingHit = WMSZ_LEFT + (hittest - HTLEFT);
1828 SendMessageA( hwnd, WM_SIZING, wpSizingHit, (LPARAM)&newRect );
1830 if (!iconic)
1832 if(!DragFullWindows)
1833 draw_moving_frame( hdc, &newRect, thickframe );
1834 else
1835 SetWindowPos( hwnd, 0, newRect.left, newRect.top,
1836 newRect.right - newRect.left,
1837 newRect.bottom - newRect.top,
1838 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
1840 sizingRect = newRect;
1845 set_movesize_capture(0);
1846 if( iconic )
1848 if( moved ) /* restore cursors, show icon title later on */
1850 ShowCursor( FALSE );
1851 SetCursor( hOldCursor );
1854 else if (moved && !DragFullWindows)
1855 draw_moving_frame( hdc, &sizingRect, thickframe );
1857 ReleaseDC( parent, hdc );
1859 wine_tsx11_lock();
1860 XUngrabPointer( thread_data->display, CurrentTime );
1861 if (grab)
1863 XSync( thread_data->display, False );
1864 XUngrabServer( thread_data->display );
1865 XSync( thread_data->display, False );
1866 gdi_display = old_gdi_display;
1868 wine_tsx11_unlock();
1869 thread_data->grab_window = None;
1871 if (HOOK_CallHooks( WH_CBT, HCBT_MOVESIZE, (WPARAM)hwnd, (LPARAM)&sizingRect, TRUE ))
1872 moved = FALSE;
1874 SendMessageA( hwnd, WM_EXITSIZEMOVE, 0, 0 );
1875 SendMessageA( hwnd, WM_SETVISIBLE, !IsIconic(hwnd), 0L);
1877 /* window moved or resized */
1878 if (moved)
1880 /* if the moving/resizing isn't canceled call SetWindowPos
1881 * with the new position or the new size of the window
1883 if (!((msg.message == WM_KEYDOWN) && (msg.wParam == VK_ESCAPE)) )
1885 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
1886 if(!DragFullWindows)
1887 SetWindowPos( hwnd, 0, sizingRect.left, sizingRect.top,
1888 sizingRect.right - sizingRect.left,
1889 sizingRect.bottom - sizingRect.top,
1890 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
1892 else
1893 { /* restore previous size/position */
1894 if(DragFullWindows)
1895 SetWindowPos( hwnd, 0, origRect.left, origRect.top,
1896 origRect.right - origRect.left,
1897 origRect.bottom - origRect.top,
1898 ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
1902 if (IsIconic(hwnd))
1904 /* Single click brings up the system menu when iconized */
1906 if( !moved )
1908 if(style & WS_SYSMENU )
1909 SendMessageA( hwnd, WM_SYSCOMMAND,
1910 SC_MOUSEMENU + HTSYSMENU, MAKELONG(pt.x,pt.y));
1912 else WINPOS_ShowIconTitle( hwnd, TRUE );