blob: ed37de0744ff39063fba7f813e9758a1da1003cb [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
Guido van Rossum17448e21995-01-30 11:53:55 +0000435static PyMethodDef CtlObj_methods[] = {
Guido van Rossum17448e21995-01-30 11:53:55 +0000436 {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1,
437 "() -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000438 {"ShowControl", (PyCFunction)CtlObj_ShowControl, 1,
439 "() -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000440 {"HideControl", (PyCFunction)CtlObj_HideControl, 1,
441 "() -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000442 {"Draw1Control", (PyCFunction)CtlObj_Draw1Control, 1,
443 "() -> None"},
444 {"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000445 "(ControlPartCode hiliteState) -> None"},
446 {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1,
447 "(Point thePoint) -> (ControlPartCode _rv)"},
448 {"DragControl", (PyCFunction)CtlObj_DragControl, 1,
449 "(Point startPt, Rect limitRect, Rect slopRect, DragConstraint axis) -> None"},
450 {"TestControl", (PyCFunction)CtlObj_TestControl, 1,
451 "(Point thePt) -> (ControlPartCode _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000452 {"MoveControl", (PyCFunction)CtlObj_MoveControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000453 "(SInt16 h, SInt16 v) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000454 {"SizeControl", (PyCFunction)CtlObj_SizeControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000455 "(SInt16 w, SInt16 h) -> None"},
456 {"SetControlTitle", (PyCFunction)CtlObj_SetControlTitle, 1,
457 "(Str255 title) -> None"},
458 {"GetControlTitle", (PyCFunction)CtlObj_GetControlTitle, 1,
459 "(Str255 title) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000460 {"GetControlValue", (PyCFunction)CtlObj_GetControlValue, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000461 "() -> (SInt16 _rv)"},
462 {"SetControlValue", (PyCFunction)CtlObj_SetControlValue, 1,
463 "(SInt16 newValue) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000464 {"GetControlMinimum", (PyCFunction)CtlObj_GetControlMinimum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000465 "() -> (SInt16 _rv)"},
466 {"SetControlMinimum", (PyCFunction)CtlObj_SetControlMinimum, 1,
467 "(SInt16 newMinimum) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000468 {"GetControlMaximum", (PyCFunction)CtlObj_GetControlMaximum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000469 "() -> (SInt16 _rv)"},
470 {"SetControlMaximum", (PyCFunction)CtlObj_SetControlMaximum, 1,
471 "(SInt16 newMaximum) -> None"},
472 {"GetControlVariant", (PyCFunction)CtlObj_GetControlVariant, 1,
473 "() -> (SInt16 _rv)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000474 {"SetControlAction", (PyCFunction)CtlObj_SetControlAction, 1,
475 "() -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000476 {"SetControlReference", (PyCFunction)CtlObj_SetControlReference, 1,
477 "(SInt32 data) -> None"},
478 {"GetControlReference", (PyCFunction)CtlObj_GetControlReference, 1,
479 "() -> (SInt32 _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000480 {NULL, NULL, 0}
481};
482
483PyMethodChain CtlObj_chain = { CtlObj_methods, NULL };
484
485static PyObject *CtlObj_getattr(self, name)
486 ControlObject *self;
487 char *name;
488{
489 return Py_FindMethodInChain(&CtlObj_chain, (PyObject *)self, name);
490}
491
492#define CtlObj_setattr NULL
493
494PyTypeObject Control_Type = {
495 PyObject_HEAD_INIT(&PyType_Type)
496 0, /*ob_size*/
497 "Control", /*tp_name*/
498 sizeof(ControlObject), /*tp_basicsize*/
499 0, /*tp_itemsize*/
500 /* methods */
501 (destructor) CtlObj_dealloc, /*tp_dealloc*/
502 0, /*tp_print*/
503 (getattrfunc) CtlObj_getattr, /*tp_getattr*/
504 (setattrfunc) CtlObj_setattr, /*tp_setattr*/
505};
506
507/* -------------------- End object type Control --------------------- */
508
509
510static PyObject *Ctl_NewControl(_self, _args)
511 PyObject *_self;
512 PyObject *_args;
513{
514 PyObject *_res = NULL;
515 ControlHandle _rv;
516 WindowPtr theWindow;
517 Rect boundsRect;
518 Str255 title;
519 Boolean visible;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000520 SInt16 value;
521 SInt16 min;
522 SInt16 max;
523 SInt16 procID;
524 SInt32 refCon;
Guido van Rossum17448e21995-01-30 11:53:55 +0000525 if (!PyArg_ParseTuple(_args, "O&O&O&bhhhhl",
526 WinObj_Convert, &theWindow,
527 PyMac_GetRect, &boundsRect,
528 PyMac_GetStr255, title,
529 &visible,
530 &value,
531 &min,
532 &max,
533 &procID,
534 &refCon))
535 return NULL;
536 _rv = NewControl(theWindow,
537 &boundsRect,
538 title,
539 visible,
540 value,
541 min,
542 max,
543 procID,
544 refCon);
545 _res = Py_BuildValue("O&",
546 CtlObj_New, _rv);
547 return _res;
548}
549
550static PyObject *Ctl_GetNewControl(_self, _args)
551 PyObject *_self;
552 PyObject *_args;
553{
554 PyObject *_res = NULL;
555 ControlHandle _rv;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000556 SInt16 controlID;
Guido van Rossum17448e21995-01-30 11:53:55 +0000557 WindowPtr owner;
558 if (!PyArg_ParseTuple(_args, "hO&",
559 &controlID,
560 WinObj_Convert, &owner))
561 return NULL;
562 _rv = GetNewControl(controlID,
563 owner);
564 _res = Py_BuildValue("O&",
565 CtlObj_New, _rv);
566 return _res;
567}
568
569static PyObject *Ctl_KillControls(_self, _args)
570 PyObject *_self;
571 PyObject *_args;
572{
573 PyObject *_res = NULL;
574 WindowPtr theWindow;
575 if (!PyArg_ParseTuple(_args, "O&",
576 WinObj_Convert, &theWindow))
577 return NULL;
578 KillControls(theWindow);
579 Py_INCREF(Py_None);
580 _res = Py_None;
581 return _res;
582}
583
584static PyObject *Ctl_DrawControls(_self, _args)
585 PyObject *_self;
586 PyObject *_args;
587{
588 PyObject *_res = NULL;
589 WindowPtr theWindow;
590 if (!PyArg_ParseTuple(_args, "O&",
591 WinObj_Convert, &theWindow))
592 return NULL;
593 DrawControls(theWindow);
594 Py_INCREF(Py_None);
595 _res = Py_None;
596 return _res;
597}
598
Guido van Rossum17448e21995-01-30 11:53:55 +0000599static PyObject *Ctl_UpdateControls(_self, _args)
600 PyObject *_self;
601 PyObject *_args;
602{
603 PyObject *_res = NULL;
604 WindowPtr theWindow;
605 if (!PyArg_ParseTuple(_args, "O&",
606 WinObj_Convert, &theWindow))
607 return NULL;
608 UpdateControls(theWindow,
609 theWindow->visRgn);
610 Py_INCREF(Py_None);
611 _res = Py_None;
612 return _res;
613}
614
615static PyObject *Ctl_FindControl(_self, _args)
616 PyObject *_self;
617 PyObject *_args;
618{
619 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000620 ControlPartCode _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000621 Point thePoint;
622 WindowPtr theWindow;
623 ControlHandle theControl;
624 if (!PyArg_ParseTuple(_args, "O&O&",
625 PyMac_GetPoint, &thePoint,
626 WinObj_Convert, &theWindow))
627 return NULL;
628 _rv = FindControl(thePoint,
629 theWindow,
630 &theControl);
631 _res = Py_BuildValue("hO&",
632 _rv,
633 CtlObj_WhichControl, theControl);
634 return _res;
635}
636
637static PyMethodDef Ctl_methods[] = {
638 {"NewControl", (PyCFunction)Ctl_NewControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000639 "(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 +0000640 {"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000641 "(SInt16 controlID, WindowPtr owner) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000642 {"KillControls", (PyCFunction)Ctl_KillControls, 1,
643 "(WindowPtr theWindow) -> None"},
644 {"DrawControls", (PyCFunction)Ctl_DrawControls, 1,
645 "(WindowPtr theWindow) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000646 {"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1,
647 "(WindowPtr theWindow) -> None"},
648 {"FindControl", (PyCFunction)Ctl_FindControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000649 "(Point thePoint, WindowPtr theWindow) -> (ControlPartCode _rv, ControlHandle theControl)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000650 {NULL, NULL, 0}
651};
652
653
654
655PyObject *
656CtlObj_WhichControl(ControlHandle c)
657{
658 PyObject *it;
659
660 /* XXX What if we find a control belonging to some other package? */
661 if (c == NULL)
662 it = NULL;
663 else
664 it = (PyObject *) GetCRefCon(c);
665 if (it == NULL || ((ControlObject *)it)->ob_itself != c)
666 it = Py_None;
667 Py_INCREF(it);
668 return it;
669}
670
671
672void initCtl()
673{
674 PyObject *m;
675 PyObject *d;
676
677
678
679
680 m = Py_InitModule("Ctl", Ctl_methods);
681 d = PyModule_GetDict(m);
682 Ctl_Error = PyMac_GetOSErrException();
683 if (Ctl_Error == NULL ||
684 PyDict_SetItemString(d, "Error", Ctl_Error) != 0)
685 Py_FatalError("can't initialize Ctl.Error");
686}
687
688/* ========================= End module Ctl ========================= */
689