Release 980628
[wine/multimedia.git] / misc / printdrv.c
blob37a1748d6408dcb4f93be8a621f6cf711862ac4d
1 /*
2 * Implementation of some printer driver bits
3 *
4 * Copyright 1996 John Harvey
5 */
7 #include <stdlib.h>
8 #include <string.h>
9 #include <ctype.h>
10 #include "windows.h"
11 #include "win.h"
12 #include "winerror.h"
13 #include "winreg.h"
14 #include "debug.h"
16 #define INT_PD_DEFAULT_DEVMODE 1
17 #define INT_PD_DEFAULT_MODEL 2
19 static char PrinterModel[] = "Printer Model";
20 static char DefaultDevMode[] = "Default DevMode";
21 static char PrinterDriverData[] = "PrinterDriverData";
22 static char Printers[] = "System\\CurrentControlSet\\Control\\Print\\Printers\\";
24 INT16 WINAPI StartDoc16( HDC16 hdc, const DOCINFO16 *lpdoc )
26 INT16 retVal;
27 TRACE(print,"(%p)\n", lpdoc );
28 TRACE(print,"%d 0x%lx:0x%p 0x%lx:0x%p\n",lpdoc->cbSize,
29 lpdoc->lpszDocName,PTR_SEG_TO_LIN(lpdoc->lpszDocName),
30 lpdoc->lpszOutput,PTR_SEG_TO_LIN(lpdoc->lpszOutput));
31 TRACE(print, "%d %s %s\n",lpdoc->cbSize,
32 (LPSTR)PTR_SEG_TO_LIN(lpdoc->lpszDocName),
33 (LPSTR)PTR_SEG_TO_LIN(lpdoc->lpszOutput));
34 retVal = Escape16(hdc, STARTDOC, sizeof(DOCINFO16), lpdoc->lpszDocName, 0);
35 TRACE(print,"Escape16 returned %d\n",retVal);
36 return retVal;
39 INT16 WINAPI EndDoc16(HDC16 hdc)
41 return Escape16(hdc, ENDDOC, 0, 0, 0);
44 WORD DrvGetPrinterDataInternal(LPSTR RegStr_Printer, LPBYTE lpPrinterData, int cbData)
46 WORD res = -1;
47 HKEY hkey;
48 DWORD dwType, cbQueryData;
50 if (!(RegOpenKey32A(HKEY_LOCAL_MACHINE, RegStr_Printer, &hkey))) {
51 if (cbData > 1) { /* "Default DevMode" */
52 if (!(RegQueryValueEx32A(hkey, DefaultDevMode, 0, &dwType, 0, &cbQueryData))) {
53 if (!lpPrinterData) res = cbQueryData;
54 else
55 if ((cbQueryData) && (cbQueryData <= cbData)) {
56 cbQueryData = cbData;
57 if (RegQueryValueEx32A(hkey, DefaultDevMode, 0,
58 &dwType, lpPrinterData, &cbQueryData))
59 res = cbQueryData;
62 else /* "Printer Driver" */
64 cbQueryData = 32;
65 RegQueryValueEx32A(hkey, "Printer Driver", 0,
66 &dwType, lpPrinterData, &cbQueryData);
67 res = cbQueryData;
71 if (hkey) RegCloseKey(hkey);
72 return res;
76 DWORD WINAPI DrvGetPrinterData(LPSTR lpPrinter, LPSTR lpProfile,
77 LPDWORD lpType, LPBYTE lpPrinterData,
78 int cbData, LPDWORD lpNeeded)
80 LPSTR RegStr_Printer;
81 HKEY hkey = 0, hkey2 = 0;
82 DWORD res = 0;
83 DWORD dwType, PrinterAttr, cbPrinterAttr, SetData, size;
85 if (HIWORD(lpPrinter))
86 TRACE(print,"printer %s\n",lpPrinter);
87 else
88 TRACE(print,"printer %p\n",lpPrinter);
89 if (HIWORD(lpProfile))
90 TRACE(print,"profile %s\n",lpProfile);
91 else
92 TRACE(print,"profile %p\n",lpProfile);
93 TRACE(print,"lpType %p\n",lpType);
95 if ((!lpPrinter) || (!lpProfile) || (!lpNeeded))
96 return ERROR_INVALID_PARAMETER;
98 RegStr_Printer = HeapAlloc(GetProcessHeap(), 0,
99 strlen(Printers) + strlen(lpPrinter) + 2);
100 strcpy(RegStr_Printer, Printers);
101 strcat(RegStr_Printer, lpPrinter);
103 if (((DWORD)lpProfile == INT_PD_DEFAULT_DEVMODE) ||
104 (!lstrcmp32A(lpProfile, DefaultDevMode))) {
105 size = DrvGetPrinterDataInternal(RegStr_Printer, lpPrinterData, cbData);
106 if (size+1) {
107 *lpNeeded = size;
108 if ((lpPrinterData) && (*lpNeeded > cbData))
109 res = ERROR_MORE_DATA;
111 else res = ERROR_INVALID_PRINTER_NAME;
113 else
114 if (((DWORD)lpProfile == INT_PD_DEFAULT_MODEL) ||
115 (!lstrcmp32A(lpProfile, PrinterModel))) {
116 *lpNeeded = 32;
117 if (!lpPrinterData) goto failed;
118 if (cbData < 32) {
119 res = ERROR_MORE_DATA;
120 goto failed;
122 size = DrvGetPrinterDataInternal(RegStr_Printer, lpPrinterData, 1);
123 if ((size+1) && (lpType))
124 *lpType = REG_SZ;
125 else
126 res = ERROR_INVALID_PRINTER_NAME;
128 else
130 if ((res = RegOpenKey32A(HKEY_LOCAL_MACHINE, RegStr_Printer, &hkey)))
131 goto failed;
132 cbPrinterAttr = 4;
133 if ((res = RegQueryValueEx32A(hkey, "Attributes", 0, &dwType, (LPBYTE)&PrinterAttr, &cbPrinterAttr)))
134 goto failed;
135 if ((res = RegOpenKey32A(hkey, PrinterDriverData, &hkey2)))
136 goto failed;
137 *lpNeeded = cbData;
138 res = RegQueryValueEx32A(hkey2, lpProfile, 0, lpType, lpPrinterData, lpNeeded);
139 if ((res != ERROR_CANTREAD) && ((PrinterAttr & (0x800|0x10)) == 0x10))
141 if (!(res) && (*lpType == REG_DWORD) && (*(LPDWORD)lpPrinterData == -1))
142 res = ERROR_INVALID_DATA;
144 else
146 SetData = -1;
147 RegSetValueEx32A(hkey2, lpProfile, 0, REG_DWORD, (LPBYTE)&SetData, 4); /* no result returned */
151 failed:
152 if (hkey2) RegCloseKey(hkey2);
153 if (hkey) RegCloseKey(hkey);
154 HeapFree(GetProcessHeap(), 0, RegStr_Printer);
155 return res;
160 DWORD WINAPI DrvSetPrinterData(LPSTR lpPrinter, LPSTR lpProfile,
161 DWORD lpType, LPBYTE lpPrinterData,
162 DWORD dwSize)
164 LPSTR RegStr_Printer;
165 HKEY hkey = 0;
166 DWORD res = 0;
168 if (HIWORD(lpPrinter))
169 TRACE(print,"printer %s\n",lpPrinter);
170 else
171 TRACE(print,"printer %p\n",lpPrinter);
172 if (HIWORD(lpProfile))
173 TRACE(print,"profile %s\n",lpProfile);
174 else
175 TRACE(print,"profile %p\n",lpProfile);
176 TRACE(print,"lpType %08lx\n",lpType);
178 if ((!lpPrinter) || (!lpProfile) ||
179 ((DWORD)lpProfile == INT_PD_DEFAULT_MODEL) ||
180 (!lstrcmp32A(lpProfile, PrinterModel)))
181 return ERROR_INVALID_PARAMETER;
183 RegStr_Printer = HeapAlloc(GetProcessHeap(), 0,
184 strlen(Printers) + strlen(lpPrinter) + 2);
185 strcpy(RegStr_Printer, Printers);
186 strcat(RegStr_Printer, lpPrinter);
188 if (((DWORD)lpProfile == INT_PD_DEFAULT_DEVMODE) ||
189 (!lstrcmp32A(lpProfile, DefaultDevMode))) {
190 if (!(RegOpenKey32A(HKEY_LOCAL_MACHINE, RegStr_Printer, &hkey)) ||
191 (RegSetValueEx32A(hkey, DefaultDevMode, 0, REG_BINARY, lpPrinterData, dwSize)))
192 res = ERROR_INVALID_PRINTER_NAME;
194 else
196 strcat(RegStr_Printer, "\\");
198 if (!(res = RegOpenKey32A(HKEY_LOCAL_MACHINE, RegStr_Printer, &hkey))) {
200 if (!lpPrinterData)
201 res = RegDeleteValue32A(hkey, lpProfile);
202 else
203 res = RegSetValueEx32A(hkey, lpProfile, 0, lpType, lpPrinterData, dwSize);
207 if (hkey) RegCloseKey(hkey);
208 HeapFree(GetProcessHeap(), 0, RegStr_Printer);
209 return res;
213 INT32 WINAPI DeviceCapabilities32A(LPCSTR printer,LPCSTR target,WORD z,
214 LPSTR a,LPDEVMODE32A b)
216 FIXME(print,"(%s,%s,%d,%p,%p):stub.\n",printer,target,z,a,b);
217 return 1;
220 LONG WINAPI DocumentProperties32A(HWND32 hWnd,HANDLE32 hPrinter,
221 LPSTR pDeviceName, LPDEVMODE32A pDevModeOutput,
222 LPDEVMODE32A pDevModeInput,DWORD fMode )
224 FIXME(print,"(%d,%d,%s,%p,%p,%ld):stub.\n",
225 hWnd,hPrinter,pDeviceName,pDevModeOutput,pDevModeInput,fMode
227 return 1;
230 BOOL32 WINAPI OpenPrinter32A(LPSTR lpPrinterName,HANDLE32 *phPrinter,
231 LPPRINTER_DEFAULTS32A pDefault)
233 FIXME(print,"(%s,%p,%p):stub.\n",
234 lpPrinterName, phPrinter, pDefault);
235 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
236 return FALSE;
238 BOOL32 WINAPI EnumPrinters32A(DWORD dwType, LPSTR lpszName,
239 DWORD dwLevel, LPBYTE lpbPrinters,
240 DWORD cbBuf, LPDWORD lpdwNeeded,
241 LPDWORD lpdwReturned)
243 FIXME(print,"Nearly empty stub\n");
244 *lpdwReturned=0;
245 return TRUE;
249 BOOL32 WINAPI AddMonitor32A(LPCSTR pName, DWORD Level, LPBYTE pMonitors)
251 FIXME(print, "(%s,%lx,%p):stub!\n", pName, Level, pMonitors);
252 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
253 return FALSE;
257 BOOL32 WINAPI
258 DeletePrinterDriver32A (LPSTR pName, LPSTR pEnvironment, LPSTR pDriverName)
260 FIXME(print, "(%s,%s,%s):stub!\n", pName, pEnvironment, pDriverName);
261 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
262 return FALSE;
266 BOOL32 WINAPI
267 DeleteMonitor32A (LPSTR pName, LPSTR pEnvironment, LPSTR pMonitorName)
269 FIXME(print, "(%s,%s,%s):stub!\n", pName, pEnvironment, pMonitorName);
270 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
271 return FALSE;
275 BOOL32 WINAPI
276 DeletePort32A (LPSTR pName, HWND32 hWnd, LPSTR pPortName)
278 FIXME(print, "(%s,0x%08x,%s):stub!\n", pName, hWnd, pPortName);
279 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
280 return FALSE;