Prevent warning in optimized builds
[reactos.git] / reactos / lib / gdi32 / objects / dc.c
index 7025d40..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 NtGdiGetObjectType(a0);
-}
-
-
-
-/*
- * @implemented
- */
-BOOL
-STDCALL
-DPtoLP(
-        HDC     a0,
-        LPPOINT a1,
-        int     a2
-        )
-{
-        return NtGdiDPtoLP(a0, a1, a2);
-}
-
-
-/*
- * @implemented
- */
-COLORREF
-STDCALL
-SetBkColor(
-        HDC             a0,
-        COLORREF        a1
-        )
-{
-        return NtGdiSetBkColor(a0, a1);
-}
-
-
-/*
- * @implemented
- */
-int
-STDCALL
-GetGraphicsMode(
-        HDC     a0
-        )
-{
-        return NtGdiGetGraphicsMode(a0);
-}
-
-
-/*
- * @implemented
- */
-int
-STDCALL
-SetGraphicsMode(
-        HDC     hdc,
-        int     iMode
-        )
-{
-        return NtGdiSetGraphicsMode(hdc, iMode);
-}
-
-
-/*
- * @implemented
- */
-int
-STDCALL
-GetMapMode(
-        HDC     a0
-        )
-{
-        return NtGdiGetMapMode(a0);
-}
-
-/*
- * @implemented
- */
-BOOL
-STDCALL
-GetCurrentPositionEx(
-        HDC     a0,
-        LPPOINT a1
-        )
-{
-        return NtGdiGetCurrentPositionEx(a0, a1);
-}
-
-
-/*
- * @implemented
- */
-COLORREF
-STDCALL
-GetBkColor(
-        HDC     a0
-        )
-{
-        return NtGdiGetBkColor(a0);
-}
-
-
-/*
- * @implemented
- */
-int
-STDCALL
-GetBkMode(
-        HDC     a0
-        )
-{
-        return NtGdiGetBkMode(a0);
-}
-
-/*
- * @implemented
- */
-BOOL
-STDCALL
-GetBrushOrgEx(
-        HDC     a0,
-        LPPOINT a1
-        )
-{
-        return NtGdiGetBrushOrgEx(a0, a1);
-}
-
-
-/*
- * @implemented
- */
-int
-STDCALL
-GetROP2(
-        HDC     a0
-        )
-{
-        return NtGdiGetROP2(a0);
-
-}
-
-
-/*
- * @implemented
- */
-int
-STDCALL
-GetStretchBltMode(
-        HDC     a0
-        )
-{
-        return NtGdiGetStretchBltMode(a0);
-
-}
-
-
-
-/*
- * @implemented
- */
-UINT
-STDCALL
-GetTextAlign(
-        HDC     hDc
-        )
-{
-        return NtGdiGetTextAlign(hDc);
-
-}
-
-
-/*
- * @implemented
- */
-COLORREF
-STDCALL
-GetTextColor(
-        HDC     hDc
-        )
-{
-        return NtGdiGetTextColor(hDc);
-
-}
-
-
-/*
- * @implemented
- */
-BOOL
-STDCALL
-GetViewportExtEx(
-        HDC     hDc,
-        LPSIZE  lpSize
-        )
-{
-        return NtGdiGetViewportExtEx(hDc, lpSize);
-
-}
-
-
-/*
- * @implemented
- */
-BOOL
-STDCALL
-GetViewportOrgEx(
-        HDC             hDc,
-        LPPOINT         lpPoint
-        )
-{
-        return NtGdiGetViewportOrgEx(hDc, lpPoint);
-
-}
-
-
-/*
- * @implemented
- */
-BOOL
-STDCALL
-GetWindowExtEx(
-        HDC             hDc,
-        LPSIZE          lpSize
-        )
-{
-        return NtGdiGetWindowExtEx(hDc, lpSize);
-}
-
-
-/*
- * @implemented
- */
-BOOL
-STDCALL
-GetWindowOrgEx(
-        HDC             hDc,
-        LPPOINT         lpPoint
-        )
-{
-        return NtGdiGetWindowOrgEx(hDc, lpPoint);
-}
-
-
-/*
- * @implemented
- */
-int
-STDCALL
-SetBkMode(
-        HDC     a0,
-        int     a1
-        )
-{
-        return NtGdiSetBkMode(a0, a1);
-
-}
-
-
-/*
- * @implemented
- */
-int
-STDCALL
-SetROP2(
-        HDC     a0,
-        int     a1
-        )
-{
-        return NtGdiSetROP2(a0, a1);
-}
-
-
-/*
- * @implemented
- */
-int
-STDCALL
-SetStretchBltMode(
-        HDC     a0,
-        int     a1
-        )
-{
-        return NtGdiSetStretchBltMode(a0, a1);
-
-}
-
-
-/*
- * @implemented
- */
-DWORD
-STDCALL
-GetRelAbs(
-         HDC  a0,
-         DWORD a1
-           )
-{
-        return NtGdiGetRelAbs(a0);
-
-}
-
-
-/*
- * @implemented
- */
-HGDIOBJ STDCALL
-GetStockObject(int Index)
-{
-  return(NtGdiGetStockObject(Index));
-}
-
-
-/*
- * @implemented
- */
-int STDCALL
-GetClipBox(HDC hDc, LPRECT Rect)
-{
-  return(NtGdiGetClipBox(hDc, Rect));
-}
-
-
-/*
- * @implemented
- */
-int
-STDCALL
-GetPolyFillMode(
-       HDC     a0
-       )
-{
-       return NtGdiGetPolyFillMode(a0);
-}
+#define NDEBUG
+#include <debug.h>
 
 
 /*
@@ -451,85 +105,84 @@ CreateDCW (
 }
 
 
-/*
- * @implemented
- */
-BOOL STDCALL DeleteDC( HDC hDC )
-{
-  return NtGdiDeleteDC( hDC );
-}
-
-
 /*
  * @implemented
  */
 HDC
 STDCALL
-CreateCompatibleDC(
-       HDC  hDC
-       )
-{
-       return NtGdiCreateCompatableDC(hDC);
-}
-
-
-/*
- * @implemented
- */
-HGDIOBJ
-STDCALL
-SelectObject(
-       HDC     hDC,
-       HGDIOBJ hGDIObj
-       )
-{
-       return NtGdiSelectObject(hDC, hGDIObj);
-}
-
-
-/*
- * @implemented
- */
-int
-STDCALL
-SetMapMode(
-       HDC     a0,
-       int     a1
-       )
-{
-  return NtGdiSetMapMode( a0, a1 );
-}
-
-
-/*
- * @implemented
- */
-BOOL
-STDCALL
-SetViewportOrgEx(
-       HDC     a0,
-       int     a1,
-       int     a2,
-       LPPOINT a3
+CreateICW(
+       LPCWSTR                 lpszDriver,
+       LPCWSTR                 lpszDevice,
+       LPCWSTR                 lpszOutput,
+       CONST DEVMODEW *        lpdvmInit
        )
 {
-  return NtGdiSetViewportOrgEx( a0, a1, a2, a3 );
+  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 );
 }
 
 
 /*
  * @implemented
  */
-BOOL
+HDC
 STDCALL
-OffsetViewportOrgEx(
-       HDC     DC,
-       int     XOffset,
-       int     YOffset,
-       LPPOINT Point
-       )
-{
-  return NtGdiOffsetViewportOrgEx(DC, XOffset, YOffset, Point);
+CreateICA(
+       LPCSTR                  lpszDriver,
+       LPCSTR                  lpszDevice,
+       LPCSTR                  lpszOutput,
+       CONST DEVMODEA *        lpdvmInit
+       )
+{
+  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;
 }
 
 
@@ -538,359 +191,263 @@ OffsetViewportOrgEx(
  */
 BOOL
 STDCALL
-SetWindowOrgEx(
-       HDC     a0,
-       int     a1,
-       int     a2,
-       LPPOINT a3
-       )
+DeleteObject(HGDIOBJ hObject)
 {
-  return NtGdiSetWindowOrgEx( a0, a1, a2, a3 );
-}
-
+  if (0 != ((DWORD) hObject & GDI_HANDLE_STOCK_MASK))
+    {
+      DPRINT1("Trying to delete system object 0x%x\n", hObject);
+      return TRUE;
+    }
 
-/*
- * @implemented
- */
-BOOL
-STDCALL
-DeleteObject(
-       HGDIOBJ         a0
-       )
-{
-       return NtGdiDeleteObject(a0);
+  /* 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
  */
-HPALETTE
+DWORD
 STDCALL
-SelectPalette(
-       HDC             a0,
-       HPALETTE        a1,
-       BOOL            a2
-       )
+GetRelAbs(
+         HDC  hdc,
+         DWORD dwIgnore
+           )
 {
-       return NtGdiSelectPalette( a0, a1,a2 );
+  return NtGdiGetRelAbs(hdc);
 }
 
-
 /*
  * @implemented
- */
-UINT
+*/
+LONG
 STDCALL
-RealizePalette(
-       HDC     a0
-       )
+GetDCOrg(
+    HDC hdc
+    )
 {
-       return NtGdiRealizePalette( a0 );
+  // Officially obsolete by Microsoft
+  POINT Pt;
+  if (!NtGdiGetDCOrgEx(hdc, &Pt))
+    return 0;
+  return(MAKELONG(Pt.x, Pt.y));
 }
 
 
 /*
- * @implemented
+ * @unimplemented
  */
-BOOL
-STDCALL
-LPtoDP(
-       HDC     a0,
-       LPPOINT a1,
-       int     a2
-       )
+int   
+STDCALL 
+GetObjectA(HGDIOBJ Handle, int Size, LPVOID Buffer)
 {
-       return NtGdiLPtoDP(a0, a1, a2);
-}
-
+  LOGFONTW LogFontW;
+  DWORD Type;
+  int Result;
 
-/*
- * @implemented
- */
-int
-STDCALL
-SetPolyFillMode(
-       HDC     a0,
-       int     a1
-       )
-{
-       return NtGdiSetPolyFillMode(a0, a1);
-}
+  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);
+    }
 
-/*
- * @implemented
- */
-int
-STDCALL
-GetDeviceCaps(
-       HDC     DC,
-       int     Index
-       )
-{
-       return NtGdiGetDeviceCaps(DC, Index);
+  return Result;
 }
 
-/*
- * @implemented
- */
-HPALETTE
-STDCALL
-CreatePalette(
-       CONST LOGPALETTE        *a0
-       )
-{
-       return NtGdiCreatePalette((CONST PLOGPALETTE)a0);
-}
 
 /*
- * @implemented
+ * @unimplemented
  */
-COLORREF
-STDCALL
-GetNearestColor(
-       HDC             a0,
-       COLORREF        a1
-       )
+int   
+STDCALL 
+GetObjectW(HGDIOBJ Handle, int Size, LPVOID Buffer)
 {
-       return NtGdiGetNearestColor(a0,a1);
+  return NtGdiGetObject(Handle, Size, Buffer);
 }
 
-/*
- * @implemented
- */
-UINT
-STDCALL
-GetNearestPaletteIndex(
-       HPALETTE        a0,
-       COLORREF        a1
-       )
-{
-       return NtGdiGetNearestPaletteIndex(a0,a1);
-}
 
 /*
  * @implemented
  */
-UINT
+COLORREF 
 STDCALL
-GetPaletteEntries(
-       HPALETTE        a0,
-       UINT            a1,
-       UINT            a2,
-       LPPALETTEENTRY  a3
-       )
+GetDCBrushColor(
+       HDC hdc
+)
 {
-       return NtGdiGetPaletteEntries(a0,a1,a2,a3);
+  return NtUserGetDCBrushColor(hdc);
 }
 
 /*
  * @implemented
  */
-UINT
+COLORREF 
 STDCALL
-GetSystemPaletteEntries(
-       HDC             a0,
-       UINT            a1,
-       UINT            a2,
-       LPPALETTEENTRY  a3
-       )
+GetDCPenColor(
+       HDC hdc
+)
 {
-       return NtGdiGetSystemPaletteEntries(a0,a1,a2,a3);
+  return NtUserGetDCPenColor(hdc);
 }
 
 /*
  * @implemented
  */
-BOOL
+COLORREF 
 STDCALL
-RestoreDC(
-       HDC     a0,
-       int     a1
-       )
+SetDCBrushColor(
+       HDC hdc,
+       COLORREF crColor
+)
 {
-       return NtGdiRestoreDC(a0,a1);
+  return NtUserSetDCBrushColor(hdc, crColor);
 }
 
-
 /*
  * @implemented
  */
-int
+COLORREF 
 STDCALL
-SaveDC(
-       HDC     a0
-       )
+SetDCPenColor(
+       HDC hdc,
+       COLORREF crColor
+)
 {
-       return NtGdiSaveDC(a0);
+  return NtUserSetDCPenColor(hdc, crColor);
 }
 
-/*
- * @implemented
- */
-UINT
-STDCALL
-SetPaletteEntries(
-       HPALETTE                a0,
-       UINT                    a1,
-       UINT                    a2,
-       CONST PALETTEENTRY      *a3
-       )
-{
-       return NtGdiSetPaletteEntries(a0,a1,a2,(CONST PPALETTEENTRY)a3);
-}
 
 /*
  * @implemented
  */
-BOOL
+HDC
 STDCALL
-GetWorldTransform(
+ResetDCW(
        HDC             hdc,
-       LPXFORM         a1
-       )
-{
-       return NtGdiGetWorldTransform(hdc,a1);
-}
-
-/*
- * @implemented
- */
-BOOL
-STDCALL
-SetWorldTransform(
-       HDC             a0,
-       CONST XFORM     *a1
-       )
-{
-       return NtGdiSetWorldTransform(a0,(CONST PXFORM)a1);
-}
-
-/*
- * @implemented
- */
-BOOL
-STDCALL
-ModifyWorldTransform(
-       HDC             a0,
-       CONST XFORM     *a1,
-       DWORD           a2
+       CONST DEVMODEW  *lpInitData
        )
 {
-       return NtGdiModifyWorldTransform(a0,(CONST PXFORM)a1,a2);
+  return NtGdiResetDC ( hdc, lpInitData );
 }
 
-/*
- * @implemented
- */
-BOOL
-STDCALL
-CombineTransform(
-       LPXFORM         a0,
-       CONST XFORM     *a1,
-       CONST XFORM     *a2
-       )
-{
-       return NtGdiCombineTransform(a0,(CONST PXFORM)a1,(CONST PXFORM)a2);
-}
 
 /*
  * @implemented
  */
-UINT
+HDC
 STDCALL
-SetDIBColorTable(
+ResetDCA(
        HDC             hdc,
-       UINT            a1,
-       UINT            a2,
-       CONST RGBQUAD   *a3
+       CONST DEVMODEA  *lpInitData
        )
 {
-       return NtGdiSetDIBColorTable(hdc,a1,a2,(CONST PRGBQUAD)a3);
-}
+  LPDEVMODEW InitDataW;
+  HDC hDc;
 
-/*
- * @implemented
- */
-HPALETTE
-STDCALL
-CreateHalftonePalette(
-       HDC     hdc
-       )
-{
-       return NtGdiCreateHalftonePalette(hdc);
-}
+  InitDataW = GdiConvertToDevmodeW((LPDEVMODEA)lpInitData);
 
-/*
- * @implemented
- */
-BOOL
-STDCALL
-SetViewportExtEx(
-       HDC     a0,
-       int     a1,
-       int     a2,
-       LPSIZE  a3
-       )
-{
-       return NtGdiSetViewportExtEx(a0,a1,a2,a3);
+  hDc = NtGdiResetDC ( hdc, InitDataW );
+  HEAP_free(InitDataW);
+  return hDc;
 }
 
-/*
- * @implemented
- */
-BOOL
-STDCALL
-SetWindowExtEx(
-       HDC     a0,
-       int     a1,
-       int     a2,
-       LPSIZE  a3
-       )
-{
-       return NtGdiSetWindowExtEx(a0,a1,a2,a3);
-}
 
 /*
  * @implemented
  */
-BOOL
-STDCALL
-OffsetWindowOrgEx(
-       HDC     a0,
-       int     a1,
-       int     a2,
-       LPPOINT a3
+int 
+STDCALL 
+StartDocW(
+       HDC             hdc,
+       CONST DOCINFOW  *a1
        )
 {
-       return NtGdiOffsetWindowOrgEx(a0,a1,a2,a3);
+       return NtGdiStartDoc ( hdc, (DOCINFOW *)a1 );
 }
 
-/*
- * @implemented
- */
-BOOL
-STDCALL
-SetBitmapDimensionEx(
-       HBITMAP a0,
-       int     a1,
-       int     a2,
-       LPSIZE  a3
-       )
-{
-       return NtGdiSetBitmapDimensionEx(a0,a1,a2,a3);
-}
 
 /*
  * @implemented
  */
-BOOL
+DWORD
 STDCALL
-GetDCOrgEx(
-       HDC     a0,
-       LPPOINT a1
-       )
-{
-       return NtGdiGetDCOrgEx(a0,a1);
+GetObjectType(
+       HGDIOBJ h
+       )
+{
+  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;
 }