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 */ |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 50 | extern PyObject *QdRGB_New(RGBColorPtr); |
| 51 | extern QdRGB_Convert(PyObject *, RGBColorPtr); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 52 | |
| 53 | #ifdef THINK_C |
| 54 | #define ControlActionUPP ProcPtr |
| 55 | #endif |
| 56 | |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 57 | /* |
| 58 | ** Parse/generate ControlFontStyleRec records |
| 59 | */ |
| 60 | #if 0 /* Not needed */ |
| 61 | PyObject *ControlFontStyle_New(itself) |
| 62 | ControlFontStyleRec *itself; |
| 63 | { |
| 64 | |
| 65 | return Py_BuildValue("hhhhhhO&O&", itself->flags, itself->font, |
| 66 | itself->size, itself->style, itself->mode, itself->just, |
| 67 | QdRGB_New, &itself->foreColor, QdRGB_New, &itself->backColor); |
| 68 | } |
| 69 | #endif |
| 70 | |
| 71 | ControlFontStyle_Convert(v, itself) |
| 72 | PyObject *v; |
| 73 | ControlFontStyleRec *itself; |
| 74 | { |
| 75 | return PyArg_ParseTuple(v, "hhhhhhO&O&", &itself->flags, |
| 76 | &itself->font, &itself->size, &itself->style, &itself->mode, |
| 77 | &itself->just, QdRGB_Convert, &itself->foreColor, |
| 78 | QdRGB_Convert, &itself->backColor); |
| 79 | } |
| 80 | |
Jack Jansen | 848250c | 1998-05-28 14:20:09 +0000 | [diff] [blame^] | 81 | /* TrackControl callback support */ |
| 82 | static PyObject *tracker; |
| 83 | static ControlActionUPP mytracker_upp; |
| 84 | |
| 85 | extern int settrackfunc(PyObject *); /* forward */ |
| 86 | extern void clrtrackfunc(void); /* forward */ |
| 87 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 88 | static PyObject *Ctl_Error; |
| 89 | |
| 90 | /* ---------------------- Object type Control ----------------------- */ |
| 91 | |
| 92 | PyTypeObject Control_Type; |
| 93 | |
| 94 | #define CtlObj_Check(x) ((x)->ob_type == &Control_Type) |
| 95 | |
| 96 | typedef struct ControlObject { |
| 97 | PyObject_HEAD |
| 98 | ControlHandle ob_itself; |
| 99 | } ControlObject; |
| 100 | |
| 101 | PyObject *CtlObj_New(itself) |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 102 | ControlHandle itself; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 103 | { |
| 104 | ControlObject *it; |
| 105 | if (itself == NULL) return PyMac_Error(resNotFound); |
| 106 | it = PyObject_NEW(ControlObject, &Control_Type); |
| 107 | if (it == NULL) return NULL; |
| 108 | it->ob_itself = itself; |
Jack Jansen | 85ae4a8 | 1997-04-08 15:26:03 +0000 | [diff] [blame] | 109 | SetControlReference(itself, (long)it); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 110 | return (PyObject *)it; |
| 111 | } |
| 112 | CtlObj_Convert(v, p_itself) |
| 113 | PyObject *v; |
| 114 | ControlHandle *p_itself; |
| 115 | { |
| 116 | if (!CtlObj_Check(v)) |
| 117 | { |
| 118 | PyErr_SetString(PyExc_TypeError, "Control required"); |
| 119 | return 0; |
| 120 | } |
| 121 | *p_itself = ((ControlObject *)v)->ob_itself; |
| 122 | return 1; |
| 123 | } |
| 124 | |
| 125 | static void CtlObj_dealloc(self) |
| 126 | ControlObject *self; |
| 127 | { |
Jack Jansen | 85ae4a8 | 1997-04-08 15:26:03 +0000 | [diff] [blame] | 128 | 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] | 129 | PyMem_DEL(self); |
| 130 | } |
| 131 | |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 132 | static PyObject *CtlObj_HiliteControl(_self, _args) |
| 133 | ControlObject *_self; |
| 134 | PyObject *_args; |
| 135 | { |
| 136 | PyObject *_res = NULL; |
| 137 | ControlPartCode hiliteState; |
| 138 | if (!PyArg_ParseTuple(_args, "h", |
| 139 | &hiliteState)) |
| 140 | return NULL; |
| 141 | HiliteControl(_self->ob_itself, |
| 142 | hiliteState); |
| 143 | Py_INCREF(Py_None); |
| 144 | _res = Py_None; |
| 145 | return _res; |
| 146 | } |
| 147 | |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 148 | static PyObject *CtlObj_ShowControl(_self, _args) |
| 149 | ControlObject *_self; |
| 150 | PyObject *_args; |
| 151 | { |
| 152 | PyObject *_res = NULL; |
| 153 | if (!PyArg_ParseTuple(_args, "")) |
| 154 | return NULL; |
| 155 | ShowControl(_self->ob_itself); |
| 156 | Py_INCREF(Py_None); |
| 157 | _res = Py_None; |
| 158 | return _res; |
| 159 | } |
| 160 | |
| 161 | static PyObject *CtlObj_HideControl(_self, _args) |
| 162 | ControlObject *_self; |
| 163 | PyObject *_args; |
| 164 | { |
| 165 | PyObject *_res = NULL; |
| 166 | if (!PyArg_ParseTuple(_args, "")) |
| 167 | return NULL; |
| 168 | HideControl(_self->ob_itself); |
| 169 | Py_INCREF(Py_None); |
| 170 | _res = Py_None; |
| 171 | return _res; |
| 172 | } |
| 173 | |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 174 | static PyObject *CtlObj_IsControlActive(_self, _args) |
| 175 | ControlObject *_self; |
| 176 | PyObject *_args; |
| 177 | { |
| 178 | PyObject *_res = NULL; |
| 179 | Boolean _rv; |
| 180 | if (!PyArg_ParseTuple(_args, "")) |
| 181 | return NULL; |
| 182 | _rv = IsControlActive(_self->ob_itself); |
| 183 | _res = Py_BuildValue("b", |
| 184 | _rv); |
| 185 | return _res; |
| 186 | } |
| 187 | |
| 188 | static PyObject *CtlObj_IsControlVisible(_self, _args) |
| 189 | ControlObject *_self; |
| 190 | PyObject *_args; |
| 191 | { |
| 192 | PyObject *_res = NULL; |
| 193 | Boolean _rv; |
| 194 | if (!PyArg_ParseTuple(_args, "")) |
| 195 | return NULL; |
| 196 | _rv = IsControlVisible(_self->ob_itself); |
| 197 | _res = Py_BuildValue("b", |
| 198 | _rv); |
| 199 | return _res; |
| 200 | } |
| 201 | |
| 202 | static PyObject *CtlObj_ActivateControl(_self, _args) |
| 203 | ControlObject *_self; |
| 204 | PyObject *_args; |
| 205 | { |
| 206 | PyObject *_res = NULL; |
| 207 | OSErr _err; |
| 208 | if (!PyArg_ParseTuple(_args, "")) |
| 209 | return NULL; |
| 210 | _err = ActivateControl(_self->ob_itself); |
| 211 | if (_err != noErr) return PyMac_Error(_err); |
| 212 | Py_INCREF(Py_None); |
| 213 | _res = Py_None; |
| 214 | return _res; |
| 215 | } |
| 216 | |
| 217 | static PyObject *CtlObj_DeactivateControl(_self, _args) |
| 218 | ControlObject *_self; |
| 219 | PyObject *_args; |
| 220 | { |
| 221 | PyObject *_res = NULL; |
| 222 | OSErr _err; |
| 223 | if (!PyArg_ParseTuple(_args, "")) |
| 224 | return NULL; |
| 225 | _err = DeactivateControl(_self->ob_itself); |
| 226 | if (_err != noErr) return PyMac_Error(_err); |
| 227 | Py_INCREF(Py_None); |
| 228 | _res = Py_None; |
| 229 | return _res; |
| 230 | } |
| 231 | |
| 232 | static PyObject *CtlObj_SetControlVisibility(_self, _args) |
| 233 | ControlObject *_self; |
| 234 | PyObject *_args; |
| 235 | { |
| 236 | PyObject *_res = NULL; |
| 237 | OSErr _err; |
| 238 | Boolean inIsVisible; |
| 239 | Boolean inDoDraw; |
| 240 | if (!PyArg_ParseTuple(_args, "bb", |
| 241 | &inIsVisible, |
| 242 | &inDoDraw)) |
| 243 | return NULL; |
| 244 | _err = SetControlVisibility(_self->ob_itself, |
| 245 | inIsVisible, |
| 246 | inDoDraw); |
| 247 | if (_err != noErr) return PyMac_Error(_err); |
| 248 | Py_INCREF(Py_None); |
| 249 | _res = Py_None; |
| 250 | return _res; |
| 251 | } |
| 252 | |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 253 | static PyObject *CtlObj_Draw1Control(_self, _args) |
| 254 | ControlObject *_self; |
| 255 | PyObject *_args; |
| 256 | { |
| 257 | PyObject *_res = NULL; |
| 258 | if (!PyArg_ParseTuple(_args, "")) |
| 259 | return NULL; |
| 260 | Draw1Control(_self->ob_itself); |
| 261 | Py_INCREF(Py_None); |
| 262 | _res = Py_None; |
| 263 | return _res; |
| 264 | } |
| 265 | |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 266 | static PyObject *CtlObj_GetBestControlRect(_self, _args) |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 267 | ControlObject *_self; |
| 268 | PyObject *_args; |
| 269 | { |
| 270 | PyObject *_res = NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 271 | OSErr _err; |
| 272 | Rect outRect; |
| 273 | SInt16 outBaseLineOffset; |
| 274 | if (!PyArg_ParseTuple(_args, "")) |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 275 | return NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 276 | _err = GetBestControlRect(_self->ob_itself, |
| 277 | &outRect, |
| 278 | &outBaseLineOffset); |
| 279 | if (_err != noErr) return PyMac_Error(_err); |
| 280 | _res = Py_BuildValue("O&h", |
| 281 | PyMac_BuildRect, &outRect, |
| 282 | outBaseLineOffset); |
| 283 | return _res; |
| 284 | } |
| 285 | |
| 286 | static PyObject *CtlObj_SetControlFontStyle(_self, _args) |
| 287 | ControlObject *_self; |
| 288 | PyObject *_args; |
| 289 | { |
| 290 | PyObject *_res = NULL; |
| 291 | OSErr _err; |
| 292 | ControlFontStyleRec inStyle; |
| 293 | if (!PyArg_ParseTuple(_args, "O&", |
| 294 | ControlFontStyle_Convert, &inStyle)) |
| 295 | return NULL; |
| 296 | _err = SetControlFontStyle(_self->ob_itself, |
| 297 | &inStyle); |
| 298 | if (_err != noErr) return PyMac_Error(_err); |
| 299 | Py_INCREF(Py_None); |
| 300 | _res = Py_None; |
| 301 | return _res; |
| 302 | } |
| 303 | |
| 304 | static PyObject *CtlObj_DrawControlInCurrentPort(_self, _args) |
| 305 | ControlObject *_self; |
| 306 | PyObject *_args; |
| 307 | { |
| 308 | PyObject *_res = NULL; |
| 309 | if (!PyArg_ParseTuple(_args, "")) |
| 310 | return NULL; |
| 311 | DrawControlInCurrentPort(_self->ob_itself); |
| 312 | Py_INCREF(Py_None); |
| 313 | _res = Py_None; |
| 314 | return _res; |
| 315 | } |
| 316 | |
| 317 | static PyObject *CtlObj_SetUpControlBackground(_self, _args) |
| 318 | ControlObject *_self; |
| 319 | PyObject *_args; |
| 320 | { |
| 321 | PyObject *_res = NULL; |
| 322 | OSErr _err; |
| 323 | SInt16 inDepth; |
| 324 | Boolean inIsColorDevice; |
| 325 | if (!PyArg_ParseTuple(_args, "hb", |
| 326 | &inDepth, |
| 327 | &inIsColorDevice)) |
| 328 | return NULL; |
| 329 | _err = SetUpControlBackground(_self->ob_itself, |
| 330 | inDepth, |
| 331 | inIsColorDevice); |
| 332 | if (_err != noErr) return PyMac_Error(_err); |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 333 | Py_INCREF(Py_None); |
| 334 | _res = Py_None; |
| 335 | return _res; |
| 336 | } |
| 337 | |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 338 | static PyObject *CtlObj_DragControl(_self, _args) |
| 339 | ControlObject *_self; |
| 340 | PyObject *_args; |
| 341 | { |
| 342 | PyObject *_res = NULL; |
Jack Jansen | 754d4a4 | 1995-11-14 10:41:55 +0000 | [diff] [blame] | 343 | Point startPoint; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 344 | Rect limitRect; |
| 345 | Rect slopRect; |
| 346 | DragConstraint axis; |
| 347 | if (!PyArg_ParseTuple(_args, "O&O&O&h", |
Jack Jansen | 754d4a4 | 1995-11-14 10:41:55 +0000 | [diff] [blame] | 348 | PyMac_GetPoint, &startPoint, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 349 | PyMac_GetRect, &limitRect, |
| 350 | PyMac_GetRect, &slopRect, |
| 351 | &axis)) |
| 352 | return NULL; |
| 353 | DragControl(_self->ob_itself, |
Jack Jansen | 754d4a4 | 1995-11-14 10:41:55 +0000 | [diff] [blame] | 354 | startPoint, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 355 | &limitRect, |
| 356 | &slopRect, |
| 357 | axis); |
| 358 | Py_INCREF(Py_None); |
| 359 | _res = Py_None; |
| 360 | return _res; |
| 361 | } |
| 362 | |
| 363 | static PyObject *CtlObj_TestControl(_self, _args) |
| 364 | ControlObject *_self; |
| 365 | PyObject *_args; |
| 366 | { |
| 367 | PyObject *_res = NULL; |
| 368 | ControlPartCode _rv; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 369 | Point testPoint; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 370 | if (!PyArg_ParseTuple(_args, "O&", |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 371 | PyMac_GetPoint, &testPoint)) |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 372 | return NULL; |
| 373 | _rv = TestControl(_self->ob_itself, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 374 | testPoint); |
| 375 | _res = Py_BuildValue("h", |
| 376 | _rv); |
| 377 | return _res; |
| 378 | } |
| 379 | |
| 380 | static PyObject *CtlObj_HandleControlKey(_self, _args) |
| 381 | ControlObject *_self; |
| 382 | PyObject *_args; |
| 383 | { |
| 384 | PyObject *_res = NULL; |
| 385 | SInt16 _rv; |
| 386 | SInt16 inKeyCode; |
| 387 | SInt16 inCharCode; |
| 388 | SInt16 inModifiers; |
| 389 | if (!PyArg_ParseTuple(_args, "hhh", |
| 390 | &inKeyCode, |
| 391 | &inCharCode, |
| 392 | &inModifiers)) |
| 393 | return NULL; |
| 394 | _rv = HandleControlKey(_self->ob_itself, |
| 395 | inKeyCode, |
| 396 | inCharCode, |
| 397 | inModifiers); |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 398 | _res = Py_BuildValue("h", |
| 399 | _rv); |
| 400 | return _res; |
| 401 | } |
| 402 | |
| 403 | static PyObject *CtlObj_MoveControl(_self, _args) |
| 404 | ControlObject *_self; |
| 405 | PyObject *_args; |
| 406 | { |
| 407 | PyObject *_res = NULL; |
| 408 | SInt16 h; |
| 409 | SInt16 v; |
| 410 | if (!PyArg_ParseTuple(_args, "hh", |
| 411 | &h, |
| 412 | &v)) |
| 413 | return NULL; |
| 414 | MoveControl(_self->ob_itself, |
| 415 | h, |
| 416 | v); |
| 417 | Py_INCREF(Py_None); |
| 418 | _res = Py_None; |
| 419 | return _res; |
| 420 | } |
| 421 | |
| 422 | static PyObject *CtlObj_SizeControl(_self, _args) |
| 423 | ControlObject *_self; |
| 424 | PyObject *_args; |
| 425 | { |
| 426 | PyObject *_res = NULL; |
| 427 | SInt16 w; |
| 428 | SInt16 h; |
| 429 | if (!PyArg_ParseTuple(_args, "hh", |
| 430 | &w, |
| 431 | &h)) |
| 432 | return NULL; |
| 433 | SizeControl(_self->ob_itself, |
| 434 | w, |
| 435 | h); |
| 436 | Py_INCREF(Py_None); |
| 437 | _res = Py_None; |
| 438 | return _res; |
| 439 | } |
| 440 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 441 | static PyObject *CtlObj_SetControlTitle(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 442 | ControlObject *_self; |
| 443 | PyObject *_args; |
| 444 | { |
| 445 | PyObject *_res = NULL; |
| 446 | Str255 title; |
| 447 | if (!PyArg_ParseTuple(_args, "O&", |
| 448 | PyMac_GetStr255, title)) |
| 449 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 450 | SetControlTitle(_self->ob_itself, |
| 451 | title); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 452 | Py_INCREF(Py_None); |
| 453 | _res = Py_None; |
| 454 | return _res; |
| 455 | } |
| 456 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 457 | static PyObject *CtlObj_GetControlTitle(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 458 | ControlObject *_self; |
| 459 | PyObject *_args; |
| 460 | { |
| 461 | PyObject *_res = NULL; |
| 462 | Str255 title; |
| 463 | if (!PyArg_ParseTuple(_args, "O&", |
| 464 | PyMac_GetStr255, title)) |
| 465 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 466 | GetControlTitle(_self->ob_itself, |
| 467 | title); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 468 | Py_INCREF(Py_None); |
| 469 | _res = Py_None; |
| 470 | return _res; |
| 471 | } |
| 472 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 473 | static PyObject *CtlObj_GetControlValue(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 474 | ControlObject *_self; |
| 475 | PyObject *_args; |
| 476 | { |
| 477 | PyObject *_res = NULL; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 478 | SInt16 _rv; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 479 | if (!PyArg_ParseTuple(_args, "")) |
| 480 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 481 | _rv = GetControlValue(_self->ob_itself); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 482 | _res = Py_BuildValue("h", |
| 483 | _rv); |
| 484 | return _res; |
| 485 | } |
| 486 | |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 487 | static PyObject *CtlObj_SetControlValue(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 488 | ControlObject *_self; |
| 489 | PyObject *_args; |
| 490 | { |
| 491 | PyObject *_res = NULL; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 492 | SInt16 newValue; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 493 | if (!PyArg_ParseTuple(_args, "h", |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 494 | &newValue)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 495 | return NULL; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 496 | SetControlValue(_self->ob_itself, |
| 497 | newValue); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 498 | Py_INCREF(Py_None); |
| 499 | _res = Py_None; |
| 500 | return _res; |
| 501 | } |
| 502 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 503 | static PyObject *CtlObj_GetControlMinimum(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 504 | ControlObject *_self; |
| 505 | PyObject *_args; |
| 506 | { |
| 507 | PyObject *_res = NULL; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 508 | SInt16 _rv; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 509 | if (!PyArg_ParseTuple(_args, "")) |
| 510 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 511 | _rv = GetControlMinimum(_self->ob_itself); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 512 | _res = Py_BuildValue("h", |
| 513 | _rv); |
| 514 | return _res; |
| 515 | } |
| 516 | |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 517 | static PyObject *CtlObj_SetControlMinimum(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 518 | ControlObject *_self; |
| 519 | PyObject *_args; |
| 520 | { |
| 521 | PyObject *_res = NULL; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 522 | SInt16 newMinimum; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 523 | if (!PyArg_ParseTuple(_args, "h", |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 524 | &newMinimum)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 525 | return NULL; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 526 | SetControlMinimum(_self->ob_itself, |
| 527 | newMinimum); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 528 | Py_INCREF(Py_None); |
| 529 | _res = Py_None; |
| 530 | return _res; |
| 531 | } |
| 532 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 533 | static PyObject *CtlObj_GetControlMaximum(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 534 | ControlObject *_self; |
| 535 | PyObject *_args; |
| 536 | { |
| 537 | PyObject *_res = NULL; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 538 | SInt16 _rv; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 539 | if (!PyArg_ParseTuple(_args, "")) |
| 540 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 541 | _rv = GetControlMaximum(_self->ob_itself); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 542 | _res = Py_BuildValue("h", |
| 543 | _rv); |
| 544 | return _res; |
| 545 | } |
| 546 | |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 547 | static PyObject *CtlObj_SetControlMaximum(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 548 | ControlObject *_self; |
| 549 | PyObject *_args; |
| 550 | { |
| 551 | PyObject *_res = NULL; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 552 | SInt16 newMaximum; |
| 553 | if (!PyArg_ParseTuple(_args, "h", |
| 554 | &newMaximum)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 555 | return NULL; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 556 | SetControlMaximum(_self->ob_itself, |
| 557 | newMaximum); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 558 | Py_INCREF(Py_None); |
| 559 | _res = Py_None; |
| 560 | return _res; |
| 561 | } |
| 562 | |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 563 | static PyObject *CtlObj_GetControlVariant(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 564 | ControlObject *_self; |
| 565 | PyObject *_args; |
| 566 | { |
| 567 | PyObject *_res = NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 568 | ControlVariant _rv; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 569 | if (!PyArg_ParseTuple(_args, "")) |
| 570 | return NULL; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 571 | _rv = GetControlVariant(_self->ob_itself); |
| 572 | _res = Py_BuildValue("h", |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 573 | _rv); |
| 574 | return _res; |
| 575 | } |
| 576 | |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 577 | static PyObject *CtlObj_SetControlReference(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 578 | ControlObject *_self; |
| 579 | PyObject *_args; |
| 580 | { |
| 581 | PyObject *_res = NULL; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 582 | SInt32 data; |
| 583 | if (!PyArg_ParseTuple(_args, "l", |
| 584 | &data)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 585 | return NULL; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 586 | SetControlReference(_self->ob_itself, |
| 587 | data); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 588 | Py_INCREF(Py_None); |
| 589 | _res = Py_None; |
| 590 | return _res; |
| 591 | } |
| 592 | |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 593 | static PyObject *CtlObj_GetControlReference(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 594 | ControlObject *_self; |
| 595 | PyObject *_args; |
| 596 | { |
| 597 | PyObject *_res = NULL; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 598 | SInt32 _rv; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 599 | if (!PyArg_ParseTuple(_args, "")) |
| 600 | return NULL; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 601 | _rv = GetControlReference(_self->ob_itself); |
| 602 | _res = Py_BuildValue("l", |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 603 | _rv); |
| 604 | return _res; |
| 605 | } |
| 606 | |
Jack Jansen | c7fefed | 1997-08-15 14:32:18 +0000 | [diff] [blame] | 607 | static PyObject *CtlObj_GetAuxiliaryControlRecord(_self, _args) |
| 608 | ControlObject *_self; |
| 609 | PyObject *_args; |
| 610 | { |
| 611 | PyObject *_res = NULL; |
| 612 | Boolean _rv; |
| 613 | AuxCtlHandle acHndl; |
| 614 | if (!PyArg_ParseTuple(_args, "")) |
| 615 | return NULL; |
| 616 | _rv = GetAuxiliaryControlRecord(_self->ob_itself, |
| 617 | &acHndl); |
| 618 | _res = Py_BuildValue("bO&", |
| 619 | _rv, |
| 620 | ResObj_New, acHndl); |
| 621 | return _res; |
| 622 | } |
| 623 | |
| 624 | static PyObject *CtlObj_SetControlColor(_self, _args) |
| 625 | ControlObject *_self; |
| 626 | PyObject *_args; |
| 627 | { |
| 628 | PyObject *_res = NULL; |
| 629 | CCTabHandle newColorTable; |
| 630 | if (!PyArg_ParseTuple(_args, "O&", |
| 631 | ResObj_Convert, &newColorTable)) |
| 632 | return NULL; |
| 633 | SetControlColor(_self->ob_itself, |
| 634 | newColorTable); |
| 635 | Py_INCREF(Py_None); |
| 636 | _res = Py_None; |
| 637 | return _res; |
| 638 | } |
| 639 | |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 640 | static PyObject *CtlObj_SendControlMessage(_self, _args) |
| 641 | ControlObject *_self; |
| 642 | PyObject *_args; |
| 643 | { |
| 644 | PyObject *_res = NULL; |
| 645 | SInt32 _rv; |
| 646 | SInt16 inMessage; |
| 647 | SInt32 inParam; |
| 648 | if (!PyArg_ParseTuple(_args, "hl", |
| 649 | &inMessage, |
| 650 | &inParam)) |
| 651 | return NULL; |
| 652 | _rv = SendControlMessage(_self->ob_itself, |
| 653 | inMessage, |
| 654 | inParam); |
| 655 | _res = Py_BuildValue("l", |
| 656 | _rv); |
| 657 | return _res; |
| 658 | } |
| 659 | |
| 660 | static PyObject *CtlObj_EmbedControl(_self, _args) |
| 661 | ControlObject *_self; |
| 662 | PyObject *_args; |
| 663 | { |
| 664 | PyObject *_res = NULL; |
| 665 | OSErr _err; |
| 666 | ControlHandle inContainer; |
| 667 | if (!PyArg_ParseTuple(_args, "O&", |
| 668 | CtlObj_Convert, &inContainer)) |
| 669 | return NULL; |
| 670 | _err = EmbedControl(_self->ob_itself, |
| 671 | inContainer); |
| 672 | if (_err != noErr) return PyMac_Error(_err); |
| 673 | Py_INCREF(Py_None); |
| 674 | _res = Py_None; |
| 675 | return _res; |
| 676 | } |
| 677 | |
| 678 | static PyObject *CtlObj_AutoEmbedControl(_self, _args) |
| 679 | ControlObject *_self; |
| 680 | PyObject *_args; |
| 681 | { |
| 682 | PyObject *_res = NULL; |
| 683 | OSErr _err; |
| 684 | WindowPtr inWindow; |
| 685 | if (!PyArg_ParseTuple(_args, "O&", |
| 686 | WinObj_Convert, &inWindow)) |
| 687 | return NULL; |
| 688 | _err = AutoEmbedControl(_self->ob_itself, |
| 689 | inWindow); |
| 690 | if (_err != noErr) return PyMac_Error(_err); |
| 691 | Py_INCREF(Py_None); |
| 692 | _res = Py_None; |
| 693 | return _res; |
| 694 | } |
| 695 | |
| 696 | static PyObject *CtlObj_GetSuperControl(_self, _args) |
| 697 | ControlObject *_self; |
| 698 | PyObject *_args; |
| 699 | { |
| 700 | PyObject *_res = NULL; |
| 701 | OSErr _err; |
| 702 | ControlHandle outParent; |
| 703 | if (!PyArg_ParseTuple(_args, "")) |
| 704 | return NULL; |
| 705 | _err = GetSuperControl(_self->ob_itself, |
| 706 | &outParent); |
| 707 | if (_err != noErr) return PyMac_Error(_err); |
| 708 | _res = Py_BuildValue("O&", |
| 709 | CtlObj_WhichControl, outParent); |
| 710 | return _res; |
| 711 | } |
| 712 | |
| 713 | static PyObject *CtlObj_CountSubControls(_self, _args) |
| 714 | ControlObject *_self; |
| 715 | PyObject *_args; |
| 716 | { |
| 717 | PyObject *_res = NULL; |
| 718 | OSErr _err; |
| 719 | SInt16 outNumChildren; |
| 720 | if (!PyArg_ParseTuple(_args, "")) |
| 721 | return NULL; |
| 722 | _err = CountSubControls(_self->ob_itself, |
| 723 | &outNumChildren); |
| 724 | if (_err != noErr) return PyMac_Error(_err); |
| 725 | _res = Py_BuildValue("h", |
| 726 | outNumChildren); |
| 727 | return _res; |
| 728 | } |
| 729 | |
| 730 | static PyObject *CtlObj_GetIndexedSubControl(_self, _args) |
| 731 | ControlObject *_self; |
| 732 | PyObject *_args; |
| 733 | { |
| 734 | PyObject *_res = NULL; |
| 735 | OSErr _err; |
| 736 | SInt16 inIndex; |
| 737 | ControlHandle outSubControl; |
| 738 | if (!PyArg_ParseTuple(_args, "h", |
| 739 | &inIndex)) |
| 740 | return NULL; |
| 741 | _err = GetIndexedSubControl(_self->ob_itself, |
| 742 | inIndex, |
| 743 | &outSubControl); |
| 744 | if (_err != noErr) return PyMac_Error(_err); |
| 745 | _res = Py_BuildValue("O&", |
| 746 | CtlObj_WhichControl, outSubControl); |
| 747 | return _res; |
| 748 | } |
| 749 | |
| 750 | static PyObject *CtlObj_SetControlSupervisor(_self, _args) |
| 751 | ControlObject *_self; |
| 752 | PyObject *_args; |
| 753 | { |
| 754 | PyObject *_res = NULL; |
| 755 | OSErr _err; |
| 756 | ControlHandle inBoss; |
| 757 | if (!PyArg_ParseTuple(_args, "O&", |
| 758 | CtlObj_Convert, &inBoss)) |
| 759 | return NULL; |
| 760 | _err = SetControlSupervisor(_self->ob_itself, |
| 761 | inBoss); |
| 762 | if (_err != noErr) return PyMac_Error(_err); |
| 763 | Py_INCREF(Py_None); |
| 764 | _res = Py_None; |
| 765 | return _res; |
| 766 | } |
| 767 | |
| 768 | static PyObject *CtlObj_GetControlFeatures(_self, _args) |
| 769 | ControlObject *_self; |
| 770 | PyObject *_args; |
| 771 | { |
| 772 | PyObject *_res = NULL; |
| 773 | OSErr _err; |
| 774 | UInt32 outFeatures; |
| 775 | if (!PyArg_ParseTuple(_args, "")) |
| 776 | return NULL; |
| 777 | _err = GetControlFeatures(_self->ob_itself, |
| 778 | &outFeatures); |
| 779 | if (_err != noErr) return PyMac_Error(_err); |
| 780 | _res = Py_BuildValue("l", |
| 781 | outFeatures); |
| 782 | return _res; |
| 783 | } |
| 784 | |
| 785 | static PyObject *CtlObj_GetControlDataSize(_self, _args) |
| 786 | ControlObject *_self; |
| 787 | PyObject *_args; |
| 788 | { |
| 789 | PyObject *_res = NULL; |
| 790 | OSErr _err; |
| 791 | ControlPartCode inPart; |
| 792 | ResType inTagName; |
| 793 | Size outMaxSize; |
| 794 | if (!PyArg_ParseTuple(_args, "hO&", |
| 795 | &inPart, |
| 796 | PyMac_GetOSType, &inTagName)) |
| 797 | return NULL; |
| 798 | _err = GetControlDataSize(_self->ob_itself, |
| 799 | inPart, |
| 800 | inTagName, |
| 801 | &outMaxSize); |
| 802 | if (_err != noErr) return PyMac_Error(_err); |
| 803 | _res = Py_BuildValue("l", |
| 804 | outMaxSize); |
| 805 | return _res; |
| 806 | } |
| 807 | |
Jack Jansen | 5d56f4b | 1995-06-18 20:16:33 +0000 | [diff] [blame] | 808 | static PyObject *CtlObj_as_Resource(_self, _args) |
| 809 | ControlObject *_self; |
| 810 | PyObject *_args; |
| 811 | { |
| 812 | PyObject *_res = NULL; |
| 813 | |
| 814 | return ResObj_New((Handle)_self->ob_itself); |
| 815 | |
| 816 | } |
| 817 | |
Jack Jansen | cfb60ee | 1996-10-01 10:46:46 +0000 | [diff] [blame] | 818 | static PyObject *CtlObj_DisposeControl(_self, _args) |
| 819 | ControlObject *_self; |
| 820 | PyObject *_args; |
| 821 | { |
| 822 | PyObject *_res = NULL; |
| 823 | |
| 824 | if (!PyArg_ParseTuple(_args, "")) |
| 825 | return NULL; |
| 826 | if ( _self->ob_itself ) { |
Jack Jansen | 85ae4a8 | 1997-04-08 15:26:03 +0000 | [diff] [blame] | 827 | SetControlReference(_self->ob_itself, (long)0); /* Make it forget about us */ |
Jack Jansen | cfb60ee | 1996-10-01 10:46:46 +0000 | [diff] [blame] | 828 | DisposeControl(_self->ob_itself); |
| 829 | _self->ob_itself = NULL; |
| 830 | } |
| 831 | Py_INCREF(Py_None); |
| 832 | _res = Py_None; |
| 833 | return _res; |
| 834 | |
| 835 | } |
| 836 | |
Jack Jansen | 848250c | 1998-05-28 14:20:09 +0000 | [diff] [blame^] | 837 | static PyObject *CtlObj_TrackControl(_self, _args) |
| 838 | ControlObject *_self; |
| 839 | PyObject *_args; |
| 840 | { |
| 841 | PyObject *_res = NULL; |
| 842 | |
| 843 | ControlPartCode _rv; |
| 844 | Point startPoint; |
| 845 | ControlActionUPP upp = 0; |
| 846 | PyObject *callback = 0; |
| 847 | |
| 848 | if (!PyArg_ParseTuple(_args, "O&|O", |
| 849 | PyMac_GetPoint, &startPoint, &callback)) |
| 850 | return NULL; |
| 851 | if (callback && callback != Py_None) { |
| 852 | if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1) |
| 853 | upp = (ControlActionUPP)-1; |
| 854 | else { |
| 855 | settrackfunc(callback); |
| 856 | upp = mytracker_upp; |
| 857 | } |
| 858 | } |
| 859 | _rv = TrackControl(_self->ob_itself, |
| 860 | startPoint, |
| 861 | upp); |
| 862 | clrtrackfunc(); |
| 863 | _res = Py_BuildValue("h", |
| 864 | _rv); |
| 865 | return _res; |
| 866 | |
| 867 | } |
| 868 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 869 | static PyMethodDef CtlObj_methods[] = { |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 870 | {"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1, |
| 871 | "(ControlPartCode hiliteState) -> None"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 872 | {"ShowControl", (PyCFunction)CtlObj_ShowControl, 1, |
| 873 | "() -> None"}, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 874 | {"HideControl", (PyCFunction)CtlObj_HideControl, 1, |
| 875 | "() -> None"}, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 876 | {"IsControlActive", (PyCFunction)CtlObj_IsControlActive, 1, |
| 877 | "() -> (Boolean _rv)"}, |
| 878 | {"IsControlVisible", (PyCFunction)CtlObj_IsControlVisible, 1, |
| 879 | "() -> (Boolean _rv)"}, |
| 880 | {"ActivateControl", (PyCFunction)CtlObj_ActivateControl, 1, |
| 881 | "() -> None"}, |
| 882 | {"DeactivateControl", (PyCFunction)CtlObj_DeactivateControl, 1, |
| 883 | "() -> None"}, |
| 884 | {"SetControlVisibility", (PyCFunction)CtlObj_SetControlVisibility, 1, |
| 885 | "(Boolean inIsVisible, Boolean inDoDraw) -> None"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 886 | {"Draw1Control", (PyCFunction)CtlObj_Draw1Control, 1, |
| 887 | "() -> None"}, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 888 | {"GetBestControlRect", (PyCFunction)CtlObj_GetBestControlRect, 1, |
| 889 | "() -> (Rect outRect, SInt16 outBaseLineOffset)"}, |
| 890 | {"SetControlFontStyle", (PyCFunction)CtlObj_SetControlFontStyle, 1, |
| 891 | "(ControlFontStyleRec inStyle) -> None"}, |
| 892 | {"DrawControlInCurrentPort", (PyCFunction)CtlObj_DrawControlInCurrentPort, 1, |
| 893 | "() -> None"}, |
| 894 | {"SetUpControlBackground", (PyCFunction)CtlObj_SetUpControlBackground, 1, |
| 895 | "(SInt16 inDepth, Boolean inIsColorDevice) -> None"}, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 896 | {"DragControl", (PyCFunction)CtlObj_DragControl, 1, |
Jack Jansen | 754d4a4 | 1995-11-14 10:41:55 +0000 | [diff] [blame] | 897 | "(Point startPoint, Rect limitRect, Rect slopRect, DragConstraint axis) -> None"}, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 898 | {"TestControl", (PyCFunction)CtlObj_TestControl, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 899 | "(Point testPoint) -> (ControlPartCode _rv)"}, |
| 900 | {"HandleControlKey", (PyCFunction)CtlObj_HandleControlKey, 1, |
| 901 | "(SInt16 inKeyCode, SInt16 inCharCode, SInt16 inModifiers) -> (SInt16 _rv)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 902 | {"MoveControl", (PyCFunction)CtlObj_MoveControl, 1, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 903 | "(SInt16 h, SInt16 v) -> None"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 904 | {"SizeControl", (PyCFunction)CtlObj_SizeControl, 1, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 905 | "(SInt16 w, SInt16 h) -> None"}, |
| 906 | {"SetControlTitle", (PyCFunction)CtlObj_SetControlTitle, 1, |
| 907 | "(Str255 title) -> None"}, |
| 908 | {"GetControlTitle", (PyCFunction)CtlObj_GetControlTitle, 1, |
| 909 | "(Str255 title) -> None"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 910 | {"GetControlValue", (PyCFunction)CtlObj_GetControlValue, 1, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 911 | "() -> (SInt16 _rv)"}, |
| 912 | {"SetControlValue", (PyCFunction)CtlObj_SetControlValue, 1, |
| 913 | "(SInt16 newValue) -> None"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 914 | {"GetControlMinimum", (PyCFunction)CtlObj_GetControlMinimum, 1, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 915 | "() -> (SInt16 _rv)"}, |
| 916 | {"SetControlMinimum", (PyCFunction)CtlObj_SetControlMinimum, 1, |
| 917 | "(SInt16 newMinimum) -> None"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 918 | {"GetControlMaximum", (PyCFunction)CtlObj_GetControlMaximum, 1, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 919 | "() -> (SInt16 _rv)"}, |
| 920 | {"SetControlMaximum", (PyCFunction)CtlObj_SetControlMaximum, 1, |
| 921 | "(SInt16 newMaximum) -> None"}, |
| 922 | {"GetControlVariant", (PyCFunction)CtlObj_GetControlVariant, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 923 | "() -> (ControlVariant _rv)"}, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 924 | {"SetControlReference", (PyCFunction)CtlObj_SetControlReference, 1, |
| 925 | "(SInt32 data) -> None"}, |
| 926 | {"GetControlReference", (PyCFunction)CtlObj_GetControlReference, 1, |
| 927 | "() -> (SInt32 _rv)"}, |
Jack Jansen | c7fefed | 1997-08-15 14:32:18 +0000 | [diff] [blame] | 928 | {"GetAuxiliaryControlRecord", (PyCFunction)CtlObj_GetAuxiliaryControlRecord, 1, |
| 929 | "() -> (Boolean _rv, AuxCtlHandle acHndl)"}, |
| 930 | {"SetControlColor", (PyCFunction)CtlObj_SetControlColor, 1, |
| 931 | "(CCTabHandle newColorTable) -> None"}, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 932 | {"SendControlMessage", (PyCFunction)CtlObj_SendControlMessage, 1, |
| 933 | "(SInt16 inMessage, SInt32 inParam) -> (SInt32 _rv)"}, |
| 934 | {"EmbedControl", (PyCFunction)CtlObj_EmbedControl, 1, |
| 935 | "(ControlHandle inContainer) -> None"}, |
| 936 | {"AutoEmbedControl", (PyCFunction)CtlObj_AutoEmbedControl, 1, |
| 937 | "(WindowPtr inWindow) -> None"}, |
| 938 | {"GetSuperControl", (PyCFunction)CtlObj_GetSuperControl, 1, |
| 939 | "() -> (ControlHandle outParent)"}, |
| 940 | {"CountSubControls", (PyCFunction)CtlObj_CountSubControls, 1, |
| 941 | "() -> (SInt16 outNumChildren)"}, |
| 942 | {"GetIndexedSubControl", (PyCFunction)CtlObj_GetIndexedSubControl, 1, |
| 943 | "(SInt16 inIndex) -> (ControlHandle outSubControl)"}, |
| 944 | {"SetControlSupervisor", (PyCFunction)CtlObj_SetControlSupervisor, 1, |
| 945 | "(ControlHandle inBoss) -> None"}, |
| 946 | {"GetControlFeatures", (PyCFunction)CtlObj_GetControlFeatures, 1, |
| 947 | "() -> (UInt32 outFeatures)"}, |
| 948 | {"GetControlDataSize", (PyCFunction)CtlObj_GetControlDataSize, 1, |
| 949 | "(ControlPartCode inPart, ResType inTagName) -> (Size outMaxSize)"}, |
Jack Jansen | 5d56f4b | 1995-06-18 20:16:33 +0000 | [diff] [blame] | 950 | {"as_Resource", (PyCFunction)CtlObj_as_Resource, 1, |
| 951 | "Return this Control as a Resource"}, |
Jack Jansen | cfb60ee | 1996-10-01 10:46:46 +0000 | [diff] [blame] | 952 | {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1, |
| 953 | "() -> None"}, |
Jack Jansen | 848250c | 1998-05-28 14:20:09 +0000 | [diff] [blame^] | 954 | {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1, |
| 955 | NULL}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 956 | {NULL, NULL, 0} |
| 957 | }; |
| 958 | |
| 959 | PyMethodChain CtlObj_chain = { CtlObj_methods, NULL }; |
| 960 | |
| 961 | static PyObject *CtlObj_getattr(self, name) |
| 962 | ControlObject *self; |
| 963 | char *name; |
| 964 | { |
| 965 | return Py_FindMethodInChain(&CtlObj_chain, (PyObject *)self, name); |
| 966 | } |
| 967 | |
| 968 | #define CtlObj_setattr NULL |
| 969 | |
| 970 | PyTypeObject Control_Type = { |
| 971 | PyObject_HEAD_INIT(&PyType_Type) |
| 972 | 0, /*ob_size*/ |
| 973 | "Control", /*tp_name*/ |
| 974 | sizeof(ControlObject), /*tp_basicsize*/ |
| 975 | 0, /*tp_itemsize*/ |
| 976 | /* methods */ |
| 977 | (destructor) CtlObj_dealloc, /*tp_dealloc*/ |
| 978 | 0, /*tp_print*/ |
| 979 | (getattrfunc) CtlObj_getattr, /*tp_getattr*/ |
| 980 | (setattrfunc) CtlObj_setattr, /*tp_setattr*/ |
| 981 | }; |
| 982 | |
| 983 | /* -------------------- End object type Control --------------------- */ |
| 984 | |
| 985 | |
| 986 | static PyObject *Ctl_NewControl(_self, _args) |
| 987 | PyObject *_self; |
| 988 | PyObject *_args; |
| 989 | { |
| 990 | PyObject *_res = NULL; |
| 991 | ControlHandle _rv; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 992 | WindowPtr owningWindow; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 993 | Rect boundsRect; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 994 | Str255 controlTitle; |
| 995 | Boolean initiallyVisible; |
| 996 | SInt16 initialValue; |
| 997 | SInt16 minimumValue; |
| 998 | SInt16 maximumValue; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 999 | SInt16 procID; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1000 | SInt32 controlReference; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1001 | if (!PyArg_ParseTuple(_args, "O&O&O&bhhhhl", |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1002 | WinObj_Convert, &owningWindow, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1003 | PyMac_GetRect, &boundsRect, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1004 | PyMac_GetStr255, controlTitle, |
| 1005 | &initiallyVisible, |
| 1006 | &initialValue, |
| 1007 | &minimumValue, |
| 1008 | &maximumValue, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1009 | &procID, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1010 | &controlReference)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1011 | return NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1012 | _rv = NewControl(owningWindow, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1013 | &boundsRect, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1014 | controlTitle, |
| 1015 | initiallyVisible, |
| 1016 | initialValue, |
| 1017 | minimumValue, |
| 1018 | maximumValue, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1019 | procID, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1020 | controlReference); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1021 | _res = Py_BuildValue("O&", |
| 1022 | CtlObj_New, _rv); |
| 1023 | return _res; |
| 1024 | } |
| 1025 | |
| 1026 | static PyObject *Ctl_GetNewControl(_self, _args) |
| 1027 | PyObject *_self; |
| 1028 | PyObject *_args; |
| 1029 | { |
| 1030 | PyObject *_res = NULL; |
| 1031 | ControlHandle _rv; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1032 | SInt16 resourceID; |
| 1033 | WindowPtr owningWindow; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1034 | if (!PyArg_ParseTuple(_args, "hO&", |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1035 | &resourceID, |
| 1036 | WinObj_Convert, &owningWindow)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1037 | return NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1038 | _rv = GetNewControl(resourceID, |
| 1039 | owningWindow); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1040 | _res = Py_BuildValue("O&", |
| 1041 | CtlObj_New, _rv); |
| 1042 | return _res; |
| 1043 | } |
| 1044 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1045 | static PyObject *Ctl_DrawControls(_self, _args) |
| 1046 | PyObject *_self; |
| 1047 | PyObject *_args; |
| 1048 | { |
| 1049 | PyObject *_res = NULL; |
| 1050 | WindowPtr theWindow; |
| 1051 | if (!PyArg_ParseTuple(_args, "O&", |
| 1052 | WinObj_Convert, &theWindow)) |
| 1053 | return NULL; |
| 1054 | DrawControls(theWindow); |
| 1055 | Py_INCREF(Py_None); |
| 1056 | _res = Py_None; |
| 1057 | return _res; |
| 1058 | } |
| 1059 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1060 | static PyObject *Ctl_UpdateControls(_self, _args) |
| 1061 | PyObject *_self; |
| 1062 | PyObject *_args; |
| 1063 | { |
| 1064 | PyObject *_res = NULL; |
| 1065 | WindowPtr theWindow; |
Jack Jansen | 2b72417 | 1996-04-10 14:48:19 +0000 | [diff] [blame] | 1066 | RgnHandle updateRegion; |
| 1067 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 1068 | WinObj_Convert, &theWindow, |
| 1069 | ResObj_Convert, &updateRegion)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1070 | return NULL; |
| 1071 | UpdateControls(theWindow, |
Jack Jansen | 2b72417 | 1996-04-10 14:48:19 +0000 | [diff] [blame] | 1072 | updateRegion); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1073 | Py_INCREF(Py_None); |
| 1074 | _res = Py_None; |
| 1075 | return _res; |
| 1076 | } |
| 1077 | |
| 1078 | static PyObject *Ctl_FindControl(_self, _args) |
| 1079 | PyObject *_self; |
| 1080 | PyObject *_args; |
| 1081 | { |
| 1082 | PyObject *_res = NULL; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 1083 | ControlPartCode _rv; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1084 | Point testPoint; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1085 | WindowPtr theWindow; |
| 1086 | ControlHandle theControl; |
| 1087 | if (!PyArg_ParseTuple(_args, "O&O&", |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1088 | PyMac_GetPoint, &testPoint, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1089 | WinObj_Convert, &theWindow)) |
| 1090 | return NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1091 | _rv = FindControl(testPoint, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1092 | theWindow, |
| 1093 | &theControl); |
| 1094 | _res = Py_BuildValue("hO&", |
| 1095 | _rv, |
| 1096 | CtlObj_WhichControl, theControl); |
| 1097 | return _res; |
| 1098 | } |
| 1099 | |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1100 | static PyObject *Ctl_FindControlUnderMouse(_self, _args) |
| 1101 | PyObject *_self; |
| 1102 | PyObject *_args; |
| 1103 | { |
| 1104 | PyObject *_res = NULL; |
| 1105 | ControlHandle _rv; |
| 1106 | Point inWhere; |
| 1107 | WindowPtr inWindow; |
| 1108 | SInt16 outPart; |
| 1109 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 1110 | PyMac_GetPoint, &inWhere, |
| 1111 | WinObj_Convert, &inWindow)) |
| 1112 | return NULL; |
| 1113 | _rv = FindControlUnderMouse(inWhere, |
| 1114 | inWindow, |
| 1115 | &outPart); |
| 1116 | _res = Py_BuildValue("O&h", |
| 1117 | CtlObj_New, _rv, |
| 1118 | outPart); |
| 1119 | return _res; |
| 1120 | } |
| 1121 | |
| 1122 | static PyObject *Ctl_IdleControls(_self, _args) |
| 1123 | PyObject *_self; |
| 1124 | PyObject *_args; |
| 1125 | { |
| 1126 | PyObject *_res = NULL; |
| 1127 | WindowPtr inWindow; |
| 1128 | if (!PyArg_ParseTuple(_args, "O&", |
| 1129 | WinObj_Convert, &inWindow)) |
| 1130 | return NULL; |
| 1131 | IdleControls(inWindow); |
| 1132 | Py_INCREF(Py_None); |
| 1133 | _res = Py_None; |
| 1134 | return _res; |
| 1135 | } |
| 1136 | |
| 1137 | static PyObject *Ctl_DumpControlHierarchy(_self, _args) |
| 1138 | PyObject *_self; |
| 1139 | PyObject *_args; |
| 1140 | { |
| 1141 | PyObject *_res = NULL; |
| 1142 | OSErr _err; |
| 1143 | WindowPtr inWindow; |
| 1144 | FSSpec inDumpFile; |
| 1145 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 1146 | WinObj_Convert, &inWindow, |
| 1147 | PyMac_GetFSSpec, &inDumpFile)) |
| 1148 | return NULL; |
| 1149 | _err = DumpControlHierarchy(inWindow, |
| 1150 | &inDumpFile); |
| 1151 | if (_err != noErr) return PyMac_Error(_err); |
| 1152 | Py_INCREF(Py_None); |
| 1153 | _res = Py_None; |
| 1154 | return _res; |
| 1155 | } |
| 1156 | |
| 1157 | static PyObject *Ctl_CreateRootControl(_self, _args) |
| 1158 | PyObject *_self; |
| 1159 | PyObject *_args; |
| 1160 | { |
| 1161 | PyObject *_res = NULL; |
| 1162 | OSErr _err; |
| 1163 | WindowPtr inWindow; |
| 1164 | ControlHandle outControl; |
| 1165 | if (!PyArg_ParseTuple(_args, "O&", |
| 1166 | WinObj_Convert, &inWindow)) |
| 1167 | return NULL; |
| 1168 | _err = CreateRootControl(inWindow, |
| 1169 | &outControl); |
| 1170 | if (_err != noErr) return PyMac_Error(_err); |
| 1171 | _res = Py_BuildValue("O&", |
| 1172 | CtlObj_WhichControl, outControl); |
| 1173 | return _res; |
| 1174 | } |
| 1175 | |
| 1176 | static PyObject *Ctl_GetRootControl(_self, _args) |
| 1177 | PyObject *_self; |
| 1178 | PyObject *_args; |
| 1179 | { |
| 1180 | PyObject *_res = NULL; |
| 1181 | OSErr _err; |
| 1182 | WindowPtr inWindow; |
| 1183 | ControlHandle outControl; |
| 1184 | if (!PyArg_ParseTuple(_args, "O&", |
| 1185 | WinObj_Convert, &inWindow)) |
| 1186 | return NULL; |
| 1187 | _err = GetRootControl(inWindow, |
| 1188 | &outControl); |
| 1189 | if (_err != noErr) return PyMac_Error(_err); |
| 1190 | _res = Py_BuildValue("O&", |
| 1191 | CtlObj_WhichControl, outControl); |
| 1192 | return _res; |
| 1193 | } |
| 1194 | |
| 1195 | static PyObject *Ctl_GetKeyboardFocus(_self, _args) |
| 1196 | PyObject *_self; |
| 1197 | PyObject *_args; |
| 1198 | { |
| 1199 | PyObject *_res = NULL; |
| 1200 | OSErr _err; |
| 1201 | WindowPtr inWindow; |
| 1202 | ControlHandle outControl; |
| 1203 | if (!PyArg_ParseTuple(_args, "O&", |
| 1204 | WinObj_Convert, &inWindow)) |
| 1205 | return NULL; |
| 1206 | _err = GetKeyboardFocus(inWindow, |
| 1207 | &outControl); |
| 1208 | if (_err != noErr) return PyMac_Error(_err); |
| 1209 | _res = Py_BuildValue("O&", |
| 1210 | CtlObj_WhichControl, outControl); |
| 1211 | return _res; |
| 1212 | } |
| 1213 | |
| 1214 | static PyObject *Ctl_SetKeyboardFocus(_self, _args) |
| 1215 | PyObject *_self; |
| 1216 | PyObject *_args; |
| 1217 | { |
| 1218 | PyObject *_res = NULL; |
| 1219 | OSErr _err; |
| 1220 | WindowPtr inWindow; |
| 1221 | ControlHandle inControl; |
| 1222 | ControlFocusPart inPart; |
| 1223 | if (!PyArg_ParseTuple(_args, "O&O&h", |
| 1224 | WinObj_Convert, &inWindow, |
| 1225 | CtlObj_Convert, &inControl, |
| 1226 | &inPart)) |
| 1227 | return NULL; |
| 1228 | _err = SetKeyboardFocus(inWindow, |
| 1229 | inControl, |
| 1230 | inPart); |
| 1231 | if (_err != noErr) return PyMac_Error(_err); |
| 1232 | Py_INCREF(Py_None); |
| 1233 | _res = Py_None; |
| 1234 | return _res; |
| 1235 | } |
| 1236 | |
| 1237 | static PyObject *Ctl_AdvanceKeyboardFocus(_self, _args) |
| 1238 | PyObject *_self; |
| 1239 | PyObject *_args; |
| 1240 | { |
| 1241 | PyObject *_res = NULL; |
| 1242 | OSErr _err; |
| 1243 | WindowPtr inWindow; |
| 1244 | if (!PyArg_ParseTuple(_args, "O&", |
| 1245 | WinObj_Convert, &inWindow)) |
| 1246 | return NULL; |
| 1247 | _err = AdvanceKeyboardFocus(inWindow); |
| 1248 | if (_err != noErr) return PyMac_Error(_err); |
| 1249 | Py_INCREF(Py_None); |
| 1250 | _res = Py_None; |
| 1251 | return _res; |
| 1252 | } |
| 1253 | |
| 1254 | static PyObject *Ctl_ReverseKeyboardFocus(_self, _args) |
| 1255 | PyObject *_self; |
| 1256 | PyObject *_args; |
| 1257 | { |
| 1258 | PyObject *_res = NULL; |
| 1259 | OSErr _err; |
| 1260 | WindowPtr inWindow; |
| 1261 | if (!PyArg_ParseTuple(_args, "O&", |
| 1262 | WinObj_Convert, &inWindow)) |
| 1263 | return NULL; |
| 1264 | _err = ReverseKeyboardFocus(inWindow); |
| 1265 | if (_err != noErr) return PyMac_Error(_err); |
| 1266 | Py_INCREF(Py_None); |
| 1267 | _res = Py_None; |
| 1268 | return _res; |
| 1269 | } |
| 1270 | |
| 1271 | static PyObject *Ctl_ClearKeyboardFocus(_self, _args) |
| 1272 | PyObject *_self; |
| 1273 | PyObject *_args; |
| 1274 | { |
| 1275 | PyObject *_res = NULL; |
| 1276 | OSErr _err; |
| 1277 | WindowPtr inWindow; |
| 1278 | if (!PyArg_ParseTuple(_args, "O&", |
| 1279 | WinObj_Convert, &inWindow)) |
| 1280 | return NULL; |
| 1281 | _err = ClearKeyboardFocus(inWindow); |
| 1282 | if (_err != noErr) return PyMac_Error(_err); |
| 1283 | Py_INCREF(Py_None); |
| 1284 | _res = Py_None; |
| 1285 | return _res; |
| 1286 | } |
| 1287 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1288 | static PyMethodDef Ctl_methods[] = { |
| 1289 | {"NewControl", (PyCFunction)Ctl_NewControl, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1290 | "(WindowPtr owningWindow, Rect boundsRect, Str255 controlTitle, Boolean initiallyVisible, SInt16 initialValue, SInt16 minimumValue, SInt16 maximumValue, SInt16 procID, SInt32 controlReference) -> (ControlHandle _rv)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1291 | {"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1292 | "(SInt16 resourceID, WindowPtr owningWindow) -> (ControlHandle _rv)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1293 | {"DrawControls", (PyCFunction)Ctl_DrawControls, 1, |
| 1294 | "(WindowPtr theWindow) -> None"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1295 | {"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1, |
Jack Jansen | 2b72417 | 1996-04-10 14:48:19 +0000 | [diff] [blame] | 1296 | "(WindowPtr theWindow, RgnHandle updateRegion) -> None"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1297 | {"FindControl", (PyCFunction)Ctl_FindControl, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1298 | "(Point testPoint, WindowPtr theWindow) -> (ControlPartCode _rv, ControlHandle theControl)"}, |
| 1299 | {"FindControlUnderMouse", (PyCFunction)Ctl_FindControlUnderMouse, 1, |
| 1300 | "(Point inWhere, WindowPtr inWindow) -> (ControlHandle _rv, SInt16 outPart)"}, |
| 1301 | {"IdleControls", (PyCFunction)Ctl_IdleControls, 1, |
| 1302 | "(WindowPtr inWindow) -> None"}, |
| 1303 | {"DumpControlHierarchy", (PyCFunction)Ctl_DumpControlHierarchy, 1, |
| 1304 | "(WindowPtr inWindow, FSSpec inDumpFile) -> None"}, |
| 1305 | {"CreateRootControl", (PyCFunction)Ctl_CreateRootControl, 1, |
| 1306 | "(WindowPtr inWindow) -> (ControlHandle outControl)"}, |
| 1307 | {"GetRootControl", (PyCFunction)Ctl_GetRootControl, 1, |
| 1308 | "(WindowPtr inWindow) -> (ControlHandle outControl)"}, |
| 1309 | {"GetKeyboardFocus", (PyCFunction)Ctl_GetKeyboardFocus, 1, |
| 1310 | "(WindowPtr inWindow) -> (ControlHandle outControl)"}, |
| 1311 | {"SetKeyboardFocus", (PyCFunction)Ctl_SetKeyboardFocus, 1, |
| 1312 | "(WindowPtr inWindow, ControlHandle inControl, ControlFocusPart inPart) -> None"}, |
| 1313 | {"AdvanceKeyboardFocus", (PyCFunction)Ctl_AdvanceKeyboardFocus, 1, |
| 1314 | "(WindowPtr inWindow) -> None"}, |
| 1315 | {"ReverseKeyboardFocus", (PyCFunction)Ctl_ReverseKeyboardFocus, 1, |
| 1316 | "(WindowPtr inWindow) -> None"}, |
| 1317 | {"ClearKeyboardFocus", (PyCFunction)Ctl_ClearKeyboardFocus, 1, |
| 1318 | "(WindowPtr inWindow) -> None"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1319 | {NULL, NULL, 0} |
| 1320 | }; |
| 1321 | |
| 1322 | |
| 1323 | |
| 1324 | PyObject * |
| 1325 | CtlObj_WhichControl(ControlHandle c) |
| 1326 | { |
| 1327 | PyObject *it; |
| 1328 | |
| 1329 | /* XXX What if we find a control belonging to some other package? */ |
| 1330 | if (c == NULL) |
| 1331 | it = NULL; |
| 1332 | else |
Jack Jansen | 85ae4a8 | 1997-04-08 15:26:03 +0000 | [diff] [blame] | 1333 | it = (PyObject *) GetControlReference(c); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1334 | if (it == NULL || ((ControlObject *)it)->ob_itself != c) |
| 1335 | it = Py_None; |
| 1336 | Py_INCREF(it); |
| 1337 | return it; |
| 1338 | } |
| 1339 | |
Jack Jansen | 848250c | 1998-05-28 14:20:09 +0000 | [diff] [blame^] | 1340 | static int |
| 1341 | settrackfunc(obj) |
| 1342 | PyObject *obj; |
| 1343 | { |
| 1344 | if (tracker) { |
| 1345 | PyErr_SetString(Ctl_Error, "Tracker function in use"); |
| 1346 | return 0; |
| 1347 | } |
| 1348 | tracker = obj; |
| 1349 | Py_INCREF(tracker); |
| 1350 | } |
| 1351 | |
| 1352 | static void |
| 1353 | clrtrackfunc() |
| 1354 | { |
| 1355 | Py_XDECREF(tracker); |
| 1356 | tracker = 0; |
| 1357 | } |
| 1358 | |
| 1359 | static pascal void |
| 1360 | mytracker(ctl, part) |
| 1361 | ControlHandle ctl; |
| 1362 | short part; |
| 1363 | { |
| 1364 | PyObject *args, *rv=0; |
| 1365 | |
| 1366 | args = Py_BuildValue("(O&i)", CtlObj_WhichControl, ctl, (int)part); |
| 1367 | if (args && tracker) { |
| 1368 | rv = PyEval_CallObject(tracker, args); |
| 1369 | Py_DECREF(args); |
| 1370 | } |
| 1371 | if (rv) |
| 1372 | Py_DECREF(rv); |
| 1373 | else |
| 1374 | fprintf(stderr, "TrackControl: exception in tracker function\n"); |
| 1375 | } |
| 1376 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1377 | |
| 1378 | void initCtl() |
| 1379 | { |
| 1380 | PyObject *m; |
| 1381 | PyObject *d; |
| 1382 | |
| 1383 | |
| 1384 | |
Jack Jansen | 848250c | 1998-05-28 14:20:09 +0000 | [diff] [blame^] | 1385 | mytracker_upp = NewControlActionProc(mytracker); |
| 1386 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1387 | |
| 1388 | m = Py_InitModule("Ctl", Ctl_methods); |
| 1389 | d = PyModule_GetDict(m); |
| 1390 | Ctl_Error = PyMac_GetOSErrException(); |
| 1391 | if (Ctl_Error == NULL || |
| 1392 | PyDict_SetItemString(d, "Error", Ctl_Error) != 0) |
| 1393 | Py_FatalError("can't initialize Ctl.Error"); |
Jack Jansen | a755e68 | 1997-09-20 17:40:22 +0000 | [diff] [blame] | 1394 | Control_Type.ob_type = &PyType_Type; |
| 1395 | Py_INCREF(&Control_Type); |
| 1396 | if (PyDict_SetItemString(d, "ControlType", (PyObject *)&Control_Type) != 0) |
| 1397 | Py_FatalError("can't initialize ControlType"); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | /* ========================= End module Ctl ========================= */ |
| 1401 | |