blob: 7267cd7880f8d3a08974da4b383357633305770f [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 *);
18
19extern PyObject *WinObj_New(WindowPtr);
20extern int WinObj_Convert(PyObject *, WindowPtr *);
21
22extern PyObject *DlgObj_New(DialogPtr);
23extern int DlgObj_Convert(PyObject *, DialogPtr *);
24extern PyTypeObject Dialog_Type;
25#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
26
27extern PyObject *MenuObj_New(MenuHandle);
28extern int MenuObj_Convert(PyObject *, MenuHandle *);
29
30extern PyObject *CtlObj_New(ControlHandle);
31extern int CtlObj_Convert(PyObject *, ControlHandle *);
32
33extern PyObject *WinObj_WhichWindow(WindowPtr);
34
35#include <Controls.h>
36
37#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
38
39extern PyObject *CtlObj_WhichControl(ControlHandle); /* Forward */
40
41#ifdef THINK_C
42#define ControlActionUPP ProcPtr
43#endif
44
45static PyObject *Ctl_Error;
46
47/* ---------------------- Object type Control ----------------------- */
48
49PyTypeObject Control_Type;
50
51#define CtlObj_Check(x) ((x)->ob_type == &Control_Type)
52
53typedef struct ControlObject {
54 PyObject_HEAD
55 ControlHandle ob_itself;
56} ControlObject;
57
58PyObject *CtlObj_New(itself)
Jack Jansenae8a68f1995-06-06 12:55:40 +000059 ControlHandle itself;
Guido van Rossum17448e21995-01-30 11:53:55 +000060{
61 ControlObject *it;
62 if (itself == NULL) return PyMac_Error(resNotFound);
63 it = PyObject_NEW(ControlObject, &Control_Type);
64 if (it == NULL) return NULL;
65 it->ob_itself = itself;
66 SetCRefCon(itself, (long)it);
67 return (PyObject *)it;
68}
69CtlObj_Convert(v, p_itself)
70 PyObject *v;
71 ControlHandle *p_itself;
72{
73 if (!CtlObj_Check(v))
74 {
75 PyErr_SetString(PyExc_TypeError, "Control required");
76 return 0;
77 }
78 *p_itself = ((ControlObject *)v)->ob_itself;
79 return 1;
80}
81
82static void CtlObj_dealloc(self)
83 ControlObject *self;
84{
85 /* Cleanup of self->ob_itself goes here */
86 PyMem_DEL(self);
87}
88
Jack Jansen7d0bc831995-06-09 20:56:31 +000089static PyObject *CtlObj_DisposeControl(_self, _args)
90 ControlObject *_self;
91 PyObject *_args;
92{
93 PyObject *_res = NULL;
94 if (!PyArg_ParseTuple(_args, ""))
95 return NULL;
96 DisposeControl(_self->ob_itself);
97 Py_INCREF(Py_None);
98 _res = Py_None;
99 return _res;
100}
101
102static PyObject *CtlObj_ShowControl(_self, _args)
103 ControlObject *_self;
104 PyObject *_args;
105{
106 PyObject *_res = NULL;
107 if (!PyArg_ParseTuple(_args, ""))
108 return NULL;
109 ShowControl(_self->ob_itself);
110 Py_INCREF(Py_None);
111 _res = Py_None;
112 return _res;
113}
114
115static PyObject *CtlObj_HideControl(_self, _args)
116 ControlObject *_self;
117 PyObject *_args;
118{
119 PyObject *_res = NULL;
120 if (!PyArg_ParseTuple(_args, ""))
121 return NULL;
122 HideControl(_self->ob_itself);
123 Py_INCREF(Py_None);
124 _res = Py_None;
125 return _res;
126}
127
128static PyObject *CtlObj_Draw1Control(_self, _args)
129 ControlObject *_self;
130 PyObject *_args;
131{
132 PyObject *_res = NULL;
133 if (!PyArg_ParseTuple(_args, ""))
134 return NULL;
135 Draw1Control(_self->ob_itself);
136 Py_INCREF(Py_None);
137 _res = Py_None;
138 return _res;
139}
140
141static PyObject *CtlObj_HiliteControl(_self, _args)
142 ControlObject *_self;
143 PyObject *_args;
144{
145 PyObject *_res = NULL;
146 ControlPartCode hiliteState;
147 if (!PyArg_ParseTuple(_args, "h",
148 &hiliteState))
149 return NULL;
150 HiliteControl(_self->ob_itself,
151 hiliteState);
152 Py_INCREF(Py_None);
153 _res = Py_None;
154 return _res;
155}
156
157static PyObject *CtlObj_TrackControl(_self, _args)
158 ControlObject *_self;
159 PyObject *_args;
160{
161 PyObject *_res = NULL;
162 ControlPartCode _rv;
163 Point thePoint;
164 if (!PyArg_ParseTuple(_args, "O&",
165 PyMac_GetPoint, &thePoint))
166 return NULL;
167 _rv = TrackControl(_self->ob_itself,
168 thePoint,
169 (ControlActionUPP)0);
170 _res = Py_BuildValue("h",
171 _rv);
172 return _res;
173}
174
175static PyObject *CtlObj_DragControl(_self, _args)
176 ControlObject *_self;
177 PyObject *_args;
178{
179 PyObject *_res = NULL;
180 Point startPt;
181 Rect limitRect;
182 Rect slopRect;
183 DragConstraint axis;
184 if (!PyArg_ParseTuple(_args, "O&O&O&h",
185 PyMac_GetPoint, &startPt,
186 PyMac_GetRect, &limitRect,
187 PyMac_GetRect, &slopRect,
188 &axis))
189 return NULL;
190 DragControl(_self->ob_itself,
191 startPt,
192 &limitRect,
193 &slopRect,
194 axis);
195 Py_INCREF(Py_None);
196 _res = Py_None;
197 return _res;
198}
199
200static PyObject *CtlObj_TestControl(_self, _args)
201 ControlObject *_self;
202 PyObject *_args;
203{
204 PyObject *_res = NULL;
205 ControlPartCode _rv;
206 Point thePt;
207 if (!PyArg_ParseTuple(_args, "O&",
208 PyMac_GetPoint, &thePt))
209 return NULL;
210 _rv = TestControl(_self->ob_itself,
211 thePt);
212 _res = Py_BuildValue("h",
213 _rv);
214 return _res;
215}
216
217static PyObject *CtlObj_MoveControl(_self, _args)
218 ControlObject *_self;
219 PyObject *_args;
220{
221 PyObject *_res = NULL;
222 SInt16 h;
223 SInt16 v;
224 if (!PyArg_ParseTuple(_args, "hh",
225 &h,
226 &v))
227 return NULL;
228 MoveControl(_self->ob_itself,
229 h,
230 v);
231 Py_INCREF(Py_None);
232 _res = Py_None;
233 return _res;
234}
235
236static PyObject *CtlObj_SizeControl(_self, _args)
237 ControlObject *_self;
238 PyObject *_args;
239{
240 PyObject *_res = NULL;
241 SInt16 w;
242 SInt16 h;
243 if (!PyArg_ParseTuple(_args, "hh",
244 &w,
245 &h))
246 return NULL;
247 SizeControl(_self->ob_itself,
248 w,
249 h);
250 Py_INCREF(Py_None);
251 _res = Py_None;
252 return _res;
253}
254
Jack Jansenae8a68f1995-06-06 12:55:40 +0000255static PyObject *CtlObj_SetControlTitle(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000256 ControlObject *_self;
257 PyObject *_args;
258{
259 PyObject *_res = NULL;
260 Str255 title;
261 if (!PyArg_ParseTuple(_args, "O&",
262 PyMac_GetStr255, title))
263 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000264 SetControlTitle(_self->ob_itself,
265 title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000266 Py_INCREF(Py_None);
267 _res = Py_None;
268 return _res;
269}
270
Jack Jansenae8a68f1995-06-06 12:55:40 +0000271static PyObject *CtlObj_GetControlTitle(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000272 ControlObject *_self;
273 PyObject *_args;
274{
275 PyObject *_res = NULL;
276 Str255 title;
277 if (!PyArg_ParseTuple(_args, "O&",
278 PyMac_GetStr255, title))
279 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000280 GetControlTitle(_self->ob_itself,
281 title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000282 Py_INCREF(Py_None);
283 _res = Py_None;
284 return _res;
285}
286
Jack Jansenae8a68f1995-06-06 12:55:40 +0000287static PyObject *CtlObj_GetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000288 ControlObject *_self;
289 PyObject *_args;
290{
291 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000292 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000293 if (!PyArg_ParseTuple(_args, ""))
294 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000295 _rv = GetControlValue(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000296 _res = Py_BuildValue("h",
297 _rv);
298 return _res;
299}
300
Jack Jansen7d0bc831995-06-09 20:56:31 +0000301static PyObject *CtlObj_SetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000302 ControlObject *_self;
303 PyObject *_args;
304{
305 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000306 SInt16 newValue;
Guido van Rossum17448e21995-01-30 11:53:55 +0000307 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000308 &newValue))
Guido van Rossum17448e21995-01-30 11:53:55 +0000309 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000310 SetControlValue(_self->ob_itself,
311 newValue);
Guido van Rossum17448e21995-01-30 11:53:55 +0000312 Py_INCREF(Py_None);
313 _res = Py_None;
314 return _res;
315}
316
Jack Jansenae8a68f1995-06-06 12:55:40 +0000317static PyObject *CtlObj_GetControlMinimum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000318 ControlObject *_self;
319 PyObject *_args;
320{
321 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000322 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000323 if (!PyArg_ParseTuple(_args, ""))
324 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000325 _rv = GetControlMinimum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000326 _res = Py_BuildValue("h",
327 _rv);
328 return _res;
329}
330
Jack Jansen7d0bc831995-06-09 20:56:31 +0000331static PyObject *CtlObj_SetControlMinimum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000332 ControlObject *_self;
333 PyObject *_args;
334{
335 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000336 SInt16 newMinimum;
Guido van Rossum17448e21995-01-30 11:53:55 +0000337 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000338 &newMinimum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000339 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000340 SetControlMinimum(_self->ob_itself,
341 newMinimum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000342 Py_INCREF(Py_None);
343 _res = Py_None;
344 return _res;
345}
346
Jack Jansenae8a68f1995-06-06 12:55:40 +0000347static PyObject *CtlObj_GetControlMaximum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000348 ControlObject *_self;
349 PyObject *_args;
350{
351 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000352 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000353 if (!PyArg_ParseTuple(_args, ""))
354 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000355 _rv = GetControlMaximum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000356 _res = Py_BuildValue("h",
357 _rv);
358 return _res;
359}
360
Jack Jansen7d0bc831995-06-09 20:56:31 +0000361static PyObject *CtlObj_SetControlMaximum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000362 ControlObject *_self;
363 PyObject *_args;
364{
365 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000366 SInt16 newMaximum;
367 if (!PyArg_ParseTuple(_args, "h",
368 &newMaximum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000369 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000370 SetControlMaximum(_self->ob_itself,
371 newMaximum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000372 Py_INCREF(Py_None);
373 _res = Py_None;
374 return _res;
375}
376
Jack Jansen7d0bc831995-06-09 20:56:31 +0000377static PyObject *CtlObj_GetControlVariant(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000378 ControlObject *_self;
379 PyObject *_args;
380{
381 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000382 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000383 if (!PyArg_ParseTuple(_args, ""))
384 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000385 _rv = GetControlVariant(_self->ob_itself);
386 _res = Py_BuildValue("h",
Guido van Rossum17448e21995-01-30 11:53:55 +0000387 _rv);
388 return _res;
389}
390
Jack Jansenae8a68f1995-06-06 12:55:40 +0000391static PyObject *CtlObj_SetControlAction(_self, _args)
392 ControlObject *_self;
393 PyObject *_args;
394{
395 PyObject *_res = NULL;
396 if (!PyArg_ParseTuple(_args, ""))
397 return NULL;
398 SetControlAction(_self->ob_itself,
399 (ControlActionUPP)0);
400 Py_INCREF(Py_None);
401 _res = Py_None;
402 return _res;
403}
404
Jack Jansen7d0bc831995-06-09 20:56:31 +0000405static PyObject *CtlObj_SetControlReference(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000406 ControlObject *_self;
407 PyObject *_args;
408{
409 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000410 SInt32 data;
411 if (!PyArg_ParseTuple(_args, "l",
412 &data))
Guido van Rossum17448e21995-01-30 11:53:55 +0000413 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000414 SetControlReference(_self->ob_itself,
415 data);
Guido van Rossum17448e21995-01-30 11:53:55 +0000416 Py_INCREF(Py_None);
417 _res = Py_None;
418 return _res;
419}
420
Jack Jansen7d0bc831995-06-09 20:56:31 +0000421static PyObject *CtlObj_GetControlReference(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000422 ControlObject *_self;
423 PyObject *_args;
424{
425 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000426 SInt32 _rv;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000427 if (!PyArg_ParseTuple(_args, ""))
428 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000429 _rv = GetControlReference(_self->ob_itself);
430 _res = Py_BuildValue("l",
Guido van Rossum17448e21995-01-30 11:53:55 +0000431 _rv);
432 return _res;
433}
434
Jack Jansen5d56f4b1995-06-18 20:16:33 +0000435static PyObject *CtlObj_as_Resource(_self, _args)
436 ControlObject *_self;
437 PyObject *_args;
438{
439 PyObject *_res = NULL;
440
441 return ResObj_New((Handle)_self->ob_itself);
442
443}
444
Guido van Rossum17448e21995-01-30 11:53:55 +0000445static PyMethodDef CtlObj_methods[] = {
Guido van Rossum17448e21995-01-30 11:53:55 +0000446 {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1,
447 "() -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000448 {"ShowControl", (PyCFunction)CtlObj_ShowControl, 1,
449 "() -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000450 {"HideControl", (PyCFunction)CtlObj_HideControl, 1,
451 "() -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000452 {"Draw1Control", (PyCFunction)CtlObj_Draw1Control, 1,
453 "() -> None"},
454 {"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000455 "(ControlPartCode hiliteState) -> None"},
456 {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1,
457 "(Point thePoint) -> (ControlPartCode _rv)"},
458 {"DragControl", (PyCFunction)CtlObj_DragControl, 1,
459 "(Point startPt, Rect limitRect, Rect slopRect, DragConstraint axis) -> None"},
460 {"TestControl", (PyCFunction)CtlObj_TestControl, 1,
461 "(Point thePt) -> (ControlPartCode _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000462 {"MoveControl", (PyCFunction)CtlObj_MoveControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000463 "(SInt16 h, SInt16 v) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000464 {"SizeControl", (PyCFunction)CtlObj_SizeControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000465 "(SInt16 w, SInt16 h) -> None"},
466 {"SetControlTitle", (PyCFunction)CtlObj_SetControlTitle, 1,
467 "(Str255 title) -> None"},
468 {"GetControlTitle", (PyCFunction)CtlObj_GetControlTitle, 1,
469 "(Str255 title) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000470 {"GetControlValue", (PyCFunction)CtlObj_GetControlValue, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000471 "() -> (SInt16 _rv)"},
472 {"SetControlValue", (PyCFunction)CtlObj_SetControlValue, 1,
473 "(SInt16 newValue) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000474 {"GetControlMinimum", (PyCFunction)CtlObj_GetControlMinimum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000475 "() -> (SInt16 _rv)"},
476 {"SetControlMinimum", (PyCFunction)CtlObj_SetControlMinimum, 1,
477 "(SInt16 newMinimum) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000478 {"GetControlMaximum", (PyCFunction)CtlObj_GetControlMaximum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000479 "() -> (SInt16 _rv)"},
480 {"SetControlMaximum", (PyCFunction)CtlObj_SetControlMaximum, 1,
481 "(SInt16 newMaximum) -> None"},
482 {"GetControlVariant", (PyCFunction)CtlObj_GetControlVariant, 1,
483 "() -> (SInt16 _rv)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000484 {"SetControlAction", (PyCFunction)CtlObj_SetControlAction, 1,
485 "() -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000486 {"SetControlReference", (PyCFunction)CtlObj_SetControlReference, 1,
487 "(SInt32 data) -> None"},
488 {"GetControlReference", (PyCFunction)CtlObj_GetControlReference, 1,
489 "() -> (SInt32 _rv)"},
Jack Jansen5d56f4b1995-06-18 20:16:33 +0000490 {"as_Resource", (PyCFunction)CtlObj_as_Resource, 1,
491 "Return this Control as a Resource"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000492 {NULL, NULL, 0}
493};
494
495PyMethodChain CtlObj_chain = { CtlObj_methods, NULL };
496
497static PyObject *CtlObj_getattr(self, name)
498 ControlObject *self;
499 char *name;
500{
501 return Py_FindMethodInChain(&CtlObj_chain, (PyObject *)self, name);
502}
503
504#define CtlObj_setattr NULL
505
506PyTypeObject Control_Type = {
507 PyObject_HEAD_INIT(&PyType_Type)
508 0, /*ob_size*/
509 "Control", /*tp_name*/
510 sizeof(ControlObject), /*tp_basicsize*/
511 0, /*tp_itemsize*/
512 /* methods */
513 (destructor) CtlObj_dealloc, /*tp_dealloc*/
514 0, /*tp_print*/
515 (getattrfunc) CtlObj_getattr, /*tp_getattr*/
516 (setattrfunc) CtlObj_setattr, /*tp_setattr*/
517};
518
519/* -------------------- End object type Control --------------------- */
520
521
522static PyObject *Ctl_NewControl(_self, _args)
523 PyObject *_self;
524 PyObject *_args;
525{
526 PyObject *_res = NULL;
527 ControlHandle _rv;
528 WindowPtr theWindow;
529 Rect boundsRect;
530 Str255 title;
531 Boolean visible;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000532 SInt16 value;
533 SInt16 min;
534 SInt16 max;
535 SInt16 procID;
536 SInt32 refCon;
Guido van Rossum17448e21995-01-30 11:53:55 +0000537 if (!PyArg_ParseTuple(_args, "O&O&O&bhhhhl",
538 WinObj_Convert, &theWindow,
539 PyMac_GetRect, &boundsRect,
540 PyMac_GetStr255, title,
541 &visible,
542 &value,
543 &min,
544 &max,
545 &procID,
546 &refCon))
547 return NULL;
548 _rv = NewControl(theWindow,
549 &boundsRect,
550 title,
551 visible,
552 value,
553 min,
554 max,
555 procID,
556 refCon);
557 _res = Py_BuildValue("O&",
558 CtlObj_New, _rv);
559 return _res;
560}
561
562static PyObject *Ctl_GetNewControl(_self, _args)
563 PyObject *_self;
564 PyObject *_args;
565{
566 PyObject *_res = NULL;
567 ControlHandle _rv;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000568 SInt16 controlID;
Guido van Rossum17448e21995-01-30 11:53:55 +0000569 WindowPtr owner;
570 if (!PyArg_ParseTuple(_args, "hO&",
571 &controlID,
572 WinObj_Convert, &owner))
573 return NULL;
574 _rv = GetNewControl(controlID,
575 owner);
576 _res = Py_BuildValue("O&",
577 CtlObj_New, _rv);
578 return _res;
579}
580
581static PyObject *Ctl_KillControls(_self, _args)
582 PyObject *_self;
583 PyObject *_args;
584{
585 PyObject *_res = NULL;
586 WindowPtr theWindow;
587 if (!PyArg_ParseTuple(_args, "O&",
588 WinObj_Convert, &theWindow))
589 return NULL;
590 KillControls(theWindow);
591 Py_INCREF(Py_None);
592 _res = Py_None;
593 return _res;
594}
595
596static PyObject *Ctl_DrawControls(_self, _args)
597 PyObject *_self;
598 PyObject *_args;
599{
600 PyObject *_res = NULL;
601 WindowPtr theWindow;
602 if (!PyArg_ParseTuple(_args, "O&",
603 WinObj_Convert, &theWindow))
604 return NULL;
605 DrawControls(theWindow);
606 Py_INCREF(Py_None);
607 _res = Py_None;
608 return _res;
609}
610
Guido van Rossum17448e21995-01-30 11:53:55 +0000611static PyObject *Ctl_UpdateControls(_self, _args)
612 PyObject *_self;
613 PyObject *_args;
614{
615 PyObject *_res = NULL;
616 WindowPtr theWindow;
617 if (!PyArg_ParseTuple(_args, "O&",
618 WinObj_Convert, &theWindow))
619 return NULL;
620 UpdateControls(theWindow,
621 theWindow->visRgn);
622 Py_INCREF(Py_None);
623 _res = Py_None;
624 return _res;
625}
626
627static PyObject *Ctl_FindControl(_self, _args)
628 PyObject *_self;
629 PyObject *_args;
630{
631 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000632 ControlPartCode _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000633 Point thePoint;
634 WindowPtr theWindow;
635 ControlHandle theControl;
636 if (!PyArg_ParseTuple(_args, "O&O&",
637 PyMac_GetPoint, &thePoint,
638 WinObj_Convert, &theWindow))
639 return NULL;
640 _rv = FindControl(thePoint,
641 theWindow,
642 &theControl);
643 _res = Py_BuildValue("hO&",
644 _rv,
645 CtlObj_WhichControl, theControl);
646 return _res;
647}
648
649static PyMethodDef Ctl_methods[] = {
650 {"NewControl", (PyCFunction)Ctl_NewControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000651 "(WindowPtr theWindow, Rect boundsRect, Str255 title, Boolean visible, SInt16 value, SInt16 min, SInt16 max, SInt16 procID, SInt32 refCon) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000652 {"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000653 "(SInt16 controlID, WindowPtr owner) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000654 {"KillControls", (PyCFunction)Ctl_KillControls, 1,
655 "(WindowPtr theWindow) -> None"},
656 {"DrawControls", (PyCFunction)Ctl_DrawControls, 1,
657 "(WindowPtr theWindow) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000658 {"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1,
659 "(WindowPtr theWindow) -> None"},
660 {"FindControl", (PyCFunction)Ctl_FindControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000661 "(Point thePoint, WindowPtr theWindow) -> (ControlPartCode _rv, ControlHandle theControl)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000662 {NULL, NULL, 0}
663};
664
665
666
667PyObject *
668CtlObj_WhichControl(ControlHandle c)
669{
670 PyObject *it;
671
672 /* XXX What if we find a control belonging to some other package? */
673 if (c == NULL)
674 it = NULL;
675 else
676 it = (PyObject *) GetCRefCon(c);
677 if (it == NULL || ((ControlObject *)it)->ob_itself != c)
678 it = Py_None;
679 Py_INCREF(it);
680 return it;
681}
682
683
684void initCtl()
685{
686 PyObject *m;
687 PyObject *d;
688
689
690
691
692 m = Py_InitModule("Ctl", Ctl_methods);
693 d = PyModule_GetDict(m);
694 Ctl_Error = PyMac_GetOSErrException();
695 if (Ctl_Error == NULL ||
696 PyDict_SetItemString(d, "Error", Ctl_Error) != 0)
697 Py_FatalError("can't initialize Ctl.Error");
698}
699
700/* ========================= End module Ctl ========================= */
701