blob: 3ea6b91a229af3e08b82a8995f4660dc72ae57ba [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);
Jack Jansend4c26461995-08-17 14:35:56 +000017extern PyObject *ResObj_OptNew(Handle);
Guido van Rossum17448e21995-01-30 11:53:55 +000018extern int ResObj_Convert(PyObject *, Handle *);
19
20extern PyObject *WinObj_New(WindowPtr);
21extern int WinObj_Convert(PyObject *, WindowPtr *);
22
23extern PyObject *DlgObj_New(DialogPtr);
24extern int DlgObj_Convert(PyObject *, DialogPtr *);
25extern PyTypeObject Dialog_Type;
26#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
27
28extern PyObject *MenuObj_New(MenuHandle);
29extern int MenuObj_Convert(PyObject *, MenuHandle *);
30
31extern PyObject *CtlObj_New(ControlHandle);
32extern int CtlObj_Convert(PyObject *, ControlHandle *);
33
34extern PyObject *WinObj_WhichWindow(WindowPtr);
35
36#include <Controls.h>
37
38#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
39
40extern PyObject *CtlObj_WhichControl(ControlHandle); /* Forward */
41
42#ifdef THINK_C
43#define ControlActionUPP ProcPtr
44#endif
45
46static PyObject *Ctl_Error;
47
48/* ---------------------- Object type Control ----------------------- */
49
50PyTypeObject Control_Type;
51
52#define CtlObj_Check(x) ((x)->ob_type == &Control_Type)
53
54typedef struct ControlObject {
55 PyObject_HEAD
56 ControlHandle ob_itself;
57} ControlObject;
58
59PyObject *CtlObj_New(itself)
Jack Jansenae8a68f1995-06-06 12:55:40 +000060 ControlHandle itself;
Guido van Rossum17448e21995-01-30 11:53:55 +000061{
62 ControlObject *it;
63 if (itself == NULL) return PyMac_Error(resNotFound);
64 it = PyObject_NEW(ControlObject, &Control_Type);
65 if (it == NULL) return NULL;
66 it->ob_itself = itself;
67 SetCRefCon(itself, (long)it);
68 return (PyObject *)it;
69}
70CtlObj_Convert(v, p_itself)
71 PyObject *v;
72 ControlHandle *p_itself;
73{
74 if (!CtlObj_Check(v))
75 {
76 PyErr_SetString(PyExc_TypeError, "Control required");
77 return 0;
78 }
79 *p_itself = ((ControlObject *)v)->ob_itself;
80 return 1;
81}
82
83static void CtlObj_dealloc(self)
84 ControlObject *self;
85{
86 /* Cleanup of self->ob_itself goes here */
87 PyMem_DEL(self);
88}
89
Jack Jansen7d0bc831995-06-09 20:56:31 +000090static PyObject *CtlObj_DisposeControl(_self, _args)
91 ControlObject *_self;
92 PyObject *_args;
93{
94 PyObject *_res = NULL;
95 if (!PyArg_ParseTuple(_args, ""))
96 return NULL;
97 DisposeControl(_self->ob_itself);
98 Py_INCREF(Py_None);
99 _res = Py_None;
100 return _res;
101}
102
103static PyObject *CtlObj_ShowControl(_self, _args)
104 ControlObject *_self;
105 PyObject *_args;
106{
107 PyObject *_res = NULL;
108 if (!PyArg_ParseTuple(_args, ""))
109 return NULL;
110 ShowControl(_self->ob_itself);
111 Py_INCREF(Py_None);
112 _res = Py_None;
113 return _res;
114}
115
116static PyObject *CtlObj_HideControl(_self, _args)
117 ControlObject *_self;
118 PyObject *_args;
119{
120 PyObject *_res = NULL;
121 if (!PyArg_ParseTuple(_args, ""))
122 return NULL;
123 HideControl(_self->ob_itself);
124 Py_INCREF(Py_None);
125 _res = Py_None;
126 return _res;
127}
128
129static PyObject *CtlObj_Draw1Control(_self, _args)
130 ControlObject *_self;
131 PyObject *_args;
132{
133 PyObject *_res = NULL;
134 if (!PyArg_ParseTuple(_args, ""))
135 return NULL;
136 Draw1Control(_self->ob_itself);
137 Py_INCREF(Py_None);
138 _res = Py_None;
139 return _res;
140}
141
142static PyObject *CtlObj_HiliteControl(_self, _args)
143 ControlObject *_self;
144 PyObject *_args;
145{
146 PyObject *_res = NULL;
147 ControlPartCode hiliteState;
148 if (!PyArg_ParseTuple(_args, "h",
149 &hiliteState))
150 return NULL;
151 HiliteControl(_self->ob_itself,
152 hiliteState);
153 Py_INCREF(Py_None);
154 _res = Py_None;
155 return _res;
156}
157
158static PyObject *CtlObj_TrackControl(_self, _args)
159 ControlObject *_self;
160 PyObject *_args;
161{
162 PyObject *_res = NULL;
163 ControlPartCode _rv;
164 Point thePoint;
165 if (!PyArg_ParseTuple(_args, "O&",
166 PyMac_GetPoint, &thePoint))
167 return NULL;
168 _rv = TrackControl(_self->ob_itself,
169 thePoint,
170 (ControlActionUPP)0);
171 _res = Py_BuildValue("h",
172 _rv);
173 return _res;
174}
175
176static PyObject *CtlObj_DragControl(_self, _args)
177 ControlObject *_self;
178 PyObject *_args;
179{
180 PyObject *_res = NULL;
Jack Jansen754d4a41995-11-14 10:41:55 +0000181 Point startPoint;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000182 Rect limitRect;
183 Rect slopRect;
184 DragConstraint axis;
185 if (!PyArg_ParseTuple(_args, "O&O&O&h",
Jack Jansen754d4a41995-11-14 10:41:55 +0000186 PyMac_GetPoint, &startPoint,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000187 PyMac_GetRect, &limitRect,
188 PyMac_GetRect, &slopRect,
189 &axis))
190 return NULL;
191 DragControl(_self->ob_itself,
Jack Jansen754d4a41995-11-14 10:41:55 +0000192 startPoint,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000193 &limitRect,
194 &slopRect,
195 axis);
196 Py_INCREF(Py_None);
197 _res = Py_None;
198 return _res;
199}
200
201static PyObject *CtlObj_TestControl(_self, _args)
202 ControlObject *_self;
203 PyObject *_args;
204{
205 PyObject *_res = NULL;
206 ControlPartCode _rv;
Jack Jansen754d4a41995-11-14 10:41:55 +0000207 Point thePoint;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000208 if (!PyArg_ParseTuple(_args, "O&",
Jack Jansen754d4a41995-11-14 10:41:55 +0000209 PyMac_GetPoint, &thePoint))
Jack Jansen7d0bc831995-06-09 20:56:31 +0000210 return NULL;
211 _rv = TestControl(_self->ob_itself,
Jack Jansen754d4a41995-11-14 10:41:55 +0000212 thePoint);
Jack Jansen7d0bc831995-06-09 20:56:31 +0000213 _res = Py_BuildValue("h",
214 _rv);
215 return _res;
216}
217
218static PyObject *CtlObj_MoveControl(_self, _args)
219 ControlObject *_self;
220 PyObject *_args;
221{
222 PyObject *_res = NULL;
223 SInt16 h;
224 SInt16 v;
225 if (!PyArg_ParseTuple(_args, "hh",
226 &h,
227 &v))
228 return NULL;
229 MoveControl(_self->ob_itself,
230 h,
231 v);
232 Py_INCREF(Py_None);
233 _res = Py_None;
234 return _res;
235}
236
237static PyObject *CtlObj_SizeControl(_self, _args)
238 ControlObject *_self;
239 PyObject *_args;
240{
241 PyObject *_res = NULL;
242 SInt16 w;
243 SInt16 h;
244 if (!PyArg_ParseTuple(_args, "hh",
245 &w,
246 &h))
247 return NULL;
248 SizeControl(_self->ob_itself,
249 w,
250 h);
251 Py_INCREF(Py_None);
252 _res = Py_None;
253 return _res;
254}
255
Jack Jansenae8a68f1995-06-06 12:55:40 +0000256static PyObject *CtlObj_SetControlTitle(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000257 ControlObject *_self;
258 PyObject *_args;
259{
260 PyObject *_res = NULL;
261 Str255 title;
262 if (!PyArg_ParseTuple(_args, "O&",
263 PyMac_GetStr255, title))
264 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000265 SetControlTitle(_self->ob_itself,
266 title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000267 Py_INCREF(Py_None);
268 _res = Py_None;
269 return _res;
270}
271
Jack Jansenae8a68f1995-06-06 12:55:40 +0000272static PyObject *CtlObj_GetControlTitle(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000273 ControlObject *_self;
274 PyObject *_args;
275{
276 PyObject *_res = NULL;
277 Str255 title;
278 if (!PyArg_ParseTuple(_args, "O&",
279 PyMac_GetStr255, title))
280 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000281 GetControlTitle(_self->ob_itself,
282 title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000283 Py_INCREF(Py_None);
284 _res = Py_None;
285 return _res;
286}
287
Jack Jansenae8a68f1995-06-06 12:55:40 +0000288static PyObject *CtlObj_GetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000289 ControlObject *_self;
290 PyObject *_args;
291{
292 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000293 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000294 if (!PyArg_ParseTuple(_args, ""))
295 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000296 _rv = GetControlValue(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000297 _res = Py_BuildValue("h",
298 _rv);
299 return _res;
300}
301
Jack Jansen7d0bc831995-06-09 20:56:31 +0000302static PyObject *CtlObj_SetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000303 ControlObject *_self;
304 PyObject *_args;
305{
306 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000307 SInt16 newValue;
Guido van Rossum17448e21995-01-30 11:53:55 +0000308 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000309 &newValue))
Guido van Rossum17448e21995-01-30 11:53:55 +0000310 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000311 SetControlValue(_self->ob_itself,
312 newValue);
Guido van Rossum17448e21995-01-30 11:53:55 +0000313 Py_INCREF(Py_None);
314 _res = Py_None;
315 return _res;
316}
317
Jack Jansenae8a68f1995-06-06 12:55:40 +0000318static PyObject *CtlObj_GetControlMinimum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000319 ControlObject *_self;
320 PyObject *_args;
321{
322 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000323 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000324 if (!PyArg_ParseTuple(_args, ""))
325 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000326 _rv = GetControlMinimum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000327 _res = Py_BuildValue("h",
328 _rv);
329 return _res;
330}
331
Jack Jansen7d0bc831995-06-09 20:56:31 +0000332static PyObject *CtlObj_SetControlMinimum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000333 ControlObject *_self;
334 PyObject *_args;
335{
336 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000337 SInt16 newMinimum;
Guido van Rossum17448e21995-01-30 11:53:55 +0000338 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000339 &newMinimum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000340 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000341 SetControlMinimum(_self->ob_itself,
342 newMinimum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000343 Py_INCREF(Py_None);
344 _res = Py_None;
345 return _res;
346}
347
Jack Jansenae8a68f1995-06-06 12:55:40 +0000348static PyObject *CtlObj_GetControlMaximum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000349 ControlObject *_self;
350 PyObject *_args;
351{
352 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000353 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000354 if (!PyArg_ParseTuple(_args, ""))
355 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000356 _rv = GetControlMaximum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000357 _res = Py_BuildValue("h",
358 _rv);
359 return _res;
360}
361
Jack Jansen7d0bc831995-06-09 20:56:31 +0000362static PyObject *CtlObj_SetControlMaximum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000363 ControlObject *_self;
364 PyObject *_args;
365{
366 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000367 SInt16 newMaximum;
368 if (!PyArg_ParseTuple(_args, "h",
369 &newMaximum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000370 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000371 SetControlMaximum(_self->ob_itself,
372 newMaximum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000373 Py_INCREF(Py_None);
374 _res = Py_None;
375 return _res;
376}
377
Jack Jansen7d0bc831995-06-09 20:56:31 +0000378static PyObject *CtlObj_GetControlVariant(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000379 ControlObject *_self;
380 PyObject *_args;
381{
382 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000383 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000384 if (!PyArg_ParseTuple(_args, ""))
385 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000386 _rv = GetControlVariant(_self->ob_itself);
387 _res = Py_BuildValue("h",
Guido van Rossum17448e21995-01-30 11:53:55 +0000388 _rv);
389 return _res;
390}
391
Jack Jansenae8a68f1995-06-06 12:55:40 +0000392static PyObject *CtlObj_SetControlAction(_self, _args)
393 ControlObject *_self;
394 PyObject *_args;
395{
396 PyObject *_res = NULL;
397 if (!PyArg_ParseTuple(_args, ""))
398 return NULL;
399 SetControlAction(_self->ob_itself,
400 (ControlActionUPP)0);
401 Py_INCREF(Py_None);
402 _res = Py_None;
403 return _res;
404}
405
Jack Jansen7d0bc831995-06-09 20:56:31 +0000406static PyObject *CtlObj_SetControlReference(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000407 ControlObject *_self;
408 PyObject *_args;
409{
410 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000411 SInt32 data;
412 if (!PyArg_ParseTuple(_args, "l",
413 &data))
Guido van Rossum17448e21995-01-30 11:53:55 +0000414 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000415 SetControlReference(_self->ob_itself,
416 data);
Guido van Rossum17448e21995-01-30 11:53:55 +0000417 Py_INCREF(Py_None);
418 _res = Py_None;
419 return _res;
420}
421
Jack Jansen7d0bc831995-06-09 20:56:31 +0000422static PyObject *CtlObj_GetControlReference(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000423 ControlObject *_self;
424 PyObject *_args;
425{
426 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000427 SInt32 _rv;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000428 if (!PyArg_ParseTuple(_args, ""))
429 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000430 _rv = GetControlReference(_self->ob_itself);
431 _res = Py_BuildValue("l",
Guido van Rossum17448e21995-01-30 11:53:55 +0000432 _rv);
433 return _res;
434}
435
Jack Jansen5d56f4b1995-06-18 20:16:33 +0000436static PyObject *CtlObj_as_Resource(_self, _args)
437 ControlObject *_self;
438 PyObject *_args;
439{
440 PyObject *_res = NULL;
441
442 return ResObj_New((Handle)_self->ob_itself);
443
444}
445
Guido van Rossum17448e21995-01-30 11:53:55 +0000446static PyMethodDef CtlObj_methods[] = {
Guido van Rossum17448e21995-01-30 11:53:55 +0000447 {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1,
448 "() -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000449 {"ShowControl", (PyCFunction)CtlObj_ShowControl, 1,
450 "() -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000451 {"HideControl", (PyCFunction)CtlObj_HideControl, 1,
452 "() -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000453 {"Draw1Control", (PyCFunction)CtlObj_Draw1Control, 1,
454 "() -> None"},
455 {"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000456 "(ControlPartCode hiliteState) -> None"},
457 {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1,
458 "(Point thePoint) -> (ControlPartCode _rv)"},
459 {"DragControl", (PyCFunction)CtlObj_DragControl, 1,
Jack Jansen754d4a41995-11-14 10:41:55 +0000460 "(Point startPoint, Rect limitRect, Rect slopRect, DragConstraint axis) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000461 {"TestControl", (PyCFunction)CtlObj_TestControl, 1,
Jack Jansen754d4a41995-11-14 10:41:55 +0000462 "(Point thePoint) -> (ControlPartCode _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000463 {"MoveControl", (PyCFunction)CtlObj_MoveControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000464 "(SInt16 h, SInt16 v) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000465 {"SizeControl", (PyCFunction)CtlObj_SizeControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000466 "(SInt16 w, SInt16 h) -> None"},
467 {"SetControlTitle", (PyCFunction)CtlObj_SetControlTitle, 1,
468 "(Str255 title) -> None"},
469 {"GetControlTitle", (PyCFunction)CtlObj_GetControlTitle, 1,
470 "(Str255 title) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000471 {"GetControlValue", (PyCFunction)CtlObj_GetControlValue, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000472 "() -> (SInt16 _rv)"},
473 {"SetControlValue", (PyCFunction)CtlObj_SetControlValue, 1,
474 "(SInt16 newValue) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000475 {"GetControlMinimum", (PyCFunction)CtlObj_GetControlMinimum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000476 "() -> (SInt16 _rv)"},
477 {"SetControlMinimum", (PyCFunction)CtlObj_SetControlMinimum, 1,
478 "(SInt16 newMinimum) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000479 {"GetControlMaximum", (PyCFunction)CtlObj_GetControlMaximum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000480 "() -> (SInt16 _rv)"},
481 {"SetControlMaximum", (PyCFunction)CtlObj_SetControlMaximum, 1,
482 "(SInt16 newMaximum) -> None"},
483 {"GetControlVariant", (PyCFunction)CtlObj_GetControlVariant, 1,
484 "() -> (SInt16 _rv)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000485 {"SetControlAction", (PyCFunction)CtlObj_SetControlAction, 1,
486 "() -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000487 {"SetControlReference", (PyCFunction)CtlObj_SetControlReference, 1,
488 "(SInt32 data) -> None"},
489 {"GetControlReference", (PyCFunction)CtlObj_GetControlReference, 1,
490 "() -> (SInt32 _rv)"},
Jack Jansen5d56f4b1995-06-18 20:16:33 +0000491 {"as_Resource", (PyCFunction)CtlObj_as_Resource, 1,
492 "Return this Control as a Resource"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000493 {NULL, NULL, 0}
494};
495
496PyMethodChain CtlObj_chain = { CtlObj_methods, NULL };
497
498static PyObject *CtlObj_getattr(self, name)
499 ControlObject *self;
500 char *name;
501{
502 return Py_FindMethodInChain(&CtlObj_chain, (PyObject *)self, name);
503}
504
505#define CtlObj_setattr NULL
506
507PyTypeObject Control_Type = {
508 PyObject_HEAD_INIT(&PyType_Type)
509 0, /*ob_size*/
510 "Control", /*tp_name*/
511 sizeof(ControlObject), /*tp_basicsize*/
512 0, /*tp_itemsize*/
513 /* methods */
514 (destructor) CtlObj_dealloc, /*tp_dealloc*/
515 0, /*tp_print*/
516 (getattrfunc) CtlObj_getattr, /*tp_getattr*/
517 (setattrfunc) CtlObj_setattr, /*tp_setattr*/
518};
519
520/* -------------------- End object type Control --------------------- */
521
522
523static PyObject *Ctl_NewControl(_self, _args)
524 PyObject *_self;
525 PyObject *_args;
526{
527 PyObject *_res = NULL;
528 ControlHandle _rv;
529 WindowPtr theWindow;
530 Rect boundsRect;
531 Str255 title;
532 Boolean visible;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000533 SInt16 value;
534 SInt16 min;
535 SInt16 max;
536 SInt16 procID;
537 SInt32 refCon;
Guido van Rossum17448e21995-01-30 11:53:55 +0000538 if (!PyArg_ParseTuple(_args, "O&O&O&bhhhhl",
539 WinObj_Convert, &theWindow,
540 PyMac_GetRect, &boundsRect,
541 PyMac_GetStr255, title,
542 &visible,
543 &value,
544 &min,
545 &max,
546 &procID,
547 &refCon))
548 return NULL;
549 _rv = NewControl(theWindow,
550 &boundsRect,
551 title,
552 visible,
553 value,
554 min,
555 max,
556 procID,
557 refCon);
558 _res = Py_BuildValue("O&",
559 CtlObj_New, _rv);
560 return _res;
561}
562
563static PyObject *Ctl_GetNewControl(_self, _args)
564 PyObject *_self;
565 PyObject *_args;
566{
567 PyObject *_res = NULL;
568 ControlHandle _rv;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000569 SInt16 controlID;
Guido van Rossum17448e21995-01-30 11:53:55 +0000570 WindowPtr owner;
571 if (!PyArg_ParseTuple(_args, "hO&",
572 &controlID,
573 WinObj_Convert, &owner))
574 return NULL;
575 _rv = GetNewControl(controlID,
576 owner);
577 _res = Py_BuildValue("O&",
578 CtlObj_New, _rv);
579 return _res;
580}
581
582static PyObject *Ctl_KillControls(_self, _args)
583 PyObject *_self;
584 PyObject *_args;
585{
586 PyObject *_res = NULL;
587 WindowPtr theWindow;
588 if (!PyArg_ParseTuple(_args, "O&",
589 WinObj_Convert, &theWindow))
590 return NULL;
591 KillControls(theWindow);
592 Py_INCREF(Py_None);
593 _res = Py_None;
594 return _res;
595}
596
597static PyObject *Ctl_DrawControls(_self, _args)
598 PyObject *_self;
599 PyObject *_args;
600{
601 PyObject *_res = NULL;
602 WindowPtr theWindow;
603 if (!PyArg_ParseTuple(_args, "O&",
604 WinObj_Convert, &theWindow))
605 return NULL;
606 DrawControls(theWindow);
607 Py_INCREF(Py_None);
608 _res = Py_None;
609 return _res;
610}
611
Guido van Rossum17448e21995-01-30 11:53:55 +0000612static PyObject *Ctl_UpdateControls(_self, _args)
613 PyObject *_self;
614 PyObject *_args;
615{
616 PyObject *_res = NULL;
617 WindowPtr theWindow;
618 if (!PyArg_ParseTuple(_args, "O&",
619 WinObj_Convert, &theWindow))
620 return NULL;
621 UpdateControls(theWindow,
622 theWindow->visRgn);
623 Py_INCREF(Py_None);
624 _res = Py_None;
625 return _res;
626}
627
628static PyObject *Ctl_FindControl(_self, _args)
629 PyObject *_self;
630 PyObject *_args;
631{
632 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000633 ControlPartCode _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000634 Point thePoint;
635 WindowPtr theWindow;
636 ControlHandle theControl;
637 if (!PyArg_ParseTuple(_args, "O&O&",
638 PyMac_GetPoint, &thePoint,
639 WinObj_Convert, &theWindow))
640 return NULL;
641 _rv = FindControl(thePoint,
642 theWindow,
643 &theControl);
644 _res = Py_BuildValue("hO&",
645 _rv,
646 CtlObj_WhichControl, theControl);
647 return _res;
648}
649
650static PyMethodDef Ctl_methods[] = {
651 {"NewControl", (PyCFunction)Ctl_NewControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000652 "(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 +0000653 {"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000654 "(SInt16 controlID, WindowPtr owner) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000655 {"KillControls", (PyCFunction)Ctl_KillControls, 1,
656 "(WindowPtr theWindow) -> None"},
657 {"DrawControls", (PyCFunction)Ctl_DrawControls, 1,
658 "(WindowPtr theWindow) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000659 {"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1,
660 "(WindowPtr theWindow) -> None"},
661 {"FindControl", (PyCFunction)Ctl_FindControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000662 "(Point thePoint, WindowPtr theWindow) -> (ControlPartCode _rv, ControlHandle theControl)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000663 {NULL, NULL, 0}
664};
665
666
667
668PyObject *
669CtlObj_WhichControl(ControlHandle c)
670{
671 PyObject *it;
672
673 /* XXX What if we find a control belonging to some other package? */
674 if (c == NULL)
675 it = NULL;
676 else
677 it = (PyObject *) GetCRefCon(c);
678 if (it == NULL || ((ControlObject *)it)->ob_itself != c)
679 it = Py_None;
680 Py_INCREF(it);
681 return it;
682}
683
684
685void initCtl()
686{
687 PyObject *m;
688 PyObject *d;
689
690
691
692
693 m = Py_InitModule("Ctl", Ctl_methods);
694 d = PyModule_GetDict(m);
695 Ctl_Error = PyMac_GetOSErrException();
696 if (Ctl_Error == NULL ||
697 PyDict_SetItemString(d, "Error", Ctl_Error) != 0)
698 Py_FatalError("can't initialize Ctl.Error");
699}
700
701/* ========================= End module Ctl ========================= */
702