blob: 629d3fb3823888447889ec2892258938d34940d4 [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
47#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
48
49extern PyObject *CtlObj_WhichControl(ControlHandle); /* Forward */
50
51#ifdef THINK_C
52#define ControlActionUPP ProcPtr
53#endif
54
55static PyObject *Ctl_Error;
56
57/* ---------------------- Object type Control ----------------------- */
58
59PyTypeObject Control_Type;
60
61#define CtlObj_Check(x) ((x)->ob_type == &Control_Type)
62
63typedef struct ControlObject {
64 PyObject_HEAD
65 ControlHandle ob_itself;
66} ControlObject;
67
68PyObject *CtlObj_New(itself)
Jack Jansenae8a68f1995-06-06 12:55:40 +000069 ControlHandle itself;
Guido van Rossum17448e21995-01-30 11:53:55 +000070{
71 ControlObject *it;
72 if (itself == NULL) return PyMac_Error(resNotFound);
73 it = PyObject_NEW(ControlObject, &Control_Type);
74 if (it == NULL) return NULL;
75 it->ob_itself = itself;
76 SetCRefCon(itself, (long)it);
77 return (PyObject *)it;
78}
79CtlObj_Convert(v, p_itself)
80 PyObject *v;
81 ControlHandle *p_itself;
82{
83 if (!CtlObj_Check(v))
84 {
85 PyErr_SetString(PyExc_TypeError, "Control required");
86 return 0;
87 }
88 *p_itself = ((ControlObject *)v)->ob_itself;
89 return 1;
90}
91
92static void CtlObj_dealloc(self)
93 ControlObject *self;
94{
Jack Jansenc574b431996-04-12 16:26:59 +000095 SetCRefCon(self->ob_itself, (long)0); /* Make it forget about us */
Guido van Rossum17448e21995-01-30 11:53:55 +000096 PyMem_DEL(self);
97}
98
Jack Jansen7d0bc831995-06-09 20:56:31 +000099static PyObject *CtlObj_DisposeControl(_self, _args)
100 ControlObject *_self;
101 PyObject *_args;
102{
103 PyObject *_res = NULL;
104 if (!PyArg_ParseTuple(_args, ""))
105 return NULL;
106 DisposeControl(_self->ob_itself);
107 Py_INCREF(Py_None);
108 _res = Py_None;
109 return _res;
110}
111
112static PyObject *CtlObj_ShowControl(_self, _args)
113 ControlObject *_self;
114 PyObject *_args;
115{
116 PyObject *_res = NULL;
117 if (!PyArg_ParseTuple(_args, ""))
118 return NULL;
119 ShowControl(_self->ob_itself);
120 Py_INCREF(Py_None);
121 _res = Py_None;
122 return _res;
123}
124
125static PyObject *CtlObj_HideControl(_self, _args)
126 ControlObject *_self;
127 PyObject *_args;
128{
129 PyObject *_res = NULL;
130 if (!PyArg_ParseTuple(_args, ""))
131 return NULL;
132 HideControl(_self->ob_itself);
133 Py_INCREF(Py_None);
134 _res = Py_None;
135 return _res;
136}
137
138static PyObject *CtlObj_Draw1Control(_self, _args)
139 ControlObject *_self;
140 PyObject *_args;
141{
142 PyObject *_res = NULL;
143 if (!PyArg_ParseTuple(_args, ""))
144 return NULL;
145 Draw1Control(_self->ob_itself);
146 Py_INCREF(Py_None);
147 _res = Py_None;
148 return _res;
149}
150
151static PyObject *CtlObj_HiliteControl(_self, _args)
152 ControlObject *_self;
153 PyObject *_args;
154{
155 PyObject *_res = NULL;
156 ControlPartCode hiliteState;
157 if (!PyArg_ParseTuple(_args, "h",
158 &hiliteState))
159 return NULL;
160 HiliteControl(_self->ob_itself,
161 hiliteState);
162 Py_INCREF(Py_None);
163 _res = Py_None;
164 return _res;
165}
166
167static PyObject *CtlObj_TrackControl(_self, _args)
168 ControlObject *_self;
169 PyObject *_args;
170{
171 PyObject *_res = NULL;
172 ControlPartCode _rv;
173 Point thePoint;
174 if (!PyArg_ParseTuple(_args, "O&",
175 PyMac_GetPoint, &thePoint))
176 return NULL;
177 _rv = TrackControl(_self->ob_itself,
178 thePoint,
179 (ControlActionUPP)0);
180 _res = Py_BuildValue("h",
181 _rv);
182 return _res;
183}
184
185static PyObject *CtlObj_DragControl(_self, _args)
186 ControlObject *_self;
187 PyObject *_args;
188{
189 PyObject *_res = NULL;
Jack Jansen754d4a41995-11-14 10:41:55 +0000190 Point startPoint;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000191 Rect limitRect;
192 Rect slopRect;
193 DragConstraint axis;
194 if (!PyArg_ParseTuple(_args, "O&O&O&h",
Jack Jansen754d4a41995-11-14 10:41:55 +0000195 PyMac_GetPoint, &startPoint,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000196 PyMac_GetRect, &limitRect,
197 PyMac_GetRect, &slopRect,
198 &axis))
199 return NULL;
200 DragControl(_self->ob_itself,
Jack Jansen754d4a41995-11-14 10:41:55 +0000201 startPoint,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000202 &limitRect,
203 &slopRect,
204 axis);
205 Py_INCREF(Py_None);
206 _res = Py_None;
207 return _res;
208}
209
210static PyObject *CtlObj_TestControl(_self, _args)
211 ControlObject *_self;
212 PyObject *_args;
213{
214 PyObject *_res = NULL;
215 ControlPartCode _rv;
Jack Jansen754d4a41995-11-14 10:41:55 +0000216 Point thePoint;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000217 if (!PyArg_ParseTuple(_args, "O&",
Jack Jansen754d4a41995-11-14 10:41:55 +0000218 PyMac_GetPoint, &thePoint))
Jack Jansen7d0bc831995-06-09 20:56:31 +0000219 return NULL;
220 _rv = TestControl(_self->ob_itself,
Jack Jansen754d4a41995-11-14 10:41:55 +0000221 thePoint);
Jack Jansen7d0bc831995-06-09 20:56:31 +0000222 _res = Py_BuildValue("h",
223 _rv);
224 return _res;
225}
226
227static PyObject *CtlObj_MoveControl(_self, _args)
228 ControlObject *_self;
229 PyObject *_args;
230{
231 PyObject *_res = NULL;
232 SInt16 h;
233 SInt16 v;
234 if (!PyArg_ParseTuple(_args, "hh",
235 &h,
236 &v))
237 return NULL;
238 MoveControl(_self->ob_itself,
239 h,
240 v);
241 Py_INCREF(Py_None);
242 _res = Py_None;
243 return _res;
244}
245
246static PyObject *CtlObj_SizeControl(_self, _args)
247 ControlObject *_self;
248 PyObject *_args;
249{
250 PyObject *_res = NULL;
251 SInt16 w;
252 SInt16 h;
253 if (!PyArg_ParseTuple(_args, "hh",
254 &w,
255 &h))
256 return NULL;
257 SizeControl(_self->ob_itself,
258 w,
259 h);
260 Py_INCREF(Py_None);
261 _res = Py_None;
262 return _res;
263}
264
Jack Jansenae8a68f1995-06-06 12:55:40 +0000265static PyObject *CtlObj_SetControlTitle(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000266 ControlObject *_self;
267 PyObject *_args;
268{
269 PyObject *_res = NULL;
270 Str255 title;
271 if (!PyArg_ParseTuple(_args, "O&",
272 PyMac_GetStr255, title))
273 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000274 SetControlTitle(_self->ob_itself,
275 title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000276 Py_INCREF(Py_None);
277 _res = Py_None;
278 return _res;
279}
280
Jack Jansenae8a68f1995-06-06 12:55:40 +0000281static PyObject *CtlObj_GetControlTitle(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000282 ControlObject *_self;
283 PyObject *_args;
284{
285 PyObject *_res = NULL;
286 Str255 title;
287 if (!PyArg_ParseTuple(_args, "O&",
288 PyMac_GetStr255, title))
289 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000290 GetControlTitle(_self->ob_itself,
291 title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000292 Py_INCREF(Py_None);
293 _res = Py_None;
294 return _res;
295}
296
Jack Jansenae8a68f1995-06-06 12:55:40 +0000297static PyObject *CtlObj_GetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000298 ControlObject *_self;
299 PyObject *_args;
300{
301 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000302 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000303 if (!PyArg_ParseTuple(_args, ""))
304 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000305 _rv = GetControlValue(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000306 _res = Py_BuildValue("h",
307 _rv);
308 return _res;
309}
310
Jack Jansen7d0bc831995-06-09 20:56:31 +0000311static PyObject *CtlObj_SetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000312 ControlObject *_self;
313 PyObject *_args;
314{
315 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000316 SInt16 newValue;
Guido van Rossum17448e21995-01-30 11:53:55 +0000317 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000318 &newValue))
Guido van Rossum17448e21995-01-30 11:53:55 +0000319 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000320 SetControlValue(_self->ob_itself,
321 newValue);
Guido van Rossum17448e21995-01-30 11:53:55 +0000322 Py_INCREF(Py_None);
323 _res = Py_None;
324 return _res;
325}
326
Jack Jansenae8a68f1995-06-06 12:55:40 +0000327static PyObject *CtlObj_GetControlMinimum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000328 ControlObject *_self;
329 PyObject *_args;
330{
331 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000332 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000333 if (!PyArg_ParseTuple(_args, ""))
334 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000335 _rv = GetControlMinimum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000336 _res = Py_BuildValue("h",
337 _rv);
338 return _res;
339}
340
Jack Jansen7d0bc831995-06-09 20:56:31 +0000341static PyObject *CtlObj_SetControlMinimum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000342 ControlObject *_self;
343 PyObject *_args;
344{
345 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000346 SInt16 newMinimum;
Guido van Rossum17448e21995-01-30 11:53:55 +0000347 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000348 &newMinimum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000349 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000350 SetControlMinimum(_self->ob_itself,
351 newMinimum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000352 Py_INCREF(Py_None);
353 _res = Py_None;
354 return _res;
355}
356
Jack Jansenae8a68f1995-06-06 12:55:40 +0000357static PyObject *CtlObj_GetControlMaximum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000358 ControlObject *_self;
359 PyObject *_args;
360{
361 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000362 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000363 if (!PyArg_ParseTuple(_args, ""))
364 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000365 _rv = GetControlMaximum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000366 _res = Py_BuildValue("h",
367 _rv);
368 return _res;
369}
370
Jack Jansen7d0bc831995-06-09 20:56:31 +0000371static PyObject *CtlObj_SetControlMaximum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000372 ControlObject *_self;
373 PyObject *_args;
374{
375 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000376 SInt16 newMaximum;
377 if (!PyArg_ParseTuple(_args, "h",
378 &newMaximum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000379 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000380 SetControlMaximum(_self->ob_itself,
381 newMaximum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000382 Py_INCREF(Py_None);
383 _res = Py_None;
384 return _res;
385}
386
Jack Jansen7d0bc831995-06-09 20:56:31 +0000387static PyObject *CtlObj_GetControlVariant(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000388 ControlObject *_self;
389 PyObject *_args;
390{
391 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000392 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000393 if (!PyArg_ParseTuple(_args, ""))
394 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000395 _rv = GetControlVariant(_self->ob_itself);
396 _res = Py_BuildValue("h",
Guido van Rossum17448e21995-01-30 11:53:55 +0000397 _rv);
398 return _res;
399}
400
Jack Jansenae8a68f1995-06-06 12:55:40 +0000401static PyObject *CtlObj_SetControlAction(_self, _args)
402 ControlObject *_self;
403 PyObject *_args;
404{
405 PyObject *_res = NULL;
406 if (!PyArg_ParseTuple(_args, ""))
407 return NULL;
408 SetControlAction(_self->ob_itself,
409 (ControlActionUPP)0);
410 Py_INCREF(Py_None);
411 _res = Py_None;
412 return _res;
413}
414
Jack Jansen7d0bc831995-06-09 20:56:31 +0000415static PyObject *CtlObj_SetControlReference(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000416 ControlObject *_self;
417 PyObject *_args;
418{
419 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000420 SInt32 data;
421 if (!PyArg_ParseTuple(_args, "l",
422 &data))
Guido van Rossum17448e21995-01-30 11:53:55 +0000423 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000424 SetControlReference(_self->ob_itself,
425 data);
Guido van Rossum17448e21995-01-30 11:53:55 +0000426 Py_INCREF(Py_None);
427 _res = Py_None;
428 return _res;
429}
430
Jack Jansen7d0bc831995-06-09 20:56:31 +0000431static PyObject *CtlObj_GetControlReference(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000432 ControlObject *_self;
433 PyObject *_args;
434{
435 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000436 SInt32 _rv;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000437 if (!PyArg_ParseTuple(_args, ""))
438 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000439 _rv = GetControlReference(_self->ob_itself);
440 _res = Py_BuildValue("l",
Guido van Rossum17448e21995-01-30 11:53:55 +0000441 _rv);
442 return _res;
443}
444
Jack Jansen5d56f4b1995-06-18 20:16:33 +0000445static PyObject *CtlObj_as_Resource(_self, _args)
446 ControlObject *_self;
447 PyObject *_args;
448{
449 PyObject *_res = NULL;
450
451 return ResObj_New((Handle)_self->ob_itself);
452
453}
454
Guido van Rossum17448e21995-01-30 11:53:55 +0000455static PyMethodDef CtlObj_methods[] = {
Guido van Rossum17448e21995-01-30 11:53:55 +0000456 {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1,
457 "() -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000458 {"ShowControl", (PyCFunction)CtlObj_ShowControl, 1,
459 "() -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000460 {"HideControl", (PyCFunction)CtlObj_HideControl, 1,
461 "() -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000462 {"Draw1Control", (PyCFunction)CtlObj_Draw1Control, 1,
463 "() -> None"},
464 {"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000465 "(ControlPartCode hiliteState) -> None"},
466 {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1,
467 "(Point thePoint) -> (ControlPartCode _rv)"},
468 {"DragControl", (PyCFunction)CtlObj_DragControl, 1,
Jack Jansen754d4a41995-11-14 10:41:55 +0000469 "(Point startPoint, Rect limitRect, Rect slopRect, DragConstraint axis) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000470 {"TestControl", (PyCFunction)CtlObj_TestControl, 1,
Jack Jansen754d4a41995-11-14 10:41:55 +0000471 "(Point thePoint) -> (ControlPartCode _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000472 {"MoveControl", (PyCFunction)CtlObj_MoveControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000473 "(SInt16 h, SInt16 v) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000474 {"SizeControl", (PyCFunction)CtlObj_SizeControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000475 "(SInt16 w, SInt16 h) -> None"},
476 {"SetControlTitle", (PyCFunction)CtlObj_SetControlTitle, 1,
477 "(Str255 title) -> None"},
478 {"GetControlTitle", (PyCFunction)CtlObj_GetControlTitle, 1,
479 "(Str255 title) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000480 {"GetControlValue", (PyCFunction)CtlObj_GetControlValue, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000481 "() -> (SInt16 _rv)"},
482 {"SetControlValue", (PyCFunction)CtlObj_SetControlValue, 1,
483 "(SInt16 newValue) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000484 {"GetControlMinimum", (PyCFunction)CtlObj_GetControlMinimum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000485 "() -> (SInt16 _rv)"},
486 {"SetControlMinimum", (PyCFunction)CtlObj_SetControlMinimum, 1,
487 "(SInt16 newMinimum) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000488 {"GetControlMaximum", (PyCFunction)CtlObj_GetControlMaximum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000489 "() -> (SInt16 _rv)"},
490 {"SetControlMaximum", (PyCFunction)CtlObj_SetControlMaximum, 1,
491 "(SInt16 newMaximum) -> None"},
492 {"GetControlVariant", (PyCFunction)CtlObj_GetControlVariant, 1,
493 "() -> (SInt16 _rv)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000494 {"SetControlAction", (PyCFunction)CtlObj_SetControlAction, 1,
495 "() -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000496 {"SetControlReference", (PyCFunction)CtlObj_SetControlReference, 1,
497 "(SInt32 data) -> None"},
498 {"GetControlReference", (PyCFunction)CtlObj_GetControlReference, 1,
499 "() -> (SInt32 _rv)"},
Jack Jansen5d56f4b1995-06-18 20:16:33 +0000500 {"as_Resource", (PyCFunction)CtlObj_as_Resource, 1,
501 "Return this Control as a Resource"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000502 {NULL, NULL, 0}
503};
504
505PyMethodChain CtlObj_chain = { CtlObj_methods, NULL };
506
507static PyObject *CtlObj_getattr(self, name)
508 ControlObject *self;
509 char *name;
510{
511 return Py_FindMethodInChain(&CtlObj_chain, (PyObject *)self, name);
512}
513
514#define CtlObj_setattr NULL
515
516PyTypeObject Control_Type = {
517 PyObject_HEAD_INIT(&PyType_Type)
518 0, /*ob_size*/
519 "Control", /*tp_name*/
520 sizeof(ControlObject), /*tp_basicsize*/
521 0, /*tp_itemsize*/
522 /* methods */
523 (destructor) CtlObj_dealloc, /*tp_dealloc*/
524 0, /*tp_print*/
525 (getattrfunc) CtlObj_getattr, /*tp_getattr*/
526 (setattrfunc) CtlObj_setattr, /*tp_setattr*/
527};
528
529/* -------------------- End object type Control --------------------- */
530
531
532static PyObject *Ctl_NewControl(_self, _args)
533 PyObject *_self;
534 PyObject *_args;
535{
536 PyObject *_res = NULL;
537 ControlHandle _rv;
538 WindowPtr theWindow;
539 Rect boundsRect;
540 Str255 title;
541 Boolean visible;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000542 SInt16 value;
543 SInt16 min;
544 SInt16 max;
545 SInt16 procID;
546 SInt32 refCon;
Guido van Rossum17448e21995-01-30 11:53:55 +0000547 if (!PyArg_ParseTuple(_args, "O&O&O&bhhhhl",
548 WinObj_Convert, &theWindow,
549 PyMac_GetRect, &boundsRect,
550 PyMac_GetStr255, title,
551 &visible,
552 &value,
553 &min,
554 &max,
555 &procID,
556 &refCon))
557 return NULL;
558 _rv = NewControl(theWindow,
559 &boundsRect,
560 title,
561 visible,
562 value,
563 min,
564 max,
565 procID,
566 refCon);
567 _res = Py_BuildValue("O&",
568 CtlObj_New, _rv);
569 return _res;
570}
571
572static PyObject *Ctl_GetNewControl(_self, _args)
573 PyObject *_self;
574 PyObject *_args;
575{
576 PyObject *_res = NULL;
577 ControlHandle _rv;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000578 SInt16 controlID;
Guido van Rossum17448e21995-01-30 11:53:55 +0000579 WindowPtr owner;
580 if (!PyArg_ParseTuple(_args, "hO&",
581 &controlID,
582 WinObj_Convert, &owner))
583 return NULL;
584 _rv = GetNewControl(controlID,
585 owner);
586 _res = Py_BuildValue("O&",
587 CtlObj_New, _rv);
588 return _res;
589}
590
591static PyObject *Ctl_KillControls(_self, _args)
592 PyObject *_self;
593 PyObject *_args;
594{
595 PyObject *_res = NULL;
596 WindowPtr theWindow;
597 if (!PyArg_ParseTuple(_args, "O&",
598 WinObj_Convert, &theWindow))
599 return NULL;
600 KillControls(theWindow);
601 Py_INCREF(Py_None);
602 _res = Py_None;
603 return _res;
604}
605
606static PyObject *Ctl_DrawControls(_self, _args)
607 PyObject *_self;
608 PyObject *_args;
609{
610 PyObject *_res = NULL;
611 WindowPtr theWindow;
612 if (!PyArg_ParseTuple(_args, "O&",
613 WinObj_Convert, &theWindow))
614 return NULL;
615 DrawControls(theWindow);
616 Py_INCREF(Py_None);
617 _res = Py_None;
618 return _res;
619}
620
Guido van Rossum17448e21995-01-30 11:53:55 +0000621static PyObject *Ctl_UpdateControls(_self, _args)
622 PyObject *_self;
623 PyObject *_args;
624{
625 PyObject *_res = NULL;
626 WindowPtr theWindow;
Jack Jansen2b724171996-04-10 14:48:19 +0000627 RgnHandle updateRegion;
628 if (!PyArg_ParseTuple(_args, "O&O&",
629 WinObj_Convert, &theWindow,
630 ResObj_Convert, &updateRegion))
Guido van Rossum17448e21995-01-30 11:53:55 +0000631 return NULL;
632 UpdateControls(theWindow,
Jack Jansen2b724171996-04-10 14:48:19 +0000633 updateRegion);
Guido van Rossum17448e21995-01-30 11:53:55 +0000634 Py_INCREF(Py_None);
635 _res = Py_None;
636 return _res;
637}
638
639static PyObject *Ctl_FindControl(_self, _args)
640 PyObject *_self;
641 PyObject *_args;
642{
643 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000644 ControlPartCode _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000645 Point thePoint;
646 WindowPtr theWindow;
647 ControlHandle theControl;
648 if (!PyArg_ParseTuple(_args, "O&O&",
649 PyMac_GetPoint, &thePoint,
650 WinObj_Convert, &theWindow))
651 return NULL;
652 _rv = FindControl(thePoint,
653 theWindow,
654 &theControl);
655 _res = Py_BuildValue("hO&",
656 _rv,
657 CtlObj_WhichControl, theControl);
658 return _res;
659}
660
661static PyMethodDef Ctl_methods[] = {
662 {"NewControl", (PyCFunction)Ctl_NewControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000663 "(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 +0000664 {"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000665 "(SInt16 controlID, WindowPtr owner) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000666 {"KillControls", (PyCFunction)Ctl_KillControls, 1,
667 "(WindowPtr theWindow) -> None"},
668 {"DrawControls", (PyCFunction)Ctl_DrawControls, 1,
669 "(WindowPtr theWindow) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000670 {"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1,
Jack Jansen2b724171996-04-10 14:48:19 +0000671 "(WindowPtr theWindow, RgnHandle updateRegion) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000672 {"FindControl", (PyCFunction)Ctl_FindControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000673 "(Point thePoint, WindowPtr theWindow) -> (ControlPartCode _rv, ControlHandle theControl)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000674 {NULL, NULL, 0}
675};
676
677
678
679PyObject *
680CtlObj_WhichControl(ControlHandle c)
681{
682 PyObject *it;
683
684 /* XXX What if we find a control belonging to some other package? */
685 if (c == NULL)
686 it = NULL;
687 else
688 it = (PyObject *) GetCRefCon(c);
689 if (it == NULL || ((ControlObject *)it)->ob_itself != c)
690 it = Py_None;
691 Py_INCREF(it);
692 return it;
693}
694
695
696void initCtl()
697{
698 PyObject *m;
699 PyObject *d;
700
701
702
703
704 m = Py_InitModule("Ctl", Ctl_methods);
705 d = PyModule_GetDict(m);
706 Ctl_Error = PyMac_GetOSErrException();
707 if (Ctl_Error == NULL ||
708 PyDict_SetItemString(d, "Error", Ctl_Error) != 0)
709 Py_FatalError("can't initialize Ctl.Error");
710}
711
712/* ========================= End module Ctl ========================= */
713