[GDI32]
[reactos.git] / reactos / win32ss / gdi / gdi32 / include / gdi32p.h
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS System Libraries
4 * FILE: lib/gdi32/include/gdi32p.h
5 * PURPOSE: User-Mode Win32 GDI Library Private Header
6 * PROGRAMMER: Alex Ionescu (alex@relsoft.net)
7 */
8
9 #pragma once
10
11 /* DATA **********************************************************************/
12
13 extern PGDI_TABLE_ENTRY GdiHandleTable;
14 extern PGDI_SHARED_HANDLE_TABLE GdiSharedHandleTable;
15 extern HANDLE hProcessHeap;
16 extern HANDLE CurrentProcessId;
17 extern DWORD GDI_BatchLimit;
18 extern PDEVCAPS GdiDevCaps;
19 extern BOOL gbLpk; // Global bool LanguagePack
20 extern HANDLE ghSpooler;
21 extern RTL_CRITICAL_SECTION semLocal;
22
23 typedef INT
24 (CALLBACK* EMFPLAYPROC)(
25 HDC hdc,
26 INT iFunction,
27 HANDLE hPageQuery
28 );
29
30 /* DEFINES *******************************************************************/
31
32 #define HANDLE_LIST_INC 20
33
34 #define METAFILE_MEMORY 1
35 #define METAFILE_DISK 2
36
37 #define SAPCALLBACKDELAY 244
38
39 /* MACRO ********************************************************************/
40
41 #define ROP_USES_SOURCE(Rop) (((Rop) << 2 ^ Rop) & 0xCC0000)
42
43 /* TYPES *********************************************************************/
44
45 // Based on wmfapi.h and Wine.
46 typedef struct tagMETAFILEDC
47 {
48 PVOID pvMetaBuffer;
49 HANDLE hFile;
50 DWORD Size;
51 DWORD dwWritten;
52 METAHEADER mh;
53 WORD reserved;
54 HLOCAL MFObjList;
55 HPEN hPen;
56 HBRUSH hBrush;
57 HDC hDc;
58 HGDIOBJ hMetaDc;
59 HPALETTE hPalette;
60 HFONT hFont;
61 HBITMAP hBitmap;
62 HRGN hRegion;
63 HGDIOBJ hMetafile;
64 HGDIOBJ hMemDc;
65 HPEN hExtPen;
66 HGDIOBJ hEnhMetaDc;
67 HGDIOBJ hEnhMetaFile;
68 HCOLORSPACE hColorSpace;
69 WCHAR Filename[MAX_PATH+2];
70 } METAFILEDC,*PMETAFILEDC;
71
72 // Metafile Entry handle
73 typedef struct tagMF_ENTRY
74 {
75 LIST_ENTRY List;
76 HGDIOBJ hmDC; // Handle return from NtGdiCreateClientObj.
77 PMETAFILEDC pmfDC;
78 } MF_ENTRY, *PMF_ENTRY;
79
80 typedef struct tagENHMETAFILE
81 {
82 PVOID pvMetaBuffer;
83 HANDLE hFile; /* Handle for disk based MetaFile */
84 DWORD Size;
85 INT iType;
86 PENHMETAHEADER emf;
87 UINT handles_size, cur_handles;
88 HGDIOBJ *handles;
89 INT horzres, vertres;
90 INT horzsize, vertsize;
91 INT logpixelsx, logpixelsy;
92 INT bitspixel;
93 INT textcaps;
94 INT rastercaps;
95 INT technology;
96 INT planes;
97 } ENHMETAFILE,*PENHMETAFILE;
98
99
100 #define PDEV_UMPD_ID 0xFEDCBA98
101 // UMPDEV flags
102 #define UMPDEV_NO_ESCAPE 0x0002
103 #define UMPDEV_SUPPORT_ESCAPE 0x0004
104 typedef struct _UMPDEV
105 {
106 DWORD Sig; // Init with PDEV_UMPD_ID
107 struct _UMPDEV *pumpdNext;
108 PDRIVER_INFO_5W pdi5Info;
109 HMODULE hModule;
110 DWORD dwFlags;
111 DWORD dwDriverAttributes;
112 DWORD dwConfigVersion; // Number of times the configuration
113 // file for this driver has been upgraded
114 // or downgraded since the last spooler restart.
115 DWORD dwDriverCount; // After init should be 2
116 DWORD WOW64_UMPDev;
117 DWORD WOW64_hMod;
118 DWORD Unknown;
119 PVOID apfn[INDEX_LAST]; // Print Driver pfn
120 } UMPDEV, *PUMPDEV;
121
122 #define LOCALFONT_COUNT 10
123 typedef struct _LOCALFONT
124 {
125 FONT_ATTR lfa[LOCALFONT_COUNT];
126 } LOCALFONT, *PLOCALFONT;
127
128 // sdk/winspool.h
129 typedef BOOL (WINAPI *ABORTPRINTER) (HANDLE);
130 typedef BOOL (WINAPI *CLOSEPRINTER) (HANDLE);
131 typedef BOOL (WINAPI *CLOSESPOOLFILEHANDLE) (HANDLE, HANDLE); // W2k8
132 typedef HANDLE (WINAPI *COMMITSPOOLDATA) (HANDLE,HANDLE,DWORD); // W2k8
133 typedef LONG (WINAPI *DOCUMENTPROPERTIESW) (HWND,HANDLE,LPWSTR,PDEVMODEW,PDEVMODEW,DWORD);
134 typedef BOOL (WINAPI *ENDDOCPRINTER) (HANDLE);
135 typedef BOOL (WINAPI *ENDPAGEPRINTER) (HANDLE);
136 typedef BOOL (WINAPI *GETPRINTERW) (HANDLE,DWORD,LPBYTE,DWORD,LPDWORD);
137 typedef BOOL (WINAPI *GETPRINTERDRIVERW) (HANDLE,LPWSTR,DWORD,LPBYTE,DWORD,LPDWORD);
138 typedef HANDLE (WINAPI *GETSPOOLFILEHANDLE) (HANDLE); // W2k8
139 typedef BOOL (WINAPI *ISVALIDDEVMODEW) (PDEVMODEW,size_t);
140 typedef BOOL (WINAPI *OPENPRINTERW) (LPWSTR,PHANDLE,LPPRINTER_DEFAULTSW);
141 typedef BOOL (WINAPI *READPRINTER) (HANDLE,PVOID,DWORD,PDWORD);
142 typedef BOOL (WINAPI *RESETPRINTERW) (HANDLE,LPPRINTER_DEFAULTSW);
143 typedef LPWSTR (WINAPI *STARTDOCDLGW) (HANDLE,DOCINFOW *);
144 typedef DWORD (WINAPI *STARTDOCPRINTERW) (HANDLE,DWORD,PBYTE);
145 typedef BOOL (WINAPI *STARTPAGEPRINTER) (HANDLE);
146 // ddk/winsplp.h
147 typedef BOOL (WINAPI *SEEKPRINTER) (HANDLE,LARGE_INTEGER,PLARGE_INTEGER,DWORD,BOOL);
148 typedef BOOL (WINAPI *SPLREADPRINTER) (HANDLE,LPBYTE *,DWORD);
149 // Same as ddk/winsplp.h DriverUnloadComplete?
150 typedef BOOL (WINAPI *SPLDRIVERUNLOADCOMPLETE) (LPWSTR);
151 // Driver support:
152 // DrvDocumentEvent api/winddiui.h not W2k8 DocumentEventAW
153 typedef INT (WINAPI *DOCUMENTEVENT) (HANDLE,HDC,INT,ULONG,PVOID,ULONG,PVOID);
154 // DrvQueryColorProfile
155 typedef BOOL (WINAPI *QUERYCOLORPROFILE) (HANDLE,PDEVMODEW,ULONG,VOID*,ULONG,FLONG);
156 // Unknown:
157 typedef DWORD (WINAPI *QUERYSPOOLMODE) (HANDLE,DWORD,DWORD);
158 typedef DWORD (WINAPI *QUERYREMOTEFONTS) (DWORD,DWORD,DWORD);
159
160 extern CLOSEPRINTER fpClosePrinter;
161 extern OPENPRINTERW fpOpenPrinterW;
162
163 /* FUNCTIONS *****************************************************************/
164
165 PVOID
166 HEAP_alloc(DWORD len);
167
168 NTSTATUS
169 HEAP_strdupA2W(
170 LPWSTR* ppszW,
171 LPCSTR lpszA
172 );
173
174 VOID
175 HEAP_free(LPVOID memory);
176
177 VOID
178 FASTCALL
179 FONT_TextMetricWToA(
180 const TEXTMETRICW *ptmW,
181 LPTEXTMETRICA ptmA
182 );
183
184 VOID
185 FASTCALL
186 NewTextMetricW2A(
187 NEWTEXTMETRICA *tma,
188 NEWTEXTMETRICW *tmw
189 );
190
191 VOID
192 FASTCALL
193 NewTextMetricExW2A(
194 NEWTEXTMETRICEXA *tma,
195 NEWTEXTMETRICEXW *tmw
196 );
197
198 BOOL
199 FASTCALL
200 DeleteRegion( HRGN );
201
202 BOOL
203 GdiIsHandleValid(HGDIOBJ hGdiObj);
204
205 BOOL
206 GdiGetHandleUserData(
207 HGDIOBJ hGdiObj,
208 DWORD ObjectType,
209 PVOID *UserData
210 );
211
212 PLDC
213 FASTCALL
214 GdiGetLDC(HDC hDC);
215
216 HGDIOBJ
217 WINAPI
218 GdiFixUpHandle(HGDIOBJ hGO);
219
220 BOOL
221 WINAPI
222 CalculateColorTableSize(
223 CONST BITMAPINFOHEADER *BitmapInfoHeader,
224 UINT *ColorSpec,
225 UINT *ColorTableSize
226 );
227
228 LPBITMAPINFO
229 WINAPI
230 ConvertBitmapInfo(
231 CONST BITMAPINFO *BitmapInfo,
232 UINT ColorSpec,
233 UINT *BitmapInfoSize,
234 BOOL FollowedByData
235 );
236
237 DWORD
238 WINAPI
239 GetAndSetDCDWord( HDC, INT, DWORD, DWORD, DWORD, DWORD );
240
241 DWORD
242 WINAPI
243 GetDCDWord( HDC, INT, DWORD);
244
245 HGDIOBJ
246 WINAPI
247 GetDCObject( HDC, INT);
248
249 VOID
250 NTAPI
251 LogFontA2W(
252 LPLOGFONTW pW,
253 CONST LOGFONTA *pA
254 );
255
256 VOID
257 NTAPI
258 LogFontW2A(
259 LPLOGFONTA pA,
260 CONST LOGFONTW *pW
261 );
262
263 VOID
264 WINAPI
265 EnumLogFontExW2A(
266 LPENUMLOGFONTEXA fontA,
267 CONST ENUMLOGFONTEXW *fontW );
268
269 /* FIXME: Put in some public header */
270 UINT
271 WINAPI
272 UserRealizePalette(HDC hDC);
273
274 int
275 WINAPI
276 GdiAddFontResourceW(LPCWSTR lpszFilename,FLONG fl,DESIGNVECTOR *pdv);
277
278 VOID
279 WINAPI
280 GdiSetLastError( DWORD dwErrCode );
281
282 DWORD WINAPI GdiGetCodePage(HDC);
283
284 int
285 WINAPI
286 GdiGetBitmapBitsSize(BITMAPINFO *lpbmi);
287
288 VOID GdiSAPCallback(PLDC pldc);
289 HGDIOBJ FASTCALL hGetPEBHandle(HANDLECACHETYPE,COLORREF);
290
291 int FASTCALL DocumentEventEx(PVOID,HANDLE,HDC,int,ULONG,PVOID,ULONG,PVOID);
292 BOOL FASTCALL EndPagePrinterEx(PVOID,HANDLE);
293 BOOL FASTCALL LoadTheSpoolerDrv(VOID);
294
295 FORCEINLINE
296 PVOID
297 GdiAllocBatchCommand(
298 HDC hdc,
299 USHORT Cmd)
300 {
301 PTEB pTeb;
302 USHORT cjSize;
303 PGDIBATCHHDR pHdr;
304
305 /* Get a pointer to the TEB */
306 pTeb = NtCurrentTeb();
307
308 /* Check if we have a valid environment */
309 if (!pTeb || !pTeb->Win32ThreadInfo) return NULL;
310
311 /* Do we use a DC? */
312 if (hdc)
313 {
314 /* If the batch DC is NULL, we set this one as the new one */
315 if (!pTeb->GdiTebBatch.HDC) pTeb->GdiTebBatch.HDC = hdc;
316
317 /* If not, check if the batch DC equal to our DC */
318 else if (pTeb->GdiTebBatch.HDC != hdc) return NULL;
319 }
320
321 /* Get the size of the entry */
322 if (Cmd == GdiBCPatBlt) cjSize = 0;
323 else if (Cmd == GdiBCPolyPatBlt) cjSize = 0;
324 else if (Cmd == GdiBCTextOut) cjSize = 0;
325 else if (Cmd == GdiBCExtTextOut) cjSize = 0;
326 else if (Cmd == GdiBCSetBrushOrg) cjSize = sizeof(GDIBSSETBRHORG);
327 else if (Cmd == GdiBCExtSelClipRgn) cjSize = 0;
328 else if (Cmd == GdiBCSelObj) cjSize = sizeof(GDIBSOBJECT);
329 else if (Cmd == GdiBCDelRgn) cjSize = sizeof(GDIBSOBJECT);
330 else if (Cmd == GdiBCDelObj) cjSize = sizeof(GDIBSOBJECT);
331 else cjSize = 0;
332
333 /* Unsupported operation */
334 if (cjSize == 0) return NULL;
335
336 /* Check if the buffer is full */
337 if ((pTeb->GdiBatchCount >= GDI_BatchLimit) ||
338 ((pTeb->GdiTebBatch.Offset + cjSize) > GDIBATCHBUFSIZE))
339 {
340 /* Call win32k, the kernel will call NtGdiFlushUserBatch to flush
341 the current batch */
342 NtGdiFlush();
343 }
344
345 /* Get the head of the entry */
346 pHdr = (PVOID)((PUCHAR)pTeb->GdiTebBatch.Buffer + pTeb->GdiTebBatch.Offset);
347
348 /* Update Offset and batch count */
349 pTeb->GdiTebBatch.Offset += cjSize;
350 pTeb->GdiBatchCount++;
351
352 /* Fill in the core fields */
353 pHdr->Cmd = Cmd;
354 pHdr->Size = cjSize;
355
356 return pHdr;
357 }
358
359 FORCEINLINE
360 PDC_ATTR
361 GdiGetDcAttr(HDC hdc)
362 {
363 PDC_ATTR pdcattr;
364
365 if (!GdiGetHandleUserData((HGDIOBJ)hdc, GDI_OBJECT_TYPE_DC, (PVOID*)&pdcattr)) return NULL;
366 return pdcattr;
367 }
368
369 #ifdef _M_IX86
370 FLOATL FASTCALL EFtoF(EFLOAT_S * efp);
371 #define FOtoF(pfo) EFtoF((EFLOAT_S*)pfo)
372 #else
373 #define FOtoF(pfo) (*(pfo))
374 #endif
375
376 /* This is an inlined version of lrintf. */
377 FORCEINLINE
378 int
379 _lrintf(float f)
380 {
381 #if defined(_M_IX86) && defined(__GNUC__)
382 int result;
383 __asm__ __volatile__ ("fistpl %0" : "=m" (result) : "t" (f) : "st");
384 return result;
385 #elif defined(_M_IX86) && defined(_MSC_VER)
386 int result;
387 __asm
388 {
389 fld f;
390 fistp result;
391 }
392 #else
393 /* slow, but portable */
394 return (int)(f >= 0 ? f+0.5 : f-0.5);
395 #endif
396 }
397
398 /* EOF */