[ros-diffs] [cwittich] 26441: implement NtGdiGetSystemPaletteEntries (patch by w3seek)

cwittich at svn.reactos.org cwittich at svn.reactos.org
Sat Apr 21 00:36:57 CEST 2007


Author: cwittich
Date: Sat Apr 21 02:36:57 2007
New Revision: 26441

URL: http://svn.reactos.org/svn/reactos?rev=26441&view=rev
Log:
implement NtGdiGetSystemPaletteEntries (patch by w3seek)

Modified:
    trunk/reactos/subsystems/win32/win32k/objects/color.c

Modified: trunk/reactos/subsystems/win32/win32k/objects/color.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/objects/color.c?rev=26441&r1=26440&r2=26441&view=diff
==============================================================================
--- trunk/reactos/subsystems/win32/win32k/objects/color.c (original)
+++ trunk/reactos/subsystems/win32/win32k/objects/color.c Sat Apr 21 02:36:57 2007
@@ -309,35 +309,77 @@
                                   UINT  Entries,
                                   LPPALETTEENTRY  pe)
 {
-  //UINT i;
-  //PDC dc;
-/*
-  if (!(dc = AccessUserObject(hdc))) return 0;
-
-  if (!pe)
-  {
-    Entries = dc->GDIInfo->ulNumPalReg;
-    goto done;
-  }
-
-  if (StartIndex >= dc->GDIInfo->ulNumPalReg)
-  {
-    Entries = 0;
-    goto done;
-  }
-
-  if (StartIndex + Entries >= dc->GDIInfo->ulNumPalReg) Entries = dc->GDIInfo->ulNumPalReg - StartIndex;
-
-  for (i = 0; i < Entries; i++)
-  {
-    *(COLORREF*)(entries + i) = COLOR_GetSystemPaletteEntry(StartIndex + i);
-  }
-
-  done:
-//    GDI_ReleaseObj(hdc);
-  return count; */
-  // FIXME UNIMPLEMENTED;
-  return 0;
+    PPALGDI palGDI = NULL;
+    PDC dc = NULL;
+    UINT EntriesSize = 0;
+    UINT Ret = 0;
+
+    if (Entries == 0)
+    {
+        SetLastWin32Error(ERROR_INVALID_PARAMETER);
+        return 0;
+    }
+
+    _SEH_TRY
+    {
+        if (pe != NULL)
+        {
+            EntriesSize = Entries * sizeof(pe[0]);
+            if (Entries != EntriesSize / sizeof(pe[0]))
+            {
+                /* Integer overflow! */
+                SetLastWin32Error(ERROR_INVALID_PARAMETER);
+                _SEH_LEAVE;
+            }
+
+            ProbeForWrite(pe,
+                          EntriesSize,
+                          sizeof(UINT));
+        }
+
+        if (!(dc = DC_LockDc(hDC)))
+        {
+            SetLastWin32Error(ERROR_INVALID_HANDLE);
+            _SEH_LEAVE;
+        }
+
+        palGDI = PALETTE_LockPalette(dc->w.hPalette);
+        if (palGDI != NULL)
+        {
+            if (pe != NULL)
+            {
+                UINT CopyEntries;
+
+                if (StartIndex + Entries < palGDI->NumColors)
+                    CopyEntries = StartIndex + Entries;
+                else
+                    CopyEntries = palGDI->NumColors - StartIndex;
+
+                memcpy(pe,
+                       palGDI->IndexedColors + StartIndex,
+                       CopyEntries * sizeof(pe[0]));
+
+                Ret = CopyEntries;
+            }
+            else
+            {
+                Ret = dc->GDIInfo->ulNumPalReg;
+            }
+        }
+    }
+    _SEH_HANDLE
+    {
+        SetLastNtError(_SEH_GetExceptionCode());
+    }
+    _SEH_END;
+
+    if (palGDI != NULL)
+        PALETTE_UnlockPalette(palGDI);
+
+    if (dc != NULL)
+        DC_UnlockDc(dc);
+
+    return Ret;
 }
 
 UINT STDCALL NtGdiGetSystemPaletteUse(HDC  hDC)




More information about the Ros-diffs mailing list