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