blob: 536da3c3408907a1243a3487208778c313e2cdee [file] [log] [blame]
Guido van Rossum17448e21995-01-30 11:53:55 +00001
2/* =========================== Module Ctl =========================== */
3
4#include "Python.h"
5
6
7
Guido van Rossum17448e21995-01-30 11:53:55 +00008#include "macglue.h"
Jack Jansen9d8b96c2000-07-14 22:16:45 +00009#include "pymactoolbox.h"
Guido van Rossum17448e21995-01-30 11:53:55 +000010
Jack Jansenfa77e1a2001-05-22 21:56:42 +000011#ifdef WITHOUT_FRAMEWORKS
Guido van Rossum17448e21995-01-30 11:53:55 +000012#include <Controls.h>
Jack Jansenf7d5aa62000-12-10 23:43:49 +000013#include <ControlDefinitions.h>
Jack Jansenfa77e1a2001-05-22 21:56:42 +000014#else
15#include <Carbon/Carbon.h>
Jack Jansenf7d5aa62000-12-10 23:43:49 +000016#endif
Guido van Rossum17448e21995-01-30 11:53:55 +000017
Jack Jansen0e04eec2001-05-17 21:58:34 +000018#ifdef USE_TOOLBOX_OBJECT_GLUE
19extern PyObject *_CtlObj_New(ControlHandle);
20extern int _CtlObj_Convert(PyObject *, ControlHandle *);
21
22#define CtlObj_New _CtlObj_New
23#define CtlObj_Convert _CtlObj_Convert
24#endif
25
Jack Jansen9d8b96c2000-07-14 22:16:45 +000026staticforward PyObject *CtlObj_WhichControl(ControlHandle);
27
Jack Jansene0581891999-02-07 14:02:03 +000028#define as_Control(h) ((ControlHandle)h)
Jack Jansena1a0fef1999-12-23 14:32:06 +000029#define as_Resource(ctl) ((Handle)ctl)
Jack Jansen74a1e632000-07-14 22:37:27 +000030#if TARGET_API_MAC_CARBON
Jack Jansene79dc762000-06-02 21:35:07 +000031#define GetControlRect(ctl, rectp) GetControlBounds(ctl, rectp)
32#else
Jack Jansen1a7d5b12000-03-21 16:25:23 +000033#define GetControlRect(ctl, rectp) (*(rectp) = ((*(ctl))->contrlRect))
Jack Jansene79dc762000-06-02 21:35:07 +000034#endif
Guido van Rossum17448e21995-01-30 11:53:55 +000035
Jack Jansen21f96871998-02-20 16:02:09 +000036/*
37** Parse/generate ControlFontStyleRec records
38*/
39#if 0 /* Not needed */
Jack Jansen9d8b96c2000-07-14 22:16:45 +000040static PyObject *
Jack Jansenfa77e1a2001-05-22 21:56:42 +000041ControlFontStyle_New(ControlFontStyleRec *itself)
Jack Jansen21f96871998-02-20 16:02:09 +000042{
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 Jansen9d8b96c2000-07-14 22:16:45 +000050static int
Jack Jansenfa77e1a2001-05-22 21:56:42 +000051ControlFontStyle_Convert(PyObject *v, ControlFontStyleRec *itself)
Jack Jansen21f96871998-02-20 16:02:09 +000052{
53 return PyArg_ParseTuple(v, "hhhhhhO&O&", &itself->flags,
Jack Jansen24c35311999-12-09 22:49:51 +000054 &itself->font, &itself->size, &itself->style, &itself->mode,
55 &itself->just, QdRGB_Convert, &itself->foreColor,
Jack Jansen21f96871998-02-20 16:02:09 +000056 QdRGB_Convert, &itself->backColor);
57}
58
Jack Jansenf7d5aa62000-12-10 23:43:49 +000059/*
60** Parse/generate ControlID records
61*/
62static PyObject *
Jack Jansenfa77e1a2001-05-22 21:56:42 +000063PyControlID_New(ControlID *itself)
Jack Jansenf7d5aa62000-12-10 23:43:49 +000064{
65
66 return Py_BuildValue("O&l", PyMac_BuildOSType, itself->signature, itself->id);
67}
68
69static int
Jack Jansenfa77e1a2001-05-22 21:56:42 +000070PyControlID_Convert(PyObject *v, ControlID *itself)
Jack Jansenf7d5aa62000-12-10 23:43:49 +000071{
72 return PyArg_ParseTuple(v, "O&l", PyMac_GetOSType, &itself->signature, &itself->id);
73}
74
75
Jack Jansen24c35311999-12-09 22:49:51 +000076/* TrackControl and HandleControlClick callback support */
Jack Jansen848250c1998-05-28 14:20:09 +000077static PyObject *tracker;
78static ControlActionUPP mytracker_upp;
Jack Jansenabc411b2000-03-20 16:09:09 +000079static ControlUserPaneDrawUPP mydrawproc_upp;
80static ControlUserPaneIdleUPP myidleproc_upp;
Jack Jansena27e9fb2000-03-21 23:03:02 +000081static ControlUserPaneHitTestUPP myhittestproc_upp;
82static ControlUserPaneTrackingUPP mytrackingproc_upp;
Jack Jansen848250c1998-05-28 14:20:09 +000083
Jack Jansenb8248d82001-06-20 21:31:28 +000084staticforward int settrackfunc(PyObject *); /* forward */
85staticforward void clrtrackfunc(void); /* forward */
Jack Jansen85152b92000-07-11 21:12:55 +000086staticforward int setcallback(PyObject *, OSType, PyObject *, UniversalProcPtr *);
Jack Jansen848250c1998-05-28 14:20:09 +000087
Guido van Rossum17448e21995-01-30 11:53:55 +000088static PyObject *Ctl_Error;
89
90/* ---------------------- Object type Control ----------------------- */
91
92PyTypeObject Control_Type;
93
94#define CtlObj_Check(x) ((x)->ob_type == &Control_Type)
95
96typedef struct ControlObject {
97 PyObject_HEAD
98 ControlHandle ob_itself;
Jack Jansenabc411b2000-03-20 16:09:09 +000099 PyObject *ob_callbackdict;
Guido van Rossum17448e21995-01-30 11:53:55 +0000100} ControlObject;
101
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000102PyObject *CtlObj_New(ControlHandle itself)
Guido van Rossum17448e21995-01-30 11:53:55 +0000103{
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 Jansen85ae4a81997-04-08 15:26:03 +0000109 SetControlReference(itself, (long)it);
Jack Jansenabc411b2000-03-20 16:09:09 +0000110 it->ob_callbackdict = NULL;
Guido van Rossum17448e21995-01-30 11:53:55 +0000111 return (PyObject *)it;
112}
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000113CtlObj_Convert(PyObject *v, ControlHandle *p_itself)
Guido van Rossum17448e21995-01-30 11:53:55 +0000114{
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 Jansenfa77e1a2001-05-22 21:56:42 +0000124static void CtlObj_dealloc(ControlObject *self)
Guido van Rossum17448e21995-01-30 11:53:55 +0000125{
Jack Jansenabc411b2000-03-20 16:09:09 +0000126 Py_XDECREF(self->ob_callbackdict);
Jack Jansen24c35311999-12-09 22:49:51 +0000127 if (self->ob_itself)SetControlReference(self->ob_itself, (long)0); /* Make it forget about us */
Guido van Rossum17448e21995-01-30 11:53:55 +0000128 PyMem_DEL(self);
129}
130
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000131static PyObject *CtlObj_HiliteControl(ControlObject *_self, PyObject *_args)
Jack Jansen21f96871998-02-20 16:02:09 +0000132{
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 Jansenfa77e1a2001-05-22 21:56:42 +0000145static PyObject *CtlObj_ShowControl(ControlObject *_self, PyObject *_args)
Jack Jansen7d0bc831995-06-09 20:56:31 +0000146{
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 Jansenfa77e1a2001-05-22 21:56:42 +0000156static PyObject *CtlObj_HideControl(ControlObject *_self, PyObject *_args)
Jack Jansen7d0bc831995-06-09 20:56:31 +0000157{
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 Jansenfa77e1a2001-05-22 21:56:42 +0000167static PyObject *CtlObj_IsControlActive(ControlObject *_self, PyObject *_args)
Jack Jansen21f96871998-02-20 16:02:09 +0000168{
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 Jansenfa77e1a2001-05-22 21:56:42 +0000179static PyObject *CtlObj_IsControlVisible(ControlObject *_self, PyObject *_args)
Jack Jansen21f96871998-02-20 16:02:09 +0000180{
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 Jansenfa77e1a2001-05-22 21:56:42 +0000191static PyObject *CtlObj_ActivateControl(ControlObject *_self, PyObject *_args)
Jack Jansen21f96871998-02-20 16:02:09 +0000192{
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 Jansenfa77e1a2001-05-22 21:56:42 +0000204static PyObject *CtlObj_DeactivateControl(ControlObject *_self, PyObject *_args)
Jack Jansen21f96871998-02-20 16:02:09 +0000205{
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 Jansenfa77e1a2001-05-22 21:56:42 +0000217static PyObject *CtlObj_SetControlVisibility(ControlObject *_self, PyObject *_args)
Jack Jansen21f96871998-02-20 16:02:09 +0000218{
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 Jansenfa77e1a2001-05-22 21:56:42 +0000236static PyObject *CtlObj_Draw1Control(ControlObject *_self, PyObject *_args)
Jack Jansen7d0bc831995-06-09 20:56:31 +0000237{
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 Jansenfa77e1a2001-05-22 21:56:42 +0000247static PyObject *CtlObj_GetBestControlRect(ControlObject *_self, PyObject *_args)
Jack Jansen7d0bc831995-06-09 20:56:31 +0000248{
249 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000250 OSErr _err;
251 Rect outRect;
252 SInt16 outBaseLineOffset;
253 if (!PyArg_ParseTuple(_args, ""))
Jack Jansen7d0bc831995-06-09 20:56:31 +0000254 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000255 _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 Jansenfa77e1a2001-05-22 21:56:42 +0000265static PyObject *CtlObj_SetControlFontStyle(ControlObject *_self, PyObject *_args)
Jack Jansen21f96871998-02-20 16:02:09 +0000266{
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 Jansenfa77e1a2001-05-22 21:56:42 +0000281static PyObject *CtlObj_DrawControlInCurrentPort(ControlObject *_self, PyObject *_args)
Jack Jansen21f96871998-02-20 16:02:09 +0000282{
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 Jansenfa77e1a2001-05-22 21:56:42 +0000292static PyObject *CtlObj_SetUpControlBackground(ControlObject *_self, PyObject *_args)
Jack Jansen21f96871998-02-20 16:02:09 +0000293{
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 Jansen7d0bc831995-06-09 20:56:31 +0000306 Py_INCREF(Py_None);
307 _res = Py_None;
308 return _res;
309}
310
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000311static PyObject *CtlObj_SetUpControlTextColor(ControlObject *_self, PyObject *_args)
Jack Jansena05ac601999-12-12 21:41:51 +0000312{
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 Jansenfa77e1a2001-05-22 21:56:42 +0000330static PyObject *CtlObj_DragControl(ControlObject *_self, PyObject *_args)
Jack Jansen7d0bc831995-06-09 20:56:31 +0000331{
332 PyObject *_res = NULL;
Jack Jansen754d4a41995-11-14 10:41:55 +0000333 Point startPoint;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000334 Rect limitRect;
335 Rect slopRect;
336 DragConstraint axis;
Jack Jansen0b13e7c2000-07-07 13:09:35 +0000337 if (!PyArg_ParseTuple(_args, "O&O&O&H",
Jack Jansen754d4a41995-11-14 10:41:55 +0000338 PyMac_GetPoint, &startPoint,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000339 PyMac_GetRect, &limitRect,
340 PyMac_GetRect, &slopRect,
341 &axis))
342 return NULL;
343 DragControl(_self->ob_itself,
Jack Jansen754d4a41995-11-14 10:41:55 +0000344 startPoint,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000345 &limitRect,
346 &slopRect,
347 axis);
348 Py_INCREF(Py_None);
349 _res = Py_None;
350 return _res;
351}
352
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000353static PyObject *CtlObj_TestControl(ControlObject *_self, PyObject *_args)
Jack Jansen7d0bc831995-06-09 20:56:31 +0000354{
355 PyObject *_res = NULL;
356 ControlPartCode _rv;
Jack Jansen21f96871998-02-20 16:02:09 +0000357 Point testPoint;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000358 if (!PyArg_ParseTuple(_args, "O&",
Jack Jansen21f96871998-02-20 16:02:09 +0000359 PyMac_GetPoint, &testPoint))
Jack Jansen7d0bc831995-06-09 20:56:31 +0000360 return NULL;
361 _rv = TestControl(_self->ob_itself,
Jack Jansen21f96871998-02-20 16:02:09 +0000362 testPoint);
363 _res = Py_BuildValue("h",
364 _rv);
365 return _res;
366}
367
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000368#if TARGET_API_MAC_CARBON
369
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000370static PyObject *CtlObj_HandleControlContextualMenuClick(ControlObject *_self, PyObject *_args)
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000371{
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 Jansenfa77e1a2001-05-22 21:56:42 +0000391static PyObject *CtlObj_GetControlClickActivation(ControlObject *_self, PyObject *_args)
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000392{
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 Jansenfa77e1a2001-05-22 21:56:42 +0000413static PyObject *CtlObj_HandleControlKey(ControlObject *_self, PyObject *_args)
Jack Jansen21f96871998-02-20 16:02:09 +0000414{
415 PyObject *_res = NULL;
416 SInt16 _rv;
417 SInt16 inKeyCode;
418 SInt16 inCharCode;
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000419 EventModifiers inModifiers;
420 if (!PyArg_ParseTuple(_args, "hhH",
Jack Jansen21f96871998-02-20 16:02:09 +0000421 &inKeyCode,
422 &inCharCode,
423 &inModifiers))
424 return NULL;
425 _rv = HandleControlKey(_self->ob_itself,
426 inKeyCode,
427 inCharCode,
428 inModifiers);
Jack Jansen7d0bc831995-06-09 20:56:31 +0000429 _res = Py_BuildValue("h",
430 _rv);
431 return _res;
432}
433
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000434#if TARGET_API_MAC_CARBON
435
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000436static PyObject *CtlObj_HandleControlSetCursor(ControlObject *_self, PyObject *_args)
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000437{
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 Jansenfa77e1a2001-05-22 21:56:42 +0000458static PyObject *CtlObj_MoveControl(ControlObject *_self, PyObject *_args)
Jack Jansen7d0bc831995-06-09 20:56:31 +0000459{
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 Jansenfa77e1a2001-05-22 21:56:42 +0000475static PyObject *CtlObj_SizeControl(ControlObject *_self, PyObject *_args)
Jack Jansen7d0bc831995-06-09 20:56:31 +0000476{
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 Jansenfa77e1a2001-05-22 21:56:42 +0000492static PyObject *CtlObj_SetControlTitle(ControlObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000493{
494 PyObject *_res = NULL;
495 Str255 title;
496 if (!PyArg_ParseTuple(_args, "O&",
497 PyMac_GetStr255, title))
498 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000499 SetControlTitle(_self->ob_itself,
500 title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000501 Py_INCREF(Py_None);
502 _res = Py_None;
503 return _res;
504}
505
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000506static PyObject *CtlObj_GetControlTitle(ControlObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000507{
508 PyObject *_res = NULL;
509 Str255 title;
Jack Jansen41009001999-03-07 20:05:20 +0000510 if (!PyArg_ParseTuple(_args, ""))
Guido van Rossum17448e21995-01-30 11:53:55 +0000511 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000512 GetControlTitle(_self->ob_itself,
513 title);
Jack Jansen41009001999-03-07 20:05:20 +0000514 _res = Py_BuildValue("O&",
515 PyMac_BuildStr255, title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000516 return _res;
517}
518
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000519static PyObject *CtlObj_GetControlValue(ControlObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000520{
521 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000522 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000523 if (!PyArg_ParseTuple(_args, ""))
524 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000525 _rv = GetControlValue(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000526 _res = Py_BuildValue("h",
527 _rv);
528 return _res;
529}
530
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000531static PyObject *CtlObj_SetControlValue(ControlObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000532{
533 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000534 SInt16 newValue;
Guido van Rossum17448e21995-01-30 11:53:55 +0000535 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000536 &newValue))
Guido van Rossum17448e21995-01-30 11:53:55 +0000537 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000538 SetControlValue(_self->ob_itself,
539 newValue);
Guido van Rossum17448e21995-01-30 11:53:55 +0000540 Py_INCREF(Py_None);
541 _res = Py_None;
542 return _res;
543}
544
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000545static PyObject *CtlObj_GetControlMinimum(ControlObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000546{
547 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000548 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000549 if (!PyArg_ParseTuple(_args, ""))
550 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000551 _rv = GetControlMinimum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000552 _res = Py_BuildValue("h",
553 _rv);
554 return _res;
555}
556
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000557static PyObject *CtlObj_SetControlMinimum(ControlObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000558{
559 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000560 SInt16 newMinimum;
Guido van Rossum17448e21995-01-30 11:53:55 +0000561 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000562 &newMinimum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000563 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000564 SetControlMinimum(_self->ob_itself,
565 newMinimum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000566 Py_INCREF(Py_None);
567 _res = Py_None;
568 return _res;
569}
570
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000571static PyObject *CtlObj_GetControlMaximum(ControlObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000572{
573 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000574 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000575 if (!PyArg_ParseTuple(_args, ""))
576 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000577 _rv = GetControlMaximum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000578 _res = Py_BuildValue("h",
579 _rv);
580 return _res;
581}
582
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000583static PyObject *CtlObj_SetControlMaximum(ControlObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000584{
585 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000586 SInt16 newMaximum;
587 if (!PyArg_ParseTuple(_args, "h",
588 &newMaximum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000589 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000590 SetControlMaximum(_self->ob_itself,
591 newMaximum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000592 Py_INCREF(Py_None);
593 _res = Py_None;
594 return _res;
595}
596
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000597static PyObject *CtlObj_GetControlViewSize(ControlObject *_self, PyObject *_args)
Jack Jansena05ac601999-12-12 21:41:51 +0000598{
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 Jansenfa77e1a2001-05-22 21:56:42 +0000609static PyObject *CtlObj_SetControlViewSize(ControlObject *_self, PyObject *_args)
Jack Jansena05ac601999-12-12 21:41:51 +0000610{
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 Jansenfa77e1a2001-05-22 21:56:42 +0000623static PyObject *CtlObj_GetControl32BitValue(ControlObject *_self, PyObject *_args)
Jack Jansena05ac601999-12-12 21:41:51 +0000624{
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 Jansenfa77e1a2001-05-22 21:56:42 +0000635static PyObject *CtlObj_SetControl32BitValue(ControlObject *_self, PyObject *_args)
Jack Jansena05ac601999-12-12 21:41:51 +0000636{
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 Jansenfa77e1a2001-05-22 21:56:42 +0000649static PyObject *CtlObj_GetControl32BitMaximum(ControlObject *_self, PyObject *_args)
Jack Jansena05ac601999-12-12 21:41:51 +0000650{
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 Jansenfa77e1a2001-05-22 21:56:42 +0000661static PyObject *CtlObj_SetControl32BitMaximum(ControlObject *_self, PyObject *_args)
Jack Jansena05ac601999-12-12 21:41:51 +0000662{
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 Jansenfa77e1a2001-05-22 21:56:42 +0000675static PyObject *CtlObj_GetControl32BitMinimum(ControlObject *_self, PyObject *_args)
Jack Jansena05ac601999-12-12 21:41:51 +0000676{
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 Jansenfa77e1a2001-05-22 21:56:42 +0000687static PyObject *CtlObj_SetControl32BitMinimum(ControlObject *_self, PyObject *_args)
Jack Jansena05ac601999-12-12 21:41:51 +0000688{
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 Jansenfa77e1a2001-05-22 21:56:42 +0000701static PyObject *CtlObj_IsValidControlHandle(ControlObject *_self, PyObject *_args)
Jack Jansena05ac601999-12-12 21:41:51 +0000702{
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 Jansenf7d5aa62000-12-10 23:43:49 +0000713#if TARGET_API_MAC_CARBON
714
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000715static PyObject *CtlObj_SetControlID(ControlObject *_self, PyObject *_args)
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000716{
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 Jansenfa77e1a2001-05-22 21:56:42 +0000734static PyObject *CtlObj_GetControlID(ControlObject *_self, PyObject *_args)
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000735{
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 Jansenfa77e1a2001-05-22 21:56:42 +0000750static PyObject *CtlObj_RemoveControlProperty(ControlObject *_self, PyObject *_args)
Jack Jansena05ac601999-12-12 21:41:51 +0000751{
752 PyObject *_res = NULL;
Jack Jansene79dc762000-06-02 21:35:07 +0000753 OSStatus _err;
Jack Jansena05ac601999-12-12 21:41:51 +0000754 OSType propertyCreator;
755 OSType propertyTag;
756 if (!PyArg_ParseTuple(_args, "O&O&",
757 PyMac_GetOSType, &propertyCreator,
758 PyMac_GetOSType, &propertyTag))
759 return NULL;
Jack Jansene79dc762000-06-02 21:35:07 +0000760 _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 Jansena05ac601999-12-12 21:41:51 +0000766 return _res;
767}
768
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000769#if TARGET_API_MAC_CARBON
770
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000771static PyObject *CtlObj_GetControlPropertyAttributes(ControlObject *_self, PyObject *_args)
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000772{
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 Jansenfa77e1a2001-05-22 21:56:42 +0000795static PyObject *CtlObj_ChangeControlPropertyAttributes(ControlObject *_self, PyObject *_args)
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000796{
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 Jansenfa77e1a2001-05-22 21:56:42 +0000821static PyObject *CtlObj_GetControlRegion(ControlObject *_self, PyObject *_args)
Jack Jansena05ac601999-12-12 21:41:51 +0000822{
823 PyObject *_res = NULL;
Jack Jansene79dc762000-06-02 21:35:07 +0000824 OSStatus _err;
Jack Jansena05ac601999-12-12 21:41:51 +0000825 ControlPartCode inPart;
826 RgnHandle outRegion;
827 if (!PyArg_ParseTuple(_args, "hO&",
828 &inPart,
829 ResObj_Convert, &outRegion))
830 return NULL;
Jack Jansene79dc762000-06-02 21:35:07 +0000831 _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 Jansena05ac601999-12-12 21:41:51 +0000837 return _res;
838}
839
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000840static PyObject *CtlObj_GetControlVariant(ControlObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000841{
842 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000843 ControlVariant _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000844 if (!PyArg_ParseTuple(_args, ""))
845 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000846 _rv = GetControlVariant(_self->ob_itself);
847 _res = Py_BuildValue("h",
Guido van Rossum17448e21995-01-30 11:53:55 +0000848 _rv);
849 return _res;
850}
851
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000852static PyObject *CtlObj_SetControlReference(ControlObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000853{
854 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000855 SInt32 data;
856 if (!PyArg_ParseTuple(_args, "l",
857 &data))
Guido van Rossum17448e21995-01-30 11:53:55 +0000858 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000859 SetControlReference(_self->ob_itself,
860 data);
Guido van Rossum17448e21995-01-30 11:53:55 +0000861 Py_INCREF(Py_None);
862 _res = Py_None;
863 return _res;
864}
865
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000866static PyObject *CtlObj_GetControlReference(ControlObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000867{
868 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000869 SInt32 _rv;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000870 if (!PyArg_ParseTuple(_args, ""))
871 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000872 _rv = GetControlReference(_self->ob_itself);
873 _res = Py_BuildValue("l",
Guido van Rossum17448e21995-01-30 11:53:55 +0000874 _rv);
875 return _res;
876}
877
Jack Jansen74a1e632000-07-14 22:37:27 +0000878#if !TARGET_API_MAC_CARBON
Jack Jansene79dc762000-06-02 21:35:07 +0000879
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000880static PyObject *CtlObj_GetAuxiliaryControlRecord(ControlObject *_self, PyObject *_args)
Jack Jansenc7fefed1997-08-15 14:32:18 +0000881{
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 Jansene79dc762000-06-02 21:35:07 +0000894#endif
895
Jack Jansen74a1e632000-07-14 22:37:27 +0000896#if !TARGET_API_MAC_CARBON
Jack Jansenc7fefed1997-08-15 14:32:18 +0000897
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000898static PyObject *CtlObj_SetControlColor(ControlObject *_self, PyObject *_args)
Jack Jansenc7fefed1997-08-15 14:32:18 +0000899{
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 Jansene79dc762000-06-02 21:35:07 +0000911#endif
912
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000913static PyObject *CtlObj_EmbedControl(ControlObject *_self, PyObject *_args)
Jack Jansen21f96871998-02-20 16:02:09 +0000914{
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 Jansenfa77e1a2001-05-22 21:56:42 +0000929static PyObject *CtlObj_AutoEmbedControl(ControlObject *_self, PyObject *_args)
Jack Jansen21f96871998-02-20 16:02:09 +0000930{
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 Jansenfa77e1a2001-05-22 21:56:42 +0000945static PyObject *CtlObj_GetSuperControl(ControlObject *_self, PyObject *_args)
Jack Jansen21f96871998-02-20 16:02:09 +0000946{
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 Jansenfa77e1a2001-05-22 21:56:42 +0000960static PyObject *CtlObj_CountSubControls(ControlObject *_self, PyObject *_args)
Jack Jansen21f96871998-02-20 16:02:09 +0000961{
962 PyObject *_res = NULL;
963 OSErr _err;
Jack Jansen24c35311999-12-09 22:49:51 +0000964 UInt16 outNumChildren;
Jack Jansen21f96871998-02-20 16:02:09 +0000965 if (!PyArg_ParseTuple(_args, ""))
966 return NULL;
967 _err = CountSubControls(_self->ob_itself,
968 &outNumChildren);
969 if (_err != noErr) return PyMac_Error(_err);
Jack Jansen0b13e7c2000-07-07 13:09:35 +0000970 _res = Py_BuildValue("H",
Jack Jansen21f96871998-02-20 16:02:09 +0000971 outNumChildren);
972 return _res;
973}
974
Jack Jansenfa77e1a2001-05-22 21:56:42 +0000975static PyObject *CtlObj_GetIndexedSubControl(ControlObject *_self, PyObject *_args)
Jack Jansen21f96871998-02-20 16:02:09 +0000976{
977 PyObject *_res = NULL;
978 OSErr _err;
Jack Jansen24c35311999-12-09 22:49:51 +0000979 UInt16 inIndex;
Jack Jansen21f96871998-02-20 16:02:09 +0000980 ControlHandle outSubControl;
Jack Jansen0b13e7c2000-07-07 13:09:35 +0000981 if (!PyArg_ParseTuple(_args, "H",
Jack Jansen21f96871998-02-20 16:02:09 +0000982 &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 Jansenfa77e1a2001-05-22 21:56:42 +0000993static PyObject *CtlObj_SetControlSupervisor(ControlObject *_self, PyObject *_args)
Jack Jansen21f96871998-02-20 16:02:09 +0000994{
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 Jansenfa77e1a2001-05-22 21:56:42 +00001009static PyObject *CtlObj_GetControlFeatures(ControlObject *_self, PyObject *_args)
Jack Jansen21f96871998-02-20 16:02:09 +00001010{
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 Jansenfa77e1a2001-05-22 21:56:42 +00001024static PyObject *CtlObj_GetControlDataSize(ControlObject *_self, PyObject *_args)
Jack Jansen21f96871998-02-20 16:02:09 +00001025{
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 Jansenf7d5aa62000-12-10 23:43:49 +00001045#if TARGET_API_MAC_CARBON
1046
Jack Jansenfa77e1a2001-05-22 21:56:42 +00001047static PyObject *CtlObj_HandleControlDragTracking(ControlObject *_self, PyObject *_args)
Jack Jansen723ad8a2000-12-12 22:10:21 +00001048{
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 Jansenfa77e1a2001-05-22 21:56:42 +00001071static PyObject *CtlObj_HandleControlDragReceive(ControlObject *_self, PyObject *_args)
Jack Jansen723ad8a2000-12-12 22:10:21 +00001072{
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 Jansenfa77e1a2001-05-22 21:56:42 +00001090static PyObject *CtlObj_SetControlDragTrackingEnabled(ControlObject *_self, PyObject *_args)
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001091{
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 Jansenfa77e1a2001-05-22 21:56:42 +00001109static PyObject *CtlObj_IsControlDragTrackingEnabled(ControlObject *_self, PyObject *_args)
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001110{
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 Jansenfa77e1a2001-05-22 21:56:42 +00001127static PyObject *CtlObj_GetControlBounds(ControlObject *_self, PyObject *_args)
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001128{
1129 PyObject *_res = NULL;
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001130 Rect bounds;
1131 if (!PyArg_ParseTuple(_args, ""))
1132 return NULL;
Jack Jansena9e3db32001-01-09 22:10:16 +00001133 GetControlBounds(_self->ob_itself,
1134 &bounds);
1135 _res = Py_BuildValue("O&",
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001136 PyMac_BuildRect, &bounds);
1137 return _res;
1138}
1139#endif
1140
1141#if ACCESSOR_CALLS_ARE_FUNCTIONS
1142
Jack Jansenfa77e1a2001-05-22 21:56:42 +00001143static PyObject *CtlObj_IsControlHilited(ControlObject *_self, PyObject *_args)
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001144{
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 Jansenfa77e1a2001-05-22 21:56:42 +00001158static PyObject *CtlObj_GetControlHilite(ControlObject *_self, PyObject *_args)
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001159{
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 Jansenfa77e1a2001-05-22 21:56:42 +00001173static PyObject *CtlObj_GetControlOwner(ControlObject *_self, PyObject *_args)
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001174{
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 Jansenfa77e1a2001-05-22 21:56:42 +00001188static PyObject *CtlObj_GetControlDataHandle(ControlObject *_self, PyObject *_args)
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001189{
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 Jansenfa77e1a2001-05-22 21:56:42 +00001203static PyObject *CtlObj_GetControlPopupMenuHandle(ControlObject *_self, PyObject *_args)
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001204{
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 Jansenfa77e1a2001-05-22 21:56:42 +00001218static PyObject *CtlObj_GetControlPopupMenuID(ControlObject *_self, PyObject *_args)
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001219{
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 Jansenfa77e1a2001-05-22 21:56:42 +00001233static PyObject *CtlObj_SetControlDataHandle(ControlObject *_self, PyObject *_args)
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001234{
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 Jansenfa77e1a2001-05-22 21:56:42 +00001250static PyObject *CtlObj_SetControlBounds(ControlObject *_self, PyObject *_args)
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001251{
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 Jansenfa77e1a2001-05-22 21:56:42 +00001267static PyObject *CtlObj_SetControlPopupMenuHandle(ControlObject *_self, PyObject *_args)
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001268{
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 Jansenfa77e1a2001-05-22 21:56:42 +00001284static PyObject *CtlObj_SetControlPopupMenuID(ControlObject *_self, PyObject *_args)
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001285{
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 Jansenfa77e1a2001-05-22 21:56:42 +00001299static PyObject *CtlObj_GetBevelButtonMenuValue(ControlObject *_self, PyObject *_args)
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001300{
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 Jansenfa77e1a2001-05-22 21:56:42 +00001314static PyObject *CtlObj_SetBevelButtonMenuValue(ControlObject *_self, PyObject *_args)
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001315{
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 Jansenfa77e1a2001-05-22 21:56:42 +00001330static PyObject *CtlObj_GetBevelButtonMenuHandle(ControlObject *_self, PyObject *_args)
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001331{
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 Jansenfa77e1a2001-05-22 21:56:42 +00001345static PyObject *CtlObj_SetBevelButtonTransform(ControlObject *_self, PyObject *_args)
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001346{
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 Jansenfa77e1a2001-05-22 21:56:42 +00001361static PyObject *CtlObj_SetDisclosureTriangleLastValue(ControlObject *_self, PyObject *_args)
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001362{
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 Jansenfa77e1a2001-05-22 21:56:42 +00001377static PyObject *CtlObj_GetTabContentRect(ControlObject *_self, PyObject *_args)
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001378{
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 Jansenfa77e1a2001-05-22 21:56:42 +00001392static PyObject *CtlObj_SetTabEnabled(ControlObject *_self, PyObject *_args)
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001393{
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 Jansenfa77e1a2001-05-22 21:56:42 +00001411static PyObject *CtlObj_SetImageWellTransform(ControlObject *_self, PyObject *_args)
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001412{
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 Jansenfa77e1a2001-05-22 21:56:42 +00001427static PyObject *CtlObj_as_Resource(ControlObject *_self, PyObject *_args)
Jack Jansen5d56f4b1995-06-18 20:16:33 +00001428{
1429 PyObject *_res = NULL;
Jack Jansena1a0fef1999-12-23 14:32:06 +00001430 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 Jansen5d56f4b1995-06-18 20:16:33 +00001437}
1438
Jack Jansenfa77e1a2001-05-22 21:56:42 +00001439static PyObject *CtlObj_GetControlRect(ControlObject *_self, PyObject *_args)
Jack Jansen1a7d5b12000-03-21 16:25:23 +00001440{
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 Jansenfa77e1a2001-05-22 21:56:42 +00001452static PyObject *CtlObj_DisposeControl(ControlObject *_self, PyObject *_args)
Jack Jansencfb60ee1996-10-01 10:46:46 +00001453{
1454 PyObject *_res = NULL;
1455
1456 if (!PyArg_ParseTuple(_args, ""))
1457 return NULL;
1458 if ( _self->ob_itself ) {
Jack Jansen85ae4a81997-04-08 15:26:03 +00001459 SetControlReference(_self->ob_itself, (long)0); /* Make it forget about us */
Jack Jansencfb60ee1996-10-01 10:46:46 +00001460 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 Jansenfa77e1a2001-05-22 21:56:42 +00001469static PyObject *CtlObj_TrackControl(ControlObject *_self, PyObject *_args)
Jack Jansen848250c1998-05-28 14:20:09 +00001470{
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 Jansenfa77e1a2001-05-22 21:56:42 +00001499static PyObject *CtlObj_HandleControlClick(ControlObject *_self, PyObject *_args)
Jack Jansen24c35311999-12-09 22:49:51 +00001500{
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 Jansenfa77e1a2001-05-22 21:56:42 +00001533static PyObject *CtlObj_SetControlData(ControlObject *_self, PyObject *_args)
Jack Jansen24c35311999-12-09 22:49:51 +00001534{
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 Jansenfa77e1a2001-05-22 21:56:42 +00001562static PyObject *CtlObj_GetControlData(ControlObject *_self, PyObject *_args)
Jack Jansen24c35311999-12-09 22:49:51 +00001563{
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 Jansenfa77e1a2001-05-22 21:56:42 +00001606static PyObject *CtlObj_SetControlData_Handle(ControlObject *_self, PyObject *_args)
Jack Jansen1f9249c1999-12-19 00:05:50 +00001607{
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 Jansenb9247d31999-12-23 23:06:07 +00001618 OptResObj_Convert, &buffer))
Jack Jansen1f9249c1999-12-19 00:05:50 +00001619 return NULL;
1620
1621 _err = SetControlData(_self->ob_itself,
1622 inPart,
1623 inTagName,
1624 sizeof(buffer),
Jack Jansenf7ac1d31999-12-29 12:37:22 +00001625 (Ptr)&buffer);
Jack Jansen1f9249c1999-12-19 00:05:50 +00001626
1627 if (_err != noErr)
1628 return PyMac_Error(_err);
1629 _res = Py_None;
1630 return _res;
1631
1632}
1633
Jack Jansenfa77e1a2001-05-22 21:56:42 +00001634static PyObject *CtlObj_GetControlData_Handle(ControlObject *_self, PyObject *_args)
Jack Jansen1f9249c1999-12-19 00:05:50 +00001635{
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 Jansenfa77e1a2001-05-22 21:56:42 +00001675static PyObject *CtlObj_SetControlData_Callback(ControlObject *_self, PyObject *_args)
Jack Jansenabc411b2000-03-20 16:09:09 +00001676{
1677 PyObject *_res = NULL;
1678
1679 OSErr _err;
1680 ControlPartCode inPart;
1681 ResType inTagName;
1682 PyObject *callback;
Jack Jansen85152b92000-07-11 21:12:55 +00001683 UniversalProcPtr c_callback;
Jack Jansenabc411b2000-03-20 16:09:09 +00001684
1685 if (!PyArg_ParseTuple(_args, "hO&O",
1686 &inPart,
1687 PyMac_GetOSType, &inTagName,
1688 &callback))
1689 return NULL;
1690
Jack Jansen85152b92000-07-11 21:12:55 +00001691 if ( setcallback((PyObject *)_self, inTagName, callback, &c_callback) < 0 )
Jack Jansenabc411b2000-03-20 16:09:09 +00001692 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 Jansene79dc762000-06-02 21:35:07 +00001705
Jack Jansen736b51d2001-01-12 23:39:00 +00001706#if !TARGET_API_MAC_CARBON
Jack Jansenabc411b2000-03-20 16:09:09 +00001707
Jack Jansenfa77e1a2001-05-22 21:56:42 +00001708static PyObject *CtlObj_GetPopupData(ControlObject *_self, PyObject *_args)
Jack Jansen4c704131998-06-19 13:35:14 +00001709{
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 Jansene79dc762000-06-02 21:35:07 +00001725#endif
1726
Jack Jansen736b51d2001-01-12 23:39:00 +00001727#if !TARGET_API_MAC_CARBON
Jack Jansen4c704131998-06-19 13:35:14 +00001728
Jack Jansenfa77e1a2001-05-22 21:56:42 +00001729static PyObject *CtlObj_SetPopupData(ControlObject *_self, PyObject *_args)
Jack Jansen4c704131998-06-19 13:35:14 +00001730{
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 Jansene79dc762000-06-02 21:35:07 +00001750#endif
Jack Jansen4c704131998-06-19 13:35:14 +00001751
Guido van Rossum17448e21995-01-30 11:53:55 +00001752static PyMethodDef CtlObj_methods[] = {
Jack Jansen21f96871998-02-20 16:02:09 +00001753 {"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1,
1754 "(ControlPartCode hiliteState) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001755 {"ShowControl", (PyCFunction)CtlObj_ShowControl, 1,
1756 "() -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001757 {"HideControl", (PyCFunction)CtlObj_HideControl, 1,
1758 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001759 {"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 Rossum17448e21995-01-30 11:53:55 +00001769 {"Draw1Control", (PyCFunction)CtlObj_Draw1Control, 1,
1770 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001771 {"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 Jansena05ac601999-12-12 21:41:51 +00001779 {"SetUpControlTextColor", (PyCFunction)CtlObj_SetUpControlTextColor, 1,
1780 "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001781 {"DragControl", (PyCFunction)CtlObj_DragControl, 1,
Jack Jansen754d4a41995-11-14 10:41:55 +00001782 "(Point startPoint, Rect limitRect, Rect slopRect, DragConstraint axis) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001783 {"TestControl", (PyCFunction)CtlObj_TestControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001784 "(Point testPoint) -> (ControlPartCode _rv)"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001785
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 Jansen21f96871998-02-20 16:02:09 +00001795 {"HandleControlKey", (PyCFunction)CtlObj_HandleControlKey, 1,
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001796 "(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 Rossum17448e21995-01-30 11:53:55 +00001802 {"MoveControl", (PyCFunction)CtlObj_MoveControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001803 "(SInt16 h, SInt16 v) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001804 {"SizeControl", (PyCFunction)CtlObj_SizeControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001805 "(SInt16 w, SInt16 h) -> None"},
1806 {"SetControlTitle", (PyCFunction)CtlObj_SetControlTitle, 1,
1807 "(Str255 title) -> None"},
1808 {"GetControlTitle", (PyCFunction)CtlObj_GetControlTitle, 1,
Jack Jansen41009001999-03-07 20:05:20 +00001809 "() -> (Str255 title)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001810 {"GetControlValue", (PyCFunction)CtlObj_GetControlValue, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001811 "() -> (SInt16 _rv)"},
1812 {"SetControlValue", (PyCFunction)CtlObj_SetControlValue, 1,
1813 "(SInt16 newValue) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001814 {"GetControlMinimum", (PyCFunction)CtlObj_GetControlMinimum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001815 "() -> (SInt16 _rv)"},
1816 {"SetControlMinimum", (PyCFunction)CtlObj_SetControlMinimum, 1,
1817 "(SInt16 newMinimum) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001818 {"GetControlMaximum", (PyCFunction)CtlObj_GetControlMaximum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001819 "() -> (SInt16 _rv)"},
1820 {"SetControlMaximum", (PyCFunction)CtlObj_SetControlMaximum, 1,
1821 "(SInt16 newMaximum) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +00001822 {"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 Jansenf7d5aa62000-12-10 23:43:49 +00001840
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 Jansena05ac601999-12-12 21:41:51 +00001850 {"RemoveControlProperty", (PyCFunction)CtlObj_RemoveControlProperty, 1,
Jack Jansene79dc762000-06-02 21:35:07 +00001851 "(OSType propertyCreator, OSType propertyTag) -> None"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001852
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 Jansena05ac601999-12-12 21:41:51 +00001862 {"GetControlRegion", (PyCFunction)CtlObj_GetControlRegion, 1,
Jack Jansene79dc762000-06-02 21:35:07 +00001863 "(ControlPartCode inPart, RgnHandle outRegion) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001864 {"GetControlVariant", (PyCFunction)CtlObj_GetControlVariant, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001865 "() -> (ControlVariant _rv)"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001866 {"SetControlReference", (PyCFunction)CtlObj_SetControlReference, 1,
1867 "(SInt32 data) -> None"},
1868 {"GetControlReference", (PyCFunction)CtlObj_GetControlReference, 1,
1869 "() -> (SInt32 _rv)"},
Jack Jansene79dc762000-06-02 21:35:07 +00001870
Jack Jansen74a1e632000-07-14 22:37:27 +00001871#if !TARGET_API_MAC_CARBON
Jack Jansenc7fefed1997-08-15 14:32:18 +00001872 {"GetAuxiliaryControlRecord", (PyCFunction)CtlObj_GetAuxiliaryControlRecord, 1,
1873 "() -> (Boolean _rv, AuxCtlHandle acHndl)"},
Jack Jansene79dc762000-06-02 21:35:07 +00001874#endif
1875
Jack Jansen74a1e632000-07-14 22:37:27 +00001876#if !TARGET_API_MAC_CARBON
Jack Jansenc7fefed1997-08-15 14:32:18 +00001877 {"SetControlColor", (PyCFunction)CtlObj_SetControlColor, 1,
1878 "(CCTabHandle newColorTable) -> None"},
Jack Jansene79dc762000-06-02 21:35:07 +00001879#endif
Jack Jansen21f96871998-02-20 16:02:09 +00001880 {"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 Jansen24c35311999-12-09 22:49:51 +00001887 "() -> (UInt16 outNumChildren)"},
Jack Jansen21f96871998-02-20 16:02:09 +00001888 {"GetIndexedSubControl", (PyCFunction)CtlObj_GetIndexedSubControl, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00001889 "(UInt16 inIndex) -> (ControlHandle outSubControl)"},
Jack Jansen21f96871998-02-20 16:02:09 +00001890 {"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 Jansenf7d5aa62000-12-10 23:43:49 +00001896
1897#if TARGET_API_MAC_CARBON
Jack Jansen723ad8a2000-12-12 22:10:21 +00001898 {"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 Jansenf7d5aa62000-12-10 23:43:49 +00001908 {"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 Jansena9e3db32001-01-09 22:10:16 +00001919 "() -> (Rect bounds)"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001920#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 Jansen5d56f4b1995-06-18 20:16:33 +00001987 {"as_Resource", (PyCFunction)CtlObj_as_Resource, 1,
Jack Jansena1a0fef1999-12-23 14:32:06 +00001988 "() -> (Handle _rv)"},
Jack Jansen1a7d5b12000-03-21 16:25:23 +00001989 {"GetControlRect", (PyCFunction)CtlObj_GetControlRect, 1,
1990 "() -> (Rect rect)"},
Jack Jansencfb60ee1996-10-01 10:46:46 +00001991 {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1,
1992 "() -> None"},
Jack Jansen848250c1998-05-28 14:20:09 +00001993 {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00001994 "(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 Jansena9e3db32001-01-09 22:10:16 +00002001 {"SetControlData_Handle", (PyCFunction)CtlObj_SetControlData_Handle, 1,
Jack Jansen1f9249c1999-12-19 00:05:50 +00002002 "(ResObj) -> None"},
Jack Jansena9e3db32001-01-09 22:10:16 +00002003 {"GetControlData_Handle", (PyCFunction)CtlObj_GetControlData_Handle, 1,
Jack Jansen1f9249c1999-12-19 00:05:50 +00002004 "(part, type) -> ResObj"},
Jack Jansena9e3db32001-01-09 22:10:16 +00002005 {"SetControlData_Callback", (PyCFunction)CtlObj_SetControlData_Callback, 1,
Jack Jansenabc411b2000-03-20 16:09:09 +00002006 "(callbackfunc) -> None"},
Jack Jansene79dc762000-06-02 21:35:07 +00002007
Jack Jansen736b51d2001-01-12 23:39:00 +00002008#if !TARGET_API_MAC_CARBON
Jack Jansen4c704131998-06-19 13:35:14 +00002009 {"GetPopupData", (PyCFunction)CtlObj_GetPopupData, 1,
2010 NULL},
Jack Jansene79dc762000-06-02 21:35:07 +00002011#endif
2012
Jack Jansen736b51d2001-01-12 23:39:00 +00002013#if !TARGET_API_MAC_CARBON
Jack Jansen4c704131998-06-19 13:35:14 +00002014 {"SetPopupData", (PyCFunction)CtlObj_SetPopupData, 1,
2015 NULL},
Jack Jansene79dc762000-06-02 21:35:07 +00002016#endif
Guido van Rossum17448e21995-01-30 11:53:55 +00002017 {NULL, NULL, 0}
2018};
2019
2020PyMethodChain CtlObj_chain = { CtlObj_methods, NULL };
2021
Jack Jansenfa77e1a2001-05-22 21:56:42 +00002022static PyObject *CtlObj_getattr(ControlObject *self, char *name)
Guido van Rossum17448e21995-01-30 11:53:55 +00002023{
2024 return Py_FindMethodInChain(&CtlObj_chain, (PyObject *)self, name);
2025}
2026
2027#define CtlObj_setattr NULL
2028
Jack Jansenfa77e1a2001-05-22 21:56:42 +00002029static int CtlObj_compare(ControlObject *self, ControlObject *other)
Jack Jansen8387af61999-03-13 23:07:32 +00002030{
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 Jansenfa77e1a2001-05-22 21:56:42 +00002050static long CtlObj_hash(ControlObject *self)
Jack Jansen8387af61999-03-13 23:07:32 +00002051{
2052 return (long)self->ob_itself;
2053}
2054
Guido van Rossum17448e21995-01-30 11:53:55 +00002055PyTypeObject 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 Jansen8387af61999-03-13 23:07:32 +00002066 (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 Rossum17448e21995-01-30 11:53:55 +00002072};
2073
2074/* -------------------- End object type Control --------------------- */
2075
2076
Jack Jansenfa77e1a2001-05-22 21:56:42 +00002077static PyObject *Ctl_NewControl(PyObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +00002078{
2079 PyObject *_res = NULL;
2080 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00002081 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00002082 Rect boundsRect;
Jack Jansen21f96871998-02-20 16:02:09 +00002083 Str255 controlTitle;
2084 Boolean initiallyVisible;
2085 SInt16 initialValue;
2086 SInt16 minimumValue;
2087 SInt16 maximumValue;
Jack Jansen7d0bc831995-06-09 20:56:31 +00002088 SInt16 procID;
Jack Jansen21f96871998-02-20 16:02:09 +00002089 SInt32 controlReference;
Guido van Rossum17448e21995-01-30 11:53:55 +00002090 if (!PyArg_ParseTuple(_args, "O&O&O&bhhhhl",
Jack Jansen21f96871998-02-20 16:02:09 +00002091 WinObj_Convert, &owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00002092 PyMac_GetRect, &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00002093 PyMac_GetStr255, controlTitle,
2094 &initiallyVisible,
2095 &initialValue,
2096 &minimumValue,
2097 &maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00002098 &procID,
Jack Jansen21f96871998-02-20 16:02:09 +00002099 &controlReference))
Guido van Rossum17448e21995-01-30 11:53:55 +00002100 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00002101 _rv = NewControl(owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00002102 &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00002103 controlTitle,
2104 initiallyVisible,
2105 initialValue,
2106 minimumValue,
2107 maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00002108 procID,
Jack Jansen21f96871998-02-20 16:02:09 +00002109 controlReference);
Guido van Rossum17448e21995-01-30 11:53:55 +00002110 _res = Py_BuildValue("O&",
2111 CtlObj_New, _rv);
2112 return _res;
2113}
2114
Jack Jansenfa77e1a2001-05-22 21:56:42 +00002115static PyObject *Ctl_GetNewControl(PyObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +00002116{
2117 PyObject *_res = NULL;
2118 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00002119 SInt16 resourceID;
2120 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00002121 if (!PyArg_ParseTuple(_args, "hO&",
Jack Jansen21f96871998-02-20 16:02:09 +00002122 &resourceID,
2123 WinObj_Convert, &owningWindow))
Guido van Rossum17448e21995-01-30 11:53:55 +00002124 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00002125 _rv = GetNewControl(resourceID,
2126 owningWindow);
Guido van Rossum17448e21995-01-30 11:53:55 +00002127 _res = Py_BuildValue("O&",
2128 CtlObj_New, _rv);
2129 return _res;
2130}
2131
Jack Jansenfa77e1a2001-05-22 21:56:42 +00002132static PyObject *Ctl_DrawControls(PyObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +00002133{
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 Jansenfa77e1a2001-05-22 21:56:42 +00002145static PyObject *Ctl_UpdateControls(PyObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +00002146{
2147 PyObject *_res = NULL;
2148 WindowPtr theWindow;
Jack Jansen2b724171996-04-10 14:48:19 +00002149 RgnHandle updateRegion;
2150 if (!PyArg_ParseTuple(_args, "O&O&",
2151 WinObj_Convert, &theWindow,
2152 ResObj_Convert, &updateRegion))
Guido van Rossum17448e21995-01-30 11:53:55 +00002153 return NULL;
2154 UpdateControls(theWindow,
Jack Jansen2b724171996-04-10 14:48:19 +00002155 updateRegion);
Guido van Rossum17448e21995-01-30 11:53:55 +00002156 Py_INCREF(Py_None);
2157 _res = Py_None;
2158 return _res;
2159}
2160
Jack Jansenfa77e1a2001-05-22 21:56:42 +00002161static PyObject *Ctl_FindControl(PyObject *_self, PyObject *_args)
Guido van Rossum17448e21995-01-30 11:53:55 +00002162{
2163 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +00002164 ControlPartCode _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00002165 Point testPoint;
Guido van Rossum17448e21995-01-30 11:53:55 +00002166 WindowPtr theWindow;
2167 ControlHandle theControl;
2168 if (!PyArg_ParseTuple(_args, "O&O&",
Jack Jansen21f96871998-02-20 16:02:09 +00002169 PyMac_GetPoint, &testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00002170 WinObj_Convert, &theWindow))
2171 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00002172 _rv = FindControl(testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00002173 theWindow,
2174 &theControl);
2175 _res = Py_BuildValue("hO&",
2176 _rv,
2177 CtlObj_WhichControl, theControl);
2178 return _res;
2179}
2180
Jack Jansenfa77e1a2001-05-22 21:56:42 +00002181static PyObject *Ctl_FindControlUnderMouse(PyObject *_self, PyObject *_args)
Jack Jansen21f96871998-02-20 16:02:09 +00002182{
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 Jansenfa77e1a2001-05-22 21:56:42 +00002201static PyObject *Ctl_IdleControls(PyObject *_self, PyObject *_args)
Jack Jansen21f96871998-02-20 16:02:09 +00002202{
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 Jansenf7d5aa62000-12-10 23:43:49 +00002214#if TARGET_API_MAC_CARBON
2215
Jack Jansenfa77e1a2001-05-22 21:56:42 +00002216static PyObject *Ctl_GetControlByID(PyObject *_self, PyObject *_args)
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002217{
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 Jansenfa77e1a2001-05-22 21:56:42 +00002237static PyObject *Ctl_DumpControlHierarchy(PyObject *_self, PyObject *_args)
Jack Jansen21f96871998-02-20 16:02:09 +00002238{
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 Jansenfa77e1a2001-05-22 21:56:42 +00002255static PyObject *Ctl_CreateRootControl(PyObject *_self, PyObject *_args)
Jack Jansen21f96871998-02-20 16:02:09 +00002256{
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 Jansenfa77e1a2001-05-22 21:56:42 +00002272static PyObject *Ctl_GetRootControl(PyObject *_self, PyObject *_args)
Jack Jansen21f96871998-02-20 16:02:09 +00002273{
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 Jansenfa77e1a2001-05-22 21:56:42 +00002289static PyObject *Ctl_GetKeyboardFocus(PyObject *_self, PyObject *_args)
Jack Jansen21f96871998-02-20 16:02:09 +00002290{
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 Jansenfa77e1a2001-05-22 21:56:42 +00002306static PyObject *Ctl_SetKeyboardFocus(PyObject *_self, PyObject *_args)
Jack Jansen21f96871998-02-20 16:02:09 +00002307{
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 Jansenfa77e1a2001-05-22 21:56:42 +00002327static PyObject *Ctl_AdvanceKeyboardFocus(PyObject *_self, PyObject *_args)
Jack Jansen21f96871998-02-20 16:02:09 +00002328{
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 Jansenfa77e1a2001-05-22 21:56:42 +00002342static PyObject *Ctl_ReverseKeyboardFocus(PyObject *_self, PyObject *_args)
Jack Jansen21f96871998-02-20 16:02:09 +00002343{
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 Jansenfa77e1a2001-05-22 21:56:42 +00002357static PyObject *Ctl_ClearKeyboardFocus(PyObject *_self, PyObject *_args)
Jack Jansen21f96871998-02-20 16:02:09 +00002358{
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 Jansenf7d5aa62000-12-10 23:43:49 +00002372#if TARGET_API_MAC_CARBON
2373
Jack Jansenfa77e1a2001-05-22 21:56:42 +00002374static PyObject *Ctl_SetAutomaticControlDragTrackingEnabledForWindow(PyObject *_self, PyObject *_args)
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002375{
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 Jansenfa77e1a2001-05-22 21:56:42 +00002395static PyObject *Ctl_IsAutomaticControlDragTrackingEnabledForWindow(PyObject *_self, PyObject *_args)
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002396{
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 Jansenfa77e1a2001-05-22 21:56:42 +00002413static PyObject *Ctl_as_Control(PyObject *_self, PyObject *_args)
Jack Jansene0581891999-02-07 14:02:03 +00002414{
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 Rossum17448e21995-01-30 11:53:55 +00002427static PyMethodDef Ctl_methods[] = {
2428 {"NewControl", (PyCFunction)Ctl_NewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00002429 "(WindowPtr owningWindow, Rect boundsRect, Str255 controlTitle, Boolean initiallyVisible, SInt16 initialValue, SInt16 minimumValue, SInt16 maximumValue, SInt16 procID, SInt32 controlReference) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002430 {"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00002431 "(SInt16 resourceID, WindowPtr owningWindow) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002432 {"DrawControls", (PyCFunction)Ctl_DrawControls, 1,
2433 "(WindowPtr theWindow) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002434 {"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1,
Jack Jansen2b724171996-04-10 14:48:19 +00002435 "(WindowPtr theWindow, RgnHandle updateRegion) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002436 {"FindControl", (PyCFunction)Ctl_FindControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00002437 "(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 Jansenf7d5aa62000-12-10 23:43:49 +00002442
2443#if TARGET_API_MAC_CARBON
2444 {"GetControlByID", (PyCFunction)Ctl_GetControlByID, 1,
2445 "(WindowPtr inWindow, ControlID inID) -> (ControlHandle outControl)"},
2446#endif
Jack Jansen21f96871998-02-20 16:02:09 +00002447 {"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 Jansenf7d5aa62000-12-10 23:43:49 +00002463
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 Jansene0581891999-02-07 14:02:03 +00002473 {"as_Control", (PyCFunction)Ctl_as_Control, 1,
2474 "(Handle h) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002475 {NULL, NULL, 0}
2476};
2477
2478
2479
Jack Jansen9d8b96c2000-07-14 22:16:45 +00002480static PyObject *
Jack Jansenfa77e1a2001-05-22 21:56:42 +00002481CtlObj_NewUnmanaged(ControlHandle itself)
Jack Jansen8387af61999-03-13 23:07:32 +00002482{
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 Jansen1a7d5b12000-03-21 16:25:23 +00002488 it->ob_callbackdict = NULL;
Jack Jansen8387af61999-03-13 23:07:32 +00002489 return (PyObject *)it;
2490}
2491
Jack Jansen9d8b96c2000-07-14 22:16:45 +00002492static PyObject *
Guido van Rossum17448e21995-01-30 11:53:55 +00002493CtlObj_WhichControl(ControlHandle c)
2494{
2495 PyObject *it;
Jack Jansen24c35311999-12-09 22:49:51 +00002496
Guido van Rossum17448e21995-01-30 11:53:55 +00002497 if (c == NULL)
Guido van Rossum17448e21995-01-30 11:53:55 +00002498 it = Py_None;
Jack Jansen8387af61999-03-13 23:07:32 +00002499 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 Rossum17448e21995-01-30 11:53:55 +00002508 Py_INCREF(it);
2509 return it;
2510}
2511
Jack Jansen848250c1998-05-28 14:20:09 +00002512static int
Jack Jansenfa77e1a2001-05-22 21:56:42 +00002513settrackfunc(PyObject *obj)
Jack Jansen848250c1998-05-28 14:20:09 +00002514{
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
2523static void
Jack Jansenfa77e1a2001-05-22 21:56:42 +00002524clrtrackfunc(void)
Jack Jansen848250c1998-05-28 14:20:09 +00002525{
2526 Py_XDECREF(tracker);
2527 tracker = 0;
2528}
2529
2530static pascal void
Jack Jansene79dc762000-06-02 21:35:07 +00002531mytracker(ControlHandle ctl, short part)
Jack Jansen848250c1998-05-28 14:20:09 +00002532{
2533 PyObject *args, *rv=0;
Jack Jansen24c35311999-12-09 22:49:51 +00002534
Jack Jansen848250c1998-05-28 14:20:09 +00002535 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 Jansen24c35311999-12-09 22:49:51 +00002543 PySys_WriteStderr("TrackControl or HandleControlClick: exception in tracker function\n");
Jack Jansen848250c1998-05-28 14:20:09 +00002544}
2545
Jack Jansenabc411b2000-03-20 16:09:09 +00002546static int
Jack Jansenfa77e1a2001-05-22 21:56:42 +00002547setcallback(PyObject *myself, OSType which, PyObject *callback, UniversalProcPtr *uppp)
Jack Jansenabc411b2000-03-20 16:09:09 +00002548{
Jack Jansen85152b92000-07-11 21:12:55 +00002549 ControlObject *self = (ControlObject *)myself;
Jack Jansenabc411b2000-03-20 16:09:09 +00002550 char keybuf[9];
2551
2552 if ( which == kControlUserPaneDrawProcTag )
Jack Jansen1b6e8212000-04-05 21:30:57 +00002553 *uppp = (UniversalProcPtr)mydrawproc_upp;
Jack Jansenabc411b2000-03-20 16:09:09 +00002554 else if ( which == kControlUserPaneIdleProcTag )
Jack Jansen1b6e8212000-04-05 21:30:57 +00002555 *uppp = (UniversalProcPtr)myidleproc_upp;
Jack Jansena27e9fb2000-03-21 23:03:02 +00002556 else if ( which == kControlUserPaneHitTestProcTag )
Jack Jansen1b6e8212000-04-05 21:30:57 +00002557 *uppp = (UniversalProcPtr)myhittestproc_upp;
Jack Jansena27e9fb2000-03-21 23:03:02 +00002558 else if ( which == kControlUserPaneTrackingProcTag )
Jack Jansen1b6e8212000-04-05 21:30:57 +00002559 *uppp = (UniversalProcPtr)mytrackingproc_upp;
Jack Jansenabc411b2000-03-20 16:09:09 +00002560 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
2576static PyObject *
Jack Jansenfa77e1a2001-05-22 21:56:42 +00002577callcallback(ControlObject *self, OSType which, PyObject *arglist)
Jack Jansenabc411b2000-03-20 16:09:09 +00002578{
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 Jansena27e9fb2000-03-21 23:03:02 +00002585 PySys_WriteStderr("Control callback %x without callback object\n", which);
Jack Jansenabc411b2000-03-20 16:09:09 +00002586 return NULL;
2587 }
2588 rv = PyEval_CallObject(func, arglist);
2589 if ( rv == NULL )
Jack Jansena27e9fb2000-03-21 23:03:02 +00002590 PySys_WriteStderr("Exception in control callback %x handler\n", which);
Jack Jansenabc411b2000-03-20 16:09:09 +00002591 return rv;
2592}
2593
2594static pascal void
2595mydrawproc(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
2607static pascal void
2608myidleproc(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 Jansena27e9fb2000-03-21 23:03:02 +00002620static pascal ControlPartCode
2621myhittestproc(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 Jansendeb63732000-03-22 15:35:24 +00002628 arglist = Py_BuildValue("OO&", ctl_obj, PyMac_BuildPoint, where);
Jack Jansena27e9fb2000-03-21 23:03:02 +00002629 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
2638static pascal ControlPartCode
2639mytrackingproc(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 Jansendeb63732000-03-22 15:35:24 +00002647 arglist = Py_BuildValue("OO&", ctl_obj, PyMac_BuildPoint, startPt);
Jack Jansena27e9fb2000-03-21 23:03:02 +00002648 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 Jansenabc411b2000-03-20 16:09:09 +00002655
Guido van Rossum17448e21995-01-30 11:53:55 +00002656
Jack Jansenfa77e1a2001-05-22 21:56:42 +00002657void initCtl(void)
Guido van Rossum17448e21995-01-30 11:53:55 +00002658{
2659 PyObject *m;
2660 PyObject *d;
2661
2662
2663
Jack Jansenfa77e1a2001-05-22 21:56:42 +00002664 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 Jansen848250c1998-05-28 14:20:09 +00002671
Guido van Rossum17448e21995-01-30 11:53:55 +00002672
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 Jansenf7d5aa62000-12-10 23:43:49 +00002678 return;
Jack Jansena755e681997-09-20 17:40:22 +00002679 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 Rossum17448e21995-01-30 11:53:55 +00002683}
2684
2685/* ========================= End module Ctl ========================= */
2686