2 * Window position related functions.
4 * Copyright 1993, 1994, 1995, 2001 Alexandre Julliard
5 * Copyright 1995, 1996, 1999 Alex Korobka
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include <X11/Xutil.h>
33 #include "wine/wingdi16.h"
38 #include "wine/server.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(x11drv
);
43 #define SWP_AGG_NOPOSCHANGE \
44 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_NOZORDER)
46 #define SWP_EX_NOCOPY 0x0001
47 #define SWP_EX_PAINTSELF 0x0002
48 #define SWP_EX_NONCLIENT 0x0004
50 #define HAS_THICKFRAME(style) \
51 (((style) & WS_THICKFRAME) && \
52 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
54 #define ON_LEFT_BORDER(hit) \
55 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
56 #define ON_RIGHT_BORDER(hit) \
57 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
58 #define ON_TOP_BORDER(hit) \
59 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
60 #define ON_BOTTOM_BORDER(hit) \
61 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
63 #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0
64 #define _NET_WM_MOVERESIZE_SIZE_TOP 1
65 #define _NET_WM_MOVERESIZE_SIZE_TOPRIGHT 2
66 #define _NET_WM_MOVERESIZE_SIZE_RIGHT 3
67 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
68 #define _NET_WM_MOVERESIZE_SIZE_BOTTOM 5
69 #define _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
70 #define _NET_WM_MOVERESIZE_SIZE_LEFT 7
71 #define _NET_WM_MOVERESIZE_MOVE 8 /* movement only */
72 #define _NET_WM_MOVERESIZE_SIZE_KEYBOARD 9 /* size via keyboard */
73 #define _NET_WM_MOVERESIZE_MOVE_KEYBOARD 10 /* move via keyboard */
75 #define _NET_WM_STATE_REMOVE 0
76 #define _NET_WM_STATE_ADD 1
77 #define _NET_WM_STATE_TOGGLE 2
79 static const char managed_prop
[] = "__wine_x11_managed";
81 /***********************************************************************
84 void X11DRV_Expose( HWND hwnd
, XEvent
*xev
)
86 XExposeEvent
*event
= &xev
->xexpose
;
88 struct x11drv_win_data
*data
;
89 int flags
= RDW_INVALIDATE
| RDW_ERASE
| RDW_ALLCHILDREN
;
91 TRACE( "win %p (%lx) %d,%d %dx%d\n",
92 hwnd
, event
->window
, event
->x
, event
->y
, event
->width
, event
->height
);
94 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
96 rect
.left
= data
->whole_rect
.left
+ event
->x
;
97 rect
.top
= data
->whole_rect
.top
+ event
->y
;
98 rect
.right
= rect
.left
+ event
->width
;
99 rect
.bottom
= rect
.top
+ event
->height
;
101 if (event
->window
== root_window
)
102 OffsetRect( &rect
, virtual_screen_rect
.left
, virtual_screen_rect
.top
);
104 if (rect
.left
< data
->client_rect
.left
||
105 rect
.top
< data
->client_rect
.top
||
106 rect
.right
> data
->client_rect
.right
||
107 rect
.bottom
> data
->client_rect
.bottom
) flags
|= RDW_FRAME
;
109 SERVER_START_REQ( update_window_zorder
)
112 req
->rect
.left
= rect
.left
;
113 req
->rect
.top
= rect
.top
;
114 req
->rect
.right
= rect
.right
;
115 req
->rect
.bottom
= rect
.bottom
;
116 wine_server_call( req
);
120 /* make position relative to client area instead of parent */
121 OffsetRect( &rect
, -data
->client_rect
.left
, -data
->client_rect
.top
);
122 RedrawWindow( hwnd
, &rect
, 0, flags
);
125 /***********************************************************************
126 * SetWindowStyle (X11DRV.@)
128 * Update the X state of a window to reflect a style change
130 void X11DRV_SetWindowStyle( HWND hwnd
, DWORD old_style
)
132 Display
*display
= thread_display();
133 struct x11drv_win_data
*data
;
134 DWORD new_style
, changed
;
136 if (hwnd
== GetDesktopWindow()) return;
137 new_style
= GetWindowLongW( hwnd
, GWL_STYLE
);
138 changed
= new_style
^ old_style
;
140 if (changed
& WS_VISIBLE
)
142 data
= X11DRV_get_win_data( hwnd
);
143 if (data
) invalidate_dce( hwnd
, &data
->window_rect
);
145 /* we don't unmap windows, that causes trouble with the window manager */
146 if (!(new_style
& WS_VISIBLE
)) return;
148 if (!data
&& !(data
= X11DRV_create_win_data( hwnd
))) return;
150 if (data
->whole_window
&& X11DRV_is_window_rect_mapped( &data
->window_rect
))
152 X11DRV_set_wm_hints( display
, data
);
155 TRACE( "mapping win %p\n", hwnd
);
156 X11DRV_sync_window_style( display
, data
);
158 XMapWindow( display
, data
->whole_window
);
165 if (changed
& WS_DISABLED
)
167 data
= X11DRV_get_win_data( hwnd
);
168 if (data
&& data
->wm_hints
)
171 data
->wm_hints
->input
= !(new_style
& WS_DISABLED
);
172 XSetWMHints( display
, data
->whole_window
, data
->wm_hints
);
179 /***********************************************************************
182 static void update_wm_states( Display
*display
, struct x11drv_win_data
*data
, BOOL force
)
184 static const unsigned int state_atoms
[NB_WM_STATES
] =
186 XATOM__NET_WM_STATE_FULLSCREEN
,
187 XATOM__NET_WM_STATE_ABOVE
,
188 XATOM__NET_WM_STATE_SKIP_PAGER
,
189 XATOM__NET_WM_STATE_SKIP_TASKBAR
192 DWORD i
, ex_style
, new_state
= 0;
195 if (!data
->managed
) return;
196 if (!data
->mapped
) return;
198 if (data
->whole_rect
.left
<= 0 && data
->whole_rect
.right
>= screen_width
&&
199 data
->whole_rect
.top
<= 0 && data
->whole_rect
.bottom
>= screen_height
)
200 new_state
|= (1 << WM_STATE_FULLSCREEN
);
202 ex_style
= GetWindowLongW( data
->hwnd
, GWL_EXSTYLE
);
203 if (ex_style
& WS_EX_TOPMOST
)
204 new_state
|= (1 << WM_STATE_ABOVE
);
205 if (ex_style
& WS_EX_TOOLWINDOW
)
206 new_state
|= (1 << WM_STATE_SKIP_TASKBAR
) | (1 << WM_STATE_SKIP_PAGER
);
208 xev
.xclient
.type
= ClientMessage
;
209 xev
.xclient
.window
= data
->whole_window
;
210 xev
.xclient
.message_type
= x11drv_atom(_NET_WM_STATE
);
211 xev
.xclient
.serial
= 0;
212 xev
.xclient
.display
= display
;
213 xev
.xclient
.send_event
= True
;
214 xev
.xclient
.format
= 32;
215 xev
.xclient
.data
.l
[2] = 0;
216 xev
.xclient
.data
.l
[3] = 1;
218 for (i
= 0; i
< NB_WM_STATES
; i
++)
220 if (!((data
->wm_state
^ new_state
) & (1 << i
))) /* unchanged */
222 /* if forced, we only add states, we don't remove them */
223 if (!force
|| !(new_state
& (1 << i
))) continue;
226 TRACE( "setting wm state %u for window %p/%lx to %u prev %u\n",
227 i
, data
->hwnd
, data
->whole_window
,
228 (new_state
& (1 << i
)) != 0, (data
->wm_state
& (1 << i
)) != 0 );
230 xev
.xclient
.data
.l
[0] = (new_state
& (1 << i
)) ? _NET_WM_STATE_ADD
: _NET_WM_STATE_REMOVE
;
231 xev
.xclient
.data
.l
[1] = X11DRV_Atoms
[state_atoms
[i
] - FIRST_XATOM
];
233 XSendEvent( display
, root_window
, False
, SubstructureRedirectMask
| SubstructureNotifyMask
, &xev
);
236 data
->wm_state
= new_state
;
240 /***********************************************************************
243 * Move the window bits when a window is moved.
245 static void move_window_bits( struct x11drv_win_data
*data
, const RECT
*old_rect
, const RECT
*new_rect
,
246 const RECT
*old_whole_rect
)
248 RECT src_rect
= *old_rect
;
249 RECT dst_rect
= *new_rect
;
250 HDC hdc_src
, hdc_dst
;
255 if (!data
->whole_window
)
257 OffsetRect( &dst_rect
, -data
->window_rect
.left
, -data
->window_rect
.top
);
258 parent
= GetAncestor( data
->hwnd
, GA_PARENT
);
259 hdc_src
= GetDCEx( parent
, 0, DCX_CACHE
);
260 hdc_dst
= GetDCEx( data
->hwnd
, 0, DCX_CACHE
| DCX_WINDOW
);
264 OffsetRect( &dst_rect
, -data
->whole_rect
.left
, -data
->whole_rect
.top
);
265 /* make src rect relative to the old position of the window */
266 OffsetRect( &src_rect
, -old_whole_rect
->left
, -old_whole_rect
->top
);
267 if (dst_rect
.left
== src_rect
.left
&& dst_rect
.top
== src_rect
.top
) return;
268 /* now make them relative to window rect for DCX_WINDOW */
269 OffsetRect( &dst_rect
, data
->whole_rect
.left
- data
->window_rect
.left
,
270 data
->whole_rect
.top
- data
->window_rect
.top
);
271 OffsetRect( &src_rect
, data
->whole_rect
.left
- data
->window_rect
.left
,
272 data
->whole_rect
.top
- data
->window_rect
.top
);
273 hdc_src
= hdc_dst
= GetDCEx( data
->hwnd
, 0, DCX_CACHE
| DCX_WINDOW
);
276 code
= X11DRV_START_EXPOSURES
;
277 ExtEscape( hdc_dst
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, 0, NULL
);
279 TRACE( "copying bits for win %p/%lx %s -> %s\n",
280 data
->hwnd
, data
->whole_window
, wine_dbgstr_rect(&src_rect
), wine_dbgstr_rect(&dst_rect
) );
281 BitBlt( hdc_dst
, dst_rect
.left
, dst_rect
.top
,
282 dst_rect
.right
- dst_rect
.left
, dst_rect
.bottom
- dst_rect
.top
,
283 hdc_src
, src_rect
.left
, src_rect
.top
, SRCCOPY
);
285 code
= X11DRV_END_EXPOSURES
;
286 ExtEscape( hdc_dst
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, sizeof(rgn
), (LPSTR
)&rgn
);
288 ReleaseDC( data
->hwnd
, hdc_dst
);
289 if (hdc_src
!= hdc_dst
) ReleaseDC( parent
, hdc_src
);
293 OffsetRgn( rgn
, data
->window_rect
.left
- data
->client_rect
.left
,
294 data
->window_rect
.top
- data
->client_rect
.top
);
295 RedrawWindow( data
->hwnd
, NULL
, rgn
, RDW_INVALIDATE
| RDW_FRAME
| RDW_ERASE
| RDW_ALLCHILDREN
);
300 /***********************************************************************
301 * SetWindowPos (X11DRV.@)
303 void X11DRV_SetWindowPos( HWND hwnd
, HWND insert_after
, UINT swp_flags
,
304 const RECT
*rectWindow
, const RECT
*rectClient
,
305 const RECT
*visible_rect
, const RECT
*valid_rects
)
307 Display
*display
= thread_display();
308 struct x11drv_win_data
*data
= X11DRV_get_win_data( hwnd
);
309 DWORD new_style
= GetWindowLongW( hwnd
, GWL_STYLE
);
310 RECT old_window_rect
, old_whole_rect
, old_client_rect
;
314 /* create the win data if the window is being made visible */
315 if (!(new_style
& WS_VISIBLE
)) return;
316 if (!(data
= X11DRV_create_win_data( hwnd
))) return;
319 /* check if we need to switch the window to managed */
320 if (!data
->managed
&& data
->whole_window
&& is_window_managed( hwnd
, swp_flags
, rectWindow
))
322 TRACE( "making win %p/%lx managed\n", hwnd
, data
->whole_window
);
323 data
->managed
= TRUE
;
324 SetPropA( hwnd
, managed_prop
, (HANDLE
)1 );
328 XUnmapWindow( display
, data
->whole_window
);
330 data
->mapped
= FALSE
;
334 old_window_rect
= data
->window_rect
;
335 old_whole_rect
= data
->whole_rect
;
336 old_client_rect
= data
->client_rect
;
337 data
->window_rect
= *rectWindow
;
338 data
->whole_rect
= *rectWindow
;
339 data
->client_rect
= *rectClient
;
340 X11DRV_window_to_X_rect( data
, &data
->whole_rect
);
341 if (memcmp( &visible_rect
, &data
->whole_rect
, sizeof(RECT
) ))
343 TRACE( "%p: need to update visible rect %s -> %s\n", hwnd
,
344 wine_dbgstr_rect(visible_rect
), wine_dbgstr_rect(&data
->whole_rect
) );
345 SERVER_START_REQ( set_window_visible_rect
)
348 req
->flags
= swp_flags
;
349 req
->visible
.left
= data
->whole_rect
.left
;
350 req
->visible
.top
= data
->whole_rect
.top
;
351 req
->visible
.right
= data
->whole_rect
.right
;
352 req
->visible
.bottom
= data
->whole_rect
.bottom
;
353 wine_server_call( req
);
358 /* invalidate DCEs */
359 if ((((swp_flags
& SWP_AGG_NOPOSCHANGE
) != SWP_AGG_NOPOSCHANGE
) && (new_style
& WS_VISIBLE
)) ||
360 (swp_flags
& (SWP_HIDEWINDOW
| SWP_SHOWWINDOW
)))
363 UnionRect( &rect
, rectWindow
, &old_window_rect
);
364 invalidate_dce( hwnd
, &rect
);
367 TRACE( "win %p window %s client %s style %08x\n",
368 hwnd
, wine_dbgstr_rect(rectWindow
), wine_dbgstr_rect(rectClient
), new_style
);
370 if (!IsRectEmpty( &valid_rects
[0] ))
372 int x_offset
= old_whole_rect
.left
- data
->whole_rect
.left
;
373 int y_offset
= old_whole_rect
.top
- data
->whole_rect
.top
;
375 /* if all that happened is that the whole window moved, copy everything */
376 if (!(swp_flags
& SWP_FRAMECHANGED
) &&
377 old_whole_rect
.right
- data
->whole_rect
.right
== x_offset
&&
378 old_whole_rect
.bottom
- data
->whole_rect
.bottom
== y_offset
&&
379 old_client_rect
.left
- data
->client_rect
.left
== x_offset
&&
380 old_client_rect
.right
- data
->client_rect
.right
== x_offset
&&
381 old_client_rect
.top
- data
->client_rect
.top
== y_offset
&&
382 old_client_rect
.bottom
- data
->client_rect
.bottom
== y_offset
&&
383 !memcmp( &valid_rects
[0], &data
->client_rect
, sizeof(RECT
) ))
385 /* if we have an X window the bits will be moved by the X server */
386 if (!data
->whole_window
)
387 move_window_bits( data
, &old_whole_rect
, &data
->whole_rect
, &old_whole_rect
);
390 move_window_bits( data
, &valid_rects
[1], &valid_rects
[0], &old_whole_rect
);
393 if (data
->gl_drawable
&&
394 data
->client_rect
.right
-data
->client_rect
.left
== old_client_rect
.right
-old_client_rect
.left
&&
395 data
->client_rect
.bottom
-data
->client_rect
.top
== old_client_rect
.bottom
-old_client_rect
.top
)
396 X11DRV_sync_gl_drawable( display
, data
);
398 if (!data
->whole_window
|| data
->lock_changes
) return; /* nothing more to do */
400 if (data
->mapped
&& (!(new_style
& WS_VISIBLE
) || !X11DRV_is_window_rect_mapped( rectWindow
)))
402 TRACE( "unmapping win %p\n", hwnd
);
404 XUnmapWindow( display
, data
->whole_window
);
406 data
->mapped
= FALSE
;
409 X11DRV_sync_window_position( display
, data
, swp_flags
, &old_client_rect
, &old_whole_rect
);
411 if ((new_style
& WS_VISIBLE
) && !(new_style
& WS_MINIMIZE
) &&
412 X11DRV_is_window_rect_mapped( rectWindow
))
414 BOOL was_mapped
= data
->mapped
;
416 if (!data
->mapped
|| (swp_flags
& SWP_FRAMECHANGED
))
417 X11DRV_set_wm_hints( display
, data
);
421 TRACE( "mapping win %p\n", hwnd
);
422 X11DRV_sync_window_style( display
, data
);
424 XMapWindow( display
, data
->whole_window
);
429 update_wm_states( display
, data
, !was_mapped
);
434 /***********************************************************************
437 * Find a suitable place for an iconic window.
439 static POINT
WINPOS_FindIconPos( HWND hwnd
, POINT pt
)
441 RECT rect
, rectParent
;
444 int xspacing
, yspacing
;
446 parent
= GetAncestor( hwnd
, GA_PARENT
);
447 GetClientRect( parent
, &rectParent
);
448 if ((pt
.x
>= rectParent
.left
) && (pt
.x
+ GetSystemMetrics(SM_CXICON
) < rectParent
.right
) &&
449 (pt
.y
>= rectParent
.top
) && (pt
.y
+ GetSystemMetrics(SM_CYICON
) < rectParent
.bottom
))
450 return pt
; /* The icon already has a suitable position */
452 xspacing
= GetSystemMetrics(SM_CXICONSPACING
);
453 yspacing
= GetSystemMetrics(SM_CYICONSPACING
);
455 /* Check if another icon already occupies this spot */
456 /* FIXME: this is completely inefficient */
458 hrgn
= CreateRectRgn( 0, 0, 0, 0 );
459 tmp
= CreateRectRgn( 0, 0, 0, 0 );
460 for (child
= GetWindow( parent
, GW_HWNDFIRST
); child
; child
= GetWindow( child
, GW_HWNDNEXT
))
463 if (child
== hwnd
) continue;
464 if ((GetWindowLongW( child
, GWL_STYLE
) & (WS_VISIBLE
|WS_MINIMIZE
)) != (WS_VISIBLE
|WS_MINIMIZE
))
466 if (!(childPtr
= WIN_GetPtr( child
)) || childPtr
== WND_OTHER_PROCESS
)
468 SetRectRgn( tmp
, childPtr
->rectWindow
.left
, childPtr
->rectWindow
.top
,
469 childPtr
->rectWindow
.right
, childPtr
->rectWindow
.bottom
);
470 CombineRgn( hrgn
, hrgn
, tmp
, RGN_OR
);
471 WIN_ReleasePtr( childPtr
);
475 for (rect
.bottom
= rectParent
.bottom
; rect
.bottom
>= yspacing
; rect
.bottom
-= yspacing
)
477 for (rect
.left
= rectParent
.left
; rect
.left
<= rectParent
.right
- xspacing
; rect
.left
+= xspacing
)
479 rect
.right
= rect
.left
+ xspacing
;
480 rect
.top
= rect
.bottom
- yspacing
;
481 if (!RectInRegion( hrgn
, &rect
))
483 /* No window was found, so it's OK for us */
484 pt
.x
= rect
.left
+ (xspacing
- GetSystemMetrics(SM_CXICON
)) / 2;
485 pt
.y
= rect
.top
+ (yspacing
- GetSystemMetrics(SM_CYICON
)) / 2;
486 DeleteObject( hrgn
);
491 DeleteObject( hrgn
);
497 /***********************************************************************
500 UINT
WINPOS_MinMaximize( HWND hwnd
, UINT cmd
, LPRECT rect
)
508 TRACE("%p %u\n", hwnd
, cmd
);
510 wpl
.length
= sizeof(wpl
);
511 GetWindowPlacement( hwnd
, &wpl
);
513 if (HOOK_CallHooks( WH_CBT
, HCBT_MINMAX
, (WPARAM
)hwnd
, cmd
, TRUE
))
514 return SWP_NOSIZE
| SWP_NOMOVE
;
516 if (IsIconic( hwnd
))
520 case SW_SHOWMINNOACTIVE
:
521 case SW_SHOWMINIMIZED
:
522 case SW_FORCEMINIMIZE
:
524 return SWP_NOSIZE
| SWP_NOMOVE
;
526 if (!SendMessageW( hwnd
, WM_QUERYOPEN
, 0, 0 )) return SWP_NOSIZE
| SWP_NOMOVE
;
527 swpFlags
|= SWP_NOCOPYBITS
;
532 case SW_SHOWMINNOACTIVE
:
533 case SW_SHOWMINIMIZED
:
534 case SW_FORCEMINIMIZE
:
536 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
537 if( wndPtr
->dwStyle
& WS_MAXIMIZE
) wndPtr
->flags
|= WIN_RESTORE_MAX
;
538 else wndPtr
->flags
&= ~WIN_RESTORE_MAX
;
539 WIN_ReleasePtr( wndPtr
);
541 old_style
= WIN_SetStyle( hwnd
, WS_MINIMIZE
, WS_MAXIMIZE
);
543 X11DRV_set_iconic_state( hwnd
);
545 wpl
.ptMinPosition
= WINPOS_FindIconPos( hwnd
, wpl
.ptMinPosition
);
547 if (!(old_style
& WS_MINIMIZE
)) swpFlags
|= SWP_STATECHANGED
;
548 SetRect( rect
, wpl
.ptMinPosition
.x
, wpl
.ptMinPosition
.y
,
549 GetSystemMetrics(SM_CXICON
), GetSystemMetrics(SM_CYICON
) );
550 swpFlags
|= SWP_NOCOPYBITS
;
554 old_style
= GetWindowLongW( hwnd
, GWL_STYLE
);
555 if ((old_style
& WS_MAXIMIZE
) && (old_style
& WS_VISIBLE
)) return SWP_NOSIZE
| SWP_NOMOVE
;
557 WINPOS_GetMinMaxInfo( hwnd
, &size
, &wpl
.ptMaxPosition
, NULL
, NULL
);
559 old_style
= WIN_SetStyle( hwnd
, WS_MAXIMIZE
, WS_MINIMIZE
);
560 if (old_style
& WS_MINIMIZE
)
562 WINPOS_ShowIconTitle( hwnd
, FALSE
);
563 X11DRV_set_iconic_state( hwnd
);
565 if (!(old_style
& WS_MAXIMIZE
)) swpFlags
|= SWP_STATECHANGED
;
566 SetRect( rect
, wpl
.ptMaxPosition
.x
, wpl
.ptMaxPosition
.y
, size
.x
, size
.y
);
569 case SW_SHOWNOACTIVATE
:
572 old_style
= WIN_SetStyle( hwnd
, 0, WS_MINIMIZE
| WS_MAXIMIZE
);
573 if (old_style
& WS_MINIMIZE
)
577 WINPOS_ShowIconTitle( hwnd
, FALSE
);
578 X11DRV_set_iconic_state( hwnd
);
580 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
581 restore_max
= (wndPtr
->flags
& WIN_RESTORE_MAX
) != 0;
582 WIN_ReleasePtr( wndPtr
);
585 /* Restore to maximized position */
586 WINPOS_GetMinMaxInfo( hwnd
, &size
, &wpl
.ptMaxPosition
, NULL
, NULL
);
587 WIN_SetStyle( hwnd
, WS_MAXIMIZE
, 0 );
588 swpFlags
|= SWP_STATECHANGED
;
589 SetRect( rect
, wpl
.ptMaxPosition
.x
, wpl
.ptMaxPosition
.y
, size
.x
, size
.y
);
593 else if (!(old_style
& WS_MAXIMIZE
)) break;
595 swpFlags
|= SWP_STATECHANGED
;
597 /* Restore to normal position */
599 *rect
= wpl
.rcNormalPosition
;
600 rect
->right
-= rect
->left
;
601 rect
->bottom
-= rect
->top
;
610 /***********************************************************************
611 * ShowWindow (X11DRV.@)
613 BOOL
X11DRV_ShowWindow( HWND hwnd
, INT cmd
)
617 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
618 BOOL wasVisible
= (style
& WS_VISIBLE
) != 0;
619 BOOL showFlag
= TRUE
;
620 RECT newPos
= {0, 0, 0, 0};
623 TRACE("hwnd=%p, cmd=%d, wasVisible %d\n", hwnd
, cmd
, wasVisible
);
628 if (!wasVisible
) return FALSE
;
630 swp
|= SWP_HIDEWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
631 if (hwnd
!= GetActiveWindow())
632 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
635 case SW_SHOWMINNOACTIVE
:
636 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
639 case SW_FORCEMINIMIZE
: /* FIXME: Does not work if thread is hung. */
640 if (style
& WS_CHILD
) swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
642 case SW_SHOWMINIMIZED
:
643 swp
|= SWP_SHOWWINDOW
| SWP_FRAMECHANGED
;
644 swp
|= WINPOS_MinMaximize( hwnd
, cmd
, &newPos
);
645 if ((style
& WS_MINIMIZE
) && wasVisible
) return TRUE
;
648 case SW_SHOWMAXIMIZED
: /* same as SW_MAXIMIZE */
649 if (!wasVisible
) swp
|= SWP_SHOWWINDOW
;
650 swp
|= SWP_FRAMECHANGED
;
651 swp
|= WINPOS_MinMaximize( hwnd
, SW_MAXIMIZE
, &newPos
);
652 if ((style
& WS_MAXIMIZE
) && wasVisible
) return TRUE
;
656 swp
|= SWP_NOACTIVATE
| SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
657 if (style
& WS_CHILD
) swp
|= SWP_NOZORDER
;
660 if (wasVisible
) return TRUE
;
661 swp
|= SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
662 if (style
& WS_CHILD
) swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
665 case SW_SHOWNOACTIVATE
:
666 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
670 case SW_SHOWNORMAL
: /* same as SW_NORMAL: */
671 case SW_SHOWDEFAULT
: /* FIXME: should have its own handler */
672 if (!wasVisible
) swp
|= SWP_SHOWWINDOW
;
673 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
675 swp
|= SWP_FRAMECHANGED
;
676 swp
|= WINPOS_MinMaximize( hwnd
, cmd
, &newPos
);
680 if (wasVisible
) return TRUE
;
681 swp
|= SWP_NOSIZE
| SWP_NOMOVE
;
683 if (style
& WS_CHILD
&& !(swp
& SWP_STATECHANGED
)) swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
687 if ((showFlag
!= wasVisible
|| cmd
== SW_SHOWNA
) && cmd
!= SW_SHOWMAXIMIZED
&& !(swp
& SWP_STATECHANGED
))
689 SendMessageW( hwnd
, WM_SHOWWINDOW
, showFlag
, 0 );
690 if (!IsWindow( hwnd
)) return wasVisible
;
693 parent
= GetAncestor( hwnd
, GA_PARENT
);
694 if (parent
&& !IsWindowVisible( parent
) && !(swp
& SWP_STATECHANGED
))
696 /* if parent is not visible simply toggle WS_VISIBLE and return */
697 if (showFlag
) WIN_SetStyle( hwnd
, WS_VISIBLE
, 0 );
698 else WIN_SetStyle( hwnd
, 0, WS_VISIBLE
);
701 SetWindowPos( hwnd
, HWND_TOP
, newPos
.left
, newPos
.top
,
702 newPos
.right
, newPos
.bottom
, LOWORD(swp
) );
708 /* FIXME: This will cause the window to be activated irrespective
709 * of whether it is owned by the same thread. Has to be done
713 if (hwnd
== GetActiveWindow())
714 WINPOS_ActivateOtherWindow(hwnd
);
716 /* Revert focus to parent */
718 if (hwnd
== hFocus
|| IsChild(hwnd
, hFocus
))
720 HWND parent
= GetAncestor(hwnd
, GA_PARENT
);
721 if (parent
== GetDesktopWindow()) parent
= 0;
726 if (IsIconic(hwnd
)) WINPOS_ShowIconTitle( hwnd
, TRUE
);
728 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return wasVisible
;
730 if (wndPtr
->flags
& WIN_NEED_SIZE
)
732 /* should happen only in CreateWindowEx() */
733 int wParam
= SIZE_RESTORED
;
734 RECT client
= wndPtr
->rectClient
;
736 wndPtr
->flags
&= ~WIN_NEED_SIZE
;
737 if (wndPtr
->dwStyle
& WS_MAXIMIZE
) wParam
= SIZE_MAXIMIZED
;
738 else if (wndPtr
->dwStyle
& WS_MINIMIZE
) wParam
= SIZE_MINIMIZED
;
739 WIN_ReleasePtr( wndPtr
);
741 SendMessageW( hwnd
, WM_SIZE
, wParam
,
742 MAKELONG( client
.right
- client
.left
, client
.bottom
- client
.top
));
743 SendMessageW( hwnd
, WM_MOVE
, 0, MAKELONG( client
.left
, client
.top
));
745 else WIN_ReleasePtr( wndPtr
);
747 /* if previous state was minimized Windows sets focus to the window */
748 if (style
& WS_MINIMIZE
) SetFocus( hwnd
);
754 /**********************************************************************
757 void X11DRV_MapNotify( HWND hwnd
, XEvent
*event
)
759 struct x11drv_win_data
*data
;
760 HWND hwndFocus
= GetFocus();
763 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
765 if (!(win
= WIN_GetPtr( hwnd
))) return;
767 if (data
->managed
&& (win
->dwStyle
& WS_VISIBLE
) && (win
->dwStyle
& WS_MINIMIZE
))
770 unsigned int width
, height
, border
, depth
;
773 LONG style
= WS_VISIBLE
;
777 XGetGeometry( event
->xmap
.display
, data
->whole_window
, &root
, &x
, &y
, &width
, &height
,
779 XTranslateCoordinates( event
->xmap
.display
, data
->whole_window
, root
, 0, 0, &x
, &y
, &top
);
783 rect
.right
= x
+ width
;
784 rect
.bottom
= y
+ height
;
785 OffsetRect( &rect
, virtual_screen_rect
.left
, virtual_screen_rect
.top
);
786 X11DRV_X_to_window_rect( data
, &rect
);
788 invalidate_dce( hwnd
, &data
->window_rect
);
790 if (win
->flags
& WIN_RESTORE_MAX
) style
|= WS_MAXIMIZE
;
791 WIN_SetStyle( hwnd
, style
, WS_MINIMIZE
);
792 WIN_ReleasePtr( win
);
794 SendMessageW( hwnd
, WM_SHOWWINDOW
, SW_RESTORE
, 0 );
795 data
->lock_changes
++;
796 SetWindowPos( hwnd
, 0, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
,
797 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_FRAMECHANGED
| SWP_STATECHANGED
);
798 data
->lock_changes
--;
800 else WIN_ReleasePtr( win
);
801 if (hwndFocus
&& IsChild( hwnd
, hwndFocus
)) X11DRV_SetFocus(hwndFocus
); /* FIXME */
805 /**********************************************************************
808 void X11DRV_UnmapNotify( HWND hwnd
, XEvent
*event
)
810 struct x11drv_win_data
*data
;
813 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
815 if (!(win
= WIN_GetPtr( hwnd
))) return;
817 if ((win
->dwStyle
& WS_VISIBLE
) && data
->managed
&&
818 X11DRV_is_window_rect_mapped( &win
->rectWindow
))
820 if (win
->dwStyle
& WS_MAXIMIZE
)
821 win
->flags
|= WIN_RESTORE_MAX
;
822 else if (!(win
->dwStyle
& WS_MINIMIZE
))
823 win
->flags
&= ~WIN_RESTORE_MAX
;
825 WIN_SetStyle( hwnd
, WS_MINIMIZE
, WS_MAXIMIZE
);
826 WIN_ReleasePtr( win
);
829 SendMessageW( hwnd
, WM_SHOWWINDOW
, SW_MINIMIZE
, 0 );
830 data
->lock_changes
++;
831 SetWindowPos( hwnd
, 0, 0, 0, GetSystemMetrics(SM_CXICON
), GetSystemMetrics(SM_CYICON
),
832 SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_STATECHANGED
);
833 data
->lock_changes
--;
835 else WIN_ReleasePtr( win
);
838 struct desktop_resize_data
840 RECT old_screen_rect
;
841 RECT old_virtual_rect
;
844 static BOOL CALLBACK
update_windows_on_desktop_resize( HWND hwnd
, LPARAM lparam
)
846 struct x11drv_win_data
*data
;
847 Display
*display
= thread_display();
848 struct desktop_resize_data
*resize_data
= (struct desktop_resize_data
*)lparam
;
851 if (!(data
= X11DRV_get_win_data( hwnd
))) return TRUE
;
853 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
)
855 /* update the full screen state */
856 update_wm_states( display
, data
, FALSE
);
859 if (resize_data
->old_virtual_rect
.left
!= virtual_screen_rect
.left
) mask
|= CWX
;
860 if (resize_data
->old_virtual_rect
.top
!= virtual_screen_rect
.top
) mask
|= CWY
;
861 if (mask
&& data
->whole_window
)
863 XWindowChanges changes
;
866 changes
.x
= data
->whole_rect
.left
- virtual_screen_rect
.left
;
867 changes
.y
= data
->whole_rect
.top
- virtual_screen_rect
.top
;
868 XReconfigureWMWindow( display
, data
->whole_window
,
869 DefaultScreen(display
), mask
, &changes
);
876 /***********************************************************************
877 * X11DRV_resize_desktop
879 void X11DRV_resize_desktop( unsigned int width
, unsigned int height
)
881 HWND hwnd
= GetDesktopWindow();
882 struct desktop_resize_data resize_data
;
884 SetRect( &resize_data
.old_screen_rect
, 0, 0, screen_width
, screen_height
);
885 resize_data
.old_virtual_rect
= virtual_screen_rect
;
887 xinerama_init( width
, height
);
889 if (GetWindowThreadProcessId( hwnd
, NULL
) != GetCurrentThreadId())
891 SendMessageW( hwnd
, WM_X11DRV_RESIZE_DESKTOP
, 0, MAKELPARAM( width
, height
) );
895 TRACE( "desktop %p change to (%dx%d)\n", hwnd
, width
, height
);
896 SetWindowPos( hwnd
, 0, virtual_screen_rect
.left
, virtual_screen_rect
.top
,
897 virtual_screen_rect
.right
- virtual_screen_rect
.left
,
898 virtual_screen_rect
.bottom
- virtual_screen_rect
.top
,
899 SWP_NOZORDER
| SWP_NOACTIVATE
);
900 SendMessageTimeoutW( HWND_BROADCAST
, WM_DISPLAYCHANGE
, screen_bpp
,
901 MAKELPARAM( width
, height
), SMTO_ABORTIFHUNG
, 2000, NULL
);
904 EnumWindows( update_windows_on_desktop_resize
, (LPARAM
)&resize_data
);
908 /***********************************************************************
909 * X11DRV_ConfigureNotify
911 void X11DRV_ConfigureNotify( HWND hwnd
, XEvent
*xev
)
913 XConfigureEvent
*event
= &xev
->xconfigure
;
914 struct x11drv_win_data
*data
;
917 int cx
, cy
, x
= event
->x
, y
= event
->y
;
920 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
924 if (!event
->send_event
) /* normal event, need to map coordinates to the root */
928 XTranslateCoordinates( event
->display
, data
->whole_window
, root_window
,
929 0, 0, &x
, &y
, &child
);
934 rect
.right
= x
+ event
->width
;
935 rect
.bottom
= y
+ event
->height
;
936 OffsetRect( &rect
, virtual_screen_rect
.left
, virtual_screen_rect
.top
);
937 TRACE( "win %p new X rect %d,%d,%dx%d (event %d,%d,%dx%d)\n",
938 hwnd
, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
,
939 event
->x
, event
->y
, event
->width
, event
->height
);
940 X11DRV_X_to_window_rect( data
, &rect
);
944 cx
= rect
.right
- rect
.left
;
945 cy
= rect
.bottom
- rect
.top
;
946 flags
= SWP_NOACTIVATE
| SWP_NOZORDER
;
948 /* Compare what has changed */
950 GetWindowRect( hwnd
, &rect
);
951 if (rect
.left
== x
&& rect
.top
== y
) flags
|= SWP_NOMOVE
;
953 TRACE( "%p moving from (%d,%d) to (%d,%d)\n",
954 hwnd
, rect
.left
, rect
.top
, x
, y
);
956 if ((rect
.right
- rect
.left
== cx
&& rect
.bottom
- rect
.top
== cy
) ||
958 (IsRectEmpty( &rect
) && event
->width
== 1 && event
->height
== 1))
960 if (flags
& SWP_NOMOVE
) return; /* if nothing changed, don't do anything */
964 TRACE( "%p resizing from (%dx%d) to (%dx%d)\n",
965 hwnd
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, cx
, cy
);
967 data
->lock_changes
++;
968 SetWindowPos( hwnd
, 0, x
, y
, cx
, cy
, flags
);
969 data
->lock_changes
--;
973 /***********************************************************************
976 * Draw the frame used when moving or resizing window.
978 * FIXME: This causes problems in Win95 mode. (why?)
980 static void draw_moving_frame( HDC hdc
, RECT
*rect
, BOOL thickframe
)
984 const int width
= GetSystemMetrics(SM_CXFRAME
);
985 const int height
= GetSystemMetrics(SM_CYFRAME
);
987 HBRUSH hbrush
= SelectObject( hdc
, GetStockObject( GRAY_BRUSH
) );
988 PatBlt( hdc
, rect
->left
, rect
->top
,
989 rect
->right
- rect
->left
- width
, height
, PATINVERT
);
990 PatBlt( hdc
, rect
->left
, rect
->top
+ height
, width
,
991 rect
->bottom
- rect
->top
- height
, PATINVERT
);
992 PatBlt( hdc
, rect
->left
+ width
, rect
->bottom
- 1,
993 rect
->right
- rect
->left
- width
, -height
, PATINVERT
);
994 PatBlt( hdc
, rect
->right
- 1, rect
->top
, -width
,
995 rect
->bottom
- rect
->top
- height
, PATINVERT
);
996 SelectObject( hdc
, hbrush
);
998 else DrawFocusRect( hdc
, rect
);
1002 /***********************************************************************
1005 * Initialization of a move or resize, when initiated from a menu choice.
1006 * Return hit test code for caption or sizing border.
1008 static LONG
start_size_move( HWND hwnd
, WPARAM wParam
, POINT
*capturePoint
, LONG style
)
1015 GetWindowRect( hwnd
, &rectWindow
);
1017 if ((wParam
& 0xfff0) == SC_MOVE
)
1019 /* Move pointer at the center of the caption */
1020 RECT rect
= rectWindow
;
1021 /* Note: to be exactly centered we should take the different types
1022 * of border into account, but it shouldn't make more than a few pixels
1023 * of difference so let's not bother with that */
1024 rect
.top
+= GetSystemMetrics(SM_CYBORDER
);
1025 if (style
& WS_SYSMENU
)
1026 rect
.left
+= GetSystemMetrics(SM_CXSIZE
) + 1;
1027 if (style
& WS_MINIMIZEBOX
)
1028 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
1029 if (style
& WS_MAXIMIZEBOX
)
1030 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
1031 pt
.x
= (rect
.right
+ rect
.left
) / 2;
1032 pt
.y
= rect
.top
+ GetSystemMetrics(SM_CYSIZE
)/2;
1033 hittest
= HTCAPTION
;
1041 GetMessageW( &msg
, 0, WM_KEYFIRST
, WM_MOUSELAST
);
1042 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
1048 hittest
= SendMessageW( hwnd
, WM_NCHITTEST
, 0, MAKELONG( pt
.x
, pt
.y
) );
1049 if ((hittest
< HTLEFT
) || (hittest
> HTBOTTOMRIGHT
)) hittest
= 0;
1060 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
1061 pt
.y
= rectWindow
.top
+ GetSystemMetrics(SM_CYFRAME
) / 2;
1065 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
1066 pt
.y
= rectWindow
.bottom
- GetSystemMetrics(SM_CYFRAME
) / 2;
1070 pt
.x
= rectWindow
.left
+ GetSystemMetrics(SM_CXFRAME
) / 2;
1071 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
1075 pt
.x
= rectWindow
.right
- GetSystemMetrics(SM_CXFRAME
) / 2;
1076 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
1079 case VK_ESCAPE
: return 0;
1085 SetCursorPos( pt
.x
, pt
.y
);
1086 SendMessageW( hwnd
, WM_SETCURSOR
, (WPARAM
)hwnd
, MAKELONG( hittest
, WM_MOUSEMOVE
));
1091 /***********************************************************************
1092 * set_movesize_capture
1094 static void set_movesize_capture( HWND hwnd
)
1098 SERVER_START_REQ( set_capture_window
)
1101 req
->flags
= CAPTURE_MOVESIZE
;
1102 if (!wine_server_call_err( req
))
1104 previous
= reply
->previous
;
1105 hwnd
= reply
->full_handle
;
1109 if (previous
&& previous
!= hwnd
)
1110 SendMessageW( previous
, WM_CAPTURECHANGED
, 0, (LPARAM
)hwnd
);
1113 /***********************************************************************
1114 * X11DRV_WMMoveResizeWindow
1116 * Tells the window manager to initiate a move or resize operation.
1119 * http://freedesktop.org/Standards/wm-spec/1.3/ar01s04.html
1120 * or search for "_NET_WM_MOVERESIZE"
1122 static BOOL
X11DRV_WMMoveResizeWindow( HWND hwnd
, int x
, int y
, WPARAM wparam
)
1124 WPARAM syscommand
= wparam
& 0xfff0;
1125 WPARAM hittest
= wparam
& 0x0f;
1128 Display
*display
= thread_display();
1130 if (syscommand
== SC_MOVE
)
1132 if (!hittest
) dir
= _NET_WM_MOVERESIZE_MOVE_KEYBOARD
;
1133 else dir
= _NET_WM_MOVERESIZE_MOVE
;
1137 /* windows without WS_THICKFRAME are not resizable through the window manager */
1138 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_THICKFRAME
)) return FALSE
;
1142 case WMSZ_LEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_LEFT
; break;
1143 case WMSZ_RIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_RIGHT
; break;
1144 case WMSZ_TOP
: dir
= _NET_WM_MOVERESIZE_SIZE_TOP
; break;
1145 case WMSZ_TOPLEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_TOPLEFT
; break;
1146 case WMSZ_TOPRIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_TOPRIGHT
; break;
1147 case WMSZ_BOTTOM
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOM
; break;
1148 case WMSZ_BOTTOMLEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT
; break;
1149 case WMSZ_BOTTOMRIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT
; break;
1150 default: dir
= _NET_WM_MOVERESIZE_SIZE_KEYBOARD
; break;
1154 TRACE("hwnd %p, x %d, y %d, dir %d\n", hwnd
, x
, y
, dir
);
1156 xev
.xclient
.type
= ClientMessage
;
1157 xev
.xclient
.window
= X11DRV_get_whole_window(hwnd
);
1158 xev
.xclient
.message_type
= x11drv_atom(_NET_WM_MOVERESIZE
);
1159 xev
.xclient
.serial
= 0;
1160 xev
.xclient
.display
= display
;
1161 xev
.xclient
.send_event
= True
;
1162 xev
.xclient
.format
= 32;
1163 xev
.xclient
.data
.l
[0] = x
; /* x coord */
1164 xev
.xclient
.data
.l
[1] = y
; /* y coord */
1165 xev
.xclient
.data
.l
[2] = dir
; /* direction */
1166 xev
.xclient
.data
.l
[3] = 1; /* button */
1167 xev
.xclient
.data
.l
[4] = 0; /* unused */
1169 /* need to ungrab the pointer that may have been automatically grabbed
1170 * with a ButtonPress event */
1172 XUngrabPointer( display
, CurrentTime
);
1173 XSendEvent(display
, root_window
, False
, SubstructureNotifyMask
, &xev
);
1174 wine_tsx11_unlock();
1178 /***********************************************************************
1179 * SysCommandSizeMove (X11DRV.@)
1181 * Perform SC_MOVE and SC_SIZE commands.
1183 void X11DRV_SysCommandSizeMove( HWND hwnd
, WPARAM wParam
)
1186 RECT sizingRect
, mouseRect
, origRect
;
1189 LONG hittest
= (LONG
)(wParam
& 0x0f);
1190 WPARAM syscommand
= wParam
& 0xfff0;
1191 HCURSOR hDragCursor
= 0, hOldCursor
= 0;
1192 POINT minTrack
, maxTrack
;
1193 POINT capturePoint
, pt
;
1194 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
1195 BOOL thickframe
= HAS_THICKFRAME( style
);
1196 BOOL iconic
= style
& WS_MINIMIZE
;
1198 DWORD dwPoint
= GetMessagePos ();
1199 BOOL DragFullWindows
= TRUE
;
1200 Window parent_win
, whole_win
;
1201 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1202 struct x11drv_win_data
*data
;
1204 pt
.x
= (short)LOWORD(dwPoint
);
1205 pt
.y
= (short)HIWORD(dwPoint
);
1208 if (IsZoomed(hwnd
) || !IsWindowVisible(hwnd
)) return;
1210 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1212 TRACE("hwnd %p (%smanaged), command %04lx, hittest %d, pos %d,%d\n",
1213 hwnd
, data
->managed
? "" : "NOT ", syscommand
, hittest
, pt
.x
, pt
.y
);
1215 /* if we are managed then we let the WM do all the work */
1216 if (data
->managed
&& X11DRV_WMMoveResizeWindow( hwnd
, pt
.x
, pt
.y
, wParam
)) return;
1218 if (syscommand
== SC_MOVE
)
1220 if (!hittest
) hittest
= start_size_move( hwnd
, wParam
, &capturePoint
, style
);
1221 if (!hittest
) return;
1225 if ( hittest
&& (syscommand
!= SC_MOUSEMENU
) )
1226 hittest
+= (HTLEFT
- WMSZ_LEFT
);
1229 set_movesize_capture( hwnd
);
1230 hittest
= start_size_move( hwnd
, wParam
, &capturePoint
, style
);
1233 set_movesize_capture(0);
1239 /* Get min/max info */
1241 WINPOS_GetMinMaxInfo( hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
1242 GetWindowRect( hwnd
, &sizingRect
);
1243 if (style
& WS_CHILD
)
1245 parent
= GetParent(hwnd
);
1246 /* make sizing rect relative to parent */
1247 MapWindowPoints( 0, parent
, (POINT
*)&sizingRect
, 2 );
1248 GetClientRect( parent
, &mouseRect
);
1253 mouseRect
= virtual_screen_rect
;
1255 origRect
= sizingRect
;
1257 if (ON_LEFT_BORDER(hittest
))
1259 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.right
-maxTrack
.x
);
1260 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.right
-minTrack
.x
);
1262 else if (ON_RIGHT_BORDER(hittest
))
1264 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.left
+minTrack
.x
);
1265 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.left
+maxTrack
.x
);
1267 if (ON_TOP_BORDER(hittest
))
1269 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.bottom
-maxTrack
.y
);
1270 mouseRect
.bottom
= min( mouseRect
.bottom
,sizingRect
.bottom
-minTrack
.y
);
1272 else if (ON_BOTTOM_BORDER(hittest
))
1274 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.top
+minTrack
.y
);
1275 mouseRect
.bottom
= min( mouseRect
.bottom
, sizingRect
.top
+maxTrack
.y
);
1277 if (parent
) MapWindowPoints( parent
, 0, (LPPOINT
)&mouseRect
, 2 );
1279 /* Retrieve a default cache DC (without using the window style) */
1280 hdc
= GetDCEx( parent
, 0, DCX_CACHE
);
1282 if( iconic
) /* create a cursor for dragging */
1284 hDragCursor
= (HCURSOR
)GetClassLongPtrW( hwnd
, GCLP_HICON
);
1285 if( !hDragCursor
) hDragCursor
= (HCURSOR
)SendMessageW( hwnd
, WM_QUERYDRAGICON
, 0, 0L);
1286 if( !hDragCursor
) iconic
= FALSE
;
1289 /* repaint the window before moving it around */
1290 RedrawWindow( hwnd
, NULL
, 0, RDW_UPDATENOW
| RDW_ALLCHILDREN
);
1292 SendMessageW( hwnd
, WM_ENTERSIZEMOVE
, 0, 0 );
1293 set_movesize_capture( hwnd
);
1295 /* we only allow disabling the full window drag for child windows, or in desktop mode */
1296 /* otherwise we'd need to grab the server and we want to avoid that */
1297 if (parent
|| (root_window
!= DefaultRootWindow(gdi_display
)))
1298 SystemParametersInfoA(SPI_GETDRAGFULLWINDOWS
, 0, &DragFullWindows
, 0);
1300 whole_win
= X11DRV_get_whole_window( GetAncestor(hwnd
,GA_ROOT
) );
1301 parent_win
= parent
? X11DRV_get_whole_window( GetAncestor(parent
,GA_ROOT
) ) : root_window
;
1304 XGrabPointer( thread_data
->display
, whole_win
, False
,
1305 PointerMotionMask
| ButtonPressMask
| ButtonReleaseMask
,
1306 GrabModeAsync
, GrabModeAsync
, parent_win
, None
, CurrentTime
);
1307 wine_tsx11_unlock();
1308 thread_data
->grab_window
= whole_win
;
1314 if (!GetMessageW( &msg
, 0, 0, 0 )) break;
1315 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
1317 /* Exit on button-up, Return, or Esc */
1318 if ((msg
.message
== WM_LBUTTONUP
) ||
1319 ((msg
.message
== WM_KEYDOWN
) &&
1320 ((msg
.wParam
== VK_RETURN
) || (msg
.wParam
== VK_ESCAPE
)))) break;
1322 if ((msg
.message
!= WM_KEYDOWN
) && (msg
.message
!= WM_MOUSEMOVE
))
1324 TranslateMessage( &msg
);
1325 DispatchMessageW( &msg
);
1326 continue; /* We are not interested in other messages */
1331 if (msg
.message
== WM_KEYDOWN
) switch(msg
.wParam
)
1333 case VK_UP
: pt
.y
-= 8; break;
1334 case VK_DOWN
: pt
.y
+= 8; break;
1335 case VK_LEFT
: pt
.x
-= 8; break;
1336 case VK_RIGHT
: pt
.x
+= 8; break;
1339 pt
.x
= max( pt
.x
, mouseRect
.left
);
1340 pt
.x
= min( pt
.x
, mouseRect
.right
);
1341 pt
.y
= max( pt
.y
, mouseRect
.top
);
1342 pt
.y
= min( pt
.y
, mouseRect
.bottom
);
1344 dx
= pt
.x
- capturePoint
.x
;
1345 dy
= pt
.y
- capturePoint
.y
;
1353 if( iconic
) /* ok, no system popup tracking */
1355 hOldCursor
= SetCursor(hDragCursor
);
1357 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1359 else if(!DragFullWindows
)
1360 draw_moving_frame( hdc
, &sizingRect
, thickframe
);
1363 if (msg
.message
== WM_KEYDOWN
) SetCursorPos( pt
.x
, pt
.y
);
1366 RECT newRect
= sizingRect
;
1367 WPARAM wpSizingHit
= 0;
1369 if (hittest
== HTCAPTION
) OffsetRect( &newRect
, dx
, dy
);
1370 if (ON_LEFT_BORDER(hittest
)) newRect
.left
+= dx
;
1371 else if (ON_RIGHT_BORDER(hittest
)) newRect
.right
+= dx
;
1372 if (ON_TOP_BORDER(hittest
)) newRect
.top
+= dy
;
1373 else if (ON_BOTTOM_BORDER(hittest
)) newRect
.bottom
+= dy
;
1374 if(!iconic
&& !DragFullWindows
) draw_moving_frame( hdc
, &sizingRect
, thickframe
);
1377 /* determine the hit location */
1378 if (hittest
>= HTLEFT
&& hittest
<= HTBOTTOMRIGHT
)
1379 wpSizingHit
= WMSZ_LEFT
+ (hittest
- HTLEFT
);
1380 SendMessageW( hwnd
, WM_SIZING
, wpSizingHit
, (LPARAM
)&newRect
);
1384 if(!DragFullWindows
)
1385 draw_moving_frame( hdc
, &newRect
, thickframe
);
1387 SetWindowPos( hwnd
, 0, newRect
.left
, newRect
.top
,
1388 newRect
.right
- newRect
.left
,
1389 newRect
.bottom
- newRect
.top
,
1390 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
1392 sizingRect
= newRect
;
1397 set_movesize_capture(0);
1400 if( moved
) /* restore cursors, show icon title later on */
1402 ShowCursor( FALSE
);
1403 SetCursor( hOldCursor
);
1406 else if (moved
&& !DragFullWindows
)
1408 draw_moving_frame( hdc
, &sizingRect
, thickframe
);
1409 /* make sure the moving frame is erased before we move the window */
1411 XFlush( gdi_display
);
1412 wine_tsx11_unlock();
1415 ReleaseDC( parent
, hdc
);
1418 XUngrabPointer( thread_data
->display
, CurrentTime
);
1419 wine_tsx11_unlock();
1420 thread_data
->grab_window
= None
;
1422 if (HOOK_CallHooks( WH_CBT
, HCBT_MOVESIZE
, (WPARAM
)hwnd
, (LPARAM
)&sizingRect
, TRUE
))
1425 SendMessageW( hwnd
, WM_EXITSIZEMOVE
, 0, 0 );
1426 SendMessageW( hwnd
, WM_SETVISIBLE
, !IsIconic(hwnd
), 0L);
1428 /* window moved or resized */
1431 /* if the moving/resizing isn't canceled call SetWindowPos
1432 * with the new position or the new size of the window
1434 if (!((msg
.message
== WM_KEYDOWN
) && (msg
.wParam
== VK_ESCAPE
)) )
1436 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
1437 if(!DragFullWindows
)
1438 SetWindowPos( hwnd
, 0, sizingRect
.left
, sizingRect
.top
,
1439 sizingRect
.right
- sizingRect
.left
,
1440 sizingRect
.bottom
- sizingRect
.top
,
1441 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
1444 { /* restore previous size/position */
1446 SetWindowPos( hwnd
, 0, origRect
.left
, origRect
.top
,
1447 origRect
.right
- origRect
.left
,
1448 origRect
.bottom
- origRect
.top
,
1449 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
1455 /* Single click brings up the system menu when iconized */
1459 if(style
& WS_SYSMENU
)
1460 SendMessageW( hwnd
, WM_SYSCOMMAND
,
1461 SC_MOUSEMENU
+ HTSYSMENU
, MAKELONG(pt
.x
,pt
.y
));
1463 else WINPOS_ShowIconTitle( hwnd
, TRUE
);