Prevent warning in optimized builds
[reactos.git] / reactos / lib / gdi32 / objects / dc.c
index 4048bcd..f8f18e4 100644 (file)
@@ -1,353 +1,7 @@
-#ifdef UNICODE
-#undef UNICODE
-#endif
+#include "precomp.h"
 
-#undef WIN32_LEAN_AND_MEAN
-#include <windows.h>
-#include <ddk/ntddk.h>
-#include <win32k/kapi.h>
-
-
-/*
- * @implemented
- */
-DWORD
-STDCALL
-GetObjectType(
-        HGDIOBJ         a0
-        )
-{
-        return W32kGetObjectType(a0);
-}
-
-
-
-/*
- * @implemented
- */
-BOOL
-STDCALL
-DPtoLP(
-        HDC     a0,
-        LPPOINT a1,
-        int     a2
-        )
-{
-        return W32kDPtoLP(a0, a1, a2);
-}
-
-
-/*
- * @implemented
- */
-COLORREF
-STDCALL
-SetBkColor(
-        HDC             a0,
-        COLORREF        a1
-        )
-{
-        return W32kSetBkColor(a0, a1);
-}
-
-
-/*
- * @implemented
- */
-int
-STDCALL
-GetGraphicsMode(
-        HDC     a0
-        )
-{
-        return W32kGetGraphicsMode(a0);
-}
-
-
-/*
- * @implemented
- */
-int
-STDCALL
-SetGraphicsMode(
-        HDC     hdc,
-        int     iMode
-        )
-{
-        return W32kSetGraphicsMode(hdc, iMode);
-}
-
-
-/*
- * @implemented
- */
-int
-STDCALL
-GetMapMode(
-        HDC     a0
-        )
-{
-        return W32kGetMapMode(a0);
-}
-
-/*
- * @implemented
- */
-BOOL
-STDCALL
-GetCurrentPositionEx(
-        HDC     a0,
-        LPPOINT a1
-        )
-{
-        return W32kGetCurrentPositionEx(a0, a1);
-}
-
-
-/*
- * @implemented
- */
-COLORREF
-STDCALL
-GetBkColor(
-        HDC     a0
-        )
-{
-        return W32kGetBkColor(a0);
-}
-
-
-/*
- * @implemented
- */
-int
-STDCALL
-GetBkMode(
-        HDC     a0
-        )
-{
-        return W32kGetBkMode(a0);
-}
-
-/*
- * @implemented
- */
-BOOL
-STDCALL
-GetBrushOrgEx(
-        HDC     a0,
-        LPPOINT a1
-        )
-{
-        return W32kGetBrushOrgEx(a0, a1);
-}
-
-
-/*
- * @implemented
- */
-int
-STDCALL
-GetROP2(
-        HDC     a0
-        )
-{
-        return W32kGetROP2(a0);
-
-}
-
-
-/*
- * @implemented
- */
-int
-STDCALL
-GetStretchBltMode(
-        HDC     a0
-        )
-{
-        return W32kGetStretchBltMode(a0);
-
-}
-
-
-
-/*
- * @implemented
- */
-UINT
-STDCALL
-GetTextAlign(
-        HDC     hDc
-        )
-{
-        return W32kGetTextAlign(hDc);
-
-}
-
-
-/*
- * @implemented
- */
-COLORREF
-STDCALL
-GetTextColor(
-        HDC     hDc
-        )
-{
-        return W32kGetTextColor(hDc);
-
-}
-
-
-/*
- * @implemented
- */
-BOOL
-STDCALL
-GetViewportExtEx(
-        HDC     hDc,
-        LPSIZE  lpSize
-        )
-{
-        return W32kGetViewportExtEx(hDc, lpSize);
-
-}
-
-
-/*
- * @implemented
- */
-BOOL
-STDCALL
-GetViewportOrgEx(
-        HDC             hDc,
-        LPPOINT         lpPoint
-        )
-{
-        return W32kGetViewportOrgEx(hDc, lpPoint);
-
-}
-
-
-/*
- * @implemented
- */
-BOOL
-STDCALL
-GetWindowExtEx(
-        HDC             hDc,
-        LPSIZE          lpSize
-        )
-{
-        return W32kGetWindowExtEx(hDc, lpSize);
-}
-
-
-/*
- * @implemented
- */
-BOOL
-STDCALL
-GetWindowOrgEx(
-        HDC             hDc,
-        LPPOINT         lpPoint
-        )
-{
-        return W32kGetWindowOrgEx(hDc, lpPoint);
-}
-
-
-/*
- * @implemented
- */
-int
-STDCALL
-SetBkMode(
-        HDC     a0,
-        int     a1
-        )
-{
-        return W32kSetBkMode(a0, a1);
-
-}
-
-
-/*
- * @implemented
- */
-int
-STDCALL
-SetROP2(
-        HDC     a0,
-        int     a1
-        )
-{
-        return W32kSetROP2(a0, a1);
-}
-
-
-/*
- * @implemented
- */
-int
-STDCALL
-SetStretchBltMode(
-        HDC     a0,
-        int     a1
-        )
-{
-        return W32kSetStretchBltMode(a0, a1);
-
-}
-
-
-/*
- * @implemented
- */
-DWORD
-STDCALL
-GetRelAbs(
-         HDC  a0,
-         DWORD a1
-           )
-{
-        return W32kGetRelAbs(a0);
-
-}
-
-
-/*
- * @implemented
- */
-HGDIOBJ STDCALL
-GetStockObject(int Index)
-{
-  return(W32kGetStockObject(Index));
-}
-
-
-/*
- * @implemented
- */
-int STDCALL
-GetClipBox(HDC hDc, LPRECT Rect)
-{
-  return(W32kGetClipBox(hDc, Rect));
-}
-
-
-/*
- * @implemented
- */
-int
-STDCALL
-GetPolyFillMode(
-       HDC     a0
-       )
-{
-       return W32kGetPolyFillMode(a0);
-}
+#define NDEBUG
+#include <debug.h>
 
 
 /*
@@ -435,21 +89,46 @@ CreateDCW (
        CONST DEVMODEW  * lpInitData
        )
 {
-       return W32kCreateDC (
-                       lpwszDriver,
-                       lpwszDevice,
-                       lpwszOutput,
-                       (PDEVMODEW)lpInitData
-                       );
+       UNICODE_STRING Driver, Device, Output;
+
+       if(lpwszDriver)
+               RtlInitUnicodeString(&Driver, lpwszDriver);
+       if(lpwszDevice)
+               RtlInitUnicodeString(&Driver, lpwszDevice);
+       if(lpwszOutput)
+               RtlInitUnicodeString(&Driver, lpwszOutput);
+
+       return NtGdiCreateDC((lpwszDriver ? &Driver : NULL),
+                                                (lpwszDevice ? &Device : NULL),
+                                                (lpwszOutput ? &Output : NULL),
+                                                (PDEVMODEW)lpInitData);
 }
 
 
 /*
  * @implemented
  */
-BOOL STDCALL DeleteDC( HDC hDC )
+HDC
+STDCALL
+CreateICW(
+       LPCWSTR                 lpszDriver,
+       LPCWSTR                 lpszDevice,
+       LPCWSTR                 lpszOutput,
+       CONST DEVMODEW *        lpdvmInit
+       )
 {
-  return W32kDeleteDC( hDC );
+  UNICODE_STRING Driver, Device, Output;
+  
+  if(lpszDriver)
+    RtlInitUnicodeString(&Driver, lpszDriver);
+  if(lpszDevice)
+    RtlInitUnicodeString(&Device, lpszDevice);
+  if(lpszOutput)
+    RtlInitUnicodeString(&Output, lpszOutput);
+  return NtGdiCreateIC ((lpszDriver ? &Driver : NULL),
+                     (lpszDevice ? &Device : NULL),
+                     (lpszOutput ? &Output : NULL),
+                     (CONST PDEVMODEW)lpdvmInit );
 }
 
 
@@ -458,169 +137,317 @@ BOOL STDCALL DeleteDC( HDC hDC )
  */
 HDC
 STDCALL
-CreateCompatibleDC(
-       HDC  hDC
+CreateICA(
+       LPCSTR                  lpszDriver,
+       LPCSTR                  lpszDevice,
+       LPCSTR                  lpszOutput,
+       CONST DEVMODEA *        lpdvmInit
        )
 {
-       return W32kCreateCompatableDC(hDC);
+  NTSTATUS Status;
+  LPWSTR lpszDriverW, lpszDeviceW, lpszOutputW;
+  UNICODE_STRING Driver, Device, Output;
+  LPDEVMODEW dvmInitW = NULL;
+  HDC rc = 0;
+
+  Status = HEAP_strdupA2W ( &lpszDriverW, lpszDriver );
+  if (!NT_SUCCESS (Status))
+    SetLastError (RtlNtStatusToDosError(Status));
+  else
+  {
+    Status = HEAP_strdupA2W ( &lpszDeviceW, lpszDevice );
+    if (!NT_SUCCESS (Status))
+      SetLastError (RtlNtStatusToDosError(Status));
+    else
+      {
+       Status = HEAP_strdupA2W ( &lpszOutputW, lpszOutput );
+       if (!NT_SUCCESS (Status))
+         SetLastError (RtlNtStatusToDosError(Status));
+       else
+         {
+           if ( lpdvmInit )
+          dvmInitW = GdiConvertToDevmodeW((LPDEVMODEA)lpdvmInit);
+        
+        RtlInitUnicodeString(&Driver, lpszDriverW);
+        RtlInitUnicodeString(&Device, lpszDeviceW);
+        RtlInitUnicodeString(&Output, lpszOutputW);
+           rc = NtGdiCreateIC ( &Driver,
+                               &Device,
+                               &Output,
+                               lpdvmInit ? dvmInitW : NULL );
+        HEAP_free (dvmInitW);
+           HEAP_free ( lpszOutputW );
+         }
+       HEAP_free ( lpszDeviceW );
+      }
+    HEAP_free ( lpszDriverW );
+  }
+  return rc;
 }
 
 
 /*
  * @implemented
  */
-HGDIOBJ
+BOOL
 STDCALL
-SelectObject(
-       HDC     hDC,
-       HGDIOBJ hGDIObj
-       )
+DeleteObject(HGDIOBJ hObject)
 {
-       return W32kSelectObject(hDC, hGDIObj);
+  if (0 != ((DWORD) hObject & GDI_HANDLE_STOCK_MASK))
+    {
+      DPRINT1("Trying to delete system object 0x%x\n", hObject);
+      return TRUE;
+    }
+
+  /* deleting a handle that doesn't belong to the caller should be rather rarely
+     so for the sake of speed just try to delete it without checking validity */
+  return NtGdiDeleteObject(hObject);
 }
 
 
 /*
  * @implemented
  */
-int
+DWORD
 STDCALL
-SetMapMode(
-       HDC     a0,
-       int     a1
-       )
+GetRelAbs(
+         HDC  hdc,
+         DWORD dwIgnore
+           )
 {
-  return W32kSetMapMode( a0, a1 );
+  return NtGdiGetRelAbs(hdc);
 }
 
-
 /*
  * @implemented
- */
-BOOL
+*/
+LONG
 STDCALL
-SetViewportOrgEx(
-       HDC     a0,
-       int     a1,
-       int     a2,
-       LPPOINT a3
-       )
+GetDCOrg(
+    HDC hdc
+    )
 {
-  return W32kSetViewportOrgEx( a0, a1, a2, a3 );
+  // Officially obsolete by Microsoft
+  POINT Pt;
+  if (!NtGdiGetDCOrgEx(hdc, &Pt))
+    return 0;
+  return(MAKELONG(Pt.x, Pt.y));
 }
 
 
 /*
- * @implemented
+ * @unimplemented
  */
-BOOL
-STDCALL
-OffsetViewportOrgEx(
-       HDC     DC,
-       int     XOffset,
-       int     YOffset,
-       LPPOINT Point
-       )
+int   
+STDCALL 
+GetObjectA(HGDIOBJ Handle, int Size, LPVOID Buffer)
 {
-  return W32kOffsetViewportOrgEx(DC, XOffset, YOffset, Point);
+  LOGFONTW LogFontW;
+  DWORD Type;
+  int Result;
+
+  Type = NtGdiGetObjectType(Handle);
+  if (0 == Type)
+    {
+      return 0;
+    }
+
+  if (OBJ_FONT == Type)
+    {
+      if (Size < sizeof(LOGFONTA))
+        {
+          SetLastError(ERROR_BUFFER_OVERFLOW);
+          return 0;
+        }
+      Result = NtGdiGetObject(Handle, sizeof(LOGFONTW), &LogFontW);
+      if (0 == Result)
+        {
+          return 0;
+        }
+      LogFontW2A((LPLOGFONTA) Buffer, &LogFontW);
+      Result = sizeof(LOGFONTA);
+    }
+  else
+    {
+      Result = NtGdiGetObject(Handle, Size, Buffer);
+    }
+
+  return Result;
+}
+
+
+/*
+ * @unimplemented
+ */
+int   
+STDCALL 
+GetObjectW(HGDIOBJ Handle, int Size, LPVOID Buffer)
+{
+  return NtGdiGetObject(Handle, Size, Buffer);
 }
 
 
 /*
  * @implemented
  */
-BOOL
+COLORREF 
 STDCALL
-SetWindowOrgEx(
-       HDC     a0,
-       int     a1,
-       int     a2,
-       LPPOINT a3
-       )
+GetDCBrushColor(
+       HDC hdc
+)
 {
-  return W32kSetWindowOrgEx( a0, a1, a2, a3 );
+  return NtUserGetDCBrushColor(hdc);
 }
 
-
 /*
  * @implemented
  */
-BOOL
+COLORREF 
 STDCALL
-DeleteObject(
-       HGDIOBJ         a0
-       )
+GetDCPenColor(
+       HDC hdc
+)
 {
-       return W32kDeleteObject(a0);
+  return NtUserGetDCPenColor(hdc);
 }
 
+/*
+ * @implemented
+ */
+COLORREF 
+STDCALL
+SetDCBrushColor(
+       HDC hdc,
+       COLORREF crColor
+)
+{
+  return NtUserSetDCBrushColor(hdc, crColor);
+}
 
 /*
  * @implemented
  */
-HPALETTE
+COLORREF 
 STDCALL
-SelectPalette(
-       HDC             a0,
-       HPALETTE        a1,
-       BOOL            a2
-       )
+SetDCPenColor(
+       HDC hdc,
+       COLORREF crColor
+)
 {
-       return W32kSelectPalette( a0, a1,a2 );
+  return NtUserSetDCPenColor(hdc, crColor);
 }
 
 
 /*
  * @implemented
  */
-UINT
+HDC
 STDCALL
-RealizePalette(
-       HDC     a0
+ResetDCW(
+       HDC             hdc,
+       CONST DEVMODEW  *lpInitData
        )
 {
-       return W32kRealizePalette( a0 );
+  return NtGdiResetDC ( hdc, lpInitData );
 }
 
 
 /*
  * @implemented
  */
-BOOL
+HDC
 STDCALL
-LPtoDP(
-       HDC     a0,
-       LPPOINT a1,
-       int     a2
+ResetDCA(
+       HDC             hdc,
+       CONST DEVMODEA  *lpInitData
        )
 {
-       return W32kLPtoDP(a0, a1, a2);
+  LPDEVMODEW InitDataW;
+  HDC hDc;
+
+  InitDataW = GdiConvertToDevmodeW((LPDEVMODEA)lpInitData);
+
+  hDc = NtGdiResetDC ( hdc, InitDataW );
+  HEAP_free(InitDataW);
+  return hDc;
 }
 
 
 /*
  * @implemented
  */
-int
-STDCALL
-SetPolyFillMode(
-       HDC     a0,
-       int     a1
+int 
+STDCALL 
+StartDocW(
+       HDC             hdc,
+       CONST DOCINFOW  *a1
        )
 {
-       return W32kSetPolyFillMode(a0, a1);
+       return NtGdiStartDoc ( hdc, (DOCINFOW *)a1 );
 }
 
 
 /*
  * @implemented
  */
-int
+DWORD
 STDCALL
-GetDeviceCaps(
-       HDC     DC,
-       int     Index
+GetObjectType(
+       HGDIOBJ h
        )
 {
-       return W32kGetDeviceCaps(DC, Index);
+  DWORD Ret = 0;
+  
+  if(GdiIsHandleValid(h))
+  {
+    LONG Type = GDI_HANDLE_GET_TYPE(h);
+    switch(Type)
+    {
+      case GDI_OBJECT_TYPE_PEN:
+        Ret = OBJ_PEN;
+        break;
+      case GDI_OBJECT_TYPE_BRUSH:
+        Ret = OBJ_BRUSH;
+        break;
+      case GDI_OBJECT_TYPE_BITMAP:
+        Ret = OBJ_BITMAP;
+        break;
+      case GDI_OBJECT_TYPE_FONT:
+        Ret = OBJ_FONT;
+        break;
+      case GDI_OBJECT_TYPE_PALETTE:
+        Ret = OBJ_PAL;
+        break;
+      case GDI_OBJECT_TYPE_REGION:
+        Ret = OBJ_REGION;
+        break;
+      case GDI_OBJECT_TYPE_DC:
+        Ret = OBJ_DC;
+        break;
+      case GDI_OBJECT_TYPE_METADC:
+        Ret = OBJ_METADC;
+        break;
+      case GDI_OBJECT_TYPE_METAFILE:
+        Ret = OBJ_METAFILE;
+        break;
+      case GDI_OBJECT_TYPE_ENHMETAFILE:
+        Ret = OBJ_ENHMETAFILE;
+        break;
+      case GDI_OBJECT_TYPE_ENHMETADC:
+        Ret = OBJ_ENHMETADC;
+        break;
+      case GDI_OBJECT_TYPE_EXTPEN:
+        Ret = OBJ_EXTPEN;
+        break;
+      case GDI_OBJECT_TYPE_MEMDC:
+        Ret = OBJ_MEMDC;
+        break;
+
+      default:
+        DPRINT1("GetObjectType: Magic 0x%08x not implemented\n", Type);
+        break;
+    }
+  }
+
+  return Ret;
 }