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