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 */
42 #include "cursoricon.h"
43 #include "nonclient.h"
45 #include "wine/server.h"
46 #include "wine/debug.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(x11drv
);
50 #define SWP_AGG_NOGEOMETRYCHANGE \
51 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE)
52 #define SWP_AGG_NOPOSCHANGE \
53 (SWP_AGG_NOGEOMETRYCHANGE | SWP_NOZORDER)
54 #define SWP_AGG_STATUSFLAGS \
55 (SWP_AGG_NOPOSCHANGE | SWP_FRAMECHANGED | SWP_HIDEWINDOW | SWP_SHOWWINDOW)
57 #define SWP_EX_NOCOPY 0x0001
58 #define SWP_EX_PAINTSELF 0x0002
59 #define SWP_EX_NONCLIENT 0x0004
61 #define HAS_THICKFRAME(style,exStyle) \
62 (((style) & WS_THICKFRAME) && \
63 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
65 #define ON_LEFT_BORDER(hit) \
66 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
67 #define ON_RIGHT_BORDER(hit) \
68 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
69 #define ON_TOP_BORDER(hit) \
70 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
71 #define ON_BOTTOM_BORDER(hit) \
72 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
75 /***********************************************************************
78 * Clip all children of a given window out of the visible region
80 static int clip_children( HWND parent
, HWND last
, HRGN hrgn
, int whole_window
)
85 int i
, x
, y
, ret
= SIMPLEREGION
;
87 /* first check if we have anything to do */
88 if (!(list
= WIN_ListChildren( parent
))) return ret
;
89 for (i
= 0; list
[i
] && list
[i
] != last
; i
++)
90 if (GetWindowLongW( list
[i
], GWL_STYLE
) & WS_VISIBLE
) break;
91 if (!list
[i
] || list
[i
] == last
) goto done
; /* no children to clip */
95 WND
*win
= WIN_FindWndPtr( parent
);
96 x
= win
->rectWindow
.left
- win
->rectClient
.left
;
97 y
= win
->rectWindow
.top
- win
->rectClient
.top
;
98 WIN_ReleaseWndPtr( win
);
102 rectRgn
= CreateRectRgn( 0, 0, 0, 0 );
104 for ( ; list
[i
] && list
[i
] != last
; i
++)
106 if (!(ptr
= WIN_FindWndPtr( list
[i
] ))) continue;
107 if (ptr
->dwStyle
& WS_VISIBLE
)
109 SetRectRgn( rectRgn
, ptr
->rectWindow
.left
+ x
, ptr
->rectWindow
.top
+ y
,
110 ptr
->rectWindow
.right
+ x
, ptr
->rectWindow
.bottom
+ y
);
111 if ((ret
= CombineRgn( hrgn
, hrgn
, rectRgn
, RGN_DIFF
)) == NULLREGION
)
113 WIN_ReleaseWndPtr( ptr
);
114 break; /* no need to go on, region is empty */
117 WIN_ReleaseWndPtr( ptr
);
119 DeleteObject( rectRgn
);
121 HeapFree( GetProcessHeap(), 0, list
);
126 /***********************************************************************
129 * Compute the visible region of a window
131 static HRGN
get_visible_region( WND
*win
, HWND top
, UINT flags
, int mode
)
135 int xoffset
, yoffset
;
136 X11DRV_WND_DATA
*data
= win
->pDriverData
;
138 if (flags
& DCX_WINDOW
)
140 xoffset
= win
->rectWindow
.left
;
141 yoffset
= win
->rectWindow
.top
;
145 xoffset
= win
->rectClient
.left
;
146 yoffset
= win
->rectClient
.top
;
149 if (flags
& DCX_PARENTCLIP
)
150 GetClientRect( win
->parent
, &rect
);
151 else if (flags
& DCX_WINDOW
)
152 rect
= data
->whole_rect
;
154 rect
= win
->rectClient
;
156 /* vis region is relative to the start of the client/window area */
157 OffsetRect( &rect
, -xoffset
, -yoffset
);
159 if (!(rgn
= CreateRectRgn( rect
.left
, rect
.top
, rect
.right
, rect
.bottom
))) return 0;
161 if ((flags
& DCX_CLIPCHILDREN
) && (mode
!= ClipByChildren
))
163 /* we need to clip children by hand */
164 if (clip_children( win
->hwndSelf
, 0, rgn
, (flags
& DCX_WINDOW
) ) == NULLREGION
) return rgn
;
167 if (top
&& top
!= win
->hwndSelf
) /* need to clip siblings of ancestors */
169 WND
*parent
, *ptr
= WIN_FindWndPtr( win
->hwndSelf
);
172 OffsetRgn( rgn
, xoffset
, yoffset
);
175 if (ptr
->dwStyle
& WS_CLIPSIBLINGS
)
177 if (clip_children( ptr
->parent
, ptr
->hwndSelf
, rgn
, FALSE
) == NULLREGION
) break;
179 if (ptr
->hwndSelf
== top
) break;
180 if (!(parent
= WIN_FindWndPtr( ptr
->parent
))) break;
181 WIN_ReleaseWndPtr( ptr
);
183 /* clip to parent client area */
184 if (tmp
) SetRectRgn( tmp
, 0, 0, ptr
->rectClient
.right
- ptr
->rectClient
.left
,
185 ptr
->rectClient
.bottom
- ptr
->rectClient
.top
);
186 else tmp
= CreateRectRgn( 0, 0, ptr
->rectClient
.right
- ptr
->rectClient
.left
,
187 ptr
->rectClient
.bottom
- ptr
->rectClient
.top
);
188 CombineRgn( rgn
, rgn
, tmp
, RGN_AND
);
189 OffsetRgn( rgn
, ptr
->rectClient
.left
, ptr
->rectClient
.top
);
190 xoffset
+= ptr
->rectClient
.left
;
191 yoffset
+= ptr
->rectClient
.top
;
193 WIN_ReleaseWndPtr( ptr
);
194 /* make it relative to the target window again */
195 OffsetRgn( rgn
, -xoffset
, -yoffset
);
196 if (tmp
) DeleteObject( tmp
);
203 /***********************************************************************
206 * Compute the portion of 'rgn' that is covered by non-clipped siblings.
207 * This is the area that is covered from X point of view, but may still need
209 * 'rgn' must be relative to the client area of the parent of 'win'.
211 static int get_covered_region( WND
*win
, HRGN rgn
)
215 WND
*parent
, *ptr
= WIN_FindWndPtr( win
->hwndSelf
);
216 int xoffset
= 0, yoffset
= 0;
218 tmp
= CreateRectRgn( 0, 0, 0, 0 );
219 CombineRgn( tmp
, rgn
, 0, RGN_COPY
);
221 /* to make things easier we actually build the uncovered
222 * area by removing all siblings and then we subtract that
223 * from the total region to get the covered area */
226 if (!(ptr
->dwStyle
& WS_CLIPSIBLINGS
))
228 if (clip_children( ptr
->parent
, ptr
->hwndSelf
, tmp
, FALSE
) == NULLREGION
) break;
230 if (!(parent
= WIN_FindWndPtr( ptr
->parent
))) break;
231 WIN_ReleaseWndPtr( ptr
);
233 OffsetRgn( tmp
, ptr
->rectClient
.left
, ptr
->rectClient
.top
);
234 xoffset
+= ptr
->rectClient
.left
;
235 yoffset
+= ptr
->rectClient
.top
;
237 WIN_ReleaseWndPtr( ptr
);
238 /* make it relative to the target window again */
239 OffsetRgn( tmp
, -xoffset
, -yoffset
);
241 /* now subtract the computed region from the original one */
242 ret
= CombineRgn( rgn
, rgn
, tmp
, RGN_DIFF
);
248 /***********************************************************************
251 * Expose a region of a given window.
253 static void expose_window( HWND hwnd
, RECT
*rect
, HRGN rgn
, int flags
)
260 /* find the top most parent that doesn't clip children or siblings and
261 * invalidate the area on its parent, including all children */
262 if ((list
= WIN_ListParents( hwnd
)))
265 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
266 for (i
= 0; list
[i
] && list
[i
] != GetDesktopWindow(); i
++)
268 if (!(style
& WS_CLIPSIBLINGS
)) top
= current
;
269 style
= GetWindowLongW( list
[i
], GWL_STYLE
);
270 if (!(style
& WS_CLIPCHILDREN
)) top
= current
;
276 /* find the parent of the top window, reusing the parent list */
277 if (top
== hwnd
) i
= 0;
280 for (i
= 0; list
[i
]; i
++) if (list
[i
] == top
) break;
281 if (list
[i
] && list
[i
+1]) i
++;
283 if (list
[i
] != GetDesktopWindow()) top
= list
[i
];
284 flags
&= ~RDW_FRAME
; /* parent will invalidate children frame anyway */
285 flags
|= RDW_ALLCHILDREN
;
287 HeapFree( GetProcessHeap(), 0, list
);
290 if (!top
) top
= hwnd
;
292 /* make coords relative to top */
293 offset
.x
= offset
.y
= 0;
294 MapWindowPoints( hwnd
, top
, &offset
, 1 );
298 OffsetRect( rect
, offset
.x
, offset
.y
);
299 RedrawWindow( top
, rect
, 0, flags
);
303 OffsetRgn( rgn
, offset
.x
, offset
.y
);
304 RedrawWindow( top
, NULL
, rgn
, flags
);
309 /***********************************************************************
310 * expose_covered_parent_area
312 * Expose the parent area that has been uncovered by moving/hiding a
313 * given window, but that is still covered by other siblings (the area
314 * not covered by siblings will be exposed automatically by X).
316 static void expose_covered_parent_area( WND
*win
, const RECT
*old_rect
)
318 int ret
= SIMPLEREGION
;
319 HRGN hrgn
= CreateRectRgnIndirect( old_rect
);
321 if (win
->dwStyle
& WS_VISIBLE
)
323 HRGN tmp
= CreateRectRgnIndirect( &win
->rectWindow
);
324 ret
= CombineRgn( hrgn
, hrgn
, tmp
, RGN_DIFF
);
328 if (ret
!= NULLREGION
)
330 if (get_covered_region( win
, hrgn
) != NULLREGION
)
331 expose_window( win
->parent
, NULL
, hrgn
, RDW_INVALIDATE
| RDW_ERASE
| RDW_ALLCHILDREN
);
333 DeleteObject( hrgn
);
337 /***********************************************************************
338 * expose_covered_window_area
340 * Expose the area of a window that is covered by other siblings.
342 static void expose_covered_window_area( WND
*win
, const RECT
*old_client_rect
, BOOL frame
)
345 int ret
= SIMPLEREGION
;
348 hrgn
= CreateRectRgn( win
->rectWindow
.left
- win
->rectClient
.left
,
349 win
->rectWindow
.top
- win
->rectClient
.top
,
350 win
->rectWindow
.right
- win
->rectWindow
.left
,
351 win
->rectWindow
.bottom
- win
->rectWindow
.top
);
353 hrgn
= CreateRectRgn( 0, 0,
354 win
->rectClient
.right
- win
->rectClient
.left
,
355 win
->rectClient
.bottom
- win
->rectClient
.top
);
357 /* if the client rect didn't move we don't need to repaint it all */
358 if (old_client_rect
->left
== win
->rectClient
.left
&&
359 old_client_rect
->top
== win
->rectClient
.top
)
363 if (IntersectRect( &rc
, old_client_rect
, &win
->rectClient
))
366 /* subtract the unchanged client area from the region to expose */
367 OffsetRect( &rc
, -win
->rectClient
.left
, -win
->rectClient
.top
);
368 if ((tmp
= CreateRectRgnIndirect( &rc
)))
370 ret
= CombineRgn( hrgn
, hrgn
, tmp
, RGN_DIFF
);
376 if (ret
!= NULLREGION
)
378 if (get_covered_region( win
, hrgn
) != NULLREGION
)
379 expose_window( win
->hwndSelf
, NULL
, hrgn
,
380 RDW_INVALIDATE
| RDW_ERASE
| RDW_FRAME
| RDW_ALLCHILDREN
);
383 DeleteObject( hrgn
);
387 /***********************************************************************
390 void X11DRV_Expose( HWND hwnd
, XExposeEvent
*event
)
393 struct x11drv_win_data
*data
;
394 int flags
= RDW_INVALIDATE
| RDW_ERASE
;
397 TRACE( "win %p (%lx) %d,%d %dx%d\n",
398 hwnd
, event
->window
, event
->x
, event
->y
, event
->width
, event
->height
);
400 rect
.left
= event
->x
;
402 rect
.right
= rect
.left
+ event
->width
;
403 rect
.bottom
= rect
.top
+ event
->height
;
405 if (!(win
= WIN_GetPtr( hwnd
))) return;
406 data
= win
->pDriverData
;
408 if (event
->window
!= data
->client_window
) /* whole window or icon window */
411 /* make position relative to client area instead of window */
412 OffsetRect( &rect
, -data
->client_rect
.left
, -data
->client_rect
.top
);
414 WIN_ReleasePtr( win
);
416 expose_window( hwnd
, &rect
, 0, flags
);
420 /***********************************************************************
423 * Set the drawable, origin and dimensions for the DC associated to
426 BOOL
X11DRV_GetDC( HWND hwnd
, HDC hdc
, HRGN hrgn
, DWORD flags
)
428 WND
*win
= WIN_GetPtr( hwnd
);
430 X11DRV_WND_DATA
*data
= win
->pDriverData
;
433 POINT org
, drawable_org
;
434 int mode
= IncludeInferiors
;
436 /* don't clip siblings if using parent clip region */
437 if (flags
& DCX_PARENTCLIP
) flags
&= ~DCX_CLIPSIBLINGS
;
439 /* find the top parent in the hierarchy that isn't clipping siblings */
440 visible
= (win
->dwStyle
& WS_VISIBLE
) != 0;
444 HWND
*list
= WIN_ListParents( hwnd
);
448 for (i
= 0; list
[i
] != GetDesktopWindow(); i
++)
450 LONG style
= GetWindowLongW( list
[i
], GWL_STYLE
);
451 if (!(style
& WS_VISIBLE
))
457 if (!(style
& WS_CLIPSIBLINGS
)) top
= list
[i
];
459 HeapFree( GetProcessHeap(), 0, list
);
461 if (!top
&& visible
&& !(flags
& DCX_CLIPSIBLINGS
)) top
= hwnd
;
466 HWND parent
= GetAncestor( top
, GA_PARENT
);
468 if (flags
& DCX_WINDOW
)
470 org
.x
= win
->rectWindow
.left
- win
->rectClient
.left
;
471 org
.y
= win
->rectWindow
.top
- win
->rectClient
.top
;
473 MapWindowPoints( hwnd
, parent
, &org
, 1 );
474 drawable_org
.x
= drawable_org
.y
= 0;
475 MapWindowPoints( parent
, 0, &drawable_org
, 1 );
476 /* have to use the parent so that we include siblings */
477 if (parent
) drawable
= X11DRV_get_client_window( parent
);
478 else drawable
= root_window
;
482 if (IsIconic( hwnd
))
484 drawable
= data
->icon_window
? data
->icon_window
: data
->whole_window
;
489 else if (flags
& DCX_WINDOW
)
491 drawable
= data
->whole_window
;
492 org
.x
= win
->rectWindow
.left
- data
->whole_rect
.left
;
493 org
.y
= win
->rectWindow
.top
- data
->whole_rect
.top
;
494 drawable_org
.x
= data
->whole_rect
.left
- win
->rectClient
.left
;
495 drawable_org
.y
= data
->whole_rect
.top
- win
->rectClient
.top
;
499 drawable
= data
->client_window
;
503 if (flags
& DCX_CLIPCHILDREN
) mode
= ClipByChildren
; /* can use X11 clipping */
505 MapWindowPoints( hwnd
, 0, &drawable_org
, 1 );
508 X11DRV_SetDrawable( hdc
, drawable
, mode
, &org
, &drawable_org
);
510 if (flags
& (DCX_EXCLUDERGN
| DCX_INTERSECTRGN
) ||
511 SetHookFlags16( HDC_16(hdc
), DCHF_VALIDATEVISRGN
)) /* DC was dirty */
513 /* need to recompute the visible region */
518 visRgn
= get_visible_region( win
, top
, flags
, mode
);
520 if (flags
& (DCX_EXCLUDERGN
| DCX_INTERSECTRGN
))
521 CombineRgn( visRgn
, visRgn
, hrgn
,
522 (flags
& DCX_INTERSECTRGN
) ? RGN_AND
: RGN_DIFF
);
524 else visRgn
= CreateRectRgn( 0, 0, 0, 0 );
526 SelectVisRgn16( HDC_16(hdc
), HRGN_16(visRgn
) );
527 DeleteObject( visRgn
);
530 WIN_ReleasePtr( win
);
535 /***********************************************************************
536 * ReleaseDC (X11DRV.@)
538 void X11DRV_ReleaseDC( HWND hwnd
, HDC hdc
)
543 X11DRV_SetDrawable( hdc
, root_window
, IncludeInferiors
, &org
, &org
);
547 /***********************************************************************
548 * SWP_DoWinPosChanging
550 static BOOL
SWP_DoWinPosChanging( WINDOWPOS
* pWinpos
, RECT
* pNewWindowRect
, RECT
* pNewClientRect
)
554 /* Send WM_WINDOWPOSCHANGING message */
556 if (!(pWinpos
->flags
& SWP_NOSENDCHANGING
))
557 SendMessageA( pWinpos
->hwnd
, WM_WINDOWPOSCHANGING
, 0, (LPARAM
)pWinpos
);
559 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return FALSE
;
561 /* Calculate new position and size */
563 *pNewWindowRect
= wndPtr
->rectWindow
;
564 *pNewClientRect
= (wndPtr
->dwStyle
& WS_MINIMIZE
) ? wndPtr
->rectWindow
565 : wndPtr
->rectClient
;
567 if (!(pWinpos
->flags
& SWP_NOSIZE
))
569 pNewWindowRect
->right
= pNewWindowRect
->left
+ pWinpos
->cx
;
570 pNewWindowRect
->bottom
= pNewWindowRect
->top
+ pWinpos
->cy
;
572 if (!(pWinpos
->flags
& SWP_NOMOVE
))
574 pNewWindowRect
->left
= pWinpos
->x
;
575 pNewWindowRect
->top
= pWinpos
->y
;
576 pNewWindowRect
->right
+= pWinpos
->x
- wndPtr
->rectWindow
.left
;
577 pNewWindowRect
->bottom
+= pWinpos
->y
- wndPtr
->rectWindow
.top
;
579 OffsetRect( pNewClientRect
, pWinpos
->x
- wndPtr
->rectWindow
.left
,
580 pWinpos
->y
- wndPtr
->rectWindow
.top
);
582 pWinpos
->flags
|= SWP_NOCLIENTMOVE
| SWP_NOCLIENTSIZE
;
583 WIN_ReleasePtr( wndPtr
);
587 /***********************************************************************
590 static UINT
SWP_DoNCCalcSize( WINDOWPOS
* pWinpos
, RECT
* pNewWindowRect
, RECT
* pNewClientRect
)
595 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
597 /* Send WM_NCCALCSIZE message to get new client area */
598 if( (pWinpos
->flags
& (SWP_FRAMECHANGED
| SWP_NOSIZE
)) != SWP_NOSIZE
)
600 NCCALCSIZE_PARAMS params
;
601 WINDOWPOS winposCopy
;
603 params
.rgrc
[0] = *pNewWindowRect
;
604 params
.rgrc
[1] = wndPtr
->rectWindow
;
605 params
.rgrc
[2] = wndPtr
->rectClient
;
606 params
.lppos
= &winposCopy
;
607 winposCopy
= *pWinpos
;
608 WIN_ReleasePtr( wndPtr
);
610 wvrFlags
= SendMessageW( pWinpos
->hwnd
, WM_NCCALCSIZE
, TRUE
, (LPARAM
)¶ms
);
612 TRACE( "(%ld,%ld)-(%ld,%ld)\n", params
.rgrc
[0].left
, params
.rgrc
[0].top
,
613 params
.rgrc
[0].right
, params
.rgrc
[0].bottom
);
615 /* If the application send back garbage, ignore it */
616 if (params
.rgrc
[0].left
<= params
.rgrc
[0].right
&&
617 params
.rgrc
[0].top
<= params
.rgrc
[0].bottom
)
618 *pNewClientRect
= params
.rgrc
[0];
620 /* FIXME: WVR_ALIGNxxx */
622 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
624 if( pNewClientRect
->left
!= wndPtr
->rectClient
.left
||
625 pNewClientRect
->top
!= wndPtr
->rectClient
.top
)
626 pWinpos
->flags
&= ~SWP_NOCLIENTMOVE
;
628 if( (pNewClientRect
->right
- pNewClientRect
->left
!=
629 wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
) ||
630 (pNewClientRect
->bottom
- pNewClientRect
->top
!=
631 wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
) )
632 pWinpos
->flags
&= ~SWP_NOCLIENTSIZE
;
636 if (!(pWinpos
->flags
& SWP_NOMOVE
) &&
637 (pNewClientRect
->left
!= wndPtr
->rectClient
.left
||
638 pNewClientRect
->top
!= wndPtr
->rectClient
.top
))
639 pWinpos
->flags
&= ~SWP_NOCLIENTMOVE
;
641 WIN_ReleasePtr( wndPtr
);
646 /***********************************************************************
649 * fix Z order taking into account owned popups -
650 * basically we need to maintain them above the window that owns them
652 * FIXME: hide/show owned popups when owner visibility changes.
654 static HWND
SWP_DoOwnedPopups(HWND hwnd
, HWND hwndInsertAfter
)
657 HWND owner
= GetWindow( hwnd
, GW_OWNER
);
658 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
660 WARN("(%p) hInsertAfter = %p\n", hwnd
, hwndInsertAfter
);
662 if ((style
& WS_POPUP
) && owner
)
664 /* make sure this popup stays above the owner */
666 HWND hwndLocalPrev
= HWND_TOP
;
668 if( hwndInsertAfter
!= HWND_TOP
)
670 if ((list
= WIN_ListChildren( GetDesktopWindow() )))
673 for (i
= 0; list
[i
]; i
++)
675 if (list
[i
] == owner
) break;
676 if (list
[i
] != hwnd
) hwndLocalPrev
= list
[i
];
677 if (hwndLocalPrev
== hwndInsertAfter
) break;
679 hwndInsertAfter
= hwndLocalPrev
;
683 else if (style
& WS_CHILD
) return hwndInsertAfter
;
685 if (!list
) list
= WIN_ListChildren( GetDesktopWindow() );
689 for (i
= 0; list
[i
]; i
++)
691 if (list
[i
] == hwnd
) break;
692 if ((GetWindowLongW( list
[i
], GWL_STYLE
) & WS_POPUP
) &&
693 GetWindow( list
[i
], GW_OWNER
) == hwnd
)
695 SetWindowPos( list
[i
], hwndInsertAfter
, 0, 0, 0, 0,
696 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
|
697 SWP_NOSENDCHANGING
| SWP_DEFERERASE
);
698 hwndInsertAfter
= list
[i
];
701 HeapFree( GetProcessHeap(), 0, list
);
704 return hwndInsertAfter
;
708 /* fix redundant flags and values in the WINDOWPOS structure */
709 static BOOL
fixup_flags( WINDOWPOS
*winpos
)
711 WND
*wndPtr
= WIN_GetPtr( winpos
->hwnd
);
714 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
)
716 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
719 winpos
->hwnd
= wndPtr
->hwndSelf
; /* make it a full handle */
721 if (wndPtr
->dwStyle
& WS_VISIBLE
) winpos
->flags
&= ~SWP_SHOWWINDOW
;
724 winpos
->flags
&= ~SWP_HIDEWINDOW
;
725 if (!(winpos
->flags
& SWP_SHOWWINDOW
)) winpos
->flags
|= SWP_NOREDRAW
;
728 if (winpos
->cx
< 0) winpos
->cx
= 0;
729 if (winpos
->cy
< 0) winpos
->cy
= 0;
731 if ((wndPtr
->rectWindow
.right
- wndPtr
->rectWindow
.left
== winpos
->cx
) &&
732 (wndPtr
->rectWindow
.bottom
- wndPtr
->rectWindow
.top
== winpos
->cy
))
733 winpos
->flags
|= SWP_NOSIZE
; /* Already the right size */
735 if ((wndPtr
->rectWindow
.left
== winpos
->x
) && (wndPtr
->rectWindow
.top
== winpos
->y
))
736 winpos
->flags
|= SWP_NOMOVE
; /* Already the right position */
738 if (winpos
->hwnd
== GetForegroundWindow())
739 winpos
->flags
|= SWP_NOACTIVATE
; /* Already active */
740 else if ((wndPtr
->dwStyle
& (WS_POPUP
| WS_CHILD
)) != WS_CHILD
)
742 if (!(winpos
->flags
& SWP_NOACTIVATE
)) /* Bring to the top when activating */
744 winpos
->flags
&= ~SWP_NOZORDER
;
745 winpos
->hwndInsertAfter
= HWND_TOP
;
750 /* Check hwndInsertAfter */
751 if (winpos
->flags
& SWP_NOZORDER
) goto done
;
753 /* fix sign extension */
754 if (winpos
->hwndInsertAfter
== (HWND
)0xffff) winpos
->hwndInsertAfter
= HWND_TOPMOST
;
755 else if (winpos
->hwndInsertAfter
== (HWND
)0xfffe) winpos
->hwndInsertAfter
= HWND_NOTOPMOST
;
757 /* FIXME: TOPMOST not supported yet */
758 if ((winpos
->hwndInsertAfter
== HWND_TOPMOST
) ||
759 (winpos
->hwndInsertAfter
== HWND_NOTOPMOST
)) winpos
->hwndInsertAfter
= HWND_TOP
;
761 /* hwndInsertAfter must be a sibling of the window */
762 if ((winpos
->hwndInsertAfter
!= HWND_TOP
) && (winpos
->hwndInsertAfter
!= HWND_BOTTOM
))
764 if (GetAncestor( winpos
->hwndInsertAfter
, GA_PARENT
) != wndPtr
->parent
) ret
= FALSE
;
767 /* don't need to change the Zorder of hwnd if it's already inserted
768 * after hwndInsertAfter or when inserting hwnd after itself.
770 if ((winpos
->hwnd
== winpos
->hwndInsertAfter
) ||
771 (winpos
->hwnd
== GetWindow( winpos
->hwndInsertAfter
, GW_HWNDNEXT
)))
772 winpos
->flags
|= SWP_NOZORDER
;
776 WIN_ReleasePtr( wndPtr
);
781 /***********************************************************************
784 * Set/clear the WS_VISIBLE style of a window and map/unmap the X window.
786 static void set_visible_style( HWND hwnd
, BOOL set
)
790 if (!(win
= WIN_GetPtr( hwnd
))) return;
791 if (win
== WND_OTHER_PROCESS
) return;
793 TRACE( "hwnd %p (%lx) set %d visible %d empty %d\n",
794 hwnd
, get_whole_window(win
),
795 set
, (win
->dwStyle
& WS_VISIBLE
) != 0, IsRectEmpty(&win
->rectWindow
) );
799 if (win
->dwStyle
& WS_VISIBLE
) goto done
;
800 WIN_SetStyle( hwnd
, win
->dwStyle
| WS_VISIBLE
);
801 if (!IsRectEmpty( &win
->rectWindow
) && get_whole_window(win
) && is_window_top_level(win
))
803 Display
*display
= thread_display();
804 X11DRV_sync_window_style( display
, win
);
805 X11DRV_set_wm_hints( display
, win
);
806 TRACE( "mapping win %p\n", hwnd
);
807 TSXMapWindow( display
, get_whole_window(win
) );
812 if (!(win
->dwStyle
& WS_VISIBLE
)) goto done
;
813 WIN_SetStyle( hwnd
, win
->dwStyle
& ~WS_VISIBLE
);
814 if (!IsRectEmpty( &win
->rectWindow
) && get_whole_window(win
) && is_window_top_level(win
))
816 TRACE( "unmapping win %p\n", hwnd
);
817 TSXUnmapWindow( thread_display(), get_whole_window(win
) );
821 WIN_ReleasePtr( win
);
825 /***********************************************************************
826 * SetWindowStyle (X11DRV.@)
828 * Update the X state of a window to reflect a style change
830 void X11DRV_SetWindowStyle( HWND hwnd
, LONG oldStyle
)
832 Display
*display
= thread_display();
836 if (hwnd
== GetDesktopWindow()) return;
837 if (!(wndPtr
= WIN_GetPtr( hwnd
))) return;
838 if (wndPtr
== WND_OTHER_PROCESS
) return;
840 changed
= wndPtr
->dwStyle
^ oldStyle
;
842 if (changed
& WS_VISIBLE
)
844 if (!IsRectEmpty( &wndPtr
->rectWindow
))
846 if (wndPtr
->dwStyle
& WS_VISIBLE
)
848 TRACE( "mapping win %p\n", hwnd
);
849 if (is_window_top_level(wndPtr
))
851 X11DRV_sync_window_style( display
, wndPtr
);
852 X11DRV_set_wm_hints( display
, wndPtr
);
854 TSXMapWindow( display
, get_whole_window(wndPtr
) );
856 else if (!is_window_top_level(wndPtr
)) /* don't unmap managed windows */
858 TRACE( "unmapping win %p\n", hwnd
);
859 TSXUnmapWindow( display
, get_whole_window(wndPtr
) );
864 if (changed
& WS_DISABLED
)
866 if (wndPtr
->dwExStyle
& WS_EX_MANAGED
)
870 if (!(wm_hints
= XGetWMHints( display
, get_whole_window(wndPtr
) )))
871 wm_hints
= XAllocWMHints();
874 wm_hints
->flags
|= InputHint
;
875 wm_hints
->input
= !(wndPtr
->dwStyle
& WS_DISABLED
);
876 XSetWMHints( display
, get_whole_window(wndPtr
), wm_hints
);
882 WIN_ReleasePtr(wndPtr
);
886 /***********************************************************************
887 * SetWindowPos (X11DRV.@)
889 BOOL
X11DRV_SetWindowPos( WINDOWPOS
*winpos
)
892 RECT newWindowRect
, newClientRect
;
893 RECT oldWindowRect
, oldClientRect
;
897 TRACE( "hwnd %p, swp (%i,%i)-(%i,%i) flags %08x\n",
898 winpos
->hwnd
, winpos
->x
, winpos
->y
,
899 winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
, winpos
->flags
);
901 bChangePos
= !(winpos
->flags
& SWP_WINE_NOHOSTMOVE
);
902 winpos
->flags
&= ~SWP_WINE_NOHOSTMOVE
;
904 /* Fix redundant flags */
905 if (!fixup_flags( winpos
)) return FALSE
;
907 /* Check window handle */
908 if (winpos
->hwnd
== GetDesktopWindow()) return FALSE
;
910 SWP_DoWinPosChanging( winpos
, &newWindowRect
, &newClientRect
);
912 if (!(wndPtr
= WIN_FindWndPtr( winpos
->hwnd
))) return FALSE
;
914 TRACE("\tcurrent (%ld,%ld)-(%ld,%ld), style %08x\n",
915 wndPtr
->rectWindow
.left
, wndPtr
->rectWindow
.top
,
916 wndPtr
->rectWindow
.right
, wndPtr
->rectWindow
.bottom
, (unsigned)wndPtr
->dwStyle
);
918 if((winpos
->flags
& (SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_SHOWWINDOW
)) != SWP_NOZORDER
)
920 if (GetAncestor( winpos
->hwnd
, GA_PARENT
) == GetDesktopWindow())
921 winpos
->hwndInsertAfter
= SWP_DoOwnedPopups( winpos
->hwnd
, winpos
->hwndInsertAfter
);
924 /* Common operations */
926 wvrFlags
= SWP_DoNCCalcSize( winpos
, &newWindowRect
, &newClientRect
);
928 if(!(winpos
->flags
& SWP_NOZORDER
) && winpos
->hwnd
!= winpos
->hwndInsertAfter
)
930 HWND parent
= GetAncestor( winpos
->hwnd
, GA_PARENT
);
931 if (parent
) WIN_LinkWindow( winpos
->hwnd
, parent
, winpos
->hwndInsertAfter
);
934 /* Reset active DCEs */
936 if( (((winpos
->flags
& SWP_AGG_NOPOSCHANGE
) != SWP_AGG_NOPOSCHANGE
) &&
937 wndPtr
->dwStyle
& WS_VISIBLE
) ||
938 (winpos
->flags
& (SWP_HIDEWINDOW
| SWP_SHOWWINDOW
)) )
942 UnionRect(&rect
, &newWindowRect
, &wndPtr
->rectWindow
);
943 DCE_InvalidateDCE(wndPtr
->hwndSelf
, &rect
);
946 oldWindowRect
= wndPtr
->rectWindow
;
947 oldClientRect
= wndPtr
->rectClient
;
949 /* Find out if we have to redraw the whole client rect */
951 if( oldClientRect
.bottom
- oldClientRect
.top
==
952 newClientRect
.bottom
- newClientRect
.top
) wvrFlags
&= ~WVR_VREDRAW
;
954 if( oldClientRect
.right
- oldClientRect
.left
==
955 newClientRect
.right
- newClientRect
.left
) wvrFlags
&= ~WVR_HREDRAW
;
957 /* FIXME: actually do something with WVR_VALIDRECTS */
959 WIN_SetRectangles( winpos
->hwnd
, &newWindowRect
, &newClientRect
);
961 if (get_whole_window(wndPtr
)) /* don't do anything if X window not created yet */
963 Display
*display
= thread_display();
965 if (!(winpos
->flags
& SWP_SHOWWINDOW
) && (winpos
->flags
& SWP_HIDEWINDOW
))
967 /* clear the update region */
968 RedrawWindow( winpos
->hwnd
, NULL
, 0, RDW_VALIDATE
| RDW_NOFRAME
|
969 RDW_NOERASE
| RDW_NOINTERNALPAINT
| RDW_ALLCHILDREN
);
970 set_visible_style( winpos
->hwnd
, FALSE
);
972 else if ((wndPtr
->dwStyle
& WS_VISIBLE
) &&
973 !IsRectEmpty( &oldWindowRect
) && IsRectEmpty( &newWindowRect
))
975 /* resizing to zero size -> unmap */
976 TRACE( "unmapping zero size win %p\n", winpos
->hwnd
);
977 TSXUnmapWindow( display
, get_whole_window(wndPtr
) );
982 X11DRV_sync_whole_window_position( display
, wndPtr
, !(winpos
->flags
& SWP_NOZORDER
) );
985 struct x11drv_win_data
*data
= wndPtr
->pDriverData
;
986 data
->whole_rect
= wndPtr
->rectWindow
;
987 X11DRV_window_to_X_rect( wndPtr
, &data
->whole_rect
);
990 if (X11DRV_sync_client_window_position( display
, wndPtr
) ||
991 (winpos
->flags
& SWP_FRAMECHANGED
))
993 /* if we moved the client area, repaint the whole non-client window */
994 XClearArea( display
, get_whole_window(wndPtr
), 0, 0, 0, 0, True
);
995 winpos
->flags
|= SWP_FRAMECHANGED
;
997 if (winpos
->flags
& SWP_SHOWWINDOW
)
999 set_visible_style( winpos
->hwnd
, TRUE
);
1001 else if ((wndPtr
->dwStyle
& WS_VISIBLE
) &&
1002 IsRectEmpty( &oldWindowRect
) && !IsRectEmpty( &newWindowRect
))
1004 /* resizing from zero size to non-zero -> map */
1005 TRACE( "mapping non zero size win %p\n", winpos
->hwnd
);
1006 XMapWindow( display
, get_whole_window(wndPtr
) );
1008 XFlush( display
); /* FIXME: should not be necessary */
1009 wine_tsx11_unlock();
1011 else /* no X window, simply toggle the window style */
1013 if (winpos
->flags
& SWP_SHOWWINDOW
)
1014 set_visible_style( winpos
->hwnd
, TRUE
);
1015 else if (winpos
->flags
& SWP_HIDEWINDOW
)
1016 set_visible_style( winpos
->hwnd
, FALSE
);
1019 /* manually expose the areas that X won't expose because they are still covered by something */
1021 if (!(winpos
->flags
& SWP_SHOWWINDOW
))
1022 expose_covered_parent_area( wndPtr
, &oldWindowRect
);
1024 if (wndPtr
->dwStyle
& WS_VISIBLE
)
1025 expose_covered_window_area( wndPtr
, &oldClientRect
, winpos
->flags
& SWP_FRAMECHANGED
);
1027 WIN_ReleaseWndPtr(wndPtr
);
1029 if (wvrFlags
& WVR_REDRAW
) RedrawWindow( winpos
->hwnd
, NULL
, 0, RDW_INVALIDATE
| RDW_ERASE
);
1031 if( winpos
->flags
& SWP_HIDEWINDOW
)
1032 HideCaret(winpos
->hwnd
);
1033 else if (winpos
->flags
& SWP_SHOWWINDOW
)
1034 ShowCaret(winpos
->hwnd
);
1036 if (!(winpos
->flags
& SWP_NOACTIVATE
))
1038 /* child windows get WM_CHILDACTIVATE message */
1039 if ((GetWindowLongW( winpos
->hwnd
, GWL_STYLE
) & (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
1040 SendMessageA( winpos
->hwnd
, WM_CHILDACTIVATE
, 0, 0 );
1042 SetForegroundWindow( winpos
->hwnd
);
1045 /* And last, send the WM_WINDOWPOSCHANGED message */
1047 TRACE("\tstatus flags = %04x\n", winpos
->flags
& SWP_AGG_STATUSFLAGS
);
1049 if (((winpos
->flags
& SWP_AGG_STATUSFLAGS
) != SWP_AGG_NOPOSCHANGE
))
1050 SendMessageA( winpos
->hwnd
, WM_WINDOWPOSCHANGED
, 0, (LPARAM
)winpos
);
1051 /* WM_WINDOWPOSCHANGED is send even if SWP_NOSENDCHANGING is set */
1057 /***********************************************************************
1058 * WINPOS_FindIconPos
1060 * Find a suitable place for an iconic window.
1062 static POINT
WINPOS_FindIconPos( WND
* wndPtr
, POINT pt
)
1066 short x
, y
, xspacing
, yspacing
;
1068 GetClientRect( wndPtr
->parent
, &rectParent
);
1069 if ((pt
.x
>= rectParent
.left
) && (pt
.x
+ GetSystemMetrics(SM_CXICON
) < rectParent
.right
) &&
1070 (pt
.y
>= rectParent
.top
) && (pt
.y
+ GetSystemMetrics(SM_CYICON
) < rectParent
.bottom
))
1071 return pt
; /* The icon already has a suitable position */
1073 xspacing
= GetSystemMetrics(SM_CXICONSPACING
);
1074 yspacing
= GetSystemMetrics(SM_CYICONSPACING
);
1076 list
= WIN_ListChildren( wndPtr
->parent
);
1077 y
= rectParent
.bottom
;
1080 x
= rectParent
.left
;
1083 /* Check if another icon already occupies this spot */
1084 /* FIXME: this is completely inefficient */
1090 for (i
= 0; list
[i
]; i
++)
1092 if (list
[i
] == wndPtr
->hwndSelf
) continue;
1093 if (!IsIconic( list
[i
] )) continue;
1094 if (!(childPtr
= WIN_FindWndPtr( list
[i
] ))) continue;
1095 if ((childPtr
->rectWindow
.left
< x
+ xspacing
) &&
1096 (childPtr
->rectWindow
.right
>= x
) &&
1097 (childPtr
->rectWindow
.top
<= y
) &&
1098 (childPtr
->rectWindow
.bottom
> y
- yspacing
))
1100 WIN_ReleaseWndPtr( childPtr
);
1101 break; /* There's a window in there */
1103 WIN_ReleaseWndPtr( childPtr
);
1107 /* found something here, try next spot */
1113 /* No window was found, so it's OK for us */
1114 pt
.x
= x
+ (xspacing
- GetSystemMetrics(SM_CXICON
)) / 2;
1115 pt
.y
= y
- (yspacing
+ GetSystemMetrics(SM_CYICON
)) / 2;
1116 HeapFree( GetProcessHeap(), 0, list
);
1119 } while(x
<= rectParent
.right
-xspacing
);
1128 UINT
WINPOS_MinMaximize( HWND hwnd
, UINT cmd
, LPRECT rect
)
1134 WINDOWPLACEMENT wpl
;
1136 TRACE("%p %u\n", hwnd
, cmd
);
1138 wpl
.length
= sizeof(wpl
);
1139 GetWindowPlacement( hwnd
, &wpl
);
1141 if (HOOK_CallHooks( WH_CBT
, HCBT_MINMAX
, (WPARAM
)hwnd
, cmd
, TRUE
))
1142 return SWP_NOSIZE
| SWP_NOMOVE
;
1144 if (IsIconic( hwnd
))
1146 if (cmd
== SW_MINIMIZE
) return SWP_NOSIZE
| SWP_NOMOVE
;
1147 if (!SendMessageA( hwnd
, WM_QUERYOPEN
, 0, 0 )) return SWP_NOSIZE
| SWP_NOMOVE
;
1148 swpFlags
|= SWP_NOCOPYBITS
;
1151 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return 0;
1153 size
.x
= wndPtr
->rectWindow
.left
;
1154 size
.y
= wndPtr
->rectWindow
.top
;
1159 if( wndPtr
->dwStyle
& WS_MAXIMIZE
) wndPtr
->flags
|= WIN_RESTORE_MAX
;
1160 else wndPtr
->flags
&= ~WIN_RESTORE_MAX
;
1162 WIN_SetStyle( hwnd
, (wndPtr
->dwStyle
& ~WS_MAXIMIZE
) | WS_MINIMIZE
);
1164 X11DRV_set_iconic_state( wndPtr
);
1166 wpl
.ptMinPosition
= WINPOS_FindIconPos( wndPtr
, wpl
.ptMinPosition
);
1168 SetRect( rect
, wpl
.ptMinPosition
.x
, wpl
.ptMinPosition
.y
,
1169 GetSystemMetrics(SM_CXICON
), GetSystemMetrics(SM_CYICON
) );
1170 swpFlags
|= SWP_NOCOPYBITS
;
1174 WINPOS_GetMinMaxInfo( hwnd
, &size
, &wpl
.ptMaxPosition
, NULL
, NULL
);
1176 old_style
= WIN_SetStyle( hwnd
, (wndPtr
->dwStyle
& ~WS_MINIMIZE
) | WS_MAXIMIZE
);
1177 if (old_style
& WS_MINIMIZE
)
1179 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1180 X11DRV_set_iconic_state( wndPtr
);
1182 SetRect( rect
, wpl
.ptMaxPosition
.x
, wpl
.ptMaxPosition
.y
, size
.x
, size
.y
);
1186 old_style
= WIN_SetStyle( hwnd
, wndPtr
->dwStyle
& ~(WS_MINIMIZE
|WS_MAXIMIZE
) );
1187 if (old_style
& WS_MINIMIZE
)
1189 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1190 X11DRV_set_iconic_state( wndPtr
);
1192 if( wndPtr
->flags
& WIN_RESTORE_MAX
)
1194 /* Restore to maximized position */
1195 WINPOS_GetMinMaxInfo( hwnd
, &size
, &wpl
.ptMaxPosition
, NULL
, NULL
);
1196 WIN_SetStyle( hwnd
, wndPtr
->dwStyle
| WS_MAXIMIZE
);
1197 SetRect( rect
, wpl
.ptMaxPosition
.x
, wpl
.ptMaxPosition
.y
, size
.x
, size
.y
);
1201 else if (!(old_style
& WS_MAXIMIZE
)) break;
1203 /* Restore to normal position */
1205 *rect
= wpl
.rcNormalPosition
;
1206 rect
->right
-= rect
->left
;
1207 rect
->bottom
-= rect
->top
;
1212 WIN_ReleaseWndPtr( wndPtr
);
1217 /***********************************************************************
1218 * ShowWindow (X11DRV.@)
1220 BOOL
X11DRV_ShowWindow( HWND hwnd
, INT cmd
)
1222 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
1223 BOOL wasVisible
, showFlag
;
1224 RECT newPos
= {0, 0, 0, 0};
1227 if (!wndPtr
) return FALSE
;
1228 hwnd
= wndPtr
->hwndSelf
; /* make it a full handle */
1230 TRACE("hwnd=%p, cmd=%d\n", hwnd
, cmd
);
1232 wasVisible
= (wndPtr
->dwStyle
& WS_VISIBLE
) != 0;
1237 if (!wasVisible
) goto END
;
1238 swp
|= SWP_HIDEWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
|
1239 SWP_NOACTIVATE
| SWP_NOZORDER
;
1242 case SW_SHOWMINNOACTIVE
:
1243 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1245 case SW_SHOWMINIMIZED
:
1246 case SW_FORCEMINIMIZE
: /* FIXME: Does not work if thread is hung. */
1247 swp
|= SWP_SHOWWINDOW
;
1250 swp
|= SWP_FRAMECHANGED
;
1251 if( !(wndPtr
->dwStyle
& WS_MINIMIZE
) )
1252 swp
|= WINPOS_MinMaximize( hwnd
, SW_MINIMIZE
, &newPos
);
1253 else swp
|= SWP_NOSIZE
| SWP_NOMOVE
;
1256 case SW_SHOWMAXIMIZED
: /* same as SW_MAXIMIZE */
1257 swp
|= SWP_SHOWWINDOW
| SWP_FRAMECHANGED
;
1258 if( !(wndPtr
->dwStyle
& WS_MAXIMIZE
) )
1259 swp
|= WINPOS_MinMaximize( hwnd
, SW_MAXIMIZE
, &newPos
);
1260 else swp
|= SWP_NOSIZE
| SWP_NOMOVE
;
1264 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1267 swp
|= SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
1270 * ShowWindow has a little peculiar behavior that if the
1271 * window is already the topmost window, it will not
1274 if (GetTopWindow(NULL
)==hwnd
&& (wasVisible
|| GetActiveWindow() == hwnd
))
1275 swp
|= SWP_NOACTIVATE
;
1279 case SW_SHOWNOACTIVATE
:
1280 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1282 case SW_SHOWNORMAL
: /* same as SW_NORMAL: */
1283 case SW_SHOWDEFAULT
: /* FIXME: should have its own handler */
1285 swp
|= SWP_SHOWWINDOW
| SWP_FRAMECHANGED
;
1287 if( wndPtr
->dwStyle
& (WS_MINIMIZE
| WS_MAXIMIZE
) )
1288 swp
|= WINPOS_MinMaximize( hwnd
, SW_RESTORE
, &newPos
);
1289 else swp
|= SWP_NOSIZE
| SWP_NOMOVE
;
1293 showFlag
= (cmd
!= SW_HIDE
);
1294 if (showFlag
!= wasVisible
)
1296 SendMessageA( hwnd
, WM_SHOWWINDOW
, showFlag
, 0 );
1297 if (!IsWindow( hwnd
)) goto END
;
1300 /* We can't activate a child window */
1301 if ((wndPtr
->dwStyle
& WS_CHILD
) &&
1302 !(wndPtr
->dwExStyle
& WS_EX_MDICHILD
))
1303 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1305 SetWindowPos( hwnd
, HWND_TOP
, newPos
.left
, newPos
.top
,
1306 newPos
.right
, newPos
.bottom
, LOWORD(swp
) );
1309 /* FIXME: This will cause the window to be activated irrespective
1310 * of whether it is owned by the same thread. Has to be done
1314 if (hwnd
== GetActiveWindow())
1315 WINPOS_ActivateOtherWindow(hwnd
);
1317 /* Revert focus to parent */
1318 if (hwnd
== GetFocus() || IsChild(hwnd
, GetFocus()))
1319 SetFocus( GetParent(hwnd
) );
1321 if (!IsWindow( hwnd
)) goto END
;
1322 else if( wndPtr
->dwStyle
& WS_MINIMIZE
) WINPOS_ShowIconTitle( hwnd
, TRUE
);
1324 if (wndPtr
->flags
& WIN_NEED_SIZE
)
1326 /* should happen only in CreateWindowEx() */
1327 int wParam
= SIZE_RESTORED
;
1329 wndPtr
->flags
&= ~WIN_NEED_SIZE
;
1330 if (wndPtr
->dwStyle
& WS_MAXIMIZE
) wParam
= SIZE_MAXIMIZED
;
1331 else if (wndPtr
->dwStyle
& WS_MINIMIZE
) wParam
= SIZE_MINIMIZED
;
1332 SendMessageA( hwnd
, WM_SIZE
, wParam
,
1333 MAKELONG(wndPtr
->rectClient
.right
-wndPtr
->rectClient
.left
,
1334 wndPtr
->rectClient
.bottom
-wndPtr
->rectClient
.top
));
1335 SendMessageA( hwnd
, WM_MOVE
, 0,
1336 MAKELONG(wndPtr
->rectClient
.left
, wndPtr
->rectClient
.top
) );
1340 WIN_ReleaseWndPtr(wndPtr
);
1345 /**********************************************************************
1348 void X11DRV_MapNotify( HWND hwnd
, XMapEvent
*event
)
1350 HWND hwndFocus
= GetFocus();
1353 if (!(win
= WIN_GetPtr( hwnd
))) return;
1355 if ((win
->dwStyle
& WS_VISIBLE
) &&
1356 (win
->dwStyle
& WS_MINIMIZE
) &&
1357 (win
->dwExStyle
& WS_EX_MANAGED
))
1360 unsigned int width
, height
, border
, depth
;
1363 LONG style
= (win
->dwStyle
& ~(WS_MINIMIZE
|WS_MAXIMIZE
)) | WS_VISIBLE
;
1367 XGetGeometry( event
->display
, get_whole_window(win
), &root
, &x
, &y
, &width
, &height
,
1369 XTranslateCoordinates( event
->display
, get_whole_window(win
), root
, 0, 0, &x
, &y
, &top
);
1370 wine_tsx11_unlock();
1373 rect
.right
= x
+ width
;
1374 rect
.bottom
= y
+ height
;
1375 X11DRV_X_to_window_rect( win
, &rect
);
1377 DCE_InvalidateDCE( hwnd
, &win
->rectWindow
);
1379 if (win
->flags
& WIN_RESTORE_MAX
) style
|= WS_MAXIMIZE
;
1380 WIN_SetStyle( hwnd
, style
);
1381 WIN_ReleasePtr( win
);
1383 SendMessageA( hwnd
, WM_SHOWWINDOW
, SW_RESTORE
, 0 );
1384 SetWindowPos( hwnd
, 0, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
,
1385 SWP_NOZORDER
| SWP_WINE_NOHOSTMOVE
);
1387 else WIN_ReleasePtr( win
);
1388 if (hwndFocus
&& IsChild( hwnd
, hwndFocus
)) X11DRV_SetFocus(hwndFocus
); /* FIXME */
1392 /**********************************************************************
1393 * X11DRV_UnmapNotify
1395 void X11DRV_UnmapNotify( HWND hwnd
, XUnmapEvent
*event
)
1399 if (!(win
= WIN_GetPtr( hwnd
))) return;
1401 if ((win
->dwStyle
& WS_VISIBLE
) && (win
->dwExStyle
& WS_EX_MANAGED
))
1403 if (win
->dwStyle
& WS_MAXIMIZE
)
1404 win
->flags
|= WIN_RESTORE_MAX
;
1406 win
->flags
&= ~WIN_RESTORE_MAX
;
1408 WIN_SetStyle( hwnd
, (win
->dwStyle
& ~WS_MAXIMIZE
) | WS_MINIMIZE
);
1409 WIN_ReleasePtr( win
);
1412 SendMessageA( hwnd
, WM_SHOWWINDOW
, SW_MINIMIZE
, 0 );
1413 SetWindowPos( hwnd
, 0, 0, 0, GetSystemMetrics(SM_CXICON
), GetSystemMetrics(SM_CYICON
),
1414 SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_WINE_NOHOSTMOVE
);
1416 else WIN_ReleasePtr( win
);
1420 /***********************************************************************
1423 * Synchronize internal z-order with the window manager's.
1425 static Window
__get_common_ancestor( Display
*display
, Window A
, Window B
,
1426 Window
** children
, unsigned* total
)
1428 /* find the real root window */
1430 Window root
, *childrenB
;
1433 while( A
!= B
&& A
&& B
)
1435 TSXQueryTree( display
, A
, &root
, &A
, children
, total
);
1436 TSXQueryTree( display
, B
, &root
, &B
, &childrenB
, &totalB
);
1437 if( childrenB
) TSXFree( childrenB
);
1438 if( *children
) TSXFree( *children
), *children
= NULL
;
1443 TSXQueryTree( display
, A
, &root
, &B
, children
, total
);
1449 static Window
__get_top_decoration( Display
*display
, Window w
, Window ancestor
)
1451 Window
* children
, root
, prev
= w
, parent
= w
;
1457 TSXQueryTree( display
, w
, &root
, &parent
, &children
, &total
);
1458 if( children
) TSXFree( children
);
1459 } while( parent
&& parent
!= ancestor
);
1460 TRACE("\t%08x -> %08x\n", (unsigned)prev
, (unsigned)w
);
1461 return ( parent
) ? w
: 0 ;
1464 static unsigned __td_lookup( Window w
, Window
* list
, unsigned max
)
1467 for( i
= max
; i
> 0; i
-- ) if( list
[i
- 1] == w
) break;
1471 static HWND
query_zorder( Display
*display
, HWND hWndCheck
)
1473 HWND hwndInsertAfter
= HWND_TOP
;
1474 Window w
, parent
, *children
= NULL
;
1475 unsigned total
, check
, pos
, best
;
1476 HWND
*list
= WIN_ListChildren( GetDesktopWindow() );
1477 HWND hwndA
= 0, hwndB
= 0;
1480 /* find at least two managed windows */
1481 if (!list
) return 0;
1482 for (i
= 0; list
[i
]; i
++)
1484 if (!(GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_MANAGED
)) continue;
1485 if (!(GetWindowLongW( list
[i
], GWL_STYLE
) & WS_VISIBLE
)) continue;
1486 if (!hwndA
) hwndA
= list
[i
];
1493 if (!hwndA
|| !hwndB
) goto done
;
1495 parent
= __get_common_ancestor( display
, X11DRV_get_whole_window(hwndA
),
1496 X11DRV_get_whole_window(hwndB
), &children
, &total
);
1497 if( parent
&& children
)
1499 /* w is the ancestor if hWndCheck that is a direct descendant of 'parent' */
1501 w
= __get_top_decoration( display
, X11DRV_get_whole_window(hWndCheck
), parent
);
1503 if( w
!= children
[total
-1] ) /* check if at the top */
1505 /* X child at index 0 is at the bottom, at index total-1 is at the top */
1506 check
= __td_lookup( w
, children
, total
);
1509 /* go through all windows in Wine z-order... */
1510 for (i
= 0; list
[i
]; i
++)
1512 if (list
[i
] == hWndCheck
) continue;
1513 if (!(GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_MANAGED
)) continue;
1514 if (!(w
= __get_top_decoration( display
, X11DRV_get_whole_window(list
[i
]),
1515 parent
))) continue;
1516 pos
= __td_lookup( w
, children
, total
);
1517 if( pos
< best
&& pos
> check
)
1519 /* find a nearest Wine window precedes hWndCheck in the real z-order */
1521 hwndInsertAfter
= list
[i
];
1523 if( best
- check
== 1 ) break;
1527 if( children
) TSXFree( children
);
1530 HeapFree( GetProcessHeap(), 0, list
);
1531 return hwndInsertAfter
;
1535 /***********************************************************************
1536 * X11DRV_ConfigureNotify
1538 void X11DRV_ConfigureNotify( HWND hwnd
, XConfigureEvent
*event
)
1540 HWND oldInsertAfter
;
1541 struct x11drv_win_data
*data
;
1545 int x
= event
->x
, y
= event
->y
;
1547 if (!(win
= WIN_GetPtr( hwnd
))) return;
1548 data
= win
->pDriverData
;
1552 if (!event
->send_event
) /* normal event, need to map coordinates to the root */
1556 XTranslateCoordinates( event
->display
, data
->whole_window
, root_window
,
1557 0, 0, &x
, &y
, &child
);
1558 wine_tsx11_unlock();
1562 rect
.right
= x
+ event
->width
;
1563 rect
.bottom
= y
+ event
->height
;
1564 TRACE( "win %p new X rect %ld,%ld,%ldx%ld (event %d,%d,%dx%d)\n",
1565 hwnd
, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
,
1566 event
->x
, event
->y
, event
->width
, event
->height
);
1567 X11DRV_X_to_window_rect( win
, &rect
);
1568 WIN_ReleasePtr( win
);
1571 winpos
.x
= rect
.left
;
1572 winpos
.y
= rect
.top
;
1573 winpos
.cx
= rect
.right
- rect
.left
;
1574 winpos
.cy
= rect
.bottom
- rect
.top
;
1575 winpos
.flags
= SWP_NOACTIVATE
;
1577 /* Get Z-order (FIXME) */
1579 winpos
.hwndInsertAfter
= query_zorder( event
->display
, hwnd
);
1581 /* needs to find the first Visible Window above the current one */
1582 oldInsertAfter
= hwnd
;
1585 oldInsertAfter
= GetWindow( oldInsertAfter
, GW_HWNDPREV
);
1586 if (!oldInsertAfter
)
1588 oldInsertAfter
= HWND_TOP
;
1591 if (GetWindowLongA( oldInsertAfter
, GWL_STYLE
) & WS_VISIBLE
) break;
1594 /* Compare what has changed */
1596 GetWindowRect( hwnd
, &rect
);
1597 if (rect
.left
== winpos
.x
&& rect
.top
== winpos
.y
) winpos
.flags
|= SWP_NOMOVE
;
1599 TRACE( "%p moving from (%ld,%ld) to (%d,%d)\n",
1600 hwnd
, rect
.left
, rect
.top
, winpos
.x
, winpos
.y
);
1602 if ((rect
.right
- rect
.left
== winpos
.cx
&& rect
.bottom
- rect
.top
== winpos
.cy
) ||
1604 (IsRectEmpty( &rect
) && winpos
.cx
== 1 && winpos
.cy
== 1))
1605 winpos
.flags
|= SWP_NOSIZE
;
1607 TRACE( "%p resizing from (%ldx%ld) to (%dx%d)\n",
1608 hwnd
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
1609 winpos
.cx
, winpos
.cy
);
1611 if (winpos
.hwndInsertAfter
== oldInsertAfter
) winpos
.flags
|= SWP_NOZORDER
;
1613 TRACE( "%p restacking from after %p to after %p\n",
1614 hwnd
, oldInsertAfter
, winpos
.hwndInsertAfter
);
1616 /* if nothing changed, don't do anything */
1617 if (winpos
.flags
== (SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
)) return;
1619 SetWindowPos( hwnd
, winpos
.hwndInsertAfter
, winpos
.x
, winpos
.y
,
1620 winpos
.cx
, winpos
.cy
, winpos
.flags
| SWP_WINE_NOHOSTMOVE
);
1624 /***********************************************************************
1625 * SetWindowRgn (X11DRV.@)
1627 * Assign specified region to window (for non-rectangular windows)
1629 int X11DRV_SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL redraw
)
1633 if ((wndPtr
= WIN_GetPtr( hwnd
)) == WND_OTHER_PROCESS
)
1635 if (IsWindow( hwnd
))
1636 FIXME( "not supported on other process window %p\n", hwnd
);
1641 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
1645 if (wndPtr
->hrgnWnd
== hrgn
)
1647 WIN_ReleasePtr( wndPtr
);
1651 if (wndPtr
->hrgnWnd
)
1653 /* delete previous region */
1654 DeleteObject(wndPtr
->hrgnWnd
);
1655 wndPtr
->hrgnWnd
= 0;
1657 wndPtr
->hrgnWnd
= hrgn
;
1659 #ifdef HAVE_LIBXSHAPE
1661 Display
*display
= thread_display();
1662 X11DRV_WND_DATA
*data
= wndPtr
->pDriverData
;
1664 if (data
->whole_window
)
1669 XShapeCombineMask( display
, data
->whole_window
,
1670 ShapeBounding
, 0, 0, None
, ShapeSet
);
1671 wine_tsx11_unlock();
1676 int x_offset
, y_offset
;
1678 DWORD dwBufferSize
= GetRegionData(hrgn
, 0, NULL
);
1679 PRGNDATA pRegionData
= HeapAlloc(GetProcessHeap(), 0, dwBufferSize
);
1682 WIN_ReleasePtr( wndPtr
);
1685 GetRegionData(hrgn
, dwBufferSize
, pRegionData
);
1686 size
= pRegionData
->rdh
.nCount
;
1687 x_offset
= wndPtr
->rectWindow
.left
- data
->whole_rect
.left
;
1688 y_offset
= wndPtr
->rectWindow
.top
- data
->whole_rect
.top
;
1689 /* convert region's "Windows rectangles" to XRectangles */
1690 aXRect
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(*aXRect
) );
1693 XRectangle
* pCurrRect
= aXRect
;
1694 RECT
*pRect
= (RECT
*) pRegionData
->Buffer
;
1695 for (; pRect
< ((RECT
*) pRegionData
->Buffer
) + size
; ++pRect
, ++pCurrRect
)
1697 pCurrRect
->x
= pRect
->left
+ x_offset
;
1698 pCurrRect
->y
= pRect
->top
+ y_offset
;
1699 pCurrRect
->height
= pRect
->bottom
- pRect
->top
;
1700 pCurrRect
->width
= pRect
->right
- pRect
->left
;
1702 TRACE("Rectangle %04d of %04ld data: X=%04d, Y=%04d, Height=%04d, Width=%04d.\n",
1703 pRect
- (RECT
*) pRegionData
->Buffer
,
1711 /* shape = non-rectangular windows (X11/extensions) */
1713 XShapeCombineRectangles( display
, data
->whole_window
, ShapeBounding
,
1715 pCurrRect
- aXRect
, ShapeSet
, YXBanded
);
1716 wine_tsx11_unlock();
1717 HeapFree(GetProcessHeap(), 0, aXRect
);
1719 HeapFree(GetProcessHeap(), 0, pRegionData
);
1723 #endif /* HAVE_LIBXSHAPE */
1725 WIN_ReleasePtr( wndPtr
);
1726 if (redraw
) RedrawWindow( hwnd
, NULL
, 0, RDW_FRAME
| RDW_INVALIDATE
| RDW_ERASE
);
1731 /***********************************************************************
1734 * Draw the frame used when moving or resizing window.
1736 * FIXME: This causes problems in Win95 mode. (why?)
1738 static void draw_moving_frame( HDC hdc
, RECT
*rect
, BOOL thickframe
)
1742 const int width
= GetSystemMetrics(SM_CXFRAME
);
1743 const int height
= GetSystemMetrics(SM_CYFRAME
);
1745 HBRUSH hbrush
= SelectObject( hdc
, GetStockObject( GRAY_BRUSH
) );
1746 PatBlt( hdc
, rect
->left
, rect
->top
,
1747 rect
->right
- rect
->left
- width
, height
, PATINVERT
);
1748 PatBlt( hdc
, rect
->left
, rect
->top
+ height
, width
,
1749 rect
->bottom
- rect
->top
- height
, PATINVERT
);
1750 PatBlt( hdc
, rect
->left
+ width
, rect
->bottom
- 1,
1751 rect
->right
- rect
->left
- width
, -height
, PATINVERT
);
1752 PatBlt( hdc
, rect
->right
- 1, rect
->top
, -width
,
1753 rect
->bottom
- rect
->top
- height
, PATINVERT
);
1754 SelectObject( hdc
, hbrush
);
1756 else DrawFocusRect( hdc
, rect
);
1760 /***********************************************************************
1763 * Initialisation of a move or resize, when initiatied from a menu choice.
1764 * Return hit test code for caption or sizing border.
1766 static LONG
start_size_move( HWND hwnd
, WPARAM wParam
, POINT
*capturePoint
, LONG style
)
1773 GetWindowRect( hwnd
, &rectWindow
);
1775 if ((wParam
& 0xfff0) == SC_MOVE
)
1777 /* Move pointer at the center of the caption */
1779 NC_GetInsideRect( hwnd
, &rect
);
1780 if (style
& WS_SYSMENU
)
1781 rect
.left
+= GetSystemMetrics(SM_CXSIZE
) + 1;
1782 if (style
& WS_MINIMIZEBOX
)
1783 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
1784 if (style
& WS_MAXIMIZEBOX
)
1785 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
1786 pt
.x
= rectWindow
.left
+ (rect
.right
- rect
.left
) / 2;
1787 pt
.y
= rectWindow
.top
+ rect
.top
+ GetSystemMetrics(SM_CYSIZE
)/2;
1788 hittest
= HTCAPTION
;
1795 GetMessageW( &msg
, 0, WM_KEYFIRST
, WM_MOUSELAST
);
1796 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
1801 hittest
= NC_HandleNCHitTest( hwnd
, msg
.pt
);
1802 if ((hittest
< HTLEFT
) || (hittest
> HTBOTTOMRIGHT
))
1814 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
1815 pt
.y
= rectWindow
.top
+ GetSystemMetrics(SM_CYFRAME
) / 2;
1819 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
1820 pt
.y
= rectWindow
.bottom
- GetSystemMetrics(SM_CYFRAME
) / 2;
1824 pt
.x
= rectWindow
.left
+ GetSystemMetrics(SM_CXFRAME
) / 2;
1825 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
1829 pt
.x
= rectWindow
.right
- GetSystemMetrics(SM_CXFRAME
) / 2;
1830 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
1833 case VK_ESCAPE
: return 0;
1839 SetCursorPos( pt
.x
, pt
.y
);
1840 NC_HandleSetCursor( hwnd
, (WPARAM
)hwnd
, MAKELONG( hittest
, WM_MOUSEMOVE
));
1845 /***********************************************************************
1846 * set_movesize_capture
1848 static void set_movesize_capture( HWND hwnd
)
1852 SERVER_START_REQ( set_capture_window
)
1855 req
->flags
= CAPTURE_MOVESIZE
;
1856 if (!wine_server_call_err( req
))
1858 previous
= reply
->previous
;
1859 hwnd
= reply
->full_handle
;
1863 if (previous
&& previous
!= hwnd
)
1864 SendMessageW( previous
, WM_CAPTURECHANGED
, 0, (LPARAM
)hwnd
);
1868 /***********************************************************************
1869 * SysCommandSizeMove (X11DRV.@)
1871 * Perform SC_MOVE and SC_SIZE commands.
1873 void X11DRV_SysCommandSizeMove( HWND hwnd
, WPARAM wParam
)
1876 RECT sizingRect
, mouseRect
, origRect
;
1879 LONG hittest
= (LONG
)(wParam
& 0x0f);
1880 HCURSOR hDragCursor
= 0, hOldCursor
= 0;
1881 POINT minTrack
, maxTrack
;
1882 POINT capturePoint
, pt
;
1883 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
1884 LONG exstyle
= GetWindowLongA( hwnd
, GWL_EXSTYLE
);
1885 BOOL thickframe
= HAS_THICKFRAME( style
, exstyle
);
1886 BOOL iconic
= style
& WS_MINIMIZE
;
1888 DWORD dwPoint
= GetMessagePos ();
1889 BOOL DragFullWindows
= FALSE
;
1892 Display
*old_gdi_display
= NULL
;
1893 Display
*display
= thread_display();
1895 SystemParametersInfoA(SPI_GETDRAGFULLWINDOWS
, 0, &DragFullWindows
, 0);
1897 pt
.x
= SLOWORD(dwPoint
);
1898 pt
.y
= SHIWORD(dwPoint
);
1901 if (IsZoomed(hwnd
) || !IsWindowVisible(hwnd
) || (exstyle
& WS_EX_MANAGED
)) return;
1903 if ((wParam
& 0xfff0) == SC_MOVE
)
1905 if (!hittest
) hittest
= start_size_move( hwnd
, wParam
, &capturePoint
, style
);
1906 if (!hittest
) return;
1910 if (!thickframe
) return;
1911 if ( hittest
&& ((wParam
& 0xfff0) != SC_MOUSEMENU
) )
1912 hittest
+= (HTLEFT
- WMSZ_LEFT
);
1915 set_movesize_capture( hwnd
);
1916 hittest
= start_size_move( hwnd
, wParam
, &capturePoint
, style
);
1919 set_movesize_capture(0);
1925 /* Get min/max info */
1927 WINPOS_GetMinMaxInfo( hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
1928 GetWindowRect( hwnd
, &sizingRect
);
1929 if (style
& WS_CHILD
)
1931 parent
= GetParent(hwnd
);
1932 /* make sizing rect relative to parent */
1933 MapWindowPoints( 0, parent
, (POINT
*)&sizingRect
, 2 );
1934 GetClientRect( parent
, &mouseRect
);
1939 SetRect(&mouseRect
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
));
1941 origRect
= sizingRect
;
1943 if (ON_LEFT_BORDER(hittest
))
1945 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.right
-maxTrack
.x
);
1946 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.right
-minTrack
.x
);
1948 else if (ON_RIGHT_BORDER(hittest
))
1950 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.left
+minTrack
.x
);
1951 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.left
+maxTrack
.x
);
1953 if (ON_TOP_BORDER(hittest
))
1955 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.bottom
-maxTrack
.y
);
1956 mouseRect
.bottom
= min( mouseRect
.bottom
,sizingRect
.bottom
-minTrack
.y
);
1958 else if (ON_BOTTOM_BORDER(hittest
))
1960 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.top
+minTrack
.y
);
1961 mouseRect
.bottom
= min( mouseRect
.bottom
, sizingRect
.top
+maxTrack
.y
);
1963 if (parent
) MapWindowPoints( parent
, 0, (LPPOINT
)&mouseRect
, 2 );
1965 /* Retrieve a default cache DC (without using the window style) */
1966 hdc
= GetDCEx( parent
, 0, DCX_CACHE
);
1968 if( iconic
) /* create a cursor for dragging */
1970 hDragCursor
= (HCURSOR
)GetClassLongA( hwnd
, GCL_HICON
);
1971 if( !hDragCursor
) hDragCursor
= (HCURSOR
)SendMessageA( hwnd
, WM_QUERYDRAGICON
, 0, 0L);
1972 if( !hDragCursor
) iconic
= FALSE
;
1975 /* repaint the window before moving it around */
1976 RedrawWindow( hwnd
, NULL
, 0, RDW_UPDATENOW
| RDW_ALLCHILDREN
);
1978 SendMessageA( hwnd
, WM_ENTERSIZEMOVE
, 0, 0 );
1979 set_movesize_capture( hwnd
);
1981 /* grab the server only when moving top-level windows without desktop */
1982 grab
= (!DragFullWindows
&& !parent
&& (root_window
== DefaultRootWindow(gdi_display
)));
1987 XSync( gdi_display
, False
);
1988 XGrabServer( display
);
1989 XSync( display
, False
);
1990 /* switch gdi display to the thread display, since the server is grabbed */
1991 old_gdi_display
= gdi_display
;
1992 gdi_display
= display
;
1994 XGrabPointer( display
, X11DRV_get_whole_window(hwnd
), False
,
1995 PointerMotionMask
| ButtonPressMask
| ButtonReleaseMask
,
1996 GrabModeAsync
, GrabModeAsync
,
1997 parent
? X11DRV_get_client_window(parent
) : root_window
,
1998 None
, CurrentTime
);
1999 wine_tsx11_unlock();
2005 if (!GetMessageW( &msg
, 0, WM_KEYFIRST
, WM_MOUSELAST
)) break;
2006 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
2008 /* Exit on button-up, Return, or Esc */
2009 if ((msg
.message
== WM_LBUTTONUP
) ||
2010 ((msg
.message
== WM_KEYDOWN
) &&
2011 ((msg
.wParam
== VK_RETURN
) || (msg
.wParam
== VK_ESCAPE
)))) break;
2013 if ((msg
.message
!= WM_KEYDOWN
) && (msg
.message
!= WM_MOUSEMOVE
))
2014 continue; /* We are not interested in other messages */
2018 if (msg
.message
== WM_KEYDOWN
) switch(msg
.wParam
)
2020 case VK_UP
: pt
.y
-= 8; break;
2021 case VK_DOWN
: pt
.y
+= 8; break;
2022 case VK_LEFT
: pt
.x
-= 8; break;
2023 case VK_RIGHT
: pt
.x
+= 8; break;
2026 pt
.x
= max( pt
.x
, mouseRect
.left
);
2027 pt
.x
= min( pt
.x
, mouseRect
.right
);
2028 pt
.y
= max( pt
.y
, mouseRect
.top
);
2029 pt
.y
= min( pt
.y
, mouseRect
.bottom
);
2031 dx
= pt
.x
- capturePoint
.x
;
2032 dy
= pt
.y
- capturePoint
.y
;
2040 if( iconic
) /* ok, no system popup tracking */
2042 hOldCursor
= SetCursor(hDragCursor
);
2044 WINPOS_ShowIconTitle( hwnd
, FALSE
);
2046 else if(!DragFullWindows
)
2047 draw_moving_frame( hdc
, &sizingRect
, thickframe
);
2050 if (msg
.message
== WM_KEYDOWN
) SetCursorPos( pt
.x
, pt
.y
);
2053 RECT newRect
= sizingRect
;
2054 WPARAM wpSizingHit
= 0;
2056 if (hittest
== HTCAPTION
) OffsetRect( &newRect
, dx
, dy
);
2057 if (ON_LEFT_BORDER(hittest
)) newRect
.left
+= dx
;
2058 else if (ON_RIGHT_BORDER(hittest
)) newRect
.right
+= dx
;
2059 if (ON_TOP_BORDER(hittest
)) newRect
.top
+= dy
;
2060 else if (ON_BOTTOM_BORDER(hittest
)) newRect
.bottom
+= dy
;
2061 if(!iconic
&& !DragFullWindows
) draw_moving_frame( hdc
, &sizingRect
, thickframe
);
2064 /* determine the hit location */
2065 if (hittest
>= HTLEFT
&& hittest
<= HTBOTTOMRIGHT
)
2066 wpSizingHit
= WMSZ_LEFT
+ (hittest
- HTLEFT
);
2067 SendMessageA( hwnd
, WM_SIZING
, wpSizingHit
, (LPARAM
)&newRect
);
2071 if(!DragFullWindows
)
2072 draw_moving_frame( hdc
, &newRect
, thickframe
);
2074 /* To avoid any deadlocks, all the locks on the windows
2075 structures must be suspended before the SetWindowPos */
2076 iWndsLocks
= WIN_SuspendWndsLock();
2077 SetWindowPos( hwnd
, 0, newRect
.left
, newRect
.top
,
2078 newRect
.right
- newRect
.left
,
2079 newRect
.bottom
- newRect
.top
,
2080 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
2081 WIN_RestoreWndsLock(iWndsLocks
);
2084 sizingRect
= newRect
;
2089 set_movesize_capture(0);
2092 if( moved
) /* restore cursors, show icon title later on */
2094 ShowCursor( FALSE
);
2095 SetCursor( hOldCursor
);
2098 else if (moved
&& !DragFullWindows
)
2099 draw_moving_frame( hdc
, &sizingRect
, thickframe
);
2101 ReleaseDC( parent
, hdc
);
2104 XUngrabPointer( display
, CurrentTime
);
2107 XSync( display
, False
);
2108 XUngrabServer( display
);
2109 XSync( display
, False
);
2110 gdi_display
= old_gdi_display
;
2112 wine_tsx11_unlock();
2114 if (HOOK_CallHooks( WH_CBT
, HCBT_MOVESIZE
, (WPARAM
)hwnd
, (LPARAM
)&sizingRect
, TRUE
))
2117 SendMessageA( hwnd
, WM_EXITSIZEMOVE
, 0, 0 );
2118 SendMessageA( hwnd
, WM_SETVISIBLE
, !IsIconic(hwnd
), 0L);
2120 /* window moved or resized */
2123 /* To avoid any deadlocks, all the locks on the windows
2124 structures must be suspended before the SetWindowPos */
2125 iWndsLocks
= WIN_SuspendWndsLock();
2127 /* if the moving/resizing isn't canceled call SetWindowPos
2128 * with the new position or the new size of the window
2130 if (!((msg
.message
== WM_KEYDOWN
) && (msg
.wParam
== VK_ESCAPE
)) )
2132 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
2133 if(!DragFullWindows
)
2134 SetWindowPos( hwnd
, 0, sizingRect
.left
, sizingRect
.top
,
2135 sizingRect
.right
- sizingRect
.left
,
2136 sizingRect
.bottom
- sizingRect
.top
,
2137 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
2140 { /* restore previous size/position */
2142 SetWindowPos( hwnd
, 0, origRect
.left
, origRect
.top
,
2143 origRect
.right
- origRect
.left
,
2144 origRect
.bottom
- origRect
.top
,
2145 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
2148 WIN_RestoreWndsLock(iWndsLocks
);
2153 /* Single click brings up the system menu when iconized */
2157 if(style
& WS_SYSMENU
)
2158 SendMessageA( hwnd
, WM_SYSCOMMAND
,
2159 SC_MOUSEMENU
+ HTSYSMENU
, MAKELONG(pt
.x
,pt
.y
));
2161 else WINPOS_ShowIconTitle( hwnd
, TRUE
);
2166 /***********************************************************************
2167 * ForceWindowRaise (X11DRV.@)
2169 * Raise a window on top of the X stacking order, while preserving
2170 * the correct Windows Z order.
2172 * FIXME: this should go away.
2174 void X11DRV_ForceWindowRaise( HWND hwnd
)
2178 XWindowChanges winChanges
;
2179 Display
*display
= thread_display();
2180 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
2182 if (!wndPtr
) return;
2184 if ((wndPtr
->dwExStyle
& WS_EX_MANAGED
) ||
2185 wndPtr
->parent
!= GetDesktopWindow() ||
2186 IsRectEmpty( &wndPtr
->rectWindow
) ||
2187 !get_whole_window(wndPtr
))
2189 WIN_ReleaseWndPtr( wndPtr
);
2192 WIN_ReleaseWndPtr( wndPtr
);
2194 /* Raise all windows up to wndPtr according to their Z order.
2195 * (it would be easier with sibling-related Below but it doesn't
2196 * work very well with SGI mwm for instance)
2198 winChanges
.stack_mode
= Above
;
2199 if (!(list
= WIN_ListChildren( GetDesktopWindow() ))) return;
2200 while (list
[i
] && list
[i
] != hwnd
) i
++;
2203 for ( ; i
>= 0; i
--)
2205 WND
*ptr
= WIN_FindWndPtr( list
[i
] );
2207 if (!IsRectEmpty( &ptr
->rectWindow
) && get_whole_window(ptr
))
2208 TSXReconfigureWMWindow( display
, get_whole_window(ptr
), 0,
2209 CWStackMode
, &winChanges
);
2210 WIN_ReleaseWndPtr( ptr
);
2213 HeapFree( GetProcessHeap(), 0, list
);