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