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 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 8 | #include "macglue.h" |
Jack Jansen | 9d8b96c | 2000-07-14 22:16:45 +0000 | [diff] [blame] | 9 | #include "pymactoolbox.h" |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 10 | |
| 11 | #include <Dialogs.h> |
| 12 | |
Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame] | 13 | #if !ACCESSOR_CALLS_ARE_FUNCTIONS |
| 14 | #define GetDialogTextEditHandle(dlg) (((DialogPeek)(dlg))->textH) |
| 15 | #define SetPortDialogPort(dlg) SetPort(dlg) |
| 16 | #define GetDialogPort(dlg) ((CGrafPtr)(dlg)) |
| 17 | #define GetDialogFromWindow(win) ((DialogRef)(win)) |
| 18 | #endif |
| 19 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 20 | /* XXX Shouldn't this be a stack? */ |
| 21 | static PyObject *Dlg_FilterProc_callback = NULL; |
| 22 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 23 | static pascal Boolean Dlg_UnivFilterProc(DialogPtr dialog, |
| 24 | EventRecord *event, |
| 25 | short *itemHit) |
| 26 | { |
| 27 | Boolean rv; |
| 28 | PyObject *args, *res; |
| 29 | PyObject *callback = Dlg_FilterProc_callback; |
| 30 | if (callback == NULL) |
| 31 | return 0; /* Default behavior */ |
| 32 | Dlg_FilterProc_callback = NULL; /* We'll restore it when call successful */ |
Jack Jansen | 69e7f11 | 2001-02-06 16:14:54 +0000 | [diff] [blame^] | 33 | args = Py_BuildValue("O&O&", DlgObj_WhichDialog, dialog, PyMac_BuildEventRecord, event); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 34 | if (args == NULL) |
| 35 | res = NULL; |
| 36 | else { |
| 37 | res = PyEval_CallObject(callback, args); |
| 38 | Py_DECREF(args); |
| 39 | } |
| 40 | if (res == NULL) { |
Jack Jansen | deff89c | 1998-10-12 20:53:15 +0000 | [diff] [blame] | 41 | PySys_WriteStderr("Exception in Dialog Filter\n"); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 42 | PyErr_Print(); |
| 43 | *itemHit = -1; /* Fake return item */ |
| 44 | return 1; /* We handled it */ |
| 45 | } |
| 46 | else { |
| 47 | Dlg_FilterProc_callback = callback; |
| 48 | if (PyInt_Check(res)) { |
| 49 | *itemHit = PyInt_AsLong(res); |
| 50 | rv = 1; |
| 51 | } |
| 52 | else |
| 53 | rv = PyObject_IsTrue(res); |
| 54 | } |
| 55 | Py_DECREF(res); |
| 56 | return rv; |
| 57 | } |
| 58 | |
| 59 | static ModalFilterProcPtr |
| 60 | Dlg_PassFilterProc(PyObject *callback) |
| 61 | { |
| 62 | PyObject *tmp = Dlg_FilterProc_callback; |
| 63 | Dlg_FilterProc_callback = NULL; |
| 64 | if (callback == Py_None) { |
| 65 | Py_XDECREF(tmp); |
| 66 | return NULL; |
| 67 | } |
| 68 | Py_INCREF(callback); |
| 69 | Dlg_FilterProc_callback = callback; |
| 70 | Py_XDECREF(tmp); |
| 71 | return &Dlg_UnivFilterProc; |
| 72 | } |
| 73 | |
Jack Jansen | df901df | 1998-07-10 15:47:48 +0000 | [diff] [blame] | 74 | static PyObject *Dlg_UserItemProc_callback = NULL; |
| 75 | |
| 76 | static pascal void Dlg_UnivUserItemProc(DialogPtr dialog, |
| 77 | short item) |
| 78 | { |
| 79 | PyObject *args, *res; |
| 80 | |
| 81 | if (Dlg_UserItemProc_callback == NULL) |
| 82 | return; /* Default behavior */ |
| 83 | Dlg_FilterProc_callback = NULL; /* We'll restore it when call successful */ |
Jack Jansen | 69e7f11 | 2001-02-06 16:14:54 +0000 | [diff] [blame^] | 84 | args = Py_BuildValue("O&h", DlgObj_WhichDialog, dialog, item); |
Jack Jansen | df901df | 1998-07-10 15:47:48 +0000 | [diff] [blame] | 85 | if (args == NULL) |
| 86 | res = NULL; |
| 87 | else { |
| 88 | res = PyEval_CallObject(Dlg_UserItemProc_callback, args); |
| 89 | Py_DECREF(args); |
| 90 | } |
| 91 | if (res == NULL) { |
Jack Jansen | deff89c | 1998-10-12 20:53:15 +0000 | [diff] [blame] | 92 | PySys_WriteStderr("Exception in Dialog UserItem proc\n"); |
Jack Jansen | df901df | 1998-07-10 15:47:48 +0000 | [diff] [blame] | 93 | PyErr_Print(); |
| 94 | } |
| 95 | Py_XDECREF(res); |
| 96 | return; |
| 97 | } |
| 98 | |
Jack Jansen | 69e7f11 | 2001-02-06 16:14:54 +0000 | [diff] [blame^] | 99 | #if 0 |
Jack Jansen | b8c4c7b | 2000-08-25 22:25:54 +0000 | [diff] [blame] | 100 | /* |
| 101 | ** Treating DialogObjects as WindowObjects is (I think) illegal under Carbon. |
| 102 | ** However, as they are still identical under MacOS9 Carbon this is a problem, even |
| 103 | ** if we neatly call GetDialogWindow() at the right places: there's one refcon field |
| 104 | ** and it points to the DialogObject, so WinObj_WhichWindow will smartly return the |
| 105 | ** dialog object, and therefore we still don't have a WindowObject. |
| 106 | ** I'll leave the chaining code in place for now, with this comment to warn the |
| 107 | ** unsuspecting victims (i.e. me, probably, in a few weeks:-) |
| 108 | */ |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 109 | extern PyMethodChain WinObj_chain; |
Jack Jansen | b8c4c7b | 2000-08-25 22:25:54 +0000 | [diff] [blame] | 110 | #endif |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 111 | |
| 112 | static PyObject *Dlg_Error; |
| 113 | |
| 114 | /* ----------------------- Object type Dialog ----------------------- */ |
| 115 | |
| 116 | PyTypeObject Dialog_Type; |
| 117 | |
| 118 | #define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type) |
| 119 | |
| 120 | typedef struct DialogObject { |
| 121 | PyObject_HEAD |
| 122 | DialogPtr ob_itself; |
| 123 | } DialogObject; |
| 124 | |
| 125 | PyObject *DlgObj_New(itself) |
Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 126 | DialogPtr itself; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 127 | { |
| 128 | DialogObject *it; |
| 129 | if (itself == NULL) return Py_None; |
| 130 | it = PyObject_NEW(DialogObject, &Dialog_Type); |
| 131 | if (it == NULL) return NULL; |
| 132 | it->ob_itself = itself; |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 133 | SetWRefCon(GetDialogWindow(itself), (long)it); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 134 | return (PyObject *)it; |
| 135 | } |
| 136 | DlgObj_Convert(v, p_itself) |
| 137 | PyObject *v; |
| 138 | DialogPtr *p_itself; |
| 139 | { |
| 140 | if (v == Py_None) { *p_itself = NULL; return 1; } |
| 141 | if (PyInt_Check(v)) { *p_itself = (DialogPtr)PyInt_AsLong(v); |
| 142 | return 1; } |
| 143 | if (!DlgObj_Check(v)) |
| 144 | { |
| 145 | PyErr_SetString(PyExc_TypeError, "Dialog required"); |
| 146 | return 0; |
| 147 | } |
| 148 | *p_itself = ((DialogObject *)v)->ob_itself; |
| 149 | return 1; |
| 150 | } |
| 151 | |
| 152 | static void DlgObj_dealloc(self) |
| 153 | DialogObject *self; |
| 154 | { |
| 155 | DisposeDialog(self->ob_itself); |
| 156 | PyMem_DEL(self); |
| 157 | } |
| 158 | |
| 159 | static PyObject *DlgObj_DrawDialog(_self, _args) |
| 160 | DialogObject *_self; |
| 161 | PyObject *_args; |
| 162 | { |
| 163 | PyObject *_res = NULL; |
| 164 | if (!PyArg_ParseTuple(_args, "")) |
| 165 | return NULL; |
| 166 | DrawDialog(_self->ob_itself); |
| 167 | Py_INCREF(Py_None); |
| 168 | _res = Py_None; |
| 169 | return _res; |
| 170 | } |
| 171 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 172 | static PyObject *DlgObj_UpdateDialog(_self, _args) |
| 173 | DialogObject *_self; |
| 174 | PyObject *_args; |
| 175 | { |
| 176 | PyObject *_res = NULL; |
Jack Jansen | 2b72417 | 1996-04-10 14:48:19 +0000 | [diff] [blame] | 177 | RgnHandle updateRgn; |
| 178 | if (!PyArg_ParseTuple(_args, "O&", |
| 179 | ResObj_Convert, &updateRgn)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 180 | return NULL; |
| 181 | UpdateDialog(_self->ob_itself, |
Jack Jansen | 2b72417 | 1996-04-10 14:48:19 +0000 | [diff] [blame] | 182 | updateRgn); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 183 | Py_INCREF(Py_None); |
| 184 | _res = Py_None; |
| 185 | return _res; |
| 186 | } |
| 187 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 188 | static PyObject *DlgObj_HideDialogItem(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 189 | DialogObject *_self; |
| 190 | PyObject *_args; |
| 191 | { |
| 192 | PyObject *_res = NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 193 | DialogItemIndex itemNo; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 194 | if (!PyArg_ParseTuple(_args, "h", |
| 195 | &itemNo)) |
| 196 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 197 | HideDialogItem(_self->ob_itself, |
| 198 | itemNo); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 199 | Py_INCREF(Py_None); |
| 200 | _res = Py_None; |
| 201 | return _res; |
| 202 | } |
| 203 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 204 | static PyObject *DlgObj_ShowDialogItem(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 205 | DialogObject *_self; |
| 206 | PyObject *_args; |
| 207 | { |
| 208 | PyObject *_res = NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 209 | DialogItemIndex itemNo; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 210 | if (!PyArg_ParseTuple(_args, "h", |
| 211 | &itemNo)) |
| 212 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 213 | ShowDialogItem(_self->ob_itself, |
| 214 | itemNo); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 215 | Py_INCREF(Py_None); |
| 216 | _res = Py_None; |
| 217 | return _res; |
| 218 | } |
| 219 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 220 | static PyObject *DlgObj_FindDialogItem(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 221 | DialogObject *_self; |
| 222 | PyObject *_args; |
| 223 | { |
| 224 | PyObject *_res = NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 225 | DialogItemIndexZeroBased _rv; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 226 | Point thePt; |
| 227 | if (!PyArg_ParseTuple(_args, "O&", |
| 228 | PyMac_GetPoint, &thePt)) |
| 229 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 230 | _rv = FindDialogItem(_self->ob_itself, |
| 231 | thePt); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 232 | _res = Py_BuildValue("h", |
| 233 | _rv); |
| 234 | return _res; |
| 235 | } |
| 236 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 237 | static PyObject *DlgObj_DialogCut(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 238 | DialogObject *_self; |
| 239 | PyObject *_args; |
| 240 | { |
| 241 | PyObject *_res = NULL; |
| 242 | if (!PyArg_ParseTuple(_args, "")) |
| 243 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 244 | DialogCut(_self->ob_itself); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 245 | Py_INCREF(Py_None); |
| 246 | _res = Py_None; |
| 247 | return _res; |
| 248 | } |
| 249 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 250 | static PyObject *DlgObj_DialogPaste(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 251 | DialogObject *_self; |
| 252 | PyObject *_args; |
| 253 | { |
| 254 | PyObject *_res = NULL; |
| 255 | if (!PyArg_ParseTuple(_args, "")) |
| 256 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 257 | DialogPaste(_self->ob_itself); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 258 | Py_INCREF(Py_None); |
| 259 | _res = Py_None; |
| 260 | return _res; |
| 261 | } |
| 262 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 263 | static PyObject *DlgObj_DialogCopy(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 264 | DialogObject *_self; |
| 265 | PyObject *_args; |
| 266 | { |
| 267 | PyObject *_res = NULL; |
| 268 | if (!PyArg_ParseTuple(_args, "")) |
| 269 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 270 | DialogCopy(_self->ob_itself); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 271 | Py_INCREF(Py_None); |
| 272 | _res = Py_None; |
| 273 | return _res; |
| 274 | } |
| 275 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 276 | static PyObject *DlgObj_DialogDelete(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 277 | DialogObject *_self; |
| 278 | PyObject *_args; |
| 279 | { |
| 280 | PyObject *_res = NULL; |
| 281 | if (!PyArg_ParseTuple(_args, "")) |
| 282 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 283 | DialogDelete(_self->ob_itself); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 284 | Py_INCREF(Py_None); |
| 285 | _res = Py_None; |
| 286 | return _res; |
| 287 | } |
| 288 | |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 289 | static PyObject *DlgObj_GetDialogItem(_self, _args) |
| 290 | DialogObject *_self; |
| 291 | PyObject *_args; |
| 292 | { |
| 293 | PyObject *_res = NULL; |
| 294 | DialogItemIndex itemNo; |
| 295 | DialogItemType itemType; |
| 296 | Handle item; |
| 297 | Rect box; |
| 298 | if (!PyArg_ParseTuple(_args, "h", |
| 299 | &itemNo)) |
| 300 | return NULL; |
| 301 | GetDialogItem(_self->ob_itself, |
| 302 | itemNo, |
| 303 | &itemType, |
| 304 | &item, |
| 305 | &box); |
| 306 | _res = Py_BuildValue("hO&O&", |
| 307 | itemType, |
| 308 | OptResObj_New, item, |
| 309 | PyMac_BuildRect, &box); |
| 310 | return _res; |
| 311 | } |
| 312 | |
| 313 | static PyObject *DlgObj_SetDialogItem(_self, _args) |
| 314 | DialogObject *_self; |
| 315 | PyObject *_args; |
| 316 | { |
| 317 | PyObject *_res = NULL; |
| 318 | DialogItemIndex itemNo; |
| 319 | DialogItemType itemType; |
| 320 | Handle item; |
| 321 | Rect box; |
| 322 | if (!PyArg_ParseTuple(_args, "hhO&O&", |
| 323 | &itemNo, |
| 324 | &itemType, |
| 325 | ResObj_Convert, &item, |
| 326 | PyMac_GetRect, &box)) |
| 327 | return NULL; |
| 328 | SetDialogItem(_self->ob_itself, |
| 329 | itemNo, |
| 330 | itemType, |
| 331 | item, |
| 332 | &box); |
| 333 | Py_INCREF(Py_None); |
| 334 | _res = Py_None; |
| 335 | return _res; |
| 336 | } |
| 337 | |
| 338 | static PyObject *DlgObj_SelectDialogItemText(_self, _args) |
| 339 | DialogObject *_self; |
| 340 | PyObject *_args; |
| 341 | { |
| 342 | PyObject *_res = NULL; |
| 343 | DialogItemIndex itemNo; |
| 344 | SInt16 strtSel; |
| 345 | SInt16 endSel; |
| 346 | if (!PyArg_ParseTuple(_args, "hhh", |
| 347 | &itemNo, |
| 348 | &strtSel, |
| 349 | &endSel)) |
| 350 | return NULL; |
| 351 | SelectDialogItemText(_self->ob_itself, |
| 352 | itemNo, |
| 353 | strtSel, |
| 354 | endSel); |
| 355 | Py_INCREF(Py_None); |
| 356 | _res = Py_None; |
| 357 | return _res; |
| 358 | } |
| 359 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 360 | static PyObject *DlgObj_AppendDITL(_self, _args) |
| 361 | DialogObject *_self; |
| 362 | PyObject *_args; |
| 363 | { |
| 364 | PyObject *_res = NULL; |
| 365 | Handle theHandle; |
| 366 | DITLMethod method; |
| 367 | if (!PyArg_ParseTuple(_args, "O&h", |
| 368 | ResObj_Convert, &theHandle, |
| 369 | &method)) |
| 370 | return NULL; |
| 371 | AppendDITL(_self->ob_itself, |
| 372 | theHandle, |
| 373 | method); |
| 374 | Py_INCREF(Py_None); |
| 375 | _res = Py_None; |
| 376 | return _res; |
| 377 | } |
| 378 | |
| 379 | static PyObject *DlgObj_CountDITL(_self, _args) |
| 380 | DialogObject *_self; |
| 381 | PyObject *_args; |
| 382 | { |
| 383 | PyObject *_res = NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 384 | DialogItemIndex _rv; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 385 | if (!PyArg_ParseTuple(_args, "")) |
| 386 | return NULL; |
| 387 | _rv = CountDITL(_self->ob_itself); |
| 388 | _res = Py_BuildValue("h", |
| 389 | _rv); |
| 390 | return _res; |
| 391 | } |
| 392 | |
| 393 | static PyObject *DlgObj_ShortenDITL(_self, _args) |
| 394 | DialogObject *_self; |
| 395 | PyObject *_args; |
| 396 | { |
| 397 | PyObject *_res = NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 398 | DialogItemIndex numberItems; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 399 | if (!PyArg_ParseTuple(_args, "h", |
| 400 | &numberItems)) |
| 401 | return NULL; |
| 402 | ShortenDITL(_self->ob_itself, |
| 403 | numberItems); |
| 404 | Py_INCREF(Py_None); |
| 405 | _res = Py_None; |
| 406 | return _res; |
| 407 | } |
| 408 | |
Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame] | 409 | #if TARGET_API_MAC_CARBON |
| 410 | |
| 411 | static PyObject *DlgObj_InsertDialogItem(_self, _args) |
| 412 | DialogObject *_self; |
| 413 | PyObject *_args; |
| 414 | { |
| 415 | PyObject *_res = NULL; |
| 416 | OSStatus _err; |
| 417 | DialogItemIndex afterItem; |
| 418 | DialogItemType itemType; |
| 419 | Handle itemHandle; |
| 420 | Rect box; |
| 421 | if (!PyArg_ParseTuple(_args, "hhO&O&", |
| 422 | &afterItem, |
| 423 | &itemType, |
| 424 | ResObj_Convert, &itemHandle, |
| 425 | PyMac_GetRect, &box)) |
| 426 | return NULL; |
| 427 | _err = InsertDialogItem(_self->ob_itself, |
| 428 | afterItem, |
| 429 | itemType, |
| 430 | itemHandle, |
| 431 | &box); |
| 432 | if (_err != noErr) return PyMac_Error(_err); |
| 433 | Py_INCREF(Py_None); |
| 434 | _res = Py_None; |
| 435 | return _res; |
| 436 | } |
| 437 | #endif |
| 438 | |
| 439 | #if TARGET_API_MAC_CARBON |
| 440 | |
| 441 | static PyObject *DlgObj_RemoveDialogItems(_self, _args) |
| 442 | DialogObject *_self; |
| 443 | PyObject *_args; |
| 444 | { |
| 445 | PyObject *_res = NULL; |
| 446 | OSStatus _err; |
| 447 | DialogItemIndex itemNo; |
| 448 | DialogItemIndex amountToRemove; |
| 449 | Boolean disposeItemData; |
| 450 | if (!PyArg_ParseTuple(_args, "hhb", |
| 451 | &itemNo, |
| 452 | &amountToRemove, |
| 453 | &disposeItemData)) |
| 454 | return NULL; |
| 455 | _err = RemoveDialogItems(_self->ob_itself, |
| 456 | itemNo, |
| 457 | amountToRemove, |
| 458 | disposeItemData); |
| 459 | if (_err != noErr) return PyMac_Error(_err); |
| 460 | Py_INCREF(Py_None); |
| 461 | _res = Py_None; |
| 462 | return _res; |
| 463 | } |
| 464 | #endif |
| 465 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 466 | static PyObject *DlgObj_StdFilterProc(_self, _args) |
| 467 | DialogObject *_self; |
| 468 | PyObject *_args; |
| 469 | { |
| 470 | PyObject *_res = NULL; |
| 471 | Boolean _rv; |
| 472 | EventRecord event; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 473 | DialogItemIndex itemHit; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 474 | if (!PyArg_ParseTuple(_args, "")) |
| 475 | return NULL; |
| 476 | _rv = StdFilterProc(_self->ob_itself, |
| 477 | &event, |
| 478 | &itemHit); |
| 479 | _res = Py_BuildValue("bO&h", |
| 480 | _rv, |
| 481 | PyMac_BuildEventRecord, &event, |
| 482 | itemHit); |
| 483 | return _res; |
| 484 | } |
| 485 | |
| 486 | static PyObject *DlgObj_SetDialogDefaultItem(_self, _args) |
| 487 | DialogObject *_self; |
| 488 | PyObject *_args; |
| 489 | { |
| 490 | PyObject *_res = NULL; |
| 491 | OSErr _err; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 492 | DialogItemIndex newItem; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 493 | if (!PyArg_ParseTuple(_args, "h", |
| 494 | &newItem)) |
| 495 | return NULL; |
| 496 | _err = SetDialogDefaultItem(_self->ob_itself, |
| 497 | newItem); |
| 498 | if (_err != noErr) return PyMac_Error(_err); |
| 499 | Py_INCREF(Py_None); |
| 500 | _res = Py_None; |
| 501 | return _res; |
| 502 | } |
| 503 | |
| 504 | static PyObject *DlgObj_SetDialogCancelItem(_self, _args) |
| 505 | DialogObject *_self; |
| 506 | PyObject *_args; |
| 507 | { |
| 508 | PyObject *_res = NULL; |
| 509 | OSErr _err; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 510 | DialogItemIndex newItem; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 511 | if (!PyArg_ParseTuple(_args, "h", |
| 512 | &newItem)) |
| 513 | return NULL; |
| 514 | _err = SetDialogCancelItem(_self->ob_itself, |
| 515 | newItem); |
| 516 | if (_err != noErr) return PyMac_Error(_err); |
| 517 | Py_INCREF(Py_None); |
| 518 | _res = Py_None; |
| 519 | return _res; |
| 520 | } |
| 521 | |
| 522 | static PyObject *DlgObj_SetDialogTracksCursor(_self, _args) |
| 523 | DialogObject *_self; |
| 524 | PyObject *_args; |
| 525 | { |
| 526 | PyObject *_res = NULL; |
| 527 | OSErr _err; |
| 528 | Boolean tracks; |
| 529 | if (!PyArg_ParseTuple(_args, "b", |
| 530 | &tracks)) |
| 531 | return NULL; |
| 532 | _err = SetDialogTracksCursor(_self->ob_itself, |
| 533 | tracks); |
| 534 | if (_err != noErr) return PyMac_Error(_err); |
| 535 | Py_INCREF(Py_None); |
| 536 | _res = Py_None; |
| 537 | return _res; |
| 538 | } |
| 539 | |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 540 | static PyObject *DlgObj_AutoSizeDialog(_self, _args) |
| 541 | DialogObject *_self; |
| 542 | PyObject *_args; |
| 543 | { |
| 544 | PyObject *_res = NULL; |
| 545 | OSErr _err; |
| 546 | if (!PyArg_ParseTuple(_args, "")) |
| 547 | return NULL; |
| 548 | _err = AutoSizeDialog(_self->ob_itself); |
| 549 | if (_err != noErr) return PyMac_Error(_err); |
| 550 | Py_INCREF(Py_None); |
| 551 | _res = Py_None; |
| 552 | return _res; |
| 553 | } |
| 554 | |
| 555 | static PyObject *DlgObj_GetDialogItemAsControl(_self, _args) |
| 556 | DialogObject *_self; |
| 557 | PyObject *_args; |
| 558 | { |
| 559 | PyObject *_res = NULL; |
| 560 | OSErr _err; |
| 561 | SInt16 inItemNo; |
| 562 | ControlHandle outControl; |
| 563 | if (!PyArg_ParseTuple(_args, "h", |
| 564 | &inItemNo)) |
| 565 | return NULL; |
| 566 | _err = GetDialogItemAsControl(_self->ob_itself, |
| 567 | inItemNo, |
| 568 | &outControl); |
| 569 | if (_err != noErr) return PyMac_Error(_err); |
| 570 | _res = Py_BuildValue("O&", |
| 571 | CtlObj_New, outControl); |
| 572 | return _res; |
| 573 | } |
| 574 | |
| 575 | static PyObject *DlgObj_MoveDialogItem(_self, _args) |
| 576 | DialogObject *_self; |
| 577 | PyObject *_args; |
| 578 | { |
| 579 | PyObject *_res = NULL; |
| 580 | OSErr _err; |
| 581 | SInt16 inItemNo; |
| 582 | SInt16 inHoriz; |
| 583 | SInt16 inVert; |
| 584 | if (!PyArg_ParseTuple(_args, "hhh", |
| 585 | &inItemNo, |
| 586 | &inHoriz, |
| 587 | &inVert)) |
| 588 | return NULL; |
| 589 | _err = MoveDialogItem(_self->ob_itself, |
| 590 | inItemNo, |
| 591 | inHoriz, |
| 592 | inVert); |
| 593 | if (_err != noErr) return PyMac_Error(_err); |
| 594 | Py_INCREF(Py_None); |
| 595 | _res = Py_None; |
| 596 | return _res; |
| 597 | } |
| 598 | |
| 599 | static PyObject *DlgObj_SizeDialogItem(_self, _args) |
| 600 | DialogObject *_self; |
| 601 | PyObject *_args; |
| 602 | { |
| 603 | PyObject *_res = NULL; |
| 604 | OSErr _err; |
| 605 | SInt16 inItemNo; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 606 | SInt16 inWidth; |
Jack Jansen | 1c4e614 | 1998-04-21 15:23:55 +0000 | [diff] [blame] | 607 | SInt16 inHeight; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 608 | if (!PyArg_ParseTuple(_args, "hhh", |
| 609 | &inItemNo, |
Jack Jansen | 1c4e614 | 1998-04-21 15:23:55 +0000 | [diff] [blame] | 610 | &inWidth, |
| 611 | &inHeight)) |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 612 | return NULL; |
| 613 | _err = SizeDialogItem(_self->ob_itself, |
| 614 | inItemNo, |
Jack Jansen | 1c4e614 | 1998-04-21 15:23:55 +0000 | [diff] [blame] | 615 | inWidth, |
| 616 | inHeight); |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 617 | if (_err != noErr) return PyMac_Error(_err); |
| 618 | Py_INCREF(Py_None); |
| 619 | _res = Py_None; |
| 620 | return _res; |
| 621 | } |
| 622 | |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 623 | static PyObject *DlgObj_AppendDialogItemList(_self, _args) |
| 624 | DialogObject *_self; |
| 625 | PyObject *_args; |
| 626 | { |
| 627 | PyObject *_res = NULL; |
| 628 | OSErr _err; |
| 629 | SInt16 ditlID; |
| 630 | DITLMethod method; |
| 631 | if (!PyArg_ParseTuple(_args, "hh", |
| 632 | &ditlID, |
| 633 | &method)) |
| 634 | return NULL; |
| 635 | _err = AppendDialogItemList(_self->ob_itself, |
| 636 | ditlID, |
| 637 | method); |
| 638 | if (_err != noErr) return PyMac_Error(_err); |
| 639 | Py_INCREF(Py_None); |
| 640 | _res = Py_None; |
| 641 | return _res; |
| 642 | } |
| 643 | |
| 644 | static PyObject *DlgObj_SetDialogTimeout(_self, _args) |
| 645 | DialogObject *_self; |
| 646 | PyObject *_args; |
| 647 | { |
| 648 | PyObject *_res = NULL; |
| 649 | OSStatus _err; |
| 650 | SInt16 inButtonToPress; |
| 651 | UInt32 inSecondsToWait; |
| 652 | if (!PyArg_ParseTuple(_args, "hl", |
| 653 | &inButtonToPress, |
| 654 | &inSecondsToWait)) |
| 655 | return NULL; |
| 656 | _err = SetDialogTimeout(_self->ob_itself, |
| 657 | inButtonToPress, |
| 658 | inSecondsToWait); |
| 659 | if (_err != noErr) return PyMac_Error(_err); |
| 660 | Py_INCREF(Py_None); |
| 661 | _res = Py_None; |
| 662 | return _res; |
| 663 | } |
| 664 | |
| 665 | static PyObject *DlgObj_GetDialogTimeout(_self, _args) |
| 666 | DialogObject *_self; |
| 667 | PyObject *_args; |
| 668 | { |
| 669 | PyObject *_res = NULL; |
| 670 | OSStatus _err; |
| 671 | SInt16 outButtonToPress; |
| 672 | UInt32 outSecondsToWait; |
| 673 | UInt32 outSecondsRemaining; |
| 674 | if (!PyArg_ParseTuple(_args, "")) |
| 675 | return NULL; |
| 676 | _err = GetDialogTimeout(_self->ob_itself, |
| 677 | &outButtonToPress, |
| 678 | &outSecondsToWait, |
| 679 | &outSecondsRemaining); |
| 680 | if (_err != noErr) return PyMac_Error(_err); |
| 681 | _res = Py_BuildValue("hll", |
| 682 | outButtonToPress, |
| 683 | outSecondsToWait, |
| 684 | outSecondsRemaining); |
| 685 | return _res; |
| 686 | } |
| 687 | |
| 688 | static PyObject *DlgObj_SetModalDialogEventMask(_self, _args) |
| 689 | DialogObject *_self; |
| 690 | PyObject *_args; |
| 691 | { |
| 692 | PyObject *_res = NULL; |
| 693 | OSStatus _err; |
| 694 | EventMask inMask; |
Jack Jansen | 0b13e7c | 2000-07-07 13:09:35 +0000 | [diff] [blame] | 695 | if (!PyArg_ParseTuple(_args, "H", |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 696 | &inMask)) |
| 697 | return NULL; |
| 698 | _err = SetModalDialogEventMask(_self->ob_itself, |
| 699 | inMask); |
| 700 | if (_err != noErr) return PyMac_Error(_err); |
| 701 | Py_INCREF(Py_None); |
| 702 | _res = Py_None; |
| 703 | return _res; |
| 704 | } |
| 705 | |
| 706 | static PyObject *DlgObj_GetModalDialogEventMask(_self, _args) |
| 707 | DialogObject *_self; |
| 708 | PyObject *_args; |
| 709 | { |
| 710 | PyObject *_res = NULL; |
| 711 | OSStatus _err; |
| 712 | EventMask outMask; |
| 713 | if (!PyArg_ParseTuple(_args, "")) |
| 714 | return NULL; |
| 715 | _err = GetModalDialogEventMask(_self->ob_itself, |
| 716 | &outMask); |
| 717 | if (_err != noErr) return PyMac_Error(_err); |
Jack Jansen | 0b13e7c | 2000-07-07 13:09:35 +0000 | [diff] [blame] | 718 | _res = Py_BuildValue("H", |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 719 | outMask); |
| 720 | return _res; |
| 721 | } |
| 722 | |
Jack Jansen | d96cb50 | 1996-09-23 15:48:46 +0000 | [diff] [blame] | 723 | static PyObject *DlgObj_GetDialogWindow(_self, _args) |
| 724 | DialogObject *_self; |
| 725 | PyObject *_args; |
| 726 | { |
| 727 | PyObject *_res = NULL; |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 728 | WindowPtr _rv; |
Jack Jansen | d96cb50 | 1996-09-23 15:48:46 +0000 | [diff] [blame] | 729 | if (!PyArg_ParseTuple(_args, "")) |
| 730 | return NULL; |
| 731 | _rv = GetDialogWindow(_self->ob_itself); |
| 732 | _res = Py_BuildValue("O&", |
Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame] | 733 | WinObj_New, _rv); |
| 734 | return _res; |
| 735 | } |
| 736 | |
| 737 | static PyObject *DlgObj_GetDialogTextEditHandle(_self, _args) |
| 738 | DialogObject *_self; |
| 739 | PyObject *_args; |
| 740 | { |
| 741 | PyObject *_res = NULL; |
| 742 | TEHandle _rv; |
| 743 | if (!PyArg_ParseTuple(_args, "")) |
| 744 | return NULL; |
| 745 | _rv = GetDialogTextEditHandle(_self->ob_itself); |
| 746 | _res = Py_BuildValue("O&", |
| 747 | ResObj_New, _rv); |
Jack Jansen | d96cb50 | 1996-09-23 15:48:46 +0000 | [diff] [blame] | 748 | return _res; |
| 749 | } |
| 750 | |
| 751 | static PyObject *DlgObj_GetDialogDefaultItem(_self, _args) |
| 752 | DialogObject *_self; |
| 753 | PyObject *_args; |
| 754 | { |
| 755 | PyObject *_res = NULL; |
| 756 | SInt16 _rv; |
| 757 | if (!PyArg_ParseTuple(_args, "")) |
| 758 | return NULL; |
| 759 | _rv = GetDialogDefaultItem(_self->ob_itself); |
| 760 | _res = Py_BuildValue("h", |
| 761 | _rv); |
| 762 | return _res; |
| 763 | } |
| 764 | |
| 765 | static PyObject *DlgObj_GetDialogCancelItem(_self, _args) |
| 766 | DialogObject *_self; |
| 767 | PyObject *_args; |
| 768 | { |
| 769 | PyObject *_res = NULL; |
| 770 | SInt16 _rv; |
| 771 | if (!PyArg_ParseTuple(_args, "")) |
| 772 | return NULL; |
| 773 | _rv = GetDialogCancelItem(_self->ob_itself); |
| 774 | _res = Py_BuildValue("h", |
| 775 | _rv); |
| 776 | return _res; |
| 777 | } |
| 778 | |
| 779 | static PyObject *DlgObj_GetDialogKeyboardFocusItem(_self, _args) |
| 780 | DialogObject *_self; |
| 781 | PyObject *_args; |
| 782 | { |
| 783 | PyObject *_res = NULL; |
| 784 | SInt16 _rv; |
| 785 | if (!PyArg_ParseTuple(_args, "")) |
| 786 | return NULL; |
| 787 | _rv = GetDialogKeyboardFocusItem(_self->ob_itself); |
| 788 | _res = Py_BuildValue("h", |
| 789 | _rv); |
| 790 | return _res; |
| 791 | } |
| 792 | |
Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame] | 793 | static PyObject *DlgObj_SetPortDialogPort(_self, _args) |
| 794 | DialogObject *_self; |
| 795 | PyObject *_args; |
| 796 | { |
| 797 | PyObject *_res = NULL; |
| 798 | if (!PyArg_ParseTuple(_args, "")) |
| 799 | return NULL; |
| 800 | SetPortDialogPort(_self->ob_itself); |
| 801 | Py_INCREF(Py_None); |
| 802 | _res = Py_None; |
| 803 | return _res; |
| 804 | } |
| 805 | |
| 806 | static PyObject *DlgObj_GetDialogPort(_self, _args) |
| 807 | DialogObject *_self; |
| 808 | PyObject *_args; |
| 809 | { |
| 810 | PyObject *_res = NULL; |
| 811 | CGrafPtr _rv; |
| 812 | if (!PyArg_ParseTuple(_args, "")) |
| 813 | return NULL; |
| 814 | _rv = GetDialogPort(_self->ob_itself); |
| 815 | _res = Py_BuildValue("O&", |
| 816 | GrafObj_New, _rv); |
| 817 | return _res; |
| 818 | } |
| 819 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 820 | #if !TARGET_API_MAC_CARBON |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 821 | |
Jack Jansen | d96cb50 | 1996-09-23 15:48:46 +0000 | [diff] [blame] | 822 | static PyObject *DlgObj_SetGrafPortOfDialog(_self, _args) |
| 823 | DialogObject *_self; |
| 824 | PyObject *_args; |
| 825 | { |
| 826 | PyObject *_res = NULL; |
| 827 | if (!PyArg_ParseTuple(_args, "")) |
| 828 | return NULL; |
| 829 | SetGrafPortOfDialog(_self->ob_itself); |
| 830 | Py_INCREF(Py_None); |
| 831 | _res = Py_None; |
| 832 | return _res; |
| 833 | } |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 834 | #endif |
Jack Jansen | d96cb50 | 1996-09-23 15:48:46 +0000 | [diff] [blame] | 835 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 836 | static PyMethodDef DlgObj_methods[] = { |
| 837 | {"DrawDialog", (PyCFunction)DlgObj_DrawDialog, 1, |
| 838 | "() -> None"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 839 | {"UpdateDialog", (PyCFunction)DlgObj_UpdateDialog, 1, |
Jack Jansen | 2b72417 | 1996-04-10 14:48:19 +0000 | [diff] [blame] | 840 | "(RgnHandle updateRgn) -> None"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 841 | {"HideDialogItem", (PyCFunction)DlgObj_HideDialogItem, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 842 | "(DialogItemIndex itemNo) -> None"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 843 | {"ShowDialogItem", (PyCFunction)DlgObj_ShowDialogItem, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 844 | "(DialogItemIndex itemNo) -> None"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 845 | {"FindDialogItem", (PyCFunction)DlgObj_FindDialogItem, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 846 | "(Point thePt) -> (DialogItemIndexZeroBased _rv)"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 847 | {"DialogCut", (PyCFunction)DlgObj_DialogCut, 1, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 848 | "() -> None"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 849 | {"DialogPaste", (PyCFunction)DlgObj_DialogPaste, 1, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 850 | "() -> None"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 851 | {"DialogCopy", (PyCFunction)DlgObj_DialogCopy, 1, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 852 | "() -> None"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 853 | {"DialogDelete", (PyCFunction)DlgObj_DialogDelete, 1, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 854 | "() -> None"}, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 855 | {"GetDialogItem", (PyCFunction)DlgObj_GetDialogItem, 1, |
| 856 | "(DialogItemIndex itemNo) -> (DialogItemType itemType, Handle item, Rect box)"}, |
| 857 | {"SetDialogItem", (PyCFunction)DlgObj_SetDialogItem, 1, |
| 858 | "(DialogItemIndex itemNo, DialogItemType itemType, Handle item, Rect box) -> None"}, |
| 859 | {"SelectDialogItemText", (PyCFunction)DlgObj_SelectDialogItemText, 1, |
| 860 | "(DialogItemIndex itemNo, SInt16 strtSel, SInt16 endSel) -> None"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 861 | {"AppendDITL", (PyCFunction)DlgObj_AppendDITL, 1, |
| 862 | "(Handle theHandle, DITLMethod method) -> None"}, |
| 863 | {"CountDITL", (PyCFunction)DlgObj_CountDITL, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 864 | "() -> (DialogItemIndex _rv)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 865 | {"ShortenDITL", (PyCFunction)DlgObj_ShortenDITL, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 866 | "(DialogItemIndex numberItems) -> None"}, |
Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame] | 867 | |
| 868 | #if TARGET_API_MAC_CARBON |
| 869 | {"InsertDialogItem", (PyCFunction)DlgObj_InsertDialogItem, 1, |
| 870 | "(DialogItemIndex afterItem, DialogItemType itemType, Handle itemHandle, Rect box) -> None"}, |
| 871 | #endif |
| 872 | |
| 873 | #if TARGET_API_MAC_CARBON |
| 874 | {"RemoveDialogItems", (PyCFunction)DlgObj_RemoveDialogItems, 1, |
| 875 | "(DialogItemIndex itemNo, DialogItemIndex amountToRemove, Boolean disposeItemData) -> None"}, |
| 876 | #endif |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 877 | {"StdFilterProc", (PyCFunction)DlgObj_StdFilterProc, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 878 | "() -> (Boolean _rv, EventRecord event, DialogItemIndex itemHit)"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 879 | {"SetDialogDefaultItem", (PyCFunction)DlgObj_SetDialogDefaultItem, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 880 | "(DialogItemIndex newItem) -> None"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 881 | {"SetDialogCancelItem", (PyCFunction)DlgObj_SetDialogCancelItem, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 882 | "(DialogItemIndex newItem) -> None"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 883 | {"SetDialogTracksCursor", (PyCFunction)DlgObj_SetDialogTracksCursor, 1, |
| 884 | "(Boolean tracks) -> None"}, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 885 | {"AutoSizeDialog", (PyCFunction)DlgObj_AutoSizeDialog, 1, |
| 886 | "() -> None"}, |
| 887 | {"GetDialogItemAsControl", (PyCFunction)DlgObj_GetDialogItemAsControl, 1, |
| 888 | "(SInt16 inItemNo) -> (ControlHandle outControl)"}, |
| 889 | {"MoveDialogItem", (PyCFunction)DlgObj_MoveDialogItem, 1, |
| 890 | "(SInt16 inItemNo, SInt16 inHoriz, SInt16 inVert) -> None"}, |
| 891 | {"SizeDialogItem", (PyCFunction)DlgObj_SizeDialogItem, 1, |
Jack Jansen | 1c4e614 | 1998-04-21 15:23:55 +0000 | [diff] [blame] | 892 | "(SInt16 inItemNo, SInt16 inWidth, SInt16 inHeight) -> None"}, |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 893 | {"AppendDialogItemList", (PyCFunction)DlgObj_AppendDialogItemList, 1, |
| 894 | "(SInt16 ditlID, DITLMethod method) -> None"}, |
| 895 | {"SetDialogTimeout", (PyCFunction)DlgObj_SetDialogTimeout, 1, |
| 896 | "(SInt16 inButtonToPress, UInt32 inSecondsToWait) -> None"}, |
| 897 | {"GetDialogTimeout", (PyCFunction)DlgObj_GetDialogTimeout, 1, |
| 898 | "() -> (SInt16 outButtonToPress, UInt32 outSecondsToWait, UInt32 outSecondsRemaining)"}, |
| 899 | {"SetModalDialogEventMask", (PyCFunction)DlgObj_SetModalDialogEventMask, 1, |
| 900 | "(EventMask inMask) -> None"}, |
| 901 | {"GetModalDialogEventMask", (PyCFunction)DlgObj_GetModalDialogEventMask, 1, |
| 902 | "() -> (EventMask outMask)"}, |
Jack Jansen | d96cb50 | 1996-09-23 15:48:46 +0000 | [diff] [blame] | 903 | {"GetDialogWindow", (PyCFunction)DlgObj_GetDialogWindow, 1, |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 904 | "() -> (WindowPtr _rv)"}, |
Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame] | 905 | {"GetDialogTextEditHandle", (PyCFunction)DlgObj_GetDialogTextEditHandle, 1, |
| 906 | "() -> (TEHandle _rv)"}, |
Jack Jansen | d96cb50 | 1996-09-23 15:48:46 +0000 | [diff] [blame] | 907 | {"GetDialogDefaultItem", (PyCFunction)DlgObj_GetDialogDefaultItem, 1, |
| 908 | "() -> (SInt16 _rv)"}, |
| 909 | {"GetDialogCancelItem", (PyCFunction)DlgObj_GetDialogCancelItem, 1, |
| 910 | "() -> (SInt16 _rv)"}, |
| 911 | {"GetDialogKeyboardFocusItem", (PyCFunction)DlgObj_GetDialogKeyboardFocusItem, 1, |
| 912 | "() -> (SInt16 _rv)"}, |
Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame] | 913 | {"SetPortDialogPort", (PyCFunction)DlgObj_SetPortDialogPort, 1, |
| 914 | "() -> None"}, |
| 915 | {"GetDialogPort", (PyCFunction)DlgObj_GetDialogPort, 1, |
| 916 | "() -> (CGrafPtr _rv)"}, |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 917 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 918 | #if !TARGET_API_MAC_CARBON |
Jack Jansen | d96cb50 | 1996-09-23 15:48:46 +0000 | [diff] [blame] | 919 | {"SetGrafPortOfDialog", (PyCFunction)DlgObj_SetGrafPortOfDialog, 1, |
| 920 | "() -> None"}, |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 921 | #endif |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 922 | {NULL, NULL, 0} |
| 923 | }; |
| 924 | |
Jack Jansen | 69e7f11 | 2001-02-06 16:14:54 +0000 | [diff] [blame^] | 925 | PyMethodChain DlgObj_chain = { DlgObj_methods, NULL }; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 926 | |
| 927 | static PyObject *DlgObj_getattr(self, name) |
| 928 | DialogObject *self; |
| 929 | char *name; |
| 930 | { |
| 931 | return Py_FindMethodInChain(&DlgObj_chain, (PyObject *)self, name); |
| 932 | } |
| 933 | |
| 934 | #define DlgObj_setattr NULL |
| 935 | |
Jack Jansen | 69e7f11 | 2001-02-06 16:14:54 +0000 | [diff] [blame^] | 936 | static int DlgObj_compare(self, other) |
| 937 | DialogObject *self, *other; |
| 938 | { |
| 939 | if ( self->ob_itself > other->ob_itself ) return 1; |
| 940 | if ( self->ob_itself < other->ob_itself ) return -1; |
| 941 | return 0; |
| 942 | } |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 943 | |
| 944 | #define DlgObj_repr NULL |
| 945 | |
Jack Jansen | 69e7f11 | 2001-02-06 16:14:54 +0000 | [diff] [blame^] | 946 | static int DlgObj_hash(self) |
| 947 | DialogObject *self; |
| 948 | { |
| 949 | return (int)self->ob_itself; |
| 950 | } |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 951 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 952 | PyTypeObject Dialog_Type = { |
| 953 | PyObject_HEAD_INIT(&PyType_Type) |
| 954 | 0, /*ob_size*/ |
| 955 | "Dialog", /*tp_name*/ |
| 956 | sizeof(DialogObject), /*tp_basicsize*/ |
| 957 | 0, /*tp_itemsize*/ |
| 958 | /* methods */ |
| 959 | (destructor) DlgObj_dealloc, /*tp_dealloc*/ |
| 960 | 0, /*tp_print*/ |
| 961 | (getattrfunc) DlgObj_getattr, /*tp_getattr*/ |
| 962 | (setattrfunc) DlgObj_setattr, /*tp_setattr*/ |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 963 | (cmpfunc) DlgObj_compare, /*tp_compare*/ |
| 964 | (reprfunc) DlgObj_repr, /*tp_repr*/ |
| 965 | (PyNumberMethods *)0, /* tp_as_number */ |
| 966 | (PySequenceMethods *)0, /* tp_as_sequence */ |
| 967 | (PyMappingMethods *)0, /* tp_as_mapping */ |
| 968 | (hashfunc) DlgObj_hash, /*tp_hash*/ |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 969 | }; |
| 970 | |
| 971 | /* --------------------- End object type Dialog --------------------- */ |
| 972 | |
| 973 | |
| 974 | static PyObject *Dlg_NewDialog(_self, _args) |
| 975 | PyObject *_self; |
| 976 | PyObject *_args; |
| 977 | { |
| 978 | PyObject *_res = NULL; |
| 979 | DialogPtr _rv; |
| 980 | Rect boundsRect; |
| 981 | Str255 title; |
| 982 | Boolean visible; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 983 | SInt16 procID; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 984 | WindowPtr behind; |
| 985 | Boolean goAwayFlag; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 986 | SInt32 refCon; |
| 987 | Handle items; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 988 | if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&", |
| 989 | PyMac_GetRect, &boundsRect, |
| 990 | PyMac_GetStr255, title, |
| 991 | &visible, |
| 992 | &procID, |
| 993 | WinObj_Convert, &behind, |
| 994 | &goAwayFlag, |
| 995 | &refCon, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 996 | ResObj_Convert, &items)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 997 | return NULL; |
| 998 | _rv = NewDialog((void *)0, |
| 999 | &boundsRect, |
| 1000 | title, |
| 1001 | visible, |
| 1002 | procID, |
| 1003 | behind, |
| 1004 | goAwayFlag, |
| 1005 | refCon, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1006 | items); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1007 | _res = Py_BuildValue("O&", |
| 1008 | DlgObj_New, _rv); |
| 1009 | return _res; |
| 1010 | } |
| 1011 | |
| 1012 | static PyObject *Dlg_GetNewDialog(_self, _args) |
| 1013 | PyObject *_self; |
| 1014 | PyObject *_args; |
| 1015 | { |
| 1016 | PyObject *_res = NULL; |
| 1017 | DialogPtr _rv; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1018 | SInt16 dialogID; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1019 | WindowPtr behind; |
| 1020 | if (!PyArg_ParseTuple(_args, "hO&", |
| 1021 | &dialogID, |
| 1022 | WinObj_Convert, &behind)) |
| 1023 | return NULL; |
| 1024 | _rv = GetNewDialog(dialogID, |
| 1025 | (void *)0, |
| 1026 | behind); |
| 1027 | _res = Py_BuildValue("O&", |
| 1028 | DlgObj_New, _rv); |
| 1029 | return _res; |
| 1030 | } |
| 1031 | |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1032 | static PyObject *Dlg_NewColorDialog(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1033 | PyObject *_self; |
| 1034 | PyObject *_args; |
| 1035 | { |
| 1036 | PyObject *_res = NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1037 | DialogPtr _rv; |
| 1038 | Rect boundsRect; |
| 1039 | Str255 title; |
| 1040 | Boolean visible; |
| 1041 | SInt16 procID; |
| 1042 | WindowPtr behind; |
| 1043 | Boolean goAwayFlag; |
| 1044 | SInt32 refCon; |
| 1045 | Handle items; |
| 1046 | if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&", |
| 1047 | PyMac_GetRect, &boundsRect, |
| 1048 | PyMac_GetStr255, title, |
| 1049 | &visible, |
| 1050 | &procID, |
| 1051 | WinObj_Convert, &behind, |
| 1052 | &goAwayFlag, |
| 1053 | &refCon, |
| 1054 | ResObj_Convert, &items)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1055 | return NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1056 | _rv = NewColorDialog((void *)0, |
| 1057 | &boundsRect, |
| 1058 | title, |
| 1059 | visible, |
| 1060 | procID, |
| 1061 | behind, |
| 1062 | goAwayFlag, |
| 1063 | refCon, |
| 1064 | items); |
| 1065 | _res = Py_BuildValue("O&", |
| 1066 | DlgObj_New, _rv); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1067 | return _res; |
| 1068 | } |
| 1069 | |
| 1070 | static PyObject *Dlg_ModalDialog(_self, _args) |
| 1071 | PyObject *_self; |
| 1072 | PyObject *_args; |
| 1073 | { |
| 1074 | PyObject *_res = NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 1075 | PyObject* modalFilter; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1076 | DialogItemIndex itemHit; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1077 | if (!PyArg_ParseTuple(_args, "O", |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 1078 | &modalFilter)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1079 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 1080 | ModalDialog(NewModalFilterProc(Dlg_PassFilterProc(modalFilter)), |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1081 | &itemHit); |
| 1082 | _res = Py_BuildValue("h", |
| 1083 | itemHit); |
| 1084 | return _res; |
| 1085 | } |
| 1086 | |
| 1087 | static PyObject *Dlg_IsDialogEvent(_self, _args) |
| 1088 | PyObject *_self; |
| 1089 | PyObject *_args; |
| 1090 | { |
| 1091 | PyObject *_res = NULL; |
| 1092 | Boolean _rv; |
| 1093 | EventRecord theEvent; |
| 1094 | if (!PyArg_ParseTuple(_args, "O&", |
| 1095 | PyMac_GetEventRecord, &theEvent)) |
| 1096 | return NULL; |
| 1097 | _rv = IsDialogEvent(&theEvent); |
| 1098 | _res = Py_BuildValue("b", |
| 1099 | _rv); |
| 1100 | return _res; |
| 1101 | } |
| 1102 | |
| 1103 | static PyObject *Dlg_DialogSelect(_self, _args) |
| 1104 | PyObject *_self; |
| 1105 | PyObject *_args; |
| 1106 | { |
| 1107 | PyObject *_res = NULL; |
| 1108 | Boolean _rv; |
| 1109 | EventRecord theEvent; |
| 1110 | DialogPtr theDialog; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1111 | DialogItemIndex itemHit; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1112 | if (!PyArg_ParseTuple(_args, "O&", |
| 1113 | PyMac_GetEventRecord, &theEvent)) |
| 1114 | return NULL; |
| 1115 | _rv = DialogSelect(&theEvent, |
| 1116 | &theDialog, |
| 1117 | &itemHit); |
| 1118 | _res = Py_BuildValue("bO&h", |
| 1119 | _rv, |
Jack Jansen | 69e7f11 | 2001-02-06 16:14:54 +0000 | [diff] [blame^] | 1120 | DlgObj_WhichDialog, theDialog, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1121 | itemHit); |
| 1122 | return _res; |
| 1123 | } |
| 1124 | |
| 1125 | static PyObject *Dlg_Alert(_self, _args) |
| 1126 | PyObject *_self; |
| 1127 | PyObject *_args; |
| 1128 | { |
| 1129 | PyObject *_res = NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1130 | DialogItemIndex _rv; |
| 1131 | SInt16 alertID; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 1132 | PyObject* modalFilter; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1133 | if (!PyArg_ParseTuple(_args, "hO", |
| 1134 | &alertID, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 1135 | &modalFilter)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1136 | return NULL; |
| 1137 | _rv = Alert(alertID, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 1138 | NewModalFilterProc(Dlg_PassFilterProc(modalFilter))); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1139 | _res = Py_BuildValue("h", |
| 1140 | _rv); |
| 1141 | return _res; |
| 1142 | } |
| 1143 | |
| 1144 | static PyObject *Dlg_StopAlert(_self, _args) |
| 1145 | PyObject *_self; |
| 1146 | PyObject *_args; |
| 1147 | { |
| 1148 | PyObject *_res = NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1149 | DialogItemIndex _rv; |
| 1150 | SInt16 alertID; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 1151 | PyObject* modalFilter; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1152 | if (!PyArg_ParseTuple(_args, "hO", |
| 1153 | &alertID, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 1154 | &modalFilter)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1155 | return NULL; |
| 1156 | _rv = StopAlert(alertID, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 1157 | NewModalFilterProc(Dlg_PassFilterProc(modalFilter))); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1158 | _res = Py_BuildValue("h", |
| 1159 | _rv); |
| 1160 | return _res; |
| 1161 | } |
| 1162 | |
| 1163 | static PyObject *Dlg_NoteAlert(_self, _args) |
| 1164 | PyObject *_self; |
| 1165 | PyObject *_args; |
| 1166 | { |
| 1167 | PyObject *_res = NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1168 | DialogItemIndex _rv; |
| 1169 | SInt16 alertID; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 1170 | PyObject* modalFilter; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1171 | if (!PyArg_ParseTuple(_args, "hO", |
| 1172 | &alertID, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 1173 | &modalFilter)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1174 | return NULL; |
| 1175 | _rv = NoteAlert(alertID, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 1176 | NewModalFilterProc(Dlg_PassFilterProc(modalFilter))); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1177 | _res = Py_BuildValue("h", |
| 1178 | _rv); |
| 1179 | return _res; |
| 1180 | } |
| 1181 | |
| 1182 | static PyObject *Dlg_CautionAlert(_self, _args) |
| 1183 | PyObject *_self; |
| 1184 | PyObject *_args; |
| 1185 | { |
| 1186 | PyObject *_res = NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1187 | DialogItemIndex _rv; |
| 1188 | SInt16 alertID; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 1189 | PyObject* modalFilter; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1190 | if (!PyArg_ParseTuple(_args, "hO", |
| 1191 | &alertID, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 1192 | &modalFilter)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1193 | return NULL; |
| 1194 | _rv = CautionAlert(alertID, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 1195 | NewModalFilterProc(Dlg_PassFilterProc(modalFilter))); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1196 | _res = Py_BuildValue("h", |
| 1197 | _rv); |
| 1198 | return _res; |
| 1199 | } |
| 1200 | |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1201 | static PyObject *Dlg_ParamText(_self, _args) |
| 1202 | PyObject *_self; |
| 1203 | PyObject *_args; |
| 1204 | { |
| 1205 | PyObject *_res = NULL; |
| 1206 | Str255 param0; |
| 1207 | Str255 param1; |
| 1208 | Str255 param2; |
| 1209 | Str255 param3; |
| 1210 | if (!PyArg_ParseTuple(_args, "O&O&O&O&", |
| 1211 | PyMac_GetStr255, param0, |
| 1212 | PyMac_GetStr255, param1, |
| 1213 | PyMac_GetStr255, param2, |
| 1214 | PyMac_GetStr255, param3)) |
| 1215 | return NULL; |
| 1216 | ParamText(param0, |
| 1217 | param1, |
| 1218 | param2, |
| 1219 | param3); |
| 1220 | Py_INCREF(Py_None); |
| 1221 | _res = Py_None; |
| 1222 | return _res; |
| 1223 | } |
| 1224 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 1225 | static PyObject *Dlg_GetDialogItemText(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1226 | PyObject *_self; |
| 1227 | PyObject *_args; |
| 1228 | { |
| 1229 | PyObject *_res = NULL; |
| 1230 | Handle item; |
| 1231 | Str255 text; |
| 1232 | if (!PyArg_ParseTuple(_args, "O&", |
| 1233 | ResObj_Convert, &item)) |
| 1234 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 1235 | GetDialogItemText(item, |
| 1236 | text); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1237 | _res = Py_BuildValue("O&", |
| 1238 | PyMac_BuildStr255, text); |
| 1239 | return _res; |
| 1240 | } |
| 1241 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 1242 | static PyObject *Dlg_SetDialogItemText(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1243 | PyObject *_self; |
| 1244 | PyObject *_args; |
| 1245 | { |
| 1246 | PyObject *_res = NULL; |
| 1247 | Handle item; |
| 1248 | Str255 text; |
| 1249 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 1250 | ResObj_Convert, &item, |
| 1251 | PyMac_GetStr255, text)) |
| 1252 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 1253 | SetDialogItemText(item, |
| 1254 | text); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1255 | Py_INCREF(Py_None); |
| 1256 | _res = Py_None; |
| 1257 | return _res; |
| 1258 | } |
| 1259 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 1260 | static PyObject *Dlg_GetAlertStage(_self, _args) |
| 1261 | PyObject *_self; |
| 1262 | PyObject *_args; |
| 1263 | { |
| 1264 | PyObject *_res = NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1265 | SInt16 _rv; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 1266 | if (!PyArg_ParseTuple(_args, "")) |
| 1267 | return NULL; |
| 1268 | _rv = GetAlertStage(); |
| 1269 | _res = Py_BuildValue("h", |
| 1270 | _rv); |
| 1271 | return _res; |
| 1272 | } |
| 1273 | |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1274 | static PyObject *Dlg_SetDialogFont(_self, _args) |
| 1275 | PyObject *_self; |
| 1276 | PyObject *_args; |
| 1277 | { |
| 1278 | PyObject *_res = NULL; |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 1279 | SInt16 fontNum; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1280 | if (!PyArg_ParseTuple(_args, "h", |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 1281 | &fontNum)) |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1282 | return NULL; |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 1283 | SetDialogFont(fontNum); |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1284 | Py_INCREF(Py_None); |
| 1285 | _res = Py_None; |
| 1286 | return _res; |
| 1287 | } |
| 1288 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 1289 | static PyObject *Dlg_ResetAlertStage(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1290 | PyObject *_self; |
| 1291 | PyObject *_args; |
| 1292 | { |
| 1293 | PyObject *_res = NULL; |
| 1294 | if (!PyArg_ParseTuple(_args, "")) |
| 1295 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 1296 | ResetAlertStage(); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1297 | Py_INCREF(Py_None); |
| 1298 | _res = Py_None; |
| 1299 | return _res; |
| 1300 | } |
| 1301 | |
Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame] | 1302 | #if TARGET_API_MAC_CARBON |
| 1303 | |
| 1304 | static PyObject *Dlg_GetParamText(_self, _args) |
| 1305 | PyObject *_self; |
| 1306 | PyObject *_args; |
| 1307 | { |
| 1308 | PyObject *_res = NULL; |
| 1309 | Str255 param0; |
| 1310 | Str255 param1; |
| 1311 | Str255 param2; |
| 1312 | Str255 param3; |
| 1313 | if (!PyArg_ParseTuple(_args, "O&O&O&O&", |
| 1314 | PyMac_GetStr255, param0, |
| 1315 | PyMac_GetStr255, param1, |
| 1316 | PyMac_GetStr255, param2, |
| 1317 | PyMac_GetStr255, param3)) |
| 1318 | return NULL; |
| 1319 | GetParamText(param0, |
| 1320 | param1, |
| 1321 | param2, |
| 1322 | param3); |
| 1323 | Py_INCREF(Py_None); |
| 1324 | _res = Py_None; |
| 1325 | return _res; |
| 1326 | } |
| 1327 | #endif |
| 1328 | |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1329 | static PyObject *Dlg_NewFeaturesDialog(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1330 | PyObject *_self; |
| 1331 | PyObject *_args; |
| 1332 | { |
| 1333 | PyObject *_res = NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1334 | DialogPtr _rv; |
| 1335 | Rect inBoundsRect; |
| 1336 | Str255 inTitle; |
| 1337 | Boolean inIsVisible; |
| 1338 | SInt16 inProcID; |
| 1339 | WindowPtr inBehind; |
| 1340 | Boolean inGoAwayFlag; |
| 1341 | SInt32 inRefCon; |
| 1342 | Handle inItemListHandle; |
| 1343 | UInt32 inFlags; |
| 1344 | if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&l", |
| 1345 | PyMac_GetRect, &inBoundsRect, |
| 1346 | PyMac_GetStr255, inTitle, |
| 1347 | &inIsVisible, |
| 1348 | &inProcID, |
| 1349 | WinObj_Convert, &inBehind, |
| 1350 | &inGoAwayFlag, |
| 1351 | &inRefCon, |
| 1352 | ResObj_Convert, &inItemListHandle, |
| 1353 | &inFlags)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1354 | return NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1355 | _rv = NewFeaturesDialog((void *)0, |
| 1356 | &inBoundsRect, |
| 1357 | inTitle, |
| 1358 | inIsVisible, |
| 1359 | inProcID, |
| 1360 | inBehind, |
| 1361 | inGoAwayFlag, |
| 1362 | inRefCon, |
| 1363 | inItemListHandle, |
| 1364 | inFlags); |
| 1365 | _res = Py_BuildValue("O&", |
| 1366 | DlgObj_New, _rv); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1367 | return _res; |
| 1368 | } |
| 1369 | |
Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame] | 1370 | static PyObject *Dlg_GetDialogFromWindow(_self, _args) |
| 1371 | PyObject *_self; |
| 1372 | PyObject *_args; |
| 1373 | { |
| 1374 | PyObject *_res = NULL; |
| 1375 | DialogPtr _rv; |
| 1376 | WindowPtr window; |
| 1377 | if (!PyArg_ParseTuple(_args, "O&", |
| 1378 | WinObj_Convert, &window)) |
| 1379 | return NULL; |
| 1380 | _rv = GetDialogFromWindow(window); |
| 1381 | _res = Py_BuildValue("O&", |
| 1382 | DlgObj_New, _rv); |
| 1383 | return _res; |
| 1384 | } |
| 1385 | |
Jack Jansen | df901df | 1998-07-10 15:47:48 +0000 | [diff] [blame] | 1386 | static PyObject *Dlg_SetUserItemHandler(_self, _args) |
| 1387 | PyObject *_self; |
| 1388 | PyObject *_args; |
| 1389 | { |
| 1390 | PyObject *_res = NULL; |
| 1391 | |
| 1392 | PyObject *new = NULL; |
| 1393 | |
| 1394 | |
| 1395 | if (!PyArg_ParseTuple(_args, "|O", &new)) |
| 1396 | return NULL; |
| 1397 | |
| 1398 | if (Dlg_UserItemProc_callback && new && new != Py_None) { |
| 1399 | PyErr_SetString(Dlg_Error, "Another UserItemProc is already installed"); |
| 1400 | return NULL; |
| 1401 | } |
| 1402 | |
| 1403 | if (new == Py_None) { |
| 1404 | new = NULL; |
| 1405 | _res = Py_None; |
| 1406 | Py_INCREF(Py_None); |
| 1407 | } else { |
| 1408 | Py_INCREF(new); |
| 1409 | _res = Py_BuildValue("O&", ResObj_New, (Handle)NewUserItemProc(Dlg_UnivUserItemProc)); |
| 1410 | } |
| 1411 | |
| 1412 | Dlg_UserItemProc_callback = new; |
| 1413 | return _res; |
| 1414 | |
| 1415 | } |
| 1416 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1417 | static PyMethodDef Dlg_methods[] = { |
| 1418 | {"NewDialog", (PyCFunction)Dlg_NewDialog, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1419 | "(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] | 1420 | {"GetNewDialog", (PyCFunction)Dlg_GetNewDialog, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1421 | "(SInt16 dialogID, WindowPtr behind) -> (DialogPtr _rv)"}, |
| 1422 | {"NewColorDialog", (PyCFunction)Dlg_NewColorDialog, 1, |
| 1423 | "(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] | 1424 | {"ModalDialog", (PyCFunction)Dlg_ModalDialog, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1425 | "(PyObject* modalFilter) -> (DialogItemIndex itemHit)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1426 | {"IsDialogEvent", (PyCFunction)Dlg_IsDialogEvent, 1, |
| 1427 | "(EventRecord theEvent) -> (Boolean _rv)"}, |
| 1428 | {"DialogSelect", (PyCFunction)Dlg_DialogSelect, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1429 | "(EventRecord theEvent) -> (Boolean _rv, DialogPtr theDialog, DialogItemIndex itemHit)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1430 | {"Alert", (PyCFunction)Dlg_Alert, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1431 | "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1432 | {"StopAlert", (PyCFunction)Dlg_StopAlert, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1433 | "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1434 | {"NoteAlert", (PyCFunction)Dlg_NoteAlert, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1435 | "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1436 | {"CautionAlert", (PyCFunction)Dlg_CautionAlert, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1437 | "(SInt16 alertID, PyObject* modalFilter) -> (DialogItemIndex _rv)"}, |
| 1438 | {"ParamText", (PyCFunction)Dlg_ParamText, 1, |
| 1439 | "(Str255 param0, Str255 param1, Str255 param2, Str255 param3) -> None"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 1440 | {"GetDialogItemText", (PyCFunction)Dlg_GetDialogItemText, 1, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1441 | "(Handle item) -> (Str255 text)"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 1442 | {"SetDialogItemText", (PyCFunction)Dlg_SetDialogItemText, 1, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1443 | "(Handle item, Str255 text) -> None"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 1444 | {"GetAlertStage", (PyCFunction)Dlg_GetAlertStage, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1445 | "() -> (SInt16 _rv)"}, |
| 1446 | {"SetDialogFont", (PyCFunction)Dlg_SetDialogFont, 1, |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 1447 | "(SInt16 fontNum) -> None"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 1448 | {"ResetAlertStage", (PyCFunction)Dlg_ResetAlertStage, 1, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1449 | "() -> None"}, |
Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame] | 1450 | |
| 1451 | #if TARGET_API_MAC_CARBON |
| 1452 | {"GetParamText", (PyCFunction)Dlg_GetParamText, 1, |
| 1453 | "(Str255 param0, Str255 param1, Str255 param2, Str255 param3) -> None"}, |
| 1454 | #endif |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1455 | {"NewFeaturesDialog", (PyCFunction)Dlg_NewFeaturesDialog, 1, |
| 1456 | "(Rect inBoundsRect, Str255 inTitle, Boolean inIsVisible, SInt16 inProcID, WindowPtr inBehind, Boolean inGoAwayFlag, SInt32 inRefCon, Handle inItemListHandle, UInt32 inFlags) -> (DialogPtr _rv)"}, |
Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame] | 1457 | {"GetDialogFromWindow", (PyCFunction)Dlg_GetDialogFromWindow, 1, |
| 1458 | "(WindowPtr window) -> (DialogPtr _rv)"}, |
Jack Jansen | df901df | 1998-07-10 15:47:48 +0000 | [diff] [blame] | 1459 | {"SetUserItemHandler", (PyCFunction)Dlg_SetUserItemHandler, 1, |
| 1460 | NULL}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1461 | {NULL, NULL, 0} |
| 1462 | }; |
| 1463 | |
| 1464 | |
| 1465 | |
Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame] | 1466 | /* Return the WindowPtr corresponding to a DialogObject */ |
| 1467 | |
| 1468 | WindowPtr |
| 1469 | DlgObj_ConvertToWindow(self) |
| 1470 | PyObject *self; |
| 1471 | { |
| 1472 | if ( DlgObj_Check(self) ) |
| 1473 | return GetDialogWindow(((DialogObject *)self)->ob_itself); |
| 1474 | return NULL; |
| 1475 | } |
Jack Jansen | 69e7f11 | 2001-02-06 16:14:54 +0000 | [diff] [blame^] | 1476 | /* Return the object corresponding to the dialog, or None */ |
| 1477 | |
| 1478 | PyObject * |
| 1479 | DlgObj_WhichDialog(d) |
| 1480 | DialogPtr d; |
| 1481 | { |
| 1482 | PyObject *it; |
| 1483 | |
| 1484 | if (d == NULL) { |
| 1485 | it = Py_None; |
| 1486 | Py_INCREF(it); |
| 1487 | } else { |
| 1488 | WindowPtr w = GetDialogWindow(d); |
| 1489 | |
| 1490 | it = (PyObject *) GetWRefCon(w); |
| 1491 | if (it == NULL || ((DialogObject *)it)->ob_itself != d || !DlgObj_Check(it)) { |
| 1492 | #if 0 |
| 1493 | /* Should do this, but we don't have an ob_freeit for dialogs yet. */ |
| 1494 | it = WinObj_New(w); |
| 1495 | ((WindowObject *)it)->ob_freeit = NULL; |
| 1496 | #else |
| 1497 | it = Py_None; |
| 1498 | Py_INCREF(it); |
| 1499 | #endif |
| 1500 | } else { |
| 1501 | Py_INCREF(it); |
| 1502 | } |
| 1503 | } |
| 1504 | return it; |
| 1505 | } |
Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame] | 1506 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1507 | |
| 1508 | void initDlg() |
| 1509 | { |
| 1510 | PyObject *m; |
| 1511 | PyObject *d; |
| 1512 | |
| 1513 | |
| 1514 | |
| 1515 | |
| 1516 | m = Py_InitModule("Dlg", Dlg_methods); |
| 1517 | d = PyModule_GetDict(m); |
| 1518 | Dlg_Error = PyMac_GetOSErrException(); |
| 1519 | if (Dlg_Error == NULL || |
| 1520 | PyDict_SetItemString(d, "Error", Dlg_Error) != 0) |
Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame] | 1521 | return; |
Jack Jansen | a755e68 | 1997-09-20 17:40:22 +0000 | [diff] [blame] | 1522 | Dialog_Type.ob_type = &PyType_Type; |
| 1523 | Py_INCREF(&Dialog_Type); |
| 1524 | if (PyDict_SetItemString(d, "DialogType", (PyObject *)&Dialog_Type) != 0) |
| 1525 | Py_FatalError("can't initialize DialogType"); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1526 | } |
| 1527 | |
| 1528 | /* ========================= End module Dlg ========================= */ |
| 1529 | |