Release 960506
[wine.git] / windows / winpos.c
blobe059ef073e918ad725868ccda74ab603f3e309ba
1 /*
2 * Window position related functions.
4 * Copyright 1993, 1994, 1995 Alexandre Julliard
5 * 1995,1996 Alex Korobka
6 */
8 #include "sysmetrics.h"
9 #include "module.h"
10 #include "user.h"
11 #include "win.h"
12 #include "event.h"
13 #include "hook.h"
14 #include "message.h"
15 #include "queue.h"
16 #include "stackframe.h"
17 #include "winpos.h"
18 #include "nonclient.h"
19 #include "stddebug.h"
20 /* #define DEBUG_WIN */
21 #include "debug.h"
23 #define SWP_NOPOSCHANGE (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE)
25 /* ----- external functions ----- */
27 void FOCUS_SwitchFocus( HWND , HWND );
28 HRGN DCE_GetVisRgn( HWND, WORD );
30 /* ----- internal variables ----- */
32 static HWND hwndActive = 0; /* Currently active window */
33 static HWND hwndPrevActive = 0; /* Previously active window */
35 /***********************************************************************
36 * WINPOS_FindIconPos
38 * Find a suitable place for an iconic window.
39 * The new position is stored into wndPtr->ptIconPos.
41 void WINPOS_FindIconPos( HWND hwnd )
43 RECT rectParent;
44 short x, y, xspacing, yspacing;
45 WND * wndPtr = WIN_FindWndPtr( hwnd );
47 if (!wndPtr || !wndPtr->parent) return;
48 GetClientRect( wndPtr->parent->hwndSelf, &rectParent );
49 if ((wndPtr->ptIconPos.x >= rectParent.left) &&
50 (wndPtr->ptIconPos.x + SYSMETRICS_CXICON < rectParent.right) &&
51 (wndPtr->ptIconPos.y >= rectParent.top) &&
52 (wndPtr->ptIconPos.y + SYSMETRICS_CYICON < rectParent.bottom))
53 return; /* The icon already has a suitable position */
55 xspacing = yspacing = 70; /* FIXME: This should come from WIN.INI */
56 y = rectParent.bottom;
57 for (;;)
59 for (x = rectParent.left; x<=rectParent.right-xspacing; x += xspacing)
61 /* Check if another icon already occupies this spot */
62 WND *childPtr = wndPtr->parent->child;
63 while (childPtr)
65 if ((childPtr->dwStyle & WS_MINIMIZE) && (childPtr != wndPtr))
67 if ((childPtr->rectWindow.left < x + xspacing) &&
68 (childPtr->rectWindow.right >= x) &&
69 (childPtr->rectWindow.top <= y) &&
70 (childPtr->rectWindow.bottom > y - yspacing))
71 break; /* There's a window in there */
73 childPtr = childPtr->next;
75 if (!childPtr)
77 /* No window was found, so it's OK for us */
78 wndPtr->ptIconPos.x = x + (xspacing - SYSMETRICS_CXICON) / 2;
79 wndPtr->ptIconPos.y = y - (yspacing + SYSMETRICS_CYICON) / 2;
80 return;
83 y -= yspacing;
88 /***********************************************************************
89 * ArrangeIconicWindows (USER.170)
91 UINT ArrangeIconicWindows( HWND parent )
93 RECT rectParent;
94 HWND hwndChild;
95 INT x, y, xspacing, yspacing;
97 GetClientRect( parent, &rectParent );
98 x = rectParent.left;
99 y = rectParent.bottom;
100 xspacing = yspacing = 70; /* FIXME: This should come from WIN.INI */
101 hwndChild = GetWindow( parent, GW_CHILD );
102 while (hwndChild)
104 if (IsIconic( hwndChild ))
106 SetWindowPos( hwndChild, 0, x + (xspacing - SYSMETRICS_CXICON) / 2,
107 y - (yspacing + SYSMETRICS_CYICON) / 2, 0, 0,
108 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
109 if (x <= rectParent.right - xspacing) x += xspacing;
110 else
112 x = rectParent.left;
113 y -= yspacing;
116 hwndChild = GetWindow( hwndChild, GW_HWNDNEXT );
118 return yspacing;
122 /***********************************************************************
123 * GetWindowRect (USER.32)
125 void GetWindowRect( HWND hwnd, LPRECT rect )
127 WND * wndPtr = WIN_FindWndPtr( hwnd );
128 if (!wndPtr) return;
130 *rect = wndPtr->rectWindow;
131 if (wndPtr->dwStyle & WS_CHILD)
132 MapWindowPoints( wndPtr->parent->hwndSelf, 0, (POINT *)rect, 2 );
136 /***********************************************************************
137 * GetClientRect (USER.33)
139 void GetClientRect( HWND hwnd, LPRECT rect )
141 WND * wndPtr = WIN_FindWndPtr( hwnd );
143 rect->left = rect->top = rect->right = rect->bottom = 0;
144 if (wndPtr)
146 rect->right = wndPtr->rectClient.right - wndPtr->rectClient.left;
147 rect->bottom = wndPtr->rectClient.bottom - wndPtr->rectClient.top;
152 /*******************************************************************
153 * ClientToScreen (USER.28)
155 BOOL ClientToScreen( HWND hwnd, LPPOINT lppnt )
157 MapWindowPoints( hwnd, 0, lppnt, 1 );
158 return TRUE;
162 /*******************************************************************
163 * ScreenToClient (USER.29)
165 void ScreenToClient( HWND hwnd, LPPOINT lppnt )
167 MapWindowPoints( 0, hwnd, lppnt, 1 );
171 /***********************************************************************
172 * WINPOS_WindowFromPoint
174 * Find the window and hittest for a given point.
176 INT WINPOS_WindowFromPoint( POINT pt, WND **ppWnd )
178 WND *wndPtr;
179 INT hittest = HTERROR;
180 INT x, y;
182 *ppWnd = NULL;
183 x = pt.x;
184 y = pt.y;
185 wndPtr = WIN_GetDesktop()->child;
186 for (;;)
188 while (wndPtr)
190 /* If point is in window, and window is visible, and it */
191 /* is enabled (or it's a top-level window), then explore */
192 /* its children. Otherwise, go to the next window. */
194 if ((wndPtr->dwStyle & WS_VISIBLE) &&
195 (!(wndPtr->dwStyle & WS_DISABLED) ||
196 ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD)) &&
197 (x >= wndPtr->rectWindow.left) &&
198 (x < wndPtr->rectWindow.right) &&
199 (y >= wndPtr->rectWindow.top) &&
200 (y < wndPtr->rectWindow.bottom))
202 *ppWnd = wndPtr; /* Got a suitable window */
204 /* If window is minimized or disabled, return at once */
205 if (wndPtr->dwStyle & WS_MINIMIZE) return HTCAPTION;
206 if (wndPtr->dwStyle & WS_DISABLED) return HTERROR;
208 /* If point is not in client area, ignore the children */
209 if ((x < wndPtr->rectClient.left) ||
210 (x >= wndPtr->rectClient.right) ||
211 (y < wndPtr->rectClient.top) ||
212 (y >= wndPtr->rectClient.bottom)) break;
214 x -= wndPtr->rectClient.left;
215 y -= wndPtr->rectClient.top;
216 wndPtr = wndPtr->child;
218 else wndPtr = wndPtr->next;
221 /* If nothing found, return the desktop window */
222 if (!*ppWnd)
224 *ppWnd = WIN_GetDesktop();
225 return HTCLIENT;
228 /* Send the WM_NCHITTEST message (only if to the same task) */
229 if ((*ppWnd)->hmemTaskQ != GetTaskQueue(0)) return HTCLIENT;
230 hittest = (INT)SendMessage( (*ppWnd)->hwndSelf, WM_NCHITTEST, 0,
231 MAKELONG( pt.x, pt.y ) );
232 if (hittest != HTTRANSPARENT) return hittest; /* Found the window */
234 /* If no children found in last search, make point relative to parent*/
235 if (!wndPtr)
237 x += (*ppWnd)->rectClient.left;
238 y += (*ppWnd)->rectClient.top;
241 /* Restart the search from the next sibling */
242 wndPtr = (*ppWnd)->next;
243 *ppWnd = (*ppWnd)->parent;
248 /*******************************************************************
249 * WindowFromPoint (USER.30)
251 HWND WindowFromPoint( POINT pt )
253 WND *pWnd;
254 WINPOS_WindowFromPoint( pt, &pWnd );
255 return pWnd->hwndSelf;
259 /*******************************************************************
260 * ChildWindowFromPoint (USER.191)
262 HWND ChildWindowFromPoint( HWND hwndParent, POINT pt )
264 /* pt is in the client coordinates */
266 WND* wnd = WIN_FindWndPtr(hwndParent);
267 RECT rect;
269 if( !wnd ) return 0;
271 /* get client rect fast */
272 rect.top = rect.left = 0;
273 rect.right = wnd->rectClient.right - wnd->rectClient.left;
274 rect.bottom = wnd->rectClient.bottom - wnd->rectClient.top;
276 if (!PtInRect( &rect, pt )) return 0;
278 wnd = wnd->child;
279 while ( wnd )
281 if (PtInRect( &wnd->rectWindow, pt )) return wnd->hwndSelf;
282 wnd = wnd->next;
284 return hwndParent;
287 /*******************************************************************
288 * MapWindowPoints (USER.258)
290 void MapWindowPoints( HWND hwndFrom, HWND hwndTo, LPPOINT lppt, WORD count )
292 WND * wndPtr;
293 POINT * curpt;
294 POINT origin = { 0, 0 };
295 WORD i;
297 if( hwndFrom == hwndTo ) return;
299 /* Translate source window origin to screen coords */
300 if (hwndFrom)
302 if (!(wndPtr = WIN_FindWndPtr( hwndFrom )))
304 fprintf(stderr,"MapWindowPoints: bad hwndFrom = %04x\n",hwndFrom);
305 return;
307 while (wndPtr->parent)
309 origin.x += wndPtr->rectClient.left;
310 origin.y += wndPtr->rectClient.top;
311 wndPtr = wndPtr->parent;
315 /* Translate origin to destination window coords */
316 if (hwndTo)
318 if (!(wndPtr = WIN_FindWndPtr( hwndTo )))
320 fprintf(stderr,"MapWindowPoints: bad hwndTo = %04x\n", hwndTo );
321 return;
323 while (wndPtr->parent)
325 origin.x -= wndPtr->rectClient.left;
326 origin.y -= wndPtr->rectClient.top;
327 wndPtr = wndPtr->parent;
331 /* Translate points */
332 for (i = 0, curpt = lppt; i < count; i++, curpt++)
334 curpt->x += origin.x;
335 curpt->y += origin.y;
340 /***********************************************************************
341 * IsIconic (USER.31)
343 BOOL IsIconic(HWND hWnd)
345 WND * wndPtr = WIN_FindWndPtr(hWnd);
346 if (wndPtr == NULL) return FALSE;
347 return (wndPtr->dwStyle & WS_MINIMIZE) != 0;
351 /***********************************************************************
352 * IsZoomed (USER.272)
354 BOOL IsZoomed(HWND hWnd)
356 WND * wndPtr = WIN_FindWndPtr(hWnd);
357 if (wndPtr == NULL) return FALSE;
358 return (wndPtr->dwStyle & WS_MAXIMIZE) != 0;
362 /*******************************************************************
363 * GetActiveWindow (USER.60)
365 HWND GetActiveWindow()
367 return hwndActive;
371 /*******************************************************************
372 * SetActiveWindow (USER.59)
374 HWND SetActiveWindow( HWND hwnd )
376 HWND prev = hwndActive;
377 WND *wndPtr = WIN_FindWndPtr( hwnd );
379 if (!wndPtr || (wndPtr->dwStyle & WS_DISABLED) ||
380 !(wndPtr->dwStyle & WS_VISIBLE)) return 0;
382 WINPOS_SetActiveWindow( hwnd, 0, 0 );
383 return prev;
387 /***********************************************************************
388 * BringWindowToTop (USER.45)
390 BOOL BringWindowToTop( HWND hwnd )
392 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
396 /***********************************************************************
397 * MoveWindow (USER.56)
399 BOOL MoveWindow( HWND hwnd, short x, short y, short cx, short cy, BOOL repaint)
401 int flags = SWP_NOZORDER | SWP_NOACTIVATE;
402 if (!repaint) flags |= SWP_NOREDRAW;
403 dprintf_win(stddeb, "MoveWindow: %04x %d,%d %dx%d %d\n",
404 hwnd, x, y, cx, cy, repaint );
405 return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
409 /***********************************************************************
410 * ShowWindow (USER.42)
412 BOOL ShowWindow( HWND hwnd, int cmd )
414 WND * wndPtr = WIN_FindWndPtr( hwnd );
415 BOOL wasVisible;
416 POINT maxSize;
417 int swpflags = 0;
418 short x = 0, y = 0, cx = 0, cy = 0;
420 if (!wndPtr) return FALSE;
422 dprintf_win(stddeb,"ShowWindow: hwnd=%04x, cmd=%d\n", hwnd, cmd);
424 wasVisible = (wndPtr->dwStyle & WS_VISIBLE) != 0;
426 switch(cmd)
428 case SW_HIDE:
429 if (!wasVisible) return FALSE;
430 swpflags |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE |
431 SWP_NOACTIVATE | SWP_NOZORDER;
432 break;
434 case SW_SHOWMINNOACTIVE:
435 swpflags |= SWP_NOACTIVATE | SWP_NOZORDER;
436 /* fall through */
437 case SW_SHOWMINIMIZED:
438 swpflags |= SWP_SHOWWINDOW;
439 /* fall through */
440 case SW_MINIMIZE:
441 swpflags |= SWP_FRAMECHANGED;
442 if (!(wndPtr->dwStyle & WS_MINIMIZE))
444 if (wndPtr->dwStyle & WS_MAXIMIZE)
446 wndPtr->flags |= WIN_RESTORE_MAX;
447 wndPtr->dwStyle &= ~WS_MAXIMIZE;
449 else
451 wndPtr->flags &= ~WIN_RESTORE_MAX;
452 wndPtr->rectNormal = wndPtr->rectWindow;
454 wndPtr->dwStyle |= WS_MINIMIZE;
455 WINPOS_FindIconPos( hwnd );
456 x = wndPtr->ptIconPos.x;
457 y = wndPtr->ptIconPos.y;
458 cx = SYSMETRICS_CXICON;
459 cy = SYSMETRICS_CYICON;
461 else swpflags |= SWP_NOSIZE | SWP_NOMOVE;
462 break;
464 case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE: */
465 swpflags |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
466 if (!(wndPtr->dwStyle & WS_MAXIMIZE))
468 /* Store the current position and find the maximized size */
469 if (!(wndPtr->dwStyle & WS_MINIMIZE))
470 wndPtr->rectNormal = wndPtr->rectWindow;
472 NC_GetMinMaxInfo( hwnd, &maxSize,
473 &wndPtr->ptMaxPos, NULL, NULL );
474 x = wndPtr->ptMaxPos.x;
475 y = wndPtr->ptMaxPos.y;
477 if( wndPtr->dwStyle & WS_MINIMIZE )
478 if( !SendMessage( hwnd, WM_QUERYOPEN, 0, 0L ) )
480 swpflags |= SWP_NOSIZE;
481 break;
484 cx = maxSize.x;
485 cy = maxSize.y;
486 wndPtr->dwStyle &= ~WS_MINIMIZE;
487 wndPtr->dwStyle |= WS_MAXIMIZE;
489 else swpflags |= SWP_NOSIZE | SWP_NOMOVE;
490 break;
492 case SW_SHOWNA:
493 swpflags |= SWP_NOACTIVATE | SWP_NOZORDER;
494 /* fall through */
495 case SW_SHOW:
496 swpflags |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
497 break;
499 case SW_SHOWNOACTIVATE:
500 swpflags |= SWP_NOZORDER;
501 if (GetActiveWindow()) swpflags |= SWP_NOACTIVATE;
502 /* fall through */
503 case SW_SHOWNORMAL: /* same as SW_NORMAL: */
504 case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
505 case SW_RESTORE:
506 swpflags |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
508 if (wndPtr->dwStyle & WS_MINIMIZE)
510 if( !SendMessage( hwnd, WM_QUERYOPEN, 0, 0L) )
512 swpflags |= SWP_NOSIZE;
513 break;
515 wndPtr->ptIconPos.x = wndPtr->rectWindow.left;
516 wndPtr->ptIconPos.y = wndPtr->rectWindow.top;
517 wndPtr->dwStyle &= ~WS_MINIMIZE;
518 if (wndPtr->flags & WIN_RESTORE_MAX)
520 /* Restore to maximized position */
521 NC_GetMinMaxInfo( hwnd, &maxSize, &wndPtr->ptMaxPos,
522 NULL, NULL );
523 x = wndPtr->ptMaxPos.x;
524 y = wndPtr->ptMaxPos.y;
525 cx = maxSize.x;
526 cy = maxSize.y;
527 wndPtr->dwStyle |= WS_MAXIMIZE;
529 else /* Restore to normal position */
531 x = wndPtr->rectNormal.left;
532 y = wndPtr->rectNormal.top;
533 cx = wndPtr->rectNormal.right - wndPtr->rectNormal.left;
534 cy = wndPtr->rectNormal.bottom - wndPtr->rectNormal.top;
537 else if (wndPtr->dwStyle & WS_MAXIMIZE)
539 wndPtr->ptMaxPos.x = wndPtr->rectWindow.left;
540 wndPtr->ptMaxPos.y = wndPtr->rectWindow.top;
541 wndPtr->dwStyle &= ~WS_MAXIMIZE;
542 x = wndPtr->rectNormal.left;
543 y = wndPtr->rectNormal.top;
544 cx = wndPtr->rectNormal.right - wndPtr->rectNormal.left;
545 cy = wndPtr->rectNormal.bottom - wndPtr->rectNormal.top;
547 else swpflags |= SWP_NOSIZE | SWP_NOMOVE;
548 break;
551 SendMessage( hwnd, WM_SHOWWINDOW, (cmd != SW_HIDE), 0 );
552 SetWindowPos( hwnd, HWND_TOP, x, y, cx, cy, swpflags );
554 /* Send WM_SIZE and WM_MOVE messages if not already done */
555 if (!(wndPtr->flags & WIN_GOT_SIZEMSG))
557 int wParam = SIZE_RESTORED;
558 if (wndPtr->dwStyle & WS_MAXIMIZE) wParam = SIZE_MAXIMIZED;
559 else if (wndPtr->dwStyle & WS_MINIMIZE) wParam = SIZE_MINIMIZED;
560 wndPtr->flags |= WIN_GOT_SIZEMSG;
561 SendMessage( hwnd, WM_SIZE, wParam,
562 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
563 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
564 SendMessage( hwnd, WM_MOVE, 0,
565 MAKELONG(wndPtr->rectClient.left, wndPtr->rectClient.top) );
568 return wasVisible;
572 /***********************************************************************
573 * GetInternalWindowPos (USER.460)
575 WORD GetInternalWindowPos( HWND hwnd, LPRECT rectWnd, LPPOINT ptIcon )
577 WINDOWPLACEMENT wndpl;
578 if (!GetWindowPlacement( hwnd, &wndpl )) return 0;
579 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
580 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
581 return wndpl.showCmd;
585 /***********************************************************************
586 * SetInternalWindowPos (USER.461)
588 void SetInternalWindowPos( HWND hwnd, WORD showCmd, LPRECT rect, LPPOINT pt )
590 WINDOWPLACEMENT wndpl;
591 WND *wndPtr = WIN_FindWndPtr( hwnd );
593 wndpl.length = sizeof(wndpl);
594 wndpl.flags = (pt != NULL) ? WPF_SETMINPOSITION : 0;
595 wndpl.showCmd = showCmd;
596 if (pt) wndpl.ptMinPosition = *pt;
597 wndpl.rcNormalPosition = (rect != NULL) ? *rect : wndPtr->rectNormal;
598 wndpl.ptMaxPosition = wndPtr->ptMaxPos;
599 SetWindowPlacement( hwnd, &wndpl );
603 /***********************************************************************
604 * GetWindowPlacement (USER.370)
606 BOOL GetWindowPlacement( HWND hwnd, WINDOWPLACEMENT *wndpl )
608 WND *wndPtr = WIN_FindWndPtr( hwnd );
609 if (!wndPtr) return FALSE;
611 wndpl->length = sizeof(*wndpl);
612 wndpl->flags = 0;
613 wndpl->showCmd = IsZoomed(hwnd) ? SW_SHOWMAXIMIZED :
614 (IsIconic(hwnd) ? SW_SHOWMINIMIZED : SW_SHOWNORMAL);
615 wndpl->ptMinPosition = wndPtr->ptIconPos;
616 wndpl->ptMaxPosition = wndPtr->ptMaxPos;
617 wndpl->rcNormalPosition = wndPtr->rectNormal;
618 return TRUE;
622 /***********************************************************************
623 * SetWindowPlacement (USER.371)
625 BOOL SetWindowPlacement( HWND hwnd, WINDOWPLACEMENT *wndpl )
627 WND *wndPtr = WIN_FindWndPtr( hwnd );
628 if (!wndPtr) return FALSE;
630 if (wndpl->flags & WPF_SETMINPOSITION)
631 wndPtr->ptIconPos = wndpl->ptMinPosition;
632 if ((wndpl->flags & WPF_RESTORETOMAXIMIZED) &&
633 (wndpl->showCmd == SW_SHOWMINIMIZED)) wndPtr->flags |= WIN_RESTORE_MAX;
634 wndPtr->ptMaxPos = wndpl->ptMaxPosition;
635 wndPtr->rectNormal = wndpl->rcNormalPosition;
636 ShowWindow( hwnd, wndpl->showCmd );
637 return TRUE;
640 /*******************************************************************
641 * ACTIVATEAPP_callback
643 BOOL ACTIVATEAPP_callback(HWND hWnd, LPARAM lParam)
645 ACTIVATESTRUCT *lpActStruct = (ACTIVATESTRUCT*)lParam;
647 if (GetWindowTask(hWnd) != lpActStruct->hTaskSendTo) return 1;
649 SendMessage( hWnd, WM_ACTIVATEAPP, lpActStruct->wFlag,
650 (LPARAM)((lpActStruct->hWindowTask)?lpActStruct->hWindowTask:0));
651 return 1;
655 /*******************************************************************
656 * WINPOS_SetActiveWindow
658 * back-end to SetActiveWindow
660 BOOL WINPOS_SetActiveWindow( HWND hWnd, BOOL fMouse, BOOL fChangeFocus )
662 WND *wndPtr = WIN_FindWndPtr(hWnd);
663 WND *wndTemp = WIN_FindWndPtr(hwndActive);
664 CBTACTIVATESTRUCT cbtStruct = { fMouse , hwndActive };
665 FARPROC enumCallback = MODULE_GetWndProcEntry16("ActivateAppProc");
666 ACTIVATESTRUCT actStruct;
667 WORD wIconized=0,wRet= 0;
669 /* FIXME: When proper support for cooperative multitasking is in place
670 * hActiveQ will be global
673 HANDLE hActiveQ = 0;
675 /* paranoid checks */
676 if( !hWnd || hWnd == GetDesktopWindow() || hWnd == hwndActive )
677 return 0;
679 if( GetTaskQueue(0) != wndPtr->hmemTaskQ )
680 return 0;
682 if( wndTemp )
683 wIconized = HIWORD(wndTemp->dwStyle & WS_MINIMIZE);
684 else
685 dprintf_win(stddeb,"WINPOS_ActivateWindow: no current active window.\n");
687 /* call CBT hook chain */
688 wRet = HOOK_CallHooks(WH_CBT, HCBT_ACTIVATE, (WPARAM)hWnd,
689 (LPARAM)MAKE_SEGPTR(&cbtStruct));
691 if( wRet ) return wRet;
693 /* set prev active wnd to current active wnd and send notification */
694 if( (hwndPrevActive = hwndActive) )
696 /* FIXME: need a Win32 translation for WINELIB32 */
697 if( !SendMessage(hwndPrevActive, WM_NCACTIVATE, 0, MAKELONG(hWnd,wIconized)) )
699 if (GetSysModalWindow() != hWnd) return 0;
700 /* disregard refusal if hWnd is sysmodal */
703 #ifdef WINELIB32
704 SendMessage( hwndActive, WM_ACTIVATE,
705 MAKEWPARAM( WA_INACTIVE, wIconized ),
706 (LPARAM)hWnd );
707 #else
708 SendMessage(hwndPrevActive, WM_ACTIVATE, WA_INACTIVE,
709 MAKELONG(hWnd,wIconized));
710 #endif
712 /* check if something happened during message processing */
713 if( hwndPrevActive != hwndActive ) return 0;
716 /* set active wnd */
717 hwndActive = hWnd;
719 /* send palette messages */
720 if( SendMessage( hWnd, WM_QUERYNEWPALETTE, 0, 0L) )
721 SendMessage((HWND)-1, WM_PALETTEISCHANGING, (WPARAM)hWnd, 0L );
723 /* if prev wnd is minimized redraw icon title
724 if( hwndPrevActive )
726 wndTemp = WIN_FindWndPtr( WIN_GetTopParent( hwndPrevActive ) );
727 if(wndTemp)
728 if(wndTemp->dwStyle & WS_MINIMIZE)
729 RedrawIconTitle(hwndPrevActive);
732 if (!(wndPtr->dwStyle & WS_CHILD))
734 /* check Z-order and bring hWnd to the top */
735 for (wndTemp = WIN_GetDesktop()->child; wndTemp; wndTemp = wndTemp->next)
736 if (wndTemp->dwStyle & WS_VISIBLE) break;
738 if( wndTemp != wndPtr )
739 SetWindowPos(hWnd, HWND_TOP, 0,0,0,0,
740 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE );
743 if( !IsWindow(hWnd) ) return 0;
745 if (hwndPrevActive)
747 wndTemp = WIN_FindWndPtr( hwndPrevActive );
748 if (wndTemp) hActiveQ = wndTemp->hmemTaskQ;
751 /* send WM_ACTIVATEAPP if necessary */
752 if (hActiveQ != wndPtr->hmemTaskQ)
754 HTASK hT = QUEUE_GetQueueTask( hActiveQ );
756 actStruct.wFlag = 0; /* deactivate */
757 actStruct.hWindowTask = QUEUE_GetQueueTask(wndPtr->hmemTaskQ);
758 actStruct.hTaskSendTo = hT;
760 /* send WM_ACTIVATEAPP to top-level windows
761 * that belong to the actStruct.hTaskSendTo task
763 EnumWindows( enumCallback , (LPARAM)&actStruct );
765 actStruct.wFlag = 1; /* activate */
766 actStruct.hWindowTask = hT;
767 actStruct.hTaskSendTo = QUEUE_GetQueueTask( wndPtr->hmemTaskQ );
769 EnumWindows( enumCallback , (LPARAM)&actStruct );
771 if( !IsWindow(hWnd) ) return 0;
774 /* walk up to the first unowned window */
775 wndTemp = wndPtr;
776 while (wndTemp->owner) wndTemp = wndTemp->owner;
777 /* and set last active owned popup */
778 wndTemp->hwndLastActive = hWnd;
780 wIconized = HIWORD(wndTemp->dwStyle & WS_MINIMIZE);
781 /* FIXME: Needs a Win32 translation for WINELIB32 */
782 SendMessage( hWnd, WM_NCACTIVATE, 1,
783 MAKELONG(hwndPrevActive,wIconized));
784 #ifdef WINELIB32
785 SendMessage( hWnd, WM_ACTIVATE,
786 MAKEWPARAM( (fMouse)?WA_CLICKACTIVE:WA_ACTIVE, wIconized),
787 (LPARAM)hwndPrevActive );
788 #else
789 SendMessage( hWnd, WM_ACTIVATE, (fMouse)? WA_CLICKACTIVE : WA_ACTIVE,
790 MAKELONG(hwndPrevActive,wIconized));
791 #endif
793 if( !IsWindow(hWnd) ) return 0;
795 /* change focus if possible */
796 if( fChangeFocus && GetFocus() )
797 if( WIN_GetTopParent(GetFocus()) != hwndActive )
798 FOCUS_SwitchFocus( GetFocus(),
799 (wndPtr->dwStyle & WS_MINIMIZE)? 0: hwndActive);
801 /* if active wnd is minimized redraw icon title
802 if( hwndActive )
804 wndPtr = WIN_FindWndPtr(hwndActive);
805 if(wndPtr->dwStyle & WS_MINIMIZE)
806 RedrawIconTitle(hwndActive);
809 return (hWnd == hwndActive);
813 /*******************************************************************
814 * WINPOS_ChangeActiveWindow
817 BOOL WINPOS_ChangeActiveWindow( HWND hWnd, BOOL mouseMsg )
819 WND *wndPtr = WIN_FindWndPtr(hWnd);
821 if( !wndPtr ) return FALSE;
823 /* child windows get WM_CHILDACTIVATE message */
824 if( (wndPtr->dwStyle & WS_CHILD) && !( wndPtr->dwStyle & WS_POPUP))
825 return SendMessage(hWnd, WM_CHILDACTIVATE, 0, 0L);
827 /* owned popups imply owner activation */
828 if( wndPtr->dwStyle & WS_POPUP && wndPtr->owner )
830 wndPtr = wndPtr->owner;
831 if( !wndPtr ) return FALSE;
832 hWnd = wndPtr->hwndSelf;
835 if( hWnd == hwndActive ) return FALSE;
837 if( !WINPOS_SetActiveWindow(hWnd ,mouseMsg ,TRUE) )
838 return FALSE;
840 /* switch desktop queue to current active */
841 if( wndPtr->parent == WIN_GetDesktop())
842 WIN_GetDesktop()->hmemTaskQ = wndPtr->hmemTaskQ;
844 return TRUE;
848 /***********************************************************************
849 * WINPOS_SendNCCalcSize
851 * Send a WM_NCCALCSIZE message to a window.
852 * All parameters are read-only except newClientRect.
853 * oldWindowRect, oldClientRect and winpos must be non-NULL only
854 * when calcValidRect is TRUE.
856 LONG WINPOS_SendNCCalcSize( HWND hwnd, BOOL calcValidRect, RECT *newWindowRect,
857 RECT *oldWindowRect, RECT *oldClientRect,
858 SEGPTR winpos, RECT *newClientRect )
860 NCCALCSIZE_PARAMS params;
861 LONG result;
863 params.rgrc[0] = *newWindowRect;
864 if (calcValidRect)
866 params.rgrc[1] = *oldWindowRect;
867 params.rgrc[2] = *oldClientRect;
868 params.lppos = winpos;
870 result = SendMessage( hwnd, WM_NCCALCSIZE, calcValidRect,
871 (LPARAM)MAKE_SEGPTR( &params ) );
872 dprintf_win(stddeb, "WINPOS_SendNCCalcSize: %d %d %d %d\n",
873 (int)params.rgrc[0].top, (int)params.rgrc[0].left,
874 (int)params.rgrc[0].bottom, (int)params.rgrc[0].right);
875 *newClientRect = params.rgrc[0];
876 return result;
880 /***********************************************************************
881 * WINPOS_HandleWindowPosChanging
883 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
885 LONG WINPOS_HandleWindowPosChanging( WINDOWPOS *winpos )
887 POINT maxSize;
888 WND *wndPtr = WIN_FindWndPtr( winpos->hwnd );
889 if (!wndPtr || (winpos->flags & SWP_NOSIZE)) return 0;
890 if ((wndPtr->dwStyle & WS_THICKFRAME) ||
891 ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) == 0))
893 NC_GetMinMaxInfo( winpos->hwnd, &maxSize, NULL, NULL, NULL );
894 winpos->cx = MIN( winpos->cx, maxSize.x );
895 winpos->cy = MIN( winpos->cy, maxSize.y );
897 return 0;
901 /***********************************************************************
902 * WINPOS_MoveWindowZOrder
904 * Move a window in Z order, invalidating everything that needs it.
905 * Only necessary for windows without associated X window.
907 static void WINPOS_MoveWindowZOrder( HWND hwnd, HWND hwndAfter )
909 BOOL movingUp;
910 WND *pWndAfter, *pWndCur, *wndPtr = WIN_FindWndPtr( hwnd );
912 /* We have two possible cases:
913 * - The window is moving up: we have to invalidate all areas
914 * of the window that were covered by other windows
915 * - The window is moving down: we have to invalidate areas
916 * of other windows covered by this one.
919 if (hwndAfter == HWND_TOP)
921 movingUp = TRUE;
923 else if (hwndAfter == HWND_BOTTOM)
925 if (!wndPtr->next) return; /* Already at the bottom */
926 movingUp = FALSE;
928 else
930 if (!(pWndAfter = WIN_FindWndPtr( hwndAfter ))) return;
931 if (wndPtr->next == pWndAfter) return; /* Already placed right */
933 /* Determine which window we encounter first in Z-order */
934 pWndCur = wndPtr->parent->child;
935 while ((pWndCur != wndPtr) && (pWndCur != pWndAfter))
936 pWndCur = pWndCur->next;
937 movingUp = (pWndCur == pWndAfter);
940 if (movingUp)
942 WND *pWndPrevAfter = wndPtr->next;
943 WIN_UnlinkWindow( hwnd );
944 WIN_LinkWindow( hwnd, hwndAfter );
945 pWndCur = wndPtr->next;
946 while (pWndCur != pWndPrevAfter)
948 RECT rect = pWndCur->rectWindow;
949 OffsetRect( &rect, -wndPtr->rectClient.left,
950 -wndPtr->rectClient.top );
951 RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE | RDW_ALLCHILDREN |
952 RDW_FRAME | RDW_ERASE );
953 pWndCur = pWndCur->next;
956 else /* Moving down */
958 pWndCur = wndPtr->next;
959 WIN_UnlinkWindow( hwnd );
960 WIN_LinkWindow( hwnd, hwndAfter );
961 while (pWndCur != wndPtr)
963 RECT rect = wndPtr->rectWindow;
964 OffsetRect( &rect, -pWndCur->rectClient.left,
965 -pWndCur->rectClient.top );
966 RedrawWindow( pWndCur->hwndSelf, &rect, 0, RDW_INVALIDATE |
967 RDW_ALLCHILDREN | RDW_FRAME | RDW_ERASE );
968 pWndCur = pWndCur->next;
973 /***********************************************************************
974 * WINPOS_ReorderOwnedPopups
976 * fix Z order taking into account owned popups -
977 * basically we need to maintain them above owner window
979 HWND WINPOS_ReorderOwnedPopups(HWND hwndInsertAfter, WND* wndPtr, WORD flags)
981 WND* w = WIN_GetDesktop();
983 w = w->child;
985 /* if we are dealing with owned popup...
987 if( wndPtr->dwStyle & WS_POPUP && wndPtr->owner && hwndInsertAfter != HWND_TOP )
989 BOOL bFound = FALSE;
990 HWND hwndLocalPrev = HWND_TOP;
991 HWND hwndNewAfter = 0;
993 while( w )
995 if( !bFound && hwndInsertAfter == hwndLocalPrev )
996 hwndInsertAfter = HWND_TOP;
998 if( w->dwStyle & WS_POPUP && w->owner == wndPtr->owner )
1000 bFound = TRUE;
1002 if( hwndInsertAfter == HWND_TOP )
1004 hwndInsertAfter = hwndLocalPrev;
1005 break;
1007 hwndNewAfter = hwndLocalPrev;
1010 if( w == wndPtr->owner )
1012 /* basically HWND_BOTTOM */
1013 hwndInsertAfter = hwndLocalPrev;
1015 if( bFound )
1016 hwndInsertAfter = hwndNewAfter;
1017 break;
1020 if( w != wndPtr )
1021 hwndLocalPrev = w->hwndSelf;
1023 w = w->next;
1026 else
1027 /* or overlapped top-level window...
1029 if( !(wndPtr->dwStyle & WS_CHILD) )
1030 while( w )
1032 if( w == wndPtr ) break;
1034 if( w->dwStyle & WS_POPUP && w->owner == wndPtr )
1036 SetWindowPos(w->hwndSelf, hwndInsertAfter, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE |
1037 SWP_NOACTIVATE | SWP_NOSENDCHANGING | SWP_DEFERERASE);
1038 hwndInsertAfter = w->hwndSelf;
1040 w = w->next;
1043 return hwndInsertAfter;
1046 /***********************************************************************
1047 * WINPOS_SizeMoveClean
1049 * Make window look nice without excessive repainting
1051 * the pain:
1053 * visible regions are in window coordinates
1054 * update regions are in window client coordinates
1055 * client and window rectangles are in parent client coordinates
1057 static void WINPOS_SizeMoveClean(WND* Wnd, HRGN oldVisRgn, LPRECT lpOldWndRect, LPRECT lpOldClientRect, BOOL bNoCopy )
1059 HRGN newVisRgn = DCE_GetVisRgn(Wnd->hwndSelf, DCX_WINDOW | DCX_CLIPSIBLINGS );
1060 HRGN dirtyRgn = CreateRectRgn(0,0,0,0);
1061 int other, my;
1063 dprintf_win(stddeb,"cleaning up...new wnd=(%i %i-%i %i) old wnd=(%i %i-%i %i)\n\
1064 \t\tnew client=(%i %i-%i %i) old client=(%i %i-%i %i)\n",
1065 Wnd->rectWindow.left, Wnd->rectWindow.top, Wnd->rectWindow.right, Wnd->rectWindow.bottom,
1066 lpOldWndRect->left, lpOldWndRect->top, lpOldWndRect->right, lpOldWndRect->bottom,
1067 Wnd->rectClient.left,Wnd->rectClient.top,Wnd->rectClient.right,Wnd->rectClient.bottom,
1068 lpOldClientRect->left,lpOldClientRect->top,lpOldClientRect->right,lpOldClientRect->bottom);
1070 CombineRgn( dirtyRgn, newVisRgn, 0, RGN_COPY);
1072 if( !bNoCopy )
1074 HRGN hRgn = CreateRectRgn( lpOldClientRect->left - lpOldWndRect->left, lpOldClientRect->top - lpOldWndRect->top,
1075 lpOldClientRect->right - lpOldWndRect->left, lpOldClientRect->bottom - lpOldWndRect->top);
1076 CombineRgn( newVisRgn, newVisRgn, oldVisRgn, RGN_AND );
1077 CombineRgn( newVisRgn, newVisRgn, hRgn, RGN_AND );
1078 DeleteObject(hRgn);
1081 /* map regions to the parent client area */
1083 OffsetRgn(dirtyRgn, Wnd->rectWindow.left, Wnd->rectWindow.top);
1084 OffsetRgn(oldVisRgn, lpOldWndRect->left, lpOldWndRect->top);
1086 /* compute invalidated region outside Wnd - (in client coordinates of the parent window) */
1088 other = CombineRgn(dirtyRgn, oldVisRgn, dirtyRgn, RGN_DIFF);
1090 /* map visible region to the Wnd client area */
1092 OffsetRgn( newVisRgn, Wnd->rectWindow.left - Wnd->rectClient.left,
1093 Wnd->rectWindow.top - Wnd->rectClient.top );
1095 /* substract previously invalidated region from the Wnd visible region */
1097 my = (Wnd->hrgnUpdate > 1)? CombineRgn( newVisRgn, newVisRgn, Wnd->hrgnUpdate, RGN_DIFF)
1098 : COMPLEXREGION;
1100 if( bNoCopy ) /* invalidate Wnd visible region */
1102 if (my != NULLREGION) RedrawWindow( Wnd->hwndSelf, NULL, newVisRgn, RDW_INVALIDATE |
1103 RDW_FRAME | RDW_ALLCHILDREN | RDW_ERASE );
1105 else /* bitblt old client area */
1107 HDC hDC;
1108 int update;
1109 HRGN updateRgn;
1111 /* client rect */
1113 updateRgn = CreateRectRgn( 0,0, Wnd->rectClient.right - Wnd->rectClient.left,
1114 Wnd->rectClient.bottom - Wnd->rectClient.top );
1116 /* clip visible region with client rect */
1118 my = CombineRgn( newVisRgn, newVisRgn, updateRgn, RGN_AND );
1120 /* substract result from client rect to get region that won't be copied */
1122 update = CombineRgn( updateRgn, updateRgn, newVisRgn, RGN_DIFF );
1124 /* Blt valid bits using parent window DC */
1126 if( my != NULLREGION )
1128 int xfrom = lpOldClientRect->left;
1129 int yfrom = lpOldClientRect->top;
1130 int xto = Wnd->rectClient.left;
1131 int yto = Wnd->rectClient.top;
1133 /* check if we can skip copying */
1135 if( xfrom != xto || yfrom != yto )
1137 /* compute clipping region in parent client coordinates */
1139 OffsetRgn( newVisRgn, Wnd->rectClient.left, Wnd->rectClient.top);
1140 CombineRgn( oldVisRgn, oldVisRgn, newVisRgn, RGN_OR );
1142 hDC = GetDCEx( Wnd->parent->hwndSelf, oldVisRgn, DCX_INTERSECTRGN | DCX_CACHE | DCX_CLIPSIBLINGS);
1144 BitBlt(hDC, xto, yto, lpOldClientRect->right - lpOldClientRect->left + 1,
1145 lpOldClientRect->bottom - lpOldClientRect->top + 1,
1146 hDC, xfrom, yfrom, SRCCOPY );
1148 ReleaseDC( Wnd->parent->hwndSelf, hDC);
1152 if( update != NULLREGION )
1153 RedrawWindow( Wnd->hwndSelf, NULL, updateRgn, RDW_INVALIDATE |
1154 RDW_FRAME | RDW_ALLCHILDREN | RDW_ERASE );
1155 DeleteObject( updateRgn );
1158 /* erase uncovered areas */
1160 if( other != NULLREGION )
1161 RedrawWindow( Wnd->parent->hwndSelf, NULL, dirtyRgn,
1162 RDW_INVALIDATE | RDW_ALLCHILDREN | RDW_ERASE );
1164 DeleteObject(dirtyRgn);
1165 DeleteObject(newVisRgn);
1168 /***********************************************************************
1169 * WINPOS_SetXWindowPos
1171 * SetWindowPos() for an X window. Used by the real SetWindowPos().
1173 static void WINPOS_SetXWindowPos( WINDOWPOS *winpos )
1175 XWindowChanges winChanges;
1176 int changeMask = 0;
1177 WND *wndPtr = WIN_FindWndPtr( winpos->hwnd );
1179 if (!(winpos->flags & SWP_NOSIZE))
1181 winChanges.width = winpos->cx;
1182 winChanges.height = winpos->cy;
1183 changeMask |= CWWidth | CWHeight;
1185 if (!(winpos->flags & SWP_NOMOVE))
1187 winChanges.x = winpos->x;
1188 winChanges.y = winpos->y;
1189 changeMask |= CWX | CWY;
1191 if (!(winpos->flags & SWP_NOZORDER))
1193 if (winpos->hwndInsertAfter == HWND_TOP) winChanges.stack_mode = Above;
1194 else winChanges.stack_mode = Below;
1195 if ((winpos->hwndInsertAfter != HWND_TOP) &&
1196 (winpos->hwndInsertAfter != HWND_BOTTOM))
1198 WND * insertPtr = WIN_FindWndPtr( winpos->hwndInsertAfter );
1199 winChanges.sibling = insertPtr->window;
1200 changeMask |= CWSibling;
1202 changeMask |= CWStackMode;
1204 if (changeMask)
1205 XConfigureWindow( display, wndPtr->window, changeMask, &winChanges );
1209 /***********************************************************************
1210 * SetWindowPos (USER.232)
1212 BOOL SetWindowPos( HWND hwnd, HWND hwndInsertAfter, INT x, INT y,
1213 INT cx, INT cy, WORD flags )
1215 WINDOWPOS winpos;
1216 WND * wndPtr;
1217 RECT newWindowRect, newClientRect;
1218 HRGN visRgn = 0;
1219 int result = 0;
1221 dprintf_win(stddeb,"SetWindowPos: hwnd %04x, flags %08x\n", hwnd, flags);
1223 /* Check window handle */
1225 if (hwnd == GetDesktopWindow()) return FALSE;
1226 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return FALSE;
1228 /* Check for windows that may not be resized
1229 FIXME: this should be done only for Windows 3.0 programs */
1230 if (flags ==(SWP_SHOWWINDOW) || flags ==(SWP_HIDEWINDOW ) )
1231 flags |= SWP_NOSIZE | SWP_NOMOVE;
1233 /* Check dimensions */
1235 if (cx <= 0) cx = 1;
1236 if (cy <= 0) cy = 1;
1238 /* Check flags */
1240 if (hwnd == hwndActive) flags |= SWP_NOACTIVATE; /* Already active */
1241 if ((wndPtr->rectWindow.right - wndPtr->rectWindow.left == cx) &&
1242 (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top == cy))
1243 flags |= SWP_NOSIZE; /* Already the right size */
1244 if ((wndPtr->rectWindow.left == x) && (wndPtr->rectWindow.top == y))
1245 flags |= SWP_NOMOVE; /* Already the right position */
1247 /* Check hwndInsertAfter */
1249 if (!(flags & (SWP_NOZORDER | SWP_NOACTIVATE)))
1251 /* Ignore TOPMOST flags when activating a window */
1252 /* _and_ moving it in Z order. */
1253 if ((hwndInsertAfter == HWND_TOPMOST) ||
1254 (hwndInsertAfter == HWND_NOTOPMOST))
1255 hwndInsertAfter = HWND_TOP;
1257 /* TOPMOST not supported yet */
1258 if ((hwndInsertAfter == HWND_TOPMOST) ||
1259 (hwndInsertAfter == HWND_NOTOPMOST)) hwndInsertAfter = HWND_TOP;
1261 /* hwndInsertAfter must be a sibling of the window */
1262 if ((hwndInsertAfter != HWND_TOP) && (hwndInsertAfter != HWND_BOTTOM))
1264 WND* wnd = WIN_FindWndPtr(hwndInsertAfter);
1265 if( wnd->parent != wndPtr->parent ) return FALSE;
1266 if( wnd->next == wndPtr ) flags |= SWP_NOZORDER;
1268 else
1269 if (hwndInsertAfter == HWND_TOP)
1270 flags |= ( wndPtr->parent->child == wndPtr)? SWP_NOZORDER: 0;
1271 else /* HWND_BOTTOM */
1272 flags |= ( wndPtr->next )? 0: SWP_NOZORDER;
1274 /* Fill the WINDOWPOS structure */
1276 winpos.hwnd = hwnd;
1277 winpos.hwndInsertAfter = hwndInsertAfter;
1278 winpos.x = x;
1279 winpos.y = y;
1280 winpos.cx = cx;
1281 winpos.cy = cy;
1282 winpos.flags = flags;
1284 /* Send WM_WINDOWPOSCHANGING message */
1286 if (!(flags & SWP_NOSENDCHANGING))
1287 SendMessage( hwnd, WM_WINDOWPOSCHANGING, 0, (LPARAM)MAKE_SEGPTR(&winpos) );
1289 /* Calculate new position and size */
1291 newWindowRect = wndPtr->rectWindow;
1292 newClientRect = wndPtr->rectClient;
1294 if (!(winpos.flags & SWP_NOSIZE))
1296 newWindowRect.right = newWindowRect.left + winpos.cx;
1297 newWindowRect.bottom = newWindowRect.top + winpos.cy;
1299 if (!(winpos.flags & SWP_NOMOVE))
1301 newWindowRect.left = winpos.x;
1302 newWindowRect.top = winpos.y;
1303 newWindowRect.right += winpos.x - wndPtr->rectWindow.left;
1304 newWindowRect.bottom += winpos.y - wndPtr->rectWindow.top;
1306 OffsetRect(&newClientRect, winpos.x - wndPtr->rectWindow.left,
1307 winpos.y - wndPtr->rectWindow.top );
1310 winpos.flags |= SWP_NOCLIENTMOVE | SWP_NOCLIENTSIZE;
1312 /* Reposition window in Z order */
1314 if (!(winpos.flags & SWP_NOZORDER))
1316 /* reorder owned popups if hwnd is top-level window
1318 if( wndPtr->parent == WIN_GetDesktop() )
1319 hwndInsertAfter = WINPOS_ReorderOwnedPopups( hwndInsertAfter,
1320 wndPtr, flags );
1322 if (wndPtr->window)
1324 WIN_UnlinkWindow( winpos.hwnd );
1325 WIN_LinkWindow( winpos.hwnd, hwndInsertAfter );
1327 else WINPOS_MoveWindowZOrder( winpos.hwnd, hwndInsertAfter );
1330 if ( !wndPtr->window && !(flags & SWP_NOREDRAW) &&
1331 (!(flags & SWP_NOMOVE) || !(flags & SWP_NOSIZE) || (flags & SWP_FRAMECHANGED)) )
1332 visRgn = DCE_GetVisRgn(hwnd, DCX_WINDOW | DCX_CLIPSIBLINGS);
1335 /* Send WM_NCCALCSIZE message to get new client area */
1336 if( (flags & (SWP_FRAMECHANGED | SWP_NOSIZE)) != SWP_NOSIZE )
1338 result = WINPOS_SendNCCalcSize( winpos.hwnd, TRUE, &newWindowRect,
1339 &wndPtr->rectWindow, &wndPtr->rectClient,
1340 MAKE_SEGPTR(&winpos), &newClientRect );
1342 /* FIXME: WVR_ALIGNxxx */
1344 if( newClientRect.left != wndPtr->rectClient.left ||
1345 newClientRect.top != wndPtr->rectClient.top )
1346 winpos.flags &= ~SWP_NOCLIENTMOVE;
1348 if( (newClientRect.right - newClientRect.left !=
1349 wndPtr->rectClient.right - wndPtr->rectClient.left) ||
1350 (newClientRect.bottom - newClientRect.top !=
1351 wndPtr->rectClient.bottom - wndPtr->rectClient.top) )
1352 winpos.flags &= ~SWP_NOCLIENTSIZE;
1354 else
1355 if( !(flags & SWP_NOMOVE) && (newClientRect.left != wndPtr->rectClient.left ||
1356 newClientRect.top != wndPtr->rectClient.top) )
1357 winpos.flags &= ~SWP_NOCLIENTMOVE;
1359 /* Perform the moving and resizing */
1361 if (wndPtr->window)
1363 RECT oldWindowRect = wndPtr->rectWindow;
1364 RECT oldClientRect = wndPtr->rectClient;
1366 HWND bogusInsertAfter = winpos.hwndInsertAfter;
1368 winpos.hwndInsertAfter = hwndInsertAfter;
1369 WINPOS_SetXWindowPos( &winpos );
1371 wndPtr->rectWindow = newWindowRect;
1372 wndPtr->rectClient = newClientRect;
1373 winpos.hwndInsertAfter = bogusInsertAfter;
1375 /* FIXME: should do something like WINPOS_SizeMoveClean */
1377 if( (oldClientRect.left - oldWindowRect.left !=
1378 newClientRect.left - newWindowRect.left) ||
1379 (oldClientRect.top - oldWindowRect.top !=
1380 newClientRect.top - newWindowRect.top) )
1382 RedrawWindow(wndPtr->hwndSelf, NULL, 0, RDW_ALLCHILDREN | RDW_FRAME | RDW_ERASE);
1383 else
1384 if( winpos.flags & SWP_FRAMECHANGED )
1386 WORD wErase = 0;
1387 RECT rect;
1389 if( oldClientRect.right > newClientRect.right )
1391 rect.left = newClientRect.right; rect.top = newClientRect.top;
1392 rect.right = oldClientRect.right; rect.bottom = newClientRect.bottom;
1393 wErase = 1;
1394 RedrawWindow(wndPtr->hwndSelf, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);
1396 if( oldClientRect.bottom > newClientRect.bottom )
1398 rect.left = newClientRect.left; rect.top = newClientRect.bottom;
1399 rect.right = (wErase)?oldClientRect.right:newClientRect.right;
1400 rect.bottom = oldClientRect.bottom;
1401 wErase = 1;
1402 RedrawWindow(wndPtr->hwndSelf, &rect, 0, RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);
1405 if( !wErase ) wndPtr->flags |= WIN_NEEDS_NCPAINT;
1408 else
1410 RECT oldWindowRect = wndPtr->rectWindow;
1411 RECT oldClientRect = wndPtr->rectClient;
1413 wndPtr->rectWindow = newWindowRect;
1414 wndPtr->rectClient = newClientRect;
1416 if( !(flags & SWP_NOREDRAW) )
1418 BOOL bNoCopy = (flags & SWP_NOCOPYBITS) ||
1419 (result >= WVR_HREDRAW && result < WVR_VALIDRECTS);
1421 if( (winpos.flags & SWP_NOPOSCHANGE) != SWP_NOPOSCHANGE )
1423 /* optimize cleanup by BitBlt'ing where possible */
1425 WINPOS_SizeMoveClean(wndPtr, visRgn, &oldWindowRect, &oldClientRect, bNoCopy);
1426 DeleteObject(visRgn);
1428 else
1429 if( winpos.flags & SWP_FRAMECHANGED )
1430 RedrawWindow( winpos.hwnd, NULL, 0, RDW_NOCHILDREN | RDW_FRAME );
1433 DeleteObject(visRgn);
1436 if (flags & SWP_SHOWWINDOW)
1438 wndPtr->dwStyle |= WS_VISIBLE;
1439 if (wndPtr->window)
1441 XMapWindow( display, wndPtr->window );
1443 else
1445 if (!(flags & SWP_NOREDRAW))
1446 RedrawWindow( winpos.hwnd, NULL, 0,
1447 RDW_INVALIDATE | RDW_ALLCHILDREN |
1448 RDW_FRAME | RDW_ERASE );
1451 else if (flags & SWP_HIDEWINDOW)
1453 wndPtr->dwStyle &= ~WS_VISIBLE;
1454 if (wndPtr->window)
1456 XUnmapWindow( display, wndPtr->window );
1458 else
1460 if (!(flags & SWP_NOREDRAW))
1461 RedrawWindow( wndPtr->parent->hwndSelf, &wndPtr->rectWindow, 0,
1462 RDW_INVALIDATE | RDW_ALLCHILDREN | RDW_ERASE );
1465 if ((winpos.hwnd == GetFocus()) || IsChild(winpos.hwnd, GetFocus()))
1466 SetFocus( GetParent(winpos.hwnd) ); /* Revert focus to parent */
1468 if (winpos.hwnd == hwndActive)
1470 /* Activate previously active window if possible */
1471 HWND newActive = hwndPrevActive;
1472 if (!IsWindow(newActive) || (newActive == winpos.hwnd))
1474 newActive = GetTopWindow( GetDesktopWindow() );
1475 if (newActive == winpos.hwnd)
1476 newActive = wndPtr->next ? wndPtr->next->hwndSelf : 0;
1478 WINPOS_ChangeActiveWindow( newActive, FALSE );
1482 /* Activate the window */
1484 if (!(flags & SWP_NOACTIVATE))
1485 WINPOS_ChangeActiveWindow( winpos.hwnd, FALSE );
1487 /* Repaint the window */
1489 if (wndPtr->window) MSG_Synchronize(); /* Wait for all expose events */
1491 EVENT_DummyMotionNotify(); /* Simulate a mouse event to set the cursor */
1493 if (!(flags & SWP_DEFERERASE))
1494 RedrawWindow( wndPtr->parent->hwndSelf, NULL, 0,
1495 RDW_ALLCHILDREN | RDW_ERASENOW );
1497 /* And last, send the WM_WINDOWPOSCHANGED message */
1499 if (!(winpos.flags & SWP_NOSENDCHANGING))
1500 SendMessage( winpos.hwnd, WM_WINDOWPOSCHANGED,
1501 0, (LPARAM)MAKE_SEGPTR(&winpos) );
1503 return TRUE;
1507 /***********************************************************************
1508 * BeginDeferWindowPos (USER.259)
1510 HDWP BeginDeferWindowPos( INT count )
1512 HDWP handle;
1513 DWP *pDWP;
1515 if (count <= 0) return 0;
1516 handle = USER_HEAP_ALLOC( sizeof(DWP) + (count-1)*sizeof(WINDOWPOS) );
1517 if (!handle) return 0;
1518 pDWP = (DWP *) USER_HEAP_LIN_ADDR( handle );
1519 pDWP->actualCount = 0;
1520 pDWP->suggestedCount = count;
1521 pDWP->valid = TRUE;
1522 pDWP->wMagic = DWP_MAGIC;
1523 pDWP->hwndParent = 0;
1524 return handle;
1528 /***********************************************************************
1529 * DeferWindowPos (USER.260)
1531 HDWP DeferWindowPos( HDWP hdwp, HWND hwnd, HWND hwndAfter, INT x, INT y,
1532 INT cx, INT cy, UINT flags )
1534 DWP *pDWP;
1535 int i;
1536 HDWP newhdwp = hdwp;
1537 HWND parent;
1539 pDWP = (DWP *) USER_HEAP_LIN_ADDR( hdwp );
1540 if (!pDWP) return 0;
1541 if (hwnd == GetDesktopWindow()) return 0;
1543 /* All the windows of a DeferWindowPos() must have the same parent */
1545 parent = WIN_FindWndPtr( hwnd )->parent->hwndSelf;
1546 if (pDWP->actualCount == 0) pDWP->hwndParent = parent;
1547 else if (parent != pDWP->hwndParent)
1549 USER_HEAP_FREE( hdwp );
1550 return 0;
1553 for (i = 0; i < pDWP->actualCount; i++)
1555 if (pDWP->winPos[i].hwnd == hwnd)
1557 /* Merge with the other changes */
1558 if (!(flags & SWP_NOZORDER))
1560 pDWP->winPos[i].hwndInsertAfter = hwndAfter;
1562 if (!(flags & SWP_NOMOVE))
1564 pDWP->winPos[i].x = x;
1565 pDWP->winPos[i].y = y;
1567 if (!(flags & SWP_NOSIZE))
1569 pDWP->winPos[i].cx = cx;
1570 pDWP->winPos[i].cy = cy;
1572 pDWP->winPos[i].flags &= flags & (SWP_NOSIZE | SWP_NOMOVE |
1573 SWP_NOZORDER | SWP_NOREDRAW |
1574 SWP_NOACTIVATE | SWP_NOCOPYBITS |
1575 SWP_NOOWNERZORDER);
1576 pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
1577 SWP_FRAMECHANGED);
1578 return hdwp;
1581 if (pDWP->actualCount >= pDWP->suggestedCount)
1583 newhdwp = USER_HEAP_REALLOC( hdwp,
1584 sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS) );
1585 if (!newhdwp) return 0;
1586 pDWP = (DWP *) USER_HEAP_LIN_ADDR( newhdwp );
1587 pDWP->suggestedCount++;
1589 pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
1590 pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
1591 pDWP->winPos[pDWP->actualCount].x = x;
1592 pDWP->winPos[pDWP->actualCount].y = y;
1593 pDWP->winPos[pDWP->actualCount].cx = cx;
1594 pDWP->winPos[pDWP->actualCount].cy = cy;
1595 pDWP->winPos[pDWP->actualCount].flags = flags;
1596 pDWP->actualCount++;
1597 return newhdwp;
1601 /***********************************************************************
1602 * EndDeferWindowPos (USER.261)
1604 BOOL EndDeferWindowPos( HDWP hdwp )
1606 DWP *pDWP;
1607 WINDOWPOS *winpos;
1608 BOOL res = TRUE;
1609 int i;
1611 pDWP = (DWP *) USER_HEAP_LIN_ADDR( hdwp );
1612 if (!pDWP) return FALSE;
1613 for (i = 0, winpos = pDWP->winPos; i < pDWP->actualCount; i++, winpos++)
1615 if (!(res = SetWindowPos( winpos->hwnd, winpos->hwndInsertAfter,
1616 winpos->x, winpos->y, winpos->cx, winpos->cy,
1617 winpos->flags ))) break;
1619 USER_HEAP_FREE( hdwp );
1620 return res;
1624 /***********************************************************************
1625 * TileChildWindows (USER.199)
1627 void TileChildWindows( HWND parent, WORD action )
1629 printf("STUB TileChildWindows(%04x, %d)\n", parent, action);
1632 /***********************************************************************
1633 * CascageChildWindows (USER.198)
1635 void CascadeChildWindows( HWND parent, WORD action )
1637 printf("STUB CascadeChildWindows(%04x, %d)\n", parent, action);