[USER32]
[reactos.git] / reactos / dll / win32 / user32 / windows / dialog.c
index 2814fa3..a8cc5e0 100644 (file)
@@ -133,32 +133,42 @@ const struct builtin_class_descr DIALOG_builtin_class =
 *
 * ReactOS
 */
-DIALOGINFO * DIALOG_get_info( HWND hWnd, BOOL create )
+DIALOGINFO *DIALOG_get_info( HWND hWnd, BOOL create )
 {
     PWND pWindow;
-    DIALOGINFO* dlgInfo = (DIALOGINFO *)GetWindowLongPtrW( hWnd, DWLP_ROS_DIALOGINFO );
+    DIALOGINFO* dlgInfo;
 
-    if(!dlgInfo && create)
+    pWindow = ValidateHwnd( hWnd );
+    if (!pWindow)
     {
-        pWindow = ValidateHwnd( hWnd );
-        if (!pWindow)
-        {
-           SetLastError( ERROR_INVALID_WINDOW_HANDLE );
-           return NULL;
-        }
+       return NULL;
+    }
 
-        if (pWindow && pWindow->cbwndExtra >= DLGWINDOWEXTRA && hWnd != GetDesktopWindow())
+    dlgInfo = (DIALOGINFO *)GetWindowLongPtrW( hWnd, DWLP_ROS_DIALOGINFO );
+
+    if (!dlgInfo && create)
+    {
+        if (pWindow && pWindow->cbwndExtra >= DLGWINDOWEXTRA)
         {
             if (!(dlgInfo = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*dlgInfo) )))
                 return NULL;
 
+            dlgInfo->idResult = IDOK;
             SETDLGINFO( hWnd, dlgInfo );
 
-            NtUserCallHwndParam( hWnd, (DWORD_PTR)dlgInfo, HWNDPARAM_ROUTINE_SETDIALOGPOINTER );
-        }
-        else
+           NtUserxSetDialogPointer( hWnd, dlgInfo );
+       }
+       else
+       {
+           return NULL;
+       }
+    }
+    else
+    {
+        if (!(pWindow->state & WNDS_DIALOGWINDOW) || pWindow->fnid != FNID_DIALOG)
         {
-            return NULL;
+           ERR("Wrong window class for Dialog!\n");
+           return NULL;
         }
     }
     return dlgInfo;
@@ -346,14 +356,14 @@ static BOOL DIALOG_CreateControls32( HWND hwnd, LPCSTR template, const DLG_TEMPL
             LPSTR class = (LPSTR)info.className;
             LPSTR caption = (LPSTR)info.windowName;
 
-            if (HIWORD(class))
+            if (!IS_INTRESOURCE(class))
             {
                 DWORD len = WideCharToMultiByte( CP_ACP, 0, info.className, -1, NULL, 0, NULL, NULL );
                 class = HeapAlloc( GetProcessHeap(), 0, len );
                 if (class != NULL)
                     WideCharToMultiByte( CP_ACP, 0, info.className, -1, class, len, NULL, NULL );
             }
-            if (HIWORD(caption))
+            if (!IS_INTRESOURCE(caption))
             {
                 DWORD len = WideCharToMultiByte( CP_ACP, 0, info.windowName, -1, NULL, 0, NULL, NULL );
                 caption = HeapAlloc( GetProcessHeap(), 0, len );
@@ -374,8 +384,8 @@ static BOOL DIALOG_CreateControls32( HWND hwnd, LPCSTR template, const DLG_TEMPL
             }
             else
                 hwndCtrl = NULL;
-            if (HIWORD(class)) HeapFree( GetProcessHeap(), 0, class );
-            if (HIWORD(caption)) HeapFree( GetProcessHeap(), 0, caption );
+            if (!IS_INTRESOURCE(class)) HeapFree( GetProcessHeap(), 0, class );
+            if (!IS_INTRESOURCE(caption)) HeapFree( GetProcessHeap(), 0, caption );
         }
 
         if (info.windowNameFree)
@@ -504,7 +514,7 @@ static HWND DIALOG_FindMsgDestination( HWND hwndDlg )
 
         pWnd = ValidateHwnd(hParent);
         // FIXME: Use pWnd->fnid == FNID_DESKTOP
-        if (!pWnd || hParent == GetDesktopWindow()) break;
+        if (!pWnd || !TestWindowProcess(pWnd) || hParent == GetDesktopWindow()) break;
 
         if (!(pWnd->state & WNDS_DIALOGWINDOW))
         {
@@ -927,14 +937,14 @@ static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCVOID dlgTemplate,
         LPSTR class_tmp = NULL;
         LPSTR caption_tmp = NULL;
 
-        if (HIWORD(class))
+        if (!IS_INTRESOURCE(class))
         {
             DWORD len = WideCharToMultiByte( CP_ACP, 0, template.className, -1, NULL, 0, NULL, NULL );
             class_tmp = HeapAlloc( GetProcessHeap(), 0, len );
             WideCharToMultiByte( CP_ACP, 0, template.className, -1, class_tmp, len, NULL, NULL );
             class = class_tmp;
         }
-        if (HIWORD(caption))
+        if (!IS_INTRESOURCE(caption))
         {
             DWORD len = WideCharToMultiByte( CP_ACP, 0, template.caption, -1, NULL, 0, NULL, NULL );
             caption_tmp = HeapAlloc( GetProcessHeap(), 0, len );
@@ -960,6 +970,7 @@ static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCVOID dlgTemplate,
     will be valid only after WM_CREATE message has been handled in DefDlgProc
     All the members of the structure get filled here using temp variables */
     dlgInfo = DIALOG_get_info( hwnd, TRUE );
+    // ReactOS
     if (dlgInfo == NULL)
     {
         if (hUserFont) DeleteObject( hUserFont );
@@ -967,13 +978,12 @@ static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCVOID dlgTemplate,
         if (modal && (flags & DF_OWNERENABLED)) DIALOG_EnableOwner(owner);
         return 0;
     }
-
+    //
     dlgInfo->hwndFocus   = 0;
     dlgInfo->hUserFont   = hUserFont;
     dlgInfo->hMenu       = hMenu;
     dlgInfo->xBaseUnit   = xBaseUnit;
     dlgInfo->yBaseUnit   = yBaseUnit;
-    dlgInfo->idResult    = IDOK;
     dlgInfo->flags       = flags;
 
     if (template.helpId) SetWindowContextHelpId( hwnd, template.helpId );
@@ -1157,7 +1167,7 @@ static LRESULT DEFDLG_Proc( HWND hwnd, UINT msg, WPARAM wParam,
                 if (dlgInfo->hMenu) DestroyMenu( dlgInfo->hMenu );
                 HeapFree( GetProcessHeap(), 0, dlgInfo );
                 NtUserSetThreadState(0,DF_DIALOGACTIVE);
-                NtUserCallHwndParam( hwnd, 0, HWNDPARAM_ROUTINE_SETDIALOGPOINTER );
+                NtUserxSetDialogPointer( hwnd, 0 );
             }
              /* Window clean-up */
             return DefWindowProcA( hwnd, msg, wParam, lParam );
@@ -1966,7 +1976,11 @@ EndDialog(
     DIALOGINFO * dlgInfo;
     HWND owner;
 
-    if (!(dlgInfo = GETDLGINFO(hDlg))) return FALSE;
+    if (!(dlgInfo = GETDLGINFO(hDlg)))
+    {
+        ERR("got invalid window handle (%p); buggy app !?\n", hDlg);
+        return FALSE;
+    }
 
     dlgInfo->idResult = nResult;
     dlgInfo->flags |= DF_END;
@@ -2066,7 +2080,7 @@ GetDlgItemInt(
 {
     char str[30];
     char * endptr;
-    long result = 0;
+    LONG_PTR result = 0;
 
     if (lpTranslated) *lpTranslated = FALSE;
     if (!SendDlgItemMessageA(hDlg, nIDDlgItem, WM_GETTEXT, sizeof(str), (LPARAM)str))
@@ -2252,16 +2266,26 @@ GetNextDlgTabItem(
   HWND hCtl,
   BOOL bPrevious)
 {
-       /* Undocumented but tested under Win2000 and WinME */
-       if (hDlg == hCtl) hCtl = NULL;
+    PWND pWindow;
+      
+    pWindow = ValidateHwnd( hDlg );
+    if (!pWindow) return NULL;
+    if (hCtl)
+    {
+       pWindow = ValidateHwnd( hCtl );
+       if (!pWindow) return NULL;
+    }
 
-       /* Contrary to MSDN documentation, tested under Win2000 and WinME
-       * NB GetLastError returns whatever was set before the function was
-       * called.
-       */
-       if (!hCtl && bPrevious) return 0;
+    /* Undocumented but tested under Win2000 and WinME */
+    if (hDlg == hCtl) hCtl = NULL;
+
+    /* Contrary to MSDN documentation, tested under Win2000 and WinME
+     * NB GetLastError returns whatever was set before the function was
+     * called.
+     */
+    if (!hCtl && bPrevious) return 0;
 
-       return DIALOG_GetNextTabItem(hDlg, hDlg, hCtl, bPrevious);
+    return DIALOG_GetNextTabItem(hDlg, hDlg, hCtl, bPrevious);
 }
 
 
@@ -2402,6 +2426,14 @@ IsDialogMessageW(
          case VK_TAB:
             if (!(dlgCode & DLGC_WANTTAB))
             {
+                BOOL fIsDialog = TRUE;
+                WND *pWnd = ValidateHwnd(hDlg);
+
+                if (pWnd && TestWindowProcess(pWnd))
+                {
+                    fIsDialog = (GETDLGINFO(hDlg) != NULL);
+                }
+  
                 SendMessageW(hDlg, WM_CHANGEUISTATE, MAKEWPARAM(UIS_CLEAR, UISF_HIDEFOCUS), 0);
 
                 /* I am not sure under which circumstances the TAB is handled
@@ -2409,7 +2441,7 @@ IsDialogMessageW(
                  * send WM_NEXTDLGCTL.  (Personally I have never yet seen it
                  * do so but I presume someone has)
                  */
-                if (GETDLGINFO(hDlg))
+                if (fIsDialog)
                     SendMessageW( hDlg, WM_NEXTDLGCTL, (GetKeyState(VK_SHIFT) & 0x8000), 0 );
                 else
                 {
@@ -2510,7 +2542,7 @@ IsDialogMessageW(
 //// ReactOS
      case WM_SYSKEYDOWN:
          /* If the ALT key is being pressed display the keyboard cues */
-         if (lpMsg->lParam & (1 << 29))
+         if (HIWORD(lpMsg->lParam) & KF_ALTDOWN)
              SendMessageW(hDlg, WM_CHANGEUISTATE, MAKEWPARAM(UIS_CLEAR, UISF_HIDEACCEL | UISF_HIDEFOCUS), 0);
          break;
 
@@ -2573,7 +2605,9 @@ SendDlgItemMessageA(
   WPARAM wParam,
   LPARAM lParam)
 {
-       HWND hwndCtrl = GetDlgItem( hDlg, nIDDlgItem );
+       HWND hwndCtrl;
+       if ( hDlg == HWND_TOPMOST || hDlg == HWND_BROADCAST ) return 0; // ReactOS
+       hwndCtrl = GetDlgItem( hDlg, nIDDlgItem );
        if (hwndCtrl) return SendMessageA( hwndCtrl, Msg, wParam, lParam );
        else return 0;
 }
@@ -2591,7 +2625,9 @@ SendDlgItemMessageW(
   WPARAM wParam,
   LPARAM lParam)
 {
-       HWND hwndCtrl = GetDlgItem( hDlg, nIDDlgItem );
+       HWND hwndCtrl;
+       if ( hDlg == HWND_TOPMOST || hDlg == HWND_BROADCAST ) return 0; // ReactOS
+       hwndCtrl = GetDlgItem( hDlg, nIDDlgItem );
        if (hwndCtrl) return SendMessageW( hwndCtrl, Msg, wParam, lParam );
        else return 0;
 }
@@ -2627,7 +2663,9 @@ SetDlgItemTextA(
   int nIDDlgItem,
   LPCSTR lpString)
 {
-  return SendDlgItemMessageA( hDlg, nIDDlgItem, WM_SETTEXT, 0, (LPARAM)lpString );
+  HWND hwndCtrl = GetDlgItem( hDlg, nIDDlgItem ); // ReactOS Themes
+  if (hwndCtrl) return SetWindowTextA( hwndCtrl, lpString );
+  return FALSE;
 }
 
 
@@ -2641,7 +2679,9 @@ SetDlgItemTextW(
   int nIDDlgItem,
   LPCWSTR lpString)
 {
-  return SendDlgItemMessageW( hDlg, nIDDlgItem, WM_SETTEXT, 0, (LPARAM)lpString );
+  HWND hwndCtrl = GetDlgItem( hDlg, nIDDlgItem ); // ReactOS Themes
+  if (hwndCtrl) return SetWindowTextW( hwndCtrl, lpString );
+  return FALSE;
 }