blob: bc690cd9bc48f1d9062d1aa91073f05925362c04 [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
Jack Jansen2b724171996-04-10 14:48:19 +000043extern PyObject *PMObj_New(PixMapHandle);
44extern int PMObj_Convert(PyObject *, PixMapHandle *);
45
Guido van Rossum17448e21995-01-30 11:53:55 +000046extern PyObject *WinObj_WhichWindow(WindowPtr);
47
48#include <Controls.h>
49
50#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
51
52extern PyObject *CtlObj_WhichControl(ControlHandle); /* Forward */
53
54#ifdef THINK_C
55#define ControlActionUPP ProcPtr
56#endif
57
58static PyObject *Ctl_Error;
59
60/* ---------------------- Object type Control ----------------------- */
61
62PyTypeObject Control_Type;
63
64#define CtlObj_Check(x) ((x)->ob_type == &Control_Type)
65
66typedef struct ControlObject {
67 PyObject_HEAD
68 ControlHandle ob_itself;
69} ControlObject;
70
71PyObject *CtlObj_New(itself)
Jack Jansenae8a68f1995-06-06 12:55:40 +000072 ControlHandle itself;
Guido van Rossum17448e21995-01-30 11:53:55 +000073{
74 ControlObject *it;
75 if (itself == NULL) return PyMac_Error(resNotFound);
76 it = PyObject_NEW(ControlObject, &Control_Type);
77 if (it == NULL) return NULL;
78 it->ob_itself = itself;
79 SetCRefCon(itself, (long)it);
80 return (PyObject *)it;
81}
82CtlObj_Convert(v, p_itself)
83 PyObject *v;
84 ControlHandle *p_itself;
85{
86 if (!CtlObj_Check(v))
87 {
88 PyErr_SetString(PyExc_TypeError, "Control required");
89 return 0;
90 }
91 *p_itself = ((ControlObject *)v)->ob_itself;
92 return 1;
93}
94
95static void CtlObj_dealloc(self)
96 ControlObject *self;
97{
98 /* Cleanup of self->ob_itself goes here */
99 PyMem_DEL(self);
100}
101
Jack Jansen7d0bc831995-06-09 20:56:31 +0000102static PyObject *CtlObj_DisposeControl(_self, _args)
103 ControlObject *_self;
104 PyObject *_args;
105{
106 PyObject *_res = NULL;
107 if (!PyArg_ParseTuple(_args, ""))
108 return NULL;
109 DisposeControl(_self->ob_itself);
110 Py_INCREF(Py_None);
111 _res = Py_None;
112 return _res;
113}
114
115static PyObject *CtlObj_ShowControl(_self, _args)
116 ControlObject *_self;
117 PyObject *_args;
118{
119 PyObject *_res = NULL;
120 if (!PyArg_ParseTuple(_args, ""))
121 return NULL;
122 ShowControl(_self->ob_itself);
123 Py_INCREF(Py_None);
124 _res = Py_None;
125 return _res;
126}
127
128static PyObject *CtlObj_HideControl(_self, _args)
129 ControlObject *_self;
130 PyObject *_args;
131{
132 PyObject *_res = NULL;
133 if (!PyArg_ParseTuple(_args, ""))
134 return NULL;
135 HideControl(_self->ob_itself);
136 Py_INCREF(Py_None);
137 _res = Py_None;
138 return _res;
139}
140
141static PyObject *CtlObj_Draw1Control(_self, _args)
142 ControlObject *_self;
143 PyObject *_args;
144{
145 PyObject *_res = NULL;
146 if (!PyArg_ParseTuple(_args, ""))
147 return NULL;
148 Draw1Control(_self->ob_itself);
149 Py_INCREF(Py_None);
150 _res = Py_None;
151 return _res;
152}
153
154static PyObject *CtlObj_HiliteControl(_self, _args)
155 ControlObject *_self;
156 PyObject *_args;
157{
158 PyObject *_res = NULL;
159 ControlPartCode hiliteState;
160 if (!PyArg_ParseTuple(_args, "h",
161 &hiliteState))
162 return NULL;
163 HiliteControl(_self->ob_itself,
164 hiliteState);
165 Py_INCREF(Py_None);
166 _res = Py_None;
167 return _res;
168}
169
170static PyObject *CtlObj_TrackControl(_self, _args)
171 ControlObject *_self;
172 PyObject *_args;
173{
174 PyObject *_res = NULL;
175 ControlPartCode _rv;
176 Point thePoint;
177 if (!PyArg_ParseTuple(_args, "O&",
178 PyMac_GetPoint, &thePoint))
179 return NULL;
180 _rv = TrackControl(_self->ob_itself,
181 thePoint,
182 (ControlActionUPP)0);
183 _res = Py_BuildValue("h",
184 _rv);
185 return _res;
186}
187
188static PyObject *CtlObj_DragControl(_self, _args)
189 ControlObject *_self;
190 PyObject *_args;
191{
192 PyObject *_res = NULL;
Jack Jansen754d4a41995-11-14 10:41:55 +0000193 Point startPoint;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000194 Rect limitRect;
195 Rect slopRect;
196 DragConstraint axis;
197 if (!PyArg_ParseTuple(_args, "O&O&O&h",
Jack Jansen754d4a41995-11-14 10:41:55 +0000198 PyMac_GetPoint, &startPoint,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000199 PyMac_GetRect, &limitRect,
200 PyMac_GetRect, &slopRect,
201 &axis))
202 return NULL;
203 DragControl(_self->ob_itself,
Jack Jansen754d4a41995-11-14 10:41:55 +0000204 startPoint,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000205 &limitRect,
206 &slopRect,
207 axis);
208 Py_INCREF(Py_None);
209 _res = Py_None;
210 return _res;
211}
212
213static PyObject *CtlObj_TestControl(_self, _args)
214 ControlObject *_self;
215 PyObject *_args;
216{
217 PyObject *_res = NULL;
218 ControlPartCode _rv;
Jack Jansen754d4a41995-11-14 10:41:55 +0000219 Point thePoint;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000220 if (!PyArg_ParseTuple(_args, "O&",
Jack Jansen754d4a41995-11-14 10:41:55 +0000221 PyMac_GetPoint, &thePoint))
Jack Jansen7d0bc831995-06-09 20:56:31 +0000222 return NULL;
223 _rv = TestControl(_self->ob_itself,
Jack Jansen754d4a41995-11-14 10:41:55 +0000224 thePoint);
Jack Jansen7d0bc831995-06-09 20:56:31 +0000225 _res = Py_BuildValue("h",
226 _rv);
227 return _res;
228}
229
230static PyObject *CtlObj_MoveControl(_self, _args)
231 ControlObject *_self;
232 PyObject *_args;
233{
234 PyObject *_res = NULL;
235 SInt16 h;
236 SInt16 v;
237 if (!PyArg_ParseTuple(_args, "hh",
238 &h,
239 &v))
240 return NULL;
241 MoveControl(_self->ob_itself,
242 h,
243 v);
244 Py_INCREF(Py_None);
245 _res = Py_None;
246 return _res;
247}
248
249static PyObject *CtlObj_SizeControl(_self, _args)
250 ControlObject *_self;
251 PyObject *_args;
252{
253 PyObject *_res = NULL;
254 SInt16 w;
255 SInt16 h;
256 if (!PyArg_ParseTuple(_args, "hh",
257 &w,
258 &h))
259 return NULL;
260 SizeControl(_self->ob_itself,
261 w,
262 h);
263 Py_INCREF(Py_None);
264 _res = Py_None;
265 return _res;
266}
267
Jack Jansenae8a68f1995-06-06 12:55:40 +0000268static PyObject *CtlObj_SetControlTitle(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000269 ControlObject *_self;
270 PyObject *_args;
271{
272 PyObject *_res = NULL;
273 Str255 title;
274 if (!PyArg_ParseTuple(_args, "O&",
275 PyMac_GetStr255, title))
276 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000277 SetControlTitle(_self->ob_itself,
278 title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000279 Py_INCREF(Py_None);
280 _res = Py_None;
281 return _res;
282}
283
Jack Jansenae8a68f1995-06-06 12:55:40 +0000284static PyObject *CtlObj_GetControlTitle(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000285 ControlObject *_self;
286 PyObject *_args;
287{
288 PyObject *_res = NULL;
289 Str255 title;
290 if (!PyArg_ParseTuple(_args, "O&",
291 PyMac_GetStr255, title))
292 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000293 GetControlTitle(_self->ob_itself,
294 title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000295 Py_INCREF(Py_None);
296 _res = Py_None;
297 return _res;
298}
299
Jack Jansenae8a68f1995-06-06 12:55:40 +0000300static PyObject *CtlObj_GetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000301 ControlObject *_self;
302 PyObject *_args;
303{
304 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000305 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000306 if (!PyArg_ParseTuple(_args, ""))
307 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000308 _rv = GetControlValue(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000309 _res = Py_BuildValue("h",
310 _rv);
311 return _res;
312}
313
Jack Jansen7d0bc831995-06-09 20:56:31 +0000314static PyObject *CtlObj_SetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000315 ControlObject *_self;
316 PyObject *_args;
317{
318 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000319 SInt16 newValue;
Guido van Rossum17448e21995-01-30 11:53:55 +0000320 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000321 &newValue))
Guido van Rossum17448e21995-01-30 11:53:55 +0000322 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000323 SetControlValue(_self->ob_itself,
324 newValue);
Guido van Rossum17448e21995-01-30 11:53:55 +0000325 Py_INCREF(Py_None);
326 _res = Py_None;
327 return _res;
328}
329
Jack Jansenae8a68f1995-06-06 12:55:40 +0000330static PyObject *CtlObj_GetControlMinimum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000331 ControlObject *_self;
332 PyObject *_args;
333{
334 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000335 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000336 if (!PyArg_ParseTuple(_args, ""))
337 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000338 _rv = GetControlMinimum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000339 _res = Py_BuildValue("h",
340 _rv);
341 return _res;
342}
343
Jack Jansen7d0bc831995-06-09 20:56:31 +0000344static PyObject *CtlObj_SetControlMinimum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000345 ControlObject *_self;
346 PyObject *_args;
347{
348 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000349 SInt16 newMinimum;
Guido van Rossum17448e21995-01-30 11:53:55 +0000350 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000351 &newMinimum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000352 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000353 SetControlMinimum(_self->ob_itself,
354 newMinimum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000355 Py_INCREF(Py_None);
356 _res = Py_None;
357 return _res;
358}
359
Jack Jansenae8a68f1995-06-06 12:55:40 +0000360static PyObject *CtlObj_GetControlMaximum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000361 ControlObject *_self;
362 PyObject *_args;
363{
364 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000365 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000366 if (!PyArg_ParseTuple(_args, ""))
367 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000368 _rv = GetControlMaximum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000369 _res = Py_BuildValue("h",
370 _rv);
371 return _res;
372}
373
Jack Jansen7d0bc831995-06-09 20:56:31 +0000374static PyObject *CtlObj_SetControlMaximum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000375 ControlObject *_self;
376 PyObject *_args;
377{
378 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000379 SInt16 newMaximum;
380 if (!PyArg_ParseTuple(_args, "h",
381 &newMaximum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000382 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000383 SetControlMaximum(_self->ob_itself,
384 newMaximum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000385 Py_INCREF(Py_None);
386 _res = Py_None;
387 return _res;
388}
389
Jack Jansen7d0bc831995-06-09 20:56:31 +0000390static PyObject *CtlObj_GetControlVariant(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000391 ControlObject *_self;
392 PyObject *_args;
393{
394 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000395 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000396 if (!PyArg_ParseTuple(_args, ""))
397 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000398 _rv = GetControlVariant(_self->ob_itself);
399 _res = Py_BuildValue("h",
Guido van Rossum17448e21995-01-30 11:53:55 +0000400 _rv);
401 return _res;
402}
403
Jack Jansenae8a68f1995-06-06 12:55:40 +0000404static PyObject *CtlObj_SetControlAction(_self, _args)
405 ControlObject *_self;
406 PyObject *_args;
407{
408 PyObject *_res = NULL;
409 if (!PyArg_ParseTuple(_args, ""))
410 return NULL;
411 SetControlAction(_self->ob_itself,
412 (ControlActionUPP)0);
413 Py_INCREF(Py_None);
414 _res = Py_None;
415 return _res;
416}
417
Jack Jansen7d0bc831995-06-09 20:56:31 +0000418static PyObject *CtlObj_SetControlReference(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000419 ControlObject *_self;
420 PyObject *_args;
421{
422 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000423 SInt32 data;
424 if (!PyArg_ParseTuple(_args, "l",
425 &data))
Guido van Rossum17448e21995-01-30 11:53:55 +0000426 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000427 SetControlReference(_self->ob_itself,
428 data);
Guido van Rossum17448e21995-01-30 11:53:55 +0000429 Py_INCREF(Py_None);
430 _res = Py_None;
431 return _res;
432}
433
Jack Jansen7d0bc831995-06-09 20:56:31 +0000434static PyObject *CtlObj_GetControlReference(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000435 ControlObject *_self;
436 PyObject *_args;
437{
438 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000439 SInt32 _rv;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000440 if (!PyArg_ParseTuple(_args, ""))
441 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000442 _rv = GetControlReference(_self->ob_itself);
443 _res = Py_BuildValue("l",
Guido van Rossum17448e21995-01-30 11:53:55 +0000444 _rv);
445 return _res;
446}
447
Jack Jansen5d56f4b1995-06-18 20:16:33 +0000448static PyObject *CtlObj_as_Resource(_self, _args)
449 ControlObject *_self;
450 PyObject *_args;
451{
452 PyObject *_res = NULL;
453
454 return ResObj_New((Handle)_self->ob_itself);
455
456}
457
Guido van Rossum17448e21995-01-30 11:53:55 +0000458static PyMethodDef CtlObj_methods[] = {
Guido van Rossum17448e21995-01-30 11:53:55 +0000459 {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1,
460 "() -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000461 {"ShowControl", (PyCFunction)CtlObj_ShowControl, 1,
462 "() -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000463 {"HideControl", (PyCFunction)CtlObj_HideControl, 1,
464 "() -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000465 {"Draw1Control", (PyCFunction)CtlObj_Draw1Control, 1,
466 "() -> None"},
467 {"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000468 "(ControlPartCode hiliteState) -> None"},
469 {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1,
470 "(Point thePoint) -> (ControlPartCode _rv)"},
471 {"DragControl", (PyCFunction)CtlObj_DragControl, 1,
Jack Jansen754d4a41995-11-14 10:41:55 +0000472 "(Point startPoint, Rect limitRect, Rect slopRect, DragConstraint axis) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000473 {"TestControl", (PyCFunction)CtlObj_TestControl, 1,
Jack Jansen754d4a41995-11-14 10:41:55 +0000474 "(Point thePoint) -> (ControlPartCode _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000475 {"MoveControl", (PyCFunction)CtlObj_MoveControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000476 "(SInt16 h, SInt16 v) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000477 {"SizeControl", (PyCFunction)CtlObj_SizeControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000478 "(SInt16 w, SInt16 h) -> None"},
479 {"SetControlTitle", (PyCFunction)CtlObj_SetControlTitle, 1,
480 "(Str255 title) -> None"},
481 {"GetControlTitle", (PyCFunction)CtlObj_GetControlTitle, 1,
482 "(Str255 title) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000483 {"GetControlValue", (PyCFunction)CtlObj_GetControlValue, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000484 "() -> (SInt16 _rv)"},
485 {"SetControlValue", (PyCFunction)CtlObj_SetControlValue, 1,
486 "(SInt16 newValue) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000487 {"GetControlMinimum", (PyCFunction)CtlObj_GetControlMinimum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000488 "() -> (SInt16 _rv)"},
489 {"SetControlMinimum", (PyCFunction)CtlObj_SetControlMinimum, 1,
490 "(SInt16 newMinimum) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000491 {"GetControlMaximum", (PyCFunction)CtlObj_GetControlMaximum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000492 "() -> (SInt16 _rv)"},
493 {"SetControlMaximum", (PyCFunction)CtlObj_SetControlMaximum, 1,
494 "(SInt16 newMaximum) -> None"},
495 {"GetControlVariant", (PyCFunction)CtlObj_GetControlVariant, 1,
496 "() -> (SInt16 _rv)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000497 {"SetControlAction", (PyCFunction)CtlObj_SetControlAction, 1,
498 "() -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000499 {"SetControlReference", (PyCFunction)CtlObj_SetControlReference, 1,
500 "(SInt32 data) -> None"},
501 {"GetControlReference", (PyCFunction)CtlObj_GetControlReference, 1,
502 "() -> (SInt32 _rv)"},
Jack Jansen5d56f4b1995-06-18 20:16:33 +0000503 {"as_Resource", (PyCFunction)CtlObj_as_Resource, 1,
504 "Return this Control as a Resource"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000505 {NULL, NULL, 0}
506};
507
508PyMethodChain CtlObj_chain = { CtlObj_methods, NULL };
509
510static PyObject *CtlObj_getattr(self, name)
511 ControlObject *self;
512 char *name;
513{
514 return Py_FindMethodInChain(&CtlObj_chain, (PyObject *)self, name);
515}
516
517#define CtlObj_setattr NULL
518
519PyTypeObject Control_Type = {
520 PyObject_HEAD_INIT(&PyType_Type)
521 0, /*ob_size*/
522 "Control", /*tp_name*/
523 sizeof(ControlObject), /*tp_basicsize*/
524 0, /*tp_itemsize*/
525 /* methods */
526 (destructor) CtlObj_dealloc, /*tp_dealloc*/
527 0, /*tp_print*/
528 (getattrfunc) CtlObj_getattr, /*tp_getattr*/
529 (setattrfunc) CtlObj_setattr, /*tp_setattr*/
530};
531
532/* -------------------- End object type Control --------------------- */
533
534
535static PyObject *Ctl_NewControl(_self, _args)
536 PyObject *_self;
537 PyObject *_args;
538{
539 PyObject *_res = NULL;
540 ControlHandle _rv;
541 WindowPtr theWindow;
542 Rect boundsRect;
543 Str255 title;
544 Boolean visible;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000545 SInt16 value;
546 SInt16 min;
547 SInt16 max;
548 SInt16 procID;
549 SInt32 refCon;
Guido van Rossum17448e21995-01-30 11:53:55 +0000550 if (!PyArg_ParseTuple(_args, "O&O&O&bhhhhl",
551 WinObj_Convert, &theWindow,
552 PyMac_GetRect, &boundsRect,
553 PyMac_GetStr255, title,
554 &visible,
555 &value,
556 &min,
557 &max,
558 &procID,
559 &refCon))
560 return NULL;
561 _rv = NewControl(theWindow,
562 &boundsRect,
563 title,
564 visible,
565 value,
566 min,
567 max,
568 procID,
569 refCon);
570 _res = Py_BuildValue("O&",
571 CtlObj_New, _rv);
572 return _res;
573}
574
575static PyObject *Ctl_GetNewControl(_self, _args)
576 PyObject *_self;
577 PyObject *_args;
578{
579 PyObject *_res = NULL;
580 ControlHandle _rv;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000581 SInt16 controlID;
Guido van Rossum17448e21995-01-30 11:53:55 +0000582 WindowPtr owner;
583 if (!PyArg_ParseTuple(_args, "hO&",
584 &controlID,
585 WinObj_Convert, &owner))
586 return NULL;
587 _rv = GetNewControl(controlID,
588 owner);
589 _res = Py_BuildValue("O&",
590 CtlObj_New, _rv);
591 return _res;
592}
593
594static PyObject *Ctl_KillControls(_self, _args)
595 PyObject *_self;
596 PyObject *_args;
597{
598 PyObject *_res = NULL;
599 WindowPtr theWindow;
600 if (!PyArg_ParseTuple(_args, "O&",
601 WinObj_Convert, &theWindow))
602 return NULL;
603 KillControls(theWindow);
604 Py_INCREF(Py_None);
605 _res = Py_None;
606 return _res;
607}
608
609static PyObject *Ctl_DrawControls(_self, _args)
610 PyObject *_self;
611 PyObject *_args;
612{
613 PyObject *_res = NULL;
614 WindowPtr theWindow;
615 if (!PyArg_ParseTuple(_args, "O&",
616 WinObj_Convert, &theWindow))
617 return NULL;
618 DrawControls(theWindow);
619 Py_INCREF(Py_None);
620 _res = Py_None;
621 return _res;
622}
623
Guido van Rossum17448e21995-01-30 11:53:55 +0000624static PyObject *Ctl_UpdateControls(_self, _args)
625 PyObject *_self;
626 PyObject *_args;
627{
628 PyObject *_res = NULL;
629 WindowPtr theWindow;
Jack Jansen2b724171996-04-10 14:48:19 +0000630 RgnHandle updateRegion;
631 if (!PyArg_ParseTuple(_args, "O&O&",
632 WinObj_Convert, &theWindow,
633 ResObj_Convert, &updateRegion))
Guido van Rossum17448e21995-01-30 11:53:55 +0000634 return NULL;
635 UpdateControls(theWindow,
Jack Jansen2b724171996-04-10 14:48:19 +0000636 updateRegion);
Guido van Rossum17448e21995-01-30 11:53:55 +0000637 Py_INCREF(Py_None);
638 _res = Py_None;
639 return _res;
640}
641
642static PyObject *Ctl_FindControl(_self, _args)
643 PyObject *_self;
644 PyObject *_args;
645{
646 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000647 ControlPartCode _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000648 Point thePoint;
649 WindowPtr theWindow;
650 ControlHandle theControl;
651 if (!PyArg_ParseTuple(_args, "O&O&",
652 PyMac_GetPoint, &thePoint,
653 WinObj_Convert, &theWindow))
654 return NULL;
655 _rv = FindControl(thePoint,
656 theWindow,
657 &theControl);
658 _res = Py_BuildValue("hO&",
659 _rv,
660 CtlObj_WhichControl, theControl);
661 return _res;
662}
663
664static PyMethodDef Ctl_methods[] = {
665 {"NewControl", (PyCFunction)Ctl_NewControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000666 "(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 +0000667 {"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000668 "(SInt16 controlID, WindowPtr owner) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000669 {"KillControls", (PyCFunction)Ctl_KillControls, 1,
670 "(WindowPtr theWindow) -> None"},
671 {"DrawControls", (PyCFunction)Ctl_DrawControls, 1,
672 "(WindowPtr theWindow) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000673 {"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1,
Jack Jansen2b724171996-04-10 14:48:19 +0000674 "(WindowPtr theWindow, RgnHandle updateRegion) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000675 {"FindControl", (PyCFunction)Ctl_FindControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000676 "(Point thePoint, WindowPtr theWindow) -> (ControlPartCode _rv, ControlHandle theControl)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000677 {NULL, NULL, 0}
678};
679
680
681
682PyObject *
683CtlObj_WhichControl(ControlHandle c)
684{
685 PyObject *it;
686
687 /* XXX What if we find a control belonging to some other package? */
688 if (c == NULL)
689 it = NULL;
690 else
691 it = (PyObject *) GetCRefCon(c);
692 if (it == NULL || ((ControlObject *)it)->ob_itself != c)
693 it = Py_None;
694 Py_INCREF(it);
695 return it;
696}
697
698
699void initCtl()
700{
701 PyObject *m;
702 PyObject *d;
703
704
705
706
707 m = Py_InitModule("Ctl", Ctl_methods);
708 d = PyModule_GetDict(m);
709 Ctl_Error = PyMac_GetOSErrException();
710 if (Ctl_Error == NULL ||
711 PyDict_SetItemString(d, "Error", Ctl_Error) != 0)
712 Py_FatalError("can't initialize Ctl.Error");
713}
714
715/* ========================= End module Ctl ========================= */
716