2 * Window position related functions.
4 * Copyright 1993, 1994, 1995, 2001 Alexandre Julliard
5 * Copyright 1995, 1996, 1999 Alex Korobka
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <X11/IntrinsicP.h>
27 #include <X11/extensions/shape.h>
28 #endif /* HAVE_LIBXSHAPE */
40 #include "cursoricon.h"
41 #include "nonclient.h"
43 #include "wine/server.h"
44 #include "wine/debug.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(x11drv
);
48 #define SWP_AGG_NOGEOMETRYCHANGE \
49 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE)
50 #define SWP_AGG_NOPOSCHANGE \
51 (SWP_AGG_NOGEOMETRYCHANGE | SWP_NOZORDER)
52 #define SWP_AGG_STATUSFLAGS \
53 (SWP_AGG_NOPOSCHANGE | SWP_FRAMECHANGED | SWP_HIDEWINDOW | SWP_SHOWWINDOW)
55 #define SWP_EX_NOCOPY 0x0001
56 #define SWP_EX_PAINTSELF 0x0002
57 #define SWP_EX_NONCLIENT 0x0004
59 #define HAS_THICKFRAME(style,exStyle) \
60 (((style) & WS_THICKFRAME) && \
61 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
63 #define ON_LEFT_BORDER(hit) \
64 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
65 #define ON_RIGHT_BORDER(hit) \
66 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
67 #define ON_TOP_BORDER(hit) \
68 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
69 #define ON_BOTTOM_BORDER(hit) \
70 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
73 /***********************************************************************
76 * Clip all children of a given window out of the visible region
78 static int clip_children( HWND parent
, HWND last
, HRGN hrgn
, int whole_window
)
83 int i
, x
, y
, ret
= SIMPLEREGION
;
85 /* first check if we have anything to do */
86 if (!(list
= WIN_ListChildren( parent
))) return ret
;
87 for (i
= 0; list
[i
] && list
[i
] != last
; i
++)
88 if (GetWindowLongW( list
[i
], GWL_STYLE
) & WS_VISIBLE
) break;
89 if (!list
[i
] || list
[i
] == last
) goto done
; /* no children to clip */
93 WND
*win
= WIN_FindWndPtr( parent
);
94 x
= win
->rectWindow
.left
- win
->rectClient
.left
;
95 y
= win
->rectWindow
.top
- win
->rectClient
.top
;
96 WIN_ReleaseWndPtr( win
);
100 rectRgn
= CreateRectRgn( 0, 0, 0, 0 );
102 for ( ; list
[i
] && list
[i
] != last
; i
++)
104 if (!(ptr
= WIN_FindWndPtr( list
[i
] ))) continue;
105 if (ptr
->dwStyle
& WS_VISIBLE
)
107 SetRectRgn( rectRgn
, ptr
->rectWindow
.left
+ x
, ptr
->rectWindow
.top
+ y
,
108 ptr
->rectWindow
.right
+ x
, ptr
->rectWindow
.bottom
+ y
);
109 if ((ret
= CombineRgn( hrgn
, hrgn
, rectRgn
, RGN_DIFF
)) == NULLREGION
)
111 WIN_ReleaseWndPtr( ptr
);
112 break; /* no need to go on, region is empty */
115 WIN_ReleaseWndPtr( ptr
);
117 DeleteObject( rectRgn
);
119 HeapFree( GetProcessHeap(), 0, list
);
124 /***********************************************************************
127 * Compute the visible region of a window
129 static HRGN
get_visible_region( WND
*win
, HWND top
, UINT flags
, int mode
)
133 int xoffset
, yoffset
;
134 X11DRV_WND_DATA
*data
= win
->pDriverData
;
136 if (flags
& DCX_WINDOW
)
138 xoffset
= win
->rectWindow
.left
;
139 yoffset
= win
->rectWindow
.top
;
143 xoffset
= win
->rectClient
.left
;
144 yoffset
= win
->rectClient
.top
;
147 if (flags
& DCX_PARENTCLIP
)
148 GetClientRect( win
->parent
, &rect
);
149 else if (flags
& DCX_WINDOW
)
150 rect
= data
->whole_rect
;
152 rect
= win
->rectClient
;
154 /* vis region is relative to the start of the client/window area */
155 OffsetRect( &rect
, -xoffset
, -yoffset
);
157 if (!(rgn
= CreateRectRgn( rect
.left
, rect
.top
, rect
.right
, rect
.bottom
))) return 0;
159 if ((flags
& DCX_CLIPCHILDREN
) && (mode
!= ClipByChildren
))
161 /* we need to clip children by hand */
162 if (clip_children( win
->hwndSelf
, 0, rgn
, (flags
& DCX_WINDOW
) ) == NULLREGION
) return rgn
;
165 if (top
&& top
!= win
->hwndSelf
) /* need to clip siblings of ancestors */
167 WND
*parent
, *ptr
= WIN_FindWndPtr( win
->hwndSelf
);
170 OffsetRgn( rgn
, xoffset
, yoffset
);
173 if (ptr
->dwStyle
& WS_CLIPSIBLINGS
)
175 if (clip_children( ptr
->parent
, ptr
->hwndSelf
, rgn
, FALSE
) == NULLREGION
) break;
177 if (ptr
->hwndSelf
== top
) break;
178 if (!(parent
= WIN_FindWndPtr( ptr
->parent
))) break;
179 WIN_ReleaseWndPtr( ptr
);
181 /* clip to parent client area */
182 if (tmp
) SetRectRgn( tmp
, 0, 0, ptr
->rectClient
.right
- ptr
->rectClient
.left
,
183 ptr
->rectClient
.bottom
- ptr
->rectClient
.top
);
184 else tmp
= CreateRectRgn( 0, 0, ptr
->rectClient
.right
- ptr
->rectClient
.left
,
185 ptr
->rectClient
.bottom
- ptr
->rectClient
.top
);
186 CombineRgn( rgn
, rgn
, tmp
, RGN_AND
);
187 OffsetRgn( rgn
, ptr
->rectClient
.left
, ptr
->rectClient
.top
);
188 xoffset
+= ptr
->rectClient
.left
;
189 yoffset
+= ptr
->rectClient
.top
;
191 WIN_ReleaseWndPtr( ptr
);
192 /* make it relative to the target window again */
193 OffsetRgn( rgn
, -xoffset
, -yoffset
);
194 if (tmp
) DeleteObject( tmp
);
201 /***********************************************************************
204 * Compute the portion of 'rgn' that is covered by non-clipped siblings.
205 * This is the area that is covered from X point of view, but may still need
207 * 'rgn' must be relative to the client area of the parent of 'win'.
209 static int get_covered_region( WND
*win
, HRGN rgn
)
213 WND
*parent
, *ptr
= WIN_FindWndPtr( win
->hwndSelf
);
214 int xoffset
= 0, yoffset
= 0;
216 tmp
= CreateRectRgn( 0, 0, 0, 0 );
217 CombineRgn( tmp
, rgn
, 0, RGN_COPY
);
219 /* to make things easier we actually build the uncovered
220 * area by removing all siblings and then we subtract that
221 * from the total region to get the covered area */
224 if (!(ptr
->dwStyle
& WS_CLIPSIBLINGS
))
226 if (clip_children( ptr
->parent
, ptr
->hwndSelf
, tmp
, FALSE
) == NULLREGION
) break;
228 if (!(parent
= WIN_FindWndPtr( ptr
->parent
))) break;
229 WIN_ReleaseWndPtr( ptr
);
231 OffsetRgn( tmp
, ptr
->rectClient
.left
, ptr
->rectClient
.top
);
232 xoffset
+= ptr
->rectClient
.left
;
233 yoffset
+= ptr
->rectClient
.top
;
235 WIN_ReleaseWndPtr( ptr
);
236 /* make it relative to the target window again */
237 OffsetRgn( tmp
, -xoffset
, -yoffset
);
239 /* now subtract the computed region from the original one */
240 ret
= CombineRgn( rgn
, rgn
, tmp
, RGN_DIFF
);
246 /***********************************************************************
249 * Expose a region of a given window.
251 static void expose_window( HWND hwnd
, RECT
*rect
, HRGN rgn
, int flags
)
258 /* find the top most parent that doesn't clip children or siblings and
259 * invalidate the area on its parent, including all children */
260 if ((list
= WIN_ListParents( hwnd
)))
263 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
264 for (i
= 0; list
[i
] && list
[i
] != GetDesktopWindow(); i
++)
266 if (!(style
& WS_CLIPSIBLINGS
)) top
= current
;
267 style
= GetWindowLongW( list
[i
], GWL_STYLE
);
268 if (!(style
& WS_CLIPCHILDREN
)) top
= current
;
274 /* find the parent of the top window, reusing the parent list */
275 if (top
== hwnd
) i
= 0;
278 for (i
= 0; list
[i
]; i
++) if (list
[i
] == top
) break;
279 if (list
[i
] && list
[i
+1]) i
++;
281 if (list
[i
] != GetDesktopWindow()) top
= list
[i
];
282 flags
&= ~RDW_FRAME
; /* parent will invalidate children frame anyway */
283 flags
|= RDW_ALLCHILDREN
;
285 HeapFree( GetProcessHeap(), 0, list
);
288 if (!top
) top
= hwnd
;
290 /* make coords relative to top */
291 offset
.x
= offset
.y
= 0;
292 MapWindowPoints( hwnd
, top
, &offset
, 1 );
296 OffsetRect( rect
, offset
.x
, offset
.y
);
297 RedrawWindow( top
, rect
, 0, flags
);
301 OffsetRgn( rgn
, offset
.x
, offset
.y
);
302 RedrawWindow( top
, NULL
, rgn
, flags
);
307 /***********************************************************************
308 * expose_covered_parent_area
310 * Expose the parent area that has been uncovered by moving/hiding a
311 * given window, but that is still covered by other siblings (the area
312 * not covered by siblings will be exposed automatically by X).
314 static void expose_covered_parent_area( WND
*win
, const RECT
*old_rect
)
316 int ret
= SIMPLEREGION
;
317 HRGN hrgn
= CreateRectRgnIndirect( old_rect
);
319 if (win
->dwStyle
& WS_VISIBLE
)
321 HRGN tmp
= CreateRectRgnIndirect( &win
->rectWindow
);
322 ret
= CombineRgn( hrgn
, hrgn
, tmp
, RGN_DIFF
);
326 if (ret
!= NULLREGION
)
328 if (get_covered_region( win
, hrgn
) != NULLREGION
)
329 expose_window( win
->parent
, NULL
, hrgn
, RDW_INVALIDATE
| RDW_ERASE
| RDW_ALLCHILDREN
);
331 DeleteObject( hrgn
);
335 /***********************************************************************
336 * expose_covered_window_area
338 * Expose the area of a window that is covered by other siblings.
340 static void expose_covered_window_area( WND
*win
, const RECT
*old_client_rect
, BOOL frame
)
343 int ret
= SIMPLEREGION
;
346 hrgn
= CreateRectRgn( win
->rectWindow
.left
- win
->rectClient
.left
,
347 win
->rectWindow
.top
- win
->rectClient
.top
,
348 win
->rectWindow
.right
- win
->rectWindow
.left
,
349 win
->rectWindow
.bottom
- win
->rectWindow
.top
);
351 hrgn
= CreateRectRgn( 0, 0,
352 win
->rectClient
.right
- win
->rectClient
.left
,
353 win
->rectClient
.bottom
- win
->rectClient
.top
);
355 /* if the client rect didn't move we don't need to repaint it all */
356 if (old_client_rect
->left
== win
->rectClient
.left
&&
357 old_client_rect
->top
== win
->rectClient
.top
)
361 if (IntersectRect( &rc
, old_client_rect
, &win
->rectClient
))
364 /* subtract the unchanged client area from the region to expose */
365 OffsetRect( &rc
, -win
->rectClient
.left
, -win
->rectClient
.top
);
366 if ((tmp
= CreateRectRgnIndirect( &rc
)))
368 ret
= CombineRgn( hrgn
, hrgn
, tmp
, RGN_DIFF
);
374 if (ret
!= NULLREGION
)
376 if (get_covered_region( win
, hrgn
) != NULLREGION
)
377 expose_window( win
->hwndSelf
, NULL
, hrgn
,
378 RDW_INVALIDATE
| RDW_ERASE
| RDW_FRAME
| RDW_ALLCHILDREN
);
381 DeleteObject( hrgn
);
385 /***********************************************************************
388 void X11DRV_Expose( HWND hwnd
, XExposeEvent
*event
)
391 struct x11drv_win_data
*data
;
392 int flags
= RDW_INVALIDATE
| RDW_ERASE
;
395 TRACE( "win %p (%lx) %d,%d %dx%d\n",
396 hwnd
, event
->window
, event
->x
, event
->y
, event
->width
, event
->height
);
398 rect
.left
= event
->x
;
400 rect
.right
= rect
.left
+ event
->width
;
401 rect
.bottom
= rect
.top
+ event
->height
;
403 if (!(win
= WIN_GetPtr( hwnd
))) return;
404 data
= win
->pDriverData
;
406 if (event
->window
!= data
->client_window
) /* whole window or icon window */
409 /* make position relative to client area instead of window */
410 OffsetRect( &rect
, -data
->client_rect
.left
, -data
->client_rect
.top
);
412 WIN_ReleasePtr( win
);
414 expose_window( hwnd
, &rect
, 0, flags
);
418 /***********************************************************************
421 * Set the drawable, origin and dimensions for the DC associated to
424 BOOL
X11DRV_GetDC( HWND hwnd
, HDC hdc
, HRGN hrgn
, DWORD flags
)
426 WND
*win
= WIN_GetPtr( hwnd
);
428 X11DRV_WND_DATA
*data
= win
->pDriverData
;
431 POINT org
, drawable_org
;
432 int mode
= IncludeInferiors
;
434 /* don't clip siblings if using parent clip region */
435 if (flags
& DCX_PARENTCLIP
) flags
&= ~DCX_CLIPSIBLINGS
;
437 /* find the top parent in the hierarchy that isn't clipping siblings */
438 visible
= (win
->dwStyle
& WS_VISIBLE
) != 0;
442 HWND
*list
= WIN_ListParents( hwnd
);
446 for (i
= 0; list
[i
] != GetDesktopWindow(); i
++)
448 LONG style
= GetWindowLongW( list
[i
], GWL_STYLE
);
449 if (!(style
& WS_VISIBLE
))
455 if (!(style
& WS_CLIPSIBLINGS
)) top
= list
[i
];
457 HeapFree( GetProcessHeap(), 0, list
);
459 if (!top
&& visible
&& !(flags
& DCX_CLIPSIBLINGS
)) top
= hwnd
;
464 HWND parent
= GetAncestor( top
, GA_PARENT
);
466 if (flags
& DCX_WINDOW
)
468 org
.x
= win
->rectWindow
.left
- win
->rectClient
.left
;
469 org
.y
= win
->rectWindow
.top
- win
->rectClient
.top
;
472 MapWindowPoints( hwnd
, parent
, &org
, 1 );
473 MapWindowPoints( hwnd
, 0, &drawable_org
, 1 );
474 /* have to use the parent so that we include siblings */
475 if (parent
) drawable
= X11DRV_get_client_window( parent
);
476 else drawable
= root_window
;
480 if (IsIconic( hwnd
))
482 drawable
= data
->icon_window
? data
->icon_window
: data
->whole_window
;
487 else if (flags
& DCX_WINDOW
)
489 drawable
= data
->whole_window
;
490 org
.x
= win
->rectWindow
.left
- data
->whole_rect
.left
;
491 org
.y
= win
->rectWindow
.top
- data
->whole_rect
.top
;
492 drawable_org
.x
= data
->whole_rect
.left
- win
->rectClient
.left
;
493 drawable_org
.y
= data
->whole_rect
.top
- win
->rectClient
.top
;
497 drawable
= data
->client_window
;
501 if (flags
& DCX_CLIPCHILDREN
) mode
= ClipByChildren
; /* can use X11 clipping */
503 MapWindowPoints( hwnd
, 0, &drawable_org
, 1 );
506 X11DRV_SetDrawable( hdc
, drawable
, mode
, &org
, &drawable_org
);
508 if (flags
& (DCX_EXCLUDERGN
| DCX_INTERSECTRGN
) ||
509 SetHookFlags16( HDC_16(hdc
), DCHF_VALIDATEVISRGN
)) /* DC was dirty */
511 /* need to recompute the visible region */
516 visRgn
= get_visible_region( win
, top
, flags
, mode
);
518 if (flags
& (DCX_EXCLUDERGN
| DCX_INTERSECTRGN
))
519 CombineRgn( visRgn
, visRgn
, hrgn
,
520 (flags
& DCX_INTERSECTRGN
) ? RGN_AND
: RGN_DIFF
);
522 else visRgn
= CreateRectRgn( 0, 0, 0, 0 );
524 SelectVisRgn16( HDC_16(hdc
), HRGN_16(visRgn
) );
525 DeleteObject( visRgn
);
528 WIN_ReleasePtr( win
);
533 /***********************************************************************
534 * ReleaseDC (X11DRV.@)
536 void X11DRV_ReleaseDC( HWND hwnd
, HDC hdc
)
541 X11DRV_SetDrawable( hdc
, root_window
, IncludeInferiors
, &org
, &org
);
545 /***********************************************************************
546 * SWP_DoWinPosChanging
548 static BOOL
SWP_DoWinPosChanging( WINDOWPOS
* pWinpos
, RECT
* pNewWindowRect
, RECT
* pNewClientRect
)
552 /* Send WM_WINDOWPOSCHANGING message */
554 if (!(pWinpos
->flags
& SWP_NOSENDCHANGING
))
555 SendMessageA( pWinpos
->hwnd
, WM_WINDOWPOSCHANGING
, 0, (LPARAM
)pWinpos
);
557 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return FALSE
;
559 /* Calculate new position and size */
561 *pNewWindowRect
= wndPtr
->rectWindow
;
562 *pNewClientRect
= (wndPtr
->dwStyle
& WS_MINIMIZE
) ? wndPtr
->rectWindow
563 : wndPtr
->rectClient
;
565 if (!(pWinpos
->flags
& SWP_NOSIZE
))
567 pNewWindowRect
->right
= pNewWindowRect
->left
+ pWinpos
->cx
;
568 pNewWindowRect
->bottom
= pNewWindowRect
->top
+ pWinpos
->cy
;
570 if (!(pWinpos
->flags
& SWP_NOMOVE
))
572 pNewWindowRect
->left
= pWinpos
->x
;
573 pNewWindowRect
->top
= pWinpos
->y
;
574 pNewWindowRect
->right
+= pWinpos
->x
- wndPtr
->rectWindow
.left
;
575 pNewWindowRect
->bottom
+= pWinpos
->y
- wndPtr
->rectWindow
.top
;
577 OffsetRect( pNewClientRect
, pWinpos
->x
- wndPtr
->rectWindow
.left
,
578 pWinpos
->y
- wndPtr
->rectWindow
.top
);
580 pWinpos
->flags
|= SWP_NOCLIENTMOVE
| SWP_NOCLIENTSIZE
;
581 WIN_ReleasePtr( wndPtr
);
585 /***********************************************************************
588 static UINT
SWP_DoNCCalcSize( WINDOWPOS
* pWinpos
, RECT
* pNewWindowRect
, RECT
* pNewClientRect
)
593 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
595 /* Send WM_NCCALCSIZE message to get new client area */
596 if( (pWinpos
->flags
& (SWP_FRAMECHANGED
| SWP_NOSIZE
)) != SWP_NOSIZE
)
598 NCCALCSIZE_PARAMS params
;
599 WINDOWPOS winposCopy
;
601 params
.rgrc
[0] = *pNewWindowRect
;
602 params
.rgrc
[1] = wndPtr
->rectWindow
;
603 params
.rgrc
[2] = wndPtr
->rectClient
;
604 params
.lppos
= &winposCopy
;
605 winposCopy
= *pWinpos
;
606 WIN_ReleasePtr( wndPtr
);
608 wvrFlags
= SendMessageW( pWinpos
->hwnd
, WM_NCCALCSIZE
, TRUE
, (LPARAM
)¶ms
);
610 TRACE( "(%ld,%ld)-(%ld,%ld)\n", params
.rgrc
[0].left
, params
.rgrc
[0].top
,
611 params
.rgrc
[0].right
, params
.rgrc
[0].bottom
);
613 /* If the application send back garbage, ignore it */
614 if (params
.rgrc
[0].left
<= params
.rgrc
[0].right
&&
615 params
.rgrc
[0].top
<= params
.rgrc
[0].bottom
)
616 *pNewClientRect
= params
.rgrc
[0];
618 /* FIXME: WVR_ALIGNxxx */
620 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
622 if( pNewClientRect
->left
!= wndPtr
->rectClient
.left
||
623 pNewClientRect
->top
!= wndPtr
->rectClient
.top
)
624 pWinpos
->flags
&= ~SWP_NOCLIENTMOVE
;
626 if( (pNewClientRect
->right
- pNewClientRect
->left
!=
627 wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
) ||
628 (pNewClientRect
->bottom
- pNewClientRect
->top
!=
629 wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
) )
630 pWinpos
->flags
&= ~SWP_NOCLIENTSIZE
;
634 if (!(pWinpos
->flags
& SWP_NOMOVE
) &&
635 (pNewClientRect
->left
!= wndPtr
->rectClient
.left
||
636 pNewClientRect
->top
!= wndPtr
->rectClient
.top
))
637 pWinpos
->flags
&= ~SWP_NOCLIENTMOVE
;
639 WIN_ReleasePtr( wndPtr
);
644 /***********************************************************************
647 * fix Z order taking into account owned popups -
648 * basically we need to maintain them above the window that owns them
650 * FIXME: hide/show owned popups when owner visibility changes.
652 static HWND
SWP_DoOwnedPopups(HWND hwnd
, HWND hwndInsertAfter
)
655 HWND owner
= GetWindow( hwnd
, GW_OWNER
);
656 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
658 WARN("(%p) hInsertAfter = %p\n", hwnd
, hwndInsertAfter
);
660 if ((style
& WS_POPUP
) && owner
)
662 /* make sure this popup stays above the owner */
664 HWND hwndLocalPrev
= HWND_TOP
;
666 if( hwndInsertAfter
!= HWND_TOP
)
668 if ((list
= WIN_ListChildren( GetDesktopWindow() )))
671 for (i
= 0; list
[i
]; i
++)
673 if (list
[i
] == owner
) break;
674 if (list
[i
] != hwnd
) hwndLocalPrev
= list
[i
];
675 if (hwndLocalPrev
== hwndInsertAfter
) break;
677 hwndInsertAfter
= hwndLocalPrev
;
681 else if (style
& WS_CHILD
) return hwndInsertAfter
;
683 if (!list
) list
= WIN_ListChildren( GetDesktopWindow() );
687 for (i
= 0; list
[i
]; i
++)
689 if (list
[i
] == hwnd
) break;
690 if ((GetWindowLongW( list
[i
], GWL_STYLE
) & WS_POPUP
) &&
691 GetWindow( list
[i
], GW_OWNER
) == hwnd
)
693 SetWindowPos( list
[i
], hwndInsertAfter
, 0, 0, 0, 0,
694 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
|
695 SWP_NOSENDCHANGING
| SWP_DEFERERASE
);
696 hwndInsertAfter
= list
[i
];
699 HeapFree( GetProcessHeap(), 0, list
);
702 return hwndInsertAfter
;
706 /* fix redundant flags and values in the WINDOWPOS structure */
707 static BOOL
fixup_flags( WINDOWPOS
*winpos
)
709 WND
*wndPtr
= WIN_GetPtr( winpos
->hwnd
);
712 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
)
714 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
717 winpos
->hwnd
= wndPtr
->hwndSelf
; /* make it a full handle */
719 if (wndPtr
->dwStyle
& WS_VISIBLE
) winpos
->flags
&= ~SWP_SHOWWINDOW
;
722 winpos
->flags
&= ~SWP_HIDEWINDOW
;
723 if (!(winpos
->flags
& SWP_SHOWWINDOW
)) winpos
->flags
|= SWP_NOREDRAW
;
726 if (winpos
->cx
< 0) winpos
->cx
= 0;
727 if (winpos
->cy
< 0) winpos
->cy
= 0;
729 if ((wndPtr
->rectWindow
.right
- wndPtr
->rectWindow
.left
== winpos
->cx
) &&
730 (wndPtr
->rectWindow
.bottom
- wndPtr
->rectWindow
.top
== winpos
->cy
))
731 winpos
->flags
|= SWP_NOSIZE
; /* Already the right size */
733 if ((wndPtr
->rectWindow
.left
== winpos
->x
) && (wndPtr
->rectWindow
.top
== winpos
->y
))
734 winpos
->flags
|= SWP_NOMOVE
; /* Already the right position */
736 if (winpos
->hwnd
== GetForegroundWindow())
737 winpos
->flags
|= SWP_NOACTIVATE
; /* Already active */
738 else if ((wndPtr
->dwStyle
& (WS_POPUP
| WS_CHILD
)) != WS_CHILD
)
740 if (!(winpos
->flags
& SWP_NOACTIVATE
)) /* Bring to the top when activating */
742 winpos
->flags
&= ~SWP_NOZORDER
;
743 winpos
->hwndInsertAfter
= HWND_TOP
;
748 /* Check hwndInsertAfter */
749 if (winpos
->flags
& SWP_NOZORDER
) goto done
;
751 /* fix sign extension */
752 if (winpos
->hwndInsertAfter
== (HWND
)0xffff) winpos
->hwndInsertAfter
= HWND_TOPMOST
;
753 else if (winpos
->hwndInsertAfter
== (HWND
)0xfffe) winpos
->hwndInsertAfter
= HWND_NOTOPMOST
;
755 /* FIXME: TOPMOST not supported yet */
756 if ((winpos
->hwndInsertAfter
== HWND_TOPMOST
) ||
757 (winpos
->hwndInsertAfter
== HWND_NOTOPMOST
)) winpos
->hwndInsertAfter
= HWND_TOP
;
759 /* hwndInsertAfter must be a sibling of the window */
760 if ((winpos
->hwndInsertAfter
!= HWND_TOP
) && (winpos
->hwndInsertAfter
!= HWND_BOTTOM
))
762 if (GetAncestor( winpos
->hwndInsertAfter
, GA_PARENT
) != wndPtr
->parent
) ret
= FALSE
;
765 /* don't need to change the Zorder of hwnd if it's already inserted
766 * after hwndInsertAfter or when inserting hwnd after itself.
768 if ((winpos
->hwnd
== winpos
->hwndInsertAfter
) ||
769 (winpos
->hwnd
== GetWindow( winpos
->hwndInsertAfter
, GW_HWNDNEXT
)))
770 winpos
->flags
|= SWP_NOZORDER
;
774 WIN_ReleasePtr( wndPtr
);
779 /***********************************************************************
782 * Set/clear the WS_VISIBLE style of a window and map/unmap the X window.
784 static void set_visible_style( HWND hwnd
, BOOL set
)
788 if (!(win
= WIN_GetPtr( hwnd
))) return;
789 if (win
== WND_OTHER_PROCESS
) return;
791 TRACE( "hwnd %p (%lx) set %d visible %d empty %d\n",
792 hwnd
, get_whole_window(win
),
793 set
, (win
->dwStyle
& WS_VISIBLE
) != 0, IsRectEmpty(&win
->rectWindow
) );
797 if (win
->dwStyle
& WS_VISIBLE
) goto done
;
798 WIN_SetStyle( hwnd
, win
->dwStyle
| WS_VISIBLE
);
799 if (!IsRectEmpty( &win
->rectWindow
) && get_whole_window(win
) && is_window_top_level(win
))
801 Display
*display
= thread_display();
802 X11DRV_sync_window_style( display
, win
);
803 X11DRV_set_wm_hints( display
, win
);
804 TRACE( "mapping win %p\n", hwnd
);
805 TSXMapWindow( display
, get_whole_window(win
) );
810 if (!(win
->dwStyle
& WS_VISIBLE
)) goto done
;
811 WIN_SetStyle( hwnd
, win
->dwStyle
& ~WS_VISIBLE
);
812 if (!IsRectEmpty( &win
->rectWindow
) && get_whole_window(win
) && is_window_top_level(win
))
814 TRACE( "unmapping win %p\n", hwnd
);
815 TSXUnmapWindow( thread_display(), get_whole_window(win
) );
819 WIN_ReleasePtr( win
);
823 /***********************************************************************
824 * SetWindowStyle (X11DRV.@)
826 * Update the X state of a window to reflect a style change
828 void X11DRV_SetWindowStyle( HWND hwnd
, LONG oldStyle
)
830 Display
*display
= thread_display();
834 if (hwnd
== GetDesktopWindow()) return;
835 if (!(wndPtr
= WIN_GetPtr( hwnd
))) return;
836 if (wndPtr
== WND_OTHER_PROCESS
) return;
838 changed
= wndPtr
->dwStyle
^ oldStyle
;
840 if (changed
& WS_VISIBLE
)
842 if (!IsRectEmpty( &wndPtr
->rectWindow
) && !is_window_top_level(wndPtr
))
844 if (wndPtr
->dwStyle
& WS_VISIBLE
)
846 TRACE( "mapping win %p\n", hwnd
);
847 TSXMapWindow( display
, get_whole_window(wndPtr
) );
851 TRACE( "unmapping win %p\n", hwnd
);
852 TSXUnmapWindow( display
, get_whole_window(wndPtr
) );
857 if (changed
& WS_DISABLED
)
859 if (wndPtr
->dwExStyle
& WS_EX_MANAGED
)
863 if (!(wm_hints
= XGetWMHints( display
, get_whole_window(wndPtr
) )))
864 wm_hints
= XAllocWMHints();
867 wm_hints
->flags
|= InputHint
;
868 wm_hints
->input
= !(wndPtr
->dwStyle
& WS_DISABLED
);
869 XSetWMHints( display
, get_whole_window(wndPtr
), wm_hints
);
875 WIN_ReleasePtr(wndPtr
);
879 /***********************************************************************
880 * SetWindowPos (X11DRV.@)
882 BOOL
X11DRV_SetWindowPos( WINDOWPOS
*winpos
)
885 RECT newWindowRect
, newClientRect
;
886 RECT oldWindowRect
, oldClientRect
;
890 TRACE( "hwnd %p, swp (%i,%i)-(%i,%i) flags %08x\n",
891 winpos
->hwnd
, winpos
->x
, winpos
->y
,
892 winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
, winpos
->flags
);
894 bChangePos
= !(winpos
->flags
& SWP_WINE_NOHOSTMOVE
);
895 winpos
->flags
&= ~SWP_WINE_NOHOSTMOVE
;
897 /* Fix redundant flags */
898 if (!fixup_flags( winpos
)) return FALSE
;
900 /* Check window handle */
901 if (winpos
->hwnd
== GetDesktopWindow()) return FALSE
;
903 SWP_DoWinPosChanging( winpos
, &newWindowRect
, &newClientRect
);
905 if (!(wndPtr
= WIN_FindWndPtr( winpos
->hwnd
))) return FALSE
;
907 TRACE("\tcurrent (%ld,%ld)-(%ld,%ld), style %08x\n",
908 wndPtr
->rectWindow
.left
, wndPtr
->rectWindow
.top
,
909 wndPtr
->rectWindow
.right
, wndPtr
->rectWindow
.bottom
, (unsigned)wndPtr
->dwStyle
);
911 if((winpos
->flags
& (SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_SHOWWINDOW
)) != SWP_NOZORDER
)
913 if (GetAncestor( winpos
->hwnd
, GA_PARENT
) == GetDesktopWindow())
914 winpos
->hwndInsertAfter
= SWP_DoOwnedPopups( winpos
->hwnd
, winpos
->hwndInsertAfter
);
917 /* Common operations */
919 wvrFlags
= SWP_DoNCCalcSize( winpos
, &newWindowRect
, &newClientRect
);
921 if(!(winpos
->flags
& SWP_NOZORDER
) && winpos
->hwnd
!= winpos
->hwndInsertAfter
)
923 HWND parent
= GetAncestor( winpos
->hwnd
, GA_PARENT
);
924 if (parent
) WIN_LinkWindow( winpos
->hwnd
, parent
, winpos
->hwndInsertAfter
);
927 /* Reset active DCEs */
929 if( (((winpos
->flags
& SWP_AGG_NOPOSCHANGE
) != SWP_AGG_NOPOSCHANGE
) &&
930 wndPtr
->dwStyle
& WS_VISIBLE
) ||
931 (winpos
->flags
& (SWP_HIDEWINDOW
| SWP_SHOWWINDOW
)) )
935 UnionRect(&rect
, &newWindowRect
, &wndPtr
->rectWindow
);
936 DCE_InvalidateDCE(wndPtr
->hwndSelf
, &rect
);
939 oldWindowRect
= wndPtr
->rectWindow
;
940 oldClientRect
= wndPtr
->rectClient
;
942 /* Find out if we have to redraw the whole client rect */
944 if( oldClientRect
.bottom
- oldClientRect
.top
==
945 newClientRect
.bottom
- newClientRect
.top
) wvrFlags
&= ~WVR_VREDRAW
;
947 if( oldClientRect
.right
- oldClientRect
.left
==
948 newClientRect
.right
- newClientRect
.left
) wvrFlags
&= ~WVR_HREDRAW
;
950 /* FIXME: actually do something with WVR_VALIDRECTS */
952 WIN_SetRectangles( winpos
->hwnd
, &newWindowRect
, &newClientRect
);
954 if (get_whole_window(wndPtr
)) /* don't do anything if X window not created yet */
956 Display
*display
= thread_display();
958 if (!(winpos
->flags
& SWP_SHOWWINDOW
) && (winpos
->flags
& SWP_HIDEWINDOW
))
960 /* clear the update region */
961 RedrawWindow( winpos
->hwnd
, NULL
, 0, RDW_VALIDATE
| RDW_NOFRAME
|
962 RDW_NOERASE
| RDW_NOINTERNALPAINT
| RDW_ALLCHILDREN
);
963 set_visible_style( winpos
->hwnd
, FALSE
);
965 else if ((wndPtr
->dwStyle
& WS_VISIBLE
) &&
966 !IsRectEmpty( &oldWindowRect
) && IsRectEmpty( &newWindowRect
))
968 /* resizing to zero size -> unmap */
969 TRACE( "unmapping zero size win %p\n", winpos
->hwnd
);
970 TSXUnmapWindow( display
, get_whole_window(wndPtr
) );
975 X11DRV_sync_whole_window_position( display
, wndPtr
, !(winpos
->flags
& SWP_NOZORDER
) );
978 struct x11drv_win_data
*data
= wndPtr
->pDriverData
;
979 data
->whole_rect
= wndPtr
->rectWindow
;
980 X11DRV_window_to_X_rect( wndPtr
, &data
->whole_rect
);
983 if (X11DRV_sync_client_window_position( display
, wndPtr
) ||
984 (winpos
->flags
& SWP_FRAMECHANGED
))
986 /* if we moved the client area, repaint the whole non-client window */
987 XClearArea( display
, get_whole_window(wndPtr
), 0, 0, 0, 0, True
);
988 winpos
->flags
|= SWP_FRAMECHANGED
;
990 if (winpos
->flags
& SWP_SHOWWINDOW
)
992 set_visible_style( winpos
->hwnd
, TRUE
);
994 else if ((wndPtr
->dwStyle
& WS_VISIBLE
) &&
995 IsRectEmpty( &oldWindowRect
) && !IsRectEmpty( &newWindowRect
))
997 /* resizing from zero size to non-zero -> map */
998 TRACE( "mapping non zero size win %p\n", winpos
->hwnd
);
999 XMapWindow( display
, get_whole_window(wndPtr
) );
1001 XFlush( display
); /* FIXME: should not be necessary */
1002 wine_tsx11_unlock();
1004 else /* no X window, simply toggle the window style */
1006 if (winpos
->flags
& SWP_SHOWWINDOW
)
1007 set_visible_style( winpos
->hwnd
, TRUE
);
1008 else if (winpos
->flags
& SWP_HIDEWINDOW
)
1009 set_visible_style( winpos
->hwnd
, FALSE
);
1012 /* manually expose the areas that X won't expose because they are still covered by something */
1014 if (!(winpos
->flags
& SWP_SHOWWINDOW
))
1015 expose_covered_parent_area( wndPtr
, &oldWindowRect
);
1017 if (wndPtr
->dwStyle
& WS_VISIBLE
)
1018 expose_covered_window_area( wndPtr
, &oldClientRect
, winpos
->flags
& SWP_FRAMECHANGED
);
1020 WIN_ReleaseWndPtr(wndPtr
);
1022 if (wvrFlags
& WVR_REDRAW
) RedrawWindow( winpos
->hwnd
, NULL
, 0, RDW_INVALIDATE
| RDW_ERASE
);
1024 if( winpos
->flags
& SWP_HIDEWINDOW
)
1025 HideCaret(winpos
->hwnd
);
1026 else if (winpos
->flags
& SWP_SHOWWINDOW
)
1027 ShowCaret(winpos
->hwnd
);
1029 if (!(winpos
->flags
& SWP_NOACTIVATE
))
1031 /* child windows get WM_CHILDACTIVATE message */
1032 if ((GetWindowLongW( winpos
->hwnd
, GWL_STYLE
) & (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
1033 SendMessageA( winpos
->hwnd
, WM_CHILDACTIVATE
, 0, 0 );
1035 SetForegroundWindow( winpos
->hwnd
);
1038 /* And last, send the WM_WINDOWPOSCHANGED message */
1040 TRACE("\tstatus flags = %04x\n", winpos
->flags
& SWP_AGG_STATUSFLAGS
);
1042 if (((winpos
->flags
& SWP_AGG_STATUSFLAGS
) != SWP_AGG_NOPOSCHANGE
))
1043 SendMessageA( winpos
->hwnd
, WM_WINDOWPOSCHANGED
, 0, (LPARAM
)winpos
);
1044 /* WM_WINDOWPOSCHANGED is send even if SWP_NOSENDCHANGING is set */
1050 /***********************************************************************
1051 * WINPOS_FindIconPos
1053 * Find a suitable place for an iconic window.
1055 static POINT
WINPOS_FindIconPos( WND
* wndPtr
, POINT pt
)
1059 short x
, y
, xspacing
, yspacing
;
1061 GetClientRect( wndPtr
->parent
, &rectParent
);
1062 if ((pt
.x
>= rectParent
.left
) && (pt
.x
+ GetSystemMetrics(SM_CXICON
) < rectParent
.right
) &&
1063 (pt
.y
>= rectParent
.top
) && (pt
.y
+ GetSystemMetrics(SM_CYICON
) < rectParent
.bottom
))
1064 return pt
; /* The icon already has a suitable position */
1066 xspacing
= GetSystemMetrics(SM_CXICONSPACING
);
1067 yspacing
= GetSystemMetrics(SM_CYICONSPACING
);
1069 list
= WIN_ListChildren( wndPtr
->parent
);
1070 y
= rectParent
.bottom
;
1073 x
= rectParent
.left
;
1076 /* Check if another icon already occupies this spot */
1077 /* FIXME: this is completely inefficient */
1083 for (i
= 0; list
[i
]; i
++)
1085 if (list
[i
] == wndPtr
->hwndSelf
) continue;
1086 if (!IsIconic( list
[i
] )) continue;
1087 if (!(childPtr
= WIN_FindWndPtr( list
[i
] ))) continue;
1088 if ((childPtr
->rectWindow
.left
< x
+ xspacing
) &&
1089 (childPtr
->rectWindow
.right
>= x
) &&
1090 (childPtr
->rectWindow
.top
<= y
) &&
1091 (childPtr
->rectWindow
.bottom
> y
- yspacing
))
1093 WIN_ReleaseWndPtr( childPtr
);
1094 break; /* There's a window in there */
1096 WIN_ReleaseWndPtr( childPtr
);
1100 /* found something here, try next spot */
1106 /* No window was found, so it's OK for us */
1107 pt
.x
= x
+ (xspacing
- GetSystemMetrics(SM_CXICON
)) / 2;
1108 pt
.y
= y
- (yspacing
+ GetSystemMetrics(SM_CYICON
)) / 2;
1109 HeapFree( GetProcessHeap(), 0, list
);
1112 } while(x
<= rectParent
.right
-xspacing
);
1121 UINT
WINPOS_MinMaximize( HWND hwnd
, UINT cmd
, LPRECT rect
)
1127 WINDOWPLACEMENT wpl
;
1129 TRACE("%p %u\n", hwnd
, cmd
);
1131 wpl
.length
= sizeof(wpl
);
1132 GetWindowPlacement( hwnd
, &wpl
);
1134 if (HOOK_CallHooks( WH_CBT
, HCBT_MINMAX
, (WPARAM
)hwnd
, cmd
, TRUE
))
1135 return SWP_NOSIZE
| SWP_NOMOVE
;
1137 if (IsIconic( hwnd
))
1139 if (cmd
== SW_MINIMIZE
) return SWP_NOSIZE
| SWP_NOMOVE
;
1140 if (!SendMessageA( hwnd
, WM_QUERYOPEN
, 0, 0 )) return SWP_NOSIZE
| SWP_NOMOVE
;
1141 swpFlags
|= SWP_NOCOPYBITS
;
1144 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return 0;
1146 size
.x
= wndPtr
->rectWindow
.left
;
1147 size
.y
= wndPtr
->rectWindow
.top
;
1152 if( wndPtr
->dwStyle
& WS_MAXIMIZE
) wndPtr
->flags
|= WIN_RESTORE_MAX
;
1153 else wndPtr
->flags
&= ~WIN_RESTORE_MAX
;
1155 WIN_SetStyle( hwnd
, (wndPtr
->dwStyle
& ~WS_MAXIMIZE
) | WS_MINIMIZE
);
1157 X11DRV_set_iconic_state( wndPtr
);
1159 wpl
.ptMinPosition
= WINPOS_FindIconPos( wndPtr
, wpl
.ptMinPosition
);
1161 SetRect( rect
, wpl
.ptMinPosition
.x
, wpl
.ptMinPosition
.y
,
1162 GetSystemMetrics(SM_CXICON
), GetSystemMetrics(SM_CYICON
) );
1163 swpFlags
|= SWP_NOCOPYBITS
;
1167 WINPOS_GetMinMaxInfo( hwnd
, &size
, &wpl
.ptMaxPosition
, NULL
, NULL
);
1169 old_style
= WIN_SetStyle( hwnd
, (wndPtr
->dwStyle
& ~WS_MINIMIZE
) | WS_MAXIMIZE
);
1170 if (old_style
& WS_MINIMIZE
)
1172 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1173 X11DRV_set_iconic_state( wndPtr
);
1175 SetRect( rect
, wpl
.ptMaxPosition
.x
, wpl
.ptMaxPosition
.y
, size
.x
, size
.y
);
1179 old_style
= WIN_SetStyle( hwnd
, wndPtr
->dwStyle
& ~(WS_MINIMIZE
|WS_MAXIMIZE
) );
1180 if (old_style
& WS_MINIMIZE
)
1182 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1183 X11DRV_set_iconic_state( wndPtr
);
1185 if( wndPtr
->flags
& WIN_RESTORE_MAX
)
1187 /* Restore to maximized position */
1188 WINPOS_GetMinMaxInfo( hwnd
, &size
, &wpl
.ptMaxPosition
, NULL
, NULL
);
1189 WIN_SetStyle( hwnd
, wndPtr
->dwStyle
| WS_MAXIMIZE
);
1190 SetRect( rect
, wpl
.ptMaxPosition
.x
, wpl
.ptMaxPosition
.y
, size
.x
, size
.y
);
1194 else if (!(old_style
& WS_MAXIMIZE
)) break;
1196 /* Restore to normal position */
1198 *rect
= wpl
.rcNormalPosition
;
1199 rect
->right
-= rect
->left
;
1200 rect
->bottom
-= rect
->top
;
1205 WIN_ReleaseWndPtr( wndPtr
);
1210 /***********************************************************************
1211 * ShowWindow (X11DRV.@)
1213 BOOL
X11DRV_ShowWindow( HWND hwnd
, INT cmd
)
1215 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
1216 BOOL wasVisible
, showFlag
;
1217 RECT newPos
= {0, 0, 0, 0};
1220 if (!wndPtr
) return FALSE
;
1221 hwnd
= wndPtr
->hwndSelf
; /* make it a full handle */
1223 TRACE("hwnd=%p, cmd=%d\n", hwnd
, cmd
);
1225 wasVisible
= (wndPtr
->dwStyle
& WS_VISIBLE
) != 0;
1230 if (!wasVisible
) goto END
;
1231 swp
|= SWP_HIDEWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
|
1232 SWP_NOACTIVATE
| SWP_NOZORDER
;
1235 case SW_SHOWMINNOACTIVE
:
1236 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1238 case SW_SHOWMINIMIZED
:
1239 case SW_FORCEMINIMIZE
: /* FIXME: Does not work if thread is hung. */
1240 swp
|= SWP_SHOWWINDOW
;
1243 swp
|= SWP_FRAMECHANGED
;
1244 if( !(wndPtr
->dwStyle
& WS_MINIMIZE
) )
1245 swp
|= WINPOS_MinMaximize( hwnd
, SW_MINIMIZE
, &newPos
);
1246 else swp
|= SWP_NOSIZE
| SWP_NOMOVE
;
1249 case SW_SHOWMAXIMIZED
: /* same as SW_MAXIMIZE */
1250 swp
|= SWP_SHOWWINDOW
| SWP_FRAMECHANGED
;
1251 if( !(wndPtr
->dwStyle
& WS_MAXIMIZE
) )
1252 swp
|= WINPOS_MinMaximize( hwnd
, SW_MAXIMIZE
, &newPos
);
1253 else swp
|= SWP_NOSIZE
| SWP_NOMOVE
;
1257 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1260 swp
|= SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
1263 * ShowWindow has a little peculiar behavior that if the
1264 * window is already the topmost window, it will not
1267 if (GetTopWindow(NULL
)==hwnd
&& (wasVisible
|| GetActiveWindow() == hwnd
))
1268 swp
|= SWP_NOACTIVATE
;
1272 case SW_SHOWNOACTIVATE
:
1273 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1275 case SW_SHOWNORMAL
: /* same as SW_NORMAL: */
1276 case SW_SHOWDEFAULT
: /* FIXME: should have its own handler */
1278 swp
|= SWP_SHOWWINDOW
| SWP_FRAMECHANGED
;
1280 if( wndPtr
->dwStyle
& (WS_MINIMIZE
| WS_MAXIMIZE
) )
1281 swp
|= WINPOS_MinMaximize( hwnd
, SW_RESTORE
, &newPos
);
1282 else swp
|= SWP_NOSIZE
| SWP_NOMOVE
;
1286 showFlag
= (cmd
!= SW_HIDE
);
1287 if (showFlag
!= wasVisible
)
1289 SendMessageA( hwnd
, WM_SHOWWINDOW
, showFlag
, 0 );
1290 if (!IsWindow( hwnd
)) goto END
;
1293 /* We can't activate a child window */
1294 if ((wndPtr
->dwStyle
& WS_CHILD
) &&
1295 !(wndPtr
->dwExStyle
& WS_EX_MDICHILD
))
1296 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1298 SetWindowPos( hwnd
, HWND_TOP
, newPos
.left
, newPos
.top
,
1299 newPos
.right
, newPos
.bottom
, LOWORD(swp
) );
1302 /* FIXME: This will cause the window to be activated irrespective
1303 * of whether it is owned by the same thread. Has to be done
1307 if (hwnd
== GetActiveWindow())
1308 WINPOS_ActivateOtherWindow(hwnd
);
1310 /* Revert focus to parent */
1311 if (hwnd
== GetFocus() || IsChild(hwnd
, GetFocus()))
1312 SetFocus( GetParent(hwnd
) );
1314 if (!IsWindow( hwnd
)) goto END
;
1315 else if( wndPtr
->dwStyle
& WS_MINIMIZE
) WINPOS_ShowIconTitle( hwnd
, TRUE
);
1317 if (wndPtr
->flags
& WIN_NEED_SIZE
)
1319 /* should happen only in CreateWindowEx() */
1320 int wParam
= SIZE_RESTORED
;
1322 wndPtr
->flags
&= ~WIN_NEED_SIZE
;
1323 if (wndPtr
->dwStyle
& WS_MAXIMIZE
) wParam
= SIZE_MAXIMIZED
;
1324 else if (wndPtr
->dwStyle
& WS_MINIMIZE
) wParam
= SIZE_MINIMIZED
;
1325 SendMessageA( hwnd
, WM_SIZE
, wParam
,
1326 MAKELONG(wndPtr
->rectClient
.right
-wndPtr
->rectClient
.left
,
1327 wndPtr
->rectClient
.bottom
-wndPtr
->rectClient
.top
));
1328 SendMessageA( hwnd
, WM_MOVE
, 0,
1329 MAKELONG(wndPtr
->rectClient
.left
, wndPtr
->rectClient
.top
) );
1333 WIN_ReleaseWndPtr(wndPtr
);
1338 /**********************************************************************
1341 void X11DRV_MapNotify( HWND hwnd
, XMapEvent
*event
)
1343 HWND hwndFocus
= GetFocus();
1346 if (!(win
= WIN_GetPtr( hwnd
))) return;
1348 if ((win
->dwStyle
& WS_VISIBLE
) &&
1349 (win
->dwStyle
& WS_MINIMIZE
) &&
1350 (win
->dwExStyle
& WS_EX_MANAGED
))
1353 unsigned int width
, height
, border
, depth
;
1356 LONG style
= (win
->dwStyle
& ~(WS_MINIMIZE
|WS_MAXIMIZE
)) | WS_VISIBLE
;
1360 XGetGeometry( event
->display
, get_whole_window(win
), &root
, &x
, &y
, &width
, &height
,
1362 XTranslateCoordinates( event
->display
, get_whole_window(win
), root
, 0, 0, &x
, &y
, &top
);
1363 wine_tsx11_unlock();
1366 rect
.right
= x
+ width
;
1367 rect
.bottom
= y
+ height
;
1368 X11DRV_X_to_window_rect( win
, &rect
);
1370 DCE_InvalidateDCE( hwnd
, &win
->rectWindow
);
1372 if (win
->flags
& WIN_RESTORE_MAX
) style
|= WS_MAXIMIZE
;
1373 WIN_SetStyle( hwnd
, style
);
1374 WIN_ReleasePtr( win
);
1376 SendMessageA( hwnd
, WM_SHOWWINDOW
, SW_RESTORE
, 0 );
1377 SetWindowPos( hwnd
, 0, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
,
1378 SWP_NOZORDER
| SWP_WINE_NOHOSTMOVE
);
1380 else WIN_ReleasePtr( win
);
1381 if (hwndFocus
&& IsChild( hwnd
, hwndFocus
)) X11DRV_SetFocus(hwndFocus
); /* FIXME */
1385 /**********************************************************************
1386 * X11DRV_UnmapNotify
1388 void X11DRV_UnmapNotify( HWND hwnd
, XUnmapEvent
*event
)
1392 if (!(win
= WIN_GetPtr( hwnd
))) return;
1394 if ((win
->dwStyle
& WS_VISIBLE
) && (win
->dwExStyle
& WS_EX_MANAGED
))
1396 if (win
->dwStyle
& WS_MAXIMIZE
)
1397 win
->flags
|= WIN_RESTORE_MAX
;
1399 win
->flags
&= ~WIN_RESTORE_MAX
;
1401 WIN_SetStyle( hwnd
, (win
->dwStyle
& ~WS_MAXIMIZE
) | WS_MINIMIZE
);
1402 WIN_ReleasePtr( win
);
1405 SendMessageA( hwnd
, WM_SHOWWINDOW
, SW_MINIMIZE
, 0 );
1406 SetWindowPos( hwnd
, 0, 0, 0, GetSystemMetrics(SM_CXICON
), GetSystemMetrics(SM_CYICON
),
1407 SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_WINE_NOHOSTMOVE
);
1409 else WIN_ReleasePtr( win
);
1413 /***********************************************************************
1416 * Synchronize internal z-order with the window manager's.
1418 static Window
__get_common_ancestor( Display
*display
, Window A
, Window B
,
1419 Window
** children
, unsigned* total
)
1421 /* find the real root window */
1423 Window root
, *childrenB
;
1426 while( A
!= B
&& A
&& B
)
1428 TSXQueryTree( display
, A
, &root
, &A
, children
, total
);
1429 TSXQueryTree( display
, B
, &root
, &B
, &childrenB
, &totalB
);
1430 if( childrenB
) TSXFree( childrenB
);
1431 if( *children
) TSXFree( *children
), *children
= NULL
;
1436 TSXQueryTree( display
, A
, &root
, &B
, children
, total
);
1442 static Window
__get_top_decoration( Display
*display
, Window w
, Window ancestor
)
1444 Window
* children
, root
, prev
= w
, parent
= w
;
1450 TSXQueryTree( display
, w
, &root
, &parent
, &children
, &total
);
1451 if( children
) TSXFree( children
);
1452 } while( parent
&& parent
!= ancestor
);
1453 TRACE("\t%08x -> %08x\n", (unsigned)prev
, (unsigned)w
);
1454 return ( parent
) ? w
: 0 ;
1457 static unsigned __td_lookup( Window w
, Window
* list
, unsigned max
)
1460 for( i
= max
; i
> 0; i
-- ) if( list
[i
- 1] == w
) break;
1464 static HWND
query_zorder( Display
*display
, HWND hWndCheck
)
1466 HWND hwndInsertAfter
= HWND_TOP
;
1467 Window w
, parent
, *children
= NULL
;
1468 unsigned total
, check
, pos
, best
;
1469 HWND
*list
= WIN_ListChildren( GetDesktopWindow() );
1470 HWND hwndA
= 0, hwndB
= 0;
1473 /* find at least two managed windows */
1474 if (!list
) return 0;
1475 for (i
= 0; list
[i
]; i
++)
1477 if (!(GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_MANAGED
)) continue;
1478 if (!(GetWindowLongW( list
[i
], GWL_STYLE
) & WS_VISIBLE
)) continue;
1479 if (!hwndA
) hwndA
= list
[i
];
1486 if (!hwndA
|| !hwndB
) goto done
;
1488 parent
= __get_common_ancestor( display
, X11DRV_get_whole_window(hwndA
),
1489 X11DRV_get_whole_window(hwndB
), &children
, &total
);
1490 if( parent
&& children
)
1492 /* w is the ancestor if hWndCheck that is a direct descendant of 'parent' */
1494 w
= __get_top_decoration( display
, X11DRV_get_whole_window(hWndCheck
), parent
);
1496 if( w
!= children
[total
-1] ) /* check if at the top */
1498 /* X child at index 0 is at the bottom, at index total-1 is at the top */
1499 check
= __td_lookup( w
, children
, total
);
1502 /* go through all windows in Wine z-order... */
1503 for (i
= 0; list
[i
]; i
++)
1505 if (list
[i
] == hWndCheck
) continue;
1506 if (!(GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_MANAGED
)) continue;
1507 if (!(w
= __get_top_decoration( display
, X11DRV_get_whole_window(list
[i
]),
1508 parent
))) continue;
1509 pos
= __td_lookup( w
, children
, total
);
1510 if( pos
< best
&& pos
> check
)
1512 /* find a nearest Wine window precedes hWndCheck in the real z-order */
1514 hwndInsertAfter
= list
[i
];
1516 if( best
- check
== 1 ) break;
1520 if( children
) TSXFree( children
);
1523 HeapFree( GetProcessHeap(), 0, list
);
1524 return hwndInsertAfter
;
1528 /***********************************************************************
1529 * X11DRV_ConfigureNotify
1531 void X11DRV_ConfigureNotify( HWND hwnd
, XConfigureEvent
*event
)
1533 HWND oldInsertAfter
;
1534 struct x11drv_win_data
*data
;
1538 int x
= event
->x
, y
= event
->y
;
1540 if (!(win
= WIN_GetPtr( hwnd
))) return;
1541 data
= win
->pDriverData
;
1545 if (!event
->send_event
) /* normal event, need to map coordinates to the root */
1549 XTranslateCoordinates( event
->display
, data
->whole_window
, root_window
,
1550 0, 0, &x
, &y
, &child
);
1551 wine_tsx11_unlock();
1555 rect
.right
= x
+ event
->width
;
1556 rect
.bottom
= y
+ event
->height
;
1557 TRACE( "win %p new X rect %ld,%ld,%ldx%ld (event %d,%d,%dx%d)\n",
1558 hwnd
, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
,
1559 event
->x
, event
->y
, event
->width
, event
->height
);
1560 X11DRV_X_to_window_rect( win
, &rect
);
1561 WIN_ReleasePtr( win
);
1564 winpos
.x
= rect
.left
;
1565 winpos
.y
= rect
.top
;
1566 winpos
.cx
= rect
.right
- rect
.left
;
1567 winpos
.cy
= rect
.bottom
- rect
.top
;
1568 winpos
.flags
= SWP_NOACTIVATE
;
1570 /* Get Z-order (FIXME) */
1572 winpos
.hwndInsertAfter
= query_zorder( event
->display
, hwnd
);
1574 /* needs to find the first Visible Window above the current one */
1575 oldInsertAfter
= hwnd
;
1578 oldInsertAfter
= GetWindow( oldInsertAfter
, GW_HWNDPREV
);
1579 if (!oldInsertAfter
)
1581 oldInsertAfter
= HWND_TOP
;
1584 if (GetWindowLongA( oldInsertAfter
, GWL_STYLE
) & WS_VISIBLE
) break;
1587 /* Compare what has changed */
1589 GetWindowRect( hwnd
, &rect
);
1590 if (rect
.left
== winpos
.x
&& rect
.top
== winpos
.y
) winpos
.flags
|= SWP_NOMOVE
;
1592 TRACE( "%p moving from (%ld,%ld) to (%d,%d)\n",
1593 hwnd
, rect
.left
, rect
.top
, winpos
.x
, winpos
.y
);
1595 if ((rect
.right
- rect
.left
== winpos
.cx
&& rect
.bottom
- rect
.top
== winpos
.cy
) ||
1597 (IsRectEmpty( &rect
) && winpos
.cx
== 1 && winpos
.cy
== 1))
1598 winpos
.flags
|= SWP_NOSIZE
;
1600 TRACE( "%p resizing from (%ldx%ld) to (%dx%d)\n",
1601 hwnd
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
1602 winpos
.cx
, winpos
.cy
);
1604 if (winpos
.hwndInsertAfter
== oldInsertAfter
) winpos
.flags
|= SWP_NOZORDER
;
1606 TRACE( "%p restacking from after %p to after %p\n",
1607 hwnd
, oldInsertAfter
, winpos
.hwndInsertAfter
);
1609 /* if nothing changed, don't do anything */
1610 if (winpos
.flags
== (SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
)) return;
1612 SetWindowPos( hwnd
, winpos
.hwndInsertAfter
, winpos
.x
, winpos
.y
,
1613 winpos
.cx
, winpos
.cy
, winpos
.flags
| SWP_WINE_NOHOSTMOVE
);
1617 /***********************************************************************
1618 * SetWindowRgn (X11DRV.@)
1620 * Assign specified region to window (for non-rectangular windows)
1622 int X11DRV_SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL redraw
)
1626 if ((wndPtr
= WIN_GetPtr( hwnd
)) == WND_OTHER_PROCESS
)
1628 if (IsWindow( hwnd
))
1629 FIXME( "not supported on other process window %p\n", hwnd
);
1634 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
1638 if (wndPtr
->hrgnWnd
== hrgn
)
1640 WIN_ReleasePtr( wndPtr
);
1644 if (wndPtr
->hrgnWnd
)
1646 /* delete previous region */
1647 DeleteObject(wndPtr
->hrgnWnd
);
1648 wndPtr
->hrgnWnd
= 0;
1650 wndPtr
->hrgnWnd
= hrgn
;
1652 #ifdef HAVE_LIBXSHAPE
1654 Display
*display
= thread_display();
1655 X11DRV_WND_DATA
*data
= wndPtr
->pDriverData
;
1657 if (data
->whole_window
)
1662 XShapeCombineMask( display
, data
->whole_window
,
1663 ShapeBounding
, 0, 0, None
, ShapeSet
);
1664 wine_tsx11_unlock();
1669 int x_offset
, y_offset
;
1671 DWORD dwBufferSize
= GetRegionData(hrgn
, 0, NULL
);
1672 PRGNDATA pRegionData
= HeapAlloc(GetProcessHeap(), 0, dwBufferSize
);
1675 WIN_ReleasePtr( wndPtr
);
1678 GetRegionData(hrgn
, dwBufferSize
, pRegionData
);
1679 size
= pRegionData
->rdh
.nCount
;
1680 x_offset
= wndPtr
->rectWindow
.left
- data
->whole_rect
.left
;
1681 y_offset
= wndPtr
->rectWindow
.top
- data
->whole_rect
.top
;
1682 /* convert region's "Windows rectangles" to XRectangles */
1683 aXRect
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(*aXRect
) );
1686 XRectangle
* pCurrRect
= aXRect
;
1687 RECT
*pRect
= (RECT
*) pRegionData
->Buffer
;
1688 for (; pRect
< ((RECT
*) pRegionData
->Buffer
) + size
; ++pRect
, ++pCurrRect
)
1690 pCurrRect
->x
= pRect
->left
+ x_offset
;
1691 pCurrRect
->y
= pRect
->top
+ y_offset
;
1692 pCurrRect
->height
= pRect
->bottom
- pRect
->top
;
1693 pCurrRect
->width
= pRect
->right
- pRect
->left
;
1695 TRACE("Rectangle %04d of %04ld data: X=%04d, Y=%04d, Height=%04d, Width=%04d.\n",
1696 pRect
- (RECT
*) pRegionData
->Buffer
,
1704 /* shape = non-rectangular windows (X11/extensions) */
1706 XShapeCombineRectangles( display
, data
->whole_window
, ShapeBounding
,
1708 pCurrRect
- aXRect
, ShapeSet
, YXBanded
);
1709 wine_tsx11_unlock();
1710 HeapFree(GetProcessHeap(), 0, aXRect
);
1712 HeapFree(GetProcessHeap(), 0, pRegionData
);
1716 #endif /* HAVE_LIBXSHAPE */
1718 WIN_ReleasePtr( wndPtr
);
1719 if (redraw
) RedrawWindow( hwnd
, NULL
, 0, RDW_FRAME
| RDW_INVALIDATE
| RDW_ERASE
);
1724 /***********************************************************************
1727 * Draw the frame used when moving or resizing window.
1729 * FIXME: This causes problems in Win95 mode. (why?)
1731 static void draw_moving_frame( HDC hdc
, RECT
*rect
, BOOL thickframe
)
1735 const int width
= GetSystemMetrics(SM_CXFRAME
);
1736 const int height
= GetSystemMetrics(SM_CYFRAME
);
1738 HBRUSH hbrush
= SelectObject( hdc
, GetStockObject( GRAY_BRUSH
) );
1739 PatBlt( hdc
, rect
->left
, rect
->top
,
1740 rect
->right
- rect
->left
- width
, height
, PATINVERT
);
1741 PatBlt( hdc
, rect
->left
, rect
->top
+ height
, width
,
1742 rect
->bottom
- rect
->top
- height
, PATINVERT
);
1743 PatBlt( hdc
, rect
->left
+ width
, rect
->bottom
- 1,
1744 rect
->right
- rect
->left
- width
, -height
, PATINVERT
);
1745 PatBlt( hdc
, rect
->right
- 1, rect
->top
, -width
,
1746 rect
->bottom
- rect
->top
- height
, PATINVERT
);
1747 SelectObject( hdc
, hbrush
);
1749 else DrawFocusRect( hdc
, rect
);
1753 /***********************************************************************
1756 * Initialisation of a move or resize, when initiatied from a menu choice.
1757 * Return hit test code for caption or sizing border.
1759 static LONG
start_size_move( HWND hwnd
, WPARAM wParam
, POINT
*capturePoint
, LONG style
)
1766 GetWindowRect( hwnd
, &rectWindow
);
1768 if ((wParam
& 0xfff0) == SC_MOVE
)
1770 /* Move pointer at the center of the caption */
1772 NC_GetInsideRect( hwnd
, &rect
);
1773 if (style
& WS_SYSMENU
)
1774 rect
.left
+= GetSystemMetrics(SM_CXSIZE
) + 1;
1775 if (style
& WS_MINIMIZEBOX
)
1776 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
1777 if (style
& WS_MAXIMIZEBOX
)
1778 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
1779 pt
.x
= rectWindow
.left
+ (rect
.right
- rect
.left
) / 2;
1780 pt
.y
= rectWindow
.top
+ rect
.top
+ GetSystemMetrics(SM_CYSIZE
)/2;
1781 hittest
= HTCAPTION
;
1788 GetMessageW( &msg
, 0, WM_KEYFIRST
, WM_MOUSELAST
);
1789 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
1794 hittest
= NC_HandleNCHitTest( hwnd
, msg
.pt
);
1795 if ((hittest
< HTLEFT
) || (hittest
> HTBOTTOMRIGHT
))
1807 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
1808 pt
.y
= rectWindow
.top
+ GetSystemMetrics(SM_CYFRAME
) / 2;
1812 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
1813 pt
.y
= rectWindow
.bottom
- GetSystemMetrics(SM_CYFRAME
) / 2;
1817 pt
.x
= rectWindow
.left
+ GetSystemMetrics(SM_CXFRAME
) / 2;
1818 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
1822 pt
.x
= rectWindow
.right
- GetSystemMetrics(SM_CXFRAME
) / 2;
1823 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
1826 case VK_ESCAPE
: return 0;
1832 SetCursorPos( pt
.x
, pt
.y
);
1833 NC_HandleSetCursor( hwnd
, (WPARAM
)hwnd
, MAKELONG( hittest
, WM_MOUSEMOVE
));
1838 /***********************************************************************
1839 * set_movesize_capture
1841 static void set_movesize_capture( HWND hwnd
)
1845 SERVER_START_REQ( set_capture_window
)
1848 req
->flags
= CAPTURE_MOVESIZE
;
1849 if (!wine_server_call_err( req
))
1851 previous
= reply
->previous
;
1852 hwnd
= reply
->full_handle
;
1856 if (previous
&& previous
!= hwnd
)
1857 SendMessageW( previous
, WM_CAPTURECHANGED
, 0, (LPARAM
)hwnd
);
1861 /***********************************************************************
1862 * SysCommandSizeMove (X11DRV.@)
1864 * Perform SC_MOVE and SC_SIZE commands.
1866 void X11DRV_SysCommandSizeMove( HWND hwnd
, WPARAM wParam
)
1869 RECT sizingRect
, mouseRect
, origRect
;
1872 LONG hittest
= (LONG
)(wParam
& 0x0f);
1873 HCURSOR hDragCursor
= 0, hOldCursor
= 0;
1874 POINT minTrack
, maxTrack
;
1875 POINT capturePoint
, pt
;
1876 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
1877 LONG exstyle
= GetWindowLongA( hwnd
, GWL_EXSTYLE
);
1878 BOOL thickframe
= HAS_THICKFRAME( style
, exstyle
);
1879 BOOL iconic
= style
& WS_MINIMIZE
;
1881 DWORD dwPoint
= GetMessagePos ();
1882 BOOL DragFullWindows
= FALSE
;
1885 Display
*old_gdi_display
= NULL
;
1886 Display
*display
= thread_display();
1888 SystemParametersInfoA(SPI_GETDRAGFULLWINDOWS
, 0, &DragFullWindows
, 0);
1890 pt
.x
= SLOWORD(dwPoint
);
1891 pt
.y
= SHIWORD(dwPoint
);
1894 if (IsZoomed(hwnd
) || !IsWindowVisible(hwnd
) || (exstyle
& WS_EX_MANAGED
)) return;
1896 if ((wParam
& 0xfff0) == SC_MOVE
)
1898 if (!hittest
) hittest
= start_size_move( hwnd
, wParam
, &capturePoint
, style
);
1899 if (!hittest
) return;
1903 if (!thickframe
) return;
1904 if ( hittest
&& ((wParam
& 0xfff0) != SC_MOUSEMENU
) )
1905 hittest
+= (HTLEFT
- WMSZ_LEFT
);
1908 set_movesize_capture( hwnd
);
1909 hittest
= start_size_move( hwnd
, wParam
, &capturePoint
, style
);
1912 set_movesize_capture(0);
1918 /* Get min/max info */
1920 WINPOS_GetMinMaxInfo( hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
1921 GetWindowRect( hwnd
, &sizingRect
);
1922 if (style
& WS_CHILD
)
1924 parent
= GetParent(hwnd
);
1925 /* make sizing rect relative to parent */
1926 MapWindowPoints( 0, parent
, (POINT
*)&sizingRect
, 2 );
1927 GetClientRect( parent
, &mouseRect
);
1932 SetRect(&mouseRect
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
));
1934 origRect
= sizingRect
;
1936 if (ON_LEFT_BORDER(hittest
))
1938 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.right
-maxTrack
.x
);
1939 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.right
-minTrack
.x
);
1941 else if (ON_RIGHT_BORDER(hittest
))
1943 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.left
+minTrack
.x
);
1944 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.left
+maxTrack
.x
);
1946 if (ON_TOP_BORDER(hittest
))
1948 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.bottom
-maxTrack
.y
);
1949 mouseRect
.bottom
= min( mouseRect
.bottom
,sizingRect
.bottom
-minTrack
.y
);
1951 else if (ON_BOTTOM_BORDER(hittest
))
1953 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.top
+minTrack
.y
);
1954 mouseRect
.bottom
= min( mouseRect
.bottom
, sizingRect
.top
+maxTrack
.y
);
1956 if (parent
) MapWindowPoints( parent
, 0, (LPPOINT
)&mouseRect
, 2 );
1958 /* Retrieve a default cache DC (without using the window style) */
1959 hdc
= GetDCEx( parent
, 0, DCX_CACHE
);
1961 if( iconic
) /* create a cursor for dragging */
1963 hDragCursor
= (HCURSOR
)GetClassLongA( hwnd
, GCL_HICON
);
1964 if( !hDragCursor
) hDragCursor
= (HCURSOR
)SendMessageA( hwnd
, WM_QUERYDRAGICON
, 0, 0L);
1965 if( !hDragCursor
) iconic
= FALSE
;
1968 /* repaint the window before moving it around */
1969 RedrawWindow( hwnd
, NULL
, 0, RDW_UPDATENOW
| RDW_ALLCHILDREN
);
1971 SendMessageA( hwnd
, WM_ENTERSIZEMOVE
, 0, 0 );
1972 set_movesize_capture( hwnd
);
1974 /* grab the server only when moving top-level windows without desktop */
1975 grab
= (!DragFullWindows
&& !parent
&& (root_window
== DefaultRootWindow(gdi_display
)));
1980 XSync( gdi_display
, False
);
1981 XGrabServer( display
);
1982 XSync( display
, False
);
1983 /* switch gdi display to the thread display, since the server is grabbed */
1984 old_gdi_display
= gdi_display
;
1985 gdi_display
= display
;
1987 XGrabPointer( display
, X11DRV_get_whole_window(hwnd
), False
,
1988 PointerMotionMask
| ButtonPressMask
| ButtonReleaseMask
,
1989 GrabModeAsync
, GrabModeAsync
,
1990 parent
? X11DRV_get_client_window(parent
) : root_window
,
1991 None
, CurrentTime
);
1992 wine_tsx11_unlock();
1998 if (!GetMessageW( &msg
, 0, WM_KEYFIRST
, WM_MOUSELAST
)) break;
1999 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
2001 /* Exit on button-up, Return, or Esc */
2002 if ((msg
.message
== WM_LBUTTONUP
) ||
2003 ((msg
.message
== WM_KEYDOWN
) &&
2004 ((msg
.wParam
== VK_RETURN
) || (msg
.wParam
== VK_ESCAPE
)))) break;
2006 if ((msg
.message
!= WM_KEYDOWN
) && (msg
.message
!= WM_MOUSEMOVE
))
2007 continue; /* We are not interested in other messages */
2011 if (msg
.message
== WM_KEYDOWN
) switch(msg
.wParam
)
2013 case VK_UP
: pt
.y
-= 8; break;
2014 case VK_DOWN
: pt
.y
+= 8; break;
2015 case VK_LEFT
: pt
.x
-= 8; break;
2016 case VK_RIGHT
: pt
.x
+= 8; break;
2019 pt
.x
= max( pt
.x
, mouseRect
.left
);
2020 pt
.x
= min( pt
.x
, mouseRect
.right
);
2021 pt
.y
= max( pt
.y
, mouseRect
.top
);
2022 pt
.y
= min( pt
.y
, mouseRect
.bottom
);
2024 dx
= pt
.x
- capturePoint
.x
;
2025 dy
= pt
.y
- capturePoint
.y
;
2033 if( iconic
) /* ok, no system popup tracking */
2035 hOldCursor
= SetCursor(hDragCursor
);
2037 WINPOS_ShowIconTitle( hwnd
, FALSE
);
2039 else if(!DragFullWindows
)
2040 draw_moving_frame( hdc
, &sizingRect
, thickframe
);
2043 if (msg
.message
== WM_KEYDOWN
) SetCursorPos( pt
.x
, pt
.y
);
2046 RECT newRect
= sizingRect
;
2047 WPARAM wpSizingHit
= 0;
2049 if (hittest
== HTCAPTION
) OffsetRect( &newRect
, dx
, dy
);
2050 if (ON_LEFT_BORDER(hittest
)) newRect
.left
+= dx
;
2051 else if (ON_RIGHT_BORDER(hittest
)) newRect
.right
+= dx
;
2052 if (ON_TOP_BORDER(hittest
)) newRect
.top
+= dy
;
2053 else if (ON_BOTTOM_BORDER(hittest
)) newRect
.bottom
+= dy
;
2054 if(!iconic
&& !DragFullWindows
) draw_moving_frame( hdc
, &sizingRect
, thickframe
);
2057 /* determine the hit location */
2058 if (hittest
>= HTLEFT
&& hittest
<= HTBOTTOMRIGHT
)
2059 wpSizingHit
= WMSZ_LEFT
+ (hittest
- HTLEFT
);
2060 SendMessageA( hwnd
, WM_SIZING
, wpSizingHit
, (LPARAM
)&newRect
);
2064 if(!DragFullWindows
)
2065 draw_moving_frame( hdc
, &newRect
, thickframe
);
2067 /* To avoid any deadlocks, all the locks on the windows
2068 structures must be suspended before the SetWindowPos */
2069 iWndsLocks
= WIN_SuspendWndsLock();
2070 SetWindowPos( hwnd
, 0, newRect
.left
, newRect
.top
,
2071 newRect
.right
- newRect
.left
,
2072 newRect
.bottom
- newRect
.top
,
2073 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
2074 WIN_RestoreWndsLock(iWndsLocks
);
2077 sizingRect
= newRect
;
2082 set_movesize_capture(0);
2085 if( moved
) /* restore cursors, show icon title later on */
2087 ShowCursor( FALSE
);
2088 SetCursor( hOldCursor
);
2091 else if (moved
&& !DragFullWindows
)
2092 draw_moving_frame( hdc
, &sizingRect
, thickframe
);
2094 ReleaseDC( parent
, hdc
);
2097 XUngrabPointer( display
, CurrentTime
);
2100 XSync( display
, False
);
2101 XUngrabServer( display
);
2102 XSync( display
, False
);
2103 gdi_display
= old_gdi_display
;
2105 wine_tsx11_unlock();
2107 if (HOOK_CallHooks( WH_CBT
, HCBT_MOVESIZE
, (WPARAM
)hwnd
, (LPARAM
)&sizingRect
, TRUE
))
2110 SendMessageA( hwnd
, WM_EXITSIZEMOVE
, 0, 0 );
2111 SendMessageA( hwnd
, WM_SETVISIBLE
, !IsIconic(hwnd
), 0L);
2113 /* window moved or resized */
2116 /* To avoid any deadlocks, all the locks on the windows
2117 structures must be suspended before the SetWindowPos */
2118 iWndsLocks
= WIN_SuspendWndsLock();
2120 /* if the moving/resizing isn't canceled call SetWindowPos
2121 * with the new position or the new size of the window
2123 if (!((msg
.message
== WM_KEYDOWN
) && (msg
.wParam
== VK_ESCAPE
)) )
2125 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
2126 if(!DragFullWindows
)
2127 SetWindowPos( hwnd
, 0, sizingRect
.left
, sizingRect
.top
,
2128 sizingRect
.right
- sizingRect
.left
,
2129 sizingRect
.bottom
- sizingRect
.top
,
2130 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
2133 { /* restore previous size/position */
2135 SetWindowPos( hwnd
, 0, origRect
.left
, origRect
.top
,
2136 origRect
.right
- origRect
.left
,
2137 origRect
.bottom
- origRect
.top
,
2138 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
2141 WIN_RestoreWndsLock(iWndsLocks
);
2146 /* Single click brings up the system menu when iconized */
2150 if(style
& WS_SYSMENU
)
2151 SendMessageA( hwnd
, WM_SYSCOMMAND
,
2152 SC_MOUSEMENU
+ HTSYSMENU
, MAKELONG(pt
.x
,pt
.y
));
2154 else WINPOS_ShowIconTitle( hwnd
, TRUE
);
2159 /***********************************************************************
2160 * ForceWindowRaise (X11DRV.@)
2162 * Raise a window on top of the X stacking order, while preserving
2163 * the correct Windows Z order.
2165 * FIXME: this should go away.
2167 void X11DRV_ForceWindowRaise( HWND hwnd
)
2171 XWindowChanges winChanges
;
2172 Display
*display
= thread_display();
2173 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
2175 if (!wndPtr
) return;
2177 if ((wndPtr
->dwExStyle
& WS_EX_MANAGED
) ||
2178 wndPtr
->parent
!= GetDesktopWindow() ||
2179 IsRectEmpty( &wndPtr
->rectWindow
) ||
2180 !get_whole_window(wndPtr
))
2182 WIN_ReleaseWndPtr( wndPtr
);
2185 WIN_ReleaseWndPtr( wndPtr
);
2187 /* Raise all windows up to wndPtr according to their Z order.
2188 * (it would be easier with sibling-related Below but it doesn't
2189 * work very well with SGI mwm for instance)
2191 winChanges
.stack_mode
= Above
;
2192 if (!(list
= WIN_ListChildren( GetDesktopWindow() ))) return;
2193 while (list
[i
] && list
[i
] != hwnd
) i
++;
2196 for ( ; i
>= 0; i
--)
2198 WND
*ptr
= WIN_FindWndPtr( list
[i
] );
2200 if (!IsRectEmpty( &ptr
->rectWindow
) && get_whole_window(ptr
))
2201 TSXReconfigureWMWindow( display
, get_whole_window(ptr
), 0,
2202 CWStackMode
, &winChanges
);
2203 WIN_ReleaseWndPtr( ptr
);
2206 HeapFree( GetProcessHeap(), 0, list
);