ReactOS  0.4.14-dev-384-g5b37caa
gdiobj.c
Go to the documentation of this file.
1 #include <precomp.h>
2 
3 #define NDEBUG
4 #include <debug.h>
5 
7 
8 /*
9  * @implemented
10  */
11 HGDIOBJ
12 WINAPI
14  INT fnObject)
15 {
16  HGDIOBJ hobj;
17 
18  if ((fnObject < 0) || (fnObject >= NB_STOCK_OBJECTS))
19  return NULL;
20 
21  hobj = stock_objects[fnObject];
22  if (hobj == NULL)
23  {
24  hobj = NtGdiGetStockObject(fnObject);
25 
26  if (!GdiValidateHandle(hobj))
27  {
28  return NULL;
29  }
30 
31  stock_objects[fnObject] = hobj;
32  }
33 
34  return hobj;
35 }
36 
37 
38 /*
39  * @implemented
40  */
41 DWORD
42 WINAPI
44  HGDIOBJ h)
45 {
46  DWORD Ret = 0;
47 
48  if (GdiValidateHandle(h))
49  {
51  switch(Type)
52  {
54  Ret = OBJ_PEN;
55  break;
57  Ret = OBJ_BRUSH;
58  break;
60  Ret = OBJ_BITMAP;
61  break;
63  Ret = OBJ_FONT;
64  break;
66  Ret = OBJ_PAL;
67  break;
69  Ret = OBJ_REGION;
70  break;
71  case GDI_OBJECT_TYPE_DC:
72  if ( GetDCDWord( h, GdiGetIsMemDc, 0))
73  {
74  Ret = OBJ_MEMDC;
75  }
76  else
77  Ret = OBJ_DC;
78  break;
80  Ret = OBJ_COLORSPACE;
81  break;
83  Ret = OBJ_METAFILE;
84  break;
86  Ret = OBJ_ENHMETAFILE;
87  break;
89  Ret = OBJ_METADC;
90  break;
92  Ret = OBJ_EXTPEN;
93  break;
94 
96  // FIXME: could be something else?
97  Ret = OBJ_ENHMETADC;
98  break;
99 
100  default:
101  DPRINT1("GetObjectType: Magic 0x%08x not implemented\n", Type);
102  break;
103  }
104  }
105  else
106  /* From Wine: GetObjectType does SetLastError() on a null object */
108  return Ret;
109 }
110 
111 ULONG
112 WINAPI
115  _In_ ULONG cbSize,
117 {
118  ENUMLOGFONTEXDVW elfedvW;
119  ENUMLOGFONTEXDVA elfedvA;
120  ULONG cbResult;
121 
122  /* Check if size only is requested */
123  if (!lpBuffer) return sizeof(LOGFONTA);
124 
125  /* Check for size 0 */
126  if (cbSize == 0)
127  {
128  /* Windows does not SetLastError() */
129  return 0;
130  }
131 
132  /* Windows does this ... */
133  if (cbSize == sizeof(LOGFONTW)) cbSize = sizeof(LOGFONTA);
134 
135  /* Call win32k to get the logfont (widechar) */
136  cbResult = NtGdiExtGetObjectW(hfont, sizeof(ENUMLOGFONTEXDVW), &elfedvW);
137  if (cbResult == 0)
138  {
139  return 0;
140  }
141 
142  /* Convert the logfont from widechar to ansi */
144  elfedvA.elfDesignVector = elfedvW.elfDesignVector;
145 
146  /* Don't copy more than maximum */
147  if (cbSize > sizeof(ENUMLOGFONTEXDVA)) cbSize = sizeof(ENUMLOGFONTEXDVA);
148 
149  /* Copy the number of bytes requested */
150  memcpy(lpBuffer, &elfedvA, cbSize);
151 
152  /* Return the number of bytes copied */
153  return cbSize;
154 }
155 
156 
157 /*
158  * @implemented
159  */
160 int
161 WINAPI
163  _In_ HGDIOBJ hGdiObj,
164  _In_ int cbSize,
166 {
167  DWORD dwType = GDI_HANDLE_GET_TYPE(hGdiObj);
168 
169  /* Chjeck if this is anything else but a font */
170  if (dwType == GDI_OBJECT_TYPE_FONT)
171  {
172  return GetFontObjectA(hGdiObj, cbSize, lpBuffer);
173  }
174  else
175  {
176  /* Simply pass it to the widechar version */
177  return GetObjectW(hGdiObj, cbSize, lpBuffer);
178  }
179 }
180 
181 
182 /*
183  * @implemented
184  */
185 int
186 WINAPI
188  _In_ HGDIOBJ hGdiObj,
189  _In_ int cbSize,
191 {
192  DWORD dwType;
193  INT cbResult = 0;
194 
195  /* Fixup handles with upper 16 bits masked */
196  hGdiObj = GdiFixUpHandle(hGdiObj);
197 
198  /* Get the object type */
199  dwType = GDI_HANDLE_GET_TYPE(hGdiObj);
200 
201  /* Check what kind of object we have */
202  switch (dwType)
203  {
204  case GDI_OBJECT_TYPE_PEN:
205  if (!lpBuffer) return sizeof(LOGPEN);
206  break;
207 
209  if (!lpBuffer || !cbSize) return sizeof(LOGBRUSH);
210  break;
211 
213  if (!lpBuffer) return sizeof(BITMAP);
214  break;
215 
217  if (!lpBuffer) return sizeof(WORD);
218  break;
219 
221  if (!lpBuffer) return sizeof(LOGFONTW);
222  break;
223 
225  /* we don't know the size, ask win32k */
226  break;
227 
229  if ((cbSize < 328) || !lpBuffer)
230  {
232  return 0;
233  }
234  break;
235 
236  case GDI_OBJECT_TYPE_DC:
238  case GDI_OBJECT_TYPE_EMF:
242  default:
243  return 0;
244  }
245 
246  /* Call win32k */
247  cbResult = NtGdiExtGetObjectW(hGdiObj, cbSize, lpBuffer);
248 
249  /* Handle error */
250  if (cbResult == 0)
251  {
252  if (!GdiValidateHandle(hGdiObj))
253  {
254  if ((dwType == GDI_OBJECT_TYPE_PEN) ||
255  (dwType == GDI_OBJECT_TYPE_EXTPEN) ||
256  (dwType == GDI_OBJECT_TYPE_BRUSH) ||
257  (dwType == GDI_OBJECT_TYPE_COLORSPACE))
258  {
260  }
261  }
262  else
263  {
264  if ((dwType == GDI_OBJECT_TYPE_PEN) ||
265  (dwType == GDI_OBJECT_TYPE_BRUSH) ||
266  (dwType == GDI_OBJECT_TYPE_COLORSPACE) ||
267  ( (dwType == GDI_OBJECT_TYPE_EXTPEN) &&
268  ( (cbSize >= sizeof(EXTLOGPEN)) || (cbSize == 0) ) ) ||
269  ( (dwType == GDI_OBJECT_TYPE_BITMAP) && (cbSize >= sizeof(BITMAP)) ))
270  {
272  }
273  }
274  }
275 
276  return cbResult;
277 }
278 
279 static
280 BOOL
282  HGDIOBJ hobj)
283 {
284  GDILOOBJTYPE eObjectType;
285  PBRUSH_ATTR pbrattr;
286  PTEB pTeb;
287  PGDIBSOBJECT pgO;
288 
289  eObjectType = GDI_HANDLE_GET_TYPE(hobj);
290 
291  if ((GdiGetHandleUserData(hobj, eObjectType, (PVOID*)&pbrattr)) &&
292  (pbrattr != NULL))
293  {
294  pTeb = NtCurrentTeb();
295  if (pTeb->Win32ThreadInfo != NULL)
296  {
298  if (pgO)
299  {
301  pgO->hgdiobj = hobj;
302  return TRUE;
303  }
304  }
305  }
306 
307  return NtGdiDeleteObjectApp(hobj);
308 }
309 
310 /*
311  * @implemented
312  */
313 BOOL
314 WINAPI
316 {
317  /* Check if the handle is valid (FIXME: we need some special
318  sauce for the stock object flag) */
319  if (!GdiValidateHandle(hObject))
320  return FALSE;
321 
322  /* Check if this is a stock object */
323  if ((DWORD_PTR)hObject & GDI_HANDLE_STOCK_MASK)
324  {
325  /* Ignore the attempt to delete a stock object */
326  DPRINT("Trying to delete system object 0x%p\n", hObject);
327  return TRUE;
328  }
329 
330  /* If we have any METAFILE objects, we need to check them */
331  if (gcClientObj > 0)
332  {
333  METADC_DeleteObject(hObject);
334  }
335 
336  /* Switch by object type */
337  switch (GDI_HANDLE_GET_TYPE(hObject))
338  {
341  return FALSE;
342 
345  return DeleteDC(hObject);
346 
348  return NtGdiDeleteColorSpace(hObject);
349 
351  return DeleteRegion(hObject);
352 #if 0
354  return MFDRV_DeleteObject( hObject );
355  case GDI_OBJECT_TYPE_EMF:
356  {
357  PLDC pLDC = GdiGetLDC(hObject);
358  if ( !pLDC ) return FALSE;
359  return EMFDRV_DeleteObject( hObject );
360  }
361 #endif
365  return GdiDeleteBrushOrPen(hObject);
366 
369  default:
370  break;
371  }
372 
373  return NtGdiDeleteObjectApp(hObject);
374 }
375 
376 
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
HGDIOBJ WINAPI GetStockObject(INT fnObject)
Definition: gdiobj.c:13
ULONG WINAPI GetFontObjectA(_In_ HGDIOBJ hfont, _In_ ULONG cbSize, _Out_ LPVOID lpBuffer)
Definition: gdiobj.c:113
#define TRUE
Definition: types.h:120
struct tagENUMLOGFONTEXDVA ENUMLOGFONTEXDVA
Type
Definition: Type.h:6
static void DeleteRegion(GLUtesselator *tess, ActiveRegion *reg)
Definition: sweep.c:151
#define NB_STOCK_OBJECTS
Definition: ntgdityp.h:191
PVOID Win32ThreadInfo
Definition: compat.h:503
#define GDI_OBJECT_TYPE_ENHMETAFILE
Definition: gdi.h:59
int WINAPI GetObjectA(_In_ HGDIOBJ hGdiObj, _In_ int cbSize, _Out_ LPVOID lpBuffer)
Definition: gdiobj.c:162
#define OBJ_MEMDC
Definition: objidl.idl:1418
__kernel_entry W32KAPI HANDLE APIENTRY NtGdiGetStockObject(_In_ INT iObject)
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
#define GDI_OBJECT_TYPE_REGION
Definition: gdi.h:47
ENUMLOGFONTEXA elfEnumLogfontEx
Definition: wingdi.h:2769
BOOL MFDRV_DeleteObject(PHYSDEV dev, HGDIOBJ obj) DECLSPEC_HIDDEN
Definition: objects.c:98
int32_t INT
Definition: typedefs.h:56
HGDIOBJ stock_objects[NB_STOCK_OBJECTS]
Definition: gdiobj.c:6
#define GDI_OBJECT_TYPE_EXTPEN
Definition: gdi.h:55
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
#define OBJ_PEN
Definition: objidl.idl:1409
#define GDI_OBJECT_TYPE_COLORSPACE
Definition: gdi.h:56
W32KAPI INT APIENTRY NtGdiExtGetObjectW(IN HANDLE hobj, IN INT cjBufferSize, OUT LPVOID lpBuffer)
Definition: gdiobj.c:1323
__kernel_entry W32KAPI BOOL APIENTRY NtGdiDeleteColorSpace(_In_ HANDLE hColorSpace)
#define ERROR_NOACCESS
Definition: winerror.h:578
#define OBJ_ENHMETAFILE
Definition: objidl.idl:1421
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
#define GDI_OBJECT_TYPE_BRUSH
Definition: gdi.h:52
#define OBJ_COLORSPACE
Definition: wingdi.h:703
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:173
smooth NULL
Definition: ftsmooth.c:416
#define _Out_
Definition: no_sal2.h:323
#define OBJ_REGION
Definition: objidl.idl:1416
void DPRINT(...)
Definition: polytest.cpp:61
BOOL EMFDRV_DeleteObject(PHYSDEV dev, HGDIOBJ obj) DECLSPEC_HIDDEN
Definition: objects.c:77
HGDIOBJ WINAPI GdiFixUpHandle(HGDIOBJ hGO)
Definition: misc.c:734
#define GDI_OBJECT_TYPE_PALETTE
Definition: gdi.h:49
static HFONT hfont
DESIGNVECTOR elfDesignVector
Definition: wingdi.h:2770
#define GDI_HANDLE_GET_TYPE(h)
Definition: gdi.h:31
#define OBJ_METAFILE
Definition: objidl.idl:1417
PLDC FASTCALL GdiGetLDC(HDC hDC)
Definition: misc.c:785
DWORD WINAPI GetObjectType(HGDIOBJ h)
Definition: gdiobj.c:43
#define GDI_OBJECT_TYPE_PEN
Definition: gdi.h:54
struct tagLOGFONTW LOGFONTW
HGDIOBJ hgdiobj
Definition: ntgdityp.h:559
#define OBJ_ENHMETADC
Definition: objidl.idl:1420
DWORD WINAPI GetDCDWord(_In_ HDC hdc, _In_ UINT u, _In_ DWORD dwError)
Definition: dc.c:763
#define WINAPI
Definition: msvc.h:8
BOOL WINAPI DeleteObject(HGDIOBJ hObject)
Definition: gdiobj.c:315
unsigned short WORD
Definition: ntddk_ex.h:93
#define OBJ_DC
Definition: objidl.idl:1411
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:417
#define OBJ_PAL
Definition: objidl.idl:1413
#define GDI_OBJECT_TYPE_METADC
Definition: gdi.h:57
#define OBJ_FONT
Definition: objidl.idl:1414
Definition: ntgdihdl.h:275
#define GDI_OBJECT_TYPE_DC
Definition: gdi.h:46
#define GDI_OBJECT_TYPE_METAFILE
Definition: gdi.h:58
#define GDI_OBJECT_TYPE_BITMAP
Definition: gdi.h:48
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
uint32_t DWORD_PTR
Definition: typedefs.h:63
#define OBJ_EXTPEN
Definition: objidl.idl:1419
static BOOL GdiDeleteBrushOrPen(HGDIOBJ hobj)
Definition: gdiobj.c:281
#define _In_
Definition: no_sal2.h:204
Definition: compat.h:492
struct tagLOGPEN LOGPEN
PVOID GdiGetHandleUserData(_In_ HGDIOBJ hobj)
Definition: gditools.c:68
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
__kernel_entry W32KAPI BOOL APIENTRY NtGdiDeleteObjectApp(_In_ HANDLE hobj)
BOOL WINAPI DeleteDC(_In_ HDC)
#define OBJ_BRUSH
Definition: objidl.idl:1410
#define GDI_OBJECT_TYPE_EMF
Definition: gdi.h:53
Definition: bl.h:1331
VOID WINAPI METADC_DeleteObject(HGDIOBJ hobj)
Definition: rosglue.c:1229
#define OBJ_METADC
Definition: objidl.idl:1412
#define DPRINT1
Definition: precomp.h:8
int WINAPI GetObjectW(_In_ HGDIOBJ hGdiObj, _In_ int cbSize, _Out_ LPVOID lpBuffer)
Definition: gdiobj.c:187
DESIGNVECTOR elfDesignVector
Definition: wingdi.h:2775
struct tagLOGFONTA LOGFONTA
unsigned int ULONG
Definition: retypes.h:1
ENUMLOGFONTEXW elfEnumLogfontEx
Definition: wingdi.h:2774
FORCEINLINE PVOID GdiAllocBatchCommand(HDC hdc, USHORT Cmd)
Definition: gdi32p.h:381
enum GDILoObjType GDILOOBJTYPE
VOID WINAPI EnumLogFontExW2A(LPENUMLOGFONTEXA fontA, CONST ENUMLOGFONTEXW *fontW)
Definition: utils.c:402
struct tagLOGBRUSH LOGBRUSH
ULONG gcClientObj
Definition: clientobj.c:11
#define GDI_OBJECT_TYPE_FONT
Definition: gdi.h:50
#define OBJ_BITMAP
Definition: objidl.idl:1415
#define BITMAP
Definition: pedump.c:503
BOOL WINAPI GdiValidateHandle(HGDIOBJ)
Definition: misc.c:712
#define GDI_HANDLE_STOCK_MASK
Definition: gdi.h:19
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10