Jack Jansen | 02facaf | 1998-04-21 15:23:02 +0000 | [diff] [blame] | 1 | /****************************************************************** |
| 2 | Copyright 1998 by Just van Rossum, Den Haag, The Netherlands. |
| 3 | |
| 4 | All Rights Reserved |
| 5 | |
| 6 | Permission to use, copy, modify, and distribute this software and its |
| 7 | documentation for any purpose and without fee is hereby granted, |
| 8 | provided that the above copyright notice appear in all copies and that |
| 9 | both that copyright notice and this permission notice appear in |
| 10 | supporting documentation, and that the name of Just van Rossum not be |
| 11 | used in advertising or publicity pertaining to distribution of the |
| 12 | software without specific, written prior permission. |
| 13 | |
| 14 | JUST VAN ROSSUM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
| 15 | INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO |
| 16 | EVENT SHALL JUST VAN ROSSUM BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
| 17 | CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF |
| 18 | USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR |
| 19 | OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 20 | PERFORMANCE OF THIS SOFTWARE. |
| 21 | |
| 22 | ******************************************************************/ |
| 23 | |
| 24 | #include "Python.h" |
| 25 | #include "macglue.h" |
Jack Jansen | 9d8b96c | 2000-07-14 22:16:45 +0000 | [diff] [blame] | 26 | #include "pymactoolbox.h" |
Jack Jansen | 02facaf | 1998-04-21 15:23:02 +0000 | [diff] [blame] | 27 | #include <Printing.h> |
| 28 | |
Jack Jansen | 02facaf | 1998-04-21 15:23:02 +0000 | [diff] [blame] | 29 | static PyObject *ErrorObject; |
| 30 | |
| 31 | /* ----------------------------------------------------- */ |
| 32 | |
| 33 | static int |
| 34 | TPRect_Convert(PyObject *v, TPRect *r) |
| 35 | { |
| 36 | if (v == Py_None) { |
| 37 | *r = NULL; |
| 38 | return 1; |
| 39 | } |
| 40 | return PyArg_Parse(v, "(hhhh)", &(*r)->left, &(*r)->top, &(*r)->right, &(*r)->bottom); |
| 41 | } |
| 42 | |
| 43 | |
| 44 | static char Pr_NewTPrintRecord__doc__[] = |
| 45 | "creates a new TPrint handle" |
| 46 | ; |
| 47 | |
| 48 | static PyObject * |
| 49 | Pr_NewTPrintRecord(self, args) |
| 50 | PyObject *self; /* Not used */ |
| 51 | PyObject *args; |
| 52 | { |
| 53 | Handle hPrint; |
| 54 | |
| 55 | if (!PyArg_ParseTuple(args, "")) |
| 56 | return NULL; |
| 57 | hPrint = NewHandleClear((long) sizeof(TPrint)); |
| 58 | if ( hPrint == NULL ) { |
| 59 | PyErr_NoMemory(); |
| 60 | return NULL; |
| 61 | } |
| 62 | return (PyObject *)ResObj_New(hPrint); |
| 63 | } |
| 64 | |
| 65 | static char Pr_PrPurge__doc__[] = |
| 66 | "PrPurge() -> None" |
| 67 | ; |
| 68 | |
| 69 | static PyObject * |
| 70 | Pr_PrPurge(self, args) |
| 71 | PyObject *self; /* Not used */ |
| 72 | PyObject *args; |
| 73 | { |
| 74 | |
| 75 | if (!PyArg_ParseTuple(args, "")) |
| 76 | return NULL; |
| 77 | PrPurge(); |
| 78 | { |
| 79 | OSErr _err = PrError(); |
| 80 | if (_err != noErr) return PyMac_Error(_err); |
| 81 | } |
| 82 | Py_INCREF(Py_None); |
| 83 | return Py_None; |
| 84 | } |
| 85 | |
| 86 | static char Pr_PrNoPurge__doc__[] = |
| 87 | "PrNoPurge() -> None" |
| 88 | ; |
| 89 | |
| 90 | static PyObject * |
| 91 | Pr_PrNoPurge(self, args) |
| 92 | PyObject *self; /* Not used */ |
| 93 | PyObject *args; |
| 94 | { |
| 95 | |
| 96 | if (!PyArg_ParseTuple(args, "")) |
| 97 | return NULL; |
| 98 | PrNoPurge(); |
| 99 | { |
| 100 | OSErr _err = PrError(); |
| 101 | if (_err != noErr) return PyMac_Error(_err); |
| 102 | } |
| 103 | Py_INCREF(Py_None); |
| 104 | return Py_None; |
| 105 | } |
| 106 | |
| 107 | static char Pr_PrOpen__doc__[] = |
| 108 | "PrOpen() -> None" |
| 109 | ; |
| 110 | |
| 111 | static PyObject * |
| 112 | Pr_PrOpen(self, args) |
| 113 | PyObject *self; /* Not used */ |
| 114 | PyObject *args; |
| 115 | { |
| 116 | |
| 117 | if (!PyArg_ParseTuple(args, "")) |
| 118 | return NULL; |
| 119 | PrOpen(); |
| 120 | { |
| 121 | OSErr _err = PrError(); |
| 122 | if (_err != noErr) return PyMac_Error(_err); |
| 123 | } |
| 124 | Py_INCREF(Py_None); |
| 125 | return Py_None; |
| 126 | } |
| 127 | |
| 128 | static char Pr_PrClose__doc__[] = |
| 129 | "PrClose() -> None" |
| 130 | ; |
| 131 | |
| 132 | static PyObject * |
| 133 | Pr_PrClose(self, args) |
| 134 | PyObject *self; /* Not used */ |
| 135 | PyObject *args; |
| 136 | { |
| 137 | |
| 138 | if (!PyArg_ParseTuple(args, "")) |
| 139 | return NULL; |
| 140 | PrClose(); |
| 141 | { |
| 142 | OSErr _err = PrError(); |
| 143 | if (_err != noErr) return PyMac_Error(_err); |
| 144 | } |
| 145 | Py_INCREF(Py_None); |
| 146 | return Py_None; |
| 147 | } |
| 148 | |
| 149 | static char Pr_PrintDefault__doc__[] = |
| 150 | "PrintDefault(THPrint hPrint) -> None" |
| 151 | ; |
| 152 | |
| 153 | static PyObject * |
| 154 | Pr_PrintDefault(self, args) |
| 155 | PyObject *self; /* Not used */ |
| 156 | PyObject *args; |
| 157 | { |
| 158 | THPrint hPrint; |
| 159 | |
| 160 | if (!PyArg_ParseTuple(args, "O&", ResObj_Convert, &hPrint)) |
| 161 | return NULL; |
| 162 | PrintDefault(hPrint); |
| 163 | { |
| 164 | OSErr _err = PrError(); |
| 165 | if (_err != noErr) return PyMac_Error(_err); |
| 166 | } |
| 167 | Py_INCREF(Py_None); |
| 168 | return Py_None; |
| 169 | } |
| 170 | |
| 171 | static char Pr_PrValidate__doc__[] = |
| 172 | "PrValidate(THPrint hPrint) -> None" |
| 173 | ; |
| 174 | |
| 175 | static PyObject * |
| 176 | Pr_PrValidate(self, args) |
| 177 | PyObject *self; /* Not used */ |
| 178 | PyObject *args; |
| 179 | { |
| 180 | THPrint hPrint; |
| 181 | |
| 182 | if (!PyArg_ParseTuple(args, "O&", ResObj_Convert, &hPrint)) |
| 183 | return NULL; |
| 184 | PrValidate(hPrint); |
| 185 | { |
| 186 | OSErr _err = PrError(); |
| 187 | if (_err != noErr) return PyMac_Error(_err); |
| 188 | } |
| 189 | Py_INCREF(Py_None); |
| 190 | return Py_None; |
| 191 | } |
| 192 | |
| 193 | static char Pr_PrStlDialog__doc__[] = |
| 194 | "PrStlDialog(THPrint hPrint) -> Boolean" |
| 195 | ; |
| 196 | |
| 197 | static PyObject * |
| 198 | Pr_PrStlDialog(self, args) |
| 199 | PyObject *self; /* Not used */ |
| 200 | PyObject *args; |
| 201 | { |
| 202 | THPrint hPrint; |
| 203 | Boolean rv; |
| 204 | |
| 205 | if (!PyArg_ParseTuple(args, "O&", ResObj_Convert, &hPrint)) |
| 206 | return NULL; |
| 207 | rv = PrStlDialog(hPrint); |
| 208 | { |
| 209 | OSErr _err = PrError(); |
| 210 | if (_err != noErr) return PyMac_Error(_err); |
| 211 | } |
| 212 | return Py_BuildValue("h", rv); |
| 213 | } |
| 214 | |
| 215 | static char Pr_PrJobDialog__doc__[] = |
| 216 | "PrJobDialog(THPrint hPrint) -> Boolean" |
| 217 | ; |
| 218 | |
| 219 | static PyObject * |
| 220 | Pr_PrJobDialog(self, args) |
| 221 | PyObject *self; /* Not used */ |
| 222 | PyObject *args; |
| 223 | { |
| 224 | THPrint hPrint; |
| 225 | Boolean rv; |
| 226 | |
| 227 | if (!PyArg_ParseTuple(args, "O&", ResObj_Convert, &hPrint)) |
| 228 | return NULL; |
| 229 | rv = PrJobDialog(hPrint); |
| 230 | { |
| 231 | OSErr _err = PrError(); |
| 232 | if (_err != noErr) return PyMac_Error(_err); |
| 233 | } |
| 234 | return Py_BuildValue("h", rv); |
| 235 | } |
| 236 | |
| 237 | static char Pr_PrJobMerge__doc__[] = |
| 238 | "PrJobMerge(THPrint hPrintSrc, THPrint hPrintDst) -> none" |
| 239 | ; |
| 240 | |
| 241 | static PyObject * |
| 242 | Pr_PrJobMerge(self, args) |
| 243 | PyObject *self; /* Not used */ |
| 244 | PyObject *args; |
| 245 | { |
| 246 | THPrint hPrintSrc, hPrintDst; |
| 247 | |
| 248 | if (!PyArg_ParseTuple(args, "O&O&", ResObj_Convert, &hPrintSrc, ResObj_Convert, &hPrintDst)) |
| 249 | return NULL; |
| 250 | PrJobMerge(hPrintSrc, hPrintDst); |
| 251 | { |
| 252 | OSErr _err = PrError(); |
| 253 | if (_err != noErr) return PyMac_Error(_err); |
| 254 | } |
| 255 | Py_INCREF(Py_None); |
| 256 | return Py_None; |
| 257 | } |
| 258 | |
| 259 | static char Pr_PrOpenDoc__doc__[] = |
| 260 | "PrOpenDoc(THPrint hPrint) -> TPPrPort aTPPort" |
| 261 | ; |
| 262 | |
| 263 | static PyObject * |
| 264 | Pr_PrOpenDoc(self, args) |
| 265 | PyObject *self; /* Not used */ |
| 266 | PyObject *args; |
| 267 | { |
| 268 | THPrint hPrint; |
| 269 | TPPrPort aTPPort; |
| 270 | |
| 271 | if (!PyArg_ParseTuple(args, "O&", ResObj_Convert, &hPrint)) |
| 272 | return NULL; |
| 273 | aTPPort = PrOpenDoc(hPrint, NULL, NULL); |
| 274 | { |
| 275 | OSErr _err = PrError(); |
| 276 | if (_err != noErr) return PyMac_Error(_err); |
| 277 | } |
| 278 | return Py_BuildValue("O&", GrafObj_New, aTPPort); |
| 279 | } |
| 280 | |
| 281 | static char Pr_PrCloseDoc__doc__[] = |
| 282 | "PrCloseDoc(TPPrPort pPrPort) -> None" |
| 283 | ; |
| 284 | |
| 285 | static PyObject * |
| 286 | Pr_PrCloseDoc(self, args) |
| 287 | PyObject *self; /* Not used */ |
| 288 | PyObject *args; |
| 289 | { |
| 290 | TPPrPort pPrPort; |
| 291 | |
| 292 | if (!PyArg_ParseTuple(args, "O&", GrafObj_Convert, &pPrPort)) |
| 293 | return NULL; |
| 294 | PrCloseDoc(pPrPort); |
| 295 | { |
| 296 | OSErr _err = PrError(); |
| 297 | if (_err != noErr) return PyMac_Error(_err); |
| 298 | } |
| 299 | Py_INCREF(Py_None); |
| 300 | return Py_None; |
| 301 | } |
| 302 | |
| 303 | static char Pr_PrOpenPage__doc__[] = |
| 304 | "PrOpenPage(TPPrPort pPrPort, TPRect pPageFrame) -> None" |
| 305 | ; |
| 306 | |
| 307 | static PyObject * |
| 308 | Pr_PrOpenPage(self, args) |
| 309 | PyObject *self; /* Not used */ |
| 310 | PyObject *args; |
| 311 | { |
| 312 | TPPrPort pPrPort; |
| 313 | Rect dummyrect = {0, 0, 0, 0}; |
| 314 | TPRect pPageFrame = &dummyrect; |
| 315 | |
| 316 | if (!PyArg_ParseTuple(args, "O&O&", GrafObj_Convert, &pPrPort, TPRect_Convert, &pPageFrame)) |
| 317 | return NULL; |
| 318 | PrOpenPage(pPrPort, pPageFrame); |
| 319 | { |
| 320 | OSErr _err = PrError(); |
| 321 | if (_err != noErr) return PyMac_Error(_err); |
| 322 | } |
| 323 | Py_INCREF(Py_None); |
| 324 | return Py_None; |
| 325 | } |
| 326 | |
| 327 | static char Pr_PrClosePage__doc__[] = |
| 328 | "PrClosePage(TPPrPort pPrPort) -> None" |
| 329 | ; |
| 330 | |
| 331 | static PyObject * |
| 332 | Pr_PrClosePage(self, args) |
| 333 | PyObject *self; /* Not used */ |
| 334 | PyObject *args; |
| 335 | { |
| 336 | TPPrPort pPrPort; |
| 337 | |
| 338 | if (!PyArg_ParseTuple(args, "O&", GrafObj_Convert, &pPrPort)) |
| 339 | return NULL; |
| 340 | PrClosePage(pPrPort); |
| 341 | { |
| 342 | OSErr _err = PrError(); |
| 343 | if (_err != noErr) return PyMac_Error(_err); |
| 344 | } |
| 345 | Py_INCREF(Py_None); |
| 346 | return Py_None; |
| 347 | } |
| 348 | |
| 349 | static char Pr_PrPicFile__doc__[] = |
| 350 | "PrPicFile(THPrint hPrint) -> none" |
| 351 | ; |
| 352 | |
| 353 | static PyObject * |
| 354 | Pr_PrPicFile(self, args) |
| 355 | PyObject *self; /* Not used */ |
| 356 | PyObject *args; |
| 357 | { |
| 358 | THPrint hPrint; |
| 359 | TPrStatus prStatus; |
| 360 | |
| 361 | if (!PyArg_ParseTuple(args, "O&", ResObj_Convert, &hPrint)) |
| 362 | return NULL; |
| 363 | PrPicFile(hPrint, NULL, NULL, NULL, &prStatus); |
| 364 | { |
| 365 | OSErr _err = PrError(); |
| 366 | if (_err != noErr) return PyMac_Error(_err); |
| 367 | } |
| 368 | Py_INCREF(Py_None); |
| 369 | return Py_None; |
| 370 | } |
| 371 | |
| 372 | static char Pr_PrGeneral__doc__[] = |
| 373 | "not implemented" |
| 374 | ; |
| 375 | |
| 376 | static PyObject * |
| 377 | Pr_PrGeneral(self, args) |
| 378 | PyObject *self; /* Not used */ |
| 379 | PyObject *args; |
| 380 | { |
| 381 | |
| 382 | if (!PyArg_ParseTuple(args, "")) |
| 383 | return NULL; |
| 384 | //PrGeneral(); |
| 385 | { |
| 386 | OSErr _err = PrError(); |
| 387 | if (_err != noErr) return PyMac_Error(_err); |
| 388 | } |
| 389 | Py_INCREF(Py_None); |
| 390 | return Py_None; |
| 391 | } |
| 392 | |
| 393 | static char Pr_PrDrvrVers__doc__[] = |
| 394 | "PrDrvrVers() -> version" |
| 395 | ; |
| 396 | |
| 397 | static PyObject * |
| 398 | Pr_PrDrvrVers(self, args) |
| 399 | PyObject *self; /* Not used */ |
| 400 | PyObject *args; |
| 401 | { |
| 402 | short rv; |
| 403 | |
| 404 | if (!PyArg_ParseTuple(args, "")) |
| 405 | return NULL; |
| 406 | rv = PrDrvrVers(); |
| 407 | { |
| 408 | OSErr _err = PrError(); |
| 409 | if (_err != noErr) return PyMac_Error(_err); |
| 410 | } |
| 411 | return Py_BuildValue("h", rv); |
| 412 | } |
| 413 | |
| 414 | /* List of methods defined in the module */ |
| 415 | |
| 416 | static struct PyMethodDef Pr_methods[] = { |
| 417 | {"NewTPrintRecord", (PyCFunction)Pr_NewTPrintRecord, METH_VARARGS, Pr_NewTPrintRecord__doc__}, |
| 418 | {"PrPurge", (PyCFunction)Pr_PrPurge, METH_VARARGS, Pr_PrPurge__doc__}, |
| 419 | {"PrNoPurge", (PyCFunction)Pr_PrNoPurge, METH_VARARGS, Pr_PrNoPurge__doc__}, |
| 420 | {"PrOpen", (PyCFunction)Pr_PrOpen, METH_VARARGS, Pr_PrOpen__doc__}, |
| 421 | {"PrClose", (PyCFunction)Pr_PrClose, METH_VARARGS, Pr_PrClose__doc__}, |
| 422 | {"PrintDefault",(PyCFunction)Pr_PrintDefault, METH_VARARGS, Pr_PrintDefault__doc__}, |
| 423 | {"PrValidate", (PyCFunction)Pr_PrValidate, METH_VARARGS, Pr_PrValidate__doc__}, |
| 424 | {"PrStlDialog", (PyCFunction)Pr_PrStlDialog, METH_VARARGS, Pr_PrStlDialog__doc__}, |
| 425 | {"PrJobDialog", (PyCFunction)Pr_PrJobDialog, METH_VARARGS, Pr_PrJobDialog__doc__}, |
| 426 | {"PrJobMerge", (PyCFunction)Pr_PrJobMerge, METH_VARARGS, Pr_PrJobMerge__doc__}, |
| 427 | {"PrOpenDoc", (PyCFunction)Pr_PrOpenDoc, METH_VARARGS, Pr_PrOpenDoc__doc__}, |
| 428 | {"PrCloseDoc", (PyCFunction)Pr_PrCloseDoc, METH_VARARGS, Pr_PrCloseDoc__doc__}, |
| 429 | {"PrOpenPage", (PyCFunction)Pr_PrOpenPage, METH_VARARGS, Pr_PrOpenPage__doc__}, |
| 430 | {"PrClosePage", (PyCFunction)Pr_PrClosePage, METH_VARARGS, Pr_PrClosePage__doc__}, |
| 431 | {"PrPicFile", (PyCFunction)Pr_PrPicFile, METH_VARARGS, Pr_PrPicFile__doc__}, |
Jack Jansen | aa70234 | 1998-04-27 15:08:39 +0000 | [diff] [blame] | 432 | // {"PrGeneral", (PyCFunction)Pr_PrGeneral, METH_VARARGS, Pr_PrGeneral__doc__}, |
Jack Jansen | 02facaf | 1998-04-21 15:23:02 +0000 | [diff] [blame] | 433 | {"PrDrvrVers", (PyCFunction)Pr_PrDrvrVers, METH_VARARGS, Pr_PrDrvrVers__doc__}, |
| 434 | |
| 435 | {NULL, (PyCFunction)NULL, 0, NULL} /* sentinel */ |
| 436 | }; |
| 437 | |
| 438 | |
| 439 | /* Initialization function for the module (*must* be called initPrinting) */ |
| 440 | |
| 441 | static char Printing_module_documentation[] = |
| 442 | "" |
| 443 | ; |
| 444 | |
| 445 | void initPrinting(); |
| 446 | |
| 447 | void |
| 448 | initPrinting() |
| 449 | { |
| 450 | PyObject *m, *d; |
| 451 | |
| 452 | /* Create the module and add the functions */ |
| 453 | m = Py_InitModule4("Printing", Pr_methods, |
| 454 | Printing_module_documentation, |
| 455 | (PyObject*)NULL,PYTHON_API_VERSION); |
| 456 | |
| 457 | /* Add some symbolic constants to the module */ |
| 458 | d = PyModule_GetDict(m); |
| 459 | ErrorObject = PyString_FromString("Printing.error"); |
| 460 | PyDict_SetItemString(d, "error", ErrorObject); |
| 461 | |
| 462 | /* XXXX Add constants here */ |
| 463 | |
Jack Jansen | 02facaf | 1998-04-21 15:23:02 +0000 | [diff] [blame] | 464 | } |
| 465 | |