blob: 526338bf84a1ef39b05cc39738cc9b75535bb87b [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 Jansencfb60ee1996-10-01 10:46:46 +000095 if (self->ob_itself) 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_ShowControl(_self, _args)
100 ControlObject *_self;
101 PyObject *_args;
102{
103 PyObject *_res = NULL;
104 if (!PyArg_ParseTuple(_args, ""))
105 return NULL;
106 ShowControl(_self->ob_itself);
107 Py_INCREF(Py_None);
108 _res = Py_None;
109 return _res;
110}
111
112static PyObject *CtlObj_HideControl(_self, _args)
113 ControlObject *_self;
114 PyObject *_args;
115{
116 PyObject *_res = NULL;
117 if (!PyArg_ParseTuple(_args, ""))
118 return NULL;
119 HideControl(_self->ob_itself);
120 Py_INCREF(Py_None);
121 _res = Py_None;
122 return _res;
123}
124
125static PyObject *CtlObj_Draw1Control(_self, _args)
126 ControlObject *_self;
127 PyObject *_args;
128{
129 PyObject *_res = NULL;
130 if (!PyArg_ParseTuple(_args, ""))
131 return NULL;
132 Draw1Control(_self->ob_itself);
133 Py_INCREF(Py_None);
134 _res = Py_None;
135 return _res;
136}
137
138static PyObject *CtlObj_HiliteControl(_self, _args)
139 ControlObject *_self;
140 PyObject *_args;
141{
142 PyObject *_res = NULL;
143 ControlPartCode hiliteState;
144 if (!PyArg_ParseTuple(_args, "h",
145 &hiliteState))
146 return NULL;
147 HiliteControl(_self->ob_itself,
148 hiliteState);
149 Py_INCREF(Py_None);
150 _res = Py_None;
151 return _res;
152}
153
154static PyObject *CtlObj_TrackControl(_self, _args)
155 ControlObject *_self;
156 PyObject *_args;
157{
158 PyObject *_res = NULL;
159 ControlPartCode _rv;
160 Point thePoint;
161 if (!PyArg_ParseTuple(_args, "O&",
162 PyMac_GetPoint, &thePoint))
163 return NULL;
164 _rv = TrackControl(_self->ob_itself,
165 thePoint,
166 (ControlActionUPP)0);
167 _res = Py_BuildValue("h",
168 _rv);
169 return _res;
170}
171
172static PyObject *CtlObj_DragControl(_self, _args)
173 ControlObject *_self;
174 PyObject *_args;
175{
176 PyObject *_res = NULL;
Jack Jansen754d4a41995-11-14 10:41:55 +0000177 Point startPoint;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000178 Rect limitRect;
179 Rect slopRect;
180 DragConstraint axis;
181 if (!PyArg_ParseTuple(_args, "O&O&O&h",
Jack Jansen754d4a41995-11-14 10:41:55 +0000182 PyMac_GetPoint, &startPoint,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000183 PyMac_GetRect, &limitRect,
184 PyMac_GetRect, &slopRect,
185 &axis))
186 return NULL;
187 DragControl(_self->ob_itself,
Jack Jansen754d4a41995-11-14 10:41:55 +0000188 startPoint,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000189 &limitRect,
190 &slopRect,
191 axis);
192 Py_INCREF(Py_None);
193 _res = Py_None;
194 return _res;
195}
196
197static PyObject *CtlObj_TestControl(_self, _args)
198 ControlObject *_self;
199 PyObject *_args;
200{
201 PyObject *_res = NULL;
202 ControlPartCode _rv;
Jack Jansen754d4a41995-11-14 10:41:55 +0000203 Point thePoint;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000204 if (!PyArg_ParseTuple(_args, "O&",
Jack Jansen754d4a41995-11-14 10:41:55 +0000205 PyMac_GetPoint, &thePoint))
Jack Jansen7d0bc831995-06-09 20:56:31 +0000206 return NULL;
207 _rv = TestControl(_self->ob_itself,
Jack Jansen754d4a41995-11-14 10:41:55 +0000208 thePoint);
Jack Jansen7d0bc831995-06-09 20:56:31 +0000209 _res = Py_BuildValue("h",
210 _rv);
211 return _res;
212}
213
214static PyObject *CtlObj_MoveControl(_self, _args)
215 ControlObject *_self;
216 PyObject *_args;
217{
218 PyObject *_res = NULL;
219 SInt16 h;
220 SInt16 v;
221 if (!PyArg_ParseTuple(_args, "hh",
222 &h,
223 &v))
224 return NULL;
225 MoveControl(_self->ob_itself,
226 h,
227 v);
228 Py_INCREF(Py_None);
229 _res = Py_None;
230 return _res;
231}
232
233static PyObject *CtlObj_SizeControl(_self, _args)
234 ControlObject *_self;
235 PyObject *_args;
236{
237 PyObject *_res = NULL;
238 SInt16 w;
239 SInt16 h;
240 if (!PyArg_ParseTuple(_args, "hh",
241 &w,
242 &h))
243 return NULL;
244 SizeControl(_self->ob_itself,
245 w,
246 h);
247 Py_INCREF(Py_None);
248 _res = Py_None;
249 return _res;
250}
251
Jack Jansenae8a68f1995-06-06 12:55:40 +0000252static PyObject *CtlObj_SetControlTitle(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000253 ControlObject *_self;
254 PyObject *_args;
255{
256 PyObject *_res = NULL;
257 Str255 title;
258 if (!PyArg_ParseTuple(_args, "O&",
259 PyMac_GetStr255, title))
260 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000261 SetControlTitle(_self->ob_itself,
262 title);
Guido van Rossum17448e21995-01-30 11:53:55 +0000263 Py_INCREF(Py_None);
264 _res = Py_None;
265 return _res;
266}
267
Jack Jansenae8a68f1995-06-06 12:55:40 +0000268static PyObject *CtlObj_GetControlTitle(_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 GetControlTitle(_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_GetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000285 ControlObject *_self;
286 PyObject *_args;
287{
288 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000289 SInt16 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000290 if (!PyArg_ParseTuple(_args, ""))
291 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000292 _rv = GetControlValue(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000293 _res = Py_BuildValue("h",
294 _rv);
295 return _res;
296}
297
Jack Jansen7d0bc831995-06-09 20:56:31 +0000298static PyObject *CtlObj_SetControlValue(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000299 ControlObject *_self;
300 PyObject *_args;
301{
302 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000303 SInt16 newValue;
Guido van Rossum17448e21995-01-30 11:53:55 +0000304 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000305 &newValue))
Guido van Rossum17448e21995-01-30 11:53:55 +0000306 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000307 SetControlValue(_self->ob_itself,
308 newValue);
Guido van Rossum17448e21995-01-30 11:53:55 +0000309 Py_INCREF(Py_None);
310 _res = Py_None;
311 return _res;
312}
313
Jack Jansenae8a68f1995-06-06 12:55:40 +0000314static PyObject *CtlObj_GetControlMinimum(_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 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000320 if (!PyArg_ParseTuple(_args, ""))
321 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000322 _rv = GetControlMinimum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000323 _res = Py_BuildValue("h",
324 _rv);
325 return _res;
326}
327
Jack Jansen7d0bc831995-06-09 20:56:31 +0000328static PyObject *CtlObj_SetControlMinimum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000329 ControlObject *_self;
330 PyObject *_args;
331{
332 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000333 SInt16 newMinimum;
Guido van Rossum17448e21995-01-30 11:53:55 +0000334 if (!PyArg_ParseTuple(_args, "h",
Jack Jansen7d0bc831995-06-09 20:56:31 +0000335 &newMinimum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000336 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000337 SetControlMinimum(_self->ob_itself,
338 newMinimum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000339 Py_INCREF(Py_None);
340 _res = Py_None;
341 return _res;
342}
343
Jack Jansenae8a68f1995-06-06 12:55:40 +0000344static PyObject *CtlObj_GetControlMaximum(_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 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000350 if (!PyArg_ParseTuple(_args, ""))
351 return NULL;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000352 _rv = GetControlMaximum(_self->ob_itself);
Guido van Rossum17448e21995-01-30 11:53:55 +0000353 _res = Py_BuildValue("h",
354 _rv);
355 return _res;
356}
357
Jack Jansen7d0bc831995-06-09 20:56:31 +0000358static PyObject *CtlObj_SetControlMaximum(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000359 ControlObject *_self;
360 PyObject *_args;
361{
362 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000363 SInt16 newMaximum;
364 if (!PyArg_ParseTuple(_args, "h",
365 &newMaximum))
Guido van Rossum17448e21995-01-30 11:53:55 +0000366 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000367 SetControlMaximum(_self->ob_itself,
368 newMaximum);
Guido van Rossum17448e21995-01-30 11:53:55 +0000369 Py_INCREF(Py_None);
370 _res = Py_None;
371 return _res;
372}
373
Jack Jansen7d0bc831995-06-09 20:56:31 +0000374static PyObject *CtlObj_GetControlVariant(_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 _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000380 if (!PyArg_ParseTuple(_args, ""))
381 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000382 _rv = GetControlVariant(_self->ob_itself);
383 _res = Py_BuildValue("h",
Guido van Rossum17448e21995-01-30 11:53:55 +0000384 _rv);
385 return _res;
386}
387
Jack Jansenae8a68f1995-06-06 12:55:40 +0000388static PyObject *CtlObj_SetControlAction(_self, _args)
389 ControlObject *_self;
390 PyObject *_args;
391{
392 PyObject *_res = NULL;
393 if (!PyArg_ParseTuple(_args, ""))
394 return NULL;
395 SetControlAction(_self->ob_itself,
396 (ControlActionUPP)0);
397 Py_INCREF(Py_None);
398 _res = Py_None;
399 return _res;
400}
401
Jack Jansen7d0bc831995-06-09 20:56:31 +0000402static PyObject *CtlObj_SetControlReference(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000403 ControlObject *_self;
404 PyObject *_args;
405{
406 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000407 SInt32 data;
408 if (!PyArg_ParseTuple(_args, "l",
409 &data))
Guido van Rossum17448e21995-01-30 11:53:55 +0000410 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000411 SetControlReference(_self->ob_itself,
412 data);
Guido van Rossum17448e21995-01-30 11:53:55 +0000413 Py_INCREF(Py_None);
414 _res = Py_None;
415 return _res;
416}
417
Jack Jansen7d0bc831995-06-09 20:56:31 +0000418static PyObject *CtlObj_GetControlReference(_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 _rv;
Jack Jansenae8a68f1995-06-06 12:55:40 +0000424 if (!PyArg_ParseTuple(_args, ""))
425 return NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000426 _rv = GetControlReference(_self->ob_itself);
427 _res = Py_BuildValue("l",
Guido van Rossum17448e21995-01-30 11:53:55 +0000428 _rv);
429 return _res;
430}
431
Jack Jansen5d56f4b1995-06-18 20:16:33 +0000432static PyObject *CtlObj_as_Resource(_self, _args)
433 ControlObject *_self;
434 PyObject *_args;
435{
436 PyObject *_res = NULL;
437
438 return ResObj_New((Handle)_self->ob_itself);
439
440}
441
Jack Jansencfb60ee1996-10-01 10:46:46 +0000442static PyObject *CtlObj_DisposeControl(_self, _args)
443 ControlObject *_self;
444 PyObject *_args;
445{
446 PyObject *_res = NULL;
447
448 if (!PyArg_ParseTuple(_args, ""))
449 return NULL;
450 if ( _self->ob_itself ) {
451 SetCRefCon(_self->ob_itself, (long)0); /* Make it forget about us */
452 DisposeControl(_self->ob_itself);
453 _self->ob_itself = NULL;
454 }
455 Py_INCREF(Py_None);
456 _res = Py_None;
457 return _res;
458
459}
460
Guido van Rossum17448e21995-01-30 11:53:55 +0000461static PyMethodDef CtlObj_methods[] = {
Guido van Rossum17448e21995-01-30 11:53:55 +0000462 {"ShowControl", (PyCFunction)CtlObj_ShowControl, 1,
463 "() -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000464 {"HideControl", (PyCFunction)CtlObj_HideControl, 1,
465 "() -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000466 {"Draw1Control", (PyCFunction)CtlObj_Draw1Control, 1,
467 "() -> None"},
468 {"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000469 "(ControlPartCode hiliteState) -> None"},
470 {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1,
471 "(Point thePoint) -> (ControlPartCode _rv)"},
472 {"DragControl", (PyCFunction)CtlObj_DragControl, 1,
Jack Jansen754d4a41995-11-14 10:41:55 +0000473 "(Point startPoint, Rect limitRect, Rect slopRect, DragConstraint axis) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000474 {"TestControl", (PyCFunction)CtlObj_TestControl, 1,
Jack Jansen754d4a41995-11-14 10:41:55 +0000475 "(Point thePoint) -> (ControlPartCode _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000476 {"MoveControl", (PyCFunction)CtlObj_MoveControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000477 "(SInt16 h, SInt16 v) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000478 {"SizeControl", (PyCFunction)CtlObj_SizeControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000479 "(SInt16 w, SInt16 h) -> None"},
480 {"SetControlTitle", (PyCFunction)CtlObj_SetControlTitle, 1,
481 "(Str255 title) -> None"},
482 {"GetControlTitle", (PyCFunction)CtlObj_GetControlTitle, 1,
483 "(Str255 title) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000484 {"GetControlValue", (PyCFunction)CtlObj_GetControlValue, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000485 "() -> (SInt16 _rv)"},
486 {"SetControlValue", (PyCFunction)CtlObj_SetControlValue, 1,
487 "(SInt16 newValue) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000488 {"GetControlMinimum", (PyCFunction)CtlObj_GetControlMinimum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000489 "() -> (SInt16 _rv)"},
490 {"SetControlMinimum", (PyCFunction)CtlObj_SetControlMinimum, 1,
491 "(SInt16 newMinimum) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000492 {"GetControlMaximum", (PyCFunction)CtlObj_GetControlMaximum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000493 "() -> (SInt16 _rv)"},
494 {"SetControlMaximum", (PyCFunction)CtlObj_SetControlMaximum, 1,
495 "(SInt16 newMaximum) -> None"},
496 {"GetControlVariant", (PyCFunction)CtlObj_GetControlVariant, 1,
497 "() -> (SInt16 _rv)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000498 {"SetControlAction", (PyCFunction)CtlObj_SetControlAction, 1,
499 "() -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000500 {"SetControlReference", (PyCFunction)CtlObj_SetControlReference, 1,
501 "(SInt32 data) -> None"},
502 {"GetControlReference", (PyCFunction)CtlObj_GetControlReference, 1,
503 "() -> (SInt32 _rv)"},
Jack Jansen5d56f4b1995-06-18 20:16:33 +0000504 {"as_Resource", (PyCFunction)CtlObj_as_Resource, 1,
505 "Return this Control as a Resource"},
Jack Jansencfb60ee1996-10-01 10:46:46 +0000506 {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1,
507 "() -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000508 {NULL, NULL, 0}
509};
510
511PyMethodChain CtlObj_chain = { CtlObj_methods, NULL };
512
513static PyObject *CtlObj_getattr(self, name)
514 ControlObject *self;
515 char *name;
516{
517 return Py_FindMethodInChain(&CtlObj_chain, (PyObject *)self, name);
518}
519
520#define CtlObj_setattr NULL
521
522PyTypeObject Control_Type = {
523 PyObject_HEAD_INIT(&PyType_Type)
524 0, /*ob_size*/
525 "Control", /*tp_name*/
526 sizeof(ControlObject), /*tp_basicsize*/
527 0, /*tp_itemsize*/
528 /* methods */
529 (destructor) CtlObj_dealloc, /*tp_dealloc*/
530 0, /*tp_print*/
531 (getattrfunc) CtlObj_getattr, /*tp_getattr*/
532 (setattrfunc) CtlObj_setattr, /*tp_setattr*/
533};
534
535/* -------------------- End object type Control --------------------- */
536
537
538static PyObject *Ctl_NewControl(_self, _args)
539 PyObject *_self;
540 PyObject *_args;
541{
542 PyObject *_res = NULL;
543 ControlHandle _rv;
544 WindowPtr theWindow;
545 Rect boundsRect;
546 Str255 title;
547 Boolean visible;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000548 SInt16 value;
549 SInt16 min;
550 SInt16 max;
551 SInt16 procID;
552 SInt32 refCon;
Guido van Rossum17448e21995-01-30 11:53:55 +0000553 if (!PyArg_ParseTuple(_args, "O&O&O&bhhhhl",
554 WinObj_Convert, &theWindow,
555 PyMac_GetRect, &boundsRect,
556 PyMac_GetStr255, title,
557 &visible,
558 &value,
559 &min,
560 &max,
561 &procID,
562 &refCon))
563 return NULL;
564 _rv = NewControl(theWindow,
565 &boundsRect,
566 title,
567 visible,
568 value,
569 min,
570 max,
571 procID,
572 refCon);
573 _res = Py_BuildValue("O&",
574 CtlObj_New, _rv);
575 return _res;
576}
577
578static PyObject *Ctl_GetNewControl(_self, _args)
579 PyObject *_self;
580 PyObject *_args;
581{
582 PyObject *_res = NULL;
583 ControlHandle _rv;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000584 SInt16 controlID;
Guido van Rossum17448e21995-01-30 11:53:55 +0000585 WindowPtr owner;
586 if (!PyArg_ParseTuple(_args, "hO&",
587 &controlID,
588 WinObj_Convert, &owner))
589 return NULL;
590 _rv = GetNewControl(controlID,
591 owner);
592 _res = Py_BuildValue("O&",
593 CtlObj_New, _rv);
594 return _res;
595}
596
Guido van Rossum17448e21995-01-30 11:53:55 +0000597static 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;
Jack Jansen2b724171996-04-10 14:48:19 +0000618 RgnHandle updateRegion;
619 if (!PyArg_ParseTuple(_args, "O&O&",
620 WinObj_Convert, &theWindow,
621 ResObj_Convert, &updateRegion))
Guido van Rossum17448e21995-01-30 11:53:55 +0000622 return NULL;
623 UpdateControls(theWindow,
Jack Jansen2b724171996-04-10 14:48:19 +0000624 updateRegion);
Guido van Rossum17448e21995-01-30 11:53:55 +0000625 Py_INCREF(Py_None);
626 _res = Py_None;
627 return _res;
628}
629
630static PyObject *Ctl_FindControl(_self, _args)
631 PyObject *_self;
632 PyObject *_args;
633{
634 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000635 ControlPartCode _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000636 Point thePoint;
637 WindowPtr theWindow;
638 ControlHandle theControl;
639 if (!PyArg_ParseTuple(_args, "O&O&",
640 PyMac_GetPoint, &thePoint,
641 WinObj_Convert, &theWindow))
642 return NULL;
643 _rv = FindControl(thePoint,
644 theWindow,
645 &theControl);
646 _res = Py_BuildValue("hO&",
647 _rv,
648 CtlObj_WhichControl, theControl);
649 return _res;
650}
651
652static PyMethodDef Ctl_methods[] = {
653 {"NewControl", (PyCFunction)Ctl_NewControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000654 "(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 +0000655 {"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000656 "(SInt16 controlID, WindowPtr owner) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000657 {"DrawControls", (PyCFunction)Ctl_DrawControls, 1,
658 "(WindowPtr theWindow) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000659 {"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1,
Jack Jansen2b724171996-04-10 14:48:19 +0000660 "(WindowPtr theWindow, RgnHandle updateRegion) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000661 {"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