[Win32k]
[reactos.git] / reactos / win32ss / user / user32 / windows / mdi.c
index d24eb03..ae86741 100644 (file)
@@ -123,6 +123,7 @@ typedef struct
     UINT      nTotalCreated;
     UINT      mdiFlags;
     UINT      sbRecalc;   /* SB_xxx flags for scrollbar fixup */
+    DWORD     initialStyle; /* Style when window was created */ // See http://bugs.winehq.org/show_bug.cgi?id=9435
     HBITMAP   hBmpClose; /* ReactOS modification */
 } MDICLIENTINFO;
 
@@ -792,7 +793,7 @@ static LONG MDICascade( HWND client, MDICLIENTINFO *ci )
 static void MDITile( HWND client, MDICLIENTINFO *ci, WPARAM wParam )
 {
     HWND *win_array;
-    int i, total;
+    int i, total, rows, columns;
     BOOL has_icons = FALSE;
 
     if (ci->hwndChildMaximized)
@@ -803,7 +804,7 @@ static void MDITile( HWND client, MDICLIENTINFO *ci, WPARAM wParam )
     if (!(win_array = WIN_ListChildren( client ))) return;
 
     /* remove all the windows we don't want */
-    for (i = total = 0; win_array[i]; i++)
+    for (i = total = rows = 0; win_array[i]; i++)
     {
         if (!IsWindowVisible( win_array[i] )) continue;
         if (GetWindow( win_array[i], GW_OWNER )) continue; /* skip owned windows (icon titles) */
@@ -813,6 +814,7 @@ static void MDITile( HWND client, MDICLIENTINFO *ci, WPARAM wParam )
             continue;
         }
         if ((wParam & MDITILE_SKIPDISABLED) && !IsWindowEnabled( win_array[i] )) continue;
+        if(total == (rows * (rows + 2))) rows++; /* total+1 == (rows+1)*(rows+1) */
         win_array[total++] = win_array[i];
     }
     win_array[total] = 0;
@@ -824,11 +826,11 @@ static void MDITile( HWND client, MDICLIENTINFO *ci, WPARAM wParam )
         HWND *pWnd = win_array;
         RECT rect;
         int x, y, xsize, ysize;
-        int rows, columns, r, c, i;
+        int r, c, i;
 
         GetClientRect(client,&rect);
-        rows    = (int) sqrt((double)total);
-        columns = total / rows;
+        columns = total/rows;
+        //while(total < rows*columns) rows++;
 
         if( wParam & MDITILE_HORIZONTAL )  /* version >= 3.1 */
         {
@@ -895,8 +897,11 @@ static BOOL MDI_AugmentFrameMenu( HWND frame, HWND hChild )
     nItems = GetMenuItemCount(menu) - 1;
     iId = GetMenuItemID(menu,nItems) ;
     if (iId == SC_RESTORE || iId == SC_CLOSE)
+    {
+        ERR("system buttons already exist\n");
        return 0;
-
+    }
+//// End
     /* create a copy of sysmenu popup and insert it into frame menu bar */
     if (!(hSysPopup = GetSystemMenu(hChild, FALSE)))
     {
@@ -905,20 +910,19 @@ static BOOL MDI_AugmentFrameMenu( HWND frame, HWND hChild )
     }
 
     AppendMenuW(menu, MF_HELP | MF_BITMAP,
-                SC_MINIMIZE, (LPCWSTR)HBMMENU_MBAR_MINIMIZE ) ;
+                SC_CLOSE, is_close_enabled(hChild, hSysPopup) ?
+                (LPCWSTR)HBMMENU_MBAR_CLOSE : (LPCWSTR)HBMMENU_MBAR_CLOSE_D );
     AppendMenuW(menu, MF_HELP | MF_BITMAP,
                 SC_RESTORE, (LPCWSTR)HBMMENU_MBAR_RESTORE );
     AppendMenuW(menu, MF_HELP | MF_BITMAP,
-                SC_CLOSE, is_close_enabled(hChild, hSysPopup) ?
-                (LPCWSTR)HBMMENU_MBAR_CLOSE : (LPCWSTR)HBMMENU_MBAR_CLOSE_D );
+                SC_MINIMIZE, (LPCWSTR)HBMMENU_MBAR_MINIMIZE ) ;
 
     /* The system menu is replaced by the child icon */
-    hIcon = (HICON)GetClassLongPtrW(hChild, GCLP_HICONSM);
+    hIcon = (HICON)SendMessageW(hChild, WM_GETICON, ICON_SMALL, 0);
     if (!hIcon)
-        hIcon = (HICON)GetClassLongPtrW(hChild, GCLP_HICON);
+        hIcon = (HICON)SendMessageW(hChild, WM_GETICON, ICON_BIG, 0);
     if (!hIcon)
-        hIcon = LoadIconW(NULL, IDI_APPLICATION);
-//// End
+        hIcon = LoadImageW(0, MAKEINTRESOURCEW(IDI_WINLOGO), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR);
     if (hIcon)
     {
       HDC hMemDC;
@@ -982,7 +986,10 @@ static BOOL MDI_RestoreFrameMenu( HWND frame, HWND hChild, HBITMAP hBmpClose )
     nItems = GetMenuItemCount(menu) - 1;
     iId = GetMenuItemID(menu,nItems) ;
     if( !(iId == SC_RESTORE || iId == SC_CLOSE) )
+    {
+        ERR("no system buttons then nothing to do\n");
        return 0;
+    }
 
     /*
      * Remove the system menu, If that menu is the icon of the window
@@ -1139,7 +1146,8 @@ LRESULT WINAPI MDIClientWndProc_common( HWND hwnd, UINT message, WPARAM wParam,
        ci->nTotalCreated       = 0;
        ci->frameTitle          = NULL;
        ci->mdiFlags            = 0;
-        ci->hFrameMenu = GetMenu(cs->hwndParent);
+       ci->initialStyle        = cs->style;
+       ci->hFrameMenu = GetMenu(cs->hwndParent);
 
        if (!ci->hBmpClose) ci->hBmpClose = CreateMDIMenuBitmap();
 
@@ -1230,8 +1238,11 @@ LRESULT WINAPI MDIClientWndProc_common( HWND hwnd, UINT message, WPARAM wParam,
 
       case WM_MDINEXT: /* lParam != 0 means previous window */
       {
-        HWND next = MDI_GetWindow( ci, (HWND)wParam, !lParam, 0 );
+        HWND hwnd = wParam ? WIN_GetFullHandle((HWND)wParam) : ci->hwndActiveChild;
+        HWND next = MDI_GetWindow( ci, hwnd, !lParam, 0 );
         MDI_SwitchActiveChild( ci, next, TRUE );
+        if(!lParam)
+            SetWindowPos(hwnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
        break;
       }
 
@@ -1430,7 +1441,7 @@ LRESULT WINAPI DefFrameProcW( HWND hwnd, HWND hwndMDIClient,
                     case SC_NEXTWINDOW:
                     case SC_PREVWINDOW:
                     case SC_RESTORE:
-                        return SendMessageW( ci->hwndActiveChild, WM_SYSCOMMAND,
+                        return SendMessageW( ci->hwndChildMaximized, WM_SYSCOMMAND,
                                              wParam, lParam);
                     }
                 }
@@ -1522,9 +1533,7 @@ LRESULT WINAPI DefMDIChildProcA( HWND hwnd, UINT message,
     case WM_CHILDACTIVATE:
     case WM_SYSCOMMAND:
     case WM_SHOWWINDOW:
-#ifndef __REACTOS__
     case WM_SETVISIBLE:
-#endif
     case WM_SIZE:
     case WM_NEXTMENU:
     case WM_SYSCHAR:
@@ -1562,7 +1571,7 @@ LRESULT WINAPI DefMDIChildProcW( HWND hwnd, UINT message,
         return 0;
 
     case WM_MENUCHAR:
-        return 0x00010000; /* MDI children don't have menu bars */
+        return MAKELRESULT( 0, MNC_CLOSE ); /* MDI children don't have menu bars */
 
     case WM_CLOSE:
         SendMessageW( client, WM_MDIDESTROY, (WPARAM)hwnd, 0 );
@@ -1592,20 +1601,19 @@ LRESULT WINAPI DefMDIChildProcW( HWND hwnd, UINT message,
                 return SendMessageW( GetParent(client), message, wParam, lParam);
             break;
         case SC_NEXTWINDOW:
-            SendMessageW( client, WM_MDINEXT, 0, 0);
+            SendMessageW( client, WM_MDINEXT, (WPARAM)ci->hwndActiveChild, 0);
             return 0;
         case SC_PREVWINDOW:
-            SendMessageW( client, WM_MDINEXT, 0, 1);
+            SendMessageW( client, WM_MDINEXT, (WPARAM)ci->hwndActiveChild, 1);
             return 0;
         }
         break;
 
     case WM_SHOWWINDOW:
-#ifndef __REACTOS__
     case WM_SETVISIBLE:
-#endif
-        if (ci->hwndChildMaximized) ci->mdiFlags &= ~MDIF_NEEDUPDATE;
-        else MDI_PostUpdate(client, ci, SB_BOTH+1);
+        //// Commented out r57663
+        /*if (ci->hwndChildMaximized) ci->mdiFlags &= ~MDIF_NEEDUPDATE;
+        else*/ MDI_PostUpdate(client, ci, SB_BOTH+1);
         break;
 
     case WM_SIZE:
@@ -1801,8 +1809,10 @@ void WINAPI CalcChildScroll( HWND hwnd, INT scroll )
     SCROLLINFO info;
     RECT childRect, clientRect;
     HWND *list;
+    MDICLIENTINFO *ci;
     WINDOWINFO WindowInfo;
 
+    ci = get_client_info(hwnd);
     GetClientRect( hwnd, &clientRect );
     SetRectEmpty( &childRect );
 
@@ -1820,6 +1830,7 @@ void WINAPI CalcChildScroll( HWND hwnd, INT scroll )
         return;
     }
 
+    ERR("CalcChildScroll 1\n");
     if ((list = WIN_ListChildren( hwnd )))
     {
         int i;
@@ -1830,6 +1841,7 @@ void WINAPI CalcChildScroll( HWND hwnd, INT scroll )
             {
                 HeapFree( GetProcessHeap(), 0, list );
                 ShowScrollBar( hwnd, SB_BOTH, FALSE );
+                ERR("CalcChildScroll 2\n");
                 return;
             }
             if (style & WS_VISIBLE)
@@ -1838,14 +1850,15 @@ void WINAPI CalcChildScroll( HWND hwnd, INT scroll )
                 GetWindowRect( list[i], &rect );
                 OffsetRect(&rect, -WindowInfo.rcClient.left,
                                   -WindowInfo.rcClient.top);
+                //WIN_GetRectangles( list[i], COORDS_PARENT, &rect, NULL );
+                ERR("CalcChildScroll L\n");
                 UnionRect( &childRect, &rect, &childRect );
             }
         }
         HeapFree( GetProcessHeap(), 0, list );
     }
-    MapWindowPoints( 0, hwnd, (POINT *)&childRect, 2 );
     UnionRect( &childRect, &clientRect, &childRect );
-
+    ERR("CalcChildScroll 3\n");
     /* set common info values */
     info.cbSize = sizeof(info);
     info.fMask = SIF_POS | SIF_RANGE | SIF_PAGE;
@@ -1864,15 +1877,30 @@ void WINAPI CalcChildScroll( HWND hwnd, INT scroll )
                        info.nMax = childRect.right;
                        info.nPos = 0;
                        info.nPage = 1 + clientRect.right - clientRect.left;
-                       SetScrollInfo(hwnd, SB_HORZ, &info, TRUE);
-                       if (scroll == SB_HORZ) break;
+                       //info.nMax = childRect.right - clientRect.right;
+                       //info.nPos = clientRect.left - childRect.left;
+                       if (ci->initialStyle & WS_HSCROLL)
+                           SetScrollInfo(hwnd, SB_HORZ, &info, TRUE);
+                       if (scroll == SB_HORZ)
+                       {
+                           ERR("CalcChildScroll H\n");
+                          break;
+                       }
+                       else
+                       {
+                           ERR("CalcChildScroll B\n");
+                        }
                        /* fall through */
        case SB_VERT:
                        info.nMin = childRect.top;
                        info.nMax = childRect.bottom;
                        info.nPos = 0;
                        info.nPage = 1 + clientRect.bottom - clientRect.top;
-                       SetScrollInfo(hwnd, SB_VERT, &info, TRUE);
+                       //info.nMax = childRect.bottom - clientRect.bottom;
+                       //info.nPos = clientRect.top - childRect.top;
+                       ERR("CalcChildScroll V\n");
+                       if (ci->initialStyle & WS_VSCROLL)
+                           SetScrollInfo(hwnd, SB_VERT, &info, TRUE);
                        break;
     }
 }