blob: 991b567db129de8e6bb280c4ea8c4af00af28af9 [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 Jansen1a7d5b12000-03-21 16:25:23 +000049#define GetControlRect(ctl, rectp) (*(rectp) = ((*(ctl))->contrlRect))
Jack Jansene0581891999-02-07 14:02:03 +000050
Guido van Rossum17448e21995-01-30 11:53:55 +000051#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
52
53extern PyObject *CtlObj_WhichControl(ControlHandle); /* Forward */
Jack Jansen21f96871998-02-20 16:02:09 +000054extern PyObject *QdRGB_New(RGBColorPtr);
55extern QdRGB_Convert(PyObject *, RGBColorPtr);
Guido van Rossum17448e21995-01-30 11:53:55 +000056
57#ifdef THINK_C
58#define ControlActionUPP ProcPtr
59#endif
60
Jack Jansen21f96871998-02-20 16:02:09 +000061/*
62** Parse/generate ControlFontStyleRec records
63*/
64#if 0 /* Not needed */
65PyObject *ControlFontStyle_New(itself)
66 ControlFontStyleRec *itself;
67{
68
69 return Py_BuildValue("hhhhhhO&O&", itself->flags, itself->font,
70 itself->size, itself->style, itself->mode, itself->just,
71 QdRGB_New, &itself->foreColor, QdRGB_New, &itself->backColor);
72}
73#endif
74
75ControlFontStyle_Convert(v, itself)
76 PyObject *v;
77 ControlFontStyleRec *itself;
78{
79 return PyArg_ParseTuple(v, "hhhhhhO&O&", &itself->flags,
Jack Jansen24c35311999-12-09 22:49:51 +000080 &itself->font, &itself->size, &itself->style, &itself->mode,
81 &itself->just, QdRGB_Convert, &itself->foreColor,
Jack Jansen21f96871998-02-20 16:02:09 +000082 QdRGB_Convert, &itself->backColor);
83}
84
Jack Jansen24c35311999-12-09 22:49:51 +000085/* TrackControl and HandleControlClick callback support */
Jack Jansen848250c1998-05-28 14:20:09 +000086static PyObject *tracker;
87static ControlActionUPP mytracker_upp;
Jack Jansenabc411b2000-03-20 16:09:09 +000088static ControlUserPaneDrawUPP mydrawproc_upp;
89static ControlUserPaneIdleUPP myidleproc_upp;
Jack Jansena27e9fb2000-03-21 23:03:02 +000090static ControlUserPaneHitTestUPP myhittestproc_upp;
91static ControlUserPaneTrackingUPP mytrackingproc_upp;
Jack Jansen848250c1998-05-28 14:20:09 +000092
93extern int settrackfunc(PyObject *); /* forward */
94extern void clrtrackfunc(void); /* forward */
95
Guido van Rossum17448e21995-01-30 11:53:55 +000096static PyObject *Ctl_Error;
97
98/* ---------------------- Object type Control ----------------------- */
99
100PyTypeObject Control_Type;
101
102#define CtlObj_Check(x) ((x)->ob_type == &Control_Type)
103
104typedef struct ControlObject {
105 PyObject_HEAD
106 ControlHandle ob_itself;
Jack Jansenabc411b2000-03-20 16:09:09 +0000107 PyObject *ob_callbackdict;
Guido van Rossum17448e21995-01-30 11:53:55 +0000108} ControlObject;
109
110PyObject *CtlObj_New(itself)
Jack Jansenae8a68f1995-06-06 12:55:40 +0000111 ControlHandle itself;
Guido van Rossum17448e21995-01-30 11:53:55 +0000112{
113 ControlObject *it;
114 if (itself == NULL) return PyMac_Error(resNotFound);
115 it = PyObject_NEW(ControlObject, &Control_Type);
116 if (it == NULL) return NULL;
117 it->ob_itself = itself;
Jack Jansen85ae4a81997-04-08 15:26:03 +0000118 SetControlReference(itself, (long)it);
Jack Jansenabc411b2000-03-20 16:09:09 +0000119 it->ob_callbackdict = NULL;
Guido van Rossum17448e21995-01-30 11:53:55 +0000120 return (PyObject *)it;
121}
122CtlObj_Convert(v, p_itself)
123 PyObject *v;
124 ControlHandle *p_itself;
125{
126 if (!CtlObj_Check(v))
127 {
128 PyErr_SetString(PyExc_TypeError, "Control required");
129 return 0;
130 }
131 *p_itself = ((ControlObject *)v)->ob_itself;
132 return 1;
133}
134
135static void CtlObj_dealloc(self)
136 ControlObject *self;
137{
Jack Jansenabc411b2000-03-20 16:09:09 +0000138 Py_XDECREF(self->ob_callbackdict);
Jack Jansen24c35311999-12-09 22:49:51 +0000139 if (self->ob_itself)SetControlReference(self->ob_itself, (long)0); /* Make it forget about us */
Guido van Rossum17448e21995-01-30 11:53:55 +0000140 PyMem_DEL(self);
141}
142
Jack Jansen21f96871998-02-20 16:02:09 +0000143static PyObject *CtlObj_HiliteControl(_self, _args)
144 ControlObject *_self;
145 PyObject *_args;
146{
147 PyObject *_res = NULL;
148 ControlPartCode hiliteState;
149 if (!PyArg_ParseTuple(_args, "h",
150 &hiliteState))
151 return NULL;
152 HiliteControl(_self->ob_itself,
153 hiliteState);
154 Py_INCREF(Py_None);
155 _res = Py_None;
156 return _res;
157}
158
Jack Jansen7d0bc831995-06-09 20:56:31 +0000159static PyObject *CtlObj_ShowControl(_self, _args)
160 ControlObject *_self;
161 PyObject *_args;
162{
163 PyObject *_res = NULL;
164 if (!PyArg_ParseTuple(_args, ""))
165 return NULL;
166 ShowControl(_self->ob_itself);
167 Py_INCREF(Py_None);
168 _res = Py_None;
169 return _res;
170}
171
172static PyObject *CtlObj_HideControl(_self, _args)
173 ControlObject *_self;
174 PyObject *_args;
175{
176 PyObject *_res = NULL;
177 if (!PyArg_ParseTuple(_args, ""))
178 return NULL;
179 HideControl(_self->ob_itself);
180 Py_INCREF(Py_None);
181 _res = Py_None;
182 return _res;
183}
184
Jack Jansen21f96871998-02-20 16:02:09 +0000185static PyObject *CtlObj_IsControlActive(_self, _args)
186 ControlObject *_self;
187 PyObject *_args;
188{
189 PyObject *_res = NULL;
190 Boolean _rv;
191 if (!PyArg_ParseTuple(_args, ""))
192 return NULL;
193 _rv = IsControlActive(_self->ob_itself);
194 _res = Py_BuildValue("b",
195 _rv);
196 return _res;
197}
198
199static PyObject *CtlObj_IsControlVisible(_self, _args)
200 ControlObject *_self;
201 PyObject *_args;
202{
203 PyObject *_res = NULL;
204 Boolean _rv;
205 if (!PyArg_ParseTuple(_args, ""))
206 return NULL;
207 _rv = IsControlVisible(_self->ob_itself);
208 _res = Py_BuildValue("b",
209 _rv);
210 return _res;
211}
212
213static PyObject *CtlObj_ActivateControl(_self, _args)
214 ControlObject *_self;
215 PyObject *_args;
216{
217 PyObject *_res = NULL;
218 OSErr _err;
219 if (!PyArg_ParseTuple(_args, ""))
220 return NULL;
221 _err = ActivateControl(_self->ob_itself);
222 if (_err != noErr) return PyMac_Error(_err);
223 Py_INCREF(Py_None);
224 _res = Py_None;
225 return _res;
226}
227
228static PyObject *CtlObj_DeactivateControl(_self, _args)
229 ControlObject *_self;
230 PyObject *_args;
231{
232 PyObject *_res = NULL;
233 OSErr _err;
234 if (!PyArg_ParseTuple(_args, ""))
235 return NULL;
236 _err = DeactivateControl(_self->ob_itself);
237 if (_err != noErr) return PyMac_Error(_err);
238 Py_INCREF(Py_None);
239 _res = Py_None;
240 return _res;
241}
242
243static PyObject *CtlObj_SetControlVisibility(_self, _args)
244 ControlObject *_self;
245 PyObject *_args;
246{
247 PyObject *_res = NULL;
248 OSErr _err;
249 Boolean inIsVisible;
250 Boolean inDoDraw;
251 if (!PyArg_ParseTuple(_args, "bb",
252 &inIsVisible,
253 &inDoDraw))
254 return NULL;
255 _err = SetControlVisibility(_self->ob_itself,
256 inIsVisible,
257 inDoDraw);
258 if (_err != noErr) return PyMac_Error(_err);
259 Py_INCREF(Py_None);
260 _res = Py_None;
261 return _res;
262}
263
Jack Jansen7d0bc831995-06-09 20:56:31 +0000264static PyObject *CtlObj_Draw1Control(_self, _args)
265 ControlObject *_self;
266 PyObject *_args;
267{
268 PyObject *_res = NULL;
269 if (!PyArg_ParseTuple(_args, ""))
270 return NULL;
271 Draw1Control(_self->ob_itself);
272 Py_INCREF(Py_None);
273 _res = Py_None;
274 return _res;
275}
276
Jack Jansen21f96871998-02-20 16:02:09 +0000277static PyObject *CtlObj_GetBestControlRect(_self, _args)
Jack Jansen7d0bc831995-06-09 20:56:31 +0000278 ControlObject *_self;
279 PyObject *_args;
280{
281 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000282 OSErr _err;
283 Rect outRect;
284 SInt16 outBaseLineOffset;
285 if (!PyArg_ParseTuple(_args, ""))
Jack Jansen7d0bc831995-06-09 20:56:31 +0000286 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000287 _err = GetBestControlRect(_self->ob_itself,
288 &outRect,
289 &outBaseLineOffset);
290 if (_err != noErr) return PyMac_Error(_err);
291 _res = Py_BuildValue("O&h",
292 PyMac_BuildRect, &outRect,
293 outBaseLineOffset);
294 return _res;
295}
296
297static PyObject *CtlObj_SetControlFontStyle(_self, _args)
298 ControlObject *_self;
299 PyObject *_args;
300{
301 PyObject *_res = NULL;
302 OSErr _err;
303 ControlFontStyleRec inStyle;
304 if (!PyArg_ParseTuple(_args, "O&",
305 ControlFontStyle_Convert, &inStyle))
306 return NULL;
307 _err = SetControlFontStyle(_self->ob_itself,
308 &inStyle);
309 if (_err != noErr) return PyMac_Error(_err);
310 Py_INCREF(Py_None);
311 _res = Py_None;
312 return _res;
313}
314
315static PyObject *CtlObj_DrawControlInCurrentPort(_self, _args)
316 ControlObject *_self;
317 PyObject *_args;
318{
319 PyObject *_res = NULL;
320 if (!PyArg_ParseTuple(_args, ""))
321 return NULL;
322 DrawControlInCurrentPort(_self->ob_itself);
323 Py_INCREF(Py_None);
324 _res = Py_None;
325 return _res;
326}
327
328static PyObject *CtlObj_SetUpControlBackground(_self, _args)
329 ControlObject *_self;
330 PyObject *_args;
331{
332 PyObject *_res = NULL;
333 OSErr _err;
334 SInt16 inDepth;
335 Boolean inIsColorDevice;
336 if (!PyArg_ParseTuple(_args, "hb",
337 &inDepth,
338 &inIsColorDevice))
339 return NULL;
340 _err = SetUpControlBackground(_self->ob_itself,
341 inDepth,
342 inIsColorDevice);
343 if (_err != noErr) return PyMac_Error(_err);
Jack Jansen7d0bc831995-06-09 20:56:31 +0000344 Py_INCREF(Py_None);
345 _res = Py_None;
346 return _res;
347}
348
Jack Jansena05ac601999-12-12 21:41:51 +0000349static PyObject *CtlObj_SetUpControlTextColor(_self, _args)
350 ControlObject *_self;
351 PyObject *_args;
352{
353 PyObject *_res = NULL;
354 OSErr _err;
355 SInt16 inDepth;
356 Boolean inIsColorDevice;
357 if (!PyArg_ParseTuple(_args, "hb",
358 &inDepth,
359 &inIsColorDevice))
360 return NULL;
361 _err = SetUpControlTextColor(_self->ob_itself,
362 inDepth,
363 inIsColorDevice);
364 if (_err != noErr) return PyMac_Error(_err);
365 Py_INCREF(Py_None);
366 _res = Py_None;
367 return _res;
368}
369
Jack Jansen7d0bc831995-06-09 20:56:31 +0000370static PyObject *CtlObj_DragControl(_self, _args)
371 ControlObject *_self;
372 PyObject *_args;
373{
374 PyObject *_res = NULL;
Jack Jansen754d4a41995-11-14 10:41:55 +0000375 Point startPoint;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000376 Rect limitRect;
377 Rect slopRect;
378 DragConstraint axis;
379 if (!PyArg_ParseTuple(_args, "O&O&O&h",
Jack Jansen754d4a41995-11-14 10:41:55 +0000380 PyMac_GetPoint, &startPoint,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000381 PyMac_GetRect, &limitRect,
382 PyMac_GetRect, &slopRect,
383 &axis))
384 return NULL;
385 DragControl(_self->ob_itself,
Jack Jansen754d4a41995-11-14 10:41:55 +0000386 startPoint,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000387 &limitRect,
388 &slopRect,
389 axis);
390 Py_INCREF(Py_None);
391 _res = Py_None;
392 return _res;
393}
394
395static PyObject *CtlObj_TestControl(_self, _args)
396 ControlObject *_self;
397 PyObject *_args;
398{
399 PyObject *_res = NULL;
400 ControlPartCode _rv;
Jack Jansen21f96871998-02-20 16:02:09 +0000401 Point testPoint;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000402 if (!PyArg_ParseTuple(_args, "O&",
Jack Jansen21f96871998-02-20 16:02:09 +0000403 PyMac_GetPoint, &testPoint))
Jack Jansen7d0bc831995-06-09 20:56:31 +0000404 return NULL;
405 _rv = TestControl(_self->ob_itself,
Jack Jansen21f96871998-02-20 16:02:09 +0000406 testPoint);
407 _res = Py_BuildValue("h",
408 _rv);
409 return _res;
410}
411
412static PyObject *CtlObj_HandleControlKey(_self, _args)
413 ControlObject *_self;
414 PyObject *_args;
415{
416 PyObject *_res = NULL;
417 SInt16 _rv;
418 SInt16 inKeyCode;
419 SInt16 inCharCode;
420 SInt16 inModifiers;
421 if (!PyArg_ParseTuple(_args, "hhh",
422 &inKeyCode,
423 &inCharCode,
424 &inModifiers))
425 return NULL;
426 _rv = HandleControlKey(_self->ob_itself,
427 inKeyCode,
428 inCharCode,
429 inModifiers);
Jack Jansen7d0bc831995-06-09 20:56:31 +0000430 _res = Py_BuildValue("h",
431 _rv);
432 return _res;
433}
434
435static PyObject *CtlObj_MoveControl(_self, _args)
436 ControlObject *_self;
437 PyObject *_args;
438{
439 PyObject *_res = NULL;
440 SInt16 h;
441 SInt16 v;
442 if (!PyArg_ParseTuple(_args, "hh",
443 &h,
444 &v))
445 return NULL;
446 MoveControl(_self->ob_itself,
447 h,
448 v);
449 Py_INCREF(Py_None);
450 _res = Py_None;
451 return _res;
452}
453
454static PyObject *CtlObj_SizeControl(_self, _args)
455 ControlObject *_self;
456 PyObject *_args;
457{
458 PyObject *_res = NULL;
459 SInt16 w;
460 SInt16 h;
461 if (!PyArg_ParseTuple(_args, "hh",
462 &w,
463 &h))
464 return NULL;
465 SizeControl(_self->ob_itself,
466 w,
467 h);
468 Py_INCREF(Py_None);
469 _res = Py_None;
470 return _res;
471}
472
Jack Jansenae8a68f1995-06-06 12:55:40 +0000473static PyObject *CtlObj_SetControlTitle(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000474 ControlObject *_self;
475 PyObject *_args;
476{
477 PyObject *_res = NULL;
478 Str255 title;
479 if (!PyArg_ParseTuple(_args, "O&",
480 PyMac_GetStr255, title))
481 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000482 SetControlTitle(_self->ob_itself,
483 title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000484 Py_INCREF(Py_None);
485 _res = Py_None;
486 return _res;
487}
488
Jack Jansenae8a68f1995-06-06 12:55:40 +0000489static PyObject *CtlObj_GetControlTitle(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000490 ControlObject *_self;
491 PyObject *_args;
492{
493 PyObject *_res = NULL;
494 Str255 title;
Jack Jansen41009001999-03-07 20:05:20 +0000495 if (!PyArg_ParseTuple(_args, ""))
Guido van Rossum17448e21995-01-30 11:53:55 +0000496 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000497 GetControlTitle(_self->ob_itself,
498 title);
Jack Jansen41009001999-03-07 20:05:20 +0000499 _res = Py_BuildValue("O&",
500 PyMac_BuildStr255, title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000501 return _res;
502}
503
Jack Jansenae8a68f1995-06-06 12:55:40 +0000504static PyObject *CtlObj_GetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000505 ControlObject *_self;
506 PyObject *_args;
507{
508 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000509 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000510 if (!PyArg_ParseTuple(_args, ""))
511 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000512 _rv = GetControlValue(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000513 _res = Py_BuildValue("h",
514 _rv);
515 return _res;
516}
517
Jack Jansen7d0bc831995-06-09 20:56:31 +0000518static PyObject *CtlObj_SetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000519 ControlObject *_self;
520 PyObject *_args;
521{
522 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000523 SInt16 newValue;
Guido van Rossum17448e21995-01-30 11:53:55 +0000524 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000525 &newValue))
Guido van Rossum17448e21995-01-30 11:53:55 +0000526 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000527 SetControlValue(_self->ob_itself,
528 newValue);
Guido van Rossum17448e21995-01-30 11:53:55 +0000529 Py_INCREF(Py_None);
530 _res = Py_None;
531 return _res;
532}
533
Jack Jansenae8a68f1995-06-06 12:55:40 +0000534static PyObject *CtlObj_GetControlMinimum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000535 ControlObject *_self;
536 PyObject *_args;
537{
538 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000539 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000540 if (!PyArg_ParseTuple(_args, ""))
541 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000542 _rv = GetControlMinimum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000543 _res = Py_BuildValue("h",
544 _rv);
545 return _res;
546}
547
Jack Jansen7d0bc831995-06-09 20:56:31 +0000548static PyObject *CtlObj_SetControlMinimum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000549 ControlObject *_self;
550 PyObject *_args;
551{
552 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000553 SInt16 newMinimum;
Guido van Rossum17448e21995-01-30 11:53:55 +0000554 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000555 &newMinimum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000556 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000557 SetControlMinimum(_self->ob_itself,
558 newMinimum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000559 Py_INCREF(Py_None);
560 _res = Py_None;
561 return _res;
562}
563
Jack Jansenae8a68f1995-06-06 12:55:40 +0000564static PyObject *CtlObj_GetControlMaximum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000565 ControlObject *_self;
566 PyObject *_args;
567{
568 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000569 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000570 if (!PyArg_ParseTuple(_args, ""))
571 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000572 _rv = GetControlMaximum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000573 _res = Py_BuildValue("h",
574 _rv);
575 return _res;
576}
577
Jack Jansen7d0bc831995-06-09 20:56:31 +0000578static PyObject *CtlObj_SetControlMaximum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000579 ControlObject *_self;
580 PyObject *_args;
581{
582 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000583 SInt16 newMaximum;
584 if (!PyArg_ParseTuple(_args, "h",
585 &newMaximum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000586 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000587 SetControlMaximum(_self->ob_itself,
588 newMaximum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000589 Py_INCREF(Py_None);
590 _res = Py_None;
591 return _res;
592}
593
Jack Jansena05ac601999-12-12 21:41:51 +0000594static PyObject *CtlObj_GetControlViewSize(_self, _args)
595 ControlObject *_self;
596 PyObject *_args;
597{
598 PyObject *_res = NULL;
599 SInt32 _rv;
600 if (!PyArg_ParseTuple(_args, ""))
601 return NULL;
602 _rv = GetControlViewSize(_self->ob_itself);
603 _res = Py_BuildValue("l",
604 _rv);
605 return _res;
606}
607
608static PyObject *CtlObj_SetControlViewSize(_self, _args)
609 ControlObject *_self;
610 PyObject *_args;
611{
612 PyObject *_res = NULL;
613 SInt32 newViewSize;
614 if (!PyArg_ParseTuple(_args, "l",
615 &newViewSize))
616 return NULL;
617 SetControlViewSize(_self->ob_itself,
618 newViewSize);
619 Py_INCREF(Py_None);
620 _res = Py_None;
621 return _res;
622}
623
624static PyObject *CtlObj_GetControl32BitValue(_self, _args)
625 ControlObject *_self;
626 PyObject *_args;
627{
628 PyObject *_res = NULL;
629 SInt32 _rv;
630 if (!PyArg_ParseTuple(_args, ""))
631 return NULL;
632 _rv = GetControl32BitValue(_self->ob_itself);
633 _res = Py_BuildValue("l",
634 _rv);
635 return _res;
636}
637
638static PyObject *CtlObj_SetControl32BitValue(_self, _args)
639 ControlObject *_self;
640 PyObject *_args;
641{
642 PyObject *_res = NULL;
643 SInt32 newValue;
644 if (!PyArg_ParseTuple(_args, "l",
645 &newValue))
646 return NULL;
647 SetControl32BitValue(_self->ob_itself,
648 newValue);
649 Py_INCREF(Py_None);
650 _res = Py_None;
651 return _res;
652}
653
654static PyObject *CtlObj_GetControl32BitMaximum(_self, _args)
655 ControlObject *_self;
656 PyObject *_args;
657{
658 PyObject *_res = NULL;
659 SInt32 _rv;
660 if (!PyArg_ParseTuple(_args, ""))
661 return NULL;
662 _rv = GetControl32BitMaximum(_self->ob_itself);
663 _res = Py_BuildValue("l",
664 _rv);
665 return _res;
666}
667
668static PyObject *CtlObj_SetControl32BitMaximum(_self, _args)
669 ControlObject *_self;
670 PyObject *_args;
671{
672 PyObject *_res = NULL;
673 SInt32 newMaximum;
674 if (!PyArg_ParseTuple(_args, "l",
675 &newMaximum))
676 return NULL;
677 SetControl32BitMaximum(_self->ob_itself,
678 newMaximum);
679 Py_INCREF(Py_None);
680 _res = Py_None;
681 return _res;
682}
683
684static PyObject *CtlObj_GetControl32BitMinimum(_self, _args)
685 ControlObject *_self;
686 PyObject *_args;
687{
688 PyObject *_res = NULL;
689 SInt32 _rv;
690 if (!PyArg_ParseTuple(_args, ""))
691 return NULL;
692 _rv = GetControl32BitMinimum(_self->ob_itself);
693 _res = Py_BuildValue("l",
694 _rv);
695 return _res;
696}
697
698static PyObject *CtlObj_SetControl32BitMinimum(_self, _args)
699 ControlObject *_self;
700 PyObject *_args;
701{
702 PyObject *_res = NULL;
703 SInt32 newMinimum;
704 if (!PyArg_ParseTuple(_args, "l",
705 &newMinimum))
706 return NULL;
707 SetControl32BitMinimum(_self->ob_itself,
708 newMinimum);
709 Py_INCREF(Py_None);
710 _res = Py_None;
711 return _res;
712}
713
714static PyObject *CtlObj_IsValidControlHandle(_self, _args)
715 ControlObject *_self;
716 PyObject *_args;
717{
718 PyObject *_res = NULL;
719 Boolean _rv;
720 if (!PyArg_ParseTuple(_args, ""))
721 return NULL;
722 _rv = IsValidControlHandle(_self->ob_itself);
723 _res = Py_BuildValue("b",
724 _rv);
725 return _res;
726}
727
728static PyObject *CtlObj_RemoveControlProperty(_self, _args)
729 ControlObject *_self;
730 PyObject *_args;
731{
732 PyObject *_res = NULL;
Jack Jansenabc411b2000-03-20 16:09:09 +0000733 OSStatus _rv;
Jack Jansena05ac601999-12-12 21:41:51 +0000734 OSType propertyCreator;
735 OSType propertyTag;
736 if (!PyArg_ParseTuple(_args, "O&O&",
737 PyMac_GetOSType, &propertyCreator,
738 PyMac_GetOSType, &propertyTag))
739 return NULL;
Jack Jansenabc411b2000-03-20 16:09:09 +0000740 _rv = RemoveControlProperty(_self->ob_itself,
741 propertyCreator,
742 propertyTag);
743 _res = Py_BuildValue("l",
744 _rv);
Jack Jansena05ac601999-12-12 21:41:51 +0000745 return _res;
746}
747
748static PyObject *CtlObj_GetControlRegion(_self, _args)
749 ControlObject *_self;
750 PyObject *_args;
751{
752 PyObject *_res = NULL;
Jack Jansenabc411b2000-03-20 16:09:09 +0000753 OSStatus _rv;
Jack Jansena05ac601999-12-12 21:41:51 +0000754 ControlPartCode inPart;
755 RgnHandle outRegion;
756 if (!PyArg_ParseTuple(_args, "hO&",
757 &inPart,
758 ResObj_Convert, &outRegion))
759 return NULL;
Jack Jansenabc411b2000-03-20 16:09:09 +0000760 _rv = GetControlRegion(_self->ob_itself,
761 inPart,
762 outRegion);
763 _res = Py_BuildValue("l",
764 _rv);
Jack Jansena05ac601999-12-12 21:41:51 +0000765 return _res;
766}
767
Jack Jansen7d0bc831995-06-09 20:56:31 +0000768static PyObject *CtlObj_GetControlVariant(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000769 ControlObject *_self;
770 PyObject *_args;
771{
772 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000773 ControlVariant _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000774 if (!PyArg_ParseTuple(_args, ""))
775 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000776 _rv = GetControlVariant(_self->ob_itself);
777 _res = Py_BuildValue("h",
Guido van Rossum17448e21995-01-30 11:53:55 +0000778 _rv);
779 return _res;
780}
781
Jack Jansen7d0bc831995-06-09 20:56:31 +0000782static PyObject *CtlObj_SetControlReference(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000783 ControlObject *_self;
784 PyObject *_args;
785{
786 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000787 SInt32 data;
788 if (!PyArg_ParseTuple(_args, "l",
789 &data))
Guido van Rossum17448e21995-01-30 11:53:55 +0000790 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000791 SetControlReference(_self->ob_itself,
792 data);
Guido van Rossum17448e21995-01-30 11:53:55 +0000793 Py_INCREF(Py_None);
794 _res = Py_None;
795 return _res;
796}
797
Jack Jansen7d0bc831995-06-09 20:56:31 +0000798static PyObject *CtlObj_GetControlReference(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000799 ControlObject *_self;
800 PyObject *_args;
801{
802 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000803 SInt32 _rv;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000804 if (!PyArg_ParseTuple(_args, ""))
805 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000806 _rv = GetControlReference(_self->ob_itself);
807 _res = Py_BuildValue("l",
Guido van Rossum17448e21995-01-30 11:53:55 +0000808 _rv);
809 return _res;
810}
811
Jack Jansenc7fefed1997-08-15 14:32:18 +0000812static PyObject *CtlObj_GetAuxiliaryControlRecord(_self, _args)
813 ControlObject *_self;
814 PyObject *_args;
815{
816 PyObject *_res = NULL;
817 Boolean _rv;
818 AuxCtlHandle acHndl;
819 if (!PyArg_ParseTuple(_args, ""))
820 return NULL;
821 _rv = GetAuxiliaryControlRecord(_self->ob_itself,
822 &acHndl);
823 _res = Py_BuildValue("bO&",
824 _rv,
825 ResObj_New, acHndl);
826 return _res;
827}
828
829static PyObject *CtlObj_SetControlColor(_self, _args)
830 ControlObject *_self;
831 PyObject *_args;
832{
833 PyObject *_res = NULL;
834 CCTabHandle newColorTable;
835 if (!PyArg_ParseTuple(_args, "O&",
836 ResObj_Convert, &newColorTable))
837 return NULL;
838 SetControlColor(_self->ob_itself,
839 newColorTable);
840 Py_INCREF(Py_None);
841 _res = Py_None;
842 return _res;
843}
844
Jack Jansen21f96871998-02-20 16:02:09 +0000845static PyObject *CtlObj_SendControlMessage(_self, _args)
846 ControlObject *_self;
847 PyObject *_args;
848{
849 PyObject *_res = NULL;
850 SInt32 _rv;
851 SInt16 inMessage;
852 SInt32 inParam;
853 if (!PyArg_ParseTuple(_args, "hl",
854 &inMessage,
855 &inParam))
856 return NULL;
857 _rv = SendControlMessage(_self->ob_itself,
858 inMessage,
859 inParam);
860 _res = Py_BuildValue("l",
861 _rv);
862 return _res;
863}
864
865static PyObject *CtlObj_EmbedControl(_self, _args)
866 ControlObject *_self;
867 PyObject *_args;
868{
869 PyObject *_res = NULL;
870 OSErr _err;
871 ControlHandle inContainer;
872 if (!PyArg_ParseTuple(_args, "O&",
873 CtlObj_Convert, &inContainer))
874 return NULL;
875 _err = EmbedControl(_self->ob_itself,
876 inContainer);
877 if (_err != noErr) return PyMac_Error(_err);
878 Py_INCREF(Py_None);
879 _res = Py_None;
880 return _res;
881}
882
883static PyObject *CtlObj_AutoEmbedControl(_self, _args)
884 ControlObject *_self;
885 PyObject *_args;
886{
887 PyObject *_res = NULL;
888 OSErr _err;
889 WindowPtr inWindow;
890 if (!PyArg_ParseTuple(_args, "O&",
891 WinObj_Convert, &inWindow))
892 return NULL;
893 _err = AutoEmbedControl(_self->ob_itself,
894 inWindow);
895 if (_err != noErr) return PyMac_Error(_err);
896 Py_INCREF(Py_None);
897 _res = Py_None;
898 return _res;
899}
900
901static PyObject *CtlObj_GetSuperControl(_self, _args)
902 ControlObject *_self;
903 PyObject *_args;
904{
905 PyObject *_res = NULL;
906 OSErr _err;
907 ControlHandle outParent;
908 if (!PyArg_ParseTuple(_args, ""))
909 return NULL;
910 _err = GetSuperControl(_self->ob_itself,
911 &outParent);
912 if (_err != noErr) return PyMac_Error(_err);
913 _res = Py_BuildValue("O&",
914 CtlObj_WhichControl, outParent);
915 return _res;
916}
917
918static PyObject *CtlObj_CountSubControls(_self, _args)
919 ControlObject *_self;
920 PyObject *_args;
921{
922 PyObject *_res = NULL;
923 OSErr _err;
Jack Jansen24c35311999-12-09 22:49:51 +0000924 UInt16 outNumChildren;
Jack Jansen21f96871998-02-20 16:02:09 +0000925 if (!PyArg_ParseTuple(_args, ""))
926 return NULL;
927 _err = CountSubControls(_self->ob_itself,
928 &outNumChildren);
929 if (_err != noErr) return PyMac_Error(_err);
930 _res = Py_BuildValue("h",
931 outNumChildren);
932 return _res;
933}
934
935static PyObject *CtlObj_GetIndexedSubControl(_self, _args)
936 ControlObject *_self;
937 PyObject *_args;
938{
939 PyObject *_res = NULL;
940 OSErr _err;
Jack Jansen24c35311999-12-09 22:49:51 +0000941 UInt16 inIndex;
Jack Jansen21f96871998-02-20 16:02:09 +0000942 ControlHandle outSubControl;
943 if (!PyArg_ParseTuple(_args, "h",
944 &inIndex))
945 return NULL;
946 _err = GetIndexedSubControl(_self->ob_itself,
947 inIndex,
948 &outSubControl);
949 if (_err != noErr) return PyMac_Error(_err);
950 _res = Py_BuildValue("O&",
951 CtlObj_WhichControl, outSubControl);
952 return _res;
953}
954
955static PyObject *CtlObj_SetControlSupervisor(_self, _args)
956 ControlObject *_self;
957 PyObject *_args;
958{
959 PyObject *_res = NULL;
960 OSErr _err;
961 ControlHandle inBoss;
962 if (!PyArg_ParseTuple(_args, "O&",
963 CtlObj_Convert, &inBoss))
964 return NULL;
965 _err = SetControlSupervisor(_self->ob_itself,
966 inBoss);
967 if (_err != noErr) return PyMac_Error(_err);
968 Py_INCREF(Py_None);
969 _res = Py_None;
970 return _res;
971}
972
973static PyObject *CtlObj_GetControlFeatures(_self, _args)
974 ControlObject *_self;
975 PyObject *_args;
976{
977 PyObject *_res = NULL;
978 OSErr _err;
979 UInt32 outFeatures;
980 if (!PyArg_ParseTuple(_args, ""))
981 return NULL;
982 _err = GetControlFeatures(_self->ob_itself,
983 &outFeatures);
984 if (_err != noErr) return PyMac_Error(_err);
985 _res = Py_BuildValue("l",
986 outFeatures);
987 return _res;
988}
989
990static PyObject *CtlObj_GetControlDataSize(_self, _args)
991 ControlObject *_self;
992 PyObject *_args;
993{
994 PyObject *_res = NULL;
995 OSErr _err;
996 ControlPartCode inPart;
997 ResType inTagName;
998 Size outMaxSize;
999 if (!PyArg_ParseTuple(_args, "hO&",
1000 &inPart,
1001 PyMac_GetOSType, &inTagName))
1002 return NULL;
1003 _err = GetControlDataSize(_self->ob_itself,
1004 inPart,
1005 inTagName,
1006 &outMaxSize);
1007 if (_err != noErr) return PyMac_Error(_err);
1008 _res = Py_BuildValue("l",
1009 outMaxSize);
1010 return _res;
1011}
1012
Jack Jansen5d56f4b1995-06-18 20:16:33 +00001013static PyObject *CtlObj_as_Resource(_self, _args)
1014 ControlObject *_self;
1015 PyObject *_args;
1016{
1017 PyObject *_res = NULL;
Jack Jansena1a0fef1999-12-23 14:32:06 +00001018 Handle _rv;
1019 if (!PyArg_ParseTuple(_args, ""))
1020 return NULL;
1021 _rv = as_Resource(_self->ob_itself);
1022 _res = Py_BuildValue("O&",
1023 ResObj_New, _rv);
1024 return _res;
Jack Jansen5d56f4b1995-06-18 20:16:33 +00001025}
1026
Jack Jansen1a7d5b12000-03-21 16:25:23 +00001027static PyObject *CtlObj_GetControlRect(_self, _args)
1028 ControlObject *_self;
1029 PyObject *_args;
1030{
1031 PyObject *_res = NULL;
1032 Rect rect;
1033 if (!PyArg_ParseTuple(_args, ""))
1034 return NULL;
1035 GetControlRect(_self->ob_itself,
1036 &rect);
1037 _res = Py_BuildValue("O&",
1038 PyMac_BuildRect, &rect);
1039 return _res;
1040}
1041
Jack Jansencfb60ee1996-10-01 10:46:46 +00001042static PyObject *CtlObj_DisposeControl(_self, _args)
1043 ControlObject *_self;
1044 PyObject *_args;
1045{
1046 PyObject *_res = NULL;
1047
1048 if (!PyArg_ParseTuple(_args, ""))
1049 return NULL;
1050 if ( _self->ob_itself ) {
Jack Jansen85ae4a81997-04-08 15:26:03 +00001051 SetControlReference(_self->ob_itself, (long)0); /* Make it forget about us */
Jack Jansencfb60ee1996-10-01 10:46:46 +00001052 DisposeControl(_self->ob_itself);
1053 _self->ob_itself = NULL;
1054 }
1055 Py_INCREF(Py_None);
1056 _res = Py_None;
1057 return _res;
1058
1059}
1060
Jack Jansen848250c1998-05-28 14:20:09 +00001061static PyObject *CtlObj_TrackControl(_self, _args)
1062 ControlObject *_self;
1063 PyObject *_args;
1064{
1065 PyObject *_res = NULL;
1066
1067 ControlPartCode _rv;
1068 Point startPoint;
1069 ControlActionUPP upp = 0;
1070 PyObject *callback = 0;
1071
1072 if (!PyArg_ParseTuple(_args, "O&|O",
1073 PyMac_GetPoint, &startPoint, &callback))
1074 return NULL;
1075 if (callback && callback != Py_None) {
1076 if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
1077 upp = (ControlActionUPP)-1;
1078 else {
1079 settrackfunc(callback);
1080 upp = mytracker_upp;
1081 }
1082 }
1083 _rv = TrackControl(_self->ob_itself,
1084 startPoint,
1085 upp);
1086 clrtrackfunc();
1087 _res = Py_BuildValue("h",
1088 _rv);
1089 return _res;
1090
1091}
1092
Jack Jansen24c35311999-12-09 22:49:51 +00001093static PyObject *CtlObj_HandleControlClick(_self, _args)
1094 ControlObject *_self;
1095 PyObject *_args;
1096{
1097 PyObject *_res = NULL;
1098
1099 ControlPartCode _rv;
1100 Point startPoint;
1101 SInt16 modifiers;
1102 ControlActionUPP upp = 0;
1103 PyObject *callback = 0;
1104
1105 if (!PyArg_ParseTuple(_args, "O&h|O",
1106 PyMac_GetPoint, &startPoint,
1107 &modifiers,
1108 &callback))
1109 return NULL;
1110 if (callback && callback != Py_None) {
1111 if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
1112 upp = (ControlActionUPP)-1;
1113 else {
1114 settrackfunc(callback);
1115 upp = mytracker_upp;
1116 }
1117 }
1118 _rv = HandleControlClick(_self->ob_itself,
1119 startPoint,
1120 modifiers,
1121 upp);
1122 clrtrackfunc();
1123 _res = Py_BuildValue("h",
1124 _rv);
1125 return _res;
1126
1127}
1128
1129static PyObject *CtlObj_SetControlData(_self, _args)
1130 ControlObject *_self;
1131 PyObject *_args;
1132{
1133 PyObject *_res = NULL;
1134
1135 OSErr _err;
1136 ControlPartCode inPart;
1137 ResType inTagName;
1138 Size bufferSize;
1139 Ptr buffer;
1140
1141 if (!PyArg_ParseTuple(_args, "hO&s#",
1142 &inPart,
1143 PyMac_GetOSType, &inTagName,
1144 &buffer, &bufferSize))
1145 return NULL;
1146
1147 _err = SetControlData(_self->ob_itself,
1148 inPart,
1149 inTagName,
1150 bufferSize,
1151 buffer);
1152
1153 if (_err != noErr)
1154 return PyMac_Error(_err);
1155 _res = Py_None;
1156 return _res;
1157
1158}
1159
1160static PyObject *CtlObj_GetControlData(_self, _args)
1161 ControlObject *_self;
1162 PyObject *_args;
1163{
1164 PyObject *_res = NULL;
1165
1166 OSErr _err;
1167 ControlPartCode inPart;
1168 ResType inTagName;
1169 Size bufferSize;
1170 Ptr buffer;
1171 Size outSize;
1172
1173 if (!PyArg_ParseTuple(_args, "hO&",
1174 &inPart,
1175 PyMac_GetOSType, &inTagName))
1176 return NULL;
1177
1178 /* allocate a buffer for the data */
1179 _err = GetControlDataSize(_self->ob_itself,
1180 inPart,
1181 inTagName,
1182 &bufferSize);
1183 if (_err != noErr)
1184 return PyMac_Error(_err);
1185 buffer = PyMem_NEW(char, bufferSize);
1186 if (buffer == NULL)
1187 return PyErr_NoMemory();
1188
1189 _err = GetControlData(_self->ob_itself,
1190 inPart,
1191 inTagName,
1192 bufferSize,
1193 buffer,
1194 &outSize);
1195
1196 if (_err != noErr) {
1197 PyMem_DEL(buffer);
1198 return PyMac_Error(_err);
1199 }
1200 _res = Py_BuildValue("s#", buffer, outSize);
1201 PyMem_DEL(buffer);
1202 return _res;
1203
1204}
1205
Jack Jansen1f9249c1999-12-19 00:05:50 +00001206static PyObject *CtlObj_SetControlDataHandle(_self, _args)
1207 ControlObject *_self;
1208 PyObject *_args;
1209{
1210 PyObject *_res = NULL;
1211
1212 OSErr _err;
1213 ControlPartCode inPart;
1214 ResType inTagName;
1215 Handle buffer;
1216
1217 if (!PyArg_ParseTuple(_args, "hO&O&",
1218 &inPart,
1219 PyMac_GetOSType, &inTagName,
Jack Jansenb9247d31999-12-23 23:06:07 +00001220 OptResObj_Convert, &buffer))
Jack Jansen1f9249c1999-12-19 00:05:50 +00001221 return NULL;
1222
1223 _err = SetControlData(_self->ob_itself,
1224 inPart,
1225 inTagName,
1226 sizeof(buffer),
Jack Jansenf7ac1d31999-12-29 12:37:22 +00001227 (Ptr)&buffer);
Jack Jansen1f9249c1999-12-19 00:05:50 +00001228
1229 if (_err != noErr)
1230 return PyMac_Error(_err);
1231 _res = Py_None;
1232 return _res;
1233
1234}
1235
1236static PyObject *CtlObj_GetControlDataHandle(_self, _args)
1237 ControlObject *_self;
1238 PyObject *_args;
1239{
1240 PyObject *_res = NULL;
1241
1242 OSErr _err;
1243 ControlPartCode inPart;
1244 ResType inTagName;
1245 Size bufferSize;
1246 Handle hdl;
1247
1248 if (!PyArg_ParseTuple(_args, "hO&",
1249 &inPart,
1250 PyMac_GetOSType, &inTagName))
1251 return NULL;
1252
1253 /* Check it is handle-sized */
1254 _err = GetControlDataSize(_self->ob_itself,
1255 inPart,
1256 inTagName,
1257 &bufferSize);
1258 if (_err != noErr)
1259 return PyMac_Error(_err);
1260 if (bufferSize != sizeof(Handle)) {
1261 PyErr_SetString(Ctl_Error, "GetControlDataSize() != sizeof(Handle)");
1262 return NULL;
1263 }
1264
1265 _err = GetControlData(_self->ob_itself,
1266 inPart,
1267 inTagName,
1268 sizeof(Handle),
1269 (Ptr)&hdl,
1270 &bufferSize);
1271
1272 if (_err != noErr) {
1273 return PyMac_Error(_err);
1274 }
1275 return Py_BuildValue("O&", OptResObj_New, hdl);
1276
1277}
1278
Jack Jansenabc411b2000-03-20 16:09:09 +00001279static PyObject *CtlObj_SetControlDataCallback(_self, _args)
1280 ControlObject *_self;
1281 PyObject *_args;
1282{
1283 PyObject *_res = NULL;
1284
1285 OSErr _err;
1286 ControlPartCode inPart;
1287 ResType inTagName;
1288 PyObject *callback;
1289 UniversalProcPtr *c_callback;
1290
1291 if (!PyArg_ParseTuple(_args, "hO&O",
1292 &inPart,
1293 PyMac_GetOSType, &inTagName,
1294 &callback))
1295 return NULL;
1296
1297 if ( setcallback(_self, inTagName, callback, &c_callback) < 0 )
1298 return NULL;
1299 _err = SetControlData(_self->ob_itself,
1300 inPart,
1301 inTagName,
1302 sizeof(c_callback),
1303 (Ptr)&c_callback);
1304
1305 if (_err != noErr)
1306 return PyMac_Error(_err);
1307 _res = Py_None;
1308 return _res;
1309
1310}
1311
Jack Jansen4c704131998-06-19 13:35:14 +00001312static PyObject *CtlObj_GetPopupData(_self, _args)
1313 ControlObject *_self;
1314 PyObject *_args;
1315{
1316 PyObject *_res = NULL;
1317
1318 PopupPrivateDataHandle hdl;
1319
1320 if ( (*_self->ob_itself)->contrlData == NULL ) {
1321 PyErr_SetString(Ctl_Error, "No contrlData handle in control");
1322 return 0;
1323 }
1324 hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
1325 HLock((Handle)hdl);
1326 _res = Py_BuildValue("O&i", MenuObj_New, (*hdl)->mHandle, (int)(*hdl)->mID);
1327 HUnlock((Handle)hdl);
1328 return _res;
1329
1330}
1331
1332static PyObject *CtlObj_SetPopupData(_self, _args)
1333 ControlObject *_self;
1334 PyObject *_args;
1335{
1336 PyObject *_res = NULL;
1337
1338 PopupPrivateDataHandle hdl;
1339 MenuHandle mHandle;
1340 short mID;
1341
1342 if (!PyArg_ParseTuple(_args, "O&h", MenuObj_Convert, &mHandle, &mID) )
1343 return 0;
1344 if ( (*_self->ob_itself)->contrlData == NULL ) {
1345 PyErr_SetString(Ctl_Error, "No contrlData handle in control");
1346 return 0;
1347 }
1348 hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
1349 (*hdl)->mHandle = mHandle;
1350 (*hdl)->mID = mID;
1351 Py_INCREF(Py_None);
1352 return Py_None;
1353
1354}
1355
Guido van Rossum17448e21995-01-30 11:53:55 +00001356static PyMethodDef CtlObj_methods[] = {
Jack Jansen21f96871998-02-20 16:02:09 +00001357 {"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1,
1358 "(ControlPartCode hiliteState) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001359 {"ShowControl", (PyCFunction)CtlObj_ShowControl, 1,
1360 "() -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001361 {"HideControl", (PyCFunction)CtlObj_HideControl, 1,
1362 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001363 {"IsControlActive", (PyCFunction)CtlObj_IsControlActive, 1,
1364 "() -> (Boolean _rv)"},
1365 {"IsControlVisible", (PyCFunction)CtlObj_IsControlVisible, 1,
1366 "() -> (Boolean _rv)"},
1367 {"ActivateControl", (PyCFunction)CtlObj_ActivateControl, 1,
1368 "() -> None"},
1369 {"DeactivateControl", (PyCFunction)CtlObj_DeactivateControl, 1,
1370 "() -> None"},
1371 {"SetControlVisibility", (PyCFunction)CtlObj_SetControlVisibility, 1,
1372 "(Boolean inIsVisible, Boolean inDoDraw) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001373 {"Draw1Control", (PyCFunction)CtlObj_Draw1Control, 1,
1374 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001375 {"GetBestControlRect", (PyCFunction)CtlObj_GetBestControlRect, 1,
1376 "() -> (Rect outRect, SInt16 outBaseLineOffset)"},
1377 {"SetControlFontStyle", (PyCFunction)CtlObj_SetControlFontStyle, 1,
1378 "(ControlFontStyleRec inStyle) -> None"},
1379 {"DrawControlInCurrentPort", (PyCFunction)CtlObj_DrawControlInCurrentPort, 1,
1380 "() -> None"},
1381 {"SetUpControlBackground", (PyCFunction)CtlObj_SetUpControlBackground, 1,
1382 "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +00001383 {"SetUpControlTextColor", (PyCFunction)CtlObj_SetUpControlTextColor, 1,
1384 "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001385 {"DragControl", (PyCFunction)CtlObj_DragControl, 1,
Jack Jansen754d4a41995-11-14 10:41:55 +00001386 "(Point startPoint, Rect limitRect, Rect slopRect, DragConstraint axis) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001387 {"TestControl", (PyCFunction)CtlObj_TestControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001388 "(Point testPoint) -> (ControlPartCode _rv)"},
1389 {"HandleControlKey", (PyCFunction)CtlObj_HandleControlKey, 1,
1390 "(SInt16 inKeyCode, SInt16 inCharCode, SInt16 inModifiers) -> (SInt16 _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001391 {"MoveControl", (PyCFunction)CtlObj_MoveControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001392 "(SInt16 h, SInt16 v) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001393 {"SizeControl", (PyCFunction)CtlObj_SizeControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001394 "(SInt16 w, SInt16 h) -> None"},
1395 {"SetControlTitle", (PyCFunction)CtlObj_SetControlTitle, 1,
1396 "(Str255 title) -> None"},
1397 {"GetControlTitle", (PyCFunction)CtlObj_GetControlTitle, 1,
Jack Jansen41009001999-03-07 20:05:20 +00001398 "() -> (Str255 title)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001399 {"GetControlValue", (PyCFunction)CtlObj_GetControlValue, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001400 "() -> (SInt16 _rv)"},
1401 {"SetControlValue", (PyCFunction)CtlObj_SetControlValue, 1,
1402 "(SInt16 newValue) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001403 {"GetControlMinimum", (PyCFunction)CtlObj_GetControlMinimum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001404 "() -> (SInt16 _rv)"},
1405 {"SetControlMinimum", (PyCFunction)CtlObj_SetControlMinimum, 1,
1406 "(SInt16 newMinimum) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001407 {"GetControlMaximum", (PyCFunction)CtlObj_GetControlMaximum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001408 "() -> (SInt16 _rv)"},
1409 {"SetControlMaximum", (PyCFunction)CtlObj_SetControlMaximum, 1,
1410 "(SInt16 newMaximum) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +00001411 {"GetControlViewSize", (PyCFunction)CtlObj_GetControlViewSize, 1,
1412 "() -> (SInt32 _rv)"},
1413 {"SetControlViewSize", (PyCFunction)CtlObj_SetControlViewSize, 1,
1414 "(SInt32 newViewSize) -> None"},
1415 {"GetControl32BitValue", (PyCFunction)CtlObj_GetControl32BitValue, 1,
1416 "() -> (SInt32 _rv)"},
1417 {"SetControl32BitValue", (PyCFunction)CtlObj_SetControl32BitValue, 1,
1418 "(SInt32 newValue) -> None"},
1419 {"GetControl32BitMaximum", (PyCFunction)CtlObj_GetControl32BitMaximum, 1,
1420 "() -> (SInt32 _rv)"},
1421 {"SetControl32BitMaximum", (PyCFunction)CtlObj_SetControl32BitMaximum, 1,
1422 "(SInt32 newMaximum) -> None"},
1423 {"GetControl32BitMinimum", (PyCFunction)CtlObj_GetControl32BitMinimum, 1,
1424 "() -> (SInt32 _rv)"},
1425 {"SetControl32BitMinimum", (PyCFunction)CtlObj_SetControl32BitMinimum, 1,
1426 "(SInt32 newMinimum) -> None"},
1427 {"IsValidControlHandle", (PyCFunction)CtlObj_IsValidControlHandle, 1,
1428 "() -> (Boolean _rv)"},
1429 {"RemoveControlProperty", (PyCFunction)CtlObj_RemoveControlProperty, 1,
Jack Jansenabc411b2000-03-20 16:09:09 +00001430 "(OSType propertyCreator, OSType propertyTag) -> (OSStatus _rv)"},
Jack Jansena05ac601999-12-12 21:41:51 +00001431 {"GetControlRegion", (PyCFunction)CtlObj_GetControlRegion, 1,
Jack Jansenabc411b2000-03-20 16:09:09 +00001432 "(ControlPartCode inPart, RgnHandle outRegion) -> (OSStatus _rv)"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001433 {"GetControlVariant", (PyCFunction)CtlObj_GetControlVariant, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001434 "() -> (ControlVariant _rv)"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001435 {"SetControlReference", (PyCFunction)CtlObj_SetControlReference, 1,
1436 "(SInt32 data) -> None"},
1437 {"GetControlReference", (PyCFunction)CtlObj_GetControlReference, 1,
1438 "() -> (SInt32 _rv)"},
Jack Jansenc7fefed1997-08-15 14:32:18 +00001439 {"GetAuxiliaryControlRecord", (PyCFunction)CtlObj_GetAuxiliaryControlRecord, 1,
1440 "() -> (Boolean _rv, AuxCtlHandle acHndl)"},
1441 {"SetControlColor", (PyCFunction)CtlObj_SetControlColor, 1,
1442 "(CCTabHandle newColorTable) -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001443 {"SendControlMessage", (PyCFunction)CtlObj_SendControlMessage, 1,
1444 "(SInt16 inMessage, SInt32 inParam) -> (SInt32 _rv)"},
1445 {"EmbedControl", (PyCFunction)CtlObj_EmbedControl, 1,
1446 "(ControlHandle inContainer) -> None"},
1447 {"AutoEmbedControl", (PyCFunction)CtlObj_AutoEmbedControl, 1,
1448 "(WindowPtr inWindow) -> None"},
1449 {"GetSuperControl", (PyCFunction)CtlObj_GetSuperControl, 1,
1450 "() -> (ControlHandle outParent)"},
1451 {"CountSubControls", (PyCFunction)CtlObj_CountSubControls, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00001452 "() -> (UInt16 outNumChildren)"},
Jack Jansen21f96871998-02-20 16:02:09 +00001453 {"GetIndexedSubControl", (PyCFunction)CtlObj_GetIndexedSubControl, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00001454 "(UInt16 inIndex) -> (ControlHandle outSubControl)"},
Jack Jansen21f96871998-02-20 16:02:09 +00001455 {"SetControlSupervisor", (PyCFunction)CtlObj_SetControlSupervisor, 1,
1456 "(ControlHandle inBoss) -> None"},
1457 {"GetControlFeatures", (PyCFunction)CtlObj_GetControlFeatures, 1,
1458 "() -> (UInt32 outFeatures)"},
1459 {"GetControlDataSize", (PyCFunction)CtlObj_GetControlDataSize, 1,
1460 "(ControlPartCode inPart, ResType inTagName) -> (Size outMaxSize)"},
Jack Jansen5d56f4b1995-06-18 20:16:33 +00001461 {"as_Resource", (PyCFunction)CtlObj_as_Resource, 1,
Jack Jansena1a0fef1999-12-23 14:32:06 +00001462 "() -> (Handle _rv)"},
Jack Jansen1a7d5b12000-03-21 16:25:23 +00001463 {"GetControlRect", (PyCFunction)CtlObj_GetControlRect, 1,
1464 "() -> (Rect rect)"},
Jack Jansencfb60ee1996-10-01 10:46:46 +00001465 {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1,
1466 "() -> None"},
Jack Jansen848250c1998-05-28 14:20:09 +00001467 {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00001468 "(Point startPoint [,trackercallback]) -> (ControlPartCode _rv)"},
1469 {"HandleControlClick", (PyCFunction)CtlObj_HandleControlClick, 1,
1470 "(Point startPoint, Integer modifiers, [,trackercallback]) -> (ControlPartCode _rv)"},
1471 {"SetControlData", (PyCFunction)CtlObj_SetControlData, 1,
1472 "(stuff) -> None"},
1473 {"GetControlData", (PyCFunction)CtlObj_GetControlData, 1,
1474 "(part, type) -> String"},
Jack Jansen1f9249c1999-12-19 00:05:50 +00001475 {"SetControlDataHandle", (PyCFunction)CtlObj_SetControlDataHandle, 1,
1476 "(ResObj) -> None"},
1477 {"GetControlDataHandle", (PyCFunction)CtlObj_GetControlDataHandle, 1,
1478 "(part, type) -> ResObj"},
Jack Jansenabc411b2000-03-20 16:09:09 +00001479 {"SetControlDataCallback", (PyCFunction)CtlObj_SetControlDataCallback, 1,
1480 "(callbackfunc) -> None"},
Jack Jansen4c704131998-06-19 13:35:14 +00001481 {"GetPopupData", (PyCFunction)CtlObj_GetPopupData, 1,
1482 NULL},
1483 {"SetPopupData", (PyCFunction)CtlObj_SetPopupData, 1,
1484 NULL},
Guido van Rossum17448e21995-01-30 11:53:55 +00001485 {NULL, NULL, 0}
1486};
1487
1488PyMethodChain CtlObj_chain = { CtlObj_methods, NULL };
1489
1490static PyObject *CtlObj_getattr(self, name)
1491 ControlObject *self;
1492 char *name;
1493{
1494 return Py_FindMethodInChain(&CtlObj_chain, (PyObject *)self, name);
1495}
1496
1497#define CtlObj_setattr NULL
1498
Jack Jansen8387af61999-03-13 23:07:32 +00001499static int CtlObj_compare(self, other)
1500 ControlObject *self, *other;
1501{
1502 unsigned long v, w;
1503
1504 if (!CtlObj_Check((PyObject *)other))
1505 {
1506 v=(unsigned long)self;
1507 w=(unsigned long)other;
1508 }
1509 else
1510 {
1511 v=(unsigned long)self->ob_itself;
1512 w=(unsigned long)other->ob_itself;
1513 }
1514 if( v < w ) return -1;
1515 if( v > w ) return 1;
1516 return 0;
1517}
1518
1519#define CtlObj_repr NULL
1520
1521static long CtlObj_hash(self)
1522 ControlObject *self;
1523{
1524 return (long)self->ob_itself;
1525}
1526
Guido van Rossum17448e21995-01-30 11:53:55 +00001527PyTypeObject Control_Type = {
1528 PyObject_HEAD_INIT(&PyType_Type)
1529 0, /*ob_size*/
1530 "Control", /*tp_name*/
1531 sizeof(ControlObject), /*tp_basicsize*/
1532 0, /*tp_itemsize*/
1533 /* methods */
1534 (destructor) CtlObj_dealloc, /*tp_dealloc*/
1535 0, /*tp_print*/
1536 (getattrfunc) CtlObj_getattr, /*tp_getattr*/
1537 (setattrfunc) CtlObj_setattr, /*tp_setattr*/
Jack Jansen8387af61999-03-13 23:07:32 +00001538 (cmpfunc) CtlObj_compare, /*tp_compare*/
1539 (reprfunc) CtlObj_repr, /*tp_repr*/
1540 (PyNumberMethods *)0, /* tp_as_number */
1541 (PySequenceMethods *)0, /* tp_as_sequence */
1542 (PyMappingMethods *)0, /* tp_as_mapping */
1543 (hashfunc) CtlObj_hash, /*tp_hash*/
Guido van Rossum17448e21995-01-30 11:53:55 +00001544};
1545
1546/* -------------------- End object type Control --------------------- */
1547
1548
1549static PyObject *Ctl_NewControl(_self, _args)
1550 PyObject *_self;
1551 PyObject *_args;
1552{
1553 PyObject *_res = NULL;
1554 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001555 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00001556 Rect boundsRect;
Jack Jansen21f96871998-02-20 16:02:09 +00001557 Str255 controlTitle;
1558 Boolean initiallyVisible;
1559 SInt16 initialValue;
1560 SInt16 minimumValue;
1561 SInt16 maximumValue;
Jack Jansen7d0bc831995-06-09 20:56:31 +00001562 SInt16 procID;
Jack Jansen21f96871998-02-20 16:02:09 +00001563 SInt32 controlReference;
Guido van Rossum17448e21995-01-30 11:53:55 +00001564 if (!PyArg_ParseTuple(_args, "O&O&O&bhhhhl",
Jack Jansen21f96871998-02-20 16:02:09 +00001565 WinObj_Convert, &owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00001566 PyMac_GetRect, &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00001567 PyMac_GetStr255, controlTitle,
1568 &initiallyVisible,
1569 &initialValue,
1570 &minimumValue,
1571 &maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00001572 &procID,
Jack Jansen21f96871998-02-20 16:02:09 +00001573 &controlReference))
Guido van Rossum17448e21995-01-30 11:53:55 +00001574 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001575 _rv = NewControl(owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00001576 &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00001577 controlTitle,
1578 initiallyVisible,
1579 initialValue,
1580 minimumValue,
1581 maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00001582 procID,
Jack Jansen21f96871998-02-20 16:02:09 +00001583 controlReference);
Guido van Rossum17448e21995-01-30 11:53:55 +00001584 _res = Py_BuildValue("O&",
1585 CtlObj_New, _rv);
1586 return _res;
1587}
1588
1589static PyObject *Ctl_GetNewControl(_self, _args)
1590 PyObject *_self;
1591 PyObject *_args;
1592{
1593 PyObject *_res = NULL;
1594 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001595 SInt16 resourceID;
1596 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00001597 if (!PyArg_ParseTuple(_args, "hO&",
Jack Jansen21f96871998-02-20 16:02:09 +00001598 &resourceID,
1599 WinObj_Convert, &owningWindow))
Guido van Rossum17448e21995-01-30 11:53:55 +00001600 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001601 _rv = GetNewControl(resourceID,
1602 owningWindow);
Guido van Rossum17448e21995-01-30 11:53:55 +00001603 _res = Py_BuildValue("O&",
1604 CtlObj_New, _rv);
1605 return _res;
1606}
1607
Guido van Rossum17448e21995-01-30 11:53:55 +00001608static PyObject *Ctl_DrawControls(_self, _args)
1609 PyObject *_self;
1610 PyObject *_args;
1611{
1612 PyObject *_res = NULL;
1613 WindowPtr theWindow;
1614 if (!PyArg_ParseTuple(_args, "O&",
1615 WinObj_Convert, &theWindow))
1616 return NULL;
1617 DrawControls(theWindow);
1618 Py_INCREF(Py_None);
1619 _res = Py_None;
1620 return _res;
1621}
1622
Guido van Rossum17448e21995-01-30 11:53:55 +00001623static PyObject *Ctl_UpdateControls(_self, _args)
1624 PyObject *_self;
1625 PyObject *_args;
1626{
1627 PyObject *_res = NULL;
1628 WindowPtr theWindow;
Jack Jansen2b724171996-04-10 14:48:19 +00001629 RgnHandle updateRegion;
1630 if (!PyArg_ParseTuple(_args, "O&O&",
1631 WinObj_Convert, &theWindow,
1632 ResObj_Convert, &updateRegion))
Guido van Rossum17448e21995-01-30 11:53:55 +00001633 return NULL;
1634 UpdateControls(theWindow,
Jack Jansen2b724171996-04-10 14:48:19 +00001635 updateRegion);
Guido van Rossum17448e21995-01-30 11:53:55 +00001636 Py_INCREF(Py_None);
1637 _res = Py_None;
1638 return _res;
1639}
1640
1641static PyObject *Ctl_FindControl(_self, _args)
1642 PyObject *_self;
1643 PyObject *_args;
1644{
1645 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +00001646 ControlPartCode _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001647 Point testPoint;
Guido van Rossum17448e21995-01-30 11:53:55 +00001648 WindowPtr theWindow;
1649 ControlHandle theControl;
1650 if (!PyArg_ParseTuple(_args, "O&O&",
Jack Jansen21f96871998-02-20 16:02:09 +00001651 PyMac_GetPoint, &testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00001652 WinObj_Convert, &theWindow))
1653 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001654 _rv = FindControl(testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00001655 theWindow,
1656 &theControl);
1657 _res = Py_BuildValue("hO&",
1658 _rv,
1659 CtlObj_WhichControl, theControl);
1660 return _res;
1661}
1662
Jack Jansen21f96871998-02-20 16:02:09 +00001663static PyObject *Ctl_FindControlUnderMouse(_self, _args)
1664 PyObject *_self;
1665 PyObject *_args;
1666{
1667 PyObject *_res = NULL;
1668 ControlHandle _rv;
1669 Point inWhere;
1670 WindowPtr inWindow;
1671 SInt16 outPart;
1672 if (!PyArg_ParseTuple(_args, "O&O&",
1673 PyMac_GetPoint, &inWhere,
1674 WinObj_Convert, &inWindow))
1675 return NULL;
1676 _rv = FindControlUnderMouse(inWhere,
1677 inWindow,
1678 &outPart);
1679 _res = Py_BuildValue("O&h",
1680 CtlObj_New, _rv,
1681 outPart);
1682 return _res;
1683}
1684
1685static PyObject *Ctl_IdleControls(_self, _args)
1686 PyObject *_self;
1687 PyObject *_args;
1688{
1689 PyObject *_res = NULL;
1690 WindowPtr inWindow;
1691 if (!PyArg_ParseTuple(_args, "O&",
1692 WinObj_Convert, &inWindow))
1693 return NULL;
1694 IdleControls(inWindow);
1695 Py_INCREF(Py_None);
1696 _res = Py_None;
1697 return _res;
1698}
1699
1700static PyObject *Ctl_DumpControlHierarchy(_self, _args)
1701 PyObject *_self;
1702 PyObject *_args;
1703{
1704 PyObject *_res = NULL;
1705 OSErr _err;
1706 WindowPtr inWindow;
1707 FSSpec inDumpFile;
1708 if (!PyArg_ParseTuple(_args, "O&O&",
1709 WinObj_Convert, &inWindow,
1710 PyMac_GetFSSpec, &inDumpFile))
1711 return NULL;
1712 _err = DumpControlHierarchy(inWindow,
1713 &inDumpFile);
1714 if (_err != noErr) return PyMac_Error(_err);
1715 Py_INCREF(Py_None);
1716 _res = Py_None;
1717 return _res;
1718}
1719
1720static PyObject *Ctl_CreateRootControl(_self, _args)
1721 PyObject *_self;
1722 PyObject *_args;
1723{
1724 PyObject *_res = NULL;
1725 OSErr _err;
1726 WindowPtr inWindow;
1727 ControlHandle outControl;
1728 if (!PyArg_ParseTuple(_args, "O&",
1729 WinObj_Convert, &inWindow))
1730 return NULL;
1731 _err = CreateRootControl(inWindow,
1732 &outControl);
1733 if (_err != noErr) return PyMac_Error(_err);
1734 _res = Py_BuildValue("O&",
1735 CtlObj_WhichControl, outControl);
1736 return _res;
1737}
1738
1739static PyObject *Ctl_GetRootControl(_self, _args)
1740 PyObject *_self;
1741 PyObject *_args;
1742{
1743 PyObject *_res = NULL;
1744 OSErr _err;
1745 WindowPtr inWindow;
1746 ControlHandle outControl;
1747 if (!PyArg_ParseTuple(_args, "O&",
1748 WinObj_Convert, &inWindow))
1749 return NULL;
1750 _err = GetRootControl(inWindow,
1751 &outControl);
1752 if (_err != noErr) return PyMac_Error(_err);
1753 _res = Py_BuildValue("O&",
1754 CtlObj_WhichControl, outControl);
1755 return _res;
1756}
1757
1758static PyObject *Ctl_GetKeyboardFocus(_self, _args)
1759 PyObject *_self;
1760 PyObject *_args;
1761{
1762 PyObject *_res = NULL;
1763 OSErr _err;
1764 WindowPtr inWindow;
1765 ControlHandle outControl;
1766 if (!PyArg_ParseTuple(_args, "O&",
1767 WinObj_Convert, &inWindow))
1768 return NULL;
1769 _err = GetKeyboardFocus(inWindow,
1770 &outControl);
1771 if (_err != noErr) return PyMac_Error(_err);
1772 _res = Py_BuildValue("O&",
1773 CtlObj_WhichControl, outControl);
1774 return _res;
1775}
1776
1777static PyObject *Ctl_SetKeyboardFocus(_self, _args)
1778 PyObject *_self;
1779 PyObject *_args;
1780{
1781 PyObject *_res = NULL;
1782 OSErr _err;
1783 WindowPtr inWindow;
1784 ControlHandle inControl;
1785 ControlFocusPart inPart;
1786 if (!PyArg_ParseTuple(_args, "O&O&h",
1787 WinObj_Convert, &inWindow,
1788 CtlObj_Convert, &inControl,
1789 &inPart))
1790 return NULL;
1791 _err = SetKeyboardFocus(inWindow,
1792 inControl,
1793 inPart);
1794 if (_err != noErr) return PyMac_Error(_err);
1795 Py_INCREF(Py_None);
1796 _res = Py_None;
1797 return _res;
1798}
1799
1800static PyObject *Ctl_AdvanceKeyboardFocus(_self, _args)
1801 PyObject *_self;
1802 PyObject *_args;
1803{
1804 PyObject *_res = NULL;
1805 OSErr _err;
1806 WindowPtr inWindow;
1807 if (!PyArg_ParseTuple(_args, "O&",
1808 WinObj_Convert, &inWindow))
1809 return NULL;
1810 _err = AdvanceKeyboardFocus(inWindow);
1811 if (_err != noErr) return PyMac_Error(_err);
1812 Py_INCREF(Py_None);
1813 _res = Py_None;
1814 return _res;
1815}
1816
1817static PyObject *Ctl_ReverseKeyboardFocus(_self, _args)
1818 PyObject *_self;
1819 PyObject *_args;
1820{
1821 PyObject *_res = NULL;
1822 OSErr _err;
1823 WindowPtr inWindow;
1824 if (!PyArg_ParseTuple(_args, "O&",
1825 WinObj_Convert, &inWindow))
1826 return NULL;
1827 _err = ReverseKeyboardFocus(inWindow);
1828 if (_err != noErr) return PyMac_Error(_err);
1829 Py_INCREF(Py_None);
1830 _res = Py_None;
1831 return _res;
1832}
1833
1834static PyObject *Ctl_ClearKeyboardFocus(_self, _args)
1835 PyObject *_self;
1836 PyObject *_args;
1837{
1838 PyObject *_res = NULL;
1839 OSErr _err;
1840 WindowPtr inWindow;
1841 if (!PyArg_ParseTuple(_args, "O&",
1842 WinObj_Convert, &inWindow))
1843 return NULL;
1844 _err = ClearKeyboardFocus(inWindow);
1845 if (_err != noErr) return PyMac_Error(_err);
1846 Py_INCREF(Py_None);
1847 _res = Py_None;
1848 return _res;
1849}
1850
Jack Jansene0581891999-02-07 14:02:03 +00001851static PyObject *Ctl_as_Control(_self, _args)
1852 PyObject *_self;
1853 PyObject *_args;
1854{
1855 PyObject *_res = NULL;
1856 ControlHandle _rv;
1857 Handle h;
1858 if (!PyArg_ParseTuple(_args, "O&",
1859 ResObj_Convert, &h))
1860 return NULL;
1861 _rv = as_Control(h);
1862 _res = Py_BuildValue("O&",
1863 CtlObj_New, _rv);
1864 return _res;
1865}
1866
Guido van Rossum17448e21995-01-30 11:53:55 +00001867static PyMethodDef Ctl_methods[] = {
1868 {"NewControl", (PyCFunction)Ctl_NewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001869 "(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 +00001870 {"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001871 "(SInt16 resourceID, WindowPtr owningWindow) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001872 {"DrawControls", (PyCFunction)Ctl_DrawControls, 1,
1873 "(WindowPtr theWindow) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001874 {"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1,
Jack Jansen2b724171996-04-10 14:48:19 +00001875 "(WindowPtr theWindow, RgnHandle updateRegion) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001876 {"FindControl", (PyCFunction)Ctl_FindControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001877 "(Point testPoint, WindowPtr theWindow) -> (ControlPartCode _rv, ControlHandle theControl)"},
1878 {"FindControlUnderMouse", (PyCFunction)Ctl_FindControlUnderMouse, 1,
1879 "(Point inWhere, WindowPtr inWindow) -> (ControlHandle _rv, SInt16 outPart)"},
1880 {"IdleControls", (PyCFunction)Ctl_IdleControls, 1,
1881 "(WindowPtr inWindow) -> None"},
1882 {"DumpControlHierarchy", (PyCFunction)Ctl_DumpControlHierarchy, 1,
1883 "(WindowPtr inWindow, FSSpec inDumpFile) -> None"},
1884 {"CreateRootControl", (PyCFunction)Ctl_CreateRootControl, 1,
1885 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
1886 {"GetRootControl", (PyCFunction)Ctl_GetRootControl, 1,
1887 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
1888 {"GetKeyboardFocus", (PyCFunction)Ctl_GetKeyboardFocus, 1,
1889 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
1890 {"SetKeyboardFocus", (PyCFunction)Ctl_SetKeyboardFocus, 1,
1891 "(WindowPtr inWindow, ControlHandle inControl, ControlFocusPart inPart) -> None"},
1892 {"AdvanceKeyboardFocus", (PyCFunction)Ctl_AdvanceKeyboardFocus, 1,
1893 "(WindowPtr inWindow) -> None"},
1894 {"ReverseKeyboardFocus", (PyCFunction)Ctl_ReverseKeyboardFocus, 1,
1895 "(WindowPtr inWindow) -> None"},
1896 {"ClearKeyboardFocus", (PyCFunction)Ctl_ClearKeyboardFocus, 1,
1897 "(WindowPtr inWindow) -> None"},
Jack Jansene0581891999-02-07 14:02:03 +00001898 {"as_Control", (PyCFunction)Ctl_as_Control, 1,
1899 "(Handle h) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001900 {NULL, NULL, 0}
1901};
1902
1903
1904
Jack Jansen8387af61999-03-13 23:07:32 +00001905PyObject *CtlObj_NewUnmanaged(itself)
1906 ControlHandle itself;
1907{
1908 ControlObject *it;
1909 if (itself == NULL) return PyMac_Error(resNotFound);
1910 it = PyObject_NEW(ControlObject, &Control_Type);
1911 if (it == NULL) return NULL;
1912 it->ob_itself = itself;
Jack Jansen1a7d5b12000-03-21 16:25:23 +00001913 it->ob_callbackdict = NULL;
Jack Jansen8387af61999-03-13 23:07:32 +00001914 return (PyObject *)it;
1915}
1916
Guido van Rossum17448e21995-01-30 11:53:55 +00001917PyObject *
1918CtlObj_WhichControl(ControlHandle c)
1919{
1920 PyObject *it;
Jack Jansen24c35311999-12-09 22:49:51 +00001921
Guido van Rossum17448e21995-01-30 11:53:55 +00001922 if (c == NULL)
Guido van Rossum17448e21995-01-30 11:53:55 +00001923 it = Py_None;
Jack Jansen8387af61999-03-13 23:07:32 +00001924 else {
1925 it = (PyObject *) GetControlReference(c);
1926 /*
1927 ** If the refcon is zero or doesn't point back to the Python object
1928 ** the control is not ours. Return a temporary object.
1929 */
1930 if (it == NULL || ((ControlObject *)it)->ob_itself != c)
1931 return CtlObj_NewUnmanaged(c);
1932 }
Guido van Rossum17448e21995-01-30 11:53:55 +00001933 Py_INCREF(it);
1934 return it;
1935}
1936
Jack Jansen848250c1998-05-28 14:20:09 +00001937static int
1938settrackfunc(obj)
1939 PyObject *obj;
1940{
1941 if (tracker) {
1942 PyErr_SetString(Ctl_Error, "Tracker function in use");
1943 return 0;
1944 }
1945 tracker = obj;
1946 Py_INCREF(tracker);
1947}
1948
1949static void
1950clrtrackfunc()
1951{
1952 Py_XDECREF(tracker);
1953 tracker = 0;
1954}
1955
1956static pascal void
1957mytracker(ctl, part)
1958 ControlHandle ctl;
1959 short part;
1960{
1961 PyObject *args, *rv=0;
Jack Jansen24c35311999-12-09 22:49:51 +00001962
Jack Jansen848250c1998-05-28 14:20:09 +00001963 args = Py_BuildValue("(O&i)", CtlObj_WhichControl, ctl, (int)part);
1964 if (args && tracker) {
1965 rv = PyEval_CallObject(tracker, args);
1966 Py_DECREF(args);
1967 }
1968 if (rv)
1969 Py_DECREF(rv);
1970 else
Jack Jansen24c35311999-12-09 22:49:51 +00001971 PySys_WriteStderr("TrackControl or HandleControlClick: exception in tracker function\n");
Jack Jansen848250c1998-05-28 14:20:09 +00001972}
1973
Jack Jansenabc411b2000-03-20 16:09:09 +00001974static int
1975setcallback(self, which, callback, uppp)
1976 ControlObject *self;
1977 OSType which;
1978 PyObject *callback;
1979 UniversalProcPtr *uppp;
1980{
1981 char keybuf[9];
1982
1983 if ( which == kControlUserPaneDrawProcTag )
1984 *uppp = mydrawproc_upp;
1985 else if ( which == kControlUserPaneIdleProcTag )
1986 *uppp = myidleproc_upp;
Jack Jansena27e9fb2000-03-21 23:03:02 +00001987 else if ( which == kControlUserPaneHitTestProcTag )
1988 *uppp = myhittestproc_upp;
1989 else if ( which == kControlUserPaneTrackingProcTag )
1990 *uppp = mytrackingproc_upp;
Jack Jansenabc411b2000-03-20 16:09:09 +00001991 else
1992 return -1;
1993 /* Only now do we test for clearing of the callback: */
1994 if ( callback == Py_None )
1995 *uppp = NULL;
1996 /* Create the dict if it doesn't exist yet (so we don't get such a dict for every control) */
1997 if ( self->ob_callbackdict == NULL )
1998 if ( (self->ob_callbackdict = PyDict_New()) == NULL )
1999 return -1;
2000 /* And store the Python callback */
2001 sprintf(keybuf, "%x", which);
2002 if (PyDict_SetItemString(self->ob_callbackdict, keybuf, callback) < 0)
2003 return -1;
2004 return 0;
2005}
2006
2007static PyObject *
2008callcallback(self, which, arglist)
2009 ControlObject *self;
2010 OSType which;
2011 PyObject *arglist;
2012{
2013 char keybuf[9];
2014 PyObject *func, *rv;
2015
2016 sprintf(keybuf, "%x", which);
2017 if ( self->ob_callbackdict == NULL ||
2018 (func = PyDict_GetItemString(self->ob_callbackdict, keybuf)) == NULL ) {
Jack Jansena27e9fb2000-03-21 23:03:02 +00002019 PySys_WriteStderr("Control callback %x without callback object\n", which);
Jack Jansenabc411b2000-03-20 16:09:09 +00002020 return NULL;
2021 }
2022 rv = PyEval_CallObject(func, arglist);
2023 if ( rv == NULL )
Jack Jansena27e9fb2000-03-21 23:03:02 +00002024 PySys_WriteStderr("Exception in control callback %x handler\n", which);
Jack Jansenabc411b2000-03-20 16:09:09 +00002025 return rv;
2026}
2027
2028static pascal void
2029mydrawproc(ControlHandle control, SInt16 part)
2030{
2031 ControlObject *ctl_obj;
2032 PyObject *arglist, *rv;
2033
2034 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
2035 arglist = Py_BuildValue("Oh", ctl_obj, part);
2036 rv = callcallback(ctl_obj, kControlUserPaneDrawProcTag, arglist);
2037 Py_XDECREF(arglist);
2038 Py_XDECREF(rv);
2039}
2040
2041static pascal void
2042myidleproc(ControlHandle control)
2043{
2044 ControlObject *ctl_obj;
2045 PyObject *arglist, *rv;
2046
2047 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
2048 arglist = Py_BuildValue("O", ctl_obj);
2049 rv = callcallback(ctl_obj, kControlUserPaneIdleProcTag, arglist);
2050 Py_XDECREF(arglist);
2051 Py_XDECREF(rv);
2052}
2053
Jack Jansena27e9fb2000-03-21 23:03:02 +00002054static pascal ControlPartCode
2055myhittestproc(ControlHandle control, Point where)
2056{
2057 ControlObject *ctl_obj;
2058 PyObject *arglist, *rv;
2059 short c_rv = -1;
2060
2061 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
Jack Jansendeb63732000-03-22 15:35:24 +00002062 arglist = Py_BuildValue("OO&", ctl_obj, PyMac_BuildPoint, where);
Jack Jansena27e9fb2000-03-21 23:03:02 +00002063 rv = callcallback(ctl_obj, kControlUserPaneHitTestProcTag, arglist);
2064 Py_XDECREF(arglist);
2065 /* Ignore errors, nothing we can do about them */
2066 if ( rv )
2067 PyArg_Parse(rv, "h", &c_rv);
2068 Py_XDECREF(rv);
2069 return (ControlPartCode)c_rv;
2070}
2071
2072static pascal ControlPartCode
2073mytrackingproc(ControlHandle control, Point startPt, ControlActionUPP actionProc)
2074{
2075 ControlObject *ctl_obj;
2076 PyObject *arglist, *rv;
2077 short c_rv = -1;
2078
2079 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
2080 /* We cannot pass the actionProc without lots of work */
Jack Jansendeb63732000-03-22 15:35:24 +00002081 arglist = Py_BuildValue("OO&", ctl_obj, PyMac_BuildPoint, startPt);
Jack Jansena27e9fb2000-03-21 23:03:02 +00002082 rv = callcallback(ctl_obj, kControlUserPaneTrackingProcTag, arglist);
2083 Py_XDECREF(arglist);
2084 if ( rv )
2085 PyArg_Parse(rv, "h", &c_rv);
2086 Py_XDECREF(rv);
2087 return (ControlPartCode)c_rv;
2088}
2089
Jack Jansenabc411b2000-03-20 16:09:09 +00002090
Guido van Rossum17448e21995-01-30 11:53:55 +00002091
2092void initCtl()
2093{
2094 PyObject *m;
2095 PyObject *d;
2096
2097
2098
Jack Jansen848250c1998-05-28 14:20:09 +00002099 mytracker_upp = NewControlActionProc(mytracker);
Jack Jansenabc411b2000-03-20 16:09:09 +00002100 mydrawproc_upp = NewControlUserPaneDrawProc(mydrawproc);
2101 myidleproc_upp = NewControlUserPaneDrawProc(myidleproc);
Jack Jansena27e9fb2000-03-21 23:03:02 +00002102 myhittestproc_upp = NewControlUserPaneHitTestProc(myhittestproc);
2103 mytrackingproc_upp = NewControlUserPaneTrackingProc(mytrackingproc);
Jack Jansen848250c1998-05-28 14:20:09 +00002104
Guido van Rossum17448e21995-01-30 11:53:55 +00002105
2106 m = Py_InitModule("Ctl", Ctl_methods);
2107 d = PyModule_GetDict(m);
2108 Ctl_Error = PyMac_GetOSErrException();
2109 if (Ctl_Error == NULL ||
2110 PyDict_SetItemString(d, "Error", Ctl_Error) != 0)
2111 Py_FatalError("can't initialize Ctl.Error");
Jack Jansena755e681997-09-20 17:40:22 +00002112 Control_Type.ob_type = &PyType_Type;
2113 Py_INCREF(&Control_Type);
2114 if (PyDict_SetItemString(d, "ControlType", (PyObject *)&Control_Type) != 0)
2115 Py_FatalError("can't initialize ControlType");
Guido van Rossum17448e21995-01-30 11:53:55 +00002116}
2117
2118/* ========================= End module Ctl ========================= */
2119