Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1 | |
| 2 | /* =========================== Module Ctl =========================== */ |
| 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 *); |
| 18 | |
| 19 | extern PyObject *WinObj_New(WindowPtr); |
| 20 | extern int WinObj_Convert(PyObject *, WindowPtr *); |
| 21 | |
| 22 | extern PyObject *DlgObj_New(DialogPtr); |
| 23 | extern int DlgObj_Convert(PyObject *, DialogPtr *); |
| 24 | extern PyTypeObject Dialog_Type; |
| 25 | #define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type) |
| 26 | |
| 27 | extern PyObject *MenuObj_New(MenuHandle); |
| 28 | extern int MenuObj_Convert(PyObject *, MenuHandle *); |
| 29 | |
| 30 | extern PyObject *CtlObj_New(ControlHandle); |
| 31 | extern int CtlObj_Convert(PyObject *, ControlHandle *); |
| 32 | |
| 33 | extern PyObject *WinObj_WhichWindow(WindowPtr); |
| 34 | |
| 35 | #include <Controls.h> |
| 36 | |
| 37 | #define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */ |
| 38 | |
| 39 | extern PyObject *CtlObj_WhichControl(ControlHandle); /* Forward */ |
| 40 | |
| 41 | #ifdef THINK_C |
| 42 | #define ControlActionUPP ProcPtr |
| 43 | #endif |
| 44 | |
| 45 | static PyObject *Ctl_Error; |
| 46 | |
| 47 | /* ---------------------- Object type Control ----------------------- */ |
| 48 | |
| 49 | PyTypeObject Control_Type; |
| 50 | |
| 51 | #define CtlObj_Check(x) ((x)->ob_type == &Control_Type) |
| 52 | |
| 53 | typedef struct ControlObject { |
| 54 | PyObject_HEAD |
| 55 | ControlHandle ob_itself; |
| 56 | } ControlObject; |
| 57 | |
| 58 | PyObject *CtlObj_New(itself) |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 59 | ControlHandle itself; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 60 | { |
| 61 | ControlObject *it; |
| 62 | if (itself == NULL) return PyMac_Error(resNotFound); |
| 63 | it = PyObject_NEW(ControlObject, &Control_Type); |
| 64 | if (it == NULL) return NULL; |
| 65 | it->ob_itself = itself; |
| 66 | SetCRefCon(itself, (long)it); |
| 67 | return (PyObject *)it; |
| 68 | } |
| 69 | CtlObj_Convert(v, p_itself) |
| 70 | PyObject *v; |
| 71 | ControlHandle *p_itself; |
| 72 | { |
| 73 | if (!CtlObj_Check(v)) |
| 74 | { |
| 75 | PyErr_SetString(PyExc_TypeError, "Control required"); |
| 76 | return 0; |
| 77 | } |
| 78 | *p_itself = ((ControlObject *)v)->ob_itself; |
| 79 | return 1; |
| 80 | } |
| 81 | |
| 82 | static void CtlObj_dealloc(self) |
| 83 | ControlObject *self; |
| 84 | { |
| 85 | /* Cleanup of self->ob_itself goes here */ |
| 86 | PyMem_DEL(self); |
| 87 | } |
| 88 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 89 | static PyObject *CtlObj_SetControlTitle(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 90 | ControlObject *_self; |
| 91 | PyObject *_args; |
| 92 | { |
| 93 | PyObject *_res = NULL; |
| 94 | Str255 title; |
| 95 | if (!PyArg_ParseTuple(_args, "O&", |
| 96 | PyMac_GetStr255, title)) |
| 97 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 98 | SetControlTitle(_self->ob_itself, |
| 99 | title); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 100 | Py_INCREF(Py_None); |
| 101 | _res = Py_None; |
| 102 | return _res; |
| 103 | } |
| 104 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 105 | static PyObject *CtlObj_GetControlTitle(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 106 | ControlObject *_self; |
| 107 | PyObject *_args; |
| 108 | { |
| 109 | PyObject *_res = NULL; |
| 110 | Str255 title; |
| 111 | if (!PyArg_ParseTuple(_args, "O&", |
| 112 | PyMac_GetStr255, title)) |
| 113 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 114 | GetControlTitle(_self->ob_itself, |
| 115 | title); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 116 | Py_INCREF(Py_None); |
| 117 | _res = Py_None; |
| 118 | return _res; |
| 119 | } |
| 120 | |
| 121 | static PyObject *CtlObj_DisposeControl(_self, _args) |
| 122 | ControlObject *_self; |
| 123 | PyObject *_args; |
| 124 | { |
| 125 | PyObject *_res = NULL; |
| 126 | if (!PyArg_ParseTuple(_args, "")) |
| 127 | return NULL; |
| 128 | DisposeControl(_self->ob_itself); |
| 129 | Py_INCREF(Py_None); |
| 130 | _res = Py_None; |
| 131 | return _res; |
| 132 | } |
| 133 | |
| 134 | static PyObject *CtlObj_HideControl(_self, _args) |
| 135 | ControlObject *_self; |
| 136 | PyObject *_args; |
| 137 | { |
| 138 | PyObject *_res = NULL; |
| 139 | if (!PyArg_ParseTuple(_args, "")) |
| 140 | return NULL; |
| 141 | HideControl(_self->ob_itself); |
| 142 | Py_INCREF(Py_None); |
| 143 | _res = Py_None; |
| 144 | return _res; |
| 145 | } |
| 146 | |
| 147 | static PyObject *CtlObj_ShowControl(_self, _args) |
| 148 | ControlObject *_self; |
| 149 | PyObject *_args; |
| 150 | { |
| 151 | PyObject *_res = NULL; |
| 152 | if (!PyArg_ParseTuple(_args, "")) |
| 153 | return NULL; |
| 154 | ShowControl(_self->ob_itself); |
| 155 | Py_INCREF(Py_None); |
| 156 | _res = Py_None; |
| 157 | return _res; |
| 158 | } |
| 159 | |
| 160 | static PyObject *CtlObj_Draw1Control(_self, _args) |
| 161 | ControlObject *_self; |
| 162 | PyObject *_args; |
| 163 | { |
| 164 | PyObject *_res = NULL; |
| 165 | if (!PyArg_ParseTuple(_args, "")) |
| 166 | return NULL; |
| 167 | Draw1Control(_self->ob_itself); |
| 168 | Py_INCREF(Py_None); |
| 169 | _res = Py_None; |
| 170 | return _res; |
| 171 | } |
| 172 | |
| 173 | static PyObject *CtlObj_HiliteControl(_self, _args) |
| 174 | ControlObject *_self; |
| 175 | PyObject *_args; |
| 176 | { |
| 177 | PyObject *_res = NULL; |
| 178 | short hiliteState; |
| 179 | if (!PyArg_ParseTuple(_args, "h", |
| 180 | &hiliteState)) |
| 181 | return NULL; |
| 182 | HiliteControl(_self->ob_itself, |
| 183 | hiliteState); |
| 184 | Py_INCREF(Py_None); |
| 185 | _res = Py_None; |
| 186 | return _res; |
| 187 | } |
| 188 | |
| 189 | static PyObject *CtlObj_MoveControl(_self, _args) |
| 190 | ControlObject *_self; |
| 191 | PyObject *_args; |
| 192 | { |
| 193 | PyObject *_res = NULL; |
| 194 | short h; |
| 195 | short v; |
| 196 | if (!PyArg_ParseTuple(_args, "hh", |
| 197 | &h, |
| 198 | &v)) |
| 199 | return NULL; |
| 200 | MoveControl(_self->ob_itself, |
| 201 | h, |
| 202 | v); |
| 203 | Py_INCREF(Py_None); |
| 204 | _res = Py_None; |
| 205 | return _res; |
| 206 | } |
| 207 | |
| 208 | static PyObject *CtlObj_SizeControl(_self, _args) |
| 209 | ControlObject *_self; |
| 210 | PyObject *_args; |
| 211 | { |
| 212 | PyObject *_res = NULL; |
| 213 | short w; |
| 214 | short h; |
| 215 | if (!PyArg_ParseTuple(_args, "hh", |
| 216 | &w, |
| 217 | &h)) |
| 218 | return NULL; |
| 219 | SizeControl(_self->ob_itself, |
| 220 | w, |
| 221 | h); |
| 222 | Py_INCREF(Py_None); |
| 223 | _res = Py_None; |
| 224 | return _res; |
| 225 | } |
| 226 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 227 | static PyObject *CtlObj_SetControlValue(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 228 | ControlObject *_self; |
| 229 | PyObject *_args; |
| 230 | { |
| 231 | PyObject *_res = NULL; |
| 232 | short theValue; |
| 233 | if (!PyArg_ParseTuple(_args, "h", |
| 234 | &theValue)) |
| 235 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 236 | SetControlValue(_self->ob_itself, |
| 237 | theValue); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 238 | Py_INCREF(Py_None); |
| 239 | _res = Py_None; |
| 240 | return _res; |
| 241 | } |
| 242 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 243 | static PyObject *CtlObj_GetControlValue(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 244 | ControlObject *_self; |
| 245 | PyObject *_args; |
| 246 | { |
| 247 | PyObject *_res = NULL; |
| 248 | short _rv; |
| 249 | if (!PyArg_ParseTuple(_args, "")) |
| 250 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 251 | _rv = GetControlValue(_self->ob_itself); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 252 | _res = Py_BuildValue("h", |
| 253 | _rv); |
| 254 | return _res; |
| 255 | } |
| 256 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 257 | static PyObject *CtlObj_SetControlMinimum(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 258 | ControlObject *_self; |
| 259 | PyObject *_args; |
| 260 | { |
| 261 | PyObject *_res = NULL; |
| 262 | short minValue; |
| 263 | if (!PyArg_ParseTuple(_args, "h", |
| 264 | &minValue)) |
| 265 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 266 | SetControlMinimum(_self->ob_itself, |
| 267 | minValue); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 268 | Py_INCREF(Py_None); |
| 269 | _res = Py_None; |
| 270 | return _res; |
| 271 | } |
| 272 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 273 | static PyObject *CtlObj_GetControlMinimum(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 274 | ControlObject *_self; |
| 275 | PyObject *_args; |
| 276 | { |
| 277 | PyObject *_res = NULL; |
| 278 | short _rv; |
| 279 | if (!PyArg_ParseTuple(_args, "")) |
| 280 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 281 | _rv = GetControlMinimum(_self->ob_itself); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 282 | _res = Py_BuildValue("h", |
| 283 | _rv); |
| 284 | return _res; |
| 285 | } |
| 286 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 287 | static PyObject *CtlObj_SetControlMaximum(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 288 | ControlObject *_self; |
| 289 | PyObject *_args; |
| 290 | { |
| 291 | PyObject *_res = NULL; |
| 292 | short maxValue; |
| 293 | if (!PyArg_ParseTuple(_args, "h", |
| 294 | &maxValue)) |
| 295 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 296 | SetControlMaximum(_self->ob_itself, |
| 297 | maxValue); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 298 | Py_INCREF(Py_None); |
| 299 | _res = Py_None; |
| 300 | return _res; |
| 301 | } |
| 302 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 303 | static PyObject *CtlObj_GetControlMaximum(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 304 | ControlObject *_self; |
| 305 | PyObject *_args; |
| 306 | { |
| 307 | PyObject *_res = NULL; |
| 308 | short _rv; |
| 309 | if (!PyArg_ParseTuple(_args, "")) |
| 310 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 311 | _rv = GetControlMaximum(_self->ob_itself); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 312 | _res = Py_BuildValue("h", |
| 313 | _rv); |
| 314 | return _res; |
| 315 | } |
| 316 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 317 | static PyObject *CtlObj_SetControlReference(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 318 | ControlObject *_self; |
| 319 | PyObject *_args; |
| 320 | { |
| 321 | PyObject *_res = NULL; |
| 322 | long data; |
| 323 | if (!PyArg_ParseTuple(_args, "l", |
| 324 | &data)) |
| 325 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 326 | SetControlReference(_self->ob_itself, |
| 327 | data); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 328 | Py_INCREF(Py_None); |
| 329 | _res = Py_None; |
| 330 | return _res; |
| 331 | } |
| 332 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 333 | static PyObject *CtlObj_GetControlReference(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 334 | ControlObject *_self; |
| 335 | PyObject *_args; |
| 336 | { |
| 337 | PyObject *_res = NULL; |
| 338 | long _rv; |
| 339 | if (!PyArg_ParseTuple(_args, "")) |
| 340 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 341 | _rv = GetControlReference(_self->ob_itself); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 342 | _res = Py_BuildValue("l", |
| 343 | _rv); |
| 344 | return _res; |
| 345 | } |
| 346 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 347 | static PyObject *CtlObj_SetControlAction(_self, _args) |
| 348 | ControlObject *_self; |
| 349 | PyObject *_args; |
| 350 | { |
| 351 | PyObject *_res = NULL; |
| 352 | if (!PyArg_ParseTuple(_args, "")) |
| 353 | return NULL; |
| 354 | SetControlAction(_self->ob_itself, |
| 355 | (ControlActionUPP)0); |
| 356 | Py_INCREF(Py_None); |
| 357 | _res = Py_None; |
| 358 | return _res; |
| 359 | } |
| 360 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 361 | static PyObject *CtlObj_DragControl(_self, _args) |
| 362 | ControlObject *_self; |
| 363 | PyObject *_args; |
| 364 | { |
| 365 | PyObject *_res = NULL; |
| 366 | Point startPt; |
| 367 | Rect limitRect; |
| 368 | Rect slopRect; |
| 369 | short axis; |
| 370 | if (!PyArg_ParseTuple(_args, "O&O&O&h", |
| 371 | PyMac_GetPoint, &startPt, |
| 372 | PyMac_GetRect, &limitRect, |
| 373 | PyMac_GetRect, &slopRect, |
| 374 | &axis)) |
| 375 | return NULL; |
| 376 | DragControl(_self->ob_itself, |
| 377 | startPt, |
| 378 | &limitRect, |
| 379 | &slopRect, |
| 380 | axis); |
| 381 | Py_INCREF(Py_None); |
| 382 | _res = Py_None; |
| 383 | return _res; |
| 384 | } |
| 385 | |
| 386 | static PyObject *CtlObj_TestControl(_self, _args) |
| 387 | ControlObject *_self; |
| 388 | PyObject *_args; |
| 389 | { |
| 390 | PyObject *_res = NULL; |
| 391 | short _rv; |
| 392 | Point thePt; |
| 393 | if (!PyArg_ParseTuple(_args, "O&", |
| 394 | PyMac_GetPoint, &thePt)) |
| 395 | return NULL; |
| 396 | _rv = TestControl(_self->ob_itself, |
| 397 | thePt); |
| 398 | _res = Py_BuildValue("h", |
| 399 | _rv); |
| 400 | return _res; |
| 401 | } |
| 402 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 403 | static PyObject *CtlObj_GetControlVariant(_self, _args) |
| 404 | ControlObject *_self; |
| 405 | PyObject *_args; |
| 406 | { |
| 407 | PyObject *_res = NULL; |
| 408 | short _rv; |
| 409 | if (!PyArg_ParseTuple(_args, "")) |
| 410 | return NULL; |
| 411 | _rv = GetControlVariant(_self->ob_itself); |
| 412 | _res = Py_BuildValue("h", |
| 413 | _rv); |
| 414 | return _res; |
| 415 | } |
| 416 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 417 | static PyObject *CtlObj_TrackControl(_self, _args) |
| 418 | ControlObject *_self; |
| 419 | PyObject *_args; |
| 420 | { |
| 421 | PyObject *_res = NULL; |
| 422 | short _rv; |
| 423 | Point thePoint; |
| 424 | if (!PyArg_ParseTuple(_args, "O&", |
| 425 | PyMac_GetPoint, &thePoint)) |
| 426 | return NULL; |
| 427 | _rv = TrackControl(_self->ob_itself, |
| 428 | thePoint, |
| 429 | (ControlActionUPP)0); |
| 430 | _res = Py_BuildValue("h", |
| 431 | _rv); |
| 432 | return _res; |
| 433 | } |
| 434 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 435 | static PyMethodDef CtlObj_methods[] = { |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 436 | {"SetControlTitle", (PyCFunction)CtlObj_SetControlTitle, 1, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 437 | "(Str255 title) -> None"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 438 | {"GetControlTitle", (PyCFunction)CtlObj_GetControlTitle, 1, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 439 | "(Str255 title) -> None"}, |
| 440 | {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1, |
| 441 | "() -> None"}, |
| 442 | {"HideControl", (PyCFunction)CtlObj_HideControl, 1, |
| 443 | "() -> None"}, |
| 444 | {"ShowControl", (PyCFunction)CtlObj_ShowControl, 1, |
| 445 | "() -> None"}, |
| 446 | {"Draw1Control", (PyCFunction)CtlObj_Draw1Control, 1, |
| 447 | "() -> None"}, |
| 448 | {"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1, |
| 449 | "(short hiliteState) -> None"}, |
| 450 | {"MoveControl", (PyCFunction)CtlObj_MoveControl, 1, |
| 451 | "(short h, short v) -> None"}, |
| 452 | {"SizeControl", (PyCFunction)CtlObj_SizeControl, 1, |
| 453 | "(short w, short h) -> None"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 454 | {"SetControlValue", (PyCFunction)CtlObj_SetControlValue, 1, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 455 | "(short theValue) -> None"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 456 | {"GetControlValue", (PyCFunction)CtlObj_GetControlValue, 1, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 457 | "() -> (short _rv)"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 458 | {"SetControlMinimum", (PyCFunction)CtlObj_SetControlMinimum, 1, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 459 | "(short minValue) -> None"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 460 | {"GetControlMinimum", (PyCFunction)CtlObj_GetControlMinimum, 1, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 461 | "() -> (short _rv)"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 462 | {"SetControlMaximum", (PyCFunction)CtlObj_SetControlMaximum, 1, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 463 | "(short maxValue) -> None"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 464 | {"GetControlMaximum", (PyCFunction)CtlObj_GetControlMaximum, 1, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 465 | "() -> (short _rv)"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 466 | {"SetControlReference", (PyCFunction)CtlObj_SetControlReference, 1, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 467 | "(long data) -> None"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 468 | {"GetControlReference", (PyCFunction)CtlObj_GetControlReference, 1, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 469 | "() -> (long _rv)"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 470 | {"SetControlAction", (PyCFunction)CtlObj_SetControlAction, 1, |
| 471 | "() -> None"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 472 | {"DragControl", (PyCFunction)CtlObj_DragControl, 1, |
| 473 | "(Point startPt, Rect limitRect, Rect slopRect, short axis) -> None"}, |
| 474 | {"TestControl", (PyCFunction)CtlObj_TestControl, 1, |
| 475 | "(Point thePt) -> (short _rv)"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 476 | {"GetControlVariant", (PyCFunction)CtlObj_GetControlVariant, 1, |
| 477 | "() -> (short _rv)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 478 | {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1, |
| 479 | "(Point thePoint) -> (short _rv)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 480 | {NULL, NULL, 0} |
| 481 | }; |
| 482 | |
| 483 | PyMethodChain CtlObj_chain = { CtlObj_methods, NULL }; |
| 484 | |
| 485 | static PyObject *CtlObj_getattr(self, name) |
| 486 | ControlObject *self; |
| 487 | char *name; |
| 488 | { |
| 489 | return Py_FindMethodInChain(&CtlObj_chain, (PyObject *)self, name); |
| 490 | } |
| 491 | |
| 492 | #define CtlObj_setattr NULL |
| 493 | |
| 494 | PyTypeObject Control_Type = { |
| 495 | PyObject_HEAD_INIT(&PyType_Type) |
| 496 | 0, /*ob_size*/ |
| 497 | "Control", /*tp_name*/ |
| 498 | sizeof(ControlObject), /*tp_basicsize*/ |
| 499 | 0, /*tp_itemsize*/ |
| 500 | /* methods */ |
| 501 | (destructor) CtlObj_dealloc, /*tp_dealloc*/ |
| 502 | 0, /*tp_print*/ |
| 503 | (getattrfunc) CtlObj_getattr, /*tp_getattr*/ |
| 504 | (setattrfunc) CtlObj_setattr, /*tp_setattr*/ |
| 505 | }; |
| 506 | |
| 507 | /* -------------------- End object type Control --------------------- */ |
| 508 | |
| 509 | |
| 510 | static PyObject *Ctl_NewControl(_self, _args) |
| 511 | PyObject *_self; |
| 512 | PyObject *_args; |
| 513 | { |
| 514 | PyObject *_res = NULL; |
| 515 | ControlHandle _rv; |
| 516 | WindowPtr theWindow; |
| 517 | Rect boundsRect; |
| 518 | Str255 title; |
| 519 | Boolean visible; |
| 520 | short value; |
| 521 | short min; |
| 522 | short max; |
| 523 | short procID; |
| 524 | long refCon; |
| 525 | if (!PyArg_ParseTuple(_args, "O&O&O&bhhhhl", |
| 526 | WinObj_Convert, &theWindow, |
| 527 | PyMac_GetRect, &boundsRect, |
| 528 | PyMac_GetStr255, title, |
| 529 | &visible, |
| 530 | &value, |
| 531 | &min, |
| 532 | &max, |
| 533 | &procID, |
| 534 | &refCon)) |
| 535 | return NULL; |
| 536 | _rv = NewControl(theWindow, |
| 537 | &boundsRect, |
| 538 | title, |
| 539 | visible, |
| 540 | value, |
| 541 | min, |
| 542 | max, |
| 543 | procID, |
| 544 | refCon); |
| 545 | _res = Py_BuildValue("O&", |
| 546 | CtlObj_New, _rv); |
| 547 | return _res; |
| 548 | } |
| 549 | |
| 550 | static PyObject *Ctl_GetNewControl(_self, _args) |
| 551 | PyObject *_self; |
| 552 | PyObject *_args; |
| 553 | { |
| 554 | PyObject *_res = NULL; |
| 555 | ControlHandle _rv; |
| 556 | short controlID; |
| 557 | WindowPtr owner; |
| 558 | if (!PyArg_ParseTuple(_args, "hO&", |
| 559 | &controlID, |
| 560 | WinObj_Convert, &owner)) |
| 561 | return NULL; |
| 562 | _rv = GetNewControl(controlID, |
| 563 | owner); |
| 564 | _res = Py_BuildValue("O&", |
| 565 | CtlObj_New, _rv); |
| 566 | return _res; |
| 567 | } |
| 568 | |
| 569 | static PyObject *Ctl_KillControls(_self, _args) |
| 570 | PyObject *_self; |
| 571 | PyObject *_args; |
| 572 | { |
| 573 | PyObject *_res = NULL; |
| 574 | WindowPtr theWindow; |
| 575 | if (!PyArg_ParseTuple(_args, "O&", |
| 576 | WinObj_Convert, &theWindow)) |
| 577 | return NULL; |
| 578 | KillControls(theWindow); |
| 579 | Py_INCREF(Py_None); |
| 580 | _res = Py_None; |
| 581 | return _res; |
| 582 | } |
| 583 | |
| 584 | static PyObject *Ctl_DrawControls(_self, _args) |
| 585 | PyObject *_self; |
| 586 | PyObject *_args; |
| 587 | { |
| 588 | PyObject *_res = NULL; |
| 589 | WindowPtr theWindow; |
| 590 | if (!PyArg_ParseTuple(_args, "O&", |
| 591 | WinObj_Convert, &theWindow)) |
| 592 | return NULL; |
| 593 | DrawControls(theWindow); |
| 594 | Py_INCREF(Py_None); |
| 595 | _res = Py_None; |
| 596 | return _res; |
| 597 | } |
| 598 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 599 | static PyObject *Ctl_UpdateControls(_self, _args) |
| 600 | PyObject *_self; |
| 601 | PyObject *_args; |
| 602 | { |
| 603 | PyObject *_res = NULL; |
| 604 | WindowPtr theWindow; |
| 605 | if (!PyArg_ParseTuple(_args, "O&", |
| 606 | WinObj_Convert, &theWindow)) |
| 607 | return NULL; |
| 608 | UpdateControls(theWindow, |
| 609 | theWindow->visRgn); |
| 610 | Py_INCREF(Py_None); |
| 611 | _res = Py_None; |
| 612 | return _res; |
| 613 | } |
| 614 | |
| 615 | static PyObject *Ctl_FindControl(_self, _args) |
| 616 | PyObject *_self; |
| 617 | PyObject *_args; |
| 618 | { |
| 619 | PyObject *_res = NULL; |
| 620 | short _rv; |
| 621 | Point thePoint; |
| 622 | WindowPtr theWindow; |
| 623 | ControlHandle theControl; |
| 624 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 625 | PyMac_GetPoint, &thePoint, |
| 626 | WinObj_Convert, &theWindow)) |
| 627 | return NULL; |
| 628 | _rv = FindControl(thePoint, |
| 629 | theWindow, |
| 630 | &theControl); |
| 631 | _res = Py_BuildValue("hO&", |
| 632 | _rv, |
| 633 | CtlObj_WhichControl, theControl); |
| 634 | return _res; |
| 635 | } |
| 636 | |
| 637 | static PyMethodDef Ctl_methods[] = { |
| 638 | {"NewControl", (PyCFunction)Ctl_NewControl, 1, |
| 639 | "(WindowPtr theWindow, Rect boundsRect, Str255 title, Boolean visible, short value, short min, short max, short procID, long refCon) -> (ControlHandle _rv)"}, |
| 640 | {"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1, |
| 641 | "(short controlID, WindowPtr owner) -> (ControlHandle _rv)"}, |
| 642 | {"KillControls", (PyCFunction)Ctl_KillControls, 1, |
| 643 | "(WindowPtr theWindow) -> None"}, |
| 644 | {"DrawControls", (PyCFunction)Ctl_DrawControls, 1, |
| 645 | "(WindowPtr theWindow) -> None"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 646 | {"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1, |
| 647 | "(WindowPtr theWindow) -> None"}, |
| 648 | {"FindControl", (PyCFunction)Ctl_FindControl, 1, |
| 649 | "(Point thePoint, WindowPtr theWindow) -> (short _rv, ControlHandle theControl)"}, |
| 650 | {NULL, NULL, 0} |
| 651 | }; |
| 652 | |
| 653 | |
| 654 | |
| 655 | PyObject * |
| 656 | CtlObj_WhichControl(ControlHandle c) |
| 657 | { |
| 658 | PyObject *it; |
| 659 | |
| 660 | /* XXX What if we find a control belonging to some other package? */ |
| 661 | if (c == NULL) |
| 662 | it = NULL; |
| 663 | else |
| 664 | it = (PyObject *) GetCRefCon(c); |
| 665 | if (it == NULL || ((ControlObject *)it)->ob_itself != c) |
| 666 | it = Py_None; |
| 667 | Py_INCREF(it); |
| 668 | return it; |
| 669 | } |
| 670 | |
| 671 | |
| 672 | void initCtl() |
| 673 | { |
| 674 | PyObject *m; |
| 675 | PyObject *d; |
| 676 | |
| 677 | |
| 678 | |
| 679 | |
| 680 | m = Py_InitModule("Ctl", Ctl_methods); |
| 681 | d = PyModule_GetDict(m); |
| 682 | Ctl_Error = PyMac_GetOSErrException(); |
| 683 | if (Ctl_Error == NULL || |
| 684 | PyDict_SetItemString(d, "Error", Ctl_Error) != 0) |
| 685 | Py_FatalError("can't initialize Ctl.Error"); |
| 686 | } |
| 687 | |
| 688 | /* ========================= End module Ctl ========================= */ |
| 689 | |