2 * Window position related functions.
4 * Copyright 1993, 1994 Alexandre Julliard
7 static char Copyright
[] = "Copyright Alexandre Julliard, 1993, 1994";
9 #include "sysmetrics.h"
15 /* #define DEBUG_WIN */
16 /* #undef DEBUG_WIN */
19 static HWND hwndActive
= 0; /* Currently active window */
22 /***********************************************************************
23 * GetWindowRect (USER.32)
25 void GetWindowRect( HWND hwnd
, LPRECT rect
)
27 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
30 *rect
= wndPtr
->rectWindow
;
31 if (wndPtr
->dwStyle
& WS_CHILD
)
32 MapWindowPoints( wndPtr
->hwndParent
, 0, (POINT
*)rect
, 2 );
36 /***********************************************************************
37 * GetClientRect (USER.33)
39 void GetClientRect( HWND hwnd
, LPRECT rect
)
41 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
43 rect
->left
= rect
->top
= rect
->right
= rect
->bottom
= 0;
46 rect
->right
= wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
;
47 rect
->bottom
= wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
;
52 /*******************************************************************
53 * ClientToScreen (USER.28)
55 void ClientToScreen( HWND hwnd
, LPPOINT lppnt
)
57 MapWindowPoints( hwnd
, 0, lppnt
, 1 );
61 /*******************************************************************
62 * ScreenToClient (USER.29)
64 void ScreenToClient( HWND hwnd
, LPPOINT lppnt
)
66 MapWindowPoints( 0, hwnd
, lppnt
, 1 );
70 /*******************************************************************
71 * WindowFromPoint (USER.30)
73 HWND
WindowFromPoint( POINT pt
)
76 HWND hwnd
= GetDesktopWindow();
80 /* If point is in window, and window is visible, */
81 /* not disabled and not transparent, then explore */
82 /* its children. Otherwise, go to the next window. */
84 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
85 if ((pt
.x
>= wndPtr
->rectWindow
.left
) &&
86 (pt
.x
< wndPtr
->rectWindow
.right
) &&
87 (pt
.y
>= wndPtr
->rectWindow
.top
) &&
88 (pt
.y
< wndPtr
->rectWindow
.bottom
) &&
89 !(wndPtr
->dwStyle
& WS_DISABLED
) &&
90 (wndPtr
->dwStyle
& WS_VISIBLE
) &&
91 !(wndPtr
->dwExStyle
& WS_EX_TRANSPARENT
))
94 /* If window is minimized, ignore its children */
95 if (wndPtr
->dwStyle
& WS_MINIMIZE
) break;
96 pt
.x
-= wndPtr
->rectClient
.left
;
97 pt
.y
-= wndPtr
->rectClient
.top
;
98 hwnd
= wndPtr
->hwndChild
;
100 else hwnd
= wndPtr
->hwndNext
;
105 /*******************************************************************
106 * ChildWindowFromPoint (USER.191)
108 HWND
ChildWindowFromPoint( HWND hwndParent
, POINT pt
)
113 GetWindowRect( hwndParent
, &rect
);
114 if (!PtInRect( &rect
, pt
)) return 0;
115 hwnd
= GetTopWindow( hwndParent
);
118 GetWindowRect( hwnd
, &rect
);
119 if (PtInRect( &rect
, pt
)) return hwnd
;
120 hwnd
= GetWindow( hwnd
, GW_HWNDNEXT
);
126 /*******************************************************************
127 * MapWindowPoints (USER.258)
129 void MapWindowPoints( HWND hwndFrom
, HWND hwndTo
, LPPOINT lppt
, WORD count
)
133 POINT origin
= { 0, 0 };
136 /* Translate source window origin to screen coords */
139 wndPtr
= WIN_FindWndPtr( hwndFrom
);
140 origin
.x
+= wndPtr
->rectClient
.left
;
141 origin
.y
+= wndPtr
->rectClient
.top
;
142 hwndFrom
= (wndPtr
->dwStyle
& WS_CHILD
) ? wndPtr
->hwndParent
: 0;
145 /* Translate origin to destination window coords */
148 wndPtr
= WIN_FindWndPtr( hwndTo
);
149 origin
.x
-= wndPtr
->rectClient
.left
;
150 origin
.y
-= wndPtr
->rectClient
.top
;
151 hwndTo
= (wndPtr
->dwStyle
& WS_CHILD
) ? wndPtr
->hwndParent
: 0;
154 /* Translate points */
155 for (i
= 0, curpt
= lppt
; i
< count
; i
++, curpt
++)
157 curpt
->x
+= origin
.x
;
158 curpt
->y
+= origin
.y
;
163 /***********************************************************************
166 BOOL
IsIconic(HWND hWnd
)
168 WND
* wndPtr
= WIN_FindWndPtr(hWnd
);
169 if (wndPtr
== NULL
) return FALSE
;
170 return (wndPtr
->dwStyle
& WS_MINIMIZE
) != 0;
174 /***********************************************************************
175 * IsZoomed (USER.272)
177 BOOL
IsZoomed(HWND hWnd
)
179 WND
* wndPtr
= WIN_FindWndPtr(hWnd
);
180 if (wndPtr
== NULL
) return FALSE
;
181 return (wndPtr
->dwStyle
& WS_MAXIMIZE
) != 0;
185 /*******************************************************************
186 * GetActiveWindow (USER.60)
188 HWND
GetActiveWindow()
193 /*******************************************************************
194 * SetActiveWindow (USER.59)
196 HWND
SetActiveWindow( HWND hwnd
)
198 HWND prev
= hwndActive
;
199 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
200 if (!wndPtr
|| (wndPtr
->dwStyle
& WS_CHILD
)) return 0;
201 SetWindowPos( hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
);
206 /***********************************************************************
207 * BringWindowToTop (USER.45)
209 BOOL
BringWindowToTop( HWND hwnd
)
211 return SetWindowPos( hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
);
215 /***********************************************************************
216 * MoveWindow (USER.56)
218 BOOL
MoveWindow( HWND hwnd
, short x
, short y
, short cx
, short cy
, BOOL repaint
)
220 int flags
= SWP_NOZORDER
| SWP_NOACTIVATE
;
221 if (!repaint
) flags
|= SWP_NOREDRAW
;
222 dprintf_win(stddeb
, "MoveWindow: %d %d,%d %dx%d %d\n",
223 hwnd
, x
, y
, cx
, cy
, repaint
);
224 return SetWindowPos( hwnd
, 0, x
, y
, cx
, cy
, flags
);
228 /***********************************************************************
229 * ShowWindow (USER.42)
231 BOOL
ShowWindow( HWND hwnd
, int cmd
)
233 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
238 if (!wndPtr
) return FALSE
;
240 dprintf_win(stddeb
,"ShowWindow: hwnd=%04X, cmd=%d\n", hwnd
, cmd
);
243 * wasVisible is true if user has not made window invisible
244 * wasIconic is true if the window is not iconified
246 wasVisible
= (wndPtr
->dwStyle
& WS_VISIBLE
) != 0;
252 * if the window wasn't visible to begin with -- just return
255 return FALSE
; /* Nothing to do */
256 swpflags
|= SWP_HIDEWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
|
257 SWP_NOACTIVATE
| SWP_NOZORDER
;
261 case SW_SHOWMINNOACTIVE
:
262 case SW_SHOWMINIMIZED
:
264 wndPtr
->dwStyle
|= WS_MINIMIZE
;
265 swpflags
|= SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
|
266 SWP_NOACTIVATE
| SWP_NOZORDER
;
268 /* store the size and position of the window, so we can
269 * deiconify it to the same size and position
271 wndPtr
->rectNormal
= wndPtr
->rectWindow
;
272 wndPtr
->ptIconPos
.x
= wndPtr
->rectWindow
.left
;
273 wndPtr
->ptIconPos
.y
= wndPtr
->rectWindow
.top
;
274 /* move the window to icon size and position and
275 * tell it that it is going to have to be painted
277 MoveWindow(hwnd
, wndPtr
->ptIconPos
.x
, wndPtr
->ptIconPos
.y
,
278 SYSMETRICS_CXICON
, SYSMETRICS_CYICON
, FALSE
);
279 RedrawWindow( hwnd
, NULL
, 0, RDW_FRAME
| RDW_ERASENOW
);
283 case SW_SHOWMAXIMIZED
: /* same as SW_MAXIMIZE: */
285 swpflags
|= SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
289 case SW_SHOWNORMAL
: /* same as SW_NORMAL: */
290 case SW_SHOWNOACTIVATE
:
292 wasIconic
= IsIconic(hwnd
);
293 wndPtr
->dwStyle
&= ~WS_MINIMIZE
;
294 wndPtr
->dwStyle
&= ~WS_MAXIMIZE
;
295 swpflags
|= SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
296 if (cmd
== SW_SHOWNOACTIVATE
)
298 swpflags
|= SWP_NOZORDER
;
299 if (GetActiveWindow()) swpflags
|= SWP_NOACTIVATE
;
302 MoveWindow(hwnd
, wndPtr
->rectNormal
.left
,
303 wndPtr
->rectNormal
.top
,
304 wndPtr
->rectNormal
.right
- wndPtr
->rectNormal
.left
,
305 wndPtr
->rectNormal
.bottom
- wndPtr
->rectNormal
.top
,
311 SendMessage( hwnd
, WM_SHOWWINDOW
, (cmd
!= SW_HIDE
), 0 );
312 SetWindowPos( hwnd
, 0, 0, 0, 0, 0, swpflags
);
314 /* Send WM_SIZE and WM_MOVE messages if not already done */
315 if (!(wndPtr
->flags
& WIN_GOT_SIZEMSG
))
317 int wParam
= SIZE_RESTORED
;
318 if (wndPtr
->dwStyle
& WS_MAXIMIZE
) wParam
= SIZE_MAXIMIZED
;
319 else if (wndPtr
->dwStyle
& WS_MINIMIZE
) wParam
= SIZE_MINIMIZED
;
320 wndPtr
->flags
|= WIN_GOT_SIZEMSG
;
321 SendMessage( hwnd
, WM_SIZE
, wParam
,
322 MAKELONG(wndPtr
->rectClient
.right
-wndPtr
->rectClient
.left
,
323 wndPtr
->rectClient
.bottom
-wndPtr
->rectClient
.top
));
324 SendMessage( hwnd
, WM_MOVE
, 0,
325 MAKELONG(wndPtr
->rectClient
.left
, wndPtr
->rectClient
.top
) );
332 /***********************************************************************
333 * GetInternalWindowPos (USER.460)
335 WORD
GetInternalWindowPos( HWND hwnd
, LPRECT rectWnd
, LPPOINT ptIcon
)
337 WINDOWPLACEMENT wndpl
;
338 if (!GetWindowPlacement( hwnd
, &wndpl
)) return 0;
339 if (rectWnd
) *rectWnd
= wndpl
.rcNormalPosition
;
340 if (ptIcon
) *ptIcon
= wndpl
.ptMinPosition
;
341 return wndpl
.showCmd
;
345 /***********************************************************************
346 * SetInternalWindowPos (USER.461)
348 void SetInternalWindowPos( HWND hwnd
, WORD showCmd
, LPRECT rect
, LPPOINT pt
)
350 WINDOWPLACEMENT wndpl
;
351 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
353 wndpl
.length
= sizeof(wndpl
);
354 wndpl
.flags
= (pt
!= NULL
) ? WPF_SETMINPOSITION
: 0;
355 wndpl
.showCmd
= showCmd
;
356 if (pt
) wndpl
.ptMinPosition
= *pt
;
357 wndpl
.rcNormalPosition
= (rect
!= NULL
) ? *rect
: wndPtr
->rectNormal
;
358 wndpl
.ptMaxPosition
= wndPtr
->ptMaxPos
;
359 SetWindowPlacement( hwnd
, &wndpl
);
363 /***********************************************************************
364 * GetWindowPlacement (USER.370)
366 BOOL
GetWindowPlacement( HWND hwnd
, WINDOWPLACEMENT
*wndpl
)
368 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
369 if (!wndPtr
) return FALSE
;
371 wndpl
->length
= sizeof(*wndpl
);
373 wndpl
->showCmd
= IsZoomed(hwnd
) ? SW_SHOWMAXIMIZED
:
374 (IsIconic(hwnd
) ? SW_SHOWMINIMIZED
: SW_SHOWNORMAL
);
375 wndpl
->ptMinPosition
= wndPtr
->ptIconPos
;
376 wndpl
->ptMaxPosition
= wndPtr
->ptMaxPos
;
377 wndpl
->rcNormalPosition
= wndPtr
->rectNormal
;
382 /***********************************************************************
383 * SetWindowPlacement (USER.371)
385 BOOL
SetWindowPlacement( HWND hwnd
, WINDOWPLACEMENT
*wndpl
)
387 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
388 if (!wndPtr
) return FALSE
;
390 if (wndpl
->flags
& WPF_SETMINPOSITION
)
391 wndPtr
->ptIconPos
= wndpl
->ptMinPosition
;
392 if ((wndpl
->flags
& WPF_RESTORETOMAXIMIZED
) &&
393 (wndpl
->showCmd
== SW_SHOWMINIMIZED
)) wndPtr
->flags
|= WIN_RESTORE_MAX
;
394 wndPtr
->ptMaxPos
= wndpl
->ptMaxPosition
;
395 wndPtr
->rectNormal
= wndpl
->rcNormalPosition
;
396 ShowWindow( hwnd
, wndpl
->showCmd
);
401 /*******************************************************************
402 * WINPOS_NextWindowFromPoint
404 * Looks for next enabled window that is
405 * a) sibling of hwnd, later in Z-order and encloses pt, or
408 HWND
WINPOS_NextWindowFromPoint( HWND hwnd
, POINT pt
)
410 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
412 if (!wndPtr
->hwndParent
) return hwnd
; /* desktop window */
413 ScreenToClient( wndPtr
->hwndParent
, &pt
); /* make pt relative to parent */
416 if (!wndPtr
->hwndNext
) break; /* No more children */
417 hwnd
= wndPtr
->hwndNext
;
418 wndPtr
= WIN_FindWndPtr( hwnd
);
419 if ((wndPtr
->dwStyle
& WS_VISIBLE
) &&
420 !(wndPtr
->dwStyle
& WS_DISABLED
) &&
421 PtInRect( &wndPtr
->rectWindow
, pt
)) return hwnd
;
423 return wndPtr
->hwndParent
;
427 /*******************************************************************
428 * WINPOS_GetMinMaxInfo
430 * Send a WM_GETMINMAXINFO to the window.
432 void WINPOS_GetMinMaxInfo( HWND hwnd
, POINT
*maxSize
, POINT
*maxPos
,
433 POINT
*minTrack
, POINT
*maxTrack
)
436 MINMAXINFO MinMax
, *pMinMax
;
437 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
439 MinMax
.ptMaxSize
.x
= SYSMETRICS_CXSCREEN
;
440 MinMax
.ptMaxSize
.y
= SYSMETRICS_CYSCREEN
;
441 MinMax
.ptMaxPosition
= wndPtr
->ptMaxPos
;
442 MinMax
.ptMinTrackSize
.x
= SYSMETRICS_CXMINTRACK
;
443 MinMax
.ptMinTrackSize
.y
= SYSMETRICS_CYMINTRACK
;
444 MinMax
.ptMaxTrackSize
.x
= SYSMETRICS_CXSCREEN
;
445 MinMax
.ptMaxTrackSize
.y
= SYSMETRICS_CYSCREEN
;
447 minmaxHandle
= USER_HEAP_ALLOC( LMEM_MOVEABLE
, sizeof(MINMAXINFO
) );
450 pMinMax
= (MINMAXINFO
*) USER_HEAP_ADDR( minmaxHandle
);
451 memcpy( pMinMax
, &MinMax
, sizeof(MinMax
) );
452 SendMessage( hwnd
, WM_GETMINMAXINFO
, 0, (LONG
)pMinMax
);
454 else pMinMax
= &MinMax
;
456 /* Some sanity checks */
458 pMinMax
->ptMaxTrackSize
.x
= max( pMinMax
->ptMaxTrackSize
.x
,
459 pMinMax
->ptMinTrackSize
.x
);
460 pMinMax
->ptMaxTrackSize
.y
= max( pMinMax
->ptMaxTrackSize
.y
,
461 pMinMax
->ptMinTrackSize
.y
);
463 if (maxSize
) *maxSize
= pMinMax
->ptMaxSize
;
464 if (maxPos
) *maxPos
= pMinMax
->ptMaxPosition
;
465 if (minTrack
) *minTrack
= pMinMax
->ptMinTrackSize
;
466 if (maxTrack
) *maxTrack
= pMinMax
->ptMaxTrackSize
;
467 if (minmaxHandle
) USER_HEAP_FREE( minmaxHandle
);
471 /*******************************************************************
472 * WINPOS_ChangeActiveWindow
474 * Change the active window and send the corresponding messages.
476 HWND
WINPOS_ChangeActiveWindow( HWND hwnd
, BOOL mouseMsg
)
478 HWND prevActive
= hwndActive
;
479 if (hwnd
== hwndActive
) return 0;
482 if (!SendMessage( hwndActive
, WM_NCACTIVATE
, FALSE
, 0 )) return 0;
483 SendMessage( hwndActive
, WM_ACTIVATE
, WA_INACTIVE
,
484 MAKELONG( IsIconic(hwndActive
), hwnd
) );
485 /* Send WM_ACTIVATEAPP here */
491 WND
*wndPtr
= WIN_FindWndPtr( hwndActive
);
492 wndPtr
->hwndPrevActive
= prevActive
;
494 /* Send WM_ACTIVATEAPP here */
495 SendMessage( hwnd
, WM_NCACTIVATE
, TRUE
, 0 );
496 SendMessage( hwnd
, WM_ACTIVATE
, mouseMsg
? WA_CLICKACTIVE
: WA_ACTIVE
,
497 MAKELONG( IsIconic(hwnd
), prevActive
) );
503 /***********************************************************************
504 * WINPOS_SendNCCalcSize
506 * Send a WM_NCCALCSIZE message to a window.
507 * All parameters are read-only except newClientRect.
508 * oldWindowRect, oldClientRect and winpos must be non-NULL only
509 * when calcValidRect is TRUE.
511 LONG
WINPOS_SendNCCalcSize( HWND hwnd
, BOOL calcValidRect
, RECT
*newWindowRect
,
512 RECT
*oldWindowRect
, RECT
*oldClientRect
,
513 WINDOWPOS
*winpos
, RECT
*newClientRect
)
515 NCCALCSIZE_PARAMS
*params
;
519 if (!(hparams
= USER_HEAP_ALLOC( GMEM_MOVEABLE
, sizeof(*params
) )))
521 params
= (NCCALCSIZE_PARAMS
*) USER_HEAP_ADDR( hparams
);
522 params
->rgrc
[0] = *newWindowRect
;
525 params
->rgrc
[1] = *oldWindowRect
;
526 params
->rgrc
[2] = *oldClientRect
;
527 params
->lppos
= winpos
;
529 result
= SendMessage( hwnd
, WM_NCCALCSIZE
, calcValidRect
, (LONG
)params
);
530 *newClientRect
= params
->rgrc
[0];
531 USER_HEAP_FREE( hparams
);
536 /***********************************************************************
537 * WINPOS_HandleWindowPosChanging
539 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
541 LONG
WINPOS_HandleWindowPosChanging( WINDOWPOS
*winpos
)
544 WND
*wndPtr
= WIN_FindWndPtr( winpos
->hwnd
);
545 if (!wndPtr
|| (winpos
->flags
& SWP_NOSIZE
)) return 0;
546 if ((wndPtr
->dwStyle
& WS_THICKFRAME
) ||
547 (wndPtr
->dwStyle
& (WS_POPUP
| WS_CHILD
) == 0))
549 WINPOS_GetMinMaxInfo( winpos
->hwnd
, &maxSize
, NULL
, NULL
, NULL
);
550 winpos
->cx
= min( winpos
->cx
, maxSize
.x
);
551 winpos
->cy
= min( winpos
->cy
, maxSize
.y
);
557 /***********************************************************************
558 * WINPOS_MoveWindowZOrder
560 * Move a window in Z order, invalidating everything that needs it.
561 * Only necessary for windows without associated X window.
563 static void WINPOS_MoveWindowZOrder( HWND hwnd
, HWND hwndAfter
, BOOL erase
)
567 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
569 /* We have two possible cases:
570 * - The window is moving up: we have to invalidate all areas
571 * of the window that were covered by other windows
572 * - The window is moving down: we have to invalidate areas
573 * of other windows covered by this one.
576 if (hwndAfter
== HWND_TOP
)
580 else if (hwndAfter
== HWND_BOTTOM
)
582 if (!wndPtr
->hwndNext
) return; /* Already at the bottom */
587 if (wndPtr
->hwndNext
== hwndAfter
) return; /* Already placed right */
589 /* Determine which window we encounter first in Z-order */
590 hwndCur
= GetWindow( wndPtr
->hwndParent
, GW_CHILD
);
591 while ((hwndCur
!= hwnd
) && (hwndCur
!= hwndAfter
))
592 hwndCur
= GetWindow( hwndCur
, GW_HWNDNEXT
);
593 movingUp
= (hwndCur
== hwndAfter
);
598 HWND hwndPrevAfter
= wndPtr
->hwndNext
;
599 WIN_UnlinkWindow( hwnd
);
600 WIN_LinkWindow( hwnd
, hwndAfter
);
601 hwndCur
= wndPtr
->hwndNext
;
602 while (hwndCur
!= hwndPrevAfter
)
604 WND
*curPtr
= WIN_FindWndPtr( hwndCur
);
605 RECT rect
= curPtr
->rectWindow
;
606 OffsetRect( &rect
, -wndPtr
->rectClient
.left
,
607 -wndPtr
->rectClient
.top
);
608 RedrawWindow( hwnd
, &rect
, 0, RDW_INVALIDATE
| RDW_ALLCHILDREN
|
609 RDW_FRAME
| (erase
? RDW_ERASENOW
: RDW_ERASE
) );
610 hwndCur
= curPtr
->hwndNext
;
613 else /* Moving down */
615 hwndCur
= wndPtr
->hwndNext
;
616 WIN_UnlinkWindow( hwnd
);
617 WIN_LinkWindow( hwnd
, hwndAfter
);
618 while (hwndCur
!= hwnd
)
620 WND
*curPtr
= WIN_FindWndPtr( hwndCur
);
621 RECT rect
= wndPtr
->rectWindow
;
622 OffsetRect( &rect
, -curPtr
->rectClient
.left
,
623 -curPtr
->rectClient
.top
);
624 RedrawWindow( hwndCur
, &rect
, 0, RDW_INVALIDATE
| RDW_ALLCHILDREN
|
625 RDW_FRAME
| (erase
? RDW_ERASENOW
: RDW_ERASE
) );
626 hwndCur
= curPtr
->hwndNext
;
632 /***********************************************************************
633 * WINPOS_InternalSetWindowPos
635 * Helper function for SetWindowPos.
637 static BOOL
WINPOS_InternalSetWindowPos( WINDOWPOS
*winpos
)
641 RECT newWindowRect
, newClientRect
;
644 XWindowChanges winChanges
;
646 /* Send WM_WINDOWPOSCHANGING message */
648 if (!(winpos
->flags
& SWP_NOSENDCHANGING
))
649 SendMessage( winpos
->hwnd
, WM_WINDOWPOSCHANGING
, 0, (LONG
)winpos
);
651 /* Check window handle */
653 if (winpos
->hwnd
== GetDesktopWindow()) return FALSE
;
654 if (!(wndPtr
= WIN_FindWndPtr( winpos
->hwnd
))) return FALSE
;
656 /* Check dimensions */
658 if (winpos
->cx
<= 0) winpos
->cx
= 1;
659 if (winpos
->cy
<= 0) winpos
->cy
= 1;
663 flags
= winpos
->flags
;
664 if (winpos
->hwnd
== hwndActive
) flags
|= SWP_NOACTIVATE
; /*Already active*/
666 /* Check hwndAfter */
668 hwndAfter
= winpos
->hwndInsertAfter
;
669 if (!(flags
& (SWP_NOZORDER
| SWP_NOACTIVATE
)))
671 /* Ignore TOPMOST flags when activating a window */
672 /* _and_ moving it in Z order. */
673 if ((hwndAfter
== HWND_TOPMOST
) || (hwndAfter
== HWND_NOTOPMOST
))
674 hwndAfter
= HWND_TOP
;
676 /* TOPMOST not supported yet */
677 if ((hwndAfter
== HWND_TOPMOST
) || (hwndAfter
== HWND_NOTOPMOST
))
678 hwndAfter
= HWND_TOP
;
679 /* hwndAfter must be a sibling of the window */
680 if ((hwndAfter
!= HWND_TOP
) && (hwndAfter
!= HWND_BOTTOM
) &&
681 (GetParent(winpos
->hwnd
) != GetParent(hwndAfter
))) return FALSE
;
683 /* Calculate new position and size */
685 newWindowRect
= wndPtr
->rectWindow
;
686 newClientRect
= wndPtr
->rectClient
;
688 if (!(flags
& SWP_NOSIZE
))
690 newWindowRect
.right
= newWindowRect
.left
+ winpos
->cx
;
691 newWindowRect
.bottom
= newWindowRect
.top
+ winpos
->cy
;
692 winChanges
.width
= winpos
->cx
;
693 winChanges
.height
= winpos
->cy
;
694 changeMask
|= CWWidth
| CWHeight
;
696 if (!(flags
& SWP_NOMOVE
))
698 newWindowRect
.left
= winpos
->x
;
699 newWindowRect
.top
= winpos
->y
;
700 newWindowRect
.right
+= winpos
->x
- wndPtr
->rectWindow
.left
;
701 newWindowRect
.bottom
+= winpos
->y
- wndPtr
->rectWindow
.top
;
702 if (wndPtr
->dwStyle
& WS_CHILD
)
704 WND
*parentPtr
= WIN_FindWndPtr(wndPtr
->hwndParent
);
705 winChanges
.x
= winpos
->x
+ parentPtr
->rectClient
.left
706 - parentPtr
->rectWindow
.left
;
707 winChanges
.y
= winpos
->y
+ parentPtr
->rectClient
.top
708 - parentPtr
->rectWindow
.top
;
712 winChanges
.x
= winpos
->x
;
713 winChanges
.y
= winpos
->y
;
715 changeMask
|= CWX
| CWY
;
718 /* Reposition window in Z order */
720 if (!(flags
& SWP_NOZORDER
))
724 WIN_UnlinkWindow( winpos
->hwnd
);
725 WIN_LinkWindow( winpos
->hwnd
, hwndAfter
);
726 if (hwndAfter
== HWND_TOP
) winChanges
.stack_mode
= Above
;
727 else winChanges
.stack_mode
= Below
;
728 if ((hwndAfter
!= HWND_TOP
) && (hwndAfter
!= HWND_BOTTOM
))
730 WND
* insertPtr
= WIN_FindWndPtr( hwndAfter
);
731 winChanges
.sibling
= insertPtr
->window
;
732 changeMask
|= CWSibling
;
734 changeMask
|= CWStackMode
;
736 else WINPOS_MoveWindowZOrder( winpos
->hwnd
, hwndAfter
,
737 !(flags
& SWP_DEFERERASE
) );
740 /* Send WM_NCCALCSIZE message to get new client area */
742 result
= WINPOS_SendNCCalcSize( winpos
->hwnd
, TRUE
, &newWindowRect
,
743 &wndPtr
->rectWindow
, &wndPtr
->rectClient
,
744 winpos
, &newClientRect
);
745 /* .... Should handle result here */
747 /* Perform the moving and resizing */
751 if (changeMask
) XConfigureWindow( display
, wndPtr
->window
,
752 changeMask
, &winChanges
);
753 wndPtr
->rectWindow
= newWindowRect
;
754 wndPtr
->rectClient
= newClientRect
;
758 RECT oldWindowRect
= wndPtr
->rectWindow
;
760 wndPtr
->rectWindow
= newWindowRect
;
761 wndPtr
->rectClient
= newClientRect
;
765 HRGN hrgn1
= CreateRectRgnIndirect( &oldWindowRect
);
766 HRGN hrgn2
= CreateRectRgnIndirect( &wndPtr
->rectWindow
);
767 HRGN hrgn3
= CreateRectRgn( 0, 0, 0, 0 );
768 CombineRgn( hrgn3
, hrgn1
, hrgn2
, RGN_DIFF
);
769 RedrawWindow( wndPtr
->hwndParent
, NULL
, hrgn3
,
770 RDW_INVALIDATE
| RDW_ALLCHILDREN
| RDW_ERASENOW
);
771 if ((oldWindowRect
.left
!= wndPtr
->rectWindow
.left
) ||
772 (oldWindowRect
.top
!= wndPtr
->rectWindow
.top
))
774 RedrawWindow( winpos
->hwnd
, NULL
, 0, RDW_INVALIDATE
|
775 RDW_FRAME
| RDW_ALLCHILDREN
| RDW_ERASENOW
);
777 DeleteObject( hrgn1
);
778 DeleteObject( hrgn2
);
779 DeleteObject( hrgn3
);
783 if (flags
& SWP_SHOWWINDOW
)
785 wndPtr
->dwStyle
|= WS_VISIBLE
;
788 XMapWindow( display
, wndPtr
->window
);
790 if (flags
& SWP_NOREDRAW
) /* Validate the whole window */
791 RedrawWindow( winpos
->hwnd
, NULL
, 0, RDW_VALIDATE
);
794 else if (flags
& SWP_HIDEWINDOW
)
796 wndPtr
->dwStyle
&= ~WS_VISIBLE
;
799 XUnmapWindow( display
, wndPtr
->window
);
803 RedrawWindow( wndPtr
->hwndParent
, &wndPtr
->rectWindow
, 0,
804 RDW_INVALIDATE
| RDW_FRAME
|
805 RDW_ALLCHILDREN
| RDW_ERASENOW
);
807 if ((winpos
->hwnd
== GetFocus()) || IsChild(winpos
->hwnd
, GetFocus()))
808 SetFocus( GetParent(winpos
->hwnd
) ); /* Revert focus to parent */
809 if (winpos
->hwnd
== hwndActive
)
811 /* Activate previously active window if possible */
812 HWND newActive
= wndPtr
->hwndPrevActive
;
813 if (!IsWindow(newActive
) || (newActive
== winpos
->hwnd
))
815 newActive
= GetTopWindow(GetDesktopWindow());
816 if (newActive
== winpos
->hwnd
) newActive
= wndPtr
->hwndNext
;
818 WINPOS_ChangeActiveWindow( newActive
, FALSE
);
822 /* Activate the window */
824 if (!(flags
& SWP_NOACTIVATE
))
826 if (!(wndPtr
->dwStyle
& WS_CHILD
))
827 WINPOS_ChangeActiveWindow( winpos
->hwnd
, FALSE
);
830 /* Send WM_NCPAINT message if needed */
832 if (flags
& SWP_SHOWWINDOW
)
834 /* Repaint the window frame and background */
835 RedrawWindow( winpos
->hwnd
, NULL
, 0,
836 RDW_INVALIDATE
| RDW_FRAME
| RDW_ERASENOW
);
840 if ((flags
& SWP_FRAMECHANGED
) ||
841 (!(flags
& SWP_NOSIZE
)) ||
842 (!(flags
& SWP_NOMOVE
)) ||
843 (!(flags
& SWP_NOACTIVATE
)) ||
844 (!(flags
& SWP_NOZORDER
)))
845 SendMessage( winpos
->hwnd
, WM_NCPAINT
, 1, 0L );
848 /* And last, send the WM_WINDOWPOSCHANGED message */
850 SendMessage( winpos
->hwnd
, WM_WINDOWPOSCHANGED
, 0, (LONG
)winpos
);
855 /***********************************************************************
856 * BeginDeferWindowPos (USER.259)
858 HDWP
BeginDeferWindowPos( INT count
)
863 if (count
<= 0) return 0;
864 handle
= USER_HEAP_ALLOC( GMEM_MOVEABLE
,
865 sizeof(DWP
) + (count
-1)*sizeof(WINDOWPOS
) );
866 if (!handle
) return 0;
867 pDWP
= (DWP
*) USER_HEAP_ADDR( handle
);
868 pDWP
->actualCount
= 0;
869 pDWP
->suggestedCount
= count
;
871 pDWP
->wMagic
= DWP_MAGIC
;
872 pDWP
->hwndParent
= 0;
877 /***********************************************************************
878 * DeferWindowPos (USER.260)
880 HDWP
DeferWindowPos( HDWP hdwp
, HWND hwnd
, HWND hwndAfter
, INT x
, INT y
,
881 INT cx
, INT cy
, WORD flags
)
887 pDWP
= (DWP
*) USER_HEAP_ADDR( hdwp
);
890 /* All the windows of a DeferWindowPos() must have the same parent */
892 if (pDWP
->actualCount
== 0) pDWP
->hwndParent
= GetParent( hwnd
);
893 else if (GetParent( hwnd
) != pDWP
->hwndParent
)
895 USER_HEAP_FREE( hdwp
);
899 for (i
= 0; i
< pDWP
->actualCount
; i
++)
901 if (pDWP
->winPos
[i
].hwnd
== hwnd
)
903 /* Merge with the other changes */
904 if (!(flags
& SWP_NOZORDER
))
906 pDWP
->winPos
[i
].hwndInsertAfter
= hwndAfter
;
908 if (!(flags
& SWP_NOMOVE
))
910 pDWP
->winPos
[i
].x
= x
;
911 pDWP
->winPos
[i
].y
= y
;
913 if (!(flags
& SWP_NOSIZE
))
915 pDWP
->winPos
[i
].cx
= cx
;
916 pDWP
->winPos
[i
].cy
= cy
;
918 pDWP
->winPos
[i
].flags
&= flags
& (SWP_NOSIZE
| SWP_NOMOVE
|
919 SWP_NOZORDER
| SWP_NOREDRAW
|
920 SWP_NOACTIVATE
| SWP_NOCOPYBITS
|
922 pDWP
->winPos
[i
].flags
|= flags
& (SWP_SHOWWINDOW
| SWP_HIDEWINDOW
|
927 if (pDWP
->actualCount
>= pDWP
->suggestedCount
)
929 newhdwp
= USER_HEAP_REALLOC( hdwp
,
930 sizeof(DWP
) + pDWP
->suggestedCount
*sizeof(WINDOWPOS
), 0);
931 if (!newhdwp
) return 0;
932 pDWP
= (DWP
*) USER_HEAP_ADDR( newhdwp
);
933 pDWP
->suggestedCount
++;
935 pDWP
->winPos
[pDWP
->actualCount
].hwnd
= hwnd
;
936 pDWP
->winPos
[pDWP
->actualCount
].hwndInsertAfter
= hwndAfter
;
937 pDWP
->winPos
[pDWP
->actualCount
].x
= x
;
938 pDWP
->winPos
[pDWP
->actualCount
].y
= y
;
939 pDWP
->winPos
[pDWP
->actualCount
].cx
= cx
;
940 pDWP
->winPos
[pDWP
->actualCount
].cy
= cy
;
941 pDWP
->winPos
[pDWP
->actualCount
].flags
= flags
;
947 /***********************************************************************
948 * EndDeferWindowPos (USER.261)
950 BOOL
EndDeferWindowPos( HDWP hdwp
)
956 pDWP
= (DWP
*) USER_HEAP_ADDR( hdwp
);
957 if (!pDWP
) return FALSE
;
958 for (i
= 0; i
< pDWP
->actualCount
; i
++)
960 if (!(res
= WINPOS_InternalSetWindowPos( &pDWP
->winPos
[i
] ))) break;
962 USER_HEAP_FREE( hdwp
);
967 /***********************************************************************
968 * SetWindowPos (USER.232)
970 BOOL
SetWindowPos( HWND hwnd
, HWND hwndInsertAfter
, INT x
, INT y
,
971 INT cx
, INT cy
, WORD flags
)
975 dprintf_win(stddeb
, "SetWindowPos: %04X %d %d,%d %dx%d 0x%x\n",
976 hwnd
, hwndInsertAfter
, x
, y
, cx
, cy
, flags
);
977 if (!(hdwp
= BeginDeferWindowPos( 1 ))) return FALSE
;
978 if (!(hdwp
= DeferWindowPos( hdwp
, hwnd
, hwndInsertAfter
,
979 x
, y
, cx
, cy
, flags
))) return FALSE
;
980 return EndDeferWindowPos( hdwp
);
983 /***********************************************************************
984 * TileChildWindows (USER.199)
986 void TileChildWindows( HWND parent
, WORD action
)
988 printf("STUB TileChildWindows(%04X, %d)\n", parent
, action
);
991 /***********************************************************************
992 * CascageChildWindows (USER.198)
994 void CascadeChildWindows( HWND parent
, WORD action
)
996 printf("STUB CascadeChildWindows(%04X, %d)\n", parent
, action
);
999 /***********************************************************************
1000 * ArrangeIconicWindows (USER.170)
1002 WORD
ArrangeIconicWindows( HWND parent
)
1004 printf("STUB ArrangeIconicWindows(%04X)\n", parent
);