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