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 /***********************************************************************
179 static void update_wm_states( Display
*display
, struct x11drv_win_data
*data
, BOOL force
)
181 static const unsigned int state_atoms
[NB_WM_STATES
] =
183 XATOM__NET_WM_STATE_FULLSCREEN
,
184 XATOM__NET_WM_STATE_ABOVE
,
185 XATOM__NET_WM_STATE_SKIP_PAGER
,
186 XATOM__NET_WM_STATE_SKIP_TASKBAR
189 DWORD i
, ex_style
, new_state
= 0;
192 if (!data
->managed
) return;
194 if (data
->client_rect
.left
<= 0 && data
->client_rect
.right
>= screen_width
&&
195 data
->client_rect
.top
<= 0 && data
->client_rect
.bottom
>= screen_height
)
196 new_state
|= (1 << WM_STATE_FULLSCREEN
);
198 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
199 if (ex_style
& WS_EX_TOPMOST
)
200 new_state
|= (1 << WM_STATE_ABOVE
);
201 if (ex_style
& WS_EX_TOOLWINDOW
)
202 new_state
|= (1 << WM_STATE_SKIP_TASKBAR
) | (1 << WM_STATE_SKIP_PAGER
);
204 xev
.xclient
.type
= ClientMessage
;
205 xev
.xclient
.window
= data
->whole_window
;
206 xev
.xclient
.message_type
= x11drv_atom(_NET_WM_STATE
);
207 xev
.xclient
.serial
= 0;
208 xev
.xclient
.display
= display
;
209 xev
.xclient
.send_event
= True
;
210 xev
.xclient
.format
= 32;
211 xev
.xclient
.data
.l
[2] = 0;
212 xev
.xclient
.data
.l
[3] = 1;
214 for (i
= 0; i
< NB_WM_STATES
; i
++)
216 if (!((data
->wm_state
^ new_state
) & (1 << i
))) /* unchanged */
218 /* if forced, we only add states, we don't remove them */
219 if (!force
|| !(new_state
& (1 << i
))) continue;
222 TRACE( "setting wm state %u for window %p/%lx to %u prev %u\n",
223 i
, data
->hwnd
, data
->whole_window
,
224 (new_state
& (1 << i
)) != 0, (data
->wm_state
& (1 << i
)) != 0 );
226 xev
.xclient
.data
.l
[0] = (new_state
& (1 << i
)) ? _NET_WM_STATE_ADD
: _NET_WM_STATE_REMOVE
;
227 xev
.xclient
.data
.l
[1] = X11DRV_Atoms
[state_atoms
[i
] - FIRST_XATOM
];
229 XSendEvent( display
, root_window
, False
, SubstructureRedirectMask
| SubstructureNotifyMask
, &xev
);
232 data
->wm_state
= new_state
;
236 /***********************************************************************
237 * SetWindowPos (X11DRV.@)
239 BOOL
X11DRV_SetWindowPos( HWND hwnd
, HWND insert_after
, const RECT
*rectWindow
,
240 const RECT
*rectClient
, UINT swp_flags
, const RECT
*valid_rects
)
242 Display
*display
= thread_display();
243 struct x11drv_win_data
*data
;
244 RECT new_whole_rect
, old_client_rect
;
246 DWORD old_style
, new_style
, new_ex_style
;
247 BOOL ret
, make_managed
= FALSE
;
249 if (!(data
= X11DRV_get_win_data( hwnd
))) return FALSE
;
251 /* check if we need to switch the window to managed */
252 if (!data
->managed
&& data
->whole_window
&& managed_mode
&&
253 root_window
== DefaultRootWindow( display
) &&
254 data
->whole_window
!= root_window
)
256 if (is_window_managed( hwnd
, swp_flags
, rectWindow
))
258 TRACE( "making win %p/%lx managed\n", hwnd
, data
->whole_window
);
260 data
->managed
= TRUE
;
261 SetPropA( hwnd
, managed_prop
, (HANDLE
)1 );
265 new_whole_rect
= *rectWindow
;
266 X11DRV_window_to_X_rect( data
, &new_whole_rect
);
268 old_client_rect
= data
->client_rect
;
270 if (!data
->whole_window
) swp_flags
|= SWP_NOCOPYBITS
; /* we can't rely on X11 to move the bits */
272 if (!(win
= WIN_GetPtr( hwnd
))) return FALSE
;
273 if (win
== WND_OTHER_PROCESS
)
275 if (IsWindow( hwnd
)) ERR( "cannot set rectangles of other process window %p\n", hwnd
);
278 SERVER_START_REQ( set_window_pos
)
281 req
->previous
= insert_after
;
282 req
->flags
= swp_flags
;
283 req
->window
.left
= rectWindow
->left
;
284 req
->window
.top
= rectWindow
->top
;
285 req
->window
.right
= rectWindow
->right
;
286 req
->window
.bottom
= rectWindow
->bottom
;
287 req
->client
.left
= rectClient
->left
;
288 req
->client
.top
= rectClient
->top
;
289 req
->client
.right
= rectClient
->right
;
290 req
->client
.bottom
= rectClient
->bottom
;
291 if (memcmp( rectWindow
, &new_whole_rect
, sizeof(RECT
) ) || !IsRectEmpty( &valid_rects
[0] ))
293 wine_server_add_data( req
, &new_whole_rect
, sizeof(new_whole_rect
) );
294 if (!IsRectEmpty( &valid_rects
[0] ))
295 wine_server_add_data( req
, valid_rects
, 2 * sizeof(*valid_rects
) );
297 ret
= !wine_server_call( req
);
298 new_style
= reply
->new_style
;
299 new_ex_style
= reply
->new_ex_style
;
303 if (win
== WND_DESKTOP
|| data
->whole_window
== DefaultRootWindow(gdi_display
))
305 data
->whole_rect
= data
->client_rect
= data
->window_rect
= *rectWindow
;
306 if (win
!= WND_DESKTOP
)
308 win
->rectWindow
= *rectWindow
;
309 win
->rectClient
= *rectClient
;
310 win
->dwStyle
= new_style
;
311 win
->dwExStyle
= new_ex_style
;
312 WIN_ReleasePtr( win
);
319 /* invalidate DCEs */
321 if ((((swp_flags
& SWP_AGG_NOPOSCHANGE
) != SWP_AGG_NOPOSCHANGE
) && (new_style
& WS_VISIBLE
)) ||
322 (swp_flags
& (SWP_HIDEWINDOW
| SWP_SHOWWINDOW
)))
325 UnionRect( &rect
, rectWindow
, &win
->rectWindow
);
326 invalidate_dce( hwnd
, &rect
);
329 win
->rectWindow
= *rectWindow
;
330 win
->rectClient
= *rectClient
;
331 old_style
= win
->dwStyle
;
332 win
->dwStyle
= new_style
;
333 win
->dwExStyle
= new_ex_style
;
334 data
->window_rect
= *rectWindow
;
336 TRACE( "win %p window %s client %s style %08x\n",
337 hwnd
, wine_dbgstr_rect(rectWindow
), wine_dbgstr_rect(rectClient
), new_style
);
339 if (make_managed
&& (old_style
& WS_VISIBLE
))
342 XUnmapWindow( display
, data
->whole_window
);
344 old_style
&= ~WS_VISIBLE
; /* force it to be mapped again below */
347 if (!IsRectEmpty( &valid_rects
[0] ))
349 int x_offset
= 0, y_offset
= 0;
351 if (data
->whole_window
)
353 /* the X server will move the bits for us */
354 x_offset
= data
->whole_rect
.left
- new_whole_rect
.left
;
355 y_offset
= data
->whole_rect
.top
- new_whole_rect
.top
;
358 if (x_offset
!= valid_rects
[1].left
- valid_rects
[0].left
||
359 y_offset
!= valid_rects
[1].top
- valid_rects
[0].top
)
361 /* FIXME: should copy the window bits here */
362 RECT invalid_rect
= valid_rects
[0];
364 /* invalid_rects are relative to the client area */
365 OffsetRect( &invalid_rect
, -rectClient
->left
, -rectClient
->top
);
366 RedrawWindow( hwnd
, &invalid_rect
, NULL
, RDW_INVALIDATE
| RDW_ERASE
| RDW_ALLCHILDREN
);
371 if (data
->whole_window
&& !data
->lock_changes
)
373 if ((old_style
& WS_VISIBLE
) && !(new_style
& WS_VISIBLE
))
375 /* window got hidden, unmap it */
376 TRACE( "unmapping win %p\n", hwnd
);
378 XUnmapWindow( display
, data
->whole_window
);
381 else if ((new_style
& WS_VISIBLE
) && !X11DRV_is_window_rect_mapped( rectWindow
))
383 /* resizing to zero size or off screen -> unmap */
384 TRACE( "unmapping zero size or off-screen win %p\n", hwnd
);
386 XUnmapWindow( display
, data
->whole_window
);
391 X11DRV_sync_window_position( display
, data
, swp_flags
, rectClient
, &new_whole_rect
);
393 if (data
->whole_window
&& !data
->lock_changes
)
397 if ((new_style
& WS_VISIBLE
) && !(new_style
& WS_MINIMIZE
) &&
398 X11DRV_is_window_rect_mapped( rectWindow
))
400 if (!(old_style
& WS_VISIBLE
))
402 /* window got shown, map it */
403 TRACE( "mapping win %p\n", hwnd
);
406 else if ((swp_flags
& (SWP_NOSIZE
| SWP_NOMOVE
)) != (SWP_NOSIZE
| SWP_NOMOVE
))
408 /* resizing from zero size to non-zero -> map */
409 TRACE( "mapping non zero size or off-screen win %p\n", hwnd
);
413 if (mapped
|| (swp_flags
& SWP_FRAMECHANGED
))
414 X11DRV_set_wm_hints( display
, data
);
418 X11DRV_sync_window_style( display
, data
);
420 XMapWindow( display
, data
->whole_window
);
424 update_wm_states( display
, data
, mapped
);
428 WIN_ReleasePtr( win
);
433 /***********************************************************************
436 * Find a suitable place for an iconic window.
438 static POINT
WINPOS_FindIconPos( HWND hwnd
, POINT pt
)
440 RECT rect
, rectParent
;
443 int xspacing
, yspacing
;
445 parent
= GetAncestor( hwnd
, GA_PARENT
);
446 GetClientRect( parent
, &rectParent
);
447 if ((pt
.x
>= rectParent
.left
) && (pt
.x
+ GetSystemMetrics(SM_CXICON
) < rectParent
.right
) &&
448 (pt
.y
>= rectParent
.top
) && (pt
.y
+ GetSystemMetrics(SM_CYICON
) < rectParent
.bottom
))
449 return pt
; /* The icon already has a suitable position */
451 xspacing
= GetSystemMetrics(SM_CXICONSPACING
);
452 yspacing
= GetSystemMetrics(SM_CYICONSPACING
);
454 /* Check if another icon already occupies this spot */
455 /* FIXME: this is completely inefficient */
457 hrgn
= CreateRectRgn( 0, 0, 0, 0 );
458 tmp
= CreateRectRgn( 0, 0, 0, 0 );
459 for (child
= GetWindow( parent
, GW_HWNDFIRST
); child
; child
= GetWindow( child
, GW_HWNDNEXT
))
462 if (child
== hwnd
) continue;
463 if ((GetWindowLongW( child
, GWL_STYLE
) & (WS_VISIBLE
|WS_MINIMIZE
)) != (WS_VISIBLE
|WS_MINIMIZE
))
465 if (!(childPtr
= WIN_GetPtr( child
)) || childPtr
== WND_OTHER_PROCESS
)
467 SetRectRgn( tmp
, childPtr
->rectWindow
.left
, childPtr
->rectWindow
.top
,
468 childPtr
->rectWindow
.right
, childPtr
->rectWindow
.bottom
);
469 CombineRgn( hrgn
, hrgn
, tmp
, RGN_OR
);
470 WIN_ReleasePtr( childPtr
);
474 for (rect
.bottom
= rectParent
.bottom
; rect
.bottom
>= yspacing
; rect
.bottom
-= yspacing
)
476 for (rect
.left
= rectParent
.left
; rect
.left
<= rectParent
.right
- xspacing
; rect
.left
+= xspacing
)
478 rect
.right
= rect
.left
+ xspacing
;
479 rect
.top
= rect
.bottom
- yspacing
;
480 if (!RectInRegion( hrgn
, &rect
))
482 /* No window was found, so it's OK for us */
483 pt
.x
= rect
.left
+ (xspacing
- GetSystemMetrics(SM_CXICON
)) / 2;
484 pt
.y
= rect
.top
+ (yspacing
- GetSystemMetrics(SM_CYICON
)) / 2;
485 DeleteObject( hrgn
);
490 DeleteObject( hrgn
);
496 /***********************************************************************
499 UINT
WINPOS_MinMaximize( HWND hwnd
, UINT cmd
, LPRECT rect
)
507 TRACE("%p %u\n", hwnd
, cmd
);
509 wpl
.length
= sizeof(wpl
);
510 GetWindowPlacement( hwnd
, &wpl
);
512 if (HOOK_CallHooks( WH_CBT
, HCBT_MINMAX
, (WPARAM
)hwnd
, cmd
, TRUE
))
513 return SWP_NOSIZE
| SWP_NOMOVE
;
515 if (IsIconic( hwnd
))
519 case SW_SHOWMINNOACTIVE
:
520 case SW_SHOWMINIMIZED
:
521 case SW_FORCEMINIMIZE
:
523 return SWP_NOSIZE
| SWP_NOMOVE
;
525 if (!SendMessageW( hwnd
, WM_QUERYOPEN
, 0, 0 )) return SWP_NOSIZE
| SWP_NOMOVE
;
526 swpFlags
|= SWP_NOCOPYBITS
;
531 case SW_SHOWMINNOACTIVE
:
532 case SW_SHOWMINIMIZED
:
533 case SW_FORCEMINIMIZE
:
535 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
536 if( wndPtr
->dwStyle
& WS_MAXIMIZE
) wndPtr
->flags
|= WIN_RESTORE_MAX
;
537 else wndPtr
->flags
&= ~WIN_RESTORE_MAX
;
538 WIN_ReleasePtr( wndPtr
);
540 old_style
= WIN_SetStyle( hwnd
, WS_MINIMIZE
, WS_MAXIMIZE
);
542 X11DRV_set_iconic_state( hwnd
);
544 wpl
.ptMinPosition
= WINPOS_FindIconPos( hwnd
, wpl
.ptMinPosition
);
546 if (!(old_style
& WS_MINIMIZE
)) swpFlags
|= SWP_STATECHANGED
;
547 SetRect( rect
, wpl
.ptMinPosition
.x
, wpl
.ptMinPosition
.y
,
548 GetSystemMetrics(SM_CXICON
), GetSystemMetrics(SM_CYICON
) );
549 swpFlags
|= SWP_NOCOPYBITS
;
553 old_style
= GetWindowLongW( hwnd
, GWL_STYLE
);
554 if ((old_style
& WS_MAXIMIZE
) && (old_style
& WS_VISIBLE
)) return SWP_NOSIZE
| SWP_NOMOVE
;
556 WINPOS_GetMinMaxInfo( hwnd
, &size
, &wpl
.ptMaxPosition
, NULL
, NULL
);
558 old_style
= WIN_SetStyle( hwnd
, WS_MAXIMIZE
, WS_MINIMIZE
);
559 if (old_style
& WS_MINIMIZE
)
561 WINPOS_ShowIconTitle( hwnd
, FALSE
);
562 X11DRV_set_iconic_state( hwnd
);
564 if (!(old_style
& WS_MAXIMIZE
)) swpFlags
|= SWP_STATECHANGED
;
565 SetRect( rect
, wpl
.ptMaxPosition
.x
, wpl
.ptMaxPosition
.y
, size
.x
, size
.y
);
568 case SW_SHOWNOACTIVATE
:
571 old_style
= WIN_SetStyle( hwnd
, 0, WS_MINIMIZE
| WS_MAXIMIZE
);
572 if (old_style
& WS_MINIMIZE
)
576 WINPOS_ShowIconTitle( hwnd
, FALSE
);
577 X11DRV_set_iconic_state( hwnd
);
579 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
580 restore_max
= (wndPtr
->flags
& WIN_RESTORE_MAX
) != 0;
581 WIN_ReleasePtr( wndPtr
);
584 /* Restore to maximized position */
585 WINPOS_GetMinMaxInfo( hwnd
, &size
, &wpl
.ptMaxPosition
, NULL
, NULL
);
586 WIN_SetStyle( hwnd
, WS_MAXIMIZE
, 0 );
587 swpFlags
|= SWP_STATECHANGED
;
588 SetRect( rect
, wpl
.ptMaxPosition
.x
, wpl
.ptMaxPosition
.y
, size
.x
, size
.y
);
592 else if (!(old_style
& WS_MAXIMIZE
)) break;
594 swpFlags
|= SWP_STATECHANGED
;
596 /* Restore to normal position */
598 *rect
= wpl
.rcNormalPosition
;
599 rect
->right
-= rect
->left
;
600 rect
->bottom
-= rect
->top
;
609 /***********************************************************************
610 * ShowWindow (X11DRV.@)
612 BOOL
X11DRV_ShowWindow( HWND hwnd
, INT cmd
)
616 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
617 BOOL wasVisible
= (style
& WS_VISIBLE
) != 0;
618 BOOL showFlag
= TRUE
;
619 RECT newPos
= {0, 0, 0, 0};
622 TRACE("hwnd=%p, cmd=%d, wasVisible %d\n", hwnd
, cmd
, wasVisible
);
627 if (!wasVisible
) return FALSE
;
629 swp
|= SWP_HIDEWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
630 if (hwnd
!= GetActiveWindow())
631 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
634 case SW_SHOWMINNOACTIVE
:
635 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
638 case SW_FORCEMINIMIZE
: /* FIXME: Does not work if thread is hung. */
639 if (style
& WS_CHILD
) swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
641 case SW_SHOWMINIMIZED
:
642 swp
|= SWP_SHOWWINDOW
| SWP_FRAMECHANGED
;
643 swp
|= WINPOS_MinMaximize( hwnd
, cmd
, &newPos
);
644 if ((style
& WS_MINIMIZE
) && wasVisible
) return TRUE
;
647 case SW_SHOWMAXIMIZED
: /* same as SW_MAXIMIZE */
648 if (!wasVisible
) swp
|= SWP_SHOWWINDOW
;
649 swp
|= SWP_FRAMECHANGED
;
650 swp
|= WINPOS_MinMaximize( hwnd
, SW_MAXIMIZE
, &newPos
);
651 if ((style
& WS_MAXIMIZE
) && wasVisible
) return TRUE
;
655 swp
|= SWP_NOACTIVATE
| SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
656 if (style
& WS_CHILD
) swp
|= SWP_NOZORDER
;
659 if (wasVisible
) return TRUE
;
660 swp
|= SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
661 if (style
& WS_CHILD
) swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
664 case SW_SHOWNOACTIVATE
:
665 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
669 case SW_SHOWNORMAL
: /* same as SW_NORMAL: */
670 case SW_SHOWDEFAULT
: /* FIXME: should have its own handler */
671 if (!wasVisible
) swp
|= SWP_SHOWWINDOW
;
672 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
674 swp
|= SWP_FRAMECHANGED
;
675 swp
|= WINPOS_MinMaximize( hwnd
, cmd
, &newPos
);
679 if (wasVisible
) return TRUE
;
680 swp
|= SWP_NOSIZE
| SWP_NOMOVE
;
682 if (style
& WS_CHILD
&& !(swp
& SWP_STATECHANGED
)) swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
686 if ((showFlag
!= wasVisible
|| cmd
== SW_SHOWNA
) && cmd
!= SW_SHOWMAXIMIZED
&& !(swp
& SWP_STATECHANGED
))
688 SendMessageW( hwnd
, WM_SHOWWINDOW
, showFlag
, 0 );
689 if (!IsWindow( hwnd
)) return wasVisible
;
692 parent
= GetAncestor( hwnd
, GA_PARENT
);
693 if (parent
&& !IsWindowVisible( parent
) && !(swp
& SWP_STATECHANGED
))
695 /* if parent is not visible simply toggle WS_VISIBLE and return */
696 if (showFlag
) WIN_SetStyle( hwnd
, WS_VISIBLE
, 0 );
697 else WIN_SetStyle( hwnd
, 0, WS_VISIBLE
);
700 SetWindowPos( hwnd
, HWND_TOP
, newPos
.left
, newPos
.top
,
701 newPos
.right
, newPos
.bottom
, LOWORD(swp
) );
707 /* FIXME: This will cause the window to be activated irrespective
708 * of whether it is owned by the same thread. Has to be done
712 if (hwnd
== GetActiveWindow())
713 WINPOS_ActivateOtherWindow(hwnd
);
715 /* Revert focus to parent */
717 if (hwnd
== hFocus
|| IsChild(hwnd
, hFocus
))
719 HWND parent
= GetAncestor(hwnd
, GA_PARENT
);
720 if (parent
== GetDesktopWindow()) parent
= 0;
725 if (IsIconic(hwnd
)) WINPOS_ShowIconTitle( hwnd
, TRUE
);
727 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return wasVisible
;
729 if (wndPtr
->flags
& WIN_NEED_SIZE
)
731 /* should happen only in CreateWindowEx() */
732 int wParam
= SIZE_RESTORED
;
733 RECT client
= wndPtr
->rectClient
;
735 wndPtr
->flags
&= ~WIN_NEED_SIZE
;
736 if (wndPtr
->dwStyle
& WS_MAXIMIZE
) wParam
= SIZE_MAXIMIZED
;
737 else if (wndPtr
->dwStyle
& WS_MINIMIZE
) wParam
= SIZE_MINIMIZED
;
738 WIN_ReleasePtr( wndPtr
);
740 SendMessageW( hwnd
, WM_SIZE
, wParam
,
741 MAKELONG( client
.right
- client
.left
, client
.bottom
- client
.top
));
742 SendMessageW( hwnd
, WM_MOVE
, 0, MAKELONG( client
.left
, client
.top
));
744 else WIN_ReleasePtr( wndPtr
);
746 /* if previous state was minimized Windows sets focus to the window */
747 if (style
& WS_MINIMIZE
) SetFocus( hwnd
);
753 /**********************************************************************
756 void X11DRV_MapNotify( HWND hwnd
, XEvent
*event
)
758 struct x11drv_win_data
*data
;
759 HWND hwndFocus
= GetFocus();
762 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
764 if (!(win
= WIN_GetPtr( hwnd
))) return;
766 if (data
->managed
&& (win
->dwStyle
& WS_VISIBLE
) && (win
->dwStyle
& WS_MINIMIZE
))
769 unsigned int width
, height
, border
, depth
;
772 LONG style
= WS_VISIBLE
;
776 XGetGeometry( event
->xmap
.display
, data
->whole_window
, &root
, &x
, &y
, &width
, &height
,
778 XTranslateCoordinates( event
->xmap
.display
, data
->whole_window
, root
, 0, 0, &x
, &y
, &top
);
782 rect
.right
= x
+ width
;
783 rect
.bottom
= y
+ height
;
784 OffsetRect( &rect
, virtual_screen_rect
.left
, virtual_screen_rect
.top
);
785 X11DRV_X_to_window_rect( data
, &rect
);
787 invalidate_dce( hwnd
, &data
->window_rect
);
789 if (win
->flags
& WIN_RESTORE_MAX
) style
|= WS_MAXIMIZE
;
790 WIN_SetStyle( hwnd
, style
, WS_MINIMIZE
);
791 WIN_ReleasePtr( win
);
793 SendMessageW( hwnd
, WM_SHOWWINDOW
, SW_RESTORE
, 0 );
794 data
->lock_changes
++;
795 SetWindowPos( hwnd
, 0, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
,
796 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_FRAMECHANGED
| SWP_STATECHANGED
);
797 data
->lock_changes
--;
799 else WIN_ReleasePtr( win
);
800 if (hwndFocus
&& IsChild( hwnd
, hwndFocus
)) X11DRV_SetFocus(hwndFocus
); /* FIXME */
804 /**********************************************************************
807 void X11DRV_UnmapNotify( HWND hwnd
, XEvent
*event
)
809 struct x11drv_win_data
*data
;
812 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
814 if (!(win
= WIN_GetPtr( hwnd
))) return;
816 if ((win
->dwStyle
& WS_VISIBLE
) && data
->managed
&&
817 X11DRV_is_window_rect_mapped( &win
->rectWindow
))
819 if (win
->dwStyle
& WS_MAXIMIZE
)
820 win
->flags
|= WIN_RESTORE_MAX
;
821 else if (!(win
->dwStyle
& WS_MINIMIZE
))
822 win
->flags
&= ~WIN_RESTORE_MAX
;
824 WIN_SetStyle( hwnd
, WS_MINIMIZE
, WS_MAXIMIZE
);
825 WIN_ReleasePtr( win
);
828 SendMessageW( hwnd
, WM_SHOWWINDOW
, SW_MINIMIZE
, 0 );
829 data
->lock_changes
++;
830 SetWindowPos( hwnd
, 0, 0, 0, GetSystemMetrics(SM_CXICON
), GetSystemMetrics(SM_CYICON
),
831 SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_STATECHANGED
);
832 data
->lock_changes
--;
834 else WIN_ReleasePtr( win
);
837 struct desktop_resize_data
839 RECT old_screen_rect
;
840 RECT old_virtual_rect
;
843 static BOOL CALLBACK
update_windows_on_desktop_resize( HWND hwnd
, LPARAM lparam
)
845 struct x11drv_win_data
*data
;
846 Display
*display
= thread_display();
847 struct desktop_resize_data
*resize_data
= (struct desktop_resize_data
*)lparam
;
850 if (!(data
= X11DRV_get_win_data( hwnd
))) return TRUE
;
852 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
)
854 /* update the full screen state */
855 update_wm_states( display
, data
, FALSE
);
858 if (resize_data
->old_virtual_rect
.left
!= virtual_screen_rect
.left
) mask
|= CWX
;
859 if (resize_data
->old_virtual_rect
.top
!= virtual_screen_rect
.top
) mask
|= CWY
;
860 if (mask
&& data
->whole_window
)
862 XWindowChanges changes
;
865 changes
.x
= data
->whole_rect
.left
- virtual_screen_rect
.left
;
866 changes
.y
= data
->whole_rect
.top
- virtual_screen_rect
.top
;
867 XReconfigureWMWindow( display
, data
->whole_window
,
868 DefaultScreen(display
), mask
, &changes
);
875 /***********************************************************************
876 * X11DRV_handle_desktop_resize
878 void X11DRV_handle_desktop_resize( unsigned int width
, unsigned int height
)
880 HWND hwnd
= GetDesktopWindow();
881 struct x11drv_win_data
*data
;
882 struct desktop_resize_data resize_data
;
884 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
886 SetRect( &resize_data
.old_screen_rect
, 0, 0, screen_width
, screen_height
);
887 resize_data
.old_virtual_rect
= virtual_screen_rect
;
889 screen_width
= width
;
890 screen_height
= height
;
892 TRACE("desktop %p change to (%dx%d)\n", hwnd
, width
, height
);
893 data
->lock_changes
++;
894 X11DRV_SetWindowPos( hwnd
, 0, &virtual_screen_rect
, &virtual_screen_rect
,
895 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOACTIVATE
, NULL
);
896 data
->lock_changes
--;
898 SendMessageTimeoutW( HWND_BROADCAST
, WM_DISPLAYCHANGE
, screen_bpp
,
899 MAKELPARAM( width
, height
), SMTO_ABORTIFHUNG
, 2000, NULL
);
901 EnumWindows( update_windows_on_desktop_resize
, (LPARAM
)&resize_data
);
905 /***********************************************************************
906 * X11DRV_ConfigureNotify
908 void X11DRV_ConfigureNotify( HWND hwnd
, XEvent
*xev
)
910 XConfigureEvent
*event
= &xev
->xconfigure
;
911 struct x11drv_win_data
*data
;
914 int cx
, cy
, x
= event
->x
, y
= event
->y
;
917 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
921 if (!event
->send_event
) /* normal event, need to map coordinates to the root */
925 XTranslateCoordinates( event
->display
, data
->whole_window
, root_window
,
926 0, 0, &x
, &y
, &child
);
931 rect
.right
= x
+ event
->width
;
932 rect
.bottom
= y
+ event
->height
;
933 OffsetRect( &rect
, virtual_screen_rect
.left
, virtual_screen_rect
.top
);
934 TRACE( "win %p new X rect %d,%d,%dx%d (event %d,%d,%dx%d)\n",
935 hwnd
, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
,
936 event
->x
, event
->y
, event
->width
, event
->height
);
937 X11DRV_X_to_window_rect( data
, &rect
);
941 cx
= rect
.right
- rect
.left
;
942 cy
= rect
.bottom
- rect
.top
;
943 flags
= SWP_NOACTIVATE
| SWP_NOZORDER
;
945 /* Compare what has changed */
947 GetWindowRect( hwnd
, &rect
);
948 if (rect
.left
== x
&& rect
.top
== y
) flags
|= SWP_NOMOVE
;
950 TRACE( "%p moving from (%d,%d) to (%d,%d)\n",
951 hwnd
, rect
.left
, rect
.top
, x
, y
);
953 if ((rect
.right
- rect
.left
== cx
&& rect
.bottom
- rect
.top
== cy
) ||
955 (IsRectEmpty( &rect
) && event
->width
== 1 && event
->height
== 1))
957 if (flags
& SWP_NOMOVE
) return; /* if nothing changed, don't do anything */
961 TRACE( "%p resizing from (%dx%d) to (%dx%d)\n",
962 hwnd
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, cx
, cy
);
964 data
->lock_changes
++;
965 SetWindowPos( hwnd
, 0, x
, y
, cx
, cy
, flags
);
966 data
->lock_changes
--;
970 /***********************************************************************
971 * SetWindowRgn (X11DRV.@)
973 * Assign specified region to window (for non-rectangular windows)
975 int X11DRV_SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL redraw
)
977 struct x11drv_win_data
*data
;
979 if (!(data
= X11DRV_get_win_data( hwnd
)))
981 if (IsWindow( hwnd
))
982 FIXME( "not supported on other thread window %p\n", hwnd
);
983 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
987 #ifdef HAVE_LIBXSHAPE
988 if (data
->whole_window
)
990 Display
*display
= thread_display();
995 XShapeCombineMask( display
, data
->whole_window
,
996 ShapeBounding
, 0, 0, None
, ShapeSet
);
1001 RGNDATA
*pRegionData
= X11DRV_GetRegionData( hrgn
, 0 );
1005 XShapeCombineRectangles( display
, data
->whole_window
, ShapeBounding
,
1006 data
->window_rect
.left
- data
->whole_rect
.left
,
1007 data
->window_rect
.top
- data
->whole_rect
.top
,
1008 (XRectangle
*)pRegionData
->Buffer
,
1009 pRegionData
->rdh
.nCount
,
1010 ShapeSet
, YXBanded
);
1011 wine_tsx11_unlock();
1012 HeapFree(GetProcessHeap(), 0, pRegionData
);
1016 #endif /* HAVE_LIBXSHAPE */
1018 invalidate_dce( hwnd
, &data
->window_rect
);
1023 /***********************************************************************
1026 * Draw the frame used when moving or resizing window.
1028 * FIXME: This causes problems in Win95 mode. (why?)
1030 static void draw_moving_frame( HDC hdc
, RECT
*rect
, BOOL thickframe
)
1034 const int width
= GetSystemMetrics(SM_CXFRAME
);
1035 const int height
= GetSystemMetrics(SM_CYFRAME
);
1037 HBRUSH hbrush
= SelectObject( hdc
, GetStockObject( GRAY_BRUSH
) );
1038 PatBlt( hdc
, rect
->left
, rect
->top
,
1039 rect
->right
- rect
->left
- width
, height
, PATINVERT
);
1040 PatBlt( hdc
, rect
->left
, rect
->top
+ height
, width
,
1041 rect
->bottom
- rect
->top
- height
, PATINVERT
);
1042 PatBlt( hdc
, rect
->left
+ width
, rect
->bottom
- 1,
1043 rect
->right
- rect
->left
- width
, -height
, PATINVERT
);
1044 PatBlt( hdc
, rect
->right
- 1, rect
->top
, -width
,
1045 rect
->bottom
- rect
->top
- height
, PATINVERT
);
1046 SelectObject( hdc
, hbrush
);
1048 else DrawFocusRect( hdc
, rect
);
1052 /***********************************************************************
1055 * Initialisation of a move or resize, when initiatied from a menu choice.
1056 * Return hit test code for caption or sizing border.
1058 static LONG
start_size_move( HWND hwnd
, WPARAM wParam
, POINT
*capturePoint
, LONG style
)
1065 GetWindowRect( hwnd
, &rectWindow
);
1067 if ((wParam
& 0xfff0) == SC_MOVE
)
1069 /* Move pointer at the center of the caption */
1070 RECT rect
= rectWindow
;
1071 /* Note: to be exactly centered we should take the different types
1072 * of border into account, but it shouldn't make more that a few pixels
1073 * of difference so let's not bother with that */
1074 rect
.top
+= GetSystemMetrics(SM_CYBORDER
);
1075 if (style
& WS_SYSMENU
)
1076 rect
.left
+= GetSystemMetrics(SM_CXSIZE
) + 1;
1077 if (style
& WS_MINIMIZEBOX
)
1078 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
1079 if (style
& WS_MAXIMIZEBOX
)
1080 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
1081 pt
.x
= (rect
.right
+ rect
.left
) / 2;
1082 pt
.y
= rect
.top
+ GetSystemMetrics(SM_CYSIZE
)/2;
1083 hittest
= HTCAPTION
;
1091 GetMessageW( &msg
, 0, WM_KEYFIRST
, WM_MOUSELAST
);
1092 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
1098 hittest
= SendMessageW( hwnd
, WM_NCHITTEST
, 0, MAKELONG( pt
.x
, pt
.y
) );
1099 if ((hittest
< HTLEFT
) || (hittest
> HTBOTTOMRIGHT
)) hittest
= 0;
1110 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
1111 pt
.y
= rectWindow
.top
+ GetSystemMetrics(SM_CYFRAME
) / 2;
1115 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
1116 pt
.y
= rectWindow
.bottom
- GetSystemMetrics(SM_CYFRAME
) / 2;
1120 pt
.x
= rectWindow
.left
+ GetSystemMetrics(SM_CXFRAME
) / 2;
1121 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
1125 pt
.x
= rectWindow
.right
- GetSystemMetrics(SM_CXFRAME
) / 2;
1126 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
1129 case VK_ESCAPE
: return 0;
1135 SetCursorPos( pt
.x
, pt
.y
);
1136 SendMessageW( hwnd
, WM_SETCURSOR
, (WPARAM
)hwnd
, MAKELONG( hittest
, WM_MOUSEMOVE
));
1141 /***********************************************************************
1142 * set_movesize_capture
1144 static void set_movesize_capture( HWND hwnd
)
1148 SERVER_START_REQ( set_capture_window
)
1151 req
->flags
= CAPTURE_MOVESIZE
;
1152 if (!wine_server_call_err( req
))
1154 previous
= reply
->previous
;
1155 hwnd
= reply
->full_handle
;
1159 if (previous
&& previous
!= hwnd
)
1160 SendMessageW( previous
, WM_CAPTURECHANGED
, 0, (LPARAM
)hwnd
);
1163 /***********************************************************************
1164 * X11DRV_WMMoveResizeWindow
1166 * Tells the window manager to initiate a move or resize operation.
1169 * http://freedesktop.org/Standards/wm-spec/1.3/ar01s04.html
1170 * or search for "_NET_WM_MOVERESIZE"
1172 static BOOL
X11DRV_WMMoveResizeWindow( HWND hwnd
, int x
, int y
, WPARAM wparam
)
1174 WPARAM syscommand
= wparam
& 0xfff0;
1175 WPARAM hittest
= wparam
& 0x0f;
1178 Display
*display
= thread_display();
1180 if (syscommand
== SC_MOVE
)
1182 if (!hittest
) dir
= _NET_WM_MOVERESIZE_MOVE_KEYBOARD
;
1183 else dir
= _NET_WM_MOVERESIZE_MOVE
;
1187 /* windows without WS_THICKFRAME are not resizable through the window manager */
1188 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_THICKFRAME
)) return FALSE
;
1192 case WMSZ_LEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_LEFT
; break;
1193 case WMSZ_RIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_RIGHT
; break;
1194 case WMSZ_TOP
: dir
= _NET_WM_MOVERESIZE_SIZE_TOP
; break;
1195 case WMSZ_TOPLEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_TOPLEFT
; break;
1196 case WMSZ_TOPRIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_TOPRIGHT
; break;
1197 case WMSZ_BOTTOM
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOM
; break;
1198 case WMSZ_BOTTOMLEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT
; break;
1199 case WMSZ_BOTTOMRIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT
; break;
1200 default: dir
= _NET_WM_MOVERESIZE_SIZE_KEYBOARD
; break;
1204 TRACE("hwnd %p, x %d, y %d, dir %d\n", hwnd
, x
, y
, dir
);
1206 xev
.xclient
.type
= ClientMessage
;
1207 xev
.xclient
.window
= X11DRV_get_whole_window(hwnd
);
1208 xev
.xclient
.message_type
= x11drv_atom(_NET_WM_MOVERESIZE
);
1209 xev
.xclient
.serial
= 0;
1210 xev
.xclient
.display
= display
;
1211 xev
.xclient
.send_event
= True
;
1212 xev
.xclient
.format
= 32;
1213 xev
.xclient
.data
.l
[0] = x
; /* x coord */
1214 xev
.xclient
.data
.l
[1] = y
; /* y coord */
1215 xev
.xclient
.data
.l
[2] = dir
; /* direction */
1216 xev
.xclient
.data
.l
[3] = 1; /* button */
1217 xev
.xclient
.data
.l
[4] = 0; /* unused */
1219 /* need to ungrab the pointer that may have been automatically grabbed
1220 * with a ButtonPress event */
1222 XUngrabPointer( display
, CurrentTime
);
1223 XSendEvent(display
, root_window
, False
, SubstructureNotifyMask
, &xev
);
1224 wine_tsx11_unlock();
1228 /***********************************************************************
1229 * SysCommandSizeMove (X11DRV.@)
1231 * Perform SC_MOVE and SC_SIZE commands.
1233 void X11DRV_SysCommandSizeMove( HWND hwnd
, WPARAM wParam
)
1236 RECT sizingRect
, mouseRect
, origRect
;
1239 LONG hittest
= (LONG
)(wParam
& 0x0f);
1240 WPARAM syscommand
= wParam
& 0xfff0;
1241 HCURSOR hDragCursor
= 0, hOldCursor
= 0;
1242 POINT minTrack
, maxTrack
;
1243 POINT capturePoint
, pt
;
1244 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
1245 BOOL thickframe
= HAS_THICKFRAME( style
);
1246 BOOL iconic
= style
& WS_MINIMIZE
;
1248 DWORD dwPoint
= GetMessagePos ();
1249 BOOL DragFullWindows
= TRUE
;
1250 Window parent_win
, whole_win
;
1251 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1252 struct x11drv_win_data
*data
;
1254 pt
.x
= (short)LOWORD(dwPoint
);
1255 pt
.y
= (short)HIWORD(dwPoint
);
1258 if (IsZoomed(hwnd
) || !IsWindowVisible(hwnd
)) return;
1260 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1262 TRACE("hwnd %p (%smanaged), command %04lx, hittest %d, pos %d,%d\n",
1263 hwnd
, data
->managed
? "" : "NOT ", syscommand
, hittest
, pt
.x
, pt
.y
);
1265 /* if we are managed then we let the WM do all the work */
1266 if (data
->managed
&& X11DRV_WMMoveResizeWindow( hwnd
, pt
.x
, pt
.y
, wParam
)) return;
1268 if (syscommand
== SC_MOVE
)
1270 if (!hittest
) hittest
= start_size_move( hwnd
, wParam
, &capturePoint
, style
);
1271 if (!hittest
) return;
1275 if ( hittest
&& (syscommand
!= SC_MOUSEMENU
) )
1276 hittest
+= (HTLEFT
- WMSZ_LEFT
);
1279 set_movesize_capture( hwnd
);
1280 hittest
= start_size_move( hwnd
, wParam
, &capturePoint
, style
);
1283 set_movesize_capture(0);
1289 /* Get min/max info */
1291 WINPOS_GetMinMaxInfo( hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
1292 GetWindowRect( hwnd
, &sizingRect
);
1293 if (style
& WS_CHILD
)
1295 parent
= GetParent(hwnd
);
1296 /* make sizing rect relative to parent */
1297 MapWindowPoints( 0, parent
, (POINT
*)&sizingRect
, 2 );
1298 GetClientRect( parent
, &mouseRect
);
1303 mouseRect
= virtual_screen_rect
;
1305 origRect
= sizingRect
;
1307 if (ON_LEFT_BORDER(hittest
))
1309 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.right
-maxTrack
.x
);
1310 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.right
-minTrack
.x
);
1312 else if (ON_RIGHT_BORDER(hittest
))
1314 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.left
+minTrack
.x
);
1315 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.left
+maxTrack
.x
);
1317 if (ON_TOP_BORDER(hittest
))
1319 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.bottom
-maxTrack
.y
);
1320 mouseRect
.bottom
= min( mouseRect
.bottom
,sizingRect
.bottom
-minTrack
.y
);
1322 else if (ON_BOTTOM_BORDER(hittest
))
1324 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.top
+minTrack
.y
);
1325 mouseRect
.bottom
= min( mouseRect
.bottom
, sizingRect
.top
+maxTrack
.y
);
1327 if (parent
) MapWindowPoints( parent
, 0, (LPPOINT
)&mouseRect
, 2 );
1329 /* Retrieve a default cache DC (without using the window style) */
1330 hdc
= GetDCEx( parent
, 0, DCX_CACHE
);
1332 if( iconic
) /* create a cursor for dragging */
1334 hDragCursor
= (HCURSOR
)GetClassLongPtrW( hwnd
, GCLP_HICON
);
1335 if( !hDragCursor
) hDragCursor
= (HCURSOR
)SendMessageW( hwnd
, WM_QUERYDRAGICON
, 0, 0L);
1336 if( !hDragCursor
) iconic
= FALSE
;
1339 /* repaint the window before moving it around */
1340 RedrawWindow( hwnd
, NULL
, 0, RDW_UPDATENOW
| RDW_ALLCHILDREN
);
1342 SendMessageW( hwnd
, WM_ENTERSIZEMOVE
, 0, 0 );
1343 set_movesize_capture( hwnd
);
1345 /* we only allow disabling the full window drag for child windows, or in desktop mode */
1346 /* otherwise we'd need to grab the server and we want to avoid that */
1347 if (parent
|| (root_window
!= DefaultRootWindow(gdi_display
)))
1348 SystemParametersInfoA(SPI_GETDRAGFULLWINDOWS
, 0, &DragFullWindows
, 0);
1350 whole_win
= X11DRV_get_whole_window( GetAncestor(hwnd
,GA_ROOT
) );
1351 parent_win
= parent
? X11DRV_get_whole_window( GetAncestor(parent
,GA_ROOT
) ) : root_window
;
1354 XGrabPointer( thread_data
->display
, whole_win
, False
,
1355 PointerMotionMask
| ButtonPressMask
| ButtonReleaseMask
,
1356 GrabModeAsync
, GrabModeAsync
, parent_win
, None
, CurrentTime
);
1357 wine_tsx11_unlock();
1358 thread_data
->grab_window
= whole_win
;
1364 if (!GetMessageW( &msg
, 0, 0, 0 )) break;
1365 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
1367 /* Exit on button-up, Return, or Esc */
1368 if ((msg
.message
== WM_LBUTTONUP
) ||
1369 ((msg
.message
== WM_KEYDOWN
) &&
1370 ((msg
.wParam
== VK_RETURN
) || (msg
.wParam
== VK_ESCAPE
)))) break;
1372 if ((msg
.message
!= WM_KEYDOWN
) && (msg
.message
!= WM_MOUSEMOVE
))
1374 TranslateMessage( &msg
);
1375 DispatchMessageW( &msg
);
1376 continue; /* We are not interested in other messages */
1381 if (msg
.message
== WM_KEYDOWN
) switch(msg
.wParam
)
1383 case VK_UP
: pt
.y
-= 8; break;
1384 case VK_DOWN
: pt
.y
+= 8; break;
1385 case VK_LEFT
: pt
.x
-= 8; break;
1386 case VK_RIGHT
: pt
.x
+= 8; break;
1389 pt
.x
= max( pt
.x
, mouseRect
.left
);
1390 pt
.x
= min( pt
.x
, mouseRect
.right
);
1391 pt
.y
= max( pt
.y
, mouseRect
.top
);
1392 pt
.y
= min( pt
.y
, mouseRect
.bottom
);
1394 dx
= pt
.x
- capturePoint
.x
;
1395 dy
= pt
.y
- capturePoint
.y
;
1403 if( iconic
) /* ok, no system popup tracking */
1405 hOldCursor
= SetCursor(hDragCursor
);
1407 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1409 else if(!DragFullWindows
)
1410 draw_moving_frame( hdc
, &sizingRect
, thickframe
);
1413 if (msg
.message
== WM_KEYDOWN
) SetCursorPos( pt
.x
, pt
.y
);
1416 RECT newRect
= sizingRect
;
1417 WPARAM wpSizingHit
= 0;
1419 if (hittest
== HTCAPTION
) OffsetRect( &newRect
, dx
, dy
);
1420 if (ON_LEFT_BORDER(hittest
)) newRect
.left
+= dx
;
1421 else if (ON_RIGHT_BORDER(hittest
)) newRect
.right
+= dx
;
1422 if (ON_TOP_BORDER(hittest
)) newRect
.top
+= dy
;
1423 else if (ON_BOTTOM_BORDER(hittest
)) newRect
.bottom
+= dy
;
1424 if(!iconic
&& !DragFullWindows
) draw_moving_frame( hdc
, &sizingRect
, thickframe
);
1427 /* determine the hit location */
1428 if (hittest
>= HTLEFT
&& hittest
<= HTBOTTOMRIGHT
)
1429 wpSizingHit
= WMSZ_LEFT
+ (hittest
- HTLEFT
);
1430 SendMessageW( hwnd
, WM_SIZING
, wpSizingHit
, (LPARAM
)&newRect
);
1434 if(!DragFullWindows
)
1435 draw_moving_frame( hdc
, &newRect
, thickframe
);
1437 SetWindowPos( hwnd
, 0, newRect
.left
, newRect
.top
,
1438 newRect
.right
- newRect
.left
,
1439 newRect
.bottom
- newRect
.top
,
1440 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
1442 sizingRect
= newRect
;
1447 set_movesize_capture(0);
1450 if( moved
) /* restore cursors, show icon title later on */
1452 ShowCursor( FALSE
);
1453 SetCursor( hOldCursor
);
1456 else if (moved
&& !DragFullWindows
)
1458 draw_moving_frame( hdc
, &sizingRect
, thickframe
);
1459 /* make sure the moving frame is erased before we move the window */
1461 XFlush( gdi_display
);
1462 wine_tsx11_unlock();
1465 ReleaseDC( parent
, hdc
);
1468 XUngrabPointer( thread_data
->display
, CurrentTime
);
1469 wine_tsx11_unlock();
1470 thread_data
->grab_window
= None
;
1472 if (HOOK_CallHooks( WH_CBT
, HCBT_MOVESIZE
, (WPARAM
)hwnd
, (LPARAM
)&sizingRect
, TRUE
))
1475 SendMessageW( hwnd
, WM_EXITSIZEMOVE
, 0, 0 );
1476 SendMessageW( hwnd
, WM_SETVISIBLE
, !IsIconic(hwnd
), 0L);
1478 /* window moved or resized */
1481 /* if the moving/resizing isn't canceled call SetWindowPos
1482 * with the new position or the new size of the window
1484 if (!((msg
.message
== WM_KEYDOWN
) && (msg
.wParam
== VK_ESCAPE
)) )
1486 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
1487 if(!DragFullWindows
)
1488 SetWindowPos( hwnd
, 0, sizingRect
.left
, sizingRect
.top
,
1489 sizingRect
.right
- sizingRect
.left
,
1490 sizingRect
.bottom
- sizingRect
.top
,
1491 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
1494 { /* restore previous size/position */
1496 SetWindowPos( hwnd
, 0, origRect
.left
, origRect
.top
,
1497 origRect
.right
- origRect
.left
,
1498 origRect
.bottom
- origRect
.top
,
1499 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
1505 /* Single click brings up the system menu when iconized */
1509 if(style
& WS_SYSMENU
)
1510 SendMessageW( hwnd
, WM_SYSCOMMAND
,
1511 SC_MOUSEMENU
+ HTSYSMENU
, MAKELONG(pt
.x
,pt
.y
));
1513 else WINPOS_ShowIconTitle( hwnd
, TRUE
);