blob: 37f8c5a08c8d63b285f2327100215ab356646720 [file] [log] [blame]
Guido van Rossum17448e21995-01-30 11:53:55 +00001
2/* =========================== Module Ctl =========================== */
3
4#include "Python.h"
5
6
7
8#define SystemSevenOrLater 1
9
10#include "macglue.h"
11#include <Memory.h>
12#include <Dialogs.h>
13#include <Menus.h>
14#include <Controls.h>
15
16extern PyObject *ResObj_New(Handle);
17extern int ResObj_Convert(PyObject *, Handle *);
Jack Jansen425e9eb1995-12-12 15:02:03 +000018extern PyObject *OptResObj_New(Handle);
19extern int OptResObj_Convert(PyObject *, Handle *);
Guido van Rossum17448e21995-01-30 11:53:55 +000020
21extern PyObject *WinObj_New(WindowPtr);
22extern int WinObj_Convert(PyObject *, WindowPtr *);
Jack Jansen425e9eb1995-12-12 15:02:03 +000023extern PyTypeObject Window_Type;
24#define WinObj_Check(x) ((x)->ob_type == &Window_Type)
Guido van Rossum17448e21995-01-30 11:53:55 +000025
26extern PyObject *DlgObj_New(DialogPtr);
27extern int DlgObj_Convert(PyObject *, DialogPtr *);
28extern PyTypeObject Dialog_Type;
29#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
30
31extern PyObject *MenuObj_New(MenuHandle);
32extern int MenuObj_Convert(PyObject *, MenuHandle *);
33
34extern PyObject *CtlObj_New(ControlHandle);
35extern int CtlObj_Convert(PyObject *, ControlHandle *);
36
Jack Jansen425e9eb1995-12-12 15:02:03 +000037extern PyObject *GrafObj_New(GrafPtr);
38extern int GrafObj_Convert(PyObject *, GrafPtr *);
39
40extern PyObject *BMObj_New(BitMapPtr);
41extern int BMObj_Convert(PyObject *, BitMapPtr *);
42
Guido van Rossum17448e21995-01-30 11:53:55 +000043extern PyObject *WinObj_WhichWindow(WindowPtr);
44
45#include <Controls.h>
46
Jack Jansene0581891999-02-07 14:02:03 +000047#define as_Control(h) ((ControlHandle)h)
Jack Jansena1a0fef1999-12-23 14:32:06 +000048#define as_Resource(ctl) ((Handle)ctl)
Jack Jansene79dc762000-06-02 21:35:07 +000049#ifdef TARGET_API_MAC_CARBON
50#define GetControlRect(ctl, rectp) GetControlBounds(ctl, rectp)
51#else
Jack Jansen1a7d5b12000-03-21 16:25:23 +000052#define GetControlRect(ctl, rectp) (*(rectp) = ((*(ctl))->contrlRect))
Jack Jansene79dc762000-06-02 21:35:07 +000053#endif
Guido van Rossum17448e21995-01-30 11:53:55 +000054#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
55
56extern PyObject *CtlObj_WhichControl(ControlHandle); /* Forward */
Jack Jansen21f96871998-02-20 16:02:09 +000057extern PyObject *QdRGB_New(RGBColorPtr);
58extern QdRGB_Convert(PyObject *, RGBColorPtr);
Guido van Rossum17448e21995-01-30 11:53:55 +000059
60#ifdef THINK_C
61#define ControlActionUPP ProcPtr
62#endif
63
Jack Jansen21f96871998-02-20 16:02:09 +000064/*
65** Parse/generate ControlFontStyleRec records
66*/
67#if 0 /* Not needed */
68PyObject *ControlFontStyle_New(itself)
69 ControlFontStyleRec *itself;
70{
71
72 return Py_BuildValue("hhhhhhO&O&", itself->flags, itself->font,
73 itself->size, itself->style, itself->mode, itself->just,
74 QdRGB_New, &itself->foreColor, QdRGB_New, &itself->backColor);
75}
76#endif
77
78ControlFontStyle_Convert(v, itself)
79 PyObject *v;
80 ControlFontStyleRec *itself;
81{
82 return PyArg_ParseTuple(v, "hhhhhhO&O&", &itself->flags,
Jack Jansen24c35311999-12-09 22:49:51 +000083 &itself->font, &itself->size, &itself->style, &itself->mode,
84 &itself->just, QdRGB_Convert, &itself->foreColor,
Jack Jansen21f96871998-02-20 16:02:09 +000085 QdRGB_Convert, &itself->backColor);
86}
87
Jack Jansen24c35311999-12-09 22:49:51 +000088/* TrackControl and HandleControlClick callback support */
Jack Jansen848250c1998-05-28 14:20:09 +000089static PyObject *tracker;
90static ControlActionUPP mytracker_upp;
Jack Jansene79dc762000-06-02 21:35:07 +000091#ifndef TARGET_API_MAC_CARBON_NOTYET
Jack Jansenabc411b2000-03-20 16:09:09 +000092static ControlUserPaneDrawUPP mydrawproc_upp;
93static ControlUserPaneIdleUPP myidleproc_upp;
Jack Jansena27e9fb2000-03-21 23:03:02 +000094static ControlUserPaneHitTestUPP myhittestproc_upp;
95static ControlUserPaneTrackingUPP mytrackingproc_upp;
Jack Jansene79dc762000-06-02 21:35:07 +000096#endif
Jack Jansen848250c1998-05-28 14:20:09 +000097
98extern int settrackfunc(PyObject *); /* forward */
99extern void clrtrackfunc(void); /* forward */
100
Guido van Rossum17448e21995-01-30 11:53:55 +0000101static PyObject *Ctl_Error;
102
103/* ---------------------- Object type Control ----------------------- */
104
105PyTypeObject Control_Type;
106
107#define CtlObj_Check(x) ((x)->ob_type == &Control_Type)
108
109typedef struct ControlObject {
110 PyObject_HEAD
111 ControlHandle ob_itself;
Jack Jansenabc411b2000-03-20 16:09:09 +0000112 PyObject *ob_callbackdict;
Guido van Rossum17448e21995-01-30 11:53:55 +0000113} ControlObject;
114
115PyObject *CtlObj_New(itself)
Jack Jansenae8a68f1995-06-06 12:55:40 +0000116 ControlHandle itself;
Guido van Rossum17448e21995-01-30 11:53:55 +0000117{
118 ControlObject *it;
119 if (itself == NULL) return PyMac_Error(resNotFound);
120 it = PyObject_NEW(ControlObject, &Control_Type);
121 if (it == NULL) return NULL;
122 it->ob_itself = itself;
Jack Jansen85ae4a81997-04-08 15:26:03 +0000123 SetControlReference(itself, (long)it);
Jack Jansenabc411b2000-03-20 16:09:09 +0000124 it->ob_callbackdict = NULL;
Guido van Rossum17448e21995-01-30 11:53:55 +0000125 return (PyObject *)it;
126}
127CtlObj_Convert(v, p_itself)
128 PyObject *v;
129 ControlHandle *p_itself;
130{
131 if (!CtlObj_Check(v))
132 {
133 PyErr_SetString(PyExc_TypeError, "Control required");
134 return 0;
135 }
136 *p_itself = ((ControlObject *)v)->ob_itself;
137 return 1;
138}
139
140static void CtlObj_dealloc(self)
141 ControlObject *self;
142{
Jack Jansenabc411b2000-03-20 16:09:09 +0000143 Py_XDECREF(self->ob_callbackdict);
Jack Jansen24c35311999-12-09 22:49:51 +0000144 if (self->ob_itself)SetControlReference(self->ob_itself, (long)0); /* Make it forget about us */
Guido van Rossum17448e21995-01-30 11:53:55 +0000145 PyMem_DEL(self);
146}
147
Jack Jansen21f96871998-02-20 16:02:09 +0000148static PyObject *CtlObj_HiliteControl(_self, _args)
149 ControlObject *_self;
150 PyObject *_args;
151{
152 PyObject *_res = NULL;
153 ControlPartCode hiliteState;
154 if (!PyArg_ParseTuple(_args, "h",
155 &hiliteState))
156 return NULL;
157 HiliteControl(_self->ob_itself,
158 hiliteState);
159 Py_INCREF(Py_None);
160 _res = Py_None;
161 return _res;
162}
163
Jack Jansen7d0bc831995-06-09 20:56:31 +0000164static PyObject *CtlObj_ShowControl(_self, _args)
165 ControlObject *_self;
166 PyObject *_args;
167{
168 PyObject *_res = NULL;
169 if (!PyArg_ParseTuple(_args, ""))
170 return NULL;
171 ShowControl(_self->ob_itself);
172 Py_INCREF(Py_None);
173 _res = Py_None;
174 return _res;
175}
176
177static PyObject *CtlObj_HideControl(_self, _args)
178 ControlObject *_self;
179 PyObject *_args;
180{
181 PyObject *_res = NULL;
182 if (!PyArg_ParseTuple(_args, ""))
183 return NULL;
184 HideControl(_self->ob_itself);
185 Py_INCREF(Py_None);
186 _res = Py_None;
187 return _res;
188}
189
Jack Jansen21f96871998-02-20 16:02:09 +0000190static PyObject *CtlObj_IsControlActive(_self, _args)
191 ControlObject *_self;
192 PyObject *_args;
193{
194 PyObject *_res = NULL;
195 Boolean _rv;
196 if (!PyArg_ParseTuple(_args, ""))
197 return NULL;
198 _rv = IsControlActive(_self->ob_itself);
199 _res = Py_BuildValue("b",
200 _rv);
201 return _res;
202}
203
204static PyObject *CtlObj_IsControlVisible(_self, _args)
205 ControlObject *_self;
206 PyObject *_args;
207{
208 PyObject *_res = NULL;
209 Boolean _rv;
210 if (!PyArg_ParseTuple(_args, ""))
211 return NULL;
212 _rv = IsControlVisible(_self->ob_itself);
213 _res = Py_BuildValue("b",
214 _rv);
215 return _res;
216}
217
218static PyObject *CtlObj_ActivateControl(_self, _args)
219 ControlObject *_self;
220 PyObject *_args;
221{
222 PyObject *_res = NULL;
223 OSErr _err;
224 if (!PyArg_ParseTuple(_args, ""))
225 return NULL;
226 _err = ActivateControl(_self->ob_itself);
227 if (_err != noErr) return PyMac_Error(_err);
228 Py_INCREF(Py_None);
229 _res = Py_None;
230 return _res;
231}
232
233static PyObject *CtlObj_DeactivateControl(_self, _args)
234 ControlObject *_self;
235 PyObject *_args;
236{
237 PyObject *_res = NULL;
238 OSErr _err;
239 if (!PyArg_ParseTuple(_args, ""))
240 return NULL;
241 _err = DeactivateControl(_self->ob_itself);
242 if (_err != noErr) return PyMac_Error(_err);
243 Py_INCREF(Py_None);
244 _res = Py_None;
245 return _res;
246}
247
248static PyObject *CtlObj_SetControlVisibility(_self, _args)
249 ControlObject *_self;
250 PyObject *_args;
251{
252 PyObject *_res = NULL;
253 OSErr _err;
254 Boolean inIsVisible;
255 Boolean inDoDraw;
256 if (!PyArg_ParseTuple(_args, "bb",
257 &inIsVisible,
258 &inDoDraw))
259 return NULL;
260 _err = SetControlVisibility(_self->ob_itself,
261 inIsVisible,
262 inDoDraw);
263 if (_err != noErr) return PyMac_Error(_err);
264 Py_INCREF(Py_None);
265 _res = Py_None;
266 return _res;
267}
268
Jack Jansen7d0bc831995-06-09 20:56:31 +0000269static PyObject *CtlObj_Draw1Control(_self, _args)
270 ControlObject *_self;
271 PyObject *_args;
272{
273 PyObject *_res = NULL;
274 if (!PyArg_ParseTuple(_args, ""))
275 return NULL;
276 Draw1Control(_self->ob_itself);
277 Py_INCREF(Py_None);
278 _res = Py_None;
279 return _res;
280}
281
Jack Jansen21f96871998-02-20 16:02:09 +0000282static PyObject *CtlObj_GetBestControlRect(_self, _args)
Jack Jansen7d0bc831995-06-09 20:56:31 +0000283 ControlObject *_self;
284 PyObject *_args;
285{
286 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000287 OSErr _err;
288 Rect outRect;
289 SInt16 outBaseLineOffset;
290 if (!PyArg_ParseTuple(_args, ""))
Jack Jansen7d0bc831995-06-09 20:56:31 +0000291 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000292 _err = GetBestControlRect(_self->ob_itself,
293 &outRect,
294 &outBaseLineOffset);
295 if (_err != noErr) return PyMac_Error(_err);
296 _res = Py_BuildValue("O&h",
297 PyMac_BuildRect, &outRect,
298 outBaseLineOffset);
299 return _res;
300}
301
302static PyObject *CtlObj_SetControlFontStyle(_self, _args)
303 ControlObject *_self;
304 PyObject *_args;
305{
306 PyObject *_res = NULL;
307 OSErr _err;
308 ControlFontStyleRec inStyle;
309 if (!PyArg_ParseTuple(_args, "O&",
310 ControlFontStyle_Convert, &inStyle))
311 return NULL;
312 _err = SetControlFontStyle(_self->ob_itself,
313 &inStyle);
314 if (_err != noErr) return PyMac_Error(_err);
315 Py_INCREF(Py_None);
316 _res = Py_None;
317 return _res;
318}
319
320static PyObject *CtlObj_DrawControlInCurrentPort(_self, _args)
321 ControlObject *_self;
322 PyObject *_args;
323{
324 PyObject *_res = NULL;
325 if (!PyArg_ParseTuple(_args, ""))
326 return NULL;
327 DrawControlInCurrentPort(_self->ob_itself);
328 Py_INCREF(Py_None);
329 _res = Py_None;
330 return _res;
331}
332
333static PyObject *CtlObj_SetUpControlBackground(_self, _args)
334 ControlObject *_self;
335 PyObject *_args;
336{
337 PyObject *_res = NULL;
338 OSErr _err;
339 SInt16 inDepth;
340 Boolean inIsColorDevice;
341 if (!PyArg_ParseTuple(_args, "hb",
342 &inDepth,
343 &inIsColorDevice))
344 return NULL;
345 _err = SetUpControlBackground(_self->ob_itself,
346 inDepth,
347 inIsColorDevice);
348 if (_err != noErr) return PyMac_Error(_err);
Jack Jansen7d0bc831995-06-09 20:56:31 +0000349 Py_INCREF(Py_None);
350 _res = Py_None;
351 return _res;
352}
353
Jack Jansena05ac601999-12-12 21:41:51 +0000354static PyObject *CtlObj_SetUpControlTextColor(_self, _args)
355 ControlObject *_self;
356 PyObject *_args;
357{
358 PyObject *_res = NULL;
359 OSErr _err;
360 SInt16 inDepth;
361 Boolean inIsColorDevice;
362 if (!PyArg_ParseTuple(_args, "hb",
363 &inDepth,
364 &inIsColorDevice))
365 return NULL;
366 _err = SetUpControlTextColor(_self->ob_itself,
367 inDepth,
368 inIsColorDevice);
369 if (_err != noErr) return PyMac_Error(_err);
370 Py_INCREF(Py_None);
371 _res = Py_None;
372 return _res;
373}
374
Jack Jansen7d0bc831995-06-09 20:56:31 +0000375static PyObject *CtlObj_DragControl(_self, _args)
376 ControlObject *_self;
377 PyObject *_args;
378{
379 PyObject *_res = NULL;
Jack Jansen754d4a41995-11-14 10:41:55 +0000380 Point startPoint;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000381 Rect limitRect;
382 Rect slopRect;
383 DragConstraint axis;
384 if (!PyArg_ParseTuple(_args, "O&O&O&h",
Jack Jansen754d4a41995-11-14 10:41:55 +0000385 PyMac_GetPoint, &startPoint,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000386 PyMac_GetRect, &limitRect,
387 PyMac_GetRect, &slopRect,
388 &axis))
389 return NULL;
390 DragControl(_self->ob_itself,
Jack Jansen754d4a41995-11-14 10:41:55 +0000391 startPoint,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000392 &limitRect,
393 &slopRect,
394 axis);
395 Py_INCREF(Py_None);
396 _res = Py_None;
397 return _res;
398}
399
400static PyObject *CtlObj_TestControl(_self, _args)
401 ControlObject *_self;
402 PyObject *_args;
403{
404 PyObject *_res = NULL;
405 ControlPartCode _rv;
Jack Jansen21f96871998-02-20 16:02:09 +0000406 Point testPoint;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000407 if (!PyArg_ParseTuple(_args, "O&",
Jack Jansen21f96871998-02-20 16:02:09 +0000408 PyMac_GetPoint, &testPoint))
Jack Jansen7d0bc831995-06-09 20:56:31 +0000409 return NULL;
410 _rv = TestControl(_self->ob_itself,
Jack Jansen21f96871998-02-20 16:02:09 +0000411 testPoint);
412 _res = Py_BuildValue("h",
413 _rv);
414 return _res;
415}
416
417static PyObject *CtlObj_HandleControlKey(_self, _args)
418 ControlObject *_self;
419 PyObject *_args;
420{
421 PyObject *_res = NULL;
422 SInt16 _rv;
423 SInt16 inKeyCode;
424 SInt16 inCharCode;
425 SInt16 inModifiers;
426 if (!PyArg_ParseTuple(_args, "hhh",
427 &inKeyCode,
428 &inCharCode,
429 &inModifiers))
430 return NULL;
431 _rv = HandleControlKey(_self->ob_itself,
432 inKeyCode,
433 inCharCode,
434 inModifiers);
Jack Jansen7d0bc831995-06-09 20:56:31 +0000435 _res = Py_BuildValue("h",
436 _rv);
437 return _res;
438}
439
440static PyObject *CtlObj_MoveControl(_self, _args)
441 ControlObject *_self;
442 PyObject *_args;
443{
444 PyObject *_res = NULL;
445 SInt16 h;
446 SInt16 v;
447 if (!PyArg_ParseTuple(_args, "hh",
448 &h,
449 &v))
450 return NULL;
451 MoveControl(_self->ob_itself,
452 h,
453 v);
454 Py_INCREF(Py_None);
455 _res = Py_None;
456 return _res;
457}
458
459static PyObject *CtlObj_SizeControl(_self, _args)
460 ControlObject *_self;
461 PyObject *_args;
462{
463 PyObject *_res = NULL;
464 SInt16 w;
465 SInt16 h;
466 if (!PyArg_ParseTuple(_args, "hh",
467 &w,
468 &h))
469 return NULL;
470 SizeControl(_self->ob_itself,
471 w,
472 h);
473 Py_INCREF(Py_None);
474 _res = Py_None;
475 return _res;
476}
477
Jack Jansenae8a68f1995-06-06 12:55:40 +0000478static PyObject *CtlObj_SetControlTitle(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000479 ControlObject *_self;
480 PyObject *_args;
481{
482 PyObject *_res = NULL;
483 Str255 title;
484 if (!PyArg_ParseTuple(_args, "O&",
485 PyMac_GetStr255, title))
486 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000487 SetControlTitle(_self->ob_itself,
488 title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000489 Py_INCREF(Py_None);
490 _res = Py_None;
491 return _res;
492}
493
Jack Jansenae8a68f1995-06-06 12:55:40 +0000494static PyObject *CtlObj_GetControlTitle(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000495 ControlObject *_self;
496 PyObject *_args;
497{
498 PyObject *_res = NULL;
499 Str255 title;
Jack Jansen41009001999-03-07 20:05:20 +0000500 if (!PyArg_ParseTuple(_args, ""))
Guido van Rossum17448e21995-01-30 11:53:55 +0000501 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000502 GetControlTitle(_self->ob_itself,
503 title);
Jack Jansen41009001999-03-07 20:05:20 +0000504 _res = Py_BuildValue("O&",
505 PyMac_BuildStr255, title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000506 return _res;
507}
508
Jack Jansenae8a68f1995-06-06 12:55:40 +0000509static PyObject *CtlObj_GetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000510 ControlObject *_self;
511 PyObject *_args;
512{
513 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000514 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000515 if (!PyArg_ParseTuple(_args, ""))
516 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000517 _rv = GetControlValue(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000518 _res = Py_BuildValue("h",
519 _rv);
520 return _res;
521}
522
Jack Jansen7d0bc831995-06-09 20:56:31 +0000523static PyObject *CtlObj_SetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000524 ControlObject *_self;
525 PyObject *_args;
526{
527 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000528 SInt16 newValue;
Guido van Rossum17448e21995-01-30 11:53:55 +0000529 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000530 &newValue))
Guido van Rossum17448e21995-01-30 11:53:55 +0000531 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000532 SetControlValue(_self->ob_itself,
533 newValue);
Guido van Rossum17448e21995-01-30 11:53:55 +0000534 Py_INCREF(Py_None);
535 _res = Py_None;
536 return _res;
537}
538
Jack Jansenae8a68f1995-06-06 12:55:40 +0000539static PyObject *CtlObj_GetControlMinimum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000540 ControlObject *_self;
541 PyObject *_args;
542{
543 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000544 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000545 if (!PyArg_ParseTuple(_args, ""))
546 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000547 _rv = GetControlMinimum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000548 _res = Py_BuildValue("h",
549 _rv);
550 return _res;
551}
552
Jack Jansen7d0bc831995-06-09 20:56:31 +0000553static PyObject *CtlObj_SetControlMinimum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000554 ControlObject *_self;
555 PyObject *_args;
556{
557 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000558 SInt16 newMinimum;
Guido van Rossum17448e21995-01-30 11:53:55 +0000559 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000560 &newMinimum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000561 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000562 SetControlMinimum(_self->ob_itself,
563 newMinimum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000564 Py_INCREF(Py_None);
565 _res = Py_None;
566 return _res;
567}
568
Jack Jansenae8a68f1995-06-06 12:55:40 +0000569static PyObject *CtlObj_GetControlMaximum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000570 ControlObject *_self;
571 PyObject *_args;
572{
573 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000574 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000575 if (!PyArg_ParseTuple(_args, ""))
576 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000577 _rv = GetControlMaximum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000578 _res = Py_BuildValue("h",
579 _rv);
580 return _res;
581}
582
Jack Jansen7d0bc831995-06-09 20:56:31 +0000583static PyObject *CtlObj_SetControlMaximum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000584 ControlObject *_self;
585 PyObject *_args;
586{
587 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000588 SInt16 newMaximum;
589 if (!PyArg_ParseTuple(_args, "h",
590 &newMaximum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000591 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000592 SetControlMaximum(_self->ob_itself,
593 newMaximum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000594 Py_INCREF(Py_None);
595 _res = Py_None;
596 return _res;
597}
598
Jack Jansena05ac601999-12-12 21:41:51 +0000599static PyObject *CtlObj_GetControlViewSize(_self, _args)
600 ControlObject *_self;
601 PyObject *_args;
602{
603 PyObject *_res = NULL;
604 SInt32 _rv;
605 if (!PyArg_ParseTuple(_args, ""))
606 return NULL;
607 _rv = GetControlViewSize(_self->ob_itself);
608 _res = Py_BuildValue("l",
609 _rv);
610 return _res;
611}
612
613static PyObject *CtlObj_SetControlViewSize(_self, _args)
614 ControlObject *_self;
615 PyObject *_args;
616{
617 PyObject *_res = NULL;
618 SInt32 newViewSize;
619 if (!PyArg_ParseTuple(_args, "l",
620 &newViewSize))
621 return NULL;
622 SetControlViewSize(_self->ob_itself,
623 newViewSize);
624 Py_INCREF(Py_None);
625 _res = Py_None;
626 return _res;
627}
628
629static PyObject *CtlObj_GetControl32BitValue(_self, _args)
630 ControlObject *_self;
631 PyObject *_args;
632{
633 PyObject *_res = NULL;
634 SInt32 _rv;
635 if (!PyArg_ParseTuple(_args, ""))
636 return NULL;
637 _rv = GetControl32BitValue(_self->ob_itself);
638 _res = Py_BuildValue("l",
639 _rv);
640 return _res;
641}
642
643static PyObject *CtlObj_SetControl32BitValue(_self, _args)
644 ControlObject *_self;
645 PyObject *_args;
646{
647 PyObject *_res = NULL;
648 SInt32 newValue;
649 if (!PyArg_ParseTuple(_args, "l",
650 &newValue))
651 return NULL;
652 SetControl32BitValue(_self->ob_itself,
653 newValue);
654 Py_INCREF(Py_None);
655 _res = Py_None;
656 return _res;
657}
658
659static PyObject *CtlObj_GetControl32BitMaximum(_self, _args)
660 ControlObject *_self;
661 PyObject *_args;
662{
663 PyObject *_res = NULL;
664 SInt32 _rv;
665 if (!PyArg_ParseTuple(_args, ""))
666 return NULL;
667 _rv = GetControl32BitMaximum(_self->ob_itself);
668 _res = Py_BuildValue("l",
669 _rv);
670 return _res;
671}
672
673static PyObject *CtlObj_SetControl32BitMaximum(_self, _args)
674 ControlObject *_self;
675 PyObject *_args;
676{
677 PyObject *_res = NULL;
678 SInt32 newMaximum;
679 if (!PyArg_ParseTuple(_args, "l",
680 &newMaximum))
681 return NULL;
682 SetControl32BitMaximum(_self->ob_itself,
683 newMaximum);
684 Py_INCREF(Py_None);
685 _res = Py_None;
686 return _res;
687}
688
689static PyObject *CtlObj_GetControl32BitMinimum(_self, _args)
690 ControlObject *_self;
691 PyObject *_args;
692{
693 PyObject *_res = NULL;
694 SInt32 _rv;
695 if (!PyArg_ParseTuple(_args, ""))
696 return NULL;
697 _rv = GetControl32BitMinimum(_self->ob_itself);
698 _res = Py_BuildValue("l",
699 _rv);
700 return _res;
701}
702
703static PyObject *CtlObj_SetControl32BitMinimum(_self, _args)
704 ControlObject *_self;
705 PyObject *_args;
706{
707 PyObject *_res = NULL;
708 SInt32 newMinimum;
709 if (!PyArg_ParseTuple(_args, "l",
710 &newMinimum))
711 return NULL;
712 SetControl32BitMinimum(_self->ob_itself,
713 newMinimum);
714 Py_INCREF(Py_None);
715 _res = Py_None;
716 return _res;
717}
718
719static PyObject *CtlObj_IsValidControlHandle(_self, _args)
720 ControlObject *_self;
721 PyObject *_args;
722{
723 PyObject *_res = NULL;
724 Boolean _rv;
725 if (!PyArg_ParseTuple(_args, ""))
726 return NULL;
727 _rv = IsValidControlHandle(_self->ob_itself);
728 _res = Py_BuildValue("b",
729 _rv);
730 return _res;
731}
732
733static PyObject *CtlObj_RemoveControlProperty(_self, _args)
734 ControlObject *_self;
735 PyObject *_args;
736{
737 PyObject *_res = NULL;
Jack Jansene79dc762000-06-02 21:35:07 +0000738 OSStatus _err;
Jack Jansena05ac601999-12-12 21:41:51 +0000739 OSType propertyCreator;
740 OSType propertyTag;
741 if (!PyArg_ParseTuple(_args, "O&O&",
742 PyMac_GetOSType, &propertyCreator,
743 PyMac_GetOSType, &propertyTag))
744 return NULL;
Jack Jansene79dc762000-06-02 21:35:07 +0000745 _err = RemoveControlProperty(_self->ob_itself,
746 propertyCreator,
747 propertyTag);
748 if (_err != noErr) return PyMac_Error(_err);
749 Py_INCREF(Py_None);
750 _res = Py_None;
Jack Jansena05ac601999-12-12 21:41:51 +0000751 return _res;
752}
753
754static PyObject *CtlObj_GetControlRegion(_self, _args)
755 ControlObject *_self;
756 PyObject *_args;
757{
758 PyObject *_res = NULL;
Jack Jansene79dc762000-06-02 21:35:07 +0000759 OSStatus _err;
Jack Jansena05ac601999-12-12 21:41:51 +0000760 ControlPartCode inPart;
761 RgnHandle outRegion;
762 if (!PyArg_ParseTuple(_args, "hO&",
763 &inPart,
764 ResObj_Convert, &outRegion))
765 return NULL;
Jack Jansene79dc762000-06-02 21:35:07 +0000766 _err = GetControlRegion(_self->ob_itself,
767 inPart,
768 outRegion);
769 if (_err != noErr) return PyMac_Error(_err);
770 Py_INCREF(Py_None);
771 _res = Py_None;
Jack Jansena05ac601999-12-12 21:41:51 +0000772 return _res;
773}
774
Jack Jansen7d0bc831995-06-09 20:56:31 +0000775static PyObject *CtlObj_GetControlVariant(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000776 ControlObject *_self;
777 PyObject *_args;
778{
779 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000780 ControlVariant _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000781 if (!PyArg_ParseTuple(_args, ""))
782 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000783 _rv = GetControlVariant(_self->ob_itself);
784 _res = Py_BuildValue("h",
Guido van Rossum17448e21995-01-30 11:53:55 +0000785 _rv);
786 return _res;
787}
788
Jack Jansen7d0bc831995-06-09 20:56:31 +0000789static PyObject *CtlObj_SetControlReference(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000790 ControlObject *_self;
791 PyObject *_args;
792{
793 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000794 SInt32 data;
795 if (!PyArg_ParseTuple(_args, "l",
796 &data))
Guido van Rossum17448e21995-01-30 11:53:55 +0000797 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000798 SetControlReference(_self->ob_itself,
799 data);
Guido van Rossum17448e21995-01-30 11:53:55 +0000800 Py_INCREF(Py_None);
801 _res = Py_None;
802 return _res;
803}
804
Jack Jansen7d0bc831995-06-09 20:56:31 +0000805static PyObject *CtlObj_GetControlReference(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000806 ControlObject *_self;
807 PyObject *_args;
808{
809 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000810 SInt32 _rv;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000811 if (!PyArg_ParseTuple(_args, ""))
812 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000813 _rv = GetControlReference(_self->ob_itself);
814 _res = Py_BuildValue("l",
Guido van Rossum17448e21995-01-30 11:53:55 +0000815 _rv);
816 return _res;
817}
818
Jack Jansene79dc762000-06-02 21:35:07 +0000819#ifndef TARGET_API_MAC_CARBON
820
Jack Jansenc7fefed1997-08-15 14:32:18 +0000821static PyObject *CtlObj_GetAuxiliaryControlRecord(_self, _args)
822 ControlObject *_self;
823 PyObject *_args;
824{
825 PyObject *_res = NULL;
826 Boolean _rv;
827 AuxCtlHandle acHndl;
828 if (!PyArg_ParseTuple(_args, ""))
829 return NULL;
830 _rv = GetAuxiliaryControlRecord(_self->ob_itself,
831 &acHndl);
832 _res = Py_BuildValue("bO&",
833 _rv,
834 ResObj_New, acHndl);
835 return _res;
836}
Jack Jansene79dc762000-06-02 21:35:07 +0000837#endif
838
839#ifndef TARGET_API_MAC_CARBON
Jack Jansenc7fefed1997-08-15 14:32:18 +0000840
841static PyObject *CtlObj_SetControlColor(_self, _args)
842 ControlObject *_self;
843 PyObject *_args;
844{
845 PyObject *_res = NULL;
846 CCTabHandle newColorTable;
847 if (!PyArg_ParseTuple(_args, "O&",
848 ResObj_Convert, &newColorTable))
849 return NULL;
850 SetControlColor(_self->ob_itself,
851 newColorTable);
852 Py_INCREF(Py_None);
853 _res = Py_None;
854 return _res;
855}
Jack Jansene79dc762000-06-02 21:35:07 +0000856#endif
857
858static PyObject *CtlObj_GetBevelButtonMenuValue(_self, _args)
859 ControlObject *_self;
860 PyObject *_args;
861{
862 PyObject *_res = NULL;
863 OSErr _err;
864 SInt16 outValue;
865 if (!PyArg_ParseTuple(_args, ""))
866 return NULL;
867 _err = GetBevelButtonMenuValue(_self->ob_itself,
868 &outValue);
869 if (_err != noErr) return PyMac_Error(_err);
870 _res = Py_BuildValue("h",
871 outValue);
872 return _res;
873}
874
875static PyObject *CtlObj_SetBevelButtonMenuValue(_self, _args)
876 ControlObject *_self;
877 PyObject *_args;
878{
879 PyObject *_res = NULL;
880 OSErr _err;
881 SInt16 inValue;
882 if (!PyArg_ParseTuple(_args, "h",
883 &inValue))
884 return NULL;
885 _err = SetBevelButtonMenuValue(_self->ob_itself,
886 inValue);
887 if (_err != noErr) return PyMac_Error(_err);
888 Py_INCREF(Py_None);
889 _res = Py_None;
890 return _res;
891}
892
893static PyObject *CtlObj_GetBevelButtonMenuHandle(_self, _args)
894 ControlObject *_self;
895 PyObject *_args;
896{
897 PyObject *_res = NULL;
898 OSErr _err;
899 MenuHandle outHandle;
900 if (!PyArg_ParseTuple(_args, ""))
901 return NULL;
902 _err = GetBevelButtonMenuHandle(_self->ob_itself,
903 &outHandle);
904 if (_err != noErr) return PyMac_Error(_err);
905 _res = Py_BuildValue("O&",
906 MenuObj_New, outHandle);
907 return _res;
908}
909
910static PyObject *CtlObj_SetBevelButtonTransform(_self, _args)
911 ControlObject *_self;
912 PyObject *_args;
913{
914 PyObject *_res = NULL;
915 OSErr _err;
916 IconTransformType transform;
917 if (!PyArg_ParseTuple(_args, "h",
918 &transform))
919 return NULL;
920 _err = SetBevelButtonTransform(_self->ob_itself,
921 transform);
922 if (_err != noErr) return PyMac_Error(_err);
923 Py_INCREF(Py_None);
924 _res = Py_None;
925 return _res;
926}
927
928static PyObject *CtlObj_SetImageWellTransform(_self, _args)
929 ControlObject *_self;
930 PyObject *_args;
931{
932 PyObject *_res = NULL;
933 OSErr _err;
934 IconTransformType inTransform;
935 if (!PyArg_ParseTuple(_args, "h",
936 &inTransform))
937 return NULL;
938 _err = SetImageWellTransform(_self->ob_itself,
939 inTransform);
940 if (_err != noErr) return PyMac_Error(_err);
941 Py_INCREF(Py_None);
942 _res = Py_None;
943 return _res;
944}
945
946static PyObject *CtlObj_GetTabContentRect(_self, _args)
947 ControlObject *_self;
948 PyObject *_args;
949{
950 PyObject *_res = NULL;
951 OSErr _err;
952 Rect outContentRect;
953 if (!PyArg_ParseTuple(_args, ""))
954 return NULL;
955 _err = GetTabContentRect(_self->ob_itself,
956 &outContentRect);
957 if (_err != noErr) return PyMac_Error(_err);
958 _res = Py_BuildValue("O&",
959 PyMac_BuildRect, &outContentRect);
960 return _res;
961}
962
963static PyObject *CtlObj_SetTabEnabled(_self, _args)
964 ControlObject *_self;
965 PyObject *_args;
966{
967 PyObject *_res = NULL;
968 OSErr _err;
969 SInt16 inTabToHilite;
970 Boolean inEnabled;
971 if (!PyArg_ParseTuple(_args, "hb",
972 &inTabToHilite,
973 &inEnabled))
974 return NULL;
975 _err = SetTabEnabled(_self->ob_itself,
976 inTabToHilite,
977 inEnabled);
978 if (_err != noErr) return PyMac_Error(_err);
979 Py_INCREF(Py_None);
980 _res = Py_None;
981 return _res;
982}
983
984static PyObject *CtlObj_SetDisclosureTriangleLastValue(_self, _args)
985 ControlObject *_self;
986 PyObject *_args;
987{
988 PyObject *_res = NULL;
989 OSErr _err;
990 SInt16 inValue;
991 if (!PyArg_ParseTuple(_args, "h",
992 &inValue))
993 return NULL;
994 _err = SetDisclosureTriangleLastValue(_self->ob_itself,
995 inValue);
996 if (_err != noErr) return PyMac_Error(_err);
997 Py_INCREF(Py_None);
998 _res = Py_None;
999 return _res;
1000}
Jack Jansenc7fefed1997-08-15 14:32:18 +00001001
Jack Jansen21f96871998-02-20 16:02:09 +00001002static PyObject *CtlObj_SendControlMessage(_self, _args)
1003 ControlObject *_self;
1004 PyObject *_args;
1005{
1006 PyObject *_res = NULL;
1007 SInt32 _rv;
1008 SInt16 inMessage;
1009 SInt32 inParam;
1010 if (!PyArg_ParseTuple(_args, "hl",
1011 &inMessage,
1012 &inParam))
1013 return NULL;
1014 _rv = SendControlMessage(_self->ob_itself,
1015 inMessage,
1016 inParam);
1017 _res = Py_BuildValue("l",
1018 _rv);
1019 return _res;
1020}
1021
1022static PyObject *CtlObj_EmbedControl(_self, _args)
1023 ControlObject *_self;
1024 PyObject *_args;
1025{
1026 PyObject *_res = NULL;
1027 OSErr _err;
1028 ControlHandle inContainer;
1029 if (!PyArg_ParseTuple(_args, "O&",
1030 CtlObj_Convert, &inContainer))
1031 return NULL;
1032 _err = EmbedControl(_self->ob_itself,
1033 inContainer);
1034 if (_err != noErr) return PyMac_Error(_err);
1035 Py_INCREF(Py_None);
1036 _res = Py_None;
1037 return _res;
1038}
1039
1040static PyObject *CtlObj_AutoEmbedControl(_self, _args)
1041 ControlObject *_self;
1042 PyObject *_args;
1043{
1044 PyObject *_res = NULL;
1045 OSErr _err;
1046 WindowPtr inWindow;
1047 if (!PyArg_ParseTuple(_args, "O&",
1048 WinObj_Convert, &inWindow))
1049 return NULL;
1050 _err = AutoEmbedControl(_self->ob_itself,
1051 inWindow);
1052 if (_err != noErr) return PyMac_Error(_err);
1053 Py_INCREF(Py_None);
1054 _res = Py_None;
1055 return _res;
1056}
1057
1058static PyObject *CtlObj_GetSuperControl(_self, _args)
1059 ControlObject *_self;
1060 PyObject *_args;
1061{
1062 PyObject *_res = NULL;
1063 OSErr _err;
1064 ControlHandle outParent;
1065 if (!PyArg_ParseTuple(_args, ""))
1066 return NULL;
1067 _err = GetSuperControl(_self->ob_itself,
1068 &outParent);
1069 if (_err != noErr) return PyMac_Error(_err);
1070 _res = Py_BuildValue("O&",
1071 CtlObj_WhichControl, outParent);
1072 return _res;
1073}
1074
1075static PyObject *CtlObj_CountSubControls(_self, _args)
1076 ControlObject *_self;
1077 PyObject *_args;
1078{
1079 PyObject *_res = NULL;
1080 OSErr _err;
Jack Jansen24c35311999-12-09 22:49:51 +00001081 UInt16 outNumChildren;
Jack Jansen21f96871998-02-20 16:02:09 +00001082 if (!PyArg_ParseTuple(_args, ""))
1083 return NULL;
1084 _err = CountSubControls(_self->ob_itself,
1085 &outNumChildren);
1086 if (_err != noErr) return PyMac_Error(_err);
1087 _res = Py_BuildValue("h",
1088 outNumChildren);
1089 return _res;
1090}
1091
1092static PyObject *CtlObj_GetIndexedSubControl(_self, _args)
1093 ControlObject *_self;
1094 PyObject *_args;
1095{
1096 PyObject *_res = NULL;
1097 OSErr _err;
Jack Jansen24c35311999-12-09 22:49:51 +00001098 UInt16 inIndex;
Jack Jansen21f96871998-02-20 16:02:09 +00001099 ControlHandle outSubControl;
1100 if (!PyArg_ParseTuple(_args, "h",
1101 &inIndex))
1102 return NULL;
1103 _err = GetIndexedSubControl(_self->ob_itself,
1104 inIndex,
1105 &outSubControl);
1106 if (_err != noErr) return PyMac_Error(_err);
1107 _res = Py_BuildValue("O&",
1108 CtlObj_WhichControl, outSubControl);
1109 return _res;
1110}
1111
1112static PyObject *CtlObj_SetControlSupervisor(_self, _args)
1113 ControlObject *_self;
1114 PyObject *_args;
1115{
1116 PyObject *_res = NULL;
1117 OSErr _err;
1118 ControlHandle inBoss;
1119 if (!PyArg_ParseTuple(_args, "O&",
1120 CtlObj_Convert, &inBoss))
1121 return NULL;
1122 _err = SetControlSupervisor(_self->ob_itself,
1123 inBoss);
1124 if (_err != noErr) return PyMac_Error(_err);
1125 Py_INCREF(Py_None);
1126 _res = Py_None;
1127 return _res;
1128}
1129
1130static PyObject *CtlObj_GetControlFeatures(_self, _args)
1131 ControlObject *_self;
1132 PyObject *_args;
1133{
1134 PyObject *_res = NULL;
1135 OSErr _err;
1136 UInt32 outFeatures;
1137 if (!PyArg_ParseTuple(_args, ""))
1138 return NULL;
1139 _err = GetControlFeatures(_self->ob_itself,
1140 &outFeatures);
1141 if (_err != noErr) return PyMac_Error(_err);
1142 _res = Py_BuildValue("l",
1143 outFeatures);
1144 return _res;
1145}
1146
1147static PyObject *CtlObj_GetControlDataSize(_self, _args)
1148 ControlObject *_self;
1149 PyObject *_args;
1150{
1151 PyObject *_res = NULL;
1152 OSErr _err;
1153 ControlPartCode inPart;
1154 ResType inTagName;
1155 Size outMaxSize;
1156 if (!PyArg_ParseTuple(_args, "hO&",
1157 &inPart,
1158 PyMac_GetOSType, &inTagName))
1159 return NULL;
1160 _err = GetControlDataSize(_self->ob_itself,
1161 inPart,
1162 inTagName,
1163 &outMaxSize);
1164 if (_err != noErr) return PyMac_Error(_err);
1165 _res = Py_BuildValue("l",
1166 outMaxSize);
1167 return _res;
1168}
1169
Jack Jansen5d56f4b1995-06-18 20:16:33 +00001170static PyObject *CtlObj_as_Resource(_self, _args)
1171 ControlObject *_self;
1172 PyObject *_args;
1173{
1174 PyObject *_res = NULL;
Jack Jansena1a0fef1999-12-23 14:32:06 +00001175 Handle _rv;
1176 if (!PyArg_ParseTuple(_args, ""))
1177 return NULL;
1178 _rv = as_Resource(_self->ob_itself);
1179 _res = Py_BuildValue("O&",
1180 ResObj_New, _rv);
1181 return _res;
Jack Jansen5d56f4b1995-06-18 20:16:33 +00001182}
1183
Jack Jansen1a7d5b12000-03-21 16:25:23 +00001184static PyObject *CtlObj_GetControlRect(_self, _args)
1185 ControlObject *_self;
1186 PyObject *_args;
1187{
1188 PyObject *_res = NULL;
1189 Rect rect;
1190 if (!PyArg_ParseTuple(_args, ""))
1191 return NULL;
1192 GetControlRect(_self->ob_itself,
1193 &rect);
1194 _res = Py_BuildValue("O&",
1195 PyMac_BuildRect, &rect);
1196 return _res;
1197}
1198
Jack Jansencfb60ee1996-10-01 10:46:46 +00001199static PyObject *CtlObj_DisposeControl(_self, _args)
1200 ControlObject *_self;
1201 PyObject *_args;
1202{
1203 PyObject *_res = NULL;
1204
1205 if (!PyArg_ParseTuple(_args, ""))
1206 return NULL;
1207 if ( _self->ob_itself ) {
Jack Jansen85ae4a81997-04-08 15:26:03 +00001208 SetControlReference(_self->ob_itself, (long)0); /* Make it forget about us */
Jack Jansencfb60ee1996-10-01 10:46:46 +00001209 DisposeControl(_self->ob_itself);
1210 _self->ob_itself = NULL;
1211 }
1212 Py_INCREF(Py_None);
1213 _res = Py_None;
1214 return _res;
1215
1216}
1217
Jack Jansen848250c1998-05-28 14:20:09 +00001218static PyObject *CtlObj_TrackControl(_self, _args)
1219 ControlObject *_self;
1220 PyObject *_args;
1221{
1222 PyObject *_res = NULL;
1223
1224 ControlPartCode _rv;
1225 Point startPoint;
1226 ControlActionUPP upp = 0;
1227 PyObject *callback = 0;
1228
1229 if (!PyArg_ParseTuple(_args, "O&|O",
1230 PyMac_GetPoint, &startPoint, &callback))
1231 return NULL;
1232 if (callback && callback != Py_None) {
1233 if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
1234 upp = (ControlActionUPP)-1;
1235 else {
1236 settrackfunc(callback);
1237 upp = mytracker_upp;
1238 }
1239 }
1240 _rv = TrackControl(_self->ob_itself,
1241 startPoint,
1242 upp);
1243 clrtrackfunc();
1244 _res = Py_BuildValue("h",
1245 _rv);
1246 return _res;
1247
1248}
1249
Jack Jansen24c35311999-12-09 22:49:51 +00001250static PyObject *CtlObj_HandleControlClick(_self, _args)
1251 ControlObject *_self;
1252 PyObject *_args;
1253{
1254 PyObject *_res = NULL;
1255
1256 ControlPartCode _rv;
1257 Point startPoint;
1258 SInt16 modifiers;
1259 ControlActionUPP upp = 0;
1260 PyObject *callback = 0;
1261
1262 if (!PyArg_ParseTuple(_args, "O&h|O",
1263 PyMac_GetPoint, &startPoint,
1264 &modifiers,
1265 &callback))
1266 return NULL;
1267 if (callback && callback != Py_None) {
1268 if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
1269 upp = (ControlActionUPP)-1;
1270 else {
1271 settrackfunc(callback);
1272 upp = mytracker_upp;
1273 }
1274 }
1275 _rv = HandleControlClick(_self->ob_itself,
1276 startPoint,
1277 modifiers,
1278 upp);
1279 clrtrackfunc();
1280 _res = Py_BuildValue("h",
1281 _rv);
1282 return _res;
1283
1284}
1285
1286static PyObject *CtlObj_SetControlData(_self, _args)
1287 ControlObject *_self;
1288 PyObject *_args;
1289{
1290 PyObject *_res = NULL;
1291
1292 OSErr _err;
1293 ControlPartCode inPart;
1294 ResType inTagName;
1295 Size bufferSize;
1296 Ptr buffer;
1297
1298 if (!PyArg_ParseTuple(_args, "hO&s#",
1299 &inPart,
1300 PyMac_GetOSType, &inTagName,
1301 &buffer, &bufferSize))
1302 return NULL;
1303
1304 _err = SetControlData(_self->ob_itself,
1305 inPart,
1306 inTagName,
1307 bufferSize,
1308 buffer);
1309
1310 if (_err != noErr)
1311 return PyMac_Error(_err);
1312 _res = Py_None;
1313 return _res;
1314
1315}
1316
1317static PyObject *CtlObj_GetControlData(_self, _args)
1318 ControlObject *_self;
1319 PyObject *_args;
1320{
1321 PyObject *_res = NULL;
1322
1323 OSErr _err;
1324 ControlPartCode inPart;
1325 ResType inTagName;
1326 Size bufferSize;
1327 Ptr buffer;
1328 Size outSize;
1329
1330 if (!PyArg_ParseTuple(_args, "hO&",
1331 &inPart,
1332 PyMac_GetOSType, &inTagName))
1333 return NULL;
1334
1335 /* allocate a buffer for the data */
1336 _err = GetControlDataSize(_self->ob_itself,
1337 inPart,
1338 inTagName,
1339 &bufferSize);
1340 if (_err != noErr)
1341 return PyMac_Error(_err);
1342 buffer = PyMem_NEW(char, bufferSize);
1343 if (buffer == NULL)
1344 return PyErr_NoMemory();
1345
1346 _err = GetControlData(_self->ob_itself,
1347 inPart,
1348 inTagName,
1349 bufferSize,
1350 buffer,
1351 &outSize);
1352
1353 if (_err != noErr) {
1354 PyMem_DEL(buffer);
1355 return PyMac_Error(_err);
1356 }
1357 _res = Py_BuildValue("s#", buffer, outSize);
1358 PyMem_DEL(buffer);
1359 return _res;
1360
1361}
1362
Jack Jansen1f9249c1999-12-19 00:05:50 +00001363static PyObject *CtlObj_SetControlDataHandle(_self, _args)
1364 ControlObject *_self;
1365 PyObject *_args;
1366{
1367 PyObject *_res = NULL;
1368
1369 OSErr _err;
1370 ControlPartCode inPart;
1371 ResType inTagName;
1372 Handle buffer;
1373
1374 if (!PyArg_ParseTuple(_args, "hO&O&",
1375 &inPart,
1376 PyMac_GetOSType, &inTagName,
Jack Jansenb9247d31999-12-23 23:06:07 +00001377 OptResObj_Convert, &buffer))
Jack Jansen1f9249c1999-12-19 00:05:50 +00001378 return NULL;
1379
1380 _err = SetControlData(_self->ob_itself,
1381 inPart,
1382 inTagName,
1383 sizeof(buffer),
Jack Jansenf7ac1d31999-12-29 12:37:22 +00001384 (Ptr)&buffer);
Jack Jansen1f9249c1999-12-19 00:05:50 +00001385
1386 if (_err != noErr)
1387 return PyMac_Error(_err);
1388 _res = Py_None;
1389 return _res;
1390
1391}
1392
1393static PyObject *CtlObj_GetControlDataHandle(_self, _args)
1394 ControlObject *_self;
1395 PyObject *_args;
1396{
1397 PyObject *_res = NULL;
1398
1399 OSErr _err;
1400 ControlPartCode inPart;
1401 ResType inTagName;
1402 Size bufferSize;
1403 Handle hdl;
1404
1405 if (!PyArg_ParseTuple(_args, "hO&",
1406 &inPart,
1407 PyMac_GetOSType, &inTagName))
1408 return NULL;
1409
1410 /* Check it is handle-sized */
1411 _err = GetControlDataSize(_self->ob_itself,
1412 inPart,
1413 inTagName,
1414 &bufferSize);
1415 if (_err != noErr)
1416 return PyMac_Error(_err);
1417 if (bufferSize != sizeof(Handle)) {
1418 PyErr_SetString(Ctl_Error, "GetControlDataSize() != sizeof(Handle)");
1419 return NULL;
1420 }
1421
1422 _err = GetControlData(_self->ob_itself,
1423 inPart,
1424 inTagName,
1425 sizeof(Handle),
1426 (Ptr)&hdl,
1427 &bufferSize);
1428
1429 if (_err != noErr) {
1430 return PyMac_Error(_err);
1431 }
1432 return Py_BuildValue("O&", OptResObj_New, hdl);
1433
1434}
1435
Jack Jansene79dc762000-06-02 21:35:07 +00001436#ifndef TARGET_API_MAC_CARBON_NOTYET
1437
Jack Jansenabc411b2000-03-20 16:09:09 +00001438static PyObject *CtlObj_SetControlDataCallback(_self, _args)
1439 ControlObject *_self;
1440 PyObject *_args;
1441{
1442 PyObject *_res = NULL;
1443
1444 OSErr _err;
1445 ControlPartCode inPart;
1446 ResType inTagName;
1447 PyObject *callback;
1448 UniversalProcPtr *c_callback;
1449
1450 if (!PyArg_ParseTuple(_args, "hO&O",
1451 &inPart,
1452 PyMac_GetOSType, &inTagName,
1453 &callback))
1454 return NULL;
1455
1456 if ( setcallback(_self, inTagName, callback, &c_callback) < 0 )
1457 return NULL;
1458 _err = SetControlData(_self->ob_itself,
1459 inPart,
1460 inTagName,
1461 sizeof(c_callback),
1462 (Ptr)&c_callback);
1463
1464 if (_err != noErr)
1465 return PyMac_Error(_err);
1466 _res = Py_None;
1467 return _res;
1468
1469}
Jack Jansene79dc762000-06-02 21:35:07 +00001470#endif
1471
1472#ifndef TARGET_API_MAC_CARBON_NOTYET
Jack Jansenabc411b2000-03-20 16:09:09 +00001473
Jack Jansen4c704131998-06-19 13:35:14 +00001474static PyObject *CtlObj_GetPopupData(_self, _args)
1475 ControlObject *_self;
1476 PyObject *_args;
1477{
1478 PyObject *_res = NULL;
1479
1480 PopupPrivateDataHandle hdl;
1481
1482 if ( (*_self->ob_itself)->contrlData == NULL ) {
1483 PyErr_SetString(Ctl_Error, "No contrlData handle in control");
1484 return 0;
1485 }
1486 hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
1487 HLock((Handle)hdl);
1488 _res = Py_BuildValue("O&i", MenuObj_New, (*hdl)->mHandle, (int)(*hdl)->mID);
1489 HUnlock((Handle)hdl);
1490 return _res;
1491
1492}
Jack Jansene79dc762000-06-02 21:35:07 +00001493#endif
1494
1495#ifndef TARGET_API_MAC_CARBON_NOTYET
Jack Jansen4c704131998-06-19 13:35:14 +00001496
1497static PyObject *CtlObj_SetPopupData(_self, _args)
1498 ControlObject *_self;
1499 PyObject *_args;
1500{
1501 PyObject *_res = NULL;
1502
1503 PopupPrivateDataHandle hdl;
1504 MenuHandle mHandle;
1505 short mID;
1506
1507 if (!PyArg_ParseTuple(_args, "O&h", MenuObj_Convert, &mHandle, &mID) )
1508 return 0;
1509 if ( (*_self->ob_itself)->contrlData == NULL ) {
1510 PyErr_SetString(Ctl_Error, "No contrlData handle in control");
1511 return 0;
1512 }
1513 hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
1514 (*hdl)->mHandle = mHandle;
1515 (*hdl)->mID = mID;
1516 Py_INCREF(Py_None);
1517 return Py_None;
1518
1519}
Jack Jansene79dc762000-06-02 21:35:07 +00001520#endif
Jack Jansen4c704131998-06-19 13:35:14 +00001521
Guido van Rossum17448e21995-01-30 11:53:55 +00001522static PyMethodDef CtlObj_methods[] = {
Jack Jansen21f96871998-02-20 16:02:09 +00001523 {"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1,
1524 "(ControlPartCode hiliteState) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001525 {"ShowControl", (PyCFunction)CtlObj_ShowControl, 1,
1526 "() -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001527 {"HideControl", (PyCFunction)CtlObj_HideControl, 1,
1528 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001529 {"IsControlActive", (PyCFunction)CtlObj_IsControlActive, 1,
1530 "() -> (Boolean _rv)"},
1531 {"IsControlVisible", (PyCFunction)CtlObj_IsControlVisible, 1,
1532 "() -> (Boolean _rv)"},
1533 {"ActivateControl", (PyCFunction)CtlObj_ActivateControl, 1,
1534 "() -> None"},
1535 {"DeactivateControl", (PyCFunction)CtlObj_DeactivateControl, 1,
1536 "() -> None"},
1537 {"SetControlVisibility", (PyCFunction)CtlObj_SetControlVisibility, 1,
1538 "(Boolean inIsVisible, Boolean inDoDraw) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001539 {"Draw1Control", (PyCFunction)CtlObj_Draw1Control, 1,
1540 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001541 {"GetBestControlRect", (PyCFunction)CtlObj_GetBestControlRect, 1,
1542 "() -> (Rect outRect, SInt16 outBaseLineOffset)"},
1543 {"SetControlFontStyle", (PyCFunction)CtlObj_SetControlFontStyle, 1,
1544 "(ControlFontStyleRec inStyle) -> None"},
1545 {"DrawControlInCurrentPort", (PyCFunction)CtlObj_DrawControlInCurrentPort, 1,
1546 "() -> None"},
1547 {"SetUpControlBackground", (PyCFunction)CtlObj_SetUpControlBackground, 1,
1548 "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +00001549 {"SetUpControlTextColor", (PyCFunction)CtlObj_SetUpControlTextColor, 1,
1550 "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001551 {"DragControl", (PyCFunction)CtlObj_DragControl, 1,
Jack Jansen754d4a41995-11-14 10:41:55 +00001552 "(Point startPoint, Rect limitRect, Rect slopRect, DragConstraint axis) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001553 {"TestControl", (PyCFunction)CtlObj_TestControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001554 "(Point testPoint) -> (ControlPartCode _rv)"},
1555 {"HandleControlKey", (PyCFunction)CtlObj_HandleControlKey, 1,
1556 "(SInt16 inKeyCode, SInt16 inCharCode, SInt16 inModifiers) -> (SInt16 _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001557 {"MoveControl", (PyCFunction)CtlObj_MoveControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001558 "(SInt16 h, SInt16 v) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001559 {"SizeControl", (PyCFunction)CtlObj_SizeControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001560 "(SInt16 w, SInt16 h) -> None"},
1561 {"SetControlTitle", (PyCFunction)CtlObj_SetControlTitle, 1,
1562 "(Str255 title) -> None"},
1563 {"GetControlTitle", (PyCFunction)CtlObj_GetControlTitle, 1,
Jack Jansen41009001999-03-07 20:05:20 +00001564 "() -> (Str255 title)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001565 {"GetControlValue", (PyCFunction)CtlObj_GetControlValue, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001566 "() -> (SInt16 _rv)"},
1567 {"SetControlValue", (PyCFunction)CtlObj_SetControlValue, 1,
1568 "(SInt16 newValue) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001569 {"GetControlMinimum", (PyCFunction)CtlObj_GetControlMinimum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001570 "() -> (SInt16 _rv)"},
1571 {"SetControlMinimum", (PyCFunction)CtlObj_SetControlMinimum, 1,
1572 "(SInt16 newMinimum) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001573 {"GetControlMaximum", (PyCFunction)CtlObj_GetControlMaximum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001574 "() -> (SInt16 _rv)"},
1575 {"SetControlMaximum", (PyCFunction)CtlObj_SetControlMaximum, 1,
1576 "(SInt16 newMaximum) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +00001577 {"GetControlViewSize", (PyCFunction)CtlObj_GetControlViewSize, 1,
1578 "() -> (SInt32 _rv)"},
1579 {"SetControlViewSize", (PyCFunction)CtlObj_SetControlViewSize, 1,
1580 "(SInt32 newViewSize) -> None"},
1581 {"GetControl32BitValue", (PyCFunction)CtlObj_GetControl32BitValue, 1,
1582 "() -> (SInt32 _rv)"},
1583 {"SetControl32BitValue", (PyCFunction)CtlObj_SetControl32BitValue, 1,
1584 "(SInt32 newValue) -> None"},
1585 {"GetControl32BitMaximum", (PyCFunction)CtlObj_GetControl32BitMaximum, 1,
1586 "() -> (SInt32 _rv)"},
1587 {"SetControl32BitMaximum", (PyCFunction)CtlObj_SetControl32BitMaximum, 1,
1588 "(SInt32 newMaximum) -> None"},
1589 {"GetControl32BitMinimum", (PyCFunction)CtlObj_GetControl32BitMinimum, 1,
1590 "() -> (SInt32 _rv)"},
1591 {"SetControl32BitMinimum", (PyCFunction)CtlObj_SetControl32BitMinimum, 1,
1592 "(SInt32 newMinimum) -> None"},
1593 {"IsValidControlHandle", (PyCFunction)CtlObj_IsValidControlHandle, 1,
1594 "() -> (Boolean _rv)"},
1595 {"RemoveControlProperty", (PyCFunction)CtlObj_RemoveControlProperty, 1,
Jack Jansene79dc762000-06-02 21:35:07 +00001596 "(OSType propertyCreator, OSType propertyTag) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +00001597 {"GetControlRegion", (PyCFunction)CtlObj_GetControlRegion, 1,
Jack Jansene79dc762000-06-02 21:35:07 +00001598 "(ControlPartCode inPart, RgnHandle outRegion) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001599 {"GetControlVariant", (PyCFunction)CtlObj_GetControlVariant, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001600 "() -> (ControlVariant _rv)"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001601 {"SetControlReference", (PyCFunction)CtlObj_SetControlReference, 1,
1602 "(SInt32 data) -> None"},
1603 {"GetControlReference", (PyCFunction)CtlObj_GetControlReference, 1,
1604 "() -> (SInt32 _rv)"},
Jack Jansene79dc762000-06-02 21:35:07 +00001605
1606#ifndef TARGET_API_MAC_CARBON
Jack Jansenc7fefed1997-08-15 14:32:18 +00001607 {"GetAuxiliaryControlRecord", (PyCFunction)CtlObj_GetAuxiliaryControlRecord, 1,
1608 "() -> (Boolean _rv, AuxCtlHandle acHndl)"},
Jack Jansene79dc762000-06-02 21:35:07 +00001609#endif
1610
1611#ifndef TARGET_API_MAC_CARBON
Jack Jansenc7fefed1997-08-15 14:32:18 +00001612 {"SetControlColor", (PyCFunction)CtlObj_SetControlColor, 1,
1613 "(CCTabHandle newColorTable) -> None"},
Jack Jansene79dc762000-06-02 21:35:07 +00001614#endif
1615 {"GetBevelButtonMenuValue", (PyCFunction)CtlObj_GetBevelButtonMenuValue, 1,
1616 "() -> (SInt16 outValue)"},
1617 {"SetBevelButtonMenuValue", (PyCFunction)CtlObj_SetBevelButtonMenuValue, 1,
1618 "(SInt16 inValue) -> None"},
1619 {"GetBevelButtonMenuHandle", (PyCFunction)CtlObj_GetBevelButtonMenuHandle, 1,
1620 "() -> (MenuHandle outHandle)"},
1621 {"SetBevelButtonTransform", (PyCFunction)CtlObj_SetBevelButtonTransform, 1,
1622 "(IconTransformType transform) -> None"},
1623 {"SetImageWellTransform", (PyCFunction)CtlObj_SetImageWellTransform, 1,
1624 "(IconTransformType inTransform) -> None"},
1625 {"GetTabContentRect", (PyCFunction)CtlObj_GetTabContentRect, 1,
1626 "() -> (Rect outContentRect)"},
1627 {"SetTabEnabled", (PyCFunction)CtlObj_SetTabEnabled, 1,
1628 "(SInt16 inTabToHilite, Boolean inEnabled) -> None"},
1629 {"SetDisclosureTriangleLastValue", (PyCFunction)CtlObj_SetDisclosureTriangleLastValue, 1,
1630 "(SInt16 inValue) -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001631 {"SendControlMessage", (PyCFunction)CtlObj_SendControlMessage, 1,
1632 "(SInt16 inMessage, SInt32 inParam) -> (SInt32 _rv)"},
1633 {"EmbedControl", (PyCFunction)CtlObj_EmbedControl, 1,
1634 "(ControlHandle inContainer) -> None"},
1635 {"AutoEmbedControl", (PyCFunction)CtlObj_AutoEmbedControl, 1,
1636 "(WindowPtr inWindow) -> None"},
1637 {"GetSuperControl", (PyCFunction)CtlObj_GetSuperControl, 1,
1638 "() -> (ControlHandle outParent)"},
1639 {"CountSubControls", (PyCFunction)CtlObj_CountSubControls, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00001640 "() -> (UInt16 outNumChildren)"},
Jack Jansen21f96871998-02-20 16:02:09 +00001641 {"GetIndexedSubControl", (PyCFunction)CtlObj_GetIndexedSubControl, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00001642 "(UInt16 inIndex) -> (ControlHandle outSubControl)"},
Jack Jansen21f96871998-02-20 16:02:09 +00001643 {"SetControlSupervisor", (PyCFunction)CtlObj_SetControlSupervisor, 1,
1644 "(ControlHandle inBoss) -> None"},
1645 {"GetControlFeatures", (PyCFunction)CtlObj_GetControlFeatures, 1,
1646 "() -> (UInt32 outFeatures)"},
1647 {"GetControlDataSize", (PyCFunction)CtlObj_GetControlDataSize, 1,
1648 "(ControlPartCode inPart, ResType inTagName) -> (Size outMaxSize)"},
Jack Jansen5d56f4b1995-06-18 20:16:33 +00001649 {"as_Resource", (PyCFunction)CtlObj_as_Resource, 1,
Jack Jansena1a0fef1999-12-23 14:32:06 +00001650 "() -> (Handle _rv)"},
Jack Jansen1a7d5b12000-03-21 16:25:23 +00001651 {"GetControlRect", (PyCFunction)CtlObj_GetControlRect, 1,
1652 "() -> (Rect rect)"},
Jack Jansencfb60ee1996-10-01 10:46:46 +00001653 {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1,
1654 "() -> None"},
Jack Jansen848250c1998-05-28 14:20:09 +00001655 {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00001656 "(Point startPoint [,trackercallback]) -> (ControlPartCode _rv)"},
1657 {"HandleControlClick", (PyCFunction)CtlObj_HandleControlClick, 1,
1658 "(Point startPoint, Integer modifiers, [,trackercallback]) -> (ControlPartCode _rv)"},
1659 {"SetControlData", (PyCFunction)CtlObj_SetControlData, 1,
1660 "(stuff) -> None"},
1661 {"GetControlData", (PyCFunction)CtlObj_GetControlData, 1,
1662 "(part, type) -> String"},
Jack Jansen1f9249c1999-12-19 00:05:50 +00001663 {"SetControlDataHandle", (PyCFunction)CtlObj_SetControlDataHandle, 1,
1664 "(ResObj) -> None"},
1665 {"GetControlDataHandle", (PyCFunction)CtlObj_GetControlDataHandle, 1,
1666 "(part, type) -> ResObj"},
Jack Jansene79dc762000-06-02 21:35:07 +00001667
1668#ifndef TARGET_API_MAC_CARBON_NOTYET
Jack Jansenabc411b2000-03-20 16:09:09 +00001669 {"SetControlDataCallback", (PyCFunction)CtlObj_SetControlDataCallback, 1,
1670 "(callbackfunc) -> None"},
Jack Jansene79dc762000-06-02 21:35:07 +00001671#endif
1672
1673#ifndef TARGET_API_MAC_CARBON_NOTYET
Jack Jansen4c704131998-06-19 13:35:14 +00001674 {"GetPopupData", (PyCFunction)CtlObj_GetPopupData, 1,
1675 NULL},
Jack Jansene79dc762000-06-02 21:35:07 +00001676#endif
1677
1678#ifndef TARGET_API_MAC_CARBON_NOTYET
Jack Jansen4c704131998-06-19 13:35:14 +00001679 {"SetPopupData", (PyCFunction)CtlObj_SetPopupData, 1,
1680 NULL},
Jack Jansene79dc762000-06-02 21:35:07 +00001681#endif
Guido van Rossum17448e21995-01-30 11:53:55 +00001682 {NULL, NULL, 0}
1683};
1684
1685PyMethodChain CtlObj_chain = { CtlObj_methods, NULL };
1686
1687static PyObject *CtlObj_getattr(self, name)
1688 ControlObject *self;
1689 char *name;
1690{
1691 return Py_FindMethodInChain(&CtlObj_chain, (PyObject *)self, name);
1692}
1693
1694#define CtlObj_setattr NULL
1695
Jack Jansen8387af61999-03-13 23:07:32 +00001696static int CtlObj_compare(self, other)
1697 ControlObject *self, *other;
1698{
1699 unsigned long v, w;
1700
1701 if (!CtlObj_Check((PyObject *)other))
1702 {
1703 v=(unsigned long)self;
1704 w=(unsigned long)other;
1705 }
1706 else
1707 {
1708 v=(unsigned long)self->ob_itself;
1709 w=(unsigned long)other->ob_itself;
1710 }
1711 if( v < w ) return -1;
1712 if( v > w ) return 1;
1713 return 0;
1714}
1715
1716#define CtlObj_repr NULL
1717
1718static long CtlObj_hash(self)
1719 ControlObject *self;
1720{
1721 return (long)self->ob_itself;
1722}
1723
Guido van Rossum17448e21995-01-30 11:53:55 +00001724PyTypeObject Control_Type = {
1725 PyObject_HEAD_INIT(&PyType_Type)
1726 0, /*ob_size*/
1727 "Control", /*tp_name*/
1728 sizeof(ControlObject), /*tp_basicsize*/
1729 0, /*tp_itemsize*/
1730 /* methods */
1731 (destructor) CtlObj_dealloc, /*tp_dealloc*/
1732 0, /*tp_print*/
1733 (getattrfunc) CtlObj_getattr, /*tp_getattr*/
1734 (setattrfunc) CtlObj_setattr, /*tp_setattr*/
Jack Jansen8387af61999-03-13 23:07:32 +00001735 (cmpfunc) CtlObj_compare, /*tp_compare*/
1736 (reprfunc) CtlObj_repr, /*tp_repr*/
1737 (PyNumberMethods *)0, /* tp_as_number */
1738 (PySequenceMethods *)0, /* tp_as_sequence */
1739 (PyMappingMethods *)0, /* tp_as_mapping */
1740 (hashfunc) CtlObj_hash, /*tp_hash*/
Guido van Rossum17448e21995-01-30 11:53:55 +00001741};
1742
1743/* -------------------- End object type Control --------------------- */
1744
1745
1746static PyObject *Ctl_NewControl(_self, _args)
1747 PyObject *_self;
1748 PyObject *_args;
1749{
1750 PyObject *_res = NULL;
1751 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001752 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00001753 Rect boundsRect;
Jack Jansen21f96871998-02-20 16:02:09 +00001754 Str255 controlTitle;
1755 Boolean initiallyVisible;
1756 SInt16 initialValue;
1757 SInt16 minimumValue;
1758 SInt16 maximumValue;
Jack Jansen7d0bc831995-06-09 20:56:31 +00001759 SInt16 procID;
Jack Jansen21f96871998-02-20 16:02:09 +00001760 SInt32 controlReference;
Guido van Rossum17448e21995-01-30 11:53:55 +00001761 if (!PyArg_ParseTuple(_args, "O&O&O&bhhhhl",
Jack Jansen21f96871998-02-20 16:02:09 +00001762 WinObj_Convert, &owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00001763 PyMac_GetRect, &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00001764 PyMac_GetStr255, controlTitle,
1765 &initiallyVisible,
1766 &initialValue,
1767 &minimumValue,
1768 &maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00001769 &procID,
Jack Jansen21f96871998-02-20 16:02:09 +00001770 &controlReference))
Guido van Rossum17448e21995-01-30 11:53:55 +00001771 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001772 _rv = NewControl(owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00001773 &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00001774 controlTitle,
1775 initiallyVisible,
1776 initialValue,
1777 minimumValue,
1778 maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00001779 procID,
Jack Jansen21f96871998-02-20 16:02:09 +00001780 controlReference);
Guido van Rossum17448e21995-01-30 11:53:55 +00001781 _res = Py_BuildValue("O&",
1782 CtlObj_New, _rv);
1783 return _res;
1784}
1785
1786static PyObject *Ctl_GetNewControl(_self, _args)
1787 PyObject *_self;
1788 PyObject *_args;
1789{
1790 PyObject *_res = NULL;
1791 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001792 SInt16 resourceID;
1793 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00001794 if (!PyArg_ParseTuple(_args, "hO&",
Jack Jansen21f96871998-02-20 16:02:09 +00001795 &resourceID,
1796 WinObj_Convert, &owningWindow))
Guido van Rossum17448e21995-01-30 11:53:55 +00001797 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001798 _rv = GetNewControl(resourceID,
1799 owningWindow);
Guido van Rossum17448e21995-01-30 11:53:55 +00001800 _res = Py_BuildValue("O&",
1801 CtlObj_New, _rv);
1802 return _res;
1803}
1804
Guido van Rossum17448e21995-01-30 11:53:55 +00001805static PyObject *Ctl_DrawControls(_self, _args)
1806 PyObject *_self;
1807 PyObject *_args;
1808{
1809 PyObject *_res = NULL;
1810 WindowPtr theWindow;
1811 if (!PyArg_ParseTuple(_args, "O&",
1812 WinObj_Convert, &theWindow))
1813 return NULL;
1814 DrawControls(theWindow);
1815 Py_INCREF(Py_None);
1816 _res = Py_None;
1817 return _res;
1818}
1819
Guido van Rossum17448e21995-01-30 11:53:55 +00001820static PyObject *Ctl_UpdateControls(_self, _args)
1821 PyObject *_self;
1822 PyObject *_args;
1823{
1824 PyObject *_res = NULL;
1825 WindowPtr theWindow;
Jack Jansen2b724171996-04-10 14:48:19 +00001826 RgnHandle updateRegion;
1827 if (!PyArg_ParseTuple(_args, "O&O&",
1828 WinObj_Convert, &theWindow,
1829 ResObj_Convert, &updateRegion))
Guido van Rossum17448e21995-01-30 11:53:55 +00001830 return NULL;
1831 UpdateControls(theWindow,
Jack Jansen2b724171996-04-10 14:48:19 +00001832 updateRegion);
Guido van Rossum17448e21995-01-30 11:53:55 +00001833 Py_INCREF(Py_None);
1834 _res = Py_None;
1835 return _res;
1836}
1837
1838static PyObject *Ctl_FindControl(_self, _args)
1839 PyObject *_self;
1840 PyObject *_args;
1841{
1842 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +00001843 ControlPartCode _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001844 Point testPoint;
Guido van Rossum17448e21995-01-30 11:53:55 +00001845 WindowPtr theWindow;
1846 ControlHandle theControl;
1847 if (!PyArg_ParseTuple(_args, "O&O&",
Jack Jansen21f96871998-02-20 16:02:09 +00001848 PyMac_GetPoint, &testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00001849 WinObj_Convert, &theWindow))
1850 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001851 _rv = FindControl(testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00001852 theWindow,
1853 &theControl);
1854 _res = Py_BuildValue("hO&",
1855 _rv,
1856 CtlObj_WhichControl, theControl);
1857 return _res;
1858}
1859
Jack Jansen21f96871998-02-20 16:02:09 +00001860static PyObject *Ctl_FindControlUnderMouse(_self, _args)
1861 PyObject *_self;
1862 PyObject *_args;
1863{
1864 PyObject *_res = NULL;
1865 ControlHandle _rv;
1866 Point inWhere;
1867 WindowPtr inWindow;
1868 SInt16 outPart;
1869 if (!PyArg_ParseTuple(_args, "O&O&",
1870 PyMac_GetPoint, &inWhere,
1871 WinObj_Convert, &inWindow))
1872 return NULL;
1873 _rv = FindControlUnderMouse(inWhere,
1874 inWindow,
1875 &outPart);
1876 _res = Py_BuildValue("O&h",
1877 CtlObj_New, _rv,
1878 outPart);
1879 return _res;
1880}
1881
1882static PyObject *Ctl_IdleControls(_self, _args)
1883 PyObject *_self;
1884 PyObject *_args;
1885{
1886 PyObject *_res = NULL;
1887 WindowPtr inWindow;
1888 if (!PyArg_ParseTuple(_args, "O&",
1889 WinObj_Convert, &inWindow))
1890 return NULL;
1891 IdleControls(inWindow);
1892 Py_INCREF(Py_None);
1893 _res = Py_None;
1894 return _res;
1895}
1896
1897static PyObject *Ctl_DumpControlHierarchy(_self, _args)
1898 PyObject *_self;
1899 PyObject *_args;
1900{
1901 PyObject *_res = NULL;
1902 OSErr _err;
1903 WindowPtr inWindow;
1904 FSSpec inDumpFile;
1905 if (!PyArg_ParseTuple(_args, "O&O&",
1906 WinObj_Convert, &inWindow,
1907 PyMac_GetFSSpec, &inDumpFile))
1908 return NULL;
1909 _err = DumpControlHierarchy(inWindow,
1910 &inDumpFile);
1911 if (_err != noErr) return PyMac_Error(_err);
1912 Py_INCREF(Py_None);
1913 _res = Py_None;
1914 return _res;
1915}
1916
1917static PyObject *Ctl_CreateRootControl(_self, _args)
1918 PyObject *_self;
1919 PyObject *_args;
1920{
1921 PyObject *_res = NULL;
1922 OSErr _err;
1923 WindowPtr inWindow;
1924 ControlHandle outControl;
1925 if (!PyArg_ParseTuple(_args, "O&",
1926 WinObj_Convert, &inWindow))
1927 return NULL;
1928 _err = CreateRootControl(inWindow,
1929 &outControl);
1930 if (_err != noErr) return PyMac_Error(_err);
1931 _res = Py_BuildValue("O&",
1932 CtlObj_WhichControl, outControl);
1933 return _res;
1934}
1935
1936static PyObject *Ctl_GetRootControl(_self, _args)
1937 PyObject *_self;
1938 PyObject *_args;
1939{
1940 PyObject *_res = NULL;
1941 OSErr _err;
1942 WindowPtr inWindow;
1943 ControlHandle outControl;
1944 if (!PyArg_ParseTuple(_args, "O&",
1945 WinObj_Convert, &inWindow))
1946 return NULL;
1947 _err = GetRootControl(inWindow,
1948 &outControl);
1949 if (_err != noErr) return PyMac_Error(_err);
1950 _res = Py_BuildValue("O&",
1951 CtlObj_WhichControl, outControl);
1952 return _res;
1953}
1954
1955static PyObject *Ctl_GetKeyboardFocus(_self, _args)
1956 PyObject *_self;
1957 PyObject *_args;
1958{
1959 PyObject *_res = NULL;
1960 OSErr _err;
1961 WindowPtr inWindow;
1962 ControlHandle outControl;
1963 if (!PyArg_ParseTuple(_args, "O&",
1964 WinObj_Convert, &inWindow))
1965 return NULL;
1966 _err = GetKeyboardFocus(inWindow,
1967 &outControl);
1968 if (_err != noErr) return PyMac_Error(_err);
1969 _res = Py_BuildValue("O&",
1970 CtlObj_WhichControl, outControl);
1971 return _res;
1972}
1973
1974static PyObject *Ctl_SetKeyboardFocus(_self, _args)
1975 PyObject *_self;
1976 PyObject *_args;
1977{
1978 PyObject *_res = NULL;
1979 OSErr _err;
1980 WindowPtr inWindow;
1981 ControlHandle inControl;
1982 ControlFocusPart inPart;
1983 if (!PyArg_ParseTuple(_args, "O&O&h",
1984 WinObj_Convert, &inWindow,
1985 CtlObj_Convert, &inControl,
1986 &inPart))
1987 return NULL;
1988 _err = SetKeyboardFocus(inWindow,
1989 inControl,
1990 inPart);
1991 if (_err != noErr) return PyMac_Error(_err);
1992 Py_INCREF(Py_None);
1993 _res = Py_None;
1994 return _res;
1995}
1996
1997static PyObject *Ctl_AdvanceKeyboardFocus(_self, _args)
1998 PyObject *_self;
1999 PyObject *_args;
2000{
2001 PyObject *_res = NULL;
2002 OSErr _err;
2003 WindowPtr inWindow;
2004 if (!PyArg_ParseTuple(_args, "O&",
2005 WinObj_Convert, &inWindow))
2006 return NULL;
2007 _err = AdvanceKeyboardFocus(inWindow);
2008 if (_err != noErr) return PyMac_Error(_err);
2009 Py_INCREF(Py_None);
2010 _res = Py_None;
2011 return _res;
2012}
2013
2014static PyObject *Ctl_ReverseKeyboardFocus(_self, _args)
2015 PyObject *_self;
2016 PyObject *_args;
2017{
2018 PyObject *_res = NULL;
2019 OSErr _err;
2020 WindowPtr inWindow;
2021 if (!PyArg_ParseTuple(_args, "O&",
2022 WinObj_Convert, &inWindow))
2023 return NULL;
2024 _err = ReverseKeyboardFocus(inWindow);
2025 if (_err != noErr) return PyMac_Error(_err);
2026 Py_INCREF(Py_None);
2027 _res = Py_None;
2028 return _res;
2029}
2030
2031static PyObject *Ctl_ClearKeyboardFocus(_self, _args)
2032 PyObject *_self;
2033 PyObject *_args;
2034{
2035 PyObject *_res = NULL;
2036 OSErr _err;
2037 WindowPtr inWindow;
2038 if (!PyArg_ParseTuple(_args, "O&",
2039 WinObj_Convert, &inWindow))
2040 return NULL;
2041 _err = ClearKeyboardFocus(inWindow);
2042 if (_err != noErr) return PyMac_Error(_err);
2043 Py_INCREF(Py_None);
2044 _res = Py_None;
2045 return _res;
2046}
2047
Jack Jansene0581891999-02-07 14:02:03 +00002048static PyObject *Ctl_as_Control(_self, _args)
2049 PyObject *_self;
2050 PyObject *_args;
2051{
2052 PyObject *_res = NULL;
2053 ControlHandle _rv;
2054 Handle h;
2055 if (!PyArg_ParseTuple(_args, "O&",
2056 ResObj_Convert, &h))
2057 return NULL;
2058 _rv = as_Control(h);
2059 _res = Py_BuildValue("O&",
2060 CtlObj_New, _rv);
2061 return _res;
2062}
2063
Guido van Rossum17448e21995-01-30 11:53:55 +00002064static PyMethodDef Ctl_methods[] = {
2065 {"NewControl", (PyCFunction)Ctl_NewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00002066 "(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 +00002067 {"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00002068 "(SInt16 resourceID, WindowPtr owningWindow) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002069 {"DrawControls", (PyCFunction)Ctl_DrawControls, 1,
2070 "(WindowPtr theWindow) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002071 {"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1,
Jack Jansen2b724171996-04-10 14:48:19 +00002072 "(WindowPtr theWindow, RgnHandle updateRegion) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002073 {"FindControl", (PyCFunction)Ctl_FindControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00002074 "(Point testPoint, WindowPtr theWindow) -> (ControlPartCode _rv, ControlHandle theControl)"},
2075 {"FindControlUnderMouse", (PyCFunction)Ctl_FindControlUnderMouse, 1,
2076 "(Point inWhere, WindowPtr inWindow) -> (ControlHandle _rv, SInt16 outPart)"},
2077 {"IdleControls", (PyCFunction)Ctl_IdleControls, 1,
2078 "(WindowPtr inWindow) -> None"},
2079 {"DumpControlHierarchy", (PyCFunction)Ctl_DumpControlHierarchy, 1,
2080 "(WindowPtr inWindow, FSSpec inDumpFile) -> None"},
2081 {"CreateRootControl", (PyCFunction)Ctl_CreateRootControl, 1,
2082 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
2083 {"GetRootControl", (PyCFunction)Ctl_GetRootControl, 1,
2084 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
2085 {"GetKeyboardFocus", (PyCFunction)Ctl_GetKeyboardFocus, 1,
2086 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
2087 {"SetKeyboardFocus", (PyCFunction)Ctl_SetKeyboardFocus, 1,
2088 "(WindowPtr inWindow, ControlHandle inControl, ControlFocusPart inPart) -> None"},
2089 {"AdvanceKeyboardFocus", (PyCFunction)Ctl_AdvanceKeyboardFocus, 1,
2090 "(WindowPtr inWindow) -> None"},
2091 {"ReverseKeyboardFocus", (PyCFunction)Ctl_ReverseKeyboardFocus, 1,
2092 "(WindowPtr inWindow) -> None"},
2093 {"ClearKeyboardFocus", (PyCFunction)Ctl_ClearKeyboardFocus, 1,
2094 "(WindowPtr inWindow) -> None"},
Jack Jansene0581891999-02-07 14:02:03 +00002095 {"as_Control", (PyCFunction)Ctl_as_Control, 1,
2096 "(Handle h) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00002097 {NULL, NULL, 0}
2098};
2099
2100
2101
Jack Jansen8387af61999-03-13 23:07:32 +00002102PyObject *CtlObj_NewUnmanaged(itself)
2103 ControlHandle itself;
2104{
2105 ControlObject *it;
2106 if (itself == NULL) return PyMac_Error(resNotFound);
2107 it = PyObject_NEW(ControlObject, &Control_Type);
2108 if (it == NULL) return NULL;
2109 it->ob_itself = itself;
Jack Jansen1a7d5b12000-03-21 16:25:23 +00002110 it->ob_callbackdict = NULL;
Jack Jansen8387af61999-03-13 23:07:32 +00002111 return (PyObject *)it;
2112}
2113
Guido van Rossum17448e21995-01-30 11:53:55 +00002114PyObject *
2115CtlObj_WhichControl(ControlHandle c)
2116{
2117 PyObject *it;
Jack Jansen24c35311999-12-09 22:49:51 +00002118
Guido van Rossum17448e21995-01-30 11:53:55 +00002119 if (c == NULL)
Guido van Rossum17448e21995-01-30 11:53:55 +00002120 it = Py_None;
Jack Jansen8387af61999-03-13 23:07:32 +00002121 else {
2122 it = (PyObject *) GetControlReference(c);
2123 /*
2124 ** If the refcon is zero or doesn't point back to the Python object
2125 ** the control is not ours. Return a temporary object.
2126 */
2127 if (it == NULL || ((ControlObject *)it)->ob_itself != c)
2128 return CtlObj_NewUnmanaged(c);
2129 }
Guido van Rossum17448e21995-01-30 11:53:55 +00002130 Py_INCREF(it);
2131 return it;
2132}
2133
Jack Jansen848250c1998-05-28 14:20:09 +00002134static int
2135settrackfunc(obj)
2136 PyObject *obj;
2137{
2138 if (tracker) {
2139 PyErr_SetString(Ctl_Error, "Tracker function in use");
2140 return 0;
2141 }
2142 tracker = obj;
2143 Py_INCREF(tracker);
2144}
2145
2146static void
2147clrtrackfunc()
2148{
2149 Py_XDECREF(tracker);
2150 tracker = 0;
2151}
2152
2153static pascal void
Jack Jansene79dc762000-06-02 21:35:07 +00002154mytracker(ControlHandle ctl, short part)
Jack Jansen848250c1998-05-28 14:20:09 +00002155{
2156 PyObject *args, *rv=0;
Jack Jansen24c35311999-12-09 22:49:51 +00002157
Jack Jansen848250c1998-05-28 14:20:09 +00002158 args = Py_BuildValue("(O&i)", CtlObj_WhichControl, ctl, (int)part);
2159 if (args && tracker) {
2160 rv = PyEval_CallObject(tracker, args);
2161 Py_DECREF(args);
2162 }
2163 if (rv)
2164 Py_DECREF(rv);
2165 else
Jack Jansen24c35311999-12-09 22:49:51 +00002166 PySys_WriteStderr("TrackControl or HandleControlClick: exception in tracker function\n");
Jack Jansen848250c1998-05-28 14:20:09 +00002167}
2168
Jack Jansene79dc762000-06-02 21:35:07 +00002169#ifndef TARGET_API_MAC_CARBON_NOTYET
Jack Jansenabc411b2000-03-20 16:09:09 +00002170static int
2171setcallback(self, which, callback, uppp)
2172 ControlObject *self;
2173 OSType which;
2174 PyObject *callback;
2175 UniversalProcPtr *uppp;
2176{
2177 char keybuf[9];
2178
2179 if ( which == kControlUserPaneDrawProcTag )
Jack Jansen1b6e8212000-04-05 21:30:57 +00002180 *uppp = (UniversalProcPtr)mydrawproc_upp;
Jack Jansenabc411b2000-03-20 16:09:09 +00002181 else if ( which == kControlUserPaneIdleProcTag )
Jack Jansen1b6e8212000-04-05 21:30:57 +00002182 *uppp = (UniversalProcPtr)myidleproc_upp;
Jack Jansena27e9fb2000-03-21 23:03:02 +00002183 else if ( which == kControlUserPaneHitTestProcTag )
Jack Jansen1b6e8212000-04-05 21:30:57 +00002184 *uppp = (UniversalProcPtr)myhittestproc_upp;
Jack Jansena27e9fb2000-03-21 23:03:02 +00002185 else if ( which == kControlUserPaneTrackingProcTag )
Jack Jansen1b6e8212000-04-05 21:30:57 +00002186 *uppp = (UniversalProcPtr)mytrackingproc_upp;
Jack Jansenabc411b2000-03-20 16:09:09 +00002187 else
2188 return -1;
2189 /* Only now do we test for clearing of the callback: */
2190 if ( callback == Py_None )
2191 *uppp = NULL;
2192 /* Create the dict if it doesn't exist yet (so we don't get such a dict for every control) */
2193 if ( self->ob_callbackdict == NULL )
2194 if ( (self->ob_callbackdict = PyDict_New()) == NULL )
2195 return -1;
2196 /* And store the Python callback */
2197 sprintf(keybuf, "%x", which);
2198 if (PyDict_SetItemString(self->ob_callbackdict, keybuf, callback) < 0)
2199 return -1;
2200 return 0;
2201}
2202
2203static PyObject *
2204callcallback(self, which, arglist)
2205 ControlObject *self;
2206 OSType which;
2207 PyObject *arglist;
2208{
2209 char keybuf[9];
2210 PyObject *func, *rv;
2211
2212 sprintf(keybuf, "%x", which);
2213 if ( self->ob_callbackdict == NULL ||
2214 (func = PyDict_GetItemString(self->ob_callbackdict, keybuf)) == NULL ) {
Jack Jansena27e9fb2000-03-21 23:03:02 +00002215 PySys_WriteStderr("Control callback %x without callback object\n", which);
Jack Jansenabc411b2000-03-20 16:09:09 +00002216 return NULL;
2217 }
2218 rv = PyEval_CallObject(func, arglist);
2219 if ( rv == NULL )
Jack Jansena27e9fb2000-03-21 23:03:02 +00002220 PySys_WriteStderr("Exception in control callback %x handler\n", which);
Jack Jansenabc411b2000-03-20 16:09:09 +00002221 return rv;
2222}
2223
2224static pascal void
2225mydrawproc(ControlHandle control, SInt16 part)
2226{
2227 ControlObject *ctl_obj;
2228 PyObject *arglist, *rv;
2229
2230 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
2231 arglist = Py_BuildValue("Oh", ctl_obj, part);
2232 rv = callcallback(ctl_obj, kControlUserPaneDrawProcTag, arglist);
2233 Py_XDECREF(arglist);
2234 Py_XDECREF(rv);
2235}
2236
2237static pascal void
2238myidleproc(ControlHandle control)
2239{
2240 ControlObject *ctl_obj;
2241 PyObject *arglist, *rv;
2242
2243 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
2244 arglist = Py_BuildValue("O", ctl_obj);
2245 rv = callcallback(ctl_obj, kControlUserPaneIdleProcTag, arglist);
2246 Py_XDECREF(arglist);
2247 Py_XDECREF(rv);
2248}
2249
Jack Jansena27e9fb2000-03-21 23:03:02 +00002250static pascal ControlPartCode
2251myhittestproc(ControlHandle control, Point where)
2252{
2253 ControlObject *ctl_obj;
2254 PyObject *arglist, *rv;
2255 short c_rv = -1;
2256
2257 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
Jack Jansendeb63732000-03-22 15:35:24 +00002258 arglist = Py_BuildValue("OO&", ctl_obj, PyMac_BuildPoint, where);
Jack Jansena27e9fb2000-03-21 23:03:02 +00002259 rv = callcallback(ctl_obj, kControlUserPaneHitTestProcTag, arglist);
2260 Py_XDECREF(arglist);
2261 /* Ignore errors, nothing we can do about them */
2262 if ( rv )
2263 PyArg_Parse(rv, "h", &c_rv);
2264 Py_XDECREF(rv);
2265 return (ControlPartCode)c_rv;
2266}
2267
2268static pascal ControlPartCode
2269mytrackingproc(ControlHandle control, Point startPt, ControlActionUPP actionProc)
2270{
2271 ControlObject *ctl_obj;
2272 PyObject *arglist, *rv;
2273 short c_rv = -1;
2274
2275 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
2276 /* We cannot pass the actionProc without lots of work */
Jack Jansendeb63732000-03-22 15:35:24 +00002277 arglist = Py_BuildValue("OO&", ctl_obj, PyMac_BuildPoint, startPt);
Jack Jansena27e9fb2000-03-21 23:03:02 +00002278 rv = callcallback(ctl_obj, kControlUserPaneTrackingProcTag, arglist);
2279 Py_XDECREF(arglist);
2280 if ( rv )
2281 PyArg_Parse(rv, "h", &c_rv);
2282 Py_XDECREF(rv);
2283 return (ControlPartCode)c_rv;
2284}
Jack Jansene79dc762000-06-02 21:35:07 +00002285#endif
Jack Jansenabc411b2000-03-20 16:09:09 +00002286
Guido van Rossum17448e21995-01-30 11:53:55 +00002287
2288void initCtl()
2289{
2290 PyObject *m;
2291 PyObject *d;
2292
2293
2294
Jack Jansen848250c1998-05-28 14:20:09 +00002295 mytracker_upp = NewControlActionProc(mytracker);
Jack Jansene79dc762000-06-02 21:35:07 +00002296#ifndef TARGET_API_MAC_CARBON_NOTYET
Jack Jansenabc411b2000-03-20 16:09:09 +00002297 mydrawproc_upp = NewControlUserPaneDrawProc(mydrawproc);
Jack Jansen1b6e8212000-04-05 21:30:57 +00002298 myidleproc_upp = NewControlUserPaneIdleProc(myidleproc);
Jack Jansena27e9fb2000-03-21 23:03:02 +00002299 myhittestproc_upp = NewControlUserPaneHitTestProc(myhittestproc);
2300 mytrackingproc_upp = NewControlUserPaneTrackingProc(mytrackingproc);
Jack Jansene79dc762000-06-02 21:35:07 +00002301#endif
Jack Jansen848250c1998-05-28 14:20:09 +00002302
Guido van Rossum17448e21995-01-30 11:53:55 +00002303
2304 m = Py_InitModule("Ctl", Ctl_methods);
2305 d = PyModule_GetDict(m);
2306 Ctl_Error = PyMac_GetOSErrException();
2307 if (Ctl_Error == NULL ||
2308 PyDict_SetItemString(d, "Error", Ctl_Error) != 0)
2309 Py_FatalError("can't initialize Ctl.Error");
Jack Jansena755e681997-09-20 17:40:22 +00002310 Control_Type.ob_type = &PyType_Type;
2311 Py_INCREF(&Control_Type);
2312 if (PyDict_SetItemString(d, "ControlType", (PyObject *)&Control_Type) != 0)
2313 Py_FatalError("can't initialize ControlType");
Guido van Rossum17448e21995-01-30 11:53:55 +00002314}
2315
2316/* ========================= End module Ctl ========================= */
2317