blob: c20e9b86277a9949f858ffd7bacfb4f4e9aed483 [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
Jack Jansen723ad8a2000-12-12 22:10:21 +00001187static PyObject *CtlObj_HandleControlDragTracking(_self, _args)
1188 ControlObject *_self;
1189 PyObject *_args;
1190{
1191 PyObject *_res = NULL;
1192 OSStatus _err;
1193 DragTrackingMessage inMessage;
1194 DragReference inDrag;
1195 Boolean outLikesDrag;
1196 if (!PyArg_ParseTuple(_args, "hO&",
1197 &inMessage,
1198 DragObj_Convert, &inDrag))
1199 return NULL;
1200 _err = HandleControlDragTracking(_self->ob_itself,
1201 inMessage,
1202 inDrag,
1203 &outLikesDrag);
1204 if (_err != noErr) return PyMac_Error(_err);
1205 _res = Py_BuildValue("b",
1206 outLikesDrag);
1207 return _res;
1208}
1209#endif
1210
1211#if TARGET_API_MAC_CARBON
1212
1213static PyObject *CtlObj_HandleControlDragReceive(_self, _args)
1214 ControlObject *_self;
1215 PyObject *_args;
1216{
1217 PyObject *_res = NULL;
1218 OSStatus _err;
1219 DragReference inDrag;
1220 if (!PyArg_ParseTuple(_args, "O&",
1221 DragObj_Convert, &inDrag))
1222 return NULL;
1223 _err = HandleControlDragReceive(_self->ob_itself,
1224 inDrag);
1225 if (_err != noErr) return PyMac_Error(_err);
1226 Py_INCREF(Py_None);
1227 _res = Py_None;
1228 return _res;
1229}
1230#endif
1231
1232#if TARGET_API_MAC_CARBON
1233
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001234static PyObject *CtlObj_SetControlDragTrackingEnabled(_self, _args)
1235 ControlObject *_self;
1236 PyObject *_args;
1237{
1238 PyObject *_res = NULL;
1239 OSStatus _err;
1240 Boolean tracks;
1241 if (!PyArg_ParseTuple(_args, "b",
1242 &tracks))
1243 return NULL;
1244 _err = SetControlDragTrackingEnabled(_self->ob_itself,
1245 tracks);
1246 if (_err != noErr) return PyMac_Error(_err);
1247 Py_INCREF(Py_None);
1248 _res = Py_None;
1249 return _res;
1250}
1251#endif
1252
1253#if TARGET_API_MAC_CARBON
1254
1255static PyObject *CtlObj_IsControlDragTrackingEnabled(_self, _args)
1256 ControlObject *_self;
1257 PyObject *_args;
1258{
1259 PyObject *_res = NULL;
1260 OSStatus _err;
1261 Boolean tracks;
1262 if (!PyArg_ParseTuple(_args, ""))
1263 return NULL;
1264 _err = IsControlDragTrackingEnabled(_self->ob_itself,
1265 &tracks);
1266 if (_err != noErr) return PyMac_Error(_err);
1267 _res = Py_BuildValue("b",
1268 tracks);
1269 return _res;
1270}
1271#endif
1272
1273#if ACCESSOR_CALLS_ARE_FUNCTIONS
1274
1275static PyObject *CtlObj_GetControlBounds(_self, _args)
1276 ControlObject *_self;
1277 PyObject *_args;
1278{
1279 PyObject *_res = NULL;
1280 Rect _rv;
1281 Rect bounds;
1282 if (!PyArg_ParseTuple(_args, ""))
1283 return NULL;
1284 _rv = GetControlBounds(_self->ob_itself,
1285 &bounds);
1286 _res = Py_BuildValue("O&O&",
1287 PyMac_BuildRect, &_rv,
1288 PyMac_BuildRect, &bounds);
1289 return _res;
1290}
1291#endif
1292
1293#if ACCESSOR_CALLS_ARE_FUNCTIONS
1294
1295static PyObject *CtlObj_IsControlHilited(_self, _args)
1296 ControlObject *_self;
1297 PyObject *_args;
1298{
1299 PyObject *_res = NULL;
1300 Boolean _rv;
1301 if (!PyArg_ParseTuple(_args, ""))
1302 return NULL;
1303 _rv = IsControlHilited(_self->ob_itself);
1304 _res = Py_BuildValue("b",
1305 _rv);
1306 return _res;
1307}
1308#endif
1309
1310#if ACCESSOR_CALLS_ARE_FUNCTIONS
1311
1312static PyObject *CtlObj_GetControlHilite(_self, _args)
1313 ControlObject *_self;
1314 PyObject *_args;
1315{
1316 PyObject *_res = NULL;
1317 UInt16 _rv;
1318 if (!PyArg_ParseTuple(_args, ""))
1319 return NULL;
1320 _rv = GetControlHilite(_self->ob_itself);
1321 _res = Py_BuildValue("H",
1322 _rv);
1323 return _res;
1324}
1325#endif
1326
1327#if ACCESSOR_CALLS_ARE_FUNCTIONS
1328
1329static PyObject *CtlObj_GetControlOwner(_self, _args)
1330 ControlObject *_self;
1331 PyObject *_args;
1332{
1333 PyObject *_res = NULL;
1334 WindowPtr _rv;
1335 if (!PyArg_ParseTuple(_args, ""))
1336 return NULL;
1337 _rv = GetControlOwner(_self->ob_itself);
1338 _res = Py_BuildValue("O&",
1339 WinObj_New, _rv);
1340 return _res;
1341}
1342#endif
1343
1344#if ACCESSOR_CALLS_ARE_FUNCTIONS
1345
1346static PyObject *CtlObj_GetControlDataHandle(_self, _args)
1347 ControlObject *_self;
1348 PyObject *_args;
1349{
1350 PyObject *_res = NULL;
1351 Handle _rv;
1352 if (!PyArg_ParseTuple(_args, ""))
1353 return NULL;
1354 _rv = GetControlDataHandle(_self->ob_itself);
1355 _res = Py_BuildValue("O&",
1356 ResObj_New, _rv);
1357 return _res;
1358}
1359#endif
1360
1361#if ACCESSOR_CALLS_ARE_FUNCTIONS
1362
1363static PyObject *CtlObj_GetControlPopupMenuHandle(_self, _args)
1364 ControlObject *_self;
1365 PyObject *_args;
1366{
1367 PyObject *_res = NULL;
1368 MenuHandle _rv;
1369 if (!PyArg_ParseTuple(_args, ""))
1370 return NULL;
1371 _rv = GetControlPopupMenuHandle(_self->ob_itself);
1372 _res = Py_BuildValue("O&",
1373 MenuObj_New, _rv);
1374 return _res;
1375}
1376#endif
1377
1378#if ACCESSOR_CALLS_ARE_FUNCTIONS
1379
1380static PyObject *CtlObj_GetControlPopupMenuID(_self, _args)
1381 ControlObject *_self;
1382 PyObject *_args;
1383{
1384 PyObject *_res = NULL;
1385 short _rv;
1386 if (!PyArg_ParseTuple(_args, ""))
1387 return NULL;
1388 _rv = GetControlPopupMenuID(_self->ob_itself);
1389 _res = Py_BuildValue("h",
1390 _rv);
1391 return _res;
1392}
1393#endif
1394
1395#if ACCESSOR_CALLS_ARE_FUNCTIONS
1396
1397static PyObject *CtlObj_SetControlDataHandle(_self, _args)
1398 ControlObject *_self;
1399 PyObject *_args;
1400{
1401 PyObject *_res = NULL;
1402 Handle dataHandle;
1403 if (!PyArg_ParseTuple(_args, "O&",
1404 ResObj_Convert, &dataHandle))
1405 return NULL;
1406 SetControlDataHandle(_self->ob_itself,
1407 dataHandle);
1408 Py_INCREF(Py_None);
1409 _res = Py_None;
1410 return _res;
1411}
1412#endif
1413
1414#if ACCESSOR_CALLS_ARE_FUNCTIONS
1415
1416static PyObject *CtlObj_SetControlBounds(_self, _args)
1417 ControlObject *_self;
1418 PyObject *_args;
1419{
1420 PyObject *_res = NULL;
1421 Rect bounds;
1422 if (!PyArg_ParseTuple(_args, "O&",
1423 PyMac_GetRect, &bounds))
1424 return NULL;
1425 SetControlBounds(_self->ob_itself,
1426 &bounds);
1427 Py_INCREF(Py_None);
1428 _res = Py_None;
1429 return _res;
1430}
1431#endif
1432
1433#if ACCESSOR_CALLS_ARE_FUNCTIONS
1434
1435static PyObject *CtlObj_SetControlPopupMenuHandle(_self, _args)
1436 ControlObject *_self;
1437 PyObject *_args;
1438{
1439 PyObject *_res = NULL;
1440 MenuHandle popupMenu;
1441 if (!PyArg_ParseTuple(_args, "O&",
1442 MenuObj_Convert, &popupMenu))
1443 return NULL;
1444 SetControlPopupMenuHandle(_self->ob_itself,
1445 popupMenu);
1446 Py_INCREF(Py_None);
1447 _res = Py_None;
1448 return _res;
1449}
1450#endif
1451
1452#if ACCESSOR_CALLS_ARE_FUNCTIONS
1453
1454static PyObject *CtlObj_SetControlPopupMenuID(_self, _args)
1455 ControlObject *_self;
1456 PyObject *_args;
1457{
1458 PyObject *_res = NULL;
1459 short menuID;
1460 if (!PyArg_ParseTuple(_args, "h",
1461 &menuID))
1462 return NULL;
1463 SetControlPopupMenuID(_self->ob_itself,
1464 menuID);
1465 Py_INCREF(Py_None);
1466 _res = Py_None;
1467 return _res;
1468}
1469#endif
1470
1471static PyObject *CtlObj_GetBevelButtonMenuValue(_self, _args)
1472 ControlObject *_self;
1473 PyObject *_args;
1474{
1475 PyObject *_res = NULL;
1476 OSErr _err;
1477 SInt16 outValue;
1478 if (!PyArg_ParseTuple(_args, ""))
1479 return NULL;
1480 _err = GetBevelButtonMenuValue(_self->ob_itself,
1481 &outValue);
1482 if (_err != noErr) return PyMac_Error(_err);
1483 _res = Py_BuildValue("h",
1484 outValue);
1485 return _res;
1486}
1487
1488static PyObject *CtlObj_SetBevelButtonMenuValue(_self, _args)
1489 ControlObject *_self;
1490 PyObject *_args;
1491{
1492 PyObject *_res = NULL;
1493 OSErr _err;
1494 SInt16 inValue;
1495 if (!PyArg_ParseTuple(_args, "h",
1496 &inValue))
1497 return NULL;
1498 _err = SetBevelButtonMenuValue(_self->ob_itself,
1499 inValue);
1500 if (_err != noErr) return PyMac_Error(_err);
1501 Py_INCREF(Py_None);
1502 _res = Py_None;
1503 return _res;
1504}
1505
1506static PyObject *CtlObj_GetBevelButtonMenuHandle(_self, _args)
1507 ControlObject *_self;
1508 PyObject *_args;
1509{
1510 PyObject *_res = NULL;
1511 OSErr _err;
1512 MenuHandle outHandle;
1513 if (!PyArg_ParseTuple(_args, ""))
1514 return NULL;
1515 _err = GetBevelButtonMenuHandle(_self->ob_itself,
1516 &outHandle);
1517 if (_err != noErr) return PyMac_Error(_err);
1518 _res = Py_BuildValue("O&",
1519 MenuObj_New, outHandle);
1520 return _res;
1521}
1522
1523static PyObject *CtlObj_SetBevelButtonTransform(_self, _args)
1524 ControlObject *_self;
1525 PyObject *_args;
1526{
1527 PyObject *_res = NULL;
1528 OSErr _err;
1529 IconTransformType transform;
1530 if (!PyArg_ParseTuple(_args, "h",
1531 &transform))
1532 return NULL;
1533 _err = SetBevelButtonTransform(_self->ob_itself,
1534 transform);
1535 if (_err != noErr) return PyMac_Error(_err);
1536 Py_INCREF(Py_None);
1537 _res = Py_None;
1538 return _res;
1539}
1540
1541static PyObject *CtlObj_SetDisclosureTriangleLastValue(_self, _args)
1542 ControlObject *_self;
1543 PyObject *_args;
1544{
1545 PyObject *_res = NULL;
1546 OSErr _err;
1547 SInt16 inValue;
1548 if (!PyArg_ParseTuple(_args, "h",
1549 &inValue))
1550 return NULL;
1551 _err = SetDisclosureTriangleLastValue(_self->ob_itself,
1552 inValue);
1553 if (_err != noErr) return PyMac_Error(_err);
1554 Py_INCREF(Py_None);
1555 _res = Py_None;
1556 return _res;
1557}
1558
1559static PyObject *CtlObj_GetTabContentRect(_self, _args)
1560 ControlObject *_self;
1561 PyObject *_args;
1562{
1563 PyObject *_res = NULL;
1564 OSErr _err;
1565 Rect outContentRect;
1566 if (!PyArg_ParseTuple(_args, ""))
1567 return NULL;
1568 _err = GetTabContentRect(_self->ob_itself,
1569 &outContentRect);
1570 if (_err != noErr) return PyMac_Error(_err);
1571 _res = Py_BuildValue("O&",
1572 PyMac_BuildRect, &outContentRect);
1573 return _res;
1574}
1575
1576static PyObject *CtlObj_SetTabEnabled(_self, _args)
1577 ControlObject *_self;
1578 PyObject *_args;
1579{
1580 PyObject *_res = NULL;
1581 OSErr _err;
1582 SInt16 inTabToHilite;
1583 Boolean inEnabled;
1584 if (!PyArg_ParseTuple(_args, "hb",
1585 &inTabToHilite,
1586 &inEnabled))
1587 return NULL;
1588 _err = SetTabEnabled(_self->ob_itself,
1589 inTabToHilite,
1590 inEnabled);
1591 if (_err != noErr) return PyMac_Error(_err);
1592 Py_INCREF(Py_None);
1593 _res = Py_None;
1594 return _res;
1595}
1596
1597static PyObject *CtlObj_SetImageWellTransform(_self, _args)
1598 ControlObject *_self;
1599 PyObject *_args;
1600{
1601 PyObject *_res = NULL;
1602 OSErr _err;
1603 IconTransformType inTransform;
1604 if (!PyArg_ParseTuple(_args, "h",
1605 &inTransform))
1606 return NULL;
1607 _err = SetImageWellTransform(_self->ob_itself,
1608 inTransform);
1609 if (_err != noErr) return PyMac_Error(_err);
1610 Py_INCREF(Py_None);
1611 _res = Py_None;
1612 return _res;
1613}
1614
Jack Jansen5d56f4b1995-06-18 20:16:33 +00001615static PyObject *CtlObj_as_Resource(_self, _args)
1616 ControlObject *_self;
1617 PyObject *_args;
1618{
1619 PyObject *_res = NULL;
Jack Jansena1a0fef1999-12-23 14:32:06 +00001620 Handle _rv;
1621 if (!PyArg_ParseTuple(_args, ""))
1622 return NULL;
1623 _rv = as_Resource(_self->ob_itself);
1624 _res = Py_BuildValue("O&",
1625 ResObj_New, _rv);
1626 return _res;
Jack Jansen5d56f4b1995-06-18 20:16:33 +00001627}
1628
Jack Jansen1a7d5b12000-03-21 16:25:23 +00001629static PyObject *CtlObj_GetControlRect(_self, _args)
1630 ControlObject *_self;
1631 PyObject *_args;
1632{
1633 PyObject *_res = NULL;
1634 Rect rect;
1635 if (!PyArg_ParseTuple(_args, ""))
1636 return NULL;
1637 GetControlRect(_self->ob_itself,
1638 &rect);
1639 _res = Py_BuildValue("O&",
1640 PyMac_BuildRect, &rect);
1641 return _res;
1642}
1643
Jack Jansencfb60ee1996-10-01 10:46:46 +00001644static PyObject *CtlObj_DisposeControl(_self, _args)
1645 ControlObject *_self;
1646 PyObject *_args;
1647{
1648 PyObject *_res = NULL;
1649
1650 if (!PyArg_ParseTuple(_args, ""))
1651 return NULL;
1652 if ( _self->ob_itself ) {
Jack Jansen85ae4a81997-04-08 15:26:03 +00001653 SetControlReference(_self->ob_itself, (long)0); /* Make it forget about us */
Jack Jansencfb60ee1996-10-01 10:46:46 +00001654 DisposeControl(_self->ob_itself);
1655 _self->ob_itself = NULL;
1656 }
1657 Py_INCREF(Py_None);
1658 _res = Py_None;
1659 return _res;
1660
1661}
1662
Jack Jansen848250c1998-05-28 14:20:09 +00001663static PyObject *CtlObj_TrackControl(_self, _args)
1664 ControlObject *_self;
1665 PyObject *_args;
1666{
1667 PyObject *_res = NULL;
1668
1669 ControlPartCode _rv;
1670 Point startPoint;
1671 ControlActionUPP upp = 0;
1672 PyObject *callback = 0;
1673
1674 if (!PyArg_ParseTuple(_args, "O&|O",
1675 PyMac_GetPoint, &startPoint, &callback))
1676 return NULL;
1677 if (callback && callback != Py_None) {
1678 if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
1679 upp = (ControlActionUPP)-1;
1680 else {
1681 settrackfunc(callback);
1682 upp = mytracker_upp;
1683 }
1684 }
1685 _rv = TrackControl(_self->ob_itself,
1686 startPoint,
1687 upp);
1688 clrtrackfunc();
1689 _res = Py_BuildValue("h",
1690 _rv);
1691 return _res;
1692
1693}
1694
Jack Jansen24c35311999-12-09 22:49:51 +00001695static PyObject *CtlObj_HandleControlClick(_self, _args)
1696 ControlObject *_self;
1697 PyObject *_args;
1698{
1699 PyObject *_res = NULL;
1700
1701 ControlPartCode _rv;
1702 Point startPoint;
1703 SInt16 modifiers;
1704 ControlActionUPP upp = 0;
1705 PyObject *callback = 0;
1706
1707 if (!PyArg_ParseTuple(_args, "O&h|O",
1708 PyMac_GetPoint, &startPoint,
1709 &modifiers,
1710 &callback))
1711 return NULL;
1712 if (callback && callback != Py_None) {
1713 if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
1714 upp = (ControlActionUPP)-1;
1715 else {
1716 settrackfunc(callback);
1717 upp = mytracker_upp;
1718 }
1719 }
1720 _rv = HandleControlClick(_self->ob_itself,
1721 startPoint,
1722 modifiers,
1723 upp);
1724 clrtrackfunc();
1725 _res = Py_BuildValue("h",
1726 _rv);
1727 return _res;
1728
1729}
1730
1731static PyObject *CtlObj_SetControlData(_self, _args)
1732 ControlObject *_self;
1733 PyObject *_args;
1734{
1735 PyObject *_res = NULL;
1736
1737 OSErr _err;
1738 ControlPartCode inPart;
1739 ResType inTagName;
1740 Size bufferSize;
1741 Ptr buffer;
1742
1743 if (!PyArg_ParseTuple(_args, "hO&s#",
1744 &inPart,
1745 PyMac_GetOSType, &inTagName,
1746 &buffer, &bufferSize))
1747 return NULL;
1748
1749 _err = SetControlData(_self->ob_itself,
1750 inPart,
1751 inTagName,
1752 bufferSize,
1753 buffer);
1754
1755 if (_err != noErr)
1756 return PyMac_Error(_err);
1757 _res = Py_None;
1758 return _res;
1759
1760}
1761
1762static PyObject *CtlObj_GetControlData(_self, _args)
1763 ControlObject *_self;
1764 PyObject *_args;
1765{
1766 PyObject *_res = NULL;
1767
1768 OSErr _err;
1769 ControlPartCode inPart;
1770 ResType inTagName;
1771 Size bufferSize;
1772 Ptr buffer;
1773 Size outSize;
1774
1775 if (!PyArg_ParseTuple(_args, "hO&",
1776 &inPart,
1777 PyMac_GetOSType, &inTagName))
1778 return NULL;
1779
1780 /* allocate a buffer for the data */
1781 _err = GetControlDataSize(_self->ob_itself,
1782 inPart,
1783 inTagName,
1784 &bufferSize);
1785 if (_err != noErr)
1786 return PyMac_Error(_err);
1787 buffer = PyMem_NEW(char, bufferSize);
1788 if (buffer == NULL)
1789 return PyErr_NoMemory();
1790
1791 _err = GetControlData(_self->ob_itself,
1792 inPart,
1793 inTagName,
1794 bufferSize,
1795 buffer,
1796 &outSize);
1797
1798 if (_err != noErr) {
1799 PyMem_DEL(buffer);
1800 return PyMac_Error(_err);
1801 }
1802 _res = Py_BuildValue("s#", buffer, outSize);
1803 PyMem_DEL(buffer);
1804 return _res;
1805
1806}
1807
Jack Jansen1f9249c1999-12-19 00:05:50 +00001808static PyObject *CtlObj_SetControlDataHandle(_self, _args)
1809 ControlObject *_self;
1810 PyObject *_args;
1811{
1812 PyObject *_res = NULL;
1813
1814 OSErr _err;
1815 ControlPartCode inPart;
1816 ResType inTagName;
1817 Handle buffer;
1818
1819 if (!PyArg_ParseTuple(_args, "hO&O&",
1820 &inPart,
1821 PyMac_GetOSType, &inTagName,
Jack Jansenb9247d31999-12-23 23:06:07 +00001822 OptResObj_Convert, &buffer))
Jack Jansen1f9249c1999-12-19 00:05:50 +00001823 return NULL;
1824
1825 _err = SetControlData(_self->ob_itself,
1826 inPart,
1827 inTagName,
1828 sizeof(buffer),
Jack Jansenf7ac1d31999-12-29 12:37:22 +00001829 (Ptr)&buffer);
Jack Jansen1f9249c1999-12-19 00:05:50 +00001830
1831 if (_err != noErr)
1832 return PyMac_Error(_err);
1833 _res = Py_None;
1834 return _res;
1835
1836}
1837
1838static PyObject *CtlObj_GetControlDataHandle(_self, _args)
1839 ControlObject *_self;
1840 PyObject *_args;
1841{
1842 PyObject *_res = NULL;
1843
1844 OSErr _err;
1845 ControlPartCode inPart;
1846 ResType inTagName;
1847 Size bufferSize;
1848 Handle hdl;
1849
1850 if (!PyArg_ParseTuple(_args, "hO&",
1851 &inPart,
1852 PyMac_GetOSType, &inTagName))
1853 return NULL;
1854
1855 /* Check it is handle-sized */
1856 _err = GetControlDataSize(_self->ob_itself,
1857 inPart,
1858 inTagName,
1859 &bufferSize);
1860 if (_err != noErr)
1861 return PyMac_Error(_err);
1862 if (bufferSize != sizeof(Handle)) {
1863 PyErr_SetString(Ctl_Error, "GetControlDataSize() != sizeof(Handle)");
1864 return NULL;
1865 }
1866
1867 _err = GetControlData(_self->ob_itself,
1868 inPart,
1869 inTagName,
1870 sizeof(Handle),
1871 (Ptr)&hdl,
1872 &bufferSize);
1873
1874 if (_err != noErr) {
1875 return PyMac_Error(_err);
1876 }
1877 return Py_BuildValue("O&", OptResObj_New, hdl);
1878
1879}
1880
Jack Jansen74a1e632000-07-14 22:37:27 +00001881#if !TARGET_API_MAC_CARBON_NOTYET
Jack Jansene79dc762000-06-02 21:35:07 +00001882
Jack Jansenabc411b2000-03-20 16:09:09 +00001883static PyObject *CtlObj_SetControlDataCallback(_self, _args)
1884 ControlObject *_self;
1885 PyObject *_args;
1886{
1887 PyObject *_res = NULL;
1888
1889 OSErr _err;
1890 ControlPartCode inPart;
1891 ResType inTagName;
1892 PyObject *callback;
Jack Jansen85152b92000-07-11 21:12:55 +00001893 UniversalProcPtr c_callback;
Jack Jansenabc411b2000-03-20 16:09:09 +00001894
1895 if (!PyArg_ParseTuple(_args, "hO&O",
1896 &inPart,
1897 PyMac_GetOSType, &inTagName,
1898 &callback))
1899 return NULL;
1900
Jack Jansen85152b92000-07-11 21:12:55 +00001901 if ( setcallback((PyObject *)_self, inTagName, callback, &c_callback) < 0 )
Jack Jansenabc411b2000-03-20 16:09:09 +00001902 return NULL;
1903 _err = SetControlData(_self->ob_itself,
1904 inPart,
1905 inTagName,
1906 sizeof(c_callback),
1907 (Ptr)&c_callback);
1908
1909 if (_err != noErr)
1910 return PyMac_Error(_err);
1911 _res = Py_None;
1912 return _res;
1913
1914}
Jack Jansene79dc762000-06-02 21:35:07 +00001915#endif
1916
Jack Jansen74a1e632000-07-14 22:37:27 +00001917#if !TARGET_API_MAC_CARBON_NOTYET
Jack Jansenabc411b2000-03-20 16:09:09 +00001918
Jack Jansen4c704131998-06-19 13:35:14 +00001919static PyObject *CtlObj_GetPopupData(_self, _args)
1920 ControlObject *_self;
1921 PyObject *_args;
1922{
1923 PyObject *_res = NULL;
1924
1925 PopupPrivateDataHandle hdl;
1926
1927 if ( (*_self->ob_itself)->contrlData == NULL ) {
1928 PyErr_SetString(Ctl_Error, "No contrlData handle in control");
1929 return 0;
1930 }
1931 hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
1932 HLock((Handle)hdl);
1933 _res = Py_BuildValue("O&i", MenuObj_New, (*hdl)->mHandle, (int)(*hdl)->mID);
1934 HUnlock((Handle)hdl);
1935 return _res;
1936
1937}
Jack Jansene79dc762000-06-02 21:35:07 +00001938#endif
1939
Jack Jansen74a1e632000-07-14 22:37:27 +00001940#if !TARGET_API_MAC_CARBON_NOTYET
Jack Jansen4c704131998-06-19 13:35:14 +00001941
1942static PyObject *CtlObj_SetPopupData(_self, _args)
1943 ControlObject *_self;
1944 PyObject *_args;
1945{
1946 PyObject *_res = NULL;
1947
1948 PopupPrivateDataHandle hdl;
1949 MenuHandle mHandle;
1950 short mID;
1951
1952 if (!PyArg_ParseTuple(_args, "O&h", MenuObj_Convert, &mHandle, &mID) )
1953 return 0;
1954 if ( (*_self->ob_itself)->contrlData == NULL ) {
1955 PyErr_SetString(Ctl_Error, "No contrlData handle in control");
1956 return 0;
1957 }
1958 hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
1959 (*hdl)->mHandle = mHandle;
1960 (*hdl)->mID = mID;
1961 Py_INCREF(Py_None);
1962 return Py_None;
1963
1964}
Jack Jansene79dc762000-06-02 21:35:07 +00001965#endif
Jack Jansen4c704131998-06-19 13:35:14 +00001966
Guido van Rossum17448e21995-01-30 11:53:55 +00001967static PyMethodDef CtlObj_methods[] = {
Jack Jansen21f96871998-02-20 16:02:09 +00001968 {"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1,
1969 "(ControlPartCode hiliteState) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001970 {"ShowControl", (PyCFunction)CtlObj_ShowControl, 1,
1971 "() -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001972 {"HideControl", (PyCFunction)CtlObj_HideControl, 1,
1973 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001974 {"IsControlActive", (PyCFunction)CtlObj_IsControlActive, 1,
1975 "() -> (Boolean _rv)"},
1976 {"IsControlVisible", (PyCFunction)CtlObj_IsControlVisible, 1,
1977 "() -> (Boolean _rv)"},
1978 {"ActivateControl", (PyCFunction)CtlObj_ActivateControl, 1,
1979 "() -> None"},
1980 {"DeactivateControl", (PyCFunction)CtlObj_DeactivateControl, 1,
1981 "() -> None"},
1982 {"SetControlVisibility", (PyCFunction)CtlObj_SetControlVisibility, 1,
1983 "(Boolean inIsVisible, Boolean inDoDraw) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001984 {"Draw1Control", (PyCFunction)CtlObj_Draw1Control, 1,
1985 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001986 {"GetBestControlRect", (PyCFunction)CtlObj_GetBestControlRect, 1,
1987 "() -> (Rect outRect, SInt16 outBaseLineOffset)"},
1988 {"SetControlFontStyle", (PyCFunction)CtlObj_SetControlFontStyle, 1,
1989 "(ControlFontStyleRec inStyle) -> None"},
1990 {"DrawControlInCurrentPort", (PyCFunction)CtlObj_DrawControlInCurrentPort, 1,
1991 "() -> None"},
1992 {"SetUpControlBackground", (PyCFunction)CtlObj_SetUpControlBackground, 1,
1993 "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +00001994 {"SetUpControlTextColor", (PyCFunction)CtlObj_SetUpControlTextColor, 1,
1995 "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001996 {"DragControl", (PyCFunction)CtlObj_DragControl, 1,
Jack Jansen754d4a41995-11-14 10:41:55 +00001997 "(Point startPoint, Rect limitRect, Rect slopRect, DragConstraint axis) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001998 {"TestControl", (PyCFunction)CtlObj_TestControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001999 "(Point testPoint) -> (ControlPartCode _rv)"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002000
2001#if TARGET_API_MAC_CARBON
2002 {"HandleControlContextualMenuClick", (PyCFunction)CtlObj_HandleControlContextualMenuClick, 1,
2003 "(Point inWhere) -> (Boolean menuDisplayed)"},
2004#endif
2005
2006#if TARGET_API_MAC_CARBON
2007 {"GetControlClickActivation", (PyCFunction)CtlObj_GetControlClickActivation, 1,
2008 "(Point inWhere, EventModifiers inModifiers) -> (ClickActivationResult outResult)"},
2009#endif
Jack Jansen21f96871998-02-20 16:02:09 +00002010 {"HandleControlKey", (PyCFunction)CtlObj_HandleControlKey, 1,
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002011 "(SInt16 inKeyCode, SInt16 inCharCode, EventModifiers inModifiers) -> (SInt16 _rv)"},
2012
2013#if TARGET_API_MAC_CARBON
2014 {"HandleControlSetCursor", (PyCFunction)CtlObj_HandleControlSetCursor, 1,
2015 "(Point localPoint, EventModifiers modifiers) -> (Boolean cursorWasSet)"},
2016#endif
Guido van Rossum17448e21995-01-30 11:53:55 +00002017 {"MoveControl", (PyCFunction)CtlObj_MoveControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00002018 "(SInt16 h, SInt16 v) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002019 {"SizeControl", (PyCFunction)CtlObj_SizeControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00002020 "(SInt16 w, SInt16 h) -> None"},
2021 {"SetControlTitle", (PyCFunction)CtlObj_SetControlTitle, 1,
2022 "(Str255 title) -> None"},
2023 {"GetControlTitle", (PyCFunction)CtlObj_GetControlTitle, 1,
Jack Jansen41009001999-03-07 20:05:20 +00002024 "() -> (Str255 title)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00002025 {"GetControlValue", (PyCFunction)CtlObj_GetControlValue, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00002026 "() -> (SInt16 _rv)"},
2027 {"SetControlValue", (PyCFunction)CtlObj_SetControlValue, 1,
2028 "(SInt16 newValue) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00002029 {"GetControlMinimum", (PyCFunction)CtlObj_GetControlMinimum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00002030 "() -> (SInt16 _rv)"},
2031 {"SetControlMinimum", (PyCFunction)CtlObj_SetControlMinimum, 1,
2032 "(SInt16 newMinimum) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00002033 {"GetControlMaximum", (PyCFunction)CtlObj_GetControlMaximum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00002034 "() -> (SInt16 _rv)"},
2035 {"SetControlMaximum", (PyCFunction)CtlObj_SetControlMaximum, 1,
2036 "(SInt16 newMaximum) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +00002037 {"GetControlViewSize", (PyCFunction)CtlObj_GetControlViewSize, 1,
2038 "() -> (SInt32 _rv)"},
2039 {"SetControlViewSize", (PyCFunction)CtlObj_SetControlViewSize, 1,
2040 "(SInt32 newViewSize) -> None"},
2041 {"GetControl32BitValue", (PyCFunction)CtlObj_GetControl32BitValue, 1,
2042 "() -> (SInt32 _rv)"},
2043 {"SetControl32BitValue", (PyCFunction)CtlObj_SetControl32BitValue, 1,
2044 "(SInt32 newValue) -> None"},
2045 {"GetControl32BitMaximum", (PyCFunction)CtlObj_GetControl32BitMaximum, 1,
2046 "() -> (SInt32 _rv)"},
2047 {"SetControl32BitMaximum", (PyCFunction)CtlObj_SetControl32BitMaximum, 1,
2048 "(SInt32 newMaximum) -> None"},
2049 {"GetControl32BitMinimum", (PyCFunction)CtlObj_GetControl32BitMinimum, 1,
2050 "() -> (SInt32 _rv)"},
2051 {"SetControl32BitMinimum", (PyCFunction)CtlObj_SetControl32BitMinimum, 1,
2052 "(SInt32 newMinimum) -> None"},
2053 {"IsValidControlHandle", (PyCFunction)CtlObj_IsValidControlHandle, 1,
2054 "() -> (Boolean _rv)"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002055
2056#if TARGET_API_MAC_CARBON
2057 {"SetControlID", (PyCFunction)CtlObj_SetControlID, 1,
2058 "(ControlID inID) -> None"},
2059#endif
2060
2061#if TARGET_API_MAC_CARBON
2062 {"GetControlID", (PyCFunction)CtlObj_GetControlID, 1,
2063 "() -> (ControlID outID)"},
2064#endif
Jack Jansena05ac601999-12-12 21:41:51 +00002065 {"RemoveControlProperty", (PyCFunction)CtlObj_RemoveControlProperty, 1,
Jack Jansene79dc762000-06-02 21:35:07 +00002066 "(OSType propertyCreator, OSType propertyTag) -> None"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002067
2068#if TARGET_API_MAC_CARBON
2069 {"GetControlPropertyAttributes", (PyCFunction)CtlObj_GetControlPropertyAttributes, 1,
2070 "(OSType propertyCreator, OSType propertyTag) -> (UInt32 attributes)"},
2071#endif
2072
2073#if TARGET_API_MAC_CARBON
2074 {"ChangeControlPropertyAttributes", (PyCFunction)CtlObj_ChangeControlPropertyAttributes, 1,
2075 "(OSType propertyCreator, OSType propertyTag, UInt32 attributesToSet, UInt32 attributesToClear) -> None"},
2076#endif
Jack Jansena05ac601999-12-12 21:41:51 +00002077 {"GetControlRegion", (PyCFunction)CtlObj_GetControlRegion, 1,
Jack Jansene79dc762000-06-02 21:35:07 +00002078 "(ControlPartCode inPart, RgnHandle outRegion) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00002079 {"GetControlVariant", (PyCFunction)CtlObj_GetControlVariant, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00002080 "() -> (ControlVariant _rv)"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00002081 {"SetControlReference", (PyCFunction)CtlObj_SetControlReference, 1,
2082 "(SInt32 data) -> None"},
2083 {"GetControlReference", (PyCFunction)CtlObj_GetControlReference, 1,
2084 "() -> (SInt32 _rv)"},
Jack Jansene79dc762000-06-02 21:35:07 +00002085
Jack Jansen74a1e632000-07-14 22:37:27 +00002086#if !TARGET_API_MAC_CARBON
Jack Jansenc7fefed1997-08-15 14:32:18 +00002087 {"GetAuxiliaryControlRecord", (PyCFunction)CtlObj_GetAuxiliaryControlRecord, 1,
2088 "() -> (Boolean _rv, AuxCtlHandle acHndl)"},
Jack Jansene79dc762000-06-02 21:35:07 +00002089#endif
2090
Jack Jansen74a1e632000-07-14 22:37:27 +00002091#if !TARGET_API_MAC_CARBON
Jack Jansenc7fefed1997-08-15 14:32:18 +00002092 {"SetControlColor", (PyCFunction)CtlObj_SetControlColor, 1,
2093 "(CCTabHandle newColorTable) -> None"},
Jack Jansene79dc762000-06-02 21:35:07 +00002094#endif
Jack Jansen21f96871998-02-20 16:02:09 +00002095 {"SendControlMessage", (PyCFunction)CtlObj_SendControlMessage, 1,
2096 "(SInt16 inMessage, SInt32 inParam) -> (SInt32 _rv)"},
2097 {"EmbedControl", (PyCFunction)CtlObj_EmbedControl, 1,
2098 "(ControlHandle inContainer) -> None"},
2099 {"AutoEmbedControl", (PyCFunction)CtlObj_AutoEmbedControl, 1,
2100 "(WindowPtr inWindow) -> None"},
2101 {"GetSuperControl", (PyCFunction)CtlObj_GetSuperControl, 1,
2102 "() -> (ControlHandle outParent)"},
2103 {"CountSubControls", (PyCFunction)CtlObj_CountSubControls, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00002104 "() -> (UInt16 outNumChildren)"},
Jack Jansen21f96871998-02-20 16:02:09 +00002105 {"GetIndexedSubControl", (PyCFunction)CtlObj_GetIndexedSubControl, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00002106 "(UInt16 inIndex) -> (ControlHandle outSubControl)"},
Jack Jansen21f96871998-02-20 16:02:09 +00002107 {"SetControlSupervisor", (PyCFunction)CtlObj_SetControlSupervisor, 1,
2108 "(ControlHandle inBoss) -> None"},
2109 {"GetControlFeatures", (PyCFunction)CtlObj_GetControlFeatures, 1,
2110 "() -> (UInt32 outFeatures)"},
2111 {"GetControlDataSize", (PyCFunction)CtlObj_GetControlDataSize, 1,
2112 "(ControlPartCode inPart, ResType inTagName) -> (Size outMaxSize)"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002113
2114#if TARGET_API_MAC_CARBON
Jack Jansen723ad8a2000-12-12 22:10:21 +00002115 {"HandleControlDragTracking", (PyCFunction)CtlObj_HandleControlDragTracking, 1,
2116 "(DragTrackingMessage inMessage, DragReference inDrag) -> (Boolean outLikesDrag)"},
2117#endif
2118
2119#if TARGET_API_MAC_CARBON
2120 {"HandleControlDragReceive", (PyCFunction)CtlObj_HandleControlDragReceive, 1,
2121 "(DragReference inDrag) -> None"},
2122#endif
2123
2124#if TARGET_API_MAC_CARBON
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002125 {"SetControlDragTrackingEnabled", (PyCFunction)CtlObj_SetControlDragTrackingEnabled, 1,
2126 "(Boolean tracks) -> None"},
2127#endif
2128
2129#if TARGET_API_MAC_CARBON
2130 {"IsControlDragTrackingEnabled", (PyCFunction)CtlObj_IsControlDragTrackingEnabled, 1,
2131 "() -> (Boolean tracks)"},
2132#endif
2133
2134#if ACCESSOR_CALLS_ARE_FUNCTIONS
2135 {"GetControlBounds", (PyCFunction)CtlObj_GetControlBounds, 1,
2136 "() -> (Rect _rv, Rect bounds)"},
2137#endif
2138
2139#if ACCESSOR_CALLS_ARE_FUNCTIONS
2140 {"IsControlHilited", (PyCFunction)CtlObj_IsControlHilited, 1,
2141 "() -> (Boolean _rv)"},
2142#endif
2143
2144#if ACCESSOR_CALLS_ARE_FUNCTIONS
2145 {"GetControlHilite", (PyCFunction)CtlObj_GetControlHilite, 1,
2146 "() -> (UInt16 _rv)"},
2147#endif
2148
2149#if ACCESSOR_CALLS_ARE_FUNCTIONS
2150 {"GetControlOwner", (PyCFunction)CtlObj_GetControlOwner, 1,
2151 "() -> (WindowPtr _rv)"},
2152#endif
2153
2154#if ACCESSOR_CALLS_ARE_FUNCTIONS
2155 {"GetControlDataHandle", (PyCFunction)CtlObj_GetControlDataHandle, 1,
2156 "() -> (Handle _rv)"},
2157#endif
2158
2159#if ACCESSOR_CALLS_ARE_FUNCTIONS
2160 {"GetControlPopupMenuHandle", (PyCFunction)CtlObj_GetControlPopupMenuHandle, 1,
2161 "() -> (MenuHandle _rv)"},
2162#endif
2163
2164#if ACCESSOR_CALLS_ARE_FUNCTIONS
2165 {"GetControlPopupMenuID", (PyCFunction)CtlObj_GetControlPopupMenuID, 1,
2166 "() -> (short _rv)"},
2167#endif
2168
2169#if ACCESSOR_CALLS_ARE_FUNCTIONS
2170 {"SetControlDataHandle", (PyCFunction)CtlObj_SetControlDataHandle, 1,
2171 "(Handle dataHandle) -> None"},
2172#endif
2173
2174#if ACCESSOR_CALLS_ARE_FUNCTIONS
2175 {"SetControlBounds", (PyCFunction)CtlObj_SetControlBounds, 1,
2176 "(Rect bounds) -> None"},
2177#endif
2178
2179#if ACCESSOR_CALLS_ARE_FUNCTIONS
2180 {"SetControlPopupMenuHandle", (PyCFunction)CtlObj_SetControlPopupMenuHandle, 1,
2181 "(MenuHandle popupMenu) -> None"},
2182#endif
2183
2184#if ACCESSOR_CALLS_ARE_FUNCTIONS
2185 {"SetControlPopupMenuID", (PyCFunction)CtlObj_SetControlPopupMenuID, 1,
2186 "(short menuID) -> None"},
2187#endif
2188 {"GetBevelButtonMenuValue", (PyCFunction)CtlObj_GetBevelButtonMenuValue, 1,
2189 "() -> (SInt16 outValue)"},
2190 {"SetBevelButtonMenuValue", (PyCFunction)CtlObj_SetBevelButtonMenuValue, 1,
2191 "(SInt16 inValue) -> None"},
2192 {"GetBevelButtonMenuHandle", (PyCFunction)CtlObj_GetBevelButtonMenuHandle, 1,
2193 "() -> (MenuHandle outHandle)"},
2194 {"SetBevelButtonTransform", (PyCFunction)CtlObj_SetBevelButtonTransform, 1,
2195 "(IconTransformType transform) -> None"},
2196 {"SetDisclosureTriangleLastValue", (PyCFunction)CtlObj_SetDisclosureTriangleLastValue, 1,
2197 "(SInt16 inValue) -> None"},
2198 {"GetTabContentRect", (PyCFunction)CtlObj_GetTabContentRect, 1,
2199 "() -> (Rect outContentRect)"},
2200 {"SetTabEnabled", (PyCFunction)CtlObj_SetTabEnabled, 1,
2201 "(SInt16 inTabToHilite, Boolean inEnabled) -> None"},
2202 {"SetImageWellTransform", (PyCFunction)CtlObj_SetImageWellTransform, 1,
2203 "(IconTransformType inTransform) -> None"},
Jack Jansen5d56f4b1995-06-18 20:16:33 +00002204 {"as_Resource", (PyCFunction)CtlObj_as_Resource, 1,
Jack Jansena1a0fef1999-12-23 14:32:06 +00002205 "() -> (Handle _rv)"},
Jack Jansen1a7d5b12000-03-21 16:25:23 +00002206 {"GetControlRect", (PyCFunction)CtlObj_GetControlRect, 1,
2207 "() -> (Rect rect)"},
Jack Jansencfb60ee1996-10-01 10:46:46 +00002208 {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1,
2209 "() -> None"},
Jack Jansen848250c1998-05-28 14:20:09 +00002210 {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00002211 "(Point startPoint [,trackercallback]) -> (ControlPartCode _rv)"},
2212 {"HandleControlClick", (PyCFunction)CtlObj_HandleControlClick, 1,
2213 "(Point startPoint, Integer modifiers, [,trackercallback]) -> (ControlPartCode _rv)"},
2214 {"SetControlData", (PyCFunction)CtlObj_SetControlData, 1,
2215 "(stuff) -> None"},
2216 {"GetControlData", (PyCFunction)CtlObj_GetControlData, 1,
2217 "(part, type) -> String"},
Jack Jansen1f9249c1999-12-19 00:05:50 +00002218 {"SetControlDataHandle", (PyCFunction)CtlObj_SetControlDataHandle, 1,
2219 "(ResObj) -> None"},
2220 {"GetControlDataHandle", (PyCFunction)CtlObj_GetControlDataHandle, 1,
2221 "(part, type) -> ResObj"},
Jack Jansene79dc762000-06-02 21:35:07 +00002222
Jack Jansen74a1e632000-07-14 22:37:27 +00002223#if !TARGET_API_MAC_CARBON_NOTYET
Jack Jansenabc411b2000-03-20 16:09:09 +00002224 {"SetControlDataCallback", (PyCFunction)CtlObj_SetControlDataCallback, 1,
2225 "(callbackfunc) -> None"},
Jack Jansene79dc762000-06-02 21:35:07 +00002226#endif
2227
Jack Jansen74a1e632000-07-14 22:37:27 +00002228#if !TARGET_API_MAC_CARBON_NOTYET
Jack Jansen4c704131998-06-19 13:35:14 +00002229 {"GetPopupData", (PyCFunction)CtlObj_GetPopupData, 1,
2230 NULL},
Jack Jansene79dc762000-06-02 21:35:07 +00002231#endif
2232
Jack Jansen74a1e632000-07-14 22:37:27 +00002233#if !TARGET_API_MAC_CARBON_NOTYET
Jack Jansen4c704131998-06-19 13:35:14 +00002234 {"SetPopupData", (PyCFunction)CtlObj_SetPopupData, 1,
2235 NULL},
Jack Jansene79dc762000-06-02 21:35:07 +00002236#endif
Guido van Rossum17448e21995-01-30 11:53:55 +00002237 {NULL, NULL, 0}
2238};
2239
2240PyMethodChain CtlObj_chain = { CtlObj_methods, NULL };
2241
2242static PyObject *CtlObj_getattr(self, name)
2243 ControlObject *self;
2244 char *name;
2245{
2246 return Py_FindMethodInChain(&CtlObj_chain, (PyObject *)self, name);
2247}
2248
2249#define CtlObj_setattr NULL
2250
Jack Jansen8387af61999-03-13 23:07:32 +00002251static int CtlObj_compare(self, other)
2252 ControlObject *self, *other;
2253{
2254 unsigned long v, w;
2255
2256 if (!CtlObj_Check((PyObject *)other))
2257 {
2258 v=(unsigned long)self;
2259 w=(unsigned long)other;
2260 }
2261 else
2262 {
2263 v=(unsigned long)self->ob_itself;
2264 w=(unsigned long)other->ob_itself;
2265 }
2266 if( v < w ) return -1;
2267 if( v > w ) return 1;
2268 return 0;
2269}
2270
2271#define CtlObj_repr NULL
2272
2273static long CtlObj_hash(self)
2274 ControlObject *self;
2275{
2276 return (long)self->ob_itself;
2277}
2278
Guido van Rossum17448e21995-01-30 11:53:55 +00002279PyTypeObject Control_Type = {
2280 PyObject_HEAD_INIT(&PyType_Type)
2281 0, /*ob_size*/
2282 "Control", /*tp_name*/
2283 sizeof(ControlObject), /*tp_basicsize*/
2284 0, /*tp_itemsize*/
2285 /* methods */
2286 (destructor) CtlObj_dealloc, /*tp_dealloc*/
2287 0, /*tp_print*/
2288 (getattrfunc) CtlObj_getattr, /*tp_getattr*/
2289 (setattrfunc) CtlObj_setattr, /*tp_setattr*/
Jack Jansen8387af61999-03-13 23:07:32 +00002290 (cmpfunc) CtlObj_compare, /*tp_compare*/
2291 (reprfunc) CtlObj_repr, /*tp_repr*/
2292 (PyNumberMethods *)0, /* tp_as_number */
2293 (PySequenceMethods *)0, /* tp_as_sequence */
2294 (PyMappingMethods *)0, /* tp_as_mapping */
2295 (hashfunc) CtlObj_hash, /*tp_hash*/
Guido van Rossum17448e21995-01-30 11:53:55 +00002296};
2297
2298/* -------------------- End object type Control --------------------- */
2299
2300
2301static PyObject *Ctl_NewControl(_self, _args)
2302 PyObject *_self;
2303 PyObject *_args;
2304{
2305 PyObject *_res = NULL;
2306 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00002307 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00002308 Rect boundsRect;
Jack Jansen21f96871998-02-20 16:02:09 +00002309 Str255 controlTitle;
2310 Boolean initiallyVisible;
2311 SInt16 initialValue;
2312 SInt16 minimumValue;
2313 SInt16 maximumValue;
Jack Jansen7d0bc831995-06-09 20:56:31 +00002314 SInt16 procID;
Jack Jansen21f96871998-02-20 16:02:09 +00002315 SInt32 controlReference;
Guido van Rossum17448e21995-01-30 11:53:55 +00002316 if (!PyArg_ParseTuple(_args, "O&O&O&bhhhhl",
Jack Jansen21f96871998-02-20 16:02:09 +00002317 WinObj_Convert, &owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00002318 PyMac_GetRect, &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00002319 PyMac_GetStr255, controlTitle,
2320 &initiallyVisible,
2321 &initialValue,
2322 &minimumValue,
2323 &maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00002324 &procID,
Jack Jansen21f96871998-02-20 16:02:09 +00002325 &controlReference))
Guido van Rossum17448e21995-01-30 11:53:55 +00002326 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00002327 _rv = NewControl(owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00002328 &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00002329 controlTitle,
2330 initiallyVisible,
2331 initialValue,
2332 minimumValue,
2333 maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00002334 procID,
Jack Jansen21f96871998-02-20 16:02:09 +00002335 controlReference);
Guido van Rossum17448e21995-01-30 11:53:55 +00002336 _res = Py_BuildValue("O&",
2337 CtlObj_New, _rv);
2338 return _res;
2339}
2340
2341static PyObject *Ctl_GetNewControl(_self, _args)
2342 PyObject *_self;
2343 PyObject *_args;
2344{
2345 PyObject *_res = NULL;
2346 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00002347 SInt16 resourceID;
2348 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00002349 if (!PyArg_ParseTuple(_args, "hO&",
Jack Jansen21f96871998-02-20 16:02:09 +00002350 &resourceID,
2351 WinObj_Convert, &owningWindow))
Guido van Rossum17448e21995-01-30 11:53:55 +00002352 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00002353 _rv = GetNewControl(resourceID,
2354 owningWindow);
Guido van Rossum17448e21995-01-30 11:53:55 +00002355 _res = Py_BuildValue("O&",
2356 CtlObj_New, _rv);
2357 return _res;
2358}
2359
Guido van Rossum17448e21995-01-30 11:53:55 +00002360static PyObject *Ctl_DrawControls(_self, _args)
2361 PyObject *_self;
2362 PyObject *_args;
2363{
2364 PyObject *_res = NULL;
2365 WindowPtr theWindow;
2366 if (!PyArg_ParseTuple(_args, "O&",
2367 WinObj_Convert, &theWindow))
2368 return NULL;
2369 DrawControls(theWindow);
2370 Py_INCREF(Py_None);
2371 _res = Py_None;
2372 return _res;
2373}
2374
Guido van Rossum17448e21995-01-30 11:53:55 +00002375static PyObject *Ctl_UpdateControls(_self, _args)
2376 PyObject *_self;
2377 PyObject *_args;
2378{
2379 PyObject *_res = NULL;
2380 WindowPtr theWindow;
Jack Jansen2b724171996-04-10 14:48:19 +00002381 RgnHandle updateRegion;
2382 if (!PyArg_ParseTuple(_args, "O&O&",
2383 WinObj_Convert, &theWindow,
2384 ResObj_Convert, &updateRegion))
Guido van Rossum17448e21995-01-30 11:53:55 +00002385 return NULL;
2386 UpdateControls(theWindow,
Jack Jansen2b724171996-04-10 14:48:19 +00002387 updateRegion);
Guido van Rossum17448e21995-01-30 11:53:55 +00002388 Py_INCREF(Py_None);
2389 _res = Py_None;
2390 return _res;
2391}
2392
2393static PyObject *Ctl_FindControl(_self, _args)
2394 PyObject *_self;
2395 PyObject *_args;
2396{
2397 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +00002398 ControlPartCode _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00002399 Point testPoint;
Guido van Rossum17448e21995-01-30 11:53:55 +00002400 WindowPtr theWindow;
2401 ControlHandle theControl;
2402 if (!PyArg_ParseTuple(_args, "O&O&",
Jack Jansen21f96871998-02-20 16:02:09 +00002403 PyMac_GetPoint, &testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00002404 WinObj_Convert, &theWindow))
2405 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00002406 _rv = FindControl(testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00002407 theWindow,
2408 &theControl);
2409 _res = Py_BuildValue("hO&",
2410 _rv,
2411 CtlObj_WhichControl, theControl);
2412 return _res;
2413}
2414
Jack Jansen21f96871998-02-20 16:02:09 +00002415static PyObject *Ctl_FindControlUnderMouse(_self, _args)
2416 PyObject *_self;
2417 PyObject *_args;
2418{
2419 PyObject *_res = NULL;
2420 ControlHandle _rv;
2421 Point inWhere;
2422 WindowPtr inWindow;
2423 SInt16 outPart;
2424 if (!PyArg_ParseTuple(_args, "O&O&",
2425 PyMac_GetPoint, &inWhere,
2426 WinObj_Convert, &inWindow))
2427 return NULL;
2428 _rv = FindControlUnderMouse(inWhere,
2429 inWindow,
2430 &outPart);
2431 _res = Py_BuildValue("O&h",
2432 CtlObj_New, _rv,
2433 outPart);
2434 return _res;
2435}
2436
2437static PyObject *Ctl_IdleControls(_self, _args)
2438 PyObject *_self;
2439 PyObject *_args;
2440{
2441 PyObject *_res = NULL;
2442 WindowPtr inWindow;
2443 if (!PyArg_ParseTuple(_args, "O&",
2444 WinObj_Convert, &inWindow))
2445 return NULL;
2446 IdleControls(inWindow);
2447 Py_INCREF(Py_None);
2448 _res = Py_None;
2449 return _res;
2450}
2451
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002452#if TARGET_API_MAC_CARBON
2453
2454static PyObject *Ctl_GetControlByID(_self, _args)
2455 PyObject *_self;
2456 PyObject *_args;
2457{
2458 PyObject *_res = NULL;
2459 OSStatus _err;
2460 WindowPtr inWindow;
2461 ControlID inID;
2462 ControlHandle outControl;
2463 if (!PyArg_ParseTuple(_args, "O&O&",
2464 WinObj_Convert, &inWindow,
2465 PyControlID_Convert, &inID))
2466 return NULL;
2467 _err = GetControlByID(inWindow,
2468 &inID,
2469 &outControl);
2470 if (_err != noErr) return PyMac_Error(_err);
2471 _res = Py_BuildValue("O&",
2472 CtlObj_WhichControl, outControl);
2473 return _res;
2474}
2475#endif
2476
Jack Jansen21f96871998-02-20 16:02:09 +00002477static PyObject *Ctl_DumpControlHierarchy(_self, _args)
2478 PyObject *_self;
2479 PyObject *_args;
2480{
2481 PyObject *_res = NULL;
2482 OSErr _err;
2483 WindowPtr inWindow;
2484 FSSpec inDumpFile;
2485 if (!PyArg_ParseTuple(_args, "O&O&",
2486 WinObj_Convert, &inWindow,
2487 PyMac_GetFSSpec, &inDumpFile))
2488 return NULL;
2489 _err = DumpControlHierarchy(inWindow,
2490 &inDumpFile);
2491 if (_err != noErr) return PyMac_Error(_err);
2492 Py_INCREF(Py_None);
2493 _res = Py_None;
2494 return _res;
2495}
2496
2497static PyObject *Ctl_CreateRootControl(_self, _args)
2498 PyObject *_self;
2499 PyObject *_args;
2500{
2501 PyObject *_res = NULL;
2502 OSErr _err;
2503 WindowPtr inWindow;
2504 ControlHandle outControl;
2505 if (!PyArg_ParseTuple(_args, "O&",
2506 WinObj_Convert, &inWindow))
2507 return NULL;
2508 _err = CreateRootControl(inWindow,
2509 &outControl);
2510 if (_err != noErr) return PyMac_Error(_err);
2511 _res = Py_BuildValue("O&",
2512 CtlObj_WhichControl, outControl);
2513 return _res;
2514}
2515
2516static PyObject *Ctl_GetRootControl(_self, _args)
2517 PyObject *_self;
2518 PyObject *_args;
2519{
2520 PyObject *_res = NULL;
2521 OSErr _err;
2522 WindowPtr inWindow;
2523 ControlHandle outControl;
2524 if (!PyArg_ParseTuple(_args, "O&",
2525 WinObj_Convert, &inWindow))
2526 return NULL;
2527 _err = GetRootControl(inWindow,
2528 &outControl);
2529 if (_err != noErr) return PyMac_Error(_err);
2530 _res = Py_BuildValue("O&",
2531 CtlObj_WhichControl, outControl);
2532 return _res;
2533}
2534
2535static PyObject *Ctl_GetKeyboardFocus(_self, _args)
2536 PyObject *_self;
2537 PyObject *_args;
2538{
2539 PyObject *_res = NULL;
2540 OSErr _err;
2541 WindowPtr inWindow;
2542 ControlHandle outControl;
2543 if (!PyArg_ParseTuple(_args, "O&",
2544 WinObj_Convert, &inWindow))
2545 return NULL;
2546 _err = GetKeyboardFocus(inWindow,
2547 &outControl);
2548 if (_err != noErr) return PyMac_Error(_err);
2549 _res = Py_BuildValue("O&",
2550 CtlObj_WhichControl, outControl);
2551 return _res;
2552}
2553
2554static PyObject *Ctl_SetKeyboardFocus(_self, _args)
2555 PyObject *_self;
2556 PyObject *_args;
2557{
2558 PyObject *_res = NULL;
2559 OSErr _err;
2560 WindowPtr inWindow;
2561 ControlHandle inControl;
2562 ControlFocusPart inPart;
2563 if (!PyArg_ParseTuple(_args, "O&O&h",
2564 WinObj_Convert, &inWindow,
2565 CtlObj_Convert, &inControl,
2566 &inPart))
2567 return NULL;
2568 _err = SetKeyboardFocus(inWindow,
2569 inControl,
2570 inPart);
2571 if (_err != noErr) return PyMac_Error(_err);
2572 Py_INCREF(Py_None);
2573 _res = Py_None;
2574 return _res;
2575}
2576
2577static PyObject *Ctl_AdvanceKeyboardFocus(_self, _args)
2578 PyObject *_self;
2579 PyObject *_args;
2580{
2581 PyObject *_res = NULL;
2582 OSErr _err;
2583 WindowPtr inWindow;
2584 if (!PyArg_ParseTuple(_args, "O&",
2585 WinObj_Convert, &inWindow))
2586 return NULL;
2587 _err = AdvanceKeyboardFocus(inWindow);
2588 if (_err != noErr) return PyMac_Error(_err);
2589 Py_INCREF(Py_None);
2590 _res = Py_None;
2591 return _res;
2592}
2593
2594static PyObject *Ctl_ReverseKeyboardFocus(_self, _args)
2595 PyObject *_self;
2596 PyObject *_args;
2597{
2598 PyObject *_res = NULL;
2599 OSErr _err;
2600 WindowPtr inWindow;
2601 if (!PyArg_ParseTuple(_args, "O&",
2602 WinObj_Convert, &inWindow))
2603 return NULL;
2604 _err = ReverseKeyboardFocus(inWindow);
2605 if (_err != noErr) return PyMac_Error(_err);
2606 Py_INCREF(Py_None);
2607 _res = Py_None;
2608 return _res;
2609}
2610
2611static PyObject *Ctl_ClearKeyboardFocus(_self, _args)
2612 PyObject *_self;
2613 PyObject *_args;
2614{
2615 PyObject *_res = NULL;
2616 OSErr _err;
2617 WindowPtr inWindow;
2618 if (!PyArg_ParseTuple(_args, "O&",
2619 WinObj_Convert, &inWindow))
2620 return NULL;
2621 _err = ClearKeyboardFocus(inWindow);
2622 if (_err != noErr) return PyMac_Error(_err);
2623 Py_INCREF(Py_None);
2624 _res = Py_None;
2625 return _res;
2626}
2627
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002628#if TARGET_API_MAC_CARBON
2629
2630static PyObject *Ctl_SetAutomaticControlDragTrackingEnabledForWindow(_self, _args)
2631 PyObject *_self;
2632 PyObject *_args;
2633{
2634 PyObject *_res = NULL;
2635 OSStatus _err;
2636 WindowPtr theWindow;
2637 Boolean tracks;
2638 if (!PyArg_ParseTuple(_args, "O&b",
2639 WinObj_Convert, &theWindow,
2640 &tracks))
2641 return NULL;
2642 _err = SetAutomaticControlDragTrackingEnabledForWindow(theWindow,
2643 tracks);
2644 if (_err != noErr) return PyMac_Error(_err);
2645 Py_INCREF(Py_None);
2646 _res = Py_None;
2647 return _res;
2648}
2649#endif
2650
2651#if TARGET_API_MAC_CARBON
2652
2653static PyObject *Ctl_IsAutomaticControlDragTrackingEnabledForWindow(_self, _args)
2654 PyObject *_self;
2655 PyObject *_args;
2656{
2657 PyObject *_res = NULL;
2658 OSStatus _err;
2659 WindowPtr theWindow;
2660 Boolean tracks;
2661 if (!PyArg_ParseTuple(_args, "O&",
2662 WinObj_Convert, &theWindow))
2663 return NULL;
2664 _err = IsAutomaticControlDragTrackingEnabledForWindow(theWindow,
2665 &tracks);
2666 if (_err != noErr) return PyMac_Error(_err);
2667 _res = Py_BuildValue("b",
2668 tracks);
2669 return _res;
2670}
2671#endif
2672
Jack Jansene0581891999-02-07 14:02:03 +00002673static PyObject *Ctl_as_Control(_self, _args)
2674 PyObject *_self;
2675 PyObject *_args;
2676{
2677 PyObject *_res = NULL;
2678 ControlHandle _rv;
2679 Handle h;
2680 if (!PyArg_ParseTuple(_args, "O&",
2681 ResObj_Convert, &h))
2682 return NULL;
2683 _rv = as_Control(h);
2684 _res = Py_BuildValue("O&",
2685 CtlObj_New, _rv);
2686 return _res;
2687}
2688
Guido van Rossum17448e21995-01-30 11:53:55 +00002689static PyMethodDef Ctl_methods[] = {
2690 {"NewControl", (PyCFunction)Ctl_NewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00002691 "(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 +00002692 {"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00002693 "(SInt16 resourceID, WindowPtr owningWindow) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002694 {"DrawControls", (PyCFunction)Ctl_DrawControls, 1,
2695 "(WindowPtr theWindow) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002696 {"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1,
Jack Jansen2b724171996-04-10 14:48:19 +00002697 "(WindowPtr theWindow, RgnHandle updateRegion) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002698 {"FindControl", (PyCFunction)Ctl_FindControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00002699 "(Point testPoint, WindowPtr theWindow) -> (ControlPartCode _rv, ControlHandle theControl)"},
2700 {"FindControlUnderMouse", (PyCFunction)Ctl_FindControlUnderMouse, 1,
2701 "(Point inWhere, WindowPtr inWindow) -> (ControlHandle _rv, SInt16 outPart)"},
2702 {"IdleControls", (PyCFunction)Ctl_IdleControls, 1,
2703 "(WindowPtr inWindow) -> None"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002704
2705#if TARGET_API_MAC_CARBON
2706 {"GetControlByID", (PyCFunction)Ctl_GetControlByID, 1,
2707 "(WindowPtr inWindow, ControlID inID) -> (ControlHandle outControl)"},
2708#endif
Jack Jansen21f96871998-02-20 16:02:09 +00002709 {"DumpControlHierarchy", (PyCFunction)Ctl_DumpControlHierarchy, 1,
2710 "(WindowPtr inWindow, FSSpec inDumpFile) -> None"},
2711 {"CreateRootControl", (PyCFunction)Ctl_CreateRootControl, 1,
2712 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
2713 {"GetRootControl", (PyCFunction)Ctl_GetRootControl, 1,
2714 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
2715 {"GetKeyboardFocus", (PyCFunction)Ctl_GetKeyboardFocus, 1,
2716 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
2717 {"SetKeyboardFocus", (PyCFunction)Ctl_SetKeyboardFocus, 1,
2718 "(WindowPtr inWindow, ControlHandle inControl, ControlFocusPart inPart) -> None"},
2719 {"AdvanceKeyboardFocus", (PyCFunction)Ctl_AdvanceKeyboardFocus, 1,
2720 "(WindowPtr inWindow) -> None"},
2721 {"ReverseKeyboardFocus", (PyCFunction)Ctl_ReverseKeyboardFocus, 1,
2722 "(WindowPtr inWindow) -> None"},
2723 {"ClearKeyboardFocus", (PyCFunction)Ctl_ClearKeyboardFocus, 1,
2724 "(WindowPtr inWindow) -> None"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002725
2726#if TARGET_API_MAC_CARBON
2727 {"SetAutomaticControlDragTrackingEnabledForWindow", (PyCFunction)Ctl_SetAutomaticControlDragTrackingEnabledForWindow, 1,
2728 "(WindowPtr theWindow, Boolean tracks) -> None"},
2729#endif
2730
2731#if TARGET_API_MAC_CARBON
2732 {"IsAutomaticControlDragTrackingEnabledForWindow", (PyCFunction)Ctl_IsAutomaticControlDragTrackingEnabledForWindow, 1,
2733 "(WindowPtr theWindow) -> (Boolean tracks)"},
2734#endif
Jack Jansene0581891999-02-07 14:02:03 +00002735 {"as_Control", (PyCFunction)Ctl_as_Control, 1,
2736 "(Handle h) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002737 {NULL, NULL, 0}
2738};
2739
2740
2741
Jack Jansen9d8b96c2000-07-14 22:16:45 +00002742static PyObject *
2743CtlObj_NewUnmanaged(itself)
Jack Jansen8387af61999-03-13 23:07:32 +00002744 ControlHandle itself;
2745{
2746 ControlObject *it;
2747 if (itself == NULL) return PyMac_Error(resNotFound);
2748 it = PyObject_NEW(ControlObject, &Control_Type);
2749 if (it == NULL) return NULL;
2750 it->ob_itself = itself;
Jack Jansen1a7d5b12000-03-21 16:25:23 +00002751 it->ob_callbackdict = NULL;
Jack Jansen8387af61999-03-13 23:07:32 +00002752 return (PyObject *)it;
2753}
2754
Jack Jansen9d8b96c2000-07-14 22:16:45 +00002755static PyObject *
Guido van Rossum17448e21995-01-30 11:53:55 +00002756CtlObj_WhichControl(ControlHandle c)
2757{
2758 PyObject *it;
Jack Jansen24c35311999-12-09 22:49:51 +00002759
Guido van Rossum17448e21995-01-30 11:53:55 +00002760 if (c == NULL)
Guido van Rossum17448e21995-01-30 11:53:55 +00002761 it = Py_None;
Jack Jansen8387af61999-03-13 23:07:32 +00002762 else {
2763 it = (PyObject *) GetControlReference(c);
2764 /*
2765 ** If the refcon is zero or doesn't point back to the Python object
2766 ** the control is not ours. Return a temporary object.
2767 */
2768 if (it == NULL || ((ControlObject *)it)->ob_itself != c)
2769 return CtlObj_NewUnmanaged(c);
2770 }
Guido van Rossum17448e21995-01-30 11:53:55 +00002771 Py_INCREF(it);
2772 return it;
2773}
2774
Jack Jansen848250c1998-05-28 14:20:09 +00002775static int
2776settrackfunc(obj)
2777 PyObject *obj;
2778{
2779 if (tracker) {
2780 PyErr_SetString(Ctl_Error, "Tracker function in use");
2781 return 0;
2782 }
2783 tracker = obj;
2784 Py_INCREF(tracker);
2785}
2786
2787static void
2788clrtrackfunc()
2789{
2790 Py_XDECREF(tracker);
2791 tracker = 0;
2792}
2793
2794static pascal void
Jack Jansene79dc762000-06-02 21:35:07 +00002795mytracker(ControlHandle ctl, short part)
Jack Jansen848250c1998-05-28 14:20:09 +00002796{
2797 PyObject *args, *rv=0;
Jack Jansen24c35311999-12-09 22:49:51 +00002798
Jack Jansen848250c1998-05-28 14:20:09 +00002799 args = Py_BuildValue("(O&i)", CtlObj_WhichControl, ctl, (int)part);
2800 if (args && tracker) {
2801 rv = PyEval_CallObject(tracker, args);
2802 Py_DECREF(args);
2803 }
2804 if (rv)
2805 Py_DECREF(rv);
2806 else
Jack Jansen24c35311999-12-09 22:49:51 +00002807 PySys_WriteStderr("TrackControl or HandleControlClick: exception in tracker function\n");
Jack Jansen848250c1998-05-28 14:20:09 +00002808}
2809
Jack Jansen74a1e632000-07-14 22:37:27 +00002810#if !TARGET_API_MAC_CARBON_NOTYET
Jack Jansenabc411b2000-03-20 16:09:09 +00002811static int
Jack Jansen85152b92000-07-11 21:12:55 +00002812setcallback(myself, which, callback, uppp)
2813 PyObject *myself;
Jack Jansenabc411b2000-03-20 16:09:09 +00002814 OSType which;
2815 PyObject *callback;
2816 UniversalProcPtr *uppp;
2817{
Jack Jansen85152b92000-07-11 21:12:55 +00002818 ControlObject *self = (ControlObject *)myself;
Jack Jansenabc411b2000-03-20 16:09:09 +00002819 char keybuf[9];
2820
2821 if ( which == kControlUserPaneDrawProcTag )
Jack Jansen1b6e8212000-04-05 21:30:57 +00002822 *uppp = (UniversalProcPtr)mydrawproc_upp;
Jack Jansenabc411b2000-03-20 16:09:09 +00002823 else if ( which == kControlUserPaneIdleProcTag )
Jack Jansen1b6e8212000-04-05 21:30:57 +00002824 *uppp = (UniversalProcPtr)myidleproc_upp;
Jack Jansena27e9fb2000-03-21 23:03:02 +00002825 else if ( which == kControlUserPaneHitTestProcTag )
Jack Jansen1b6e8212000-04-05 21:30:57 +00002826 *uppp = (UniversalProcPtr)myhittestproc_upp;
Jack Jansena27e9fb2000-03-21 23:03:02 +00002827 else if ( which == kControlUserPaneTrackingProcTag )
Jack Jansen1b6e8212000-04-05 21:30:57 +00002828 *uppp = (UniversalProcPtr)mytrackingproc_upp;
Jack Jansenabc411b2000-03-20 16:09:09 +00002829 else
2830 return -1;
2831 /* Only now do we test for clearing of the callback: */
2832 if ( callback == Py_None )
2833 *uppp = NULL;
2834 /* Create the dict if it doesn't exist yet (so we don't get such a dict for every control) */
2835 if ( self->ob_callbackdict == NULL )
2836 if ( (self->ob_callbackdict = PyDict_New()) == NULL )
2837 return -1;
2838 /* And store the Python callback */
2839 sprintf(keybuf, "%x", which);
2840 if (PyDict_SetItemString(self->ob_callbackdict, keybuf, callback) < 0)
2841 return -1;
2842 return 0;
2843}
2844
2845static PyObject *
2846callcallback(self, which, arglist)
2847 ControlObject *self;
2848 OSType which;
2849 PyObject *arglist;
2850{
2851 char keybuf[9];
2852 PyObject *func, *rv;
2853
2854 sprintf(keybuf, "%x", which);
2855 if ( self->ob_callbackdict == NULL ||
2856 (func = PyDict_GetItemString(self->ob_callbackdict, keybuf)) == NULL ) {
Jack Jansena27e9fb2000-03-21 23:03:02 +00002857 PySys_WriteStderr("Control callback %x without callback object\n", which);
Jack Jansenabc411b2000-03-20 16:09:09 +00002858 return NULL;
2859 }
2860 rv = PyEval_CallObject(func, arglist);
2861 if ( rv == NULL )
Jack Jansena27e9fb2000-03-21 23:03:02 +00002862 PySys_WriteStderr("Exception in control callback %x handler\n", which);
Jack Jansenabc411b2000-03-20 16:09:09 +00002863 return rv;
2864}
2865
2866static pascal void
2867mydrawproc(ControlHandle control, SInt16 part)
2868{
2869 ControlObject *ctl_obj;
2870 PyObject *arglist, *rv;
2871
2872 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
2873 arglist = Py_BuildValue("Oh", ctl_obj, part);
2874 rv = callcallback(ctl_obj, kControlUserPaneDrawProcTag, arglist);
2875 Py_XDECREF(arglist);
2876 Py_XDECREF(rv);
2877}
2878
2879static pascal void
2880myidleproc(ControlHandle control)
2881{
2882 ControlObject *ctl_obj;
2883 PyObject *arglist, *rv;
2884
2885 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
2886 arglist = Py_BuildValue("O", ctl_obj);
2887 rv = callcallback(ctl_obj, kControlUserPaneIdleProcTag, arglist);
2888 Py_XDECREF(arglist);
2889 Py_XDECREF(rv);
2890}
2891
Jack Jansena27e9fb2000-03-21 23:03:02 +00002892static pascal ControlPartCode
2893myhittestproc(ControlHandle control, Point where)
2894{
2895 ControlObject *ctl_obj;
2896 PyObject *arglist, *rv;
2897 short c_rv = -1;
2898
2899 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
Jack Jansendeb63732000-03-22 15:35:24 +00002900 arglist = Py_BuildValue("OO&", ctl_obj, PyMac_BuildPoint, where);
Jack Jansena27e9fb2000-03-21 23:03:02 +00002901 rv = callcallback(ctl_obj, kControlUserPaneHitTestProcTag, arglist);
2902 Py_XDECREF(arglist);
2903 /* Ignore errors, nothing we can do about them */
2904 if ( rv )
2905 PyArg_Parse(rv, "h", &c_rv);
2906 Py_XDECREF(rv);
2907 return (ControlPartCode)c_rv;
2908}
2909
2910static pascal ControlPartCode
2911mytrackingproc(ControlHandle control, Point startPt, ControlActionUPP actionProc)
2912{
2913 ControlObject *ctl_obj;
2914 PyObject *arglist, *rv;
2915 short c_rv = -1;
2916
2917 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
2918 /* We cannot pass the actionProc without lots of work */
Jack Jansendeb63732000-03-22 15:35:24 +00002919 arglist = Py_BuildValue("OO&", ctl_obj, PyMac_BuildPoint, startPt);
Jack Jansena27e9fb2000-03-21 23:03:02 +00002920 rv = callcallback(ctl_obj, kControlUserPaneTrackingProcTag, arglist);
2921 Py_XDECREF(arglist);
2922 if ( rv )
2923 PyArg_Parse(rv, "h", &c_rv);
2924 Py_XDECREF(rv);
2925 return (ControlPartCode)c_rv;
2926}
Jack Jansene79dc762000-06-02 21:35:07 +00002927#endif
Jack Jansenabc411b2000-03-20 16:09:09 +00002928
Guido van Rossum17448e21995-01-30 11:53:55 +00002929
2930void initCtl()
2931{
2932 PyObject *m;
2933 PyObject *d;
2934
2935
2936
Jack Jansen848250c1998-05-28 14:20:09 +00002937 mytracker_upp = NewControlActionProc(mytracker);
Jack Jansen74a1e632000-07-14 22:37:27 +00002938#if !TARGET_API_MAC_CARBON_NOTYET
Jack Jansenabc411b2000-03-20 16:09:09 +00002939 mydrawproc_upp = NewControlUserPaneDrawProc(mydrawproc);
Jack Jansen1b6e8212000-04-05 21:30:57 +00002940 myidleproc_upp = NewControlUserPaneIdleProc(myidleproc);
Jack Jansena27e9fb2000-03-21 23:03:02 +00002941 myhittestproc_upp = NewControlUserPaneHitTestProc(myhittestproc);
2942 mytrackingproc_upp = NewControlUserPaneTrackingProc(mytrackingproc);
Jack Jansene79dc762000-06-02 21:35:07 +00002943#endif
Jack Jansen848250c1998-05-28 14:20:09 +00002944
Guido van Rossum17448e21995-01-30 11:53:55 +00002945
2946 m = Py_InitModule("Ctl", Ctl_methods);
2947 d = PyModule_GetDict(m);
2948 Ctl_Error = PyMac_GetOSErrException();
2949 if (Ctl_Error == NULL ||
2950 PyDict_SetItemString(d, "Error", Ctl_Error) != 0)
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002951 return;
Jack Jansena755e681997-09-20 17:40:22 +00002952 Control_Type.ob_type = &PyType_Type;
2953 Py_INCREF(&Control_Type);
2954 if (PyDict_SetItemString(d, "ControlType", (PyObject *)&Control_Type) != 0)
2955 Py_FatalError("can't initialize ControlType");
Guido van Rossum17448e21995-01-30 11:53:55 +00002956}
2957
2958/* ========================= End module Ctl ========================= */
2959