Use max tracking size instead of maximized size to limit window size.
[reactos.git] / reactos / lib / user32 / windows / defwnd.c
index 6d7ed4b..2756baa 100644 (file)
 
 /* INCLUDES ******************************************************************/
 
-#include "user32.h"
-#include <windowsx.h>
-#include <window.h>
-#include <user32/wininternal.h>
-#include <string.h>
-#include <cursor.h>
-#include <menu.h>
-#include <scroll.h>
-#include <winpos.h>
-
+#include <user32.h>
 #define NDEBUG
 #include <debug.h>
 
@@ -31,7 +22,7 @@
 #define WM_QUERYDROPOBJECT  0x022B
 #endif
 
-LRESULT DefWndNCPaint(HWND hWnd, HRGN hRgn);
+LRESULT DefWndNCPaint(HWND hWnd, HRGN hRgn, BOOL Active);
 LRESULT DefWndNCCalcSize(HWND hWnd, BOOL CalcSizeStruct, RECT *Rect);
 LRESULT DefWndNCActivate(HWND hWnd, WPARAM wParam);
 LRESULT DefWndNCHitTest(HWND hWnd, POINT Point);
@@ -78,7 +69,7 @@ GetSysColor(int nIndex)
   {
     return SysColors[nIndex];
   }
-  
+
   SetLastError(ERROR_INVALID_PARAMETER);
   return 0;
 }
@@ -132,7 +123,7 @@ SetSysColors(
 
   ChangeSysColors.Elements = (INT*)lpaElements;
   ChangeSysColors.Colors = (COLORREF*)lpaRgbValues;
-  
+
   if(cElements > 0)
   {
     Ret = NtUserSetSysColors(&ChangeSysColors, cElements);
@@ -147,7 +138,7 @@ SetSysColors(
     SetLastError(ERROR_INVALID_PARAMETER);
     Ret = FALSE;
   }
-  
+
   return Ret;
 }
 
@@ -286,15 +277,15 @@ DefWndHandleSetCursor(HWND hWnd, WPARAM wParam, LPARAM lParam, ULONG Style)
   return((LRESULT)SetCursor(LoadCursorW(0, IDC_ARROW)));
 }
 
-static LONG 
+static LONG
 DefWndStartSizeMove(HWND hWnd, WPARAM wParam, POINT *capturePoint)
 {
   LONG hittest = 0;
   POINT pt;
   MSG msg;
   RECT rectWindow;
-  ULONG Style = GetWindowLongW(hWnd, GWL_STYLE); 
-  
+  ULONG Style = GetWindowLongW(hWnd, GWL_STYLE);
+
   GetWindowRect(hWnd, &rectWindow);
 
   if ((wParam & 0xfff0) == SC_MOVE)
@@ -315,9 +306,11 @@ DefWndStartSizeMove(HWND hWnd, WPARAM wParam, POINT *capturePoint)
     }
   else  /* SC_SIZE */
     {
+      pt.x = pt.y = 0;
       while(!hittest)
        {
-         GetMessageW(&msg, NULL, 0, 0);
+         if (GetMessageW(&msg, NULL, 0, 0) <= 0)
+           break;
          switch(msg.message)
            {
            case WM_MOUSEMOVE:
@@ -325,10 +318,10 @@ DefWndStartSizeMove(HWND hWnd, WPARAM wParam, POINT *capturePoint)
              if ((hittest < HTLEFT) || (hittest > HTBOTTOMRIGHT))
                hittest = 0;
              break;
-             
+
            case WM_LBUTTONUP:
              return 0;
-             
+
            case WM_KEYDOWN:
              switch(msg.wParam)
                {
@@ -373,22 +366,23 @@ DefWndStartSizeMove(HWND hWnd, WPARAM wParam, POINT *capturePoint)
 #define ON_BOTTOM_BORDER(hit) \
  (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
 
-VOID STATIC 
+VOID STATIC
 UserDrawWindowFrame(HDC hdc, const RECT *rect,
                    ULONG width, ULONG height)
 {
   static HBRUSH hDraggingRectBrush = NULL;
-  
+  HBRUSH hbrush;
+
   if(!hDraggingRectBrush)
   {
     static HBITMAP hDraggingPattern = NULL;
     const DWORD Pattern[4] = {0x5555AAAA, 0x5555AAAA, 0x5555AAAA, 0x5555AAAA};
-    
+
     hDraggingPattern = CreateBitmap(8, 8, 1, 1, Pattern);
     hDraggingRectBrush = CreatePatternBrush(hDraggingPattern);
   }
-  
-  HBRUSH hbrush = SelectObject( hdc, hDraggingRectBrush );
+
+  hbrush = SelectObject( hdc, hDraggingRectBrush );
   PatBlt( hdc, rect->left, rect->top,
          rect->right - rect->left - width, height, PATINVERT );
   PatBlt( hdc, rect->left, rect->top + height, width,
@@ -425,7 +419,7 @@ DefWndDoSizeMove(HWND hwnd, WORD wParam)
   POINT minTrack, maxTrack;
   POINT capturePoint, pt;
   ULONG Style = GetWindowLongW(hwnd, GWL_STYLE);
-  ULONG ExStyle = GetWindowLongW(hwnd, GWL_EXSTYLE); 
+  ULONG ExStyle = GetWindowLongW(hwnd, GWL_EXSTYLE);
   BOOL thickframe;
   BOOL iconic = Style & WS_MINIMIZE;
   BOOL moved = FALSE;
@@ -434,20 +428,20 @@ DefWndDoSizeMove(HWND hwnd, WORD wParam)
   HWND hWndParent = NULL;
 
   SystemParametersInfoA(SPI_GETDRAGFULLWINDOWS, 0, &DragFullWindows, 0);
-  
+
   pt.x = GET_X_LPARAM(dwPoint);
   pt.y = GET_Y_LPARAM(dwPoint);
   capturePoint = pt;
-  
+
   if (IsZoomed(hwnd) || !IsWindowVisible(hwnd))
     {
       return;
     }
-  
+
   thickframe = UserHasThickFrameStyle(Style, ExStyle) && !(Style & WS_MINIMIZE);
   if ((wParam & 0xfff0) == SC_MOVE)
     {
-      if (!hittest) 
+      if (!hittest)
        {
          hittest = DefWndStartSizeMove(hwnd, wParam, &capturePoint);
        }
@@ -478,24 +472,20 @@ DefWndDoSizeMove(HWND hwnd, WORD wParam)
        }
     }
 
-  if (Style & WS_CHILD)
-    {
-      hWndParent = GetParent(hwnd);
-    }
-  
   /* Get min/max info */
-  
+
   WinPosGetMinMaxInfo(hwnd, NULL, NULL, &minTrack, &maxTrack);
   GetWindowRect(hwnd, &sizingRect);
-  unmodRect = sizingRect;
   if (Style & WS_CHILD)
     {
+      hWndParent = GetParent(hwnd);
       MapWindowPoints( 0, hWndParent, (LPPOINT)&sizingRect, 2 );
+      unmodRect = sizingRect;
       GetClientRect(hWndParent, &mouseRect );
       clipRect = mouseRect;
       MapWindowPoints(hWndParent, HWND_DESKTOP, (LPPOINT)&clipRect, 2);
     }
-  else 
+  else
     {
       if(!(ExStyle & WS_EX_TOPMOST))
       {
@@ -507,9 +497,10 @@ DefWndDoSizeMove(HWND hwnd, WORD wParam)
         SetRect(&mouseRect, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
         clipRect = mouseRect;
       }
+      unmodRect = sizingRect;
     }
   ClipCursor(&clipRect);
-  
+
   origRect = sizingRect;
   if (ON_LEFT_BORDER(hittest))
     {
@@ -532,14 +523,14 @@ DefWndDoSizeMove(HWND hwnd, WORD wParam)
       mouseRect.bottom = min( mouseRect.bottom, sizingRect.top+maxTrack.y );
     }
   if (Style & WS_CHILD)
-    {      
+    {
       MapWindowPoints( hWndParent, 0, (LPPOINT)&mouseRect, 2 );
     }
-  
+
   SendMessageA( hwnd, WM_ENTERSIZEMOVE, 0, 0 );
   NtUserSetGUIThreadHandle(MSQ_STATE_MOVESIZE, hwnd);
-  if (GetCapture() != hwnd) SetCapture( hwnd );    
-  
+  if (GetCapture() != hwnd) SetCapture( hwnd );
+
   if (Style & WS_CHILD)
     {
       /* Retrieve a default cache DC (without using the window style) */
@@ -551,9 +542,9 @@ DefWndDoSizeMove(HWND hwnd, WORD wParam)
       hdc = GetDC( 0 );
       DesktopRgn = CreateRectRgnIndirect(&clipRect);
     }
-  
+
   SelectObject(hdc, DesktopRgn);
-  
+
   if( iconic ) /* create a cursor for dragging */
     {
       HICON hIcon = (HICON)GetClassLongW(hwnd, GCL_HICON);
@@ -561,24 +552,25 @@ DefWndDoSizeMove(HWND hwnd, WORD wParam)
       if( hIcon ) hDragCursor = CursorIconToCursor( hIcon, TRUE );
       if( !hDragCursor ) iconic = FALSE;
     }
-  
+
   /* invert frame if WIN31_LOOK to indicate mouse click on caption */
   if( !iconic && !DragFullWindows)
     {
       UserDrawMovingFrame( hdc, &sizingRect, thickframe);
     }
-  
+
   for(;;)
     {
       int dx = 0, dy = 0;
 
-      GetMessageW(&msg, 0, 0, 0);
-      
+      if (GetMessageW(&msg, 0, 0, 0) <= 0)
+        break;
+
       /* Exit on button-up, Return, or Esc */
       if ((msg.message == WM_LBUTTONUP) ||
-         ((msg.message == WM_KEYDOWN) && 
+         ((msg.message == WM_KEYDOWN) &&
           ((msg.wParam == VK_RETURN) || (msg.wParam == VK_ESCAPE)))) break;
-      
+
       if (msg.message == WM_PAINT)
         {
          if(!iconic && !DragFullWindows) UserDrawMovingFrame( hdc, &sizingRect, thickframe );
@@ -586,47 +578,47 @@ DefWndDoSizeMove(HWND hwnd, WORD wParam)
          if(!iconic && !DragFullWindows) UserDrawMovingFrame( hdc, &sizingRect, thickframe );
          continue;
         }
-      
+
       if ((msg.message != WM_KEYDOWN) && (msg.message != WM_MOUSEMOVE))
        continue;  /* We are not interested in other messages */
-      
+
       pt = msg.pt;
-      
+
       if (msg.message == WM_KEYDOWN) switch(msg.wParam)
        {
        case VK_UP:    pt.y -= 8; break;
        case VK_DOWN:  pt.y += 8; break;
        case VK_LEFT:  pt.x -= 8; break;
-       case VK_RIGHT: pt.x += 8; break;                
+       case VK_RIGHT: pt.x += 8; break;
        }
-      
+
       pt.x = max( pt.x, mouseRect.left );
       pt.x = min( pt.x, mouseRect.right );
       pt.y = max( pt.y, mouseRect.top );
       pt.y = min( pt.y, mouseRect.bottom );
-      
+
       dx = pt.x - capturePoint.x;
       dy = pt.y - capturePoint.y;
-      
+
       if (dx || dy)
        {
          if( !moved )
            {
              moved = TRUE;
-             
+
                if( iconic ) /* ok, no system popup tracking */
                  {
                    hOldCursor = SetCursor(hDragCursor);
                    ShowCursor( TRUE );
-                 } 
+                 }
            }
-         
+
          if (msg.message == WM_KEYDOWN) SetCursorPos( pt.x, pt.y );
          else
            {
              RECT newRect = unmodRect;
              WPARAM wpSizingHit = 0;
-             
+
              if (hittest == HTCAPTION) OffsetRect( &newRect, dx, dy );
              if (ON_LEFT_BORDER(hittest)) newRect.left += dx;
              else if (ON_RIGHT_BORDER(hittest)) newRect.right += dx;
@@ -634,13 +626,13 @@ DefWndDoSizeMove(HWND hwnd, WORD wParam)
              else if (ON_BOTTOM_BORDER(hittest)) newRect.bottom += dy;
              if(!iconic && !DragFullWindows) UserDrawMovingFrame( hdc, &sizingRect, thickframe );
              capturePoint = pt;
-             
+
              /* determine the hit location */
              if (hittest >= HTLEFT && hittest <= HTBOTTOMRIGHT)
                wpSizingHit = WMSZ_LEFT + (hittest - HTLEFT);
              unmodRect = newRect;
              SendMessageA( hwnd, WM_SIZING, wpSizingHit, (LPARAM)&newRect );
-             
+
              if (!iconic)
                {
                  if(!DragFullWindows)
@@ -658,7 +650,7 @@ DefWndDoSizeMove(HWND hwnd, WORD wParam)
            }
        }
     }
-  
+
   ReleaseCapture();
   ClipCursor(NULL);
   if( iconic )
@@ -672,7 +664,7 @@ DefWndDoSizeMove(HWND hwnd, WORD wParam)
     }
   else if(!DragFullWindows)
       UserDrawMovingFrame( hdc, &sizingRect, thickframe );
-  
+
   if (Style & WS_CHILD)
     ReleaseDC( hWndParent, hdc );
   else
@@ -686,7 +678,7 @@ DefWndDoSizeMove(HWND hwnd, WORD wParam)
   NtUserSetGUIThreadHandle(MSQ_STATE_MOVESIZE, NULL);
   SendMessageA( hwnd, WM_EXITSIZEMOVE, 0, 0 );
   SendMessageA( hwnd, WM_SETVISIBLE, !IsIconic(hwnd), 0L);
-  
+
   /* window moved or resized */
   if (moved)
     {
@@ -708,17 +700,17 @@ DefWndDoSizeMove(HWND hwnd, WORD wParam)
                        origRect.right - origRect.left,
                        origRect.bottom - origRect.top,
                        ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
-      }      
+      }
     }
-  
+
   if( IsWindow(hwnd) )
     if( Style & WS_MINIMIZE )
       {
        /* Single click brings up the system menu when iconized */
-       
-       if( !moved ) 
+
+       if( !moved )
          {
-           if( Style & WS_SYSMENU ) 
+           if( Style & WS_SYSMENU )
              SendMessageA( hwnd, WM_SYSCOMMAND,
                            SC_MOUSEMENU + HTSYSMENU, MAKELONG(pt.x,pt.y));
          }
@@ -760,7 +752,7 @@ LRESULT
 DefWndHandleSysCommand(HWND hWnd, WPARAM wParam, POINT Pt)
 {
   WINDOWPLACEMENT wp;
-  
+
   switch (wParam & 0xfff0)
     {
       case SC_MOVE:
@@ -817,15 +809,15 @@ DefWndHandleSysCommand(HWND hWnd, WPARAM wParam, POINT Pt)
 LRESULT
 DefWndHandleWindowPosChanging(HWND hWnd, WINDOWPOS* Pos)
 {
-    POINT maxSize, minTrack;
+    POINT maxTrack, minTrack;
     LONG style = GetWindowLongA(hWnd, GWL_STYLE);
 
     if (Pos->flags & SWP_NOSIZE) return 0;
     if ((style & WS_THICKFRAME) || ((style & (WS_POPUP | WS_CHILD)) == 0))
     {
-        WinPosGetMinMaxInfo(hWnd, &maxSize, NULL, &minTrack, NULL);
-        Pos->cx = min(Pos->cx, maxSize.x);
-        Pos->cy = min(Pos->cy, maxSize.y);
+        WinPosGetMinMaxInfo(hWnd, NULL, NULL, &minTrack, &maxTrack);
+        Pos->cx = min(Pos->cx, maxTrack.x);
+        Pos->cy = min(Pos->cy, maxTrack.y);
         if (!(style & WS_MINIMIZE))
         {
             if (Pos->cx < minTrack.x) Pos->cx = minTrack.x;
@@ -933,7 +925,7 @@ DefWndControlColor(HDC hDC, UINT ctlType)
 VOID FASTCALL
 DefWndScreenshot(HWND hWnd)
 {
-   
+
 }
 
 LRESULT STDCALL
@@ -947,7 +939,7 @@ User32DefWindowProc(HWND hWnd,
     {
        case WM_NCPAINT:
        {
-            return DefWndNCPaint(hWnd, (HRGN)wParam);
+            return DefWndNCPaint(hWnd, (HRGN)wParam, -1);
         }
 
         case WM_NCCALCSIZE:
@@ -1028,9 +1020,9 @@ User32DefWindowProc(HWND hWnd,
                 POINT Pt;
                 DWORD Style;
                 LONG HitCode;
-                
+
                 Style = GetWindowLongW(hWnd, GWL_STYLE);
-                
+
                 Pt.x = GET_X_LPARAM(lParam);
                 Pt.y = GET_Y_LPARAM(lParam);
                 if (Style & WS_CHILD)
@@ -1044,17 +1036,17 @@ User32DefWindowProc(HWND hWnd,
                 {
                     HMENU SystemMenu;
                     UINT Flags;
-                    
+
                     if((SystemMenu = GetSystemMenu(hWnd, FALSE)))
                     {
                       MenuInitSysMenuPopup(SystemMenu, GetWindowLongW(hWnd, GWL_STYLE),
                                            GetClassLongW(hWnd, GCL_STYLE), HitCode);
-                      
+
                       if(HitCode == HTCAPTION)
                         Flags = TPM_LEFTBUTTON | TPM_RIGHTBUTTON;
                       else
                         Flags = TPM_LEFTBUTTON;
-                      
+
                       TrackPopupMenu(SystemMenu, Flags,
                                      Pt.x, Pt.y, 0, hWnd, NULL);
                     }
@@ -1062,7 +1054,7 @@ User32DefWindowProc(HWND hWnd,
            }
             break;
         }
-        
+
         case WM_PRINT:
         {
             /* FIXME: Implement. */
@@ -1075,7 +1067,7 @@ User32DefWindowProc(HWND hWnd,
             PAINTSTRUCT Ps;
             HDC hDC = BeginPaint(hWnd, &Ps);
             if (hDC)
-            {          
+            {
                 HICON hIcon;
                 if (GetWindowLongW(hWnd, GWL_STYLE) & WS_MINIMIZE &&
                     (hIcon = (HICON)GetClassLongW(hWnd, GCL_HICON)) != NULL)
@@ -1088,7 +1080,7 @@ User32DefWindowProc(HWND hWnd,
                     y = (ClientRect.bottom - ClientRect.top -
                          GetSystemMetrics(SM_CYICON)) / 2;
                     DrawIcon(hDC, x, y, hIcon);
-                } 
+                }
                 EndPaint(hWnd, &Ps);
             }
             return (0);
@@ -1195,7 +1187,7 @@ User32DefWindowProc(HWND hWnd,
             FillRect((HDC)wParam, &Rect, hBrush);
             return (1);
         }
-        
+
         case WM_CTLCOLORMSGBOX:
         case WM_CTLCOLOREDIT:
         case WM_CTLCOLORLISTBOX:
@@ -1208,7 +1200,7 @@ User32DefWindowProc(HWND hWnd,
         case WM_SETCURSOR:
         {
             ULONG Style = GetWindowLongW(hWnd, GWL_STYLE);
-            
+
             if (Style & WS_CHILD)
             {
                 if (LOWORD(lParam) < HTLEFT || LOWORD(lParam) > HTBOTTOMRIGHT)
@@ -1272,7 +1264,7 @@ User32DefWindowProc(HWND hWnd,
             }
             break;
         }
-        
+
         case WM_SHOWWINDOW:
         {
             LONG Style;
@@ -1280,14 +1272,15 @@ User32DefWindowProc(HWND hWnd,
             if (!lParam)
                 return 0;
             Style = GetWindowLongW(hWnd, GWL_STYLE);
-            if (!(Style & WS_POPUP))
-                return 0;
+//            if (!(Style & WS_POPUP))
+//                return 0;
             if ((Style & WS_VISIBLE) && wParam)
                 return 0;
             if (!(Style & WS_VISIBLE) && !wParam)
                 return 0;
             if (!GetWindow(hWnd, GW_OWNER))
                 return 0;
+            NtUserCallTwoParam((DWORD) hWnd, (DWORD) wParam, TWOPARAM_ROUTINE_ROS_SHOWWINDOW);
             ShowWindow(hWnd, wParam ? SW_SHOWNA : SW_HIDE);
             break;
         }
@@ -1307,7 +1300,7 @@ User32DefWindowProc(HWND hWnd,
             return (-1);
 /*
         case WM_DROPOBJECT:
-  
+
             break;
 */
         case WM_QUERYDROPOBJECT:
@@ -1382,7 +1375,7 @@ User32DefWindowProc(HWND hWnd,
             }
             break;
         }
-        
+
         case WM_SYSTIMER:
         {
           THRDCARETINFO CaretInfo;
@@ -1457,7 +1450,7 @@ DefWindowProcA(HWND hWnd,
         {
             ANSI_STRING AnsiString;
             UNICODE_STRING UnicodeString;
-            
+
             if(lParam)
             {
               RtlInitAnsiString(&AnsiString, (LPSTR)lParam);
@@ -1467,10 +1460,10 @@ DefWindowProcA(HWND hWnd,
             }
             else
               NtUserDefSetText(hWnd, NULL);
-            
+
             if ((GetWindowLongW(hWnd, GWL_STYLE) & WS_CAPTION) == WS_CAPTION)
             {
-                DefWndNCPaint(hWnd, (HRGN)1);
+                DefWndNCPaint(hWnd, (HRGN)1, -1);
             }
             return TRUE;
         }
@@ -1525,12 +1518,12 @@ DefWindowProcW(HWND hWnd,
 
             if(lParam)
               RtlInitUnicodeString(&UnicodeString, (LPWSTR)lParam);
-            
+
             NtUserDefSetText(hWnd, (lParam ? &UnicodeString : NULL));
-            
+
             if ((GetWindowLongW(hWnd, GWL_STYLE) & WS_CAPTION) == WS_CAPTION)
             {
-                DefWndNCPaint(hWnd, (HRGN)1);
+                DefWndNCPaint(hWnd, (HRGN)1, -1);
             }
             return (1);
         }