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
39 #include "cursoricon.h"
40 #include "nonclient.h"
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(x11drv
);
47 #define SWP_AGG_NOGEOMETRYCHANGE \
48 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE)
49 #define SWP_AGG_NOPOSCHANGE \
50 (SWP_AGG_NOGEOMETRYCHANGE | SWP_NOZORDER)
51 #define SWP_AGG_STATUSFLAGS \
52 (SWP_AGG_NOPOSCHANGE | SWP_FRAMECHANGED | SWP_HIDEWINDOW | SWP_SHOWWINDOW)
54 #define SWP_EX_NOCOPY 0x0001
55 #define SWP_EX_PAINTSELF 0x0002
56 #define SWP_EX_NONCLIENT 0x0004
58 #define HAS_THICKFRAME(style,exStyle) \
59 (((style) & WS_THICKFRAME) && \
60 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
62 #define ON_LEFT_BORDER(hit) \
63 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
64 #define ON_RIGHT_BORDER(hit) \
65 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
66 #define ON_TOP_BORDER(hit) \
67 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
68 #define ON_BOTTOM_BORDER(hit) \
69 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
72 /***********************************************************************
75 * Clip all children of a given window out of the visible region
77 static int clip_children( HWND parent
, HWND last
, HRGN hrgn
, int whole_window
)
82 int i
, x
, y
, ret
= SIMPLEREGION
;
84 /* first check if we have anything to do */
85 if (!(list
= WIN_ListChildren( parent
))) return ret
;
86 for (i
= 0; list
[i
] && list
[i
] != last
; i
++)
87 if (GetWindowLongW( list
[i
], GWL_STYLE
) & WS_VISIBLE
) break;
88 if (!list
[i
] || list
[i
] == last
) goto done
; /* no children to clip */
92 WND
*win
= WIN_FindWndPtr( parent
);
93 x
= win
->rectWindow
.left
- win
->rectClient
.left
;
94 y
= win
->rectWindow
.top
- win
->rectClient
.top
;
95 WIN_ReleaseWndPtr( win
);
99 rectRgn
= CreateRectRgn( 0, 0, 0, 0 );
101 for ( ; list
[i
] && list
[i
] != last
; i
++)
103 if (!(ptr
= WIN_FindWndPtr( list
[i
] ))) continue;
104 if (ptr
->dwStyle
& WS_VISIBLE
)
106 SetRectRgn( rectRgn
, ptr
->rectWindow
.left
+ x
, ptr
->rectWindow
.top
+ y
,
107 ptr
->rectWindow
.right
+ x
, ptr
->rectWindow
.bottom
+ y
);
108 if ((ret
= CombineRgn( hrgn
, hrgn
, rectRgn
, RGN_DIFF
)) == NULLREGION
)
110 WIN_ReleaseWndPtr( ptr
);
111 break; /* no need to go on, region is empty */
114 WIN_ReleaseWndPtr( ptr
);
116 DeleteObject( rectRgn
);
118 HeapFree( GetProcessHeap(), 0, list
);
123 /***********************************************************************
126 * Compute the visible region of a window
128 static HRGN
get_visible_region( WND
*win
, HWND top
, UINT flags
, int mode
)
132 int xoffset
, yoffset
;
133 X11DRV_WND_DATA
*data
= win
->pDriverData
;
135 if (flags
& DCX_WINDOW
)
137 xoffset
= win
->rectWindow
.left
;
138 yoffset
= win
->rectWindow
.top
;
142 xoffset
= win
->rectClient
.left
;
143 yoffset
= win
->rectClient
.top
;
146 if (flags
& DCX_PARENTCLIP
)
147 GetClientRect( win
->parent
, &rect
);
148 else if (flags
& DCX_WINDOW
)
149 rect
= data
->whole_rect
;
151 rect
= win
->rectClient
;
153 /* vis region is relative to the start of the client/window area */
154 OffsetRect( &rect
, -xoffset
, -yoffset
);
156 if (!(rgn
= CreateRectRgn( rect
.left
, rect
.top
, rect
.right
, rect
.bottom
))) return 0;
158 if ((flags
& DCX_CLIPCHILDREN
) && (mode
!= ClipByChildren
))
160 /* we need to clip children by hand */
161 if (clip_children( win
->hwndSelf
, 0, rgn
, (flags
& DCX_WINDOW
) ) == NULLREGION
) return rgn
;
164 if (top
&& top
!= win
->hwndSelf
) /* need to clip siblings of ancestors */
166 WND
*parent
, *ptr
= WIN_FindWndPtr( win
->hwndSelf
);
169 OffsetRgn( rgn
, xoffset
, yoffset
);
172 if (ptr
->dwStyle
& WS_CLIPSIBLINGS
)
174 if (clip_children( ptr
->parent
, ptr
->hwndSelf
, rgn
, FALSE
) == NULLREGION
) break;
176 if (ptr
->hwndSelf
== top
) break;
177 if (!(parent
= WIN_FindWndPtr( ptr
->parent
))) break;
178 WIN_ReleaseWndPtr( ptr
);
180 /* clip to parent client area */
181 if (tmp
) SetRectRgn( tmp
, 0, 0, ptr
->rectClient
.right
- ptr
->rectClient
.left
,
182 ptr
->rectClient
.bottom
- ptr
->rectClient
.top
);
183 else tmp
= CreateRectRgn( 0, 0, ptr
->rectClient
.right
- ptr
->rectClient
.left
,
184 ptr
->rectClient
.bottom
- ptr
->rectClient
.top
);
185 CombineRgn( rgn
, rgn
, tmp
, RGN_AND
);
186 OffsetRgn( rgn
, ptr
->rectClient
.left
, ptr
->rectClient
.top
);
187 xoffset
+= ptr
->rectClient
.left
;
188 yoffset
+= ptr
->rectClient
.top
;
190 WIN_ReleaseWndPtr( ptr
);
191 /* make it relative to the target window again */
192 OffsetRgn( rgn
, -xoffset
, -yoffset
);
193 if (tmp
) DeleteObject( tmp
);
200 /***********************************************************************
203 * Compute the portion of 'rgn' that is covered by non-clipped siblings.
204 * This is the area that is covered from X point of view, but may still need
206 * 'rgn' must be relative to the client area of the parent of 'win'.
208 static int get_covered_region( WND
*win
, HRGN rgn
)
212 WND
*parent
, *ptr
= WIN_FindWndPtr( win
->hwndSelf
);
213 int xoffset
= 0, yoffset
= 0;
215 tmp
= CreateRectRgn( 0, 0, 0, 0 );
216 CombineRgn( tmp
, rgn
, 0, RGN_COPY
);
218 /* to make things easier we actually build the uncovered
219 * area by removing all siblings and then we subtract that
220 * from the total region to get the covered area */
223 if (!(ptr
->dwStyle
& WS_CLIPSIBLINGS
))
225 if (clip_children( ptr
->parent
, ptr
->hwndSelf
, tmp
, FALSE
) == NULLREGION
) break;
227 if (!(parent
= WIN_FindWndPtr( ptr
->parent
))) break;
228 WIN_ReleaseWndPtr( ptr
);
230 OffsetRgn( tmp
, ptr
->rectClient
.left
, ptr
->rectClient
.top
);
231 xoffset
+= ptr
->rectClient
.left
;
232 yoffset
+= ptr
->rectClient
.top
;
234 WIN_ReleaseWndPtr( ptr
);
235 /* make it relative to the target window again */
236 OffsetRgn( tmp
, -xoffset
, -yoffset
);
238 /* now subtract the computed region from the original one */
239 ret
= CombineRgn( rgn
, rgn
, tmp
, RGN_DIFF
);
245 /***********************************************************************
248 * Expose a region of a given window.
250 static void expose_window( HWND hwnd
, RECT
*rect
, HRGN rgn
, int flags
)
257 /* find the top most parent that doesn't clip children or siblings and
258 * invalidate the area on its parent, including all children */
259 if ((list
= WIN_ListParents( hwnd
)))
262 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
263 for (i
= 0; list
[i
] && list
[i
] != GetDesktopWindow(); i
++)
265 if (!(style
& WS_CLIPSIBLINGS
)) top
= current
;
266 style
= GetWindowLongW( list
[i
], GWL_STYLE
);
267 if (!(style
& WS_CLIPCHILDREN
)) top
= current
;
273 /* find the parent of the top window, reusing the parent list */
274 if (top
== hwnd
) i
= 0;
277 for (i
= 0; list
[i
]; i
++) if (list
[i
] == top
) break;
278 if (list
[i
] && list
[i
+1]) i
++;
280 if (list
[i
] != GetDesktopWindow()) top
= list
[i
];
281 flags
&= ~RDW_FRAME
; /* parent will invalidate children frame anyway */
282 flags
|= RDW_ALLCHILDREN
;
284 HeapFree( GetProcessHeap(), 0, list
);
287 if (!top
) top
= hwnd
;
289 /* make coords relative to top */
290 offset
.x
= offset
.y
= 0;
291 MapWindowPoints( hwnd
, top
, &offset
, 1 );
295 OffsetRect( rect
, offset
.x
, offset
.y
);
296 RedrawWindow( top
, rect
, 0, flags
);
300 OffsetRgn( rgn
, offset
.x
, offset
.y
);
301 RedrawWindow( top
, NULL
, rgn
, flags
);
306 /***********************************************************************
307 * expose_covered_parent_area
309 * Expose the parent area that has been uncovered by moving/hiding a
310 * given window, but that is still covered by other siblings (the area
311 * not covered by siblings will be exposed automatically by X).
313 static void expose_covered_parent_area( WND
*win
, const RECT
*old_rect
)
315 int ret
= SIMPLEREGION
;
316 HRGN hrgn
= CreateRectRgnIndirect( old_rect
);
318 if (win
->dwStyle
& WS_VISIBLE
)
320 HRGN tmp
= CreateRectRgnIndirect( &win
->rectWindow
);
321 ret
= CombineRgn( hrgn
, hrgn
, tmp
, RGN_DIFF
);
325 if (ret
!= NULLREGION
)
327 if (get_covered_region( win
, hrgn
) != NULLREGION
)
328 expose_window( win
->parent
, NULL
, hrgn
, RDW_INVALIDATE
| RDW_ERASE
| RDW_ALLCHILDREN
);
330 DeleteObject( hrgn
);
334 /***********************************************************************
335 * expose_covered_window_area
337 * Expose the area of a window that is covered by other siblings.
339 static void expose_covered_window_area( WND
*win
, const RECT
*old_client_rect
, BOOL frame
)
342 int ret
= SIMPLEREGION
;
345 hrgn
= CreateRectRgn( win
->rectWindow
.left
- win
->rectClient
.left
,
346 win
->rectWindow
.top
- win
->rectClient
.top
,
347 win
->rectWindow
.right
- win
->rectWindow
.left
,
348 win
->rectWindow
.bottom
- win
->rectWindow
.top
);
350 hrgn
= CreateRectRgn( 0, 0,
351 win
->rectClient
.right
- win
->rectClient
.left
,
352 win
->rectClient
.bottom
- win
->rectClient
.top
);
354 /* if the client rect didn't move we don't need to repaint it all */
355 if (old_client_rect
->left
== win
->rectClient
.left
&&
356 old_client_rect
->top
== win
->rectClient
.top
)
360 if (IntersectRect( &rc
, old_client_rect
, &win
->rectClient
))
363 /* subtract the unchanged client area from the region to expose */
364 OffsetRect( &rc
, -win
->rectClient
.left
, -win
->rectClient
.top
);
365 if ((tmp
= CreateRectRgnIndirect( &rc
)))
367 ret
= CombineRgn( hrgn
, hrgn
, tmp
, RGN_DIFF
);
373 if (ret
!= NULLREGION
)
375 if (get_covered_region( win
, hrgn
) != NULLREGION
)
376 expose_window( win
->hwndSelf
, NULL
, hrgn
,
377 RDW_INVALIDATE
| RDW_ERASE
| RDW_FRAME
| RDW_ALLCHILDREN
);
380 DeleteObject( hrgn
);
384 /***********************************************************************
387 void X11DRV_Expose( HWND hwnd
, XExposeEvent
*event
)
390 struct x11drv_win_data
*data
;
391 int flags
= RDW_INVALIDATE
| RDW_ERASE
;
394 TRACE( "win %x (%lx) %d,%d %dx%d\n",
395 hwnd
, event
->window
, event
->x
, event
->y
, event
->width
, event
->height
);
397 rect
.left
= event
->x
;
399 rect
.right
= rect
.left
+ event
->width
;
400 rect
.bottom
= rect
.top
+ event
->height
;
402 if (!(win
= WIN_GetPtr( hwnd
))) return;
403 data
= win
->pDriverData
;
405 if (event
->window
!= data
->client_window
) /* whole window or icon window */
408 /* make position relative to client area instead of window */
409 OffsetRect( &rect
, -data
->client_rect
.left
, -data
->client_rect
.top
);
411 WIN_ReleasePtr( win
);
413 expose_window( hwnd
, &rect
, 0, flags
);
417 /***********************************************************************
420 * Set the drawable, origin and dimensions for the DC associated to
423 BOOL
X11DRV_GetDC( HWND hwnd
, HDC hdc
, HRGN hrgn
, DWORD flags
)
425 WND
*win
= WIN_GetPtr( hwnd
);
427 X11DRV_WND_DATA
*data
= win
->pDriverData
;
431 int mode
= IncludeInferiors
;
433 /* don't clip siblings if using parent clip region */
434 if (flags
& DCX_PARENTCLIP
) flags
&= ~DCX_CLIPSIBLINGS
;
436 /* find the top parent in the hierarchy that isn't clipping siblings */
437 visible
= (win
->dwStyle
& WS_VISIBLE
) != 0;
441 HWND
*list
= WIN_ListParents( hwnd
);
445 for (i
= 0; list
[i
] != GetDesktopWindow(); i
++)
447 LONG style
= GetWindowLongW( list
[i
], GWL_STYLE
);
448 if (!(style
& WS_VISIBLE
))
454 if (!(style
& WS_CLIPSIBLINGS
)) top
= list
[i
];
456 HeapFree( GetProcessHeap(), 0, list
);
458 if (!top
&& visible
&& !(flags
& DCX_CLIPSIBLINGS
)) top
= hwnd
;
463 HWND parent
= GetAncestor( top
, GA_PARENT
);
465 if (flags
& DCX_WINDOW
)
467 org
.x
= win
->rectWindow
.left
- win
->rectClient
.left
;
468 org
.y
= win
->rectWindow
.top
- win
->rectClient
.top
;
470 MapWindowPoints( hwnd
, parent
, &org
, 1 );
471 /* have to use the parent so that we include siblings */
472 if (parent
) drawable
= X11DRV_get_client_window( parent
);
473 else drawable
= root_window
;
477 if (IsIconic( hwnd
))
479 drawable
= data
->icon_window
? data
->icon_window
: data
->whole_window
;
483 else if (flags
& DCX_WINDOW
)
485 drawable
= data
->whole_window
;
486 org
.x
= win
->rectWindow
.left
- data
->whole_rect
.left
;
487 org
.y
= win
->rectWindow
.top
- data
->whole_rect
.top
;
491 drawable
= data
->client_window
;
494 if (flags
& DCX_CLIPCHILDREN
) mode
= ClipByChildren
; /* can use X11 clipping */
498 X11DRV_SetDrawable( hdc
, drawable
, mode
, org
.x
, org
.y
);
500 if (flags
& (DCX_EXCLUDERGN
| DCX_INTERSECTRGN
) ||
501 SetHookFlags16( hdc
, DCHF_VALIDATEVISRGN
)) /* DC was dirty */
503 /* need to recompute the visible region */
508 visRgn
= get_visible_region( win
, top
, flags
, mode
);
510 if (flags
& (DCX_EXCLUDERGN
| DCX_INTERSECTRGN
))
511 CombineRgn( visRgn
, visRgn
, hrgn
,
512 (flags
& DCX_INTERSECTRGN
) ? RGN_AND
: RGN_DIFF
);
514 /* make it relative to the drawable origin */
515 OffsetRgn( visRgn
, org
.x
, org
.y
);
517 else visRgn
= CreateRectRgn( 0, 0, 0, 0 );
519 SelectVisRgn16( hdc
, visRgn
);
520 DeleteObject( visRgn
);
523 WIN_ReleasePtr( win
);
529 /***********************************************************************
530 * SWP_DoWinPosChanging
532 static BOOL
SWP_DoWinPosChanging( WINDOWPOS
* pWinpos
, RECT
* pNewWindowRect
, RECT
* pNewClientRect
)
536 /* Send WM_WINDOWPOSCHANGING message */
538 if (!(pWinpos
->flags
& SWP_NOSENDCHANGING
))
539 SendMessageA( pWinpos
->hwnd
, WM_WINDOWPOSCHANGING
, 0, (LPARAM
)pWinpos
);
541 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return FALSE
;
543 /* Calculate new position and size */
545 *pNewWindowRect
= wndPtr
->rectWindow
;
546 *pNewClientRect
= (wndPtr
->dwStyle
& WS_MINIMIZE
) ? wndPtr
->rectWindow
547 : wndPtr
->rectClient
;
549 if (!(pWinpos
->flags
& SWP_NOSIZE
))
551 pNewWindowRect
->right
= pNewWindowRect
->left
+ pWinpos
->cx
;
552 pNewWindowRect
->bottom
= pNewWindowRect
->top
+ pWinpos
->cy
;
554 if (!(pWinpos
->flags
& SWP_NOMOVE
))
556 pNewWindowRect
->left
= pWinpos
->x
;
557 pNewWindowRect
->top
= pWinpos
->y
;
558 pNewWindowRect
->right
+= pWinpos
->x
- wndPtr
->rectWindow
.left
;
559 pNewWindowRect
->bottom
+= pWinpos
->y
- wndPtr
->rectWindow
.top
;
561 OffsetRect( pNewClientRect
, pWinpos
->x
- wndPtr
->rectWindow
.left
,
562 pWinpos
->y
- wndPtr
->rectWindow
.top
);
564 pWinpos
->flags
|= SWP_NOCLIENTMOVE
| SWP_NOCLIENTSIZE
;
565 WIN_ReleasePtr( wndPtr
);
569 /***********************************************************************
572 static UINT
SWP_DoNCCalcSize( WINDOWPOS
* pWinpos
, RECT
* pNewWindowRect
, RECT
* pNewClientRect
)
577 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
579 /* Send WM_NCCALCSIZE message to get new client area */
580 if( (pWinpos
->flags
& (SWP_FRAMECHANGED
| SWP_NOSIZE
)) != SWP_NOSIZE
)
582 NCCALCSIZE_PARAMS params
;
583 WINDOWPOS winposCopy
;
585 params
.rgrc
[0] = *pNewWindowRect
;
586 params
.rgrc
[1] = wndPtr
->rectWindow
;
587 params
.rgrc
[2] = wndPtr
->rectClient
;
588 params
.lppos
= &winposCopy
;
589 winposCopy
= *pWinpos
;
590 WIN_ReleasePtr( wndPtr
);
592 wvrFlags
= SendMessageW( pWinpos
->hwnd
, WM_NCCALCSIZE
, TRUE
, (LPARAM
)¶ms
);
594 TRACE( "%d,%d-%d,%d\n", params
.rgrc
[0].left
, params
.rgrc
[0].top
,
595 params
.rgrc
[0].right
, params
.rgrc
[0].bottom
);
597 /* If the application send back garbage, ignore it */
598 if (params
.rgrc
[0].left
<= params
.rgrc
[0].right
&&
599 params
.rgrc
[0].top
<= params
.rgrc
[0].bottom
)
600 *pNewClientRect
= params
.rgrc
[0];
602 /* FIXME: WVR_ALIGNxxx */
604 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
606 if( pNewClientRect
->left
!= wndPtr
->rectClient
.left
||
607 pNewClientRect
->top
!= wndPtr
->rectClient
.top
)
608 pWinpos
->flags
&= ~SWP_NOCLIENTMOVE
;
610 if( (pNewClientRect
->right
- pNewClientRect
->left
!=
611 wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
) ||
612 (pNewClientRect
->bottom
- pNewClientRect
->top
!=
613 wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
) )
614 pWinpos
->flags
&= ~SWP_NOCLIENTSIZE
;
618 if (!(pWinpos
->flags
& SWP_NOMOVE
) &&
619 (pNewClientRect
->left
!= wndPtr
->rectClient
.left
||
620 pNewClientRect
->top
!= wndPtr
->rectClient
.top
))
621 pWinpos
->flags
&= ~SWP_NOCLIENTMOVE
;
623 WIN_ReleasePtr( wndPtr
);
628 /***********************************************************************
631 * fix Z order taking into account owned popups -
632 * basically we need to maintain them above the window that owns them
634 * FIXME: hide/show owned popups when owner visibility changes.
636 static HWND
SWP_DoOwnedPopups(HWND hwnd
, HWND hwndInsertAfter
)
639 HWND owner
= GetWindow( hwnd
, GW_OWNER
);
640 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
642 WARN("(%04x) hInsertAfter = %04x\n", hwnd
, hwndInsertAfter
);
644 if ((style
& WS_POPUP
) && owner
)
646 /* make sure this popup stays above the owner */
648 HWND hwndLocalPrev
= HWND_TOP
;
650 if( hwndInsertAfter
!= HWND_TOP
)
652 if ((list
= WIN_ListChildren( GetDesktopWindow() )))
655 for (i
= 0; list
[i
]; i
++)
657 if (list
[i
] == owner
) break;
658 if (list
[i
] != hwnd
) hwndLocalPrev
= list
[i
];
659 if (hwndLocalPrev
== hwndInsertAfter
) break;
661 hwndInsertAfter
= hwndLocalPrev
;
665 else if (style
& WS_CHILD
) return hwndInsertAfter
;
667 if (!list
) list
= WIN_ListChildren( GetDesktopWindow() );
671 for (i
= 0; list
[i
]; i
++)
673 if (list
[i
] == hwnd
) break;
674 if ((GetWindowLongW( list
[i
], GWL_STYLE
) & WS_POPUP
) &&
675 GetWindow( list
[i
], GW_OWNER
) == hwnd
)
677 SetWindowPos( list
[i
], hwndInsertAfter
, 0, 0, 0, 0,
678 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
|
679 SWP_NOSENDCHANGING
| SWP_DEFERERASE
);
680 hwndInsertAfter
= list
[i
];
683 HeapFree( GetProcessHeap(), 0, list
);
686 return hwndInsertAfter
;
690 /* fix redundant flags and values in the WINDOWPOS structure */
691 static BOOL
fixup_flags( WINDOWPOS
*winpos
)
693 WND
*wndPtr
= WIN_GetPtr( winpos
->hwnd
);
696 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
)
698 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
701 winpos
->hwnd
= wndPtr
->hwndSelf
; /* make it a full handle */
703 if (wndPtr
->dwStyle
& WS_VISIBLE
) winpos
->flags
&= ~SWP_SHOWWINDOW
;
706 winpos
->flags
&= ~SWP_HIDEWINDOW
;
707 if (!(winpos
->flags
& SWP_SHOWWINDOW
)) winpos
->flags
|= SWP_NOREDRAW
;
710 if (winpos
->cx
< 0) winpos
->cx
= 0;
711 if (winpos
->cy
< 0) winpos
->cy
= 0;
713 if ((wndPtr
->rectWindow
.right
- wndPtr
->rectWindow
.left
== winpos
->cx
) &&
714 (wndPtr
->rectWindow
.bottom
- wndPtr
->rectWindow
.top
== winpos
->cy
))
715 winpos
->flags
|= SWP_NOSIZE
; /* Already the right size */
717 if ((wndPtr
->rectWindow
.left
== winpos
->x
) && (wndPtr
->rectWindow
.top
== winpos
->y
))
718 winpos
->flags
|= SWP_NOMOVE
; /* Already the right position */
720 if (winpos
->hwnd
== GetForegroundWindow())
721 winpos
->flags
|= SWP_NOACTIVATE
; /* Already active */
722 else if ((wndPtr
->dwStyle
& (WS_POPUP
| WS_CHILD
)) != WS_CHILD
)
724 if (!(winpos
->flags
& SWP_NOACTIVATE
)) /* Bring to the top when activating */
726 winpos
->flags
&= ~SWP_NOZORDER
;
727 winpos
->hwndInsertAfter
= HWND_TOP
;
732 /* Check hwndInsertAfter */
733 if (winpos
->flags
& SWP_NOZORDER
) goto done
;
735 /* fix sign extension */
736 if (winpos
->hwndInsertAfter
== (HWND
)0xffff) winpos
->hwndInsertAfter
= HWND_TOPMOST
;
737 else if (winpos
->hwndInsertAfter
== (HWND
)0xfffe) winpos
->hwndInsertAfter
= HWND_NOTOPMOST
;
739 /* FIXME: TOPMOST not supported yet */
740 if ((winpos
->hwndInsertAfter
== HWND_TOPMOST
) ||
741 (winpos
->hwndInsertAfter
== HWND_NOTOPMOST
)) winpos
->hwndInsertAfter
= HWND_TOP
;
743 /* hwndInsertAfter must be a sibling of the window */
744 if ((winpos
->hwndInsertAfter
!= HWND_TOP
) && (winpos
->hwndInsertAfter
!= HWND_BOTTOM
))
746 winpos
->hwndInsertAfter
= WIN_GetFullHandle( winpos
->hwndInsertAfter
);
747 if (GetAncestor( winpos
->hwndInsertAfter
, GA_PARENT
) != wndPtr
->parent
) ret
= FALSE
;
750 /* don't need to change the Zorder of hwnd if it's already inserted
751 * after hwndInsertAfter or when inserting hwnd after itself.
753 if ((winpos
->hwnd
== winpos
->hwndInsertAfter
) ||
754 (winpos
->hwnd
== GetWindow( winpos
->hwndInsertAfter
, GW_HWNDNEXT
)))
755 winpos
->flags
|= SWP_NOZORDER
;
759 WIN_ReleasePtr( wndPtr
);
764 /***********************************************************************
765 * SetWindowStyle (X11DRV.@)
767 * Update the X state of a window to reflect a style change
769 void X11DRV_SetWindowStyle( HWND hwnd
, LONG oldStyle
)
771 Display
*display
= thread_display();
775 if (hwnd
== GetDesktopWindow()) return;
776 if (!(wndPtr
= WIN_GetPtr( hwnd
))) return;
777 if (wndPtr
== WND_OTHER_PROCESS
) return;
779 changed
= wndPtr
->dwStyle
^ oldStyle
;
781 if (changed
& WS_VISIBLE
)
783 if (!IsRectEmpty( &wndPtr
->rectWindow
))
785 if (wndPtr
->dwStyle
& WS_VISIBLE
)
787 TRACE( "mapping win %x\n", hwnd
);
788 TSXMapWindow( display
, get_whole_window(wndPtr
) );
792 TRACE( "unmapping win %x\n", hwnd
);
793 TSXUnmapWindow( display
, get_whole_window(wndPtr
) );
798 if (changed
& WS_DISABLED
)
800 if (wndPtr
->dwExStyle
& WS_EX_MANAGED
)
804 if (!(wm_hints
= XGetWMHints( display
, get_whole_window(wndPtr
) )))
805 wm_hints
= XAllocWMHints();
808 wm_hints
->flags
|= InputHint
;
809 wm_hints
->input
= !(wndPtr
->dwStyle
& WS_DISABLED
);
810 XSetWMHints( display
, get_whole_window(wndPtr
), wm_hints
);
816 WIN_ReleasePtr(wndPtr
);
820 /***********************************************************************
821 * SetWindowPos (X11DRV.@)
823 BOOL
X11DRV_SetWindowPos( WINDOWPOS
*winpos
)
826 RECT newWindowRect
, newClientRect
;
827 RECT oldWindowRect
, oldClientRect
;
831 TRACE( "hwnd %04x, swp (%i,%i)-(%i,%i) flags %08x\n",
832 winpos
->hwnd
, winpos
->x
, winpos
->y
,
833 winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
, winpos
->flags
);
835 bChangePos
= !(winpos
->flags
& SWP_WINE_NOHOSTMOVE
);
836 winpos
->flags
&= ~SWP_WINE_NOHOSTMOVE
;
838 /* Fix redundant flags */
839 if (!fixup_flags( winpos
)) return FALSE
;
841 /* Check window handle */
842 if (winpos
->hwnd
== GetDesktopWindow()) return FALSE
;
844 SWP_DoWinPosChanging( winpos
, &newWindowRect
, &newClientRect
);
846 if (!(wndPtr
= WIN_FindWndPtr( winpos
->hwnd
))) return FALSE
;
848 TRACE("\tcurrent (%i,%i)-(%i,%i), style %08x\n",
849 wndPtr
->rectWindow
.left
, wndPtr
->rectWindow
.top
,
850 wndPtr
->rectWindow
.right
, wndPtr
->rectWindow
.bottom
, (unsigned)wndPtr
->dwStyle
);
852 if((winpos
->flags
& (SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_SHOWWINDOW
)) != SWP_NOZORDER
)
854 if (GetAncestor( winpos
->hwnd
, GA_PARENT
) == GetDesktopWindow())
855 winpos
->hwndInsertAfter
= SWP_DoOwnedPopups( winpos
->hwnd
, winpos
->hwndInsertAfter
);
858 /* Common operations */
860 wvrFlags
= SWP_DoNCCalcSize( winpos
, &newWindowRect
, &newClientRect
);
862 if(!(winpos
->flags
& SWP_NOZORDER
) && winpos
->hwnd
!= winpos
->hwndInsertAfter
)
864 HWND parent
= GetAncestor( winpos
->hwnd
, GA_PARENT
);
865 if (parent
) WIN_LinkWindow( winpos
->hwnd
, parent
, winpos
->hwndInsertAfter
);
868 /* Reset active DCEs */
870 if( (((winpos
->flags
& SWP_AGG_NOPOSCHANGE
) != SWP_AGG_NOPOSCHANGE
) &&
871 wndPtr
->dwStyle
& WS_VISIBLE
) ||
872 (winpos
->flags
& (SWP_HIDEWINDOW
| SWP_SHOWWINDOW
)) )
876 UnionRect(&rect
, &newWindowRect
, &wndPtr
->rectWindow
);
877 DCE_InvalidateDCE(wndPtr
->hwndSelf
, &rect
);
880 oldWindowRect
= wndPtr
->rectWindow
;
881 oldClientRect
= wndPtr
->rectClient
;
883 /* Find out if we have to redraw the whole client rect */
885 if( oldClientRect
.bottom
- oldClientRect
.top
==
886 newClientRect
.bottom
- newClientRect
.top
) wvrFlags
&= ~WVR_VREDRAW
;
888 if( oldClientRect
.right
- oldClientRect
.left
==
889 newClientRect
.right
- newClientRect
.left
) wvrFlags
&= ~WVR_HREDRAW
;
891 /* FIXME: actually do something with WVR_VALIDRECTS */
893 WIN_SetRectangles( winpos
->hwnd
, &newWindowRect
, &newClientRect
);
895 if (get_whole_window(wndPtr
)) /* don't do anything if X window not created yet */
897 Display
*display
= thread_display();
899 if (!(winpos
->flags
& SWP_SHOWWINDOW
) && (winpos
->flags
& SWP_HIDEWINDOW
))
901 /* clear the update region */
902 RedrawWindow( winpos
->hwnd
, NULL
, 0, RDW_VALIDATE
| RDW_NOFRAME
|
903 RDW_NOERASE
| RDW_NOINTERNALPAINT
| RDW_ALLCHILDREN
);
904 WIN_SetStyle( winpos
->hwnd
, wndPtr
->dwStyle
& ~WS_VISIBLE
);
906 else if ((wndPtr
->dwStyle
& WS_VISIBLE
) &&
907 !IsRectEmpty( &oldWindowRect
) && IsRectEmpty( &newWindowRect
))
909 /* resizing to zero size -> unmap */
910 TRACE( "unmapping zero size win %x\n", winpos
->hwnd
);
911 TSXUnmapWindow( display
, get_whole_window(wndPtr
) );
916 X11DRV_sync_whole_window_position( display
, wndPtr
, !(winpos
->flags
& SWP_NOZORDER
) );
919 struct x11drv_win_data
*data
= wndPtr
->pDriverData
;
920 data
->whole_rect
= wndPtr
->rectWindow
;
921 X11DRV_window_to_X_rect( wndPtr
, &data
->whole_rect
);
924 if (X11DRV_sync_client_window_position( display
, wndPtr
) ||
925 (winpos
->flags
& SWP_FRAMECHANGED
))
927 /* if we moved the client area, repaint the whole non-client window */
928 XClearArea( display
, get_whole_window(wndPtr
), 0, 0, 0, 0, True
);
929 winpos
->flags
|= SWP_FRAMECHANGED
;
931 if (winpos
->flags
& SWP_SHOWWINDOW
)
933 WIN_SetStyle( winpos
->hwnd
, wndPtr
->dwStyle
| WS_VISIBLE
);
935 else if ((wndPtr
->dwStyle
& WS_VISIBLE
) &&
936 IsRectEmpty( &oldWindowRect
) && !IsRectEmpty( &newWindowRect
))
938 /* resizing from zero size to non-zero -> map */
939 TRACE( "mapping non zero size win %x\n", winpos
->hwnd
);
940 XMapWindow( display
, get_whole_window(wndPtr
) );
942 XFlush( display
); /* FIXME: should not be necessary */
945 else /* no X window, simply toggle the window style */
947 if (winpos
->flags
& SWP_SHOWWINDOW
)
948 WIN_SetStyle( winpos
->hwnd
, wndPtr
->dwStyle
| WS_VISIBLE
);
949 else if (winpos
->flags
& SWP_HIDEWINDOW
)
950 WIN_SetStyle( winpos
->hwnd
, wndPtr
->dwStyle
& ~WS_VISIBLE
);
953 /* manually expose the areas that X won't expose because they are still covered by something */
955 if (!(winpos
->flags
& SWP_SHOWWINDOW
))
956 expose_covered_parent_area( wndPtr
, &oldWindowRect
);
958 if (wndPtr
->dwStyle
& WS_VISIBLE
)
959 expose_covered_window_area( wndPtr
, &oldClientRect
, winpos
->flags
& SWP_FRAMECHANGED
);
961 WIN_ReleaseWndPtr(wndPtr
);
963 if (wvrFlags
& WVR_REDRAW
) RedrawWindow( winpos
->hwnd
, NULL
, 0, RDW_INVALIDATE
| RDW_ERASE
);
965 if (winpos
->hwnd
== CARET_GetHwnd())
967 if( winpos
->flags
& SWP_HIDEWINDOW
)
968 HideCaret(winpos
->hwnd
);
969 else if (winpos
->flags
& SWP_SHOWWINDOW
)
970 ShowCaret(winpos
->hwnd
);
973 if (!(winpos
->flags
& SWP_NOACTIVATE
))
975 /* child windows get WM_CHILDACTIVATE message */
976 if ((GetWindowLongW( winpos
->hwnd
, GWL_STYLE
) & (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
977 SendMessageA( winpos
->hwnd
, WM_CHILDACTIVATE
, 0, 0 );
979 SetActiveWindow( winpos
->hwnd
);
982 /* And last, send the WM_WINDOWPOSCHANGED message */
984 TRACE("\tstatus flags = %04x\n", winpos
->flags
& SWP_AGG_STATUSFLAGS
);
986 if (((winpos
->flags
& SWP_AGG_STATUSFLAGS
) != SWP_AGG_NOPOSCHANGE
) &&
987 !(winpos
->flags
& SWP_NOSENDCHANGING
))
988 SendMessageA( winpos
->hwnd
, WM_WINDOWPOSCHANGED
, 0, (LPARAM
)winpos
);
994 /***********************************************************************
997 * Find a suitable place for an iconic window.
999 static POINT
WINPOS_FindIconPos( WND
* wndPtr
, POINT pt
)
1003 short x
, y
, xspacing
, yspacing
;
1005 GetClientRect( wndPtr
->parent
, &rectParent
);
1006 if ((pt
.x
>= rectParent
.left
) && (pt
.x
+ GetSystemMetrics(SM_CXICON
) < rectParent
.right
) &&
1007 (pt
.y
>= rectParent
.top
) && (pt
.y
+ GetSystemMetrics(SM_CYICON
) < rectParent
.bottom
))
1008 return pt
; /* The icon already has a suitable position */
1010 xspacing
= GetSystemMetrics(SM_CXICONSPACING
);
1011 yspacing
= GetSystemMetrics(SM_CYICONSPACING
);
1013 list
= WIN_ListChildren( wndPtr
->parent
);
1014 y
= rectParent
.bottom
;
1017 x
= rectParent
.left
;
1020 /* Check if another icon already occupies this spot */
1021 /* FIXME: this is completely inefficient */
1027 for (i
= 0; list
[i
]; i
++)
1029 if (list
[i
] == wndPtr
->hwndSelf
) continue;
1030 if (!IsIconic( list
[i
] )) continue;
1031 if (!(childPtr
= WIN_FindWndPtr( list
[i
] ))) continue;
1032 if ((childPtr
->rectWindow
.left
< x
+ xspacing
) &&
1033 (childPtr
->rectWindow
.right
>= x
) &&
1034 (childPtr
->rectWindow
.top
<= y
) &&
1035 (childPtr
->rectWindow
.bottom
> y
- yspacing
))
1037 WIN_ReleaseWndPtr( childPtr
);
1038 break; /* There's a window in there */
1040 WIN_ReleaseWndPtr( childPtr
);
1044 /* found something here, try next spot */
1050 /* No window was found, so it's OK for us */
1051 pt
.x
= x
+ (xspacing
- GetSystemMetrics(SM_CXICON
)) / 2;
1052 pt
.y
= y
- (yspacing
+ GetSystemMetrics(SM_CYICON
)) / 2;
1055 } while(x
<= rectParent
.right
-xspacing
);
1064 UINT
WINPOS_MinMaximize( HWND hwnd
, UINT cmd
, LPRECT rect
)
1070 WINDOWPLACEMENT wpl
;
1072 TRACE("0x%04x %u\n", hwnd
, cmd
);
1074 wpl
.length
= sizeof(wpl
);
1075 GetWindowPlacement( hwnd
, &wpl
);
1077 if (HOOK_CallHooksA( WH_CBT
, HCBT_MINMAX
, (WPARAM
)hwnd
, cmd
))
1078 return SWP_NOSIZE
| SWP_NOMOVE
;
1080 if (IsIconic( hwnd
))
1082 if (cmd
== SW_MINIMIZE
) return SWP_NOSIZE
| SWP_NOMOVE
;
1083 if (!SendMessageA( hwnd
, WM_QUERYOPEN
, 0, 0 )) return SWP_NOSIZE
| SWP_NOMOVE
;
1084 swpFlags
|= SWP_NOCOPYBITS
;
1087 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return 0;
1089 size
.x
= wndPtr
->rectWindow
.left
;
1090 size
.y
= wndPtr
->rectWindow
.top
;
1095 if( wndPtr
->dwStyle
& WS_MAXIMIZE
) wndPtr
->flags
|= WIN_RESTORE_MAX
;
1096 else wndPtr
->flags
&= ~WIN_RESTORE_MAX
;
1098 WIN_SetStyle( hwnd
, (wndPtr
->dwStyle
& ~WS_MAXIMIZE
) | WS_MINIMIZE
);
1100 X11DRV_set_iconic_state( wndPtr
);
1102 wpl
.ptMinPosition
= WINPOS_FindIconPos( wndPtr
, wpl
.ptMinPosition
);
1104 SetRect( rect
, wpl
.ptMinPosition
.x
, wpl
.ptMinPosition
.y
,
1105 GetSystemMetrics(SM_CXICON
), GetSystemMetrics(SM_CYICON
) );
1106 swpFlags
|= SWP_NOCOPYBITS
;
1110 WINPOS_GetMinMaxInfo( hwnd
, &size
, &wpl
.ptMaxPosition
, NULL
, NULL
);
1112 old_style
= WIN_SetStyle( hwnd
, (wndPtr
->dwStyle
& ~WS_MINIMIZE
) | WS_MAXIMIZE
);
1113 if (old_style
& WS_MINIMIZE
)
1115 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1116 X11DRV_set_iconic_state( wndPtr
);
1118 SetRect( rect
, wpl
.ptMaxPosition
.x
, wpl
.ptMaxPosition
.y
, size
.x
, size
.y
);
1122 old_style
= WIN_SetStyle( hwnd
, wndPtr
->dwStyle
& ~(WS_MINIMIZE
|WS_MAXIMIZE
) );
1123 if (old_style
& WS_MINIMIZE
)
1125 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1126 X11DRV_set_iconic_state( wndPtr
);
1128 if( wndPtr
->flags
& WIN_RESTORE_MAX
)
1130 /* Restore to maximized position */
1131 WINPOS_GetMinMaxInfo( hwnd
, &size
, &wpl
.ptMaxPosition
, NULL
, NULL
);
1132 WIN_SetStyle( hwnd
, wndPtr
->dwStyle
| WS_MAXIMIZE
);
1133 SetRect( rect
, wpl
.ptMaxPosition
.x
, wpl
.ptMaxPosition
.y
, size
.x
, size
.y
);
1137 else if (!(old_style
& WS_MAXIMIZE
)) break;
1139 /* Restore to normal position */
1141 *rect
= wpl
.rcNormalPosition
;
1142 rect
->right
-= rect
->left
;
1143 rect
->bottom
-= rect
->top
;
1148 WIN_ReleaseWndPtr( wndPtr
);
1153 /***********************************************************************
1154 * ShowWindow (X11DRV.@)
1156 BOOL
X11DRV_ShowWindow( HWND hwnd
, INT cmd
)
1158 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
1159 BOOL wasVisible
, showFlag
;
1160 RECT newPos
= {0, 0, 0, 0};
1163 if (!wndPtr
) return FALSE
;
1164 hwnd
= wndPtr
->hwndSelf
; /* make it a full handle */
1166 TRACE("hwnd=%04x, cmd=%d\n", hwnd
, cmd
);
1168 wasVisible
= (wndPtr
->dwStyle
& WS_VISIBLE
) != 0;
1173 if (!wasVisible
) goto END
;;
1174 swp
|= SWP_HIDEWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
|
1175 SWP_NOACTIVATE
| SWP_NOZORDER
;
1178 case SW_SHOWMINNOACTIVE
:
1179 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1181 case SW_SHOWMINIMIZED
:
1182 case SW_FORCEMINIMIZE
: /* FIXME: Does not work if thread is hung. */
1183 swp
|= SWP_SHOWWINDOW
;
1186 swp
|= SWP_FRAMECHANGED
;
1187 if( !(wndPtr
->dwStyle
& WS_MINIMIZE
) )
1188 swp
|= WINPOS_MinMaximize( hwnd
, SW_MINIMIZE
, &newPos
);
1189 else swp
|= SWP_NOSIZE
| SWP_NOMOVE
;
1192 case SW_SHOWMAXIMIZED
: /* same as SW_MAXIMIZE */
1193 swp
|= SWP_SHOWWINDOW
| SWP_FRAMECHANGED
;
1194 if( !(wndPtr
->dwStyle
& WS_MAXIMIZE
) )
1195 swp
|= WINPOS_MinMaximize( hwnd
, SW_MAXIMIZE
, &newPos
);
1196 else swp
|= SWP_NOSIZE
| SWP_NOMOVE
;
1200 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1203 swp
|= SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
1206 * ShowWindow has a little peculiar behavior that if the
1207 * window is already the topmost window, it will not
1210 if (GetTopWindow((HWND
)0)==hwnd
&& (wasVisible
|| GetActiveWindow() == hwnd
))
1211 swp
|= SWP_NOACTIVATE
;
1215 case SW_SHOWNOACTIVATE
:
1216 swp
|= SWP_NOZORDER
;
1217 if (GetActiveWindow()) swp
|= SWP_NOACTIVATE
;
1219 case SW_SHOWNORMAL
: /* same as SW_NORMAL: */
1220 case SW_SHOWDEFAULT
: /* FIXME: should have its own handler */
1222 swp
|= SWP_SHOWWINDOW
| SWP_FRAMECHANGED
;
1224 if( wndPtr
->dwStyle
& (WS_MINIMIZE
| WS_MAXIMIZE
) )
1225 swp
|= WINPOS_MinMaximize( hwnd
, SW_RESTORE
, &newPos
);
1226 else swp
|= SWP_NOSIZE
| SWP_NOMOVE
;
1230 showFlag
= (cmd
!= SW_HIDE
);
1231 if (showFlag
!= wasVisible
)
1233 SendMessageA( hwnd
, WM_SHOWWINDOW
, showFlag
, 0 );
1234 if (!IsWindow( hwnd
)) goto END
;
1237 /* We can't activate a child window */
1238 if ((wndPtr
->dwStyle
& WS_CHILD
) &&
1239 !(wndPtr
->dwExStyle
& WS_EX_MDICHILD
))
1240 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1242 SetWindowPos( hwnd
, HWND_TOP
, newPos
.left
, newPos
.top
,
1243 newPos
.right
, newPos
.bottom
, LOWORD(swp
) );
1246 /* FIXME: This will cause the window to be activated irrespective
1247 * of whether it is owned by the same thread. Has to be done
1251 if (hwnd
== GetActiveWindow())
1252 WINPOS_ActivateOtherWindow(hwnd
);
1254 /* Revert focus to parent */
1255 if (hwnd
== GetFocus() || IsChild(hwnd
, GetFocus()))
1256 SetFocus( GetParent(hwnd
) );
1258 if (!IsWindow( hwnd
)) goto END
;
1259 else if( wndPtr
->dwStyle
& WS_MINIMIZE
) WINPOS_ShowIconTitle( hwnd
, TRUE
);
1261 if (wndPtr
->flags
& WIN_NEED_SIZE
)
1263 /* should happen only in CreateWindowEx() */
1264 int wParam
= SIZE_RESTORED
;
1266 wndPtr
->flags
&= ~WIN_NEED_SIZE
;
1267 if (wndPtr
->dwStyle
& WS_MAXIMIZE
) wParam
= SIZE_MAXIMIZED
;
1268 else if (wndPtr
->dwStyle
& WS_MINIMIZE
) wParam
= SIZE_MINIMIZED
;
1269 SendMessageA( hwnd
, WM_SIZE
, wParam
,
1270 MAKELONG(wndPtr
->rectClient
.right
-wndPtr
->rectClient
.left
,
1271 wndPtr
->rectClient
.bottom
-wndPtr
->rectClient
.top
));
1272 SendMessageA( hwnd
, WM_MOVE
, 0,
1273 MAKELONG(wndPtr
->rectClient
.left
, wndPtr
->rectClient
.top
) );
1277 WIN_ReleaseWndPtr(wndPtr
);
1282 /**********************************************************************
1285 void X11DRV_MapNotify( HWND hwnd
, XMapEvent
*event
)
1287 HWND hwndFocus
= GetFocus();
1290 if (!(win
= WIN_GetPtr( hwnd
))) return;
1292 if ((win
->dwStyle
& WS_VISIBLE
) &&
1293 (win
->dwStyle
& WS_MINIMIZE
) &&
1294 (win
->dwExStyle
& WS_EX_MANAGED
))
1297 unsigned int width
, height
, border
, depth
;
1300 LONG style
= (win
->dwStyle
& ~(WS_MINIMIZE
|WS_MAXIMIZE
)) | WS_VISIBLE
;
1304 XGetGeometry( event
->display
, get_whole_window(win
), &root
, &x
, &y
, &width
, &height
,
1306 XTranslateCoordinates( event
->display
, get_whole_window(win
), root
, 0, 0, &x
, &y
, &top
);
1307 wine_tsx11_unlock();
1310 rect
.right
= x
+ width
;
1311 rect
.bottom
= y
+ height
;
1312 X11DRV_X_to_window_rect( win
, &rect
);
1314 DCE_InvalidateDCE( hwnd
, &win
->rectWindow
);
1316 if (win
->flags
& WIN_RESTORE_MAX
) style
|= WS_MAXIMIZE
;
1317 WIN_SetStyle( hwnd
, style
);
1318 WIN_ReleasePtr( win
);
1320 WIN_InternalShowOwnedPopups( hwnd
, TRUE
, TRUE
);
1321 SendMessageA( hwnd
, WM_SHOWWINDOW
, SW_RESTORE
, 0 );
1322 SetWindowPos( hwnd
, 0, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
,
1323 SWP_NOZORDER
| SWP_WINE_NOHOSTMOVE
);
1325 else WIN_ReleasePtr( win
);
1326 if (hwndFocus
&& IsChild( hwnd
, hwndFocus
)) X11DRV_SetFocus(hwndFocus
); /* FIXME */
1330 /**********************************************************************
1331 * X11DRV_UnmapNotify
1333 void X11DRV_UnmapNotify( HWND hwnd
, XUnmapEvent
*event
)
1337 if (!(win
= WIN_GetPtr( hwnd
))) return;
1339 if ((win
->dwStyle
& WS_VISIBLE
) && (win
->dwExStyle
& WS_EX_MANAGED
))
1341 if (win
->dwStyle
& WS_MAXIMIZE
)
1342 win
->flags
|= WIN_RESTORE_MAX
;
1344 win
->flags
&= ~WIN_RESTORE_MAX
;
1346 WIN_SetStyle( hwnd
, (win
->dwStyle
& ~WS_MAXIMIZE
) | WS_MINIMIZE
);
1347 WIN_ReleasePtr( win
);
1350 SendMessageA( hwnd
, WM_SHOWWINDOW
, SW_MINIMIZE
, 0 );
1351 SetWindowPos( hwnd
, 0, 0, 0, GetSystemMetrics(SM_CXICON
), GetSystemMetrics(SM_CYICON
),
1352 SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_WINE_NOHOSTMOVE
);
1354 WIN_InternalShowOwnedPopups( hwnd
, FALSE
, TRUE
);
1356 else WIN_ReleasePtr( win
);
1360 /***********************************************************************
1363 * Synchronize internal z-order with the window manager's.
1365 static Window
__get_common_ancestor( Display
*display
, Window A
, Window B
,
1366 Window
** children
, unsigned* total
)
1368 /* find the real root window */
1370 Window root
, *childrenB
;
1373 while( A
!= B
&& A
&& B
)
1375 TSXQueryTree( display
, A
, &root
, &A
, children
, total
);
1376 TSXQueryTree( display
, B
, &root
, &B
, &childrenB
, &totalB
);
1377 if( childrenB
) TSXFree( childrenB
);
1378 if( *children
) TSXFree( *children
), *children
= NULL
;
1383 TSXQueryTree( display
, A
, &root
, &B
, children
, total
);
1389 static Window
__get_top_decoration( Display
*display
, Window w
, Window ancestor
)
1391 Window
* children
, root
, prev
= w
, parent
= w
;
1397 TSXQueryTree( display
, w
, &root
, &parent
, &children
, &total
);
1398 if( children
) TSXFree( children
);
1399 } while( parent
&& parent
!= ancestor
);
1400 TRACE("\t%08x -> %08x\n", (unsigned)prev
, (unsigned)w
);
1401 return ( parent
) ? w
: 0 ;
1404 static unsigned __td_lookup( Window w
, Window
* list
, unsigned max
)
1407 for( i
= max
- 1; i
>= 0; i
-- ) if( list
[i
] == w
) break;
1411 static HWND
query_zorder( Display
*display
, HWND hWndCheck
)
1413 HWND hwndInsertAfter
= HWND_TOP
;
1414 Window w
, parent
, *children
= NULL
;
1415 unsigned total
, check
, pos
, best
;
1416 HWND
*list
= WIN_ListChildren( GetDesktopWindow() );
1417 HWND hwndA
= 0, hwndB
= 0;
1420 /* find at least two managed windows */
1421 if (!list
) return 0;
1422 for (i
= 0; list
[i
]; i
++)
1424 if (!(GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_MANAGED
)) continue;
1425 if (!(GetWindowLongW( list
[i
], GWL_STYLE
) & WS_VISIBLE
)) continue;
1426 if (!hwndA
) hwndA
= list
[i
];
1433 if (!hwndA
|| !hwndB
) goto done
;
1435 parent
= __get_common_ancestor( display
, X11DRV_get_whole_window(hwndA
),
1436 X11DRV_get_whole_window(hwndB
), &children
, &total
);
1437 if( parent
&& children
)
1439 /* w is the ancestor if hWndCheck that is a direct descendant of 'parent' */
1441 w
= __get_top_decoration( display
, X11DRV_get_whole_window(hWndCheck
), parent
);
1443 if( w
!= children
[total
-1] ) /* check if at the top */
1445 /* X child at index 0 is at the bottom, at index total-1 is at the top */
1446 check
= __td_lookup( w
, children
, total
);
1449 /* go through all windows in Wine z-order... */
1450 for (i
= 0; list
[i
]; i
++)
1452 if (list
[i
] == hWndCheck
) continue;
1453 if (!(GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_MANAGED
)) continue;
1454 if (!(w
= __get_top_decoration( display
, X11DRV_get_whole_window(list
[i
]),
1455 parent
))) continue;
1456 pos
= __td_lookup( w
, children
, total
);
1457 if( pos
< best
&& pos
> check
)
1459 /* find a nearest Wine window precedes hWndCheck in the real z-order */
1461 hwndInsertAfter
= list
[i
];
1463 if( best
- check
== 1 ) break;
1467 if( children
) TSXFree( children
);
1470 HeapFree( GetProcessHeap(), 0, list
);
1471 return hwndInsertAfter
;
1475 /***********************************************************************
1476 * X11DRV_ConfigureNotify
1478 void X11DRV_ConfigureNotify( HWND hwnd
, XConfigureEvent
*event
)
1480 HWND oldInsertAfter
;
1481 struct x11drv_win_data
*data
;
1485 int x
= event
->x
, y
= event
->y
;
1487 if (!(win
= WIN_GetPtr( hwnd
))) return;
1488 data
= win
->pDriverData
;
1492 if (!event
->send_event
) /* normal event, need to map coordinates to the root */
1496 XTranslateCoordinates( event
->display
, data
->whole_window
, root_window
,
1497 0, 0, &x
, &y
, &child
);
1498 wine_tsx11_unlock();
1502 rect
.right
= x
+ event
->width
;
1503 rect
.bottom
= y
+ event
->height
;
1504 TRACE( "win %x new X rect %d,%d,%dx%d (event %d,%d,%dx%d)\n",
1505 hwnd
, rect
.left
, rect
.top
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
,
1506 event
->x
, event
->y
, event
->width
, event
->height
);
1507 X11DRV_X_to_window_rect( win
, &rect
);
1508 WIN_ReleasePtr( win
);
1511 winpos
.x
= rect
.left
;
1512 winpos
.y
= rect
.top
;
1513 winpos
.cx
= rect
.right
- rect
.left
;
1514 winpos
.cy
= rect
.bottom
- rect
.top
;
1515 winpos
.flags
= SWP_NOACTIVATE
;
1517 /* Get Z-order (FIXME) */
1519 winpos
.hwndInsertAfter
= query_zorder( event
->display
, hwnd
);
1521 /* needs to find the first Visible Window above the current one */
1522 oldInsertAfter
= hwnd
;
1525 oldInsertAfter
= GetWindow( oldInsertAfter
, GW_HWNDPREV
);
1526 if (!oldInsertAfter
)
1528 oldInsertAfter
= HWND_TOP
;
1531 if (GetWindowLongA( oldInsertAfter
, GWL_STYLE
) & WS_VISIBLE
) break;
1534 /* Compare what has changed */
1536 GetWindowRect( hwnd
, &rect
);
1537 if (rect
.left
== winpos
.x
&& rect
.top
== winpos
.y
) winpos
.flags
|= SWP_NOMOVE
;
1539 TRACE( "%04x moving from (%d,%d) to (%d,%d)\n",
1540 hwnd
, rect
.left
, rect
.top
, winpos
.x
, winpos
.y
);
1542 if ((rect
.right
- rect
.left
== winpos
.cx
&& rect
.bottom
- rect
.top
== winpos
.cy
) ||
1544 (IsRectEmpty( &rect
) && winpos
.cx
== 1 && winpos
.cy
== 1))
1545 winpos
.flags
|= SWP_NOSIZE
;
1547 TRACE( "%04x resizing from (%dx%d) to (%dx%d)\n",
1548 hwnd
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
1549 winpos
.cx
, winpos
.cy
);
1551 if (winpos
.hwndInsertAfter
== oldInsertAfter
) winpos
.flags
|= SWP_NOZORDER
;
1553 TRACE( "%04x restacking from after %04x to after %04x\n",
1554 hwnd
, oldInsertAfter
, winpos
.hwndInsertAfter
);
1556 /* if nothing changed, don't do anything */
1557 if (winpos
.flags
== (SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
)) return;
1559 SetWindowPos( hwnd
, winpos
.hwndInsertAfter
, winpos
.x
, winpos
.y
,
1560 winpos
.cx
, winpos
.cy
, winpos
.flags
| SWP_WINE_NOHOSTMOVE
);
1564 /***********************************************************************
1565 * SetWindowRgn (X11DRV.@)
1567 * Assign specified region to window (for non-rectangular windows)
1569 int X11DRV_SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL redraw
)
1573 if ((wndPtr
= WIN_GetPtr( hwnd
)) == WND_OTHER_PROCESS
)
1575 if (IsWindow( hwnd
))
1576 FIXME( "not supported on other process window %x\n", hwnd
);
1581 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
1585 if (wndPtr
->hrgnWnd
== hrgn
)
1587 WIN_ReleasePtr( wndPtr
);
1591 if (wndPtr
->hrgnWnd
)
1593 /* delete previous region */
1594 DeleteObject(wndPtr
->hrgnWnd
);
1595 wndPtr
->hrgnWnd
= 0;
1597 wndPtr
->hrgnWnd
= hrgn
;
1599 #ifdef HAVE_LIBXSHAPE
1601 Display
*display
= thread_display();
1602 X11DRV_WND_DATA
*data
= wndPtr
->pDriverData
;
1604 if (data
->whole_window
)
1608 TSXShapeCombineMask( display
, data
->whole_window
,
1609 ShapeBounding
, 0, 0, None
, ShapeSet
);
1614 int x_offset
, y_offset
;
1616 DWORD dwBufferSize
= GetRegionData(hrgn
, 0, NULL
);
1617 PRGNDATA pRegionData
= HeapAlloc(GetProcessHeap(), 0, dwBufferSize
);
1620 WIN_ReleasePtr( wndPtr
);
1623 GetRegionData(hrgn
, dwBufferSize
, pRegionData
);
1624 size
= pRegionData
->rdh
.nCount
;
1625 x_offset
= wndPtr
->rectWindow
.left
- data
->whole_rect
.left
;
1626 y_offset
= wndPtr
->rectWindow
.top
- data
->whole_rect
.top
;
1627 /* convert region's "Windows rectangles" to XRectangles */
1628 aXRect
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(*aXRect
) );
1631 XRectangle
* pCurrRect
= aXRect
;
1632 RECT
*pRect
= (RECT
*) pRegionData
->Buffer
;
1633 for (; pRect
< ((RECT
*) pRegionData
->Buffer
) + size
; ++pRect
, ++pCurrRect
)
1635 pCurrRect
->x
= pRect
->left
+ x_offset
;
1636 pCurrRect
->y
= pRect
->top
+ y_offset
;
1637 pCurrRect
->height
= pRect
->bottom
- pRect
->top
;
1638 pCurrRect
->width
= pRect
->right
- pRect
->left
;
1640 TRACE("Rectangle %04d of %04ld data: X=%04d, Y=%04d, Height=%04d, Width=%04d.\n",
1641 pRect
- (RECT
*) pRegionData
->Buffer
,
1649 /* shape = non-rectangular windows (X11/extensions) */
1650 TSXShapeCombineRectangles( display
, data
->whole_window
, ShapeBounding
,
1652 pCurrRect
- aXRect
, ShapeSet
, YXBanded
);
1653 HeapFree(GetProcessHeap(), 0, aXRect
);
1655 HeapFree(GetProcessHeap(), 0, pRegionData
);
1659 #endif /* HAVE_LIBXSHAPE */
1661 WIN_ReleasePtr( wndPtr
);
1662 if (redraw
) RedrawWindow( hwnd
, NULL
, 0, RDW_FRAME
| RDW_INVALIDATE
| RDW_ERASE
);
1667 /***********************************************************************
1670 * Draw the frame used when moving or resizing window.
1672 * FIXME: This causes problems in Win95 mode. (why?)
1674 static void draw_moving_frame( HDC hdc
, RECT
*rect
, BOOL thickframe
)
1678 const int width
= GetSystemMetrics(SM_CXFRAME
);
1679 const int height
= GetSystemMetrics(SM_CYFRAME
);
1681 HBRUSH hbrush
= SelectObject( hdc
, GetStockObject( GRAY_BRUSH
) );
1682 PatBlt( hdc
, rect
->left
, rect
->top
,
1683 rect
->right
- rect
->left
- width
, height
, PATINVERT
);
1684 PatBlt( hdc
, rect
->left
, rect
->top
+ height
, width
,
1685 rect
->bottom
- rect
->top
- height
, PATINVERT
);
1686 PatBlt( hdc
, rect
->left
+ width
, rect
->bottom
- 1,
1687 rect
->right
- rect
->left
- width
, -height
, PATINVERT
);
1688 PatBlt( hdc
, rect
->right
- 1, rect
->top
, -width
,
1689 rect
->bottom
- rect
->top
- height
, PATINVERT
);
1690 SelectObject( hdc
, hbrush
);
1692 else DrawFocusRect( hdc
, rect
);
1696 /***********************************************************************
1699 * Initialisation of a move or resize, when initiatied from a menu choice.
1700 * Return hit test code for caption or sizing border.
1702 static LONG
start_size_move( HWND hwnd
, WPARAM wParam
, POINT
*capturePoint
, LONG style
)
1709 GetWindowRect( hwnd
, &rectWindow
);
1711 if ((wParam
& 0xfff0) == SC_MOVE
)
1713 /* Move pointer at the center of the caption */
1715 NC_GetInsideRect( hwnd
, &rect
);
1716 if (style
& WS_SYSMENU
)
1717 rect
.left
+= GetSystemMetrics(SM_CXSIZE
) + 1;
1718 if (style
& WS_MINIMIZEBOX
)
1719 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
1720 if (style
& WS_MAXIMIZEBOX
)
1721 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
1722 pt
.x
= rectWindow
.left
+ (rect
.right
- rect
.left
) / 2;
1723 pt
.y
= rectWindow
.top
+ rect
.top
+ GetSystemMetrics(SM_CYSIZE
)/2;
1724 hittest
= HTCAPTION
;
1731 GetMessageW( &msg
, 0, WM_KEYFIRST
, WM_MOUSELAST
);
1732 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
1737 hittest
= NC_HandleNCHitTest( hwnd
, msg
.pt
);
1738 if ((hittest
< HTLEFT
) || (hittest
> HTBOTTOMRIGHT
))
1750 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
1751 pt
.y
= rectWindow
.top
+ GetSystemMetrics(SM_CYFRAME
) / 2;
1755 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
1756 pt
.y
= rectWindow
.bottom
- GetSystemMetrics(SM_CYFRAME
) / 2;
1760 pt
.x
= rectWindow
.left
+ GetSystemMetrics(SM_CXFRAME
) / 2;
1761 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
1765 pt
.x
= rectWindow
.right
- GetSystemMetrics(SM_CXFRAME
) / 2;
1766 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
1769 case VK_ESCAPE
: return 0;
1775 SetCursorPos( pt
.x
, pt
.y
);
1776 NC_HandleSetCursor( hwnd
, (WPARAM
)hwnd
, MAKELONG( hittest
, WM_MOUSEMOVE
));
1781 /***********************************************************************
1782 * SysCommandSizeMove (X11DRV.@)
1784 * Perform SC_MOVE and SC_SIZE commands.
1786 void X11DRV_SysCommandSizeMove( HWND hwnd
, WPARAM wParam
)
1789 RECT sizingRect
, mouseRect
, origRect
;
1792 LONG hittest
= (LONG
)(wParam
& 0x0f);
1793 HCURSOR16 hDragCursor
= 0, hOldCursor
= 0;
1794 POINT minTrack
, maxTrack
;
1795 POINT capturePoint
, pt
;
1796 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
1797 LONG exstyle
= GetWindowLongA( hwnd
, GWL_EXSTYLE
);
1798 BOOL thickframe
= HAS_THICKFRAME( style
, exstyle
);
1799 BOOL iconic
= style
& WS_MINIMIZE
;
1801 DWORD dwPoint
= GetMessagePos ();
1802 BOOL DragFullWindows
= FALSE
;
1805 Display
*old_gdi_display
= NULL
;
1806 Display
*display
= thread_display();
1808 SystemParametersInfoA(SPI_GETDRAGFULLWINDOWS
, 0, &DragFullWindows
, 0);
1810 pt
.x
= SLOWORD(dwPoint
);
1811 pt
.y
= SHIWORD(dwPoint
);
1814 if (IsZoomed(hwnd
) || !IsWindowVisible(hwnd
) || (exstyle
& WS_EX_MANAGED
)) return;
1816 if ((wParam
& 0xfff0) == SC_MOVE
)
1818 if (!hittest
) hittest
= start_size_move( hwnd
, wParam
, &capturePoint
, style
);
1819 if (!hittest
) return;
1823 if (!thickframe
) return;
1824 if ( hittest
&& hittest
!= HTSYSMENU
) hittest
+= 2;
1828 hittest
= start_size_move( hwnd
, wParam
, &capturePoint
, style
);
1837 /* Get min/max info */
1839 WINPOS_GetMinMaxInfo( hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
1840 GetWindowRect( hwnd
, &sizingRect
);
1841 if (style
& WS_CHILD
)
1843 parent
= GetParent(hwnd
);
1844 /* make sizing rect relative to parent */
1845 MapWindowPoints( 0, parent
, (POINT
*)&sizingRect
, 2 );
1846 GetClientRect( parent
, &mouseRect
);
1851 SetRect(&mouseRect
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
));
1853 origRect
= sizingRect
;
1855 if (ON_LEFT_BORDER(hittest
))
1857 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.right
-maxTrack
.x
);
1858 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.right
-minTrack
.x
);
1860 else if (ON_RIGHT_BORDER(hittest
))
1862 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.left
+minTrack
.x
);
1863 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.left
+maxTrack
.x
);
1865 if (ON_TOP_BORDER(hittest
))
1867 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.bottom
-maxTrack
.y
);
1868 mouseRect
.bottom
= min( mouseRect
.bottom
,sizingRect
.bottom
-minTrack
.y
);
1870 else if (ON_BOTTOM_BORDER(hittest
))
1872 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.top
+minTrack
.y
);
1873 mouseRect
.bottom
= min( mouseRect
.bottom
, sizingRect
.top
+maxTrack
.y
);
1875 if (parent
) MapWindowPoints( parent
, 0, (LPPOINT
)&mouseRect
, 2 );
1877 /* Retrieve a default cache DC (without using the window style) */
1878 hdc
= GetDCEx( parent
, 0, DCX_CACHE
);
1880 if( iconic
) /* create a cursor for dragging */
1882 HICON hIcon
= GetClassLongA( hwnd
, GCL_HICON
);
1883 if(!hIcon
) hIcon
= (HICON
)SendMessageA( hwnd
, WM_QUERYDRAGICON
, 0, 0L);
1884 if( hIcon
) hDragCursor
= CURSORICON_IconToCursor( hIcon
, TRUE
);
1885 if( !hDragCursor
) iconic
= FALSE
;
1888 /* repaint the window before moving it around */
1889 RedrawWindow( hwnd
, NULL
, 0, RDW_UPDATENOW
| RDW_ALLCHILDREN
);
1891 SendMessageA( hwnd
, WM_ENTERSIZEMOVE
, 0, 0 );
1894 /* grab the server only when moving top-level windows without desktop */
1895 grab
= (!DragFullWindows
&& !parent
&& (root_window
== DefaultRootWindow(gdi_display
)));
1900 XSync( gdi_display
, False
);
1901 XGrabServer( display
);
1902 XSync( display
, False
);
1903 /* switch gdi display to the thread display, since the server is grabbed */
1904 old_gdi_display
= gdi_display
;
1905 gdi_display
= display
;
1907 XGrabPointer( display
, X11DRV_get_whole_window(hwnd
), False
,
1908 PointerMotionMask
| ButtonPressMask
| ButtonReleaseMask
,
1909 GrabModeAsync
, GrabModeAsync
,
1910 parent
? X11DRV_get_client_window(parent
) : root_window
,
1911 None
, CurrentTime
);
1912 wine_tsx11_unlock();
1918 if (!GetMessageW( &msg
, 0, WM_KEYFIRST
, WM_MOUSELAST
)) break;
1919 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
1921 /* Exit on button-up, Return, or Esc */
1922 if ((msg
.message
== WM_LBUTTONUP
) ||
1923 ((msg
.message
== WM_KEYDOWN
) &&
1924 ((msg
.wParam
== VK_RETURN
) || (msg
.wParam
== VK_ESCAPE
)))) break;
1926 if ((msg
.message
!= WM_KEYDOWN
) && (msg
.message
!= WM_MOUSEMOVE
))
1927 continue; /* We are not interested in other messages */
1931 if (msg
.message
== WM_KEYDOWN
) switch(msg
.wParam
)
1933 case VK_UP
: pt
.y
-= 8; break;
1934 case VK_DOWN
: pt
.y
+= 8; break;
1935 case VK_LEFT
: pt
.x
-= 8; break;
1936 case VK_RIGHT
: pt
.x
+= 8; break;
1939 pt
.x
= max( pt
.x
, mouseRect
.left
);
1940 pt
.x
= min( pt
.x
, mouseRect
.right
);
1941 pt
.y
= max( pt
.y
, mouseRect
.top
);
1942 pt
.y
= min( pt
.y
, mouseRect
.bottom
);
1944 dx
= pt
.x
- capturePoint
.x
;
1945 dy
= pt
.y
- capturePoint
.y
;
1953 if( iconic
) /* ok, no system popup tracking */
1955 hOldCursor
= SetCursor(hDragCursor
);
1957 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1959 else if(!DragFullWindows
)
1960 draw_moving_frame( hdc
, &sizingRect
, thickframe
);
1963 if (msg
.message
== WM_KEYDOWN
) SetCursorPos( pt
.x
, pt
.y
);
1966 RECT newRect
= sizingRect
;
1967 WPARAM wpSizingHit
= 0;
1969 if (hittest
== HTCAPTION
) OffsetRect( &newRect
, dx
, dy
);
1970 if (ON_LEFT_BORDER(hittest
)) newRect
.left
+= dx
;
1971 else if (ON_RIGHT_BORDER(hittest
)) newRect
.right
+= dx
;
1972 if (ON_TOP_BORDER(hittest
)) newRect
.top
+= dy
;
1973 else if (ON_BOTTOM_BORDER(hittest
)) newRect
.bottom
+= dy
;
1974 if(!iconic
&& !DragFullWindows
) draw_moving_frame( hdc
, &sizingRect
, thickframe
);
1977 /* determine the hit location */
1978 if (hittest
>= HTLEFT
&& hittest
<= HTBOTTOMRIGHT
)
1979 wpSizingHit
= WMSZ_LEFT
+ (hittest
- HTLEFT
);
1980 SendMessageA( hwnd
, WM_SIZING
, wpSizingHit
, (LPARAM
)&newRect
);
1984 if(!DragFullWindows
)
1985 draw_moving_frame( hdc
, &newRect
, thickframe
);
1987 /* To avoid any deadlocks, all the locks on the windows
1988 structures must be suspended before the SetWindowPos */
1989 iWndsLocks
= WIN_SuspendWndsLock();
1990 SetWindowPos( hwnd
, 0, newRect
.left
, newRect
.top
,
1991 newRect
.right
- newRect
.left
,
1992 newRect
.bottom
- newRect
.top
,
1993 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
1994 WIN_RestoreWndsLock(iWndsLocks
);
1997 sizingRect
= newRect
;
2005 if( moved
) /* restore cursors, show icon title later on */
2007 ShowCursor( FALSE
);
2008 SetCursor( hOldCursor
);
2010 DestroyCursor( hDragCursor
);
2012 else if (moved
&& !DragFullWindows
)
2013 draw_moving_frame( hdc
, &sizingRect
, thickframe
);
2015 ReleaseDC( parent
, hdc
);
2018 XUngrabPointer( display
, CurrentTime
);
2021 XSync( display
, False
);
2022 XUngrabServer( display
);
2023 XSync( display
, False
);
2024 gdi_display
= old_gdi_display
;
2026 wine_tsx11_unlock();
2028 if (HOOK_CallHooksA( WH_CBT
, HCBT_MOVESIZE
, (WPARAM
)hwnd
, (LPARAM
)&sizingRect
)) moved
= FALSE
;
2030 SendMessageA( hwnd
, WM_EXITSIZEMOVE
, 0, 0 );
2031 SendMessageA( hwnd
, WM_SETVISIBLE
, !IsIconic(hwnd
), 0L);
2033 /* window moved or resized */
2036 /* To avoid any deadlocks, all the locks on the windows
2037 structures must be suspended before the SetWindowPos */
2038 iWndsLocks
= WIN_SuspendWndsLock();
2040 /* if the moving/resizing isn't canceled call SetWindowPos
2041 * with the new position or the new size of the window
2043 if (!((msg
.message
== WM_KEYDOWN
) && (msg
.wParam
== VK_ESCAPE
)) )
2045 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
2046 if(!DragFullWindows
)
2047 SetWindowPos( hwnd
, 0, sizingRect
.left
, sizingRect
.top
,
2048 sizingRect
.right
- sizingRect
.left
,
2049 sizingRect
.bottom
- sizingRect
.top
,
2050 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
2053 { /* restore previous size/position */
2055 SetWindowPos( hwnd
, 0, origRect
.left
, origRect
.top
,
2056 origRect
.right
- origRect
.left
,
2057 origRect
.bottom
- origRect
.top
,
2058 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
2061 WIN_RestoreWndsLock(iWndsLocks
);
2066 /* Single click brings up the system menu when iconized */
2070 if(style
& WS_SYSMENU
)
2071 SendMessageA( hwnd
, WM_SYSCOMMAND
,
2072 SC_MOUSEMENU
+ HTSYSMENU
, MAKELONG(pt
.x
,pt
.y
));
2074 else WINPOS_ShowIconTitle( hwnd
, TRUE
);
2079 /***********************************************************************
2080 * ForceWindowRaise (X11DRV.@)
2082 * Raise a window on top of the X stacking order, while preserving
2083 * the correct Windows Z order.
2085 * FIXME: this should go away.
2087 void X11DRV_ForceWindowRaise( HWND hwnd
)
2091 XWindowChanges winChanges
;
2092 Display
*display
= thread_display();
2093 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
2095 if (!wndPtr
) return;
2097 if ((wndPtr
->dwExStyle
& WS_EX_MANAGED
) ||
2098 wndPtr
->parent
!= GetDesktopWindow() ||
2099 IsRectEmpty( &wndPtr
->rectWindow
) ||
2100 !get_whole_window(wndPtr
))
2102 WIN_ReleaseWndPtr( wndPtr
);
2105 WIN_ReleaseWndPtr( wndPtr
);
2107 /* Raise all windows up to wndPtr according to their Z order.
2108 * (it would be easier with sibling-related Below but it doesn't
2109 * work very well with SGI mwm for instance)
2111 winChanges
.stack_mode
= Above
;
2112 if (!(list
= WIN_ListChildren( GetDesktopWindow() ))) return;
2113 while (list
[i
] && list
[i
] != hwnd
) i
++;
2116 for ( ; i
>= 0; i
--)
2118 WND
*ptr
= WIN_FindWndPtr( list
[i
] );
2120 if (!IsRectEmpty( &ptr
->rectWindow
) && get_whole_window(ptr
))
2121 TSXReconfigureWMWindow( display
, get_whole_window(ptr
), 0,
2122 CWStackMode
, &winChanges
);
2123 WIN_ReleaseWndPtr( ptr
);
2126 HeapFree( GetProcessHeap(), 0, list
);