2 /* =========================== Module Ctl =========================== */
8 #define SystemSevenOrLater 1
16 extern PyObject
*ResObj_New(Handle
);
17 extern int ResObj_Convert(PyObject
*, Handle
*);
19 extern PyObject
*WinObj_New(WindowPtr
);
20 extern int WinObj_Convert(PyObject
*, WindowPtr
*);
22 extern PyObject
*DlgObj_New(DialogPtr
);
23 extern int DlgObj_Convert(PyObject
*, DialogPtr
*);
24 extern PyTypeObject Dialog_Type
;
25 #define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
27 extern PyObject
*MenuObj_New(MenuHandle
);
28 extern int MenuObj_Convert(PyObject
*, MenuHandle
*);
30 extern PyObject
*CtlObj_New(ControlHandle
);
31 extern int CtlObj_Convert(PyObject
*, ControlHandle
*);
33 extern PyObject
*WinObj_WhichWindow(WindowPtr
);
37 #define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
39 extern PyObject
*CtlObj_WhichControl(ControlHandle
); /* Forward */
42 #define ControlActionUPP ProcPtr
45 static PyObject
*Ctl_Error
;
47 /* ---------------------- Object type Control ----------------------- */
49 PyTypeObject Control_Type
;
51 #define CtlObj_Check(x) ((x)->ob_type == &Control_Type)
53 typedef struct ControlObject
{
55 ControlHandle ob_itself
;
58 PyObject
*CtlObj_New(itself
)
59 const ControlHandle itself
;
62 if (itself
== NULL
) return PyMac_Error(resNotFound
);
63 it
= PyObject_NEW(ControlObject
, &Control_Type
);
64 if (it
== NULL
) return NULL
;
65 it
->ob_itself
= itself
;
66 SetCRefCon(itself
, (long)it
);
67 return (PyObject
*)it
;
69 CtlObj_Convert(v
, p_itself
)
71 ControlHandle
*p_itself
;
75 PyErr_SetString(PyExc_TypeError
, "Control required");
78 *p_itself
= ((ControlObject
*)v
)->ob_itself
;
82 static void CtlObj_dealloc(self
)
85 /* Cleanup of self->ob_itself goes here */
89 static PyObject
*CtlObj_SetCTitle(_self
, _args
)
93 PyObject
*_res
= NULL
;
95 if (!PyArg_ParseTuple(_args
, "O&",
96 PyMac_GetStr255
, title
))
98 SetCTitle(_self
->ob_itself
,
105 static PyObject
*CtlObj_GetCTitle(_self
, _args
)
106 ControlObject
*_self
;
109 PyObject
*_res
= NULL
;
111 if (!PyArg_ParseTuple(_args
, "O&",
112 PyMac_GetStr255
, title
))
114 GetCTitle(_self
->ob_itself
,
121 static PyObject
*CtlObj_DisposeControl(_self
, _args
)
122 ControlObject
*_self
;
125 PyObject
*_res
= NULL
;
126 if (!PyArg_ParseTuple(_args
, ""))
128 DisposeControl(_self
->ob_itself
);
134 static PyObject
*CtlObj_HideControl(_self
, _args
)
135 ControlObject
*_self
;
138 PyObject
*_res
= NULL
;
139 if (!PyArg_ParseTuple(_args
, ""))
141 HideControl(_self
->ob_itself
);
147 static PyObject
*CtlObj_ShowControl(_self
, _args
)
148 ControlObject
*_self
;
151 PyObject
*_res
= NULL
;
152 if (!PyArg_ParseTuple(_args
, ""))
154 ShowControl(_self
->ob_itself
);
160 static PyObject
*CtlObj_Draw1Control(_self
, _args
)
161 ControlObject
*_self
;
164 PyObject
*_res
= NULL
;
165 if (!PyArg_ParseTuple(_args
, ""))
167 Draw1Control(_self
->ob_itself
);
173 static PyObject
*CtlObj_HiliteControl(_self
, _args
)
174 ControlObject
*_self
;
177 PyObject
*_res
= NULL
;
179 if (!PyArg_ParseTuple(_args
, "h",
182 HiliteControl(_self
->ob_itself
,
189 static PyObject
*CtlObj_MoveControl(_self
, _args
)
190 ControlObject
*_self
;
193 PyObject
*_res
= NULL
;
196 if (!PyArg_ParseTuple(_args
, "hh",
200 MoveControl(_self
->ob_itself
,
208 static PyObject
*CtlObj_SizeControl(_self
, _args
)
209 ControlObject
*_self
;
212 PyObject
*_res
= NULL
;
215 if (!PyArg_ParseTuple(_args
, "hh",
219 SizeControl(_self
->ob_itself
,
227 static PyObject
*CtlObj_SetCtlValue(_self
, _args
)
228 ControlObject
*_self
;
231 PyObject
*_res
= NULL
;
233 if (!PyArg_ParseTuple(_args
, "h",
236 SetCtlValue(_self
->ob_itself
,
243 static PyObject
*CtlObj_GetCtlValue(_self
, _args
)
244 ControlObject
*_self
;
247 PyObject
*_res
= NULL
;
249 if (!PyArg_ParseTuple(_args
, ""))
251 _rv
= GetCtlValue(_self
->ob_itself
);
252 _res
= Py_BuildValue("h",
257 static PyObject
*CtlObj_SetCtlMin(_self
, _args
)
258 ControlObject
*_self
;
261 PyObject
*_res
= NULL
;
263 if (!PyArg_ParseTuple(_args
, "h",
266 SetCtlMin(_self
->ob_itself
,
273 static PyObject
*CtlObj_GetCtlMin(_self
, _args
)
274 ControlObject
*_self
;
277 PyObject
*_res
= NULL
;
279 if (!PyArg_ParseTuple(_args
, ""))
281 _rv
= GetCtlMin(_self
->ob_itself
);
282 _res
= Py_BuildValue("h",
287 static PyObject
*CtlObj_SetCtlMax(_self
, _args
)
288 ControlObject
*_self
;
291 PyObject
*_res
= NULL
;
293 if (!PyArg_ParseTuple(_args
, "h",
296 SetCtlMax(_self
->ob_itself
,
303 static PyObject
*CtlObj_GetCtlMax(_self
, _args
)
304 ControlObject
*_self
;
307 PyObject
*_res
= NULL
;
309 if (!PyArg_ParseTuple(_args
, ""))
311 _rv
= GetCtlMax(_self
->ob_itself
);
312 _res
= Py_BuildValue("h",
317 static PyObject
*CtlObj_SetCRefCon(_self
, _args
)
318 ControlObject
*_self
;
321 PyObject
*_res
= NULL
;
323 if (!PyArg_ParseTuple(_args
, "l",
326 SetCRefCon(_self
->ob_itself
,
333 static PyObject
*CtlObj_GetCRefCon(_self
, _args
)
334 ControlObject
*_self
;
337 PyObject
*_res
= NULL
;
339 if (!PyArg_ParseTuple(_args
, ""))
341 _rv
= GetCRefCon(_self
->ob_itself
);
342 _res
= Py_BuildValue("l",
347 static PyObject
*CtlObj_DragControl(_self
, _args
)
348 ControlObject
*_self
;
351 PyObject
*_res
= NULL
;
356 if (!PyArg_ParseTuple(_args
, "O&O&O&h",
357 PyMac_GetPoint
, &startPt
,
358 PyMac_GetRect
, &limitRect
,
359 PyMac_GetRect
, &slopRect
,
362 DragControl(_self
->ob_itself
,
372 static PyObject
*CtlObj_TestControl(_self
, _args
)
373 ControlObject
*_self
;
376 PyObject
*_res
= NULL
;
379 if (!PyArg_ParseTuple(_args
, "O&",
380 PyMac_GetPoint
, &thePt
))
382 _rv
= TestControl(_self
->ob_itself
,
384 _res
= Py_BuildValue("h",
389 static PyObject
*CtlObj_TrackControl(_self
, _args
)
390 ControlObject
*_self
;
393 PyObject
*_res
= NULL
;
396 if (!PyArg_ParseTuple(_args
, "O&",
397 PyMac_GetPoint
, &thePoint
))
399 _rv
= TrackControl(_self
->ob_itself
,
401 (ControlActionUPP
)0);
402 _res
= Py_BuildValue("h",
407 static PyObject
*CtlObj_GetCVariant(_self
, _args
)
408 ControlObject
*_self
;
411 PyObject
*_res
= NULL
;
413 if (!PyArg_ParseTuple(_args
, ""))
415 _rv
= GetCVariant(_self
->ob_itself
);
416 _res
= Py_BuildValue("h",
421 static PyMethodDef CtlObj_methods
[] = {
422 {"SetCTitle", (PyCFunction
)CtlObj_SetCTitle
, 1,
423 "(Str255 title) -> None"},
424 {"GetCTitle", (PyCFunction
)CtlObj_GetCTitle
, 1,
425 "(Str255 title) -> None"},
426 {"DisposeControl", (PyCFunction
)CtlObj_DisposeControl
, 1,
428 {"HideControl", (PyCFunction
)CtlObj_HideControl
, 1,
430 {"ShowControl", (PyCFunction
)CtlObj_ShowControl
, 1,
432 {"Draw1Control", (PyCFunction
)CtlObj_Draw1Control
, 1,
434 {"HiliteControl", (PyCFunction
)CtlObj_HiliteControl
, 1,
435 "(short hiliteState) -> None"},
436 {"MoveControl", (PyCFunction
)CtlObj_MoveControl
, 1,
437 "(short h, short v) -> None"},
438 {"SizeControl", (PyCFunction
)CtlObj_SizeControl
, 1,
439 "(short w, short h) -> None"},
440 {"SetCtlValue", (PyCFunction
)CtlObj_SetCtlValue
, 1,
441 "(short theValue) -> None"},
442 {"GetCtlValue", (PyCFunction
)CtlObj_GetCtlValue
, 1,
443 "() -> (short _rv)"},
444 {"SetCtlMin", (PyCFunction
)CtlObj_SetCtlMin
, 1,
445 "(short minValue) -> None"},
446 {"GetCtlMin", (PyCFunction
)CtlObj_GetCtlMin
, 1,
447 "() -> (short _rv)"},
448 {"SetCtlMax", (PyCFunction
)CtlObj_SetCtlMax
, 1,
449 "(short maxValue) -> None"},
450 {"GetCtlMax", (PyCFunction
)CtlObj_GetCtlMax
, 1,
451 "() -> (short _rv)"},
452 {"SetCRefCon", (PyCFunction
)CtlObj_SetCRefCon
, 1,
453 "(long data) -> None"},
454 {"GetCRefCon", (PyCFunction
)CtlObj_GetCRefCon
, 1,
456 {"DragControl", (PyCFunction
)CtlObj_DragControl
, 1,
457 "(Point startPt, Rect limitRect, Rect slopRect, short axis) -> None"},
458 {"TestControl", (PyCFunction
)CtlObj_TestControl
, 1,
459 "(Point thePt) -> (short _rv)"},
460 {"TrackControl", (PyCFunction
)CtlObj_TrackControl
, 1,
461 "(Point thePoint) -> (short _rv)"},
462 {"GetCVariant", (PyCFunction
)CtlObj_GetCVariant
, 1,
463 "() -> (short _rv)"},
467 PyMethodChain CtlObj_chain
= { CtlObj_methods
, NULL
};
469 static PyObject
*CtlObj_getattr(self
, name
)
473 return Py_FindMethodInChain(&CtlObj_chain
, (PyObject
*)self
, name
);
476 #define CtlObj_setattr NULL
478 PyTypeObject Control_Type
= {
479 PyObject_HEAD_INIT(&PyType_Type
)
481 "Control", /*tp_name*/
482 sizeof(ControlObject
), /*tp_basicsize*/
485 (destructor
) CtlObj_dealloc
, /*tp_dealloc*/
487 (getattrfunc
) CtlObj_getattr
, /*tp_getattr*/
488 (setattrfunc
) CtlObj_setattr
, /*tp_setattr*/
491 /* -------------------- End object type Control --------------------- */
494 static PyObject
*Ctl_NewControl(_self
, _args
)
498 PyObject
*_res
= NULL
;
509 if (!PyArg_ParseTuple(_args
, "O&O&O&bhhhhl",
510 WinObj_Convert
, &theWindow
,
511 PyMac_GetRect
, &boundsRect
,
512 PyMac_GetStr255
, title
,
520 _rv
= NewControl(theWindow
,
529 _res
= Py_BuildValue("O&",
534 static PyObject
*Ctl_GetNewControl(_self
, _args
)
538 PyObject
*_res
= NULL
;
542 if (!PyArg_ParseTuple(_args
, "hO&",
544 WinObj_Convert
, &owner
))
546 _rv
= GetNewControl(controlID
,
548 _res
= Py_BuildValue("O&",
553 static PyObject
*Ctl_KillControls(_self
, _args
)
557 PyObject
*_res
= NULL
;
559 if (!PyArg_ParseTuple(_args
, "O&",
560 WinObj_Convert
, &theWindow
))
562 KillControls(theWindow
);
568 static PyObject
*Ctl_DrawControls(_self
, _args
)
572 PyObject
*_res
= NULL
;
574 if (!PyArg_ParseTuple(_args
, "O&",
575 WinObj_Convert
, &theWindow
))
577 DrawControls(theWindow
);
583 static PyObject
*Ctl_UpdtControl(_self
, _args
)
587 PyObject
*_res
= NULL
;
589 if (!PyArg_ParseTuple(_args
, "O&",
590 WinObj_Convert
, &theWindow
))
592 UpdtControl(theWindow
,
599 static PyObject
*Ctl_UpdateControls(_self
, _args
)
603 PyObject
*_res
= NULL
;
605 if (!PyArg_ParseTuple(_args
, "O&",
606 WinObj_Convert
, &theWindow
))
608 UpdateControls(theWindow
,
615 static PyObject
*Ctl_FindControl(_self
, _args
)
619 PyObject
*_res
= NULL
;
623 ControlHandle theControl
;
624 if (!PyArg_ParseTuple(_args
, "O&O&",
625 PyMac_GetPoint
, &thePoint
,
626 WinObj_Convert
, &theWindow
))
628 _rv
= FindControl(thePoint
,
631 _res
= Py_BuildValue("hO&",
633 CtlObj_WhichControl
, theControl
);
637 static PyMethodDef Ctl_methods
[] = {
638 {"NewControl", (PyCFunction
)Ctl_NewControl
, 1,
639 "(WindowPtr theWindow, Rect boundsRect, Str255 title, Boolean visible, short value, short min, short max, short procID, long refCon) -> (ControlHandle _rv)"},
640 {"GetNewControl", (PyCFunction
)Ctl_GetNewControl
, 1,
641 "(short controlID, WindowPtr owner) -> (ControlHandle _rv)"},
642 {"KillControls", (PyCFunction
)Ctl_KillControls
, 1,
643 "(WindowPtr theWindow) -> None"},
644 {"DrawControls", (PyCFunction
)Ctl_DrawControls
, 1,
645 "(WindowPtr theWindow) -> None"},
646 {"UpdtControl", (PyCFunction
)Ctl_UpdtControl
, 1,
647 "(WindowPtr theWindow) -> None"},
648 {"UpdateControls", (PyCFunction
)Ctl_UpdateControls
, 1,
649 "(WindowPtr theWindow) -> None"},
650 {"FindControl", (PyCFunction
)Ctl_FindControl
, 1,
651 "(Point thePoint, WindowPtr theWindow) -> (short _rv, ControlHandle theControl)"},
658 CtlObj_WhichControl(ControlHandle c
)
662 /* XXX What if we find a control belonging to some other package? */
666 it
= (PyObject
*) GetCRefCon(c
);
667 if (it
== NULL
|| ((ControlObject
*)it
)->ob_itself
!= c
)
682 m
= Py_InitModule("Ctl", Ctl_methods
);
683 d
= PyModule_GetDict(m
);
684 Ctl_Error
= PyMac_GetOSErrException();
685 if (Ctl_Error
== NULL
||
686 PyDict_SetItemString(d
, "Error", Ctl_Error
) != 0)
687 Py_FatalError("can't initialize Ctl.Error");
690 /* ========================= End module Ctl ========================= */