Alexandre Julliard | 0e270f4 | 1996-08-24 18:26:35 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Implementation of some printer driver bits |
| 3 | * |
| 4 | * Copyright 1996 John Harvey |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 5 | * Copyright 1998 Huw Davies |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 6 | * Copyright 1998 Andreas Mohr |
Klaas van Gend | 7f73a08 | 1999-03-28 12:37:34 +0000 | [diff] [blame] | 7 | * Copyright 1999 Klaas van Gend |
Alexandre Julliard | 0e270f4 | 1996-08-24 18:26:35 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <stdlib.h> |
Alexandre Julliard | 0e270f4 | 1996-08-24 18:26:35 +0000 | [diff] [blame] | 11 | #include <string.h> |
| 12 | #include <ctype.h> |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 13 | #include <errno.h> |
| 14 | #include <unistd.h> |
| 15 | #include <fcntl.h> |
| 16 | #include "ldt.h" |
Huw D M Davies | a9f55c4 | 1999-05-08 12:45:18 +0000 | [diff] [blame] | 17 | #include "winbase.h" |
Alexandre Julliard | 83f52d1 | 2000-09-26 22:20:14 +0000 | [diff] [blame] | 18 | #include "wine/winbase16.h" |
Huw D M Davies | a9f55c4 | 1999-05-08 12:45:18 +0000 | [diff] [blame] | 19 | #include "wine/wingdi16.h" |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 20 | #include "winspool.h" |
Alexandre Julliard | 0e270f4 | 1996-08-24 18:26:35 +0000 | [diff] [blame] | 21 | #include "winerror.h" |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 22 | #include "winreg.h" |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 23 | #include "debugtools.h" |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 24 | #include "gdi.h" |
| 25 | #include "dc.h" |
| 26 | #include "callback.h" |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 27 | #include "options.h" |
Huw D M Davies | 8156150 | 1999-07-25 11:25:59 +0000 | [diff] [blame] | 28 | #include "heap.h" |
Frederic Boulanger | f93dcc2 | 2000-06-15 00:29:54 +0000 | [diff] [blame] | 29 | #include "file.h" |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 30 | |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 31 | DEFAULT_DEBUG_CHANNEL(print) |
Klaas van Gend | 7f73a08 | 1999-03-28 12:37:34 +0000 | [diff] [blame] | 32 | |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 33 | static char PrinterModel[] = "Printer Model"; |
| 34 | static char DefaultDevMode[] = "Default DevMode"; |
| 35 | static char PrinterDriverData[] = "PrinterDriverData"; |
| 36 | static char Printers[] = "System\\CurrentControlSet\\Control\\Print\\Printers\\"; |
| 37 | |
Huw D M Davies | 7d5fd8d | 1998-12-08 09:44:30 +0000 | [diff] [blame] | 38 | /****************************************************************** |
| 39 | * StartDoc16 [GDI.377] |
| 40 | * |
| 41 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 42 | INT16 WINAPI StartDoc16( HDC16 hdc, const DOCINFO16 *lpdoc ) |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 43 | { |
Huw D M Davies | 8156150 | 1999-07-25 11:25:59 +0000 | [diff] [blame] | 44 | DOCINFOA docA; |
| 45 | |
| 46 | docA.cbSize = lpdoc->cbSize; |
| 47 | docA.lpszDocName = PTR_SEG_TO_LIN(lpdoc->lpszDocName); |
| 48 | docA.lpszOutput = PTR_SEG_TO_LIN(lpdoc->lpszOutput); |
Huw D M Davies | c0da44e4 | 1999-10-31 01:49:30 +0000 | [diff] [blame] | 49 | |
| 50 | if(lpdoc->cbSize >= 14) |
| 51 | docA.lpszDatatype = PTR_SEG_TO_LIN(lpdoc->lpszDatatype); |
| 52 | else |
| 53 | docA.lpszDatatype = NULL; |
| 54 | |
| 55 | if(lpdoc->cbSize >= 18) |
| 56 | docA.fwType = lpdoc->fwType; |
| 57 | else |
| 58 | docA.fwType = 0; |
Huw D M Davies | 8156150 | 1999-07-25 11:25:59 +0000 | [diff] [blame] | 59 | |
| 60 | return StartDocA(hdc, &docA); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Huw D M Davies | 7d5fd8d | 1998-12-08 09:44:30 +0000 | [diff] [blame] | 63 | /****************************************************************** |
Huw D M Davies | 8156150 | 1999-07-25 11:25:59 +0000 | [diff] [blame] | 64 | * StartDocA [GDI32.347] |
Nick Holloway | 36a806c | 1999-01-24 18:59:58 +0000 | [diff] [blame] | 65 | * |
Huw D M Davies | c0da44e4 | 1999-10-31 01:49:30 +0000 | [diff] [blame] | 66 | * StartDoc calls the STARTDOC Escape with the input data pointing to DocName |
| 67 | * and the output data (which is used as a second input parameter).pointing at |
| 68 | * the whole docinfo structure. This seems to be an undocumented feature of |
| 69 | * the STARTDOC Escape. |
Nick Holloway | 36a806c | 1999-01-24 18:59:58 +0000 | [diff] [blame] | 70 | */ |
Huw D M Davies | 8156150 | 1999-07-25 11:25:59 +0000 | [diff] [blame] | 71 | INT WINAPI StartDocA(HDC hdc, const DOCINFOA* doc) |
Nick Holloway | 36a806c | 1999-01-24 18:59:58 +0000 | [diff] [blame] | 72 | { |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 73 | INT ret; |
Huw D M Davies | 8156150 | 1999-07-25 11:25:59 +0000 | [diff] [blame] | 74 | DC *dc = DC_GetDCPtr( hdc ); |
Nick Holloway | 36a806c | 1999-01-24 18:59:58 +0000 | [diff] [blame] | 75 | |
Huw D M Davies | d016b0a | 1999-07-24 12:09:34 +0000 | [diff] [blame] | 76 | TRACE("DocName = '%s' Output = '%s' Datatype = '%s'\n", |
| 77 | doc->lpszDocName, doc->lpszOutput, doc->lpszDatatype); |
Huw D M Davies | 8156150 | 1999-07-25 11:25:59 +0000 | [diff] [blame] | 78 | |
Patrik Stridvall | cbab770 | 2000-05-18 00:52:08 +0000 | [diff] [blame] | 79 | if(!dc) return SP_ERROR; |
Huw D M Davies | 8156150 | 1999-07-25 11:25:59 +0000 | [diff] [blame] | 80 | |
| 81 | if(dc->funcs->pStartDoc) |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 82 | ret = dc->funcs->pStartDoc( dc, doc ); |
Huw D M Davies | 8156150 | 1999-07-25 11:25:59 +0000 | [diff] [blame] | 83 | else |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 84 | ret = Escape(hdc, STARTDOC, strlen(doc->lpszDocName), |
Huw D M Davies | c0da44e4 | 1999-10-31 01:49:30 +0000 | [diff] [blame] | 85 | doc->lpszDocName, (LPVOID)doc); |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 86 | GDI_ReleaseObj( hdc ); |
| 87 | return ret; |
Huw D M Davies | 7d5fd8d | 1998-12-08 09:44:30 +0000 | [diff] [blame] | 88 | } |
| 89 | |
Huw D M Davies | 5a50273 | 1998-12-11 10:17:31 +0000 | [diff] [blame] | 90 | /************************************************************************* |
Huw D M Davies | 8156150 | 1999-07-25 11:25:59 +0000 | [diff] [blame] | 91 | * StartDocW [GDI32.348] |
Huw D M Davies | 5a50273 | 1998-12-11 10:17:31 +0000 | [diff] [blame] | 92 | * |
| 93 | */ |
Huw D M Davies | 8156150 | 1999-07-25 11:25:59 +0000 | [diff] [blame] | 94 | INT WINAPI StartDocW(HDC hdc, const DOCINFOW* doc) |
Huw D M Davies | 7d5fd8d | 1998-12-08 09:44:30 +0000 | [diff] [blame] | 95 | { |
Huw D M Davies | 8156150 | 1999-07-25 11:25:59 +0000 | [diff] [blame] | 96 | DOCINFOA docA; |
| 97 | INT ret; |
Huw D M Davies | 7d5fd8d | 1998-12-08 09:44:30 +0000 | [diff] [blame] | 98 | |
Huw D M Davies | 8156150 | 1999-07-25 11:25:59 +0000 | [diff] [blame] | 99 | docA.cbSize = doc->cbSize; |
| 100 | docA.lpszDocName = doc->lpszDocName ? |
| 101 | HEAP_strdupWtoA( GetProcessHeap(), 0, doc->lpszDocName ) : NULL; |
| 102 | docA.lpszOutput = doc->lpszOutput ? |
| 103 | HEAP_strdupWtoA( GetProcessHeap(), 0, doc->lpszOutput ) : NULL; |
| 104 | docA.lpszDatatype = doc->lpszDatatype ? |
| 105 | HEAP_strdupWtoA( GetProcessHeap(), 0, doc->lpszDatatype ) : NULL; |
| 106 | docA.fwType = doc->fwType; |
| 107 | |
| 108 | ret = StartDocA(hdc, &docA); |
| 109 | |
| 110 | if(docA.lpszDocName) |
| 111 | HeapFree( GetProcessHeap(), 0, (LPSTR)docA.lpszDocName ); |
| 112 | if(docA.lpszOutput) |
| 113 | HeapFree( GetProcessHeap(), 0, (LPSTR)docA.lpszOutput ); |
| 114 | if(docA.lpszDatatype) |
| 115 | HeapFree( GetProcessHeap(), 0, (LPSTR)docA.lpszDatatype ); |
| 116 | |
| 117 | return ret; |
Huw D M Davies | 7d5fd8d | 1998-12-08 09:44:30 +0000 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | /****************************************************************** |
| 121 | * EndDoc16 [GDI.378] |
| 122 | * |
| 123 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 124 | INT16 WINAPI EndDoc16(HDC16 hdc) |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 125 | { |
Huw D M Davies | 8156150 | 1999-07-25 11:25:59 +0000 | [diff] [blame] | 126 | return EndDoc(hdc); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 127 | } |
| 128 | |
Huw D M Davies | 7d5fd8d | 1998-12-08 09:44:30 +0000 | [diff] [blame] | 129 | /****************************************************************** |
Huw D M Davies | 8156150 | 1999-07-25 11:25:59 +0000 | [diff] [blame] | 130 | * EndDoc [GDI32.76] |
Huw D M Davies | 7d5fd8d | 1998-12-08 09:44:30 +0000 | [diff] [blame] | 131 | * |
| 132 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 133 | INT WINAPI EndDoc(HDC hdc) |
Huw D M Davies | 7d5fd8d | 1998-12-08 09:44:30 +0000 | [diff] [blame] | 134 | { |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 135 | INT ret; |
Huw D M Davies | 8156150 | 1999-07-25 11:25:59 +0000 | [diff] [blame] | 136 | DC *dc = DC_GetDCPtr( hdc ); |
Patrik Stridvall | cbab770 | 2000-05-18 00:52:08 +0000 | [diff] [blame] | 137 | if(!dc) return SP_ERROR; |
Huw D M Davies | 8156150 | 1999-07-25 11:25:59 +0000 | [diff] [blame] | 138 | |
| 139 | if(dc->funcs->pEndDoc) |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 140 | ret = dc->funcs->pEndDoc( dc ); |
Huw D M Davies | 8156150 | 1999-07-25 11:25:59 +0000 | [diff] [blame] | 141 | else |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 142 | ret = Escape(hdc, ENDDOC, 0, 0, 0); |
| 143 | GDI_ReleaseObj( hdc ); |
| 144 | return ret; |
Huw D M Davies | 8156150 | 1999-07-25 11:25:59 +0000 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | /****************************************************************** |
| 148 | * StartPage16 [GDI.379] |
| 149 | * |
| 150 | */ |
| 151 | INT16 WINAPI StartPage16(HDC16 hdc) |
| 152 | { |
| 153 | return StartPage(hdc); |
| 154 | } |
| 155 | |
| 156 | /****************************************************************** |
| 157 | * StartPage [GDI32.349] |
| 158 | * |
| 159 | */ |
| 160 | INT WINAPI StartPage(HDC hdc) |
| 161 | { |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 162 | INT ret = 1; |
Huw D M Davies | 8156150 | 1999-07-25 11:25:59 +0000 | [diff] [blame] | 163 | DC *dc = DC_GetDCPtr( hdc ); |
Patrik Stridvall | cbab770 | 2000-05-18 00:52:08 +0000 | [diff] [blame] | 164 | if(!dc) return SP_ERROR; |
Huw D M Davies | 8156150 | 1999-07-25 11:25:59 +0000 | [diff] [blame] | 165 | |
| 166 | if(dc->funcs->pStartPage) |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 167 | ret = dc->funcs->pStartPage( dc ); |
| 168 | else |
| 169 | FIXME("stub\n"); |
| 170 | GDI_ReleaseObj( hdc ); |
| 171 | return ret; |
Huw D M Davies | 8156150 | 1999-07-25 11:25:59 +0000 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | /****************************************************************** |
| 175 | * EndPage16 [GDI.380] |
| 176 | * |
| 177 | */ |
| 178 | INT16 WINAPI EndPage16( HDC16 hdc ) |
| 179 | { |
| 180 | return EndPage(hdc); |
| 181 | } |
| 182 | |
| 183 | /****************************************************************** |
| 184 | * EndPage [GDI32.77] |
| 185 | * |
| 186 | */ |
| 187 | INT WINAPI EndPage(HDC hdc) |
| 188 | { |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 189 | INT ret; |
Huw D M Davies | 8156150 | 1999-07-25 11:25:59 +0000 | [diff] [blame] | 190 | DC *dc = DC_GetDCPtr( hdc ); |
Patrik Stridvall | cbab770 | 2000-05-18 00:52:08 +0000 | [diff] [blame] | 191 | if(!dc) return SP_ERROR; |
Huw D M Davies | 8156150 | 1999-07-25 11:25:59 +0000 | [diff] [blame] | 192 | |
| 193 | if(dc->funcs->pEndPage) |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 194 | ret = dc->funcs->pEndPage( dc ); |
Huw D M Davies | 8156150 | 1999-07-25 11:25:59 +0000 | [diff] [blame] | 195 | else |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 196 | ret = Escape(hdc, NEWFRAME, 0, 0, 0); |
| 197 | GDI_ReleaseObj( hdc ); |
| 198 | return ret; |
Huw D M Davies | 7d5fd8d | 1998-12-08 09:44:30 +0000 | [diff] [blame] | 199 | } |
| 200 | |
Huw D M Davies | 5a50273 | 1998-12-11 10:17:31 +0000 | [diff] [blame] | 201 | /****************************************************************************** |
| 202 | * AbortDoc16 [GDI.382] |
| 203 | */ |
| 204 | INT16 WINAPI AbortDoc16(HDC16 hdc) |
| 205 | { |
Huw D M Davies | 8156150 | 1999-07-25 11:25:59 +0000 | [diff] [blame] | 206 | return AbortDoc(hdc); |
Huw D M Davies | 5a50273 | 1998-12-11 10:17:31 +0000 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | /****************************************************************************** |
Huw D M Davies | 8156150 | 1999-07-25 11:25:59 +0000 | [diff] [blame] | 210 | * AbortDoc [GDI32.105] |
Huw D M Davies | 5a50273 | 1998-12-11 10:17:31 +0000 | [diff] [blame] | 211 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 212 | INT WINAPI AbortDoc(HDC hdc) |
Huw D M Davies | 5a50273 | 1998-12-11 10:17:31 +0000 | [diff] [blame] | 213 | { |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 214 | INT ret; |
Huw D M Davies | 8156150 | 1999-07-25 11:25:59 +0000 | [diff] [blame] | 215 | DC *dc = DC_GetDCPtr( hdc ); |
Patrik Stridvall | cbab770 | 2000-05-18 00:52:08 +0000 | [diff] [blame] | 216 | if(!dc) return SP_ERROR; |
Huw D M Davies | 8156150 | 1999-07-25 11:25:59 +0000 | [diff] [blame] | 217 | |
| 218 | if(dc->funcs->pAbortDoc) |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 219 | ret = dc->funcs->pAbortDoc( dc ); |
Huw D M Davies | 8156150 | 1999-07-25 11:25:59 +0000 | [diff] [blame] | 220 | else |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 221 | ret = Escape(hdc, ABORTDOC, 0, 0, 0); |
| 222 | GDI_ReleaseObj( hdc ); |
| 223 | return ret; |
Huw D M Davies | 5a50273 | 1998-12-11 10:17:31 +0000 | [diff] [blame] | 224 | } |
| 225 | |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 226 | /********************************************************************** |
Huw D M Davies | 8156150 | 1999-07-25 11:25:59 +0000 | [diff] [blame] | 227 | * QueryAbort16 (GDI.155) |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 228 | * |
| 229 | * Calls the app's AbortProc function if avail. |
| 230 | * |
| 231 | * RETURNS |
| 232 | * TRUE if no AbortProc avail or AbortProc wants to continue printing. |
| 233 | * FALSE if AbortProc wants to abort printing. |
| 234 | */ |
| 235 | BOOL16 WINAPI QueryAbort16(HDC16 hdc, INT16 reserved) |
| 236 | { |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 237 | BOOL ret = TRUE; |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 238 | DC *dc = DC_GetDCPtr( hdc ); |
| 239 | |
Huw D M Davies | d016b0a | 1999-07-24 12:09:34 +0000 | [diff] [blame] | 240 | if(!dc) { |
| 241 | ERR("Invalid hdc %04x\n", hdc); |
| 242 | return FALSE; |
| 243 | } |
| 244 | |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 245 | if (dc->w.pAbortProc) ret = dc->w.pAbortProc(hdc, 0); |
| 246 | GDI_ReleaseObj( hdc ); |
| 247 | return ret; |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 248 | } |
| 249 | |
Huw D M Davies | 304d9a4 | 1999-09-13 15:15:45 +0000 | [diff] [blame] | 250 | /* ### start build ### */ |
| 251 | extern WORD CALLBACK PRTDRV_CallTo16_word_ww(FARPROC16,WORD,WORD); |
| 252 | /* ### stop build ### */ |
| 253 | |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 254 | /********************************************************************** |
| 255 | * SetAbortProc16 (GDI.381) |
| 256 | * |
| 257 | */ |
| 258 | INT16 WINAPI SetAbortProc16(HDC16 hdc, SEGPTR abrtprc) |
| 259 | { |
Huw D M Davies | 304d9a4 | 1999-09-13 15:15:45 +0000 | [diff] [blame] | 260 | ABORTPROC proc32 = (ABORTPROC)THUNK_Alloc((FARPROC16)abrtprc, |
| 261 | (RELAY)PRTDRV_CallTo16_word_ww); |
| 262 | return SetAbortProc(hdc, proc32); |
Huw D M Davies | d016b0a | 1999-07-24 12:09:34 +0000 | [diff] [blame] | 263 | } |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 264 | |
| 265 | /********************************************************************** |
Patrik Stridvall | 39fc90a | 2000-03-28 19:30:06 +0000 | [diff] [blame] | 266 | * SetAbortProc (GDI32.301) |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 267 | * |
| 268 | */ |
| 269 | INT WINAPI SetAbortProc(HDC hdc, ABORTPROC abrtprc) |
| 270 | { |
Huw D M Davies | d016b0a | 1999-07-24 12:09:34 +0000 | [diff] [blame] | 271 | DC *dc = DC_GetDCPtr( hdc ); |
| 272 | |
Huw D M Davies | 304d9a4 | 1999-09-13 15:15:45 +0000 | [diff] [blame] | 273 | if(dc->w.pAbortProc) THUNK_Free((FARPROC)dc->w.pAbortProc); |
| 274 | dc->w.pAbortProc = abrtprc; |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 275 | GDI_ReleaseObj( hdc ); |
Huw D M Davies | d016b0a | 1999-07-24 12:09:34 +0000 | [diff] [blame] | 276 | return TRUE; |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | |
| 280 | /****************** misc. printer related functions */ |
| 281 | |
| 282 | /* |
| 283 | * The following function should implement a queing system |
| 284 | */ |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 285 | struct hpq |
| 286 | { |
| 287 | struct hpq *next; |
| 288 | int tag; |
| 289 | int key; |
| 290 | }; |
| 291 | |
| 292 | static struct hpq *hpqueue; |
| 293 | |
| 294 | /********************************************************************** |
| 295 | * CreatePQ (GDI.230) |
| 296 | * |
| 297 | */ |
Patrik Stridvall | 8276f69 | 1999-09-23 11:48:02 +0000 | [diff] [blame] | 298 | HPQ16 WINAPI CreatePQ16(INT16 size) |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 299 | { |
| 300 | #if 0 |
| 301 | HGLOBAL16 hpq = 0; |
| 302 | WORD tmp_size; |
| 303 | LPWORD pPQ; |
| 304 | |
| 305 | tmp_size = size << 2; |
| 306 | if (!(hpq = GlobalAlloc16(GMEM_SHARE|GMEM_MOVEABLE, tmp_size + 8))) |
| 307 | return 0xffff; |
| 308 | pPQ = GlobalLock16(hpq); |
| 309 | *pPQ++ = 0; |
| 310 | *pPQ++ = tmp_size; |
| 311 | *pPQ++ = 0; |
| 312 | *pPQ++ = 0; |
| 313 | GlobalUnlock16(hpq); |
| 314 | |
Patrik Stridvall | 8276f69 | 1999-09-23 11:48:02 +0000 | [diff] [blame] | 315 | return (HPQ16)hpq; |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 316 | #else |
| 317 | FIXME("(%d): stub\n",size); |
| 318 | return 1; |
| 319 | #endif |
| 320 | } |
| 321 | |
| 322 | /********************************************************************** |
| 323 | * DeletePQ (GDI.235) |
| 324 | * |
| 325 | */ |
Patrik Stridvall | 8276f69 | 1999-09-23 11:48:02 +0000 | [diff] [blame] | 326 | INT16 WINAPI DeletePQ16(HPQ16 hPQ) |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 327 | { |
| 328 | return GlobalFree16((HGLOBAL16)hPQ); |
| 329 | } |
| 330 | |
| 331 | /********************************************************************** |
| 332 | * ExtractPQ (GDI.232) |
| 333 | * |
| 334 | */ |
Patrik Stridvall | 8276f69 | 1999-09-23 11:48:02 +0000 | [diff] [blame] | 335 | INT16 WINAPI ExtractPQ16(HPQ16 hPQ) |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 336 | { |
| 337 | struct hpq *queue, *prev, *current, *currentPrev; |
| 338 | int key = 0, tag = -1; |
| 339 | currentPrev = prev = NULL; |
| 340 | queue = current = hpqueue; |
| 341 | if (current) |
| 342 | key = current->key; |
| 343 | |
| 344 | while (current) |
| 345 | { |
| 346 | currentPrev = current; |
| 347 | current = current->next; |
| 348 | if (current) |
| 349 | { |
| 350 | if (current->key < key) |
| 351 | { |
| 352 | queue = current; |
| 353 | prev = currentPrev; |
| 354 | } |
| 355 | } |
| 356 | } |
| 357 | if (queue) |
| 358 | { |
| 359 | tag = queue->tag; |
| 360 | |
| 361 | if (prev) |
| 362 | prev->next = queue->next; |
| 363 | else |
| 364 | hpqueue = queue->next; |
Dimitrie O. Paun | 9ad9636 | 2000-03-19 14:29:50 +0000 | [diff] [blame] | 365 | HeapFree(GetProcessHeap(), 0, queue); |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | TRACE("%x got tag %d key %d\n", hPQ, tag, key); |
| 369 | |
| 370 | return tag; |
| 371 | } |
| 372 | |
| 373 | /********************************************************************** |
| 374 | * InsertPQ (GDI.233) |
| 375 | * |
| 376 | */ |
Patrik Stridvall | 8276f69 | 1999-09-23 11:48:02 +0000 | [diff] [blame] | 377 | INT16 WINAPI InsertPQ16(HPQ16 hPQ, INT16 tag, INT16 key) |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 378 | { |
Dimitrie O. Paun | 9ad9636 | 2000-03-19 14:29:50 +0000 | [diff] [blame] | 379 | struct hpq *queueItem = HeapAlloc(GetProcessHeap(), 0, sizeof(struct hpq)); |
| 380 | if(queueItem == NULL) { |
| 381 | ERR("Memory exausted!"); |
| 382 | return FALSE; |
| 383 | } |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 384 | queueItem->next = hpqueue; |
| 385 | hpqueue = queueItem; |
| 386 | queueItem->key = key; |
| 387 | queueItem->tag = tag; |
| 388 | |
| 389 | FIXME("(%x %d %d): stub???\n", hPQ, tag, key); |
| 390 | return TRUE; |
| 391 | } |
| 392 | |
| 393 | /********************************************************************** |
| 394 | * MinPQ (GDI.231) |
| 395 | * |
| 396 | */ |
Patrik Stridvall | 8276f69 | 1999-09-23 11:48:02 +0000 | [diff] [blame] | 397 | INT16 WINAPI MinPQ16(HPQ16 hPQ) |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 398 | { |
| 399 | FIXME("(%x): stub\n", hPQ); |
| 400 | return 0; |
| 401 | } |
| 402 | |
| 403 | /********************************************************************** |
| 404 | * SizePQ (GDI.234) |
| 405 | * |
| 406 | */ |
Patrik Stridvall | 8276f69 | 1999-09-23 11:48:02 +0000 | [diff] [blame] | 407 | INT16 WINAPI SizePQ16(HPQ16 hPQ, INT16 sizechange) |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 408 | { |
| 409 | FIXME("(%x %d): stub\n", hPQ, sizechange); |
| 410 | return -1; |
| 411 | } |
| 412 | |
| 413 | |
| 414 | |
| 415 | /* |
| 416 | * The following functions implement part of the spooling process to |
| 417 | * print manager. I would like to see wine have a version of print managers |
| 418 | * that used LPR/LPD. For simplicity print jobs will be sent to a file for |
| 419 | * now. |
| 420 | */ |
| 421 | typedef struct PRINTJOB |
| 422 | { |
| 423 | char *pszOutput; |
| 424 | char *pszTitle; |
| 425 | HDC16 hDC; |
| 426 | HANDLE16 hHandle; |
| 427 | int nIndex; |
| 428 | int fd; |
| 429 | } PRINTJOB, *PPRINTJOB; |
| 430 | |
| 431 | #define MAX_PRINT_JOBS 1 |
| 432 | #define SP_OK 1 |
| 433 | |
| 434 | PPRINTJOB gPrintJobsTable[MAX_PRINT_JOBS]; |
| 435 | |
| 436 | |
| 437 | static PPRINTJOB FindPrintJobFromHandle(HANDLE16 hHandle) |
| 438 | { |
| 439 | return gPrintJobsTable[0]; |
| 440 | } |
| 441 | |
Huw D M Davies | 8156150 | 1999-07-25 11:25:59 +0000 | [diff] [blame] | 442 | static int CreateSpoolFile(LPCSTR pszOutput) |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 443 | { |
| 444 | int fd=-1; |
| 445 | char psCmd[1024]; |
| 446 | char *psCmdP = psCmd; |
| 447 | |
| 448 | /* TTD convert the 'output device' into a spool file name */ |
| 449 | |
| 450 | if (pszOutput == NULL || *pszOutput == '\0') |
| 451 | return -1; |
| 452 | |
| 453 | PROFILE_GetWineIniString( "spooler", pszOutput, "", psCmd, sizeof(psCmd) ); |
| 454 | TRACE("Got printerSpoolCommand '%s' for output device '%s'\n", |
| 455 | psCmd, pszOutput); |
| 456 | if (!*psCmd) |
Huw D M Davies | 8156150 | 1999-07-25 11:25:59 +0000 | [diff] [blame] | 457 | psCmdP = (char *)pszOutput; |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 458 | else |
| 459 | { |
| 460 | while (*psCmdP && isspace(*psCmdP)) |
| 461 | { |
| 462 | psCmdP++; |
| 463 | }; |
| 464 | if (!*psCmdP) |
| 465 | return -1; |
| 466 | } |
| 467 | if (*psCmdP == '|') |
| 468 | { |
| 469 | int fds[2]; |
| 470 | if (pipe(fds)) |
| 471 | return -1; |
| 472 | if (fork() == 0) |
| 473 | { |
| 474 | psCmdP++; |
| 475 | |
| 476 | TRACE("In child need to exec %s\n",psCmdP); |
| 477 | close(0); |
| 478 | dup2(fds[0],0); |
| 479 | close (fds[1]); |
| 480 | system(psCmdP); |
| 481 | exit(0); |
| 482 | |
| 483 | } |
| 484 | close (fds[0]); |
| 485 | fd = fds[1]; |
| 486 | TRACE("Need to execute a cmnd and pipe the output to it\n"); |
| 487 | } |
| 488 | else |
| 489 | { |
Frederic Boulanger | f93dcc2 | 2000-06-15 00:29:54 +0000 | [diff] [blame] | 490 | DOS_FULL_NAME fullName; |
| 491 | |
Andreas Mohr | 3496556 | 2000-08-26 20:31:48 +0000 | [diff] [blame] | 492 | TRACE("Just assume it's a file\n"); |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 493 | |
Frederic Boulanger | f93dcc2 | 2000-06-15 00:29:54 +0000 | [diff] [blame] | 494 | /** |
| 495 | * The file name can be dos based, we have to find its |
| 496 | * Unix correspondant file name |
| 497 | */ |
| 498 | DOSFS_GetFullName(psCmdP, FALSE, &fullName); |
| 499 | |
| 500 | if ((fd = open(fullName.long_name, O_CREAT | O_TRUNC | O_WRONLY , 0600)) < 0) |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 501 | { |
Andreas Mohr | 3496556 | 2000-08-26 20:31:48 +0000 | [diff] [blame] | 502 | ERR("Failed to create spool file %s (%s)\n", |
| 503 | fullName.long_name, strerror(errno)); |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 504 | } |
| 505 | } |
| 506 | return fd; |
| 507 | } |
| 508 | |
| 509 | static int FreePrintJob(HANDLE16 hJob) |
| 510 | { |
| 511 | int nRet = SP_ERROR; |
| 512 | PPRINTJOB pPrintJob; |
| 513 | |
| 514 | pPrintJob = FindPrintJobFromHandle(hJob); |
| 515 | if (pPrintJob != NULL) |
| 516 | { |
| 517 | gPrintJobsTable[pPrintJob->nIndex] = NULL; |
Dimitrie O. Paun | 9ad9636 | 2000-03-19 14:29:50 +0000 | [diff] [blame] | 518 | HeapFree(GetProcessHeap(), 0, pPrintJob->pszOutput); |
| 519 | HeapFree(GetProcessHeap(), 0, pPrintJob->pszTitle); |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 520 | if (pPrintJob->fd >= 0) close(pPrintJob->fd); |
Dimitrie O. Paun | 9ad9636 | 2000-03-19 14:29:50 +0000 | [diff] [blame] | 521 | HeapFree(GetProcessHeap(), 0, pPrintJob); |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 522 | nRet = SP_OK; |
| 523 | } |
| 524 | return nRet; |
| 525 | } |
| 526 | |
| 527 | /********************************************************************** |
| 528 | * OpenJob (GDI.240) |
| 529 | * |
| 530 | */ |
Patrik Stridvall | 8276f69 | 1999-09-23 11:48:02 +0000 | [diff] [blame] | 531 | HPJOB16 WINAPI OpenJob16(LPCSTR lpOutput, LPCSTR lpTitle, HDC16 hDC) |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 532 | { |
Patrik Stridvall | 8276f69 | 1999-09-23 11:48:02 +0000 | [diff] [blame] | 533 | HPJOB16 hHandle = (HPJOB16)SP_ERROR; |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 534 | PPRINTJOB pPrintJob; |
| 535 | |
| 536 | TRACE("'%s' '%s' %04x\n", lpOutput, lpTitle, hDC); |
| 537 | |
| 538 | pPrintJob = gPrintJobsTable[0]; |
| 539 | if (pPrintJob == NULL) |
| 540 | { |
| 541 | int fd; |
| 542 | |
| 543 | /* Try an create a spool file */ |
| 544 | fd = CreateSpoolFile(lpOutput); |
| 545 | if (fd >= 0) |
| 546 | { |
Dimitrie O. Paun | 9ad9636 | 2000-03-19 14:29:50 +0000 | [diff] [blame] | 547 | pPrintJob = HeapAlloc(GetProcessHeap(), 0, sizeof(PRINTJOB)); |
| 548 | if(pPrintJob == NULL) { |
| 549 | WARN("Memory exausted!"); |
| 550 | return hHandle; |
| 551 | } |
| 552 | |
| 553 | hHandle = 1; |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 554 | |
Dimitrie O. Paun | 9ad9636 | 2000-03-19 14:29:50 +0000 | [diff] [blame] | 555 | pPrintJob->pszOutput = HEAP_strdupA(GetProcessHeap(), 0, lpOutput); |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 556 | if(lpTitle) |
Dimitrie O. Paun | 9ad9636 | 2000-03-19 14:29:50 +0000 | [diff] [blame] | 557 | pPrintJob->pszTitle = HEAP_strdupA(GetProcessHeap(), 0, lpTitle); |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 558 | pPrintJob->hDC = hDC; |
| 559 | pPrintJob->fd = fd; |
| 560 | pPrintJob->nIndex = 0; |
| 561 | pPrintJob->hHandle = hHandle; |
| 562 | gPrintJobsTable[pPrintJob->nIndex] = pPrintJob; |
| 563 | } |
| 564 | } |
| 565 | TRACE("return %04x\n", hHandle); |
| 566 | return hHandle; |
| 567 | } |
| 568 | |
| 569 | /********************************************************************** |
| 570 | * CloseJob (GDI.243) |
| 571 | * |
| 572 | */ |
Patrik Stridvall | 8276f69 | 1999-09-23 11:48:02 +0000 | [diff] [blame] | 573 | INT16 WINAPI CloseJob16(HPJOB16 hJob) |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 574 | { |
| 575 | int nRet = SP_ERROR; |
| 576 | PPRINTJOB pPrintJob = NULL; |
| 577 | |
| 578 | TRACE("%04x\n", hJob); |
| 579 | |
| 580 | pPrintJob = FindPrintJobFromHandle(hJob); |
| 581 | if (pPrintJob != NULL) |
| 582 | { |
| 583 | /* Close the spool file */ |
| 584 | close(pPrintJob->fd); |
| 585 | FreePrintJob(hJob); |
| 586 | nRet = 1; |
| 587 | } |
| 588 | return nRet; |
| 589 | } |
| 590 | |
| 591 | /********************************************************************** |
| 592 | * WriteSpool (GDI.241) |
| 593 | * |
| 594 | */ |
Patrik Stridvall | 8276f69 | 1999-09-23 11:48:02 +0000 | [diff] [blame] | 595 | INT16 WINAPI WriteSpool16(HPJOB16 hJob, LPSTR lpData, INT16 cch) |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 596 | { |
| 597 | int nRet = SP_ERROR; |
| 598 | PPRINTJOB pPrintJob = NULL; |
| 599 | |
| 600 | TRACE("%04x %08lx %04x\n", hJob, (DWORD)lpData, cch); |
| 601 | |
| 602 | pPrintJob = FindPrintJobFromHandle(hJob); |
| 603 | if (pPrintJob != NULL && pPrintJob->fd >= 0 && cch) |
| 604 | { |
| 605 | if (write(pPrintJob->fd, lpData, cch) != cch) |
| 606 | nRet = SP_OUTOFDISK; |
| 607 | else |
| 608 | nRet = cch; |
| 609 | if (pPrintJob->hDC == 0) { |
| 610 | TRACE("hDC == 0 so no QueryAbort\n"); |
| 611 | } |
| 612 | else if (!(QueryAbort16(pPrintJob->hDC, (nRet == SP_OUTOFDISK) ? nRet : 0 ))) |
| 613 | { |
| 614 | CloseJob16(hJob); /* printing aborted */ |
| 615 | nRet = SP_APPABORT; |
| 616 | } |
| 617 | } |
| 618 | return nRet; |
| 619 | } |
| 620 | |
| 621 | /********************************************************************** |
| 622 | * WriteDialog (GDI.242) |
| 623 | * |
| 624 | */ |
Patrik Stridvall | 8276f69 | 1999-09-23 11:48:02 +0000 | [diff] [blame] | 625 | INT16 WINAPI WriteDialog16(HPJOB16 hJob, LPSTR lpMsg, INT16 cchMsg) |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 626 | { |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 627 | TRACE("%04x %04x '%s'\n", hJob, cchMsg, lpMsg); |
| 628 | |
Alexandre Julliard | 6ec108a | 2000-03-24 21:42:15 +0000 | [diff] [blame] | 629 | return Callout.MessageBoxA(0, lpMsg, "Printing Error", MB_OKCANCEL); |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | |
| 633 | /********************************************************************** |
| 634 | * DeleteJob (GDI.244) |
| 635 | * |
| 636 | */ |
Patrik Stridvall | 8276f69 | 1999-09-23 11:48:02 +0000 | [diff] [blame] | 637 | INT16 WINAPI DeleteJob16(HPJOB16 hJob, INT16 nNotUsed) |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 638 | { |
| 639 | int nRet; |
| 640 | |
| 641 | TRACE("%04x\n", hJob); |
| 642 | |
| 643 | nRet = FreePrintJob(hJob); |
| 644 | return nRet; |
| 645 | } |
| 646 | |
| 647 | /* |
| 648 | * The following two function would allow a page to be sent to the printer |
| 649 | * when it has been processed. For simplicity they havn't been implemented. |
| 650 | * This means a whole job has to be processed before it is sent to the printer. |
| 651 | */ |
| 652 | |
| 653 | /********************************************************************** |
| 654 | * StartSpoolPage (GDI.246) |
| 655 | * |
| 656 | */ |
Patrik Stridvall | 8276f69 | 1999-09-23 11:48:02 +0000 | [diff] [blame] | 657 | INT16 WINAPI StartSpoolPage16(HPJOB16 hJob) |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 658 | { |
| 659 | FIXME("StartSpoolPage GDI.246 unimplemented\n"); |
| 660 | return 1; |
| 661 | |
| 662 | } |
| 663 | |
| 664 | |
| 665 | /********************************************************************** |
| 666 | * EndSpoolPage (GDI.247) |
| 667 | * |
| 668 | */ |
Patrik Stridvall | 8276f69 | 1999-09-23 11:48:02 +0000 | [diff] [blame] | 669 | INT16 WINAPI EndSpoolPage16(HPJOB16 hJob) |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 670 | { |
| 671 | FIXME("EndSpoolPage GDI.247 unimplemented\n"); |
| 672 | return 1; |
| 673 | } |
| 674 | |
| 675 | |
| 676 | /********************************************************************** |
| 677 | * GetSpoolJob (GDI.245) |
| 678 | * |
| 679 | */ |
| 680 | DWORD WINAPI GetSpoolJob16(int nOption, LONG param) |
| 681 | { |
| 682 | DWORD retval = 0; |
| 683 | TRACE("In GetSpoolJob param 0x%lx noption %d\n",param, nOption); |
| 684 | return retval; |
| 685 | } |
| 686 | |
| 687 | |
Huw D M Davies | 7d5fd8d | 1998-12-08 09:44:30 +0000 | [diff] [blame] | 688 | /****************************************************************** |
| 689 | * DrvGetPrinterDataInternal |
| 690 | * |
| 691 | * Helper for DrvGetPrinterData |
| 692 | */ |
| 693 | static DWORD DrvGetPrinterDataInternal(LPSTR RegStr_Printer, |
Huw D M Davies | d92c95d | 1999-01-26 10:07:39 +0000 | [diff] [blame] | 694 | LPBYTE lpPrinterData, int cbData, int what) |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 695 | { |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 696 | DWORD res = -1; |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 697 | HKEY hkey; |
| 698 | DWORD dwType, cbQueryData; |
| 699 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 700 | if (!(RegOpenKeyA(HKEY_LOCAL_MACHINE, RegStr_Printer, &hkey))) { |
Huw D M Davies | d92c95d | 1999-01-26 10:07:39 +0000 | [diff] [blame] | 701 | if (what == INT_PD_DEFAULT_DEVMODE) { /* "Default DevMode" */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 702 | if (!(RegQueryValueExA(hkey, DefaultDevMode, 0, &dwType, 0, &cbQueryData))) { |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 703 | if (!lpPrinterData) |
| 704 | res = cbQueryData; |
| 705 | else if ((cbQueryData) && (cbQueryData <= cbData)) { |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 706 | cbQueryData = cbData; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 707 | if (RegQueryValueExA(hkey, DefaultDevMode, 0, |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 708 | &dwType, lpPrinterData, &cbQueryData)) |
| 709 | res = cbQueryData; |
| 710 | } |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 711 | } |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 712 | } else { /* "Printer Driver" */ |
| 713 | cbQueryData = 32; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 714 | RegQueryValueExA(hkey, "Printer Driver", 0, |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 715 | &dwType, lpPrinterData, &cbQueryData); |
| 716 | res = cbQueryData; |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 717 | } |
| 718 | } |
| 719 | if (hkey) RegCloseKey(hkey); |
| 720 | return res; |
| 721 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 722 | |
Huw D M Davies | 7d5fd8d | 1998-12-08 09:44:30 +0000 | [diff] [blame] | 723 | /****************************************************************** |
| 724 | * DrvGetPrinterData [GDI.282] |
| 725 | * |
| 726 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 727 | DWORD WINAPI DrvGetPrinterData16(LPSTR lpPrinter, LPSTR lpProfile, |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 728 | LPDWORD lpType, LPBYTE lpPrinterData, |
| 729 | int cbData, LPDWORD lpNeeded) |
Alexandre Julliard | 0e270f4 | 1996-08-24 18:26:35 +0000 | [diff] [blame] | 730 | { |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 731 | LPSTR RegStr_Printer; |
| 732 | HKEY hkey = 0, hkey2 = 0; |
| 733 | DWORD res = 0; |
| 734 | DWORD dwType, PrinterAttr, cbPrinterAttr, SetData, size; |
| 735 | |
Alexandre Julliard | 33072e1 | 1997-06-29 18:08:02 +0000 | [diff] [blame] | 736 | if (HIWORD(lpPrinter)) |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 737 | TRACE("printer %s\n",lpPrinter); |
Alexandre Julliard | 33072e1 | 1997-06-29 18:08:02 +0000 | [diff] [blame] | 738 | else |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 739 | TRACE("printer %p\n",lpPrinter); |
Alexandre Julliard | 33072e1 | 1997-06-29 18:08:02 +0000 | [diff] [blame] | 740 | if (HIWORD(lpProfile)) |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 741 | TRACE("profile %s\n",lpProfile); |
Alexandre Julliard | 33072e1 | 1997-06-29 18:08:02 +0000 | [diff] [blame] | 742 | else |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 743 | TRACE("profile %p\n",lpProfile); |
| 744 | TRACE("lpType %p\n",lpType); |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 745 | |
| 746 | if ((!lpPrinter) || (!lpProfile) || (!lpNeeded)) |
| 747 | return ERROR_INVALID_PARAMETER; |
| 748 | |
| 749 | RegStr_Printer = HeapAlloc(GetProcessHeap(), 0, |
| 750 | strlen(Printers) + strlen(lpPrinter) + 2); |
| 751 | strcpy(RegStr_Printer, Printers); |
| 752 | strcat(RegStr_Printer, lpPrinter); |
| 753 | |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 754 | if (((DWORD)lpProfile == INT_PD_DEFAULT_DEVMODE) || (HIWORD(lpProfile) && |
| 755 | (!strcmp(lpProfile, DefaultDevMode)))) { |
Huw D M Davies | d92c95d | 1999-01-26 10:07:39 +0000 | [diff] [blame] | 756 | size = DrvGetPrinterDataInternal(RegStr_Printer, lpPrinterData, cbData, |
| 757 | INT_PD_DEFAULT_DEVMODE); |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 758 | if (size+1) { |
| 759 | *lpNeeded = size; |
| 760 | if ((lpPrinterData) && (*lpNeeded > cbData)) |
| 761 | res = ERROR_MORE_DATA; |
| 762 | } |
| 763 | else res = ERROR_INVALID_PRINTER_NAME; |
| 764 | } |
| 765 | else |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 766 | if (((DWORD)lpProfile == INT_PD_DEFAULT_MODEL) || (HIWORD(lpProfile) && |
| 767 | (!strcmp(lpProfile, PrinterModel)))) { |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 768 | *lpNeeded = 32; |
| 769 | if (!lpPrinterData) goto failed; |
| 770 | if (cbData < 32) { |
| 771 | res = ERROR_MORE_DATA; |
| 772 | goto failed; |
| 773 | } |
Huw D M Davies | d92c95d | 1999-01-26 10:07:39 +0000 | [diff] [blame] | 774 | size = DrvGetPrinterDataInternal(RegStr_Printer, lpPrinterData, cbData, |
| 775 | INT_PD_DEFAULT_MODEL); |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 776 | if ((size+1) && (lpType)) |
| 777 | *lpType = REG_SZ; |
| 778 | else |
| 779 | res = ERROR_INVALID_PRINTER_NAME; |
| 780 | } |
| 781 | else |
| 782 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 783 | if ((res = RegOpenKeyA(HKEY_LOCAL_MACHINE, RegStr_Printer, &hkey))) |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 784 | goto failed; |
| 785 | cbPrinterAttr = 4; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 786 | if ((res = RegQueryValueExA(hkey, "Attributes", 0, |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 787 | &dwType, (LPBYTE)&PrinterAttr, &cbPrinterAttr))) |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 788 | goto failed; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 789 | if ((res = RegOpenKeyA(hkey, PrinterDriverData, &hkey2))) |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 790 | goto failed; |
| 791 | *lpNeeded = cbData; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 792 | res = RegQueryValueExA(hkey2, lpProfile, 0, |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 793 | lpType, lpPrinterData, lpNeeded); |
| 794 | if ((res != ERROR_CANTREAD) && |
| 795 | ((PrinterAttr & |
| 796 | (PRINTER_ATTRIBUTE_ENABLE_BIDI|PRINTER_ATTRIBUTE_NETWORK)) |
| 797 | == PRINTER_ATTRIBUTE_NETWORK)) |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 798 | { |
| 799 | if (!(res) && (*lpType == REG_DWORD) && (*(LPDWORD)lpPrinterData == -1)) |
| 800 | res = ERROR_INVALID_DATA; |
| 801 | } |
| 802 | else |
| 803 | { |
| 804 | SetData = -1; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 805 | RegSetValueExA(hkey2, lpProfile, 0, REG_DWORD, (LPBYTE)&SetData, 4); /* no result returned */ |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 806 | } |
| 807 | } |
| 808 | |
| 809 | failed: |
| 810 | if (hkey2) RegCloseKey(hkey2); |
| 811 | if (hkey) RegCloseKey(hkey); |
| 812 | HeapFree(GetProcessHeap(), 0, RegStr_Printer); |
| 813 | return res; |
Alexandre Julliard | 0e270f4 | 1996-08-24 18:26:35 +0000 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | |
Huw D M Davies | 7d5fd8d | 1998-12-08 09:44:30 +0000 | [diff] [blame] | 817 | /****************************************************************** |
| 818 | * DrvSetPrinterData [GDI.281] |
| 819 | * |
| 820 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 821 | DWORD WINAPI DrvSetPrinterData16(LPSTR lpPrinter, LPSTR lpProfile, |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 822 | DWORD lpType, LPBYTE lpPrinterData, |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 823 | DWORD dwSize) |
Alexandre Julliard | 0e270f4 | 1996-08-24 18:26:35 +0000 | [diff] [blame] | 824 | { |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 825 | LPSTR RegStr_Printer; |
| 826 | HKEY hkey = 0; |
| 827 | DWORD res = 0; |
| 828 | |
Alexandre Julliard | 33072e1 | 1997-06-29 18:08:02 +0000 | [diff] [blame] | 829 | if (HIWORD(lpPrinter)) |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 830 | TRACE("printer %s\n",lpPrinter); |
Alexandre Julliard | 33072e1 | 1997-06-29 18:08:02 +0000 | [diff] [blame] | 831 | else |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 832 | TRACE("printer %p\n",lpPrinter); |
Alexandre Julliard | 33072e1 | 1997-06-29 18:08:02 +0000 | [diff] [blame] | 833 | if (HIWORD(lpProfile)) |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 834 | TRACE("profile %s\n",lpProfile); |
Alexandre Julliard | 33072e1 | 1997-06-29 18:08:02 +0000 | [diff] [blame] | 835 | else |
Huw D M Davies | e39b676 | 1999-05-17 16:20:51 +0000 | [diff] [blame] | 836 | TRACE("profile %p\n",lpProfile); |
| 837 | TRACE("lpType %08lx\n",lpType); |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 838 | |
| 839 | if ((!lpPrinter) || (!lpProfile) || |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 840 | ((DWORD)lpProfile == INT_PD_DEFAULT_MODEL) || (HIWORD(lpProfile) && |
| 841 | (!strcmp(lpProfile, PrinterModel)))) |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 842 | return ERROR_INVALID_PARAMETER; |
| 843 | |
| 844 | RegStr_Printer = HeapAlloc(GetProcessHeap(), 0, |
| 845 | strlen(Printers) + strlen(lpPrinter) + 2); |
| 846 | strcpy(RegStr_Printer, Printers); |
| 847 | strcat(RegStr_Printer, lpPrinter); |
| 848 | |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 849 | if (((DWORD)lpProfile == INT_PD_DEFAULT_DEVMODE) || (HIWORD(lpProfile) && |
| 850 | (!strcmp(lpProfile, DefaultDevMode)))) { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 851 | if ( RegOpenKeyA(HKEY_LOCAL_MACHINE, RegStr_Printer, &hkey) |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 852 | != ERROR_SUCCESS || |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 853 | RegSetValueExA(hkey, DefaultDevMode, 0, REG_BINARY, |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 854 | lpPrinterData, dwSize) != ERROR_SUCCESS ) |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 855 | res = ERROR_INVALID_PRINTER_NAME; |
| 856 | } |
| 857 | else |
| 858 | { |
| 859 | strcat(RegStr_Printer, "\\"); |
| 860 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 861 | if( (res = RegOpenKeyA(HKEY_LOCAL_MACHINE, RegStr_Printer, &hkey)) == |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 862 | ERROR_SUCCESS ) { |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 863 | |
| 864 | if (!lpPrinterData) |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 865 | res = RegDeleteValueA(hkey, lpProfile); |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 866 | else |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 867 | res = RegSetValueExA(hkey, lpProfile, 0, lpType, |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 868 | lpPrinterData, dwSize); |
Alexandre Julliard | f90efa9 | 1998-06-14 15:24:15 +0000 | [diff] [blame] | 869 | } |
| 870 | } |
| 871 | |
| 872 | if (hkey) RegCloseKey(hkey); |
| 873 | HeapFree(GetProcessHeap(), 0, RegStr_Printer); |
| 874 | return res; |
Alexandre Julliard | 0e270f4 | 1996-08-24 18:26:35 +0000 | [diff] [blame] | 875 | } |