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 | |
Jack Jansen | e058189 | 1999-02-07 14:02:03 +0000 | [diff] [blame] | 47 | #define as_Control(h) ((ControlHandle)h) |
Jack Jansen | a1a0fef | 1999-12-23 14:32:06 +0000 | [diff] [blame] | 48 | #define as_Resource(ctl) ((Handle)ctl) |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 49 | #ifdef TARGET_API_MAC_CARBON |
| 50 | #define GetControlRect(ctl, rectp) GetControlBounds(ctl, rectp) |
| 51 | #else |
Jack Jansen | 1a7d5b1 | 2000-03-21 16:25:23 +0000 | [diff] [blame] | 52 | #define GetControlRect(ctl, rectp) (*(rectp) = ((*(ctl))->contrlRect)) |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 53 | #endif |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 54 | #define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */ |
| 55 | |
| 56 | extern PyObject *CtlObj_WhichControl(ControlHandle); /* Forward */ |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 57 | extern PyObject *QdRGB_New(RGBColorPtr); |
| 58 | extern QdRGB_Convert(PyObject *, RGBColorPtr); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 59 | |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 60 | /* |
| 61 | ** Parse/generate ControlFontStyleRec records |
| 62 | */ |
| 63 | #if 0 /* Not needed */ |
| 64 | PyObject *ControlFontStyle_New(itself) |
| 65 | ControlFontStyleRec *itself; |
| 66 | { |
| 67 | |
| 68 | return Py_BuildValue("hhhhhhO&O&", itself->flags, itself->font, |
| 69 | itself->size, itself->style, itself->mode, itself->just, |
| 70 | QdRGB_New, &itself->foreColor, QdRGB_New, &itself->backColor); |
| 71 | } |
| 72 | #endif |
| 73 | |
| 74 | ControlFontStyle_Convert(v, itself) |
| 75 | PyObject *v; |
| 76 | ControlFontStyleRec *itself; |
| 77 | { |
| 78 | return PyArg_ParseTuple(v, "hhhhhhO&O&", &itself->flags, |
Jack Jansen | 24c3531 | 1999-12-09 22:49:51 +0000 | [diff] [blame] | 79 | &itself->font, &itself->size, &itself->style, &itself->mode, |
| 80 | &itself->just, QdRGB_Convert, &itself->foreColor, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 81 | QdRGB_Convert, &itself->backColor); |
| 82 | } |
| 83 | |
Jack Jansen | 24c3531 | 1999-12-09 22:49:51 +0000 | [diff] [blame] | 84 | /* TrackControl and HandleControlClick callback support */ |
Jack Jansen | 848250c | 1998-05-28 14:20:09 +0000 | [diff] [blame] | 85 | static PyObject *tracker; |
| 86 | static ControlActionUPP mytracker_upp; |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 87 | #ifndef TARGET_API_MAC_CARBON_NOTYET |
Jack Jansen | abc411b | 2000-03-20 16:09:09 +0000 | [diff] [blame] | 88 | static ControlUserPaneDrawUPP mydrawproc_upp; |
| 89 | static ControlUserPaneIdleUPP myidleproc_upp; |
Jack Jansen | a27e9fb | 2000-03-21 23:03:02 +0000 | [diff] [blame] | 90 | static ControlUserPaneHitTestUPP myhittestproc_upp; |
| 91 | static ControlUserPaneTrackingUPP mytrackingproc_upp; |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 92 | #endif |
Jack Jansen | 848250c | 1998-05-28 14:20:09 +0000 | [diff] [blame] | 93 | |
| 94 | extern int settrackfunc(PyObject *); /* forward */ |
| 95 | extern void clrtrackfunc(void); /* forward */ |
Jack Jansen | 85152b9 | 2000-07-11 21:12:55 +0000 | [diff] [blame^] | 96 | #ifndef TARGET_API_MAC_CARBON_NOTYET |
| 97 | staticforward int setcallback(PyObject *, OSType, PyObject *, UniversalProcPtr *); |
| 98 | #endif |
Jack Jansen | 848250c | 1998-05-28 14:20:09 +0000 | [diff] [blame] | 99 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 100 | static PyObject *Ctl_Error; |
| 101 | |
| 102 | /* ---------------------- Object type Control ----------------------- */ |
| 103 | |
| 104 | PyTypeObject Control_Type; |
| 105 | |
| 106 | #define CtlObj_Check(x) ((x)->ob_type == &Control_Type) |
| 107 | |
| 108 | typedef struct ControlObject { |
| 109 | PyObject_HEAD |
| 110 | ControlHandle ob_itself; |
Jack Jansen | abc411b | 2000-03-20 16:09:09 +0000 | [diff] [blame] | 111 | PyObject *ob_callbackdict; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 112 | } ControlObject; |
| 113 | |
| 114 | PyObject *CtlObj_New(itself) |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 115 | ControlHandle itself; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 116 | { |
| 117 | ControlObject *it; |
| 118 | if (itself == NULL) return PyMac_Error(resNotFound); |
| 119 | it = PyObject_NEW(ControlObject, &Control_Type); |
| 120 | if (it == NULL) return NULL; |
| 121 | it->ob_itself = itself; |
Jack Jansen | 85ae4a8 | 1997-04-08 15:26:03 +0000 | [diff] [blame] | 122 | SetControlReference(itself, (long)it); |
Jack Jansen | abc411b | 2000-03-20 16:09:09 +0000 | [diff] [blame] | 123 | it->ob_callbackdict = NULL; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 124 | return (PyObject *)it; |
| 125 | } |
| 126 | CtlObj_Convert(v, p_itself) |
| 127 | PyObject *v; |
| 128 | ControlHandle *p_itself; |
| 129 | { |
| 130 | if (!CtlObj_Check(v)) |
| 131 | { |
| 132 | PyErr_SetString(PyExc_TypeError, "Control required"); |
| 133 | return 0; |
| 134 | } |
| 135 | *p_itself = ((ControlObject *)v)->ob_itself; |
| 136 | return 1; |
| 137 | } |
| 138 | |
| 139 | static void CtlObj_dealloc(self) |
| 140 | ControlObject *self; |
| 141 | { |
Jack Jansen | abc411b | 2000-03-20 16:09:09 +0000 | [diff] [blame] | 142 | Py_XDECREF(self->ob_callbackdict); |
Jack Jansen | 24c3531 | 1999-12-09 22:49:51 +0000 | [diff] [blame] | 143 | 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] | 144 | PyMem_DEL(self); |
| 145 | } |
| 146 | |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 147 | static PyObject *CtlObj_HiliteControl(_self, _args) |
| 148 | ControlObject *_self; |
| 149 | PyObject *_args; |
| 150 | { |
| 151 | PyObject *_res = NULL; |
| 152 | ControlPartCode hiliteState; |
| 153 | if (!PyArg_ParseTuple(_args, "h", |
| 154 | &hiliteState)) |
| 155 | return NULL; |
| 156 | HiliteControl(_self->ob_itself, |
| 157 | hiliteState); |
| 158 | Py_INCREF(Py_None); |
| 159 | _res = Py_None; |
| 160 | return _res; |
| 161 | } |
| 162 | |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 163 | static PyObject *CtlObj_ShowControl(_self, _args) |
| 164 | ControlObject *_self; |
| 165 | PyObject *_args; |
| 166 | { |
| 167 | PyObject *_res = NULL; |
| 168 | if (!PyArg_ParseTuple(_args, "")) |
| 169 | return NULL; |
| 170 | ShowControl(_self->ob_itself); |
| 171 | Py_INCREF(Py_None); |
| 172 | _res = Py_None; |
| 173 | return _res; |
| 174 | } |
| 175 | |
| 176 | static PyObject *CtlObj_HideControl(_self, _args) |
| 177 | ControlObject *_self; |
| 178 | PyObject *_args; |
| 179 | { |
| 180 | PyObject *_res = NULL; |
| 181 | if (!PyArg_ParseTuple(_args, "")) |
| 182 | return NULL; |
| 183 | HideControl(_self->ob_itself); |
| 184 | Py_INCREF(Py_None); |
| 185 | _res = Py_None; |
| 186 | return _res; |
| 187 | } |
| 188 | |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 189 | static PyObject *CtlObj_IsControlActive(_self, _args) |
| 190 | ControlObject *_self; |
| 191 | PyObject *_args; |
| 192 | { |
| 193 | PyObject *_res = NULL; |
| 194 | Boolean _rv; |
| 195 | if (!PyArg_ParseTuple(_args, "")) |
| 196 | return NULL; |
| 197 | _rv = IsControlActive(_self->ob_itself); |
| 198 | _res = Py_BuildValue("b", |
| 199 | _rv); |
| 200 | return _res; |
| 201 | } |
| 202 | |
| 203 | static PyObject *CtlObj_IsControlVisible(_self, _args) |
| 204 | ControlObject *_self; |
| 205 | PyObject *_args; |
| 206 | { |
| 207 | PyObject *_res = NULL; |
| 208 | Boolean _rv; |
| 209 | if (!PyArg_ParseTuple(_args, "")) |
| 210 | return NULL; |
| 211 | _rv = IsControlVisible(_self->ob_itself); |
| 212 | _res = Py_BuildValue("b", |
| 213 | _rv); |
| 214 | return _res; |
| 215 | } |
| 216 | |
| 217 | static PyObject *CtlObj_ActivateControl(_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 = ActivateControl(_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_DeactivateControl(_self, _args) |
| 233 | ControlObject *_self; |
| 234 | PyObject *_args; |
| 235 | { |
| 236 | PyObject *_res = NULL; |
| 237 | OSErr _err; |
| 238 | if (!PyArg_ParseTuple(_args, "")) |
| 239 | return NULL; |
| 240 | _err = DeactivateControl(_self->ob_itself); |
| 241 | if (_err != noErr) return PyMac_Error(_err); |
| 242 | Py_INCREF(Py_None); |
| 243 | _res = Py_None; |
| 244 | return _res; |
| 245 | } |
| 246 | |
| 247 | static PyObject *CtlObj_SetControlVisibility(_self, _args) |
| 248 | ControlObject *_self; |
| 249 | PyObject *_args; |
| 250 | { |
| 251 | PyObject *_res = NULL; |
| 252 | OSErr _err; |
| 253 | Boolean inIsVisible; |
| 254 | Boolean inDoDraw; |
| 255 | if (!PyArg_ParseTuple(_args, "bb", |
| 256 | &inIsVisible, |
| 257 | &inDoDraw)) |
| 258 | return NULL; |
| 259 | _err = SetControlVisibility(_self->ob_itself, |
| 260 | inIsVisible, |
| 261 | inDoDraw); |
| 262 | if (_err != noErr) return PyMac_Error(_err); |
| 263 | Py_INCREF(Py_None); |
| 264 | _res = Py_None; |
| 265 | return _res; |
| 266 | } |
| 267 | |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 268 | static PyObject *CtlObj_Draw1Control(_self, _args) |
| 269 | ControlObject *_self; |
| 270 | PyObject *_args; |
| 271 | { |
| 272 | PyObject *_res = NULL; |
| 273 | if (!PyArg_ParseTuple(_args, "")) |
| 274 | return NULL; |
| 275 | Draw1Control(_self->ob_itself); |
| 276 | Py_INCREF(Py_None); |
| 277 | _res = Py_None; |
| 278 | return _res; |
| 279 | } |
| 280 | |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 281 | static PyObject *CtlObj_GetBestControlRect(_self, _args) |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 282 | ControlObject *_self; |
| 283 | PyObject *_args; |
| 284 | { |
| 285 | PyObject *_res = NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 286 | OSErr _err; |
| 287 | Rect outRect; |
| 288 | SInt16 outBaseLineOffset; |
| 289 | if (!PyArg_ParseTuple(_args, "")) |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 290 | return NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 291 | _err = GetBestControlRect(_self->ob_itself, |
| 292 | &outRect, |
| 293 | &outBaseLineOffset); |
| 294 | if (_err != noErr) return PyMac_Error(_err); |
| 295 | _res = Py_BuildValue("O&h", |
| 296 | PyMac_BuildRect, &outRect, |
| 297 | outBaseLineOffset); |
| 298 | return _res; |
| 299 | } |
| 300 | |
| 301 | static PyObject *CtlObj_SetControlFontStyle(_self, _args) |
| 302 | ControlObject *_self; |
| 303 | PyObject *_args; |
| 304 | { |
| 305 | PyObject *_res = NULL; |
| 306 | OSErr _err; |
| 307 | ControlFontStyleRec inStyle; |
| 308 | if (!PyArg_ParseTuple(_args, "O&", |
| 309 | ControlFontStyle_Convert, &inStyle)) |
| 310 | return NULL; |
| 311 | _err = SetControlFontStyle(_self->ob_itself, |
| 312 | &inStyle); |
| 313 | if (_err != noErr) return PyMac_Error(_err); |
| 314 | Py_INCREF(Py_None); |
| 315 | _res = Py_None; |
| 316 | return _res; |
| 317 | } |
| 318 | |
| 319 | static PyObject *CtlObj_DrawControlInCurrentPort(_self, _args) |
| 320 | ControlObject *_self; |
| 321 | PyObject *_args; |
| 322 | { |
| 323 | PyObject *_res = NULL; |
| 324 | if (!PyArg_ParseTuple(_args, "")) |
| 325 | return NULL; |
| 326 | DrawControlInCurrentPort(_self->ob_itself); |
| 327 | Py_INCREF(Py_None); |
| 328 | _res = Py_None; |
| 329 | return _res; |
| 330 | } |
| 331 | |
| 332 | static PyObject *CtlObj_SetUpControlBackground(_self, _args) |
| 333 | ControlObject *_self; |
| 334 | PyObject *_args; |
| 335 | { |
| 336 | PyObject *_res = NULL; |
| 337 | OSErr _err; |
| 338 | SInt16 inDepth; |
| 339 | Boolean inIsColorDevice; |
| 340 | if (!PyArg_ParseTuple(_args, "hb", |
| 341 | &inDepth, |
| 342 | &inIsColorDevice)) |
| 343 | return NULL; |
| 344 | _err = SetUpControlBackground(_self->ob_itself, |
| 345 | inDepth, |
| 346 | inIsColorDevice); |
| 347 | if (_err != noErr) return PyMac_Error(_err); |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 348 | Py_INCREF(Py_None); |
| 349 | _res = Py_None; |
| 350 | return _res; |
| 351 | } |
| 352 | |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 353 | static PyObject *CtlObj_SetUpControlTextColor(_self, _args) |
| 354 | ControlObject *_self; |
| 355 | PyObject *_args; |
| 356 | { |
| 357 | PyObject *_res = NULL; |
| 358 | OSErr _err; |
| 359 | SInt16 inDepth; |
| 360 | Boolean inIsColorDevice; |
| 361 | if (!PyArg_ParseTuple(_args, "hb", |
| 362 | &inDepth, |
| 363 | &inIsColorDevice)) |
| 364 | return NULL; |
| 365 | _err = SetUpControlTextColor(_self->ob_itself, |
| 366 | inDepth, |
| 367 | inIsColorDevice); |
| 368 | if (_err != noErr) return PyMac_Error(_err); |
| 369 | Py_INCREF(Py_None); |
| 370 | _res = Py_None; |
| 371 | return _res; |
| 372 | } |
| 373 | |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 374 | static PyObject *CtlObj_DragControl(_self, _args) |
| 375 | ControlObject *_self; |
| 376 | PyObject *_args; |
| 377 | { |
| 378 | PyObject *_res = NULL; |
Jack Jansen | 754d4a4 | 1995-11-14 10:41:55 +0000 | [diff] [blame] | 379 | Point startPoint; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 380 | Rect limitRect; |
| 381 | Rect slopRect; |
| 382 | DragConstraint axis; |
Jack Jansen | 0b13e7c | 2000-07-07 13:09:35 +0000 | [diff] [blame] | 383 | if (!PyArg_ParseTuple(_args, "O&O&O&H", |
Jack Jansen | 754d4a4 | 1995-11-14 10:41:55 +0000 | [diff] [blame] | 384 | PyMac_GetPoint, &startPoint, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 385 | PyMac_GetRect, &limitRect, |
| 386 | PyMac_GetRect, &slopRect, |
| 387 | &axis)) |
| 388 | return NULL; |
| 389 | DragControl(_self->ob_itself, |
Jack Jansen | 754d4a4 | 1995-11-14 10:41:55 +0000 | [diff] [blame] | 390 | startPoint, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 391 | &limitRect, |
| 392 | &slopRect, |
| 393 | axis); |
| 394 | Py_INCREF(Py_None); |
| 395 | _res = Py_None; |
| 396 | return _res; |
| 397 | } |
| 398 | |
| 399 | static PyObject *CtlObj_TestControl(_self, _args) |
| 400 | ControlObject *_self; |
| 401 | PyObject *_args; |
| 402 | { |
| 403 | PyObject *_res = NULL; |
| 404 | ControlPartCode _rv; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 405 | Point testPoint; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 406 | if (!PyArg_ParseTuple(_args, "O&", |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 407 | PyMac_GetPoint, &testPoint)) |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 408 | return NULL; |
| 409 | _rv = TestControl(_self->ob_itself, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 410 | testPoint); |
| 411 | _res = Py_BuildValue("h", |
| 412 | _rv); |
| 413 | return _res; |
| 414 | } |
| 415 | |
| 416 | static PyObject *CtlObj_HandleControlKey(_self, _args) |
| 417 | ControlObject *_self; |
| 418 | PyObject *_args; |
| 419 | { |
| 420 | PyObject *_res = NULL; |
| 421 | SInt16 _rv; |
| 422 | SInt16 inKeyCode; |
| 423 | SInt16 inCharCode; |
| 424 | SInt16 inModifiers; |
| 425 | if (!PyArg_ParseTuple(_args, "hhh", |
| 426 | &inKeyCode, |
| 427 | &inCharCode, |
| 428 | &inModifiers)) |
| 429 | return NULL; |
| 430 | _rv = HandleControlKey(_self->ob_itself, |
| 431 | inKeyCode, |
| 432 | inCharCode, |
| 433 | inModifiers); |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 434 | _res = Py_BuildValue("h", |
| 435 | _rv); |
| 436 | return _res; |
| 437 | } |
| 438 | |
| 439 | static PyObject *CtlObj_MoveControl(_self, _args) |
| 440 | ControlObject *_self; |
| 441 | PyObject *_args; |
| 442 | { |
| 443 | PyObject *_res = NULL; |
| 444 | SInt16 h; |
| 445 | SInt16 v; |
| 446 | if (!PyArg_ParseTuple(_args, "hh", |
| 447 | &h, |
| 448 | &v)) |
| 449 | return NULL; |
| 450 | MoveControl(_self->ob_itself, |
| 451 | h, |
| 452 | v); |
| 453 | Py_INCREF(Py_None); |
| 454 | _res = Py_None; |
| 455 | return _res; |
| 456 | } |
| 457 | |
| 458 | static PyObject *CtlObj_SizeControl(_self, _args) |
| 459 | ControlObject *_self; |
| 460 | PyObject *_args; |
| 461 | { |
| 462 | PyObject *_res = NULL; |
| 463 | SInt16 w; |
| 464 | SInt16 h; |
| 465 | if (!PyArg_ParseTuple(_args, "hh", |
| 466 | &w, |
| 467 | &h)) |
| 468 | return NULL; |
| 469 | SizeControl(_self->ob_itself, |
| 470 | w, |
| 471 | h); |
| 472 | Py_INCREF(Py_None); |
| 473 | _res = Py_None; |
| 474 | return _res; |
| 475 | } |
| 476 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 477 | static PyObject *CtlObj_SetControlTitle(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 478 | ControlObject *_self; |
| 479 | PyObject *_args; |
| 480 | { |
| 481 | PyObject *_res = NULL; |
| 482 | Str255 title; |
| 483 | if (!PyArg_ParseTuple(_args, "O&", |
| 484 | PyMac_GetStr255, title)) |
| 485 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 486 | SetControlTitle(_self->ob_itself, |
| 487 | title); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 488 | Py_INCREF(Py_None); |
| 489 | _res = Py_None; |
| 490 | return _res; |
| 491 | } |
| 492 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 493 | static PyObject *CtlObj_GetControlTitle(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 494 | ControlObject *_self; |
| 495 | PyObject *_args; |
| 496 | { |
| 497 | PyObject *_res = NULL; |
| 498 | Str255 title; |
Jack Jansen | 4100900 | 1999-03-07 20:05:20 +0000 | [diff] [blame] | 499 | if (!PyArg_ParseTuple(_args, "")) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 500 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 501 | GetControlTitle(_self->ob_itself, |
| 502 | title); |
Jack Jansen | 4100900 | 1999-03-07 20:05:20 +0000 | [diff] [blame] | 503 | _res = Py_BuildValue("O&", |
| 504 | PyMac_BuildStr255, title); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 505 | return _res; |
| 506 | } |
| 507 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 508 | static PyObject *CtlObj_GetControlValue(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 509 | ControlObject *_self; |
| 510 | PyObject *_args; |
| 511 | { |
| 512 | PyObject *_res = NULL; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 513 | SInt16 _rv; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 514 | if (!PyArg_ParseTuple(_args, "")) |
| 515 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 516 | _rv = GetControlValue(_self->ob_itself); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 517 | _res = Py_BuildValue("h", |
| 518 | _rv); |
| 519 | return _res; |
| 520 | } |
| 521 | |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 522 | static PyObject *CtlObj_SetControlValue(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 523 | ControlObject *_self; |
| 524 | PyObject *_args; |
| 525 | { |
| 526 | PyObject *_res = NULL; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 527 | SInt16 newValue; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 528 | if (!PyArg_ParseTuple(_args, "h", |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 529 | &newValue)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 530 | return NULL; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 531 | SetControlValue(_self->ob_itself, |
| 532 | newValue); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 533 | Py_INCREF(Py_None); |
| 534 | _res = Py_None; |
| 535 | return _res; |
| 536 | } |
| 537 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 538 | static PyObject *CtlObj_GetControlMinimum(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 539 | ControlObject *_self; |
| 540 | PyObject *_args; |
| 541 | { |
| 542 | PyObject *_res = NULL; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 543 | SInt16 _rv; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 544 | if (!PyArg_ParseTuple(_args, "")) |
| 545 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 546 | _rv = GetControlMinimum(_self->ob_itself); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 547 | _res = Py_BuildValue("h", |
| 548 | _rv); |
| 549 | return _res; |
| 550 | } |
| 551 | |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 552 | static PyObject *CtlObj_SetControlMinimum(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 553 | ControlObject *_self; |
| 554 | PyObject *_args; |
| 555 | { |
| 556 | PyObject *_res = NULL; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 557 | SInt16 newMinimum; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 558 | if (!PyArg_ParseTuple(_args, "h", |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 559 | &newMinimum)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 560 | return NULL; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 561 | SetControlMinimum(_self->ob_itself, |
| 562 | newMinimum); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 563 | Py_INCREF(Py_None); |
| 564 | _res = Py_None; |
| 565 | return _res; |
| 566 | } |
| 567 | |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 568 | static PyObject *CtlObj_GetControlMaximum(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 569 | ControlObject *_self; |
| 570 | PyObject *_args; |
| 571 | { |
| 572 | PyObject *_res = NULL; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 573 | SInt16 _rv; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 574 | if (!PyArg_ParseTuple(_args, "")) |
| 575 | return NULL; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 576 | _rv = GetControlMaximum(_self->ob_itself); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 577 | _res = Py_BuildValue("h", |
| 578 | _rv); |
| 579 | return _res; |
| 580 | } |
| 581 | |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 582 | static PyObject *CtlObj_SetControlMaximum(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 583 | ControlObject *_self; |
| 584 | PyObject *_args; |
| 585 | { |
| 586 | PyObject *_res = NULL; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 587 | SInt16 newMaximum; |
| 588 | if (!PyArg_ParseTuple(_args, "h", |
| 589 | &newMaximum)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 590 | return NULL; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 591 | SetControlMaximum(_self->ob_itself, |
| 592 | newMaximum); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 593 | Py_INCREF(Py_None); |
| 594 | _res = Py_None; |
| 595 | return _res; |
| 596 | } |
| 597 | |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 598 | static PyObject *CtlObj_GetControlViewSize(_self, _args) |
| 599 | ControlObject *_self; |
| 600 | PyObject *_args; |
| 601 | { |
| 602 | PyObject *_res = NULL; |
| 603 | SInt32 _rv; |
| 604 | if (!PyArg_ParseTuple(_args, "")) |
| 605 | return NULL; |
| 606 | _rv = GetControlViewSize(_self->ob_itself); |
| 607 | _res = Py_BuildValue("l", |
| 608 | _rv); |
| 609 | return _res; |
| 610 | } |
| 611 | |
| 612 | static PyObject *CtlObj_SetControlViewSize(_self, _args) |
| 613 | ControlObject *_self; |
| 614 | PyObject *_args; |
| 615 | { |
| 616 | PyObject *_res = NULL; |
| 617 | SInt32 newViewSize; |
| 618 | if (!PyArg_ParseTuple(_args, "l", |
| 619 | &newViewSize)) |
| 620 | return NULL; |
| 621 | SetControlViewSize(_self->ob_itself, |
| 622 | newViewSize); |
| 623 | Py_INCREF(Py_None); |
| 624 | _res = Py_None; |
| 625 | return _res; |
| 626 | } |
| 627 | |
| 628 | static PyObject *CtlObj_GetControl32BitValue(_self, _args) |
| 629 | ControlObject *_self; |
| 630 | PyObject *_args; |
| 631 | { |
| 632 | PyObject *_res = NULL; |
| 633 | SInt32 _rv; |
| 634 | if (!PyArg_ParseTuple(_args, "")) |
| 635 | return NULL; |
| 636 | _rv = GetControl32BitValue(_self->ob_itself); |
| 637 | _res = Py_BuildValue("l", |
| 638 | _rv); |
| 639 | return _res; |
| 640 | } |
| 641 | |
| 642 | static PyObject *CtlObj_SetControl32BitValue(_self, _args) |
| 643 | ControlObject *_self; |
| 644 | PyObject *_args; |
| 645 | { |
| 646 | PyObject *_res = NULL; |
| 647 | SInt32 newValue; |
| 648 | if (!PyArg_ParseTuple(_args, "l", |
| 649 | &newValue)) |
| 650 | return NULL; |
| 651 | SetControl32BitValue(_self->ob_itself, |
| 652 | newValue); |
| 653 | Py_INCREF(Py_None); |
| 654 | _res = Py_None; |
| 655 | return _res; |
| 656 | } |
| 657 | |
| 658 | static PyObject *CtlObj_GetControl32BitMaximum(_self, _args) |
| 659 | ControlObject *_self; |
| 660 | PyObject *_args; |
| 661 | { |
| 662 | PyObject *_res = NULL; |
| 663 | SInt32 _rv; |
| 664 | if (!PyArg_ParseTuple(_args, "")) |
| 665 | return NULL; |
| 666 | _rv = GetControl32BitMaximum(_self->ob_itself); |
| 667 | _res = Py_BuildValue("l", |
| 668 | _rv); |
| 669 | return _res; |
| 670 | } |
| 671 | |
| 672 | static PyObject *CtlObj_SetControl32BitMaximum(_self, _args) |
| 673 | ControlObject *_self; |
| 674 | PyObject *_args; |
| 675 | { |
| 676 | PyObject *_res = NULL; |
| 677 | SInt32 newMaximum; |
| 678 | if (!PyArg_ParseTuple(_args, "l", |
| 679 | &newMaximum)) |
| 680 | return NULL; |
| 681 | SetControl32BitMaximum(_self->ob_itself, |
| 682 | newMaximum); |
| 683 | Py_INCREF(Py_None); |
| 684 | _res = Py_None; |
| 685 | return _res; |
| 686 | } |
| 687 | |
| 688 | static PyObject *CtlObj_GetControl32BitMinimum(_self, _args) |
| 689 | ControlObject *_self; |
| 690 | PyObject *_args; |
| 691 | { |
| 692 | PyObject *_res = NULL; |
| 693 | SInt32 _rv; |
| 694 | if (!PyArg_ParseTuple(_args, "")) |
| 695 | return NULL; |
| 696 | _rv = GetControl32BitMinimum(_self->ob_itself); |
| 697 | _res = Py_BuildValue("l", |
| 698 | _rv); |
| 699 | return _res; |
| 700 | } |
| 701 | |
| 702 | static PyObject *CtlObj_SetControl32BitMinimum(_self, _args) |
| 703 | ControlObject *_self; |
| 704 | PyObject *_args; |
| 705 | { |
| 706 | PyObject *_res = NULL; |
| 707 | SInt32 newMinimum; |
| 708 | if (!PyArg_ParseTuple(_args, "l", |
| 709 | &newMinimum)) |
| 710 | return NULL; |
| 711 | SetControl32BitMinimum(_self->ob_itself, |
| 712 | newMinimum); |
| 713 | Py_INCREF(Py_None); |
| 714 | _res = Py_None; |
| 715 | return _res; |
| 716 | } |
| 717 | |
| 718 | static PyObject *CtlObj_IsValidControlHandle(_self, _args) |
| 719 | ControlObject *_self; |
| 720 | PyObject *_args; |
| 721 | { |
| 722 | PyObject *_res = NULL; |
| 723 | Boolean _rv; |
| 724 | if (!PyArg_ParseTuple(_args, "")) |
| 725 | return NULL; |
| 726 | _rv = IsValidControlHandle(_self->ob_itself); |
| 727 | _res = Py_BuildValue("b", |
| 728 | _rv); |
| 729 | return _res; |
| 730 | } |
| 731 | |
| 732 | static PyObject *CtlObj_RemoveControlProperty(_self, _args) |
| 733 | ControlObject *_self; |
| 734 | PyObject *_args; |
| 735 | { |
| 736 | PyObject *_res = NULL; |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 737 | OSStatus _err; |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 738 | OSType propertyCreator; |
| 739 | OSType propertyTag; |
| 740 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 741 | PyMac_GetOSType, &propertyCreator, |
| 742 | PyMac_GetOSType, &propertyTag)) |
| 743 | return NULL; |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 744 | _err = RemoveControlProperty(_self->ob_itself, |
| 745 | propertyCreator, |
| 746 | propertyTag); |
| 747 | if (_err != noErr) return PyMac_Error(_err); |
| 748 | Py_INCREF(Py_None); |
| 749 | _res = Py_None; |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 750 | return _res; |
| 751 | } |
| 752 | |
| 753 | static PyObject *CtlObj_GetControlRegion(_self, _args) |
| 754 | ControlObject *_self; |
| 755 | PyObject *_args; |
| 756 | { |
| 757 | PyObject *_res = NULL; |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 758 | OSStatus _err; |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 759 | ControlPartCode inPart; |
| 760 | RgnHandle outRegion; |
| 761 | if (!PyArg_ParseTuple(_args, "hO&", |
| 762 | &inPart, |
| 763 | ResObj_Convert, &outRegion)) |
| 764 | return NULL; |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 765 | _err = GetControlRegion(_self->ob_itself, |
| 766 | inPart, |
| 767 | outRegion); |
| 768 | if (_err != noErr) return PyMac_Error(_err); |
| 769 | Py_INCREF(Py_None); |
| 770 | _res = Py_None; |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 771 | return _res; |
| 772 | } |
| 773 | |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 774 | static PyObject *CtlObj_GetControlVariant(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 775 | ControlObject *_self; |
| 776 | PyObject *_args; |
| 777 | { |
| 778 | PyObject *_res = NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 779 | ControlVariant _rv; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 780 | if (!PyArg_ParseTuple(_args, "")) |
| 781 | return NULL; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 782 | _rv = GetControlVariant(_self->ob_itself); |
| 783 | _res = Py_BuildValue("h", |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 784 | _rv); |
| 785 | return _res; |
| 786 | } |
| 787 | |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 788 | static PyObject *CtlObj_SetControlReference(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 789 | ControlObject *_self; |
| 790 | PyObject *_args; |
| 791 | { |
| 792 | PyObject *_res = NULL; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 793 | SInt32 data; |
| 794 | if (!PyArg_ParseTuple(_args, "l", |
| 795 | &data)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 796 | return NULL; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 797 | SetControlReference(_self->ob_itself, |
| 798 | data); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 799 | Py_INCREF(Py_None); |
| 800 | _res = Py_None; |
| 801 | return _res; |
| 802 | } |
| 803 | |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 804 | static PyObject *CtlObj_GetControlReference(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 805 | ControlObject *_self; |
| 806 | PyObject *_args; |
| 807 | { |
| 808 | PyObject *_res = NULL; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 809 | SInt32 _rv; |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 810 | if (!PyArg_ParseTuple(_args, "")) |
| 811 | return NULL; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 812 | _rv = GetControlReference(_self->ob_itself); |
| 813 | _res = Py_BuildValue("l", |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 814 | _rv); |
| 815 | return _res; |
| 816 | } |
| 817 | |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 818 | #ifndef TARGET_API_MAC_CARBON |
| 819 | |
Jack Jansen | c7fefed | 1997-08-15 14:32:18 +0000 | [diff] [blame] | 820 | static PyObject *CtlObj_GetAuxiliaryControlRecord(_self, _args) |
| 821 | ControlObject *_self; |
| 822 | PyObject *_args; |
| 823 | { |
| 824 | PyObject *_res = NULL; |
| 825 | Boolean _rv; |
| 826 | AuxCtlHandle acHndl; |
| 827 | if (!PyArg_ParseTuple(_args, "")) |
| 828 | return NULL; |
| 829 | _rv = GetAuxiliaryControlRecord(_self->ob_itself, |
| 830 | &acHndl); |
| 831 | _res = Py_BuildValue("bO&", |
| 832 | _rv, |
| 833 | ResObj_New, acHndl); |
| 834 | return _res; |
| 835 | } |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 836 | #endif |
| 837 | |
| 838 | #ifndef TARGET_API_MAC_CARBON |
Jack Jansen | c7fefed | 1997-08-15 14:32:18 +0000 | [diff] [blame] | 839 | |
| 840 | static PyObject *CtlObj_SetControlColor(_self, _args) |
| 841 | ControlObject *_self; |
| 842 | PyObject *_args; |
| 843 | { |
| 844 | PyObject *_res = NULL; |
| 845 | CCTabHandle newColorTable; |
| 846 | if (!PyArg_ParseTuple(_args, "O&", |
| 847 | ResObj_Convert, &newColorTable)) |
| 848 | return NULL; |
| 849 | SetControlColor(_self->ob_itself, |
| 850 | newColorTable); |
| 851 | Py_INCREF(Py_None); |
| 852 | _res = Py_None; |
| 853 | return _res; |
| 854 | } |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 855 | #endif |
| 856 | |
| 857 | static PyObject *CtlObj_GetBevelButtonMenuValue(_self, _args) |
| 858 | ControlObject *_self; |
| 859 | PyObject *_args; |
| 860 | { |
| 861 | PyObject *_res = NULL; |
| 862 | OSErr _err; |
| 863 | SInt16 outValue; |
| 864 | if (!PyArg_ParseTuple(_args, "")) |
| 865 | return NULL; |
| 866 | _err = GetBevelButtonMenuValue(_self->ob_itself, |
| 867 | &outValue); |
| 868 | if (_err != noErr) return PyMac_Error(_err); |
| 869 | _res = Py_BuildValue("h", |
| 870 | outValue); |
| 871 | return _res; |
| 872 | } |
| 873 | |
| 874 | static PyObject *CtlObj_SetBevelButtonMenuValue(_self, _args) |
| 875 | ControlObject *_self; |
| 876 | PyObject *_args; |
| 877 | { |
| 878 | PyObject *_res = NULL; |
| 879 | OSErr _err; |
| 880 | SInt16 inValue; |
| 881 | if (!PyArg_ParseTuple(_args, "h", |
| 882 | &inValue)) |
| 883 | return NULL; |
| 884 | _err = SetBevelButtonMenuValue(_self->ob_itself, |
| 885 | inValue); |
| 886 | if (_err != noErr) return PyMac_Error(_err); |
| 887 | Py_INCREF(Py_None); |
| 888 | _res = Py_None; |
| 889 | return _res; |
| 890 | } |
| 891 | |
| 892 | static PyObject *CtlObj_GetBevelButtonMenuHandle(_self, _args) |
| 893 | ControlObject *_self; |
| 894 | PyObject *_args; |
| 895 | { |
| 896 | PyObject *_res = NULL; |
| 897 | OSErr _err; |
| 898 | MenuHandle outHandle; |
| 899 | if (!PyArg_ParseTuple(_args, "")) |
| 900 | return NULL; |
| 901 | _err = GetBevelButtonMenuHandle(_self->ob_itself, |
| 902 | &outHandle); |
| 903 | if (_err != noErr) return PyMac_Error(_err); |
| 904 | _res = Py_BuildValue("O&", |
| 905 | MenuObj_New, outHandle); |
| 906 | return _res; |
| 907 | } |
| 908 | |
| 909 | static PyObject *CtlObj_SetBevelButtonTransform(_self, _args) |
| 910 | ControlObject *_self; |
| 911 | PyObject *_args; |
| 912 | { |
| 913 | PyObject *_res = NULL; |
| 914 | OSErr _err; |
| 915 | IconTransformType transform; |
| 916 | if (!PyArg_ParseTuple(_args, "h", |
| 917 | &transform)) |
| 918 | return NULL; |
| 919 | _err = SetBevelButtonTransform(_self->ob_itself, |
| 920 | transform); |
| 921 | if (_err != noErr) return PyMac_Error(_err); |
| 922 | Py_INCREF(Py_None); |
| 923 | _res = Py_None; |
| 924 | return _res; |
| 925 | } |
| 926 | |
| 927 | static PyObject *CtlObj_SetImageWellTransform(_self, _args) |
| 928 | ControlObject *_self; |
| 929 | PyObject *_args; |
| 930 | { |
| 931 | PyObject *_res = NULL; |
| 932 | OSErr _err; |
| 933 | IconTransformType inTransform; |
| 934 | if (!PyArg_ParseTuple(_args, "h", |
| 935 | &inTransform)) |
| 936 | return NULL; |
| 937 | _err = SetImageWellTransform(_self->ob_itself, |
| 938 | inTransform); |
| 939 | if (_err != noErr) return PyMac_Error(_err); |
| 940 | Py_INCREF(Py_None); |
| 941 | _res = Py_None; |
| 942 | return _res; |
| 943 | } |
| 944 | |
| 945 | static PyObject *CtlObj_GetTabContentRect(_self, _args) |
| 946 | ControlObject *_self; |
| 947 | PyObject *_args; |
| 948 | { |
| 949 | PyObject *_res = NULL; |
| 950 | OSErr _err; |
| 951 | Rect outContentRect; |
| 952 | if (!PyArg_ParseTuple(_args, "")) |
| 953 | return NULL; |
| 954 | _err = GetTabContentRect(_self->ob_itself, |
| 955 | &outContentRect); |
| 956 | if (_err != noErr) return PyMac_Error(_err); |
| 957 | _res = Py_BuildValue("O&", |
| 958 | PyMac_BuildRect, &outContentRect); |
| 959 | return _res; |
| 960 | } |
| 961 | |
| 962 | static PyObject *CtlObj_SetTabEnabled(_self, _args) |
| 963 | ControlObject *_self; |
| 964 | PyObject *_args; |
| 965 | { |
| 966 | PyObject *_res = NULL; |
| 967 | OSErr _err; |
| 968 | SInt16 inTabToHilite; |
| 969 | Boolean inEnabled; |
| 970 | if (!PyArg_ParseTuple(_args, "hb", |
| 971 | &inTabToHilite, |
| 972 | &inEnabled)) |
| 973 | return NULL; |
| 974 | _err = SetTabEnabled(_self->ob_itself, |
| 975 | inTabToHilite, |
| 976 | inEnabled); |
| 977 | if (_err != noErr) return PyMac_Error(_err); |
| 978 | Py_INCREF(Py_None); |
| 979 | _res = Py_None; |
| 980 | return _res; |
| 981 | } |
| 982 | |
| 983 | static PyObject *CtlObj_SetDisclosureTriangleLastValue(_self, _args) |
| 984 | ControlObject *_self; |
| 985 | PyObject *_args; |
| 986 | { |
| 987 | PyObject *_res = NULL; |
| 988 | OSErr _err; |
| 989 | SInt16 inValue; |
| 990 | if (!PyArg_ParseTuple(_args, "h", |
| 991 | &inValue)) |
| 992 | return NULL; |
| 993 | _err = SetDisclosureTriangleLastValue(_self->ob_itself, |
| 994 | inValue); |
| 995 | if (_err != noErr) return PyMac_Error(_err); |
| 996 | Py_INCREF(Py_None); |
| 997 | _res = Py_None; |
| 998 | return _res; |
| 999 | } |
Jack Jansen | c7fefed | 1997-08-15 14:32:18 +0000 | [diff] [blame] | 1000 | |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1001 | static PyObject *CtlObj_SendControlMessage(_self, _args) |
| 1002 | ControlObject *_self; |
| 1003 | PyObject *_args; |
| 1004 | { |
| 1005 | PyObject *_res = NULL; |
| 1006 | SInt32 _rv; |
| 1007 | SInt16 inMessage; |
| 1008 | SInt32 inParam; |
| 1009 | if (!PyArg_ParseTuple(_args, "hl", |
| 1010 | &inMessage, |
| 1011 | &inParam)) |
| 1012 | return NULL; |
| 1013 | _rv = SendControlMessage(_self->ob_itself, |
| 1014 | inMessage, |
| 1015 | inParam); |
| 1016 | _res = Py_BuildValue("l", |
| 1017 | _rv); |
| 1018 | return _res; |
| 1019 | } |
| 1020 | |
| 1021 | static PyObject *CtlObj_EmbedControl(_self, _args) |
| 1022 | ControlObject *_self; |
| 1023 | PyObject *_args; |
| 1024 | { |
| 1025 | PyObject *_res = NULL; |
| 1026 | OSErr _err; |
| 1027 | ControlHandle inContainer; |
| 1028 | if (!PyArg_ParseTuple(_args, "O&", |
| 1029 | CtlObj_Convert, &inContainer)) |
| 1030 | return NULL; |
| 1031 | _err = EmbedControl(_self->ob_itself, |
| 1032 | inContainer); |
| 1033 | if (_err != noErr) return PyMac_Error(_err); |
| 1034 | Py_INCREF(Py_None); |
| 1035 | _res = Py_None; |
| 1036 | return _res; |
| 1037 | } |
| 1038 | |
| 1039 | static PyObject *CtlObj_AutoEmbedControl(_self, _args) |
| 1040 | ControlObject *_self; |
| 1041 | PyObject *_args; |
| 1042 | { |
| 1043 | PyObject *_res = NULL; |
| 1044 | OSErr _err; |
| 1045 | WindowPtr inWindow; |
| 1046 | if (!PyArg_ParseTuple(_args, "O&", |
| 1047 | WinObj_Convert, &inWindow)) |
| 1048 | return NULL; |
| 1049 | _err = AutoEmbedControl(_self->ob_itself, |
| 1050 | inWindow); |
| 1051 | if (_err != noErr) return PyMac_Error(_err); |
| 1052 | Py_INCREF(Py_None); |
| 1053 | _res = Py_None; |
| 1054 | return _res; |
| 1055 | } |
| 1056 | |
| 1057 | static PyObject *CtlObj_GetSuperControl(_self, _args) |
| 1058 | ControlObject *_self; |
| 1059 | PyObject *_args; |
| 1060 | { |
| 1061 | PyObject *_res = NULL; |
| 1062 | OSErr _err; |
| 1063 | ControlHandle outParent; |
| 1064 | if (!PyArg_ParseTuple(_args, "")) |
| 1065 | return NULL; |
| 1066 | _err = GetSuperControl(_self->ob_itself, |
| 1067 | &outParent); |
| 1068 | if (_err != noErr) return PyMac_Error(_err); |
| 1069 | _res = Py_BuildValue("O&", |
| 1070 | CtlObj_WhichControl, outParent); |
| 1071 | return _res; |
| 1072 | } |
| 1073 | |
| 1074 | static PyObject *CtlObj_CountSubControls(_self, _args) |
| 1075 | ControlObject *_self; |
| 1076 | PyObject *_args; |
| 1077 | { |
| 1078 | PyObject *_res = NULL; |
| 1079 | OSErr _err; |
Jack Jansen | 24c3531 | 1999-12-09 22:49:51 +0000 | [diff] [blame] | 1080 | UInt16 outNumChildren; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1081 | if (!PyArg_ParseTuple(_args, "")) |
| 1082 | return NULL; |
| 1083 | _err = CountSubControls(_self->ob_itself, |
| 1084 | &outNumChildren); |
| 1085 | if (_err != noErr) return PyMac_Error(_err); |
Jack Jansen | 0b13e7c | 2000-07-07 13:09:35 +0000 | [diff] [blame] | 1086 | _res = Py_BuildValue("H", |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1087 | outNumChildren); |
| 1088 | return _res; |
| 1089 | } |
| 1090 | |
| 1091 | static PyObject *CtlObj_GetIndexedSubControl(_self, _args) |
| 1092 | ControlObject *_self; |
| 1093 | PyObject *_args; |
| 1094 | { |
| 1095 | PyObject *_res = NULL; |
| 1096 | OSErr _err; |
Jack Jansen | 24c3531 | 1999-12-09 22:49:51 +0000 | [diff] [blame] | 1097 | UInt16 inIndex; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1098 | ControlHandle outSubControl; |
Jack Jansen | 0b13e7c | 2000-07-07 13:09:35 +0000 | [diff] [blame] | 1099 | if (!PyArg_ParseTuple(_args, "H", |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1100 | &inIndex)) |
| 1101 | return NULL; |
| 1102 | _err = GetIndexedSubControl(_self->ob_itself, |
| 1103 | inIndex, |
| 1104 | &outSubControl); |
| 1105 | if (_err != noErr) return PyMac_Error(_err); |
| 1106 | _res = Py_BuildValue("O&", |
| 1107 | CtlObj_WhichControl, outSubControl); |
| 1108 | return _res; |
| 1109 | } |
| 1110 | |
| 1111 | static PyObject *CtlObj_SetControlSupervisor(_self, _args) |
| 1112 | ControlObject *_self; |
| 1113 | PyObject *_args; |
| 1114 | { |
| 1115 | PyObject *_res = NULL; |
| 1116 | OSErr _err; |
| 1117 | ControlHandle inBoss; |
| 1118 | if (!PyArg_ParseTuple(_args, "O&", |
| 1119 | CtlObj_Convert, &inBoss)) |
| 1120 | return NULL; |
| 1121 | _err = SetControlSupervisor(_self->ob_itself, |
| 1122 | inBoss); |
| 1123 | if (_err != noErr) return PyMac_Error(_err); |
| 1124 | Py_INCREF(Py_None); |
| 1125 | _res = Py_None; |
| 1126 | return _res; |
| 1127 | } |
| 1128 | |
| 1129 | static PyObject *CtlObj_GetControlFeatures(_self, _args) |
| 1130 | ControlObject *_self; |
| 1131 | PyObject *_args; |
| 1132 | { |
| 1133 | PyObject *_res = NULL; |
| 1134 | OSErr _err; |
| 1135 | UInt32 outFeatures; |
| 1136 | if (!PyArg_ParseTuple(_args, "")) |
| 1137 | return NULL; |
| 1138 | _err = GetControlFeatures(_self->ob_itself, |
| 1139 | &outFeatures); |
| 1140 | if (_err != noErr) return PyMac_Error(_err); |
| 1141 | _res = Py_BuildValue("l", |
| 1142 | outFeatures); |
| 1143 | return _res; |
| 1144 | } |
| 1145 | |
| 1146 | static PyObject *CtlObj_GetControlDataSize(_self, _args) |
| 1147 | ControlObject *_self; |
| 1148 | PyObject *_args; |
| 1149 | { |
| 1150 | PyObject *_res = NULL; |
| 1151 | OSErr _err; |
| 1152 | ControlPartCode inPart; |
| 1153 | ResType inTagName; |
| 1154 | Size outMaxSize; |
| 1155 | if (!PyArg_ParseTuple(_args, "hO&", |
| 1156 | &inPart, |
| 1157 | PyMac_GetOSType, &inTagName)) |
| 1158 | return NULL; |
| 1159 | _err = GetControlDataSize(_self->ob_itself, |
| 1160 | inPart, |
| 1161 | inTagName, |
| 1162 | &outMaxSize); |
| 1163 | if (_err != noErr) return PyMac_Error(_err); |
| 1164 | _res = Py_BuildValue("l", |
| 1165 | outMaxSize); |
| 1166 | return _res; |
| 1167 | } |
| 1168 | |
Jack Jansen | 5d56f4b | 1995-06-18 20:16:33 +0000 | [diff] [blame] | 1169 | static PyObject *CtlObj_as_Resource(_self, _args) |
| 1170 | ControlObject *_self; |
| 1171 | PyObject *_args; |
| 1172 | { |
| 1173 | PyObject *_res = NULL; |
Jack Jansen | a1a0fef | 1999-12-23 14:32:06 +0000 | [diff] [blame] | 1174 | Handle _rv; |
| 1175 | if (!PyArg_ParseTuple(_args, "")) |
| 1176 | return NULL; |
| 1177 | _rv = as_Resource(_self->ob_itself); |
| 1178 | _res = Py_BuildValue("O&", |
| 1179 | ResObj_New, _rv); |
| 1180 | return _res; |
Jack Jansen | 5d56f4b | 1995-06-18 20:16:33 +0000 | [diff] [blame] | 1181 | } |
| 1182 | |
Jack Jansen | 1a7d5b1 | 2000-03-21 16:25:23 +0000 | [diff] [blame] | 1183 | static PyObject *CtlObj_GetControlRect(_self, _args) |
| 1184 | ControlObject *_self; |
| 1185 | PyObject *_args; |
| 1186 | { |
| 1187 | PyObject *_res = NULL; |
| 1188 | Rect rect; |
| 1189 | if (!PyArg_ParseTuple(_args, "")) |
| 1190 | return NULL; |
| 1191 | GetControlRect(_self->ob_itself, |
| 1192 | &rect); |
| 1193 | _res = Py_BuildValue("O&", |
| 1194 | PyMac_BuildRect, &rect); |
| 1195 | return _res; |
| 1196 | } |
| 1197 | |
Jack Jansen | cfb60ee | 1996-10-01 10:46:46 +0000 | [diff] [blame] | 1198 | static PyObject *CtlObj_DisposeControl(_self, _args) |
| 1199 | ControlObject *_self; |
| 1200 | PyObject *_args; |
| 1201 | { |
| 1202 | PyObject *_res = NULL; |
| 1203 | |
| 1204 | if (!PyArg_ParseTuple(_args, "")) |
| 1205 | return NULL; |
| 1206 | if ( _self->ob_itself ) { |
Jack Jansen | 85ae4a8 | 1997-04-08 15:26:03 +0000 | [diff] [blame] | 1207 | SetControlReference(_self->ob_itself, (long)0); /* Make it forget about us */ |
Jack Jansen | cfb60ee | 1996-10-01 10:46:46 +0000 | [diff] [blame] | 1208 | DisposeControl(_self->ob_itself); |
| 1209 | _self->ob_itself = NULL; |
| 1210 | } |
| 1211 | Py_INCREF(Py_None); |
| 1212 | _res = Py_None; |
| 1213 | return _res; |
| 1214 | |
| 1215 | } |
| 1216 | |
Jack Jansen | 848250c | 1998-05-28 14:20:09 +0000 | [diff] [blame] | 1217 | static PyObject *CtlObj_TrackControl(_self, _args) |
| 1218 | ControlObject *_self; |
| 1219 | PyObject *_args; |
| 1220 | { |
| 1221 | PyObject *_res = NULL; |
| 1222 | |
| 1223 | ControlPartCode _rv; |
| 1224 | Point startPoint; |
| 1225 | ControlActionUPP upp = 0; |
| 1226 | PyObject *callback = 0; |
| 1227 | |
| 1228 | if (!PyArg_ParseTuple(_args, "O&|O", |
| 1229 | PyMac_GetPoint, &startPoint, &callback)) |
| 1230 | return NULL; |
| 1231 | if (callback && callback != Py_None) { |
| 1232 | if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1) |
| 1233 | upp = (ControlActionUPP)-1; |
| 1234 | else { |
| 1235 | settrackfunc(callback); |
| 1236 | upp = mytracker_upp; |
| 1237 | } |
| 1238 | } |
| 1239 | _rv = TrackControl(_self->ob_itself, |
| 1240 | startPoint, |
| 1241 | upp); |
| 1242 | clrtrackfunc(); |
| 1243 | _res = Py_BuildValue("h", |
| 1244 | _rv); |
| 1245 | return _res; |
| 1246 | |
| 1247 | } |
| 1248 | |
Jack Jansen | 24c3531 | 1999-12-09 22:49:51 +0000 | [diff] [blame] | 1249 | static PyObject *CtlObj_HandleControlClick(_self, _args) |
| 1250 | ControlObject *_self; |
| 1251 | PyObject *_args; |
| 1252 | { |
| 1253 | PyObject *_res = NULL; |
| 1254 | |
| 1255 | ControlPartCode _rv; |
| 1256 | Point startPoint; |
| 1257 | SInt16 modifiers; |
| 1258 | ControlActionUPP upp = 0; |
| 1259 | PyObject *callback = 0; |
| 1260 | |
| 1261 | if (!PyArg_ParseTuple(_args, "O&h|O", |
| 1262 | PyMac_GetPoint, &startPoint, |
| 1263 | &modifiers, |
| 1264 | &callback)) |
| 1265 | return NULL; |
| 1266 | if (callback && callback != Py_None) { |
| 1267 | if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1) |
| 1268 | upp = (ControlActionUPP)-1; |
| 1269 | else { |
| 1270 | settrackfunc(callback); |
| 1271 | upp = mytracker_upp; |
| 1272 | } |
| 1273 | } |
| 1274 | _rv = HandleControlClick(_self->ob_itself, |
| 1275 | startPoint, |
| 1276 | modifiers, |
| 1277 | upp); |
| 1278 | clrtrackfunc(); |
| 1279 | _res = Py_BuildValue("h", |
| 1280 | _rv); |
| 1281 | return _res; |
| 1282 | |
| 1283 | } |
| 1284 | |
| 1285 | static PyObject *CtlObj_SetControlData(_self, _args) |
| 1286 | ControlObject *_self; |
| 1287 | PyObject *_args; |
| 1288 | { |
| 1289 | PyObject *_res = NULL; |
| 1290 | |
| 1291 | OSErr _err; |
| 1292 | ControlPartCode inPart; |
| 1293 | ResType inTagName; |
| 1294 | Size bufferSize; |
| 1295 | Ptr buffer; |
| 1296 | |
| 1297 | if (!PyArg_ParseTuple(_args, "hO&s#", |
| 1298 | &inPart, |
| 1299 | PyMac_GetOSType, &inTagName, |
| 1300 | &buffer, &bufferSize)) |
| 1301 | return NULL; |
| 1302 | |
| 1303 | _err = SetControlData(_self->ob_itself, |
| 1304 | inPart, |
| 1305 | inTagName, |
| 1306 | bufferSize, |
| 1307 | buffer); |
| 1308 | |
| 1309 | if (_err != noErr) |
| 1310 | return PyMac_Error(_err); |
| 1311 | _res = Py_None; |
| 1312 | return _res; |
| 1313 | |
| 1314 | } |
| 1315 | |
| 1316 | static PyObject *CtlObj_GetControlData(_self, _args) |
| 1317 | ControlObject *_self; |
| 1318 | PyObject *_args; |
| 1319 | { |
| 1320 | PyObject *_res = NULL; |
| 1321 | |
| 1322 | OSErr _err; |
| 1323 | ControlPartCode inPart; |
| 1324 | ResType inTagName; |
| 1325 | Size bufferSize; |
| 1326 | Ptr buffer; |
| 1327 | Size outSize; |
| 1328 | |
| 1329 | if (!PyArg_ParseTuple(_args, "hO&", |
| 1330 | &inPart, |
| 1331 | PyMac_GetOSType, &inTagName)) |
| 1332 | return NULL; |
| 1333 | |
| 1334 | /* allocate a buffer for the data */ |
| 1335 | _err = GetControlDataSize(_self->ob_itself, |
| 1336 | inPart, |
| 1337 | inTagName, |
| 1338 | &bufferSize); |
| 1339 | if (_err != noErr) |
| 1340 | return PyMac_Error(_err); |
| 1341 | buffer = PyMem_NEW(char, bufferSize); |
| 1342 | if (buffer == NULL) |
| 1343 | return PyErr_NoMemory(); |
| 1344 | |
| 1345 | _err = GetControlData(_self->ob_itself, |
| 1346 | inPart, |
| 1347 | inTagName, |
| 1348 | bufferSize, |
| 1349 | buffer, |
| 1350 | &outSize); |
| 1351 | |
| 1352 | if (_err != noErr) { |
| 1353 | PyMem_DEL(buffer); |
| 1354 | return PyMac_Error(_err); |
| 1355 | } |
| 1356 | _res = Py_BuildValue("s#", buffer, outSize); |
| 1357 | PyMem_DEL(buffer); |
| 1358 | return _res; |
| 1359 | |
| 1360 | } |
| 1361 | |
Jack Jansen | 1f9249c | 1999-12-19 00:05:50 +0000 | [diff] [blame] | 1362 | static PyObject *CtlObj_SetControlDataHandle(_self, _args) |
| 1363 | ControlObject *_self; |
| 1364 | PyObject *_args; |
| 1365 | { |
| 1366 | PyObject *_res = NULL; |
| 1367 | |
| 1368 | OSErr _err; |
| 1369 | ControlPartCode inPart; |
| 1370 | ResType inTagName; |
| 1371 | Handle buffer; |
| 1372 | |
| 1373 | if (!PyArg_ParseTuple(_args, "hO&O&", |
| 1374 | &inPart, |
| 1375 | PyMac_GetOSType, &inTagName, |
Jack Jansen | b9247d3 | 1999-12-23 23:06:07 +0000 | [diff] [blame] | 1376 | OptResObj_Convert, &buffer)) |
Jack Jansen | 1f9249c | 1999-12-19 00:05:50 +0000 | [diff] [blame] | 1377 | return NULL; |
| 1378 | |
| 1379 | _err = SetControlData(_self->ob_itself, |
| 1380 | inPart, |
| 1381 | inTagName, |
| 1382 | sizeof(buffer), |
Jack Jansen | f7ac1d3 | 1999-12-29 12:37:22 +0000 | [diff] [blame] | 1383 | (Ptr)&buffer); |
Jack Jansen | 1f9249c | 1999-12-19 00:05:50 +0000 | [diff] [blame] | 1384 | |
| 1385 | if (_err != noErr) |
| 1386 | return PyMac_Error(_err); |
| 1387 | _res = Py_None; |
| 1388 | return _res; |
| 1389 | |
| 1390 | } |
| 1391 | |
| 1392 | static PyObject *CtlObj_GetControlDataHandle(_self, _args) |
| 1393 | ControlObject *_self; |
| 1394 | PyObject *_args; |
| 1395 | { |
| 1396 | PyObject *_res = NULL; |
| 1397 | |
| 1398 | OSErr _err; |
| 1399 | ControlPartCode inPart; |
| 1400 | ResType inTagName; |
| 1401 | Size bufferSize; |
| 1402 | Handle hdl; |
| 1403 | |
| 1404 | if (!PyArg_ParseTuple(_args, "hO&", |
| 1405 | &inPart, |
| 1406 | PyMac_GetOSType, &inTagName)) |
| 1407 | return NULL; |
| 1408 | |
| 1409 | /* Check it is handle-sized */ |
| 1410 | _err = GetControlDataSize(_self->ob_itself, |
| 1411 | inPart, |
| 1412 | inTagName, |
| 1413 | &bufferSize); |
| 1414 | if (_err != noErr) |
| 1415 | return PyMac_Error(_err); |
| 1416 | if (bufferSize != sizeof(Handle)) { |
| 1417 | PyErr_SetString(Ctl_Error, "GetControlDataSize() != sizeof(Handle)"); |
| 1418 | return NULL; |
| 1419 | } |
| 1420 | |
| 1421 | _err = GetControlData(_self->ob_itself, |
| 1422 | inPart, |
| 1423 | inTagName, |
| 1424 | sizeof(Handle), |
| 1425 | (Ptr)&hdl, |
| 1426 | &bufferSize); |
| 1427 | |
| 1428 | if (_err != noErr) { |
| 1429 | return PyMac_Error(_err); |
| 1430 | } |
| 1431 | return Py_BuildValue("O&", OptResObj_New, hdl); |
| 1432 | |
| 1433 | } |
| 1434 | |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 1435 | #ifndef TARGET_API_MAC_CARBON_NOTYET |
| 1436 | |
Jack Jansen | abc411b | 2000-03-20 16:09:09 +0000 | [diff] [blame] | 1437 | static PyObject *CtlObj_SetControlDataCallback(_self, _args) |
| 1438 | ControlObject *_self; |
| 1439 | PyObject *_args; |
| 1440 | { |
| 1441 | PyObject *_res = NULL; |
| 1442 | |
| 1443 | OSErr _err; |
| 1444 | ControlPartCode inPart; |
| 1445 | ResType inTagName; |
| 1446 | PyObject *callback; |
Jack Jansen | 85152b9 | 2000-07-11 21:12:55 +0000 | [diff] [blame^] | 1447 | UniversalProcPtr c_callback; |
Jack Jansen | abc411b | 2000-03-20 16:09:09 +0000 | [diff] [blame] | 1448 | |
| 1449 | if (!PyArg_ParseTuple(_args, "hO&O", |
| 1450 | &inPart, |
| 1451 | PyMac_GetOSType, &inTagName, |
| 1452 | &callback)) |
| 1453 | return NULL; |
| 1454 | |
Jack Jansen | 85152b9 | 2000-07-11 21:12:55 +0000 | [diff] [blame^] | 1455 | if ( setcallback((PyObject *)_self, inTagName, callback, &c_callback) < 0 ) |
Jack Jansen | abc411b | 2000-03-20 16:09:09 +0000 | [diff] [blame] | 1456 | return NULL; |
| 1457 | _err = SetControlData(_self->ob_itself, |
| 1458 | inPart, |
| 1459 | inTagName, |
| 1460 | sizeof(c_callback), |
| 1461 | (Ptr)&c_callback); |
| 1462 | |
| 1463 | if (_err != noErr) |
| 1464 | return PyMac_Error(_err); |
| 1465 | _res = Py_None; |
| 1466 | return _res; |
| 1467 | |
| 1468 | } |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 1469 | #endif |
| 1470 | |
| 1471 | #ifndef TARGET_API_MAC_CARBON_NOTYET |
Jack Jansen | abc411b | 2000-03-20 16:09:09 +0000 | [diff] [blame] | 1472 | |
Jack Jansen | 4c70413 | 1998-06-19 13:35:14 +0000 | [diff] [blame] | 1473 | static PyObject *CtlObj_GetPopupData(_self, _args) |
| 1474 | ControlObject *_self; |
| 1475 | PyObject *_args; |
| 1476 | { |
| 1477 | PyObject *_res = NULL; |
| 1478 | |
| 1479 | PopupPrivateDataHandle hdl; |
| 1480 | |
| 1481 | if ( (*_self->ob_itself)->contrlData == NULL ) { |
| 1482 | PyErr_SetString(Ctl_Error, "No contrlData handle in control"); |
| 1483 | return 0; |
| 1484 | } |
| 1485 | hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData; |
| 1486 | HLock((Handle)hdl); |
| 1487 | _res = Py_BuildValue("O&i", MenuObj_New, (*hdl)->mHandle, (int)(*hdl)->mID); |
| 1488 | HUnlock((Handle)hdl); |
| 1489 | return _res; |
| 1490 | |
| 1491 | } |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 1492 | #endif |
| 1493 | |
| 1494 | #ifndef TARGET_API_MAC_CARBON_NOTYET |
Jack Jansen | 4c70413 | 1998-06-19 13:35:14 +0000 | [diff] [blame] | 1495 | |
| 1496 | static PyObject *CtlObj_SetPopupData(_self, _args) |
| 1497 | ControlObject *_self; |
| 1498 | PyObject *_args; |
| 1499 | { |
| 1500 | PyObject *_res = NULL; |
| 1501 | |
| 1502 | PopupPrivateDataHandle hdl; |
| 1503 | MenuHandle mHandle; |
| 1504 | short mID; |
| 1505 | |
| 1506 | if (!PyArg_ParseTuple(_args, "O&h", MenuObj_Convert, &mHandle, &mID) ) |
| 1507 | return 0; |
| 1508 | if ( (*_self->ob_itself)->contrlData == NULL ) { |
| 1509 | PyErr_SetString(Ctl_Error, "No contrlData handle in control"); |
| 1510 | return 0; |
| 1511 | } |
| 1512 | hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData; |
| 1513 | (*hdl)->mHandle = mHandle; |
| 1514 | (*hdl)->mID = mID; |
| 1515 | Py_INCREF(Py_None); |
| 1516 | return Py_None; |
| 1517 | |
| 1518 | } |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 1519 | #endif |
Jack Jansen | 4c70413 | 1998-06-19 13:35:14 +0000 | [diff] [blame] | 1520 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1521 | static PyMethodDef CtlObj_methods[] = { |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1522 | {"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1, |
| 1523 | "(ControlPartCode hiliteState) -> None"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1524 | {"ShowControl", (PyCFunction)CtlObj_ShowControl, 1, |
| 1525 | "() -> None"}, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 1526 | {"HideControl", (PyCFunction)CtlObj_HideControl, 1, |
| 1527 | "() -> None"}, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1528 | {"IsControlActive", (PyCFunction)CtlObj_IsControlActive, 1, |
| 1529 | "() -> (Boolean _rv)"}, |
| 1530 | {"IsControlVisible", (PyCFunction)CtlObj_IsControlVisible, 1, |
| 1531 | "() -> (Boolean _rv)"}, |
| 1532 | {"ActivateControl", (PyCFunction)CtlObj_ActivateControl, 1, |
| 1533 | "() -> None"}, |
| 1534 | {"DeactivateControl", (PyCFunction)CtlObj_DeactivateControl, 1, |
| 1535 | "() -> None"}, |
| 1536 | {"SetControlVisibility", (PyCFunction)CtlObj_SetControlVisibility, 1, |
| 1537 | "(Boolean inIsVisible, Boolean inDoDraw) -> None"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1538 | {"Draw1Control", (PyCFunction)CtlObj_Draw1Control, 1, |
| 1539 | "() -> None"}, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1540 | {"GetBestControlRect", (PyCFunction)CtlObj_GetBestControlRect, 1, |
| 1541 | "() -> (Rect outRect, SInt16 outBaseLineOffset)"}, |
| 1542 | {"SetControlFontStyle", (PyCFunction)CtlObj_SetControlFontStyle, 1, |
| 1543 | "(ControlFontStyleRec inStyle) -> None"}, |
| 1544 | {"DrawControlInCurrentPort", (PyCFunction)CtlObj_DrawControlInCurrentPort, 1, |
| 1545 | "() -> None"}, |
| 1546 | {"SetUpControlBackground", (PyCFunction)CtlObj_SetUpControlBackground, 1, |
| 1547 | "(SInt16 inDepth, Boolean inIsColorDevice) -> None"}, |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 1548 | {"SetUpControlTextColor", (PyCFunction)CtlObj_SetUpControlTextColor, 1, |
| 1549 | "(SInt16 inDepth, Boolean inIsColorDevice) -> None"}, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 1550 | {"DragControl", (PyCFunction)CtlObj_DragControl, 1, |
Jack Jansen | 754d4a4 | 1995-11-14 10:41:55 +0000 | [diff] [blame] | 1551 | "(Point startPoint, Rect limitRect, Rect slopRect, DragConstraint axis) -> None"}, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 1552 | {"TestControl", (PyCFunction)CtlObj_TestControl, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1553 | "(Point testPoint) -> (ControlPartCode _rv)"}, |
| 1554 | {"HandleControlKey", (PyCFunction)CtlObj_HandleControlKey, 1, |
| 1555 | "(SInt16 inKeyCode, SInt16 inCharCode, SInt16 inModifiers) -> (SInt16 _rv)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1556 | {"MoveControl", (PyCFunction)CtlObj_MoveControl, 1, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 1557 | "(SInt16 h, SInt16 v) -> None"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1558 | {"SizeControl", (PyCFunction)CtlObj_SizeControl, 1, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 1559 | "(SInt16 w, SInt16 h) -> None"}, |
| 1560 | {"SetControlTitle", (PyCFunction)CtlObj_SetControlTitle, 1, |
| 1561 | "(Str255 title) -> None"}, |
| 1562 | {"GetControlTitle", (PyCFunction)CtlObj_GetControlTitle, 1, |
Jack Jansen | 4100900 | 1999-03-07 20:05:20 +0000 | [diff] [blame] | 1563 | "() -> (Str255 title)"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 1564 | {"GetControlValue", (PyCFunction)CtlObj_GetControlValue, 1, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 1565 | "() -> (SInt16 _rv)"}, |
| 1566 | {"SetControlValue", (PyCFunction)CtlObj_SetControlValue, 1, |
| 1567 | "(SInt16 newValue) -> None"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 1568 | {"GetControlMinimum", (PyCFunction)CtlObj_GetControlMinimum, 1, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 1569 | "() -> (SInt16 _rv)"}, |
| 1570 | {"SetControlMinimum", (PyCFunction)CtlObj_SetControlMinimum, 1, |
| 1571 | "(SInt16 newMinimum) -> None"}, |
Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 1572 | {"GetControlMaximum", (PyCFunction)CtlObj_GetControlMaximum, 1, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 1573 | "() -> (SInt16 _rv)"}, |
| 1574 | {"SetControlMaximum", (PyCFunction)CtlObj_SetControlMaximum, 1, |
| 1575 | "(SInt16 newMaximum) -> None"}, |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 1576 | {"GetControlViewSize", (PyCFunction)CtlObj_GetControlViewSize, 1, |
| 1577 | "() -> (SInt32 _rv)"}, |
| 1578 | {"SetControlViewSize", (PyCFunction)CtlObj_SetControlViewSize, 1, |
| 1579 | "(SInt32 newViewSize) -> None"}, |
| 1580 | {"GetControl32BitValue", (PyCFunction)CtlObj_GetControl32BitValue, 1, |
| 1581 | "() -> (SInt32 _rv)"}, |
| 1582 | {"SetControl32BitValue", (PyCFunction)CtlObj_SetControl32BitValue, 1, |
| 1583 | "(SInt32 newValue) -> None"}, |
| 1584 | {"GetControl32BitMaximum", (PyCFunction)CtlObj_GetControl32BitMaximum, 1, |
| 1585 | "() -> (SInt32 _rv)"}, |
| 1586 | {"SetControl32BitMaximum", (PyCFunction)CtlObj_SetControl32BitMaximum, 1, |
| 1587 | "(SInt32 newMaximum) -> None"}, |
| 1588 | {"GetControl32BitMinimum", (PyCFunction)CtlObj_GetControl32BitMinimum, 1, |
| 1589 | "() -> (SInt32 _rv)"}, |
| 1590 | {"SetControl32BitMinimum", (PyCFunction)CtlObj_SetControl32BitMinimum, 1, |
| 1591 | "(SInt32 newMinimum) -> None"}, |
| 1592 | {"IsValidControlHandle", (PyCFunction)CtlObj_IsValidControlHandle, 1, |
| 1593 | "() -> (Boolean _rv)"}, |
| 1594 | {"RemoveControlProperty", (PyCFunction)CtlObj_RemoveControlProperty, 1, |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 1595 | "(OSType propertyCreator, OSType propertyTag) -> None"}, |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 1596 | {"GetControlRegion", (PyCFunction)CtlObj_GetControlRegion, 1, |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 1597 | "(ControlPartCode inPart, RgnHandle outRegion) -> None"}, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 1598 | {"GetControlVariant", (PyCFunction)CtlObj_GetControlVariant, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1599 | "() -> (ControlVariant _rv)"}, |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 1600 | {"SetControlReference", (PyCFunction)CtlObj_SetControlReference, 1, |
| 1601 | "(SInt32 data) -> None"}, |
| 1602 | {"GetControlReference", (PyCFunction)CtlObj_GetControlReference, 1, |
| 1603 | "() -> (SInt32 _rv)"}, |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 1604 | |
| 1605 | #ifndef TARGET_API_MAC_CARBON |
Jack Jansen | c7fefed | 1997-08-15 14:32:18 +0000 | [diff] [blame] | 1606 | {"GetAuxiliaryControlRecord", (PyCFunction)CtlObj_GetAuxiliaryControlRecord, 1, |
| 1607 | "() -> (Boolean _rv, AuxCtlHandle acHndl)"}, |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 1608 | #endif |
| 1609 | |
| 1610 | #ifndef TARGET_API_MAC_CARBON |
Jack Jansen | c7fefed | 1997-08-15 14:32:18 +0000 | [diff] [blame] | 1611 | {"SetControlColor", (PyCFunction)CtlObj_SetControlColor, 1, |
| 1612 | "(CCTabHandle newColorTable) -> None"}, |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 1613 | #endif |
| 1614 | {"GetBevelButtonMenuValue", (PyCFunction)CtlObj_GetBevelButtonMenuValue, 1, |
| 1615 | "() -> (SInt16 outValue)"}, |
| 1616 | {"SetBevelButtonMenuValue", (PyCFunction)CtlObj_SetBevelButtonMenuValue, 1, |
| 1617 | "(SInt16 inValue) -> None"}, |
| 1618 | {"GetBevelButtonMenuHandle", (PyCFunction)CtlObj_GetBevelButtonMenuHandle, 1, |
| 1619 | "() -> (MenuHandle outHandle)"}, |
| 1620 | {"SetBevelButtonTransform", (PyCFunction)CtlObj_SetBevelButtonTransform, 1, |
| 1621 | "(IconTransformType transform) -> None"}, |
| 1622 | {"SetImageWellTransform", (PyCFunction)CtlObj_SetImageWellTransform, 1, |
| 1623 | "(IconTransformType inTransform) -> None"}, |
| 1624 | {"GetTabContentRect", (PyCFunction)CtlObj_GetTabContentRect, 1, |
| 1625 | "() -> (Rect outContentRect)"}, |
| 1626 | {"SetTabEnabled", (PyCFunction)CtlObj_SetTabEnabled, 1, |
| 1627 | "(SInt16 inTabToHilite, Boolean inEnabled) -> None"}, |
| 1628 | {"SetDisclosureTriangleLastValue", (PyCFunction)CtlObj_SetDisclosureTriangleLastValue, 1, |
| 1629 | "(SInt16 inValue) -> None"}, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1630 | {"SendControlMessage", (PyCFunction)CtlObj_SendControlMessage, 1, |
| 1631 | "(SInt16 inMessage, SInt32 inParam) -> (SInt32 _rv)"}, |
| 1632 | {"EmbedControl", (PyCFunction)CtlObj_EmbedControl, 1, |
| 1633 | "(ControlHandle inContainer) -> None"}, |
| 1634 | {"AutoEmbedControl", (PyCFunction)CtlObj_AutoEmbedControl, 1, |
| 1635 | "(WindowPtr inWindow) -> None"}, |
| 1636 | {"GetSuperControl", (PyCFunction)CtlObj_GetSuperControl, 1, |
| 1637 | "() -> (ControlHandle outParent)"}, |
| 1638 | {"CountSubControls", (PyCFunction)CtlObj_CountSubControls, 1, |
Jack Jansen | 24c3531 | 1999-12-09 22:49:51 +0000 | [diff] [blame] | 1639 | "() -> (UInt16 outNumChildren)"}, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1640 | {"GetIndexedSubControl", (PyCFunction)CtlObj_GetIndexedSubControl, 1, |
Jack Jansen | 24c3531 | 1999-12-09 22:49:51 +0000 | [diff] [blame] | 1641 | "(UInt16 inIndex) -> (ControlHandle outSubControl)"}, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1642 | {"SetControlSupervisor", (PyCFunction)CtlObj_SetControlSupervisor, 1, |
| 1643 | "(ControlHandle inBoss) -> None"}, |
| 1644 | {"GetControlFeatures", (PyCFunction)CtlObj_GetControlFeatures, 1, |
| 1645 | "() -> (UInt32 outFeatures)"}, |
| 1646 | {"GetControlDataSize", (PyCFunction)CtlObj_GetControlDataSize, 1, |
| 1647 | "(ControlPartCode inPart, ResType inTagName) -> (Size outMaxSize)"}, |
Jack Jansen | 5d56f4b | 1995-06-18 20:16:33 +0000 | [diff] [blame] | 1648 | {"as_Resource", (PyCFunction)CtlObj_as_Resource, 1, |
Jack Jansen | a1a0fef | 1999-12-23 14:32:06 +0000 | [diff] [blame] | 1649 | "() -> (Handle _rv)"}, |
Jack Jansen | 1a7d5b1 | 2000-03-21 16:25:23 +0000 | [diff] [blame] | 1650 | {"GetControlRect", (PyCFunction)CtlObj_GetControlRect, 1, |
| 1651 | "() -> (Rect rect)"}, |
Jack Jansen | cfb60ee | 1996-10-01 10:46:46 +0000 | [diff] [blame] | 1652 | {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1, |
| 1653 | "() -> None"}, |
Jack Jansen | 848250c | 1998-05-28 14:20:09 +0000 | [diff] [blame] | 1654 | {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1, |
Jack Jansen | 24c3531 | 1999-12-09 22:49:51 +0000 | [diff] [blame] | 1655 | "(Point startPoint [,trackercallback]) -> (ControlPartCode _rv)"}, |
| 1656 | {"HandleControlClick", (PyCFunction)CtlObj_HandleControlClick, 1, |
| 1657 | "(Point startPoint, Integer modifiers, [,trackercallback]) -> (ControlPartCode _rv)"}, |
| 1658 | {"SetControlData", (PyCFunction)CtlObj_SetControlData, 1, |
| 1659 | "(stuff) -> None"}, |
| 1660 | {"GetControlData", (PyCFunction)CtlObj_GetControlData, 1, |
| 1661 | "(part, type) -> String"}, |
Jack Jansen | 1f9249c | 1999-12-19 00:05:50 +0000 | [diff] [blame] | 1662 | {"SetControlDataHandle", (PyCFunction)CtlObj_SetControlDataHandle, 1, |
| 1663 | "(ResObj) -> None"}, |
| 1664 | {"GetControlDataHandle", (PyCFunction)CtlObj_GetControlDataHandle, 1, |
| 1665 | "(part, type) -> ResObj"}, |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 1666 | |
| 1667 | #ifndef TARGET_API_MAC_CARBON_NOTYET |
Jack Jansen | abc411b | 2000-03-20 16:09:09 +0000 | [diff] [blame] | 1668 | {"SetControlDataCallback", (PyCFunction)CtlObj_SetControlDataCallback, 1, |
| 1669 | "(callbackfunc) -> None"}, |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 1670 | #endif |
| 1671 | |
| 1672 | #ifndef TARGET_API_MAC_CARBON_NOTYET |
Jack Jansen | 4c70413 | 1998-06-19 13:35:14 +0000 | [diff] [blame] | 1673 | {"GetPopupData", (PyCFunction)CtlObj_GetPopupData, 1, |
| 1674 | NULL}, |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 1675 | #endif |
| 1676 | |
| 1677 | #ifndef TARGET_API_MAC_CARBON_NOTYET |
Jack Jansen | 4c70413 | 1998-06-19 13:35:14 +0000 | [diff] [blame] | 1678 | {"SetPopupData", (PyCFunction)CtlObj_SetPopupData, 1, |
| 1679 | NULL}, |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 1680 | #endif |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1681 | {NULL, NULL, 0} |
| 1682 | }; |
| 1683 | |
| 1684 | PyMethodChain CtlObj_chain = { CtlObj_methods, NULL }; |
| 1685 | |
| 1686 | static PyObject *CtlObj_getattr(self, name) |
| 1687 | ControlObject *self; |
| 1688 | char *name; |
| 1689 | { |
| 1690 | return Py_FindMethodInChain(&CtlObj_chain, (PyObject *)self, name); |
| 1691 | } |
| 1692 | |
| 1693 | #define CtlObj_setattr NULL |
| 1694 | |
Jack Jansen | 8387af6 | 1999-03-13 23:07:32 +0000 | [diff] [blame] | 1695 | static int CtlObj_compare(self, other) |
| 1696 | ControlObject *self, *other; |
| 1697 | { |
| 1698 | unsigned long v, w; |
| 1699 | |
| 1700 | if (!CtlObj_Check((PyObject *)other)) |
| 1701 | { |
| 1702 | v=(unsigned long)self; |
| 1703 | w=(unsigned long)other; |
| 1704 | } |
| 1705 | else |
| 1706 | { |
| 1707 | v=(unsigned long)self->ob_itself; |
| 1708 | w=(unsigned long)other->ob_itself; |
| 1709 | } |
| 1710 | if( v < w ) return -1; |
| 1711 | if( v > w ) return 1; |
| 1712 | return 0; |
| 1713 | } |
| 1714 | |
| 1715 | #define CtlObj_repr NULL |
| 1716 | |
| 1717 | static long CtlObj_hash(self) |
| 1718 | ControlObject *self; |
| 1719 | { |
| 1720 | return (long)self->ob_itself; |
| 1721 | } |
| 1722 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1723 | PyTypeObject Control_Type = { |
| 1724 | PyObject_HEAD_INIT(&PyType_Type) |
| 1725 | 0, /*ob_size*/ |
| 1726 | "Control", /*tp_name*/ |
| 1727 | sizeof(ControlObject), /*tp_basicsize*/ |
| 1728 | 0, /*tp_itemsize*/ |
| 1729 | /* methods */ |
| 1730 | (destructor) CtlObj_dealloc, /*tp_dealloc*/ |
| 1731 | 0, /*tp_print*/ |
| 1732 | (getattrfunc) CtlObj_getattr, /*tp_getattr*/ |
| 1733 | (setattrfunc) CtlObj_setattr, /*tp_setattr*/ |
Jack Jansen | 8387af6 | 1999-03-13 23:07:32 +0000 | [diff] [blame] | 1734 | (cmpfunc) CtlObj_compare, /*tp_compare*/ |
| 1735 | (reprfunc) CtlObj_repr, /*tp_repr*/ |
| 1736 | (PyNumberMethods *)0, /* tp_as_number */ |
| 1737 | (PySequenceMethods *)0, /* tp_as_sequence */ |
| 1738 | (PyMappingMethods *)0, /* tp_as_mapping */ |
| 1739 | (hashfunc) CtlObj_hash, /*tp_hash*/ |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1740 | }; |
| 1741 | |
| 1742 | /* -------------------- End object type Control --------------------- */ |
| 1743 | |
| 1744 | |
| 1745 | static PyObject *Ctl_NewControl(_self, _args) |
| 1746 | PyObject *_self; |
| 1747 | PyObject *_args; |
| 1748 | { |
| 1749 | PyObject *_res = NULL; |
| 1750 | ControlHandle _rv; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1751 | WindowPtr owningWindow; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1752 | Rect boundsRect; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1753 | Str255 controlTitle; |
| 1754 | Boolean initiallyVisible; |
| 1755 | SInt16 initialValue; |
| 1756 | SInt16 minimumValue; |
| 1757 | SInt16 maximumValue; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 1758 | SInt16 procID; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1759 | SInt32 controlReference; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1760 | if (!PyArg_ParseTuple(_args, "O&O&O&bhhhhl", |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1761 | WinObj_Convert, &owningWindow, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1762 | PyMac_GetRect, &boundsRect, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1763 | PyMac_GetStr255, controlTitle, |
| 1764 | &initiallyVisible, |
| 1765 | &initialValue, |
| 1766 | &minimumValue, |
| 1767 | &maximumValue, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1768 | &procID, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1769 | &controlReference)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1770 | return NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1771 | _rv = NewControl(owningWindow, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1772 | &boundsRect, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1773 | controlTitle, |
| 1774 | initiallyVisible, |
| 1775 | initialValue, |
| 1776 | minimumValue, |
| 1777 | maximumValue, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1778 | procID, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1779 | controlReference); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1780 | _res = Py_BuildValue("O&", |
| 1781 | CtlObj_New, _rv); |
| 1782 | return _res; |
| 1783 | } |
| 1784 | |
| 1785 | static PyObject *Ctl_GetNewControl(_self, _args) |
| 1786 | PyObject *_self; |
| 1787 | PyObject *_args; |
| 1788 | { |
| 1789 | PyObject *_res = NULL; |
| 1790 | ControlHandle _rv; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1791 | SInt16 resourceID; |
| 1792 | WindowPtr owningWindow; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1793 | if (!PyArg_ParseTuple(_args, "hO&", |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1794 | &resourceID, |
| 1795 | WinObj_Convert, &owningWindow)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1796 | return NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1797 | _rv = GetNewControl(resourceID, |
| 1798 | owningWindow); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1799 | _res = Py_BuildValue("O&", |
| 1800 | CtlObj_New, _rv); |
| 1801 | return _res; |
| 1802 | } |
| 1803 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1804 | static PyObject *Ctl_DrawControls(_self, _args) |
| 1805 | PyObject *_self; |
| 1806 | PyObject *_args; |
| 1807 | { |
| 1808 | PyObject *_res = NULL; |
| 1809 | WindowPtr theWindow; |
| 1810 | if (!PyArg_ParseTuple(_args, "O&", |
| 1811 | WinObj_Convert, &theWindow)) |
| 1812 | return NULL; |
| 1813 | DrawControls(theWindow); |
| 1814 | Py_INCREF(Py_None); |
| 1815 | _res = Py_None; |
| 1816 | return _res; |
| 1817 | } |
| 1818 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1819 | static PyObject *Ctl_UpdateControls(_self, _args) |
| 1820 | PyObject *_self; |
| 1821 | PyObject *_args; |
| 1822 | { |
| 1823 | PyObject *_res = NULL; |
| 1824 | WindowPtr theWindow; |
Jack Jansen | 2b72417 | 1996-04-10 14:48:19 +0000 | [diff] [blame] | 1825 | RgnHandle updateRegion; |
| 1826 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 1827 | WinObj_Convert, &theWindow, |
| 1828 | ResObj_Convert, &updateRegion)) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1829 | return NULL; |
| 1830 | UpdateControls(theWindow, |
Jack Jansen | 2b72417 | 1996-04-10 14:48:19 +0000 | [diff] [blame] | 1831 | updateRegion); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1832 | Py_INCREF(Py_None); |
| 1833 | _res = Py_None; |
| 1834 | return _res; |
| 1835 | } |
| 1836 | |
| 1837 | static PyObject *Ctl_FindControl(_self, _args) |
| 1838 | PyObject *_self; |
| 1839 | PyObject *_args; |
| 1840 | { |
| 1841 | PyObject *_res = NULL; |
Jack Jansen | 7d0bc83 | 1995-06-09 20:56:31 +0000 | [diff] [blame] | 1842 | ControlPartCode _rv; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1843 | Point testPoint; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1844 | WindowPtr theWindow; |
| 1845 | ControlHandle theControl; |
| 1846 | if (!PyArg_ParseTuple(_args, "O&O&", |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1847 | PyMac_GetPoint, &testPoint, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1848 | WinObj_Convert, &theWindow)) |
| 1849 | return NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1850 | _rv = FindControl(testPoint, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1851 | theWindow, |
| 1852 | &theControl); |
| 1853 | _res = Py_BuildValue("hO&", |
| 1854 | _rv, |
| 1855 | CtlObj_WhichControl, theControl); |
| 1856 | return _res; |
| 1857 | } |
| 1858 | |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1859 | static PyObject *Ctl_FindControlUnderMouse(_self, _args) |
| 1860 | PyObject *_self; |
| 1861 | PyObject *_args; |
| 1862 | { |
| 1863 | PyObject *_res = NULL; |
| 1864 | ControlHandle _rv; |
| 1865 | Point inWhere; |
| 1866 | WindowPtr inWindow; |
| 1867 | SInt16 outPart; |
| 1868 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 1869 | PyMac_GetPoint, &inWhere, |
| 1870 | WinObj_Convert, &inWindow)) |
| 1871 | return NULL; |
| 1872 | _rv = FindControlUnderMouse(inWhere, |
| 1873 | inWindow, |
| 1874 | &outPart); |
| 1875 | _res = Py_BuildValue("O&h", |
| 1876 | CtlObj_New, _rv, |
| 1877 | outPart); |
| 1878 | return _res; |
| 1879 | } |
| 1880 | |
| 1881 | static PyObject *Ctl_IdleControls(_self, _args) |
| 1882 | PyObject *_self; |
| 1883 | PyObject *_args; |
| 1884 | { |
| 1885 | PyObject *_res = NULL; |
| 1886 | WindowPtr inWindow; |
| 1887 | if (!PyArg_ParseTuple(_args, "O&", |
| 1888 | WinObj_Convert, &inWindow)) |
| 1889 | return NULL; |
| 1890 | IdleControls(inWindow); |
| 1891 | Py_INCREF(Py_None); |
| 1892 | _res = Py_None; |
| 1893 | return _res; |
| 1894 | } |
| 1895 | |
| 1896 | static PyObject *Ctl_DumpControlHierarchy(_self, _args) |
| 1897 | PyObject *_self; |
| 1898 | PyObject *_args; |
| 1899 | { |
| 1900 | PyObject *_res = NULL; |
| 1901 | OSErr _err; |
| 1902 | WindowPtr inWindow; |
| 1903 | FSSpec inDumpFile; |
| 1904 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 1905 | WinObj_Convert, &inWindow, |
| 1906 | PyMac_GetFSSpec, &inDumpFile)) |
| 1907 | return NULL; |
| 1908 | _err = DumpControlHierarchy(inWindow, |
| 1909 | &inDumpFile); |
| 1910 | if (_err != noErr) return PyMac_Error(_err); |
| 1911 | Py_INCREF(Py_None); |
| 1912 | _res = Py_None; |
| 1913 | return _res; |
| 1914 | } |
| 1915 | |
| 1916 | static PyObject *Ctl_CreateRootControl(_self, _args) |
| 1917 | PyObject *_self; |
| 1918 | PyObject *_args; |
| 1919 | { |
| 1920 | PyObject *_res = NULL; |
| 1921 | OSErr _err; |
| 1922 | WindowPtr inWindow; |
| 1923 | ControlHandle outControl; |
| 1924 | if (!PyArg_ParseTuple(_args, "O&", |
| 1925 | WinObj_Convert, &inWindow)) |
| 1926 | return NULL; |
| 1927 | _err = CreateRootControl(inWindow, |
| 1928 | &outControl); |
| 1929 | if (_err != noErr) return PyMac_Error(_err); |
| 1930 | _res = Py_BuildValue("O&", |
| 1931 | CtlObj_WhichControl, outControl); |
| 1932 | return _res; |
| 1933 | } |
| 1934 | |
| 1935 | static PyObject *Ctl_GetRootControl(_self, _args) |
| 1936 | PyObject *_self; |
| 1937 | PyObject *_args; |
| 1938 | { |
| 1939 | PyObject *_res = NULL; |
| 1940 | OSErr _err; |
| 1941 | WindowPtr inWindow; |
| 1942 | ControlHandle outControl; |
| 1943 | if (!PyArg_ParseTuple(_args, "O&", |
| 1944 | WinObj_Convert, &inWindow)) |
| 1945 | return NULL; |
| 1946 | _err = GetRootControl(inWindow, |
| 1947 | &outControl); |
| 1948 | if (_err != noErr) return PyMac_Error(_err); |
| 1949 | _res = Py_BuildValue("O&", |
| 1950 | CtlObj_WhichControl, outControl); |
| 1951 | return _res; |
| 1952 | } |
| 1953 | |
| 1954 | static PyObject *Ctl_GetKeyboardFocus(_self, _args) |
| 1955 | PyObject *_self; |
| 1956 | PyObject *_args; |
| 1957 | { |
| 1958 | PyObject *_res = NULL; |
| 1959 | OSErr _err; |
| 1960 | WindowPtr inWindow; |
| 1961 | ControlHandle outControl; |
| 1962 | if (!PyArg_ParseTuple(_args, "O&", |
| 1963 | WinObj_Convert, &inWindow)) |
| 1964 | return NULL; |
| 1965 | _err = GetKeyboardFocus(inWindow, |
| 1966 | &outControl); |
| 1967 | if (_err != noErr) return PyMac_Error(_err); |
| 1968 | _res = Py_BuildValue("O&", |
| 1969 | CtlObj_WhichControl, outControl); |
| 1970 | return _res; |
| 1971 | } |
| 1972 | |
| 1973 | static PyObject *Ctl_SetKeyboardFocus(_self, _args) |
| 1974 | PyObject *_self; |
| 1975 | PyObject *_args; |
| 1976 | { |
| 1977 | PyObject *_res = NULL; |
| 1978 | OSErr _err; |
| 1979 | WindowPtr inWindow; |
| 1980 | ControlHandle inControl; |
| 1981 | ControlFocusPart inPart; |
| 1982 | if (!PyArg_ParseTuple(_args, "O&O&h", |
| 1983 | WinObj_Convert, &inWindow, |
| 1984 | CtlObj_Convert, &inControl, |
| 1985 | &inPart)) |
| 1986 | return NULL; |
| 1987 | _err = SetKeyboardFocus(inWindow, |
| 1988 | inControl, |
| 1989 | inPart); |
| 1990 | if (_err != noErr) return PyMac_Error(_err); |
| 1991 | Py_INCREF(Py_None); |
| 1992 | _res = Py_None; |
| 1993 | return _res; |
| 1994 | } |
| 1995 | |
| 1996 | static PyObject *Ctl_AdvanceKeyboardFocus(_self, _args) |
| 1997 | PyObject *_self; |
| 1998 | PyObject *_args; |
| 1999 | { |
| 2000 | PyObject *_res = NULL; |
| 2001 | OSErr _err; |
| 2002 | WindowPtr inWindow; |
| 2003 | if (!PyArg_ParseTuple(_args, "O&", |
| 2004 | WinObj_Convert, &inWindow)) |
| 2005 | return NULL; |
| 2006 | _err = AdvanceKeyboardFocus(inWindow); |
| 2007 | if (_err != noErr) return PyMac_Error(_err); |
| 2008 | Py_INCREF(Py_None); |
| 2009 | _res = Py_None; |
| 2010 | return _res; |
| 2011 | } |
| 2012 | |
| 2013 | static PyObject *Ctl_ReverseKeyboardFocus(_self, _args) |
| 2014 | PyObject *_self; |
| 2015 | PyObject *_args; |
| 2016 | { |
| 2017 | PyObject *_res = NULL; |
| 2018 | OSErr _err; |
| 2019 | WindowPtr inWindow; |
| 2020 | if (!PyArg_ParseTuple(_args, "O&", |
| 2021 | WinObj_Convert, &inWindow)) |
| 2022 | return NULL; |
| 2023 | _err = ReverseKeyboardFocus(inWindow); |
| 2024 | if (_err != noErr) return PyMac_Error(_err); |
| 2025 | Py_INCREF(Py_None); |
| 2026 | _res = Py_None; |
| 2027 | return _res; |
| 2028 | } |
| 2029 | |
| 2030 | static PyObject *Ctl_ClearKeyboardFocus(_self, _args) |
| 2031 | PyObject *_self; |
| 2032 | PyObject *_args; |
| 2033 | { |
| 2034 | PyObject *_res = NULL; |
| 2035 | OSErr _err; |
| 2036 | WindowPtr inWindow; |
| 2037 | if (!PyArg_ParseTuple(_args, "O&", |
| 2038 | WinObj_Convert, &inWindow)) |
| 2039 | return NULL; |
| 2040 | _err = ClearKeyboardFocus(inWindow); |
| 2041 | if (_err != noErr) return PyMac_Error(_err); |
| 2042 | Py_INCREF(Py_None); |
| 2043 | _res = Py_None; |
| 2044 | return _res; |
| 2045 | } |
| 2046 | |
Jack Jansen | e058189 | 1999-02-07 14:02:03 +0000 | [diff] [blame] | 2047 | static PyObject *Ctl_as_Control(_self, _args) |
| 2048 | PyObject *_self; |
| 2049 | PyObject *_args; |
| 2050 | { |
| 2051 | PyObject *_res = NULL; |
| 2052 | ControlHandle _rv; |
| 2053 | Handle h; |
| 2054 | if (!PyArg_ParseTuple(_args, "O&", |
| 2055 | ResObj_Convert, &h)) |
| 2056 | return NULL; |
| 2057 | _rv = as_Control(h); |
| 2058 | _res = Py_BuildValue("O&", |
| 2059 | CtlObj_New, _rv); |
| 2060 | return _res; |
| 2061 | } |
| 2062 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 2063 | static PyMethodDef Ctl_methods[] = { |
| 2064 | {"NewControl", (PyCFunction)Ctl_NewControl, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 2065 | "(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] | 2066 | {"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 2067 | "(SInt16 resourceID, WindowPtr owningWindow) -> (ControlHandle _rv)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 2068 | {"DrawControls", (PyCFunction)Ctl_DrawControls, 1, |
| 2069 | "(WindowPtr theWindow) -> None"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 2070 | {"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1, |
Jack Jansen | 2b72417 | 1996-04-10 14:48:19 +0000 | [diff] [blame] | 2071 | "(WindowPtr theWindow, RgnHandle updateRegion) -> None"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 2072 | {"FindControl", (PyCFunction)Ctl_FindControl, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 2073 | "(Point testPoint, WindowPtr theWindow) -> (ControlPartCode _rv, ControlHandle theControl)"}, |
| 2074 | {"FindControlUnderMouse", (PyCFunction)Ctl_FindControlUnderMouse, 1, |
| 2075 | "(Point inWhere, WindowPtr inWindow) -> (ControlHandle _rv, SInt16 outPart)"}, |
| 2076 | {"IdleControls", (PyCFunction)Ctl_IdleControls, 1, |
| 2077 | "(WindowPtr inWindow) -> None"}, |
| 2078 | {"DumpControlHierarchy", (PyCFunction)Ctl_DumpControlHierarchy, 1, |
| 2079 | "(WindowPtr inWindow, FSSpec inDumpFile) -> None"}, |
| 2080 | {"CreateRootControl", (PyCFunction)Ctl_CreateRootControl, 1, |
| 2081 | "(WindowPtr inWindow) -> (ControlHandle outControl)"}, |
| 2082 | {"GetRootControl", (PyCFunction)Ctl_GetRootControl, 1, |
| 2083 | "(WindowPtr inWindow) -> (ControlHandle outControl)"}, |
| 2084 | {"GetKeyboardFocus", (PyCFunction)Ctl_GetKeyboardFocus, 1, |
| 2085 | "(WindowPtr inWindow) -> (ControlHandle outControl)"}, |
| 2086 | {"SetKeyboardFocus", (PyCFunction)Ctl_SetKeyboardFocus, 1, |
| 2087 | "(WindowPtr inWindow, ControlHandle inControl, ControlFocusPart inPart) -> None"}, |
| 2088 | {"AdvanceKeyboardFocus", (PyCFunction)Ctl_AdvanceKeyboardFocus, 1, |
| 2089 | "(WindowPtr inWindow) -> None"}, |
| 2090 | {"ReverseKeyboardFocus", (PyCFunction)Ctl_ReverseKeyboardFocus, 1, |
| 2091 | "(WindowPtr inWindow) -> None"}, |
| 2092 | {"ClearKeyboardFocus", (PyCFunction)Ctl_ClearKeyboardFocus, 1, |
| 2093 | "(WindowPtr inWindow) -> None"}, |
Jack Jansen | e058189 | 1999-02-07 14:02:03 +0000 | [diff] [blame] | 2094 | {"as_Control", (PyCFunction)Ctl_as_Control, 1, |
| 2095 | "(Handle h) -> (ControlHandle _rv)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 2096 | {NULL, NULL, 0} |
| 2097 | }; |
| 2098 | |
| 2099 | |
| 2100 | |
Jack Jansen | 8387af6 | 1999-03-13 23:07:32 +0000 | [diff] [blame] | 2101 | PyObject *CtlObj_NewUnmanaged(itself) |
| 2102 | ControlHandle itself; |
| 2103 | { |
| 2104 | ControlObject *it; |
| 2105 | if (itself == NULL) return PyMac_Error(resNotFound); |
| 2106 | it = PyObject_NEW(ControlObject, &Control_Type); |
| 2107 | if (it == NULL) return NULL; |
| 2108 | it->ob_itself = itself; |
Jack Jansen | 1a7d5b1 | 2000-03-21 16:25:23 +0000 | [diff] [blame] | 2109 | it->ob_callbackdict = NULL; |
Jack Jansen | 8387af6 | 1999-03-13 23:07:32 +0000 | [diff] [blame] | 2110 | return (PyObject *)it; |
| 2111 | } |
| 2112 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 2113 | PyObject * |
| 2114 | CtlObj_WhichControl(ControlHandle c) |
| 2115 | { |
| 2116 | PyObject *it; |
Jack Jansen | 24c3531 | 1999-12-09 22:49:51 +0000 | [diff] [blame] | 2117 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 2118 | if (c == NULL) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 2119 | it = Py_None; |
Jack Jansen | 8387af6 | 1999-03-13 23:07:32 +0000 | [diff] [blame] | 2120 | else { |
| 2121 | it = (PyObject *) GetControlReference(c); |
| 2122 | /* |
| 2123 | ** If the refcon is zero or doesn't point back to the Python object |
| 2124 | ** the control is not ours. Return a temporary object. |
| 2125 | */ |
| 2126 | if (it == NULL || ((ControlObject *)it)->ob_itself != c) |
| 2127 | return CtlObj_NewUnmanaged(c); |
| 2128 | } |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 2129 | Py_INCREF(it); |
| 2130 | return it; |
| 2131 | } |
| 2132 | |
Jack Jansen | 848250c | 1998-05-28 14:20:09 +0000 | [diff] [blame] | 2133 | static int |
| 2134 | settrackfunc(obj) |
| 2135 | PyObject *obj; |
| 2136 | { |
| 2137 | if (tracker) { |
| 2138 | PyErr_SetString(Ctl_Error, "Tracker function in use"); |
| 2139 | return 0; |
| 2140 | } |
| 2141 | tracker = obj; |
| 2142 | Py_INCREF(tracker); |
| 2143 | } |
| 2144 | |
| 2145 | static void |
| 2146 | clrtrackfunc() |
| 2147 | { |
| 2148 | Py_XDECREF(tracker); |
| 2149 | tracker = 0; |
| 2150 | } |
| 2151 | |
| 2152 | static pascal void |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 2153 | mytracker(ControlHandle ctl, short part) |
Jack Jansen | 848250c | 1998-05-28 14:20:09 +0000 | [diff] [blame] | 2154 | { |
| 2155 | PyObject *args, *rv=0; |
Jack Jansen | 24c3531 | 1999-12-09 22:49:51 +0000 | [diff] [blame] | 2156 | |
Jack Jansen | 848250c | 1998-05-28 14:20:09 +0000 | [diff] [blame] | 2157 | args = Py_BuildValue("(O&i)", CtlObj_WhichControl, ctl, (int)part); |
| 2158 | if (args && tracker) { |
| 2159 | rv = PyEval_CallObject(tracker, args); |
| 2160 | Py_DECREF(args); |
| 2161 | } |
| 2162 | if (rv) |
| 2163 | Py_DECREF(rv); |
| 2164 | else |
Jack Jansen | 24c3531 | 1999-12-09 22:49:51 +0000 | [diff] [blame] | 2165 | PySys_WriteStderr("TrackControl or HandleControlClick: exception in tracker function\n"); |
Jack Jansen | 848250c | 1998-05-28 14:20:09 +0000 | [diff] [blame] | 2166 | } |
| 2167 | |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 2168 | #ifndef TARGET_API_MAC_CARBON_NOTYET |
Jack Jansen | abc411b | 2000-03-20 16:09:09 +0000 | [diff] [blame] | 2169 | static int |
Jack Jansen | 85152b9 | 2000-07-11 21:12:55 +0000 | [diff] [blame^] | 2170 | setcallback(myself, which, callback, uppp) |
| 2171 | PyObject *myself; |
Jack Jansen | abc411b | 2000-03-20 16:09:09 +0000 | [diff] [blame] | 2172 | OSType which; |
| 2173 | PyObject *callback; |
| 2174 | UniversalProcPtr *uppp; |
| 2175 | { |
Jack Jansen | 85152b9 | 2000-07-11 21:12:55 +0000 | [diff] [blame^] | 2176 | ControlObject *self = (ControlObject *)myself; |
Jack Jansen | abc411b | 2000-03-20 16:09:09 +0000 | [diff] [blame] | 2177 | char keybuf[9]; |
| 2178 | |
| 2179 | if ( which == kControlUserPaneDrawProcTag ) |
Jack Jansen | 1b6e821 | 2000-04-05 21:30:57 +0000 | [diff] [blame] | 2180 | *uppp = (UniversalProcPtr)mydrawproc_upp; |
Jack Jansen | abc411b | 2000-03-20 16:09:09 +0000 | [diff] [blame] | 2181 | else if ( which == kControlUserPaneIdleProcTag ) |
Jack Jansen | 1b6e821 | 2000-04-05 21:30:57 +0000 | [diff] [blame] | 2182 | *uppp = (UniversalProcPtr)myidleproc_upp; |
Jack Jansen | a27e9fb | 2000-03-21 23:03:02 +0000 | [diff] [blame] | 2183 | else if ( which == kControlUserPaneHitTestProcTag ) |
Jack Jansen | 1b6e821 | 2000-04-05 21:30:57 +0000 | [diff] [blame] | 2184 | *uppp = (UniversalProcPtr)myhittestproc_upp; |
Jack Jansen | a27e9fb | 2000-03-21 23:03:02 +0000 | [diff] [blame] | 2185 | else if ( which == kControlUserPaneTrackingProcTag ) |
Jack Jansen | 1b6e821 | 2000-04-05 21:30:57 +0000 | [diff] [blame] | 2186 | *uppp = (UniversalProcPtr)mytrackingproc_upp; |
Jack Jansen | abc411b | 2000-03-20 16:09:09 +0000 | [diff] [blame] | 2187 | else |
| 2188 | return -1; |
| 2189 | /* Only now do we test for clearing of the callback: */ |
| 2190 | if ( callback == Py_None ) |
| 2191 | *uppp = NULL; |
| 2192 | /* Create the dict if it doesn't exist yet (so we don't get such a dict for every control) */ |
| 2193 | if ( self->ob_callbackdict == NULL ) |
| 2194 | if ( (self->ob_callbackdict = PyDict_New()) == NULL ) |
| 2195 | return -1; |
| 2196 | /* And store the Python callback */ |
| 2197 | sprintf(keybuf, "%x", which); |
| 2198 | if (PyDict_SetItemString(self->ob_callbackdict, keybuf, callback) < 0) |
| 2199 | return -1; |
| 2200 | return 0; |
| 2201 | } |
| 2202 | |
| 2203 | static PyObject * |
| 2204 | callcallback(self, which, arglist) |
| 2205 | ControlObject *self; |
| 2206 | OSType which; |
| 2207 | PyObject *arglist; |
| 2208 | { |
| 2209 | char keybuf[9]; |
| 2210 | PyObject *func, *rv; |
| 2211 | |
| 2212 | sprintf(keybuf, "%x", which); |
| 2213 | if ( self->ob_callbackdict == NULL || |
| 2214 | (func = PyDict_GetItemString(self->ob_callbackdict, keybuf)) == NULL ) { |
Jack Jansen | a27e9fb | 2000-03-21 23:03:02 +0000 | [diff] [blame] | 2215 | PySys_WriteStderr("Control callback %x without callback object\n", which); |
Jack Jansen | abc411b | 2000-03-20 16:09:09 +0000 | [diff] [blame] | 2216 | return NULL; |
| 2217 | } |
| 2218 | rv = PyEval_CallObject(func, arglist); |
| 2219 | if ( rv == NULL ) |
Jack Jansen | a27e9fb | 2000-03-21 23:03:02 +0000 | [diff] [blame] | 2220 | PySys_WriteStderr("Exception in control callback %x handler\n", which); |
Jack Jansen | abc411b | 2000-03-20 16:09:09 +0000 | [diff] [blame] | 2221 | return rv; |
| 2222 | } |
| 2223 | |
| 2224 | static pascal void |
| 2225 | mydrawproc(ControlHandle control, SInt16 part) |
| 2226 | { |
| 2227 | ControlObject *ctl_obj; |
| 2228 | PyObject *arglist, *rv; |
| 2229 | |
| 2230 | ctl_obj = (ControlObject *)CtlObj_WhichControl(control); |
| 2231 | arglist = Py_BuildValue("Oh", ctl_obj, part); |
| 2232 | rv = callcallback(ctl_obj, kControlUserPaneDrawProcTag, arglist); |
| 2233 | Py_XDECREF(arglist); |
| 2234 | Py_XDECREF(rv); |
| 2235 | } |
| 2236 | |
| 2237 | static pascal void |
| 2238 | myidleproc(ControlHandle control) |
| 2239 | { |
| 2240 | ControlObject *ctl_obj; |
| 2241 | PyObject *arglist, *rv; |
| 2242 | |
| 2243 | ctl_obj = (ControlObject *)CtlObj_WhichControl(control); |
| 2244 | arglist = Py_BuildValue("O", ctl_obj); |
| 2245 | rv = callcallback(ctl_obj, kControlUserPaneIdleProcTag, arglist); |
| 2246 | Py_XDECREF(arglist); |
| 2247 | Py_XDECREF(rv); |
| 2248 | } |
| 2249 | |
Jack Jansen | a27e9fb | 2000-03-21 23:03:02 +0000 | [diff] [blame] | 2250 | static pascal ControlPartCode |
| 2251 | myhittestproc(ControlHandle control, Point where) |
| 2252 | { |
| 2253 | ControlObject *ctl_obj; |
| 2254 | PyObject *arglist, *rv; |
| 2255 | short c_rv = -1; |
| 2256 | |
| 2257 | ctl_obj = (ControlObject *)CtlObj_WhichControl(control); |
Jack Jansen | deb6373 | 2000-03-22 15:35:24 +0000 | [diff] [blame] | 2258 | arglist = Py_BuildValue("OO&", ctl_obj, PyMac_BuildPoint, where); |
Jack Jansen | a27e9fb | 2000-03-21 23:03:02 +0000 | [diff] [blame] | 2259 | rv = callcallback(ctl_obj, kControlUserPaneHitTestProcTag, arglist); |
| 2260 | Py_XDECREF(arglist); |
| 2261 | /* Ignore errors, nothing we can do about them */ |
| 2262 | if ( rv ) |
| 2263 | PyArg_Parse(rv, "h", &c_rv); |
| 2264 | Py_XDECREF(rv); |
| 2265 | return (ControlPartCode)c_rv; |
| 2266 | } |
| 2267 | |
| 2268 | static pascal ControlPartCode |
| 2269 | mytrackingproc(ControlHandle control, Point startPt, ControlActionUPP actionProc) |
| 2270 | { |
| 2271 | ControlObject *ctl_obj; |
| 2272 | PyObject *arglist, *rv; |
| 2273 | short c_rv = -1; |
| 2274 | |
| 2275 | ctl_obj = (ControlObject *)CtlObj_WhichControl(control); |
| 2276 | /* We cannot pass the actionProc without lots of work */ |
Jack Jansen | deb6373 | 2000-03-22 15:35:24 +0000 | [diff] [blame] | 2277 | arglist = Py_BuildValue("OO&", ctl_obj, PyMac_BuildPoint, startPt); |
Jack Jansen | a27e9fb | 2000-03-21 23:03:02 +0000 | [diff] [blame] | 2278 | rv = callcallback(ctl_obj, kControlUserPaneTrackingProcTag, arglist); |
| 2279 | Py_XDECREF(arglist); |
| 2280 | if ( rv ) |
| 2281 | PyArg_Parse(rv, "h", &c_rv); |
| 2282 | Py_XDECREF(rv); |
| 2283 | return (ControlPartCode)c_rv; |
| 2284 | } |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 2285 | #endif |
Jack Jansen | abc411b | 2000-03-20 16:09:09 +0000 | [diff] [blame] | 2286 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 2287 | |
| 2288 | void initCtl() |
| 2289 | { |
| 2290 | PyObject *m; |
| 2291 | PyObject *d; |
| 2292 | |
| 2293 | |
| 2294 | |
Jack Jansen | 848250c | 1998-05-28 14:20:09 +0000 | [diff] [blame] | 2295 | mytracker_upp = NewControlActionProc(mytracker); |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 2296 | #ifndef TARGET_API_MAC_CARBON_NOTYET |
Jack Jansen | abc411b | 2000-03-20 16:09:09 +0000 | [diff] [blame] | 2297 | mydrawproc_upp = NewControlUserPaneDrawProc(mydrawproc); |
Jack Jansen | 1b6e821 | 2000-04-05 21:30:57 +0000 | [diff] [blame] | 2298 | myidleproc_upp = NewControlUserPaneIdleProc(myidleproc); |
Jack Jansen | a27e9fb | 2000-03-21 23:03:02 +0000 | [diff] [blame] | 2299 | myhittestproc_upp = NewControlUserPaneHitTestProc(myhittestproc); |
| 2300 | mytrackingproc_upp = NewControlUserPaneTrackingProc(mytrackingproc); |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 2301 | #endif |
Jack Jansen | 848250c | 1998-05-28 14:20:09 +0000 | [diff] [blame] | 2302 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 2303 | |
| 2304 | m = Py_InitModule("Ctl", Ctl_methods); |
| 2305 | d = PyModule_GetDict(m); |
| 2306 | Ctl_Error = PyMac_GetOSErrException(); |
| 2307 | if (Ctl_Error == NULL || |
| 2308 | PyDict_SetItemString(d, "Error", Ctl_Error) != 0) |
| 2309 | Py_FatalError("can't initialize Ctl.Error"); |
Jack Jansen | a755e68 | 1997-09-20 17:40:22 +0000 | [diff] [blame] | 2310 | Control_Type.ob_type = &PyType_Type; |
| 2311 | Py_INCREF(&Control_Type); |
| 2312 | if (PyDict_SetItemString(d, "ControlType", (PyObject *)&Control_Type) != 0) |
| 2313 | Py_FatalError("can't initialize ControlType"); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 2314 | } |
| 2315 | |
| 2316 | /* ========================= End module Ctl ========================= */ |
| 2317 | |