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