xref: /reactos/win32ss/gdi/ntgdi/metafile.c (revision da264743)
1 /*
2  * PROJECT:         ReactOS Win32k Subsystem
3  * LICENSE:         GPL - See COPYING in the top level directory
4  * FILE:            win32ss/gdi/ntgdi/metafile.c
5  * PURPOSE:         Metafile Implementations, Metafile Clipboard Data Xfers
6  * PROGRAMMERS:     ...
7  */
8 
9 /* INCLUDES ******************************************************************/
10 
11 #include <win32k.h>
12 
13 #define NDEBUG
14 #include <debug.h>
15 
16 
17 // Internal Use Only
18 typedef struct _METATYPEOBJ
19 {
20     BASEOBJECT  BaseObject;
21     DWORD iType;
22     DWORD mm;
23     DWORD xExt;
24     DWORD yExt;
25     ULONG cjData;
26     PBYTE pjData[4];
27 } METATYPEOBJ, *PMETATYPEOBJ;
28 
29 
30 /* System Service Calls ******************************************************/
31 
32 /*
33  * @implemented
34  */
35 HDC
36 APIENTRY
NtGdiCreateMetafileDC(IN HDC hdc)37 NtGdiCreateMetafileDC(IN HDC hdc)
38 {
39     //if (hdc)
40         /* Call the internal function to create an alternative info DC */
41         return GreCreateCompatibleDC(hdc, TRUE);
42     // No HDC call NtUser.
43     //return UserGetDesktopDC(DCTYPE_INFO, TRUE, FALSE);
44 }
45 
46 /*
47  * @implemented
48  */
49 HANDLE
50 APIENTRY
NtGdiCreateServerMetaFile(IN DWORD iType,IN ULONG cjData,IN PBYTE pjData,IN DWORD mm,IN DWORD xExt,IN DWORD yExt)51 NtGdiCreateServerMetaFile(
52     IN DWORD iType,
53     IN ULONG cjData,
54     IN PBYTE pjData,
55     IN DWORD mm,
56     IN DWORD xExt,
57     IN DWORD yExt
58 )
59 {
60     BOOL Pass = TRUE;
61     PMETATYPEOBJ pmto;
62 
63     if ( ( iType == GDITAG_TYPE_EMF || iType == GDITAG_TYPE_MFP ) &&
64         cjData &&
65         pjData )
66     {
67         pmto = (PMETATYPEOBJ)GDIOBJ_AllocObjWithHandle(GDILoObjType_LO_META_TYPE, sizeof(METATYPEOBJ) + cjData);
68         if ( pmto )
69         {
70             pmto->iType  = iType;
71             pmto->mm     = mm;
72             pmto->xExt   = xExt;
73             pmto->yExt   = yExt;
74             pmto->cjData = cjData;
75 
76             _SEH2_TRY
77             {
78                 ProbeForRead( pjData, cjData, 1 );
79                 RtlCopyMemory( pmto->pjData, pjData, cjData) ;
80             }
81             _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
82             {
83                 Pass = FALSE;
84             }
85             _SEH2_END;
86 
87             if (Pass)
88             {
89                GDIOBJ_vSetObjectOwner(&pmto->BaseObject, GDI_OBJ_HMGR_PUBLIC);
90                GDIOBJ_vUnlockObject(&pmto->BaseObject);
91                return pmto->BaseObject.hHmgr;
92             }
93             else
94             {
95                GDIOBJ_vDeleteObject(&pmto->BaseObject);
96             }
97         }
98     }
99     return NULL;
100 }
101 
102 /*
103  * @implemented
104  */
105 ULONG
106 APIENTRY
NtGdiGetServerMetaFileBits(IN HANDLE hmo,IN ULONG cjData,OUT OPTIONAL PBYTE pjData,OUT PDWORD piType,OUT PDWORD pmm,OUT PDWORD pxExt,OUT PDWORD pyExt)107 NtGdiGetServerMetaFileBits(
108     IN HANDLE hmo,
109     IN ULONG cjData,
110     OUT OPTIONAL PBYTE pjData,
111     OUT PDWORD piType,
112     OUT PDWORD pmm,
113     OUT PDWORD pxExt,
114     OUT PDWORD pyExt
115 )
116 {
117     ULONG cjRet = 0;
118     PMETATYPEOBJ pmto;
119 
120     pmto = (PMETATYPEOBJ) GDIOBJ_LockObject( hmo, GDIObjType_META_TYPE);
121 
122     if (!pmto)
123         return 0;
124 
125     if ( pmto->iType == GDITAG_TYPE_EMF || pmto->iType == GDITAG_TYPE_MFP )
126     {
127         cjRet = pmto->cjData;
128 
129         if ( cjData )
130         {
131             if (cjData == pmto->cjData)
132             {
133                 _SEH2_TRY
134                 {
135                     ProbeForWrite( piType, sizeof(DWORD), 1);
136                     *piType = pmto->iType;
137 
138                     ProbeForWrite( pmm, sizeof(DWORD), 1);
139                     *pmm = pmto->mm;
140 
141                     ProbeForWrite( pxExt, sizeof(DWORD), 1);
142                     *pxExt = pmto->xExt;
143 
144                     ProbeForWrite( pyExt, sizeof(DWORD), 1);
145                     *pyExt = pmto->yExt;
146 
147                     ProbeForWrite( pjData, cjData, 1 );
148                     RtlCopyMemory( pjData, pmto->pjData, cjData) ;
149                 }
150                 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
151                 {
152                     cjRet = 0;
153                 }
154                 _SEH2_END;
155             }
156             else
157             {
158                 cjRet = 0;
159             }
160         }
161     }
162 
163     GDIOBJ_vUnlockObject(&pmto->BaseObject);
164     return cjRet;
165 }
166 
167 /*
168  * @unimplemented
169  */
170 LONG
171 APIENTRY
NtGdiConvertMetafileRect(IN HDC hDC,IN OUT PRECTL pRect)172 NtGdiConvertMetafileRect(IN HDC hDC,
173                          IN OUT PRECTL pRect)
174 {
175     UNIMPLEMENTED;
176     return 0;
177 }
178 
179 /* EOF */
180