blob: 743a1f5d9abc25f0714d2caa390310e83ad81903 [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;
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001280 Rect bounds;
1281 if (!PyArg_ParseTuple(_args, ""))
1282 return NULL;
Jack Jansena9e3db32001-01-09 22:10:16 +00001283 GetControlBounds(_self->ob_itself,
1284 &bounds);
1285 _res = Py_BuildValue("O&",
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001286 PyMac_BuildRect, &bounds);
1287 return _res;
1288}
1289#endif
1290
1291#if ACCESSOR_CALLS_ARE_FUNCTIONS
1292
1293static PyObject *CtlObj_IsControlHilited(_self, _args)
1294 ControlObject *_self;
1295 PyObject *_args;
1296{
1297 PyObject *_res = NULL;
1298 Boolean _rv;
1299 if (!PyArg_ParseTuple(_args, ""))
1300 return NULL;
1301 _rv = IsControlHilited(_self->ob_itself);
1302 _res = Py_BuildValue("b",
1303 _rv);
1304 return _res;
1305}
1306#endif
1307
1308#if ACCESSOR_CALLS_ARE_FUNCTIONS
1309
1310static PyObject *CtlObj_GetControlHilite(_self, _args)
1311 ControlObject *_self;
1312 PyObject *_args;
1313{
1314 PyObject *_res = NULL;
1315 UInt16 _rv;
1316 if (!PyArg_ParseTuple(_args, ""))
1317 return NULL;
1318 _rv = GetControlHilite(_self->ob_itself);
1319 _res = Py_BuildValue("H",
1320 _rv);
1321 return _res;
1322}
1323#endif
1324
1325#if ACCESSOR_CALLS_ARE_FUNCTIONS
1326
1327static PyObject *CtlObj_GetControlOwner(_self, _args)
1328 ControlObject *_self;
1329 PyObject *_args;
1330{
1331 PyObject *_res = NULL;
1332 WindowPtr _rv;
1333 if (!PyArg_ParseTuple(_args, ""))
1334 return NULL;
1335 _rv = GetControlOwner(_self->ob_itself);
1336 _res = Py_BuildValue("O&",
1337 WinObj_New, _rv);
1338 return _res;
1339}
1340#endif
1341
1342#if ACCESSOR_CALLS_ARE_FUNCTIONS
1343
1344static PyObject *CtlObj_GetControlDataHandle(_self, _args)
1345 ControlObject *_self;
1346 PyObject *_args;
1347{
1348 PyObject *_res = NULL;
1349 Handle _rv;
1350 if (!PyArg_ParseTuple(_args, ""))
1351 return NULL;
1352 _rv = GetControlDataHandle(_self->ob_itself);
1353 _res = Py_BuildValue("O&",
1354 ResObj_New, _rv);
1355 return _res;
1356}
1357#endif
1358
1359#if ACCESSOR_CALLS_ARE_FUNCTIONS
1360
1361static PyObject *CtlObj_GetControlPopupMenuHandle(_self, _args)
1362 ControlObject *_self;
1363 PyObject *_args;
1364{
1365 PyObject *_res = NULL;
1366 MenuHandle _rv;
1367 if (!PyArg_ParseTuple(_args, ""))
1368 return NULL;
1369 _rv = GetControlPopupMenuHandle(_self->ob_itself);
1370 _res = Py_BuildValue("O&",
1371 MenuObj_New, _rv);
1372 return _res;
1373}
1374#endif
1375
1376#if ACCESSOR_CALLS_ARE_FUNCTIONS
1377
1378static PyObject *CtlObj_GetControlPopupMenuID(_self, _args)
1379 ControlObject *_self;
1380 PyObject *_args;
1381{
1382 PyObject *_res = NULL;
1383 short _rv;
1384 if (!PyArg_ParseTuple(_args, ""))
1385 return NULL;
1386 _rv = GetControlPopupMenuID(_self->ob_itself);
1387 _res = Py_BuildValue("h",
1388 _rv);
1389 return _res;
1390}
1391#endif
1392
1393#if ACCESSOR_CALLS_ARE_FUNCTIONS
1394
1395static PyObject *CtlObj_SetControlDataHandle(_self, _args)
1396 ControlObject *_self;
1397 PyObject *_args;
1398{
1399 PyObject *_res = NULL;
1400 Handle dataHandle;
1401 if (!PyArg_ParseTuple(_args, "O&",
1402 ResObj_Convert, &dataHandle))
1403 return NULL;
1404 SetControlDataHandle(_self->ob_itself,
1405 dataHandle);
1406 Py_INCREF(Py_None);
1407 _res = Py_None;
1408 return _res;
1409}
1410#endif
1411
1412#if ACCESSOR_CALLS_ARE_FUNCTIONS
1413
1414static PyObject *CtlObj_SetControlBounds(_self, _args)
1415 ControlObject *_self;
1416 PyObject *_args;
1417{
1418 PyObject *_res = NULL;
1419 Rect bounds;
1420 if (!PyArg_ParseTuple(_args, "O&",
1421 PyMac_GetRect, &bounds))
1422 return NULL;
1423 SetControlBounds(_self->ob_itself,
1424 &bounds);
1425 Py_INCREF(Py_None);
1426 _res = Py_None;
1427 return _res;
1428}
1429#endif
1430
1431#if ACCESSOR_CALLS_ARE_FUNCTIONS
1432
1433static PyObject *CtlObj_SetControlPopupMenuHandle(_self, _args)
1434 ControlObject *_self;
1435 PyObject *_args;
1436{
1437 PyObject *_res = NULL;
1438 MenuHandle popupMenu;
1439 if (!PyArg_ParseTuple(_args, "O&",
1440 MenuObj_Convert, &popupMenu))
1441 return NULL;
1442 SetControlPopupMenuHandle(_self->ob_itself,
1443 popupMenu);
1444 Py_INCREF(Py_None);
1445 _res = Py_None;
1446 return _res;
1447}
1448#endif
1449
1450#if ACCESSOR_CALLS_ARE_FUNCTIONS
1451
1452static PyObject *CtlObj_SetControlPopupMenuID(_self, _args)
1453 ControlObject *_self;
1454 PyObject *_args;
1455{
1456 PyObject *_res = NULL;
1457 short menuID;
1458 if (!PyArg_ParseTuple(_args, "h",
1459 &menuID))
1460 return NULL;
1461 SetControlPopupMenuID(_self->ob_itself,
1462 menuID);
1463 Py_INCREF(Py_None);
1464 _res = Py_None;
1465 return _res;
1466}
1467#endif
1468
1469static PyObject *CtlObj_GetBevelButtonMenuValue(_self, _args)
1470 ControlObject *_self;
1471 PyObject *_args;
1472{
1473 PyObject *_res = NULL;
1474 OSErr _err;
1475 SInt16 outValue;
1476 if (!PyArg_ParseTuple(_args, ""))
1477 return NULL;
1478 _err = GetBevelButtonMenuValue(_self->ob_itself,
1479 &outValue);
1480 if (_err != noErr) return PyMac_Error(_err);
1481 _res = Py_BuildValue("h",
1482 outValue);
1483 return _res;
1484}
1485
1486static PyObject *CtlObj_SetBevelButtonMenuValue(_self, _args)
1487 ControlObject *_self;
1488 PyObject *_args;
1489{
1490 PyObject *_res = NULL;
1491 OSErr _err;
1492 SInt16 inValue;
1493 if (!PyArg_ParseTuple(_args, "h",
1494 &inValue))
1495 return NULL;
1496 _err = SetBevelButtonMenuValue(_self->ob_itself,
1497 inValue);
1498 if (_err != noErr) return PyMac_Error(_err);
1499 Py_INCREF(Py_None);
1500 _res = Py_None;
1501 return _res;
1502}
1503
1504static PyObject *CtlObj_GetBevelButtonMenuHandle(_self, _args)
1505 ControlObject *_self;
1506 PyObject *_args;
1507{
1508 PyObject *_res = NULL;
1509 OSErr _err;
1510 MenuHandle outHandle;
1511 if (!PyArg_ParseTuple(_args, ""))
1512 return NULL;
1513 _err = GetBevelButtonMenuHandle(_self->ob_itself,
1514 &outHandle);
1515 if (_err != noErr) return PyMac_Error(_err);
1516 _res = Py_BuildValue("O&",
1517 MenuObj_New, outHandle);
1518 return _res;
1519}
1520
1521static PyObject *CtlObj_SetBevelButtonTransform(_self, _args)
1522 ControlObject *_self;
1523 PyObject *_args;
1524{
1525 PyObject *_res = NULL;
1526 OSErr _err;
1527 IconTransformType transform;
1528 if (!PyArg_ParseTuple(_args, "h",
1529 &transform))
1530 return NULL;
1531 _err = SetBevelButtonTransform(_self->ob_itself,
1532 transform);
1533 if (_err != noErr) return PyMac_Error(_err);
1534 Py_INCREF(Py_None);
1535 _res = Py_None;
1536 return _res;
1537}
1538
1539static PyObject *CtlObj_SetDisclosureTriangleLastValue(_self, _args)
1540 ControlObject *_self;
1541 PyObject *_args;
1542{
1543 PyObject *_res = NULL;
1544 OSErr _err;
1545 SInt16 inValue;
1546 if (!PyArg_ParseTuple(_args, "h",
1547 &inValue))
1548 return NULL;
1549 _err = SetDisclosureTriangleLastValue(_self->ob_itself,
1550 inValue);
1551 if (_err != noErr) return PyMac_Error(_err);
1552 Py_INCREF(Py_None);
1553 _res = Py_None;
1554 return _res;
1555}
1556
1557static PyObject *CtlObj_GetTabContentRect(_self, _args)
1558 ControlObject *_self;
1559 PyObject *_args;
1560{
1561 PyObject *_res = NULL;
1562 OSErr _err;
1563 Rect outContentRect;
1564 if (!PyArg_ParseTuple(_args, ""))
1565 return NULL;
1566 _err = GetTabContentRect(_self->ob_itself,
1567 &outContentRect);
1568 if (_err != noErr) return PyMac_Error(_err);
1569 _res = Py_BuildValue("O&",
1570 PyMac_BuildRect, &outContentRect);
1571 return _res;
1572}
1573
1574static PyObject *CtlObj_SetTabEnabled(_self, _args)
1575 ControlObject *_self;
1576 PyObject *_args;
1577{
1578 PyObject *_res = NULL;
1579 OSErr _err;
1580 SInt16 inTabToHilite;
1581 Boolean inEnabled;
1582 if (!PyArg_ParseTuple(_args, "hb",
1583 &inTabToHilite,
1584 &inEnabled))
1585 return NULL;
1586 _err = SetTabEnabled(_self->ob_itself,
1587 inTabToHilite,
1588 inEnabled);
1589 if (_err != noErr) return PyMac_Error(_err);
1590 Py_INCREF(Py_None);
1591 _res = Py_None;
1592 return _res;
1593}
1594
1595static PyObject *CtlObj_SetImageWellTransform(_self, _args)
1596 ControlObject *_self;
1597 PyObject *_args;
1598{
1599 PyObject *_res = NULL;
1600 OSErr _err;
1601 IconTransformType inTransform;
1602 if (!PyArg_ParseTuple(_args, "h",
1603 &inTransform))
1604 return NULL;
1605 _err = SetImageWellTransform(_self->ob_itself,
1606 inTransform);
1607 if (_err != noErr) return PyMac_Error(_err);
1608 Py_INCREF(Py_None);
1609 _res = Py_None;
1610 return _res;
1611}
1612
Jack Jansen5d56f4b1995-06-18 20:16:33 +00001613static PyObject *CtlObj_as_Resource(_self, _args)
1614 ControlObject *_self;
1615 PyObject *_args;
1616{
1617 PyObject *_res = NULL;
Jack Jansena1a0fef1999-12-23 14:32:06 +00001618 Handle _rv;
1619 if (!PyArg_ParseTuple(_args, ""))
1620 return NULL;
1621 _rv = as_Resource(_self->ob_itself);
1622 _res = Py_BuildValue("O&",
1623 ResObj_New, _rv);
1624 return _res;
Jack Jansen5d56f4b1995-06-18 20:16:33 +00001625}
1626
Jack Jansen1a7d5b12000-03-21 16:25:23 +00001627static PyObject *CtlObj_GetControlRect(_self, _args)
1628 ControlObject *_self;
1629 PyObject *_args;
1630{
1631 PyObject *_res = NULL;
1632 Rect rect;
1633 if (!PyArg_ParseTuple(_args, ""))
1634 return NULL;
1635 GetControlRect(_self->ob_itself,
1636 &rect);
1637 _res = Py_BuildValue("O&",
1638 PyMac_BuildRect, &rect);
1639 return _res;
1640}
1641
Jack Jansencfb60ee1996-10-01 10:46:46 +00001642static PyObject *CtlObj_DisposeControl(_self, _args)
1643 ControlObject *_self;
1644 PyObject *_args;
1645{
1646 PyObject *_res = NULL;
1647
1648 if (!PyArg_ParseTuple(_args, ""))
1649 return NULL;
1650 if ( _self->ob_itself ) {
Jack Jansen85ae4a81997-04-08 15:26:03 +00001651 SetControlReference(_self->ob_itself, (long)0); /* Make it forget about us */
Jack Jansencfb60ee1996-10-01 10:46:46 +00001652 DisposeControl(_self->ob_itself);
1653 _self->ob_itself = NULL;
1654 }
1655 Py_INCREF(Py_None);
1656 _res = Py_None;
1657 return _res;
1658
1659}
1660
Jack Jansen848250c1998-05-28 14:20:09 +00001661static PyObject *CtlObj_TrackControl(_self, _args)
1662 ControlObject *_self;
1663 PyObject *_args;
1664{
1665 PyObject *_res = NULL;
1666
1667 ControlPartCode _rv;
1668 Point startPoint;
1669 ControlActionUPP upp = 0;
1670 PyObject *callback = 0;
1671
1672 if (!PyArg_ParseTuple(_args, "O&|O",
1673 PyMac_GetPoint, &startPoint, &callback))
1674 return NULL;
1675 if (callback && callback != Py_None) {
1676 if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
1677 upp = (ControlActionUPP)-1;
1678 else {
1679 settrackfunc(callback);
1680 upp = mytracker_upp;
1681 }
1682 }
1683 _rv = TrackControl(_self->ob_itself,
1684 startPoint,
1685 upp);
1686 clrtrackfunc();
1687 _res = Py_BuildValue("h",
1688 _rv);
1689 return _res;
1690
1691}
1692
Jack Jansen24c35311999-12-09 22:49:51 +00001693static PyObject *CtlObj_HandleControlClick(_self, _args)
1694 ControlObject *_self;
1695 PyObject *_args;
1696{
1697 PyObject *_res = NULL;
1698
1699 ControlPartCode _rv;
1700 Point startPoint;
1701 SInt16 modifiers;
1702 ControlActionUPP upp = 0;
1703 PyObject *callback = 0;
1704
1705 if (!PyArg_ParseTuple(_args, "O&h|O",
1706 PyMac_GetPoint, &startPoint,
1707 &modifiers,
1708 &callback))
1709 return NULL;
1710 if (callback && callback != Py_None) {
1711 if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
1712 upp = (ControlActionUPP)-1;
1713 else {
1714 settrackfunc(callback);
1715 upp = mytracker_upp;
1716 }
1717 }
1718 _rv = HandleControlClick(_self->ob_itself,
1719 startPoint,
1720 modifiers,
1721 upp);
1722 clrtrackfunc();
1723 _res = Py_BuildValue("h",
1724 _rv);
1725 return _res;
1726
1727}
1728
1729static PyObject *CtlObj_SetControlData(_self, _args)
1730 ControlObject *_self;
1731 PyObject *_args;
1732{
1733 PyObject *_res = NULL;
1734
1735 OSErr _err;
1736 ControlPartCode inPart;
1737 ResType inTagName;
1738 Size bufferSize;
1739 Ptr buffer;
1740
1741 if (!PyArg_ParseTuple(_args, "hO&s#",
1742 &inPart,
1743 PyMac_GetOSType, &inTagName,
1744 &buffer, &bufferSize))
1745 return NULL;
1746
1747 _err = SetControlData(_self->ob_itself,
1748 inPart,
1749 inTagName,
1750 bufferSize,
1751 buffer);
1752
1753 if (_err != noErr)
1754 return PyMac_Error(_err);
1755 _res = Py_None;
1756 return _res;
1757
1758}
1759
1760static PyObject *CtlObj_GetControlData(_self, _args)
1761 ControlObject *_self;
1762 PyObject *_args;
1763{
1764 PyObject *_res = NULL;
1765
1766 OSErr _err;
1767 ControlPartCode inPart;
1768 ResType inTagName;
1769 Size bufferSize;
1770 Ptr buffer;
1771 Size outSize;
1772
1773 if (!PyArg_ParseTuple(_args, "hO&",
1774 &inPart,
1775 PyMac_GetOSType, &inTagName))
1776 return NULL;
1777
1778 /* allocate a buffer for the data */
1779 _err = GetControlDataSize(_self->ob_itself,
1780 inPart,
1781 inTagName,
1782 &bufferSize);
1783 if (_err != noErr)
1784 return PyMac_Error(_err);
1785 buffer = PyMem_NEW(char, bufferSize);
1786 if (buffer == NULL)
1787 return PyErr_NoMemory();
1788
1789 _err = GetControlData(_self->ob_itself,
1790 inPart,
1791 inTagName,
1792 bufferSize,
1793 buffer,
1794 &outSize);
1795
1796 if (_err != noErr) {
1797 PyMem_DEL(buffer);
1798 return PyMac_Error(_err);
1799 }
1800 _res = Py_BuildValue("s#", buffer, outSize);
1801 PyMem_DEL(buffer);
1802 return _res;
1803
1804}
1805
Jack Jansena9e3db32001-01-09 22:10:16 +00001806static PyObject *CtlObj_SetControlData_Handle(_self, _args)
Jack Jansen1f9249c1999-12-19 00:05:50 +00001807 ControlObject *_self;
1808 PyObject *_args;
1809{
1810 PyObject *_res = NULL;
1811
1812 OSErr _err;
1813 ControlPartCode inPart;
1814 ResType inTagName;
1815 Handle buffer;
1816
1817 if (!PyArg_ParseTuple(_args, "hO&O&",
1818 &inPart,
1819 PyMac_GetOSType, &inTagName,
Jack Jansenb9247d31999-12-23 23:06:07 +00001820 OptResObj_Convert, &buffer))
Jack Jansen1f9249c1999-12-19 00:05:50 +00001821 return NULL;
1822
1823 _err = SetControlData(_self->ob_itself,
1824 inPart,
1825 inTagName,
1826 sizeof(buffer),
Jack Jansenf7ac1d31999-12-29 12:37:22 +00001827 (Ptr)&buffer);
Jack Jansen1f9249c1999-12-19 00:05:50 +00001828
1829 if (_err != noErr)
1830 return PyMac_Error(_err);
1831 _res = Py_None;
1832 return _res;
1833
1834}
1835
Jack Jansena9e3db32001-01-09 22:10:16 +00001836static PyObject *CtlObj_GetControlData_Handle(_self, _args)
Jack Jansen1f9249c1999-12-19 00:05:50 +00001837 ControlObject *_self;
1838 PyObject *_args;
1839{
1840 PyObject *_res = NULL;
1841
1842 OSErr _err;
1843 ControlPartCode inPart;
1844 ResType inTagName;
1845 Size bufferSize;
1846 Handle hdl;
1847
1848 if (!PyArg_ParseTuple(_args, "hO&",
1849 &inPart,
1850 PyMac_GetOSType, &inTagName))
1851 return NULL;
1852
1853 /* Check it is handle-sized */
1854 _err = GetControlDataSize(_self->ob_itself,
1855 inPart,
1856 inTagName,
1857 &bufferSize);
1858 if (_err != noErr)
1859 return PyMac_Error(_err);
1860 if (bufferSize != sizeof(Handle)) {
1861 PyErr_SetString(Ctl_Error, "GetControlDataSize() != sizeof(Handle)");
1862 return NULL;
1863 }
1864
1865 _err = GetControlData(_self->ob_itself,
1866 inPart,
1867 inTagName,
1868 sizeof(Handle),
1869 (Ptr)&hdl,
1870 &bufferSize);
1871
1872 if (_err != noErr) {
1873 return PyMac_Error(_err);
1874 }
1875 return Py_BuildValue("O&", OptResObj_New, hdl);
1876
1877}
1878
Jack Jansen74a1e632000-07-14 22:37:27 +00001879#if !TARGET_API_MAC_CARBON_NOTYET
Jack Jansene79dc762000-06-02 21:35:07 +00001880
Jack Jansena9e3db32001-01-09 22:10:16 +00001881static PyObject *CtlObj_SetControlData_Callback(_self, _args)
Jack Jansenabc411b2000-03-20 16:09:09 +00001882 ControlObject *_self;
1883 PyObject *_args;
1884{
1885 PyObject *_res = NULL;
1886
1887 OSErr _err;
1888 ControlPartCode inPart;
1889 ResType inTagName;
1890 PyObject *callback;
Jack Jansen85152b92000-07-11 21:12:55 +00001891 UniversalProcPtr c_callback;
Jack Jansenabc411b2000-03-20 16:09:09 +00001892
1893 if (!PyArg_ParseTuple(_args, "hO&O",
1894 &inPart,
1895 PyMac_GetOSType, &inTagName,
1896 &callback))
1897 return NULL;
1898
Jack Jansen85152b92000-07-11 21:12:55 +00001899 if ( setcallback((PyObject *)_self, inTagName, callback, &c_callback) < 0 )
Jack Jansenabc411b2000-03-20 16:09:09 +00001900 return NULL;
1901 _err = SetControlData(_self->ob_itself,
1902 inPart,
1903 inTagName,
1904 sizeof(c_callback),
1905 (Ptr)&c_callback);
1906
1907 if (_err != noErr)
1908 return PyMac_Error(_err);
1909 _res = Py_None;
1910 return _res;
1911
1912}
Jack Jansene79dc762000-06-02 21:35:07 +00001913#endif
1914
Jack Jansen74a1e632000-07-14 22:37:27 +00001915#if !TARGET_API_MAC_CARBON_NOTYET
Jack Jansenabc411b2000-03-20 16:09:09 +00001916
Jack Jansen4c704131998-06-19 13:35:14 +00001917static PyObject *CtlObj_GetPopupData(_self, _args)
1918 ControlObject *_self;
1919 PyObject *_args;
1920{
1921 PyObject *_res = NULL;
1922
1923 PopupPrivateDataHandle hdl;
1924
1925 if ( (*_self->ob_itself)->contrlData == NULL ) {
1926 PyErr_SetString(Ctl_Error, "No contrlData handle in control");
1927 return 0;
1928 }
1929 hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
1930 HLock((Handle)hdl);
1931 _res = Py_BuildValue("O&i", MenuObj_New, (*hdl)->mHandle, (int)(*hdl)->mID);
1932 HUnlock((Handle)hdl);
1933 return _res;
1934
1935}
Jack Jansene79dc762000-06-02 21:35:07 +00001936#endif
1937
Jack Jansen74a1e632000-07-14 22:37:27 +00001938#if !TARGET_API_MAC_CARBON_NOTYET
Jack Jansen4c704131998-06-19 13:35:14 +00001939
1940static PyObject *CtlObj_SetPopupData(_self, _args)
1941 ControlObject *_self;
1942 PyObject *_args;
1943{
1944 PyObject *_res = NULL;
1945
1946 PopupPrivateDataHandle hdl;
1947 MenuHandle mHandle;
1948 short mID;
1949
1950 if (!PyArg_ParseTuple(_args, "O&h", MenuObj_Convert, &mHandle, &mID) )
1951 return 0;
1952 if ( (*_self->ob_itself)->contrlData == NULL ) {
1953 PyErr_SetString(Ctl_Error, "No contrlData handle in control");
1954 return 0;
1955 }
1956 hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
1957 (*hdl)->mHandle = mHandle;
1958 (*hdl)->mID = mID;
1959 Py_INCREF(Py_None);
1960 return Py_None;
1961
1962}
Jack Jansene79dc762000-06-02 21:35:07 +00001963#endif
Jack Jansen4c704131998-06-19 13:35:14 +00001964
Guido van Rossum17448e21995-01-30 11:53:55 +00001965static PyMethodDef CtlObj_methods[] = {
Jack Jansen21f96871998-02-20 16:02:09 +00001966 {"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1,
1967 "(ControlPartCode hiliteState) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001968 {"ShowControl", (PyCFunction)CtlObj_ShowControl, 1,
1969 "() -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001970 {"HideControl", (PyCFunction)CtlObj_HideControl, 1,
1971 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001972 {"IsControlActive", (PyCFunction)CtlObj_IsControlActive, 1,
1973 "() -> (Boolean _rv)"},
1974 {"IsControlVisible", (PyCFunction)CtlObj_IsControlVisible, 1,
1975 "() -> (Boolean _rv)"},
1976 {"ActivateControl", (PyCFunction)CtlObj_ActivateControl, 1,
1977 "() -> None"},
1978 {"DeactivateControl", (PyCFunction)CtlObj_DeactivateControl, 1,
1979 "() -> None"},
1980 {"SetControlVisibility", (PyCFunction)CtlObj_SetControlVisibility, 1,
1981 "(Boolean inIsVisible, Boolean inDoDraw) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001982 {"Draw1Control", (PyCFunction)CtlObj_Draw1Control, 1,
1983 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001984 {"GetBestControlRect", (PyCFunction)CtlObj_GetBestControlRect, 1,
1985 "() -> (Rect outRect, SInt16 outBaseLineOffset)"},
1986 {"SetControlFontStyle", (PyCFunction)CtlObj_SetControlFontStyle, 1,
1987 "(ControlFontStyleRec inStyle) -> None"},
1988 {"DrawControlInCurrentPort", (PyCFunction)CtlObj_DrawControlInCurrentPort, 1,
1989 "() -> None"},
1990 {"SetUpControlBackground", (PyCFunction)CtlObj_SetUpControlBackground, 1,
1991 "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +00001992 {"SetUpControlTextColor", (PyCFunction)CtlObj_SetUpControlTextColor, 1,
1993 "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001994 {"DragControl", (PyCFunction)CtlObj_DragControl, 1,
Jack Jansen754d4a41995-11-14 10:41:55 +00001995 "(Point startPoint, Rect limitRect, Rect slopRect, DragConstraint axis) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001996 {"TestControl", (PyCFunction)CtlObj_TestControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001997 "(Point testPoint) -> (ControlPartCode _rv)"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00001998
1999#if TARGET_API_MAC_CARBON
2000 {"HandleControlContextualMenuClick", (PyCFunction)CtlObj_HandleControlContextualMenuClick, 1,
2001 "(Point inWhere) -> (Boolean menuDisplayed)"},
2002#endif
2003
2004#if TARGET_API_MAC_CARBON
2005 {"GetControlClickActivation", (PyCFunction)CtlObj_GetControlClickActivation, 1,
2006 "(Point inWhere, EventModifiers inModifiers) -> (ClickActivationResult outResult)"},
2007#endif
Jack Jansen21f96871998-02-20 16:02:09 +00002008 {"HandleControlKey", (PyCFunction)CtlObj_HandleControlKey, 1,
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002009 "(SInt16 inKeyCode, SInt16 inCharCode, EventModifiers inModifiers) -> (SInt16 _rv)"},
2010
2011#if TARGET_API_MAC_CARBON
2012 {"HandleControlSetCursor", (PyCFunction)CtlObj_HandleControlSetCursor, 1,
2013 "(Point localPoint, EventModifiers modifiers) -> (Boolean cursorWasSet)"},
2014#endif
Guido van Rossum17448e21995-01-30 11:53:55 +00002015 {"MoveControl", (PyCFunction)CtlObj_MoveControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00002016 "(SInt16 h, SInt16 v) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002017 {"SizeControl", (PyCFunction)CtlObj_SizeControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00002018 "(SInt16 w, SInt16 h) -> None"},
2019 {"SetControlTitle", (PyCFunction)CtlObj_SetControlTitle, 1,
2020 "(Str255 title) -> None"},
2021 {"GetControlTitle", (PyCFunction)CtlObj_GetControlTitle, 1,
Jack Jansen41009001999-03-07 20:05:20 +00002022 "() -> (Str255 title)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00002023 {"GetControlValue", (PyCFunction)CtlObj_GetControlValue, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00002024 "() -> (SInt16 _rv)"},
2025 {"SetControlValue", (PyCFunction)CtlObj_SetControlValue, 1,
2026 "(SInt16 newValue) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00002027 {"GetControlMinimum", (PyCFunction)CtlObj_GetControlMinimum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00002028 "() -> (SInt16 _rv)"},
2029 {"SetControlMinimum", (PyCFunction)CtlObj_SetControlMinimum, 1,
2030 "(SInt16 newMinimum) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00002031 {"GetControlMaximum", (PyCFunction)CtlObj_GetControlMaximum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00002032 "() -> (SInt16 _rv)"},
2033 {"SetControlMaximum", (PyCFunction)CtlObj_SetControlMaximum, 1,
2034 "(SInt16 newMaximum) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +00002035 {"GetControlViewSize", (PyCFunction)CtlObj_GetControlViewSize, 1,
2036 "() -> (SInt32 _rv)"},
2037 {"SetControlViewSize", (PyCFunction)CtlObj_SetControlViewSize, 1,
2038 "(SInt32 newViewSize) -> None"},
2039 {"GetControl32BitValue", (PyCFunction)CtlObj_GetControl32BitValue, 1,
2040 "() -> (SInt32 _rv)"},
2041 {"SetControl32BitValue", (PyCFunction)CtlObj_SetControl32BitValue, 1,
2042 "(SInt32 newValue) -> None"},
2043 {"GetControl32BitMaximum", (PyCFunction)CtlObj_GetControl32BitMaximum, 1,
2044 "() -> (SInt32 _rv)"},
2045 {"SetControl32BitMaximum", (PyCFunction)CtlObj_SetControl32BitMaximum, 1,
2046 "(SInt32 newMaximum) -> None"},
2047 {"GetControl32BitMinimum", (PyCFunction)CtlObj_GetControl32BitMinimum, 1,
2048 "() -> (SInt32 _rv)"},
2049 {"SetControl32BitMinimum", (PyCFunction)CtlObj_SetControl32BitMinimum, 1,
2050 "(SInt32 newMinimum) -> None"},
2051 {"IsValidControlHandle", (PyCFunction)CtlObj_IsValidControlHandle, 1,
2052 "() -> (Boolean _rv)"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002053
2054#if TARGET_API_MAC_CARBON
2055 {"SetControlID", (PyCFunction)CtlObj_SetControlID, 1,
2056 "(ControlID inID) -> None"},
2057#endif
2058
2059#if TARGET_API_MAC_CARBON
2060 {"GetControlID", (PyCFunction)CtlObj_GetControlID, 1,
2061 "() -> (ControlID outID)"},
2062#endif
Jack Jansena05ac601999-12-12 21:41:51 +00002063 {"RemoveControlProperty", (PyCFunction)CtlObj_RemoveControlProperty, 1,
Jack Jansene79dc762000-06-02 21:35:07 +00002064 "(OSType propertyCreator, OSType propertyTag) -> None"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002065
2066#if TARGET_API_MAC_CARBON
2067 {"GetControlPropertyAttributes", (PyCFunction)CtlObj_GetControlPropertyAttributes, 1,
2068 "(OSType propertyCreator, OSType propertyTag) -> (UInt32 attributes)"},
2069#endif
2070
2071#if TARGET_API_MAC_CARBON
2072 {"ChangeControlPropertyAttributes", (PyCFunction)CtlObj_ChangeControlPropertyAttributes, 1,
2073 "(OSType propertyCreator, OSType propertyTag, UInt32 attributesToSet, UInt32 attributesToClear) -> None"},
2074#endif
Jack Jansena05ac601999-12-12 21:41:51 +00002075 {"GetControlRegion", (PyCFunction)CtlObj_GetControlRegion, 1,
Jack Jansene79dc762000-06-02 21:35:07 +00002076 "(ControlPartCode inPart, RgnHandle outRegion) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00002077 {"GetControlVariant", (PyCFunction)CtlObj_GetControlVariant, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00002078 "() -> (ControlVariant _rv)"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00002079 {"SetControlReference", (PyCFunction)CtlObj_SetControlReference, 1,
2080 "(SInt32 data) -> None"},
2081 {"GetControlReference", (PyCFunction)CtlObj_GetControlReference, 1,
2082 "() -> (SInt32 _rv)"},
Jack Jansene79dc762000-06-02 21:35:07 +00002083
Jack Jansen74a1e632000-07-14 22:37:27 +00002084#if !TARGET_API_MAC_CARBON
Jack Jansenc7fefed1997-08-15 14:32:18 +00002085 {"GetAuxiliaryControlRecord", (PyCFunction)CtlObj_GetAuxiliaryControlRecord, 1,
2086 "() -> (Boolean _rv, AuxCtlHandle acHndl)"},
Jack Jansene79dc762000-06-02 21:35:07 +00002087#endif
2088
Jack Jansen74a1e632000-07-14 22:37:27 +00002089#if !TARGET_API_MAC_CARBON
Jack Jansenc7fefed1997-08-15 14:32:18 +00002090 {"SetControlColor", (PyCFunction)CtlObj_SetControlColor, 1,
2091 "(CCTabHandle newColorTable) -> None"},
Jack Jansene79dc762000-06-02 21:35:07 +00002092#endif
Jack Jansen21f96871998-02-20 16:02:09 +00002093 {"SendControlMessage", (PyCFunction)CtlObj_SendControlMessage, 1,
2094 "(SInt16 inMessage, SInt32 inParam) -> (SInt32 _rv)"},
2095 {"EmbedControl", (PyCFunction)CtlObj_EmbedControl, 1,
2096 "(ControlHandle inContainer) -> None"},
2097 {"AutoEmbedControl", (PyCFunction)CtlObj_AutoEmbedControl, 1,
2098 "(WindowPtr inWindow) -> None"},
2099 {"GetSuperControl", (PyCFunction)CtlObj_GetSuperControl, 1,
2100 "() -> (ControlHandle outParent)"},
2101 {"CountSubControls", (PyCFunction)CtlObj_CountSubControls, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00002102 "() -> (UInt16 outNumChildren)"},
Jack Jansen21f96871998-02-20 16:02:09 +00002103 {"GetIndexedSubControl", (PyCFunction)CtlObj_GetIndexedSubControl, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00002104 "(UInt16 inIndex) -> (ControlHandle outSubControl)"},
Jack Jansen21f96871998-02-20 16:02:09 +00002105 {"SetControlSupervisor", (PyCFunction)CtlObj_SetControlSupervisor, 1,
2106 "(ControlHandle inBoss) -> None"},
2107 {"GetControlFeatures", (PyCFunction)CtlObj_GetControlFeatures, 1,
2108 "() -> (UInt32 outFeatures)"},
2109 {"GetControlDataSize", (PyCFunction)CtlObj_GetControlDataSize, 1,
2110 "(ControlPartCode inPart, ResType inTagName) -> (Size outMaxSize)"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002111
2112#if TARGET_API_MAC_CARBON
Jack Jansen723ad8a2000-12-12 22:10:21 +00002113 {"HandleControlDragTracking", (PyCFunction)CtlObj_HandleControlDragTracking, 1,
2114 "(DragTrackingMessage inMessage, DragReference inDrag) -> (Boolean outLikesDrag)"},
2115#endif
2116
2117#if TARGET_API_MAC_CARBON
2118 {"HandleControlDragReceive", (PyCFunction)CtlObj_HandleControlDragReceive, 1,
2119 "(DragReference inDrag) -> None"},
2120#endif
2121
2122#if TARGET_API_MAC_CARBON
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002123 {"SetControlDragTrackingEnabled", (PyCFunction)CtlObj_SetControlDragTrackingEnabled, 1,
2124 "(Boolean tracks) -> None"},
2125#endif
2126
2127#if TARGET_API_MAC_CARBON
2128 {"IsControlDragTrackingEnabled", (PyCFunction)CtlObj_IsControlDragTrackingEnabled, 1,
2129 "() -> (Boolean tracks)"},
2130#endif
2131
2132#if ACCESSOR_CALLS_ARE_FUNCTIONS
2133 {"GetControlBounds", (PyCFunction)CtlObj_GetControlBounds, 1,
Jack Jansena9e3db32001-01-09 22:10:16 +00002134 "() -> (Rect bounds)"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002135#endif
2136
2137#if ACCESSOR_CALLS_ARE_FUNCTIONS
2138 {"IsControlHilited", (PyCFunction)CtlObj_IsControlHilited, 1,
2139 "() -> (Boolean _rv)"},
2140#endif
2141
2142#if ACCESSOR_CALLS_ARE_FUNCTIONS
2143 {"GetControlHilite", (PyCFunction)CtlObj_GetControlHilite, 1,
2144 "() -> (UInt16 _rv)"},
2145#endif
2146
2147#if ACCESSOR_CALLS_ARE_FUNCTIONS
2148 {"GetControlOwner", (PyCFunction)CtlObj_GetControlOwner, 1,
2149 "() -> (WindowPtr _rv)"},
2150#endif
2151
2152#if ACCESSOR_CALLS_ARE_FUNCTIONS
2153 {"GetControlDataHandle", (PyCFunction)CtlObj_GetControlDataHandle, 1,
2154 "() -> (Handle _rv)"},
2155#endif
2156
2157#if ACCESSOR_CALLS_ARE_FUNCTIONS
2158 {"GetControlPopupMenuHandle", (PyCFunction)CtlObj_GetControlPopupMenuHandle, 1,
2159 "() -> (MenuHandle _rv)"},
2160#endif
2161
2162#if ACCESSOR_CALLS_ARE_FUNCTIONS
2163 {"GetControlPopupMenuID", (PyCFunction)CtlObj_GetControlPopupMenuID, 1,
2164 "() -> (short _rv)"},
2165#endif
2166
2167#if ACCESSOR_CALLS_ARE_FUNCTIONS
2168 {"SetControlDataHandle", (PyCFunction)CtlObj_SetControlDataHandle, 1,
2169 "(Handle dataHandle) -> None"},
2170#endif
2171
2172#if ACCESSOR_CALLS_ARE_FUNCTIONS
2173 {"SetControlBounds", (PyCFunction)CtlObj_SetControlBounds, 1,
2174 "(Rect bounds) -> None"},
2175#endif
2176
2177#if ACCESSOR_CALLS_ARE_FUNCTIONS
2178 {"SetControlPopupMenuHandle", (PyCFunction)CtlObj_SetControlPopupMenuHandle, 1,
2179 "(MenuHandle popupMenu) -> None"},
2180#endif
2181
2182#if ACCESSOR_CALLS_ARE_FUNCTIONS
2183 {"SetControlPopupMenuID", (PyCFunction)CtlObj_SetControlPopupMenuID, 1,
2184 "(short menuID) -> None"},
2185#endif
2186 {"GetBevelButtonMenuValue", (PyCFunction)CtlObj_GetBevelButtonMenuValue, 1,
2187 "() -> (SInt16 outValue)"},
2188 {"SetBevelButtonMenuValue", (PyCFunction)CtlObj_SetBevelButtonMenuValue, 1,
2189 "(SInt16 inValue) -> None"},
2190 {"GetBevelButtonMenuHandle", (PyCFunction)CtlObj_GetBevelButtonMenuHandle, 1,
2191 "() -> (MenuHandle outHandle)"},
2192 {"SetBevelButtonTransform", (PyCFunction)CtlObj_SetBevelButtonTransform, 1,
2193 "(IconTransformType transform) -> None"},
2194 {"SetDisclosureTriangleLastValue", (PyCFunction)CtlObj_SetDisclosureTriangleLastValue, 1,
2195 "(SInt16 inValue) -> None"},
2196 {"GetTabContentRect", (PyCFunction)CtlObj_GetTabContentRect, 1,
2197 "() -> (Rect outContentRect)"},
2198 {"SetTabEnabled", (PyCFunction)CtlObj_SetTabEnabled, 1,
2199 "(SInt16 inTabToHilite, Boolean inEnabled) -> None"},
2200 {"SetImageWellTransform", (PyCFunction)CtlObj_SetImageWellTransform, 1,
2201 "(IconTransformType inTransform) -> None"},
Jack Jansen5d56f4b1995-06-18 20:16:33 +00002202 {"as_Resource", (PyCFunction)CtlObj_as_Resource, 1,
Jack Jansena1a0fef1999-12-23 14:32:06 +00002203 "() -> (Handle _rv)"},
Jack Jansen1a7d5b12000-03-21 16:25:23 +00002204 {"GetControlRect", (PyCFunction)CtlObj_GetControlRect, 1,
2205 "() -> (Rect rect)"},
Jack Jansencfb60ee1996-10-01 10:46:46 +00002206 {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1,
2207 "() -> None"},
Jack Jansen848250c1998-05-28 14:20:09 +00002208 {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00002209 "(Point startPoint [,trackercallback]) -> (ControlPartCode _rv)"},
2210 {"HandleControlClick", (PyCFunction)CtlObj_HandleControlClick, 1,
2211 "(Point startPoint, Integer modifiers, [,trackercallback]) -> (ControlPartCode _rv)"},
2212 {"SetControlData", (PyCFunction)CtlObj_SetControlData, 1,
2213 "(stuff) -> None"},
2214 {"GetControlData", (PyCFunction)CtlObj_GetControlData, 1,
2215 "(part, type) -> String"},
Jack Jansena9e3db32001-01-09 22:10:16 +00002216 {"SetControlData_Handle", (PyCFunction)CtlObj_SetControlData_Handle, 1,
Jack Jansen1f9249c1999-12-19 00:05:50 +00002217 "(ResObj) -> None"},
Jack Jansena9e3db32001-01-09 22:10:16 +00002218 {"GetControlData_Handle", (PyCFunction)CtlObj_GetControlData_Handle, 1,
Jack Jansen1f9249c1999-12-19 00:05:50 +00002219 "(part, type) -> ResObj"},
Jack Jansene79dc762000-06-02 21:35:07 +00002220
Jack Jansen74a1e632000-07-14 22:37:27 +00002221#if !TARGET_API_MAC_CARBON_NOTYET
Jack Jansena9e3db32001-01-09 22:10:16 +00002222 {"SetControlData_Callback", (PyCFunction)CtlObj_SetControlData_Callback, 1,
Jack Jansenabc411b2000-03-20 16:09:09 +00002223 "(callbackfunc) -> None"},
Jack Jansene79dc762000-06-02 21:35:07 +00002224#endif
2225
Jack Jansen74a1e632000-07-14 22:37:27 +00002226#if !TARGET_API_MAC_CARBON_NOTYET
Jack Jansen4c704131998-06-19 13:35:14 +00002227 {"GetPopupData", (PyCFunction)CtlObj_GetPopupData, 1,
2228 NULL},
Jack Jansene79dc762000-06-02 21:35:07 +00002229#endif
2230
Jack Jansen74a1e632000-07-14 22:37:27 +00002231#if !TARGET_API_MAC_CARBON_NOTYET
Jack Jansen4c704131998-06-19 13:35:14 +00002232 {"SetPopupData", (PyCFunction)CtlObj_SetPopupData, 1,
2233 NULL},
Jack Jansene79dc762000-06-02 21:35:07 +00002234#endif
Guido van Rossum17448e21995-01-30 11:53:55 +00002235 {NULL, NULL, 0}
2236};
2237
2238PyMethodChain CtlObj_chain = { CtlObj_methods, NULL };
2239
2240static PyObject *CtlObj_getattr(self, name)
2241 ControlObject *self;
2242 char *name;
2243{
2244 return Py_FindMethodInChain(&CtlObj_chain, (PyObject *)self, name);
2245}
2246
2247#define CtlObj_setattr NULL
2248
Jack Jansen8387af61999-03-13 23:07:32 +00002249static int CtlObj_compare(self, other)
2250 ControlObject *self, *other;
2251{
2252 unsigned long v, w;
2253
2254 if (!CtlObj_Check((PyObject *)other))
2255 {
2256 v=(unsigned long)self;
2257 w=(unsigned long)other;
2258 }
2259 else
2260 {
2261 v=(unsigned long)self->ob_itself;
2262 w=(unsigned long)other->ob_itself;
2263 }
2264 if( v < w ) return -1;
2265 if( v > w ) return 1;
2266 return 0;
2267}
2268
2269#define CtlObj_repr NULL
2270
2271static long CtlObj_hash(self)
2272 ControlObject *self;
2273{
2274 return (long)self->ob_itself;
2275}
2276
Guido van Rossum17448e21995-01-30 11:53:55 +00002277PyTypeObject Control_Type = {
2278 PyObject_HEAD_INIT(&PyType_Type)
2279 0, /*ob_size*/
2280 "Control", /*tp_name*/
2281 sizeof(ControlObject), /*tp_basicsize*/
2282 0, /*tp_itemsize*/
2283 /* methods */
2284 (destructor) CtlObj_dealloc, /*tp_dealloc*/
2285 0, /*tp_print*/
2286 (getattrfunc) CtlObj_getattr, /*tp_getattr*/
2287 (setattrfunc) CtlObj_setattr, /*tp_setattr*/
Jack Jansen8387af61999-03-13 23:07:32 +00002288 (cmpfunc) CtlObj_compare, /*tp_compare*/
2289 (reprfunc) CtlObj_repr, /*tp_repr*/
2290 (PyNumberMethods *)0, /* tp_as_number */
2291 (PySequenceMethods *)0, /* tp_as_sequence */
2292 (PyMappingMethods *)0, /* tp_as_mapping */
2293 (hashfunc) CtlObj_hash, /*tp_hash*/
Guido van Rossum17448e21995-01-30 11:53:55 +00002294};
2295
2296/* -------------------- End object type Control --------------------- */
2297
2298
2299static PyObject *Ctl_NewControl(_self, _args)
2300 PyObject *_self;
2301 PyObject *_args;
2302{
2303 PyObject *_res = NULL;
2304 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00002305 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00002306 Rect boundsRect;
Jack Jansen21f96871998-02-20 16:02:09 +00002307 Str255 controlTitle;
2308 Boolean initiallyVisible;
2309 SInt16 initialValue;
2310 SInt16 minimumValue;
2311 SInt16 maximumValue;
Jack Jansen7d0bc831995-06-09 20:56:31 +00002312 SInt16 procID;
Jack Jansen21f96871998-02-20 16:02:09 +00002313 SInt32 controlReference;
Guido van Rossum17448e21995-01-30 11:53:55 +00002314 if (!PyArg_ParseTuple(_args, "O&O&O&bhhhhl",
Jack Jansen21f96871998-02-20 16:02:09 +00002315 WinObj_Convert, &owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00002316 PyMac_GetRect, &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00002317 PyMac_GetStr255, controlTitle,
2318 &initiallyVisible,
2319 &initialValue,
2320 &minimumValue,
2321 &maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00002322 &procID,
Jack Jansen21f96871998-02-20 16:02:09 +00002323 &controlReference))
Guido van Rossum17448e21995-01-30 11:53:55 +00002324 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00002325 _rv = NewControl(owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00002326 &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00002327 controlTitle,
2328 initiallyVisible,
2329 initialValue,
2330 minimumValue,
2331 maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00002332 procID,
Jack Jansen21f96871998-02-20 16:02:09 +00002333 controlReference);
Guido van Rossum17448e21995-01-30 11:53:55 +00002334 _res = Py_BuildValue("O&",
2335 CtlObj_New, _rv);
2336 return _res;
2337}
2338
2339static PyObject *Ctl_GetNewControl(_self, _args)
2340 PyObject *_self;
2341 PyObject *_args;
2342{
2343 PyObject *_res = NULL;
2344 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00002345 SInt16 resourceID;
2346 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00002347 if (!PyArg_ParseTuple(_args, "hO&",
Jack Jansen21f96871998-02-20 16:02:09 +00002348 &resourceID,
2349 WinObj_Convert, &owningWindow))
Guido van Rossum17448e21995-01-30 11:53:55 +00002350 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00002351 _rv = GetNewControl(resourceID,
2352 owningWindow);
Guido van Rossum17448e21995-01-30 11:53:55 +00002353 _res = Py_BuildValue("O&",
2354 CtlObj_New, _rv);
2355 return _res;
2356}
2357
Guido van Rossum17448e21995-01-30 11:53:55 +00002358static PyObject *Ctl_DrawControls(_self, _args)
2359 PyObject *_self;
2360 PyObject *_args;
2361{
2362 PyObject *_res = NULL;
2363 WindowPtr theWindow;
2364 if (!PyArg_ParseTuple(_args, "O&",
2365 WinObj_Convert, &theWindow))
2366 return NULL;
2367 DrawControls(theWindow);
2368 Py_INCREF(Py_None);
2369 _res = Py_None;
2370 return _res;
2371}
2372
Guido van Rossum17448e21995-01-30 11:53:55 +00002373static PyObject *Ctl_UpdateControls(_self, _args)
2374 PyObject *_self;
2375 PyObject *_args;
2376{
2377 PyObject *_res = NULL;
2378 WindowPtr theWindow;
Jack Jansen2b724171996-04-10 14:48:19 +00002379 RgnHandle updateRegion;
2380 if (!PyArg_ParseTuple(_args, "O&O&",
2381 WinObj_Convert, &theWindow,
2382 ResObj_Convert, &updateRegion))
Guido van Rossum17448e21995-01-30 11:53:55 +00002383 return NULL;
2384 UpdateControls(theWindow,
Jack Jansen2b724171996-04-10 14:48:19 +00002385 updateRegion);
Guido van Rossum17448e21995-01-30 11:53:55 +00002386 Py_INCREF(Py_None);
2387 _res = Py_None;
2388 return _res;
2389}
2390
2391static PyObject *Ctl_FindControl(_self, _args)
2392 PyObject *_self;
2393 PyObject *_args;
2394{
2395 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +00002396 ControlPartCode _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00002397 Point testPoint;
Guido van Rossum17448e21995-01-30 11:53:55 +00002398 WindowPtr theWindow;
2399 ControlHandle theControl;
2400 if (!PyArg_ParseTuple(_args, "O&O&",
Jack Jansen21f96871998-02-20 16:02:09 +00002401 PyMac_GetPoint, &testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00002402 WinObj_Convert, &theWindow))
2403 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00002404 _rv = FindControl(testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00002405 theWindow,
2406 &theControl);
2407 _res = Py_BuildValue("hO&",
2408 _rv,
2409 CtlObj_WhichControl, theControl);
2410 return _res;
2411}
2412
Jack Jansen21f96871998-02-20 16:02:09 +00002413static PyObject *Ctl_FindControlUnderMouse(_self, _args)
2414 PyObject *_self;
2415 PyObject *_args;
2416{
2417 PyObject *_res = NULL;
2418 ControlHandle _rv;
2419 Point inWhere;
2420 WindowPtr inWindow;
2421 SInt16 outPart;
2422 if (!PyArg_ParseTuple(_args, "O&O&",
2423 PyMac_GetPoint, &inWhere,
2424 WinObj_Convert, &inWindow))
2425 return NULL;
2426 _rv = FindControlUnderMouse(inWhere,
2427 inWindow,
2428 &outPart);
2429 _res = Py_BuildValue("O&h",
2430 CtlObj_New, _rv,
2431 outPart);
2432 return _res;
2433}
2434
2435static PyObject *Ctl_IdleControls(_self, _args)
2436 PyObject *_self;
2437 PyObject *_args;
2438{
2439 PyObject *_res = NULL;
2440 WindowPtr inWindow;
2441 if (!PyArg_ParseTuple(_args, "O&",
2442 WinObj_Convert, &inWindow))
2443 return NULL;
2444 IdleControls(inWindow);
2445 Py_INCREF(Py_None);
2446 _res = Py_None;
2447 return _res;
2448}
2449
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002450#if TARGET_API_MAC_CARBON
2451
2452static PyObject *Ctl_GetControlByID(_self, _args)
2453 PyObject *_self;
2454 PyObject *_args;
2455{
2456 PyObject *_res = NULL;
2457 OSStatus _err;
2458 WindowPtr inWindow;
2459 ControlID inID;
2460 ControlHandle outControl;
2461 if (!PyArg_ParseTuple(_args, "O&O&",
2462 WinObj_Convert, &inWindow,
2463 PyControlID_Convert, &inID))
2464 return NULL;
2465 _err = GetControlByID(inWindow,
2466 &inID,
2467 &outControl);
2468 if (_err != noErr) return PyMac_Error(_err);
2469 _res = Py_BuildValue("O&",
2470 CtlObj_WhichControl, outControl);
2471 return _res;
2472}
2473#endif
2474
Jack Jansen21f96871998-02-20 16:02:09 +00002475static PyObject *Ctl_DumpControlHierarchy(_self, _args)
2476 PyObject *_self;
2477 PyObject *_args;
2478{
2479 PyObject *_res = NULL;
2480 OSErr _err;
2481 WindowPtr inWindow;
2482 FSSpec inDumpFile;
2483 if (!PyArg_ParseTuple(_args, "O&O&",
2484 WinObj_Convert, &inWindow,
2485 PyMac_GetFSSpec, &inDumpFile))
2486 return NULL;
2487 _err = DumpControlHierarchy(inWindow,
2488 &inDumpFile);
2489 if (_err != noErr) return PyMac_Error(_err);
2490 Py_INCREF(Py_None);
2491 _res = Py_None;
2492 return _res;
2493}
2494
2495static PyObject *Ctl_CreateRootControl(_self, _args)
2496 PyObject *_self;
2497 PyObject *_args;
2498{
2499 PyObject *_res = NULL;
2500 OSErr _err;
2501 WindowPtr inWindow;
2502 ControlHandle outControl;
2503 if (!PyArg_ParseTuple(_args, "O&",
2504 WinObj_Convert, &inWindow))
2505 return NULL;
2506 _err = CreateRootControl(inWindow,
2507 &outControl);
2508 if (_err != noErr) return PyMac_Error(_err);
2509 _res = Py_BuildValue("O&",
2510 CtlObj_WhichControl, outControl);
2511 return _res;
2512}
2513
2514static PyObject *Ctl_GetRootControl(_self, _args)
2515 PyObject *_self;
2516 PyObject *_args;
2517{
2518 PyObject *_res = NULL;
2519 OSErr _err;
2520 WindowPtr inWindow;
2521 ControlHandle outControl;
2522 if (!PyArg_ParseTuple(_args, "O&",
2523 WinObj_Convert, &inWindow))
2524 return NULL;
2525 _err = GetRootControl(inWindow,
2526 &outControl);
2527 if (_err != noErr) return PyMac_Error(_err);
2528 _res = Py_BuildValue("O&",
2529 CtlObj_WhichControl, outControl);
2530 return _res;
2531}
2532
2533static PyObject *Ctl_GetKeyboardFocus(_self, _args)
2534 PyObject *_self;
2535 PyObject *_args;
2536{
2537 PyObject *_res = NULL;
2538 OSErr _err;
2539 WindowPtr inWindow;
2540 ControlHandle outControl;
2541 if (!PyArg_ParseTuple(_args, "O&",
2542 WinObj_Convert, &inWindow))
2543 return NULL;
2544 _err = GetKeyboardFocus(inWindow,
2545 &outControl);
2546 if (_err != noErr) return PyMac_Error(_err);
2547 _res = Py_BuildValue("O&",
2548 CtlObj_WhichControl, outControl);
2549 return _res;
2550}
2551
2552static PyObject *Ctl_SetKeyboardFocus(_self, _args)
2553 PyObject *_self;
2554 PyObject *_args;
2555{
2556 PyObject *_res = NULL;
2557 OSErr _err;
2558 WindowPtr inWindow;
2559 ControlHandle inControl;
2560 ControlFocusPart inPart;
2561 if (!PyArg_ParseTuple(_args, "O&O&h",
2562 WinObj_Convert, &inWindow,
2563 CtlObj_Convert, &inControl,
2564 &inPart))
2565 return NULL;
2566 _err = SetKeyboardFocus(inWindow,
2567 inControl,
2568 inPart);
2569 if (_err != noErr) return PyMac_Error(_err);
2570 Py_INCREF(Py_None);
2571 _res = Py_None;
2572 return _res;
2573}
2574
2575static PyObject *Ctl_AdvanceKeyboardFocus(_self, _args)
2576 PyObject *_self;
2577 PyObject *_args;
2578{
2579 PyObject *_res = NULL;
2580 OSErr _err;
2581 WindowPtr inWindow;
2582 if (!PyArg_ParseTuple(_args, "O&",
2583 WinObj_Convert, &inWindow))
2584 return NULL;
2585 _err = AdvanceKeyboardFocus(inWindow);
2586 if (_err != noErr) return PyMac_Error(_err);
2587 Py_INCREF(Py_None);
2588 _res = Py_None;
2589 return _res;
2590}
2591
2592static PyObject *Ctl_ReverseKeyboardFocus(_self, _args)
2593 PyObject *_self;
2594 PyObject *_args;
2595{
2596 PyObject *_res = NULL;
2597 OSErr _err;
2598 WindowPtr inWindow;
2599 if (!PyArg_ParseTuple(_args, "O&",
2600 WinObj_Convert, &inWindow))
2601 return NULL;
2602 _err = ReverseKeyboardFocus(inWindow);
2603 if (_err != noErr) return PyMac_Error(_err);
2604 Py_INCREF(Py_None);
2605 _res = Py_None;
2606 return _res;
2607}
2608
2609static PyObject *Ctl_ClearKeyboardFocus(_self, _args)
2610 PyObject *_self;
2611 PyObject *_args;
2612{
2613 PyObject *_res = NULL;
2614 OSErr _err;
2615 WindowPtr inWindow;
2616 if (!PyArg_ParseTuple(_args, "O&",
2617 WinObj_Convert, &inWindow))
2618 return NULL;
2619 _err = ClearKeyboardFocus(inWindow);
2620 if (_err != noErr) return PyMac_Error(_err);
2621 Py_INCREF(Py_None);
2622 _res = Py_None;
2623 return _res;
2624}
2625
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002626#if TARGET_API_MAC_CARBON
2627
2628static PyObject *Ctl_SetAutomaticControlDragTrackingEnabledForWindow(_self, _args)
2629 PyObject *_self;
2630 PyObject *_args;
2631{
2632 PyObject *_res = NULL;
2633 OSStatus _err;
2634 WindowPtr theWindow;
2635 Boolean tracks;
2636 if (!PyArg_ParseTuple(_args, "O&b",
2637 WinObj_Convert, &theWindow,
2638 &tracks))
2639 return NULL;
2640 _err = SetAutomaticControlDragTrackingEnabledForWindow(theWindow,
2641 tracks);
2642 if (_err != noErr) return PyMac_Error(_err);
2643 Py_INCREF(Py_None);
2644 _res = Py_None;
2645 return _res;
2646}
2647#endif
2648
2649#if TARGET_API_MAC_CARBON
2650
2651static PyObject *Ctl_IsAutomaticControlDragTrackingEnabledForWindow(_self, _args)
2652 PyObject *_self;
2653 PyObject *_args;
2654{
2655 PyObject *_res = NULL;
2656 OSStatus _err;
2657 WindowPtr theWindow;
2658 Boolean tracks;
2659 if (!PyArg_ParseTuple(_args, "O&",
2660 WinObj_Convert, &theWindow))
2661 return NULL;
2662 _err = IsAutomaticControlDragTrackingEnabledForWindow(theWindow,
2663 &tracks);
2664 if (_err != noErr) return PyMac_Error(_err);
2665 _res = Py_BuildValue("b",
2666 tracks);
2667 return _res;
2668}
2669#endif
2670
Jack Jansene0581891999-02-07 14:02:03 +00002671static PyObject *Ctl_as_Control(_self, _args)
2672 PyObject *_self;
2673 PyObject *_args;
2674{
2675 PyObject *_res = NULL;
2676 ControlHandle _rv;
2677 Handle h;
2678 if (!PyArg_ParseTuple(_args, "O&",
2679 ResObj_Convert, &h))
2680 return NULL;
2681 _rv = as_Control(h);
2682 _res = Py_BuildValue("O&",
2683 CtlObj_New, _rv);
2684 return _res;
2685}
2686
Guido van Rossum17448e21995-01-30 11:53:55 +00002687static PyMethodDef Ctl_methods[] = {
2688 {"NewControl", (PyCFunction)Ctl_NewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00002689 "(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 +00002690 {"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00002691 "(SInt16 resourceID, WindowPtr owningWindow) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002692 {"DrawControls", (PyCFunction)Ctl_DrawControls, 1,
2693 "(WindowPtr theWindow) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002694 {"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1,
Jack Jansen2b724171996-04-10 14:48:19 +00002695 "(WindowPtr theWindow, RgnHandle updateRegion) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002696 {"FindControl", (PyCFunction)Ctl_FindControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00002697 "(Point testPoint, WindowPtr theWindow) -> (ControlPartCode _rv, ControlHandle theControl)"},
2698 {"FindControlUnderMouse", (PyCFunction)Ctl_FindControlUnderMouse, 1,
2699 "(Point inWhere, WindowPtr inWindow) -> (ControlHandle _rv, SInt16 outPart)"},
2700 {"IdleControls", (PyCFunction)Ctl_IdleControls, 1,
2701 "(WindowPtr inWindow) -> None"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002702
2703#if TARGET_API_MAC_CARBON
2704 {"GetControlByID", (PyCFunction)Ctl_GetControlByID, 1,
2705 "(WindowPtr inWindow, ControlID inID) -> (ControlHandle outControl)"},
2706#endif
Jack Jansen21f96871998-02-20 16:02:09 +00002707 {"DumpControlHierarchy", (PyCFunction)Ctl_DumpControlHierarchy, 1,
2708 "(WindowPtr inWindow, FSSpec inDumpFile) -> None"},
2709 {"CreateRootControl", (PyCFunction)Ctl_CreateRootControl, 1,
2710 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
2711 {"GetRootControl", (PyCFunction)Ctl_GetRootControl, 1,
2712 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
2713 {"GetKeyboardFocus", (PyCFunction)Ctl_GetKeyboardFocus, 1,
2714 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
2715 {"SetKeyboardFocus", (PyCFunction)Ctl_SetKeyboardFocus, 1,
2716 "(WindowPtr inWindow, ControlHandle inControl, ControlFocusPart inPart) -> None"},
2717 {"AdvanceKeyboardFocus", (PyCFunction)Ctl_AdvanceKeyboardFocus, 1,
2718 "(WindowPtr inWindow) -> None"},
2719 {"ReverseKeyboardFocus", (PyCFunction)Ctl_ReverseKeyboardFocus, 1,
2720 "(WindowPtr inWindow) -> None"},
2721 {"ClearKeyboardFocus", (PyCFunction)Ctl_ClearKeyboardFocus, 1,
2722 "(WindowPtr inWindow) -> None"},
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002723
2724#if TARGET_API_MAC_CARBON
2725 {"SetAutomaticControlDragTrackingEnabledForWindow", (PyCFunction)Ctl_SetAutomaticControlDragTrackingEnabledForWindow, 1,
2726 "(WindowPtr theWindow, Boolean tracks) -> None"},
2727#endif
2728
2729#if TARGET_API_MAC_CARBON
2730 {"IsAutomaticControlDragTrackingEnabledForWindow", (PyCFunction)Ctl_IsAutomaticControlDragTrackingEnabledForWindow, 1,
2731 "(WindowPtr theWindow) -> (Boolean tracks)"},
2732#endif
Jack Jansene0581891999-02-07 14:02:03 +00002733 {"as_Control", (PyCFunction)Ctl_as_Control, 1,
2734 "(Handle h) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002735 {NULL, NULL, 0}
2736};
2737
2738
2739
Jack Jansen9d8b96c2000-07-14 22:16:45 +00002740static PyObject *
2741CtlObj_NewUnmanaged(itself)
Jack Jansen8387af61999-03-13 23:07:32 +00002742 ControlHandle itself;
2743{
2744 ControlObject *it;
2745 if (itself == NULL) return PyMac_Error(resNotFound);
2746 it = PyObject_NEW(ControlObject, &Control_Type);
2747 if (it == NULL) return NULL;
2748 it->ob_itself = itself;
Jack Jansen1a7d5b12000-03-21 16:25:23 +00002749 it->ob_callbackdict = NULL;
Jack Jansen8387af61999-03-13 23:07:32 +00002750 return (PyObject *)it;
2751}
2752
Jack Jansen9d8b96c2000-07-14 22:16:45 +00002753static PyObject *
Guido van Rossum17448e21995-01-30 11:53:55 +00002754CtlObj_WhichControl(ControlHandle c)
2755{
2756 PyObject *it;
Jack Jansen24c35311999-12-09 22:49:51 +00002757
Guido van Rossum17448e21995-01-30 11:53:55 +00002758 if (c == NULL)
Guido van Rossum17448e21995-01-30 11:53:55 +00002759 it = Py_None;
Jack Jansen8387af61999-03-13 23:07:32 +00002760 else {
2761 it = (PyObject *) GetControlReference(c);
2762 /*
2763 ** If the refcon is zero or doesn't point back to the Python object
2764 ** the control is not ours. Return a temporary object.
2765 */
2766 if (it == NULL || ((ControlObject *)it)->ob_itself != c)
2767 return CtlObj_NewUnmanaged(c);
2768 }
Guido van Rossum17448e21995-01-30 11:53:55 +00002769 Py_INCREF(it);
2770 return it;
2771}
2772
Jack Jansen848250c1998-05-28 14:20:09 +00002773static int
2774settrackfunc(obj)
2775 PyObject *obj;
2776{
2777 if (tracker) {
2778 PyErr_SetString(Ctl_Error, "Tracker function in use");
2779 return 0;
2780 }
2781 tracker = obj;
2782 Py_INCREF(tracker);
2783}
2784
2785static void
2786clrtrackfunc()
2787{
2788 Py_XDECREF(tracker);
2789 tracker = 0;
2790}
2791
2792static pascal void
Jack Jansene79dc762000-06-02 21:35:07 +00002793mytracker(ControlHandle ctl, short part)
Jack Jansen848250c1998-05-28 14:20:09 +00002794{
2795 PyObject *args, *rv=0;
Jack Jansen24c35311999-12-09 22:49:51 +00002796
Jack Jansen848250c1998-05-28 14:20:09 +00002797 args = Py_BuildValue("(O&i)", CtlObj_WhichControl, ctl, (int)part);
2798 if (args && tracker) {
2799 rv = PyEval_CallObject(tracker, args);
2800 Py_DECREF(args);
2801 }
2802 if (rv)
2803 Py_DECREF(rv);
2804 else
Jack Jansen24c35311999-12-09 22:49:51 +00002805 PySys_WriteStderr("TrackControl or HandleControlClick: exception in tracker function\n");
Jack Jansen848250c1998-05-28 14:20:09 +00002806}
2807
Jack Jansen74a1e632000-07-14 22:37:27 +00002808#if !TARGET_API_MAC_CARBON_NOTYET
Jack Jansenabc411b2000-03-20 16:09:09 +00002809static int
Jack Jansen85152b92000-07-11 21:12:55 +00002810setcallback(myself, which, callback, uppp)
2811 PyObject *myself;
Jack Jansenabc411b2000-03-20 16:09:09 +00002812 OSType which;
2813 PyObject *callback;
2814 UniversalProcPtr *uppp;
2815{
Jack Jansen85152b92000-07-11 21:12:55 +00002816 ControlObject *self = (ControlObject *)myself;
Jack Jansenabc411b2000-03-20 16:09:09 +00002817 char keybuf[9];
2818
2819 if ( which == kControlUserPaneDrawProcTag )
Jack Jansen1b6e8212000-04-05 21:30:57 +00002820 *uppp = (UniversalProcPtr)mydrawproc_upp;
Jack Jansenabc411b2000-03-20 16:09:09 +00002821 else if ( which == kControlUserPaneIdleProcTag )
Jack Jansen1b6e8212000-04-05 21:30:57 +00002822 *uppp = (UniversalProcPtr)myidleproc_upp;
Jack Jansena27e9fb2000-03-21 23:03:02 +00002823 else if ( which == kControlUserPaneHitTestProcTag )
Jack Jansen1b6e8212000-04-05 21:30:57 +00002824 *uppp = (UniversalProcPtr)myhittestproc_upp;
Jack Jansena27e9fb2000-03-21 23:03:02 +00002825 else if ( which == kControlUserPaneTrackingProcTag )
Jack Jansen1b6e8212000-04-05 21:30:57 +00002826 *uppp = (UniversalProcPtr)mytrackingproc_upp;
Jack Jansenabc411b2000-03-20 16:09:09 +00002827 else
2828 return -1;
2829 /* Only now do we test for clearing of the callback: */
2830 if ( callback == Py_None )
2831 *uppp = NULL;
2832 /* Create the dict if it doesn't exist yet (so we don't get such a dict for every control) */
2833 if ( self->ob_callbackdict == NULL )
2834 if ( (self->ob_callbackdict = PyDict_New()) == NULL )
2835 return -1;
2836 /* And store the Python callback */
2837 sprintf(keybuf, "%x", which);
2838 if (PyDict_SetItemString(self->ob_callbackdict, keybuf, callback) < 0)
2839 return -1;
2840 return 0;
2841}
2842
2843static PyObject *
2844callcallback(self, which, arglist)
2845 ControlObject *self;
2846 OSType which;
2847 PyObject *arglist;
2848{
2849 char keybuf[9];
2850 PyObject *func, *rv;
2851
2852 sprintf(keybuf, "%x", which);
2853 if ( self->ob_callbackdict == NULL ||
2854 (func = PyDict_GetItemString(self->ob_callbackdict, keybuf)) == NULL ) {
Jack Jansena27e9fb2000-03-21 23:03:02 +00002855 PySys_WriteStderr("Control callback %x without callback object\n", which);
Jack Jansenabc411b2000-03-20 16:09:09 +00002856 return NULL;
2857 }
2858 rv = PyEval_CallObject(func, arglist);
2859 if ( rv == NULL )
Jack Jansena27e9fb2000-03-21 23:03:02 +00002860 PySys_WriteStderr("Exception in control callback %x handler\n", which);
Jack Jansenabc411b2000-03-20 16:09:09 +00002861 return rv;
2862}
2863
2864static pascal void
2865mydrawproc(ControlHandle control, SInt16 part)
2866{
2867 ControlObject *ctl_obj;
2868 PyObject *arglist, *rv;
2869
2870 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
2871 arglist = Py_BuildValue("Oh", ctl_obj, part);
2872 rv = callcallback(ctl_obj, kControlUserPaneDrawProcTag, arglist);
2873 Py_XDECREF(arglist);
2874 Py_XDECREF(rv);
2875}
2876
2877static pascal void
2878myidleproc(ControlHandle control)
2879{
2880 ControlObject *ctl_obj;
2881 PyObject *arglist, *rv;
2882
2883 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
2884 arglist = Py_BuildValue("O", ctl_obj);
2885 rv = callcallback(ctl_obj, kControlUserPaneIdleProcTag, arglist);
2886 Py_XDECREF(arglist);
2887 Py_XDECREF(rv);
2888}
2889
Jack Jansena27e9fb2000-03-21 23:03:02 +00002890static pascal ControlPartCode
2891myhittestproc(ControlHandle control, Point where)
2892{
2893 ControlObject *ctl_obj;
2894 PyObject *arglist, *rv;
2895 short c_rv = -1;
2896
2897 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
Jack Jansendeb63732000-03-22 15:35:24 +00002898 arglist = Py_BuildValue("OO&", ctl_obj, PyMac_BuildPoint, where);
Jack Jansena27e9fb2000-03-21 23:03:02 +00002899 rv = callcallback(ctl_obj, kControlUserPaneHitTestProcTag, arglist);
2900 Py_XDECREF(arglist);
2901 /* Ignore errors, nothing we can do about them */
2902 if ( rv )
2903 PyArg_Parse(rv, "h", &c_rv);
2904 Py_XDECREF(rv);
2905 return (ControlPartCode)c_rv;
2906}
2907
2908static pascal ControlPartCode
2909mytrackingproc(ControlHandle control, Point startPt, ControlActionUPP actionProc)
2910{
2911 ControlObject *ctl_obj;
2912 PyObject *arglist, *rv;
2913 short c_rv = -1;
2914
2915 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
2916 /* We cannot pass the actionProc without lots of work */
Jack Jansendeb63732000-03-22 15:35:24 +00002917 arglist = Py_BuildValue("OO&", ctl_obj, PyMac_BuildPoint, startPt);
Jack Jansena27e9fb2000-03-21 23:03:02 +00002918 rv = callcallback(ctl_obj, kControlUserPaneTrackingProcTag, arglist);
2919 Py_XDECREF(arglist);
2920 if ( rv )
2921 PyArg_Parse(rv, "h", &c_rv);
2922 Py_XDECREF(rv);
2923 return (ControlPartCode)c_rv;
2924}
Jack Jansene79dc762000-06-02 21:35:07 +00002925#endif
Jack Jansenabc411b2000-03-20 16:09:09 +00002926
Guido van Rossum17448e21995-01-30 11:53:55 +00002927
2928void initCtl()
2929{
2930 PyObject *m;
2931 PyObject *d;
2932
2933
2934
Jack Jansen848250c1998-05-28 14:20:09 +00002935 mytracker_upp = NewControlActionProc(mytracker);
Jack Jansen74a1e632000-07-14 22:37:27 +00002936#if !TARGET_API_MAC_CARBON_NOTYET
Jack Jansenabc411b2000-03-20 16:09:09 +00002937 mydrawproc_upp = NewControlUserPaneDrawProc(mydrawproc);
Jack Jansen1b6e8212000-04-05 21:30:57 +00002938 myidleproc_upp = NewControlUserPaneIdleProc(myidleproc);
Jack Jansena27e9fb2000-03-21 23:03:02 +00002939 myhittestproc_upp = NewControlUserPaneHitTestProc(myhittestproc);
2940 mytrackingproc_upp = NewControlUserPaneTrackingProc(mytrackingproc);
Jack Jansene79dc762000-06-02 21:35:07 +00002941#endif
Jack Jansen848250c1998-05-28 14:20:09 +00002942
Guido van Rossum17448e21995-01-30 11:53:55 +00002943
2944 m = Py_InitModule("Ctl", Ctl_methods);
2945 d = PyModule_GetDict(m);
2946 Ctl_Error = PyMac_GetOSErrException();
2947 if (Ctl_Error == NULL ||
2948 PyDict_SetItemString(d, "Error", Ctl_Error) != 0)
Jack Jansenf7d5aa62000-12-10 23:43:49 +00002949 return;
Jack Jansena755e681997-09-20 17:40:22 +00002950 Control_Type.ob_type = &PyType_Type;
2951 Py_INCREF(&Control_Type);
2952 if (PyDict_SetItemString(d, "ControlType", (PyObject *)&Control_Type) != 0)
2953 Py_FatalError("can't initialize ControlType");
Guido van Rossum17448e21995-01-30 11:53:55 +00002954}
2955
2956/* ========================= End module Ctl ========================= */
2957