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;
99 rect
.left
= data
->whole_rect
.left
+ event
->x
;
100 rect
.top
= data
->whole_rect
.top
+ event
->y
;
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
;
116 req
->rect
.top
= rect
.top
;
117 req
->rect
.right
= rect
.right
;
118 req
->rect
.bottom
= rect
.bottom
;
119 wine_server_call( req
);
123 /* make position relative to client area instead of parent */
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
->whole_rect
.left
<= 0 && data
->whole_rect
.right
>= screen_width
&&
195 data
->whole_rect
.top
<= 0 && data
->whole_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 /***********************************************************************
239 * Move the window bits when a window is moved.
241 static void move_window_bits( struct x11drv_win_data
*data
, const RECT
*old_rect
, const RECT
*new_rect
,
242 const RECT
*old_whole_rect
)
244 RECT src_rect
= *old_rect
;
245 RECT dst_rect
= *new_rect
;
246 HDC hdc_src
, hdc_dst
;
251 if (!data
->whole_window
)
253 OffsetRect( &dst_rect
, -data
->window_rect
.left
, -data
->window_rect
.top
);
254 parent
= GetAncestor( data
->hwnd
, GA_PARENT
);
255 hdc_src
= GetDCEx( parent
, 0, DCX_CACHE
);
256 hdc_dst
= GetDCEx( data
->hwnd
, 0, DCX_CACHE
| DCX_WINDOW
);
260 OffsetRect( &dst_rect
, -data
->whole_rect
.left
, -data
->whole_rect
.top
);
261 /* make src rect relative to the old position of the window */
262 OffsetRect( &src_rect
, -old_whole_rect
->left
, -old_whole_rect
->top
);
263 if (dst_rect
.left
== src_rect
.left
&& dst_rect
.top
== src_rect
.top
) return;
264 /* now make them relative to window rect for DCX_WINDOW */
265 OffsetRect( &dst_rect
, data
->whole_rect
.left
- data
->window_rect
.left
,
266 data
->whole_rect
.top
- data
->window_rect
.top
);
267 OffsetRect( &src_rect
, data
->whole_rect
.left
- data
->window_rect
.left
,
268 data
->whole_rect
.top
- data
->window_rect
.top
);
269 hdc_src
= hdc_dst
= GetDCEx( data
->hwnd
, 0, DCX_CACHE
| DCX_WINDOW
);
272 code
= X11DRV_START_EXPOSURES
;
273 ExtEscape( hdc_dst
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, 0, NULL
);
275 TRACE( "copying bits for win %p/%lx %s -> %s\n",
276 data
->hwnd
, data
->whole_window
, wine_dbgstr_rect(&src_rect
), wine_dbgstr_rect(&dst_rect
) );
277 BitBlt( hdc_dst
, dst_rect
.left
, dst_rect
.top
,
278 dst_rect
.right
- dst_rect
.left
, dst_rect
.bottom
- dst_rect
.top
,
279 hdc_src
, src_rect
.left
, src_rect
.top
, SRCCOPY
);
281 code
= X11DRV_END_EXPOSURES
;
282 ExtEscape( hdc_dst
, X11DRV_ESCAPE
, sizeof(code
), (LPSTR
)&code
, sizeof(rgn
), (LPSTR
)&rgn
);
284 ReleaseDC( data
->hwnd
, hdc_dst
);
285 if (hdc_src
!= hdc_dst
) ReleaseDC( parent
, hdc_src
);
289 OffsetRgn( rgn
, data
->window_rect
.left
- data
->client_rect
.left
,
290 data
->window_rect
.top
- data
->client_rect
.top
);
291 RedrawWindow( data
->hwnd
, NULL
, rgn
, RDW_INVALIDATE
| RDW_FRAME
| RDW_ERASE
| RDW_ALLCHILDREN
);
296 /***********************************************************************
297 * set_server_window_pos
299 * Set the window pos on the server side only. Helper for SetWindowPos.
301 static BOOL
set_server_window_pos( HWND hwnd
, HWND insert_after
, const RECT
*rectWindow
,
302 const RECT
*rectClient
, UINT swp_flags
, const RECT
*valid_rects
,
308 if (!(win
= WIN_GetPtr( hwnd
))) return FALSE
;
309 if (win
== WND_DESKTOP
|| win
== WND_OTHER_PROCESS
) return FALSE
;
311 SERVER_START_REQ( set_window_pos
)
314 req
->previous
= insert_after
;
315 req
->flags
= swp_flags
;
316 req
->window
.left
= rectWindow
->left
;
317 req
->window
.top
= rectWindow
->top
;
318 req
->window
.right
= rectWindow
->right
;
319 req
->window
.bottom
= rectWindow
->bottom
;
320 req
->client
.left
= rectClient
->left
;
321 req
->client
.top
= rectClient
->top
;
322 req
->client
.right
= rectClient
->right
;
323 req
->client
.bottom
= rectClient
->bottom
;
324 if (!IsRectEmpty( &valid_rects
[0] ))
325 wine_server_add_data( req
, valid_rects
, 2 * sizeof(*valid_rects
) );
326 if ((ret
= !wine_server_call( req
)))
328 win
->dwStyle
= reply
->new_style
;
329 win
->dwExStyle
= reply
->new_ex_style
;
330 win
->rectWindow
= *rectWindow
;
331 win
->rectClient
= *rectClient
;
332 visible_rect
->left
= reply
->visible
.left
;
333 visible_rect
->top
= reply
->visible
.top
;
334 visible_rect
->right
= reply
->visible
.right
;
335 visible_rect
->bottom
= reply
->visible
.bottom
;
340 WIN_ReleasePtr( win
);
345 /***********************************************************************
346 * SetWindowPos (X11DRV.@)
348 BOOL
X11DRV_SetWindowPos( HWND hwnd
, HWND insert_after
, const RECT
*rectWindow
,
349 const RECT
*rectClient
, UINT swp_flags
, const RECT
*valid_rects
)
351 Display
*display
= thread_display();
352 struct x11drv_win_data
*data
;
353 RECT old_window_rect
, old_whole_rect
, old_client_rect
, visible_rect
;
354 DWORD old_style
, new_style
;
356 if (!(data
= X11DRV_get_win_data( hwnd
))) return FALSE
;
358 old_style
= GetWindowLongW( hwnd
, GWL_STYLE
);
360 if (!set_server_window_pos( hwnd
, insert_after
, rectWindow
, rectClient
, swp_flags
,
361 valid_rects
, &visible_rect
))
364 if (data
->whole_window
== DefaultRootWindow(gdi_display
))
366 data
->whole_rect
= data
->client_rect
= data
->window_rect
= *rectWindow
;
370 /* check if we need to switch the window to managed */
371 if (!data
->managed
&& data
->whole_window
&& managed_mode
&&
372 root_window
== DefaultRootWindow( display
) &&
373 is_window_managed( hwnd
, swp_flags
, rectWindow
))
375 TRACE( "making win %p/%lx managed\n", hwnd
, data
->whole_window
);
376 data
->managed
= TRUE
;
377 SetPropA( hwnd
, managed_prop
, (HANDLE
)1 );
378 if (old_style
& WS_VISIBLE
)
381 XUnmapWindow( display
, data
->whole_window
);
383 old_style
&= ~WS_VISIBLE
; /* force it to be mapped again below */
387 new_style
= GetWindowLongW( hwnd
, GWL_STYLE
);
388 old_window_rect
= data
->window_rect
;
389 old_whole_rect
= data
->whole_rect
;
390 old_client_rect
= data
->client_rect
;
391 data
->window_rect
= *rectWindow
;
392 data
->whole_rect
= *rectWindow
;
393 data
->client_rect
= *rectClient
;
394 X11DRV_window_to_X_rect( data
, &data
->whole_rect
);
395 if (memcmp( &visible_rect
, &data
->whole_rect
, sizeof(RECT
) ))
397 TRACE( "%p: need to update visible rect %s -> %s\n", hwnd
,
398 wine_dbgstr_rect(&visible_rect
), wine_dbgstr_rect(&data
->whole_rect
) );
399 SERVER_START_REQ( set_window_visible_rect
)
402 req
->flags
= swp_flags
;
403 req
->visible
.left
= data
->whole_rect
.left
;
404 req
->visible
.top
= data
->whole_rect
.top
;
405 req
->visible
.right
= data
->whole_rect
.right
;
406 req
->visible
.bottom
= data
->whole_rect
.bottom
;
407 wine_server_call( req
);
412 /* invalidate DCEs */
413 if ((((swp_flags
& SWP_AGG_NOPOSCHANGE
) != SWP_AGG_NOPOSCHANGE
) && (new_style
& WS_VISIBLE
)) ||
414 (swp_flags
& (SWP_HIDEWINDOW
| SWP_SHOWWINDOW
)))
417 UnionRect( &rect
, rectWindow
, &old_window_rect
);
418 invalidate_dce( hwnd
, &rect
);
421 TRACE( "win %p window %s client %s style %08x\n",
422 hwnd
, wine_dbgstr_rect(rectWindow
), wine_dbgstr_rect(rectClient
), new_style
);
424 if (!IsRectEmpty( &valid_rects
[0] ))
426 int x_offset
= old_whole_rect
.left
- data
->whole_rect
.left
;
427 int y_offset
= old_whole_rect
.top
- data
->whole_rect
.top
;
429 /* if all that happened is that the whole window moved, copy everything */
430 if (!(swp_flags
& SWP_FRAMECHANGED
) &&
431 old_whole_rect
.right
- data
->whole_rect
.right
== x_offset
&&
432 old_whole_rect
.bottom
- data
->whole_rect
.bottom
== y_offset
&&
433 old_client_rect
.left
- data
->client_rect
.left
== x_offset
&&
434 old_client_rect
.right
- data
->client_rect
.right
== x_offset
&&
435 old_client_rect
.top
- data
->client_rect
.top
== y_offset
&&
436 old_client_rect
.bottom
- data
->client_rect
.bottom
== y_offset
&&
437 !memcmp( &valid_rects
[0], &data
->client_rect
, sizeof(RECT
) ))
439 /* if we have an X window the bits will be moved by the X server */
440 if (!data
->whole_window
)
441 move_window_bits( data
, &old_whole_rect
, &data
->whole_rect
, &old_whole_rect
);
444 move_window_bits( data
, &valid_rects
[1], &valid_rects
[0], &old_whole_rect
);
447 if (data
->gl_drawable
&&
448 data
->client_rect
.right
-data
->client_rect
.left
== old_client_rect
.right
-old_client_rect
.left
&&
449 data
->client_rect
.bottom
-data
->client_rect
.top
== old_client_rect
.bottom
-old_client_rect
.top
)
450 X11DRV_sync_gl_drawable( display
, data
);
452 if (!data
->whole_window
|| data
->lock_changes
) return TRUE
; /* nothing more to do */
454 if ((old_style
& WS_VISIBLE
) && !(new_style
& WS_VISIBLE
))
456 /* window got hidden, unmap it */
457 TRACE( "unmapping win %p\n", hwnd
);
459 XUnmapWindow( display
, data
->whole_window
);
462 else if ((new_style
& WS_VISIBLE
) && !X11DRV_is_window_rect_mapped( rectWindow
))
464 /* resizing to zero size or off screen -> unmap */
465 TRACE( "unmapping zero size or off-screen win %p\n", hwnd
);
467 XUnmapWindow( display
, data
->whole_window
);
471 X11DRV_sync_window_position( display
, data
, swp_flags
, &old_client_rect
, &old_whole_rect
);
473 if ((new_style
& WS_VISIBLE
) && !(new_style
& WS_MINIMIZE
) &&
474 X11DRV_is_window_rect_mapped( rectWindow
))
478 if (!(old_style
& WS_VISIBLE
))
480 /* window got shown, map it */
481 TRACE( "mapping win %p\n", hwnd
);
484 else if ((swp_flags
& (SWP_NOSIZE
| SWP_NOMOVE
)) != (SWP_NOSIZE
| SWP_NOMOVE
))
486 /* resizing from zero size to non-zero -> map */
487 TRACE( "mapping non zero size or off-screen win %p\n", hwnd
);
491 if (mapped
|| (swp_flags
& SWP_FRAMECHANGED
))
492 X11DRV_set_wm_hints( display
, data
);
496 X11DRV_sync_window_style( display
, data
);
498 XMapWindow( display
, data
->whole_window
);
502 update_wm_states( display
, data
, mapped
);
509 /***********************************************************************
512 * Find a suitable place for an iconic window.
514 static POINT
WINPOS_FindIconPos( HWND hwnd
, POINT pt
)
516 RECT rect
, rectParent
;
519 int xspacing
, yspacing
;
521 parent
= GetAncestor( hwnd
, GA_PARENT
);
522 GetClientRect( parent
, &rectParent
);
523 if ((pt
.x
>= rectParent
.left
) && (pt
.x
+ GetSystemMetrics(SM_CXICON
) < rectParent
.right
) &&
524 (pt
.y
>= rectParent
.top
) && (pt
.y
+ GetSystemMetrics(SM_CYICON
) < rectParent
.bottom
))
525 return pt
; /* The icon already has a suitable position */
527 xspacing
= GetSystemMetrics(SM_CXICONSPACING
);
528 yspacing
= GetSystemMetrics(SM_CYICONSPACING
);
530 /* Check if another icon already occupies this spot */
531 /* FIXME: this is completely inefficient */
533 hrgn
= CreateRectRgn( 0, 0, 0, 0 );
534 tmp
= CreateRectRgn( 0, 0, 0, 0 );
535 for (child
= GetWindow( parent
, GW_HWNDFIRST
); child
; child
= GetWindow( child
, GW_HWNDNEXT
))
538 if (child
== hwnd
) continue;
539 if ((GetWindowLongW( child
, GWL_STYLE
) & (WS_VISIBLE
|WS_MINIMIZE
)) != (WS_VISIBLE
|WS_MINIMIZE
))
541 if (!(childPtr
= WIN_GetPtr( child
)) || childPtr
== WND_OTHER_PROCESS
)
543 SetRectRgn( tmp
, childPtr
->rectWindow
.left
, childPtr
->rectWindow
.top
,
544 childPtr
->rectWindow
.right
, childPtr
->rectWindow
.bottom
);
545 CombineRgn( hrgn
, hrgn
, tmp
, RGN_OR
);
546 WIN_ReleasePtr( childPtr
);
550 for (rect
.bottom
= rectParent
.bottom
; rect
.bottom
>= yspacing
; rect
.bottom
-= yspacing
)
552 for (rect
.left
= rectParent
.left
; rect
.left
<= rectParent
.right
- xspacing
; rect
.left
+= xspacing
)
554 rect
.right
= rect
.left
+ xspacing
;
555 rect
.top
= rect
.bottom
- yspacing
;
556 if (!RectInRegion( hrgn
, &rect
))
558 /* No window was found, so it's OK for us */
559 pt
.x
= rect
.left
+ (xspacing
- GetSystemMetrics(SM_CXICON
)) / 2;
560 pt
.y
= rect
.top
+ (yspacing
- GetSystemMetrics(SM_CYICON
)) / 2;
561 DeleteObject( hrgn
);
566 DeleteObject( hrgn
);
572 /***********************************************************************
575 UINT
WINPOS_MinMaximize( HWND hwnd
, UINT cmd
, LPRECT rect
)
583 TRACE("%p %u\n", hwnd
, cmd
);
585 wpl
.length
= sizeof(wpl
);
586 GetWindowPlacement( hwnd
, &wpl
);
588 if (HOOK_CallHooks( WH_CBT
, HCBT_MINMAX
, (WPARAM
)hwnd
, cmd
, TRUE
))
589 return SWP_NOSIZE
| SWP_NOMOVE
;
591 if (IsIconic( hwnd
))
595 case SW_SHOWMINNOACTIVE
:
596 case SW_SHOWMINIMIZED
:
597 case SW_FORCEMINIMIZE
:
599 return SWP_NOSIZE
| SWP_NOMOVE
;
601 if (!SendMessageW( hwnd
, WM_QUERYOPEN
, 0, 0 )) return SWP_NOSIZE
| SWP_NOMOVE
;
602 swpFlags
|= SWP_NOCOPYBITS
;
607 case SW_SHOWMINNOACTIVE
:
608 case SW_SHOWMINIMIZED
:
609 case SW_FORCEMINIMIZE
:
611 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
612 if( wndPtr
->dwStyle
& WS_MAXIMIZE
) wndPtr
->flags
|= WIN_RESTORE_MAX
;
613 else wndPtr
->flags
&= ~WIN_RESTORE_MAX
;
614 WIN_ReleasePtr( wndPtr
);
616 old_style
= WIN_SetStyle( hwnd
, WS_MINIMIZE
, WS_MAXIMIZE
);
618 X11DRV_set_iconic_state( hwnd
);
620 wpl
.ptMinPosition
= WINPOS_FindIconPos( hwnd
, wpl
.ptMinPosition
);
622 if (!(old_style
& WS_MINIMIZE
)) swpFlags
|= SWP_STATECHANGED
;
623 SetRect( rect
, wpl
.ptMinPosition
.x
, wpl
.ptMinPosition
.y
,
624 GetSystemMetrics(SM_CXICON
), GetSystemMetrics(SM_CYICON
) );
625 swpFlags
|= SWP_NOCOPYBITS
;
629 old_style
= GetWindowLongW( hwnd
, GWL_STYLE
);
630 if ((old_style
& WS_MAXIMIZE
) && (old_style
& WS_VISIBLE
)) return SWP_NOSIZE
| SWP_NOMOVE
;
632 WINPOS_GetMinMaxInfo( hwnd
, &size
, &wpl
.ptMaxPosition
, NULL
, NULL
);
634 old_style
= WIN_SetStyle( hwnd
, WS_MAXIMIZE
, WS_MINIMIZE
);
635 if (old_style
& WS_MINIMIZE
)
637 WINPOS_ShowIconTitle( hwnd
, FALSE
);
638 X11DRV_set_iconic_state( hwnd
);
640 if (!(old_style
& WS_MAXIMIZE
)) swpFlags
|= SWP_STATECHANGED
;
641 SetRect( rect
, wpl
.ptMaxPosition
.x
, wpl
.ptMaxPosition
.y
, size
.x
, size
.y
);
644 case SW_SHOWNOACTIVATE
:
647 old_style
= WIN_SetStyle( hwnd
, 0, WS_MINIMIZE
| WS_MAXIMIZE
);
648 if (old_style
& WS_MINIMIZE
)
652 WINPOS_ShowIconTitle( hwnd
, FALSE
);
653 X11DRV_set_iconic_state( hwnd
);
655 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
656 restore_max
= (wndPtr
->flags
& WIN_RESTORE_MAX
) != 0;
657 WIN_ReleasePtr( wndPtr
);
660 /* Restore to maximized position */
661 WINPOS_GetMinMaxInfo( hwnd
, &size
, &wpl
.ptMaxPosition
, NULL
, NULL
);
662 WIN_SetStyle( hwnd
, WS_MAXIMIZE
, 0 );
663 swpFlags
|= SWP_STATECHANGED
;
664 SetRect( rect
, wpl
.ptMaxPosition
.x
, wpl
.ptMaxPosition
.y
, size
.x
, size
.y
);
668 else if (!(old_style
& WS_MAXIMIZE
)) break;
670 swpFlags
|= SWP_STATECHANGED
;
672 /* Restore to normal position */
674 *rect
= wpl
.rcNormalPosition
;
675 rect
->right
-= rect
->left
;
676 rect
->bottom
-= rect
->top
;
685 /***********************************************************************
686 * ShowWindow (X11DRV.@)
688 BOOL
X11DRV_ShowWindow( HWND hwnd
, INT cmd
)
692 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
693 BOOL wasVisible
= (style
& WS_VISIBLE
) != 0;
694 BOOL showFlag
= TRUE
;
695 RECT newPos
= {0, 0, 0, 0};
698 TRACE("hwnd=%p, cmd=%d, wasVisible %d\n", hwnd
, cmd
, wasVisible
);
703 if (!wasVisible
) return FALSE
;
705 swp
|= SWP_HIDEWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
706 if (hwnd
!= GetActiveWindow())
707 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
710 case SW_SHOWMINNOACTIVE
:
711 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
714 case SW_FORCEMINIMIZE
: /* FIXME: Does not work if thread is hung. */
715 if (style
& WS_CHILD
) swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
717 case SW_SHOWMINIMIZED
:
718 swp
|= SWP_SHOWWINDOW
| SWP_FRAMECHANGED
;
719 swp
|= WINPOS_MinMaximize( hwnd
, cmd
, &newPos
);
720 if ((style
& WS_MINIMIZE
) && wasVisible
) return TRUE
;
723 case SW_SHOWMAXIMIZED
: /* same as SW_MAXIMIZE */
724 if (!wasVisible
) swp
|= SWP_SHOWWINDOW
;
725 swp
|= SWP_FRAMECHANGED
;
726 swp
|= WINPOS_MinMaximize( hwnd
, SW_MAXIMIZE
, &newPos
);
727 if ((style
& WS_MAXIMIZE
) && wasVisible
) return TRUE
;
731 swp
|= SWP_NOACTIVATE
| SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
732 if (style
& WS_CHILD
) swp
|= SWP_NOZORDER
;
735 if (wasVisible
) return TRUE
;
736 swp
|= SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
737 if (style
& WS_CHILD
) swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
740 case SW_SHOWNOACTIVATE
:
741 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
745 case SW_SHOWNORMAL
: /* same as SW_NORMAL: */
746 case SW_SHOWDEFAULT
: /* FIXME: should have its own handler */
747 if (!wasVisible
) swp
|= SWP_SHOWWINDOW
;
748 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
750 swp
|= SWP_FRAMECHANGED
;
751 swp
|= WINPOS_MinMaximize( hwnd
, cmd
, &newPos
);
755 if (wasVisible
) return TRUE
;
756 swp
|= SWP_NOSIZE
| SWP_NOMOVE
;
758 if (style
& WS_CHILD
&& !(swp
& SWP_STATECHANGED
)) swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
762 if ((showFlag
!= wasVisible
|| cmd
== SW_SHOWNA
) && cmd
!= SW_SHOWMAXIMIZED
&& !(swp
& SWP_STATECHANGED
))
764 SendMessageW( hwnd
, WM_SHOWWINDOW
, showFlag
, 0 );
765 if (!IsWindow( hwnd
)) return wasVisible
;
768 parent
= GetAncestor( hwnd
, GA_PARENT
);
769 if (parent
&& !IsWindowVisible( parent
) && !(swp
& SWP_STATECHANGED
))
771 /* if parent is not visible simply toggle WS_VISIBLE and return */
772 if (showFlag
) WIN_SetStyle( hwnd
, WS_VISIBLE
, 0 );
773 else WIN_SetStyle( hwnd
, 0, WS_VISIBLE
);
776 SetWindowPos( hwnd
, HWND_TOP
, newPos
.left
, newPos
.top
,
777 newPos
.right
, newPos
.bottom
, LOWORD(swp
) );
783 /* FIXME: This will cause the window to be activated irrespective
784 * of whether it is owned by the same thread. Has to be done
788 if (hwnd
== GetActiveWindow())
789 WINPOS_ActivateOtherWindow(hwnd
);
791 /* Revert focus to parent */
793 if (hwnd
== hFocus
|| IsChild(hwnd
, hFocus
))
795 HWND parent
= GetAncestor(hwnd
, GA_PARENT
);
796 if (parent
== GetDesktopWindow()) parent
= 0;
801 if (IsIconic(hwnd
)) WINPOS_ShowIconTitle( hwnd
, TRUE
);
803 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return wasVisible
;
805 if (wndPtr
->flags
& WIN_NEED_SIZE
)
807 /* should happen only in CreateWindowEx() */
808 int wParam
= SIZE_RESTORED
;
809 RECT client
= wndPtr
->rectClient
;
811 wndPtr
->flags
&= ~WIN_NEED_SIZE
;
812 if (wndPtr
->dwStyle
& WS_MAXIMIZE
) wParam
= SIZE_MAXIMIZED
;
813 else if (wndPtr
->dwStyle
& WS_MINIMIZE
) wParam
= SIZE_MINIMIZED
;
814 WIN_ReleasePtr( wndPtr
);
816 SendMessageW( hwnd
, WM_SIZE
, wParam
,
817 MAKELONG( client
.right
- client
.left
, client
.bottom
- client
.top
));
818 SendMessageW( hwnd
, WM_MOVE
, 0, MAKELONG( client
.left
, client
.top
));
820 else WIN_ReleasePtr( wndPtr
);
822 /* if previous state was minimized Windows sets focus to the window */
823 if (style
& WS_MINIMIZE
) SetFocus( hwnd
);
829 /**********************************************************************
832 void X11DRV_MapNotify( HWND hwnd
, XEvent
*event
)
834 struct x11drv_win_data
*data
;
835 HWND hwndFocus
= GetFocus();
838 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
840 if (!(win
= WIN_GetPtr( hwnd
))) return;
842 if (data
->managed
&& (win
->dwStyle
& WS_VISIBLE
) && (win
->dwStyle
& WS_MINIMIZE
))
845 unsigned int width
, height
, border
, depth
;
848 LONG style
= WS_VISIBLE
;
852 XGetGeometry( event
->xmap
.display
, data
->whole_window
, &root
, &x
, &y
, &width
, &height
,
854 XTranslateCoordinates( event
->xmap
.display
, data
->whole_window
, root
, 0, 0, &x
, &y
, &top
);
858 rect
.right
= x
+ width
;
859 rect
.bottom
= y
+ height
;
860 OffsetRect( &rect
, virtual_screen_rect
.left
, virtual_screen_rect
.top
);
861 X11DRV_X_to_window_rect( data
, &rect
);
863 invalidate_dce( hwnd
, &data
->window_rect
);
865 if (win
->flags
& WIN_RESTORE_MAX
) style
|= WS_MAXIMIZE
;
866 WIN_SetStyle( hwnd
, style
, WS_MINIMIZE
);
867 WIN_ReleasePtr( win
);
869 SendMessageW( hwnd
, WM_SHOWWINDOW
, SW_RESTORE
, 0 );
870 data
->lock_changes
++;
871 SetWindowPos( hwnd
, 0, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
,
872 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_FRAMECHANGED
| SWP_STATECHANGED
);
873 data
->lock_changes
--;
875 else WIN_ReleasePtr( win
);
876 if (hwndFocus
&& IsChild( hwnd
, hwndFocus
)) X11DRV_SetFocus(hwndFocus
); /* FIXME */
880 /**********************************************************************
883 void X11DRV_UnmapNotify( HWND hwnd
, XEvent
*event
)
885 struct x11drv_win_data
*data
;
888 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
890 if (!(win
= WIN_GetPtr( hwnd
))) return;
892 if ((win
->dwStyle
& WS_VISIBLE
) && data
->managed
&&
893 X11DRV_is_window_rect_mapped( &win
->rectWindow
))
895 if (win
->dwStyle
& WS_MAXIMIZE
)
896 win
->flags
|= WIN_RESTORE_MAX
;
897 else if (!(win
->dwStyle
& WS_MINIMIZE
))
898 win
->flags
&= ~WIN_RESTORE_MAX
;
900 WIN_SetStyle( hwnd
, WS_MINIMIZE
, WS_MAXIMIZE
);
901 WIN_ReleasePtr( win
);
904 SendMessageW( hwnd
, WM_SHOWWINDOW
, SW_MINIMIZE
, 0 );
905 data
->lock_changes
++;
906 SetWindowPos( hwnd
, 0, 0, 0, GetSystemMetrics(SM_CXICON
), GetSystemMetrics(SM_CYICON
),
907 SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_STATECHANGED
);
908 data
->lock_changes
--;
910 else WIN_ReleasePtr( win
);
913 struct desktop_resize_data
915 RECT old_screen_rect
;
916 RECT old_virtual_rect
;
919 static BOOL CALLBACK
update_windows_on_desktop_resize( HWND hwnd
, LPARAM lparam
)
921 struct x11drv_win_data
*data
;
922 Display
*display
= thread_display();
923 struct desktop_resize_data
*resize_data
= (struct desktop_resize_data
*)lparam
;
926 if (!(data
= X11DRV_get_win_data( hwnd
))) return TRUE
;
928 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
)
930 /* update the full screen state */
931 update_wm_states( display
, data
, FALSE
);
934 if (resize_data
->old_virtual_rect
.left
!= virtual_screen_rect
.left
) mask
|= CWX
;
935 if (resize_data
->old_virtual_rect
.top
!= virtual_screen_rect
.top
) mask
|= CWY
;
936 if (mask
&& data
->whole_window
)
938 XWindowChanges changes
;
941 changes
.x
= data
->whole_rect
.left
- virtual_screen_rect
.left
;
942 changes
.y
= data
->whole_rect
.top
- virtual_screen_rect
.top
;
943 XReconfigureWMWindow( display
, data
->whole_window
,
944 DefaultScreen(display
), mask
, &changes
);
951 /***********************************************************************
952 * X11DRV_resize_desktop
954 void X11DRV_resize_desktop( unsigned int width
, unsigned int height
)
956 HWND hwnd
= GetDesktopWindow();
957 struct x11drv_win_data
*data
;
958 struct desktop_resize_data resize_data
;
960 SetRect( &resize_data
.old_screen_rect
, 0, 0, screen_width
, screen_height
);
961 resize_data
.old_virtual_rect
= virtual_screen_rect
;
963 xinerama_init( width
, height
);
965 if (!(data
= X11DRV_get_win_data( hwnd
)))
967 SendMessageW( hwnd
, WM_X11DRV_RESIZE_DESKTOP
, 0, MAKELPARAM( width
, height
) );
971 TRACE( "desktop %p change to (%dx%d)\n", hwnd
, width
, height
);
972 SetWindowPos( hwnd
, 0, virtual_screen_rect
.left
, virtual_screen_rect
.top
,
973 virtual_screen_rect
.right
- virtual_screen_rect
.left
,
974 virtual_screen_rect
.bottom
- virtual_screen_rect
.top
,
975 SWP_NOZORDER
| SWP_NOACTIVATE
);
976 SendMessageTimeoutW( HWND_BROADCAST
, WM_DISPLAYCHANGE
, screen_bpp
,
977 MAKELPARAM( width
, height
), SMTO_ABORTIFHUNG
, 2000, NULL
);
980 EnumWindows( update_windows_on_desktop_resize
, (LPARAM
)&resize_data
);
984 /***********************************************************************
985 * X11DRV_ConfigureNotify
987 void X11DRV_ConfigureNotify( HWND hwnd
, XEvent
*xev
)
989 XConfigureEvent
*event
= &xev
->xconfigure
;
990 struct x11drv_win_data
*data
;
993 int cx
, cy
, x
= event
->x
, y
= event
->y
;
996 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1000 if (!event
->send_event
) /* normal event, need to map coordinates to the root */
1004 XTranslateCoordinates( event
->display
, data
->whole_window
, root_window
,
1005 0, 0, &x
, &y
, &child
);
1006 wine_tsx11_unlock();
1010 rect
.right
= x
+ event
->width
;
1011 rect
.bottom
= y
+ event
->height
;
1012 OffsetRect( &rect
, virtual_screen_rect
.left
, virtual_screen_rect
.top
);
1013 TRACE( "win %p new X rect %d,%d,%dx%d (event %d,%d,%dx%d)\n",
1014 hwnd
, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
,
1015 event
->x
, event
->y
, event
->width
, event
->height
);
1016 X11DRV_X_to_window_rect( data
, &rect
);
1020 cx
= rect
.right
- rect
.left
;
1021 cy
= rect
.bottom
- rect
.top
;
1022 flags
= SWP_NOACTIVATE
| SWP_NOZORDER
;
1024 /* Compare what has changed */
1026 GetWindowRect( hwnd
, &rect
);
1027 if (rect
.left
== x
&& rect
.top
== y
) flags
|= SWP_NOMOVE
;
1029 TRACE( "%p moving from (%d,%d) to (%d,%d)\n",
1030 hwnd
, rect
.left
, rect
.top
, x
, y
);
1032 if ((rect
.right
- rect
.left
== cx
&& rect
.bottom
- rect
.top
== cy
) ||
1034 (IsRectEmpty( &rect
) && event
->width
== 1 && event
->height
== 1))
1036 if (flags
& SWP_NOMOVE
) return; /* if nothing changed, don't do anything */
1037 flags
|= SWP_NOSIZE
;
1040 TRACE( "%p resizing from (%dx%d) to (%dx%d)\n",
1041 hwnd
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, cx
, cy
);
1043 data
->lock_changes
++;
1044 SetWindowPos( hwnd
, 0, x
, y
, cx
, cy
, flags
);
1045 data
->lock_changes
--;
1049 /***********************************************************************
1050 * SetWindowRgn (X11DRV.@)
1052 * Assign specified region to window (for non-rectangular windows)
1054 int X11DRV_SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL redraw
)
1056 struct x11drv_win_data
*data
;
1058 if (!(data
= X11DRV_get_win_data( hwnd
)))
1060 if (IsWindow( hwnd
))
1061 FIXME( "not supported on other thread window %p\n", hwnd
);
1062 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
1066 #ifdef HAVE_LIBXSHAPE
1067 if (data
->whole_window
)
1069 Display
*display
= thread_display();
1074 XShapeCombineMask( display
, data
->whole_window
,
1075 ShapeBounding
, 0, 0, None
, ShapeSet
);
1076 wine_tsx11_unlock();
1080 RGNDATA
*pRegionData
= X11DRV_GetRegionData( hrgn
, 0 );
1084 XShapeCombineRectangles( display
, data
->whole_window
, ShapeBounding
,
1085 data
->window_rect
.left
- data
->whole_rect
.left
,
1086 data
->window_rect
.top
- data
->whole_rect
.top
,
1087 (XRectangle
*)pRegionData
->Buffer
,
1088 pRegionData
->rdh
.nCount
,
1089 ShapeSet
, YXBanded
);
1090 wine_tsx11_unlock();
1091 HeapFree(GetProcessHeap(), 0, pRegionData
);
1095 #endif /* HAVE_LIBXSHAPE */
1097 invalidate_dce( hwnd
, &data
->window_rect
);
1102 /***********************************************************************
1105 * Draw the frame used when moving or resizing window.
1107 * FIXME: This causes problems in Win95 mode. (why?)
1109 static void draw_moving_frame( HDC hdc
, RECT
*rect
, BOOL thickframe
)
1113 const int width
= GetSystemMetrics(SM_CXFRAME
);
1114 const int height
= GetSystemMetrics(SM_CYFRAME
);
1116 HBRUSH hbrush
= SelectObject( hdc
, GetStockObject( GRAY_BRUSH
) );
1117 PatBlt( hdc
, rect
->left
, rect
->top
,
1118 rect
->right
- rect
->left
- width
, height
, PATINVERT
);
1119 PatBlt( hdc
, rect
->left
, rect
->top
+ height
, width
,
1120 rect
->bottom
- rect
->top
- height
, PATINVERT
);
1121 PatBlt( hdc
, rect
->left
+ width
, rect
->bottom
- 1,
1122 rect
->right
- rect
->left
- width
, -height
, PATINVERT
);
1123 PatBlt( hdc
, rect
->right
- 1, rect
->top
, -width
,
1124 rect
->bottom
- rect
->top
- height
, PATINVERT
);
1125 SelectObject( hdc
, hbrush
);
1127 else DrawFocusRect( hdc
, rect
);
1131 /***********************************************************************
1134 * Initialization of a move or resize, when initiated from a menu choice.
1135 * Return hit test code for caption or sizing border.
1137 static LONG
start_size_move( HWND hwnd
, WPARAM wParam
, POINT
*capturePoint
, LONG style
)
1144 GetWindowRect( hwnd
, &rectWindow
);
1146 if ((wParam
& 0xfff0) == SC_MOVE
)
1148 /* Move pointer at the center of the caption */
1149 RECT rect
= rectWindow
;
1150 /* Note: to be exactly centered we should take the different types
1151 * of border into account, but it shouldn't make more than a few pixels
1152 * of difference so let's not bother with that */
1153 rect
.top
+= GetSystemMetrics(SM_CYBORDER
);
1154 if (style
& WS_SYSMENU
)
1155 rect
.left
+= GetSystemMetrics(SM_CXSIZE
) + 1;
1156 if (style
& WS_MINIMIZEBOX
)
1157 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
1158 if (style
& WS_MAXIMIZEBOX
)
1159 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
1160 pt
.x
= (rect
.right
+ rect
.left
) / 2;
1161 pt
.y
= rect
.top
+ GetSystemMetrics(SM_CYSIZE
)/2;
1162 hittest
= HTCAPTION
;
1170 GetMessageW( &msg
, 0, WM_KEYFIRST
, WM_MOUSELAST
);
1171 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
1177 hittest
= SendMessageW( hwnd
, WM_NCHITTEST
, 0, MAKELONG( pt
.x
, pt
.y
) );
1178 if ((hittest
< HTLEFT
) || (hittest
> HTBOTTOMRIGHT
)) hittest
= 0;
1189 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
1190 pt
.y
= rectWindow
.top
+ GetSystemMetrics(SM_CYFRAME
) / 2;
1194 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
1195 pt
.y
= rectWindow
.bottom
- GetSystemMetrics(SM_CYFRAME
) / 2;
1199 pt
.x
= rectWindow
.left
+ GetSystemMetrics(SM_CXFRAME
) / 2;
1200 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
1204 pt
.x
= rectWindow
.right
- GetSystemMetrics(SM_CXFRAME
) / 2;
1205 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
1208 case VK_ESCAPE
: return 0;
1214 SetCursorPos( pt
.x
, pt
.y
);
1215 SendMessageW( hwnd
, WM_SETCURSOR
, (WPARAM
)hwnd
, MAKELONG( hittest
, WM_MOUSEMOVE
));
1220 /***********************************************************************
1221 * set_movesize_capture
1223 static void set_movesize_capture( HWND hwnd
)
1227 SERVER_START_REQ( set_capture_window
)
1230 req
->flags
= CAPTURE_MOVESIZE
;
1231 if (!wine_server_call_err( req
))
1233 previous
= reply
->previous
;
1234 hwnd
= reply
->full_handle
;
1238 if (previous
&& previous
!= hwnd
)
1239 SendMessageW( previous
, WM_CAPTURECHANGED
, 0, (LPARAM
)hwnd
);
1242 /***********************************************************************
1243 * X11DRV_WMMoveResizeWindow
1245 * Tells the window manager to initiate a move or resize operation.
1248 * http://freedesktop.org/Standards/wm-spec/1.3/ar01s04.html
1249 * or search for "_NET_WM_MOVERESIZE"
1251 static BOOL
X11DRV_WMMoveResizeWindow( HWND hwnd
, int x
, int y
, WPARAM wparam
)
1253 WPARAM syscommand
= wparam
& 0xfff0;
1254 WPARAM hittest
= wparam
& 0x0f;
1257 Display
*display
= thread_display();
1259 if (syscommand
== SC_MOVE
)
1261 if (!hittest
) dir
= _NET_WM_MOVERESIZE_MOVE_KEYBOARD
;
1262 else dir
= _NET_WM_MOVERESIZE_MOVE
;
1266 /* windows without WS_THICKFRAME are not resizable through the window manager */
1267 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_THICKFRAME
)) return FALSE
;
1271 case WMSZ_LEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_LEFT
; break;
1272 case WMSZ_RIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_RIGHT
; break;
1273 case WMSZ_TOP
: dir
= _NET_WM_MOVERESIZE_SIZE_TOP
; break;
1274 case WMSZ_TOPLEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_TOPLEFT
; break;
1275 case WMSZ_TOPRIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_TOPRIGHT
; break;
1276 case WMSZ_BOTTOM
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOM
; break;
1277 case WMSZ_BOTTOMLEFT
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT
; break;
1278 case WMSZ_BOTTOMRIGHT
: dir
= _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT
; break;
1279 default: dir
= _NET_WM_MOVERESIZE_SIZE_KEYBOARD
; break;
1283 TRACE("hwnd %p, x %d, y %d, dir %d\n", hwnd
, x
, y
, dir
);
1285 xev
.xclient
.type
= ClientMessage
;
1286 xev
.xclient
.window
= X11DRV_get_whole_window(hwnd
);
1287 xev
.xclient
.message_type
= x11drv_atom(_NET_WM_MOVERESIZE
);
1288 xev
.xclient
.serial
= 0;
1289 xev
.xclient
.display
= display
;
1290 xev
.xclient
.send_event
= True
;
1291 xev
.xclient
.format
= 32;
1292 xev
.xclient
.data
.l
[0] = x
; /* x coord */
1293 xev
.xclient
.data
.l
[1] = y
; /* y coord */
1294 xev
.xclient
.data
.l
[2] = dir
; /* direction */
1295 xev
.xclient
.data
.l
[3] = 1; /* button */
1296 xev
.xclient
.data
.l
[4] = 0; /* unused */
1298 /* need to ungrab the pointer that may have been automatically grabbed
1299 * with a ButtonPress event */
1301 XUngrabPointer( display
, CurrentTime
);
1302 XSendEvent(display
, root_window
, False
, SubstructureNotifyMask
, &xev
);
1303 wine_tsx11_unlock();
1307 /***********************************************************************
1308 * SysCommandSizeMove (X11DRV.@)
1310 * Perform SC_MOVE and SC_SIZE commands.
1312 void X11DRV_SysCommandSizeMove( HWND hwnd
, WPARAM wParam
)
1315 RECT sizingRect
, mouseRect
, origRect
;
1318 LONG hittest
= (LONG
)(wParam
& 0x0f);
1319 WPARAM syscommand
= wParam
& 0xfff0;
1320 HCURSOR hDragCursor
= 0, hOldCursor
= 0;
1321 POINT minTrack
, maxTrack
;
1322 POINT capturePoint
, pt
;
1323 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
1324 BOOL thickframe
= HAS_THICKFRAME( style
);
1325 BOOL iconic
= style
& WS_MINIMIZE
;
1327 DWORD dwPoint
= GetMessagePos ();
1328 BOOL DragFullWindows
= TRUE
;
1329 Window parent_win
, whole_win
;
1330 struct x11drv_thread_data
*thread_data
= x11drv_thread_data();
1331 struct x11drv_win_data
*data
;
1333 pt
.x
= (short)LOWORD(dwPoint
);
1334 pt
.y
= (short)HIWORD(dwPoint
);
1337 if (IsZoomed(hwnd
) || !IsWindowVisible(hwnd
)) return;
1339 if (!(data
= X11DRV_get_win_data( hwnd
))) return;
1341 TRACE("hwnd %p (%smanaged), command %04lx, hittest %d, pos %d,%d\n",
1342 hwnd
, data
->managed
? "" : "NOT ", syscommand
, hittest
, pt
.x
, pt
.y
);
1344 /* if we are managed then we let the WM do all the work */
1345 if (data
->managed
&& X11DRV_WMMoveResizeWindow( hwnd
, pt
.x
, pt
.y
, wParam
)) return;
1347 if (syscommand
== SC_MOVE
)
1349 if (!hittest
) hittest
= start_size_move( hwnd
, wParam
, &capturePoint
, style
);
1350 if (!hittest
) return;
1354 if ( hittest
&& (syscommand
!= SC_MOUSEMENU
) )
1355 hittest
+= (HTLEFT
- WMSZ_LEFT
);
1358 set_movesize_capture( hwnd
);
1359 hittest
= start_size_move( hwnd
, wParam
, &capturePoint
, style
);
1362 set_movesize_capture(0);
1368 /* Get min/max info */
1370 WINPOS_GetMinMaxInfo( hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
1371 GetWindowRect( hwnd
, &sizingRect
);
1372 if (style
& WS_CHILD
)
1374 parent
= GetParent(hwnd
);
1375 /* make sizing rect relative to parent */
1376 MapWindowPoints( 0, parent
, (POINT
*)&sizingRect
, 2 );
1377 GetClientRect( parent
, &mouseRect
);
1382 mouseRect
= virtual_screen_rect
;
1384 origRect
= sizingRect
;
1386 if (ON_LEFT_BORDER(hittest
))
1388 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.right
-maxTrack
.x
);
1389 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.right
-minTrack
.x
);
1391 else if (ON_RIGHT_BORDER(hittest
))
1393 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.left
+minTrack
.x
);
1394 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.left
+maxTrack
.x
);
1396 if (ON_TOP_BORDER(hittest
))
1398 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.bottom
-maxTrack
.y
);
1399 mouseRect
.bottom
= min( mouseRect
.bottom
,sizingRect
.bottom
-minTrack
.y
);
1401 else if (ON_BOTTOM_BORDER(hittest
))
1403 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.top
+minTrack
.y
);
1404 mouseRect
.bottom
= min( mouseRect
.bottom
, sizingRect
.top
+maxTrack
.y
);
1406 if (parent
) MapWindowPoints( parent
, 0, (LPPOINT
)&mouseRect
, 2 );
1408 /* Retrieve a default cache DC (without using the window style) */
1409 hdc
= GetDCEx( parent
, 0, DCX_CACHE
);
1411 if( iconic
) /* create a cursor for dragging */
1413 hDragCursor
= (HCURSOR
)GetClassLongPtrW( hwnd
, GCLP_HICON
);
1414 if( !hDragCursor
) hDragCursor
= (HCURSOR
)SendMessageW( hwnd
, WM_QUERYDRAGICON
, 0, 0L);
1415 if( !hDragCursor
) iconic
= FALSE
;
1418 /* repaint the window before moving it around */
1419 RedrawWindow( hwnd
, NULL
, 0, RDW_UPDATENOW
| RDW_ALLCHILDREN
);
1421 SendMessageW( hwnd
, WM_ENTERSIZEMOVE
, 0, 0 );
1422 set_movesize_capture( hwnd
);
1424 /* we only allow disabling the full window drag for child windows, or in desktop mode */
1425 /* otherwise we'd need to grab the server and we want to avoid that */
1426 if (parent
|| (root_window
!= DefaultRootWindow(gdi_display
)))
1427 SystemParametersInfoA(SPI_GETDRAGFULLWINDOWS
, 0, &DragFullWindows
, 0);
1429 whole_win
= X11DRV_get_whole_window( GetAncestor(hwnd
,GA_ROOT
) );
1430 parent_win
= parent
? X11DRV_get_whole_window( GetAncestor(parent
,GA_ROOT
) ) : root_window
;
1433 XGrabPointer( thread_data
->display
, whole_win
, False
,
1434 PointerMotionMask
| ButtonPressMask
| ButtonReleaseMask
,
1435 GrabModeAsync
, GrabModeAsync
, parent_win
, None
, CurrentTime
);
1436 wine_tsx11_unlock();
1437 thread_data
->grab_window
= whole_win
;
1443 if (!GetMessageW( &msg
, 0, 0, 0 )) break;
1444 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
1446 /* Exit on button-up, Return, or Esc */
1447 if ((msg
.message
== WM_LBUTTONUP
) ||
1448 ((msg
.message
== WM_KEYDOWN
) &&
1449 ((msg
.wParam
== VK_RETURN
) || (msg
.wParam
== VK_ESCAPE
)))) break;
1451 if ((msg
.message
!= WM_KEYDOWN
) && (msg
.message
!= WM_MOUSEMOVE
))
1453 TranslateMessage( &msg
);
1454 DispatchMessageW( &msg
);
1455 continue; /* We are not interested in other messages */
1460 if (msg
.message
== WM_KEYDOWN
) switch(msg
.wParam
)
1462 case VK_UP
: pt
.y
-= 8; break;
1463 case VK_DOWN
: pt
.y
+= 8; break;
1464 case VK_LEFT
: pt
.x
-= 8; break;
1465 case VK_RIGHT
: pt
.x
+= 8; break;
1468 pt
.x
= max( pt
.x
, mouseRect
.left
);
1469 pt
.x
= min( pt
.x
, mouseRect
.right
);
1470 pt
.y
= max( pt
.y
, mouseRect
.top
);
1471 pt
.y
= min( pt
.y
, mouseRect
.bottom
);
1473 dx
= pt
.x
- capturePoint
.x
;
1474 dy
= pt
.y
- capturePoint
.y
;
1482 if( iconic
) /* ok, no system popup tracking */
1484 hOldCursor
= SetCursor(hDragCursor
);
1486 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1488 else if(!DragFullWindows
)
1489 draw_moving_frame( hdc
, &sizingRect
, thickframe
);
1492 if (msg
.message
== WM_KEYDOWN
) SetCursorPos( pt
.x
, pt
.y
);
1495 RECT newRect
= sizingRect
;
1496 WPARAM wpSizingHit
= 0;
1498 if (hittest
== HTCAPTION
) OffsetRect( &newRect
, dx
, dy
);
1499 if (ON_LEFT_BORDER(hittest
)) newRect
.left
+= dx
;
1500 else if (ON_RIGHT_BORDER(hittest
)) newRect
.right
+= dx
;
1501 if (ON_TOP_BORDER(hittest
)) newRect
.top
+= dy
;
1502 else if (ON_BOTTOM_BORDER(hittest
)) newRect
.bottom
+= dy
;
1503 if(!iconic
&& !DragFullWindows
) draw_moving_frame( hdc
, &sizingRect
, thickframe
);
1506 /* determine the hit location */
1507 if (hittest
>= HTLEFT
&& hittest
<= HTBOTTOMRIGHT
)
1508 wpSizingHit
= WMSZ_LEFT
+ (hittest
- HTLEFT
);
1509 SendMessageW( hwnd
, WM_SIZING
, wpSizingHit
, (LPARAM
)&newRect
);
1513 if(!DragFullWindows
)
1514 draw_moving_frame( hdc
, &newRect
, thickframe
);
1516 SetWindowPos( hwnd
, 0, newRect
.left
, newRect
.top
,
1517 newRect
.right
- newRect
.left
,
1518 newRect
.bottom
- newRect
.top
,
1519 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
1521 sizingRect
= newRect
;
1526 set_movesize_capture(0);
1529 if( moved
) /* restore cursors, show icon title later on */
1531 ShowCursor( FALSE
);
1532 SetCursor( hOldCursor
);
1535 else if (moved
&& !DragFullWindows
)
1537 draw_moving_frame( hdc
, &sizingRect
, thickframe
);
1538 /* make sure the moving frame is erased before we move the window */
1540 XFlush( gdi_display
);
1541 wine_tsx11_unlock();
1544 ReleaseDC( parent
, hdc
);
1547 XUngrabPointer( thread_data
->display
, CurrentTime
);
1548 wine_tsx11_unlock();
1549 thread_data
->grab_window
= None
;
1551 if (HOOK_CallHooks( WH_CBT
, HCBT_MOVESIZE
, (WPARAM
)hwnd
, (LPARAM
)&sizingRect
, TRUE
))
1554 SendMessageW( hwnd
, WM_EXITSIZEMOVE
, 0, 0 );
1555 SendMessageW( hwnd
, WM_SETVISIBLE
, !IsIconic(hwnd
), 0L);
1557 /* window moved or resized */
1560 /* if the moving/resizing isn't canceled call SetWindowPos
1561 * with the new position or the new size of the window
1563 if (!((msg
.message
== WM_KEYDOWN
) && (msg
.wParam
== VK_ESCAPE
)) )
1565 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
1566 if(!DragFullWindows
)
1567 SetWindowPos( hwnd
, 0, sizingRect
.left
, sizingRect
.top
,
1568 sizingRect
.right
- sizingRect
.left
,
1569 sizingRect
.bottom
- sizingRect
.top
,
1570 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
1573 { /* restore previous size/position */
1575 SetWindowPos( hwnd
, 0, origRect
.left
, origRect
.top
,
1576 origRect
.right
- origRect
.left
,
1577 origRect
.bottom
- origRect
.top
,
1578 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
1584 /* Single click brings up the system menu when iconized */
1588 if(style
& WS_SYSMENU
)
1589 SendMessageW( hwnd
, WM_SYSCOMMAND
,
1590 SC_MOUSEMENU
+ HTSYSMENU
, MAKELONG(pt
.x
,pt
.y
));
1592 else WINPOS_ShowIconTitle( hwnd
, TRUE
);