[Win32k]
[reactos.git] / reactos / win32ss / user / ntuser / window.c
index c9d7c79..6259742 100644 (file)
@@ -459,7 +459,7 @@ UserFreeWindowInfo(PTHREADINFO ti, PWND Wnd)
    }
 
 //    DesktopHeapFree(Wnd->head.rpdesk, Wnd);
-//    WindowObject->Wnd = NULL;
+//    WindowObject->hWnd = NULL;
 }
 
 /***********************************************************************
@@ -479,7 +479,7 @@ static LRESULT co_UserFreeWindow(PWND Window,
    HWND *Children;
    HWND *ChildHandle;
    PWND Child;
-   PMENU_OBJECT Menu;
+   PMENU Menu;
    BOOLEAN BelongsToThreadData;
 
    ASSERT(Window);
@@ -792,7 +792,7 @@ IntSetMenu(
    HMENU Menu,
    BOOL *Changed)
 {
-   PMENU_OBJECT OldMenu, NewMenu = NULL;
+   PMENU OldMenu, NewMenu = NULL;
 
    if ((Wnd->style & (WS_CHILD | WS_POPUP)) == WS_CHILD)
    {
@@ -810,7 +810,7 @@ IntSetMenu(
    if (Wnd->IDMenu)
    {
       OldMenu = IntGetMenuObject((HMENU) Wnd->IDMenu);
-      ASSERT(NULL == OldMenu || OldMenu->MenuInfo.Wnd == Wnd->head.h);
+      ASSERT(NULL == OldMenu || OldMenu->hWnd == Wnd->head.h);
    }
    else
    {
@@ -829,7 +829,7 @@ IntSetMenu(
          EngSetLastError(ERROR_INVALID_MENU_HANDLE);
          return FALSE;
       }
-      if (NULL != NewMenu->MenuInfo.Wnd)
+      if (NULL != NewMenu->hWnd)
       {
          /* Can't use the same menu for two windows */
          if (NULL != OldMenu)
@@ -845,12 +845,12 @@ IntSetMenu(
    Wnd->IDMenu = (UINT) Menu;
    if (NULL != NewMenu)
    {
-      NewMenu->MenuInfo.Wnd = Wnd->head.h;
+      NewMenu->hWnd = Wnd->head.h;
       IntReleaseMenuObject(NewMenu);
    }
    if (NULL != OldMenu)
    {
-      OldMenu->MenuInfo.Wnd = NULL;
+      OldMenu->hWnd = NULL;
       IntReleaseMenuObject(OldMenu);
    }
 
@@ -895,13 +895,13 @@ co_DestroyThreadWindows(struct _ETHREAD *Thread)
    }
 }
 
-PMENU_OBJECT FASTCALL
+PMENU FASTCALL
 IntGetSystemMenu(PWND Window, BOOL bRevert, BOOL RetMenu)
 {
-   PMENU_OBJECT Menu, NewMenu = NULL, SysMenu = NULL, ret = NULL;
+   PMENU Menu, NewMenu = NULL, SysMenu = NULL, ret = NULL;
    PTHREADINFO W32Thread;
    HMENU hNewMenu, hSysMenu;
-   ROSMENUITEMINFO ItemInfo;
+   ROSMENUITEMINFO ItemInfo = {0};
 
    if(bRevert)
    {
@@ -929,10 +929,10 @@ IntGetSystemMenu(PWND Window, BOOL bRevert, BOOL RetMenu)
 
          NewMenu = IntCloneMenu(Menu);
          if(NewMenu)
-         {
-            Window->SystemMenu = NewMenu->MenuInfo.Self;
-            NewMenu->MenuInfo.Flags |= MNF_SYSDESKMN;
-            NewMenu->MenuInfo.Wnd = Window->head.h;
+         {  // Use spmenuSys
+            Window->SystemMenu = NewMenu->head.h;
+            NewMenu->fFlags |= MNF_SYSDESKMN;
+            NewMenu->hWnd = Window->head.h;
             ret = NewMenu;
             //IntReleaseMenuObject(NewMenu);
          }
@@ -950,9 +950,14 @@ IntGetSystemMenu(PWND Window, BOOL bRevert, BOOL RetMenu)
             UserDestroyMenu(hSysMenu);
             return NULL;
          }
-         SysMenu->MenuInfo.Flags |= MNF_SYSDESKMN;
-         SysMenu->MenuInfo.Wnd = Window->head.h;
+         SysMenu->fFlags |= MNF_SYSDESKMN;
+         SysMenu->hWnd = Window->head.h;
          hNewMenu = co_IntLoadSysMenuTemplate();
+         //if ( Window->ExStyle & WS_EX_MDICHILD )
+         //hNewMenu = co_IntCallLoadMenu( NULL, L"SYSMENUMDI");
+         // else
+         //hNewMenu = co_IntCallLoadMenu( NULL, L"SYSMENU");
+         // Do the rest in here.
          if(!hNewMenu)
          {
             IntReleaseMenuObject(SysMenu);
@@ -970,21 +975,24 @@ IntGetSystemMenu(PWND Window, BOOL bRevert, BOOL RetMenu)
          NewMenu = IntCloneMenu(Menu);
          if(NewMenu)
          {
-            NewMenu->MenuInfo.Flags |= MNF_SYSDESKMN | MNF_POPUP;
-            NewMenu->MenuInfo.dwStyle = MNS_CHECKORBMP;
+            NewMenu->fFlags |= MNF_SYSDESKMN | MNF_POPUP;
+            // Do not set MNS_CHECKORBMP it breaks menus, also original code destroyed the style anyway.
             IntReleaseMenuObject(NewMenu);
             UserSetMenuDefaultItem(NewMenu, SC_CLOSE, FALSE);
 
+            if (Window->pcls->style & CS_NOCLOSE)
+               IntRemoveMenuItem(NewMenu, SC_CLOSE, MF_BYCOMMAND, TRUE);
+
             ItemInfo.cbSize = sizeof(MENUITEMINFOW);
             ItemInfo.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_STATE | MIIM_SUBMENU;
             ItemInfo.fType = 0;
             ItemInfo.fState = MFS_ENABLED;
             ItemInfo.dwTypeData = NULL;
             ItemInfo.cch = 0;
-            ItemInfo.hSubMenu = NewMenu->MenuInfo.Self;
-            IntInsertMenuItem(SysMenu, (UINT) -1, TRUE, &ItemInfo);
+            ItemInfo.hSubMenu = NewMenu->head.h;
+            IntInsertMenuItem(SysMenu, (UINT) -1, TRUE, &ItemInfo, NULL);
 
-            Window->SystemMenu = SysMenu->MenuInfo.Self;
+            Window->SystemMenu = SysMenu->head.h;
 
             ret = SysMenu;
          }
@@ -1353,7 +1361,7 @@ co_IntSetParent(PWND Wnd, PWND WndNewParent)
    co_WinPosSetWindowPos( Wnd,
                          (0 == (Wnd->ExStyle & WS_EX_TOPMOST) ? HWND_TOP : HWND_TOPMOST),
                           pt.x, pt.y, 0, 0, swFlags);
-   //ERR("IntSetParent SetWindowPos 2\n");
+   //ERR("IntSetParent SetWindowPos 2 X %d Y %d\n",pt.x, pt.y);
    if (WasVisible) co_WinPosShowWindow(Wnd, SW_SHOWNORMAL);
 
    return WndOldParent;
@@ -1419,15 +1427,15 @@ co_UserSetParent(HWND hWndChild, HWND hWndNewParent)
 }
 
 BOOL FASTCALL
-IntSetSystemMenu(PWND Window, PMENU_OBJECT Menu)
+IntSetSystemMenu(PWND Window, PMENU Menu)
 {
-   PMENU_OBJECT OldMenu;
+   PMENU OldMenu;
    if(Window->SystemMenu)
    {
       OldMenu = IntGetMenuObject(Window->SystemMenu);
       if(OldMenu)
       {
-         OldMenu->MenuInfo.Flags &= ~ MNF_SYSDESKMN;
+         OldMenu->fFlags &= ~ MNF_SYSDESKMN;
          IntReleaseMenuObject(OldMenu);
       }
    }
@@ -1435,10 +1443,10 @@ IntSetSystemMenu(PWND Window, PMENU_OBJECT Menu)
    if(Menu)
    {
       /* FIXME: Check window style, propably return FALSE? */
-      Window->SystemMenu = Menu->MenuInfo.Self;
-      Menu->MenuInfo.Flags |= MNF_SYSDESKMN;
+      Window->SystemMenu = Menu->head.h;
+      Menu->fFlags |= MNF_SYSDESKMN;
    }
-   else
+   else // Use spmenuSys too!
       Window->SystemMenu = (HMENU)0;
 
    return TRUE;
@@ -1742,25 +1750,26 @@ IntFixWindowCoordinates(CREATESTRUCTW* Cs, PWND ParentWindow, DWORD* dwShowMode)
 
 /* Allocates and initializes a window */
 PWND FASTCALL IntCreateWindow(CREATESTRUCTW* Cs,
-                                        PLARGE_STRING WindowName,
-                                        PCLS Class,
-                                        PWND ParentWindow,
-                                        PWND OwnerWindow,
-                                        PVOID acbiBuffer,
-                                        PDESKTOP pdeskCreated)
+                              PLARGE_STRING WindowName,
+                              PCLS Class,
+                              PWND ParentWindow,
+                              PWND OwnerWindow,
+                              PVOID acbiBuffer,
+                              PDESKTOP pdeskCreated)
 {
    PWND pWnd = NULL;
    HWND hWnd;
    PTHREADINFO pti = NULL;
-   PMENU_OBJECT SystemMenu;
+   PMENU SystemMenu;
    BOOL MenuChanged;
    BOOL bUnicodeWindow;
 
    pti = pdeskCreated ? gptiDesktopThread : GetW32ThreadInfo();
 
    if (!(Cs->dwExStyle & WS_EX_LAYOUTRTL))
-   {
-      if (ParentWindow)
+   {      // Need both here for wine win.c test_CreateWindow.
+      //if (Cs->hwndParent && ParentWindow)
+      if (ParentWindow) // It breaks more tests..... WIP.
       {
          if ( (Cs->style & (WS_CHILD|WS_POPUP)) == WS_CHILD &&
               ParentWindow->ExStyle & WS_EX_LAYOUTRTL &&
@@ -1776,7 +1785,6 @@ PWND FASTCALL IntCreateWindow(CREATESTRUCTW* Cs,
          */
          if ( Class->fnid != FNID_DIALOG )
          {
-            ERR("No parent and not a dialog Fix HACK\n");
             if (pti->ppi->dwLayout & LAYOUT_RTL)
             {
                Cs->dwExStyle |= WS_EX_LAYOUTRTL;
@@ -1985,8 +1993,8 @@ PWND FASTCALL IntCreateWindow(CREATESTRUCTW* Cs,
    {
       SystemMenu = IntGetSystemMenu(pWnd, TRUE, TRUE);
       if(SystemMenu)
-      {
-         pWnd->SystemMenu = SystemMenu->MenuInfo.Self;
+      {  //    spmenuSys
+         pWnd->SystemMenu = SystemMenu->head.h;
          IntReleaseMenuObject(SystemMenu);
       }
    }
@@ -2115,10 +2123,7 @@ co_UserCreateWindowEx(CREATESTRUCTW* Cs,
    }
 
    /* Now find the parent and the owner window */
-   ///////////////
-   // FIXME!!!! Breaks wine win.c test_CreateWindow line 5470!
    hWndParent = pti->rpdesk->pDeskInfo->spwnd->head.h;
-   ///////////////
    hWndOwner = NULL;
 
     if (Cs->hwndParent == HWND_MESSAGE)
@@ -3681,7 +3686,7 @@ HMENU APIENTRY
 NtUserGetSystemMenu(HWND hWnd, BOOL bRevert)
 {
    PWND Window;
-   PMENU_OBJECT Menu;
+   PMENU Menu;
    DECLARE_RETURN(HMENU);
 
    TRACE("Enter NtUserGetSystemMenu\n");
@@ -3697,7 +3702,7 @@ NtUserGetSystemMenu(HWND hWnd, BOOL bRevert)
       RETURN(NULL);
    }
 
-   RETURN(Menu->MenuInfo.Self);
+   RETURN(Menu->head.h);
 
 CLEANUP:
    TRACE("Leave NtUserGetSystemMenu, ret=%p\n", _ret_);
@@ -3717,7 +3722,7 @@ NtUserSetSystemMenu(HWND hWnd, HMENU hMenu)
 {
    BOOL Result = FALSE;
    PWND Window;
-   PMENU_OBJECT Menu;
+   PMENU Menu;
    DECLARE_RETURN(BOOL);
 
    TRACE("Enter NtUserSetSystemMenu\n");