blob: 573f581fb90eb9b27249fd7318e346b535fabfa9 [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;
Jack Jansen85ae4a81997-04-08 15:26:03 +000076 SetControlReference(itself, (long)it);
Guido van Rossum17448e21995-01-30 11:53:55 +000077 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 Jansen85ae4a81997-04-08 15:26:03 +000095 if (self->ob_itself) SetControlReference(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 Jansenc7fefed1997-08-15 14:32:18 +0000432static PyObject *CtlObj_GetAuxiliaryControlRecord(_self, _args)
433 ControlObject *_self;
434 PyObject *_args;
435{
436 PyObject *_res = NULL;
437 Boolean _rv;
438 AuxCtlHandle acHndl;
439 if (!PyArg_ParseTuple(_args, ""))
440 return NULL;
441 _rv = GetAuxiliaryControlRecord(_self->ob_itself,
442 &acHndl);
443 _res = Py_BuildValue("bO&",
444 _rv,
445 ResObj_New, acHndl);
446 return _res;
447}
448
449static PyObject *CtlObj_SetControlColor(_self, _args)
450 ControlObject *_self;
451 PyObject *_args;
452{
453 PyObject *_res = NULL;
454 CCTabHandle newColorTable;
455 if (!PyArg_ParseTuple(_args, "O&",
456 ResObj_Convert, &newColorTable))
457 return NULL;
458 SetControlColor(_self->ob_itself,
459 newColorTable);
460 Py_INCREF(Py_None);
461 _res = Py_None;
462 return _res;
463}
464
Jack Jansen5d56f4b1995-06-18 20:16:33 +0000465static PyObject *CtlObj_as_Resource(_self, _args)
466 ControlObject *_self;
467 PyObject *_args;
468{
469 PyObject *_res = NULL;
470
471 return ResObj_New((Handle)_self->ob_itself);
472
473}
474
Jack Jansencfb60ee1996-10-01 10:46:46 +0000475static PyObject *CtlObj_DisposeControl(_self, _args)
476 ControlObject *_self;
477 PyObject *_args;
478{
479 PyObject *_res = NULL;
480
481 if (!PyArg_ParseTuple(_args, ""))
482 return NULL;
483 if ( _self->ob_itself ) {
Jack Jansen85ae4a81997-04-08 15:26:03 +0000484 SetControlReference(_self->ob_itself, (long)0); /* Make it forget about us */
Jack Jansencfb60ee1996-10-01 10:46:46 +0000485 DisposeControl(_self->ob_itself);
486 _self->ob_itself = NULL;
487 }
488 Py_INCREF(Py_None);
489 _res = Py_None;
490 return _res;
491
492}
493
Guido van Rossum17448e21995-01-30 11:53:55 +0000494static PyMethodDef CtlObj_methods[] = {
Guido van Rossum17448e21995-01-30 11:53:55 +0000495 {"ShowControl", (PyCFunction)CtlObj_ShowControl, 1,
496 "() -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000497 {"HideControl", (PyCFunction)CtlObj_HideControl, 1,
498 "() -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000499 {"Draw1Control", (PyCFunction)CtlObj_Draw1Control, 1,
500 "() -> None"},
501 {"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000502 "(ControlPartCode hiliteState) -> None"},
503 {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1,
504 "(Point thePoint) -> (ControlPartCode _rv)"},
505 {"DragControl", (PyCFunction)CtlObj_DragControl, 1,
Jack Jansen754d4a41995-11-14 10:41:55 +0000506 "(Point startPoint, Rect limitRect, Rect slopRect, DragConstraint axis) -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000507 {"TestControl", (PyCFunction)CtlObj_TestControl, 1,
Jack Jansen754d4a41995-11-14 10:41:55 +0000508 "(Point thePoint) -> (ControlPartCode _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000509 {"MoveControl", (PyCFunction)CtlObj_MoveControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000510 "(SInt16 h, SInt16 v) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000511 {"SizeControl", (PyCFunction)CtlObj_SizeControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000512 "(SInt16 w, SInt16 h) -> None"},
513 {"SetControlTitle", (PyCFunction)CtlObj_SetControlTitle, 1,
514 "(Str255 title) -> None"},
515 {"GetControlTitle", (PyCFunction)CtlObj_GetControlTitle, 1,
516 "(Str255 title) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000517 {"GetControlValue", (PyCFunction)CtlObj_GetControlValue, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000518 "() -> (SInt16 _rv)"},
519 {"SetControlValue", (PyCFunction)CtlObj_SetControlValue, 1,
520 "(SInt16 newValue) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000521 {"GetControlMinimum", (PyCFunction)CtlObj_GetControlMinimum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000522 "() -> (SInt16 _rv)"},
523 {"SetControlMinimum", (PyCFunction)CtlObj_SetControlMinimum, 1,
524 "(SInt16 newMinimum) -> None"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000525 {"GetControlMaximum", (PyCFunction)CtlObj_GetControlMaximum, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000526 "() -> (SInt16 _rv)"},
527 {"SetControlMaximum", (PyCFunction)CtlObj_SetControlMaximum, 1,
528 "(SInt16 newMaximum) -> None"},
529 {"GetControlVariant", (PyCFunction)CtlObj_GetControlVariant, 1,
530 "() -> (SInt16 _rv)"},
Jack Jansenae8a68f1995-06-06 12:55:40 +0000531 {"SetControlAction", (PyCFunction)CtlObj_SetControlAction, 1,
532 "() -> None"},
Jack Jansen7d0bc831995-06-09 20:56:31 +0000533 {"SetControlReference", (PyCFunction)CtlObj_SetControlReference, 1,
534 "(SInt32 data) -> None"},
535 {"GetControlReference", (PyCFunction)CtlObj_GetControlReference, 1,
536 "() -> (SInt32 _rv)"},
Jack Jansenc7fefed1997-08-15 14:32:18 +0000537 {"GetAuxiliaryControlRecord", (PyCFunction)CtlObj_GetAuxiliaryControlRecord, 1,
538 "() -> (Boolean _rv, AuxCtlHandle acHndl)"},
539 {"SetControlColor", (PyCFunction)CtlObj_SetControlColor, 1,
540 "(CCTabHandle newColorTable) -> None"},
Jack Jansen5d56f4b1995-06-18 20:16:33 +0000541 {"as_Resource", (PyCFunction)CtlObj_as_Resource, 1,
542 "Return this Control as a Resource"},
Jack Jansencfb60ee1996-10-01 10:46:46 +0000543 {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1,
544 "() -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000545 {NULL, NULL, 0}
546};
547
548PyMethodChain CtlObj_chain = { CtlObj_methods, NULL };
549
550static PyObject *CtlObj_getattr(self, name)
551 ControlObject *self;
552 char *name;
553{
554 return Py_FindMethodInChain(&CtlObj_chain, (PyObject *)self, name);
555}
556
557#define CtlObj_setattr NULL
558
559PyTypeObject Control_Type = {
560 PyObject_HEAD_INIT(&PyType_Type)
561 0, /*ob_size*/
562 "Control", /*tp_name*/
563 sizeof(ControlObject), /*tp_basicsize*/
564 0, /*tp_itemsize*/
565 /* methods */
566 (destructor) CtlObj_dealloc, /*tp_dealloc*/
567 0, /*tp_print*/
568 (getattrfunc) CtlObj_getattr, /*tp_getattr*/
569 (setattrfunc) CtlObj_setattr, /*tp_setattr*/
570};
571
572/* -------------------- End object type Control --------------------- */
573
574
575static PyObject *Ctl_NewControl(_self, _args)
576 PyObject *_self;
577 PyObject *_args;
578{
579 PyObject *_res = NULL;
580 ControlHandle _rv;
581 WindowPtr theWindow;
582 Rect boundsRect;
583 Str255 title;
584 Boolean visible;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000585 SInt16 value;
586 SInt16 min;
587 SInt16 max;
588 SInt16 procID;
589 SInt32 refCon;
Guido van Rossum17448e21995-01-30 11:53:55 +0000590 if (!PyArg_ParseTuple(_args, "O&O&O&bhhhhl",
591 WinObj_Convert, &theWindow,
592 PyMac_GetRect, &boundsRect,
593 PyMac_GetStr255, title,
594 &visible,
595 &value,
596 &min,
597 &max,
598 &procID,
599 &refCon))
600 return NULL;
601 _rv = NewControl(theWindow,
602 &boundsRect,
603 title,
604 visible,
605 value,
606 min,
607 max,
608 procID,
609 refCon);
610 _res = Py_BuildValue("O&",
611 CtlObj_New, _rv);
612 return _res;
613}
614
615static PyObject *Ctl_GetNewControl(_self, _args)
616 PyObject *_self;
617 PyObject *_args;
618{
619 PyObject *_res = NULL;
620 ControlHandle _rv;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000621 SInt16 controlID;
Guido van Rossum17448e21995-01-30 11:53:55 +0000622 WindowPtr owner;
623 if (!PyArg_ParseTuple(_args, "hO&",
624 &controlID,
625 WinObj_Convert, &owner))
626 return NULL;
627 _rv = GetNewControl(controlID,
628 owner);
629 _res = Py_BuildValue("O&",
630 CtlObj_New, _rv);
631 return _res;
632}
633
Guido van Rossum17448e21995-01-30 11:53:55 +0000634static PyObject *Ctl_DrawControls(_self, _args)
635 PyObject *_self;
636 PyObject *_args;
637{
638 PyObject *_res = NULL;
639 WindowPtr theWindow;
640 if (!PyArg_ParseTuple(_args, "O&",
641 WinObj_Convert, &theWindow))
642 return NULL;
643 DrawControls(theWindow);
644 Py_INCREF(Py_None);
645 _res = Py_None;
646 return _res;
647}
648
Guido van Rossum17448e21995-01-30 11:53:55 +0000649static PyObject *Ctl_UpdateControls(_self, _args)
650 PyObject *_self;
651 PyObject *_args;
652{
653 PyObject *_res = NULL;
654 WindowPtr theWindow;
Jack Jansen2b724171996-04-10 14:48:19 +0000655 RgnHandle updateRegion;
656 if (!PyArg_ParseTuple(_args, "O&O&",
657 WinObj_Convert, &theWindow,
658 ResObj_Convert, &updateRegion))
Guido van Rossum17448e21995-01-30 11:53:55 +0000659 return NULL;
660 UpdateControls(theWindow,
Jack Jansen2b724171996-04-10 14:48:19 +0000661 updateRegion);
Guido van Rossum17448e21995-01-30 11:53:55 +0000662 Py_INCREF(Py_None);
663 _res = Py_None;
664 return _res;
665}
666
667static PyObject *Ctl_FindControl(_self, _args)
668 PyObject *_self;
669 PyObject *_args;
670{
671 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000672 ControlPartCode _rv;
Guido van Rossum17448e21995-01-30 11:53:55 +0000673 Point thePoint;
674 WindowPtr theWindow;
675 ControlHandle theControl;
676 if (!PyArg_ParseTuple(_args, "O&O&",
677 PyMac_GetPoint, &thePoint,
678 WinObj_Convert, &theWindow))
679 return NULL;
680 _rv = FindControl(thePoint,
681 theWindow,
682 &theControl);
683 _res = Py_BuildValue("hO&",
684 _rv,
685 CtlObj_WhichControl, theControl);
686 return _res;
687}
688
689static PyMethodDef Ctl_methods[] = {
690 {"NewControl", (PyCFunction)Ctl_NewControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000691 "(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 +0000692 {"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000693 "(SInt16 controlID, WindowPtr owner) -> (ControlHandle _rv)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000694 {"DrawControls", (PyCFunction)Ctl_DrawControls, 1,
695 "(WindowPtr theWindow) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000696 {"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1,
Jack Jansen2b724171996-04-10 14:48:19 +0000697 "(WindowPtr theWindow, RgnHandle updateRegion) -> None"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000698 {"FindControl", (PyCFunction)Ctl_FindControl, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000699 "(Point thePoint, WindowPtr theWindow) -> (ControlPartCode _rv, ControlHandle theControl)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000700 {NULL, NULL, 0}
701};
702
703
704
705PyObject *
706CtlObj_WhichControl(ControlHandle c)
707{
708 PyObject *it;
709
710 /* XXX What if we find a control belonging to some other package? */
711 if (c == NULL)
712 it = NULL;
713 else
Jack Jansen85ae4a81997-04-08 15:26:03 +0000714 it = (PyObject *) GetControlReference(c);
Guido van Rossum17448e21995-01-30 11:53:55 +0000715 if (it == NULL || ((ControlObject *)it)->ob_itself != c)
716 it = Py_None;
717 Py_INCREF(it);
718 return it;
719}
720
721
722void initCtl()
723{
724 PyObject *m;
725 PyObject *d;
726
727
728
729
730 m = Py_InitModule("Ctl", Ctl_methods);
731 d = PyModule_GetDict(m);
732 Ctl_Error = PyMac_GetOSErrException();
733 if (Ctl_Error == NULL ||
734 PyDict_SetItemString(d, "Error", Ctl_Error) != 0)
735 Py_FatalError("can't initialize Ctl.Error");
Jack Jansena755e681997-09-20 17:40:22 +0000736 Control_Type.ob_type = &PyType_Type;
737 Py_INCREF(&Control_Type);
738 if (PyDict_SetItemString(d, "ControlType", (PyObject *)&Control_Type) != 0)
739 Py_FatalError("can't initialize ControlType");
Guido van Rossum17448e21995-01-30 11:53:55 +0000740}
741
742/* ========================= End module Ctl ========================= */
743