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 */
39 #include "cursoricon.h"
40 #include "nonclient.h"
43 #include "wine/server.h"
44 #include "wine/debug.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(x11drv
);
48 #define SWP_AGG_NOGEOMETRYCHANGE \
49 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE)
50 #define SWP_AGG_NOPOSCHANGE \
51 (SWP_AGG_NOGEOMETRYCHANGE | SWP_NOZORDER)
52 #define SWP_AGG_STATUSFLAGS \
53 (SWP_AGG_NOPOSCHANGE | SWP_FRAMECHANGED | SWP_HIDEWINDOW | SWP_SHOWWINDOW)
55 #define SWP_EX_NOCOPY 0x0001
56 #define SWP_EX_PAINTSELF 0x0002
57 #define SWP_EX_NONCLIENT 0x0004
59 #define HAS_THICKFRAME(style,exStyle) \
60 (((style) & WS_THICKFRAME) && \
61 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
63 #define ON_LEFT_BORDER(hit) \
64 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
65 #define ON_RIGHT_BORDER(hit) \
66 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
67 #define ON_TOP_BORDER(hit) \
68 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
69 #define ON_BOTTOM_BORDER(hit) \
70 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
73 /***********************************************************************
76 * Clip all children of a given window out of the visible region
78 static int clip_children( HWND parent
, HWND last
, HRGN hrgn
, int whole_window
)
83 int i
, x
, y
, ret
= SIMPLEREGION
;
85 /* first check if we have anything to do */
86 if (!(list
= WIN_ListChildren( parent
))) return ret
;
87 for (i
= 0; list
[i
] && list
[i
] != last
; i
++)
88 if (GetWindowLongW( list
[i
], GWL_STYLE
) & WS_VISIBLE
) break;
89 if (!list
[i
] || list
[i
] == last
) goto done
; /* no children to clip */
93 WND
*win
= WIN_FindWndPtr( parent
);
94 x
= win
->rectWindow
.left
- win
->rectClient
.left
;
95 y
= win
->rectWindow
.top
- win
->rectClient
.top
;
96 WIN_ReleaseWndPtr( win
);
100 rectRgn
= CreateRectRgn( 0, 0, 0, 0 );
102 for ( ; list
[i
] && list
[i
] != last
; i
++)
104 if (!(ptr
= WIN_FindWndPtr( list
[i
] ))) continue;
105 if (ptr
->dwStyle
& WS_VISIBLE
)
107 SetRectRgn( rectRgn
, ptr
->rectWindow
.left
+ x
, ptr
->rectWindow
.top
+ y
,
108 ptr
->rectWindow
.right
+ x
, ptr
->rectWindow
.bottom
+ y
);
109 if ((ret
= CombineRgn( hrgn
, hrgn
, rectRgn
, RGN_DIFF
)) == NULLREGION
)
111 WIN_ReleaseWndPtr( ptr
);
112 break; /* no need to go on, region is empty */
115 WIN_ReleaseWndPtr( ptr
);
117 DeleteObject( rectRgn
);
119 HeapFree( GetProcessHeap(), 0, list
);
124 /***********************************************************************
127 * Compute the visible region of a window
129 static HRGN
get_visible_region( WND
*win
, HWND top
, UINT flags
, int mode
)
133 int xoffset
, yoffset
;
134 X11DRV_WND_DATA
*data
= win
->pDriverData
;
136 if (flags
& DCX_WINDOW
)
138 xoffset
= win
->rectWindow
.left
;
139 yoffset
= win
->rectWindow
.top
;
143 xoffset
= win
->rectClient
.left
;
144 yoffset
= win
->rectClient
.top
;
147 if (flags
& DCX_PARENTCLIP
)
148 GetClientRect( win
->parent
, &rect
);
149 else if (flags
& DCX_WINDOW
)
150 rect
= data
->whole_rect
;
152 rect
= win
->rectClient
;
154 /* vis region is relative to the start of the client/window area */
155 OffsetRect( &rect
, -xoffset
, -yoffset
);
157 if (!(rgn
= CreateRectRgn( rect
.left
, rect
.top
, rect
.right
, rect
.bottom
))) return 0;
159 if ((flags
& DCX_CLIPCHILDREN
) && (mode
!= ClipByChildren
))
161 /* we need to clip children by hand */
162 if (clip_children( win
->hwndSelf
, 0, rgn
, (flags
& DCX_WINDOW
) ) == NULLREGION
) return rgn
;
165 if (top
&& top
!= win
->hwndSelf
) /* need to clip siblings of ancestors */
167 WND
*parent
, *ptr
= WIN_FindWndPtr( win
->hwndSelf
);
170 OffsetRgn( rgn
, xoffset
, yoffset
);
173 if (ptr
->dwStyle
& WS_CLIPSIBLINGS
)
175 if (clip_children( ptr
->parent
, ptr
->hwndSelf
, rgn
, FALSE
) == NULLREGION
) break;
177 if (ptr
->hwndSelf
== top
) break;
178 if (!(parent
= WIN_FindWndPtr( ptr
->parent
))) break;
179 WIN_ReleaseWndPtr( ptr
);
181 /* clip to parent client area */
182 if (tmp
) SetRectRgn( tmp
, 0, 0, ptr
->rectClient
.right
- ptr
->rectClient
.left
,
183 ptr
->rectClient
.bottom
- ptr
->rectClient
.top
);
184 else tmp
= CreateRectRgn( 0, 0, ptr
->rectClient
.right
- ptr
->rectClient
.left
,
185 ptr
->rectClient
.bottom
- ptr
->rectClient
.top
);
186 CombineRgn( rgn
, rgn
, tmp
, RGN_AND
);
187 OffsetRgn( rgn
, ptr
->rectClient
.left
, ptr
->rectClient
.top
);
188 xoffset
+= ptr
->rectClient
.left
;
189 yoffset
+= ptr
->rectClient
.top
;
191 WIN_ReleaseWndPtr( ptr
);
192 /* make it relative to the target window again */
193 OffsetRgn( rgn
, -xoffset
, -yoffset
);
194 if (tmp
) DeleteObject( tmp
);
201 /***********************************************************************
204 * Compute the portion of 'rgn' that is covered by non-clipped siblings.
205 * This is the area that is covered from X point of view, but may still need
207 * 'rgn' must be relative to the client area of the parent of 'win'.
209 static int get_covered_region( WND
*win
, HRGN rgn
)
213 WND
*parent
, *ptr
= WIN_FindWndPtr( win
->hwndSelf
);
214 int xoffset
= 0, yoffset
= 0;
216 tmp
= CreateRectRgn( 0, 0, 0, 0 );
217 CombineRgn( tmp
, rgn
, 0, RGN_COPY
);
219 /* to make things easier we actually build the uncovered
220 * area by removing all siblings and then we subtract that
221 * from the total region to get the covered area */
224 if (!(ptr
->dwStyle
& WS_CLIPSIBLINGS
))
226 if (clip_children( ptr
->parent
, ptr
->hwndSelf
, tmp
, FALSE
) == NULLREGION
) break;
228 if (!(parent
= WIN_FindWndPtr( ptr
->parent
))) break;
229 WIN_ReleaseWndPtr( ptr
);
231 OffsetRgn( tmp
, ptr
->rectClient
.left
, ptr
->rectClient
.top
);
232 xoffset
+= ptr
->rectClient
.left
;
233 yoffset
+= ptr
->rectClient
.top
;
235 WIN_ReleaseWndPtr( ptr
);
236 /* make it relative to the target window again */
237 OffsetRgn( tmp
, -xoffset
, -yoffset
);
239 /* now subtract the computed region from the original one */
240 ret
= CombineRgn( rgn
, rgn
, tmp
, RGN_DIFF
);
246 /***********************************************************************
249 * Expose a region of a given window.
251 static void expose_window( HWND hwnd
, RECT
*rect
, HRGN rgn
, int flags
)
258 /* find the top most parent that doesn't clip children or siblings and
259 * invalidate the area on its parent, including all children */
260 if ((list
= WIN_ListParents( hwnd
)))
263 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
264 for (i
= 0; list
[i
] && list
[i
] != GetDesktopWindow(); i
++)
266 if (!(style
& WS_CLIPSIBLINGS
)) top
= current
;
267 style
= GetWindowLongW( list
[i
], GWL_STYLE
);
268 if (!(style
& WS_CLIPCHILDREN
)) top
= current
;
274 /* find the parent of the top window, reusing the parent list */
275 if (top
== hwnd
) i
= 0;
278 for (i
= 0; list
[i
]; i
++) if (list
[i
] == top
) break;
279 if (list
[i
] && list
[i
+1]) i
++;
281 if (list
[i
] != GetDesktopWindow()) top
= list
[i
];
282 flags
&= ~RDW_FRAME
; /* parent will invalidate children frame anyway */
283 flags
|= RDW_ALLCHILDREN
;
285 HeapFree( GetProcessHeap(), 0, list
);
288 if (!top
) top
= hwnd
;
290 /* make coords relative to top */
291 offset
.x
= offset
.y
= 0;
292 MapWindowPoints( hwnd
, top
, &offset
, 1 );
296 OffsetRect( rect
, offset
.x
, offset
.y
);
297 RedrawWindow( top
, rect
, 0, flags
);
301 OffsetRgn( rgn
, offset
.x
, offset
.y
);
302 RedrawWindow( top
, NULL
, rgn
, flags
);
307 /***********************************************************************
308 * expose_covered_parent_area
310 * Expose the parent area that has been uncovered by moving/hiding a
311 * given window, but that is still covered by other siblings (the area
312 * not covered by siblings will be exposed automatically by X).
314 static void expose_covered_parent_area( WND
*win
, const RECT
*old_rect
)
316 int ret
= SIMPLEREGION
;
317 HRGN hrgn
= CreateRectRgnIndirect( old_rect
);
319 if (win
->dwStyle
& WS_VISIBLE
)
321 HRGN tmp
= CreateRectRgnIndirect( &win
->rectWindow
);
322 ret
= CombineRgn( hrgn
, hrgn
, tmp
, RGN_DIFF
);
326 if (ret
!= NULLREGION
)
328 if (get_covered_region( win
, hrgn
) != NULLREGION
)
329 expose_window( win
->parent
, NULL
, hrgn
, RDW_INVALIDATE
| RDW_ERASE
| RDW_ALLCHILDREN
);
331 DeleteObject( hrgn
);
335 /***********************************************************************
336 * expose_covered_window_area
338 * Expose the area of a window that is covered by other siblings.
340 static void expose_covered_window_area( WND
*win
, const RECT
*old_client_rect
, BOOL frame
)
343 int ret
= SIMPLEREGION
;
346 hrgn
= CreateRectRgn( win
->rectWindow
.left
- win
->rectClient
.left
,
347 win
->rectWindow
.top
- win
->rectClient
.top
,
348 win
->rectWindow
.right
- win
->rectWindow
.left
,
349 win
->rectWindow
.bottom
- win
->rectWindow
.top
);
351 hrgn
= CreateRectRgn( 0, 0,
352 win
->rectClient
.right
- win
->rectClient
.left
,
353 win
->rectClient
.bottom
- win
->rectClient
.top
);
355 /* if the client rect didn't move we don't need to repaint it all */
356 if (old_client_rect
->left
== win
->rectClient
.left
&&
357 old_client_rect
->top
== win
->rectClient
.top
)
361 if (IntersectRect( &rc
, old_client_rect
, &win
->rectClient
))
364 /* subtract the unchanged client area from the region to expose */
365 OffsetRect( &rc
, -win
->rectClient
.left
, -win
->rectClient
.top
);
366 if ((tmp
= CreateRectRgnIndirect( &rc
)))
368 ret
= CombineRgn( hrgn
, hrgn
, tmp
, RGN_DIFF
);
374 if (ret
!= NULLREGION
)
376 if (get_covered_region( win
, hrgn
) != NULLREGION
)
377 expose_window( win
->hwndSelf
, NULL
, hrgn
,
378 RDW_INVALIDATE
| RDW_ERASE
| RDW_FRAME
| RDW_ALLCHILDREN
);
381 DeleteObject( hrgn
);
385 /***********************************************************************
388 void X11DRV_Expose( HWND hwnd
, XExposeEvent
*event
)
391 struct x11drv_win_data
*data
;
392 int flags
= RDW_INVALIDATE
| RDW_ERASE
;
395 TRACE( "win %x (%lx) %d,%d %dx%d\n",
396 hwnd
, event
->window
, event
->x
, event
->y
, event
->width
, event
->height
);
398 rect
.left
= event
->x
;
400 rect
.right
= rect
.left
+ event
->width
;
401 rect
.bottom
= rect
.top
+ event
->height
;
403 if (!(win
= WIN_GetPtr( hwnd
))) return;
404 data
= win
->pDriverData
;
406 if (event
->window
!= data
->client_window
) /* whole window or icon window */
409 /* make position relative to client area instead of window */
410 OffsetRect( &rect
, -data
->client_rect
.left
, -data
->client_rect
.top
);
412 WIN_ReleasePtr( win
);
414 expose_window( hwnd
, &rect
, 0, flags
);
418 /***********************************************************************
421 * Set the drawable, origin and dimensions for the DC associated to
424 BOOL
X11DRV_GetDC( HWND hwnd
, HDC hdc
, HRGN hrgn
, DWORD flags
)
426 WND
*win
= WIN_GetPtr( hwnd
);
428 X11DRV_WND_DATA
*data
= win
->pDriverData
;
431 POINT org
, drawable_org
;
432 int mode
= IncludeInferiors
;
434 /* don't clip siblings if using parent clip region */
435 if (flags
& DCX_PARENTCLIP
) flags
&= ~DCX_CLIPSIBLINGS
;
437 /* find the top parent in the hierarchy that isn't clipping siblings */
438 visible
= (win
->dwStyle
& WS_VISIBLE
) != 0;
442 HWND
*list
= WIN_ListParents( hwnd
);
446 for (i
= 0; list
[i
] != GetDesktopWindow(); i
++)
448 LONG style
= GetWindowLongW( list
[i
], GWL_STYLE
);
449 if (!(style
& WS_VISIBLE
))
455 if (!(style
& WS_CLIPSIBLINGS
)) top
= list
[i
];
457 HeapFree( GetProcessHeap(), 0, list
);
459 if (!top
&& visible
&& !(flags
& DCX_CLIPSIBLINGS
)) top
= hwnd
;
464 HWND parent
= GetAncestor( top
, GA_PARENT
);
466 if (flags
& DCX_WINDOW
)
468 org
.x
= win
->rectWindow
.left
- win
->rectClient
.left
;
469 org
.y
= win
->rectWindow
.top
- win
->rectClient
.top
;
472 MapWindowPoints( hwnd
, parent
, &org
, 1 );
473 MapWindowPoints( hwnd
, 0, &drawable_org
, 1 );
474 /* have to use the parent so that we include siblings */
475 if (parent
) drawable
= X11DRV_get_client_window( parent
);
476 else drawable
= root_window
;
480 if (IsIconic( hwnd
))
482 drawable
= data
->icon_window
? data
->icon_window
: data
->whole_window
;
487 else if (flags
& DCX_WINDOW
)
489 drawable
= data
->whole_window
;
490 org
.x
= win
->rectWindow
.left
- data
->whole_rect
.left
;
491 org
.y
= win
->rectWindow
.top
- data
->whole_rect
.top
;
492 drawable_org
.x
= data
->whole_rect
.left
- win
->rectClient
.left
;
493 drawable_org
.y
= data
->whole_rect
.top
- win
->rectClient
.top
;
497 drawable
= data
->client_window
;
501 if (flags
& DCX_CLIPCHILDREN
) mode
= ClipByChildren
; /* can use X11 clipping */
503 MapWindowPoints( hwnd
, 0, &drawable_org
, 1 );
506 X11DRV_SetDrawable( hdc
, drawable
, mode
, &org
, &drawable_org
);
508 if (flags
& (DCX_EXCLUDERGN
| DCX_INTERSECTRGN
) ||
509 SetHookFlags16( hdc
, DCHF_VALIDATEVISRGN
)) /* DC was dirty */
511 /* need to recompute the visible region */
516 visRgn
= get_visible_region( win
, top
, flags
, mode
);
518 if (flags
& (DCX_EXCLUDERGN
| DCX_INTERSECTRGN
))
519 CombineRgn( visRgn
, visRgn
, hrgn
,
520 (flags
& DCX_INTERSECTRGN
) ? RGN_AND
: RGN_DIFF
);
522 else visRgn
= CreateRectRgn( 0, 0, 0, 0 );
524 SelectVisRgn16( hdc
, visRgn
);
525 DeleteObject( visRgn
);
528 WIN_ReleasePtr( win
);
534 /***********************************************************************
535 * SWP_DoWinPosChanging
537 static BOOL
SWP_DoWinPosChanging( WINDOWPOS
* pWinpos
, RECT
* pNewWindowRect
, RECT
* pNewClientRect
)
541 /* Send WM_WINDOWPOSCHANGING message */
543 if (!(pWinpos
->flags
& SWP_NOSENDCHANGING
))
544 SendMessageA( pWinpos
->hwnd
, WM_WINDOWPOSCHANGING
, 0, (LPARAM
)pWinpos
);
546 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return FALSE
;
548 /* Calculate new position and size */
550 *pNewWindowRect
= wndPtr
->rectWindow
;
551 *pNewClientRect
= (wndPtr
->dwStyle
& WS_MINIMIZE
) ? wndPtr
->rectWindow
552 : wndPtr
->rectClient
;
554 if (!(pWinpos
->flags
& SWP_NOSIZE
))
556 pNewWindowRect
->right
= pNewWindowRect
->left
+ pWinpos
->cx
;
557 pNewWindowRect
->bottom
= pNewWindowRect
->top
+ pWinpos
->cy
;
559 if (!(pWinpos
->flags
& SWP_NOMOVE
))
561 pNewWindowRect
->left
= pWinpos
->x
;
562 pNewWindowRect
->top
= pWinpos
->y
;
563 pNewWindowRect
->right
+= pWinpos
->x
- wndPtr
->rectWindow
.left
;
564 pNewWindowRect
->bottom
+= pWinpos
->y
- wndPtr
->rectWindow
.top
;
566 OffsetRect( pNewClientRect
, pWinpos
->x
- wndPtr
->rectWindow
.left
,
567 pWinpos
->y
- wndPtr
->rectWindow
.top
);
569 pWinpos
->flags
|= SWP_NOCLIENTMOVE
| SWP_NOCLIENTSIZE
;
570 WIN_ReleasePtr( wndPtr
);
574 /***********************************************************************
577 static UINT
SWP_DoNCCalcSize( WINDOWPOS
* pWinpos
, RECT
* pNewWindowRect
, RECT
* pNewClientRect
)
582 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
584 /* Send WM_NCCALCSIZE message to get new client area */
585 if( (pWinpos
->flags
& (SWP_FRAMECHANGED
| SWP_NOSIZE
)) != SWP_NOSIZE
)
587 NCCALCSIZE_PARAMS params
;
588 WINDOWPOS winposCopy
;
590 params
.rgrc
[0] = *pNewWindowRect
;
591 params
.rgrc
[1] = wndPtr
->rectWindow
;
592 params
.rgrc
[2] = wndPtr
->rectClient
;
593 params
.lppos
= &winposCopy
;
594 winposCopy
= *pWinpos
;
595 WIN_ReleasePtr( wndPtr
);
597 wvrFlags
= SendMessageW( pWinpos
->hwnd
, WM_NCCALCSIZE
, TRUE
, (LPARAM
)¶ms
);
599 TRACE( "%d,%d-%d,%d\n", params
.rgrc
[0].left
, params
.rgrc
[0].top
,
600 params
.rgrc
[0].right
, params
.rgrc
[0].bottom
);
602 /* If the application send back garbage, ignore it */
603 if (params
.rgrc
[0].left
<= params
.rgrc
[0].right
&&
604 params
.rgrc
[0].top
<= params
.rgrc
[0].bottom
)
605 *pNewClientRect
= params
.rgrc
[0];
607 /* FIXME: WVR_ALIGNxxx */
609 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
611 if( pNewClientRect
->left
!= wndPtr
->rectClient
.left
||
612 pNewClientRect
->top
!= wndPtr
->rectClient
.top
)
613 pWinpos
->flags
&= ~SWP_NOCLIENTMOVE
;
615 if( (pNewClientRect
->right
- pNewClientRect
->left
!=
616 wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
) ||
617 (pNewClientRect
->bottom
- pNewClientRect
->top
!=
618 wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
) )
619 pWinpos
->flags
&= ~SWP_NOCLIENTSIZE
;
623 if (!(pWinpos
->flags
& SWP_NOMOVE
) &&
624 (pNewClientRect
->left
!= wndPtr
->rectClient
.left
||
625 pNewClientRect
->top
!= wndPtr
->rectClient
.top
))
626 pWinpos
->flags
&= ~SWP_NOCLIENTMOVE
;
628 WIN_ReleasePtr( wndPtr
);
633 /***********************************************************************
636 * fix Z order taking into account owned popups -
637 * basically we need to maintain them above the window that owns them
639 * FIXME: hide/show owned popups when owner visibility changes.
641 static HWND
SWP_DoOwnedPopups(HWND hwnd
, HWND hwndInsertAfter
)
644 HWND owner
= GetWindow( hwnd
, GW_OWNER
);
645 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
647 WARN("(%04x) hInsertAfter = %04x\n", hwnd
, hwndInsertAfter
);
649 if ((style
& WS_POPUP
) && owner
)
651 /* make sure this popup stays above the owner */
653 HWND hwndLocalPrev
= HWND_TOP
;
655 if( hwndInsertAfter
!= HWND_TOP
)
657 if ((list
= WIN_ListChildren( GetDesktopWindow() )))
660 for (i
= 0; list
[i
]; i
++)
662 if (list
[i
] == owner
) break;
663 if (list
[i
] != hwnd
) hwndLocalPrev
= list
[i
];
664 if (hwndLocalPrev
== hwndInsertAfter
) break;
666 hwndInsertAfter
= hwndLocalPrev
;
670 else if (style
& WS_CHILD
) return hwndInsertAfter
;
672 if (!list
) list
= WIN_ListChildren( GetDesktopWindow() );
676 for (i
= 0; list
[i
]; i
++)
678 if (list
[i
] == hwnd
) break;
679 if ((GetWindowLongW( list
[i
], GWL_STYLE
) & WS_POPUP
) &&
680 GetWindow( list
[i
], GW_OWNER
) == hwnd
)
682 SetWindowPos( list
[i
], hwndInsertAfter
, 0, 0, 0, 0,
683 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
|
684 SWP_NOSENDCHANGING
| SWP_DEFERERASE
);
685 hwndInsertAfter
= list
[i
];
688 HeapFree( GetProcessHeap(), 0, list
);
691 return hwndInsertAfter
;
695 /* fix redundant flags and values in the WINDOWPOS structure */
696 static BOOL
fixup_flags( WINDOWPOS
*winpos
)
698 WND
*wndPtr
= WIN_GetPtr( winpos
->hwnd
);
701 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
)
703 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
706 winpos
->hwnd
= wndPtr
->hwndSelf
; /* make it a full handle */
708 if (wndPtr
->dwStyle
& WS_VISIBLE
) winpos
->flags
&= ~SWP_SHOWWINDOW
;
711 winpos
->flags
&= ~SWP_HIDEWINDOW
;
712 if (!(winpos
->flags
& SWP_SHOWWINDOW
)) winpos
->flags
|= SWP_NOREDRAW
;
715 if (winpos
->cx
< 0) winpos
->cx
= 0;
716 if (winpos
->cy
< 0) winpos
->cy
= 0;
718 if ((wndPtr
->rectWindow
.right
- wndPtr
->rectWindow
.left
== winpos
->cx
) &&
719 (wndPtr
->rectWindow
.bottom
- wndPtr
->rectWindow
.top
== winpos
->cy
))
720 winpos
->flags
|= SWP_NOSIZE
; /* Already the right size */
722 if ((wndPtr
->rectWindow
.left
== winpos
->x
) && (wndPtr
->rectWindow
.top
== winpos
->y
))
723 winpos
->flags
|= SWP_NOMOVE
; /* Already the right position */
725 if (winpos
->hwnd
== GetForegroundWindow())
726 winpos
->flags
|= SWP_NOACTIVATE
; /* Already active */
727 else if ((wndPtr
->dwStyle
& (WS_POPUP
| WS_CHILD
)) != WS_CHILD
)
729 if (!(winpos
->flags
& SWP_NOACTIVATE
)) /* Bring to the top when activating */
731 winpos
->flags
&= ~SWP_NOZORDER
;
732 winpos
->hwndInsertAfter
= HWND_TOP
;
737 /* Check hwndInsertAfter */
738 if (winpos
->flags
& SWP_NOZORDER
) goto done
;
740 /* fix sign extension */
741 if (winpos
->hwndInsertAfter
== (HWND
)0xffff) winpos
->hwndInsertAfter
= HWND_TOPMOST
;
742 else if (winpos
->hwndInsertAfter
== (HWND
)0xfffe) winpos
->hwndInsertAfter
= HWND_NOTOPMOST
;
744 /* FIXME: TOPMOST not supported yet */
745 if ((winpos
->hwndInsertAfter
== HWND_TOPMOST
) ||
746 (winpos
->hwndInsertAfter
== HWND_NOTOPMOST
)) winpos
->hwndInsertAfter
= HWND_TOP
;
748 /* hwndInsertAfter must be a sibling of the window */
749 if ((winpos
->hwndInsertAfter
!= HWND_TOP
) && (winpos
->hwndInsertAfter
!= HWND_BOTTOM
))
751 winpos
->hwndInsertAfter
= WIN_GetFullHandle( winpos
->hwndInsertAfter
);
752 if (GetAncestor( winpos
->hwndInsertAfter
, GA_PARENT
) != wndPtr
->parent
) ret
= FALSE
;
755 /* don't need to change the Zorder of hwnd if it's already inserted
756 * after hwndInsertAfter or when inserting hwnd after itself.
758 if ((winpos
->hwnd
== winpos
->hwndInsertAfter
) ||
759 (winpos
->hwnd
== GetWindow( winpos
->hwndInsertAfter
, GW_HWNDNEXT
)))
760 winpos
->flags
|= SWP_NOZORDER
;
764 WIN_ReleasePtr( wndPtr
);
769 /***********************************************************************
772 * Set/clear the WS_VISIBLE style of a window and map/unmap the X window.
774 static void set_visible_style( HWND hwnd
, BOOL set
)
778 if (!(win
= WIN_GetPtr( hwnd
))) return;
779 if (win
== WND_OTHER_PROCESS
) return;
781 TRACE( "hwnd %x (%lx) set %d visible %d empty %d\n",
782 hwnd
, get_whole_window(win
),
783 set
, (win
->dwStyle
& WS_VISIBLE
) != 0, IsRectEmpty(&win
->rectWindow
) );
787 if (win
->dwStyle
& WS_VISIBLE
) goto done
;
788 WIN_SetStyle( hwnd
, win
->dwStyle
| WS_VISIBLE
);
789 if (!IsRectEmpty( &win
->rectWindow
) && get_whole_window(win
) && is_window_top_level(win
))
791 Display
*display
= thread_display();
792 X11DRV_sync_window_style( display
, win
);
793 X11DRV_set_wm_hints( display
, win
);
794 TRACE( "mapping win %x\n", hwnd
);
795 TSXMapWindow( display
, get_whole_window(win
) );
800 if (!(win
->dwStyle
& WS_VISIBLE
)) goto done
;
801 WIN_SetStyle( hwnd
, win
->dwStyle
& ~WS_VISIBLE
);
802 if (!IsRectEmpty( &win
->rectWindow
) && get_whole_window(win
) && is_window_top_level(win
))
804 TRACE( "unmapping win %x\n", hwnd
);
805 TSXUnmapWindow( thread_display(), get_whole_window(win
) );
809 WIN_ReleasePtr( win
);
813 /***********************************************************************
814 * SetWindowStyle (X11DRV.@)
816 * Update the X state of a window to reflect a style change
818 void X11DRV_SetWindowStyle( HWND hwnd
, LONG oldStyle
)
820 Display
*display
= thread_display();
824 if (hwnd
== GetDesktopWindow()) return;
825 if (!(wndPtr
= WIN_GetPtr( hwnd
))) return;
826 if (wndPtr
== WND_OTHER_PROCESS
) return;
828 changed
= wndPtr
->dwStyle
^ oldStyle
;
830 if (changed
& WS_VISIBLE
)
832 if (!IsRectEmpty( &wndPtr
->rectWindow
) && !is_window_top_level(wndPtr
))
834 if (wndPtr
->dwStyle
& WS_VISIBLE
)
836 TRACE( "mapping win %x\n", hwnd
);
837 TSXMapWindow( display
, get_whole_window(wndPtr
) );
841 TRACE( "unmapping win %x\n", hwnd
);
842 TSXUnmapWindow( display
, get_whole_window(wndPtr
) );
847 if (changed
& WS_DISABLED
)
849 if (wndPtr
->dwExStyle
& WS_EX_MANAGED
)
853 if (!(wm_hints
= XGetWMHints( display
, get_whole_window(wndPtr
) )))
854 wm_hints
= XAllocWMHints();
857 wm_hints
->flags
|= InputHint
;
858 wm_hints
->input
= !(wndPtr
->dwStyle
& WS_DISABLED
);
859 XSetWMHints( display
, get_whole_window(wndPtr
), wm_hints
);
865 WIN_ReleasePtr(wndPtr
);
869 /***********************************************************************
870 * SetWindowPos (X11DRV.@)
872 BOOL
X11DRV_SetWindowPos( WINDOWPOS
*winpos
)
875 RECT newWindowRect
, newClientRect
;
876 RECT oldWindowRect
, oldClientRect
;
880 TRACE( "hwnd %04x, swp (%i,%i)-(%i,%i) flags %08x\n",
881 winpos
->hwnd
, winpos
->x
, winpos
->y
,
882 winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
, winpos
->flags
);
884 bChangePos
= !(winpos
->flags
& SWP_WINE_NOHOSTMOVE
);
885 winpos
->flags
&= ~SWP_WINE_NOHOSTMOVE
;
887 /* Fix redundant flags */
888 if (!fixup_flags( winpos
)) return FALSE
;
890 /* Check window handle */
891 if (winpos
->hwnd
== GetDesktopWindow()) return FALSE
;
893 SWP_DoWinPosChanging( winpos
, &newWindowRect
, &newClientRect
);
895 if (!(wndPtr
= WIN_FindWndPtr( winpos
->hwnd
))) return FALSE
;
897 TRACE("\tcurrent (%i,%i)-(%i,%i), style %08x\n",
898 wndPtr
->rectWindow
.left
, wndPtr
->rectWindow
.top
,
899 wndPtr
->rectWindow
.right
, wndPtr
->rectWindow
.bottom
, (unsigned)wndPtr
->dwStyle
);
901 if((winpos
->flags
& (SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_SHOWWINDOW
)) != SWP_NOZORDER
)
903 if (GetAncestor( winpos
->hwnd
, GA_PARENT
) == GetDesktopWindow())
904 winpos
->hwndInsertAfter
= SWP_DoOwnedPopups( winpos
->hwnd
, winpos
->hwndInsertAfter
);
907 /* Common operations */
909 wvrFlags
= SWP_DoNCCalcSize( winpos
, &newWindowRect
, &newClientRect
);
911 if(!(winpos
->flags
& SWP_NOZORDER
) && winpos
->hwnd
!= winpos
->hwndInsertAfter
)
913 HWND parent
= GetAncestor( winpos
->hwnd
, GA_PARENT
);
914 if (parent
) WIN_LinkWindow( winpos
->hwnd
, parent
, winpos
->hwndInsertAfter
);
917 /* Reset active DCEs */
919 if( (((winpos
->flags
& SWP_AGG_NOPOSCHANGE
) != SWP_AGG_NOPOSCHANGE
) &&
920 wndPtr
->dwStyle
& WS_VISIBLE
) ||
921 (winpos
->flags
& (SWP_HIDEWINDOW
| SWP_SHOWWINDOW
)) )
925 UnionRect(&rect
, &newWindowRect
, &wndPtr
->rectWindow
);
926 DCE_InvalidateDCE(wndPtr
->hwndSelf
, &rect
);
929 oldWindowRect
= wndPtr
->rectWindow
;
930 oldClientRect
= wndPtr
->rectClient
;
932 /* Find out if we have to redraw the whole client rect */
934 if( oldClientRect
.bottom
- oldClientRect
.top
==
935 newClientRect
.bottom
- newClientRect
.top
) wvrFlags
&= ~WVR_VREDRAW
;
937 if( oldClientRect
.right
- oldClientRect
.left
==
938 newClientRect
.right
- newClientRect
.left
) wvrFlags
&= ~WVR_HREDRAW
;
940 /* FIXME: actually do something with WVR_VALIDRECTS */
942 WIN_SetRectangles( winpos
->hwnd
, &newWindowRect
, &newClientRect
);
944 if (get_whole_window(wndPtr
)) /* don't do anything if X window not created yet */
946 Display
*display
= thread_display();
948 if (!(winpos
->flags
& SWP_SHOWWINDOW
) && (winpos
->flags
& SWP_HIDEWINDOW
))
950 /* clear the update region */
951 RedrawWindow( winpos
->hwnd
, NULL
, 0, RDW_VALIDATE
| RDW_NOFRAME
|
952 RDW_NOERASE
| RDW_NOINTERNALPAINT
| RDW_ALLCHILDREN
);
953 set_visible_style( winpos
->hwnd
, FALSE
);
955 else if ((wndPtr
->dwStyle
& WS_VISIBLE
) &&
956 !IsRectEmpty( &oldWindowRect
) && IsRectEmpty( &newWindowRect
))
958 /* resizing to zero size -> unmap */
959 TRACE( "unmapping zero size win %x\n", winpos
->hwnd
);
960 TSXUnmapWindow( display
, get_whole_window(wndPtr
) );
965 X11DRV_sync_whole_window_position( display
, wndPtr
, !(winpos
->flags
& SWP_NOZORDER
) );
968 struct x11drv_win_data
*data
= wndPtr
->pDriverData
;
969 data
->whole_rect
= wndPtr
->rectWindow
;
970 X11DRV_window_to_X_rect( wndPtr
, &data
->whole_rect
);
973 if (X11DRV_sync_client_window_position( display
, wndPtr
) ||
974 (winpos
->flags
& SWP_FRAMECHANGED
))
976 /* if we moved the client area, repaint the whole non-client window */
977 XClearArea( display
, get_whole_window(wndPtr
), 0, 0, 0, 0, True
);
978 winpos
->flags
|= SWP_FRAMECHANGED
;
980 if (winpos
->flags
& SWP_SHOWWINDOW
)
982 set_visible_style( winpos
->hwnd
, TRUE
);
984 else if ((wndPtr
->dwStyle
& WS_VISIBLE
) &&
985 IsRectEmpty( &oldWindowRect
) && !IsRectEmpty( &newWindowRect
))
987 /* resizing from zero size to non-zero -> map */
988 TRACE( "mapping non zero size win %x\n", winpos
->hwnd
);
989 XMapWindow( display
, get_whole_window(wndPtr
) );
991 XFlush( display
); /* FIXME: should not be necessary */
994 else /* no X window, simply toggle the window style */
996 if (winpos
->flags
& SWP_SHOWWINDOW
)
997 set_visible_style( winpos
->hwnd
, TRUE
);
998 else if (winpos
->flags
& SWP_HIDEWINDOW
)
999 set_visible_style( winpos
->hwnd
, FALSE
);
1002 /* manually expose the areas that X won't expose because they are still covered by something */
1004 if (!(winpos
->flags
& SWP_SHOWWINDOW
))
1005 expose_covered_parent_area( wndPtr
, &oldWindowRect
);
1007 if (wndPtr
->dwStyle
& WS_VISIBLE
)
1008 expose_covered_window_area( wndPtr
, &oldClientRect
, winpos
->flags
& SWP_FRAMECHANGED
);
1010 WIN_ReleaseWndPtr(wndPtr
);
1012 if (wvrFlags
& WVR_REDRAW
) RedrawWindow( winpos
->hwnd
, NULL
, 0, RDW_INVALIDATE
| RDW_ERASE
);
1014 if( winpos
->flags
& SWP_HIDEWINDOW
)
1015 HideCaret(winpos
->hwnd
);
1016 else if (winpos
->flags
& SWP_SHOWWINDOW
)
1017 ShowCaret(winpos
->hwnd
);
1019 if (!(winpos
->flags
& SWP_NOACTIVATE
))
1021 /* child windows get WM_CHILDACTIVATE message */
1022 if ((GetWindowLongW( winpos
->hwnd
, GWL_STYLE
) & (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
1023 SendMessageA( winpos
->hwnd
, WM_CHILDACTIVATE
, 0, 0 );
1025 SetForegroundWindow( winpos
->hwnd
);
1028 /* And last, send the WM_WINDOWPOSCHANGED message */
1030 TRACE("\tstatus flags = %04x\n", winpos
->flags
& SWP_AGG_STATUSFLAGS
);
1032 if (((winpos
->flags
& SWP_AGG_STATUSFLAGS
) != SWP_AGG_NOPOSCHANGE
))
1033 SendMessageA( winpos
->hwnd
, WM_WINDOWPOSCHANGED
, 0, (LPARAM
)winpos
);
1034 /* WM_WINDOWPOSCHANGED is send even if SWP_NOSENDCHANGING is set */
1040 /***********************************************************************
1041 * WINPOS_FindIconPos
1043 * Find a suitable place for an iconic window.
1045 static POINT
WINPOS_FindIconPos( WND
* wndPtr
, POINT pt
)
1049 short x
, y
, xspacing
, yspacing
;
1051 GetClientRect( wndPtr
->parent
, &rectParent
);
1052 if ((pt
.x
>= rectParent
.left
) && (pt
.x
+ GetSystemMetrics(SM_CXICON
) < rectParent
.right
) &&
1053 (pt
.y
>= rectParent
.top
) && (pt
.y
+ GetSystemMetrics(SM_CYICON
) < rectParent
.bottom
))
1054 return pt
; /* The icon already has a suitable position */
1056 xspacing
= GetSystemMetrics(SM_CXICONSPACING
);
1057 yspacing
= GetSystemMetrics(SM_CYICONSPACING
);
1059 list
= WIN_ListChildren( wndPtr
->parent
);
1060 y
= rectParent
.bottom
;
1063 x
= rectParent
.left
;
1066 /* Check if another icon already occupies this spot */
1067 /* FIXME: this is completely inefficient */
1073 for (i
= 0; list
[i
]; i
++)
1075 if (list
[i
] == wndPtr
->hwndSelf
) continue;
1076 if (!IsIconic( list
[i
] )) continue;
1077 if (!(childPtr
= WIN_FindWndPtr( list
[i
] ))) continue;
1078 if ((childPtr
->rectWindow
.left
< x
+ xspacing
) &&
1079 (childPtr
->rectWindow
.right
>= x
) &&
1080 (childPtr
->rectWindow
.top
<= y
) &&
1081 (childPtr
->rectWindow
.bottom
> y
- yspacing
))
1083 WIN_ReleaseWndPtr( childPtr
);
1084 break; /* There's a window in there */
1086 WIN_ReleaseWndPtr( childPtr
);
1090 /* found something here, try next spot */
1096 /* No window was found, so it's OK for us */
1097 pt
.x
= x
+ (xspacing
- GetSystemMetrics(SM_CXICON
)) / 2;
1098 pt
.y
= y
- (yspacing
+ GetSystemMetrics(SM_CYICON
)) / 2;
1099 HeapFree( GetProcessHeap(), 0, list
);
1102 } while(x
<= rectParent
.right
-xspacing
);
1111 UINT
WINPOS_MinMaximize( HWND hwnd
, UINT cmd
, LPRECT rect
)
1117 WINDOWPLACEMENT wpl
;
1119 TRACE("0x%04x %u\n", hwnd
, cmd
);
1121 wpl
.length
= sizeof(wpl
);
1122 GetWindowPlacement( hwnd
, &wpl
);
1124 if (HOOK_CallHooks( WH_CBT
, HCBT_MINMAX
, (WPARAM
)hwnd
, cmd
, TRUE
))
1125 return SWP_NOSIZE
| SWP_NOMOVE
;
1127 if (IsIconic( hwnd
))
1129 if (cmd
== SW_MINIMIZE
) return SWP_NOSIZE
| SWP_NOMOVE
;
1130 if (!SendMessageA( hwnd
, WM_QUERYOPEN
, 0, 0 )) return SWP_NOSIZE
| SWP_NOMOVE
;
1131 swpFlags
|= SWP_NOCOPYBITS
;
1134 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return 0;
1136 size
.x
= wndPtr
->rectWindow
.left
;
1137 size
.y
= wndPtr
->rectWindow
.top
;
1142 if( wndPtr
->dwStyle
& WS_MAXIMIZE
) wndPtr
->flags
|= WIN_RESTORE_MAX
;
1143 else wndPtr
->flags
&= ~WIN_RESTORE_MAX
;
1145 WIN_SetStyle( hwnd
, (wndPtr
->dwStyle
& ~WS_MAXIMIZE
) | WS_MINIMIZE
);
1147 X11DRV_set_iconic_state( wndPtr
);
1149 wpl
.ptMinPosition
= WINPOS_FindIconPos( wndPtr
, wpl
.ptMinPosition
);
1151 SetRect( rect
, wpl
.ptMinPosition
.x
, wpl
.ptMinPosition
.y
,
1152 GetSystemMetrics(SM_CXICON
), GetSystemMetrics(SM_CYICON
) );
1153 swpFlags
|= SWP_NOCOPYBITS
;
1157 WINPOS_GetMinMaxInfo( hwnd
, &size
, &wpl
.ptMaxPosition
, NULL
, NULL
);
1159 old_style
= WIN_SetStyle( hwnd
, (wndPtr
->dwStyle
& ~WS_MINIMIZE
) | WS_MAXIMIZE
);
1160 if (old_style
& WS_MINIMIZE
)
1162 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1163 X11DRV_set_iconic_state( wndPtr
);
1165 SetRect( rect
, wpl
.ptMaxPosition
.x
, wpl
.ptMaxPosition
.y
, size
.x
, size
.y
);
1169 old_style
= WIN_SetStyle( hwnd
, wndPtr
->dwStyle
& ~(WS_MINIMIZE
|WS_MAXIMIZE
) );
1170 if (old_style
& WS_MINIMIZE
)
1172 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1173 X11DRV_set_iconic_state( wndPtr
);
1175 if( wndPtr
->flags
& WIN_RESTORE_MAX
)
1177 /* Restore to maximized position */
1178 WINPOS_GetMinMaxInfo( hwnd
, &size
, &wpl
.ptMaxPosition
, NULL
, NULL
);
1179 WIN_SetStyle( hwnd
, wndPtr
->dwStyle
| WS_MAXIMIZE
);
1180 SetRect( rect
, wpl
.ptMaxPosition
.x
, wpl
.ptMaxPosition
.y
, size
.x
, size
.y
);
1184 else if (!(old_style
& WS_MAXIMIZE
)) break;
1186 /* Restore to normal position */
1188 *rect
= wpl
.rcNormalPosition
;
1189 rect
->right
-= rect
->left
;
1190 rect
->bottom
-= rect
->top
;
1195 WIN_ReleaseWndPtr( wndPtr
);
1200 /***********************************************************************
1201 * ShowWindow (X11DRV.@)
1203 BOOL
X11DRV_ShowWindow( HWND hwnd
, INT cmd
)
1205 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
1206 BOOL wasVisible
, showFlag
;
1207 RECT newPos
= {0, 0, 0, 0};
1210 if (!wndPtr
) return FALSE
;
1211 hwnd
= wndPtr
->hwndSelf
; /* make it a full handle */
1213 TRACE("hwnd=%04x, cmd=%d\n", hwnd
, cmd
);
1215 wasVisible
= (wndPtr
->dwStyle
& WS_VISIBLE
) != 0;
1220 if (!wasVisible
) goto END
;
1221 swp
|= SWP_HIDEWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
|
1222 SWP_NOACTIVATE
| SWP_NOZORDER
;
1225 case SW_SHOWMINNOACTIVE
:
1226 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1228 case SW_SHOWMINIMIZED
:
1229 case SW_FORCEMINIMIZE
: /* FIXME: Does not work if thread is hung. */
1230 swp
|= SWP_SHOWWINDOW
;
1233 swp
|= SWP_FRAMECHANGED
;
1234 if( !(wndPtr
->dwStyle
& WS_MINIMIZE
) )
1235 swp
|= WINPOS_MinMaximize( hwnd
, SW_MINIMIZE
, &newPos
);
1236 else swp
|= SWP_NOSIZE
| SWP_NOMOVE
;
1239 case SW_SHOWMAXIMIZED
: /* same as SW_MAXIMIZE */
1240 swp
|= SWP_SHOWWINDOW
| SWP_FRAMECHANGED
;
1241 if( !(wndPtr
->dwStyle
& WS_MAXIMIZE
) )
1242 swp
|= WINPOS_MinMaximize( hwnd
, SW_MAXIMIZE
, &newPos
);
1243 else swp
|= SWP_NOSIZE
| SWP_NOMOVE
;
1247 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1250 swp
|= SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
1253 * ShowWindow has a little peculiar behavior that if the
1254 * window is already the topmost window, it will not
1257 if (GetTopWindow((HWND
)0)==hwnd
&& (wasVisible
|| GetActiveWindow() == hwnd
))
1258 swp
|= SWP_NOACTIVATE
;
1262 case SW_SHOWNOACTIVATE
:
1263 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1265 case SW_SHOWNORMAL
: /* same as SW_NORMAL: */
1266 case SW_SHOWDEFAULT
: /* FIXME: should have its own handler */
1268 swp
|= SWP_SHOWWINDOW
| SWP_FRAMECHANGED
;
1270 if( wndPtr
->dwStyle
& (WS_MINIMIZE
| WS_MAXIMIZE
) )
1271 swp
|= WINPOS_MinMaximize( hwnd
, SW_RESTORE
, &newPos
);
1272 else swp
|= SWP_NOSIZE
| SWP_NOMOVE
;
1276 showFlag
= (cmd
!= SW_HIDE
);
1277 if (showFlag
!= wasVisible
)
1279 SendMessageA( hwnd
, WM_SHOWWINDOW
, showFlag
, 0 );
1280 if (!IsWindow( hwnd
)) goto END
;
1283 /* We can't activate a child window */
1284 if ((wndPtr
->dwStyle
& WS_CHILD
) &&
1285 !(wndPtr
->dwExStyle
& WS_EX_MDICHILD
))
1286 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1288 SetWindowPos( hwnd
, HWND_TOP
, newPos
.left
, newPos
.top
,
1289 newPos
.right
, newPos
.bottom
, LOWORD(swp
) );
1292 /* FIXME: This will cause the window to be activated irrespective
1293 * of whether it is owned by the same thread. Has to be done
1297 if (hwnd
== GetActiveWindow())
1298 WINPOS_ActivateOtherWindow(hwnd
);
1300 /* Revert focus to parent */
1301 if (hwnd
== GetFocus() || IsChild(hwnd
, GetFocus()))
1302 SetFocus( GetParent(hwnd
) );
1304 if (!IsWindow( hwnd
)) goto END
;
1305 else if( wndPtr
->dwStyle
& WS_MINIMIZE
) WINPOS_ShowIconTitle( hwnd
, TRUE
);
1307 if (wndPtr
->flags
& WIN_NEED_SIZE
)
1309 /* should happen only in CreateWindowEx() */
1310 int wParam
= SIZE_RESTORED
;
1312 wndPtr
->flags
&= ~WIN_NEED_SIZE
;
1313 if (wndPtr
->dwStyle
& WS_MAXIMIZE
) wParam
= SIZE_MAXIMIZED
;
1314 else if (wndPtr
->dwStyle
& WS_MINIMIZE
) wParam
= SIZE_MINIMIZED
;
1315 SendMessageA( hwnd
, WM_SIZE
, wParam
,
1316 MAKELONG(wndPtr
->rectClient
.right
-wndPtr
->rectClient
.left
,
1317 wndPtr
->rectClient
.bottom
-wndPtr
->rectClient
.top
));
1318 SendMessageA( hwnd
, WM_MOVE
, 0,
1319 MAKELONG(wndPtr
->rectClient
.left
, wndPtr
->rectClient
.top
) );
1323 WIN_ReleaseWndPtr(wndPtr
);
1328 /**********************************************************************
1331 void X11DRV_MapNotify( HWND hwnd
, XMapEvent
*event
)
1333 HWND hwndFocus
= GetFocus();
1336 if (!(win
= WIN_GetPtr( hwnd
))) return;
1338 if ((win
->dwStyle
& WS_VISIBLE
) &&
1339 (win
->dwStyle
& WS_MINIMIZE
) &&
1340 (win
->dwExStyle
& WS_EX_MANAGED
))
1343 unsigned int width
, height
, border
, depth
;
1346 LONG style
= (win
->dwStyle
& ~(WS_MINIMIZE
|WS_MAXIMIZE
)) | WS_VISIBLE
;
1350 XGetGeometry( event
->display
, get_whole_window(win
), &root
, &x
, &y
, &width
, &height
,
1352 XTranslateCoordinates( event
->display
, get_whole_window(win
), root
, 0, 0, &x
, &y
, &top
);
1353 wine_tsx11_unlock();
1356 rect
.right
= x
+ width
;
1357 rect
.bottom
= y
+ height
;
1358 X11DRV_X_to_window_rect( win
, &rect
);
1360 DCE_InvalidateDCE( hwnd
, &win
->rectWindow
);
1362 if (win
->flags
& WIN_RESTORE_MAX
) style
|= WS_MAXIMIZE
;
1363 WIN_SetStyle( hwnd
, style
);
1364 WIN_ReleasePtr( win
);
1366 SendMessageA( hwnd
, WM_SHOWWINDOW
, SW_RESTORE
, 0 );
1367 SetWindowPos( hwnd
, 0, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
,
1368 SWP_NOZORDER
| SWP_WINE_NOHOSTMOVE
);
1370 else WIN_ReleasePtr( win
);
1371 if (hwndFocus
&& IsChild( hwnd
, hwndFocus
)) X11DRV_SetFocus(hwndFocus
); /* FIXME */
1375 /**********************************************************************
1376 * X11DRV_UnmapNotify
1378 void X11DRV_UnmapNotify( HWND hwnd
, XUnmapEvent
*event
)
1382 if (!(win
= WIN_GetPtr( hwnd
))) return;
1384 if ((win
->dwStyle
& WS_VISIBLE
) && (win
->dwExStyle
& WS_EX_MANAGED
))
1386 if (win
->dwStyle
& WS_MAXIMIZE
)
1387 win
->flags
|= WIN_RESTORE_MAX
;
1389 win
->flags
&= ~WIN_RESTORE_MAX
;
1391 WIN_SetStyle( hwnd
, (win
->dwStyle
& ~WS_MAXIMIZE
) | WS_MINIMIZE
);
1392 WIN_ReleasePtr( win
);
1395 SendMessageA( hwnd
, WM_SHOWWINDOW
, SW_MINIMIZE
, 0 );
1396 SetWindowPos( hwnd
, 0, 0, 0, GetSystemMetrics(SM_CXICON
), GetSystemMetrics(SM_CYICON
),
1397 SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_WINE_NOHOSTMOVE
);
1399 else WIN_ReleasePtr( win
);
1403 /***********************************************************************
1406 * Synchronize internal z-order with the window manager's.
1408 static Window
__get_common_ancestor( Display
*display
, Window A
, Window B
,
1409 Window
** children
, unsigned* total
)
1411 /* find the real root window */
1413 Window root
, *childrenB
;
1416 while( A
!= B
&& A
&& B
)
1418 TSXQueryTree( display
, A
, &root
, &A
, children
, total
);
1419 TSXQueryTree( display
, B
, &root
, &B
, &childrenB
, &totalB
);
1420 if( childrenB
) TSXFree( childrenB
);
1421 if( *children
) TSXFree( *children
), *children
= NULL
;
1426 TSXQueryTree( display
, A
, &root
, &B
, children
, total
);
1432 static Window
__get_top_decoration( Display
*display
, Window w
, Window ancestor
)
1434 Window
* children
, root
, prev
= w
, parent
= w
;
1440 TSXQueryTree( display
, w
, &root
, &parent
, &children
, &total
);
1441 if( children
) TSXFree( children
);
1442 } while( parent
&& parent
!= ancestor
);
1443 TRACE("\t%08x -> %08x\n", (unsigned)prev
, (unsigned)w
);
1444 return ( parent
) ? w
: 0 ;
1447 static unsigned __td_lookup( Window w
, Window
* list
, unsigned max
)
1450 for( i
= max
; i
> 0; i
-- ) if( list
[i
- 1] == w
) break;
1454 static HWND
query_zorder( Display
*display
, HWND hWndCheck
)
1456 HWND hwndInsertAfter
= HWND_TOP
;
1457 Window w
, parent
, *children
= NULL
;
1458 unsigned total
, check
, pos
, best
;
1459 HWND
*list
= WIN_ListChildren( GetDesktopWindow() );
1460 HWND hwndA
= 0, hwndB
= 0;
1463 /* find at least two managed windows */
1464 if (!list
) return 0;
1465 for (i
= 0; list
[i
]; i
++)
1467 if (!(GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_MANAGED
)) continue;
1468 if (!(GetWindowLongW( list
[i
], GWL_STYLE
) & WS_VISIBLE
)) continue;
1469 if (!hwndA
) hwndA
= list
[i
];
1476 if (!hwndA
|| !hwndB
) goto done
;
1478 parent
= __get_common_ancestor( display
, X11DRV_get_whole_window(hwndA
),
1479 X11DRV_get_whole_window(hwndB
), &children
, &total
);
1480 if( parent
&& children
)
1482 /* w is the ancestor if hWndCheck that is a direct descendant of 'parent' */
1484 w
= __get_top_decoration( display
, X11DRV_get_whole_window(hWndCheck
), parent
);
1486 if( w
!= children
[total
-1] ) /* check if at the top */
1488 /* X child at index 0 is at the bottom, at index total-1 is at the top */
1489 check
= __td_lookup( w
, children
, total
);
1492 /* go through all windows in Wine z-order... */
1493 for (i
= 0; list
[i
]; i
++)
1495 if (list
[i
] == hWndCheck
) continue;
1496 if (!(GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_MANAGED
)) continue;
1497 if (!(w
= __get_top_decoration( display
, X11DRV_get_whole_window(list
[i
]),
1498 parent
))) continue;
1499 pos
= __td_lookup( w
, children
, total
);
1500 if( pos
< best
&& pos
> check
)
1502 /* find a nearest Wine window precedes hWndCheck in the real z-order */
1504 hwndInsertAfter
= list
[i
];
1506 if( best
- check
== 1 ) break;
1510 if( children
) TSXFree( children
);
1513 HeapFree( GetProcessHeap(), 0, list
);
1514 return hwndInsertAfter
;
1518 /***********************************************************************
1519 * X11DRV_ConfigureNotify
1521 void X11DRV_ConfigureNotify( HWND hwnd
, XConfigureEvent
*event
)
1523 HWND oldInsertAfter
;
1524 struct x11drv_win_data
*data
;
1528 int x
= event
->x
, y
= event
->y
;
1530 if (!(win
= WIN_GetPtr( hwnd
))) return;
1531 data
= win
->pDriverData
;
1535 if (!event
->send_event
) /* normal event, need to map coordinates to the root */
1539 XTranslateCoordinates( event
->display
, data
->whole_window
, root_window
,
1540 0, 0, &x
, &y
, &child
);
1541 wine_tsx11_unlock();
1545 rect
.right
= x
+ event
->width
;
1546 rect
.bottom
= y
+ event
->height
;
1547 TRACE( "win %x new X rect %d,%d,%dx%d (event %d,%d,%dx%d)\n",
1548 hwnd
, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
,
1549 event
->x
, event
->y
, event
->width
, event
->height
);
1550 X11DRV_X_to_window_rect( win
, &rect
);
1551 WIN_ReleasePtr( win
);
1554 winpos
.x
= rect
.left
;
1555 winpos
.y
= rect
.top
;
1556 winpos
.cx
= rect
.right
- rect
.left
;
1557 winpos
.cy
= rect
.bottom
- rect
.top
;
1558 winpos
.flags
= SWP_NOACTIVATE
;
1560 /* Get Z-order (FIXME) */
1562 winpos
.hwndInsertAfter
= query_zorder( event
->display
, hwnd
);
1564 /* needs to find the first Visible Window above the current one */
1565 oldInsertAfter
= hwnd
;
1568 oldInsertAfter
= GetWindow( oldInsertAfter
, GW_HWNDPREV
);
1569 if (!oldInsertAfter
)
1571 oldInsertAfter
= HWND_TOP
;
1574 if (GetWindowLongA( oldInsertAfter
, GWL_STYLE
) & WS_VISIBLE
) break;
1577 /* Compare what has changed */
1579 GetWindowRect( hwnd
, &rect
);
1580 if (rect
.left
== winpos
.x
&& rect
.top
== winpos
.y
) winpos
.flags
|= SWP_NOMOVE
;
1582 TRACE( "%04x moving from (%d,%d) to (%d,%d)\n",
1583 hwnd
, rect
.left
, rect
.top
, winpos
.x
, winpos
.y
);
1585 if ((rect
.right
- rect
.left
== winpos
.cx
&& rect
.bottom
- rect
.top
== winpos
.cy
) ||
1587 (IsRectEmpty( &rect
) && winpos
.cx
== 1 && winpos
.cy
== 1))
1588 winpos
.flags
|= SWP_NOSIZE
;
1590 TRACE( "%04x resizing from (%dx%d) to (%dx%d)\n",
1591 hwnd
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
1592 winpos
.cx
, winpos
.cy
);
1594 if (winpos
.hwndInsertAfter
== oldInsertAfter
) winpos
.flags
|= SWP_NOZORDER
;
1596 TRACE( "%04x restacking from after %04x to after %04x\n",
1597 hwnd
, oldInsertAfter
, winpos
.hwndInsertAfter
);
1599 /* if nothing changed, don't do anything */
1600 if (winpos
.flags
== (SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
)) return;
1602 SetWindowPos( hwnd
, winpos
.hwndInsertAfter
, winpos
.x
, winpos
.y
,
1603 winpos
.cx
, winpos
.cy
, winpos
.flags
| SWP_WINE_NOHOSTMOVE
);
1607 /***********************************************************************
1608 * SetWindowRgn (X11DRV.@)
1610 * Assign specified region to window (for non-rectangular windows)
1612 int X11DRV_SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL redraw
)
1616 if ((wndPtr
= WIN_GetPtr( hwnd
)) == WND_OTHER_PROCESS
)
1618 if (IsWindow( hwnd
))
1619 FIXME( "not supported on other process window %x\n", hwnd
);
1624 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
1628 if (wndPtr
->hrgnWnd
== hrgn
)
1630 WIN_ReleasePtr( wndPtr
);
1634 if (wndPtr
->hrgnWnd
)
1636 /* delete previous region */
1637 DeleteObject(wndPtr
->hrgnWnd
);
1638 wndPtr
->hrgnWnd
= 0;
1640 wndPtr
->hrgnWnd
= hrgn
;
1642 #ifdef HAVE_LIBXSHAPE
1644 Display
*display
= thread_display();
1645 X11DRV_WND_DATA
*data
= wndPtr
->pDriverData
;
1647 if (data
->whole_window
)
1652 XShapeCombineMask( display
, data
->whole_window
,
1653 ShapeBounding
, 0, 0, None
, ShapeSet
);
1654 wine_tsx11_unlock();
1659 int x_offset
, y_offset
;
1661 DWORD dwBufferSize
= GetRegionData(hrgn
, 0, NULL
);
1662 PRGNDATA pRegionData
= HeapAlloc(GetProcessHeap(), 0, dwBufferSize
);
1665 WIN_ReleasePtr( wndPtr
);
1668 GetRegionData(hrgn
, dwBufferSize
, pRegionData
);
1669 size
= pRegionData
->rdh
.nCount
;
1670 x_offset
= wndPtr
->rectWindow
.left
- data
->whole_rect
.left
;
1671 y_offset
= wndPtr
->rectWindow
.top
- data
->whole_rect
.top
;
1672 /* convert region's "Windows rectangles" to XRectangles */
1673 aXRect
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(*aXRect
) );
1676 XRectangle
* pCurrRect
= aXRect
;
1677 RECT
*pRect
= (RECT
*) pRegionData
->Buffer
;
1678 for (; pRect
< ((RECT
*) pRegionData
->Buffer
) + size
; ++pRect
, ++pCurrRect
)
1680 pCurrRect
->x
= pRect
->left
+ x_offset
;
1681 pCurrRect
->y
= pRect
->top
+ y_offset
;
1682 pCurrRect
->height
= pRect
->bottom
- pRect
->top
;
1683 pCurrRect
->width
= pRect
->right
- pRect
->left
;
1685 TRACE("Rectangle %04d of %04ld data: X=%04d, Y=%04d, Height=%04d, Width=%04d.\n",
1686 pRect
- (RECT
*) pRegionData
->Buffer
,
1694 /* shape = non-rectangular windows (X11/extensions) */
1696 XShapeCombineRectangles( display
, data
->whole_window
, ShapeBounding
,
1698 pCurrRect
- aXRect
, ShapeSet
, YXBanded
);
1699 wine_tsx11_unlock();
1700 HeapFree(GetProcessHeap(), 0, aXRect
);
1702 HeapFree(GetProcessHeap(), 0, pRegionData
);
1706 #endif /* HAVE_LIBXSHAPE */
1708 WIN_ReleasePtr( wndPtr
);
1709 if (redraw
) RedrawWindow( hwnd
, NULL
, 0, RDW_FRAME
| RDW_INVALIDATE
| RDW_ERASE
);
1714 /***********************************************************************
1717 * Draw the frame used when moving or resizing window.
1719 * FIXME: This causes problems in Win95 mode. (why?)
1721 static void draw_moving_frame( HDC hdc
, RECT
*rect
, BOOL thickframe
)
1725 const int width
= GetSystemMetrics(SM_CXFRAME
);
1726 const int height
= GetSystemMetrics(SM_CYFRAME
);
1728 HBRUSH hbrush
= SelectObject( hdc
, GetStockObject( GRAY_BRUSH
) );
1729 PatBlt( hdc
, rect
->left
, rect
->top
,
1730 rect
->right
- rect
->left
- width
, height
, PATINVERT
);
1731 PatBlt( hdc
, rect
->left
, rect
->top
+ height
, width
,
1732 rect
->bottom
- rect
->top
- height
, PATINVERT
);
1733 PatBlt( hdc
, rect
->left
+ width
, rect
->bottom
- 1,
1734 rect
->right
- rect
->left
- width
, -height
, PATINVERT
);
1735 PatBlt( hdc
, rect
->right
- 1, rect
->top
, -width
,
1736 rect
->bottom
- rect
->top
- height
, PATINVERT
);
1737 SelectObject( hdc
, hbrush
);
1739 else DrawFocusRect( hdc
, rect
);
1743 /***********************************************************************
1746 * Initialisation of a move or resize, when initiatied from a menu choice.
1747 * Return hit test code for caption or sizing border.
1749 static LONG
start_size_move( HWND hwnd
, WPARAM wParam
, POINT
*capturePoint
, LONG style
)
1756 GetWindowRect( hwnd
, &rectWindow
);
1758 if ((wParam
& 0xfff0) == SC_MOVE
)
1760 /* Move pointer at the center of the caption */
1762 NC_GetInsideRect( hwnd
, &rect
);
1763 if (style
& WS_SYSMENU
)
1764 rect
.left
+= GetSystemMetrics(SM_CXSIZE
) + 1;
1765 if (style
& WS_MINIMIZEBOX
)
1766 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
1767 if (style
& WS_MAXIMIZEBOX
)
1768 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
1769 pt
.x
= rectWindow
.left
+ (rect
.right
- rect
.left
) / 2;
1770 pt
.y
= rectWindow
.top
+ rect
.top
+ GetSystemMetrics(SM_CYSIZE
)/2;
1771 hittest
= HTCAPTION
;
1778 GetMessageW( &msg
, 0, WM_KEYFIRST
, WM_MOUSELAST
);
1779 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
1784 hittest
= NC_HandleNCHitTest( hwnd
, msg
.pt
);
1785 if ((hittest
< HTLEFT
) || (hittest
> HTBOTTOMRIGHT
))
1797 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
1798 pt
.y
= rectWindow
.top
+ GetSystemMetrics(SM_CYFRAME
) / 2;
1802 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
1803 pt
.y
= rectWindow
.bottom
- GetSystemMetrics(SM_CYFRAME
) / 2;
1807 pt
.x
= rectWindow
.left
+ GetSystemMetrics(SM_CXFRAME
) / 2;
1808 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
1812 pt
.x
= rectWindow
.right
- GetSystemMetrics(SM_CXFRAME
) / 2;
1813 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
1816 case VK_ESCAPE
: return 0;
1822 SetCursorPos( pt
.x
, pt
.y
);
1823 NC_HandleSetCursor( hwnd
, (WPARAM
)hwnd
, MAKELONG( hittest
, WM_MOUSEMOVE
));
1828 /***********************************************************************
1829 * set_movesize_capture
1831 static void set_movesize_capture( HWND hwnd
)
1835 SERVER_START_REQ( set_capture_window
)
1838 req
->flags
= CAPTURE_MOVESIZE
;
1839 if (!wine_server_call_err( req
))
1841 previous
= reply
->previous
;
1842 hwnd
= reply
->full_handle
;
1846 if (previous
&& previous
!= hwnd
)
1847 SendMessageW( previous
, WM_CAPTURECHANGED
, 0, (LPARAM
)hwnd
);
1851 /***********************************************************************
1852 * SysCommandSizeMove (X11DRV.@)
1854 * Perform SC_MOVE and SC_SIZE commands.
1856 void X11DRV_SysCommandSizeMove( HWND hwnd
, WPARAM wParam
)
1859 RECT sizingRect
, mouseRect
, origRect
;
1862 LONG hittest
= (LONG
)(wParam
& 0x0f);
1863 HCURSOR hDragCursor
= 0, hOldCursor
= 0;
1864 POINT minTrack
, maxTrack
;
1865 POINT capturePoint
, pt
;
1866 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
1867 LONG exstyle
= GetWindowLongA( hwnd
, GWL_EXSTYLE
);
1868 BOOL thickframe
= HAS_THICKFRAME( style
, exstyle
);
1869 BOOL iconic
= style
& WS_MINIMIZE
;
1871 DWORD dwPoint
= GetMessagePos ();
1872 BOOL DragFullWindows
= FALSE
;
1875 Display
*old_gdi_display
= NULL
;
1876 Display
*display
= thread_display();
1878 SystemParametersInfoA(SPI_GETDRAGFULLWINDOWS
, 0, &DragFullWindows
, 0);
1880 pt
.x
= SLOWORD(dwPoint
);
1881 pt
.y
= SHIWORD(dwPoint
);
1884 if (IsZoomed(hwnd
) || !IsWindowVisible(hwnd
) || (exstyle
& WS_EX_MANAGED
)) return;
1886 if ((wParam
& 0xfff0) == SC_MOVE
)
1888 if (!hittest
) hittest
= start_size_move( hwnd
, wParam
, &capturePoint
, style
);
1889 if (!hittest
) return;
1893 if (!thickframe
) return;
1894 if ( hittest
&& hittest
!= HTSYSMENU
) hittest
+= 2;
1897 set_movesize_capture( hwnd
);
1898 hittest
= start_size_move( hwnd
, wParam
, &capturePoint
, style
);
1901 set_movesize_capture(0);
1907 /* Get min/max info */
1909 WINPOS_GetMinMaxInfo( hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
1910 GetWindowRect( hwnd
, &sizingRect
);
1911 if (style
& WS_CHILD
)
1913 parent
= GetParent(hwnd
);
1914 /* make sizing rect relative to parent */
1915 MapWindowPoints( 0, parent
, (POINT
*)&sizingRect
, 2 );
1916 GetClientRect( parent
, &mouseRect
);
1921 SetRect(&mouseRect
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
));
1923 origRect
= sizingRect
;
1925 if (ON_LEFT_BORDER(hittest
))
1927 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.right
-maxTrack
.x
);
1928 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.right
-minTrack
.x
);
1930 else if (ON_RIGHT_BORDER(hittest
))
1932 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.left
+minTrack
.x
);
1933 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.left
+maxTrack
.x
);
1935 if (ON_TOP_BORDER(hittest
))
1937 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.bottom
-maxTrack
.y
);
1938 mouseRect
.bottom
= min( mouseRect
.bottom
,sizingRect
.bottom
-minTrack
.y
);
1940 else if (ON_BOTTOM_BORDER(hittest
))
1942 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.top
+minTrack
.y
);
1943 mouseRect
.bottom
= min( mouseRect
.bottom
, sizingRect
.top
+maxTrack
.y
);
1945 if (parent
) MapWindowPoints( parent
, 0, (LPPOINT
)&mouseRect
, 2 );
1947 /* Retrieve a default cache DC (without using the window style) */
1948 hdc
= GetDCEx( parent
, 0, DCX_CACHE
);
1950 if( iconic
) /* create a cursor for dragging */
1952 hDragCursor
= (HCURSOR
)GetClassLongA( hwnd
, GCL_HICON
);
1953 if( !hDragCursor
) hDragCursor
= (HCURSOR
)SendMessageA( hwnd
, WM_QUERYDRAGICON
, 0, 0L);
1954 if( !hDragCursor
) iconic
= FALSE
;
1957 /* repaint the window before moving it around */
1958 RedrawWindow( hwnd
, NULL
, 0, RDW_UPDATENOW
| RDW_ALLCHILDREN
);
1960 SendMessageA( hwnd
, WM_ENTERSIZEMOVE
, 0, 0 );
1961 set_movesize_capture( hwnd
);
1963 /* grab the server only when moving top-level windows without desktop */
1964 grab
= (!DragFullWindows
&& !parent
&& (root_window
== DefaultRootWindow(gdi_display
)));
1969 XSync( gdi_display
, False
);
1970 XGrabServer( display
);
1971 XSync( display
, False
);
1972 /* switch gdi display to the thread display, since the server is grabbed */
1973 old_gdi_display
= gdi_display
;
1974 gdi_display
= display
;
1976 XGrabPointer( display
, X11DRV_get_whole_window(hwnd
), False
,
1977 PointerMotionMask
| ButtonPressMask
| ButtonReleaseMask
,
1978 GrabModeAsync
, GrabModeAsync
,
1979 parent
? X11DRV_get_client_window(parent
) : root_window
,
1980 None
, CurrentTime
);
1981 wine_tsx11_unlock();
1987 if (!GetMessageW( &msg
, 0, WM_KEYFIRST
, WM_MOUSELAST
)) break;
1988 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
1990 /* Exit on button-up, Return, or Esc */
1991 if ((msg
.message
== WM_LBUTTONUP
) ||
1992 ((msg
.message
== WM_KEYDOWN
) &&
1993 ((msg
.wParam
== VK_RETURN
) || (msg
.wParam
== VK_ESCAPE
)))) break;
1995 if ((msg
.message
!= WM_KEYDOWN
) && (msg
.message
!= WM_MOUSEMOVE
))
1996 continue; /* We are not interested in other messages */
2000 if (msg
.message
== WM_KEYDOWN
) switch(msg
.wParam
)
2002 case VK_UP
: pt
.y
-= 8; break;
2003 case VK_DOWN
: pt
.y
+= 8; break;
2004 case VK_LEFT
: pt
.x
-= 8; break;
2005 case VK_RIGHT
: pt
.x
+= 8; break;
2008 pt
.x
= max( pt
.x
, mouseRect
.left
);
2009 pt
.x
= min( pt
.x
, mouseRect
.right
);
2010 pt
.y
= max( pt
.y
, mouseRect
.top
);
2011 pt
.y
= min( pt
.y
, mouseRect
.bottom
);
2013 dx
= pt
.x
- capturePoint
.x
;
2014 dy
= pt
.y
- capturePoint
.y
;
2022 if( iconic
) /* ok, no system popup tracking */
2024 hOldCursor
= SetCursor(hDragCursor
);
2026 WINPOS_ShowIconTitle( hwnd
, FALSE
);
2028 else if(!DragFullWindows
)
2029 draw_moving_frame( hdc
, &sizingRect
, thickframe
);
2032 if (msg
.message
== WM_KEYDOWN
) SetCursorPos( pt
.x
, pt
.y
);
2035 RECT newRect
= sizingRect
;
2036 WPARAM wpSizingHit
= 0;
2038 if (hittest
== HTCAPTION
) OffsetRect( &newRect
, dx
, dy
);
2039 if (ON_LEFT_BORDER(hittest
)) newRect
.left
+= dx
;
2040 else if (ON_RIGHT_BORDER(hittest
)) newRect
.right
+= dx
;
2041 if (ON_TOP_BORDER(hittest
)) newRect
.top
+= dy
;
2042 else if (ON_BOTTOM_BORDER(hittest
)) newRect
.bottom
+= dy
;
2043 if(!iconic
&& !DragFullWindows
) draw_moving_frame( hdc
, &sizingRect
, thickframe
);
2046 /* determine the hit location */
2047 if (hittest
>= HTLEFT
&& hittest
<= HTBOTTOMRIGHT
)
2048 wpSizingHit
= WMSZ_LEFT
+ (hittest
- HTLEFT
);
2049 SendMessageA( hwnd
, WM_SIZING
, wpSizingHit
, (LPARAM
)&newRect
);
2053 if(!DragFullWindows
)
2054 draw_moving_frame( hdc
, &newRect
, thickframe
);
2056 /* To avoid any deadlocks, all the locks on the windows
2057 structures must be suspended before the SetWindowPos */
2058 iWndsLocks
= WIN_SuspendWndsLock();
2059 SetWindowPos( hwnd
, 0, newRect
.left
, newRect
.top
,
2060 newRect
.right
- newRect
.left
,
2061 newRect
.bottom
- newRect
.top
,
2062 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
2063 WIN_RestoreWndsLock(iWndsLocks
);
2066 sizingRect
= newRect
;
2071 set_movesize_capture(0);
2074 if( moved
) /* restore cursors, show icon title later on */
2076 ShowCursor( FALSE
);
2077 SetCursor( hOldCursor
);
2080 else if (moved
&& !DragFullWindows
)
2081 draw_moving_frame( hdc
, &sizingRect
, thickframe
);
2083 ReleaseDC( parent
, hdc
);
2086 XUngrabPointer( display
, CurrentTime
);
2089 XSync( display
, False
);
2090 XUngrabServer( display
);
2091 XSync( display
, False
);
2092 gdi_display
= old_gdi_display
;
2094 wine_tsx11_unlock();
2096 if (HOOK_CallHooks( WH_CBT
, HCBT_MOVESIZE
, (WPARAM
)hwnd
, (LPARAM
)&sizingRect
, TRUE
))
2099 SendMessageA( hwnd
, WM_EXITSIZEMOVE
, 0, 0 );
2100 SendMessageA( hwnd
, WM_SETVISIBLE
, !IsIconic(hwnd
), 0L);
2102 /* window moved or resized */
2105 /* To avoid any deadlocks, all the locks on the windows
2106 structures must be suspended before the SetWindowPos */
2107 iWndsLocks
= WIN_SuspendWndsLock();
2109 /* if the moving/resizing isn't canceled call SetWindowPos
2110 * with the new position or the new size of the window
2112 if (!((msg
.message
== WM_KEYDOWN
) && (msg
.wParam
== VK_ESCAPE
)) )
2114 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
2115 if(!DragFullWindows
)
2116 SetWindowPos( hwnd
, 0, sizingRect
.left
, sizingRect
.top
,
2117 sizingRect
.right
- sizingRect
.left
,
2118 sizingRect
.bottom
- sizingRect
.top
,
2119 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
2122 { /* restore previous size/position */
2124 SetWindowPos( hwnd
, 0, origRect
.left
, origRect
.top
,
2125 origRect
.right
- origRect
.left
,
2126 origRect
.bottom
- origRect
.top
,
2127 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
2130 WIN_RestoreWndsLock(iWndsLocks
);
2135 /* Single click brings up the system menu when iconized */
2139 if(style
& WS_SYSMENU
)
2140 SendMessageA( hwnd
, WM_SYSCOMMAND
,
2141 SC_MOUSEMENU
+ HTSYSMENU
, MAKELONG(pt
.x
,pt
.y
));
2143 else WINPOS_ShowIconTitle( hwnd
, TRUE
);
2148 /***********************************************************************
2149 * ForceWindowRaise (X11DRV.@)
2151 * Raise a window on top of the X stacking order, while preserving
2152 * the correct Windows Z order.
2154 * FIXME: this should go away.
2156 void X11DRV_ForceWindowRaise( HWND hwnd
)
2160 XWindowChanges winChanges
;
2161 Display
*display
= thread_display();
2162 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
2164 if (!wndPtr
) return;
2166 if ((wndPtr
->dwExStyle
& WS_EX_MANAGED
) ||
2167 wndPtr
->parent
!= GetDesktopWindow() ||
2168 IsRectEmpty( &wndPtr
->rectWindow
) ||
2169 !get_whole_window(wndPtr
))
2171 WIN_ReleaseWndPtr( wndPtr
);
2174 WIN_ReleaseWndPtr( wndPtr
);
2176 /* Raise all windows up to wndPtr according to their Z order.
2177 * (it would be easier with sibling-related Below but it doesn't
2178 * work very well with SGI mwm for instance)
2180 winChanges
.stack_mode
= Above
;
2181 if (!(list
= WIN_ListChildren( GetDesktopWindow() ))) return;
2182 while (list
[i
] && list
[i
] != hwnd
) i
++;
2185 for ( ; i
>= 0; i
--)
2187 WND
*ptr
= WIN_FindWndPtr( list
[i
] );
2189 if (!IsRectEmpty( &ptr
->rectWindow
) && get_whole_window(ptr
))
2190 TSXReconfigureWMWindow( display
, get_whole_window(ptr
), 0,
2191 CWStackMode
, &winChanges
);
2192 WIN_ReleaseWndPtr( ptr
);
2195 HeapFree( GetProcessHeap(), 0, list
);