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