win32u: Use KBDTABLES for NtUserVkKeyScanEx.
[wine.git] / dlls / winprint / printproc.c
blob3c2fb3ad3c8e6c668bd8f318d6831e1d3ba4981b
1 /*
2 * Print processor implementation.
4 * Copyright 2022 Piotr Caban for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 /* Missing datatypes support:
22 * RAW [FF appended]
23 * RAW [FF auto]
24 * NT EMF 1.003
25 * NT EMF 1.006
26 * NT EMF 1.007
27 * NT EMF 1.008
28 * TEXT
29 * XPS2GDI
31 * Implement print processor features like e.g. printing multiple copies. */
33 #include <stdlib.h>
35 #include "windows.h"
36 #include "winspool.h"
37 #include "ddk/winsplp.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(winprint);
43 #define PP_MAGIC 0x952173fd
45 struct pp_data
47 DWORD magic;
48 HANDLE hport;
49 WCHAR *doc_name;
50 WCHAR *out_file;
53 static struct pp_data* get_handle_data(HANDLE pp)
55 struct pp_data *ret = (struct pp_data *)pp;
57 if (!ret || ret->magic != PP_MAGIC)
59 SetLastError(ERROR_INVALID_HANDLE);
60 return NULL;
62 return ret;
65 BOOL WINAPI EnumPrintProcessorDatatypesW(WCHAR *server, WCHAR *name, DWORD level,
66 BYTE *datatypes, DWORD size, DWORD *needed, DWORD *no)
68 static const WCHAR raw[] = L"RAW";
70 DATATYPES_INFO_1W *info = (DATATYPES_INFO_1W *)datatypes;
72 TRACE("%s, %s, %ld, %p, %ld, %p, %p\n", debugstr_w(server), debugstr_w(name),
73 level, datatypes, size, needed, no);
75 if (!needed || !no)
77 SetLastError(ERROR_INVALID_PARAMETER);
78 return FALSE;
81 *no = 0;
82 *needed = sizeof(*info) + sizeof(raw);
84 if (level != 1 || (size && !datatypes))
86 SetLastError(ERROR_INVALID_PARAMETER);
87 return FALSE;
90 if (size < *needed)
92 SetLastError(ERROR_INSUFFICIENT_BUFFER);
93 return FALSE;
96 *no = 1;
97 info->pName = (WCHAR*)(info + 1);
98 memcpy(info + 1, raw, sizeof(raw));
99 return TRUE;
102 HANDLE WINAPI OpenPrintProcessor(WCHAR *port, PRINTPROCESSOROPENDATA *open_data)
104 struct pp_data *data;
105 HANDLE hport;
107 TRACE("%s, %p\n", debugstr_w(port), open_data);
109 if (!port || !open_data || !open_data->pDatatype)
111 SetLastError(ERROR_INVALID_PARAMETER);
112 return NULL;
114 if (wcscmp(open_data->pDatatype, L"RAW"))
116 SetLastError(ERROR_INVALID_DATATYPE);
117 return NULL;
120 if (!OpenPrinterW(port, &hport, NULL))
121 return NULL;
123 data = LocalAlloc(LMEM_FIXED | LMEM_ZEROINIT, sizeof(*data));
124 if (!data)
125 return NULL;
126 data->magic = PP_MAGIC;
127 data->hport = hport;
128 data->doc_name = wcsdup(open_data->pDocumentName);
129 data->out_file = wcsdup(open_data->pOutputFile);
130 return (HANDLE)data;
133 BOOL WINAPI PrintDocumentOnPrintProcessor(HANDLE pp, WCHAR *doc_name)
135 struct pp_data *data = get_handle_data(pp);
136 HANDLE spool_data;
137 DOC_INFO_1W info;
138 BYTE buf[0x1000];
139 DWORD r, w;
141 TRACE("%p, %s\n", pp, debugstr_w(doc_name));
143 if (!data)
144 return FALSE;
146 if (!OpenPrinterW(doc_name, &spool_data, NULL))
147 return FALSE;
149 info.pDocName = data->doc_name;
150 info.pOutputFile = data->out_file;
151 info.pDatatype = (WCHAR *)L"RAW";
152 if (!StartDocPrinterW(data->hport, 1, (BYTE *)&info))
154 ClosePrinter(spool_data);
155 return FALSE;
158 while (ReadPrinter(spool_data, buf, sizeof(buf), &r) && r)
160 if (!WritePrinter(data->hport, buf, r, &w) || r != w)
162 ClosePrinter(spool_data);
163 EndDocPrinter(data->hport);
164 return FALSE;
167 ClosePrinter(spool_data);
169 return EndDocPrinter(data->hport);
172 BOOL WINAPI ControlPrintProcessor(HANDLE pp, DWORD cmd)
174 FIXME("%p, %ld\n", pp, cmd);
175 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
176 return FALSE;
179 BOOL WINAPI ClosePrintProcessor(HANDLE pp)
181 struct pp_data *data = get_handle_data(pp);
183 TRACE("%p\n", pp);
185 if (!data)
186 return FALSE;
188 ClosePrinter(data->hport);
189 free(data->doc_name);
190 free(data->out_file);
192 memset(data, 0, sizeof(*data));
193 LocalFree(data);
194 return TRUE;
197 HRESULT WINAPI DllRegisterServer(void)
199 AddPrintProcessorW(NULL, (WCHAR *)L"Windows 4.0", (WCHAR *)L"winprint.dll", (WCHAR *)L"winprint");
200 AddPrintProcessorW(NULL, NULL, (WCHAR *)L"winprint.dll", (WCHAR *)L"winprint");
201 return S_OK;