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
26 #include <X11/IntrinsicP.h>
27 #include <X11/extensions/shape.h>
28 #endif /* HAVE_LIBXSHAPE */
38 #include "wine/wingdi16.h"
45 #include "wine/server.h"
46 #include "wine/debug.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(x11drv
);
50 #define SWP_AGG_NOGEOMETRYCHANGE \
51 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE)
52 #define SWP_AGG_NOPOSCHANGE \
53 (SWP_AGG_NOGEOMETRYCHANGE | SWP_NOZORDER)
54 #define SWP_AGG_STATUSFLAGS \
55 (SWP_AGG_NOPOSCHANGE | SWP_FRAMECHANGED | SWP_HIDEWINDOW | SWP_SHOWWINDOW)
57 #define SWP_EX_NOCOPY 0x0001
58 #define SWP_EX_PAINTSELF 0x0002
59 #define SWP_EX_NONCLIENT 0x0004
61 #define HAS_THICKFRAME(style,exStyle) \
62 (((style) & WS_THICKFRAME) && \
63 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
65 #define ON_LEFT_BORDER(hit) \
66 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
67 #define ON_RIGHT_BORDER(hit) \
68 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
69 #define ON_TOP_BORDER(hit) \
70 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
71 #define ON_BOTTOM_BORDER(hit) \
72 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
74 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
75 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
76 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
77 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
78 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
79 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
80 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
81 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
82 #define _NET_WM_MOVERESIZE_MOVE 8 /* movement only */
83 #define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9 /* size via keyboard */
84 #define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10 /* move via keyboard */
87 /***********************************************************************
88 * get_server_visible_region
90 static HRGN
get_server_visible_region( HWND hwnd
, HWND top
, UINT flags
)
99 if (!(data
= HeapAlloc( GetProcessHeap(), 0, sizeof(*data
) + size
- 1 ))) return 0;
100 SERVER_START_REQ( get_visible_region
)
105 wine_server_set_reply( req
, data
->Buffer
, size
);
106 if (!(status
= wine_server_call( req
)))
108 size_t reply_size
= wine_server_reply_size( reply
);
109 data
->rdh
.dwSize
= sizeof(data
->rdh
);
110 data
->rdh
.iType
= RDH_RECTANGLES
;
111 data
->rdh
.nCount
= reply_size
/ sizeof(RECT
);
112 data
->rdh
.nRgnSize
= reply_size
;
113 ret
= ExtCreateRegion( NULL
, size
, data
);
115 else size
= reply
->total_size
;
118 HeapFree( GetProcessHeap(), 0, data
);
119 } while (status
== STATUS_BUFFER_OVERFLOW
);
121 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
126 /***********************************************************************
127 * get_top_clipping_window
129 * Get the top window to clip against (i.e. the top parent that has
130 * an associated X window).
132 static HWND
get_top_clipping_window( HWND hwnd
)
136 if (!using_wine_desktop
) ret
= GetAncestor( hwnd
, GA_ROOT
);
137 if (!ret
) ret
= GetDesktopWindow();
142 /***********************************************************************
145 * Expose a region of a given window.
147 static void expose_window( HWND hwnd
, RECT
*rect
, HRGN rgn
, int flags
)
154 /* find the top most parent that doesn't clip children or siblings and
155 * invalidate the area on its parent, including all children */
156 if ((list
= WIN_ListParents( hwnd
)))
159 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
160 for (i
= 0; list
[i
] && list
[i
] != GetDesktopWindow(); i
++)
162 if (!(style
& WS_CLIPSIBLINGS
)) top
= current
;
163 style
= GetWindowLongW( list
[i
], GWL_STYLE
);
164 if (!(style
& WS_CLIPCHILDREN
)) top
= current
;
170 /* find the parent of the top window, reusing the parent list */
171 if (top
== hwnd
) i
= 0;
174 for (i
= 0; list
[i
]; i
++) if (list
[i
] == top
) break;
175 if (list
[i
] && list
[i
+1]) i
++;
177 if (list
[i
] != GetDesktopWindow()) top
= list
[i
];
178 flags
&= ~RDW_FRAME
; /* parent will invalidate children frame anyway */
179 flags
|= RDW_ALLCHILDREN
;
181 HeapFree( GetProcessHeap(), 0, list
);
184 if (!top
) top
= hwnd
;
186 /* make coords relative to top */
187 offset
.x
= offset
.y
= 0;
188 MapWindowPoints( hwnd
, top
, &offset
, 1 );
192 OffsetRect( rect
, offset
.x
, offset
.y
);
193 RedrawWindow( top
, rect
, 0, flags
);
197 OffsetRgn( rgn
, offset
.x
, offset
.y
);
198 RedrawWindow( top
, NULL
, rgn
, flags
);
203 /***********************************************************************
206 void X11DRV_Expose( HWND hwnd
, XExposeEvent
*event
)
209 struct x11drv_win_data
*data
;
210 int flags
= RDW_INVALIDATE
| RDW_ERASE
;
212 TRACE( "win %p (%lx) %d,%d %dx%d\n",
213 hwnd
, event
->window
, event
->x
, event
->y
, event
->width
, event
->height
);
215 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
217 rect
.left
= event
->x
;
219 rect
.right
= rect
.left
+ event
->width
;
220 rect
.bottom
= rect
.top
+ event
->height
;
222 if (event
->window
!= data
->client_window
) /* whole window or icon window */
225 /* make position relative to client area instead of window */
226 OffsetRect( &rect
, -data
->client_rect
.left
, -data
->client_rect
.top
);
229 expose_window( hwnd
, &rect
, 0, flags
);
233 /***********************************************************************
236 * Set the drawable, origin and dimensions for the DC associated to
239 BOOL
X11DRV_GetDC( HWND hwnd
, HDC hdc
, HRGN hrgn
, DWORD flags
)
241 HWND top
= get_top_clipping_window( hwnd
);
242 WND
*win
= WIN_GetPtr( hwnd
);
243 struct x11drv_win_data
*data
= win
->pDriverData
;
244 struct x11drv_escape_set_drawable escape
;
246 escape
.mode
= IncludeInferiors
;
247 /* don't clip siblings if using parent clip region */
248 if (flags
& DCX_PARENTCLIP
) flags
&= ~DCX_CLIPSIBLINGS
;
252 /* find the top most parent that doesn't clip siblings */
253 HWND clipping_parent
= 0;
254 HWND
*list
= WIN_ListParents( hwnd
);
258 for (i
= 0; list
[i
] != top
; i
++)
260 LONG style
= GetWindowLongW( list
[i
], GWL_STYLE
);
261 if (!(style
& WS_CLIPSIBLINGS
)) clipping_parent
= list
[i
];
263 HeapFree( GetProcessHeap(), 0, list
);
266 clipping_parent
= GetAncestor( clipping_parent
, GA_PARENT
);
267 else if (!(flags
& DCX_CLIPSIBLINGS
) || (flags
& DCX_WINDOW
))
268 clipping_parent
= GetAncestor( hwnd
, GA_PARENT
);
270 clipping_parent
= hwnd
;
272 escape
.org
.x
= escape
.org
.y
= 0;
273 escape
.drawable_org
.x
= escape
.drawable_org
.y
= 0;
274 if (flags
& DCX_WINDOW
)
276 escape
.org
.x
= win
->rectWindow
.left
- win
->rectClient
.left
;
277 escape
.org
.y
= win
->rectWindow
.top
- win
->rectClient
.top
;
279 MapWindowPoints( hwnd
, clipping_parent
, &escape
.org
, 1 );
280 MapWindowPoints( clipping_parent
, 0, &escape
.drawable_org
, 1 );
281 escape
.drawable
= X11DRV_get_client_window( clipping_parent
);
285 if (IsIconic( hwnd
))
287 escape
.drawable
= data
->icon_window
? data
->icon_window
: data
->whole_window
;
290 escape
.drawable_org
= escape
.org
;
292 else if (flags
& DCX_WINDOW
)
294 escape
.drawable
= data
->whole_window
;
295 escape
.drawable_org
.x
= data
->whole_rect
.left
;
296 escape
.drawable_org
.y
= data
->whole_rect
.top
;
297 escape
.org
.x
= win
->rectWindow
.left
- data
->whole_rect
.left
;
298 escape
.org
.y
= win
->rectWindow
.top
- data
->whole_rect
.top
;
302 escape
.drawable
= data
->client_window
;
303 escape
.drawable_org
.x
= win
->rectClient
.left
;
304 escape
.drawable_org
.y
= win
->rectClient
.top
;
310 escape
.code
= X11DRV_SET_DRAWABLE
;
311 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
313 if (flags
& (DCX_EXCLUDERGN
| DCX_INTERSECTRGN
) ||
314 SetHookFlags16( HDC_16(hdc
), DCHF_VALIDATEVISRGN
)) /* DC was dirty */
316 /* need to recompute the visible region */
317 HRGN visRgn
= get_server_visible_region( hwnd
, top
, flags
);
319 if (flags
& (DCX_EXCLUDERGN
| DCX_INTERSECTRGN
))
320 CombineRgn( visRgn
, visRgn
, hrgn
, (flags
& DCX_INTERSECTRGN
) ? RGN_AND
: RGN_DIFF
);
322 SelectVisRgn16( HDC_16(hdc
), HRGN_16(visRgn
) );
323 DeleteObject( visRgn
);
326 WIN_ReleasePtr( win
);
331 /***********************************************************************
332 * ReleaseDC (X11DRV.@)
334 void X11DRV_ReleaseDC( HWND hwnd
, HDC hdc
)
336 struct x11drv_escape_set_drawable escape
;
338 escape
.code
= X11DRV_SET_DRAWABLE
;
339 escape
.drawable
= root_window
;
340 escape
.mode
= IncludeInferiors
;
341 escape
.org
.x
= escape
.org
.y
= 0;
342 escape
.drawable_org
.x
= escape
.drawable_org
.y
= 0;
344 ExtEscape( hdc
, X11DRV_ESCAPE
, sizeof(escape
), (LPSTR
)&escape
, 0, NULL
);
348 /***********************************************************************
349 * SWP_DoWinPosChanging
351 static BOOL
SWP_DoWinPosChanging( WINDOWPOS
* pWinpos
, RECT
* pNewWindowRect
, RECT
* pNewClientRect
)
355 /* Send WM_WINDOWPOSCHANGING message */
357 if (!(pWinpos
->flags
& SWP_NOSENDCHANGING
))
358 SendMessageW( pWinpos
->hwnd
, WM_WINDOWPOSCHANGING
, 0, (LPARAM
)pWinpos
);
360 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return FALSE
;
362 /* Calculate new position and size */
364 *pNewWindowRect
= wndPtr
->rectWindow
;
365 *pNewClientRect
= (wndPtr
->dwStyle
& WS_MINIMIZE
) ? wndPtr
->rectWindow
366 : wndPtr
->rectClient
;
368 if (!(pWinpos
->flags
& SWP_NOSIZE
))
370 pNewWindowRect
->right
= pNewWindowRect
->left
+ pWinpos
->cx
;
371 pNewWindowRect
->bottom
= pNewWindowRect
->top
+ pWinpos
->cy
;
373 if (!(pWinpos
->flags
& SWP_NOMOVE
))
375 pNewWindowRect
->left
= pWinpos
->x
;
376 pNewWindowRect
->top
= pWinpos
->y
;
377 pNewWindowRect
->right
+= pWinpos
->x
- wndPtr
->rectWindow
.left
;
378 pNewWindowRect
->bottom
+= pWinpos
->y
- wndPtr
->rectWindow
.top
;
380 OffsetRect( pNewClientRect
, pWinpos
->x
- wndPtr
->rectWindow
.left
,
381 pWinpos
->y
- wndPtr
->rectWindow
.top
);
383 pWinpos
->flags
|= SWP_NOCLIENTMOVE
| SWP_NOCLIENTSIZE
;
385 TRACE( "hwnd %p, after %p, swp %d,%d %dx%d flags %08x\n",
386 pWinpos
->hwnd
, pWinpos
->hwndInsertAfter
, pWinpos
->x
, pWinpos
->y
,
387 pWinpos
->cx
, pWinpos
->cy
, pWinpos
->flags
);
388 TRACE( "current %s style %08lx new %s\n",
389 wine_dbgstr_rect( &wndPtr
->rectWindow
), wndPtr
->dwStyle
,
390 wine_dbgstr_rect( pNewWindowRect
));
392 WIN_ReleasePtr( wndPtr
);
396 /***********************************************************************
399 static UINT
SWP_DoNCCalcSize( WINDOWPOS
* pWinpos
, const RECT
* pNewWindowRect
, RECT
* pNewClientRect
)
404 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
406 /* Send WM_NCCALCSIZE message to get new client area */
407 if( (pWinpos
->flags
& (SWP_FRAMECHANGED
| SWP_NOSIZE
)) != SWP_NOSIZE
)
409 NCCALCSIZE_PARAMS params
;
410 WINDOWPOS winposCopy
;
412 params
.rgrc
[0] = *pNewWindowRect
;
413 params
.rgrc
[1] = wndPtr
->rectWindow
;
414 params
.rgrc
[2] = wndPtr
->rectClient
;
415 params
.lppos
= &winposCopy
;
416 winposCopy
= *pWinpos
;
417 WIN_ReleasePtr( wndPtr
);
419 wvrFlags
= SendMessageW( pWinpos
->hwnd
, WM_NCCALCSIZE
, TRUE
, (LPARAM
)¶ms
);
421 TRACE( "(%ld,%ld)-(%ld,%ld)\n", params
.rgrc
[0].left
, params
.rgrc
[0].top
,
422 params
.rgrc
[0].right
, params
.rgrc
[0].bottom
);
424 /* If the application sends back garbage, ignore it */
426 if (params
.rgrc
[0].left
< pNewWindowRect
->left
) params
.rgrc
[0].left
= pNewWindowRect
->left
;
427 if (params
.rgrc
[0].top
< pNewWindowRect
->top
) params
.rgrc
[0].top
= pNewWindowRect
->top
;
428 if (params
.rgrc
[0].right
> pNewWindowRect
->right
) params
.rgrc
[0].right
= pNewWindowRect
->right
;
429 if (params
.rgrc
[0].bottom
> pNewWindowRect
->bottom
) params
.rgrc
[0].bottom
= pNewWindowRect
->bottom
;
431 if (params
.rgrc
[0].left
<= params
.rgrc
[0].right
&&
432 params
.rgrc
[0].top
<= params
.rgrc
[0].bottom
)
433 *pNewClientRect
= params
.rgrc
[0];
435 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
437 if( pNewClientRect
->left
!= wndPtr
->rectClient
.left
||
438 pNewClientRect
->top
!= wndPtr
->rectClient
.top
)
439 pWinpos
->flags
&= ~SWP_NOCLIENTMOVE
;
441 if( (pNewClientRect
->right
- pNewClientRect
->left
!=
442 wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
) ||
443 (pNewClientRect
->bottom
- pNewClientRect
->top
!=
444 wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
) )
445 pWinpos
->flags
&= ~SWP_NOCLIENTSIZE
;
449 if (!(pWinpos
->flags
& SWP_NOMOVE
) &&
450 (pNewClientRect
->left
!= wndPtr
->rectClient
.left
||
451 pNewClientRect
->top
!= wndPtr
->rectClient
.top
))
452 pWinpos
->flags
&= ~SWP_NOCLIENTMOVE
;
454 WIN_ReleasePtr( wndPtr
);
459 /***********************************************************************
462 * fix Z order taking into account owned popups -
463 * basically we need to maintain them above the window that owns them
465 * FIXME: hide/show owned popups when owner visibility changes.
467 static HWND
SWP_DoOwnedPopups(HWND hwnd
, HWND hwndInsertAfter
)
470 HWND owner
= GetWindow( hwnd
, GW_OWNER
);
471 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
473 WARN("(%p) hInsertAfter = %p\n", hwnd
, hwndInsertAfter
);
475 if ((style
& WS_POPUP
) && owner
)
477 /* make sure this popup stays above the owner */
479 HWND hwndLocalPrev
= HWND_TOP
;
481 if( hwndInsertAfter
!= HWND_TOP
)
483 if ((list
= WIN_ListChildren( GetDesktopWindow() )))
486 for (i
= 0; list
[i
]; i
++)
488 if (list
[i
] == owner
) break;
489 if (list
[i
] != hwnd
) hwndLocalPrev
= list
[i
];
490 if (hwndLocalPrev
== hwndInsertAfter
) break;
492 hwndInsertAfter
= hwndLocalPrev
;
496 else if (style
& WS_CHILD
) return hwndInsertAfter
;
498 if (!list
) list
= WIN_ListChildren( GetDesktopWindow() );
502 for (i
= 0; list
[i
]; i
++)
504 if (list
[i
] == hwnd
) break;
505 if ((GetWindowLongW( list
[i
], GWL_STYLE
) & WS_POPUP
) &&
506 GetWindow( list
[i
], GW_OWNER
) == hwnd
)
508 SetWindowPos( list
[i
], hwndInsertAfter
, 0, 0, 0, 0,
509 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
|
510 SWP_NOSENDCHANGING
| SWP_DEFERERASE
);
511 hwndInsertAfter
= list
[i
];
514 HeapFree( GetProcessHeap(), 0, list
);
517 return hwndInsertAfter
;
521 /* fix redundant flags and values in the WINDOWPOS structure */
522 static BOOL
fixup_flags( WINDOWPOS
*winpos
)
524 WND
*wndPtr
= WIN_GetPtr( winpos
->hwnd
);
527 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
)
529 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
532 winpos
->hwnd
= wndPtr
->hwndSelf
; /* make it a full handle */
534 /* Finally make sure that all coordinates are valid */
535 if (winpos
->x
< -32768) winpos
->x
= -32768;
536 else if (winpos
->x
> 32767) winpos
->x
= 32767;
537 if (winpos
->y
< -32768) winpos
->y
= -32768;
538 else if (winpos
->y
> 32767) winpos
->y
= 32767;
540 if (winpos
->cx
< 0) winpos
->cx
= 0;
541 else if (winpos
->cx
> 32767) winpos
->cx
= 32767;
542 if (winpos
->cy
< 0) winpos
->cy
= 0;
543 else if (winpos
->cy
> 32767) winpos
->cy
= 32767;
545 if (wndPtr
->dwStyle
& WS_VISIBLE
) winpos
->flags
&= ~SWP_SHOWWINDOW
;
548 winpos
->flags
&= ~SWP_HIDEWINDOW
;
549 if (!(winpos
->flags
& SWP_SHOWWINDOW
)) winpos
->flags
|= SWP_NOREDRAW
;
552 if ((wndPtr
->rectWindow
.right
- wndPtr
->rectWindow
.left
== winpos
->cx
) &&
553 (wndPtr
->rectWindow
.bottom
- wndPtr
->rectWindow
.top
== winpos
->cy
))
554 winpos
->flags
|= SWP_NOSIZE
; /* Already the right size */
556 if ((wndPtr
->rectWindow
.left
== winpos
->x
) && (wndPtr
->rectWindow
.top
== winpos
->y
))
557 winpos
->flags
|= SWP_NOMOVE
; /* Already the right position */
559 if ((wndPtr
->dwStyle
& (WS_POPUP
| WS_CHILD
)) != WS_CHILD
)
561 if (!(winpos
->flags
& SWP_NOACTIVATE
)) /* Bring to the top when activating */
563 winpos
->flags
&= ~SWP_NOZORDER
;
564 winpos
->hwndInsertAfter
= HWND_TOP
;
568 /* Check hwndInsertAfter */
569 if (winpos
->flags
& SWP_NOZORDER
) goto done
;
571 /* fix sign extension */
572 if (winpos
->hwndInsertAfter
== (HWND
)0xffff) winpos
->hwndInsertAfter
= HWND_TOPMOST
;
573 else if (winpos
->hwndInsertAfter
== (HWND
)0xfffe) winpos
->hwndInsertAfter
= HWND_NOTOPMOST
;
575 /* FIXME: TOPMOST not supported yet */
576 if ((winpos
->hwndInsertAfter
== HWND_TOPMOST
) ||
577 (winpos
->hwndInsertAfter
== HWND_NOTOPMOST
)) winpos
->hwndInsertAfter
= HWND_TOP
;
579 /* hwndInsertAfter must be a sibling of the window */
580 if (winpos
->hwndInsertAfter
== HWND_TOP
)
582 if (GetWindow(winpos
->hwnd
, GW_HWNDFIRST
) == winpos
->hwnd
)
583 winpos
->flags
|= SWP_NOZORDER
;
585 else if (winpos
->hwndInsertAfter
== HWND_BOTTOM
)
587 if (GetWindow(winpos
->hwnd
, GW_HWNDLAST
) == winpos
->hwnd
)
588 winpos
->flags
|= SWP_NOZORDER
;
592 if (GetAncestor( winpos
->hwndInsertAfter
, GA_PARENT
) != wndPtr
->parent
) ret
= FALSE
;
595 /* don't need to change the Zorder of hwnd if it's already inserted
596 * after hwndInsertAfter or when inserting hwnd after itself.
598 if ((winpos
->hwnd
== winpos
->hwndInsertAfter
) ||
599 (winpos
->hwnd
== GetWindow( winpos
->hwndInsertAfter
, GW_HWNDNEXT
)))
600 winpos
->flags
|= SWP_NOZORDER
;
604 WIN_ReleasePtr( wndPtr
);
609 /***********************************************************************
610 * SetWindowStyle (X11DRV.@)
612 * Update the X state of a window to reflect a style change
614 void X11DRV_SetWindowStyle( HWND hwnd
, DWORD old_style
)
616 Display
*display
= thread_display();
617 struct x11drv_win_data
*data
;
618 DWORD new_style
, changed
;
620 if (hwnd
== GetDesktopWindow()) return;
621 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
623 new_style
= GetWindowLongW( hwnd
, GWL_STYLE
);
624 changed
= new_style
^ old_style
;
626 if (changed
& WS_VISIBLE
)
628 if (X11DRV_is_window_rect_mapped( &data
->window_rect
))
630 if (new_style
& WS_VISIBLE
)
632 TRACE( "mapping win %p\n", hwnd
);
633 if (is_window_top_level( hwnd
))
635 X11DRV_sync_window_style( display
, data
);
636 X11DRV_set_wm_hints( display
, data
);
639 XMapWindow( display
, data
->whole_window
);
642 else if (!is_window_top_level( hwnd
)) /* don't unmap managed windows */
644 TRACE( "unmapping win %p\n", hwnd
);
646 XUnmapWindow( display
, data
->whole_window
);
650 DCE_InvalidateDCE( hwnd
, &data
->window_rect
);
653 if (changed
& WS_DISABLED
)
655 if (GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_MANAGED
)
659 if (!(wm_hints
= XGetWMHints( display
, data
->whole_window
)))
660 wm_hints
= XAllocWMHints();
663 wm_hints
->flags
|= InputHint
;
664 wm_hints
->input
= !(new_style
& WS_DISABLED
);
665 XSetWMHints( display
, data
->whole_window
, wm_hints
);
674 /***********************************************************************
675 * X11DRV_set_window_pos
677 * Set a window position and Z order.
679 BOOL
X11DRV_set_window_pos( HWND hwnd
, HWND insert_after
, const RECT
*rectWindow
,
680 const RECT
*rectClient
, UINT swp_flags
, UINT wvr_flags
)
682 HWND top
= get_top_clipping_window( hwnd
);
683 WND
*win
= WIN_GetPtr( hwnd
);
684 DWORD old_style
, new_style
;
687 if (!win
) return FALSE
;
688 if (win
== WND_OTHER_PROCESS
)
690 if (IsWindow( hwnd
)) ERR( "cannot set rectangles of other process window %p\n", hwnd
);
693 old_style
= win
->dwStyle
;
694 SERVER_START_REQ( set_window_pos
)
698 req
->previous
= insert_after
;
699 req
->flags
= swp_flags
& ~SWP_WINE_NOHOSTMOVE
;
700 req
->redraw_flags
= wvr_flags
;
701 req
->window
.left
= rectWindow
->left
;
702 req
->window
.top
= rectWindow
->top
;
703 req
->window
.right
= rectWindow
->right
;
704 req
->window
.bottom
= rectWindow
->bottom
;
705 req
->client
.left
= rectClient
->left
;
706 req
->client
.top
= rectClient
->top
;
707 req
->client
.right
= rectClient
->right
;
708 req
->client
.bottom
= rectClient
->bottom
;
709 ret
= !wine_server_call( req
);
710 new_style
= reply
->new_style
;
716 struct x11drv_win_data
*data
= win
->pDriverData
;
717 Display
*display
= thread_display();
719 /* invalidate DCEs */
721 if ((((swp_flags
& SWP_AGG_NOPOSCHANGE
) != SWP_AGG_NOPOSCHANGE
) && (new_style
& WS_VISIBLE
)) ||
722 (swp_flags
& (SWP_HIDEWINDOW
| SWP_SHOWWINDOW
)))
725 UnionRect( &rect
, rectWindow
, &win
->rectWindow
);
726 DCE_InvalidateDCE( hwnd
, &rect
);
729 win
->rectWindow
= *rectWindow
;
730 win
->rectClient
= *rectClient
;
731 win
->dwStyle
= new_style
;
732 data
->window_rect
= *rectWindow
;
734 TRACE( "win %p window %s client %s style %08lx\n",
735 hwnd
, wine_dbgstr_rect(rectWindow
), wine_dbgstr_rect(rectClient
), new_style
);
737 /* FIXME: copy the valid bits */
739 if (swp_flags
& SWP_WINE_NOHOSTMOVE
)
741 data
->whole_rect
= *rectWindow
;
742 X11DRV_window_to_X_rect( hwnd
, &data
->whole_rect
);
743 if (data
->client_window
!= data
->whole_window
)
744 X11DRV_sync_client_window_position( display
, data
, rectClient
);
746 else if (data
->whole_window
) /* don't do anything if X window not created yet */
748 if ((old_style
& WS_VISIBLE
) && !(new_style
& WS_VISIBLE
))
750 /* window got hidden, unmap it */
751 TRACE( "unmapping win %p\n", hwnd
);
753 XUnmapWindow( thread_display(), data
->whole_window
);
756 else if ((new_style
& WS_VISIBLE
) && !X11DRV_is_window_rect_mapped( rectWindow
))
758 /* resizing to zero size or off screen -> unmap */
759 TRACE( "unmapping zero size or off-screen win %p\n", hwnd
);
761 XUnmapWindow( display
, data
->whole_window
);
765 X11DRV_sync_whole_window_position( display
, data
, !(swp_flags
& SWP_NOZORDER
) );
766 X11DRV_sync_client_window_position( display
, data
, rectClient
);
768 if (!(old_style
& WS_VISIBLE
) && (new_style
& WS_VISIBLE
))
770 /* window got shown, map it */
771 if (X11DRV_is_window_rect_mapped( rectWindow
))
773 TRACE( "mapping win %p\n", hwnd
);
774 if (is_window_top_level( hwnd
))
776 X11DRV_sync_window_style( display
, data
);
777 X11DRV_set_wm_hints( display
, data
);
780 XMapWindow( display
, data
->whole_window
);
784 else if ((new_style
& WS_VISIBLE
) && X11DRV_is_window_rect_mapped( rectWindow
))
786 /* resizing from zero size to non-zero -> map */
787 TRACE( "mapping non zero size or off-screen win %p\n", hwnd
);
789 XMapWindow( display
, data
->whole_window
);
793 XFlush( display
); /* FIXME: should not be necessary */
797 WIN_ReleasePtr( win
);
802 /***********************************************************************
803 * SetWindowPos (X11DRV.@)
805 BOOL
X11DRV_SetWindowPos( WINDOWPOS
*winpos
)
807 RECT newWindowRect
, newClientRect
;
808 UINT wvr_flags
, orig_flags
;
810 TRACE( "hwnd %p, after %p, swp %d,%d %dx%d flags %08x\n",
811 winpos
->hwnd
, winpos
->hwndInsertAfter
, winpos
->x
, winpos
->y
,
812 winpos
->cx
, winpos
->cy
, winpos
->flags
);
814 orig_flags
= winpos
->flags
;
815 winpos
->flags
&= ~SWP_WINE_NOHOSTMOVE
;
817 /* Check window handle */
818 if (winpos
->hwnd
== GetDesktopWindow()) return FALSE
;
820 /* First make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
821 if (!(winpos
->flags
& SWP_NOMOVE
))
823 if (winpos
->x
< -32768) winpos
->x
= -32768;
824 else if (winpos
->x
> 32767) winpos
->x
= 32767;
825 if (winpos
->y
< -32768) winpos
->y
= -32768;
826 else if (winpos
->y
> 32767) winpos
->y
= 32767;
828 if (!(winpos
->flags
& SWP_NOSIZE
))
830 if (winpos
->cx
< 0) winpos
->cx
= 0;
831 else if (winpos
->cx
> 32767) winpos
->cx
= 32767;
832 if (winpos
->cy
< 0) winpos
->cy
= 0;
833 else if (winpos
->cy
> 32767) winpos
->cy
= 32767;
836 if (!SWP_DoWinPosChanging( winpos
, &newWindowRect
, &newClientRect
)) return FALSE
;
838 /* Fix redundant flags */
839 if (!fixup_flags( winpos
)) return FALSE
;
841 if((winpos
->flags
& (SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_SHOWWINDOW
)) != SWP_NOZORDER
)
843 if (GetAncestor( winpos
->hwnd
, GA_PARENT
) == GetDesktopWindow())
844 winpos
->hwndInsertAfter
= SWP_DoOwnedPopups( winpos
->hwnd
, winpos
->hwndInsertAfter
);
847 /* Common operations */
849 wvr_flags
= SWP_DoNCCalcSize( winpos
, &newWindowRect
, &newClientRect
);
851 /* FIXME: actually do something with WVR_VALIDRECTS */
853 if (!X11DRV_set_window_pos( winpos
->hwnd
, winpos
->hwndInsertAfter
,
854 &newWindowRect
, &newClientRect
,
855 orig_flags
, wvr_flags
))
858 if( winpos
->flags
& SWP_HIDEWINDOW
)
859 HideCaret(winpos
->hwnd
);
860 else if (winpos
->flags
& SWP_SHOWWINDOW
)
861 ShowCaret(winpos
->hwnd
);
863 if (!(winpos
->flags
& SWP_NOACTIVATE
))
865 /* child windows get WM_CHILDACTIVATE message */
866 if ((GetWindowLongW( winpos
->hwnd
, GWL_STYLE
) & (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
867 SendMessageA( winpos
->hwnd
, WM_CHILDACTIVATE
, 0, 0 );
869 SetForegroundWindow( winpos
->hwnd
);
872 /* And last, send the WM_WINDOWPOSCHANGED message */
874 TRACE("\tstatus flags = %04x\n", winpos
->flags
& SWP_AGG_STATUSFLAGS
);
876 if (((winpos
->flags
& SWP_AGG_STATUSFLAGS
) != SWP_AGG_NOPOSCHANGE
))
878 /* WM_WINDOWPOSCHANGED is sent even if SWP_NOSENDCHANGING is set
879 and always contains final window position.
881 winpos
->x
= newWindowRect
.left
;
882 winpos
->y
= newWindowRect
.top
;
883 winpos
->cx
= newWindowRect
.right
- newWindowRect
.left
;
884 winpos
->cy
= newWindowRect
.bottom
- newWindowRect
.top
;
885 SendMessageW( winpos
->hwnd
, WM_WINDOWPOSCHANGED
, 0, (LPARAM
)winpos
);
892 /***********************************************************************
895 * Find a suitable place for an iconic window.
897 static POINT
WINPOS_FindIconPos( WND
* wndPtr
, POINT pt
)
901 short x
, y
, xspacing
, yspacing
;
903 GetClientRect( wndPtr
->parent
, &rectParent
);
904 if ((pt
.x
>= rectParent
.left
) && (pt
.x
+ GetSystemMetrics(SM_CXICON
) < rectParent
.right
) &&
905 (pt
.y
>= rectParent
.top
) && (pt
.y
+ GetSystemMetrics(SM_CYICON
) < rectParent
.bottom
))
906 return pt
; /* The icon already has a suitable position */
908 xspacing
= GetSystemMetrics(SM_CXICONSPACING
);
909 yspacing
= GetSystemMetrics(SM_CYICONSPACING
);
911 list
= WIN_ListChildren( wndPtr
->parent
);
912 y
= rectParent
.bottom
;
918 /* Check if another icon already occupies this spot */
919 /* FIXME: this is completely inefficient */
925 for (i
= 0; list
[i
]; i
++)
927 if (list
[i
] == wndPtr
->hwndSelf
) continue;
928 if (!IsIconic( list
[i
] )) continue;
929 if (!(childPtr
= WIN_FindWndPtr( list
[i
] ))) continue;
930 if ((childPtr
->rectWindow
.left
< x
+ xspacing
) &&
931 (childPtr
->rectWindow
.right
>= x
) &&
932 (childPtr
->rectWindow
.top
<= y
) &&
933 (childPtr
->rectWindow
.bottom
> y
- yspacing
))
935 WIN_ReleaseWndPtr( childPtr
);
936 break; /* There's a window in there */
938 WIN_ReleaseWndPtr( childPtr
);
942 /* found something here, try next spot */
948 /* No window was found, so it's OK for us */
949 pt
.x
= x
+ (xspacing
- GetSystemMetrics(SM_CXICON
)) / 2;
950 pt
.y
= y
- (yspacing
+ GetSystemMetrics(SM_CYICON
)) / 2;
951 HeapFree( GetProcessHeap(), 0, list
);
954 } while(x
<= rectParent
.right
-xspacing
);
963 UINT
WINPOS_MinMaximize( HWND hwnd
, UINT cmd
, LPRECT rect
)
971 TRACE("%p %u\n", hwnd
, cmd
);
973 wpl
.length
= sizeof(wpl
);
974 GetWindowPlacement( hwnd
, &wpl
);
976 if (HOOK_CallHooks( WH_CBT
, HCBT_MINMAX
, (WPARAM
)hwnd
, cmd
, TRUE
))
977 return SWP_NOSIZE
| SWP_NOMOVE
;
979 if (IsIconic( hwnd
))
981 if (cmd
== SW_MINIMIZE
) return SWP_NOSIZE
| SWP_NOMOVE
;
982 if (!SendMessageA( hwnd
, WM_QUERYOPEN
, 0, 0 )) return SWP_NOSIZE
| SWP_NOMOVE
;
983 swpFlags
|= SWP_NOCOPYBITS
;
986 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return 0;
988 size
.x
= wndPtr
->rectWindow
.left
;
989 size
.y
= wndPtr
->rectWindow
.top
;
994 if( wndPtr
->dwStyle
& WS_MAXIMIZE
) wndPtr
->flags
|= WIN_RESTORE_MAX
;
995 else wndPtr
->flags
&= ~WIN_RESTORE_MAX
;
997 WIN_SetStyle( hwnd
, (wndPtr
->dwStyle
& ~WS_MAXIMIZE
) | WS_MINIMIZE
);
999 X11DRV_set_iconic_state( hwnd
);
1001 wpl
.ptMinPosition
= WINPOS_FindIconPos( wndPtr
, wpl
.ptMinPosition
);
1003 SetRect( rect
, wpl
.ptMinPosition
.x
, wpl
.ptMinPosition
.y
,
1004 GetSystemMetrics(SM_CXICON
), GetSystemMetrics(SM_CYICON
) );
1005 swpFlags
|= SWP_NOCOPYBITS
;
1009 WINPOS_GetMinMaxInfo( hwnd
, &size
, &wpl
.ptMaxPosition
, NULL
, NULL
);
1011 old_style
= WIN_SetStyle( hwnd
, (wndPtr
->dwStyle
& ~WS_MINIMIZE
) | WS_MAXIMIZE
);
1012 if (old_style
& WS_MINIMIZE
)
1014 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1015 X11DRV_set_iconic_state( hwnd
);
1017 SetRect( rect
, wpl
.ptMaxPosition
.x
, wpl
.ptMaxPosition
.y
, size
.x
, size
.y
);
1021 old_style
= WIN_SetStyle( hwnd
, wndPtr
->dwStyle
& ~(WS_MINIMIZE
|WS_MAXIMIZE
) );
1022 if (old_style
& WS_MINIMIZE
)
1024 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1025 X11DRV_set_iconic_state( hwnd
);
1027 if( wndPtr
->flags
& WIN_RESTORE_MAX
)
1029 /* Restore to maximized position */
1030 WINPOS_GetMinMaxInfo( hwnd
, &size
, &wpl
.ptMaxPosition
, NULL
, NULL
);
1031 WIN_SetStyle( hwnd
, wndPtr
->dwStyle
| WS_MAXIMIZE
);
1032 SetRect( rect
, wpl
.ptMaxPosition
.x
, wpl
.ptMaxPosition
.y
, size
.x
, size
.y
);
1036 else if (!(old_style
& WS_MAXIMIZE
)) break;
1038 /* Restore to normal position */
1040 *rect
= wpl
.rcNormalPosition
;
1041 rect
->right
-= rect
->left
;
1042 rect
->bottom
-= rect
->top
;
1047 WIN_ReleaseWndPtr( wndPtr
);
1052 /***********************************************************************
1053 * ShowWindow (X11DRV.@)
1055 BOOL
X11DRV_ShowWindow( HWND hwnd
, INT cmd
)
1057 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
1058 BOOL wasVisible
, showFlag
;
1059 RECT newPos
= {0, 0, 0, 0};
1062 if (!wndPtr
) return FALSE
;
1063 hwnd
= wndPtr
->hwndSelf
; /* make it a full handle */
1065 wasVisible
= (wndPtr
->dwStyle
& WS_VISIBLE
) != 0;
1067 TRACE("hwnd=%p, cmd=%d, wasVisible %d\n", hwnd
, cmd
, wasVisible
);
1072 if (!wasVisible
) goto END
;
1073 swp
|= SWP_HIDEWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
|
1074 SWP_NOACTIVATE
| SWP_NOZORDER
;
1077 case SW_SHOWMINNOACTIVE
:
1078 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1080 case SW_SHOWMINIMIZED
:
1081 case SW_FORCEMINIMIZE
: /* FIXME: Does not work if thread is hung. */
1082 swp
|= SWP_SHOWWINDOW
;
1085 swp
|= SWP_FRAMECHANGED
;
1086 if( !(wndPtr
->dwStyle
& WS_MINIMIZE
) )
1087 swp
|= WINPOS_MinMaximize( hwnd
, SW_MINIMIZE
, &newPos
);
1088 else swp
|= SWP_NOSIZE
| SWP_NOMOVE
;
1091 case SW_SHOWMAXIMIZED
: /* same as SW_MAXIMIZE */
1092 swp
|= SWP_SHOWWINDOW
| SWP_FRAMECHANGED
;
1093 if( !(wndPtr
->dwStyle
& WS_MAXIMIZE
) )
1094 swp
|= WINPOS_MinMaximize( hwnd
, SW_MAXIMIZE
, &newPos
);
1095 else swp
|= SWP_NOSIZE
| SWP_NOMOVE
;
1099 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1102 if (wasVisible
) goto END
;
1104 swp
|= SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
1108 swp
|= SWP_FRAMECHANGED
;
1110 case SW_SHOWNOACTIVATE
:
1111 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1113 case SW_SHOWNORMAL
: /* same as SW_NORMAL: */
1114 case SW_SHOWDEFAULT
: /* FIXME: should have its own handler */
1115 swp
|= SWP_SHOWWINDOW
;
1117 if( wndPtr
->dwStyle
& (WS_MINIMIZE
| WS_MAXIMIZE
) )
1118 swp
|= WINPOS_MinMaximize( hwnd
, SW_RESTORE
, &newPos
);
1119 else swp
|= SWP_NOSIZE
| SWP_NOMOVE
;
1123 showFlag
= (cmd
!= SW_HIDE
);
1124 if (showFlag
!= wasVisible
)
1126 SendMessageW( hwnd
, WM_SHOWWINDOW
, showFlag
, 0 );
1127 if (!IsWindow( hwnd
)) goto END
;
1130 /* ShowWindow won't activate a not being maximized child window */
1131 if ((wndPtr
->dwStyle
& WS_CHILD
) && cmd
!= SW_MAXIMIZE
)
1132 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1134 SetWindowPos( hwnd
, HWND_TOP
, newPos
.left
, newPos
.top
,
1135 newPos
.right
, newPos
.bottom
, LOWORD(swp
) );
1140 /* FIXME: This will cause the window to be activated irrespective
1141 * of whether it is owned by the same thread. Has to be done
1145 if (hwnd
== GetActiveWindow())
1146 WINPOS_ActivateOtherWindow(hwnd
);
1148 /* Revert focus to parent */
1149 hFocus
= GetFocus();
1150 if (hwnd
== hFocus
|| IsChild(hwnd
, hFocus
))
1152 HWND parent
= GetAncestor(hwnd
, GA_PARENT
);
1153 if (parent
== GetDesktopWindow()) parent
= 0;
1157 if (!IsWindow( hwnd
)) goto END
;
1158 else if( wndPtr
->dwStyle
& WS_MINIMIZE
) WINPOS_ShowIconTitle( hwnd
, TRUE
);
1160 if (wndPtr
->flags
& WIN_NEED_SIZE
)
1162 /* should happen only in CreateWindowEx() */
1163 int wParam
= SIZE_RESTORED
;
1165 wndPtr
->flags
&= ~WIN_NEED_SIZE
;
1166 if (wndPtr
->dwStyle
& WS_MAXIMIZE
) wParam
= SIZE_MAXIMIZED
;
1167 else if (wndPtr
->dwStyle
& WS_MINIMIZE
) wParam
= SIZE_MINIMIZED
;
1168 SendMessageA( hwnd
, WM_SIZE
, wParam
,
1169 MAKELONG(wndPtr
->rectClient
.right
-wndPtr
->rectClient
.left
,
1170 wndPtr
->rectClient
.bottom
-wndPtr
->rectClient
.top
));
1171 SendMessageA( hwnd
, WM_MOVE
, 0,
1172 MAKELONG(wndPtr
->rectClient
.left
, wndPtr
->rectClient
.top
) );
1176 WIN_ReleaseWndPtr(wndPtr
);
1181 /**********************************************************************
1184 void X11DRV_MapNotify( HWND hwnd
, XMapEvent
*event
)
1186 HWND hwndFocus
= GetFocus();
1189 if (!(win
= WIN_GetPtr( hwnd
))) return;
1191 if ((win
->dwStyle
& WS_VISIBLE
) &&
1192 (win
->dwStyle
& WS_MINIMIZE
) &&
1193 (win
->dwExStyle
& WS_EX_MANAGED
))
1195 struct x11drv_win_data
*data
= win
->pDriverData
;
1197 unsigned int width
, height
, border
, depth
;
1200 LONG style
= (win
->dwStyle
& ~(WS_MINIMIZE
|WS_MAXIMIZE
)) | WS_VISIBLE
;
1204 XGetGeometry( event
->display
, data
->whole_window
, &root
, &x
, &y
, &width
, &height
,
1206 XTranslateCoordinates( event
->display
, data
->whole_window
, root
, 0, 0, &x
, &y
, &top
);
1207 wine_tsx11_unlock();
1210 rect
.right
= x
+ width
;
1211 rect
.bottom
= y
+ height
;
1212 X11DRV_X_to_window_rect( hwnd
, &rect
);
1214 DCE_InvalidateDCE( hwnd
, &win
->rectWindow
);
1216 if (win
->flags
& WIN_RESTORE_MAX
) style
|= WS_MAXIMIZE
;
1217 WIN_SetStyle( hwnd
, style
);
1218 WIN_ReleasePtr( win
);
1220 SendMessageA( hwnd
, WM_SHOWWINDOW
, SW_RESTORE
, 0 );
1221 SetWindowPos( hwnd
, 0, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
,
1222 SWP_NOZORDER
| SWP_WINE_NOHOSTMOVE
);
1224 else WIN_ReleasePtr( win
);
1225 if (hwndFocus
&& IsChild( hwnd
, hwndFocus
)) X11DRV_SetFocus(hwndFocus
); /* FIXME */
1229 /**********************************************************************
1230 * X11DRV_UnmapNotify
1232 void X11DRV_UnmapNotify( HWND hwnd
, XUnmapEvent
*event
)
1236 if (!(win
= WIN_GetPtr( hwnd
))) return;
1238 if ((win
->dwStyle
& WS_VISIBLE
) && (win
->dwExStyle
& WS_EX_MANAGED
) &&
1239 X11DRV_is_window_rect_mapped( &win
->rectWindow
))
1241 if (win
->dwStyle
& WS_MAXIMIZE
)
1242 win
->flags
|= WIN_RESTORE_MAX
;
1244 win
->flags
&= ~WIN_RESTORE_MAX
;
1246 WIN_SetStyle( hwnd
, (win
->dwStyle
& ~WS_MAXIMIZE
) | WS_MINIMIZE
);
1247 WIN_ReleasePtr( win
);
1250 SendMessageA( hwnd
, WM_SHOWWINDOW
, SW_MINIMIZE
, 0 );
1251 SetWindowPos( hwnd
, 0, 0, 0, GetSystemMetrics(SM_CXICON
), GetSystemMetrics(SM_CYICON
),
1252 SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_WINE_NOHOSTMOVE
);
1254 else WIN_ReleasePtr( win
);
1258 /***********************************************************************
1261 * Synchronize internal z-order with the window manager's.
1263 static Window
__get_common_ancestor( Display
*display
, Window A
, Window B
,
1264 Window
** children
, unsigned* total
)
1266 /* find the real root window */
1268 Window root
, *childrenB
;
1272 while( A
!= B
&& A
&& B
)
1274 XQueryTree( display
, A
, &root
, &A
, children
, total
);
1275 XQueryTree( display
, B
, &root
, &B
, &childrenB
, &totalB
);
1276 if( childrenB
) XFree( childrenB
);
1277 if( *children
) XFree( *children
), *children
= NULL
;
1282 XQueryTree( display
, A
, &root
, &B
, children
, total
);
1283 wine_tsx11_unlock();
1286 wine_tsx11_unlock();
1290 static Window
__get_top_decoration( Display
*display
, Window w
, Window ancestor
)
1292 Window
* children
, root
, prev
= w
, parent
= w
;
1299 XQueryTree( display
, w
, &root
, &parent
, &children
, &total
);
1300 if( children
) XFree( children
);
1301 } while( parent
&& parent
!= ancestor
);
1302 wine_tsx11_unlock();
1303 TRACE("\t%08x -> %08x\n", (unsigned)prev
, (unsigned)w
);
1304 return ( parent
) ? w
: 0 ;
1307 static unsigned __td_lookup( Window w
, Window
* list
, unsigned max
)
1310 for( i
= max
; i
> 0; i
-- ) if( list
[i
- 1] == w
) break;
1314 static HWND
query_zorder( Display
*display
, HWND hWndCheck
)
1316 HWND hwndInsertAfter
= HWND_TOP
;
1317 Window w
, parent
, *children
= NULL
;
1318 unsigned total
, check
, pos
, best
;
1319 HWND
*list
= WIN_ListChildren( GetDesktopWindow() );
1320 HWND hwndA
= 0, hwndB
= 0;
1323 /* find at least two managed windows */
1324 if (!list
) return 0;
1325 for (i
= 0; list
[i
]; i
++)
1327 if (!(GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_MANAGED
)) continue;
1328 if (!(GetWindowLongW( list
[i
], GWL_STYLE
) & WS_VISIBLE
)) continue;
1329 if (!hwndA
) hwndA
= list
[i
];
1336 if (!hwndA
|| !hwndB
) goto done
;
1338 parent
= __get_common_ancestor( display
, X11DRV_get_whole_window(hwndA
),
1339 X11DRV_get_whole_window(hwndB
), &children
, &total
);
1340 if( parent
&& children
)
1342 /* w is the ancestor if hWndCheck that is a direct descendant of 'parent' */
1344 w
= __get_top_decoration( display
, X11DRV_get_whole_window(hWndCheck
), parent
);
1346 if( w
!= children
[total
-1] ) /* check if at the top */
1348 /* X child at index 0 is at the bottom, at index total-1 is at the top */
1349 check
= __td_lookup( w
, children
, total
);
1352 /* go through all windows in Wine z-order... */
1353 for (i
= 0; list
[i
]; i
++)
1355 if (list
[i
] == hWndCheck
) continue;
1356 if (!(GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_MANAGED
)) continue;
1357 if (!(w
= __get_top_decoration( display
, X11DRV_get_whole_window(list
[i
]),
1358 parent
))) continue;
1359 pos
= __td_lookup( w
, children
, total
);
1360 if( pos
< best
&& pos
> check
)
1362 /* find a nearest Wine window precedes hWndCheck in the real z-order */
1364 hwndInsertAfter
= list
[i
];
1366 if( best
- check
== 1 ) break;
1371 if( children
) XFree( children
);
1372 wine_tsx11_unlock();
1375 HeapFree( GetProcessHeap(), 0, list
);
1376 return hwndInsertAfter
;
1380 /***********************************************************************
1381 * X11DRV_handle_desktop_resize
1383 void X11DRV_handle_desktop_resize( unsigned int width
, unsigned int height
)
1386 HWND hwnd
= GetDesktopWindow();
1388 screen_width
= width
;
1389 screen_height
= height
;
1390 TRACE("desktop %p change to (%dx%d)\n", hwnd
, width
, height
);
1391 SetRect( &rect
, 0, 0, width
, height
);
1392 X11DRV_set_window_pos( hwnd
, 0, &rect
, &rect
, SWP_NOZORDER
|SWP_NOMOVE
|SWP_WINE_NOHOSTMOVE
, 0 );
1393 SendMessageTimeoutW( HWND_BROADCAST
, WM_DISPLAYCHANGE
, screen_depth
,
1394 MAKELPARAM( width
, height
), SMTO_ABORTIFHUNG
, 2000, NULL
);
1398 /***********************************************************************
1399 * X11DRV_ConfigureNotify
1401 void X11DRV_ConfigureNotify( HWND hwnd
, XConfigureEvent
*event
)
1403 HWND oldInsertAfter
;
1404 struct x11drv_win_data
*data
;
1407 int x
= event
->x
, y
= event
->y
;
1409 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1413 if (!event
->send_event
) /* normal event, need to map coordinates to the root */
1417 XTranslateCoordinates( event
->display
, data
->whole_window
, root_window
,
1418 0, 0, &x
, &y
, &child
);
1419 wine_tsx11_unlock();
1423 rect
.right
= x
+ event
->width
;
1424 rect
.bottom
= y
+ event
->height
;
1425 TRACE( "win %p new X rect %ld,%ld,%ldx%ld (event %d,%d,%dx%d)\n",
1426 hwnd
, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
,
1427 event
->x
, event
->y
, event
->width
, event
->height
);
1428 X11DRV_X_to_window_rect( hwnd
, &rect
);
1431 winpos
.x
= rect
.left
;
1432 winpos
.y
= rect
.top
;
1433 winpos
.cx
= rect
.right
- rect
.left
;
1434 winpos
.cy
= rect
.bottom
- rect
.top
;
1435 winpos
.flags
= SWP_NOACTIVATE
;
1437 /* Get Z-order (FIXME) */
1439 winpos
.hwndInsertAfter
= query_zorder( event
->display
, hwnd
);
1441 /* needs to find the first Visible Window above the current one */
1442 oldInsertAfter
= hwnd
;
1445 oldInsertAfter
= GetWindow( oldInsertAfter
, GW_HWNDPREV
);
1446 if (!oldInsertAfter
)
1448 oldInsertAfter
= HWND_TOP
;
1451 if (GetWindowLongA( oldInsertAfter
, GWL_STYLE
) & WS_VISIBLE
) break;
1454 /* Compare what has changed */
1456 GetWindowRect( hwnd
, &rect
);
1457 if (rect
.left
== winpos
.x
&& rect
.top
== winpos
.y
) winpos
.flags
|= SWP_NOMOVE
;
1459 TRACE( "%p moving from (%ld,%ld) to (%d,%d)\n",
1460 hwnd
, rect
.left
, rect
.top
, winpos
.x
, winpos
.y
);
1462 if ((rect
.right
- rect
.left
== winpos
.cx
&& rect
.bottom
- rect
.top
== winpos
.cy
) ||
1464 (IsRectEmpty( &rect
) && winpos
.cx
== 1 && winpos
.cy
== 1))
1465 winpos
.flags
|= SWP_NOSIZE
;
1467 TRACE( "%p resizing from (%ldx%ld) to (%dx%d)\n",
1468 hwnd
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
1469 winpos
.cx
, winpos
.cy
);
1471 if (winpos
.hwndInsertAfter
== oldInsertAfter
) winpos
.flags
|= SWP_NOZORDER
;
1473 TRACE( "%p restacking from after %p to after %p\n",
1474 hwnd
, oldInsertAfter
, winpos
.hwndInsertAfter
);
1476 /* if nothing changed, don't do anything */
1477 if (winpos
.flags
== (SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
)) return;
1479 SetWindowPos( hwnd
, winpos
.hwndInsertAfter
, winpos
.x
, winpos
.y
,
1480 winpos
.cx
, winpos
.cy
, winpos
.flags
| SWP_WINE_NOHOSTMOVE
);
1484 /***********************************************************************
1485 * SetWindowRgn (X11DRV.@)
1487 * Assign specified region to window (for non-rectangular windows)
1489 int X11DRV_SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL redraw
)
1491 struct x11drv_win_data
*data
;
1493 if (!(data
= X11DRV_get_win_data( hwnd
)))
1495 if (IsWindow( hwnd
))
1496 FIXME( "not supported on other process window %p\n", hwnd
);
1497 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
1501 #ifdef HAVE_LIBXSHAPE
1502 if (data
->whole_window
)
1504 Display
*display
= thread_display();
1509 XShapeCombineMask( display
, data
->whole_window
,
1510 ShapeBounding
, 0, 0, None
, ShapeSet
);
1511 wine_tsx11_unlock();
1515 RGNDATA
*pRegionData
= X11DRV_GetRegionData( hrgn
, 0 );
1519 XShapeCombineRectangles( display
, data
->whole_window
, ShapeBounding
,
1520 data
->window_rect
.left
- data
->whole_rect
.left
,
1521 data
->window_rect
.top
- data
->whole_rect
.top
,
1522 (XRectangle
*)pRegionData
->Buffer
,
1523 pRegionData
->rdh
.nCount
,
1524 ShapeSet
, YXBanded
);
1525 wine_tsx11_unlock();
1526 HeapFree(GetProcessHeap(), 0, pRegionData
);
1530 #endif /* HAVE_LIBXSHAPE */
1536 /***********************************************************************
1539 * Draw the frame used when moving or resizing window.
1541 * FIXME: This causes problems in Win95 mode. (why?)
1543 static void draw_moving_frame( HDC hdc
, RECT
*rect
, BOOL thickframe
)
1547 const int width
= GetSystemMetrics(SM_CXFRAME
);
1548 const int height
= GetSystemMetrics(SM_CYFRAME
);
1550 HBRUSH hbrush
= SelectObject( hdc
, GetStockObject( GRAY_BRUSH
) );
1551 PatBlt( hdc
, rect
->left
, rect
->top
,
1552 rect
->right
- rect
->left
- width
, height
, PATINVERT
);
1553 PatBlt( hdc
, rect
->left
, rect
->top
+ height
, width
,
1554 rect
->bottom
- rect
->top
- height
, PATINVERT
);
1555 PatBlt( hdc
, rect
->left
+ width
, rect
->bottom
- 1,
1556 rect
->right
- rect
->left
- width
, -height
, PATINVERT
);
1557 PatBlt( hdc
, rect
->right
- 1, rect
->top
, -width
,
1558 rect
->bottom
- rect
->top
- height
, PATINVERT
);
1559 SelectObject( hdc
, hbrush
);
1561 else DrawFocusRect( hdc
, rect
);
1565 /***********************************************************************
1568 * Initialisation of a move or resize, when initiatied from a menu choice.
1569 * Return hit test code for caption or sizing border.
1571 static LONG
start_size_move( HWND hwnd
, WPARAM wParam
, POINT
*capturePoint
, LONG style
)
1578 GetWindowRect( hwnd
, &rectWindow
);
1580 if ((wParam
& 0xfff0) == SC_MOVE
)
1582 /* Move pointer at the center of the caption */
1583 RECT rect
= rectWindow
;
1584 /* Note: to be exactly centered we should take the different types
1585 * of border into account, but it shouldn't make more that a few pixels
1586 * of difference so let's not bother with that */
1587 rect
.top
+= GetSystemMetrics(SM_CYBORDER
);
1588 if (style
& WS_SYSMENU
)
1589 rect
.left
+= GetSystemMetrics(SM_CXSIZE
) + 1;
1590 if (style
& WS_MINIMIZEBOX
)
1591 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
1592 if (style
& WS_MAXIMIZEBOX
)
1593 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
1594 pt
.x
= (rect
.right
+ rect
.left
) / 2;
1595 pt
.y
= rect
.top
+ GetSystemMetrics(SM_CYSIZE
)/2;
1596 hittest
= HTCAPTION
;
1603 GetMessageW( &msg
, 0, WM_KEYFIRST
, WM_MOUSELAST
);
1604 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
1610 hittest
= SendMessageW( hwnd
, WM_NCHITTEST
, 0, MAKELONG( pt
.x
, pt
.y
) );
1611 if ((hittest
< HTLEFT
) || (hittest
> HTBOTTOMRIGHT
)) hittest
= 0;
1622 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
1623 pt
.y
= rectWindow
.top
+ GetSystemMetrics(SM_CYFRAME
) / 2;
1627 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
1628 pt
.y
= rectWindow
.bottom
- GetSystemMetrics(SM_CYFRAME
) / 2;
1632 pt
.x
= rectWindow
.left
+ GetSystemMetrics(SM_CXFRAME
) / 2;
1633 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
1637 pt
.x
= rectWindow
.right
- GetSystemMetrics(SM_CXFRAME
) / 2;
1638 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
1641 case VK_ESCAPE
: return 0;
1647 SetCursorPos( pt
.x
, pt
.y
);
1648 SendMessageW( hwnd
, WM_SETCURSOR
, (WPARAM
)hwnd
, MAKELONG( hittest
, WM_MOUSEMOVE
));
1653 /***********************************************************************
1654 * set_movesize_capture
1656 static void set_movesize_capture( HWND hwnd
)
1660 SERVER_START_REQ( set_capture_window
)
1663 req
->flags
= CAPTURE_MOVESIZE
;
1664 if (!wine_server_call_err( req
))
1666 previous
= reply
->previous
;
1667 hwnd
= reply
->full_handle
;
1671 if (previous
&& previous
!= hwnd
)
1672 SendMessageW( previous
, WM_CAPTURECHANGED
, 0, (LPARAM
)hwnd
);
1675 /***********************************************************************
1676 * X11DRV_WMMoveResizeWindow
1678 * Tells the window manager to initiate a move or resize operation.
1681 * http://freedesktop.org/Standards/wm-spec/1.3/ar01s04.html
1682 * or search for "_NET_WM_MOVERESIZE"
1684 static void X11DRV_WMMoveResizeWindow( HWND hwnd
, int x
, int y
, int dir
)
1687 Display
*display
= thread_display();
1689 xev
.xclient
.type
= ClientMessage
;
1690 xev
.xclient
.window
= X11DRV_get_whole_window(hwnd
);
1691 xev
.xclient
.message_type
= x11drv_atom(_NET_WM_MOVERESIZE
);
1692 xev
.xclient
.serial
= 0;
1693 xev
.xclient
.display
= display
;
1694 xev
.xclient
.send_event
= True
;
1695 xev
.xclient
.format
= 32;
1696 xev
.xclient
.data
.l
[0] = x
; /* x coord */
1697 xev
.xclient
.data
.l
[1] = y
; /* y coord */
1698 xev
.xclient
.data
.l
[2] = dir
; /* direction */
1699 xev
.xclient
.data
.l
[3] = 1; /* button */
1700 xev
.xclient
.data
.l
[4] = 0; /* unused */
1702 /* need to ungrab the pointer that may have been automatically grabbed
1703 * with a ButtonPress event */
1705 XUngrabPointer( display
, CurrentTime
);
1706 XSendEvent(display
, root_window
, False
, SubstructureNotifyMask
, &xev
);
1707 wine_tsx11_unlock();
1710 /***********************************************************************
1711 * SysCommandSizeMove (X11DRV.@)
1713 * Perform SC_MOVE and SC_SIZE commands.
1715 void X11DRV_SysCommandSizeMove( HWND hwnd
, WPARAM wParam
)
1718 RECT sizingRect
, mouseRect
, origRect
;
1721 LONG hittest
= (LONG
)(wParam
& 0x0f);
1722 WPARAM syscommand
= wParam
& 0xfff0;
1723 HCURSOR hDragCursor
= 0, hOldCursor
= 0;
1724 POINT minTrack
, maxTrack
;
1725 POINT capturePoint
, pt
;
1726 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
1727 LONG exstyle
= GetWindowLongA( hwnd
, GWL_EXSTYLE
);
1728 BOOL thickframe
= HAS_THICKFRAME( style
, exstyle
);
1729 BOOL iconic
= style
& WS_MINIMIZE
;
1731 DWORD dwPoint
= GetMessagePos ();
1732 BOOL DragFullWindows
= FALSE
;
1734 Window parent_win
, whole_win
;
1735 Display
*old_gdi_display
= NULL
;
1736 Display
*display
= thread_display();
1738 pt
.x
= (short)LOWORD(dwPoint
);
1739 pt
.y
= (short)HIWORD(dwPoint
);
1742 if (IsZoomed(hwnd
) || !IsWindowVisible(hwnd
)) return;
1744 /* if we are managed then we let the WM do all the work */
1745 if (exstyle
& WS_EX_MANAGED
)
1748 if (syscommand
== SC_MOVE
)
1750 if (!hittest
) dir
= _NET_WM_MOVERESIZE_MOVE_KEYBOARD
;
1751 else dir
= _NET_WM_MOVERESIZE_MOVE
;
1753 else if (!hittest
) dir
= _NET_WM_MOVERESIZE_SIZE_KEYBOARD
;
1757 case WMSZ_LEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_LEFT
; break;
1758 case WMSZ_RIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_RIGHT
; break;
1759 case WMSZ_TOP
: dir
= _NET_WM_MOVERESIZE_SIZE_TOP
; break;
1760 case WMSZ_TOPLEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_TOPLEFT
; break;
1761 case WMSZ_TOPRIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_TOPRIGHT
; break;
1762 case WMSZ_BOTTOM
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOM
; break;
1763 case WMSZ_BOTTOMLEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT
; break;
1764 case WMSZ_BOTTOMRIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT
; break;
1766 ERR("Invalid hittest value: %ld\n", hittest
);
1767 dir
= _NET_WM_MOVERESIZE_SIZE_KEYBOARD
;
1769 X11DRV_WMMoveResizeWindow( hwnd
, pt
.x
, pt
.y
, dir
);
1773 SystemParametersInfoA(SPI_GETDRAGFULLWINDOWS
, 0, &DragFullWindows
, 0);
1775 if (syscommand
== SC_MOVE
)
1777 if (!hittest
) hittest
= start_size_move( hwnd
, wParam
, &capturePoint
, style
);
1778 if (!hittest
) return;
1782 if ( hittest
&& (syscommand
!= SC_MOUSEMENU
) )
1783 hittest
+= (HTLEFT
- WMSZ_LEFT
);
1786 set_movesize_capture( hwnd
);
1787 hittest
= start_size_move( hwnd
, wParam
, &capturePoint
, style
);
1790 set_movesize_capture(0);
1796 /* Get min/max info */
1798 WINPOS_GetMinMaxInfo( hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
1799 GetWindowRect( hwnd
, &sizingRect
);
1800 if (style
& WS_CHILD
)
1802 parent
= GetParent(hwnd
);
1803 /* make sizing rect relative to parent */
1804 MapWindowPoints( 0, parent
, (POINT
*)&sizingRect
, 2 );
1805 GetClientRect( parent
, &mouseRect
);
1810 SetRect(&mouseRect
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
));
1812 origRect
= sizingRect
;
1814 if (ON_LEFT_BORDER(hittest
))
1816 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.right
-maxTrack
.x
);
1817 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.right
-minTrack
.x
);
1819 else if (ON_RIGHT_BORDER(hittest
))
1821 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.left
+minTrack
.x
);
1822 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.left
+maxTrack
.x
);
1824 if (ON_TOP_BORDER(hittest
))
1826 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.bottom
-maxTrack
.y
);
1827 mouseRect
.bottom
= min( mouseRect
.bottom
,sizingRect
.bottom
-minTrack
.y
);
1829 else if (ON_BOTTOM_BORDER(hittest
))
1831 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.top
+minTrack
.y
);
1832 mouseRect
.bottom
= min( mouseRect
.bottom
, sizingRect
.top
+maxTrack
.y
);
1834 if (parent
) MapWindowPoints( parent
, 0, (LPPOINT
)&mouseRect
, 2 );
1836 /* Retrieve a default cache DC (without using the window style) */
1837 hdc
= GetDCEx( parent
, 0, DCX_CACHE
);
1839 if( iconic
) /* create a cursor for dragging */
1841 hDragCursor
= (HCURSOR
)GetClassLongA( hwnd
, GCL_HICON
);
1842 if( !hDragCursor
) hDragCursor
= (HCURSOR
)SendMessageA( hwnd
, WM_QUERYDRAGICON
, 0, 0L);
1843 if( !hDragCursor
) iconic
= FALSE
;
1846 /* repaint the window before moving it around */
1847 RedrawWindow( hwnd
, NULL
, 0, RDW_UPDATENOW
| RDW_ALLCHILDREN
);
1849 SendMessageA( hwnd
, WM_ENTERSIZEMOVE
, 0, 0 );
1850 set_movesize_capture( hwnd
);
1852 /* grab the server only when moving top-level windows without desktop */
1853 grab
= (!DragFullWindows
&& !parent
&& (root_window
== DefaultRootWindow(gdi_display
)));
1858 XSync( gdi_display
, False
);
1859 XGrabServer( display
);
1860 XSync( display
, False
);
1861 /* switch gdi display to the thread display, since the server is grabbed */
1862 old_gdi_display
= gdi_display
;
1863 gdi_display
= display
;
1864 wine_tsx11_unlock();
1866 whole_win
= X11DRV_get_whole_window(hwnd
);
1867 parent_win
= parent
? X11DRV_get_client_window(parent
) : root_window
;
1870 XGrabPointer( display
, whole_win
, False
,
1871 PointerMotionMask
| ButtonPressMask
| ButtonReleaseMask
,
1872 GrabModeAsync
, GrabModeAsync
, parent_win
, None
, CurrentTime
);
1873 wine_tsx11_unlock();
1879 if (!GetMessageW( &msg
, 0, WM_KEYFIRST
, WM_MOUSELAST
)) break;
1880 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
1882 /* Exit on button-up, Return, or Esc */
1883 if ((msg
.message
== WM_LBUTTONUP
) ||
1884 ((msg
.message
== WM_KEYDOWN
) &&
1885 ((msg
.wParam
== VK_RETURN
) || (msg
.wParam
== VK_ESCAPE
)))) break;
1887 if ((msg
.message
!= WM_KEYDOWN
) && (msg
.message
!= WM_MOUSEMOVE
))
1888 continue; /* We are not interested in other messages */
1892 if (msg
.message
== WM_KEYDOWN
) switch(msg
.wParam
)
1894 case VK_UP
: pt
.y
-= 8; break;
1895 case VK_DOWN
: pt
.y
+= 8; break;
1896 case VK_LEFT
: pt
.x
-= 8; break;
1897 case VK_RIGHT
: pt
.x
+= 8; break;
1900 pt
.x
= max( pt
.x
, mouseRect
.left
);
1901 pt
.x
= min( pt
.x
, mouseRect
.right
);
1902 pt
.y
= max( pt
.y
, mouseRect
.top
);
1903 pt
.y
= min( pt
.y
, mouseRect
.bottom
);
1905 dx
= pt
.x
- capturePoint
.x
;
1906 dy
= pt
.y
- capturePoint
.y
;
1914 if( iconic
) /* ok, no system popup tracking */
1916 hOldCursor
= SetCursor(hDragCursor
);
1918 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1920 else if(!DragFullWindows
)
1921 draw_moving_frame( hdc
, &sizingRect
, thickframe
);
1924 if (msg
.message
== WM_KEYDOWN
) SetCursorPos( pt
.x
, pt
.y
);
1927 RECT newRect
= sizingRect
;
1928 WPARAM wpSizingHit
= 0;
1930 if (hittest
== HTCAPTION
) OffsetRect( &newRect
, dx
, dy
);
1931 if (ON_LEFT_BORDER(hittest
)) newRect
.left
+= dx
;
1932 else if (ON_RIGHT_BORDER(hittest
)) newRect
.right
+= dx
;
1933 if (ON_TOP_BORDER(hittest
)) newRect
.top
+= dy
;
1934 else if (ON_BOTTOM_BORDER(hittest
)) newRect
.bottom
+= dy
;
1935 if(!iconic
&& !DragFullWindows
) draw_moving_frame( hdc
, &sizingRect
, thickframe
);
1938 /* determine the hit location */
1939 if (hittest
>= HTLEFT
&& hittest
<= HTBOTTOMRIGHT
)
1940 wpSizingHit
= WMSZ_LEFT
+ (hittest
- HTLEFT
);
1941 SendMessageA( hwnd
, WM_SIZING
, wpSizingHit
, (LPARAM
)&newRect
);
1945 if(!DragFullWindows
)
1946 draw_moving_frame( hdc
, &newRect
, thickframe
);
1948 SetWindowPos( hwnd
, 0, newRect
.left
, newRect
.top
,
1949 newRect
.right
- newRect
.left
,
1950 newRect
.bottom
- newRect
.top
,
1951 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
1953 sizingRect
= newRect
;
1958 set_movesize_capture(0);
1961 if( moved
) /* restore cursors, show icon title later on */
1963 ShowCursor( FALSE
);
1964 SetCursor( hOldCursor
);
1967 else if (moved
&& !DragFullWindows
)
1968 draw_moving_frame( hdc
, &sizingRect
, thickframe
);
1970 ReleaseDC( parent
, hdc
);
1973 XUngrabPointer( display
, CurrentTime
);
1976 XSync( display
, False
);
1977 XUngrabServer( display
);
1978 XSync( display
, False
);
1979 gdi_display
= old_gdi_display
;
1981 wine_tsx11_unlock();
1983 if (HOOK_CallHooks( WH_CBT
, HCBT_MOVESIZE
, (WPARAM
)hwnd
, (LPARAM
)&sizingRect
, TRUE
))
1986 SendMessageA( hwnd
, WM_EXITSIZEMOVE
, 0, 0 );
1987 SendMessageA( hwnd
, WM_SETVISIBLE
, !IsIconic(hwnd
), 0L);
1989 /* window moved or resized */
1992 /* if the moving/resizing isn't canceled call SetWindowPos
1993 * with the new position or the new size of the window
1995 if (!((msg
.message
== WM_KEYDOWN
) && (msg
.wParam
== VK_ESCAPE
)) )
1997 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
1998 if(!DragFullWindows
)
1999 SetWindowPos( hwnd
, 0, sizingRect
.left
, sizingRect
.top
,
2000 sizingRect
.right
- sizingRect
.left
,
2001 sizingRect
.bottom
- sizingRect
.top
,
2002 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
2005 { /* restore previous size/position */
2007 SetWindowPos( hwnd
, 0, origRect
.left
, origRect
.top
,
2008 origRect
.right
- origRect
.left
,
2009 origRect
.bottom
- origRect
.top
,
2010 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
2016 /* Single click brings up the system menu when iconized */
2020 if(style
& WS_SYSMENU
)
2021 SendMessageA( hwnd
, WM_SYSCOMMAND
,
2022 SC_MOUSEMENU
+ HTSYSMENU
, MAKELONG(pt
.x
,pt
.y
));
2024 else WINPOS_ShowIconTitle( hwnd
, TRUE
);