blob: 530904c92510a248ab7f6fada39e6622c190057c [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 Jansene0581891999-02-07 14:02:03 +000049
Guido van Rossum17448e21995-01-30 11:53:55 +000050#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
51
52extern PyObject *CtlObj_WhichControl(ControlHandle); /* Forward */
Jack Jansen21f96871998-02-20 16:02:09 +000053extern PyObject *QdRGB_New(RGBColorPtr);
54extern QdRGB_Convert(PyObject *, RGBColorPtr);
Guido van Rossum17448e21995-01-30 11:53:55 +000055
56#ifdef THINK_C
57#define ControlActionUPP ProcPtr
58#endif
59
Jack Jansen21f96871998-02-20 16:02:09 +000060/*
61** Parse/generate ControlFontStyleRec records
62*/
63#if 0 /* Not needed */
64PyObject *ControlFontStyle_New(itself)
65 ControlFontStyleRec *itself;
66{
67
68 return Py_BuildValue("hhhhhhO&O&", itself->flags, itself->font,
69 itself->size, itself->style, itself->mode, itself->just,
70 QdRGB_New, &itself->foreColor, QdRGB_New, &itself->backColor);
71}
72#endif
73
74ControlFontStyle_Convert(v, itself)
75 PyObject *v;
76 ControlFontStyleRec *itself;
77{
78 return PyArg_ParseTuple(v, "hhhhhhO&O&", &itself->flags,
Jack Jansen24c35311999-12-09 22:49:51 +000079 &itself->font, &itself->size, &itself->style, &itself->mode,
80 &itself->just, QdRGB_Convert, &itself->foreColor,
Jack Jansen21f96871998-02-20 16:02:09 +000081 QdRGB_Convert, &itself->backColor);
82}
83
Jack Jansen24c35311999-12-09 22:49:51 +000084/* TrackControl and HandleControlClick callback support */
Jack Jansen848250c1998-05-28 14:20:09 +000085static PyObject *tracker;
86static ControlActionUPP mytracker_upp;
Jack Jansenabc411b2000-03-20 16:09:09 +000087static ControlUserPaneDrawUPP mydrawproc_upp;
88static ControlUserPaneIdleUPP myidleproc_upp;
Jack Jansen848250c1998-05-28 14:20:09 +000089
90extern int settrackfunc(PyObject *); /* forward */
91extern void clrtrackfunc(void); /* forward */
92
Guido van Rossum17448e21995-01-30 11:53:55 +000093static PyObject *Ctl_Error;
94
95/* ---------------------- Object type Control ----------------------- */
96
97PyTypeObject Control_Type;
98
99#define CtlObj_Check(x) ((x)->ob_type == &Control_Type)
100
101typedef struct ControlObject {
102 PyObject_HEAD
103 ControlHandle ob_itself;
Jack Jansenabc411b2000-03-20 16:09:09 +0000104 PyObject *ob_callbackdict;
Guido van Rossum17448e21995-01-30 11:53:55 +0000105} ControlObject;
106
107PyObject *CtlObj_New(itself)
Jack Jansenae8a68f1995-06-06 12:55:40 +0000108 ControlHandle itself;
Guido van Rossum17448e21995-01-30 11:53:55 +0000109{
110 ControlObject *it;
111 if (itself == NULL) return PyMac_Error(resNotFound);
112 it = PyObject_NEW(ControlObject, &Control_Type);
113 if (it == NULL) return NULL;
114 it->ob_itself = itself;
Jack Jansen85ae4a81997-04-08 15:26:03 +0000115 SetControlReference(itself, (long)it);
Jack Jansenabc411b2000-03-20 16:09:09 +0000116 it->ob_callbackdict = NULL;
Guido van Rossum17448e21995-01-30 11:53:55 +0000117 return (PyObject *)it;
118}
119CtlObj_Convert(v, p_itself)
120 PyObject *v;
121 ControlHandle *p_itself;
122{
123 if (!CtlObj_Check(v))
124 {
125 PyErr_SetString(PyExc_TypeError, "Control required");
126 return 0;
127 }
128 *p_itself = ((ControlObject *)v)->ob_itself;
129 return 1;
130}
131
132static void CtlObj_dealloc(self)
133 ControlObject *self;
134{
Jack Jansenabc411b2000-03-20 16:09:09 +0000135 Py_XDECREF(self->ob_callbackdict);
Jack Jansen24c35311999-12-09 22:49:51 +0000136 if (self->ob_itself)SetControlReference(self->ob_itself, (long)0); /* Make it forget about us */
Guido van Rossum17448e21995-01-30 11:53:55 +0000137 PyMem_DEL(self);
138}
139
Jack Jansen21f96871998-02-20 16:02:09 +0000140static PyObject *CtlObj_HiliteControl(_self, _args)
141 ControlObject *_self;
142 PyObject *_args;
143{
144 PyObject *_res = NULL;
145 ControlPartCode hiliteState;
146 if (!PyArg_ParseTuple(_args, "h",
147 &hiliteState))
148 return NULL;
149 HiliteControl(_self->ob_itself,
150 hiliteState);
151 Py_INCREF(Py_None);
152 _res = Py_None;
153 return _res;
154}
155
Jack Jansen7d0bc831995-06-09 20:56:31 +0000156static PyObject *CtlObj_ShowControl(_self, _args)
157 ControlObject *_self;
158 PyObject *_args;
159{
160 PyObject *_res = NULL;
161 if (!PyArg_ParseTuple(_args, ""))
162 return NULL;
163 ShowControl(_self->ob_itself);
164 Py_INCREF(Py_None);
165 _res = Py_None;
166 return _res;
167}
168
169static PyObject *CtlObj_HideControl(_self, _args)
170 ControlObject *_self;
171 PyObject *_args;
172{
173 PyObject *_res = NULL;
174 if (!PyArg_ParseTuple(_args, ""))
175 return NULL;
176 HideControl(_self->ob_itself);
177 Py_INCREF(Py_None);
178 _res = Py_None;
179 return _res;
180}
181
Jack Jansen21f96871998-02-20 16:02:09 +0000182static PyObject *CtlObj_IsControlActive(_self, _args)
183 ControlObject *_self;
184 PyObject *_args;
185{
186 PyObject *_res = NULL;
187 Boolean _rv;
188 if (!PyArg_ParseTuple(_args, ""))
189 return NULL;
190 _rv = IsControlActive(_self->ob_itself);
191 _res = Py_BuildValue("b",
192 _rv);
193 return _res;
194}
195
196static PyObject *CtlObj_IsControlVisible(_self, _args)
197 ControlObject *_self;
198 PyObject *_args;
199{
200 PyObject *_res = NULL;
201 Boolean _rv;
202 if (!PyArg_ParseTuple(_args, ""))
203 return NULL;
204 _rv = IsControlVisible(_self->ob_itself);
205 _res = Py_BuildValue("b",
206 _rv);
207 return _res;
208}
209
210static PyObject *CtlObj_ActivateControl(_self, _args)
211 ControlObject *_self;
212 PyObject *_args;
213{
214 PyObject *_res = NULL;
215 OSErr _err;
216 if (!PyArg_ParseTuple(_args, ""))
217 return NULL;
218 _err = ActivateControl(_self->ob_itself);
219 if (_err != noErr) return PyMac_Error(_err);
220 Py_INCREF(Py_None);
221 _res = Py_None;
222 return _res;
223}
224
225static PyObject *CtlObj_DeactivateControl(_self, _args)
226 ControlObject *_self;
227 PyObject *_args;
228{
229 PyObject *_res = NULL;
230 OSErr _err;
231 if (!PyArg_ParseTuple(_args, ""))
232 return NULL;
233 _err = DeactivateControl(_self->ob_itself);
234 if (_err != noErr) return PyMac_Error(_err);
235 Py_INCREF(Py_None);
236 _res = Py_None;
237 return _res;
238}
239
240static PyObject *CtlObj_SetControlVisibility(_self, _args)
241 ControlObject *_self;
242 PyObject *_args;
243{
244 PyObject *_res = NULL;
245 OSErr _err;
246 Boolean inIsVisible;
247 Boolean inDoDraw;
248 if (!PyArg_ParseTuple(_args, "bb",
249 &inIsVisible,
250 &inDoDraw))
251 return NULL;
252 _err = SetControlVisibility(_self->ob_itself,
253 inIsVisible,
254 inDoDraw);
255 if (_err != noErr) return PyMac_Error(_err);
256 Py_INCREF(Py_None);
257 _res = Py_None;
258 return _res;
259}
260
Jack Jansen7d0bc831995-06-09 20:56:31 +0000261static PyObject *CtlObj_Draw1Control(_self, _args)
262 ControlObject *_self;
263 PyObject *_args;
264{
265 PyObject *_res = NULL;
266 if (!PyArg_ParseTuple(_args, ""))
267 return NULL;
268 Draw1Control(_self->ob_itself);
269 Py_INCREF(Py_None);
270 _res = Py_None;
271 return _res;
272}
273
Jack Jansen21f96871998-02-20 16:02:09 +0000274static PyObject *CtlObj_GetBestControlRect(_self, _args)
Jack Jansen7d0bc831995-06-09 20:56:31 +0000275 ControlObject *_self;
276 PyObject *_args;
277{
278 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000279 OSErr _err;
280 Rect outRect;
281 SInt16 outBaseLineOffset;
282 if (!PyArg_ParseTuple(_args, ""))
Jack Jansen7d0bc831995-06-09 20:56:31 +0000283 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000284 _err = GetBestControlRect(_self->ob_itself,
285 &outRect,
286 &outBaseLineOffset);
287 if (_err != noErr) return PyMac_Error(_err);
288 _res = Py_BuildValue("O&h",
289 PyMac_BuildRect, &outRect,
290 outBaseLineOffset);
291 return _res;
292}
293
294static PyObject *CtlObj_SetControlFontStyle(_self, _args)
295 ControlObject *_self;
296 PyObject *_args;
297{
298 PyObject *_res = NULL;
299 OSErr _err;
300 ControlFontStyleRec inStyle;
301 if (!PyArg_ParseTuple(_args, "O&",
302 ControlFontStyle_Convert, &inStyle))
303 return NULL;
304 _err = SetControlFontStyle(_self->ob_itself,
305 &inStyle);
306 if (_err != noErr) return PyMac_Error(_err);
307 Py_INCREF(Py_None);
308 _res = Py_None;
309 return _res;
310}
311
312static PyObject *CtlObj_DrawControlInCurrentPort(_self, _args)
313 ControlObject *_self;
314 PyObject *_args;
315{
316 PyObject *_res = NULL;
317 if (!PyArg_ParseTuple(_args, ""))
318 return NULL;
319 DrawControlInCurrentPort(_self->ob_itself);
320 Py_INCREF(Py_None);
321 _res = Py_None;
322 return _res;
323}
324
325static PyObject *CtlObj_SetUpControlBackground(_self, _args)
326 ControlObject *_self;
327 PyObject *_args;
328{
329 PyObject *_res = NULL;
330 OSErr _err;
331 SInt16 inDepth;
332 Boolean inIsColorDevice;
333 if (!PyArg_ParseTuple(_args, "hb",
334 &inDepth,
335 &inIsColorDevice))
336 return NULL;
337 _err = SetUpControlBackground(_self->ob_itself,
338 inDepth,
339 inIsColorDevice);
340 if (_err != noErr) return PyMac_Error(_err);
Jack Jansen7d0bc831995-06-09 20:56:31 +0000341 Py_INCREF(Py_None);
342 _res = Py_None;
343 return _res;
344}
345
Jack Jansena05ac601999-12-12 21:41:51 +0000346static PyObject *CtlObj_SetUpControlTextColor(_self, _args)
347 ControlObject *_self;
348 PyObject *_args;
349{
350 PyObject *_res = NULL;
351 OSErr _err;
352 SInt16 inDepth;
353 Boolean inIsColorDevice;
354 if (!PyArg_ParseTuple(_args, "hb",
355 &inDepth,
356 &inIsColorDevice))
357 return NULL;
358 _err = SetUpControlTextColor(_self->ob_itself,
359 inDepth,
360 inIsColorDevice);
361 if (_err != noErr) return PyMac_Error(_err);
362 Py_INCREF(Py_None);
363 _res = Py_None;
364 return _res;
365}
366
Jack Jansen7d0bc831995-06-09 20:56:31 +0000367static PyObject *CtlObj_DragControl(_self, _args)
368 ControlObject *_self;
369 PyObject *_args;
370{
371 PyObject *_res = NULL;
Jack Jansen754d4a41995-11-14 10:41:55 +0000372 Point startPoint;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000373 Rect limitRect;
374 Rect slopRect;
375 DragConstraint axis;
376 if (!PyArg_ParseTuple(_args, "O&O&O&h",
Jack Jansen754d4a41995-11-14 10:41:55 +0000377 PyMac_GetPoint, &startPoint,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000378 PyMac_GetRect, &limitRect,
379 PyMac_GetRect, &slopRect,
380 &axis))
381 return NULL;
382 DragControl(_self->ob_itself,
Jack Jansen754d4a41995-11-14 10:41:55 +0000383 startPoint,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000384 &limitRect,
385 &slopRect,
386 axis);
387 Py_INCREF(Py_None);
388 _res = Py_None;
389 return _res;
390}
391
392static PyObject *CtlObj_TestControl(_self, _args)
393 ControlObject *_self;
394 PyObject *_args;
395{
396 PyObject *_res = NULL;
397 ControlPartCode _rv;
Jack Jansen21f96871998-02-20 16:02:09 +0000398 Point testPoint;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000399 if (!PyArg_ParseTuple(_args, "O&",
Jack Jansen21f96871998-02-20 16:02:09 +0000400 PyMac_GetPoint, &testPoint))
Jack Jansen7d0bc831995-06-09 20:56:31 +0000401 return NULL;
402 _rv = TestControl(_self->ob_itself,
Jack Jansen21f96871998-02-20 16:02:09 +0000403 testPoint);
404 _res = Py_BuildValue("h",
405 _rv);
406 return _res;
407}
408
409static PyObject *CtlObj_HandleControlKey(_self, _args)
410 ControlObject *_self;
411 PyObject *_args;
412{
413 PyObject *_res = NULL;
414 SInt16 _rv;
415 SInt16 inKeyCode;
416 SInt16 inCharCode;
417 SInt16 inModifiers;
418 if (!PyArg_ParseTuple(_args, "hhh",
419 &inKeyCode,
420 &inCharCode,
421 &inModifiers))
422 return NULL;
423 _rv = HandleControlKey(_self->ob_itself,
424 inKeyCode,
425 inCharCode,
426 inModifiers);
Jack Jansen7d0bc831995-06-09 20:56:31 +0000427 _res = Py_BuildValue("h",
428 _rv);
429 return _res;
430}
431
432static PyObject *CtlObj_MoveControl(_self, _args)
433 ControlObject *_self;
434 PyObject *_args;
435{
436 PyObject *_res = NULL;
437 SInt16 h;
438 SInt16 v;
439 if (!PyArg_ParseTuple(_args, "hh",
440 &h,
441 &v))
442 return NULL;
443 MoveControl(_self->ob_itself,
444 h,
445 v);
446 Py_INCREF(Py_None);
447 _res = Py_None;
448 return _res;
449}
450
451static PyObject *CtlObj_SizeControl(_self, _args)
452 ControlObject *_self;
453 PyObject *_args;
454{
455 PyObject *_res = NULL;
456 SInt16 w;
457 SInt16 h;
458 if (!PyArg_ParseTuple(_args, "hh",
459 &w,
460 &h))
461 return NULL;
462 SizeControl(_self->ob_itself,
463 w,
464 h);
465 Py_INCREF(Py_None);
466 _res = Py_None;
467 return _res;
468}
469
Jack Jansenae8a68f1995-06-06 12:55:40 +0000470static PyObject *CtlObj_SetControlTitle(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000471 ControlObject *_self;
472 PyObject *_args;
473{
474 PyObject *_res = NULL;
475 Str255 title;
476 if (!PyArg_ParseTuple(_args, "O&",
477 PyMac_GetStr255, title))
478 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000479 SetControlTitle(_self->ob_itself,
480 title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000481 Py_INCREF(Py_None);
482 _res = Py_None;
483 return _res;
484}
485
Jack Jansenae8a68f1995-06-06 12:55:40 +0000486static PyObject *CtlObj_GetControlTitle(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000487 ControlObject *_self;
488 PyObject *_args;
489{
490 PyObject *_res = NULL;
491 Str255 title;
Jack Jansen41009001999-03-07 20:05:20 +0000492 if (!PyArg_ParseTuple(_args, ""))
Guido van Rossum17448e21995-01-30 11:53:55 +0000493 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000494 GetControlTitle(_self->ob_itself,
495 title);
Jack Jansen41009001999-03-07 20:05:20 +0000496 _res = Py_BuildValue("O&",
497 PyMac_BuildStr255, title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000498 return _res;
499}
500
Jack Jansenae8a68f1995-06-06 12:55:40 +0000501static PyObject *CtlObj_GetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000502 ControlObject *_self;
503 PyObject *_args;
504{
505 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000506 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000507 if (!PyArg_ParseTuple(_args, ""))
508 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000509 _rv = GetControlValue(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000510 _res = Py_BuildValue("h",
511 _rv);
512 return _res;
513}
514
Jack Jansen7d0bc831995-06-09 20:56:31 +0000515static PyObject *CtlObj_SetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000516 ControlObject *_self;
517 PyObject *_args;
518{
519 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000520 SInt16 newValue;
Guido van Rossum17448e21995-01-30 11:53:55 +0000521 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000522 &newValue))
Guido van Rossum17448e21995-01-30 11:53:55 +0000523 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000524 SetControlValue(_self->ob_itself,
525 newValue);
Guido van Rossum17448e21995-01-30 11:53:55 +0000526 Py_INCREF(Py_None);
527 _res = Py_None;
528 return _res;
529}
530
Jack Jansenae8a68f1995-06-06 12:55:40 +0000531static PyObject *CtlObj_GetControlMinimum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000532 ControlObject *_self;
533 PyObject *_args;
534{
535 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000536 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000537 if (!PyArg_ParseTuple(_args, ""))
538 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000539 _rv = GetControlMinimum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000540 _res = Py_BuildValue("h",
541 _rv);
542 return _res;
543}
544
Jack Jansen7d0bc831995-06-09 20:56:31 +0000545static PyObject *CtlObj_SetControlMinimum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000546 ControlObject *_self;
547 PyObject *_args;
548{
549 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000550 SInt16 newMinimum;
Guido van Rossum17448e21995-01-30 11:53:55 +0000551 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000552 &newMinimum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000553 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000554 SetControlMinimum(_self->ob_itself,
555 newMinimum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000556 Py_INCREF(Py_None);
557 _res = Py_None;
558 return _res;
559}
560
Jack Jansenae8a68f1995-06-06 12:55:40 +0000561static PyObject *CtlObj_GetControlMaximum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000562 ControlObject *_self;
563 PyObject *_args;
564{
565 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000566 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000567 if (!PyArg_ParseTuple(_args, ""))
568 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000569 _rv = GetControlMaximum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000570 _res = Py_BuildValue("h",
571 _rv);
572 return _res;
573}
574
Jack Jansen7d0bc831995-06-09 20:56:31 +0000575static PyObject *CtlObj_SetControlMaximum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000576 ControlObject *_self;
577 PyObject *_args;
578{
579 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000580 SInt16 newMaximum;
581 if (!PyArg_ParseTuple(_args, "h",
582 &newMaximum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000583 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000584 SetControlMaximum(_self->ob_itself,
585 newMaximum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000586 Py_INCREF(Py_None);
587 _res = Py_None;
588 return _res;
589}
590
Jack Jansena05ac601999-12-12 21:41:51 +0000591static PyObject *CtlObj_GetControlViewSize(_self, _args)
592 ControlObject *_self;
593 PyObject *_args;
594{
595 PyObject *_res = NULL;
596 SInt32 _rv;
597 if (!PyArg_ParseTuple(_args, ""))
598 return NULL;
599 _rv = GetControlViewSize(_self->ob_itself);
600 _res = Py_BuildValue("l",
601 _rv);
602 return _res;
603}
604
605static PyObject *CtlObj_SetControlViewSize(_self, _args)
606 ControlObject *_self;
607 PyObject *_args;
608{
609 PyObject *_res = NULL;
610 SInt32 newViewSize;
611 if (!PyArg_ParseTuple(_args, "l",
612 &newViewSize))
613 return NULL;
614 SetControlViewSize(_self->ob_itself,
615 newViewSize);
616 Py_INCREF(Py_None);
617 _res = Py_None;
618 return _res;
619}
620
621static PyObject *CtlObj_GetControl32BitValue(_self, _args)
622 ControlObject *_self;
623 PyObject *_args;
624{
625 PyObject *_res = NULL;
626 SInt32 _rv;
627 if (!PyArg_ParseTuple(_args, ""))
628 return NULL;
629 _rv = GetControl32BitValue(_self->ob_itself);
630 _res = Py_BuildValue("l",
631 _rv);
632 return _res;
633}
634
635static PyObject *CtlObj_SetControl32BitValue(_self, _args)
636 ControlObject *_self;
637 PyObject *_args;
638{
639 PyObject *_res = NULL;
640 SInt32 newValue;
641 if (!PyArg_ParseTuple(_args, "l",
642 &newValue))
643 return NULL;
644 SetControl32BitValue(_self->ob_itself,
645 newValue);
646 Py_INCREF(Py_None);
647 _res = Py_None;
648 return _res;
649}
650
651static PyObject *CtlObj_GetControl32BitMaximum(_self, _args)
652 ControlObject *_self;
653 PyObject *_args;
654{
655 PyObject *_res = NULL;
656 SInt32 _rv;
657 if (!PyArg_ParseTuple(_args, ""))
658 return NULL;
659 _rv = GetControl32BitMaximum(_self->ob_itself);
660 _res = Py_BuildValue("l",
661 _rv);
662 return _res;
663}
664
665static PyObject *CtlObj_SetControl32BitMaximum(_self, _args)
666 ControlObject *_self;
667 PyObject *_args;
668{
669 PyObject *_res = NULL;
670 SInt32 newMaximum;
671 if (!PyArg_ParseTuple(_args, "l",
672 &newMaximum))
673 return NULL;
674 SetControl32BitMaximum(_self->ob_itself,
675 newMaximum);
676 Py_INCREF(Py_None);
677 _res = Py_None;
678 return _res;
679}
680
681static PyObject *CtlObj_GetControl32BitMinimum(_self, _args)
682 ControlObject *_self;
683 PyObject *_args;
684{
685 PyObject *_res = NULL;
686 SInt32 _rv;
687 if (!PyArg_ParseTuple(_args, ""))
688 return NULL;
689 _rv = GetControl32BitMinimum(_self->ob_itself);
690 _res = Py_BuildValue("l",
691 _rv);
692 return _res;
693}
694
695static PyObject *CtlObj_SetControl32BitMinimum(_self, _args)
696 ControlObject *_self;
697 PyObject *_args;
698{
699 PyObject *_res = NULL;
700 SInt32 newMinimum;
701 if (!PyArg_ParseTuple(_args, "l",
702 &newMinimum))
703 return NULL;
704 SetControl32BitMinimum(_self->ob_itself,
705 newMinimum);
706 Py_INCREF(Py_None);
707 _res = Py_None;
708 return _res;
709}
710
711static PyObject *CtlObj_IsValidControlHandle(_self, _args)
712 ControlObject *_self;
713 PyObject *_args;
714{
715 PyObject *_res = NULL;
716 Boolean _rv;
717 if (!PyArg_ParseTuple(_args, ""))
718 return NULL;
719 _rv = IsValidControlHandle(_self->ob_itself);
720 _res = Py_BuildValue("b",
721 _rv);
722 return _res;
723}
724
725static PyObject *CtlObj_RemoveControlProperty(_self, _args)
726 ControlObject *_self;
727 PyObject *_args;
728{
729 PyObject *_res = NULL;
Jack Jansenabc411b2000-03-20 16:09:09 +0000730 OSStatus _rv;
Jack Jansena05ac601999-12-12 21:41:51 +0000731 OSType propertyCreator;
732 OSType propertyTag;
733 if (!PyArg_ParseTuple(_args, "O&O&",
734 PyMac_GetOSType, &propertyCreator,
735 PyMac_GetOSType, &propertyTag))
736 return NULL;
Jack Jansenabc411b2000-03-20 16:09:09 +0000737 _rv = RemoveControlProperty(_self->ob_itself,
738 propertyCreator,
739 propertyTag);
740 _res = Py_BuildValue("l",
741 _rv);
Jack Jansena05ac601999-12-12 21:41:51 +0000742 return _res;
743}
744
745static PyObject *CtlObj_GetControlRegion(_self, _args)
746 ControlObject *_self;
747 PyObject *_args;
748{
749 PyObject *_res = NULL;
Jack Jansenabc411b2000-03-20 16:09:09 +0000750 OSStatus _rv;
Jack Jansena05ac601999-12-12 21:41:51 +0000751 ControlPartCode inPart;
752 RgnHandle outRegion;
753 if (!PyArg_ParseTuple(_args, "hO&",
754 &inPart,
755 ResObj_Convert, &outRegion))
756 return NULL;
Jack Jansenabc411b2000-03-20 16:09:09 +0000757 _rv = GetControlRegion(_self->ob_itself,
758 inPart,
759 outRegion);
760 _res = Py_BuildValue("l",
761 _rv);
Jack Jansena05ac601999-12-12 21:41:51 +0000762 return _res;
763}
764
Jack Jansen7d0bc831995-06-09 20:56:31 +0000765static PyObject *CtlObj_GetControlVariant(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000766 ControlObject *_self;
767 PyObject *_args;
768{
769 PyObject *_res = NULL;
Jack Jansen21f96871998-02-20 16:02:09 +0000770 ControlVariant _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000771 if (!PyArg_ParseTuple(_args, ""))
772 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000773 _rv = GetControlVariant(_self->ob_itself);
774 _res = Py_BuildValue("h",
Guido van Rossum17448e21995-01-30 11:53:55 +0000775 _rv);
776 return _res;
777}
778
Jack Jansen7d0bc831995-06-09 20:56:31 +0000779static PyObject *CtlObj_SetControlReference(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000780 ControlObject *_self;
781 PyObject *_args;
782{
783 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000784 SInt32 data;
785 if (!PyArg_ParseTuple(_args, "l",
786 &data))
Guido van Rossum17448e21995-01-30 11:53:55 +0000787 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000788 SetControlReference(_self->ob_itself,
789 data);
Guido van Rossum17448e21995-01-30 11:53:55 +0000790 Py_INCREF(Py_None);
791 _res = Py_None;
792 return _res;
793}
794
Jack Jansen7d0bc831995-06-09 20:56:31 +0000795static PyObject *CtlObj_GetControlReference(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000796 ControlObject *_self;
797 PyObject *_args;
798{
799 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000800 SInt32 _rv;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000801 if (!PyArg_ParseTuple(_args, ""))
802 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000803 _rv = GetControlReference(_self->ob_itself);
804 _res = Py_BuildValue("l",
Guido van Rossum17448e21995-01-30 11:53:55 +0000805 _rv);
806 return _res;
807}
808
Jack Jansenc7fefed1997-08-15 14:32:18 +0000809static PyObject *CtlObj_GetAuxiliaryControlRecord(_self, _args)
810 ControlObject *_self;
811 PyObject *_args;
812{
813 PyObject *_res = NULL;
814 Boolean _rv;
815 AuxCtlHandle acHndl;
816 if (!PyArg_ParseTuple(_args, ""))
817 return NULL;
818 _rv = GetAuxiliaryControlRecord(_self->ob_itself,
819 &acHndl);
820 _res = Py_BuildValue("bO&",
821 _rv,
822 ResObj_New, acHndl);
823 return _res;
824}
825
826static PyObject *CtlObj_SetControlColor(_self, _args)
827 ControlObject *_self;
828 PyObject *_args;
829{
830 PyObject *_res = NULL;
831 CCTabHandle newColorTable;
832 if (!PyArg_ParseTuple(_args, "O&",
833 ResObj_Convert, &newColorTable))
834 return NULL;
835 SetControlColor(_self->ob_itself,
836 newColorTable);
837 Py_INCREF(Py_None);
838 _res = Py_None;
839 return _res;
840}
841
Jack Jansen21f96871998-02-20 16:02:09 +0000842static PyObject *CtlObj_SendControlMessage(_self, _args)
843 ControlObject *_self;
844 PyObject *_args;
845{
846 PyObject *_res = NULL;
847 SInt32 _rv;
848 SInt16 inMessage;
849 SInt32 inParam;
850 if (!PyArg_ParseTuple(_args, "hl",
851 &inMessage,
852 &inParam))
853 return NULL;
854 _rv = SendControlMessage(_self->ob_itself,
855 inMessage,
856 inParam);
857 _res = Py_BuildValue("l",
858 _rv);
859 return _res;
860}
861
862static PyObject *CtlObj_EmbedControl(_self, _args)
863 ControlObject *_self;
864 PyObject *_args;
865{
866 PyObject *_res = NULL;
867 OSErr _err;
868 ControlHandle inContainer;
869 if (!PyArg_ParseTuple(_args, "O&",
870 CtlObj_Convert, &inContainer))
871 return NULL;
872 _err = EmbedControl(_self->ob_itself,
873 inContainer);
874 if (_err != noErr) return PyMac_Error(_err);
875 Py_INCREF(Py_None);
876 _res = Py_None;
877 return _res;
878}
879
880static PyObject *CtlObj_AutoEmbedControl(_self, _args)
881 ControlObject *_self;
882 PyObject *_args;
883{
884 PyObject *_res = NULL;
885 OSErr _err;
886 WindowPtr inWindow;
887 if (!PyArg_ParseTuple(_args, "O&",
888 WinObj_Convert, &inWindow))
889 return NULL;
890 _err = AutoEmbedControl(_self->ob_itself,
891 inWindow);
892 if (_err != noErr) return PyMac_Error(_err);
893 Py_INCREF(Py_None);
894 _res = Py_None;
895 return _res;
896}
897
898static PyObject *CtlObj_GetSuperControl(_self, _args)
899 ControlObject *_self;
900 PyObject *_args;
901{
902 PyObject *_res = NULL;
903 OSErr _err;
904 ControlHandle outParent;
905 if (!PyArg_ParseTuple(_args, ""))
906 return NULL;
907 _err = GetSuperControl(_self->ob_itself,
908 &outParent);
909 if (_err != noErr) return PyMac_Error(_err);
910 _res = Py_BuildValue("O&",
911 CtlObj_WhichControl, outParent);
912 return _res;
913}
914
915static PyObject *CtlObj_CountSubControls(_self, _args)
916 ControlObject *_self;
917 PyObject *_args;
918{
919 PyObject *_res = NULL;
920 OSErr _err;
Jack Jansen24c35311999-12-09 22:49:51 +0000921 UInt16 outNumChildren;
Jack Jansen21f96871998-02-20 16:02:09 +0000922 if (!PyArg_ParseTuple(_args, ""))
923 return NULL;
924 _err = CountSubControls(_self->ob_itself,
925 &outNumChildren);
926 if (_err != noErr) return PyMac_Error(_err);
927 _res = Py_BuildValue("h",
928 outNumChildren);
929 return _res;
930}
931
932static PyObject *CtlObj_GetIndexedSubControl(_self, _args)
933 ControlObject *_self;
934 PyObject *_args;
935{
936 PyObject *_res = NULL;
937 OSErr _err;
Jack Jansen24c35311999-12-09 22:49:51 +0000938 UInt16 inIndex;
Jack Jansen21f96871998-02-20 16:02:09 +0000939 ControlHandle outSubControl;
940 if (!PyArg_ParseTuple(_args, "h",
941 &inIndex))
942 return NULL;
943 _err = GetIndexedSubControl(_self->ob_itself,
944 inIndex,
945 &outSubControl);
946 if (_err != noErr) return PyMac_Error(_err);
947 _res = Py_BuildValue("O&",
948 CtlObj_WhichControl, outSubControl);
949 return _res;
950}
951
952static PyObject *CtlObj_SetControlSupervisor(_self, _args)
953 ControlObject *_self;
954 PyObject *_args;
955{
956 PyObject *_res = NULL;
957 OSErr _err;
958 ControlHandle inBoss;
959 if (!PyArg_ParseTuple(_args, "O&",
960 CtlObj_Convert, &inBoss))
961 return NULL;
962 _err = SetControlSupervisor(_self->ob_itself,
963 inBoss);
964 if (_err != noErr) return PyMac_Error(_err);
965 Py_INCREF(Py_None);
966 _res = Py_None;
967 return _res;
968}
969
970static PyObject *CtlObj_GetControlFeatures(_self, _args)
971 ControlObject *_self;
972 PyObject *_args;
973{
974 PyObject *_res = NULL;
975 OSErr _err;
976 UInt32 outFeatures;
977 if (!PyArg_ParseTuple(_args, ""))
978 return NULL;
979 _err = GetControlFeatures(_self->ob_itself,
980 &outFeatures);
981 if (_err != noErr) return PyMac_Error(_err);
982 _res = Py_BuildValue("l",
983 outFeatures);
984 return _res;
985}
986
987static PyObject *CtlObj_GetControlDataSize(_self, _args)
988 ControlObject *_self;
989 PyObject *_args;
990{
991 PyObject *_res = NULL;
992 OSErr _err;
993 ControlPartCode inPart;
994 ResType inTagName;
995 Size outMaxSize;
996 if (!PyArg_ParseTuple(_args, "hO&",
997 &inPart,
998 PyMac_GetOSType, &inTagName))
999 return NULL;
1000 _err = GetControlDataSize(_self->ob_itself,
1001 inPart,
1002 inTagName,
1003 &outMaxSize);
1004 if (_err != noErr) return PyMac_Error(_err);
1005 _res = Py_BuildValue("l",
1006 outMaxSize);
1007 return _res;
1008}
1009
Jack Jansen5d56f4b1995-06-18 20:16:33 +00001010static PyObject *CtlObj_as_Resource(_self, _args)
1011 ControlObject *_self;
1012 PyObject *_args;
1013{
1014 PyObject *_res = NULL;
Jack Jansena1a0fef1999-12-23 14:32:06 +00001015 Handle _rv;
1016 if (!PyArg_ParseTuple(_args, ""))
1017 return NULL;
1018 _rv = as_Resource(_self->ob_itself);
1019 _res = Py_BuildValue("O&",
1020 ResObj_New, _rv);
1021 return _res;
Jack Jansen5d56f4b1995-06-18 20:16:33 +00001022}
1023
Jack Jansencfb60ee1996-10-01 10:46:46 +00001024static PyObject *CtlObj_DisposeControl(_self, _args)
1025 ControlObject *_self;
1026 PyObject *_args;
1027{
1028 PyObject *_res = NULL;
1029
1030 if (!PyArg_ParseTuple(_args, ""))
1031 return NULL;
1032 if ( _self->ob_itself ) {
Jack Jansen85ae4a81997-04-08 15:26:03 +00001033 SetControlReference(_self->ob_itself, (long)0); /* Make it forget about us */
Jack Jansencfb60ee1996-10-01 10:46:46 +00001034 DisposeControl(_self->ob_itself);
1035 _self->ob_itself = NULL;
1036 }
1037 Py_INCREF(Py_None);
1038 _res = Py_None;
1039 return _res;
1040
1041}
1042
Jack Jansen848250c1998-05-28 14:20:09 +00001043static PyObject *CtlObj_TrackControl(_self, _args)
1044 ControlObject *_self;
1045 PyObject *_args;
1046{
1047 PyObject *_res = NULL;
1048
1049 ControlPartCode _rv;
1050 Point startPoint;
1051 ControlActionUPP upp = 0;
1052 PyObject *callback = 0;
1053
1054 if (!PyArg_ParseTuple(_args, "O&|O",
1055 PyMac_GetPoint, &startPoint, &callback))
1056 return NULL;
1057 if (callback && callback != Py_None) {
1058 if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
1059 upp = (ControlActionUPP)-1;
1060 else {
1061 settrackfunc(callback);
1062 upp = mytracker_upp;
1063 }
1064 }
1065 _rv = TrackControl(_self->ob_itself,
1066 startPoint,
1067 upp);
1068 clrtrackfunc();
1069 _res = Py_BuildValue("h",
1070 _rv);
1071 return _res;
1072
1073}
1074
Jack Jansen24c35311999-12-09 22:49:51 +00001075static PyObject *CtlObj_HandleControlClick(_self, _args)
1076 ControlObject *_self;
1077 PyObject *_args;
1078{
1079 PyObject *_res = NULL;
1080
1081 ControlPartCode _rv;
1082 Point startPoint;
1083 SInt16 modifiers;
1084 ControlActionUPP upp = 0;
1085 PyObject *callback = 0;
1086
1087 if (!PyArg_ParseTuple(_args, "O&h|O",
1088 PyMac_GetPoint, &startPoint,
1089 &modifiers,
1090 &callback))
1091 return NULL;
1092 if (callback && callback != Py_None) {
1093 if (PyInt_Check(callback) && PyInt_AS_LONG(callback) == -1)
1094 upp = (ControlActionUPP)-1;
1095 else {
1096 settrackfunc(callback);
1097 upp = mytracker_upp;
1098 }
1099 }
1100 _rv = HandleControlClick(_self->ob_itself,
1101 startPoint,
1102 modifiers,
1103 upp);
1104 clrtrackfunc();
1105 _res = Py_BuildValue("h",
1106 _rv);
1107 return _res;
1108
1109}
1110
1111static PyObject *CtlObj_SetControlData(_self, _args)
1112 ControlObject *_self;
1113 PyObject *_args;
1114{
1115 PyObject *_res = NULL;
1116
1117 OSErr _err;
1118 ControlPartCode inPart;
1119 ResType inTagName;
1120 Size bufferSize;
1121 Ptr buffer;
1122
1123 if (!PyArg_ParseTuple(_args, "hO&s#",
1124 &inPart,
1125 PyMac_GetOSType, &inTagName,
1126 &buffer, &bufferSize))
1127 return NULL;
1128
1129 _err = SetControlData(_self->ob_itself,
1130 inPart,
1131 inTagName,
1132 bufferSize,
1133 buffer);
1134
1135 if (_err != noErr)
1136 return PyMac_Error(_err);
1137 _res = Py_None;
1138 return _res;
1139
1140}
1141
1142static PyObject *CtlObj_GetControlData(_self, _args)
1143 ControlObject *_self;
1144 PyObject *_args;
1145{
1146 PyObject *_res = NULL;
1147
1148 OSErr _err;
1149 ControlPartCode inPart;
1150 ResType inTagName;
1151 Size bufferSize;
1152 Ptr buffer;
1153 Size outSize;
1154
1155 if (!PyArg_ParseTuple(_args, "hO&",
1156 &inPart,
1157 PyMac_GetOSType, &inTagName))
1158 return NULL;
1159
1160 /* allocate a buffer for the data */
1161 _err = GetControlDataSize(_self->ob_itself,
1162 inPart,
1163 inTagName,
1164 &bufferSize);
1165 if (_err != noErr)
1166 return PyMac_Error(_err);
1167 buffer = PyMem_NEW(char, bufferSize);
1168 if (buffer == NULL)
1169 return PyErr_NoMemory();
1170
1171 _err = GetControlData(_self->ob_itself,
1172 inPart,
1173 inTagName,
1174 bufferSize,
1175 buffer,
1176 &outSize);
1177
1178 if (_err != noErr) {
1179 PyMem_DEL(buffer);
1180 return PyMac_Error(_err);
1181 }
1182 _res = Py_BuildValue("s#", buffer, outSize);
1183 PyMem_DEL(buffer);
1184 return _res;
1185
1186}
1187
Jack Jansen1f9249c1999-12-19 00:05:50 +00001188static PyObject *CtlObj_SetControlDataHandle(_self, _args)
1189 ControlObject *_self;
1190 PyObject *_args;
1191{
1192 PyObject *_res = NULL;
1193
1194 OSErr _err;
1195 ControlPartCode inPart;
1196 ResType inTagName;
1197 Handle buffer;
1198
1199 if (!PyArg_ParseTuple(_args, "hO&O&",
1200 &inPart,
1201 PyMac_GetOSType, &inTagName,
Jack Jansenb9247d31999-12-23 23:06:07 +00001202 OptResObj_Convert, &buffer))
Jack Jansen1f9249c1999-12-19 00:05:50 +00001203 return NULL;
1204
1205 _err = SetControlData(_self->ob_itself,
1206 inPart,
1207 inTagName,
1208 sizeof(buffer),
Jack Jansenf7ac1d31999-12-29 12:37:22 +00001209 (Ptr)&buffer);
Jack Jansen1f9249c1999-12-19 00:05:50 +00001210
1211 if (_err != noErr)
1212 return PyMac_Error(_err);
1213 _res = Py_None;
1214 return _res;
1215
1216}
1217
1218static PyObject *CtlObj_GetControlDataHandle(_self, _args)
1219 ControlObject *_self;
1220 PyObject *_args;
1221{
1222 PyObject *_res = NULL;
1223
1224 OSErr _err;
1225 ControlPartCode inPart;
1226 ResType inTagName;
1227 Size bufferSize;
1228 Handle hdl;
1229
1230 if (!PyArg_ParseTuple(_args, "hO&",
1231 &inPart,
1232 PyMac_GetOSType, &inTagName))
1233 return NULL;
1234
1235 /* Check it is handle-sized */
1236 _err = GetControlDataSize(_self->ob_itself,
1237 inPart,
1238 inTagName,
1239 &bufferSize);
1240 if (_err != noErr)
1241 return PyMac_Error(_err);
1242 if (bufferSize != sizeof(Handle)) {
1243 PyErr_SetString(Ctl_Error, "GetControlDataSize() != sizeof(Handle)");
1244 return NULL;
1245 }
1246
1247 _err = GetControlData(_self->ob_itself,
1248 inPart,
1249 inTagName,
1250 sizeof(Handle),
1251 (Ptr)&hdl,
1252 &bufferSize);
1253
1254 if (_err != noErr) {
1255 return PyMac_Error(_err);
1256 }
1257 return Py_BuildValue("O&", OptResObj_New, hdl);
1258
1259}
1260
Jack Jansenabc411b2000-03-20 16:09:09 +00001261static PyObject *CtlObj_SetControlDataCallback(_self, _args)
1262 ControlObject *_self;
1263 PyObject *_args;
1264{
1265 PyObject *_res = NULL;
1266
1267 OSErr _err;
1268 ControlPartCode inPart;
1269 ResType inTagName;
1270 PyObject *callback;
1271 UniversalProcPtr *c_callback;
1272
1273 if (!PyArg_ParseTuple(_args, "hO&O",
1274 &inPart,
1275 PyMac_GetOSType, &inTagName,
1276 &callback))
1277 return NULL;
1278
1279 if ( setcallback(_self, inTagName, callback, &c_callback) < 0 )
1280 return NULL;
1281 _err = SetControlData(_self->ob_itself,
1282 inPart,
1283 inTagName,
1284 sizeof(c_callback),
1285 (Ptr)&c_callback);
1286
1287 if (_err != noErr)
1288 return PyMac_Error(_err);
1289 _res = Py_None;
1290 return _res;
1291
1292}
1293
Jack Jansen4c704131998-06-19 13:35:14 +00001294static PyObject *CtlObj_GetPopupData(_self, _args)
1295 ControlObject *_self;
1296 PyObject *_args;
1297{
1298 PyObject *_res = NULL;
1299
1300 PopupPrivateDataHandle hdl;
1301
1302 if ( (*_self->ob_itself)->contrlData == NULL ) {
1303 PyErr_SetString(Ctl_Error, "No contrlData handle in control");
1304 return 0;
1305 }
1306 hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
1307 HLock((Handle)hdl);
1308 _res = Py_BuildValue("O&i", MenuObj_New, (*hdl)->mHandle, (int)(*hdl)->mID);
1309 HUnlock((Handle)hdl);
1310 return _res;
1311
1312}
1313
1314static PyObject *CtlObj_SetPopupData(_self, _args)
1315 ControlObject *_self;
1316 PyObject *_args;
1317{
1318 PyObject *_res = NULL;
1319
1320 PopupPrivateDataHandle hdl;
1321 MenuHandle mHandle;
1322 short mID;
1323
1324 if (!PyArg_ParseTuple(_args, "O&h", MenuObj_Convert, &mHandle, &mID) )
1325 return 0;
1326 if ( (*_self->ob_itself)->contrlData == NULL ) {
1327 PyErr_SetString(Ctl_Error, "No contrlData handle in control");
1328 return 0;
1329 }
1330 hdl = (PopupPrivateDataHandle)(*_self->ob_itself)->contrlData;
1331 (*hdl)->mHandle = mHandle;
1332 (*hdl)->mID = mID;
1333 Py_INCREF(Py_None);
1334 return Py_None;
1335
1336}
1337
Guido van Rossum17448e21995-01-30 11:53:55 +00001338static PyMethodDef CtlObj_methods[] = {
Jack Jansen21f96871998-02-20 16:02:09 +00001339 {"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1,
1340 "(ControlPartCode hiliteState) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001341 {"ShowControl", (PyCFunction)CtlObj_ShowControl, 1,
1342 "() -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001343 {"HideControl", (PyCFunction)CtlObj_HideControl, 1,
1344 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001345 {"IsControlActive", (PyCFunction)CtlObj_IsControlActive, 1,
1346 "() -> (Boolean _rv)"},
1347 {"IsControlVisible", (PyCFunction)CtlObj_IsControlVisible, 1,
1348 "() -> (Boolean _rv)"},
1349 {"ActivateControl", (PyCFunction)CtlObj_ActivateControl, 1,
1350 "() -> None"},
1351 {"DeactivateControl", (PyCFunction)CtlObj_DeactivateControl, 1,
1352 "() -> None"},
1353 {"SetControlVisibility", (PyCFunction)CtlObj_SetControlVisibility, 1,
1354 "(Boolean inIsVisible, Boolean inDoDraw) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001355 {"Draw1Control", (PyCFunction)CtlObj_Draw1Control, 1,
1356 "() -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001357 {"GetBestControlRect", (PyCFunction)CtlObj_GetBestControlRect, 1,
1358 "() -> (Rect outRect, SInt16 outBaseLineOffset)"},
1359 {"SetControlFontStyle", (PyCFunction)CtlObj_SetControlFontStyle, 1,
1360 "(ControlFontStyleRec inStyle) -> None"},
1361 {"DrawControlInCurrentPort", (PyCFunction)CtlObj_DrawControlInCurrentPort, 1,
1362 "() -> None"},
1363 {"SetUpControlBackground", (PyCFunction)CtlObj_SetUpControlBackground, 1,
1364 "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +00001365 {"SetUpControlTextColor", (PyCFunction)CtlObj_SetUpControlTextColor, 1,
1366 "(SInt16 inDepth, Boolean inIsColorDevice) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001367 {"DragControl", (PyCFunction)CtlObj_DragControl, 1,
Jack Jansen754d4a41995-11-14 10:41:55 +00001368 "(Point startPoint, Rect limitRect, Rect slopRect, DragConstraint axis) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001369 {"TestControl", (PyCFunction)CtlObj_TestControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001370 "(Point testPoint) -> (ControlPartCode _rv)"},
1371 {"HandleControlKey", (PyCFunction)CtlObj_HandleControlKey, 1,
1372 "(SInt16 inKeyCode, SInt16 inCharCode, SInt16 inModifiers) -> (SInt16 _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001373 {"MoveControl", (PyCFunction)CtlObj_MoveControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001374 "(SInt16 h, SInt16 v) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001375 {"SizeControl", (PyCFunction)CtlObj_SizeControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001376 "(SInt16 w, SInt16 h) -> None"},
1377 {"SetControlTitle", (PyCFunction)CtlObj_SetControlTitle, 1,
1378 "(Str255 title) -> None"},
1379 {"GetControlTitle", (PyCFunction)CtlObj_GetControlTitle, 1,
Jack Jansen41009001999-03-07 20:05:20 +00001380 "() -> (Str255 title)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001381 {"GetControlValue", (PyCFunction)CtlObj_GetControlValue, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001382 "() -> (SInt16 _rv)"},
1383 {"SetControlValue", (PyCFunction)CtlObj_SetControlValue, 1,
1384 "(SInt16 newValue) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001385 {"GetControlMinimum", (PyCFunction)CtlObj_GetControlMinimum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001386 "() -> (SInt16 _rv)"},
1387 {"SetControlMinimum", (PyCFunction)CtlObj_SetControlMinimum, 1,
1388 "(SInt16 newMinimum) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +00001389 {"GetControlMaximum", (PyCFunction)CtlObj_GetControlMaximum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +00001390 "() -> (SInt16 _rv)"},
1391 {"SetControlMaximum", (PyCFunction)CtlObj_SetControlMaximum, 1,
1392 "(SInt16 newMaximum) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +00001393 {"GetControlViewSize", (PyCFunction)CtlObj_GetControlViewSize, 1,
1394 "() -> (SInt32 _rv)"},
1395 {"SetControlViewSize", (PyCFunction)CtlObj_SetControlViewSize, 1,
1396 "(SInt32 newViewSize) -> None"},
1397 {"GetControl32BitValue", (PyCFunction)CtlObj_GetControl32BitValue, 1,
1398 "() -> (SInt32 _rv)"},
1399 {"SetControl32BitValue", (PyCFunction)CtlObj_SetControl32BitValue, 1,
1400 "(SInt32 newValue) -> None"},
1401 {"GetControl32BitMaximum", (PyCFunction)CtlObj_GetControl32BitMaximum, 1,
1402 "() -> (SInt32 _rv)"},
1403 {"SetControl32BitMaximum", (PyCFunction)CtlObj_SetControl32BitMaximum, 1,
1404 "(SInt32 newMaximum) -> None"},
1405 {"GetControl32BitMinimum", (PyCFunction)CtlObj_GetControl32BitMinimum, 1,
1406 "() -> (SInt32 _rv)"},
1407 {"SetControl32BitMinimum", (PyCFunction)CtlObj_SetControl32BitMinimum, 1,
1408 "(SInt32 newMinimum) -> None"},
1409 {"IsValidControlHandle", (PyCFunction)CtlObj_IsValidControlHandle, 1,
1410 "() -> (Boolean _rv)"},
1411 {"RemoveControlProperty", (PyCFunction)CtlObj_RemoveControlProperty, 1,
Jack Jansenabc411b2000-03-20 16:09:09 +00001412 "(OSType propertyCreator, OSType propertyTag) -> (OSStatus _rv)"},
Jack Jansena05ac601999-12-12 21:41:51 +00001413 {"GetControlRegion", (PyCFunction)CtlObj_GetControlRegion, 1,
Jack Jansenabc411b2000-03-20 16:09:09 +00001414 "(ControlPartCode inPart, RgnHandle outRegion) -> (OSStatus _rv)"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001415 {"GetControlVariant", (PyCFunction)CtlObj_GetControlVariant, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001416 "() -> (ControlVariant _rv)"},
Jack Jansen7d0bc831995-06-09 20:56:31 +00001417 {"SetControlReference", (PyCFunction)CtlObj_SetControlReference, 1,
1418 "(SInt32 data) -> None"},
1419 {"GetControlReference", (PyCFunction)CtlObj_GetControlReference, 1,
1420 "() -> (SInt32 _rv)"},
Jack Jansenc7fefed1997-08-15 14:32:18 +00001421 {"GetAuxiliaryControlRecord", (PyCFunction)CtlObj_GetAuxiliaryControlRecord, 1,
1422 "() -> (Boolean _rv, AuxCtlHandle acHndl)"},
1423 {"SetControlColor", (PyCFunction)CtlObj_SetControlColor, 1,
1424 "(CCTabHandle newColorTable) -> None"},
Jack Jansen21f96871998-02-20 16:02:09 +00001425 {"SendControlMessage", (PyCFunction)CtlObj_SendControlMessage, 1,
1426 "(SInt16 inMessage, SInt32 inParam) -> (SInt32 _rv)"},
1427 {"EmbedControl", (PyCFunction)CtlObj_EmbedControl, 1,
1428 "(ControlHandle inContainer) -> None"},
1429 {"AutoEmbedControl", (PyCFunction)CtlObj_AutoEmbedControl, 1,
1430 "(WindowPtr inWindow) -> None"},
1431 {"GetSuperControl", (PyCFunction)CtlObj_GetSuperControl, 1,
1432 "() -> (ControlHandle outParent)"},
1433 {"CountSubControls", (PyCFunction)CtlObj_CountSubControls, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00001434 "() -> (UInt16 outNumChildren)"},
Jack Jansen21f96871998-02-20 16:02:09 +00001435 {"GetIndexedSubControl", (PyCFunction)CtlObj_GetIndexedSubControl, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00001436 "(UInt16 inIndex) -> (ControlHandle outSubControl)"},
Jack Jansen21f96871998-02-20 16:02:09 +00001437 {"SetControlSupervisor", (PyCFunction)CtlObj_SetControlSupervisor, 1,
1438 "(ControlHandle inBoss) -> None"},
1439 {"GetControlFeatures", (PyCFunction)CtlObj_GetControlFeatures, 1,
1440 "() -> (UInt32 outFeatures)"},
1441 {"GetControlDataSize", (PyCFunction)CtlObj_GetControlDataSize, 1,
1442 "(ControlPartCode inPart, ResType inTagName) -> (Size outMaxSize)"},
Jack Jansen5d56f4b1995-06-18 20:16:33 +00001443 {"as_Resource", (PyCFunction)CtlObj_as_Resource, 1,
Jack Jansena1a0fef1999-12-23 14:32:06 +00001444 "() -> (Handle _rv)"},
Jack Jansencfb60ee1996-10-01 10:46:46 +00001445 {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1,
1446 "() -> None"},
Jack Jansen848250c1998-05-28 14:20:09 +00001447 {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1,
Jack Jansen24c35311999-12-09 22:49:51 +00001448 "(Point startPoint [,trackercallback]) -> (ControlPartCode _rv)"},
1449 {"HandleControlClick", (PyCFunction)CtlObj_HandleControlClick, 1,
1450 "(Point startPoint, Integer modifiers, [,trackercallback]) -> (ControlPartCode _rv)"},
1451 {"SetControlData", (PyCFunction)CtlObj_SetControlData, 1,
1452 "(stuff) -> None"},
1453 {"GetControlData", (PyCFunction)CtlObj_GetControlData, 1,
1454 "(part, type) -> String"},
Jack Jansen1f9249c1999-12-19 00:05:50 +00001455 {"SetControlDataHandle", (PyCFunction)CtlObj_SetControlDataHandle, 1,
1456 "(ResObj) -> None"},
1457 {"GetControlDataHandle", (PyCFunction)CtlObj_GetControlDataHandle, 1,
1458 "(part, type) -> ResObj"},
Jack Jansenabc411b2000-03-20 16:09:09 +00001459 {"SetControlDataCallback", (PyCFunction)CtlObj_SetControlDataCallback, 1,
1460 "(callbackfunc) -> None"},
Jack Jansen4c704131998-06-19 13:35:14 +00001461 {"GetPopupData", (PyCFunction)CtlObj_GetPopupData, 1,
1462 NULL},
1463 {"SetPopupData", (PyCFunction)CtlObj_SetPopupData, 1,
1464 NULL},
Guido van Rossum17448e21995-01-30 11:53:55 +00001465 {NULL, NULL, 0}
1466};
1467
1468PyMethodChain CtlObj_chain = { CtlObj_methods, NULL };
1469
1470static PyObject *CtlObj_getattr(self, name)
1471 ControlObject *self;
1472 char *name;
1473{
1474 return Py_FindMethodInChain(&CtlObj_chain, (PyObject *)self, name);
1475}
1476
1477#define CtlObj_setattr NULL
1478
Jack Jansen8387af61999-03-13 23:07:32 +00001479static int CtlObj_compare(self, other)
1480 ControlObject *self, *other;
1481{
1482 unsigned long v, w;
1483
1484 if (!CtlObj_Check((PyObject *)other))
1485 {
1486 v=(unsigned long)self;
1487 w=(unsigned long)other;
1488 }
1489 else
1490 {
1491 v=(unsigned long)self->ob_itself;
1492 w=(unsigned long)other->ob_itself;
1493 }
1494 if( v < w ) return -1;
1495 if( v > w ) return 1;
1496 return 0;
1497}
1498
1499#define CtlObj_repr NULL
1500
1501static long CtlObj_hash(self)
1502 ControlObject *self;
1503{
1504 return (long)self->ob_itself;
1505}
1506
Guido van Rossum17448e21995-01-30 11:53:55 +00001507PyTypeObject Control_Type = {
1508 PyObject_HEAD_INIT(&PyType_Type)
1509 0, /*ob_size*/
1510 "Control", /*tp_name*/
1511 sizeof(ControlObject), /*tp_basicsize*/
1512 0, /*tp_itemsize*/
1513 /* methods */
1514 (destructor) CtlObj_dealloc, /*tp_dealloc*/
1515 0, /*tp_print*/
1516 (getattrfunc) CtlObj_getattr, /*tp_getattr*/
1517 (setattrfunc) CtlObj_setattr, /*tp_setattr*/
Jack Jansen8387af61999-03-13 23:07:32 +00001518 (cmpfunc) CtlObj_compare, /*tp_compare*/
1519 (reprfunc) CtlObj_repr, /*tp_repr*/
1520 (PyNumberMethods *)0, /* tp_as_number */
1521 (PySequenceMethods *)0, /* tp_as_sequence */
1522 (PyMappingMethods *)0, /* tp_as_mapping */
1523 (hashfunc) CtlObj_hash, /*tp_hash*/
Guido van Rossum17448e21995-01-30 11:53:55 +00001524};
1525
1526/* -------------------- End object type Control --------------------- */
1527
1528
1529static PyObject *Ctl_NewControl(_self, _args)
1530 PyObject *_self;
1531 PyObject *_args;
1532{
1533 PyObject *_res = NULL;
1534 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001535 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00001536 Rect boundsRect;
Jack Jansen21f96871998-02-20 16:02:09 +00001537 Str255 controlTitle;
1538 Boolean initiallyVisible;
1539 SInt16 initialValue;
1540 SInt16 minimumValue;
1541 SInt16 maximumValue;
Jack Jansen7d0bc831995-06-09 20:56:31 +00001542 SInt16 procID;
Jack Jansen21f96871998-02-20 16:02:09 +00001543 SInt32 controlReference;
Guido van Rossum17448e21995-01-30 11:53:55 +00001544 if (!PyArg_ParseTuple(_args, "O&O&O&bhhhhl",
Jack Jansen21f96871998-02-20 16:02:09 +00001545 WinObj_Convert, &owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00001546 PyMac_GetRect, &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00001547 PyMac_GetStr255, controlTitle,
1548 &initiallyVisible,
1549 &initialValue,
1550 &minimumValue,
1551 &maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00001552 &procID,
Jack Jansen21f96871998-02-20 16:02:09 +00001553 &controlReference))
Guido van Rossum17448e21995-01-30 11:53:55 +00001554 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001555 _rv = NewControl(owningWindow,
Guido van Rossum17448e21995-01-30 11:53:55 +00001556 &boundsRect,
Jack Jansen21f96871998-02-20 16:02:09 +00001557 controlTitle,
1558 initiallyVisible,
1559 initialValue,
1560 minimumValue,
1561 maximumValue,
Guido van Rossum17448e21995-01-30 11:53:55 +00001562 procID,
Jack Jansen21f96871998-02-20 16:02:09 +00001563 controlReference);
Guido van Rossum17448e21995-01-30 11:53:55 +00001564 _res = Py_BuildValue("O&",
1565 CtlObj_New, _rv);
1566 return _res;
1567}
1568
1569static PyObject *Ctl_GetNewControl(_self, _args)
1570 PyObject *_self;
1571 PyObject *_args;
1572{
1573 PyObject *_res = NULL;
1574 ControlHandle _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001575 SInt16 resourceID;
1576 WindowPtr owningWindow;
Guido van Rossum17448e21995-01-30 11:53:55 +00001577 if (!PyArg_ParseTuple(_args, "hO&",
Jack Jansen21f96871998-02-20 16:02:09 +00001578 &resourceID,
1579 WinObj_Convert, &owningWindow))
Guido van Rossum17448e21995-01-30 11:53:55 +00001580 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001581 _rv = GetNewControl(resourceID,
1582 owningWindow);
Guido van Rossum17448e21995-01-30 11:53:55 +00001583 _res = Py_BuildValue("O&",
1584 CtlObj_New, _rv);
1585 return _res;
1586}
1587
Guido van Rossum17448e21995-01-30 11:53:55 +00001588static PyObject *Ctl_DrawControls(_self, _args)
1589 PyObject *_self;
1590 PyObject *_args;
1591{
1592 PyObject *_res = NULL;
1593 WindowPtr theWindow;
1594 if (!PyArg_ParseTuple(_args, "O&",
1595 WinObj_Convert, &theWindow))
1596 return NULL;
1597 DrawControls(theWindow);
1598 Py_INCREF(Py_None);
1599 _res = Py_None;
1600 return _res;
1601}
1602
Guido van Rossum17448e21995-01-30 11:53:55 +00001603static PyObject *Ctl_UpdateControls(_self, _args)
1604 PyObject *_self;
1605 PyObject *_args;
1606{
1607 PyObject *_res = NULL;
1608 WindowPtr theWindow;
Jack Jansen2b724171996-04-10 14:48:19 +00001609 RgnHandle updateRegion;
1610 if (!PyArg_ParseTuple(_args, "O&O&",
1611 WinObj_Convert, &theWindow,
1612 ResObj_Convert, &updateRegion))
Guido van Rossum17448e21995-01-30 11:53:55 +00001613 return NULL;
1614 UpdateControls(theWindow,
Jack Jansen2b724171996-04-10 14:48:19 +00001615 updateRegion);
Guido van Rossum17448e21995-01-30 11:53:55 +00001616 Py_INCREF(Py_None);
1617 _res = Py_None;
1618 return _res;
1619}
1620
1621static PyObject *Ctl_FindControl(_self, _args)
1622 PyObject *_self;
1623 PyObject *_args;
1624{
1625 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +00001626 ControlPartCode _rv;
Jack Jansen21f96871998-02-20 16:02:09 +00001627 Point testPoint;
Guido van Rossum17448e21995-01-30 11:53:55 +00001628 WindowPtr theWindow;
1629 ControlHandle theControl;
1630 if (!PyArg_ParseTuple(_args, "O&O&",
Jack Jansen21f96871998-02-20 16:02:09 +00001631 PyMac_GetPoint, &testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00001632 WinObj_Convert, &theWindow))
1633 return NULL;
Jack Jansen21f96871998-02-20 16:02:09 +00001634 _rv = FindControl(testPoint,
Guido van Rossum17448e21995-01-30 11:53:55 +00001635 theWindow,
1636 &theControl);
1637 _res = Py_BuildValue("hO&",
1638 _rv,
1639 CtlObj_WhichControl, theControl);
1640 return _res;
1641}
1642
Jack Jansen21f96871998-02-20 16:02:09 +00001643static PyObject *Ctl_FindControlUnderMouse(_self, _args)
1644 PyObject *_self;
1645 PyObject *_args;
1646{
1647 PyObject *_res = NULL;
1648 ControlHandle _rv;
1649 Point inWhere;
1650 WindowPtr inWindow;
1651 SInt16 outPart;
1652 if (!PyArg_ParseTuple(_args, "O&O&",
1653 PyMac_GetPoint, &inWhere,
1654 WinObj_Convert, &inWindow))
1655 return NULL;
1656 _rv = FindControlUnderMouse(inWhere,
1657 inWindow,
1658 &outPart);
1659 _res = Py_BuildValue("O&h",
1660 CtlObj_New, _rv,
1661 outPart);
1662 return _res;
1663}
1664
1665static PyObject *Ctl_IdleControls(_self, _args)
1666 PyObject *_self;
1667 PyObject *_args;
1668{
1669 PyObject *_res = NULL;
1670 WindowPtr inWindow;
1671 if (!PyArg_ParseTuple(_args, "O&",
1672 WinObj_Convert, &inWindow))
1673 return NULL;
1674 IdleControls(inWindow);
1675 Py_INCREF(Py_None);
1676 _res = Py_None;
1677 return _res;
1678}
1679
1680static PyObject *Ctl_DumpControlHierarchy(_self, _args)
1681 PyObject *_self;
1682 PyObject *_args;
1683{
1684 PyObject *_res = NULL;
1685 OSErr _err;
1686 WindowPtr inWindow;
1687 FSSpec inDumpFile;
1688 if (!PyArg_ParseTuple(_args, "O&O&",
1689 WinObj_Convert, &inWindow,
1690 PyMac_GetFSSpec, &inDumpFile))
1691 return NULL;
1692 _err = DumpControlHierarchy(inWindow,
1693 &inDumpFile);
1694 if (_err != noErr) return PyMac_Error(_err);
1695 Py_INCREF(Py_None);
1696 _res = Py_None;
1697 return _res;
1698}
1699
1700static PyObject *Ctl_CreateRootControl(_self, _args)
1701 PyObject *_self;
1702 PyObject *_args;
1703{
1704 PyObject *_res = NULL;
1705 OSErr _err;
1706 WindowPtr inWindow;
1707 ControlHandle outControl;
1708 if (!PyArg_ParseTuple(_args, "O&",
1709 WinObj_Convert, &inWindow))
1710 return NULL;
1711 _err = CreateRootControl(inWindow,
1712 &outControl);
1713 if (_err != noErr) return PyMac_Error(_err);
1714 _res = Py_BuildValue("O&",
1715 CtlObj_WhichControl, outControl);
1716 return _res;
1717}
1718
1719static PyObject *Ctl_GetRootControl(_self, _args)
1720 PyObject *_self;
1721 PyObject *_args;
1722{
1723 PyObject *_res = NULL;
1724 OSErr _err;
1725 WindowPtr inWindow;
1726 ControlHandle outControl;
1727 if (!PyArg_ParseTuple(_args, "O&",
1728 WinObj_Convert, &inWindow))
1729 return NULL;
1730 _err = GetRootControl(inWindow,
1731 &outControl);
1732 if (_err != noErr) return PyMac_Error(_err);
1733 _res = Py_BuildValue("O&",
1734 CtlObj_WhichControl, outControl);
1735 return _res;
1736}
1737
1738static PyObject *Ctl_GetKeyboardFocus(_self, _args)
1739 PyObject *_self;
1740 PyObject *_args;
1741{
1742 PyObject *_res = NULL;
1743 OSErr _err;
1744 WindowPtr inWindow;
1745 ControlHandle outControl;
1746 if (!PyArg_ParseTuple(_args, "O&",
1747 WinObj_Convert, &inWindow))
1748 return NULL;
1749 _err = GetKeyboardFocus(inWindow,
1750 &outControl);
1751 if (_err != noErr) return PyMac_Error(_err);
1752 _res = Py_BuildValue("O&",
1753 CtlObj_WhichControl, outControl);
1754 return _res;
1755}
1756
1757static PyObject *Ctl_SetKeyboardFocus(_self, _args)
1758 PyObject *_self;
1759 PyObject *_args;
1760{
1761 PyObject *_res = NULL;
1762 OSErr _err;
1763 WindowPtr inWindow;
1764 ControlHandle inControl;
1765 ControlFocusPart inPart;
1766 if (!PyArg_ParseTuple(_args, "O&O&h",
1767 WinObj_Convert, &inWindow,
1768 CtlObj_Convert, &inControl,
1769 &inPart))
1770 return NULL;
1771 _err = SetKeyboardFocus(inWindow,
1772 inControl,
1773 inPart);
1774 if (_err != noErr) return PyMac_Error(_err);
1775 Py_INCREF(Py_None);
1776 _res = Py_None;
1777 return _res;
1778}
1779
1780static PyObject *Ctl_AdvanceKeyboardFocus(_self, _args)
1781 PyObject *_self;
1782 PyObject *_args;
1783{
1784 PyObject *_res = NULL;
1785 OSErr _err;
1786 WindowPtr inWindow;
1787 if (!PyArg_ParseTuple(_args, "O&",
1788 WinObj_Convert, &inWindow))
1789 return NULL;
1790 _err = AdvanceKeyboardFocus(inWindow);
1791 if (_err != noErr) return PyMac_Error(_err);
1792 Py_INCREF(Py_None);
1793 _res = Py_None;
1794 return _res;
1795}
1796
1797static PyObject *Ctl_ReverseKeyboardFocus(_self, _args)
1798 PyObject *_self;
1799 PyObject *_args;
1800{
1801 PyObject *_res = NULL;
1802 OSErr _err;
1803 WindowPtr inWindow;
1804 if (!PyArg_ParseTuple(_args, "O&",
1805 WinObj_Convert, &inWindow))
1806 return NULL;
1807 _err = ReverseKeyboardFocus(inWindow);
1808 if (_err != noErr) return PyMac_Error(_err);
1809 Py_INCREF(Py_None);
1810 _res = Py_None;
1811 return _res;
1812}
1813
1814static PyObject *Ctl_ClearKeyboardFocus(_self, _args)
1815 PyObject *_self;
1816 PyObject *_args;
1817{
1818 PyObject *_res = NULL;
1819 OSErr _err;
1820 WindowPtr inWindow;
1821 if (!PyArg_ParseTuple(_args, "O&",
1822 WinObj_Convert, &inWindow))
1823 return NULL;
1824 _err = ClearKeyboardFocus(inWindow);
1825 if (_err != noErr) return PyMac_Error(_err);
1826 Py_INCREF(Py_None);
1827 _res = Py_None;
1828 return _res;
1829}
1830
Jack Jansene0581891999-02-07 14:02:03 +00001831static PyObject *Ctl_as_Control(_self, _args)
1832 PyObject *_self;
1833 PyObject *_args;
1834{
1835 PyObject *_res = NULL;
1836 ControlHandle _rv;
1837 Handle h;
1838 if (!PyArg_ParseTuple(_args, "O&",
1839 ResObj_Convert, &h))
1840 return NULL;
1841 _rv = as_Control(h);
1842 _res = Py_BuildValue("O&",
1843 CtlObj_New, _rv);
1844 return _res;
1845}
1846
Guido van Rossum17448e21995-01-30 11:53:55 +00001847static PyMethodDef Ctl_methods[] = {
1848 {"NewControl", (PyCFunction)Ctl_NewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001849 "(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 +00001850 {"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001851 "(SInt16 resourceID, WindowPtr owningWindow) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001852 {"DrawControls", (PyCFunction)Ctl_DrawControls, 1,
1853 "(WindowPtr theWindow) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001854 {"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1,
Jack Jansen2b724171996-04-10 14:48:19 +00001855 "(WindowPtr theWindow, RgnHandle updateRegion) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001856 {"FindControl", (PyCFunction)Ctl_FindControl, 1,
Jack Jansen21f96871998-02-20 16:02:09 +00001857 "(Point testPoint, WindowPtr theWindow) -> (ControlPartCode _rv, ControlHandle theControl)"},
1858 {"FindControlUnderMouse", (PyCFunction)Ctl_FindControlUnderMouse, 1,
1859 "(Point inWhere, WindowPtr inWindow) -> (ControlHandle _rv, SInt16 outPart)"},
1860 {"IdleControls", (PyCFunction)Ctl_IdleControls, 1,
1861 "(WindowPtr inWindow) -> None"},
1862 {"DumpControlHierarchy", (PyCFunction)Ctl_DumpControlHierarchy, 1,
1863 "(WindowPtr inWindow, FSSpec inDumpFile) -> None"},
1864 {"CreateRootControl", (PyCFunction)Ctl_CreateRootControl, 1,
1865 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
1866 {"GetRootControl", (PyCFunction)Ctl_GetRootControl, 1,
1867 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
1868 {"GetKeyboardFocus", (PyCFunction)Ctl_GetKeyboardFocus, 1,
1869 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
1870 {"SetKeyboardFocus", (PyCFunction)Ctl_SetKeyboardFocus, 1,
1871 "(WindowPtr inWindow, ControlHandle inControl, ControlFocusPart inPart) -> None"},
1872 {"AdvanceKeyboardFocus", (PyCFunction)Ctl_AdvanceKeyboardFocus, 1,
1873 "(WindowPtr inWindow) -> None"},
1874 {"ReverseKeyboardFocus", (PyCFunction)Ctl_ReverseKeyboardFocus, 1,
1875 "(WindowPtr inWindow) -> None"},
1876 {"ClearKeyboardFocus", (PyCFunction)Ctl_ClearKeyboardFocus, 1,
1877 "(WindowPtr inWindow) -> None"},
Jack Jansene0581891999-02-07 14:02:03 +00001878 {"as_Control", (PyCFunction)Ctl_as_Control, 1,
1879 "(Handle h) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +00001880 {NULL, NULL, 0}
1881};
1882
1883
1884
Jack Jansen8387af61999-03-13 23:07:32 +00001885PyObject *CtlObj_NewUnmanaged(itself)
1886 ControlHandle itself;
1887{
1888 ControlObject *it;
1889 if (itself == NULL) return PyMac_Error(resNotFound);
1890 it = PyObject_NEW(ControlObject, &Control_Type);
1891 if (it == NULL) return NULL;
1892 it->ob_itself = itself;
1893 return (PyObject *)it;
1894}
1895
Guido van Rossum17448e21995-01-30 11:53:55 +00001896PyObject *
1897CtlObj_WhichControl(ControlHandle c)
1898{
1899 PyObject *it;
Jack Jansen24c35311999-12-09 22:49:51 +00001900
Guido van Rossum17448e21995-01-30 11:53:55 +00001901 if (c == NULL)
Guido van Rossum17448e21995-01-30 11:53:55 +00001902 it = Py_None;
Jack Jansen8387af61999-03-13 23:07:32 +00001903 else {
1904 it = (PyObject *) GetControlReference(c);
1905 /*
1906 ** If the refcon is zero or doesn't point back to the Python object
1907 ** the control is not ours. Return a temporary object.
1908 */
1909 if (it == NULL || ((ControlObject *)it)->ob_itself != c)
1910 return CtlObj_NewUnmanaged(c);
1911 }
Guido van Rossum17448e21995-01-30 11:53:55 +00001912 Py_INCREF(it);
1913 return it;
1914}
1915
Jack Jansen848250c1998-05-28 14:20:09 +00001916static int
1917settrackfunc(obj)
1918 PyObject *obj;
1919{
1920 if (tracker) {
1921 PyErr_SetString(Ctl_Error, "Tracker function in use");
1922 return 0;
1923 }
1924 tracker = obj;
1925 Py_INCREF(tracker);
1926}
1927
1928static void
1929clrtrackfunc()
1930{
1931 Py_XDECREF(tracker);
1932 tracker = 0;
1933}
1934
1935static pascal void
1936mytracker(ctl, part)
1937 ControlHandle ctl;
1938 short part;
1939{
1940 PyObject *args, *rv=0;
Jack Jansen24c35311999-12-09 22:49:51 +00001941
Jack Jansen848250c1998-05-28 14:20:09 +00001942 args = Py_BuildValue("(O&i)", CtlObj_WhichControl, ctl, (int)part);
1943 if (args && tracker) {
1944 rv = PyEval_CallObject(tracker, args);
1945 Py_DECREF(args);
1946 }
1947 if (rv)
1948 Py_DECREF(rv);
1949 else
Jack Jansen24c35311999-12-09 22:49:51 +00001950 PySys_WriteStderr("TrackControl or HandleControlClick: exception in tracker function\n");
Jack Jansen848250c1998-05-28 14:20:09 +00001951}
1952
Jack Jansenabc411b2000-03-20 16:09:09 +00001953static int
1954setcallback(self, which, callback, uppp)
1955 ControlObject *self;
1956 OSType which;
1957 PyObject *callback;
1958 UniversalProcPtr *uppp;
1959{
1960 char keybuf[9];
1961
1962 if ( which == kControlUserPaneDrawProcTag )
1963 *uppp = mydrawproc_upp;
1964 else if ( which == kControlUserPaneIdleProcTag )
1965 *uppp = myidleproc_upp;
1966 else
1967 return -1;
1968 /* Only now do we test for clearing of the callback: */
1969 if ( callback == Py_None )
1970 *uppp = NULL;
1971 /* Create the dict if it doesn't exist yet (so we don't get such a dict for every control) */
1972 if ( self->ob_callbackdict == NULL )
1973 if ( (self->ob_callbackdict = PyDict_New()) == NULL )
1974 return -1;
1975 /* And store the Python callback */
1976 sprintf(keybuf, "%x", which);
1977 if (PyDict_SetItemString(self->ob_callbackdict, keybuf, callback) < 0)
1978 return -1;
1979 return 0;
1980}
1981
1982static PyObject *
1983callcallback(self, which, arglist)
1984 ControlObject *self;
1985 OSType which;
1986 PyObject *arglist;
1987{
1988 char keybuf[9];
1989 PyObject *func, *rv;
1990
1991 sprintf(keybuf, "%x", which);
1992 if ( self->ob_callbackdict == NULL ||
1993 (func = PyDict_GetItemString(self->ob_callbackdict, keybuf)) == NULL ) {
1994 PySys_WriteStderr("Control callback without callback object\n");
1995 return NULL;
1996 }
1997 rv = PyEval_CallObject(func, arglist);
1998 if ( rv == NULL )
1999 PySys_WriteStderr("Exception in control callback handler\n");
2000 return rv;
2001}
2002
2003static pascal void
2004mydrawproc(ControlHandle control, SInt16 part)
2005{
2006 ControlObject *ctl_obj;
2007 PyObject *arglist, *rv;
2008
2009 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
2010 arglist = Py_BuildValue("Oh", ctl_obj, part);
2011 rv = callcallback(ctl_obj, kControlUserPaneDrawProcTag, arglist);
2012 Py_XDECREF(arglist);
2013 Py_XDECREF(rv);
2014}
2015
2016static pascal void
2017myidleproc(ControlHandle control)
2018{
2019 ControlObject *ctl_obj;
2020 PyObject *arglist, *rv;
2021
2022 ctl_obj = (ControlObject *)CtlObj_WhichControl(control);
2023 arglist = Py_BuildValue("O", ctl_obj);
2024 rv = callcallback(ctl_obj, kControlUserPaneIdleProcTag, arglist);
2025 Py_XDECREF(arglist);
2026 Py_XDECREF(rv);
2027}
2028
2029
Guido van Rossum17448e21995-01-30 11:53:55 +00002030
2031void initCtl()
2032{
2033 PyObject *m;
2034 PyObject *d;
2035
2036
2037
Jack Jansen848250c1998-05-28 14:20:09 +00002038 mytracker_upp = NewControlActionProc(mytracker);
Jack Jansenabc411b2000-03-20 16:09:09 +00002039 mydrawproc_upp = NewControlUserPaneDrawProc(mydrawproc);
2040 myidleproc_upp = NewControlUserPaneDrawProc(myidleproc);
Jack Jansen848250c1998-05-28 14:20:09 +00002041
Guido van Rossum17448e21995-01-30 11:53:55 +00002042
2043 m = Py_InitModule("Ctl", Ctl_methods);
2044 d = PyModule_GetDict(m);
2045 Ctl_Error = PyMac_GetOSErrException();
2046 if (Ctl_Error == NULL ||
2047 PyDict_SetItemString(d, "Error", Ctl_Error) != 0)
2048 Py_FatalError("can't initialize Ctl.Error");
Jack Jansena755e681997-09-20 17:40:22 +00002049 Control_Type.ob_type = &PyType_Type;
2050 Py_INCREF(&Control_Type);
2051 if (PyDict_SetItemString(d, "ControlType", (PyObject *)&Control_Type) != 0)
2052 Py_FatalError("can't initialize ControlType");
Guido van Rossum17448e21995-01-30 11:53:55 +00002053}
2054
2055/* ========================= End module Ctl ========================= */
2056