2 * Window position related functions.
4 * Copyright 1993, 1994, 1995 Alexandre Julliard
5 * 1995,1996 Alex Korobka
8 #include "sysmetrics.h"
17 #include "stackframe.h"
19 #include "nonclient.h"
21 /* #define DEBUG_WIN */
24 #define SWP_NOPOSCHANGE (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE)
26 /* ----- external functions ----- */
28 extern void FOCUS_SwitchFocus( HWND , HWND );
29 extern HRGN DCE_GetVisRgn( HWND, WORD );
30 extern HWND CARET_GetHwnd();
32 /* ----- internal variables ----- */
34 static HWND hwndActive = 0; /* Currently active window */
35 static HWND hwndPrevActive = 0; /* Previously active window */
37 /***********************************************************************
40 * Find a suitable place for an iconic window.
41 * The new position is stored into wndPtr->ptIconPos.
43 void WINPOS_FindIconPos( HWND hwnd )
46 short x, y, xspacing, yspacing;
47 WND * wndPtr = WIN_FindWndPtr( hwnd );
49 if (!wndPtr || !wndPtr->parent) return;
50 GetClientRect16( wndPtr->parent->hwndSelf, &rectParent );
51 if ((wndPtr->ptIconPos.x >= rectParent.left) &&
52 (wndPtr->ptIconPos.x + SYSMETRICS_CXICON < rectParent.right) &&
53 (wndPtr->ptIconPos.y >= rectParent.top) &&
54 (wndPtr->ptIconPos.y + SYSMETRICS_CYICON < rectParent.bottom))
55 return; /* The icon already has a suitable position */
57 xspacing = yspacing = 70; /* FIXME: This should come from WIN.INI */
58 y = rectParent.bottom;
61 for (x = rectParent.left; x<=rectParent.right-xspacing; x += xspacing)
63 /* Check if another icon already occupies this spot */
64 WND *childPtr = wndPtr->parent->child;
67 if ((childPtr->dwStyle & WS_MINIMIZE) && (childPtr != wndPtr))
69 if ((childPtr->rectWindow.left < x + xspacing) &&
70 (childPtr->rectWindow.right >= x) &&
71 (childPtr->rectWindow.top <= y) &&
72 (childPtr->rectWindow.bottom > y - yspacing))
73 break; /* There's a window in there */
75 childPtr = childPtr->next;
79 /* No window was found, so it's OK for us */
80 wndPtr->ptIconPos.x = x + (xspacing - SYSMETRICS_CXICON) / 2;
81 wndPtr->ptIconPos.y = y - (yspacing + SYSMETRICS_CYICON) / 2;
90 /***********************************************************************
91 * ArrangeIconicWindows (USER.170)
93 UINT ArrangeIconicWindows( HWND parent )
97 INT x, y, xspacing, yspacing;
99 GetClientRect16( parent, &rectParent );
101 y = rectParent.bottom;
102 xspacing = yspacing = 70; /* FIXME: This should come from WIN.INI */
103 hwndChild = GetWindow( parent, GW_CHILD );
106 if (IsIconic( hwndChild ))
108 SetWindowPos( hwndChild, 0, x + (xspacing - SYSMETRICS_CXICON) / 2,
109 y - (yspacing + SYSMETRICS_CYICON) / 2, 0, 0,
110 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
111 if (x <= rectParent.right - xspacing) x += xspacing;
118 hwndChild = GetWindow( hwndChild, GW_HWNDNEXT );
124 /***********************************************************************
125 * GetWindowRect16 (USER.32)
127 void GetWindowRect16( HWND16 hwnd, LPRECT16 rect )
129 WND * wndPtr = WIN_FindWndPtr( hwnd );
132 *rect = wndPtr->rectWindow;
133 if (wndPtr->dwStyle & WS_CHILD)
134 MapWindowPoints16( wndPtr->parent->hwndSelf, 0, (POINT16 *)rect, 2 );
138 /***********************************************************************
139 * GetWindowRect32 (USER.32)
141 void GetWindowRect32( HWND32 hwnd, LPRECT32 rect )
143 WND * wndPtr = WIN_FindWndPtr( hwnd );
146 CONV_RECT16TO32( &wndPtr->rectWindow, rect );
147 if (wndPtr->dwStyle & WS_CHILD)
148 MapWindowPoints32( wndPtr->parent->hwndSelf, 0, (POINT32 *)rect, 2 );
152 /***********************************************************************
153 * GetClientRect16 (USER.33)
155 void GetClientRect16( HWND16 hwnd, LPRECT16 rect )
157 WND * wndPtr = WIN_FindWndPtr( hwnd );
159 rect->left = rect->top = rect->right = rect->bottom = 0;
162 rect->right = wndPtr->rectClient.right - wndPtr->rectClient.left;
163 rect->bottom = wndPtr->rectClient.bottom - wndPtr->rectClient.top;
168 /***********************************************************************
169 * GetClientRect32 (USER32.219)
171 void GetClientRect32( HWND32 hwnd, LPRECT32 rect )
173 WND * wndPtr = WIN_FindWndPtr( hwnd );
175 rect->left = rect->top = rect->right = rect->bottom = 0;
178 rect->right = wndPtr->rectClient.right - wndPtr->rectClient.left;
179 rect->bottom = wndPtr->rectClient.bottom - wndPtr->rectClient.top;
184 /*******************************************************************
185 * ClientToScreen16 (USER.28)
187 BOOL16 ClientToScreen16( HWND16 hwnd, LPPOINT16 lppnt )
189 MapWindowPoints16( hwnd, 0, lppnt, 1 );
194 /*******************************************************************
195 * ClientToScreen32 (USER32.51)
197 BOOL32 ClientToScreen32( HWND32 hwnd, LPPOINT32 lppnt )
199 MapWindowPoints32( hwnd, 0, lppnt, 1 );
204 /*******************************************************************
205 * ScreenToClient16 (USER.29)
207 void ScreenToClient16( HWND16 hwnd, LPPOINT16 lppnt )
209 MapWindowPoints16( 0, hwnd, lppnt, 1 );
213 /*******************************************************************
214 * ScreenToClient32 (USER32.446)
216 void ScreenToClient32( HWND32 hwnd, LPPOINT32 lppnt )
218 MapWindowPoints32( 0, hwnd, lppnt, 1 );
222 /***********************************************************************
223 * WINPOS_WindowFromPoint
225 * Find the window and hittest for a given point.
227 INT16 WINPOS_WindowFromPoint( POINT16 pt, WND **ppWnd )
230 INT16 hittest = HTERROR;
236 wndPtr = WIN_GetDesktop()->child;
241 /* If point is in window, and window is visible, and it */
242 /* is enabled (or it's a top-level window), then explore */
243 /* its children. Otherwise, go to the next window. */
245 if ((wndPtr->dwStyle & WS_VISIBLE) &&
246 (!(wndPtr->dwStyle & WS_DISABLED) ||
247 ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD)) &&
248 (x >= wndPtr->rectWindow.left) &&
249 (x < wndPtr->rectWindow.right) &&
250 (y >= wndPtr->rectWindow.top) &&
251 (y < wndPtr->rectWindow.bottom))
253 *ppWnd = wndPtr; /* Got a suitable window */
255 /* If window is minimized or disabled, return at once */
256 if (wndPtr->dwStyle & WS_MINIMIZE) return HTCAPTION;
257 if (wndPtr->dwStyle & WS_DISABLED) return HTERROR;
259 /* If point is not in client area, ignore the children */
260 if ((x < wndPtr->rectClient.left) ||
261 (x >= wndPtr->rectClient.right) ||
262 (y < wndPtr->rectClient.top) ||
263 (y >= wndPtr->rectClient.bottom)) break;
265 x -= wndPtr->rectClient.left;
266 y -= wndPtr->rectClient.top;
267 wndPtr = wndPtr->child;
269 else wndPtr = wndPtr->next;
272 /* If nothing found, return the desktop window */
275 *ppWnd = WIN_GetDesktop();
279 /* Send the WM_NCHITTEST message (only if to the same task) */
280 if ((*ppWnd)->hmemTaskQ != GetTaskQueue(0)) return HTCLIENT;
281 hittest = (INT)SendMessage16( (*ppWnd)->hwndSelf, WM_NCHITTEST, 0,
282 MAKELONG( pt.x, pt.y ) );
283 if (hittest != HTTRANSPARENT) return hittest; /* Found the window */
285 /* If no children found in last search, make point relative to parent*/
288 x += (*ppWnd)->rectClient.left;
289 y += (*ppWnd)->rectClient.top;
292 /* Restart the search from the next sibling */
293 wndPtr = (*ppWnd)->next;
294 *ppWnd = (*ppWnd)->parent;
299 /*******************************************************************
300 * WindowFromPoint16 (USER.30)
302 HWND16 WindowFromPoint16( POINT16 pt )
305 WINPOS_WindowFromPoint( pt, &pWnd );
306 return pWnd->hwndSelf;
310 /*******************************************************************
311 * WindowFromPoint32 (USER32.581)
313 HWND32 WindowFromPoint32( POINT32 pt )
317 CONV_POINT32TO16( &pt, &pt16 );
318 WINPOS_WindowFromPoint( pt16, &pWnd );
319 return (HWND32)pWnd->hwndSelf;
323 /*******************************************************************
324 * ChildWindowFromPoint16 (USER.191)
326 HWND16 ChildWindowFromPoint16( HWND16 hwndParent, POINT16 pt )
328 /* pt is in the client coordinates */
330 WND* wnd = WIN_FindWndPtr(hwndParent);
335 /* get client rect fast */
336 rect.top = rect.left = 0;
337 rect.right = wnd->rectClient.right - wnd->rectClient.left;
338 rect.bottom = wnd->rectClient.bottom - wnd->rectClient.top;
340 if (!PtInRect16( &rect, pt )) return 0;
345 if (PtInRect16( &wnd->rectWindow, pt )) return wnd->hwndSelf;
352 /*******************************************************************
353 * ChildWindowFromPoint32 (USER32.)
355 HWND32 ChildWindowFromPoint32( HWND32 hwndParent, POINT32 pt )
358 CONV_POINT32TO16( &pt, &pt16 );
359 return (HWND32)ChildWindowFromPoint16( hwndParent, pt16 );
363 /*******************************************************************
364 * WINPOS_GetWinOffset
366 * Calculate the offset between the origin of the two windows. Used
367 * to implement MapWindowPoints.
369 static void WINPOS_GetWinOffset( HWND32 hwndFrom, HWND32 hwndTo,
374 offset->x = offset->y = 0;
375 if (hwndFrom == hwndTo ) return;
377 /* Translate source window origin to screen coords */
380 if (!(wndPtr = WIN_FindWndPtr( hwndFrom )))
382 fprintf(stderr,"MapWindowPoints: bad hwndFrom = %04x\n",hwndFrom);
385 while (wndPtr->parent)
387 offset->x += wndPtr->rectClient.left;
388 offset->y += wndPtr->rectClient.top;
389 wndPtr = wndPtr->parent;
393 /* Translate origin to destination window coords */
396 if (!(wndPtr = WIN_FindWndPtr( hwndTo )))
398 fprintf(stderr,"MapWindowPoints: bad hwndTo = %04x\n", hwndTo );
401 while (wndPtr->parent)
403 offset->x -= wndPtr->rectClient.left;
404 offset->y -= wndPtr->rectClient.top;
405 wndPtr = wndPtr->parent;
411 /*******************************************************************
412 * MapWindowPoints16 (USER.258)
414 void MapWindowPoints16( HWND16 hwndFrom, HWND16 hwndTo,
415 LPPOINT16 lppt, UINT16 count )
419 WINPOS_GetWinOffset( hwndFrom, hwndTo, &offset );
429 /*******************************************************************
430 * MapWindowPoints32 (USER32.385)
432 void MapWindowPoints32( HWND32 hwndFrom, HWND32 hwndTo,
433 LPPOINT32 lppt, UINT32 count )
437 WINPOS_GetWinOffset( hwndFrom, hwndTo, &offset );
447 /***********************************************************************
450 BOOL IsIconic(HWND hWnd)
452 WND * wndPtr = WIN_FindWndPtr(hWnd);
453 if (wndPtr == NULL) return FALSE;
454 return (wndPtr->dwStyle & WS_MINIMIZE) != 0;
458 /***********************************************************************
459 * IsZoomed (USER.272)
461 BOOL IsZoomed(HWND hWnd)
463 WND * wndPtr = WIN_FindWndPtr(hWnd);
464 if (wndPtr == NULL) return FALSE;
465 return (wndPtr->dwStyle & WS_MAXIMIZE) != 0;
469 /*******************************************************************
470 * GetActiveWindow (USER.60)
472 HWND GetActiveWindow()
478 /*******************************************************************
479 * SetActiveWindow (USER.59)
481 HWND SetActiveWindow( HWND hwnd )
483 HWND prev = hwndActive;
484 WND *wndPtr = WIN_FindWndPtr( hwnd );
486 if (!wndPtr || (wndPtr->dwStyle & WS_DISABLED) ||
487 !(wndPtr->dwStyle & WS_VISIBLE)) return 0;
489 WINPOS_SetActiveWindow( hwnd, 0, 0 );
494 /***********************************************************************
495 * BringWindowToTop (USER.45)
497 BOOL BringWindowToTop( HWND hwnd )
499 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
503 /***********************************************************************
504 * MoveWindow (USER.56)
506 BOOL MoveWindow( HWND hwnd, short x, short y, short cx, short cy, BOOL repaint)
508 int flags = SWP_NOZORDER | SWP_NOACTIVATE;
509 if (!repaint) flags |= SWP_NOREDRAW;
510 dprintf_win(stddeb, "MoveWindow: %04x %d,%d %dx%d %d\n",
511 hwnd, x, y, cx, cy, repaint );
512 return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
516 /***********************************************************************
517 * ShowWindow (USER.42)
519 BOOL ShowWindow( HWND hwnd, int cmd )
521 WND * wndPtr = WIN_FindWndPtr( hwnd );
525 short x = 0, y = 0, cx = 0, cy = 0;
527 if (!wndPtr) return FALSE;
529 dprintf_win(stddeb,"ShowWindow: hwnd=%04x, cmd=%d\n", hwnd, cmd);
531 wasVisible = (wndPtr->dwStyle & WS_VISIBLE) != 0;
536 if (!wasVisible) return FALSE;
537 swpflags |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE |
538 SWP_NOACTIVATE | SWP_NOZORDER;
541 case SW_SHOWMINNOACTIVE:
542 swpflags |= SWP_NOACTIVATE | SWP_NOZORDER;
544 case SW_SHOWMINIMIZED:
545 swpflags |= SWP_SHOWWINDOW;
548 swpflags |= SWP_FRAMECHANGED;
549 if (!(wndPtr->dwStyle & WS_MINIMIZE))
551 if (wndPtr->dwStyle & WS_MAXIMIZE)
553 wndPtr->flags |= WIN_RESTORE_MAX;
554 wndPtr->dwStyle &= ~WS_MAXIMIZE;
558 wndPtr->flags &= ~WIN_RESTORE_MAX;
559 wndPtr->rectNormal = wndPtr->rectWindow;
561 wndPtr->dwStyle |= WS_MINIMIZE;
562 WINPOS_FindIconPos( hwnd );
563 x = wndPtr->ptIconPos.x;
564 y = wndPtr->ptIconPos.y;
565 cx = SYSMETRICS_CXICON;
566 cy = SYSMETRICS_CYICON;
568 else swpflags |= SWP_NOSIZE | SWP_NOMOVE;
571 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE: */
572 swpflags |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
573 if (!(wndPtr->dwStyle & WS_MAXIMIZE))
575 /* Store the current position and find the maximized size */
576 if (!(wndPtr->dwStyle & WS_MINIMIZE))
577 wndPtr->rectNormal = wndPtr->rectWindow;
579 NC_GetMinMaxInfo( hwnd, &maxSize,
580 &wndPtr->ptMaxPos, NULL, NULL );
581 x = wndPtr->ptMaxPos.x;
582 y = wndPtr->ptMaxPos.y;
584 if( wndPtr->dwStyle & WS_MINIMIZE )
585 if( !SendMessage16( hwnd, WM_QUERYOPEN, 0, 0L ) )
587 swpflags |= SWP_NOSIZE;
593 wndPtr->dwStyle &= ~WS_MINIMIZE;
594 wndPtr->dwStyle |= WS_MAXIMIZE;
596 else swpflags |= SWP_NOSIZE | SWP_NOMOVE;
600 swpflags |= SWP_NOACTIVATE | SWP_NOZORDER;
603 swpflags |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
606 case SW_SHOWNOACTIVATE:
607 swpflags |= SWP_NOZORDER;
608 if (GetActiveWindow()) swpflags |= SWP_NOACTIVATE;
610 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
611 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
613 swpflags |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
615 if (wndPtr->dwStyle & WS_MINIMIZE)
617 if( !SendMessage16( hwnd, WM_QUERYOPEN, 0, 0L) )
619 swpflags |= SWP_NOSIZE;
622 wndPtr->ptIconPos.x = wndPtr->rectWindow.left;
623 wndPtr->ptIconPos.y = wndPtr->rectWindow.top;
624 wndPtr->dwStyle &= ~WS_MINIMIZE;
625 if (wndPtr->flags & WIN_RESTORE_MAX)
627 /* Restore to maximized position */
628 NC_GetMinMaxInfo( hwnd, &maxSize, &wndPtr->ptMaxPos,
630 x = wndPtr->ptMaxPos.x;
631 y = wndPtr->ptMaxPos.y;
634 wndPtr->dwStyle |= WS_MAXIMIZE;
636 else /* Restore to normal position */
638 x = wndPtr->rectNormal.left;
639 y = wndPtr->rectNormal.top;
640 cx = wndPtr->rectNormal.right - wndPtr->rectNormal.left;
641 cy = wndPtr->rectNormal.bottom - wndPtr->rectNormal.top;
644 else if (wndPtr->dwStyle & WS_MAXIMIZE)
646 wndPtr->ptMaxPos.x = wndPtr->rectWindow.left;
647 wndPtr->ptMaxPos.y = wndPtr->rectWindow.top;
648 wndPtr->dwStyle &= ~WS_MAXIMIZE;
649 x = wndPtr->rectNormal.left;
650 y = wndPtr->rectNormal.top;
651 cx = wndPtr->rectNormal.right - wndPtr->rectNormal.left;
652 cy = wndPtr->rectNormal.bottom - wndPtr->rectNormal.top;
654 else swpflags |= SWP_NOSIZE | SWP_NOMOVE;
658 SendMessage16( hwnd, WM_SHOWWINDOW, (cmd != SW_HIDE), 0 );
659 SetWindowPos( hwnd, HWND_TOP, x, y, cx, cy, swpflags );
661 if (wndPtr->flags & WIN_NEED_SIZE)
663 int wParam = SIZE_RESTORED;
665 wndPtr->flags &= ~WIN_NEED_SIZE;
666 if (wndPtr->dwStyle & WS_MAXIMIZE) wParam = SIZE_MAXIMIZED;
667 else if (wndPtr->dwStyle & WS_MINIMIZE) wParam = SIZE_MINIMIZED;
668 SendMessage16( hwnd, WM_SIZE, wParam,
669 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
670 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
671 SendMessage16( hwnd, WM_MOVE, 0,
672 MAKELONG(wndPtr->rectClient.left, wndPtr->rectClient.top) );
675 if (hwnd == GetFocus())
677 SetFocus( (wndPtr->dwStyle & WS_CHILD)? wndPtr->parent->hwndSelf: 0 );
678 if (hwnd == CARET_GetHwnd()) DestroyCaret();
685 /***********************************************************************
686 * GetInternalWindowPos16 (USER.460)
688 UINT16 GetInternalWindowPos16( HWND16 hwnd, LPRECT16 rectWnd, LPPOINT16 ptIcon)
690 WINDOWPLACEMENT16 wndpl;
691 if (!GetWindowPlacement16( hwnd, &wndpl )) return 0;
692 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
693 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
694 return wndpl.showCmd;
698 /***********************************************************************
699 * GetInternalWindowPos32 (USER32.244)
701 UINT32 GetInternalWindowPos32( HWND32 hwnd, LPRECT32 rectWnd, LPPOINT32 ptIcon)
703 WINDOWPLACEMENT32 wndpl;
704 if (!GetWindowPlacement32( hwnd, &wndpl )) return 0;
705 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
706 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
707 return wndpl.showCmd;
711 /***********************************************************************
712 * SetInternalWindowPos16 (USER.461)
714 void SetInternalWindowPos16( HWND16 hwnd, UINT16 showCmd,
715 LPRECT16 rect, LPPOINT16 pt )
717 WINDOWPLACEMENT16 wndpl;
718 WND *wndPtr = WIN_FindWndPtr( hwnd );
720 wndpl.length = sizeof(wndpl);
721 wndpl.flags = (pt != NULL) ? WPF_SETMINPOSITION : 0;
722 wndpl.showCmd = showCmd;
723 if (pt) wndpl.ptMinPosition = *pt;
724 wndpl.rcNormalPosition = (rect != NULL) ? *rect : wndPtr->rectNormal;
725 wndpl.ptMaxPosition = wndPtr->ptMaxPos;
726 SetWindowPlacement16( hwnd, &wndpl );
730 /***********************************************************************
731 * SetInternalWindowPos32 (USER32.482)
733 void SetInternalWindowPos32( HWND32 hwnd, UINT32 showCmd,
734 LPRECT32 rect, LPPOINT32 pt )
736 WINDOWPLACEMENT32 wndpl;
737 WND *wndPtr = WIN_FindWndPtr( hwnd );
739 wndpl.length = sizeof(wndpl);
740 wndpl.flags = (pt != NULL) ? WPF_SETMINPOSITION : 0;
741 wndpl.showCmd = showCmd;
742 if (pt) wndpl.ptMinPosition = *pt;
743 if (rect) wndpl.rcNormalPosition = *rect;
744 else CONV_RECT16TO32( &wndPtr->rectNormal, &wndpl.rcNormalPosition );
745 CONV_POINT16TO32( &wndPtr->ptMaxPos, &wndpl.ptMaxPosition );
746 SetWindowPlacement32( hwnd, &wndpl );
750 /***********************************************************************
751 * GetWindowPlacement16 (USER.370)
753 BOOL16 GetWindowPlacement16( HWND16 hwnd, WINDOWPLACEMENT16 *wndpl )
755 WND *wndPtr = WIN_FindWndPtr( hwnd );
756 if (!wndPtr) return FALSE;
758 wndpl->length = sizeof(*wndpl);
760 wndpl->showCmd = IsZoomed(hwnd) ? SW_SHOWMAXIMIZED :
761 (IsIconic(hwnd) ? SW_SHOWMINIMIZED : SW_SHOWNORMAL);
762 wndpl->ptMinPosition = wndPtr->ptIconPos;
763 wndpl->ptMaxPosition = wndPtr->ptMaxPos;
764 wndpl->rcNormalPosition = wndPtr->rectNormal;
769 /***********************************************************************
770 * GetWindowPlacement32 (USER32.306)
772 BOOL32 GetWindowPlacement32( HWND32 hwnd, WINDOWPLACEMENT32 *wndpl )
774 WND *wndPtr = WIN_FindWndPtr( hwnd );
775 if (!wndPtr) return FALSE;
777 wndpl->length = sizeof(*wndpl);
779 wndpl->showCmd = IsZoomed(hwnd) ? SW_SHOWMAXIMIZED :
780 (IsIconic(hwnd) ? SW_SHOWMINIMIZED : SW_SHOWNORMAL);
781 CONV_POINT16TO32( &wndPtr->ptIconPos, &wndpl->ptMinPosition );
782 CONV_POINT16TO32( &wndPtr->ptMaxPos, &wndpl->ptMaxPosition );
783 CONV_RECT16TO32( &wndPtr->rectNormal, &wndpl->rcNormalPosition );
788 /***********************************************************************
789 * SetWindowPlacement16 (USER.371)
791 BOOL16 SetWindowPlacement16( HWND16 hwnd, const WINDOWPLACEMENT16 *wndpl )
793 WND *wndPtr = WIN_FindWndPtr( hwnd );
794 if (!wndPtr) return FALSE;
796 if (wndpl->flags & WPF_SETMINPOSITION)
797 wndPtr->ptIconPos = wndpl->ptMinPosition;
798 if ((wndpl->flags & WPF_RESTORETOMAXIMIZED) &&
799 (wndpl->showCmd == SW_SHOWMINIMIZED)) wndPtr->flags |= WIN_RESTORE_MAX;
800 wndPtr->ptMaxPos = wndpl->ptMaxPosition;
801 wndPtr->rectNormal = wndpl->rcNormalPosition;
802 ShowWindow( hwnd, wndpl->showCmd );
807 /***********************************************************************
808 * SetWindowPlacement32 (USER32.518)
810 BOOL32 SetWindowPlacement32( HWND32 hwnd, const WINDOWPLACEMENT32 *wndpl )
812 WND *wndPtr = WIN_FindWndPtr( hwnd );
813 if (!wndPtr) return FALSE;
815 if (wndpl->flags & WPF_SETMINPOSITION)
816 CONV_POINT32TO16( &wndpl->ptMinPosition, &wndPtr->ptIconPos );
817 if ((wndpl->flags & WPF_RESTORETOMAXIMIZED) &&
818 (wndpl->showCmd == SW_SHOWMINIMIZED)) wndPtr->flags |= WIN_RESTORE_MAX;
819 CONV_POINT32TO16( &wndpl->ptMaxPosition, &wndPtr->ptMaxPos );
820 CONV_RECT32TO16( &wndpl->rcNormalPosition, &wndPtr->rectNormal );
821 ShowWindow( hwnd, wndpl->showCmd );
826 /*******************************************************************
827 * ACTIVATEAPP_callback
829 BOOL ACTIVATEAPP_callback(HWND hWnd, LPARAM lParam)
831 ACTIVATESTRUCT *lpActStruct = (ACTIVATESTRUCT*)lParam;
833 if (GetWindowTask(hWnd) != lpActStruct->hTaskSendTo) return 1;
835 SendMessage16( hWnd, WM_ACTIVATEAPP, lpActStruct->wFlag,
836 (LPARAM)((lpActStruct->hWindowTask)?lpActStruct->hWindowTask:0));
841 /*******************************************************************
842 * WINPOS_SetActiveWindow
844 * back-end to SetActiveWindow
846 BOOL WINPOS_SetActiveWindow( HWND hWnd, BOOL fMouse, BOOL fChangeFocus )
848 WND *wndPtr = WIN_FindWndPtr(hWnd);
849 WND *wndTemp = WIN_FindWndPtr(hwndActive);
850 CBTACTIVATESTRUCT *cbtStruct;
851 FARPROC enumCallback = MODULE_GetWndProcEntry16("ActivateAppProc");
852 ACTIVATESTRUCT actStruct;
855 /* FIXME: When proper support for cooperative multitasking is in place
856 * hActiveQ will be global
861 /* paranoid checks */
862 if( !hWnd || hWnd == GetDesktopWindow() || hWnd == hwndActive )
865 if( GetTaskQueue(0) != wndPtr->hmemTaskQ )
869 wIconized = HIWORD(wndTemp->dwStyle & WS_MINIMIZE);
871 dprintf_win(stddeb,"WINPOS_ActivateWindow: no current active window.\n");
873 /* call CBT hook chain */
874 if ((cbtStruct = SEGPTR_NEW(CBTACTIVATESTRUCT)))
877 cbtStruct->fMouse = fMouse;
878 cbtStruct->hWndActive = hwndActive;
879 wRet = HOOK_CallHooks( WH_CBT, HCBT_ACTIVATE, (WPARAM)hWnd,
880 (LPARAM)SEGPTR_GET(cbtStruct) );
881 SEGPTR_FREE(cbtStruct);
882 if (wRet) return wRet;
885 /* set prev active wnd to current active wnd and send notification */
886 if( (hwndPrevActive = hwndActive) )
888 /* FIXME: need a Win32 translation for WINELIB32 */
889 if( !SendMessage16(hwndPrevActive, WM_NCACTIVATE, 0, MAKELONG(hWnd,wIconized)) )
891 if (GetSysModalWindow() != hWnd) return 0;
892 /* disregard refusal if hWnd is sysmodal */
896 SendMessage32A( hwndActive, WM_ACTIVATE,
897 MAKEWPARAM( WA_INACTIVE, wIconized ),
900 SendMessage16(hwndPrevActive, WM_ACTIVATE, WA_INACTIVE,
901 MAKELONG(hWnd,wIconized));
904 /* check if something happened during message processing */
905 if( hwndPrevActive != hwndActive ) return 0;
911 /* send palette messages */
912 if( SendMessage16( hWnd, WM_QUERYNEWPALETTE, 0, 0L) )
913 SendMessage16((HWND16)-1, WM_PALETTEISCHANGING, (WPARAM)hWnd, 0L );
915 /* if prev wnd is minimized redraw icon title
918 wndTemp = WIN_FindWndPtr( WIN_GetTopParent( hwndPrevActive ) );
920 if(wndTemp->dwStyle & WS_MINIMIZE)
921 RedrawIconTitle(hwndPrevActive);
925 /* managed windows will get ConfigureNotify event */
926 if (!(wndPtr->dwStyle & WS_CHILD) && !(wndPtr->flags & WIN_MANAGED))
928 /* check Z-order and bring hWnd to the top */
929 for (wndTemp = WIN_GetDesktop()->child; wndTemp; wndTemp = wndTemp->next)
930 if (wndTemp->dwStyle & WS_VISIBLE) break;
932 if( wndTemp != wndPtr )
933 SetWindowPos(hWnd, HWND_TOP, 0,0,0,0,
934 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE );
937 if( !IsWindow(hWnd) ) return 0;
941 wndTemp = WIN_FindWndPtr( hwndPrevActive );
942 if (wndTemp) hActiveQ = wndTemp->hmemTaskQ;
945 /* send WM_ACTIVATEAPP if necessary */
946 if (hActiveQ != wndPtr->hmemTaskQ)
948 HTASK hT = QUEUE_GetQueueTask( hActiveQ );
950 actStruct.wFlag = 0; /* deactivate */
951 actStruct.hWindowTask = QUEUE_GetQueueTask(wndPtr->hmemTaskQ);
952 actStruct.hTaskSendTo = hT;
954 /* send WM_ACTIVATEAPP to top-level windows
955 * that belong to the actStruct.hTaskSendTo task
957 EnumWindows( enumCallback , (LPARAM)&actStruct );
959 actStruct.wFlag = 1; /* activate */
960 actStruct.hWindowTask = hT;
961 actStruct.hTaskSendTo = QUEUE_GetQueueTask( wndPtr->hmemTaskQ );
963 EnumWindows( enumCallback , (LPARAM)&actStruct );
965 if( !IsWindow(hWnd) ) return 0;
968 /* walk up to the first unowned window */
970 while (wndTemp->owner) wndTemp = wndTemp->owner;
971 /* and set last active owned popup */
972 wndTemp->hwndLastActive = hWnd;
974 wIconized = HIWORD(wndTemp->dwStyle & WS_MINIMIZE);
975 /* FIXME: Needs a Win32 translation for WINELIB32 */
976 SendMessage16( hWnd, WM_NCACTIVATE, 1,
977 MAKELONG(hwndPrevActive,wIconized));
979 SendMessage32A( hWnd, WM_ACTIVATE,
980 MAKEWPARAM( (fMouse)?WA_CLICKACTIVE:WA_ACTIVE, wIconized),
981 (LPARAM)hwndPrevActive );
983 SendMessage16( hWnd, WM_ACTIVATE, (fMouse)? WA_CLICKACTIVE : WA_ACTIVE,
984 MAKELONG(hwndPrevActive,wIconized));
987 if( !IsWindow(hWnd) ) return 0;
989 /* change focus if possible */
990 if( fChangeFocus && GetFocus() )
991 if( WIN_GetTopParent(GetFocus()) != hwndActive )
992 FOCUS_SwitchFocus( GetFocus(),
993 (wndPtr->dwStyle & WS_MINIMIZE)? 0: hwndActive);
995 /* if active wnd is minimized redraw icon title
998 wndPtr = WIN_FindWndPtr(hwndActive);
999 if(wndPtr->dwStyle & WS_MINIMIZE)
1000 RedrawIconTitle(hwndActive);
1003 return (hWnd == hwndActive);
1007 /*******************************************************************
1008 * WINPOS_ChangeActiveWindow
1011 BOOL WINPOS_ChangeActiveWindow( HWND hWnd, BOOL mouseMsg )
1013 WND *wndPtr = WIN_FindWndPtr(hWnd);
1015 if( !wndPtr ) return FALSE;
1017 /* child windows get WM_CHILDACTIVATE message */
1018 if( (wndPtr->dwStyle & (WS_CHILD | WS_POPUP)) == WS_CHILD )
1019 return SendMessage16(hWnd, WM_CHILDACTIVATE, 0, 0L);
1021 /* owned popups imply owner activation - not sure */
1022 if ((wndPtr->dwStyle & WS_POPUP) && wndPtr->owner &&
1023 !(wndPtr->owner->dwStyle & WS_DISABLED ))
1025 if (!(wndPtr = wndPtr->owner)) return FALSE;
1026 hWnd = wndPtr->hwndSelf;
1029 if( hWnd == hwndActive ) return FALSE;
1031 if( !WINPOS_SetActiveWindow(hWnd ,mouseMsg ,TRUE) )
1034 /* switch desktop queue to current active */
1035 if( wndPtr->parent == WIN_GetDesktop())
1036 WIN_GetDesktop()->hmemTaskQ = wndPtr->hmemTaskQ;
1042 /***********************************************************************
1043 * WINPOS_SendNCCalcSize
1045 * Send a WM_NCCALCSIZE message to a window.
1046 * All parameters are read-only except newClientRect.
1047 * oldWindowRect, oldClientRect and winpos must be non-NULL only
1048 * when calcValidRect is TRUE.
1050 LONG WINPOS_SendNCCalcSize( HWND hwnd, BOOL calcValidRect,
1051 RECT16 *newWindowRect, RECT16 *oldWindowRect,
1052 RECT16 *oldClientRect, SEGPTR winpos,
1053 RECT16 *newClientRect )
1055 NCCALCSIZE_PARAMS16 *params;
1058 if (!(params = SEGPTR_NEW(NCCALCSIZE_PARAMS16))) return 0;
1059 params->rgrc[0] = *newWindowRect;
1062 params->rgrc[1] = *oldWindowRect;
1063 params->rgrc[2] = *oldClientRect;
1064 params->lppos = winpos;
1066 result = SendMessage16( hwnd, WM_NCCALCSIZE, calcValidRect,
1067 (LPARAM)SEGPTR_GET( params ) );
1068 dprintf_win(stddeb, "WINPOS_SendNCCalcSize: %d %d %d %d\n",
1069 (int)params->rgrc[0].top, (int)params->rgrc[0].left,
1070 (int)params->rgrc[0].bottom, (int)params->rgrc[0].right);
1071 *newClientRect = params->rgrc[0];
1072 SEGPTR_FREE(params);
1077 /***********************************************************************
1078 * WINPOS_HandleWindowPosChanging16
1080 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1082 LONG WINPOS_HandleWindowPosChanging16( WND *wndPtr, WINDOWPOS16 *winpos )
1085 if (winpos->flags & SWP_NOSIZE) return 0;
1086 if ((wndPtr->dwStyle & WS_THICKFRAME) ||
1087 ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) == 0))
1089 NC_GetMinMaxInfo( winpos->hwnd, &maxSize, NULL, NULL, NULL );
1090 winpos->cx = MIN( winpos->cx, maxSize.x );
1091 winpos->cy = MIN( winpos->cy, maxSize.y );
1097 /***********************************************************************
1098 * WINPOS_HandleWindowPosChanging32
1100 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1102 LONG WINPOS_HandleWindowPosChanging32( WND *wndPtr, WINDOWPOS32 *winpos )
1105 if (winpos->flags & SWP_NOSIZE) return 0;
1106 if ((wndPtr->dwStyle & WS_THICKFRAME) ||
1107 ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) == 0))
1109 NC_GetMinMaxInfo( winpos->hwnd, &maxSize, NULL, NULL, NULL );
1110 winpos->cx = MIN( winpos->cx, maxSize.x );
1111 winpos->cy = MIN( winpos->cy, maxSize.y );
1117 /***********************************************************************
1118 * WINPOS_MoveWindowZOrder
1120 * Move a window in Z order, invalidating everything that needs it.
1121 * Only necessary for windows without associated X window.
1123 static void WINPOS_MoveWindowZOrder( HWND hwnd, HWND hwndAfter )
1126 WND *pWndAfter, *pWndCur, *wndPtr = WIN_FindWndPtr( hwnd );
1128 /* We have two possible cases:
1129 * - The window is moving up: we have to invalidate all areas
1130 * of the window that were covered by other windows
1131 * - The window is moving down: we have to invalidate areas
1132 * of other windows covered by this one.
1135 if (hwndAfter == HWND_TOP)
1139 else if (hwndAfter == HWND_BOTTOM)
1141 if (!wndPtr->next) return; /* Already at the bottom */
1146 if (!(pWndAfter = WIN_FindWndPtr( hwndAfter ))) return;
1147 if (wndPtr->next == pWndAfter) return; /* Already placed right */
1149 /* Determine which window we encounter first in Z-order */
1150 pWndCur = wndPtr->parent->child;
1151 while ((pWndCur != wndPtr) && (pWndCur != pWndAfter))
1152 pWndCur = pWndCur->next;
1153 movingUp = (pWndCur == pWndAfter);
1158 WND *pWndPrevAfter = wndPtr->next;
1159 WIN_UnlinkWindow( hwnd );
1160 WIN_LinkWindow( hwnd, hwndAfter );
1161 pWndCur = wndPtr->next;
1162 while (pWndCur != pWndPrevAfter)
1164 RECT16 rect = pWndCur->rectWindow;
1165 OffsetRect16( &rect, -wndPtr->rectClient.left,
1166 -wndPtr->rectClient.top );
1167 RedrawWindow16( hwnd, &rect, 0, RDW_INVALIDATE | RDW_ALLCHILDREN |
1168 RDW_FRAME | RDW_ERASE );
1169 pWndCur = pWndCur->next;
1172 else /* Moving down */
1174 pWndCur = wndPtr->next;
1175 WIN_UnlinkWindow( hwnd );
1176 WIN_LinkWindow( hwnd, hwndAfter );
1177 while (pWndCur != wndPtr)
1179 RECT16 rect = wndPtr->rectWindow;
1180 OffsetRect16( &rect, -pWndCur->rectClient.left,
1181 -pWndCur->rectClient.top );
1182 RedrawWindow16( pWndCur->hwndSelf, &rect, 0, RDW_INVALIDATE |
1183 RDW_ALLCHILDREN | RDW_FRAME | RDW_ERASE );
1184 pWndCur = pWndCur->next;
1189 /***********************************************************************
1190 * WINPOS_ReorderOwnedPopups
1192 * fix Z order taking into account owned popups -
1193 * basically we need to maintain them above owner window
1195 HWND WINPOS_ReorderOwnedPopups(HWND hwndInsertAfter, WND* wndPtr, WORD flags)
1197 WND* w = WIN_GetDesktop();
1201 /* if we are dealing with owned popup...
1203 if( wndPtr->dwStyle & WS_POPUP && wndPtr->owner && hwndInsertAfter != HWND_TOP )
1205 BOOL bFound = FALSE;
1206 HWND hwndLocalPrev = HWND_TOP;
1207 HWND hwndNewAfter = 0;
1211 if( !bFound && hwndInsertAfter == hwndLocalPrev )
1212 hwndInsertAfter = HWND_TOP;
1214 if( w->dwStyle & WS_POPUP && w->owner == wndPtr->owner )
1218 if( hwndInsertAfter == HWND_TOP )
1220 hwndInsertAfter = hwndLocalPrev;
1223 hwndNewAfter = hwndLocalPrev;
1226 if( w == wndPtr->owner )
1228 /* basically HWND_BOTTOM */
1229 hwndInsertAfter = hwndLocalPrev;
1232 hwndInsertAfter = hwndNewAfter;
1237 hwndLocalPrev = w->hwndSelf;
1243 /* or overlapped top-level window...
1245 if( !(wndPtr->dwStyle & WS_CHILD) )
1248 if( w == wndPtr ) break;
1250 if( w->dwStyle & WS_POPUP && w->owner == wndPtr )
1252 SetWindowPos(w->hwndSelf, hwndInsertAfter, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE |
1253 SWP_NOACTIVATE | SWP_NOSENDCHANGING | SWP_DEFERERASE);
1254 hwndInsertAfter = w->hwndSelf;
1259 return hwndInsertAfter;
1262 /***********************************************************************
1263 * WINPOS_SizeMoveClean
1265 * Make window look nice without excessive repainting
1269 * visible regions are in window coordinates
1270 * update regions are in window client coordinates
1271 * client and window rectangles are in parent client coordinates
1273 static void WINPOS_SizeMoveClean(WND* Wnd, HRGN oldVisRgn, LPRECT16 lpOldWndRect, LPRECT16 lpOldClientRect, BOOL bNoCopy )
1275 HRGN newVisRgn = DCE_GetVisRgn(Wnd->hwndSelf, DCX_WINDOW | DCX_CLIPSIBLINGS );
1276 HRGN dirtyRgn = CreateRectRgn(0,0,0,0);
1279 dprintf_win(stddeb,"cleaning up...new wnd=(%i %i-%i %i) old wnd=(%i %i-%i %i)\n\
1280 \t\tnew client=(%i %i-%i %i) old client=(%i %i-%i %i)\n",
1281 Wnd->rectWindow.left, Wnd->rectWindow.top, Wnd->rectWindow.right, Wnd->rectWindow.bottom,
1282 lpOldWndRect->left, lpOldWndRect->top, lpOldWndRect->right, lpOldWndRect->bottom,
1283 Wnd->rectClient.left,Wnd->rectClient.top,Wnd->rectClient.right,Wnd->rectClient.bottom,
1284 lpOldClientRect->left,lpOldClientRect->top,lpOldClientRect->right,lpOldClientRect->bottom);
1286 CombineRgn( dirtyRgn, newVisRgn, 0, RGN_COPY);
1290 HRGN hRgn = CreateRectRgn( lpOldClientRect->left - lpOldWndRect->left, lpOldClientRect->top - lpOldWndRect->top,
1291 lpOldClientRect->right - lpOldWndRect->left, lpOldClientRect->bottom - lpOldWndRect->top);
1292 CombineRgn( newVisRgn, newVisRgn, oldVisRgn, RGN_AND );
1293 CombineRgn( newVisRgn, newVisRgn, hRgn, RGN_AND );
1297 /* map regions to the parent client area */
1299 OffsetRgn(dirtyRgn, Wnd->rectWindow.left, Wnd->rectWindow.top);
1300 OffsetRgn(oldVisRgn, lpOldWndRect->left, lpOldWndRect->top);
1302 /* compute invalidated region outside Wnd - (in client coordinates of the parent window) */
1304 other = CombineRgn(dirtyRgn, oldVisRgn, dirtyRgn, RGN_DIFF);
1306 /* map visible region to the Wnd client area */
1308 OffsetRgn( newVisRgn, Wnd->rectWindow.left - Wnd->rectClient.left,
1309 Wnd->rectWindow.top - Wnd->rectClient.top );
1311 /* substract previously invalidated region from the Wnd visible region */
1313 my = (Wnd->hrgnUpdate > 1)? CombineRgn( newVisRgn, newVisRgn, Wnd->hrgnUpdate, RGN_DIFF)
1316 if( bNoCopy ) /* invalidate Wnd visible region */
1318 if (my != NULLREGION) RedrawWindow32( Wnd->hwndSelf, NULL, newVisRgn, RDW_INVALIDATE |
1319 RDW_FRAME | RDW_ALLCHILDREN | RDW_ERASE );
1321 else /* bitblt old client area */
1329 updateRgn = CreateRectRgn( 0,0, Wnd->rectClient.right - Wnd->rectClient.left,
1330 Wnd->rectClient.bottom - Wnd->rectClient.top );
1332 /* clip visible region with client rect */
1334 my = CombineRgn( newVisRgn, newVisRgn, updateRgn, RGN_AND );
1336 /* substract result from client rect to get region that won't be copied */
1338 update = CombineRgn( updateRgn, updateRgn, newVisRgn, RGN_DIFF );
1340 /* Blt valid bits using parent window DC */
1342 if( my != NULLREGION )
1344 int xfrom = lpOldClientRect->left;
1345 int yfrom = lpOldClientRect->top;
1346 int xto = Wnd->rectClient.left;
1347 int yto = Wnd->rectClient.top;
1349 /* check if we can skip copying */
1351 if( xfrom != xto || yfrom != yto )
1353 /* compute clipping region in parent client coordinates */
1355 OffsetRgn( newVisRgn, Wnd->rectClient.left, Wnd->rectClient.top);
1356 CombineRgn( oldVisRgn, oldVisRgn, newVisRgn, RGN_OR );
1358 hDC = GetDCEx( Wnd->parent->hwndSelf, oldVisRgn, DCX_INTERSECTRGN | DCX_CACHE | DCX_CLIPSIBLINGS);
1360 BitBlt(hDC, xto, yto, lpOldClientRect->right - lpOldClientRect->left + 1,
1361 lpOldClientRect->bottom - lpOldClientRect->top + 1,
1362 hDC, xfrom, yfrom, SRCCOPY );
1364 ReleaseDC( Wnd->parent->hwndSelf, hDC);
1368 if( update != NULLREGION )
1369 RedrawWindow32( Wnd->hwndSelf, NULL, updateRgn, RDW_INVALIDATE |
1370 RDW_FRAME | RDW_ALLCHILDREN | RDW_ERASE );
1371 DeleteObject( updateRgn );
1374 /* erase uncovered areas */
1376 if( other != NULLREGION )
1377 RedrawWindow32( Wnd->parent->hwndSelf, NULL, dirtyRgn,
1378 RDW_INVALIDATE | RDW_ALLCHILDREN | RDW_ERASE );
1380 DeleteObject(dirtyRgn);
1381 DeleteObject(newVisRgn);
1384 /***********************************************************************
1385 * WINPOS_SetXWindowPos
1387 * SetWindowPos() for an X window. Used by the real SetWindowPos().
1389 static void WINPOS_SetXWindowPos( WINDOWPOS16 *winpos )
1391 XWindowChanges winChanges;
1393 WND *wndPtr = WIN_FindWndPtr( winpos->hwnd );
1395 if (!(winpos->flags & SWP_NOSIZE))
1397 winChanges.width = winpos->cx;
1398 winChanges.height = winpos->cy;
1399 changeMask |= CWWidth | CWHeight;
1401 if (!(winpos->flags & SWP_NOMOVE))
1403 winChanges.x = winpos->x;
1404 winChanges.y = winpos->y;
1405 changeMask |= CWX | CWY;
1407 if (!(winpos->flags & SWP_NOZORDER))
1409 if (winpos->hwndInsertAfter == HWND_TOP) winChanges.stack_mode = Above;
1410 else winChanges.stack_mode = Below;
1411 if ((winpos->hwndInsertAfter != HWND_TOP) &&
1412 (winpos->hwndInsertAfter != HWND_BOTTOM))
1414 WND * insertPtr = WIN_FindWndPtr( winpos->hwndInsertAfter );
1415 winChanges.sibling = insertPtr->window;
1416 changeMask |= CWSibling;
1418 changeMask |= CWStackMode;
1421 XConfigureWindow( display, wndPtr->window, changeMask, &winChanges );
1425 /***********************************************************************
1426 * SetWindowPos (USER.232)
1428 BOOL SetWindowPos( HWND hwnd, HWND hwndInsertAfter, INT x, INT y,
1429 INT cx, INT cy, WORD flags )
1433 RECT16 newWindowRect, newClientRect;
1437 dprintf_win(stddeb,"SetWindowPos: hwnd %04x, flags %08x\n", hwnd, flags);
1439 /* Check window handle */
1441 if (hwnd == GetDesktopWindow()) return FALSE;
1442 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return FALSE;
1444 /* Check for windows that may not be resized
1445 FIXME: this should be done only for Windows 3.0 programs */
1446 if (flags ==(SWP_SHOWWINDOW) || flags ==(SWP_HIDEWINDOW ) )
1447 flags |= SWP_NOSIZE | SWP_NOMOVE;
1449 /* Check dimensions */
1451 if (cx <= 0) cx = 1;
1452 if (cy <= 0) cy = 1;
1456 if (hwnd == hwndActive) flags |= SWP_NOACTIVATE; /* Already active */
1457 if ((wndPtr->rectWindow.right - wndPtr->rectWindow.left == cx) &&
1458 (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top == cy))
1459 flags |= SWP_NOSIZE; /* Already the right size */
1460 if ((wndPtr->rectWindow.left == x) && (wndPtr->rectWindow.top == y))
1461 flags |= SWP_NOMOVE; /* Already the right position */
1463 /* Check hwndInsertAfter */
1465 if (!(flags & (SWP_NOZORDER | SWP_NOACTIVATE)))
1467 /* Ignore TOPMOST flags when activating a window */
1468 /* _and_ moving it in Z order. */
1469 if ((hwndInsertAfter == HWND_TOPMOST) ||
1470 (hwndInsertAfter == HWND_NOTOPMOST))
1471 hwndInsertAfter = HWND_TOP;
1473 /* TOPMOST not supported yet */
1474 if ((hwndInsertAfter == HWND_TOPMOST) ||
1475 (hwndInsertAfter == HWND_NOTOPMOST)) hwndInsertAfter = HWND_TOP;
1477 /* hwndInsertAfter must be a sibling of the window */
1478 if ((hwndInsertAfter != HWND_TOP) && (hwndInsertAfter != HWND_BOTTOM))
1480 WND* wnd = WIN_FindWndPtr(hwndInsertAfter);
1481 if( wnd->parent != wndPtr->parent ) return FALSE;
1482 if( wnd->next == wndPtr ) flags |= SWP_NOZORDER;
1485 if (hwndInsertAfter == HWND_TOP)
1486 flags |= ( wndPtr->parent->child == wndPtr)? SWP_NOZORDER: 0;
1487 else /* HWND_BOTTOM */
1488 flags |= ( wndPtr->next )? 0: SWP_NOZORDER;
1490 /* Fill the WINDOWPOS structure */
1493 winpos.hwndInsertAfter = hwndInsertAfter;
1498 winpos.flags = flags;
1500 /* Send WM_WINDOWPOSCHANGING message */
1502 if (!(flags & SWP_NOSENDCHANGING))
1503 SendMessage16( hwnd, WM_WINDOWPOSCHANGING, 0, (LPARAM)MAKE_SEGPTR(&winpos) );
1505 /* Calculate new position and size */
1507 newWindowRect = wndPtr->rectWindow;
1508 newClientRect = wndPtr->rectClient;
1510 if (!(winpos.flags & SWP_NOSIZE))
1512 newWindowRect.right = newWindowRect.left + winpos.cx;
1513 newWindowRect.bottom = newWindowRect.top + winpos.cy;
1515 if (!(winpos.flags & SWP_NOMOVE))
1517 newWindowRect.left = winpos.x;
1518 newWindowRect.top = winpos.y;
1519 newWindowRect.right += winpos.x - wndPtr->rectWindow.left;
1520 newWindowRect.bottom += winpos.y - wndPtr->rectWindow.top;
1522 OffsetRect16( &newClientRect, winpos.x - wndPtr->rectWindow.left,
1523 winpos.y - wndPtr->rectWindow.top );
1526 winpos.flags |= SWP_NOCLIENTMOVE | SWP_NOCLIENTSIZE;
1528 /* Reposition window in Z order */
1530 if (!(winpos.flags & SWP_NOZORDER))
1532 /* reorder owned popups if hwnd is top-level window
1534 if( wndPtr->parent == WIN_GetDesktop() )
1535 hwndInsertAfter = WINPOS_ReorderOwnedPopups( hwndInsertAfter,
1540 WIN_UnlinkWindow( winpos.hwnd );
1541 WIN_LinkWindow( winpos.hwnd, hwndInsertAfter );
1543 else WINPOS_MoveWindowZOrder( winpos.hwnd, hwndInsertAfter );
1546 if ( !wndPtr->window && !(flags & SWP_NOREDRAW) &&
1547 (!(flags & SWP_NOMOVE) || !(flags & SWP_NOSIZE) || (flags & SWP_FRAMECHANGED)) )
1548 visRgn = DCE_GetVisRgn(hwnd, DCX_WINDOW | DCX_CLIPSIBLINGS);
1551 /* Send WM_NCCALCSIZE message to get new client area */
1552 if( (flags & (SWP_FRAMECHANGED | SWP_NOSIZE)) != SWP_NOSIZE )
1554 result = WINPOS_SendNCCalcSize( winpos.hwnd, TRUE, &newWindowRect,
1555 &wndPtr->rectWindow, &wndPtr->rectClient,
1556 MAKE_SEGPTR(&winpos), &newClientRect );
1558 /* FIXME: WVR_ALIGNxxx */
1560 if( newClientRect.left != wndPtr->rectClient.left ||
1561 newClientRect.top != wndPtr->rectClient.top )
1562 winpos.flags &= ~SWP_NOCLIENTMOVE;
1564 if( (newClientRect.right - newClientRect.left !=
1565 wndPtr->rectClient.right - wndPtr->rectClient.left) ||
1566 (newClientRect.bottom - newClientRect.top !=
1567 wndPtr->rectClient.bottom - wndPtr->rectClient.top) )
1568 winpos.flags &= ~SWP_NOCLIENTSIZE;
1571 if( !(flags & SWP_NOMOVE) && (newClientRect.left != wndPtr->rectClient.left ||
1572 newClientRect.top != wndPtr->rectClient.top) )
1573 winpos.flags &= ~SWP_NOCLIENTMOVE;
1575 /* Perform the moving and resizing */
1579 RECT16 oldWindowRect = wndPtr->rectWindow;
1580 RECT16 oldClientRect = wndPtr->rectClient;
1582 HWND bogusInsertAfter = winpos.hwndInsertAfter;
1584 winpos.hwndInsertAfter = hwndInsertAfter;
1585 WINPOS_SetXWindowPos( &winpos );
1587 wndPtr->rectWindow = newWindowRect;
1588 wndPtr->rectClient = newClientRect;
1589 winpos.hwndInsertAfter = bogusInsertAfter;
1591 /* FIXME: should do something like WINPOS_SizeMoveClean */
1593 if( (oldClientRect.left - oldWindowRect.left !=
1594 newClientRect.left - newWindowRect.left) ||
1595 (oldClientRect.top - oldWindowRect.top !=
1596 newClientRect.top - newWindowRect.top) )
1598 RedrawWindow32( wndPtr->hwndSelf, NULL, 0,
1599 RDW_ALLCHILDREN | RDW_FRAME | RDW_ERASE );
1601 if( winpos.flags & SWP_FRAMECHANGED )
1606 if( oldClientRect.right > newClientRect.right )
1608 rect.left = newClientRect.right; rect.top = newClientRect.top;
1609 rect.right = oldClientRect.right; rect.bottom = newClientRect.bottom;
1611 RedrawWindow32( wndPtr->hwndSelf, &rect, 0,
1612 RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN );
1614 if( oldClientRect.bottom > newClientRect.bottom )
1616 rect.left = newClientRect.left; rect.top = newClientRect.bottom;
1617 rect.right = (wErase)?oldClientRect.right:newClientRect.right;
1618 rect.bottom = oldClientRect.bottom;
1620 RedrawWindow32( wndPtr->hwndSelf, &rect, 0,
1621 RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN );
1623 if( !wErase ) wndPtr->flags |= WIN_NEEDS_NCPAINT;
1628 RECT16 oldWindowRect = wndPtr->rectWindow;
1629 RECT16 oldClientRect = wndPtr->rectClient;
1631 wndPtr->rectWindow = newWindowRect;
1632 wndPtr->rectClient = newClientRect;
1634 if( !(flags & SWP_NOREDRAW) )
1636 BOOL bNoCopy = (flags & SWP_NOCOPYBITS) ||
1637 (result >= WVR_HREDRAW && result < WVR_VALIDRECTS);
1639 if( (winpos.flags & SWP_NOPOSCHANGE) != SWP_NOPOSCHANGE )
1641 /* optimize cleanup by BitBlt'ing where possible */
1643 WINPOS_SizeMoveClean(wndPtr, visRgn, &oldWindowRect, &oldClientRect, bNoCopy);
1644 DeleteObject(visRgn);
1647 if( winpos.flags & SWP_FRAMECHANGED )
1648 RedrawWindow32( winpos.hwnd, NULL, 0, RDW_NOCHILDREN | RDW_FRAME );
1651 DeleteObject(visRgn);
1654 if (flags & SWP_SHOWWINDOW)
1656 wndPtr->dwStyle |= WS_VISIBLE;
1659 XMapWindow( display, wndPtr->window );
1663 if (!(flags & SWP_NOREDRAW))
1664 RedrawWindow32( winpos.hwnd, NULL, 0,
1665 RDW_INVALIDATE | RDW_ALLCHILDREN |
1666 RDW_FRAME | RDW_ERASE );
1669 else if (flags & SWP_HIDEWINDOW)
1671 wndPtr->dwStyle &= ~WS_VISIBLE;
1674 XUnmapWindow( display, wndPtr->window );
1678 if (!(flags & SWP_NOREDRAW))
1679 RedrawWindow16( wndPtr->parent->hwndSelf, &wndPtr->rectWindow, 0,
1680 RDW_INVALIDATE | RDW_ALLCHILDREN | RDW_ERASE );
1683 if ((winpos.hwnd == GetFocus()) || IsChild(winpos.hwnd, GetFocus()))
1684 SetFocus( GetParent(winpos.hwnd) ); /* Revert focus to parent */
1686 if (winpos.hwnd == hwndActive)
1688 /* Activate previously active window if possible */
1689 HWND newActive = hwndPrevActive;
1690 if (!IsWindow(newActive) || (newActive == winpos.hwnd))
1692 newActive = GetTopWindow( GetDesktopWindow() );
1693 if (newActive == winpos.hwnd)
1694 newActive = wndPtr->next ? wndPtr->next->hwndSelf : 0;
1696 WINPOS_ChangeActiveWindow( newActive, FALSE );
1700 /* Activate the window */
1702 if (!(flags & SWP_NOACTIVATE))
1703 WINPOS_ChangeActiveWindow( winpos.hwnd, FALSE );
1705 /* Repaint the window */
1707 if (wndPtr->window) MSG_Synchronize(); /* Wait for all expose events */
1709 EVENT_DummyMotionNotify(); /* Simulate a mouse event to set the cursor */
1711 if (!(flags & SWP_DEFERERASE))
1712 RedrawWindow32( wndPtr->parent->hwndSelf, NULL, 0,
1713 RDW_ALLCHILDREN | RDW_ERASENOW );
1715 /* And last, send the WM_WINDOWPOSCHANGED message */
1717 if (!(winpos.flags & SWP_NOSENDCHANGING))
1718 SendMessage16( winpos.hwnd, WM_WINDOWPOSCHANGED,
1719 0, (LPARAM)MAKE_SEGPTR(&winpos) );
1725 /***********************************************************************
1726 * BeginDeferWindowPos (USER.259)
1728 HDWP16 BeginDeferWindowPos( INT count )
1733 if (count <= 0) return 0;
1734 handle = USER_HEAP_ALLOC( sizeof(DWP) + (count-1)*sizeof(WINDOWPOS16) );
1735 if (!handle) return 0;
1736 pDWP = (DWP *) USER_HEAP_LIN_ADDR( handle );
1737 pDWP->actualCount = 0;
1738 pDWP->suggestedCount = count;
1740 pDWP->wMagic = DWP_MAGIC;
1741 pDWP->hwndParent = 0;
1746 /***********************************************************************
1747 * DeferWindowPos (USER.260)
1749 HDWP16 DeferWindowPos( HDWP16 hdwp, HWND hwnd, HWND hwndAfter, INT x, INT y,
1750 INT cx, INT cy, UINT flags )
1754 HDWP16 newhdwp = hdwp;
1757 pDWP = (DWP *) USER_HEAP_LIN_ADDR( hdwp );
1758 if (!pDWP) return 0;
1759 if (hwnd == GetDesktopWindow()) return 0;
1761 /* All the windows of a DeferWindowPos() must have the same parent */
1763 parent = WIN_FindWndPtr( hwnd )->parent->hwndSelf;
1764 if (pDWP->actualCount == 0) pDWP->hwndParent = parent;
1765 else if (parent != pDWP->hwndParent)
1767 USER_HEAP_FREE( hdwp );
1771 for (i = 0; i < pDWP->actualCount; i++)
1773 if (pDWP->winPos[i].hwnd == hwnd)
1775 /* Merge with the other changes */
1776 if (!(flags & SWP_NOZORDER))
1778 pDWP->winPos[i].hwndInsertAfter = hwndAfter;
1780 if (!(flags & SWP_NOMOVE))
1782 pDWP->winPos[i].x = x;
1783 pDWP->winPos[i].y = y;
1785 if (!(flags & SWP_NOSIZE))
1787 pDWP->winPos[i].cx = cx;
1788 pDWP->winPos[i].cy = cy;
1790 pDWP->winPos[i].flags &= flags & (SWP_NOSIZE | SWP_NOMOVE |
1791 SWP_NOZORDER | SWP_NOREDRAW |
1792 SWP_NOACTIVATE | SWP_NOCOPYBITS |
1794 pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
1799 if (pDWP->actualCount >= pDWP->suggestedCount)
1801 newhdwp = USER_HEAP_REALLOC( hdwp,
1802 sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS16) );
1803 if (!newhdwp) return 0;
1804 pDWP = (DWP *) USER_HEAP_LIN_ADDR( newhdwp );
1805 pDWP->suggestedCount++;
1807 pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
1808 pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
1809 pDWP->winPos[pDWP->actualCount].x = x;
1810 pDWP->winPos[pDWP->actualCount].y = y;
1811 pDWP->winPos[pDWP->actualCount].cx = cx;
1812 pDWP->winPos[pDWP->actualCount].cy = cy;
1813 pDWP->winPos[pDWP->actualCount].flags = flags;
1814 pDWP->actualCount++;
1819 /***********************************************************************
1820 * EndDeferWindowPos (USER.261)
1822 BOOL EndDeferWindowPos( HDWP16 hdwp )
1825 WINDOWPOS16 *winpos;
1829 pDWP = (DWP *) USER_HEAP_LIN_ADDR( hdwp );
1830 if (!pDWP) return FALSE;
1831 for (i = 0, winpos = pDWP->winPos; i < pDWP->actualCount; i++, winpos++)
1833 if (!(res = SetWindowPos( winpos->hwnd, winpos->hwndInsertAfter,
1834 winpos->x, winpos->y, winpos->cx, winpos->cy,
1835 winpos->flags ))) break;
1837 USER_HEAP_FREE( hdwp );
1842 /***********************************************************************
1843 * TileChildWindows (USER.199)
1845 void TileChildWindows( HWND parent, WORD action )
1847 printf("STUB TileChildWindows(%04x, %d)\n", parent, action);
1850 /***********************************************************************
1851 * CascageChildWindows (USER.198)
1853 void CascadeChildWindows( HWND parent, WORD action )
1855 printf("STUB CascadeChildWindows(%04x, %d)\n", parent, action);