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