2 * Window position related functions.
4 * Copyright 1993, 1994, 1995, 2001 Alexandre Julliard
5 * Copyright 1995, 1996, 1999 Alex Korobka
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include <X11/Xutil.h>
27 #include <X11/extensions/shape.h>
28 #endif /* HAVE_LIBXSHAPE */
36 #include "wine/wingdi16.h"
41 #include "wine/server.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(x11drv
);
46 #define SWP_AGG_NOPOSCHANGE \
47 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_NOZORDER)
49 #define SWP_EX_NOCOPY 0x0001
50 #define SWP_EX_PAINTSELF 0x0002
51 #define SWP_EX_NONCLIENT 0x0004
53 #define HAS_THICKFRAME(style) \
54 (((style) & WS_THICKFRAME) && \
55 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
57 #define ON_LEFT_BORDER(hit) \
58 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
59 #define ON_RIGHT_BORDER(hit) \
60 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
61 #define ON_TOP_BORDER(hit) \
62 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
63 #define ON_BOTTOM_BORDER(hit) \
64 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
66 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
67 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
68 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
69 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
70 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
71 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
72 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
73 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
74 #define _NET_WM_MOVERESIZE_MOVE 8 /* movement only */
75 #define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9 /* size via keyboard */
76 #define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10 /* move via keyboard */
78 #define _NET_WM_STATE_REMOVE 0
79 #define _NET_WM_STATE_ADD 1
80 #define _NET_WM_STATE_TOGGLE 2
82 static const char managed_prop
[] = "__wine_x11_managed";
84 /***********************************************************************
87 void X11DRV_Expose( HWND hwnd
, XEvent
*xev
)
89 XExposeEvent
*event
= &xev
->xexpose
;
91 struct x11drv_win_data
*data
;
92 int flags
= RDW_INVALIDATE
| RDW_ERASE
| RDW_ALLCHILDREN
;
94 TRACE( "win %p (%lx) %d,%d %dx%d\n",
95 hwnd
, event
->window
, event
->x
, event
->y
, event
->width
, event
->height
);
97 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
101 rect
.right
= rect
.left
+ event
->width
;
102 rect
.bottom
= rect
.top
+ event
->height
;
104 if (event
->window
== root_window
)
105 OffsetRect( &rect
, virtual_screen_rect
.left
, virtual_screen_rect
.top
);
107 if (rect
.left
< data
->client_rect
.left
||
108 rect
.top
< data
->client_rect
.top
||
109 rect
.right
> data
->client_rect
.right
||
110 rect
.bottom
> data
->client_rect
.bottom
) flags
|= RDW_FRAME
;
112 SERVER_START_REQ( update_window_zorder
)
115 req
->rect
.left
= rect
.left
+ data
->whole_rect
.left
;
116 req
->rect
.top
= rect
.top
+ data
->whole_rect
.top
;
117 req
->rect
.right
= rect
.right
+ data
->whole_rect
.left
;
118 req
->rect
.bottom
= rect
.bottom
+ data
->whole_rect
.top
;
119 wine_server_call( req
);
123 /* make position relative to client area instead of window */
124 OffsetRect( &rect
, -data
->client_rect
.left
, -data
->client_rect
.top
);
125 RedrawWindow( hwnd
, &rect
, 0, flags
);
128 /***********************************************************************
129 * SetWindowStyle (X11DRV.@)
131 * Update the X state of a window to reflect a style change
133 void X11DRV_SetWindowStyle( HWND hwnd
, DWORD old_style
)
135 Display
*display
= thread_display();
136 struct x11drv_win_data
*data
;
137 DWORD new_style
, changed
;
139 if (hwnd
== GetDesktopWindow()) return;
140 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
142 new_style
= GetWindowLongW( hwnd
, GWL_STYLE
);
143 changed
= new_style
^ old_style
;
145 if (changed
& WS_VISIBLE
)
147 if (data
->whole_window
&& X11DRV_is_window_rect_mapped( &data
->window_rect
))
149 if (new_style
& WS_VISIBLE
)
151 TRACE( "mapping win %p\n", hwnd
);
152 X11DRV_sync_window_style( display
, data
);
153 X11DRV_set_wm_hints( display
, data
);
155 XMapWindow( display
, data
->whole_window
);
158 /* we don't unmap windows, that causes trouble with the window manager */
160 invalidate_dce( hwnd
, &data
->window_rect
);
163 if (changed
& WS_DISABLED
)
165 if (data
->whole_window
&& data
->wm_hints
)
168 data
->wm_hints
->input
= !(new_style
& WS_DISABLED
);
169 XSetWMHints( display
, data
->whole_window
, data
->wm_hints
);
176 /***********************************************************************
177 * update_fullscreen_state
179 * Use the NETWM protocol to set the fullscreen state.
180 * This only works for mapped windows.
182 static void update_fullscreen_state( Display
*display
, Window win
, BOOL new_fs_state
)
186 TRACE("setting fullscreen state for window %lx to %s\n", win
, new_fs_state
? "true" : "false");
188 xev
.xclient
.type
= ClientMessage
;
189 xev
.xclient
.window
= win
;
190 xev
.xclient
.message_type
= x11drv_atom(_NET_WM_STATE
);
191 xev
.xclient
.serial
= 0;
192 xev
.xclient
.display
= display
;
193 xev
.xclient
.send_event
= True
;
194 xev
.xclient
.format
= 32;
195 xev
.xclient
.data
.l
[0] = new_fs_state
? _NET_WM_STATE_ADD
: _NET_WM_STATE_REMOVE
;
196 xev
.xclient
.data
.l
[1] = x11drv_atom(_NET_WM_STATE_FULLSCREEN
);
197 xev
.xclient
.data
.l
[2] = 0;
199 XSendEvent(display
, root_window
, False
, SubstructureRedirectMask
| SubstructureNotifyMask
, &xev
);
203 /***********************************************************************
204 * fullscreen_state_changed
206 * Check if the fullscreen state of a given window has changed
208 static BOOL
fullscreen_state_changed( const struct x11drv_win_data
*data
,
209 const RECT
*old_client_rect
, const RECT
*old_screen_rect
,
212 BOOL old_fs_state
= FALSE
;
214 *new_fs_state
= FALSE
;
216 if (old_client_rect
->left
<= 0 && old_client_rect
->right
>= old_screen_rect
->right
&&
217 old_client_rect
->top
<= 0 && old_client_rect
->bottom
>= old_screen_rect
->bottom
)
220 if (data
->client_rect
.left
<= 0 && data
->client_rect
.right
>= screen_width
&&
221 data
->client_rect
.top
<= 0 && data
->client_rect
.bottom
>= screen_height
)
222 *new_fs_state
= TRUE
;
224 #if 0 /* useful to debug fullscreen state problems */
225 TRACE("hwnd %p, old rect %s, new rect %s, old screen %s, new screen (0,0-%d,%d)\n",
227 wine_dbgstr_rect(old_client_rect
), wine_dbgstr_rect(&data
->client_rect
),
228 wine_dbgstr_rect(old_screen_rect
), screen_width
, screen_height
);
229 TRACE("old fs state %d\n, new fs state = %d\n", old_fs_state
, *new_fs_state
);
231 return *new_fs_state
!= old_fs_state
;
235 /***********************************************************************
236 * SetWindowPos (X11DRV.@)
238 BOOL
X11DRV_SetWindowPos( HWND hwnd
, HWND insert_after
, const RECT
*rectWindow
,
239 const RECT
*rectClient
, UINT swp_flags
, const RECT
*valid_rects
)
241 Display
*display
= thread_display();
242 struct x11drv_win_data
*data
;
243 RECT new_whole_rect
, old_client_rect
, old_screen_rect
;
245 DWORD old_style
, new_style
;
246 BOOL ret
, make_managed
= FALSE
;
248 if (!(data
= X11DRV_get_win_data( hwnd
))) return FALSE
;
250 /* check if we need to switch the window to managed */
251 if (!data
->managed
&& data
->whole_window
&& managed_mode
&&
252 root_window
== DefaultRootWindow( display
) &&
253 data
->whole_window
!= root_window
)
255 if (is_window_managed( hwnd
, swp_flags
, rectWindow
))
257 TRACE( "making win %p/%lx managed\n", hwnd
, data
->whole_window
);
259 data
->managed
= TRUE
;
260 SetPropA( hwnd
, managed_prop
, (HANDLE
)1 );
264 new_whole_rect
= *rectWindow
;
265 X11DRV_window_to_X_rect( data
, &new_whole_rect
);
267 old_client_rect
= data
->client_rect
;
269 if (!(win
= WIN_GetPtr( hwnd
))) return FALSE
;
270 if (win
== WND_OTHER_PROCESS
)
272 if (IsWindow( hwnd
)) ERR( "cannot set rectangles of other process window %p\n", hwnd
);
275 SERVER_START_REQ( set_window_pos
)
278 req
->previous
= insert_after
;
279 req
->flags
= swp_flags
;
280 req
->window
.left
= rectWindow
->left
;
281 req
->window
.top
= rectWindow
->top
;
282 req
->window
.right
= rectWindow
->right
;
283 req
->window
.bottom
= rectWindow
->bottom
;
284 req
->client
.left
= rectClient
->left
;
285 req
->client
.top
= rectClient
->top
;
286 req
->client
.right
= rectClient
->right
;
287 req
->client
.bottom
= rectClient
->bottom
;
288 if (memcmp( rectWindow
, &new_whole_rect
, sizeof(RECT
) ) || !IsRectEmpty( &valid_rects
[0] ))
290 wine_server_add_data( req
, &new_whole_rect
, sizeof(new_whole_rect
) );
291 if (!IsRectEmpty( &valid_rects
[0] ))
292 wine_server_add_data( req
, valid_rects
, 2 * sizeof(*valid_rects
) );
294 ret
= !wine_server_call( req
);
295 new_style
= reply
->new_style
;
299 if (win
== WND_DESKTOP
|| data
->whole_window
== DefaultRootWindow(gdi_display
))
301 data
->whole_rect
= data
->client_rect
= data
->window_rect
= *rectWindow
;
302 if (win
!= WND_DESKTOP
)
304 win
->rectWindow
= *rectWindow
;
305 win
->rectClient
= *rectClient
;
306 win
->dwStyle
= new_style
;
307 WIN_ReleasePtr( win
);
314 /* invalidate DCEs */
316 if ((((swp_flags
& SWP_AGG_NOPOSCHANGE
) != SWP_AGG_NOPOSCHANGE
) && (new_style
& WS_VISIBLE
)) ||
317 (swp_flags
& (SWP_HIDEWINDOW
| SWP_SHOWWINDOW
)))
320 UnionRect( &rect
, rectWindow
, &win
->rectWindow
);
321 invalidate_dce( hwnd
, &rect
);
324 win
->rectWindow
= *rectWindow
;
325 win
->rectClient
= *rectClient
;
326 old_style
= win
->dwStyle
;
327 win
->dwStyle
= new_style
;
328 data
->window_rect
= *rectWindow
;
330 TRACE( "win %p window %s client %s style %08x\n",
331 hwnd
, wine_dbgstr_rect(rectWindow
), wine_dbgstr_rect(rectClient
), new_style
);
333 if (make_managed
&& (old_style
& WS_VISIBLE
))
336 XUnmapWindow( display
, data
->whole_window
);
338 old_style
&= ~WS_VISIBLE
; /* force it to be mapped again below */
341 if (!IsRectEmpty( &valid_rects
[0] ))
343 int x_offset
= 0, y_offset
= 0;
345 if (data
->whole_window
)
347 /* the X server will move the bits for us */
348 x_offset
= data
->whole_rect
.left
- new_whole_rect
.left
;
349 y_offset
= data
->whole_rect
.top
- new_whole_rect
.top
;
352 if (x_offset
!= valid_rects
[1].left
- valid_rects
[0].left
||
353 y_offset
!= valid_rects
[1].top
- valid_rects
[0].top
)
355 /* FIXME: should copy the window bits here */
356 RECT invalid_rect
= valid_rects
[0];
358 /* invalid_rects are relative to the client area */
359 OffsetRect( &invalid_rect
, -rectClient
->left
, -rectClient
->top
);
360 RedrawWindow( hwnd
, &invalid_rect
, NULL
, RDW_INVALIDATE
| RDW_ERASE
| RDW_ALLCHILDREN
);
365 if (data
->whole_window
&& !data
->lock_changes
)
367 if ((old_style
& WS_VISIBLE
) && !(new_style
& WS_VISIBLE
))
369 /* window got hidden, unmap it */
370 TRACE( "unmapping win %p\n", hwnd
);
372 XUnmapWindow( display
, data
->whole_window
);
375 else if ((new_style
& WS_VISIBLE
) && !X11DRV_is_window_rect_mapped( rectWindow
))
377 /* resizing to zero size or off screen -> unmap */
378 TRACE( "unmapping zero size or off-screen win %p\n", hwnd
);
380 XUnmapWindow( display
, data
->whole_window
);
385 X11DRV_sync_window_position( display
, data
, swp_flags
, rectClient
, &new_whole_rect
);
387 if (data
->whole_window
&& !data
->lock_changes
)
389 BOOL new_fs_state
, mapped
= FALSE
;
391 if ((new_style
& WS_VISIBLE
) && !(new_style
& WS_MINIMIZE
) &&
392 X11DRV_is_window_rect_mapped( rectWindow
))
394 if (!(old_style
& WS_VISIBLE
))
396 /* window got shown, map it */
397 TRACE( "mapping win %p\n", hwnd
);
400 else if ((swp_flags
& (SWP_NOSIZE
| SWP_NOMOVE
)) != (SWP_NOSIZE
| SWP_NOMOVE
))
402 /* resizing from zero size to non-zero -> map */
403 TRACE( "mapping non zero size or off-screen win %p\n", hwnd
);
408 X11DRV_sync_window_style( display
, data
);
409 X11DRV_set_wm_hints( display
, data
);
411 XMapWindow( display
, data
->whole_window
);
415 SetRect( &old_screen_rect
, 0, 0, screen_width
, screen_height
);
416 if (fullscreen_state_changed( data
, &old_client_rect
, &old_screen_rect
, &new_fs_state
) || mapped
)
417 update_fullscreen_state( display
, data
->whole_window
, new_fs_state
);
421 WIN_ReleasePtr( win
);
426 /***********************************************************************
429 * Find a suitable place for an iconic window.
431 static POINT
WINPOS_FindIconPos( HWND hwnd
, POINT pt
)
433 RECT rect
, rectParent
;
436 int xspacing
, yspacing
;
438 parent
= GetAncestor( hwnd
, GA_PARENT
);
439 GetClientRect( parent
, &rectParent
);
440 if ((pt
.x
>= rectParent
.left
) && (pt
.x
+ GetSystemMetrics(SM_CXICON
) < rectParent
.right
) &&
441 (pt
.y
>= rectParent
.top
) && (pt
.y
+ GetSystemMetrics(SM_CYICON
) < rectParent
.bottom
))
442 return pt
; /* The icon already has a suitable position */
444 xspacing
= GetSystemMetrics(SM_CXICONSPACING
);
445 yspacing
= GetSystemMetrics(SM_CYICONSPACING
);
447 /* Check if another icon already occupies this spot */
448 /* FIXME: this is completely inefficient */
450 hrgn
= CreateRectRgn( 0, 0, 0, 0 );
451 tmp
= CreateRectRgn( 0, 0, 0, 0 );
452 for (child
= GetWindow( parent
, GW_HWNDFIRST
); child
; child
= GetWindow( child
, GW_HWNDNEXT
))
455 if (child
== hwnd
) continue;
456 if ((GetWindowLongW( child
, GWL_STYLE
) & (WS_VISIBLE
|WS_MINIMIZE
)) != (WS_VISIBLE
|WS_MINIMIZE
))
458 if (!(childPtr
= WIN_GetPtr( child
)) || childPtr
== WND_OTHER_PROCESS
)
460 SetRectRgn( tmp
, childPtr
->rectWindow
.left
, childPtr
->rectWindow
.top
,
461 childPtr
->rectWindow
.right
, childPtr
->rectWindow
.bottom
);
462 CombineRgn( hrgn
, hrgn
, tmp
, RGN_OR
);
463 WIN_ReleasePtr( childPtr
);
467 for (rect
.bottom
= rectParent
.bottom
; rect
.bottom
>= yspacing
; rect
.bottom
-= yspacing
)
469 for (rect
.left
= rectParent
.left
; rect
.left
<= rectParent
.right
- xspacing
; rect
.left
+= xspacing
)
471 rect
.right
= rect
.left
+ xspacing
;
472 rect
.top
= rect
.bottom
- yspacing
;
473 if (!RectInRegion( hrgn
, &rect
))
475 /* No window was found, so it's OK for us */
476 pt
.x
= rect
.left
+ (xspacing
- GetSystemMetrics(SM_CXICON
)) / 2;
477 pt
.y
= rect
.top
+ (yspacing
- GetSystemMetrics(SM_CYICON
)) / 2;
478 DeleteObject( hrgn
);
483 DeleteObject( hrgn
);
489 /***********************************************************************
492 UINT
WINPOS_MinMaximize( HWND hwnd
, UINT cmd
, LPRECT rect
)
500 TRACE("%p %u\n", hwnd
, cmd
);
502 wpl
.length
= sizeof(wpl
);
503 GetWindowPlacement( hwnd
, &wpl
);
505 if (HOOK_CallHooks( WH_CBT
, HCBT_MINMAX
, (WPARAM
)hwnd
, cmd
, TRUE
))
506 return SWP_NOSIZE
| SWP_NOMOVE
;
508 if (IsIconic( hwnd
))
512 case SW_SHOWMINNOACTIVE
:
513 case SW_SHOWMINIMIZED
:
514 case SW_FORCEMINIMIZE
:
516 return SWP_NOSIZE
| SWP_NOMOVE
;
518 if (!SendMessageW( hwnd
, WM_QUERYOPEN
, 0, 0 )) return SWP_NOSIZE
| SWP_NOMOVE
;
519 swpFlags
|= SWP_NOCOPYBITS
;
524 case SW_SHOWMINNOACTIVE
:
525 case SW_SHOWMINIMIZED
:
526 case SW_FORCEMINIMIZE
:
528 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
529 if( wndPtr
->dwStyle
& WS_MAXIMIZE
) wndPtr
->flags
|= WIN_RESTORE_MAX
;
530 else wndPtr
->flags
&= ~WIN_RESTORE_MAX
;
531 WIN_ReleasePtr( wndPtr
);
533 old_style
= WIN_SetStyle( hwnd
, WS_MINIMIZE
, WS_MAXIMIZE
);
535 X11DRV_set_iconic_state( hwnd
);
537 wpl
.ptMinPosition
= WINPOS_FindIconPos( hwnd
, wpl
.ptMinPosition
);
539 if (!(old_style
& WS_MINIMIZE
)) swpFlags
|= SWP_STATECHANGED
;
540 SetRect( rect
, wpl
.ptMinPosition
.x
, wpl
.ptMinPosition
.y
,
541 GetSystemMetrics(SM_CXICON
), GetSystemMetrics(SM_CYICON
) );
542 swpFlags
|= SWP_NOCOPYBITS
;
546 old_style
= GetWindowLongW( hwnd
, GWL_STYLE
);
547 if ((old_style
& WS_MAXIMIZE
) && (old_style
& WS_VISIBLE
)) return SWP_NOSIZE
| SWP_NOMOVE
;
549 WINPOS_GetMinMaxInfo( hwnd
, &size
, &wpl
.ptMaxPosition
, NULL
, NULL
);
551 old_style
= WIN_SetStyle( hwnd
, WS_MAXIMIZE
, WS_MINIMIZE
);
552 if (old_style
& WS_MINIMIZE
)
554 WINPOS_ShowIconTitle( hwnd
, FALSE
);
555 X11DRV_set_iconic_state( hwnd
);
557 if (!(old_style
& WS_MAXIMIZE
)) swpFlags
|= SWP_STATECHANGED
;
558 SetRect( rect
, wpl
.ptMaxPosition
.x
, wpl
.ptMaxPosition
.y
, size
.x
, size
.y
);
561 case SW_SHOWNOACTIVATE
:
564 old_style
= WIN_SetStyle( hwnd
, 0, WS_MINIMIZE
| WS_MAXIMIZE
);
565 if (old_style
& WS_MINIMIZE
)
569 WINPOS_ShowIconTitle( hwnd
, FALSE
);
570 X11DRV_set_iconic_state( hwnd
);
572 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
573 restore_max
= (wndPtr
->flags
& WIN_RESTORE_MAX
) != 0;
574 WIN_ReleasePtr( wndPtr
);
577 /* Restore to maximized position */
578 WINPOS_GetMinMaxInfo( hwnd
, &size
, &wpl
.ptMaxPosition
, NULL
, NULL
);
579 WIN_SetStyle( hwnd
, WS_MAXIMIZE
, 0 );
580 swpFlags
|= SWP_STATECHANGED
;
581 SetRect( rect
, wpl
.ptMaxPosition
.x
, wpl
.ptMaxPosition
.y
, size
.x
, size
.y
);
585 else if (!(old_style
& WS_MAXIMIZE
)) break;
587 swpFlags
|= SWP_STATECHANGED
;
589 /* Restore to normal position */
591 *rect
= wpl
.rcNormalPosition
;
592 rect
->right
-= rect
->left
;
593 rect
->bottom
-= rect
->top
;
602 /***********************************************************************
603 * ShowWindow (X11DRV.@)
605 BOOL
X11DRV_ShowWindow( HWND hwnd
, INT cmd
)
609 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
610 BOOL wasVisible
= (style
& WS_VISIBLE
) != 0;
611 BOOL showFlag
= TRUE
;
612 RECT newPos
= {0, 0, 0, 0};
615 TRACE("hwnd=%p, cmd=%d, wasVisible %d\n", hwnd
, cmd
, wasVisible
);
620 if (!wasVisible
) return FALSE
;
622 swp
|= SWP_HIDEWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
623 if (hwnd
!= GetActiveWindow())
624 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
627 case SW_SHOWMINNOACTIVE
:
628 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
631 case SW_FORCEMINIMIZE
: /* FIXME: Does not work if thread is hung. */
632 if (style
& WS_CHILD
) swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
634 case SW_SHOWMINIMIZED
:
635 swp
|= SWP_SHOWWINDOW
| SWP_FRAMECHANGED
;
636 swp
|= WINPOS_MinMaximize( hwnd
, cmd
, &newPos
);
637 if ((style
& WS_MINIMIZE
) && wasVisible
) return TRUE
;
640 case SW_SHOWMAXIMIZED
: /* same as SW_MAXIMIZE */
641 if (!wasVisible
) swp
|= SWP_SHOWWINDOW
;
642 swp
|= SWP_FRAMECHANGED
;
643 swp
|= WINPOS_MinMaximize( hwnd
, SW_MAXIMIZE
, &newPos
);
644 if ((style
& WS_MAXIMIZE
) && wasVisible
) return TRUE
;
648 swp
|= SWP_NOACTIVATE
| SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
649 if (style
& WS_CHILD
) swp
|= SWP_NOZORDER
;
652 if (wasVisible
) return TRUE
;
653 swp
|= SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
654 if (style
& WS_CHILD
) swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
657 case SW_SHOWNOACTIVATE
:
658 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
662 case SW_SHOWNORMAL
: /* same as SW_NORMAL: */
663 case SW_SHOWDEFAULT
: /* FIXME: should have its own handler */
664 if (!wasVisible
) swp
|= SWP_SHOWWINDOW
;
665 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
667 swp
|= SWP_FRAMECHANGED
;
668 swp
|= WINPOS_MinMaximize( hwnd
, cmd
, &newPos
);
672 if (wasVisible
) return TRUE
;
673 swp
|= SWP_NOSIZE
| SWP_NOMOVE
;
675 if (style
& WS_CHILD
&& !(swp
& SWP_STATECHANGED
)) swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
679 if ((showFlag
!= wasVisible
|| cmd
== SW_SHOWNA
) && cmd
!= SW_SHOWMAXIMIZED
&& !(swp
& SWP_STATECHANGED
))
681 SendMessageW( hwnd
, WM_SHOWWINDOW
, showFlag
, 0 );
682 if (!IsWindow( hwnd
)) return wasVisible
;
685 parent
= GetAncestor( hwnd
, GA_PARENT
);
686 if (parent
&& !IsWindowVisible( parent
) && !(swp
& SWP_STATECHANGED
))
688 /* if parent is not visible simply toggle WS_VISIBLE and return */
689 if (showFlag
) WIN_SetStyle( hwnd
, WS_VISIBLE
, 0 );
690 else WIN_SetStyle( hwnd
, 0, WS_VISIBLE
);
693 SetWindowPos( hwnd
, HWND_TOP
, newPos
.left
, newPos
.top
,
694 newPos
.right
, newPos
.bottom
, LOWORD(swp
) );
700 /* FIXME: This will cause the window to be activated irrespective
701 * of whether it is owned by the same thread. Has to be done
705 if (hwnd
== GetActiveWindow())
706 WINPOS_ActivateOtherWindow(hwnd
);
708 /* Revert focus to parent */
710 if (hwnd
== hFocus
|| IsChild(hwnd
, hFocus
))
712 HWND parent
= GetAncestor(hwnd
, GA_PARENT
);
713 if (parent
== GetDesktopWindow()) parent
= 0;
718 if (IsIconic(hwnd
)) WINPOS_ShowIconTitle( hwnd
, TRUE
);
720 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return wasVisible
;
722 if (wndPtr
->flags
& WIN_NEED_SIZE
)
724 /* should happen only in CreateWindowEx() */
725 int wParam
= SIZE_RESTORED
;
726 RECT client
= wndPtr
->rectClient
;
728 wndPtr
->flags
&= ~WIN_NEED_SIZE
;
729 if (wndPtr
->dwStyle
& WS_MAXIMIZE
) wParam
= SIZE_MAXIMIZED
;
730 else if (wndPtr
->dwStyle
& WS_MINIMIZE
) wParam
= SIZE_MINIMIZED
;
731 WIN_ReleasePtr( wndPtr
);
733 SendMessageW( hwnd
, WM_SIZE
, wParam
,
734 MAKELONG( client
.right
- client
.left
, client
.bottom
- client
.top
));
735 SendMessageW( hwnd
, WM_MOVE
, 0, MAKELONG( client
.left
, client
.top
));
737 else WIN_ReleasePtr( wndPtr
);
739 /* if previous state was minimized Windows sets focus to the window */
740 if (style
& WS_MINIMIZE
) SetFocus( hwnd
);
746 /**********************************************************************
749 void X11DRV_MapNotify( HWND hwnd
, XEvent
*event
)
751 struct x11drv_win_data
*data
;
752 HWND hwndFocus
= GetFocus();
755 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
757 if (!(win
= WIN_GetPtr( hwnd
))) return;
759 if (data
->managed
&& (win
->dwStyle
& WS_VISIBLE
) && (win
->dwStyle
& WS_MINIMIZE
))
762 unsigned int width
, height
, border
, depth
;
765 LONG style
= WS_VISIBLE
;
769 XGetGeometry( event
->xmap
.display
, data
->whole_window
, &root
, &x
, &y
, &width
, &height
,
771 XTranslateCoordinates( event
->xmap
.display
, data
->whole_window
, root
, 0, 0, &x
, &y
, &top
);
775 rect
.right
= x
+ width
;
776 rect
.bottom
= y
+ height
;
777 OffsetRect( &rect
, virtual_screen_rect
.left
, virtual_screen_rect
.top
);
778 X11DRV_X_to_window_rect( data
, &rect
);
780 invalidate_dce( hwnd
, &data
->window_rect
);
782 if (win
->flags
& WIN_RESTORE_MAX
) style
|= WS_MAXIMIZE
;
783 WIN_SetStyle( hwnd
, style
, WS_MINIMIZE
);
784 WIN_ReleasePtr( win
);
786 SendMessageW( hwnd
, WM_SHOWWINDOW
, SW_RESTORE
, 0 );
787 data
->lock_changes
++;
788 SetWindowPos( hwnd
, 0, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
,
789 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_FRAMECHANGED
| SWP_STATECHANGED
);
790 data
->lock_changes
--;
792 else WIN_ReleasePtr( win
);
793 if (hwndFocus
&& IsChild( hwnd
, hwndFocus
)) X11DRV_SetFocus(hwndFocus
); /* FIXME */
797 /**********************************************************************
800 void X11DRV_UnmapNotify( HWND hwnd
, XEvent
*event
)
802 struct x11drv_win_data
*data
;
805 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
807 if (!(win
= WIN_GetPtr( hwnd
))) return;
809 if ((win
->dwStyle
& WS_VISIBLE
) && data
->managed
&&
810 X11DRV_is_window_rect_mapped( &win
->rectWindow
))
812 if (win
->dwStyle
& WS_MAXIMIZE
)
813 win
->flags
|= WIN_RESTORE_MAX
;
814 else if (!(win
->dwStyle
& WS_MINIMIZE
))
815 win
->flags
&= ~WIN_RESTORE_MAX
;
817 WIN_SetStyle( hwnd
, WS_MINIMIZE
, WS_MAXIMIZE
);
818 WIN_ReleasePtr( win
);
821 SendMessageW( hwnd
, WM_SHOWWINDOW
, SW_MINIMIZE
, 0 );
822 data
->lock_changes
++;
823 SetWindowPos( hwnd
, 0, 0, 0, GetSystemMetrics(SM_CXICON
), GetSystemMetrics(SM_CYICON
),
824 SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_STATECHANGED
);
825 data
->lock_changes
--;
827 else WIN_ReleasePtr( win
);
830 struct desktop_resize_data
832 RECT old_screen_rect
;
833 RECT old_virtual_rect
;
836 static BOOL CALLBACK
update_windows_on_desktop_resize( HWND hwnd
, LPARAM lparam
)
838 struct x11drv_win_data
*data
;
839 Display
*display
= thread_display();
840 struct desktop_resize_data
*resize_data
= (struct desktop_resize_data
*)lparam
;
843 if (!(data
= X11DRV_get_win_data( hwnd
))) return TRUE
;
845 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
)
849 if (fullscreen_state_changed( data
, &data
->client_rect
, &resize_data
->old_screen_rect
, &new_fs_state
))
850 update_fullscreen_state( display
, data
->whole_window
, new_fs_state
);
853 if (resize_data
->old_virtual_rect
.left
!= virtual_screen_rect
.left
) mask
|= CWX
;
854 if (resize_data
->old_virtual_rect
.top
!= virtual_screen_rect
.top
) mask
|= CWY
;
855 if (mask
&& data
->whole_window
)
857 XWindowChanges changes
;
860 changes
.x
= data
->whole_rect
.left
- virtual_screen_rect
.left
;
861 changes
.y
= data
->whole_rect
.top
- virtual_screen_rect
.top
;
862 XReconfigureWMWindow( display
, data
->whole_window
,
863 DefaultScreen(display
), mask
, &changes
);
870 /***********************************************************************
871 * X11DRV_handle_desktop_resize
873 void X11DRV_handle_desktop_resize( unsigned int width
, unsigned int height
)
875 HWND hwnd
= GetDesktopWindow();
876 struct x11drv_win_data
*data
;
877 struct desktop_resize_data resize_data
;
879 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
881 SetRect( &resize_data
.old_screen_rect
, 0, 0, screen_width
, screen_height
);
882 resize_data
.old_virtual_rect
= virtual_screen_rect
;
884 screen_width
= width
;
885 screen_height
= height
;
887 TRACE("desktop %p change to (%dx%d)\n", hwnd
, width
, height
);
888 data
->lock_changes
++;
889 X11DRV_SetWindowPos( hwnd
, 0, &virtual_screen_rect
, &virtual_screen_rect
,
890 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOACTIVATE
, NULL
);
891 data
->lock_changes
--;
893 SendMessageTimeoutW( HWND_BROADCAST
, WM_DISPLAYCHANGE
, screen_depth
,
894 MAKELPARAM( width
, height
), SMTO_ABORTIFHUNG
, 2000, NULL
);
896 EnumWindows( update_windows_on_desktop_resize
, (LPARAM
)&resize_data
);
900 /***********************************************************************
901 * X11DRV_ConfigureNotify
903 void X11DRV_ConfigureNotify( HWND hwnd
, XEvent
*xev
)
905 XConfigureEvent
*event
= &xev
->xconfigure
;
906 struct x11drv_win_data
*data
;
909 int cx
, cy
, x
= event
->x
, y
= event
->y
;
912 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
916 if (!event
->send_event
) /* normal event, need to map coordinates to the root */
920 XTranslateCoordinates( event
->display
, data
->whole_window
, root_window
,
921 0, 0, &x
, &y
, &child
);
926 rect
.right
= x
+ event
->width
;
927 rect
.bottom
= y
+ event
->height
;
928 OffsetRect( &rect
, virtual_screen_rect
.left
, virtual_screen_rect
.top
);
929 TRACE( "win %p new X rect %d,%d,%dx%d (event %d,%d,%dx%d)\n",
930 hwnd
, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
,
931 event
->x
, event
->y
, event
->width
, event
->height
);
932 X11DRV_X_to_window_rect( data
, &rect
);
936 cx
= rect
.right
- rect
.left
;
937 cy
= rect
.bottom
- rect
.top
;
938 flags
= SWP_NOACTIVATE
| SWP_NOZORDER
;
940 /* Compare what has changed */
942 GetWindowRect( hwnd
, &rect
);
943 if (rect
.left
== x
&& rect
.top
== y
) flags
|= SWP_NOMOVE
;
945 TRACE( "%p moving from (%d,%d) to (%d,%d)\n",
946 hwnd
, rect
.left
, rect
.top
, x
, y
);
948 if ((rect
.right
- rect
.left
== cx
&& rect
.bottom
- rect
.top
== cy
) ||
950 (IsRectEmpty( &rect
) && event
->width
== 1 && event
->height
== 1))
952 if (flags
& SWP_NOMOVE
) return; /* if nothing changed, don't do anything */
956 TRACE( "%p resizing from (%dx%d) to (%dx%d)\n",
957 hwnd
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, cx
, cy
);
959 data
->lock_changes
++;
960 SetWindowPos( hwnd
, 0, x
, y
, cx
, cy
, flags
);
961 data
->lock_changes
--;
965 /***********************************************************************
966 * SetWindowRgn (X11DRV.@)
968 * Assign specified region to window (for non-rectangular windows)
970 int X11DRV_SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL redraw
)
972 struct x11drv_win_data
*data
;
974 if (!(data
= X11DRV_get_win_data( hwnd
)))
976 if (IsWindow( hwnd
))
977 FIXME( "not supported on other thread window %p\n", hwnd
);
978 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
982 #ifdef HAVE_LIBXSHAPE
983 if (data
->whole_window
)
985 Display
*display
= thread_display();
990 XShapeCombineMask( display
, data
->whole_window
,
991 ShapeBounding
, 0, 0, None
, ShapeSet
);
996 RGNDATA
*pRegionData
= X11DRV_GetRegionData( hrgn
, 0 );
1000 XShapeCombineRectangles( display
, data
->whole_window
, ShapeBounding
,
1001 data
->window_rect
.left
- data
->whole_rect
.left
,
1002 data
->window_rect
.top
- data
->whole_rect
.top
,
1003 (XRectangle
*)pRegionData
->Buffer
,
1004 pRegionData
->rdh
.nCount
,
1005 ShapeSet
, YXBanded
);
1006 wine_tsx11_unlock();
1007 HeapFree(GetProcessHeap(), 0, pRegionData
);
1011 #endif /* HAVE_LIBXSHAPE */
1013 invalidate_dce( hwnd
, &data
->window_rect
);
1018 /***********************************************************************
1021 * Draw the frame used when moving or resizing window.
1023 * FIXME: This causes problems in Win95 mode. (why?)
1025 static void draw_moving_frame( HDC hdc
, RECT
*rect
, BOOL thickframe
)
1029 const int width
= GetSystemMetrics(SM_CXFRAME
);
1030 const int height
= GetSystemMetrics(SM_CYFRAME
);
1032 HBRUSH hbrush
= SelectObject( hdc
, GetStockObject( GRAY_BRUSH
) );
1033 PatBlt( hdc
, rect
->left
, rect
->top
,
1034 rect
->right
- rect
->left
- width
, height
, PATINVERT
);
1035 PatBlt( hdc
, rect
->left
, rect
->top
+ height
, width
,
1036 rect
->bottom
- rect
->top
- height
, PATINVERT
);
1037 PatBlt( hdc
, rect
->left
+ width
, rect
->bottom
- 1,
1038 rect
->right
- rect
->left
- width
, -height
, PATINVERT
);
1039 PatBlt( hdc
, rect
->right
- 1, rect
->top
, -width
,
1040 rect
->bottom
- rect
->top
- height
, PATINVERT
);
1041 SelectObject( hdc
, hbrush
);
1043 else DrawFocusRect( hdc
, rect
);
1047 /***********************************************************************
1050 * Initialisation of a move or resize, when initiatied from a menu choice.
1051 * Return hit test code for caption or sizing border.
1053 static LONG
start_size_move( HWND hwnd
, WPARAM wParam
, POINT
*capturePoint
, LONG style
)
1060 GetWindowRect( hwnd
, &rectWindow
);
1062 if ((wParam
& 0xfff0) == SC_MOVE
)
1064 /* Move pointer at the center of the caption */
1065 RECT rect
= rectWindow
;
1066 /* Note: to be exactly centered we should take the different types
1067 * of border into account, but it shouldn't make more that a few pixels
1068 * of difference so let's not bother with that */
1069 rect
.top
+= GetSystemMetrics(SM_CYBORDER
);
1070 if (style
& WS_SYSMENU
)
1071 rect
.left
+= GetSystemMetrics(SM_CXSIZE
) + 1;
1072 if (style
& WS_MINIMIZEBOX
)
1073 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
1074 if (style
& WS_MAXIMIZEBOX
)
1075 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
1076 pt
.x
= (rect
.right
+ rect
.left
) / 2;
1077 pt
.y
= rect
.top
+ GetSystemMetrics(SM_CYSIZE
)/2;
1078 hittest
= HTCAPTION
;
1086 GetMessageW( &msg
, 0, WM_KEYFIRST
, WM_MOUSELAST
);
1087 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
1093 hittest
= SendMessageW( hwnd
, WM_NCHITTEST
, 0, MAKELONG( pt
.x
, pt
.y
) );
1094 if ((hittest
< HTLEFT
) || (hittest
> HTBOTTOMRIGHT
)) hittest
= 0;
1105 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
1106 pt
.y
= rectWindow
.top
+ GetSystemMetrics(SM_CYFRAME
) / 2;
1110 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
1111 pt
.y
= rectWindow
.bottom
- GetSystemMetrics(SM_CYFRAME
) / 2;
1115 pt
.x
= rectWindow
.left
+ GetSystemMetrics(SM_CXFRAME
) / 2;
1116 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
1120 pt
.x
= rectWindow
.right
- GetSystemMetrics(SM_CXFRAME
) / 2;
1121 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
1124 case VK_ESCAPE
: return 0;
1130 SetCursorPos( pt
.x
, pt
.y
);
1131 SendMessageW( hwnd
, WM_SETCURSOR
, (WPARAM
)hwnd
, MAKELONG( hittest
, WM_MOUSEMOVE
));
1136 /***********************************************************************
1137 * set_movesize_capture
1139 static void set_movesize_capture( HWND hwnd
)
1143 SERVER_START_REQ( set_capture_window
)
1146 req
->flags
= CAPTURE_MOVESIZE
;
1147 if (!wine_server_call_err( req
))
1149 previous
= reply
->previous
;
1150 hwnd
= reply
->full_handle
;
1154 if (previous
&& previous
!= hwnd
)
1155 SendMessageW( previous
, WM_CAPTURECHANGED
, 0, (LPARAM
)hwnd
);
1158 /***********************************************************************
1159 * X11DRV_WMMoveResizeWindow
1161 * Tells the window manager to initiate a move or resize operation.
1164 * http://freedesktop.org/Standards/wm-spec/1.3/ar01s04.html
1165 * or search for "_NET_WM_MOVERESIZE"
1167 static void X11DRV_WMMoveResizeWindow( HWND hwnd
, int x
, int y
, int dir
)
1170 Display
*display
= thread_display();
1172 TRACE("hwnd %p, x %d, y %d, dir %d\n", hwnd
, x
, y
, dir
);
1174 xev
.xclient
.type
= ClientMessage
;
1175 xev
.xclient
.window
= X11DRV_get_whole_window(hwnd
);
1176 xev
.xclient
.message_type
= x11drv_atom(_NET_WM_MOVERESIZE
);
1177 xev
.xclient
.serial
= 0;
1178 xev
.xclient
.display
= display
;
1179 xev
.xclient
.send_event
= True
;
1180 xev
.xclient
.format
= 32;
1181 xev
.xclient
.data
.l
[0] = x
; /* x coord */
1182 xev
.xclient
.data
.l
[1] = y
; /* y coord */
1183 xev
.xclient
.data
.l
[2] = dir
; /* direction */
1184 xev
.xclient
.data
.l
[3] = 1; /* button */
1185 xev
.xclient
.data
.l
[4] = 0; /* unused */
1187 /* need to ungrab the pointer that may have been automatically grabbed
1188 * with a ButtonPress event */
1190 XUngrabPointer( display
, CurrentTime
);
1191 XSendEvent(display
, root_window
, False
, SubstructureNotifyMask
, &xev
);
1192 wine_tsx11_unlock();
1195 /***********************************************************************
1196 * SysCommandSizeMove (X11DRV.@)
1198 * Perform SC_MOVE and SC_SIZE commands.
1200 void X11DRV_SysCommandSizeMove( HWND hwnd
, WPARAM wParam
)
1203 RECT sizingRect
, mouseRect
, origRect
;
1206 LONG hittest
= (LONG
)(wParam
& 0x0f);
1207 WPARAM syscommand
= wParam
& 0xfff0;
1208 HCURSOR hDragCursor
= 0, hOldCursor
= 0;
1209 POINT minTrack
, maxTrack
;
1210 POINT capturePoint
, pt
;
1211 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
1212 BOOL thickframe
= HAS_THICKFRAME( style
);
1213 BOOL iconic
= style
& WS_MINIMIZE
;
1215 DWORD dwPoint
= GetMessagePos ();
1216 BOOL DragFullWindows
= FALSE
;
1218 Window parent_win
, whole_win
;
1219 Display
*old_gdi_display
= NULL
;
1220 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1221 struct x11drv_win_data
*data
;
1223 pt
.x
= (short)LOWORD(dwPoint
);
1224 pt
.y
= (short)HIWORD(dwPoint
);
1227 if (IsZoomed(hwnd
) || !IsWindowVisible(hwnd
)) return;
1229 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1231 TRACE("hwnd %p (%smanaged), command %04lx, hittest %d, pos %d,%d\n",
1232 hwnd
, data
->managed
? "" : "NOT ", syscommand
, hittest
, pt
.x
, pt
.y
);
1234 /* if we are managed then we let the WM do all the work */
1238 if (syscommand
== SC_MOVE
)
1240 if (!hittest
) dir
= _NET_WM_MOVERESIZE_MOVE_KEYBOARD
;
1241 else dir
= _NET_WM_MOVERESIZE_MOVE
;
1243 else if (!hittest
) dir
= _NET_WM_MOVERESIZE_SIZE_KEYBOARD
;
1247 case WMSZ_LEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_LEFT
; break;
1248 case WMSZ_RIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_RIGHT
; break;
1249 case WMSZ_TOP
: dir
= _NET_WM_MOVERESIZE_SIZE_TOP
; break;
1250 case WMSZ_TOPLEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_TOPLEFT
; break;
1251 case WMSZ_TOPRIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_TOPRIGHT
; break;
1252 case WMSZ_BOTTOM
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOM
; break;
1253 case WMSZ_BOTTOMLEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT
; break;
1254 case WMSZ_BOTTOMRIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT
; break;
1256 ERR("Invalid hittest value: %d\n", hittest
);
1257 dir
= _NET_WM_MOVERESIZE_SIZE_KEYBOARD
;
1259 X11DRV_WMMoveResizeWindow( hwnd
, pt
.x
, pt
.y
, dir
);
1263 SystemParametersInfoA(SPI_GETDRAGFULLWINDOWS
, 0, &DragFullWindows
, 0);
1265 if (syscommand
== SC_MOVE
)
1267 if (!hittest
) hittest
= start_size_move( hwnd
, wParam
, &capturePoint
, style
);
1268 if (!hittest
) return;
1272 if ( hittest
&& (syscommand
!= SC_MOUSEMENU
) )
1273 hittest
+= (HTLEFT
- WMSZ_LEFT
);
1276 set_movesize_capture( hwnd
);
1277 hittest
= start_size_move( hwnd
, wParam
, &capturePoint
, style
);
1280 set_movesize_capture(0);
1286 /* Get min/max info */
1288 WINPOS_GetMinMaxInfo( hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
1289 GetWindowRect( hwnd
, &sizingRect
);
1290 if (style
& WS_CHILD
)
1292 parent
= GetParent(hwnd
);
1293 /* make sizing rect relative to parent */
1294 MapWindowPoints( 0, parent
, (POINT
*)&sizingRect
, 2 );
1295 GetClientRect( parent
, &mouseRect
);
1300 mouseRect
= virtual_screen_rect
;
1302 origRect
= sizingRect
;
1304 if (ON_LEFT_BORDER(hittest
))
1306 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.right
-maxTrack
.x
);
1307 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.right
-minTrack
.x
);
1309 else if (ON_RIGHT_BORDER(hittest
))
1311 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.left
+minTrack
.x
);
1312 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.left
+maxTrack
.x
);
1314 if (ON_TOP_BORDER(hittest
))
1316 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.bottom
-maxTrack
.y
);
1317 mouseRect
.bottom
= min( mouseRect
.bottom
,sizingRect
.bottom
-minTrack
.y
);
1319 else if (ON_BOTTOM_BORDER(hittest
))
1321 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.top
+minTrack
.y
);
1322 mouseRect
.bottom
= min( mouseRect
.bottom
, sizingRect
.top
+maxTrack
.y
);
1324 if (parent
) MapWindowPoints( parent
, 0, (LPPOINT
)&mouseRect
, 2 );
1326 /* Retrieve a default cache DC (without using the window style) */
1327 hdc
= GetDCEx( parent
, 0, DCX_CACHE
);
1329 if( iconic
) /* create a cursor for dragging */
1331 hDragCursor
= (HCURSOR
)GetClassLongPtrW( hwnd
, GCLP_HICON
);
1332 if( !hDragCursor
) hDragCursor
= (HCURSOR
)SendMessageW( hwnd
, WM_QUERYDRAGICON
, 0, 0L);
1333 if( !hDragCursor
) iconic
= FALSE
;
1336 /* repaint the window before moving it around */
1337 RedrawWindow( hwnd
, NULL
, 0, RDW_UPDATENOW
| RDW_ALLCHILDREN
);
1339 SendMessageW( hwnd
, WM_ENTERSIZEMOVE
, 0, 0 );
1340 set_movesize_capture( hwnd
);
1342 /* grab the server only when moving top-level windows without desktop */
1343 grab
= (!DragFullWindows
&& !parent
&& (root_window
== DefaultRootWindow(gdi_display
)));
1348 XSync( gdi_display
, False
);
1349 XGrabServer( thread_data
->display
);
1350 XSync( thread_data
->display
, False
);
1351 /* switch gdi display to the thread display, since the server is grabbed */
1352 old_gdi_display
= gdi_display
;
1353 gdi_display
= thread_data
->display
;
1354 wine_tsx11_unlock();
1356 whole_win
= X11DRV_get_whole_window( GetAncestor(hwnd
,GA_ROOT
) );
1357 parent_win
= parent
? X11DRV_get_whole_window( GetAncestor(parent
,GA_ROOT
) ) : root_window
;
1360 XGrabPointer( thread_data
->display
, whole_win
, False
,
1361 PointerMotionMask
| ButtonPressMask
| ButtonReleaseMask
,
1362 GrabModeAsync
, GrabModeAsync
, parent_win
, None
, CurrentTime
);
1363 wine_tsx11_unlock();
1364 thread_data
->grab_window
= whole_win
;
1370 if (!GetMessageW( &msg
, 0, WM_KEYFIRST
, WM_MOUSELAST
)) break;
1371 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
1373 /* Exit on button-up, Return, or Esc */
1374 if ((msg
.message
== WM_LBUTTONUP
) ||
1375 ((msg
.message
== WM_KEYDOWN
) &&
1376 ((msg
.wParam
== VK_RETURN
) || (msg
.wParam
== VK_ESCAPE
)))) break;
1378 if ((msg
.message
!= WM_KEYDOWN
) && (msg
.message
!= WM_MOUSEMOVE
))
1379 continue; /* We are not interested in other messages */
1383 if (msg
.message
== WM_KEYDOWN
) switch(msg
.wParam
)
1385 case VK_UP
: pt
.y
-= 8; break;
1386 case VK_DOWN
: pt
.y
+= 8; break;
1387 case VK_LEFT
: pt
.x
-= 8; break;
1388 case VK_RIGHT
: pt
.x
+= 8; break;
1391 pt
.x
= max( pt
.x
, mouseRect
.left
);
1392 pt
.x
= min( pt
.x
, mouseRect
.right
);
1393 pt
.y
= max( pt
.y
, mouseRect
.top
);
1394 pt
.y
= min( pt
.y
, mouseRect
.bottom
);
1396 dx
= pt
.x
- capturePoint
.x
;
1397 dy
= pt
.y
- capturePoint
.y
;
1405 if( iconic
) /* ok, no system popup tracking */
1407 hOldCursor
= SetCursor(hDragCursor
);
1409 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1411 else if(!DragFullWindows
)
1412 draw_moving_frame( hdc
, &sizingRect
, thickframe
);
1415 if (msg
.message
== WM_KEYDOWN
) SetCursorPos( pt
.x
, pt
.y
);
1418 RECT newRect
= sizingRect
;
1419 WPARAM wpSizingHit
= 0;
1421 if (hittest
== HTCAPTION
) OffsetRect( &newRect
, dx
, dy
);
1422 if (ON_LEFT_BORDER(hittest
)) newRect
.left
+= dx
;
1423 else if (ON_RIGHT_BORDER(hittest
)) newRect
.right
+= dx
;
1424 if (ON_TOP_BORDER(hittest
)) newRect
.top
+= dy
;
1425 else if (ON_BOTTOM_BORDER(hittest
)) newRect
.bottom
+= dy
;
1426 if(!iconic
&& !DragFullWindows
) draw_moving_frame( hdc
, &sizingRect
, thickframe
);
1429 /* determine the hit location */
1430 if (hittest
>= HTLEFT
&& hittest
<= HTBOTTOMRIGHT
)
1431 wpSizingHit
= WMSZ_LEFT
+ (hittest
- HTLEFT
);
1432 SendMessageW( hwnd
, WM_SIZING
, wpSizingHit
, (LPARAM
)&newRect
);
1436 if(!DragFullWindows
)
1437 draw_moving_frame( hdc
, &newRect
, thickframe
);
1439 SetWindowPos( hwnd
, 0, newRect
.left
, newRect
.top
,
1440 newRect
.right
- newRect
.left
,
1441 newRect
.bottom
- newRect
.top
,
1442 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
1444 sizingRect
= newRect
;
1449 set_movesize_capture(0);
1452 if( moved
) /* restore cursors, show icon title later on */
1454 ShowCursor( FALSE
);
1455 SetCursor( hOldCursor
);
1458 else if (moved
&& !DragFullWindows
)
1459 draw_moving_frame( hdc
, &sizingRect
, thickframe
);
1461 ReleaseDC( parent
, hdc
);
1464 XUngrabPointer( thread_data
->display
, CurrentTime
);
1467 XSync( thread_data
->display
, False
);
1468 XUngrabServer( thread_data
->display
);
1469 XSync( thread_data
->display
, False
);
1470 gdi_display
= old_gdi_display
;
1472 wine_tsx11_unlock();
1473 thread_data
->grab_window
= None
;
1475 if (HOOK_CallHooks( WH_CBT
, HCBT_MOVESIZE
, (WPARAM
)hwnd
, (LPARAM
)&sizingRect
, TRUE
))
1478 SendMessageW( hwnd
, WM_EXITSIZEMOVE
, 0, 0 );
1479 SendMessageW( hwnd
, WM_SETVISIBLE
, !IsIconic(hwnd
), 0L);
1481 /* window moved or resized */
1484 /* if the moving/resizing isn't canceled call SetWindowPos
1485 * with the new position or the new size of the window
1487 if (!((msg
.message
== WM_KEYDOWN
) && (msg
.wParam
== VK_ESCAPE
)) )
1489 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
1490 if(!DragFullWindows
)
1491 SetWindowPos( hwnd
, 0, sizingRect
.left
, sizingRect
.top
,
1492 sizingRect
.right
- sizingRect
.left
,
1493 sizingRect
.bottom
- sizingRect
.top
,
1494 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
1497 { /* restore previous size/position */
1499 SetWindowPos( hwnd
, 0, origRect
.left
, origRect
.top
,
1500 origRect
.right
- origRect
.left
,
1501 origRect
.bottom
- origRect
.top
,
1502 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
1508 /* Single click brings up the system menu when iconized */
1512 if(style
& WS_SYSMENU
)
1513 SendMessageW( hwnd
, WM_SYSCOMMAND
,
1514 SC_MOUSEMENU
+ HTSYSMENU
, MAKELONG(pt
.x
,pt
.y
));
1516 else WINPOS_ShowIconTitle( hwnd
, TRUE
);