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