4 * Copyright 1998,1999 Patrik Stridvall
14 #include "debugtools.h"
16 DEFAULT_DEBUG_CHANNEL(ttydrv);
18 WND_DRIVER TTYDRV_WND_Driver =
20 TTYDRV_WND_ForceWindowRaise,
21 TTYDRV_WND_PreSizeMove,
22 TTYDRV_WND_PostSizeMove,
23 TTYDRV_WND_ScrollWindow,
24 TTYDRV_WND_SetHostAttr
27 #define SWP_AGG_NOGEOMETRYCHANGE \
28 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE)
29 #define SWP_AGG_NOPOSCHANGE \
30 (SWP_AGG_NOGEOMETRYCHANGE | SWP_NOZORDER)
31 #define SWP_AGG_STATUSFLAGS \
32 (SWP_AGG_NOPOSCHANGE | SWP_FRAMECHANGED | SWP_HIDEWINDOW | SWP_SHOWWINDOW)
34 /**********************************************************************
35 * CreateWindow (TTYDRV.@)
37 BOOL TTYDRV_CreateWindow( HWND hwnd )
40 WND *wndPtr = WIN_FindWndPtr( hwnd );
42 INT cellWidth=8, cellHeight=8; /* FIXME: Hardcoded */
44 TRACE("(%x)\n", hwnd);
46 /* Only create top-level windows */
47 if (wndPtr->dwStyle & WS_CHILD)
49 WIN_ReleaseWndPtr( wndPtr );
53 if (!wndPtr->parent) /* desktop */
57 int x = wndPtr->rectWindow.left;
58 int y = wndPtr->rectWindow.top;
59 int cx = wndPtr->rectWindow.right - wndPtr->rectWindow.left;
60 int cy = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top;
62 window = subwin( root_window, cy/cellHeight, cx/cellWidth,
63 y/cellHeight, x/cellWidth);
67 wndPtr->pDriverData = window;
68 WIN_ReleaseWndPtr( wndPtr );
69 #else /* defined(WINE_CURSES) */
70 FIXME("(%x): stub\n", hwnd);
71 #endif /* defined(WINE_CURSES) */
75 /***********************************************************************
76 * DestroyWindow (TTYDRV.@)
78 BOOL TTYDRV_DestroyWindow( HWND hwnd )
81 WND *wndPtr = WIN_FindWndPtr( hwnd );
82 WINDOW *window = wndPtr->pDriverData;
84 TRACE("(%x)\n", hwnd);
86 if (window && window != root_window) delwin(window);
87 wndPtr->pDriverData = NULL;
88 WIN_ReleaseWndPtr( wndPtr );
89 #else /* defined(WINE_CURSES) */
90 FIXME("(%x): stub\n", hwnd);
91 #endif /* defined(WINE_CURSES) */
95 /***********************************************************************
96 * TTYDRV_WND_ForceWindowRaise
98 void TTYDRV_WND_ForceWindowRaise(WND *wndPtr)
100 FIXME("(%p): stub\n", wndPtr);
103 /*****************************************************************
104 * TTYDRV_WND_PreSizeMove
106 void TTYDRV_WND_PreSizeMove(WND *wndPtr)
108 FIXME("(%p): stub\n", wndPtr);
111 /*****************************************************************
112 * TTYDRV_WND_PostSizeMove
114 void TTYDRV_WND_PostSizeMove(WND *wndPtr)
116 FIXME("(%p): stub\n", wndPtr);
119 /*****************************************************************
120 * TTYDRV_WND_ScrollWindow
122 void TTYDRV_WND_ScrollWindow( WND *wndPtr, HDC hdc, INT dx, INT dy,
123 const RECT *clipRect, BOOL bUpdate)
125 FIXME("(%p, %x, %d, %d, %p, %d): stub\n",
126 wndPtr, hdc, dx, dy, clipRect, bUpdate);
129 /***********************************************************************
130 * TTYDRV_WND_SetHostAttr
132 BOOL TTYDRV_WND_SetHostAttr(WND *wndPtr, INT attr, INT value)
134 FIXME("(%p): stub\n", wndPtr);
140 /***********************************************************************
143 * Change region from DC-origin relative coordinates to screen coords.
146 static void DCE_OffsetVisRgn( HDC hDC, HRGN hVisRgn )
149 if (!(dc = DC_GetDCPtr( hDC ))) return;
151 OffsetRgn( hVisRgn, dc->DCOrgX, dc->DCOrgY );
153 GDI_ReleaseObj( hDC );
157 /***********************************************************************
160 * Calculate the visible rectangle of a window (i.e. the client or
161 * window area clipped by the client area of all ancestors) in the
162 * corresponding coordinates. Return FALSE if the visible region is empty.
164 static BOOL DCE_GetVisRect( WND *wndPtr, BOOL clientArea, RECT *lprect )
166 *lprect = clientArea ? wndPtr->rectClient : wndPtr->rectWindow;
168 if (wndPtr->dwStyle & WS_VISIBLE)
170 INT xoffset = lprect->left;
171 INT yoffset = lprect->top;
173 while ((wndPtr = WIN_LockWndPtr(wndPtr->parent)))
175 if ( (wndPtr->dwStyle & (WS_ICONIC | WS_VISIBLE)) != WS_VISIBLE )
177 WIN_ReleaseWndPtr(wndPtr);
181 xoffset += wndPtr->rectClient.left;
182 yoffset += wndPtr->rectClient.top;
183 OffsetRect( lprect, wndPtr->rectClient.left,
184 wndPtr->rectClient.top );
186 if( (wndPtr->rectClient.left >= wndPtr->rectClient.right) ||
187 (wndPtr->rectClient.top >= wndPtr->rectClient.bottom) ||
188 (lprect->left >= wndPtr->rectClient.right) ||
189 (lprect->right <= wndPtr->rectClient.left) ||
190 (lprect->top >= wndPtr->rectClient.bottom) ||
191 (lprect->bottom <= wndPtr->rectClient.top) )
193 WIN_ReleaseWndPtr(wndPtr);
197 lprect->left = max( lprect->left, wndPtr->rectClient.left );
198 lprect->right = min( lprect->right, wndPtr->rectClient.right );
199 lprect->top = max( lprect->top, wndPtr->rectClient.top );
200 lprect->bottom = min( lprect->bottom, wndPtr->rectClient.bottom );
202 WIN_ReleaseWndPtr(wndPtr);
204 OffsetRect( lprect, -xoffset, -yoffset );
209 SetRectEmpty( lprect );
214 /***********************************************************************
217 * Go through the linked list of windows from pWndStart to pWndEnd,
218 * adding to the clip region the intersection of the target rectangle
219 * with an offset window rectangle.
221 static BOOL DCE_AddClipRects( WND *pWndStart, WND *pWndEnd,
222 HRGN hrgnClip, LPRECT lpRect, int x, int y )
226 for (WIN_LockWndPtr(pWndStart); (pWndStart && (pWndStart != pWndEnd)); WIN_UpdateWndPtr(&pWndStart,pWndStart->next))
228 if( !(pWndStart->dwStyle & WS_VISIBLE) ) continue;
230 rect.left = pWndStart->rectWindow.left + x;
231 rect.top = pWndStart->rectWindow.top + y;
232 rect.right = pWndStart->rectWindow.right + x;
233 rect.bottom = pWndStart->rectWindow.bottom + y;
235 if( IntersectRect( &rect, &rect, lpRect ))
237 if(!REGION_UnionRectWithRgn( hrgnClip, &rect )) break;
240 WIN_ReleaseWndPtr(pWndStart);
241 return (pWndStart == pWndEnd);
245 /***********************************************************************
248 * Return the visible region of a window, i.e. the client or window area
249 * clipped by the client area of all ancestors, and then optionally
250 * by siblings and children.
252 static HRGN DCE_GetVisRgn( HWND hwnd, WORD flags, HWND hwndChild, WORD cflags )
256 WND *wndPtr = WIN_FindWndPtr( hwnd );
257 WND *childWnd = WIN_FindWndPtr( hwndChild );
259 /* Get visible rectangle and create a region with it. */
261 if (wndPtr && DCE_GetVisRect(wndPtr, !(flags & DCX_WINDOW), &rect))
263 if((hrgnVis = CreateRectRgnIndirect( &rect )))
265 HRGN hrgnClip = CreateRectRgn( 0, 0, 0, 0 );
266 INT xoffset, yoffset;
270 /* Compute obscured region for the visible rectangle by
271 * clipping children, siblings, and ancestors. Note that
272 * DCE_GetVisRect() returns a rectangle either in client
273 * or in window coordinates (for DCX_WINDOW request). */
275 if( (flags & DCX_CLIPCHILDREN) && wndPtr->child )
277 if( flags & DCX_WINDOW )
279 /* adjust offsets since child window rectangles are
280 * in client coordinates */
282 xoffset = wndPtr->rectClient.left - wndPtr->rectWindow.left;
283 yoffset = wndPtr->rectClient.top - wndPtr->rectWindow.top;
286 xoffset = yoffset = 0;
288 DCE_AddClipRects( wndPtr->child, NULL, hrgnClip, &rect, xoffset, yoffset );
291 /* We may need to clip children of child window, if a window with PARENTDC
292 * class style and CLIPCHILDREN window style (like in Free Agent 16
293 * preference dialogs) gets here, we take the region for the parent window
294 * but apparently still need to clip the children of the child window... */
296 if( (cflags & DCX_CLIPCHILDREN) && childWnd && childWnd->child )
298 if( flags & DCX_WINDOW )
300 /* adjust offsets since child window rectangles are
301 * in client coordinates */
303 xoffset = wndPtr->rectClient.left - wndPtr->rectWindow.left;
304 yoffset = wndPtr->rectClient.top - wndPtr->rectWindow.top;
307 xoffset = yoffset = 0;
309 /* client coordinates of child window */
310 xoffset += childWnd->rectClient.left;
311 yoffset += childWnd->rectClient.top;
313 DCE_AddClipRects( childWnd->child, NULL, hrgnClip,
314 &rect, xoffset, yoffset );
317 /* sibling window rectangles are in client
318 * coordinates of the parent window */
320 if (flags & DCX_WINDOW)
322 xoffset = -wndPtr->rectWindow.left;
323 yoffset = -wndPtr->rectWindow.top;
327 xoffset = -wndPtr->rectClient.left;
328 yoffset = -wndPtr->rectClient.top;
331 if (flags & DCX_CLIPSIBLINGS && wndPtr->parent )
332 DCE_AddClipRects( wndPtr->parent->child,
333 wndPtr, hrgnClip, &rect, xoffset, yoffset );
335 /* Clip siblings of all ancestors that have the
336 * WS_CLIPSIBLINGS style
339 while (wndPtr->parent)
341 WIN_UpdateWndPtr(&wndPtr,wndPtr->parent);
342 xoffset -= wndPtr->rectClient.left;
343 yoffset -= wndPtr->rectClient.top;
344 if(wndPtr->dwStyle & WS_CLIPSIBLINGS && wndPtr->parent)
346 DCE_AddClipRects( wndPtr->parent->child, wndPtr,
347 hrgnClip, &rect, xoffset, yoffset );
351 /* Now once we've got a jumbo clip region we have
352 * to substract it from the visible rectangle.
354 CombineRgn( hrgnVis, hrgnVis, hrgnClip, RGN_DIFF );
355 DeleteObject( hrgnClip );
359 DeleteObject( hrgnVis );
365 hrgnVis = CreateRectRgn(0, 0, 0, 0); /* empty */
366 WIN_ReleaseWndPtr(wndPtr);
367 WIN_ReleaseWndPtr(childWnd);
372 /***********************************************************************
375 * Set the drawable, origin and dimensions for the DC associated to
378 BOOL TTYDRV_GetDC( HWND hwnd, HDC hdc, HRGN hrgn, DWORD flags )
380 WND *wndPtr = WIN_FindWndPtr(hwnd);
383 HRGN hrgnVisible = 0;
385 if (!wndPtr) return FALSE;
387 if (!(dc = DC_GetDCPtr( hdc )))
389 WIN_ReleaseWndPtr( wndPtr );
393 if(flags & DCX_WINDOW)
395 dc->DCOrgX = wndPtr->rectWindow.left;
396 dc->DCOrgY = wndPtr->rectWindow.top;
400 dc->DCOrgX = wndPtr->rectClient.left;
401 dc->DCOrgY = wndPtr->rectClient.top;
403 updateVisRgn = (dc->flags & DC_DIRTY) != 0;
404 GDI_ReleaseObj( hdc );
408 if (flags & DCX_PARENTCLIP)
410 WND *parentPtr = WIN_LockWndPtr(wndPtr->parent);
412 if( wndPtr->dwStyle & WS_VISIBLE && !(parentPtr->dwStyle & WS_MINIMIZE) )
416 if( parentPtr->dwStyle & WS_CLIPSIBLINGS )
417 dcxFlags = DCX_CLIPSIBLINGS | (flags & ~(DCX_CLIPCHILDREN | DCX_WINDOW));
419 dcxFlags = flags & ~(DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN | DCX_WINDOW);
421 hrgnVisible = DCE_GetVisRgn( parentPtr->hwndSelf, dcxFlags,
422 wndPtr->hwndSelf, flags );
423 if( flags & DCX_WINDOW )
424 OffsetRgn( hrgnVisible, -wndPtr->rectWindow.left,
425 -wndPtr->rectWindow.top );
427 OffsetRgn( hrgnVisible, -wndPtr->rectClient.left,
428 -wndPtr->rectClient.top );
429 DCE_OffsetVisRgn( hdc, hrgnVisible );
432 hrgnVisible = CreateRectRgn( 0, 0, 0, 0 );
433 WIN_ReleaseWndPtr(parentPtr);
437 hrgnVisible = DCE_GetVisRgn( hwnd, flags, 0, 0 );
438 DCE_OffsetVisRgn( hdc, hrgnVisible );
440 SelectVisRgn16( hdc, hrgnVisible );
443 /* apply additional region operation (if any) */
445 if( flags & (DCX_EXCLUDERGN | DCX_INTERSECTRGN) )
447 if( !hrgnVisible ) hrgnVisible = CreateRectRgn( 0, 0, 0, 0 );
449 TRACE("\tsaved VisRgn, clipRgn = %04x\n", hrgn);
452 CombineRgn( hrgnVisible, hrgn, 0, RGN_COPY );
453 DCE_OffsetVisRgn( hdc, hrgnVisible );
454 CombineRgn( hrgnVisible, InquireVisRgn16( hdc ), hrgnVisible,
455 (flags & DCX_INTERSECTRGN) ? RGN_AND : RGN_DIFF );
456 SelectVisRgn16( hdc, hrgnVisible );
459 if (hrgnVisible) DeleteObject( hrgnVisible );
461 WIN_ReleaseWndPtr( wndPtr );
466 /***********************************************************************
467 * SetWindowPos (TTYDRV.@)
469 BOOL TTYDRV_SetWindowPos( WINDOWPOS *winpos )
472 RECT newWindowRect, newClientRect;
474 HWND hwndActive = GetForegroundWindow();
476 TRACE( "hwnd %04x, swp (%i,%i)-(%i,%i) flags %08x\n",
477 winpos->hwnd, winpos->x, winpos->y,
478 winpos->x + winpos->cx, winpos->y + winpos->cy, winpos->flags);
480 /* ------------------------------------------------------------------------ CHECKS */
482 /* Check window handle */
484 if (winpos->hwnd == GetDesktopWindow()) return FALSE;
485 if (!(wndPtr = WIN_FindWndPtr( winpos->hwnd ))) return FALSE;
487 TRACE("\tcurrent (%i,%i)-(%i,%i), style %08x\n",
488 wndPtr->rectWindow.left, wndPtr->rectWindow.top,
489 wndPtr->rectWindow.right, wndPtr->rectWindow.bottom, (unsigned)wndPtr->dwStyle );
491 /* Fix redundant flags */
493 if(wndPtr->dwStyle & WS_VISIBLE)
494 winpos->flags &= ~SWP_SHOWWINDOW;
497 if (!(winpos->flags & SWP_SHOWWINDOW)) winpos->flags |= SWP_NOREDRAW;
498 winpos->flags &= ~SWP_HIDEWINDOW;
501 if ( winpos->cx < 0 ) winpos->cx = 0;
502 if ( winpos->cy < 0 ) winpos->cy = 0;
504 if ((wndPtr->rectWindow.right - wndPtr->rectWindow.left == winpos->cx) &&
505 (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top == winpos->cy))
506 winpos->flags |= SWP_NOSIZE; /* Already the right size */
508 if ((wndPtr->rectWindow.left == winpos->x) && (wndPtr->rectWindow.top == winpos->y))
509 winpos->flags |= SWP_NOMOVE; /* Already the right position */
511 if (winpos->hwnd == hwndActive)
512 winpos->flags |= SWP_NOACTIVATE; /* Already active */
513 else if ( (wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD )
515 if(!(winpos->flags & SWP_NOACTIVATE)) /* Bring to the top when activating */
517 winpos->flags &= ~SWP_NOZORDER;
518 winpos->hwndInsertAfter = HWND_TOP;
523 /* Check hwndInsertAfter */
525 /* FIXME: TOPMOST not supported yet */
526 if ((winpos->hwndInsertAfter == HWND_TOPMOST) ||
527 (winpos->hwndInsertAfter == HWND_NOTOPMOST)) winpos->hwndInsertAfter = HWND_TOP;
529 /* hwndInsertAfter must be a sibling of the window */
530 if ((winpos->hwndInsertAfter != HWND_TOP) && (winpos->hwndInsertAfter != HWND_BOTTOM))
532 WND* wnd = WIN_FindWndPtr(winpos->hwndInsertAfter);
535 if( wnd->parent != wndPtr->parent )
538 WIN_ReleaseWndPtr(wnd);
541 /* don't need to change the Zorder of hwnd if it's already inserted
542 * after hwndInsertAfter or when inserting hwnd after itself.
544 if(( wnd->next == wndPtr ) || (winpos->hwnd == winpos->hwndInsertAfter))
545 winpos->flags |= SWP_NOZORDER;
547 WIN_ReleaseWndPtr(wnd);
550 Pos: /* ------------------------------------------------------------------------ MAIN part */
552 /* Send WM_WINDOWPOSCHANGING message */
554 if (!(winpos->flags & SWP_NOSENDCHANGING))
555 SendMessageA( wndPtr->hwndSelf, WM_WINDOWPOSCHANGING, 0, (LPARAM)winpos );
557 /* Calculate new position and size */
559 newWindowRect = wndPtr->rectWindow;
560 newClientRect = (wndPtr->dwStyle & WS_MINIMIZE) ? wndPtr->rectWindow
561 : wndPtr->rectClient;
563 if (!(winpos->flags & SWP_NOSIZE))
565 newWindowRect.right = newWindowRect.left + winpos->cx;
566 newWindowRect.bottom = newWindowRect.top + winpos->cy;
568 if (!(winpos->flags & SWP_NOMOVE))
570 newWindowRect.left = winpos->x;
571 newWindowRect.top = winpos->y;
572 newWindowRect.right += winpos->x - wndPtr->rectWindow.left;
573 newWindowRect.bottom += winpos->y - wndPtr->rectWindow.top;
575 OffsetRect( &newClientRect, winpos->x - wndPtr->rectWindow.left,
576 winpos->y - wndPtr->rectWindow.top );
579 if( winpos->hwndInsertAfter == HWND_TOP )
580 winpos->flags |= ( wndPtr->parent->child == wndPtr)? SWP_NOZORDER: 0;
582 if( winpos->hwndInsertAfter == HWND_BOTTOM )
583 winpos->flags |= ( wndPtr->next )? 0: SWP_NOZORDER;
585 if( !(winpos->flags & SWP_NOZORDER) )
586 if( GetWindow(winpos->hwndInsertAfter, GW_HWNDNEXT) == wndPtr->hwndSelf )
587 winpos->flags |= SWP_NOZORDER;
589 /* Common operations */
591 /* Send WM_NCCALCSIZE message to get new client area */
592 if( (winpos->flags & (SWP_FRAMECHANGED | SWP_NOSIZE)) != SWP_NOSIZE )
594 WINPOS_SendNCCalcSize( winpos->hwnd, TRUE, &newWindowRect,
595 &wndPtr->rectWindow, &wndPtr->rectClient,
596 winpos, &newClientRect );
599 if(!(winpos->flags & SWP_NOZORDER) && winpos->hwnd != winpos->hwndInsertAfter)
601 if ( WIN_UnlinkWindow( winpos->hwnd ) )
602 WIN_LinkWindow( winpos->hwnd, winpos->hwndInsertAfter );
605 /* FIXME: actually do something with WVR_VALIDRECTS */
607 wndPtr->rectWindow = newWindowRect;
608 wndPtr->rectClient = newClientRect;
610 if( winpos->flags & SWP_SHOWWINDOW )
612 wndPtr->dwStyle |= WS_VISIBLE;
614 else if( winpos->flags & SWP_HIDEWINDOW )
616 wndPtr->dwStyle &= ~WS_VISIBLE;
619 /* ------------------------------------------------------------------------ FINAL */
621 /* repaint invalidated region (if any)
623 * FIXME: if SWP_NOACTIVATE is not set then set invalid regions here without any painting
624 * and force update after ChangeActiveWindow() to avoid painting frames twice.
627 if( !(winpos->flags & SWP_NOREDRAW) )
629 RedrawWindow( wndPtr->parent->hwndSelf, NULL, 0,
630 RDW_ERASE | RDW_INVALIDATE | RDW_ALLCHILDREN );
631 if (wndPtr->parent->hwndSelf == GetDesktopWindow() ||
632 wndPtr->parent->parent->hwndSelf == GetDesktopWindow())
634 RedrawWindow( wndPtr->parent->hwndSelf, NULL, 0,
635 RDW_ERASENOW | RDW_NOCHILDREN );
639 if (!(winpos->flags & SWP_NOACTIVATE))
640 WINPOS_ChangeActiveWindow( winpos->hwnd, FALSE );
642 /* And last, send the WM_WINDOWPOSCHANGED message */
644 TRACE("\tstatus flags = %04x\n", winpos->flags & SWP_AGG_STATUSFLAGS);
646 if ((((winpos->flags & SWP_AGG_STATUSFLAGS) != SWP_AGG_NOPOSCHANGE) &&
647 !(winpos->flags & SWP_NOSENDCHANGING)) )
648 SendMessageA( winpos->hwnd, WM_WINDOWPOSCHANGED, 0, (LPARAM)winpos );
652 WIN_ReleaseWndPtr(wndPtr);