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