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