Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1 | |
| 2 | /* =========================== Module Dlg =========================== */ |
| 3 | |
| 4 | #include "Python.h" |
| 5 | |
| 6 | |
| 7 | |
| 8 | #define SystemSevenOrLater 1 |
| 9 | |
| 10 | #include "macglue.h" |
| 11 | #include <Memory.h> |
| 12 | #include <Dialogs.h> |
| 13 | #include <Menus.h> |
| 14 | #include <Controls.h> |
| 15 | |
| 16 | extern PyObject *ResObj_New(Handle); |
| 17 | extern int ResObj_Convert(PyObject *, Handle *); |
Jack Jansen | 425e9eb | 1995-12-12 15:02:03 +0000 | [diff] [blame] | 18 | extern PyObject *OptResObj_New(Handle); |
| 19 | extern int OptResObj_Convert(PyObject *, Handle *); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 20 | |
| 21 | extern PyObject *WinObj_New(WindowPtr); |
| 22 | extern int WinObj_Convert(PyObject *, WindowPtr *); |
Jack Jansen | 425e9eb | 1995-12-12 15:02:03 +0000 | [diff] [blame] | 23 | extern PyTypeObject Window_Type; |
| 24 | #define WinObj_Check(x) ((x)->ob_type == &Window_Type) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 25 | |
| 26 | extern PyObject *DlgObj_New(DialogPtr); |
| 27 | extern int DlgObj_Convert(PyObject *, DialogPtr *); |
| 28 | extern PyTypeObject Dialog_Type; |
| 29 | #define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type) |
| 30 | |
| 31 | extern PyObject *MenuObj_New(MenuHandle); |
| 32 | extern int MenuObj_Convert(PyObject *, MenuHandle *); |
| 33 | |
| 34 | extern PyObject *CtlObj_New(ControlHandle); |
| 35 | extern int CtlObj_Convert(PyObject *, ControlHandle *); |
| 36 | |
Jack Jansen | 425e9eb | 1995-12-12 15:02:03 +0000 | [diff] [blame] | 37 | extern PyObject *GrafObj_New(GrafPtr); |
| 38 | extern int GrafObj_Convert(PyObject *, GrafPtr *); |
| 39 | |
| 40 | extern PyObject *BMObj_New(BitMapPtr); |
| 41 | extern int BMObj_Convert(PyObject *, BitMapPtr *); |
| 42 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 43 | extern PyObject *WinObj_WhichWindow(WindowPtr); |
| 44 | |
| 45 | #include <Dialogs.h> |
| 46 | |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 47 | #ifndef HAVE_UNIVERSAL_HEADERS |
| 48 | #define NewModalFilterProc(x) (x) |
| 49 | #endif |
| 50 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 51 | #define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */ |
| 52 | |
| 53 | /* XXX Shouldn't this be a stack? */ |
| 54 | static PyObject *Dlg_FilterProc_callback = NULL; |
| 55 | |
| 56 | static PyObject *DlgObj_New(DialogPtr); /* Forward */ |
| 57 | |
| 58 | static pascal Boolean Dlg_UnivFilterProc(DialogPtr dialog, |
| 59 | EventRecord *event, |
| 60 | short *itemHit) |
| 61 | { |
| 62 | Boolean rv; |
| 63 | PyObject *args, *res; |
| 64 | PyObject *callback = Dlg_FilterProc_callback; |
| 65 | if (callback == NULL) |
| 66 | return 0; /* Default behavior */ |
| 67 | Dlg_FilterProc_callback = NULL; /* We'll restore it when call successful */ |
Guido van Rossum | 0437e89 | 1995-02-21 20:56:21 +0000 | [diff] [blame] | 68 | args = Py_BuildValue("O&O&", WinObj_WhichWindow, dialog, PyMac_BuildEventRecord, event); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 69 | if (args == NULL) |
| 70 | res = NULL; |
| 71 | else { |
| 72 | res = PyEval_CallObject(callback, args); |
| 73 | Py_DECREF(args); |
| 74 | } |
| 75 | if (res == NULL) { |
| 76 | fprintf(stderr, "Exception in Dialog Filter\n"); |
| 77 | PyErr_Print(); |
| 78 | *itemHit = -1; /* Fake return item */ |
| 79 | return 1; /* We handled it */ |
| 80 | } |
| 81 | else { |
| 82 | Dlg_FilterProc_callback = callback; |
| 83 | if (PyInt_Check(res)) { |
| 84 | *itemHit = PyInt_AsLong(res); |
| 85 | rv = 1; |
| 86 | } |
| 87 | else |
| 88 | rv = PyObject_IsTrue(res); |
| 89 | } |
| 90 | Py_DECREF(res); |
| 91 | return rv; |
| 92 | } |
| 93 | |
| 94 | static ModalFilterProcPtr |
| 95 | Dlg_PassFilterProc(PyObject *callback) |
| 96 | { |
| 97 | PyObject *tmp = Dlg_FilterProc_callback; |
| 98 | Dlg_FilterProc_callback = NULL; |
| 99 | if (callback == Py_None) { |
| 100 | Py_XDECREF(tmp); |
| 101 | return NULL; |
| 102 | } |
| 103 | Py_INCREF(callback); |
| 104 | Dlg_FilterProc_callback = callback; |
| 105 | Py_XDECREF(tmp); |
| 106 | return &Dlg_UnivFilterProc; |
| 107 | } |
| 108 | |
| 109 | extern PyMethodChain WinObj_chain; |
| 110 | |
| 111 | static PyObject *Dlg_Error; |
| 112 | |
| 113 | /* ----------------------- Object type Dialog ----------------------- */ |
| 114 | |
| 115 | PyTypeObject Dialog_Type; |
| 116 | |
| 117 | #define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type) |
| 118 | |
| 119 | typedef struct DialogObject { |
| 120 | PyObject_HEAD |
| 121 | DialogPtr ob_itself; |
| 122 | } DialogObject; |
| 123 | |
| 124 | PyObject *DlgObj_New(itself) |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 125 | DialogPtr itself; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 126 | { |
| 127 | DialogObject *it; |
| 128 | if (itself == NULL) return Py_None; |
| 129 | it = PyObject_NEW(DialogObject, &Dialog_Type); |
| 130 | if (it == NULL) return NULL; |
| 131 | it->ob_itself = itself; |
| 132 | SetWRefCon(itself, (long)it); |
| 133 | return (PyObject *)it; |
| 134 | } |
| 135 | DlgObj_Convert(v, p_itself) |
| 136 | PyObject *v; |
| 137 | DialogPtr *p_itself; |
| 138 | { |
| 139 | if (v == Py_None) { *p_itself = NULL; return 1; } |
| 140 | if (PyInt_Check(v)) { *p_itself = (DialogPtr)PyInt_AsLong(v); |
| 141 | return 1; } |
| 142 | if (!DlgObj_Check(v)) |
| 143 | { |
| 144 | PyErr_SetString(PyExc_TypeError, "Dialog required"); |
| 145 | return 0; |
| 146 | } |
| 147 | *p_itself = ((DialogObject *)v)->ob_itself; |
| 148 | return 1; |
| 149 | } |
| 150 | |
| 151 | static void DlgObj_dealloc(self) |
| 152 | DialogObject *self; |
| 153 | { |
| 154 | DisposeDialog(self->ob_itself); |
| 155 | PyMem_DEL(self); |
| 156 | } |
| 157 | |
| 158 | static PyObject *DlgObj_DrawDialog(_self, _args) |
| 159 | DialogObject *_self; |
| 160 | PyObject *_args; |
| 161 | { |
| 162 | PyObject *_res = NULL; |
| 163 | if (!PyArg_ParseTuple(_args, "")) |
| 164 | return NULL; |
| 165 | DrawDialog(_self->ob_itself); |
| 166 | Py_INCREF(Py_None); |
| 167 | _res = Py_None; |
| 168 | return _res; |
| 169 | } |
| 170 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 171 | static PyObject *DlgObj_UpdateDialog(_self, _args) |
| 172 | DialogObject *_self; |
| 173 | PyObject *_args; |
| 174 | { |
| 175 | PyObject *_res = NULL; |
Jack Jansen | 2b72417 | 1996-04-10 14:48:19 +0000 | [diff] [blame] | 176 | RgnHandle updateRgn; |
| 177 | if (!PyArg_ParseTuple(_args, "O&", |
| 178 | ResObj_Convert, &updateRgn)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 179 | return NULL; |
| 180 | UpdateDialog(_self->ob_itself, |
Jack Jansen | 2b72417 | 1996-04-10 14:48:19 +0000 | [diff] [blame] | 181 | updateRgn); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 182 | Py_INCREF(Py_None); |
| 183 | _res = Py_None; |
| 184 | return _res; |
| 185 | } |
| 186 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 187 | static PyObject *DlgObj_HideDialogItem(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 188 | DialogObject *_self; |
| 189 | PyObject *_args; |
| 190 | { |
| 191 | PyObject *_res = NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 192 | DialogItemIndex itemNo; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 193 | if (!PyArg_ParseTuple(_args, "h", |
| 194 | &itemNo)) |
| 195 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 196 | HideDialogItem(_self->ob_itself, |
| 197 | itemNo); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 198 | Py_INCREF(Py_None); |
| 199 | _res = Py_None; |
| 200 | return _res; |
| 201 | } |
| 202 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 203 | static PyObject *DlgObj_ShowDialogItem(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 204 | DialogObject *_self; |
| 205 | PyObject *_args; |
| 206 | { |
| 207 | PyObject *_res = NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 208 | DialogItemIndex itemNo; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 209 | if (!PyArg_ParseTuple(_args, "h", |
| 210 | &itemNo)) |
| 211 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 212 | ShowDialogItem(_self->ob_itself, |
| 213 | itemNo); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 214 | Py_INCREF(Py_None); |
| 215 | _res = Py_None; |
| 216 | return _res; |
| 217 | } |
| 218 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 219 | static PyObject *DlgObj_FindDialogItem(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 220 | DialogObject *_self; |
| 221 | PyObject *_args; |
| 222 | { |
| 223 | PyObject *_res = NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 224 | DialogItemIndexZeroBased _rv; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 225 | Point thePt; |
| 226 | if (!PyArg_ParseTuple(_args, "O&", |
| 227 | PyMac_GetPoint, &thePt)) |
| 228 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 229 | _rv = FindDialogItem(_self->ob_itself, |
| 230 | thePt); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 231 | _res = Py_BuildValue("h", |
| 232 | _rv); |
| 233 | return _res; |
| 234 | } |
| 235 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 236 | static PyObject *DlgObj_DialogCut(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 237 | DialogObject *_self; |
| 238 | PyObject *_args; |
| 239 | { |
| 240 | PyObject *_res = NULL; |
| 241 | if (!PyArg_ParseTuple(_args, "")) |
| 242 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 243 | DialogCut(_self->ob_itself); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 244 | Py_INCREF(Py_None); |
| 245 | _res = Py_None; |
| 246 | return _res; |
| 247 | } |
| 248 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 249 | static PyObject *DlgObj_DialogPaste(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 250 | DialogObject *_self; |
| 251 | PyObject *_args; |
| 252 | { |
| 253 | PyObject *_res = NULL; |
| 254 | if (!PyArg_ParseTuple(_args, "")) |
| 255 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 256 | DialogPaste(_self->ob_itself); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 257 | Py_INCREF(Py_None); |
| 258 | _res = Py_None; |
| 259 | return _res; |
| 260 | } |
| 261 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 262 | static PyObject *DlgObj_DialogCopy(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 263 | DialogObject *_self; |
| 264 | PyObject *_args; |
| 265 | { |
| 266 | PyObject *_res = NULL; |
| 267 | if (!PyArg_ParseTuple(_args, "")) |
| 268 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 269 | DialogCopy(_self->ob_itself); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 270 | Py_INCREF(Py_None); |
| 271 | _res = Py_None; |
| 272 | return _res; |
| 273 | } |
| 274 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 275 | static PyObject *DlgObj_DialogDelete(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 276 | DialogObject *_self; |
| 277 | PyObject *_args; |
| 278 | { |
| 279 | PyObject *_res = NULL; |
| 280 | if (!PyArg_ParseTuple(_args, "")) |
| 281 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 282 | DialogDelete(_self->ob_itself); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 283 | Py_INCREF(Py_None); |
| 284 | _res = Py_None; |
| 285 | return _res; |
| 286 | } |
| 287 | |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 288 | static PyObject *DlgObj_GetDialogItem(_self, _args) |
| 289 | DialogObject *_self; |
| 290 | PyObject *_args; |
| 291 | { |
| 292 | PyObject *_res = NULL; |
| 293 | DialogItemIndex itemNo; |
| 294 | DialogItemType itemType; |
| 295 | Handle item; |
| 296 | Rect box; |
| 297 | if (!PyArg_ParseTuple(_args, "h", |
| 298 | &itemNo)) |
| 299 | return NULL; |
| 300 | GetDialogItem(_self->ob_itself, |
| 301 | itemNo, |
| 302 | &itemType, |
| 303 | &item, |
| 304 | &box); |
| 305 | _res = Py_BuildValue("hO&O&", |
| 306 | itemType, |
| 307 | OptResObj_New, item, |
| 308 | PyMac_BuildRect, &box); |
| 309 | return _res; |
| 310 | } |
| 311 | |
| 312 | static PyObject *DlgObj_SetDialogItem(_self, _args) |
| 313 | DialogObject *_self; |
| 314 | PyObject *_args; |
| 315 | { |
| 316 | PyObject *_res = NULL; |
| 317 | DialogItemIndex itemNo; |
| 318 | DialogItemType itemType; |
| 319 | Handle item; |
| 320 | Rect box; |
| 321 | if (!PyArg_ParseTuple(_args, "hhO&O&", |
| 322 | &itemNo, |
| 323 | &itemType, |
| 324 | ResObj_Convert, &item, |
| 325 | PyMac_GetRect, &box)) |
| 326 | return NULL; |
| 327 | SetDialogItem(_self->ob_itself, |
| 328 | itemNo, |
| 329 | itemType, |
| 330 | item, |
| 331 | &box); |
| 332 | Py_INCREF(Py_None); |
| 333 | _res = Py_None; |
| 334 | return _res; |
| 335 | } |
| 336 | |
| 337 | static PyObject *DlgObj_SelectDialogItemText(_self, _args) |
| 338 | DialogObject *_self; |
| 339 | PyObject *_args; |
| 340 | { |
| 341 | PyObject *_res = NULL; |
| 342 | DialogItemIndex itemNo; |
| 343 | SInt16 strtSel; |
| 344 | SInt16 endSel; |
| 345 | if (!PyArg_ParseTuple(_args, "hhh", |
| 346 | &itemNo, |
| 347 | &strtSel, |
| 348 | &endSel)) |
| 349 | return NULL; |
| 350 | SelectDialogItemText(_self->ob_itself, |
| 351 | itemNo, |
| 352 | strtSel, |
| 353 | endSel); |
| 354 | Py_INCREF(Py_None); |
| 355 | _res = Py_None; |
| 356 | return _res; |
| 357 | } |
| 358 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 359 | static PyObject *DlgObj_AppendDITL(_self, _args) |
| 360 | DialogObject *_self; |
| 361 | PyObject *_args; |
| 362 | { |
| 363 | PyObject *_res = NULL; |
| 364 | Handle theHandle; |
| 365 | DITLMethod method; |
| 366 | if (!PyArg_ParseTuple(_args, "O&h", |
| 367 | ResObj_Convert, &theHandle, |
| 368 | &method)) |
| 369 | return NULL; |
| 370 | AppendDITL(_self->ob_itself, |
| 371 | theHandle, |
| 372 | method); |
| 373 | Py_INCREF(Py_None); |
| 374 | _res = Py_None; |
| 375 | return _res; |
| 376 | } |
| 377 | |
| 378 | static PyObject *DlgObj_CountDITL(_self, _args) |
| 379 | DialogObject *_self; |
| 380 | PyObject *_args; |
| 381 | { |
| 382 | PyObject *_res = NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 383 | DialogItemIndex _rv; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 384 | if (!PyArg_ParseTuple(_args, "")) |
| 385 | return NULL; |
| 386 | _rv = CountDITL(_self->ob_itself); |
| 387 | _res = Py_BuildValue("h", |
| 388 | _rv); |
| 389 | return _res; |
| 390 | } |
| 391 | |
| 392 | static PyObject *DlgObj_ShortenDITL(_self, _args) |
| 393 | DialogObject *_self; |
| 394 | PyObject *_args; |
| 395 | { |
| 396 | PyObject *_res = NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 397 | DialogItemIndex numberItems; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 398 | if (!PyArg_ParseTuple(_args, "h", |
| 399 | &numberItems)) |
| 400 | return NULL; |
| 401 | ShortenDITL(_self->ob_itself, |
| 402 | numberItems); |
| 403 | Py_INCREF(Py_None); |
| 404 | _res = Py_None; |
| 405 | return _res; |
| 406 | } |
| 407 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 408 | static PyObject *DlgObj_StdFilterProc(_self, _args) |
| 409 | DialogObject *_self; |
| 410 | PyObject *_args; |
| 411 | { |
| 412 | PyObject *_res = NULL; |
| 413 | Boolean _rv; |
| 414 | EventRecord event; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 415 | DialogItemIndex itemHit; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 416 | if (!PyArg_ParseTuple(_args, "")) |
| 417 | return NULL; |
| 418 | _rv = StdFilterProc(_self->ob_itself, |
| 419 | &event, |
| 420 | &itemHit); |
| 421 | _res = Py_BuildValue("bO&h", |
| 422 | _rv, |
| 423 | PyMac_BuildEventRecord, &event, |
| 424 | itemHit); |
| 425 | return _res; |
| 426 | } |
| 427 | |
| 428 | static PyObject *DlgObj_SetDialogDefaultItem(_self, _args) |
| 429 | DialogObject *_self; |
| 430 | PyObject *_args; |
| 431 | { |
| 432 | PyObject *_res = NULL; |
| 433 | OSErr _err; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 434 | DialogItemIndex newItem; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 435 | if (!PyArg_ParseTuple(_args, "h", |
| 436 | &newItem)) |
| 437 | return NULL; |
| 438 | _err = SetDialogDefaultItem(_self->ob_itself, |
| 439 | newItem); |
| 440 | if (_err != noErr) return PyMac_Error(_err); |
| 441 | Py_INCREF(Py_None); |
| 442 | _res = Py_None; |
| 443 | return _res; |
| 444 | } |
| 445 | |
| 446 | static PyObject *DlgObj_SetDialogCancelItem(_self, _args) |
| 447 | DialogObject *_self; |
| 448 | PyObject *_args; |
| 449 | { |
| 450 | PyObject *_res = NULL; |
| 451 | OSErr _err; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 452 | DialogItemIndex newItem; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 453 | if (!PyArg_ParseTuple(_args, "h", |
| 454 | &newItem)) |
| 455 | return NULL; |
| 456 | _err = SetDialogCancelItem(_self->ob_itself, |
| 457 | newItem); |
| 458 | if (_err != noErr) return PyMac_Error(_err); |
| 459 | Py_INCREF(Py_None); |
| 460 | _res = Py_None; |
| 461 | return _res; |
| 462 | } |
| 463 | |
| 464 | static PyObject *DlgObj_SetDialogTracksCursor(_self, _args) |
| 465 | DialogObject *_self; |
| 466 | PyObject *_args; |
| 467 | { |
| 468 | PyObject *_res = NULL; |
| 469 | OSErr _err; |
| 470 | Boolean tracks; |
| 471 | if (!PyArg_ParseTuple(_args, "b", |
| 472 | &tracks)) |
| 473 | return NULL; |
| 474 | _err = SetDialogTracksCursor(_self->ob_itself, |
| 475 | tracks); |
| 476 | if (_err != noErr) return PyMac_Error(_err); |
| 477 | Py_INCREF(Py_None); |
| 478 | _res = Py_None; |
| 479 | return _res; |
| 480 | } |
| 481 | |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 482 | static PyObject *DlgObj_AutoSizeDialog(_self, _args) |
| 483 | DialogObject *_self; |
| 484 | PyObject *_args; |
| 485 | { |
| 486 | PyObject *_res = NULL; |
| 487 | OSErr _err; |
| 488 | if (!PyArg_ParseTuple(_args, "")) |
| 489 | return NULL; |
| 490 | _err = AutoSizeDialog(_self->ob_itself); |
| 491 | if (_err != noErr) return PyMac_Error(_err); |
| 492 | Py_INCREF(Py_None); |
| 493 | _res = Py_None; |
| 494 | return _res; |
| 495 | } |
| 496 | |
| 497 | static PyObject *DlgObj_GetDialogItemAsControl(_self, _args) |
| 498 | DialogObject *_self; |
| 499 | PyObject *_args; |
| 500 | { |
| 501 | PyObject *_res = NULL; |
| 502 | OSErr _err; |
| 503 | SInt16 inItemNo; |
| 504 | ControlHandle outControl; |
| 505 | if (!PyArg_ParseTuple(_args, "h", |
| 506 | &inItemNo)) |
| 507 | return NULL; |
| 508 | _err = GetDialogItemAsControl(_self->ob_itself, |
| 509 | inItemNo, |
| 510 | &outControl); |
| 511 | if (_err != noErr) return PyMac_Error(_err); |
| 512 | _res = Py_BuildValue("O&", |
| 513 | CtlObj_New, outControl); |
| 514 | return _res; |
| 515 | } |
| 516 | |
| 517 | static PyObject *DlgObj_MoveDialogItem(_self, _args) |
| 518 | DialogObject *_self; |
| 519 | PyObject *_args; |
| 520 | { |
| 521 | PyObject *_res = NULL; |
| 522 | OSErr _err; |
| 523 | SInt16 inItemNo; |
| 524 | SInt16 inHoriz; |
| 525 | SInt16 inVert; |
| 526 | if (!PyArg_ParseTuple(_args, "hhh", |
| 527 | &inItemNo, |
| 528 | &inHoriz, |
| 529 | &inVert)) |
| 530 | return NULL; |
| 531 | _err = MoveDialogItem(_self->ob_itself, |
| 532 | inItemNo, |
| 533 | inHoriz, |
| 534 | inVert); |
| 535 | if (_err != noErr) return PyMac_Error(_err); |
| 536 | Py_INCREF(Py_None); |
| 537 | _res = Py_None; |
| 538 | return _res; |
| 539 | } |
| 540 | |
| 541 | static PyObject *DlgObj_SizeDialogItem(_self, _args) |
| 542 | DialogObject *_self; |
| 543 | PyObject *_args; |
| 544 | { |
| 545 | PyObject *_res = NULL; |
| 546 | OSErr _err; |
| 547 | SInt16 inItemNo; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 548 | SInt16 inWidth; |
Jack Jansen | 1c4e614 | 1998-04-21 15:23:55 +0000 | [diff] [blame^] | 549 | SInt16 inHeight; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 550 | if (!PyArg_ParseTuple(_args, "hhh", |
| 551 | &inItemNo, |
Jack Jansen | 1c4e614 | 1998-04-21 15:23:55 +0000 | [diff] [blame^] | 552 | &inWidth, |
| 553 | &inHeight)) |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 554 | return NULL; |
| 555 | _err = SizeDialogItem(_self->ob_itself, |
| 556 | inItemNo, |
Jack Jansen | 1c4e614 | 1998-04-21 15:23:55 +0000 | [diff] [blame^] | 557 | inWidth, |
| 558 | inHeight); |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 559 | if (_err != noErr) return PyMac_Error(_err); |
| 560 | Py_INCREF(Py_None); |
| 561 | _res = Py_None; |
| 562 | return _res; |
| 563 | } |
| 564 | |
Jack Jansen | d96cb50 | 1996-09-23 15:48:46 +0000 | [diff] [blame] | 565 | static PyObject *DlgObj_GetDialogWindow(_self, _args) |
| 566 | DialogObject *_self; |
| 567 | PyObject *_args; |
| 568 | { |
| 569 | PyObject *_res = NULL; |
| 570 | DialogPtr _rv; |
| 571 | if (!PyArg_ParseTuple(_args, "")) |
| 572 | return NULL; |
| 573 | _rv = GetDialogWindow(_self->ob_itself); |
| 574 | _res = Py_BuildValue("O&", |
| 575 | WinObj_WhichWindow, _rv); |
| 576 | return _res; |
| 577 | } |
| 578 | |
| 579 | static PyObject *DlgObj_GetDialogDefaultItem(_self, _args) |
| 580 | DialogObject *_self; |
| 581 | PyObject *_args; |
| 582 | { |
| 583 | PyObject *_res = NULL; |
| 584 | SInt16 _rv; |
| 585 | if (!PyArg_ParseTuple(_args, "")) |
| 586 | return NULL; |
| 587 | _rv = GetDialogDefaultItem(_self->ob_itself); |
| 588 | _res = Py_BuildValue("h", |
| 589 | _rv); |
| 590 | return _res; |
| 591 | } |
| 592 | |
| 593 | static PyObject *DlgObj_GetDialogCancelItem(_self, _args) |
| 594 | DialogObject *_self; |
| 595 | PyObject *_args; |
| 596 | { |
| 597 | PyObject *_res = NULL; |
| 598 | SInt16 _rv; |
| 599 | if (!PyArg_ParseTuple(_args, "")) |
| 600 | return NULL; |
| 601 | _rv = GetDialogCancelItem(_self->ob_itself); |
| 602 | _res = Py_BuildValue("h", |
| 603 | _rv); |
| 604 | return _res; |
| 605 | } |
| 606 | |
| 607 | static PyObject *DlgObj_GetDialogKeyboardFocusItem(_self, _args) |
| 608 | DialogObject *_self; |
| 609 | PyObject *_args; |
| 610 | { |
| 611 | PyObject *_res = NULL; |
| 612 | SInt16 _rv; |
| 613 | if (!PyArg_ParseTuple(_args, "")) |
| 614 | return NULL; |
| 615 | _rv = GetDialogKeyboardFocusItem(_self->ob_itself); |
| 616 | _res = Py_BuildValue("h", |
| 617 | _rv); |
| 618 | return _res; |
| 619 | } |
| 620 | |
| 621 | static PyObject *DlgObj_SetGrafPortOfDialog(_self, _args) |
| 622 | DialogObject *_self; |
| 623 | PyObject *_args; |
| 624 | { |
| 625 | PyObject *_res = NULL; |
| 626 | if (!PyArg_ParseTuple(_args, "")) |
| 627 | return NULL; |
| 628 | SetGrafPortOfDialog(_self->ob_itself); |
| 629 | Py_INCREF(Py_None); |
| 630 | _res = Py_None; |
| 631 | return _res; |
| 632 | } |
| 633 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 634 | static PyMethodDef DlgObj_methods[] = { |
| 635 | {"DrawDialog", (PyCFunction)DlgObj_DrawDialog, 1, |
| 636 | "() -> None"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 637 | {"UpdateDialog", (PyCFunction)DlgObj_UpdateDialog, 1, |
Jack Jansen | 2b72417 | 1996-04-10 14:48:19 +0000 | [diff] [blame] | 638 | "(RgnHandle updateRgn) -> None"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 639 | {"HideDialogItem", (PyCFunction)DlgObj_HideDialogItem, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 640 | "(DialogItemIndex itemNo) -> None"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 641 | {"ShowDialogItem", (PyCFunction)DlgObj_ShowDialogItem, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 642 | "(DialogItemIndex itemNo) -> None"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 643 | {"FindDialogItem", (PyCFunction)DlgObj_FindDialogItem, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 644 | "(Point thePt) -> (DialogItemIndexZeroBased _rv)"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 645 | {"DialogCut", (PyCFunction)DlgObj_DialogCut, 1, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 646 | "() -> None"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 647 | {"DialogPaste", (PyCFunction)DlgObj_DialogPaste, 1, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 648 | "() -> None"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 649 | {"DialogCopy", (PyCFunction)DlgObj_DialogCopy, 1, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 650 | "() -> None"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 651 | {"DialogDelete", (PyCFunction)DlgObj_DialogDelete, 1, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 652 | "() -> None"}, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 653 | {"GetDialogItem", (PyCFunction)DlgObj_GetDialogItem, 1, |
| 654 | "(DialogItemIndex itemNo) -> (DialogItemType itemType, Handle item, Rect box)"}, |
| 655 | {"SetDialogItem", (PyCFunction)DlgObj_SetDialogItem, 1, |
| 656 | "(DialogItemIndex itemNo, DialogItemType itemType, Handle item, Rect box) -> None"}, |
| 657 | {"SelectDialogItemText", (PyCFunction)DlgObj_SelectDialogItemText, 1, |
| 658 | "(DialogItemIndex itemNo, SInt16 strtSel, SInt16 endSel) -> None"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 659 | {"AppendDITL", (PyCFunction)DlgObj_AppendDITL, 1, |
| 660 | "(Handle theHandle, DITLMethod method) -> None"}, |
| 661 | {"CountDITL", (PyCFunction)DlgObj_CountDITL, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 662 | "() -> (DialogItemIndex _rv)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 663 | {"ShortenDITL", (PyCFunction)DlgObj_ShortenDITL, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 664 | "(DialogItemIndex numberItems) -> None"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 665 | {"StdFilterProc", (PyCFunction)DlgObj_StdFilterProc, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 666 | "() -> (Boolean _rv, EventRecord event, DialogItemIndex itemHit)"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 667 | {"SetDialogDefaultItem", (PyCFunction)DlgObj_SetDialogDefaultItem, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 668 | "(DialogItemIndex newItem) -> None"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 669 | {"SetDialogCancelItem", (PyCFunction)DlgObj_SetDialogCancelItem, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 670 | "(DialogItemIndex newItem) -> None"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 671 | {"SetDialogTracksCursor", (PyCFunction)DlgObj_SetDialogTracksCursor, 1, |
| 672 | "(Boolean tracks) -> None"}, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 673 | {"AutoSizeDialog", (PyCFunction)DlgObj_AutoSizeDialog, 1, |
| 674 | "() -> None"}, |
| 675 | {"GetDialogItemAsControl", (PyCFunction)DlgObj_GetDialogItemAsControl, 1, |
| 676 | "(SInt16 inItemNo) -> (ControlHandle outControl)"}, |
| 677 | {"MoveDialogItem", (PyCFunction)DlgObj_MoveDialogItem, 1, |
| 678 | "(SInt16 inItemNo, SInt16 inHoriz, SInt16 inVert) -> None"}, |
| 679 | {"SizeDialogItem", (PyCFunction)DlgObj_SizeDialogItem, 1, |
Jack Jansen | 1c4e614 | 1998-04-21 15:23:55 +0000 | [diff] [blame^] | 680 | "(SInt16 inItemNo, SInt16 inWidth, SInt16 inHeight) -> None"}, |
Jack Jansen | d96cb50 | 1996-09-23 15:48:46 +0000 | [diff] [blame] | 681 | {"GetDialogWindow", (PyCFunction)DlgObj_GetDialogWindow, 1, |
| 682 | "() -> (DialogPtr _rv)"}, |
| 683 | {"GetDialogDefaultItem", (PyCFunction)DlgObj_GetDialogDefaultItem, 1, |
| 684 | "() -> (SInt16 _rv)"}, |
| 685 | {"GetDialogCancelItem", (PyCFunction)DlgObj_GetDialogCancelItem, 1, |
| 686 | "() -> (SInt16 _rv)"}, |
| 687 | {"GetDialogKeyboardFocusItem", (PyCFunction)DlgObj_GetDialogKeyboardFocusItem, 1, |
| 688 | "() -> (SInt16 _rv)"}, |
| 689 | {"SetGrafPortOfDialog", (PyCFunction)DlgObj_SetGrafPortOfDialog, 1, |
| 690 | "() -> None"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 691 | {NULL, NULL, 0} |
| 692 | }; |
| 693 | |
| 694 | PyMethodChain DlgObj_chain = { DlgObj_methods, &WinObj_chain }; |
| 695 | |
| 696 | static PyObject *DlgObj_getattr(self, name) |
| 697 | DialogObject *self; |
| 698 | char *name; |
| 699 | { |
| 700 | return Py_FindMethodInChain(&DlgObj_chain, (PyObject *)self, name); |
| 701 | } |
| 702 | |
| 703 | #define DlgObj_setattr NULL |
| 704 | |
| 705 | PyTypeObject Dialog_Type = { |
| 706 | PyObject_HEAD_INIT(&PyType_Type) |
| 707 | 0, /*ob_size*/ |
| 708 | "Dialog", /*tp_name*/ |
| 709 | sizeof(DialogObject), /*tp_basicsize*/ |
| 710 | 0, /*tp_itemsize*/ |
| 711 | /* methods */ |
| 712 | (destructor) DlgObj_dealloc, /*tp_dealloc*/ |
| 713 | 0, /*tp_print*/ |
| 714 | (getattrfunc) DlgObj_getattr, /*tp_getattr*/ |
| 715 | (setattrfunc) DlgObj_setattr, /*tp_setattr*/ |
| 716 | }; |
| 717 | |
| 718 | /* --------------------- End object type Dialog --------------------- */ |
| 719 | |
| 720 | |
| 721 | static PyObject *Dlg_NewDialog(_self, _args) |
| 722 | PyObject *_self; |
| 723 | PyObject *_args; |
| 724 | { |
| 725 | PyObject *_res = NULL; |
| 726 | DialogPtr _rv; |
| 727 | Rect boundsRect; |
| 728 | Str255 title; |
| 729 | Boolean visible; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 730 | SInt16 procID; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 731 | WindowPtr behind; |
| 732 | Boolean goAwayFlag; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 733 | SInt32 refCon; |
| 734 | Handle items; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 735 | if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&", |
| 736 | PyMac_GetRect, &boundsRect, |
| 737 | PyMac_GetStr255, title, |
| 738 | &visible, |
| 739 | &procID, |
| 740 | WinObj_Convert, &behind, |
| 741 | &goAwayFlag, |
| 742 | &refCon, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 743 | ResObj_Convert, &items)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 744 | return NULL; |
| 745 | _rv = NewDialog((void *)0, |
| 746 | &boundsRect, |
| 747 | title, |
| 748 | visible, |
| 749 | procID, |
| 750 | behind, |
| 751 | goAwayFlag, |
| 752 | refCon, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 753 | items); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 754 | _res = Py_BuildValue("O&", |
| 755 | DlgObj_New, _rv); |
| 756 | return _res; |
| 757 | } |
| 758 | |
| 759 | static PyObject *Dlg_GetNewDialog(_self, _args) |
| 760 | PyObject *_self; |
| 761 | PyObject *_args; |
| 762 | { |
| 763 | PyObject *_res = NULL; |
| 764 | DialogPtr _rv; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 765 | SInt16 dialogID; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 766 | WindowPtr behind; |
| 767 | if (!PyArg_ParseTuple(_args, "hO&", |
| 768 | &dialogID, |
| 769 | WinObj_Convert, &behind)) |
| 770 | return NULL; |
| 771 | _rv = GetNewDialog(dialogID, |
| 772 | (void *)0, |
| 773 | behind); |
| 774 | _res = Py_BuildValue("O&", |
| 775 | DlgObj_New, _rv); |
| 776 | return _res; |
| 777 | } |
| 778 | |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 779 | static PyObject *Dlg_NewColorDialog(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 780 | PyObject *_self; |
| 781 | PyObject *_args; |
| 782 | { |
| 783 | PyObject *_res = NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 784 | DialogPtr _rv; |
| 785 | Rect boundsRect; |
| 786 | Str255 title; |
| 787 | Boolean visible; |
| 788 | SInt16 procID; |
| 789 | WindowPtr behind; |
| 790 | Boolean goAwayFlag; |
| 791 | SInt32 refCon; |
| 792 | Handle items; |
| 793 | if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&", |
| 794 | PyMac_GetRect, &boundsRect, |
| 795 | PyMac_GetStr255, title, |
| 796 | &visible, |
| 797 | &procID, |
| 798 | WinObj_Convert, &behind, |
| 799 | &goAwayFlag, |
| 800 | &refCon, |
| 801 | ResObj_Convert, &items)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 802 | return NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 803 | _rv = NewColorDialog((void *)0, |
| 804 | &boundsRect, |
| 805 | title, |
| 806 | visible, |
| 807 | procID, |
| 808 | behind, |
| 809 | goAwayFlag, |
| 810 | refCon, |
| 811 | items); |
| 812 | _res = Py_BuildValue("O&", |
| 813 | DlgObj_New, _rv); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 814 | return _res; |
| 815 | } |
| 816 | |
| 817 | static PyObject *Dlg_ModalDialog(_self, _args) |
| 818 | PyObject *_self; |
| 819 | PyObject *_args; |
| 820 | { |
| 821 | PyObject *_res = NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 822 | PyObject* modalFilter; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 823 | DialogItemIndex itemHit; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 824 | if (!PyArg_ParseTuple(_args, "O", |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 825 | &modalFilter)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 826 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 827 | ModalDialog(NewModalFilterProc(Dlg_PassFilterProc(modalFilter)), |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 828 | &itemHit); |
| 829 | _res = Py_BuildValue("h", |
| 830 | itemHit); |
| 831 | return _res; |
| 832 | } |
| 833 | |
| 834 | static PyObject *Dlg_IsDialogEvent(_self, _args) |
| 835 | PyObject *_self; |
| 836 | PyObject *_args; |
| 837 | { |
| 838 | PyObject *_res = NULL; |
| 839 | Boolean _rv; |
| 840 | EventRecord theEvent; |
| 841 | if (!PyArg_ParseTuple(_args, "O&", |
| 842 | PyMac_GetEventRecord, &theEvent)) |
| 843 | return NULL; |
| 844 | _rv = IsDialogEvent(&theEvent); |
| 845 | _res = Py_BuildValue("b", |
| 846 | _rv); |
| 847 | return _res; |
| 848 | } |
| 849 | |
| 850 | static PyObject *Dlg_DialogSelect(_self, _args) |
| 851 | PyObject *_self; |
| 852 | PyObject *_args; |
| 853 | { |
| 854 | PyObject *_res = NULL; |
| 855 | Boolean _rv; |
| 856 | EventRecord theEvent; |
| 857 | DialogPtr theDialog; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 858 | DialogItemIndex itemHit; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 859 | if (!PyArg_ParseTuple(_args, "O&", |
| 860 | PyMac_GetEventRecord, &theEvent)) |
| 861 | return NULL; |
| 862 | _rv = DialogSelect(&theEvent, |
| 863 | &theDialog, |
| 864 | &itemHit); |
| 865 | _res = Py_BuildValue("bO&h", |
| 866 | _rv, |
| 867 | WinObj_WhichWindow, theDialog, |
| 868 | itemHit); |
| 869 | return _res; |
| 870 | } |
| 871 | |
| 872 | static PyObject *Dlg_Alert(_self, _args) |
| 873 | PyObject *_self; |
| 874 | PyObject *_args; |
| 875 | { |
| 876 | PyObject *_res = NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 877 | DialogItemIndex _rv; |
| 878 | SInt16 alertID; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 879 | PyObject* modalFilter; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 880 | if (!PyArg_ParseTuple(_args, "hO", |
| 881 | &alertID, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 882 | &modalFilter)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 883 | return NULL; |
| 884 | _rv = Alert(alertID, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 885 | NewModalFilterProc(Dlg_PassFilterProc(modalFilter))); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 886 | _res = Py_BuildValue("h", |
| 887 | _rv); |
| 888 | return _res; |
| 889 | } |
| 890 | |
| 891 | static PyObject *Dlg_StopAlert(_self, _args) |
| 892 | PyObject *_self; |
| 893 | PyObject *_args; |
| 894 | { |
| 895 | PyObject *_res = NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 896 | DialogItemIndex _rv; |
| 897 | SInt16 alertID; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 898 | PyObject* modalFilter; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 899 | if (!PyArg_ParseTuple(_args, "hO", |
| 900 | &alertID, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 901 | &modalFilter)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 902 | return NULL; |
| 903 | _rv = StopAlert(alertID, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 904 | NewModalFilterProc(Dlg_PassFilterProc(modalFilter))); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 905 | _res = Py_BuildValue("h", |
| 906 | _rv); |
| 907 | return _res; |
| 908 | } |
| 909 | |
| 910 | static PyObject *Dlg_NoteAlert(_self, _args) |
| 911 | PyObject *_self; |
| 912 | PyObject *_args; |
| 913 | { |
| 914 | PyObject *_res = NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 915 | DialogItemIndex _rv; |
| 916 | SInt16 alertID; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 917 | PyObject* modalFilter; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 918 | if (!PyArg_ParseTuple(_args, "hO", |
| 919 | &alertID, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 920 | &modalFilter)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 921 | return NULL; |
| 922 | _rv = NoteAlert(alertID, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 923 | NewModalFilterProc(Dlg_PassFilterProc(modalFilter))); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 924 | _res = Py_BuildValue("h", |
| 925 | _rv); |
| 926 | return _res; |
| 927 | } |
| 928 | |
| 929 | static PyObject *Dlg_CautionAlert(_self, _args) |
| 930 | PyObject *_self; |
| 931 | PyObject *_args; |
| 932 | { |
| 933 | PyObject *_res = NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 934 | DialogItemIndex _rv; |
| 935 | SInt16 alertID; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 936 | PyObject* modalFilter; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 937 | if (!PyArg_ParseTuple(_args, "hO", |
| 938 | &alertID, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 939 | &modalFilter)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 940 | return NULL; |
| 941 | _rv = CautionAlert(alertID, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 942 | NewModalFilterProc(Dlg_PassFilterProc(modalFilter))); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 943 | _res = Py_BuildValue("h", |
| 944 | _rv); |
| 945 | return _res; |
| 946 | } |
| 947 | |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 948 | static PyObject *Dlg_ParamText(_self, _args) |
| 949 | PyObject *_self; |
| 950 | PyObject *_args; |
| 951 | { |
| 952 | PyObject *_res = NULL; |
| 953 | Str255 param0; |
| 954 | Str255 param1; |
| 955 | Str255 param2; |
| 956 | Str255 param3; |
| 957 | if (!PyArg_ParseTuple(_args, "O&O&O&O&", |
| 958 | PyMac_GetStr255, param0, |
| 959 | PyMac_GetStr255, param1, |
| 960 | PyMac_GetStr255, param2, |
| 961 | PyMac_GetStr255, param3)) |
| 962 | return NULL; |
| 963 | ParamText(param0, |
| 964 | param1, |
| 965 | param2, |
| 966 | param3); |
| 967 | Py_INCREF(Py_None); |
| 968 | _res = Py_None; |
| 969 | return _res; |
| 970 | } |
| 971 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 972 | static PyObject *Dlg_GetDialogItemText(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 973 | PyObject *_self; |
| 974 | PyObject *_args; |
| 975 | { |
| 976 | PyObject *_res = NULL; |
| 977 | Handle item; |
| 978 | Str255 text; |
| 979 | if (!PyArg_ParseTuple(_args, "O&", |
| 980 | ResObj_Convert, &item)) |
| 981 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 982 | GetDialogItemText(item, |
| 983 | text); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 984 | _res = Py_BuildValue("O&", |
| 985 | PyMac_BuildStr255, text); |
| 986 | return _res; |
| 987 | } |
| 988 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 989 | static PyObject *Dlg_SetDialogItemText(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 990 | PyObject *_self; |
| 991 | PyObject *_args; |
| 992 | { |
| 993 | PyObject *_res = NULL; |
| 994 | Handle item; |
| 995 | Str255 text; |
| 996 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 997 | ResObj_Convert, &item, |
| 998 | PyMac_GetStr255, text)) |
| 999 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 1000 | SetDialogItemText(item, |
| 1001 | text); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1002 | Py_INCREF(Py_None); |
| 1003 | _res = Py_None; |
| 1004 | return _res; |
| 1005 | } |
| 1006 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 1007 | static PyObject *Dlg_GetAlertStage(_self, _args) |
| 1008 | PyObject *_self; |
| 1009 | PyObject *_args; |
| 1010 | { |
| 1011 | PyObject *_res = NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1012 | SInt16 _rv; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 1013 | if (!PyArg_ParseTuple(_args, "")) |
| 1014 | return NULL; |
| 1015 | _rv = GetAlertStage(); |
| 1016 | _res = Py_BuildValue("h", |
| 1017 | _rv); |
| 1018 | return _res; |
| 1019 | } |
| 1020 | |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1021 | static PyObject *Dlg_SetDialogFont(_self, _args) |
| 1022 | PyObject *_self; |
| 1023 | PyObject *_args; |
| 1024 | { |
| 1025 | PyObject *_res = NULL; |
| 1026 | SInt16 value; |
| 1027 | if (!PyArg_ParseTuple(_args, "h", |
| 1028 | &value)) |
| 1029 | return NULL; |
| 1030 | SetDialogFont(value); |
| 1031 | Py_INCREF(Py_None); |
| 1032 | _res = Py_None; |
| 1033 | return _res; |
| 1034 | } |
| 1035 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 1036 | static PyObject *Dlg_ResetAlertStage(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1037 | PyObject *_self; |
| 1038 | PyObject *_args; |
| 1039 | { |
| 1040 | PyObject *_res = NULL; |
| 1041 | if (!PyArg_ParseTuple(_args, "")) |
| 1042 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 1043 | ResetAlertStage(); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1044 | Py_INCREF(Py_None); |
| 1045 | _res = Py_None; |
| 1046 | return _res; |
| 1047 | } |
| 1048 | |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1049 | static PyObject *Dlg_NewFeaturesDialog(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1050 | PyObject *_self; |
| 1051 | PyObject *_args; |
| 1052 | { |
| 1053 | PyObject *_res = NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1054 | DialogPtr _rv; |
| 1055 | Rect inBoundsRect; |
| 1056 | Str255 inTitle; |
| 1057 | Boolean inIsVisible; |
| 1058 | SInt16 inProcID; |
| 1059 | WindowPtr inBehind; |
| 1060 | Boolean inGoAwayFlag; |
| 1061 | SInt32 inRefCon; |
| 1062 | Handle inItemListHandle; |
| 1063 | UInt32 inFlags; |
| 1064 | if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&l", |
| 1065 | PyMac_GetRect, &inBoundsRect, |
| 1066 | PyMac_GetStr255, inTitle, |
| 1067 | &inIsVisible, |
| 1068 | &inProcID, |
| 1069 | WinObj_Convert, &inBehind, |
| 1070 | &inGoAwayFlag, |
| 1071 | &inRefCon, |
| 1072 | ResObj_Convert, &inItemListHandle, |
| 1073 | &inFlags)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1074 | return NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1075 | _rv = NewFeaturesDialog((void *)0, |
| 1076 | &inBoundsRect, |
| 1077 | inTitle, |
| 1078 | inIsVisible, |
| 1079 | inProcID, |
| 1080 | inBehind, |
| 1081 | inGoAwayFlag, |
| 1082 | inRefCon, |
| 1083 | inItemListHandle, |
| 1084 | inFlags); |
| 1085 | _res = Py_BuildValue("O&", |
| 1086 | DlgObj_New, _rv); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1087 | return _res; |
| 1088 | } |
| 1089 | |
| 1090 | static PyMethodDef Dlg_methods[] = { |
| 1091 | {"NewDialog", (PyCFunction)Dlg_NewDialog, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1092 | "(Rect boundsRect, Str255 title, Boolean visible, SInt16 procID, WindowPtr behind, Boolean goAwayFlag, SInt32 refCon, Handle items) -> (DialogPtr _rv)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1093 | {"GetNewDialog", (PyCFunction)Dlg_GetNewDialog, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1094 | "(SInt16 dialogID, WindowPtr behind) -> (DialogPtr _rv)"}, |
| 1095 | {"NewColorDialog", (PyCFunction)Dlg_NewColorDialog, 1, |
| 1096 | "(Rect boundsRect, Str255 title, Boolean visible, SInt16 procID, WindowPtr behind, Boolean goAwayFlag, SInt32 refCon, Handle items) -> (DialogPtr _rv)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1097 | {"ModalDialog", (PyCFunction)Dlg_ModalDialog, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1098 | "(PyObject* modalFilter) -> (DialogItemIndex itemHit)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1099 | {"IsDialogEvent", (PyCFunction)Dlg_IsDialogEvent, 1, |
| 1100 | "(EventRecord theEvent) -> (Boolean _rv)"}, |
| 1101 | {"DialogSelect", (PyCFunction)Dlg_DialogSelect, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1102 | "(EventRecord theEvent) -> (Boolean _rv, DialogPtr theDialog, DialogItemIndex itemHit)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1103 | {"Alert", (PyCFunction)Dlg_Alert, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1104 | "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1105 | {"StopAlert", (PyCFunction)Dlg_StopAlert, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1106 | "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1107 | {"NoteAlert", (PyCFunction)Dlg_NoteAlert, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1108 | "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1109 | {"CautionAlert", (PyCFunction)Dlg_CautionAlert, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1110 | "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"}, |
| 1111 | {"ParamText", (PyCFunction)Dlg_ParamText, 1, |
| 1112 | "(Str255 param0, Str255 param1, Str255 param2, Str255 param3) -> None"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 1113 | {"GetDialogItemText", (PyCFunction)Dlg_GetDialogItemText, 1, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1114 | "(Handle item) -> (Str255 text)"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 1115 | {"SetDialogItemText", (PyCFunction)Dlg_SetDialogItemText, 1, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1116 | "(Handle item, Str255 text) -> None"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 1117 | {"GetAlertStage", (PyCFunction)Dlg_GetAlertStage, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1118 | "() -> (SInt16 _rv)"}, |
| 1119 | {"SetDialogFont", (PyCFunction)Dlg_SetDialogFont, 1, |
| 1120 | "(SInt16 value) -> None"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 1121 | {"ResetAlertStage", (PyCFunction)Dlg_ResetAlertStage, 1, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1122 | "() -> None"}, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1123 | {"NewFeaturesDialog", (PyCFunction)Dlg_NewFeaturesDialog, 1, |
| 1124 | "(Rect inBoundsRect, Str255 inTitle, Boolean inIsVisible, SInt16 inProcID, WindowPtr inBehind, Boolean inGoAwayFlag, SInt32 inRefCon, Handle inItemListHandle, UInt32 inFlags) -> (DialogPtr _rv)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1125 | {NULL, NULL, 0} |
| 1126 | }; |
| 1127 | |
| 1128 | |
| 1129 | |
| 1130 | |
| 1131 | void initDlg() |
| 1132 | { |
| 1133 | PyObject *m; |
| 1134 | PyObject *d; |
| 1135 | |
| 1136 | |
| 1137 | |
| 1138 | |
| 1139 | m = Py_InitModule("Dlg", Dlg_methods); |
| 1140 | d = PyModule_GetDict(m); |
| 1141 | Dlg_Error = PyMac_GetOSErrException(); |
| 1142 | if (Dlg_Error == NULL || |
| 1143 | PyDict_SetItemString(d, "Error", Dlg_Error) != 0) |
| 1144 | Py_FatalError("can't initialize Dlg.Error"); |
Jack Jansen | a755e68 | 1997-09-20 17:40:22 +0000 | [diff] [blame] | 1145 | Dialog_Type.ob_type = &PyType_Type; |
| 1146 | Py_INCREF(&Dialog_Type); |
| 1147 | if (PyDict_SetItemString(d, "DialogType", (PyObject *)&Dialog_Type) != 0) |
| 1148 | Py_FatalError("can't initialize DialogType"); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1149 | } |
| 1150 | |
| 1151 | /* ========================= End module Dlg ========================= */ |
| 1152 | |