blob: cd452603b7f7667c05cfc3e26bf096f9f0146dd5 [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
11#include <Controls.h>
Jack Jansenf7d5aa62000-12-10 23:43:49 +000012#ifndef kControlCheckBoxUncheckedValue
13#include <ControlDefinitions.h>
14#endif
Guido van Rossum17448e21995-01-30 11:53:55 +000015
Jack Jansen9d8b96c2000-07-14 22:16:45 +000016staticforward PyObject *CtlObj_WhichControl(ControlHandle);
17
Jack Jansene0581891999-02-07 14:02:03 +000018#define as_Control(h) ((ControlHandle)h)
Jack Jansena1a0fef1999-12-23 14:32:06 +000019#define as_Resource(ctl) ((Handle)ctl)
Jack Jansen74a1e632000-07-14 22:37:27 +000020#if TARGET_API_MAC_CARBON
Jack Jansene79dc762000-06-02 21:35:07 +000021#define GetControlRect(ctl, rectp) GetControlBounds(ctl, rectp)
22#else
Jack Jansen1a7d5b12000-03-21 16:25:23 +000023#define GetControlRect(ctl, rectp) (*(rectp) = ((*(ctl))->contrlRect))
Jack Jansene79dc762000-06-02 21:35:07 +000024#endif
Guido van Rossum17448e21995-01-30 11:53:55 +000025
Jack Jansen21f96871998-02-20 16:02:09 +000026/*
27** Parse/generate ControlFontStyleRec records
28*/
29#if 0 /* Not needed */
Jack Jansen9d8b96c2000-07-14 22:16:45 +000030static PyObject *
31ControlFontStyle_New(itself)
Jack Jansen21f96871998-02-20 16:02:09 +000032 ControlFontStyleRec *itself;
33{
34
35 return Py_BuildValue("hhhhhhO&O&", itself->flags, itself->font,
36 itself->size, itself->style, itself->mode, itself->just,
37 QdRGB_New, &itself->foreColor, QdRGB_New, &itself->backColor);
38}
39#endif
40
Jack Jansen9d8b96c2000-07-14 22:16:45 +000041static int
Jack Jansen21f96871998-02-20 16:02:09 +000042ControlFontStyle_Convert(v, itself)
43 PyObject *v;
44 ControlFontStyleRec *itself;
45{
46 return PyArg_ParseTuple(v, "hhhhhhO&O&", &itself->flags,
Jack Jansen24c35311999-12-09 22:49:51 +000047 &itself->font, &itself->size, &itself->style, &itself->mode,
48 &itself->just, QdRGB_Convert, &itself->foreColor,
Jack Jansen21f96871998-02-20 16:02:09 +000049 QdRGB_Convert, &itself->backColor);
50}
51
Jack Jansenf7d5aa62000-12-10 23:43:49 +000052/*
53** Parse/generate ControlID records
54*/
55static PyObject *
56PyControlID_New(itself)
57 ControlID *itself;
58{
59
60 return Py_BuildValue("O&l", PyMac_BuildOSType, itself->signature, itself->id);
61}
62
63static int
64PyControlID_Convert(v, itself)
65 PyObject *v;
66 ControlID *itself;
67{
68 return PyArg_ParseTuple(v, "O&l", PyMac_GetOSType, &itself->signature, &itself->id);
69}
70
71
Jack Jansen24c35311999-12-09 22:49:51 +000072/* TrackControl and HandleControlClick callback support */
Jack Jansen848250c1998-05-28 14:20:09 +000073static PyObject *tracker;
74static ControlActionUPP mytracker_upp;
Jack Jansen74a1e632000-07-14 22:37:27 +000075#if !TARGET_API_MAC_CARBON_NOTYET
Jack Jansenabc411b2000-03-20 16:09:09 +000076static ControlUserPaneDrawUPP mydrawproc_upp;
77static ControlUserPaneIdleUPP myidleproc_upp;
Jack Jansena27e9fb2000-03-21 23:03:02 +000078static ControlUserPaneHitTestUPP myhittestproc_upp;
79static ControlUserPaneTrackingUPP mytrackingproc_upp;
Jack Jansene79dc762000-06-02 21:35:07 +000080#endif
Jack Jansen848250c1998-05-28 14:20:09 +000081
82extern int settrackfunc(PyObject *); /* forward */
83extern void clrtrackfunc(void); /* forward */
Jack Jansen74a1e632000-07-14 22:37:27 +000084#if !TARGET_API_MAC_CARBON_NOTYET
Jack Jansen85152b92000-07-11 21:12:55 +000085staticforward int setcallback(PyObject *, OSType, PyObject *, UniversalProcPtr *);
86#endif
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
102PyObject *CtlObj_New(itself)
Jack Jansenae8a68f1995-06-06 12:55:40 +0000103 ControlHandle itself;
Guido van Rossum17448e21995-01-30 11:53:55 +0000104{
105 ControlObject *it;
106 if (itself == NULL) return PyMac_Error(resNotFound);
107 it = PyObject_NEW(ControlObject, &Control_Type);
108 if (it == NULL) return NULL;
109 it->ob_itself = itself;
Jack Jansen85ae4a81997-04-08 15:26:03 +0000110 SetControlReference(itself, (long)it);
Jack Jansenabc411b2000-03-20 16:09:09 +0000111 it->ob_callbackdict = NULL;
Guido van Rossum17448e21995-01-30 11:53:55 +0000112 return (PyObject *)it;
113}
114CtlObj_Convert(v, p_itself)
115 PyObject *v;
116 ControlHandle *p_itself;
117{
118 if (!CtlObj_Check(v))
119 {
120 PyErr_SetString(PyExc_TypeError, "Control required");
121 return 0;
122 }
123 *p_itself = ((ControlObject *)v)->ob_itself;
124 return 1;
125}
126
127static void CtlObj_dealloc(self)
128 ControlObject *self;
129{
Jack Jansenabc411b2000-03-20 16:09:09 +0000130 Py_XDECREF(self->ob_callbackdict);
Jack Jansen24c35311999-12-09 22:49:51 +0000131 if (self->ob_itself)SetControlReference(self->ob_itself, (long)0); /* Make it forget about us */
Guido van Rossum17448e21995-01-30 11:53:55 +0000132 PyMem_DEL(self);
133}
134
Jack Jansen21f96871998-02-20 16:02:09 +0000135static PyObject *CtlObj_HiliteControl(_self, _args)
136 ControlObject *_self;
137 PyObject *_args;
138{
139 PyObject *_res = NULL;
140 ControlPartCode hiliteState;
141 if (!PyArg_ParseTuple(_args, "h",
142 &hiliteState))
143 return NULL;
144 HiliteControl(_self->ob_itself,
145 hiliteState);
146 Py_INCREF(Py_None);
147 _res = Py_None;
148 return _res;
149}
150
Jack Jansen7d0bc831995-06-09 20:56:31 +0000151static PyObject *CtlObj_ShowControl(_self, _args)
152 ControlObject *_self;
153 PyObject *_args;
154{
155 PyObject *_res = NULL;
156 if (!PyArg_ParseTuple(_args, ""))
157 return NULL;
158 ShowControl(_self->ob_itself);
159 Py_INCREF(Py_None);
160 _res = Py_None;
161 return _res;
162}
163
164static PyObject *CtlObj_HideControl(_self, _args)
165 ControlObject *_self;
166 PyObject *_args;
167{
168 PyObject *_res = NULL;
169 if (!PyArg_ParseTuple(_args, ""))
170 return NULL;
171 HideControl(_self->ob_itself);
172 Py_INCREF(Py_None);
173 _res = Py_None;
174 return _res;
175}
176
Jack Jansen21f96871998-02-20 16:02:09 +0000177static PyObject *CtlObj_IsControlActive(_self, _args)
178 ControlObject *_self;
179 PyObject *_args;
180{
181 PyObject *_res = NULL;
182 Boolean _rv;
183 if (!PyArg_ParseTuple(_args, ""))
184 return NULL;
185 _rv = IsControlActive(_self->ob_itself);
186 _res = Py_BuildValue("b",
187 _rv);
188 return _res;
189}
190
191static PyObject *CtlObj_IsControlVisible(_self, _args)
192 ControlObject *_self;
193 PyObject *_args;
194{
195 PyObject *_res = NULL;
196 Boolean _rv;
197 if (!PyArg_ParseTuple(_args, ""))
198 return NULL;
199 _rv = IsControlVisible(_self->ob_itself);
200 _res = Py_BuildValue("b",
201 _rv);
202 return _res;
203}
204
205static PyObject *CtlObj_ActivateControl(_self, _args)
206 ControlObject *_self;
207 PyObject *_args;
208{
209 PyObject *_res = NULL;
210 OSErr _err;
211 if (!PyArg_ParseTuple(_args, ""))
212 return NULL;
213 _err = ActivateControl(_self->ob_itself);
214 if (_err != noErr) return PyMac_Error(_err);
215 Py_INCREF(Py_None);
216 _res = Py_None;
217 return _res;
218}
219
220static PyObject *CtlObj_DeactivateControl(_self, _args)
221 ControlObject *_self;
222 PyObject *_args;
223{
224 PyObject *_res = NULL;
225 OSErr _err;
226 if (!PyArg_ParseTuple(_args, ""))
227 return NULL;
228 _err = DeactivateControl(_self->ob_itself);
229 if (_err != noErr) return PyMac_Error(_err);
230 Py_INCREF(Py_None);
231 _res = Py_None;
232 return _res;
233}
234
235static PyObject *CtlObj_SetControlVisibility(_self, _args)
236 ControlObject *_self;
237 PyObject *_args;
238{
239 PyObject *_res = NULL;
240 OSErr _err;
241 Boolean inIsVisible;
242 Boolean inDoDraw;
243 if (!PyArg_ParseTuple(_args, "bb",
244 &inIsVisible,
245 &inDoDraw))
246 return NULL;
247 _err = SetControlVisibility(_self->ob_itself,
248 inIsVisible,
249 inDoDraw);
250 if (_err != noErr) return PyMac_Error(_err);
251 Py_INCREF(Py_None);
252 _res = Py_None;
253 return _res;
254}
255
Jack Jansen7d0bc831995-06-09 20:56:31 +0000256static PyObject *CtlObj_Draw1Control(_self, _args)
257 ControlObject *_self;
258 PyObject *_args;
259{
260 PyObject *_res = NULL;
261 if (!PyArg_ParseTuple(_args, ""))
262 return NULL;
263 Draw1Control(_self->ob_itself);
264 Py_INCREF(Py_None);
265 _res = Py_None;
266 return _res;
267}
268
Jack Jansen21f96871998-02-20 16:02:09 +0000269static PyObject *CtlObj_GetBestControlRect(_self, _args)
Jack Jansen7d0bc831995-06-09 20:56:31 +0000270 ControlObject *_self;
271 PyObject *_args;
272{
273 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000274 OSErr _err;
275 Rect outRect;
276 SInt16 outBaseLineOffset;
277 if (!PyArg_ParseTuple(_args, ""))
Jack Jansen7d0bc831995-06-09 20:56:31 +0000278 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000279 _err = GetBestControlRect(_self->ob_itself,
280 &outRect,
281 &outBaseLineOffset);
282 if (_err != noErr) return PyMac_Error(_err);
283 _res = Py_BuildValue("O&h",
284 PyMac_BuildRect, &outRect,
285 outBaseLineOffset);
286 return _res;
287}
288
289static PyObject *CtlObj_SetControlFontStyle(_self, _args)
290 ControlObject *_self;
291 PyObject *_args;
292{
293 PyObject *_res = NULL;
294 OSErr _err;
295 ControlFontStyleRec inStyle;
296 if (!PyArg_ParseTuple(_args, "O&",
297 ControlFontStyle_Convert, &inStyle))
298 return NULL;
299 _err = SetControlFontStyle(_self->ob_itself,
300 &inStyle);
301 if (_err != noErr) return PyMac_Error(_err);
302 Py_INCREF(Py_None);
303 _res = Py_None;
304 return _res;
305}
306
307static PyObject *CtlObj_DrawControlInCurrentPort(_self, _args)
308 ControlObject *_self;
309 PyObject *_args;
310{
311 PyObject *_res = NULL;
312 if (!PyArg_ParseTuple(_args, ""))
313 return NULL;
314 DrawControlInCurrentPort(_self->ob_itself);
315 Py_INCREF(Py_None);
316 _res = Py_None;
317 return _res;
318}
319
320static PyObject *CtlObj_SetUpControlBackground(_self, _args)
321 ControlObject *_self;
322 PyObject *_args;
323{
324 PyObject *_res = NULL;
325 OSErr _err;
326 SInt16 inDepth;
327 Boolean inIsColorDevice;
328 if (!PyArg_ParseTuple(_args, "hb",
329 &inDepth,
330 &inIsColorDevice))
331 return NULL;
332 _err = SetUpControlBackground(_self->ob_itself,
333 inDepth,
334 inIsColorDevice);
335 if (_err != noErr) return PyMac_Error(_err);
Jack Jansen7d0bc831995-06-09 20:56:31 +0000336 Py_INCREF(Py_None);
337 _res = Py_None;
338 return _res;
339}
340
Jack Jansena05ac601999-12-12 21:41:51 +0000341static PyObject *CtlObj_SetUpControlTextColor(_self, _args)
342 ControlObject *_self;
343 PyObject *_args;
344{
345 PyObject *_res = NULL;
346 OSErr _err;
347 SInt16 inDepth;
348 Boolean inIsColorDevice;
349 if (!PyArg_ParseTuple(_args, "hb",
350 &inDepth,
351 &inIsColorDevice))
352 return NULL;
353 _err = SetUpControlTextColor(_self->ob_itself,
354 inDepth,
355 inIsColorDevice);
356 if (_err != noErr) return PyMac_Error(_err);
357 Py_INCREF(Py_None);
358 _res = Py_None;
359 return _res;
360}
361
Jack Jansen7d0bc831995-06-09 20:56:31 +0000362static PyObject *CtlObj_DragControl(_self, _args)
363 ControlObject *_self;
364 PyObject *_args;
365{
366 PyObject *_res = NULL;
Jack Jansen754d4a41995-11-14 10:41:55 +0000367 Point startPoint;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000368 Rect limitRect;
369 Rect slopRect;
370 DragConstraint axis;
Jack Jansen0b13e7c2000-07-07 13:09:35 +0000371 if (!PyArg_ParseTuple(_args, "O&O&O&H",
Jack Jansen754d4a41995-11-14 10:41:55 +0000372 PyMac_GetPoint, &startPoint,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000373 PyMac_GetRect, &limitRect,
374 PyMac_GetRect, &slopRect,
375 &axis))
376 return NULL;
377 DragControl(_self->ob_itself,
Jack Jansen754d4a41995-11-14 10:41:55 +0000378 startPoint,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000379 &limitRect,
380 &slopRect,
381 axis);
382 Py_INCREF(Py_None);
383 _res = Py_None;
384 return _res;
385}
386
387static PyObject *CtlObj_TestControl(_self, _args)
388 ControlObject *_self;
389 PyObject *_args;
390{
391 PyObject *_res = NULL;
392 ControlPartCode _rv;
Jack Jansen21f96871998-02-20 16:02:09 +0000393 Point testPoint;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000394 if (!PyArg_ParseTuple(_args, "O&",
Jack Jansen21f96871998-02-20 16:02:09 +0000395 PyMac_GetPoint, &testPoint))
Jack Jansen7d0bc831995-06-09 20:56:31 +0000396 return NULL;
397 _rv = TestControl(_self->ob_itself,
Jack Jansen21f96871998-02-20 16:02:09 +0000398 testPoint);
399 _res = Py_BuildValue("h",
400 _rv);
401 return _res;
402}
403
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000404#if TARGET_API_MAC_CARBON
405
406static PyObject *CtlObj_HandleControlContextualMenuClick(_self, _args)
407 ControlObject *_self;
408 PyObject *_args;
409{
410 PyObject *_res = NULL;
411 OSStatus _err;
412 Point inWhere;
413 Boolean menuDisplayed;
414 if (!PyArg_ParseTuple(_args, "O&",
415 PyMac_GetPoint, &inWhere))
416 return NULL;
417 _err = HandleControlContextualMenuClick(_self->ob_itself,
418 inWhere,
419 &menuDisplayed);
420 if (_err != noErr) return PyMac_Error(_err);
421 _res = Py_BuildValue("b",
422 menuDisplayed);
423 return _res;
424}
425#endif
426
427#if TARGET_API_MAC_CARBON
428
429static PyObject *CtlObj_GetControlClickActivation(_self, _args)
430 ControlObject *_self;
431 PyObject *_args;
432{
433 PyObject *_res = NULL;
434 OSStatus _err;
435 Point inWhere;
436 EventModifiers inModifiers;
437 ClickActivationResult outResult;
438 if (!PyArg_ParseTuple(_args, "O&H",
439 PyMac_GetPoint, &inWhere,
440 &inModifiers))
441 return NULL;
442 _err = GetControlClickActivation(_self->ob_itself,
443 inWhere,
444 inModifiers,
445 &outResult);
446 if (_err != noErr) return PyMac_Error(_err);
447 _res = Py_BuildValue("l",
448 outResult);
449 return _res;
450}
451#endif
452
Jack Jansen21f96871998-02-20 16:02:09 +0000453static PyObject *CtlObj_HandleControlKey(_self, _args)
454 ControlObject *_self;
455 PyObject *_args;
456{
457 PyObject *_res = NULL;
458 SInt16 _rv;
459 SInt16 inKeyCode;
460 SInt16 inCharCode;
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000461 EventModifiers inModifiers;
462 if (!PyArg_ParseTuple(_args, "hhH",
Jack Jansen21f96871998-02-20 16:02:09 +0000463 &inKeyCode,
464 &inCharCode,
465 &inModifiers))
466 return NULL;
467 _rv = HandleControlKey(_self->ob_itself,
468 inKeyCode,
469 inCharCode,
470 inModifiers);
Jack Jansen7d0bc831995-06-09 20:56:31 +0000471 _res = Py_BuildValue("h",
472 _rv);
473 return _res;
474}
475
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000476#if TARGET_API_MAC_CARBON
477
478static PyObject *CtlObj_HandleControlSetCursor(_self, _args)
479 ControlObject *_self;
480 PyObject *_args;
481{
482 PyObject *_res = NULL;
483 OSStatus _err;
484 Point localPoint;
485 EventModifiers modifiers;
486 Boolean cursorWasSet;
487 if (!PyArg_ParseTuple(_args, "O&H",
488 PyMac_GetPoint, &localPoint,
489 &modifiers))
490 return NULL;
491 _err = HandleControlSetCursor(_self->ob_itself,
492 localPoint,
493 modifiers,
494 &cursorWasSet);
495 if (_err != noErr) return PyMac_Error(_err);
496 _res = Py_BuildValue("b",
497 cursorWasSet);
498 return _res;
499}
500#endif
501
Jack Jansen7d0bc831995-06-09 20:56:31 +0000502static PyObject *CtlObj_MoveControl(_self, _args)
503 ControlObject *_self;
504 PyObject *_args;
505{
506 PyObject *_res = NULL;
507 SInt16 h;
508 SInt16 v;
509 if (!PyArg_ParseTuple(_args, "hh",
510 &h,
511 &v))
512 return NULL;
513 MoveControl(_self->ob_itself,
514 h,
515 v);
516 Py_INCREF(Py_None);
517 _res = Py_None;
518 return _res;
519}
520
521static PyObject *CtlObj_SizeControl(_self, _args)
522 ControlObject *_self;
523 PyObject *_args;
524{
525 PyObject *_res = NULL;
526 SInt16 w;
527 SInt16 h;
528 if (!PyArg_ParseTuple(_args, "hh",
529 &w,
530 &h))
531 return NULL;
532 SizeControl(_self->ob_itself,
533 w,
534 h);
535 Py_INCREF(Py_None);
536 _res = Py_None;
537 return _res;
538}
539
Jack Jansenae8a68f1995-06-06 12:55:40 +0000540static PyObject *CtlObj_SetControlTitle(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000541 ControlObject *_self;
542 PyObject *_args;
543{
544 PyObject *_res = NULL;
545 Str255 title;
546 if (!PyArg_ParseTuple(_args, "O&",
547 PyMac_GetStr255, title))
548 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000549 SetControlTitle(_self->ob_itself,
550 title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000551 Py_INCREF(Py_None);
552 _res = Py_None;
553 return _res;
554}
555
Jack Jansenae8a68f1995-06-06 12:55:40 +0000556static PyObject *CtlObj_GetControlTitle(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000557 ControlObject *_self;
558 PyObject *_args;
559{
560 PyObject *_res = NULL;
561 Str255 title;
Jack Jansen41009001999-03-07 20:05:20 +0000562 if (!PyArg_ParseTuple(_args, ""))
Guido van Rossum17448e21995-01-30 11:53:55 +0000563 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000564 GetControlTitle(_self->ob_itself,
565 title);
Jack Jansen41009001999-03-07 20:05:20 +0000566 _res = Py_BuildValue("O&",
567 PyMac_BuildStr255, title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000568 return _res;
569}
570
Jack Jansenae8a68f1995-06-06 12:55:40 +0000571static PyObject *CtlObj_GetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000572 ControlObject *_self;
573 PyObject *_args;
574{
575 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000576 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000577 if (!PyArg_ParseTuple(_args, ""))
578 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000579 _rv = GetControlValue(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000580 _res = Py_BuildValue("h",
581 _rv);
582 return _res;
583}
584
Jack Jansen7d0bc831995-06-09 20:56:31 +0000585static PyObject *CtlObj_SetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000586 ControlObject *_self;
587 PyObject *_args;
588{
589 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000590 SInt16 newValue;
Guido van Rossum17448e21995-01-30 11:53:55 +0000591 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000592 &newValue))
Guido van Rossum17448e21995-01-30 11:53:55 +0000593 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000594 SetControlValue(_self->ob_itself,
595 newValue);
Guido van Rossum17448e21995-01-30 11:53:55 +0000596 Py_INCREF(Py_None);
597 _res = Py_None;
598 return _res;
599}
600
Jack Jansenae8a68f1995-06-06 12:55:40 +0000601static PyObject *CtlObj_GetControlMinimum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000602 ControlObject *_self;
603 PyObject *_args;
604{
605 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000606 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000607 if (!PyArg_ParseTuple(_args, ""))
608 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000609 _rv = GetControlMinimum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000610 _res = Py_BuildValue("h",
611 _rv);
612 return _res;
613}
614
Jack Jansen7d0bc831995-06-09 20:56:31 +0000615static PyObject *CtlObj_SetControlMinimum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000616 ControlObject *_self;
617 PyObject *_args;
618{
619 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000620 SInt16 newMinimum;
Guido van Rossum17448e21995-01-30 11:53:55 +0000621 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000622 &newMinimum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000623 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000624 SetControlMinimum(_self->ob_itself,
625 newMinimum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000626 Py_INCREF(Py_None);
627 _res = Py_None;
628 return _res;
629}
630
Jack Jansenae8a68f1995-06-06 12:55:40 +0000631static PyObject *CtlObj_GetControlMaximum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000632 ControlObject *_self;
633 PyObject *_args;
634{
635 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000636 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000637 if (!PyArg_ParseTuple(_args, ""))
638 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000639 _rv = GetControlMaximum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000640 _res = Py_BuildValue("h",
641 _rv);
642 return _res;
643}
644
Jack Jansen7d0bc831995-06-09 20:56:31 +0000645static PyObject *CtlObj_SetControlMaximum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000646 ControlObject *_self;
647 PyObject *_args;
648{
649 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000650 SInt16 newMaximum;
651 if (!PyArg_ParseTuple(_args, "h",
652 &newMaximum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000653 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000654 SetControlMaximum(_self->ob_itself,
655 newMaximum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000656 Py_INCREF(Py_None);
657 _res = Py_None;
658 return _res;
659}
660
Jack Jansena05ac601999-12-12 21:41:51 +0000661static PyObject *CtlObj_GetControlViewSize(_self, _args)
662 ControlObject *_self;
663 PyObject *_args;
664{
665 PyObject *_res = NULL;
666 SInt32 _rv;
667 if (!PyArg_ParseTuple(_args, ""))
668 return NULL;
669 _rv = GetControlViewSize(_self->ob_itself);
670 _res = Py_BuildValue("l",
671 _rv);
672 return _res;
673}
674
675static PyObject *CtlObj_SetControlViewSize(_self, _args)
676 ControlObject *_self;
677 PyObject *_args;
678{
679 PyObject *_res = NULL;
680 SInt32 newViewSize;
681 if (!PyArg_ParseTuple(_args, "l",
682 &newViewSize))
683 return NULL;
684 SetControlViewSize(_self->ob_itself,
685 newViewSize);
686 Py_INCREF(Py_None);
687 _res = Py_None;
688 return _res;
689}
690
691static PyObject *CtlObj_GetControl32BitValue(_self, _args)
692 ControlObject *_self;
693 PyObject *_args;
694{
695 PyObject *_res = NULL;
696 SInt32 _rv;
697 if (!PyArg_ParseTuple(_args, ""))
698 return NULL;
699 _rv = GetControl32BitValue(_self->ob_itself);
700 _res = Py_BuildValue("l",
701 _rv);
702 return _res;
703}
704
705static PyObject *CtlObj_SetControl32BitValue(_self, _args)
706 ControlObject *_self;
707 PyObject *_args;
708{
709 PyObject *_res = NULL;
710 SInt32 newValue;
711 if (!PyArg_ParseTuple(_args, "l",
712 &newValue))
713 return NULL;
714 SetControl32BitValue(_self->ob_itself,
715 newValue);
716 Py_INCREF(Py_None);
717 _res = Py_None;
718 return _res;
719}
720
721static PyObject *CtlObj_GetControl32BitMaximum(_self, _args)
722 ControlObject *_self;
723 PyObject *_args;
724{
725 PyObject *_res = NULL;
726 SInt32 _rv;
727 if (!PyArg_ParseTuple(_args, ""))
728 return NULL;
729 _rv = GetControl32BitMaximum(_self->ob_itself);
730 _res = Py_BuildValue("l",
731 _rv);
732 return _res;
733}
734
735static PyObject *CtlObj_SetControl32BitMaximum(_self, _args)
736 ControlObject *_self;
737 PyObject *_args;
738{
739 PyObject *_res = NULL;
740 SInt32 newMaximum;
741 if (!PyArg_ParseTuple(_args, "l",
742 &newMaximum))
743 return NULL;
744 SetControl32BitMaximum(_self->ob_itself,
745 newMaximum);
746 Py_INCREF(Py_None);
747 _res = Py_None;
748 return _res;
749}
750
751static PyObject *CtlObj_GetControl32BitMinimum(_self, _args)
752 ControlObject *_self;
753 PyObject *_args;
754{
755 PyObject *_res = NULL;
756 SInt32 _rv;
757 if (!PyArg_ParseTuple(_args, ""))
758 return NULL;
759 _rv = GetControl32BitMinimum(_self->ob_itself);
760 _res = Py_BuildValue("l",
761 _rv);
762 return _res;
763}
764
765static PyObject *CtlObj_SetControl32BitMinimum(_self, _args)
766 ControlObject *_self;
767 PyObject *_args;
768{
769 PyObject *_res = NULL;
770 SInt32 newMinimum;
771 if (!PyArg_ParseTuple(_args, "l",
772 &newMinimum))
773 return NULL;
774 SetControl32BitMinimum(_self->ob_itself,
775 newMinimum);
776 Py_INCREF(Py_None);
777 _res = Py_None;
778 return _res;
779}
780
781static PyObject *CtlObj_IsValidControlHandle(_self, _args)
782 ControlObject *_self;
783 PyObject *_args;
784{
785 PyObject *_res = NULL;
786 Boolean _rv;
787 if (!PyArg_ParseTuple(_args, ""))
788 return NULL;
789 _rv = IsValidControlHandle(_self->ob_itself);
790 _res = Py_BuildValue("b",
791 _rv);
792 return _res;
793}
794
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000795#if TARGET_API_MAC_CARBON
796
797static PyObject *CtlObj_SetControlID(_self, _args)
798 ControlObject *_self;
799 PyObject *_args;
800{
801 PyObject *_res = NULL;
802 OSStatus _err;
803 ControlID inID;
804 if (!PyArg_ParseTuple(_args, "O&",
805 PyControlID_Convert, &inID))
806 return NULL;
807 _err = SetControlID(_self->ob_itself,
808 &inID);
809 if (_err != noErr) return PyMac_Error(_err);
810 Py_INCREF(Py_None);
811 _res = Py_None;
812 return _res;
813}
814#endif
815
816#if TARGET_API_MAC_CARBON
817
818static PyObject *CtlObj_GetControlID(_self, _args)
819 ControlObject *_self;
820 PyObject *_args;
821{
822 PyObject *_res = NULL;
823 OSStatus _err;
824 ControlID outID;
825 if (!PyArg_ParseTuple(_args, ""))
826 return NULL;
827 _err = GetControlID(_self->ob_itself,
828 &outID);
829 if (_err != noErr) return PyMac_Error(_err);
830 _res = Py_BuildValue("O&",
831 PyControlID_New, &outID);
832 return _res;
833}
834#endif
835
Jack Jansena05ac601999-12-12 21:41:51 +0000836static PyObject *CtlObj_RemoveControlProperty(_self, _args)
837 ControlObject *_self;
838 PyObject *_args;
839{
840 PyObject *_res = NULL;
Jack Jansene79dc762000-06-02 21:35:07 +0000841 OSStatus _err;
Jack Jansena05ac601999-12-12 21:41:51 +0000842 OSType propertyCreator;
843 OSType propertyTag;
844 if (!PyArg_ParseTuple(_args, "O&O&",
845 PyMac_GetOSType, &propertyCreator,
846 PyMac_GetOSType, &propertyTag))
847 return NULL;
Jack Jansene79dc762000-06-02 21:35:07 +0000848 _err = RemoveControlProperty(_self->ob_itself,
849 propertyCreator,
850 propertyTag);
851 if (_err != noErr) return PyMac_Error(_err);
852 Py_INCREF(Py_None);
853 _res = Py_None;
Jack Jansena05ac601999-12-12 21:41:51 +0000854 return _res;
855}
856
Jack Jansenf7d5aa62000-12-10 23:43:49 +0000857#if TARGET_API_MAC_CARBON
858
859static PyObject *CtlObj_GetControlPropertyAttributes(_self, _args)
860 ControlObject *_self;
861 PyObject *_args;
862{
863 PyObject *_res = NULL;
864 OSStatus _err;
865 OSType propertyCreator;
866 OSType propertyTag;
867 UInt32 attributes;
868 if (!PyArg_ParseTuple(_args, "O&O&",
869 PyMac_GetOSType, &propertyCreator,
870 PyMac_GetOSType, &propertyTag))
871 return NULL;
872 _err = GetControlPropertyAttributes(_self->ob_itself,
873 propertyCreator,
874 propertyTag,
875 &attributes);
876 if (_err != noErr) return PyMac_Error(_err);
877 _res = Py_BuildValue("l",
878 attributes);
879 return _res;
880}
881#endif
882
883#if TARGET_API_MAC_CARBON
884
885static PyObject *CtlObj_ChangeControlPropertyAttributes(_self, _args)
886 ControlObject *_self;
887 PyObject *_args;
888{
889 PyObject *_res = NULL;
890 OSStatus _err;
891 OSType propertyCreator;
892 OSType propertyTag;
893 UInt32 attributesToSet;
894 UInt32 attributesToClear;
895 if (!PyArg_ParseTuple(_args, "O&O&ll",
896 PyMac_GetOSType, &propertyCreator,
897 PyMac_GetOSType, &propertyTag,
898 &attributesToSet,
899 &attributesToClear))
900 return NULL;
901 _err = ChangeControlPropertyAttributes(_self->ob_itself,
902 propertyCreator,
903 propertyTag,
904 attributesToSet,
905 attributesToClear);
906 if (_err != noErr) return PyMac_Error(_err);
907 Py_INCREF(Py_None);
908 _res = Py_None;
909 return _res;
910}
911#endif
912
Jack Jansena05ac601999-12-12 21:41:51 +0000913static PyObject *CtlObj_GetControlRegion(_self, _args)
914 ControlObject *_self;
915 PyObject *_args;
916{
917 PyObject *_res = NULL;
Jack Jansene79dc762000-06-02 21:35:07 +0000918 OSStatus _err;
Jack Jansena05ac601999-12-12 21:41:51 +0000919 ControlPartCode inPart;
920 RgnHandle outRegion;
921 if (!PyArg_ParseTuple(_args, "hO&",
922 &inPart,
923 ResObj_Convert, &outRegion))
924 return NULL;
Jack Jansene79dc762000-06-02 21:35:07 +0000925 _err = GetControlRegion(_self->ob_itself,
926 inPart,
927 outRegion);
928 if (_err != noErr) return PyMac_Error(_err);
929 Py_INCREF(Py_None);
930 _res = Py_None;
Jack Jansena05ac601999-12-12 21:41:51 +0000931 return _res;
932}
933
Jack Jansen7d0bc831995-06-09 20:56:31 +0000934static PyObject *CtlObj_GetControlVariant(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000935 ControlObject *_self;
936 PyObject *_args;
937{
938 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000939 ControlVariant _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000940 if (!PyArg_ParseTuple(_args, ""))
941 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000942 _rv = GetControlVariant(_self->ob_itself);
943 _res = Py_BuildValue("h",
Guido van Rossum17448e21995-01-30 11:53:55 +0000944 _rv);
945 return _res;
946}
947
Jack Jansen7d0bc831995-06-09 20:56:31 +0000948static PyObject *CtlObj_SetControlReference(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000949 ControlObject *_self;
950 PyObject *_args;
951{
952 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000953 SInt32 data;
954 if (!PyArg_ParseTuple(_args, "l",
955 &data))
Guido van Rossum17448e21995-01-30 11:53:55 +0000956 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000957 SetControlReference(_self->ob_itself,
958 data);
Guido van Rossum17448e21995-01-30 11:53:55 +0000959 Py_INCREF(Py_None);
960 _res = Py_None;
961 return _res;
962}
963
Jack Jansen7d0bc831995-06-09 20:56:31 +0000964static PyObject *CtlObj_GetControlReference(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000965 ControlObject *_self;
966 PyObject *_args;
967{
968 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000969 SInt32 _rv;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000970 if (!PyArg_ParseTuple(_args, ""))
971 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000972 _rv = GetControlReference(_self->ob_itself);
973 _res = Py_BuildValue("l",
Guido van Rossum17448e21995-01-30 11:53:55 +0000974 _rv);
975 return _res;
976}
977
Jack Jansen74a1e632000-07-14 22:37:27 +0000978#if !TARGET_API_MAC_CARBON
Jack Jansene79dc762000-06-02 21:35:07 +0000979
Jack Jansenc7fefed1997-08-15 14:32:18 +0000980static PyObject *CtlObj_GetAuxiliaryControlRecord(_self, _args)
981 ControlObject *_self;
982 PyObject *_args;
983{
984 PyObject *_res = NULL;
985 Boolean _rv;
986 AuxCtlHandle acHndl;
987 if (!PyArg_ParseTuple(_args, ""))
988 return NULL;
989 _rv = GetAuxiliaryControlRecord(_self->ob_itself,
990 &acHndl);
991 _res = Py_BuildValue("bO&",
992 _rv,
993 ResObj_New, acHndl);
994 return _res;
995}
Jack Jansene79dc762000-06-02 21:35:07 +0000996#endif
997
Jack Jansen74a1e632000-07-14 22:37:27 +0000998#if !TARGET_API_MAC_CARBON
Jack Jansenc7fefed1997-08-15 14:32:18 +0000999
1000static PyObject *CtlObj_SetControlColor(_self, _args)
1001 ControlObject *_self;
1002 PyObject *_args;
1003{
1004 PyObject *_res = NULL;
1005 CCTabHandle newColorTable;
1006 if (!PyArg_ParseTuple(_args, "O&",
1007 ResObj_Convert, &newColorTable))
1008 return NULL;
1009 SetControlColor(_self->ob_itself,
1010 newColorTable);
1011 Py_INCREF(Py_None);
1012 _res = Py_None;
1013 return _res;
1014}
Jack Jansene79dc762000-06-02 21:35:07 +00001015#endif
1016
Jack Jansen21f96871998-02-20 16:02:09 +00001017static PyObject *CtlObj_SendControlMessage(_self, _args)
1018 ControlObject *_self;
1019 PyObject *_args;
1020{
1021 PyObject *_res = NULL;
1022 SInt32 _rv;
1023 SInt16 inMessage;
1024 SInt32 inParam;
1025 if (!PyArg_ParseTuple(_args, "hl",
1026 &inMessage,
1027 &inParam))
1028 return NULL;
1029 _rv = SendControlMessage(_self->ob_itself,
1030 inMessage,
1031 inParam);
1032 _res = Py_BuildValue("l",
1033 _rv);
1034 return _res;
1035}
1036
1037static PyObject *CtlObj_EmbedControl(_self, _args)
1038 ControlObject *_self;
1039 PyObject *_args;
1040{
1041 PyObject *_res = NULL;
1042 OSErr _err;
1043 ControlHandle inContainer;
1044 if (!PyArg_ParseTuple(_args, "O&",
1045 CtlObj_Convert, &inContainer))
1046 return NULL;
1047 _err = EmbedControl(_self->ob_itself,
1048 inContainer);
1049 if (_err != noErr) return PyMac_Error(_err);
1050 Py_INCREF(Py_None);
1051 _res = Py_None;
1052 return _res;
1053}
1054
1055static PyObject *CtlObj_AutoEmbedControl(_self, _args)
1056 ControlObject *_self;
1057 PyObject *_args;
1058{
1059 PyObject *_res = NULL;
1060 OSErr _err;
1061 WindowPtr inWindow;
1062 if (!PyArg_ParseTuple(_args, "O&",
1063 WinObj_Convert, &inWindow))
1064 return NULL;
1065 _err = AutoEmbedControl(_self->ob_itself,
1066 inWindow);
1067 if (_err != noErr) return PyMac_Error(_err);
1068 Py_INCREF(Py_None);
1069 _res = Py_None;
1070 return _res;
1071}
1072
1073static PyObject *CtlObj_GetSuperControl(_self, _args)
1074 ControlObject *_self;
1075 PyObject *_args;
1076{
1077 PyObject *_res = NULL;
1078 OSErr _err;
1079 ControlHandle outParent;
1080 if (!PyArg_ParseTuple(_args, ""))
1081 return NULL;
1082 _err = GetSuperControl(_self->ob_itself,
1083 &outParent);
1084 if (_err != noErr) return PyMac_Error(_err);
1085 _res = Py_BuildValue("O&",
1086 CtlObj_WhichControl, outParent);
1087 return _res;
1088}
1089
1090static PyObject *CtlObj_CountSubControls(_self, _args)
1091 ControlObject *_self;
1092 PyObject *_args;
1093{
1094 PyObject *_res = NULL;
1095 OSErr _err;
Jack Jansen24c35311999-12-09 22:49:51 +00001096 UInt16 outNumChildren;
Jack Jansen21f96871998-02-20 16:02:09 +00001097 if (!PyArg_ParseTuple(_args, ""))
1098 return NULL;
1099 _err = CountSubControls(_self->ob_itself,
1100 &outNumChildren);
1101 if (_err != noErr) return PyMac_Error(_err);
Jack Jansen0b13e7c2000-07-07 13:09:35 +00001102 _res = Py_BuildValue("H",
Jack Jansen21f96871998-02-20 16:02:09 +00001103 outNumChildren);
1104 return _res;
1105}
1106
1107static PyObject *CtlObj_GetIndexedSubControl(_self, _args)
1108 ControlObject *_self;
1109 PyObject *_args;
1110{
1111 PyObject *_res = NULL;
1112 OSErr _err;
Jack Jansen24c35311999-12-09 22:49:51 +00001113 UInt16 inIndex;
Jack Jansen21f96871998-02-20 16:02:09 +00001114 ControlHandle outSubControl;
Jack Jansen0b13e7c2000-07-07 13:09:35 +00001115 if (!PyArg_ParseTuple(_args, "H",
Jack Jansen21f96871998-02-20 16:02:09 +00001116 &inIndex))
1117 return NULL;
1118 _err = GetIndexedSubControl(_self->ob_itself,
1119 inIndex,
1120 &outSubControl);
1121 if (_err != noErr) return PyMac_Error(_err);
1122 _res = Py_BuildValue("O&",
1123 CtlObj_WhichControl, outSubControl);
1124 return _res;
1125}
1126
1127static PyObject *CtlObj_SetControlSupervisor(_self, _args)
1128 ControlObject *_self;
1129 PyObject *_args;
1130{
1131 PyObject *_res = NULL;
1132 OSErr _err;
1133 ControlHandle inBoss;
1134 if (!PyArg_ParseTuple(_args, "O&",
1135 CtlObj_Convert, &inBoss))
1136 return NULL;
1137 _err = SetControlSupervisor(_self->ob_itself,
1138 inBoss);
1139 if (_err != noErr) return PyMac_Error(_err);
1140 Py_INCREF(Py_None);
1141 _res = Py_None;
1142 return _res;
1143}
1144
1145static PyObject *CtlObj_GetControlFeatures(_self, _args)
1146 ControlObject *_self;
1147 PyObject *_args;
1148{
1149 PyObject *_res = NULL;
1150 OSErr _err;
1151 UInt32 outFeatures;
1152 if (!PyArg_ParseTuple(_args, ""))
1153 return NULL;
1154 _err = GetControlFeatures(_self->ob_itself,
1155 &outFeatures);
1156 if (_err != noErr) return PyMac_Error(_err);
1157 _res = Py_BuildValue("l",
1158 outFeatures);
1159 return _res;
1160}
1161
1162static PyObject *CtlObj_GetControlDataSize(_self, _args)
1163 ControlObject *_self;
1164 PyObject *_args;
1165{
1166 PyObject *_res = NULL;
1167 OSErr _err;
1168 ControlPartCode inPart;
1169 ResType inTagName;
1170 Size outMaxSize;
1171 if (!PyArg_ParseTuple(_args, "hO&",
1172 &inPart,
1173 PyMac_GetOSType, &inTagName))
1174 return NULL;
1175 _err = GetControlDataSize(_self->ob_itself,
1176 inPart,
1177 inTagName,
1178 &outMaxSize);
1179 if (_err != noErr) return PyMac_Error(_err);
1180 _res = Py_BuildValue("l",
1181 outMaxSize);
1182 return _res;
1183}
1184
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001185#if TARGET_API_MAC_CARBON
1186
1187static PyObject *CtlObj_SetControlDragTrackingEnabled(_self, _args)
1188 ControlObject *_self;
1189 PyObject *_args;
1190{
1191 PyObject *_res = NULL;
1192 OSStatus _err;
1193 Boolean tracks;
1194 if (!PyArg_ParseTuple(_args, "b",
1195 &tracks))
1196 return NULL;
1197 _err = SetControlDragTrackingEnabled(_self->ob_itself,
1198 tracks);
1199 if (_err != noErr) return PyMac_Error(_err);
1200 Py_INCREF(Py_None);
1201 _res = Py_None;
1202 return _res;
1203}
1204#endif
1205
1206#if TARGET_API_MAC_CARBON
1207
1208static PyObject *CtlObj_IsControlDragTrackingEnabled(_self, _args)
1209 ControlObject *_self;
1210 PyObject *_args;
1211{
1212 PyObject *_res = NULL;
1213 OSStatus _err;
1214 Boolean tracks;
1215 if (!PyArg_ParseTuple(_args, ""))
1216 return NULL;
1217 _err = IsControlDragTrackingEnabled(_self->ob_itself,
1218 &tracks);
1219 if (_err != noErr) return PyMac_Error(_err);
1220 _res = Py_BuildValue("b",
1221 tracks);
1222 return _res;
1223}
1224#endif
1225
1226#if ACCESSOR_CALLS_ARE_FUNCTIONS
1227
1228static PyObject *CtlObj_GetControlBounds(_self, _args)
1229 ControlObject *_self;
1230 PyObject *_args;
1231{
1232 PyObject *_res = NULL;
1233 Rect _rv;
1234 Rect bounds;
1235 if (!PyArg_ParseTuple(_args, ""))
1236 return NULL;
1237 _rv = GetControlBounds(_self->ob_itself,
1238 &bounds);
1239 _res = Py_BuildValue("O&O&",
1240 PyMac_BuildRect, &_rv,
1241 PyMac_BuildRect, &bounds);
1242 return _res;
1243}
1244#endif
1245
1246#if ACCESSOR_CALLS_ARE_FUNCTIONS
1247
1248static PyObject *CtlObj_IsControlHilited(_self, _args)
1249 ControlObject *_self;
1250 PyObject *_args;
1251{
1252 PyObject *_res = NULL;
1253 Boolean _rv;
1254 if (!PyArg_ParseTuple(_args, ""))
1255 return NULL;
1256 _rv = IsControlHilited(_self->ob_itself);
1257 _res = Py_BuildValue("b",
1258 _rv);
1259 return _res;
1260}
1261#endif
1262
1263#if ACCESSOR_CALLS_ARE_FUNCTIONS
1264
1265static PyObject *CtlObj_GetControlHilite(_self, _args)
1266 ControlObject *_self;
1267 PyObject *_args;
1268{
1269 PyObject *_res = NULL;
1270 UInt16 _rv;
1271 if (!PyArg_ParseTuple(_args, ""))
1272 return NULL;
1273 _rv = GetControlHilite(_self->ob_itself);
1274 _res = Py_BuildValue("H",
1275 _rv);
1276 return _res;
1277}
1278#endif
1279
1280#if ACCESSOR_CALLS_ARE_FUNCTIONS
1281
1282static PyObject *CtlObj_GetControlOwner(_self, _args)
1283 ControlObject *_self;
1284 PyObject *_args;
1285{
1286 PyObject *_res = NULL;
1287 WindowPtr _rv;
1288 if (!PyArg_ParseTuple(_args, ""))
1289 return NULL;
1290 _rv = GetControlOwner(_self->ob_itself);
1291 _res = Py_BuildValue("O&",
1292 WinObj_New, _rv);
1293 return _res;
1294}
1295#endif
1296
1297#if ACCESSOR_CALLS_ARE_FUNCTIONS
1298
1299static PyObject *CtlObj_GetControlDataHandle(_self, _args)
1300 ControlObject *_self;
1301 PyObject *_args;
1302{
1303 PyObject *_res = NULL;
1304 Handle _rv;
1305 if (!PyArg_ParseTuple(_args, ""))
1306 return NULL;
1307 _rv = GetControlDataHandle(_self->ob_itself);
1308 _res = Py_BuildValue("O&",
1309 ResObj_New, _rv);
1310 return _res;
1311}
1312#endif
1313
1314#if ACCESSOR_CALLS_ARE_FUNCTIONS
1315
1316static PyObject *CtlObj_GetControlPopupMenuHandle(_self, _args)
1317 ControlObject *_self;
1318 PyObject *_args;
1319{
1320 PyObject *_res = NULL;
1321 MenuHandle _rv;
1322 if (!PyArg_ParseTuple(_args, ""))
1323 return NULL;
1324 _rv = GetControlPopupMenuHandle(_self->ob_itself);
1325 _res = Py_BuildValue("O&",
1326 MenuObj_New, _rv);
1327 return _res;
1328}
1329#endif
1330
1331#if ACCESSOR_CALLS_ARE_FUNCTIONS
1332
1333static PyObject *CtlObj_GetControlPopupMenuID(_self, _args)
1334 ControlObject *_self;
1335 PyObject *_args;
1336{
1337 PyObject *_res = NULL;
1338 short _rv;
1339 if (!PyArg_ParseTuple(_args, ""))
1340 return NULL;
1341 _rv = GetControlPopupMenuID(_self->ob_itself);
1342 _res = Py_BuildValue("h",
1343 _rv);
1344 return _res;
1345}
1346#endif
1347
1348#if ACCESSOR_CALLS_ARE_FUNCTIONS
1349
1350static PyObject *CtlObj_SetControlDataHandle(_self, _args)
1351 ControlObject *_self;
1352 PyObject *_args;
1353{
1354 PyObject *_res = NULL;
1355 Handle dataHandle;
1356 if (!PyArg_ParseTuple(_args, "O&",
1357 ResObj_Convert, &dataHandle))
1358 return NULL;
1359 SetControlDataHandle(_self->ob_itself,
1360 dataHandle);
1361 Py_INCREF(Py_None);
1362 _res = Py_None;
1363 return _res;
1364}
1365#endif
1366
1367#if ACCESSOR_CALLS_ARE_FUNCTIONS
1368
1369static PyObject *CtlObj_SetControlBounds(_self, _args)
1370 ControlObject *_self;
1371 PyObject *_args;
1372{
1373 PyObject *_res = NULL;
1374 Rect bounds;
1375 if (!PyArg_ParseTuple(_args, "O&",
1376 PyMac_GetRect, &bounds))
1377 return NULL;
1378 SetControlBounds(_self->ob_itself,
1379 &bounds);
1380 Py_INCREF(Py_None);
1381 _res = Py_None;
1382 return _res;
1383}
1384#endif
1385
1386#if ACCESSOR_CALLS_ARE_FUNCTIONS
1387
1388static PyObject *CtlObj_SetControlPopupMenuHandle(_self, _args)
1389 ControlObject *_self;
1390 PyObject *_args;
1391{
1392 PyObject *_res = NULL;
1393 MenuHandle popupMenu;
1394 if (!PyArg_ParseTuple(_args, "O&",
1395 MenuObj_Convert, &popupMenu))
1396 return NULL;
1397 SetControlPopupMenuHandle(_self->ob_itself,
1398 popupMenu);
1399 Py_INCREF(Py_None);
1400 _res = Py_None;
1401 return _res;
1402}
1403#endif
1404
1405#if ACCESSOR_CALLS_ARE_FUNCTIONS
1406
1407static PyObject *CtlObj_SetControlPopupMenuID(_self, _args)
1408 ControlObject *_self;
1409 PyObject *_args;
1410{
1411 PyObject *_res = NULL;
1412 short menuID;
1413 if (!PyArg_ParseTuple(_args, "h",
1414 &menuID))
1415 return NULL;
1416 SetControlPopupMenuID(_self->ob_itself,
1417 menuID);
1418 Py_INCREF(Py_None);
1419 _res = Py_None;
1420 return _res;
1421}
1422#endif
1423
1424static PyObject *CtlObj_GetBevelButtonMenuValue(_self, _args)
1425 ControlObject *_self;
1426 PyObject *_args;
1427{
1428 PyObject *_res = NULL;
1429 OSErr _err;
1430 SInt16 outValue;
1431 if (!PyArg_ParseTuple(_args, ""))
1432 return NULL;
1433 _err = GetBevelButtonMenuValue(_self->ob_itself,
1434 &outValue);
1435 if (_err != noErr) return PyMac_Error(_err);
1436 _res = Py_BuildValue("h",
1437 outValue);
1438 return _res;
1439}
1440
1441static PyObject *CtlObj_SetBevelButtonMenuValue(_self, _args)
1442 ControlObject *_self;
1443 PyObject *_args;
1444{
1445 PyObject *_res = NULL;
1446 OSErr _err;
1447 SInt16 inValue;
1448 if (!PyArg_ParseTuple(_args, "h",
1449 &inValue))
1450 return NULL;
1451 _err = SetBevelButtonMenuValue(_self->ob_itself,
1452 inValue);
1453 if (_err != noErr) return PyMac_Error(_err);
1454 Py_INCREF(Py_None);
1455 _res = Py_None;
1456 return _res;
1457}
1458
1459static PyObject *CtlObj_GetBevelButtonMenuHandle(_self, _args)
1460 ControlObject *_self;
1461 PyObject *_args;
1462{
1463 PyObject *_res = NULL;
1464 OSErr _err;
1465 MenuHandle outHandle;
1466 if (!PyArg_ParseTuple(_args, ""))
1467 return NULL;
1468 _err = GetBevelButtonMenuHandle(_self->ob_itself,
1469 &outHandle);
1470 if (_err != noErr) return PyMac_Error(_err);
1471 _res = Py_BuildValue("O&",
1472 MenuObj_New, outHandle);
1473 return _res;
1474}
1475
1476static PyObject *CtlObj_SetBevelButtonTransform(_self, _args)
1477 ControlObject *_self;
1478 PyObject *_args;
1479{
1480 PyObject *_res = NULL;
1481 OSErr _err;
1482 IconTransformType transform;
1483 if (!PyArg_ParseTuple(_args, "h",
1484 &transform))
1485 return NULL;
1486 _err = SetBevelButtonTransform(_self->ob_itself,
1487 transform);
1488 if (_err != noErr) return PyMac_Error(_err);
1489 Py_INCREF(Py_None);
1490 _res = Py_None;
1491 return _res;
1492}
1493
1494static PyObject *CtlObj_SetDisclosureTriangleLastValue(_self, _args)
1495 ControlObject *_self;
1496 PyObject *_args;
1497{
1498 PyObject *_res = NULL;
1499 OSErr _err;
1500 SInt16 inValue;
1501 if (!PyArg_ParseTuple(_args, "h",
1502 &inValue))
1503 return NULL;
1504 _err = SetDisclosureTriangleLastValue(_self->ob_itself,
1505 inValue);
1506 if (_err != noErr) return PyMac_Error(_err);
1507 Py_INCREF(Py_None);
1508 _res = Py_None;
1509 return _res;
1510}
1511
1512static PyObject *CtlObj_GetTabContentRect(_self, _args)
1513 ControlObject *_self;
1514 PyObject *_args;
1515{
1516 PyObject *_res = NULL;
1517 OSErr _err;
1518 Rect outContentRect;
1519 if (!PyArg_ParseTuple(_args, ""))
1520 return NULL;
1521 _err = GetTabContentRect(_self->ob_itself,
1522 &outContentRect);
1523 if (_err != noErr) return PyMac_Error(_err);
1524 _res = Py_BuildValue("O&",
1525 PyMac_BuildRect, &outContentRect);
1526 return _res;
1527}
1528
1529static PyObject *CtlObj_SetTabEnabled(_self, _args)
1530 ControlObject *_self;
1531 PyObject *_args;
1532{
1533 PyObject *_res = NULL;
1534 OSErr _err;
1535 SInt16 inTabToHilite;
1536 Boolean inEnabled;
1537 if (!PyArg_ParseTuple(_args, "hb",
1538 &inTabToHilite,
1539 &inEnabled))
1540 return NULL;
1541 _err = SetTabEnabled(_self->ob_itself,
1542 inTabToHilite,
1543 inEnabled);
1544 if (_err != noErr) return PyMac_Error(_err);
1545 Py_INCREF(Py_None);
1546 _res = Py_None;
1547 return _res;
1548}
1549
1550static PyObject *CtlObj_SetImageWellTransform(_self, _args)
1551 ControlObject *_self;
1552 PyObject *_args;
1553{
1554 PyObject *_res = NULL;
1555 OSErr _err;
1556 IconTransformType inTransform;
1557 if (!PyArg_ParseTuple(_args, "h",
1558 &inTransform))
1559 return NULL;
1560 _err = SetImageWellTransform(_self->ob_itself,
1561 inTransform);
1562 if (_err != noErr) return PyMac_Error(_err);
1563 Py_INCREF(Py_None);
1564 _res = Py_None;
1565 return _res;
1566}
1567
Jack Jansen5d56f4b1995-06-18 20:16:33 +00001568static PyObject *CtlObj_as_Resource(_self, _args)
1569 ControlObject *_self;
1570 PyObject *_args;
1571{
1572 PyObject *_res = NULL;
Jack Jansena1a0fef1999-12-23 14:32:06 +00001573 Handle _rv;
1574 if (!PyArg_ParseTuple(_args, ""))
1575 return NULL;
1576 _rv = as_Resource(_self->ob_itself);
1577 _res = Py_BuildValue("O&",
1578 ResObj_New, _rv);
1579 return _res;
Jack Jansen5d56f4b1995-06-18 20:16:33 +00001580}
1581
Jack Jansen1a7d5b12000-03-21 16:25:23 +00001582static PyObject *CtlObj_GetControlRect(_self, _args)
1583 ControlObject *_self;
1584 PyObject *_args;
1585{
1586 PyObject *_res = NULL;
1587 Rect rect;
1588 if (!PyArg_ParseTuple(_args, ""))
1589 return NULL;
1590 GetControlRect(_self->ob_itself,
1591 &rect);
1592 _res = Py_BuildValue("O&",
1593 PyMac_BuildRect, &rect);
1594 return _res;
1595}
1596
Jack Jansencfb60ee1996-10-01 10:46:46 +00001597static PyObject *CtlObj_DisposeControl(_self, _args)
1598 ControlObject *_self;
1599 PyObject *_args;
1600{
1601 PyObject *_res = NULL;
1602
1603 if (!PyArg_ParseTuple(_args, ""))
1604 return NULL;
1605 if ( _self->ob_itself ) {
Jack Jansen85ae4a81997-04-08 15:26:03 +00001606 SetControlReference(_self->ob_itself, (long)0); /* Make it forget about us */
Jack Jansencfb60ee1996-10-01 10:46:46 +00001607 DisposeControl(_self->ob_itself);
1608 _self->ob_itself = NULL;
1609 }
1610 Py_INCREF(Py_None);
1611 _res = Py_None;
1612 return _res;
1613
1614}
1615
Jack Jansen848250c1998-05-28 14:20:09 +00001616static PyObject *CtlObj_TrackControl(_self, _args)
1617 ControlObject *_self;
1618 PyObject *_args;
1619{
1620 PyObject *_res = NULL;
1621
1622 ControlPartCode _rv;
1623 Point startPoint;
1624 ControlActionUPP upp = 0;
1625 PyObject *callback = 0;
1626
1627 if (!PyArg_ParseTuple(_args, "O&|O",
1628 PyMac_GetPoint, &startPoint, &callback))
1629 return NULL;
1630 if (callback && callback != Py_None) {
1631 if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
1632 upp = (ControlActionUPP)-1;
1633 else {
1634 settrackfunc(callback);
1635 upp = mytracker_upp;
1636 }
1637 }
1638 _rv = TrackControl(_self->ob_itself,
1639 startPoint,
1640 upp);
1641 clrtrackfunc();
1642 _res = Py_BuildValue("h",
1643 _rv);
1644 return _res;
1645
1646}
1647
Jack Jansen24c35311999-12-09 22:49:51 +00001648static PyObject *CtlObj_HandleControlClick(_self, _args)
1649 ControlObject *_self;
1650 PyObject *_args;
1651{
1652 PyObject *_res = NULL;
1653
1654 ControlPartCode _rv;
1655 Point startPoint;
1656 SInt16 modifiers;
1657 ControlActionUPP upp = 0;
1658 PyObject *callback = 0;
1659
1660 if (!PyArg_ParseTuple(_args, "O&h|O",
1661 PyMac_GetPoint, &startPoint,
1662 &modifiers,
1663 &callback))
1664 return NULL;
1665 if (callback && callback != Py_None) {
1666 if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
1667 upp = (ControlActionUPP)-1;
1668 else {
1669 settrackfunc(callback);
1670 upp = mytracker_upp;
1671 }
1672 }
1673 _rv = HandleControlClick(_self->ob_itself,
1674 startPoint,
1675 modifiers,
1676 upp);
1677 clrtrackfunc();
1678 _res = Py_BuildValue("h",
1679 _rv);
1680 return _res;
1681
1682}
1683
1684static PyObject *CtlObj_SetControlData(_self, _args)
1685 ControlObject *_self;
1686 PyObject *_args;
1687{
1688 PyObject *_res = NULL;
1689
1690 OSErr _err;
1691 ControlPartCode inPart;
1692 ResType inTagName;
1693 Size bufferSize;
1694 Ptr buffer;
1695
1696 if (!PyArg_ParseTuple(_args, "hO&s#",
1697 &inPart,
1698 PyMac_GetOSType, &inTagName,
1699 &buffer, &bufferSize))
1700 return NULL;
1701
1702 _err = SetControlData(_self->ob_itself,
1703 inPart,
1704 inTagName,
1705 bufferSize,
1706 buffer);
1707
1708 if (_err != noErr)
1709 return PyMac_Error(_err);
1710 _res = Py_None;
1711 return _res;
1712
1713}
1714
1715static PyObject *CtlObj_GetControlData(_self, _args)
1716 ControlObject *_self;
1717 PyObject *_args;
1718{
1719 PyObject *_res = NULL;
1720
1721 OSErr _err;
1722 ControlPartCode inPart;
1723 ResType inTagName;
1724 Size bufferSize;
1725 Ptr buffer;
1726 Size outSize;
1727
1728 if (!PyArg_ParseTuple(_args, "hO&",
1729 &inPart,
1730 PyMac_GetOSType, &inTagName))
1731 return NULL;
1732
1733 /* allocate a buffer for the data */
1734 _err = GetControlDataSize(_self->ob_itself,
1735 inPart,
1736 inTagName,
1737 &bufferSize);
1738 if (_err != noErr)
1739 return PyMac_Error(_err);
1740 buffer = PyMem_NEW(char, bufferSize);
1741 if (buffer == NULL)
1742 return PyErr_NoMemory();
1743
1744 _err = GetControlData(_self->ob_itself,
1745 inPart,
1746 inTagName,
1747 bufferSize,
1748 buffer,
1749 &outSize);
1750
1751 if (_err != noErr) {
1752 PyMem_DEL(buffer);
1753 return PyMac_Error(_err);
1754 }
1755 _res = Py_BuildValue("s#", buffer, outSize);
1756 PyMem_DEL(buffer);
1757 return _res;
1758
1759}
1760
Jack Jansen1f9249c1999-12-19 00:05:50 +00001761static PyObject *CtlObj_SetControlDataHandle(_self, _args)
1762 ControlObject *_self;
1763 PyObject *_args;
1764{
1765 PyObject *_res = NULL;
1766
1767 OSErr _err;
1768 ControlPartCode inPart;
1769 ResType inTagName;
1770 Handle buffer;
1771
1772 if (!PyArg_ParseTuple(_args, "hO&O&",
1773 &inPart,
1774 PyMac_GetOSType, &inTagName,
Jack Jansenb9247d31999-12-23 23:06:07 +00001775 OptResObj_Convert, &buffer))
Jack Jansen1f9249c1999-12-19 00:05:50 +00001776 return NULL;
1777
1778 _err = SetControlData(_self->ob_itself,
1779 inPart,
1780 inTagName,
1781 sizeof(buffer),
Jack Jansenf7ac1d31999-12-29 12:37:22 +00001782 (Ptr)&buffer);
Jack Jansen1f9249c1999-12-19 00:05:50 +00001783
1784 if (_err != noErr)
1785 return PyMac_Error(_err);
1786 _res = Py_None;
1787 return _res;
1788
1789}
1790
1791static PyObject *CtlObj_GetControlDataHandle(_self, _args)
1792 ControlObject *_self;
1793 PyObject *_args;
1794{
1795 PyObject *_res = NULL;
1796
1797 OSErr _err;
1798 ControlPartCode inPart;
1799 ResType inTagName;
1800 Size bufferSize;
1801 Handle hdl;
1802
1803 if (!PyArg_ParseTuple(_args, "hO&",
1804 &inPart,
1805 PyMac_GetOSType, &inTagName))
1806 return NULL;
1807
1808 /* Check it is handle-sized */
1809 _err = GetControlDataSize(_self->ob_itself,
1810 inPart,
1811 inTagName,
1812 &bufferSize);
1813 if (_err != noErr)
1814 return PyMac_Error(_err);
1815 if (bufferSize != sizeof(Handle)) {
1816 PyErr_SetString(Ctl_Error, "GetControlDataSize() != sizeof(Handle)");
1817 return NULL;
1818 }
1819
1820 _err = GetControlData(_self->ob_itself,
1821 inPart,
1822 inTagName,
1823 sizeof(Handle),
1824 (Ptr)&hdl,
1825 &bufferSize);
1826
1827 if (_err != noErr) {
1828 return PyMac_Error(_err);
1829 }
1830 return Py_BuildValue("O&", OptResObj_New, hdl);
1831
1832}
1833
Jack Jansen74a1e632000-07-14 22:37:27 +00001834#if !TARGET_API_MAC_CARBON_NOTYET
Jack Jansene79dc762000-06-02 21:35:07 +00001835
Jack Jansenabc411b2000-03-20 16:09:09 +00001836static PyObject *CtlObj_SetControlDataCallback(_self, _args)
1837 ControlObject *_self;
1838 PyObject *_args;
1839{
1840 PyObject *_res = NULL;
1841
1842 OSErr _err;
1843 ControlPartCode inPart;
1844 ResType inTagName;
1845 PyObject *callback;
Jack Jansen85152b92000-07-11 21:12:55 +00001846 UniversalProcPtr c_callback;
Jack Jansenabc411b2000-03-20 16:09:09 +00001847
1848 if (!PyArg_ParseTuple(_args, "hO&O",
1849 &inPart,
1850 PyMac_GetOSType, &inTagName,
1851 &callback))
1852 return NULL;
1853
Jack Jansen85152b92000-07-11 21:12:55 +00001854 if ( setcallback((PyObject *)_self, inTagName, callback, &c_callback) < 0 )
Jack Jansenabc411b2000-03-20 16:09:09 +00001855 return NULL;
1856 _err = SetControlData(_self->ob_itself,
1857 inPart,
1858 inTagName,
1859 sizeof(c_callback),
1860 (Ptr)&c_callback);
1861
1862 if (_err != noErr)
1863 return PyMac_Error(_err);
1864 _res = Py_None;
1865 return _res;
1866
1867}
Jack Jansene79dc762000-06-02 21:35:07 +00001868#endif
1869
Jack Jansen74a1e632000-07-14 22:37:27 +00001870#if !TARGET_API_MAC_CARBON_NOTYET
Jack Jansenabc411b2000-03-20 16:09:09 +00001871
Jack Jansen4c704131998-06-19 13:35:14 +00001872static PyObject *CtlObj_GetPopupData(_self, _args)
1873 ControlObject *_self;
1874 PyObject *_args;
1875{
1876 PyObject *_res = NULL;
1877
1878 PopupPrivateDataHandle hdl;
1879
1880 if ( (*_self->ob_itself)->contrlData == NULL ) {
1881 PyErr_SetString(Ctl_Error, "No contrlData handle in control");
1882 return 0;
1883 }
1884 hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
1885 HLock((Handle)hdl);
1886 _res = Py_BuildValue("O&i", MenuObj_New, (*hdl)->mHandle, (int)(*hdl)->mID);
1887 HUnlock((Handle)hdl);
1888 return _res;
1889
1890}
Jack Jansene79dc762000-06-02 21:35:07 +00001891#endif
1892
Jack Jansen74a1e632000-07-14 22:37:27 +00001893#if !TARGET_API_MAC_CARBON_NOTYET
Jack Jansen4c704131998-06-19 13:35:14 +00001894
1895static PyObject *CtlObj_SetPopupData(_self, _args)
1896 ControlObject *_self;
1897 PyObject *_args;
1898{
1899 PyObject *_res = NULL;
1900
1901 PopupPrivateDataHandle hdl;
1902 MenuHandle mHandle;
1903 short mID;
1904
1905 if (!PyArg_ParseTuple(_args, "O&h", MenuObj_Convert, &mHandle, &mID) )
1906 return 0;
1907 if ( (*_self->ob_itself)->contrlData == NULL ) {
1908 PyErr_SetString(Ctl_Error, "No contrlData handle in control");
1909 return 0;
1910 }
1911 hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
1912 (*hdl)->mHandle = mHandle;
1913 (*hdl)->mID = mID;
1914 Py_INCREF(Py_None);
1915 return Py_None;
1916
1917}
Jack Jansene79dc762000-06-02 21:35:07 +00001918#endif
Jack Jansen4c704131998-06-19 13:35:14 +00001919
Guido van Rossum17448e21995-01-30 11:53:55 +00001920static PyMethodDef CtlObj_methods[] = {
Jack Jansen21f96871998-02-20 16:02:09 +00001921 {"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1,
1922 "(ControlPartCode hiliteState) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001923 {"ShowControl", (PyCFunction)CtlObj_ShowControl, 1,
1924 "() -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001925 {"HideControl", (PyCFunction)CtlObj_HideControl, 1,
1926 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001927 {"IsControlActive", (PyCFunction)CtlObj_IsControlActive, 1,
1928 "() -> (Boolean _rv)"},
1929 {"IsControlVisible", (PyCFunction)CtlObj_IsControlVisible, 1,
1930 "() -> (Boolean _rv)"},
1931 {"ActivateControl", (PyCFunction)CtlObj_ActivateControl, 1,
1932 "() -> None"},
1933 {"DeactivateControl", (PyCFunction)CtlObj_DeactivateControl, 1,
1934 "() -> None"},
1935 {"SetControlVisibility", (PyCFunction)CtlObj_SetControlVisibility, 1,
1936 "(Boolean inIsVisible, Boolean inDoDraw) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001937 {"Draw1Control", (PyCFunction)CtlObj_Draw1Control, 1,
1938 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001939 {"GetBestControlRect", (PyCFunction)CtlObj_GetBestControlRect, 1,
1940 "() -> (Rect outRect, SInt16 outBaseLineOffset)"},
1941 {"SetControlFontStyle", (PyCFunction)CtlObj_SetControlFontStyle, 1,
1942 "(ControlFontStyleRec inStyle) -> None"},
1943 {"DrawControlInCurrentPort", (PyCFunction)CtlObj_DrawControlInCurrentPort, 1,
1944 "() -> None"},
1945 {"SetUpControlBackground", (PyCFunction)CtlObj_SetUpControlBackground, 1,
1946 "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +00001947 {"SetUpControlTextColor", (PyCFunction)CtlObj_SetUpControlTextColor, 1,
1948 "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001949 {"DragControl", (PyCFunction)CtlObj_DragControl, 1,
Jack Jansen754d4a41995-11-14 10:41:55 +00001950 "(Point startPoint, Rect limitRect, Rect slopRect, DragConstraint axis) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001951 {"TestControl", (PyCFunction)CtlObj_TestControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001952 "(Point testPoint) -> (ControlPartCode _rv)"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001953
1954#if TARGET_API_MAC_CARBON
1955 {"HandleControlContextualMenuClick", (PyCFunction)CtlObj_HandleControlContextualMenuClick, 1,
1956 "(Point inWhere) -> (Boolean menuDisplayed)"},
1957#endif
1958
1959#if TARGET_API_MAC_CARBON
1960 {"GetControlClickActivation", (PyCFunction)CtlObj_GetControlClickActivation, 1,
1961 "(Point inWhere, EventModifiers inModifiers) -> (ClickActivationResult outResult)"},
1962#endif
Jack Jansen21f96871998-02-20 16:02:09 +00001963 {"HandleControlKey", (PyCFunction)CtlObj_HandleControlKey, 1,
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001964 "(SInt16 inKeyCode, SInt16 inCharCode, EventModifiers inModifiers) -> (SInt16 _rv)"},
1965
1966#if TARGET_API_MAC_CARBON
1967 {"HandleControlSetCursor", (PyCFunction)CtlObj_HandleControlSetCursor, 1,
1968 "(Point localPoint, EventModifiers modifiers) -> (Boolean cursorWasSet)"},
1969#endif
Guido van Rossum17448e21995-01-30 11:53:55 +00001970 {"MoveControl", (PyCFunction)CtlObj_MoveControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001971 "(SInt16 h, SInt16 v) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001972 {"SizeControl", (PyCFunction)CtlObj_SizeControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001973 "(SInt16 w, SInt16 h) -> None"},
1974 {"SetControlTitle", (PyCFunction)CtlObj_SetControlTitle, 1,
1975 "(Str255 title) -> None"},
1976 {"GetControlTitle", (PyCFunction)CtlObj_GetControlTitle, 1,
Jack Jansen41009001999-03-07 20:05:20 +00001977 "() -> (Str255 title)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001978 {"GetControlValue", (PyCFunction)CtlObj_GetControlValue, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001979 "() -> (SInt16 _rv)"},
1980 {"SetControlValue", (PyCFunction)CtlObj_SetControlValue, 1,
1981 "(SInt16 newValue) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001982 {"GetControlMinimum", (PyCFunction)CtlObj_GetControlMinimum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001983 "() -> (SInt16 _rv)"},
1984 {"SetControlMinimum", (PyCFunction)CtlObj_SetControlMinimum, 1,
1985 "(SInt16 newMinimum) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001986 {"GetControlMaximum", (PyCFunction)CtlObj_GetControlMaximum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001987 "() -> (SInt16 _rv)"},
1988 {"SetControlMaximum", (PyCFunction)CtlObj_SetControlMaximum, 1,
1989 "(SInt16 newMaximum) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +00001990 {"GetControlViewSize", (PyCFunction)CtlObj_GetControlViewSize, 1,
1991 "() -> (SInt32 _rv)"},
1992 {"SetControlViewSize", (PyCFunction)CtlObj_SetControlViewSize, 1,
1993 "(SInt32 newViewSize) -> None"},
1994 {"GetControl32BitValue", (PyCFunction)CtlObj_GetControl32BitValue, 1,
1995 "() -> (SInt32 _rv)"},
1996 {"SetControl32BitValue", (PyCFunction)CtlObj_SetControl32BitValue, 1,
1997 "(SInt32 newValue) -> None"},
1998 {"GetControl32BitMaximum", (PyCFunction)CtlObj_GetControl32BitMaximum, 1,
1999 "() -> (SInt32 _rv)"},
2000 {"SetControl32BitMaximum", (PyCFunction)CtlObj_SetControl32BitMaximum, 1,
2001 "(SInt32 newMaximum) -> None"},
2002 {"GetControl32BitMinimum", (PyCFunction)CtlObj_GetControl32BitMinimum, 1,
2003 "() -> (SInt32 _rv)"},
2004 {"SetControl32BitMinimum", (PyCFunction)CtlObj_SetControl32BitMinimum, 1,
2005 "(SInt32 newMinimum) -> None"},
2006 {"IsValidControlHandle", (PyCFunction)CtlObj_IsValidControlHandle, 1,
2007 "() -> (Boolean _rv)"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002008
2009#if TARGET_API_MAC_CARBON
2010 {"SetControlID", (PyCFunction)CtlObj_SetControlID, 1,
2011 "(ControlID inID) -> None"},
2012#endif
2013
2014#if TARGET_API_MAC_CARBON
2015 {"GetControlID", (PyCFunction)CtlObj_GetControlID, 1,
2016 "() -> (ControlID outID)"},
2017#endif
Jack Jansena05ac601999-12-12 21:41:51 +00002018 {"RemoveControlProperty", (PyCFunction)CtlObj_RemoveControlProperty, 1,
Jack Jansene79dc762000-06-02 21:35:07 +00002019 "(OSType propertyCreator, OSType propertyTag) -> None"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002020
2021#if TARGET_API_MAC_CARBON
2022 {"GetControlPropertyAttributes", (PyCFunction)CtlObj_GetControlPropertyAttributes, 1,
2023 "(OSType propertyCreator, OSType propertyTag) -> (UInt32 attributes)"},
2024#endif
2025
2026#if TARGET_API_MAC_CARBON
2027 {"ChangeControlPropertyAttributes", (PyCFunction)CtlObj_ChangeControlPropertyAttributes, 1,
2028 "(OSType propertyCreator, OSType propertyTag, UInt32 attributesToSet, UInt32 attributesToClear) -> None"},
2029#endif
Jack Jansena05ac601999-12-12 21:41:51 +00002030 {"GetControlRegion", (PyCFunction)CtlObj_GetControlRegion, 1,
Jack Jansene79dc762000-06-02 21:35:07 +00002031 "(ControlPartCode inPart, RgnHandle outRegion) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00002032 {"GetControlVariant", (PyCFunction)CtlObj_GetControlVariant, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00002033 "() -> (ControlVariant _rv)"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00002034 {"SetControlReference", (PyCFunction)CtlObj_SetControlReference, 1,
2035 "(SInt32 data) -> None"},
2036 {"GetControlReference", (PyCFunction)CtlObj_GetControlReference, 1,
2037 "() -> (SInt32 _rv)"},
Jack Jansene79dc762000-06-02 21:35:07 +00002038
Jack Jansen74a1e632000-07-14 22:37:27 +00002039#if !TARGET_API_MAC_CARBON
Jack Jansenc7fefed1997-08-15 14:32:18 +00002040 {"GetAuxiliaryControlRecord", (PyCFunction)CtlObj_GetAuxiliaryControlRecord, 1,
2041 "() -> (Boolean _rv, AuxCtlHandle acHndl)"},
Jack Jansene79dc762000-06-02 21:35:07 +00002042#endif
2043
Jack Jansen74a1e632000-07-14 22:37:27 +00002044#if !TARGET_API_MAC_CARBON
Jack Jansenc7fefed1997-08-15 14:32:18 +00002045 {"SetControlColor", (PyCFunction)CtlObj_SetControlColor, 1,
2046 "(CCTabHandle newColorTable) -> None"},
Jack Jansene79dc762000-06-02 21:35:07 +00002047#endif
Jack Jansen21f96871998-02-20 16:02:09 +00002048 {"SendControlMessage", (PyCFunction)CtlObj_SendControlMessage, 1,
2049 "(SInt16 inMessage, SInt32 inParam) -> (SInt32 _rv)"},
2050 {"EmbedControl", (PyCFunction)CtlObj_EmbedControl, 1,
2051 "(ControlHandle inContainer) -> None"},
2052 {"AutoEmbedControl", (PyCFunction)CtlObj_AutoEmbedControl, 1,
2053 "(WindowPtr inWindow) -> None"},
2054 {"GetSuperControl", (PyCFunction)CtlObj_GetSuperControl, 1,
2055 "() -> (ControlHandle outParent)"},
2056 {"CountSubControls", (PyCFunction)CtlObj_CountSubControls, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00002057 "() -> (UInt16 outNumChildren)"},
Jack Jansen21f96871998-02-20 16:02:09 +00002058 {"GetIndexedSubControl", (PyCFunction)CtlObj_GetIndexedSubControl, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00002059 "(UInt16 inIndex) -> (ControlHandle outSubControl)"},
Jack Jansen21f96871998-02-20 16:02:09 +00002060 {"SetControlSupervisor", (PyCFunction)CtlObj_SetControlSupervisor, 1,
2061 "(ControlHandle inBoss) -> None"},
2062 {"GetControlFeatures", (PyCFunction)CtlObj_GetControlFeatures, 1,
2063 "() -> (UInt32 outFeatures)"},
2064 {"GetControlDataSize", (PyCFunction)CtlObj_GetControlDataSize, 1,
2065 "(ControlPartCode inPart, ResType inTagName) -> (Size outMaxSize)"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002066
2067#if TARGET_API_MAC_CARBON
2068 {"SetControlDragTrackingEnabled", (PyCFunction)CtlObj_SetControlDragTrackingEnabled, 1,
2069 "(Boolean tracks) -> None"},
2070#endif
2071
2072#if TARGET_API_MAC_CARBON
2073 {"IsControlDragTrackingEnabled", (PyCFunction)CtlObj_IsControlDragTrackingEnabled, 1,
2074 "() -> (Boolean tracks)"},
2075#endif
2076
2077#if ACCESSOR_CALLS_ARE_FUNCTIONS
2078 {"GetControlBounds", (PyCFunction)CtlObj_GetControlBounds, 1,
2079 "() -> (Rect _rv, Rect bounds)"},
2080#endif
2081
2082#if ACCESSOR_CALLS_ARE_FUNCTIONS
2083 {"IsControlHilited", (PyCFunction)CtlObj_IsControlHilited, 1,
2084 "() -> (Boolean _rv)"},
2085#endif
2086
2087#if ACCESSOR_CALLS_ARE_FUNCTIONS
2088 {"GetControlHilite", (PyCFunction)CtlObj_GetControlHilite, 1,
2089 "() -> (UInt16 _rv)"},
2090#endif
2091
2092#if ACCESSOR_CALLS_ARE_FUNCTIONS
2093 {"GetControlOwner", (PyCFunction)CtlObj_GetControlOwner, 1,
2094 "() -> (WindowPtr _rv)"},
2095#endif
2096
2097#if ACCESSOR_CALLS_ARE_FUNCTIONS
2098 {"GetControlDataHandle", (PyCFunction)CtlObj_GetControlDataHandle, 1,
2099 "() -> (Handle _rv)"},
2100#endif
2101
2102#if ACCESSOR_CALLS_ARE_FUNCTIONS
2103 {"GetControlPopupMenuHandle", (PyCFunction)CtlObj_GetControlPopupMenuHandle, 1,
2104 "() -> (MenuHandle _rv)"},
2105#endif
2106
2107#if ACCESSOR_CALLS_ARE_FUNCTIONS
2108 {"GetControlPopupMenuID", (PyCFunction)CtlObj_GetControlPopupMenuID, 1,
2109 "() -> (short _rv)"},
2110#endif
2111
2112#if ACCESSOR_CALLS_ARE_FUNCTIONS
2113 {"SetControlDataHandle", (PyCFunction)CtlObj_SetControlDataHandle, 1,
2114 "(Handle dataHandle) -> None"},
2115#endif
2116
2117#if ACCESSOR_CALLS_ARE_FUNCTIONS
2118 {"SetControlBounds", (PyCFunction)CtlObj_SetControlBounds, 1,
2119 "(Rect bounds) -> None"},
2120#endif
2121
2122#if ACCESSOR_CALLS_ARE_FUNCTIONS
2123 {"SetControlPopupMenuHandle", (PyCFunction)CtlObj_SetControlPopupMenuHandle, 1,
2124 "(MenuHandle popupMenu) -> None"},
2125#endif
2126
2127#if ACCESSOR_CALLS_ARE_FUNCTIONS
2128 {"SetControlPopupMenuID", (PyCFunction)CtlObj_SetControlPopupMenuID, 1,
2129 "(short menuID) -> None"},
2130#endif
2131 {"GetBevelButtonMenuValue", (PyCFunction)CtlObj_GetBevelButtonMenuValue, 1,
2132 "() -> (SInt16 outValue)"},
2133 {"SetBevelButtonMenuValue", (PyCFunction)CtlObj_SetBevelButtonMenuValue, 1,
2134 "(SInt16 inValue) -> None"},
2135 {"GetBevelButtonMenuHandle", (PyCFunction)CtlObj_GetBevelButtonMenuHandle, 1,
2136 "() -> (MenuHandle outHandle)"},
2137 {"SetBevelButtonTransform", (PyCFunction)CtlObj_SetBevelButtonTransform, 1,
2138 "(IconTransformType transform) -> None"},
2139 {"SetDisclosureTriangleLastValue", (PyCFunction)CtlObj_SetDisclosureTriangleLastValue, 1,
2140 "(SInt16 inValue) -> None"},
2141 {"GetTabContentRect", (PyCFunction)CtlObj_GetTabContentRect, 1,
2142 "() -> (Rect outContentRect)"},
2143 {"SetTabEnabled", (PyCFunction)CtlObj_SetTabEnabled, 1,
2144 "(SInt16 inTabToHilite, Boolean inEnabled) -> None"},
2145 {"SetImageWellTransform", (PyCFunction)CtlObj_SetImageWellTransform, 1,
2146 "(IconTransformType inTransform) -> None"},
Jack Jansen5d56f4b1995-06-18 20:16:33 +00002147 {"as_Resource", (PyCFunction)CtlObj_as_Resource, 1,
Jack Jansena1a0fef1999-12-23 14:32:06 +00002148 "() -> (Handle _rv)"},
Jack Jansen1a7d5b12000-03-21 16:25:23 +00002149 {"GetControlRect", (PyCFunction)CtlObj_GetControlRect, 1,
2150 "() -> (Rect rect)"},
Jack Jansencfb60ee1996-10-01 10:46:46 +00002151 {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1,
2152 "() -> None"},
Jack Jansen848250c1998-05-28 14:20:09 +00002153 {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00002154 "(Point startPoint [,trackercallback]) -> (ControlPartCode _rv)"},
2155 {"HandleControlClick", (PyCFunction)CtlObj_HandleControlClick, 1,
2156 "(Point startPoint, Integer modifiers, [,trackercallback]) -> (ControlPartCode _rv)"},
2157 {"SetControlData", (PyCFunction)CtlObj_SetControlData, 1,
2158 "(stuff) -> None"},
2159 {"GetControlData", (PyCFunction)CtlObj_GetControlData, 1,
2160 "(part, type) -> String"},
Jack Jansen1f9249c1999-12-19 00:05:50 +00002161 {"SetControlDataHandle", (PyCFunction)CtlObj_SetControlDataHandle, 1,
2162 "(ResObj) -> None"},
2163 {"GetControlDataHandle", (PyCFunction)CtlObj_GetControlDataHandle, 1,
2164 "(part, type) -> ResObj"},
Jack Jansene79dc762000-06-02 21:35:07 +00002165
Jack Jansen74a1e632000-07-14 22:37:27 +00002166#if !TARGET_API_MAC_CARBON_NOTYET
Jack Jansenabc411b2000-03-20 16:09:09 +00002167 {"SetControlDataCallback", (PyCFunction)CtlObj_SetControlDataCallback, 1,
2168 "(callbackfunc) -> None"},
Jack Jansene79dc762000-06-02 21:35:07 +00002169#endif
2170
Jack Jansen74a1e632000-07-14 22:37:27 +00002171#if !TARGET_API_MAC_CARBON_NOTYET
Jack Jansen4c704131998-06-19 13:35:14 +00002172 {"GetPopupData", (PyCFunction)CtlObj_GetPopupData, 1,
2173 NULL},
Jack Jansene79dc762000-06-02 21:35:07 +00002174#endif
2175
Jack Jansen74a1e632000-07-14 22:37:27 +00002176#if !TARGET_API_MAC_CARBON_NOTYET
Jack Jansen4c704131998-06-19 13:35:14 +00002177 {"SetPopupData", (PyCFunction)CtlObj_SetPopupData, 1,
2178 NULL},
Jack Jansene79dc762000-06-02 21:35:07 +00002179#endif
Guido van Rossum17448e21995-01-30 11:53:55 +00002180 {NULL, NULL, 0}
2181};
2182
2183PyMethodChain CtlObj_chain = { CtlObj_methods, NULL };
2184
2185static PyObject *CtlObj_getattr(self, name)
2186 ControlObject *self;
2187 char *name;
2188{
2189 return Py_FindMethodInChain(&CtlObj_chain, (PyObject *)self, name);
2190}
2191
2192#define CtlObj_setattr NULL
2193
Jack Jansen8387af61999-03-13 23:07:32 +00002194static int CtlObj_compare(self, other)
2195 ControlObject *self, *other;
2196{
2197 unsigned long v, w;
2198
2199 if (!CtlObj_Check((PyObject *)other))
2200 {
2201 v=(unsigned long)self;
2202 w=(unsigned long)other;
2203 }
2204 else
2205 {
2206 v=(unsigned long)self->ob_itself;
2207 w=(unsigned long)other->ob_itself;
2208 }
2209 if( v < w ) return -1;
2210 if( v > w ) return 1;
2211 return 0;
2212}
2213
2214#define CtlObj_repr NULL
2215
2216static long CtlObj_hash(self)
2217 ControlObject *self;
2218{
2219 return (long)self->ob_itself;
2220}
2221
Guido van Rossum17448e21995-01-30 11:53:55 +00002222PyTypeObject Control_Type = {
2223 PyObject_HEAD_INIT(&PyType_Type)
2224 0, /*ob_size*/
2225 "Control", /*tp_name*/
2226 sizeof(ControlObject), /*tp_basicsize*/
2227 0, /*tp_itemsize*/
2228 /* methods */
2229 (destructor) CtlObj_dealloc, /*tp_dealloc*/
2230 0, /*tp_print*/
2231 (getattrfunc) CtlObj_getattr, /*tp_getattr*/
2232 (setattrfunc) CtlObj_setattr, /*tp_setattr*/
Jack Jansen8387af61999-03-13 23:07:32 +00002233 (cmpfunc) CtlObj_compare, /*tp_compare*/
2234 (reprfunc) CtlObj_repr, /*tp_repr*/
2235 (PyNumberMethods *)0, /* tp_as_number */
2236 (PySequenceMethods *)0, /* tp_as_sequence */
2237 (PyMappingMethods *)0, /* tp_as_mapping */
2238 (hashfunc) CtlObj_hash, /*tp_hash*/
Guido van Rossum17448e21995-01-30 11:53:55 +00002239};
2240
2241/* -------------------- End object type Control --------------------- */
2242
2243
2244static PyObject *Ctl_NewControl(_self, _args)
2245 PyObject *_self;
2246 PyObject *_args;
2247{
2248 PyObject *_res = NULL;
2249 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00002250 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00002251 Rect boundsRect;
Jack Jansen21f96871998-02-20 16:02:09 +00002252 Str255 controlTitle;
2253 Boolean initiallyVisible;
2254 SInt16 initialValue;
2255 SInt16 minimumValue;
2256 SInt16 maximumValue;
Jack Jansen7d0bc831995-06-09 20:56:31 +00002257 SInt16 procID;
Jack Jansen21f96871998-02-20 16:02:09 +00002258 SInt32 controlReference;
Guido van Rossum17448e21995-01-30 11:53:55 +00002259 if (!PyArg_ParseTuple(_args, "O&O&O&bhhhhl",
Jack Jansen21f96871998-02-20 16:02:09 +00002260 WinObj_Convert, &owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00002261 PyMac_GetRect, &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00002262 PyMac_GetStr255, controlTitle,
2263 &initiallyVisible,
2264 &initialValue,
2265 &minimumValue,
2266 &maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00002267 &procID,
Jack Jansen21f96871998-02-20 16:02:09 +00002268 &controlReference))
Guido van Rossum17448e21995-01-30 11:53:55 +00002269 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00002270 _rv = NewControl(owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00002271 &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00002272 controlTitle,
2273 initiallyVisible,
2274 initialValue,
2275 minimumValue,
2276 maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00002277 procID,
Jack Jansen21f96871998-02-20 16:02:09 +00002278 controlReference);
Guido van Rossum17448e21995-01-30 11:53:55 +00002279 _res = Py_BuildValue("O&",
2280 CtlObj_New, _rv);
2281 return _res;
2282}
2283
2284static PyObject *Ctl_GetNewControl(_self, _args)
2285 PyObject *_self;
2286 PyObject *_args;
2287{
2288 PyObject *_res = NULL;
2289 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00002290 SInt16 resourceID;
2291 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00002292 if (!PyArg_ParseTuple(_args, "hO&",
Jack Jansen21f96871998-02-20 16:02:09 +00002293 &resourceID,
2294 WinObj_Convert, &owningWindow))
Guido van Rossum17448e21995-01-30 11:53:55 +00002295 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00002296 _rv = GetNewControl(resourceID,
2297 owningWindow);
Guido van Rossum17448e21995-01-30 11:53:55 +00002298 _res = Py_BuildValue("O&",
2299 CtlObj_New, _rv);
2300 return _res;
2301}
2302
Guido van Rossum17448e21995-01-30 11:53:55 +00002303static PyObject *Ctl_DrawControls(_self, _args)
2304 PyObject *_self;
2305 PyObject *_args;
2306{
2307 PyObject *_res = NULL;
2308 WindowPtr theWindow;
2309 if (!PyArg_ParseTuple(_args, "O&",
2310 WinObj_Convert, &theWindow))
2311 return NULL;
2312 DrawControls(theWindow);
2313 Py_INCREF(Py_None);
2314 _res = Py_None;
2315 return _res;
2316}
2317
Guido van Rossum17448e21995-01-30 11:53:55 +00002318static PyObject *Ctl_UpdateControls(_self, _args)
2319 PyObject *_self;
2320 PyObject *_args;
2321{
2322 PyObject *_res = NULL;
2323 WindowPtr theWindow;
Jack Jansen2b724171996-04-10 14:48:19 +00002324 RgnHandle updateRegion;
2325 if (!PyArg_ParseTuple(_args, "O&O&",
2326 WinObj_Convert, &theWindow,
2327 ResObj_Convert, &updateRegion))
Guido van Rossum17448e21995-01-30 11:53:55 +00002328 return NULL;
2329 UpdateControls(theWindow,
Jack Jansen2b724171996-04-10 14:48:19 +00002330 updateRegion);
Guido van Rossum17448e21995-01-30 11:53:55 +00002331 Py_INCREF(Py_None);
2332 _res = Py_None;
2333 return _res;
2334}
2335
2336static PyObject *Ctl_FindControl(_self, _args)
2337 PyObject *_self;
2338 PyObject *_args;
2339{
2340 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +00002341 ControlPartCode _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00002342 Point testPoint;
Guido van Rossum17448e21995-01-30 11:53:55 +00002343 WindowPtr theWindow;
2344 ControlHandle theControl;
2345 if (!PyArg_ParseTuple(_args, "O&O&",
Jack Jansen21f96871998-02-20 16:02:09 +00002346 PyMac_GetPoint, &testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00002347 WinObj_Convert, &theWindow))
2348 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00002349 _rv = FindControl(testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00002350 theWindow,
2351 &theControl);
2352 _res = Py_BuildValue("hO&",
2353 _rv,
2354 CtlObj_WhichControl, theControl);
2355 return _res;
2356}
2357
Jack Jansen21f96871998-02-20 16:02:09 +00002358static PyObject *Ctl_FindControlUnderMouse(_self, _args)
2359 PyObject *_self;
2360 PyObject *_args;
2361{
2362 PyObject *_res = NULL;
2363 ControlHandle _rv;
2364 Point inWhere;
2365 WindowPtr inWindow;
2366 SInt16 outPart;
2367 if (!PyArg_ParseTuple(_args, "O&O&",
2368 PyMac_GetPoint, &inWhere,
2369 WinObj_Convert, &inWindow))
2370 return NULL;
2371 _rv = FindControlUnderMouse(inWhere,
2372 inWindow,
2373 &outPart);
2374 _res = Py_BuildValue("O&h",
2375 CtlObj_New, _rv,
2376 outPart);
2377 return _res;
2378}
2379
2380static PyObject *Ctl_IdleControls(_self, _args)
2381 PyObject *_self;
2382 PyObject *_args;
2383{
2384 PyObject *_res = NULL;
2385 WindowPtr inWindow;
2386 if (!PyArg_ParseTuple(_args, "O&",
2387 WinObj_Convert, &inWindow))
2388 return NULL;
2389 IdleControls(inWindow);
2390 Py_INCREF(Py_None);
2391 _res = Py_None;
2392 return _res;
2393}
2394
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002395#if TARGET_API_MAC_CARBON
2396
2397static PyObject *Ctl_GetControlByID(_self, _args)
2398 PyObject *_self;
2399 PyObject *_args;
2400{
2401 PyObject *_res = NULL;
2402 OSStatus _err;
2403 WindowPtr inWindow;
2404 ControlID inID;
2405 ControlHandle outControl;
2406 if (!PyArg_ParseTuple(_args, "O&O&",
2407 WinObj_Convert, &inWindow,
2408 PyControlID_Convert, &inID))
2409 return NULL;
2410 _err = GetControlByID(inWindow,
2411 &inID,
2412 &outControl);
2413 if (_err != noErr) return PyMac_Error(_err);
2414 _res = Py_BuildValue("O&",
2415 CtlObj_WhichControl, outControl);
2416 return _res;
2417}
2418#endif
2419
Jack Jansen21f96871998-02-20 16:02:09 +00002420static PyObject *Ctl_DumpControlHierarchy(_self, _args)
2421 PyObject *_self;
2422 PyObject *_args;
2423{
2424 PyObject *_res = NULL;
2425 OSErr _err;
2426 WindowPtr inWindow;
2427 FSSpec inDumpFile;
2428 if (!PyArg_ParseTuple(_args, "O&O&",
2429 WinObj_Convert, &inWindow,
2430 PyMac_GetFSSpec, &inDumpFile))
2431 return NULL;
2432 _err = DumpControlHierarchy(inWindow,
2433 &inDumpFile);
2434 if (_err != noErr) return PyMac_Error(_err);
2435 Py_INCREF(Py_None);
2436 _res = Py_None;
2437 return _res;
2438}
2439
2440static PyObject *Ctl_CreateRootControl(_self, _args)
2441 PyObject *_self;
2442 PyObject *_args;
2443{
2444 PyObject *_res = NULL;
2445 OSErr _err;
2446 WindowPtr inWindow;
2447 ControlHandle outControl;
2448 if (!PyArg_ParseTuple(_args, "O&",
2449 WinObj_Convert, &inWindow))
2450 return NULL;
2451 _err = CreateRootControl(inWindow,
2452 &outControl);
2453 if (_err != noErr) return PyMac_Error(_err);
2454 _res = Py_BuildValue("O&",
2455 CtlObj_WhichControl, outControl);
2456 return _res;
2457}
2458
2459static PyObject *Ctl_GetRootControl(_self, _args)
2460 PyObject *_self;
2461 PyObject *_args;
2462{
2463 PyObject *_res = NULL;
2464 OSErr _err;
2465 WindowPtr inWindow;
2466 ControlHandle outControl;
2467 if (!PyArg_ParseTuple(_args, "O&",
2468 WinObj_Convert, &inWindow))
2469 return NULL;
2470 _err = GetRootControl(inWindow,
2471 &outControl);
2472 if (_err != noErr) return PyMac_Error(_err);
2473 _res = Py_BuildValue("O&",
2474 CtlObj_WhichControl, outControl);
2475 return _res;
2476}
2477
2478static PyObject *Ctl_GetKeyboardFocus(_self, _args)
2479 PyObject *_self;
2480 PyObject *_args;
2481{
2482 PyObject *_res = NULL;
2483 OSErr _err;
2484 WindowPtr inWindow;
2485 ControlHandle outControl;
2486 if (!PyArg_ParseTuple(_args, "O&",
2487 WinObj_Convert, &inWindow))
2488 return NULL;
2489 _err = GetKeyboardFocus(inWindow,
2490 &outControl);
2491 if (_err != noErr) return PyMac_Error(_err);
2492 _res = Py_BuildValue("O&",
2493 CtlObj_WhichControl, outControl);
2494 return _res;
2495}
2496
2497static PyObject *Ctl_SetKeyboardFocus(_self, _args)
2498 PyObject *_self;
2499 PyObject *_args;
2500{
2501 PyObject *_res = NULL;
2502 OSErr _err;
2503 WindowPtr inWindow;
2504 ControlHandle inControl;
2505 ControlFocusPart inPart;
2506 if (!PyArg_ParseTuple(_args, "O&O&h",
2507 WinObj_Convert, &inWindow,
2508 CtlObj_Convert, &inControl,
2509 &inPart))
2510 return NULL;
2511 _err = SetKeyboardFocus(inWindow,
2512 inControl,
2513 inPart);
2514 if (_err != noErr) return PyMac_Error(_err);
2515 Py_INCREF(Py_None);
2516 _res = Py_None;
2517 return _res;
2518}
2519
2520static PyObject *Ctl_AdvanceKeyboardFocus(_self, _args)
2521 PyObject *_self;
2522 PyObject *_args;
2523{
2524 PyObject *_res = NULL;
2525 OSErr _err;
2526 WindowPtr inWindow;
2527 if (!PyArg_ParseTuple(_args, "O&",
2528 WinObj_Convert, &inWindow))
2529 return NULL;
2530 _err = AdvanceKeyboardFocus(inWindow);
2531 if (_err != noErr) return PyMac_Error(_err);
2532 Py_INCREF(Py_None);
2533 _res = Py_None;
2534 return _res;
2535}
2536
2537static PyObject *Ctl_ReverseKeyboardFocus(_self, _args)
2538 PyObject *_self;
2539 PyObject *_args;
2540{
2541 PyObject *_res = NULL;
2542 OSErr _err;
2543 WindowPtr inWindow;
2544 if (!PyArg_ParseTuple(_args, "O&",
2545 WinObj_Convert, &inWindow))
2546 return NULL;
2547 _err = ReverseKeyboardFocus(inWindow);
2548 if (_err != noErr) return PyMac_Error(_err);
2549 Py_INCREF(Py_None);
2550 _res = Py_None;
2551 return _res;
2552}
2553
2554static PyObject *Ctl_ClearKeyboardFocus(_self, _args)
2555 PyObject *_self;
2556 PyObject *_args;
2557{
2558 PyObject *_res = NULL;
2559 OSErr _err;
2560 WindowPtr inWindow;
2561 if (!PyArg_ParseTuple(_args, "O&",
2562 WinObj_Convert, &inWindow))
2563 return NULL;
2564 _err = ClearKeyboardFocus(inWindow);
2565 if (_err != noErr) return PyMac_Error(_err);
2566 Py_INCREF(Py_None);
2567 _res = Py_None;
2568 return _res;
2569}
2570
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002571#if TARGET_API_MAC_CARBON
2572
2573static PyObject *Ctl_SetAutomaticControlDragTrackingEnabledForWindow(_self, _args)
2574 PyObject *_self;
2575 PyObject *_args;
2576{
2577 PyObject *_res = NULL;
2578 OSStatus _err;
2579 WindowPtr theWindow;
2580 Boolean tracks;
2581 if (!PyArg_ParseTuple(_args, "O&b",
2582 WinObj_Convert, &theWindow,
2583 &tracks))
2584 return NULL;
2585 _err = SetAutomaticControlDragTrackingEnabledForWindow(theWindow,
2586 tracks);
2587 if (_err != noErr) return PyMac_Error(_err);
2588 Py_INCREF(Py_None);
2589 _res = Py_None;
2590 return _res;
2591}
2592#endif
2593
2594#if TARGET_API_MAC_CARBON
2595
2596static PyObject *Ctl_IsAutomaticControlDragTrackingEnabledForWindow(_self, _args)
2597 PyObject *_self;
2598 PyObject *_args;
2599{
2600 PyObject *_res = NULL;
2601 OSStatus _err;
2602 WindowPtr theWindow;
2603 Boolean tracks;
2604 if (!PyArg_ParseTuple(_args, "O&",
2605 WinObj_Convert, &theWindow))
2606 return NULL;
2607 _err = IsAutomaticControlDragTrackingEnabledForWindow(theWindow,
2608 &tracks);
2609 if (_err != noErr) return PyMac_Error(_err);
2610 _res = Py_BuildValue("b",
2611 tracks);
2612 return _res;
2613}
2614#endif
2615
Jack Jansene0581891999-02-07 14:02:03 +00002616static PyObject *Ctl_as_Control(_self, _args)
2617 PyObject *_self;
2618 PyObject *_args;
2619{
2620 PyObject *_res = NULL;
2621 ControlHandle _rv;
2622 Handle h;
2623 if (!PyArg_ParseTuple(_args, "O&",
2624 ResObj_Convert, &h))
2625 return NULL;
2626 _rv = as_Control(h);
2627 _res = Py_BuildValue("O&",
2628 CtlObj_New, _rv);
2629 return _res;
2630}
2631
Guido van Rossum17448e21995-01-30 11:53:55 +00002632static PyMethodDef Ctl_methods[] = {
2633 {"NewControl", (PyCFunction)Ctl_NewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00002634 "(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 +00002635 {"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00002636 "(SInt16 resourceID, WindowPtr owningWindow) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002637 {"DrawControls", (PyCFunction)Ctl_DrawControls, 1,
2638 "(WindowPtr theWindow) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002639 {"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1,
Jack Jansen2b724171996-04-10 14:48:19 +00002640 "(WindowPtr theWindow, RgnHandle updateRegion) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002641 {"FindControl", (PyCFunction)Ctl_FindControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00002642 "(Point testPoint, WindowPtr theWindow) -> (ControlPartCode _rv, ControlHandle theControl)"},
2643 {"FindControlUnderMouse", (PyCFunction)Ctl_FindControlUnderMouse, 1,
2644 "(Point inWhere, WindowPtr inWindow) -> (ControlHandle _rv, SInt16 outPart)"},
2645 {"IdleControls", (PyCFunction)Ctl_IdleControls, 1,
2646 "(WindowPtr inWindow) -> None"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002647
2648#if TARGET_API_MAC_CARBON
2649 {"GetControlByID", (PyCFunction)Ctl_GetControlByID, 1,
2650 "(WindowPtr inWindow, ControlID inID) -> (ControlHandle outControl)"},
2651#endif
Jack Jansen21f96871998-02-20 16:02:09 +00002652 {"DumpControlHierarchy", (PyCFunction)Ctl_DumpControlHierarchy, 1,
2653 "(WindowPtr inWindow, FSSpec inDumpFile) -> None"},
2654 {"CreateRootControl", (PyCFunction)Ctl_CreateRootControl, 1,
2655 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
2656 {"GetRootControl", (PyCFunction)Ctl_GetRootControl, 1,
2657 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
2658 {"GetKeyboardFocus", (PyCFunction)Ctl_GetKeyboardFocus, 1,
2659 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
2660 {"SetKeyboardFocus", (PyCFunction)Ctl_SetKeyboardFocus, 1,
2661 "(WindowPtr inWindow, ControlHandle inControl, ControlFocusPart inPart) -> None"},
2662 {"AdvanceKeyboardFocus", (PyCFunction)Ctl_AdvanceKeyboardFocus, 1,
2663 "(WindowPtr inWindow) -> None"},
2664 {"ReverseKeyboardFocus", (PyCFunction)Ctl_ReverseKeyboardFocus, 1,
2665 "(WindowPtr inWindow) -> None"},
2666 {"ClearKeyboardFocus", (PyCFunction)Ctl_ClearKeyboardFocus, 1,
2667 "(WindowPtr inWindow) -> None"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002668
2669#if TARGET_API_MAC_CARBON
2670 {"SetAutomaticControlDragTrackingEnabledForWindow", (PyCFunction)Ctl_SetAutomaticControlDragTrackingEnabledForWindow, 1,
2671 "(WindowPtr theWindow, Boolean tracks) -> None"},
2672#endif
2673
2674#if TARGET_API_MAC_CARBON
2675 {"IsAutomaticControlDragTrackingEnabledForWindow", (PyCFunction)Ctl_IsAutomaticControlDragTrackingEnabledForWindow, 1,
2676 "(WindowPtr theWindow) -> (Boolean tracks)"},
2677#endif
Jack Jansene0581891999-02-07 14:02:03 +00002678 {"as_Control", (PyCFunction)Ctl_as_Control, 1,
2679 "(Handle h) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002680 {NULL, NULL, 0}
2681};
2682
2683
2684
Jack Jansen9d8b96c2000-07-14 22:16:45 +00002685static PyObject *
2686CtlObj_NewUnmanaged(itself)
Jack Jansen8387af61999-03-13 23:07:32 +00002687 ControlHandle itself;
2688{
2689 ControlObject *it;
2690 if (itself == NULL) return PyMac_Error(resNotFound);
2691 it = PyObject_NEW(ControlObject, &Control_Type);
2692 if (it == NULL) return NULL;
2693 it->ob_itself = itself;
Jack Jansen1a7d5b12000-03-21 16:25:23 +00002694 it->ob_callbackdict = NULL;
Jack Jansen8387af61999-03-13 23:07:32 +00002695 return (PyObject *)it;
2696}
2697
Jack Jansen9d8b96c2000-07-14 22:16:45 +00002698static PyObject *
Guido van Rossum17448e21995-01-30 11:53:55 +00002699CtlObj_WhichControl(ControlHandle c)
2700{
2701 PyObject *it;
Jack Jansen24c35311999-12-09 22:49:51 +00002702
Guido van Rossum17448e21995-01-30 11:53:55 +00002703 if (c == NULL)
Guido van Rossum17448e21995-01-30 11:53:55 +00002704 it = Py_None;
Jack Jansen8387af61999-03-13 23:07:32 +00002705 else {
2706 it = (PyObject *) GetControlReference(c);
2707 /*
2708 ** If the refcon is zero or doesn't point back to the Python object
2709 ** the control is not ours. Return a temporary object.
2710 */
2711 if (it == NULL || ((ControlObject *)it)->ob_itself != c)
2712 return CtlObj_NewUnmanaged(c);
2713 }
Guido van Rossum17448e21995-01-30 11:53:55 +00002714 Py_INCREF(it);
2715 return it;
2716}
2717
Jack Jansen848250c1998-05-28 14:20:09 +00002718static int
2719settrackfunc(obj)
2720 PyObject *obj;
2721{
2722 if (tracker) {
2723 PyErr_SetString(Ctl_Error, "Tracker function in use");
2724 return 0;
2725 }
2726 tracker = obj;
2727 Py_INCREF(tracker);
2728}
2729
2730static void
2731clrtrackfunc()
2732{
2733 Py_XDECREF(tracker);
2734 tracker = 0;
2735}
2736
2737static pascal void
Jack Jansene79dc762000-06-02 21:35:07 +00002738mytracker(ControlHandle ctl, short part)
Jack Jansen848250c1998-05-28 14:20:09 +00002739{
2740 PyObject *args, *rv=0;
Jack Jansen24c35311999-12-09 22:49:51 +00002741
Jack Jansen848250c1998-05-28 14:20:09 +00002742 args = Py_BuildValue("(O&i)", CtlObj_WhichControl, ctl, (int)part);
2743 if (args && tracker) {
2744 rv = PyEval_CallObject(tracker, args);
2745 Py_DECREF(args);
2746 }
2747 if (rv)
2748 Py_DECREF(rv);
2749 else
Jack Jansen24c35311999-12-09 22:49:51 +00002750 PySys_WriteStderr("TrackControl or HandleControlClick: exception in tracker function\n");
Jack Jansen848250c1998-05-28 14:20:09 +00002751}
2752
Jack Jansen74a1e632000-07-14 22:37:27 +00002753#if !TARGET_API_MAC_CARBON_NOTYET
Jack Jansenabc411b2000-03-20 16:09:09 +00002754static int
Jack Jansen85152b92000-07-11 21:12:55 +00002755setcallback(myself, which, callback, uppp)
2756 PyObject *myself;
Jack Jansenabc411b2000-03-20 16:09:09 +00002757 OSType which;
2758 PyObject *callback;
2759 UniversalProcPtr *uppp;
2760{
Jack Jansen85152b92000-07-11 21:12:55 +00002761 ControlObject *self = (ControlObject *)myself;
Jack Jansenabc411b2000-03-20 16:09:09 +00002762 char keybuf[9];
2763
2764 if ( which == kControlUserPaneDrawProcTag )
Jack Jansen1b6e8212000-04-05 21:30:57 +00002765 *uppp = (UniversalProcPtr)mydrawproc_upp;
Jack Jansenabc411b2000-03-20 16:09:09 +00002766 else if ( which == kControlUserPaneIdleProcTag )
Jack Jansen1b6e8212000-04-05 21:30:57 +00002767 *uppp = (UniversalProcPtr)myidleproc_upp;
Jack Jansena27e9fb2000-03-21 23:03:02 +00002768 else if ( which == kControlUserPaneHitTestProcTag )
Jack Jansen1b6e8212000-04-05 21:30:57 +00002769 *uppp = (UniversalProcPtr)myhittestproc_upp;
Jack Jansena27e9fb2000-03-21 23:03:02 +00002770 else if ( which == kControlUserPaneTrackingProcTag )
Jack Jansen1b6e8212000-04-05 21:30:57 +00002771 *uppp = (UniversalProcPtr)mytrackingproc_upp;
Jack Jansenabc411b2000-03-20 16:09:09 +00002772 else
2773 return -1;
2774 /* Only now do we test for clearing of the callback: */
2775 if ( callback == Py_None )
2776 *uppp = NULL;
2777 /* Create the dict if it doesn't exist yet (so we don't get such a dict for every control) */
2778 if ( self->ob_callbackdict == NULL )
2779 if ( (self->ob_callbackdict = PyDict_New()) == NULL )
2780 return -1;
2781 /* And store the Python callback */
2782 sprintf(keybuf, "%x", which);
2783 if (PyDict_SetItemString(self->ob_callbackdict, keybuf, callback) < 0)
2784 return -1;
2785 return 0;
2786}
2787
2788static PyObject *
2789callcallback(self, which, arglist)
2790 ControlObject *self;
2791 OSType which;
2792 PyObject *arglist;
2793{
2794 char keybuf[9];
2795 PyObject *func, *rv;
2796
2797 sprintf(keybuf, "%x", which);
2798 if ( self->ob_callbackdict == NULL ||
2799 (func = PyDict_GetItemString(self->ob_callbackdict, keybuf)) == NULL ) {
Jack Jansena27e9fb2000-03-21 23:03:02 +00002800 PySys_WriteStderr("Control callback %x without callback object\n", which);
Jack Jansenabc411b2000-03-20 16:09:09 +00002801 return NULL;
2802 }
2803 rv = PyEval_CallObject(func, arglist);
2804 if ( rv == NULL )
Jack Jansena27e9fb2000-03-21 23:03:02 +00002805 PySys_WriteStderr("Exception in control callback %x handler\n", which);
Jack Jansenabc411b2000-03-20 16:09:09 +00002806 return rv;
2807}
2808
2809static pascal void
2810mydrawproc(ControlHandle control, SInt16 part)
2811{
2812 ControlObject *ctl_obj;
2813 PyObject *arglist, *rv;
2814
2815 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
2816 arglist = Py_BuildValue("Oh", ctl_obj, part);
2817 rv = callcallback(ctl_obj, kControlUserPaneDrawProcTag, arglist);
2818 Py_XDECREF(arglist);
2819 Py_XDECREF(rv);
2820}
2821
2822static pascal void
2823myidleproc(ControlHandle control)
2824{
2825 ControlObject *ctl_obj;
2826 PyObject *arglist, *rv;
2827
2828 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
2829 arglist = Py_BuildValue("O", ctl_obj);
2830 rv = callcallback(ctl_obj, kControlUserPaneIdleProcTag, arglist);
2831 Py_XDECREF(arglist);
2832 Py_XDECREF(rv);
2833}
2834
Jack Jansena27e9fb2000-03-21 23:03:02 +00002835static pascal ControlPartCode
2836myhittestproc(ControlHandle control, Point where)
2837{
2838 ControlObject *ctl_obj;
2839 PyObject *arglist, *rv;
2840 short c_rv = -1;
2841
2842 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
Jack Jansendeb63732000-03-22 15:35:24 +00002843 arglist = Py_BuildValue("OO&", ctl_obj, PyMac_BuildPoint, where);
Jack Jansena27e9fb2000-03-21 23:03:02 +00002844 rv = callcallback(ctl_obj, kControlUserPaneHitTestProcTag, arglist);
2845 Py_XDECREF(arglist);
2846 /* Ignore errors, nothing we can do about them */
2847 if ( rv )
2848 PyArg_Parse(rv, "h", &c_rv);
2849 Py_XDECREF(rv);
2850 return (ControlPartCode)c_rv;
2851}
2852
2853static pascal ControlPartCode
2854mytrackingproc(ControlHandle control, Point startPt, ControlActionUPP actionProc)
2855{
2856 ControlObject *ctl_obj;
2857 PyObject *arglist, *rv;
2858 short c_rv = -1;
2859
2860 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
2861 /* We cannot pass the actionProc without lots of work */
Jack Jansendeb63732000-03-22 15:35:24 +00002862 arglist = Py_BuildValue("OO&", ctl_obj, PyMac_BuildPoint, startPt);
Jack Jansena27e9fb2000-03-21 23:03:02 +00002863 rv = callcallback(ctl_obj, kControlUserPaneTrackingProcTag, arglist);
2864 Py_XDECREF(arglist);
2865 if ( rv )
2866 PyArg_Parse(rv, "h", &c_rv);
2867 Py_XDECREF(rv);
2868 return (ControlPartCode)c_rv;
2869}
Jack Jansene79dc762000-06-02 21:35:07 +00002870#endif
Jack Jansenabc411b2000-03-20 16:09:09 +00002871
Guido van Rossum17448e21995-01-30 11:53:55 +00002872
2873void initCtl()
2874{
2875 PyObject *m;
2876 PyObject *d;
2877
2878
2879
Jack Jansen848250c1998-05-28 14:20:09 +00002880 mytracker_upp = NewControlActionProc(mytracker);
Jack Jansen74a1e632000-07-14 22:37:27 +00002881#if !TARGET_API_MAC_CARBON_NOTYET
Jack Jansenabc411b2000-03-20 16:09:09 +00002882 mydrawproc_upp = NewControlUserPaneDrawProc(mydrawproc);
Jack Jansen1b6e8212000-04-05 21:30:57 +00002883 myidleproc_upp = NewControlUserPaneIdleProc(myidleproc);
Jack Jansena27e9fb2000-03-21 23:03:02 +00002884 myhittestproc_upp = NewControlUserPaneHitTestProc(myhittestproc);
2885 mytrackingproc_upp = NewControlUserPaneTrackingProc(mytrackingproc);
Jack Jansene79dc762000-06-02 21:35:07 +00002886#endif
Jack Jansen848250c1998-05-28 14:20:09 +00002887
Guido van Rossum17448e21995-01-30 11:53:55 +00002888
2889 m = Py_InitModule("Ctl", Ctl_methods);
2890 d = PyModule_GetDict(m);
2891 Ctl_Error = PyMac_GetOSErrException();
2892 if (Ctl_Error == NULL ||
2893 PyDict_SetItemString(d, "Error", Ctl_Error) != 0)
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002894 return;
Jack Jansena755e681997-09-20 17:40:22 +00002895 Control_Type.ob_type = &PyType_Type;
2896 Py_INCREF(&Control_Type);
2897 if (PyDict_SetItemString(d, "ControlType", (PyObject *)&Control_Type) != 0)
2898 Py_FatalError("can't initialize ControlType");
Guido van Rossum17448e21995-01-30 11:53:55 +00002899}
2900
2901/* ========================= End module Ctl ========================= */
2902