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"
44 #include "wine/server.h"
45 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(x11drv
);
49 #define SWP_AGG_NOGEOMETRYCHANGE \
50 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE)
51 #define SWP_AGG_NOPOSCHANGE \
52 (SWP_AGG_NOGEOMETRYCHANGE | SWP_NOZORDER)
53 #define SWP_AGG_STATUSFLAGS \
54 (SWP_AGG_NOPOSCHANGE | SWP_FRAMECHANGED | SWP_HIDEWINDOW | SWP_SHOWWINDOW)
56 #define SWP_EX_NOCOPY 0x0001
57 #define SWP_EX_PAINTSELF 0x0002
58 #define SWP_EX_NONCLIENT 0x0004
60 #define HAS_THICKFRAME(style,exStyle) \
61 (((style) & WS_THICKFRAME) && \
62 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
64 #define ON_LEFT_BORDER(hit) \
65 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
66 #define ON_RIGHT_BORDER(hit) \
67 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
68 #define ON_TOP_BORDER(hit) \
69 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
70 #define ON_BOTTOM_BORDER(hit) \
71 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
74 /***********************************************************************
77 * Clip all children of a given window out of the visible region
79 static int clip_children( HWND parent
, HWND last
, HRGN hrgn
, int whole_window
)
84 int i
, x
, y
, ret
= SIMPLEREGION
;
86 /* first check if we have anything to do */
87 if (!(list
= WIN_ListChildren( parent
))) return ret
;
88 for (i
= 0; list
[i
] && list
[i
] != last
; i
++)
89 if (GetWindowLongW( list
[i
], GWL_STYLE
) & WS_VISIBLE
) break;
90 if (!list
[i
] || list
[i
] == last
) goto done
; /* no children to clip */
94 WND
*win
= WIN_FindWndPtr( parent
);
95 x
= win
->rectWindow
.left
- win
->rectClient
.left
;
96 y
= win
->rectWindow
.top
- win
->rectClient
.top
;
97 WIN_ReleaseWndPtr( win
);
101 rectRgn
= CreateRectRgn( 0, 0, 0, 0 );
103 for ( ; list
[i
] && list
[i
] != last
; i
++)
105 if (!(ptr
= WIN_FindWndPtr( list
[i
] ))) continue;
106 if (ptr
->dwStyle
& WS_VISIBLE
)
108 SetRectRgn( rectRgn
, ptr
->rectWindow
.left
+ x
, ptr
->rectWindow
.top
+ y
,
109 ptr
->rectWindow
.right
+ x
, ptr
->rectWindow
.bottom
+ y
);
110 if ((ret
= CombineRgn( hrgn
, hrgn
, rectRgn
, RGN_DIFF
)) == NULLREGION
)
112 WIN_ReleaseWndPtr( ptr
);
113 break; /* no need to go on, region is empty */
116 WIN_ReleaseWndPtr( ptr
);
118 DeleteObject( rectRgn
);
120 HeapFree( GetProcessHeap(), 0, list
);
125 /***********************************************************************
128 * Compute the visible region of a window
130 static HRGN
get_visible_region( WND
*win
, HWND top
, UINT flags
, int mode
)
134 int xoffset
, yoffset
;
135 X11DRV_WND_DATA
*data
= win
->pDriverData
;
137 if (flags
& DCX_WINDOW
)
139 xoffset
= win
->rectWindow
.left
;
140 yoffset
= win
->rectWindow
.top
;
144 xoffset
= win
->rectClient
.left
;
145 yoffset
= win
->rectClient
.top
;
148 if (flags
& DCX_PARENTCLIP
)
149 GetClientRect( win
->parent
, &rect
);
150 else if (flags
& DCX_WINDOW
)
151 rect
= data
->whole_rect
;
153 rect
= win
->rectClient
;
155 /* vis region is relative to the start of the client/window area */
156 OffsetRect( &rect
, -xoffset
, -yoffset
);
158 if (!(rgn
= CreateRectRgn( rect
.left
, rect
.top
, rect
.right
, rect
.bottom
))) return 0;
160 if ((flags
& DCX_CLIPCHILDREN
) && (mode
!= ClipByChildren
))
162 /* we need to clip children by hand */
163 if (clip_children( win
->hwndSelf
, 0, rgn
, (flags
& DCX_WINDOW
) ) == NULLREGION
) return rgn
;
166 if (top
&& top
!= win
->hwndSelf
) /* need to clip siblings of ancestors */
168 WND
*parent
, *ptr
= WIN_FindWndPtr( win
->hwndSelf
);
171 OffsetRgn( rgn
, xoffset
, yoffset
);
174 if (ptr
->dwStyle
& WS_CLIPSIBLINGS
)
176 if (clip_children( ptr
->parent
, ptr
->hwndSelf
, rgn
, FALSE
) == NULLREGION
) break;
178 if (ptr
->hwndSelf
== top
) break;
179 if (!(parent
= WIN_FindWndPtr( ptr
->parent
))) break;
180 WIN_ReleaseWndPtr( ptr
);
182 /* clip to parent client area */
183 if (tmp
) SetRectRgn( tmp
, 0, 0, ptr
->rectClient
.right
- ptr
->rectClient
.left
,
184 ptr
->rectClient
.bottom
- ptr
->rectClient
.top
);
185 else tmp
= CreateRectRgn( 0, 0, ptr
->rectClient
.right
- ptr
->rectClient
.left
,
186 ptr
->rectClient
.bottom
- ptr
->rectClient
.top
);
187 CombineRgn( rgn
, rgn
, tmp
, RGN_AND
);
188 OffsetRgn( rgn
, ptr
->rectClient
.left
, ptr
->rectClient
.top
);
189 xoffset
+= ptr
->rectClient
.left
;
190 yoffset
+= ptr
->rectClient
.top
;
192 WIN_ReleaseWndPtr( ptr
);
193 /* make it relative to the target window again */
194 OffsetRgn( rgn
, -xoffset
, -yoffset
);
195 if (tmp
) DeleteObject( tmp
);
202 /***********************************************************************
205 * Compute the portion of 'rgn' that is covered by non-clipped siblings.
206 * This is the area that is covered from X point of view, but may still need
208 * 'rgn' must be relative to the client area of the parent of 'win'.
210 static int get_covered_region( WND
*win
, HRGN rgn
)
214 WND
*parent
, *ptr
= WIN_FindWndPtr( win
->hwndSelf
);
215 int xoffset
= 0, yoffset
= 0;
217 tmp
= CreateRectRgn( 0, 0, 0, 0 );
218 CombineRgn( tmp
, rgn
, 0, RGN_COPY
);
220 /* to make things easier we actually build the uncovered
221 * area by removing all siblings and then we subtract that
222 * from the total region to get the covered area */
225 if (!(ptr
->dwStyle
& WS_CLIPSIBLINGS
))
227 if (clip_children( ptr
->parent
, ptr
->hwndSelf
, tmp
, FALSE
) == NULLREGION
) break;
229 if (!(parent
= WIN_FindWndPtr( ptr
->parent
))) break;
230 WIN_ReleaseWndPtr( ptr
);
232 OffsetRgn( tmp
, ptr
->rectClient
.left
, ptr
->rectClient
.top
);
233 xoffset
+= ptr
->rectClient
.left
;
234 yoffset
+= ptr
->rectClient
.top
;
236 WIN_ReleaseWndPtr( ptr
);
237 /* make it relative to the target window again */
238 OffsetRgn( tmp
, -xoffset
, -yoffset
);
240 /* now subtract the computed region from the original one */
241 ret
= CombineRgn( rgn
, rgn
, tmp
, RGN_DIFF
);
247 /***********************************************************************
250 * Expose a region of a given window.
252 static void expose_window( HWND hwnd
, RECT
*rect
, HRGN rgn
, int flags
)
259 /* find the top most parent that doesn't clip children or siblings and
260 * invalidate the area on its parent, including all children */
261 if ((list
= WIN_ListParents( hwnd
)))
264 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
265 for (i
= 0; list
[i
] && list
[i
] != GetDesktopWindow(); i
++)
267 if (!(style
& WS_CLIPSIBLINGS
)) top
= current
;
268 style
= GetWindowLongW( list
[i
], GWL_STYLE
);
269 if (!(style
& WS_CLIPCHILDREN
)) top
= current
;
275 /* find the parent of the top window, reusing the parent list */
276 if (top
== hwnd
) i
= 0;
279 for (i
= 0; list
[i
]; i
++) if (list
[i
] == top
) break;
280 if (list
[i
] && list
[i
+1]) i
++;
282 if (list
[i
] != GetDesktopWindow()) top
= list
[i
];
283 flags
&= ~RDW_FRAME
; /* parent will invalidate children frame anyway */
284 flags
|= RDW_ALLCHILDREN
;
286 HeapFree( GetProcessHeap(), 0, list
);
289 if (!top
) top
= hwnd
;
291 /* make coords relative to top */
292 offset
.x
= offset
.y
= 0;
293 MapWindowPoints( hwnd
, top
, &offset
, 1 );
297 OffsetRect( rect
, offset
.x
, offset
.y
);
298 RedrawWindow( top
, rect
, 0, flags
);
302 OffsetRgn( rgn
, offset
.x
, offset
.y
);
303 RedrawWindow( top
, NULL
, rgn
, flags
);
308 /***********************************************************************
309 * expose_covered_parent_area
311 * Expose the parent area that has been uncovered by moving/hiding a
312 * given window, but that is still covered by other siblings (the area
313 * not covered by siblings will be exposed automatically by X).
315 static void expose_covered_parent_area( WND
*win
, const RECT
*old_rect
)
317 int ret
= SIMPLEREGION
;
318 HRGN hrgn
= CreateRectRgnIndirect( old_rect
);
320 if (win
->dwStyle
& WS_VISIBLE
)
322 HRGN tmp
= CreateRectRgnIndirect( &win
->rectWindow
);
323 ret
= CombineRgn( hrgn
, hrgn
, tmp
, RGN_DIFF
);
327 if (ret
!= NULLREGION
)
329 if (get_covered_region( win
, hrgn
) != NULLREGION
)
330 expose_window( win
->parent
, NULL
, hrgn
, RDW_INVALIDATE
| RDW_ERASE
| RDW_ALLCHILDREN
);
332 DeleteObject( hrgn
);
336 /***********************************************************************
337 * expose_covered_window_area
339 * Expose the area of a window that is covered by other siblings.
341 static void expose_covered_window_area( WND
*win
, const RECT
*old_client_rect
, BOOL frame
)
344 int ret
= SIMPLEREGION
;
347 hrgn
= CreateRectRgn( win
->rectWindow
.left
- win
->rectClient
.left
,
348 win
->rectWindow
.top
- win
->rectClient
.top
,
349 win
->rectWindow
.right
- win
->rectWindow
.left
,
350 win
->rectWindow
.bottom
- win
->rectWindow
.top
);
352 hrgn
= CreateRectRgn( 0, 0,
353 win
->rectClient
.right
- win
->rectClient
.left
,
354 win
->rectClient
.bottom
- win
->rectClient
.top
);
356 /* if the client rect didn't move we don't need to repaint it all */
357 if (old_client_rect
->left
== win
->rectClient
.left
&&
358 old_client_rect
->top
== win
->rectClient
.top
)
362 if (IntersectRect( &rc
, old_client_rect
, &win
->rectClient
))
365 /* subtract the unchanged client area from the region to expose */
366 OffsetRect( &rc
, -win
->rectClient
.left
, -win
->rectClient
.top
);
367 if ((tmp
= CreateRectRgnIndirect( &rc
)))
369 ret
= CombineRgn( hrgn
, hrgn
, tmp
, RGN_DIFF
);
375 if (ret
!= NULLREGION
)
377 if (get_covered_region( win
, hrgn
) != NULLREGION
)
378 expose_window( win
->hwndSelf
, NULL
, hrgn
,
379 RDW_INVALIDATE
| RDW_ERASE
| RDW_FRAME
| RDW_ALLCHILDREN
);
382 DeleteObject( hrgn
);
386 /***********************************************************************
389 void X11DRV_Expose( HWND hwnd
, XExposeEvent
*event
)
392 struct x11drv_win_data
*data
;
393 int flags
= RDW_INVALIDATE
| RDW_ERASE
;
396 TRACE( "win %x (%lx) %d,%d %dx%d\n",
397 hwnd
, event
->window
, event
->x
, event
->y
, event
->width
, event
->height
);
399 rect
.left
= event
->x
;
401 rect
.right
= rect
.left
+ event
->width
;
402 rect
.bottom
= rect
.top
+ event
->height
;
404 if (!(win
= WIN_GetPtr( hwnd
))) return;
405 data
= win
->pDriverData
;
407 if (event
->window
!= data
->client_window
) /* whole window or icon window */
410 /* make position relative to client area instead of window */
411 OffsetRect( &rect
, -data
->client_rect
.left
, -data
->client_rect
.top
);
413 WIN_ReleasePtr( win
);
415 expose_window( hwnd
, &rect
, 0, flags
);
419 /***********************************************************************
422 * Set the drawable, origin and dimensions for the DC associated to
425 BOOL
X11DRV_GetDC( HWND hwnd
, HDC hdc
, HRGN hrgn
, DWORD flags
)
427 WND
*win
= WIN_GetPtr( hwnd
);
429 X11DRV_WND_DATA
*data
= win
->pDriverData
;
432 POINT org
, drawable_org
;
433 int mode
= IncludeInferiors
;
435 /* don't clip siblings if using parent clip region */
436 if (flags
& DCX_PARENTCLIP
) flags
&= ~DCX_CLIPSIBLINGS
;
438 /* find the top parent in the hierarchy that isn't clipping siblings */
439 visible
= (win
->dwStyle
& WS_VISIBLE
) != 0;
443 HWND
*list
= WIN_ListParents( hwnd
);
447 for (i
= 0; list
[i
] != GetDesktopWindow(); i
++)
449 LONG style
= GetWindowLongW( list
[i
], GWL_STYLE
);
450 if (!(style
& WS_VISIBLE
))
456 if (!(style
& WS_CLIPSIBLINGS
)) top
= list
[i
];
458 HeapFree( GetProcessHeap(), 0, list
);
460 if (!top
&& visible
&& !(flags
& DCX_CLIPSIBLINGS
)) top
= hwnd
;
465 HWND parent
= GetAncestor( top
, GA_PARENT
);
467 if (flags
& DCX_WINDOW
)
469 org
.x
= win
->rectWindow
.left
- win
->rectClient
.left
;
470 org
.y
= win
->rectWindow
.top
- win
->rectClient
.top
;
473 MapWindowPoints( hwnd
, parent
, &org
, 1 );
474 MapWindowPoints( hwnd
, 0, &drawable_org
, 1 );
475 /* have to use the parent so that we include siblings */
476 if (parent
) drawable
= X11DRV_get_client_window( parent
);
477 else drawable
= root_window
;
481 if (IsIconic( hwnd
))
483 drawable
= data
->icon_window
? data
->icon_window
: data
->whole_window
;
488 else if (flags
& DCX_WINDOW
)
490 drawable
= data
->whole_window
;
491 org
.x
= win
->rectWindow
.left
- data
->whole_rect
.left
;
492 org
.y
= win
->rectWindow
.top
- data
->whole_rect
.top
;
493 drawable_org
.x
= data
->whole_rect
.left
- win
->rectClient
.left
;
494 drawable_org
.y
= data
->whole_rect
.top
- win
->rectClient
.top
;
498 drawable
= data
->client_window
;
502 if (flags
& DCX_CLIPCHILDREN
) mode
= ClipByChildren
; /* can use X11 clipping */
504 MapWindowPoints( hwnd
, 0, &drawable_org
, 1 );
507 X11DRV_SetDrawable( hdc
, drawable
, mode
, &org
, &drawable_org
);
509 if (flags
& (DCX_EXCLUDERGN
| DCX_INTERSECTRGN
) ||
510 SetHookFlags16( hdc
, DCHF_VALIDATEVISRGN
)) /* DC was dirty */
512 /* need to recompute the visible region */
517 visRgn
= get_visible_region( win
, top
, flags
, mode
);
519 if (flags
& (DCX_EXCLUDERGN
| DCX_INTERSECTRGN
))
520 CombineRgn( visRgn
, visRgn
, hrgn
,
521 (flags
& DCX_INTERSECTRGN
) ? RGN_AND
: RGN_DIFF
);
523 else visRgn
= CreateRectRgn( 0, 0, 0, 0 );
525 SelectVisRgn16( hdc
, visRgn
);
526 DeleteObject( visRgn
);
529 WIN_ReleasePtr( win
);
535 /***********************************************************************
536 * SWP_DoWinPosChanging
538 static BOOL
SWP_DoWinPosChanging( WINDOWPOS
* pWinpos
, RECT
* pNewWindowRect
, RECT
* pNewClientRect
)
542 /* Send WM_WINDOWPOSCHANGING message */
544 if (!(pWinpos
->flags
& SWP_NOSENDCHANGING
))
545 SendMessageA( pWinpos
->hwnd
, WM_WINDOWPOSCHANGING
, 0, (LPARAM
)pWinpos
);
547 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return FALSE
;
549 /* Calculate new position and size */
551 *pNewWindowRect
= wndPtr
->rectWindow
;
552 *pNewClientRect
= (wndPtr
->dwStyle
& WS_MINIMIZE
) ? wndPtr
->rectWindow
553 : wndPtr
->rectClient
;
555 if (!(pWinpos
->flags
& SWP_NOSIZE
))
557 pNewWindowRect
->right
= pNewWindowRect
->left
+ pWinpos
->cx
;
558 pNewWindowRect
->bottom
= pNewWindowRect
->top
+ pWinpos
->cy
;
560 if (!(pWinpos
->flags
& SWP_NOMOVE
))
562 pNewWindowRect
->left
= pWinpos
->x
;
563 pNewWindowRect
->top
= pWinpos
->y
;
564 pNewWindowRect
->right
+= pWinpos
->x
- wndPtr
->rectWindow
.left
;
565 pNewWindowRect
->bottom
+= pWinpos
->y
- wndPtr
->rectWindow
.top
;
567 OffsetRect( pNewClientRect
, pWinpos
->x
- wndPtr
->rectWindow
.left
,
568 pWinpos
->y
- wndPtr
->rectWindow
.top
);
570 pWinpos
->flags
|= SWP_NOCLIENTMOVE
| SWP_NOCLIENTSIZE
;
571 WIN_ReleasePtr( wndPtr
);
575 /***********************************************************************
578 static UINT
SWP_DoNCCalcSize( WINDOWPOS
* pWinpos
, RECT
* pNewWindowRect
, RECT
* pNewClientRect
)
583 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
585 /* Send WM_NCCALCSIZE message to get new client area */
586 if( (pWinpos
->flags
& (SWP_FRAMECHANGED
| SWP_NOSIZE
)) != SWP_NOSIZE
)
588 NCCALCSIZE_PARAMS params
;
589 WINDOWPOS winposCopy
;
591 params
.rgrc
[0] = *pNewWindowRect
;
592 params
.rgrc
[1] = wndPtr
->rectWindow
;
593 params
.rgrc
[2] = wndPtr
->rectClient
;
594 params
.lppos
= &winposCopy
;
595 winposCopy
= *pWinpos
;
596 WIN_ReleasePtr( wndPtr
);
598 wvrFlags
= SendMessageW( pWinpos
->hwnd
, WM_NCCALCSIZE
, TRUE
, (LPARAM
)¶ms
);
600 TRACE( "%d,%d-%d,%d\n", params
.rgrc
[0].left
, params
.rgrc
[0].top
,
601 params
.rgrc
[0].right
, params
.rgrc
[0].bottom
);
603 /* If the application send back garbage, ignore it */
604 if (params
.rgrc
[0].left
<= params
.rgrc
[0].right
&&
605 params
.rgrc
[0].top
<= params
.rgrc
[0].bottom
)
606 *pNewClientRect
= params
.rgrc
[0];
608 /* FIXME: WVR_ALIGNxxx */
610 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
612 if( pNewClientRect
->left
!= wndPtr
->rectClient
.left
||
613 pNewClientRect
->top
!= wndPtr
->rectClient
.top
)
614 pWinpos
->flags
&= ~SWP_NOCLIENTMOVE
;
616 if( (pNewClientRect
->right
- pNewClientRect
->left
!=
617 wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
) ||
618 (pNewClientRect
->bottom
- pNewClientRect
->top
!=
619 wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
) )
620 pWinpos
->flags
&= ~SWP_NOCLIENTSIZE
;
624 if (!(pWinpos
->flags
& SWP_NOMOVE
) &&
625 (pNewClientRect
->left
!= wndPtr
->rectClient
.left
||
626 pNewClientRect
->top
!= wndPtr
->rectClient
.top
))
627 pWinpos
->flags
&= ~SWP_NOCLIENTMOVE
;
629 WIN_ReleasePtr( wndPtr
);
634 /***********************************************************************
637 * fix Z order taking into account owned popups -
638 * basically we need to maintain them above the window that owns them
640 * FIXME: hide/show owned popups when owner visibility changes.
642 static HWND
SWP_DoOwnedPopups(HWND hwnd
, HWND hwndInsertAfter
)
645 HWND owner
= GetWindow( hwnd
, GW_OWNER
);
646 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
648 WARN("(%04x) hInsertAfter = %04x\n", hwnd
, hwndInsertAfter
);
650 if ((style
& WS_POPUP
) && owner
)
652 /* make sure this popup stays above the owner */
654 HWND hwndLocalPrev
= HWND_TOP
;
656 if( hwndInsertAfter
!= HWND_TOP
)
658 if ((list
= WIN_ListChildren( GetDesktopWindow() )))
661 for (i
= 0; list
[i
]; i
++)
663 if (list
[i
] == owner
) break;
664 if (list
[i
] != hwnd
) hwndLocalPrev
= list
[i
];
665 if (hwndLocalPrev
== hwndInsertAfter
) break;
667 hwndInsertAfter
= hwndLocalPrev
;
671 else if (style
& WS_CHILD
) return hwndInsertAfter
;
673 if (!list
) list
= WIN_ListChildren( GetDesktopWindow() );
677 for (i
= 0; list
[i
]; i
++)
679 if (list
[i
] == hwnd
) break;
680 if ((GetWindowLongW( list
[i
], GWL_STYLE
) & WS_POPUP
) &&
681 GetWindow( list
[i
], GW_OWNER
) == hwnd
)
683 SetWindowPos( list
[i
], hwndInsertAfter
, 0, 0, 0, 0,
684 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
|
685 SWP_NOSENDCHANGING
| SWP_DEFERERASE
);
686 hwndInsertAfter
= list
[i
];
689 HeapFree( GetProcessHeap(), 0, list
);
692 return hwndInsertAfter
;
696 /* fix redundant flags and values in the WINDOWPOS structure */
697 static BOOL
fixup_flags( WINDOWPOS
*winpos
)
699 WND
*wndPtr
= WIN_GetPtr( winpos
->hwnd
);
702 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
)
704 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
707 winpos
->hwnd
= wndPtr
->hwndSelf
; /* make it a full handle */
709 if (wndPtr
->dwStyle
& WS_VISIBLE
) winpos
->flags
&= ~SWP_SHOWWINDOW
;
712 winpos
->flags
&= ~SWP_HIDEWINDOW
;
713 if (!(winpos
->flags
& SWP_SHOWWINDOW
)) winpos
->flags
|= SWP_NOREDRAW
;
716 if (winpos
->cx
< 0) winpos
->cx
= 0;
717 if (winpos
->cy
< 0) winpos
->cy
= 0;
719 if ((wndPtr
->rectWindow
.right
- wndPtr
->rectWindow
.left
== winpos
->cx
) &&
720 (wndPtr
->rectWindow
.bottom
- wndPtr
->rectWindow
.top
== winpos
->cy
))
721 winpos
->flags
|= SWP_NOSIZE
; /* Already the right size */
723 if ((wndPtr
->rectWindow
.left
== winpos
->x
) && (wndPtr
->rectWindow
.top
== winpos
->y
))
724 winpos
->flags
|= SWP_NOMOVE
; /* Already the right position */
726 if (winpos
->hwnd
== GetForegroundWindow())
727 winpos
->flags
|= SWP_NOACTIVATE
; /* Already active */
728 else if ((wndPtr
->dwStyle
& (WS_POPUP
| WS_CHILD
)) != WS_CHILD
)
730 if (!(winpos
->flags
& SWP_NOACTIVATE
)) /* Bring to the top when activating */
732 winpos
->flags
&= ~SWP_NOZORDER
;
733 winpos
->hwndInsertAfter
= HWND_TOP
;
738 /* Check hwndInsertAfter */
739 if (winpos
->flags
& SWP_NOZORDER
) goto done
;
741 /* fix sign extension */
742 if (winpos
->hwndInsertAfter
== (HWND
)0xffff) winpos
->hwndInsertAfter
= HWND_TOPMOST
;
743 else if (winpos
->hwndInsertAfter
== (HWND
)0xfffe) winpos
->hwndInsertAfter
= HWND_NOTOPMOST
;
745 /* FIXME: TOPMOST not supported yet */
746 if ((winpos
->hwndInsertAfter
== HWND_TOPMOST
) ||
747 (winpos
->hwndInsertAfter
== HWND_NOTOPMOST
)) winpos
->hwndInsertAfter
= HWND_TOP
;
749 /* hwndInsertAfter must be a sibling of the window */
750 if ((winpos
->hwndInsertAfter
!= HWND_TOP
) && (winpos
->hwndInsertAfter
!= HWND_BOTTOM
))
752 winpos
->hwndInsertAfter
= WIN_GetFullHandle( winpos
->hwndInsertAfter
);
753 if (GetAncestor( winpos
->hwndInsertAfter
, GA_PARENT
) != wndPtr
->parent
) ret
= FALSE
;
756 /* don't need to change the Zorder of hwnd if it's already inserted
757 * after hwndInsertAfter or when inserting hwnd after itself.
759 if ((winpos
->hwnd
== winpos
->hwndInsertAfter
) ||
760 (winpos
->hwnd
== GetWindow( winpos
->hwndInsertAfter
, GW_HWNDNEXT
)))
761 winpos
->flags
|= SWP_NOZORDER
;
765 WIN_ReleasePtr( wndPtr
);
770 /***********************************************************************
773 * Set/clear the WS_VISIBLE style of a window and map/unmap the X window.
775 static void set_visible_style( HWND hwnd
, BOOL set
)
779 if (!(win
= WIN_GetPtr( hwnd
))) return;
780 if (win
== WND_OTHER_PROCESS
) return;
782 TRACE( "hwnd %x (%lx) set %d visible %d empty %d\n",
783 hwnd
, get_whole_window(win
),
784 set
, (win
->dwStyle
& WS_VISIBLE
) != 0, IsRectEmpty(&win
->rectWindow
) );
788 if (win
->dwStyle
& WS_VISIBLE
) goto done
;
789 WIN_SetStyle( hwnd
, win
->dwStyle
| WS_VISIBLE
);
790 if (!IsRectEmpty( &win
->rectWindow
) && get_whole_window(win
) && is_window_top_level(win
))
792 Display
*display
= thread_display();
793 X11DRV_sync_window_style( display
, win
);
794 X11DRV_set_wm_hints( display
, win
);
795 TRACE( "mapping win %x\n", hwnd
);
796 TSXMapWindow( display
, get_whole_window(win
) );
801 if (!(win
->dwStyle
& WS_VISIBLE
)) goto done
;
802 WIN_SetStyle( hwnd
, win
->dwStyle
& ~WS_VISIBLE
);
803 if (!IsRectEmpty( &win
->rectWindow
) && get_whole_window(win
) && is_window_top_level(win
))
805 TRACE( "unmapping win %x\n", hwnd
);
806 TSXUnmapWindow( thread_display(), get_whole_window(win
) );
810 WIN_ReleasePtr( win
);
814 /***********************************************************************
815 * SetWindowStyle (X11DRV.@)
817 * Update the X state of a window to reflect a style change
819 void X11DRV_SetWindowStyle( HWND hwnd
, LONG oldStyle
)
821 Display
*display
= thread_display();
825 if (hwnd
== GetDesktopWindow()) return;
826 if (!(wndPtr
= WIN_GetPtr( hwnd
))) return;
827 if (wndPtr
== WND_OTHER_PROCESS
) return;
829 changed
= wndPtr
->dwStyle
^ oldStyle
;
831 if (changed
& WS_VISIBLE
)
833 if (!IsRectEmpty( &wndPtr
->rectWindow
) && !is_window_top_level(wndPtr
))
835 if (wndPtr
->dwStyle
& WS_VISIBLE
)
837 TRACE( "mapping win %x\n", hwnd
);
838 TSXMapWindow( display
, get_whole_window(wndPtr
) );
842 TRACE( "unmapping win %x\n", hwnd
);
843 TSXUnmapWindow( display
, get_whole_window(wndPtr
) );
848 if (changed
& WS_DISABLED
)
850 if (wndPtr
->dwExStyle
& WS_EX_MANAGED
)
854 if (!(wm_hints
= XGetWMHints( display
, get_whole_window(wndPtr
) )))
855 wm_hints
= XAllocWMHints();
858 wm_hints
->flags
|= InputHint
;
859 wm_hints
->input
= !(wndPtr
->dwStyle
& WS_DISABLED
);
860 XSetWMHints( display
, get_whole_window(wndPtr
), wm_hints
);
866 WIN_ReleasePtr(wndPtr
);
870 /***********************************************************************
871 * SetWindowPos (X11DRV.@)
873 BOOL
X11DRV_SetWindowPos( WINDOWPOS
*winpos
)
876 RECT newWindowRect
, newClientRect
;
877 RECT oldWindowRect
, oldClientRect
;
881 TRACE( "hwnd %04x, swp (%i,%i)-(%i,%i) flags %08x\n",
882 winpos
->hwnd
, winpos
->x
, winpos
->y
,
883 winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
, winpos
->flags
);
885 bChangePos
= !(winpos
->flags
& SWP_WINE_NOHOSTMOVE
);
886 winpos
->flags
&= ~SWP_WINE_NOHOSTMOVE
;
888 /* Fix redundant flags */
889 if (!fixup_flags( winpos
)) return FALSE
;
891 /* Check window handle */
892 if (winpos
->hwnd
== GetDesktopWindow()) return FALSE
;
894 SWP_DoWinPosChanging( winpos
, &newWindowRect
, &newClientRect
);
896 if (!(wndPtr
= WIN_FindWndPtr( winpos
->hwnd
))) return FALSE
;
898 TRACE("\tcurrent (%i,%i)-(%i,%i), style %08x\n",
899 wndPtr
->rectWindow
.left
, wndPtr
->rectWindow
.top
,
900 wndPtr
->rectWindow
.right
, wndPtr
->rectWindow
.bottom
, (unsigned)wndPtr
->dwStyle
);
902 if((winpos
->flags
& (SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_SHOWWINDOW
)) != SWP_NOZORDER
)
904 if (GetAncestor( winpos
->hwnd
, GA_PARENT
) == GetDesktopWindow())
905 winpos
->hwndInsertAfter
= SWP_DoOwnedPopups( winpos
->hwnd
, winpos
->hwndInsertAfter
);
908 /* Common operations */
910 wvrFlags
= SWP_DoNCCalcSize( winpos
, &newWindowRect
, &newClientRect
);
912 if(!(winpos
->flags
& SWP_NOZORDER
) && winpos
->hwnd
!= winpos
->hwndInsertAfter
)
914 HWND parent
= GetAncestor( winpos
->hwnd
, GA_PARENT
);
915 if (parent
) WIN_LinkWindow( winpos
->hwnd
, parent
, winpos
->hwndInsertAfter
);
918 /* Reset active DCEs */
920 if( (((winpos
->flags
& SWP_AGG_NOPOSCHANGE
) != SWP_AGG_NOPOSCHANGE
) &&
921 wndPtr
->dwStyle
& WS_VISIBLE
) ||
922 (winpos
->flags
& (SWP_HIDEWINDOW
| SWP_SHOWWINDOW
)) )
926 UnionRect(&rect
, &newWindowRect
, &wndPtr
->rectWindow
);
927 DCE_InvalidateDCE(wndPtr
->hwndSelf
, &rect
);
930 oldWindowRect
= wndPtr
->rectWindow
;
931 oldClientRect
= wndPtr
->rectClient
;
933 /* Find out if we have to redraw the whole client rect */
935 if( oldClientRect
.bottom
- oldClientRect
.top
==
936 newClientRect
.bottom
- newClientRect
.top
) wvrFlags
&= ~WVR_VREDRAW
;
938 if( oldClientRect
.right
- oldClientRect
.left
==
939 newClientRect
.right
- newClientRect
.left
) wvrFlags
&= ~WVR_HREDRAW
;
941 /* FIXME: actually do something with WVR_VALIDRECTS */
943 WIN_SetRectangles( winpos
->hwnd
, &newWindowRect
, &newClientRect
);
945 if (get_whole_window(wndPtr
)) /* don't do anything if X window not created yet */
947 Display
*display
= thread_display();
949 if (!(winpos
->flags
& SWP_SHOWWINDOW
) && (winpos
->flags
& SWP_HIDEWINDOW
))
951 /* clear the update region */
952 RedrawWindow( winpos
->hwnd
, NULL
, 0, RDW_VALIDATE
| RDW_NOFRAME
|
953 RDW_NOERASE
| RDW_NOINTERNALPAINT
| RDW_ALLCHILDREN
);
954 set_visible_style( winpos
->hwnd
, FALSE
);
956 else if ((wndPtr
->dwStyle
& WS_VISIBLE
) &&
957 !IsRectEmpty( &oldWindowRect
) && IsRectEmpty( &newWindowRect
))
959 /* resizing to zero size -> unmap */
960 TRACE( "unmapping zero size win %x\n", winpos
->hwnd
);
961 TSXUnmapWindow( display
, get_whole_window(wndPtr
) );
966 X11DRV_sync_whole_window_position( display
, wndPtr
, !(winpos
->flags
& SWP_NOZORDER
) );
969 struct x11drv_win_data
*data
= wndPtr
->pDriverData
;
970 data
->whole_rect
= wndPtr
->rectWindow
;
971 X11DRV_window_to_X_rect( wndPtr
, &data
->whole_rect
);
974 if (X11DRV_sync_client_window_position( display
, wndPtr
) ||
975 (winpos
->flags
& SWP_FRAMECHANGED
))
977 /* if we moved the client area, repaint the whole non-client window */
978 XClearArea( display
, get_whole_window(wndPtr
), 0, 0, 0, 0, True
);
979 winpos
->flags
|= SWP_FRAMECHANGED
;
981 if (winpos
->flags
& SWP_SHOWWINDOW
)
983 set_visible_style( winpos
->hwnd
, TRUE
);
985 else if ((wndPtr
->dwStyle
& WS_VISIBLE
) &&
986 IsRectEmpty( &oldWindowRect
) && !IsRectEmpty( &newWindowRect
))
988 /* resizing from zero size to non-zero -> map */
989 TRACE( "mapping non zero size win %x\n", winpos
->hwnd
);
990 XMapWindow( display
, get_whole_window(wndPtr
) );
992 XFlush( display
); /* FIXME: should not be necessary */
995 else /* no X window, simply toggle the window style */
997 if (winpos
->flags
& SWP_SHOWWINDOW
)
998 set_visible_style( winpos
->hwnd
, TRUE
);
999 else if (winpos
->flags
& SWP_HIDEWINDOW
)
1000 set_visible_style( winpos
->hwnd
, FALSE
);
1003 /* manually expose the areas that X won't expose because they are still covered by something */
1005 if (!(winpos
->flags
& SWP_SHOWWINDOW
))
1006 expose_covered_parent_area( wndPtr
, &oldWindowRect
);
1008 if (wndPtr
->dwStyle
& WS_VISIBLE
)
1009 expose_covered_window_area( wndPtr
, &oldClientRect
, winpos
->flags
& SWP_FRAMECHANGED
);
1011 WIN_ReleaseWndPtr(wndPtr
);
1013 if (wvrFlags
& WVR_REDRAW
) RedrawWindow( winpos
->hwnd
, NULL
, 0, RDW_INVALIDATE
| RDW_ERASE
);
1015 if (winpos
->hwnd
== CARET_GetHwnd())
1017 if( winpos
->flags
& SWP_HIDEWINDOW
)
1018 HideCaret(winpos
->hwnd
);
1019 else if (winpos
->flags
& SWP_SHOWWINDOW
)
1020 ShowCaret(winpos
->hwnd
);
1023 if (!(winpos
->flags
& SWP_NOACTIVATE
))
1025 /* child windows get WM_CHILDACTIVATE message */
1026 if ((GetWindowLongW( winpos
->hwnd
, GWL_STYLE
) & (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
1027 SendMessageA( winpos
->hwnd
, WM_CHILDACTIVATE
, 0, 0 );
1029 SetForegroundWindow( winpos
->hwnd
);
1032 /* And last, send the WM_WINDOWPOSCHANGED message */
1034 TRACE("\tstatus flags = %04x\n", winpos
->flags
& SWP_AGG_STATUSFLAGS
);
1036 if (((winpos
->flags
& SWP_AGG_STATUSFLAGS
) != SWP_AGG_NOPOSCHANGE
))
1037 SendMessageA( winpos
->hwnd
, WM_WINDOWPOSCHANGED
, 0, (LPARAM
)winpos
);
1038 /* WM_WINDOWPOSCHANGED is send even if SWP_NOSENDCHANGING is set */
1044 /***********************************************************************
1045 * WINPOS_FindIconPos
1047 * Find a suitable place for an iconic window.
1049 static POINT
WINPOS_FindIconPos( WND
* wndPtr
, POINT pt
)
1053 short x
, y
, xspacing
, yspacing
;
1055 GetClientRect( wndPtr
->parent
, &rectParent
);
1056 if ((pt
.x
>= rectParent
.left
) && (pt
.x
+ GetSystemMetrics(SM_CXICON
) < rectParent
.right
) &&
1057 (pt
.y
>= rectParent
.top
) && (pt
.y
+ GetSystemMetrics(SM_CYICON
) < rectParent
.bottom
))
1058 return pt
; /* The icon already has a suitable position */
1060 xspacing
= GetSystemMetrics(SM_CXICONSPACING
);
1061 yspacing
= GetSystemMetrics(SM_CYICONSPACING
);
1063 list
= WIN_ListChildren( wndPtr
->parent
);
1064 y
= rectParent
.bottom
;
1067 x
= rectParent
.left
;
1070 /* Check if another icon already occupies this spot */
1071 /* FIXME: this is completely inefficient */
1077 for (i
= 0; list
[i
]; i
++)
1079 if (list
[i
] == wndPtr
->hwndSelf
) continue;
1080 if (!IsIconic( list
[i
] )) continue;
1081 if (!(childPtr
= WIN_FindWndPtr( list
[i
] ))) continue;
1082 if ((childPtr
->rectWindow
.left
< x
+ xspacing
) &&
1083 (childPtr
->rectWindow
.right
>= x
) &&
1084 (childPtr
->rectWindow
.top
<= y
) &&
1085 (childPtr
->rectWindow
.bottom
> y
- yspacing
))
1087 WIN_ReleaseWndPtr( childPtr
);
1088 break; /* There's a window in there */
1090 WIN_ReleaseWndPtr( childPtr
);
1094 /* found something here, try next spot */
1100 /* No window was found, so it's OK for us */
1101 pt
.x
= x
+ (xspacing
- GetSystemMetrics(SM_CXICON
)) / 2;
1102 pt
.y
= y
- (yspacing
+ GetSystemMetrics(SM_CYICON
)) / 2;
1103 HeapFree( GetProcessHeap(), 0, list
);
1106 } while(x
<= rectParent
.right
-xspacing
);
1115 UINT
WINPOS_MinMaximize( HWND hwnd
, UINT cmd
, LPRECT rect
)
1121 WINDOWPLACEMENT wpl
;
1123 TRACE("0x%04x %u\n", hwnd
, cmd
);
1125 wpl
.length
= sizeof(wpl
);
1126 GetWindowPlacement( hwnd
, &wpl
);
1128 if (HOOK_CallHooksA( WH_CBT
, HCBT_MINMAX
, (WPARAM
)hwnd
, cmd
))
1129 return SWP_NOSIZE
| SWP_NOMOVE
;
1131 if (IsIconic( hwnd
))
1133 if (cmd
== SW_MINIMIZE
) return SWP_NOSIZE
| SWP_NOMOVE
;
1134 if (!SendMessageA( hwnd
, WM_QUERYOPEN
, 0, 0 )) return SWP_NOSIZE
| SWP_NOMOVE
;
1135 swpFlags
|= SWP_NOCOPYBITS
;
1138 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return 0;
1140 size
.x
= wndPtr
->rectWindow
.left
;
1141 size
.y
= wndPtr
->rectWindow
.top
;
1146 if( wndPtr
->dwStyle
& WS_MAXIMIZE
) wndPtr
->flags
|= WIN_RESTORE_MAX
;
1147 else wndPtr
->flags
&= ~WIN_RESTORE_MAX
;
1149 WIN_SetStyle( hwnd
, (wndPtr
->dwStyle
& ~WS_MAXIMIZE
) | WS_MINIMIZE
);
1151 X11DRV_set_iconic_state( wndPtr
);
1153 wpl
.ptMinPosition
= WINPOS_FindIconPos( wndPtr
, wpl
.ptMinPosition
);
1155 SetRect( rect
, wpl
.ptMinPosition
.x
, wpl
.ptMinPosition
.y
,
1156 GetSystemMetrics(SM_CXICON
), GetSystemMetrics(SM_CYICON
) );
1157 swpFlags
|= SWP_NOCOPYBITS
;
1161 WINPOS_GetMinMaxInfo( hwnd
, &size
, &wpl
.ptMaxPosition
, NULL
, NULL
);
1163 old_style
= WIN_SetStyle( hwnd
, (wndPtr
->dwStyle
& ~WS_MINIMIZE
) | WS_MAXIMIZE
);
1164 if (old_style
& WS_MINIMIZE
)
1166 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1167 X11DRV_set_iconic_state( wndPtr
);
1169 SetRect( rect
, wpl
.ptMaxPosition
.x
, wpl
.ptMaxPosition
.y
, size
.x
, size
.y
);
1173 old_style
= WIN_SetStyle( hwnd
, wndPtr
->dwStyle
& ~(WS_MINIMIZE
|WS_MAXIMIZE
) );
1174 if (old_style
& WS_MINIMIZE
)
1176 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1177 X11DRV_set_iconic_state( wndPtr
);
1179 if( wndPtr
->flags
& WIN_RESTORE_MAX
)
1181 /* Restore to maximized position */
1182 WINPOS_GetMinMaxInfo( hwnd
, &size
, &wpl
.ptMaxPosition
, NULL
, NULL
);
1183 WIN_SetStyle( hwnd
, wndPtr
->dwStyle
| WS_MAXIMIZE
);
1184 SetRect( rect
, wpl
.ptMaxPosition
.x
, wpl
.ptMaxPosition
.y
, size
.x
, size
.y
);
1188 else if (!(old_style
& WS_MAXIMIZE
)) break;
1190 /* Restore to normal position */
1192 *rect
= wpl
.rcNormalPosition
;
1193 rect
->right
-= rect
->left
;
1194 rect
->bottom
-= rect
->top
;
1199 WIN_ReleaseWndPtr( wndPtr
);
1204 /***********************************************************************
1205 * ShowWindow (X11DRV.@)
1207 BOOL
X11DRV_ShowWindow( HWND hwnd
, INT cmd
)
1209 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
1210 BOOL wasVisible
, showFlag
;
1211 RECT newPos
= {0, 0, 0, 0};
1214 if (!wndPtr
) return FALSE
;
1215 hwnd
= wndPtr
->hwndSelf
; /* make it a full handle */
1217 TRACE("hwnd=%04x, cmd=%d\n", hwnd
, cmd
);
1219 wasVisible
= (wndPtr
->dwStyle
& WS_VISIBLE
) != 0;
1224 if (!wasVisible
) goto END
;
1225 swp
|= SWP_HIDEWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
|
1226 SWP_NOACTIVATE
| SWP_NOZORDER
;
1229 case SW_SHOWMINNOACTIVE
:
1230 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1232 case SW_SHOWMINIMIZED
:
1233 case SW_FORCEMINIMIZE
: /* FIXME: Does not work if thread is hung. */
1234 swp
|= SWP_SHOWWINDOW
;
1237 swp
|= SWP_FRAMECHANGED
;
1238 if( !(wndPtr
->dwStyle
& WS_MINIMIZE
) )
1239 swp
|= WINPOS_MinMaximize( hwnd
, SW_MINIMIZE
, &newPos
);
1240 else swp
|= SWP_NOSIZE
| SWP_NOMOVE
;
1243 case SW_SHOWMAXIMIZED
: /* same as SW_MAXIMIZE */
1244 swp
|= SWP_SHOWWINDOW
| SWP_FRAMECHANGED
;
1245 if( !(wndPtr
->dwStyle
& WS_MAXIMIZE
) )
1246 swp
|= WINPOS_MinMaximize( hwnd
, SW_MAXIMIZE
, &newPos
);
1247 else swp
|= SWP_NOSIZE
| SWP_NOMOVE
;
1251 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1254 swp
|= SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
1257 * ShowWindow has a little peculiar behavior that if the
1258 * window is already the topmost window, it will not
1261 if (GetTopWindow((HWND
)0)==hwnd
&& (wasVisible
|| GetActiveWindow() == hwnd
))
1262 swp
|= SWP_NOACTIVATE
;
1266 case SW_SHOWNOACTIVATE
:
1267 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1269 case SW_SHOWNORMAL
: /* same as SW_NORMAL: */
1270 case SW_SHOWDEFAULT
: /* FIXME: should have its own handler */
1272 swp
|= SWP_SHOWWINDOW
| SWP_FRAMECHANGED
;
1274 if( wndPtr
->dwStyle
& (WS_MINIMIZE
| WS_MAXIMIZE
) )
1275 swp
|= WINPOS_MinMaximize( hwnd
, SW_RESTORE
, &newPos
);
1276 else swp
|= SWP_NOSIZE
| SWP_NOMOVE
;
1280 showFlag
= (cmd
!= SW_HIDE
);
1281 if (showFlag
!= wasVisible
)
1283 SendMessageA( hwnd
, WM_SHOWWINDOW
, showFlag
, 0 );
1284 if (!IsWindow( hwnd
)) goto END
;
1287 /* We can't activate a child window */
1288 if ((wndPtr
->dwStyle
& WS_CHILD
) &&
1289 !(wndPtr
->dwExStyle
& WS_EX_MDICHILD
))
1290 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1292 SetWindowPos( hwnd
, HWND_TOP
, newPos
.left
, newPos
.top
,
1293 newPos
.right
, newPos
.bottom
, LOWORD(swp
) );
1296 /* FIXME: This will cause the window to be activated irrespective
1297 * of whether it is owned by the same thread. Has to be done
1301 if (hwnd
== GetActiveWindow())
1302 WINPOS_ActivateOtherWindow(hwnd
);
1304 /* Revert focus to parent */
1305 if (hwnd
== GetFocus() || IsChild(hwnd
, GetFocus()))
1306 SetFocus( GetParent(hwnd
) );
1308 if (!IsWindow( hwnd
)) goto END
;
1309 else if( wndPtr
->dwStyle
& WS_MINIMIZE
) WINPOS_ShowIconTitle( hwnd
, TRUE
);
1311 if (wndPtr
->flags
& WIN_NEED_SIZE
)
1313 /* should happen only in CreateWindowEx() */
1314 int wParam
= SIZE_RESTORED
;
1316 wndPtr
->flags
&= ~WIN_NEED_SIZE
;
1317 if (wndPtr
->dwStyle
& WS_MAXIMIZE
) wParam
= SIZE_MAXIMIZED
;
1318 else if (wndPtr
->dwStyle
& WS_MINIMIZE
) wParam
= SIZE_MINIMIZED
;
1319 SendMessageA( hwnd
, WM_SIZE
, wParam
,
1320 MAKELONG(wndPtr
->rectClient
.right
-wndPtr
->rectClient
.left
,
1321 wndPtr
->rectClient
.bottom
-wndPtr
->rectClient
.top
));
1322 SendMessageA( hwnd
, WM_MOVE
, 0,
1323 MAKELONG(wndPtr
->rectClient
.left
, wndPtr
->rectClient
.top
) );
1327 WIN_ReleaseWndPtr(wndPtr
);
1332 /**********************************************************************
1335 void X11DRV_MapNotify( HWND hwnd
, XMapEvent
*event
)
1337 HWND hwndFocus
= GetFocus();
1340 if (!(win
= WIN_GetPtr( hwnd
))) return;
1342 if ((win
->dwStyle
& WS_VISIBLE
) &&
1343 (win
->dwStyle
& WS_MINIMIZE
) &&
1344 (win
->dwExStyle
& WS_EX_MANAGED
))
1347 unsigned int width
, height
, border
, depth
;
1350 LONG style
= (win
->dwStyle
& ~(WS_MINIMIZE
|WS_MAXIMIZE
)) | WS_VISIBLE
;
1354 XGetGeometry( event
->display
, get_whole_window(win
), &root
, &x
, &y
, &width
, &height
,
1356 XTranslateCoordinates( event
->display
, get_whole_window(win
), root
, 0, 0, &x
, &y
, &top
);
1357 wine_tsx11_unlock();
1360 rect
.right
= x
+ width
;
1361 rect
.bottom
= y
+ height
;
1362 X11DRV_X_to_window_rect( win
, &rect
);
1364 DCE_InvalidateDCE( hwnd
, &win
->rectWindow
);
1366 if (win
->flags
& WIN_RESTORE_MAX
) style
|= WS_MAXIMIZE
;
1367 WIN_SetStyle( hwnd
, style
);
1368 WIN_ReleasePtr( win
);
1370 SendMessageA( hwnd
, WM_SHOWWINDOW
, SW_RESTORE
, 0 );
1371 SetWindowPos( hwnd
, 0, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
,
1372 SWP_NOZORDER
| SWP_WINE_NOHOSTMOVE
);
1374 else WIN_ReleasePtr( win
);
1375 if (hwndFocus
&& IsChild( hwnd
, hwndFocus
)) X11DRV_SetFocus(hwndFocus
); /* FIXME */
1379 /**********************************************************************
1380 * X11DRV_UnmapNotify
1382 void X11DRV_UnmapNotify( HWND hwnd
, XUnmapEvent
*event
)
1386 if (!(win
= WIN_GetPtr( hwnd
))) return;
1388 if ((win
->dwStyle
& WS_VISIBLE
) && (win
->dwExStyle
& WS_EX_MANAGED
))
1390 if (win
->dwStyle
& WS_MAXIMIZE
)
1391 win
->flags
|= WIN_RESTORE_MAX
;
1393 win
->flags
&= ~WIN_RESTORE_MAX
;
1395 WIN_SetStyle( hwnd
, (win
->dwStyle
& ~WS_MAXIMIZE
) | WS_MINIMIZE
);
1396 WIN_ReleasePtr( win
);
1399 SendMessageA( hwnd
, WM_SHOWWINDOW
, SW_MINIMIZE
, 0 );
1400 SetWindowPos( hwnd
, 0, 0, 0, GetSystemMetrics(SM_CXICON
), GetSystemMetrics(SM_CYICON
),
1401 SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_WINE_NOHOSTMOVE
);
1403 else WIN_ReleasePtr( win
);
1407 /***********************************************************************
1410 * Synchronize internal z-order with the window manager's.
1412 static Window
__get_common_ancestor( Display
*display
, Window A
, Window B
,
1413 Window
** children
, unsigned* total
)
1415 /* find the real root window */
1417 Window root
, *childrenB
;
1420 while( A
!= B
&& A
&& B
)
1422 TSXQueryTree( display
, A
, &root
, &A
, children
, total
);
1423 TSXQueryTree( display
, B
, &root
, &B
, &childrenB
, &totalB
);
1424 if( childrenB
) TSXFree( childrenB
);
1425 if( *children
) TSXFree( *children
), *children
= NULL
;
1430 TSXQueryTree( display
, A
, &root
, &B
, children
, total
);
1436 static Window
__get_top_decoration( Display
*display
, Window w
, Window ancestor
)
1438 Window
* children
, root
, prev
= w
, parent
= w
;
1444 TSXQueryTree( display
, w
, &root
, &parent
, &children
, &total
);
1445 if( children
) TSXFree( children
);
1446 } while( parent
&& parent
!= ancestor
);
1447 TRACE("\t%08x -> %08x\n", (unsigned)prev
, (unsigned)w
);
1448 return ( parent
) ? w
: 0 ;
1451 static unsigned __td_lookup( Window w
, Window
* list
, unsigned max
)
1454 for( i
= max
; i
> 0; i
-- ) if( list
[i
- 1] == w
) break;
1458 static HWND
query_zorder( Display
*display
, HWND hWndCheck
)
1460 HWND hwndInsertAfter
= HWND_TOP
;
1461 Window w
, parent
, *children
= NULL
;
1462 unsigned total
, check
, pos
, best
;
1463 HWND
*list
= WIN_ListChildren( GetDesktopWindow() );
1464 HWND hwndA
= 0, hwndB
= 0;
1467 /* find at least two managed windows */
1468 if (!list
) return 0;
1469 for (i
= 0; list
[i
]; i
++)
1471 if (!(GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_MANAGED
)) continue;
1472 if (!(GetWindowLongW( list
[i
], GWL_STYLE
) & WS_VISIBLE
)) continue;
1473 if (!hwndA
) hwndA
= list
[i
];
1480 if (!hwndA
|| !hwndB
) goto done
;
1482 parent
= __get_common_ancestor( display
, X11DRV_get_whole_window(hwndA
),
1483 X11DRV_get_whole_window(hwndB
), &children
, &total
);
1484 if( parent
&& children
)
1486 /* w is the ancestor if hWndCheck that is a direct descendant of 'parent' */
1488 w
= __get_top_decoration( display
, X11DRV_get_whole_window(hWndCheck
), parent
);
1490 if( w
!= children
[total
-1] ) /* check if at the top */
1492 /* X child at index 0 is at the bottom, at index total-1 is at the top */
1493 check
= __td_lookup( w
, children
, total
);
1496 /* go through all windows in Wine z-order... */
1497 for (i
= 0; list
[i
]; i
++)
1499 if (list
[i
] == hWndCheck
) continue;
1500 if (!(GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_MANAGED
)) continue;
1501 if (!(w
= __get_top_decoration( display
, X11DRV_get_whole_window(list
[i
]),
1502 parent
))) continue;
1503 pos
= __td_lookup( w
, children
, total
);
1504 if( pos
< best
&& pos
> check
)
1506 /* find a nearest Wine window precedes hWndCheck in the real z-order */
1508 hwndInsertAfter
= list
[i
];
1510 if( best
- check
== 1 ) break;
1514 if( children
) TSXFree( children
);
1517 HeapFree( GetProcessHeap(), 0, list
);
1518 return hwndInsertAfter
;
1522 /***********************************************************************
1523 * X11DRV_ConfigureNotify
1525 void X11DRV_ConfigureNotify( HWND hwnd
, XConfigureEvent
*event
)
1527 HWND oldInsertAfter
;
1528 struct x11drv_win_data
*data
;
1532 int x
= event
->x
, y
= event
->y
;
1534 if (!(win
= WIN_GetPtr( hwnd
))) return;
1535 data
= win
->pDriverData
;
1539 if (!event
->send_event
) /* normal event, need to map coordinates to the root */
1543 XTranslateCoordinates( event
->display
, data
->whole_window
, root_window
,
1544 0, 0, &x
, &y
, &child
);
1545 wine_tsx11_unlock();
1549 rect
.right
= x
+ event
->width
;
1550 rect
.bottom
= y
+ event
->height
;
1551 TRACE( "win %x new X rect %d,%d,%dx%d (event %d,%d,%dx%d)\n",
1552 hwnd
, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
,
1553 event
->x
, event
->y
, event
->width
, event
->height
);
1554 X11DRV_X_to_window_rect( win
, &rect
);
1555 WIN_ReleasePtr( win
);
1558 winpos
.x
= rect
.left
;
1559 winpos
.y
= rect
.top
;
1560 winpos
.cx
= rect
.right
- rect
.left
;
1561 winpos
.cy
= rect
.bottom
- rect
.top
;
1562 winpos
.flags
= SWP_NOACTIVATE
;
1564 /* Get Z-order (FIXME) */
1566 winpos
.hwndInsertAfter
= query_zorder( event
->display
, hwnd
);
1568 /* needs to find the first Visible Window above the current one */
1569 oldInsertAfter
= hwnd
;
1572 oldInsertAfter
= GetWindow( oldInsertAfter
, GW_HWNDPREV
);
1573 if (!oldInsertAfter
)
1575 oldInsertAfter
= HWND_TOP
;
1578 if (GetWindowLongA( oldInsertAfter
, GWL_STYLE
) & WS_VISIBLE
) break;
1581 /* Compare what has changed */
1583 GetWindowRect( hwnd
, &rect
);
1584 if (rect
.left
== winpos
.x
&& rect
.top
== winpos
.y
) winpos
.flags
|= SWP_NOMOVE
;
1586 TRACE( "%04x moving from (%d,%d) to (%d,%d)\n",
1587 hwnd
, rect
.left
, rect
.top
, winpos
.x
, winpos
.y
);
1589 if ((rect
.right
- rect
.left
== winpos
.cx
&& rect
.bottom
- rect
.top
== winpos
.cy
) ||
1591 (IsRectEmpty( &rect
) && winpos
.cx
== 1 && winpos
.cy
== 1))
1592 winpos
.flags
|= SWP_NOSIZE
;
1594 TRACE( "%04x resizing from (%dx%d) to (%dx%d)\n",
1595 hwnd
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
1596 winpos
.cx
, winpos
.cy
);
1598 if (winpos
.hwndInsertAfter
== oldInsertAfter
) winpos
.flags
|= SWP_NOZORDER
;
1600 TRACE( "%04x restacking from after %04x to after %04x\n",
1601 hwnd
, oldInsertAfter
, winpos
.hwndInsertAfter
);
1603 /* if nothing changed, don't do anything */
1604 if (winpos
.flags
== (SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
)) return;
1606 SetWindowPos( hwnd
, winpos
.hwndInsertAfter
, winpos
.x
, winpos
.y
,
1607 winpos
.cx
, winpos
.cy
, winpos
.flags
| SWP_WINE_NOHOSTMOVE
);
1611 /***********************************************************************
1612 * SetWindowRgn (X11DRV.@)
1614 * Assign specified region to window (for non-rectangular windows)
1616 int X11DRV_SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL redraw
)
1620 if ((wndPtr
= WIN_GetPtr( hwnd
)) == WND_OTHER_PROCESS
)
1622 if (IsWindow( hwnd
))
1623 FIXME( "not supported on other process window %x\n", hwnd
);
1628 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
1632 if (wndPtr
->hrgnWnd
== hrgn
)
1634 WIN_ReleasePtr( wndPtr
);
1638 if (wndPtr
->hrgnWnd
)
1640 /* delete previous region */
1641 DeleteObject(wndPtr
->hrgnWnd
);
1642 wndPtr
->hrgnWnd
= 0;
1644 wndPtr
->hrgnWnd
= hrgn
;
1646 #ifdef HAVE_LIBXSHAPE
1648 Display
*display
= thread_display();
1649 X11DRV_WND_DATA
*data
= wndPtr
->pDriverData
;
1651 if (data
->whole_window
)
1656 XShapeCombineMask( display
, data
->whole_window
,
1657 ShapeBounding
, 0, 0, None
, ShapeSet
);
1658 wine_tsx11_unlock();
1663 int x_offset
, y_offset
;
1665 DWORD dwBufferSize
= GetRegionData(hrgn
, 0, NULL
);
1666 PRGNDATA pRegionData
= HeapAlloc(GetProcessHeap(), 0, dwBufferSize
);
1669 WIN_ReleasePtr( wndPtr
);
1672 GetRegionData(hrgn
, dwBufferSize
, pRegionData
);
1673 size
= pRegionData
->rdh
.nCount
;
1674 x_offset
= wndPtr
->rectWindow
.left
- data
->whole_rect
.left
;
1675 y_offset
= wndPtr
->rectWindow
.top
- data
->whole_rect
.top
;
1676 /* convert region's "Windows rectangles" to XRectangles */
1677 aXRect
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(*aXRect
) );
1680 XRectangle
* pCurrRect
= aXRect
;
1681 RECT
*pRect
= (RECT
*) pRegionData
->Buffer
;
1682 for (; pRect
< ((RECT
*) pRegionData
->Buffer
) + size
; ++pRect
, ++pCurrRect
)
1684 pCurrRect
->x
= pRect
->left
+ x_offset
;
1685 pCurrRect
->y
= pRect
->top
+ y_offset
;
1686 pCurrRect
->height
= pRect
->bottom
- pRect
->top
;
1687 pCurrRect
->width
= pRect
->right
- pRect
->left
;
1689 TRACE("Rectangle %04d of %04ld data: X=%04d, Y=%04d, Height=%04d, Width=%04d.\n",
1690 pRect
- (RECT
*) pRegionData
->Buffer
,
1698 /* shape = non-rectangular windows (X11/extensions) */
1700 XShapeCombineRectangles( display
, data
->whole_window
, ShapeBounding
,
1702 pCurrRect
- aXRect
, ShapeSet
, YXBanded
);
1703 wine_tsx11_unlock();
1704 HeapFree(GetProcessHeap(), 0, aXRect
);
1706 HeapFree(GetProcessHeap(), 0, pRegionData
);
1710 #endif /* HAVE_LIBXSHAPE */
1712 WIN_ReleasePtr( wndPtr
);
1713 if (redraw
) RedrawWindow( hwnd
, NULL
, 0, RDW_FRAME
| RDW_INVALIDATE
| RDW_ERASE
);
1718 /***********************************************************************
1721 * Draw the frame used when moving or resizing window.
1723 * FIXME: This causes problems in Win95 mode. (why?)
1725 static void draw_moving_frame( HDC hdc
, RECT
*rect
, BOOL thickframe
)
1729 const int width
= GetSystemMetrics(SM_CXFRAME
);
1730 const int height
= GetSystemMetrics(SM_CYFRAME
);
1732 HBRUSH hbrush
= SelectObject( hdc
, GetStockObject( GRAY_BRUSH
) );
1733 PatBlt( hdc
, rect
->left
, rect
->top
,
1734 rect
->right
- rect
->left
- width
, height
, PATINVERT
);
1735 PatBlt( hdc
, rect
->left
, rect
->top
+ height
, width
,
1736 rect
->bottom
- rect
->top
- height
, PATINVERT
);
1737 PatBlt( hdc
, rect
->left
+ width
, rect
->bottom
- 1,
1738 rect
->right
- rect
->left
- width
, -height
, PATINVERT
);
1739 PatBlt( hdc
, rect
->right
- 1, rect
->top
, -width
,
1740 rect
->bottom
- rect
->top
- height
, PATINVERT
);
1741 SelectObject( hdc
, hbrush
);
1743 else DrawFocusRect( hdc
, rect
);
1747 /***********************************************************************
1750 * Initialisation of a move or resize, when initiatied from a menu choice.
1751 * Return hit test code for caption or sizing border.
1753 static LONG
start_size_move( HWND hwnd
, WPARAM wParam
, POINT
*capturePoint
, LONG style
)
1760 GetWindowRect( hwnd
, &rectWindow
);
1762 if ((wParam
& 0xfff0) == SC_MOVE
)
1764 /* Move pointer at the center of the caption */
1766 NC_GetInsideRect( hwnd
, &rect
);
1767 if (style
& WS_SYSMENU
)
1768 rect
.left
+= GetSystemMetrics(SM_CXSIZE
) + 1;
1769 if (style
& WS_MINIMIZEBOX
)
1770 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
1771 if (style
& WS_MAXIMIZEBOX
)
1772 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
1773 pt
.x
= rectWindow
.left
+ (rect
.right
- rect
.left
) / 2;
1774 pt
.y
= rectWindow
.top
+ rect
.top
+ GetSystemMetrics(SM_CYSIZE
)/2;
1775 hittest
= HTCAPTION
;
1782 GetMessageW( &msg
, 0, WM_KEYFIRST
, WM_MOUSELAST
);
1783 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
1788 hittest
= NC_HandleNCHitTest( hwnd
, msg
.pt
);
1789 if ((hittest
< HTLEFT
) || (hittest
> HTBOTTOMRIGHT
))
1801 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
1802 pt
.y
= rectWindow
.top
+ GetSystemMetrics(SM_CYFRAME
) / 2;
1806 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
1807 pt
.y
= rectWindow
.bottom
- GetSystemMetrics(SM_CYFRAME
) / 2;
1811 pt
.x
= rectWindow
.left
+ GetSystemMetrics(SM_CXFRAME
) / 2;
1812 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
1816 pt
.x
= rectWindow
.right
- GetSystemMetrics(SM_CXFRAME
) / 2;
1817 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
1820 case VK_ESCAPE
: return 0;
1826 SetCursorPos( pt
.x
, pt
.y
);
1827 NC_HandleSetCursor( hwnd
, (WPARAM
)hwnd
, MAKELONG( hittest
, WM_MOUSEMOVE
));
1832 /***********************************************************************
1833 * set_movesize_capture
1835 static void set_movesize_capture( HWND hwnd
)
1839 SERVER_START_REQ( set_capture_window
)
1842 req
->flags
= CAPTURE_MOVESIZE
;
1843 if (!wine_server_call_err( req
))
1845 previous
= reply
->previous
;
1846 hwnd
= reply
->full_handle
;
1850 if (previous
&& previous
!= hwnd
)
1851 SendMessageW( previous
, WM_CAPTURECHANGED
, 0, (LPARAM
)hwnd
);
1855 /***********************************************************************
1856 * SysCommandSizeMove (X11DRV.@)
1858 * Perform SC_MOVE and SC_SIZE commands.
1860 void X11DRV_SysCommandSizeMove( HWND hwnd
, WPARAM wParam
)
1863 RECT sizingRect
, mouseRect
, origRect
;
1866 LONG hittest
= (LONG
)(wParam
& 0x0f);
1867 HCURSOR hDragCursor
= 0, hOldCursor
= 0;
1868 POINT minTrack
, maxTrack
;
1869 POINT capturePoint
, pt
;
1870 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
1871 LONG exstyle
= GetWindowLongA( hwnd
, GWL_EXSTYLE
);
1872 BOOL thickframe
= HAS_THICKFRAME( style
, exstyle
);
1873 BOOL iconic
= style
& WS_MINIMIZE
;
1875 DWORD dwPoint
= GetMessagePos ();
1876 BOOL DragFullWindows
= FALSE
;
1879 Display
*old_gdi_display
= NULL
;
1880 Display
*display
= thread_display();
1882 SystemParametersInfoA(SPI_GETDRAGFULLWINDOWS
, 0, &DragFullWindows
, 0);
1884 pt
.x
= SLOWORD(dwPoint
);
1885 pt
.y
= SHIWORD(dwPoint
);
1888 if (IsZoomed(hwnd
) || !IsWindowVisible(hwnd
) || (exstyle
& WS_EX_MANAGED
)) return;
1890 if ((wParam
& 0xfff0) == SC_MOVE
)
1892 if (!hittest
) hittest
= start_size_move( hwnd
, wParam
, &capturePoint
, style
);
1893 if (!hittest
) return;
1897 if (!thickframe
) return;
1898 if ( hittest
&& hittest
!= HTSYSMENU
) hittest
+= 2;
1901 set_movesize_capture( hwnd
);
1902 hittest
= start_size_move( hwnd
, wParam
, &capturePoint
, style
);
1905 set_movesize_capture(0);
1911 /* Get min/max info */
1913 WINPOS_GetMinMaxInfo( hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
1914 GetWindowRect( hwnd
, &sizingRect
);
1915 if (style
& WS_CHILD
)
1917 parent
= GetParent(hwnd
);
1918 /* make sizing rect relative to parent */
1919 MapWindowPoints( 0, parent
, (POINT
*)&sizingRect
, 2 );
1920 GetClientRect( parent
, &mouseRect
);
1925 SetRect(&mouseRect
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
));
1927 origRect
= sizingRect
;
1929 if (ON_LEFT_BORDER(hittest
))
1931 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.right
-maxTrack
.x
);
1932 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.right
-minTrack
.x
);
1934 else if (ON_RIGHT_BORDER(hittest
))
1936 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.left
+minTrack
.x
);
1937 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.left
+maxTrack
.x
);
1939 if (ON_TOP_BORDER(hittest
))
1941 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.bottom
-maxTrack
.y
);
1942 mouseRect
.bottom
= min( mouseRect
.bottom
,sizingRect
.bottom
-minTrack
.y
);
1944 else if (ON_BOTTOM_BORDER(hittest
))
1946 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.top
+minTrack
.y
);
1947 mouseRect
.bottom
= min( mouseRect
.bottom
, sizingRect
.top
+maxTrack
.y
);
1949 if (parent
) MapWindowPoints( parent
, 0, (LPPOINT
)&mouseRect
, 2 );
1951 /* Retrieve a default cache DC (without using the window style) */
1952 hdc
= GetDCEx( parent
, 0, DCX_CACHE
);
1954 if( iconic
) /* create a cursor for dragging */
1956 hDragCursor
= (HCURSOR
)GetClassLongA( hwnd
, GCL_HICON
);
1957 if( !hDragCursor
) hDragCursor
= (HCURSOR
)SendMessageA( hwnd
, WM_QUERYDRAGICON
, 0, 0L);
1958 if( !hDragCursor
) iconic
= FALSE
;
1961 /* repaint the window before moving it around */
1962 RedrawWindow( hwnd
, NULL
, 0, RDW_UPDATENOW
| RDW_ALLCHILDREN
);
1964 SendMessageA( hwnd
, WM_ENTERSIZEMOVE
, 0, 0 );
1965 set_movesize_capture( hwnd
);
1967 /* grab the server only when moving top-level windows without desktop */
1968 grab
= (!DragFullWindows
&& !parent
&& (root_window
== DefaultRootWindow(gdi_display
)));
1973 XSync( gdi_display
, False
);
1974 XGrabServer( display
);
1975 XSync( display
, False
);
1976 /* switch gdi display to the thread display, since the server is grabbed */
1977 old_gdi_display
= gdi_display
;
1978 gdi_display
= display
;
1980 XGrabPointer( display
, X11DRV_get_whole_window(hwnd
), False
,
1981 PointerMotionMask
| ButtonPressMask
| ButtonReleaseMask
,
1982 GrabModeAsync
, GrabModeAsync
,
1983 parent
? X11DRV_get_client_window(parent
) : root_window
,
1984 None
, CurrentTime
);
1985 wine_tsx11_unlock();
1991 if (!GetMessageW( &msg
, 0, WM_KEYFIRST
, WM_MOUSELAST
)) break;
1992 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
1994 /* Exit on button-up, Return, or Esc */
1995 if ((msg
.message
== WM_LBUTTONUP
) ||
1996 ((msg
.message
== WM_KEYDOWN
) &&
1997 ((msg
.wParam
== VK_RETURN
) || (msg
.wParam
== VK_ESCAPE
)))) break;
1999 if ((msg
.message
!= WM_KEYDOWN
) && (msg
.message
!= WM_MOUSEMOVE
))
2000 continue; /* We are not interested in other messages */
2004 if (msg
.message
== WM_KEYDOWN
) switch(msg
.wParam
)
2006 case VK_UP
: pt
.y
-= 8; break;
2007 case VK_DOWN
: pt
.y
+= 8; break;
2008 case VK_LEFT
: pt
.x
-= 8; break;
2009 case VK_RIGHT
: pt
.x
+= 8; break;
2012 pt
.x
= max( pt
.x
, mouseRect
.left
);
2013 pt
.x
= min( pt
.x
, mouseRect
.right
);
2014 pt
.y
= max( pt
.y
, mouseRect
.top
);
2015 pt
.y
= min( pt
.y
, mouseRect
.bottom
);
2017 dx
= pt
.x
- capturePoint
.x
;
2018 dy
= pt
.y
- capturePoint
.y
;
2026 if( iconic
) /* ok, no system popup tracking */
2028 hOldCursor
= SetCursor(hDragCursor
);
2030 WINPOS_ShowIconTitle( hwnd
, FALSE
);
2032 else if(!DragFullWindows
)
2033 draw_moving_frame( hdc
, &sizingRect
, thickframe
);
2036 if (msg
.message
== WM_KEYDOWN
) SetCursorPos( pt
.x
, pt
.y
);
2039 RECT newRect
= sizingRect
;
2040 WPARAM wpSizingHit
= 0;
2042 if (hittest
== HTCAPTION
) OffsetRect( &newRect
, dx
, dy
);
2043 if (ON_LEFT_BORDER(hittest
)) newRect
.left
+= dx
;
2044 else if (ON_RIGHT_BORDER(hittest
)) newRect
.right
+= dx
;
2045 if (ON_TOP_BORDER(hittest
)) newRect
.top
+= dy
;
2046 else if (ON_BOTTOM_BORDER(hittest
)) newRect
.bottom
+= dy
;
2047 if(!iconic
&& !DragFullWindows
) draw_moving_frame( hdc
, &sizingRect
, thickframe
);
2050 /* determine the hit location */
2051 if (hittest
>= HTLEFT
&& hittest
<= HTBOTTOMRIGHT
)
2052 wpSizingHit
= WMSZ_LEFT
+ (hittest
- HTLEFT
);
2053 SendMessageA( hwnd
, WM_SIZING
, wpSizingHit
, (LPARAM
)&newRect
);
2057 if(!DragFullWindows
)
2058 draw_moving_frame( hdc
, &newRect
, thickframe
);
2060 /* To avoid any deadlocks, all the locks on the windows
2061 structures must be suspended before the SetWindowPos */
2062 iWndsLocks
= WIN_SuspendWndsLock();
2063 SetWindowPos( hwnd
, 0, newRect
.left
, newRect
.top
,
2064 newRect
.right
- newRect
.left
,
2065 newRect
.bottom
- newRect
.top
,
2066 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
2067 WIN_RestoreWndsLock(iWndsLocks
);
2070 sizingRect
= newRect
;
2075 set_movesize_capture(0);
2078 if( moved
) /* restore cursors, show icon title later on */
2080 ShowCursor( FALSE
);
2081 SetCursor( hOldCursor
);
2084 else if (moved
&& !DragFullWindows
)
2085 draw_moving_frame( hdc
, &sizingRect
, thickframe
);
2087 ReleaseDC( parent
, hdc
);
2090 XUngrabPointer( display
, CurrentTime
);
2093 XSync( display
, False
);
2094 XUngrabServer( display
);
2095 XSync( display
, False
);
2096 gdi_display
= old_gdi_display
;
2098 wine_tsx11_unlock();
2100 if (HOOK_CallHooksA( WH_CBT
, HCBT_MOVESIZE
, (WPARAM
)hwnd
, (LPARAM
)&sizingRect
)) moved
= FALSE
;
2102 SendMessageA( hwnd
, WM_EXITSIZEMOVE
, 0, 0 );
2103 SendMessageA( hwnd
, WM_SETVISIBLE
, !IsIconic(hwnd
), 0L);
2105 /* window moved or resized */
2108 /* To avoid any deadlocks, all the locks on the windows
2109 structures must be suspended before the SetWindowPos */
2110 iWndsLocks
= WIN_SuspendWndsLock();
2112 /* if the moving/resizing isn't canceled call SetWindowPos
2113 * with the new position or the new size of the window
2115 if (!((msg
.message
== WM_KEYDOWN
) && (msg
.wParam
== VK_ESCAPE
)) )
2117 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
2118 if(!DragFullWindows
)
2119 SetWindowPos( hwnd
, 0, sizingRect
.left
, sizingRect
.top
,
2120 sizingRect
.right
- sizingRect
.left
,
2121 sizingRect
.bottom
- sizingRect
.top
,
2122 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
2125 { /* restore previous size/position */
2127 SetWindowPos( hwnd
, 0, origRect
.left
, origRect
.top
,
2128 origRect
.right
- origRect
.left
,
2129 origRect
.bottom
- origRect
.top
,
2130 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
2133 WIN_RestoreWndsLock(iWndsLocks
);
2138 /* Single click brings up the system menu when iconized */
2142 if(style
& WS_SYSMENU
)
2143 SendMessageA( hwnd
, WM_SYSCOMMAND
,
2144 SC_MOUSEMENU
+ HTSYSMENU
, MAKELONG(pt
.x
,pt
.y
));
2146 else WINPOS_ShowIconTitle( hwnd
, TRUE
);
2151 /***********************************************************************
2152 * ForceWindowRaise (X11DRV.@)
2154 * Raise a window on top of the X stacking order, while preserving
2155 * the correct Windows Z order.
2157 * FIXME: this should go away.
2159 void X11DRV_ForceWindowRaise( HWND hwnd
)
2163 XWindowChanges winChanges
;
2164 Display
*display
= thread_display();
2165 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
2167 if (!wndPtr
) return;
2169 if ((wndPtr
->dwExStyle
& WS_EX_MANAGED
) ||
2170 wndPtr
->parent
!= GetDesktopWindow() ||
2171 IsRectEmpty( &wndPtr
->rectWindow
) ||
2172 !get_whole_window(wndPtr
))
2174 WIN_ReleaseWndPtr( wndPtr
);
2177 WIN_ReleaseWndPtr( wndPtr
);
2179 /* Raise all windows up to wndPtr according to their Z order.
2180 * (it would be easier with sibling-related Below but it doesn't
2181 * work very well with SGI mwm for instance)
2183 winChanges
.stack_mode
= Above
;
2184 if (!(list
= WIN_ListChildren( GetDesktopWindow() ))) return;
2185 while (list
[i
] && list
[i
] != hwnd
) i
++;
2188 for ( ; i
>= 0; i
--)
2190 WND
*ptr
= WIN_FindWndPtr( list
[i
] );
2192 if (!IsRectEmpty( &ptr
->rectWindow
) && get_whole_window(ptr
))
2193 TSXReconfigureWMWindow( display
, get_whole_window(ptr
), 0,
2194 CWStackMode
, &winChanges
);
2195 WIN_ReleaseWndPtr( ptr
);
2198 HeapFree( GetProcessHeap(), 0, list
);