blob: 6944fb31b422f98bddcecf56554c2651a9832c19 [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>
12
Jack Jansen9d8b96c2000-07-14 22:16:45 +000013staticforward PyObject *CtlObj_WhichControl(ControlHandle);
14
Jack Jansene0581891999-02-07 14:02:03 +000015#define as_Control(h) ((ControlHandle)h)
Jack Jansena1a0fef1999-12-23 14:32:06 +000016#define as_Resource(ctl) ((Handle)ctl)
Jack Jansene79dc762000-06-02 21:35:07 +000017#ifdef TARGET_API_MAC_CARBON
18#define GetControlRect(ctl, rectp) GetControlBounds(ctl, rectp)
19#else
Jack Jansen1a7d5b12000-03-21 16:25:23 +000020#define GetControlRect(ctl, rectp) (*(rectp) = ((*(ctl))->contrlRect))
Jack Jansene79dc762000-06-02 21:35:07 +000021#endif
Guido van Rossum17448e21995-01-30 11:53:55 +000022
Jack Jansen21f96871998-02-20 16:02:09 +000023/*
24** Parse/generate ControlFontStyleRec records
25*/
26#if 0 /* Not needed */
Jack Jansen9d8b96c2000-07-14 22:16:45 +000027static PyObject *
28ControlFontStyle_New(itself)
Jack Jansen21f96871998-02-20 16:02:09 +000029 ControlFontStyleRec *itself;
30{
31
32 return Py_BuildValue("hhhhhhO&O&", itself->flags, itself->font,
33 itself->size, itself->style, itself->mode, itself->just,
34 QdRGB_New, &itself->foreColor, QdRGB_New, &itself->backColor);
35}
36#endif
37
Jack Jansen9d8b96c2000-07-14 22:16:45 +000038static int
Jack Jansen21f96871998-02-20 16:02:09 +000039ControlFontStyle_Convert(v, itself)
40 PyObject *v;
41 ControlFontStyleRec *itself;
42{
43 return PyArg_ParseTuple(v, "hhhhhhO&O&", &itself->flags,
Jack Jansen24c35311999-12-09 22:49:51 +000044 &itself->font, &itself->size, &itself->style, &itself->mode,
45 &itself->just, QdRGB_Convert, &itself->foreColor,
Jack Jansen21f96871998-02-20 16:02:09 +000046 QdRGB_Convert, &itself->backColor);
47}
48
Jack Jansen24c35311999-12-09 22:49:51 +000049/* TrackControl and HandleControlClick callback support */
Jack Jansen848250c1998-05-28 14:20:09 +000050static PyObject *tracker;
51static ControlActionUPP mytracker_upp;
Jack Jansene79dc762000-06-02 21:35:07 +000052#ifndef TARGET_API_MAC_CARBON_NOTYET
Jack Jansenabc411b2000-03-20 16:09:09 +000053static ControlUserPaneDrawUPP mydrawproc_upp;
54static ControlUserPaneIdleUPP myidleproc_upp;
Jack Jansena27e9fb2000-03-21 23:03:02 +000055static ControlUserPaneHitTestUPP myhittestproc_upp;
56static ControlUserPaneTrackingUPP mytrackingproc_upp;
Jack Jansene79dc762000-06-02 21:35:07 +000057#endif
Jack Jansen848250c1998-05-28 14:20:09 +000058
59extern int settrackfunc(PyObject *); /* forward */
60extern void clrtrackfunc(void); /* forward */
Jack Jansen85152b92000-07-11 21:12:55 +000061#ifndef TARGET_API_MAC_CARBON_NOTYET
62staticforward int setcallback(PyObject *, OSType, PyObject *, UniversalProcPtr *);
63#endif
Jack Jansen848250c1998-05-28 14:20:09 +000064
Guido van Rossum17448e21995-01-30 11:53:55 +000065static PyObject *Ctl_Error;
66
67/* ---------------------- Object type Control ----------------------- */
68
69PyTypeObject Control_Type;
70
71#define CtlObj_Check(x) ((x)->ob_type == &Control_Type)
72
73typedef struct ControlObject {
74 PyObject_HEAD
75 ControlHandle ob_itself;
Jack Jansenabc411b2000-03-20 16:09:09 +000076 PyObject *ob_callbackdict;
Guido van Rossum17448e21995-01-30 11:53:55 +000077} ControlObject;
78
79PyObject *CtlObj_New(itself)
Jack Jansenae8a68f1995-06-06 12:55:40 +000080 ControlHandle itself;
Guido van Rossum17448e21995-01-30 11:53:55 +000081{
82 ControlObject *it;
83 if (itself == NULL) return PyMac_Error(resNotFound);
84 it = PyObject_NEW(ControlObject, &Control_Type);
85 if (it == NULL) return NULL;
86 it->ob_itself = itself;
Jack Jansen85ae4a81997-04-08 15:26:03 +000087 SetControlReference(itself, (long)it);
Jack Jansenabc411b2000-03-20 16:09:09 +000088 it->ob_callbackdict = NULL;
Guido van Rossum17448e21995-01-30 11:53:55 +000089 return (PyObject *)it;
90}
91CtlObj_Convert(v, p_itself)
92 PyObject *v;
93 ControlHandle *p_itself;
94{
95 if (!CtlObj_Check(v))
96 {
97 PyErr_SetString(PyExc_TypeError, "Control required");
98 return 0;
99 }
100 *p_itself = ((ControlObject *)v)->ob_itself;
101 return 1;
102}
103
104static void CtlObj_dealloc(self)
105 ControlObject *self;
106{
Jack Jansenabc411b2000-03-20 16:09:09 +0000107 Py_XDECREF(self->ob_callbackdict);
Jack Jansen24c35311999-12-09 22:49:51 +0000108 if (self->ob_itself)SetControlReference(self->ob_itself, (long)0); /* Make it forget about us */
Guido van Rossum17448e21995-01-30 11:53:55 +0000109 PyMem_DEL(self);
110}
111
Jack Jansen21f96871998-02-20 16:02:09 +0000112static PyObject *CtlObj_HiliteControl(_self, _args)
113 ControlObject *_self;
114 PyObject *_args;
115{
116 PyObject *_res = NULL;
117 ControlPartCode hiliteState;
118 if (!PyArg_ParseTuple(_args, "h",
119 &hiliteState))
120 return NULL;
121 HiliteControl(_self->ob_itself,
122 hiliteState);
123 Py_INCREF(Py_None);
124 _res = Py_None;
125 return _res;
126}
127
Jack Jansen7d0bc831995-06-09 20:56:31 +0000128static PyObject *CtlObj_ShowControl(_self, _args)
129 ControlObject *_self;
130 PyObject *_args;
131{
132 PyObject *_res = NULL;
133 if (!PyArg_ParseTuple(_args, ""))
134 return NULL;
135 ShowControl(_self->ob_itself);
136 Py_INCREF(Py_None);
137 _res = Py_None;
138 return _res;
139}
140
141static PyObject *CtlObj_HideControl(_self, _args)
142 ControlObject *_self;
143 PyObject *_args;
144{
145 PyObject *_res = NULL;
146 if (!PyArg_ParseTuple(_args, ""))
147 return NULL;
148 HideControl(_self->ob_itself);
149 Py_INCREF(Py_None);
150 _res = Py_None;
151 return _res;
152}
153
Jack Jansen21f96871998-02-20 16:02:09 +0000154static PyObject *CtlObj_IsControlActive(_self, _args)
155 ControlObject *_self;
156 PyObject *_args;
157{
158 PyObject *_res = NULL;
159 Boolean _rv;
160 if (!PyArg_ParseTuple(_args, ""))
161 return NULL;
162 _rv = IsControlActive(_self->ob_itself);
163 _res = Py_BuildValue("b",
164 _rv);
165 return _res;
166}
167
168static PyObject *CtlObj_IsControlVisible(_self, _args)
169 ControlObject *_self;
170 PyObject *_args;
171{
172 PyObject *_res = NULL;
173 Boolean _rv;
174 if (!PyArg_ParseTuple(_args, ""))
175 return NULL;
176 _rv = IsControlVisible(_self->ob_itself);
177 _res = Py_BuildValue("b",
178 _rv);
179 return _res;
180}
181
182static PyObject *CtlObj_ActivateControl(_self, _args)
183 ControlObject *_self;
184 PyObject *_args;
185{
186 PyObject *_res = NULL;
187 OSErr _err;
188 if (!PyArg_ParseTuple(_args, ""))
189 return NULL;
190 _err = ActivateControl(_self->ob_itself);
191 if (_err != noErr) return PyMac_Error(_err);
192 Py_INCREF(Py_None);
193 _res = Py_None;
194 return _res;
195}
196
197static PyObject *CtlObj_DeactivateControl(_self, _args)
198 ControlObject *_self;
199 PyObject *_args;
200{
201 PyObject *_res = NULL;
202 OSErr _err;
203 if (!PyArg_ParseTuple(_args, ""))
204 return NULL;
205 _err = DeactivateControl(_self->ob_itself);
206 if (_err != noErr) return PyMac_Error(_err);
207 Py_INCREF(Py_None);
208 _res = Py_None;
209 return _res;
210}
211
212static PyObject *CtlObj_SetControlVisibility(_self, _args)
213 ControlObject *_self;
214 PyObject *_args;
215{
216 PyObject *_res = NULL;
217 OSErr _err;
218 Boolean inIsVisible;
219 Boolean inDoDraw;
220 if (!PyArg_ParseTuple(_args, "bb",
221 &inIsVisible,
222 &inDoDraw))
223 return NULL;
224 _err = SetControlVisibility(_self->ob_itself,
225 inIsVisible,
226 inDoDraw);
227 if (_err != noErr) return PyMac_Error(_err);
228 Py_INCREF(Py_None);
229 _res = Py_None;
230 return _res;
231}
232
Jack Jansen7d0bc831995-06-09 20:56:31 +0000233static PyObject *CtlObj_Draw1Control(_self, _args)
234 ControlObject *_self;
235 PyObject *_args;
236{
237 PyObject *_res = NULL;
238 if (!PyArg_ParseTuple(_args, ""))
239 return NULL;
240 Draw1Control(_self->ob_itself);
241 Py_INCREF(Py_None);
242 _res = Py_None;
243 return _res;
244}
245
Jack Jansen21f96871998-02-20 16:02:09 +0000246static PyObject *CtlObj_GetBestControlRect(_self, _args)
Jack Jansen7d0bc831995-06-09 20:56:31 +0000247 ControlObject *_self;
248 PyObject *_args;
249{
250 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000251 OSErr _err;
252 Rect outRect;
253 SInt16 outBaseLineOffset;
254 if (!PyArg_ParseTuple(_args, ""))
Jack Jansen7d0bc831995-06-09 20:56:31 +0000255 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000256 _err = GetBestControlRect(_self->ob_itself,
257 &outRect,
258 &outBaseLineOffset);
259 if (_err != noErr) return PyMac_Error(_err);
260 _res = Py_BuildValue("O&h",
261 PyMac_BuildRect, &outRect,
262 outBaseLineOffset);
263 return _res;
264}
265
266static PyObject *CtlObj_SetControlFontStyle(_self, _args)
267 ControlObject *_self;
268 PyObject *_args;
269{
270 PyObject *_res = NULL;
271 OSErr _err;
272 ControlFontStyleRec inStyle;
273 if (!PyArg_ParseTuple(_args, "O&",
274 ControlFontStyle_Convert, &inStyle))
275 return NULL;
276 _err = SetControlFontStyle(_self->ob_itself,
277 &inStyle);
278 if (_err != noErr) return PyMac_Error(_err);
279 Py_INCREF(Py_None);
280 _res = Py_None;
281 return _res;
282}
283
284static PyObject *CtlObj_DrawControlInCurrentPort(_self, _args)
285 ControlObject *_self;
286 PyObject *_args;
287{
288 PyObject *_res = NULL;
289 if (!PyArg_ParseTuple(_args, ""))
290 return NULL;
291 DrawControlInCurrentPort(_self->ob_itself);
292 Py_INCREF(Py_None);
293 _res = Py_None;
294 return _res;
295}
296
297static PyObject *CtlObj_SetUpControlBackground(_self, _args)
298 ControlObject *_self;
299 PyObject *_args;
300{
301 PyObject *_res = NULL;
302 OSErr _err;
303 SInt16 inDepth;
304 Boolean inIsColorDevice;
305 if (!PyArg_ParseTuple(_args, "hb",
306 &inDepth,
307 &inIsColorDevice))
308 return NULL;
309 _err = SetUpControlBackground(_self->ob_itself,
310 inDepth,
311 inIsColorDevice);
312 if (_err != noErr) return PyMac_Error(_err);
Jack Jansen7d0bc831995-06-09 20:56:31 +0000313 Py_INCREF(Py_None);
314 _res = Py_None;
315 return _res;
316}
317
Jack Jansena05ac601999-12-12 21:41:51 +0000318static PyObject *CtlObj_SetUpControlTextColor(_self, _args)
319 ControlObject *_self;
320 PyObject *_args;
321{
322 PyObject *_res = NULL;
323 OSErr _err;
324 SInt16 inDepth;
325 Boolean inIsColorDevice;
326 if (!PyArg_ParseTuple(_args, "hb",
327 &inDepth,
328 &inIsColorDevice))
329 return NULL;
330 _err = SetUpControlTextColor(_self->ob_itself,
331 inDepth,
332 inIsColorDevice);
333 if (_err != noErr) return PyMac_Error(_err);
334 Py_INCREF(Py_None);
335 _res = Py_None;
336 return _res;
337}
338
Jack Jansen7d0bc831995-06-09 20:56:31 +0000339static PyObject *CtlObj_DragControl(_self, _args)
340 ControlObject *_self;
341 PyObject *_args;
342{
343 PyObject *_res = NULL;
Jack Jansen754d4a41995-11-14 10:41:55 +0000344 Point startPoint;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000345 Rect limitRect;
346 Rect slopRect;
347 DragConstraint axis;
Jack Jansen0b13e7c2000-07-07 13:09:35 +0000348 if (!PyArg_ParseTuple(_args, "O&O&O&H",
Jack Jansen754d4a41995-11-14 10:41:55 +0000349 PyMac_GetPoint, &startPoint,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000350 PyMac_GetRect, &limitRect,
351 PyMac_GetRect, &slopRect,
352 &axis))
353 return NULL;
354 DragControl(_self->ob_itself,
Jack Jansen754d4a41995-11-14 10:41:55 +0000355 startPoint,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000356 &limitRect,
357 &slopRect,
358 axis);
359 Py_INCREF(Py_None);
360 _res = Py_None;
361 return _res;
362}
363
364static PyObject *CtlObj_TestControl(_self, _args)
365 ControlObject *_self;
366 PyObject *_args;
367{
368 PyObject *_res = NULL;
369 ControlPartCode _rv;
Jack Jansen21f96871998-02-20 16:02:09 +0000370 Point testPoint;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000371 if (!PyArg_ParseTuple(_args, "O&",
Jack Jansen21f96871998-02-20 16:02:09 +0000372 PyMac_GetPoint, &testPoint))
Jack Jansen7d0bc831995-06-09 20:56:31 +0000373 return NULL;
374 _rv = TestControl(_self->ob_itself,
Jack Jansen21f96871998-02-20 16:02:09 +0000375 testPoint);
376 _res = Py_BuildValue("h",
377 _rv);
378 return _res;
379}
380
381static PyObject *CtlObj_HandleControlKey(_self, _args)
382 ControlObject *_self;
383 PyObject *_args;
384{
385 PyObject *_res = NULL;
386 SInt16 _rv;
387 SInt16 inKeyCode;
388 SInt16 inCharCode;
389 SInt16 inModifiers;
390 if (!PyArg_ParseTuple(_args, "hhh",
391 &inKeyCode,
392 &inCharCode,
393 &inModifiers))
394 return NULL;
395 _rv = HandleControlKey(_self->ob_itself,
396 inKeyCode,
397 inCharCode,
398 inModifiers);
Jack Jansen7d0bc831995-06-09 20:56:31 +0000399 _res = Py_BuildValue("h",
400 _rv);
401 return _res;
402}
403
404static PyObject *CtlObj_MoveControl(_self, _args)
405 ControlObject *_self;
406 PyObject *_args;
407{
408 PyObject *_res = NULL;
409 SInt16 h;
410 SInt16 v;
411 if (!PyArg_ParseTuple(_args, "hh",
412 &h,
413 &v))
414 return NULL;
415 MoveControl(_self->ob_itself,
416 h,
417 v);
418 Py_INCREF(Py_None);
419 _res = Py_None;
420 return _res;
421}
422
423static PyObject *CtlObj_SizeControl(_self, _args)
424 ControlObject *_self;
425 PyObject *_args;
426{
427 PyObject *_res = NULL;
428 SInt16 w;
429 SInt16 h;
430 if (!PyArg_ParseTuple(_args, "hh",
431 &w,
432 &h))
433 return NULL;
434 SizeControl(_self->ob_itself,
435 w,
436 h);
437 Py_INCREF(Py_None);
438 _res = Py_None;
439 return _res;
440}
441
Jack Jansenae8a68f1995-06-06 12:55:40 +0000442static PyObject *CtlObj_SetControlTitle(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000443 ControlObject *_self;
444 PyObject *_args;
445{
446 PyObject *_res = NULL;
447 Str255 title;
448 if (!PyArg_ParseTuple(_args, "O&",
449 PyMac_GetStr255, title))
450 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000451 SetControlTitle(_self->ob_itself,
452 title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000453 Py_INCREF(Py_None);
454 _res = Py_None;
455 return _res;
456}
457
Jack Jansenae8a68f1995-06-06 12:55:40 +0000458static PyObject *CtlObj_GetControlTitle(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000459 ControlObject *_self;
460 PyObject *_args;
461{
462 PyObject *_res = NULL;
463 Str255 title;
Jack Jansen41009001999-03-07 20:05:20 +0000464 if (!PyArg_ParseTuple(_args, ""))
Guido van Rossum17448e21995-01-30 11:53:55 +0000465 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000466 GetControlTitle(_self->ob_itself,
467 title);
Jack Jansen41009001999-03-07 20:05:20 +0000468 _res = Py_BuildValue("O&",
469 PyMac_BuildStr255, title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000470 return _res;
471}
472
Jack Jansenae8a68f1995-06-06 12:55:40 +0000473static PyObject *CtlObj_GetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000474 ControlObject *_self;
475 PyObject *_args;
476{
477 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000478 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000479 if (!PyArg_ParseTuple(_args, ""))
480 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000481 _rv = GetControlValue(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000482 _res = Py_BuildValue("h",
483 _rv);
484 return _res;
485}
486
Jack Jansen7d0bc831995-06-09 20:56:31 +0000487static PyObject *CtlObj_SetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000488 ControlObject *_self;
489 PyObject *_args;
490{
491 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000492 SInt16 newValue;
Guido van Rossum17448e21995-01-30 11:53:55 +0000493 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000494 &newValue))
Guido van Rossum17448e21995-01-30 11:53:55 +0000495 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000496 SetControlValue(_self->ob_itself,
497 newValue);
Guido van Rossum17448e21995-01-30 11:53:55 +0000498 Py_INCREF(Py_None);
499 _res = Py_None;
500 return _res;
501}
502
Jack Jansenae8a68f1995-06-06 12:55:40 +0000503static PyObject *CtlObj_GetControlMinimum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000504 ControlObject *_self;
505 PyObject *_args;
506{
507 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000508 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000509 if (!PyArg_ParseTuple(_args, ""))
510 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000511 _rv = GetControlMinimum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000512 _res = Py_BuildValue("h",
513 _rv);
514 return _res;
515}
516
Jack Jansen7d0bc831995-06-09 20:56:31 +0000517static PyObject *CtlObj_SetControlMinimum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000518 ControlObject *_self;
519 PyObject *_args;
520{
521 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000522 SInt16 newMinimum;
Guido van Rossum17448e21995-01-30 11:53:55 +0000523 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000524 &newMinimum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000525 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000526 SetControlMinimum(_self->ob_itself,
527 newMinimum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000528 Py_INCREF(Py_None);
529 _res = Py_None;
530 return _res;
531}
532
Jack Jansenae8a68f1995-06-06 12:55:40 +0000533static PyObject *CtlObj_GetControlMaximum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000534 ControlObject *_self;
535 PyObject *_args;
536{
537 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000538 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000539 if (!PyArg_ParseTuple(_args, ""))
540 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000541 _rv = GetControlMaximum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000542 _res = Py_BuildValue("h",
543 _rv);
544 return _res;
545}
546
Jack Jansen7d0bc831995-06-09 20:56:31 +0000547static PyObject *CtlObj_SetControlMaximum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000548 ControlObject *_self;
549 PyObject *_args;
550{
551 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000552 SInt16 newMaximum;
553 if (!PyArg_ParseTuple(_args, "h",
554 &newMaximum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000555 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000556 SetControlMaximum(_self->ob_itself,
557 newMaximum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000558 Py_INCREF(Py_None);
559 _res = Py_None;
560 return _res;
561}
562
Jack Jansena05ac601999-12-12 21:41:51 +0000563static PyObject *CtlObj_GetControlViewSize(_self, _args)
564 ControlObject *_self;
565 PyObject *_args;
566{
567 PyObject *_res = NULL;
568 SInt32 _rv;
569 if (!PyArg_ParseTuple(_args, ""))
570 return NULL;
571 _rv = GetControlViewSize(_self->ob_itself);
572 _res = Py_BuildValue("l",
573 _rv);
574 return _res;
575}
576
577static PyObject *CtlObj_SetControlViewSize(_self, _args)
578 ControlObject *_self;
579 PyObject *_args;
580{
581 PyObject *_res = NULL;
582 SInt32 newViewSize;
583 if (!PyArg_ParseTuple(_args, "l",
584 &newViewSize))
585 return NULL;
586 SetControlViewSize(_self->ob_itself,
587 newViewSize);
588 Py_INCREF(Py_None);
589 _res = Py_None;
590 return _res;
591}
592
593static PyObject *CtlObj_GetControl32BitValue(_self, _args)
594 ControlObject *_self;
595 PyObject *_args;
596{
597 PyObject *_res = NULL;
598 SInt32 _rv;
599 if (!PyArg_ParseTuple(_args, ""))
600 return NULL;
601 _rv = GetControl32BitValue(_self->ob_itself);
602 _res = Py_BuildValue("l",
603 _rv);
604 return _res;
605}
606
607static PyObject *CtlObj_SetControl32BitValue(_self, _args)
608 ControlObject *_self;
609 PyObject *_args;
610{
611 PyObject *_res = NULL;
612 SInt32 newValue;
613 if (!PyArg_ParseTuple(_args, "l",
614 &newValue))
615 return NULL;
616 SetControl32BitValue(_self->ob_itself,
617 newValue);
618 Py_INCREF(Py_None);
619 _res = Py_None;
620 return _res;
621}
622
623static PyObject *CtlObj_GetControl32BitMaximum(_self, _args)
624 ControlObject *_self;
625 PyObject *_args;
626{
627 PyObject *_res = NULL;
628 SInt32 _rv;
629 if (!PyArg_ParseTuple(_args, ""))
630 return NULL;
631 _rv = GetControl32BitMaximum(_self->ob_itself);
632 _res = Py_BuildValue("l",
633 _rv);
634 return _res;
635}
636
637static PyObject *CtlObj_SetControl32BitMaximum(_self, _args)
638 ControlObject *_self;
639 PyObject *_args;
640{
641 PyObject *_res = NULL;
642 SInt32 newMaximum;
643 if (!PyArg_ParseTuple(_args, "l",
644 &newMaximum))
645 return NULL;
646 SetControl32BitMaximum(_self->ob_itself,
647 newMaximum);
648 Py_INCREF(Py_None);
649 _res = Py_None;
650 return _res;
651}
652
653static PyObject *CtlObj_GetControl32BitMinimum(_self, _args)
654 ControlObject *_self;
655 PyObject *_args;
656{
657 PyObject *_res = NULL;
658 SInt32 _rv;
659 if (!PyArg_ParseTuple(_args, ""))
660 return NULL;
661 _rv = GetControl32BitMinimum(_self->ob_itself);
662 _res = Py_BuildValue("l",
663 _rv);
664 return _res;
665}
666
667static PyObject *CtlObj_SetControl32BitMinimum(_self, _args)
668 ControlObject *_self;
669 PyObject *_args;
670{
671 PyObject *_res = NULL;
672 SInt32 newMinimum;
673 if (!PyArg_ParseTuple(_args, "l",
674 &newMinimum))
675 return NULL;
676 SetControl32BitMinimum(_self->ob_itself,
677 newMinimum);
678 Py_INCREF(Py_None);
679 _res = Py_None;
680 return _res;
681}
682
683static PyObject *CtlObj_IsValidControlHandle(_self, _args)
684 ControlObject *_self;
685 PyObject *_args;
686{
687 PyObject *_res = NULL;
688 Boolean _rv;
689 if (!PyArg_ParseTuple(_args, ""))
690 return NULL;
691 _rv = IsValidControlHandle(_self->ob_itself);
692 _res = Py_BuildValue("b",
693 _rv);
694 return _res;
695}
696
697static PyObject *CtlObj_RemoveControlProperty(_self, _args)
698 ControlObject *_self;
699 PyObject *_args;
700{
701 PyObject *_res = NULL;
Jack Jansene79dc762000-06-02 21:35:07 +0000702 OSStatus _err;
Jack Jansena05ac601999-12-12 21:41:51 +0000703 OSType propertyCreator;
704 OSType propertyTag;
705 if (!PyArg_ParseTuple(_args, "O&O&",
706 PyMac_GetOSType, &propertyCreator,
707 PyMac_GetOSType, &propertyTag))
708 return NULL;
Jack Jansene79dc762000-06-02 21:35:07 +0000709 _err = RemoveControlProperty(_self->ob_itself,
710 propertyCreator,
711 propertyTag);
712 if (_err != noErr) return PyMac_Error(_err);
713 Py_INCREF(Py_None);
714 _res = Py_None;
Jack Jansena05ac601999-12-12 21:41:51 +0000715 return _res;
716}
717
718static PyObject *CtlObj_GetControlRegion(_self, _args)
719 ControlObject *_self;
720 PyObject *_args;
721{
722 PyObject *_res = NULL;
Jack Jansene79dc762000-06-02 21:35:07 +0000723 OSStatus _err;
Jack Jansena05ac601999-12-12 21:41:51 +0000724 ControlPartCode inPart;
725 RgnHandle outRegion;
726 if (!PyArg_ParseTuple(_args, "hO&",
727 &inPart,
728 ResObj_Convert, &outRegion))
729 return NULL;
Jack Jansene79dc762000-06-02 21:35:07 +0000730 _err = GetControlRegion(_self->ob_itself,
731 inPart,
732 outRegion);
733 if (_err != noErr) return PyMac_Error(_err);
734 Py_INCREF(Py_None);
735 _res = Py_None;
Jack Jansena05ac601999-12-12 21:41:51 +0000736 return _res;
737}
738
Jack Jansen7d0bc831995-06-09 20:56:31 +0000739static PyObject *CtlObj_GetControlVariant(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000740 ControlObject *_self;
741 PyObject *_args;
742{
743 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000744 ControlVariant _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000745 if (!PyArg_ParseTuple(_args, ""))
746 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000747 _rv = GetControlVariant(_self->ob_itself);
748 _res = Py_BuildValue("h",
Guido van Rossum17448e21995-01-30 11:53:55 +0000749 _rv);
750 return _res;
751}
752
Jack Jansen7d0bc831995-06-09 20:56:31 +0000753static PyObject *CtlObj_SetControlReference(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000754 ControlObject *_self;
755 PyObject *_args;
756{
757 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000758 SInt32 data;
759 if (!PyArg_ParseTuple(_args, "l",
760 &data))
Guido van Rossum17448e21995-01-30 11:53:55 +0000761 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000762 SetControlReference(_self->ob_itself,
763 data);
Guido van Rossum17448e21995-01-30 11:53:55 +0000764 Py_INCREF(Py_None);
765 _res = Py_None;
766 return _res;
767}
768
Jack Jansen7d0bc831995-06-09 20:56:31 +0000769static PyObject *CtlObj_GetControlReference(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000770 ControlObject *_self;
771 PyObject *_args;
772{
773 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000774 SInt32 _rv;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000775 if (!PyArg_ParseTuple(_args, ""))
776 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000777 _rv = GetControlReference(_self->ob_itself);
778 _res = Py_BuildValue("l",
Guido van Rossum17448e21995-01-30 11:53:55 +0000779 _rv);
780 return _res;
781}
782
Jack Jansene79dc762000-06-02 21:35:07 +0000783#ifndef TARGET_API_MAC_CARBON
784
Jack Jansenc7fefed1997-08-15 14:32:18 +0000785static PyObject *CtlObj_GetAuxiliaryControlRecord(_self, _args)
786 ControlObject *_self;
787 PyObject *_args;
788{
789 PyObject *_res = NULL;
790 Boolean _rv;
791 AuxCtlHandle acHndl;
792 if (!PyArg_ParseTuple(_args, ""))
793 return NULL;
794 _rv = GetAuxiliaryControlRecord(_self->ob_itself,
795 &acHndl);
796 _res = Py_BuildValue("bO&",
797 _rv,
798 ResObj_New, acHndl);
799 return _res;
800}
Jack Jansene79dc762000-06-02 21:35:07 +0000801#endif
802
803#ifndef TARGET_API_MAC_CARBON
Jack Jansenc7fefed1997-08-15 14:32:18 +0000804
805static PyObject *CtlObj_SetControlColor(_self, _args)
806 ControlObject *_self;
807 PyObject *_args;
808{
809 PyObject *_res = NULL;
810 CCTabHandle newColorTable;
811 if (!PyArg_ParseTuple(_args, "O&",
812 ResObj_Convert, &newColorTable))
813 return NULL;
814 SetControlColor(_self->ob_itself,
815 newColorTable);
816 Py_INCREF(Py_None);
817 _res = Py_None;
818 return _res;
819}
Jack Jansene79dc762000-06-02 21:35:07 +0000820#endif
821
Jack Jansen9d8b96c2000-07-14 22:16:45 +0000822#ifndef TARGET_API_MAC_CARBON
823
Jack Jansene79dc762000-06-02 21:35:07 +0000824static PyObject *CtlObj_GetBevelButtonMenuValue(_self, _args)
825 ControlObject *_self;
826 PyObject *_args;
827{
828 PyObject *_res = NULL;
829 OSErr _err;
830 SInt16 outValue;
831 if (!PyArg_ParseTuple(_args, ""))
832 return NULL;
833 _err = GetBevelButtonMenuValue(_self->ob_itself,
834 &outValue);
835 if (_err != noErr) return PyMac_Error(_err);
836 _res = Py_BuildValue("h",
837 outValue);
838 return _res;
839}
Jack Jansen9d8b96c2000-07-14 22:16:45 +0000840#endif
841
842#ifndef TARGET_API_MAC_CARBON
Jack Jansene79dc762000-06-02 21:35:07 +0000843
844static PyObject *CtlObj_SetBevelButtonMenuValue(_self, _args)
845 ControlObject *_self;
846 PyObject *_args;
847{
848 PyObject *_res = NULL;
849 OSErr _err;
850 SInt16 inValue;
851 if (!PyArg_ParseTuple(_args, "h",
852 &inValue))
853 return NULL;
854 _err = SetBevelButtonMenuValue(_self->ob_itself,
855 inValue);
856 if (_err != noErr) return PyMac_Error(_err);
857 Py_INCREF(Py_None);
858 _res = Py_None;
859 return _res;
860}
Jack Jansen9d8b96c2000-07-14 22:16:45 +0000861#endif
862
863#ifndef TARGET_API_MAC_CARBON
Jack Jansene79dc762000-06-02 21:35:07 +0000864
865static PyObject *CtlObj_GetBevelButtonMenuHandle(_self, _args)
866 ControlObject *_self;
867 PyObject *_args;
868{
869 PyObject *_res = NULL;
870 OSErr _err;
871 MenuHandle outHandle;
872 if (!PyArg_ParseTuple(_args, ""))
873 return NULL;
874 _err = GetBevelButtonMenuHandle(_self->ob_itself,
875 &outHandle);
876 if (_err != noErr) return PyMac_Error(_err);
877 _res = Py_BuildValue("O&",
878 MenuObj_New, outHandle);
879 return _res;
880}
Jack Jansen9d8b96c2000-07-14 22:16:45 +0000881#endif
882
883#ifndef TARGET_API_MAC_CARBON
Jack Jansene79dc762000-06-02 21:35:07 +0000884
885static PyObject *CtlObj_SetBevelButtonTransform(_self, _args)
886 ControlObject *_self;
887 PyObject *_args;
888{
889 PyObject *_res = NULL;
890 OSErr _err;
891 IconTransformType transform;
892 if (!PyArg_ParseTuple(_args, "h",
893 &transform))
894 return NULL;
895 _err = SetBevelButtonTransform(_self->ob_itself,
896 transform);
897 if (_err != noErr) return PyMac_Error(_err);
898 Py_INCREF(Py_None);
899 _res = Py_None;
900 return _res;
901}
Jack Jansen9d8b96c2000-07-14 22:16:45 +0000902#endif
903
904#ifndef TARGET_API_MAC_CARBON
Jack Jansene79dc762000-06-02 21:35:07 +0000905
906static PyObject *CtlObj_SetImageWellTransform(_self, _args)
907 ControlObject *_self;
908 PyObject *_args;
909{
910 PyObject *_res = NULL;
911 OSErr _err;
912 IconTransformType inTransform;
913 if (!PyArg_ParseTuple(_args, "h",
914 &inTransform))
915 return NULL;
916 _err = SetImageWellTransform(_self->ob_itself,
917 inTransform);
918 if (_err != noErr) return PyMac_Error(_err);
919 Py_INCREF(Py_None);
920 _res = Py_None;
921 return _res;
922}
Jack Jansen9d8b96c2000-07-14 22:16:45 +0000923#endif
924
925#ifndef TARGET_API_MAC_CARBON
Jack Jansene79dc762000-06-02 21:35:07 +0000926
927static PyObject *CtlObj_GetTabContentRect(_self, _args)
928 ControlObject *_self;
929 PyObject *_args;
930{
931 PyObject *_res = NULL;
932 OSErr _err;
933 Rect outContentRect;
934 if (!PyArg_ParseTuple(_args, ""))
935 return NULL;
936 _err = GetTabContentRect(_self->ob_itself,
937 &outContentRect);
938 if (_err != noErr) return PyMac_Error(_err);
939 _res = Py_BuildValue("O&",
940 PyMac_BuildRect, &outContentRect);
941 return _res;
942}
Jack Jansen9d8b96c2000-07-14 22:16:45 +0000943#endif
944
945#ifndef TARGET_API_MAC_CARBON
Jack Jansene79dc762000-06-02 21:35:07 +0000946
947static PyObject *CtlObj_SetTabEnabled(_self, _args)
948 ControlObject *_self;
949 PyObject *_args;
950{
951 PyObject *_res = NULL;
952 OSErr _err;
953 SInt16 inTabToHilite;
954 Boolean inEnabled;
955 if (!PyArg_ParseTuple(_args, "hb",
956 &inTabToHilite,
957 &inEnabled))
958 return NULL;
959 _err = SetTabEnabled(_self->ob_itself,
960 inTabToHilite,
961 inEnabled);
962 if (_err != noErr) return PyMac_Error(_err);
963 Py_INCREF(Py_None);
964 _res = Py_None;
965 return _res;
966}
Jack Jansen9d8b96c2000-07-14 22:16:45 +0000967#endif
968
969#ifndef TARGET_API_MAC_CARBON
Jack Jansene79dc762000-06-02 21:35:07 +0000970
971static PyObject *CtlObj_SetDisclosureTriangleLastValue(_self, _args)
972 ControlObject *_self;
973 PyObject *_args;
974{
975 PyObject *_res = NULL;
976 OSErr _err;
977 SInt16 inValue;
978 if (!PyArg_ParseTuple(_args, "h",
979 &inValue))
980 return NULL;
981 _err = SetDisclosureTriangleLastValue(_self->ob_itself,
982 inValue);
983 if (_err != noErr) return PyMac_Error(_err);
984 Py_INCREF(Py_None);
985 _res = Py_None;
986 return _res;
987}
Jack Jansen9d8b96c2000-07-14 22:16:45 +0000988#endif
Jack Jansenc7fefed1997-08-15 14:32:18 +0000989
Jack Jansen21f96871998-02-20 16:02:09 +0000990static PyObject *CtlObj_SendControlMessage(_self, _args)
991 ControlObject *_self;
992 PyObject *_args;
993{
994 PyObject *_res = NULL;
995 SInt32 _rv;
996 SInt16 inMessage;
997 SInt32 inParam;
998 if (!PyArg_ParseTuple(_args, "hl",
999 &inMessage,
1000 &inParam))
1001 return NULL;
1002 _rv = SendControlMessage(_self->ob_itself,
1003 inMessage,
1004 inParam);
1005 _res = Py_BuildValue("l",
1006 _rv);
1007 return _res;
1008}
1009
1010static PyObject *CtlObj_EmbedControl(_self, _args)
1011 ControlObject *_self;
1012 PyObject *_args;
1013{
1014 PyObject *_res = NULL;
1015 OSErr _err;
1016 ControlHandle inContainer;
1017 if (!PyArg_ParseTuple(_args, "O&",
1018 CtlObj_Convert, &inContainer))
1019 return NULL;
1020 _err = EmbedControl(_self->ob_itself,
1021 inContainer);
1022 if (_err != noErr) return PyMac_Error(_err);
1023 Py_INCREF(Py_None);
1024 _res = Py_None;
1025 return _res;
1026}
1027
1028static PyObject *CtlObj_AutoEmbedControl(_self, _args)
1029 ControlObject *_self;
1030 PyObject *_args;
1031{
1032 PyObject *_res = NULL;
1033 OSErr _err;
1034 WindowPtr inWindow;
1035 if (!PyArg_ParseTuple(_args, "O&",
1036 WinObj_Convert, &inWindow))
1037 return NULL;
1038 _err = AutoEmbedControl(_self->ob_itself,
1039 inWindow);
1040 if (_err != noErr) return PyMac_Error(_err);
1041 Py_INCREF(Py_None);
1042 _res = Py_None;
1043 return _res;
1044}
1045
1046static PyObject *CtlObj_GetSuperControl(_self, _args)
1047 ControlObject *_self;
1048 PyObject *_args;
1049{
1050 PyObject *_res = NULL;
1051 OSErr _err;
1052 ControlHandle outParent;
1053 if (!PyArg_ParseTuple(_args, ""))
1054 return NULL;
1055 _err = GetSuperControl(_self->ob_itself,
1056 &outParent);
1057 if (_err != noErr) return PyMac_Error(_err);
1058 _res = Py_BuildValue("O&",
1059 CtlObj_WhichControl, outParent);
1060 return _res;
1061}
1062
1063static PyObject *CtlObj_CountSubControls(_self, _args)
1064 ControlObject *_self;
1065 PyObject *_args;
1066{
1067 PyObject *_res = NULL;
1068 OSErr _err;
Jack Jansen24c35311999-12-09 22:49:51 +00001069 UInt16 outNumChildren;
Jack Jansen21f96871998-02-20 16:02:09 +00001070 if (!PyArg_ParseTuple(_args, ""))
1071 return NULL;
1072 _err = CountSubControls(_self->ob_itself,
1073 &outNumChildren);
1074 if (_err != noErr) return PyMac_Error(_err);
Jack Jansen0b13e7c2000-07-07 13:09:35 +00001075 _res = Py_BuildValue("H",
Jack Jansen21f96871998-02-20 16:02:09 +00001076 outNumChildren);
1077 return _res;
1078}
1079
1080static PyObject *CtlObj_GetIndexedSubControl(_self, _args)
1081 ControlObject *_self;
1082 PyObject *_args;
1083{
1084 PyObject *_res = NULL;
1085 OSErr _err;
Jack Jansen24c35311999-12-09 22:49:51 +00001086 UInt16 inIndex;
Jack Jansen21f96871998-02-20 16:02:09 +00001087 ControlHandle outSubControl;
Jack Jansen0b13e7c2000-07-07 13:09:35 +00001088 if (!PyArg_ParseTuple(_args, "H",
Jack Jansen21f96871998-02-20 16:02:09 +00001089 &inIndex))
1090 return NULL;
1091 _err = GetIndexedSubControl(_self->ob_itself,
1092 inIndex,
1093 &outSubControl);
1094 if (_err != noErr) return PyMac_Error(_err);
1095 _res = Py_BuildValue("O&",
1096 CtlObj_WhichControl, outSubControl);
1097 return _res;
1098}
1099
1100static PyObject *CtlObj_SetControlSupervisor(_self, _args)
1101 ControlObject *_self;
1102 PyObject *_args;
1103{
1104 PyObject *_res = NULL;
1105 OSErr _err;
1106 ControlHandle inBoss;
1107 if (!PyArg_ParseTuple(_args, "O&",
1108 CtlObj_Convert, &inBoss))
1109 return NULL;
1110 _err = SetControlSupervisor(_self->ob_itself,
1111 inBoss);
1112 if (_err != noErr) return PyMac_Error(_err);
1113 Py_INCREF(Py_None);
1114 _res = Py_None;
1115 return _res;
1116}
1117
1118static PyObject *CtlObj_GetControlFeatures(_self, _args)
1119 ControlObject *_self;
1120 PyObject *_args;
1121{
1122 PyObject *_res = NULL;
1123 OSErr _err;
1124 UInt32 outFeatures;
1125 if (!PyArg_ParseTuple(_args, ""))
1126 return NULL;
1127 _err = GetControlFeatures(_self->ob_itself,
1128 &outFeatures);
1129 if (_err != noErr) return PyMac_Error(_err);
1130 _res = Py_BuildValue("l",
1131 outFeatures);
1132 return _res;
1133}
1134
1135static PyObject *CtlObj_GetControlDataSize(_self, _args)
1136 ControlObject *_self;
1137 PyObject *_args;
1138{
1139 PyObject *_res = NULL;
1140 OSErr _err;
1141 ControlPartCode inPart;
1142 ResType inTagName;
1143 Size outMaxSize;
1144 if (!PyArg_ParseTuple(_args, "hO&",
1145 &inPart,
1146 PyMac_GetOSType, &inTagName))
1147 return NULL;
1148 _err = GetControlDataSize(_self->ob_itself,
1149 inPart,
1150 inTagName,
1151 &outMaxSize);
1152 if (_err != noErr) return PyMac_Error(_err);
1153 _res = Py_BuildValue("l",
1154 outMaxSize);
1155 return _res;
1156}
1157
Jack Jansen5d56f4b1995-06-18 20:16:33 +00001158static PyObject *CtlObj_as_Resource(_self, _args)
1159 ControlObject *_self;
1160 PyObject *_args;
1161{
1162 PyObject *_res = NULL;
Jack Jansena1a0fef1999-12-23 14:32:06 +00001163 Handle _rv;
1164 if (!PyArg_ParseTuple(_args, ""))
1165 return NULL;
1166 _rv = as_Resource(_self->ob_itself);
1167 _res = Py_BuildValue("O&",
1168 ResObj_New, _rv);
1169 return _res;
Jack Jansen5d56f4b1995-06-18 20:16:33 +00001170}
1171
Jack Jansen1a7d5b12000-03-21 16:25:23 +00001172static PyObject *CtlObj_GetControlRect(_self, _args)
1173 ControlObject *_self;
1174 PyObject *_args;
1175{
1176 PyObject *_res = NULL;
1177 Rect rect;
1178 if (!PyArg_ParseTuple(_args, ""))
1179 return NULL;
1180 GetControlRect(_self->ob_itself,
1181 &rect);
1182 _res = Py_BuildValue("O&",
1183 PyMac_BuildRect, &rect);
1184 return _res;
1185}
1186
Jack Jansencfb60ee1996-10-01 10:46:46 +00001187static PyObject *CtlObj_DisposeControl(_self, _args)
1188 ControlObject *_self;
1189 PyObject *_args;
1190{
1191 PyObject *_res = NULL;
1192
1193 if (!PyArg_ParseTuple(_args, ""))
1194 return NULL;
1195 if ( _self->ob_itself ) {
Jack Jansen85ae4a81997-04-08 15:26:03 +00001196 SetControlReference(_self->ob_itself, (long)0); /* Make it forget about us */
Jack Jansencfb60ee1996-10-01 10:46:46 +00001197 DisposeControl(_self->ob_itself);
1198 _self->ob_itself = NULL;
1199 }
1200 Py_INCREF(Py_None);
1201 _res = Py_None;
1202 return _res;
1203
1204}
1205
Jack Jansen848250c1998-05-28 14:20:09 +00001206static PyObject *CtlObj_TrackControl(_self, _args)
1207 ControlObject *_self;
1208 PyObject *_args;
1209{
1210 PyObject *_res = NULL;
1211
1212 ControlPartCode _rv;
1213 Point startPoint;
1214 ControlActionUPP upp = 0;
1215 PyObject *callback = 0;
1216
1217 if (!PyArg_ParseTuple(_args, "O&|O",
1218 PyMac_GetPoint, &startPoint, &callback))
1219 return NULL;
1220 if (callback && callback != Py_None) {
1221 if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
1222 upp = (ControlActionUPP)-1;
1223 else {
1224 settrackfunc(callback);
1225 upp = mytracker_upp;
1226 }
1227 }
1228 _rv = TrackControl(_self->ob_itself,
1229 startPoint,
1230 upp);
1231 clrtrackfunc();
1232 _res = Py_BuildValue("h",
1233 _rv);
1234 return _res;
1235
1236}
1237
Jack Jansen24c35311999-12-09 22:49:51 +00001238static PyObject *CtlObj_HandleControlClick(_self, _args)
1239 ControlObject *_self;
1240 PyObject *_args;
1241{
1242 PyObject *_res = NULL;
1243
1244 ControlPartCode _rv;
1245 Point startPoint;
1246 SInt16 modifiers;
1247 ControlActionUPP upp = 0;
1248 PyObject *callback = 0;
1249
1250 if (!PyArg_ParseTuple(_args, "O&h|O",
1251 PyMac_GetPoint, &startPoint,
1252 &modifiers,
1253 &callback))
1254 return NULL;
1255 if (callback && callback != Py_None) {
1256 if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
1257 upp = (ControlActionUPP)-1;
1258 else {
1259 settrackfunc(callback);
1260 upp = mytracker_upp;
1261 }
1262 }
1263 _rv = HandleControlClick(_self->ob_itself,
1264 startPoint,
1265 modifiers,
1266 upp);
1267 clrtrackfunc();
1268 _res = Py_BuildValue("h",
1269 _rv);
1270 return _res;
1271
1272}
1273
1274static PyObject *CtlObj_SetControlData(_self, _args)
1275 ControlObject *_self;
1276 PyObject *_args;
1277{
1278 PyObject *_res = NULL;
1279
1280 OSErr _err;
1281 ControlPartCode inPart;
1282 ResType inTagName;
1283 Size bufferSize;
1284 Ptr buffer;
1285
1286 if (!PyArg_ParseTuple(_args, "hO&s#",
1287 &inPart,
1288 PyMac_GetOSType, &inTagName,
1289 &buffer, &bufferSize))
1290 return NULL;
1291
1292 _err = SetControlData(_self->ob_itself,
1293 inPart,
1294 inTagName,
1295 bufferSize,
1296 buffer);
1297
1298 if (_err != noErr)
1299 return PyMac_Error(_err);
1300 _res = Py_None;
1301 return _res;
1302
1303}
1304
1305static PyObject *CtlObj_GetControlData(_self, _args)
1306 ControlObject *_self;
1307 PyObject *_args;
1308{
1309 PyObject *_res = NULL;
1310
1311 OSErr _err;
1312 ControlPartCode inPart;
1313 ResType inTagName;
1314 Size bufferSize;
1315 Ptr buffer;
1316 Size outSize;
1317
1318 if (!PyArg_ParseTuple(_args, "hO&",
1319 &inPart,
1320 PyMac_GetOSType, &inTagName))
1321 return NULL;
1322
1323 /* allocate a buffer for the data */
1324 _err = GetControlDataSize(_self->ob_itself,
1325 inPart,
1326 inTagName,
1327 &bufferSize);
1328 if (_err != noErr)
1329 return PyMac_Error(_err);
1330 buffer = PyMem_NEW(char, bufferSize);
1331 if (buffer == NULL)
1332 return PyErr_NoMemory();
1333
1334 _err = GetControlData(_self->ob_itself,
1335 inPart,
1336 inTagName,
1337 bufferSize,
1338 buffer,
1339 &outSize);
1340
1341 if (_err != noErr) {
1342 PyMem_DEL(buffer);
1343 return PyMac_Error(_err);
1344 }
1345 _res = Py_BuildValue("s#", buffer, outSize);
1346 PyMem_DEL(buffer);
1347 return _res;
1348
1349}
1350
Jack Jansen1f9249c1999-12-19 00:05:50 +00001351static PyObject *CtlObj_SetControlDataHandle(_self, _args)
1352 ControlObject *_self;
1353 PyObject *_args;
1354{
1355 PyObject *_res = NULL;
1356
1357 OSErr _err;
1358 ControlPartCode inPart;
1359 ResType inTagName;
1360 Handle buffer;
1361
1362 if (!PyArg_ParseTuple(_args, "hO&O&",
1363 &inPart,
1364 PyMac_GetOSType, &inTagName,
Jack Jansenb9247d31999-12-23 23:06:07 +00001365 OptResObj_Convert, &buffer))
Jack Jansen1f9249c1999-12-19 00:05:50 +00001366 return NULL;
1367
1368 _err = SetControlData(_self->ob_itself,
1369 inPart,
1370 inTagName,
1371 sizeof(buffer),
Jack Jansenf7ac1d31999-12-29 12:37:22 +00001372 (Ptr)&buffer);
Jack Jansen1f9249c1999-12-19 00:05:50 +00001373
1374 if (_err != noErr)
1375 return PyMac_Error(_err);
1376 _res = Py_None;
1377 return _res;
1378
1379}
1380
1381static PyObject *CtlObj_GetControlDataHandle(_self, _args)
1382 ControlObject *_self;
1383 PyObject *_args;
1384{
1385 PyObject *_res = NULL;
1386
1387 OSErr _err;
1388 ControlPartCode inPart;
1389 ResType inTagName;
1390 Size bufferSize;
1391 Handle hdl;
1392
1393 if (!PyArg_ParseTuple(_args, "hO&",
1394 &inPart,
1395 PyMac_GetOSType, &inTagName))
1396 return NULL;
1397
1398 /* Check it is handle-sized */
1399 _err = GetControlDataSize(_self->ob_itself,
1400 inPart,
1401 inTagName,
1402 &bufferSize);
1403 if (_err != noErr)
1404 return PyMac_Error(_err);
1405 if (bufferSize != sizeof(Handle)) {
1406 PyErr_SetString(Ctl_Error, "GetControlDataSize() != sizeof(Handle)");
1407 return NULL;
1408 }
1409
1410 _err = GetControlData(_self->ob_itself,
1411 inPart,
1412 inTagName,
1413 sizeof(Handle),
1414 (Ptr)&hdl,
1415 &bufferSize);
1416
1417 if (_err != noErr) {
1418 return PyMac_Error(_err);
1419 }
1420 return Py_BuildValue("O&", OptResObj_New, hdl);
1421
1422}
1423
Jack Jansene79dc762000-06-02 21:35:07 +00001424#ifndef TARGET_API_MAC_CARBON_NOTYET
1425
Jack Jansenabc411b2000-03-20 16:09:09 +00001426static PyObject *CtlObj_SetControlDataCallback(_self, _args)
1427 ControlObject *_self;
1428 PyObject *_args;
1429{
1430 PyObject *_res = NULL;
1431
1432 OSErr _err;
1433 ControlPartCode inPart;
1434 ResType inTagName;
1435 PyObject *callback;
Jack Jansen85152b92000-07-11 21:12:55 +00001436 UniversalProcPtr c_callback;
Jack Jansenabc411b2000-03-20 16:09:09 +00001437
1438 if (!PyArg_ParseTuple(_args, "hO&O",
1439 &inPart,
1440 PyMac_GetOSType, &inTagName,
1441 &callback))
1442 return NULL;
1443
Jack Jansen85152b92000-07-11 21:12:55 +00001444 if ( setcallback((PyObject *)_self, inTagName, callback, &c_callback) < 0 )
Jack Jansenabc411b2000-03-20 16:09:09 +00001445 return NULL;
1446 _err = SetControlData(_self->ob_itself,
1447 inPart,
1448 inTagName,
1449 sizeof(c_callback),
1450 (Ptr)&c_callback);
1451
1452 if (_err != noErr)
1453 return PyMac_Error(_err);
1454 _res = Py_None;
1455 return _res;
1456
1457}
Jack Jansene79dc762000-06-02 21:35:07 +00001458#endif
1459
1460#ifndef TARGET_API_MAC_CARBON_NOTYET
Jack Jansenabc411b2000-03-20 16:09:09 +00001461
Jack Jansen4c704131998-06-19 13:35:14 +00001462static PyObject *CtlObj_GetPopupData(_self, _args)
1463 ControlObject *_self;
1464 PyObject *_args;
1465{
1466 PyObject *_res = NULL;
1467
1468 PopupPrivateDataHandle hdl;
1469
1470 if ( (*_self->ob_itself)->contrlData == NULL ) {
1471 PyErr_SetString(Ctl_Error, "No contrlData handle in control");
1472 return 0;
1473 }
1474 hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
1475 HLock((Handle)hdl);
1476 _res = Py_BuildValue("O&i", MenuObj_New, (*hdl)->mHandle, (int)(*hdl)->mID);
1477 HUnlock((Handle)hdl);
1478 return _res;
1479
1480}
Jack Jansene79dc762000-06-02 21:35:07 +00001481#endif
1482
1483#ifndef TARGET_API_MAC_CARBON_NOTYET
Jack Jansen4c704131998-06-19 13:35:14 +00001484
1485static PyObject *CtlObj_SetPopupData(_self, _args)
1486 ControlObject *_self;
1487 PyObject *_args;
1488{
1489 PyObject *_res = NULL;
1490
1491 PopupPrivateDataHandle hdl;
1492 MenuHandle mHandle;
1493 short mID;
1494
1495 if (!PyArg_ParseTuple(_args, "O&h", MenuObj_Convert, &mHandle, &mID) )
1496 return 0;
1497 if ( (*_self->ob_itself)->contrlData == NULL ) {
1498 PyErr_SetString(Ctl_Error, "No contrlData handle in control");
1499 return 0;
1500 }
1501 hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
1502 (*hdl)->mHandle = mHandle;
1503 (*hdl)->mID = mID;
1504 Py_INCREF(Py_None);
1505 return Py_None;
1506
1507}
Jack Jansene79dc762000-06-02 21:35:07 +00001508#endif
Jack Jansen4c704131998-06-19 13:35:14 +00001509
Guido van Rossum17448e21995-01-30 11:53:55 +00001510static PyMethodDef CtlObj_methods[] = {
Jack Jansen21f96871998-02-20 16:02:09 +00001511 {"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1,
1512 "(ControlPartCode hiliteState) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001513 {"ShowControl", (PyCFunction)CtlObj_ShowControl, 1,
1514 "() -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001515 {"HideControl", (PyCFunction)CtlObj_HideControl, 1,
1516 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001517 {"IsControlActive", (PyCFunction)CtlObj_IsControlActive, 1,
1518 "() -> (Boolean _rv)"},
1519 {"IsControlVisible", (PyCFunction)CtlObj_IsControlVisible, 1,
1520 "() -> (Boolean _rv)"},
1521 {"ActivateControl", (PyCFunction)CtlObj_ActivateControl, 1,
1522 "() -> None"},
1523 {"DeactivateControl", (PyCFunction)CtlObj_DeactivateControl, 1,
1524 "() -> None"},
1525 {"SetControlVisibility", (PyCFunction)CtlObj_SetControlVisibility, 1,
1526 "(Boolean inIsVisible, Boolean inDoDraw) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001527 {"Draw1Control", (PyCFunction)CtlObj_Draw1Control, 1,
1528 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001529 {"GetBestControlRect", (PyCFunction)CtlObj_GetBestControlRect, 1,
1530 "() -> (Rect outRect, SInt16 outBaseLineOffset)"},
1531 {"SetControlFontStyle", (PyCFunction)CtlObj_SetControlFontStyle, 1,
1532 "(ControlFontStyleRec inStyle) -> None"},
1533 {"DrawControlInCurrentPort", (PyCFunction)CtlObj_DrawControlInCurrentPort, 1,
1534 "() -> None"},
1535 {"SetUpControlBackground", (PyCFunction)CtlObj_SetUpControlBackground, 1,
1536 "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +00001537 {"SetUpControlTextColor", (PyCFunction)CtlObj_SetUpControlTextColor, 1,
1538 "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001539 {"DragControl", (PyCFunction)CtlObj_DragControl, 1,
Jack Jansen754d4a41995-11-14 10:41:55 +00001540 "(Point startPoint, Rect limitRect, Rect slopRect, DragConstraint axis) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001541 {"TestControl", (PyCFunction)CtlObj_TestControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001542 "(Point testPoint) -> (ControlPartCode _rv)"},
1543 {"HandleControlKey", (PyCFunction)CtlObj_HandleControlKey, 1,
1544 "(SInt16 inKeyCode, SInt16 inCharCode, SInt16 inModifiers) -> (SInt16 _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001545 {"MoveControl", (PyCFunction)CtlObj_MoveControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001546 "(SInt16 h, SInt16 v) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001547 {"SizeControl", (PyCFunction)CtlObj_SizeControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001548 "(SInt16 w, SInt16 h) -> None"},
1549 {"SetControlTitle", (PyCFunction)CtlObj_SetControlTitle, 1,
1550 "(Str255 title) -> None"},
1551 {"GetControlTitle", (PyCFunction)CtlObj_GetControlTitle, 1,
Jack Jansen41009001999-03-07 20:05:20 +00001552 "() -> (Str255 title)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001553 {"GetControlValue", (PyCFunction)CtlObj_GetControlValue, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001554 "() -> (SInt16 _rv)"},
1555 {"SetControlValue", (PyCFunction)CtlObj_SetControlValue, 1,
1556 "(SInt16 newValue) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001557 {"GetControlMinimum", (PyCFunction)CtlObj_GetControlMinimum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001558 "() -> (SInt16 _rv)"},
1559 {"SetControlMinimum", (PyCFunction)CtlObj_SetControlMinimum, 1,
1560 "(SInt16 newMinimum) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001561 {"GetControlMaximum", (PyCFunction)CtlObj_GetControlMaximum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001562 "() -> (SInt16 _rv)"},
1563 {"SetControlMaximum", (PyCFunction)CtlObj_SetControlMaximum, 1,
1564 "(SInt16 newMaximum) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +00001565 {"GetControlViewSize", (PyCFunction)CtlObj_GetControlViewSize, 1,
1566 "() -> (SInt32 _rv)"},
1567 {"SetControlViewSize", (PyCFunction)CtlObj_SetControlViewSize, 1,
1568 "(SInt32 newViewSize) -> None"},
1569 {"GetControl32BitValue", (PyCFunction)CtlObj_GetControl32BitValue, 1,
1570 "() -> (SInt32 _rv)"},
1571 {"SetControl32BitValue", (PyCFunction)CtlObj_SetControl32BitValue, 1,
1572 "(SInt32 newValue) -> None"},
1573 {"GetControl32BitMaximum", (PyCFunction)CtlObj_GetControl32BitMaximum, 1,
1574 "() -> (SInt32 _rv)"},
1575 {"SetControl32BitMaximum", (PyCFunction)CtlObj_SetControl32BitMaximum, 1,
1576 "(SInt32 newMaximum) -> None"},
1577 {"GetControl32BitMinimum", (PyCFunction)CtlObj_GetControl32BitMinimum, 1,
1578 "() -> (SInt32 _rv)"},
1579 {"SetControl32BitMinimum", (PyCFunction)CtlObj_SetControl32BitMinimum, 1,
1580 "(SInt32 newMinimum) -> None"},
1581 {"IsValidControlHandle", (PyCFunction)CtlObj_IsValidControlHandle, 1,
1582 "() -> (Boolean _rv)"},
1583 {"RemoveControlProperty", (PyCFunction)CtlObj_RemoveControlProperty, 1,
Jack Jansene79dc762000-06-02 21:35:07 +00001584 "(OSType propertyCreator, OSType propertyTag) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +00001585 {"GetControlRegion", (PyCFunction)CtlObj_GetControlRegion, 1,
Jack Jansene79dc762000-06-02 21:35:07 +00001586 "(ControlPartCode inPart, RgnHandle outRegion) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001587 {"GetControlVariant", (PyCFunction)CtlObj_GetControlVariant, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001588 "() -> (ControlVariant _rv)"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001589 {"SetControlReference", (PyCFunction)CtlObj_SetControlReference, 1,
1590 "(SInt32 data) -> None"},
1591 {"GetControlReference", (PyCFunction)CtlObj_GetControlReference, 1,
1592 "() -> (SInt32 _rv)"},
Jack Jansene79dc762000-06-02 21:35:07 +00001593
1594#ifndef TARGET_API_MAC_CARBON
Jack Jansenc7fefed1997-08-15 14:32:18 +00001595 {"GetAuxiliaryControlRecord", (PyCFunction)CtlObj_GetAuxiliaryControlRecord, 1,
1596 "() -> (Boolean _rv, AuxCtlHandle acHndl)"},
Jack Jansene79dc762000-06-02 21:35:07 +00001597#endif
1598
1599#ifndef TARGET_API_MAC_CARBON
Jack Jansenc7fefed1997-08-15 14:32:18 +00001600 {"SetControlColor", (PyCFunction)CtlObj_SetControlColor, 1,
1601 "(CCTabHandle newColorTable) -> None"},
Jack Jansene79dc762000-06-02 21:35:07 +00001602#endif
Jack Jansen9d8b96c2000-07-14 22:16:45 +00001603
1604#ifndef TARGET_API_MAC_CARBON
Jack Jansene79dc762000-06-02 21:35:07 +00001605 {"GetBevelButtonMenuValue", (PyCFunction)CtlObj_GetBevelButtonMenuValue, 1,
1606 "() -> (SInt16 outValue)"},
Jack Jansen9d8b96c2000-07-14 22:16:45 +00001607#endif
1608
1609#ifndef TARGET_API_MAC_CARBON
Jack Jansene79dc762000-06-02 21:35:07 +00001610 {"SetBevelButtonMenuValue", (PyCFunction)CtlObj_SetBevelButtonMenuValue, 1,
1611 "(SInt16 inValue) -> None"},
Jack Jansen9d8b96c2000-07-14 22:16:45 +00001612#endif
1613
1614#ifndef TARGET_API_MAC_CARBON
Jack Jansene79dc762000-06-02 21:35:07 +00001615 {"GetBevelButtonMenuHandle", (PyCFunction)CtlObj_GetBevelButtonMenuHandle, 1,
1616 "() -> (MenuHandle outHandle)"},
Jack Jansen9d8b96c2000-07-14 22:16:45 +00001617#endif
1618
1619#ifndef TARGET_API_MAC_CARBON
Jack Jansene79dc762000-06-02 21:35:07 +00001620 {"SetBevelButtonTransform", (PyCFunction)CtlObj_SetBevelButtonTransform, 1,
1621 "(IconTransformType transform) -> None"},
Jack Jansen9d8b96c2000-07-14 22:16:45 +00001622#endif
1623
1624#ifndef TARGET_API_MAC_CARBON
Jack Jansene79dc762000-06-02 21:35:07 +00001625 {"SetImageWellTransform", (PyCFunction)CtlObj_SetImageWellTransform, 1,
1626 "(IconTransformType inTransform) -> None"},
Jack Jansen9d8b96c2000-07-14 22:16:45 +00001627#endif
1628
1629#ifndef TARGET_API_MAC_CARBON
Jack Jansene79dc762000-06-02 21:35:07 +00001630 {"GetTabContentRect", (PyCFunction)CtlObj_GetTabContentRect, 1,
1631 "() -> (Rect outContentRect)"},
Jack Jansen9d8b96c2000-07-14 22:16:45 +00001632#endif
1633
1634#ifndef TARGET_API_MAC_CARBON
Jack Jansene79dc762000-06-02 21:35:07 +00001635 {"SetTabEnabled", (PyCFunction)CtlObj_SetTabEnabled, 1,
1636 "(SInt16 inTabToHilite, Boolean inEnabled) -> None"},
Jack Jansen9d8b96c2000-07-14 22:16:45 +00001637#endif
1638
1639#ifndef TARGET_API_MAC_CARBON
Jack Jansene79dc762000-06-02 21:35:07 +00001640 {"SetDisclosureTriangleLastValue", (PyCFunction)CtlObj_SetDisclosureTriangleLastValue, 1,
1641 "(SInt16 inValue) -> None"},
Jack Jansen9d8b96c2000-07-14 22:16:45 +00001642#endif
Jack Jansen21f96871998-02-20 16:02:09 +00001643 {"SendControlMessage", (PyCFunction)CtlObj_SendControlMessage, 1,
1644 "(SInt16 inMessage, SInt32 inParam) -> (SInt32 _rv)"},
1645 {"EmbedControl", (PyCFunction)CtlObj_EmbedControl, 1,
1646 "(ControlHandle inContainer) -> None"},
1647 {"AutoEmbedControl", (PyCFunction)CtlObj_AutoEmbedControl, 1,
1648 "(WindowPtr inWindow) -> None"},
1649 {"GetSuperControl", (PyCFunction)CtlObj_GetSuperControl, 1,
1650 "() -> (ControlHandle outParent)"},
1651 {"CountSubControls", (PyCFunction)CtlObj_CountSubControls, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00001652 "() -> (UInt16 outNumChildren)"},
Jack Jansen21f96871998-02-20 16:02:09 +00001653 {"GetIndexedSubControl", (PyCFunction)CtlObj_GetIndexedSubControl, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00001654 "(UInt16 inIndex) -> (ControlHandle outSubControl)"},
Jack Jansen21f96871998-02-20 16:02:09 +00001655 {"SetControlSupervisor", (PyCFunction)CtlObj_SetControlSupervisor, 1,
1656 "(ControlHandle inBoss) -> None"},
1657 {"GetControlFeatures", (PyCFunction)CtlObj_GetControlFeatures, 1,
1658 "() -> (UInt32 outFeatures)"},
1659 {"GetControlDataSize", (PyCFunction)CtlObj_GetControlDataSize, 1,
1660 "(ControlPartCode inPart, ResType inTagName) -> (Size outMaxSize)"},
Jack Jansen5d56f4b1995-06-18 20:16:33 +00001661 {"as_Resource", (PyCFunction)CtlObj_as_Resource, 1,
Jack Jansena1a0fef1999-12-23 14:32:06 +00001662 "() -> (Handle _rv)"},
Jack Jansen1a7d5b12000-03-21 16:25:23 +00001663 {"GetControlRect", (PyCFunction)CtlObj_GetControlRect, 1,
1664 "() -> (Rect rect)"},
Jack Jansencfb60ee1996-10-01 10:46:46 +00001665 {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1,
1666 "() -> None"},
Jack Jansen848250c1998-05-28 14:20:09 +00001667 {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00001668 "(Point startPoint [,trackercallback]) -> (ControlPartCode _rv)"},
1669 {"HandleControlClick", (PyCFunction)CtlObj_HandleControlClick, 1,
1670 "(Point startPoint, Integer modifiers, [,trackercallback]) -> (ControlPartCode _rv)"},
1671 {"SetControlData", (PyCFunction)CtlObj_SetControlData, 1,
1672 "(stuff) -> None"},
1673 {"GetControlData", (PyCFunction)CtlObj_GetControlData, 1,
1674 "(part, type) -> String"},
Jack Jansen1f9249c1999-12-19 00:05:50 +00001675 {"SetControlDataHandle", (PyCFunction)CtlObj_SetControlDataHandle, 1,
1676 "(ResObj) -> None"},
1677 {"GetControlDataHandle", (PyCFunction)CtlObj_GetControlDataHandle, 1,
1678 "(part, type) -> ResObj"},
Jack Jansene79dc762000-06-02 21:35:07 +00001679
1680#ifndef TARGET_API_MAC_CARBON_NOTYET
Jack Jansenabc411b2000-03-20 16:09:09 +00001681 {"SetControlDataCallback", (PyCFunction)CtlObj_SetControlDataCallback, 1,
1682 "(callbackfunc) -> None"},
Jack Jansene79dc762000-06-02 21:35:07 +00001683#endif
1684
1685#ifndef TARGET_API_MAC_CARBON_NOTYET
Jack Jansen4c704131998-06-19 13:35:14 +00001686 {"GetPopupData", (PyCFunction)CtlObj_GetPopupData, 1,
1687 NULL},
Jack Jansene79dc762000-06-02 21:35:07 +00001688#endif
1689
1690#ifndef TARGET_API_MAC_CARBON_NOTYET
Jack Jansen4c704131998-06-19 13:35:14 +00001691 {"SetPopupData", (PyCFunction)CtlObj_SetPopupData, 1,
1692 NULL},
Jack Jansene79dc762000-06-02 21:35:07 +00001693#endif
Guido van Rossum17448e21995-01-30 11:53:55 +00001694 {NULL, NULL, 0}
1695};
1696
1697PyMethodChain CtlObj_chain = { CtlObj_methods, NULL };
1698
1699static PyObject *CtlObj_getattr(self, name)
1700 ControlObject *self;
1701 char *name;
1702{
1703 return Py_FindMethodInChain(&CtlObj_chain, (PyObject *)self, name);
1704}
1705
1706#define CtlObj_setattr NULL
1707
Jack Jansen8387af61999-03-13 23:07:32 +00001708static int CtlObj_compare(self, other)
1709 ControlObject *self, *other;
1710{
1711 unsigned long v, w;
1712
1713 if (!CtlObj_Check((PyObject *)other))
1714 {
1715 v=(unsigned long)self;
1716 w=(unsigned long)other;
1717 }
1718 else
1719 {
1720 v=(unsigned long)self->ob_itself;
1721 w=(unsigned long)other->ob_itself;
1722 }
1723 if( v < w ) return -1;
1724 if( v > w ) return 1;
1725 return 0;
1726}
1727
1728#define CtlObj_repr NULL
1729
1730static long CtlObj_hash(self)
1731 ControlObject *self;
1732{
1733 return (long)self->ob_itself;
1734}
1735
Guido van Rossum17448e21995-01-30 11:53:55 +00001736PyTypeObject Control_Type = {
1737 PyObject_HEAD_INIT(&PyType_Type)
1738 0, /*ob_size*/
1739 "Control", /*tp_name*/
1740 sizeof(ControlObject), /*tp_basicsize*/
1741 0, /*tp_itemsize*/
1742 /* methods */
1743 (destructor) CtlObj_dealloc, /*tp_dealloc*/
1744 0, /*tp_print*/
1745 (getattrfunc) CtlObj_getattr, /*tp_getattr*/
1746 (setattrfunc) CtlObj_setattr, /*tp_setattr*/
Jack Jansen8387af61999-03-13 23:07:32 +00001747 (cmpfunc) CtlObj_compare, /*tp_compare*/
1748 (reprfunc) CtlObj_repr, /*tp_repr*/
1749 (PyNumberMethods *)0, /* tp_as_number */
1750 (PySequenceMethods *)0, /* tp_as_sequence */
1751 (PyMappingMethods *)0, /* tp_as_mapping */
1752 (hashfunc) CtlObj_hash, /*tp_hash*/
Guido van Rossum17448e21995-01-30 11:53:55 +00001753};
1754
1755/* -------------------- End object type Control --------------------- */
1756
1757
1758static PyObject *Ctl_NewControl(_self, _args)
1759 PyObject *_self;
1760 PyObject *_args;
1761{
1762 PyObject *_res = NULL;
1763 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001764 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00001765 Rect boundsRect;
Jack Jansen21f96871998-02-20 16:02:09 +00001766 Str255 controlTitle;
1767 Boolean initiallyVisible;
1768 SInt16 initialValue;
1769 SInt16 minimumValue;
1770 SInt16 maximumValue;
Jack Jansen7d0bc831995-06-09 20:56:31 +00001771 SInt16 procID;
Jack Jansen21f96871998-02-20 16:02:09 +00001772 SInt32 controlReference;
Guido van Rossum17448e21995-01-30 11:53:55 +00001773 if (!PyArg_ParseTuple(_args, "O&O&O&bhhhhl",
Jack Jansen21f96871998-02-20 16:02:09 +00001774 WinObj_Convert, &owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00001775 PyMac_GetRect, &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00001776 PyMac_GetStr255, controlTitle,
1777 &initiallyVisible,
1778 &initialValue,
1779 &minimumValue,
1780 &maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00001781 &procID,
Jack Jansen21f96871998-02-20 16:02:09 +00001782 &controlReference))
Guido van Rossum17448e21995-01-30 11:53:55 +00001783 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001784 _rv = NewControl(owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00001785 &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00001786 controlTitle,
1787 initiallyVisible,
1788 initialValue,
1789 minimumValue,
1790 maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00001791 procID,
Jack Jansen21f96871998-02-20 16:02:09 +00001792 controlReference);
Guido van Rossum17448e21995-01-30 11:53:55 +00001793 _res = Py_BuildValue("O&",
1794 CtlObj_New, _rv);
1795 return _res;
1796}
1797
1798static PyObject *Ctl_GetNewControl(_self, _args)
1799 PyObject *_self;
1800 PyObject *_args;
1801{
1802 PyObject *_res = NULL;
1803 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001804 SInt16 resourceID;
1805 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00001806 if (!PyArg_ParseTuple(_args, "hO&",
Jack Jansen21f96871998-02-20 16:02:09 +00001807 &resourceID,
1808 WinObj_Convert, &owningWindow))
Guido van Rossum17448e21995-01-30 11:53:55 +00001809 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001810 _rv = GetNewControl(resourceID,
1811 owningWindow);
Guido van Rossum17448e21995-01-30 11:53:55 +00001812 _res = Py_BuildValue("O&",
1813 CtlObj_New, _rv);
1814 return _res;
1815}
1816
Guido van Rossum17448e21995-01-30 11:53:55 +00001817static PyObject *Ctl_DrawControls(_self, _args)
1818 PyObject *_self;
1819 PyObject *_args;
1820{
1821 PyObject *_res = NULL;
1822 WindowPtr theWindow;
1823 if (!PyArg_ParseTuple(_args, "O&",
1824 WinObj_Convert, &theWindow))
1825 return NULL;
1826 DrawControls(theWindow);
1827 Py_INCREF(Py_None);
1828 _res = Py_None;
1829 return _res;
1830}
1831
Guido van Rossum17448e21995-01-30 11:53:55 +00001832static PyObject *Ctl_UpdateControls(_self, _args)
1833 PyObject *_self;
1834 PyObject *_args;
1835{
1836 PyObject *_res = NULL;
1837 WindowPtr theWindow;
Jack Jansen2b724171996-04-10 14:48:19 +00001838 RgnHandle updateRegion;
1839 if (!PyArg_ParseTuple(_args, "O&O&",
1840 WinObj_Convert, &theWindow,
1841 ResObj_Convert, &updateRegion))
Guido van Rossum17448e21995-01-30 11:53:55 +00001842 return NULL;
1843 UpdateControls(theWindow,
Jack Jansen2b724171996-04-10 14:48:19 +00001844 updateRegion);
Guido van Rossum17448e21995-01-30 11:53:55 +00001845 Py_INCREF(Py_None);
1846 _res = Py_None;
1847 return _res;
1848}
1849
1850static PyObject *Ctl_FindControl(_self, _args)
1851 PyObject *_self;
1852 PyObject *_args;
1853{
1854 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +00001855 ControlPartCode _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001856 Point testPoint;
Guido van Rossum17448e21995-01-30 11:53:55 +00001857 WindowPtr theWindow;
1858 ControlHandle theControl;
1859 if (!PyArg_ParseTuple(_args, "O&O&",
Jack Jansen21f96871998-02-20 16:02:09 +00001860 PyMac_GetPoint, &testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00001861 WinObj_Convert, &theWindow))
1862 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001863 _rv = FindControl(testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00001864 theWindow,
1865 &theControl);
1866 _res = Py_BuildValue("hO&",
1867 _rv,
1868 CtlObj_WhichControl, theControl);
1869 return _res;
1870}
1871
Jack Jansen21f96871998-02-20 16:02:09 +00001872static PyObject *Ctl_FindControlUnderMouse(_self, _args)
1873 PyObject *_self;
1874 PyObject *_args;
1875{
1876 PyObject *_res = NULL;
1877 ControlHandle _rv;
1878 Point inWhere;
1879 WindowPtr inWindow;
1880 SInt16 outPart;
1881 if (!PyArg_ParseTuple(_args, "O&O&",
1882 PyMac_GetPoint, &inWhere,
1883 WinObj_Convert, &inWindow))
1884 return NULL;
1885 _rv = FindControlUnderMouse(inWhere,
1886 inWindow,
1887 &outPart);
1888 _res = Py_BuildValue("O&h",
1889 CtlObj_New, _rv,
1890 outPart);
1891 return _res;
1892}
1893
1894static PyObject *Ctl_IdleControls(_self, _args)
1895 PyObject *_self;
1896 PyObject *_args;
1897{
1898 PyObject *_res = NULL;
1899 WindowPtr inWindow;
1900 if (!PyArg_ParseTuple(_args, "O&",
1901 WinObj_Convert, &inWindow))
1902 return NULL;
1903 IdleControls(inWindow);
1904 Py_INCREF(Py_None);
1905 _res = Py_None;
1906 return _res;
1907}
1908
1909static PyObject *Ctl_DumpControlHierarchy(_self, _args)
1910 PyObject *_self;
1911 PyObject *_args;
1912{
1913 PyObject *_res = NULL;
1914 OSErr _err;
1915 WindowPtr inWindow;
1916 FSSpec inDumpFile;
1917 if (!PyArg_ParseTuple(_args, "O&O&",
1918 WinObj_Convert, &inWindow,
1919 PyMac_GetFSSpec, &inDumpFile))
1920 return NULL;
1921 _err = DumpControlHierarchy(inWindow,
1922 &inDumpFile);
1923 if (_err != noErr) return PyMac_Error(_err);
1924 Py_INCREF(Py_None);
1925 _res = Py_None;
1926 return _res;
1927}
1928
1929static PyObject *Ctl_CreateRootControl(_self, _args)
1930 PyObject *_self;
1931 PyObject *_args;
1932{
1933 PyObject *_res = NULL;
1934 OSErr _err;
1935 WindowPtr inWindow;
1936 ControlHandle outControl;
1937 if (!PyArg_ParseTuple(_args, "O&",
1938 WinObj_Convert, &inWindow))
1939 return NULL;
1940 _err = CreateRootControl(inWindow,
1941 &outControl);
1942 if (_err != noErr) return PyMac_Error(_err);
1943 _res = Py_BuildValue("O&",
1944 CtlObj_WhichControl, outControl);
1945 return _res;
1946}
1947
1948static PyObject *Ctl_GetRootControl(_self, _args)
1949 PyObject *_self;
1950 PyObject *_args;
1951{
1952 PyObject *_res = NULL;
1953 OSErr _err;
1954 WindowPtr inWindow;
1955 ControlHandle outControl;
1956 if (!PyArg_ParseTuple(_args, "O&",
1957 WinObj_Convert, &inWindow))
1958 return NULL;
1959 _err = GetRootControl(inWindow,
1960 &outControl);
1961 if (_err != noErr) return PyMac_Error(_err);
1962 _res = Py_BuildValue("O&",
1963 CtlObj_WhichControl, outControl);
1964 return _res;
1965}
1966
1967static PyObject *Ctl_GetKeyboardFocus(_self, _args)
1968 PyObject *_self;
1969 PyObject *_args;
1970{
1971 PyObject *_res = NULL;
1972 OSErr _err;
1973 WindowPtr inWindow;
1974 ControlHandle outControl;
1975 if (!PyArg_ParseTuple(_args, "O&",
1976 WinObj_Convert, &inWindow))
1977 return NULL;
1978 _err = GetKeyboardFocus(inWindow,
1979 &outControl);
1980 if (_err != noErr) return PyMac_Error(_err);
1981 _res = Py_BuildValue("O&",
1982 CtlObj_WhichControl, outControl);
1983 return _res;
1984}
1985
1986static PyObject *Ctl_SetKeyboardFocus(_self, _args)
1987 PyObject *_self;
1988 PyObject *_args;
1989{
1990 PyObject *_res = NULL;
1991 OSErr _err;
1992 WindowPtr inWindow;
1993 ControlHandle inControl;
1994 ControlFocusPart inPart;
1995 if (!PyArg_ParseTuple(_args, "O&O&h",
1996 WinObj_Convert, &inWindow,
1997 CtlObj_Convert, &inControl,
1998 &inPart))
1999 return NULL;
2000 _err = SetKeyboardFocus(inWindow,
2001 inControl,
2002 inPart);
2003 if (_err != noErr) return PyMac_Error(_err);
2004 Py_INCREF(Py_None);
2005 _res = Py_None;
2006 return _res;
2007}
2008
2009static PyObject *Ctl_AdvanceKeyboardFocus(_self, _args)
2010 PyObject *_self;
2011 PyObject *_args;
2012{
2013 PyObject *_res = NULL;
2014 OSErr _err;
2015 WindowPtr inWindow;
2016 if (!PyArg_ParseTuple(_args, "O&",
2017 WinObj_Convert, &inWindow))
2018 return NULL;
2019 _err = AdvanceKeyboardFocus(inWindow);
2020 if (_err != noErr) return PyMac_Error(_err);
2021 Py_INCREF(Py_None);
2022 _res = Py_None;
2023 return _res;
2024}
2025
2026static PyObject *Ctl_ReverseKeyboardFocus(_self, _args)
2027 PyObject *_self;
2028 PyObject *_args;
2029{
2030 PyObject *_res = NULL;
2031 OSErr _err;
2032 WindowPtr inWindow;
2033 if (!PyArg_ParseTuple(_args, "O&",
2034 WinObj_Convert, &inWindow))
2035 return NULL;
2036 _err = ReverseKeyboardFocus(inWindow);
2037 if (_err != noErr) return PyMac_Error(_err);
2038 Py_INCREF(Py_None);
2039 _res = Py_None;
2040 return _res;
2041}
2042
2043static PyObject *Ctl_ClearKeyboardFocus(_self, _args)
2044 PyObject *_self;
2045 PyObject *_args;
2046{
2047 PyObject *_res = NULL;
2048 OSErr _err;
2049 WindowPtr inWindow;
2050 if (!PyArg_ParseTuple(_args, "O&",
2051 WinObj_Convert, &inWindow))
2052 return NULL;
2053 _err = ClearKeyboardFocus(inWindow);
2054 if (_err != noErr) return PyMac_Error(_err);
2055 Py_INCREF(Py_None);
2056 _res = Py_None;
2057 return _res;
2058}
2059
Jack Jansene0581891999-02-07 14:02:03 +00002060static PyObject *Ctl_as_Control(_self, _args)
2061 PyObject *_self;
2062 PyObject *_args;
2063{
2064 PyObject *_res = NULL;
2065 ControlHandle _rv;
2066 Handle h;
2067 if (!PyArg_ParseTuple(_args, "O&",
2068 ResObj_Convert, &h))
2069 return NULL;
2070 _rv = as_Control(h);
2071 _res = Py_BuildValue("O&",
2072 CtlObj_New, _rv);
2073 return _res;
2074}
2075
Guido van Rossum17448e21995-01-30 11:53:55 +00002076static PyMethodDef Ctl_methods[] = {
2077 {"NewControl", (PyCFunction)Ctl_NewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00002078 "(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 +00002079 {"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00002080 "(SInt16 resourceID, WindowPtr owningWindow) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002081 {"DrawControls", (PyCFunction)Ctl_DrawControls, 1,
2082 "(WindowPtr theWindow) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002083 {"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1,
Jack Jansen2b724171996-04-10 14:48:19 +00002084 "(WindowPtr theWindow, RgnHandle updateRegion) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002085 {"FindControl", (PyCFunction)Ctl_FindControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00002086 "(Point testPoint, WindowPtr theWindow) -> (ControlPartCode _rv, ControlHandle theControl)"},
2087 {"FindControlUnderMouse", (PyCFunction)Ctl_FindControlUnderMouse, 1,
2088 "(Point inWhere, WindowPtr inWindow) -> (ControlHandle _rv, SInt16 outPart)"},
2089 {"IdleControls", (PyCFunction)Ctl_IdleControls, 1,
2090 "(WindowPtr inWindow) -> None"},
2091 {"DumpControlHierarchy", (PyCFunction)Ctl_DumpControlHierarchy, 1,
2092 "(WindowPtr inWindow, FSSpec inDumpFile) -> None"},
2093 {"CreateRootControl", (PyCFunction)Ctl_CreateRootControl, 1,
2094 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
2095 {"GetRootControl", (PyCFunction)Ctl_GetRootControl, 1,
2096 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
2097 {"GetKeyboardFocus", (PyCFunction)Ctl_GetKeyboardFocus, 1,
2098 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
2099 {"SetKeyboardFocus", (PyCFunction)Ctl_SetKeyboardFocus, 1,
2100 "(WindowPtr inWindow, ControlHandle inControl, ControlFocusPart inPart) -> None"},
2101 {"AdvanceKeyboardFocus", (PyCFunction)Ctl_AdvanceKeyboardFocus, 1,
2102 "(WindowPtr inWindow) -> None"},
2103 {"ReverseKeyboardFocus", (PyCFunction)Ctl_ReverseKeyboardFocus, 1,
2104 "(WindowPtr inWindow) -> None"},
2105 {"ClearKeyboardFocus", (PyCFunction)Ctl_ClearKeyboardFocus, 1,
2106 "(WindowPtr inWindow) -> None"},
Jack Jansene0581891999-02-07 14:02:03 +00002107 {"as_Control", (PyCFunction)Ctl_as_Control, 1,
2108 "(Handle h) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002109 {NULL, NULL, 0}
2110};
2111
2112
2113
Jack Jansen9d8b96c2000-07-14 22:16:45 +00002114static PyObject *
2115CtlObj_NewUnmanaged(itself)
Jack Jansen8387af61999-03-13 23:07:32 +00002116 ControlHandle itself;
2117{
2118 ControlObject *it;
2119 if (itself == NULL) return PyMac_Error(resNotFound);
2120 it = PyObject_NEW(ControlObject, &Control_Type);
2121 if (it == NULL) return NULL;
2122 it->ob_itself = itself;
Jack Jansen1a7d5b12000-03-21 16:25:23 +00002123 it->ob_callbackdict = NULL;
Jack Jansen8387af61999-03-13 23:07:32 +00002124 return (PyObject *)it;
2125}
2126
Jack Jansen9d8b96c2000-07-14 22:16:45 +00002127static PyObject *
Guido van Rossum17448e21995-01-30 11:53:55 +00002128CtlObj_WhichControl(ControlHandle c)
2129{
2130 PyObject *it;
Jack Jansen24c35311999-12-09 22:49:51 +00002131
Guido van Rossum17448e21995-01-30 11:53:55 +00002132 if (c == NULL)
Guido van Rossum17448e21995-01-30 11:53:55 +00002133 it = Py_None;
Jack Jansen8387af61999-03-13 23:07:32 +00002134 else {
2135 it = (PyObject *) GetControlReference(c);
2136 /*
2137 ** If the refcon is zero or doesn't point back to the Python object
2138 ** the control is not ours. Return a temporary object.
2139 */
2140 if (it == NULL || ((ControlObject *)it)->ob_itself != c)
2141 return CtlObj_NewUnmanaged(c);
2142 }
Guido van Rossum17448e21995-01-30 11:53:55 +00002143 Py_INCREF(it);
2144 return it;
2145}
2146
Jack Jansen848250c1998-05-28 14:20:09 +00002147static int
2148settrackfunc(obj)
2149 PyObject *obj;
2150{
2151 if (tracker) {
2152 PyErr_SetString(Ctl_Error, "Tracker function in use");
2153 return 0;
2154 }
2155 tracker = obj;
2156 Py_INCREF(tracker);
2157}
2158
2159static void
2160clrtrackfunc()
2161{
2162 Py_XDECREF(tracker);
2163 tracker = 0;
2164}
2165
2166static pascal void
Jack Jansene79dc762000-06-02 21:35:07 +00002167mytracker(ControlHandle ctl, short part)
Jack Jansen848250c1998-05-28 14:20:09 +00002168{
2169 PyObject *args, *rv=0;
Jack Jansen24c35311999-12-09 22:49:51 +00002170
Jack Jansen848250c1998-05-28 14:20:09 +00002171 args = Py_BuildValue("(O&i)", CtlObj_WhichControl, ctl, (int)part);
2172 if (args && tracker) {
2173 rv = PyEval_CallObject(tracker, args);
2174 Py_DECREF(args);
2175 }
2176 if (rv)
2177 Py_DECREF(rv);
2178 else
Jack Jansen24c35311999-12-09 22:49:51 +00002179 PySys_WriteStderr("TrackControl or HandleControlClick: exception in tracker function\n");
Jack Jansen848250c1998-05-28 14:20:09 +00002180}
2181
Jack Jansene79dc762000-06-02 21:35:07 +00002182#ifndef TARGET_API_MAC_CARBON_NOTYET
Jack Jansenabc411b2000-03-20 16:09:09 +00002183static int
Jack Jansen85152b92000-07-11 21:12:55 +00002184setcallback(myself, which, callback, uppp)
2185 PyObject *myself;
Jack Jansenabc411b2000-03-20 16:09:09 +00002186 OSType which;
2187 PyObject *callback;
2188 UniversalProcPtr *uppp;
2189{
Jack Jansen85152b92000-07-11 21:12:55 +00002190 ControlObject *self = (ControlObject *)myself;
Jack Jansenabc411b2000-03-20 16:09:09 +00002191 char keybuf[9];
2192
2193 if ( which == kControlUserPaneDrawProcTag )
Jack Jansen1b6e8212000-04-05 21:30:57 +00002194 *uppp = (UniversalProcPtr)mydrawproc_upp;
Jack Jansenabc411b2000-03-20 16:09:09 +00002195 else if ( which == kControlUserPaneIdleProcTag )
Jack Jansen1b6e8212000-04-05 21:30:57 +00002196 *uppp = (UniversalProcPtr)myidleproc_upp;
Jack Jansena27e9fb2000-03-21 23:03:02 +00002197 else if ( which == kControlUserPaneHitTestProcTag )
Jack Jansen1b6e8212000-04-05 21:30:57 +00002198 *uppp = (UniversalProcPtr)myhittestproc_upp;
Jack Jansena27e9fb2000-03-21 23:03:02 +00002199 else if ( which == kControlUserPaneTrackingProcTag )
Jack Jansen1b6e8212000-04-05 21:30:57 +00002200 *uppp = (UniversalProcPtr)mytrackingproc_upp;
Jack Jansenabc411b2000-03-20 16:09:09 +00002201 else
2202 return -1;
2203 /* Only now do we test for clearing of the callback: */
2204 if ( callback == Py_None )
2205 *uppp = NULL;
2206 /* Create the dict if it doesn't exist yet (so we don't get such a dict for every control) */
2207 if ( self->ob_callbackdict == NULL )
2208 if ( (self->ob_callbackdict = PyDict_New()) == NULL )
2209 return -1;
2210 /* And store the Python callback */
2211 sprintf(keybuf, "%x", which);
2212 if (PyDict_SetItemString(self->ob_callbackdict, keybuf, callback) < 0)
2213 return -1;
2214 return 0;
2215}
2216
2217static PyObject *
2218callcallback(self, which, arglist)
2219 ControlObject *self;
2220 OSType which;
2221 PyObject *arglist;
2222{
2223 char keybuf[9];
2224 PyObject *func, *rv;
2225
2226 sprintf(keybuf, "%x", which);
2227 if ( self->ob_callbackdict == NULL ||
2228 (func = PyDict_GetItemString(self->ob_callbackdict, keybuf)) == NULL ) {
Jack Jansena27e9fb2000-03-21 23:03:02 +00002229 PySys_WriteStderr("Control callback %x without callback object\n", which);
Jack Jansenabc411b2000-03-20 16:09:09 +00002230 return NULL;
2231 }
2232 rv = PyEval_CallObject(func, arglist);
2233 if ( rv == NULL )
Jack Jansena27e9fb2000-03-21 23:03:02 +00002234 PySys_WriteStderr("Exception in control callback %x handler\n", which);
Jack Jansenabc411b2000-03-20 16:09:09 +00002235 return rv;
2236}
2237
2238static pascal void
2239mydrawproc(ControlHandle control, SInt16 part)
2240{
2241 ControlObject *ctl_obj;
2242 PyObject *arglist, *rv;
2243
2244 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
2245 arglist = Py_BuildValue("Oh", ctl_obj, part);
2246 rv = callcallback(ctl_obj, kControlUserPaneDrawProcTag, arglist);
2247 Py_XDECREF(arglist);
2248 Py_XDECREF(rv);
2249}
2250
2251static pascal void
2252myidleproc(ControlHandle control)
2253{
2254 ControlObject *ctl_obj;
2255 PyObject *arglist, *rv;
2256
2257 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
2258 arglist = Py_BuildValue("O", ctl_obj);
2259 rv = callcallback(ctl_obj, kControlUserPaneIdleProcTag, arglist);
2260 Py_XDECREF(arglist);
2261 Py_XDECREF(rv);
2262}
2263
Jack Jansena27e9fb2000-03-21 23:03:02 +00002264static pascal ControlPartCode
2265myhittestproc(ControlHandle control, Point where)
2266{
2267 ControlObject *ctl_obj;
2268 PyObject *arglist, *rv;
2269 short c_rv = -1;
2270
2271 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
Jack Jansendeb63732000-03-22 15:35:24 +00002272 arglist = Py_BuildValue("OO&", ctl_obj, PyMac_BuildPoint, where);
Jack Jansena27e9fb2000-03-21 23:03:02 +00002273 rv = callcallback(ctl_obj, kControlUserPaneHitTestProcTag, arglist);
2274 Py_XDECREF(arglist);
2275 /* Ignore errors, nothing we can do about them */
2276 if ( rv )
2277 PyArg_Parse(rv, "h", &c_rv);
2278 Py_XDECREF(rv);
2279 return (ControlPartCode)c_rv;
2280}
2281
2282static pascal ControlPartCode
2283mytrackingproc(ControlHandle control, Point startPt, ControlActionUPP actionProc)
2284{
2285 ControlObject *ctl_obj;
2286 PyObject *arglist, *rv;
2287 short c_rv = -1;
2288
2289 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
2290 /* We cannot pass the actionProc without lots of work */
Jack Jansendeb63732000-03-22 15:35:24 +00002291 arglist = Py_BuildValue("OO&", ctl_obj, PyMac_BuildPoint, startPt);
Jack Jansena27e9fb2000-03-21 23:03:02 +00002292 rv = callcallback(ctl_obj, kControlUserPaneTrackingProcTag, arglist);
2293 Py_XDECREF(arglist);
2294 if ( rv )
2295 PyArg_Parse(rv, "h", &c_rv);
2296 Py_XDECREF(rv);
2297 return (ControlPartCode)c_rv;
2298}
Jack Jansene79dc762000-06-02 21:35:07 +00002299#endif
Jack Jansenabc411b2000-03-20 16:09:09 +00002300
Guido van Rossum17448e21995-01-30 11:53:55 +00002301
2302void initCtl()
2303{
2304 PyObject *m;
2305 PyObject *d;
2306
2307
2308
Jack Jansen848250c1998-05-28 14:20:09 +00002309 mytracker_upp = NewControlActionProc(mytracker);
Jack Jansene79dc762000-06-02 21:35:07 +00002310#ifndef TARGET_API_MAC_CARBON_NOTYET
Jack Jansenabc411b2000-03-20 16:09:09 +00002311 mydrawproc_upp = NewControlUserPaneDrawProc(mydrawproc);
Jack Jansen1b6e8212000-04-05 21:30:57 +00002312 myidleproc_upp = NewControlUserPaneIdleProc(myidleproc);
Jack Jansena27e9fb2000-03-21 23:03:02 +00002313 myhittestproc_upp = NewControlUserPaneHitTestProc(myhittestproc);
2314 mytrackingproc_upp = NewControlUserPaneTrackingProc(mytrackingproc);
Jack Jansene79dc762000-06-02 21:35:07 +00002315#endif
Jack Jansen848250c1998-05-28 14:20:09 +00002316
Guido van Rossum17448e21995-01-30 11:53:55 +00002317
2318 m = Py_InitModule("Ctl", Ctl_methods);
2319 d = PyModule_GetDict(m);
2320 Ctl_Error = PyMac_GetOSErrException();
2321 if (Ctl_Error == NULL ||
2322 PyDict_SetItemString(d, "Error", Ctl_Error) != 0)
2323 Py_FatalError("can't initialize Ctl.Error");
Jack Jansena755e681997-09-20 17:40:22 +00002324 Control_Type.ob_type = &PyType_Type;
2325 Py_INCREF(&Control_Type);
2326 if (PyDict_SetItemString(d, "ControlType", (PyObject *)&Control_Type) != 0)
2327 Py_FatalError("can't initialize ControlType");
Guido van Rossum17448e21995-01-30 11:53:55 +00002328}
2329
2330/* ========================= End module Ctl ========================= */
2331