2 * Window position related functions.
4 * Copyright 1993, 1994, 1995 Alexandre Julliard
5 * 1995,1996 Alex Korobka
8 #include "sysmetrics.h"
16 #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();
31 extern BOOL
DCE_InvalidateDCE(WND
*, RECT16
* );
33 /* ----- internal variables ----- */
35 static HWND hwndActive
= 0; /* Currently active window */
36 static HWND hwndPrevActive
= 0; /* Previously active window */
38 /***********************************************************************
41 * Find a suitable place for an iconic window.
42 * The new position is stored into wndPtr->ptIconPos.
44 void WINPOS_FindIconPos( HWND hwnd
)
47 short x
, y
, xspacing
, yspacing
;
48 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
50 if (!wndPtr
|| !wndPtr
->parent
) return;
51 GetClientRect16( wndPtr
->parent
->hwndSelf
, &rectParent
);
52 if ((wndPtr
->ptIconPos
.x
>= rectParent
.left
) &&
53 (wndPtr
->ptIconPos
.x
+ SYSMETRICS_CXICON
< rectParent
.right
) &&
54 (wndPtr
->ptIconPos
.y
>= rectParent
.top
) &&
55 (wndPtr
->ptIconPos
.y
+ SYSMETRICS_CYICON
< rectParent
.bottom
))
56 return; /* The icon already has a suitable position */
58 xspacing
= yspacing
= 70; /* FIXME: This should come from WIN.INI */
59 y
= rectParent
.bottom
;
62 for (x
= rectParent
.left
; x
<=rectParent
.right
-xspacing
; x
+= xspacing
)
64 /* Check if another icon already occupies this spot */
65 WND
*childPtr
= wndPtr
->parent
->child
;
68 if ((childPtr
->dwStyle
& WS_MINIMIZE
) && (childPtr
!= wndPtr
))
70 if ((childPtr
->rectWindow
.left
< x
+ xspacing
) &&
71 (childPtr
->rectWindow
.right
>= x
) &&
72 (childPtr
->rectWindow
.top
<= y
) &&
73 (childPtr
->rectWindow
.bottom
> y
- yspacing
))
74 break; /* There's a window in there */
76 childPtr
= childPtr
->next
;
80 /* No window was found, so it's OK for us */
81 wndPtr
->ptIconPos
.x
= x
+ (xspacing
- SYSMETRICS_CXICON
) / 2;
82 wndPtr
->ptIconPos
.y
= y
- (yspacing
+ SYSMETRICS_CYICON
) / 2;
91 /***********************************************************************
92 * ArrangeIconicWindows (USER.170)
94 UINT
ArrangeIconicWindows( HWND parent
)
98 INT x
, y
, xspacing
, yspacing
;
100 GetClientRect16( parent
, &rectParent
);
102 y
= rectParent
.bottom
;
103 xspacing
= yspacing
= 70; /* FIXME: This should come from WIN.INI */
104 hwndChild
= GetWindow( parent
, GW_CHILD
);
107 if (IsIconic( hwndChild
))
109 SetWindowPos( hwndChild
, 0, x
+ (xspacing
- SYSMETRICS_CXICON
) / 2,
110 y
- (yspacing
+ SYSMETRICS_CYICON
) / 2, 0, 0,
111 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
112 if (x
<= rectParent
.right
- xspacing
) x
+= xspacing
;
119 hwndChild
= GetWindow( hwndChild
, GW_HWNDNEXT
);
125 /***********************************************************************
126 * GetWindowRect16 (USER.32)
128 void GetWindowRect16( HWND16 hwnd
, LPRECT16 rect
)
130 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
133 *rect
= wndPtr
->rectWindow
;
134 if (wndPtr
->dwStyle
& WS_CHILD
)
135 MapWindowPoints16( wndPtr
->parent
->hwndSelf
, 0, (POINT16
*)rect
, 2 );
139 /***********************************************************************
140 * GetWindowRect32 (USER.32)
142 void GetWindowRect32( HWND32 hwnd
, LPRECT32 rect
)
144 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
147 CONV_RECT16TO32( &wndPtr
->rectWindow
, rect
);
148 if (wndPtr
->dwStyle
& WS_CHILD
)
149 MapWindowPoints32( wndPtr
->parent
->hwndSelf
, 0, (POINT32
*)rect
, 2 );
153 /***********************************************************************
154 * GetClientRect16 (USER.33)
156 void GetClientRect16( HWND16 hwnd
, LPRECT16 rect
)
158 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
160 rect
->left
= rect
->top
= rect
->right
= rect
->bottom
= 0;
163 rect
->right
= wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
;
164 rect
->bottom
= wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
;
169 /***********************************************************************
170 * GetClientRect32 (USER32.219)
172 void GetClientRect32( HWND32 hwnd
, LPRECT32 rect
)
174 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
176 rect
->left
= rect
->top
= rect
->right
= rect
->bottom
= 0;
179 rect
->right
= wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
;
180 rect
->bottom
= wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
;
185 /*******************************************************************
186 * ClientToScreen16 (USER.28)
188 BOOL16
ClientToScreen16( HWND16 hwnd
, LPPOINT16 lppnt
)
190 MapWindowPoints16( hwnd
, 0, lppnt
, 1 );
195 /*******************************************************************
196 * ClientToScreen32 (USER32.51)
198 BOOL32
ClientToScreen32( HWND32 hwnd
, LPPOINT32 lppnt
)
200 MapWindowPoints32( hwnd
, 0, lppnt
, 1 );
205 /*******************************************************************
206 * ScreenToClient16 (USER.29)
208 void ScreenToClient16( HWND16 hwnd
, LPPOINT16 lppnt
)
210 MapWindowPoints16( 0, hwnd
, lppnt
, 1 );
214 /*******************************************************************
215 * ScreenToClient32 (USER32.446)
217 void ScreenToClient32( HWND32 hwnd
, LPPOINT32 lppnt
)
219 MapWindowPoints32( 0, hwnd
, lppnt
, 1 );
223 /***********************************************************************
224 * WINPOS_WindowFromPoint
226 * Find the window and hittest for a given point.
228 INT16
WINPOS_WindowFromPoint( POINT16 pt
, WND
**ppWnd
)
231 INT16 hittest
= HTERROR
;
237 wndPtr
= WIN_GetDesktop()->child
;
242 /* If point is in window, and window is visible, and it */
243 /* is enabled (or it's a top-level window), then explore */
244 /* its children. Otherwise, go to the next window. */
246 if ((wndPtr
->dwStyle
& WS_VISIBLE
) &&
247 (!(wndPtr
->dwStyle
& WS_DISABLED
) ||
248 ((wndPtr
->dwStyle
& (WS_POPUP
| WS_CHILD
)) != WS_CHILD
)) &&
249 (x
>= wndPtr
->rectWindow
.left
) &&
250 (x
< wndPtr
->rectWindow
.right
) &&
251 (y
>= wndPtr
->rectWindow
.top
) &&
252 (y
< wndPtr
->rectWindow
.bottom
))
254 *ppWnd
= wndPtr
; /* Got a suitable window */
256 /* If window is minimized or disabled, return at once */
257 if (wndPtr
->dwStyle
& WS_MINIMIZE
) return HTCAPTION
;
258 if (wndPtr
->dwStyle
& WS_DISABLED
) return HTERROR
;
260 /* If point is not in client area, ignore the children */
261 if ((x
< wndPtr
->rectClient
.left
) ||
262 (x
>= wndPtr
->rectClient
.right
) ||
263 (y
< wndPtr
->rectClient
.top
) ||
264 (y
>= wndPtr
->rectClient
.bottom
)) break;
266 x
-= wndPtr
->rectClient
.left
;
267 y
-= wndPtr
->rectClient
.top
;
268 wndPtr
= wndPtr
->child
;
270 else wndPtr
= wndPtr
->next
;
273 /* If nothing found, return the desktop window */
276 *ppWnd
= WIN_GetDesktop();
280 /* Send the WM_NCHITTEST message (only if to the same task) */
281 if ((*ppWnd
)->hmemTaskQ
!= GetTaskQueue(0)) return HTCLIENT
;
282 hittest
= (INT
)SendMessage16( (*ppWnd
)->hwndSelf
, WM_NCHITTEST
, 0,
283 MAKELONG( pt
.x
, pt
.y
) );
284 if (hittest
!= HTTRANSPARENT
) return hittest
; /* Found the window */
286 /* If no children found in last search, make point relative to parent*/
289 x
+= (*ppWnd
)->rectClient
.left
;
290 y
+= (*ppWnd
)->rectClient
.top
;
293 /* Restart the search from the next sibling */
294 wndPtr
= (*ppWnd
)->next
;
295 *ppWnd
= (*ppWnd
)->parent
;
300 /*******************************************************************
301 * WindowFromPoint16 (USER.30)
303 HWND16
WindowFromPoint16( POINT16 pt
)
306 WINPOS_WindowFromPoint( pt
, &pWnd
);
307 return pWnd
->hwndSelf
;
311 /*******************************************************************
312 * WindowFromPoint32 (USER32.581)
314 HWND32
WindowFromPoint32( POINT32 pt
)
318 CONV_POINT32TO16( &pt
, &pt16
);
319 WINPOS_WindowFromPoint( pt16
, &pWnd
);
320 return (HWND32
)pWnd
->hwndSelf
;
324 /*******************************************************************
325 * ChildWindowFromPoint16 (USER.191)
327 HWND16
ChildWindowFromPoint16( HWND16 hwndParent
, POINT16 pt
)
329 /* pt is in the client coordinates */
331 WND
* wnd
= WIN_FindWndPtr(hwndParent
);
336 /* get client rect fast */
337 rect
.top
= rect
.left
= 0;
338 rect
.right
= wnd
->rectClient
.right
- wnd
->rectClient
.left
;
339 rect
.bottom
= wnd
->rectClient
.bottom
- wnd
->rectClient
.top
;
341 if (!PtInRect16( &rect
, pt
)) return 0;
346 if (PtInRect16( &wnd
->rectWindow
, pt
)) return wnd
->hwndSelf
;
353 /*******************************************************************
354 * ChildWindowFromPoint32 (USER32.)
356 HWND32
ChildWindowFromPoint32( HWND32 hwndParent
, POINT32 pt
)
359 CONV_POINT32TO16( &pt
, &pt16
);
360 return (HWND32
)ChildWindowFromPoint16( hwndParent
, pt16
);
364 /*******************************************************************
365 * WINPOS_GetWinOffset
367 * Calculate the offset between the origin of the two windows. Used
368 * to implement MapWindowPoints.
370 static void WINPOS_GetWinOffset( HWND32 hwndFrom
, HWND32 hwndTo
,
375 offset
->x
= offset
->y
= 0;
376 if (hwndFrom
== hwndTo
) return;
378 /* Translate source window origin to screen coords */
381 if (!(wndPtr
= WIN_FindWndPtr( hwndFrom
)))
383 fprintf(stderr
,"MapWindowPoints: bad hwndFrom = %04x\n",hwndFrom
);
386 while (wndPtr
->parent
)
388 offset
->x
+= wndPtr
->rectClient
.left
;
389 offset
->y
+= wndPtr
->rectClient
.top
;
390 wndPtr
= wndPtr
->parent
;
394 /* Translate origin to destination window coords */
397 if (!(wndPtr
= WIN_FindWndPtr( hwndTo
)))
399 fprintf(stderr
,"MapWindowPoints: bad hwndTo = %04x\n", hwndTo
);
402 while (wndPtr
->parent
)
404 offset
->x
-= wndPtr
->rectClient
.left
;
405 offset
->y
-= wndPtr
->rectClient
.top
;
406 wndPtr
= wndPtr
->parent
;
412 /*******************************************************************
413 * MapWindowPoints16 (USER.258)
415 void MapWindowPoints16( HWND16 hwndFrom
, HWND16 hwndTo
,
416 LPPOINT16 lppt
, UINT16 count
)
420 WINPOS_GetWinOffset( hwndFrom
, hwndTo
, &offset
);
430 /*******************************************************************
431 * MapWindowPoints32 (USER32.385)
433 void MapWindowPoints32( HWND32 hwndFrom
, HWND32 hwndTo
,
434 LPPOINT32 lppt
, UINT32 count
)
438 WINPOS_GetWinOffset( hwndFrom
, hwndTo
, &offset
);
448 /***********************************************************************
451 BOOL
IsIconic(HWND hWnd
)
453 WND
* wndPtr
= WIN_FindWndPtr(hWnd
);
454 if (wndPtr
== NULL
) return FALSE
;
455 return (wndPtr
->dwStyle
& WS_MINIMIZE
) != 0;
459 /***********************************************************************
460 * IsZoomed (USER.272)
462 BOOL
IsZoomed(HWND hWnd
)
464 WND
* wndPtr
= WIN_FindWndPtr(hWnd
);
465 if (wndPtr
== NULL
) return FALSE
;
466 return (wndPtr
->dwStyle
& WS_MAXIMIZE
) != 0;
470 /*******************************************************************
471 * GetActiveWindow (USER.60)
473 HWND
GetActiveWindow()
479 /*******************************************************************
480 * SetActiveWindow (USER.59)
482 HWND
SetActiveWindow( HWND hwnd
)
484 HWND prev
= hwndActive
;
485 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
487 if (!wndPtr
|| (wndPtr
->dwStyle
& WS_DISABLED
) ||
488 !(wndPtr
->dwStyle
& WS_VISIBLE
)) return 0;
490 WINPOS_SetActiveWindow( hwnd
, 0, 0 );
495 /***********************************************************************
496 * BringWindowToTop (USER.45)
498 BOOL
BringWindowToTop( HWND hwnd
)
500 return SetWindowPos( hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
);
504 /***********************************************************************
505 * MoveWindow (USER.56)
507 BOOL
MoveWindow( HWND hwnd
, short x
, short y
, short cx
, short cy
, BOOL repaint
)
509 int flags
= SWP_NOZORDER
| SWP_NOACTIVATE
;
510 if (!repaint
) flags
|= SWP_NOREDRAW
;
511 dprintf_win(stddeb
, "MoveWindow: %04x %d,%d %dx%d %d\n",
512 hwnd
, x
, y
, cx
, cy
, repaint
);
513 return SetWindowPos( hwnd
, 0, x
, y
, cx
, cy
, flags
);
517 /***********************************************************************
518 * ShowWindow (USER.42)
520 BOOL
ShowWindow( HWND hwnd
, int cmd
)
522 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
526 short x
= 0, y
= 0, cx
= 0, cy
= 0;
528 if (!wndPtr
) return FALSE
;
530 dprintf_win(stddeb
,"ShowWindow: hwnd=%04x, cmd=%d\n", hwnd
, cmd
);
532 wasVisible
= (wndPtr
->dwStyle
& WS_VISIBLE
) != 0;
537 if (!wasVisible
) return FALSE
;
538 swpflags
|= SWP_HIDEWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
|
539 SWP_NOACTIVATE
| SWP_NOZORDER
;
542 case SW_SHOWMINNOACTIVE
:
543 swpflags
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
545 case SW_SHOWMINIMIZED
:
546 swpflags
|= SWP_SHOWWINDOW
;
549 swpflags
|= SWP_FRAMECHANGED
;
550 if (!(wndPtr
->dwStyle
& WS_MINIMIZE
))
552 if (wndPtr
->dwStyle
& WS_MAXIMIZE
)
554 wndPtr
->flags
|= WIN_RESTORE_MAX
;
555 wndPtr
->dwStyle
&= ~WS_MAXIMIZE
;
559 wndPtr
->flags
&= ~WIN_RESTORE_MAX
;
560 wndPtr
->rectNormal
= wndPtr
->rectWindow
;
562 wndPtr
->dwStyle
|= WS_MINIMIZE
;
563 WINPOS_FindIconPos( hwnd
);
564 x
= wndPtr
->ptIconPos
.x
;
565 y
= wndPtr
->ptIconPos
.y
;
566 cx
= SYSMETRICS_CXICON
;
567 cy
= SYSMETRICS_CYICON
;
569 else swpflags
|= SWP_NOSIZE
| SWP_NOMOVE
;
572 case SW_SHOWMAXIMIZED
: /* same as SW_MAXIMIZE: */
573 swpflags
|= SWP_SHOWWINDOW
| SWP_FRAMECHANGED
;
574 if (!(wndPtr
->dwStyle
& WS_MAXIMIZE
))
576 /* Store the current position and find the maximized size */
577 if (!(wndPtr
->dwStyle
& WS_MINIMIZE
))
578 wndPtr
->rectNormal
= wndPtr
->rectWindow
;
580 NC_GetMinMaxInfo( hwnd
, &maxSize
,
581 &wndPtr
->ptMaxPos
, NULL
, NULL
);
582 x
= wndPtr
->ptMaxPos
.x
;
583 y
= wndPtr
->ptMaxPos
.y
;
585 if( wndPtr
->dwStyle
& WS_MINIMIZE
)
586 if( !SendMessage16( hwnd
, WM_QUERYOPEN
, 0, 0L ) )
588 swpflags
|= SWP_NOSIZE
;
594 wndPtr
->dwStyle
&= ~WS_MINIMIZE
;
595 wndPtr
->dwStyle
|= WS_MAXIMIZE
;
597 else swpflags
|= SWP_NOSIZE
| SWP_NOMOVE
;
601 swpflags
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
604 swpflags
|= SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
607 case SW_SHOWNOACTIVATE
:
608 swpflags
|= SWP_NOZORDER
;
609 if (GetActiveWindow()) swpflags
|= SWP_NOACTIVATE
;
611 case SW_SHOWNORMAL
: /* same as SW_NORMAL: */
612 case SW_SHOWDEFAULT
: /* FIXME: should have its own handler */
614 swpflags
|= SWP_SHOWWINDOW
| SWP_FRAMECHANGED
;
616 if (wndPtr
->dwStyle
& WS_MINIMIZE
)
618 if( !SendMessage16( hwnd
, WM_QUERYOPEN
, 0, 0L) )
620 swpflags
|= SWP_NOSIZE
;
623 wndPtr
->ptIconPos
.x
= wndPtr
->rectWindow
.left
;
624 wndPtr
->ptIconPos
.y
= wndPtr
->rectWindow
.top
;
625 wndPtr
->dwStyle
&= ~WS_MINIMIZE
;
626 if (wndPtr
->flags
& WIN_RESTORE_MAX
)
628 /* Restore to maximized position */
629 NC_GetMinMaxInfo( hwnd
, &maxSize
, &wndPtr
->ptMaxPos
,
631 x
= wndPtr
->ptMaxPos
.x
;
632 y
= wndPtr
->ptMaxPos
.y
;
635 wndPtr
->dwStyle
|= WS_MAXIMIZE
;
637 else /* Restore to normal position */
639 x
= wndPtr
->rectNormal
.left
;
640 y
= wndPtr
->rectNormal
.top
;
641 cx
= wndPtr
->rectNormal
.right
- wndPtr
->rectNormal
.left
;
642 cy
= wndPtr
->rectNormal
.bottom
- wndPtr
->rectNormal
.top
;
645 else if (wndPtr
->dwStyle
& WS_MAXIMIZE
)
647 wndPtr
->ptMaxPos
.x
= wndPtr
->rectWindow
.left
;
648 wndPtr
->ptMaxPos
.y
= wndPtr
->rectWindow
.top
;
649 wndPtr
->dwStyle
&= ~WS_MAXIMIZE
;
650 x
= wndPtr
->rectNormal
.left
;
651 y
= wndPtr
->rectNormal
.top
;
652 cx
= wndPtr
->rectNormal
.right
- wndPtr
->rectNormal
.left
;
653 cy
= wndPtr
->rectNormal
.bottom
- wndPtr
->rectNormal
.top
;
655 else swpflags
|= SWP_NOSIZE
| SWP_NOMOVE
;
659 SendMessage16( hwnd
, WM_SHOWWINDOW
, (cmd
!= SW_HIDE
), 0 );
660 SetWindowPos( hwnd
, HWND_TOP
, x
, y
, cx
, cy
, swpflags
);
662 if (wndPtr
->flags
& WIN_NEED_SIZE
)
664 int wParam
= SIZE_RESTORED
;
666 wndPtr
->flags
&= ~WIN_NEED_SIZE
;
667 if (wndPtr
->dwStyle
& WS_MAXIMIZE
) wParam
= SIZE_MAXIMIZED
;
668 else if (wndPtr
->dwStyle
& WS_MINIMIZE
) wParam
= SIZE_MINIMIZED
;
669 SendMessage16( hwnd
, WM_SIZE
, wParam
,
670 MAKELONG(wndPtr
->rectClient
.right
-wndPtr
->rectClient
.left
,
671 wndPtr
->rectClient
.bottom
-wndPtr
->rectClient
.top
));
672 SendMessage16( hwnd
, WM_MOVE
, 0,
673 MAKELONG(wndPtr
->rectClient
.left
, wndPtr
->rectClient
.top
) );
676 if (hwnd
== GetFocus())
678 SetFocus( (wndPtr
->dwStyle
& WS_CHILD
)? wndPtr
->parent
->hwndSelf
: 0 );
679 if (hwnd
== CARET_GetHwnd()) DestroyCaret();
686 /***********************************************************************
687 * GetInternalWindowPos16 (USER.460)
689 UINT16
GetInternalWindowPos16( HWND16 hwnd
, LPRECT16 rectWnd
, LPPOINT16 ptIcon
)
691 WINDOWPLACEMENT16 wndpl
;
692 if (!GetWindowPlacement16( hwnd
, &wndpl
)) return 0;
693 if (rectWnd
) *rectWnd
= wndpl
.rcNormalPosition
;
694 if (ptIcon
) *ptIcon
= wndpl
.ptMinPosition
;
695 return wndpl
.showCmd
;
699 /***********************************************************************
700 * GetInternalWindowPos32 (USER32.244)
702 UINT32
GetInternalWindowPos32( HWND32 hwnd
, LPRECT32 rectWnd
, LPPOINT32 ptIcon
)
704 WINDOWPLACEMENT32 wndpl
;
705 if (!GetWindowPlacement32( hwnd
, &wndpl
)) return 0;
706 if (rectWnd
) *rectWnd
= wndpl
.rcNormalPosition
;
707 if (ptIcon
) *ptIcon
= wndpl
.ptMinPosition
;
708 return wndpl
.showCmd
;
712 /***********************************************************************
713 * SetInternalWindowPos16 (USER.461)
715 void SetInternalWindowPos16( HWND16 hwnd
, UINT16 showCmd
,
716 LPRECT16 rect
, LPPOINT16 pt
)
718 WINDOWPLACEMENT16 wndpl
;
719 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
721 wndpl
.length
= sizeof(wndpl
);
722 wndpl
.flags
= (pt
!= NULL
) ? WPF_SETMINPOSITION
: 0;
723 wndpl
.showCmd
= showCmd
;
724 if (pt
) wndpl
.ptMinPosition
= *pt
;
725 wndpl
.rcNormalPosition
= (rect
!= NULL
) ? *rect
: wndPtr
->rectNormal
;
726 wndpl
.ptMaxPosition
= wndPtr
->ptMaxPos
;
727 SetWindowPlacement16( hwnd
, &wndpl
);
731 /***********************************************************************
732 * SetInternalWindowPos32 (USER32.482)
734 void SetInternalWindowPos32( HWND32 hwnd
, UINT32 showCmd
,
735 LPRECT32 rect
, LPPOINT32 pt
)
737 WINDOWPLACEMENT32 wndpl
;
738 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
740 wndpl
.length
= sizeof(wndpl
);
741 wndpl
.flags
= (pt
!= NULL
) ? WPF_SETMINPOSITION
: 0;
742 wndpl
.showCmd
= showCmd
;
743 if (pt
) wndpl
.ptMinPosition
= *pt
;
744 if (rect
) wndpl
.rcNormalPosition
= *rect
;
745 else CONV_RECT16TO32( &wndPtr
->rectNormal
, &wndpl
.rcNormalPosition
);
746 CONV_POINT16TO32( &wndPtr
->ptMaxPos
, &wndpl
.ptMaxPosition
);
747 SetWindowPlacement32( hwnd
, &wndpl
);
751 /***********************************************************************
752 * GetWindowPlacement16 (USER.370)
754 BOOL16
GetWindowPlacement16( HWND16 hwnd
, WINDOWPLACEMENT16
*wndpl
)
756 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
757 if (!wndPtr
) return FALSE
;
759 wndpl
->length
= sizeof(*wndpl
);
761 wndpl
->showCmd
= IsZoomed(hwnd
) ? SW_SHOWMAXIMIZED
:
762 (IsIconic(hwnd
) ? SW_SHOWMINIMIZED
: SW_SHOWNORMAL
);
763 wndpl
->ptMinPosition
= wndPtr
->ptIconPos
;
764 wndpl
->ptMaxPosition
= wndPtr
->ptMaxPos
;
765 wndpl
->rcNormalPosition
= wndPtr
->rectNormal
;
770 /***********************************************************************
771 * GetWindowPlacement32 (USER32.306)
773 BOOL32
GetWindowPlacement32( HWND32 hwnd
, WINDOWPLACEMENT32
*wndpl
)
775 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
776 if (!wndPtr
) return FALSE
;
778 wndpl
->length
= sizeof(*wndpl
);
780 wndpl
->showCmd
= IsZoomed(hwnd
) ? SW_SHOWMAXIMIZED
:
781 (IsIconic(hwnd
) ? SW_SHOWMINIMIZED
: SW_SHOWNORMAL
);
782 CONV_POINT16TO32( &wndPtr
->ptIconPos
, &wndpl
->ptMinPosition
);
783 CONV_POINT16TO32( &wndPtr
->ptMaxPos
, &wndpl
->ptMaxPosition
);
784 CONV_RECT16TO32( &wndPtr
->rectNormal
, &wndpl
->rcNormalPosition
);
789 /***********************************************************************
790 * SetWindowPlacement16 (USER.371)
792 BOOL16
SetWindowPlacement16( HWND16 hwnd
, const WINDOWPLACEMENT16
*wndpl
)
794 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
795 if (!wndPtr
) return FALSE
;
797 if (wndpl
->flags
& WPF_SETMINPOSITION
)
798 wndPtr
->ptIconPos
= wndpl
->ptMinPosition
;
799 if ((wndpl
->flags
& WPF_RESTORETOMAXIMIZED
) &&
800 (wndpl
->showCmd
== SW_SHOWMINIMIZED
)) wndPtr
->flags
|= WIN_RESTORE_MAX
;
801 wndPtr
->ptMaxPos
= wndpl
->ptMaxPosition
;
802 wndPtr
->rectNormal
= wndpl
->rcNormalPosition
;
803 ShowWindow( hwnd
, wndpl
->showCmd
);
808 /***********************************************************************
809 * SetWindowPlacement32 (USER32.518)
811 BOOL32
SetWindowPlacement32( HWND32 hwnd
, const WINDOWPLACEMENT32
*wndpl
)
813 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
814 if (!wndPtr
) return FALSE
;
816 if (wndpl
->flags
& WPF_SETMINPOSITION
)
817 CONV_POINT32TO16( &wndpl
->ptMinPosition
, &wndPtr
->ptIconPos
);
818 if ((wndpl
->flags
& WPF_RESTORETOMAXIMIZED
) &&
819 (wndpl
->showCmd
== SW_SHOWMINIMIZED
)) wndPtr
->flags
|= WIN_RESTORE_MAX
;
820 CONV_POINT32TO16( &wndpl
->ptMaxPosition
, &wndPtr
->ptMaxPos
);
821 CONV_RECT32TO16( &wndpl
->rcNormalPosition
, &wndPtr
->rectNormal
);
822 ShowWindow( hwnd
, wndpl
->showCmd
);
827 /*******************************************************************
828 * ACTIVATEAPP_callback
830 BOOL
ACTIVATEAPP_callback(HWND hWnd
, LPARAM lParam
)
832 ACTIVATESTRUCT
*lpActStruct
= (ACTIVATESTRUCT
*)lParam
;
834 if (GetWindowTask(hWnd
) != lpActStruct
->hTaskSendTo
) return 1;
836 SendMessage16( hWnd
, WM_ACTIVATEAPP
, lpActStruct
->wFlag
,
837 (LPARAM
)((lpActStruct
->hWindowTask
)?lpActStruct
->hWindowTask
:0));
842 /*******************************************************************
843 * WINPOS_SetActiveWindow
845 * back-end to SetActiveWindow
847 BOOL
WINPOS_SetActiveWindow( HWND hWnd
, BOOL fMouse
, BOOL fChangeFocus
)
849 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
850 WND
*wndTemp
= WIN_FindWndPtr(hwndActive
);
851 CBTACTIVATESTRUCT16
*cbtStruct
;
852 FARPROC enumCallback
= MODULE_GetWndProcEntry16("ActivateAppProc");
853 ACTIVATESTRUCT actStruct
;
856 /* FIXME: When proper support for cooperative multitasking is in place
857 * hActiveQ will be global
862 /* paranoid checks */
863 if( !hWnd
|| hWnd
== GetDesktopWindow() || hWnd
== hwndActive
)
866 if( GetTaskQueue(0) != wndPtr
->hmemTaskQ
)
870 wIconized
= HIWORD(wndTemp
->dwStyle
& WS_MINIMIZE
);
872 dprintf_win(stddeb
,"WINPOS_ActivateWindow: no current active window.\n");
874 /* call CBT hook chain */
875 if ((cbtStruct
= SEGPTR_NEW(CBTACTIVATESTRUCT16
)))
878 cbtStruct
->fMouse
= fMouse
;
879 cbtStruct
->hWndActive
= hwndActive
;
880 wRet
= HOOK_CallHooks( WH_CBT
, HCBT_ACTIVATE
, (WPARAM
)hWnd
,
881 (LPARAM
)SEGPTR_GET(cbtStruct
) );
882 SEGPTR_FREE(cbtStruct
);
883 if (wRet
) return wRet
;
886 /* set prev active wnd to current active wnd and send notification */
887 if ((hwndPrevActive
= hwndActive
) && IsWindow(hwndPrevActive
))
889 if (!SendMessage16( hwndPrevActive
, WM_NCACTIVATE
, FALSE
, 0 ))
891 if (GetSysModalWindow() != hWnd
) return 0;
892 /* disregard refusal if hWnd is sysmodal */
895 SendMessage32A( hwndPrevActive
, WM_ACTIVATE
,
896 MAKEWPARAM( WA_INACTIVE
, wIconized
),
899 /* check if something happened during message processing */
900 if( hwndPrevActive
!= hwndActive
) return 0;
906 /* send palette messages */
907 if( SendMessage16( hWnd
, WM_QUERYNEWPALETTE
, 0, 0L) )
908 SendMessage16((HWND16
)-1, WM_PALETTEISCHANGING
, (WPARAM
)hWnd
, 0L );
910 /* if prev wnd is minimized redraw icon title
913 wndTemp = WIN_FindWndPtr( WIN_GetTopParent( hwndPrevActive ) );
915 if(wndTemp->dwStyle & WS_MINIMIZE)
916 RedrawIconTitle(hwndPrevActive);
920 /* managed windows will get ConfigureNotify event */
921 if (!(wndPtr
->dwStyle
& WS_CHILD
) && !(wndPtr
->flags
& WIN_MANAGED
))
923 /* check Z-order and bring hWnd to the top */
924 for (wndTemp
= WIN_GetDesktop()->child
; wndTemp
; wndTemp
= wndTemp
->next
)
925 if (wndTemp
->dwStyle
& WS_VISIBLE
) break;
927 if( wndTemp
!= wndPtr
)
928 SetWindowPos(hWnd
, HWND_TOP
, 0,0,0,0,
929 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
932 if( !IsWindow(hWnd
) ) return 0;
936 wndTemp
= WIN_FindWndPtr( hwndPrevActive
);
937 if (wndTemp
) hActiveQ
= wndTemp
->hmemTaskQ
;
940 /* send WM_ACTIVATEAPP if necessary */
941 if (hActiveQ
!= wndPtr
->hmemTaskQ
)
943 HTASK hT
= QUEUE_GetQueueTask( hActiveQ
);
945 actStruct
.wFlag
= 0; /* deactivate */
946 actStruct
.hWindowTask
= QUEUE_GetQueueTask(wndPtr
->hmemTaskQ
);
947 actStruct
.hTaskSendTo
= hT
;
949 /* send WM_ACTIVATEAPP to top-level windows
950 * that belong to the actStruct.hTaskSendTo task
952 EnumWindows( enumCallback
, (LPARAM
)&actStruct
);
954 actStruct
.wFlag
= 1; /* activate */
955 actStruct
.hWindowTask
= hT
;
956 actStruct
.hTaskSendTo
= QUEUE_GetQueueTask( wndPtr
->hmemTaskQ
);
958 EnumWindows( enumCallback
, (LPARAM
)&actStruct
);
960 if( !IsWindow(hWnd
) ) return 0;
963 /* walk up to the first unowned window */
965 while (wndTemp
->owner
) wndTemp
= wndTemp
->owner
;
966 /* and set last active owned popup */
967 wndTemp
->hwndLastActive
= hWnd
;
969 wIconized
= HIWORD(wndTemp
->dwStyle
& WS_MINIMIZE
);
970 SendMessage16( hWnd
, WM_NCACTIVATE
, TRUE
, 0 );
972 SendMessage32A( hWnd
, WM_ACTIVATE
,
973 MAKEWPARAM( (fMouse
)?WA_CLICKACTIVE
:WA_ACTIVE
, wIconized
),
974 (LPARAM
)hwndPrevActive
);
976 SendMessage16( hWnd
, WM_ACTIVATE
, (fMouse
)? WA_CLICKACTIVE
: WA_ACTIVE
,
977 MAKELONG(hwndPrevActive
,wIconized
));
980 if( !IsWindow(hWnd
) ) return 0;
982 /* change focus if possible */
983 if( fChangeFocus
&& GetFocus() )
984 if( WIN_GetTopParent(GetFocus()) != hwndActive
)
985 FOCUS_SwitchFocus( GetFocus(),
986 (wndPtr
->dwStyle
& WS_MINIMIZE
)? 0: hwndActive
);
988 /* if active wnd is minimized redraw icon title
991 wndPtr = WIN_FindWndPtr(hwndActive);
992 if(wndPtr->dwStyle & WS_MINIMIZE)
993 RedrawIconTitle(hwndActive);
996 return (hWnd
== hwndActive
);
1000 /*******************************************************************
1001 * WINPOS_ChangeActiveWindow
1004 BOOL
WINPOS_ChangeActiveWindow( HWND hWnd
, BOOL mouseMsg
)
1006 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
1008 if( !wndPtr
) return FALSE
;
1010 /* child windows get WM_CHILDACTIVATE message */
1011 if( (wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
1012 return SendMessage16(hWnd
, WM_CHILDACTIVATE
, 0, 0L);
1014 /* owned popups imply owner activation - not sure */
1015 if ((wndPtr
->dwStyle
& WS_POPUP
) && wndPtr
->owner
&&
1016 !(wndPtr
->owner
->dwStyle
& WS_DISABLED
))
1018 if (!(wndPtr
= wndPtr
->owner
)) return FALSE
;
1019 hWnd
= wndPtr
->hwndSelf
;
1022 if( hWnd
== hwndActive
) return FALSE
;
1024 if( !WINPOS_SetActiveWindow(hWnd
,mouseMsg
,TRUE
) )
1027 /* switch desktop queue to current active */
1028 if( wndPtr
->parent
== WIN_GetDesktop())
1029 WIN_GetDesktop()->hmemTaskQ
= wndPtr
->hmemTaskQ
;
1035 /***********************************************************************
1036 * WINPOS_SendNCCalcSize
1038 * Send a WM_NCCALCSIZE message to a window.
1039 * All parameters are read-only except newClientRect.
1040 * oldWindowRect, oldClientRect and winpos must be non-NULL only
1041 * when calcValidRect is TRUE.
1043 LONG
WINPOS_SendNCCalcSize( HWND hwnd
, BOOL calcValidRect
,
1044 RECT16
*newWindowRect
, RECT16
*oldWindowRect
,
1045 RECT16
*oldClientRect
, SEGPTR winpos
,
1046 RECT16
*newClientRect
)
1048 NCCALCSIZE_PARAMS16
*params
;
1051 if (!(params
= SEGPTR_NEW(NCCALCSIZE_PARAMS16
))) return 0;
1052 params
->rgrc
[0] = *newWindowRect
;
1055 params
->rgrc
[1] = *oldWindowRect
;
1056 params
->rgrc
[2] = *oldClientRect
;
1057 params
->lppos
= winpos
;
1059 result
= SendMessage16( hwnd
, WM_NCCALCSIZE
, calcValidRect
,
1060 (LPARAM
)SEGPTR_GET( params
) );
1061 dprintf_win(stddeb
, "WINPOS_SendNCCalcSize: %d %d %d %d\n",
1062 (int)params
->rgrc
[0].top
, (int)params
->rgrc
[0].left
,
1063 (int)params
->rgrc
[0].bottom
, (int)params
->rgrc
[0].right
);
1064 *newClientRect
= params
->rgrc
[0];
1065 SEGPTR_FREE(params
);
1070 /***********************************************************************
1071 * WINPOS_HandleWindowPosChanging16
1073 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1075 LONG
WINPOS_HandleWindowPosChanging16( WND
*wndPtr
, WINDOWPOS16
*winpos
)
1078 if (winpos
->flags
& SWP_NOSIZE
) return 0;
1079 if ((wndPtr
->dwStyle
& WS_THICKFRAME
) ||
1080 ((wndPtr
->dwStyle
& (WS_POPUP
| WS_CHILD
)) == 0))
1082 NC_GetMinMaxInfo( winpos
->hwnd
, &maxSize
, NULL
, NULL
, NULL
);
1083 winpos
->cx
= MIN( winpos
->cx
, maxSize
.x
);
1084 winpos
->cy
= MIN( winpos
->cy
, maxSize
.y
);
1090 /***********************************************************************
1091 * WINPOS_HandleWindowPosChanging32
1093 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1095 LONG
WINPOS_HandleWindowPosChanging32( WND
*wndPtr
, WINDOWPOS32
*winpos
)
1098 if (winpos
->flags
& SWP_NOSIZE
) return 0;
1099 if ((wndPtr
->dwStyle
& WS_THICKFRAME
) ||
1100 ((wndPtr
->dwStyle
& (WS_POPUP
| WS_CHILD
)) == 0))
1102 NC_GetMinMaxInfo( winpos
->hwnd
, &maxSize
, NULL
, NULL
, NULL
);
1103 winpos
->cx
= MIN( winpos
->cx
, maxSize
.x
);
1104 winpos
->cy
= MIN( winpos
->cy
, maxSize
.y
);
1110 /***********************************************************************
1111 * WINPOS_MoveWindowZOrder
1113 * Move a window in Z order, invalidating everything that needs it.
1114 * Only necessary for windows without associated X window.
1116 static void WINPOS_MoveWindowZOrder( HWND hwnd
, HWND hwndAfter
)
1119 WND
*pWndAfter
, *pWndCur
, *wndPtr
= WIN_FindWndPtr( hwnd
);
1121 /* We have two possible cases:
1122 * - The window is moving up: we have to invalidate all areas
1123 * of the window that were covered by other windows
1124 * - The window is moving down: we have to invalidate areas
1125 * of other windows covered by this one.
1128 if (hwndAfter
== HWND_TOP
)
1132 else if (hwndAfter
== HWND_BOTTOM
)
1134 if (!wndPtr
->next
) return; /* Already at the bottom */
1139 if (!(pWndAfter
= WIN_FindWndPtr( hwndAfter
))) return;
1140 if (wndPtr
->next
== pWndAfter
) return; /* Already placed right */
1142 /* Determine which window we encounter first in Z-order */
1143 pWndCur
= wndPtr
->parent
->child
;
1144 while ((pWndCur
!= wndPtr
) && (pWndCur
!= pWndAfter
))
1145 pWndCur
= pWndCur
->next
;
1146 movingUp
= (pWndCur
== pWndAfter
);
1151 WND
*pWndPrevAfter
= wndPtr
->next
;
1152 WIN_UnlinkWindow( hwnd
);
1153 WIN_LinkWindow( hwnd
, hwndAfter
);
1154 pWndCur
= wndPtr
->next
;
1155 while (pWndCur
!= pWndPrevAfter
)
1157 RECT16 rect
= pWndCur
->rectWindow
;
1158 OffsetRect16( &rect
, -wndPtr
->rectClient
.left
,
1159 -wndPtr
->rectClient
.top
);
1160 RedrawWindow16( hwnd
, &rect
, 0, RDW_INVALIDATE
| RDW_ALLCHILDREN
|
1161 RDW_FRAME
| RDW_ERASE
);
1162 pWndCur
= pWndCur
->next
;
1165 else /* Moving down */
1167 pWndCur
= wndPtr
->next
;
1168 WIN_UnlinkWindow( hwnd
);
1169 WIN_LinkWindow( hwnd
, hwndAfter
);
1170 while (pWndCur
!= wndPtr
)
1172 RECT16 rect
= wndPtr
->rectWindow
;
1173 OffsetRect16( &rect
, -pWndCur
->rectClient
.left
,
1174 -pWndCur
->rectClient
.top
);
1175 RedrawWindow16( pWndCur
->hwndSelf
, &rect
, 0, RDW_INVALIDATE
|
1176 RDW_ALLCHILDREN
| RDW_FRAME
| RDW_ERASE
);
1177 pWndCur
= pWndCur
->next
;
1182 /***********************************************************************
1183 * WINPOS_ReorderOwnedPopups
1185 * fix Z order taking into account owned popups -
1186 * basically we need to maintain them above owner window
1188 HWND
WINPOS_ReorderOwnedPopups(HWND hwndInsertAfter
, WND
* wndPtr
, WORD flags
)
1190 WND
* w
= WIN_GetDesktop();
1194 /* if we are dealing with owned popup...
1196 if( wndPtr
->dwStyle
& WS_POPUP
&& wndPtr
->owner
&& hwndInsertAfter
!= HWND_TOP
)
1198 BOOL bFound
= FALSE
;
1199 HWND hwndLocalPrev
= HWND_TOP
;
1200 HWND hwndNewAfter
= 0;
1204 if( !bFound
&& hwndInsertAfter
== hwndLocalPrev
)
1205 hwndInsertAfter
= HWND_TOP
;
1207 if( w
->dwStyle
& WS_POPUP
&& w
->owner
== wndPtr
->owner
)
1211 if( hwndInsertAfter
== HWND_TOP
)
1213 hwndInsertAfter
= hwndLocalPrev
;
1216 hwndNewAfter
= hwndLocalPrev
;
1219 if( w
== wndPtr
->owner
)
1221 /* basically HWND_BOTTOM */
1222 hwndInsertAfter
= hwndLocalPrev
;
1225 hwndInsertAfter
= hwndNewAfter
;
1230 hwndLocalPrev
= w
->hwndSelf
;
1236 /* or overlapped top-level window...
1238 if( !(wndPtr
->dwStyle
& WS_CHILD
) )
1241 if( w
== wndPtr
) break;
1243 if( w
->dwStyle
& WS_POPUP
&& w
->owner
== wndPtr
)
1245 SetWindowPos(w
->hwndSelf
, hwndInsertAfter
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
|
1246 SWP_NOACTIVATE
| SWP_NOSENDCHANGING
| SWP_DEFERERASE
);
1247 hwndInsertAfter
= w
->hwndSelf
;
1252 return hwndInsertAfter
;
1255 /***********************************************************************
1256 * WINPOS_SizeMoveClean
1258 * Make window look nice without excessive repainting
1262 * visible regions are in window coordinates
1263 * update regions are in window client coordinates
1264 * client and window rectangles are in parent client coordinates
1266 static void WINPOS_SizeMoveClean(WND
* Wnd
, HRGN oldVisRgn
, LPRECT16 lpOldWndRect
, LPRECT16 lpOldClientRect
, BOOL bNoCopy
)
1268 HRGN newVisRgn
= DCE_GetVisRgn(Wnd
->hwndSelf
, DCX_WINDOW
| DCX_CLIPSIBLINGS
);
1269 HRGN dirtyRgn
= CreateRectRgn(0,0,0,0);
1272 dprintf_win(stddeb
,"cleaning up...new wnd=(%i %i-%i %i) old wnd=(%i %i-%i %i)\n\
1273 \t\tnew client=(%i %i-%i %i) old client=(%i %i-%i %i)\n",
1274 Wnd
->rectWindow
.left
, Wnd
->rectWindow
.top
, Wnd
->rectWindow
.right
, Wnd
->rectWindow
.bottom
,
1275 lpOldWndRect
->left
, lpOldWndRect
->top
, lpOldWndRect
->right
, lpOldWndRect
->bottom
,
1276 Wnd
->rectClient
.left
,Wnd
->rectClient
.top
,Wnd
->rectClient
.right
,Wnd
->rectClient
.bottom
,
1277 lpOldClientRect
->left
,lpOldClientRect
->top
,lpOldClientRect
->right
,lpOldClientRect
->bottom
);
1279 CombineRgn( dirtyRgn
, newVisRgn
, 0, RGN_COPY
);
1283 HRGN hRgn
= CreateRectRgn( lpOldClientRect
->left
- lpOldWndRect
->left
, lpOldClientRect
->top
- lpOldWndRect
->top
,
1284 lpOldClientRect
->right
- lpOldWndRect
->left
, lpOldClientRect
->bottom
- lpOldWndRect
->top
);
1285 CombineRgn( newVisRgn
, newVisRgn
, oldVisRgn
, RGN_AND
);
1286 CombineRgn( newVisRgn
, newVisRgn
, hRgn
, RGN_AND
);
1290 /* map regions to the parent client area */
1292 OffsetRgn(dirtyRgn
, Wnd
->rectWindow
.left
, Wnd
->rectWindow
.top
);
1293 OffsetRgn(oldVisRgn
, lpOldWndRect
->left
, lpOldWndRect
->top
);
1295 /* compute invalidated region outside Wnd - (in client coordinates of the parent window) */
1297 other
= CombineRgn(dirtyRgn
, oldVisRgn
, dirtyRgn
, RGN_DIFF
);
1299 /* map visible region to the Wnd client area */
1301 OffsetRgn( newVisRgn
, Wnd
->rectWindow
.left
- Wnd
->rectClient
.left
,
1302 Wnd
->rectWindow
.top
- Wnd
->rectClient
.top
);
1304 /* substract previously invalidated region from the Wnd visible region */
1306 my
= (Wnd
->hrgnUpdate
> 1)? CombineRgn( newVisRgn
, newVisRgn
, Wnd
->hrgnUpdate
, RGN_DIFF
)
1309 if( bNoCopy
) /* invalidate Wnd visible region */
1311 if (my
!= NULLREGION
) RedrawWindow32( Wnd
->hwndSelf
, NULL
, newVisRgn
, RDW_INVALIDATE
|
1312 RDW_FRAME
| RDW_ALLCHILDREN
| RDW_ERASE
);
1314 else /* bitblt old client area */
1322 updateRgn
= CreateRectRgn( 0,0, Wnd
->rectClient
.right
- Wnd
->rectClient
.left
,
1323 Wnd
->rectClient
.bottom
- Wnd
->rectClient
.top
);
1325 /* clip visible region with client rect */
1327 my
= CombineRgn( newVisRgn
, newVisRgn
, updateRgn
, RGN_AND
);
1329 /* substract result from client rect to get region that won't be copied */
1331 update
= CombineRgn( updateRgn
, updateRgn
, newVisRgn
, RGN_DIFF
);
1333 /* Blt valid bits using parent window DC */
1335 if( my
!= NULLREGION
)
1337 int xfrom
= lpOldClientRect
->left
;
1338 int yfrom
= lpOldClientRect
->top
;
1339 int xto
= Wnd
->rectClient
.left
;
1340 int yto
= Wnd
->rectClient
.top
;
1342 /* check if we can skip copying */
1344 if( xfrom
!= xto
|| yfrom
!= yto
)
1346 /* compute clipping region in parent client coordinates */
1348 OffsetRgn( newVisRgn
, Wnd
->rectClient
.left
, Wnd
->rectClient
.top
);
1349 CombineRgn( oldVisRgn
, oldVisRgn
, newVisRgn
, RGN_OR
);
1351 hDC
= GetDCEx( Wnd
->parent
->hwndSelf
, oldVisRgn
, DCX_KEEPCLIPRGN
| DCX_INTERSECTRGN
| DCX_CACHE
| DCX_CLIPSIBLINGS
);
1353 BitBlt(hDC
, xto
, yto
, lpOldClientRect
->right
- lpOldClientRect
->left
,
1354 lpOldClientRect
->bottom
- lpOldClientRect
->top
,
1355 hDC
, xfrom
, yfrom
, SRCCOPY
);
1357 ReleaseDC( Wnd
->parent
->hwndSelf
, hDC
);
1361 if( update
!= NULLREGION
)
1362 RedrawWindow32( Wnd
->hwndSelf
, NULL
, updateRgn
, RDW_INVALIDATE
|
1363 RDW_FRAME
| RDW_ALLCHILDREN
| RDW_ERASE
);
1364 DeleteObject( updateRgn
);
1367 /* erase uncovered areas */
1369 if( other
!= NULLREGION
)
1370 RedrawWindow32( Wnd
->parent
->hwndSelf
, NULL
, dirtyRgn
,
1371 RDW_INVALIDATE
| RDW_ALLCHILDREN
| RDW_ERASE
);
1373 DeleteObject(dirtyRgn
);
1374 DeleteObject(newVisRgn
);
1377 /***********************************************************************
1378 * WINPOS_SetXWindowPos
1380 * SetWindowPos() for an X window. Used by the real SetWindowPos().
1382 static void WINPOS_SetXWindowPos( WINDOWPOS16
*winpos
)
1384 XWindowChanges winChanges
;
1386 WND
*wndPtr
= WIN_FindWndPtr( winpos
->hwnd
);
1388 if (!(winpos
->flags
& SWP_NOSIZE
))
1390 winChanges
.width
= winpos
->cx
;
1391 winChanges
.height
= winpos
->cy
;
1392 changeMask
|= CWWidth
| CWHeight
;
1394 if (!(winpos
->flags
& SWP_NOMOVE
))
1396 winChanges
.x
= winpos
->x
;
1397 winChanges
.y
= winpos
->y
;
1398 changeMask
|= CWX
| CWY
;
1400 if (!(winpos
->flags
& SWP_NOZORDER
))
1402 if (winpos
->hwndInsertAfter
== HWND_TOP
) winChanges
.stack_mode
= Above
;
1403 else winChanges
.stack_mode
= Below
;
1404 if ((winpos
->hwndInsertAfter
!= HWND_TOP
) &&
1405 (winpos
->hwndInsertAfter
!= HWND_BOTTOM
))
1407 WND
* insertPtr
= WIN_FindWndPtr( winpos
->hwndInsertAfter
);
1408 winChanges
.sibling
= insertPtr
->window
;
1409 changeMask
|= CWSibling
;
1411 changeMask
|= CWStackMode
;
1414 XConfigureWindow( display
, wndPtr
->window
, changeMask
, &winChanges
);
1418 /***********************************************************************
1419 * SetWindowPos (USER.232)
1421 BOOL
SetWindowPos( HWND hwnd
, HWND hwndInsertAfter
, INT x
, INT y
,
1422 INT cx
, INT cy
, WORD flags
)
1426 RECT16 newWindowRect
, newClientRect
;
1430 dprintf_win(stddeb
,"SetWindowPos: hwnd %04x, flags %08x\n", hwnd
, flags
);
1432 /* Check window handle */
1434 if (hwnd
== GetDesktopWindow()) return FALSE
;
1435 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return FALSE
;
1437 /* Check for windows that may not be resized
1438 FIXME: this should be done only for Windows 3.0 programs */
1439 if (flags
==(SWP_SHOWWINDOW
) || flags
==(SWP_HIDEWINDOW
) )
1440 flags
|= SWP_NOSIZE
| SWP_NOMOVE
;
1442 /* Check dimensions */
1444 if (cx
<= 0) cx
= 1;
1445 if (cy
<= 0) cy
= 1;
1449 if (hwnd
== hwndActive
) flags
|= SWP_NOACTIVATE
; /* Already active */
1450 if ((wndPtr
->rectWindow
.right
- wndPtr
->rectWindow
.left
== cx
) &&
1451 (wndPtr
->rectWindow
.bottom
- wndPtr
->rectWindow
.top
== cy
))
1452 flags
|= SWP_NOSIZE
; /* Already the right size */
1453 if ((wndPtr
->rectWindow
.left
== x
) && (wndPtr
->rectWindow
.top
== y
))
1454 flags
|= SWP_NOMOVE
; /* Already the right position */
1456 /* Check hwndInsertAfter */
1458 if (!(flags
& (SWP_NOZORDER
| SWP_NOACTIVATE
)))
1460 /* Ignore TOPMOST flags when activating a window */
1461 /* _and_ moving it in Z order. */
1462 if ((hwndInsertAfter
== HWND_TOPMOST
) ||
1463 (hwndInsertAfter
== HWND_NOTOPMOST
))
1464 hwndInsertAfter
= HWND_TOP
;
1466 /* TOPMOST not supported yet */
1467 if ((hwndInsertAfter
== HWND_TOPMOST
) ||
1468 (hwndInsertAfter
== HWND_NOTOPMOST
)) hwndInsertAfter
= HWND_TOP
;
1470 /* hwndInsertAfter must be a sibling of the window */
1471 if ((hwndInsertAfter
!= HWND_TOP
) && (hwndInsertAfter
!= HWND_BOTTOM
))
1473 WND
* wnd
= WIN_FindWndPtr(hwndInsertAfter
);
1474 if( wnd
->parent
!= wndPtr
->parent
) return FALSE
;
1475 if( wnd
->next
== wndPtr
) flags
|= SWP_NOZORDER
;
1478 if (hwndInsertAfter
== HWND_TOP
)
1479 flags
|= ( wndPtr
->parent
->child
== wndPtr
)? SWP_NOZORDER
: 0;
1480 else /* HWND_BOTTOM */
1481 flags
|= ( wndPtr
->next
)? 0: SWP_NOZORDER
;
1483 /* Fill the WINDOWPOS structure */
1486 winpos
.hwndInsertAfter
= hwndInsertAfter
;
1491 winpos
.flags
= flags
;
1493 /* Send WM_WINDOWPOSCHANGING message */
1495 if (!(flags
& SWP_NOSENDCHANGING
))
1496 SendMessage16( hwnd
, WM_WINDOWPOSCHANGING
, 0, (LPARAM
)MAKE_SEGPTR(&winpos
) );
1498 /* Calculate new position and size */
1500 newWindowRect
= wndPtr
->rectWindow
;
1501 newClientRect
= wndPtr
->rectClient
;
1503 if (!(winpos
.flags
& SWP_NOSIZE
))
1505 newWindowRect
.right
= newWindowRect
.left
+ winpos
.cx
;
1506 newWindowRect
.bottom
= newWindowRect
.top
+ winpos
.cy
;
1508 if (!(winpos
.flags
& SWP_NOMOVE
))
1510 newWindowRect
.left
= winpos
.x
;
1511 newWindowRect
.top
= winpos
.y
;
1512 newWindowRect
.right
+= winpos
.x
- wndPtr
->rectWindow
.left
;
1513 newWindowRect
.bottom
+= winpos
.y
- wndPtr
->rectWindow
.top
;
1515 OffsetRect16( &newClientRect
, winpos
.x
- wndPtr
->rectWindow
.left
,
1516 winpos
.y
- wndPtr
->rectWindow
.top
);
1519 winpos
.flags
|= SWP_NOCLIENTMOVE
| SWP_NOCLIENTSIZE
;
1521 /* Reposition window in Z order */
1523 if (!(winpos
.flags
& SWP_NOZORDER
))
1525 /* reorder owned popups if hwnd is top-level window
1527 if( wndPtr
->parent
== WIN_GetDesktop() )
1528 hwndInsertAfter
= WINPOS_ReorderOwnedPopups( hwndInsertAfter
,
1533 WIN_UnlinkWindow( winpos
.hwnd
);
1534 WIN_LinkWindow( winpos
.hwnd
, hwndInsertAfter
);
1536 else WINPOS_MoveWindowZOrder( winpos
.hwnd
, hwndInsertAfter
);
1539 if ( !wndPtr
->window
&& !(flags
& SWP_NOREDRAW
) &&
1540 (!(flags
& SWP_NOMOVE
) || !(flags
& SWP_NOSIZE
) || (flags
& SWP_FRAMECHANGED
)) )
1541 visRgn
= DCE_GetVisRgn(hwnd
, DCX_WINDOW
| DCX_CLIPSIBLINGS
);
1544 /* Send WM_NCCALCSIZE message to get new client area */
1545 if( (flags
& (SWP_FRAMECHANGED
| SWP_NOSIZE
)) != SWP_NOSIZE
)
1547 result
= WINPOS_SendNCCalcSize( winpos
.hwnd
, TRUE
, &newWindowRect
,
1548 &wndPtr
->rectWindow
, &wndPtr
->rectClient
,
1549 MAKE_SEGPTR(&winpos
), &newClientRect
);
1551 /* FIXME: WVR_ALIGNxxx */
1553 if( newClientRect
.left
!= wndPtr
->rectClient
.left
||
1554 newClientRect
.top
!= wndPtr
->rectClient
.top
)
1555 winpos
.flags
&= ~SWP_NOCLIENTMOVE
;
1557 if( (newClientRect
.right
- newClientRect
.left
!=
1558 wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
) ||
1559 (newClientRect
.bottom
- newClientRect
.top
!=
1560 wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
) )
1561 winpos
.flags
&= ~SWP_NOCLIENTSIZE
;
1564 if( !(flags
& SWP_NOMOVE
) && (newClientRect
.left
!= wndPtr
->rectClient
.left
||
1565 newClientRect
.top
!= wndPtr
->rectClient
.top
) )
1566 winpos
.flags
&= ~SWP_NOCLIENTMOVE
;
1568 /* Update active DCEs */
1570 if( !(flags
& SWP_NOZORDER
) || (flags
& SWP_HIDEWINDOW
) || (flags
& SWP_SHOWWINDOW
)
1571 || (memcmp(&newWindowRect
,&wndPtr
->rectWindow
,sizeof(RECT16
))
1572 && wndPtr
->dwStyle
& WS_VISIBLE
) )
1576 UnionRect16(&rect
,&newWindowRect
,&wndPtr
->rectWindow
);
1577 DCE_InvalidateDCE(wndPtr
->parent
, &rect
);
1580 /* Perform the moving and resizing */
1584 RECT16 oldWindowRect
= wndPtr
->rectWindow
;
1585 RECT16 oldClientRect
= wndPtr
->rectClient
;
1587 HWND bogusInsertAfter
= winpos
.hwndInsertAfter
;
1589 winpos
.hwndInsertAfter
= hwndInsertAfter
;
1590 WINPOS_SetXWindowPos( &winpos
);
1592 wndPtr
->rectWindow
= newWindowRect
;
1593 wndPtr
->rectClient
= newClientRect
;
1594 winpos
.hwndInsertAfter
= bogusInsertAfter
;
1596 /* FIXME: should do something like WINPOS_SizeMoveClean */
1598 if( (oldClientRect
.left
- oldWindowRect
.left
!=
1599 newClientRect
.left
- newWindowRect
.left
) ||
1600 (oldClientRect
.top
- oldWindowRect
.top
!=
1601 newClientRect
.top
- newWindowRect
.top
) )
1603 RedrawWindow32( wndPtr
->hwndSelf
, NULL
, 0, RDW_INVALIDATE
|
1604 RDW_ALLCHILDREN
| RDW_FRAME
| RDW_ERASE
);
1606 if( winpos
.flags
& SWP_FRAMECHANGED
)
1611 if( oldClientRect
.right
> newClientRect
.right
)
1613 rect
.left
= newClientRect
.right
; rect
.top
= newClientRect
.top
;
1614 rect
.right
= oldClientRect
.right
; rect
.bottom
= newClientRect
.bottom
;
1616 RedrawWindow32( wndPtr
->hwndSelf
, &rect
, 0,
1617 RDW_INVALIDATE
| RDW_FRAME
| RDW_ALLCHILDREN
);
1619 if( oldClientRect
.bottom
> newClientRect
.bottom
)
1621 rect
.left
= newClientRect
.left
; rect
.top
= newClientRect
.bottom
;
1622 rect
.right
= (wErase
)?oldClientRect
.right
:newClientRect
.right
;
1623 rect
.bottom
= oldClientRect
.bottom
;
1625 RedrawWindow32( wndPtr
->hwndSelf
, &rect
, 0,
1626 RDW_INVALIDATE
| RDW_FRAME
| RDW_ALLCHILDREN
);
1628 if( !wErase
) wndPtr
->flags
|= WIN_NEEDS_NCPAINT
;
1633 RECT16 oldWindowRect
= wndPtr
->rectWindow
;
1634 RECT16 oldClientRect
= wndPtr
->rectClient
;
1636 wndPtr
->rectWindow
= newWindowRect
;
1637 wndPtr
->rectClient
= newClientRect
;
1639 if( !(flags
& SWP_NOREDRAW
) )
1641 BOOL bNoCopy
= (flags
& SWP_NOCOPYBITS
) ||
1642 (result
>= WVR_HREDRAW
&& result
< WVR_VALIDRECTS
);
1644 if( (winpos
.flags
& SWP_NOPOSCHANGE
) != SWP_NOPOSCHANGE
)
1645 /* optimize cleanup by BitBlt'ing where possible */
1647 WINPOS_SizeMoveClean(wndPtr
, visRgn
, &oldWindowRect
, &oldClientRect
, bNoCopy
);
1649 if( winpos
.flags
& SWP_FRAMECHANGED
)
1650 RedrawWindow32( winpos
.hwnd
, NULL
, 0, RDW_NOCHILDREN
| RDW_FRAME
);
1653 DeleteObject(visRgn
);
1656 if (flags
& SWP_SHOWWINDOW
)
1658 wndPtr
->dwStyle
|= WS_VISIBLE
;
1661 XMapWindow( display
, wndPtr
->window
);
1665 if (!(flags
& SWP_NOREDRAW
))
1666 RedrawWindow32( winpos
.hwnd
, NULL
, 0,
1667 RDW_INVALIDATE
| RDW_ALLCHILDREN
|
1668 RDW_FRAME
| RDW_ERASE
);
1671 else if (flags
& SWP_HIDEWINDOW
)
1673 wndPtr
->dwStyle
&= ~WS_VISIBLE
;
1676 XUnmapWindow( display
, wndPtr
->window
);
1680 if (!(flags
& SWP_NOREDRAW
))
1681 RedrawWindow16( wndPtr
->parent
->hwndSelf
, &wndPtr
->rectWindow
, 0,
1682 RDW_INVALIDATE
| RDW_ALLCHILDREN
| RDW_ERASE
);
1685 if ((winpos
.hwnd
== GetFocus()) || IsChild(winpos
.hwnd
, GetFocus()))
1686 SetFocus( GetParent(winpos
.hwnd
) ); /* Revert focus to parent */
1688 if (winpos
.hwnd
== hwndActive
)
1690 /* Activate previously active window if possible */
1691 HWND newActive
= hwndPrevActive
;
1692 if (!IsWindow(newActive
) || (newActive
== winpos
.hwnd
))
1694 newActive
= GetTopWindow( GetDesktopWindow() );
1695 if (newActive
== winpos
.hwnd
)
1696 newActive
= wndPtr
->next
? wndPtr
->next
->hwndSelf
: 0;
1698 WINPOS_ChangeActiveWindow( newActive
, FALSE
);
1702 /* Activate the window */
1704 if (!(flags
& SWP_NOACTIVATE
))
1705 WINPOS_ChangeActiveWindow( winpos
.hwnd
, FALSE
);
1707 /* Repaint the window */
1709 if (wndPtr
->window
) EVENT_Synchronize(); /* Wait for all expose events */
1711 EVENT_DummyMotionNotify(); /* Simulate a mouse event to set the cursor */
1713 if (!(flags
& SWP_DEFERERASE
))
1714 RedrawWindow32( wndPtr
->parent
->hwndSelf
, NULL
, 0,
1715 RDW_ALLCHILDREN
| RDW_ERASENOW
);
1717 /* And last, send the WM_WINDOWPOSCHANGED message */
1719 if (!(winpos
.flags
& SWP_NOSENDCHANGING
))
1720 SendMessage16( winpos
.hwnd
, WM_WINDOWPOSCHANGED
,
1721 0, (LPARAM
)MAKE_SEGPTR(&winpos
) );
1727 /***********************************************************************
1728 * BeginDeferWindowPos (USER.259)
1730 HDWP16
BeginDeferWindowPos( INT count
)
1735 if (count
<= 0) return 0;
1736 handle
= USER_HEAP_ALLOC( sizeof(DWP
) + (count
-1)*sizeof(WINDOWPOS16
) );
1737 if (!handle
) return 0;
1738 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( handle
);
1739 pDWP
->actualCount
= 0;
1740 pDWP
->suggestedCount
= count
;
1742 pDWP
->wMagic
= DWP_MAGIC
;
1743 pDWP
->hwndParent
= 0;
1748 /***********************************************************************
1749 * DeferWindowPos (USER.260)
1751 HDWP16
DeferWindowPos( HDWP16 hdwp
, HWND hwnd
, HWND hwndAfter
, INT x
, INT y
,
1752 INT cx
, INT cy
, UINT flags
)
1756 HDWP16 newhdwp
= hdwp
;
1759 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( hdwp
);
1760 if (!pDWP
) return 0;
1761 if (hwnd
== GetDesktopWindow()) return 0;
1763 /* All the windows of a DeferWindowPos() must have the same parent */
1765 parent
= WIN_FindWndPtr( hwnd
)->parent
->hwndSelf
;
1766 if (pDWP
->actualCount
== 0) pDWP
->hwndParent
= parent
;
1767 else if (parent
!= pDWP
->hwndParent
)
1769 USER_HEAP_FREE( hdwp
);
1773 for (i
= 0; i
< pDWP
->actualCount
; i
++)
1775 if (pDWP
->winPos
[i
].hwnd
== hwnd
)
1777 /* Merge with the other changes */
1778 if (!(flags
& SWP_NOZORDER
))
1780 pDWP
->winPos
[i
].hwndInsertAfter
= hwndAfter
;
1782 if (!(flags
& SWP_NOMOVE
))
1784 pDWP
->winPos
[i
].x
= x
;
1785 pDWP
->winPos
[i
].y
= y
;
1787 if (!(flags
& SWP_NOSIZE
))
1789 pDWP
->winPos
[i
].cx
= cx
;
1790 pDWP
->winPos
[i
].cy
= cy
;
1792 pDWP
->winPos
[i
].flags
&= flags
& (SWP_NOSIZE
| SWP_NOMOVE
|
1793 SWP_NOZORDER
| SWP_NOREDRAW
|
1794 SWP_NOACTIVATE
| SWP_NOCOPYBITS
|
1796 pDWP
->winPos
[i
].flags
|= flags
& (SWP_SHOWWINDOW
| SWP_HIDEWINDOW
|
1801 if (pDWP
->actualCount
>= pDWP
->suggestedCount
)
1803 newhdwp
= USER_HEAP_REALLOC( hdwp
,
1804 sizeof(DWP
) + pDWP
->suggestedCount
*sizeof(WINDOWPOS16
) );
1805 if (!newhdwp
) return 0;
1806 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( newhdwp
);
1807 pDWP
->suggestedCount
++;
1809 pDWP
->winPos
[pDWP
->actualCount
].hwnd
= hwnd
;
1810 pDWP
->winPos
[pDWP
->actualCount
].hwndInsertAfter
= hwndAfter
;
1811 pDWP
->winPos
[pDWP
->actualCount
].x
= x
;
1812 pDWP
->winPos
[pDWP
->actualCount
].y
= y
;
1813 pDWP
->winPos
[pDWP
->actualCount
].cx
= cx
;
1814 pDWP
->winPos
[pDWP
->actualCount
].cy
= cy
;
1815 pDWP
->winPos
[pDWP
->actualCount
].flags
= flags
;
1816 pDWP
->actualCount
++;
1821 /***********************************************************************
1822 * EndDeferWindowPos (USER.261)
1824 BOOL
EndDeferWindowPos( HDWP16 hdwp
)
1827 WINDOWPOS16
*winpos
;
1831 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( hdwp
);
1832 if (!pDWP
) return FALSE
;
1833 for (i
= 0, winpos
= pDWP
->winPos
; i
< pDWP
->actualCount
; i
++, winpos
++)
1835 if (!(res
= SetWindowPos( winpos
->hwnd
, winpos
->hwndInsertAfter
,
1836 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
,
1837 winpos
->flags
))) break;
1839 USER_HEAP_FREE( hdwp
);
1844 /***********************************************************************
1845 * TileChildWindows (USER.199)
1847 void TileChildWindows( HWND parent
, WORD action
)
1849 printf("STUB TileChildWindows(%04x, %d)\n", parent
, action
);
1852 /***********************************************************************
1853 * CascageChildWindows (USER.198)
1855 void CascadeChildWindows( HWND parent
, WORD action
)
1857 printf("STUB CascadeChildWindows(%04x, %d)\n", parent
, action
);