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 | |
Jack Jansen | 4c70413 | 1998-06-19 13:35:14 +0000 | [diff] [blame^] | 869 | static PyObject *CtlObj_GetPopupData(_self, _args) |
| 870 | ControlObject *_self; |
| 871 | PyObject *_args; |
| 872 | { |
| 873 | PyObject *_res = NULL; |
| 874 | |
| 875 | PopupPrivateDataHandle hdl; |
| 876 | |
| 877 | if ( (*_self->ob_itself)->contrlData == NULL ) { |
| 878 | PyErr_SetString(Ctl_Error, "No contrlData handle in control"); |
| 879 | return 0; |
| 880 | } |
| 881 | hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData; |
| 882 | HLock((Handle)hdl); |
| 883 | _res = Py_BuildValue("O&i", MenuObj_New, (*hdl)->mHandle, (int)(*hdl)->mID); |
| 884 | HUnlock((Handle)hdl); |
| 885 | return _res; |
| 886 | |
| 887 | } |
| 888 | |
| 889 | static PyObject *CtlObj_SetPopupData(_self, _args) |
| 890 | ControlObject *_self; |
| 891 | PyObject *_args; |
| 892 | { |
| 893 | PyObject *_res = NULL; |
| 894 | |
| 895 | PopupPrivateDataHandle hdl; |
| 896 | MenuHandle mHandle; |
| 897 | short mID; |
| 898 | |
| 899 | if (!PyArg_ParseTuple(_args, "O&h", MenuObj_Convert, &mHandle, &mID) ) |
| 900 | return 0; |
| 901 | if ( (*_self->ob_itself)->contrlData == NULL ) { |
| 902 | PyErr_SetString(Ctl_Error, "No contrlData handle in control"); |
| 903 | return 0; |
| 904 | } |
| 905 | hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData; |
| 906 | (*hdl)->mHandle = mHandle; |
| 907 | (*hdl)->mID = mID; |
| 908 | Py_INCREF(Py_None); |
| 909 | return Py_None; |
| 910 | |
| 911 | } |
| 912 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 913 | static PyMethodDef CtlObj_methods[] = { |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 914 | {"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1, |
| 915 | "(ControlPartCode hiliteState) -> None"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 916 | {"ShowControl", (PyCFunction)CtlObj_ShowControl, 1, |
| 917 | "() -> None"}, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 918 | {"HideControl", (PyCFunction)CtlObj_HideControl, 1, |
| 919 | "() -> None"}, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 920 | {"IsControlActive", (PyCFunction)CtlObj_IsControlActive, 1, |
| 921 | "() -> (Boolean _rv)"}, |
| 922 | {"IsControlVisible", (PyCFunction)CtlObj_IsControlVisible, 1, |
| 923 | "() -> (Boolean _rv)"}, |
| 924 | {"ActivateControl", (PyCFunction)CtlObj_ActivateControl, 1, |
| 925 | "() -> None"}, |
| 926 | {"DeactivateControl", (PyCFunction)CtlObj_DeactivateControl, 1, |
| 927 | "() -> None"}, |
| 928 | {"SetControlVisibility", (PyCFunction)CtlObj_SetControlVisibility, 1, |
| 929 | "(Boolean inIsVisible, Boolean inDoDraw) -> None"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 930 | {"Draw1Control", (PyCFunction)CtlObj_Draw1Control, 1, |
| 931 | "() -> None"}, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 932 | {"GetBestControlRect", (PyCFunction)CtlObj_GetBestControlRect, 1, |
| 933 | "() -> (Rect outRect, SInt16 outBaseLineOffset)"}, |
| 934 | {"SetControlFontStyle", (PyCFunction)CtlObj_SetControlFontStyle, 1, |
| 935 | "(ControlFontStyleRec inStyle) -> None"}, |
| 936 | {"DrawControlInCurrentPort", (PyCFunction)CtlObj_DrawControlInCurrentPort, 1, |
| 937 | "() -> None"}, |
| 938 | {"SetUpControlBackground", (PyCFunction)CtlObj_SetUpControlBackground, 1, |
| 939 | "(SInt16 inDepth, Boolean inIsColorDevice) -> None"}, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 940 | {"DragControl", (PyCFunction)CtlObj_DragControl, 1, |
Jack Jansen | 754d4a4 | 1995-11-14 10:41:55 +0000 | [diff] [blame] | 941 | "(Point startPoint, Rect limitRect, Rect slopRect, DragConstraint axis) -> None"}, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 942 | {"TestControl", (PyCFunction)CtlObj_TestControl, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 943 | "(Point testPoint) -> (ControlPartCode _rv)"}, |
| 944 | {"HandleControlKey", (PyCFunction)CtlObj_HandleControlKey, 1, |
| 945 | "(SInt16 inKeyCode, SInt16 inCharCode, SInt16 inModifiers) -> (SInt16 _rv)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 946 | {"MoveControl", (PyCFunction)CtlObj_MoveControl, 1, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 947 | "(SInt16 h, SInt16 v) -> None"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 948 | {"SizeControl", (PyCFunction)CtlObj_SizeControl, 1, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 949 | "(SInt16 w, SInt16 h) -> None"}, |
| 950 | {"SetControlTitle", (PyCFunction)CtlObj_SetControlTitle, 1, |
| 951 | "(Str255 title) -> None"}, |
| 952 | {"GetControlTitle", (PyCFunction)CtlObj_GetControlTitle, 1, |
| 953 | "(Str255 title) -> None"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 954 | {"GetControlValue", (PyCFunction)CtlObj_GetControlValue, 1, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 955 | "() -> (SInt16 _rv)"}, |
| 956 | {"SetControlValue", (PyCFunction)CtlObj_SetControlValue, 1, |
| 957 | "(SInt16 newValue) -> None"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 958 | {"GetControlMinimum", (PyCFunction)CtlObj_GetControlMinimum, 1, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 959 | "() -> (SInt16 _rv)"}, |
| 960 | {"SetControlMinimum", (PyCFunction)CtlObj_SetControlMinimum, 1, |
| 961 | "(SInt16 newMinimum) -> None"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 962 | {"GetControlMaximum", (PyCFunction)CtlObj_GetControlMaximum, 1, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 963 | "() -> (SInt16 _rv)"}, |
| 964 | {"SetControlMaximum", (PyCFunction)CtlObj_SetControlMaximum, 1, |
| 965 | "(SInt16 newMaximum) -> None"}, |
| 966 | {"GetControlVariant", (PyCFunction)CtlObj_GetControlVariant, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 967 | "() -> (ControlVariant _rv)"}, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 968 | {"SetControlReference", (PyCFunction)CtlObj_SetControlReference, 1, |
| 969 | "(SInt32 data) -> None"}, |
| 970 | {"GetControlReference", (PyCFunction)CtlObj_GetControlReference, 1, |
| 971 | "() -> (SInt32 _rv)"}, |
Jack Jansen | c7fefed | 1997-08-15 14:32:18 +0000 | [diff] [blame] | 972 | {"GetAuxiliaryControlRecord", (PyCFunction)CtlObj_GetAuxiliaryControlRecord, 1, |
| 973 | "() -> (Boolean _rv, AuxCtlHandle acHndl)"}, |
| 974 | {"SetControlColor", (PyCFunction)CtlObj_SetControlColor, 1, |
| 975 | "(CCTabHandle newColorTable) -> None"}, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 976 | {"SendControlMessage", (PyCFunction)CtlObj_SendControlMessage, 1, |
| 977 | "(SInt16 inMessage, SInt32 inParam) -> (SInt32 _rv)"}, |
| 978 | {"EmbedControl", (PyCFunction)CtlObj_EmbedControl, 1, |
| 979 | "(ControlHandle inContainer) -> None"}, |
| 980 | {"AutoEmbedControl", (PyCFunction)CtlObj_AutoEmbedControl, 1, |
| 981 | "(WindowPtr inWindow) -> None"}, |
| 982 | {"GetSuperControl", (PyCFunction)CtlObj_GetSuperControl, 1, |
| 983 | "() -> (ControlHandle outParent)"}, |
| 984 | {"CountSubControls", (PyCFunction)CtlObj_CountSubControls, 1, |
| 985 | "() -> (SInt16 outNumChildren)"}, |
| 986 | {"GetIndexedSubControl", (PyCFunction)CtlObj_GetIndexedSubControl, 1, |
| 987 | "(SInt16 inIndex) -> (ControlHandle outSubControl)"}, |
| 988 | {"SetControlSupervisor", (PyCFunction)CtlObj_SetControlSupervisor, 1, |
| 989 | "(ControlHandle inBoss) -> None"}, |
| 990 | {"GetControlFeatures", (PyCFunction)CtlObj_GetControlFeatures, 1, |
| 991 | "() -> (UInt32 outFeatures)"}, |
| 992 | {"GetControlDataSize", (PyCFunction)CtlObj_GetControlDataSize, 1, |
| 993 | "(ControlPartCode inPart, ResType inTagName) -> (Size outMaxSize)"}, |
Jack Jansen | 5d56f4b | 1995-06-18 20:16:33 +0000 | [diff] [blame] | 994 | {"as_Resource", (PyCFunction)CtlObj_as_Resource, 1, |
| 995 | "Return this Control as a Resource"}, |
Jack Jansen | cfb60ee | 1996-10-01 10:46:46 +0000 | [diff] [blame] | 996 | {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1, |
| 997 | "() -> None"}, |
Jack Jansen | 848250c | 1998-05-28 14:20:09 +0000 | [diff] [blame] | 998 | {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1, |
| 999 | NULL}, |
Jack Jansen | 4c70413 | 1998-06-19 13:35:14 +0000 | [diff] [blame^] | 1000 | {"GetPopupData", (PyCFunction)CtlObj_GetPopupData, 1, |
| 1001 | NULL}, |
| 1002 | {"SetPopupData", (PyCFunction)CtlObj_SetPopupData, 1, |
| 1003 | NULL}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1004 | {NULL, NULL, 0} |
| 1005 | }; |
| 1006 | |
| 1007 | PyMethodChain CtlObj_chain = { CtlObj_methods, NULL }; |
| 1008 | |
| 1009 | static PyObject *CtlObj_getattr(self, name) |
| 1010 | ControlObject *self; |
| 1011 | char *name; |
| 1012 | { |
| 1013 | return Py_FindMethodInChain(&CtlObj_chain, (PyObject *)self, name); |
| 1014 | } |
| 1015 | |
| 1016 | #define CtlObj_setattr NULL |
| 1017 | |
| 1018 | PyTypeObject Control_Type = { |
| 1019 | PyObject_HEAD_INIT(&PyType_Type) |
| 1020 | 0, /*ob_size*/ |
| 1021 | "Control", /*tp_name*/ |
| 1022 | sizeof(ControlObject), /*tp_basicsize*/ |
| 1023 | 0, /*tp_itemsize*/ |
| 1024 | /* methods */ |
| 1025 | (destructor) CtlObj_dealloc, /*tp_dealloc*/ |
| 1026 | 0, /*tp_print*/ |
| 1027 | (getattrfunc) CtlObj_getattr, /*tp_getattr*/ |
| 1028 | (setattrfunc) CtlObj_setattr, /*tp_setattr*/ |
| 1029 | }; |
| 1030 | |
| 1031 | /* -------------------- End object type Control --------------------- */ |
| 1032 | |
| 1033 | |
| 1034 | static PyObject *Ctl_NewControl(_self, _args) |
| 1035 | PyObject *_self; |
| 1036 | PyObject *_args; |
| 1037 | { |
| 1038 | PyObject *_res = NULL; |
| 1039 | ControlHandle _rv; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1040 | WindowPtr owningWindow; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1041 | Rect boundsRect; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1042 | Str255 controlTitle; |
| 1043 | Boolean initiallyVisible; |
| 1044 | SInt16 initialValue; |
| 1045 | SInt16 minimumValue; |
| 1046 | SInt16 maximumValue; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 1047 | SInt16 procID; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1048 | SInt32 controlReference; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1049 | if (!PyArg_ParseTuple(_args, "O&O&O&bhhhhl", |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1050 | WinObj_Convert, &owningWindow, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1051 | PyMac_GetRect, &boundsRect, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1052 | PyMac_GetStr255, controlTitle, |
| 1053 | &initiallyVisible, |
| 1054 | &initialValue, |
| 1055 | &minimumValue, |
| 1056 | &maximumValue, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1057 | &procID, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1058 | &controlReference)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1059 | return NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1060 | _rv = NewControl(owningWindow, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1061 | &boundsRect, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1062 | controlTitle, |
| 1063 | initiallyVisible, |
| 1064 | initialValue, |
| 1065 | minimumValue, |
| 1066 | maximumValue, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1067 | procID, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1068 | controlReference); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1069 | _res = Py_BuildValue("O&", |
| 1070 | CtlObj_New, _rv); |
| 1071 | return _res; |
| 1072 | } |
| 1073 | |
| 1074 | static PyObject *Ctl_GetNewControl(_self, _args) |
| 1075 | PyObject *_self; |
| 1076 | PyObject *_args; |
| 1077 | { |
| 1078 | PyObject *_res = NULL; |
| 1079 | ControlHandle _rv; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1080 | SInt16 resourceID; |
| 1081 | WindowPtr owningWindow; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1082 | if (!PyArg_ParseTuple(_args, "hO&", |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1083 | &resourceID, |
| 1084 | WinObj_Convert, &owningWindow)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1085 | return NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1086 | _rv = GetNewControl(resourceID, |
| 1087 | owningWindow); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1088 | _res = Py_BuildValue("O&", |
| 1089 | CtlObj_New, _rv); |
| 1090 | return _res; |
| 1091 | } |
| 1092 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1093 | static PyObject *Ctl_DrawControls(_self, _args) |
| 1094 | PyObject *_self; |
| 1095 | PyObject *_args; |
| 1096 | { |
| 1097 | PyObject *_res = NULL; |
| 1098 | WindowPtr theWindow; |
| 1099 | if (!PyArg_ParseTuple(_args, "O&", |
| 1100 | WinObj_Convert, &theWindow)) |
| 1101 | return NULL; |
| 1102 | DrawControls(theWindow); |
| 1103 | Py_INCREF(Py_None); |
| 1104 | _res = Py_None; |
| 1105 | return _res; |
| 1106 | } |
| 1107 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1108 | static PyObject *Ctl_UpdateControls(_self, _args) |
| 1109 | PyObject *_self; |
| 1110 | PyObject *_args; |
| 1111 | { |
| 1112 | PyObject *_res = NULL; |
| 1113 | WindowPtr theWindow; |
Jack Jansen | 2b72417 | 1996-04-10 14:48:19 +0000 | [diff] [blame] | 1114 | RgnHandle updateRegion; |
| 1115 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 1116 | WinObj_Convert, &theWindow, |
| 1117 | ResObj_Convert, &updateRegion)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1118 | return NULL; |
| 1119 | UpdateControls(theWindow, |
Jack Jansen | 2b72417 | 1996-04-10 14:48:19 +0000 | [diff] [blame] | 1120 | updateRegion); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1121 | Py_INCREF(Py_None); |
| 1122 | _res = Py_None; |
| 1123 | return _res; |
| 1124 | } |
| 1125 | |
| 1126 | static PyObject *Ctl_FindControl(_self, _args) |
| 1127 | PyObject *_self; |
| 1128 | PyObject *_args; |
| 1129 | { |
| 1130 | PyObject *_res = NULL; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 1131 | ControlPartCode _rv; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1132 | Point testPoint; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1133 | WindowPtr theWindow; |
| 1134 | ControlHandle theControl; |
| 1135 | if (!PyArg_ParseTuple(_args, "O&O&", |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1136 | PyMac_GetPoint, &testPoint, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1137 | WinObj_Convert, &theWindow)) |
| 1138 | return NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1139 | _rv = FindControl(testPoint, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1140 | theWindow, |
| 1141 | &theControl); |
| 1142 | _res = Py_BuildValue("hO&", |
| 1143 | _rv, |
| 1144 | CtlObj_WhichControl, theControl); |
| 1145 | return _res; |
| 1146 | } |
| 1147 | |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1148 | static PyObject *Ctl_FindControlUnderMouse(_self, _args) |
| 1149 | PyObject *_self; |
| 1150 | PyObject *_args; |
| 1151 | { |
| 1152 | PyObject *_res = NULL; |
| 1153 | ControlHandle _rv; |
| 1154 | Point inWhere; |
| 1155 | WindowPtr inWindow; |
| 1156 | SInt16 outPart; |
| 1157 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 1158 | PyMac_GetPoint, &inWhere, |
| 1159 | WinObj_Convert, &inWindow)) |
| 1160 | return NULL; |
| 1161 | _rv = FindControlUnderMouse(inWhere, |
| 1162 | inWindow, |
| 1163 | &outPart); |
| 1164 | _res = Py_BuildValue("O&h", |
| 1165 | CtlObj_New, _rv, |
| 1166 | outPart); |
| 1167 | return _res; |
| 1168 | } |
| 1169 | |
| 1170 | static PyObject *Ctl_IdleControls(_self, _args) |
| 1171 | PyObject *_self; |
| 1172 | PyObject *_args; |
| 1173 | { |
| 1174 | PyObject *_res = NULL; |
| 1175 | WindowPtr inWindow; |
| 1176 | if (!PyArg_ParseTuple(_args, "O&", |
| 1177 | WinObj_Convert, &inWindow)) |
| 1178 | return NULL; |
| 1179 | IdleControls(inWindow); |
| 1180 | Py_INCREF(Py_None); |
| 1181 | _res = Py_None; |
| 1182 | return _res; |
| 1183 | } |
| 1184 | |
| 1185 | static PyObject *Ctl_DumpControlHierarchy(_self, _args) |
| 1186 | PyObject *_self; |
| 1187 | PyObject *_args; |
| 1188 | { |
| 1189 | PyObject *_res = NULL; |
| 1190 | OSErr _err; |
| 1191 | WindowPtr inWindow; |
| 1192 | FSSpec inDumpFile; |
| 1193 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 1194 | WinObj_Convert, &inWindow, |
| 1195 | PyMac_GetFSSpec, &inDumpFile)) |
| 1196 | return NULL; |
| 1197 | _err = DumpControlHierarchy(inWindow, |
| 1198 | &inDumpFile); |
| 1199 | if (_err != noErr) return PyMac_Error(_err); |
| 1200 | Py_INCREF(Py_None); |
| 1201 | _res = Py_None; |
| 1202 | return _res; |
| 1203 | } |
| 1204 | |
| 1205 | static PyObject *Ctl_CreateRootControl(_self, _args) |
| 1206 | PyObject *_self; |
| 1207 | PyObject *_args; |
| 1208 | { |
| 1209 | PyObject *_res = NULL; |
| 1210 | OSErr _err; |
| 1211 | WindowPtr inWindow; |
| 1212 | ControlHandle outControl; |
| 1213 | if (!PyArg_ParseTuple(_args, "O&", |
| 1214 | WinObj_Convert, &inWindow)) |
| 1215 | return NULL; |
| 1216 | _err = CreateRootControl(inWindow, |
| 1217 | &outControl); |
| 1218 | if (_err != noErr) return PyMac_Error(_err); |
| 1219 | _res = Py_BuildValue("O&", |
| 1220 | CtlObj_WhichControl, outControl); |
| 1221 | return _res; |
| 1222 | } |
| 1223 | |
| 1224 | static PyObject *Ctl_GetRootControl(_self, _args) |
| 1225 | PyObject *_self; |
| 1226 | PyObject *_args; |
| 1227 | { |
| 1228 | PyObject *_res = NULL; |
| 1229 | OSErr _err; |
| 1230 | WindowPtr inWindow; |
| 1231 | ControlHandle outControl; |
| 1232 | if (!PyArg_ParseTuple(_args, "O&", |
| 1233 | WinObj_Convert, &inWindow)) |
| 1234 | return NULL; |
| 1235 | _err = GetRootControl(inWindow, |
| 1236 | &outControl); |
| 1237 | if (_err != noErr) return PyMac_Error(_err); |
| 1238 | _res = Py_BuildValue("O&", |
| 1239 | CtlObj_WhichControl, outControl); |
| 1240 | return _res; |
| 1241 | } |
| 1242 | |
| 1243 | static PyObject *Ctl_GetKeyboardFocus(_self, _args) |
| 1244 | PyObject *_self; |
| 1245 | PyObject *_args; |
| 1246 | { |
| 1247 | PyObject *_res = NULL; |
| 1248 | OSErr _err; |
| 1249 | WindowPtr inWindow; |
| 1250 | ControlHandle outControl; |
| 1251 | if (!PyArg_ParseTuple(_args, "O&", |
| 1252 | WinObj_Convert, &inWindow)) |
| 1253 | return NULL; |
| 1254 | _err = GetKeyboardFocus(inWindow, |
| 1255 | &outControl); |
| 1256 | if (_err != noErr) return PyMac_Error(_err); |
| 1257 | _res = Py_BuildValue("O&", |
| 1258 | CtlObj_WhichControl, outControl); |
| 1259 | return _res; |
| 1260 | } |
| 1261 | |
| 1262 | static PyObject *Ctl_SetKeyboardFocus(_self, _args) |
| 1263 | PyObject *_self; |
| 1264 | PyObject *_args; |
| 1265 | { |
| 1266 | PyObject *_res = NULL; |
| 1267 | OSErr _err; |
| 1268 | WindowPtr inWindow; |
| 1269 | ControlHandle inControl; |
| 1270 | ControlFocusPart inPart; |
| 1271 | if (!PyArg_ParseTuple(_args, "O&O&h", |
| 1272 | WinObj_Convert, &inWindow, |
| 1273 | CtlObj_Convert, &inControl, |
| 1274 | &inPart)) |
| 1275 | return NULL; |
| 1276 | _err = SetKeyboardFocus(inWindow, |
| 1277 | inControl, |
| 1278 | inPart); |
| 1279 | if (_err != noErr) return PyMac_Error(_err); |
| 1280 | Py_INCREF(Py_None); |
| 1281 | _res = Py_None; |
| 1282 | return _res; |
| 1283 | } |
| 1284 | |
| 1285 | static PyObject *Ctl_AdvanceKeyboardFocus(_self, _args) |
| 1286 | PyObject *_self; |
| 1287 | PyObject *_args; |
| 1288 | { |
| 1289 | PyObject *_res = NULL; |
| 1290 | OSErr _err; |
| 1291 | WindowPtr inWindow; |
| 1292 | if (!PyArg_ParseTuple(_args, "O&", |
| 1293 | WinObj_Convert, &inWindow)) |
| 1294 | return NULL; |
| 1295 | _err = AdvanceKeyboardFocus(inWindow); |
| 1296 | if (_err != noErr) return PyMac_Error(_err); |
| 1297 | Py_INCREF(Py_None); |
| 1298 | _res = Py_None; |
| 1299 | return _res; |
| 1300 | } |
| 1301 | |
| 1302 | static PyObject *Ctl_ReverseKeyboardFocus(_self, _args) |
| 1303 | PyObject *_self; |
| 1304 | PyObject *_args; |
| 1305 | { |
| 1306 | PyObject *_res = NULL; |
| 1307 | OSErr _err; |
| 1308 | WindowPtr inWindow; |
| 1309 | if (!PyArg_ParseTuple(_args, "O&", |
| 1310 | WinObj_Convert, &inWindow)) |
| 1311 | return NULL; |
| 1312 | _err = ReverseKeyboardFocus(inWindow); |
| 1313 | if (_err != noErr) return PyMac_Error(_err); |
| 1314 | Py_INCREF(Py_None); |
| 1315 | _res = Py_None; |
| 1316 | return _res; |
| 1317 | } |
| 1318 | |
| 1319 | static PyObject *Ctl_ClearKeyboardFocus(_self, _args) |
| 1320 | PyObject *_self; |
| 1321 | PyObject *_args; |
| 1322 | { |
| 1323 | PyObject *_res = NULL; |
| 1324 | OSErr _err; |
| 1325 | WindowPtr inWindow; |
| 1326 | if (!PyArg_ParseTuple(_args, "O&", |
| 1327 | WinObj_Convert, &inWindow)) |
| 1328 | return NULL; |
| 1329 | _err = ClearKeyboardFocus(inWindow); |
| 1330 | if (_err != noErr) return PyMac_Error(_err); |
| 1331 | Py_INCREF(Py_None); |
| 1332 | _res = Py_None; |
| 1333 | return _res; |
| 1334 | } |
| 1335 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1336 | static PyMethodDef Ctl_methods[] = { |
| 1337 | {"NewControl", (PyCFunction)Ctl_NewControl, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1338 | "(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] | 1339 | {"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1340 | "(SInt16 resourceID, WindowPtr owningWindow) -> (ControlHandle _rv)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1341 | {"DrawControls", (PyCFunction)Ctl_DrawControls, 1, |
| 1342 | "(WindowPtr theWindow) -> None"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1343 | {"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1, |
Jack Jansen | 2b72417 | 1996-04-10 14:48:19 +0000 | [diff] [blame] | 1344 | "(WindowPtr theWindow, RgnHandle updateRegion) -> None"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1345 | {"FindControl", (PyCFunction)Ctl_FindControl, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1346 | "(Point testPoint, WindowPtr theWindow) -> (ControlPartCode _rv, ControlHandle theControl)"}, |
| 1347 | {"FindControlUnderMouse", (PyCFunction)Ctl_FindControlUnderMouse, 1, |
| 1348 | "(Point inWhere, WindowPtr inWindow) -> (ControlHandle _rv, SInt16 outPart)"}, |
| 1349 | {"IdleControls", (PyCFunction)Ctl_IdleControls, 1, |
| 1350 | "(WindowPtr inWindow) -> None"}, |
| 1351 | {"DumpControlHierarchy", (PyCFunction)Ctl_DumpControlHierarchy, 1, |
| 1352 | "(WindowPtr inWindow, FSSpec inDumpFile) -> None"}, |
| 1353 | {"CreateRootControl", (PyCFunction)Ctl_CreateRootControl, 1, |
| 1354 | "(WindowPtr inWindow) -> (ControlHandle outControl)"}, |
| 1355 | {"GetRootControl", (PyCFunction)Ctl_GetRootControl, 1, |
| 1356 | "(WindowPtr inWindow) -> (ControlHandle outControl)"}, |
| 1357 | {"GetKeyboardFocus", (PyCFunction)Ctl_GetKeyboardFocus, 1, |
| 1358 | "(WindowPtr inWindow) -> (ControlHandle outControl)"}, |
| 1359 | {"SetKeyboardFocus", (PyCFunction)Ctl_SetKeyboardFocus, 1, |
| 1360 | "(WindowPtr inWindow, ControlHandle inControl, ControlFocusPart inPart) -> None"}, |
| 1361 | {"AdvanceKeyboardFocus", (PyCFunction)Ctl_AdvanceKeyboardFocus, 1, |
| 1362 | "(WindowPtr inWindow) -> None"}, |
| 1363 | {"ReverseKeyboardFocus", (PyCFunction)Ctl_ReverseKeyboardFocus, 1, |
| 1364 | "(WindowPtr inWindow) -> None"}, |
| 1365 | {"ClearKeyboardFocus", (PyCFunction)Ctl_ClearKeyboardFocus, 1, |
| 1366 | "(WindowPtr inWindow) -> None"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1367 | {NULL, NULL, 0} |
| 1368 | }; |
| 1369 | |
| 1370 | |
| 1371 | |
| 1372 | PyObject * |
| 1373 | CtlObj_WhichControl(ControlHandle c) |
| 1374 | { |
| 1375 | PyObject *it; |
| 1376 | |
| 1377 | /* XXX What if we find a control belonging to some other package? */ |
| 1378 | if (c == NULL) |
| 1379 | it = NULL; |
| 1380 | else |
Jack Jansen | 85ae4a8 | 1997-04-08 15:26:03 +0000 | [diff] [blame] | 1381 | it = (PyObject *) GetControlReference(c); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1382 | if (it == NULL || ((ControlObject *)it)->ob_itself != c) |
| 1383 | it = Py_None; |
| 1384 | Py_INCREF(it); |
| 1385 | return it; |
| 1386 | } |
| 1387 | |
Jack Jansen | 848250c | 1998-05-28 14:20:09 +0000 | [diff] [blame] | 1388 | static int |
| 1389 | settrackfunc(obj) |
| 1390 | PyObject *obj; |
| 1391 | { |
| 1392 | if (tracker) { |
| 1393 | PyErr_SetString(Ctl_Error, "Tracker function in use"); |
| 1394 | return 0; |
| 1395 | } |
| 1396 | tracker = obj; |
| 1397 | Py_INCREF(tracker); |
| 1398 | } |
| 1399 | |
| 1400 | static void |
| 1401 | clrtrackfunc() |
| 1402 | { |
| 1403 | Py_XDECREF(tracker); |
| 1404 | tracker = 0; |
| 1405 | } |
| 1406 | |
| 1407 | static pascal void |
| 1408 | mytracker(ctl, part) |
| 1409 | ControlHandle ctl; |
| 1410 | short part; |
| 1411 | { |
| 1412 | PyObject *args, *rv=0; |
| 1413 | |
| 1414 | args = Py_BuildValue("(O&i)", CtlObj_WhichControl, ctl, (int)part); |
| 1415 | if (args && tracker) { |
| 1416 | rv = PyEval_CallObject(tracker, args); |
| 1417 | Py_DECREF(args); |
| 1418 | } |
| 1419 | if (rv) |
| 1420 | Py_DECREF(rv); |
| 1421 | else |
| 1422 | fprintf(stderr, "TrackControl: exception in tracker function\n"); |
| 1423 | } |
| 1424 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1425 | |
| 1426 | void initCtl() |
| 1427 | { |
| 1428 | PyObject *m; |
| 1429 | PyObject *d; |
| 1430 | |
| 1431 | |
| 1432 | |
Jack Jansen | 848250c | 1998-05-28 14:20:09 +0000 | [diff] [blame] | 1433 | mytracker_upp = NewControlActionProc(mytracker); |
| 1434 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1435 | |
| 1436 | m = Py_InitModule("Ctl", Ctl_methods); |
| 1437 | d = PyModule_GetDict(m); |
| 1438 | Ctl_Error = PyMac_GetOSErrException(); |
| 1439 | if (Ctl_Error == NULL || |
| 1440 | PyDict_SetItemString(d, "Error", Ctl_Error) != 0) |
| 1441 | Py_FatalError("can't initialize Ctl.Error"); |
Jack Jansen | a755e68 | 1997-09-20 17:40:22 +0000 | [diff] [blame] | 1442 | Control_Type.ob_type = &PyType_Type; |
| 1443 | Py_INCREF(&Control_Type); |
| 1444 | if (PyDict_SetItemString(d, "ControlType", (PyObject *)&Control_Type) != 0) |
| 1445 | Py_FatalError("can't initialize ControlType"); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1446 | } |
| 1447 | |
| 1448 | /* ========================= End module Ctl ========================= */ |
| 1449 | |